Re: INSERT ... ON CONFLICT syntax issues

From: Andres Freund <andres(at)anarazel(dot)de>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Peter Geoghegan <pg(at)heroku(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Subject: Re: INSERT ... ON CONFLICT syntax issues
Date: 2015-05-06 14:53:31
Message-ID: 20150506145331.GM9855@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2015-05-05 15:27:09 +0300, Heikki Linnakangas wrote:
> I'm a bit late to the party as I haven't paid much attention to the syntax
> before, but let me give some comments on this "arbiter index inference"
> thingie.
>
>
> To recap, there are three variants:
>
> A. INSERT ... ON CONFLICT DO NOTHING
>
> No arbiter is specified. This means that a conflict on any unique or
> exclusion constraint is not allowed (and will do nothing instead). This
> variant is only accepted for DO NOTHING.
>
> B. INSERT ... ON CONFLICT ON <constraint name> DO NOTHING/UPDATE
>
> In this variant, you explicitly specify the constraint by name.

I do think it's a bit sad to not be able to specify unique indexes that
aren't constraints. So I'd like to have a corresponding ON INDEX - which
would be trivial.

> C. INSERT ... ON CONFLICT (<index params>) [WHERE <expression>] DO
> NOTHING/UPDATE
>
> This specifies an index (or indexes, in the corner case that there are
> several identical ones), by listing the columns/expressions and the
> predicate for a partial index. The list of columns and WHERE match the
> syntax for CREATE INDEX.
>
>
> That's pretty good overall. A few questions:
>
> 1. Why is the variant without specifying an index or constraint not allowed
> with DO UPDATE? I agree it might not make much sense, but then again, it
> might. If we're afraid that it's too unsafe to be the "default" if you don't
> specify any constraint, how about allowing it with a more verbose "ON
> CONFLICT ON ANY CONSTRAINT" syntax?

I think that'd be useful. Peter seems to be against it on pureness
grounds when we argued against it before, but I know that I'd wished for
it before.

> 2. Why can't you specify multiple constraints, even though we implicitly
> allow "any" with the first variant?

Yea.

> Finally, a couple of suggestions. It would be pretty handy to allow:
>
> INSERT ... ON CONFLICT ON PRIMARY KEY DO NOTHING/UPDATE

Not sure if that really has that big of a use case, but it'd also be
simple.

> Also, I wonder if we should change the B syntax to be:
>
> INSERT ... ON CONFLICT ON *CONSTRAINT* <constraint name> DO NOTHING/UPDATE

Oh yes.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2015-05-06 14:55:40 Re: Patch for bug #12845 (GB18030 encoding)
Previous Message Alvaro Herrera 2015-05-06 14:47:24 Re: Disabling trust/ident authentication configure option