pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ken Kennedy <kkennedy@kenzoid.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: kenzoid@io.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Timezone issue with date_part
Date: Sat, 2 Nov 2002 15:55:31 -0500
Message-ID: <20021102205531.GA8965@roark.kenzoid.com> (raw)
In-Reply-To: <20169.1036246634@sss.pgh.pa.us>
References: <20021102065654.GA8564@roark.kenzoid.com>
	<20169.1036246634@sss.pgh.pa.us>

On Sat, Nov 02, 2002 at 09:17:14AM -0500, Tom Lane wrote:
> 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.

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@io.com



view thread (4+ messages)  latest in thread

Message-ID: <20021102205531.GA8965@roark.kenzoid.com>
Permalink:  ../20021102205531.GA8965@roark.kenzoid.com/
Also on:    postgresql.org/message-id/20021102205531.GA8965@roark.kenzoid.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: kkennedy@kenzoid.com, tgl@sss.pgh.pa.us, kenzoid@io.com
  Subject: Re: Timezone issue with date_part
  In-Reply-To: <20021102205531.GA8965@roark.kenzoid.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox