Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-interfaces by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group