X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C6B0F52978 for ; Sat, 18 Jun 2005 01:55:15 -0300 (ADT) 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 48711-02 for ; Sat, 18 Jun 2005 04:55:11 +0000 (GMT) Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143]) by svr1.postgresql.org (Postfix) with ESMTP id 44599528E7 for ; Sat, 18 Jun 2005 01:55:10 -0300 (ADT) Received: from [172.16.1.104] grzm [61.197.227.146] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 1.5 $ on Linux via secured & encrypted transport (TLS); Fri, 17 Jun 2005 22:55:10 -0600 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v730) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-docs@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: type casting reference? Date: Sat, 18 Jun 2005 13:55:07 +0900 To: stig erikson X-Mailer: Apple Mail (2.730) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/30 X-Sequence-Number: 3123 On Jun 13, 2005, at 4:39 AM, stig erikson wrote: > hi. > i need to cast from timestamp to seconds (in the form of integer). > > i have a table with a column: > expiretime timestamp > > i have tried the following, it gives errors as below: > SELECT expiretime::float4 AS timeleft FROM table WHERE > something='1234'; > ERROR: cannot cast type timestamp without time zone to real > > SELECT expiretime::text::float4 AS timeleft FROM table WHERE > something='1234'; > ERROR: invalid input syntax for type real: "2005-06-12 > 21:21:24.368082" Are you looking for the timestamp expressed as seconds from the Unix epoch? If so, look at extract(epoch from expiretime). http://www.postgresql.org/docs/7.4/interactive/functions- datetime.html#FUNCTIONS-DATETIME-EXTRACT Michael Glaesemann grzm myrealbox com