BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres

From: onderkalaci(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres
Date: 2016-01-26 12:34:20
Message-ID: 20160126123420.2539.85100@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13891
Logged by: Onder Kalaci
Email address: onderkalaci(at)gmail(dot)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(at)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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2016-01-26 13:14:44 Re: BUG #13888: pg_dump write error
Previous Message Master ZX 2016-01-26 11:49:42 Re[2]: [BUGS] Re[2]: [BUGS] BUG #13869: Right Join query that never ends