-
Notifications
You must be signed in to change notification settings - Fork 74
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
wrong format of Posixt datetime by DBI::dbQuoteLiteral #467
Comments
Thanks. It seems indeed that DBI has this wrong, I don't remember why I chose this format. Can you confirm that |
TDLRYYYY-MM-DD HH:MI:SS should be correct, as described in th url, and I've encountered on many RDBMS, but parameters should be better. detail
IMHO you should add a parameter to choose dbQuoteLiteral_DBIConnection <- function(conn, x, ..., format ='yyyy-mm-dd hh:mi:ss', tz='UTC') {
(...)
if (inherits(x, "POSIXt")) {
return(dbQuoteString(
conn,
strftime(as.POSIXct(x), format = format , tz =tz)
))
(...)
}
|
Or Except maybe in this case if |
I forgot about time zones. Is there a universally supported format to specify at least the UTC offset? At least this works in Postgres: con <- RPostgres::postgresDefault()
DBI::dbGetQuery(con, "SELECT '2024-04-01 19:09:34+0200'::timestamptz")
#> timestamptz
#> 1 2024-04-01 17:09:34 Created on 2024-04-01 with reprex v2.1.0 (It is correct because the default Passing a format to In DBI, I'd like to implement something that works reasonably well for all databases. But it has to be correct, or fail. |
(merged Jun 26, 2024 in https://github.com/r-dbi/DBI/releases/tag/v1.2.3.9002) Thanks. but
So, for readers, for my old database I use:
but I understand the fix with timezone for normal recent RDBMS :) |
Since 1.7.0 glue_sql uses
DBI::dbQuoteLiteral()
(see tidyverse/glue#321 : "glue ≥ 1.7 : wrong format of Posixt datetime by glue_sql() ")Here is below the reprex for DBI 1.2.1 (but this is the same issue for DBI 1.1.3).
'2023-11-16 14:52:45'
DBI::dbQuoteLiteral()
gives'20231116145245'
For information I use:
DBI::dbConnect(odbc::odbc(),.connection_string=choosen_RDBMS_connection, encoding = database_encoding)
on Linux Ubuntu (see session_info below)Created on 2024-02-23 with reprex v2.1.0
Session info
The text was updated successfully, but these errors were encountered: