cockroachdb / cockroachdb/cockroach
plpgsql: implement parameterless RAISE to re-raise the current exception
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Is your feature request related to a problem? Please describe.**
PostgreSQL's PL/pgSQL supports a parameterless `RAISE;` inside an
`EXCEPTION` handler, which re-raises the exception currently being
handled (preserving its SQLSTATE, message, hint, etc.):
```sql
CREATE FUNCTION do_work() RETURNS void AS $$
BEGIN
-- ... work that may fail ...
EXCEPTION WHEN others THEN
PERFORM log_failure();
RAISE; -- re-raise the original error to the caller
END;
$$ LANGUAGE plpgsql;
```
CockroachDB rejects this at parse time:
- [`pkg/sql/plpgsql/parser/plpgsql.y:1199-1203`](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/plpgsql/parser/plpgsql.y#L1199-L1203)
```go
stmt_raise:
RAISE ';'
{
return unimplemented(plpgsqllex, "empty RAISE statement")
}
```
The error is reported under the bare telemetry key
`unimplemented.empty RAISE statement`, with no link to a tracking
issue.
**Describe the solution you'd like**
Inside an `EXCEPTION` handler, parameterless `RAISE;` should re-raise
the exception currently being handled, preserving SQLSTATE, message,
detail, hint, and any other diagnostic fields. Outside an exception
handler, parameterless `RAISE;` should produce the same error as
PostgreSQL (`RAISE without parameters cannot be used outside an
exception handler`, SQLSTATE 0A000 / 42P22 — match PG's exact
behavior). Migrate the parser site to an issue-linked unimplemented
helper referencing this issue once the work lands.
Related: #169557 (split catch-all PL/pgSQL telemetry).
Jira issue: CRDB-63538
Epic CRDB-49018
Contributor guide
Assessment
This issue has not been assessed yet.