Bug #17809 | support for DEFAULT CURRENT_USER | ||
---|---|---|---|
Submitted: | 28 Feb 2006 22:24 | Modified: | 10 Mar 2023 1:18 |
Reporter: | Peter Laursen (Basic Quality Contributor) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S4 (Feature request) |
Version: | OS: | Any (any) | |
Assigned to: | CPU Architecture: | Any |
[28 Feb 2006 22:24]
Peter Laursen
[5 Mar 2006 9:07]
Valeriy Kravchuk
Thank you for a reasonable feature request. This feature will be available as soon as expressions will be allowed in DEFAULT clause.
[5 Mar 2006 9:30]
Peter Laursen
Any idea when that will be ?
[10 Mar 2023 1:18]
Jon Stephens
This enhancement is implemented in MySQL 8.0.34, described in the 8.0.34 changelog as follows: CURRENT_USER() can now be used as a default value for CHAR, VARCHAR, and TEXT columns in CREATE TABLE and ALTER TABLE ... ADD COLUMN statements. To insure that values having the maximum possible length can be stored, the column should be able to accommodate 288 characters (or more). The synonyms SESSION_USER() and USER() are also supported in all of the cases just mentioned. For example, the following sequence of statements now works similarly to what is shown here: mysql> SELECT CURRENT_USER(); +-------------------+ | CURRENT_USER() | +-------------------+ | sakila@localhost | +-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE t ( > c1 VARCHAR(288) DEFAULT (USER()), > c2 VARCHAR(288) DEFAULT (CURRENT_USER()), > c3 VARCHAR(288) DEFAULT (SESSION_USER()) > ); Query OK, 0 rows affected (0.04 sec) mysql> INSERT INTO t VALUES ROW(); Query OK, 1 row affected (0.01 sec) mysql> TABLE t; +-------------------+-------------------+-------------------+ | c1 | c2 | c3 | +-------------------+-------------------+-------------------+ | sakila@localhost | sakila@localhost | sakila@localhost | +-------------------+-------------------+-------------------+ 1 row in set (0.00 sec) When used in this way, these functions are also included in the output of SHOW CREATE TABLE and SHOW COLUMNS, and can be seen in the COLUMN_DEFAULT column of the Information Schema COLUMNS table. Closed.