Re: Upsert error "column reference is ambiguous" - Mailing list pgsql-general

From Tom Lane
Subject Re: Upsert error "column reference is ambiguous"
Date
Msg-id 697017.1745837694@sss.pgh.pa.us
Whole thread Raw
In response to Upsert error "column reference is ambiguous"  (Tim Starling <tstarling@wikimedia.org>)
Responses Re: Upsert error "column reference is ambiguous"
List pgsql-general
Tim Starling <tstarling@wikimedia.org> writes:
> Regarding upsert syntax.
> => INSERT INTO t VALUES (1,1) ON CONFLICT (k) DO UPDATE SET v=v+1;
> ERROR:  column reference "v" is ambiguous

> Please convince me that this is not a bug.

It's not a bug.

> If I understand correctly, in the expression "v+1", both EXCLUDED.v 
> and t.v are present as the unqualified name "v". This is always the 
> case and it is never possible to reference an unqualified field name 
> in the expression of a conflict action.

Correct: it's not clear whether you mean to use "v" from the new
desired-to-be-inserted row or "v" from the existing row.

> Thus, any query with an unqualified name is statically known to be 
> invalid. It is not a b/c break to remove EXCLUDED.v from the list of 
> unqualified fields in a new major release of PG, thus allowing it to DWIM.

Even if I were on board with arbitrarily adopting one of the two
possible interpretations, it's far from obvious to me that most people
would agree that "v" should mean the value from the existing row,
rather than the new value.  Better to make them say which they want.

            regards, tom lane



pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Fwd: SQL transactions executing from VMSS
Next
From: Tom Lane
Date:
Subject: Re: Fwd: SQL transactions executing from VMSS