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 EA1E95521B for ; Wed, 2 Mar 2005 20:07:54 +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 81561-01 for ; Wed, 2 Mar 2005 20:07:52 +0000 (GMT) Received: from mail1.elevating.com (wsip-68-99-77-237.tu.ok.cox.net [68.99.77.237]) by svr1.postgresql.org (Postfix) with ESMTP id 32226562D6 for ; Wed, 2 Mar 2005 20:07:51 +0000 (GMT) Received: from bretsony.brets.elevating.com (bretsony.brets.elevating.com [10.23.0.139]) by mail1.elevating.com (8.11.6/8.11.6) with ESMTP id j22K7kK14134 for ; Wed, 2 Mar 2005 14:07:46 -0600 Subject: Re: definative way to place secs from epoc into timestamp From: Bret Hughes To: postgresql sql list In-Reply-To: <13089.1109793126@sss.pgh.pa.us> References: <1109780719.28180.86.camel@bretsony> <13089.1109793126@sss.pgh.pa.us> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 (1.0.8-9.7x.1) Date: 02 Mar 2005 14:07:46 -0600 Message-Id: <1109794066.27857.100.camel@bretsony> Mime-Version: 1.0 X-Elevating-MailScanner: Found to be clean X-Elevating-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.5, required 5, BAYES_00 -1.50) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/26 X-Sequence-Number: 20505 On Wed, 2005-03-02 at 13:52, Tom Lane wrote: > 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 Thanks for the feed back tom I say that but I could not believe that I have to jump through all those hoops on an insert or update update mytable set (lasttime =(SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second') ) is this what you are saying I need to do? also, what is happening with abstime(982384720)? this works as expected (by me ). Is this a bad idea? I can't believe that all the complicated string manipulation stuff is there but I have to run a subselect to insert a numeric value that I suspect is close to how it is stored anyway. Of course the last part is a WAG. Bret