Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3A644475A71 for ; Sat, 2 Nov 2002 15:55:18 -0500 (EST) Received: from abelard.kenzoid.com (dsl-64-192-97-37.telocity.com [64.192.97.37]) by postgresql.org (Postfix) with ESMTP id 9E23347595A for ; Sat, 2 Nov 2002 15:55:17 -0500 (EST) Received: from roark.kenzoid.com (roark.kenzoid.com [192.168.69.13]) by abelard.kenzoid.com (Postfix) with ESMTP id 2357F30AC; Sat, 2 Nov 2002 15:55:18 -0500 (EST) Received: from kkennedy by roark.kenzoid.com with local (Exim 3.36 #1 (Debian)) id 1885Ip-0002Mq-00; Sat, 02 Nov 2002 15:55:31 -0500 Date: Sat, 2 Nov 2002 15:55:31 -0500 To: Tom Lane Cc: kenzoid@io.com, pgsql-sql@postgresql.org Subject: Re: Timezone issue with date_part Message-ID: <20021102205531.GA8965@roark.kenzoid.com> Reply-To: kenzoid@io.com References: <20021102065654.GA8564@roark.kenzoid.com> <20169.1036246634@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20169.1036246634@sss.pgh.pa.us> User-Agent: Mutt/1.4i From: Ken Kennedy X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/34 X-Sequence-Number: 10176 On Sat, Nov 02, 2002 at 09:17:14AM -0500, Tom Lane wrote: > Ken Kennedy 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