Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74e1546

Browse files
committed
Doc: improve description of plpgsql's FETCH and MOVE commands.
We were not being clear about which variants of the "direction"clause are permitted in MOVE. Also, the text seemed to bewritten with only the FETCH/MOVE NEXT case in mind, so itdidn't apply very well to other variants.Also, document that "MOVE count IN cursor" only works if countis a constant. This is not the whole truth, because some othercases such as a parenthesized expression will also work, butwe want to push people to use "MOVE FORWARD count" instead.The constant case is enough to cover what we allow in plain SQL,and that seems sufficient to claim support for.Update a comment in pl_gram.y claiming that we don't documentthat point.Per gripe from Philipp Salvisberg.Discussion:https://postgr.es/m/172155553388.702.7932496598218792085@wrigleys.postgresql.org
1 parent13c58ca commit74e1546

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,13 +3384,16 @@ FETCH <optional> <replaceable>direction</replaceable> { FROM | IN } </optional>
33843384
</synopsis>
33853385

33863386
<para>
3387-
<command>FETCH</command> retrieves the next row from the
3387+
<command>FETCH</command> retrieves the next row (in the indicated
3388+
direction) from the
33883389
cursor into a target, which might be a row variable, a record
33893390
variable, or a comma-separated list of simple variables, just like
3390-
<command>SELECT INTO</command>. If there is nonext row, the
3391+
<command>SELECT INTO</command>. If there is nosuitable row, the
33913392
target is set to NULL(s). As with <command>SELECT
33923393
INTO</command>, the special variable <literal>FOUND</literal> can
3393-
be checked to see whether a row was obtained or not.
3394+
be checked to see whether a row was obtained or not. If no row is
3395+
obtained, the cursor is positioned after the last row or before the
3396+
first row, depending on the movement direction.
33943397
</para>
33953398

33963399
<para>
@@ -3442,11 +3445,25 @@ MOVE <optional> <replaceable>direction</replaceable> { FROM | IN } </optional> <
34423445

34433446
<para>
34443447
<command>MOVE</command> repositions a cursor without retrieving
3445-
any data. <command>MOVE</command> worksexactlylike the
3448+
any data. <command>MOVE</command> works like the
34463449
<command>FETCH</command> command, except it only repositions the
3447-
cursor and does not return the row moved to. As with <command>SELECT
3450+
cursor and does not return the row moved to.
3451+
The <replaceable>direction</replaceable> clause can be any of the
3452+
variants allowed in the SQL <xref linkend="sql-fetch"/>
3453+
command, including those that can fetch more than one row;
3454+
the cursor is positioned to the last such row.
3455+
(However, the case in which the <replaceable>direction</replaceable>
3456+
clause is simply a <replaceable>count</replaceable> expression with
3457+
no key word is deprecated in <application>PL/pgSQL</application>.
3458+
That syntax is ambiguous with the case where
3459+
the <replaceable>direction</replaceable> clause is omitted
3460+
altogether, and hence it may fail if
3461+
the <replaceable>count</replaceable> is not a constant.)
3462+
As with <command>SELECT
34483463
INTO</command>, the special variable <literal>FOUND</literal> can
3449-
be checked to see whether there was a next row to move to.
3464+
be checked to see whether there was a row to move to. If there is no
3465+
such row, the cursor is positioned after the last row or before the
3466+
first row, depending on the movement direction.
34503467
</para>
34513468

34523469
<para>

‎src/pl/plpgsql/src/pl_gram.y

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,11 +3194,11 @@ read_fetch_direction(void)
31943194
{
31953195
/*
31963196
* Assume it's a count expression with no preceding keyword.
3197-
* Note: we allow this syntax because core SQL does, butwe don't
3198-
*document it because oftheambiguity with the omitted-direction
3199-
*case. Forinstance, "MOVE n IN c" will fail if n is a variable.
3200-
*Perhaps this can be improved someday, but it's hardly worth a
3201-
* lot of work.
3197+
* Note: we allow this syntax because core SQL does, butit's
3198+
*ambiguous withthecase of an omitteddirection clause; for
3199+
* instance, "MOVE n IN c" will fail if n is a variable, because the
3200+
*preceding else-arm will trigger. Perhaps this can be improved
3201+
*someday, but it hardly seems worth alot of work.
32023202
*/
32033203
plpgsql_push_back_token(tok);
32043204
fetch->expr = read_sql_expression2(K_FROM, K_IN,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp