Menu

Supabase maybeSingle() PGRST116: Multiple Rows Returned
πŸ“°

Supabase maybeSingle() PGRST116: Multiple Rows Returned

DEV Community: webdevΒ·cometa-kaitoΒ·about 5 hours ago
#CQ1i2iw1
#devtowebdev#devto#dev#constraint#columns
Reading 0:00
15s threshold

Conclusion

If a table's unique constraint is a composite key over 3 columns, and your query filters on only 2 of them before calling .maybeSingle() , PGRST116 fires the moment a row exists where the third column differs. PostgREST (the REST layer Supabase runs internally) errors out on .maybeSingle() or .single() as soon as 2 or more rows match β€” it has no way to decide which one to return. Data that genuinely existed was disappearing as a 404, purely because the filter was looser than the constraint it was meant to match.

Symptom

There's an API that serves a PDF copy of the terms-of-service text a user agreed to at signature time. The copies live in a signature_evidence table, and the read side looked up a single row by entity (derived from the version) and entity_id (the contract ID) β€” 2 columns.

// src/app/api/evidence/[id]/terms/route.ts (before) const { data : ev } = await admin . from ( " signature_evidence " ) . select ( " frozen_path, mime_type, signer_snapshot " ) .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.