SQLSTATE 42710duplicate_objectHTTP 400
Postgres error 42710: duplicate object
policy "x" for table "y" already exists / role "x" already exists
A CREATE statement names an object (policy, role, trigger, constraint) that already exists.
Common causes
- Re-running a migration that creates policies or triggers.
How to fix it
- Drop it first in the same migration (drop policy if exists "x" on y;) or check the catalog before creating.
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 400 for this error and returns the SQLSTATE in the code field of the JSON error body.
Questions
What does Postgres error 42710 mean?
42710 is duplicate_object in class 42 (Syntax Error or Access Rule Violation). A CREATE statement names an object (policy, role, trigger, constraint) that already exists.
How do I fix 42710?
Drop it first in the same migration (drop policy if exists "x" on y;) or check the catalog before creating.
What HTTP status does a REST API return for 42710?
PostgREST, the REST layer behind supabase-js, answers 400.