pingcap / pingcap/tidb

Empty string treated as equal to space ' ' when used with RIGHT() function

Open
#66,101 0 comments 0 reactions 0 assignees View on GitHub
contribution severity/moderate sig/execution sig/sql-infra type/bug
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
mysql> DROP TEMPORARY TABLE IF EXISTS t_repro;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TEMPORARY TABLE t_repro (col VARCHAR(10));
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t_repro VALUES ('');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM t_repro WHERE RIGHT(col, 1) = ' ';
+------+
| col |
+------+
| |
+------+
1 row in set (0.00 sec)
```

### 2. What did you expect to see? (Required)
Return 0 rows, since `RIGHT('', 1) = '' ≠ ' '`

### 3. What did you see instead (Required)
```SQL
mysql> SELECT * FROM t_repro WHERE RIGHT(col, 1) = ' ';
+------+
| col |
+------+
| |
+------+
1 row in set (0.00 sec)
```

### 4. What is your TiDB version? (Required)
```SQL
mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-1207-g229a104ba4
Edition: Community
Git Commit Hash: 229a104ba411e831602c0b18c95b02cdcb454957
Git Branch: master
UTC Build Time: 2026-02-06 02:01:40
GoVersion: go1.25.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.