Bug #28304 TRUNCATE function should have a default round value of 0
Submitted: 8 May 2007 14:04 Modified: 6 Jul 2007 19:53
Reporter: Jorge Bernal Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Parser Severity:S4 (Feature request)
Version: OS:Any
Assigned to: Chad MILLER CPU Architecture:Any
Tags: Contribution, PatchRefused

[8 May 2007 14:04] Jorge Bernal
Description:
Currently, TRUNCATE() require a second parameter indicating the number of decimal places to keep. It should be useful to have this value being 0 by default, so it would just drop the decimals.

How to repeat:
mysql> SELECT TRUNCATE(52.64);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

Suggested fix:
TRUNCATE() should have the second parameter as optional like this:

mysql> SELECT TRUNCATE(52.64);
+-----------------+
| TRUNCATE(52.64) |
+-----------------+
|              52 | 
+-----------------+
1 row in set (0.00 sec)
[31 May 2007 6:40] Valeriy Kravchuk
Thank you for a reasonable feature request. Oracle's trunc() works the way you requested.
[12 Jun 2007 8:19] Magnus Blåudd
Hi Jorge,

Attach your patch to the bug and it will probably be a contribution. Please read more on MySQL Forge - http://forge.mysql.com/wiki/Fixing_Bugs

/ Magnus
[12 Jun 2007 11:40] Jorge Bernal
Patch to fix this bug

Attachment: 28304-truncate_default_value.diff (application/octet-stream, text), 615 bytes.

[12 Jun 2007 11:41] Jorge Bernal
Test case for previous patch

Attachment: 28304-truncate_default_value-test.diff (application/octet-stream, text), 3.22 KiB.

[6 Jul 2007 19:53] Chad MILLER
This adds a tiny amount of complexity to the parser, in exchange for a tiny amount of value.  It's hard to measure the two small quantities, so I'm going to fall back to my default disallow rule, and refuse it on the grounds that the case for adding it isn't made.

Commentary for and against adding it is welcome.