Re: setting and using variables in PSQL ????

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема Re: setting and using variables in PSQL ????
Дата
Msg-id 20071215100200.GA7070@KanotixBox
обсуждение исходный текст
Ответ на setting and using variables in PSQL ????  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Список pgsql-general
Gauthier, Dave <dave.gauthier@intel.com> schrieb:

>
>
> Hi:
>
> At the PSQL prompt, I want to set some variables based upon query results, or
> via static assignment, then insert a record with those values.  Sort of like...

You can use this:

- define in your postgresql.conf:
  custom_variable_classes = 'myvar'

- use within psql:

test=# set myvar.benutzer = 'foo';
SET
test=*# select * from foo;
 id | name
----+------
  1 | foo
  2 | bar
(2 rows)

test=*# select * from foo where name=current_setting('myvar.benutzer');
 id | name
----+------
  1 | foo
(1 row)

test=*# set myvar.benutzer = 'none';
SET
test=*# select * from foo where name=current_setting('myvar.benutzer');
 id | name
----+------
(0 rows)


HTH, 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."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

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

Предыдущее
От: Nathan Wagner
Дата:
Сообщение: Re: setting and using variables in PSQL ????
Следующее
От: rihad
Дата:
Сообщение: increasing checkpoint_timeout?