sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.43k stars 436 forks source link

array of custom types serialization fails #1157

Closed ash-hashtag closed 2 months ago

ash-hashtag commented 2 months ago

reproduction

CREATE TYPE Foo AS (
id UUID,
val BOOLEAN
);

CREATE FUNCTION ProcessFoos(foos FOO[])
RETURNS void AS
$$
BEGIN
 -- do something with foos
END;
$$ LANGUAGE plpgsql;

#[derive(postgres_types::ToSql, Debug)]
struct Foo {
   id: Uuid,
   val: Option<bool>
} 
let aSliceOfFoos = vec![ Foo { id: Uuid::max(), val: Some(true) } ];
client.query("SELECT ProcessFoos($1)", &[&aSliceOfFoos]]).await.unwrap();

returns error

Error occurred while creating a new object: error serializing parameter 0: cannot convert between the Rust type `&[Foo]` and the Postgres type `_foo`

I don't know if the _ represents array or maybe it is assuming &[Foo] as a single Foo and trying to serialize it that way?

ash-hashtag commented 2 months ago

my fault, its just alphabetic casing issue, I expected postgres to not care about it, because its mostly case insensitive.

if anyone runs into same mistake

https://github.com/sfackler/rust-postgres/issues/940#issuecomment-1221608392