Re: New function: epoch_to_timestamp...

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "David Fetter" <david(at)fetter(dot)org>, "PG Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: New function: epoch_to_timestamp...
Date: 2003-08-15 02:12:25
Message-ID: 238001c362d2$ac61ca50$2800a8c0@mars
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

You can actually kinda hack this by going:

SELECT 41235125::abstime::timestamp;

Where 41235125 is a unix epoch.

Cheers,

Chris

----- Original Message -----
From: "David Fetter" <david(at)fetter(dot)org>
To: "PG Hackers" <pgsql-hackers(at)postgresql(dot)org>
Sent: Friday, August 15, 2003 4:46 AM
Subject: [HACKERS] New function: epoch_to_timestamp...

> Kind people,
>
> After discussing this w/Josh yesterday, I'd like to propose a new
> function for date_time. Here's the Pl/PgSQL version, warts 'n' all.
>
> CREATE OR REPLACE FUNCTION epoch_to_timestamp (INTEGER)
> RETURNS TIMESTAMP AS '
> DECLARE
> the_sql TEXT;
> the_record RECORD;
> the_time TIMESTAMP;
> BEGIN
> the_sql := ''SELECT ''''January 1 1970''''::timestamp + ''''''
> || $1
> || '' seconds''''::interval AS "foo"'';
> FOR the_record IN EXECUTE the_sql LOOP
> the_time := the_record.foo;
> END LOOP;
> RETURN the_time;
> END;
> ' LANGUAGE 'plpgsql';
>
> My C skills (Hello, world!) aren't up to doing it that way, although
> that's probably The Right Thing(TM). Is there a reasonable way to add
> an optional param or two to mark time zones, or should that just the
> application programmer's hassle?
>
> TIA for any feedback :)
>
> Cheers,
> D
> --
> David Fetter david(at)fetter(dot)org http://fetter.org/
> phone: +1 510 893 6100 cell: +1 415 235 3778
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Christopher Kings-Lynne 2003-08-15 02:14:59 Re: [GENERAL] 7.4Beta
Previous Message Bruce Momjian 2003-08-15 00:41:52 Re: 7.4 beta 1 getting out of swap