© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
7 replies
chrtravels

Using onConflict for date?

Hi all, I am trying to update the entry for a date if no entry exists on that date, otherwise insert a new entry.

Is upsert the correct was to go about this with onConflict and ignoreDuplicates?

I get a 400 bad request with the following:

const { data, error } = await supabase
      .from('daily_metrics')
      .upsert({
        user_id: userId,
        created_at: today.replaceAll('/', '-'),
        weight: dailyLog.dailyWeight,
        morning_systolic_pressure: dailyLog.morningSys,
        morning_diastolic_pressure: dailyLog.morningDia,
        strength_training_duration: dailyLog.strength,
        cardio_training_duration: dailyLog.cardio,
      },
      { onConflict: 'created_at', ignoreDuplicates: true }
      )
      .select()
const { data, error } = await supabase
      .from('daily_metrics')
      .upsert({
        user_id: userId,
        created_at: today.replaceAll('/', '-'),
        weight: dailyLog.dailyWeight,
        morning_systolic_pressure: dailyLog.morningSys,
        morning_diastolic_pressure: dailyLog.morningDia,
        strength_training_duration: dailyLog.strength,
        cardio_training_duration: dailyLog.cardio,
      },
      { onConflict: 'created_at', ignoreDuplicates: true }
      )
      .select()


Any direction is appreciated.
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

Upsert onConflict
SupabaseSSupabase / help-and-questions
4y ago
onConflict Python upsert
SupabaseSSupabase / help-and-questions
4y ago
Bulk Upsert onConflict not working
SupabaseSSupabase / help-and-questions
7mo ago
Check if date is between two dates
SupabaseSSupabase / help-and-questions
4y ago