cockroachdb / cockroachdb/cockroach

EXECUTE of PREPAREd ALTER TABLE TTL setting fails with "no type for placeholder $1"

Open
#171,241 1 comment 0 reactions 0 assignees View on GitHub
C-bug O-community T-sql-queries X-blathers-triaged
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

## Describe the problem

Prepared statements for parameterized TTL storage settings fail at execution time. `PREPARE` succeeds, but `EXECUTE` triggers an internal error because placeholder `$1` has no inferred type in the ALTER TABLE TTL parameter path.

This is distinct from direct literal assignment, which works.

**Example signature:**

```
ERROR: internal error: no type for placeholder $1
SQLSTATE: XX000
```

**Representative stack frames (see full trace on your build):**

```
pkg/sql/execute.go:39: fillInPlaceholders()
pkg/sql/conn_executor_exec.go:621: execStmtInOpenState()
pkg/sql/conn_executor_exec.go:182: execStmt()
pkg/sql/conn_executor.go:2503: execCmd()
```

## To Reproduce

Start a single-node cluster for testing, e.g.

```bash
cockroach start-single-node --insecure --listen-addr=localhost
```

Run SQL (via `cockroach sql --insecure` or equivalent):

```sql
CREATE TABLE tbl (id INT PRIMARY KEY)
WITH (ttl_expire_after = '10 minutes');

PREPARE p AS
ALTER TABLE tbl SET (ttl_select_batch_size = $1);

EXECUTE p (100);
```

## Control

Direct literal update works:

```sql
ALTER TABLE tbl SET (ttl_select_batch_size = 100); -- OK
```

`PREPARE` alone also succeeds; the crash happens only on `EXECUTE`.

## Expected behavior

`ttl_select_batch_size` is an integer storage parameter. `PREPARE ... AS ALTER TABLE ... SET (ttl_select_batch_size = $1)` should infer `$1` as an integer-compatible type, and `EXECUTE` should succeed. If parameterized TTL settings are unsupported, return a clear user-facing error instead of `XX000`.

## Environment

- CockroachDB: v26.3.0-alpha.00000000-dev, CCL, linux amd64
- OS: Linux 4.18.0-553.el8_10.x86_64
- Client: `cockroach sql --insecure`

Jira issue: CRDB-64386

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.