X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D6377D1B347 for ; Sun, 6 Jun 2004 21:44:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79926-02 for ; Mon, 7 Jun 2004 00:44:51 +0000 (GMT) Received: from maynard.mail.mindspring.net (maynard.mail.mindspring.net [207.69.200.243]) by svr1.postgresql.org (Postfix) with ESMTP id 5307DD1B1EC for ; Sun, 6 Jun 2004 21:44:47 -0300 (ADT) Received: from sdn-ap-002njpennp0359.dialsprint.net ([63.185.137.105] helo=mindspring.com) by maynard.mail.mindspring.net with esmtp (Exim 3.33 #1) id 1BX8Fr-0005aC-00; Sun, 06 Jun 2004 20:44:48 -0400 Received: (from lbayuk@localhost) by mindspring.com (8.12.10/8.12.10) id i570i4LN000718; Sun, 6 Jun 2004 20:44:05 -0400 From: L J Bayuk Message-Id: <200406070044.i570i4LN000718@mindspring.com> Subject: Re: Is there a way to describe precision and scale for columns in a s To: Bshrivastav@esri.com (Brijesh Shrivastav) Date: Sun, 6 Jun 2004 20:44:04 -0400 (EDT) Cc: pgsql-interfaces@postgresql.org ('pgsql-interfaces@postgresql.org') In-Reply-To: <491DC5F3D279CD4EB4B157DDD62237F401ADE45E@zipwire.esri.com> from "Brijesh Shrivastav" at Jun 03, 2004 10:39:10 AM X-Mailer: ELM [version 2.5 PL6] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, RCVD_IN_NJABL, RCVD_IN_SORBS X-Spam-Level: * X-Archive-Number: 200406/9 X-Sequence-Number: 4937 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.