checking for the existence of a current_setting ? - Mailing list pgsql-sql

From Marc Mamin
Subject checking for the existence of a current_setting ?
Date
Msg-id C4DAC901169B624F933534A26ED7DF310861AE8A@JENMAIL01.ad.intershop.net
Whole thread Raw
List 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;

pgsql-sql by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: PLpgSQL variables persistance between several functions calls
Next
From: Susanne Ebrecht
Date:
Subject: Re: BINARY and BINARY VARYING datatypes in PostgreSQL