dbTalk Databases Forums  

8.3 and current_setting() of unset variables. Again

comp.databases.postgresql comp.databases.postgresql


Discuss 8.3 and current_setting() of unset variables. Again in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #31  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: 8.3 and current_setting() of unset variables. Again - 01-15-2008 , 02:16 AM






Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
to access settings petersprc had this solution:

select setting from pg_catalog.pg_settings where name =
'modwork.transaction_id'

but this does not work. The table looks like this:

custom_variable_classes | modwork | | Customized Options

The variable 'transaction_id' is not accessible. How can you
query for the value of the custom variable?

PS: See old question some messages ago.

I can confirm that the variable does not show up in pg_catalog.pg_settings,
but I had ne problem setting and retrieving it with SET and SHOW:

Yes, first setting it, then showing it is no problem for me, too.
But how can I check if the variable was already set? With 8.1.4
I get 'unset' if the variable is not set. With 8.3beta3 I get
an syntax error which can't be caught with plpythonu (inside
a trigger).
I don't know about pl/Python, but you could wrap current_setting() in
a PL/pgSQL function like this:

CREATE FUNCTION get_setting(IN param text, OUT value text)
LANGUAGE plpgsql STABLE STRICT AS
$$BEGIN
SELECT current_setting(param) INTO value;
EXCEPTION
WHEN UNDEFINED_OBJECT THEN
value := NULL;
END;$$;

which you can then use from your code.
It will return NULL if the configuration parameter is unknown or not set.

Yours,
Laurenz Albe


Reply With Quote
  #32  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: 8.3 and current_setting() of unset variables. Again - 01-15-2008 , 02:16 AM






Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
to access settings petersprc had this solution:

select setting from pg_catalog.pg_settings where name =
'modwork.transaction_id'

but this does not work. The table looks like this:

custom_variable_classes | modwork | | Customized Options

The variable 'transaction_id' is not accessible. How can you
query for the value of the custom variable?

PS: See old question some messages ago.

I can confirm that the variable does not show up in pg_catalog.pg_settings,
but I had ne problem setting and retrieving it with SET and SHOW:

Yes, first setting it, then showing it is no problem for me, too.
But how can I check if the variable was already set? With 8.1.4
I get 'unset' if the variable is not set. With 8.3beta3 I get
an syntax error which can't be caught with plpythonu (inside
a trigger).
I don't know about pl/Python, but you could wrap current_setting() in
a PL/pgSQL function like this:

CREATE FUNCTION get_setting(IN param text, OUT value text)
LANGUAGE plpgsql STABLE STRICT AS
$$BEGIN
SELECT current_setting(param) INTO value;
EXCEPTION
WHEN UNDEFINED_OBJECT THEN
value := NULL;
END;$$;

which you can then use from your code.
It will return NULL if the configuration parameter is unknown or not set.

Yours,
Laurenz Albe


Reply With Quote
  #33  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: 8.3 and current_setting() of unset variables. Again - 01-15-2008 , 02:16 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
to access settings petersprc had this solution:

select setting from pg_catalog.pg_settings where name =
'modwork.transaction_id'

but this does not work. The table looks like this:

custom_variable_classes | modwork | | Customized Options

The variable 'transaction_id' is not accessible. How can you
query for the value of the custom variable?

PS: See old question some messages ago.

I can confirm that the variable does not show up in pg_catalog.pg_settings,
but I had ne problem setting and retrieving it with SET and SHOW:

Yes, first setting it, then showing it is no problem for me, too.
But how can I check if the variable was already set? With 8.1.4
I get 'unset' if the variable is not set. With 8.3beta3 I get
an syntax error which can't be caught with plpythonu (inside
a trigger).
I don't know about pl/Python, but you could wrap current_setting() in
a PL/pgSQL function like this:

CREATE FUNCTION get_setting(IN param text, OUT value text)
LANGUAGE plpgsql STABLE STRICT AS
$$BEGIN
SELECT current_setting(param) INTO value;
EXCEPTION
WHEN UNDEFINED_OBJECT THEN
value := NULL;
END;$$;

which you can then use from your code.
It will return NULL if the configuration parameter is unknown or not set.

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.