Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // Exasol: function call with EMITS clause
486    FunctionEmits(Box<FunctionEmits>),
487
488    // JSON functions
489    JsonExtract(Box<JsonExtractFunc>),
490    JsonExtractScalar(Box<JsonExtractFunc>),
491    JsonExtractPath(Box<JsonPathFunc>),
492    JsonArray(Box<VarArgFunc>),
493    JsonObject(Box<JsonObjectFunc>),
494    JsonQuery(Box<JsonExtractFunc>),
495    JsonValue(Box<JsonExtractFunc>),
496    JsonArrayLength(Box<UnaryFunc>),
497    JsonKeys(Box<UnaryFunc>),
498    JsonType(Box<UnaryFunc>),
499    ParseJson(Box<UnaryFunc>),
500    ToJson(Box<UnaryFunc>),
501    JsonSet(Box<JsonModifyFunc>),
502    JsonInsert(Box<JsonModifyFunc>),
503    JsonRemove(Box<JsonPathFunc>),
504    JsonMergePatch(Box<BinaryFunc>),
505    JsonArrayAgg(Box<JsonArrayAggFunc>),
506    JsonObjectAgg(Box<JsonObjectAggFunc>),
507
508    // Type casting/conversion
509    Convert(Box<ConvertFunc>),
510    Typeof(Box<UnaryFunc>),
511
512    // Additional expressions
513    Lambda(Box<LambdaExpr>),
514    Parameter(Box<Parameter>),
515    Placeholder(Placeholder),
516    NamedArgument(Box<NamedArgument>),
517    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
518    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
519    TableArgument(Box<TableArgument>),
520    SqlComment(Box<SqlComment>),
521
522    // Additional predicates
523    NullSafeEq(Box<BinaryOp>),
524    NullSafeNeq(Box<BinaryOp>),
525    Glob(Box<BinaryOp>),
526    SimilarTo(Box<SimilarToExpr>),
527    Any(Box<QuantifiedExpr>),
528    All(Box<QuantifiedExpr>),
529    Overlaps(Box<OverlapsExpr>),
530
531    // Bitwise operations
532    BitwiseLeftShift(Box<BinaryOp>),
533    BitwiseRightShift(Box<BinaryOp>),
534    BitwiseAndAgg(Box<AggFunc>),
535    BitwiseOrAgg(Box<AggFunc>),
536    BitwiseXorAgg(Box<AggFunc>),
537
538    // Array/struct/map access
539    Subscript(Box<Subscript>),
540    Dot(Box<DotAccess>),
541    MethodCall(Box<MethodCall>),
542    ArraySlice(Box<ArraySlice>),
543
544    // DDL statements
545    CreateTable(Box<CreateTable>),
546    DropTable(Box<DropTable>),
547    Undrop(Box<Undrop>),
548    AlterTable(Box<AlterTable>),
549    CreateIndex(Box<CreateIndex>),
550    DropIndex(Box<DropIndex>),
551    CreateView(Box<CreateView>),
552    DropView(Box<DropView>),
553    AlterView(Box<AlterView>),
554    AlterIndex(Box<AlterIndex>),
555    Truncate(Box<Truncate>),
556    Use(Box<Use>),
557    Cache(Box<Cache>),
558    Uncache(Box<Uncache>),
559    LoadData(Box<LoadData>),
560    Pragma(Box<Pragma>),
561    Grant(Box<Grant>),
562    Revoke(Box<Revoke>),
563    Comment(Box<Comment>),
564    SetStatement(Box<SetStatement>),
565    // Phase 4: Additional DDL statements
566    CreateSchema(Box<CreateSchema>),
567    DropSchema(Box<DropSchema>),
568    DropNamespace(Box<DropNamespace>),
569    CreateDatabase(Box<CreateDatabase>),
570    DropDatabase(Box<DropDatabase>),
571    CreateFunction(Box<CreateFunction>),
572    DropFunction(Box<DropFunction>),
573    CreateProcedure(Box<CreateProcedure>),
574    DropProcedure(Box<DropProcedure>),
575    CreateSequence(Box<CreateSequence>),
576    CreateSynonym(Box<CreateSynonym>),
577    DropSequence(Box<DropSequence>),
578    AlterSequence(Box<AlterSequence>),
579    CreateTrigger(Box<CreateTrigger>),
580    DropTrigger(Box<DropTrigger>),
581    CreateType(Box<CreateType>),
582    DropType(Box<DropType>),
583    Describe(Box<Describe>),
584    Show(Box<Show>),
585
586    // Transaction and other commands
587    Command(Box<Command>),
588    Kill(Box<Kill>),
589    /// EXEC/EXECUTE statement (TSQL stored procedure call)
590    Execute(Box<ExecuteStatement>),
591
592    /// Snowflake CREATE TASK statement
593    CreateTask(Box<CreateTask>),
594
595    // Placeholder for unparsed/raw SQL
596    Raw(Raw),
597
598    // Paren for grouping
599    Paren(Box<Paren>),
600
601    // Expression with trailing comments (for round-trip preservation)
602    Annotated(Box<Annotated>),
603
604    // === BATCH GENERATED EXPRESSION TYPES ===
605    // Generated from Python sqlglot expressions.py
606    Refresh(Box<Refresh>),
607    LockingStatement(Box<LockingStatement>),
608    SequenceProperties(Box<SequenceProperties>),
609    TruncateTable(Box<TruncateTable>),
610    Clone(Box<Clone>),
611    Attach(Box<Attach>),
612    Detach(Box<Detach>),
613    Install(Box<Install>),
614    Summarize(Box<Summarize>),
615    Declare(Box<Declare>),
616    DeclareItem(Box<DeclareItem>),
617    Set(Box<Set>),
618    Heredoc(Box<Heredoc>),
619    SetItem(Box<SetItem>),
620    QueryBand(Box<QueryBand>),
621    UserDefinedFunction(Box<UserDefinedFunction>),
622    RecursiveWithSearch(Box<RecursiveWithSearch>),
623    ProjectionDef(Box<ProjectionDef>),
624    TableAlias(Box<TableAlias>),
625    ByteString(Box<ByteString>),
626    HexStringExpr(Box<HexStringExpr>),
627    UnicodeString(Box<UnicodeString>),
628    ColumnPosition(Box<ColumnPosition>),
629    ColumnDef(Box<ColumnDef>),
630    AlterColumn(Box<AlterColumn>),
631    AlterSortKey(Box<AlterSortKey>),
632    AlterSet(Box<AlterSet>),
633    RenameColumn(Box<RenameColumn>),
634    Comprehension(Box<Comprehension>),
635    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
636    MergeTreeTTL(Box<MergeTreeTTL>),
637    IndexConstraintOption(Box<IndexConstraintOption>),
638    ColumnConstraint(Box<ColumnConstraint>),
639    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
640    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
641    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
642    CheckColumnConstraint(Box<CheckColumnConstraint>),
643    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
644    CompressColumnConstraint(Box<CompressColumnConstraint>),
645    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
646    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
647    WithOperator(Box<WithOperator>),
648    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
649    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
650    CommentColumnConstraint(CommentColumnConstraint),
651    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
652    IndexColumnConstraint(Box<IndexColumnConstraint>),
653    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
654    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
655    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
656    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
657    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
658    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
659    InOutColumnConstraint(Box<InOutColumnConstraint>),
660    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
661    PathColumnConstraint(Box<PathColumnConstraint>),
662    Constraint(Box<Constraint>),
663    Export(Box<Export>),
664    Filter(Box<Filter>),
665    Changes(Box<Changes>),
666    CopyParameter(Box<CopyParameter>),
667    Credentials(Box<Credentials>),
668    Directory(Box<Directory>),
669    ForeignKey(Box<ForeignKey>),
670    ColumnPrefix(Box<ColumnPrefix>),
671    PrimaryKey(Box<PrimaryKey>),
672    IntoClause(Box<IntoClause>),
673    JoinHint(Box<JoinHint>),
674    Opclass(Box<Opclass>),
675    Index(Box<Index>),
676    IndexParameters(Box<IndexParameters>),
677    ConditionalInsert(Box<ConditionalInsert>),
678    MultitableInserts(Box<MultitableInserts>),
679    OnConflict(Box<OnConflict>),
680    OnCondition(Box<OnCondition>),
681    Returning(Box<Returning>),
682    Introducer(Box<Introducer>),
683    PartitionRange(Box<PartitionRange>),
684    Fetch(Box<Fetch>),
685    Group(Box<Group>),
686    Cube(Box<Cube>),
687    Rollup(Box<Rollup>),
688    GroupingSets(Box<GroupingSets>),
689    LimitOptions(Box<LimitOptions>),
690    Lateral(Box<Lateral>),
691    TableFromRows(Box<TableFromRows>),
692    RowsFrom(Box<RowsFrom>),
693    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
694    WithFill(Box<WithFill>),
695    Property(Box<Property>),
696    GrantPrivilege(Box<GrantPrivilege>),
697    GrantPrincipal(Box<GrantPrincipal>),
698    AllowedValuesProperty(Box<AllowedValuesProperty>),
699    AlgorithmProperty(Box<AlgorithmProperty>),
700    AutoIncrementProperty(Box<AutoIncrementProperty>),
701    AutoRefreshProperty(Box<AutoRefreshProperty>),
702    BackupProperty(Box<BackupProperty>),
703    BuildProperty(Box<BuildProperty>),
704    BlockCompressionProperty(Box<BlockCompressionProperty>),
705    CharacterSetProperty(Box<CharacterSetProperty>),
706    ChecksumProperty(Box<ChecksumProperty>),
707    CollateProperty(Box<CollateProperty>),
708    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
709    DataDeletionProperty(Box<DataDeletionProperty>),
710    DefinerProperty(Box<DefinerProperty>),
711    DistKeyProperty(Box<DistKeyProperty>),
712    DistributedByProperty(Box<DistributedByProperty>),
713    DistStyleProperty(Box<DistStyleProperty>),
714    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
715    EngineProperty(Box<EngineProperty>),
716    ToTableProperty(Box<ToTableProperty>),
717    ExecuteAsProperty(Box<ExecuteAsProperty>),
718    ExternalProperty(Box<ExternalProperty>),
719    FallbackProperty(Box<FallbackProperty>),
720    FileFormatProperty(Box<FileFormatProperty>),
721    CredentialsProperty(Box<CredentialsProperty>),
722    FreespaceProperty(Box<FreespaceProperty>),
723    InheritsProperty(Box<InheritsProperty>),
724    InputModelProperty(Box<InputModelProperty>),
725    OutputModelProperty(Box<OutputModelProperty>),
726    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
727    JournalProperty(Box<JournalProperty>),
728    LanguageProperty(Box<LanguageProperty>),
729    EnviromentProperty(Box<EnviromentProperty>),
730    ClusteredByProperty(Box<ClusteredByProperty>),
731    DictProperty(Box<DictProperty>),
732    DictRange(Box<DictRange>),
733    OnCluster(Box<OnCluster>),
734    LikeProperty(Box<LikeProperty>),
735    LocationProperty(Box<LocationProperty>),
736    LockProperty(Box<LockProperty>),
737    LockingProperty(Box<LockingProperty>),
738    LogProperty(Box<LogProperty>),
739    MaterializedProperty(Box<MaterializedProperty>),
740    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
741    OnProperty(Box<OnProperty>),
742    OnCommitProperty(Box<OnCommitProperty>),
743    PartitionedByProperty(Box<PartitionedByProperty>),
744    PartitionByProperty(Box<PartitionByProperty>),
745    PartitionedByBucket(Box<PartitionedByBucket>),
746    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
747    PartitionByTruncate(Box<PartitionByTruncate>),
748    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
749    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
750    PartitionByListProperty(Box<PartitionByListProperty>),
751    PartitionList(Box<PartitionList>),
752    Partition(Box<Partition>),
753    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
754    UniqueKeyProperty(Box<UniqueKeyProperty>),
755    RollupProperty(Box<RollupProperty>),
756    PartitionBoundSpec(Box<PartitionBoundSpec>),
757    PartitionedOfProperty(Box<PartitionedOfProperty>),
758    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
759    ReturnsProperty(Box<ReturnsProperty>),
760    RowFormatProperty(Box<RowFormatProperty>),
761    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
762    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
763    QueryTransform(Box<QueryTransform>),
764    SampleProperty(Box<SampleProperty>),
765    SecurityProperty(Box<SecurityProperty>),
766    SchemaCommentProperty(Box<SchemaCommentProperty>),
767    SemanticView(Box<SemanticView>),
768    SerdeProperties(Box<SerdeProperties>),
769    SetProperty(Box<SetProperty>),
770    SharingProperty(Box<SharingProperty>),
771    SetConfigProperty(Box<SetConfigProperty>),
772    SettingsProperty(Box<SettingsProperty>),
773    SortKeyProperty(Box<SortKeyProperty>),
774    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
775    SqlSecurityProperty(Box<SqlSecurityProperty>),
776    StabilityProperty(Box<StabilityProperty>),
777    StorageHandlerProperty(Box<StorageHandlerProperty>),
778    TemporaryProperty(Box<TemporaryProperty>),
779    Tags(Box<Tags>),
780    TransformModelProperty(Box<TransformModelProperty>),
781    TransientProperty(Box<TransientProperty>),
782    UsingTemplateProperty(Box<UsingTemplateProperty>),
783    ViewAttributeProperty(Box<ViewAttributeProperty>),
784    VolatileProperty(Box<VolatileProperty>),
785    WithDataProperty(Box<WithDataProperty>),
786    WithJournalTableProperty(Box<WithJournalTableProperty>),
787    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
788    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
789    WithProcedureOptions(Box<WithProcedureOptions>),
790    EncodeProperty(Box<EncodeProperty>),
791    IncludeProperty(Box<IncludeProperty>),
792    Properties(Box<Properties>),
793    OptionsProperty(Box<OptionsProperty>),
794    InputOutputFormat(Box<InputOutputFormat>),
795    Reference(Box<Reference>),
796    QueryOption(Box<QueryOption>),
797    WithTableHint(Box<WithTableHint>),
798    IndexTableHint(Box<IndexTableHint>),
799    HistoricalData(Box<HistoricalData>),
800    Get(Box<Get>),
801    SetOperation(Box<SetOperation>),
802    Var(Box<Var>),
803    Variadic(Box<Variadic>),
804    Version(Box<Version>),
805    Schema(Box<Schema>),
806    Lock(Box<Lock>),
807    TableSample(Box<TableSample>),
808    Tag(Box<Tag>),
809    UnpivotColumns(Box<UnpivotColumns>),
810    WindowSpec(Box<WindowSpec>),
811    SessionParameter(Box<SessionParameter>),
812    PseudoType(Box<PseudoType>),
813    ObjectIdentifier(Box<ObjectIdentifier>),
814    Transaction(Box<Transaction>),
815    Commit(Box<Commit>),
816    Rollback(Box<Rollback>),
817    AlterSession(Box<AlterSession>),
818    Analyze(Box<Analyze>),
819    AnalyzeStatistics(Box<AnalyzeStatistics>),
820    AnalyzeHistogram(Box<AnalyzeHistogram>),
821    AnalyzeSample(Box<AnalyzeSample>),
822    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
823    AnalyzeDelete(Box<AnalyzeDelete>),
824    AnalyzeWith(Box<AnalyzeWith>),
825    AnalyzeValidate(Box<AnalyzeValidate>),
826    AddPartition(Box<AddPartition>),
827    AttachOption(Box<AttachOption>),
828    DropPartition(Box<DropPartition>),
829    ReplacePartition(Box<ReplacePartition>),
830    DPipe(Box<DPipe>),
831    Operator(Box<Operator>),
832    PivotAny(Box<PivotAny>),
833    Aliases(Box<Aliases>),
834    AtIndex(Box<AtIndex>),
835    FromTimeZone(Box<FromTimeZone>),
836    FormatPhrase(Box<FormatPhrase>),
837    ForIn(Box<ForIn>),
838    TimeUnit(Box<TimeUnit>),
839    IntervalOp(Box<IntervalOp>),
840    IntervalSpan(Box<IntervalSpan>),
841    HavingMax(Box<HavingMax>),
842    CosineDistance(Box<CosineDistance>),
843    DotProduct(Box<DotProduct>),
844    EuclideanDistance(Box<EuclideanDistance>),
845    ManhattanDistance(Box<ManhattanDistance>),
846    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
847    Booland(Box<Booland>),
848    Boolor(Box<Boolor>),
849    ParameterizedAgg(Box<ParameterizedAgg>),
850    ArgMax(Box<ArgMax>),
851    ArgMin(Box<ArgMin>),
852    ApproxTopK(Box<ApproxTopK>),
853    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
854    ApproxTopKCombine(Box<ApproxTopKCombine>),
855    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
856    ApproxTopSum(Box<ApproxTopSum>),
857    ApproxQuantiles(Box<ApproxQuantiles>),
858    Minhash(Box<Minhash>),
859    FarmFingerprint(Box<FarmFingerprint>),
860    Float64(Box<Float64>),
861    Transform(Box<Transform>),
862    Translate(Box<Translate>),
863    Grouping(Box<Grouping>),
864    GroupingId(Box<GroupingId>),
865    Anonymous(Box<Anonymous>),
866    AnonymousAggFunc(Box<AnonymousAggFunc>),
867    CombinedAggFunc(Box<CombinedAggFunc>),
868    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
869    HashAgg(Box<HashAgg>),
870    Hll(Box<Hll>),
871    Apply(Box<Apply>),
872    ToBoolean(Box<ToBoolean>),
873    List(Box<List>),
874    ToMap(Box<ToMap>),
875    Pad(Box<Pad>),
876    ToChar(Box<ToChar>),
877    ToNumber(Box<ToNumber>),
878    ToDouble(Box<ToDouble>),
879    Int64(Box<UnaryFunc>),
880    StringFunc(Box<StringFunc>),
881    ToDecfloat(Box<ToDecfloat>),
882    TryToDecfloat(Box<TryToDecfloat>),
883    ToFile(Box<ToFile>),
884    Columns(Box<Columns>),
885    ConvertToCharset(Box<ConvertToCharset>),
886    ConvertTimezone(Box<ConvertTimezone>),
887    GenerateSeries(Box<GenerateSeries>),
888    AIAgg(Box<AIAgg>),
889    AIClassify(Box<AIClassify>),
890    ArrayAll(Box<ArrayAll>),
891    ArrayAny(Box<ArrayAny>),
892    ArrayConstructCompact(Box<ArrayConstructCompact>),
893    StPoint(Box<StPoint>),
894    StDistance(Box<StDistance>),
895    StringToArray(Box<StringToArray>),
896    ArraySum(Box<ArraySum>),
897    ObjectAgg(Box<ObjectAgg>),
898    CastToStrType(Box<CastToStrType>),
899    CheckJson(Box<CheckJson>),
900    CheckXml(Box<CheckXml>),
901    TranslateCharacters(Box<TranslateCharacters>),
902    CurrentSchemas(Box<CurrentSchemas>),
903    CurrentDatetime(Box<CurrentDatetime>),
904    Localtime(Box<Localtime>),
905    Localtimestamp(Box<Localtimestamp>),
906    Systimestamp(Box<Systimestamp>),
907    CurrentSchema(Box<CurrentSchema>),
908    CurrentUser(Box<CurrentUser>),
909    UtcTime(Box<UtcTime>),
910    UtcTimestamp(Box<UtcTimestamp>),
911    Timestamp(Box<TimestampFunc>),
912    DateBin(Box<DateBin>),
913    Datetime(Box<Datetime>),
914    DatetimeAdd(Box<DatetimeAdd>),
915    DatetimeSub(Box<DatetimeSub>),
916    DatetimeDiff(Box<DatetimeDiff>),
917    DatetimeTrunc(Box<DatetimeTrunc>),
918    Dayname(Box<Dayname>),
919    MakeInterval(Box<MakeInterval>),
920    PreviousDay(Box<PreviousDay>),
921    Elt(Box<Elt>),
922    TimestampAdd(Box<TimestampAdd>),
923    TimestampSub(Box<TimestampSub>),
924    TimestampDiff(Box<TimestampDiff>),
925    TimeSlice(Box<TimeSlice>),
926    TimeAdd(Box<TimeAdd>),
927    TimeSub(Box<TimeSub>),
928    TimeDiff(Box<TimeDiff>),
929    TimeTrunc(Box<TimeTrunc>),
930    DateFromParts(Box<DateFromParts>),
931    TimeFromParts(Box<TimeFromParts>),
932    DecodeCase(Box<DecodeCase>),
933    Decrypt(Box<Decrypt>),
934    DecryptRaw(Box<DecryptRaw>),
935    Encode(Box<Encode>),
936    Encrypt(Box<Encrypt>),
937    EncryptRaw(Box<EncryptRaw>),
938    EqualNull(Box<EqualNull>),
939    ToBinary(Box<ToBinary>),
940    Base64DecodeBinary(Box<Base64DecodeBinary>),
941    Base64DecodeString(Box<Base64DecodeString>),
942    Base64Encode(Box<Base64Encode>),
943    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
944    TryBase64DecodeString(Box<TryBase64DecodeString>),
945    GapFill(Box<GapFill>),
946    GenerateDateArray(Box<GenerateDateArray>),
947    GenerateTimestampArray(Box<GenerateTimestampArray>),
948    GetExtract(Box<GetExtract>),
949    Getbit(Box<Getbit>),
950    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
951    HexEncode(Box<HexEncode>),
952    Compress(Box<Compress>),
953    DecompressBinary(Box<DecompressBinary>),
954    DecompressString(Box<DecompressString>),
955    Xor(Box<Xor>),
956    Nullif(Box<Nullif>),
957    JSON(Box<JSON>),
958    JSONPath(Box<JSONPath>),
959    JSONPathFilter(Box<JSONPathFilter>),
960    JSONPathKey(Box<JSONPathKey>),
961    JSONPathRecursive(Box<JSONPathRecursive>),
962    JSONPathScript(Box<JSONPathScript>),
963    JSONPathSlice(Box<JSONPathSlice>),
964    JSONPathSelector(Box<JSONPathSelector>),
965    JSONPathSubscript(Box<JSONPathSubscript>),
966    JSONPathUnion(Box<JSONPathUnion>),
967    Format(Box<Format>),
968    JSONKeys(Box<JSONKeys>),
969    JSONKeyValue(Box<JSONKeyValue>),
970    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
971    JSONObject(Box<JSONObject>),
972    JSONObjectAgg(Box<JSONObjectAgg>),
973    JSONBObjectAgg(Box<JSONBObjectAgg>),
974    JSONArray(Box<JSONArray>),
975    JSONArrayAgg(Box<JSONArrayAgg>),
976    JSONExists(Box<JSONExists>),
977    JSONColumnDef(Box<JSONColumnDef>),
978    JSONSchema(Box<JSONSchema>),
979    JSONSet(Box<JSONSet>),
980    JSONStripNulls(Box<JSONStripNulls>),
981    JSONValue(Box<JSONValue>),
982    JSONValueArray(Box<JSONValueArray>),
983    JSONRemove(Box<JSONRemove>),
984    JSONTable(Box<JSONTable>),
985    JSONType(Box<JSONType>),
986    ObjectInsert(Box<ObjectInsert>),
987    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
988    OpenJSON(Box<OpenJSON>),
989    JSONBExists(Box<JSONBExists>),
990    JSONBContains(Box<BinaryFunc>),
991    JSONBExtract(Box<BinaryFunc>),
992    JSONCast(Box<JSONCast>),
993    JSONExtract(Box<JSONExtract>),
994    JSONExtractQuote(Box<JSONExtractQuote>),
995    JSONExtractArray(Box<JSONExtractArray>),
996    JSONExtractScalar(Box<JSONExtractScalar>),
997    JSONBExtractScalar(Box<JSONBExtractScalar>),
998    JSONFormat(Box<JSONFormat>),
999    JSONBool(Box<UnaryFunc>),
1000    JSONPathRoot(JSONPathRoot),
1001    JSONArrayAppend(Box<JSONArrayAppend>),
1002    JSONArrayContains(Box<JSONArrayContains>),
1003    JSONArrayInsert(Box<JSONArrayInsert>),
1004    ParseJSON(Box<ParseJSON>),
1005    ParseUrl(Box<ParseUrl>),
1006    ParseIp(Box<ParseIp>),
1007    ParseTime(Box<ParseTime>),
1008    ParseDatetime(Box<ParseDatetime>),
1009    Map(Box<Map>),
1010    MapCat(Box<MapCat>),
1011    MapDelete(Box<MapDelete>),
1012    MapInsert(Box<MapInsert>),
1013    MapPick(Box<MapPick>),
1014    ScopeResolution(Box<ScopeResolution>),
1015    Slice(Box<Slice>),
1016    VarMap(Box<VarMap>),
1017    MatchAgainst(Box<MatchAgainst>),
1018    MD5Digest(Box<MD5Digest>),
1019    MD5NumberLower64(Box<UnaryFunc>),
1020    MD5NumberUpper64(Box<UnaryFunc>),
1021    Monthname(Box<Monthname>),
1022    Ntile(Box<Ntile>),
1023    Normalize(Box<Normalize>),
1024    Normal(Box<Normal>),
1025    Predict(Box<Predict>),
1026    MLTranslate(Box<MLTranslate>),
1027    FeaturesAtTime(Box<FeaturesAtTime>),
1028    GenerateEmbedding(Box<GenerateEmbedding>),
1029    MLForecast(Box<MLForecast>),
1030    ModelAttribute(Box<ModelAttribute>),
1031    VectorSearch(Box<VectorSearch>),
1032    Quantile(Box<Quantile>),
1033    ApproxQuantile(Box<ApproxQuantile>),
1034    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1035    Randn(Box<Randn>),
1036    Randstr(Box<Randstr>),
1037    RangeN(Box<RangeN>),
1038    RangeBucket(Box<RangeBucket>),
1039    ReadCSV(Box<ReadCSV>),
1040    ReadParquet(Box<ReadParquet>),
1041    Reduce(Box<Reduce>),
1042    RegexpExtractAll(Box<RegexpExtractAll>),
1043    RegexpILike(Box<RegexpILike>),
1044    RegexpFullMatch(Box<RegexpFullMatch>),
1045    RegexpInstr(Box<RegexpInstr>),
1046    RegexpSplit(Box<RegexpSplit>),
1047    RegexpCount(Box<RegexpCount>),
1048    RegrValx(Box<RegrValx>),
1049    RegrValy(Box<RegrValy>),
1050    RegrAvgy(Box<RegrAvgy>),
1051    RegrAvgx(Box<RegrAvgx>),
1052    RegrCount(Box<RegrCount>),
1053    RegrIntercept(Box<RegrIntercept>),
1054    RegrR2(Box<RegrR2>),
1055    RegrSxx(Box<RegrSxx>),
1056    RegrSxy(Box<RegrSxy>),
1057    RegrSyy(Box<RegrSyy>),
1058    RegrSlope(Box<RegrSlope>),
1059    SafeAdd(Box<SafeAdd>),
1060    SafeDivide(Box<SafeDivide>),
1061    SafeMultiply(Box<SafeMultiply>),
1062    SafeSubtract(Box<SafeSubtract>),
1063    SHA2(Box<SHA2>),
1064    SHA2Digest(Box<SHA2Digest>),
1065    SortArray(Box<SortArray>),
1066    SplitPart(Box<SplitPart>),
1067    SubstringIndex(Box<SubstringIndex>),
1068    StandardHash(Box<StandardHash>),
1069    StrPosition(Box<StrPosition>),
1070    Search(Box<Search>),
1071    SearchIp(Box<SearchIp>),
1072    StrToDate(Box<StrToDate>),
1073    DateStrToDate(Box<UnaryFunc>),
1074    DateToDateStr(Box<UnaryFunc>),
1075    StrToTime(Box<StrToTime>),
1076    StrToUnix(Box<StrToUnix>),
1077    StrToMap(Box<StrToMap>),
1078    NumberToStr(Box<NumberToStr>),
1079    FromBase(Box<FromBase>),
1080    Stuff(Box<Stuff>),
1081    TimeToStr(Box<TimeToStr>),
1082    TimeStrToTime(Box<TimeStrToTime>),
1083    TsOrDsAdd(Box<TsOrDsAdd>),
1084    TsOrDsDiff(Box<TsOrDsDiff>),
1085    TsOrDsToDate(Box<TsOrDsToDate>),
1086    TsOrDsToTime(Box<TsOrDsToTime>),
1087    Unhex(Box<Unhex>),
1088    Uniform(Box<Uniform>),
1089    UnixToStr(Box<UnixToStr>),
1090    UnixToTime(Box<UnixToTime>),
1091    Uuid(Box<Uuid>),
1092    TimestampFromParts(Box<TimestampFromParts>),
1093    TimestampTzFromParts(Box<TimestampTzFromParts>),
1094    Corr(Box<Corr>),
1095    WidthBucket(Box<WidthBucket>),
1096    CovarSamp(Box<CovarSamp>),
1097    CovarPop(Box<CovarPop>),
1098    Week(Box<Week>),
1099    XMLElement(Box<XMLElement>),
1100    XMLGet(Box<XMLGet>),
1101    XMLTable(Box<XMLTable>),
1102    XMLKeyValueOption(Box<XMLKeyValueOption>),
1103    Zipf(Box<Zipf>),
1104    Merge(Box<Merge>),
1105    When(Box<When>),
1106    Whens(Box<Whens>),
1107    NextValueFor(Box<NextValueFor>),
1108    /// RETURN statement (DuckDB stored procedures)
1109    ReturnStmt(Box<Expression>),
1110}
1111
1112impl Expression {
1113    /// Create a `Column` variant, boxing the value automatically.
1114    #[inline]
1115    pub fn boxed_column(col: Column) -> Self {
1116        Expression::Column(Box::new(col))
1117    }
1118
1119    /// Create a `Table` variant, boxing the value automatically.
1120    #[inline]
1121    pub fn boxed_table(t: TableRef) -> Self {
1122        Expression::Table(Box::new(t))
1123    }
1124
1125    /// Returns `true` if this expression is a valid top-level SQL statement.
1126    ///
1127    /// Bare expressions like identifiers, literals, and function calls are not
1128    /// valid statements. This is used by `validate()` to reject inputs like
1129    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1130    /// plus the bare identifier `doo`.
1131    pub fn is_statement(&self) -> bool {
1132        match self {
1133            // Queries
1134            Expression::Select(_)
1135            | Expression::Union(_)
1136            | Expression::Intersect(_)
1137            | Expression::Except(_)
1138            | Expression::Subquery(_)
1139            | Expression::Values(_)
1140            | Expression::PipeOperator(_)
1141
1142            // DML
1143            | Expression::Insert(_)
1144            | Expression::Update(_)
1145            | Expression::Delete(_)
1146            | Expression::Copy(_)
1147            | Expression::Put(_)
1148            | Expression::Merge(_)
1149
1150            // DDL
1151            | Expression::CreateTable(_)
1152            | Expression::DropTable(_)
1153            | Expression::Undrop(_)
1154            | Expression::AlterTable(_)
1155            | Expression::CreateIndex(_)
1156            | Expression::DropIndex(_)
1157            | Expression::CreateView(_)
1158            | Expression::DropView(_)
1159            | Expression::AlterView(_)
1160            | Expression::AlterIndex(_)
1161            | Expression::Truncate(_)
1162            | Expression::TruncateTable(_)
1163            | Expression::CreateSchema(_)
1164            | Expression::DropSchema(_)
1165            | Expression::DropNamespace(_)
1166            | Expression::CreateDatabase(_)
1167            | Expression::DropDatabase(_)
1168            | Expression::CreateFunction(_)
1169            | Expression::DropFunction(_)
1170            | Expression::CreateProcedure(_)
1171            | Expression::DropProcedure(_)
1172            | Expression::CreateSequence(_)
1173            | Expression::CreateSynonym(_)
1174            | Expression::DropSequence(_)
1175            | Expression::AlterSequence(_)
1176            | Expression::CreateTrigger(_)
1177            | Expression::DropTrigger(_)
1178            | Expression::CreateType(_)
1179            | Expression::DropType(_)
1180            | Expression::Comment(_)
1181
1182            // Session/Transaction/Control
1183            | Expression::Use(_)
1184            | Expression::Set(_)
1185            | Expression::SetStatement(_)
1186            | Expression::Transaction(_)
1187            | Expression::Commit(_)
1188            | Expression::Rollback(_)
1189            | Expression::Grant(_)
1190            | Expression::Revoke(_)
1191            | Expression::Cache(_)
1192            | Expression::Uncache(_)
1193            | Expression::LoadData(_)
1194            | Expression::Pragma(_)
1195            | Expression::Describe(_)
1196            | Expression::Show(_)
1197            | Expression::Kill(_)
1198            | Expression::Execute(_)
1199            | Expression::Declare(_)
1200            | Expression::Refresh(_)
1201            | Expression::AlterSession(_)
1202            | Expression::LockingStatement(_)
1203
1204            // Analyze
1205            | Expression::Analyze(_)
1206            | Expression::AnalyzeStatistics(_)
1207            | Expression::AnalyzeHistogram(_)
1208            | Expression::AnalyzeSample(_)
1209            | Expression::AnalyzeListChainedRows(_)
1210            | Expression::AnalyzeDelete(_)
1211
1212            // Attach/Detach/Install/Summarize
1213            | Expression::Attach(_)
1214            | Expression::Detach(_)
1215            | Expression::Install(_)
1216            | Expression::Summarize(_)
1217
1218            // Pivot at statement level
1219            | Expression::Pivot(_)
1220            | Expression::Unpivot(_)
1221
1222            // Command (raw/unparsed statements)
1223            | Expression::Command(_)
1224            | Expression::Raw(_)
1225            | Expression::CreateTask(_)
1226
1227            // Return statement
1228            | Expression::ReturnStmt(_) => true,
1229
1230            // Annotated wraps another expression with comments — check inner
1231            Expression::Annotated(a) => a.this.is_statement(),
1232
1233            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1234            Expression::Alias(a) => a.this.is_statement(),
1235
1236            // Everything else (identifiers, literals, operators, functions, etc.)
1237            _ => false,
1238        }
1239    }
1240
1241    /// Create a literal number expression from an integer.
1242    pub fn number(n: i64) -> Self {
1243        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1244    }
1245
1246    /// Create a single-quoted literal string expression.
1247    pub fn string(s: impl Into<String>) -> Self {
1248        Expression::Literal(Box::new(Literal::String(s.into())))
1249    }
1250
1251    /// Create a literal number expression from a float.
1252    pub fn float(f: f64) -> Self {
1253        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1254    }
1255
1256    /// Get the inferred type annotation, if present.
1257    ///
1258    /// For value-producing expressions with an `inferred_type` field, returns
1259    /// the stored type. For literals and boolean constants, computes the type
1260    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1261    pub fn inferred_type(&self) -> Option<&DataType> {
1262        match self {
1263            // Structs with inferred_type field
1264            Expression::And(op)
1265            | Expression::Or(op)
1266            | Expression::Add(op)
1267            | Expression::Sub(op)
1268            | Expression::Mul(op)
1269            | Expression::Div(op)
1270            | Expression::Mod(op)
1271            | Expression::Eq(op)
1272            | Expression::Neq(op)
1273            | Expression::Lt(op)
1274            | Expression::Lte(op)
1275            | Expression::Gt(op)
1276            | Expression::Gte(op)
1277            | Expression::Concat(op)
1278            | Expression::BitwiseAnd(op)
1279            | Expression::BitwiseOr(op)
1280            | Expression::BitwiseXor(op)
1281            | Expression::Adjacent(op)
1282            | Expression::TsMatch(op)
1283            | Expression::PropertyEQ(op)
1284            | Expression::ArrayContainsAll(op)
1285            | Expression::ArrayContainedBy(op)
1286            | Expression::ArrayOverlaps(op)
1287            | Expression::JSONBContainsAllTopKeys(op)
1288            | Expression::JSONBContainsAnyTopKeys(op)
1289            | Expression::JSONBDeleteAtPath(op)
1290            | Expression::ExtendsLeft(op)
1291            | Expression::ExtendsRight(op)
1292            | Expression::Is(op)
1293            | Expression::MemberOf(op)
1294            | Expression::Match(op)
1295            | Expression::NullSafeEq(op)
1296            | Expression::NullSafeNeq(op)
1297            | Expression::Glob(op)
1298            | Expression::BitwiseLeftShift(op)
1299            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1300
1301            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1302                op.inferred_type.as_ref()
1303            }
1304
1305            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1306
1307            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1308                c.inferred_type.as_ref()
1309            }
1310
1311            Expression::Column(c) => c.inferred_type.as_ref(),
1312            Expression::Function(f) => f.inferred_type.as_ref(),
1313            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1314            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1315            Expression::Case(c) => c.inferred_type.as_ref(),
1316            Expression::Subquery(s) => s.inferred_type.as_ref(),
1317            Expression::Alias(a) => a.inferred_type.as_ref(),
1318            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1319            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1320            Expression::Count(f) => f.inferred_type.as_ref(),
1321            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1322            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1323            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1324            Expression::SumIf(f) => f.inferred_type.as_ref(),
1325
1326            // UnaryFunc variants
1327            Expression::Upper(f)
1328            | Expression::Lower(f)
1329            | Expression::Length(f)
1330            | Expression::LTrim(f)
1331            | Expression::RTrim(f)
1332            | Expression::Reverse(f)
1333            | Expression::Abs(f)
1334            | Expression::Sqrt(f)
1335            | Expression::Cbrt(f)
1336            | Expression::Ln(f)
1337            | Expression::Exp(f)
1338            | Expression::Sign(f)
1339            | Expression::Date(f)
1340            | Expression::Time(f)
1341            | Expression::Initcap(f)
1342            | Expression::Ascii(f)
1343            | Expression::Chr(f)
1344            | Expression::Soundex(f)
1345            | Expression::ByteLength(f)
1346            | Expression::Hex(f)
1347            | Expression::LowerHex(f)
1348            | Expression::Unicode(f)
1349            | Expression::Typeof(f)
1350            | Expression::Explode(f)
1351            | Expression::ExplodeOuter(f)
1352            | Expression::MapFromEntries(f)
1353            | Expression::MapKeys(f)
1354            | Expression::MapValues(f)
1355            | Expression::ArrayLength(f)
1356            | Expression::ArraySize(f)
1357            | Expression::Cardinality(f)
1358            | Expression::ArrayReverse(f)
1359            | Expression::ArrayDistinct(f)
1360            | Expression::ArrayFlatten(f)
1361            | Expression::ArrayCompact(f)
1362            | Expression::ToArray(f)
1363            | Expression::JsonArrayLength(f)
1364            | Expression::JsonKeys(f)
1365            | Expression::JsonType(f)
1366            | Expression::ParseJson(f)
1367            | Expression::ToJson(f)
1368            | Expression::Radians(f)
1369            | Expression::Degrees(f)
1370            | Expression::Sin(f)
1371            | Expression::Cos(f)
1372            | Expression::Tan(f)
1373            | Expression::Asin(f)
1374            | Expression::Acos(f)
1375            | Expression::Atan(f)
1376            | Expression::IsNan(f)
1377            | Expression::IsInf(f)
1378            | Expression::Year(f)
1379            | Expression::Month(f)
1380            | Expression::Day(f)
1381            | Expression::Hour(f)
1382            | Expression::Minute(f)
1383            | Expression::Second(f)
1384            | Expression::DayOfWeek(f)
1385            | Expression::DayOfWeekIso(f)
1386            | Expression::DayOfMonth(f)
1387            | Expression::DayOfYear(f)
1388            | Expression::WeekOfYear(f)
1389            | Expression::Quarter(f)
1390            | Expression::Epoch(f)
1391            | Expression::EpochMs(f)
1392            | Expression::BitwiseCount(f)
1393            | Expression::DateFromUnixDate(f)
1394            | Expression::UnixDate(f)
1395            | Expression::UnixSeconds(f)
1396            | Expression::UnixMillis(f)
1397            | Expression::UnixMicros(f)
1398            | Expression::TimeStrToDate(f)
1399            | Expression::DateToDi(f)
1400            | Expression::DiToDate(f)
1401            | Expression::TsOrDiToDi(f)
1402            | Expression::TsOrDsToDatetime(f)
1403            | Expression::TsOrDsToTimestamp(f)
1404            | Expression::YearOfWeek(f)
1405            | Expression::YearOfWeekIso(f)
1406            | Expression::SHA(f)
1407            | Expression::SHA1Digest(f)
1408            | Expression::TimeToUnix(f)
1409            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1410
1411            // BinaryFunc variants
1412            Expression::Power(f)
1413            | Expression::NullIf(f)
1414            | Expression::IfNull(f)
1415            | Expression::Nvl(f)
1416            | Expression::Contains(f)
1417            | Expression::StartsWith(f)
1418            | Expression::EndsWith(f)
1419            | Expression::Levenshtein(f)
1420            | Expression::ModFunc(f)
1421            | Expression::IntDiv(f)
1422            | Expression::Atan2(f)
1423            | Expression::AddMonths(f)
1424            | Expression::MonthsBetween(f)
1425            | Expression::NextDay(f)
1426            | Expression::UnixToTimeStr(f)
1427            | Expression::ArrayContains(f)
1428            | Expression::ArrayPosition(f)
1429            | Expression::ArrayAppend(f)
1430            | Expression::ArrayPrepend(f)
1431            | Expression::ArrayUnion(f)
1432            | Expression::ArrayExcept(f)
1433            | Expression::ArrayRemove(f)
1434            | Expression::StarMap(f)
1435            | Expression::MapFromArrays(f)
1436            | Expression::MapContainsKey(f)
1437            | Expression::ElementAt(f)
1438            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1439
1440            // VarArgFunc variants
1441            Expression::Coalesce(f)
1442            | Expression::Greatest(f)
1443            | Expression::Least(f)
1444            | Expression::ArrayConcat(f)
1445            | Expression::ArrayIntersect(f)
1446            | Expression::ArrayZip(f)
1447            | Expression::MapConcat(f)
1448            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1449
1450            // AggFunc variants
1451            Expression::Sum(f)
1452            | Expression::Avg(f)
1453            | Expression::Min(f)
1454            | Expression::Max(f)
1455            | Expression::ArrayAgg(f)
1456            | Expression::CountIf(f)
1457            | Expression::Stddev(f)
1458            | Expression::StddevPop(f)
1459            | Expression::StddevSamp(f)
1460            | Expression::Variance(f)
1461            | Expression::VarPop(f)
1462            | Expression::VarSamp(f)
1463            | Expression::Median(f)
1464            | Expression::Mode(f)
1465            | Expression::First(f)
1466            | Expression::Last(f)
1467            | Expression::AnyValue(f)
1468            | Expression::ApproxDistinct(f)
1469            | Expression::ApproxCountDistinct(f)
1470            | Expression::LogicalAnd(f)
1471            | Expression::LogicalOr(f)
1472            | Expression::Skewness(f)
1473            | Expression::ArrayConcatAgg(f)
1474            | Expression::ArrayUniqueAgg(f)
1475            | Expression::BoolXorAgg(f)
1476            | Expression::BitwiseAndAgg(f)
1477            | Expression::BitwiseOrAgg(f)
1478            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1479
1480            // Everything else: no inferred_type field
1481            _ => None,
1482        }
1483    }
1484
1485    /// Set the inferred type annotation on this expression.
1486    ///
1487    /// Only has an effect on value-producing expressions with an `inferred_type`
1488    /// field. For other expression types, this is a no-op.
1489    pub fn set_inferred_type(&mut self, dt: DataType) {
1490        match self {
1491            Expression::And(op)
1492            | Expression::Or(op)
1493            | Expression::Add(op)
1494            | Expression::Sub(op)
1495            | Expression::Mul(op)
1496            | Expression::Div(op)
1497            | Expression::Mod(op)
1498            | Expression::Eq(op)
1499            | Expression::Neq(op)
1500            | Expression::Lt(op)
1501            | Expression::Lte(op)
1502            | Expression::Gt(op)
1503            | Expression::Gte(op)
1504            | Expression::Concat(op)
1505            | Expression::BitwiseAnd(op)
1506            | Expression::BitwiseOr(op)
1507            | Expression::BitwiseXor(op)
1508            | Expression::Adjacent(op)
1509            | Expression::TsMatch(op)
1510            | Expression::PropertyEQ(op)
1511            | Expression::ArrayContainsAll(op)
1512            | Expression::ArrayContainedBy(op)
1513            | Expression::ArrayOverlaps(op)
1514            | Expression::JSONBContainsAllTopKeys(op)
1515            | Expression::JSONBContainsAnyTopKeys(op)
1516            | Expression::JSONBDeleteAtPath(op)
1517            | Expression::ExtendsLeft(op)
1518            | Expression::ExtendsRight(op)
1519            | Expression::Is(op)
1520            | Expression::MemberOf(op)
1521            | Expression::Match(op)
1522            | Expression::NullSafeEq(op)
1523            | Expression::NullSafeNeq(op)
1524            | Expression::Glob(op)
1525            | Expression::BitwiseLeftShift(op)
1526            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1527
1528            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1529                op.inferred_type = Some(dt)
1530            }
1531
1532            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1533
1534            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1535                c.inferred_type = Some(dt)
1536            }
1537
1538            Expression::Column(c) => c.inferred_type = Some(dt),
1539            Expression::Function(f) => f.inferred_type = Some(dt),
1540            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1541            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1542            Expression::Case(c) => c.inferred_type = Some(dt),
1543            Expression::Subquery(s) => s.inferred_type = Some(dt),
1544            Expression::Alias(a) => a.inferred_type = Some(dt),
1545            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1546            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1547            Expression::Count(f) => f.inferred_type = Some(dt),
1548            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1549            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1550            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1551            Expression::SumIf(f) => f.inferred_type = Some(dt),
1552
1553            // UnaryFunc variants
1554            Expression::Upper(f)
1555            | Expression::Lower(f)
1556            | Expression::Length(f)
1557            | Expression::LTrim(f)
1558            | Expression::RTrim(f)
1559            | Expression::Reverse(f)
1560            | Expression::Abs(f)
1561            | Expression::Sqrt(f)
1562            | Expression::Cbrt(f)
1563            | Expression::Ln(f)
1564            | Expression::Exp(f)
1565            | Expression::Sign(f)
1566            | Expression::Date(f)
1567            | Expression::Time(f)
1568            | Expression::Initcap(f)
1569            | Expression::Ascii(f)
1570            | Expression::Chr(f)
1571            | Expression::Soundex(f)
1572            | Expression::ByteLength(f)
1573            | Expression::Hex(f)
1574            | Expression::LowerHex(f)
1575            | Expression::Unicode(f)
1576            | Expression::Typeof(f)
1577            | Expression::Explode(f)
1578            | Expression::ExplodeOuter(f)
1579            | Expression::MapFromEntries(f)
1580            | Expression::MapKeys(f)
1581            | Expression::MapValues(f)
1582            | Expression::ArrayLength(f)
1583            | Expression::ArraySize(f)
1584            | Expression::Cardinality(f)
1585            | Expression::ArrayReverse(f)
1586            | Expression::ArrayDistinct(f)
1587            | Expression::ArrayFlatten(f)
1588            | Expression::ArrayCompact(f)
1589            | Expression::ToArray(f)
1590            | Expression::JsonArrayLength(f)
1591            | Expression::JsonKeys(f)
1592            | Expression::JsonType(f)
1593            | Expression::ParseJson(f)
1594            | Expression::ToJson(f)
1595            | Expression::Radians(f)
1596            | Expression::Degrees(f)
1597            | Expression::Sin(f)
1598            | Expression::Cos(f)
1599            | Expression::Tan(f)
1600            | Expression::Asin(f)
1601            | Expression::Acos(f)
1602            | Expression::Atan(f)
1603            | Expression::IsNan(f)
1604            | Expression::IsInf(f)
1605            | Expression::Year(f)
1606            | Expression::Month(f)
1607            | Expression::Day(f)
1608            | Expression::Hour(f)
1609            | Expression::Minute(f)
1610            | Expression::Second(f)
1611            | Expression::DayOfWeek(f)
1612            | Expression::DayOfWeekIso(f)
1613            | Expression::DayOfMonth(f)
1614            | Expression::DayOfYear(f)
1615            | Expression::WeekOfYear(f)
1616            | Expression::Quarter(f)
1617            | Expression::Epoch(f)
1618            | Expression::EpochMs(f)
1619            | Expression::BitwiseCount(f)
1620            | Expression::DateFromUnixDate(f)
1621            | Expression::UnixDate(f)
1622            | Expression::UnixSeconds(f)
1623            | Expression::UnixMillis(f)
1624            | Expression::UnixMicros(f)
1625            | Expression::TimeStrToDate(f)
1626            | Expression::DateToDi(f)
1627            | Expression::DiToDate(f)
1628            | Expression::TsOrDiToDi(f)
1629            | Expression::TsOrDsToDatetime(f)
1630            | Expression::TsOrDsToTimestamp(f)
1631            | Expression::YearOfWeek(f)
1632            | Expression::YearOfWeekIso(f)
1633            | Expression::SHA(f)
1634            | Expression::SHA1Digest(f)
1635            | Expression::TimeToUnix(f)
1636            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1637
1638            // BinaryFunc variants
1639            Expression::Power(f)
1640            | Expression::NullIf(f)
1641            | Expression::IfNull(f)
1642            | Expression::Nvl(f)
1643            | Expression::Contains(f)
1644            | Expression::StartsWith(f)
1645            | Expression::EndsWith(f)
1646            | Expression::Levenshtein(f)
1647            | Expression::ModFunc(f)
1648            | Expression::IntDiv(f)
1649            | Expression::Atan2(f)
1650            | Expression::AddMonths(f)
1651            | Expression::MonthsBetween(f)
1652            | Expression::NextDay(f)
1653            | Expression::UnixToTimeStr(f)
1654            | Expression::ArrayContains(f)
1655            | Expression::ArrayPosition(f)
1656            | Expression::ArrayAppend(f)
1657            | Expression::ArrayPrepend(f)
1658            | Expression::ArrayUnion(f)
1659            | Expression::ArrayExcept(f)
1660            | Expression::ArrayRemove(f)
1661            | Expression::StarMap(f)
1662            | Expression::MapFromArrays(f)
1663            | Expression::MapContainsKey(f)
1664            | Expression::ElementAt(f)
1665            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1666
1667            // VarArgFunc variants
1668            Expression::Coalesce(f)
1669            | Expression::Greatest(f)
1670            | Expression::Least(f)
1671            | Expression::ArrayConcat(f)
1672            | Expression::ArrayIntersect(f)
1673            | Expression::ArrayZip(f)
1674            | Expression::MapConcat(f)
1675            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1676
1677            // AggFunc variants
1678            Expression::Sum(f)
1679            | Expression::Avg(f)
1680            | Expression::Min(f)
1681            | Expression::Max(f)
1682            | Expression::ArrayAgg(f)
1683            | Expression::CountIf(f)
1684            | Expression::Stddev(f)
1685            | Expression::StddevPop(f)
1686            | Expression::StddevSamp(f)
1687            | Expression::Variance(f)
1688            | Expression::VarPop(f)
1689            | Expression::VarSamp(f)
1690            | Expression::Median(f)
1691            | Expression::Mode(f)
1692            | Expression::First(f)
1693            | Expression::Last(f)
1694            | Expression::AnyValue(f)
1695            | Expression::ApproxDistinct(f)
1696            | Expression::ApproxCountDistinct(f)
1697            | Expression::LogicalAnd(f)
1698            | Expression::LogicalOr(f)
1699            | Expression::Skewness(f)
1700            | Expression::ArrayConcatAgg(f)
1701            | Expression::ArrayUniqueAgg(f)
1702            | Expression::BoolXorAgg(f)
1703            | Expression::BitwiseAndAgg(f)
1704            | Expression::BitwiseOrAgg(f)
1705            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1706
1707            // Expressions without inferred_type field - no-op
1708            _ => {}
1709        }
1710    }
1711
1712    /// Create an unqualified column reference (e.g. `name`).
1713    pub fn column(name: impl Into<String>) -> Self {
1714        Expression::Column(Box::new(Column {
1715            name: Identifier::new(name),
1716            table: None,
1717            join_mark: false,
1718            trailing_comments: Vec::new(),
1719            span: None,
1720            inferred_type: None,
1721        }))
1722    }
1723
1724    /// Create a qualified column reference (`table.column`).
1725    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1726        Expression::Column(Box::new(Column {
1727            name: Identifier::new(column),
1728            table: Some(Identifier::new(table)),
1729            join_mark: false,
1730            trailing_comments: Vec::new(),
1731            span: None,
1732            inferred_type: None,
1733        }))
1734    }
1735
1736    /// Create a bare identifier expression (not a column reference).
1737    pub fn identifier(name: impl Into<String>) -> Self {
1738        Expression::Identifier(Identifier::new(name))
1739    }
1740
1741    /// Create a NULL expression
1742    pub fn null() -> Self {
1743        Expression::Null(Null)
1744    }
1745
1746    /// Create a TRUE expression
1747    pub fn true_() -> Self {
1748        Expression::Boolean(BooleanLiteral { value: true })
1749    }
1750
1751    /// Create a FALSE expression
1752    pub fn false_() -> Self {
1753        Expression::Boolean(BooleanLiteral { value: false })
1754    }
1755
1756    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1757    pub fn star() -> Self {
1758        Expression::Star(Star {
1759            table: None,
1760            except: None,
1761            replace: None,
1762            rename: None,
1763            trailing_comments: Vec::new(),
1764            span: None,
1765        })
1766    }
1767
1768    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1769    pub fn alias(self, name: impl Into<String>) -> Self {
1770        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1771    }
1772
1773    /// Check if this is a SELECT expression
1774    pub fn is_select(&self) -> bool {
1775        matches!(self, Expression::Select(_))
1776    }
1777
1778    /// Try to get as a Select
1779    pub fn as_select(&self) -> Option<&Select> {
1780        match self {
1781            Expression::Select(s) => Some(s),
1782            _ => None,
1783        }
1784    }
1785
1786    /// Try to get as a mutable Select
1787    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1788        match self {
1789            Expression::Select(s) => Some(s),
1790            _ => None,
1791        }
1792    }
1793
1794    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1795    ///
1796    /// Returns an empty string if generation fails. For dialect-specific output,
1797    /// use [`sql_for()`](Self::sql_for) instead.
1798    pub fn sql(&self) -> String {
1799        crate::generator::Generator::sql(self).unwrap_or_default()
1800    }
1801
1802    /// Generate a SQL string for this expression targeting a specific dialect.
1803    ///
1804    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1805    /// syntax variations) are applied automatically.  Returns an empty string if
1806    /// generation fails.
1807    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1808        crate::generate(self, dialect).unwrap_or_default()
1809    }
1810}
1811
1812// === Python API accessor methods ===
1813
1814impl Expression {
1815    /// Returns the serde-compatible snake_case variant name without serialization.
1816    /// This is much faster than serializing to JSON and extracting the key.
1817    pub fn variant_name(&self) -> &'static str {
1818        match self {
1819            Expression::Literal(_) => "literal",
1820            Expression::Boolean(_) => "boolean",
1821            Expression::Null(_) => "null",
1822            Expression::Identifier(_) => "identifier",
1823            Expression::Column(_) => "column",
1824            Expression::Table(_) => "table",
1825            Expression::Star(_) => "star",
1826            Expression::BracedWildcard(_) => "braced_wildcard",
1827            Expression::Select(_) => "select",
1828            Expression::Union(_) => "union",
1829            Expression::Intersect(_) => "intersect",
1830            Expression::Except(_) => "except",
1831            Expression::Subquery(_) => "subquery",
1832            Expression::PipeOperator(_) => "pipe_operator",
1833            Expression::Pivot(_) => "pivot",
1834            Expression::PivotAlias(_) => "pivot_alias",
1835            Expression::Unpivot(_) => "unpivot",
1836            Expression::Values(_) => "values",
1837            Expression::PreWhere(_) => "pre_where",
1838            Expression::Stream(_) => "stream",
1839            Expression::UsingData(_) => "using_data",
1840            Expression::XmlNamespace(_) => "xml_namespace",
1841            Expression::Insert(_) => "insert",
1842            Expression::Update(_) => "update",
1843            Expression::Delete(_) => "delete",
1844            Expression::Copy(_) => "copy",
1845            Expression::Put(_) => "put",
1846            Expression::StageReference(_) => "stage_reference",
1847            Expression::Alias(_) => "alias",
1848            Expression::Cast(_) => "cast",
1849            Expression::Collation(_) => "collation",
1850            Expression::Case(_) => "case",
1851            Expression::And(_) => "and",
1852            Expression::Or(_) => "or",
1853            Expression::Add(_) => "add",
1854            Expression::Sub(_) => "sub",
1855            Expression::Mul(_) => "mul",
1856            Expression::Div(_) => "div",
1857            Expression::Mod(_) => "mod",
1858            Expression::Eq(_) => "eq",
1859            Expression::Neq(_) => "neq",
1860            Expression::Lt(_) => "lt",
1861            Expression::Lte(_) => "lte",
1862            Expression::Gt(_) => "gt",
1863            Expression::Gte(_) => "gte",
1864            Expression::Like(_) => "like",
1865            Expression::ILike(_) => "i_like",
1866            Expression::Match(_) => "match",
1867            Expression::BitwiseAnd(_) => "bitwise_and",
1868            Expression::BitwiseOr(_) => "bitwise_or",
1869            Expression::BitwiseXor(_) => "bitwise_xor",
1870            Expression::Concat(_) => "concat",
1871            Expression::Adjacent(_) => "adjacent",
1872            Expression::TsMatch(_) => "ts_match",
1873            Expression::PropertyEQ(_) => "property_e_q",
1874            Expression::ArrayContainsAll(_) => "array_contains_all",
1875            Expression::ArrayContainedBy(_) => "array_contained_by",
1876            Expression::ArrayOverlaps(_) => "array_overlaps",
1877            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1878            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1879            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1880            Expression::ExtendsLeft(_) => "extends_left",
1881            Expression::ExtendsRight(_) => "extends_right",
1882            Expression::Not(_) => "not",
1883            Expression::Neg(_) => "neg",
1884            Expression::BitwiseNot(_) => "bitwise_not",
1885            Expression::In(_) => "in",
1886            Expression::Between(_) => "between",
1887            Expression::IsNull(_) => "is_null",
1888            Expression::IsTrue(_) => "is_true",
1889            Expression::IsFalse(_) => "is_false",
1890            Expression::IsJson(_) => "is_json",
1891            Expression::Is(_) => "is",
1892            Expression::Exists(_) => "exists",
1893            Expression::MemberOf(_) => "member_of",
1894            Expression::Function(_) => "function",
1895            Expression::AggregateFunction(_) => "aggregate_function",
1896            Expression::WindowFunction(_) => "window_function",
1897            Expression::From(_) => "from",
1898            Expression::Join(_) => "join",
1899            Expression::JoinedTable(_) => "joined_table",
1900            Expression::Where(_) => "where",
1901            Expression::GroupBy(_) => "group_by",
1902            Expression::Having(_) => "having",
1903            Expression::OrderBy(_) => "order_by",
1904            Expression::Limit(_) => "limit",
1905            Expression::Offset(_) => "offset",
1906            Expression::Qualify(_) => "qualify",
1907            Expression::With(_) => "with",
1908            Expression::Cte(_) => "cte",
1909            Expression::DistributeBy(_) => "distribute_by",
1910            Expression::ClusterBy(_) => "cluster_by",
1911            Expression::SortBy(_) => "sort_by",
1912            Expression::LateralView(_) => "lateral_view",
1913            Expression::Hint(_) => "hint",
1914            Expression::Pseudocolumn(_) => "pseudocolumn",
1915            Expression::Connect(_) => "connect",
1916            Expression::Prior(_) => "prior",
1917            Expression::ConnectByRoot(_) => "connect_by_root",
1918            Expression::MatchRecognize(_) => "match_recognize",
1919            Expression::Ordered(_) => "ordered",
1920            Expression::Window(_) => "window",
1921            Expression::Over(_) => "over",
1922            Expression::WithinGroup(_) => "within_group",
1923            Expression::DataType(_) => "data_type",
1924            Expression::Array(_) => "array",
1925            Expression::Struct(_) => "struct",
1926            Expression::Tuple(_) => "tuple",
1927            Expression::Interval(_) => "interval",
1928            Expression::ConcatWs(_) => "concat_ws",
1929            Expression::Substring(_) => "substring",
1930            Expression::Upper(_) => "upper",
1931            Expression::Lower(_) => "lower",
1932            Expression::Length(_) => "length",
1933            Expression::Trim(_) => "trim",
1934            Expression::LTrim(_) => "l_trim",
1935            Expression::RTrim(_) => "r_trim",
1936            Expression::Replace(_) => "replace",
1937            Expression::Reverse(_) => "reverse",
1938            Expression::Left(_) => "left",
1939            Expression::Right(_) => "right",
1940            Expression::Repeat(_) => "repeat",
1941            Expression::Lpad(_) => "lpad",
1942            Expression::Rpad(_) => "rpad",
1943            Expression::Split(_) => "split",
1944            Expression::RegexpLike(_) => "regexp_like",
1945            Expression::RegexpReplace(_) => "regexp_replace",
1946            Expression::RegexpExtract(_) => "regexp_extract",
1947            Expression::Overlay(_) => "overlay",
1948            Expression::Abs(_) => "abs",
1949            Expression::Round(_) => "round",
1950            Expression::Floor(_) => "floor",
1951            Expression::Ceil(_) => "ceil",
1952            Expression::Power(_) => "power",
1953            Expression::Sqrt(_) => "sqrt",
1954            Expression::Cbrt(_) => "cbrt",
1955            Expression::Ln(_) => "ln",
1956            Expression::Log(_) => "log",
1957            Expression::Exp(_) => "exp",
1958            Expression::Sign(_) => "sign",
1959            Expression::Greatest(_) => "greatest",
1960            Expression::Least(_) => "least",
1961            Expression::CurrentDate(_) => "current_date",
1962            Expression::CurrentTime(_) => "current_time",
1963            Expression::CurrentTimestamp(_) => "current_timestamp",
1964            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1965            Expression::AtTimeZone(_) => "at_time_zone",
1966            Expression::DateAdd(_) => "date_add",
1967            Expression::DateSub(_) => "date_sub",
1968            Expression::DateDiff(_) => "date_diff",
1969            Expression::DateTrunc(_) => "date_trunc",
1970            Expression::Extract(_) => "extract",
1971            Expression::ToDate(_) => "to_date",
1972            Expression::ToTimestamp(_) => "to_timestamp",
1973            Expression::Date(_) => "date",
1974            Expression::Time(_) => "time",
1975            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1976            Expression::UnixDate(_) => "unix_date",
1977            Expression::UnixSeconds(_) => "unix_seconds",
1978            Expression::UnixMillis(_) => "unix_millis",
1979            Expression::UnixMicros(_) => "unix_micros",
1980            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1981            Expression::TimeStrToDate(_) => "time_str_to_date",
1982            Expression::DateToDi(_) => "date_to_di",
1983            Expression::DiToDate(_) => "di_to_date",
1984            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1985            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1986            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1987            Expression::YearOfWeek(_) => "year_of_week",
1988            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1989            Expression::Coalesce(_) => "coalesce",
1990            Expression::NullIf(_) => "null_if",
1991            Expression::IfFunc(_) => "if_func",
1992            Expression::IfNull(_) => "if_null",
1993            Expression::Nvl(_) => "nvl",
1994            Expression::Nvl2(_) => "nvl2",
1995            Expression::TryCast(_) => "try_cast",
1996            Expression::SafeCast(_) => "safe_cast",
1997            Expression::Count(_) => "count",
1998            Expression::Sum(_) => "sum",
1999            Expression::Avg(_) => "avg",
2000            Expression::Min(_) => "min",
2001            Expression::Max(_) => "max",
2002            Expression::GroupConcat(_) => "group_concat",
2003            Expression::StringAgg(_) => "string_agg",
2004            Expression::ListAgg(_) => "list_agg",
2005            Expression::ArrayAgg(_) => "array_agg",
2006            Expression::CountIf(_) => "count_if",
2007            Expression::SumIf(_) => "sum_if",
2008            Expression::Stddev(_) => "stddev",
2009            Expression::StddevPop(_) => "stddev_pop",
2010            Expression::StddevSamp(_) => "stddev_samp",
2011            Expression::Variance(_) => "variance",
2012            Expression::VarPop(_) => "var_pop",
2013            Expression::VarSamp(_) => "var_samp",
2014            Expression::Median(_) => "median",
2015            Expression::Mode(_) => "mode",
2016            Expression::First(_) => "first",
2017            Expression::Last(_) => "last",
2018            Expression::AnyValue(_) => "any_value",
2019            Expression::ApproxDistinct(_) => "approx_distinct",
2020            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2021            Expression::ApproxPercentile(_) => "approx_percentile",
2022            Expression::Percentile(_) => "percentile",
2023            Expression::LogicalAnd(_) => "logical_and",
2024            Expression::LogicalOr(_) => "logical_or",
2025            Expression::Skewness(_) => "skewness",
2026            Expression::BitwiseCount(_) => "bitwise_count",
2027            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2028            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2029            Expression::BoolXorAgg(_) => "bool_xor_agg",
2030            Expression::RowNumber(_) => "row_number",
2031            Expression::Rank(_) => "rank",
2032            Expression::DenseRank(_) => "dense_rank",
2033            Expression::NTile(_) => "n_tile",
2034            Expression::Lead(_) => "lead",
2035            Expression::Lag(_) => "lag",
2036            Expression::FirstValue(_) => "first_value",
2037            Expression::LastValue(_) => "last_value",
2038            Expression::NthValue(_) => "nth_value",
2039            Expression::PercentRank(_) => "percent_rank",
2040            Expression::CumeDist(_) => "cume_dist",
2041            Expression::PercentileCont(_) => "percentile_cont",
2042            Expression::PercentileDisc(_) => "percentile_disc",
2043            Expression::Contains(_) => "contains",
2044            Expression::StartsWith(_) => "starts_with",
2045            Expression::EndsWith(_) => "ends_with",
2046            Expression::Position(_) => "position",
2047            Expression::Initcap(_) => "initcap",
2048            Expression::Ascii(_) => "ascii",
2049            Expression::Chr(_) => "chr",
2050            Expression::CharFunc(_) => "char_func",
2051            Expression::Soundex(_) => "soundex",
2052            Expression::Levenshtein(_) => "levenshtein",
2053            Expression::ByteLength(_) => "byte_length",
2054            Expression::Hex(_) => "hex",
2055            Expression::LowerHex(_) => "lower_hex",
2056            Expression::Unicode(_) => "unicode",
2057            Expression::ModFunc(_) => "mod_func",
2058            Expression::Random(_) => "random",
2059            Expression::Rand(_) => "rand",
2060            Expression::TruncFunc(_) => "trunc_func",
2061            Expression::Pi(_) => "pi",
2062            Expression::Radians(_) => "radians",
2063            Expression::Degrees(_) => "degrees",
2064            Expression::Sin(_) => "sin",
2065            Expression::Cos(_) => "cos",
2066            Expression::Tan(_) => "tan",
2067            Expression::Asin(_) => "asin",
2068            Expression::Acos(_) => "acos",
2069            Expression::Atan(_) => "atan",
2070            Expression::Atan2(_) => "atan2",
2071            Expression::IsNan(_) => "is_nan",
2072            Expression::IsInf(_) => "is_inf",
2073            Expression::IntDiv(_) => "int_div",
2074            Expression::Decode(_) => "decode",
2075            Expression::DateFormat(_) => "date_format",
2076            Expression::FormatDate(_) => "format_date",
2077            Expression::Year(_) => "year",
2078            Expression::Month(_) => "month",
2079            Expression::Day(_) => "day",
2080            Expression::Hour(_) => "hour",
2081            Expression::Minute(_) => "minute",
2082            Expression::Second(_) => "second",
2083            Expression::DayOfWeek(_) => "day_of_week",
2084            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2085            Expression::DayOfMonth(_) => "day_of_month",
2086            Expression::DayOfYear(_) => "day_of_year",
2087            Expression::WeekOfYear(_) => "week_of_year",
2088            Expression::Quarter(_) => "quarter",
2089            Expression::AddMonths(_) => "add_months",
2090            Expression::MonthsBetween(_) => "months_between",
2091            Expression::LastDay(_) => "last_day",
2092            Expression::NextDay(_) => "next_day",
2093            Expression::Epoch(_) => "epoch",
2094            Expression::EpochMs(_) => "epoch_ms",
2095            Expression::FromUnixtime(_) => "from_unixtime",
2096            Expression::UnixTimestamp(_) => "unix_timestamp",
2097            Expression::MakeDate(_) => "make_date",
2098            Expression::MakeTimestamp(_) => "make_timestamp",
2099            Expression::TimestampTrunc(_) => "timestamp_trunc",
2100            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2101            Expression::SessionUser(_) => "session_user",
2102            Expression::SHA(_) => "s_h_a",
2103            Expression::SHA1Digest(_) => "s_h_a1_digest",
2104            Expression::TimeToUnix(_) => "time_to_unix",
2105            Expression::ArrayFunc(_) => "array_func",
2106            Expression::ArrayLength(_) => "array_length",
2107            Expression::ArraySize(_) => "array_size",
2108            Expression::Cardinality(_) => "cardinality",
2109            Expression::ArrayContains(_) => "array_contains",
2110            Expression::ArrayPosition(_) => "array_position",
2111            Expression::ArrayAppend(_) => "array_append",
2112            Expression::ArrayPrepend(_) => "array_prepend",
2113            Expression::ArrayConcat(_) => "array_concat",
2114            Expression::ArraySort(_) => "array_sort",
2115            Expression::ArrayReverse(_) => "array_reverse",
2116            Expression::ArrayDistinct(_) => "array_distinct",
2117            Expression::ArrayJoin(_) => "array_join",
2118            Expression::ArrayToString(_) => "array_to_string",
2119            Expression::Unnest(_) => "unnest",
2120            Expression::Explode(_) => "explode",
2121            Expression::ExplodeOuter(_) => "explode_outer",
2122            Expression::ArrayFilter(_) => "array_filter",
2123            Expression::ArrayTransform(_) => "array_transform",
2124            Expression::ArrayFlatten(_) => "array_flatten",
2125            Expression::ArrayCompact(_) => "array_compact",
2126            Expression::ArrayIntersect(_) => "array_intersect",
2127            Expression::ArrayUnion(_) => "array_union",
2128            Expression::ArrayExcept(_) => "array_except",
2129            Expression::ArrayRemove(_) => "array_remove",
2130            Expression::ArrayZip(_) => "array_zip",
2131            Expression::Sequence(_) => "sequence",
2132            Expression::Generate(_) => "generate",
2133            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2134            Expression::ToArray(_) => "to_array",
2135            Expression::StarMap(_) => "star_map",
2136            Expression::StructFunc(_) => "struct_func",
2137            Expression::StructExtract(_) => "struct_extract",
2138            Expression::NamedStruct(_) => "named_struct",
2139            Expression::MapFunc(_) => "map_func",
2140            Expression::MapFromEntries(_) => "map_from_entries",
2141            Expression::MapFromArrays(_) => "map_from_arrays",
2142            Expression::MapKeys(_) => "map_keys",
2143            Expression::MapValues(_) => "map_values",
2144            Expression::MapContainsKey(_) => "map_contains_key",
2145            Expression::MapConcat(_) => "map_concat",
2146            Expression::ElementAt(_) => "element_at",
2147            Expression::TransformKeys(_) => "transform_keys",
2148            Expression::TransformValues(_) => "transform_values",
2149            Expression::FunctionEmits(_) => "function_emits",
2150            Expression::JsonExtract(_) => "json_extract",
2151            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2152            Expression::JsonExtractPath(_) => "json_extract_path",
2153            Expression::JsonArray(_) => "json_array",
2154            Expression::JsonObject(_) => "json_object",
2155            Expression::JsonQuery(_) => "json_query",
2156            Expression::JsonValue(_) => "json_value",
2157            Expression::JsonArrayLength(_) => "json_array_length",
2158            Expression::JsonKeys(_) => "json_keys",
2159            Expression::JsonType(_) => "json_type",
2160            Expression::ParseJson(_) => "parse_json",
2161            Expression::ToJson(_) => "to_json",
2162            Expression::JsonSet(_) => "json_set",
2163            Expression::JsonInsert(_) => "json_insert",
2164            Expression::JsonRemove(_) => "json_remove",
2165            Expression::JsonMergePatch(_) => "json_merge_patch",
2166            Expression::JsonArrayAgg(_) => "json_array_agg",
2167            Expression::JsonObjectAgg(_) => "json_object_agg",
2168            Expression::Convert(_) => "convert",
2169            Expression::Typeof(_) => "typeof",
2170            Expression::Lambda(_) => "lambda",
2171            Expression::Parameter(_) => "parameter",
2172            Expression::Placeholder(_) => "placeholder",
2173            Expression::NamedArgument(_) => "named_argument",
2174            Expression::TableArgument(_) => "table_argument",
2175            Expression::SqlComment(_) => "sql_comment",
2176            Expression::NullSafeEq(_) => "null_safe_eq",
2177            Expression::NullSafeNeq(_) => "null_safe_neq",
2178            Expression::Glob(_) => "glob",
2179            Expression::SimilarTo(_) => "similar_to",
2180            Expression::Any(_) => "any",
2181            Expression::All(_) => "all",
2182            Expression::Overlaps(_) => "overlaps",
2183            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2184            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2185            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2186            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2187            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2188            Expression::Subscript(_) => "subscript",
2189            Expression::Dot(_) => "dot",
2190            Expression::MethodCall(_) => "method_call",
2191            Expression::ArraySlice(_) => "array_slice",
2192            Expression::CreateTable(_) => "create_table",
2193            Expression::DropTable(_) => "drop_table",
2194            Expression::Undrop(_) => "undrop",
2195            Expression::AlterTable(_) => "alter_table",
2196            Expression::CreateIndex(_) => "create_index",
2197            Expression::DropIndex(_) => "drop_index",
2198            Expression::CreateView(_) => "create_view",
2199            Expression::DropView(_) => "drop_view",
2200            Expression::AlterView(_) => "alter_view",
2201            Expression::AlterIndex(_) => "alter_index",
2202            Expression::Truncate(_) => "truncate",
2203            Expression::Use(_) => "use",
2204            Expression::Cache(_) => "cache",
2205            Expression::Uncache(_) => "uncache",
2206            Expression::LoadData(_) => "load_data",
2207            Expression::Pragma(_) => "pragma",
2208            Expression::Grant(_) => "grant",
2209            Expression::Revoke(_) => "revoke",
2210            Expression::Comment(_) => "comment",
2211            Expression::SetStatement(_) => "set_statement",
2212            Expression::CreateSchema(_) => "create_schema",
2213            Expression::DropSchema(_) => "drop_schema",
2214            Expression::DropNamespace(_) => "drop_namespace",
2215            Expression::CreateDatabase(_) => "create_database",
2216            Expression::DropDatabase(_) => "drop_database",
2217            Expression::CreateFunction(_) => "create_function",
2218            Expression::DropFunction(_) => "drop_function",
2219            Expression::CreateProcedure(_) => "create_procedure",
2220            Expression::DropProcedure(_) => "drop_procedure",
2221            Expression::CreateSequence(_) => "create_sequence",
2222            Expression::CreateSynonym(_) => "create_synonym",
2223            Expression::DropSequence(_) => "drop_sequence",
2224            Expression::AlterSequence(_) => "alter_sequence",
2225            Expression::CreateTrigger(_) => "create_trigger",
2226            Expression::DropTrigger(_) => "drop_trigger",
2227            Expression::CreateType(_) => "create_type",
2228            Expression::DropType(_) => "drop_type",
2229            Expression::Describe(_) => "describe",
2230            Expression::Show(_) => "show",
2231            Expression::Command(_) => "command",
2232            Expression::Kill(_) => "kill",
2233            Expression::Execute(_) => "execute",
2234            Expression::Raw(_) => "raw",
2235            Expression::CreateTask(_) => "create_task",
2236            Expression::Paren(_) => "paren",
2237            Expression::Annotated(_) => "annotated",
2238            Expression::Refresh(_) => "refresh",
2239            Expression::LockingStatement(_) => "locking_statement",
2240            Expression::SequenceProperties(_) => "sequence_properties",
2241            Expression::TruncateTable(_) => "truncate_table",
2242            Expression::Clone(_) => "clone",
2243            Expression::Attach(_) => "attach",
2244            Expression::Detach(_) => "detach",
2245            Expression::Install(_) => "install",
2246            Expression::Summarize(_) => "summarize",
2247            Expression::Declare(_) => "declare",
2248            Expression::DeclareItem(_) => "declare_item",
2249            Expression::Set(_) => "set",
2250            Expression::Heredoc(_) => "heredoc",
2251            Expression::SetItem(_) => "set_item",
2252            Expression::QueryBand(_) => "query_band",
2253            Expression::UserDefinedFunction(_) => "user_defined_function",
2254            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2255            Expression::ProjectionDef(_) => "projection_def",
2256            Expression::TableAlias(_) => "table_alias",
2257            Expression::ByteString(_) => "byte_string",
2258            Expression::HexStringExpr(_) => "hex_string_expr",
2259            Expression::UnicodeString(_) => "unicode_string",
2260            Expression::ColumnPosition(_) => "column_position",
2261            Expression::ColumnDef(_) => "column_def",
2262            Expression::AlterColumn(_) => "alter_column",
2263            Expression::AlterSortKey(_) => "alter_sort_key",
2264            Expression::AlterSet(_) => "alter_set",
2265            Expression::RenameColumn(_) => "rename_column",
2266            Expression::Comprehension(_) => "comprehension",
2267            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2268            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2269            Expression::IndexConstraintOption(_) => "index_constraint_option",
2270            Expression::ColumnConstraint(_) => "column_constraint",
2271            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2272            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2273            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2274            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2275            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2276            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2277            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2278            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2279            Expression::WithOperator(_) => "with_operator",
2280            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2281                "generated_as_identity_column_constraint"
2282            }
2283            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2284            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2285            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2286            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2287            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2288            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2289            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2290            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2291            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2292            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2293            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2294            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2295            Expression::PathColumnConstraint(_) => "path_column_constraint",
2296            Expression::Constraint(_) => "constraint",
2297            Expression::Export(_) => "export",
2298            Expression::Filter(_) => "filter",
2299            Expression::Changes(_) => "changes",
2300            Expression::CopyParameter(_) => "copy_parameter",
2301            Expression::Credentials(_) => "credentials",
2302            Expression::Directory(_) => "directory",
2303            Expression::ForeignKey(_) => "foreign_key",
2304            Expression::ColumnPrefix(_) => "column_prefix",
2305            Expression::PrimaryKey(_) => "primary_key",
2306            Expression::IntoClause(_) => "into_clause",
2307            Expression::JoinHint(_) => "join_hint",
2308            Expression::Opclass(_) => "opclass",
2309            Expression::Index(_) => "index",
2310            Expression::IndexParameters(_) => "index_parameters",
2311            Expression::ConditionalInsert(_) => "conditional_insert",
2312            Expression::MultitableInserts(_) => "multitable_inserts",
2313            Expression::OnConflict(_) => "on_conflict",
2314            Expression::OnCondition(_) => "on_condition",
2315            Expression::Returning(_) => "returning",
2316            Expression::Introducer(_) => "introducer",
2317            Expression::PartitionRange(_) => "partition_range",
2318            Expression::Fetch(_) => "fetch",
2319            Expression::Group(_) => "group",
2320            Expression::Cube(_) => "cube",
2321            Expression::Rollup(_) => "rollup",
2322            Expression::GroupingSets(_) => "grouping_sets",
2323            Expression::LimitOptions(_) => "limit_options",
2324            Expression::Lateral(_) => "lateral",
2325            Expression::TableFromRows(_) => "table_from_rows",
2326            Expression::RowsFrom(_) => "rows_from",
2327            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2328            Expression::WithFill(_) => "with_fill",
2329            Expression::Property(_) => "property",
2330            Expression::GrantPrivilege(_) => "grant_privilege",
2331            Expression::GrantPrincipal(_) => "grant_principal",
2332            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2333            Expression::AlgorithmProperty(_) => "algorithm_property",
2334            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2335            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2336            Expression::BackupProperty(_) => "backup_property",
2337            Expression::BuildProperty(_) => "build_property",
2338            Expression::BlockCompressionProperty(_) => "block_compression_property",
2339            Expression::CharacterSetProperty(_) => "character_set_property",
2340            Expression::ChecksumProperty(_) => "checksum_property",
2341            Expression::CollateProperty(_) => "collate_property",
2342            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2343            Expression::DataDeletionProperty(_) => "data_deletion_property",
2344            Expression::DefinerProperty(_) => "definer_property",
2345            Expression::DistKeyProperty(_) => "dist_key_property",
2346            Expression::DistributedByProperty(_) => "distributed_by_property",
2347            Expression::DistStyleProperty(_) => "dist_style_property",
2348            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2349            Expression::EngineProperty(_) => "engine_property",
2350            Expression::ToTableProperty(_) => "to_table_property",
2351            Expression::ExecuteAsProperty(_) => "execute_as_property",
2352            Expression::ExternalProperty(_) => "external_property",
2353            Expression::FallbackProperty(_) => "fallback_property",
2354            Expression::FileFormatProperty(_) => "file_format_property",
2355            Expression::CredentialsProperty(_) => "credentials_property",
2356            Expression::FreespaceProperty(_) => "freespace_property",
2357            Expression::InheritsProperty(_) => "inherits_property",
2358            Expression::InputModelProperty(_) => "input_model_property",
2359            Expression::OutputModelProperty(_) => "output_model_property",
2360            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2361            Expression::JournalProperty(_) => "journal_property",
2362            Expression::LanguageProperty(_) => "language_property",
2363            Expression::EnviromentProperty(_) => "enviroment_property",
2364            Expression::ClusteredByProperty(_) => "clustered_by_property",
2365            Expression::DictProperty(_) => "dict_property",
2366            Expression::DictRange(_) => "dict_range",
2367            Expression::OnCluster(_) => "on_cluster",
2368            Expression::LikeProperty(_) => "like_property",
2369            Expression::LocationProperty(_) => "location_property",
2370            Expression::LockProperty(_) => "lock_property",
2371            Expression::LockingProperty(_) => "locking_property",
2372            Expression::LogProperty(_) => "log_property",
2373            Expression::MaterializedProperty(_) => "materialized_property",
2374            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2375            Expression::OnProperty(_) => "on_property",
2376            Expression::OnCommitProperty(_) => "on_commit_property",
2377            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2378            Expression::PartitionByProperty(_) => "partition_by_property",
2379            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2380            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2381            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2382            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2383            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2384            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2385            Expression::PartitionList(_) => "partition_list",
2386            Expression::Partition(_) => "partition",
2387            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2388            Expression::UniqueKeyProperty(_) => "unique_key_property",
2389            Expression::RollupProperty(_) => "rollup_property",
2390            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2391            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2392            Expression::RemoteWithConnectionModelProperty(_) => {
2393                "remote_with_connection_model_property"
2394            }
2395            Expression::ReturnsProperty(_) => "returns_property",
2396            Expression::RowFormatProperty(_) => "row_format_property",
2397            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2398            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2399            Expression::QueryTransform(_) => "query_transform",
2400            Expression::SampleProperty(_) => "sample_property",
2401            Expression::SecurityProperty(_) => "security_property",
2402            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2403            Expression::SemanticView(_) => "semantic_view",
2404            Expression::SerdeProperties(_) => "serde_properties",
2405            Expression::SetProperty(_) => "set_property",
2406            Expression::SharingProperty(_) => "sharing_property",
2407            Expression::SetConfigProperty(_) => "set_config_property",
2408            Expression::SettingsProperty(_) => "settings_property",
2409            Expression::SortKeyProperty(_) => "sort_key_property",
2410            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2411            Expression::SqlSecurityProperty(_) => "sql_security_property",
2412            Expression::StabilityProperty(_) => "stability_property",
2413            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2414            Expression::TemporaryProperty(_) => "temporary_property",
2415            Expression::Tags(_) => "tags",
2416            Expression::TransformModelProperty(_) => "transform_model_property",
2417            Expression::TransientProperty(_) => "transient_property",
2418            Expression::UsingTemplateProperty(_) => "using_template_property",
2419            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2420            Expression::VolatileProperty(_) => "volatile_property",
2421            Expression::WithDataProperty(_) => "with_data_property",
2422            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2423            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2424            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2425            Expression::WithProcedureOptions(_) => "with_procedure_options",
2426            Expression::EncodeProperty(_) => "encode_property",
2427            Expression::IncludeProperty(_) => "include_property",
2428            Expression::Properties(_) => "properties",
2429            Expression::OptionsProperty(_) => "options_property",
2430            Expression::InputOutputFormat(_) => "input_output_format",
2431            Expression::Reference(_) => "reference",
2432            Expression::QueryOption(_) => "query_option",
2433            Expression::WithTableHint(_) => "with_table_hint",
2434            Expression::IndexTableHint(_) => "index_table_hint",
2435            Expression::HistoricalData(_) => "historical_data",
2436            Expression::Get(_) => "get",
2437            Expression::SetOperation(_) => "set_operation",
2438            Expression::Var(_) => "var",
2439            Expression::Variadic(_) => "variadic",
2440            Expression::Version(_) => "version",
2441            Expression::Schema(_) => "schema",
2442            Expression::Lock(_) => "lock",
2443            Expression::TableSample(_) => "table_sample",
2444            Expression::Tag(_) => "tag",
2445            Expression::UnpivotColumns(_) => "unpivot_columns",
2446            Expression::WindowSpec(_) => "window_spec",
2447            Expression::SessionParameter(_) => "session_parameter",
2448            Expression::PseudoType(_) => "pseudo_type",
2449            Expression::ObjectIdentifier(_) => "object_identifier",
2450            Expression::Transaction(_) => "transaction",
2451            Expression::Commit(_) => "commit",
2452            Expression::Rollback(_) => "rollback",
2453            Expression::AlterSession(_) => "alter_session",
2454            Expression::Analyze(_) => "analyze",
2455            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2456            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2457            Expression::AnalyzeSample(_) => "analyze_sample",
2458            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2459            Expression::AnalyzeDelete(_) => "analyze_delete",
2460            Expression::AnalyzeWith(_) => "analyze_with",
2461            Expression::AnalyzeValidate(_) => "analyze_validate",
2462            Expression::AddPartition(_) => "add_partition",
2463            Expression::AttachOption(_) => "attach_option",
2464            Expression::DropPartition(_) => "drop_partition",
2465            Expression::ReplacePartition(_) => "replace_partition",
2466            Expression::DPipe(_) => "d_pipe",
2467            Expression::Operator(_) => "operator",
2468            Expression::PivotAny(_) => "pivot_any",
2469            Expression::Aliases(_) => "aliases",
2470            Expression::AtIndex(_) => "at_index",
2471            Expression::FromTimeZone(_) => "from_time_zone",
2472            Expression::FormatPhrase(_) => "format_phrase",
2473            Expression::ForIn(_) => "for_in",
2474            Expression::TimeUnit(_) => "time_unit",
2475            Expression::IntervalOp(_) => "interval_op",
2476            Expression::IntervalSpan(_) => "interval_span",
2477            Expression::HavingMax(_) => "having_max",
2478            Expression::CosineDistance(_) => "cosine_distance",
2479            Expression::DotProduct(_) => "dot_product",
2480            Expression::EuclideanDistance(_) => "euclidean_distance",
2481            Expression::ManhattanDistance(_) => "manhattan_distance",
2482            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2483            Expression::Booland(_) => "booland",
2484            Expression::Boolor(_) => "boolor",
2485            Expression::ParameterizedAgg(_) => "parameterized_agg",
2486            Expression::ArgMax(_) => "arg_max",
2487            Expression::ArgMin(_) => "arg_min",
2488            Expression::ApproxTopK(_) => "approx_top_k",
2489            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2490            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2491            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2492            Expression::ApproxTopSum(_) => "approx_top_sum",
2493            Expression::ApproxQuantiles(_) => "approx_quantiles",
2494            Expression::Minhash(_) => "minhash",
2495            Expression::FarmFingerprint(_) => "farm_fingerprint",
2496            Expression::Float64(_) => "float64",
2497            Expression::Transform(_) => "transform",
2498            Expression::Translate(_) => "translate",
2499            Expression::Grouping(_) => "grouping",
2500            Expression::GroupingId(_) => "grouping_id",
2501            Expression::Anonymous(_) => "anonymous",
2502            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2503            Expression::CombinedAggFunc(_) => "combined_agg_func",
2504            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2505            Expression::HashAgg(_) => "hash_agg",
2506            Expression::Hll(_) => "hll",
2507            Expression::Apply(_) => "apply",
2508            Expression::ToBoolean(_) => "to_boolean",
2509            Expression::List(_) => "list",
2510            Expression::ToMap(_) => "to_map",
2511            Expression::Pad(_) => "pad",
2512            Expression::ToChar(_) => "to_char",
2513            Expression::ToNumber(_) => "to_number",
2514            Expression::ToDouble(_) => "to_double",
2515            Expression::Int64(_) => "int64",
2516            Expression::StringFunc(_) => "string_func",
2517            Expression::ToDecfloat(_) => "to_decfloat",
2518            Expression::TryToDecfloat(_) => "try_to_decfloat",
2519            Expression::ToFile(_) => "to_file",
2520            Expression::Columns(_) => "columns",
2521            Expression::ConvertToCharset(_) => "convert_to_charset",
2522            Expression::ConvertTimezone(_) => "convert_timezone",
2523            Expression::GenerateSeries(_) => "generate_series",
2524            Expression::AIAgg(_) => "a_i_agg",
2525            Expression::AIClassify(_) => "a_i_classify",
2526            Expression::ArrayAll(_) => "array_all",
2527            Expression::ArrayAny(_) => "array_any",
2528            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2529            Expression::StPoint(_) => "st_point",
2530            Expression::StDistance(_) => "st_distance",
2531            Expression::StringToArray(_) => "string_to_array",
2532            Expression::ArraySum(_) => "array_sum",
2533            Expression::ObjectAgg(_) => "object_agg",
2534            Expression::CastToStrType(_) => "cast_to_str_type",
2535            Expression::CheckJson(_) => "check_json",
2536            Expression::CheckXml(_) => "check_xml",
2537            Expression::TranslateCharacters(_) => "translate_characters",
2538            Expression::CurrentSchemas(_) => "current_schemas",
2539            Expression::CurrentDatetime(_) => "current_datetime",
2540            Expression::Localtime(_) => "localtime",
2541            Expression::Localtimestamp(_) => "localtimestamp",
2542            Expression::Systimestamp(_) => "systimestamp",
2543            Expression::CurrentSchema(_) => "current_schema",
2544            Expression::CurrentUser(_) => "current_user",
2545            Expression::UtcTime(_) => "utc_time",
2546            Expression::UtcTimestamp(_) => "utc_timestamp",
2547            Expression::Timestamp(_) => "timestamp",
2548            Expression::DateBin(_) => "date_bin",
2549            Expression::Datetime(_) => "datetime",
2550            Expression::DatetimeAdd(_) => "datetime_add",
2551            Expression::DatetimeSub(_) => "datetime_sub",
2552            Expression::DatetimeDiff(_) => "datetime_diff",
2553            Expression::DatetimeTrunc(_) => "datetime_trunc",
2554            Expression::Dayname(_) => "dayname",
2555            Expression::MakeInterval(_) => "make_interval",
2556            Expression::PreviousDay(_) => "previous_day",
2557            Expression::Elt(_) => "elt",
2558            Expression::TimestampAdd(_) => "timestamp_add",
2559            Expression::TimestampSub(_) => "timestamp_sub",
2560            Expression::TimestampDiff(_) => "timestamp_diff",
2561            Expression::TimeSlice(_) => "time_slice",
2562            Expression::TimeAdd(_) => "time_add",
2563            Expression::TimeSub(_) => "time_sub",
2564            Expression::TimeDiff(_) => "time_diff",
2565            Expression::TimeTrunc(_) => "time_trunc",
2566            Expression::DateFromParts(_) => "date_from_parts",
2567            Expression::TimeFromParts(_) => "time_from_parts",
2568            Expression::DecodeCase(_) => "decode_case",
2569            Expression::Decrypt(_) => "decrypt",
2570            Expression::DecryptRaw(_) => "decrypt_raw",
2571            Expression::Encode(_) => "encode",
2572            Expression::Encrypt(_) => "encrypt",
2573            Expression::EncryptRaw(_) => "encrypt_raw",
2574            Expression::EqualNull(_) => "equal_null",
2575            Expression::ToBinary(_) => "to_binary",
2576            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2577            Expression::Base64DecodeString(_) => "base64_decode_string",
2578            Expression::Base64Encode(_) => "base64_encode",
2579            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2580            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2581            Expression::GapFill(_) => "gap_fill",
2582            Expression::GenerateDateArray(_) => "generate_date_array",
2583            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2584            Expression::GetExtract(_) => "get_extract",
2585            Expression::Getbit(_) => "getbit",
2586            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2587            Expression::HexEncode(_) => "hex_encode",
2588            Expression::Compress(_) => "compress",
2589            Expression::DecompressBinary(_) => "decompress_binary",
2590            Expression::DecompressString(_) => "decompress_string",
2591            Expression::Xor(_) => "xor",
2592            Expression::Nullif(_) => "nullif",
2593            Expression::JSON(_) => "j_s_o_n",
2594            Expression::JSONPath(_) => "j_s_o_n_path",
2595            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2596            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2597            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2598            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2599            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2600            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2601            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2602            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2603            Expression::Format(_) => "format",
2604            Expression::JSONKeys(_) => "j_s_o_n_keys",
2605            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2606            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2607            Expression::JSONObject(_) => "j_s_o_n_object",
2608            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2609            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2610            Expression::JSONArray(_) => "j_s_o_n_array",
2611            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2612            Expression::JSONExists(_) => "j_s_o_n_exists",
2613            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2614            Expression::JSONSchema(_) => "j_s_o_n_schema",
2615            Expression::JSONSet(_) => "j_s_o_n_set",
2616            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2617            Expression::JSONValue(_) => "j_s_o_n_value",
2618            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2619            Expression::JSONRemove(_) => "j_s_o_n_remove",
2620            Expression::JSONTable(_) => "j_s_o_n_table",
2621            Expression::JSONType(_) => "j_s_o_n_type",
2622            Expression::ObjectInsert(_) => "object_insert",
2623            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2624            Expression::OpenJSON(_) => "open_j_s_o_n",
2625            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2626            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2627            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2628            Expression::JSONCast(_) => "j_s_o_n_cast",
2629            Expression::JSONExtract(_) => "j_s_o_n_extract",
2630            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2631            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2632            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2633            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2634            Expression::JSONFormat(_) => "j_s_o_n_format",
2635            Expression::JSONBool(_) => "j_s_o_n_bool",
2636            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2637            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2638            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2639            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2640            Expression::ParseJSON(_) => "parse_j_s_o_n",
2641            Expression::ParseUrl(_) => "parse_url",
2642            Expression::ParseIp(_) => "parse_ip",
2643            Expression::ParseTime(_) => "parse_time",
2644            Expression::ParseDatetime(_) => "parse_datetime",
2645            Expression::Map(_) => "map",
2646            Expression::MapCat(_) => "map_cat",
2647            Expression::MapDelete(_) => "map_delete",
2648            Expression::MapInsert(_) => "map_insert",
2649            Expression::MapPick(_) => "map_pick",
2650            Expression::ScopeResolution(_) => "scope_resolution",
2651            Expression::Slice(_) => "slice",
2652            Expression::VarMap(_) => "var_map",
2653            Expression::MatchAgainst(_) => "match_against",
2654            Expression::MD5Digest(_) => "m_d5_digest",
2655            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2656            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2657            Expression::Monthname(_) => "monthname",
2658            Expression::Ntile(_) => "ntile",
2659            Expression::Normalize(_) => "normalize",
2660            Expression::Normal(_) => "normal",
2661            Expression::Predict(_) => "predict",
2662            Expression::MLTranslate(_) => "m_l_translate",
2663            Expression::FeaturesAtTime(_) => "features_at_time",
2664            Expression::GenerateEmbedding(_) => "generate_embedding",
2665            Expression::MLForecast(_) => "m_l_forecast",
2666            Expression::ModelAttribute(_) => "model_attribute",
2667            Expression::VectorSearch(_) => "vector_search",
2668            Expression::Quantile(_) => "quantile",
2669            Expression::ApproxQuantile(_) => "approx_quantile",
2670            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2671            Expression::Randn(_) => "randn",
2672            Expression::Randstr(_) => "randstr",
2673            Expression::RangeN(_) => "range_n",
2674            Expression::RangeBucket(_) => "range_bucket",
2675            Expression::ReadCSV(_) => "read_c_s_v",
2676            Expression::ReadParquet(_) => "read_parquet",
2677            Expression::Reduce(_) => "reduce",
2678            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2679            Expression::RegexpILike(_) => "regexp_i_like",
2680            Expression::RegexpFullMatch(_) => "regexp_full_match",
2681            Expression::RegexpInstr(_) => "regexp_instr",
2682            Expression::RegexpSplit(_) => "regexp_split",
2683            Expression::RegexpCount(_) => "regexp_count",
2684            Expression::RegrValx(_) => "regr_valx",
2685            Expression::RegrValy(_) => "regr_valy",
2686            Expression::RegrAvgy(_) => "regr_avgy",
2687            Expression::RegrAvgx(_) => "regr_avgx",
2688            Expression::RegrCount(_) => "regr_count",
2689            Expression::RegrIntercept(_) => "regr_intercept",
2690            Expression::RegrR2(_) => "regr_r2",
2691            Expression::RegrSxx(_) => "regr_sxx",
2692            Expression::RegrSxy(_) => "regr_sxy",
2693            Expression::RegrSyy(_) => "regr_syy",
2694            Expression::RegrSlope(_) => "regr_slope",
2695            Expression::SafeAdd(_) => "safe_add",
2696            Expression::SafeDivide(_) => "safe_divide",
2697            Expression::SafeMultiply(_) => "safe_multiply",
2698            Expression::SafeSubtract(_) => "safe_subtract",
2699            Expression::SHA2(_) => "s_h_a2",
2700            Expression::SHA2Digest(_) => "s_h_a2_digest",
2701            Expression::SortArray(_) => "sort_array",
2702            Expression::SplitPart(_) => "split_part",
2703            Expression::SubstringIndex(_) => "substring_index",
2704            Expression::StandardHash(_) => "standard_hash",
2705            Expression::StrPosition(_) => "str_position",
2706            Expression::Search(_) => "search",
2707            Expression::SearchIp(_) => "search_ip",
2708            Expression::StrToDate(_) => "str_to_date",
2709            Expression::DateStrToDate(_) => "date_str_to_date",
2710            Expression::DateToDateStr(_) => "date_to_date_str",
2711            Expression::StrToTime(_) => "str_to_time",
2712            Expression::StrToUnix(_) => "str_to_unix",
2713            Expression::StrToMap(_) => "str_to_map",
2714            Expression::NumberToStr(_) => "number_to_str",
2715            Expression::FromBase(_) => "from_base",
2716            Expression::Stuff(_) => "stuff",
2717            Expression::TimeToStr(_) => "time_to_str",
2718            Expression::TimeStrToTime(_) => "time_str_to_time",
2719            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2720            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2721            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2722            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2723            Expression::Unhex(_) => "unhex",
2724            Expression::Uniform(_) => "uniform",
2725            Expression::UnixToStr(_) => "unix_to_str",
2726            Expression::UnixToTime(_) => "unix_to_time",
2727            Expression::Uuid(_) => "uuid",
2728            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2729            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2730            Expression::Corr(_) => "corr",
2731            Expression::WidthBucket(_) => "width_bucket",
2732            Expression::CovarSamp(_) => "covar_samp",
2733            Expression::CovarPop(_) => "covar_pop",
2734            Expression::Week(_) => "week",
2735            Expression::XMLElement(_) => "x_m_l_element",
2736            Expression::XMLGet(_) => "x_m_l_get",
2737            Expression::XMLTable(_) => "x_m_l_table",
2738            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2739            Expression::Zipf(_) => "zipf",
2740            Expression::Merge(_) => "merge",
2741            Expression::When(_) => "when",
2742            Expression::Whens(_) => "whens",
2743            Expression::NextValueFor(_) => "next_value_for",
2744            Expression::ReturnStmt(_) => "return_stmt",
2745        }
2746    }
2747
2748    /// Returns the primary child expression (".this" in sqlglot).
2749    pub fn get_this(&self) -> Option<&Expression> {
2750        match self {
2751            // Unary ops
2752            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2753            // UnaryFunc variants
2754            Expression::Upper(f)
2755            | Expression::Lower(f)
2756            | Expression::Length(f)
2757            | Expression::LTrim(f)
2758            | Expression::RTrim(f)
2759            | Expression::Reverse(f)
2760            | Expression::Abs(f)
2761            | Expression::Sqrt(f)
2762            | Expression::Cbrt(f)
2763            | Expression::Ln(f)
2764            | Expression::Exp(f)
2765            | Expression::Sign(f)
2766            | Expression::Date(f)
2767            | Expression::Time(f)
2768            | Expression::Initcap(f)
2769            | Expression::Ascii(f)
2770            | Expression::Chr(f)
2771            | Expression::Soundex(f)
2772            | Expression::ByteLength(f)
2773            | Expression::Hex(f)
2774            | Expression::LowerHex(f)
2775            | Expression::Unicode(f)
2776            | Expression::Typeof(f)
2777            | Expression::Explode(f)
2778            | Expression::ExplodeOuter(f)
2779            | Expression::MapFromEntries(f)
2780            | Expression::MapKeys(f)
2781            | Expression::MapValues(f)
2782            | Expression::ArrayLength(f)
2783            | Expression::ArraySize(f)
2784            | Expression::Cardinality(f)
2785            | Expression::ArrayReverse(f)
2786            | Expression::ArrayDistinct(f)
2787            | Expression::ArrayFlatten(f)
2788            | Expression::ArrayCompact(f)
2789            | Expression::ToArray(f)
2790            | Expression::JsonArrayLength(f)
2791            | Expression::JsonKeys(f)
2792            | Expression::JsonType(f)
2793            | Expression::ParseJson(f)
2794            | Expression::ToJson(f)
2795            | Expression::Radians(f)
2796            | Expression::Degrees(f)
2797            | Expression::Sin(f)
2798            | Expression::Cos(f)
2799            | Expression::Tan(f)
2800            | Expression::Asin(f)
2801            | Expression::Acos(f)
2802            | Expression::Atan(f)
2803            | Expression::IsNan(f)
2804            | Expression::IsInf(f)
2805            | Expression::Year(f)
2806            | Expression::Month(f)
2807            | Expression::Day(f)
2808            | Expression::Hour(f)
2809            | Expression::Minute(f)
2810            | Expression::Second(f)
2811            | Expression::DayOfWeek(f)
2812            | Expression::DayOfWeekIso(f)
2813            | Expression::DayOfMonth(f)
2814            | Expression::DayOfYear(f)
2815            | Expression::WeekOfYear(f)
2816            | Expression::Quarter(f)
2817            | Expression::Epoch(f)
2818            | Expression::EpochMs(f)
2819            | Expression::BitwiseCount(f)
2820            | Expression::DateFromUnixDate(f)
2821            | Expression::UnixDate(f)
2822            | Expression::UnixSeconds(f)
2823            | Expression::UnixMillis(f)
2824            | Expression::UnixMicros(f)
2825            | Expression::TimeStrToDate(f)
2826            | Expression::DateToDi(f)
2827            | Expression::DiToDate(f)
2828            | Expression::TsOrDiToDi(f)
2829            | Expression::TsOrDsToDatetime(f)
2830            | Expression::TsOrDsToTimestamp(f)
2831            | Expression::YearOfWeek(f)
2832            | Expression::YearOfWeekIso(f)
2833            | Expression::SHA(f)
2834            | Expression::SHA1Digest(f)
2835            | Expression::TimeToUnix(f)
2836            | Expression::TimeStrToUnix(f)
2837            | Expression::Int64(f)
2838            | Expression::JSONBool(f)
2839            | Expression::MD5NumberLower64(f)
2840            | Expression::MD5NumberUpper64(f)
2841            | Expression::DateStrToDate(f)
2842            | Expression::DateToDateStr(f) => Some(&f.this),
2843            // BinaryFunc - this is the primary child
2844            Expression::Power(f)
2845            | Expression::NullIf(f)
2846            | Expression::IfNull(f)
2847            | Expression::Nvl(f)
2848            | Expression::Contains(f)
2849            | Expression::StartsWith(f)
2850            | Expression::EndsWith(f)
2851            | Expression::Levenshtein(f)
2852            | Expression::ModFunc(f)
2853            | Expression::IntDiv(f)
2854            | Expression::Atan2(f)
2855            | Expression::AddMonths(f)
2856            | Expression::MonthsBetween(f)
2857            | Expression::NextDay(f)
2858            | Expression::UnixToTimeStr(f)
2859            | Expression::ArrayContains(f)
2860            | Expression::ArrayPosition(f)
2861            | Expression::ArrayAppend(f)
2862            | Expression::ArrayPrepend(f)
2863            | Expression::ArrayUnion(f)
2864            | Expression::ArrayExcept(f)
2865            | Expression::ArrayRemove(f)
2866            | Expression::StarMap(f)
2867            | Expression::MapFromArrays(f)
2868            | Expression::MapContainsKey(f)
2869            | Expression::ElementAt(f)
2870            | Expression::JsonMergePatch(f)
2871            | Expression::JSONBContains(f)
2872            | Expression::JSONBExtract(f) => Some(&f.this),
2873            // AggFunc - this is the primary child
2874            Expression::Sum(af)
2875            | Expression::Avg(af)
2876            | Expression::Min(af)
2877            | Expression::Max(af)
2878            | Expression::ArrayAgg(af)
2879            | Expression::CountIf(af)
2880            | Expression::Stddev(af)
2881            | Expression::StddevPop(af)
2882            | Expression::StddevSamp(af)
2883            | Expression::Variance(af)
2884            | Expression::VarPop(af)
2885            | Expression::VarSamp(af)
2886            | Expression::Median(af)
2887            | Expression::Mode(af)
2888            | Expression::First(af)
2889            | Expression::Last(af)
2890            | Expression::AnyValue(af)
2891            | Expression::ApproxDistinct(af)
2892            | Expression::ApproxCountDistinct(af)
2893            | Expression::LogicalAnd(af)
2894            | Expression::LogicalOr(af)
2895            | Expression::Skewness(af)
2896            | Expression::ArrayConcatAgg(af)
2897            | Expression::ArrayUniqueAgg(af)
2898            | Expression::BoolXorAgg(af)
2899            | Expression::BitwiseAndAgg(af)
2900            | Expression::BitwiseOrAgg(af)
2901            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2902            // Binary operations - left is "this" in sqlglot
2903            Expression::And(op)
2904            | Expression::Or(op)
2905            | Expression::Add(op)
2906            | Expression::Sub(op)
2907            | Expression::Mul(op)
2908            | Expression::Div(op)
2909            | Expression::Mod(op)
2910            | Expression::Eq(op)
2911            | Expression::Neq(op)
2912            | Expression::Lt(op)
2913            | Expression::Lte(op)
2914            | Expression::Gt(op)
2915            | Expression::Gte(op)
2916            | Expression::BitwiseAnd(op)
2917            | Expression::BitwiseOr(op)
2918            | Expression::BitwiseXor(op)
2919            | Expression::Concat(op)
2920            | Expression::Adjacent(op)
2921            | Expression::TsMatch(op)
2922            | Expression::PropertyEQ(op)
2923            | Expression::ArrayContainsAll(op)
2924            | Expression::ArrayContainedBy(op)
2925            | Expression::ArrayOverlaps(op)
2926            | Expression::JSONBContainsAllTopKeys(op)
2927            | Expression::JSONBContainsAnyTopKeys(op)
2928            | Expression::JSONBDeleteAtPath(op)
2929            | Expression::ExtendsLeft(op)
2930            | Expression::ExtendsRight(op)
2931            | Expression::Is(op)
2932            | Expression::MemberOf(op)
2933            | Expression::Match(op)
2934            | Expression::NullSafeEq(op)
2935            | Expression::NullSafeNeq(op)
2936            | Expression::Glob(op)
2937            | Expression::BitwiseLeftShift(op)
2938            | Expression::BitwiseRightShift(op) => Some(&op.left),
2939            // Like operations - left is "this"
2940            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2941            // Structural types with .this
2942            Expression::Alias(a) => Some(&a.this),
2943            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2944            Expression::Paren(p) => Some(&p.this),
2945            Expression::Annotated(a) => Some(&a.this),
2946            Expression::Subquery(s) => Some(&s.this),
2947            Expression::Where(w) => Some(&w.this),
2948            Expression::Having(h) => Some(&h.this),
2949            Expression::Qualify(q) => Some(&q.this),
2950            Expression::IsNull(i) => Some(&i.this),
2951            Expression::Exists(e) => Some(&e.this),
2952            Expression::Ordered(o) => Some(&o.this),
2953            Expression::WindowFunction(wf) => Some(&wf.this),
2954            Expression::Cte(cte) => Some(&cte.this),
2955            Expression::Between(b) => Some(&b.this),
2956            Expression::In(i) => Some(&i.this),
2957            Expression::ReturnStmt(e) => Some(e),
2958            _ => None,
2959        }
2960    }
2961
2962    /// Returns the secondary child expression (".expression" in sqlglot).
2963    pub fn get_expression(&self) -> Option<&Expression> {
2964        match self {
2965            // Binary operations - right is "expression"
2966            Expression::And(op)
2967            | Expression::Or(op)
2968            | Expression::Add(op)
2969            | Expression::Sub(op)
2970            | Expression::Mul(op)
2971            | Expression::Div(op)
2972            | Expression::Mod(op)
2973            | Expression::Eq(op)
2974            | Expression::Neq(op)
2975            | Expression::Lt(op)
2976            | Expression::Lte(op)
2977            | Expression::Gt(op)
2978            | Expression::Gte(op)
2979            | Expression::BitwiseAnd(op)
2980            | Expression::BitwiseOr(op)
2981            | Expression::BitwiseXor(op)
2982            | Expression::Concat(op)
2983            | Expression::Adjacent(op)
2984            | Expression::TsMatch(op)
2985            | Expression::PropertyEQ(op)
2986            | Expression::ArrayContainsAll(op)
2987            | Expression::ArrayContainedBy(op)
2988            | Expression::ArrayOverlaps(op)
2989            | Expression::JSONBContainsAllTopKeys(op)
2990            | Expression::JSONBContainsAnyTopKeys(op)
2991            | Expression::JSONBDeleteAtPath(op)
2992            | Expression::ExtendsLeft(op)
2993            | Expression::ExtendsRight(op)
2994            | Expression::Is(op)
2995            | Expression::MemberOf(op)
2996            | Expression::Match(op)
2997            | Expression::NullSafeEq(op)
2998            | Expression::NullSafeNeq(op)
2999            | Expression::Glob(op)
3000            | Expression::BitwiseLeftShift(op)
3001            | Expression::BitwiseRightShift(op) => Some(&op.right),
3002            // Like operations - right is "expression"
3003            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3004            // BinaryFunc - expression is the secondary
3005            Expression::Power(f)
3006            | Expression::NullIf(f)
3007            | Expression::IfNull(f)
3008            | Expression::Nvl(f)
3009            | Expression::Contains(f)
3010            | Expression::StartsWith(f)
3011            | Expression::EndsWith(f)
3012            | Expression::Levenshtein(f)
3013            | Expression::ModFunc(f)
3014            | Expression::IntDiv(f)
3015            | Expression::Atan2(f)
3016            | Expression::AddMonths(f)
3017            | Expression::MonthsBetween(f)
3018            | Expression::NextDay(f)
3019            | Expression::UnixToTimeStr(f)
3020            | Expression::ArrayContains(f)
3021            | Expression::ArrayPosition(f)
3022            | Expression::ArrayAppend(f)
3023            | Expression::ArrayPrepend(f)
3024            | Expression::ArrayUnion(f)
3025            | Expression::ArrayExcept(f)
3026            | Expression::ArrayRemove(f)
3027            | Expression::StarMap(f)
3028            | Expression::MapFromArrays(f)
3029            | Expression::MapContainsKey(f)
3030            | Expression::ElementAt(f)
3031            | Expression::JsonMergePatch(f)
3032            | Expression::JSONBContains(f)
3033            | Expression::JSONBExtract(f) => Some(&f.expression),
3034            _ => None,
3035        }
3036    }
3037
3038    /// Returns the list of child expressions (".expressions" in sqlglot).
3039    pub fn get_expressions(&self) -> &[Expression] {
3040        match self {
3041            Expression::Select(s) => &s.expressions,
3042            Expression::Function(f) => &f.args,
3043            Expression::AggregateFunction(f) => &f.args,
3044            Expression::From(f) => &f.expressions,
3045            Expression::GroupBy(g) => &g.expressions,
3046            Expression::In(i) => &i.expressions,
3047            Expression::Array(a) => &a.expressions,
3048            Expression::Tuple(t) => &t.expressions,
3049            Expression::Coalesce(f)
3050            | Expression::Greatest(f)
3051            | Expression::Least(f)
3052            | Expression::ArrayConcat(f)
3053            | Expression::ArrayIntersect(f)
3054            | Expression::ArrayZip(f)
3055            | Expression::MapConcat(f)
3056            | Expression::JsonArray(f) => &f.expressions,
3057            _ => &[],
3058        }
3059    }
3060
3061    /// Returns the name of this expression as a string slice.
3062    pub fn get_name(&self) -> &str {
3063        match self {
3064            Expression::Identifier(id) => &id.name,
3065            Expression::Column(col) => &col.name.name,
3066            Expression::Table(t) => &t.name.name,
3067            Expression::Literal(lit) => lit.value_str(),
3068            Expression::Star(_) => "*",
3069            Expression::Function(f) => &f.name,
3070            Expression::AggregateFunction(f) => &f.name,
3071            Expression::Alias(a) => a.this.get_name(),
3072            Expression::Boolean(b) => {
3073                if b.value {
3074                    "TRUE"
3075                } else {
3076                    "FALSE"
3077                }
3078            }
3079            Expression::Null(_) => "NULL",
3080            _ => "",
3081        }
3082    }
3083
3084    /// Returns the alias name if this expression has one.
3085    pub fn get_alias(&self) -> &str {
3086        match self {
3087            Expression::Alias(a) => &a.alias.name,
3088            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3089            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3090            _ => "",
3091        }
3092    }
3093
3094    /// Returns the output name of this expression (what it shows up as in a SELECT).
3095    pub fn get_output_name(&self) -> &str {
3096        match self {
3097            Expression::Alias(a) => &a.alias.name,
3098            Expression::Column(c) => &c.name.name,
3099            Expression::Identifier(id) => &id.name,
3100            Expression::Literal(lit) => lit.value_str(),
3101            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3102            Expression::Star(_) => "*",
3103            _ => "",
3104        }
3105    }
3106
3107    /// Returns comments attached to this expression.
3108    pub fn get_comments(&self) -> Vec<&str> {
3109        match self {
3110            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3111            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3112            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3113            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3114            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3115            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3116            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3117                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3118            }
3119            Expression::And(op)
3120            | Expression::Or(op)
3121            | Expression::Add(op)
3122            | Expression::Sub(op)
3123            | Expression::Mul(op)
3124            | Expression::Div(op)
3125            | Expression::Mod(op)
3126            | Expression::Eq(op)
3127            | Expression::Neq(op)
3128            | Expression::Lt(op)
3129            | Expression::Lte(op)
3130            | Expression::Gt(op)
3131            | Expression::Gte(op)
3132            | Expression::Concat(op)
3133            | Expression::BitwiseAnd(op)
3134            | Expression::BitwiseOr(op)
3135            | Expression::BitwiseXor(op) => {
3136                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3137            }
3138            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3139            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3140            _ => Vec::new(),
3141        }
3142    }
3143}
3144
3145impl fmt::Display for Expression {
3146    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3147        // Basic display - full SQL generation is in generator module
3148        match self {
3149            Expression::Literal(lit) => write!(f, "{}", lit),
3150            Expression::Identifier(id) => write!(f, "{}", id),
3151            Expression::Column(col) => write!(f, "{}", col),
3152            Expression::Star(_) => write!(f, "*"),
3153            Expression::Null(_) => write!(f, "NULL"),
3154            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3155            Expression::Select(_) => write!(f, "SELECT ..."),
3156            _ => write!(f, "{:?}", self),
3157        }
3158    }
3159}
3160
3161/// Represent a SQL literal value.
3162///
3163/// Numeric values are stored as their original text representation (not parsed
3164/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3165/// preserved across round-trips.
3166///
3167/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3168/// strings, raw strings, etc.) each have a dedicated variant so that the
3169/// generator can emit them with the correct syntax.
3170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3171#[cfg_attr(feature = "bindings", derive(TS))]
3172#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3173pub enum Literal {
3174    /// Single-quoted string literal: `'hello'`
3175    String(String),
3176    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3177    Number(String),
3178    /// Hex string literal: `X'FF'`
3179    HexString(String),
3180    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3181    HexNumber(String),
3182    BitString(String),
3183    /// Byte string: b"..." (BigQuery style)
3184    ByteString(String),
3185    /// National string: N'abc'
3186    NationalString(String),
3187    /// DATE literal: DATE '2024-01-15'
3188    Date(String),
3189    /// TIME literal: TIME '10:30:00'
3190    Time(String),
3191    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3192    Timestamp(String),
3193    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3194    Datetime(String),
3195    /// Triple-quoted string: """...""" or '''...'''
3196    /// Contains (content, quote_char) where quote_char is '"' or '\''
3197    TripleQuotedString(String, char),
3198    /// Escape string: E'...' (PostgreSQL)
3199    EscapeString(String),
3200    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3201    DollarString(String),
3202    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3203    /// In raw strings, backslashes are literal and not escape characters.
3204    /// When converting to a regular string, backslashes must be doubled.
3205    RawString(String),
3206}
3207
3208impl Literal {
3209    /// Returns the inner value as a string slice, regardless of literal type.
3210    pub fn value_str(&self) -> &str {
3211        match self {
3212            Literal::String(s)
3213            | Literal::Number(s)
3214            | Literal::HexString(s)
3215            | Literal::HexNumber(s)
3216            | Literal::BitString(s)
3217            | Literal::ByteString(s)
3218            | Literal::NationalString(s)
3219            | Literal::Date(s)
3220            | Literal::Time(s)
3221            | Literal::Timestamp(s)
3222            | Literal::Datetime(s)
3223            | Literal::EscapeString(s)
3224            | Literal::DollarString(s)
3225            | Literal::RawString(s) => s.as_str(),
3226            Literal::TripleQuotedString(s, _) => s.as_str(),
3227        }
3228    }
3229
3230    /// Returns `true` if this is a string-type literal.
3231    pub fn is_string(&self) -> bool {
3232        matches!(
3233            self,
3234            Literal::String(_)
3235                | Literal::NationalString(_)
3236                | Literal::EscapeString(_)
3237                | Literal::DollarString(_)
3238                | Literal::RawString(_)
3239                | Literal::TripleQuotedString(_, _)
3240        )
3241    }
3242
3243    /// Returns `true` if this is a numeric literal.
3244    pub fn is_number(&self) -> bool {
3245        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3246    }
3247}
3248
3249impl fmt::Display for Literal {
3250    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3251        match self {
3252            Literal::String(s) => write!(f, "'{}'", s),
3253            Literal::Number(n) => write!(f, "{}", n),
3254            Literal::HexString(h) => write!(f, "X'{}'", h),
3255            Literal::HexNumber(h) => write!(f, "0x{}", h),
3256            Literal::BitString(b) => write!(f, "B'{}'", b),
3257            Literal::ByteString(b) => write!(f, "b'{}'", b),
3258            Literal::NationalString(s) => write!(f, "N'{}'", s),
3259            Literal::Date(d) => write!(f, "DATE '{}'", d),
3260            Literal::Time(t) => write!(f, "TIME '{}'", t),
3261            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3262            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3263            Literal::TripleQuotedString(s, q) => {
3264                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3265            }
3266            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3267            Literal::DollarString(s) => write!(f, "$${}$$", s),
3268            Literal::RawString(s) => write!(f, "r'{}'", s),
3269        }
3270    }
3271}
3272
3273/// Boolean literal
3274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3275#[cfg_attr(feature = "bindings", derive(TS))]
3276pub struct BooleanLiteral {
3277    pub value: bool,
3278}
3279
3280/// NULL literal
3281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3282#[cfg_attr(feature = "bindings", derive(TS))]
3283pub struct Null;
3284
3285/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3286///
3287/// The `quoted` flag indicates whether the identifier was originally delimited
3288/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3289/// dialect). The generator uses this flag to decide whether to emit quoting
3290/// characters.
3291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3292#[cfg_attr(feature = "bindings", derive(TS))]
3293pub struct Identifier {
3294    /// The raw text of the identifier, without any quoting characters.
3295    pub name: String,
3296    /// Whether the identifier was quoted in the source SQL.
3297    pub quoted: bool,
3298    #[serde(default)]
3299    pub trailing_comments: Vec<String>,
3300    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3301    #[serde(default, skip_serializing_if = "Option::is_none")]
3302    pub span: Option<Span>,
3303}
3304
3305impl Identifier {
3306    pub fn new(name: impl Into<String>) -> Self {
3307        Self {
3308            name: name.into(),
3309            quoted: false,
3310            trailing_comments: Vec::new(),
3311            span: None,
3312        }
3313    }
3314
3315    pub fn quoted(name: impl Into<String>) -> Self {
3316        Self {
3317            name: name.into(),
3318            quoted: true,
3319            trailing_comments: Vec::new(),
3320            span: None,
3321        }
3322    }
3323
3324    pub fn empty() -> Self {
3325        Self {
3326            name: String::new(),
3327            quoted: false,
3328            trailing_comments: Vec::new(),
3329            span: None,
3330        }
3331    }
3332
3333    pub fn is_empty(&self) -> bool {
3334        self.name.is_empty()
3335    }
3336
3337    /// Set the source span on this identifier
3338    pub fn with_span(mut self, span: Span) -> Self {
3339        self.span = Some(span);
3340        self
3341    }
3342}
3343
3344impl fmt::Display for Identifier {
3345    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3346        if self.quoted {
3347            write!(f, "\"{}\"", self.name)
3348        } else {
3349            write!(f, "{}", self.name)
3350        }
3351    }
3352}
3353
3354/// Represent a column reference, optionally qualified by a table name.
3355///
3356/// Renders as `name` when unqualified, or `table.name` when qualified.
3357/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3358/// convenient construction.
3359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3360#[cfg_attr(feature = "bindings", derive(TS))]
3361pub struct Column {
3362    /// The column name.
3363    pub name: Identifier,
3364    /// Optional table qualifier (e.g. `t` in `t.col`).
3365    pub table: Option<Identifier>,
3366    /// Oracle-style join marker (+) for outer joins
3367    #[serde(default)]
3368    pub join_mark: bool,
3369    /// Trailing comments that appeared after this column reference
3370    #[serde(default)]
3371    pub trailing_comments: Vec<String>,
3372    /// Source position span
3373    #[serde(default, skip_serializing_if = "Option::is_none")]
3374    pub span: Option<Span>,
3375    /// Inferred data type from type annotation
3376    #[serde(default, skip_serializing_if = "Option::is_none")]
3377    pub inferred_type: Option<DataType>,
3378}
3379
3380impl fmt::Display for Column {
3381    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3382        if let Some(table) = &self.table {
3383            write!(f, "{}.{}", table, self.name)
3384        } else {
3385            write!(f, "{}", self.name)
3386        }
3387    }
3388}
3389
3390/// Represent a table reference with optional schema and catalog qualifiers.
3391///
3392/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3393/// which qualifiers are present. Supports aliases, column alias lists,
3394/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3395/// several other dialect-specific extensions.
3396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3397#[cfg_attr(feature = "bindings", derive(TS))]
3398pub struct TableRef {
3399    /// The unqualified table name.
3400    pub name: Identifier,
3401    /// Optional schema qualifier (e.g. `public` in `public.users`).
3402    pub schema: Option<Identifier>,
3403    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3404    pub catalog: Option<Identifier>,
3405    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3406    pub alias: Option<Identifier>,
3407    /// Whether AS keyword was explicitly used for the alias
3408    #[serde(default)]
3409    pub alias_explicit_as: bool,
3410    /// Column aliases for table alias: AS t(c1, c2)
3411    #[serde(default)]
3412    pub column_aliases: Vec<Identifier>,
3413    /// Leading comments that appeared before this table reference in a FROM clause
3414    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3415    pub leading_comments: Vec<String>,
3416    /// Trailing comments that appeared after this table reference
3417    #[serde(default)]
3418    pub trailing_comments: Vec<String>,
3419    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3420    #[serde(default)]
3421    pub when: Option<Box<HistoricalData>>,
3422    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3423    #[serde(default)]
3424    pub only: bool,
3425    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3426    #[serde(default)]
3427    pub final_: bool,
3428    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3429    #[serde(default, skip_serializing_if = "Option::is_none")]
3430    pub table_sample: Option<Box<Sample>>,
3431    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3432    #[serde(default)]
3433    pub hints: Vec<Expression>,
3434    /// TSQL: FOR SYSTEM_TIME temporal clause
3435    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3436    #[serde(default, skip_serializing_if = "Option::is_none")]
3437    pub system_time: Option<String>,
3438    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3439    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3440    pub partitions: Vec<Identifier>,
3441    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3442    /// When set, this is used instead of the name field
3443    #[serde(default, skip_serializing_if = "Option::is_none")]
3444    pub identifier_func: Option<Box<Expression>>,
3445    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3446    #[serde(default, skip_serializing_if = "Option::is_none")]
3447    pub changes: Option<Box<Changes>>,
3448    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3449    #[serde(default, skip_serializing_if = "Option::is_none")]
3450    pub version: Option<Box<Version>>,
3451    /// Source position span
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub span: Option<Span>,
3454}
3455
3456impl TableRef {
3457    pub fn new(name: impl Into<String>) -> Self {
3458        Self {
3459            name: Identifier::new(name),
3460            schema: None,
3461            catalog: None,
3462            alias: None,
3463            alias_explicit_as: false,
3464            column_aliases: Vec::new(),
3465            leading_comments: Vec::new(),
3466            trailing_comments: Vec::new(),
3467            when: None,
3468            only: false,
3469            final_: false,
3470            table_sample: None,
3471            hints: Vec::new(),
3472            system_time: None,
3473            partitions: Vec::new(),
3474            identifier_func: None,
3475            changes: None,
3476            version: None,
3477            span: None,
3478        }
3479    }
3480
3481    /// Create with a schema qualifier.
3482    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3483        let mut t = Self::new(name);
3484        t.schema = Some(Identifier::new(schema));
3485        t
3486    }
3487
3488    /// Create with catalog and schema qualifiers.
3489    pub fn new_with_catalog(
3490        name: impl Into<String>,
3491        schema: impl Into<String>,
3492        catalog: impl Into<String>,
3493    ) -> Self {
3494        let mut t = Self::new(name);
3495        t.schema = Some(Identifier::new(schema));
3496        t.catalog = Some(Identifier::new(catalog));
3497        t
3498    }
3499
3500    /// Create from an Identifier, preserving the quoted flag
3501    pub fn from_identifier(name: Identifier) -> Self {
3502        Self {
3503            name,
3504            schema: None,
3505            catalog: None,
3506            alias: None,
3507            alias_explicit_as: false,
3508            column_aliases: Vec::new(),
3509            leading_comments: Vec::new(),
3510            trailing_comments: Vec::new(),
3511            when: None,
3512            only: false,
3513            final_: false,
3514            table_sample: None,
3515            hints: Vec::new(),
3516            system_time: None,
3517            partitions: Vec::new(),
3518            identifier_func: None,
3519            changes: None,
3520            version: None,
3521            span: None,
3522        }
3523    }
3524
3525    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3526        self.alias = Some(Identifier::new(alias));
3527        self
3528    }
3529
3530    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3531        self.schema = Some(Identifier::new(schema));
3532        self
3533    }
3534}
3535
3536/// Represent a wildcard star expression (`*`, `table.*`).
3537///
3538/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3539/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3541#[cfg_attr(feature = "bindings", derive(TS))]
3542pub struct Star {
3543    /// Optional table qualifier (e.g. `t` in `t.*`).
3544    pub table: Option<Identifier>,
3545    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3546    pub except: Option<Vec<Identifier>>,
3547    /// REPLACE expressions (BigQuery, Snowflake)
3548    pub replace: Option<Vec<Alias>>,
3549    /// RENAME columns (Snowflake)
3550    pub rename: Option<Vec<(Identifier, Identifier)>>,
3551    /// Trailing comments that appeared after the star
3552    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3553    pub trailing_comments: Vec<String>,
3554    /// Source position span
3555    #[serde(default, skip_serializing_if = "Option::is_none")]
3556    pub span: Option<Span>,
3557}
3558
3559/// Represent a complete SELECT statement.
3560///
3561/// This is the most feature-rich AST node, covering the full surface area of
3562/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3563/// `Vec` are omitted from the generated SQL when absent.
3564///
3565/// # Key Fields
3566///
3567/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3568/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3569/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3570/// - `where_clause` -- the WHERE predicate.
3571/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3572/// - `having` -- HAVING predicate.
3573/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3574/// - `limit` / `offset` / `fetch` -- result set limiting.
3575/// - `with` -- Common Table Expressions (CTEs).
3576/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3577/// - `windows` -- named window definitions (WINDOW w AS ...).
3578///
3579/// Dialect-specific extensions are supported via fields like `prewhere`
3580/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3581/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3583#[cfg_attr(feature = "bindings", derive(TS))]
3584pub struct Select {
3585    /// The select-list: columns, expressions, aliases, and wildcards.
3586    pub expressions: Vec<Expression>,
3587    /// The FROM clause, containing one or more table sources.
3588    pub from: Option<From>,
3589    /// JOIN clauses applied after the FROM source.
3590    pub joins: Vec<Join>,
3591    pub lateral_views: Vec<LateralView>,
3592    /// ClickHouse PREWHERE clause
3593    #[serde(default, skip_serializing_if = "Option::is_none")]
3594    pub prewhere: Option<Expression>,
3595    pub where_clause: Option<Where>,
3596    pub group_by: Option<GroupBy>,
3597    pub having: Option<Having>,
3598    pub qualify: Option<Qualify>,
3599    pub order_by: Option<OrderBy>,
3600    pub distribute_by: Option<DistributeBy>,
3601    pub cluster_by: Option<ClusterBy>,
3602    pub sort_by: Option<SortBy>,
3603    pub limit: Option<Limit>,
3604    pub offset: Option<Offset>,
3605    /// ClickHouse LIMIT BY clause expressions
3606    #[serde(default, skip_serializing_if = "Option::is_none")]
3607    pub limit_by: Option<Vec<Expression>>,
3608    pub fetch: Option<Fetch>,
3609    pub distinct: bool,
3610    pub distinct_on: Option<Vec<Expression>>,
3611    pub top: Option<Top>,
3612    pub with: Option<With>,
3613    pub sample: Option<Sample>,
3614    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub settings: Option<Vec<Expression>>,
3617    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3618    #[serde(default, skip_serializing_if = "Option::is_none")]
3619    pub format: Option<Expression>,
3620    pub windows: Option<Vec<NamedWindow>>,
3621    pub hint: Option<Hint>,
3622    /// Oracle CONNECT BY clause for hierarchical queries
3623    pub connect: Option<Connect>,
3624    /// SELECT ... INTO table_name for creating tables
3625    pub into: Option<SelectInto>,
3626    /// FOR UPDATE/SHARE locking clauses
3627    #[serde(default)]
3628    pub locks: Vec<Lock>,
3629    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3630    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3631    pub for_xml: Vec<Expression>,
3632    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub for_json: Vec<Expression>,
3635    /// Leading comments before the statement
3636    #[serde(default)]
3637    pub leading_comments: Vec<String>,
3638    /// Comments that appear after SELECT keyword (before expressions)
3639    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3641    pub post_select_comments: Vec<String>,
3642    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3643    #[serde(default, skip_serializing_if = "Option::is_none")]
3644    pub kind: Option<String>,
3645    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3646    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3647    pub operation_modifiers: Vec<String>,
3648    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3649    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3650    pub qualify_after_window: bool,
3651    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub option: Option<String>,
3654    /// Redshift-style EXCLUDE clause at the end of the projection list
3655    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3656    #[serde(default, skip_serializing_if = "Option::is_none")]
3657    pub exclude: Option<Vec<Expression>>,
3658}
3659
3660impl Select {
3661    pub fn new() -> Self {
3662        Self {
3663            expressions: Vec::new(),
3664            from: None,
3665            joins: Vec::new(),
3666            lateral_views: Vec::new(),
3667            prewhere: None,
3668            where_clause: None,
3669            group_by: None,
3670            having: None,
3671            qualify: None,
3672            order_by: None,
3673            distribute_by: None,
3674            cluster_by: None,
3675            sort_by: None,
3676            limit: None,
3677            offset: None,
3678            limit_by: None,
3679            fetch: None,
3680            distinct: false,
3681            distinct_on: None,
3682            top: None,
3683            with: None,
3684            sample: None,
3685            settings: None,
3686            format: None,
3687            windows: None,
3688            hint: None,
3689            connect: None,
3690            into: None,
3691            locks: Vec::new(),
3692            for_xml: Vec::new(),
3693            for_json: Vec::new(),
3694            leading_comments: Vec::new(),
3695            post_select_comments: Vec::new(),
3696            kind: None,
3697            operation_modifiers: Vec::new(),
3698            qualify_after_window: false,
3699            option: None,
3700            exclude: None,
3701        }
3702    }
3703
3704    /// Add a column to select
3705    pub fn column(mut self, expr: Expression) -> Self {
3706        self.expressions.push(expr);
3707        self
3708    }
3709
3710    /// Set the FROM clause
3711    pub fn from(mut self, table: Expression) -> Self {
3712        self.from = Some(From {
3713            expressions: vec![table],
3714        });
3715        self
3716    }
3717
3718    /// Add a WHERE clause
3719    pub fn where_(mut self, condition: Expression) -> Self {
3720        self.where_clause = Some(Where { this: condition });
3721        self
3722    }
3723
3724    /// Set DISTINCT
3725    pub fn distinct(mut self) -> Self {
3726        self.distinct = true;
3727        self
3728    }
3729
3730    /// Add a JOIN
3731    pub fn join(mut self, join: Join) -> Self {
3732        self.joins.push(join);
3733        self
3734    }
3735
3736    /// Set ORDER BY
3737    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3738        self.order_by = Some(OrderBy {
3739            expressions,
3740            siblings: false,
3741            comments: Vec::new(),
3742        });
3743        self
3744    }
3745
3746    /// Set LIMIT
3747    pub fn limit(mut self, n: Expression) -> Self {
3748        self.limit = Some(Limit {
3749            this: n,
3750            percent: false,
3751            comments: Vec::new(),
3752        });
3753        self
3754    }
3755
3756    /// Set OFFSET
3757    pub fn offset(mut self, n: Expression) -> Self {
3758        self.offset = Some(Offset {
3759            this: n,
3760            rows: None,
3761        });
3762        self
3763    }
3764}
3765
3766impl Default for Select {
3767    fn default() -> Self {
3768        Self::new()
3769    }
3770}
3771
3772/// Represent a UNION set operation between two query expressions.
3773///
3774/// When `all` is true, duplicate rows are preserved (UNION ALL).
3775/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3776/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3778#[cfg_attr(feature = "bindings", derive(TS))]
3779pub struct Union {
3780    /// The left-hand query operand.
3781    pub left: Expression,
3782    /// The right-hand query operand.
3783    pub right: Expression,
3784    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3785    pub all: bool,
3786    /// Whether DISTINCT was explicitly specified
3787    #[serde(default)]
3788    pub distinct: bool,
3789    /// Optional WITH clause
3790    pub with: Option<With>,
3791    /// ORDER BY applied to entire UNION result
3792    pub order_by: Option<OrderBy>,
3793    /// LIMIT applied to entire UNION result
3794    pub limit: Option<Box<Expression>>,
3795    /// OFFSET applied to entire UNION result
3796    pub offset: Option<Box<Expression>>,
3797    /// DISTRIBUTE BY clause (Hive/Spark)
3798    #[serde(default, skip_serializing_if = "Option::is_none")]
3799    pub distribute_by: Option<DistributeBy>,
3800    /// SORT BY clause (Hive/Spark)
3801    #[serde(default, skip_serializing_if = "Option::is_none")]
3802    pub sort_by: Option<SortBy>,
3803    /// CLUSTER BY clause (Hive/Spark)
3804    #[serde(default, skip_serializing_if = "Option::is_none")]
3805    pub cluster_by: Option<ClusterBy>,
3806    /// DuckDB BY NAME modifier
3807    #[serde(default)]
3808    pub by_name: bool,
3809    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3810    #[serde(default, skip_serializing_if = "Option::is_none")]
3811    pub side: Option<String>,
3812    /// BigQuery: Set operation kind (INNER)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub kind: Option<String>,
3815    /// BigQuery: CORRESPONDING modifier
3816    #[serde(default)]
3817    pub corresponding: bool,
3818    /// BigQuery: STRICT modifier (before CORRESPONDING)
3819    #[serde(default)]
3820    pub strict: bool,
3821    /// BigQuery: BY (columns) after CORRESPONDING
3822    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3823    pub on_columns: Vec<Expression>,
3824}
3825
3826/// Iteratively flatten the left-recursive chain to prevent stack overflow
3827/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3828impl Drop for Union {
3829    fn drop(&mut self) {
3830        loop {
3831            if let Expression::Union(ref mut inner) = self.left {
3832                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3833                let old_left = std::mem::replace(&mut self.left, next_left);
3834                drop(old_left);
3835            } else {
3836                break;
3837            }
3838        }
3839    }
3840}
3841
3842/// Represent an INTERSECT set operation between two query expressions.
3843///
3844/// Returns only rows that appear in both operands. When `all` is true,
3845/// duplicates are preserved according to their multiplicity.
3846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3847#[cfg_attr(feature = "bindings", derive(TS))]
3848pub struct Intersect {
3849    /// The left-hand query operand.
3850    pub left: Expression,
3851    /// The right-hand query operand.
3852    pub right: Expression,
3853    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3854    pub all: bool,
3855    /// Whether DISTINCT was explicitly specified
3856    #[serde(default)]
3857    pub distinct: bool,
3858    /// Optional WITH clause
3859    pub with: Option<With>,
3860    /// ORDER BY applied to entire INTERSECT result
3861    pub order_by: Option<OrderBy>,
3862    /// LIMIT applied to entire INTERSECT result
3863    pub limit: Option<Box<Expression>>,
3864    /// OFFSET applied to entire INTERSECT result
3865    pub offset: Option<Box<Expression>>,
3866    /// DISTRIBUTE BY clause (Hive/Spark)
3867    #[serde(default, skip_serializing_if = "Option::is_none")]
3868    pub distribute_by: Option<DistributeBy>,
3869    /// SORT BY clause (Hive/Spark)
3870    #[serde(default, skip_serializing_if = "Option::is_none")]
3871    pub sort_by: Option<SortBy>,
3872    /// CLUSTER BY clause (Hive/Spark)
3873    #[serde(default, skip_serializing_if = "Option::is_none")]
3874    pub cluster_by: Option<ClusterBy>,
3875    /// DuckDB BY NAME modifier
3876    #[serde(default)]
3877    pub by_name: bool,
3878    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3879    #[serde(default, skip_serializing_if = "Option::is_none")]
3880    pub side: Option<String>,
3881    /// BigQuery: Set operation kind (INNER)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub kind: Option<String>,
3884    /// BigQuery: CORRESPONDING modifier
3885    #[serde(default)]
3886    pub corresponding: bool,
3887    /// BigQuery: STRICT modifier (before CORRESPONDING)
3888    #[serde(default)]
3889    pub strict: bool,
3890    /// BigQuery: BY (columns) after CORRESPONDING
3891    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3892    pub on_columns: Vec<Expression>,
3893}
3894
3895impl Drop for Intersect {
3896    fn drop(&mut self) {
3897        loop {
3898            if let Expression::Intersect(ref mut inner) = self.left {
3899                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3900                let old_left = std::mem::replace(&mut self.left, next_left);
3901                drop(old_left);
3902            } else {
3903                break;
3904            }
3905        }
3906    }
3907}
3908
3909/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3910///
3911/// Returns rows from the left operand that do not appear in the right operand.
3912/// When `all` is true, duplicates are subtracted according to their multiplicity.
3913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3914#[cfg_attr(feature = "bindings", derive(TS))]
3915pub struct Except {
3916    /// The left-hand query operand.
3917    pub left: Expression,
3918    /// The right-hand query operand (rows to subtract).
3919    pub right: Expression,
3920    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3921    pub all: bool,
3922    /// Whether DISTINCT was explicitly specified
3923    #[serde(default)]
3924    pub distinct: bool,
3925    /// Optional WITH clause
3926    pub with: Option<With>,
3927    /// ORDER BY applied to entire EXCEPT result
3928    pub order_by: Option<OrderBy>,
3929    /// LIMIT applied to entire EXCEPT result
3930    pub limit: Option<Box<Expression>>,
3931    /// OFFSET applied to entire EXCEPT result
3932    pub offset: Option<Box<Expression>>,
3933    /// DISTRIBUTE BY clause (Hive/Spark)
3934    #[serde(default, skip_serializing_if = "Option::is_none")]
3935    pub distribute_by: Option<DistributeBy>,
3936    /// SORT BY clause (Hive/Spark)
3937    #[serde(default, skip_serializing_if = "Option::is_none")]
3938    pub sort_by: Option<SortBy>,
3939    /// CLUSTER BY clause (Hive/Spark)
3940    #[serde(default, skip_serializing_if = "Option::is_none")]
3941    pub cluster_by: Option<ClusterBy>,
3942    /// DuckDB BY NAME modifier
3943    #[serde(default)]
3944    pub by_name: bool,
3945    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3946    #[serde(default, skip_serializing_if = "Option::is_none")]
3947    pub side: Option<String>,
3948    /// BigQuery: Set operation kind (INNER)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub kind: Option<String>,
3951    /// BigQuery: CORRESPONDING modifier
3952    #[serde(default)]
3953    pub corresponding: bool,
3954    /// BigQuery: STRICT modifier (before CORRESPONDING)
3955    #[serde(default)]
3956    pub strict: bool,
3957    /// BigQuery: BY (columns) after CORRESPONDING
3958    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3959    pub on_columns: Vec<Expression>,
3960}
3961
3962impl Drop for Except {
3963    fn drop(&mut self) {
3964        loop {
3965            if let Expression::Except(ref mut inner) = self.left {
3966                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3967                let old_left = std::mem::replace(&mut self.left, next_left);
3968                drop(old_left);
3969            } else {
3970                break;
3971            }
3972        }
3973    }
3974}
3975
3976/// INTO clause for SELECT INTO statements
3977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3978#[cfg_attr(feature = "bindings", derive(TS))]
3979pub struct SelectInto {
3980    /// Target table or variable (used when single target)
3981    pub this: Expression,
3982    /// Whether TEMPORARY keyword was used
3983    #[serde(default)]
3984    pub temporary: bool,
3985    /// Whether UNLOGGED keyword was used (PostgreSQL)
3986    #[serde(default)]
3987    pub unlogged: bool,
3988    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3989    #[serde(default)]
3990    pub bulk_collect: bool,
3991    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3992    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3993    pub expressions: Vec<Expression>,
3994}
3995
3996/// Represent a parenthesized subquery expression.
3997///
3998/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3999/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4000/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4001/// modifiers are rendered inside or outside the parentheses.
4002///
4003/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4004/// scalar subqueries in select-lists, and derived tables.
4005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4006#[cfg_attr(feature = "bindings", derive(TS))]
4007pub struct Subquery {
4008    /// The inner query expression.
4009    pub this: Expression,
4010    /// Optional alias for the derived table.
4011    pub alias: Option<Identifier>,
4012    /// Optional column aliases: AS t(c1, c2)
4013    pub column_aliases: Vec<Identifier>,
4014    /// ORDER BY clause (for parenthesized queries)
4015    pub order_by: Option<OrderBy>,
4016    /// LIMIT clause
4017    pub limit: Option<Limit>,
4018    /// OFFSET clause
4019    pub offset: Option<Offset>,
4020    /// DISTRIBUTE BY clause (Hive/Spark)
4021    #[serde(default, skip_serializing_if = "Option::is_none")]
4022    pub distribute_by: Option<DistributeBy>,
4023    /// SORT BY clause (Hive/Spark)
4024    #[serde(default, skip_serializing_if = "Option::is_none")]
4025    pub sort_by: Option<SortBy>,
4026    /// CLUSTER BY clause (Hive/Spark)
4027    #[serde(default, skip_serializing_if = "Option::is_none")]
4028    pub cluster_by: Option<ClusterBy>,
4029    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4030    #[serde(default)]
4031    pub lateral: bool,
4032    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4033    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4034    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4035    #[serde(default)]
4036    pub modifiers_inside: bool,
4037    /// Trailing comments after the closing paren
4038    #[serde(default)]
4039    pub trailing_comments: Vec<String>,
4040    /// Inferred data type from type annotation
4041    #[serde(default, skip_serializing_if = "Option::is_none")]
4042    pub inferred_type: Option<DataType>,
4043}
4044
4045/// Pipe operator expression: query |> transform
4046///
4047/// Used in DataFusion and BigQuery pipe syntax:
4048///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4050#[cfg_attr(feature = "bindings", derive(TS))]
4051pub struct PipeOperator {
4052    /// The input query/expression (left side of |>)
4053    pub this: Expression,
4054    /// The piped operation (right side of |>)
4055    pub expression: Expression,
4056}
4057
4058/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4060#[cfg_attr(feature = "bindings", derive(TS))]
4061pub struct Values {
4062    /// The rows of values
4063    pub expressions: Vec<Tuple>,
4064    /// Optional alias for the table
4065    pub alias: Option<Identifier>,
4066    /// Optional column aliases: AS t(c1, c2)
4067    pub column_aliases: Vec<Identifier>,
4068}
4069
4070/// PIVOT operation - supports both standard and DuckDB simplified syntax
4071///
4072/// Standard syntax (in FROM clause):
4073///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4074///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4075///
4076/// DuckDB simplified syntax (statement-level):
4077///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4078///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4080#[cfg_attr(feature = "bindings", derive(TS))]
4081pub struct Pivot {
4082    /// Source table/expression
4083    pub this: Expression,
4084    /// For standard PIVOT: the aggregation function(s) (first is primary)
4085    /// For DuckDB simplified: unused (use `using` instead)
4086    #[serde(default)]
4087    pub expressions: Vec<Expression>,
4088    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4089    #[serde(default)]
4090    pub fields: Vec<Expression>,
4091    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4092    #[serde(default)]
4093    pub using: Vec<Expression>,
4094    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4095    #[serde(default)]
4096    pub group: Option<Box<Expression>>,
4097    /// Whether this is an UNPIVOT (vs PIVOT)
4098    #[serde(default)]
4099    pub unpivot: bool,
4100    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4101    #[serde(default)]
4102    pub into: Option<Box<Expression>>,
4103    /// Optional alias
4104    #[serde(default)]
4105    pub alias: Option<Identifier>,
4106    /// Include/exclude nulls (for UNPIVOT)
4107    #[serde(default)]
4108    pub include_nulls: Option<bool>,
4109    /// Default on null value (Snowflake)
4110    #[serde(default)]
4111    pub default_on_null: Option<Box<Expression>>,
4112    /// WITH clause (CTEs)
4113    #[serde(default, skip_serializing_if = "Option::is_none")]
4114    pub with: Option<With>,
4115}
4116
4117/// UNPIVOT operation
4118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4119#[cfg_attr(feature = "bindings", derive(TS))]
4120pub struct Unpivot {
4121    pub this: Expression,
4122    pub value_column: Identifier,
4123    pub name_column: Identifier,
4124    pub columns: Vec<Expression>,
4125    pub alias: Option<Identifier>,
4126    /// Whether the value_column was parenthesized in the original SQL
4127    #[serde(default)]
4128    pub value_column_parenthesized: bool,
4129    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4130    #[serde(default)]
4131    pub include_nulls: Option<bool>,
4132    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4133    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4134    pub extra_value_columns: Vec<Identifier>,
4135}
4136
4137/// PIVOT alias for aliasing pivot expressions
4138/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4140#[cfg_attr(feature = "bindings", derive(TS))]
4141pub struct PivotAlias {
4142    pub this: Expression,
4143    pub alias: Expression,
4144}
4145
4146/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4148#[cfg_attr(feature = "bindings", derive(TS))]
4149pub struct PreWhere {
4150    pub this: Expression,
4151}
4152
4153/// STREAM definition (Snowflake) - for change data capture
4154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4155#[cfg_attr(feature = "bindings", derive(TS))]
4156pub struct Stream {
4157    pub this: Expression,
4158    #[serde(skip_serializing_if = "Option::is_none")]
4159    pub on: Option<Expression>,
4160    #[serde(skip_serializing_if = "Option::is_none")]
4161    pub show_initial_rows: Option<bool>,
4162}
4163
4164/// USING DATA clause for data import statements
4165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub struct UsingData {
4168    pub this: Expression,
4169}
4170
4171/// XML Namespace declaration
4172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4173#[cfg_attr(feature = "bindings", derive(TS))]
4174pub struct XmlNamespace {
4175    pub this: Expression,
4176    #[serde(skip_serializing_if = "Option::is_none")]
4177    pub alias: Option<Identifier>,
4178}
4179
4180/// ROW FORMAT clause for Hive/Spark
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct RowFormat {
4184    pub delimited: bool,
4185    pub fields_terminated_by: Option<String>,
4186    pub collection_items_terminated_by: Option<String>,
4187    pub map_keys_terminated_by: Option<String>,
4188    pub lines_terminated_by: Option<String>,
4189    pub null_defined_as: Option<String>,
4190}
4191
4192/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub struct DirectoryInsert {
4196    pub local: bool,
4197    pub path: String,
4198    pub row_format: Option<RowFormat>,
4199    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4200    #[serde(default)]
4201    pub stored_as: Option<String>,
4202}
4203
4204/// INSERT statement
4205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4206#[cfg_attr(feature = "bindings", derive(TS))]
4207pub struct Insert {
4208    pub table: TableRef,
4209    pub columns: Vec<Identifier>,
4210    pub values: Vec<Vec<Expression>>,
4211    pub query: Option<Expression>,
4212    /// INSERT OVERWRITE for Hive/Spark
4213    pub overwrite: bool,
4214    /// PARTITION clause for Hive/Spark
4215    pub partition: Vec<(Identifier, Option<Expression>)>,
4216    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4217    #[serde(default)]
4218    pub directory: Option<DirectoryInsert>,
4219    /// RETURNING clause (PostgreSQL, SQLite)
4220    #[serde(default)]
4221    pub returning: Vec<Expression>,
4222    /// OUTPUT clause (TSQL)
4223    #[serde(default)]
4224    pub output: Option<OutputClause>,
4225    /// ON CONFLICT clause (PostgreSQL, SQLite)
4226    #[serde(default)]
4227    pub on_conflict: Option<Box<Expression>>,
4228    /// Leading comments before the statement
4229    #[serde(default)]
4230    pub leading_comments: Vec<String>,
4231    /// IF EXISTS clause (Hive)
4232    #[serde(default)]
4233    pub if_exists: bool,
4234    /// WITH clause (CTEs)
4235    #[serde(default)]
4236    pub with: Option<With>,
4237    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4238    #[serde(default)]
4239    pub ignore: bool,
4240    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4241    #[serde(default)]
4242    pub source_alias: Option<Identifier>,
4243    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4244    #[serde(default)]
4245    pub alias: Option<Identifier>,
4246    /// Whether the alias uses explicit AS keyword
4247    #[serde(default)]
4248    pub alias_explicit_as: bool,
4249    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4250    #[serde(default)]
4251    pub default_values: bool,
4252    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4253    #[serde(default)]
4254    pub by_name: bool,
4255    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4256    #[serde(default, skip_serializing_if = "Option::is_none")]
4257    pub conflict_action: Option<String>,
4258    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4259    #[serde(default)]
4260    pub is_replace: bool,
4261    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4262    #[serde(default, skip_serializing_if = "Option::is_none")]
4263    pub hint: Option<Hint>,
4264    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4265    #[serde(default)]
4266    pub replace_where: Option<Box<Expression>>,
4267    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4268    #[serde(default)]
4269    pub source: Option<Box<Expression>>,
4270    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4271    #[serde(default, skip_serializing_if = "Option::is_none")]
4272    pub function_target: Option<Box<Expression>>,
4273    /// ClickHouse: PARTITION BY expr
4274    #[serde(default, skip_serializing_if = "Option::is_none")]
4275    pub partition_by: Option<Box<Expression>>,
4276    /// ClickHouse: SETTINGS key = val, ...
4277    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4278    pub settings: Vec<Expression>,
4279}
4280
4281/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4283#[cfg_attr(feature = "bindings", derive(TS))]
4284pub struct OutputClause {
4285    /// Columns/expressions to output
4286    pub columns: Vec<Expression>,
4287    /// Optional INTO target table or table variable
4288    #[serde(default)]
4289    pub into_table: Option<Expression>,
4290}
4291
4292/// UPDATE statement
4293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4294#[cfg_attr(feature = "bindings", derive(TS))]
4295pub struct Update {
4296    pub table: TableRef,
4297    /// Additional tables for multi-table UPDATE (MySQL syntax)
4298    #[serde(default)]
4299    pub extra_tables: Vec<TableRef>,
4300    /// JOINs attached to the table list (MySQL multi-table syntax)
4301    #[serde(default)]
4302    pub table_joins: Vec<Join>,
4303    pub set: Vec<(Identifier, Expression)>,
4304    pub from_clause: Option<From>,
4305    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4306    #[serde(default)]
4307    pub from_joins: Vec<Join>,
4308    pub where_clause: Option<Where>,
4309    /// RETURNING clause (PostgreSQL, SQLite)
4310    #[serde(default)]
4311    pub returning: Vec<Expression>,
4312    /// OUTPUT clause (TSQL)
4313    #[serde(default)]
4314    pub output: Option<OutputClause>,
4315    /// WITH clause (CTEs)
4316    #[serde(default)]
4317    pub with: Option<With>,
4318    /// Leading comments before the statement
4319    #[serde(default)]
4320    pub leading_comments: Vec<String>,
4321    /// LIMIT clause (MySQL)
4322    #[serde(default)]
4323    pub limit: Option<Expression>,
4324    /// ORDER BY clause (MySQL)
4325    #[serde(default)]
4326    pub order_by: Option<OrderBy>,
4327    /// Whether FROM clause appears before SET (Snowflake syntax)
4328    #[serde(default)]
4329    pub from_before_set: bool,
4330}
4331
4332/// DELETE statement
4333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4334#[cfg_attr(feature = "bindings", derive(TS))]
4335pub struct Delete {
4336    pub table: TableRef,
4337    /// ClickHouse: ON CLUSTER clause for distributed DDL
4338    #[serde(default, skip_serializing_if = "Option::is_none")]
4339    pub on_cluster: Option<OnCluster>,
4340    /// Optional alias for the table
4341    pub alias: Option<Identifier>,
4342    /// Whether the alias was declared with explicit AS keyword
4343    #[serde(default)]
4344    pub alias_explicit_as: bool,
4345    /// PostgreSQL/DuckDB USING clause - additional tables to join
4346    pub using: Vec<TableRef>,
4347    pub where_clause: Option<Where>,
4348    /// OUTPUT clause (TSQL)
4349    #[serde(default)]
4350    pub output: Option<OutputClause>,
4351    /// Leading comments before the statement
4352    #[serde(default)]
4353    pub leading_comments: Vec<String>,
4354    /// WITH clause (CTEs)
4355    #[serde(default)]
4356    pub with: Option<With>,
4357    /// LIMIT clause (MySQL)
4358    #[serde(default)]
4359    pub limit: Option<Expression>,
4360    /// ORDER BY clause (MySQL)
4361    #[serde(default)]
4362    pub order_by: Option<OrderBy>,
4363    /// RETURNING clause (PostgreSQL)
4364    #[serde(default)]
4365    pub returning: Vec<Expression>,
4366    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4367    /// These are the target tables to delete from
4368    #[serde(default)]
4369    pub tables: Vec<TableRef>,
4370    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4371    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4372    #[serde(default)]
4373    pub tables_from_using: bool,
4374    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4375    #[serde(default)]
4376    pub joins: Vec<Join>,
4377    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4378    #[serde(default)]
4379    pub force_index: Option<String>,
4380    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4381    #[serde(default)]
4382    pub no_from: bool,
4383}
4384
4385/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4387#[cfg_attr(feature = "bindings", derive(TS))]
4388pub struct CopyStmt {
4389    /// Target table or query
4390    pub this: Expression,
4391    /// True for FROM (loading into table), false for TO (exporting)
4392    pub kind: bool,
4393    /// Source/destination file(s) or stage
4394    pub files: Vec<Expression>,
4395    /// Copy parameters
4396    #[serde(default)]
4397    pub params: Vec<CopyParameter>,
4398    /// Credentials for external access
4399    #[serde(default)]
4400    pub credentials: Option<Box<Credentials>>,
4401    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4402    #[serde(default)]
4403    pub is_into: bool,
4404    /// Whether parameters are wrapped in WITH (...) syntax
4405    #[serde(default)]
4406    pub with_wrapped: bool,
4407}
4408
4409/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4411#[cfg_attr(feature = "bindings", derive(TS))]
4412pub struct CopyParameter {
4413    pub name: String,
4414    pub value: Option<Expression>,
4415    pub values: Vec<Expression>,
4416    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4417    #[serde(default)]
4418    pub eq: bool,
4419}
4420
4421/// Credentials for external access (S3, Azure, etc.)
4422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4423#[cfg_attr(feature = "bindings", derive(TS))]
4424pub struct Credentials {
4425    pub credentials: Vec<(String, String)>,
4426    pub encryption: Option<String>,
4427    pub storage: Option<String>,
4428}
4429
4430/// PUT statement (Snowflake)
4431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4432#[cfg_attr(feature = "bindings", derive(TS))]
4433pub struct PutStmt {
4434    /// Source file path
4435    pub source: String,
4436    /// Whether source was quoted in the original SQL
4437    #[serde(default)]
4438    pub source_quoted: bool,
4439    /// Target stage
4440    pub target: Expression,
4441    /// PUT parameters
4442    #[serde(default)]
4443    pub params: Vec<CopyParameter>,
4444}
4445
4446/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct StageReference {
4450    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4451    pub name: String,
4452    /// Optional path within the stage (e.g., "/path/to/file.csv")
4453    #[serde(default)]
4454    pub path: Option<String>,
4455    /// Optional FILE_FORMAT parameter
4456    #[serde(default)]
4457    pub file_format: Option<Expression>,
4458    /// Optional PATTERN parameter
4459    #[serde(default)]
4460    pub pattern: Option<String>,
4461    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4462    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4463    pub quoted: bool,
4464}
4465
4466/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4468#[cfg_attr(feature = "bindings", derive(TS))]
4469pub struct HistoricalData {
4470    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4471    pub this: Box<Expression>,
4472    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4473    pub kind: String,
4474    /// The expression value (e.g., the statement ID or timestamp)
4475    pub expression: Box<Expression>,
4476}
4477
4478/// Represent an aliased expression (`expr AS name`).
4479///
4480/// Used for column aliases in select-lists, table aliases on subqueries,
4481/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4483#[cfg_attr(feature = "bindings", derive(TS))]
4484pub struct Alias {
4485    /// The expression being aliased.
4486    pub this: Expression,
4487    /// The alias name (required for simple aliases, optional when only column aliases provided)
4488    pub alias: Identifier,
4489    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4490    #[serde(default)]
4491    pub column_aliases: Vec<Identifier>,
4492    /// Comments that appeared between the expression and AS keyword
4493    #[serde(default)]
4494    pub pre_alias_comments: Vec<String>,
4495    /// Trailing comments that appeared after the alias
4496    #[serde(default)]
4497    pub trailing_comments: Vec<String>,
4498    /// Inferred data type from type annotation
4499    #[serde(default, skip_serializing_if = "Option::is_none")]
4500    pub inferred_type: Option<DataType>,
4501}
4502
4503impl Alias {
4504    /// Create a simple alias
4505    pub fn new(this: Expression, alias: Identifier) -> Self {
4506        Self {
4507            this,
4508            alias,
4509            column_aliases: Vec::new(),
4510            pre_alias_comments: Vec::new(),
4511            trailing_comments: Vec::new(),
4512            inferred_type: None,
4513        }
4514    }
4515
4516    /// Create an alias with column aliases only (no table alias name)
4517    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4518        Self {
4519            this,
4520            alias: Identifier::empty(),
4521            column_aliases,
4522            pre_alias_comments: Vec::new(),
4523            trailing_comments: Vec::new(),
4524            inferred_type: None,
4525        }
4526    }
4527}
4528
4529/// Represent a type cast expression.
4530///
4531/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4532/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4533/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4534/// CONVERSION ERROR (Oracle) clauses.
4535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4536#[cfg_attr(feature = "bindings", derive(TS))]
4537pub struct Cast {
4538    /// The expression being cast.
4539    pub this: Expression,
4540    /// The target data type.
4541    pub to: DataType,
4542    #[serde(default)]
4543    pub trailing_comments: Vec<String>,
4544    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4545    #[serde(default)]
4546    pub double_colon_syntax: bool,
4547    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4548    #[serde(skip_serializing_if = "Option::is_none", default)]
4549    pub format: Option<Box<Expression>>,
4550    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4551    #[serde(skip_serializing_if = "Option::is_none", default)]
4552    pub default: Option<Box<Expression>>,
4553    /// Inferred data type from type annotation
4554    #[serde(default, skip_serializing_if = "Option::is_none")]
4555    pub inferred_type: Option<DataType>,
4556}
4557
4558///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4560#[cfg_attr(feature = "bindings", derive(TS))]
4561pub struct CollationExpr {
4562    pub this: Expression,
4563    pub collation: String,
4564    /// True if the collation was single-quoted in the original SQL (string literal)
4565    #[serde(default)]
4566    pub quoted: bool,
4567    /// True if the collation was double-quoted in the original SQL (identifier)
4568    #[serde(default)]
4569    pub double_quoted: bool,
4570}
4571
4572/// Represent a CASE expression (both simple and searched forms).
4573///
4574/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4575/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4576/// Each entry in `whens` is a `(condition, result)` pair.
4577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4578#[cfg_attr(feature = "bindings", derive(TS))]
4579pub struct Case {
4580    /// The operand for simple CASE, or `None` for searched CASE.
4581    pub operand: Option<Expression>,
4582    /// Pairs of (WHEN condition, THEN result).
4583    pub whens: Vec<(Expression, Expression)>,
4584    /// Optional ELSE result.
4585    pub else_: Option<Expression>,
4586    /// Comments from the CASE keyword (emitted after END)
4587    #[serde(default)]
4588    #[serde(skip_serializing_if = "Vec::is_empty")]
4589    pub comments: Vec<String>,
4590    /// Inferred data type from type annotation
4591    #[serde(default, skip_serializing_if = "Option::is_none")]
4592    pub inferred_type: Option<DataType>,
4593}
4594
4595/// Represent a binary operation (two operands separated by an operator).
4596///
4597/// This is the shared payload struct for all binary operator variants in the
4598/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4599/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4600/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4601/// preservation of inline comments around operators.
4602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4603#[cfg_attr(feature = "bindings", derive(TS))]
4604pub struct BinaryOp {
4605    pub left: Expression,
4606    pub right: Expression,
4607    /// Comments after the left operand (before the operator)
4608    #[serde(default)]
4609    pub left_comments: Vec<String>,
4610    /// Comments after the operator (before the right operand)
4611    #[serde(default)]
4612    pub operator_comments: Vec<String>,
4613    /// Comments after the right operand
4614    #[serde(default)]
4615    pub trailing_comments: Vec<String>,
4616    /// Inferred data type from type annotation
4617    #[serde(default, skip_serializing_if = "Option::is_none")]
4618    pub inferred_type: Option<DataType>,
4619}
4620
4621impl BinaryOp {
4622    pub fn new(left: Expression, right: Expression) -> Self {
4623        Self {
4624            left,
4625            right,
4626            left_comments: Vec::new(),
4627            operator_comments: Vec::new(),
4628            trailing_comments: Vec::new(),
4629            inferred_type: None,
4630        }
4631    }
4632}
4633
4634/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4636#[cfg_attr(feature = "bindings", derive(TS))]
4637pub struct LikeOp {
4638    pub left: Expression,
4639    pub right: Expression,
4640    /// ESCAPE character/expression
4641    #[serde(default)]
4642    pub escape: Option<Expression>,
4643    /// Quantifier: ANY, ALL, or SOME
4644    #[serde(default)]
4645    pub quantifier: Option<String>,
4646    /// Inferred data type from type annotation
4647    #[serde(default, skip_serializing_if = "Option::is_none")]
4648    pub inferred_type: Option<DataType>,
4649}
4650
4651impl LikeOp {
4652    pub fn new(left: Expression, right: Expression) -> Self {
4653        Self {
4654            left,
4655            right,
4656            escape: None,
4657            quantifier: None,
4658            inferred_type: None,
4659        }
4660    }
4661
4662    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4663        Self {
4664            left,
4665            right,
4666            escape: Some(escape),
4667            quantifier: None,
4668            inferred_type: None,
4669        }
4670    }
4671}
4672
4673/// Represent a unary operation (single operand with a prefix operator).
4674///
4675/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4677#[cfg_attr(feature = "bindings", derive(TS))]
4678pub struct UnaryOp {
4679    /// The operand expression.
4680    pub this: Expression,
4681    /// Inferred data type from type annotation
4682    #[serde(default, skip_serializing_if = "Option::is_none")]
4683    pub inferred_type: Option<DataType>,
4684}
4685
4686impl UnaryOp {
4687    pub fn new(this: Expression) -> Self {
4688        Self {
4689            this,
4690            inferred_type: None,
4691        }
4692    }
4693}
4694
4695/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4696///
4697/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4698/// but not both. When `not` is true, the predicate is `NOT IN`.
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct In {
4702    /// The expression being tested.
4703    pub this: Expression,
4704    /// The value list (mutually exclusive with `query`).
4705    pub expressions: Vec<Expression>,
4706    /// A subquery (mutually exclusive with `expressions`).
4707    pub query: Option<Expression>,
4708    /// Whether this is NOT IN.
4709    pub not: bool,
4710    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4711    pub global: bool,
4712    /// BigQuery: IN UNNEST(expr)
4713    #[serde(default, skip_serializing_if = "Option::is_none")]
4714    pub unnest: Option<Box<Expression>>,
4715    /// Whether the right side is a bare field reference (no parentheses).
4716    /// Matches Python sqlglot's `field` attribute on `In` expression.
4717    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4718    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4719    pub is_field: bool,
4720}
4721
4722/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4724#[cfg_attr(feature = "bindings", derive(TS))]
4725pub struct Between {
4726    /// The expression being tested.
4727    pub this: Expression,
4728    /// The lower bound.
4729    pub low: Expression,
4730    /// The upper bound.
4731    pub high: Expression,
4732    /// Whether this is NOT BETWEEN.
4733    pub not: bool,
4734    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4735    #[serde(default)]
4736    pub symmetric: Option<bool>,
4737}
4738
4739/// IS NULL predicate
4740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4741#[cfg_attr(feature = "bindings", derive(TS))]
4742pub struct IsNull {
4743    pub this: Expression,
4744    pub not: bool,
4745    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4746    #[serde(default)]
4747    pub postfix_form: bool,
4748}
4749
4750/// IS TRUE / IS FALSE predicate
4751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4752#[cfg_attr(feature = "bindings", derive(TS))]
4753pub struct IsTrueFalse {
4754    pub this: Expression,
4755    pub not: bool,
4756}
4757
4758/// IS JSON predicate (SQL standard)
4759/// Checks if a value is valid JSON
4760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4761#[cfg_attr(feature = "bindings", derive(TS))]
4762pub struct IsJson {
4763    pub this: Expression,
4764    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4765    pub json_type: Option<String>,
4766    /// Key uniqueness constraint
4767    pub unique_keys: Option<JsonUniqueKeys>,
4768    /// Whether IS NOT JSON
4769    pub negated: bool,
4770}
4771
4772/// JSON unique keys constraint variants
4773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4774#[cfg_attr(feature = "bindings", derive(TS))]
4775pub enum JsonUniqueKeys {
4776    /// WITH UNIQUE KEYS
4777    With,
4778    /// WITHOUT UNIQUE KEYS
4779    Without,
4780    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4781    Shorthand,
4782}
4783
4784/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4786#[cfg_attr(feature = "bindings", derive(TS))]
4787pub struct Exists {
4788    /// The subquery expression.
4789    pub this: Expression,
4790    /// Whether this is NOT EXISTS.
4791    pub not: bool,
4792}
4793
4794/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4795///
4796/// This is the generic function node. Well-known aggregates, window functions,
4797/// and built-in functions each have their own dedicated `Expression` variants
4798/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4799/// not recognize as built-ins are represented with this struct.
4800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4801#[cfg_attr(feature = "bindings", derive(TS))]
4802pub struct Function {
4803    /// The function name, as originally written (may be schema-qualified).
4804    pub name: String,
4805    /// Positional arguments to the function.
4806    pub args: Vec<Expression>,
4807    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4808    pub distinct: bool,
4809    #[serde(default)]
4810    pub trailing_comments: Vec<String>,
4811    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4812    #[serde(default)]
4813    pub use_bracket_syntax: bool,
4814    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4815    #[serde(default)]
4816    pub no_parens: bool,
4817    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4818    #[serde(default)]
4819    pub quoted: bool,
4820    /// Source position span
4821    #[serde(default, skip_serializing_if = "Option::is_none")]
4822    pub span: Option<Span>,
4823    /// Inferred data type from type annotation
4824    #[serde(default, skip_serializing_if = "Option::is_none")]
4825    pub inferred_type: Option<DataType>,
4826}
4827
4828impl Default for Function {
4829    fn default() -> Self {
4830        Self {
4831            name: String::new(),
4832            args: Vec::new(),
4833            distinct: false,
4834            trailing_comments: Vec::new(),
4835            use_bracket_syntax: false,
4836            no_parens: false,
4837            quoted: false,
4838            span: None,
4839            inferred_type: None,
4840        }
4841    }
4842}
4843
4844impl Function {
4845    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4846        Self {
4847            name: name.into(),
4848            args,
4849            distinct: false,
4850            trailing_comments: Vec::new(),
4851            use_bracket_syntax: false,
4852            no_parens: false,
4853            quoted: false,
4854            span: None,
4855            inferred_type: None,
4856        }
4857    }
4858}
4859
4860/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4861///
4862/// This struct is used for aggregate function calls that are not covered by
4863/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4864/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4865/// IGNORE NULLS / RESPECT NULLS modifiers.
4866#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4867#[cfg_attr(feature = "bindings", derive(TS))]
4868pub struct AggregateFunction {
4869    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4870    pub name: String,
4871    /// Positional arguments.
4872    pub args: Vec<Expression>,
4873    /// Whether DISTINCT was specified.
4874    pub distinct: bool,
4875    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4876    pub filter: Option<Expression>,
4877    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4878    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4879    pub order_by: Vec<Ordered>,
4880    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4881    #[serde(default, skip_serializing_if = "Option::is_none")]
4882    pub limit: Option<Box<Expression>>,
4883    /// IGNORE NULLS / RESPECT NULLS
4884    #[serde(default, skip_serializing_if = "Option::is_none")]
4885    pub ignore_nulls: Option<bool>,
4886    /// Inferred data type from type annotation
4887    #[serde(default, skip_serializing_if = "Option::is_none")]
4888    pub inferred_type: Option<DataType>,
4889}
4890
4891/// Represent a window function call with its OVER clause.
4892///
4893/// The inner `this` expression is typically a window-specific expression
4894/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4895/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4896/// frame specification.
4897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4898#[cfg_attr(feature = "bindings", derive(TS))]
4899pub struct WindowFunction {
4900    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4901    pub this: Expression,
4902    /// The OVER clause defining the window partitioning, ordering, and frame.
4903    pub over: Over,
4904    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4905    #[serde(default, skip_serializing_if = "Option::is_none")]
4906    pub keep: Option<Keep>,
4907    /// Inferred data type from type annotation
4908    #[serde(default, skip_serializing_if = "Option::is_none")]
4909    pub inferred_type: Option<DataType>,
4910}
4911
4912/// Oracle KEEP clause for aggregate functions
4913/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4915#[cfg_attr(feature = "bindings", derive(TS))]
4916pub struct Keep {
4917    /// true = FIRST, false = LAST
4918    pub first: bool,
4919    /// ORDER BY clause inside KEEP
4920    pub order_by: Vec<Ordered>,
4921}
4922
4923/// WITHIN GROUP clause (for ordered-set aggregate functions)
4924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4925#[cfg_attr(feature = "bindings", derive(TS))]
4926pub struct WithinGroup {
4927    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4928    pub this: Expression,
4929    /// The ORDER BY clause within the group
4930    pub order_by: Vec<Ordered>,
4931}
4932
4933/// Represent the FROM clause of a SELECT statement.
4934///
4935/// Contains one or more table sources (tables, subqueries, table-valued
4936/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4938#[cfg_attr(feature = "bindings", derive(TS))]
4939pub struct From {
4940    /// The table source expressions.
4941    pub expressions: Vec<Expression>,
4942}
4943
4944/// Represent a JOIN clause between two table sources.
4945///
4946/// The join condition can be specified via `on` (ON predicate) or `using`
4947/// (USING column list), but not both. The `kind` field determines the join
4948/// type (INNER, LEFT, CROSS, etc.).
4949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4950#[cfg_attr(feature = "bindings", derive(TS))]
4951pub struct Join {
4952    /// The right-hand table expression being joined.
4953    pub this: Expression,
4954    /// The ON condition (mutually exclusive with `using`).
4955    pub on: Option<Expression>,
4956    /// The USING column list (mutually exclusive with `on`).
4957    pub using: Vec<Identifier>,
4958    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4959    pub kind: JoinKind,
4960    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4961    pub use_inner_keyword: bool,
4962    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4963    pub use_outer_keyword: bool,
4964    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4965    pub deferred_condition: bool,
4966    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4967    #[serde(default, skip_serializing_if = "Option::is_none")]
4968    pub join_hint: Option<String>,
4969    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4970    #[serde(default, skip_serializing_if = "Option::is_none")]
4971    pub match_condition: Option<Expression>,
4972    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4973    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4974    pub pivots: Vec<Expression>,
4975    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4976    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4977    pub comments: Vec<String>,
4978    /// Nesting group identifier for nested join pretty-printing.
4979    /// Joins in the same group were parsed together; group boundaries come from
4980    /// deferred condition resolution phases.
4981    #[serde(default)]
4982    pub nesting_group: usize,
4983    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4984    #[serde(default)]
4985    pub directed: bool,
4986}
4987
4988/// Enumerate all supported SQL join types.
4989///
4990/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4991/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4992/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4993/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4994#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4995#[cfg_attr(feature = "bindings", derive(TS))]
4996pub enum JoinKind {
4997    Inner,
4998    Left,
4999    Right,
5000    Full,
5001    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5002    Cross,
5003    Natural,
5004    NaturalLeft,
5005    NaturalRight,
5006    NaturalFull,
5007    Semi,
5008    Anti,
5009    // Directional SEMI/ANTI joins
5010    LeftSemi,
5011    LeftAnti,
5012    RightSemi,
5013    RightAnti,
5014    // SQL Server specific
5015    CrossApply,
5016    OuterApply,
5017    // Time-series specific
5018    AsOf,
5019    AsOfLeft,
5020    AsOfRight,
5021    // Lateral join
5022    Lateral,
5023    LeftLateral,
5024    // MySQL specific
5025    Straight,
5026    // Implicit join (comma-separated tables: FROM a, b)
5027    Implicit,
5028    // ClickHouse ARRAY JOIN
5029    Array,
5030    LeftArray,
5031    // ClickHouse PASTE JOIN (positional join)
5032    Paste,
5033    // DuckDB POSITIONAL JOIN
5034    Positional,
5035}
5036
5037impl Default for JoinKind {
5038    fn default() -> Self {
5039        JoinKind::Inner
5040    }
5041}
5042
5043/// Parenthesized table expression with joins
5044/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5046#[cfg_attr(feature = "bindings", derive(TS))]
5047pub struct JoinedTable {
5048    /// The left-hand side table expression
5049    pub left: Expression,
5050    /// The joins applied to the left table
5051    pub joins: Vec<Join>,
5052    /// LATERAL VIEW clauses (Hive/Spark)
5053    pub lateral_views: Vec<LateralView>,
5054    /// Optional alias for the joined table expression
5055    pub alias: Option<Identifier>,
5056}
5057
5058/// Represent a WHERE clause containing a boolean filter predicate.
5059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5060#[cfg_attr(feature = "bindings", derive(TS))]
5061pub struct Where {
5062    /// The filter predicate expression.
5063    pub this: Expression,
5064}
5065
5066/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5067///
5068/// The `expressions` list may contain plain columns, ordinal positions,
5069/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5071#[cfg_attr(feature = "bindings", derive(TS))]
5072pub struct GroupBy {
5073    /// The grouping expressions.
5074    pub expressions: Vec<Expression>,
5075    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5076    #[serde(default)]
5077    pub all: Option<bool>,
5078    /// ClickHouse: WITH TOTALS modifier
5079    #[serde(default)]
5080    pub totals: bool,
5081    /// Leading comments that appeared before the GROUP BY keyword
5082    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5083    pub comments: Vec<String>,
5084}
5085
5086/// Represent a HAVING clause containing a predicate over aggregate results.
5087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5088#[cfg_attr(feature = "bindings", derive(TS))]
5089pub struct Having {
5090    /// The filter predicate, typically involving aggregate functions.
5091    pub this: Expression,
5092    /// Leading comments that appeared before the HAVING keyword
5093    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5094    pub comments: Vec<String>,
5095}
5096
5097/// Represent an ORDER BY clause containing one or more sort specifications.
5098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5099#[cfg_attr(feature = "bindings", derive(TS))]
5100pub struct OrderBy {
5101    /// The sort specifications, each with direction and null ordering.
5102    pub expressions: Vec<Ordered>,
5103    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5104    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5105    pub siblings: bool,
5106    /// Leading comments that appeared before the ORDER BY keyword
5107    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5108    pub comments: Vec<String>,
5109}
5110
5111/// Represent an expression with sort direction and null ordering.
5112///
5113/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5114/// When `desc` is false the sort is ascending. The `nulls_first` field
5115/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5116/// (database default).
5117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5118#[cfg_attr(feature = "bindings", derive(TS))]
5119pub struct Ordered {
5120    /// The expression to sort by.
5121    pub this: Expression,
5122    /// Whether the sort direction is descending (true) or ascending (false).
5123    pub desc: bool,
5124    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5125    pub nulls_first: Option<bool>,
5126    /// Whether ASC was explicitly written (not just implied)
5127    #[serde(default)]
5128    pub explicit_asc: bool,
5129    /// ClickHouse WITH FILL clause
5130    #[serde(default, skip_serializing_if = "Option::is_none")]
5131    pub with_fill: Option<Box<WithFill>>,
5132}
5133
5134impl Ordered {
5135    pub fn asc(expr: Expression) -> Self {
5136        Self {
5137            this: expr,
5138            desc: false,
5139            nulls_first: None,
5140            explicit_asc: false,
5141            with_fill: None,
5142        }
5143    }
5144
5145    pub fn desc(expr: Expression) -> Self {
5146        Self {
5147            this: expr,
5148            desc: true,
5149            nulls_first: None,
5150            explicit_asc: false,
5151            with_fill: None,
5152        }
5153    }
5154}
5155
5156/// DISTRIBUTE BY clause (Hive/Spark)
5157/// Controls how rows are distributed across reducers
5158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5159#[cfg_attr(feature = "bindings", derive(TS))]
5160#[cfg_attr(feature = "bindings", ts(export))]
5161pub struct DistributeBy {
5162    pub expressions: Vec<Expression>,
5163}
5164
5165/// CLUSTER BY clause (Hive/Spark)
5166/// Combines DISTRIBUTE BY and SORT BY on the same columns
5167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5168#[cfg_attr(feature = "bindings", derive(TS))]
5169#[cfg_attr(feature = "bindings", ts(export))]
5170pub struct ClusterBy {
5171    pub expressions: Vec<Ordered>,
5172}
5173
5174/// SORT BY clause (Hive/Spark)
5175/// Sorts data within each reducer (local sort, not global)
5176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5177#[cfg_attr(feature = "bindings", derive(TS))]
5178#[cfg_attr(feature = "bindings", ts(export))]
5179pub struct SortBy {
5180    pub expressions: Vec<Ordered>,
5181}
5182
5183/// LATERAL VIEW clause (Hive/Spark)
5184/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5186#[cfg_attr(feature = "bindings", derive(TS))]
5187#[cfg_attr(feature = "bindings", ts(export))]
5188pub struct LateralView {
5189    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5190    pub this: Expression,
5191    /// Table alias for the generated table
5192    pub table_alias: Option<Identifier>,
5193    /// Column aliases for the generated columns
5194    pub column_aliases: Vec<Identifier>,
5195    /// OUTER keyword - preserve nulls when input is empty/null
5196    pub outer: bool,
5197}
5198
5199/// Query hint
5200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5201#[cfg_attr(feature = "bindings", derive(TS))]
5202#[cfg_attr(feature = "bindings", ts(export))]
5203pub struct Hint {
5204    pub expressions: Vec<HintExpression>,
5205}
5206
5207/// Individual hint expression
5208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5209#[cfg_attr(feature = "bindings", derive(TS))]
5210#[cfg_attr(feature = "bindings", ts(export))]
5211pub enum HintExpression {
5212    /// Function-style hint: USE_HASH(table)
5213    Function { name: String, args: Vec<Expression> },
5214    /// Simple identifier hint: PARALLEL
5215    Identifier(String),
5216    /// Raw hint text (unparsed)
5217    Raw(String),
5218}
5219
5220/// Pseudocolumn type
5221#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5222#[cfg_attr(feature = "bindings", derive(TS))]
5223#[cfg_attr(feature = "bindings", ts(export))]
5224pub enum PseudocolumnType {
5225    Rownum,      // Oracle ROWNUM
5226    Rowid,       // Oracle ROWID
5227    Level,       // Oracle LEVEL (for CONNECT BY)
5228    Sysdate,     // Oracle SYSDATE
5229    ObjectId,    // Oracle OBJECT_ID
5230    ObjectValue, // Oracle OBJECT_VALUE
5231}
5232
5233impl PseudocolumnType {
5234    pub fn as_str(&self) -> &'static str {
5235        match self {
5236            PseudocolumnType::Rownum => "ROWNUM",
5237            PseudocolumnType::Rowid => "ROWID",
5238            PseudocolumnType::Level => "LEVEL",
5239            PseudocolumnType::Sysdate => "SYSDATE",
5240            PseudocolumnType::ObjectId => "OBJECT_ID",
5241            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5242        }
5243    }
5244
5245    pub fn from_str(s: &str) -> Option<Self> {
5246        match s.to_uppercase().as_str() {
5247            "ROWNUM" => Some(PseudocolumnType::Rownum),
5248            "ROWID" => Some(PseudocolumnType::Rowid),
5249            "LEVEL" => Some(PseudocolumnType::Level),
5250            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5251            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5252            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5253            _ => None,
5254        }
5255    }
5256}
5257
5258/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5259/// These are special identifiers that should not be quoted
5260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5261#[cfg_attr(feature = "bindings", derive(TS))]
5262#[cfg_attr(feature = "bindings", ts(export))]
5263pub struct Pseudocolumn {
5264    pub kind: PseudocolumnType,
5265}
5266
5267impl Pseudocolumn {
5268    pub fn rownum() -> Self {
5269        Self {
5270            kind: PseudocolumnType::Rownum,
5271        }
5272    }
5273
5274    pub fn rowid() -> Self {
5275        Self {
5276            kind: PseudocolumnType::Rowid,
5277        }
5278    }
5279
5280    pub fn level() -> Self {
5281        Self {
5282            kind: PseudocolumnType::Level,
5283        }
5284    }
5285}
5286
5287/// Oracle CONNECT BY clause for hierarchical queries
5288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5289#[cfg_attr(feature = "bindings", derive(TS))]
5290#[cfg_attr(feature = "bindings", ts(export))]
5291pub struct Connect {
5292    /// START WITH condition (optional, can come before or after CONNECT BY)
5293    pub start: Option<Expression>,
5294    /// CONNECT BY condition (required, contains PRIOR references)
5295    pub connect: Expression,
5296    /// NOCYCLE keyword to prevent infinite loops
5297    pub nocycle: bool,
5298}
5299
5300/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5302#[cfg_attr(feature = "bindings", derive(TS))]
5303#[cfg_attr(feature = "bindings", ts(export))]
5304pub struct Prior {
5305    pub this: Expression,
5306}
5307
5308/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5310#[cfg_attr(feature = "bindings", derive(TS))]
5311#[cfg_attr(feature = "bindings", ts(export))]
5312pub struct ConnectByRoot {
5313    pub this: Expression,
5314}
5315
5316/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5318#[cfg_attr(feature = "bindings", derive(TS))]
5319#[cfg_attr(feature = "bindings", ts(export))]
5320pub struct MatchRecognize {
5321    /// Source table/expression
5322    pub this: Option<Box<Expression>>,
5323    /// PARTITION BY expressions
5324    pub partition_by: Option<Vec<Expression>>,
5325    /// ORDER BY expressions
5326    pub order_by: Option<Vec<Ordered>>,
5327    /// MEASURES definitions
5328    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5329    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5330    pub rows: Option<MatchRecognizeRows>,
5331    /// AFTER MATCH SKIP behavior
5332    pub after: Option<MatchRecognizeAfter>,
5333    /// PATTERN definition (stored as raw string for complex regex patterns)
5334    pub pattern: Option<String>,
5335    /// DEFINE clauses (pattern variable definitions)
5336    pub define: Option<Vec<(Identifier, Expression)>>,
5337    /// Optional alias for the result
5338    pub alias: Option<Identifier>,
5339    /// Whether AS keyword was explicitly present before alias
5340    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5341    pub alias_explicit_as: bool,
5342}
5343
5344/// MEASURES expression with optional RUNNING/FINAL semantics
5345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5346#[cfg_attr(feature = "bindings", derive(TS))]
5347#[cfg_attr(feature = "bindings", ts(export))]
5348pub struct MatchRecognizeMeasure {
5349    /// The measure expression
5350    pub this: Expression,
5351    /// RUNNING or FINAL semantics (Snowflake-specific)
5352    pub window_frame: Option<MatchRecognizeSemantics>,
5353}
5354
5355/// Semantics for MEASURES in MATCH_RECOGNIZE
5356#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5357#[cfg_attr(feature = "bindings", derive(TS))]
5358#[cfg_attr(feature = "bindings", ts(export))]
5359pub enum MatchRecognizeSemantics {
5360    Running,
5361    Final,
5362}
5363
5364/// Row output semantics for MATCH_RECOGNIZE
5365#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5366#[cfg_attr(feature = "bindings", derive(TS))]
5367#[cfg_attr(feature = "bindings", ts(export))]
5368pub enum MatchRecognizeRows {
5369    OneRowPerMatch,
5370    AllRowsPerMatch,
5371    AllRowsPerMatchShowEmptyMatches,
5372    AllRowsPerMatchOmitEmptyMatches,
5373    AllRowsPerMatchWithUnmatchedRows,
5374}
5375
5376/// AFTER MATCH SKIP behavior
5377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5378#[cfg_attr(feature = "bindings", derive(TS))]
5379#[cfg_attr(feature = "bindings", ts(export))]
5380pub enum MatchRecognizeAfter {
5381    PastLastRow,
5382    ToNextRow,
5383    ToFirst(Identifier),
5384    ToLast(Identifier),
5385}
5386
5387/// Represent a LIMIT clause that restricts the number of returned rows.
5388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5389#[cfg_attr(feature = "bindings", derive(TS))]
5390pub struct Limit {
5391    /// The limit count expression.
5392    pub this: Expression,
5393    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5394    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5395    pub percent: bool,
5396    /// Comments from before the LIMIT keyword (emitted after the limit value)
5397    #[serde(default)]
5398    #[serde(skip_serializing_if = "Vec::is_empty")]
5399    pub comments: Vec<String>,
5400}
5401
5402/// OFFSET clause
5403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5404#[cfg_attr(feature = "bindings", derive(TS))]
5405pub struct Offset {
5406    pub this: Expression,
5407    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5408    #[serde(skip_serializing_if = "Option::is_none", default)]
5409    pub rows: Option<bool>,
5410}
5411
5412/// TOP clause (SQL Server)
5413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5414#[cfg_attr(feature = "bindings", derive(TS))]
5415pub struct Top {
5416    pub this: Expression,
5417    pub percent: bool,
5418    pub with_ties: bool,
5419    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5420    #[serde(default)]
5421    pub parenthesized: bool,
5422}
5423
5424/// FETCH FIRST/NEXT clause (SQL standard)
5425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5426#[cfg_attr(feature = "bindings", derive(TS))]
5427pub struct Fetch {
5428    /// FIRST or NEXT
5429    pub direction: String,
5430    /// Count expression (optional)
5431    pub count: Option<Expression>,
5432    /// PERCENT modifier
5433    pub percent: bool,
5434    /// ROWS or ROW keyword present
5435    pub rows: bool,
5436    /// WITH TIES modifier
5437    pub with_ties: bool,
5438}
5439
5440/// Represent a QUALIFY clause for filtering on window function results.
5441///
5442/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5443/// typically references a window function (e.g.
5444/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct Qualify {
5448    /// The filter predicate over window function results.
5449    pub this: Expression,
5450}
5451
5452/// SAMPLE / TABLESAMPLE clause
5453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5454#[cfg_attr(feature = "bindings", derive(TS))]
5455pub struct Sample {
5456    pub method: SampleMethod,
5457    pub size: Expression,
5458    pub seed: Option<Expression>,
5459    /// ClickHouse OFFSET expression after SAMPLE size
5460    #[serde(default)]
5461    pub offset: Option<Expression>,
5462    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5463    pub unit_after_size: bool,
5464    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5465    #[serde(default)]
5466    pub use_sample_keyword: bool,
5467    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5468    #[serde(default)]
5469    pub explicit_method: bool,
5470    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5471    #[serde(default)]
5472    pub method_before_size: bool,
5473    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5474    #[serde(default)]
5475    pub use_seed_keyword: bool,
5476    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5477    pub bucket_numerator: Option<Box<Expression>>,
5478    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5479    pub bucket_denominator: Option<Box<Expression>>,
5480    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5481    pub bucket_field: Option<Box<Expression>>,
5482    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5483    #[serde(default)]
5484    pub is_using_sample: bool,
5485    /// Whether the unit was explicitly PERCENT (vs ROWS)
5486    #[serde(default)]
5487    pub is_percent: bool,
5488    /// Whether to suppress method output (for cross-dialect transpilation)
5489    #[serde(default)]
5490    pub suppress_method_output: bool,
5491}
5492
5493/// Sample method
5494#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5495#[cfg_attr(feature = "bindings", derive(TS))]
5496pub enum SampleMethod {
5497    Bernoulli,
5498    System,
5499    Block,
5500    Row,
5501    Percent,
5502    /// Hive bucket sampling
5503    Bucket,
5504    /// DuckDB reservoir sampling
5505    Reservoir,
5506}
5507
5508/// Named window definition (WINDOW w AS (...))
5509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5510#[cfg_attr(feature = "bindings", derive(TS))]
5511pub struct NamedWindow {
5512    pub name: Identifier,
5513    pub spec: Over,
5514}
5515
5516/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5517///
5518/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5519/// that reference themselves. Each CTE is defined in the `ctes` vector and
5520/// can be referenced by name in subsequent CTEs and in the main query body.
5521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5522#[cfg_attr(feature = "bindings", derive(TS))]
5523pub struct With {
5524    /// The list of CTE definitions, in order.
5525    pub ctes: Vec<Cte>,
5526    /// Whether the WITH RECURSIVE keyword was used.
5527    pub recursive: bool,
5528    /// Leading comments before the statement
5529    #[serde(default)]
5530    pub leading_comments: Vec<String>,
5531    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5532    #[serde(default, skip_serializing_if = "Option::is_none")]
5533    pub search: Option<Box<Expression>>,
5534}
5535
5536/// Represent a single Common Table Expression definition.
5537///
5538/// A CTE has a name (`alias`), an optional column list, and a body query.
5539/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5540/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5541/// the expression comes before the alias (`alias_first`).
5542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5543#[cfg_attr(feature = "bindings", derive(TS))]
5544pub struct Cte {
5545    /// The CTE name.
5546    pub alias: Identifier,
5547    /// The CTE body (typically a SELECT, UNION, etc.).
5548    pub this: Expression,
5549    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5550    pub columns: Vec<Identifier>,
5551    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5552    pub materialized: Option<bool>,
5553    /// USING KEY (columns) for DuckDB recursive CTEs
5554    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5555    pub key_expressions: Vec<Identifier>,
5556    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5557    #[serde(default)]
5558    pub alias_first: bool,
5559    /// Comments associated with this CTE (placed after alias name, before AS)
5560    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5561    pub comments: Vec<String>,
5562}
5563
5564/// Window specification
5565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5566#[cfg_attr(feature = "bindings", derive(TS))]
5567pub struct WindowSpec {
5568    pub partition_by: Vec<Expression>,
5569    pub order_by: Vec<Ordered>,
5570    pub frame: Option<WindowFrame>,
5571}
5572
5573/// OVER clause
5574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5575#[cfg_attr(feature = "bindings", derive(TS))]
5576pub struct Over {
5577    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5578    pub window_name: Option<Identifier>,
5579    pub partition_by: Vec<Expression>,
5580    pub order_by: Vec<Ordered>,
5581    pub frame: Option<WindowFrame>,
5582    pub alias: Option<Identifier>,
5583}
5584
5585/// Window frame
5586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5587#[cfg_attr(feature = "bindings", derive(TS))]
5588pub struct WindowFrame {
5589    pub kind: WindowFrameKind,
5590    pub start: WindowFrameBound,
5591    pub end: Option<WindowFrameBound>,
5592    pub exclude: Option<WindowFrameExclude>,
5593    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5594    #[serde(default, skip_serializing_if = "Option::is_none")]
5595    pub kind_text: Option<String>,
5596    /// Original text of the start bound side keyword (e.g. "preceding")
5597    #[serde(default, skip_serializing_if = "Option::is_none")]
5598    pub start_side_text: Option<String>,
5599    /// Original text of the end bound side keyword
5600    #[serde(default, skip_serializing_if = "Option::is_none")]
5601    pub end_side_text: Option<String>,
5602}
5603
5604#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5605#[cfg_attr(feature = "bindings", derive(TS))]
5606pub enum WindowFrameKind {
5607    Rows,
5608    Range,
5609    Groups,
5610}
5611
5612/// EXCLUDE clause for window frames
5613#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5614#[cfg_attr(feature = "bindings", derive(TS))]
5615pub enum WindowFrameExclude {
5616    CurrentRow,
5617    Group,
5618    Ties,
5619    NoOthers,
5620}
5621
5622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5623#[cfg_attr(feature = "bindings", derive(TS))]
5624pub enum WindowFrameBound {
5625    CurrentRow,
5626    UnboundedPreceding,
5627    UnboundedFollowing,
5628    Preceding(Box<Expression>),
5629    Following(Box<Expression>),
5630    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5631    BarePreceding,
5632    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5633    BareFollowing,
5634    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5635    Value(Box<Expression>),
5636}
5637
5638/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5640#[cfg_attr(feature = "bindings", derive(TS))]
5641pub struct StructField {
5642    pub name: String,
5643    pub data_type: DataType,
5644    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5645    pub options: Vec<Expression>,
5646    #[serde(default, skip_serializing_if = "Option::is_none")]
5647    pub comment: Option<String>,
5648}
5649
5650impl StructField {
5651    /// Create a new struct field without options
5652    pub fn new(name: String, data_type: DataType) -> Self {
5653        Self {
5654            name,
5655            data_type,
5656            options: Vec::new(),
5657            comment: None,
5658        }
5659    }
5660
5661    /// Create a new struct field with options
5662    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5663        Self {
5664            name,
5665            data_type,
5666            options,
5667            comment: None,
5668        }
5669    }
5670
5671    /// Create a new struct field with options and comment
5672    pub fn with_options_and_comment(
5673        name: String,
5674        data_type: DataType,
5675        options: Vec<Expression>,
5676        comment: Option<String>,
5677    ) -> Self {
5678        Self {
5679            name,
5680            data_type,
5681            options,
5682            comment,
5683        }
5684    }
5685}
5686
5687/// Enumerate all SQL data types recognized by the parser.
5688///
5689/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5690/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5691/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5692///
5693/// This enum is used in CAST expressions, column definitions, function return
5694/// types, and anywhere a data type specification appears in SQL.
5695///
5696/// Types that do not match any known variant fall through to `Custom { name }`,
5697/// preserving the original type name for round-trip fidelity.
5698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5699#[cfg_attr(feature = "bindings", derive(TS))]
5700#[serde(tag = "data_type", rename_all = "snake_case")]
5701pub enum DataType {
5702    // Numeric
5703    Boolean,
5704    TinyInt {
5705        length: Option<u32>,
5706    },
5707    SmallInt {
5708        length: Option<u32>,
5709    },
5710    /// Int type with optional length. `integer_spelling` indicates whether the original
5711    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5712    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5713    Int {
5714        length: Option<u32>,
5715        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5716        integer_spelling: bool,
5717    },
5718    BigInt {
5719        length: Option<u32>,
5720    },
5721    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5722    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5723    /// preserve the original spelling.
5724    Float {
5725        precision: Option<u32>,
5726        scale: Option<u32>,
5727        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5728        real_spelling: bool,
5729    },
5730    Double {
5731        precision: Option<u32>,
5732        scale: Option<u32>,
5733    },
5734    Decimal {
5735        precision: Option<u32>,
5736        scale: Option<u32>,
5737    },
5738
5739    // String
5740    Char {
5741        length: Option<u32>,
5742    },
5743    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5744    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5745    VarChar {
5746        length: Option<u32>,
5747        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5748        parenthesized_length: bool,
5749    },
5750    /// String type with optional max length (BigQuery STRING(n))
5751    String {
5752        length: Option<u32>,
5753    },
5754    Text,
5755    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5756    TextWithLength {
5757        length: u32,
5758    },
5759
5760    // Binary
5761    Binary {
5762        length: Option<u32>,
5763    },
5764    VarBinary {
5765        length: Option<u32>,
5766    },
5767    Blob,
5768
5769    // Bit
5770    Bit {
5771        length: Option<u32>,
5772    },
5773    VarBit {
5774        length: Option<u32>,
5775    },
5776
5777    // Date/Time
5778    Date,
5779    Time {
5780        precision: Option<u32>,
5781        #[serde(default)]
5782        timezone: bool,
5783    },
5784    Timestamp {
5785        precision: Option<u32>,
5786        timezone: bool,
5787    },
5788    Interval {
5789        unit: Option<String>,
5790        /// For range intervals like INTERVAL DAY TO HOUR
5791        #[serde(default, skip_serializing_if = "Option::is_none")]
5792        to: Option<String>,
5793    },
5794
5795    // JSON
5796    Json,
5797    JsonB,
5798
5799    // UUID
5800    Uuid,
5801
5802    // Array
5803    Array {
5804        element_type: Box<DataType>,
5805        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5806        #[serde(default, skip_serializing_if = "Option::is_none")]
5807        dimension: Option<u32>,
5808    },
5809
5810    /// List type (Materialize): INT LIST, TEXT LIST LIST
5811    /// Uses postfix LIST syntax instead of ARRAY<T>
5812    List {
5813        element_type: Box<DataType>,
5814    },
5815
5816    // Struct/Map
5817    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5818    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5819    Struct {
5820        fields: Vec<StructField>,
5821        nested: bool,
5822    },
5823    Map {
5824        key_type: Box<DataType>,
5825        value_type: Box<DataType>,
5826    },
5827
5828    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5829    Enum {
5830        values: Vec<String>,
5831        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5832        assignments: Vec<Option<String>>,
5833    },
5834
5835    // Set type (MySQL): SET('a', 'b', 'c')
5836    Set {
5837        values: Vec<String>,
5838    },
5839
5840    // Union type (DuckDB): UNION(num INT, str TEXT)
5841    Union {
5842        fields: Vec<(String, DataType)>,
5843    },
5844
5845    // Vector (Snowflake / SingleStore)
5846    Vector {
5847        #[serde(default)]
5848        element_type: Option<Box<DataType>>,
5849        dimension: Option<u32>,
5850    },
5851
5852    // Object (Snowflake structured type)
5853    // fields: Vec of (field_name, field_type, not_null)
5854    Object {
5855        fields: Vec<(String, DataType, bool)>,
5856        modifier: Option<String>,
5857    },
5858
5859    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5860    Nullable {
5861        inner: Box<DataType>,
5862    },
5863
5864    // Custom/User-defined
5865    Custom {
5866        name: String,
5867    },
5868
5869    // Spatial types
5870    Geometry {
5871        subtype: Option<String>,
5872        srid: Option<u32>,
5873    },
5874    Geography {
5875        subtype: Option<String>,
5876        srid: Option<u32>,
5877    },
5878
5879    // Character Set (for CONVERT USING in MySQL)
5880    // Renders as CHAR CHARACTER SET {name} in cast target
5881    CharacterSet {
5882        name: String,
5883    },
5884
5885    // Unknown
5886    Unknown,
5887}
5888
5889/// Array expression
5890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5891#[cfg_attr(feature = "bindings", derive(TS))]
5892#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5893pub struct Array {
5894    pub expressions: Vec<Expression>,
5895}
5896
5897/// Struct expression
5898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5899#[cfg_attr(feature = "bindings", derive(TS))]
5900pub struct Struct {
5901    pub fields: Vec<(Option<String>, Expression)>,
5902}
5903
5904/// Tuple expression
5905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5906#[cfg_attr(feature = "bindings", derive(TS))]
5907pub struct Tuple {
5908    pub expressions: Vec<Expression>,
5909}
5910
5911/// Interval expression
5912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5913#[cfg_attr(feature = "bindings", derive(TS))]
5914pub struct Interval {
5915    /// The value expression (e.g., '1', 5, column_ref)
5916    pub this: Option<Expression>,
5917    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5918    pub unit: Option<IntervalUnitSpec>,
5919}
5920
5921/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5923#[cfg_attr(feature = "bindings", derive(TS))]
5924#[serde(tag = "type", rename_all = "snake_case")]
5925pub enum IntervalUnitSpec {
5926    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5927    Simple {
5928        unit: IntervalUnit,
5929        /// Whether to use plural form (e.g., DAYS vs DAY)
5930        use_plural: bool,
5931    },
5932    /// Interval span (e.g., HOUR TO SECOND)
5933    Span(IntervalSpan),
5934    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5935    /// The start and end can be expressions like function calls with precision
5936    ExprSpan(IntervalSpanExpr),
5937    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5938    Expr(Box<Expression>),
5939}
5940
5941/// Interval span for ranges like HOUR TO SECOND
5942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5943#[cfg_attr(feature = "bindings", derive(TS))]
5944pub struct IntervalSpan {
5945    /// Start unit (e.g., HOUR)
5946    pub this: IntervalUnit,
5947    /// End unit (e.g., SECOND)
5948    pub expression: IntervalUnit,
5949}
5950
5951/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5952/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5954#[cfg_attr(feature = "bindings", derive(TS))]
5955pub struct IntervalSpanExpr {
5956    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5957    pub this: Box<Expression>,
5958    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5959    pub expression: Box<Expression>,
5960}
5961
5962#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5963#[cfg_attr(feature = "bindings", derive(TS))]
5964pub enum IntervalUnit {
5965    Year,
5966    Quarter,
5967    Month,
5968    Week,
5969    Day,
5970    Hour,
5971    Minute,
5972    Second,
5973    Millisecond,
5974    Microsecond,
5975    Nanosecond,
5976}
5977
5978/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5980#[cfg_attr(feature = "bindings", derive(TS))]
5981pub struct Command {
5982    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5983    pub this: String,
5984}
5985
5986/// EXEC/EXECUTE statement (TSQL stored procedure call)
5987/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5989#[cfg_attr(feature = "bindings", derive(TS))]
5990pub struct ExecuteStatement {
5991    /// The procedure name (can be qualified: schema.proc_name)
5992    pub this: Expression,
5993    /// Named parameters: @param=value pairs
5994    #[serde(default)]
5995    pub parameters: Vec<ExecuteParameter>,
5996    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
5997    #[serde(default, skip_serializing_if = "Option::is_none")]
5998    pub suffix: Option<String>,
5999}
6000
6001/// Named parameter in EXEC statement: @name=value
6002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6003#[cfg_attr(feature = "bindings", derive(TS))]
6004pub struct ExecuteParameter {
6005    /// Parameter name (including @)
6006    pub name: String,
6007    /// Parameter value
6008    pub value: Expression,
6009    /// Whether this is a positional parameter (no = sign)
6010    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6011    pub positional: bool,
6012    /// TSQL OUTPUT modifier on parameter
6013    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6014    pub output: bool,
6015}
6016
6017/// KILL statement (MySQL/MariaDB)
6018/// KILL [CONNECTION | QUERY] <id>
6019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6020#[cfg_attr(feature = "bindings", derive(TS))]
6021pub struct Kill {
6022    /// The target (process ID or connection ID)
6023    pub this: Expression,
6024    /// Optional kind: "CONNECTION" or "QUERY"
6025    pub kind: Option<String>,
6026}
6027
6028/// Snowflake CREATE TASK statement
6029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6030#[cfg_attr(feature = "bindings", derive(TS))]
6031pub struct CreateTask {
6032    pub or_replace: bool,
6033    pub if_not_exists: bool,
6034    /// Task name (possibly qualified: db.schema.task)
6035    pub name: String,
6036    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6037    pub properties: String,
6038    /// The SQL statement body after AS
6039    pub body: Expression,
6040}
6041
6042/// Raw/unparsed SQL
6043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6044#[cfg_attr(feature = "bindings", derive(TS))]
6045pub struct Raw {
6046    pub sql: String,
6047}
6048
6049// ============================================================================
6050// Function expression types
6051// ============================================================================
6052
6053/// Generic unary function (takes a single argument)
6054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6055#[cfg_attr(feature = "bindings", derive(TS))]
6056pub struct UnaryFunc {
6057    pub this: Expression,
6058    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6059    #[serde(skip_serializing_if = "Option::is_none", default)]
6060    pub original_name: Option<String>,
6061    /// Inferred data type from type annotation
6062    #[serde(default, skip_serializing_if = "Option::is_none")]
6063    pub inferred_type: Option<DataType>,
6064}
6065
6066impl UnaryFunc {
6067    /// Create a new UnaryFunc with no original_name
6068    pub fn new(this: Expression) -> Self {
6069        Self {
6070            this,
6071            original_name: None,
6072            inferred_type: None,
6073        }
6074    }
6075
6076    /// Create a new UnaryFunc with an original name for round-trip preservation
6077    pub fn with_name(this: Expression, name: String) -> Self {
6078        Self {
6079            this,
6080            original_name: Some(name),
6081            inferred_type: None,
6082        }
6083    }
6084}
6085
6086/// CHAR/CHR function with multiple args and optional USING charset
6087/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6088/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6090#[cfg_attr(feature = "bindings", derive(TS))]
6091pub struct CharFunc {
6092    pub args: Vec<Expression>,
6093    #[serde(skip_serializing_if = "Option::is_none", default)]
6094    pub charset: Option<String>,
6095    /// Original function name (CHAR or CHR), defaults to CHAR
6096    #[serde(skip_serializing_if = "Option::is_none", default)]
6097    pub name: Option<String>,
6098}
6099
6100/// Generic binary function (takes two arguments)
6101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6102#[cfg_attr(feature = "bindings", derive(TS))]
6103pub struct BinaryFunc {
6104    pub this: Expression,
6105    pub expression: Expression,
6106    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6107    #[serde(skip_serializing_if = "Option::is_none", default)]
6108    pub original_name: Option<String>,
6109    /// Inferred data type from type annotation
6110    #[serde(default, skip_serializing_if = "Option::is_none")]
6111    pub inferred_type: Option<DataType>,
6112}
6113
6114/// Variable argument function
6115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6116#[cfg_attr(feature = "bindings", derive(TS))]
6117pub struct VarArgFunc {
6118    pub expressions: Vec<Expression>,
6119    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6120    #[serde(skip_serializing_if = "Option::is_none", default)]
6121    pub original_name: Option<String>,
6122    /// Inferred data type from type annotation
6123    #[serde(default, skip_serializing_if = "Option::is_none")]
6124    pub inferred_type: Option<DataType>,
6125}
6126
6127/// CONCAT_WS function
6128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6129#[cfg_attr(feature = "bindings", derive(TS))]
6130pub struct ConcatWs {
6131    pub separator: Expression,
6132    pub expressions: Vec<Expression>,
6133}
6134
6135/// SUBSTRING function
6136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6137#[cfg_attr(feature = "bindings", derive(TS))]
6138pub struct SubstringFunc {
6139    pub this: Expression,
6140    pub start: Expression,
6141    pub length: Option<Expression>,
6142    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6143    #[serde(default)]
6144    pub from_for_syntax: bool,
6145}
6146
6147/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6149#[cfg_attr(feature = "bindings", derive(TS))]
6150pub struct OverlayFunc {
6151    pub this: Expression,
6152    pub replacement: Expression,
6153    pub from: Expression,
6154    pub length: Option<Expression>,
6155}
6156
6157/// TRIM function
6158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6159#[cfg_attr(feature = "bindings", derive(TS))]
6160pub struct TrimFunc {
6161    pub this: Expression,
6162    pub characters: Option<Expression>,
6163    pub position: TrimPosition,
6164    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6165    #[serde(default)]
6166    pub sql_standard_syntax: bool,
6167    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6168    #[serde(default)]
6169    pub position_explicit: bool,
6170}
6171
6172#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6173#[cfg_attr(feature = "bindings", derive(TS))]
6174pub enum TrimPosition {
6175    Both,
6176    Leading,
6177    Trailing,
6178}
6179
6180/// REPLACE function
6181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6182#[cfg_attr(feature = "bindings", derive(TS))]
6183pub struct ReplaceFunc {
6184    pub this: Expression,
6185    pub old: Expression,
6186    pub new: Expression,
6187}
6188
6189/// LEFT/RIGHT function
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct LeftRightFunc {
6193    pub this: Expression,
6194    pub length: Expression,
6195}
6196
6197/// REPEAT function
6198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6199#[cfg_attr(feature = "bindings", derive(TS))]
6200pub struct RepeatFunc {
6201    pub this: Expression,
6202    pub times: Expression,
6203}
6204
6205/// LPAD/RPAD function
6206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6207#[cfg_attr(feature = "bindings", derive(TS))]
6208pub struct PadFunc {
6209    pub this: Expression,
6210    pub length: Expression,
6211    pub fill: Option<Expression>,
6212}
6213
6214/// SPLIT function
6215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6216#[cfg_attr(feature = "bindings", derive(TS))]
6217pub struct SplitFunc {
6218    pub this: Expression,
6219    pub delimiter: Expression,
6220}
6221
6222/// REGEXP_LIKE function
6223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6224#[cfg_attr(feature = "bindings", derive(TS))]
6225pub struct RegexpFunc {
6226    pub this: Expression,
6227    pub pattern: Expression,
6228    pub flags: Option<Expression>,
6229}
6230
6231/// REGEXP_REPLACE function
6232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6233#[cfg_attr(feature = "bindings", derive(TS))]
6234pub struct RegexpReplaceFunc {
6235    pub this: Expression,
6236    pub pattern: Expression,
6237    pub replacement: Expression,
6238    pub flags: Option<Expression>,
6239}
6240
6241/// REGEXP_EXTRACT function
6242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6243#[cfg_attr(feature = "bindings", derive(TS))]
6244pub struct RegexpExtractFunc {
6245    pub this: Expression,
6246    pub pattern: Expression,
6247    pub group: Option<Expression>,
6248}
6249
6250/// ROUND function
6251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6252#[cfg_attr(feature = "bindings", derive(TS))]
6253pub struct RoundFunc {
6254    pub this: Expression,
6255    pub decimals: Option<Expression>,
6256}
6257
6258/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6260#[cfg_attr(feature = "bindings", derive(TS))]
6261pub struct FloorFunc {
6262    pub this: Expression,
6263    pub scale: Option<Expression>,
6264    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6265    #[serde(skip_serializing_if = "Option::is_none", default)]
6266    pub to: Option<Expression>,
6267}
6268
6269/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6271#[cfg_attr(feature = "bindings", derive(TS))]
6272pub struct CeilFunc {
6273    pub this: Expression,
6274    #[serde(skip_serializing_if = "Option::is_none", default)]
6275    pub decimals: Option<Expression>,
6276    /// Time unit for Druid-style CEIL(time TO unit) syntax
6277    #[serde(skip_serializing_if = "Option::is_none", default)]
6278    pub to: Option<Expression>,
6279}
6280
6281/// LOG function
6282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6283#[cfg_attr(feature = "bindings", derive(TS))]
6284pub struct LogFunc {
6285    pub this: Expression,
6286    pub base: Option<Expression>,
6287}
6288
6289/// CURRENT_DATE (no arguments)
6290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6291#[cfg_attr(feature = "bindings", derive(TS))]
6292pub struct CurrentDate;
6293
6294/// CURRENT_TIME
6295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6296#[cfg_attr(feature = "bindings", derive(TS))]
6297pub struct CurrentTime {
6298    pub precision: Option<u32>,
6299}
6300
6301/// CURRENT_TIMESTAMP
6302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6303#[cfg_attr(feature = "bindings", derive(TS))]
6304pub struct CurrentTimestamp {
6305    pub precision: Option<u32>,
6306    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6307    #[serde(default)]
6308    pub sysdate: bool,
6309}
6310
6311/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6313#[cfg_attr(feature = "bindings", derive(TS))]
6314pub struct CurrentTimestampLTZ {
6315    pub precision: Option<u32>,
6316}
6317
6318/// AT TIME ZONE expression for timezone conversion
6319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6320#[cfg_attr(feature = "bindings", derive(TS))]
6321pub struct AtTimeZone {
6322    /// The expression to convert
6323    pub this: Expression,
6324    /// The target timezone
6325    pub zone: Expression,
6326}
6327
6328/// DATE_ADD / DATE_SUB function
6329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6330#[cfg_attr(feature = "bindings", derive(TS))]
6331pub struct DateAddFunc {
6332    pub this: Expression,
6333    pub interval: Expression,
6334    pub unit: IntervalUnit,
6335}
6336
6337/// DATEDIFF function
6338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6339#[cfg_attr(feature = "bindings", derive(TS))]
6340pub struct DateDiffFunc {
6341    pub this: Expression,
6342    pub expression: Expression,
6343    pub unit: Option<IntervalUnit>,
6344}
6345
6346/// DATE_TRUNC function
6347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6348#[cfg_attr(feature = "bindings", derive(TS))]
6349pub struct DateTruncFunc {
6350    pub this: Expression,
6351    pub unit: DateTimeField,
6352}
6353
6354/// EXTRACT function
6355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6356#[cfg_attr(feature = "bindings", derive(TS))]
6357pub struct ExtractFunc {
6358    pub this: Expression,
6359    pub field: DateTimeField,
6360}
6361
6362#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6363#[cfg_attr(feature = "bindings", derive(TS))]
6364pub enum DateTimeField {
6365    Year,
6366    Month,
6367    Day,
6368    Hour,
6369    Minute,
6370    Second,
6371    Millisecond,
6372    Microsecond,
6373    DayOfWeek,
6374    DayOfYear,
6375    Week,
6376    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6377    WeekWithModifier(String),
6378    Quarter,
6379    Epoch,
6380    Timezone,
6381    TimezoneHour,
6382    TimezoneMinute,
6383    Date,
6384    Time,
6385    /// Custom datetime field for dialect-specific or arbitrary fields
6386    Custom(String),
6387}
6388
6389/// TO_DATE function
6390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6391#[cfg_attr(feature = "bindings", derive(TS))]
6392pub struct ToDateFunc {
6393    pub this: Expression,
6394    pub format: Option<Expression>,
6395}
6396
6397/// TO_TIMESTAMP function
6398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6399#[cfg_attr(feature = "bindings", derive(TS))]
6400pub struct ToTimestampFunc {
6401    pub this: Expression,
6402    pub format: Option<Expression>,
6403}
6404
6405/// IF function
6406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6407#[cfg_attr(feature = "bindings", derive(TS))]
6408pub struct IfFunc {
6409    pub condition: Expression,
6410    pub true_value: Expression,
6411    pub false_value: Option<Expression>,
6412    /// Original function name (IF, IFF, IIF) for round-trip preservation
6413    #[serde(skip_serializing_if = "Option::is_none", default)]
6414    pub original_name: Option<String>,
6415    /// Inferred data type from type annotation
6416    #[serde(default, skip_serializing_if = "Option::is_none")]
6417    pub inferred_type: Option<DataType>,
6418}
6419
6420/// NVL2 function
6421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6422#[cfg_attr(feature = "bindings", derive(TS))]
6423pub struct Nvl2Func {
6424    pub this: Expression,
6425    pub true_value: Expression,
6426    pub false_value: Expression,
6427    /// Inferred data type from type annotation
6428    #[serde(default, skip_serializing_if = "Option::is_none")]
6429    pub inferred_type: Option<DataType>,
6430}
6431
6432// ============================================================================
6433// Typed Aggregate Function types
6434// ============================================================================
6435
6436/// Generic aggregate function base type
6437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6438#[cfg_attr(feature = "bindings", derive(TS))]
6439pub struct AggFunc {
6440    pub this: Expression,
6441    pub distinct: bool,
6442    pub filter: Option<Expression>,
6443    pub order_by: Vec<Ordered>,
6444    /// Original function name (case-preserving) when parsed from SQL
6445    #[serde(skip_serializing_if = "Option::is_none", default)]
6446    pub name: Option<String>,
6447    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6448    #[serde(skip_serializing_if = "Option::is_none", default)]
6449    pub ignore_nulls: Option<bool>,
6450    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6451    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6452    #[serde(skip_serializing_if = "Option::is_none", default)]
6453    pub having_max: Option<(Box<Expression>, bool)>,
6454    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6455    #[serde(skip_serializing_if = "Option::is_none", default)]
6456    pub limit: Option<Box<Expression>>,
6457    /// Inferred data type from type annotation
6458    #[serde(default, skip_serializing_if = "Option::is_none")]
6459    pub inferred_type: Option<DataType>,
6460}
6461
6462/// COUNT function with optional star
6463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6464#[cfg_attr(feature = "bindings", derive(TS))]
6465pub struct CountFunc {
6466    pub this: Option<Expression>,
6467    pub star: bool,
6468    pub distinct: bool,
6469    pub filter: Option<Expression>,
6470    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6471    #[serde(default, skip_serializing_if = "Option::is_none")]
6472    pub ignore_nulls: Option<bool>,
6473    /// Original function name for case preservation (e.g., "count" or "COUNT")
6474    #[serde(default, skip_serializing_if = "Option::is_none")]
6475    pub original_name: Option<String>,
6476    /// Inferred data type from type annotation
6477    #[serde(default, skip_serializing_if = "Option::is_none")]
6478    pub inferred_type: Option<DataType>,
6479}
6480
6481/// GROUP_CONCAT function (MySQL style)
6482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6483#[cfg_attr(feature = "bindings", derive(TS))]
6484pub struct GroupConcatFunc {
6485    pub this: Expression,
6486    pub separator: Option<Expression>,
6487    pub order_by: Option<Vec<Ordered>>,
6488    pub distinct: bool,
6489    pub filter: Option<Expression>,
6490    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6491    #[serde(default, skip_serializing_if = "Option::is_none")]
6492    pub limit: Option<Box<Expression>>,
6493    /// Inferred data type from type annotation
6494    #[serde(default, skip_serializing_if = "Option::is_none")]
6495    pub inferred_type: Option<DataType>,
6496}
6497
6498/// STRING_AGG function (PostgreSQL/Standard SQL)
6499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6500#[cfg_attr(feature = "bindings", derive(TS))]
6501pub struct StringAggFunc {
6502    pub this: Expression,
6503    #[serde(default)]
6504    pub separator: Option<Expression>,
6505    #[serde(default)]
6506    pub order_by: Option<Vec<Ordered>>,
6507    #[serde(default)]
6508    pub distinct: bool,
6509    #[serde(default)]
6510    pub filter: Option<Expression>,
6511    /// BigQuery LIMIT inside STRING_AGG
6512    #[serde(default, skip_serializing_if = "Option::is_none")]
6513    pub limit: Option<Box<Expression>>,
6514    /// Inferred data type from type annotation
6515    #[serde(default, skip_serializing_if = "Option::is_none")]
6516    pub inferred_type: Option<DataType>,
6517}
6518
6519/// LISTAGG function (Oracle style)
6520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6521#[cfg_attr(feature = "bindings", derive(TS))]
6522pub struct ListAggFunc {
6523    pub this: Expression,
6524    pub separator: Option<Expression>,
6525    pub on_overflow: Option<ListAggOverflow>,
6526    pub order_by: Option<Vec<Ordered>>,
6527    pub distinct: bool,
6528    pub filter: Option<Expression>,
6529    /// Inferred data type from type annotation
6530    #[serde(default, skip_serializing_if = "Option::is_none")]
6531    pub inferred_type: Option<DataType>,
6532}
6533
6534/// LISTAGG ON OVERFLOW behavior
6535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6536#[cfg_attr(feature = "bindings", derive(TS))]
6537pub enum ListAggOverflow {
6538    Error,
6539    Truncate {
6540        filler: Option<Expression>,
6541        with_count: bool,
6542    },
6543}
6544
6545/// SUM_IF / COUNT_IF function
6546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6547#[cfg_attr(feature = "bindings", derive(TS))]
6548pub struct SumIfFunc {
6549    pub this: Expression,
6550    pub condition: Expression,
6551    pub filter: Option<Expression>,
6552    /// Inferred data type from type annotation
6553    #[serde(default, skip_serializing_if = "Option::is_none")]
6554    pub inferred_type: Option<DataType>,
6555}
6556
6557/// APPROX_PERCENTILE function
6558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6559#[cfg_attr(feature = "bindings", derive(TS))]
6560pub struct ApproxPercentileFunc {
6561    pub this: Expression,
6562    pub percentile: Expression,
6563    pub accuracy: Option<Expression>,
6564    pub filter: Option<Expression>,
6565}
6566
6567/// PERCENTILE_CONT / PERCENTILE_DISC function
6568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6569#[cfg_attr(feature = "bindings", derive(TS))]
6570pub struct PercentileFunc {
6571    pub this: Expression,
6572    pub percentile: Expression,
6573    pub order_by: Option<Vec<Ordered>>,
6574    pub filter: Option<Expression>,
6575}
6576
6577// ============================================================================
6578// Typed Window Function types
6579// ============================================================================
6580
6581/// ROW_NUMBER function (no arguments)
6582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6583#[cfg_attr(feature = "bindings", derive(TS))]
6584pub struct RowNumber;
6585
6586/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6588#[cfg_attr(feature = "bindings", derive(TS))]
6589pub struct Rank {
6590    /// DuckDB: RANK(ORDER BY col) - order by inside function
6591    #[serde(default, skip_serializing_if = "Option::is_none")]
6592    pub order_by: Option<Vec<Ordered>>,
6593    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6594    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6595    pub args: Vec<Expression>,
6596}
6597
6598/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6600#[cfg_attr(feature = "bindings", derive(TS))]
6601pub struct DenseRank {
6602    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6603    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6604    pub args: Vec<Expression>,
6605}
6606
6607/// NTILE function (DuckDB allows ORDER BY inside)
6608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6609#[cfg_attr(feature = "bindings", derive(TS))]
6610pub struct NTileFunc {
6611    /// num_buckets is optional to support Databricks NTILE() without arguments
6612    #[serde(default, skip_serializing_if = "Option::is_none")]
6613    pub num_buckets: Option<Expression>,
6614    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6615    #[serde(default, skip_serializing_if = "Option::is_none")]
6616    pub order_by: Option<Vec<Ordered>>,
6617}
6618
6619/// LEAD / LAG function
6620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6621#[cfg_attr(feature = "bindings", derive(TS))]
6622pub struct LeadLagFunc {
6623    pub this: Expression,
6624    pub offset: Option<Expression>,
6625    pub default: Option<Expression>,
6626    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6627    #[serde(default, skip_serializing_if = "Option::is_none")]
6628    pub ignore_nulls: Option<bool>,
6629}
6630
6631/// FIRST_VALUE / LAST_VALUE function
6632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6633#[cfg_attr(feature = "bindings", derive(TS))]
6634pub struct ValueFunc {
6635    pub this: Expression,
6636    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6637    #[serde(default, skip_serializing_if = "Option::is_none")]
6638    pub ignore_nulls: Option<bool>,
6639    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6641    pub order_by: Vec<Ordered>,
6642}
6643
6644/// NTH_VALUE function
6645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6646#[cfg_attr(feature = "bindings", derive(TS))]
6647pub struct NthValueFunc {
6648    pub this: Expression,
6649    pub offset: Expression,
6650    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6651    #[serde(default, skip_serializing_if = "Option::is_none")]
6652    pub ignore_nulls: Option<bool>,
6653    /// Snowflake FROM FIRST / FROM LAST clause
6654    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6655    #[serde(default, skip_serializing_if = "Option::is_none")]
6656    pub from_first: Option<bool>,
6657}
6658
6659/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6661#[cfg_attr(feature = "bindings", derive(TS))]
6662pub struct PercentRank {
6663    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6664    #[serde(default, skip_serializing_if = "Option::is_none")]
6665    pub order_by: Option<Vec<Ordered>>,
6666    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6667    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6668    pub args: Vec<Expression>,
6669}
6670
6671/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6673#[cfg_attr(feature = "bindings", derive(TS))]
6674pub struct CumeDist {
6675    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6676    #[serde(default, skip_serializing_if = "Option::is_none")]
6677    pub order_by: Option<Vec<Ordered>>,
6678    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6679    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6680    pub args: Vec<Expression>,
6681}
6682
6683// ============================================================================
6684// Additional String Function types
6685// ============================================================================
6686
6687/// POSITION/INSTR function
6688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6689#[cfg_attr(feature = "bindings", derive(TS))]
6690pub struct PositionFunc {
6691    pub substring: Expression,
6692    pub string: Expression,
6693    pub start: Option<Expression>,
6694}
6695
6696// ============================================================================
6697// Additional Math Function types
6698// ============================================================================
6699
6700/// RANDOM function (no arguments)
6701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6702#[cfg_attr(feature = "bindings", derive(TS))]
6703pub struct Random;
6704
6705/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6707#[cfg_attr(feature = "bindings", derive(TS))]
6708pub struct Rand {
6709    pub seed: Option<Box<Expression>>,
6710    /// Teradata RANDOM lower bound
6711    #[serde(default)]
6712    pub lower: Option<Box<Expression>>,
6713    /// Teradata RANDOM upper bound
6714    #[serde(default)]
6715    pub upper: Option<Box<Expression>>,
6716}
6717
6718/// TRUNCATE / TRUNC function
6719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6720#[cfg_attr(feature = "bindings", derive(TS))]
6721pub struct TruncateFunc {
6722    pub this: Expression,
6723    pub decimals: Option<Expression>,
6724}
6725
6726/// PI function (no arguments)
6727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6728#[cfg_attr(feature = "bindings", derive(TS))]
6729pub struct Pi;
6730
6731// ============================================================================
6732// Control Flow Function types
6733// ============================================================================
6734
6735/// DECODE function (Oracle style)
6736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6737#[cfg_attr(feature = "bindings", derive(TS))]
6738pub struct DecodeFunc {
6739    pub this: Expression,
6740    pub search_results: Vec<(Expression, Expression)>,
6741    pub default: Option<Expression>,
6742}
6743
6744// ============================================================================
6745// Additional Date/Time Function types
6746// ============================================================================
6747
6748/// DATE_FORMAT / FORMAT_DATE function
6749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6750#[cfg_attr(feature = "bindings", derive(TS))]
6751pub struct DateFormatFunc {
6752    pub this: Expression,
6753    pub format: Expression,
6754}
6755
6756/// FROM_UNIXTIME function
6757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6758#[cfg_attr(feature = "bindings", derive(TS))]
6759pub struct FromUnixtimeFunc {
6760    pub this: Expression,
6761    pub format: Option<Expression>,
6762}
6763
6764/// UNIX_TIMESTAMP function
6765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6766#[cfg_attr(feature = "bindings", derive(TS))]
6767pub struct UnixTimestampFunc {
6768    pub this: Option<Expression>,
6769    pub format: Option<Expression>,
6770}
6771
6772/// MAKE_DATE function
6773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6774#[cfg_attr(feature = "bindings", derive(TS))]
6775pub struct MakeDateFunc {
6776    pub year: Expression,
6777    pub month: Expression,
6778    pub day: Expression,
6779}
6780
6781/// MAKE_TIMESTAMP function
6782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6783#[cfg_attr(feature = "bindings", derive(TS))]
6784pub struct MakeTimestampFunc {
6785    pub year: Expression,
6786    pub month: Expression,
6787    pub day: Expression,
6788    pub hour: Expression,
6789    pub minute: Expression,
6790    pub second: Expression,
6791    pub timezone: Option<Expression>,
6792}
6793
6794/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6796#[cfg_attr(feature = "bindings", derive(TS))]
6797pub struct LastDayFunc {
6798    pub this: Expression,
6799    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6800    #[serde(skip_serializing_if = "Option::is_none", default)]
6801    pub unit: Option<DateTimeField>,
6802}
6803
6804// ============================================================================
6805// Array Function types
6806// ============================================================================
6807
6808/// ARRAY constructor
6809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6810#[cfg_attr(feature = "bindings", derive(TS))]
6811pub struct ArrayConstructor {
6812    pub expressions: Vec<Expression>,
6813    pub bracket_notation: bool,
6814    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6815    pub use_list_keyword: bool,
6816}
6817
6818/// ARRAY_SORT function
6819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6820#[cfg_attr(feature = "bindings", derive(TS))]
6821pub struct ArraySortFunc {
6822    pub this: Expression,
6823    pub comparator: Option<Expression>,
6824    pub desc: bool,
6825    pub nulls_first: Option<bool>,
6826}
6827
6828/// ARRAY_JOIN / ARRAY_TO_STRING function
6829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6830#[cfg_attr(feature = "bindings", derive(TS))]
6831pub struct ArrayJoinFunc {
6832    pub this: Expression,
6833    pub separator: Expression,
6834    pub null_replacement: Option<Expression>,
6835}
6836
6837/// UNNEST function
6838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6839#[cfg_attr(feature = "bindings", derive(TS))]
6840pub struct UnnestFunc {
6841    pub this: Expression,
6842    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6843    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6844    pub expressions: Vec<Expression>,
6845    pub with_ordinality: bool,
6846    pub alias: Option<Identifier>,
6847    /// BigQuery: offset alias for WITH OFFSET AS <name>
6848    #[serde(default, skip_serializing_if = "Option::is_none")]
6849    pub offset_alias: Option<Identifier>,
6850}
6851
6852/// ARRAY_FILTER function (with lambda)
6853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6854#[cfg_attr(feature = "bindings", derive(TS))]
6855pub struct ArrayFilterFunc {
6856    pub this: Expression,
6857    pub filter: Expression,
6858}
6859
6860/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6862#[cfg_attr(feature = "bindings", derive(TS))]
6863pub struct ArrayTransformFunc {
6864    pub this: Expression,
6865    pub transform: Expression,
6866}
6867
6868/// SEQUENCE / GENERATE_SERIES function
6869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6870#[cfg_attr(feature = "bindings", derive(TS))]
6871pub struct SequenceFunc {
6872    pub start: Expression,
6873    pub stop: Expression,
6874    pub step: Option<Expression>,
6875}
6876
6877// ============================================================================
6878// Struct Function types
6879// ============================================================================
6880
6881/// STRUCT constructor
6882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6883#[cfg_attr(feature = "bindings", derive(TS))]
6884pub struct StructConstructor {
6885    pub fields: Vec<(Option<Identifier>, Expression)>,
6886}
6887
6888/// STRUCT_EXTRACT function
6889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6890#[cfg_attr(feature = "bindings", derive(TS))]
6891pub struct StructExtractFunc {
6892    pub this: Expression,
6893    pub field: Identifier,
6894}
6895
6896/// NAMED_STRUCT function
6897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6898#[cfg_attr(feature = "bindings", derive(TS))]
6899pub struct NamedStructFunc {
6900    pub pairs: Vec<(Expression, Expression)>,
6901}
6902
6903// ============================================================================
6904// Map Function types
6905// ============================================================================
6906
6907/// MAP constructor
6908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6909#[cfg_attr(feature = "bindings", derive(TS))]
6910pub struct MapConstructor {
6911    pub keys: Vec<Expression>,
6912    pub values: Vec<Expression>,
6913    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6914    #[serde(default)]
6915    pub curly_brace_syntax: bool,
6916    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6917    #[serde(default)]
6918    pub with_map_keyword: bool,
6919}
6920
6921/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6923#[cfg_attr(feature = "bindings", derive(TS))]
6924pub struct TransformFunc {
6925    pub this: Expression,
6926    pub transform: Expression,
6927}
6928
6929/// Function call with EMITS clause (Exasol)
6930/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6932#[cfg_attr(feature = "bindings", derive(TS))]
6933pub struct FunctionEmits {
6934    /// The function call expression
6935    pub this: Expression,
6936    /// The EMITS schema definition
6937    pub emits: Expression,
6938}
6939
6940// ============================================================================
6941// JSON Function types
6942// ============================================================================
6943
6944/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6946#[cfg_attr(feature = "bindings", derive(TS))]
6947pub struct JsonExtractFunc {
6948    pub this: Expression,
6949    pub path: Expression,
6950    pub returning: Option<DataType>,
6951    /// True if parsed from -> or ->> operator syntax
6952    #[serde(default)]
6953    pub arrow_syntax: bool,
6954    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6955    #[serde(default)]
6956    pub hash_arrow_syntax: bool,
6957    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6958    #[serde(default)]
6959    pub wrapper_option: Option<String>,
6960    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6961    #[serde(default)]
6962    pub quotes_option: Option<String>,
6963    /// ON SCALAR STRING flag
6964    #[serde(default)]
6965    pub on_scalar_string: bool,
6966    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6967    #[serde(default)]
6968    pub on_error: Option<String>,
6969}
6970
6971/// JSON path extraction
6972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6973#[cfg_attr(feature = "bindings", derive(TS))]
6974pub struct JsonPathFunc {
6975    pub this: Expression,
6976    pub paths: Vec<Expression>,
6977}
6978
6979/// JSON_OBJECT function
6980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6981#[cfg_attr(feature = "bindings", derive(TS))]
6982pub struct JsonObjectFunc {
6983    pub pairs: Vec<(Expression, Expression)>,
6984    pub null_handling: Option<JsonNullHandling>,
6985    #[serde(default)]
6986    pub with_unique_keys: bool,
6987    #[serde(default)]
6988    pub returning_type: Option<DataType>,
6989    #[serde(default)]
6990    pub format_json: bool,
6991    #[serde(default)]
6992    pub encoding: Option<String>,
6993    /// For JSON_OBJECT(*) syntax
6994    #[serde(default)]
6995    pub star: bool,
6996}
6997
6998/// JSON null handling options
6999#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7000#[cfg_attr(feature = "bindings", derive(TS))]
7001pub enum JsonNullHandling {
7002    NullOnNull,
7003    AbsentOnNull,
7004}
7005
7006/// JSON_SET / JSON_INSERT function
7007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7008#[cfg_attr(feature = "bindings", derive(TS))]
7009pub struct JsonModifyFunc {
7010    pub this: Expression,
7011    pub path_values: Vec<(Expression, Expression)>,
7012}
7013
7014/// JSON_ARRAYAGG function
7015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7016#[cfg_attr(feature = "bindings", derive(TS))]
7017pub struct JsonArrayAggFunc {
7018    pub this: Expression,
7019    pub order_by: Option<Vec<Ordered>>,
7020    pub null_handling: Option<JsonNullHandling>,
7021    pub filter: Option<Expression>,
7022}
7023
7024/// JSON_OBJECTAGG function
7025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7026#[cfg_attr(feature = "bindings", derive(TS))]
7027pub struct JsonObjectAggFunc {
7028    pub key: Expression,
7029    pub value: Expression,
7030    pub null_handling: Option<JsonNullHandling>,
7031    pub filter: Option<Expression>,
7032}
7033
7034// ============================================================================
7035// Type Casting Function types
7036// ============================================================================
7037
7038/// CONVERT function (SQL Server style)
7039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7040#[cfg_attr(feature = "bindings", derive(TS))]
7041pub struct ConvertFunc {
7042    pub this: Expression,
7043    pub to: DataType,
7044    pub style: Option<Expression>,
7045}
7046
7047// ============================================================================
7048// Additional Expression types
7049// ============================================================================
7050
7051/// Lambda expression
7052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7053#[cfg_attr(feature = "bindings", derive(TS))]
7054pub struct LambdaExpr {
7055    pub parameters: Vec<Identifier>,
7056    pub body: Expression,
7057    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7058    #[serde(default)]
7059    pub colon: bool,
7060    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7061    /// Maps parameter index to data type
7062    #[serde(default)]
7063    pub parameter_types: Vec<Option<DataType>>,
7064}
7065
7066/// Parameter (parameterized queries)
7067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7068#[cfg_attr(feature = "bindings", derive(TS))]
7069pub struct Parameter {
7070    pub name: Option<String>,
7071    pub index: Option<u32>,
7072    pub style: ParameterStyle,
7073    /// Whether the name was quoted (e.g., @"x" vs @x)
7074    #[serde(default)]
7075    pub quoted: bool,
7076    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7077    #[serde(default)]
7078    pub string_quoted: bool,
7079    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7080    #[serde(default)]
7081    pub expression: Option<String>,
7082}
7083
7084/// Parameter placeholder styles
7085#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7086#[cfg_attr(feature = "bindings", derive(TS))]
7087pub enum ParameterStyle {
7088    Question,     // ?
7089    Dollar,       // $1, $2
7090    DollarBrace,  // ${name} (Databricks, Hive template variables)
7091    Brace,        // {name} (Spark/Databricks widget/template variables)
7092    Colon,        // :name
7093    At,           // @name
7094    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7095    DoubleDollar, // $$name
7096    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7097}
7098
7099/// Placeholder expression
7100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7101#[cfg_attr(feature = "bindings", derive(TS))]
7102pub struct Placeholder {
7103    pub index: Option<u32>,
7104}
7105
7106/// Named argument in function call: name => value or name := value
7107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7108#[cfg_attr(feature = "bindings", derive(TS))]
7109pub struct NamedArgument {
7110    pub name: Identifier,
7111    pub value: Expression,
7112    /// The separator used: `=>`, `:=`, or `=`
7113    pub separator: NamedArgSeparator,
7114}
7115
7116/// Separator style for named arguments
7117#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7118#[cfg_attr(feature = "bindings", derive(TS))]
7119pub enum NamedArgSeparator {
7120    /// `=>` (standard SQL, Snowflake, BigQuery)
7121    DArrow,
7122    /// `:=` (Oracle, MySQL)
7123    ColonEq,
7124    /// `=` (simple equals, some dialects)
7125    Eq,
7126}
7127
7128/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7129/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7131#[cfg_attr(feature = "bindings", derive(TS))]
7132pub struct TableArgument {
7133    /// The keyword prefix: "TABLE" or "MODEL"
7134    pub prefix: String,
7135    /// The table/model reference expression
7136    pub this: Expression,
7137}
7138
7139/// SQL Comment preservation
7140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7141#[cfg_attr(feature = "bindings", derive(TS))]
7142pub struct SqlComment {
7143    pub text: String,
7144    pub is_block: bool,
7145}
7146
7147// ============================================================================
7148// Additional Predicate types
7149// ============================================================================
7150
7151/// SIMILAR TO expression
7152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub struct SimilarToExpr {
7155    pub this: Expression,
7156    pub pattern: Expression,
7157    pub escape: Option<Expression>,
7158    pub not: bool,
7159}
7160
7161/// ANY / ALL quantified expression
7162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7163#[cfg_attr(feature = "bindings", derive(TS))]
7164pub struct QuantifiedExpr {
7165    pub this: Expression,
7166    pub subquery: Expression,
7167    pub op: Option<QuantifiedOp>,
7168}
7169
7170/// Comparison operator for quantified expressions
7171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7172#[cfg_attr(feature = "bindings", derive(TS))]
7173pub enum QuantifiedOp {
7174    Eq,
7175    Neq,
7176    Lt,
7177    Lte,
7178    Gt,
7179    Gte,
7180}
7181
7182/// OVERLAPS expression
7183/// Supports two forms:
7184/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7185/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7187#[cfg_attr(feature = "bindings", derive(TS))]
7188pub struct OverlapsExpr {
7189    /// Left operand for simple binary form
7190    #[serde(skip_serializing_if = "Option::is_none")]
7191    pub this: Option<Expression>,
7192    /// Right operand for simple binary form
7193    #[serde(skip_serializing_if = "Option::is_none")]
7194    pub expression: Option<Expression>,
7195    /// Left range start for full ANSI form
7196    #[serde(skip_serializing_if = "Option::is_none")]
7197    pub left_start: Option<Expression>,
7198    /// Left range end for full ANSI form
7199    #[serde(skip_serializing_if = "Option::is_none")]
7200    pub left_end: Option<Expression>,
7201    /// Right range start for full ANSI form
7202    #[serde(skip_serializing_if = "Option::is_none")]
7203    pub right_start: Option<Expression>,
7204    /// Right range end for full ANSI form
7205    #[serde(skip_serializing_if = "Option::is_none")]
7206    pub right_end: Option<Expression>,
7207}
7208
7209// ============================================================================
7210// Array/Struct/Map access
7211// ============================================================================
7212
7213/// Subscript access (array[index] or map[key])
7214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7215#[cfg_attr(feature = "bindings", derive(TS))]
7216pub struct Subscript {
7217    pub this: Expression,
7218    pub index: Expression,
7219}
7220
7221/// Dot access (struct.field)
7222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7223#[cfg_attr(feature = "bindings", derive(TS))]
7224pub struct DotAccess {
7225    pub this: Expression,
7226    pub field: Identifier,
7227}
7228
7229/// Method call (expr.method(args))
7230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7231#[cfg_attr(feature = "bindings", derive(TS))]
7232pub struct MethodCall {
7233    pub this: Expression,
7234    pub method: Identifier,
7235    pub args: Vec<Expression>,
7236}
7237
7238/// Array slice (array[start:end])
7239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7240#[cfg_attr(feature = "bindings", derive(TS))]
7241pub struct ArraySlice {
7242    pub this: Expression,
7243    pub start: Option<Expression>,
7244    pub end: Option<Expression>,
7245}
7246
7247// ============================================================================
7248// DDL (Data Definition Language) Statements
7249// ============================================================================
7250
7251/// ON COMMIT behavior for temporary tables
7252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7253#[cfg_attr(feature = "bindings", derive(TS))]
7254pub enum OnCommit {
7255    /// ON COMMIT PRESERVE ROWS
7256    PreserveRows,
7257    /// ON COMMIT DELETE ROWS
7258    DeleteRows,
7259}
7260
7261/// CREATE TABLE statement
7262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7263#[cfg_attr(feature = "bindings", derive(TS))]
7264pub struct CreateTable {
7265    pub name: TableRef,
7266    /// ClickHouse: ON CLUSTER clause for distributed DDL
7267    #[serde(default, skip_serializing_if = "Option::is_none")]
7268    pub on_cluster: Option<OnCluster>,
7269    pub columns: Vec<ColumnDef>,
7270    pub constraints: Vec<TableConstraint>,
7271    pub if_not_exists: bool,
7272    pub temporary: bool,
7273    pub or_replace: bool,
7274    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7275    #[serde(default, skip_serializing_if = "Option::is_none")]
7276    pub table_modifier: Option<String>,
7277    pub as_select: Option<Expression>,
7278    /// Whether the AS SELECT was wrapped in parentheses
7279    #[serde(default)]
7280    pub as_select_parenthesized: bool,
7281    /// ON COMMIT behavior for temporary tables
7282    #[serde(default)]
7283    pub on_commit: Option<OnCommit>,
7284    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7285    #[serde(default)]
7286    pub clone_source: Option<TableRef>,
7287    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7288    #[serde(default, skip_serializing_if = "Option::is_none")]
7289    pub clone_at_clause: Option<Expression>,
7290    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7291    #[serde(default)]
7292    pub is_copy: bool,
7293    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7294    #[serde(default)]
7295    pub shallow_clone: bool,
7296    /// Leading comments before the statement
7297    #[serde(default)]
7298    pub leading_comments: Vec<String>,
7299    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7300    #[serde(default)]
7301    pub with_properties: Vec<(String, String)>,
7302    /// Teradata: table options after name before columns (comma-separated)
7303    #[serde(default)]
7304    pub teradata_post_name_options: Vec<String>,
7305    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7306    #[serde(default)]
7307    pub with_data: Option<bool>,
7308    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7309    #[serde(default)]
7310    pub with_statistics: Option<bool>,
7311    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7312    #[serde(default)]
7313    pub teradata_indexes: Vec<TeradataIndex>,
7314    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7315    #[serde(default)]
7316    pub with_cte: Option<With>,
7317    /// Table properties like DEFAULT COLLATE (BigQuery)
7318    #[serde(default)]
7319    pub properties: Vec<Expression>,
7320    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7321    #[serde(default, skip_serializing_if = "Option::is_none")]
7322    pub partition_of: Option<Expression>,
7323    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7324    #[serde(default)]
7325    pub post_table_properties: Vec<Expression>,
7326    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7327    #[serde(default)]
7328    pub mysql_table_options: Vec<(String, String)>,
7329    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7330    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7331    pub inherits: Vec<TableRef>,
7332    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7333    #[serde(default, skip_serializing_if = "Option::is_none")]
7334    pub on_property: Option<OnProperty>,
7335    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7336    #[serde(default)]
7337    pub copy_grants: bool,
7338    /// Snowflake: USING TEMPLATE expression for schema inference
7339    #[serde(default, skip_serializing_if = "Option::is_none")]
7340    pub using_template: Option<Box<Expression>>,
7341    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7342    #[serde(default, skip_serializing_if = "Option::is_none")]
7343    pub rollup: Option<RollupProperty>,
7344    /// ClickHouse: UUID 'xxx' clause after table name
7345    #[serde(default, skip_serializing_if = "Option::is_none")]
7346    pub uuid: Option<String>,
7347}
7348
7349/// Teradata index specification for CREATE TABLE
7350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7351#[cfg_attr(feature = "bindings", derive(TS))]
7352pub struct TeradataIndex {
7353    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7354    pub kind: TeradataIndexKind,
7355    /// Optional index name
7356    pub name: Option<String>,
7357    /// Optional column list
7358    pub columns: Vec<String>,
7359}
7360
7361/// Kind of Teradata index
7362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7363#[cfg_attr(feature = "bindings", derive(TS))]
7364pub enum TeradataIndexKind {
7365    /// NO PRIMARY INDEX
7366    NoPrimary,
7367    /// PRIMARY INDEX
7368    Primary,
7369    /// PRIMARY AMP INDEX
7370    PrimaryAmp,
7371    /// UNIQUE INDEX
7372    Unique,
7373    /// UNIQUE PRIMARY INDEX
7374    UniquePrimary,
7375    /// INDEX (secondary, non-primary)
7376    Secondary,
7377}
7378
7379impl CreateTable {
7380    pub fn new(name: impl Into<String>) -> Self {
7381        Self {
7382            name: TableRef::new(name),
7383            on_cluster: None,
7384            columns: Vec::new(),
7385            constraints: Vec::new(),
7386            if_not_exists: false,
7387            temporary: false,
7388            or_replace: false,
7389            table_modifier: None,
7390            as_select: None,
7391            as_select_parenthesized: false,
7392            on_commit: None,
7393            clone_source: None,
7394            clone_at_clause: None,
7395            shallow_clone: false,
7396            is_copy: false,
7397            leading_comments: Vec::new(),
7398            with_properties: Vec::new(),
7399            teradata_post_name_options: Vec::new(),
7400            with_data: None,
7401            with_statistics: None,
7402            teradata_indexes: Vec::new(),
7403            with_cte: None,
7404            properties: Vec::new(),
7405            partition_of: None,
7406            post_table_properties: Vec::new(),
7407            mysql_table_options: Vec::new(),
7408            inherits: Vec::new(),
7409            on_property: None,
7410            copy_grants: false,
7411            using_template: None,
7412            rollup: None,
7413            uuid: None,
7414        }
7415    }
7416}
7417
7418/// Sort order for PRIMARY KEY ASC/DESC
7419#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7420#[cfg_attr(feature = "bindings", derive(TS))]
7421pub enum SortOrder {
7422    Asc,
7423    Desc,
7424}
7425
7426/// Type of column constraint for tracking order
7427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7428#[cfg_attr(feature = "bindings", derive(TS))]
7429pub enum ConstraintType {
7430    NotNull,
7431    Null,
7432    PrimaryKey,
7433    Unique,
7434    Default,
7435    AutoIncrement,
7436    Collate,
7437    Comment,
7438    References,
7439    Check,
7440    GeneratedAsIdentity,
7441    /// Snowflake: TAG (key='value', ...)
7442    Tags,
7443    /// Computed/generated column
7444    ComputedColumn,
7445    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7446    GeneratedAsRow,
7447    /// MySQL: ON UPDATE expression
7448    OnUpdate,
7449    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7450    Path,
7451    /// Redshift: ENCODE encoding_type
7452    Encode,
7453}
7454
7455/// Column definition in CREATE TABLE
7456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7457#[cfg_attr(feature = "bindings", derive(TS))]
7458pub struct ColumnDef {
7459    pub name: Identifier,
7460    pub data_type: DataType,
7461    pub nullable: Option<bool>,
7462    pub default: Option<Expression>,
7463    pub primary_key: bool,
7464    /// Sort order for PRIMARY KEY (ASC/DESC)
7465    #[serde(default)]
7466    pub primary_key_order: Option<SortOrder>,
7467    pub unique: bool,
7468    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7469    #[serde(default)]
7470    pub unique_nulls_not_distinct: bool,
7471    pub auto_increment: bool,
7472    pub comment: Option<String>,
7473    pub constraints: Vec<ColumnConstraint>,
7474    /// Track original order of constraints for accurate regeneration
7475    #[serde(default)]
7476    pub constraint_order: Vec<ConstraintType>,
7477    /// Teradata: FORMAT 'pattern'
7478    #[serde(default)]
7479    pub format: Option<String>,
7480    /// Teradata: TITLE 'title'
7481    #[serde(default)]
7482    pub title: Option<String>,
7483    /// Teradata: INLINE LENGTH n
7484    #[serde(default)]
7485    pub inline_length: Option<u64>,
7486    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7487    #[serde(default)]
7488    pub compress: Option<Vec<Expression>>,
7489    /// Teradata: CHARACTER SET name
7490    #[serde(default)]
7491    pub character_set: Option<String>,
7492    /// Teradata: UPPERCASE
7493    #[serde(default)]
7494    pub uppercase: bool,
7495    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7496    #[serde(default)]
7497    pub casespecific: Option<bool>,
7498    /// Snowflake: AUTOINCREMENT START value
7499    #[serde(default)]
7500    pub auto_increment_start: Option<Box<Expression>>,
7501    /// Snowflake: AUTOINCREMENT INCREMENT value
7502    #[serde(default)]
7503    pub auto_increment_increment: Option<Box<Expression>>,
7504    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7505    #[serde(default)]
7506    pub auto_increment_order: Option<bool>,
7507    /// MySQL: UNSIGNED modifier
7508    #[serde(default)]
7509    pub unsigned: bool,
7510    /// MySQL: ZEROFILL modifier
7511    #[serde(default)]
7512    pub zerofill: bool,
7513    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7514    #[serde(default, skip_serializing_if = "Option::is_none")]
7515    pub on_update: Option<Expression>,
7516    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7517    #[serde(default, skip_serializing_if = "Option::is_none")]
7518    pub unique_constraint_name: Option<String>,
7519    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7520    #[serde(default, skip_serializing_if = "Option::is_none")]
7521    pub not_null_constraint_name: Option<String>,
7522    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7523    #[serde(default, skip_serializing_if = "Option::is_none")]
7524    pub primary_key_constraint_name: Option<String>,
7525    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7526    #[serde(default, skip_serializing_if = "Option::is_none")]
7527    pub check_constraint_name: Option<String>,
7528    /// BigQuery: OPTIONS (key=value, ...) on column
7529    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7530    pub options: Vec<Expression>,
7531    /// SQLite: Column definition without explicit type
7532    #[serde(default)]
7533    pub no_type: bool,
7534    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7535    #[serde(default, skip_serializing_if = "Option::is_none")]
7536    pub encoding: Option<String>,
7537    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7538    #[serde(default, skip_serializing_if = "Option::is_none")]
7539    pub codec: Option<String>,
7540    /// ClickHouse: EPHEMERAL [expr] modifier
7541    #[serde(default, skip_serializing_if = "Option::is_none")]
7542    pub ephemeral: Option<Option<Box<Expression>>>,
7543    /// ClickHouse: MATERIALIZED expr modifier
7544    #[serde(default, skip_serializing_if = "Option::is_none")]
7545    pub materialized_expr: Option<Box<Expression>>,
7546    /// ClickHouse: ALIAS expr modifier
7547    #[serde(default, skip_serializing_if = "Option::is_none")]
7548    pub alias_expr: Option<Box<Expression>>,
7549    /// ClickHouse: TTL expr modifier on columns
7550    #[serde(default, skip_serializing_if = "Option::is_none")]
7551    pub ttl_expr: Option<Box<Expression>>,
7552    /// TSQL: NOT FOR REPLICATION
7553    #[serde(default)]
7554    pub not_for_replication: bool,
7555}
7556
7557impl ColumnDef {
7558    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7559        Self {
7560            name: Identifier::new(name),
7561            data_type,
7562            nullable: None,
7563            default: None,
7564            primary_key: false,
7565            primary_key_order: None,
7566            unique: false,
7567            unique_nulls_not_distinct: false,
7568            auto_increment: false,
7569            comment: None,
7570            constraints: Vec::new(),
7571            constraint_order: Vec::new(),
7572            format: None,
7573            title: None,
7574            inline_length: None,
7575            compress: None,
7576            character_set: None,
7577            uppercase: false,
7578            casespecific: None,
7579            auto_increment_start: None,
7580            auto_increment_increment: None,
7581            auto_increment_order: None,
7582            unsigned: false,
7583            zerofill: false,
7584            on_update: None,
7585            unique_constraint_name: None,
7586            not_null_constraint_name: None,
7587            primary_key_constraint_name: None,
7588            check_constraint_name: None,
7589            options: Vec::new(),
7590            no_type: false,
7591            encoding: None,
7592            codec: None,
7593            ephemeral: None,
7594            materialized_expr: None,
7595            alias_expr: None,
7596            ttl_expr: None,
7597            not_for_replication: false,
7598        }
7599    }
7600}
7601
7602/// Column-level constraint
7603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7604#[cfg_attr(feature = "bindings", derive(TS))]
7605pub enum ColumnConstraint {
7606    NotNull,
7607    Null,
7608    Unique,
7609    PrimaryKey,
7610    Default(Expression),
7611    Check(Expression),
7612    References(ForeignKeyRef),
7613    GeneratedAsIdentity(GeneratedAsIdentity),
7614    Collate(Identifier),
7615    Comment(String),
7616    /// Snowflake: TAG (key='value', ...)
7617    Tags(Tags),
7618    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7619    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7620    ComputedColumn(ComputedColumn),
7621    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7622    GeneratedAsRow(GeneratedAsRow),
7623    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7624    Path(Expression),
7625}
7626
7627/// Computed/generated column constraint
7628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7629#[cfg_attr(feature = "bindings", derive(TS))]
7630pub struct ComputedColumn {
7631    /// The expression that computes the column value
7632    pub expression: Box<Expression>,
7633    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7634    #[serde(default)]
7635    pub persisted: bool,
7636    /// NOT NULL (TSQL computed columns)
7637    #[serde(default)]
7638    pub not_null: bool,
7639    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7640    /// When None, defaults to dialect-appropriate output
7641    #[serde(default)]
7642    pub persistence_kind: Option<String>,
7643    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7644    #[serde(default, skip_serializing_if = "Option::is_none")]
7645    pub data_type: Option<DataType>,
7646}
7647
7648/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7650#[cfg_attr(feature = "bindings", derive(TS))]
7651pub struct GeneratedAsRow {
7652    /// true = ROW START, false = ROW END
7653    pub start: bool,
7654    /// HIDDEN modifier
7655    #[serde(default)]
7656    pub hidden: bool,
7657}
7658
7659/// Generated identity column constraint
7660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7661#[cfg_attr(feature = "bindings", derive(TS))]
7662pub struct GeneratedAsIdentity {
7663    /// True for ALWAYS, False for BY DEFAULT
7664    pub always: bool,
7665    /// ON NULL (only valid with BY DEFAULT)
7666    pub on_null: bool,
7667    /// START WITH value
7668    pub start: Option<Box<Expression>>,
7669    /// INCREMENT BY value
7670    pub increment: Option<Box<Expression>>,
7671    /// MINVALUE
7672    pub minvalue: Option<Box<Expression>>,
7673    /// MAXVALUE
7674    pub maxvalue: Option<Box<Expression>>,
7675    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7676    pub cycle: Option<bool>,
7677}
7678
7679/// Constraint modifiers (shared between table-level constraints)
7680#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7681#[cfg_attr(feature = "bindings", derive(TS))]
7682pub struct ConstraintModifiers {
7683    /// ENFORCED / NOT ENFORCED
7684    pub enforced: Option<bool>,
7685    /// DEFERRABLE / NOT DEFERRABLE
7686    pub deferrable: Option<bool>,
7687    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7688    pub initially_deferred: Option<bool>,
7689    /// NORELY (Oracle)
7690    pub norely: bool,
7691    /// RELY (Oracle)
7692    pub rely: bool,
7693    /// USING index type (MySQL): BTREE or HASH
7694    #[serde(default)]
7695    pub using: Option<String>,
7696    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7697    #[serde(default)]
7698    pub using_before_columns: bool,
7699    /// MySQL index COMMENT 'text'
7700    #[serde(default, skip_serializing_if = "Option::is_none")]
7701    pub comment: Option<String>,
7702    /// MySQL index VISIBLE/INVISIBLE
7703    #[serde(default, skip_serializing_if = "Option::is_none")]
7704    pub visible: Option<bool>,
7705    /// MySQL ENGINE_ATTRIBUTE = 'value'
7706    #[serde(default, skip_serializing_if = "Option::is_none")]
7707    pub engine_attribute: Option<String>,
7708    /// MySQL WITH PARSER name
7709    #[serde(default, skip_serializing_if = "Option::is_none")]
7710    pub with_parser: Option<String>,
7711    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7712    #[serde(default)]
7713    pub not_valid: bool,
7714    /// TSQL CLUSTERED/NONCLUSTERED modifier
7715    #[serde(default, skip_serializing_if = "Option::is_none")]
7716    pub clustered: Option<String>,
7717    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7718    #[serde(default, skip_serializing_if = "Option::is_none")]
7719    pub on_conflict: Option<String>,
7720    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7721    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7722    pub with_options: Vec<(String, String)>,
7723    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7724    #[serde(default, skip_serializing_if = "Option::is_none")]
7725    pub on_filegroup: Option<Identifier>,
7726}
7727
7728/// Table-level constraint
7729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7730#[cfg_attr(feature = "bindings", derive(TS))]
7731pub enum TableConstraint {
7732    PrimaryKey {
7733        name: Option<Identifier>,
7734        columns: Vec<Identifier>,
7735        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7736        #[serde(default)]
7737        include_columns: Vec<Identifier>,
7738        #[serde(default)]
7739        modifiers: ConstraintModifiers,
7740        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7741        #[serde(default)]
7742        has_constraint_keyword: bool,
7743    },
7744    Unique {
7745        name: Option<Identifier>,
7746        columns: Vec<Identifier>,
7747        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7748        #[serde(default)]
7749        columns_parenthesized: bool,
7750        #[serde(default)]
7751        modifiers: ConstraintModifiers,
7752        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7753        #[serde(default)]
7754        has_constraint_keyword: bool,
7755        /// PostgreSQL 15+: NULLS NOT DISTINCT
7756        #[serde(default)]
7757        nulls_not_distinct: bool,
7758    },
7759    ForeignKey {
7760        name: Option<Identifier>,
7761        columns: Vec<Identifier>,
7762        #[serde(default)]
7763        references: Option<ForeignKeyRef>,
7764        /// ON DELETE action when REFERENCES is absent
7765        #[serde(default)]
7766        on_delete: Option<ReferentialAction>,
7767        /// ON UPDATE action when REFERENCES is absent
7768        #[serde(default)]
7769        on_update: Option<ReferentialAction>,
7770        #[serde(default)]
7771        modifiers: ConstraintModifiers,
7772    },
7773    Check {
7774        name: Option<Identifier>,
7775        expression: Expression,
7776        #[serde(default)]
7777        modifiers: ConstraintModifiers,
7778    },
7779    /// ClickHouse ASSUME constraint (query optimization assumption)
7780    Assume {
7781        name: Option<Identifier>,
7782        expression: Expression,
7783    },
7784    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7785    Default {
7786        name: Option<Identifier>,
7787        expression: Expression,
7788        column: Identifier,
7789    },
7790    /// INDEX / KEY constraint (MySQL)
7791    Index {
7792        name: Option<Identifier>,
7793        columns: Vec<Identifier>,
7794        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7795        #[serde(default)]
7796        kind: Option<String>,
7797        #[serde(default)]
7798        modifiers: ConstraintModifiers,
7799        /// True if KEY keyword was used instead of INDEX
7800        #[serde(default)]
7801        use_key_keyword: bool,
7802        /// ClickHouse: indexed expression (instead of columns)
7803        #[serde(default, skip_serializing_if = "Option::is_none")]
7804        expression: Option<Box<Expression>>,
7805        /// ClickHouse: TYPE type_func(args)
7806        #[serde(default, skip_serializing_if = "Option::is_none")]
7807        index_type: Option<Box<Expression>>,
7808        /// ClickHouse: GRANULARITY n
7809        #[serde(default, skip_serializing_if = "Option::is_none")]
7810        granularity: Option<Box<Expression>>,
7811    },
7812    /// ClickHouse PROJECTION definition
7813    Projection {
7814        name: Identifier,
7815        expression: Expression,
7816    },
7817    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7818    Like {
7819        source: TableRef,
7820        /// Options as (INCLUDING|EXCLUDING, property) pairs
7821        options: Vec<(LikeOptionAction, String)>,
7822    },
7823    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7824    PeriodForSystemTime {
7825        start_col: Identifier,
7826        end_col: Identifier,
7827    },
7828    /// PostgreSQL EXCLUDE constraint
7829    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7830    Exclude {
7831        name: Option<Identifier>,
7832        /// Index access method (gist, btree, etc.)
7833        #[serde(default)]
7834        using: Option<String>,
7835        /// Elements: (expression, operator) pairs
7836        elements: Vec<ExcludeElement>,
7837        /// INCLUDE columns
7838        #[serde(default)]
7839        include_columns: Vec<Identifier>,
7840        /// WHERE predicate
7841        #[serde(default)]
7842        where_clause: Option<Box<Expression>>,
7843        /// WITH (storage_parameters)
7844        #[serde(default)]
7845        with_params: Vec<(String, String)>,
7846        /// USING INDEX TABLESPACE tablespace_name
7847        #[serde(default)]
7848        using_index_tablespace: Option<String>,
7849        #[serde(default)]
7850        modifiers: ConstraintModifiers,
7851    },
7852    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7853    Tags(Tags),
7854    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7855    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7856    /// for all deferrable constraints in the table
7857    InitiallyDeferred {
7858        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7859        deferred: bool,
7860    },
7861}
7862
7863/// Element in an EXCLUDE constraint: expression WITH operator
7864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7865#[cfg_attr(feature = "bindings", derive(TS))]
7866pub struct ExcludeElement {
7867    /// The column expression (may include operator class, ordering, nulls)
7868    pub expression: String,
7869    /// The operator (e.g., &&, =)
7870    pub operator: String,
7871}
7872
7873/// Action for LIKE clause options
7874#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7875#[cfg_attr(feature = "bindings", derive(TS))]
7876pub enum LikeOptionAction {
7877    Including,
7878    Excluding,
7879}
7880
7881/// MATCH type for foreign keys
7882#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7883#[cfg_attr(feature = "bindings", derive(TS))]
7884pub enum MatchType {
7885    Full,
7886    Partial,
7887    Simple,
7888}
7889
7890/// Foreign key reference
7891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7892#[cfg_attr(feature = "bindings", derive(TS))]
7893pub struct ForeignKeyRef {
7894    pub table: TableRef,
7895    pub columns: Vec<Identifier>,
7896    pub on_delete: Option<ReferentialAction>,
7897    pub on_update: Option<ReferentialAction>,
7898    /// True if ON UPDATE appears before ON DELETE in the original SQL
7899    #[serde(default)]
7900    pub on_update_first: bool,
7901    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7902    #[serde(default)]
7903    pub match_type: Option<MatchType>,
7904    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7905    #[serde(default)]
7906    pub match_after_actions: bool,
7907    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7908    #[serde(default)]
7909    pub constraint_name: Option<String>,
7910    /// DEFERRABLE / NOT DEFERRABLE
7911    #[serde(default)]
7912    pub deferrable: Option<bool>,
7913    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7914    #[serde(default)]
7915    pub has_foreign_key_keywords: bool,
7916}
7917
7918/// Referential action for foreign keys
7919#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7920#[cfg_attr(feature = "bindings", derive(TS))]
7921pub enum ReferentialAction {
7922    Cascade,
7923    SetNull,
7924    SetDefault,
7925    Restrict,
7926    NoAction,
7927}
7928
7929/// DROP TABLE statement
7930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7931#[cfg_attr(feature = "bindings", derive(TS))]
7932pub struct DropTable {
7933    pub names: Vec<TableRef>,
7934    pub if_exists: bool,
7935    pub cascade: bool,
7936    /// Oracle: CASCADE CONSTRAINTS
7937    #[serde(default)]
7938    pub cascade_constraints: bool,
7939    /// Oracle: PURGE
7940    #[serde(default)]
7941    pub purge: bool,
7942    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7943    #[serde(default)]
7944    pub leading_comments: Vec<String>,
7945    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7946    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7947    #[serde(default, skip_serializing_if = "Option::is_none")]
7948    pub object_id_args: Option<String>,
7949    /// ClickHouse: SYNC modifier
7950    #[serde(default)]
7951    pub sync: bool,
7952    /// Snowflake: DROP ICEBERG TABLE
7953    #[serde(default)]
7954    pub iceberg: bool,
7955    /// RESTRICT modifier (opposite of CASCADE)
7956    #[serde(default)]
7957    pub restrict: bool,
7958}
7959
7960impl DropTable {
7961    pub fn new(name: impl Into<String>) -> Self {
7962        Self {
7963            names: vec![TableRef::new(name)],
7964            if_exists: false,
7965            cascade: false,
7966            cascade_constraints: false,
7967            purge: false,
7968            leading_comments: Vec::new(),
7969            object_id_args: None,
7970            sync: false,
7971            iceberg: false,
7972            restrict: false,
7973        }
7974    }
7975}
7976
7977/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
7978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7979#[cfg_attr(feature = "bindings", derive(TS))]
7980pub struct Undrop {
7981    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
7982    pub kind: String,
7983    /// The object name
7984    pub name: TableRef,
7985    /// IF EXISTS clause
7986    #[serde(default)]
7987    pub if_exists: bool,
7988}
7989
7990/// ALTER TABLE statement
7991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7992#[cfg_attr(feature = "bindings", derive(TS))]
7993pub struct AlterTable {
7994    pub name: TableRef,
7995    pub actions: Vec<AlterTableAction>,
7996    /// IF EXISTS clause
7997    #[serde(default)]
7998    pub if_exists: bool,
7999    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8000    #[serde(default, skip_serializing_if = "Option::is_none")]
8001    pub algorithm: Option<String>,
8002    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8003    #[serde(default, skip_serializing_if = "Option::is_none")]
8004    pub lock: Option<String>,
8005    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8006    #[serde(default, skip_serializing_if = "Option::is_none")]
8007    pub with_check: Option<String>,
8008    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8009    #[serde(default, skip_serializing_if = "Option::is_none")]
8010    pub partition: Option<Vec<(Identifier, Expression)>>,
8011    /// ClickHouse: ON CLUSTER clause for distributed DDL
8012    #[serde(default, skip_serializing_if = "Option::is_none")]
8013    pub on_cluster: Option<OnCluster>,
8014    /// Snowflake: ALTER ICEBERG TABLE
8015    #[serde(default, skip_serializing_if = "Option::is_none")]
8016    pub table_modifier: Option<String>,
8017}
8018
8019impl AlterTable {
8020    pub fn new(name: impl Into<String>) -> Self {
8021        Self {
8022            name: TableRef::new(name),
8023            actions: Vec::new(),
8024            if_exists: false,
8025            algorithm: None,
8026            lock: None,
8027            with_check: None,
8028            partition: None,
8029            on_cluster: None,
8030            table_modifier: None,
8031        }
8032    }
8033}
8034
8035/// Column position for ADD COLUMN (MySQL/MariaDB)
8036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8037#[cfg_attr(feature = "bindings", derive(TS))]
8038pub enum ColumnPosition {
8039    First,
8040    After(Identifier),
8041}
8042
8043/// Actions for ALTER TABLE
8044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8045#[cfg_attr(feature = "bindings", derive(TS))]
8046pub enum AlterTableAction {
8047    AddColumn {
8048        column: ColumnDef,
8049        if_not_exists: bool,
8050        position: Option<ColumnPosition>,
8051    },
8052    DropColumn {
8053        name: Identifier,
8054        if_exists: bool,
8055        cascade: bool,
8056    },
8057    RenameColumn {
8058        old_name: Identifier,
8059        new_name: Identifier,
8060        if_exists: bool,
8061    },
8062    AlterColumn {
8063        name: Identifier,
8064        action: AlterColumnAction,
8065        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8066        #[serde(default)]
8067        use_modify_keyword: bool,
8068    },
8069    RenameTable(TableRef),
8070    AddConstraint(TableConstraint),
8071    DropConstraint {
8072        name: Identifier,
8073        if_exists: bool,
8074    },
8075    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8076    DropForeignKey {
8077        name: Identifier,
8078    },
8079    /// DROP PARTITION action (Hive/BigQuery)
8080    DropPartition {
8081        /// List of partitions to drop (each partition is a list of key=value pairs)
8082        partitions: Vec<Vec<(Identifier, Expression)>>,
8083        if_exists: bool,
8084    },
8085    /// ADD PARTITION action (Hive/Spark)
8086    AddPartition {
8087        /// The partition expression
8088        partition: Expression,
8089        if_not_exists: bool,
8090        location: Option<Expression>,
8091    },
8092    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8093    Delete {
8094        where_clause: Expression,
8095    },
8096    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8097    SwapWith(TableRef),
8098    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8099    SetProperty {
8100        properties: Vec<(String, Expression)>,
8101    },
8102    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8103    UnsetProperty {
8104        properties: Vec<String>,
8105    },
8106    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8107    ClusterBy {
8108        expressions: Vec<Expression>,
8109    },
8110    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8111    SetTag {
8112        expressions: Vec<(String, Expression)>,
8113    },
8114    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8115    UnsetTag {
8116        names: Vec<String>,
8117    },
8118    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8119    SetOptions {
8120        expressions: Vec<Expression>,
8121    },
8122    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8123    AlterIndex {
8124        name: Identifier,
8125        visible: bool,
8126    },
8127    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8128    SetAttribute {
8129        attribute: String,
8130    },
8131    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8132    SetStageFileFormat {
8133        options: Option<Expression>,
8134    },
8135    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8136    SetStageCopyOptions {
8137        options: Option<Expression>,
8138    },
8139    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8140    AddColumns {
8141        columns: Vec<ColumnDef>,
8142        cascade: bool,
8143    },
8144    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8145    DropColumns {
8146        names: Vec<Identifier>,
8147    },
8148    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8149    /// In SingleStore, data_type can be omitted for simple column renames
8150    ChangeColumn {
8151        old_name: Identifier,
8152        new_name: Identifier,
8153        #[serde(default, skip_serializing_if = "Option::is_none")]
8154        data_type: Option<DataType>,
8155        comment: Option<String>,
8156        #[serde(default)]
8157        cascade: bool,
8158    },
8159    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8160    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8161    AlterSortKey {
8162        /// AUTO or NONE keyword
8163        this: Option<String>,
8164        /// Column list for (col1, col2) syntax
8165        expressions: Vec<Expression>,
8166        /// Whether COMPOUND keyword was present
8167        compound: bool,
8168    },
8169    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8170    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8171    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8172    AlterDistStyle {
8173        /// Distribution style: ALL, EVEN, AUTO, or KEY
8174        style: String,
8175        /// DISTKEY column (only when style is KEY)
8176        distkey: Option<Identifier>,
8177    },
8178    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8179    SetTableProperties {
8180        properties: Vec<(Expression, Expression)>,
8181    },
8182    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8183    SetLocation {
8184        location: String,
8185    },
8186    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8187    SetFileFormat {
8188        format: String,
8189    },
8190    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8191    ReplacePartition {
8192        partition: Expression,
8193        source: Option<Box<Expression>>,
8194    },
8195    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8196    Raw {
8197        sql: String,
8198    },
8199}
8200
8201/// Actions for ALTER COLUMN
8202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8203#[cfg_attr(feature = "bindings", derive(TS))]
8204pub enum AlterColumnAction {
8205    SetDataType {
8206        data_type: DataType,
8207        /// USING expression for type conversion (PostgreSQL)
8208        using: Option<Expression>,
8209        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8210        #[serde(default, skip_serializing_if = "Option::is_none")]
8211        collate: Option<String>,
8212    },
8213    SetDefault(Expression),
8214    DropDefault,
8215    SetNotNull,
8216    DropNotNull,
8217    /// Set column comment
8218    Comment(String),
8219    /// MySQL: SET VISIBLE
8220    SetVisible,
8221    /// MySQL: SET INVISIBLE
8222    SetInvisible,
8223}
8224
8225/// CREATE INDEX statement
8226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8227#[cfg_attr(feature = "bindings", derive(TS))]
8228pub struct CreateIndex {
8229    pub name: Identifier,
8230    pub table: TableRef,
8231    pub columns: Vec<IndexColumn>,
8232    pub unique: bool,
8233    pub if_not_exists: bool,
8234    pub using: Option<String>,
8235    /// TSQL CLUSTERED/NONCLUSTERED modifier
8236    #[serde(default)]
8237    pub clustered: Option<String>,
8238    /// PostgreSQL CONCURRENTLY modifier
8239    #[serde(default)]
8240    pub concurrently: bool,
8241    /// PostgreSQL WHERE clause for partial indexes
8242    #[serde(default)]
8243    pub where_clause: Option<Box<Expression>>,
8244    /// PostgreSQL INCLUDE columns
8245    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8246    pub include_columns: Vec<Identifier>,
8247    /// TSQL WITH options (e.g., allow_page_locks=on)
8248    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8249    pub with_options: Vec<(String, String)>,
8250    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8251    #[serde(default)]
8252    pub on_filegroup: Option<String>,
8253}
8254
8255impl CreateIndex {
8256    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8257        Self {
8258            name: Identifier::new(name),
8259            table: TableRef::new(table),
8260            columns: Vec::new(),
8261            unique: false,
8262            if_not_exists: false,
8263            using: None,
8264            clustered: None,
8265            concurrently: false,
8266            where_clause: None,
8267            include_columns: Vec::new(),
8268            with_options: Vec::new(),
8269            on_filegroup: None,
8270        }
8271    }
8272}
8273
8274/// Index column specification
8275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8276#[cfg_attr(feature = "bindings", derive(TS))]
8277pub struct IndexColumn {
8278    pub column: Identifier,
8279    pub desc: bool,
8280    /// Explicit ASC keyword was present
8281    #[serde(default)]
8282    pub asc: bool,
8283    pub nulls_first: Option<bool>,
8284    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8285    #[serde(default, skip_serializing_if = "Option::is_none")]
8286    pub opclass: Option<String>,
8287}
8288
8289/// DROP INDEX statement
8290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8291#[cfg_attr(feature = "bindings", derive(TS))]
8292pub struct DropIndex {
8293    pub name: Identifier,
8294    pub table: Option<TableRef>,
8295    pub if_exists: bool,
8296    /// PostgreSQL CONCURRENTLY modifier
8297    #[serde(default)]
8298    pub concurrently: bool,
8299}
8300
8301impl DropIndex {
8302    pub fn new(name: impl Into<String>) -> Self {
8303        Self {
8304            name: Identifier::new(name),
8305            table: None,
8306            if_exists: false,
8307            concurrently: false,
8308        }
8309    }
8310}
8311
8312/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8314#[cfg_attr(feature = "bindings", derive(TS))]
8315pub struct ViewColumn {
8316    pub name: Identifier,
8317    pub comment: Option<String>,
8318    /// BigQuery: OPTIONS (key=value, ...) on column
8319    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8320    pub options: Vec<Expression>,
8321}
8322
8323impl ViewColumn {
8324    pub fn new(name: impl Into<String>) -> Self {
8325        Self {
8326            name: Identifier::new(name),
8327            comment: None,
8328            options: Vec::new(),
8329        }
8330    }
8331
8332    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8333        Self {
8334            name: Identifier::new(name),
8335            comment: Some(comment.into()),
8336            options: Vec::new(),
8337        }
8338    }
8339}
8340
8341/// CREATE VIEW statement
8342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8343#[cfg_attr(feature = "bindings", derive(TS))]
8344pub struct CreateView {
8345    pub name: TableRef,
8346    pub columns: Vec<ViewColumn>,
8347    pub query: Expression,
8348    pub or_replace: bool,
8349    /// TSQL: CREATE OR ALTER
8350    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8351    pub or_alter: bool,
8352    pub if_not_exists: bool,
8353    pub materialized: bool,
8354    pub temporary: bool,
8355    /// Snowflake: SECURE VIEW
8356    #[serde(default)]
8357    pub secure: bool,
8358    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8359    #[serde(skip_serializing_if = "Option::is_none")]
8360    pub algorithm: Option<String>,
8361    /// MySQL: DEFINER=user@host
8362    #[serde(skip_serializing_if = "Option::is_none")]
8363    pub definer: Option<String>,
8364    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8365    #[serde(skip_serializing_if = "Option::is_none")]
8366    pub security: Option<FunctionSecurity>,
8367    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8368    #[serde(default = "default_true")]
8369    pub security_sql_style: bool,
8370    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8371    #[serde(default)]
8372    pub security_after_name: bool,
8373    /// Whether the query was parenthesized: AS (SELECT ...)
8374    #[serde(default)]
8375    pub query_parenthesized: bool,
8376    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8377    #[serde(skip_serializing_if = "Option::is_none")]
8378    pub locking_mode: Option<String>,
8379    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8380    #[serde(skip_serializing_if = "Option::is_none")]
8381    pub locking_access: Option<String>,
8382    /// Snowflake: COPY GRANTS
8383    #[serde(default)]
8384    pub copy_grants: bool,
8385    /// Snowflake: COMMENT = 'text'
8386    #[serde(skip_serializing_if = "Option::is_none", default)]
8387    pub comment: Option<String>,
8388    /// Snowflake: TAG (name='value', ...)
8389    #[serde(default)]
8390    pub tags: Vec<(String, String)>,
8391    /// BigQuery: OPTIONS (key=value, ...)
8392    #[serde(default)]
8393    pub options: Vec<Expression>,
8394    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8395    #[serde(skip_serializing_if = "Option::is_none", default)]
8396    pub build: Option<String>,
8397    /// Doris: REFRESH property for materialized views
8398    #[serde(skip_serializing_if = "Option::is_none", default)]
8399    pub refresh: Option<Box<RefreshTriggerProperty>>,
8400    /// Doris: Schema with typed column definitions for materialized views
8401    /// This is used instead of `columns` when the view has typed column definitions
8402    #[serde(skip_serializing_if = "Option::is_none", default)]
8403    pub schema: Option<Box<Schema>>,
8404    /// Doris: KEY (columns) for materialized views
8405    #[serde(skip_serializing_if = "Option::is_none", default)]
8406    pub unique_key: Option<Box<UniqueKeyProperty>>,
8407    /// Redshift: WITH NO SCHEMA BINDING
8408    #[serde(default)]
8409    pub no_schema_binding: bool,
8410    /// Redshift: AUTO REFRESH YES|NO for materialized views
8411    #[serde(skip_serializing_if = "Option::is_none", default)]
8412    pub auto_refresh: Option<bool>,
8413    /// ClickHouse: ON CLUSTER clause
8414    #[serde(default, skip_serializing_if = "Option::is_none")]
8415    pub on_cluster: Option<OnCluster>,
8416    /// ClickHouse: TO destination_table
8417    #[serde(default, skip_serializing_if = "Option::is_none")]
8418    pub to_table: Option<TableRef>,
8419    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8420    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8421    pub table_properties: Vec<Expression>,
8422}
8423
8424impl CreateView {
8425    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8426        Self {
8427            name: TableRef::new(name),
8428            columns: Vec::new(),
8429            query,
8430            or_replace: false,
8431            or_alter: false,
8432            if_not_exists: false,
8433            materialized: false,
8434            temporary: false,
8435            secure: false,
8436            algorithm: None,
8437            definer: None,
8438            security: None,
8439            security_sql_style: true,
8440            security_after_name: false,
8441            query_parenthesized: false,
8442            locking_mode: None,
8443            locking_access: None,
8444            copy_grants: false,
8445            comment: None,
8446            tags: Vec::new(),
8447            options: Vec::new(),
8448            build: None,
8449            refresh: None,
8450            schema: None,
8451            unique_key: None,
8452            no_schema_binding: false,
8453            auto_refresh: None,
8454            on_cluster: None,
8455            to_table: None,
8456            table_properties: Vec::new(),
8457        }
8458    }
8459}
8460
8461/// DROP VIEW statement
8462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8463#[cfg_attr(feature = "bindings", derive(TS))]
8464pub struct DropView {
8465    pub name: TableRef,
8466    pub if_exists: bool,
8467    pub materialized: bool,
8468}
8469
8470impl DropView {
8471    pub fn new(name: impl Into<String>) -> Self {
8472        Self {
8473            name: TableRef::new(name),
8474            if_exists: false,
8475            materialized: false,
8476        }
8477    }
8478}
8479
8480/// TRUNCATE TABLE statement
8481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8482#[cfg_attr(feature = "bindings", derive(TS))]
8483pub struct Truncate {
8484    /// Target of TRUNCATE (TABLE vs DATABASE)
8485    #[serde(default)]
8486    pub target: TruncateTarget,
8487    /// IF EXISTS clause
8488    #[serde(default)]
8489    pub if_exists: bool,
8490    pub table: TableRef,
8491    /// ClickHouse: ON CLUSTER clause for distributed DDL
8492    #[serde(default, skip_serializing_if = "Option::is_none")]
8493    pub on_cluster: Option<OnCluster>,
8494    pub cascade: bool,
8495    /// Additional tables for multi-table TRUNCATE
8496    #[serde(default)]
8497    pub extra_tables: Vec<TruncateTableEntry>,
8498    /// RESTART IDENTITY or CONTINUE IDENTITY
8499    #[serde(default)]
8500    pub identity: Option<TruncateIdentity>,
8501    /// RESTRICT option (alternative to CASCADE)
8502    #[serde(default)]
8503    pub restrict: bool,
8504    /// Hive PARTITION clause: PARTITION(key=value, ...)
8505    #[serde(default, skip_serializing_if = "Option::is_none")]
8506    pub partition: Option<Box<Expression>>,
8507}
8508
8509/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8511#[cfg_attr(feature = "bindings", derive(TS))]
8512pub struct TruncateTableEntry {
8513    pub table: TableRef,
8514    /// Whether the table has a * suffix (inherit children)
8515    #[serde(default)]
8516    pub star: bool,
8517}
8518
8519/// TRUNCATE target type
8520#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8521#[cfg_attr(feature = "bindings", derive(TS))]
8522pub enum TruncateTarget {
8523    Table,
8524    Database,
8525}
8526
8527impl Default for TruncateTarget {
8528    fn default() -> Self {
8529        TruncateTarget::Table
8530    }
8531}
8532
8533/// TRUNCATE identity option
8534#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8535#[cfg_attr(feature = "bindings", derive(TS))]
8536pub enum TruncateIdentity {
8537    Restart,
8538    Continue,
8539}
8540
8541impl Truncate {
8542    pub fn new(table: impl Into<String>) -> Self {
8543        Self {
8544            target: TruncateTarget::Table,
8545            if_exists: false,
8546            table: TableRef::new(table),
8547            on_cluster: None,
8548            cascade: false,
8549            extra_tables: Vec::new(),
8550            identity: None,
8551            restrict: false,
8552            partition: None,
8553        }
8554    }
8555}
8556
8557/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8559#[cfg_attr(feature = "bindings", derive(TS))]
8560pub struct Use {
8561    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8562    pub kind: Option<UseKind>,
8563    /// The name of the object
8564    pub this: Identifier,
8565}
8566
8567/// Kind of USE statement
8568#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8569#[cfg_attr(feature = "bindings", derive(TS))]
8570pub enum UseKind {
8571    Database,
8572    Schema,
8573    Role,
8574    Warehouse,
8575    Catalog,
8576    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8577    SecondaryRoles,
8578}
8579
8580/// SET variable statement
8581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8582#[cfg_attr(feature = "bindings", derive(TS))]
8583pub struct SetStatement {
8584    /// The items being set
8585    pub items: Vec<SetItem>,
8586}
8587
8588/// A single SET item (variable assignment)
8589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8590#[cfg_attr(feature = "bindings", derive(TS))]
8591pub struct SetItem {
8592    /// The variable name
8593    pub name: Expression,
8594    /// The value to set
8595    pub value: Expression,
8596    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8597    pub kind: Option<String>,
8598    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8599    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8600    pub no_equals: bool,
8601}
8602
8603/// CACHE TABLE statement (Spark)
8604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8605#[cfg_attr(feature = "bindings", derive(TS))]
8606pub struct Cache {
8607    /// The table to cache
8608    pub table: Identifier,
8609    /// LAZY keyword - defer caching until first use
8610    pub lazy: bool,
8611    /// Optional OPTIONS clause (key-value pairs)
8612    pub options: Vec<(Expression, Expression)>,
8613    /// Optional AS clause with query
8614    pub query: Option<Expression>,
8615}
8616
8617/// UNCACHE TABLE statement (Spark)
8618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8619#[cfg_attr(feature = "bindings", derive(TS))]
8620pub struct Uncache {
8621    /// The table to uncache
8622    pub table: Identifier,
8623    /// IF EXISTS clause
8624    pub if_exists: bool,
8625}
8626
8627/// LOAD DATA statement (Hive)
8628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8629#[cfg_attr(feature = "bindings", derive(TS))]
8630pub struct LoadData {
8631    /// LOCAL keyword - load from local filesystem
8632    pub local: bool,
8633    /// The path to load data from (INPATH value)
8634    pub inpath: String,
8635    /// Whether to overwrite existing data
8636    pub overwrite: bool,
8637    /// The target table
8638    pub table: Expression,
8639    /// Optional PARTITION clause with key-value pairs
8640    pub partition: Vec<(Identifier, Expression)>,
8641    /// Optional INPUTFORMAT clause
8642    pub input_format: Option<String>,
8643    /// Optional SERDE clause
8644    pub serde: Option<String>,
8645}
8646
8647/// PRAGMA statement (SQLite)
8648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8649#[cfg_attr(feature = "bindings", derive(TS))]
8650pub struct Pragma {
8651    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8652    pub schema: Option<Identifier>,
8653    /// The pragma name
8654    pub name: Identifier,
8655    /// Optional value for assignment (PRAGMA name = value)
8656    pub value: Option<Expression>,
8657    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8658    pub args: Vec<Expression>,
8659}
8660
8661/// A privilege with optional column list for GRANT/REVOKE
8662/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8664#[cfg_attr(feature = "bindings", derive(TS))]
8665pub struct Privilege {
8666    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8667    pub name: String,
8668    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8669    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8670    pub columns: Vec<String>,
8671}
8672
8673/// Principal in GRANT/REVOKE (user, role, etc.)
8674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8675#[cfg_attr(feature = "bindings", derive(TS))]
8676pub struct GrantPrincipal {
8677    /// The name of the principal
8678    pub name: Identifier,
8679    /// Whether prefixed with ROLE keyword
8680    pub is_role: bool,
8681    /// Whether prefixed with GROUP keyword (Redshift)
8682    #[serde(default)]
8683    pub is_group: bool,
8684    /// Whether prefixed with SHARE keyword (Snowflake)
8685    #[serde(default)]
8686    pub is_share: bool,
8687}
8688
8689/// GRANT statement
8690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8691#[cfg_attr(feature = "bindings", derive(TS))]
8692pub struct Grant {
8693    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8694    pub privileges: Vec<Privilege>,
8695    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8696    pub kind: Option<String>,
8697    /// The object to grant on
8698    pub securable: Identifier,
8699    /// Function parameter types (for FUNCTION kind)
8700    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8701    pub function_params: Vec<String>,
8702    /// The grantees
8703    pub principals: Vec<GrantPrincipal>,
8704    /// WITH GRANT OPTION
8705    pub grant_option: bool,
8706    /// TSQL: AS principal (the grantor role)
8707    #[serde(default, skip_serializing_if = "Option::is_none")]
8708    pub as_principal: Option<Identifier>,
8709}
8710
8711/// REVOKE statement
8712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8713#[cfg_attr(feature = "bindings", derive(TS))]
8714pub struct Revoke {
8715    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8716    pub privileges: Vec<Privilege>,
8717    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8718    pub kind: Option<String>,
8719    /// The object to revoke from
8720    pub securable: Identifier,
8721    /// Function parameter types (for FUNCTION kind)
8722    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8723    pub function_params: Vec<String>,
8724    /// The grantees
8725    pub principals: Vec<GrantPrincipal>,
8726    /// GRANT OPTION FOR
8727    pub grant_option: bool,
8728    /// CASCADE
8729    pub cascade: bool,
8730    /// RESTRICT
8731    #[serde(default)]
8732    pub restrict: bool,
8733}
8734
8735/// COMMENT ON statement
8736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8737#[cfg_attr(feature = "bindings", derive(TS))]
8738pub struct Comment {
8739    /// The object being commented on
8740    pub this: Expression,
8741    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8742    pub kind: String,
8743    /// The comment text expression
8744    pub expression: Expression,
8745    /// IF EXISTS clause
8746    pub exists: bool,
8747    /// MATERIALIZED keyword
8748    pub materialized: bool,
8749}
8750
8751// ============================================================================
8752// Phase 4: Additional DDL Statements
8753// ============================================================================
8754
8755/// ALTER VIEW statement
8756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8757#[cfg_attr(feature = "bindings", derive(TS))]
8758pub struct AlterView {
8759    pub name: TableRef,
8760    pub actions: Vec<AlterViewAction>,
8761    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8762    #[serde(default, skip_serializing_if = "Option::is_none")]
8763    pub algorithm: Option<String>,
8764    /// MySQL: DEFINER = 'user'@'host'
8765    #[serde(default, skip_serializing_if = "Option::is_none")]
8766    pub definer: Option<String>,
8767    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8768    #[serde(default, skip_serializing_if = "Option::is_none")]
8769    pub sql_security: Option<String>,
8770    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8771    #[serde(default, skip_serializing_if = "Option::is_none")]
8772    pub with_option: Option<String>,
8773    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8774    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8775    pub columns: Vec<ViewColumn>,
8776}
8777
8778/// Actions for ALTER VIEW
8779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8780#[cfg_attr(feature = "bindings", derive(TS))]
8781pub enum AlterViewAction {
8782    /// Rename the view
8783    Rename(TableRef),
8784    /// Change owner
8785    OwnerTo(Identifier),
8786    /// Set schema
8787    SetSchema(Identifier),
8788    /// Set authorization (Trino/Presto)
8789    SetAuthorization(String),
8790    /// Alter column
8791    AlterColumn {
8792        name: Identifier,
8793        action: AlterColumnAction,
8794    },
8795    /// Redefine view as query (SELECT, UNION, etc.)
8796    AsSelect(Box<Expression>),
8797    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8798    SetTblproperties(Vec<(String, String)>),
8799    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8800    UnsetTblproperties(Vec<String>),
8801}
8802
8803impl AlterView {
8804    pub fn new(name: impl Into<String>) -> Self {
8805        Self {
8806            name: TableRef::new(name),
8807            actions: Vec::new(),
8808            algorithm: None,
8809            definer: None,
8810            sql_security: None,
8811            with_option: None,
8812            columns: Vec::new(),
8813        }
8814    }
8815}
8816
8817/// ALTER INDEX statement
8818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8819#[cfg_attr(feature = "bindings", derive(TS))]
8820pub struct AlterIndex {
8821    pub name: Identifier,
8822    pub table: Option<TableRef>,
8823    pub actions: Vec<AlterIndexAction>,
8824}
8825
8826/// Actions for ALTER INDEX
8827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8828#[cfg_attr(feature = "bindings", derive(TS))]
8829pub enum AlterIndexAction {
8830    /// Rename the index
8831    Rename(Identifier),
8832    /// Set tablespace
8833    SetTablespace(Identifier),
8834    /// Set visibility (MySQL)
8835    Visible(bool),
8836}
8837
8838impl AlterIndex {
8839    pub fn new(name: impl Into<String>) -> Self {
8840        Self {
8841            name: Identifier::new(name),
8842            table: None,
8843            actions: Vec::new(),
8844        }
8845    }
8846}
8847
8848/// CREATE SCHEMA statement
8849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8850#[cfg_attr(feature = "bindings", derive(TS))]
8851pub struct CreateSchema {
8852    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8853    pub name: Vec<Identifier>,
8854    pub if_not_exists: bool,
8855    pub authorization: Option<Identifier>,
8856    /// CLONE source parts, possibly dot-qualified
8857    #[serde(default)]
8858    pub clone_from: Option<Vec<Identifier>>,
8859    /// AT/BEFORE clause for time travel (Snowflake)
8860    #[serde(default)]
8861    pub at_clause: Option<Expression>,
8862    /// Schema properties like DEFAULT COLLATE
8863    #[serde(default)]
8864    pub properties: Vec<Expression>,
8865    /// Leading comments before the statement
8866    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8867    pub leading_comments: Vec<String>,
8868}
8869
8870impl CreateSchema {
8871    pub fn new(name: impl Into<String>) -> Self {
8872        Self {
8873            name: vec![Identifier::new(name)],
8874            if_not_exists: false,
8875            authorization: None,
8876            clone_from: None,
8877            at_clause: None,
8878            properties: Vec::new(),
8879            leading_comments: Vec::new(),
8880        }
8881    }
8882}
8883
8884/// DROP SCHEMA statement
8885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8886#[cfg_attr(feature = "bindings", derive(TS))]
8887pub struct DropSchema {
8888    pub name: Identifier,
8889    pub if_exists: bool,
8890    pub cascade: bool,
8891}
8892
8893impl DropSchema {
8894    pub fn new(name: impl Into<String>) -> Self {
8895        Self {
8896            name: Identifier::new(name),
8897            if_exists: false,
8898            cascade: false,
8899        }
8900    }
8901}
8902
8903/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8905#[cfg_attr(feature = "bindings", derive(TS))]
8906pub struct DropNamespace {
8907    pub name: Identifier,
8908    pub if_exists: bool,
8909    pub cascade: bool,
8910}
8911
8912impl DropNamespace {
8913    pub fn new(name: impl Into<String>) -> Self {
8914        Self {
8915            name: Identifier::new(name),
8916            if_exists: false,
8917            cascade: false,
8918        }
8919    }
8920}
8921
8922/// CREATE DATABASE statement
8923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8924#[cfg_attr(feature = "bindings", derive(TS))]
8925pub struct CreateDatabase {
8926    pub name: Identifier,
8927    pub if_not_exists: bool,
8928    pub options: Vec<DatabaseOption>,
8929    /// Snowflake CLONE source
8930    #[serde(default)]
8931    pub clone_from: Option<Identifier>,
8932    /// AT/BEFORE clause for time travel (Snowflake)
8933    #[serde(default)]
8934    pub at_clause: Option<Expression>,
8935}
8936
8937/// Database option
8938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8939#[cfg_attr(feature = "bindings", derive(TS))]
8940pub enum DatabaseOption {
8941    CharacterSet(String),
8942    Collate(String),
8943    Owner(Identifier),
8944    Template(Identifier),
8945    Encoding(String),
8946    Location(String),
8947}
8948
8949impl CreateDatabase {
8950    pub fn new(name: impl Into<String>) -> Self {
8951        Self {
8952            name: Identifier::new(name),
8953            if_not_exists: false,
8954            options: Vec::new(),
8955            clone_from: None,
8956            at_clause: None,
8957        }
8958    }
8959}
8960
8961/// DROP DATABASE statement
8962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8963#[cfg_attr(feature = "bindings", derive(TS))]
8964pub struct DropDatabase {
8965    pub name: Identifier,
8966    pub if_exists: bool,
8967    /// ClickHouse: SYNC modifier
8968    #[serde(default)]
8969    pub sync: bool,
8970}
8971
8972impl DropDatabase {
8973    pub fn new(name: impl Into<String>) -> Self {
8974        Self {
8975            name: Identifier::new(name),
8976            if_exists: false,
8977            sync: false,
8978        }
8979    }
8980}
8981
8982/// CREATE FUNCTION statement
8983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8984#[cfg_attr(feature = "bindings", derive(TS))]
8985pub struct CreateFunction {
8986    pub name: TableRef,
8987    pub parameters: Vec<FunctionParameter>,
8988    pub return_type: Option<DataType>,
8989    pub body: Option<FunctionBody>,
8990    pub or_replace: bool,
8991    /// TSQL: CREATE OR ALTER
8992    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8993    pub or_alter: bool,
8994    pub if_not_exists: bool,
8995    pub temporary: bool,
8996    pub language: Option<String>,
8997    pub deterministic: Option<bool>,
8998    pub returns_null_on_null_input: Option<bool>,
8999    pub security: Option<FunctionSecurity>,
9000    /// Whether parentheses were present in the original syntax
9001    #[serde(default = "default_true")]
9002    pub has_parens: bool,
9003    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9004    #[serde(default)]
9005    pub sql_data_access: Option<SqlDataAccess>,
9006    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9007    #[serde(default, skip_serializing_if = "Option::is_none")]
9008    pub returns_table_body: Option<String>,
9009    /// True if LANGUAGE clause appears before RETURNS clause
9010    #[serde(default)]
9011    pub language_first: bool,
9012    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9013    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9014    pub set_options: Vec<FunctionSetOption>,
9015    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9016    #[serde(default)]
9017    pub strict: bool,
9018    /// BigQuery: OPTIONS (key=value, ...)
9019    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9020    pub options: Vec<Expression>,
9021    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9022    #[serde(default)]
9023    pub is_table_function: bool,
9024    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9025    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9026    pub property_order: Vec<FunctionPropertyKind>,
9027    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9028    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9029    pub environment: Vec<Expression>,
9030    /// HANDLER 'handler_function' clause (Databricks)
9031    #[serde(default, skip_serializing_if = "Option::is_none")]
9032    pub handler: Option<String>,
9033    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9034    #[serde(default, skip_serializing_if = "Option::is_none")]
9035    pub parameter_style: Option<String>,
9036}
9037
9038/// A SET option in CREATE FUNCTION (PostgreSQL)
9039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9040#[cfg_attr(feature = "bindings", derive(TS))]
9041pub struct FunctionSetOption {
9042    pub name: String,
9043    pub value: FunctionSetValue,
9044}
9045
9046/// The value of a SET option
9047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9048#[cfg_attr(feature = "bindings", derive(TS))]
9049pub enum FunctionSetValue {
9050    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9051    Value { value: String, use_to: bool },
9052    /// SET key FROM CURRENT
9053    FromCurrent,
9054}
9055
9056/// SQL data access characteristics for functions
9057#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9058#[cfg_attr(feature = "bindings", derive(TS))]
9059pub enum SqlDataAccess {
9060    /// NO SQL
9061    NoSql,
9062    /// CONTAINS SQL
9063    ContainsSql,
9064    /// READS SQL DATA
9065    ReadsSqlData,
9066    /// MODIFIES SQL DATA
9067    ModifiesSqlData,
9068}
9069
9070/// Types of properties in CREATE FUNCTION for tracking their original order
9071#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9072#[cfg_attr(feature = "bindings", derive(TS))]
9073pub enum FunctionPropertyKind {
9074    /// SET option
9075    Set,
9076    /// AS body
9077    As,
9078    /// LANGUAGE clause
9079    Language,
9080    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9081    Determinism,
9082    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9083    NullInput,
9084    /// SECURITY DEFINER/INVOKER
9085    Security,
9086    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9087    SqlDataAccess,
9088    /// OPTIONS clause (BigQuery)
9089    Options,
9090    /// ENVIRONMENT clause (Databricks)
9091    Environment,
9092    /// HANDLER clause (Databricks)
9093    Handler,
9094    /// PARAMETER STYLE clause (Databricks)
9095    ParameterStyle,
9096}
9097
9098/// Function parameter
9099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9100#[cfg_attr(feature = "bindings", derive(TS))]
9101pub struct FunctionParameter {
9102    pub name: Option<Identifier>,
9103    pub data_type: DataType,
9104    pub mode: Option<ParameterMode>,
9105    pub default: Option<Expression>,
9106    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9107    #[serde(default, skip_serializing_if = "Option::is_none")]
9108    pub mode_text: Option<String>,
9109}
9110
9111/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9112#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9113#[cfg_attr(feature = "bindings", derive(TS))]
9114pub enum ParameterMode {
9115    In,
9116    Out,
9117    InOut,
9118    Variadic,
9119}
9120
9121/// Function body
9122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9123#[cfg_attr(feature = "bindings", derive(TS))]
9124pub enum FunctionBody {
9125    /// AS $$ ... $$ (dollar-quoted)
9126    Block(String),
9127    /// AS 'string' (single-quoted string literal body)
9128    StringLiteral(String),
9129    /// AS 'expression'
9130    Expression(Expression),
9131    /// EXTERNAL NAME 'library'
9132    External(String),
9133    /// RETURN expression
9134    Return(Expression),
9135    /// BEGIN ... END block with parsed statements
9136    Statements(Vec<Expression>),
9137    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9138    /// Stores (content, optional_tag)
9139    DollarQuoted {
9140        content: String,
9141        tag: Option<String>,
9142    },
9143    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9144    RawBlock(String),
9145}
9146
9147/// Function security (DEFINER, INVOKER, or NONE)
9148#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9149#[cfg_attr(feature = "bindings", derive(TS))]
9150pub enum FunctionSecurity {
9151    Definer,
9152    Invoker,
9153    /// StarRocks/MySQL: SECURITY NONE
9154    None,
9155}
9156
9157impl CreateFunction {
9158    pub fn new(name: impl Into<String>) -> Self {
9159        Self {
9160            name: TableRef::new(name),
9161            parameters: Vec::new(),
9162            return_type: None,
9163            body: None,
9164            or_replace: false,
9165            or_alter: false,
9166            if_not_exists: false,
9167            temporary: false,
9168            language: None,
9169            deterministic: None,
9170            returns_null_on_null_input: None,
9171            security: None,
9172            has_parens: true,
9173            sql_data_access: None,
9174            returns_table_body: None,
9175            language_first: false,
9176            set_options: Vec::new(),
9177            strict: false,
9178            options: Vec::new(),
9179            is_table_function: false,
9180            property_order: Vec::new(),
9181            environment: Vec::new(),
9182            handler: None,
9183            parameter_style: None,
9184        }
9185    }
9186}
9187
9188/// DROP FUNCTION statement
9189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9190#[cfg_attr(feature = "bindings", derive(TS))]
9191pub struct DropFunction {
9192    pub name: TableRef,
9193    pub parameters: Option<Vec<DataType>>,
9194    pub if_exists: bool,
9195    pub cascade: bool,
9196}
9197
9198impl DropFunction {
9199    pub fn new(name: impl Into<String>) -> Self {
9200        Self {
9201            name: TableRef::new(name),
9202            parameters: None,
9203            if_exists: false,
9204            cascade: false,
9205        }
9206    }
9207}
9208
9209/// CREATE PROCEDURE statement
9210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9211#[cfg_attr(feature = "bindings", derive(TS))]
9212pub struct CreateProcedure {
9213    pub name: TableRef,
9214    pub parameters: Vec<FunctionParameter>,
9215    pub body: Option<FunctionBody>,
9216    pub or_replace: bool,
9217    /// TSQL: CREATE OR ALTER
9218    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9219    pub or_alter: bool,
9220    pub if_not_exists: bool,
9221    pub language: Option<String>,
9222    pub security: Option<FunctionSecurity>,
9223    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9224    #[serde(default)]
9225    pub return_type: Option<DataType>,
9226    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9227    #[serde(default)]
9228    pub execute_as: Option<String>,
9229    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9230    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9231    pub with_options: Vec<String>,
9232    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9233    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9234    pub has_parens: bool,
9235    /// Whether the short form PROC was used (instead of PROCEDURE)
9236    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9237    pub use_proc_keyword: bool,
9238}
9239
9240impl CreateProcedure {
9241    pub fn new(name: impl Into<String>) -> Self {
9242        Self {
9243            name: TableRef::new(name),
9244            parameters: Vec::new(),
9245            body: None,
9246            or_replace: false,
9247            or_alter: false,
9248            if_not_exists: false,
9249            language: None,
9250            security: None,
9251            return_type: None,
9252            execute_as: None,
9253            with_options: Vec::new(),
9254            has_parens: true,
9255            use_proc_keyword: false,
9256        }
9257    }
9258}
9259
9260/// DROP PROCEDURE statement
9261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9262#[cfg_attr(feature = "bindings", derive(TS))]
9263pub struct DropProcedure {
9264    pub name: TableRef,
9265    pub parameters: Option<Vec<DataType>>,
9266    pub if_exists: bool,
9267    pub cascade: bool,
9268}
9269
9270impl DropProcedure {
9271    pub fn new(name: impl Into<String>) -> Self {
9272        Self {
9273            name: TableRef::new(name),
9274            parameters: None,
9275            if_exists: false,
9276            cascade: false,
9277        }
9278    }
9279}
9280
9281/// Sequence property tag for ordering
9282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9283#[cfg_attr(feature = "bindings", derive(TS))]
9284pub enum SeqPropKind {
9285    Start,
9286    Increment,
9287    Minvalue,
9288    Maxvalue,
9289    Cache,
9290    NoCache,
9291    Cycle,
9292    NoCycle,
9293    OwnedBy,
9294    Order,
9295    NoOrder,
9296    Comment,
9297    /// SHARING=<value> (Oracle)
9298    Sharing,
9299    /// KEEP (Oracle)
9300    Keep,
9301    /// NOKEEP (Oracle)
9302    NoKeep,
9303    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9304    Scale,
9305    /// NOSCALE (Oracle)
9306    NoScale,
9307    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9308    Shard,
9309    /// NOSHARD (Oracle)
9310    NoShard,
9311    /// SESSION (Oracle)
9312    Session,
9313    /// GLOBAL (Oracle)
9314    Global,
9315    /// NOCACHE (single word, Oracle)
9316    NoCacheWord,
9317    /// NOCYCLE (single word, Oracle)
9318    NoCycleWord,
9319    /// NOMINVALUE (single word, Oracle)
9320    NoMinvalueWord,
9321    /// NOMAXVALUE (single word, Oracle)
9322    NoMaxvalueWord,
9323}
9324
9325/// CREATE SYNONYM statement (TSQL)
9326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9327#[cfg_attr(feature = "bindings", derive(TS))]
9328pub struct CreateSynonym {
9329    /// The synonym name (can be qualified: schema.synonym_name)
9330    pub name: TableRef,
9331    /// The target object the synonym refers to
9332    pub target: TableRef,
9333}
9334
9335/// CREATE SEQUENCE statement
9336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9337#[cfg_attr(feature = "bindings", derive(TS))]
9338pub struct CreateSequence {
9339    pub name: TableRef,
9340    pub if_not_exists: bool,
9341    pub temporary: bool,
9342    #[serde(default)]
9343    pub or_replace: bool,
9344    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9345    #[serde(default, skip_serializing_if = "Option::is_none")]
9346    pub as_type: Option<DataType>,
9347    pub increment: Option<i64>,
9348    pub minvalue: Option<SequenceBound>,
9349    pub maxvalue: Option<SequenceBound>,
9350    pub start: Option<i64>,
9351    pub cache: Option<i64>,
9352    pub cycle: bool,
9353    pub owned_by: Option<TableRef>,
9354    /// Whether OWNED BY NONE was specified
9355    #[serde(default)]
9356    pub owned_by_none: bool,
9357    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9358    #[serde(default)]
9359    pub order: Option<bool>,
9360    /// Snowflake: COMMENT = 'value'
9361    #[serde(default)]
9362    pub comment: Option<String>,
9363    /// SHARING=<value> (Oracle)
9364    #[serde(default, skip_serializing_if = "Option::is_none")]
9365    pub sharing: Option<String>,
9366    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9367    #[serde(default, skip_serializing_if = "Option::is_none")]
9368    pub scale_modifier: Option<String>,
9369    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9370    #[serde(default, skip_serializing_if = "Option::is_none")]
9371    pub shard_modifier: Option<String>,
9372    /// Tracks the order in which properties appeared in the source
9373    #[serde(default)]
9374    pub property_order: Vec<SeqPropKind>,
9375}
9376
9377/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9379#[cfg_attr(feature = "bindings", derive(TS))]
9380pub enum SequenceBound {
9381    Value(i64),
9382    None,
9383}
9384
9385impl CreateSequence {
9386    pub fn new(name: impl Into<String>) -> Self {
9387        Self {
9388            name: TableRef::new(name),
9389            if_not_exists: false,
9390            temporary: false,
9391            or_replace: false,
9392            as_type: None,
9393            increment: None,
9394            minvalue: None,
9395            maxvalue: None,
9396            start: None,
9397            cache: None,
9398            cycle: false,
9399            owned_by: None,
9400            owned_by_none: false,
9401            order: None,
9402            comment: None,
9403            sharing: None,
9404            scale_modifier: None,
9405            shard_modifier: None,
9406            property_order: Vec::new(),
9407        }
9408    }
9409}
9410
9411/// DROP SEQUENCE statement
9412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9413#[cfg_attr(feature = "bindings", derive(TS))]
9414pub struct DropSequence {
9415    pub name: TableRef,
9416    pub if_exists: bool,
9417    pub cascade: bool,
9418}
9419
9420impl DropSequence {
9421    pub fn new(name: impl Into<String>) -> Self {
9422        Self {
9423            name: TableRef::new(name),
9424            if_exists: false,
9425            cascade: false,
9426        }
9427    }
9428}
9429
9430/// ALTER SEQUENCE statement
9431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9432#[cfg_attr(feature = "bindings", derive(TS))]
9433pub struct AlterSequence {
9434    pub name: TableRef,
9435    pub if_exists: bool,
9436    pub increment: Option<i64>,
9437    pub minvalue: Option<SequenceBound>,
9438    pub maxvalue: Option<SequenceBound>,
9439    pub start: Option<i64>,
9440    pub restart: Option<Option<i64>>,
9441    pub cache: Option<i64>,
9442    pub cycle: Option<bool>,
9443    pub owned_by: Option<Option<TableRef>>,
9444}
9445
9446impl AlterSequence {
9447    pub fn new(name: impl Into<String>) -> Self {
9448        Self {
9449            name: TableRef::new(name),
9450            if_exists: false,
9451            increment: None,
9452            minvalue: None,
9453            maxvalue: None,
9454            start: None,
9455            restart: None,
9456            cache: None,
9457            cycle: None,
9458            owned_by: None,
9459        }
9460    }
9461}
9462
9463/// CREATE TRIGGER statement
9464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9465#[cfg_attr(feature = "bindings", derive(TS))]
9466pub struct CreateTrigger {
9467    pub name: Identifier,
9468    pub table: TableRef,
9469    pub timing: TriggerTiming,
9470    pub events: Vec<TriggerEvent>,
9471    #[serde(default, skip_serializing_if = "Option::is_none")]
9472    pub for_each: Option<TriggerForEach>,
9473    pub when: Option<Expression>,
9474    /// Whether the WHEN clause was parenthesized in the original SQL
9475    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9476    pub when_paren: bool,
9477    pub body: TriggerBody,
9478    pub or_replace: bool,
9479    /// TSQL: CREATE OR ALTER
9480    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9481    pub or_alter: bool,
9482    pub constraint: bool,
9483    pub deferrable: Option<bool>,
9484    pub initially_deferred: Option<bool>,
9485    pub referencing: Option<TriggerReferencing>,
9486}
9487
9488/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9489#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9490#[cfg_attr(feature = "bindings", derive(TS))]
9491pub enum TriggerTiming {
9492    Before,
9493    After,
9494    InsteadOf,
9495}
9496
9497/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9499#[cfg_attr(feature = "bindings", derive(TS))]
9500pub enum TriggerEvent {
9501    Insert,
9502    Update(Option<Vec<Identifier>>),
9503    Delete,
9504    Truncate,
9505}
9506
9507/// Trigger FOR EACH clause
9508#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9509#[cfg_attr(feature = "bindings", derive(TS))]
9510pub enum TriggerForEach {
9511    Row,
9512    Statement,
9513}
9514
9515/// Trigger body
9516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9517#[cfg_attr(feature = "bindings", derive(TS))]
9518pub enum TriggerBody {
9519    /// EXECUTE FUNCTION/PROCEDURE name(args)
9520    Execute {
9521        function: TableRef,
9522        args: Vec<Expression>,
9523    },
9524    /// BEGIN ... END block
9525    Block(String),
9526}
9527
9528/// Trigger REFERENCING clause
9529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9530#[cfg_attr(feature = "bindings", derive(TS))]
9531pub struct TriggerReferencing {
9532    pub old_table: Option<Identifier>,
9533    pub new_table: Option<Identifier>,
9534    pub old_row: Option<Identifier>,
9535    pub new_row: Option<Identifier>,
9536}
9537
9538impl CreateTrigger {
9539    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9540        Self {
9541            name: Identifier::new(name),
9542            table: TableRef::new(table),
9543            timing: TriggerTiming::Before,
9544            events: Vec::new(),
9545            for_each: Some(TriggerForEach::Row),
9546            when: None,
9547            when_paren: false,
9548            body: TriggerBody::Execute {
9549                function: TableRef::new(""),
9550                args: Vec::new(),
9551            },
9552            or_replace: false,
9553            or_alter: false,
9554            constraint: false,
9555            deferrable: None,
9556            initially_deferred: None,
9557            referencing: None,
9558        }
9559    }
9560}
9561
9562/// DROP TRIGGER statement
9563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9564#[cfg_attr(feature = "bindings", derive(TS))]
9565pub struct DropTrigger {
9566    pub name: Identifier,
9567    pub table: Option<TableRef>,
9568    pub if_exists: bool,
9569    pub cascade: bool,
9570}
9571
9572impl DropTrigger {
9573    pub fn new(name: impl Into<String>) -> Self {
9574        Self {
9575            name: Identifier::new(name),
9576            table: None,
9577            if_exists: false,
9578            cascade: false,
9579        }
9580    }
9581}
9582
9583/// CREATE TYPE statement
9584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9585#[cfg_attr(feature = "bindings", derive(TS))]
9586pub struct CreateType {
9587    pub name: TableRef,
9588    pub definition: TypeDefinition,
9589    pub if_not_exists: bool,
9590}
9591
9592/// Type definition
9593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9594#[cfg_attr(feature = "bindings", derive(TS))]
9595pub enum TypeDefinition {
9596    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9597    Enum(Vec<String>),
9598    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9599    Composite(Vec<TypeAttribute>),
9600    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9601    Range {
9602        subtype: DataType,
9603        subtype_diff: Option<String>,
9604        canonical: Option<String>,
9605    },
9606    /// Base type (for advanced usage)
9607    Base {
9608        input: String,
9609        output: String,
9610        internallength: Option<i32>,
9611    },
9612    /// Domain type
9613    Domain {
9614        base_type: DataType,
9615        default: Option<Expression>,
9616        constraints: Vec<DomainConstraint>,
9617    },
9618}
9619
9620/// Type attribute for composite types
9621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9622#[cfg_attr(feature = "bindings", derive(TS))]
9623pub struct TypeAttribute {
9624    pub name: Identifier,
9625    pub data_type: DataType,
9626    pub collate: Option<Identifier>,
9627}
9628
9629/// Domain constraint
9630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9631#[cfg_attr(feature = "bindings", derive(TS))]
9632pub struct DomainConstraint {
9633    pub name: Option<Identifier>,
9634    pub check: Expression,
9635}
9636
9637impl CreateType {
9638    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9639        Self {
9640            name: TableRef::new(name),
9641            definition: TypeDefinition::Enum(values),
9642            if_not_exists: false,
9643        }
9644    }
9645
9646    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9647        Self {
9648            name: TableRef::new(name),
9649            definition: TypeDefinition::Composite(attributes),
9650            if_not_exists: false,
9651        }
9652    }
9653}
9654
9655/// DROP TYPE statement
9656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9657#[cfg_attr(feature = "bindings", derive(TS))]
9658pub struct DropType {
9659    pub name: TableRef,
9660    pub if_exists: bool,
9661    pub cascade: bool,
9662}
9663
9664impl DropType {
9665    pub fn new(name: impl Into<String>) -> Self {
9666        Self {
9667            name: TableRef::new(name),
9668            if_exists: false,
9669            cascade: false,
9670        }
9671    }
9672}
9673
9674/// DESCRIBE statement - shows table structure or query plan
9675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9676#[cfg_attr(feature = "bindings", derive(TS))]
9677pub struct Describe {
9678    /// The target to describe (table name or query)
9679    pub target: Expression,
9680    /// EXTENDED format
9681    pub extended: bool,
9682    /// FORMATTED format
9683    pub formatted: bool,
9684    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9685    #[serde(default)]
9686    pub kind: Option<String>,
9687    /// Properties like type=stage
9688    #[serde(default)]
9689    pub properties: Vec<(String, String)>,
9690    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9691    #[serde(default, skip_serializing_if = "Option::is_none")]
9692    pub style: Option<String>,
9693    /// Partition specification for DESCRIBE PARTITION
9694    #[serde(default)]
9695    pub partition: Option<Box<Expression>>,
9696    /// Leading comments before the statement
9697    #[serde(default)]
9698    pub leading_comments: Vec<String>,
9699    /// AS JSON suffix (Databricks)
9700    #[serde(default)]
9701    pub as_json: bool,
9702    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9703    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9704    pub params: Vec<String>,
9705}
9706
9707impl Describe {
9708    pub fn new(target: Expression) -> Self {
9709        Self {
9710            target,
9711            extended: false,
9712            formatted: false,
9713            kind: None,
9714            properties: Vec::new(),
9715            style: None,
9716            partition: None,
9717            leading_comments: Vec::new(),
9718            as_json: false,
9719            params: Vec::new(),
9720        }
9721    }
9722}
9723
9724/// SHOW statement - displays database objects
9725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9726#[cfg_attr(feature = "bindings", derive(TS))]
9727pub struct Show {
9728    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9729    pub this: String,
9730    /// Whether TERSE was specified
9731    #[serde(default)]
9732    pub terse: bool,
9733    /// Whether HISTORY was specified
9734    #[serde(default)]
9735    pub history: bool,
9736    /// LIKE pattern
9737    pub like: Option<Expression>,
9738    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9739    pub scope_kind: Option<String>,
9740    /// IN scope object
9741    pub scope: Option<Expression>,
9742    /// STARTS WITH pattern
9743    pub starts_with: Option<Expression>,
9744    /// LIMIT clause
9745    pub limit: Option<Box<Limit>>,
9746    /// FROM clause (for specific object)
9747    pub from: Option<Expression>,
9748    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9749    #[serde(default, skip_serializing_if = "Option::is_none")]
9750    pub where_clause: Option<Expression>,
9751    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9752    #[serde(default, skip_serializing_if = "Option::is_none")]
9753    pub for_target: Option<Expression>,
9754    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9755    #[serde(default, skip_serializing_if = "Option::is_none")]
9756    pub db: Option<Expression>,
9757    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9758    #[serde(default, skip_serializing_if = "Option::is_none")]
9759    pub target: Option<Expression>,
9760    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9761    #[serde(default, skip_serializing_if = "Option::is_none")]
9762    pub mutex: Option<bool>,
9763    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9764    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9765    pub privileges: Vec<String>,
9766}
9767
9768impl Show {
9769    pub fn new(this: impl Into<String>) -> Self {
9770        Self {
9771            this: this.into(),
9772            terse: false,
9773            history: false,
9774            like: None,
9775            scope_kind: None,
9776            scope: None,
9777            starts_with: None,
9778            limit: None,
9779            from: None,
9780            where_clause: None,
9781            for_target: None,
9782            db: None,
9783            target: None,
9784            mutex: None,
9785            privileges: Vec::new(),
9786        }
9787    }
9788}
9789
9790/// Represent an explicit parenthesized expression for grouping precedence.
9791///
9792/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9793/// correctly instead of being flattened to `a + b * c`.
9794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9795#[cfg_attr(feature = "bindings", derive(TS))]
9796pub struct Paren {
9797    /// The inner expression wrapped by parentheses.
9798    pub this: Expression,
9799    #[serde(default)]
9800    pub trailing_comments: Vec<String>,
9801}
9802
9803/// Expression annotated with trailing comments (for round-trip preservation)
9804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9805#[cfg_attr(feature = "bindings", derive(TS))]
9806pub struct Annotated {
9807    pub this: Expression,
9808    pub trailing_comments: Vec<String>,
9809}
9810
9811// === BATCH GENERATED STRUCT DEFINITIONS ===
9812// Generated from Python sqlglot expressions.py
9813
9814/// Refresh
9815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9816#[cfg_attr(feature = "bindings", derive(TS))]
9817pub struct Refresh {
9818    pub this: Box<Expression>,
9819    pub kind: String,
9820}
9821
9822/// LockingStatement
9823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9824#[cfg_attr(feature = "bindings", derive(TS))]
9825pub struct LockingStatement {
9826    pub this: Box<Expression>,
9827    pub expression: Box<Expression>,
9828}
9829
9830/// SequenceProperties
9831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9832#[cfg_attr(feature = "bindings", derive(TS))]
9833pub struct SequenceProperties {
9834    #[serde(default)]
9835    pub increment: Option<Box<Expression>>,
9836    #[serde(default)]
9837    pub minvalue: Option<Box<Expression>>,
9838    #[serde(default)]
9839    pub maxvalue: Option<Box<Expression>>,
9840    #[serde(default)]
9841    pub cache: Option<Box<Expression>>,
9842    #[serde(default)]
9843    pub start: Option<Box<Expression>>,
9844    #[serde(default)]
9845    pub owned: Option<Box<Expression>>,
9846    #[serde(default)]
9847    pub options: Vec<Expression>,
9848}
9849
9850/// TruncateTable
9851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9852#[cfg_attr(feature = "bindings", derive(TS))]
9853pub struct TruncateTable {
9854    #[serde(default)]
9855    pub expressions: Vec<Expression>,
9856    #[serde(default)]
9857    pub is_database: Option<Box<Expression>>,
9858    #[serde(default)]
9859    pub exists: bool,
9860    #[serde(default)]
9861    pub only: Option<Box<Expression>>,
9862    #[serde(default)]
9863    pub cluster: Option<Box<Expression>>,
9864    #[serde(default)]
9865    pub identity: Option<Box<Expression>>,
9866    #[serde(default)]
9867    pub option: Option<Box<Expression>>,
9868    #[serde(default)]
9869    pub partition: Option<Box<Expression>>,
9870}
9871
9872/// Clone
9873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9874#[cfg_attr(feature = "bindings", derive(TS))]
9875pub struct Clone {
9876    pub this: Box<Expression>,
9877    #[serde(default)]
9878    pub shallow: Option<Box<Expression>>,
9879    #[serde(default)]
9880    pub copy: Option<Box<Expression>>,
9881}
9882
9883/// Attach
9884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9885#[cfg_attr(feature = "bindings", derive(TS))]
9886pub struct Attach {
9887    pub this: Box<Expression>,
9888    #[serde(default)]
9889    pub exists: bool,
9890    #[serde(default)]
9891    pub expressions: Vec<Expression>,
9892}
9893
9894/// Detach
9895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9896#[cfg_attr(feature = "bindings", derive(TS))]
9897pub struct Detach {
9898    pub this: Box<Expression>,
9899    #[serde(default)]
9900    pub exists: bool,
9901}
9902
9903/// Install
9904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9905#[cfg_attr(feature = "bindings", derive(TS))]
9906pub struct Install {
9907    pub this: Box<Expression>,
9908    #[serde(default)]
9909    pub from_: Option<Box<Expression>>,
9910    #[serde(default)]
9911    pub force: Option<Box<Expression>>,
9912}
9913
9914/// Summarize
9915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9916#[cfg_attr(feature = "bindings", derive(TS))]
9917pub struct Summarize {
9918    pub this: Box<Expression>,
9919    #[serde(default)]
9920    pub table: Option<Box<Expression>>,
9921}
9922
9923/// Declare
9924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9925#[cfg_attr(feature = "bindings", derive(TS))]
9926pub struct Declare {
9927    #[serde(default)]
9928    pub expressions: Vec<Expression>,
9929    #[serde(default)]
9930    pub replace: bool,
9931}
9932
9933/// DeclareItem
9934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9935#[cfg_attr(feature = "bindings", derive(TS))]
9936pub struct DeclareItem {
9937    pub this: Box<Expression>,
9938    #[serde(default)]
9939    pub kind: Option<String>,
9940    #[serde(default)]
9941    pub default: Option<Box<Expression>>,
9942    #[serde(default)]
9943    pub has_as: bool,
9944    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
9945    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9946    pub additional_names: Vec<Expression>,
9947}
9948
9949/// Set
9950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9951#[cfg_attr(feature = "bindings", derive(TS))]
9952pub struct Set {
9953    #[serde(default)]
9954    pub expressions: Vec<Expression>,
9955    #[serde(default)]
9956    pub unset: Option<Box<Expression>>,
9957    #[serde(default)]
9958    pub tag: Option<Box<Expression>>,
9959}
9960
9961/// Heredoc
9962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9963#[cfg_attr(feature = "bindings", derive(TS))]
9964pub struct Heredoc {
9965    pub this: Box<Expression>,
9966    #[serde(default)]
9967    pub tag: Option<Box<Expression>>,
9968}
9969
9970/// QueryBand
9971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9972#[cfg_attr(feature = "bindings", derive(TS))]
9973pub struct QueryBand {
9974    pub this: Box<Expression>,
9975    #[serde(default)]
9976    pub scope: Option<Box<Expression>>,
9977    #[serde(default)]
9978    pub update: Option<Box<Expression>>,
9979}
9980
9981/// UserDefinedFunction
9982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9983#[cfg_attr(feature = "bindings", derive(TS))]
9984pub struct UserDefinedFunction {
9985    pub this: Box<Expression>,
9986    #[serde(default)]
9987    pub expressions: Vec<Expression>,
9988    #[serde(default)]
9989    pub wrapped: Option<Box<Expression>>,
9990}
9991
9992/// RecursiveWithSearch
9993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9994#[cfg_attr(feature = "bindings", derive(TS))]
9995pub struct RecursiveWithSearch {
9996    pub kind: String,
9997    pub this: Box<Expression>,
9998    pub expression: Box<Expression>,
9999    #[serde(default)]
10000    pub using: Option<Box<Expression>>,
10001}
10002
10003/// ProjectionDef
10004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10005#[cfg_attr(feature = "bindings", derive(TS))]
10006pub struct ProjectionDef {
10007    pub this: Box<Expression>,
10008    pub expression: Box<Expression>,
10009}
10010
10011/// TableAlias
10012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10013#[cfg_attr(feature = "bindings", derive(TS))]
10014pub struct TableAlias {
10015    #[serde(default)]
10016    pub this: Option<Box<Expression>>,
10017    #[serde(default)]
10018    pub columns: Vec<Expression>,
10019}
10020
10021/// ByteString
10022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10023#[cfg_attr(feature = "bindings", derive(TS))]
10024pub struct ByteString {
10025    pub this: Box<Expression>,
10026    #[serde(default)]
10027    pub is_bytes: Option<Box<Expression>>,
10028}
10029
10030/// HexStringExpr - Hex string expression (not literal)
10031/// BigQuery: converts to FROM_HEX(this)
10032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10033#[cfg_attr(feature = "bindings", derive(TS))]
10034pub struct HexStringExpr {
10035    pub this: Box<Expression>,
10036    #[serde(default)]
10037    pub is_integer: Option<bool>,
10038}
10039
10040/// UnicodeString
10041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10042#[cfg_attr(feature = "bindings", derive(TS))]
10043pub struct UnicodeString {
10044    pub this: Box<Expression>,
10045    #[serde(default)]
10046    pub escape: Option<Box<Expression>>,
10047}
10048
10049/// AlterColumn
10050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10051#[cfg_attr(feature = "bindings", derive(TS))]
10052pub struct AlterColumn {
10053    pub this: Box<Expression>,
10054    #[serde(default)]
10055    pub dtype: Option<Box<Expression>>,
10056    #[serde(default)]
10057    pub collate: Option<Box<Expression>>,
10058    #[serde(default)]
10059    pub using: Option<Box<Expression>>,
10060    #[serde(default)]
10061    pub default: Option<Box<Expression>>,
10062    #[serde(default)]
10063    pub drop: Option<Box<Expression>>,
10064    #[serde(default)]
10065    pub comment: Option<Box<Expression>>,
10066    #[serde(default)]
10067    pub allow_null: Option<Box<Expression>>,
10068    #[serde(default)]
10069    pub visible: Option<Box<Expression>>,
10070    #[serde(default)]
10071    pub rename_to: Option<Box<Expression>>,
10072}
10073
10074/// AlterSortKey
10075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10076#[cfg_attr(feature = "bindings", derive(TS))]
10077pub struct AlterSortKey {
10078    #[serde(default)]
10079    pub this: Option<Box<Expression>>,
10080    #[serde(default)]
10081    pub expressions: Vec<Expression>,
10082    #[serde(default)]
10083    pub compound: Option<Box<Expression>>,
10084}
10085
10086/// AlterSet
10087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10088#[cfg_attr(feature = "bindings", derive(TS))]
10089pub struct AlterSet {
10090    #[serde(default)]
10091    pub expressions: Vec<Expression>,
10092    #[serde(default)]
10093    pub option: Option<Box<Expression>>,
10094    #[serde(default)]
10095    pub tablespace: Option<Box<Expression>>,
10096    #[serde(default)]
10097    pub access_method: Option<Box<Expression>>,
10098    #[serde(default)]
10099    pub file_format: Option<Box<Expression>>,
10100    #[serde(default)]
10101    pub copy_options: Option<Box<Expression>>,
10102    #[serde(default)]
10103    pub tag: Option<Box<Expression>>,
10104    #[serde(default)]
10105    pub location: Option<Box<Expression>>,
10106    #[serde(default)]
10107    pub serde: Option<Box<Expression>>,
10108}
10109
10110/// RenameColumn
10111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10112#[cfg_attr(feature = "bindings", derive(TS))]
10113pub struct RenameColumn {
10114    pub this: Box<Expression>,
10115    #[serde(default)]
10116    pub to: Option<Box<Expression>>,
10117    #[serde(default)]
10118    pub exists: bool,
10119}
10120
10121/// Comprehension
10122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10123#[cfg_attr(feature = "bindings", derive(TS))]
10124pub struct Comprehension {
10125    pub this: Box<Expression>,
10126    pub expression: Box<Expression>,
10127    #[serde(default)]
10128    pub position: Option<Box<Expression>>,
10129    #[serde(default)]
10130    pub iterator: Option<Box<Expression>>,
10131    #[serde(default)]
10132    pub condition: Option<Box<Expression>>,
10133}
10134
10135/// MergeTreeTTLAction
10136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10137#[cfg_attr(feature = "bindings", derive(TS))]
10138pub struct MergeTreeTTLAction {
10139    pub this: Box<Expression>,
10140    #[serde(default)]
10141    pub delete: Option<Box<Expression>>,
10142    #[serde(default)]
10143    pub recompress: Option<Box<Expression>>,
10144    #[serde(default)]
10145    pub to_disk: Option<Box<Expression>>,
10146    #[serde(default)]
10147    pub to_volume: Option<Box<Expression>>,
10148}
10149
10150/// MergeTreeTTL
10151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10152#[cfg_attr(feature = "bindings", derive(TS))]
10153pub struct MergeTreeTTL {
10154    #[serde(default)]
10155    pub expressions: Vec<Expression>,
10156    #[serde(default)]
10157    pub where_: Option<Box<Expression>>,
10158    #[serde(default)]
10159    pub group: Option<Box<Expression>>,
10160    #[serde(default)]
10161    pub aggregates: Option<Box<Expression>>,
10162}
10163
10164/// IndexConstraintOption
10165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10166#[cfg_attr(feature = "bindings", derive(TS))]
10167pub struct IndexConstraintOption {
10168    #[serde(default)]
10169    pub key_block_size: Option<Box<Expression>>,
10170    #[serde(default)]
10171    pub using: Option<Box<Expression>>,
10172    #[serde(default)]
10173    pub parser: Option<Box<Expression>>,
10174    #[serde(default)]
10175    pub comment: Option<Box<Expression>>,
10176    #[serde(default)]
10177    pub visible: Option<Box<Expression>>,
10178    #[serde(default)]
10179    pub engine_attr: Option<Box<Expression>>,
10180    #[serde(default)]
10181    pub secondary_engine_attr: Option<Box<Expression>>,
10182}
10183
10184/// PeriodForSystemTimeConstraint
10185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10186#[cfg_attr(feature = "bindings", derive(TS))]
10187pub struct PeriodForSystemTimeConstraint {
10188    pub this: Box<Expression>,
10189    pub expression: Box<Expression>,
10190}
10191
10192/// CaseSpecificColumnConstraint
10193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10194#[cfg_attr(feature = "bindings", derive(TS))]
10195pub struct CaseSpecificColumnConstraint {
10196    #[serde(default)]
10197    pub not_: Option<Box<Expression>>,
10198}
10199
10200/// CharacterSetColumnConstraint
10201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10202#[cfg_attr(feature = "bindings", derive(TS))]
10203pub struct CharacterSetColumnConstraint {
10204    pub this: Box<Expression>,
10205}
10206
10207/// CheckColumnConstraint
10208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10209#[cfg_attr(feature = "bindings", derive(TS))]
10210pub struct CheckColumnConstraint {
10211    pub this: Box<Expression>,
10212    #[serde(default)]
10213    pub enforced: Option<Box<Expression>>,
10214}
10215
10216/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10218#[cfg_attr(feature = "bindings", derive(TS))]
10219pub struct AssumeColumnConstraint {
10220    pub this: Box<Expression>,
10221}
10222
10223/// CompressColumnConstraint
10224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10225#[cfg_attr(feature = "bindings", derive(TS))]
10226pub struct CompressColumnConstraint {
10227    #[serde(default)]
10228    pub this: Option<Box<Expression>>,
10229}
10230
10231/// DateFormatColumnConstraint
10232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10233#[cfg_attr(feature = "bindings", derive(TS))]
10234pub struct DateFormatColumnConstraint {
10235    pub this: Box<Expression>,
10236}
10237
10238/// EphemeralColumnConstraint
10239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10240#[cfg_attr(feature = "bindings", derive(TS))]
10241pub struct EphemeralColumnConstraint {
10242    #[serde(default)]
10243    pub this: Option<Box<Expression>>,
10244}
10245
10246/// WithOperator
10247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10248#[cfg_attr(feature = "bindings", derive(TS))]
10249pub struct WithOperator {
10250    pub this: Box<Expression>,
10251    pub op: String,
10252}
10253
10254/// GeneratedAsIdentityColumnConstraint
10255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10256#[cfg_attr(feature = "bindings", derive(TS))]
10257pub struct GeneratedAsIdentityColumnConstraint {
10258    #[serde(default)]
10259    pub this: Option<Box<Expression>>,
10260    #[serde(default)]
10261    pub expression: Option<Box<Expression>>,
10262    #[serde(default)]
10263    pub on_null: Option<Box<Expression>>,
10264    #[serde(default)]
10265    pub start: Option<Box<Expression>>,
10266    #[serde(default)]
10267    pub increment: Option<Box<Expression>>,
10268    #[serde(default)]
10269    pub minvalue: Option<Box<Expression>>,
10270    #[serde(default)]
10271    pub maxvalue: Option<Box<Expression>>,
10272    #[serde(default)]
10273    pub cycle: Option<Box<Expression>>,
10274    #[serde(default)]
10275    pub order: Option<Box<Expression>>,
10276}
10277
10278/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10279/// TSQL: outputs "IDENTITY"
10280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10281#[cfg_attr(feature = "bindings", derive(TS))]
10282pub struct AutoIncrementColumnConstraint;
10283
10284/// CommentColumnConstraint - Column comment marker
10285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10286#[cfg_attr(feature = "bindings", derive(TS))]
10287pub struct CommentColumnConstraint;
10288
10289/// GeneratedAsRowColumnConstraint
10290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10291#[cfg_attr(feature = "bindings", derive(TS))]
10292pub struct GeneratedAsRowColumnConstraint {
10293    #[serde(default)]
10294    pub start: Option<Box<Expression>>,
10295    #[serde(default)]
10296    pub hidden: Option<Box<Expression>>,
10297}
10298
10299/// IndexColumnConstraint
10300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10301#[cfg_attr(feature = "bindings", derive(TS))]
10302pub struct IndexColumnConstraint {
10303    #[serde(default)]
10304    pub this: Option<Box<Expression>>,
10305    #[serde(default)]
10306    pub expressions: Vec<Expression>,
10307    #[serde(default)]
10308    pub kind: Option<String>,
10309    #[serde(default)]
10310    pub index_type: Option<Box<Expression>>,
10311    #[serde(default)]
10312    pub options: Vec<Expression>,
10313    #[serde(default)]
10314    pub expression: Option<Box<Expression>>,
10315    #[serde(default)]
10316    pub granularity: Option<Box<Expression>>,
10317}
10318
10319/// MaskingPolicyColumnConstraint
10320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10321#[cfg_attr(feature = "bindings", derive(TS))]
10322pub struct MaskingPolicyColumnConstraint {
10323    pub this: Box<Expression>,
10324    #[serde(default)]
10325    pub expressions: Vec<Expression>,
10326}
10327
10328/// NotNullColumnConstraint
10329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10330#[cfg_attr(feature = "bindings", derive(TS))]
10331pub struct NotNullColumnConstraint {
10332    #[serde(default)]
10333    pub allow_null: Option<Box<Expression>>,
10334}
10335
10336/// DefaultColumnConstraint - DEFAULT value for a column
10337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10338#[cfg_attr(feature = "bindings", derive(TS))]
10339pub struct DefaultColumnConstraint {
10340    pub this: Box<Expression>,
10341    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10342    #[serde(default, skip_serializing_if = "Option::is_none")]
10343    pub for_column: Option<Identifier>,
10344}
10345
10346/// PrimaryKeyColumnConstraint
10347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10348#[cfg_attr(feature = "bindings", derive(TS))]
10349pub struct PrimaryKeyColumnConstraint {
10350    #[serde(default)]
10351    pub desc: Option<Box<Expression>>,
10352    #[serde(default)]
10353    pub options: Vec<Expression>,
10354}
10355
10356/// UniqueColumnConstraint
10357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10358#[cfg_attr(feature = "bindings", derive(TS))]
10359pub struct UniqueColumnConstraint {
10360    #[serde(default)]
10361    pub this: Option<Box<Expression>>,
10362    #[serde(default)]
10363    pub index_type: Option<Box<Expression>>,
10364    #[serde(default)]
10365    pub on_conflict: Option<Box<Expression>>,
10366    #[serde(default)]
10367    pub nulls: Option<Box<Expression>>,
10368    #[serde(default)]
10369    pub options: Vec<Expression>,
10370}
10371
10372/// WatermarkColumnConstraint
10373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10374#[cfg_attr(feature = "bindings", derive(TS))]
10375pub struct WatermarkColumnConstraint {
10376    pub this: Box<Expression>,
10377    pub expression: Box<Expression>,
10378}
10379
10380/// ComputedColumnConstraint
10381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10382#[cfg_attr(feature = "bindings", derive(TS))]
10383pub struct ComputedColumnConstraint {
10384    pub this: Box<Expression>,
10385    #[serde(default)]
10386    pub persisted: Option<Box<Expression>>,
10387    #[serde(default)]
10388    pub not_null: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub data_type: Option<Box<Expression>>,
10391}
10392
10393/// InOutColumnConstraint
10394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10395#[cfg_attr(feature = "bindings", derive(TS))]
10396pub struct InOutColumnConstraint {
10397    #[serde(default)]
10398    pub input_: Option<Box<Expression>>,
10399    #[serde(default)]
10400    pub output: Option<Box<Expression>>,
10401}
10402
10403/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10405#[cfg_attr(feature = "bindings", derive(TS))]
10406pub struct PathColumnConstraint {
10407    pub this: Box<Expression>,
10408}
10409
10410/// Constraint
10411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10412#[cfg_attr(feature = "bindings", derive(TS))]
10413pub struct Constraint {
10414    pub this: Box<Expression>,
10415    #[serde(default)]
10416    pub expressions: Vec<Expression>,
10417}
10418
10419/// Export
10420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10421#[cfg_attr(feature = "bindings", derive(TS))]
10422pub struct Export {
10423    pub this: Box<Expression>,
10424    #[serde(default)]
10425    pub connection: Option<Box<Expression>>,
10426    #[serde(default)]
10427    pub options: Vec<Expression>,
10428}
10429
10430/// Filter
10431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10432#[cfg_attr(feature = "bindings", derive(TS))]
10433pub struct Filter {
10434    pub this: Box<Expression>,
10435    pub expression: Box<Expression>,
10436}
10437
10438/// Changes
10439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10440#[cfg_attr(feature = "bindings", derive(TS))]
10441pub struct Changes {
10442    #[serde(default)]
10443    pub information: Option<Box<Expression>>,
10444    #[serde(default)]
10445    pub at_before: Option<Box<Expression>>,
10446    #[serde(default)]
10447    pub end: Option<Box<Expression>>,
10448}
10449
10450/// Directory
10451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10452#[cfg_attr(feature = "bindings", derive(TS))]
10453pub struct Directory {
10454    pub this: Box<Expression>,
10455    #[serde(default)]
10456    pub local: Option<Box<Expression>>,
10457    #[serde(default)]
10458    pub row_format: Option<Box<Expression>>,
10459}
10460
10461/// ForeignKey
10462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10463#[cfg_attr(feature = "bindings", derive(TS))]
10464pub struct ForeignKey {
10465    #[serde(default)]
10466    pub expressions: Vec<Expression>,
10467    #[serde(default)]
10468    pub reference: Option<Box<Expression>>,
10469    #[serde(default)]
10470    pub delete: Option<Box<Expression>>,
10471    #[serde(default)]
10472    pub update: Option<Box<Expression>>,
10473    #[serde(default)]
10474    pub options: Vec<Expression>,
10475}
10476
10477/// ColumnPrefix
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct ColumnPrefix {
10481    pub this: Box<Expression>,
10482    pub expression: Box<Expression>,
10483}
10484
10485/// PrimaryKey
10486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10487#[cfg_attr(feature = "bindings", derive(TS))]
10488pub struct PrimaryKey {
10489    #[serde(default)]
10490    pub this: Option<Box<Expression>>,
10491    #[serde(default)]
10492    pub expressions: Vec<Expression>,
10493    #[serde(default)]
10494    pub options: Vec<Expression>,
10495    #[serde(default)]
10496    pub include: Option<Box<Expression>>,
10497}
10498
10499/// Into
10500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10501#[cfg_attr(feature = "bindings", derive(TS))]
10502pub struct IntoClause {
10503    #[serde(default)]
10504    pub this: Option<Box<Expression>>,
10505    #[serde(default)]
10506    pub temporary: bool,
10507    #[serde(default)]
10508    pub unlogged: Option<Box<Expression>>,
10509    #[serde(default)]
10510    pub bulk_collect: Option<Box<Expression>>,
10511    #[serde(default)]
10512    pub expressions: Vec<Expression>,
10513}
10514
10515/// JoinHint
10516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10517#[cfg_attr(feature = "bindings", derive(TS))]
10518pub struct JoinHint {
10519    pub this: Box<Expression>,
10520    #[serde(default)]
10521    pub expressions: Vec<Expression>,
10522}
10523
10524/// Opclass
10525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10526#[cfg_attr(feature = "bindings", derive(TS))]
10527pub struct Opclass {
10528    pub this: Box<Expression>,
10529    pub expression: Box<Expression>,
10530}
10531
10532/// Index
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct Index {
10536    #[serde(default)]
10537    pub this: Option<Box<Expression>>,
10538    #[serde(default)]
10539    pub table: Option<Box<Expression>>,
10540    #[serde(default)]
10541    pub unique: bool,
10542    #[serde(default)]
10543    pub primary: Option<Box<Expression>>,
10544    #[serde(default)]
10545    pub amp: Option<Box<Expression>>,
10546    #[serde(default)]
10547    pub params: Vec<Expression>,
10548}
10549
10550/// IndexParameters
10551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10552#[cfg_attr(feature = "bindings", derive(TS))]
10553pub struct IndexParameters {
10554    #[serde(default)]
10555    pub using: Option<Box<Expression>>,
10556    #[serde(default)]
10557    pub include: Option<Box<Expression>>,
10558    #[serde(default)]
10559    pub columns: Vec<Expression>,
10560    #[serde(default)]
10561    pub with_storage: Option<Box<Expression>>,
10562    #[serde(default)]
10563    pub partition_by: Option<Box<Expression>>,
10564    #[serde(default)]
10565    pub tablespace: Option<Box<Expression>>,
10566    #[serde(default)]
10567    pub where_: Option<Box<Expression>>,
10568    #[serde(default)]
10569    pub on: Option<Box<Expression>>,
10570}
10571
10572/// ConditionalInsert
10573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10574#[cfg_attr(feature = "bindings", derive(TS))]
10575pub struct ConditionalInsert {
10576    pub this: Box<Expression>,
10577    #[serde(default)]
10578    pub expression: Option<Box<Expression>>,
10579    #[serde(default)]
10580    pub else_: Option<Box<Expression>>,
10581}
10582
10583/// MultitableInserts
10584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10585#[cfg_attr(feature = "bindings", derive(TS))]
10586pub struct MultitableInserts {
10587    #[serde(default)]
10588    pub expressions: Vec<Expression>,
10589    pub kind: String,
10590    #[serde(default)]
10591    pub source: Option<Box<Expression>>,
10592    /// Leading comments before the statement
10593    #[serde(default)]
10594    pub leading_comments: Vec<String>,
10595}
10596
10597/// OnConflict
10598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10599#[cfg_attr(feature = "bindings", derive(TS))]
10600pub struct OnConflict {
10601    #[serde(default)]
10602    pub duplicate: Option<Box<Expression>>,
10603    #[serde(default)]
10604    pub expressions: Vec<Expression>,
10605    #[serde(default)]
10606    pub action: Option<Box<Expression>>,
10607    #[serde(default)]
10608    pub conflict_keys: Option<Box<Expression>>,
10609    #[serde(default)]
10610    pub index_predicate: Option<Box<Expression>>,
10611    #[serde(default)]
10612    pub constraint: Option<Box<Expression>>,
10613    #[serde(default)]
10614    pub where_: Option<Box<Expression>>,
10615}
10616
10617/// OnCondition
10618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10619#[cfg_attr(feature = "bindings", derive(TS))]
10620pub struct OnCondition {
10621    #[serde(default)]
10622    pub error: Option<Box<Expression>>,
10623    #[serde(default)]
10624    pub empty: Option<Box<Expression>>,
10625    #[serde(default)]
10626    pub null: Option<Box<Expression>>,
10627}
10628
10629/// Returning
10630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10631#[cfg_attr(feature = "bindings", derive(TS))]
10632pub struct Returning {
10633    #[serde(default)]
10634    pub expressions: Vec<Expression>,
10635    #[serde(default)]
10636    pub into: Option<Box<Expression>>,
10637}
10638
10639/// Introducer
10640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10641#[cfg_attr(feature = "bindings", derive(TS))]
10642pub struct Introducer {
10643    pub this: Box<Expression>,
10644    pub expression: Box<Expression>,
10645}
10646
10647/// PartitionRange
10648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10649#[cfg_attr(feature = "bindings", derive(TS))]
10650pub struct PartitionRange {
10651    pub this: Box<Expression>,
10652    #[serde(default)]
10653    pub expression: Option<Box<Expression>>,
10654    #[serde(default)]
10655    pub expressions: Vec<Expression>,
10656}
10657
10658/// Group
10659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10660#[cfg_attr(feature = "bindings", derive(TS))]
10661pub struct Group {
10662    #[serde(default)]
10663    pub expressions: Vec<Expression>,
10664    #[serde(default)]
10665    pub grouping_sets: Option<Box<Expression>>,
10666    #[serde(default)]
10667    pub cube: Option<Box<Expression>>,
10668    #[serde(default)]
10669    pub rollup: Option<Box<Expression>>,
10670    #[serde(default)]
10671    pub totals: Option<Box<Expression>>,
10672    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10673    #[serde(default)]
10674    pub all: Option<bool>,
10675}
10676
10677/// Cube
10678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10679#[cfg_attr(feature = "bindings", derive(TS))]
10680pub struct Cube {
10681    #[serde(default)]
10682    pub expressions: Vec<Expression>,
10683}
10684
10685/// Rollup
10686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10687#[cfg_attr(feature = "bindings", derive(TS))]
10688pub struct Rollup {
10689    #[serde(default)]
10690    pub expressions: Vec<Expression>,
10691}
10692
10693/// GroupingSets
10694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10695#[cfg_attr(feature = "bindings", derive(TS))]
10696pub struct GroupingSets {
10697    #[serde(default)]
10698    pub expressions: Vec<Expression>,
10699}
10700
10701/// LimitOptions
10702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10703#[cfg_attr(feature = "bindings", derive(TS))]
10704pub struct LimitOptions {
10705    #[serde(default)]
10706    pub percent: Option<Box<Expression>>,
10707    #[serde(default)]
10708    pub rows: Option<Box<Expression>>,
10709    #[serde(default)]
10710    pub with_ties: Option<Box<Expression>>,
10711}
10712
10713/// Lateral
10714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10715#[cfg_attr(feature = "bindings", derive(TS))]
10716pub struct Lateral {
10717    pub this: Box<Expression>,
10718    #[serde(default)]
10719    pub view: Option<Box<Expression>>,
10720    #[serde(default)]
10721    pub outer: Option<Box<Expression>>,
10722    #[serde(default)]
10723    pub alias: Option<String>,
10724    /// Whether the alias was originally quoted (backtick/double-quote)
10725    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10726    pub alias_quoted: bool,
10727    #[serde(default)]
10728    pub cross_apply: Option<Box<Expression>>,
10729    #[serde(default)]
10730    pub ordinality: Option<Box<Expression>>,
10731    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10732    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10733    pub column_aliases: Vec<String>,
10734}
10735
10736/// TableFromRows
10737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10738#[cfg_attr(feature = "bindings", derive(TS))]
10739pub struct TableFromRows {
10740    pub this: Box<Expression>,
10741    #[serde(default)]
10742    pub alias: Option<String>,
10743    #[serde(default)]
10744    pub joins: Vec<Expression>,
10745    #[serde(default)]
10746    pub pivots: Option<Box<Expression>>,
10747    #[serde(default)]
10748    pub sample: Option<Box<Expression>>,
10749}
10750
10751/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10752/// Used for set-returning functions with typed column definitions
10753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10754#[cfg_attr(feature = "bindings", derive(TS))]
10755pub struct RowsFrom {
10756    /// List of function expressions, each potentially with an alias and typed columns
10757    pub expressions: Vec<Expression>,
10758    /// WITH ORDINALITY modifier
10759    #[serde(default)]
10760    pub ordinality: bool,
10761    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10762    #[serde(default)]
10763    pub alias: Option<Box<Expression>>,
10764}
10765
10766/// WithFill
10767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10768#[cfg_attr(feature = "bindings", derive(TS))]
10769pub struct WithFill {
10770    #[serde(default)]
10771    pub from_: Option<Box<Expression>>,
10772    #[serde(default)]
10773    pub to: Option<Box<Expression>>,
10774    #[serde(default)]
10775    pub step: Option<Box<Expression>>,
10776    #[serde(default)]
10777    pub staleness: Option<Box<Expression>>,
10778    #[serde(default)]
10779    pub interpolate: Option<Box<Expression>>,
10780}
10781
10782/// Property
10783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10784#[cfg_attr(feature = "bindings", derive(TS))]
10785pub struct Property {
10786    pub this: Box<Expression>,
10787    #[serde(default)]
10788    pub value: Option<Box<Expression>>,
10789}
10790
10791/// GrantPrivilege
10792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10793#[cfg_attr(feature = "bindings", derive(TS))]
10794pub struct GrantPrivilege {
10795    pub this: Box<Expression>,
10796    #[serde(default)]
10797    pub expressions: Vec<Expression>,
10798}
10799
10800/// AllowedValuesProperty
10801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10802#[cfg_attr(feature = "bindings", derive(TS))]
10803pub struct AllowedValuesProperty {
10804    #[serde(default)]
10805    pub expressions: Vec<Expression>,
10806}
10807
10808/// AlgorithmProperty
10809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10810#[cfg_attr(feature = "bindings", derive(TS))]
10811pub struct AlgorithmProperty {
10812    pub this: Box<Expression>,
10813}
10814
10815/// AutoIncrementProperty
10816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10817#[cfg_attr(feature = "bindings", derive(TS))]
10818pub struct AutoIncrementProperty {
10819    pub this: Box<Expression>,
10820}
10821
10822/// AutoRefreshProperty
10823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10824#[cfg_attr(feature = "bindings", derive(TS))]
10825pub struct AutoRefreshProperty {
10826    pub this: Box<Expression>,
10827}
10828
10829/// BackupProperty
10830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10831#[cfg_attr(feature = "bindings", derive(TS))]
10832pub struct BackupProperty {
10833    pub this: Box<Expression>,
10834}
10835
10836/// BuildProperty
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct BuildProperty {
10840    pub this: Box<Expression>,
10841}
10842
10843/// BlockCompressionProperty
10844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10845#[cfg_attr(feature = "bindings", derive(TS))]
10846pub struct BlockCompressionProperty {
10847    #[serde(default)]
10848    pub autotemp: Option<Box<Expression>>,
10849    #[serde(default)]
10850    pub always: Option<Box<Expression>>,
10851    #[serde(default)]
10852    pub default: Option<Box<Expression>>,
10853    #[serde(default)]
10854    pub manual: Option<Box<Expression>>,
10855    #[serde(default)]
10856    pub never: Option<Box<Expression>>,
10857}
10858
10859/// CharacterSetProperty
10860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10861#[cfg_attr(feature = "bindings", derive(TS))]
10862pub struct CharacterSetProperty {
10863    pub this: Box<Expression>,
10864    #[serde(default)]
10865    pub default: Option<Box<Expression>>,
10866}
10867
10868/// ChecksumProperty
10869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10870#[cfg_attr(feature = "bindings", derive(TS))]
10871pub struct ChecksumProperty {
10872    #[serde(default)]
10873    pub on: Option<Box<Expression>>,
10874    #[serde(default)]
10875    pub default: Option<Box<Expression>>,
10876}
10877
10878/// CollateProperty
10879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10880#[cfg_attr(feature = "bindings", derive(TS))]
10881pub struct CollateProperty {
10882    pub this: Box<Expression>,
10883    #[serde(default)]
10884    pub default: Option<Box<Expression>>,
10885}
10886
10887/// DataBlocksizeProperty
10888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10889#[cfg_attr(feature = "bindings", derive(TS))]
10890pub struct DataBlocksizeProperty {
10891    #[serde(default)]
10892    pub size: Option<i64>,
10893    #[serde(default)]
10894    pub units: Option<Box<Expression>>,
10895    #[serde(default)]
10896    pub minimum: Option<Box<Expression>>,
10897    #[serde(default)]
10898    pub maximum: Option<Box<Expression>>,
10899    #[serde(default)]
10900    pub default: Option<Box<Expression>>,
10901}
10902
10903/// DataDeletionProperty
10904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10905#[cfg_attr(feature = "bindings", derive(TS))]
10906pub struct DataDeletionProperty {
10907    pub on: Box<Expression>,
10908    #[serde(default)]
10909    pub filter_column: Option<Box<Expression>>,
10910    #[serde(default)]
10911    pub retention_period: Option<Box<Expression>>,
10912}
10913
10914/// DefinerProperty
10915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10916#[cfg_attr(feature = "bindings", derive(TS))]
10917pub struct DefinerProperty {
10918    pub this: Box<Expression>,
10919}
10920
10921/// DistKeyProperty
10922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10923#[cfg_attr(feature = "bindings", derive(TS))]
10924pub struct DistKeyProperty {
10925    pub this: Box<Expression>,
10926}
10927
10928/// DistributedByProperty
10929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10930#[cfg_attr(feature = "bindings", derive(TS))]
10931pub struct DistributedByProperty {
10932    #[serde(default)]
10933    pub expressions: Vec<Expression>,
10934    pub kind: String,
10935    #[serde(default)]
10936    pub buckets: Option<Box<Expression>>,
10937    #[serde(default)]
10938    pub order: Option<Box<Expression>>,
10939}
10940
10941/// DistStyleProperty
10942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10943#[cfg_attr(feature = "bindings", derive(TS))]
10944pub struct DistStyleProperty {
10945    pub this: Box<Expression>,
10946}
10947
10948/// DuplicateKeyProperty
10949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10950#[cfg_attr(feature = "bindings", derive(TS))]
10951pub struct DuplicateKeyProperty {
10952    #[serde(default)]
10953    pub expressions: Vec<Expression>,
10954}
10955
10956/// EngineProperty
10957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10958#[cfg_attr(feature = "bindings", derive(TS))]
10959pub struct EngineProperty {
10960    pub this: Box<Expression>,
10961}
10962
10963/// ToTableProperty
10964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10965#[cfg_attr(feature = "bindings", derive(TS))]
10966pub struct ToTableProperty {
10967    pub this: Box<Expression>,
10968}
10969
10970/// ExecuteAsProperty
10971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10972#[cfg_attr(feature = "bindings", derive(TS))]
10973pub struct ExecuteAsProperty {
10974    pub this: Box<Expression>,
10975}
10976
10977/// ExternalProperty
10978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10979#[cfg_attr(feature = "bindings", derive(TS))]
10980pub struct ExternalProperty {
10981    #[serde(default)]
10982    pub this: Option<Box<Expression>>,
10983}
10984
10985/// FallbackProperty
10986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10987#[cfg_attr(feature = "bindings", derive(TS))]
10988pub struct FallbackProperty {
10989    #[serde(default)]
10990    pub no: Option<Box<Expression>>,
10991    #[serde(default)]
10992    pub protection: Option<Box<Expression>>,
10993}
10994
10995/// FileFormatProperty
10996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10997#[cfg_attr(feature = "bindings", derive(TS))]
10998pub struct FileFormatProperty {
10999    #[serde(default)]
11000    pub this: Option<Box<Expression>>,
11001    #[serde(default)]
11002    pub expressions: Vec<Expression>,
11003    #[serde(default)]
11004    pub hive_format: Option<Box<Expression>>,
11005}
11006
11007/// CredentialsProperty
11008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11009#[cfg_attr(feature = "bindings", derive(TS))]
11010pub struct CredentialsProperty {
11011    #[serde(default)]
11012    pub expressions: Vec<Expression>,
11013}
11014
11015/// FreespaceProperty
11016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11017#[cfg_attr(feature = "bindings", derive(TS))]
11018pub struct FreespaceProperty {
11019    pub this: Box<Expression>,
11020    #[serde(default)]
11021    pub percent: Option<Box<Expression>>,
11022}
11023
11024/// InheritsProperty
11025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11026#[cfg_attr(feature = "bindings", derive(TS))]
11027pub struct InheritsProperty {
11028    #[serde(default)]
11029    pub expressions: Vec<Expression>,
11030}
11031
11032/// InputModelProperty
11033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11034#[cfg_attr(feature = "bindings", derive(TS))]
11035pub struct InputModelProperty {
11036    pub this: Box<Expression>,
11037}
11038
11039/// OutputModelProperty
11040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11041#[cfg_attr(feature = "bindings", derive(TS))]
11042pub struct OutputModelProperty {
11043    pub this: Box<Expression>,
11044}
11045
11046/// IsolatedLoadingProperty
11047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11048#[cfg_attr(feature = "bindings", derive(TS))]
11049pub struct IsolatedLoadingProperty {
11050    #[serde(default)]
11051    pub no: Option<Box<Expression>>,
11052    #[serde(default)]
11053    pub concurrent: Option<Box<Expression>>,
11054    #[serde(default)]
11055    pub target: Option<Box<Expression>>,
11056}
11057
11058/// JournalProperty
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct JournalProperty {
11062    #[serde(default)]
11063    pub no: Option<Box<Expression>>,
11064    #[serde(default)]
11065    pub dual: Option<Box<Expression>>,
11066    #[serde(default)]
11067    pub before: Option<Box<Expression>>,
11068    #[serde(default)]
11069    pub local: Option<Box<Expression>>,
11070    #[serde(default)]
11071    pub after: Option<Box<Expression>>,
11072}
11073
11074/// LanguageProperty
11075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11076#[cfg_attr(feature = "bindings", derive(TS))]
11077pub struct LanguageProperty {
11078    pub this: Box<Expression>,
11079}
11080
11081/// EnviromentProperty
11082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11083#[cfg_attr(feature = "bindings", derive(TS))]
11084pub struct EnviromentProperty {
11085    #[serde(default)]
11086    pub expressions: Vec<Expression>,
11087}
11088
11089/// ClusteredByProperty
11090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11091#[cfg_attr(feature = "bindings", derive(TS))]
11092pub struct ClusteredByProperty {
11093    #[serde(default)]
11094    pub expressions: Vec<Expression>,
11095    #[serde(default)]
11096    pub sorted_by: Option<Box<Expression>>,
11097    #[serde(default)]
11098    pub buckets: Option<Box<Expression>>,
11099}
11100
11101/// DictProperty
11102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11103#[cfg_attr(feature = "bindings", derive(TS))]
11104pub struct DictProperty {
11105    pub this: Box<Expression>,
11106    pub kind: String,
11107    #[serde(default)]
11108    pub settings: Option<Box<Expression>>,
11109}
11110
11111/// DictRange
11112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11113#[cfg_attr(feature = "bindings", derive(TS))]
11114pub struct DictRange {
11115    pub this: Box<Expression>,
11116    #[serde(default)]
11117    pub min: Option<Box<Expression>>,
11118    #[serde(default)]
11119    pub max: Option<Box<Expression>>,
11120}
11121
11122/// OnCluster
11123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11124#[cfg_attr(feature = "bindings", derive(TS))]
11125pub struct OnCluster {
11126    pub this: Box<Expression>,
11127}
11128
11129/// LikeProperty
11130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11131#[cfg_attr(feature = "bindings", derive(TS))]
11132pub struct LikeProperty {
11133    pub this: Box<Expression>,
11134    #[serde(default)]
11135    pub expressions: Vec<Expression>,
11136}
11137
11138/// LocationProperty
11139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11140#[cfg_attr(feature = "bindings", derive(TS))]
11141pub struct LocationProperty {
11142    pub this: Box<Expression>,
11143}
11144
11145/// LockProperty
11146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11147#[cfg_attr(feature = "bindings", derive(TS))]
11148pub struct LockProperty {
11149    pub this: Box<Expression>,
11150}
11151
11152/// LockingProperty
11153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11154#[cfg_attr(feature = "bindings", derive(TS))]
11155pub struct LockingProperty {
11156    #[serde(default)]
11157    pub this: Option<Box<Expression>>,
11158    pub kind: String,
11159    #[serde(default)]
11160    pub for_or_in: Option<Box<Expression>>,
11161    #[serde(default)]
11162    pub lock_type: Option<Box<Expression>>,
11163    #[serde(default)]
11164    pub override_: Option<Box<Expression>>,
11165}
11166
11167/// LogProperty
11168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11169#[cfg_attr(feature = "bindings", derive(TS))]
11170pub struct LogProperty {
11171    #[serde(default)]
11172    pub no: Option<Box<Expression>>,
11173}
11174
11175/// MaterializedProperty
11176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11177#[cfg_attr(feature = "bindings", derive(TS))]
11178pub struct MaterializedProperty {
11179    #[serde(default)]
11180    pub this: Option<Box<Expression>>,
11181}
11182
11183/// MergeBlockRatioProperty
11184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11185#[cfg_attr(feature = "bindings", derive(TS))]
11186pub struct MergeBlockRatioProperty {
11187    #[serde(default)]
11188    pub this: Option<Box<Expression>>,
11189    #[serde(default)]
11190    pub no: Option<Box<Expression>>,
11191    #[serde(default)]
11192    pub default: Option<Box<Expression>>,
11193    #[serde(default)]
11194    pub percent: Option<Box<Expression>>,
11195}
11196
11197/// OnProperty
11198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11199#[cfg_attr(feature = "bindings", derive(TS))]
11200pub struct OnProperty {
11201    pub this: Box<Expression>,
11202}
11203
11204/// OnCommitProperty
11205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11206#[cfg_attr(feature = "bindings", derive(TS))]
11207pub struct OnCommitProperty {
11208    #[serde(default)]
11209    pub delete: Option<Box<Expression>>,
11210}
11211
11212/// PartitionedByProperty
11213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11214#[cfg_attr(feature = "bindings", derive(TS))]
11215pub struct PartitionedByProperty {
11216    pub this: Box<Expression>,
11217}
11218
11219/// BigQuery PARTITION BY property in CREATE TABLE statements.
11220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11221#[cfg_attr(feature = "bindings", derive(TS))]
11222pub struct PartitionByProperty {
11223    #[serde(default)]
11224    pub expressions: Vec<Expression>,
11225}
11226
11227/// PartitionedByBucket
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct PartitionedByBucket {
11231    pub this: Box<Expression>,
11232    pub expression: Box<Expression>,
11233}
11234
11235/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11237#[cfg_attr(feature = "bindings", derive(TS))]
11238pub struct ClusterByColumnsProperty {
11239    #[serde(default)]
11240    pub columns: Vec<Identifier>,
11241}
11242
11243/// PartitionByTruncate
11244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11245#[cfg_attr(feature = "bindings", derive(TS))]
11246pub struct PartitionByTruncate {
11247    pub this: Box<Expression>,
11248    pub expression: Box<Expression>,
11249}
11250
11251/// PartitionByRangeProperty
11252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11253#[cfg_attr(feature = "bindings", derive(TS))]
11254pub struct PartitionByRangeProperty {
11255    #[serde(default)]
11256    pub partition_expressions: Option<Box<Expression>>,
11257    #[serde(default)]
11258    pub create_expressions: Option<Box<Expression>>,
11259}
11260
11261/// PartitionByRangePropertyDynamic
11262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11263#[cfg_attr(feature = "bindings", derive(TS))]
11264pub struct PartitionByRangePropertyDynamic {
11265    #[serde(default)]
11266    pub this: Option<Box<Expression>>,
11267    #[serde(default)]
11268    pub start: Option<Box<Expression>>,
11269    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11270    #[serde(default)]
11271    pub use_start_end: bool,
11272    #[serde(default)]
11273    pub end: Option<Box<Expression>>,
11274    #[serde(default)]
11275    pub every: Option<Box<Expression>>,
11276}
11277
11278/// PartitionByListProperty
11279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11280#[cfg_attr(feature = "bindings", derive(TS))]
11281pub struct PartitionByListProperty {
11282    #[serde(default)]
11283    pub partition_expressions: Option<Box<Expression>>,
11284    #[serde(default)]
11285    pub create_expressions: Option<Box<Expression>>,
11286}
11287
11288/// PartitionList
11289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11290#[cfg_attr(feature = "bindings", derive(TS))]
11291pub struct PartitionList {
11292    pub this: Box<Expression>,
11293    #[serde(default)]
11294    pub expressions: Vec<Expression>,
11295}
11296
11297/// Partition - represents PARTITION/SUBPARTITION clause
11298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11299#[cfg_attr(feature = "bindings", derive(TS))]
11300pub struct Partition {
11301    pub expressions: Vec<Expression>,
11302    #[serde(default)]
11303    pub subpartition: bool,
11304}
11305
11306/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11307/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11309#[cfg_attr(feature = "bindings", derive(TS))]
11310pub struct RefreshTriggerProperty {
11311    /// Method: COMPLETE or AUTO
11312    pub method: String,
11313    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11314    #[serde(default)]
11315    pub kind: Option<String>,
11316    /// For SCHEDULE: EVERY n (the number)
11317    #[serde(default)]
11318    pub every: Option<Box<Expression>>,
11319    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11320    #[serde(default)]
11321    pub unit: Option<String>,
11322    /// For SCHEDULE: STARTS 'datetime'
11323    #[serde(default)]
11324    pub starts: Option<Box<Expression>>,
11325}
11326
11327/// UniqueKeyProperty
11328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11329#[cfg_attr(feature = "bindings", derive(TS))]
11330pub struct UniqueKeyProperty {
11331    #[serde(default)]
11332    pub expressions: Vec<Expression>,
11333}
11334
11335/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11337#[cfg_attr(feature = "bindings", derive(TS))]
11338pub struct RollupProperty {
11339    pub expressions: Vec<RollupIndex>,
11340}
11341
11342/// RollupIndex - A single rollup index: name(col1, col2)
11343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11344#[cfg_attr(feature = "bindings", derive(TS))]
11345pub struct RollupIndex {
11346    pub name: Identifier,
11347    pub expressions: Vec<Identifier>,
11348}
11349
11350/// PartitionBoundSpec
11351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11352#[cfg_attr(feature = "bindings", derive(TS))]
11353pub struct PartitionBoundSpec {
11354    #[serde(default)]
11355    pub this: Option<Box<Expression>>,
11356    #[serde(default)]
11357    pub expression: Option<Box<Expression>>,
11358    #[serde(default)]
11359    pub from_expressions: Option<Box<Expression>>,
11360    #[serde(default)]
11361    pub to_expressions: Option<Box<Expression>>,
11362}
11363
11364/// PartitionedOfProperty
11365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11366#[cfg_attr(feature = "bindings", derive(TS))]
11367pub struct PartitionedOfProperty {
11368    pub this: Box<Expression>,
11369    pub expression: Box<Expression>,
11370}
11371
11372/// RemoteWithConnectionModelProperty
11373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11374#[cfg_attr(feature = "bindings", derive(TS))]
11375pub struct RemoteWithConnectionModelProperty {
11376    pub this: Box<Expression>,
11377}
11378
11379/// ReturnsProperty
11380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11381#[cfg_attr(feature = "bindings", derive(TS))]
11382pub struct ReturnsProperty {
11383    #[serde(default)]
11384    pub this: Option<Box<Expression>>,
11385    #[serde(default)]
11386    pub is_table: Option<Box<Expression>>,
11387    #[serde(default)]
11388    pub table: Option<Box<Expression>>,
11389    #[serde(default)]
11390    pub null: Option<Box<Expression>>,
11391}
11392
11393/// RowFormatProperty
11394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11395#[cfg_attr(feature = "bindings", derive(TS))]
11396pub struct RowFormatProperty {
11397    pub this: Box<Expression>,
11398}
11399
11400/// RowFormatDelimitedProperty
11401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11402#[cfg_attr(feature = "bindings", derive(TS))]
11403pub struct RowFormatDelimitedProperty {
11404    #[serde(default)]
11405    pub fields: Option<Box<Expression>>,
11406    #[serde(default)]
11407    pub escaped: Option<Box<Expression>>,
11408    #[serde(default)]
11409    pub collection_items: Option<Box<Expression>>,
11410    #[serde(default)]
11411    pub map_keys: Option<Box<Expression>>,
11412    #[serde(default)]
11413    pub lines: Option<Box<Expression>>,
11414    #[serde(default)]
11415    pub null: Option<Box<Expression>>,
11416    #[serde(default)]
11417    pub serde: Option<Box<Expression>>,
11418}
11419
11420/// RowFormatSerdeProperty
11421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11422#[cfg_attr(feature = "bindings", derive(TS))]
11423pub struct RowFormatSerdeProperty {
11424    pub this: Box<Expression>,
11425    #[serde(default)]
11426    pub serde_properties: Option<Box<Expression>>,
11427}
11428
11429/// QueryTransform
11430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11431#[cfg_attr(feature = "bindings", derive(TS))]
11432pub struct QueryTransform {
11433    #[serde(default)]
11434    pub expressions: Vec<Expression>,
11435    #[serde(default)]
11436    pub command_script: Option<Box<Expression>>,
11437    #[serde(default)]
11438    pub schema: Option<Box<Expression>>,
11439    #[serde(default)]
11440    pub row_format_before: Option<Box<Expression>>,
11441    #[serde(default)]
11442    pub record_writer: Option<Box<Expression>>,
11443    #[serde(default)]
11444    pub row_format_after: Option<Box<Expression>>,
11445    #[serde(default)]
11446    pub record_reader: Option<Box<Expression>>,
11447}
11448
11449/// SampleProperty
11450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11451#[cfg_attr(feature = "bindings", derive(TS))]
11452pub struct SampleProperty {
11453    pub this: Box<Expression>,
11454}
11455
11456/// SecurityProperty
11457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11458#[cfg_attr(feature = "bindings", derive(TS))]
11459pub struct SecurityProperty {
11460    pub this: Box<Expression>,
11461}
11462
11463/// SchemaCommentProperty
11464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11465#[cfg_attr(feature = "bindings", derive(TS))]
11466pub struct SchemaCommentProperty {
11467    pub this: Box<Expression>,
11468}
11469
11470/// SemanticView
11471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11472#[cfg_attr(feature = "bindings", derive(TS))]
11473pub struct SemanticView {
11474    pub this: Box<Expression>,
11475    #[serde(default)]
11476    pub metrics: Option<Box<Expression>>,
11477    #[serde(default)]
11478    pub dimensions: Option<Box<Expression>>,
11479    #[serde(default)]
11480    pub facts: Option<Box<Expression>>,
11481    #[serde(default)]
11482    pub where_: Option<Box<Expression>>,
11483}
11484
11485/// SerdeProperties
11486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11487#[cfg_attr(feature = "bindings", derive(TS))]
11488pub struct SerdeProperties {
11489    #[serde(default)]
11490    pub expressions: Vec<Expression>,
11491    #[serde(default)]
11492    pub with_: Option<Box<Expression>>,
11493}
11494
11495/// SetProperty
11496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11497#[cfg_attr(feature = "bindings", derive(TS))]
11498pub struct SetProperty {
11499    #[serde(default)]
11500    pub multi: Option<Box<Expression>>,
11501}
11502
11503/// SharingProperty
11504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11505#[cfg_attr(feature = "bindings", derive(TS))]
11506pub struct SharingProperty {
11507    #[serde(default)]
11508    pub this: Option<Box<Expression>>,
11509}
11510
11511/// SetConfigProperty
11512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11513#[cfg_attr(feature = "bindings", derive(TS))]
11514pub struct SetConfigProperty {
11515    pub this: Box<Expression>,
11516}
11517
11518/// SettingsProperty
11519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11520#[cfg_attr(feature = "bindings", derive(TS))]
11521pub struct SettingsProperty {
11522    #[serde(default)]
11523    pub expressions: Vec<Expression>,
11524}
11525
11526/// SortKeyProperty
11527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11528#[cfg_attr(feature = "bindings", derive(TS))]
11529pub struct SortKeyProperty {
11530    pub this: Box<Expression>,
11531    #[serde(default)]
11532    pub compound: Option<Box<Expression>>,
11533}
11534
11535/// SqlReadWriteProperty
11536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11537#[cfg_attr(feature = "bindings", derive(TS))]
11538pub struct SqlReadWriteProperty {
11539    pub this: Box<Expression>,
11540}
11541
11542/// SqlSecurityProperty
11543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11544#[cfg_attr(feature = "bindings", derive(TS))]
11545pub struct SqlSecurityProperty {
11546    pub this: Box<Expression>,
11547}
11548
11549/// StabilityProperty
11550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11551#[cfg_attr(feature = "bindings", derive(TS))]
11552pub struct StabilityProperty {
11553    pub this: Box<Expression>,
11554}
11555
11556/// StorageHandlerProperty
11557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11558#[cfg_attr(feature = "bindings", derive(TS))]
11559pub struct StorageHandlerProperty {
11560    pub this: Box<Expression>,
11561}
11562
11563/// TemporaryProperty
11564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11565#[cfg_attr(feature = "bindings", derive(TS))]
11566pub struct TemporaryProperty {
11567    #[serde(default)]
11568    pub this: Option<Box<Expression>>,
11569}
11570
11571/// Tags
11572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11573#[cfg_attr(feature = "bindings", derive(TS))]
11574pub struct Tags {
11575    #[serde(default)]
11576    pub expressions: Vec<Expression>,
11577}
11578
11579/// TransformModelProperty
11580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11581#[cfg_attr(feature = "bindings", derive(TS))]
11582pub struct TransformModelProperty {
11583    #[serde(default)]
11584    pub expressions: Vec<Expression>,
11585}
11586
11587/// TransientProperty
11588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11589#[cfg_attr(feature = "bindings", derive(TS))]
11590pub struct TransientProperty {
11591    #[serde(default)]
11592    pub this: Option<Box<Expression>>,
11593}
11594
11595/// UsingTemplateProperty
11596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11597#[cfg_attr(feature = "bindings", derive(TS))]
11598pub struct UsingTemplateProperty {
11599    pub this: Box<Expression>,
11600}
11601
11602/// ViewAttributeProperty
11603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11604#[cfg_attr(feature = "bindings", derive(TS))]
11605pub struct ViewAttributeProperty {
11606    pub this: Box<Expression>,
11607}
11608
11609/// VolatileProperty
11610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11611#[cfg_attr(feature = "bindings", derive(TS))]
11612pub struct VolatileProperty {
11613    #[serde(default)]
11614    pub this: Option<Box<Expression>>,
11615}
11616
11617/// WithDataProperty
11618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11619#[cfg_attr(feature = "bindings", derive(TS))]
11620pub struct WithDataProperty {
11621    #[serde(default)]
11622    pub no: Option<Box<Expression>>,
11623    #[serde(default)]
11624    pub statistics: Option<Box<Expression>>,
11625}
11626
11627/// WithJournalTableProperty
11628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11629#[cfg_attr(feature = "bindings", derive(TS))]
11630pub struct WithJournalTableProperty {
11631    pub this: Box<Expression>,
11632}
11633
11634/// WithSchemaBindingProperty
11635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11636#[cfg_attr(feature = "bindings", derive(TS))]
11637pub struct WithSchemaBindingProperty {
11638    pub this: Box<Expression>,
11639}
11640
11641/// WithSystemVersioningProperty
11642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11643#[cfg_attr(feature = "bindings", derive(TS))]
11644pub struct WithSystemVersioningProperty {
11645    #[serde(default)]
11646    pub on: Option<Box<Expression>>,
11647    #[serde(default)]
11648    pub this: Option<Box<Expression>>,
11649    #[serde(default)]
11650    pub data_consistency: Option<Box<Expression>>,
11651    #[serde(default)]
11652    pub retention_period: Option<Box<Expression>>,
11653    #[serde(default)]
11654    pub with_: Option<Box<Expression>>,
11655}
11656
11657/// WithProcedureOptions
11658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11659#[cfg_attr(feature = "bindings", derive(TS))]
11660pub struct WithProcedureOptions {
11661    #[serde(default)]
11662    pub expressions: Vec<Expression>,
11663}
11664
11665/// EncodeProperty
11666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11667#[cfg_attr(feature = "bindings", derive(TS))]
11668pub struct EncodeProperty {
11669    pub this: Box<Expression>,
11670    #[serde(default)]
11671    pub properties: Vec<Expression>,
11672    #[serde(default)]
11673    pub key: Option<Box<Expression>>,
11674}
11675
11676/// IncludeProperty
11677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11678#[cfg_attr(feature = "bindings", derive(TS))]
11679pub struct IncludeProperty {
11680    pub this: Box<Expression>,
11681    #[serde(default)]
11682    pub alias: Option<String>,
11683    #[serde(default)]
11684    pub column_def: Option<Box<Expression>>,
11685}
11686
11687/// Properties
11688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11689#[cfg_attr(feature = "bindings", derive(TS))]
11690pub struct Properties {
11691    #[serde(default)]
11692    pub expressions: Vec<Expression>,
11693}
11694
11695/// Key/value pair in a BigQuery OPTIONS (...) clause.
11696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11697#[cfg_attr(feature = "bindings", derive(TS))]
11698pub struct OptionEntry {
11699    pub key: Identifier,
11700    pub value: Expression,
11701}
11702
11703/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11705#[cfg_attr(feature = "bindings", derive(TS))]
11706pub struct OptionsProperty {
11707    #[serde(default)]
11708    pub entries: Vec<OptionEntry>,
11709}
11710
11711/// InputOutputFormat
11712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11713#[cfg_attr(feature = "bindings", derive(TS))]
11714pub struct InputOutputFormat {
11715    #[serde(default)]
11716    pub input_format: Option<Box<Expression>>,
11717    #[serde(default)]
11718    pub output_format: Option<Box<Expression>>,
11719}
11720
11721/// Reference
11722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11723#[cfg_attr(feature = "bindings", derive(TS))]
11724pub struct Reference {
11725    pub this: Box<Expression>,
11726    #[serde(default)]
11727    pub expressions: Vec<Expression>,
11728    #[serde(default)]
11729    pub options: Vec<Expression>,
11730}
11731
11732/// QueryOption
11733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11734#[cfg_attr(feature = "bindings", derive(TS))]
11735pub struct QueryOption {
11736    pub this: Box<Expression>,
11737    #[serde(default)]
11738    pub expression: Option<Box<Expression>>,
11739}
11740
11741/// WithTableHint
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct WithTableHint {
11745    #[serde(default)]
11746    pub expressions: Vec<Expression>,
11747}
11748
11749/// IndexTableHint
11750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11751#[cfg_attr(feature = "bindings", derive(TS))]
11752pub struct IndexTableHint {
11753    pub this: Box<Expression>,
11754    #[serde(default)]
11755    pub expressions: Vec<Expression>,
11756    #[serde(default)]
11757    pub target: Option<Box<Expression>>,
11758}
11759
11760/// Get
11761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11762#[cfg_attr(feature = "bindings", derive(TS))]
11763pub struct Get {
11764    pub this: Box<Expression>,
11765    #[serde(default)]
11766    pub target: Option<Box<Expression>>,
11767    #[serde(default)]
11768    pub properties: Vec<Expression>,
11769}
11770
11771/// SetOperation
11772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11773#[cfg_attr(feature = "bindings", derive(TS))]
11774pub struct SetOperation {
11775    #[serde(default)]
11776    pub with_: Option<Box<Expression>>,
11777    pub this: Box<Expression>,
11778    pub expression: Box<Expression>,
11779    #[serde(default)]
11780    pub distinct: bool,
11781    #[serde(default)]
11782    pub by_name: Option<Box<Expression>>,
11783    #[serde(default)]
11784    pub side: Option<Box<Expression>>,
11785    #[serde(default)]
11786    pub kind: Option<String>,
11787    #[serde(default)]
11788    pub on: Option<Box<Expression>>,
11789}
11790
11791/// Var - Simple variable reference (for SQL variables, keywords as values)
11792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11793#[cfg_attr(feature = "bindings", derive(TS))]
11794pub struct Var {
11795    pub this: String,
11796}
11797
11798/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11800#[cfg_attr(feature = "bindings", derive(TS))]
11801pub struct Variadic {
11802    pub this: Box<Expression>,
11803}
11804
11805/// Version
11806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11807#[cfg_attr(feature = "bindings", derive(TS))]
11808pub struct Version {
11809    pub this: Box<Expression>,
11810    pub kind: String,
11811    #[serde(default)]
11812    pub expression: Option<Box<Expression>>,
11813}
11814
11815/// Schema
11816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11817#[cfg_attr(feature = "bindings", derive(TS))]
11818pub struct Schema {
11819    #[serde(default)]
11820    pub this: Option<Box<Expression>>,
11821    #[serde(default)]
11822    pub expressions: Vec<Expression>,
11823}
11824
11825/// Lock
11826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11827#[cfg_attr(feature = "bindings", derive(TS))]
11828pub struct Lock {
11829    #[serde(default)]
11830    pub update: Option<Box<Expression>>,
11831    #[serde(default)]
11832    pub expressions: Vec<Expression>,
11833    #[serde(default)]
11834    pub wait: Option<Box<Expression>>,
11835    #[serde(default)]
11836    pub key: Option<Box<Expression>>,
11837}
11838
11839/// TableSample - wraps an expression with a TABLESAMPLE clause
11840/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11842#[cfg_attr(feature = "bindings", derive(TS))]
11843pub struct TableSample {
11844    /// The expression being sampled (subquery, function, etc.)
11845    #[serde(default, skip_serializing_if = "Option::is_none")]
11846    pub this: Option<Box<Expression>>,
11847    /// The sample specification
11848    #[serde(default, skip_serializing_if = "Option::is_none")]
11849    pub sample: Option<Box<Sample>>,
11850    #[serde(default)]
11851    pub expressions: Vec<Expression>,
11852    #[serde(default)]
11853    pub method: Option<String>,
11854    #[serde(default)]
11855    pub bucket_numerator: Option<Box<Expression>>,
11856    #[serde(default)]
11857    pub bucket_denominator: Option<Box<Expression>>,
11858    #[serde(default)]
11859    pub bucket_field: Option<Box<Expression>>,
11860    #[serde(default)]
11861    pub percent: Option<Box<Expression>>,
11862    #[serde(default)]
11863    pub rows: Option<Box<Expression>>,
11864    #[serde(default)]
11865    pub size: Option<i64>,
11866    #[serde(default)]
11867    pub seed: Option<Box<Expression>>,
11868}
11869
11870/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11872#[cfg_attr(feature = "bindings", derive(TS))]
11873pub struct Tag {
11874    #[serde(default)]
11875    pub this: Option<Box<Expression>>,
11876    #[serde(default)]
11877    pub prefix: Option<Box<Expression>>,
11878    #[serde(default)]
11879    pub postfix: Option<Box<Expression>>,
11880}
11881
11882/// UnpivotColumns
11883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11884#[cfg_attr(feature = "bindings", derive(TS))]
11885pub struct UnpivotColumns {
11886    pub this: Box<Expression>,
11887    #[serde(default)]
11888    pub expressions: Vec<Expression>,
11889}
11890
11891/// SessionParameter
11892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11893#[cfg_attr(feature = "bindings", derive(TS))]
11894pub struct SessionParameter {
11895    pub this: Box<Expression>,
11896    #[serde(default)]
11897    pub kind: Option<String>,
11898}
11899
11900/// PseudoType
11901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11902#[cfg_attr(feature = "bindings", derive(TS))]
11903pub struct PseudoType {
11904    pub this: Box<Expression>,
11905}
11906
11907/// ObjectIdentifier
11908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11909#[cfg_attr(feature = "bindings", derive(TS))]
11910pub struct ObjectIdentifier {
11911    pub this: Box<Expression>,
11912}
11913
11914/// Transaction
11915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11916#[cfg_attr(feature = "bindings", derive(TS))]
11917pub struct Transaction {
11918    #[serde(default)]
11919    pub this: Option<Box<Expression>>,
11920    #[serde(default)]
11921    pub modes: Option<Box<Expression>>,
11922    #[serde(default)]
11923    pub mark: Option<Box<Expression>>,
11924}
11925
11926/// Commit
11927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11928#[cfg_attr(feature = "bindings", derive(TS))]
11929pub struct Commit {
11930    #[serde(default)]
11931    pub chain: Option<Box<Expression>>,
11932    #[serde(default)]
11933    pub this: Option<Box<Expression>>,
11934    #[serde(default)]
11935    pub durability: Option<Box<Expression>>,
11936}
11937
11938/// Rollback
11939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11940#[cfg_attr(feature = "bindings", derive(TS))]
11941pub struct Rollback {
11942    #[serde(default)]
11943    pub savepoint: Option<Box<Expression>>,
11944    #[serde(default)]
11945    pub this: Option<Box<Expression>>,
11946}
11947
11948/// AlterSession
11949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11950#[cfg_attr(feature = "bindings", derive(TS))]
11951pub struct AlterSession {
11952    #[serde(default)]
11953    pub expressions: Vec<Expression>,
11954    #[serde(default)]
11955    pub unset: Option<Box<Expression>>,
11956}
11957
11958/// Analyze
11959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11960#[cfg_attr(feature = "bindings", derive(TS))]
11961pub struct Analyze {
11962    #[serde(default)]
11963    pub kind: Option<String>,
11964    #[serde(default)]
11965    pub this: Option<Box<Expression>>,
11966    #[serde(default)]
11967    pub options: Vec<Expression>,
11968    #[serde(default)]
11969    pub mode: Option<Box<Expression>>,
11970    #[serde(default)]
11971    pub partition: Option<Box<Expression>>,
11972    #[serde(default)]
11973    pub expression: Option<Box<Expression>>,
11974    #[serde(default)]
11975    pub properties: Vec<Expression>,
11976    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
11977    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11978    pub columns: Vec<String>,
11979}
11980
11981/// AnalyzeStatistics
11982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11983#[cfg_attr(feature = "bindings", derive(TS))]
11984pub struct AnalyzeStatistics {
11985    pub kind: String,
11986    #[serde(default)]
11987    pub option: Option<Box<Expression>>,
11988    #[serde(default)]
11989    pub this: Option<Box<Expression>>,
11990    #[serde(default)]
11991    pub expressions: Vec<Expression>,
11992}
11993
11994/// AnalyzeHistogram
11995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11996#[cfg_attr(feature = "bindings", derive(TS))]
11997pub struct AnalyzeHistogram {
11998    pub this: Box<Expression>,
11999    #[serde(default)]
12000    pub expressions: Vec<Expression>,
12001    #[serde(default)]
12002    pub expression: Option<Box<Expression>>,
12003    #[serde(default)]
12004    pub update_options: Option<Box<Expression>>,
12005}
12006
12007/// AnalyzeSample
12008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12009#[cfg_attr(feature = "bindings", derive(TS))]
12010pub struct AnalyzeSample {
12011    pub kind: String,
12012    #[serde(default)]
12013    pub sample: Option<Box<Expression>>,
12014}
12015
12016/// AnalyzeListChainedRows
12017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12018#[cfg_attr(feature = "bindings", derive(TS))]
12019pub struct AnalyzeListChainedRows {
12020    #[serde(default)]
12021    pub expression: Option<Box<Expression>>,
12022}
12023
12024/// AnalyzeDelete
12025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12026#[cfg_attr(feature = "bindings", derive(TS))]
12027pub struct AnalyzeDelete {
12028    #[serde(default)]
12029    pub kind: Option<String>,
12030}
12031
12032/// AnalyzeWith
12033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12034#[cfg_attr(feature = "bindings", derive(TS))]
12035pub struct AnalyzeWith {
12036    #[serde(default)]
12037    pub expressions: Vec<Expression>,
12038}
12039
12040/// AnalyzeValidate
12041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12042#[cfg_attr(feature = "bindings", derive(TS))]
12043pub struct AnalyzeValidate {
12044    pub kind: String,
12045    #[serde(default)]
12046    pub this: Option<Box<Expression>>,
12047    #[serde(default)]
12048    pub expression: Option<Box<Expression>>,
12049}
12050
12051/// AddPartition
12052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12053#[cfg_attr(feature = "bindings", derive(TS))]
12054pub struct AddPartition {
12055    pub this: Box<Expression>,
12056    #[serde(default)]
12057    pub exists: bool,
12058    #[serde(default)]
12059    pub location: Option<Box<Expression>>,
12060}
12061
12062/// AttachOption
12063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12064#[cfg_attr(feature = "bindings", derive(TS))]
12065pub struct AttachOption {
12066    pub this: Box<Expression>,
12067    #[serde(default)]
12068    pub expression: Option<Box<Expression>>,
12069}
12070
12071/// DropPartition
12072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12073#[cfg_attr(feature = "bindings", derive(TS))]
12074pub struct DropPartition {
12075    #[serde(default)]
12076    pub expressions: Vec<Expression>,
12077    #[serde(default)]
12078    pub exists: bool,
12079}
12080
12081/// ReplacePartition
12082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12083#[cfg_attr(feature = "bindings", derive(TS))]
12084pub struct ReplacePartition {
12085    pub expression: Box<Expression>,
12086    #[serde(default)]
12087    pub source: Option<Box<Expression>>,
12088}
12089
12090/// DPipe
12091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12092#[cfg_attr(feature = "bindings", derive(TS))]
12093pub struct DPipe {
12094    pub this: Box<Expression>,
12095    pub expression: Box<Expression>,
12096    #[serde(default)]
12097    pub safe: Option<Box<Expression>>,
12098}
12099
12100/// Operator
12101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12102#[cfg_attr(feature = "bindings", derive(TS))]
12103pub struct Operator {
12104    pub this: Box<Expression>,
12105    #[serde(default)]
12106    pub operator: Option<Box<Expression>>,
12107    pub expression: Box<Expression>,
12108    /// Comments between OPERATOR() and the RHS expression
12109    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12110    pub comments: Vec<String>,
12111}
12112
12113/// PivotAny
12114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12115#[cfg_attr(feature = "bindings", derive(TS))]
12116pub struct PivotAny {
12117    #[serde(default)]
12118    pub this: Option<Box<Expression>>,
12119}
12120
12121/// Aliases
12122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12123#[cfg_attr(feature = "bindings", derive(TS))]
12124pub struct Aliases {
12125    pub this: Box<Expression>,
12126    #[serde(default)]
12127    pub expressions: Vec<Expression>,
12128}
12129
12130/// AtIndex
12131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12132#[cfg_attr(feature = "bindings", derive(TS))]
12133pub struct AtIndex {
12134    pub this: Box<Expression>,
12135    pub expression: Box<Expression>,
12136}
12137
12138/// FromTimeZone
12139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12140#[cfg_attr(feature = "bindings", derive(TS))]
12141pub struct FromTimeZone {
12142    pub this: Box<Expression>,
12143    #[serde(default)]
12144    pub zone: Option<Box<Expression>>,
12145}
12146
12147/// Format override for a column in Teradata
12148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12149#[cfg_attr(feature = "bindings", derive(TS))]
12150pub struct FormatPhrase {
12151    pub this: Box<Expression>,
12152    pub format: String,
12153}
12154
12155/// ForIn
12156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12157#[cfg_attr(feature = "bindings", derive(TS))]
12158pub struct ForIn {
12159    pub this: Box<Expression>,
12160    pub expression: Box<Expression>,
12161}
12162
12163/// Automatically converts unit arg into a var.
12164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12165#[cfg_attr(feature = "bindings", derive(TS))]
12166pub struct TimeUnit {
12167    #[serde(default)]
12168    pub unit: Option<String>,
12169}
12170
12171/// IntervalOp
12172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12173#[cfg_attr(feature = "bindings", derive(TS))]
12174pub struct IntervalOp {
12175    #[serde(default)]
12176    pub unit: Option<String>,
12177    pub expression: Box<Expression>,
12178}
12179
12180/// HavingMax
12181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12182#[cfg_attr(feature = "bindings", derive(TS))]
12183pub struct HavingMax {
12184    pub this: Box<Expression>,
12185    pub expression: Box<Expression>,
12186    #[serde(default)]
12187    pub max: Option<Box<Expression>>,
12188}
12189
12190/// CosineDistance
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct CosineDistance {
12194    pub this: Box<Expression>,
12195    pub expression: Box<Expression>,
12196}
12197
12198/// DotProduct
12199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12200#[cfg_attr(feature = "bindings", derive(TS))]
12201pub struct DotProduct {
12202    pub this: Box<Expression>,
12203    pub expression: Box<Expression>,
12204}
12205
12206/// EuclideanDistance
12207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12208#[cfg_attr(feature = "bindings", derive(TS))]
12209pub struct EuclideanDistance {
12210    pub this: Box<Expression>,
12211    pub expression: Box<Expression>,
12212}
12213
12214/// ManhattanDistance
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct ManhattanDistance {
12218    pub this: Box<Expression>,
12219    pub expression: Box<Expression>,
12220}
12221
12222/// JarowinklerSimilarity
12223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12224#[cfg_attr(feature = "bindings", derive(TS))]
12225pub struct JarowinklerSimilarity {
12226    pub this: Box<Expression>,
12227    pub expression: Box<Expression>,
12228}
12229
12230/// Booland
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct Booland {
12234    pub this: Box<Expression>,
12235    pub expression: Box<Expression>,
12236}
12237
12238/// Boolor
12239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12240#[cfg_attr(feature = "bindings", derive(TS))]
12241pub struct Boolor {
12242    pub this: Box<Expression>,
12243    pub expression: Box<Expression>,
12244}
12245
12246/// ParameterizedAgg
12247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12248#[cfg_attr(feature = "bindings", derive(TS))]
12249pub struct ParameterizedAgg {
12250    pub this: Box<Expression>,
12251    #[serde(default)]
12252    pub expressions: Vec<Expression>,
12253    #[serde(default)]
12254    pub params: Vec<Expression>,
12255}
12256
12257/// ArgMax
12258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12259#[cfg_attr(feature = "bindings", derive(TS))]
12260pub struct ArgMax {
12261    pub this: Box<Expression>,
12262    pub expression: Box<Expression>,
12263    #[serde(default)]
12264    pub count: Option<Box<Expression>>,
12265}
12266
12267/// ArgMin
12268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12269#[cfg_attr(feature = "bindings", derive(TS))]
12270pub struct ArgMin {
12271    pub this: Box<Expression>,
12272    pub expression: Box<Expression>,
12273    #[serde(default)]
12274    pub count: Option<Box<Expression>>,
12275}
12276
12277/// ApproxTopK
12278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12279#[cfg_attr(feature = "bindings", derive(TS))]
12280pub struct ApproxTopK {
12281    pub this: Box<Expression>,
12282    #[serde(default)]
12283    pub expression: Option<Box<Expression>>,
12284    #[serde(default)]
12285    pub counters: Option<Box<Expression>>,
12286}
12287
12288/// ApproxTopKAccumulate
12289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12290#[cfg_attr(feature = "bindings", derive(TS))]
12291pub struct ApproxTopKAccumulate {
12292    pub this: Box<Expression>,
12293    #[serde(default)]
12294    pub expression: Option<Box<Expression>>,
12295}
12296
12297/// ApproxTopKCombine
12298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12299#[cfg_attr(feature = "bindings", derive(TS))]
12300pub struct ApproxTopKCombine {
12301    pub this: Box<Expression>,
12302    #[serde(default)]
12303    pub expression: Option<Box<Expression>>,
12304}
12305
12306/// ApproxTopKEstimate
12307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12308#[cfg_attr(feature = "bindings", derive(TS))]
12309pub struct ApproxTopKEstimate {
12310    pub this: Box<Expression>,
12311    #[serde(default)]
12312    pub expression: Option<Box<Expression>>,
12313}
12314
12315/// ApproxTopSum
12316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12317#[cfg_attr(feature = "bindings", derive(TS))]
12318pub struct ApproxTopSum {
12319    pub this: Box<Expression>,
12320    pub expression: Box<Expression>,
12321    #[serde(default)]
12322    pub count: Option<Box<Expression>>,
12323}
12324
12325/// ApproxQuantiles
12326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12327#[cfg_attr(feature = "bindings", derive(TS))]
12328pub struct ApproxQuantiles {
12329    pub this: Box<Expression>,
12330    #[serde(default)]
12331    pub expression: Option<Box<Expression>>,
12332}
12333
12334/// Minhash
12335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12336#[cfg_attr(feature = "bindings", derive(TS))]
12337pub struct Minhash {
12338    pub this: Box<Expression>,
12339    #[serde(default)]
12340    pub expressions: Vec<Expression>,
12341}
12342
12343/// FarmFingerprint
12344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12345#[cfg_attr(feature = "bindings", derive(TS))]
12346pub struct FarmFingerprint {
12347    #[serde(default)]
12348    pub expressions: Vec<Expression>,
12349}
12350
12351/// Float64
12352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12353#[cfg_attr(feature = "bindings", derive(TS))]
12354pub struct Float64 {
12355    pub this: Box<Expression>,
12356    #[serde(default)]
12357    pub expression: Option<Box<Expression>>,
12358}
12359
12360/// Transform
12361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12362#[cfg_attr(feature = "bindings", derive(TS))]
12363pub struct Transform {
12364    pub this: Box<Expression>,
12365    pub expression: Box<Expression>,
12366}
12367
12368/// Translate
12369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12370#[cfg_attr(feature = "bindings", derive(TS))]
12371pub struct Translate {
12372    pub this: Box<Expression>,
12373    #[serde(default)]
12374    pub from_: Option<Box<Expression>>,
12375    #[serde(default)]
12376    pub to: Option<Box<Expression>>,
12377}
12378
12379/// Grouping
12380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12381#[cfg_attr(feature = "bindings", derive(TS))]
12382pub struct Grouping {
12383    #[serde(default)]
12384    pub expressions: Vec<Expression>,
12385}
12386
12387/// GroupingId
12388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12389#[cfg_attr(feature = "bindings", derive(TS))]
12390pub struct GroupingId {
12391    #[serde(default)]
12392    pub expressions: Vec<Expression>,
12393}
12394
12395/// Anonymous
12396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12397#[cfg_attr(feature = "bindings", derive(TS))]
12398pub struct Anonymous {
12399    pub this: Box<Expression>,
12400    #[serde(default)]
12401    pub expressions: Vec<Expression>,
12402}
12403
12404/// AnonymousAggFunc
12405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12406#[cfg_attr(feature = "bindings", derive(TS))]
12407pub struct AnonymousAggFunc {
12408    pub this: Box<Expression>,
12409    #[serde(default)]
12410    pub expressions: Vec<Expression>,
12411}
12412
12413/// CombinedAggFunc
12414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12415#[cfg_attr(feature = "bindings", derive(TS))]
12416pub struct CombinedAggFunc {
12417    pub this: Box<Expression>,
12418    #[serde(default)]
12419    pub expressions: Vec<Expression>,
12420}
12421
12422/// CombinedParameterizedAgg
12423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12424#[cfg_attr(feature = "bindings", derive(TS))]
12425pub struct CombinedParameterizedAgg {
12426    pub this: Box<Expression>,
12427    #[serde(default)]
12428    pub expressions: Vec<Expression>,
12429    #[serde(default)]
12430    pub params: Vec<Expression>,
12431}
12432
12433/// HashAgg
12434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12435#[cfg_attr(feature = "bindings", derive(TS))]
12436pub struct HashAgg {
12437    pub this: Box<Expression>,
12438    #[serde(default)]
12439    pub expressions: Vec<Expression>,
12440}
12441
12442/// Hll
12443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12444#[cfg_attr(feature = "bindings", derive(TS))]
12445pub struct Hll {
12446    pub this: Box<Expression>,
12447    #[serde(default)]
12448    pub expressions: Vec<Expression>,
12449}
12450
12451/// Apply
12452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12453#[cfg_attr(feature = "bindings", derive(TS))]
12454pub struct Apply {
12455    pub this: Box<Expression>,
12456    pub expression: Box<Expression>,
12457}
12458
12459/// ToBoolean
12460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12461#[cfg_attr(feature = "bindings", derive(TS))]
12462pub struct ToBoolean {
12463    pub this: Box<Expression>,
12464    #[serde(default)]
12465    pub safe: Option<Box<Expression>>,
12466}
12467
12468/// List
12469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12470#[cfg_attr(feature = "bindings", derive(TS))]
12471pub struct List {
12472    #[serde(default)]
12473    pub expressions: Vec<Expression>,
12474}
12475
12476/// ToMap - Materialize-style map constructor
12477/// Can hold either:
12478/// - A SELECT subquery (MAP(SELECT 'a', 1))
12479/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct ToMap {
12483    /// Either a Select subquery or a Struct containing PropertyEQ entries
12484    pub this: Box<Expression>,
12485}
12486
12487/// Pad
12488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12489#[cfg_attr(feature = "bindings", derive(TS))]
12490pub struct Pad {
12491    pub this: Box<Expression>,
12492    pub expression: Box<Expression>,
12493    #[serde(default)]
12494    pub fill_pattern: Option<Box<Expression>>,
12495    #[serde(default)]
12496    pub is_left: Option<Box<Expression>>,
12497}
12498
12499/// ToChar
12500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12501#[cfg_attr(feature = "bindings", derive(TS))]
12502pub struct ToChar {
12503    pub this: Box<Expression>,
12504    #[serde(default)]
12505    pub format: Option<String>,
12506    #[serde(default)]
12507    pub nlsparam: Option<Box<Expression>>,
12508    #[serde(default)]
12509    pub is_numeric: Option<Box<Expression>>,
12510}
12511
12512/// StringFunc - String type conversion function (BigQuery STRING)
12513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12514#[cfg_attr(feature = "bindings", derive(TS))]
12515pub struct StringFunc {
12516    pub this: Box<Expression>,
12517    #[serde(default)]
12518    pub zone: Option<Box<Expression>>,
12519}
12520
12521/// ToNumber
12522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12523#[cfg_attr(feature = "bindings", derive(TS))]
12524pub struct ToNumber {
12525    pub this: Box<Expression>,
12526    #[serde(default)]
12527    pub format: Option<Box<Expression>>,
12528    #[serde(default)]
12529    pub nlsparam: Option<Box<Expression>>,
12530    #[serde(default)]
12531    pub precision: Option<Box<Expression>>,
12532    #[serde(default)]
12533    pub scale: Option<Box<Expression>>,
12534    #[serde(default)]
12535    pub safe: Option<Box<Expression>>,
12536    #[serde(default)]
12537    pub safe_name: Option<Box<Expression>>,
12538}
12539
12540/// ToDouble
12541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12542#[cfg_attr(feature = "bindings", derive(TS))]
12543pub struct ToDouble {
12544    pub this: Box<Expression>,
12545    #[serde(default)]
12546    pub format: Option<String>,
12547    #[serde(default)]
12548    pub safe: Option<Box<Expression>>,
12549}
12550
12551/// ToDecfloat
12552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12553#[cfg_attr(feature = "bindings", derive(TS))]
12554pub struct ToDecfloat {
12555    pub this: Box<Expression>,
12556    #[serde(default)]
12557    pub format: Option<String>,
12558}
12559
12560/// TryToDecfloat
12561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12562#[cfg_attr(feature = "bindings", derive(TS))]
12563pub struct TryToDecfloat {
12564    pub this: Box<Expression>,
12565    #[serde(default)]
12566    pub format: Option<String>,
12567}
12568
12569/// ToFile
12570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12571#[cfg_attr(feature = "bindings", derive(TS))]
12572pub struct ToFile {
12573    pub this: Box<Expression>,
12574    #[serde(default)]
12575    pub path: Option<Box<Expression>>,
12576    #[serde(default)]
12577    pub safe: Option<Box<Expression>>,
12578}
12579
12580/// Columns
12581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12582#[cfg_attr(feature = "bindings", derive(TS))]
12583pub struct Columns {
12584    pub this: Box<Expression>,
12585    #[serde(default)]
12586    pub unpack: Option<Box<Expression>>,
12587}
12588
12589/// ConvertToCharset
12590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12591#[cfg_attr(feature = "bindings", derive(TS))]
12592pub struct ConvertToCharset {
12593    pub this: Box<Expression>,
12594    #[serde(default)]
12595    pub dest: Option<Box<Expression>>,
12596    #[serde(default)]
12597    pub source: Option<Box<Expression>>,
12598}
12599
12600/// ConvertTimezone
12601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12602#[cfg_attr(feature = "bindings", derive(TS))]
12603pub struct ConvertTimezone {
12604    #[serde(default)]
12605    pub source_tz: Option<Box<Expression>>,
12606    #[serde(default)]
12607    pub target_tz: Option<Box<Expression>>,
12608    #[serde(default)]
12609    pub timestamp: Option<Box<Expression>>,
12610    #[serde(default)]
12611    pub options: Vec<Expression>,
12612}
12613
12614/// GenerateSeries
12615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12616#[cfg_attr(feature = "bindings", derive(TS))]
12617pub struct GenerateSeries {
12618    #[serde(default)]
12619    pub start: Option<Box<Expression>>,
12620    #[serde(default)]
12621    pub end: Option<Box<Expression>>,
12622    #[serde(default)]
12623    pub step: Option<Box<Expression>>,
12624    #[serde(default)]
12625    pub is_end_exclusive: Option<Box<Expression>>,
12626}
12627
12628/// AIAgg
12629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12630#[cfg_attr(feature = "bindings", derive(TS))]
12631pub struct AIAgg {
12632    pub this: Box<Expression>,
12633    pub expression: Box<Expression>,
12634}
12635
12636/// AIClassify
12637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12638#[cfg_attr(feature = "bindings", derive(TS))]
12639pub struct AIClassify {
12640    pub this: Box<Expression>,
12641    #[serde(default)]
12642    pub categories: Option<Box<Expression>>,
12643    #[serde(default)]
12644    pub config: Option<Box<Expression>>,
12645}
12646
12647/// ArrayAll
12648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12649#[cfg_attr(feature = "bindings", derive(TS))]
12650pub struct ArrayAll {
12651    pub this: Box<Expression>,
12652    pub expression: Box<Expression>,
12653}
12654
12655/// ArrayAny
12656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12657#[cfg_attr(feature = "bindings", derive(TS))]
12658pub struct ArrayAny {
12659    pub this: Box<Expression>,
12660    pub expression: Box<Expression>,
12661}
12662
12663/// ArrayConstructCompact
12664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12665#[cfg_attr(feature = "bindings", derive(TS))]
12666pub struct ArrayConstructCompact {
12667    #[serde(default)]
12668    pub expressions: Vec<Expression>,
12669}
12670
12671/// StPoint
12672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12673#[cfg_attr(feature = "bindings", derive(TS))]
12674pub struct StPoint {
12675    pub this: Box<Expression>,
12676    pub expression: Box<Expression>,
12677    #[serde(default)]
12678    pub null: Option<Box<Expression>>,
12679}
12680
12681/// StDistance
12682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12683#[cfg_attr(feature = "bindings", derive(TS))]
12684pub struct StDistance {
12685    pub this: Box<Expression>,
12686    pub expression: Box<Expression>,
12687    #[serde(default)]
12688    pub use_spheroid: Option<Box<Expression>>,
12689}
12690
12691/// StringToArray
12692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12693#[cfg_attr(feature = "bindings", derive(TS))]
12694pub struct StringToArray {
12695    pub this: Box<Expression>,
12696    #[serde(default)]
12697    pub expression: Option<Box<Expression>>,
12698    #[serde(default)]
12699    pub null: Option<Box<Expression>>,
12700}
12701
12702/// ArraySum
12703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12704#[cfg_attr(feature = "bindings", derive(TS))]
12705pub struct ArraySum {
12706    pub this: Box<Expression>,
12707    #[serde(default)]
12708    pub expression: Option<Box<Expression>>,
12709}
12710
12711/// ObjectAgg
12712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12713#[cfg_attr(feature = "bindings", derive(TS))]
12714pub struct ObjectAgg {
12715    pub this: Box<Expression>,
12716    pub expression: Box<Expression>,
12717}
12718
12719/// CastToStrType
12720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12721#[cfg_attr(feature = "bindings", derive(TS))]
12722pub struct CastToStrType {
12723    pub this: Box<Expression>,
12724    #[serde(default)]
12725    pub to: Option<Box<Expression>>,
12726}
12727
12728/// CheckJson
12729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12730#[cfg_attr(feature = "bindings", derive(TS))]
12731pub struct CheckJson {
12732    pub this: Box<Expression>,
12733}
12734
12735/// CheckXml
12736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12737#[cfg_attr(feature = "bindings", derive(TS))]
12738pub struct CheckXml {
12739    pub this: Box<Expression>,
12740    #[serde(default)]
12741    pub disable_auto_convert: Option<Box<Expression>>,
12742}
12743
12744/// TranslateCharacters
12745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12746#[cfg_attr(feature = "bindings", derive(TS))]
12747pub struct TranslateCharacters {
12748    pub this: Box<Expression>,
12749    pub expression: Box<Expression>,
12750    #[serde(default)]
12751    pub with_error: Option<Box<Expression>>,
12752}
12753
12754/// CurrentSchemas
12755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12756#[cfg_attr(feature = "bindings", derive(TS))]
12757pub struct CurrentSchemas {
12758    #[serde(default)]
12759    pub this: Option<Box<Expression>>,
12760}
12761
12762/// CurrentDatetime
12763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12764#[cfg_attr(feature = "bindings", derive(TS))]
12765pub struct CurrentDatetime {
12766    #[serde(default)]
12767    pub this: Option<Box<Expression>>,
12768}
12769
12770/// Localtime
12771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12772#[cfg_attr(feature = "bindings", derive(TS))]
12773pub struct Localtime {
12774    #[serde(default)]
12775    pub this: Option<Box<Expression>>,
12776}
12777
12778/// Localtimestamp
12779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12780#[cfg_attr(feature = "bindings", derive(TS))]
12781pub struct Localtimestamp {
12782    #[serde(default)]
12783    pub this: Option<Box<Expression>>,
12784}
12785
12786/// Systimestamp
12787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12788#[cfg_attr(feature = "bindings", derive(TS))]
12789pub struct Systimestamp {
12790    #[serde(default)]
12791    pub this: Option<Box<Expression>>,
12792}
12793
12794/// CurrentSchema
12795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12796#[cfg_attr(feature = "bindings", derive(TS))]
12797pub struct CurrentSchema {
12798    #[serde(default)]
12799    pub this: Option<Box<Expression>>,
12800}
12801
12802/// CurrentUser
12803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12804#[cfg_attr(feature = "bindings", derive(TS))]
12805pub struct CurrentUser {
12806    #[serde(default)]
12807    pub this: Option<Box<Expression>>,
12808}
12809
12810/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12812#[cfg_attr(feature = "bindings", derive(TS))]
12813pub struct SessionUser;
12814
12815/// JSONPathRoot - Represents $ in JSON path expressions
12816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12817#[cfg_attr(feature = "bindings", derive(TS))]
12818pub struct JSONPathRoot;
12819
12820/// UtcTime
12821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12822#[cfg_attr(feature = "bindings", derive(TS))]
12823pub struct UtcTime {
12824    #[serde(default)]
12825    pub this: Option<Box<Expression>>,
12826}
12827
12828/// UtcTimestamp
12829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12830#[cfg_attr(feature = "bindings", derive(TS))]
12831pub struct UtcTimestamp {
12832    #[serde(default)]
12833    pub this: Option<Box<Expression>>,
12834}
12835
12836/// TimestampFunc - TIMESTAMP constructor function
12837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12838#[cfg_attr(feature = "bindings", derive(TS))]
12839pub struct TimestampFunc {
12840    #[serde(default)]
12841    pub this: Option<Box<Expression>>,
12842    #[serde(default)]
12843    pub zone: Option<Box<Expression>>,
12844    #[serde(default)]
12845    pub with_tz: Option<bool>,
12846    #[serde(default)]
12847    pub safe: Option<bool>,
12848}
12849
12850/// DateBin
12851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12852#[cfg_attr(feature = "bindings", derive(TS))]
12853pub struct DateBin {
12854    pub this: Box<Expression>,
12855    pub expression: Box<Expression>,
12856    #[serde(default)]
12857    pub unit: Option<String>,
12858    #[serde(default)]
12859    pub zone: Option<Box<Expression>>,
12860    #[serde(default)]
12861    pub origin: Option<Box<Expression>>,
12862}
12863
12864/// Datetime
12865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12866#[cfg_attr(feature = "bindings", derive(TS))]
12867pub struct Datetime {
12868    pub this: Box<Expression>,
12869    #[serde(default)]
12870    pub expression: Option<Box<Expression>>,
12871}
12872
12873/// DatetimeAdd
12874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12875#[cfg_attr(feature = "bindings", derive(TS))]
12876pub struct DatetimeAdd {
12877    pub this: Box<Expression>,
12878    pub expression: Box<Expression>,
12879    #[serde(default)]
12880    pub unit: Option<String>,
12881}
12882
12883/// DatetimeSub
12884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12885#[cfg_attr(feature = "bindings", derive(TS))]
12886pub struct DatetimeSub {
12887    pub this: Box<Expression>,
12888    pub expression: Box<Expression>,
12889    #[serde(default)]
12890    pub unit: Option<String>,
12891}
12892
12893/// DatetimeDiff
12894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12895#[cfg_attr(feature = "bindings", derive(TS))]
12896pub struct DatetimeDiff {
12897    pub this: Box<Expression>,
12898    pub expression: Box<Expression>,
12899    #[serde(default)]
12900    pub unit: Option<String>,
12901}
12902
12903/// DatetimeTrunc
12904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12905#[cfg_attr(feature = "bindings", derive(TS))]
12906pub struct DatetimeTrunc {
12907    pub this: Box<Expression>,
12908    pub unit: String,
12909    #[serde(default)]
12910    pub zone: Option<Box<Expression>>,
12911}
12912
12913/// Dayname
12914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12915#[cfg_attr(feature = "bindings", derive(TS))]
12916pub struct Dayname {
12917    pub this: Box<Expression>,
12918    #[serde(default)]
12919    pub abbreviated: Option<Box<Expression>>,
12920}
12921
12922/// MakeInterval
12923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12924#[cfg_attr(feature = "bindings", derive(TS))]
12925pub struct MakeInterval {
12926    #[serde(default)]
12927    pub year: Option<Box<Expression>>,
12928    #[serde(default)]
12929    pub month: Option<Box<Expression>>,
12930    #[serde(default)]
12931    pub week: Option<Box<Expression>>,
12932    #[serde(default)]
12933    pub day: Option<Box<Expression>>,
12934    #[serde(default)]
12935    pub hour: Option<Box<Expression>>,
12936    #[serde(default)]
12937    pub minute: Option<Box<Expression>>,
12938    #[serde(default)]
12939    pub second: Option<Box<Expression>>,
12940}
12941
12942/// PreviousDay
12943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12944#[cfg_attr(feature = "bindings", derive(TS))]
12945pub struct PreviousDay {
12946    pub this: Box<Expression>,
12947    pub expression: Box<Expression>,
12948}
12949
12950/// Elt
12951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12952#[cfg_attr(feature = "bindings", derive(TS))]
12953pub struct Elt {
12954    pub this: Box<Expression>,
12955    #[serde(default)]
12956    pub expressions: Vec<Expression>,
12957}
12958
12959/// TimestampAdd
12960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12961#[cfg_attr(feature = "bindings", derive(TS))]
12962pub struct TimestampAdd {
12963    pub this: Box<Expression>,
12964    pub expression: Box<Expression>,
12965    #[serde(default)]
12966    pub unit: Option<String>,
12967}
12968
12969/// TimestampSub
12970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12971#[cfg_attr(feature = "bindings", derive(TS))]
12972pub struct TimestampSub {
12973    pub this: Box<Expression>,
12974    pub expression: Box<Expression>,
12975    #[serde(default)]
12976    pub unit: Option<String>,
12977}
12978
12979/// TimestampDiff
12980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12981#[cfg_attr(feature = "bindings", derive(TS))]
12982pub struct TimestampDiff {
12983    pub this: Box<Expression>,
12984    pub expression: Box<Expression>,
12985    #[serde(default)]
12986    pub unit: Option<String>,
12987}
12988
12989/// TimeSlice
12990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12991#[cfg_attr(feature = "bindings", derive(TS))]
12992pub struct TimeSlice {
12993    pub this: Box<Expression>,
12994    pub expression: Box<Expression>,
12995    pub unit: String,
12996    #[serde(default)]
12997    pub kind: Option<String>,
12998}
12999
13000/// TimeAdd
13001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13002#[cfg_attr(feature = "bindings", derive(TS))]
13003pub struct TimeAdd {
13004    pub this: Box<Expression>,
13005    pub expression: Box<Expression>,
13006    #[serde(default)]
13007    pub unit: Option<String>,
13008}
13009
13010/// TimeSub
13011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13012#[cfg_attr(feature = "bindings", derive(TS))]
13013pub struct TimeSub {
13014    pub this: Box<Expression>,
13015    pub expression: Box<Expression>,
13016    #[serde(default)]
13017    pub unit: Option<String>,
13018}
13019
13020/// TimeDiff
13021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13022#[cfg_attr(feature = "bindings", derive(TS))]
13023pub struct TimeDiff {
13024    pub this: Box<Expression>,
13025    pub expression: Box<Expression>,
13026    #[serde(default)]
13027    pub unit: Option<String>,
13028}
13029
13030/// TimeTrunc
13031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13032#[cfg_attr(feature = "bindings", derive(TS))]
13033pub struct TimeTrunc {
13034    pub this: Box<Expression>,
13035    pub unit: String,
13036    #[serde(default)]
13037    pub zone: Option<Box<Expression>>,
13038}
13039
13040/// DateFromParts
13041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13042#[cfg_attr(feature = "bindings", derive(TS))]
13043pub struct DateFromParts {
13044    #[serde(default)]
13045    pub year: Option<Box<Expression>>,
13046    #[serde(default)]
13047    pub month: Option<Box<Expression>>,
13048    #[serde(default)]
13049    pub day: Option<Box<Expression>>,
13050    #[serde(default)]
13051    pub allow_overflow: Option<Box<Expression>>,
13052}
13053
13054/// TimeFromParts
13055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13056#[cfg_attr(feature = "bindings", derive(TS))]
13057pub struct TimeFromParts {
13058    #[serde(default)]
13059    pub hour: Option<Box<Expression>>,
13060    #[serde(default)]
13061    pub min: Option<Box<Expression>>,
13062    #[serde(default)]
13063    pub sec: Option<Box<Expression>>,
13064    #[serde(default)]
13065    pub nano: Option<Box<Expression>>,
13066    #[serde(default)]
13067    pub fractions: Option<Box<Expression>>,
13068    #[serde(default)]
13069    pub precision: Option<i64>,
13070}
13071
13072/// DecodeCase
13073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13074#[cfg_attr(feature = "bindings", derive(TS))]
13075pub struct DecodeCase {
13076    #[serde(default)]
13077    pub expressions: Vec<Expression>,
13078}
13079
13080/// Decrypt
13081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13082#[cfg_attr(feature = "bindings", derive(TS))]
13083pub struct Decrypt {
13084    pub this: Box<Expression>,
13085    #[serde(default)]
13086    pub passphrase: Option<Box<Expression>>,
13087    #[serde(default)]
13088    pub aad: Option<Box<Expression>>,
13089    #[serde(default)]
13090    pub encryption_method: Option<Box<Expression>>,
13091    #[serde(default)]
13092    pub safe: Option<Box<Expression>>,
13093}
13094
13095/// DecryptRaw
13096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13097#[cfg_attr(feature = "bindings", derive(TS))]
13098pub struct DecryptRaw {
13099    pub this: Box<Expression>,
13100    #[serde(default)]
13101    pub key: Option<Box<Expression>>,
13102    #[serde(default)]
13103    pub iv: Option<Box<Expression>>,
13104    #[serde(default)]
13105    pub aad: Option<Box<Expression>>,
13106    #[serde(default)]
13107    pub encryption_method: Option<Box<Expression>>,
13108    #[serde(default)]
13109    pub aead: Option<Box<Expression>>,
13110    #[serde(default)]
13111    pub safe: Option<Box<Expression>>,
13112}
13113
13114/// Encode
13115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13116#[cfg_attr(feature = "bindings", derive(TS))]
13117pub struct Encode {
13118    pub this: Box<Expression>,
13119    #[serde(default)]
13120    pub charset: Option<Box<Expression>>,
13121}
13122
13123/// Encrypt
13124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13125#[cfg_attr(feature = "bindings", derive(TS))]
13126pub struct Encrypt {
13127    pub this: Box<Expression>,
13128    #[serde(default)]
13129    pub passphrase: Option<Box<Expression>>,
13130    #[serde(default)]
13131    pub aad: Option<Box<Expression>>,
13132    #[serde(default)]
13133    pub encryption_method: Option<Box<Expression>>,
13134}
13135
13136/// EncryptRaw
13137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13138#[cfg_attr(feature = "bindings", derive(TS))]
13139pub struct EncryptRaw {
13140    pub this: Box<Expression>,
13141    #[serde(default)]
13142    pub key: Option<Box<Expression>>,
13143    #[serde(default)]
13144    pub iv: Option<Box<Expression>>,
13145    #[serde(default)]
13146    pub aad: Option<Box<Expression>>,
13147    #[serde(default)]
13148    pub encryption_method: Option<Box<Expression>>,
13149}
13150
13151/// EqualNull
13152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13153#[cfg_attr(feature = "bindings", derive(TS))]
13154pub struct EqualNull {
13155    pub this: Box<Expression>,
13156    pub expression: Box<Expression>,
13157}
13158
13159/// ToBinary
13160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13161#[cfg_attr(feature = "bindings", derive(TS))]
13162pub struct ToBinary {
13163    pub this: Box<Expression>,
13164    #[serde(default)]
13165    pub format: Option<String>,
13166    #[serde(default)]
13167    pub safe: Option<Box<Expression>>,
13168}
13169
13170/// Base64DecodeBinary
13171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13172#[cfg_attr(feature = "bindings", derive(TS))]
13173pub struct Base64DecodeBinary {
13174    pub this: Box<Expression>,
13175    #[serde(default)]
13176    pub alphabet: Option<Box<Expression>>,
13177}
13178
13179/// Base64DecodeString
13180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13181#[cfg_attr(feature = "bindings", derive(TS))]
13182pub struct Base64DecodeString {
13183    pub this: Box<Expression>,
13184    #[serde(default)]
13185    pub alphabet: Option<Box<Expression>>,
13186}
13187
13188/// Base64Encode
13189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13190#[cfg_attr(feature = "bindings", derive(TS))]
13191pub struct Base64Encode {
13192    pub this: Box<Expression>,
13193    #[serde(default)]
13194    pub max_line_length: Option<Box<Expression>>,
13195    #[serde(default)]
13196    pub alphabet: Option<Box<Expression>>,
13197}
13198
13199/// TryBase64DecodeBinary
13200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13201#[cfg_attr(feature = "bindings", derive(TS))]
13202pub struct TryBase64DecodeBinary {
13203    pub this: Box<Expression>,
13204    #[serde(default)]
13205    pub alphabet: Option<Box<Expression>>,
13206}
13207
13208/// TryBase64DecodeString
13209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13210#[cfg_attr(feature = "bindings", derive(TS))]
13211pub struct TryBase64DecodeString {
13212    pub this: Box<Expression>,
13213    #[serde(default)]
13214    pub alphabet: Option<Box<Expression>>,
13215}
13216
13217/// GapFill
13218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13219#[cfg_attr(feature = "bindings", derive(TS))]
13220pub struct GapFill {
13221    pub this: Box<Expression>,
13222    #[serde(default)]
13223    pub ts_column: Option<Box<Expression>>,
13224    #[serde(default)]
13225    pub bucket_width: Option<Box<Expression>>,
13226    #[serde(default)]
13227    pub partitioning_columns: Option<Box<Expression>>,
13228    #[serde(default)]
13229    pub value_columns: Option<Box<Expression>>,
13230    #[serde(default)]
13231    pub origin: Option<Box<Expression>>,
13232    #[serde(default)]
13233    pub ignore_nulls: Option<Box<Expression>>,
13234}
13235
13236/// GenerateDateArray
13237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13238#[cfg_attr(feature = "bindings", derive(TS))]
13239pub struct GenerateDateArray {
13240    #[serde(default)]
13241    pub start: Option<Box<Expression>>,
13242    #[serde(default)]
13243    pub end: Option<Box<Expression>>,
13244    #[serde(default)]
13245    pub step: Option<Box<Expression>>,
13246}
13247
13248/// GenerateTimestampArray
13249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13250#[cfg_attr(feature = "bindings", derive(TS))]
13251pub struct GenerateTimestampArray {
13252    #[serde(default)]
13253    pub start: Option<Box<Expression>>,
13254    #[serde(default)]
13255    pub end: Option<Box<Expression>>,
13256    #[serde(default)]
13257    pub step: Option<Box<Expression>>,
13258}
13259
13260/// GetExtract
13261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13262#[cfg_attr(feature = "bindings", derive(TS))]
13263pub struct GetExtract {
13264    pub this: Box<Expression>,
13265    pub expression: Box<Expression>,
13266}
13267
13268/// Getbit
13269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13270#[cfg_attr(feature = "bindings", derive(TS))]
13271pub struct Getbit {
13272    pub this: Box<Expression>,
13273    pub expression: Box<Expression>,
13274    #[serde(default)]
13275    pub zero_is_msb: Option<Box<Expression>>,
13276}
13277
13278/// OverflowTruncateBehavior
13279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13280#[cfg_attr(feature = "bindings", derive(TS))]
13281pub struct OverflowTruncateBehavior {
13282    #[serde(default)]
13283    pub this: Option<Box<Expression>>,
13284    #[serde(default)]
13285    pub with_count: Option<Box<Expression>>,
13286}
13287
13288/// HexEncode
13289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13290#[cfg_attr(feature = "bindings", derive(TS))]
13291pub struct HexEncode {
13292    pub this: Box<Expression>,
13293    #[serde(default)]
13294    pub case: Option<Box<Expression>>,
13295}
13296
13297/// Compress
13298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13299#[cfg_attr(feature = "bindings", derive(TS))]
13300pub struct Compress {
13301    pub this: Box<Expression>,
13302    #[serde(default)]
13303    pub method: Option<String>,
13304}
13305
13306/// DecompressBinary
13307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13308#[cfg_attr(feature = "bindings", derive(TS))]
13309pub struct DecompressBinary {
13310    pub this: Box<Expression>,
13311    pub method: String,
13312}
13313
13314/// DecompressString
13315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13316#[cfg_attr(feature = "bindings", derive(TS))]
13317pub struct DecompressString {
13318    pub this: Box<Expression>,
13319    pub method: String,
13320}
13321
13322/// Xor
13323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13324#[cfg_attr(feature = "bindings", derive(TS))]
13325pub struct Xor {
13326    #[serde(default)]
13327    pub this: Option<Box<Expression>>,
13328    #[serde(default)]
13329    pub expression: Option<Box<Expression>>,
13330    #[serde(default)]
13331    pub expressions: Vec<Expression>,
13332}
13333
13334/// Nullif
13335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13336#[cfg_attr(feature = "bindings", derive(TS))]
13337pub struct Nullif {
13338    pub this: Box<Expression>,
13339    pub expression: Box<Expression>,
13340}
13341
13342/// JSON
13343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13344#[cfg_attr(feature = "bindings", derive(TS))]
13345pub struct JSON {
13346    #[serde(default)]
13347    pub this: Option<Box<Expression>>,
13348    #[serde(default)]
13349    pub with_: Option<Box<Expression>>,
13350    #[serde(default)]
13351    pub unique: bool,
13352}
13353
13354/// JSONPath
13355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13356#[cfg_attr(feature = "bindings", derive(TS))]
13357pub struct JSONPath {
13358    #[serde(default)]
13359    pub expressions: Vec<Expression>,
13360    #[serde(default)]
13361    pub escape: Option<Box<Expression>>,
13362}
13363
13364/// JSONPathFilter
13365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13366#[cfg_attr(feature = "bindings", derive(TS))]
13367pub struct JSONPathFilter {
13368    pub this: Box<Expression>,
13369}
13370
13371/// JSONPathKey
13372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13373#[cfg_attr(feature = "bindings", derive(TS))]
13374pub struct JSONPathKey {
13375    pub this: Box<Expression>,
13376}
13377
13378/// JSONPathRecursive
13379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13380#[cfg_attr(feature = "bindings", derive(TS))]
13381pub struct JSONPathRecursive {
13382    #[serde(default)]
13383    pub this: Option<Box<Expression>>,
13384}
13385
13386/// JSONPathScript
13387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13388#[cfg_attr(feature = "bindings", derive(TS))]
13389pub struct JSONPathScript {
13390    pub this: Box<Expression>,
13391}
13392
13393/// JSONPathSlice
13394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13395#[cfg_attr(feature = "bindings", derive(TS))]
13396pub struct JSONPathSlice {
13397    #[serde(default)]
13398    pub start: Option<Box<Expression>>,
13399    #[serde(default)]
13400    pub end: Option<Box<Expression>>,
13401    #[serde(default)]
13402    pub step: Option<Box<Expression>>,
13403}
13404
13405/// JSONPathSelector
13406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13407#[cfg_attr(feature = "bindings", derive(TS))]
13408pub struct JSONPathSelector {
13409    pub this: Box<Expression>,
13410}
13411
13412/// JSONPathSubscript
13413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13414#[cfg_attr(feature = "bindings", derive(TS))]
13415pub struct JSONPathSubscript {
13416    pub this: Box<Expression>,
13417}
13418
13419/// JSONPathUnion
13420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13421#[cfg_attr(feature = "bindings", derive(TS))]
13422pub struct JSONPathUnion {
13423    #[serde(default)]
13424    pub expressions: Vec<Expression>,
13425}
13426
13427/// Format
13428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13429#[cfg_attr(feature = "bindings", derive(TS))]
13430pub struct Format {
13431    pub this: Box<Expression>,
13432    #[serde(default)]
13433    pub expressions: Vec<Expression>,
13434}
13435
13436/// JSONKeys
13437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13438#[cfg_attr(feature = "bindings", derive(TS))]
13439pub struct JSONKeys {
13440    pub this: Box<Expression>,
13441    #[serde(default)]
13442    pub expression: Option<Box<Expression>>,
13443    #[serde(default)]
13444    pub expressions: Vec<Expression>,
13445}
13446
13447/// JSONKeyValue
13448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13449#[cfg_attr(feature = "bindings", derive(TS))]
13450pub struct JSONKeyValue {
13451    pub this: Box<Expression>,
13452    pub expression: Box<Expression>,
13453}
13454
13455/// JSONKeysAtDepth
13456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13457#[cfg_attr(feature = "bindings", derive(TS))]
13458pub struct JSONKeysAtDepth {
13459    pub this: Box<Expression>,
13460    #[serde(default)]
13461    pub expression: Option<Box<Expression>>,
13462    #[serde(default)]
13463    pub mode: Option<Box<Expression>>,
13464}
13465
13466/// JSONObject
13467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13468#[cfg_attr(feature = "bindings", derive(TS))]
13469pub struct JSONObject {
13470    #[serde(default)]
13471    pub expressions: Vec<Expression>,
13472    #[serde(default)]
13473    pub null_handling: Option<Box<Expression>>,
13474    #[serde(default)]
13475    pub unique_keys: Option<Box<Expression>>,
13476    #[serde(default)]
13477    pub return_type: Option<Box<Expression>>,
13478    #[serde(default)]
13479    pub encoding: Option<Box<Expression>>,
13480}
13481
13482/// JSONObjectAgg
13483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13484#[cfg_attr(feature = "bindings", derive(TS))]
13485pub struct JSONObjectAgg {
13486    #[serde(default)]
13487    pub expressions: Vec<Expression>,
13488    #[serde(default)]
13489    pub null_handling: Option<Box<Expression>>,
13490    #[serde(default)]
13491    pub unique_keys: Option<Box<Expression>>,
13492    #[serde(default)]
13493    pub return_type: Option<Box<Expression>>,
13494    #[serde(default)]
13495    pub encoding: Option<Box<Expression>>,
13496}
13497
13498/// JSONBObjectAgg
13499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13500#[cfg_attr(feature = "bindings", derive(TS))]
13501pub struct JSONBObjectAgg {
13502    pub this: Box<Expression>,
13503    pub expression: Box<Expression>,
13504}
13505
13506/// JSONArray
13507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13508#[cfg_attr(feature = "bindings", derive(TS))]
13509pub struct JSONArray {
13510    #[serde(default)]
13511    pub expressions: Vec<Expression>,
13512    #[serde(default)]
13513    pub null_handling: Option<Box<Expression>>,
13514    #[serde(default)]
13515    pub return_type: Option<Box<Expression>>,
13516    #[serde(default)]
13517    pub strict: Option<Box<Expression>>,
13518}
13519
13520/// JSONArrayAgg
13521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13522#[cfg_attr(feature = "bindings", derive(TS))]
13523pub struct JSONArrayAgg {
13524    pub this: Box<Expression>,
13525    #[serde(default)]
13526    pub order: Option<Box<Expression>>,
13527    #[serde(default)]
13528    pub null_handling: Option<Box<Expression>>,
13529    #[serde(default)]
13530    pub return_type: Option<Box<Expression>>,
13531    #[serde(default)]
13532    pub strict: Option<Box<Expression>>,
13533}
13534
13535/// JSONExists
13536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13537#[cfg_attr(feature = "bindings", derive(TS))]
13538pub struct JSONExists {
13539    pub this: Box<Expression>,
13540    #[serde(default)]
13541    pub path: Option<Box<Expression>>,
13542    #[serde(default)]
13543    pub passing: Option<Box<Expression>>,
13544    #[serde(default)]
13545    pub on_condition: Option<Box<Expression>>,
13546    #[serde(default)]
13547    pub from_dcolonqmark: Option<Box<Expression>>,
13548}
13549
13550/// JSONColumnDef
13551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13552#[cfg_attr(feature = "bindings", derive(TS))]
13553pub struct JSONColumnDef {
13554    #[serde(default)]
13555    pub this: Option<Box<Expression>>,
13556    #[serde(default)]
13557    pub kind: Option<String>,
13558    #[serde(default)]
13559    pub path: Option<Box<Expression>>,
13560    #[serde(default)]
13561    pub nested_schema: Option<Box<Expression>>,
13562    #[serde(default)]
13563    pub ordinality: Option<Box<Expression>>,
13564}
13565
13566/// JSONSchema
13567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13568#[cfg_attr(feature = "bindings", derive(TS))]
13569pub struct JSONSchema {
13570    #[serde(default)]
13571    pub expressions: Vec<Expression>,
13572}
13573
13574/// JSONSet
13575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13576#[cfg_attr(feature = "bindings", derive(TS))]
13577pub struct JSONSet {
13578    pub this: Box<Expression>,
13579    #[serde(default)]
13580    pub expressions: Vec<Expression>,
13581}
13582
13583/// JSONStripNulls
13584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13585#[cfg_attr(feature = "bindings", derive(TS))]
13586pub struct JSONStripNulls {
13587    pub this: Box<Expression>,
13588    #[serde(default)]
13589    pub expression: Option<Box<Expression>>,
13590    #[serde(default)]
13591    pub include_arrays: Option<Box<Expression>>,
13592    #[serde(default)]
13593    pub remove_empty: Option<Box<Expression>>,
13594}
13595
13596/// JSONValue
13597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13598#[cfg_attr(feature = "bindings", derive(TS))]
13599pub struct JSONValue {
13600    pub this: Box<Expression>,
13601    #[serde(default)]
13602    pub path: Option<Box<Expression>>,
13603    #[serde(default)]
13604    pub returning: Option<Box<Expression>>,
13605    #[serde(default)]
13606    pub on_condition: Option<Box<Expression>>,
13607}
13608
13609/// JSONValueArray
13610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13611#[cfg_attr(feature = "bindings", derive(TS))]
13612pub struct JSONValueArray {
13613    pub this: Box<Expression>,
13614    #[serde(default)]
13615    pub expression: Option<Box<Expression>>,
13616}
13617
13618/// JSONRemove
13619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13620#[cfg_attr(feature = "bindings", derive(TS))]
13621pub struct JSONRemove {
13622    pub this: Box<Expression>,
13623    #[serde(default)]
13624    pub expressions: Vec<Expression>,
13625}
13626
13627/// JSONTable
13628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13629#[cfg_attr(feature = "bindings", derive(TS))]
13630pub struct JSONTable {
13631    pub this: Box<Expression>,
13632    #[serde(default)]
13633    pub schema: Option<Box<Expression>>,
13634    #[serde(default)]
13635    pub path: Option<Box<Expression>>,
13636    #[serde(default)]
13637    pub error_handling: Option<Box<Expression>>,
13638    #[serde(default)]
13639    pub empty_handling: Option<Box<Expression>>,
13640}
13641
13642/// JSONType
13643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13644#[cfg_attr(feature = "bindings", derive(TS))]
13645pub struct JSONType {
13646    pub this: Box<Expression>,
13647    #[serde(default)]
13648    pub expression: Option<Box<Expression>>,
13649}
13650
13651/// ObjectInsert
13652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13653#[cfg_attr(feature = "bindings", derive(TS))]
13654pub struct ObjectInsert {
13655    pub this: Box<Expression>,
13656    #[serde(default)]
13657    pub key: Option<Box<Expression>>,
13658    #[serde(default)]
13659    pub value: Option<Box<Expression>>,
13660    #[serde(default)]
13661    pub update_flag: Option<Box<Expression>>,
13662}
13663
13664/// OpenJSONColumnDef
13665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13666#[cfg_attr(feature = "bindings", derive(TS))]
13667pub struct OpenJSONColumnDef {
13668    pub this: Box<Expression>,
13669    pub kind: String,
13670    #[serde(default)]
13671    pub path: Option<Box<Expression>>,
13672    #[serde(default)]
13673    pub as_json: Option<Box<Expression>>,
13674    /// The parsed data type for proper generation
13675    #[serde(default, skip_serializing_if = "Option::is_none")]
13676    pub data_type: Option<DataType>,
13677}
13678
13679/// OpenJSON
13680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13681#[cfg_attr(feature = "bindings", derive(TS))]
13682pub struct OpenJSON {
13683    pub this: Box<Expression>,
13684    #[serde(default)]
13685    pub path: Option<Box<Expression>>,
13686    #[serde(default)]
13687    pub expressions: Vec<Expression>,
13688}
13689
13690/// JSONBExists
13691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13692#[cfg_attr(feature = "bindings", derive(TS))]
13693pub struct JSONBExists {
13694    pub this: Box<Expression>,
13695    #[serde(default)]
13696    pub path: Option<Box<Expression>>,
13697}
13698
13699/// JSONCast
13700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13701#[cfg_attr(feature = "bindings", derive(TS))]
13702pub struct JSONCast {
13703    pub this: Box<Expression>,
13704    pub to: DataType,
13705}
13706
13707/// JSONExtract
13708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13709#[cfg_attr(feature = "bindings", derive(TS))]
13710pub struct JSONExtract {
13711    pub this: Box<Expression>,
13712    pub expression: Box<Expression>,
13713    #[serde(default)]
13714    pub only_json_types: Option<Box<Expression>>,
13715    #[serde(default)]
13716    pub expressions: Vec<Expression>,
13717    #[serde(default)]
13718    pub variant_extract: Option<Box<Expression>>,
13719    #[serde(default)]
13720    pub json_query: Option<Box<Expression>>,
13721    #[serde(default)]
13722    pub option: Option<Box<Expression>>,
13723    #[serde(default)]
13724    pub quote: Option<Box<Expression>>,
13725    #[serde(default)]
13726    pub on_condition: Option<Box<Expression>>,
13727    #[serde(default)]
13728    pub requires_json: Option<Box<Expression>>,
13729}
13730
13731/// JSONExtractQuote
13732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13733#[cfg_attr(feature = "bindings", derive(TS))]
13734pub struct JSONExtractQuote {
13735    #[serde(default)]
13736    pub option: Option<Box<Expression>>,
13737    #[serde(default)]
13738    pub scalar: Option<Box<Expression>>,
13739}
13740
13741/// JSONExtractArray
13742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13743#[cfg_attr(feature = "bindings", derive(TS))]
13744pub struct JSONExtractArray {
13745    pub this: Box<Expression>,
13746    #[serde(default)]
13747    pub expression: Option<Box<Expression>>,
13748}
13749
13750/// JSONExtractScalar
13751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13752#[cfg_attr(feature = "bindings", derive(TS))]
13753pub struct JSONExtractScalar {
13754    pub this: Box<Expression>,
13755    pub expression: Box<Expression>,
13756    #[serde(default)]
13757    pub only_json_types: Option<Box<Expression>>,
13758    #[serde(default)]
13759    pub expressions: Vec<Expression>,
13760    #[serde(default)]
13761    pub json_type: Option<Box<Expression>>,
13762    #[serde(default)]
13763    pub scalar_only: Option<Box<Expression>>,
13764}
13765
13766/// JSONBExtractScalar
13767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13768#[cfg_attr(feature = "bindings", derive(TS))]
13769pub struct JSONBExtractScalar {
13770    pub this: Box<Expression>,
13771    pub expression: Box<Expression>,
13772    #[serde(default)]
13773    pub json_type: Option<Box<Expression>>,
13774}
13775
13776/// JSONFormat
13777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13778#[cfg_attr(feature = "bindings", derive(TS))]
13779pub struct JSONFormat {
13780    #[serde(default)]
13781    pub this: Option<Box<Expression>>,
13782    #[serde(default)]
13783    pub options: Vec<Expression>,
13784    #[serde(default)]
13785    pub is_json: Option<Box<Expression>>,
13786    #[serde(default)]
13787    pub to_json: Option<Box<Expression>>,
13788}
13789
13790/// JSONArrayAppend
13791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13792#[cfg_attr(feature = "bindings", derive(TS))]
13793pub struct JSONArrayAppend {
13794    pub this: Box<Expression>,
13795    #[serde(default)]
13796    pub expressions: Vec<Expression>,
13797}
13798
13799/// JSONArrayContains
13800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13801#[cfg_attr(feature = "bindings", derive(TS))]
13802pub struct JSONArrayContains {
13803    pub this: Box<Expression>,
13804    pub expression: Box<Expression>,
13805    #[serde(default)]
13806    pub json_type: Option<Box<Expression>>,
13807}
13808
13809/// JSONArrayInsert
13810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13811#[cfg_attr(feature = "bindings", derive(TS))]
13812pub struct JSONArrayInsert {
13813    pub this: Box<Expression>,
13814    #[serde(default)]
13815    pub expressions: Vec<Expression>,
13816}
13817
13818/// ParseJSON
13819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13820#[cfg_attr(feature = "bindings", derive(TS))]
13821pub struct ParseJSON {
13822    pub this: Box<Expression>,
13823    #[serde(default)]
13824    pub expression: Option<Box<Expression>>,
13825    #[serde(default)]
13826    pub safe: Option<Box<Expression>>,
13827}
13828
13829/// ParseUrl
13830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13831#[cfg_attr(feature = "bindings", derive(TS))]
13832pub struct ParseUrl {
13833    pub this: Box<Expression>,
13834    #[serde(default)]
13835    pub part_to_extract: Option<Box<Expression>>,
13836    #[serde(default)]
13837    pub key: Option<Box<Expression>>,
13838    #[serde(default)]
13839    pub permissive: Option<Box<Expression>>,
13840}
13841
13842/// ParseIp
13843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13844#[cfg_attr(feature = "bindings", derive(TS))]
13845pub struct ParseIp {
13846    pub this: Box<Expression>,
13847    #[serde(default)]
13848    pub type_: Option<Box<Expression>>,
13849    #[serde(default)]
13850    pub permissive: Option<Box<Expression>>,
13851}
13852
13853/// ParseTime
13854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13855#[cfg_attr(feature = "bindings", derive(TS))]
13856pub struct ParseTime {
13857    pub this: Box<Expression>,
13858    pub format: String,
13859}
13860
13861/// ParseDatetime
13862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13863#[cfg_attr(feature = "bindings", derive(TS))]
13864pub struct ParseDatetime {
13865    pub this: Box<Expression>,
13866    #[serde(default)]
13867    pub format: Option<String>,
13868    #[serde(default)]
13869    pub zone: Option<Box<Expression>>,
13870}
13871
13872/// Map
13873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13874#[cfg_attr(feature = "bindings", derive(TS))]
13875pub struct Map {
13876    #[serde(default)]
13877    pub keys: Vec<Expression>,
13878    #[serde(default)]
13879    pub values: Vec<Expression>,
13880}
13881
13882/// MapCat
13883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13884#[cfg_attr(feature = "bindings", derive(TS))]
13885pub struct MapCat {
13886    pub this: Box<Expression>,
13887    pub expression: Box<Expression>,
13888}
13889
13890/// MapDelete
13891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13892#[cfg_attr(feature = "bindings", derive(TS))]
13893pub struct MapDelete {
13894    pub this: Box<Expression>,
13895    #[serde(default)]
13896    pub expressions: Vec<Expression>,
13897}
13898
13899/// MapInsert
13900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13901#[cfg_attr(feature = "bindings", derive(TS))]
13902pub struct MapInsert {
13903    pub this: Box<Expression>,
13904    #[serde(default)]
13905    pub key: Option<Box<Expression>>,
13906    #[serde(default)]
13907    pub value: Option<Box<Expression>>,
13908    #[serde(default)]
13909    pub update_flag: Option<Box<Expression>>,
13910}
13911
13912/// MapPick
13913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13914#[cfg_attr(feature = "bindings", derive(TS))]
13915pub struct MapPick {
13916    pub this: Box<Expression>,
13917    #[serde(default)]
13918    pub expressions: Vec<Expression>,
13919}
13920
13921/// ScopeResolution
13922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13923#[cfg_attr(feature = "bindings", derive(TS))]
13924pub struct ScopeResolution {
13925    #[serde(default)]
13926    pub this: Option<Box<Expression>>,
13927    pub expression: Box<Expression>,
13928}
13929
13930/// Slice
13931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13932#[cfg_attr(feature = "bindings", derive(TS))]
13933pub struct Slice {
13934    #[serde(default)]
13935    pub this: Option<Box<Expression>>,
13936    #[serde(default)]
13937    pub expression: Option<Box<Expression>>,
13938    #[serde(default)]
13939    pub step: Option<Box<Expression>>,
13940}
13941
13942/// VarMap
13943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13944#[cfg_attr(feature = "bindings", derive(TS))]
13945pub struct VarMap {
13946    #[serde(default)]
13947    pub keys: Vec<Expression>,
13948    #[serde(default)]
13949    pub values: Vec<Expression>,
13950}
13951
13952/// MatchAgainst
13953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13954#[cfg_attr(feature = "bindings", derive(TS))]
13955pub struct MatchAgainst {
13956    pub this: Box<Expression>,
13957    #[serde(default)]
13958    pub expressions: Vec<Expression>,
13959    #[serde(default)]
13960    pub modifier: Option<Box<Expression>>,
13961}
13962
13963/// MD5Digest
13964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13965#[cfg_attr(feature = "bindings", derive(TS))]
13966pub struct MD5Digest {
13967    pub this: Box<Expression>,
13968    #[serde(default)]
13969    pub expressions: Vec<Expression>,
13970}
13971
13972/// Monthname
13973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13974#[cfg_attr(feature = "bindings", derive(TS))]
13975pub struct Monthname {
13976    pub this: Box<Expression>,
13977    #[serde(default)]
13978    pub abbreviated: Option<Box<Expression>>,
13979}
13980
13981/// Ntile
13982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13983#[cfg_attr(feature = "bindings", derive(TS))]
13984pub struct Ntile {
13985    #[serde(default)]
13986    pub this: Option<Box<Expression>>,
13987}
13988
13989/// Normalize
13990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13991#[cfg_attr(feature = "bindings", derive(TS))]
13992pub struct Normalize {
13993    pub this: Box<Expression>,
13994    #[serde(default)]
13995    pub form: Option<Box<Expression>>,
13996    #[serde(default)]
13997    pub is_casefold: Option<Box<Expression>>,
13998}
13999
14000/// Normal
14001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14002#[cfg_attr(feature = "bindings", derive(TS))]
14003pub struct Normal {
14004    pub this: Box<Expression>,
14005    #[serde(default)]
14006    pub stddev: Option<Box<Expression>>,
14007    #[serde(default)]
14008    pub gen: Option<Box<Expression>>,
14009}
14010
14011/// Predict
14012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14013#[cfg_attr(feature = "bindings", derive(TS))]
14014pub struct Predict {
14015    pub this: Box<Expression>,
14016    pub expression: Box<Expression>,
14017    #[serde(default)]
14018    pub params_struct: Option<Box<Expression>>,
14019}
14020
14021/// MLTranslate
14022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14023#[cfg_attr(feature = "bindings", derive(TS))]
14024pub struct MLTranslate {
14025    pub this: Box<Expression>,
14026    pub expression: Box<Expression>,
14027    #[serde(default)]
14028    pub params_struct: Option<Box<Expression>>,
14029}
14030
14031/// FeaturesAtTime
14032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14033#[cfg_attr(feature = "bindings", derive(TS))]
14034pub struct FeaturesAtTime {
14035    pub this: Box<Expression>,
14036    #[serde(default)]
14037    pub time: Option<Box<Expression>>,
14038    #[serde(default)]
14039    pub num_rows: Option<Box<Expression>>,
14040    #[serde(default)]
14041    pub ignore_feature_nulls: Option<Box<Expression>>,
14042}
14043
14044/// GenerateEmbedding
14045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14046#[cfg_attr(feature = "bindings", derive(TS))]
14047pub struct GenerateEmbedding {
14048    pub this: Box<Expression>,
14049    pub expression: Box<Expression>,
14050    #[serde(default)]
14051    pub params_struct: Option<Box<Expression>>,
14052    #[serde(default)]
14053    pub is_text: Option<Box<Expression>>,
14054}
14055
14056/// MLForecast
14057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14058#[cfg_attr(feature = "bindings", derive(TS))]
14059pub struct MLForecast {
14060    pub this: Box<Expression>,
14061    #[serde(default)]
14062    pub expression: Option<Box<Expression>>,
14063    #[serde(default)]
14064    pub params_struct: Option<Box<Expression>>,
14065}
14066
14067/// ModelAttribute
14068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14069#[cfg_attr(feature = "bindings", derive(TS))]
14070pub struct ModelAttribute {
14071    pub this: Box<Expression>,
14072    pub expression: Box<Expression>,
14073}
14074
14075/// VectorSearch
14076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14077#[cfg_attr(feature = "bindings", derive(TS))]
14078pub struct VectorSearch {
14079    pub this: Box<Expression>,
14080    #[serde(default)]
14081    pub column_to_search: Option<Box<Expression>>,
14082    #[serde(default)]
14083    pub query_table: Option<Box<Expression>>,
14084    #[serde(default)]
14085    pub query_column_to_search: Option<Box<Expression>>,
14086    #[serde(default)]
14087    pub top_k: Option<Box<Expression>>,
14088    #[serde(default)]
14089    pub distance_type: Option<Box<Expression>>,
14090    #[serde(default)]
14091    pub options: Vec<Expression>,
14092}
14093
14094/// Quantile
14095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14096#[cfg_attr(feature = "bindings", derive(TS))]
14097pub struct Quantile {
14098    pub this: Box<Expression>,
14099    #[serde(default)]
14100    pub quantile: Option<Box<Expression>>,
14101}
14102
14103/// ApproxQuantile
14104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14105#[cfg_attr(feature = "bindings", derive(TS))]
14106pub struct ApproxQuantile {
14107    pub this: Box<Expression>,
14108    #[serde(default)]
14109    pub quantile: Option<Box<Expression>>,
14110    #[serde(default)]
14111    pub accuracy: Option<Box<Expression>>,
14112    #[serde(default)]
14113    pub weight: Option<Box<Expression>>,
14114    #[serde(default)]
14115    pub error_tolerance: Option<Box<Expression>>,
14116}
14117
14118/// ApproxPercentileEstimate
14119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14120#[cfg_attr(feature = "bindings", derive(TS))]
14121pub struct ApproxPercentileEstimate {
14122    pub this: Box<Expression>,
14123    #[serde(default)]
14124    pub percentile: Option<Box<Expression>>,
14125}
14126
14127/// Randn
14128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14129#[cfg_attr(feature = "bindings", derive(TS))]
14130pub struct Randn {
14131    #[serde(default)]
14132    pub this: Option<Box<Expression>>,
14133}
14134
14135/// Randstr
14136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14137#[cfg_attr(feature = "bindings", derive(TS))]
14138pub struct Randstr {
14139    pub this: Box<Expression>,
14140    #[serde(default)]
14141    pub generator: Option<Box<Expression>>,
14142}
14143
14144/// RangeN
14145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14146#[cfg_attr(feature = "bindings", derive(TS))]
14147pub struct RangeN {
14148    pub this: Box<Expression>,
14149    #[serde(default)]
14150    pub expressions: Vec<Expression>,
14151    #[serde(default)]
14152    pub each: Option<Box<Expression>>,
14153}
14154
14155/// RangeBucket
14156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14157#[cfg_attr(feature = "bindings", derive(TS))]
14158pub struct RangeBucket {
14159    pub this: Box<Expression>,
14160    pub expression: Box<Expression>,
14161}
14162
14163/// ReadCSV
14164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14165#[cfg_attr(feature = "bindings", derive(TS))]
14166pub struct ReadCSV {
14167    pub this: Box<Expression>,
14168    #[serde(default)]
14169    pub expressions: Vec<Expression>,
14170}
14171
14172/// ReadParquet
14173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14174#[cfg_attr(feature = "bindings", derive(TS))]
14175pub struct ReadParquet {
14176    #[serde(default)]
14177    pub expressions: Vec<Expression>,
14178}
14179
14180/// Reduce
14181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14182#[cfg_attr(feature = "bindings", derive(TS))]
14183pub struct Reduce {
14184    pub this: Box<Expression>,
14185    #[serde(default)]
14186    pub initial: Option<Box<Expression>>,
14187    #[serde(default)]
14188    pub merge: Option<Box<Expression>>,
14189    #[serde(default)]
14190    pub finish: Option<Box<Expression>>,
14191}
14192
14193/// RegexpExtractAll
14194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14195#[cfg_attr(feature = "bindings", derive(TS))]
14196pub struct RegexpExtractAll {
14197    pub this: Box<Expression>,
14198    pub expression: Box<Expression>,
14199    #[serde(default)]
14200    pub group: Option<Box<Expression>>,
14201    #[serde(default)]
14202    pub parameters: Option<Box<Expression>>,
14203    #[serde(default)]
14204    pub position: Option<Box<Expression>>,
14205    #[serde(default)]
14206    pub occurrence: Option<Box<Expression>>,
14207}
14208
14209/// RegexpILike
14210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14211#[cfg_attr(feature = "bindings", derive(TS))]
14212pub struct RegexpILike {
14213    pub this: Box<Expression>,
14214    pub expression: Box<Expression>,
14215    #[serde(default)]
14216    pub flag: Option<Box<Expression>>,
14217}
14218
14219/// RegexpFullMatch
14220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14221#[cfg_attr(feature = "bindings", derive(TS))]
14222pub struct RegexpFullMatch {
14223    pub this: Box<Expression>,
14224    pub expression: Box<Expression>,
14225    #[serde(default)]
14226    pub options: Vec<Expression>,
14227}
14228
14229/// RegexpInstr
14230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14231#[cfg_attr(feature = "bindings", derive(TS))]
14232pub struct RegexpInstr {
14233    pub this: Box<Expression>,
14234    pub expression: Box<Expression>,
14235    #[serde(default)]
14236    pub position: Option<Box<Expression>>,
14237    #[serde(default)]
14238    pub occurrence: Option<Box<Expression>>,
14239    #[serde(default)]
14240    pub option: Option<Box<Expression>>,
14241    #[serde(default)]
14242    pub parameters: Option<Box<Expression>>,
14243    #[serde(default)]
14244    pub group: Option<Box<Expression>>,
14245}
14246
14247/// RegexpSplit
14248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14249#[cfg_attr(feature = "bindings", derive(TS))]
14250pub struct RegexpSplit {
14251    pub this: Box<Expression>,
14252    pub expression: Box<Expression>,
14253    #[serde(default)]
14254    pub limit: Option<Box<Expression>>,
14255}
14256
14257/// RegexpCount
14258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14259#[cfg_attr(feature = "bindings", derive(TS))]
14260pub struct RegexpCount {
14261    pub this: Box<Expression>,
14262    pub expression: Box<Expression>,
14263    #[serde(default)]
14264    pub position: Option<Box<Expression>>,
14265    #[serde(default)]
14266    pub parameters: Option<Box<Expression>>,
14267}
14268
14269/// RegrValx
14270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14271#[cfg_attr(feature = "bindings", derive(TS))]
14272pub struct RegrValx {
14273    pub this: Box<Expression>,
14274    pub expression: Box<Expression>,
14275}
14276
14277/// RegrValy
14278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14279#[cfg_attr(feature = "bindings", derive(TS))]
14280pub struct RegrValy {
14281    pub this: Box<Expression>,
14282    pub expression: Box<Expression>,
14283}
14284
14285/// RegrAvgy
14286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14287#[cfg_attr(feature = "bindings", derive(TS))]
14288pub struct RegrAvgy {
14289    pub this: Box<Expression>,
14290    pub expression: Box<Expression>,
14291}
14292
14293/// RegrAvgx
14294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14295#[cfg_attr(feature = "bindings", derive(TS))]
14296pub struct RegrAvgx {
14297    pub this: Box<Expression>,
14298    pub expression: Box<Expression>,
14299}
14300
14301/// RegrCount
14302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14303#[cfg_attr(feature = "bindings", derive(TS))]
14304pub struct RegrCount {
14305    pub this: Box<Expression>,
14306    pub expression: Box<Expression>,
14307}
14308
14309/// RegrIntercept
14310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14311#[cfg_attr(feature = "bindings", derive(TS))]
14312pub struct RegrIntercept {
14313    pub this: Box<Expression>,
14314    pub expression: Box<Expression>,
14315}
14316
14317/// RegrR2
14318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14319#[cfg_attr(feature = "bindings", derive(TS))]
14320pub struct RegrR2 {
14321    pub this: Box<Expression>,
14322    pub expression: Box<Expression>,
14323}
14324
14325/// RegrSxx
14326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14327#[cfg_attr(feature = "bindings", derive(TS))]
14328pub struct RegrSxx {
14329    pub this: Box<Expression>,
14330    pub expression: Box<Expression>,
14331}
14332
14333/// RegrSxy
14334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14335#[cfg_attr(feature = "bindings", derive(TS))]
14336pub struct RegrSxy {
14337    pub this: Box<Expression>,
14338    pub expression: Box<Expression>,
14339}
14340
14341/// RegrSyy
14342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14343#[cfg_attr(feature = "bindings", derive(TS))]
14344pub struct RegrSyy {
14345    pub this: Box<Expression>,
14346    pub expression: Box<Expression>,
14347}
14348
14349/// RegrSlope
14350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14351#[cfg_attr(feature = "bindings", derive(TS))]
14352pub struct RegrSlope {
14353    pub this: Box<Expression>,
14354    pub expression: Box<Expression>,
14355}
14356
14357/// SafeAdd
14358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14359#[cfg_attr(feature = "bindings", derive(TS))]
14360pub struct SafeAdd {
14361    pub this: Box<Expression>,
14362    pub expression: Box<Expression>,
14363}
14364
14365/// SafeDivide
14366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14367#[cfg_attr(feature = "bindings", derive(TS))]
14368pub struct SafeDivide {
14369    pub this: Box<Expression>,
14370    pub expression: Box<Expression>,
14371}
14372
14373/// SafeMultiply
14374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14375#[cfg_attr(feature = "bindings", derive(TS))]
14376pub struct SafeMultiply {
14377    pub this: Box<Expression>,
14378    pub expression: Box<Expression>,
14379}
14380
14381/// SafeSubtract
14382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14383#[cfg_attr(feature = "bindings", derive(TS))]
14384pub struct SafeSubtract {
14385    pub this: Box<Expression>,
14386    pub expression: Box<Expression>,
14387}
14388
14389/// SHA2
14390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14391#[cfg_attr(feature = "bindings", derive(TS))]
14392pub struct SHA2 {
14393    pub this: Box<Expression>,
14394    #[serde(default)]
14395    pub length: Option<i64>,
14396}
14397
14398/// SHA2Digest
14399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14400#[cfg_attr(feature = "bindings", derive(TS))]
14401pub struct SHA2Digest {
14402    pub this: Box<Expression>,
14403    #[serde(default)]
14404    pub length: Option<i64>,
14405}
14406
14407/// SortArray
14408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14409#[cfg_attr(feature = "bindings", derive(TS))]
14410pub struct SortArray {
14411    pub this: Box<Expression>,
14412    #[serde(default)]
14413    pub asc: Option<Box<Expression>>,
14414    #[serde(default)]
14415    pub nulls_first: Option<Box<Expression>>,
14416}
14417
14418/// SplitPart
14419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14420#[cfg_attr(feature = "bindings", derive(TS))]
14421pub struct SplitPart {
14422    pub this: Box<Expression>,
14423    #[serde(default)]
14424    pub delimiter: Option<Box<Expression>>,
14425    #[serde(default)]
14426    pub part_index: Option<Box<Expression>>,
14427}
14428
14429/// SUBSTRING_INDEX(str, delim, count)
14430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14431#[cfg_attr(feature = "bindings", derive(TS))]
14432pub struct SubstringIndex {
14433    pub this: Box<Expression>,
14434    #[serde(default)]
14435    pub delimiter: Option<Box<Expression>>,
14436    #[serde(default)]
14437    pub count: Option<Box<Expression>>,
14438}
14439
14440/// StandardHash
14441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14442#[cfg_attr(feature = "bindings", derive(TS))]
14443pub struct StandardHash {
14444    pub this: Box<Expression>,
14445    #[serde(default)]
14446    pub expression: Option<Box<Expression>>,
14447}
14448
14449/// StrPosition
14450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14451#[cfg_attr(feature = "bindings", derive(TS))]
14452pub struct StrPosition {
14453    pub this: Box<Expression>,
14454    #[serde(default)]
14455    pub substr: Option<Box<Expression>>,
14456    #[serde(default)]
14457    pub position: Option<Box<Expression>>,
14458    #[serde(default)]
14459    pub occurrence: Option<Box<Expression>>,
14460}
14461
14462/// Search
14463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14464#[cfg_attr(feature = "bindings", derive(TS))]
14465pub struct Search {
14466    pub this: Box<Expression>,
14467    pub expression: Box<Expression>,
14468    #[serde(default)]
14469    pub json_scope: Option<Box<Expression>>,
14470    #[serde(default)]
14471    pub analyzer: Option<Box<Expression>>,
14472    #[serde(default)]
14473    pub analyzer_options: Option<Box<Expression>>,
14474    #[serde(default)]
14475    pub search_mode: Option<Box<Expression>>,
14476}
14477
14478/// SearchIp
14479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14480#[cfg_attr(feature = "bindings", derive(TS))]
14481pub struct SearchIp {
14482    pub this: Box<Expression>,
14483    pub expression: Box<Expression>,
14484}
14485
14486/// StrToDate
14487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14488#[cfg_attr(feature = "bindings", derive(TS))]
14489pub struct StrToDate {
14490    pub this: Box<Expression>,
14491    #[serde(default)]
14492    pub format: Option<String>,
14493    #[serde(default)]
14494    pub safe: Option<Box<Expression>>,
14495}
14496
14497/// StrToTime
14498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14499#[cfg_attr(feature = "bindings", derive(TS))]
14500pub struct StrToTime {
14501    pub this: Box<Expression>,
14502    pub format: String,
14503    #[serde(default)]
14504    pub zone: Option<Box<Expression>>,
14505    #[serde(default)]
14506    pub safe: Option<Box<Expression>>,
14507    #[serde(default)]
14508    pub target_type: Option<Box<Expression>>,
14509}
14510
14511/// StrToUnix
14512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14513#[cfg_attr(feature = "bindings", derive(TS))]
14514pub struct StrToUnix {
14515    #[serde(default)]
14516    pub this: Option<Box<Expression>>,
14517    #[serde(default)]
14518    pub format: Option<String>,
14519}
14520
14521/// StrToMap
14522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14523#[cfg_attr(feature = "bindings", derive(TS))]
14524pub struct StrToMap {
14525    pub this: Box<Expression>,
14526    #[serde(default)]
14527    pub pair_delim: Option<Box<Expression>>,
14528    #[serde(default)]
14529    pub key_value_delim: Option<Box<Expression>>,
14530    #[serde(default)]
14531    pub duplicate_resolution_callback: Option<Box<Expression>>,
14532}
14533
14534/// NumberToStr
14535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14536#[cfg_attr(feature = "bindings", derive(TS))]
14537pub struct NumberToStr {
14538    pub this: Box<Expression>,
14539    pub format: String,
14540    #[serde(default)]
14541    pub culture: Option<Box<Expression>>,
14542}
14543
14544/// FromBase
14545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14546#[cfg_attr(feature = "bindings", derive(TS))]
14547pub struct FromBase {
14548    pub this: Box<Expression>,
14549    pub expression: Box<Expression>,
14550}
14551
14552/// Stuff
14553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14554#[cfg_attr(feature = "bindings", derive(TS))]
14555pub struct Stuff {
14556    pub this: Box<Expression>,
14557    #[serde(default)]
14558    pub start: Option<Box<Expression>>,
14559    #[serde(default)]
14560    pub length: Option<i64>,
14561    pub expression: Box<Expression>,
14562}
14563
14564/// TimeToStr
14565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14566#[cfg_attr(feature = "bindings", derive(TS))]
14567pub struct TimeToStr {
14568    pub this: Box<Expression>,
14569    pub format: String,
14570    #[serde(default)]
14571    pub culture: Option<Box<Expression>>,
14572    #[serde(default)]
14573    pub zone: Option<Box<Expression>>,
14574}
14575
14576/// TimeStrToTime
14577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14578#[cfg_attr(feature = "bindings", derive(TS))]
14579pub struct TimeStrToTime {
14580    pub this: Box<Expression>,
14581    #[serde(default)]
14582    pub zone: Option<Box<Expression>>,
14583}
14584
14585/// TsOrDsAdd
14586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14587#[cfg_attr(feature = "bindings", derive(TS))]
14588pub struct TsOrDsAdd {
14589    pub this: Box<Expression>,
14590    pub expression: Box<Expression>,
14591    #[serde(default)]
14592    pub unit: Option<String>,
14593    #[serde(default)]
14594    pub return_type: Option<Box<Expression>>,
14595}
14596
14597/// TsOrDsDiff
14598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14599#[cfg_attr(feature = "bindings", derive(TS))]
14600pub struct TsOrDsDiff {
14601    pub this: Box<Expression>,
14602    pub expression: Box<Expression>,
14603    #[serde(default)]
14604    pub unit: Option<String>,
14605}
14606
14607/// TsOrDsToDate
14608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14609#[cfg_attr(feature = "bindings", derive(TS))]
14610pub struct TsOrDsToDate {
14611    pub this: Box<Expression>,
14612    #[serde(default)]
14613    pub format: Option<String>,
14614    #[serde(default)]
14615    pub safe: Option<Box<Expression>>,
14616}
14617
14618/// TsOrDsToTime
14619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14620#[cfg_attr(feature = "bindings", derive(TS))]
14621pub struct TsOrDsToTime {
14622    pub this: Box<Expression>,
14623    #[serde(default)]
14624    pub format: Option<String>,
14625    #[serde(default)]
14626    pub safe: Option<Box<Expression>>,
14627}
14628
14629/// Unhex
14630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14631#[cfg_attr(feature = "bindings", derive(TS))]
14632pub struct Unhex {
14633    pub this: Box<Expression>,
14634    #[serde(default)]
14635    pub expression: Option<Box<Expression>>,
14636}
14637
14638/// Uniform
14639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14640#[cfg_attr(feature = "bindings", derive(TS))]
14641pub struct Uniform {
14642    pub this: Box<Expression>,
14643    pub expression: Box<Expression>,
14644    #[serde(default)]
14645    pub gen: Option<Box<Expression>>,
14646    #[serde(default)]
14647    pub seed: Option<Box<Expression>>,
14648}
14649
14650/// UnixToStr
14651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14652#[cfg_attr(feature = "bindings", derive(TS))]
14653pub struct UnixToStr {
14654    pub this: Box<Expression>,
14655    #[serde(default)]
14656    pub format: Option<String>,
14657}
14658
14659/// UnixToTime
14660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14661#[cfg_attr(feature = "bindings", derive(TS))]
14662pub struct UnixToTime {
14663    pub this: Box<Expression>,
14664    #[serde(default)]
14665    pub scale: Option<i64>,
14666    #[serde(default)]
14667    pub zone: Option<Box<Expression>>,
14668    #[serde(default)]
14669    pub hours: Option<Box<Expression>>,
14670    #[serde(default)]
14671    pub minutes: Option<Box<Expression>>,
14672    #[serde(default)]
14673    pub format: Option<String>,
14674    #[serde(default)]
14675    pub target_type: Option<Box<Expression>>,
14676}
14677
14678/// Uuid
14679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14680#[cfg_attr(feature = "bindings", derive(TS))]
14681pub struct Uuid {
14682    #[serde(default)]
14683    pub this: Option<Box<Expression>>,
14684    #[serde(default)]
14685    pub name: Option<String>,
14686    #[serde(default)]
14687    pub is_string: Option<Box<Expression>>,
14688}
14689
14690/// TimestampFromParts
14691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14692#[cfg_attr(feature = "bindings", derive(TS))]
14693pub struct TimestampFromParts {
14694    #[serde(default)]
14695    pub zone: Option<Box<Expression>>,
14696    #[serde(default)]
14697    pub milli: Option<Box<Expression>>,
14698    #[serde(default)]
14699    pub this: Option<Box<Expression>>,
14700    #[serde(default)]
14701    pub expression: Option<Box<Expression>>,
14702}
14703
14704/// TimestampTzFromParts
14705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14706#[cfg_attr(feature = "bindings", derive(TS))]
14707pub struct TimestampTzFromParts {
14708    #[serde(default)]
14709    pub zone: Option<Box<Expression>>,
14710}
14711
14712/// Corr
14713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14714#[cfg_attr(feature = "bindings", derive(TS))]
14715pub struct Corr {
14716    pub this: Box<Expression>,
14717    pub expression: Box<Expression>,
14718    #[serde(default)]
14719    pub null_on_zero_variance: Option<Box<Expression>>,
14720}
14721
14722/// WidthBucket
14723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14724#[cfg_attr(feature = "bindings", derive(TS))]
14725pub struct WidthBucket {
14726    pub this: Box<Expression>,
14727    #[serde(default)]
14728    pub min_value: Option<Box<Expression>>,
14729    #[serde(default)]
14730    pub max_value: Option<Box<Expression>>,
14731    #[serde(default)]
14732    pub num_buckets: Option<Box<Expression>>,
14733    #[serde(default)]
14734    pub threshold: Option<Box<Expression>>,
14735}
14736
14737/// CovarSamp
14738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14739#[cfg_attr(feature = "bindings", derive(TS))]
14740pub struct CovarSamp {
14741    pub this: Box<Expression>,
14742    pub expression: Box<Expression>,
14743}
14744
14745/// CovarPop
14746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14747#[cfg_attr(feature = "bindings", derive(TS))]
14748pub struct CovarPop {
14749    pub this: Box<Expression>,
14750    pub expression: Box<Expression>,
14751}
14752
14753/// Week
14754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14755#[cfg_attr(feature = "bindings", derive(TS))]
14756pub struct Week {
14757    pub this: Box<Expression>,
14758    #[serde(default)]
14759    pub mode: Option<Box<Expression>>,
14760}
14761
14762/// XMLElement
14763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14764#[cfg_attr(feature = "bindings", derive(TS))]
14765pub struct XMLElement {
14766    pub this: Box<Expression>,
14767    #[serde(default)]
14768    pub expressions: Vec<Expression>,
14769    #[serde(default)]
14770    pub evalname: Option<Box<Expression>>,
14771}
14772
14773/// XMLGet
14774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14775#[cfg_attr(feature = "bindings", derive(TS))]
14776pub struct XMLGet {
14777    pub this: Box<Expression>,
14778    pub expression: Box<Expression>,
14779    #[serde(default)]
14780    pub instance: Option<Box<Expression>>,
14781}
14782
14783/// XMLTable
14784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14785#[cfg_attr(feature = "bindings", derive(TS))]
14786pub struct XMLTable {
14787    pub this: Box<Expression>,
14788    #[serde(default)]
14789    pub namespaces: Option<Box<Expression>>,
14790    #[serde(default)]
14791    pub passing: Option<Box<Expression>>,
14792    #[serde(default)]
14793    pub columns: Vec<Expression>,
14794    #[serde(default)]
14795    pub by_ref: Option<Box<Expression>>,
14796}
14797
14798/// XMLKeyValueOption
14799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14800#[cfg_attr(feature = "bindings", derive(TS))]
14801pub struct XMLKeyValueOption {
14802    pub this: Box<Expression>,
14803    #[serde(default)]
14804    pub expression: Option<Box<Expression>>,
14805}
14806
14807/// Zipf
14808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14809#[cfg_attr(feature = "bindings", derive(TS))]
14810pub struct Zipf {
14811    pub this: Box<Expression>,
14812    #[serde(default)]
14813    pub elementcount: Option<Box<Expression>>,
14814    #[serde(default)]
14815    pub gen: Option<Box<Expression>>,
14816}
14817
14818/// Merge
14819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14820#[cfg_attr(feature = "bindings", derive(TS))]
14821pub struct Merge {
14822    pub this: Box<Expression>,
14823    pub using: Box<Expression>,
14824    #[serde(default)]
14825    pub on: Option<Box<Expression>>,
14826    #[serde(default)]
14827    pub using_cond: Option<Box<Expression>>,
14828    #[serde(default)]
14829    pub whens: Option<Box<Expression>>,
14830    #[serde(default)]
14831    pub with_: Option<Box<Expression>>,
14832    #[serde(default)]
14833    pub returning: Option<Box<Expression>>,
14834}
14835
14836/// When
14837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14838#[cfg_attr(feature = "bindings", derive(TS))]
14839pub struct When {
14840    #[serde(default)]
14841    pub matched: Option<Box<Expression>>,
14842    #[serde(default)]
14843    pub source: Option<Box<Expression>>,
14844    #[serde(default)]
14845    pub condition: Option<Box<Expression>>,
14846    pub then: Box<Expression>,
14847}
14848
14849/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14851#[cfg_attr(feature = "bindings", derive(TS))]
14852pub struct Whens {
14853    #[serde(default)]
14854    pub expressions: Vec<Expression>,
14855}
14856
14857/// NextValueFor
14858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14859#[cfg_attr(feature = "bindings", derive(TS))]
14860pub struct NextValueFor {
14861    pub this: Box<Expression>,
14862    #[serde(default)]
14863    pub order: Option<Box<Expression>>,
14864}
14865
14866#[cfg(test)]
14867mod tests {
14868    use super::*;
14869
14870    #[test]
14871    #[cfg(feature = "bindings")]
14872    fn export_typescript_types() {
14873        // This test exports TypeScript types to the generated directory
14874        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14875        Expression::export_all(&ts_rs::Config::default())
14876            .expect("Failed to export Expression types");
14877    }
14878
14879    #[test]
14880    fn test_simple_select_builder() {
14881        let select = Select::new()
14882            .column(Expression::star())
14883            .from(Expression::Table(Box::new(TableRef::new("users"))));
14884
14885        assert_eq!(select.expressions.len(), 1);
14886        assert!(select.from.is_some());
14887    }
14888
14889    #[test]
14890    fn test_expression_alias() {
14891        let expr = Expression::column("id").alias("user_id");
14892
14893        match expr {
14894            Expression::Alias(a) => {
14895                assert_eq!(a.alias.name, "user_id");
14896            }
14897            _ => panic!("Expected Alias"),
14898        }
14899    }
14900
14901    #[test]
14902    fn test_literal_creation() {
14903        let num = Expression::number(42);
14904        let str = Expression::string("hello");
14905
14906        match num {
14907            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
14908                let Literal::Number(n) = lit.as_ref() else {
14909                    unreachable!()
14910                };
14911                assert_eq!(n, "42")
14912            }
14913            _ => panic!("Expected Number"),
14914        }
14915
14916        match str {
14917            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
14918                let Literal::String(s) = lit.as_ref() else {
14919                    unreachable!()
14920                };
14921                assert_eq!(s, "hello")
14922            }
14923            _ => panic!("Expected String"),
14924        }
14925    }
14926
14927    #[test]
14928    fn test_expression_sql() {
14929        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14930        assert_eq!(expr.sql(), "SELECT 1 + 2");
14931    }
14932
14933    #[test]
14934    fn test_expression_sql_for() {
14935        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14936        let sql = expr.sql_for(crate::DialectType::Generic);
14937        // Generic mode normalizes IF() to CASE WHEN
14938        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14939    }
14940}