ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข4y agoโ€ข
2 replies
jkohlin

UPSERT and autogenerated ID (primary key)

I have an HTML form with 3 rows.
I have 2 saved records in the table (user didn't fill in all)

The next time the user logs in, he continues to fill out the form, which is pre filled with the previous 2 records from the db.
- He edits one row
- Fills in the last row, and submits.

How can I:
- save the new row,
- update the edited one
- ignore the unedited row
...without adding duplicates

I tried this:
await supabase
.from('notes')
.insert([
        {
            text: 'This is a test',
            user_id: '123',
            form_row: 1,
        },
        {
            text: 'This is another test',
            user_id: '123',
            form_row: 3,
        },
    ],
    { 
        upsert: true, 
        onConflict: 'id', 
        ignoreDuplicates: false 
    })
.select()
await supabase
.from('notes')
.insert([
        {
            text: 'This is a test',
            user_id: '123',
            form_row: 1,
        },
        {
            text: 'This is another test',
            user_id: '123',
            form_row: 3,
        },
    ],
    { 
        upsert: true, 
        onConflict: 'id', 
        ignoreDuplicates: false 
    })
.select()

but get this error :
null value in column "id" of relation "notes" violates not-null constraint
null value in column "id" of relation "notes" violates not-null constraint


id
id
is auto increment

Can I use UPSERT this way?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

primary key
SupabaseSSupabase / help-and-questions
4y ago
Supabase trying to push duplicated primary key ID
SupabaseSSupabase / help-and-questions
4y ago
Composite Primary Key creation error
SupabaseSSupabase / help-and-questions
4y ago
Make composite primary key unique
SupabaseSSupabase / help-and-questions
4y ago