X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 310A2D1B44A for ; Thu, 15 Jan 2004 18:36:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 41972-04 for ; Thu, 15 Jan 2004 14:35:36 -0400 (AST) Received: from camel.luzyfuerza.org.ar (sfe194.is.net.ar [200.0.209.194]) by svr1.postgresql.org (Postfix) with SMTP id 7D6BFD1B458 for ; Thu, 15 Jan 2004 14:35:27 -0400 (AST) Received: (qmail 13757 invoked from network); 15 Jan 2004 18:35:05 -0000 Received: from unknown (HELO lcf.luzyfuerza.org.ar) (10.7.17.3) by www.luzyfuerza.org with SMTP; 15 Jan 2004 18:35:05 -0000 From: "Luis C. Ferreira" To: Jeff Boes , pgsql-sql@postgresql.org Subject: Re: Rule won't let me NOTIFY, no matter how hard I try Date: Thu, 15 Jan 2004 15:34:39 -0300 User-Agent: KMail/1.5 References: <2d8491964a9d65324f083494a9f54f8b@news.teranews.com> In-Reply-To: <2d8491964a9d65324f083494a9f54f8b@news.teranews.com> De: Mime (headers) MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-Disposition: inline Message-Id: <200401151534.39772@tu.numero.de.suerte.17> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/129 X-Sequence-Number: 16522 El Mar 13 Ene 2004 18:07, Jeff Boes escribió: >JB: Here's the setup: I wanted to write a rule that would fire on an update >JB: to one table, and do an update to another table, followed by a notify. >JB: My first attempt wasn't acceptable to PG (7.3.4): >JB: >JB: create rule "my_rule" as >JB: on update to table_A >JB: where new.col_A != old.col_A >JB: do >JB: (update table_B ...; >JB: notify "my_signal"; >JB: ); >JB: >JB: ... because you can't have a "notify" statement in a rule that fires on >JB: update (only select, update, and delete, I guess). >JB: hi, you have to write to rules first one (update): create rule "my_rule" as on update to table_A where new.col_A != old.col_A do update table_B ...; second one (notify): create rule "my_rule2" as on update to table_A notify my_rule; >JB: Second attempt was to "hide" the notify in a function: >JB: >JB: create function fn_notify(TEXT) returns VOID as ' >JB: execute ''notify " || $1 || "''; >JB: ' language 'plpgsql'; The correct syntax... create function fn_notify ( text ) RETURNS void as ' declare v_signal alias for $1; begin execute '' notify "'' || v_signal || ''"''; return; end; ' language 'plpgsql'; ...and re-write the first rule create rule "my_rule" as on update to table_A where new.col_A != old.col_A do ( update table_B ...; SELECT fn_notify('my_signal'); ); CAVEAT: This rule always returns a tuple: fn_notify ----------- (1 row) -- --------------------------------------------------------------- Luis Carlos Ferreira lcf@tuxedo.com.ar Centro de Cómputos Junin 2957 - Santa Fe - Argentina Sindicato de Luz y Fuerza Tel.: (54)(342) 4520-075 --------------------------------------------------------------- Estas loco? come vaca!!