Re: Timezone issue with date_part - Mailing list pgsql-sql

From Tom Lane
Subject Re: Timezone issue with date_part
Date
Msg-id 20169.1036246634@sss.pgh.pa.us
Whole thread Raw
In response to Timezone issue with date_part  (Ken Kennedy <kkennedy@kenzoid.com>)
Responses Re: Timezone issue with date_part  (Ken Kennedy <kkennedy@kenzoid.com>)
Re: Timezone issue with date_part  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
Ken Kennedy <kkennedy@kenzoid.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.

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.

(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.  It's far too easy to shoot
yourself in the foot when working with zoneless timestamps --- usually
in a way that you won't notice until daylight-savings transition time
comes around, or you roll out the app to users in other time zones.)
        regards, tom lane


pgsql-sql by date:

Previous
From: Ken Kennedy
Date:
Subject: Timezone issue with date_part
Next
From: "Alexander M. Pravking"
Date:
Subject: Re: Different size in the DATA directory