X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1476755FF8 for ; Wed, 2 Mar 2005 19:52:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74783-07 for ; Wed, 2 Mar 2005 19:52:08 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id A8E855521B for ; Wed, 2 Mar 2005 19:52:06 +0000 (GMT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j22Jq66x013090; Wed, 2 Mar 2005 14:52:06 -0500 (EST) To: Bret Hughes Cc: postgresql sql list Subject: Re: definative way to place secs from epoc into timestamp column In-reply-to: <1109780719.28180.86.camel@bretsony> References: <1109780719.28180.86.camel@bretsony> Comments: In-reply-to Bret Hughes message dated "02 Mar 2005 10:25:17 -0600" Date: Wed, 02 Mar 2005 14:52:06 -0500 Message-ID: <13089.1109793126@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/25 X-Sequence-Number: 20504 Bret Hughes writes: > I give up. I have STFW and STFM and still do not feel like I have a > good way to update/insert into a timestamp w/o TZ column with an integer > representing seconds from epoch. The docs say: Here is how you can convert an epoch value back to a time stamp: SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second'; If you want a timestamp w/o time zone then the right thing depends on what you think the reference epoch is. If you do SELECT TIMESTAMP WITHOUT TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second'; then what you will get is the correct equivalent of the Unix timestamp in GMT time. If you do the first calculation and then cast to timestamp w/o time zone then what you will get is a correct equivalent in your TimeZone setting. For instance regression=# show timezone; TimeZone ---------- EST5EDT (1 row) regression=# SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second'; ?column? ------------------------ 2001-02-16 23:38:40-05 (1 row) regression=# SELECT TIMESTAMP WITHOUT TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second'; ?column? --------------------- 2001-02-17 04:38:40 (1 row) regression=# SELECT (TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second')::timestamp without time zone; timestamp --------------------- 2001-02-16 23:38:40 (1 row) regards, tom lane