Skip site navigation (1) Skip section navigation (2)

Re: Insert rule and seqences

From: Bo Lorentsen <bl(at)netgroup(dot)dk>
To: Jochem van Dieten <jochemd(at)oli(dot)tudelft(dot)nl>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Insert rule and seqences
Date: 2001-09-04 08:14:46
Message-ID: 3B948D76.53D1744A@netgroup.dk (view raw or flat)
Thread:
Lists: 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


In response to

pgsql-novice by date

Next:From: Jason TanDate: 2001-09-04 09:19:04
Subject: Re: pl/pgsql recursion/arrays (fwd)
Previous:From: Bo LorentsenDate: 2001-09-04 08:00:43
Subject: Re: pl/pgsql recursion/arrays (fwd)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group