TiDB LIKE...ESCAPE compatability issues
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```sql
SELECT ('a%b' LIKE 'a\%b' ESCAPE NULL); -- Escape with NULL is not working
SELECT ('a%b' LIKE 'ax%b' ESCAPE (SELECT 'x')); -- when escape string is from subquery is not working
SELECT 'a' LIKE '%' ESCAPE CAST('' AS JSON); -- incorrect error message
SELECT 'abc' like 'a\\bc' ESCAPE ''; -- incorrect results
SELECT _latin1'abc' LIKE _latin1'a\\bc' ESCAPE _latin1''; -- Escape string with charset name is not working
```
### 2. What did you expect to see? (Required)
```sql
mysql> SELECT ('a%b' LIKE 'a\%b' ESCAPE NULL);
+---------------------------------+
| ('a%b' LIKE 'a\%b' ESCAPE NULL) |
+---------------------------------+
| 1 |
+---------------------------------+
1 row in set (0.00 sec)
mysql> SELECT ('a%b' LIKE 'ax%b' ESCAPE (SELECT 'x'));
+-----------------------------------------+
| ('a%b' LIKE 'ax%b' ESCAPE (SELECT 'x')) |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT 'a' LIKE '%' ESCAPE CAST('' AS JSON);
ERROR 3141 (22032): Invalid JSON text in argument 1 to function cast_as_json: "The document is empty." at position 0.
mysql> select 'abc' like 'a\\bc' ESCAPE '';
+------------------------------+
| 'abc' like 'a\\bc' ESCAPE '' |
+------------------------------+
| 0 |
+------------------------------+
1 row in set (0.00 sec)
mysql> SELECT _latin1'abc' LIKE _latin1'a\\bc' ESCAPE _latin1'';
+---------------------------------------------------+
| _latin1'abc' LIKE _latin1'a\\bc' ESCAPE _latin1'' |
+---------------------------------------------------+
| 0 |
+---------------------------------------------------+
1 row in set (0.00 sec)
```
### 3. What did you see instead (Required)
```sql
mysql> SELECT ('a%b' LIKE 'a\%b' ESCAPE NULL);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 37 near "NULL)"
mysql> SELECT ('a%b' LIKE 'ax%b' ESCAPE (SELECT 'x'));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 34 near "(SELECT 'x'))"
mysql> SELECT 'a' LIKE '%' ESCAPE CAST('' AS JSON);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 31 near "CAST('' AS JSON)"
mysql> select 'abc' like 'a\\bc' ESCAPE '';
+------------------------------+
| 'abc' like 'a\\bc' ESCAPE '' |
+------------------------------+
| 1 |
+------------------------------+
1 row in set (0.01 sec)
mysql> SELECT _latin1'abc' LIKE _latin1'a\\bc' ESCAPE _latin1'';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 54 near "_latin1''"
```
### 4. What is your TiDB version? (Required)
```sql
| Release Version: v5.5.0-alpha-182-gad9430039
Edition: Community
Git Commit Hash: ad9430039f54bb9af78d44831c176bc5eafcbba0
Git Branch: master
UTC Build Time: 2022-02-04 18:58:58
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
```
Contributor guide
Assessment
This issue has not been assessed yet.