pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
09.03.0400, wrong real values
2+ messages / 2 participants
[nested] [flat]

* 09.03.0400, wrong real values
@ 2015-01-20 12:41 Jens Wiechmann <jens.wiechmann@redknee.com>
  2015-01-20 20:41 ` Re: 09.03.0400, wrong real values Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Jens Wiechmann @ 2015-01-20 12:41 UTC (permalink / raw)
  To: pgsql-odbc

Hi,
I am using the database 9.4.0 with the odbc driver 09.03.0400  on linux machine with unixODBC.

There are different results if  I insert a float value=-0.0051 in the database with ODBC funtions SQLBindParameter(), SQLPrepare() and SQLExecute().
With the odbc version 09.03.0300 the saved value is 0.0051 and
with the odbc version 09.03.0400 the saved wrong value is -0.00510000018 (see below).
There is no difference between 32 and 64 bit.

Server Version on linux RHEL6:
psql (PostgreSQL) 9.4.0 (and 9.3.4 for the comparison)


~/.odbc.ini
[JWIE]
Driver=PostgreSQL
Port=5432
Database=jwie
FileUsage=1
UseServerSidePrepare=0


I use this table:
jwie=> \d TESTTABLE4;
                  Table "jwie.testtable4"
     Column      |            Type             | Modifiers
-----------------+-----------------------------+-----------
testtype        | character varying(64)       |
 testbooleanchar | character(1)                |
 testinteger     | bigint                      |
 testnumber      | numeric                     |
 testchar        | character(128)              |
 testvarchar     | character varying(128)      |
 testraw         | bytea                       |
 testlongraw     | bytea                       |
 testblob        | bytea                       |
 testlong        | text                        |
 testdate        | timestamp without time zone |
 testfloat       | double precision            |


C Code fragment:
:
   retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, ID_LEN, 0, szTypeID, 0, &typeID);
   retcode = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f2, 0, &charID);
   retcode = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f3, 0, &numberID);
   retcode = SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f4, 0, &varcharID);
   retcode = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f5, 0, &floatID);

   retcode = SQLPrepare(hstmt, (SQLCHAR*)"INSERT INTO TESTTABLE4 "
                                                    "(TESTTYPE, "
                                                    "TESTCHAR, "
                                                    "TESTNUMBER, "
                                                    "TESTVARCHAR, testfloat) "
                                                    "VALUES (?, ?, ?, ?, ?)", SQL_NTS);

   printf("retcode=%d\n", retcode);
   strcpy((char*)szTypeID, "FLOAT1");
   f2=-0.0051;
   f3=-0.0051;
   f4=-0.0051;
   f5=-0.0051;
   retcode = SQLExecute(hstmt);
:

Log files

09.03.0300 OK
========
conn = 0x198d2e0, PGAPI_Connect(DSN='JWIE', UID='jwie', PWD='xxxxx')
Driver Version='09.03.0300,201405140001'
Global Options: fetch=100, socket=4096, unknown_sizes=0, max_varchar_size=255, max_longvarchar_size=8190
                disable_optimizer=0, ksqo=1, unique_index=1, use_declarefetch=0
                text_as_longvarchar=1, unknowns_as_longvarchar=0, bools_as_char=1 NAMEDATALEN=64
                extra_systable_prefixes='dd_;', conn_settings='(null)' conn_encoding=''
    [ PostgreSQL version string = '9.3.4' ]
    [ PostgreSQL version number = '9.3' ]
conn=0x198d2e0, query='select oid, typbasetype from pg_type where typname = 'lo''
    [ fetched 0 rows ]
    [ Large Object oid = -999 ]
    [ Client encoding = 'LATIN1' (code = 8) ]
conn=0x198d2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT1', '-0.0051'::float8, '-0.0051'::float8, '-0.0051'::float8, '-0.0051'::float8)'
conn=0x198d2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT2', '4.5678e+12'::float8, '4.5678e+12'::float8, '4.5678e+12'::float8, '4.5678e+12'::float8)'


09.03.0400 not OK
========
conn = 0x247f2e0, PGAPI_Connect(DSN='JWIE', UID='jwie', PWD='xxxxx')
Driver Version='09.03.0400,Jan  6 2015'
Global Options: fetch=100, socket=4096, unknown_sizes=0, max_varchar_size=255, max_longvarchar_size=8190
                disable_optimizer=0, ksqo=1, unique_index=1, use_declarefetch=0
                text_as_longvarchar=1, unknowns_as_longvarchar=0, bools_as_char=1 NAMEDATALEN=64
                extra_systable_prefixes='dd_;', conn_settings='(null)' conn_encoding=''
    [ PostgreSQL version string = '9.4.0' ]
    [ PostgreSQL version number = '9.4' ]
conn=0x247f2e0, query='select oid, typbasetype from pg_type where typname = 'lo''
    [ fetched 0 rows ]
    [ Large Object oid = -999 ]
    [ Client encoding = 'LATIN1' (code = 8) ]
conn=0x247f2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT1', '-0.00510000018'::float8, '-0.00510000018'::float8, '-0.00510000018'::float8, '-0.00510000018'::float8)'
conn=0x247f2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT2', '4.56779996e+12'::float8, '4.56779996e+12'::float8, '4.56779996e+12'::float8, '4.56779996e+12'::float8)'

Can you please check this?
Thank you.

Best Regards
Jens Wiechmann




[cid:image001.jpg@01D034B4.BED59390]

Jens Wiechmann
> Research and Development

Tel:       + 49 30 9210 24539
Mobile:  + 49 152 56747131
E-mail:   jens.wiechmann@redknee.com<mailto:jens.wiechmann@redknee.com>
Website: www.redknee.com<http://www.redknee.com;
Twitter:  @RedkneeRKN
TSX:      RKN
[cid:image002.jpg@01D034B4.BED59390]<http://twitter.com/redkneeRKN;[cid:image003.jpg@01D034B4.BED59390]<http://www.linkedin.com/company/redknee;[cid:image004.jpg@01D034B4.BED59390]<http://www.youtube.com/user/RedkneeRKN;[cid:image005.jpg@01D034B4.BED59390]<http://www.facebook.com/pages/Redknee/153720457985750;

Email Disclaimer<http://www.redknee.com/confidentiality/;

Redknee (Germany) GmbH
Geschäftsführung / Managing Directors: David Charron, Sabine Domes / Sitz der Gesellschaft: Berlin
Registered office: Berlin / Registergericht: Berlin / Commercial register: Berlin, HRB 152437 B

Attachments:

image001.jpg (image/jpeg, 17.6K) download view image
image002.jpg (image/jpeg, 2.6K) download view image
image003.jpg (image/jpeg, 2.6K) download view image
image004.jpg (image/jpeg, 2.7K) download view image
image005.jpg (image/jpeg, 2.6K) download view image
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: 09.03.0400, wrong real values
  2015-01-20 12:41 09.03.0400, wrong real values Jens Wiechmann <jens.wiechmann@redknee.com>
@ 2015-01-20 20:41 ` Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Heikki Linnakangas @ 2015-01-20 20:41 UTC (permalink / raw)
  To: Jens Wiechmann <jens.wiechmann@redknee.com>; pgsql-odbc

