The following bug has been logged on the website:
Bug reference: 13891
Logged by: Onder Kalaci
Email address: onderkalaci@gmail.com
PostgreSQL version: 9.5.0
Operating system: MacOs
Description:
Deparsed arbiter WHERE clauses cannot be parsed by Postgres. Please follow
the steps below:
I create two tables:
CREATE TABLE test_1 (a int, b int);
CREATE TABLE test_2 (a int UNIQUE, b int);
Create a rule:
CREATE RULE r3 AS ON INSERT TO test_1
DO INSTEAD
INSERT INTO test_2 VALUES (1,1) ON CONFLICT(a) WHERE a > 100
DO UPDATE set b = test_2.b+1;
Then, SELECT * FROM pg_rules; I get the following:
CREATE RULE r3 AS ON INSERT TO test_1
DO INSTEAD
INSERT INTO test_2 (a, b) VALUES (1, 1) ON CONFLICT(a) WHERE (test_2.a >
100)
DO UPDATE SET b = (test_2.b + 1);
Cutting the query part alone:
INSERT INTO test_2 (a, b) VALUES (1, 1) ON CONFLICT(a) WHERE (test_2.a >
100)
DO UPDATE SET b = (test_2.b + 1);
This query errors out saying:
ERROR: invalid reference to FROM-clause entry for table "test_2"
LINE 1: ...test_2 (a, b) VALUES (1, 1) ON CONFLICT(a) WHERE (test_2.a >...
^
HINT: There is an entry for table "test_2", but it cannot be referenced
from this part of the query.
I guess the problem is on this line (ruletils@5533 on Postgresql 9.5.0
source)
https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/ruleutils.c#L5533
I think, postgres should set varprefix to false before calling
get_rule_expr().
Thanks,
Onder