Create a computed/PERSISTED column with current date

Persisted computed columns have to be set to deterministic expressions of one or more other columns. Using the current time in a computed column expression is non-deterministic and thus is not supported.

If you want to use the current time value in a field when you insert or update the record, you can use something like:

memsql> create table t(a int, 
 ts datetime(6) on update current_timestamp(6) default current_timestamp(6));
Query OK, 0 rows affected (0.15 sec)

memsql> insert t(a) values(1);
Query OK, 1 row affected (0.08 sec)

memsql> select * from t;
+------+----------------------------+
| a    | ts                         |
+------+----------------------------+
|    1 | 2021-02-17 15:42:40.294605 |
+------+----------------------------+

See here for more information:

Also, using the timestamp or timestamp(6) types is not recommended–they run out in 2038. Use datetime or datetime(6) instead.

1 Like