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

parser: add QUERY to bare_label_keyword #97041

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,7 @@ bare_label_keywords ::=
| 'INVOKER'
| 'LEAKPROOF'
| 'PARALLEL'
| 'QUERY'
| 'RETURN'
| 'RETURNS'
| 'SECURITY'
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -15904,13 +15904,13 @@ unrestricted_name:
| reserved_keyword

// Keyword category lists. Generally, every keyword present in the Postgres
// grammar should appear in exactly one of these lists.
// grammar should appear in exactly one of these "x_keyword" lists.
//
// Put a new keyword into the first list that it can go into without causing
// shift or reduce conflicts. The earlier lists define "less reserved"
// categories of keywords.
//
// Note: also add the new keyword to `bare_label` list to not break
// Note: also add the **new** keyword to `bare_label_keywords` list to not break
// user queries using column label without `AS`.
// "Unreserved" keywords --- available for use as any kind of name.
unreserved_keyword:
Expand Down Expand Up @@ -16374,6 +16374,7 @@ bare_label_keywords:
| INVOKER
| LEAKPROOF
| PARALLEL
| QUERY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed offline, but could you adjust the comment a bit for bare_label_keywords and the other rules above and below? i think the information is a bit outdated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just chatted with @chengxiong-ruan and have it updated. Basically we still want a keyword to be only in one of those "_keyword" lists (note, bare_labeled_keywords is not one of them), but newly added keyword should always be added to bare_labeled_keywords as well.

| RETURN
| RETURNS
| SECURITY
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/parser/testdata/select_clauses
Original file line number Diff line number Diff line change
Expand Up @@ -3051,3 +3051,11 @@ SELECT * FROM ROWS FROM (json_to_record('')) AS t (a INT8, b STRING, c foo) -- n
SELECT (*) FROM ROWS FROM ((json_to_record(('')))) AS t (a INT8, b STRING, c foo) -- fully parenthesized
SELECT * FROM ROWS FROM (json_to_record('_')) AS t (a INT8, b STRING, c foo) -- literals removed
SELECT * FROM ROWS FROM (json_to_record('')) AS _ (_ INT8, _ STRING, _ foo) -- identifiers removed

parse
SELECT substring('stringstringstring',1,10) QUERY
----
SELECT substring('stringstringstring', 1, 10) AS query -- normalized!
SELECT (substring(('stringstringstring'), (1), (10))) AS query -- fully parenthesized
SELECT substring('_', _, _) AS query -- literals removed
SELECT substring('stringstringstring', 1, 10) AS _ -- identifiers removed