How to set config param temporarily?

Поиск
Список
Период
Сортировка
От Kynn Jones
Тема How to set config param temporarily?
Дата
Msg-id c2350ba40710161135x1f05f20fh64b85633b25d85e@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to set config param temporarily?
Re: How to set config param temporarily?
Список pgsql-general
I'd like to set some config parameter "temporarily"; i.e. so that the
new setting is active, say, only during the execution of the next SQL
statement.  This is the best I've come up with:

-- first, save the original setting of the parameter
CREATE TEMP TABLE save_config AS
  SELECT setting FROM pg_settings WHERE name = 'some_param';

-- next, set the parameter to its temporary value
SET some_param = 'foobar';

-- ...yadda-yadda

-- restore the original setting
UPDATE pg_settings
   SET setting = ( SELECT * FROM save_config )
 WHERE name = 'some_param';

-- drop the temporary table
DROP TABLE save_config;




Is there a less laborious approach?

The root of needing to go through all this song and dance is that I
don't know of any way to set up a simple temporary variable to hold a
value.  The temporary table is the closest I can come up to
implementing a temporary variable.  Is there a simpler approach?

TIA!

kj

P.S. Even though the code above works, the Update statement prints out

UPDATE 0

at the end.  This makes no sense to me; the condition clearly succeeds
once, since the update in fact happened, as one can easily confirm.
So why the "UPDATE 0" output?

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

Предыдущее
От: Laurent Duperval
Дата:
Сообщение: Re: 8.2.3: Server crashes on Windows using Eclipse/Junit
Следующее
От: Michael Crozier
Дата:
Сообщение: Re: Updating a production database schema from dev server