import { AllColumns, BaseNode, Empty, Keyword } from "./Base"; import { Expr, FuncCall, Identifier, ListExpr, MemberExpr, ParenExpr, EntityName } from "./Expr"; import { Alias } from "./Alias"; import { FrameClause } from "./WindowFrame"; import { Literal, StringLiteral } from "./Literal"; import { MysqlModifier } from "./dialects/Mysql"; import { ColumnDefinition, RelationKind } from "./CreateTable"; import { DeleteStmt, InsertStmt, IntoVariablesClause, PostgresqlOperator, PostgresqlOperatorExpr, UpdateStmt } from "./Node"; export type AllSelectNodes = CompoundSelectStmt | SelectStmt | WithClause | CommonTableExpr | CteSearchClause | CteCycleClause | CteCycleClauseValues | SelectClause | SelectAll | SelectDistinct | SelectDistinctOn | SelectAsStruct | SelectAsValue | ExceptColumns | ReplaceColumns | FromClause | WhereClause | GroupByClause | GroupByRollup | GroupByCube | GroupByGroupingSets | GroupByAll | HavingClause | WindowClause | QualifyClause | NamedWindow | WindowDefinition | OrderByClause | PartitionByClause | LimitClause | LimitAll | LimitRowsExamined | OffsetClause | FetchClause | DualTable | JoinExpr | IndexedTable | NotIndexedTable | LateralDerivedTable | PartitionedTable | TableWithInheritance | TableWithoutInheritance | FuncCallWithColumnDefinitions | WithOrdinalityExpr | RowsFromExpr | UnnestWithOffsetExpr | UnnestExpr | PivotExpr | PivotForIn | UnpivotExpr | UnpivotForIn | TablesampleExpr | TablesampleMethod | TablesamplePercent | TablesampleRepeatable | ForSystemTimeAsOfExpr | JoinOnSpecification | JoinUsingSpecification | SortSpecification | SortDirectionAsc | SortDirectionDesc | SortDirectionUsingOperator | IntoTableClause | IntoDumpfileClause | IntoOutfileClause | OutfileFields | OutfileLines | OutfileOptionTerminatedBy | OutfileOptionEscapedBy | OutfileOptionStartingBy | OutfileOptionEnclosedBy | OutfileOptionCharacterSet | ForClause | ForClauseTables | LockInShareModeClause | TableClause; export interface CompoundSelectStmt extends BaseNode { type: "compound_select_stmt"; left: SubSelect; operator: Keyword<"UNION" | "EXCEPT" | "INTERSECT"> | [Keyword<"UNION" | "EXCEPT" | "INTERSECT">, Keyword<"ALL" | "DISTINCT">]; right: SubSelect; } export type SubSelect = SelectStmt | CompoundSelectStmt | ParenExpr; export interface SelectStmt extends BaseNode { type: "select_stmt"; clauses: (WithClause | SelectClause | FromClause | WhereClause | GroupByClause | HavingClause | WindowClause | QualifyClause | OrderByClause | LimitClause | OffsetClause | FetchClause | IntoTableClause | IntoVariablesClause | IntoDumpfileClause | IntoOutfileClause | ForClause | LockInShareModeClause | TableClause | ParenExpr)[]; } export interface WithClause extends BaseNode { type: "with_clause"; withKw: Keyword<"WITH">; recursiveKw?: Keyword<"RECURSIVE">; tables: ListExpr; } export interface CommonTableExpr extends BaseNode { type: "common_table_expr"; table: Identifier; columns?: ParenExpr>; asKw: Keyword<"AS">; materializedKw?: Keyword<"MATERIALIZED"> | [Keyword<"NOT">, Keyword<"MATERIALIZED">]; expr: ParenExpr; search?: CteSearchClause; cycle?: CteCycleClause; } export interface CteSearchClause extends BaseNode { type: "cte_search_clause"; searchKw: [ Keyword<"SEARCH">, Keyword<"BREADTH" | "DEPTH">, Keyword<"FIRST">, Keyword<"BY"> ]; columns: ListExpr; setKw: Keyword<"SET">; resultColumn: Identifier; } export interface CteCycleClause extends BaseNode { type: "cte_cycle_clause"; cycleKw: Keyword<"CYCLE">; columns: ListExpr; setKw: Keyword<"SET">; resultColumn: Identifier; values?: CteCycleClauseValues; usingKw: Keyword<"USING">; pathColumn: Identifier; } export interface CteCycleClauseValues extends BaseNode { type: "cte_cycle_clause_values"; toKw: Keyword<"TO">; markValue: Literal; defaultKw?: Keyword<"DEFAULT">; defaultValue: Literal; } export interface SelectClause extends BaseNode { type: "select_clause"; selectKw: Keyword<"SELECT" | "PERFORM">; modifiers: (SelectAll | SelectDistinct | SelectDistinctOn | SelectAsStruct | SelectAsValue | MysqlModifier)[]; columns?: ListExpr | Empty>; } export interface SelectAll extends BaseNode { type: "select_all"; allKw: Keyword<"ALL">; } export interface SelectDistinct extends BaseNode { type: "select_distinct"; distinctKw: Keyword<"DISTINCT" | "DISTINCTROW">; } export interface SelectDistinctOn extends BaseNode { type: "select_distinct_on"; distinctOnKw: [Keyword<"DISTINCT">, Keyword<"ON">]; columns: ParenExpr>; } export interface SelectAsStruct extends BaseNode { type: "select_as_struct"; asStructKw: [Keyword<"AS">, Keyword<"STRUCT">]; } export interface SelectAsValue extends BaseNode { type: "select_as_value"; asValueKw: [Keyword<"AS">, Keyword<"VALUE">]; } export interface ExceptColumns extends BaseNode { type: "except_columns"; expr: MemberExpr | AllColumns; exceptKw: Keyword<"EXCEPT">; columns: ParenExpr>; } export interface ReplaceColumns extends BaseNode { type: "replace_columns"; expr: MemberExpr | AllColumns; replaceKw: Keyword<"REPLACE">; columns: ParenExpr>>; } export interface FromClause extends BaseNode { type: "from_clause"; fromKw: Keyword<"FROM" | "USING">; expr: TableExpr | DualTable; } export interface WhereClause extends BaseNode { type: "where_clause"; whereKw: Keyword<"WHERE">; expr: Expr; } export interface GroupByClause extends BaseNode { type: "group_by_clause"; groupByKw: [Keyword<"GROUP">, Keyword<"BY">]; distinctKw?: Keyword<"ALL" | "DISTINCT">; columns: ListExpr; withRollupKw?: [Keyword<"WITH">, Keyword<"ROLLUP">]; } type GroupingElement = Expr | GroupByRollup | GroupByCube | GroupByGroupingSets | GroupByAll; export interface GroupByRollup extends BaseNode { type: "group_by_rollup"; rollupKw: Keyword<"ROLLUP">; columns: ParenExpr>; } export interface GroupByCube extends BaseNode { type: "group_by_cube"; cubeKw: Keyword<"CUBE">; columns: ParenExpr>; } export interface GroupByAll extends BaseNode { type: "group_by_all"; allKw: Keyword<"ALL">; } export interface GroupByGroupingSets extends BaseNode { type: "group_by_grouping_sets"; groupingSetsKw: Keyword<"GROUPING SETS">; columns: ParenExpr>; } export interface HavingClause extends BaseNode { type: "having_clause"; havingKw: Keyword<"HAVING">; expr: Expr; } export interface WindowClause extends BaseNode { type: "window_clause"; windowKw: Keyword<"WINDOW">; namedWindows: ListExpr; } export interface NamedWindow extends BaseNode { type: "named_window"; name: Identifier; asKw: Keyword<"AS">; window: ParenExpr; } export interface WindowDefinition extends BaseNode { type: "window_definition"; baseWindowName?: Identifier; partitionBy?: PartitionByClause; orderBy?: OrderByClause; frame?: FrameClause; } export interface OrderByClause extends BaseNode { type: "order_by_clause"; orderByKw: [Keyword<"ORDER">, Keyword<"BY">]; specifications: ListExpr; withRollupKw?: [Keyword<"WITH">, Keyword<"ROLLUP">]; } export interface PartitionByClause extends BaseNode { type: "partition_by_clause"; partitionByKw: [Keyword<"PARTITION">, Keyword<"BY">]; specifications: ListExpr; } export interface LimitClause extends BaseNode { type: "limit_clause"; limitKw: Keyword<"LIMIT">; count?: Expr | LimitAll; offsetKw?: Keyword<"OFFSET">; offset?: Expr; rowsExamined?: LimitRowsExamined; } export interface LimitAll extends BaseNode { type: "limit_all"; allKw: Keyword<"ALL">; } export interface LimitRowsExamined extends BaseNode { type: "limit_rows_examined"; rowsExaminedKw: [Keyword<"ROWS">, Keyword<"EXAMINED">]; count: Expr; } export interface OffsetClause extends BaseNode { type: "offset_clause"; offsetKw: Keyword<"OFFSET">; offset: Expr; rowsKw?: Keyword<"ROWS" | "ROW">; } export interface FetchClause extends BaseNode { type: "fetch_clause"; fetchKw: [Keyword<"FETCH">, Keyword<"FIRST" | "NEXT">]; count?: Expr; rowsKw: Keyword<"ROWS" | "ROW">; withTiesKw: Keyword<"ONLY"> | [Keyword<"WITH">, Keyword<"TIES">]; } export interface DualTable extends BaseNode { type: "dual_table"; dualKw: Keyword<"DUAL">; } type TableExpr = JoinExpr | PivotExpr | UnpivotExpr | TablesampleExpr | ForSystemTimeAsOfExpr | TableFactor; export interface JoinExpr extends BaseNode { type: "join_expr"; left: TableExpr; operator: JoinOp | ","; right: TableFactor; specification?: JoinOnSpecification | JoinUsingSpecification; } type JoinOp = Keyword<"NATURAL" | "LEFT" | "RIGHT" | "FULL" | "OUTER" | "INNER" | "CROSS" | "JOIN">[] | Keyword<"JOIN" | "STRAIGHT_JOIN">; export type TableFactor = RelationExpr | TableFuncCall | WithOrdinalityExpr | ParenExpr | UnnestWithOffsetExpr | UnnestExpr | LateralDerivedTable | PartitionedTable | RowsFromExpr | Alias; export type RelationExpr = EntityName | TableWithInheritance | TableWithoutInheritance | IndexedTable | NotIndexedTable; export type TableFuncCall = FuncCall | FuncCallWithColumnDefinitions; export interface IndexedTable extends BaseNode { type: "indexed_table"; table: EntityName | Alias; indexedByKw: [Keyword<"INDEXED">, Keyword<"BY">]; index: Identifier; } export interface NotIndexedTable extends BaseNode { type: "not_indexed_table"; table: EntityName | Alias; notIndexedKw: [Keyword<"NOT">, Keyword<"INDEXED">]; } export interface LateralDerivedTable extends BaseNode { type: "lateral_derived_table"; lateralKw: Keyword<"LATERAL">; expr: ParenExpr | TableFuncCall | WithOrdinalityExpr | RowsFromExpr; } export interface PartitionedTable extends BaseNode { type: "partitioned_table"; table: EntityName | Alias; partitionKw: Keyword<"PARTITION">; partitions: ParenExpr>; } export interface TableWithInheritance extends BaseNode { type: "table_with_inheritance"; table: EntityName; } export interface TableWithoutInheritance extends BaseNode { type: "table_without_inheritance"; onlyKw: Keyword<"ONLY">; table: EntityName; } export interface RowsFromExpr extends BaseNode { type: "rows_from_expr"; rowsFromKw: [Keyword<"ROWS">, Keyword<"FROM">]; expr: ParenExpr>; } export interface WithOrdinalityExpr extends BaseNode { type: "with_ordinality_expr"; expr: TableFuncCall | RowsFromExpr; withOrdinalityKw: [Keyword<"WITH">, Keyword<"ORDINALITY">]; } export interface FuncCallWithColumnDefinitions extends BaseNode { type: "func_call_with_column_definitions"; funcCall: Alias | FuncCall; asKw?: Keyword<"AS">; columns: ParenExpr>; } export interface UnnestWithOffsetExpr extends BaseNode { type: "unnest_with_offset_expr"; unnest: UnnestExpr | MemberExpr | Identifier | Alias; withOffsetKw: [Keyword<"WITH">, Keyword<"OFFSET">]; } export interface UnnestExpr extends BaseNode { type: "unnest_expr"; unnestKw: Keyword<"UNNEST">; expr: ParenExpr; } export interface PivotExpr extends BaseNode { type: "pivot_expr"; left: TableExpr; pivotKw: Keyword<"PIVOT">; args: ParenExpr; } export interface PivotForIn extends BaseNode { type: "pivot_for_in"; aggregations: ListExpr>; forKw: Keyword<"FOR">; inputColumn: Identifier; inKw: Keyword<"IN">; pivotColumns: ParenExpr>>; } export interface UnpivotExpr extends BaseNode { type: "unpivot_expr"; left: TableExpr; unpivotKw: Keyword<"UNPIVOT">; nullHandlingKw?: [Keyword<"INCLUDE" | "EXCLUDE">, Keyword<"NULLS">]; args: ParenExpr; } export interface UnpivotForIn extends BaseNode { type: "unpivot_for_in"; valuesColumn: Identifier | ParenExpr>; forKw: Keyword<"FOR">; nameColumn: Identifier; inKw: Keyword<"IN">; unpivotColumns: ParenExpr>> | ParenExpr> | Alias>>>>; } export interface TablesampleExpr extends BaseNode { type: "tablesample_expr"; left: TableExpr; tablesampleKw: Keyword<"TABLESAMPLE">; method: TablesampleMethod | Identifier; args: ParenExpr>; repeatable?: TablesampleRepeatable; } export interface TablesampleMethod extends BaseNode { type: "tablesample_method"; methodKw: Keyword<"SYSTEM" | "BERNOULLI">; } export interface TablesamplePercent extends BaseNode { type: "tablesample_percent"; percent: Expr; percentKw: Keyword<"PERCENT">; } export interface TablesampleRepeatable extends BaseNode { type: "tablesample_repeatable"; repeatableKw: Keyword<"REPEATABLE">; seed: ParenExpr; } export interface ForSystemTimeAsOfExpr extends BaseNode { type: "for_system_time_as_of_expr"; left: TableExpr; forSystemTimeAsOfKw: [ Keyword<"FOR">, Keyword<"SYSTEM_TIME">, Keyword<"AS">, Keyword<"OF"> ]; expr: Expr; } export interface JoinOnSpecification extends BaseNode { type: "join_on_specification"; onKw: Keyword<"ON">; expr: Expr; } export interface JoinUsingSpecification extends BaseNode { type: "join_using_specification"; usingKw: Keyword<"USING">; expr: ParenExpr>; } export interface SortSpecification extends BaseNode { type: "sort_specification"; expr: Expr; direction?: SortDirectionAsc | SortDirectionDesc | SortDirectionUsingOperator; nullHandlingKw?: [Keyword<"NULLS">, Keyword<"FIRST" | "LAST">]; } export interface SortDirectionAsc extends BaseNode { type: "sort_direction_asc"; ascKw: Keyword<"ASC">; } export interface SortDirectionDesc extends BaseNode { type: "sort_direction_desc"; descKw: Keyword<"DESC">; } export interface SortDirectionUsingOperator extends BaseNode { type: "sort_direction_using_operator"; usingKw: Keyword<"USING">; operator: PostgresqlOperator | PostgresqlOperatorExpr; } export interface QualifyClause extends BaseNode { type: "qualify_clause"; qualifyKw: Keyword<"QUALIFY">; expr: Expr; } export interface IntoTableClause extends BaseNode { type: "into_table_clause"; intoKw: Keyword<"INTO">; kind?: RelationKind; tableKw?: Keyword<"TABLE">; name: EntityName; } export interface IntoDumpfileClause extends BaseNode { type: "into_dumpfile_clause"; intoDumpfileKw: [Keyword<"INTO">, Keyword<"DUMPFILE">]; filename: StringLiteral; } export interface IntoOutfileClause extends BaseNode { type: "into_outfile_clause"; intoOutfileKw: [Keyword<"INTO">, Keyword<"OUTFILE">]; filename: StringLiteral; charset?: OutfileOptionCharacterSet; fields?: OutfileFields; lines?: OutfileLines; } export interface OutfileFields extends BaseNode { type: "outfile_fields"; fieldsKw: Keyword<"FIELDS" | "COLUMNS">; options: (OutfileOptionTerminatedBy | OutfileOptionEnclosedBy | OutfileOptionEscapedBy)[]; } export interface OutfileLines extends BaseNode { type: "outfile_lines"; linesKw: Keyword<"LINES">; options: (OutfileOptionStartingBy | OutfileOptionTerminatedBy)[]; } export interface OutfileOptionTerminatedBy extends BaseNode { type: "outfile_option_terminated_by"; terminatedByKw: [Keyword<"TERMINATED">, Keyword<"BY">]; value: StringLiteral; } export interface OutfileOptionEscapedBy extends BaseNode { type: "outfile_option_escaped_by"; escapedByKw: [Keyword<"ESCAPED">, Keyword<"BY">]; value: StringLiteral; } export interface OutfileOptionStartingBy extends BaseNode { type: "outfile_option_starting_by"; startingByKw: [Keyword<"STARTING">, Keyword<"BY">]; value: StringLiteral; } export interface OutfileOptionEnclosedBy extends BaseNode { type: "outfile_option_enclosed_by"; optionallyKw?: Keyword<"OPTIONALLY">; enclosedByKw: [Keyword<"ENCLOSED">, Keyword<"BY">]; value: StringLiteral; } export interface OutfileOptionCharacterSet extends BaseNode { type: "outfile_option_character_set"; characterSetKw: [Keyword<"CHARACTER">, Keyword<"SET">]; value: Identifier; } export interface ForClause extends BaseNode { type: "for_clause"; forKw: Keyword<"FOR">; lockStrengthKw: Keyword<"UPDATE"> | [Keyword<"NO">, Keyword<"KEY">, Keyword<"UPDATE">] | Keyword<"SHARE"> | [Keyword<"KEY">, Keyword<"SHARE">]; tables?: ForClauseTables; waitingKw?: Keyword<"NOWAIT"> | [Keyword<"SKIP">, Keyword<"LOCKED">]; } export interface ForClauseTables extends BaseNode { type: "for_clause_tables"; ofKw: Keyword<"OF">; tables: ListExpr; } export interface LockInShareModeClause extends BaseNode { type: "lock_in_share_mode_clause"; lockInShareModeKw: [ Keyword<"LOCK">, Keyword<"IN">, Keyword<"SHARE">, Keyword<"MODE"> ]; } export interface TableClause extends BaseNode { type: "table_clause"; tableKw: Keyword<"TABLE">; table: RelationExpr; } export {};