pub struct Expression { /* private fields */ }Expand description
RAII wrapper for a duckdb_expression.
Automatically destroyed when dropped.
Implementations§
Source§impl Expression
impl Expression
Sourcepub const unsafe fn from_raw(raw: duckdb_expression) -> Self
pub const unsafe fn from_raw(raw: duckdb_expression) -> Self
Wraps a raw duckdb_expression handle, taking ownership.
§Safety
raw must be a valid duckdb_expression returned by a DuckDB API call
(e.g. duckdb_scalar_function_bind_get_argument). The caller must not
destroy the handle after this call.
Sourcepub const fn as_raw(&self) -> duckdb_expression
pub const fn as_raw(&self) -> duckdb_expression
Returns the raw handle without consuming the Expression.
Sourcepub fn return_type(&self) -> Option<LogicalType>
pub fn return_type(&self) -> Option<LogicalType>
Returns the static return type of this expression, or None if the
handle is null.
Sourcepub fn is_foldable(&self) -> bool
pub fn is_foldable(&self) -> bool
Sourcepub fn fold(&self, context: &ClientContext) -> Result<Value, ErrorData>
pub fn fold(&self, context: &ClientContext) -> Result<Value, ErrorData>
Folds this (constant) expression into a single Value.
Only succeeds when is_foldable returns
true.
The returned Value always has a non-null handle, but may hold SQL
NULL (fold of NULL::INTEGER); its typed getters return None for
that.
§Errors
Returns the structured ErrorData if evaluation fails, and an
DuckDbErrorType::InvalidInput error when the expression handle is
null or the expression is not foldable (for example it references a
column). duckdb_expression_fold reports that last case by returning
no error and leaving the output value unset.
For an evaluation failure, DuckDB 1.5.5 builds the error from
ex.what() — the exception’s JSON form, such as
{"exception_type":"Conversion","exception_message":"Could not convert string 'abc' to INT64",...} — and always tags it INVALID_INPUT
(src/main/capi/expression-c.cpp). This unpacks it: the returned error
carries the plain exception_message and the
DuckDbErrorType named by exception_type. Text that does not parse
as that JSON is returned unchanged, still typed InvalidInput.