Dylan Su
Dylan Su

Reputation: 6065

When setting system variable 'sql_warnings' to 0, why still get the warning?

Recreating SQLs:

drop table t1;

set sql_mode = '';
create table t1 (c1 int, c2 int); 
set sql_warnings = 0;
SHOW VARIABLES LIKE '%sql_warnings%';
insert into t1 values(1,'b');

set sql_warnings = 1;
SHOW VARIABLES LIKE '%sql_warnings%';
insert into t1 values(1,'b');

Output:

mysql> create table t1 (c1 int, c2 int);
Query OK, 0 rows affected (0.01 sec)

mysql> set sql_warnings = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE '%sql_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_warnings  | OFF   |
+---------------+-------+
1 row in set, 1 warning (0.01 sec)

mysql> insert into t1 values(1,'b');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> set sql_warnings = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE '%sql_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_warnings  | ON    |
+---------------+-------+
1 row in set, 1 warning (0.00 sec)

mysql> insert into t1 values(1,'b');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

From the output, no matter setting sql_warnings to 0 or 1, I am always getting the warnings in the INSERT statement. Anyone knows why?

Update:

Result for "SHOW VARIABLES LIKE '%sql_warnings%';" is added above.

Upvotes: 2

Views: 547

Answers (1)

Dylan Su
Dylan Su

Reputation: 6065

Filed a bug to MySQL and they verified it as a bug from version 5.0 to 5.7.

http://bugs.mysql.com/bug.php?id=80404

I am curious why this obvious behavior is not found before.

Upvotes: 1

Related Questions