From: | "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | checking for the existence of a current_setting ? |
Date: | 2011-05-03 08:07:58 |
Message-ID: | C4DAC901169B624F933534A26ED7DF310861AE8A@JENMAIL01.ad.intershop.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello,
(Postgres 8.3)
I'm misusing the current settings at some places to store session
variables.
The next function retrieve such a variable, or initialized it with a
default value.
It is working as expected but performances are slow due to the exception
block.
Is there a way to make the check more smoothly, i.e. without relying on
the exception ?
maybe some undocumented internal function ?
many thanks,
Marc Mamin
CREATE OR REPLACE FUNCTION public.var_get_check(int,text)
RETURNS text AS
$BODY$
BEGIN
return current_setting('public.' || $2 || pg_backend_pid());
EXCEPTION when undefined_object then
perform set_config ('public.' || $2 || pg_backend_pid(), $1::text,
false);
return $1::text;
END ;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
From | Date | Subject | |
---|---|---|---|
Next Message | Susanne Ebrecht | 2011-05-03 09:12:24 | Re: BINARY and BINARY VARYING datatypes in PostgreSQL |
Previous Message | LaraK | 2011-05-03 07:15:21 | Re: convert in GMT time zone without summer time |