Skip to content

Commit

Permalink
plpgsql: add support for FETCH and MOVE statements
Browse files Browse the repository at this point in the history
This patch adds support for the PLpgSQL FETCH and MOVE statements,
which seek and return rows from a cursor. This is handled by a builtin
function, `crdb_internal.plpgsql_fetch`, which calls into the same logic
that implements SQL FETCH and MOVE. Since it is possible to call `FETCH`
with `INTO` variables of different types, the `crdb_internal.plpgsql_fetch`
builtin takes an argument that supplies the expected column types as a
tuple of typed NULL values like this: `(NULL::INT, NULL::BOOL)`. The
actual types supplied by the cursor are coerced into the expected types.

Note that the current implementation does not support using dynamic
expressions in the FETCH/MOVE direction; only constant integer values.
Dynamic direction counts like `FORWARD x` are not allowed in SQL syntax,
but are allowed by PLpgSQL.

Informs cockroachdb#109709

Release note (sql change): Added support for PLpgSQL FETCH and MOVE
statements. Similar to SQL FETCH/MOVE statements, commands that would
seek the cursor backward will fail. In addition, expressions other than
constant integers are not yet supported for the `count` option.
  • Loading branch information
DrewKimball committed Oct 5, 2023
1 parent e2ac0b3 commit 20dcd51
Show file tree
Hide file tree
Showing 3 changed files with 1,051 additions and 0 deletions.
Loading

0 comments on commit 20dcd51

Please sign in to comment.