Re: Indirect access to NEW or OLD records

From: "Dmitry Koterov" <dmitry(at)koterov(dot)ru>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Indirect access to NEW or OLD records
Date: 2008-09-25 18:56:08
Message-ID: d7df81620809251156x16c59c8br98434105e50e05b0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have tried plperl, but the following sample does not work:

CREATE FUNCTION "extract_field_as_varchar" (rec record, field varchar)
RETURNS varchar AS
$body$
...
$body$
LANGUAGE 'plperl' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

It says "ERROR: plperl functions cannot take type record".

So, I cannot ever create an utility function to call it as:

value := extract_field_as_varchar(NEW, 'field');

Seems I have to write an entire trigger in plperl to access NEW record
indirectly?

On Thu, Sep 25, 2008 at 10:08 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Dmitry Koterov" <dmitry(at)koterov(dot)ru> writes:
>> I have a variable with a field name and want to extract this field
>> value from NEW record:
>
>> DECLARE
>> field VARCHAR = 'some_field';
>> BEGIN
>> ...
>> value := NEW.{field}; -- ???
>> END;
>
>> Is it possible in pl/pgsql?
>
> No. Quite aside from the lack of syntax for that, plpgsql would be
> unhappy if the data type wasn't the same on successive executions.
>
> Use one of the less strongly typed PLs instead. I believe this is
> pretty easy in plperl or pltcl. (Maybe plpython too, but I don't know
> that language.)
>
> regards, tom lane
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michelle Konzack 2008-09-25 18:58:18 Re: Largest PostgreSQL 8.x DB someone is running?
Previous Message Raymond O'Donnell 2008-09-25 18:41:21 Re: My first revoke