RULE does not like the NOT EXISTS condition - Mailing list pgsql-hackers

From Szima Gábor
Subject RULE does not like the NOT EXISTS condition
Date
Msg-id alpine.LSU.2.03.1809081705070.1822@tesla.hu
Whole thread Raw
List pgsql-hackers
Hi!

I found an "interest" in RULE's operation:

CREATE TABLE ruletest (id int4);
CREATE TABLE rulelog (id int4, ts timestamp NOT NULL DEFAULT current_timestamp);

CREATE RULE ruletest_rule AS ON INSERT TO ruletest DO INSERT INTO rulelog (id) VALUES (NEW.id);

INSERT INTO ruletest (id) VALUES (1);
INSERT INTO ruletest (id) SELECT 2 WHERE NOT EXISTS (SELECT 1 FROM ruletest WHERE id=2);
INSERT INTO ruletest (id) SELECT 3;

SELECT * FROM ruletest;
SELECT * FROM rulelog;

------
Output:

CREATE TABLE
CREATE TABLE
CREATE RULE
INSERT 0 1
INSERT 0 1
INSERT 0 1

  id
----
   1
   2
   3
(3 rows)

  id |             ts
----+----------------------------
   1 | 2018-09-08 17:18:41.661292
   3 | 2018-09-08 17:18:41.683459
(2 rows)


That is, in the NOT EXISTS condition the rule is not executed.


Version:
PostgreSQL 9.5.14 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
PostgreSQL 8.3.23 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.7.4


Is this bug or feature? :)



                                 -Sygma


pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors
Next
From: Andrew Gierth
Date:
Subject: Re: RULE does not like the NOT EXISTS condition