Re: New function: epoch_to_timestamp... - Mailing list pgsql-hackers

From David Fetter
Subject Re: New function: epoch_to_timestamp...
Date
Msg-id 20030815224115.GZ14335@fetter.org
Whole thread Raw
In response to Re: New function: epoch_to_timestamp...  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: New function: epoch_to_timestamp...
List pgsql-hackers
On Fri, Aug 15, 2003 at 06:57:24AM -0400, Tom Lane wrote:
> David Fetter <david@fetter.org> writes:
> > 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?

> The return type should be timestamptz, which makes the
> transformation timezone-independent.

Do you mean the default one should read as follows, or that the
default one should take params (integer, output_timezone,
input_timezone), or...?

CREATE OR REPLACE FUNCTION epoch_to_timestampz (INTEGER)
RETURNS TIMESTAMPZ AS '
DECLARE   the_sql  TEXT;   the_record RECORD;   the_time TIMESTAMPZ;
BEGIN   the_sql := ''SELECT ''''January 1 1970''''::timestamp + ''''''            || $1            || ''
seconds''''::intervalAS "foo"'';   RAISE NOTICE ''%'', the_sql;   FOR the_record IN EXECUTE the_sql LOOP       the_time
:=the_record.foo;   END LOOP;   RETURN the_time;
 
END;
' LANGUAGE 'plpgsql';

Cheers,
D
-- 
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100    cell: +1 415 235 3778


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] 7.4Beta
Next
From: Jan Wieck
Date:
Subject: Re: [GENERAL] 7.4Beta