Re: Possible trigger bug? function call argument literalised

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>, PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Possible trigger bug? function call argument literalised
Date: 2021-01-03 17:59:57
Message-ID: e5b3b5f5-d6ab-b1f1-6c8e-ee55b6b0159a@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/3/21 9:45 AM, Thiemo Kellner wrote:
>
> Quoting Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
>> Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz> writes:
>>> create trigger CALCULATION_METHOD_BR_IU
>>>    before insert on CALCULATION_METHOD
>>>    for each row
>>>    execute function METHOD_CHECK(current_schema);
>>
>>> Executing such, the string "current_schema" gets literalised, i.e.
>>> single quoted:
>>
>> Yup, per the CREATE TRIGGER documentation [1]:
>>
>>     arguments
>>
>>     An optional comma-separated list of arguments to be provided to the
>>     function when the trigger is executed. The arguments are literal
>>     string constants. Simple names and numeric constants can be written
>>     here, too, but they will all be converted to strings. Please check
>> the
>>     description of the implementation language of the trigger function to
>>     find out how these arguments can be accessed within the function; it
>>     might be different from normal function arguments.
>>
>>> I strongly feel this is a bug,
>>
>> It's operating as designed.  There might be scope for a feature
>> improvement here, but it'd be a far-from-trivial task, with probably
>> a lot of ensuing compatibility breakage.
>>
>
> Oh, thanks! I did not read careful enough. I could not imagine such a
> behaviour to be intentional.
>
> Well, I guess, I can put the correct schema at installation, but would
> have liked to have a more general approach. Furthermore, I think this
> also implies that installation can only be done by psql. :-s

Why not grab the CURRENT_SCHEMA in the function?:

DECLARE
V_COUNT smallint;
C_SCHEMA varchar := CURRENT_SCHEMA;
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thiemo Kellner 2021-01-03 18:27:41 Re: Possible trigger bug? function call argument literalised
Previous Message Demitri Muna 2021-01-03 17:48:54 Re: Getting "could not read block" error when creating an index on a function.