{"record":{"id":"12f1a85b5d8c5960","repo":"prestodb/presto","slug":"column-name-not-specified","errorCode":"COLUMN_NAME_NOT_SPECIFIED","errorMessage":"Column name not specified at position %s","messagePattern":"Column name not specified at position (.+?)","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":1614,"sourceCode":"            for (Property property : properties) {\n                if (!propertyNames.add(property.getName().getValue())) {\n                    throw new SemanticException(DUPLICATE_PROPERTY, property, \"Duplicate property: %s\", property.getName().getValue());\n                }\n            }\n            for (Property property : properties) {\n                process(property, scope);\n            }\n        }\n\n        private void validateColumns(Statement node, RelationType descriptor)\n        {\n            // verify that all column names are specified and unique\n            // TODO: collect errors and return them all at once\n            Set<String> names = new HashSet<>();\n            for (Field field : descriptor.getVisibleFields()) {\n                Optional<String> fieldName = field.getName();\n                if (!fieldName.isPresent()) {\n                    throw new SemanticException(COLUMN_NAME_NOT_SPECIFIED, node, \"Column name not specified at position %s\", descriptor.indexOf(field) + 1);\n                }\n                if (!names.add(fieldName.get())) {\n                    throw new SemanticException(DUPLICATE_COLUMN_NAME, node, \"Column name '%s' specified more than once\", fieldName.get());\n                }\n                if (field.getType().equals(UNKNOWN)) {\n                    throw new SemanticException(COLUMN_TYPE_UNKNOWN, node, \"Column type is unknown: %s\", fieldName.get());\n                }\n            }\n        }\n\n        private void validateColumnAliases(List<Identifier> columnAliases, int sourceColumnSize)\n        {\n            if (columnAliases.size() != sourceColumnSize) {\n                throw new SemanticException(\n                        MISMATCHED_COLUMN_ALIASES,\n                        columnAliases.get(0),\n                        \"Column alias list has %s entries but subquery has %s columns\",\n                        columnAliases.size(),","sourceCodeStart":1596,"sourceCodeEnd":1632,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L1596-L1632","documentation":"During analysis, the relation descriptor's visible fields are checked to ensure every output column has a name. If any field's name is absent (Optional.empty()), analysis fails with COLUMN_NAME_NOT_SPECIFIED, reporting the 1-based ordinal position. Presto requires named columns for the result relation (e.g. for CREATE TABLE AS, views, named queries).","triggerScenarios":"Statements whose output includes an unnamed expression column where a name is required: `CREATE TABLE t AS SELECT 1 + 1;`, `CREATE VIEW v AS SELECT count(1) ...` on engines requiring aliases, or queries whose descriptor fields lack names at the checked point.","commonSituations":"CTAS/view creation from SELECTs with computed columns without AS aliases; generated SQL missing aliases after refactoring; selecting constants or function results and using them as table columns.","solutions":["Add an explicit alias to the unnamed output column: SELECT 1 + 1 AS result","If the SELECT is generated, ensure every non-trivial expression in the projection list has an AS clause","Re-run the statement; the error's position field tells which column (1-based) lacks a name"],"exampleFix":"// before\nCREATE TABLE metrics AS SELECT now() - interval '1' DAY, count(*) FROM events;\n\n// after\nCREATE TABLE metrics AS SELECT now() - interval '1' DAY AS window_start, count(*) AS event_count FROM events;","handlingStrategy":"validation","validationCode":"// Before submitting DDL, ensure every projection item has an alias\nList<String> projections = parseProjectionItems(sql);\nfor (int i = 0; i < projections.size(); i++) {\n    if (!projections.get(i).matches(\".*\\\\s+AS\\\\s+\\\\w+.*\")) {\n        throw new IllegalArgumentException(\"Column at position \" + (i + 1) + \" needs an AS alias\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(ctasSql);\n} catch (SemanticException e) {\n    if (e.getCode() == SemanticErrorCode.COLUMN_NAME_NOT_SPECIFIED) {\n        // position is in e.getMessage(); add aliases and retry\n    } else throw e;\n}","preventionTips":["Always alias computed/constant columns in SELECT for CTAS and CREATE VIEW","Enable linting that flags projection items without aliases","Keep generated SQL templates with mandatory AS slots for non-column expressions"],"tags":["presto","sql","column-alias","semantic-analysis"],"backgroundTag":"missing-column-name","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"}