Re: Timezone issue with date_part

From: Ken Kennedy <kkennedy(at)kenzoid(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: kenzoid(at)io(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Timezone issue with date_part
Date: 2002-11-02 20:55:31
Message-ID: 20021102205531.GA8965@roark.kenzoid.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Nov 02, 2002 at 09:17:14AM -0500, Tom Lane wrote:
> Ken Kennedy <kkennedy(at)kenzoid(dot)com> writes:
> > [ date_part('epoch') is wrong for a timestamp value ]
>
> The epoch value is really only correct for a TIMESTAMP WITH TIME ZONE
> value. If you apply date_part('epoch') to a timestamp without time zone,
> as you appear to be doing here, what you will get is the epoch for the
> given value interpreted as GMT.

Excellent! I see. The table is indeed using TIMESTAMP WITHOUT TIME
ZONE. (It is, in fact, an old 'datetime' hold-on in the table creation
DDL.) Hopefully, I can alter that sucker in place...it'll help for
upgrade scripts.

> A hack solution is to cast the value to TIMESTAMP WITH TIME ZONE before
> extracting the epoch; the cast will assume that the given value is local
> time. But a better idea is to store the column as TIMESTAMP WITH TIME
> ZONE in the first place.

Gotcha. I've confirmed the hack solution is working for now, and
eliminates my even hackier (more hackish?) two-call solution. I'll get
with the package owner (this is in an OpenACS package) and we'll work
out an upgrade for the table and procs.

> (IMHO, the SQL spec is really brain-dead to define timestamp without
> time zone as the default form of timestamp; the variant with time zone
> is much more useful for most applications.

I see exactly what you're saying now. I guess that's the reason
datetime resolves to 'TIMESTAMP WITHOUT TIME ZONE'? I agree...the TZ
is very useful to have tagging along!

Thanks so much for your help, Tom!

--

Ken Kennedy | http://www.kenzoid.com | kenzoid(at)io(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2002-11-02 21:21:44 Re: Timezone issue with date_part
Previous Message Alexander M. Pravking 2002-11-02 14:33:35 Re: Different size in the DATA directory