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

Dates escaped incorrectly in Postgres #727

Closed
carlganz opened this issue Dec 3, 2021 · 6 comments · Fixed by #1072
Closed

Dates escaped incorrectly in Postgres #727

carlganz opened this issue Dec 3, 2021 · 6 comments · Fixed by #1072
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL help wanted ❤️ we'd love your help!
Milestone

Comments

@carlganz
Copy link

carlganz commented Dec 3, 2021

Possibly similar to #661 but originally posted here: r-dbi/RPostgres#362

library(RPostgres)
# use whatever Postgres connection you have
con <- postgresDefault()
dbplyr::sql_escape_date(con, Sys.Date())
# <SQL> '2021-12-02'
dbQuoteLiteral(con, Sys.Date())
# <SQL> '2021-12-02'::date
@hadley
Copy link
Member

hadley commented Dec 8, 2021

What should it be?

@carlganz
Copy link
Author

carlganz commented Dec 8, 2021

The second one with the explicit date casting is correct. @krlmlr can confirm

@mgirlich
Copy link
Collaborator

mgirlich commented Apr 6, 2022

The same is true for other databases and also for datetimes. Maybe we should simply use dbQuoteLiteral() for real databases instead of using custom escape functions?

@hadley
Copy link
Member

hadley commented Apr 6, 2022

@mgirlich yeah, if dbQuoteLiteral() is implemented we should use it, but I'm not sure how widespread support is.

@hadley
Copy link
Member

hadley commented Apr 6, 2022

In general we want to push these sorts of fixes upstream as much as possible, but it's fiddly to make sure everything keeps working for folks regardless of the combination of dbplyr and upstream package installed.

@hadley
Copy link
Member

hadley commented Apr 28, 2022

I think the easiest fix here would be to supply sql_escape_date and sql_escape_datetime methods for Postgres that just called dbQuoteLiteral().

@hadley hadley added bug an unexpected problem or unintended behavior help wanted ❤️ we'd love your help! func trans 🌍 Translation of individual functions to SQL labels Apr 28, 2022
@hadley hadley added this to the 2.3.0 milestone Dec 5, 2022
hadley added a commit that referenced this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL help wanted ❤️ we'd love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants