Error 386: NO_COMMON_TYPE
This error occurs when ClickHouse cannot find a common (super) type to unify different data types in operations that require type compatibility—such as UNION, CASE statements, IF expressions, or array operations. This typically happens when trying to combine incompatible types like String and Integer, or signed and unsigned integers of different ranges.
Quick reference
What you'll see:
Or:
Most common causes:
- UNION ALL with incompatible types (String and numeric, signed vs unsigned integers)
- IF/CASE expressions with different return types
- AggregateFunction mixed with regular types in CASE statements
- Array operations requiring consistent element types
- Dynamic/JSON column type mismatches (25.x+ versions)
Quick diagnostic:
Check the types involved:
Quick fixes:
Most common causes
1. UNION with incompatible types
The most common cause—trying to UNION queries that return fundamentally different types.
2. IF/CASE expressions with mixed types
3. AggregateFunction mixed with regular types
This is a subtle error when working with AggregatingMergeTree tables:
4. Array operations with mixed types
5. Dynamic/JSON column type mismatches (25.x+)
Starting in ClickHouse 25.x with stable JSON/Dynamic types:
6. Signed vs Unsigned integer range issues
Common solutions
1. Explicit type casting to common type
2. Use appropriate merge functions for AggregateFunctions
3. Handle Dynamic/JSON columns explicitly (25.x+)
4. Restructure CASE/IF to return consistent types
5. Use widest compatible numeric type
6. Enable Variant type for UNION (future versions)
Starting from a future ClickHouse version (PR in progress):
7. Fix array homogeneity
Prevention tips
-
Plan your type schema carefully: When designing tables, ensure columns that will be combined in UNION or comparisons have compatible types.
-
Be explicit with casts: Don't rely on implicit type conversion—use explicit CAST or type conversion functions.
-
Understand signed vs unsigned limits: Be aware that combining signed and unsigned integers can fail if the unsigned value exceeds what the signed type can represent.
-
Use Nullable consistently: If one branch returns Nullable, ensure all branches do:
-
For Dynamic/JSON columns (25.x+): Always cast to specific type before comparison:
-
Test UNION queries incrementally: Test each SELECT in a UNION separately to identify type mismatches.
-
Use
toTypeName()for debugging:
Related error codes
- Error 258:
UNION_ALL_RESULT_STRUCTURES_MISMATCH- Column count or structure mismatch in UNION - Error 53:
TYPE_MISMATCH- General type mismatch error - Error 70:
CANNOT_CONVERT_TYPE- Type conversion failure
Additional resources
ClickHouse documentation:
- Data Types - Understanding ClickHouse type system
- Type Conversion Functions - CAST and conversion functions
- UNION Clause - UNION behavior and type unification
- Dynamic Type - Working with Dynamic columns (25.x+)
- JSON Type - Working with JSON columns (25.x+)
- Variant Type - Variant type for mixed types