Custom runtime variables

Started by Scott Baileyalmost 17 years ago6 messagesgeneral
Jump to latest
#1Scott Bailey
artacus@comcast.net

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?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Scott Bailey (#1)
Re: Custom runtime variables

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

#3Scott Bailey
artacus@comcast.net
In reply to: Tom Lane (#2)
Re: Custom runtime variables

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?

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Scott Bailey (#3)
Re: Custom runtime variables

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

Show quoted text

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

#5Andreas Kretschmer
akretschmer@spamfence.net
In reply to: Scott Bailey (#3)
Re: 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)

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�

#6Scott Bailey
artacus@comcast.net
In reply to: Andreas Kretschmer (#5)
Re: Custom runtime variables

----- 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.