Re: bug in date_part() function in 6.5.2, 7.0.2 - Mailing list pgsql-bugs

From Thomas Lockhart
Subject Re: bug in date_part() function in 6.5.2, 7.0.2
Date
Msg-id 39B730AF.BBEC447E@alumni.caltech.edu
Whole thread Raw
In response to Re: bug in date_part() function in 6.5.2, 7.0.2  (Karel Zak <zakkr@zf.jcu.cz>)
Responses Re: bug in date_part() function in 6.5.2, 7.0.2  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
> >  ....it's not date_part() bug, it's to_date() bug:
> Looks to me like an off-by-one kind of problem in deciding which
> timezone applies to midnight of a transition day.

Probably a bit worse (but no problem to solve ;): you need to make sure
that you rotate the date type to the correct time zone when you do the
conversion to timestamp. If you just blast the yy/mm/dd into the time
structure, leaving the time zone fields zero'd out, then you will be
doing the conversion in UTC. When the timestamp is read back out it is
converted to your local time zone.

The date->timestamp conversion code gets this right, so you might want
to look at that. From my testing, the only annoying case is for 02:00 on
the day of a DST transition, when you either skip or get an extra hour.

If you still have trouble, I'd be happy to look at your code...

                    - Thomas

pgsql-bugs by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Possible bug in referential integrity system
Next
From: Tom Lane
Date:
Subject: Re: bug in date_part() function in 6.5.2, 7.0.2