On 01/20/2015 02:41 PM, Jens Wiechmann wrote:
> Hi,
> I am using the database 9.4.0 with the odbc driver 09.03.0400  on linux machine with unixODBC.
>
> There are different results if  I insert a float value=-0.0051 in the database with ODBC funtions SQLBindParameter(), SQLPrepare() and SQLExecute().
> With the odbc version 09.03.0300 the saved value is 0.0051 and
> with the odbc version 09.03.0400 the saved wrong value is -0.00510000018 (see below).
> There is no difference between 32 and 64 bit.
>
> Server Version on linux RHEL6:
> psql (PostgreSQL) 9.4.0 (and 9.3.4 for the comparison)
>
>
> ~/.odbc.ini
> [JWIE]
> Driver=PostgreSQL
> Port=5432
> Database=jwie
> FileUsage=1
> UseServerSidePrepare=0
>
>
> I use this table:
> jwie=> \d TESTTABLE4;
>                    Table "jwie.testtable4"
>       Column      |            Type             | Modifiers
> -----------------+-----------------------------+-----------
> testtype        | character varying(64)       |
>   testbooleanchar | character(1)                |
>   testinteger     | bigint                      |
>   testnumber      | numeric                     |
>   testchar        | character(128)              |
>   testvarchar     | character varying(128)      |
>   testraw         | bytea                       |
>   testlongraw     | bytea                       |
>   testblob        | bytea                       |
>   testlong        | text                        |
>   testdate        | timestamp without time zone |
>   testfloat       | double precision            |
>
>
> C Code fragment:
> :
>     retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, ID_LEN, 0, szTypeID, 0, &typeID);
>     retcode = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f2, 0, &charID);
>     retcode = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f3, 0, &numberID);
>     retcode = SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f4, 0, &varcharID);
>     retcode = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, sizeof(float), 0, &f5, 0, &floatID);
>
>     retcode = SQLPrepare(hstmt, (SQLCHAR*)"INSERT INTO TESTTABLE4 "
>                                                      "(TESTTYPE, "
>                                                      "TESTCHAR, "
>                                                      "TESTNUMBER, "
>                                                      "TESTVARCHAR, testfloat) "
>                                                      "VALUES (?, ?, ?, ?, ?)", SQL_NTS);
>
>     printf("retcode=%d\n", retcode);
>     strcpy((char*)szTypeID, "FLOAT1");
>     f2=-0.0051;
>     f3=-0.0051;
>     f4=-0.0051;
>     f5=-0.0051;
>     retcode = SQLExecute(hstmt);
> :
>
> Log files
>
> 09.03.0300 OK
> ========
> conn = 0x198d2e0, PGAPI_Connect(DSN='JWIE', UID='jwie', PWD='xxxxx')
> Driver Version='09.03.0300,201405140001'
> Global Options: fetch=100, socket=4096, unknown_sizes=0, max_varchar_size=255, max_longvarchar_size=8190
>                  disable_optimizer=0, ksqo=1, unique_index=1, use_declarefetch=0
>                  text_as_longvarchar=1, unknowns_as_longvarchar=0, bools_as_char=1 NAMEDATALEN=64
>                  extra_systable_prefixes='dd_;', conn_settings='(null)' conn_encoding=''
>      [ PostgreSQL version string = '9.3.4' ]
>      [ PostgreSQL version number = '9.3' ]
> conn=0x198d2e0, query='select oid, typbasetype from pg_type where typname = 'lo''
>      [ fetched 0 rows ]
>      [ Large Object oid = -999 ]
>      [ Client encoding = 'LATIN1' (code = 8) ]
> conn=0x198d2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT1', '-0.0051'::float8, '-0.0051'::float8, '-0.0051'::float8, '-0.0051'::float8)'
> conn=0x198d2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT2', '4.5678e+12'::float8, '4.5678e+12'::float8, '4.5678e+12'::float8, '4.5678e+12'::float8)'
>
>
> 09.03.0400 not OK
> ========
> conn = 0x247f2e0, PGAPI_Connect(DSN='JWIE', UID='jwie', PWD='xxxxx')
> Driver Version='09.03.0400,Jan  6 2015'
> Global Options: fetch=100, socket=4096, unknown_sizes=0, max_varchar_size=255, max_longvarchar_size=8190
>                  disable_optimizer=0, ksqo=1, unique_index=1, use_declarefetch=0
>                  text_as_longvarchar=1, unknowns_as_longvarchar=0, bools_as_char=1 NAMEDATALEN=64
>                  extra_systable_prefixes='dd_;', conn_settings='(null)' conn_encoding=''
>      [ PostgreSQL version string = '9.4.0' ]
>      [ PostgreSQL version number = '9.4' ]
> conn=0x247f2e0, query='select oid, typbasetype from pg_type where typname = 'lo''
>      [ fetched 0 rows ]
>      [ Large Object oid = -999 ]
>      [ Client encoding = 'LATIN1' (code = 8) ]
> conn=0x247f2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT1', '-0.00510000018'::float8, '-0.00510000018'::float8, '-0.00510000018'::float8, '-0.00510000018'::float8)'
> conn=0x247f2e0, query='INSERT INTO TESTTABLE4 (TESTTYPE, TESTCHAR, TESTNUMBER, TESTVARCHAR, testfloat) VALUES ('FLOAT2', '4.56779996e+12'::float8, '4.56779996e+12'::float8, '4.56779996e+12'::float8, '4.56779996e+12'::float8)'
>
> Can you please check this?

