SET feature

Started by PG Bug reporting formover 3 years ago2 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/sql-set.html
Description:

Hi,

I remember in version 9 , to use variable you had to change in the
postgresql.

Today it is easier , just use

SET SESSION myprefix.myvariable = 'whatever'

and all the transactions can use it , it is very useful in some cases, for
example to track the author of a change , you don't need to change all your
java/php/python code , just use a trigger on the table to fill up a column
"change_by"

I've checked the documentation and that feature is not explained at all, not
even in the SET Command.

Hope it helps

Regards,

Sparkx

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: PG Bug reporting form (#1)
Re: SET feature

On Fri, 2022-10-28 at 10:14 +0000, PG Doc comments form wrote:

I remember in version 9 , to use variable you had to change in the
postgresql.

Today it is easier , just use

SET SESSION myprefix.myvariable =  'whatever'

and all the transactions can use it , it is very useful in some cases, for
example to track the author of a change , you don't need to change all your
java/php/python code , just use a trigger on the table to fill up a column
"change_by"

I've checked the documentation and that feature is not explained at all, not
even in the SET Command.

Most people consider this a kind of abuse of what is known as "placeholder parameters",
documented in https://www.postgresql.org/docs/current/runtime-config-custom.html

See for example /messages/by-id/2982579.1662416866@sss.pgh.pa.us

I believe it is a deliberate choice not to advertise that as "session variables",
particularly since there is an improvement in the pipeline:

https://commitfest.postgresql.org/40/1608/

Yours,
Laurenz Albe