Bug #516 union all truncates floating point fields
Submitted: 27 May 2003 8:00 Modified: 27 May 2003 9:04
Reporter: Mircea LUTIC Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.13 OS:Windows (Windows XP)
Assigned to: CPU Architecture:Any

[27 May 2003 8:00] Mircea LUTIC
Description:
union all truncates floating point fields

here is my sql statement: 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(select DL.entry,DL.device,C.id,C.name,C.mark c,M.value m,ifnull(PT.value,0.) p,0. a,0. f,0. l,0.+0. t,0.+0. P,0. C,0. N
 from DevLot DL
 left join Entry  E  on E.Lot=DL.entry
 left join Cntp   C  on C.ID=E.Cntp
 left join Device D  on D.ID=DL.device
 left join Model  M  on M.ID=D.modl
 left join Brand  B  on B.ID=M.brand
 left join DevPart  DP on DL.entry=DP.entry and DL.device=DP.device
 left join PartType  PT on PT.ID=DP.part
 where (DL.entry=1 and DL.device in(1)))
union all
(select DL.entry,DL.device,C.id,C.name,C.mark c,M.value m,0. p,0. a,0. f,RL.value*(unix_timestamp(ifnull(DT.tmax,now()))-unix_timestamp(DT.tmin))/3600. l,(unix_timestamp(ifnull(DT.tmax,now()))-unix_timestamp(DT.tmin))/3600. t,0. P,0. C,0. N
 from DevLot DL
 left join Entry  E  on E.Lot=DL.entry
 left join Cntp   C  on C.ID=E.Cntp
 left join Device D  on D.ID=DL.device
 left join Model  M  on M.ID=D.modl
 left join Brand  B  on B.ID=M.brand
 left join DevTime  DT on DL.entry=DT.entry and DL.device=DT.device
 left join Operator  O  on O.id=DT.operator
 left join Role      RL on RL.ID=O.role
 left join workplace WP on WP.ID=DT.workplace
 where (DL.entry=1 and DL.device in(1)))
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

the result 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
flux>source test.sql;
+-------+--------+------+-------+------+------+---+---+---+---+---+---+---+---+
| entry | device | id   | name  | c    | m    | p | a | f | l | t | P | C | N |
+-------+--------+------+-------+------+------+---+---+---+---+---+---+---+---+
|     1 |      1 |    1 | Codec |    0 | 1000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|     1 |      1 |    1 | Codec |    0 | 1000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+-------+--------+------+-------+------+------+---+---+---+---+---+---+---+---+
2 rows in set (0.00 sec)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
while only one side: 

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(select DL.entry,DL.device,C.id,C.name,C.mark c,M.value m,0. p,0. a,0. f,RL.value*(unix_timestamp(ifnull(DT.tmax,now()))-unix_timestamp(DT.tmin))/3600. l,(unix_timestamp(ifnull(DT.tmax,now()))-unix_timestamp(DT.tmin))/3600. t,0. P,0. C,0. N
 from DevLot DL
 left join Entry  E  on E.Lot=DL.entry
 left join Cntp   C  on C.ID=E.Cntp
 left join Device D  on D.ID=DL.device
 left join Model  M  on M.ID=D.modl
 left join Brand  B  on B.ID=M.brand
 left join DevTime  DT on DL.entry=DT.entry and DL.device=DT.device
 left join Operator  O  on O.id=DT.operator
 left join Role      RL on RL.ID=O.role
 left join workplace WP on WP.ID=DT.workplace
 where (DL.entry=1 and DL.device in(1)))
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

returns : 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
flux>source test.sql;
+------+--------+----+-------+---+------+---+---+---+------+------+---+---+---+
|entry | device | id | name  | c | m    | p | a | f | l    | t    | P | C | N |
+------+--------+----+-------+---+------+---+---+---+------+------+---+---+---+
|    1 |      1 |  1 | Codec | 0 | 1000 | 0 | 0 | 0 |    0 | 0.01 | 0 | 0 | 0 |
+------+--------+----+-------+---+------+---+---+---+------+------+---+---+---+
1 row in set (0.00 sec)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
note field "t" has the value "0.01" which is not there in the union statement.

Mircea.

How to repeat:
straight union on plain table 
(select * from a where val>2 union select * from a where val<2;)
doesn't display this problem
it may be related to outer joined tables.

Suggested fix:
union should work as expected.
[27 May 2003 8:29] Mircea LUTIC
I got more info:

when in union with a null column the value is converted to empty string.
when in union with 0 it is truncated to integer
so the workaround is to set in union with smth like 0.00000

Mircea.
[27 May 2003 9:04] MySQL Verification Team
This issue is already reported.

It will be fixed in 5.0.

Workaround: 

Instead of 0. set 0.00000