You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different timestamp display in psql and RStudio #205
I still see the same problem -- sort of. Using your example from above:
On Windows 10
RPostgres_1.1.3 from CRAN
tbl <- dbGetQuery(MimicDB, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch")
tbl
## before_epoch
## 1 1969-12-31 17:59:59
tbl <- dbGetQuery(MimicDB, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch")
tbl
## before_epoch
## 1 1960-01-01 06:00:00
I am getting slightly different results. I tested the 2 queries with RPostgres, RPostgreSQL & pgAdmin4 on Win 10 and on the DB in Linux with psql directly.
RPostgres with default timezone
library(RPostgres)
packageVersion("RPostgres")
‘1.2.0’
pool <- dbConnect(RPostgres::Postgres(),
dbname = config$db[["dbname"]],
host = config$db[["dbhost"]],
port = config$db[["dbport"]],
user = config$db[["dbuser"]],
password = config$db[["dbpwd"]]
# ,timezone = NULL
)
dbGetQuery(pool, "SHOW timezone;")
UTC
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch")
1970-01-01 00:59:59
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch")
1960-01-01 13:00:00
dbDisconnect(pool)
RPostgres with timezone = NULL
pool <- dbConnect(RPostgres::Postgres(),
dbname = config$db[["dbname"]],
host = config$db[["dbhost"]],
port = config$db[["dbport"]],
user = config$db[["dbuser"]],
password = config$db[["dbpwd"]],
timezone = NULL)
dbGetQuery(pool, "SHOW timezone;")
1 localtime
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch")
1 1970-01-01 00:59:59
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch")
1 1960-01-01 14:00:00
dbDisconnect(pool)
RPostgreSQL
library(RPostgreSQL)
pool <- dbConnect(RPostgreSQL::PostgreSQL(),
dbname = config$db[["dbname"]],
host = config$db[["dbhost"]],
port = config$db[["dbport"]],
user = config$db[["dbuser"]],
password = config$db[["dbpwd"]])
dbGetQuery(pool, "SHOW timezone;")
1 localtime
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch")
1 1960-01-01 12:00:00
dbGetQuery(pool, "SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch")
1 1960-01-01 13:00:00
dbDisconnect(pool)
pgAdmin 4 (windows 10)
SHOW timezone;
"localtime"
SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch;
"1960-01-01 12:00:00"
SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch;
"1960-01-01 13:00:00+01"
Linux + psql
date +"%Z %z"
CET +0100
postgres=# show Timezone;
localtime
postgres=# SELECT CAST('1960-01-01 12:00:00' AS timestamp) AS before_epoch;
1960-01-01 12:00:00
postgres=# SELECT CAST('1960-01-01 12:00:00' AS timestamp) AT TIME ZONE 'utc' AS before_epoch;
1960-01-01 13:00:00+01
Session
sessioninfo::session_info()
setting value
version R version 3.6.1 (2019-07-05)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate German_Germany.1252
ctype German_Germany.1252
tz Europe/Berlin
date 2019-12-18
Now with RPostgres_1.2.0 I get the same results as I posted above on Dec. 22, 2018. Is there any hope this can be resolved? Is a better solution perhaps to see if odbc works with Postgres?
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.
Activity
EarlGlynn commentedon Dec 23, 2018
Using the MIMIC data, the odbc and RPostgreSQL packages work fine to display dates back to 1800, but RPostgres does not.
RPostgres only shows dates back to 1969-12-31, but maybe that is 1970-01-01 in my timezone (but off by a second).
See additional details for these drivers with the MIMIC data in separate notebooks here.
FWIW, the MIMIC-III database is publicly available for medical researchers (after completion of required training).
krlmlr commentedon Dec 30, 2018
Thanks. From the RStudio Community post I'm guessing you're on Windows. On Linux I see:
Created on 2018-12-30 by the reprex package (v0.2.1.9000)
But on Windows this is consistent with your observation:
Created on 2018-12-30 by the reprex package (v0.2.1)
krlmlr commentedon Dec 17, 2019
Is this still an issue with RPostgres 1.2.0 (currently in development, about to hit CRAN)?
EarlGlynn commentedon Dec 18, 2019
I still see the same problem -- sort of. Using your example from above:
On Windows 10
RPostgres_1.1.3 from CRAN
Why the ~10 year difference here?
Same results using RPostgres_1.2.0 from GitHub
trafficonese commentedon Dec 18, 2019
I am getting slightly different results. I tested the 2 queries with
RPostgres,RPostgreSQL&pgAdmin4on Win 10 and on the DB in Linux withpsqldirectly.RPostgres with default timezone
RPostgres with timezone = NULL
RPostgreSQL
pgAdmin 4 (windows 10)
Linux + psql
Session
EarlGlynn commentedon Jul 17, 2020
Now with RPostgres_1.2.0 I get the same results as I posted above on Dec. 22, 2018. Is there any hope this can be resolved? Is a better solution perhaps to see if odbc works with Postgres?
krlmlr commentedon Jan 3, 2021
With #276:
Created on 2021-01-03 by the reprex package (v0.3.0)
Merge pull request #276 from r-dbi/b-timezone
krlmlr commentedon Jan 3, 2021
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?
github-actions commentedon Jan 4, 2022
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.