setting time zone in a function - Mailing list pgsql-general

From Steve Rogerson
Subject setting time zone in a function
Date
Msg-id 5718B30D.4050103@yewtc.demon.co.uk
Whole thread Raw
Responses Re: setting time zone in a function
List 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


pgsql-general by date:

Previous
From: Bráulio Bhavamitra
Date:
Subject: Columnar store as default for PostgreSQL 10?
Next
From: Francisco Olarte
Date:
Subject: Re: Columnar store as default for PostgreSQL 10?