Sorry. I forgot to thank for any help from all of you in the previous message. Thanks! :)

Just one more thing:

I now I can go to the source and change the code which converts floats to strings, and have my problem solved. But this wont be general. Others might need this kind of application.

I could post this interface to postgres interfaces site. Do you think this is ok ?

Thanks again !

Pedro M. Ferreira

Pedro Miguel Frazao Fernandes Ferreira wrote:
Hi All,

I wrote a Matlab interface to PostgreSQL based on libpq. It is working fine, supports multiple connections, supports all data types and arrays. It is a C program to do the interface and some Matlab wrapper functions around it to do the job at application level.

Matlab has an ODBC toolbox but we dont want to buy it since the interface does the job and we have been using PostgreSQL for long time.
We want to use PostgreSQl to store numeric data from simulation, computation and data acquisition sources. Basically a big bunch of float numbers.

There is still one problem, regarding float output formatting in querys and dumps, which essential for this type of application.

If I have a float8 field (named real8 below) in a table and insert the following,

insert into test(real8) values (4503599627370496);
INSERT 21192 1

A select produces,

select real8 from test;
real8
---------------------
4.5035996273705e+15
(1 row)

This is the string I would get from libpq's PQgetvalue(). PQftype() correctly returns float8. pg_dump produces the same result. If I convert PQgetvalue() to a C double I wont get the same number I inserted. If I do a restore from a dump I also wont have the same number. I can see that the original number is correctly stored because,

select to_char(real8,'9999999999999999999.99999') from test;
to_char
----------------------
4503599627370496
(1 row)

This way PQftype wont tell this is a float8.

Is there a way to set query output precision to maximum precision ?
For the type of application I mentioned this is crucial. People want to get the 'same' numbers, from querys or dumps, as they inserted them.

Matlab has a toolbox fucntion, claiming maximum precision, to convert from its double type (PostgreSQL float8) to string which does a sprintf('%25.18g',number).

Would it be possible to have a a parameter which could be changed by a SET command, in order to control output precision ? I searched the docs but could not find this.


--
----------------------------------------------------------------------
Pedro Miguel Frazao Fernandes Ferreira
Universidade do Algarve
Faculdade de Ciencias e Tecnologia
Campus de Gambelas
8000-117 Faro
Portugal
Tel./Fax:  (+351) 289 800950 / 289 819403
http://w3.ualg.pt/~pfrazao


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to