Description:
mysql> drop table if exists t1; create table t1(a int primary key, b char(20));
Query OK, 0 rows affected (0.01 sec)
insert into t1 values(1,NULL);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values(1,NULL);
Query OK, 1 row affected (0.00 sec)
mysql> select a , b , replace('xxx','yyy',b) from t1;
+---+------+------------------------+
| a | b | replace('xxx','yyy',b) |
+---+------+------------------------+
| 1 | NULL | NULL |
+---+------+------------------------+
1 row in set (0.00 sec)
mysql> select a , b , replace('xxx','',b) from t1;
+---+------+---------------------+
| a | b | replace('xxx','',b) |
+---+------+---------------------+
| 1 | NULL | xxx |
+---+------+---------------------+
1 row in set (0.00 sec)
mysql> select a , b , replace('xxx','x',b) from t1;
+---+------+----------------------+
| a | b | replace('xxx','x',b) |
+---+------+----------------------+
| 1 | NULL | NULL |
+---+------+----------------------+
1 row in set (0.00 sec)
mysql> select database(), version();
+------------+------------+
| database() | version() |
+------------+------------+
| test | 5.6.22-log |
+------------+------------+
1 row in set (0.00 sec)
mysql> show create database test;
+----------+------------------------------------------------------------------+
| Database | Create Database |
+----------+------------------------------------------------------------------+
| test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |
+----------+------------------------------------------------------------------+
1 row in set (0.00 sec)
How to repeat:
drop table if exists t1; create table t1(a int primary key, b char(20));
insert into t1 values(1,NULL);
insert into t1 values(1,NULL);
select a , b , replace('xxx','yyy',b) from t1;
select a , b , replace('xxx','',b) from t1;
select a , b , replace('xxx','x',b) from t1;
Suggested fix:
replace('xxx','',b) when column b is NULL should returns null.