Skip to content

creating a new column does not work when using odbc::odbc() as a connection #5

@Wytzepakito

Description

@Wytzepakito
library(dcmodify)
library(dcmodifydb)

# silly modification rules
m <- modifier( if (cyl == 6)  new_gear <- 10
               , gear[cyl == 4] <- 0  # this R syntax works too :-)
               , if (gear == 3) cyl <- 2
)
con <- dbConnect(odbc::odbc(),
                 driver = "PostgreSQL Unicode(x64)",
                 host = "localhost",
                 database = "testing_db",
                 port = 5432,
                 UID    = "#######",
                 PWD    = "######")
dbWriteTable(con, "mtcars", mtcars[,c("cyl", "gear")])
tbl_mtcars <- dplyr::tbl(con, "mtcars")

tbl_m <- modify(tbl_mtcars, m, copy=TRUE)

Yields an error in the SQL syntax: ERROR: syntax error at or near "2" <SQL> 'ALTER TABLE "dcmodifydb_2508036" ADD COLUMN "new_gear" 2;'

This is because of the usage of DBI::dbColumnInfo(rs) in alter_stmt(). If odbc::odbc is used as the connection, DBI::dbColumnInfo(rs) yields a dataframe like:

1  row_names   -1
2        mpg    6
3        cyl    2
4       disp    6
5         hp    6
6       drat    6
7         wt    6
8       qsec    6
9         vs    6
10        am    6
11      gear    2
12      carb    6
13      dnow   -1
14  new_gear    2

Instead the actual types as a character are needed in the second column

See:
issue1
issue2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions