docs: add grammar rule of common table expressions.#201
docs: add grammar rule of common table expressions.#201
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds Common Table Expression (CTE) support to the SQL grammar documentation. It introduces the WITH clause syntax and clarifies how CTEs can be used as relation names in queries through a new <declared-relation-name> production rule.
Changes:
- Added WITH clause syntax for defining CTEs in query expressions
- Introduced
<declared-relation-name>as a new grammar production that encompasses both table names and query names from CTEs - Updated table references to use
<declared-relation-name>instead of<table-name>to allow referencing CTEs
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [ORDER BY <order-by-element> [, ...]] | ||
| [LIMIT <integer>] | ||
| TABLE <table-name> | ||
| WITH <query-name> AS ( <query-expression> ) [, ...] <query-expression> |
There was a problem hiding this comment.
The placement of the WITH clause in the grammar creates ambiguity. In SQL standards, WITH is a prefix modifier to a query expression, not an alternative production at the same level as SELECT. The current syntax suggests it's both a complete query-expression alternative and a prefix (WITH ... ).
Consider restructuring to make it clear that WITH is a prefix, perhaps by having a separate non-terminal like <with-clause> or by placing this at the beginning of the alternatives list with clearer indentation to show it wraps the following query-expression.
This pull request updates the SQL syntax documentation to clarify the use of declared relation names and common table expressions (CTEs). The main focus is on making the distinction between table names, query names, and declared relation names more explicit in the grammar.
SQL grammar and documentation improvements:
WITHclause and clarified the use of<declared-relation-name>in place of<table-name>in relevant grammar rules.<declared-relation-name>to indicate that it can be either a<table-name>or a<query-name>, and updated table reference syntax accordingly.