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

Re: Is there a way to describe precision and scale for columns in a s

From: L J Bayuk <ljb220(at)mindspring(dot)com>
To: Bshrivastav(at)esri(dot)com (Brijesh Shrivastav)
Cc: pgsql-interfaces(at)postgresql(dot)org ('pgsql-interfaces(at)postgresql(dot)org')
Subject: Re: Is there a way to describe precision and scale for columns in a s
Date: 2004-06-07 00:44:04
Message-ID: 200406070044.i570i4LN000718@mindspring.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
Brijesh Shrivastav wrote:
> 
> Hi! All,
> 
> I am a new postgres developer and as is the case with many of us I am
> porting
> an existing application to postgres database. One of the requirement for us
> is to be able to determine the scale and precision for select columns so we
> can
> accordingly allordingly allocate memory or inform client applications. 
> 
> I looked at libpq api and found following api to describe a select statement
> 
> PQfname()
> PQftype()
> PQfsize()
> 
> However, PQfsize() gives me the space alloced for this column in database
> row. How
> can I get precision and scale for numeric columns?

It's a little tricky. Use PQfmod() on the column.  Call the result F.
The precision is the high 16 bits, and the scale is the low 16 bits,
but with an offset of 4 first:
     precision = ((F - 4)  >> 16) & 0xffff;
     scale = (F - 4) & 0xffff;

> I have run into another problem. I execute PREPARE statement with pgexec to
> prepare 
> the query before executing it multiple time with different parameter values.
> It 
> seems I can't get the select column information untill I perform an
> PQexecPrepared().
> Is there any way around it?

I don't think so. The protocol supports it ("Describe" message on a named
prepared statement, without Bind or Execute), and I assume the backend
would play along, but I don't think libpq has any way to let you do it
in the current release.

In response to

Responses

pgsql-interfaces by date

Next:From: Tom LaneDate: 2004-06-07 03:34:19
Subject: Re: Is there a way to describe precision and scale for columns in a s
Previous:From: Roman BestuzhevDate: 2004-06-06 09:58:09
Subject: Question about ODBC types

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