Re: INSERT ... ON CONFLICT syntax issues

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: INSERT ... ON CONFLICT syntax issues
Дата
Msg-id 553CAE39.9020905@iki.fi
обсуждение исходный текст
Ответ на INSERT ... ON CONFLICT syntax issues  (Andres Freund <andres@anarazel.de>)
Ответы Re: INSERT ... ON CONFLICT syntax issues  (Andres Freund <andres@anarazel.de>)
Re: INSERT ... ON CONFLICT syntax issues  (Stephen Frost <sfrost@snowman.net>)
Re: INSERT ... ON CONFLICT syntax issues  (Peter Geoghegan <pg@heroku.com>)
Список pgsql-hackers
On 04/25/2015 12:01 PM, Andres Freund wrote:
> INSERT ... ON CONFLICT (cola, colb [WHERE predicate_for_partial]) UPDATE|IGNORE
>
> My problem with the WHERE being inside the parens in the above is that
> it's
> a) different from CREATE INDEX
> b) unclear whether the WHERE belongs to colb or the whole index
>     expression. The equivalent for aggregates, which I bet is going to be
>     used less often, caused a fair amount of confusing.
>
> That's why I wanted the WHERE outside the (), which requires either
> adding DO between the index inference clause, and the action, to avoid
> ambiguities in the grammar.

Yeah, having the WHERE outside the parens seems much nicer. What is the 
ambiguity?

> But I'm generally having some doubts about the syntax.
>
> Right now it's
> INSERT ... ON CONFLICT opt_on_conf_clause UPDATE|IGNORE.
>
> A couple things:
>
> a) Why is is 'CONFLICT"? We're talking about a uniquness violation. What
>     if we, at some later point, also want to handle other kind of
>     violations? Shouldn't it be ON UNIQUE CONFLICT/ERROR/VIOLATION ...

As Peter said, it's also for exclusion constraints. Perhaps "ON 
CONSTRAINT VIOLATION"? It doesn't apply to foreign key constraints, 
though. I think "ON CONFLICT" is fine.

> b) For me there's a WITH before the index inference clause missing, to
>     have it read in 'SQL' style.

Agreed. ON would sound more natural than WITH though:

INSERT INTO mytable ON CONFLICT ON (keycol) UPDATE ...

The ability to specify a constraint by name hasn't been implemented, but 
that would read quite naturally as:

INSERT INTO mytable ON CONFLICT ON CONSTRAINT my_constraint UPDATE ...

- Heikki




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

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: inherit support for foreign tables
Следующее
От: Andres Freund
Дата:
Сообщение: Re: INSERT ... ON CONFLICT syntax issues