The corresponding function in the C client library is PQftype. It provides the type of any field from a query, as described in Retrieving Query Result Information, with other functions that apply on result fields, such as PQftable or PQfsize.
No EXPLAIN is needed, this information is shipped with every set of result coming back to a SQL client.
PQftype
Returns the data type associated with the given column number.
The integer returned is the internal OID number of the type. Column
numbers start at 0.
Oid PQftype(const PGresult *res,
int column_number);
You can query the system table pg_type to obtain the names and properties
of the various data types. The OIDs of the built-in data
types are defined in the file src/include/catalog/pg_type.h in the
source tree.
Additionally the OIDs of all types of a database can be obtained with:
select oid, typname from pg_type;
Other languages generally base their postgres support on libpq library, so they can call this function. They may or may not expose it depending on how complete their implementation is.
In the case of ruby, the ruby-pg driver apparently does it through PGResult's
ftype(column_number) instance method. I don't know if this is of any help with ActiveRecord. Database-agnostic APIs tend to leave out functions that can't be easily abstracted across all the databases they support.
COUNT(*)is abigintneither learn about applied type conversions. Or maybe I don't get purpose of information schema?