scribase
SQLSTATE 42703undefined_columnHTTP 400

Postgres error 42703: undefined column

column "x" does not exist

A query names a column the table does not have.

Common causes

  • A typo, or camelCase in code against snake_case columns.
  • A string literal written with double quotes ("active") instead of single quotes, so Postgres reads it as a column name.
  • The migration adding the column has not run here.

How to fix it

  • Use single quotes for strings.
  • Check the columns with \d table.
  • Run pending migrations on this database.

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. In supabase-js, a select string with a column that does not exist gives this error; PostgREST answers 400.

Questions

What does Postgres error 42703 mean?

42703 is undefined_column in class 42 (Syntax Error or Access Rule Violation). A query names a column the table does not have.

How do I fix 42703?

Use single quotes for strings. Check the columns with \d table. Run pending migrations on this database.

What HTTP status does a REST API return for 42703?

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
  • 42702 column reference "x" is ambiguous