pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.7k stars 249 forks source link

How to pass a array/vec of strings as arguments to a SPI select? #1947

Open lizardoluis opened 2 days ago

lizardoluis commented 2 days ago

Hi PGRX team,

How can I run the following query, where I have a WHERE IN clause. I need to pass a vec or array of strings to it as argument. Which PgBuiltInOids should I use in this case?

I tried the form below without success.

let names: Vec<&str> = ["name1", "name2"];

Spi::connect(|client| {
        let result = client
            .select("SELECT * FROM mytable WHERE name IN ($1);",
                None,
                Some(vec![(PgBuiltInOids::TEXTARRAYOID.oid(), names.as_slice().into_datum())]),
            )
            .unwrap_or_report()
            .collect::<Vec<_>>();
    });