Re: Timestamp with timezone question.

From: Andrew - Supernews <andrew+nonews(at)supernews(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Timestamp with timezone question.
Date: 2005-02-21 15:36:58
Message-ID: slrnd1k00q.1ofc.andrew+nonews@trinity.supernews.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 2005-02-21, Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> wrote:
> Consider a schema designed to store internet mail.
>
> Since pgsql always converts a timestamptz to UTC, we have lost
> the information of the Sender's local timezone.
>
> Should i go with a separete date and timetz ?

No. Consider instead storing a timestamptz with the actual time of the
mail, and a separate field with an interval representing the zone offset.
Then you can use AT TIME ZONE to recover the sender's local time.

e.g. (this table has columns serial, timestamptz, interval)

insert into dtz values (DEFAULT,
'2005-03-21 07:05:00 -0800',
'2005-03-21 07:05:00 -0800'::timestamp
- '2005-03-21 07:05:00 -0800'::timestamptz at time zone 'UTC'
);

(the timestamp - timestamptz thing is just a reasonably reliable way of
getting the timezone offset without complicated parsing.)

select * from dtz;
id | t | z
----+------------------------+-----------
1 | 2005-03-21 15:05:00+00 | -08:00:00
(1 row)

select *, t at time zone z as ot from dtz;
id | t | z | ot
----+------------------------+-----------+---------------------
1 | 2005-03-21 15:05:00+00 | -08:00:00 | 2005-03-21 07:05:00
(1 row)

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2005-02-21 16:44:04 Re: Timestamp with timezone question.
Previous Message George Weaver 2005-02-21 14:55:39 Re: Working with XML.