pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function `set_config` doesn't work in with query?
4+ messages / 3 participants
[nested] [flat]

* Function `set_config` doesn't work in with query?
@ 2019-01-04 09:36  Zexuan Luo <spacewanderlzx@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Zexuan Luo @ 2019-01-04 09:36 UTC (permalink / raw)
  To: pgsql-general

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.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Function `set_config` doesn't work in with query?
@ 2019-01-04 10:18  Rene Romero Benavides <rene.romero.b@gmail.com>
  parent: Zexuan Luo <spacewanderlzx@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Rene Romero Benavides @ 2019-01-04 10:18 UTC (permalink / raw)
  To: Zexuan Luo <spacewanderlzx@gmail.com>; +Cc: pgsql-general

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/

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Function `set_config` doesn't work in with query?
@ 2019-01-04 10:27  Andrew Gierth <andrew@tao11.riddles.org.uk>
  parent: Zexuan Luo <spacewanderlzx@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Andrew Gierth @ 2019-01-04 10:27 UTC (permalink / raw)
  To: Zexuan Luo <spacewanderlzx@gmail.com>; +Cc: pgsql-general

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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Function `set_config` doesn't work in with query?
@ 2019-01-04 10:57  Zexuan Luo <spacewanderlzx@gmail.com>
  parent: Andrew Gierth <andrew@tao11.riddles.org.uk>
  0 siblings, 0 replies; 4+ messages in thread

From: Zexuan Luo @ 2019-01-04 10:57 UTC (permalink / raw)
  To: Andrew Gierth <andrew@tao11.riddles.org.uk>; +Cc: pgsql-general

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)




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2019-01-04 10:57 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04 09:36 Function `set_config` doesn't work in with query? Zexuan Luo <spacewanderlzx@gmail.com>
2019-01-04 10:18 ` Rene Romero Benavides <rene.romero.b@gmail.com>
2019-01-04 10:27 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2019-01-04 10:57   ` Zexuan Luo <spacewanderlzx@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox