Open GoogleCodeExporter opened 9 years ago
Please don't use sQuote, dQuote in constructing queries. That make incompatible
quotes, for left side of the quote.
Since POSIXct just hold the seconds since the epoch, nothing is stripped.
compare the following two:
as.POSIXct("1997-05-23 00:00:00")
as.POSIXct("1997-05-23 01:00:00")
You should see that the 00:00:00 are not printed. This does not mean anything
is lost. The difference is just how POSIXct are printed and does not relate to
the behavior of RPostgreSQL.
Original comment by tomoa...@kenroku.kanazawa-u.ac.jp
on 23 Jul 2013 at 3:04
See also issue 44
To recover the string with the trailing 00:00:00,
you can try
format(as.POSIXct("1997-05-23"), "%Y-%m-%d %H:%M:%OS")
Original comment by tomoa...@kenroku.kanazawa-u.ac.jp
on 23 Jul 2013 at 8:18
[deleted comment]
Thanks for the reply. I forgot to include: options(useFancyQuotes=FALSE)
which makes dQuote/sQuote output compatible with the query.
Dirk replied to my previous post in StackOverflow:
http://stackoverflow.com/questions/17754635/is-there-a-specific-way-to-handle-ti
mestamp-columns-in-r-when-pulling-data-using
Apparently RPostgreSQL does not handle timestamps without timezone correctly.
However, it does handle timestamps with time zone, which is even better. I
even found some gaps in my dataset which were making my time series irregular.
I think not having timezone was a key part of the issue. When Postgres field
does not account for timezones, and RPostgreSQL reads the field into R, it
throws the timestamp field into a POSIXct vector, which apparently always
expects the values with timezones. It turns out that some values from the
database were incompatible with this expectation. For example, one of the old
db records had "2008-03-09 02:00:00", which is not a valid time value when
using daylight savings, as the clocks went 1 hour forward at that time.
POSIXct simply stripped out the time part of the value and converted it to
"2008-03-09" instead. Since the result from this field is a vector in R, and
all the POSIXct data in the vector needs to have the same format, the format of
all the data was also turned into YYYY-MM-DD.
Original comment by xjosi...@gmail.com
on 23 Jul 2013 at 3:48
An important point is that timestamp without timezone is not defined properly.
No one can determine what time it precisely refers to, without external
information.
So, I don't think there are any correct way.
If daylight savings is the problem, you may simply
try ignoring them.
> Sys.setenv(TZ='UTC')
and then pull the data.
By the way, what time zone combination are you using?
So far, I can not reproduce
"2008-03-09 02:00:00" be treated as invalid and just a day.
Please distinguish string and POSIXct data. POSIXct data is a numeric data and
do not contain the format you mentioned.
> as.POSIXct(c("2008-03-09 00:00:00", "2008-03-09 02:00:00","2008-03-09
03:00:00"),tz='CEST')
[1] "2008-03-09 00:00:00 CEST" "2008-03-09 02:00:00 CEST"
[3] "2008-03-09 03:00:00 CEST"
> as.POSIXct(c("2008-03-09 00:00:00", "2008-03-09 02:00:00","2008-03-09
03:00:00"),tz='CEST')[1]
[1] "2008-03-09 CEST"
> as.POSIXct(c("2008-03-09 00:00:00", "2008-03-09 02:00:00","2008-03-09
03:00:00"),tz='CEST')[2]
[1] "2008-03-09 02:00:00 CEST"
Original comment by tomoa...@kenroku.kanazawa-u.ac.jp
on 24 Jul 2013 at 3:07
Hmmm... I guess that is an important detail I should have included. I'm in NY,
USA, so I'm using the EST/EDT time zone. I wasn't aware of the Sys.env(TZ)
option. Thanks for the tip. Maybe it would be helpful if POSIXct threw an
error for invalid times, instead of converting it to absolute dates. Of
course, this has nothing to do with RPostgreSQL.
Original comment by xjosi...@gmail.com
on 24 Jul 2013 at 6:53
I have the same issue. The datetime column only returns the date portion and
not the time portion. :(
Original comment by howard.s...@formsdirect.net
on 24 Apr 2015 at 6:35
Original issue reported on code.google.com by
xjosi...@gmail.com
on 22 Jul 2013 at 1:09