sfackler / rust-postgres

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

`postgres-types`: Can't insert oidvector #1025

Closed mstrydom closed 1 year ago

mstrydom commented 1 year ago

postgres-types does not seem to have built in support for oidvector. I tried to do this by inserting vec![1_u32, 2_u32] as a Vec<Oid>, but doing so results in:

invalid oidvector data

Which seems to come from this line in the Postgres codebase. It looks to me like Postgres assumes a lower_bound of 0, but ToSql of Vec is always setting it as 1.

Is there another way to send in oidvector as a bound parameter?

sfackler commented 1 year ago

https://docs.rs/postgres_array/latest/postgres_array/ provides more control over array types.

sfackler commented 1 year ago

Though we could (and probably should) update that ToSql impl to use a lower_bound of 0 when the target type is oidvector.

mstrydom commented 1 year ago

https://docs.rs/postgres_array/latest/postgres_array/ provides more control over array types.

I will take a look at that and see if it solves the problem. Thanks!

mstrydom commented 1 year ago

I can confirm that postgres_array does solve my problem, thanks! I did have to muck around with some extra formatting/to_string conversions to get it to format the same in Rust as in Postgres, so I still think having an explicit oidvector type might be nice. But feel free to resolve this issue if you do not agree that more work is warranted here.