toString
Cast any ClickHouse value to a String — the universal type conversion function.
Signature
toString(value: Any): StringReturns
String
What it does
Converts any ClickHouse value to its string representation. Equivalent to CAST(col AS String). Handles all numeric types, dates, UUIDs, and IP addresses.
toString() is the universal type-cast in ClickHouse SQL. It is most commonly used when joining across tables that store IDs as different types (UInt64 vs String), when selecting for display (formatDateTime gives nicer date strings), or when inserting into a String column from a numeric source. For structured JSON output use JSONExtractString or toJSONString.
Notes
- For dates, toString returns ISO format. Use formatDateTime for custom display strings.
- toStringCutToZero() is like toString but stops at the first null byte — useful for FixedString columns.
- CAST(col AS String) and toString(col) are equivalent.
Example SQL
toString in ClickHouse SQL
TypeScript with hypequery
Use toString in a typed TypeScript query
hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like toString when you need them inside a builder query.
Common questions
What developers search for with toString
ClickHouse cast to string TypeScript
Use toString(col) to convert numbers, dates, or UUIDs to strings in ClickHouse SQL. hypequery maps ClickHouse types to TypeScript types via the generated schema.
FAQ
Frequently asked questions about toString
What is the difference between toString() and CAST(x AS String)?
They are equivalent — toString(x) is syntactic sugar for CAST(x AS String).
Related guides
Next step
Use toString in a type-safe TypeScript query
hypequery generates TypeScript types from your ClickHouse schema. Use toString alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.