cockroachdb / cockroachdb/cockroach
plpgsql: implement ALIAS FOR variable declarations
- 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 allows declaring an alias for a function
parameter or another variable using `ALIAS FOR`:
```sql
CREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
DECLARE
amount ALIAS FOR subtotal; -- alternate name for the parameter
BEGIN
RETURN amount * 0.06;
END;
$$ LANGUAGE plpgsql;
```
CockroachDB rejects this at parse time:
- [`pkg/sql/plpgsql/parser/plpgsql.y:476-479`](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/plpgsql/parser/plpgsql.y#L476-L479)
```go
| decl_varname ALIAS FOR decl_aliasitem ';'
{
return unimplemented(plpgsqllex, "alias for")
}
```
The error is reported under the bare telemetry key
`unimplemented.alias for`, with no link to a tracking issue.
**Describe the solution you'd like**
Implement ` ALIAS FOR ` in the PL/pgSQL declaration
section, where `` may be either a function parameter
(by name or by `$N` positional reference) or another previously-declared
variable. References to the alias should resolve to the underlying
slot, so reads and assignments behave identically to using the original
name. 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-63537
Epic CRDB-49018
Contributor guide
Assessment
This issue has not been assessed yet.