postgrespp icon indicating copy to clipboard operation
postgrespp copied to clipboard

Strict field type checks in `.as<T>()`

Open AntonProtasovHub opened this issue 3 months ago • 1 comments

The current implementation of the library has field type checks via the size of the binary representation of the expected type. However, there may be situations when this check is successful, but the data type specified via the template parameter postgrespp::field::as<T> does not match the type in the database. For example, the database data type is double precision (8 bytes), and the as method template specifies the type std::uint64_t (8 bytes).

I have an idea how to add additional checks on the actual field type. For this, you can use the OID returned by the PQftype method. The decoder template instance will contain means for checking whether the actual OID matches the expected type.

Do you agree to accept such changes if I prepare a pull request? We can discuss specific interfaces if you agree to such a change.

P.S. Sorry for google translate, English is not my native language.

AntonProtasovHub avatar Aug 21 '25 17:08 AntonProtasovHub

Yeah that makes sense.

Do you agree to accept such changes if I prepare a pull request? We can discuss specific interfaces if you agree to such a change.

Sure.

tghosgor avatar Aug 22 '25 12:08 tghosgor