Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name and schema in DBI::Id #255

Closed
troelsy opened this issue Aug 9, 2018 · 1 comment
Closed

Name and schema in DBI::Id #255

troelsy opened this issue Aug 9, 2018 · 1 comment

Comments

@troelsy
Copy link

troelsy commented Aug 9, 2018

I think I found a bug when working with DBI::Id. DBI::Id requires that you specify 'name' and 'schema', which makes sense, but the order of the arguments must be schema-name and not name-schema. It seems like it doesn't actually use the name of the arguments.

I made this example, to show the error. You can try with both 'table_id'

library(odbc)
library(DBI)

con <- dbConnect(odbc(),
                   Driver = "PostgreSQL Unicode",
                   Server = "...",
                   Database = "...",
                   UID = "...",
                   PWD = "...",
                   Port = 5432)

data <- data.frame("x" = c(1, 2), "y" = c(2,1))
print(data)


# table_id <- DBI::Id(name = "my_table", schema = "my_schema")
table_id <- DBI::Id(schema="my_schema", name = "my_table")
print(table_id)

DBI::dbWriteTable(con, table_id, data, overwrite = TRUE)

If you run it as is, you'll get:

$ Rscript test.R
Loading required package: methods
  x y
1 1 2
2 2 1
<Id> name = my_schema, schema = my_table

If you use the other definition of 'table_id', you'll get:

$ Rscript test.R
Loading required package: methods
  x y
1 1 2
2 2 1
<Id> name = my_table, schema = my_schema
Error: <SQL> 'CREATE TABLE "my_table"."my_schema" (
  "x" DOUBLE PRECISION,
  "y" DOUBLE PRECISION
)
'
  nanodbc/nanodbc.cpp:1587: 3F000: ERROR: schema "my_table" does not exist;
Error while executing the query
Execution halted

Notice the error message saying the schema is "my_table". I'm using Ubuntu 16.04.4 LTS with PostgreSQL 9.5.12

@ghost ghost deleted a comment from krlmlr Aug 26, 2018
@ghost
Copy link

ghost commented Aug 26, 2018

This issue was moved by krlmlr to r-dbi/odbc#214.

@ghost ghost closed this as completed Aug 26, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant