From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Christian Gregoire <cgregoir99(at)yahoo(dot)com> |
Cc: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: libpq - description of columns |
Date: | 2002-05-23 14:26:02 |
Message-ID: | 5365.1022163962@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
Christian Gregoire <cgregoir99(at)yahoo(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Johnson | 2002-05-23 16:03:52 | Re: libpq - description of columns |
Previous Message | Joel Burton | 2002-05-23 13:07:11 | Re: no pg_hba.conf |