prestodb/presto · error · SemanticException

AMBIGUOUS_ATTRIBUTE

AMBIGUOUS_ATTRIBUTE

Error message

Column '%s' is ambiguous

What it means

SemanticExceptions.ambiguousAttributeException throws AMBIGUOUS_ATTRIBUTE when a column name matches more than one source in scope and the query does not disambiguate it. Presto will not silently pick one candidate.

Source

Thrown at presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/SemanticExceptions.java:41

import static com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED;
import static java.lang.String.format;

public final class SemanticExceptions
{
    private SemanticExceptions() {}

    public static SemanticException missingAttributeException(Expression node, QualifiedName name)
    {
        throw new SemanticException(
                MISSING_ATTRIBUTE,
                node,
                name.getPrefix().isPresent() ? "'%s' cannot be resolved" : "Column '%s' cannot be resolved",
                name);
    }

    public static SemanticException ambiguousAttributeException(Expression node, QualifiedName name)
    {
        throw new SemanticException(AMBIGUOUS_ATTRIBUTE, node, "Column '%s' is ambiguous", name);
    }

    public static SemanticException notSupportedException(Node node, String notSupportedFeatureDescription)
    {
        throw new SemanticException(NOT_SUPPORTED, node, notSupportedFeatureDescription + " is not supported");
    }

    public static String subQueryNotSupportedError(Node node, String notSupportedFeatureDescription)
    {
        if (node.getLocation().isPresent()) {
            NodeLocation nodeLocation = node.getLocation().get();
            return format("line %s:%s: %s", nodeLocation.getLineNumber(), nodeLocation.getColumnNumber(), notSupportedFeatureDescription + " is not supported");
        }
        return notSupportedFeatureDescription + " is not supported";
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Qualify the column with its table alias: t.id instead of id
  2. Rename columns with aliases in subqueries to make them unique
  3. Restructure the join (USING clause) so the shared column is unambiguous

Example fix

-- before
SELECT id FROM a JOIN b ON a.x = b.x   -- id in both a and b
-- after
SELECT a.id FROM a JOIN b ON a.x = b.x
Defensive patterns

Strategy: validation

Validate before calling

-- Detect duplicate column names across joined tables before running
SELECT column_name, COUNT(*) FROM information_schema.columns
WHERE table_name IN ('a','b') AND column_name='id' GROUP BY column_name HAVING COUNT(*) > 1;

Try / catch

try { /* run query */ } catch (SemanticException e) { if ("AMBIGUOUS_ATTRIBUTE".equals(e.getErrorCode().getName())) { /* qualify the column reference */ } throw e; }

Prevention

When it happens

Trigger: SELECT/ WHERE referencing a bare column name that exists in two or more joined tables with the same name, without a table/alias qualifier.

Common situations: JOINs between tables sharing 'id', 'name', 'created_at' columns; SELECT * expansion followed by unqualified column use in ORDER BY/GROUP BY.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/ed4c58fd10219407. Report an issue: GitHub.