Several questions on how to use js sdk upsert?
# help-and-questions
j
Here are my questions: - does upsert require the id (primary key)? What if it is new data and it still does not have a primary key? - should the rows in onConflict be unique or can I specify any row?
g
I hate thinking about upsert and keys... Here is a quick one I found. But in general you have to have a unique constraint in order for the insert to "fail" and then do the alternate thing, which can be update... https://discord.com/channels/839993398554656828/1037065027271790602/1037069569564610561
j
I meant I want it to insert but the docs say it requires a primary key. So what if it is a new row.
g
https://github.com/PostgREST/postgrest/issues/1118 More info. Link is the "workarounds" Sorry it is late for me and I always struggle with this feature.

https://cdn.discordapp.com/attachments/1111130085697785877/1111136708273111151/image.png

The problem is without a primary key, if there is a conflict, how do I do the update as the primary key is null...