Thread: Custom runtime variables

Custom runtime variables

From
Scott Bailey
Date:
I want to be able to change the behavior of some functions based on
custom runtime variables.

I added the following lines to my postgresql.conf file:

custom_variable_classes = 'foo'
foo.name = '1s'

Now if I do "show foo.name" I get '1s'
But it does not show up in show all or in pg_settings.

I didn't find much in the way of documentation. How does one access the
value of foo.name from a plpgsql or sql function?

Also, can the variable be stored in a specific data type or am I stuck
with text?



Re: Custom runtime variables

From
Tom Lane
Date:
Scott Bailey <artacus@comcast.net> writes:
> I added the following lines to my postgresql.conf file:
> custom_variable_classes = 'foo'
> foo.name = '1s'

> Now if I do "show foo.name" I get '1s'
> But it does not show up in show all or in pg_settings.

No, it doesn't.  It should still work in set/show though.

> Also, can the variable be stored in a specific data type or am I stuck
> with text?

There's no data type associated with it.  This is all an artifact of the
fact that this isn't a genuine designed-in feature, but a kluge that
someone shoehorned in.  You should have to declare the variable in some
fashion...

            regards, tom lane

Re: Custom runtime variables

From
Scott Bailey
Date:
> Scott Bailey <artacus@comcast.net> writes:
>> I added the following lines to my postgresql.conf file:
>> custom_variable_classes = 'foo'
>> foo.name = '1s'
>
>> Now if I do "show foo.name" I get '1s'
>> But it does not show up in show all or in pg_settings.
>
> No, it doesn't.  It should still work in set/show though.
>
>> Also, can the variable be stored in a specific data type or am I stuck
>> with text?
>
> There's no data type associated with it.  This is all an artifact of the
> fact that this isn't a genuine designed-in feature, but a kluge that
> someone shoehorned in.  You should have to declare the variable in some
> fashion...
>
>             regards, tom lane

Thanks Tom. So how about accessing it from from plpgsql or sql?

Re: Custom runtime variables

From
Pavel Stehule
Date:
2009/6/26 Scott Bailey <artacus@comcast.net>:
>
>> Scott Bailey <artacus@comcast.net> writes:
>>>
>>> I added the following lines to my postgresql.conf file:
>>> custom_variable_classes = 'foo'
>>> foo.name = '1s'
>>
>>> Now if I do "show foo.name" I get '1s'
>>> But it does not show up in show all or in pg_settings.
>>
>> No, it doesn't.  It should still work in set/show though.
>>
>>> Also, can the variable be stored in a specific data type or am I stuck
>>> with text?
>>
>> There's no data type associated with it.  This is all an artifact of the
>> fact that this isn't a genuine designed-in feature, but a kluge that
>> someone shoehorned in.  You should have to declare the variable in some
>> fashion...
>>
>>                        regards, tom lane
>
> Thanks Tom. So how about accessing it from from plpgsql or sql?


look on http://www.postgresql.org/docs/8.3/interactive/functions-admin.html#FUNCTIONS-ADMIN-SET-TABLE

regards
Pavel Stehule

>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Re: Custom runtime variables

From
Andreas Kretschmer
Date:
Scott Bailey <artacus@comcast.net> wrote:

> Thanks Tom. So how about accessing it from from plpgsql or sql?

test=# select * from current_setting('myvar.foo');
 current_setting
-----------------

(1 Zeile)

Zeit: 0,163 ms
test=*#
test=*# set myvar.foo='bla';
SET
Zeit: 0,117 ms
test=*# select * from current_setting('myvar.foo');
 current_setting
-----------------
 bla
(1 Zeile)



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Custom runtime variables

From
artacus@comcast.net
Date:

----- Original Message -----
From: "Andreas Kretschmer" <akretschmer@spamfence.net>
To: pgsql-general@postgresql.org
Sent: Friday, June 26, 2009 1:58:08 AM GMT -08:00 US/Canada Pacific
Subject: Re: [GENERAL] Custom runtime variables

Scott Bailey <artacus@comcast.net> wrote:

> Thanks Tom. So how about accessing it from from plpgsql or sql?

test=# select * from current_setting('myvar.foo');
 current_setting
-----------------

(1 Zeile)

Zeit: 0,163 ms
test=*#
test=*# set myvar.foo='bla';
SET
Zeit: 0,117 ms
test=*# select * from current_setting('myvar.foo');
 current_setting
-----------------
 bla
(1 Zeile)


Thanks Pavel and Andreas.