Re: PL/pgSQL cursors should get generated portal names by default

Pavel Stehule <pavel.stehule@gmail.com>

From: Pavel Stehule <pavel.stehule@gmail.com>
To: Kirk Wolak <wolakk@gmail.com>
Cc: Jan Wieck <jan@wi3ck.info>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2023-01-09T15:50:29Z
Lists: pgsql-hackers
Hi

I wrote a new check in plpgsql_check, that tries to identify explicit work
with the name of the referenced portal.

create or replace function foo01()
returns refcursor as $$#option dump
declare
  c cursor for select 1;
  r refcursor;
begin
  open c;
  r := 'c';
  return r;
end;
$$ language plpgsql;
CREATE FUNCTION
(2023-01-09 16:49:10) postgres=# select * from
plpgsql_check_function('foo01', compatibility_warnings => true);
┌───────────────────────────────────────────────────────────────────────────────────┐
│                              plpgsql_check_function
        │
╞═══════════════════════════════════════════════════════════════════════════════════╡
│ compatibility:00000:7:assignment:obsolete setting of refcursor or cursor
variable │
│ Detail: Internal name of cursor should not be specified by users.
        │
│ Context: at assignment to variable "r" declared on line 4
        │
│ warning extra:00000:3:DECLARE:never read variable "c"
        │
└───────────────────────────────────────────────────────────────────────────────────┘
(4 rows)

Regards

Pavel

Commits

  1. In plpgsql, don't preassign portal names to bound cursor variables.