I'm having an issue with datetime handling in RPostgreSQL. Specifically it relates to POSIXct objects with a UTC timezone being automatically adjusted to daylight saving during upload to a postgres database. A simple example:
library(RPostgreSQL)
example = data.frame(date=as.POSIXct('2016-08-14 15:50:00',tz='UTC'))
con = dbConnect(dbDriver("PostgreSQL"),
dbname="mydb",
host="localhost",
port="5432",
user="me",
password="password")
dbWriteTable(con,name=c('myschema','mytable'),example,overwrite=T)
example2 = dbReadTable(con,name=c('myschema','mytable'))
dbDisconnect(con)
example2 # 2016-08-14 14:50:00
In this case the time is exported as 15:50 but read back in as 14:50, suggesting that British Summer Time daylight saving has been applied. I've tried adjusting my system settings to UTC, setting the timezone in R to UTC using Sys.setenv(TZ='UTC')
and setting the timezone in Postgres to UTC using SET timezone TO 'UTC'
, all to no avail.
Does anybody know where in the process the conversion is likely to be happening and where dbWriteTable is taking its timezone from? Are there any suggestions on other settings that might need adjusting?