Skip to content

Upsert doesn't return data when row already exists #452

Open
@mrkpatchaa

Description

@mrkpatchaa

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Hi Team, when doing an upsert on an existing record, the select returns an empty array.

To Reproduce

This is my code

const {data, error} = supabase
.from('chats')
.upsert(data, { onConflict: ['user_id', 'listing_id'], ignoreDuplicates: true })
.select()

Running this the first time returns data

{
  error: null,
  data: [
    {
      id: 7,
      created_at: '2023-07-25T19:19:03.942503+00:00',
      updated_at: '2023-07-25T19:19:03.942503+00:00',
      listing_id: 1,
      user_id: 'bf21737c-8684-49af-944c-94b126f90f55'
    }
  ],
  count: null,
  status: 201,
  statusText: 'Created'
}

Running it second time with the same values for listing_id and user_id returns

{
  error: null,
  data: [],
  count: null,
  status: 201,
  statusText: 'Created'
}

Expected behavior

The second call should return the same result as the first one.

Additional context

If the behaviour is normal, how should I get the id of the newly inserted / existing row? Typically I would run this code and redirect the user to the chat screen with id returned in data. The idea is to not make an extra call to the database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions