Re: INSERT ON CONFLICT and RETURNING - Mailing list pgsql-hackers

From Geoff Winkless
Subject Re: INSERT ON CONFLICT and RETURNING
Date
Msg-id CAEzk6feT1NXSqvdYffg0jDJT+wPRLekH=2LuNn50KyQ6Zw2PsA@mail.gmail.com
Whole thread Raw
In response to INSERT ON CONFLICT and RETURNING  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
Responses Re: INSERT ON CONFLICT and RETURNING  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
List pgsql-hackers
On Sat, 22 Aug 2020 at 08:16, Konstantin Knizhnik
<k.knizhnik@postgrespro.ru> wrote:
> It is possible to do something like this:
>
>    with ins as (insert into jsonb_schemas (schema) values (obj_schema)
> on conflict(schema) do nothing returning id) select coalesce((select id
> from ins),(select id from jsonb_schemas where schema=obj_schema));
>
> but it requires extra lookup.

But if

INSERT INTO jsonb_schemas (schema) VALUES (obj_schema)
  ON CONFLICT (schema) DO NOTHING RETURNING id

were to work then that would _also_ require a second lookup, since
"id" is not part of the conflict key that will be used to perform the
existence test, so the only difference is it's hidden by the syntax.

Geoff



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Avoid displaying unnecessary "Recheck Cond" in EXPLAIN ANALYZE output if the bitmap is non-lossy
Next
From: Christoph Berg
Date:
Subject: Re: deb repo doesn't have latest. or possible to update web page?