Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id AA799B5DC00 for ; Fri, 8 Jul 2011 00:17:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 95517-01 for ; Fri, 8 Jul 2011 03:17:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id F1887B5DC02 for ; Fri, 8 Jul 2011 00:17:57 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p683HuKJ058679 for ; Fri, 8 Jul 2011 03:17:56 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p683HuSl058678; Fri, 8 Jul 2011 03:17:56 GMT (envelope-from www) Date: Fri, 8 Jul 2011 03:17:56 GMT Message-Id: <201107080317.p683HuSl058678@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6096: ECPG set precision of double value to 14 digits From: "Akira Kurosawa" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201107/63 X-Sequence-Number: 30675 The following bug has been logged online: Bug reference: 6096 Logged by: Akira Kurosawa Email address: kurosawa-akira@mxc.nes.nec.co.jp PostgreSQL version: 8.4.5 Operating system: Red Hat Enterprise Linux 5.5 Description: ECPG set precision of double value to 14 digits Details: When I used host variable of double type in ECPG code, the precision of the data was treated as 14 digits. I executed following command. -------------------------------------------------- EXEC SQL BEGIN DECLARE SECTION; double dbl; EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT TO testdb@localhost:5432 USER postgres; dbl = 12345678901234; -- 14 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); dbl = 1234567890.1234; -- 14 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); dbl = 0.12345678901234; -- 14 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); dbl = 123456789012345; -- 15 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); dbl = 1234567890.12345; -- 15 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); dbl = 0.123456789012345; -- 15 digits EXEC SQL INSERT INTO double_table (c1) VALUES (:dbl); EXEC SQL COMMIT; EXEC SQL DISCONNECT; -------------------------------------------------- Then I checked inserted data, but all data was stored by 14 digits precision. -------------------------------------------------- testdb=# \d double_table Table "public.double_table" Column | Type | Modifiers --------+------------------+----------- c1 | double precision | testdb=# SELECT * FROM double_table; c1 ------------------ 12345678901234 1234567890.1234 0.12345678901234 123456789012340 1234567890.1235 0.12345678901234 (6 rows) -------------------------------------------------- The precision of double type should be 15 digits, and I think this result is wrong. PostgreSQL 9.0.4 also shows the same result. In function "ecpg_store_input:execute.c", the value of double type is changed by sprintf to a character string at 14 digits precision. I'm thinking this point is a problem. sprintf(mallocedval, "%.14g", *((double *) var->value)); Following log is result of executing same query by psql. -------------------------------------------------- testdb=# INSERT INTO double_table VALUES ('12345678901234'); INSERT 0 1 testdb=# INSERT INTO double_table VALUES ('1234567890.1234'); INSERT 0 1 testdb=# INSERT INTO double_table VALUES ('0.12345678901234'); INSERT 0 1 testdb=# INSERT INTO double_table VALUES ('123456789012345'); INSERT 0 1 testdb=# INSERT INTO double_table VALUES ('1234567890.12345'); INSERT 0 1 testdb=# INSERT INTO double_table VALUES ('0.123456789012345'); INSERT 0 1 testdb=# SELECT * FROM double_table; c1 ------------------- 12345678901234 1234567890.1234 0.12345678901234 123456789012345 1234567890.12345 0.123456789012345 (6 rows) --------------------------------------------------