md5
Computes the MD5 hash of a string. Syntaxs— the string to hash.
- The raw 128-bit MD5 digest as a 16-byte binary value. Wrap it in
hex()— orlower(hex(...))to match PostgreSQL’s lowercase output — to render it as a hexadecimal string, as shown in the example.
Hash a user's email
base64Encode
Encodes a string as Base64, following RFC 4648. Syntaxplaintext— the string to encode.
- The Base64-encoded value as a string.
Encode a string as Base64
base64Decode
Decodes a Base64-encoded string back to its original value, following RFC 4648. Raises an error if the input is not valid Base64. Syntaxencoded— the Base64-encoded string to decode.
- The decoded value as a string.
Decode a Base64 string
hex
Returns the hexadecimal representation of the argument, using uppercase lettersA-F and no 0x prefix. For string inputs, every byte is encoded as two hexadecimal digits and leading zero bytes are preserved. For numeric inputs, the output starts at the most significant non-zero byte, so leading zero bytes are omitted.
Syntax
x— the value to encode. Accepts a string or a numeric value.
- The uppercase hexadecimal representation as a string.
Hex-encode a string
unhex
Performs the inverse ofhex: interprets each pair of hexadecimal digits as a byte and returns the decoded value. The input is case-insensitive.
Syntax
s— a string of hexadecimal digits.
- The decoded value as a string.
Decode a hex string
to_hex
Returns the hexadecimal representation of an integer. The output is lowercase and leading zeros are stripped, matching PostgreSQL’sto_hex.
Syntax
n— the integer to convert.
- The lowercase hexadecimal representation as a string, without leading zeros.
Convert an integer to hex
toUUID
Parses a string into a UUID value. Raises an error if the string is not a valid UUID. Syntaxs— a string containing a UUID in the standard 8-4-4-4-12 hyphenated form.
- The parsed value as a UUID.
Parse a string into a UUID
cityHash64
Computes a fast, non-cryptographic 64-bit CityHash of its arguments. Useful for bucketing or sampling, not for security. When multiple arguments are passed, their hashes are combined (ClickHouse only). Syntaxarg1[, arg2, ...]— one or more values of any type to hash.
- The 64-bit hash as a UInt64.
Bucket users into 10 groups by hash
touuidornull
Parses a string into a UUID, returning NULL instead of raising an error when the input is not a valid UUID (ClickHouse only). Syntaxs— a string that may or may not contain a valid UUID.
- The parsed value as a UUID, or NULL if the input is not a valid UUID.
Safely parse a possibly-invalid UUID
trybase64decode
Decodes a Base64-encoded string, returning an empty string instead of raising an error when the input is not valid Base64 (ClickHouse only). Syntaxencoded— the string to decode.
- The decoded value as a string, or an empty string if the input is not valid Base64.
Safely decode a possibly-invalid Base64 string