libpq: PQexecParams, binaryFormat and float

From: "Sun, Way" <Way(dot)Sun(at)sciatl(dot)com>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: libpq: PQexecParams, binaryFormat and float
Date: 2007-06-29 19:09:22
Message-ID: 7FBC16D72C0ABF45A88EAEB9ED3464C48CC172@sausatlexch01.corp.sa.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi,

I'm having trouble inserting a float into pg using binary format.

Hope someone on the list can help me point out what I'm doing wrong....

float loadavg;

loadavg = htonl(1.23);

paramValues[0] = (char *) &loadavg
paramLengths[0] = sizeof(loadavg);
paramFormats[0] = 1;

res = PQexecParams(conn,
"INSERT INTO cpu (loadavg) VALUES ($1::real)",
1,
NULL,
paramValues,
paramLengths,
paramFormats,
1);

From psql, select returns the value as 1.20765e-38 instead of
1.23.....:(

Thanks

Way

- - - - - Appended by Scientific Atlanta, a Cisco company - - - - -
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2007-06-29 20:27:18 Re: libpq: PQexecParams, binaryFormat and float
Previous Message anoopmadavoor@gmail.com 2007-06-27 07:24:21 How I can return a set of recordset from PL/Python