I would like to "merge" two tables from a SQLite database from the R - and save this into a new table within the same database. Here is a minimum reproducible code:
install.packages("sqldf",dependencies=T)
install.packages("RSQLite",dependencies=T)
library(sqldf)
A <- data.frame(var1 = 1:5, var2=55:59)
B <- data.frame(var1 = 11:15, var2=155:159)
drv <- dbDriver("SQLite")
con <- dbConnect(drv, "basequalquer.db")
dbWriteTable(con, "TabelaA", A)
dbWriteTable(con, "TabelaB", B)
The result I want is this one:
dbGetQuery(con, 'SELECT * FROM TabelaA UNION ALL SELECT * FROM TabelaB' )
row_names var1 var2
1 1 1 55
2 2 2 56
3 3 3 57
4 4 4 58
5 5 5 59
6 1 11 155
7 2 12 156
8 3 13 157
9 4 14 158
10 5 15 159
I can do a query to get it, but I do not know how to save it directly in the database (ie without having to save it in a data.frame and then do dbWriteTable)