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

From Tom Lane
Subject Re: How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?
Date
Msg-id 4074.1004233548@sss.pgh.pa.us
Whole thread Raw
In response to 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>)
List 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 by date:

Previous
From: Gilberto Ribeiro de Queiroz
Date:
Subject: How to obtain the size of a field VARCHAR, NUMERIC(7,2) after a query with libpq?
Next
From: Michael Meskes
Date:
Subject: Re: ECPG: Automatic Storage allocation for NULL-pointing output variables