use pgx::prelude::*;
use pgx::{direct_function_call, AnyArray, IntoDatum, Json};
#[pg_extern]
fn anyarray_arg(array: AnyArray) -> Json {
unsafe { direct_function_call::<Json>(pg_sys::array_to_json, vec![array.into_datum()]) }
.expect("conversion to json returned null")
}
#[cfg(any(test, feature = "pg_test"))]
#[pgx::pg_schema]
mod tests {
#[allow(unused_imports)]
use crate as pgx_tests;
use pgx::prelude::*;
use pgx::Json;
use serde_json::*;
#[pg_test]
fn test_anyarray_arg() -> std::result::Result<(), pgx::spi::Error> {
let json = Spi::get_one::<Json>("SELECT anyarray_arg(ARRAY[1::integer,2,3]::integer[]);")?
.expect("datum was null");
assert_eq!(json.0, json! {[1,2,3]});
Ok(())
}
}