Module ast

Source
Expand description

SQL Abstract Syntax Tree (AST) types

Modules§

helpers

Structs§

AlterType
An ALTER TYPE statement (Statement::AlterType)
AlterTypeAddValue
See AlterTypeOperation::AddValue
AlterTypeRename
See AlterTypeOperation::Rename
AlterTypeRenameValue
See AlterTypeOperation::RenameValue
Array
Represents an Array Expression, either ARRAY[..], or [..]
Assignment
SQL assignment foo = expr as used in SQLUpdate
BeginEndStatements
Represents a list of statements enclosed within BEGIN and END keywords. Example:
CaseStatement
A CASE statement.
CaseWhen
A WHEN clause in a CASE expression containing both the condition and its corresponding result
ClusteredBy
Hive supports CLUSTERED BY statement in CREATE TABLE. Syntax: CLUSTERED BY (col_name, ...) [SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS
ClusteredIndex
ColumnDef
SQL column definition
ColumnOptionDef
An optionally-named ColumnOption: [ CONSTRAINT <name> ] <column-option>.
ColumnPolicyProperty
ConditionalStatementBlock
A block within a Statement::Case or Statement::If-like statement
ConnectBy
Joins a table to itself to process hierarchical data in the table.
ConstraintCharacteristics
<constraint_characteristics> = [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ENFORCED | NOT ENFORCED ]
CreateConnector
CreateFunction
CreateIndex
CREATE INDEX statement.
CreateTable
CREATE TABLE statement.
CreateViewParams
MySQL CREATE VIEW additional parameters
Cte
A single CTE (used after WITH): <alias> [(col1, col2, ...)] AS <materialized> ( <query> ) The names in the column list before AS, 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.
DictionaryField
A dictionary field within a dictionary.
DisplaySeparated
DoUpdate
DollarQuotedString
ExceptSelectItem
Bigquery EXCEPT information, with at least one column.
ExprWithAlias
An expression optionally followed by an alias.
Fetch
Function
A function call
FunctionArgumentList
This represents everything inside the parentheses when calling a function.
FunctionDesc
Generic function description for DROP FUNCTION and CREATE TRIGGER.
Grantee
The principal that receives the privileges
HavingBound
The HAVING clause in a call to ANY_VALUE on BigQuery.
HiveFormat
HiveLoadDataFormat
HiveRowDelimiter
HiveSetLocation
Ident
An identifier, decomposed into its value or character data and the quote style.
IdentWithAlias
Single aliased identifier
IdentityParameters
IdentityProperty
IfStatement
An IF statement.
IlikeSelectItem
Snowflake ILIKE information.
IndexColumn
Index column type.
InputFormatClause
FORMAT identifier in input context, specific to ClickHouse.
Insert
INSERT statement.
InsertAliases
Interpolate
InterpolateExpr
ClickHouse INTERPOLATE clause for use in ORDER BY clause when using WITH 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
JsonPath
A JSON path.
JsonTableNamedColumn
A single column definition in MySQL’s JSON_TABLE table valued function.
JsonTableNestedColumn
A nested column in a JSON_TABLE column list
LambdaFunction
A lambda function.
LateralView
A hive LATERAL VIEW with potential column aliases
LockClause
LockTable
MacroArg
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 a MATCH_RECOGNIZE operation.
MergeClause
A when clause within a MERGE Statement
MergeInsertExpr
The expression used to insert rows within a MERGE statement.
Method
A method call
NamedWindowDefinition
ObjectName
A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
Offset
OnConflict
OneOrManyWithParensIntoIter
Owned iterator implementation of OneOrManyWithParens
OpenJsonTableColumn
A single column definition in MSSQL’s OPENJSON WITH clause.
OperateFunctionArg
Function argument in CREATE OR DROP FUNCTION.
OrderBy
OrderByExpr
An ORDER BY expression
OrderByOptions
OutputClause
A Output Clause in the end of a ‘MERGE’ Statement
PrintStatement
ProcedureParam
ProjectionSelect
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 including WITH, UNION / other set operations, and ORDER BY.
RaiseStatement
A RAISE statement.
RenameTable
rename object definition
ReplaceSelectElement
Syntax
ReplaceSelectItem
Bigquery REPLACE information.
ReturnStatement
Represents a Return statement.
RowAccessPolicy
Snowflake WITH ROW ACCESS POLICY policy_name ON (identifier, ...)
SecretOption
Select
A restricted variant of SELECT (without CTEs/ORDER BY), which may appear either as the only body item of a Query, or as an operand to a set operation like UNION.
SelectInto
SetAssignment
Assignment for a SET statement (name [=|TO] value)
SetSessionParamGeneric
SetSessionParamIdentityInsert
SetSessionParamOffsets
SetSessionParamStatistics
Setting
ShowObjects
ShowStatementIn
ShowStatementOptions
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
StructField
A field definition within a struct
SymbolDefinition
A symbol defined in a MATCH_RECOGNIZE operation.
Table
A TABLE command
TableAlias
TableAliasColumnDef
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.
TableEngine
Engine of DB. Some warehouse has parameters of engine, e.g. ClickHouse
TableFunctionArgs
Arguments to a table-valued function
TableIndexHints
TableSample
TableSampleBucket
TableSampleQuantity
TableSampleSeed
TableWithJoins
Tag
Snowflake WITH TAG ( tag_name = '<tag_value>', ...)
TagsColumnOption
Tags option of column Syntax
Top
TriggerExecBody
This keyword immediately precedes the declaration of one or two relation names that provide access to the transition relations of the triggering statement
TriggerReferencing
This keyword immediately precedes the declaration of one or two relation names that provide access to the transition relations of the triggering statement
TruncateTableTarget
Target of a TRUNCATE TABLE command
UnionField
A field definition within a union
UserDefinedTypeCompositeAttributeDef
SQL user defined type attribute definition
UtilityOption
Represents a single PostgreSQL utility option.
ValueWithSpan
Wraps a primitive SQL Value with its Span location
Values
ViewColumnDef
Column definition specified in a CREATE VIEW statement.
WildcardAdditionalOptions
Additional options for wildcards, e.g. Snowflake EXCLUDE/RENAME and Bigquery EXCEPT.
WindowFrame
Specifies the data processed by a window function, e.g. RANGE UNBOUNDED PRECEDING or ROWS BETWEEN 5 PRECEDING AND CURRENT ROW.
WindowSpec
A window specification (i.e. OVER ([window_name] PARTITION BY .. ORDER BY .. etc.))
With
WithFill
ClickHouse WITH FILL modifier for ORDER BY clause. Supported by ClickHouse syntax
XmlNamespaceDefinition
Represents a single XML namespace definition in the XMLNAMESPACES clause.
XmlPassingArgument
Argument passed in the XMLTABLE PASSING clause
XmlPassingClause
The PASSING clause for XMLTABLE
XmlTableColumn
A single column definition in XMLTABLE

Enums§

AccessExpr
An element of a Expr::CompoundFieldAccess. It can be an expression or a subscript.
Action
A privilege on a database object (table, sequence, etc.).
ActionApplyType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the APPLY privilege.
ActionCreateObjectType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the CREATE privilege.
ActionExecuteObjectType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the EXECUTE privilege.
ActionManageType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the MANAGE privilege.
ActionModifyType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the MODIFY privilege.
ActionMonitorType
See https://docs.snowflake.com/en/sql-reference/sql/grant-privilege under globalPrivileges in the MONITOR privilege.
AddDropSync
AfterMatchSkip
The after match skip option in a MATCH_RECOGNIZE operation.
AlterColumnOperation
An ALTER COLUMN (Statement::AlterTable) operation
AlterConnectorOwner
AlterIndexOperation
AlterPolicyOperation
An ALTER Policy (Statement::AlterPolicy) operation
AlterRoleOperation
An ALTER ROLE (Statement::AlterRole) operation
AlterTableAlgorithm
MySQL ALTER TABLE algorithm.
AlterTableLock
MySQL ALTER TABLE lock.
AlterTableOperation
An ALTER TABLE (Statement::AlterTable) operation
AlterTypeAddValuePosition
See AlterTypeAddValue
AlterTypeOperation
An AlterType operation
AnalyzeFormat
ArgMode
The mode of an argument in CREATE FUNCTION.
ArrayElemTypeDef
Represents the data type of the elements in an array (if any) as well as the syntax used to declare the array.
AssignmentTarget
Left-hand side of an assignment in an UPDATE statement, e.g. foo in foo = 5 (ColumnName assignment) or (a, b) in (a, b) = (1, 2) (Tuple assignment).
AttachDuckDBDatabaseOption
BeginTransactionKind
Transaction started with [ TRANSACTION | WORK ]
BinaryLength
BinaryOperator
Binary operators
CascadeOption
Cascade/restrict option for Postgres TRUNCATE table, MySQL GRANT/REVOKE, etc. [ CASCADE | RESTRICT ]
CastFormat
Options for CAST / TRY_CAST BigQuery: https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#formatting_syntax
CastKind
The syntax used for in a cast expression.
CeilFloorKind
The syntax used in a CEIL or FLOOR expression.
CharLengthUnits
Possible units for characters, initially based on 2016 ANSI SQL Standard.
CharacterLength
Information about character length, including length and possibly unit.
CloseCursor
ColumnOption
ColumnOptions are modifiers that follow a column definition in a CREATE TABLE statement.
ColumnPolicy
Column policy that identify a security policy of access to a column. Syntax
CommentDef
Helper to indicate if a comment includes the = in the display form
CommentObject
ConditionalStatements
A list of statements in a ConditionalStatementBlock.
ConflictTarget
ContextModifier
Optional context modifier for statements that can be or LOCAL, GLOBAL, or SESSION.
CopyIntoSnowflakeKind
Variants of the Snowflake COPY INTO statement
CopyLegacyCsvOption
A CSV option in COPY statement before PostgreSQL version 9.0.
CopyLegacyOption
An option in COPY statement before PostgreSQL version 9.0.
CopyOption
An option in COPY statement.
CopySource
CopyTarget
CreateFunctionBody
Represent the expression body of a CREATE FUNCTION statement as well as where within the statement, the body shows up.
CreateFunctionUsing
CreatePolicyCommand
Policy command for a CREATE POLICY statement.
CreatePolicyType
Policy type for a CREATE POLICY statement.
CreateTableOptions
Sql options of a CREATE TABLE statement.
CreateViewAlgorithm
MySQL CREATE VIEW algorithm parameter: [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
CreateViewSecurity
MySQL CREATE VIEW security parameter: [SQL SECURITY { DEFINER | INVOKER }]
CteAsMaterialized
DataType
SQL data types
DateTimeField
DeclareAssignment
Represents an expression assignment within a variable DECLARE statement.
DeclareType
Represents the type of a DECLARE statement.
Deduplicate
DEDUPLICATE statement used in OPTIMIZE TABLE et al. such as in ClickHouse SQL ClickHouse
DeferrableInitial
DescribeAlias
DiscardObject
Distinct
DropBehavior
<drop behavior> ::= CASCADE | RESTRICT.
DropFunctionOption
Function describe in DROP FUNCTION.
DuplicateTreatment
EmptyMatchesMode
EnumMember
ExactNumberInfo
Additional information for NUMERIC, DECIMAL, and DEC data types following the 2016 SQL Standard.
ExcludeSelectItem
Snowflake EXCLUDE information.
Expr
An SQL expression of any type.
ExtractSyntax
EXTRACT syntax variants.
FetchDirection
Specific direction for FETCH statement
FileFormat
External table’s available file format
FlushLocation
FlushType
ForClause
FOR XML or FOR JSON clause, specific to MSSQL (formats the output of a query as XML or JSON)
ForJson
ForXml
FormatClause
FORMAT identifier or FORMAT NULL clause, specific to ClickHouse.
FromTable
A FROM clause within a DELETE statement.
FunctionArg
FunctionArgExpr
FunctionArgOperator
Operator used to separate function arguments
FunctionArgumentClause
FunctionArguments
The arguments passed to a function call.
FunctionBehavior
These attributes inform the query optimizer about the behavior of the function.
FunctionCalledOnNull
These attributes describe the behavior of the function when called with a null argument.
FunctionDeterminismSpecifier
BigQuery Determinism specifier used in a UDF definition.
FunctionParallel
If it is safe for PostgreSQL to call the function from multiple threads at once
GeneratedAs
GeneratedAss are modifiers that follow a column option in a generated. ‘ExpStored’ is used for a column generated from an expression and stored.
GeneratedExpressionMode
GeneratedExpressionModes are modifiers that follow an expression in a generated. No modifier is typically the same as Virtual.
GeometricTypeKind
Represents different types of geometric shapes which are commonly used in PostgreSQL/Redshift for spatial operations and geometry-related computations.
GrantObjects
Objects on which privileges are granted in a GRANT statement.
GranteeName
Users/roles designated in a GRANT/REVOKE
GranteesType
GroupByExpr
GroupByWithModifier
ClickHouse supports GROUP BY WITH modifiers(includes ROLLUP|CUBE|TOTALS). e.g. GROUP BY year WITH ROLLUP WITH TOTALS
HavingBoundKind
HiveDelimiter
HiveDescribeFormat
HiveDistributionStyle
HiveIOFormat
HiveRowFormat
IdentityPropertyFormatKind
A format of parameters of identity column.
IdentityPropertyKind
Identity is a column option for defining an identity or autoincrement column in a CREATE TABLE statement. Syntax
IdentityPropertyOrder
The identity column option specifies how values are generated for the auto-incremented column, either in increasing or decreasing order. Syntax
IndexOption
MySQLs index option.
IndexType
Indexing method used by that index.
JoinConstraint
JoinOperator
JsonNullClause
MSSQL’s json null clause
JsonPathElem
An element of a JSON path.
JsonTableColumn
A single column definition in MySQL’s JSON_TABLE table valued function.
JsonTableColumnErrorHandling
Stores the error handling clause of a JSON_TABLE table valued function: {NULL | DEFAULT json_string | ERROR} ON {ERROR | EMPTY }
KeyOrIndexDisplay
Representation whether a definition can can contains the KEY or INDEX keywords with the same meaning.
KillType
LimitClause
ListAggOnOverflow
The ON OVERFLOW clause of a LISTAGG invocation
LockTableType
LockType
MacroDefinition
MatchRecognizePattern
The pattern in a MATCH_RECOGNIZE operation.
MatchRecognizeSymbol
A symbol in a MATCH_RECOGNIZE pattern.
MergeAction
Underlying statement of a when clause within a MERGE Statement
MergeClauseKind
Variant of WHEN clause used within a MERGE Statement.
MergeInsertKind
The type of expression used to insert rows within a MERGE statement.
MinMaxValue
Can use to describe options in create sequence or table column type identity [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
MySQLColumnPosition
MySQL ALTER TABLE only [FIRST | AFTER column_name]
MysqlInsertPriority
Mysql specific syntax
NamedWindowExpr
An expression used in a named window declaration.
NonBlock
NormalizationForm
The Unicode Standard defines four normalization forms, which are intended to eliminate certain distinctions between visually or functionally identical characters.
NullTreatment
Specifies Ignore / Respect NULL within window functions. For example FIRST_VALUE(column2) IGNORE NULLS OVER (PARTITION BY column1)
NullsDistinctOption
PostgreSQL unique index nulls handling option: [ NULLS [ NOT ] DISTINCT ]
ObjectNamePart
A single part of an ObjectName
ObjectType
OffsetRows
Stores the keyword after OFFSET <number>
OnCommit
OnConflictAction
OnInsert
OneOrManyWithParens
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 implements Deref<Target = [T]> and IntoIterator, so you can call slice methods on it and iterate over items
OrderByKind
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
PartitionRangeDirection
Specifies which partition the boundary values on table partitioning belongs to.
Password
PivotValueSource
The source of values in a PIVOT operation.
Privileges
Privileges granted in a GRANT statement or revoked in a REVOKE statement.
RaisErrorOption
RaiseStatementValue
Represents the error value of a RaiseStatement.
ReferentialAction
<referential_action> = { RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT }
RenameSelectItem
Snowflake RENAME information.
RepetitionQuantifier
Determines the minimum and maximum allowed occurrences of a pattern in a MATCH_RECOGNIZE operation.
ResetConfig
RESET config option:
ReturnStatementValue
Variants of a RETURN statement
RoleOption
An option in ROLE statement.
RowsPerMatch
The rows per match option in a MATCH_RECOGNIZE operation.
SchemaName
Schema possible naming variants (1).
SearchModifier
Fulltext search modifiers (1).
SecondaryRoles
Snowflake SECONDARY ROLES USE variant See: https://docs.snowflake.com/en/sql-reference/sql/use-secondary-roles
SelectFlavor
What did this select look like?
SelectItem
One item of the comma-separated list following SELECT
SelectItemQualifiedWildcardKind
Represents an expression behind a wildcard expansion in a projection. `SELECT T.* FROM T;
SequenceOptions
Can use to describe options in create sequence or table column type identity
SessionParamStatsTopic
SessionParamValue
Set
SetConfigValue
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.
SetSessionParamKind
ShowCreateObject
ShowStatementFilter
ShowStatementFilterPosition
ShowStatementInClause
ShowStatementInParentType
SqlOption
SqliteOnConflict
Sqlite specific syntax
Statement
A top-level statement (SELECT, INSERT, CREATE, etc.)
StorageSerializationPolicy
Snowflake StorageSerializationPolicy for Iceberg Tables
StructBracketKind
Type of brackets used for STRUCT literals.
Subscript
The contents inside the [ and ] in a subscript expression.
TableConstraint
A table-level constraint, specified in a CREATE TABLE or an ALTER TABLE ADD <constraint> statement.
TableFactor
A table name or a parenthesized subquery with an optional alias
TableIndexHintForClause
TableIndexHintType
TableIndexType
TableObject
Represents the referenced table in an INSERT INTO statement
TableOptionsClustered
TableSampleKind
The table sample modifier options
TableSampleMethod
The table sample method names
TableSampleModifier
TableSampleSeedModifier
TableSampleUnit
TableVersion
TimezoneInfo
Timestamp and Time data types information about TimeZone formatting.
TopQuantity
TransactionAccessMode
TransactionIsolationLevel
TransactionMode
TransactionModifier
Modifier for the transaction in the BEGIN syntax
TriggerEvent
Used to describe trigger events
TriggerExecBodyType
Types of trigger body execution body.
TriggerObject
This specifies whether the trigger function should be fired once for every row affected by the trigger event, or just once per SQL statement.
TriggerPeriod
Trigger period
TriggerReferencingType
This clause indicates whether the following relation name is for the before-image transition relation or the after-image transition relation
TrimWhereField
TruncateIdentityOption
PostgreSQL identity option for TRUNCATE table [ RESTART IDENTITY | CONTINUE IDENTITY ]
UnaryOperator
Unary operators
UpdateTableFromKind
The FROM clause of an UPDATE TABLE statement
Use
A USE (Statement::Use) operation
UserDefinedTypeRepresentation
SQL user defined type definition
Value
Primitive SQL values such as number and string
ValueTableMode
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
WindowFrameBound
Specifies WindowFrame’s start_bound and end_bound
WindowFrameUnits
WindowType
WrappedCollection
Helper to indicate if a collection should be wrapped by a symbol in the display form
XmlTableColumnOption
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. See Visitor for recursively visiting parsed SQL statements.
VisitMut
A type that can be visited by a VisitorMut. See VisitorMut for recursively visiting parsed SQL statements.
Visitor
A visitor that can be used to walk an AST tree.
VisitorMut
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 in v
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 in v