Strugging with NEW and OLD records.

From: Script Head <scripthead(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Strugging with NEW and OLD records.
Date: 2005-11-23 07:48:45
Message-ID: 451eb55c0511222348o33bbd5dbq785e1f6dc09ab7db@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am a newbie to the stored proc. game and this is eating my brain.

> 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();

> 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

What am I doing wrong?

ScriptHead

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2005-11-23 07:57:26 Re: tsearch2: more than one index per table?
Previous Message Teodor Sigaev 2005-11-23 07:36:45 Re: tsearch2: more than one index per table?