Skip to main content

concat

Function concat 

Source
pub fn concat<'a, V, E1, E2>(
    expr1: E1,
    expr2: E2,
) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Text, <<E1 as Expr<'a, V>>::Nullable as NullOr<<E2 as Expr<'a, V>>::Nullable>>::Output, <<E1 as Expr<'a, V>>::Aggregate as AggOr<<E2 as Expr<'a, V>>::Aggregate>>::Output>
where V: SQLParam + 'a, E1: Expr<'a, V>, <E1 as Expr<'a, V>>::SQLType: Textual, E2: Expr<'a, V>, <E2 as Expr<'a, V>>::SQLType: Textual, <E1 as Expr<'a, V>>::Nullable: NullOr<<E2 as Expr<'a, V>>::Nullable>, <E2 as Expr<'a, V>>::Nullable: Nullability, <E2 as Expr<'a, V>>::Aggregate: AggregateKind, <E1 as Expr<'a, V>>::Aggregate: AggOr<<E2 as Expr<'a, V>>::Aggregate>,
Expand description

Concatenate two string expressions using || operator.

Nullability follows SQL concatenation rules: if either input is nullable, the result is nullable. string_concat is a compatibility alias.

§Type Safety

// ✅ OK: Both are Text
concat(users.first_name, users.last_name);

// ✅ OK: Text with string literal
concat(users.first_name, " ");

// ❌ Compile error: Int is not Textual
concat(users.id, users.name);

§Example

use drizzle_core::expr::concat;

// SELECT users.first_name || ' ' || users.last_name
let full_name = concat(concat(users.first_name, " "), users.last_name);