Re: pl/pgsql RECORD data type, how to access to the values - Mailing list pgsql-general

From Pavel Stehule
Subject Re: pl/pgsql RECORD data type, how to access to the values
Date
Msg-id 162867790804050105ga14ba5vf32bfc5ac8a987c8@mail.gmail.com
Whole thread Raw
In response to pl/pgsql RECORD data type, how to access to the values  ("Guillaume Bog" <guibog@gmail.com>)
Responses Re: pl/pgsql RECORD data type, how to access to the values  ("Guillaume Bog" <guibog@gmail.com>)
List pgsql-general
Hello

On 05/04/2008, Guillaume Bog <guibog@gmail.com> wrote:
> Hello,
>
> I'm writing a trigger in pl/pgSQL and I'd like to pass one column name as
> argument to the trigger function.
>
> Provided my table has only one column named 'id', I can do easilly
>
> CREATE FUNCTION ft() RETURNS trigger AS $$
>    BEGIN
>   RAISE NOTICE 'It works:%', OLD.id;
>   END
> $$ LANGUAGE plpgsql;
>
> But I'd like to do
>
> CREATE FUNCTION ft() RETURNS trigger AS $$
>   DECLARE
>     col VARCHAR;
>   BEGIN
>     col = TG_ARGV[0]
>     RAISE NOTICE 'This does not works:%', OLD.col
>     RAISE NOTICE 'This also does not works:%', OLD[col]
>   END
>  $$ LANGUAGE plpgsql;
>
> I tried OLD.(col) and other tricks, like "SELECT INTO" or "EXECUTE", and I
> checked the docs.

It's not possible in plpgsql. You have to use plperl, pltcl or plpython.

Regards
Pavel Stehule

>
>

pgsql-general by date:

Previous
From: Thomas Pundt
Date:
Subject: Re: Word boundaries in regular expressions
Next
From: Tomasz Ostrowski
Date:
Subject: Re: simple update queries take a long time - postgres 8.3.1