Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 52BDC475CE5 for ; Fri, 29 Nov 2002 18:34:12 -0500 (EST) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by postgresql.org (Postfix) with ESMTP id 1D753475C98 for ; Fri, 29 Nov 2002 18:34:11 -0500 (EST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id gATNY7T14241; Fri, 29 Nov 2002 18:34:07 -0500 (EST) From: Bruce Momjian Message-Id: <200211292334.gATNY7T14241@candle.pha.pa.us> Subject: Re: Determining C type for a given OID In-Reply-To: <20021129231832.61196.qmail@web14403.mail.yahoo.com> To: Graham Wilson Date: Fri, 29 Nov 2002 18:34:07 -0500 (EST) Cc: pgsql-interfaces@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/162 X-Sequence-Number: 3410 Graham Wilson wrote: > Hi all, > > I'm using the libpq `PQgetvalue` function to get > specific results from my datase. Many of these > results are numeric types. Is there an internal > function in libpq that will convert the returned > string to an appropriate C-type based on the oid > values in src/include/catalog/pg_type.h? Well, in most queries, the returned value is a C string that you have to convert in the client. I think ecpg handles such conversions natively so you don't have to worry about them, and most of the scripting languages handle a C string numeric value just like any other value (they don't have data types). It would be great if we could assign it right to a double, but you can't. You can make such assignments of float4 to float and float8 to double if you use a binary cursor _and_ your client and server have the same internal representation for such values. However, NUMERIC is stored internally a binary-coded decimal-like format that isn't going to make any sense to your client code at all. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073