Christian Gregoire <cgregoir99@yahoo.com> writes:
> Using '\d TABLENAME', psql gives me
> character(15)
> for a column, when libpq API PQfsize returns -1 for
> the same column, whereas -1 should only indicate
> fields with variable size (like TEXT i guess). Any
> idea ?
Yes, char(N) is considered a variable-length type. (Think about
multibyte encodings to see why this must be so.) psql is looking
at the typmod (PQfmod) to find out what the char length limit is.
> I then looked at psql source code and it uses system
> tables to get descriptions of tables. Fine, but in my
> application, i have to get description of cursors,
> that is description of something like
> SELECT col1,col2,...,colN FROM
> table1,table2,...,tableN WHERE ....
> which are not known at compile time.
The cleanest solution would be to do
select format_type(typeOID, typmod)
where you can get the type OID and typmod of each column from libpq.
If that seems too slow, you'll need to cache results on the application
side and/or hard-wire some of what format_type knows into your
application.
regards, tom lane