[MDEV-21020] ROUND(X,D) function does not have effect when decimal is a column Created: 2019-11-09 Updated: 2020-11-10 Resolved: 2019-11-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | Tore Andersson | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
any, docker mariadb/server default |
||
| Attachments: |
|
| Description |
|
The ROUND(X,D) function when D is a column from a joined table will cause the ROUND function to not have the proper effect. The value will actually be rounded numerically, but the number of decimals printed, even when there is only a single outout row. I have two tables, one with currencies and the number of decimals the currency trade with.
I make a query which convert the currency and given the rate and rounds it to proper number of decimals.
Attached is a file to recreate the tables and run a few different variations of the query. |
| Comments |
| Comment by Tore Andersson [ 2019-11-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another variation of the query which fail in the same manner:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-11-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Reproducible as described, also on MySQL 8.0. I couldn't find either in MariaDB or MySQL documentation whether it's expected or not, assigning to bar for an expert opinion. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-11-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can't see bugs here. Everything works as designed. This expression:
returns a value of the DECIMAL(20,4) data type. It's always printed with four decimal digits. To achieve what you need please run this query:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Joffrey MICHAIE [ 2020-11-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Greetings Bar! Sorry to re-open this bug/feature request. I understand that the answer from the ROUND(num, dec) function is/should be of the type of the num input, but then how can we explain that the result for the function differs, depending on if dec is a constant, or a value fetched from a column? Output from MariaDB 10.4.13
Thanks in advance for your lights! Joffrey | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-11-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello joffrey92, good to hear from you The results are the same - only the number of trailing spaces differs. The number of trailing spaces depends on the result data type, which is evaluated during the statement preparation time. And the result data type depends on the first and the second argument:
This behaviour is by design. |