[MDEV-10935] got error 'Invalid default value for timestamp column' when trying create copy table structure from view Created: 2016-10-01  Updated: 2016-11-18  Resolved: 2016-10-03

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Temporary
Affects Version/s: 10.1.19
Fix Version/s: 10.1.19

Type: Bug Priority: Major
Reporter: Mikhail Gavrilov Assignee: Oleksandr Byelkin
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Linux Fedora 24


Attachments: PNG File Screenshot from 2016-11-18 13-29-22.png    

 Description   

MariaDB [test]> CREATE TABLE `t_example` (
    ->   `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   `description` VARCHAR(10) DEFAULT NULL,
    ->   `insert_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY (`id`)
    -> );
Query OK, 0 rows affected (0.05 sec)
 
MariaDB [test]> CREATE VIEW `v_example` AS (
    -> SELECT
    ->   `id`          AS `id`,
    ->   `description` AS `description`,
    ->   `insert_time` AS `insert_time`
    -> FROM `t_example`);
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> CREATE TEMPORARY TABLE `tt_example` SELECT * FROM `v_example` WHERE 0;
ERROR 1067 (42000): Invalid default value for 'insert_time'
MariaDB [test]> SELECT @@SQL_MODE;
+---------------------------------------------------------------------------------------------------------------------------+
| @@SQL_MODE                                                                                                                |
+---------------------------------------------------------------------------------------------------------------------------+
| NO_BACKSLASH_ESCAPES,STRICT_ALL_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.1.17-MariaDB |
+-----------------+
1 row in set (0.00 sec)



 Comments   
Comment by Elena Stepanova [ 2016-10-01 ]

sanja, could you please take a look?

My first thought was that CREATE TABLE .. SELECT <view> is not supposed to inherit default values from the underlying tables; but this 10-year old bug suggests otherwise:
https://bugs.mysql.com/bug.php?id=19089.
It is said to be fixed long time ago, but I don't see the "fixed" behavior now, neither in MariaDB nor in MySQL (5.7), maybe it has been long lost.
I rely on you to figure out what's the right thing to do here.

Comment by Oleksandr Byelkin [ 2016-10-03 ]

The above mentioned bug was about different - automatic default and NULL/NOT NULL.

I doubts that CREATE TABLE ... SELECT could easy extract default from table created from expression (in general case). expression has not attribute default value (but has may be NULL/can not be NULL).

So it is not a bug (actually nowhere in the documentation promised transfer of default values because expression do not has it). It is probably feature request for some cases where it is not an expression possible to get default.

Internally in 99% cases the transfer has no any sens so it is not done (actually if do it in all cases for temporary tables used inside it bring some performance penalty).

Comment by Mikhail Gavrilov [ 2016-11-18 ]

Bug reproduced also in version 10.1.19, please REOPEN bug

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