pub struct TypedScalarFunctionBuilder { /* private fields */ }Expand description
A scalar function built from a safe Rust closure, ready to register.
Returned by ScalarFunctionBuilder::map1 and its siblings. The SQL
signature is fixed by the closure’s type, so this builder deliberately has
no returns, param, function, extra_info, bind or init: each of
those could make DuckDB hand the closure vectors of a different type than
it reads and writes.
use quack_rs::scalar::ScalarFunctionBuilder;
use quack_rs::types::TypeId;
// An i64 result cannot be redeclared as a 4-byte INTEGER.
let _ = ScalarFunctionBuilder::map1("widen", |x: i64| x + 1)?.returns(TypeId::Integer);use quack_rs::scalar::ScalarFunctionBuilder;
quack_rs::scalar_callback!(other, |_info, _input, _output| {});
// The trampoline cannot be swapped out from under the closure's state.
let _ = ScalarFunctionBuilder::map1("f", |x: i64| x)?.function(other);Implementations§
Source§impl TypedScalarFunctionBuilder
impl TypedScalarFunctionBuilder
Sourcepub fn volatile(self) -> Self
pub fn volatile(self) -> Self
Marks this function as volatile: re-evaluated for every row even when its arguments are constant (e.g. a random-number function).
Only the function’s stability changes; its signature does not.
Sourcepub unsafe fn register(
self,
con: duckdb_connection,
) -> Result<(), ExtensionError>
pub unsafe fn register( self, con: duckdb_connection, ) -> Result<(), ExtensionError>
Registers the function on the given connection.
§Errors
Returns ExtensionError if a scalar function with this name and
parameter types already exists (which DuckDB would silently replace
or make ambiguous), or if DuckDB reports a registration failure — for
example, the name belongs to an aggregate function or a macro. See
ScalarFunctionBuilder::register for the collision rules.
§Safety
con must be a valid, open duckdb_connection.