setting time zone in a function

From: Steve Rogerson <steve(dot)pg(at)yewtc(dot)demon(dot)co(dot)uk>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: setting time zone in a function
Date: 2016-04-21 11:01:33
Message-ID: 5718B30D.4050103@yewtc.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want the time zone if a function a bit like ...

CREATE OR REPLACE FUNCTION
short_name (timestamp with time zone, varchar) RETURNS varchar AS $$
DECLARE
...
BEGIN
SET LOCAL TIME ZONE $2;
SELECT to_char($1, 'TZ')::varchar
...
END $$
LANGUAGE 'plpgsql' VOLATILE;

But as written is doesn't compile complaining about the "naked" $2. If I quote
the $2 it sets the time zone to $2 literally (I didn't know you could do that,
but that's another issue). Escaping the quotes either as \' or '' doesn't compile.

Help.

Steve

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sameer Kumar 2016-04-21 11:56:52 Re: Invalid data read from synchronously replicated hot standby
Previous Message Francisco Olarte 2016-04-21 11:01:32 Re: Columnar store as default for PostgreSQL 10?