From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Script Head <scripthead(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Strugging with NEW and OLD records. |
Date: | 2005-11-23 12:17:57 |
Message-ID: | 43845DF5.4020401@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Script Head wrote:
> I am a newbie to the stored proc. game and this is eating my brain.
The error message is accurate but not useful...
>>CREATE TABLE name(first VARCHAR(32) NULL,last VARCHAR(32) NULL, extra
> VARCHAR(32) NULL );
>
>>CREATE OR REPLACE FUNCTION update_name() RETURNS opaque AS '
> DECLARE
> BEGIN
> NEW.extra:=NEW.first;
> RETURN NEW;
> END;
> ' LANGUAGE 'plpgsql';
>
>>CREATE TRIGGER update_name_extra BEFORE INSERT
> ON name
> EXECUTE PROCEDURE update_name();
The CREATE TRIGGER is the problem...
>>INSERT INTO name(first,last) VALUES('script','head');
>
> ERROR: record "new" is not assigned yet
> DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
> CONTEXT: PL/pgSQL function "update_name" line 4 at assignment
You need to add "FOR EACH ROW" before "EXECUTE PROCEDURE" otherwise you
have a statement-level trigger which doesn't give you access to NEW/OLD.
HTH
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Rick Schumeyer | 2005-11-23 13:55:21 | Re: tsearch2: more than one index per table? |
Previous Message | Martijn van Oosterhout | 2005-11-23 11:40:36 | Re: PREPARE in bash scripts |