Happy new year all.
I have two money fields which appear to be equal but are not. Has anyone encountered this before? There are 3 records below which should not display. An OpenROAD screen shows the difference is -0 which makes me think there are some bits floating around somewhere. The faulty data originates from data conversion via EA/MSSQL. Data is fixed now so I have just documented this for future reference.
select doc_no, status, amount_due, orig_amount,
amount_due - orig_amount from open_items
where cust_code = 'C00524'
and orig_amount <> amount_due
and status <> 'F'
Executing . . .
+--------------------+------+--------------------+--------------------+--------------------+
|doc_no |status|amount_due |orig_amount |col5 |
+--------------------+------+--------------------+--------------------+--------------------+
|149286 | | $204.81| $1853.66| $-1648.85|
|153212 | | $299.90| $2079.69| $-1779.79|
|155694 | | $0.01| $14566.63| $-14566.62|
|156443 | | $32.26| $2293.90| $-2261.64|
|157139 | | $64.85| $1138.73| $-1073.88|
|157401 | | $19.98| $2467.52| $-2447.54|
|157414 | | $280.33| $20468.20| $-20187.87|
|157900 | | $756.48| $7412.97| $-6656.49|
|159064 | | $2.62| $5723.35| $-5720.73|
|159616 | | $56.36| $4028.37| $-3972.01|
|159731 | | $33.99| $7858.43| $-7824.44|
|161071 | | $364.91| $12913.16| $-12548.25|
|162080 |P | $503.01| $10655.86| $-10152.85|
|162258 |P | $277.25| $3600.98| $-3323.73|
|162827 | | $5015.57| $5015.57| $0.00|
|162950 | | $2605.16| $2605.16| $0.00|
|163130 | | $1265.38| $1265.38| $0.00|
|CR-015297 | | $-3.45| $-38.00| $34.55|
+--------------------+------+--------------------+--------------------+--------------------+
(18 rows)
I checked these variations also
float8(amount_due) - float8(orig_amount)
float8(amount_due - orig_amount)
To fix the problem I rewrote the data.
-- This didn’t have any effect.
update open_items
set amount_due = money(amount_due), orig_amount = money(orig_amount)
where orig_amount <> amount_due
and status <> 'F'
\p\g
-- And neither did this. Hmmm my manual says round() works for any number.
update open_items
set amount_due = round(amount_due,2), orig_amount = round(orig_amount,2)
where orig_amount <> amount_due
and status <> 'F'
Executing . . .
E_US0B5C line 1, Function 'round' is not defined for arguments of type
'money' and 'integer'. Explicitly convert its arguments to the desired
type(s).
(Thu Jan 03 14:57:50 2013)
-- This worked
update open_items
set amount_due = round(float8(amount_due),2),
orig_amount = round(float8(orig_amount),2)
where cust_code = 'C00524'
and orig_amount <> amount_due
and status <> 'F'
Executing . . .
(18 rows)
continue
* * * * * * * * *
select doc_no,status,
amount_due, orig_amount,
amount_due - orig_amount from open_items
where cust_code = 'C00524'
and orig_amount <> amount_due
and status <> 'F'
Executing . . .
+--------------------+------+--------------------+--------------------+--------------------+
|doc_no |status|amount_due |orig_amount |col5 |
+--------------------+------+--------------------+--------------------+--------------------+
|149286 | | $204.81| $1853.66| $-1648.85|
|153212 | | $299.90| $2079.69| $-1779.79|
|155694 | | $0.01| $14566.63| $-14566.62|
|156443 | | $32.26| $2293.90| $-2261.64|
|157139 | | $64.85| $1138.73| $-1073.88|
|157401 | | $19.98| $2467.52| $-2447.54|
|157414 | | $280.33| $20468.20| $-20187.87|
|157900 | | $756.48| $7412.97| $-6656.49|
|159064 | | $2.62| $5723.35| $-5720.73|
|159616 | | $56.36| $4028.37| $-3972.01|
|159731 | | $33.99| $7858.43| $-7824.44|
|161071 | | $364.91| $12913.16| $-12548.25|
|162080 |P | $503.01| $10655.86| $-10152.85|
|162258 |P | $277.25| $3600.98| $-3323.73|
|CR-015297 | | $-3.45| $-38.00| $34.55|
+--------------------+------+--------------------+--------------------+--------------------+
(15 rows)
I’m sure the problem originated with data migrated via EA/MSSQL. The conversion staging data is float which shows very small differences.
original data in mssql
doc_no amount_due orig_amount
-------------------- ---------------------- ---------------------- ----------------------
149286 20481 185366 -164885
153212 29990 207969 -177979
156443 3226 229390 -226164
155694 1 1456663 -1456662
157139 6485 113873 -107388
157401 1998 246752 -244754
157414 28033 2046820 -2018787
159616 5636 402837 -397201
157900 75648 741297 -665649
159064 262 572335 -572073
159731 3399 785843 -782444
161071 36491 1291316 -1254825
162950 260516 260516 2.91038304567337E-11
163130 126538 126538 1.45519152283669E-11
162827 501557 501557 5.82076609134674E-11
CR-015297 -345 -3800 3455
(16 row(s) affected)
The migration steps used copy table statement via copy.out and copy.in scripts. EA/MSSQL creates float fields to store money.
sql mysqldb/mssql < extract.sql
create table peer_open_items(
cust_code char(12) not null not default,
assignee_no integer not null default 0,
doc_no varchar(20) not null not default,
doc_date date not null not default,
trans_type integer not null not default,
amount_due money not null not default,
orig_amount money not null not default,
gst_amount float not null default 0,
..
[steps to populate staging table]
..
copy table peer_open_items () into 'peer_open_items.ingres'; \p\g
\q
sql myingresdb < load.sql
create table peer_open_items(
cust_code char(12) not null not default,
assignee_no integer not null default 0,
doc_no varchar(20) not null not default,
doc_date date not null not default,
trans_type integer not null not default,
amount_due money not null not default,
orig_amount money not null not default,
gst_amount float not null default 0,
..
copy table peer_open_items () from 'peer_open_items.ingres'; \p\g
..
insert into open_items select * from peer_open_items \p\g
regards
Paul White
& Shift Seven Solutions
84 Annie Drive Peregian Beach QLD 4573
Mob 0414 681799
Hi Paul,
MONEY is an inexact numeric datatype so you should be expecting representation differences due to rounding.
Regarding the ROUND function, I suggest you raise an issue & mention me.
Regards,
Ian
From: info-ingr...@kettleriverconsulting.com [mailto:info-ingr...@kettleriverconsulting.com] On Behalf Of Paul White
Sent: 03 January 2013 17:39
To: 'Ingres and related product discussion forum'
Subject: [Info-Ingres] Weird money problem. EA/MSSQL conversion to Ingres
Happy new year all.
I have two money fields which appear to be equal but are not. Has anyone encountered this before? There are 3 records below which should not display. An OpenROAD screen shows the difference is -0 which makes me think there are some bits floating around somewhere. The faulty data originates from data conversion via EA/MSSQL. Data is fixed now so I have just documented this for future reference.
select doc_no, status, amount_due, orig_amount,
amount_due - orig_amount from open_items
where cust_code = 'C00524'
and orig_amount <> amount_due
and status <> 'F'
Executing . . .
+--------------------+------+--------------------+--------------------+--------------------+
|doc_no |status|amount_due |orig_amount |col5 |
+--------------------+------+--------------------+--------------------+--------------------+
|149286 | | $204.81| $1853.66| $-1648.85|
|153212 | | $299.90| $2079.69| $-1779.79|
|155694 | | $0.01| $14566.63| $-14566.62|
|156443 | | $32.26| $2293.90| $-2261.64|
|157139 | | $64.85| $1138.73| $-1073.88|
|157401 | | $19.98| $2467.52| $-2447.54|
|157414 | | $280.33| $20468.20| $-20187.87|
|157900 | | $756.48| $7412.97| $-6656.49|
|159064 | | $2.62| $5723.35| $-5720.73|
|159616 | | $56.36| $4028.37| $-3972.01|
|159731 | | $33.99| $7858.43| $-7824.44|
|161071 | | $364.91| $12913.16| $-12548.25|
|162080 |P | $503.01| $10655.86| $-10152.85|
|162258 |P | $277.25| $3600.98| $-3323.73|
|162827 | | $5015.57| $5015.57| $0.00|
|162950 | | $2605.16| $2605.16| $0.00|
|163130 | | $1265.38| $1265.38| $0.00|
|CR-015297 | | $-3.45| $-38.00| $34.55|
+--------------------+------+--------------------+--------------------+--------------------+
(18 rows)
I checked these variations also
|149286 | | $204.81| $1853.66| $-1648.85|
|153212 | | $299.90| $2079.69| $-1779.79|
|155694 | | $0.01| $14566.63| $-14566.62|
|156443 | | $32.26| $2293.90| $-2261.64|
|157139 | | $64.85| $1138.73| $-1073.88|
|157401 | | $19.98| $2467.52| $-2447.54|
|157414 | | $280.33| $20468.20| $-20187.87|
|157900 | | $756.48| $7412.97| $-6656.49|
|159064 | | $2.62| $5723.35| $-5720.73|
|159616 | | $56.36| $4028.37| $-3972.01|
|159731 | | $33.99| $7858.43| $-7824.44|
|161071 | | $364.91| $12913.16| $-12548.25|
|162080 |P | $503.01| $10655.86| $-10152.85|
|162258 |P | $277.25| $3600.98| $-3323.73|
|CR-015297 | | $-3.45| $-38.00| $34.55|
+--------------------+------+--------------------+--------------------+--------------------+
(15 rows)
I’m sure the problem originated with data migrated via EA/MSSQL. The conversion staging data is float which shows very small differences.
original data in mssql
doc_no amount_due orig_amount
-------------------- ---------------------- ---------------------- ----------------------
149286 20481 185366 -164885
153212 29990 207969 -177979
156443 3226 229390 -226164
155694 1 1456663 -1456662
157139 6485 113873 -107388
157401 1998 246752 -244754
157414 28033 2046820 -2018787
159616 5636 402837 -397201
157900 75648 741297 -665649
159064 262 572335 -572073
159731 3399 785843 -782444
161071 36491 1291316 -1254825
162950 260516 260516 2.91038304567337E-11
163130 126538 126538 1.45519152283669E-11
162827 501557 501557 5.82076609134674E-11
CR-015297 -345 -3800 3455
(16 row(s) affected)
The migration steps used copy table statement via copy.out and copy.in scripts. EA/MSSQL creates float fields to store money.
sql mysqldb/mssql < extract.sql
create table peer_open_items(
cust_code char(12) not null not default,
assignee_no integer not null default 0,
doc_no varchar(20) not null not default,
doc_date date not null not default,
trans_type integer not null not default,
amount_due money not null not default,
orig_amount money not null not default,
gst_amount float not null default 0,
..
[steps to populate staging table]
..
copy table peer_open_items () into 'peer_open_items.ingres'; \p\g
\q
sql myingresdb < load.sql
create table peer_open_items(
cust_code char(12) not null not default,
assignee_no integer not null default 0,
doc_no varchar(20) not null not default,
doc_date date not null not default,
trans_type integer not null not default,
amount_due money not null not default,
orig_amount money not null not default,
gst_amount float not null default 0,
..
copy table peer_open_items () from 'peer_open_items.ingres'; \p\g
..
insert into open_items select * from peer_open_items \p\g
regards
Hi Chris and Ian,
Thanks for your replies.
> The money type is a floating point value internally and so it has many of the same characteristics of float.
> MONEY is an inexact numeric datatype so you should be expecting representation differences
Wow. Over countless years I have relied heavily on Ingres money type to be exact.
>select ... where abs(float_col1 - float_col2) > 0.001;
I can’t imagine having to change all our applications to do the same when comparing money fields.
Should we be using decimal(16,2) for example?
EAVersion.rel
EA 2.7/1001 (int.w32/103)
14265
I used the default when creating the EA catalogs. Float. Perhaps the default should be changed to money?
E:\IngresEA\ingres>iigwcatmss
EA MSSQL 2.7/1001 (int.w32/103), MSSQL Catalog Program
Copyright (c) 2007 Ingres Corporation. All Rights Reserved.
At any time enter HELP for more info, QUIT to abort.
Alias Name> edlynsql
DBA name used to qualify unqualified objects> ingres
OpenSQL MSSQL Money Mapping
1 - FLOAT - default
2 - MONEY
[1-2]?>
Yes it was binary unload/load on the same machine but two different instances.
The source MSSQL data types were MONEY but as I mentioned, the staging table is float by default. The extract sql is something like this
insert into peer_open_items
select …, sourceamt1 * 100, sourceamt2 * 100, …
Paul
_______________________________________________
Info-Ingres mailing list
Info-...@kettleriverconsulting.com
http://ext-cando.kettleriverconsulting.com/mailman/listinfo/info-ingres