Re: ON CONFLICT and WHERE

2022-11-13 Thread jian he
On Mon, Nov 14, 2022 at 2:55 AM Adrian Klaver wrote: > On 11/13/22 13:07, Tom Lane wrote: > > Adrian Klaver writes: > >> INSERT INTO books VALUES (12, 0, CURRENT_TIMESTAMP) > >> ON CONFLICT (id) > >> WHERE updated IS NULL OR updated + INTERVAL '2min' < CURRENT_TIMESTAMP > >> DO UPDATE > >> SET v

Re: ON CONFLICT and WHERE

2022-11-13 Thread Peter Geoghegan
On Sun, Nov 13, 2022 at 1:07 PM Tom Lane wrote: > A WHERE placed there is an index_predicate attachment to the ON CONFLICT > clause. It doesn't have any run-time effect other than to allow partial > indexes to be chosen as arbiter indexes. TFM explains > > index_predicate > > Used to

Re: ON CONFLICT and WHERE

2022-11-13 Thread Adrian Klaver
On 11/13/22 13:07, Tom Lane wrote: Adrian Klaver writes: INSERT INTO books VALUES (12, 0, CURRENT_TIMESTAMP) ON CONFLICT (id) WHERE updated IS NULL OR updated + INTERVAL '2min' < CURRENT_TIMESTAMP DO UPDATE SET version = books.version + 1, updated = CURRENT_TIMESTAMP; I have not used WHERE w

Re: ON CONFLICT and WHERE

2022-11-13 Thread Tom Lane
Adrian Klaver writes: > INSERT INTO books VALUES (12, 0, CURRENT_TIMESTAMP) > ON CONFLICT (id) > WHERE updated IS NULL OR updated + INTERVAL '2min' < CURRENT_TIMESTAMP > DO UPDATE > SET version = books.version + 1, updated = CURRENT_TIMESTAMP; > I have not used WHERE with ON CONFLICT myself so it

ON CONFLICT and WHERE

2022-11-13 Thread Adrian Klaver
In process of answering an SO question I ran across the below. The original question example: CREATE TABLE books ( id int4 NOT NULL, version int8 NOT NULL, updated timestamp NULL, CONSTRAINT books_pkey PRIMARY KEY (id) ); INSERT INTO books VALUES (12, 0, CURRENT_