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

dbUnquoteIdentifier() too stringent #277

Closed
baileych opened this issue Mar 20, 2019 · 1 comment · Fixed by #279 or r-dbi/RPostgres#220
Closed

dbUnquoteIdentifier() too stringent #277

baileych opened this issue Mar 20, 2019 · 1 comment · Fixed by #279 or r-dbi/RPostgres#220
Labels
Milestone

Comments

@baileych
Copy link
Contributor

baileych commented Mar 20, 2019


It appears that the object with class "SQL" produced by dbQuoteIdentifier(pq_conn, 'some.string') surrounds the string with " which the grep() in dbUnquoteIdentifier(pq_conn, quoted_sql) sees. But the object with class "SQL" produced by DBI::SQL(dbplyr::in_schema('some', 'string')), which his how dbplyr generates the table name to pass to DBI, does not add the ", apparently because it's coming to DBI as an identifier. The absence of the double quotes dplyr's copy_to() to blow up with an RPostgres connection, via the calls to db_copy_to() and dbExistsTable().

Since dbUnquoteIdentifier() actually wants a dot-separated schema.table pair, I'm not sure why it's so fussy about the presence of the quotes. Could we consider making them optional? The operative code appears to be the regex at line 74 of RPostgres' quote.R.

An alternative might be to teach dbplyr's IDENT class handling to add quotes, but that will have a series of knock-on effects in places that assume these objects can be pasted into SQL strings - not insoluble, but would be good to understand the benefit of dbUnquoteIdentifier()'s requirement for quotation marks as a start.

require(RPostgres)
require(dplyr)
require(tibble)

copy_to(dbConnect(Postgres(), ...),
  tibble(col = 1:3),
  name = dbplyr::in_schema('test', 'name_test')
)
@krlmlr krlmlr changed the title RPostgres::dbUnquoteIdentifier too stringent dbUnquoteIdentifier() too stringent Mar 29, 2019
@krlmlr
Copy link
Member

krlmlr commented Mar 29, 2019

Ideally, we'd be able to unquote manually constructed qualified names:

library(DBI)
dbUnquoteIdentifier(ANSI(), SQL("schema.table"))
#> Error: Can't unquote schema.table
dbUnquoteIdentifier(ANSI(), SQL('"schema"."table"'))
#> [[1]]
#> <Id> schema = schema, table = table

Created on 2019-03-29 by the reprex package (v0.2.1.9000)

This was referenced May 28, 2019
@krlmlr krlmlr added this to the 1.1.0 milestone Aug 23, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2020
@krlmlr krlmlr added feature and removed enhancement labels Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants