Tom Lane wrote:
> Guy Rouillier <guyr-ml1@burntmail.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