SQLSTATE 42702ambiguous_columnHTTP 400
Postgres error 42702: ambiguous column
column reference "x" is ambiguous
The same column name exists in more than one table in the query, or a PL/pgSQL variable has the same name as a column.
Common causes
- A join where both tables have id or created_at, referenced without a table alias.
- A PL/pgSQL function parameter named like a column (user_id) used inside a query.
How to fix it
- Qualify columns with the table alias (o.id).
- Prefix function parameters (p_user_id) or qualify them with the function name.
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 42702 mean?
42702 is ambiguous_column in class 42 (Syntax Error or Access Rule Violation). The same column name exists in more than one table in the query, or a PL/pgSQL variable has the same name as a column.
How do I fix 42702?
Qualify columns with the table alias (o.id). Prefix function parameters (p_user_id) or qualify them with the function name.
What HTTP status does a REST API return for 42702?
PostgREST, the REST layer behind supabase-js, answers 400.