Re: INSERT ... ON CONFLICT syntax issues

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: INSERT ... ON CONFLICT syntax issues
Дата
Msg-id 20150506145331.GM9855@alap3.anarazel.de
обсуждение исходный текст
Ответ на Re: INSERT ... ON CONFLICT syntax issues  (Heikki Linnakangas <hlinnaka@iki.fi>)
Ответы Re: INSERT ... ON CONFLICT syntax issues  (Peter Geoghegan <pg@heroku.com>)
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Disabling trust/ident authentication configure option
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Patch for bug #12845 (GB18030 encoding)