-
Notifications
You must be signed in to change notification settings - Fork 78
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
Different results on Windows and Mac with timestamp columns #190
Comments
Thanks. What happens when you run these queries from |
On Mac, it returns |
This might be related. Writing a table with timestamp column is failing when Adding Error
RPostgres releaseTested with versions 1.1.1 and 1.1.1.9002 Session Info
|
Are you using EnterpriseDB PostgreSQL? On Windows, it has some locale defaults that aren't the same as what's traditional on Linux. You may need to re-install PostgreSQL and explicitly set the locale settings. 👎 I discovered this the hard way - by taking a |
The way I understand Relevant: https://dba.stackexchange.com/q/59006/6934 (but moot because many users of RPostgres aren't in control of the DB schema). |
Does the new |
On Windows and with the current dev version of RPostgres, the library(DBI)
Sys.unsetenv("TZ") # environment variables from the main R session get carried through to reprex::reprex() https://community.rstudio.com/t/environment-variables-in-reprex-reprex/64499
Sys.timezone() # "Native" time zone
#> [1] "Europe/Berlin"
query <- "SELECT '2018-01-01 12:30:00'::TIMESTAMP"
db <- dbConnect(RPostgres::Postgres(), dbname="postgres", timezone = "America/New_York")
dbGetQuery(db, query)[[1,1]]
#> [1] "2018-01-01 12:30:00 CET"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), dbname="postgres", timezone = "Europe/London")
dbGetQuery(db, query)[[1,1]]
#> [1] "2018-01-01 12:30:00 CET"
dbDisconnect(db)
Sys.setenv(TZ="America/New_York") # another time zone (usually -6 relative to Europe/Berlin)
Sys.timezone()
#> [1] "America/New_York"
db <- dbConnect(RPostgres::Postgres(), dbname="postgres", timezone = "America/New_York")
dbGetQuery(db, query)[[1,1]]
#> [1] "2018-01-01 06:30:00 EST"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), dbname="postgres", timezone = "Europe/London")
dbGetQuery(db, query)[[1,1]]
#> [1] "2018-01-01 06:30:00 EST"
dbDisconnect(db)
Sys.unsetenv("TZ") Session infosessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 3.6.3 (2020-02-29)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language en
#> collate German_Germany.1252
#> ctype German_Germany.1252
#> tz Europe/Berlin
#> date 2020-05-04
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1)
#> backports 1.1.6 2020-04-05 [1] CRAN (R 3.6.2)
#> bit 1.1-15.2 2020-02-10 [1] CRAN (R 3.6.2)
#> bit64 0.9-7 2017-05-08 [1] CRAN (R 3.6.0)
#> blob 1.2.1 2020-01-20 [1] CRAN (R 3.6.2)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.3)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1)
#> DBI * 1.1.0 2019-12-15 [1] CRAN (R 3.6.1)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.2)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2)
#> fs 1.4.1.9000 2020-05-04 [1] Github (r-lib/fs@bdc82be)
#> glue 1.4.0 2020-04-03 [1] CRAN (R 3.6.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
#> hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.2)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.3)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1)
#> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 3.6.3)
#> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.3)
#> reprex 0.3.0.9001 2020-05-04 [1] Github (tidyverse/reprex@a019cc4)
#> rlang 0.4.6 2020-05-02 [1] CRAN (R 3.6.3)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.2)
#> RPostgres 1.2.0.9000 2020-05-04 [1] Github (r-dbi/RPostgres@f2d698c)
#> rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
#> styler 1.3.2 2020-02-23 [1] CRAN (R 3.6.2)
#> tibble 3.0.1 2020-04-20 [1] CRAN (R 3.6.3)
#> vctrs 0.2.99.9011 2020-05-04 [1] Github (r-lib/vctrs@0ca806c)
#> withr 2.2.0 2020-04-20 [1] CRAN (R 3.6.3)
#> xfun 0.13 2020-04-13 [1] CRAN (R 3.6.3)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
#>
#> [1] C:/Users/daniel/Documents/.R/win-library
#> [2] C:/Program Files/R/R-3.6.3/library |
Should be fixed with #276. The difference between Windows and macOS was supposedly due to a different library(DBI)
# Must run in a new session on Linux
Sys.unsetenv("TZ") # environment variables from the main R session get carried through to reprex::reprex() https://community.rstudio.com/t/environment-variables-in-reprex-reprex/64499
Sys.timezone() # "Native" time zone
#> [1] "Europe/Zurich"
query <- "SELECT '2018-01-01 12:30:01.23'::TIMESTAMP"
db <- dbConnect(RPostgres::Postgres(), timezone = "America/New_York")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 EST"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), timezone = "Europe/London")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 GMT"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), timezone = "Europe/Zurich")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 CET"
dbDisconnect(db) Created on 2021-01-03 by the reprex package (v0.3.0) library(DBI)
# Must run in a new session on Linux
Sys.setenv("TZ" = "America/New_York")
Sys.timezone() # "Native" time zone
#> [1] "America/New_York"
query <- "SELECT '2018-01-01 12:30:01.23'::TIMESTAMP"
db <- dbConnect(RPostgres::Postgres(), timezone = "America/New_York")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 EST"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), timezone = "Europe/London")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 GMT"
dbDisconnect(db)
db <- dbConnect(RPostgres::Postgres(), timezone = "Europe/Zurich")
dbGetQuery(db, query)[[1]]
#> [1] "2018-01-01 12:30:01 CET"
dbDisconnect(db) Created on 2021-01-03 by the reprex package (v0.3.0) |
Should be fixed now. Could you please test the development version in the next few days, and let me know if any problems still arise? |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Hi, I'm seeing inconsistencies with how
timestamp without time zone
columns behave on Mac and Windows whenSys.getenv("TZ")
is different thanSys.timezone()
. Tested on version 1.1.1.Here's a minimal script to reproduce:
2018-01-01 12:30:00 EST
.2018-01-01 3:30:00 EST
(whenSys.timezone()
isAmerica/Los_Angeles
).What seems to be happening is on Mac,
2018-01-01 12:30:00
in the database is read in theTZ
time zone. On Windows,2018-01-01 12:30:00
in the database is read in theSys.timezone()
time zone, then converted to theTZ
time zone for display.The text was updated successfully, but these errors were encountered: