diesel::pg::expression::dsl

Function array_to_string

Source
pub fn array_to_string<Arr: ArrayOrNullableArray + SingleValue, array, del>(
    array: array,
    del: del,
) -> array_to_string<Arr, array, del>
where array: AsExpression<Arr>, del: AsExpression<Text>,
Available on crate feature postgres_backend only.
Expand description

Converts each array element to its text representation and concatenates those elements separated by the delimiter string. NULL entries are omitted in this variant. See [array_to_string_with_null_string] for a variant with that argument.

ยงExample


// Example with non-null values
let result: String = diesel::select(array_to_string::<Array<Nullable<Text>>, _, _>(
    vec![Some("first"), Some("second")], ","))
    .get_result(connection)?;
assert_eq!(result, "first,second");

// Example with `NULL` values (omitted in the result)
let result: String = diesel::select(array_to_string::<Array<Nullable<Text>>, _, _>(
    vec![Some("first"), None::<&str>, Some("third")], ","))
    .get_result(connection)?;
assert_eq!(result, "first,third");

// Example with only `NULL` values (empty result)
let result: String = diesel::select(array_to_string::<Array<Nullable<Text>>, _, _>(
    vec![None::<&str>, None::<&str>], ","))
    .get_result(connection)?;
assert_eq!(result, "");