pingcap / pingcap/tidb

Integer was cast to wrong char value in prepared statement.

Open
#62,772 1 comment 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
contribution severity/moderate sig/planner 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)

The following test case will cast integer -1 to CHAR. in the normal query, the result is `-1`, however, in the prepared statement, the result is `-`.

```
CREATE TABLE t0(c0 CHAR );
INSERT IGNORE INTO t0 VALUES ('7');
SET @b = 'M';
SELECT CAST((CASE false WHEN CAST('M' AS CHAR) THEN -1 ELSE ( (t0.c0)) END ) AS CHAR) FROM t0;
CAST((CASE false WHEN CAST('M' AS CHAR) THEN -1 ELSE ( (t0.c0)) END ) AS CHAR)
-1

PREPARE prepare_query FROM 'SELECT CAST((CASE false WHEN CAST(? AS CHAR) THEN -1 ELSE ( (t0.c0)) END ) AS CHAR) FROM t0';
EXECUTE prepare_query USING @b;
CAST((CASE false WHEN CAST(? AS CHAR) THEN -1 ELSE ( (t0.c0)) END ) AS CHAR)
-
```

### 2. What did you expect to see? (Required)

The prepared statement should also return `-1`

### 3. What did you see instead (Required)

The prepared statement returns `-`

### 4. What is your TiDB version? (Required)

tidb_version()
Release Version: v9.0.0-beta.2.pre-149-g96f5396\nEdition: Community\nGit Commit Hash: 96f5396be12ae6c5bf440bd22b1e0bec532aff9e\nGit Branch: HEAD\nUTC Build Time: 2025-07-21 20:48:44\nGoVersion: go1.23.11\nRace Enabled: false\nCheck Table Before Drop: false\nStore: tikv\nKernel Type: Classic

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.