Skip to content

RPostgreSQL driver timestamp data type mapping

3 messages · Brian Ripley, Sébastien Bihorel

#
Hi,

Using the RPostgreSQL driver to access a view on a PostgreSQL 8.4
database:

library(RPostgreSQL)
m <- dbDriver("PostgreSQL")
con <- dbConnect(m, user="me", password="pwd", dbname="dbname")
qry <- "SELECT * FROM mytable"
rs <- dbSendQuery(con, qry)

Fields corresponding to timestamp data type are mapped to POSIXct, as
shown by dbColumnInfo():

        name    Sclass      type len precision scale nullOK
...
...
8  date_time   POSIXct TIMESTAMP   8        -1    -1   TRUE

I'd like to have a bit more control over this conversion, as it
currently results in the POSIXct object having the time zone of my
locale, whereas I need to set it to GMT.  Reading the DBI manual, I
can't see how this could be done.  Any pointers would be appreciated.
Thanks.


Cheers,
#
On Tue, 12 Jan 2010, Sebastian P. Luque wrote:

            
Not really: POSIXct times are absolute times: it is when they are 
displayed that you see the locale.  So just add a tzone attribute to 
the result, as in
[1] "2010-01-13 07:07:26 GMT"
[1] "2010-01-12 23:07:26 PST"
[1] "2010-01-13 07:07:26 GMT"

  
    
#
On Wed, 13 Jan 2010 07:09:57 +0000 (GMT),
Prof Brian Ripley <ripley-+7o2aNKnwVPQzY9nttDBhA at public.gmane.org> wrote:
[...]
Does setting tzone=NULL have the same effect as setting it to "GMT", in
that daylight savings are no longer relevant?  This is the only reason I
wanted to set it "GMT", and avoid daylight savings issues that I don't
need to deal with.  Usually I do this starting from a character vector,
as in:

as.POSIXct(strptime("2010-01-13 01:00:00", "%Y-%m-%d %H:%M:%S), tz="GMT")

Thanks,