[MDEV-23531] Allow functions for column default values Created: 2020-08-21 Updated: 2023-06-12 Resolved: 2020-08-31 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Create Table |
| Fix Version/s: | 10.2.1 |
| Type: | Task | Priority: | Major |
| Reporter: | Manjot Singh (Inactive) | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
With datetime we can do:
We should be able to use any function as a default on any data type, like this:
|
| Comments |
| Comment by Sergei Golubchik [ 2020-08-30 ] | |||||||||||
|
See https://mariadb.com/kb/en/create-table/#default-column-option | |||||||||||
| Comment by Manjot Singh (Inactive) [ 2020-08-31 ] | |||||||||||
|
Thanks for pointing out the documentation I missed. But this still only works on only blob and text columns. This ticket is for any column type. In my example, updatedBy is currentUser.. I wouldn't want to take the overhead of text for something that is usually less than 50 characters. Also, ON UPDATE does not work with text.
| |||||||||||
| Comment by Sergei Golubchik [ 2020-08-31 ] | |||||||||||
|
ON UPDATE is a non-standard historical extension for TIMESTAMP columns. Use triggers instead. | |||||||||||
| Comment by Manjot Singh (Inactive) [ 2020-08-31 ] | |||||||||||
|
I just showed you that it doesn't work for int or varchar. .. it doesnt work for any column type. | |||||||||||
| Comment by Oded Arbel [ 2023-06-12 ] | |||||||||||
|
The documentation for "DEFAULT Column Option" seems to suggest that as of MariaDB 10.2.1, one can create tables with a DEFAULT option set to a function or and expression, which I understand to mean - it is possible to create a table with a column default value calling a user function. If I try to do that, I get something like this:
I think this is what the OP was talking about. |