[MDEV-11324] got error 'Invalid default value for timestamp column' when trying create copy table structure from view Created: 2016-11-21  Updated: 2016-12-07

Status: Stalled
Project: MariaDB Server
Component/s: Data Definition - Temporary
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Mikhail Gavrilov Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None

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

 Description   

I create duplicate issue of https://jira.mariadb.org/browse/MDEV-10935
Because I have no rights for REOPEN and issue still not fixed in 10.1.19
This is critical because popular software as SQLyog unable copy VIEW from one database to another.



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

mikhail,

MDEV-10935 wasn't re-opened after your comment because there was nothing to re-open it for. It was closed as not a bug with an explanation.
Naturally you can reproduce it on 10.1.19 (or any other version of MariaDB/MySQL for that matter), it does not work because it's not expected to work, and nowhere it has ever been promised to work.

There are plenty of ways to do what you are trying to do.

To copy a view structure, you don't need a temporary table which selects from the view, you need to use the same SELECT that the view uses – that is, select from the underlying table.

If you do need a table to be created by selecting from a view on whatever reason, you can unset 'NO_ZERO_DATE' in sql_mode.

If you do need the table to select from a view, and you absolutely need NO_ZERO_DATE at this very moment, you can specify the column definition explicitly, something like

CREATE TEMPORARY TABLE `tt_example` (insert_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) SELECT * FROM `v_example` WHERE 0;

The chosen way is a combination of conditions that simply cannot work together. You select from a view which has no knowledge whasoever about default column values in underlying tables, it can only use the "hard" default; then, you forbid this hard default by setting 'NO_ZERO_DATE'.

Comment by Mikhail Gavrilov [ 2016-11-27 ]

> The chosen way is a combination of conditions that simply cannot work together. You select from a view which has no knowledge whasoever about default column values in underlying tables, it can only use the "hard" default; then, you forbid this hard default by setting 'NO_ZERO_DATE'.

Why DBMS in the SELECT context with lots of JOINs understands default column values, but in VIEW no understands?
Anyway I still able create new table with TIMESTAMP without DEFAULT value and with setting 'NO_ZERO_DATE'

CREATE TABLE `t_new3` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `description` VARCHAR(10) DEFAULT NULL,
  `insert_time` TIMESTAMP NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1

I an understand this is nowhere described, but currently really annoying. Because error message senseless and expected that SELECT always can replaceble by VIEW.

It cannot be fixed by design?

Comment by Elena Stepanova [ 2016-12-07 ]

I've converted it into a feature request, if you want to make it such, but it cannot possibly be critical, because there are many ways to accomplish this goal, you're just choosing one which cannot work with current implementation.

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