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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gilberto Ribeiro de Queiroz <gribeiro(at)dpi(dot)inpe(dot)br>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: How to obtain the size of a field VARCHAR, NUMERIC(7, 2) after a query with libpq?
Date: 2001-10-28 01:45:48
Message-ID: 4074.1004233548@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Gilberto Ribeiro de Queiroz <gribeiro(at)dpi(dot)inpe(dot)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

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Meskes 2001-10-28 11:04:14 Re: ECPG: Automatic Storage allocation for NULL-pointing output variables
Previous Message Gilberto Ribeiro de Queiroz 2001-10-27 20:30:33 How to obtain the size of a field VARCHAR, NUMERIC(7, 2) after a query with libpq?