Обсуждение: Ambiguity in VALUES synopsis: LIMIT vs FETCH

Поиск
Список
Период
Сортировка

Ambiguity in VALUES synopsis: LIMIT vs FETCH

От
Cheng Ding
Дата:

Hello docs team,

I believe there’s an ambiguity in the VALUES command synopsis that can mislead readers into thinking LIMIT and FETCH can be used together.

What I ran

VALUES (12, 'nectarine') LIMIT 1 FETCH FIRST 1 ROW ONLY;

What happened

ERROR: syntax error at or near "FETCH"

Why I think the docs are ambiguous

The current synopsis for VALUES shows:

VALUES ( expression [, ...] ) [, ...] [ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]

As written, this looks like LIMIT … and FETCH … are independent optional clauses that could both appear. In practice (and in the underlying grammar), FETCH is the SQL-standard alternative to LIMIT; they are mutually exclusive.

Suggested fix (one option)

Adjust the synopsis to make the alternation explicit, for example:

[ { LIMIT { count | ALL } [ OFFSET start [ ROW | ROWS ] ] | [ OFFSET start [ ROW | ROWS ] ] FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY } ]

Alternatively, add a short note right under the synopsis:

Note: FETCH { FIRST | NEXT } … ONLY is an alternative to LIMIT and cannot be used together with it.

EnvironmentPostgreSQL v17.6

Best regards,
Cheng Ding
The University of Texas at Austin


Re: Ambiguity in VALUES synopsis: LIMIT vs FETCH

От
"David G. Johnston"
Дата:
On Tuesday, August 26, 2025, Cheng Ding <cheng.ding@utexas.edu> wrote:

Hello docs team,

I believe there’s an ambiguity in the VALUES command synopsis that can mislead readers into thinking LIMIT and FETCH can be used together.

Alternatively, add a short note right under the synopsis:

Note: FETCH { FIRST | NEXT } … ONLY is an alternative to LIMIT and cannot be used together with it.

The final paragraph in description explains the either-or nature of limit/fetch.  It also directs the user to the Select page for more details.  And the comparability section also explains that fetch is standard while limit is PostgresSQL-specific.

IMO the choice of representation here is acceptable.  The redundancy should be a big tell even if you don’t read the docs carefully.  And hopefully whatever source you actually learn about the feature from covers the material well and this quick reference page is just a reminder that both exist.

David J.