Обсуждение: Function `set_config` doesn't work in with query?

Поиск
Список
Период
Сортировка

Function `set_config` doesn't work in with query?

От
Zexuan Luo
Дата:
For instance:
```
with t as (
    select set_config('blah', '1', false)
)
    select current_setting('blah');
select current_setting('blah');
```

Execute queries above gets these error messages:
psql:test-query-dump.sql:4: ERROR:  unrecognized configuration parameter "blah"
psql:test-query-dump.sql:5: ERROR:  unrecognized configuration parameter "blah"

Thank you for any responses.


Re: Function `set_config` doesn't work in with query?

От
Rene Romero Benavides
Дата:

On Fri, Jan 4, 2019 at 3:37 AM Zexuan Luo <spacewanderlzx@gmail.com> wrote:
For instance:
```
with t as (
    select set_config('blah', '1', false)
)
    select current_setting('blah');
select current_setting('blah');
```

Execute queries above gets these error messages:
psql:test-query-dump.sql:4: ERROR:  unrecognized configuration parameter "blah"
psql:test-query-dump.sql:5: ERROR:  unrecognized configuration parameter "blah"

Thank you for any responses.


The only parameters you can set that way, are the ones listed in:
SELECT name FROM pg_settings;

For user defined parameters, check this:

--
El genio es 1% inspiración y 99% transpiración.
Thomas Alva Edison
http://pglearn.blogspot.mx/

Re: Function `set_config` doesn't work in with query?

От
Andrew Gierth
Дата:
>>>>> "Zexuan" == Zexuan Luo <spacewanderlzx@gmail.com> writes:

 Zexuan> For instance:
 Zexuan> ```
 Zexuan> with t as (
 Zexuan>     select set_config('blah', '1', false)
 Zexuan> )
 Zexuan>     select current_setting('blah');

A CTE containing a SELECT query which is not referenced anywhere will
not be executed, even if it contains volatile functions. (CTEs
containing INSERT/UPDATE/DELETE that are not referenced _will_ still be
executed.)

-- 
Andrew (irc:RhodiumToad)


Re: Function `set_config` doesn't work in with query?

От
Zexuan Luo
Дата:
Thank you!

Something like
```
with t as (
    select set_config('ns.blah', '1', false) as res
)
    select res from t;
select current_setting('ns.blah');
```
works for me.

Andrew Gierth <andrew@tao11.riddles.org.uk> 于2019年1月4日周五 下午6:27写道:
>
> >>>>> "Zexuan" == Zexuan Luo <spacewanderlzx@gmail.com> writes:
>
>  Zexuan> For instance:
>  Zexuan> ```
>  Zexuan> with t as (
>  Zexuan>     select set_config('blah', '1', false)
>  Zexuan> )
>  Zexuan>     select current_setting('blah');
>
> A CTE containing a SELECT query which is not referenced anywhere will
> not be executed, even if it contains volatile functions. (CTEs
> containing INSERT/UPDATE/DELETE that are not referenced _will_ still be
> executed.)
>
> --
> Andrew (irc:RhodiumToad)