-
Notifications
You must be signed in to change notification settings - Fork 173
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
Added lubridate specifics for Oracle #267
Conversation
R/backend-oracle.R
Outdated
@@ -45,9 +45,26 @@ sql_translate_env.Oracle <- function(con) { | |||
as.integer64 = sql_cast("NUMBER(19)"), | |||
as.numeric = sql_cast("NUMBER"), | |||
as.double = sql_cast("NUMBER"), | |||
#as.Date = sql_cast("DATE"), | |||
# Oracle date casting is NLS dependant, the following will work for the default YYYY-MM-DD | |||
as.Date = function(x) sql_expr("DATE " !!x), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like valid syntax. Can you please double check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you meant the R syntax you're right, not sure why I did it that way, it'll be corrected in my commit.
The SQL syntax is the ANSI SQL string literal. At least in Oracle SQL (I can't speak for others) using cast
is dependant on the NLS settings, which means unless you know this and format your date string in advance then you can't be certain it will work. the ANSI uses the YYYY-MM-DD format (which matches the default lubridate format string, at least in my localisation?). I thought this would be the safest way to catch most dates short of adding in and translating the format options?
The last script of the introduction section here shows this example https://oracle-base.com/articles/misc/oracle-dates-timestamps-and-intervals
R/backend-oracle.R
Outdated
|
||
# https://modern-sql.com/feature/extract | ||
yday = function(x) sql_expr((TO_NUMBER(TO_CHAR(!!x, "DDD")))), | ||
wday = function(x) build_sql("(MOD(1 + TRUNC(", !!x, ") - TRUNC(", !!x, ", 'IW'),7) +1 )"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using build_sql()
you don't need !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't aware thanks, corrected in next commit
I've supplied the basic changes needed to fully support oracle with the lubridate functions currently supported across all languages.
Main differences are: