sfackler / rust-postgres

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

Access to column type via Inner enum? #1129

Closed mydoghasfleas closed 6 months ago

mydoghasfleas commented 6 months ago

Hi, I would like to match on the type of a column in order to handle column values dynamically.

It seems that the possible types are defined in the Inner enum in type_gen.rs, but I cannot access it.

The other option would be to match on the Oid value accessible from the column type, but this does not seem like a great way to determine the column type at runtime.

Does the library offer any better way to do this? Thanks.

sfackler commented 6 months ago

Just match on the type:

match some_type {
    Type::TEXT => {},
    Type::INT8 => {},
    // ...
}
mydoghasfleas commented 6 months ago

Oh thanks, I don't know why I did not see that before! That does the trick. Thanks very much!