Re: type casting reference?

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: stig erikson <stigerikson_nospam_(at)yahoo(dot)se>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: type casting reference?
Date: 2005-06-18 04:55:07
Message-ID: FEED76A4-7D3F-4B0E-9EC7-B5153592AE40@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs


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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Christian Robottom Reis 2005-06-21 18:18:32 log_min_duration_statement versus log_statement
Previous Message Bruce Momjian 2005-06-17 16:46:22 Re: NetBSD kernel resource configuration