cockroachdb / cockroachdb/cockroach
sql: add support for TRUNCATE TABLE in stored procedures
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
We should allow `TRUNCATE TABLE` inside PL/pgSQL stored procedure bodies.
PR #168464 added support for `CREATE TABLE` and `DROP TABLE` in stored procedures by extending the optbuilder allowlist to permit those DDL statements in procedure definitions (not functions or DO blocks), gated by the cluster version (v26.3). The same approach should be followed here:
- Add the `TRUNCATE TABLE` AST node to the optbuilder allowlist for stored procedures.
- Gate the feature behind the appropriate cluster version.
- Ensure the feature is limited to stored procedures (not functions or DO blocks), consistent with the pattern established in #168464.
Note: as described in #168464, at compile time all statement references are resolved against the current catalog. This is a known divergence from PostgreSQL's late-binding model and will be addressed separately.
Jira issue: CRDB-63442
Epic CRDB-65937
Contributor guide
Assessment
This issue has not been assessed yet.