Details
-
Type:
Bug
-
Status: Confirmed
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 10.1, 10.0, 5.5
-
Component/s: Triggers
-
Labels:
-
Environment:Linux
Description
MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column.
Expected similar behavior as for AUTOINCREMENT and would be usefull for generation right value in trigger.
http://stackoverflow.com/questions/15473654/mariadb-before-insert-trigger-for-uuid
Of course in described example much better if MariaDB would support UUID data type and generate automaticaly UUID for AUTOINCREMENT fields.
But I think it would be good idea if MariaDB would allow use any function for default value it would be good replacement of generators.
For example:
CREATE TABLE `c` ( `id` VARBINARY(36) NOT NULL DEFAULT UUID(), PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8
And it would here appropriate analogy with the behavior of AUTOINCREMENT
And if make possible to work with property table autoincrement into functions would be generally be a bomb. It would be possible create complicated ID with concatenation static identifier if schema and autoincrement.
For example:
A-1
A-2
A-3
A-5
and on another schema for same table
B-1
B-2
B-3
B-4
Gliffy Diagrams
Attachments
Issue Links
- relates to
-
MDEV-4958 Adding datatype UUID
-
- Open
-
- links to
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Default specifies a value which should be inserted when no value is provided explicitly. When you attempt to insert NULL, it's not an absence of a value, it's a value NULL. So, naturally the default value is not used. It is so both for MySQL and MariaDB. AUTO_INCREMENT is essentially different in this regard.
Possibly a good solution for your case would have been using virtual columns, only they don't seem to support UUID.
What you describe in the last part, however, is easy to implement via virtual columns:
MariaDB [test]> create table t (i int auto_increment primary key, b varchar(16) as (concat('A-',i)) persistent); Query OK, 0 rows affected (0.91 sec) MariaDB [test]> insert into t (i) values (1),(2); Query OK, 2 rows affected (0.18 sec) Records: 2 Duplicates: 0 Warnings: 0 MariaDB [test]> select * from t; +---+------+ | i | b | +---+------+ | 1 | A-1 | | 2 | A-2 | +---+------+ 2 rows in set (0.00 sec)I can convert your report into a feature request, but please specify what exactly you are after, as you have several suggestions here: