public inbox for [email protected]  
help / color / mirror / Atom feed
From: Brian McMahon <[email protected]>
To: [email protected]
Subject: Support for on conflict ignore returning
Date: Tue, 30 Jul 2024 08:53:55 -0700
Message-ID: <CA+0iD35fvs6cXybmj+FSY_QWpir_c60gGzoi+GX+jTLHEf0Z-A@mail.gmail.com> (raw)

Hi!

I have a question about support / if there's plans to support a feature, I
thought it would be best to send it to the "novice" mailing list because it
might be a naive question that's been answered before.

Is there a recommended way to achieve a ON CONFLICT DO NOTHING RETURNING
<column> so that conflicting columns still have information returned?
Currently it seems like the only simple way to achieve this is with a NOOP
update, so instead doing something like ON CONFLICT UPDATE SET name =
EXCLUDED.name RETURNING <column>.

As I understand it, this isn't desirable as there's various potentially
undesirable side effects since it's not treated as a NOOP, it's treated as
an update so triggers and all sorts of internal postgres logic are invoked
(which may or may not be fine for certain applications, but it's not
desirable).

Are there current features that support this functionality, or plans to
support something like this in the future?

I should probably add my use case, I need to insert a bunch of rows into
the database to ensure they exist, then for all those rows I need to update
corresponding tables that reference them with more data. If I can't make a
query that returns the primary key, then I either need to make a subsequent
query to pull all the rows from the database that weren't inserted to get
the primary keys, or I need to use the unique fields that caused the
conflict in the next query to update the tables that reference the table I
updated, which makes things a little messier (I'd rather just work with the
primary keys when possible).

Thanks in advance.

-- 
Sincerely,
Brian McMahon


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Support for on conflict ignore returning
  In-Reply-To: <CA+0iD35fvs6cXybmj+FSY_QWpir_c60gGzoi+GX+jTLHEf0Z-A@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox