Skip to content

docs: add grammar rule of common table expressions.#201

Draft
ashigeru wants to merge 1 commit intomasterfrom
docs-compiler-cte
Draft

docs: add grammar rule of common table expressions.#201
ashigeru wants to merge 1 commit intomasterfrom
docs-compiler-cte

Conversation

@ashigeru
Copy link
Contributor

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:

  • Updated the syntax for queries to explicitly support common table expressions (CTEs) using the WITH clause and clarified the use of <declared-relation-name> in place of <table-name> in relevant grammar rules.
  • Added a new definition for <declared-relation-name> to indicate that it can be either a <table-name> or a <query-name>, and updated table reference syntax accordingly.

@ashigeru ashigeru requested a review from a team as a code owner January 30, 2026 06:36
@ashigeru ashigeru requested a review from akirakw January 30, 2026 06:36
@ashigeru ashigeru marked this pull request as draft January 30, 2026 06:36
@ashigeru ashigeru requested a review from Copilot January 30, 2026 06:37
@ashigeru ashigeru self-assigned this Jan 30, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant