{"record":{"id":"ed4c58fd10219407","repo":"prestodb/presto","slug":"ambiguous-attribute","errorCode":"AMBIGUOUS_ATTRIBUTE","errorMessage":"Column '%s' is ambiguous","messagePattern":"Column '(.+?)' is ambiguous","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/SemanticExceptions.java","lineNumber":41,"sourceCode":"import static com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED;\nimport static java.lang.String.format;\n\npublic final class SemanticExceptions\n{\n    private SemanticExceptions() {}\n\n    public static SemanticException missingAttributeException(Expression node, QualifiedName name)\n    {\n        throw new SemanticException(\n                MISSING_ATTRIBUTE,\n                node,\n                name.getPrefix().isPresent() ? \"'%s' cannot be resolved\" : \"Column '%s' cannot be resolved\",\n                name);\n    }\n\n    public static SemanticException ambiguousAttributeException(Expression node, QualifiedName name)\n    {\n        throw new SemanticException(AMBIGUOUS_ATTRIBUTE, node, \"Column '%s' is ambiguous\", name);\n    }\n\n    public static SemanticException notSupportedException(Node node, String notSupportedFeatureDescription)\n    {\n        throw new SemanticException(NOT_SUPPORTED, node, notSupportedFeatureDescription + \" is not supported\");\n    }\n\n    public static String subQueryNotSupportedError(Node node, String notSupportedFeatureDescription)\n    {\n        if (node.getLocation().isPresent()) {\n            NodeLocation nodeLocation = node.getLocation().get();\n            return format(\"line %s:%s: %s\", nodeLocation.getLineNumber(), nodeLocation.getColumnNumber(), notSupportedFeatureDescription + \" is not supported\");\n        }\n        return notSupportedFeatureDescription + \" is not supported\";\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":58,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/SemanticExceptions.java#L23-L58","documentation":"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.","triggerScenarios":"SELECT/ WHERE referencing a bare column name that exists in two or more joined tables with the same name, without a table/alias qualifier.","commonSituations":"JOINs between tables sharing 'id', 'name', 'created_at' columns; SELECT * expansion followed by unqualified column use in ORDER BY/GROUP BY.","solutions":["Qualify the column with its table alias: t.id instead of id","Rename columns with aliases in subqueries to make them unique","Restructure the join (USING clause) so the shared column is unambiguous"],"exampleFix":"-- before\nSELECT id FROM a JOIN b ON a.x = b.x   -- id in both a and b\n-- after\nSELECT a.id FROM a JOIN b ON a.x = b.x","handlingStrategy":"validation","validationCode":"-- Detect duplicate column names across joined tables before running\nSELECT column_name, COUNT(*) FROM information_schema.columns\nWHERE table_name IN ('a','b') AND column_name='id' GROUP BY column_name HAVING COUNT(*) > 1;","typeGuard":null,"tryCatchPattern":"try { /* run query */ } catch (SemanticException e) { if (\"AMBIGUOUS_ATTRIBUTE\".equals(e.getErrorCode().getName())) { /* qualify the column reference */ } throw e; }","preventionTips":["Qualify every column with its table alias in joins","Prefer JOIN ... USING for shared key columns","Alias projected columns to unique names in subqueries"],"tags":["sql","ambiguity","joins"],"backgroundTag":"ambiguous-column-reference","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}