pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Determining C type for a given OID
2+ messages / 2 participants
[nested] [flat]

* Determining C type for a given OID
@ 2002-11-29 23:18 Graham Wilson <grahamwilsonca@yahoo.ca>
  2002-11-29 23:34 ` Re: Determining C type for a given OID Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Graham Wilson @ 2002-11-29 23:18 UTC (permalink / raw)
  To: pgsql-interfaces

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?

Many thanks.



---------------------------------
Post your free ad now! Yahoo! Canada Personals

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Determining C type for a given OID
  2002-11-29 23:18 Determining C type for a given OID Graham Wilson <grahamwilsonca@yahoo.ca>
@ 2002-11-29 23:34 ` Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2002-11-29 23:34 UTC (permalink / raw)
  To: Graham Wilson <grahamwilsonca@yahoo.ca>; +Cc: pgsql-interfaces

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-11-29 23:34 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-29 23:18 Determining C type for a given OID Graham Wilson <grahamwilsonca@yahoo.ca>
2002-11-29 23:34 ` Bruce Momjian <pgman@candle.pha.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox