pub fn array_to_string_with_null_string<Arr: ArrayOrNullableArray + SingleValue, array, del, null>(
array: array,
del: del,
null: null,
) -> array_to_string_with_null_string<Arr, array, del, null>
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. If null_string
is provided and is not NULL
, then NULL
array entries are represented by that string; otherwise, they are omitted.
ยงExample
// Example with `NULL` representation as a string
let result: String = diesel::select(array_to_string_with_null_string::<Array<Nullable<Text>>, _, _, _>(
vec![Some("first"), None::<&str>, Some("third")], ",", "NULL"))
.get_result(connection)?;
assert_eq!(result, "first,NULL,third");
// Example without any `NULL` values
let result: String = diesel::select(array_to_string_with_null_string::<Array<Nullable<Text>>, _, _, _>(
vec![Some("first"), Some("second")], ",", "NULL"))
.get_result(connection)?;
assert_eq!(result, "first,second");
// Example with all `NULL` values
let result: String = diesel::select(array_to_string_with_null_string::<Array<Nullable<Text>>, _, _, _>(
vec![None::<&str>, None::<&str>], ",", "NULL"))
.get_result(connection)?;
assert_eq!(result, "NULL,NULL");