Bug #12151 | NOT NULL in view remains in create table .. select from .. left join view | ||
---|---|---|---|
Submitted: | 25 Jul 2005 13:34 | Modified: | 23 Aug 2005 10:55 |
Reporter: | Jun Murai | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 5.0.9-beta | OS: | Windows (Windows XP and Linux) |
Assigned to: | CPU Architecture: | Any |
[25 Jul 2005 13:34]
Jun Murai
[25 Jul 2005 14:17]
Valeriy Kravchuk
Thank you for your bug report. But I can't call the behaviour you described a bug. I can provide you a much simpler test case, wich has nothing to do with views and LEFT JOINs: mysql> create table t12151 (c1 int not null, c2 char(30) not null); Query OK, 0 rows affected (0.08 sec) mysql> desc t12151; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | c1 | int(11) | NO | | | | | c2 | char(30) | NO | | | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.01 sec) mysql> create table tt (c1 int, c2 char(30)); Query OK, 0 rows affected (0.11 sec) mysql> insert into tt values(NULL, NULL); Query OK, 1 row affected (0.04 sec) mysql> insert into t12151 select * from tt; Query OK, 1 row affected, 2 warnings (0.03 sec) Records: 1 Duplicates: 0 Warnings: 2 mysql> show warnings; +---------+------+-------------------------------------------------------------- ---------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------- ---------------+ | Warning | 1263 | Column set to default value; NULL supplied to NOT NULL column 'c1' at row 1 | | Warning | 1263 | Column set to default value; NULL supplied to NOT NULL column 'c2' at row 1 | +---------+------+-------------------------------------------------------------- ---------------+ 2 rows in set (0.00 sec) mysql> select * from t12151; +----+----+ | c1 | c2 | +----+----+ | 0 | | +----+----+ 1 row in set (0.00 sec) mysql> select * from t12151 where c2 is null; Empty set (0.01 sec) So, strictly according to the manual (http://dev.mysql.com/doc/mysql/en/design-limitations.html): " If you insert an ``incorrect'' value in a column, such as a too-large numeric value into a numeric column, MySQL sets the column to the ``best possible value'' instead of giving an error. For numerical values, this is 0, the smallest possible value or the largest possible value. For strings, this is either the empty string or as much of the string as can be stored in the column." 0 and empty string were inserted. (Try "select * from CopiedViewFromView where str is null;" in your case). No constraints are violated. That is why, NOT NULL remains - non-null values are inserted.
[25 Jul 2005 14:41]
Jun Murai
I know that NULL is changed to 0 or empty string when NOT NULL constraint is made. But I can't understand why NULL is allowed in case 1-4, but not in case 5-6. These cases are derived from same tables.
[23 Aug 2005 10:55]
Sergei Golubchik
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at http://www.mysql.com/downloads/ Additional info: This was apparently fixed since 5.0.9, current 5.0.12 returns identical results for all your cases 1-6.