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

Started by Zexuan Luoover 7 years ago4 messagesgeneral
Jump to latest
#1Zexuan Luo
spacewanderlzx@gmail.com

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.

#2Rene Romero Benavides
rene.romero.b@gmail.com
In reply to: Zexuan Luo (#1)
Re: Function `set_config` doesn't work in with query?

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:
https://dba.stackexchange.com/questions/29961/how-do-i-set-and-get-custom-database-variables

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

#3Andrew Gierth
andrew@tao11.riddles.org.uk
In reply to: Zexuan Luo (#1)
Re: Function `set_config` doesn't work in with query?

"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)

#4Zexuan Luo
spacewanderlzx@gmail.com
In reply to: Andrew Gierth (#3)
Re: Function `set_config` doesn't work in with query?

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写道:

Show quoted text

"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)