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

Support ICU extension and timezones for TIMESTAMPTZ converted to POSIXct and POSIXlt #184

Open
ggrothendieck opened this issue Jun 16, 2024 · 3 comments
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help!

Comments

@ggrothendieck
Copy link

This gives back a UTC time zone even if the original was in the local time zone. duckdb has an icu extension and TIMESTAMPTZ type which may solve this. Not sure.

library(duckdb)
con <- dbConnect(duckdb())
d <- data.frame(d = as.POSIXct("2000-01-01 12:13:14"))
duckdb_register(con, "d", d)
out <- dbGetQuery(con, "from d")
##                     d
## 1 2000-01-01 17:13:14

dput(out)
## structure(list(d = structure(946746794, class = c("POSIXct", 
## "POSIXt"), tzone = "UTC")), class = "data.frame", row.names = c(NA,  <--------------- note UTC
## -1L))

dput(d)
## structure(list(d = structure(946746794, class = c("POSIXct", 
## "POSIXt"), tzone = "")), class = "data.frame", row.names = c(NA, 
## -1L))

@eitsupi
Copy link
Contributor

eitsupi commented Jun 16, 2024

You may want to see the document:
https://r.duckdb.org/reference/duckdb.html#arg-timezone-out

@ggrothendieck
Copy link
Author

ggrothendieck commented Jun 16, 2024

Thanks. I will use that in the meantime but ideally POSIXct objects would be represented in duckdb as duckdb types that handle time zones in order to eliminate the impedance.

Note that that link claims that only UTC is handled by duckdb but I think that that only applies to TIMESTAMP type but not TIMESTAMPTZ type.

@krlmlr
Copy link
Collaborator

krlmlr commented Aug 16, 2024

The TIMESTAMPTZ type from the ICU extension isn't currently handled properly. We'd need to fix that before even thinking about handling POSIXct . PR welcome!

library(duckdb)
#> Loading required package: DBI
con <- dbConnect(duckdb())

dbExecute(con, "CREATE TABLE x (a TIMESTAMPTZ)")
#> [1] 0
dbExecute(con, "INSERT INTO x VALUES ('2024-01-10 13:03:12 -0800'::TIMESTAMP)")
#> Error: rapi_prepare: Failed to prepare query INSERT INTO x VALUES ('2024-01-10 13:03:12 -0800'::TIMESTAMP)
#> Error: Conversion Error: timestamp field value "2024-01-10 13:03:12 -0800" has a timestamp that is not UTC.
#> Use the TIMESTAMPTZ type with the ICU extension loaded to handle non-UTC timestamps.
#> LINE 1: ...O x VALUES ('2024-01-10 13:03:12 -0800'::TIMESTAMP)
#>                                                   ^
dbExecute(con, "INSERT INTO x VALUES ('2024-01-10 13:03:12'::TIMESTAMP)")
#> [1] 1

# dbExecute(con, "INSTALL icu")
dbExecute(con, "LOAD icu")
#> [1] 0
dbExecute(con, "INSERT INTO x VALUES ('2024-01-10 13:03:12 -0800'::TIMESTAMPTZ)")
#> [1] 1
dbExecute(con, "INSERT INTO x VALUES ('2024-01-10 13:03:12 -0500'::TIMESTAMPTZ)")
#> [1] 1
dbReadTable(con, "x")$a
#> [1] "2024-01-10 13:03:12 UTC" "2024-01-10 13:03:12 UTC"
#> [3] "2024-01-10 13:03:12 UTC"

Created on 2024-08-16 with reprex v2.1.0

@krlmlr krlmlr changed the title Timezone problem with POSIXct Support ICU extension and timezones for TIMESTAMPTZ converted to POSIXct and POSIXlt Aug 16, 2024
@krlmlr krlmlr added feature a feature request or enhancement help wanted ❤️ we'd love your help! and removed enhancement labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help!
Projects
None yet
Development

No branches or pull requests

3 participants