Thread: NOTIFY "string" from rule

NOTIFY "string" from rule

From
"Jeff Boes"
Date:
Say my table looks like:

CREATE TABLE foo(status char(5), name char(5));

and I want to have a rule that does this:

CREATE RULE nf_foo AS
ON INSERT TO foo DO
NOTIFY new.status || '_' || new.name;

Any hints? My first attempt was to write a function:

CREATE FUNCTION bar(foo) RETURNS TEXT AS
'SELECT $1.status || ''_'' || $1.name;'
LANGUAGE 'sql';

and then change the last line of the rule to

NOTIFY bar(new);

but no luck. I would like to avoid writing a bunch of rules to process
each combination of 'status' and 'name' (at least they're each a limited
set!).


-- 
Jeff Boes                                             vox 616.226.9550
Database Engineer                                     fax 616.349.9076
Nexcerpt, Inc.                                      jboes@nexcerpt.com


Re: NOTIFY "string" from rule

From
Tom Lane
Date:
"Jeff Boes" <jboes@nexcerpt.com> writes:
> CREATE FUNCTION bar(foo) RETURNS TEXT AS
> 'SELECT $1.status || ''_'' || $1.name;'
> LANGUAGE 'sql';
> and then change the last line of the rule to
> NOTIFY bar(new);
> but no luck.

AFAIK the only way to do NOTIFY with a computed name is to write a
function in plpgsql or pltcl that computes a string 'NOTIFY whatever'
and then EXECUTEs that string.  There's no equivalent functionality
in SQL-language functions.
        regards, tom lane