cockroachdb / cockroachdb/cockroach
sql: type annotation does not work correctly in 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:
Hi, the following prepared statement is equivalent to the normal statement, however, the normal statement triggers an error.
**To Reproduce**
```
PREPARE prepare_query (int8) AS SELECT DISTINCT STDDEV((($1) :::DECIMAL));
EXECUTE prepare_query(-1); -- NULL
DEALLOCATE prepare_query;
SELECT DISTINCT STDDEV((((-1)::INT8) :::DECIMAL)); -- ERROR: stddev(): incompatible type annotation for ((-1):::INT8) as decimal, found type: int
```
**Expected behavior**
No error in the normal statement.
**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.4.1 (x86_64-pc-linux-gnu, built 2025/11/26 12:08:42, go1.23.12 X:nocoverageredesign)]
- Server OS: [Linux]
- Client app [`cockroach sql`, JDBC]
**Additional context**
What was the impact?
Add any other context about the problem here.
Jira issue: CRDB-57611
Contributor guide
Research direction
Start by running the provided PREPARE/EXECUTE and normal SELECT statements in cockroach sql, then compare how the prepared statement and direct expression handle the DECIMAL type annotation. Done means the normal SELECT no longer reports an incompatible type annotation while preserving the prepared statement's behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100