Setting session global variables

From: Kyle <kyle(at)actarg(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: Jonathan Bartlett <johnnyb6(at)SDF(dot)lonestar(dot)org>
Subject: Setting session global variables
Date: 2001-05-17 14:57:16
Message-ID: 3B03E6CC.6D2A30FE@actarg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> 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';

Attachment Content-Type Size
kyle.vcf text/x-vcard 185 bytes

Browse pgsql-sql by date

  From Date Subject
Next Message Forest Wilkinson 2001-05-18 00:19:52 ON UPDATE CASCADE overhead?
Previous Message George Moga 2001-05-17 14:28:04 Re: how to add an new record from part of an old one