NO_COMMON_TYPE ClickHouse® error¶
This error usually means you're trying to combine or compare values of incompatible types. ClickHouse® can't automatically convert between these types, so you need to use explicit type casting.
The NO_COMMON_TYPE error in ClickHouse® (and Tinybird) happens when you try to perform operations between values of incompatible types, and ClickHouse® can't determine a common type for the operation. This commonly occurs in comparisons, arithmetic operations, or when combining different data types.
What causes this error¶
You typically see it when:
- Comparing values of different types (for example, String vs Int)
- Performing arithmetic operations on mixed types
- Using UNION with incompatible column types
- Combining columns with different data types in expressions
- Using functions that expect specific types but receive others
Example errors¶
SELECT if(user_id = 123, 'user_123', user_id) FROM events
SELECT value + '10' FROM events
SELECT user_id FROM events
UNION ALL
SELECT email FROM users
SELECT CASE
WHEN user_id = 123 THEN 'user_123'
WHEN user_id = 456 THEN user_id
END FROM events
How to fix it¶
Use explicit type casting¶
Convert values to compatible types using CAST or type conversion functions:
SELECT * FROM events WHERE user_id = toInt32('123')
SELECT value + toInt32('10') FROM events
Use proper type conversion functions¶
ClickHouse® provides specific conversion functions for different types:
SELECT * FROM events WHERE user_id = toInt32(user_id_string)
SELECT toString(user_id) as user_id_str FROM events
Fix UNION queries¶
Ensure all columns in UNION have compatible types:
SELECT toString(user_id) as id FROM events
UNION ALL
SELECT email as id FROM users
Common patterns and solutions¶
String vs Numeric comparisons¶
When comparing strings with numbers:
SELECT if(user_id = 123, 'user_123', user_id) FROM events
WHERE user_id = toInt32('123')
WHERE toString(user_id) = '123'
Date and DateTime operations¶
When working with dates and timestamps:
WHERE date_column = now()
WHERE toDate(date_column) = toDate(now())
Array operations¶
When working with arrays of different types:
SELECT [1, 2, 3] + ['a', 'b', 'c']
SELECT [toString(1), toString(2), toString(3)] + ['a', 'b', 'c']
Advanced solutions¶
Using CASE statements with mixed types¶
Convert all branches to a common type:
SELECT CASE
WHEN user_id = 123 THEN 'user_123'
WHEN user_id = 456 THEN 'user_456'
ELSE toString(user_id)
END as user_label FROM events
Working with JSON data¶
When extracting values from JSON:
SELECT
toInt32(JSONExtractRaw(data, 'user_id')) as user_id,
toString(JSONExtractRaw(data, 'event_type')) as event_type
FROM events
Handling NULL values¶
Be careful with NULL values in type conversions:
SELECT toInt32OrZero(user_id_string) as user_id FROM events
Tinybird-specific notes¶
In Tinybird, this error often occurs when:
- Data Sources have inconsistent data types in the same column
- Pipes try to combine data from different sources with incompatible schemas
- Schema inference assigns wrong types to columns
- JSON data contains mixed types
To debug in Tinybird:
- Check your Data Source schema for type consistency
- Use Schema Hints to enforce proper types
- Add explicit CAST operations in your Pipes
- Validate incoming data types in Data Sources
Type conversion functions¶
Common ClickHouse® type conversion functions:
toInt8(),toInt16(),toInt32(),toInt64()- Convert to integerstoUInt8(),toUInt16(),toUInt32(),toUInt64()- Convert to unsigned integerstoFloat32(),toFloat64()- Convert to floating pointtoString()- Convert to stringtoDate(),toDateTime()- Convert to date/time typestoUUID()- Convert to UUID