pub fn cast<'a, V, E, Target>(
expr: E,
target_type: impl CastTarget<'a, Target, V::DialectMarker>,
) -> SQLExpr<'a, V, Target, E::Nullable, E::Aggregate>where
V: SQLParam + 'a,
E: Expr<'a, V>,
Target: DataType,
(): CastTypePolicy<V::DialectMarker, E::SQLType, Target>,Expand description
Cast an expression to a different type.
The target type marker specifies the result type for the type system. The cast target may be:
- a SQL type string (
"INTEGER","int4","VARCHAR(255)"), or - a type marker value (
Int,Text,drizzle::sqlite::types::Integer, …).
Preserves the input expression’s nullability and aggregate marker.
§Example
use drizzle_core::expr::cast;
use drizzle_core::types::{Int, Text};
// SELECT CAST(users.age AS TEXT)
let age_text = cast::<_, _, Text>(users.age, Text);
// Explicit SQL type name (dialect-specific)
let age_text = cast::<_, _, Text>(users.age, "VARCHAR(255)");
let age_int = cast::<_, _, Int>(users.age, "int4");