[MDEV-11269] In NO_ZERO_DATE mode, multiple timestamp fields with no default can't be created Created: 2016-11-10  Updated: 2016-11-13  Resolved: 2016-11-13

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.1.18, 10.0.28, 10.2.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Nirbhay Choubey (Inactive) Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: need_feedback

Issue Links:
Relates
relates to MDEV-7635 update defaults and simplify mysqld c... Closed

 Description   

MariaDB [test]> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1(a timestamp, b timestamp);
Query OK, 0 rows affected (0.11 sec)
 
MariaDB [test]> set sql_mode = 'NO_ZERO_DATE';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t2(a timestamp, b timestamp);
ERROR 1067 (42000): Invalid default value for 'b'
 
MariaDB [test]> create table t2(a timestamp, b int, c timestamp);
ERROR 1067 (42000): Invalid default value for 'c'
 
MariaDB [test]> create table t2(a timestamp);
Query OK, 0 rows affected (0.07 sec)

Index creation is affected as well.

MariaDB [test]> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1(a timestamp, b timestamp);
Query OK, 0 rows affected (0.06 sec)
 
MariaDB [test]> set sql_mode='NO_ZERO_DATE';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create index idx on t1(a);
ERROR 1067 (42000): Invalid default value for 'b'
 
MariaDB [test]> set sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES';
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> create index idx on t1(a);
ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'b' at row 1

Also, it seems impossible to use current_timestamp in CREATE TABLE .. ON UPDATE.

MariaDB [test]> set sql_mode = 'NO_ZERO_DATE';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(5));
ERROR 1067 (42000): Invalid default value for 'a'
 
MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(4));
ERROR 1294 (HY000): Invalid ON UPDATE clause for 'a' column
 
MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(6));
ERROR 1067 (42000): Invalid default value for 'a'
 
MariaDB [test]> create table t1 (a timestamp on update current_timestamp);
ERROR 1067 (42000): Invalid default value for 'a'



 Comments   
Comment by Elena Stepanova [ 2016-11-12 ]

nirbhay_c,

I don't see anything wrong with any of these examples.
In each case when the DDL is rejected with invalid default value, one of timestamp columns is given default value '0000-00-00 00:00:00', which is not allowed with NO_ZERO_DATE.
When you create a table with multiple TIMESTAMP columns, the legacy logic is in play, the first column gets the default value CURRENT_TIMESTAMP, but others are still zero.

Comment by Nirbhay Choubey (Inactive) [ 2016-11-13 ]

So it's only the first column that gets the default. In that case, its not a bug.

Generated at Thu Feb 08 07:48:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.