SQL Statement Nodes¶
SQL Statement nodes represent the top-level operations in SQL commands. Each statement type has its own dedicated AST node class that contains the specific components and clauses relevant to that operation.
Overview¶
Statement nodes are the root nodes of parsed SQL commands. They inherit from TSqlStatement
and provide methods to access their constituent parts like clauses, expressions, and table references.
Available Statement Types¶
Data Query Language (DQL)¶
- SELECT Statement -
TSelectSqlStatement
- Query data from tables
- Supports complex joins, subqueries, aggregations
- Most commonly used statement type
Data Manipulation Language (DML)¶
- INSERT Statement -
TInsertSqlStatement
- Insert new data into tables
-
Supports VALUES clauses and SELECT-based inserts
-
UPDATE Statement -
TUpdateSqlStatement
- Modify existing data in tables
-
Includes SET clauses and WHERE conditions
-
DELETE Statement -
TDeleteSqlStatement
- Remove data from tables
- Supports conditional deletion with WHERE clauses
Data Definition Language (DDL)¶
- CREATE Statement -
TCreateSqlStatement
- Create database objects (tables, views, indexes, etc.)
-
Database-specific variations supported
-
ALTER Statement -
TAlterSqlStatement
- Modify existing database objects
-
Add/drop columns, constraints, etc.
-
DROP Statement -
TDropSqlStatement
- Remove database objects
- Cascade options supported
Common Properties¶
All statement nodes share these characteristics:
Property | Description | Access Method |
---|---|---|
sqlstatementtype |
Type of SQL statement | getSqlStatementType() |
startToken |
First token in statement | getStartToken() |
endToken |
Last token in statement | getEndToken() |
sourceString |
Original SQL text | toString() |
Usage Patterns¶
Identifying Statement Types¶
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Extracting Tables from Any Statement¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Database-Specific Considerations¶
Some statements have database-specific variations:
- SQL Server:
MERGE
statements,OUTPUT
clauses - Oracle:
MERGE
statements, hierarchical queries withCONNECT BY
- PostgreSQL:
UPSERT
withON CONFLICT
- MySQL:
REPLACE
statements,ON DUPLICATE KEY UPDATE
See Also¶
- SQL Clauses - Components within statements
- Table References - How tables are referenced
- Expressions - Expressions within statements
- API Documentation - Method-level reference