From: | François Beausoleil <francois(at)teksol(dot)info> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
Cc: | Robert James <srobertjames(at)gmail(dot)com>, Steve Crawford <scrawford(at)pinpointresearch(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Understanding TIMESTAMP WITH TIME ZONE |
Date: | 2013-01-21 04:12:20 |
Message-ID: | BC5AD6F2-4EC5-4830-B6A7-A61A65076CC5@teksol.info |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Le 2013-01-20 à 20:04, Adrian Klaver a écrit :
> On 01/20/2013 04:28 PM, Robert James wrote:
>> On 1/18/13, Steve Crawford <scrawford(at)pinpointresearch(dot)com> wrote:
>>
>> I'm confused. If I make sure to use UTC, isn't timestamp without time
>> zone identical, then? If not, what is the difference?
>>
>
> Realized my previous explanation could be better. The primary difference is that when you use WITH TIME ZONE Postgres stores the date/time as UTC and knows it has done so. If you use WITHOUT TIME ZONE it does not. For purposes of comparison it then makes the assumption the WITHOUT date/time data is whatever is set for local time. In the situation you describe above you would need to either set local time at UTC or use AT TIME ZONE to make the correction.
I was curious as well, and I thank you for the clarification.
On my servers, TZ is set to Etc/UTC. I use exclusively use WITHOUT TIME ZONE, and in my queries, I use AT TIME ZONE to translate first to UTC, then to the needed time zone (America/Montreal for instance). That means I could save a call per row, and have queries run a bit faster. I'm talking about 1M rows or more per day.
Since TZ is set to Etc/UTC, a simple ALTER TABLE should translate everything in a single run?
ALTER TABLE x
ALTER COLUMN created_at
SET TYPE TIMESTAMP WITH TIME ZONE WITH (created_at AT TIME ZONE 'Etc/UTC');
Is that expected to be a long operation? Do I even need the WITH clause? PG should assume (correctly in this case) that the conversion is to UTC.
Thanks!
François Beausoleil
> --
> Adrian Klaver
> adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | François Beausoleil | 2013-01-21 04:19:44 | Re: pg_Restore |
Previous Message | bhanu udaya | 2013-01-21 04:10:08 | Re: pg_Restore |