prestodb/presto · error · SemanticException
COLUMN_NAME_NOT_SPECIFIED
COLUMN_NAME_NOT_SPECIFIED
Error message
Column name not specified at position %s
What it means
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).
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1614
for (Property property : properties) {
if (!propertyNames.add(property.getName().getValue())) {
throw new SemanticException(DUPLICATE_PROPERTY, property, "Duplicate property: %s", property.getName().getValue());
}
}
for (Property property : properties) {
process(property, scope);
}
}
private void validateColumns(Statement node, RelationType descriptor)
{
// verify that all column names are specified and unique
// TODO: collect errors and return them all at once
Set<String> names = new HashSet<>();
for (Field field : descriptor.getVisibleFields()) {
Optional<String> fieldName = field.getName();
if (!fieldName.isPresent()) {
throw new SemanticException(COLUMN_NAME_NOT_SPECIFIED, node, "Column name not specified at position %s", descriptor.indexOf(field) + 1);
}
if (!names.add(fieldName.get())) {
throw new SemanticException(DUPLICATE_COLUMN_NAME, node, "Column name '%s' specified more than once", fieldName.get());
}
if (field.getType().equals(UNKNOWN)) {
throw new SemanticException(COLUMN_TYPE_UNKNOWN, node, "Column type is unknown: %s", fieldName.get());
}
}
}
private void validateColumnAliases(List<Identifier> columnAliases, int sourceColumnSize)
{
if (columnAliases.size() != sourceColumnSize) {
throw new SemanticException(
MISMATCHED_COLUMN_ALIASES,
columnAliases.get(0),
"Column alias list has %s entries but subquery has %s columns",
columnAliases.size(),View on GitHub (pinned to 55bb57d202)
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
Example fix
// before CREATE TABLE metrics AS SELECT now() - interval '1' DAY, count(*) FROM events; // after CREATE TABLE metrics AS SELECT now() - interval '1' DAY AS window_start, count(*) AS event_count FROM events;
Defensive patterns
Strategy: validation
Validate before calling
// Before submitting DDL, ensure every projection item has an alias
List<String> projections = parseProjectionItems(sql);
for (int i = 0; i < projections.size(); i++) {
if (!projections.get(i).matches(".*\\s+AS\\s+\\w+.*")) {
throw new IllegalArgumentException("Column at position " + (i + 1) + " needs an AS alias");
}
} Try / catch
try {
session.execute(ctasSql);
} catch (SemanticException e) {
if (e.getCode() == SemanticErrorCode.COLUMN_NAME_NOT_SPECIFIED) {
// position is in e.getMessage(); add aliases and retry
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- MUST_BE_AGGREGATE_OR_GROUP_BY
- NESTED_AGGREGATION
- NESTED_WINDOW
- MUST_BE_AGGREGATION_FUNCTION
- NOT_SUPPORTED
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/12f1a85b5d8c5960.
Report an issue: GitHub.