Re: BUG #14089: ON CONFLICT allows function variables in index expressions

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Alex Bolenok <quassnoi(at)gmail(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14089: ON CONFLICT allows function variables in index expressions
Date: 2016-04-18 14:54:16
Message-ID: CAKFQuwah_wdsETqANZBCLNsYowYmnjAZL7AsVniadpAXWc8bxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Apr 18, 2016 at 5:36 AM, Alex Bolenok <quassnoi(at)gmail(dot)com> wrote:

> I realize there is an explanation to that (it's the way it's programmed,
> after all), and that might be not a bug worthy enough to fix (however,
> there are people actually affected by it, see here:
> http://stackoverflow.com/questions/36656643/is-variable-conflict-use-variable-not-working-with-on-conflict-clause-of-upsert ),
> but it's clearly a bug in my opinion.
>

​That SO post is not convincing - though I don't know if the "tname" in the
ON CONFLICT clause can be somehow prefixed so that there is no conflict.
As written, there is a conflict between the table column and the function
parameter and, as instructed, PostgreSQL is using the variable which then
makes the ON CONFLICT clause - as executed - one that does not match
anything in the system.

I'm not particularly concerned with user-space code that uses that pragma.

Unless you are prepared to explain in great depth the hazards of the
current behavior, and probably more importantly the value in some
alternative behavior I'd suggest accepting the fact that this behavior is
precisely how functions work and move on. Just screaming "its a bug" is
not getting us anywhere.

It is possible to want to write a function that parameterizes the predicate
portion of the ON CONFLICT clause - i.e., one that when called with the
appropriate argument will find a match and resolve properly. Maybe someone
can provide an example that would work since right now I'm out of time.
So, your original premise is wrong one its face - while likely having
minimal practical use the function as written could succeed with the right
pre-conditions.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message johnlumby 2016-04-18 16:46:48 BUG #14098: misleading message "out of shared memory" when lock table space exhausted
Previous Message Alex Bolenok 2016-04-18 12:36:49 Re: BUG #14089: ON CONFLICT allows function variables in index expressions