Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expression in fetch clause #19952

Open
lmatz opened this issue Dec 27, 2024 · 0 comments
Open

Support expression in fetch clause #19952

lmatz opened this issue Dec 27, 2024 · 0 comments
Labels
component/frontend Protocol, parsing, binder. difficulty/medium Issues that need some knowledge of the whole system good first issue Good for newcomers help wanted Issues that need help from contributors
Milestone

Comments

@lmatz
Copy link
Contributor

lmatz commented Dec 27, 2024

          Not as simple as it looks like. A parsing conflict can happen:

https://github.com/postgres/postgres/blob/REL_17_2/src/backend/parser/gram.y#L13233

* Allowing full expressions without parentheses causes various parsing
* problems with the trailing ROW/ROWS key words.  SQL spec only calls for
* <simple value specification>, which is either a literal or a parameter (but
* an <SQL parameter reference> could be an identifier, bringing up conflicts
* with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
* to determine whether the expression is missing rather than trying to make it
* optional in this rule.

* c_expr covers almost all the spec-required cases (and more), but it doesn't
* cover signed numeric literals, which are allowed by the spec. So we include
* those here explicitly. We need FCONST as well as ICONST because values that
* don't fit in the platform's "long", but do fit in bigint, should still be
* accepted here. (This is possible in 64-bit Windows as well as all 32-bit
* builds.)

For example,

select 1 offset 1 row fetch first row only;
                                  ^

This is valid in PostgreSQL. When we see this row keyword, it should be part of the fetch first [n] row syntax where n is omitted, but it may be mistakenly treated as part of the row(field0, field1) expression because we will attempt to parse an expression (instead of a numerical constant) after first.

What is the actual parsing behavior when this commit sees this SQL?

Originally posted by @xiangjinwu in #19834 (comment)

@github-actions github-actions bot added this to the release-2.3 milestone Dec 27, 2024
@lmatz lmatz added help wanted Issues that need help from contributors component/frontend Protocol, parsing, binder. difficulty/medium Issues that need some knowledge of the whole system good first issue Good for newcomers labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/frontend Protocol, parsing, binder. difficulty/medium Issues that need some knowledge of the whole system good first issue Good for newcomers help wanted Issues that need help from contributors
Projects
None yet
Development

No branches or pull requests

1 participant