This was changed in commit a5fed2338b59ae16a2d3a8d2744b084949684775, see 
discussion 
athttp://www.postgresql.org/message-id/DUB121-W17AD73873B390AF3AEF384D3170@phx.gbl. 
In a nutshell, for a float4 value, we used to only send 6 decimal 
digits, but now we send 9. That change was made because 6 decimal digits 
is not enough to distinguish between all float4 values, which meant that 
for some values, if you sent the value to the database and then read it 
back, you would not get the exact same value back.

Note that in your test case, you're passing the value to 
SQLBindParameter as a 32-bit floating-point value (SQL_C_FLOAT, which is 
the same as SQL_C_REAL), but you're storing it in a 64-bit floating 
point column (double). I think you'll want to pass the value as a 
double, SQL_C_DOUBLE, instead. That'll avoid the conversion, and the 
extra digits that you don't want.

I'm pretty sure we don't want to make further changes to this. IOW this 
isn't a bug.

(In the server, there is an option called extra_float_digits to control 
the same thing, for values output from the server. The old behavior 
corresponds to extra_float_digits=0, while the new behavior corresponds 
to extra_float_digits=3. It's not directly relevant here, but you might 
want to read up on it in the documentation, to get a grasp of how 
floating-point types work)

- Heikki



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



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


end of thread, other threads:[~2015-01-20 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20 12:41 09.03.0400, wrong real values Jens Wiechmann <jens.wiechmann@redknee.com>
2015-01-20 20:41 ` Heikki Linnakangas <hlinnakangas@vmware.com>

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