From: Jan Wieck <JanWieck@Yahoo.com>
To: Martín Marqués <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: rules
Date: Thu, 26 Apr 2001 16:24:18 -0500 (EST)
Message-ID: <200104262124.QAA04341@jupiter.jw.home> (raw)
In-Reply-To: <01042617214801.04659@bugs>
Martín Marqués wrote:
> Is it posible to make a rule execute more then one query?
>
> Something like:
>
> CREATE RULE rule_name AS ON INSERT TO table1
> DO INSTEAD
> INSERT INTO table2 VALUES
> (new.value1,new.value2)
> INSERT INTO table3 VALUES
> (x,y)
Yes:
CREATE RULE rule_name AS ON INSERT TO table1
DO INSTEAD (
INSERT INTO table2 VALUES
(new.value1,new.value2);
INSERT INTO table3 VALUES
(x,y);
);
You just omitted the parens and semicoli :-)
>
> If not, is there a way to do this? Triggers maybe?
Triggers too (even if yes above and effectively you haven't
asked for):
CREATE FUNCTION whatever () RETURNS opaque AS '
BEGIN
INSERT INTO table2 VALUES
(new.value1,new.value2);
INSERT INTO table3 VALUES
(...);
RETURN NULL; -- returning NULL from a BEFORE trigger
-- suppresses the triggering INSERT to
-- happen.
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER table1_ins BEFORE INSERT ON table1
FOR EACH ROW EXECUTE whatever();
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: JanWieck@Yahoo.com, martin@bugs.unl.edu.ar
Subject: Re: rules
In-Reply-To: <200104262124.QAA04341@jupiter.jw.home>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox