class DuckDB::Expression
DuckDB::Expression represents a DuckDB expression object.
Instances are returned by DuckDB::ScalarFunction::BindInfo#get_argument during the bind phase of a scalar function.
Public Instance Methods
Source
# File lib/duckdb/expression.rb, line 18 def fold(client_context) raise DuckDB::Error, 'expression is not foldable' unless foldable? _fold(client_context) end
Evaluates the expression at planning time and returns a DuckDB::Value holding the constant result. Raises DuckDB::Error if the expression is not foldable.
sf.set_bind do |bind_info| expr = bind_info.get_argument(0) client_context = bind_info.client_context value = expr.fold(client_context) # => DuckDB::Value end
Source
static VALUE rbduckdb_expression_foldable_p(VALUE self) {
rubyDuckDBExpression *ctx;
TypedData_Get_Struct(self, rubyDuckDBExpression, &expression_data_type, ctx);
return duckdb_expression_is_foldable(ctx->expression) ? Qtrue : Qfalse;
}
Returns true if the expression can be folded to a constant at query planning time (e.g. literals, constant arithmetic), false otherwise (e.g. column references, non-deterministic functions).