Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AA03847618B for ; Sat, 2 Nov 2002 09:17:18 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id DA98C476117 for ; Sat, 2 Nov 2002 09:17:17 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id gA2EHEhR020170; Sat, 2 Nov 2002 09:17:14 -0500 (EST) To: kenzoid@io.com Cc: pgsql-sql@postgresql.org Subject: Re: Timezone issue with date_part In-reply-to: <20021102065654.GA8564@roark.kenzoid.com> References: <20021102065654.GA8564@roark.kenzoid.com> Comments: In-reply-to Ken Kennedy message dated "Sat, 02 Nov 2002 01:56:54 -0500" Date: Sat, 02 Nov 2002 09:17:14 -0500 Message-ID: <20169.1036246634@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/32 X-Sequence-Number: 10174 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. 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