Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sVxGV-00CUkx-Mm for pgsql-docs@arkaria.postgresql.org; Mon, 22 Jul 2024 17:56:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sVxGT-005Em4-SJ for pgsql-docs@arkaria.postgresql.org; Mon, 22 Jul 2024 17:56:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sVxAZ-00556w-99 for pgsql-docs@lists.postgresql.org; Mon, 22 Jul 2024 17:49:55 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sVxAX-000vG2-6D for pgsql-docs@lists.postgresql.org; Mon, 22 Jul 2024 17:49:55 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4266dc7591fso33329225e9.0 for ; Mon, 22 Jul 2024 10:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721670592; x=1722275392; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bVNN5WKFfMQCuMf9Q3foYI4ibjOJi5A5QBmD1Zln+K0=; b=Z48k+QxgHj2yGP0J3Bq5hnSul+yBeitrduenz30nm4AxLelNRqQkGeMAllMHaE6eGU NlajhXYGVYK4gFzvm4IHu/IbX75n0Z1+VFx58MJTu8OruT64eyler8itzz3dgFN4oxll ZP4jwUiSlM1M7aHaU+QEqsxdOtEUamjPUdfWDddKeFimMFl6DExnbQ4leZmYCkbI8wCR LFUc/X9TaKxGE+rRXQ3IRACx/RidKgbqJQU9MUNJQBhm9rmump82Ri7L/2nPkaMSboSp dUZr9Q1S9555ONxkk2FC46K992GmWD6IUnQP8wqm+NPk2Ib+uhuKcKOcdDIWsuNKBqwf uA+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721670592; x=1722275392; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bVNN5WKFfMQCuMf9Q3foYI4ibjOJi5A5QBmD1Zln+K0=; b=GF1+T62hfFm+aHXs+xc3IWF91UnJp2ryCDBMtM9cInVZ/wrTCAcrpbU3L808o6S9ZO PMuqAJZZHTiK0pwplwvObAfxjGeyNuUxPCMXWzq5pgxq5IqDCmC3+Q5s+1K+ei20L8gk 2JFKuih5dlq4t9EV40G4g7rb22U2XKZFucAdGDHptPEc8g8eU/xPbjKPl/CesC/RAzBr NeCAO5Cb1j1D5Jc+f1KXypbpXmdsdg0H1RiXAhJDx1pRLkcPgF8+Vivo6H2kn1w9zdNg E7BzMwYamwGlv04+c/L/B0OlAopx2Hc77cExQTU4UKevJRhtZA603A4yexCOdI5xrxJp lzuA== X-Gm-Message-State: AOJu0YyLYn0YMGUzePii3J1xMU2plPKVMEiHbirqINBxeNFyrvTH90ue rNtX1hKuabiBdOjTMiGt3x2iLD2yK09C3+qSplrllKdTnFWA+ao4RpjYvw== X-Google-Smtp-Source: AGHT+IFV4Ho+YU5qU+4zKfmqXXCX8TKBJ3lyOE/83TZYGAgKsbv0D8xJflt7QXHrT6m0N4wPaVxo7w== X-Received: by 2002:a5d:6489:0:b0:368:4e38:a349 with SMTP id ffacd0b85a97d-369dec0ae25mr411731f8f.22.1721670591906; Mon, 22 Jul 2024 10:49:51 -0700 (PDT) Received: from smtpclient.apple ([2a02:121f:3ed6:0:e012:268b:d0c9:55bc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36878694a58sm9192041f8f.58.2024.07.22.10.49.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jul 2024 10:49:51 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: Undocumented count in FORWARD/BACKWARD direction of MOVE statement From: Philipp Salvisberg In-Reply-To: <893915.1721665475@sss.pgh.pa.us> Date: Mon, 22 Jul 2024 19:49:40 +0200 Cc: pgsql-docs@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <172155553388.702.7932496598218792085@wrigleys.postgresql.org> <893915.1721665475@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3774.600.62) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 22 Jul 2024, at 18:24, Tom Lane wrote: >=20 > PG Doc comments form writes: >> The following documentation comment has been logged on the website: >> Page: https://www.postgresql.org/docs/16/plpgsql-cursors.html >> Description: >=20 >> The documentation shows this example for the MOVE statement: >=20 >> MOVE FORWARD 2 FROM curs4; >=20 >> According to the docs, this should not work. The count is documented = only >> for the directions ABSOLUTE and RELATIVE (which should be enough). = "FORWARD >> count" and "BACKWARD" count works in MOVE but not in FETCH. I don't = know if >> this is intentional. However, the docs do not seem to be correct for = MOVE >> directions. >=20 > Yeah, you're right. MOVE does not have the restriction about not > taking forms of "direction" that specify multiple rows. But the > docs just refer you to FETCH which does have that restriction, > so unless you read that as referring to SQL FETCH it's wrong. >=20 > I also notice this comment in pl_gram.y: >=20 > /* > * Assume it's a count expression with no preceding keyword. > * Note: we allow this syntax because core SQL does, but we = don't > * document it because of the ambiguity with the = omitted-direction > * case. For instance, "MOVE n IN c" will fail if n is a = variable. > * Perhaps this can be improved someday, but it's hardly worth = a > * lot of work. > */ >=20 > It seems to me that it'd be better to surface that in the docs, > that is describe the case as deprecated. >=20 > So maybe something like >=20 > MOVE repositions a cursor without retrieving any data. > MOVE works like the FETCH command, except it only repositions the > cursor and does not return the row moved to. > The direction clause can be any of the variants allowed in the SQL > FETCH command, including those that would fetch more than one row; > the cursor is positioned to the last such row. > However, the case in which the direction clause is simply a count > expression without a keyword is deprecated. (It is ambiguous with > the case where the direction clause is omitted altogether, and > hence may fail if the count is not a constant.) > As with SELECT INTO, > the special variable FOUND can be checked to see whether there was > a row to move to. >=20 > regards, tom lane Yes, that's clearer. Especially referring to SQL FETCH instead of FETCH = helps. Therefore I would change FETCH to SQL FETCH also in your second = paragraph. I read FETCH in the current documentation as PL/pgSQL FETCH and = therefore checked the list of directions mentioned in the previous = chapter. Thanks, Philipp=