Re: Cast: timestamp to integer

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Michal Durys <joe(at)anime(dot)com(dot)pl>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Cast: timestamp to integer
Date: 2003-06-12 18:05:05
Message-ID: 20030612110321.R31475-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 12 Jun 2003, Michal Durys wrote:

> Hello,
>
> I hope it's not a question for psql-novice. ;-)
>
> I'd like to convert timestamp and date fields to intergers.
> Unfortunately cast() says it's impossible:
>
> ERROR: Cannot cast type date to integer
> ERROR: Cannot cast type timestamp without time zone to integer
>
> I'm quite sure it should be possible somehow. After all timestamp is
> (AFAIR) number of seconds counted from 1970.

I believe EXTRACT has an "epoch" unit that is seconds from 1970 as a
double which you can cast to an int.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2003-06-12 18:23:15 Re: LAST_INSERT_ID equivalent
Previous Message Ian Harding 2003-06-12 17:57:47 Re: Postgres performance comments from a MySQL user