onConflictDoNothing is not returning values

Hey,

Given the following query:

const competition = await db
  .insert(competitions)
  .values({
    name: data.competition,
  })
  .onConflictDoNothing()
  .returning();


It only returns the data when it has inserted unique row, but when row exists, it doesn't return me the existing row.

The behaviour I am seeking, is if the row exists, do not insert it, but give it back to me anyway, because I need to know the ID.
Was this page helpful?