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

Adding filter creates a qualified select * which causes error #1577

Open
al-obrien opened this issue Feb 4, 2025 · 0 comments
Open

Adding filter creates a qualified select * which causes error #1577

al-obrien opened this issue Feb 4, 2025 · 0 comments

Comments

@al-obrien
Copy link

al-obrien commented Feb 4, 2025

We use a DB2 flavored SQL database. Ever since {dbplyr} was updated past version 2.3.4, an error occurs in certain combinations of commands.

It appears this is due to a SELECT statement having a qualified name combined with *. This appears to occur under certain circumstances, such as when filter() is used. If the quotes are removed or the entire qualifier with up to the catalog is provided, it works. However, I do not know how this can be enforced. Specifying specific columns also works as * is no longer used.

I believe this is related in some capacity to this prior issue: #1480

Perhaps there is a simple solution Ive missed to adjust quoting in column selection with *?

Example

Due to the nature of the system being DB2, it is hard to create a reprex. However, I have provided some pseudocode and example outputs to help elucidate the issue.

Setup Connection

library(dbplyr)
library(dplyr)
con <- DBI::dbConnect(odbc::odbc(),
               "DB2", # DSN for our DB2
                uid = Sys.getenv("myuid"),     
                pwd = Sys.getenv("mypwd"), timeout = 10)

Works - the select * does not have a quoted qualifier

DBI::dbGetQuery(con, "SELECT MYCATALOG.MYSCHEMA.MYTABLE.*
FROM MYCATALOG.MYSCHEMA.MYTABLE.
WHERE MYCOLUMN != 'SOMEVALUE'"

Fails - due to a qualified select *

mytbl <-tbl(con, in_catalog(sql("MYCATALOG"), sql("MYSCHEMA"), sql("MYTABLE")))
 mytb  %>%
  filter(MYCOLUMN != "SOMEVALUE") %>%
  show_query() # collect()

! ODBC failed with error 00000 from [IBM][CLI Driver][DB2/AIX64].
✖ SQL0204N "MYTABLE" is an undefined name. SQLSTATE=42704

• 'SELECT "MYTABLE".*
• FROM MYCATALOG.MYSCHEMA.MYTABLE
• WHERE ("MYCOLUMN " != 'SOMEVALUE')'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant