Re: pl/pgsql NEW variable substitution - Mailing list pgsql-general

From Jim Nasby
Subject Re: pl/pgsql NEW variable substitution
Date
Msg-id DBFF058F-07B8-49C4-9776-2B5F85E43FEA@decibel.org
Whole thread Raw
In response to pl/pgsql NEW variable substitution  (jef peeraer <jef.peeraer@telenet.be>)
List pgsql-general
On Sep 27, 2006, at 6:16 AM, jef peeraer wrote:
> i want to check in a trigger if certain columns are not left empty.
> The columns i have to check are stored in another table. How do i
> do the following
>
> BEGIN
>     SELECT INTO col_record * FROM modules WHERE type_module_id =
> NEW.type_module_id AND is_afsluit_kolom;
>     IF NOT FOUND THEN
>         RAISE EXCEPTION 'geen afsluitkolom gedefinieerd voor type_module
> % ', NEW.type_module_id;
>     ELSE
>         col_naam := col_record.kolom_naam;
>         RAISE NOTICE 'kolom to check is % ', col_naam;
>         --- check if afsluitrecord is empty
>         IF NEW.col_naam != '' THEN
>             RETURN NEW;
>         ELSE
>             RAISE EXCEPTION 'dit record is afgesloten voor wijzigingen !';
>         END IF;
>      END IF;
> END;
>
>
> I want col_naam to be evaluated before used with NEW . Now i get a
> warning that the table the trigger is written for doesn't has a
> column 'col_naam'.

Try http://www.postgresql.org/docs/8.1/interactive/plpgsql-
statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN, though I'm not sure
if it'll work with NEW.
--
Jim Nasby                                            jim@nasby.net
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)



pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: Restart after power outage: createdb
Next
From: Rafal Pietrak
Date:
Subject: postgress 8.1.4 deadlocking??