Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 17c03b3

Browse files
committed
Revert treatment of NOTIFY in rules to its pre-7.1 behavior: notify will
occur unconditionally, even if the rule should otherwise execute conditionally. This is more useful than giving an error, even though it's not truly the correct behavior. Per today's pghackers discussion.
1 parent 8c55728 commit 17c03b3

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

doc/src/sgml/ref/create_rule.sgml

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.25 2001/09/03 12:57:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.26 2001/09/07 20:52:30 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -249,6 +249,20 @@ SELECT * FROM emp;
249249
</programlisting></para>
250250
</example>
251251
</para>
252+
253+
<para>
254+
Presently, if a rule contains a NOTIFY query, the NOTIFY will be executed
255+
unconditionally --- that is, the NOTIFY will be issued even if there are
256+
not any rows that the rule should apply to. For example, in
257+
<programlisting>
258+
CREATE RULE notify_me AS ON UPDATE TO mytable DO NOTIFY mytable;
259+
260+
UPDATE mytable SET name = 'foo' WHERE id = 42;
261+
</programlisting>
262+
one NOTIFY event will be sent during the UPDATE, whether or not there
263+
are any rows with id = 42. This is an implementation restriction that
264+
may be fixed in future releases.
265+
</para>
252266
</refsect2>
253267
</refsect1>
254268

src/backend/rewrite/rewriteManip.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.57 2001/04/18 20:42:55 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.58 2001/09/07 20:52:31 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -592,15 +592,21 @@ AddQual(Query *parsetree, Node *qual)
592592

593593
if (parsetree->commandType == CMD_UTILITY)
594594
{
595-
596595
/*
597-
* Noplace to put the qual on a utility statement.
596+
* There's noplace to put the qual on a utility statement.
597+
*
598+
* If it's a NOTIFY, silently ignore the qual; this means that the
599+
* NOTIFY will execute, whether or not there are any qualifying rows.
600+
* While clearly wrong, this is much more useful than refusing to
601+
* execute the rule at all, and extra NOTIFY events are harmless for
602+
* typical uses of NOTIFY.
598603
*
599-
* For now, we expect utility stmt to be a NOTIFY, so give a specific
600-
* error message for that case.
604+
* If it isn't a NOTIFY, error out, since unconditional execution
605+
* of other utility stmts is unlikely to be wanted. (This case is
606+
* not currently allowed anyway, but keep the test for safety.)
601607
*/
602608
if (parsetree->utilityStmt && IsA(parsetree->utilityStmt, NotifyStmt))
603-
elog(ERROR, "Conditional NOTIFY is not implemented");
609+
return;
604610
else
605611
elog(ERROR, "Conditional utility statements are not implemented");
606612
}
@@ -634,15 +640,13 @@ AddHavingQual(Query *parsetree, Node *havingQual)
634640

635641
if (parsetree->commandType == CMD_UTILITY)
636642
{
637-
638643
/*
639-
* Noplace to put the qual on a utility statement.
644+
* There's noplace to put the qual on a utility statement.
640645
*
641-
* For now, we expect utility stmt to be a NOTIFY, so give a specific
642-
* error message for that case.
646+
* See comments in AddQual for motivation.
643647
*/
644648
if (parsetree->utilityStmt && IsA(parsetree->utilityStmt, NotifyStmt))
645-
elog(ERROR, "Conditional NOTIFY is not implemented");
649+
return;
646650
else
647651
elog(ERROR, "Conditional utility statements are not implemented");
648652
}

0 commit comments

Comments
 (0)