From: Alexi Theodore <alexitheodore@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Bug report: variable_conflict + ON CONFLICT
Date: Wed, 5 Jan 2022 16:40:58 -0800
Message-ID: <2A512572-5AE4-4072-9C04-C746C9E67F56@gmail.com> (raw)
Hi,
I'd like to report what I think is a bug. I've put together a script which highlights things pretty clearly. The short synopsis is that when using "#variable_conflict use_variable" in a function or procedure, the correct choice of variable vs column name is done everywhere (that I know of) except in the ON CONFLICT (<column name>) part of an INSERT statement. That one part only seems to not follow the conflict resolution pattern.
Thanks,
Alex
Attachments:bug report - ON CONFLICT and variable_conflict.txt (text/plain, 1.1K) download
ROLLBACK; BEGIN;
CREATE TABLE example_table (
test_column TEXT unique
)
;
INSERT INTO example_table VALUES ('abc')
ON CONFLICT (test_column) DO NOTHING
;
CREATE PROCEDURE example_works (
test_column_in TEXT
) AS
$$
#variable_conflict use_variable
BEGIN
INSERT INTO example_table (test_column) VALUES (test_column_in)
ON CONFLICT (test_column) DO NOTHING
;
END
$$
LANGUAGE plpgsql
;
CALL example_works('xyz');
SELECT * FROM example_table
;
CREATE PROCEDURE example_breaks (
test_column TEXT
-- ^ note: the new declaration name is the same as the column name
) AS
$$
#variable_conflict use_variable
BEGIN
-- ^ normally, name conflicts would be resolved successully this way...
INSERT INTO example_table (test_column) -- `variable_conflict` is working here √
VALUES (test_column) -- `variable_conflict` is working here √
ON CONFLICT (test_column) DO NOTHING -- `variable_conflict` is NOT working here X @ `(test_column)`
;
END
$$
LANGUAGE plpgsql
;
CALL example_breaks('qwe');
/*
[42P10] ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
PL/pgSQL function example_breaks(text) line 6 at SQL statement
*/
ROLLBACK;=
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: alexitheodore@gmail.com
Subject: Re: Bug report: variable_conflict + ON CONFLICT
In-Reply-To: <2A512572-5AE4-4072-9C04-C746C9E67F56@gmail.com>
References: <2A512572-5AE4-4072-9C04-C746C9E67F56@gmail.com>
* 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