Overview
Function Syntax
Function Chaining via the Dot Operator
SereneDB supports the dot syntax for function chaining. This allows the function call fn(arg1, arg2, arg3, ...) to be rewritten as arg1.fn(arg2, arg3, ...). For example, take the following use of the replace function:
SELECT replace(goose_name, 'goose', 'duck') AS duck_nameFROM unnest(['African goose', 'Faroese goose', 'Hungarian goose', 'Pomeranian goose']) breed(goose_name); duck_name----------------- African duck Faroese duck Hungarian duck Pomeranian duckThis can be rewritten as follows:
SELECT goose_name.replace('goose', 'duck') AS duck_nameFROM unnest(['African goose', 'Faroese goose', 'Hungarian goose', 'Pomeranian goose']) breed(goose_name); duck_name----------------- African duck Faroese duck Hungarian duck Pomeranian duckUsing with Literals and Arrays
Function chaining also works on literals and on the result of array access. Wrapping the argument in parentheses is optional, but makes the intent explicit:
SELECT ('hello world').replace(' ', '_'); replace------------- hello_worldSELECT (2).sqrt(); sqrt-------------------- 1.4142135623730951SELECT (m[1]).map_entries()FROM (VALUES ([MAP {'hello': 42}, MAP {'world': 42}])) t(m); map_entries---------------- {"(hello,42)"}Limitations
Function chaining via the dot operator is limited to scalar functions and is not supported for table functions.
For example, the following call returns a Parser Error:
SELECT * FROM ('my_file.parquet').read_parquet();db error: ERROR: syntax error at or near "."Additionally, the functions coalesce and ifnull cannot be used with function chaining for the time being:
SELECT (2).coalesce(0);
SELECT (2).ifnull(0);db error: ERROR: Scalar Function with name coalesce does not exist!Did you mean "(varies)"?
db error: ERROR: Scalar Function with name ifnull does not exist!Did you mean "fill"?Query Functions
The duckdb_functions() table function shows the list of functions currently built into the system.
SELECT DISTINCT ON(function_name) function_name, function_type, return_type, parameter_typesFROM sdb_functions()WHERE function_type = 'scalar' AND function_name LIKE 'b%'ORDER BY function_name; function_name | function_type | return_type | parameter_types---------------------------+---------------+-------------+------------------------------- bar | scalar | VARCHAR | {DOUBLE,DOUBLE,DOUBLE,DOUBLE} base64 | scalar | VARCHAR | {BLOB} bin | scalar | VARCHAR | {VARCHAR} bit_count | scalar | TINYINT | {TINYINT} bit_length | scalar | BIGINT | {VARCHAR} bit_position | scalar | INTEGER | {BIT,BIT} bitstring | scalar | BIT | {VARCHAR,INTEGER} bitstring_byte_comparable | scalar | BLOB | {BIT} bm25 | scalar | FLOAT | {BIGINT} broadcast | scalar | INET | {INET}In addition to the columns shown above, duckdb_functions() exposes the parameters and description columns, which provide the parameter names and a human-readable description (where available) for each function.