Skip to main content

Conversion Functions

Conversion functions cast values between CamusDB scalar types. NULL input returns NULL.

You can use either explicit conversion functions or SQL CAST syntax:

SELECT to_string(year) AS year_text
FROM robots;

SELECT CAST(year AS string) AS year_text
FROM robots;

Functions

FunctionReturnsDescription
to_string(value)STRINGConverts STRING, OID, UUID, INT64, FLOAT64, or BOOL to text. UUID values use canonical lowercase hyphenated text. Booleans become true or false.
to_int64(value)INT64Converts INT64, FLOAT64, BOOL, or integer text. Floats are truncated toward zero. Booleans become 1 or 0.
to_float64(value)FLOAT64Converts FLOAT64, INT64, BOOL, or numeric text. Booleans become 1.0 or 0.0.
to_float32(value)FLOAT32Converts numeric values or numeric text to single precision.
to_bool(value)BOOLConverts BOOL or text equal to true or false, case-insensitively.
to_date(value)DATEConverts a date/datetime value or yyyy-MM-dd text to a date.
to_datetime(value)DATETIMEConverts a date/datetime value or ISO-8601 text to a UTC datetime.
to_bytes(value)BYTESConverts bytes or 0x-prefixed hex text to bytes. SQL bytes literals can be written directly as X'...'.
to_id(value)OIDConverts an OID or a 24-character lowercase hex string to an object id.
str_id(value)OIDAlias for to_id(value).

CAST Targets

CAST(value AS type) accepts the following targets:

TargetResult Type
string, char, varchar, textSTRING
int, int64, integer, smallintINT64
float, float64, doubleFLOAT64
float32, realFLOAT32
bool, booleanBOOL
oid, id, object_idOID
uuid, guidUUID
dateDATE
datetime, timestampDATETIME
bytes, blobBYTES

Examples

SELECT to_int64("42"), to_float64("42.5"), to_bool("TrUe");
-- 42, 42.5, true

SELECT to_date("2026-03-15"), to_datetime("2026-03-15T12:00:00Z");

SELECT X'DEADBEEF';

SELECT CAST("0xDEADBEEF" AS bytes);

SELECT CAST("550e8400-e29b-41d4-a716-446655440000" AS uuid);

SELECT CAST(CAST(7 AS string) AS int64);
-- 7

SELECT name
FROM robots
WHERE CAST(year AS string) = "42";

SELECT id
FROM robots
WHERE id = str_id("507f1f77bcf86cd799439011");

Error Cases

Invalid conversions fail the query. Examples include non-numeric text passed to numeric conversion functions, non-boolean text passed to to_bool, malformed date/datetime text, malformed UUID text, malformed byte hex text, non-finite floating-point values, integer overflow, and object id strings that are not 24 lowercase hex characters.

Conversion errors include the offending value and a short hint about the expected format, such as a valid UUID string, a 64-bit integer, or a number.