at time zone question in pl/pgSQL

Started by Heather Graceabout 24 years ago2 messagesgeneral
Jump to latest
#1Heather Grace
heather@radiovoodoo.com

Using postgresql version 7.1

I'm trying to write a simple pl/pgsql function that will return the current time for the given time zone ( i have to deal multiple time zones) . But I don't seem to be using the appropriate syntax. I keep getting an error on the 'at time zone...'

DECLARE
new_time TIMESTAMP;

BEGIN
SELECT INTO new_time now() at time zone 'PST'; /*just hard coding the time zone for now */

return new_time;

END;

The following select statement works from an SQL query:

SELECT now() at time zone 'PST'

and returns the appropriate time.

I have also tried using the following statements:

Set TimeZone to PST;
return now();

but that didn't give me the time for PST, only the default time zone, EST.

thanks in advance,

--heather grace

#2Gregory Wood
gregw@com-stock.com
In reply to: Heather Grace (#1)
Re: at time zone question in pl/pgSQL

I'm trying to write a simple pl/pgsql function that will return the

current time for the given time zone ( i have to deal multiple time zones) .
But I don't seem to be using the appropriate syntax. I keep getting an
error on the 'at time zone...'

DECLARE
new_time TIMESTAMP;
BEGIN
SELECT INTO new_time now() at time zone 'PST'; /*just hard coding the

time zone for now */

return new_time;
END;

Assuming that this is a direct cut and paste, the error would appear to be
that the single quotes around the timezone are not escaped. Try changing
that line to:

SELECT INTO new_time now() at time zone ''PST''; /*just hard coding the
time zone for now */

If that's not it, nevermind :)

Greg