0

Here is mtcars data in the MonetDBLite database file.

library(MonetDBLite)
library(tidyverse)
library(DBI)

dbdir <- getwd()
con <- dbConnect(MonetDBLite::MonetDBLite(), dbdir)

dbWriteTable(conn = con, name = "mtcars_1", value = mtcars)

data_mt <- con %>% tbl("mtcars_1")

dbSendQuery(con, "ALTER TABLE mtcars_1 ADD COLUMN new=2")

How should I add a column/variable "new" to the table mtcars_1 in the MonetDBLite?

Geet
  • 2,515
  • 2
  • 19
  • 42

1 Answers1

1

Try

dbSendQuery(con, "ALTER TABLE mtcars_1 ADD COLUMN new_col INTEGER DEFAULT 2")

Hannes Mühleisen
  • 2,542
  • 11
  • 13
  • @Hannes Mühleisen Thanks! Then, how should I create new_col=mpg/cyl? I tried, dbSendQuery(con, "ALTER TABLE mtcars_1 ADD COLUMN new=mpg/cyl") , but its throwing an error. Where can I read more about these functions? – Geet Jun 06 '18 at 19:52
  • dbSendQuery(con, "ALTER TABLE mtcars_1 ADD COLUMN new_col2 DOUBLE PRECISION") dbSendQuery(con, "UPDATE mtcars_1 SET new_col2=cyl/mpg") This worked...just wondering if this can be done in one step...otherwise it's fine. – Geet Jun 06 '18 at 20:06