cockroachdb / cockroachdb/cockroach

plpgsql: local cursor variable name should become "outer" cursor name

Open
#114,702 0 comments 0 reactions 0 assignees View on GitHub
A-sql-pgcatalog A-sql-pgcompat A-sql-plpgsql C-bug O-qa P-3 T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Noticed when looking at one of our existing tests. Consider the following setup:
```sql
DROP FUNCTION IF EXISTS f();
CREATE FUNCTION f() RETURNS INT AS $$
DECLARE
curs CURSOR FOR SELECT 100;
BEGIN
OPEN curs;
RETURN 0;
END
$$ LANGUAGE PLpgSQL;
BEGIN;
SELECT f();
SELECT name FROM pg_cursors;
COMMIT;
```
In postgres it returns the following:
```
name
------
curs
```
which IIUC indicates that the local variable name for the cursor becomes the cursor names outside of the function declaration.

However, in CRDB we get the following:
```
name
----------------------

```
The name of the cursor wasn't explicitly provided, so we used internally-generated one.

Jira issue: CRDB-33640

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.