Error 47: UNKNOWN_IDENTIFIER
This error occurs when a query references a column name, alias, or identifier that does not exist in the specified scope or context. It typically indicates a column name that doesn't exist in the table, a missing alias, or incorrect identifier resolution in complex queries.
Most common causes
-
Column does not exist in table
- Referencing a column name that is not present in the table schema
- Typo in column name
- Column was dropped or never created
-
Incorrect identifier scope in joins
- Referencing columns without proper table aliases
- Ambiguous column references in multi-table queries
- Column from wrong side of join
- Using columns that exist in one table but not in the joined result
-
Missing columns in subqueries or CTEs
- Column not selected in inner query but referenced in outer query
- Column not available in the scope where it's being referenced
- Incorrect nesting of subqueries
-
Alias issues
- Using an alias before it's defined
- Referencing column by original name after aliasing
- Alias not properly propagated through query stages
-
Materialized view or integration issues
- Column missing from source table in materialized view
- Schema mismatch between source and target
- Replication or CDC tools referencing non-existent columns
-
Aggregation context problems
- Using non-aggregated columns not in
GROUP BYclause - Referencing columns that are only available after aggregation
- Incorrect use of columns in
HAVINGvsWHEREclauses
- Using non-aggregated columns not in
Common solutions
1. Verify column exists in table
2. Use proper table aliases in joins
3. Check column availability in scope
4. Fix aggregation issues
5. Use EXPLAIN to debug
This shows how ClickHouse interprets your query and may reveal the actual column names being used.
6. Handle case sensitivity
Common scenarios
Scenario 1: Missing column in materialized view
Solution: Ensure the column exists in the source table or add it to the materialized view definition.
Scenario 2: Column ambiguity in joins
Solution: The column exists in the joined table but isn't in the aggregation scope. Use proper aliases and ensure the column is accessible in the aggregation context.
Scenario 3: Alias before definition
Prevention tips
- Use explicit table aliases: Always use
table.columnoralias.columnsyntax in joins - Verify schema before querying: Use
DESCRIBE TABLEto confirm column names and types - Check column case: Column names are case-sensitive
- Review aggregation logic: Ensure all non-aggregated columns are in
GROUP BY - Use IDE or query validator: Many tools can catch column reference errors before execution
- Test subqueries independently: Verify inner queries work before nesting them
- Monitor schema changes: Track
ALTER TABLEoperations that might remove columns
Debugging steps
If you're experiencing this error:
-
Check the error message carefully - it often suggests similar column names with "maybe you meant: ['column_name']"
-
Verify table schema:
-
Check if column is in the right scope for joins and subqueries
-
Use
EXPLAIN SYNTAXto see how ClickHouse interprets your query -
Test with simpler query - remove joins and subqueries to isolate the issue
-
Check for typos in column names (including case sensitivity)
-
Review recent schema changes - was the column recently dropped or renamed?
-
For integrations/materialized views - verify source and target schemas match
Special considerations
For CDC and replication tools:
- This error often occurs when schema changes aren't synchronized
- The source table may have different columns than expected
- Check both source and target schemas
For complex queries with aggregations:
- Remember that aggregation changes the available columns
- Use proper aggregate functions or add columns to
GROUP BY HAVINGclause has different column availability thanWHERE
For materialized views:
- The source table must have all columns referenced in the view query
- Schema changes to source tables can break materialized views
- Consider using
SELECT *cautiously as it can cause issues with schema evolution