Expand description
SQL Abstract Syntax Tree (AST) types
Modules§
Structs§
- Alter
Type - An
ALTER TYPE
statement (Statement::AlterType
) - Alter
Type AddValue - See AlterTypeOperation::AddValue
- Alter
Type Rename - See AlterTypeOperation::Rename
- Alter
Type Rename Value - See AlterTypeOperation::RenameValue
- Array
- Represents an Array Expression, either
ARRAY[..]
, or[..]
- Assignment
- SQL assignment
foo = expr
as used in SQLUpdate - Begin
EndStatements - Represents a list of statements enclosed within
BEGIN
andEND
keywords. Example: - Case
Statement - A
CASE
statement. - Case
When - A WHEN clause in a CASE expression containing both the condition and its corresponding result
- Clustered
By - Hive supports
CLUSTERED BY
statement inCREATE TABLE
. Syntax:CLUSTERED BY (col_name, ...) [SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS
- Clustered
Index - Column
Def - SQL column definition
- Column
Option Def - An optionally-named
ColumnOption
:[ CONSTRAINT <name> ] <column-option>
. - Column
Policy Property - Conditional
Statement Block - A block within a Statement::Case or Statement::If-like statement
- Connect
By - Joins a table to itself to process hierarchical data in the table.
- Constraint
Characteristics <constraint_characteristics> = [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ENFORCED | NOT ENFORCED ]
- Create
Connector - Create
Function - Create
Index - CREATE INDEX statement.
- Create
Table - CREATE TABLE statement.
- Create
View Params - MySQL
CREATE VIEW
additional parameters - Cte
- A single CTE (used after
WITH
):<alias> [(col1, col2, ...)] AS <materialized> ( <query> )
The names in the column list beforeAS
, when specified, replace the names of the columns returned by the query. The parser does not validate that the number of columns in the query matches the number of columns in the query. - Declare
- A
DECLARE
statement. PostgreSQL Snowflake BigQuery - Delete
- DELETE statement.
- Dictionary
Field - A dictionary field within a dictionary.
- Display
Separated - DoUpdate
- Dollar
Quoted String - Except
Select Item - Bigquery
EXCEPT
information, with at least one column. - Expr
With Alias - An expression optionally followed by an alias.
- Fetch
- Function
- A function call
- Function
Argument List - This represents everything inside the parentheses when calling a function.
- Function
Desc - Generic function description for DROP FUNCTION and CREATE TRIGGER.
- Grantee
- The principal that receives the privileges
- Having
Bound - The
HAVING
clause in a call toANY_VALUE
on BigQuery. - Hive
Format - Hive
Load Data Format - Hive
RowDelimiter - Hive
SetLocation - Ident
- An identifier, decomposed into its value or character data and the quote style.
- Ident
With Alias - Single aliased identifier
- Identity
Parameters - Identity
Property - IfStatement
- An
IF
statement. - Ilike
Select Item - Snowflake
ILIKE
information. - Index
Column - Index column type.
- Input
Format Clause - FORMAT identifier in input context, specific to ClickHouse.
- Insert
- INSERT statement.
- Insert
Aliases - Interpolate
- Interpolate
Expr - ClickHouse
INTERPOLATE
clause for use inORDER BY
clause when usingWITH FILL
modifier. Supported by ClickHouse syntax - Interval
- Represents an INTERVAL expression, roughly in the following format:
INTERVAL '<value>' [ <leading_field> [ (<leading_precision>) ] ] [ TO <last_field> [ (<fractional_seconds_precision>) ] ]
, e.g.INTERVAL '123:45.67' MINUTE(3) TO SECOND(2)
. - Join
- Json
Path - A JSON path.
- Json
Table Named Column - A single column definition in MySQL’s
JSON_TABLE
table valued function. - Json
Table Nested Column - A nested column in a JSON_TABLE column list
- Lambda
Function - A lambda function.
- Lateral
View - A hive LATERAL VIEW with potential column aliases
- Lock
Clause - Lock
Table - Macro
Arg NAME = <EXPR>
arguments for DuckDB macros- Map
- Represents a Map expression.
- MapEntry
- A map field within a map.
- Measure
- An item in the
MEASURES
subclause of aMATCH_RECOGNIZE
operation. - Merge
Clause - A when clause within a
MERGE
Statement - Merge
Insert Expr - The expression used to insert rows within a
MERGE
statement. - Method
- A method call
- Named
Window Definition - Object
Name - A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
- Offset
- OnConflict
- OneOr
Many With Parens Into Iter - Owned iterator implementation of
OneOrManyWithParens
- Open
Json Table Column - A single column definition in MSSQL’s
OPENJSON WITH
clause. - Operate
Function Arg - Function argument in CREATE OR DROP FUNCTION.
- OrderBy
- Order
ByExpr - An
ORDER BY
expression - Order
ByOptions - Output
Clause - A Output Clause in the end of a ‘MERGE’ Statement
- Print
Statement - Procedure
Param - Projection
Select - Query syntax for ClickHouse ADD PROJECTION statement.
Its syntax is similar to SELECT statement, but it is used to add a new projection to a table.
Syntax is
SELECT <COLUMN LIST EXPR> [GROUP BY] [ORDER BY]
- Query
- The most complete variant of a
SELECT
query expression, optionally includingWITH
,UNION
/ other set operations, andORDER BY
. - Raise
Statement - A
RAISE
statement. - Rename
Table - rename object definition
- Replace
Select Element - Syntax
- Replace
Select Item - Bigquery
REPLACE
information. - Return
Statement - Represents a
Return
statement. - RowAccess
Policy - Snowflake
WITH ROW ACCESS POLICY policy_name ON (identifier, ...)
- Secret
Option - Select
- A restricted variant of
SELECT
(without CTEs/ORDER BY
), which may appear either as the only body item of aQuery
, or as an operand to a set operation likeUNION
. - Select
Into - SetAssignment
- Assignment for a
SET
statement (name [=|TO] value) - SetSession
Param Generic - SetSession
Param Identity Insert - SetSession
Param Offsets - SetSession
Param Statistics - Setting
- Show
Objects - Show
Statement In - Show
Statement Options - Represents the different options available for
SHOW
statements to filter the results. Example from Snowflake: https://docs.snowflake.com/en/sql-reference/sql/show-tables - Struct
Field - A field definition within a struct
- Symbol
Definition - A symbol defined in a
MATCH_RECOGNIZE
operation. - Table
- A
TABLE
command - Table
Alias - Table
Alias Column Def - SQL column definition in a table expression alias. Most of the time, the data type is not specified. But some table-valued functions do require specifying the data type.
- Table
Engine - Engine of DB. Some warehouse has parameters of engine, e.g. ClickHouse
- Table
Function Args - Arguments to a table-valued function
- Table
Index Hints - Table
Sample - Table
Sample Bucket - Table
Sample Quantity - Table
Sample Seed - Table
With Joins - Tag
- Snowflake
WITH TAG ( tag_name = '<tag_value>', ...)
- Tags
Column Option - Tags option of column Syntax
- Top
- Trigger
Exec Body - This keyword immediately precedes the declaration of one or two relation names that provide access to the transition relations of the triggering statement
- Trigger
Referencing - This keyword immediately precedes the declaration of one or two relation names that provide access to the transition relations of the triggering statement
- Truncate
Table Target - Target of a
TRUNCATE TABLE
command - Union
Field - A field definition within a union
- User
Defined Type Composite Attribute Def - SQL user defined type attribute definition
- Utility
Option - Represents a single PostgreSQL utility option.
- Value
With Span - Wraps a primitive SQL
Value
with itsSpan
location - Values
- View
Column Def - Column definition specified in a
CREATE VIEW
statement. - Wildcard
Additional Options - Additional options for wildcards, e.g. Snowflake
EXCLUDE
/RENAME
and BigqueryEXCEPT
. - Window
Frame - Specifies the data processed by a window function, e.g.
RANGE UNBOUNDED PRECEDING
orROWS BETWEEN 5 PRECEDING AND CURRENT ROW
. - Window
Spec - A window specification (i.e.
OVER ([window_name] PARTITION BY .. ORDER BY .. etc.)
) - With
- With
Fill - ClickHouse
WITH FILL
modifier forORDER BY
clause. Supported by ClickHouse syntax - XmlNamespace
Definition - Represents a single XML namespace definition in the XMLNAMESPACES clause.
- XmlPassing
Argument - Argument passed in the XMLTABLE PASSING clause
- XmlPassing
Clause - The PASSING clause for XMLTABLE
- XmlTable
Column - A single column definition in XMLTABLE
Enums§
- Access
Expr - An element of a
Expr::CompoundFieldAccess
. It can be an expression or a subscript. - Action
- A privilege on a database object (table, sequence, etc.).
- Action
Apply Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theAPPLY
privilege. - Action
Create Object Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theCREATE
privilege. - Action
Execute Object Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theEXECUTE
privilege. - Action
Manage Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theMANAGE
privilege. - Action
Modify Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theMODIFY
privilege. - Action
Monitor Type - See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege
under
globalPrivileges
in theMONITOR
privilege. - AddDrop
Sync - After
Match Skip - The after match skip option in a
MATCH_RECOGNIZE
operation. - Alter
Column Operation - An
ALTER COLUMN
(Statement::AlterTable
) operation - Alter
Connector Owner - Alter
Index Operation - Alter
Policy Operation - An
ALTER Policy
(Statement::AlterPolicy
) operation - Alter
Role Operation - An
ALTER ROLE
(Statement::AlterRole
) operation - Alter
Table Algorithm - MySQL
ALTER TABLE
algorithm. - Alter
Table Lock - MySQL
ALTER TABLE
lock. - Alter
Table Operation - An
ALTER TABLE
(Statement::AlterTable
) operation - Alter
Type AddValue Position - See AlterTypeAddValue
- Alter
Type Operation - An AlterType operation
- Analyze
Format - ArgMode
- The mode of an argument in CREATE FUNCTION.
- Array
Elem Type Def - Represents the data type of the elements in an array (if any) as well as the syntax used to declare the array.
- Assignment
Target - Left-hand side of an assignment in an UPDATE statement,
e.g.
foo
infoo = 5
(ColumnName assignment) or(a, b)
in(a, b) = (1, 2)
(Tuple assignment). - Attach
DuckDB Database Option - Begin
Transaction Kind - Transaction started with [ TRANSACTION | WORK ]
- Binary
Length - Binary
Operator - Binary operators
- Cascade
Option - Cascade/restrict option for Postgres TRUNCATE table, MySQL GRANT/REVOKE, etc. [ CASCADE | RESTRICT ]
- Cast
Format - Options for
CAST
/TRY_CAST
BigQuery: https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#formatting_syntax - Cast
Kind - The syntax used for in a cast expression.
- Ceil
Floor Kind - The syntax used in a CEIL or FLOOR expression.
- Char
Length Units - Possible units for characters, initially based on 2016 ANSI SQL Standard.
- Character
Length - Information about character length, including length and possibly unit.
- Close
Cursor - Column
Option ColumnOption
s are modifiers that follow a column definition in aCREATE TABLE
statement.- Column
Policy - Column policy that identify a security policy of access to a column. Syntax
- Comment
Def - Helper to indicate if a comment includes the
=
in the display form - Comment
Object - Conditional
Statements - A list of statements in a ConditionalStatementBlock.
- Conflict
Target - Context
Modifier - Optional context modifier for statements that can be or
LOCAL
,GLOBAL
, orSESSION
. - Copy
Into Snowflake Kind - Variants of the Snowflake
COPY INTO
statement - Copy
Legacy CsvOption - A
CSV
option inCOPY
statement before PostgreSQL version 9.0. - Copy
Legacy Option - An option in
COPY
statement before PostgreSQL version 9.0. - Copy
Option - An option in
COPY
statement. - Copy
Source - Copy
Target - Create
Function Body - Represent the expression body of a
CREATE FUNCTION
statement as well as where within the statement, the body shows up. - Create
Function Using - Create
Policy Command - Policy command for a
CREATE POLICY
statement. - Create
Policy Type - Policy type for a
CREATE POLICY
statement. - Create
Table Options - Sql options of a
CREATE TABLE
statement. - Create
View Algorithm - MySQL
CREATE VIEW
algorithm parameter: [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] - Create
View Security - MySQL
CREATE VIEW
security parameter: [SQL SECURITY { DEFINER | INVOKER }] - CteAs
Materialized - Data
Type - SQL data types
- Date
Time Field - Declare
Assignment - Represents an expression assignment within a variable
DECLARE
statement. - Declare
Type - Represents the type of a
DECLARE
statement. - Deduplicate
- DEDUPLICATE statement used in OPTIMIZE TABLE et al. such as in ClickHouse SQL ClickHouse
- Deferrable
Initial - Describe
Alias - Discard
Object - Distinct
- Drop
Behavior <drop behavior> ::= CASCADE | RESTRICT
.- Drop
Function Option - Function describe in DROP FUNCTION.
- Duplicate
Treatment - Empty
Matches Mode - Enum
Member - Exact
Number Info - Additional information for
NUMERIC
,DECIMAL
, andDEC
data types following the 2016 SQL Standard. - Exclude
Select Item - Snowflake
EXCLUDE
information. - Expr
- An SQL expression of any type.
- Extract
Syntax EXTRACT
syntax variants.- Fetch
Direction - Specific direction for FETCH statement
- File
Format - External table’s available file format
- Flush
Location - Flush
Type - ForClause
- FOR XML or FOR JSON clause, specific to MSSQL (formats the output of a query as XML or JSON)
- ForJson
- ForXml
- Format
Clause - FORMAT identifier or FORMAT NULL clause, specific to ClickHouse.
- From
Table - A
FROM
clause within aDELETE
statement. - Function
Arg - Function
ArgExpr - Function
ArgOperator - Operator used to separate function arguments
- Function
Argument Clause - Function
Arguments - The arguments passed to a function call.
- Function
Behavior - These attributes inform the query optimizer about the behavior of the function.
- Function
Called OnNull - These attributes describe the behavior of the function when called with a null argument.
- Function
Determinism Specifier - BigQuery Determinism specifier used in a UDF definition.
- Function
Parallel - If it is safe for PostgreSQL to call the function from multiple threads at once
- Generated
As GeneratedAs
s are modifiers that follow a column option in agenerated
. ‘ExpStored’ is used for a column generated from an expression and stored.- Generated
Expression Mode GeneratedExpressionMode
s are modifiers that follow an expression in agenerated
. No modifier is typically the same as Virtual.- Geometric
Type Kind - Represents different types of geometric shapes which are commonly used in PostgreSQL/Redshift for spatial operations and geometry-related computations.
- Grant
Objects - Objects on which privileges are granted in a GRANT statement.
- Grantee
Name - Users/roles designated in a GRANT/REVOKE
- Grantees
Type - Group
ByExpr - Group
ByWith Modifier - ClickHouse supports GROUP BY WITH modifiers(includes ROLLUP|CUBE|TOTALS). e.g. GROUP BY year WITH ROLLUP WITH TOTALS
- Having
Bound Kind - Hive
Delimiter - Hive
Describe Format - Hive
Distribution Style - HiveIO
Format - Hive
RowFormat - Identity
Property Format Kind - A format of parameters of identity column.
- Identity
Property Kind - Identity is a column option for defining an identity or autoincrement column in a
CREATE TABLE
statement. Syntax - Identity
Property Order - The identity column option specifies how values are generated for the auto-incremented column, either in increasing or decreasing order. Syntax
- Index
Option - MySQLs index option.
- Index
Type - Indexing method used by that index.
- Join
Constraint - Join
Operator - Json
Null Clause - MSSQL’s json null clause
- Json
Path Elem - An element of a JSON path.
- Json
Table Column - A single column definition in MySQL’s
JSON_TABLE
table valued function. - Json
Table Column Error Handling - Stores the error handling clause of a
JSON_TABLE
table valued function: {NULL | DEFAULT json_string | ERROR} ON {ERROR | EMPTY } - KeyOr
Index Display - Representation whether a definition can can contains the KEY or INDEX keywords with the same meaning.
- Kill
Type - Limit
Clause - List
AggOn Overflow - The
ON OVERFLOW
clause of a LISTAGG invocation - Lock
Table Type - Lock
Type - Macro
Definition - Match
Recognize Pattern - The pattern in a
MATCH_RECOGNIZE
operation. - Match
Recognize Symbol - A symbol in a
MATCH_RECOGNIZE
pattern. - Merge
Action - Underlying statement of a when clause within a
MERGE
Statement - Merge
Clause Kind - Variant of
WHEN
clause used within aMERGE
Statement. - Merge
Insert Kind - The type of expression used to insert rows within a
MERGE
statement. - MinMax
Value - Can use to describe options in create sequence or table column type identity [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
- MySQL
Column Position - MySQL
ALTER TABLE
only [FIRST | AFTER column_name] - Mysql
Insert Priority - Mysql specific syntax
- Named
Window Expr - An expression used in a named window declaration.
- NonBlock
- Normalization
Form - The Unicode Standard defines four normalization forms, which are intended to eliminate certain distinctions between visually or functionally identical characters.
- Null
Treatment - Specifies Ignore / Respect NULL within window functions.
For example
FIRST_VALUE(column2) IGNORE NULLS OVER (PARTITION BY column1)
- Nulls
Distinct Option - PostgreSQL unique index nulls handling option:
[ NULLS [ NOT ] DISTINCT ]
- Object
Name Part - A single part of an ObjectName
- Object
Type - Offset
Rows - Stores the keyword after
OFFSET <number>
- OnCommit
- OnConflict
Action - OnInsert
- OneOr
Many With Parens - Encapsulates the common pattern in SQL where either one unparenthesized item
such as an identifier or expression is permitted, or multiple of the same
item in a parenthesized list. For accessing items regardless of the form,
OneOrManyWithParens
implementsDeref<Target = [T]>
andIntoIterator
, so you can call slice methods on it and iterate over items - Order
ByKind - Owner
- Partition
- PARTITION statement used in ALTER TABLE et al. such as in Hive and ClickHouse SQL. For example, ClickHouse’s OPTIMIZE TABLE supports syntax like PARTITION ID ‘partition_id’ and PARTITION expr. ClickHouse
- Partition
Range Direction - Specifies which partition the boundary values on table partitioning belongs to.
- Password
- Pivot
Value Source - The source of values in a
PIVOT
operation. - Privileges
- Privileges granted in a GRANT statement or revoked in a REVOKE statement.
- Rais
Error Option - Raise
Statement Value - Represents the error value of a RaiseStatement.
- Referential
Action <referential_action> = { RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT }
- Rename
Select Item - Snowflake
RENAME
information. - Repetition
Quantifier - Determines the minimum and maximum allowed occurrences of a pattern in a
MATCH_RECOGNIZE
operation. - Reset
Config - RESET config option:
- Return
Statement Value - Variants of a
RETURN
statement - Role
Option - An option in
ROLE
statement. - Rows
PerMatch - The rows per match option in a
MATCH_RECOGNIZE
operation. - Schema
Name - Schema possible naming variants (1).
- Search
Modifier - Fulltext search modifiers (1).
- Secondary
Roles - Snowflake
SECONDARY ROLES
USE variant See: https://docs.snowflake.com/en/sql-reference/sql/use-secondary-roles - Select
Flavor - What did this select look like?
- Select
Item - One item of the comma-separated list following
SELECT
- Select
Item Qualified Wildcard Kind - Represents an expression behind a wildcard expansion in a projection. `SELECT T.* FROM T;
- Sequence
Options - Can use to describe options in create sequence or table column type identity
- Session
Param Stats Topic - Session
Param Value - Set
- SetConfig
Value - SET config value option:
- SetExpr
- A node in a tree, representing a “query body” expression, roughly:
SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]
- SetOperator
- SetQuantifier
- A quantifier for SetOperator.
- SetSession
Param Kind - Show
Create Object - Show
Statement Filter - Show
Statement Filter Position - Show
Statement InClause - Show
Statement InParent Type - SqlOption
- Sqlite
OnConflict - Sqlite specific syntax
- Statement
- A top-level statement (SELECT, INSERT, CREATE, etc.)
- Storage
Serialization Policy - Snowflake StorageSerializationPolicy for Iceberg Tables
- Struct
Bracket Kind - Type of brackets used for
STRUCT
literals. - Subscript
- The contents inside the
[
and]
in a subscript expression. - Table
Constraint - A table-level constraint, specified in a
CREATE TABLE
or anALTER TABLE ADD <constraint>
statement. - Table
Factor - A table name or a parenthesized subquery with an optional alias
- Table
Index Hint ForClause - Table
Index Hint Type - Table
Index Type - Table
Object - Represents the referenced table in an
INSERT INTO
statement - Table
Options Clustered - Table
Sample Kind - The table sample modifier options
- Table
Sample Method - The table sample method names
- Table
Sample Modifier - Table
Sample Seed Modifier - Table
Sample Unit - Table
Version - Timezone
Info - Timestamp and Time data types information about TimeZone formatting.
- TopQuantity
- Transaction
Access Mode - Transaction
Isolation Level - Transaction
Mode - Transaction
Modifier - Modifier for the transaction in the
BEGIN
syntax - Trigger
Event - Used to describe trigger events
- Trigger
Exec Body Type - Types of trigger body execution body.
- Trigger
Object - This specifies whether the trigger function should be fired once for every row affected by the trigger event, or just once per SQL statement.
- Trigger
Period - Trigger period
- Trigger
Referencing Type - This clause indicates whether the following relation name is for the before-image transition relation or the after-image transition relation
- Trim
Where Field - Truncate
Identity Option - PostgreSQL identity option for TRUNCATE table [ RESTART IDENTITY | CONTINUE IDENTITY ]
- Unary
Operator - Unary operators
- Update
Table From Kind - The
FROM
clause of anUPDATE TABLE
statement - Use
- A
USE
(Statement::Use
) operation - User
Defined Type Representation - SQL user defined type definition
- Value
- Primitive SQL values such as number and string
- Value
Table Mode - BigQuery supports ValueTables which have 2 modes:
SELECT AS STRUCT
SELECT AS VALUE
https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#value_tables - Window
Frame Bound - Specifies WindowFrame’s
start_bound
andend_bound
- Window
Frame Units - Window
Type - Wrapped
Collection - Helper to indicate if a collection should be wrapped by a symbol in the display form
- XmlTable
Column Option - Defines the options for an XmlTable column: Named or ForOrdinality
Traits§
- Spanned
- Trait for AST nodes that have a source location information.
- Visit
- A type that can be visited by a
Visitor
. SeeVisitor
for recursively visiting parsed SQL statements. - Visit
Mut - A type that can be visited by a
VisitorMut
. SeeVisitorMut
for recursively visiting parsed SQL statements. - Visitor
- A visitor that can be used to walk an AST tree.
- Visitor
Mut - A visitor that can be used to mutate an AST tree.
Functions§
- display_
comma_ separated - display_
separated - escape_
double_ quote_ string - escape_
quoted_ string - visit_
expressions - Invokes the provided closure on all expressions (e.g.
1 + 2
) present inv
- visit_
expressions_ mut - Invokes the provided closure iteratively with a mutable reference to all expressions
present in
v
. - visit_
relations - Invokes the provided closure on all relations (e.g. table names) present in
v
- visit_
relations_ mut - Invokes the provided closure with a mutable reference to all relations (e.g. table names)
present in
v
. - visit_
statements - Invokes the provided closure iteratively with a mutable reference to all statements
present in
v
(e.g.SELECT
,CREATE TABLE
, etc). - visit_
statements_ mut - Invokes the provided closure on all statements (e.g.
SELECT
,CREATE TABLE
, etc) present inv