public inbox for [email protected]  
help / color / mirror / Atom feed
type casting reference?
3+ messages / 2 participants
[nested] [flat]

* type casting reference?
@ 2005-06-12 19:39 stig erikson <[email protected]>
  2005-06-15 19:03 ` Re: type casting reference? SOLVED stig erikson <[email protected]>
  2005-06-18 04:55 ` Re: type casting reference? Michael Glaesemann <[email protected]>
  0 siblings, 2 replies; 3+ messages in thread

From: stig erikson @ 2005-06-12 19:39 UTC (permalink / raw)
  To: pgsql-docs

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"


postgresql 7.4.1 (i know, old)

so, my question is simply, where in the docs can i find how i should perform the 
cast?
it would help a lot if there was a table showing which types can be cased into 
which, and possibly an example or two for situations like this, casting from 
timestamp (to timestamp worked right away).

/stig



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: type casting reference? SOLVED
  2005-06-12 19:39 type casting reference? stig erikson <[email protected]>
@ 2005-06-15 19:03 ` stig erikson <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: stig erikson @ 2005-06-15 19:03 UTC (permalink / raw)
  To: pgsql-docs

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"
> 
> 
> postgresql 7.4.1 (i know, old)
> 
> so, my question is simply, where in the docs can i find how i should 
> perform the cast?
> it would help a lot if there was a table showing which types can be 
> cased into which, and possibly an example or two for situations like 
> this, casting from timestamp (to timestamp worked right away).
> 
> /stig

solved my problem this way:

UPDATE table
SET expiretime= cast( ('now'::text)::timestamp+'30 minutes'::interval AS timestamp)
WHERE sessionID='0';



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: type casting reference?
  2005-06-12 19:39 type casting reference? stig erikson <[email protected]>
@ 2005-06-18 04:55 ` Michael Glaesemann <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Glaesemann @ 2005-06-18 04:55 UTC (permalink / raw)
  To: stig erikson <[email protected]>; +Cc: 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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-06-18 04:55 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-12 19:39 type casting reference? stig erikson <[email protected]>
2005-06-15 19:03 ` Re: type casting reference? SOLVED stig erikson <[email protected]>
2005-06-18 04:55 ` Michael Glaesemann <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox