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

Possible incorrect date literal translation for Oracle? #661

Closed
mfherman opened this issue Jun 10, 2021 · 2 comments · Fixed by #811
Closed

Possible incorrect date literal translation for Oracle? #661

mfherman opened this issue Jun 10, 2021 · 2 comments · Fixed by #811

Comments

@mfherman
Copy link

I'm trying a simple filter on a date column in an Oracle 19c database and getting the following error:

Error: nanodbc/nanodbc.cpp:1655: HY000: [Oracle][ODBC][Ora]ORA-00936: missing expression

It appears that the issue (in my Oracle instance) is caused by the parenthesis surrounding the date in the dbplyr translation

tbl(con, "TEST_TABLE") %>%    
  filter(DT == as.Date("2020-01-01")) %>% 
  show_query()
# <SQL>
# SELECT *
# FROM ("TEST_TABLE") 
# WHERE ("DT" = DATE('2020-01-01'))

If I run the same query with the parentheses removed in my SQL IDE, the query runs with no error.

SELECT *
FROM ("TEST_TABLE") 
WHERE ("DT" = DATE '2020-01-01')
@cluoma
Copy link

cluoma commented Nov 2, 2021

It look like https://github.com/tidyverse/dbplyr/blob/main/R/backend-oracle.R is using the wrong function for date translation.

# https://docs.oracle.com/cd/E17952_01/mysql-5.7-en/date-and-time-functions.html#function_date
as.Date = function(x) sql_expr(DATE(!!x)),

This is actually a reference for MySQL. Oracle does not use the DATE, but rather TO_DATE.

I made this change cluoma@5f004ab and it's now working for me.

@mfherman
Copy link
Author

mfherman commented Nov 4, 2021

Looks right! I switched jobs and don’t have an Oracle DB to test anymore, but seems like it would be an easy fix!

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 a pull request may close this issue.

2 participants