Re: Insert rule and seqences - Mailing list pgsql-novice

From Bo Lorentsen
Subject Re: Insert rule and seqences
Date
Msg-id 3B948D76.53D1744A@netgroup.dk
Whole thread Raw
In response to Insert rule and seqences  (Bo Lorentsen <bl@netgroup.dk>)
List pgsql-novice
Jochem van Dieten wrote:

> I wouldn't use a RULE but a TRIGGER. Something like the one below
> (please check syntax ;) ).

Thanks, this works perfect for me now.

Is it correct that this is not possible to do when using pure "language 'sql'"
? As this language type can't refere to the "new" attribute.

> CREATE TRIGGER tr_insert_on_a AFTER INSERT OR UPDATE ON A
> FOR EACH ROW EXECUTE PROCEDURE fn_insert_on_a();
>
> CREATE function fn_insert_on_a() RETURNS OPAQUE AS '
>      BEGIN
>          INSERT INTO B name, a_ref VALUES(NEW.name, NEW.id);
>      END;
> ' LANGUAGE 'plpgsql';

You only needed the "RETURN new;" line and this was perfect, thanks.

/BL


pgsql-novice by date:

Previous
From: Bo Lorentsen
Date:
Subject: Re: pl/pgsql recursion/arrays (fwd)
Next
From: Jason Tan
Date:
Subject: Re: pl/pgsql recursion/arrays (fwd)