Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1arBVf-00073I-UE for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Apr 2016 21:42:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1arBVe-00030j-L3 for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Apr 2016 21:42:38 +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_2) (envelope-from ) id 1arBQM-0002pN-0L for pgsql-bugs@postgresql.org; Fri, 15 Apr 2016 21:37:10 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1arBQE-0001dG-Ul for pgsql-bugs@postgresql.org; Fri, 15 Apr 2016 21:37:09 +0000 MIME-Version: 1.0 Subject: BUG #14089: ON CONFLICT allows function variables in index expressions To: pgsql-bugs@postgresql.org From: quassnoi@gmail.com Date: Fri, 15 Apr 2016 21:36:14 +0000 Message-ID: <20160415213614.22913.56001@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" 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: 14089 Logged by: Alex Bolenok Email address: quassnoi@gmail.com PostgreSQL version: 9.5.2 Operating system: CentOS 6 Description: test=# CREATE TABLE test (id BIGSERIAL NOT NULL PRIMARY KEY, value INT); CREATE TABLE test=# CREATE UNIQUE INDEX ix_test ON test (value, (1)); CREATE INDEX test=# INSERT INTO test (value) VALUES (1); INSERT 0 1 test=# INSERT INTO test (value) VALUES (1); ERROR: duplicate key value violates unique constraint "ix_test" ПОДРОБНОСТИ: Key (value, (1))=(1, 1) already exists. test=# INSERT INTO test (value) VALUES (1) ON CONFLICT (value, (1)) DO NOTHING; INSERT 0 0 test=# INSERT INTO test (value) VALUES (1) ON CONFLICT (value, (2)) DO NOTHING; ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification test=# INSERT INTO test (value) VALUES (1) ON CONFLICT (value, (id)) DO NOTHING; ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification test=# INSERT INTO test (value) VALUES (1) ON CONFLICT (value, (no_such_column)) DO NOTHING; ERROR: column "no_such_column" does not exist СТРОКА 1: ...INTO test (value) VALUES (1) ON CONFLICT (value, (no_such_co... test=# INSERT INTO test (value) SELECT * FROM (VALUES (1)) q (n) ON CONFLICT (value, (n)) DO NOTHING; ERROR: column "n" does not exist СТРОКА 1: ...CT * FROM (VALUES (1)) q (n) ON CONFLICT (value, (n)) DO NOT... ПОДСКАЗКА: There is a column named "n" in table "*SELECT*", but it cannot be referenced from this part of the query. test=# DROP FUNCTION IF EXISTS fn_test(INT); CREATE FUNCTION fn_test(n INT) RETURNS VOID AS $$ INSERT INTO test (value) VALUES (1) ON CONFLICT (value, (n)) DO NOTHING; $$ LANGUAGE 'sql'; DROP FUNCTION CREATE FUNCTION test=# SELECT * FROM fn_test(1); ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification КОНТЕКСТ: SQL function "fn_test" during startup I expected CREATE FUNCTION to fail with the same messages as the INSERT query before it, because it makes no sense to reference function variables in index inference. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs