Is there a way to set a session global variable in PostgreSQL? The only
thing I see are examples of setting config variables.
Not sure if session variables are your best solution, but here's how you implement them:
-- Warning: this defines a global variable in the tcl interpretor. This could
-- crash with other TCL procedures if the same name were used during the same connection.
-- Store a value in a variable. This is helpful for caching values in a transaction
-- Calling sequence: store(variable,value)
create function store(text,text) returns int4 as '
global store_vars
return [set store_vars($1) $2]
' LANGUAGE 'pltcl';
-- Fetch a value from a variable.
-- Calling sequence: recall(variable)
create function recall(text) returns int4 as '
global store_vars
return [subst $store_vars($1)]
' LANGUAGE 'pltcl';