Re: can I define own variables?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: can I define own variables?
Дата
Msg-id 9037.1192238754@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: can I define own variables?  (Sam Mason <sam@samason.me.uk>)
Ответы Re: can I define own variables?  (Guy Rouillier <guyr-ml1@burntmail.com>)
Список pgsql-general
Sam Mason <sam@samason.me.uk> writes:
> On Sat, Oct 13, 2007 at 12:18:45AM +0200, Andreas wrote:
>> can I define connection-global variables within a ODBC connection ?

> You could use a temporary table, keyed on the variable name.  Not
> particularly nice to use, but it works.  You can create accessor
> functions reasonably easily if you want.

Another possibility, if you only need to store and retrieve values
and not do anything especially interesting with them, is to abuse
the "custom GUC variable" facility.  This is meant to provide
placeholder parameter settings for dynamically-loaded extension
modules, but there's nothing stopping you from setting and reading
a variable that in fact will never be used by any extension module.

To do this, you need to set custom_variable_classes in postgresql.conf,
perhaps
    custom_variable_classes = user_vars

and then you can do things like

    SET user_vars.foo = whatever;
    SHOW user_vars.bar;

Of course, this is a hack of the first water, and you should expect
that it might break sometime in the future.  But I don't think we'd
break it without providing some alternative solution.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Sam Mason
Дата:
Сообщение: Re: can I define own variables?
Следующее
От: Ron Peterson
Дата:
Сообщение: convert binary string to datum