pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: lulzimbilali@gmail.com
Subject: BUG #15533: error on upsert when used in a fuction and a function parameter has the same name as the column
Date: Fri, 30 Nov 2018 20:17:20 +0000
Message-ID: <15533-ac9506ee433a0d18@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15533
Logged by:          Lulzim Bilali
Email address:      lulzimbilali@gmail.com
PostgreSQL version: 11.1
Operating system:   Ubuntu 18.04
Description:        

Can't use `ON CONFLICT DO UPDATE` in a function which has a parameter with
the same name as the column where the unique key is.

Here is the error I get.

Query execution failed

       Reason:
       SQL Error [42702]: ERROR: column reference "id" is ambiguous
       Detail: It could refer to either a PL/pgSQL variable or a table
column.
       Where: PL/pgSQL function log_tst(integer,text) line 4 at SQL
statement

the test code I'm using:


    --DROP TABLE IF EXISTS tst;
    CREATE TABLE tst (
     id int UNIQUE,
     info text
    );
    
    --DROP FUNCTION IF EXISTS log_tst;
    CREATE OR REPLACE FUNCTION log_tst(id int, info text) RETURNS void AS
    $$
    BEGIN
        
        INSERT INTO tst (id, info)
        VALUES (log_tst.id, log_tst.info)
        --ON CONFLICT DO NOTHING
        ON CONFLICT (id) DO UPDATE
        SET info = log_tst.info
    ;
    END $$
    LANGUAGE plpgsql;
    
    SELECT log_tst(1, 'changed');

I would expect it to work since we can't use a parameter to check the
uniqueness even if we want (or can we!?), so PostgreSQL should know to use
the column instead.

Lulzim



view thread (7+ messages)  latest in thread

Message-ID: <15533-ac9506ee433a0d18@postgresql.org>
Permalink:  ../15533-ac9506ee433a0d18@postgresql.org/
Also on:    postgresql.org/message-id/15533-ac9506ee433a0d18@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: noreply@postgresql.org, lulzimbilali@gmail.com
  Subject: Re: BUG #15533: error on upsert when used in a fuction and a function parameter has the same name as the column
  In-Reply-To: <15533-ac9506ee433a0d18@postgresql.org>
  References: <15533-ac9506ee433a0d18@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