Bug #48801 CREATE TABLE IF NOT EXISTS t does not fail if t is a view
Submitted: 16 Nov 2009 11:30 Modified: 17 Nov 2009 13:51
Reporter: Sven Sandberg Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: DDL Severity:S2 (Serious)
Version:5.0+ OS:Any
Assigned to: CPU Architecture:Any

[16 Nov 2009 11:30] Sven Sandberg
Description:
If t is a view, 'CREATE TABLE IF NOT EXISTS t' just gives a warning, despite no table t exists after the query.  Since the user expects t to exist and be a table after the query, I think it would it be better if this generated an error. This would be consistent with other similar situations, like 'CREATE TABLE t' when t exists and is a view.

How to repeat:
CREATE TABLE t1 (a INT);
--error ER_TABLE_EXISTS_ERROR
CREATE VIEW t1 AS SELECT 1; # Gives an error as expected

CREATE VIEW v2 AS SELECT 1;
CREATE TABLE t2 (a INT);    # Does not give an error!
[16 Nov 2009 12:04] MySQL Verification Team
Thank you for the bug report. Verified as described.
[16 Nov 2009 15:28] Peter Gulutzan
1. I don't understand why "CREATE TABLE t2" should give an error
when there is no base table named t2 and no view named t2, judging
from the 'how to repeat'.

2. Since views are tables, I don't understand in what way the behaviour
contradicts the documentation.
[16 Nov 2009 17:54] Sven Sandberg
Sorry for typos in 'how to repeat'. Here is the correct 'how to repeat':

CREATE TABLE t1 (a INT);
--error ER_TABLE_EXISTS_ERROR
CREATE VIEW t1 AS SELECT 1;               # Gives an error as expected

CREATE VIEW t2 AS SELECT 1;
CREATE TABLE IF NOT EXISTS t2 (a INT);    # Does not give an error!
[17 Nov 2009 13:51] Alexey Botchkov
duplicate of this one:
http://bugs.mysql.com/bug.php?id=47132