Received: from actarg.com (host25.actarg.com [209.180.91.25] (may be forged)) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4HF31A14960 for ; Thu, 17 May 2001 11:03:01 -0400 (EDT) (envelope-from kyle@actarg.com) Received: from chi.actarg.com (IDENT:root@chi.actarg.com [192.168.2.16]) by actarg.com (8.9.3/8.9.3) with ESMTP id IAA04584; Thu, 17 May 2001 08:57:15 -0600 Received: from actarg.com (IDENT:kyle@localhost [127.0.0.1]) by chi.actarg.com (8.9.3/8.9.3) with ESMTP id IAA02462; Thu, 17 May 2001 08:57:16 -0600 Message-ID: <3B03E6CC.6D2A30FE@actarg.com> Date: Thu, 17 May 2001 08:57:16 -0600 From: Kyle Organization: Action Target Inc. X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: Jonathan Bartlett Subject: Setting session global variables References: <200105170129.f4H1TZA95638@postgresql.org> Content-Type: multipart/mixed; boundary="------------104AE9C05248F4DDAE0371ED" X-Archive-Number: 200105/185 X-Sequence-Number: 3002 This is a multi-part message in MIME format. --------------104AE9C05248F4DDAE0371ED Content-Type: multipart/alternative; boundary="------------98BFF9032669BD444D5DA54D" --------------98BFF9032669BD444D5DA54D Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > > 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'; --------------98BFF9032669BD444D5DA54D Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit
 
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';
 
  --------------98BFF9032669BD444D5DA54D-- --------------104AE9C05248F4DDAE0371ED Content-Type: text/x-vcard; charset=us-ascii; name="kyle.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Kyle Content-Disposition: attachment; filename="kyle.vcf" begin:vcard n:Bateman;Kyle x-mozilla-html:FALSE org:Action Target Inc. adr:;;;;;; version:2.1 email;internet:kyle@actarg.com title:President x-mozilla-cpt:;0 fn:Kyle Bateman end:vcard --------------104AE9C05248F4DDAE0371ED--