Re: How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?
Дата
Msg-id 4074.1004233548@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?  (Gilberto Ribeiro de Queiroz <gribeiro@dpi.inpe.br>)
Список pgsql-interfaces
Gilberto Ribeiro de Queiroz <gribeiro@dpi.inpe.br> writes:
> I am needing to recover the size of the resulting fields of a given 
> query

You need the type OID and the "typmod" associated with the column.
These are provided by PQftype and PQfmod respectively in libpq.
The cleanest way to get from there to a type description is to
invoke the backend's format_type function, eg (random example)

test71=# select format_type(1700,1704000); format_type
----------------numeric(26,60)
(1 row)

But if you don't want to expend another query to get the answer,
you could hard-wire some knowledge in your program.  Look at the
source code of format_type to see what it knows about typmod
interpretation.
        regards, tom lane


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

Предыдущее
От: Gilberto Ribeiro de Queiroz
Дата:
Сообщение: How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?
Следующее
От: Michael Meskes
Дата:
Сообщение: Re: ECPG: Automatic Storage allocation for NULL-pointing output variables