SQL Clause Nodes¶
SQL Clause nodes represent the components that appear within SQL statements. Each clause type encapsulates specific functionality like filtering, joining, grouping, or ordering data.
Overview¶
Clause nodes are building blocks of SQL statements. They inherit from base node classes and contain the expressions, conditions, and specifications needed for their particular function.
Available Clause Types¶
Data Filtering and Selection¶
- WHERE Clause -
TWhereClause
- Filter rows based on conditions
- Contains boolean expressions
-
Used in SELECT, UPDATE, DELETE statements
-
HAVING Clause -
THavingClause
- Filter grouped results
- Applied after GROUP BY
- Similar structure to WHERE clause
Data Sources and Relationships¶
- FROM Clause -
TFromClause
- Specify data sources
- Contains table references and joins
-
Foundation for data retrieval
-
JOIN Clause -
TJoin
- Combine data from multiple tables
- Various join types (INNER, LEFT, RIGHT, FULL)
- Contains join conditions
Data Organization¶
- GROUP BY Clause -
TGroupByClause
- Group rows for aggregation
- Contains grouping expressions
-
Enables aggregate functions
-
ORDER BY Clause -
TOrderByClause
- Sort result sets
- Contains sort specifications
- Supports multiple sort criteria
Database-Specific Clauses¶
- LIMIT Clause -
TLimitClause
- Limit number of returned rows
- PostgreSQL, MySQL syntax
-
Pagination support
-
TOP Clause -
TTopClause
- Limit number of returned rows
- SQL Server syntax
- Percentage options available
Common Properties¶
Most clause nodes share these characteristics:
Property | Description | Access Method |
---|---|---|
startToken |
First token in clause | getStartToken() |
endToken |
Last token in clause | getEndToken() |
sourceString |
Original SQL text | toString() |
Usage Patterns¶
Checking for Clause Presence¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Extracting All Clause Conditions¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Database-Specific Considerations¶
SQL Server¶
TOP
clause for row limitingOUTPUT
clause for modified dataWITH
clause for table hints
PostgreSQL¶
LIMIT
andOFFSET
for paginationRETURNING
clause for modified data- Advanced window function clauses
Oracle¶
ROWNUM
in WHERE clausesCONNECT BY
for hierarchical queriesMODEL
clause for spreadsheet-like calculations
MySQL¶
LIMIT
with optionalOFFSET
ON DUPLICATE KEY UPDATE
clause- Storage engine specific hints
See Also¶
- SQL Statements - Containing statements
- Expressions - Expressions within clauses
- Table References - Table references in FROM/JOIN
- API Documentation - Method-level reference