Received: from smtp015.mail.yahoo.com (smtp015.mail.yahoo.com [216.136.173.59]) by postgresql.org (8.11.3/8.11.1) with SMTP id f3QLC9352566 for ; Thu, 26 Apr 2001 17:12:09 -0400 (EDT) (envelope-from janwieck@yahoo.com) Received: from jupiter.us.greatbridge.com (HELO jupiter.jw.home) (65.196.69.55) by smtp.mail.vip.sc5.yahoo.com with SMTP; 26 Apr 2001 21:12:07 -0000 X-Apparently-From: Received: (from janwieck@localhost) by jupiter.jw.home (8.9.3/8.9.3) id QAA04341; Thu, 26 Apr 2001 16:24:18 -0500 From: Jan Wieck Message-Id: <200104262124.QAA04341@jupiter.jw.home> Subject: Re: rules In-Reply-To: <01042617214801.04659@bugs> from =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= at "Apr 26, 2001 05:21:48 pm" To: =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= Date: Thu, 26 Apr 2001 16:24:18 -0500 (EST) CC: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200104/418 X-Sequence-Number: 2780 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