Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aOA5J-0005TJ-BU for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2016 20:19:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aOA5I-0003Df-UR for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2016 20:19:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aO2pt-0005QT-PG for pgsql-bugs@postgresql.org; Tue, 26 Jan 2016 12:35:05 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aO2pq-0005Fa-HZ for pgsql-bugs@postgresql.org; Tue, 26 Jan 2016 12:35:05 +0000 MIME-Version: 1.0 Subject: BUG #13891: Deparsed arbiter WHERE clauses cannot be parsed by Postgres To: pgsql-bugs@postgresql.org From: onderkalaci@gmail.com Date: Tue, 26 Jan 2016 12:34:20 +0000 Message-ID: <20160126123420.2539.85100@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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