Re: libpq - description of columns

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: libpq - description of columns
Дата
Msg-id 5365.1022163962@sss.pgh.pa.us
обсуждение исходный текст
Ответ на libpq - description of columns  (Christian Gregoire <cgregoir99@yahoo.com>)
Ответы Re: libpq - description of columns
Список pgsql-interfaces
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


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: "Joel Burton"
Дата:
Сообщение: Re: no pg_hba.conf
Следующее
От: Ron Johnson
Дата:
Сообщение: Re: libpq - description of columns