Thread: "INSERT ON CONFLICT UPDATE" - Use of indexes ?

"INSERT ON CONFLICT UPDATE" - Use of indexes ?

From
Laura Smith
Date:
Hi,

What'st the current state of play with indexes and ON CONFLICT ?  The docs seem to vaguely suggest it is possible, but
thisSO question (https://stackoverflow.com/questions/38945027/) seems to suggest it is not. 

I've got a unique named index on a table (i.e. "create unique index xyz...") but I cannot seem to be able to refer to
itin a function ? 
ON CONFLICT (index_name) .... : does not work
ON CONFLICT ON CONSTRAINT index_name....: does not work



Re: "INSERT ON CONFLICT UPDATE" - Use of indexes ?

From
Adrian Klaver
Date:
On 6/8/20 5:42 AM, Laura Smith wrote:
> Hi,
> 
> What'st the current state of play with indexes and ON CONFLICT ?  The docs seem to vaguely suggest it is possible,
butthis SO question (https://stackoverflow.com/questions/38945027/) seems to suggest it is not.
 
> 
> I've got a unique named index on a table (i.e. "create unique index xyz...") but I cannot seem to be able to refer to
itin a function ?
 
> ON CONFLICT (index_name) .... : does not work
> ON CONFLICT ON CONSTRAINT index_name....: does not work
> 

The above is going to need more information:

1) Table definition.

2) Actual index definition

3) Complete ON CONFLICT definition

4) Error message returned.



-- 
Adrian Klaver
adrian.klaver@aklaver.com



Re: "INSERT ON CONFLICT UPDATE" - Use of indexes ?

From
Thomas Kellerer
Date:
Laura Smith schrieb am 08.06.2020 um 14:42:
> Hi,
>
> What'st the current state of play with indexes and ON CONFLICT ?  The docs seem to vaguely suggest it is possible,
butthis SO question (https://stackoverflow.com/questions/38945027/) seems to suggest it is not. 
>
> I've got a unique named index on a table (i.e. "create unique index xyz...") but I cannot seem to be able to refer to
itin a function ? 
> ON CONFLICT (index_name) .... : does not work
> ON CONFLICT ON CONSTRAINT index_name....: does not work

If c1 and c2 make up a unique index, then

    ON CONFLICT (c1, c2)

works





Re: "INSERT ON CONFLICT UPDATE" - Use of indexes ?

From
David Rowley
Date:
On Tue, 9 Jun 2020 at 00:42, Laura Smith
<n5d9xq3ti233xiyif2vp@protonmail.ch> wrote:
> What'st the current state of play with indexes and ON CONFLICT ?  The docs seem to vaguely suggest it is possible,
butthis SO question (https://stackoverflow.com/questions/38945027/) seems to suggest it is not.
 
>
> I've got a unique named index on a table (i.e. "create unique index xyz...") but I cannot seem to be able to refer to
itin a function ?
 
> ON CONFLICT (index_name) .... : does not work
> ON CONFLICT ON CONSTRAINT index_name....: does not work

Creating a unique index does not create a unique constraint.  If you
create a unique constraint, it'll create a unique index to enforce the
constraint.  ON CONSTRAINT requires a constraint name, not an index
name.

David