BUG #15960: ON CONFLICT Trying accessing to variables - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15960: ON CONFLICT Trying accessing to variables
Date
Msg-id 15960-ea463c93a1f572db@postgresql.org
Whole thread Raw
Responses Re: BUG #15960: ON CONFLICT Trying accessing to variables  (Peter Geoghegan <pg@bowt.ie>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15960
Logged by:          Anton Dutov
Email address:      anton.dutov@gmail.com
PostgreSQL version: 11.3
Operating system:   Linux
Description:

Using upsert in stored procedure  ON CONFLICT(id, ...)  trows "ERROR: column
reference "id" is ambiguous" where id used as column name and as variable,
but ON CONFLICT can't use variables



Reproduce

CREATE TABLE IF NOT EXISTS test_table (id INT PRIMARY KEY, note TEXT);

CREATE OR REPLACE FUNCTION test_table_add (
  in_id   INT
 ,in_note TEXT
 ,OUT id INT
) RETURNS INT LANGUAGE plpgsql VOLATILE SECURITY DEFINER AS $$
BEGIN
    INSERT INTO test_table (id, note) VALUES (in_id, in_note)
      ON CONFLICT (id) DO UPDATE SET note = in_note;
END;
$$;

SELECT test_table_add (1, 'ONE');


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15959: 'DROP EXTENSION pglogical' while an unused logical replication slot exists causes slot corruption
Next
From: Peter Geoghegan
Date:
Subject: Re: BUG #15960: ON CONFLICT Trying accessing to variables