Bug #70739 Use same fsp for CURRENT_TIMESTAMP as for column by default

Submitted: 27 Oct 2013 9:52 Modified: 19 Mar 2025 6:53
Reporter: Daniël van Eeden Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: DDL Severity:S4 (Feature request)
Version:5.6, 5.7, 8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: DEFAULT, fsp, timestamp

[27 Oct 2013 9:52] Daniël van Eeden
Description:
A column with a fsp only works if the default value uses the same fsp, so why shouldn't that be the default then?

How to repeat:
mysql> CREATE TABLE t1 (ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP);
ERROR 1067 (42000): Invalid default value for 'ts'

mysql> CREATE TABLE t1 (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(6));
ERROR 1067 (42000): Invalid default value for 'ts'

mysql> CREATE TABLE t1 (ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6));
Query OK, 0 rows affected (0.02 sec)

Suggested fix:
If a fsp is supplied for a column then the same fsp should also be used for the default value for the column.
[21 Aug 2017 9:48] Daniël van Eeden
update versions
[21 Aug 2017 9:49] Daniël van Eeden
Related:
Bug #71982 	TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP --> invalid
[7 Jan 2021 8:06] Daniël van Eeden
This is still valid. Could this be verified?
[19 Mar 2025 6:53] Daniël van Eeden
Note that MySQL now supports this:

...
  ts DATETIME(2) DEFAULT (NOW())
...

However this doesn't behave the same as:

...
  ts DATETIME(2) DEFAULT (NOW(2))
...

So with `()` around `NOW(...)` you don't have to match the fsp, but if you don't specify it you will loose precision as it uses a 0 fsp in that case.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 2.531 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.