Strings
Strings
The Strings module provides text and binary-string processing for Scheme and SQL compatibility. It includes:
- validation, length, concatenation, slicing, padding, trimming, and case conversion;
- splitting, searching, replacement, wildcard/regular-expression matching, and simplification;
- locale-aware collation and natural ordering;
- URL, HTML, Base64, hexadecimal, JSON, BSON, and SQL-string conversion;
- hashes, checksums, random data, and SQL-dialect compatibility functions.
Indexing and length semantics can differ between bytes and Unicode characters; consult each function's parameter description rather than assuming one unit for every operation.
string?
tells if the value is a string
Allowed number of parameters: 1–1
Parameters
- value (
any): value
Returns
- value (
bool)
concat
concatenates stringable values and returns a string
Allowed number of parameters: 1–10000
Parameters
- value (
any): first value to concat - more... (
any): additional values to concat (variadic)
Returns
- value (
string)
sql_concat
SQL CONCAT semantics: returns NULL if any argument is NULL
Allowed number of parameters: 1–10000
Parameters
- value (
any): first value to concat - more... (
any): additional values to concat (variadic)
Returns
- value (
any)
substr
returns a substring (0-based index)
Allowed number of parameters: 2–3
Parameters
- value (
string): string to cut - start (
number): first character index (0-based) - len (
number): optional length (optional)
Returns
- value (
string)
sql_substr
SQL SUBSTR/SUBSTRING with 1-based index and bounds checking
Allowed number of parameters: 2–3
Parameters
- value (
string): string to cut - start (
number): first character position (1-based) - len (
number): optional length (optional)
Returns
- value (
string)
simplify
Converts numeric text to a number. Text beginning with { or [ becomes a native JSON value when it is valid JSON; other input remains a string.
Allowed number of parameters: 1–1
Parameters
- value (
any): value to interpret as a number or JSON value
Returns
- value (
any)
strlen
returns the length of a string
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
int)
strlike
matches the string against a wildcard pattern using SQL NULL semantics
Allowed number of parameters: 2–3
Parameters
- value (
string): input string - pattern (
string): pattern with % and _ in them - collation (
string): collation in which to compare them (optional)
Returns
- value (
bool)
strlike_cs
matches the string against a wildcard pattern case-sensitively using SQL NULL semantics
Allowed number of parameters: 2–3
Parameters
- value (
string): input string - pattern (
string): pattern with % and _ in them - collation (
string): ignored (present for parser compatibility) (optional)
Returns
- value (
bool)
toLower
turns a string into lower case
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
toUpper
turns a string into upper case
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
replace
replaces all occurances in a string with another string
Allowed number of parameters: 3–3
Parameters
- s (
string): input string - find (
string): search string - replace (
string): replace string
Returns
- value (
string)
strtrim
trims whitespace from both ends of a string
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
strltrim
trims whitespace from the left of a string
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
strrtrim
trims whitespace from the right of a string
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
sql_trim
SQL TRIM(): NULL-safe trim of whitespace from both ends
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
sql_ltrim
SQL LTRIM(): NULL-safe trim of whitespace from left
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
sql_rtrim
SQL RTRIM(): NULL-safe trim of whitespace from right
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
split
splits a string using a separator or space
Allowed number of parameters: 1–2
Parameters
- value (
string): input string - separator (
string): (optional) parameter, defaults to " " (optional)
Returns
- value (
list)
string_repeat
repeats a string n times
Allowed number of parameters: 2–2
Parameters
- value (
string): string to repeat - count (
number): number of repetitions
Returns
- value (
string)
collate
returns a canonical order relation for a collation and direction. MemCP allows natural sorting of numeric literals.
Allowed number of parameters: 1–2
Parameters
- collation (
string): collation string of the form LANG or LANG_cs or LANG_ci where LANG is a BCP 47 code, for compatibility to MySQL, a CHARSET_ prefix is allowed and ignored as well as the aliases bin, danish, general, german1, german2, spanish and swedish are allowed for language codes - reverse (
bool): whether to reverse the order like in ORDER BY DESC (optional)
Returns
- relation (
func): compares two values using the selected collation and direction- Parameters
- a (
any): left operand - b (
any): right operand
- a (
- Returns
- ordered (
bool): whether a sorts before b
- ordered (
- Parameters
htmlentities
escapes the string for use in HTML
Allowed number of parameters: 1–1
Parameters
- value (
string): input string
Returns
- value (
string)
urlencode
encodes a string according to URI coding schema
Allowed number of parameters: 1–1
Parameters
- value (
string): string to encode
Returns
- value (
string)
urldecode
decodes a string according to URI coding schema
Allowed number of parameters: 1–1
Parameters
- value (
string): string to decode
Returns
- value (
string)
json_encode
encodes a value in JSON, treats lists as lists
Allowed number of parameters: 1–1
Parameters
- value (
any): value to encode
Returns
- value (
string)
json_quote
quotes a string as JSON
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_encode_assoc
encodes a value in JSON, treats lists as associative arrays
Allowed number of parameters: 1–1
Parameters
- value (
any): value to encode
Returns
- value (
string)
json_decode
parses JSON into a map
Allowed number of parameters: 1–1
Parameters
- value (
string): string to decode
Returns
- value (
any)
json_decode_scmer
parses JSON produced by json_encode and preserves Scheme symbols and lists
Allowed number of parameters: 1–1
Parameters
- value (
string): Scmer JSON to decode
Returns
- value (
any)
base64_encode
encodes a string as Base64 (standard encoding)
Allowed number of parameters: 1–1
Parameters
- value (
string): binary string to encode
Returns
- value (
string)
base64_decode
decodes a Base64 string (standard encoding)
Allowed number of parameters: 1–1
Parameters
- value (
string): base64-encoded string
Returns
- value (
string)
sql_unescape
unescapes the inner part of a sql string
Allowed number of parameters: 1–1
Parameters
- value (
string): string to decode
Returns
- value (
string)
bin2hex
turns binary data into hex with lowercase letters
Allowed number of parameters: 1–1
Parameters
- value (
string): string to encode
Returns
- value (
string)
bin2hex
turns binary data into hex with lowercase letters
Allowed number of parameters: 1–1
Parameters
- value (
string): string to encode
Returns
- value (
string)
hex2bin
decodes a hex string into binary data
Allowed number of parameters: 1–1
Parameters
- value (
string): hex string (even length)
Returns
- value (
string)
uuid
generates a new random UUID v4 string
Allowed number of parameters: 0–0
Parameters
This function has no parameters.
Returns
- value (
string)
randomBytes
returns a string with numBytes cryptographically secure random bytes
Allowed number of parameters: 1–1
Parameters
- numBytes (
number): number of random bytes
Returns
- value (
string)
regexp_replace
replaces matches of a regex pattern in a string
Allowed number of parameters: 3–3
Parameters
- str (
string): input string - pattern (
string): regex pattern - replacement (
string): replacement string
Returns
- value (
string)
fnv_hash
computes a fast non-cryptographic 64-bit FNV-1a hash of a string, returns a 16-character hex string
Allowed number of parameters: 1–1
Parameters
- str (
string): input string to hash
Returns
- value (
string)
stable_structural_hash
streams the string or serialized representation of a Scheme value into stable FNV-1a without constructing the complete representation
Allowed number of parameters: 1–2
Parameters
- value (
any): value to hash - serialize (
bool): use the Scheme serializer instead of string rendering (optional)
Returns
- value (
string)
sha1
computes the SHA-1 digest of a string, returns a 40-character lowercase hex string
Allowed number of parameters: 1–1
Parameters
- str (
string): input string to hash
Returns
- value (
string)
sha256
computes the SHA-256 digest of a string, returns a 64-character lowercase hex string
Allowed number of parameters: 1–1
Parameters
- str (
string): input string to hash
Returns
- value (
string)
regexp_test
tests if a string matches a regex pattern, returns true/false
Allowed number of parameters: 2–2
Parameters
- str (
string): input string - pattern (
string): regex pattern
Returns
- value (
bool)
json_parse_bson
validates JSON and returns a BSON-backed value
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_array
creates a MySQL-compatible JSON array
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_object
creates a MySQL-compatible JSON object
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_quote
quotes a string as JSON
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_unquote
unquotes a JSON string
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_valid
tests whether a value contains valid JSON
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_type
returns the MySQL JSON type name
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_depth
returns maximum JSON document depth
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_length
returns JSON object or array length
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_extract
extracts one or more JSON paths
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_keys
returns object member names
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_contains_path
tests whether one or all JSON paths exist
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_contains
tests JSON containment
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_overlaps
tests whether JSON values overlap
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_member_of
tests whether a JSON scalar is a member of an array
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_pretty
pretty-prints JSON
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_storage_size
returns BSON payload size
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_storage_free
returns unused BSON storage space
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_schema_valid
validates a document against a MySQL Draft 4 JSON schema
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_schema_validation_report
reports MySQL Draft 4 JSON schema validation
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_set
sets or inserts JSON path values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_insert
inserts missing JSON path values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_replace
replaces existing JSON path values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_remove
removes JSON path values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_array_append
appends values to JSON arrays
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_array_insert
inserts values into JSON arrays
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_merge_patch
merges documents using RFC 7396 semantics
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_merge_preserve
merges documents while preserving values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_search
searches JSON string values
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_value
extracts a scalar JSON value
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_to_json
implements PostgreSQL to_json and to_jsonb
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_row_to_json
implements PostgreSQL row_to_json
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_build_array
implements PostgreSQL JSON array builders
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_array_absent
implements SQL/JSON ARRAY ABSENT ON NULL
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_build_object
implements PostgreSQL JSON object builders
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_object
implements PostgreSQL json_object and jsonb_object array forms
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_serialize
implements PostgreSQL json_serialize
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_array_length
implements PostgreSQL json_array_length
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_extract_path
implements PostgreSQL json_extract_path
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_extract_path_text
implements PostgreSQL json_extract_path_text
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_set
implements PostgreSQL jsonb_set
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_set_lax
implements PostgreSQL jsonb_set_lax
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_insert
implements PostgreSQL jsonb_insert
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_strip_nulls
implements PostgreSQL json_strip_nulls
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_typeof
implements PostgreSQL json_typeof
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_populate_record_valid
validates PostgreSQL jsonb_populate_record input shape
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_concat
implements PostgreSQL jsonb concatenation
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_delete
implements PostgreSQL jsonb deletion
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_delete_path
implements PostgreSQL jsonb path deletion
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_subtract
dispatches PostgreSQL numeric and jsonb subtraction
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_exists
implements PostgreSQL jsonb top-level existence
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_path_exists
implements PostgreSQL jsonb_path_exists
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_path_match
implements PostgreSQL jsonb_path_match
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_path_query_array
implements PostgreSQL jsonb_path_query_array
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_jsonb_path_query_first
implements PostgreSQL jsonb_path_query_first
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_value
implements PostgreSQL SQL/JSON JSON_VALUE
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_get
implements PostgreSQL JSON object and array extraction
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_arrayagg_entry
wraps one JSON_ARRAYAGG input value
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_arrayagg_reduce
JSON_ARRAYAGG reducer
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_arrayagg_finalize
builds one BSON array from a collected JSON_ARRAYAGG value list
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_objectagg_entry
constructs a JSON_OBJECTAGG key/value entry
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
json_objectagg_reduce
JSON_OBJECTAGG reducer
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)
pg_json_table_rows
materializes a PostgreSQL JSON table function as rows
Allowed number of parameters: 0–10000
Parameters
- arguments (
any) (variadic)
Returns
- value (
any)