PostgreSQL: column reference is ambiguous
ERROR: column reference "<name>" is ambiguousThe column name you used exists in more than one table in the query, so Postgres cannot tell which you mean. Qualify it with a table name or alias.
What this error means
When a query joins two tables that both have a column with the same name (id is the classic case), an unqualified reference is ambiguous, and Postgres refuses to guess which one you meant.
It also happens inside PL/pgSQL when a variable shares a name with a table column.
How to fix it
Two joined tables share the column name
Prefix the column with its table alias.
SELECT o.id, c.id AS customer_id
FROM orders o
JOIN customers c ON c.id = o.customer_id;A PL/pgSQL variable clashes with a column
Rename the variable, or tell Postgres to prefer the column.
#variable_conflict use_columnHow to avoid it next time
- Alias every table and qualify columns in any query that joins more than one table.
- Give PL/pgSQL variables names that cannot collide with column names.
Frequently asked questions
Why does 'id' cause this?
Both joined tables have an id column, so id alone is ambiguous. Write o.id or c.id.
How do I fix it in a function?
Rename the PL/pgSQL variable so it does not match a column, or add #variable_conflict use_column to the function body.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.