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

Rule won't let me NOTIFY, no matter how hard I try

From: Jeff Boes <jboes(at)nexcerpt(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Rule won't let me NOTIFY, no matter how hard I try
Date: 2004-01-13 21:07:45
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Here's the setup: I wanted to write a rule that would fire on an update 
to one table, and do an update to another table, followed by a notify. 
My first attempt wasn't acceptable to PG (7.3.4):

create rule "my_rule" as
on update to table_A
where new.col_A != old.col_A
   (update table_B ...;
    notify "my_signal";

... because you can't have a "notify" statement in a rule that fires on 
update (only select, update, and delete, I guess).

Second attempt was to "hide" the notify in a function:

create function fn_notify(TEXT) returns VOID as '
  execute ''notify " || $1 || "'';
' language 'plpgsql';

Oddly enough, this works IF and ONLY IF the rule "my_rule" fires and the 
internal update statement does not update any rows. If it actually 
updates a row, then I get this error:

WARNING:  plpgsql: ERROR during compile of fn_notify near line 5
ERROR:  syntax error at or near ""

What gives? Must I use a trigger to get around this?

Jeff Boes                                      vox 269.226.9550 ext 24
Database Engineer                                     fax 269.349.9076
Nexcerpt, Inc.                       
            ...Nexcerpt... Extend your Expertise


pgsql-sql by date

Next:From: StefDate: 2004-01-13 21:40:57
Subject: Historical logging of pg_stat_activity ?
Previous:From: Peter EisentrautDate: 2004-01-13 19:36:03
Subject: Re: Configure issues

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