[MDEV-7297] IF() function consults 3rd argument to determine result display Created: 2014-12-10 Updated: 2020-04-30 Resolved: 2014-12-16 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | OTHER |
| Affects Version/s: | 5.5.33a, 5.3.13, 5.5, 10.0 |
| Fix Version/s: | 5.5.41 |
| Type: | Bug | Priority: | Major |
| Reporter: | Kolbe Kegel (Inactive) | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
In MariaDB, it seems that the 3rd argument of the IF() function is consulted to determine how a DECIMAL result is zero-padded when sent back to the client. The behavior is different in MySQL. For example: In MySQL:
And in MariaDB:
|
| Comments |
| Comment by Elena Stepanova [ 2014-12-10 ] | ||||||||||||
|
The problem was introduced in 5.3 tree (and further in 5.5.33 and 10.0.5) with the following revision:
| ||||||||||||
| Comment by Alexander Barkov [ 2014-12-16 ] | ||||||||||||
|
Behaviour before the fix was inconsistent:
Notice, all these expressions effectively return the first argument, Behaviour after the fix:
All CASE and its abbreviations return exactly the same result. | ||||||||||||
| Comment by Alexander Barkov [ 2014-12-16 ] | ||||||||||||
|
Intentional behaviour change. | ||||||||||||
| Comment by Fred Rexon [ 2014-12-19 ] | ||||||||||||
|
The expected and documented behavior of ROUND(nnn, x) is to return a string with x number of decimals, not x number of decimal precision padded with the maximum x in any ROUND/TRUNCATE that is part of a different clause. It seems like you originally got a mix of good and bad results (good - IF/CASE, bad COALESCE/IFNULL) and decided to standardize on the BAD. This is bizarre. The only thing I can think of that would cause this decision is that you'd want consistent output out of COALESCE, which could easily have been handled by putting the COALESCE within the ROUND, not by ignoring the plain intent of IF, IFNULL and CASE. SELECT ROUND(COALESCE(0.123, 0.12345), 5) Works the same in both MySQL and MariaDB. | ||||||||||||
| Comment by Alexander Barkov [ 2014-12-19 ] | ||||||||||||
|
IF (1=1,ROUND(0.123451, 3), ROUND(0.123451, 5)) is a CASE abbreviation: CASE WHEN 1=1 THEN (0.123451, 3) ELSE ROUND(0.123451, 5) END According to the SQL standard, the result type for CASE in this particulate case is | ||||||||||||
| Comment by Kolbe Kegel (Inactive) [ 2014-12-20 ] | ||||||||||||
|
If the goal is indeed to have variable precision for the result, the condition should be placed inside of the ROUND() function, not around it. For example, instead of this:
Use this instead:
|