Skip to content

glue_sql() collapses zero-length DBI::SQL object into DBI::SQL("NULL")#244

Merged
jennybc merged 5 commits intotidyverse:mainfrom
shrektan:zero-length-SQL-NULL
Nov 29, 2021
Merged

glue_sql() collapses zero-length DBI::SQL object into DBI::SQL("NULL")#244
jennybc merged 5 commits intotidyverse:mainfrom
shrektan:zero-length-SQL-NULL

Conversation

@shrektan
Copy link
Copy Markdown
Contributor

This is a missed case of #134

The real use case that hurts in reality is :

When using Oracle database, the date object must be in format like date'yyyy-mm-dd'. Thus, we need to do:

sql_dates <- DBI::SQL(sprintf("date'%s'", dates))
glue::glue_sql("select * from table where ref_date in ({sql_dates*})", .con = con)

Thus, when dates is zero-length, sql_dates would be zero-length as well, but it leads to an empty SQL string in the current version of glue.

This PR fixes this. It results a valid SQL: select * from table where ref_date in (NULL)

@shrektan shrektan changed the title glue_sql() should collapses zero-length DBI::SQL object into DBI::SQL("NULL") glue_sql() collapses zero-length DBI::SQL object into DBI::SQL("NULL") Nov 26, 2021
@jennybc
Copy link
Copy Markdown
Member

jennybc commented Nov 29, 2021

@jimhester Do you agree this is good to go?

@jennybc jennybc merged commit a24c975 into tidyverse:main Nov 29, 2021
@shrektan shrektan deleted the zero-length-SQL-NULL branch November 29, 2021 23:22
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

Successfully merging this pull request may close these issues.

3 participants