Re: Strange behavior in generate_series(date, date, interval) with DST - Mailing list pgsql-general

From Andrew Sullivan
Subject Re: Strange behavior in generate_series(date, date, interval) with DST
Date
Msg-id 20141208010513.GA21788@crankycanuck.ca
Whole thread Raw
In response to Re: Strange behavior in generate_series(date, date, interval) with DST  (Sérgio Saquetim <sergiosaquetim@gmail.com>)
List pgsql-general
On Sun, Dec 07, 2014 at 08:25:48PM -0200, Sérgio Saquetim wrote:
>
> I wasn't paying attention to the fact that generate_series really expects
> for timezone inputs. So when I was passing the upper bound
> as '2014-10-20'::DATE, the value was being cast to 2014-10-20 00:00:00-02.
>
> postgres=# SELECT '2014-10-20'::TIMESTAMPTZ;
>       timestamptz
> ------------------------
>  2014-10-20 00:00:00-02
> (1 row)

[…]

> Using a larger upper bound solved my problem.

As a more general lesson, I'd suggest that when you're working with
dates your best bet is to do it with your time zone as UTC.  If you
then want to format the output in the local time zone, you can do that
in the outer SELECT with AT TIME ZONE.  This isn't because Postgres is
going to get this wrong, but because it's far too easy to confuse
yourself with those time changes.  It makes debugging easier,
particularly because the time change only happens twice a year so
nobody _ever_ thinks of it when troubleshooting.

Best regards,

A

--
Andrew Sullivan
ajs@crankycanuck.ca


pgsql-general by date:

Previous
From: AJ Welch
Date:
Subject: Re: FW: SQL rolling window without aggregation
Next
From: David G Johnston
Date:
Subject: Re: FW: SQL rolling window without aggregation