Обсуждение: Function `set_config` doesn't work in with query?
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.
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:
>>>>> "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)
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)