cockroachdb / cockroachdb/cockroach
Integer overflow with prepared statement
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
Please describe the issue you observed, and any steps we can take to reproduce it:
**To Reproduce**
Hi,
In the following test case, I tried to insert value `2010947502` into a column with SMALLINT type and succeeded.
```
CREATE TABLE t1 (c0 SMALLINT);
PREPARE prepare_query (unknown, unknown, int8) AS UPSERT INTO t1 (c0) VALUES($1), ($2), ($3);
EXECUTE prepare_query(NULL, NULL, 2010947502);
DEALLOCATE prepare_query;
SELECT * FROM t1;
c0
NULL
NULL
-24658
```
**Expected behavior**
A clear and concise description of what you expected to happen.
I tried with a normal statement, it threw an error. I expected the prepared statement should have the same behaviour.
```
CREATE TABLE t1 (c0 SMALLINT);
UPSERT INTO t1 (c0) VALUES(NULL), (NULL), (2010947502);
ERROR: integer out of range for type int2
SQLSTATE: 22003
```
**Additional data / screenshots**
If the problem is SQL-related, include a copy of the SQL query and the schema
of the supporting tables.
If a node in your cluster encountered a fatal error, supply the contents of the
log directories (at minimum of the affected node(s), but preferably all nodes).
Note that log files can contain confidential information. Please continue
creating this issue, but contact support@cockroachlabs.com to submit the log
files in private.
If applicable, add screenshots to help explain your problem.
**Environment:**
- CockroachDB version [CockroachDB CCL v25.1.6 (x86_64-pc-linux-gnu, built 2025/05/09 15:48:03, go1.22.8 X:nocoverageredesign)]
- Server OS: [Ubuntu 24.04]
- Client app [`cockroach sql`, JDBC]
**Additional context**
What was the impact?
Add any other context about the problem here.
Jira issue: CRDB-53965
Contributor guide
Assessment
This issue has not been assessed yet.