Accessing column types in postgres_types (tokio_postgres)

I am using tokio_postgres and 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 postgres_types library in the Inner enum in type_gen.rs, but I cannot access it, as it is private.

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

There is also .type_().name() but then I am matching on a &str, which seems like it would be less performant than matching on an integer or enum?

Is there a better way of getting at the column type?

I got an answer from the postgres_types author on Github:

Just match on the type:

match some_type {
    Type::TEXT => {},
    Type::INT8 => {},
    // ...
}

That of course did the trick.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.