Re: can I define own variables?

From: Guy Rouillier <guyr-ml1(at)burntmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: can I define own variables?
Date: 2007-10-16 02:25:01
Message-ID: 471420FD.80909@burntmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Guy Rouillier <guyr-ml1(at)burntmail(dot)com> writes:
>> Tom Lane wrote:
>>> Another possibility, if you only need to store and retrieve values
>>> and not do anything especially interesting with them, is to abuse
>>> the "custom GUC variable" facility.
>
>> I've had several occasions when a user-defined variable would have come
>> in handy. What is the scope of user_vars as you've defined them above?
>
> They'd act like any other GUC variable. The scope of a SET would be the
> current connection, but there are other ways to set them with larger scope.

8.2.0 on Windows doesn't like "user_vars" as a value for
custom_variable_classes, but "uservars" is okay.

I set that up, and using the SHOW command returns the set value. I
searched the archives and I couldn't identify a way to retrieve these
values in a trigger function. When I try to execute the following:

CREATE OR REPLACE FUNCTION assign_user_name() RETURNS trigger AS $$
BEGIN
NEW.user_name := (SHOW uservars.user_name);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

it complains:

ERROR: syntax error at or near "uservars"
LINE 1: SELECT (SHOW uservars.user_name)
^
QUERY: SELECT (SHOW uservars.user_name)
CONTEXT: SQL statement in PL/PgSQL function "assign_user_name" near line 2

********** Error **********

ERROR: syntax error at or near "uservars"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "assign_user_name" near line 2

I tried the same with a standard GUC (deadlock_timeout) and got the same
error, so this has nothing to do with custom classes. How can I
retrieve GUCs within a pl/pgsql function? Thanks.

--
Guy Rouillier

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-10-16 03:10:07 Re: can I define own variables?
Previous Message Merlin Moncure 2007-10-16 01:21:53 Re: Convert bytea to Float8