Bug #83704 Invalid default value for TIMESTAMP DEFAULT CURRENT_TIMESTAMP column
Submitted: 5 Nov 2016 13:54 Modified: 7 Nov 2016 8:04
Reporter: Romain Riche Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[5 Nov 2016 13:54] Romain Riche
Description:
When using:
- a timestamp column with default 
- a temporary table
- a sub query (2 "select" in cascade)

the following error is raised:
Error Code: 1067. Invalid default value for 'ts'

This seems to be a regression in 5.7.x. The same sequence of statements work fine in 5.5.x.  Am I missing something or is it effectively a bug / regression?

How to repeat:
CREATE TABLE `TEST_TABLE` (`ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
INSERT INTO TEST_TABLE() VALUES ();

DROP TEMPORARY TABLE IF EXISTS TMP_TEST;
CREATE TEMPORARY TABLE TMP_TEST
SELECT * FROM (SELECT ts FROM TEST_TABLE) wrap;

== >> Error Code: 1067. Invalid default value for 'ts'
[5 Nov 2016 15:14] Romain Riche
to avoid confusion on the sample code, here is a better one:

CREATE TABLE TEST_TABLE (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
INSERT INTO TEST_TABLE() VALUES ();
CREATE TEMPORARY TABLE TMP_TEST SELECT * FROM (SELECT ts FROM TEST_TABLE) wrap;
[5 Nov 2016 18:48] Miguel Solorzano
Thank you for the bug report. I couldn't repeat with server with most recent source:

miguel@tikal:~/dbs $ ./57c
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.17-log Source distribution PULL: 2016-OCT-14

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.7 > use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql 5.7 > CREATE TABLE TEST_TABLE (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Query OK, 0 rows affected (0.51 sec)

mysql 5.7 > INSERT INTO TEST_TABLE() VALUES ();
Query OK, 1 row affected (0.08 sec)

mysql 5.7 > CREATE TEMPORARY TABLE TMP_TEST SELECT * FROM (SELECT ts FROM TEST_TABLE) wrap;
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql 5.7 > create database test1;
Query OK, 1 row affected (0.00 sec)

mysql 5.7 > use test1
Database changed
mysql 5.7 > CREATE TABLE `TEST_TABLE` (`ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Query OK, 0 rows affected (0.20 sec)

mysql 5.7 > INSERT INTO TEST_TABLE() VALUES ();
Query OK, 1 row affected (0.00 sec)

mysql 5.7 > 
mysql 5.7 > DROP TEMPORARY TABLE IF EXISTS TMP_TEST;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql 5.7 > CREATE TEMPORARY TABLE TMP_TEST
    -> SELECT * FROM (SELECT ts FROM TEST_TABLE) wrap;
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql 5.7 >
[7 Nov 2016 4:45] Romain Riche
I understand it is working for you but it is not on my server 5.7 although working fine on 5.5.

Also if I change TIMESTAMP to DATETIME, then no error.. Any idea what's going on here?

Thanks
[7 Nov 2016 8:04] Romain Riche
alright the problem happens when using this sql_mode:

SET SESSION sql_mode = 'NO_ZERO_DATE';

Any reason why?