Skip to main content

Scalar Functions — Type Conversion

Type conversion functions cast values between KQL's scalar types. The basic numeric and string casts work across all dialects. More advanced conversions like toguid() and gettype() are only available in ClickHouse, PostgreSQL, and DuckDB. typeof() has no SQL equivalent and is not supported in any dialect.

Legend: ✅ Supported · ⚠️ Approximated · ❌ Not Supported · 🔄 Rewritten

FunctionSQLiteMySQLClickHousePostgreSQLDuckDBNotes
tostring()SQLite/Postgres: TEXT; MySQL: CHAR; DuckDB: VARCHAR
todouble() / toreal()CAST(... AS REAL); DuckDB: DOUBLE
toint() / tolong()SQLite/PostgreSQL/DuckDB: CAST(... AS BIGINT); MySQL: CAST(... AS SIGNED); ClickHouse: toInt64() (not a CAST)
tobool()SQLite/Postgres: INTEGER; MySQL: SIGNED; DuckDB: BOOLEAN
todatetime()Postgres/DuckDB: CAST(... AS TIMESTAMP); MySQL: DATETIME; SQLite: datetime()
totimespan()⚠️⚠️⚠️Postgres/DuckDB: CAST(... AS INTERVAL); MySQL/SQLite/ClickHouse approximate as seconds
todecimal()CAST(... AS DECIMAL); MySQL: DECIMAL(38,10)
todynamic() / toobject()Postgres: jsonb; DuckDB: JSON; MySQL: JSON_EXTRACT
toguid()ClickHouse: toUUID; Postgres/DuckDB: CAST(... AS UUID)
gettype()ClickHouse: toTypeName; Postgres: pg_typeof; DuckDB: typeof
typeof()Compile-time hint; no SQL equivalent