BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres - Mailing list pgsql-bugs

From onderkalaci@gmail.com
Subject BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres
Date
Msg-id 20160126123420.2539.85100@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres
List pgsql-bugs
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

pgsql-bugs by date:

Previous
From: Master ZX
Date:
Subject: Re[2]: [BUGS] Re[2]: [BUGS] BUG #13869: Right Join query that never ends
Next
From: Peter Geoghegan
Date:
Subject: Re: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres