to_char(timestamp, 'SSSS') has a Daylight Savings bug. It includes the
missing 2am hour in it's "seconds from midnight count" for DST begin day
(4/6/2003), and does not include the extra hour for DST end day
(10/26/2003).
both seconds1 and seconds2 below should be 7200. Note 4/6/2003 is start of
daylight savings for MST7MDT.
select '4/6/2003 3:00:00'::timestamp,
'4/6/2003 00:00:00'::timestamp,
to_char('4/6/2003 3:00:00'::timestamp,'SSSS') AS seconds1,
trunc(extract(epoch from '4/6/2003 3:00:00'::timestamp)-
extract(epoch from '4/6/2003 00:00:00'::timestamp)) AS
seconds2;
timestamptz | timestamptz | seconds1 | seconds2
------------------------+------------------------+----------+----------
2003-04-06 03:00:00-06 | 2003-04-06 00:00:00-07 | 10800 | 7200
(1 row)
Included explicit TZ info, gives the same.
select '4/6/2003 3:00:00 MDT'::timestamp,
'4/6/2003 00:00:00 MST'::timestamp,
to_char('4/6/2003 3:00:00 MDT'::timestamp,'SSSS') AS seconds1,
trunc(extract(epoch from '4/6/2003 3:00:00 MDT'::timestamp)-
extract(epoch from '4/6/2003 00:00:00 MST'::timestamp)) AS
seconds2;
timestamptz | timestamptz | seconds1 | seconds2
------------------------+------------------------+----------+----------
2003-04-06 03:00:00-06 | 2003-04-06 00:00:00-07 | 10800 | 7200
(1 row)
VERSION
% psql -V
psql (PostgreSQL) 7.2.3