scribase
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.

Other class 42 errors

  • 42501 permission denied for table x / new row violates row-level security policy for table "x"
  • 42601 syntax error at or near "x"
  • 42P01 relation "x" does not exist
  • 42P07 relation "x" already exists
  • 42P05 prepared statement "s0" already exists
  • 42703 column "x" does not exist