Bug #105667 TINYINT display length is dropped when set to UNSIGNED
Description:
Setting the Unsigned attribute overrides the field display length.
For example: I can do the following:
ALTER TABLE `users`
CHANGE COLUMN `is_active` `is_active` TINYINT(1) NOT NULL DEFAULT '1' ;
and the table correctly sets the field display length. But if I do this:
ALTER TABLE `users`
CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ;
The field length is no longer set.
when I set TINYINT(1) UNSIGNED, the display length is dropped.
How to repeat:
STR:
1. Create a table with a field intended to be used as a BOOLEAN;
CREATE TABLE `users` (
`id` int unsigned NOT NULL AUTO_INCREMENT ,
`user_name` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
2. Observe that the display length on TINYINT(1) is in fact set.
3. Alter the table to make is_active an UNSIGNED value:
ALTER TABLE `users`
CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ;
4. Observe that TINYINT no longer has a display length.
Suggested fix:
I argue that the correct field attribute for a "BOOLEAN" would be unsigned since your options would be 0 or 1. Not negatives. Therefore I would expect that the UNSIGNED behavior for TINYINT(1) be identical to the signed behavior, and field display length would be set / retained.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: Setting the Unsigned attribute overrides the field display length. For example: I can do the following: ALTER TABLE `users` CHANGE COLUMN `is_active` `is_active` TINYINT(1) NOT NULL DEFAULT '1' ; and the table correctly sets the field display length. But if I do this: ALTER TABLE `users` CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ; The field length is no longer set. when I set TINYINT(1) UNSIGNED, the display length is dropped. How to repeat: STR: 1. Create a table with a field intended to be used as a BOOLEAN; CREATE TABLE `users` ( `id` int unsigned NOT NULL AUTO_INCREMENT , `user_name` varchar(50) NOT NULL, `password` varchar(255) NOT NULL, `is_active` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 2. Observe that the display length on TINYINT(1) is in fact set. 3. Alter the table to make is_active an UNSIGNED value: ALTER TABLE `users` CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ; 4. Observe that TINYINT no longer has a display length. Suggested fix: I argue that the correct field attribute for a "BOOLEAN" would be unsigned since your options would be 0 or 1. Not negatives. Therefore I would expect that the UNSIGNED behavior for TINYINT(1) be identical to the signed behavior, and field display length would be set / retained.