Skip to main content

string_concat

Function string_concat 

Source
pub fn string_concat<'a, V, L, R>(
    left: L,
    right: R,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Text, <L::Nullable as NullOr<R::Nullable>>::Output, <L::Aggregate as AggOr<R::Aggregate>>::Output>
where V: SQLParam + 'a, L: Expr<'a, V>, R: Expr<'a, V>, L::SQLType: Textual, R::SQLType: Textual, L::Nullable: NullOr<R::Nullable>, R::Nullable: Nullability, L::Aggregate: AggOr<R::Aggregate>, R::Aggregate: AggregateKind,
Expand description

Concatenate two string expressions using dialect-appropriate SQL.

Requires both operands to be Textual (Text or VarChar). Nullability follows SQL concatenation rules: nullable input -> nullable output. SQLite and PostgreSQL render left || right; MySQL renders CONCAT(left, right) because || is logical OR under its default SQL mode.

§Type Safety

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

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

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

§Example

use drizzle_core::expr::string_concat;

// SQLite/PostgreSQL: first_name || ' ' || last_name
// MySQL: CONCAT(CONCAT(first_name, ' '), last_name)
let full_name = string_concat(string_concat(users.first_name, " "), users.last_name);