Repository: diesel-rs/diesel
File: diesel/src/pg/expression/functions.rs (Rust)

Code before:
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_to_string_with_null_string;
    /// #     use diesel::sql_types::{Nullable, Text, Array};
    /// #     let connection = &mut establish_connection();
    ///
    /// let result = diesel::select(array_to_string_with_null_string::<Array<_>, Nullable<Text>, _, _, _, _>(
    ///     vec![Some("first"), None, Some("third")], ",", "NULL"))
    ///     .get_result::<String>(connection)?;
    ///
    /// assert_eq!(result, "first,NULL,third");
    /// #     Ok(())
    /// # }
    /// ```
    fn array_to_string_with_null_string<Arr: ArrayOrNullableArray<Inner=Nullable<Text>> + SingleValue, T: SingleValue, N: SingleValue>(
        a: Arr,
        e: T,
        n: N
    ) -> Text;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Converts each array element to its text representation, and concatenates those elements
    /// separated by the delimiter string. This variant omits the `null_string` argument. See [`array_to_string_with_null_string`]
    /// for a variant with that argument
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_to_string;
    /// #     use diesel::sql_types::{Text, Array};
    /// #     let connection = &mut establish_connection();
    ///
    /// let result = diesel::select(array_to_string::<Array<_>, Nullable<Text>, _, _>(
    ///     vec![Some("first"), Some("second")], ","))
    ///     .get_result::<String>(connection)?;

Review comment (suggestion):
```suggestion
    #[sql_name = "array_to_string"]
    fn array_to_string_with_null_string<Arr: ArrayOrNullableArray + SingleValue>(array: Arr, del: Text, null: Text) -> Text;
```

For similar reasons as outlined for the `array_to_string` function. The `#[sql_name]` attribute is required to use the right sql function name in the generated sql

Code after:
    /// assert_eq!(None, ints);
    /// #    Ok(())
    /// # }
    /// ```
    fn array_replace<Arr: ArrayOrNullableArray<Inner=T> + SingleValue, T: SingleValue>(a: Arr, e: T, r: T) -> Arr;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Returns a text representation of the array's dimensions
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main(){
    /// #    run_test().unwrap();
    /// # }
    /// # fn run_test()->QueryResult<()>{
    /// #   use diesel::dsl::array_dims;
    /// #   use diesel::sql_types::{Nullable,Array,Integer};
    /// #   let connection = &mut establish_connection();
    ///
    /// let dims = diesel::select(array_dims::<Array<Integer>,_>(vec![1,2]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:2]").eq(&dims));
    ///
    /// let dims = diesel::select(array_dims::<Array<Nullable<Integer>>,_>(vec![None::<i32>,Some(2)]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:2]").eq(&dims));
    ///
    /// let dims = diesel::select(array_dims::<Array<Nullable<Integer>>,_>(vec![None::<i32>]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:1]").eq(&dims));
    /// # Ok(())
    /// # }
    ///
    fn array_dims<Arr:ArrayOrNullableArray<> + SingleValue>(arr:Arr) -> Text;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Prepends an element to the beginning of an array
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {