sfackler / rust-postgres

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

Type::from_oid doesn't support oid of 0 #993

Closed lukoktonos closed 1 year ago

lukoktonos commented 1 year ago

We recently ran into this with our Parse message decoder, and handled it with some special logic for when the oid is 0, but it may make sense to bake this into Type::from_oid itself.

I am not entirely sure if that is appropriate for all the contexts Type can be used, so if this is a special case or something, maybe the only thing to do here would be update the from_oid documentation about this gotcha case.

To Reproduce:

use postgres_types::Type;

Type::from_oid(0u32).unwrap();

https://www.postgresql.org/docs/current/protocol-message-formats.html

Parse (F)
...
Int32

    Specifies the object ID of the parameter data type. Placing a zero here is equivalent to leaving the type unspecified.
sfackler commented 1 year ago

As the docs for Type::from_oid indicate, it will only return Some for OIDs that correspond to one of the built in types. There is no built in type with an OID of 0.