pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: onderkalaci@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres
Date: Tue, 26 Jan 2016 12:34:20 +0000
Message-ID: <20160126123420.2539.85100@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (14+ messages)  latest in thread

Message-ID: <20160126123420.2539.85100@wrigleys.postgresql.org>
Permalink:  ../20160126123420.2539.85100@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160126123420.2539.85100@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: onderkalaci@gmail.com
  Subject: Re: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres
  In-Reply-To: <20160126123420.2539.85100@wrigleys.postgresql.org>
  References: <20160126123420.2539.85100@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox