Skip to content

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

@al-obrien

Description

@al-obrien

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')'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions