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

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 (view raw or flat)
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

pgsql-interfaces by date

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

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