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 serde::{Deserialize, Serialize};
34use std::fmt;
35#[cfg(feature = "bindings")]
36use ts_rs::TS;
37
38/// Helper function for serde default value
39fn default_true() -> bool {
40    true
41}
42
43fn is_true(v: &bool) -> bool {
44    *v
45}
46
47/// Represent any SQL expression or statement as a single, recursive AST node.
48///
49/// `Expression` is the root type of the polyglot AST. Every parsed SQL
50/// construct -- from a simple integer literal to a multi-CTE query with
51/// window functions -- is represented as a variant of this enum.
52///
53/// Variants are organized into logical groups (see the module-level docs).
54/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
55/// stays small (currently two words: tag + pointer).
56///
57/// # Constructing Expressions
58///
59/// Use the convenience constructors on `impl Expression` for common cases:
60///
61/// ```rust,ignore
62/// use polyglot_sql::expressions::Expression;
63///
64/// let col  = Expression::column("id");
65/// let lit  = Expression::number(42);
66/// let star = Expression::star();
67/// ```
68///
69/// # Generating SQL
70///
71/// ```rust,ignore
72/// let expr = Expression::column("name");
73/// assert_eq!(expr.sql(), "name");
74/// ```
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76#[cfg_attr(feature = "bindings", derive(TS))]
77#[serde(rename_all = "snake_case")]
78#[cfg_attr(feature = "bindings", ts(export))]
79pub enum Expression {
80    // Literals
81    Literal(Literal),
82    Boolean(BooleanLiteral),
83    Null(Null),
84
85    // Identifiers
86    Identifier(Identifier),
87    Column(Column),
88    Table(TableRef),
89    Star(Star),
90    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
91    BracedWildcard(Box<Expression>),
92
93    // Queries
94    Select(Box<Select>),
95    Union(Box<Union>),
96    Intersect(Box<Intersect>),
97    Except(Box<Except>),
98    Subquery(Box<Subquery>),
99    Pivot(Box<Pivot>),
100    PivotAlias(Box<PivotAlias>),
101    Unpivot(Box<Unpivot>),
102    Values(Box<Values>),
103    PreWhere(Box<PreWhere>),
104    Stream(Box<Stream>),
105    UsingData(Box<UsingData>),
106    XmlNamespace(Box<XmlNamespace>),
107
108    // DML
109    Insert(Box<Insert>),
110    Update(Box<Update>),
111    Delete(Box<Delete>),
112    Copy(Box<CopyStmt>),
113    Put(Box<PutStmt>),
114    StageReference(Box<StageReference>),
115
116    // Expressions
117    Alias(Box<Alias>),
118    Cast(Box<Cast>),
119    Collation(Box<CollationExpr>),
120    Case(Box<Case>),
121
122    // Binary operations
123    And(Box<BinaryOp>),
124    Or(Box<BinaryOp>),
125    Add(Box<BinaryOp>),
126    Sub(Box<BinaryOp>),
127    Mul(Box<BinaryOp>),
128    Div(Box<BinaryOp>),
129    Mod(Box<BinaryOp>),
130    Eq(Box<BinaryOp>),
131    Neq(Box<BinaryOp>),
132    Lt(Box<BinaryOp>),
133    Lte(Box<BinaryOp>),
134    Gt(Box<BinaryOp>),
135    Gte(Box<BinaryOp>),
136    Like(Box<LikeOp>),
137    ILike(Box<LikeOp>),
138    /// SQLite MATCH operator (FTS)
139    Match(Box<BinaryOp>),
140    BitwiseAnd(Box<BinaryOp>),
141    BitwiseOr(Box<BinaryOp>),
142    BitwiseXor(Box<BinaryOp>),
143    Concat(Box<BinaryOp>),
144    Adjacent(Box<BinaryOp>),  // PostgreSQL range adjacency operator (-|-)
145    TsMatch(Box<BinaryOp>),   // PostgreSQL text search match operator (@@)
146    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
147
148    // PostgreSQL array/JSONB operators
149    ArrayContainsAll(Box<BinaryOp>),       // @> operator (array contains all)
150    ArrayContainedBy(Box<BinaryOp>),       // <@ operator (array contained by)
151    ArrayOverlaps(Box<BinaryOp>),          // && operator (array overlaps)
152    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
153    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
154    JSONBDeleteAtPath(Box<BinaryOp>),      // #- operator (JSONB delete at path)
155    ExtendsLeft(Box<BinaryOp>),            // &< operator (PostgreSQL range extends left)
156    ExtendsRight(Box<BinaryOp>),           // &> operator (PostgreSQL range extends right)
157
158    // Unary operations
159    Not(Box<UnaryOp>),
160    Neg(Box<UnaryOp>),
161    BitwiseNot(Box<UnaryOp>),
162
163    // Predicates
164    In(Box<In>),
165    Between(Box<Between>),
166    IsNull(Box<IsNull>),
167    IsTrue(Box<IsTrueFalse>),
168    IsFalse(Box<IsTrueFalse>),
169    IsJson(Box<IsJson>),
170    Is(Box<BinaryOp>),  // General IS expression (e.g., a IS ?)
171    Exists(Box<Exists>),
172    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
173    MemberOf(Box<BinaryOp>),
174
175    // Functions
176    Function(Box<Function>),
177    AggregateFunction(Box<AggregateFunction>),
178    WindowFunction(Box<WindowFunction>),
179
180    // Clauses
181    From(Box<From>),
182    Join(Box<Join>),
183    JoinedTable(Box<JoinedTable>),
184    Where(Box<Where>),
185    GroupBy(Box<GroupBy>),
186    Having(Box<Having>),
187    OrderBy(Box<OrderBy>),
188    Limit(Box<Limit>),
189    Offset(Box<Offset>),
190    Qualify(Box<Qualify>),
191    With(Box<With>),
192    Cte(Box<Cte>),
193    DistributeBy(Box<DistributeBy>),
194    ClusterBy(Box<ClusterBy>),
195    SortBy(Box<SortBy>),
196    LateralView(Box<LateralView>),
197    Hint(Box<Hint>),
198    Pseudocolumn(Pseudocolumn),
199
200    // Oracle hierarchical queries (CONNECT BY)
201    Connect(Box<Connect>),
202    Prior(Box<Prior>),
203    ConnectByRoot(Box<ConnectByRoot>),
204
205    // Pattern matching (MATCH_RECOGNIZE)
206    MatchRecognize(Box<MatchRecognize>),
207
208    // Order expressions
209    Ordered(Box<Ordered>),
210
211    // Window specifications
212    Window(Box<WindowSpec>),
213    Over(Box<Over>),
214    WithinGroup(Box<WithinGroup>),
215
216    // Data types
217    DataType(DataType),
218
219    // Arrays and structs
220    Array(Box<Array>),
221    Struct(Box<Struct>),
222    Tuple(Box<Tuple>),
223
224    // Interval
225    Interval(Box<Interval>),
226
227    // String functions
228    ConcatWs(Box<ConcatWs>),
229    Substring(Box<SubstringFunc>),
230    Upper(Box<UnaryFunc>),
231    Lower(Box<UnaryFunc>),
232    Length(Box<UnaryFunc>),
233    Trim(Box<TrimFunc>),
234    LTrim(Box<UnaryFunc>),
235    RTrim(Box<UnaryFunc>),
236    Replace(Box<ReplaceFunc>),
237    Reverse(Box<UnaryFunc>),
238    Left(Box<LeftRightFunc>),
239    Right(Box<LeftRightFunc>),
240    Repeat(Box<RepeatFunc>),
241    Lpad(Box<PadFunc>),
242    Rpad(Box<PadFunc>),
243    Split(Box<SplitFunc>),
244    RegexpLike(Box<RegexpFunc>),
245    RegexpReplace(Box<RegexpReplaceFunc>),
246    RegexpExtract(Box<RegexpExtractFunc>),
247    Overlay(Box<OverlayFunc>),
248
249    // Math functions
250    Abs(Box<UnaryFunc>),
251    Round(Box<RoundFunc>),
252    Floor(Box<FloorFunc>),
253    Ceil(Box<CeilFunc>),
254    Power(Box<BinaryFunc>),
255    Sqrt(Box<UnaryFunc>),
256    Cbrt(Box<UnaryFunc>),
257    Ln(Box<UnaryFunc>),
258    Log(Box<LogFunc>),
259    Exp(Box<UnaryFunc>),
260    Sign(Box<UnaryFunc>),
261    Greatest(Box<VarArgFunc>),
262    Least(Box<VarArgFunc>),
263
264    // Date/time functions
265    CurrentDate(CurrentDate),
266    CurrentTime(CurrentTime),
267    CurrentTimestamp(CurrentTimestamp),
268    CurrentTimestampLTZ(CurrentTimestampLTZ),
269    AtTimeZone(Box<AtTimeZone>),
270    DateAdd(Box<DateAddFunc>),
271    DateSub(Box<DateAddFunc>),
272    DateDiff(Box<DateDiffFunc>),
273    DateTrunc(Box<DateTruncFunc>),
274    Extract(Box<ExtractFunc>),
275    ToDate(Box<ToDateFunc>),
276    ToTimestamp(Box<ToTimestampFunc>),
277    Date(Box<UnaryFunc>),
278    Time(Box<UnaryFunc>),
279    DateFromUnixDate(Box<UnaryFunc>),
280    UnixDate(Box<UnaryFunc>),
281    UnixSeconds(Box<UnaryFunc>),
282    UnixMillis(Box<UnaryFunc>),
283    UnixMicros(Box<UnaryFunc>),
284    UnixToTimeStr(Box<BinaryFunc>),
285    TimeStrToDate(Box<UnaryFunc>),
286    DateToDi(Box<UnaryFunc>),
287    DiToDate(Box<UnaryFunc>),
288    TsOrDiToDi(Box<UnaryFunc>),
289    TsOrDsToDatetime(Box<UnaryFunc>),
290    TsOrDsToTimestamp(Box<UnaryFunc>),
291    YearOfWeek(Box<UnaryFunc>),
292    YearOfWeekIso(Box<UnaryFunc>),
293
294    // Control flow functions
295    Coalesce(Box<VarArgFunc>),
296    NullIf(Box<BinaryFunc>),
297    IfFunc(Box<IfFunc>),
298    IfNull(Box<BinaryFunc>),
299    Nvl(Box<BinaryFunc>),
300    Nvl2(Box<Nvl2Func>),
301
302    // Type conversion
303    TryCast(Box<Cast>),
304    SafeCast(Box<Cast>),
305
306    // Typed aggregate functions
307    Count(Box<CountFunc>),
308    Sum(Box<AggFunc>),
309    Avg(Box<AggFunc>),
310    Min(Box<AggFunc>),
311    Max(Box<AggFunc>),
312    GroupConcat(Box<GroupConcatFunc>),
313    StringAgg(Box<StringAggFunc>),
314    ListAgg(Box<ListAggFunc>),
315    ArrayAgg(Box<AggFunc>),
316    CountIf(Box<AggFunc>),
317    SumIf(Box<SumIfFunc>),
318    Stddev(Box<AggFunc>),
319    StddevPop(Box<AggFunc>),
320    StddevSamp(Box<AggFunc>),
321    Variance(Box<AggFunc>),
322    VarPop(Box<AggFunc>),
323    VarSamp(Box<AggFunc>),
324    Median(Box<AggFunc>),
325    Mode(Box<AggFunc>),
326    First(Box<AggFunc>),
327    Last(Box<AggFunc>),
328    AnyValue(Box<AggFunc>),
329    ApproxDistinct(Box<AggFunc>),
330    ApproxCountDistinct(Box<AggFunc>),
331    ApproxPercentile(Box<ApproxPercentileFunc>),
332    Percentile(Box<PercentileFunc>),
333    LogicalAnd(Box<AggFunc>),
334    LogicalOr(Box<AggFunc>),
335    Skewness(Box<AggFunc>),
336    BitwiseCount(Box<UnaryFunc>),
337    ArrayConcatAgg(Box<AggFunc>),
338    ArrayUniqueAgg(Box<AggFunc>),
339    BoolXorAgg(Box<AggFunc>),
340
341    // Typed window functions
342    RowNumber(RowNumber),
343    Rank(Rank),
344    DenseRank(DenseRank),
345    NTile(Box<NTileFunc>),
346    Lead(Box<LeadLagFunc>),
347    Lag(Box<LeadLagFunc>),
348    FirstValue(Box<ValueFunc>),
349    LastValue(Box<ValueFunc>),
350    NthValue(Box<NthValueFunc>),
351    PercentRank(PercentRank),
352    CumeDist(CumeDist),
353    PercentileCont(Box<PercentileFunc>),
354    PercentileDisc(Box<PercentileFunc>),
355
356    // Additional string functions
357    Contains(Box<BinaryFunc>),
358    StartsWith(Box<BinaryFunc>),
359    EndsWith(Box<BinaryFunc>),
360    Position(Box<PositionFunc>),
361    Initcap(Box<UnaryFunc>),
362    Ascii(Box<UnaryFunc>),
363    Chr(Box<UnaryFunc>),
364    /// MySQL CHAR function with multiple args and optional USING charset
365    CharFunc(Box<CharFunc>),
366    Soundex(Box<UnaryFunc>),
367    Levenshtein(Box<BinaryFunc>),
368    ByteLength(Box<UnaryFunc>),
369    Hex(Box<UnaryFunc>),
370    LowerHex(Box<UnaryFunc>),
371    Unicode(Box<UnaryFunc>),
372
373    // Additional math functions
374    ModFunc(Box<BinaryFunc>),
375    Random(Random),
376    Rand(Box<Rand>),
377    TruncFunc(Box<TruncateFunc>),
378    Pi(Pi),
379    Radians(Box<UnaryFunc>),
380    Degrees(Box<UnaryFunc>),
381    Sin(Box<UnaryFunc>),
382    Cos(Box<UnaryFunc>),
383    Tan(Box<UnaryFunc>),
384    Asin(Box<UnaryFunc>),
385    Acos(Box<UnaryFunc>),
386    Atan(Box<UnaryFunc>),
387    Atan2(Box<BinaryFunc>),
388    IsNan(Box<UnaryFunc>),
389    IsInf(Box<UnaryFunc>),
390    IntDiv(Box<BinaryFunc>),
391
392    // Control flow
393    Decode(Box<DecodeFunc>),
394
395    // Additional date/time functions
396    DateFormat(Box<DateFormatFunc>),
397    FormatDate(Box<DateFormatFunc>),
398    Year(Box<UnaryFunc>),
399    Month(Box<UnaryFunc>),
400    Day(Box<UnaryFunc>),
401    Hour(Box<UnaryFunc>),
402    Minute(Box<UnaryFunc>),
403    Second(Box<UnaryFunc>),
404    DayOfWeek(Box<UnaryFunc>),
405    DayOfWeekIso(Box<UnaryFunc>),
406    DayOfMonth(Box<UnaryFunc>),
407    DayOfYear(Box<UnaryFunc>),
408    WeekOfYear(Box<UnaryFunc>),
409    Quarter(Box<UnaryFunc>),
410    AddMonths(Box<BinaryFunc>),
411    MonthsBetween(Box<BinaryFunc>),
412    LastDay(Box<LastDayFunc>),
413    NextDay(Box<BinaryFunc>),
414    Epoch(Box<UnaryFunc>),
415    EpochMs(Box<UnaryFunc>),
416    FromUnixtime(Box<FromUnixtimeFunc>),
417    UnixTimestamp(Box<UnixTimestampFunc>),
418    MakeDate(Box<MakeDateFunc>),
419    MakeTimestamp(Box<MakeTimestampFunc>),
420    TimestampTrunc(Box<DateTruncFunc>),
421    TimeStrToUnix(Box<UnaryFunc>),
422
423    // Session/User functions
424    SessionUser(SessionUser),
425
426    // Hash/Crypto functions
427    SHA(Box<UnaryFunc>),
428    SHA1Digest(Box<UnaryFunc>),
429
430    // Time conversion functions
431    TimeToUnix(Box<UnaryFunc>),
432
433    // Array functions
434    ArrayFunc(Box<ArrayConstructor>),
435    ArrayLength(Box<UnaryFunc>),
436    ArraySize(Box<UnaryFunc>),
437    Cardinality(Box<UnaryFunc>),
438    ArrayContains(Box<BinaryFunc>),
439    ArrayPosition(Box<BinaryFunc>),
440    ArrayAppend(Box<BinaryFunc>),
441    ArrayPrepend(Box<BinaryFunc>),
442    ArrayConcat(Box<VarArgFunc>),
443    ArraySort(Box<ArraySortFunc>),
444    ArrayReverse(Box<UnaryFunc>),
445    ArrayDistinct(Box<UnaryFunc>),
446    ArrayJoin(Box<ArrayJoinFunc>),
447    ArrayToString(Box<ArrayJoinFunc>),
448    Unnest(Box<UnnestFunc>),
449    Explode(Box<UnaryFunc>),
450    ExplodeOuter(Box<UnaryFunc>),
451    ArrayFilter(Box<ArrayFilterFunc>),
452    ArrayTransform(Box<ArrayTransformFunc>),
453    ArrayFlatten(Box<UnaryFunc>),
454    ArrayCompact(Box<UnaryFunc>),
455    ArrayIntersect(Box<BinaryFunc>),
456    ArrayUnion(Box<BinaryFunc>),
457    ArrayExcept(Box<BinaryFunc>),
458    ArrayRemove(Box<BinaryFunc>),
459    ArrayZip(Box<VarArgFunc>),
460    Sequence(Box<SequenceFunc>),
461    Generate(Box<SequenceFunc>),
462    ExplodingGenerateSeries(Box<SequenceFunc>),
463    ToArray(Box<UnaryFunc>),
464    StarMap(Box<BinaryFunc>),
465
466    // Struct functions
467    StructFunc(Box<StructConstructor>),
468    StructExtract(Box<StructExtractFunc>),
469    NamedStruct(Box<NamedStructFunc>),
470
471    // Map functions
472    MapFunc(Box<MapConstructor>),
473    MapFromEntries(Box<UnaryFunc>),
474    MapFromArrays(Box<BinaryFunc>),
475    MapKeys(Box<UnaryFunc>),
476    MapValues(Box<UnaryFunc>),
477    MapContainsKey(Box<BinaryFunc>),
478    MapConcat(Box<VarArgFunc>),
479    ElementAt(Box<BinaryFunc>),
480    TransformKeys(Box<TransformFunc>),
481    TransformValues(Box<TransformFunc>),
482
483    // JSON functions
484    JsonExtract(Box<JsonExtractFunc>),
485    JsonExtractScalar(Box<JsonExtractFunc>),
486    JsonExtractPath(Box<JsonPathFunc>),
487    JsonArray(Box<VarArgFunc>),
488    JsonObject(Box<JsonObjectFunc>),
489    JsonQuery(Box<JsonExtractFunc>),
490    JsonValue(Box<JsonExtractFunc>),
491    JsonArrayLength(Box<UnaryFunc>),
492    JsonKeys(Box<UnaryFunc>),
493    JsonType(Box<UnaryFunc>),
494    ParseJson(Box<UnaryFunc>),
495    ToJson(Box<UnaryFunc>),
496    JsonSet(Box<JsonModifyFunc>),
497    JsonInsert(Box<JsonModifyFunc>),
498    JsonRemove(Box<JsonPathFunc>),
499    JsonMergePatch(Box<BinaryFunc>),
500    JsonArrayAgg(Box<JsonArrayAggFunc>),
501    JsonObjectAgg(Box<JsonObjectAggFunc>),
502
503    // Type casting/conversion
504    Convert(Box<ConvertFunc>),
505    Typeof(Box<UnaryFunc>),
506
507    // Additional expressions
508    Lambda(Box<LambdaExpr>),
509    Parameter(Box<Parameter>),
510    Placeholder(Placeholder),
511    NamedArgument(Box<NamedArgument>),
512    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
513    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
514    TableArgument(Box<TableArgument>),
515    SqlComment(Box<SqlComment>),
516
517    // Additional predicates
518    NullSafeEq(Box<BinaryOp>),
519    NullSafeNeq(Box<BinaryOp>),
520    Glob(Box<BinaryOp>),
521    SimilarTo(Box<SimilarToExpr>),
522    Any(Box<QuantifiedExpr>),
523    All(Box<QuantifiedExpr>),
524    Overlaps(Box<OverlapsExpr>),
525
526    // Bitwise operations
527    BitwiseLeftShift(Box<BinaryOp>),
528    BitwiseRightShift(Box<BinaryOp>),
529    BitwiseAndAgg(Box<AggFunc>),
530    BitwiseOrAgg(Box<AggFunc>),
531    BitwiseXorAgg(Box<AggFunc>),
532
533    // Array/struct/map access
534    Subscript(Box<Subscript>),
535    Dot(Box<DotAccess>),
536    MethodCall(Box<MethodCall>),
537    ArraySlice(Box<ArraySlice>),
538
539    // DDL statements
540    CreateTable(Box<CreateTable>),
541    DropTable(Box<DropTable>),
542    AlterTable(Box<AlterTable>),
543    CreateIndex(Box<CreateIndex>),
544    DropIndex(Box<DropIndex>),
545    CreateView(Box<CreateView>),
546    DropView(Box<DropView>),
547    AlterView(Box<AlterView>),
548    AlterIndex(Box<AlterIndex>),
549    Truncate(Box<Truncate>),
550    Use(Box<Use>),
551    Cache(Box<Cache>),
552    Uncache(Box<Uncache>),
553    LoadData(Box<LoadData>),
554    Pragma(Box<Pragma>),
555    Grant(Box<Grant>),
556    Revoke(Box<Revoke>),
557    Comment(Box<Comment>),
558    SetStatement(Box<SetStatement>),
559    // Phase 4: Additional DDL statements
560    CreateSchema(Box<CreateSchema>),
561    DropSchema(Box<DropSchema>),
562    DropNamespace(Box<DropNamespace>),
563    CreateDatabase(Box<CreateDatabase>),
564    DropDatabase(Box<DropDatabase>),
565    CreateFunction(Box<CreateFunction>),
566    DropFunction(Box<DropFunction>),
567    CreateProcedure(Box<CreateProcedure>),
568    DropProcedure(Box<DropProcedure>),
569    CreateSequence(Box<CreateSequence>),
570    DropSequence(Box<DropSequence>),
571    AlterSequence(Box<AlterSequence>),
572    CreateTrigger(Box<CreateTrigger>),
573    DropTrigger(Box<DropTrigger>),
574    CreateType(Box<CreateType>),
575    DropType(Box<DropType>),
576    Describe(Box<Describe>),
577    Show(Box<Show>),
578
579    // Transaction and other commands
580    Command(Box<Command>),
581    Kill(Box<Kill>),
582    /// EXEC/EXECUTE statement (TSQL stored procedure call)
583    Execute(Box<ExecuteStatement>),
584
585    // Placeholder for unparsed/raw SQL
586    Raw(Raw),
587
588    // Paren for grouping
589    Paren(Box<Paren>),
590
591    // Expression with trailing comments (for round-trip preservation)
592    Annotated(Box<Annotated>),
593
594    // === BATCH GENERATED EXPRESSION TYPES ===
595    // Generated from Python sqlglot expressions.py
596    Refresh(Box<Refresh>),
597    LockingStatement(Box<LockingStatement>),
598    SequenceProperties(Box<SequenceProperties>),
599    TruncateTable(Box<TruncateTable>),
600    Clone(Box<Clone>),
601    Attach(Box<Attach>),
602    Detach(Box<Detach>),
603    Install(Box<Install>),
604    Summarize(Box<Summarize>),
605    Declare(Box<Declare>),
606    DeclareItem(Box<DeclareItem>),
607    Set(Box<Set>),
608    Heredoc(Box<Heredoc>),
609    SetItem(Box<SetItem>),
610    QueryBand(Box<QueryBand>),
611    UserDefinedFunction(Box<UserDefinedFunction>),
612    RecursiveWithSearch(Box<RecursiveWithSearch>),
613    ProjectionDef(Box<ProjectionDef>),
614    TableAlias(Box<TableAlias>),
615    ByteString(Box<ByteString>),
616    HexStringExpr(Box<HexStringExpr>),
617    UnicodeString(Box<UnicodeString>),
618    ColumnPosition(Box<ColumnPosition>),
619    ColumnDef(Box<ColumnDef>),
620    AlterColumn(Box<AlterColumn>),
621    AlterSortKey(Box<AlterSortKey>),
622    AlterSet(Box<AlterSet>),
623    RenameColumn(Box<RenameColumn>),
624    Comprehension(Box<Comprehension>),
625    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
626    MergeTreeTTL(Box<MergeTreeTTL>),
627    IndexConstraintOption(Box<IndexConstraintOption>),
628    ColumnConstraint(Box<ColumnConstraint>),
629    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
630    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
631    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
632    CheckColumnConstraint(Box<CheckColumnConstraint>),
633    CompressColumnConstraint(Box<CompressColumnConstraint>),
634    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
635    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
636    WithOperator(Box<WithOperator>),
637    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
638    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
639    CommentColumnConstraint(CommentColumnConstraint),
640    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
641    IndexColumnConstraint(Box<IndexColumnConstraint>),
642    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
643    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
644    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
645    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
646    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
647    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
648    InOutColumnConstraint(Box<InOutColumnConstraint>),
649    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
650    PathColumnConstraint(Box<PathColumnConstraint>),
651    Constraint(Box<Constraint>),
652    Export(Box<Export>),
653    Filter(Box<Filter>),
654    Changes(Box<Changes>),
655    CopyParameter(Box<CopyParameter>),
656    Credentials(Box<Credentials>),
657    Directory(Box<Directory>),
658    ForeignKey(Box<ForeignKey>),
659    ColumnPrefix(Box<ColumnPrefix>),
660    PrimaryKey(Box<PrimaryKey>),
661    IntoClause(Box<IntoClause>),
662    JoinHint(Box<JoinHint>),
663    Opclass(Box<Opclass>),
664    Index(Box<Index>),
665    IndexParameters(Box<IndexParameters>),
666    ConditionalInsert(Box<ConditionalInsert>),
667    MultitableInserts(Box<MultitableInserts>),
668    OnConflict(Box<OnConflict>),
669    OnCondition(Box<OnCondition>),
670    Returning(Box<Returning>),
671    Introducer(Box<Introducer>),
672    PartitionRange(Box<PartitionRange>),
673    Fetch(Box<Fetch>),
674    Group(Box<Group>),
675    Cube(Box<Cube>),
676    Rollup(Box<Rollup>),
677    GroupingSets(Box<GroupingSets>),
678    LimitOptions(Box<LimitOptions>),
679    Lateral(Box<Lateral>),
680    TableFromRows(Box<TableFromRows>),
681    RowsFrom(Box<RowsFrom>),
682    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
683    WithFill(Box<WithFill>),
684    Property(Box<Property>),
685    GrantPrivilege(Box<GrantPrivilege>),
686    GrantPrincipal(Box<GrantPrincipal>),
687    AllowedValuesProperty(Box<AllowedValuesProperty>),
688    AlgorithmProperty(Box<AlgorithmProperty>),
689    AutoIncrementProperty(Box<AutoIncrementProperty>),
690    AutoRefreshProperty(Box<AutoRefreshProperty>),
691    BackupProperty(Box<BackupProperty>),
692    BuildProperty(Box<BuildProperty>),
693    BlockCompressionProperty(Box<BlockCompressionProperty>),
694    CharacterSetProperty(Box<CharacterSetProperty>),
695    ChecksumProperty(Box<ChecksumProperty>),
696    CollateProperty(Box<CollateProperty>),
697    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
698    DataDeletionProperty(Box<DataDeletionProperty>),
699    DefinerProperty(Box<DefinerProperty>),
700    DistKeyProperty(Box<DistKeyProperty>),
701    DistributedByProperty(Box<DistributedByProperty>),
702    DistStyleProperty(Box<DistStyleProperty>),
703    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
704    EngineProperty(Box<EngineProperty>),
705    ToTableProperty(Box<ToTableProperty>),
706    ExecuteAsProperty(Box<ExecuteAsProperty>),
707    ExternalProperty(Box<ExternalProperty>),
708    FallbackProperty(Box<FallbackProperty>),
709    FileFormatProperty(Box<FileFormatProperty>),
710    CredentialsProperty(Box<CredentialsProperty>),
711    FreespaceProperty(Box<FreespaceProperty>),
712    InheritsProperty(Box<InheritsProperty>),
713    InputModelProperty(Box<InputModelProperty>),
714    OutputModelProperty(Box<OutputModelProperty>),
715    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
716    JournalProperty(Box<JournalProperty>),
717    LanguageProperty(Box<LanguageProperty>),
718    EnviromentProperty(Box<EnviromentProperty>),
719    ClusteredByProperty(Box<ClusteredByProperty>),
720    DictProperty(Box<DictProperty>),
721    DictRange(Box<DictRange>),
722    OnCluster(Box<OnCluster>),
723    LikeProperty(Box<LikeProperty>),
724    LocationProperty(Box<LocationProperty>),
725    LockProperty(Box<LockProperty>),
726    LockingProperty(Box<LockingProperty>),
727    LogProperty(Box<LogProperty>),
728    MaterializedProperty(Box<MaterializedProperty>),
729    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
730    OnProperty(Box<OnProperty>),
731    OnCommitProperty(Box<OnCommitProperty>),
732    PartitionedByProperty(Box<PartitionedByProperty>),
733    PartitionedByBucket(Box<PartitionedByBucket>),
734    PartitionByTruncate(Box<PartitionByTruncate>),
735    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
736    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
737    PartitionByListProperty(Box<PartitionByListProperty>),
738    PartitionList(Box<PartitionList>),
739    Partition(Box<Partition>),
740    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
741    UniqueKeyProperty(Box<UniqueKeyProperty>),
742    RollupProperty(Box<RollupProperty>),
743    PartitionBoundSpec(Box<PartitionBoundSpec>),
744    PartitionedOfProperty(Box<PartitionedOfProperty>),
745    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
746    ReturnsProperty(Box<ReturnsProperty>),
747    RowFormatProperty(Box<RowFormatProperty>),
748    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
749    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
750    QueryTransform(Box<QueryTransform>),
751    SampleProperty(Box<SampleProperty>),
752    SecurityProperty(Box<SecurityProperty>),
753    SchemaCommentProperty(Box<SchemaCommentProperty>),
754    SemanticView(Box<SemanticView>),
755    SerdeProperties(Box<SerdeProperties>),
756    SetProperty(Box<SetProperty>),
757    SharingProperty(Box<SharingProperty>),
758    SetConfigProperty(Box<SetConfigProperty>),
759    SettingsProperty(Box<SettingsProperty>),
760    SortKeyProperty(Box<SortKeyProperty>),
761    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
762    SqlSecurityProperty(Box<SqlSecurityProperty>),
763    StabilityProperty(Box<StabilityProperty>),
764    StorageHandlerProperty(Box<StorageHandlerProperty>),
765    TemporaryProperty(Box<TemporaryProperty>),
766    Tags(Box<Tags>),
767    TransformModelProperty(Box<TransformModelProperty>),
768    TransientProperty(Box<TransientProperty>),
769    UsingTemplateProperty(Box<UsingTemplateProperty>),
770    ViewAttributeProperty(Box<ViewAttributeProperty>),
771    VolatileProperty(Box<VolatileProperty>),
772    WithDataProperty(Box<WithDataProperty>),
773    WithJournalTableProperty(Box<WithJournalTableProperty>),
774    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
775    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
776    WithProcedureOptions(Box<WithProcedureOptions>),
777    EncodeProperty(Box<EncodeProperty>),
778    IncludeProperty(Box<IncludeProperty>),
779    Properties(Box<Properties>),
780    InputOutputFormat(Box<InputOutputFormat>),
781    Reference(Box<Reference>),
782    QueryOption(Box<QueryOption>),
783    WithTableHint(Box<WithTableHint>),
784    IndexTableHint(Box<IndexTableHint>),
785    HistoricalData(Box<HistoricalData>),
786    Get(Box<Get>),
787    SetOperation(Box<SetOperation>),
788    Var(Box<Var>),
789    Version(Box<Version>),
790    Schema(Box<Schema>),
791    Lock(Box<Lock>),
792    TableSample(Box<TableSample>),
793    Tag(Box<Tag>),
794    UnpivotColumns(Box<UnpivotColumns>),
795    WindowSpec(Box<WindowSpec>),
796    SessionParameter(Box<SessionParameter>),
797    PseudoType(Box<PseudoType>),
798    ObjectIdentifier(Box<ObjectIdentifier>),
799    Transaction(Box<Transaction>),
800    Commit(Box<Commit>),
801    Rollback(Box<Rollback>),
802    AlterSession(Box<AlterSession>),
803    Analyze(Box<Analyze>),
804    AnalyzeStatistics(Box<AnalyzeStatistics>),
805    AnalyzeHistogram(Box<AnalyzeHistogram>),
806    AnalyzeSample(Box<AnalyzeSample>),
807    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
808    AnalyzeDelete(Box<AnalyzeDelete>),
809    AnalyzeWith(Box<AnalyzeWith>),
810    AnalyzeValidate(Box<AnalyzeValidate>),
811    AddPartition(Box<AddPartition>),
812    AttachOption(Box<AttachOption>),
813    DropPartition(Box<DropPartition>),
814    ReplacePartition(Box<ReplacePartition>),
815    DPipe(Box<DPipe>),
816    Operator(Box<Operator>),
817    PivotAny(Box<PivotAny>),
818    Aliases(Box<Aliases>),
819    AtIndex(Box<AtIndex>),
820    FromTimeZone(Box<FromTimeZone>),
821    FormatPhrase(Box<FormatPhrase>),
822    ForIn(Box<ForIn>),
823    TimeUnit(Box<TimeUnit>),
824    IntervalOp(Box<IntervalOp>),
825    IntervalSpan(Box<IntervalSpan>),
826    HavingMax(Box<HavingMax>),
827    CosineDistance(Box<CosineDistance>),
828    DotProduct(Box<DotProduct>),
829    EuclideanDistance(Box<EuclideanDistance>),
830    ManhattanDistance(Box<ManhattanDistance>),
831    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
832    Booland(Box<Booland>),
833    Boolor(Box<Boolor>),
834    ParameterizedAgg(Box<ParameterizedAgg>),
835    ArgMax(Box<ArgMax>),
836    ArgMin(Box<ArgMin>),
837    ApproxTopK(Box<ApproxTopK>),
838    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
839    ApproxTopKCombine(Box<ApproxTopKCombine>),
840    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
841    ApproxTopSum(Box<ApproxTopSum>),
842    ApproxQuantiles(Box<ApproxQuantiles>),
843    Minhash(Box<Minhash>),
844    FarmFingerprint(Box<FarmFingerprint>),
845    Float64(Box<Float64>),
846    Transform(Box<Transform>),
847    Translate(Box<Translate>),
848    Grouping(Box<Grouping>),
849    GroupingId(Box<GroupingId>),
850    Anonymous(Box<Anonymous>),
851    AnonymousAggFunc(Box<AnonymousAggFunc>),
852    CombinedAggFunc(Box<CombinedAggFunc>),
853    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
854    HashAgg(Box<HashAgg>),
855    Hll(Box<Hll>),
856    Apply(Box<Apply>),
857    ToBoolean(Box<ToBoolean>),
858    List(Box<List>),
859    ToMap(Box<ToMap>),
860    Pad(Box<Pad>),
861    ToChar(Box<ToChar>),
862    ToNumber(Box<ToNumber>),
863    ToDouble(Box<ToDouble>),
864    Int64(Box<UnaryFunc>),
865    StringFunc(Box<StringFunc>),
866    ToDecfloat(Box<ToDecfloat>),
867    TryToDecfloat(Box<TryToDecfloat>),
868    ToFile(Box<ToFile>),
869    Columns(Box<Columns>),
870    ConvertToCharset(Box<ConvertToCharset>),
871    ConvertTimezone(Box<ConvertTimezone>),
872    GenerateSeries(Box<GenerateSeries>),
873    AIAgg(Box<AIAgg>),
874    AIClassify(Box<AIClassify>),
875    ArrayAll(Box<ArrayAll>),
876    ArrayAny(Box<ArrayAny>),
877    ArrayConstructCompact(Box<ArrayConstructCompact>),
878    StPoint(Box<StPoint>),
879    StDistance(Box<StDistance>),
880    StringToArray(Box<StringToArray>),
881    ArraySum(Box<ArraySum>),
882    ObjectAgg(Box<ObjectAgg>),
883    CastToStrType(Box<CastToStrType>),
884    CheckJson(Box<CheckJson>),
885    CheckXml(Box<CheckXml>),
886    TranslateCharacters(Box<TranslateCharacters>),
887    CurrentSchemas(Box<CurrentSchemas>),
888    CurrentDatetime(Box<CurrentDatetime>),
889    Localtime(Box<Localtime>),
890    Localtimestamp(Box<Localtimestamp>),
891    Systimestamp(Box<Systimestamp>),
892    CurrentSchema(Box<CurrentSchema>),
893    CurrentUser(Box<CurrentUser>),
894    UtcTime(Box<UtcTime>),
895    UtcTimestamp(Box<UtcTimestamp>),
896    Timestamp(Box<TimestampFunc>),
897    DateBin(Box<DateBin>),
898    Datetime(Box<Datetime>),
899    DatetimeAdd(Box<DatetimeAdd>),
900    DatetimeSub(Box<DatetimeSub>),
901    DatetimeDiff(Box<DatetimeDiff>),
902    DatetimeTrunc(Box<DatetimeTrunc>),
903    Dayname(Box<Dayname>),
904    MakeInterval(Box<MakeInterval>),
905    PreviousDay(Box<PreviousDay>),
906    Elt(Box<Elt>),
907    TimestampAdd(Box<TimestampAdd>),
908    TimestampSub(Box<TimestampSub>),
909    TimestampDiff(Box<TimestampDiff>),
910    TimeSlice(Box<TimeSlice>),
911    TimeAdd(Box<TimeAdd>),
912    TimeSub(Box<TimeSub>),
913    TimeDiff(Box<TimeDiff>),
914    TimeTrunc(Box<TimeTrunc>),
915    DateFromParts(Box<DateFromParts>),
916    TimeFromParts(Box<TimeFromParts>),
917    DecodeCase(Box<DecodeCase>),
918    Decrypt(Box<Decrypt>),
919    DecryptRaw(Box<DecryptRaw>),
920    Encode(Box<Encode>),
921    Encrypt(Box<Encrypt>),
922    EncryptRaw(Box<EncryptRaw>),
923    EqualNull(Box<EqualNull>),
924    ToBinary(Box<ToBinary>),
925    Base64DecodeBinary(Box<Base64DecodeBinary>),
926    Base64DecodeString(Box<Base64DecodeString>),
927    Base64Encode(Box<Base64Encode>),
928    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
929    TryBase64DecodeString(Box<TryBase64DecodeString>),
930    GapFill(Box<GapFill>),
931    GenerateDateArray(Box<GenerateDateArray>),
932    GenerateTimestampArray(Box<GenerateTimestampArray>),
933    GetExtract(Box<GetExtract>),
934    Getbit(Box<Getbit>),
935    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
936    HexEncode(Box<HexEncode>),
937    Compress(Box<Compress>),
938    DecompressBinary(Box<DecompressBinary>),
939    DecompressString(Box<DecompressString>),
940    Xor(Box<Xor>),
941    Nullif(Box<Nullif>),
942    JSON(Box<JSON>),
943    JSONPath(Box<JSONPath>),
944    JSONPathFilter(Box<JSONPathFilter>),
945    JSONPathKey(Box<JSONPathKey>),
946    JSONPathRecursive(Box<JSONPathRecursive>),
947    JSONPathScript(Box<JSONPathScript>),
948    JSONPathSlice(Box<JSONPathSlice>),
949    JSONPathSelector(Box<JSONPathSelector>),
950    JSONPathSubscript(Box<JSONPathSubscript>),
951    JSONPathUnion(Box<JSONPathUnion>),
952    Format(Box<Format>),
953    JSONKeys(Box<JSONKeys>),
954    JSONKeyValue(Box<JSONKeyValue>),
955    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
956    JSONObject(Box<JSONObject>),
957    JSONObjectAgg(Box<JSONObjectAgg>),
958    JSONBObjectAgg(Box<JSONBObjectAgg>),
959    JSONArray(Box<JSONArray>),
960    JSONArrayAgg(Box<JSONArrayAgg>),
961    JSONExists(Box<JSONExists>),
962    JSONColumnDef(Box<JSONColumnDef>),
963    JSONSchema(Box<JSONSchema>),
964    JSONSet(Box<JSONSet>),
965    JSONStripNulls(Box<JSONStripNulls>),
966    JSONValue(Box<JSONValue>),
967    JSONValueArray(Box<JSONValueArray>),
968    JSONRemove(Box<JSONRemove>),
969    JSONTable(Box<JSONTable>),
970    JSONType(Box<JSONType>),
971    ObjectInsert(Box<ObjectInsert>),
972    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
973    OpenJSON(Box<OpenJSON>),
974    JSONBExists(Box<JSONBExists>),
975    JSONBContains(Box<BinaryFunc>),
976    JSONBExtract(Box<BinaryFunc>),
977    JSONCast(Box<JSONCast>),
978    JSONExtract(Box<JSONExtract>),
979    JSONExtractQuote(Box<JSONExtractQuote>),
980    JSONExtractArray(Box<JSONExtractArray>),
981    JSONExtractScalar(Box<JSONExtractScalar>),
982    JSONBExtractScalar(Box<JSONBExtractScalar>),
983    JSONFormat(Box<JSONFormat>),
984    JSONBool(Box<UnaryFunc>),
985    JSONPathRoot(JSONPathRoot),
986    JSONArrayAppend(Box<JSONArrayAppend>),
987    JSONArrayContains(Box<JSONArrayContains>),
988    JSONArrayInsert(Box<JSONArrayInsert>),
989    ParseJSON(Box<ParseJSON>),
990    ParseUrl(Box<ParseUrl>),
991    ParseIp(Box<ParseIp>),
992    ParseTime(Box<ParseTime>),
993    ParseDatetime(Box<ParseDatetime>),
994    Map(Box<Map>),
995    MapCat(Box<MapCat>),
996    MapDelete(Box<MapDelete>),
997    MapInsert(Box<MapInsert>),
998    MapPick(Box<MapPick>),
999    ScopeResolution(Box<ScopeResolution>),
1000    Slice(Box<Slice>),
1001    VarMap(Box<VarMap>),
1002    MatchAgainst(Box<MatchAgainst>),
1003    MD5Digest(Box<MD5Digest>),
1004    MD5NumberLower64(Box<UnaryFunc>),
1005    MD5NumberUpper64(Box<UnaryFunc>),
1006    Monthname(Box<Monthname>),
1007    Ntile(Box<Ntile>),
1008    Normalize(Box<Normalize>),
1009    Normal(Box<Normal>),
1010    Predict(Box<Predict>),
1011    MLTranslate(Box<MLTranslate>),
1012    FeaturesAtTime(Box<FeaturesAtTime>),
1013    GenerateEmbedding(Box<GenerateEmbedding>),
1014    MLForecast(Box<MLForecast>),
1015    ModelAttribute(Box<ModelAttribute>),
1016    VectorSearch(Box<VectorSearch>),
1017    Quantile(Box<Quantile>),
1018    ApproxQuantile(Box<ApproxQuantile>),
1019    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1020    Randn(Box<Randn>),
1021    Randstr(Box<Randstr>),
1022    RangeN(Box<RangeN>),
1023    RangeBucket(Box<RangeBucket>),
1024    ReadCSV(Box<ReadCSV>),
1025    ReadParquet(Box<ReadParquet>),
1026    Reduce(Box<Reduce>),
1027    RegexpExtractAll(Box<RegexpExtractAll>),
1028    RegexpILike(Box<RegexpILike>),
1029    RegexpFullMatch(Box<RegexpFullMatch>),
1030    RegexpInstr(Box<RegexpInstr>),
1031    RegexpSplit(Box<RegexpSplit>),
1032    RegexpCount(Box<RegexpCount>),
1033    RegrValx(Box<RegrValx>),
1034    RegrValy(Box<RegrValy>),
1035    RegrAvgy(Box<RegrAvgy>),
1036    RegrAvgx(Box<RegrAvgx>),
1037    RegrCount(Box<RegrCount>),
1038    RegrIntercept(Box<RegrIntercept>),
1039    RegrR2(Box<RegrR2>),
1040    RegrSxx(Box<RegrSxx>),
1041    RegrSxy(Box<RegrSxy>),
1042    RegrSyy(Box<RegrSyy>),
1043    RegrSlope(Box<RegrSlope>),
1044    SafeAdd(Box<SafeAdd>),
1045    SafeDivide(Box<SafeDivide>),
1046    SafeMultiply(Box<SafeMultiply>),
1047    SafeSubtract(Box<SafeSubtract>),
1048    SHA2(Box<SHA2>),
1049    SHA2Digest(Box<SHA2Digest>),
1050    SortArray(Box<SortArray>),
1051    SplitPart(Box<SplitPart>),
1052    SubstringIndex(Box<SubstringIndex>),
1053    StandardHash(Box<StandardHash>),
1054    StrPosition(Box<StrPosition>),
1055    Search(Box<Search>),
1056    SearchIp(Box<SearchIp>),
1057    StrToDate(Box<StrToDate>),
1058    DateStrToDate(Box<UnaryFunc>),
1059    DateToDateStr(Box<UnaryFunc>),
1060    StrToTime(Box<StrToTime>),
1061    StrToUnix(Box<StrToUnix>),
1062    StrToMap(Box<StrToMap>),
1063    NumberToStr(Box<NumberToStr>),
1064    FromBase(Box<FromBase>),
1065    Stuff(Box<Stuff>),
1066    TimeToStr(Box<TimeToStr>),
1067    TimeStrToTime(Box<TimeStrToTime>),
1068    TsOrDsAdd(Box<TsOrDsAdd>),
1069    TsOrDsDiff(Box<TsOrDsDiff>),
1070    TsOrDsToDate(Box<TsOrDsToDate>),
1071    TsOrDsToTime(Box<TsOrDsToTime>),
1072    Unhex(Box<Unhex>),
1073    Uniform(Box<Uniform>),
1074    UnixToStr(Box<UnixToStr>),
1075    UnixToTime(Box<UnixToTime>),
1076    Uuid(Box<Uuid>),
1077    TimestampFromParts(Box<TimestampFromParts>),
1078    TimestampTzFromParts(Box<TimestampTzFromParts>),
1079    Corr(Box<Corr>),
1080    WidthBucket(Box<WidthBucket>),
1081    CovarSamp(Box<CovarSamp>),
1082    CovarPop(Box<CovarPop>),
1083    Week(Box<Week>),
1084    XMLElement(Box<XMLElement>),
1085    XMLGet(Box<XMLGet>),
1086    XMLTable(Box<XMLTable>),
1087    XMLKeyValueOption(Box<XMLKeyValueOption>),
1088    Zipf(Box<Zipf>),
1089    Merge(Box<Merge>),
1090    When(Box<When>),
1091    Whens(Box<Whens>),
1092    NextValueFor(Box<NextValueFor>),
1093    /// RETURN statement (DuckDB stored procedures)
1094    ReturnStmt(Box<Expression>),
1095}
1096
1097impl Expression {
1098    /// Create a literal number expression from an integer.
1099    pub fn number(n: i64) -> Self {
1100        Expression::Literal(Literal::Number(n.to_string()))
1101    }
1102
1103    /// Create a single-quoted literal string expression.
1104    pub fn string(s: impl Into<String>) -> Self {
1105        Expression::Literal(Literal::String(s.into()))
1106    }
1107
1108    /// Create a literal number expression from a float.
1109    pub fn float(f: f64) -> Self {
1110        Expression::Literal(Literal::Number(f.to_string()))
1111    }
1112
1113    /// Create an unqualified column reference (e.g. `name`).
1114    pub fn column(name: impl Into<String>) -> Self {
1115        Expression::Column(Column {
1116            name: Identifier::new(name),
1117            table: None,
1118            join_mark: false,
1119            trailing_comments: Vec::new(),
1120        })
1121    }
1122
1123    /// Create a qualified column reference (`table.column`).
1124    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1125        Expression::Column(Column {
1126            name: Identifier::new(column),
1127            table: Some(Identifier::new(table)),
1128            join_mark: false,
1129            trailing_comments: Vec::new(),
1130        })
1131    }
1132
1133    /// Create a bare identifier expression (not a column reference).
1134    pub fn identifier(name: impl Into<String>) -> Self {
1135        Expression::Identifier(Identifier::new(name))
1136    }
1137
1138    /// Create a NULL expression
1139    pub fn null() -> Self {
1140        Expression::Null(Null)
1141    }
1142
1143    /// Create a TRUE expression
1144    pub fn true_() -> Self {
1145        Expression::Boolean(BooleanLiteral { value: true })
1146    }
1147
1148    /// Create a FALSE expression
1149    pub fn false_() -> Self {
1150        Expression::Boolean(BooleanLiteral { value: false })
1151    }
1152
1153    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1154    pub fn star() -> Self {
1155        Expression::Star(Star {
1156            table: None,
1157            except: None,
1158            replace: None,
1159            rename: None,
1160            trailing_comments: Vec::new(),
1161        })
1162    }
1163
1164    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1165    pub fn alias(self, name: impl Into<String>) -> Self {
1166        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1167    }
1168
1169    /// Check if this is a SELECT expression
1170    pub fn is_select(&self) -> bool {
1171        matches!(self, Expression::Select(_))
1172    }
1173
1174    /// Try to get as a Select
1175    pub fn as_select(&self) -> Option<&Select> {
1176        match self {
1177            Expression::Select(s) => Some(s),
1178            _ => None,
1179        }
1180    }
1181
1182    /// Try to get as a mutable Select
1183    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1184        match self {
1185            Expression::Select(s) => Some(s),
1186            _ => None,
1187        }
1188    }
1189
1190    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1191    ///
1192    /// Returns an empty string if generation fails. For dialect-specific output,
1193    /// use [`sql_for()`](Self::sql_for) instead.
1194    pub fn sql(&self) -> String {
1195        crate::generator::Generator::sql(self).unwrap_or_default()
1196    }
1197
1198    /// Generate a SQL string for this expression targeting a specific dialect.
1199    ///
1200    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1201    /// syntax variations) are applied automatically.  Returns an empty string if
1202    /// generation fails.
1203    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1204        crate::generate(self, dialect).unwrap_or_default()
1205    }
1206
1207}
1208
1209impl fmt::Display for Expression {
1210    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1211        // Basic display - full SQL generation is in generator module
1212        match self {
1213            Expression::Literal(lit) => write!(f, "{}", lit),
1214            Expression::Identifier(id) => write!(f, "{}", id),
1215            Expression::Column(col) => write!(f, "{}", col),
1216            Expression::Star(_) => write!(f, "*"),
1217            Expression::Null(_) => write!(f, "NULL"),
1218            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1219            Expression::Select(_) => write!(f, "SELECT ..."),
1220            _ => write!(f, "{:?}", self),
1221        }
1222    }
1223}
1224
1225/// Represent a SQL literal value.
1226///
1227/// Numeric values are stored as their original text representation (not parsed
1228/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1229/// preserved across round-trips.
1230///
1231/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1232/// strings, raw strings, etc.) each have a dedicated variant so that the
1233/// generator can emit them with the correct syntax.
1234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1235#[cfg_attr(feature = "bindings", derive(TS))]
1236#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1237pub enum Literal {
1238    /// Single-quoted string literal: `'hello'`
1239    String(String),
1240    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1241    Number(String),
1242    /// Hex string literal: `X'FF'`
1243    HexString(String),
1244    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1245    HexNumber(String),
1246    BitString(String),
1247    /// Byte string: b"..." (BigQuery style)
1248    ByteString(String),
1249    /// National string: N'abc'
1250    NationalString(String),
1251    /// DATE literal: DATE '2024-01-15'
1252    Date(String),
1253    /// TIME literal: TIME '10:30:00'
1254    Time(String),
1255    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1256    Timestamp(String),
1257    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1258    Datetime(String),
1259    /// Triple-quoted string: """...""" or '''...'''
1260    /// Contains (content, quote_char) where quote_char is '"' or '\''
1261    TripleQuotedString(String, char),
1262    /// Escape string: E'...' (PostgreSQL)
1263    EscapeString(String),
1264    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1265    DollarString(String),
1266    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1267    /// In raw strings, backslashes are literal and not escape characters.
1268    /// When converting to a regular string, backslashes must be doubled.
1269    RawString(String),
1270}
1271
1272impl fmt::Display for Literal {
1273    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1274        match self {
1275            Literal::String(s) => write!(f, "'{}'", s),
1276            Literal::Number(n) => write!(f, "{}", n),
1277            Literal::HexString(h) => write!(f, "X'{}'", h),
1278            Literal::HexNumber(h) => write!(f, "0x{}", h),
1279            Literal::BitString(b) => write!(f, "B'{}'", b),
1280            Literal::ByteString(b) => write!(f, "b'{}'", b),
1281            Literal::NationalString(s) => write!(f, "N'{}'", s),
1282            Literal::Date(d) => write!(f, "DATE '{}'", d),
1283            Literal::Time(t) => write!(f, "TIME '{}'", t),
1284            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1285            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1286            Literal::TripleQuotedString(s, q) => {
1287                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1288            }
1289            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1290            Literal::DollarString(s) => write!(f, "$${}$$", s),
1291            Literal::RawString(s) => write!(f, "r'{}'", s),
1292        }
1293    }
1294}
1295
1296/// Boolean literal
1297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1298#[cfg_attr(feature = "bindings", derive(TS))]
1299pub struct BooleanLiteral {
1300    pub value: bool,
1301}
1302
1303/// NULL literal
1304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1305#[cfg_attr(feature = "bindings", derive(TS))]
1306pub struct Null;
1307
1308/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1309///
1310/// The `quoted` flag indicates whether the identifier was originally delimited
1311/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1312/// dialect). The generator uses this flag to decide whether to emit quoting
1313/// characters.
1314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1315#[cfg_attr(feature = "bindings", derive(TS))]
1316pub struct Identifier {
1317    /// The raw text of the identifier, without any quoting characters.
1318    pub name: String,
1319    /// Whether the identifier was quoted in the source SQL.
1320    pub quoted: bool,
1321    #[serde(default)]
1322    pub trailing_comments: Vec<String>,
1323}
1324
1325impl Identifier {
1326    pub fn new(name: impl Into<String>) -> Self {
1327        Self {
1328            name: name.into(),
1329            quoted: false,
1330            trailing_comments: Vec::new(),
1331        }
1332    }
1333
1334    pub fn quoted(name: impl Into<String>) -> Self {
1335        Self {
1336            name: name.into(),
1337            quoted: true,
1338            trailing_comments: Vec::new(),
1339        }
1340    }
1341
1342    pub fn empty() -> Self {
1343        Self {
1344            name: String::new(),
1345            quoted: false,
1346            trailing_comments: Vec::new(),
1347        }
1348    }
1349
1350    pub fn is_empty(&self) -> bool {
1351        self.name.is_empty()
1352    }
1353}
1354
1355impl fmt::Display for Identifier {
1356    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1357        if self.quoted {
1358            write!(f, "\"{}\"", self.name)
1359        } else {
1360            write!(f, "{}", self.name)
1361        }
1362    }
1363}
1364
1365/// Represent a column reference, optionally qualified by a table name.
1366///
1367/// Renders as `name` when unqualified, or `table.name` when qualified.
1368/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1369/// convenient construction.
1370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1371#[cfg_attr(feature = "bindings", derive(TS))]
1372pub struct Column {
1373    /// The column name.
1374    pub name: Identifier,
1375    /// Optional table qualifier (e.g. `t` in `t.col`).
1376    pub table: Option<Identifier>,
1377    /// Oracle-style join marker (+) for outer joins
1378    #[serde(default)]
1379    pub join_mark: bool,
1380    /// Trailing comments that appeared after this column reference
1381    #[serde(default)]
1382    pub trailing_comments: Vec<String>,
1383}
1384
1385impl fmt::Display for Column {
1386    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1387        if let Some(table) = &self.table {
1388            write!(f, "{}.{}", table, self.name)
1389        } else {
1390            write!(f, "{}", self.name)
1391        }
1392    }
1393}
1394
1395/// Represent a table reference with optional schema and catalog qualifiers.
1396///
1397/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1398/// which qualifiers are present. Supports aliases, column alias lists,
1399/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1400/// several other dialect-specific extensions.
1401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1402#[cfg_attr(feature = "bindings", derive(TS))]
1403pub struct TableRef {
1404    /// The unqualified table name.
1405    pub name: Identifier,
1406    /// Optional schema qualifier (e.g. `public` in `public.users`).
1407    pub schema: Option<Identifier>,
1408    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
1409    pub catalog: Option<Identifier>,
1410    /// Optional table alias (e.g. `t` in `FROM users AS t`).
1411    pub alias: Option<Identifier>,
1412    /// Whether AS keyword was explicitly used for the alias
1413    #[serde(default)]
1414    pub alias_explicit_as: bool,
1415    /// Column aliases for table alias: AS t(c1, c2)
1416    #[serde(default)]
1417    pub column_aliases: Vec<Identifier>,
1418    /// Trailing comments that appeared after this table reference
1419    #[serde(default)]
1420    pub trailing_comments: Vec<String>,
1421    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
1422    #[serde(default)]
1423    pub when: Option<Box<HistoricalData>>,
1424    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
1425    #[serde(default)]
1426    pub only: bool,
1427    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
1428    #[serde(default)]
1429    pub final_: bool,
1430    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
1431    #[serde(default, skip_serializing_if = "Option::is_none")]
1432    pub table_sample: Option<Box<Sample>>,
1433    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
1434    #[serde(default)]
1435    pub hints: Vec<Expression>,
1436    /// TSQL: FOR SYSTEM_TIME temporal clause
1437    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
1438    #[serde(default, skip_serializing_if = "Option::is_none")]
1439    pub system_time: Option<String>,
1440    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
1441    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1442    pub partitions: Vec<Identifier>,
1443    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
1444    /// When set, this is used instead of the name field
1445    #[serde(default, skip_serializing_if = "Option::is_none")]
1446    pub identifier_func: Option<Box<Expression>>,
1447    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
1448    #[serde(default, skip_serializing_if = "Option::is_none")]
1449    pub changes: Option<Box<Changes>>,
1450    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
1451    #[serde(default, skip_serializing_if = "Option::is_none")]
1452    pub version: Option<Box<Version>>,
1453}
1454
1455impl TableRef {
1456    pub fn new(name: impl Into<String>) -> Self {
1457        Self {
1458            name: Identifier::new(name),
1459            schema: None,
1460            catalog: None,
1461            alias: None,
1462            alias_explicit_as: false,
1463            column_aliases: Vec::new(),
1464            trailing_comments: Vec::new(),
1465            when: None,
1466            only: false,
1467            final_: false,
1468            table_sample: None,
1469            hints: Vec::new(),
1470            system_time: None,
1471            partitions: Vec::new(),
1472            identifier_func: None,
1473            changes: None,
1474            version: None,
1475        }
1476    }
1477
1478    /// Create with a schema qualifier.
1479    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
1480        let mut t = Self::new(name);
1481        t.schema = Some(Identifier::new(schema));
1482        t
1483    }
1484
1485    /// Create with catalog and schema qualifiers.
1486    pub fn new_with_catalog(
1487        name: impl Into<String>,
1488        schema: impl Into<String>,
1489        catalog: impl Into<String>,
1490    ) -> Self {
1491        let mut t = Self::new(name);
1492        t.schema = Some(Identifier::new(schema));
1493        t.catalog = Some(Identifier::new(catalog));
1494        t
1495    }
1496
1497    /// Create from an Identifier, preserving the quoted flag
1498    pub fn from_identifier(name: Identifier) -> Self {
1499        Self {
1500            name,
1501            schema: None,
1502            catalog: None,
1503            alias: None,
1504            alias_explicit_as: false,
1505            column_aliases: Vec::new(),
1506            trailing_comments: Vec::new(),
1507            when: None,
1508            only: false,
1509            final_: false,
1510            table_sample: None,
1511            hints: Vec::new(),
1512            system_time: None,
1513            partitions: Vec::new(),
1514            identifier_func: None,
1515            changes: None,
1516            version: None,
1517        }
1518    }
1519
1520    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
1521        self.alias = Some(Identifier::new(alias));
1522        self
1523    }
1524
1525    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
1526        self.schema = Some(Identifier::new(schema));
1527        self
1528    }
1529}
1530
1531/// Represent a wildcard star expression (`*`, `table.*`).
1532///
1533/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
1534/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
1535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1536#[cfg_attr(feature = "bindings", derive(TS))]
1537pub struct Star {
1538    /// Optional table qualifier (e.g. `t` in `t.*`).
1539    pub table: Option<Identifier>,
1540    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
1541    pub except: Option<Vec<Identifier>>,
1542    /// REPLACE expressions (BigQuery, Snowflake)
1543    pub replace: Option<Vec<Alias>>,
1544    /// RENAME columns (Snowflake)
1545    pub rename: Option<Vec<(Identifier, Identifier)>>,
1546    /// Trailing comments that appeared after the star
1547    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1548    pub trailing_comments: Vec<String>,
1549}
1550
1551/// Represent a complete SELECT statement.
1552///
1553/// This is the most feature-rich AST node, covering the full surface area of
1554/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
1555/// `Vec` are omitted from the generated SQL when absent.
1556///
1557/// # Key Fields
1558///
1559/// - `expressions` -- the select-list (columns, `*`, computed expressions).
1560/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
1561/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
1562/// - `where_clause` -- the WHERE predicate.
1563/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
1564/// - `having` -- HAVING predicate.
1565/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
1566/// - `limit` / `offset` / `fetch` -- result set limiting.
1567/// - `with` -- Common Table Expressions (CTEs).
1568/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
1569/// - `windows` -- named window definitions (WINDOW w AS ...).
1570///
1571/// Dialect-specific extensions are supported via fields like `prewhere`
1572/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
1573/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
1574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1575#[cfg_attr(feature = "bindings", derive(TS))]
1576pub struct Select {
1577    /// The select-list: columns, expressions, aliases, and wildcards.
1578    pub expressions: Vec<Expression>,
1579    /// The FROM clause, containing one or more table sources.
1580    pub from: Option<From>,
1581    /// JOIN clauses applied after the FROM source.
1582    pub joins: Vec<Join>,
1583    pub lateral_views: Vec<LateralView>,
1584    /// ClickHouse PREWHERE clause
1585    #[serde(default, skip_serializing_if = "Option::is_none")]
1586    pub prewhere: Option<Expression>,
1587    pub where_clause: Option<Where>,
1588    pub group_by: Option<GroupBy>,
1589    pub having: Option<Having>,
1590    pub qualify: Option<Qualify>,
1591    pub order_by: Option<OrderBy>,
1592    pub distribute_by: Option<DistributeBy>,
1593    pub cluster_by: Option<ClusterBy>,
1594    pub sort_by: Option<SortBy>,
1595    pub limit: Option<Limit>,
1596    pub offset: Option<Offset>,
1597    /// ClickHouse LIMIT BY clause expressions
1598    #[serde(default, skip_serializing_if = "Option::is_none")]
1599    pub limit_by: Option<Vec<Expression>>,
1600    pub fetch: Option<Fetch>,
1601    pub distinct: bool,
1602    pub distinct_on: Option<Vec<Expression>>,
1603    pub top: Option<Top>,
1604    pub with: Option<With>,
1605    pub sample: Option<Sample>,
1606    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
1607    #[serde(default, skip_serializing_if = "Option::is_none")]
1608    pub settings: Option<Vec<Expression>>,
1609    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
1610    #[serde(default, skip_serializing_if = "Option::is_none")]
1611    pub format: Option<Expression>,
1612    pub windows: Option<Vec<NamedWindow>>,
1613    pub hint: Option<Hint>,
1614    /// Oracle CONNECT BY clause for hierarchical queries
1615    pub connect: Option<Connect>,
1616    /// SELECT ... INTO table_name for creating tables
1617    pub into: Option<SelectInto>,
1618    /// FOR UPDATE/SHARE locking clauses
1619    #[serde(default)]
1620    pub locks: Vec<Lock>,
1621    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
1622    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1623    pub for_xml: Vec<Expression>,
1624    /// Leading comments before the statement
1625    #[serde(default)]
1626    pub leading_comments: Vec<String>,
1627    /// Comments that appear after SELECT keyword (before expressions)
1628    /// e.g., SELECT /*hint*/ col -> post_select_comments: ["/*hint*/"]
1629    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1630    pub post_select_comments: Vec<String>,
1631    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
1632    #[serde(default, skip_serializing_if = "Option::is_none")]
1633    pub kind: Option<String>,
1634    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
1635    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1636    pub operation_modifiers: Vec<String>,
1637    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
1638    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1639    pub qualify_after_window: bool,
1640    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
1641    #[serde(default, skip_serializing_if = "Option::is_none")]
1642    pub option: Option<String>,
1643}
1644
1645impl Select {
1646    pub fn new() -> Self {
1647        Self {
1648            expressions: Vec::new(),
1649            from: None,
1650            joins: Vec::new(),
1651            lateral_views: Vec::new(),
1652            prewhere: None,
1653            where_clause: None,
1654            group_by: None,
1655            having: None,
1656            qualify: None,
1657            order_by: None,
1658            distribute_by: None,
1659            cluster_by: None,
1660            sort_by: None,
1661            limit: None,
1662            offset: None,
1663            limit_by: None,
1664            fetch: None,
1665            distinct: false,
1666            distinct_on: None,
1667            top: None,
1668            with: None,
1669            sample: None,
1670            settings: None,
1671            format: None,
1672            windows: None,
1673            hint: None,
1674            connect: None,
1675            into: None,
1676            locks: Vec::new(),
1677            for_xml: Vec::new(),
1678            leading_comments: Vec::new(),
1679            post_select_comments: Vec::new(),
1680            kind: None,
1681            operation_modifiers: Vec::new(),
1682            qualify_after_window: false,
1683            option: None,
1684        }
1685    }
1686
1687    /// Add a column to select
1688    pub fn column(mut self, expr: Expression) -> Self {
1689        self.expressions.push(expr);
1690        self
1691    }
1692
1693    /// Set the FROM clause
1694    pub fn from(mut self, table: Expression) -> Self {
1695        self.from = Some(From {
1696            expressions: vec![table],
1697        });
1698        self
1699    }
1700
1701    /// Add a WHERE clause
1702    pub fn where_(mut self, condition: Expression) -> Self {
1703        self.where_clause = Some(Where { this: condition });
1704        self
1705    }
1706
1707    /// Set DISTINCT
1708    pub fn distinct(mut self) -> Self {
1709        self.distinct = true;
1710        self
1711    }
1712
1713    /// Add a JOIN
1714    pub fn join(mut self, join: Join) -> Self {
1715        self.joins.push(join);
1716        self
1717    }
1718
1719    /// Set ORDER BY
1720    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
1721        self.order_by = Some(OrderBy { expressions, siblings: false });
1722        self
1723    }
1724
1725    /// Set LIMIT
1726    pub fn limit(mut self, n: Expression) -> Self {
1727        self.limit = Some(Limit { this: n, percent: false });
1728        self
1729    }
1730
1731    /// Set OFFSET
1732    pub fn offset(mut self, n: Expression) -> Self {
1733        self.offset = Some(Offset { this: n, rows: None });
1734        self
1735    }
1736}
1737
1738impl Default for Select {
1739    fn default() -> Self {
1740        Self::new()
1741    }
1742}
1743
1744/// Represent a UNION set operation between two query expressions.
1745///
1746/// When `all` is true, duplicate rows are preserved (UNION ALL).
1747/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
1748/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
1749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1750#[cfg_attr(feature = "bindings", derive(TS))]
1751pub struct Union {
1752    /// The left-hand query operand.
1753    pub left: Expression,
1754    /// The right-hand query operand.
1755    pub right: Expression,
1756    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
1757    pub all: bool,
1758    /// Whether DISTINCT was explicitly specified
1759    #[serde(default)]
1760    pub distinct: bool,
1761    /// Optional WITH clause
1762    pub with: Option<With>,
1763    /// ORDER BY applied to entire UNION result
1764    pub order_by: Option<OrderBy>,
1765    /// LIMIT applied to entire UNION result
1766    pub limit: Option<Box<Expression>>,
1767    /// OFFSET applied to entire UNION result
1768    pub offset: Option<Box<Expression>>,
1769    /// DISTRIBUTE BY clause (Hive/Spark)
1770    #[serde(default, skip_serializing_if = "Option::is_none")]
1771    pub distribute_by: Option<DistributeBy>,
1772    /// SORT BY clause (Hive/Spark)
1773    #[serde(default, skip_serializing_if = "Option::is_none")]
1774    pub sort_by: Option<SortBy>,
1775    /// CLUSTER BY clause (Hive/Spark)
1776    #[serde(default, skip_serializing_if = "Option::is_none")]
1777    pub cluster_by: Option<ClusterBy>,
1778    /// DuckDB BY NAME modifier
1779    #[serde(default)]
1780    pub by_name: bool,
1781    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1782    #[serde(default, skip_serializing_if = "Option::is_none")]
1783    pub side: Option<String>,
1784    /// BigQuery: Set operation kind (INNER)
1785    #[serde(default, skip_serializing_if = "Option::is_none")]
1786    pub kind: Option<String>,
1787    /// BigQuery: CORRESPONDING modifier
1788    #[serde(default)]
1789    pub corresponding: bool,
1790    /// BigQuery: STRICT modifier (before CORRESPONDING)
1791    #[serde(default)]
1792    pub strict: bool,
1793    /// BigQuery: BY (columns) after CORRESPONDING
1794    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1795    pub on_columns: Vec<Expression>,
1796}
1797
1798/// Represent an INTERSECT set operation between two query expressions.
1799///
1800/// Returns only rows that appear in both operands. When `all` is true,
1801/// duplicates are preserved according to their multiplicity.
1802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1803#[cfg_attr(feature = "bindings", derive(TS))]
1804pub struct Intersect {
1805    /// The left-hand query operand.
1806    pub left: Expression,
1807    /// The right-hand query operand.
1808    pub right: Expression,
1809    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
1810    pub all: bool,
1811    /// Whether DISTINCT was explicitly specified
1812    #[serde(default)]
1813    pub distinct: bool,
1814    /// Optional WITH clause
1815    pub with: Option<With>,
1816    /// ORDER BY applied to entire INTERSECT result
1817    pub order_by: Option<OrderBy>,
1818    /// LIMIT applied to entire INTERSECT result
1819    pub limit: Option<Box<Expression>>,
1820    /// OFFSET applied to entire INTERSECT result
1821    pub offset: Option<Box<Expression>>,
1822    /// DISTRIBUTE BY clause (Hive/Spark)
1823    #[serde(default, skip_serializing_if = "Option::is_none")]
1824    pub distribute_by: Option<DistributeBy>,
1825    /// SORT BY clause (Hive/Spark)
1826    #[serde(default, skip_serializing_if = "Option::is_none")]
1827    pub sort_by: Option<SortBy>,
1828    /// CLUSTER BY clause (Hive/Spark)
1829    #[serde(default, skip_serializing_if = "Option::is_none")]
1830    pub cluster_by: Option<ClusterBy>,
1831    /// DuckDB BY NAME modifier
1832    #[serde(default)]
1833    pub by_name: bool,
1834    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1835    #[serde(default, skip_serializing_if = "Option::is_none")]
1836    pub side: Option<String>,
1837    /// BigQuery: Set operation kind (INNER)
1838    #[serde(default, skip_serializing_if = "Option::is_none")]
1839    pub kind: Option<String>,
1840    /// BigQuery: CORRESPONDING modifier
1841    #[serde(default)]
1842    pub corresponding: bool,
1843    /// BigQuery: STRICT modifier (before CORRESPONDING)
1844    #[serde(default)]
1845    pub strict: bool,
1846    /// BigQuery: BY (columns) after CORRESPONDING
1847    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1848    pub on_columns: Vec<Expression>,
1849}
1850
1851/// Represent an EXCEPT (MINUS) set operation between two query expressions.
1852///
1853/// Returns rows from the left operand that do not appear in the right operand.
1854/// When `all` is true, duplicates are subtracted according to their multiplicity.
1855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1856#[cfg_attr(feature = "bindings", derive(TS))]
1857pub struct Except {
1858    /// The left-hand query operand.
1859    pub left: Expression,
1860    /// The right-hand query operand (rows to subtract).
1861    pub right: Expression,
1862    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
1863    pub all: bool,
1864    /// Whether DISTINCT was explicitly specified
1865    #[serde(default)]
1866    pub distinct: bool,
1867    /// Optional WITH clause
1868    pub with: Option<With>,
1869    /// ORDER BY applied to entire EXCEPT result
1870    pub order_by: Option<OrderBy>,
1871    /// LIMIT applied to entire EXCEPT result
1872    pub limit: Option<Box<Expression>>,
1873    /// OFFSET applied to entire EXCEPT result
1874    pub offset: Option<Box<Expression>>,
1875    /// DISTRIBUTE BY clause (Hive/Spark)
1876    #[serde(default, skip_serializing_if = "Option::is_none")]
1877    pub distribute_by: Option<DistributeBy>,
1878    /// SORT BY clause (Hive/Spark)
1879    #[serde(default, skip_serializing_if = "Option::is_none")]
1880    pub sort_by: Option<SortBy>,
1881    /// CLUSTER BY clause (Hive/Spark)
1882    #[serde(default, skip_serializing_if = "Option::is_none")]
1883    pub cluster_by: Option<ClusterBy>,
1884    /// DuckDB BY NAME modifier
1885    #[serde(default)]
1886    pub by_name: bool,
1887    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1888    #[serde(default, skip_serializing_if = "Option::is_none")]
1889    pub side: Option<String>,
1890    /// BigQuery: Set operation kind (INNER)
1891    #[serde(default, skip_serializing_if = "Option::is_none")]
1892    pub kind: Option<String>,
1893    /// BigQuery: CORRESPONDING modifier
1894    #[serde(default)]
1895    pub corresponding: bool,
1896    /// BigQuery: STRICT modifier (before CORRESPONDING)
1897    #[serde(default)]
1898    pub strict: bool,
1899    /// BigQuery: BY (columns) after CORRESPONDING
1900    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1901    pub on_columns: Vec<Expression>,
1902}
1903
1904/// INTO clause for SELECT INTO statements
1905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1906#[cfg_attr(feature = "bindings", derive(TS))]
1907pub struct SelectInto {
1908    /// Target table or variable (used when single target)
1909    pub this: Expression,
1910    /// Whether TEMPORARY keyword was used
1911    #[serde(default)]
1912    pub temporary: bool,
1913    /// Whether UNLOGGED keyword was used (PostgreSQL)
1914    #[serde(default)]
1915    pub unlogged: bool,
1916    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
1917    #[serde(default)]
1918    pub bulk_collect: bool,
1919    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
1920    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1921    pub expressions: Vec<Expression>,
1922}
1923
1924/// Represent a parenthesized subquery expression.
1925///
1926/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
1927/// parentheses and optionally applies an alias, column aliases, ORDER BY,
1928/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
1929/// modifiers are rendered inside or outside the parentheses.
1930///
1931/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
1932/// scalar subqueries in select-lists, and derived tables.
1933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1934#[cfg_attr(feature = "bindings", derive(TS))]
1935pub struct Subquery {
1936    /// The inner query expression.
1937    pub this: Expression,
1938    /// Optional alias for the derived table.
1939    pub alias: Option<Identifier>,
1940    /// Optional column aliases: AS t(c1, c2)
1941    pub column_aliases: Vec<Identifier>,
1942    /// ORDER BY clause (for parenthesized queries)
1943    pub order_by: Option<OrderBy>,
1944    /// LIMIT clause
1945    pub limit: Option<Limit>,
1946    /// OFFSET clause
1947    pub offset: Option<Offset>,
1948    /// DISTRIBUTE BY clause (Hive/Spark)
1949    #[serde(default, skip_serializing_if = "Option::is_none")]
1950    pub distribute_by: Option<DistributeBy>,
1951    /// SORT BY clause (Hive/Spark)
1952    #[serde(default, skip_serializing_if = "Option::is_none")]
1953    pub sort_by: Option<SortBy>,
1954    /// CLUSTER BY clause (Hive/Spark)
1955    #[serde(default, skip_serializing_if = "Option::is_none")]
1956    pub cluster_by: Option<ClusterBy>,
1957    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
1958    #[serde(default)]
1959    pub lateral: bool,
1960    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
1961    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
1962    /// false: (SELECT 1) LIMIT 1 - modifiers outside
1963    #[serde(default)]
1964    pub modifiers_inside: bool,
1965    /// Trailing comments after the closing paren
1966    #[serde(default)]
1967    pub trailing_comments: Vec<String>,
1968}
1969
1970/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
1971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1972#[cfg_attr(feature = "bindings", derive(TS))]
1973pub struct Values {
1974    /// The rows of values
1975    pub expressions: Vec<Tuple>,
1976    /// Optional alias for the table
1977    pub alias: Option<Identifier>,
1978    /// Optional column aliases: AS t(c1, c2)
1979    pub column_aliases: Vec<Identifier>,
1980}
1981
1982/// PIVOT operation - supports both standard and DuckDB simplified syntax
1983///
1984/// Standard syntax (in FROM clause):
1985///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
1986///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
1987///
1988/// DuckDB simplified syntax (statement-level):
1989///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
1990///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
1991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1992#[cfg_attr(feature = "bindings", derive(TS))]
1993pub struct Pivot {
1994    /// Source table/expression
1995    pub this: Expression,
1996    /// For standard PIVOT: the aggregation function(s) (first is primary)
1997    /// For DuckDB simplified: unused (use `using` instead)
1998    #[serde(default)]
1999    pub expressions: Vec<Expression>,
2000    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2001    #[serde(default)]
2002    pub fields: Vec<Expression>,
2003    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2004    #[serde(default)]
2005    pub using: Vec<Expression>,
2006    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2007    #[serde(default)]
2008    pub group: Option<Box<Expression>>,
2009    /// Whether this is an UNPIVOT (vs PIVOT)
2010    #[serde(default)]
2011    pub unpivot: bool,
2012    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2013    #[serde(default)]
2014    pub into: Option<Box<Expression>>,
2015    /// Optional alias
2016    #[serde(default)]
2017    pub alias: Option<Identifier>,
2018    /// Include/exclude nulls (for UNPIVOT)
2019    #[serde(default)]
2020    pub include_nulls: Option<bool>,
2021    /// Default on null value (Snowflake)
2022    #[serde(default)]
2023    pub default_on_null: Option<Box<Expression>>,
2024    /// WITH clause (CTEs)
2025    #[serde(default, skip_serializing_if = "Option::is_none")]
2026    pub with: Option<With>,
2027}
2028
2029/// UNPIVOT operation
2030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2031#[cfg_attr(feature = "bindings", derive(TS))]
2032pub struct Unpivot {
2033    pub this: Expression,
2034    pub value_column: Identifier,
2035    pub name_column: Identifier,
2036    pub columns: Vec<Expression>,
2037    pub alias: Option<Identifier>,
2038    /// Whether the value_column was parenthesized in the original SQL
2039    #[serde(default)]
2040    pub value_column_parenthesized: bool,
2041    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2042    #[serde(default)]
2043    pub include_nulls: Option<bool>,
2044    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2045    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2046    pub extra_value_columns: Vec<Identifier>,
2047}
2048
2049/// PIVOT alias for aliasing pivot expressions
2050/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2052#[cfg_attr(feature = "bindings", derive(TS))]
2053pub struct PivotAlias {
2054    pub this: Expression,
2055    pub alias: Expression,
2056}
2057
2058/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2060#[cfg_attr(feature = "bindings", derive(TS))]
2061pub struct PreWhere {
2062    pub this: Expression,
2063}
2064
2065/// STREAM definition (Snowflake) - for change data capture
2066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2067#[cfg_attr(feature = "bindings", derive(TS))]
2068pub struct Stream {
2069    pub this: Expression,
2070    #[serde(skip_serializing_if = "Option::is_none")]
2071    pub on: Option<Expression>,
2072    #[serde(skip_serializing_if = "Option::is_none")]
2073    pub show_initial_rows: Option<bool>,
2074}
2075
2076/// USING DATA clause for data import statements
2077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2078#[cfg_attr(feature = "bindings", derive(TS))]
2079pub struct UsingData {
2080    pub this: Expression,
2081}
2082
2083/// XML Namespace declaration
2084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2085#[cfg_attr(feature = "bindings", derive(TS))]
2086pub struct XmlNamespace {
2087    pub this: Expression,
2088    #[serde(skip_serializing_if = "Option::is_none")]
2089    pub alias: Option<Identifier>,
2090}
2091
2092/// ROW FORMAT clause for Hive/Spark
2093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2094#[cfg_attr(feature = "bindings", derive(TS))]
2095pub struct RowFormat {
2096    pub delimited: bool,
2097    pub fields_terminated_by: Option<String>,
2098    pub collection_items_terminated_by: Option<String>,
2099    pub map_keys_terminated_by: Option<String>,
2100    pub lines_terminated_by: Option<String>,
2101    pub null_defined_as: Option<String>,
2102}
2103
2104/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2106#[cfg_attr(feature = "bindings", derive(TS))]
2107pub struct DirectoryInsert {
2108    pub local: bool,
2109    pub path: String,
2110    pub row_format: Option<RowFormat>,
2111    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2112    #[serde(default)]
2113    pub stored_as: Option<String>,
2114}
2115
2116/// INSERT statement
2117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2118#[cfg_attr(feature = "bindings", derive(TS))]
2119pub struct Insert {
2120    pub table: TableRef,
2121    pub columns: Vec<Identifier>,
2122    pub values: Vec<Vec<Expression>>,
2123    pub query: Option<Expression>,
2124    /// INSERT OVERWRITE for Hive/Spark
2125    pub overwrite: bool,
2126    /// PARTITION clause for Hive/Spark
2127    pub partition: Vec<(Identifier, Option<Expression>)>,
2128    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2129    #[serde(default)]
2130    pub directory: Option<DirectoryInsert>,
2131    /// RETURNING clause (PostgreSQL, SQLite)
2132    #[serde(default)]
2133    pub returning: Vec<Expression>,
2134    /// OUTPUT clause (TSQL)
2135    #[serde(default)]
2136    pub output: Option<OutputClause>,
2137    /// ON CONFLICT clause (PostgreSQL, SQLite)
2138    #[serde(default)]
2139    pub on_conflict: Option<Box<Expression>>,
2140    /// Leading comments before the statement
2141    #[serde(default)]
2142    pub leading_comments: Vec<String>,
2143    /// IF EXISTS clause (Hive)
2144    #[serde(default)]
2145    pub if_exists: bool,
2146    /// WITH clause (CTEs)
2147    #[serde(default)]
2148    pub with: Option<With>,
2149    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2150    #[serde(default)]
2151    pub ignore: bool,
2152    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2153    #[serde(default)]
2154    pub source_alias: Option<Identifier>,
2155    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2156    #[serde(default)]
2157    pub alias: Option<Identifier>,
2158    /// Whether the alias uses explicit AS keyword
2159    #[serde(default)]
2160    pub alias_explicit_as: bool,
2161    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2162    #[serde(default)]
2163    pub default_values: bool,
2164    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2165    #[serde(default)]
2166    pub by_name: bool,
2167    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2168    #[serde(default, skip_serializing_if = "Option::is_none")]
2169    pub conflict_action: Option<String>,
2170    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2171    #[serde(default)]
2172    pub is_replace: bool,
2173    /// Oracle-style hint: INSERT /*+ APPEND */ INTO ...
2174    #[serde(default, skip_serializing_if = "Option::is_none")]
2175    pub hint: Option<Hint>,
2176    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2177    #[serde(default)]
2178    pub replace_where: Option<Box<Expression>>,
2179    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2180    #[serde(default)]
2181    pub source: Option<Box<Expression>>,
2182    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2183    #[serde(default, skip_serializing_if = "Option::is_none")]
2184    pub function_target: Option<Box<Expression>>,
2185    /// ClickHouse: PARTITION BY expr
2186    #[serde(default, skip_serializing_if = "Option::is_none")]
2187    pub partition_by: Option<Box<Expression>>,
2188    /// ClickHouse: SETTINGS key = val, ...
2189    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2190    pub settings: Vec<Expression>,
2191}
2192
2193/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2195#[cfg_attr(feature = "bindings", derive(TS))]
2196pub struct OutputClause {
2197    /// Columns/expressions to output
2198    pub columns: Vec<Expression>,
2199    /// Optional INTO target table or table variable
2200    #[serde(default)]
2201    pub into_table: Option<Expression>,
2202}
2203
2204/// UPDATE statement
2205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2206#[cfg_attr(feature = "bindings", derive(TS))]
2207pub struct Update {
2208    pub table: TableRef,
2209    /// Additional tables for multi-table UPDATE (MySQL syntax)
2210    #[serde(default)]
2211    pub extra_tables: Vec<TableRef>,
2212    /// JOINs attached to the table list (MySQL multi-table syntax)
2213    #[serde(default)]
2214    pub table_joins: Vec<Join>,
2215    pub set: Vec<(Identifier, Expression)>,
2216    pub from_clause: Option<From>,
2217    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2218    #[serde(default)]
2219    pub from_joins: Vec<Join>,
2220    pub where_clause: Option<Where>,
2221    /// RETURNING clause (PostgreSQL, SQLite)
2222    #[serde(default)]
2223    pub returning: Vec<Expression>,
2224    /// OUTPUT clause (TSQL)
2225    #[serde(default)]
2226    pub output: Option<OutputClause>,
2227    /// WITH clause (CTEs)
2228    #[serde(default)]
2229    pub with: Option<With>,
2230    /// Leading comments before the statement
2231    #[serde(default)]
2232    pub leading_comments: Vec<String>,
2233    /// LIMIT clause (MySQL)
2234    #[serde(default)]
2235    pub limit: Option<Expression>,
2236    /// ORDER BY clause (MySQL)
2237    #[serde(default)]
2238    pub order_by: Option<OrderBy>,
2239    /// Whether FROM clause appears before SET (Snowflake syntax)
2240    #[serde(default)]
2241    pub from_before_set: bool,
2242}
2243
2244/// DELETE statement
2245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2246#[cfg_attr(feature = "bindings", derive(TS))]
2247pub struct Delete {
2248    pub table: TableRef,
2249    /// ClickHouse: ON CLUSTER clause for distributed DDL
2250    #[serde(default, skip_serializing_if = "Option::is_none")]
2251    pub on_cluster: Option<OnCluster>,
2252    /// Optional alias for the table
2253    pub alias: Option<Identifier>,
2254    /// Whether the alias was declared with explicit AS keyword
2255    #[serde(default)]
2256    pub alias_explicit_as: bool,
2257    /// PostgreSQL/DuckDB USING clause - additional tables to join
2258    pub using: Vec<TableRef>,
2259    pub where_clause: Option<Where>,
2260    /// OUTPUT clause (TSQL)
2261    #[serde(default)]
2262    pub output: Option<OutputClause>,
2263    /// Leading comments before the statement
2264    #[serde(default)]
2265    pub leading_comments: Vec<String>,
2266    /// WITH clause (CTEs)
2267    #[serde(default)]
2268    pub with: Option<With>,
2269    /// LIMIT clause (MySQL)
2270    #[serde(default)]
2271    pub limit: Option<Expression>,
2272    /// ORDER BY clause (MySQL)
2273    #[serde(default)]
2274    pub order_by: Option<OrderBy>,
2275    /// RETURNING clause (PostgreSQL)
2276    #[serde(default)]
2277    pub returning: Vec<Expression>,
2278    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2279    /// These are the target tables to delete from
2280    #[serde(default)]
2281    pub tables: Vec<TableRef>,
2282    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2283    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2284    #[serde(default)]
2285    pub tables_from_using: bool,
2286    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2287    #[serde(default)]
2288    pub joins: Vec<Join>,
2289    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2290    #[serde(default)]
2291    pub force_index: Option<String>,
2292    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2293    #[serde(default)]
2294    pub no_from: bool,
2295}
2296
2297/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2299#[cfg_attr(feature = "bindings", derive(TS))]
2300pub struct CopyStmt {
2301    /// Target table or query
2302    pub this: Expression,
2303    /// True for FROM (loading into table), false for TO (exporting)
2304    pub kind: bool,
2305    /// Source/destination file(s) or stage
2306    pub files: Vec<Expression>,
2307    /// Copy parameters
2308    #[serde(default)]
2309    pub params: Vec<CopyParameter>,
2310    /// Credentials for external access
2311    #[serde(default)]
2312    pub credentials: Option<Box<Credentials>>,
2313    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2314    #[serde(default)]
2315    pub is_into: bool,
2316    /// Whether parameters are wrapped in WITH (...) syntax
2317    #[serde(default)]
2318    pub with_wrapped: bool,
2319}
2320
2321/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2323#[cfg_attr(feature = "bindings", derive(TS))]
2324pub struct CopyParameter {
2325    pub name: String,
2326    pub value: Option<Expression>,
2327    pub values: Vec<Expression>,
2328    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2329    #[serde(default)]
2330    pub eq: bool,
2331}
2332
2333/// Credentials for external access (S3, Azure, etc.)
2334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2335#[cfg_attr(feature = "bindings", derive(TS))]
2336pub struct Credentials {
2337    pub credentials: Vec<(String, String)>,
2338    pub encryption: Option<String>,
2339    pub storage: Option<String>,
2340}
2341
2342/// PUT statement (Snowflake)
2343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2344#[cfg_attr(feature = "bindings", derive(TS))]
2345pub struct PutStmt {
2346    /// Source file path
2347    pub source: String,
2348    /// Whether source was quoted in the original SQL
2349    #[serde(default)]
2350    pub source_quoted: bool,
2351    /// Target stage
2352    pub target: Expression,
2353    /// PUT parameters
2354    #[serde(default)]
2355    pub params: Vec<CopyParameter>,
2356}
2357
2358/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2360#[cfg_attr(feature = "bindings", derive(TS))]
2361pub struct StageReference {
2362    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2363    pub name: String,
2364    /// Optional path within the stage (e.g., "/path/to/file.csv")
2365    #[serde(default)]
2366    pub path: Option<String>,
2367    /// Optional FILE_FORMAT parameter
2368    #[serde(default)]
2369    pub file_format: Option<Expression>,
2370    /// Optional PATTERN parameter
2371    #[serde(default)]
2372    pub pattern: Option<String>,
2373    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2374    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2375    pub quoted: bool,
2376}
2377
2378/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2380#[cfg_attr(feature = "bindings", derive(TS))]
2381pub struct HistoricalData {
2382    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
2383    pub this: Box<Expression>,
2384    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
2385    pub kind: String,
2386    /// The expression value (e.g., the statement ID or timestamp)
2387    pub expression: Box<Expression>,
2388}
2389
2390/// Represent an aliased expression (`expr AS name`).
2391///
2392/// Used for column aliases in select-lists, table aliases on subqueries,
2393/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
2394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2395#[cfg_attr(feature = "bindings", derive(TS))]
2396pub struct Alias {
2397    /// The expression being aliased.
2398    pub this: Expression,
2399    /// The alias name (required for simple aliases, optional when only column aliases provided)
2400    pub alias: Identifier,
2401    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
2402    #[serde(default)]
2403    pub column_aliases: Vec<Identifier>,
2404    /// Comments that appeared between the expression and AS keyword
2405    #[serde(default)]
2406    pub pre_alias_comments: Vec<String>,
2407    /// Trailing comments that appeared after the alias
2408    #[serde(default)]
2409    pub trailing_comments: Vec<String>,
2410}
2411
2412impl Alias {
2413    /// Create a simple alias
2414    pub fn new(this: Expression, alias: Identifier) -> Self {
2415        Self {
2416            this,
2417            alias,
2418            column_aliases: Vec::new(),
2419            pre_alias_comments: Vec::new(),
2420            trailing_comments: Vec::new(),
2421        }
2422    }
2423
2424    /// Create an alias with column aliases only (no table alias name)
2425    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
2426        Self {
2427            this,
2428            alias: Identifier::empty(),
2429            column_aliases,
2430            pre_alias_comments: Vec::new(),
2431            trailing_comments: Vec::new(),
2432        }
2433    }
2434}
2435
2436/// Represent a type cast expression.
2437///
2438/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
2439/// shorthand `expr::type`. Also used as the payload for `TryCast` and
2440/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
2441/// CONVERSION ERROR (Oracle) clauses.
2442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2443#[cfg_attr(feature = "bindings", derive(TS))]
2444pub struct Cast {
2445    /// The expression being cast.
2446    pub this: Expression,
2447    /// The target data type.
2448    pub to: DataType,
2449    #[serde(default)]
2450    pub trailing_comments: Vec<String>,
2451    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
2452    #[serde(default)]
2453    pub double_colon_syntax: bool,
2454    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
2455    #[serde(skip_serializing_if = "Option::is_none", default)]
2456    pub format: Option<Box<Expression>>,
2457    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
2458    #[serde(skip_serializing_if = "Option::is_none", default)]
2459    pub default: Option<Box<Expression>>,
2460}
2461
2462///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
2463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2464#[cfg_attr(feature = "bindings", derive(TS))]
2465pub struct CollationExpr {
2466    pub this: Expression,
2467    pub collation: String,
2468    /// True if the collation was single-quoted in the original SQL (string literal)
2469    #[serde(default)]
2470    pub quoted: bool,
2471    /// True if the collation was double-quoted in the original SQL (identifier)
2472    #[serde(default)]
2473    pub double_quoted: bool,
2474}
2475
2476/// Represent a CASE expression (both simple and searched forms).
2477///
2478/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
2479/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
2480/// Each entry in `whens` is a `(condition, result)` pair.
2481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2482#[cfg_attr(feature = "bindings", derive(TS))]
2483pub struct Case {
2484    /// The operand for simple CASE, or `None` for searched CASE.
2485    pub operand: Option<Expression>,
2486    /// Pairs of (WHEN condition, THEN result).
2487    pub whens: Vec<(Expression, Expression)>,
2488    /// Optional ELSE result.
2489    pub else_: Option<Expression>,
2490}
2491
2492/// Represent a binary operation (two operands separated by an operator).
2493///
2494/// This is the shared payload struct for all binary operator variants in the
2495/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
2496/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
2497/// bitwise, and dialect-specific operators. Comment fields enable round-trip
2498/// preservation of inline comments around operators.
2499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2500#[cfg_attr(feature = "bindings", derive(TS))]
2501pub struct BinaryOp {
2502    pub left: Expression,
2503    pub right: Expression,
2504    /// Comments after the left operand (before the operator)
2505    #[serde(default)]
2506    pub left_comments: Vec<String>,
2507    /// Comments after the operator (before the right operand)
2508    #[serde(default)]
2509    pub operator_comments: Vec<String>,
2510    /// Comments after the right operand
2511    #[serde(default)]
2512    pub trailing_comments: Vec<String>,
2513}
2514
2515impl BinaryOp {
2516    pub fn new(left: Expression, right: Expression) -> Self {
2517        Self {
2518            left,
2519            right,
2520            left_comments: Vec::new(),
2521            operator_comments: Vec::new(),
2522            trailing_comments: Vec::new(),
2523        }
2524    }
2525}
2526
2527/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
2528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2529#[cfg_attr(feature = "bindings", derive(TS))]
2530pub struct LikeOp {
2531    pub left: Expression,
2532    pub right: Expression,
2533    /// ESCAPE character/expression
2534    #[serde(default)]
2535    pub escape: Option<Expression>,
2536    /// Quantifier: ANY, ALL, or SOME
2537    #[serde(default)]
2538    pub quantifier: Option<String>,
2539}
2540
2541impl LikeOp {
2542    pub fn new(left: Expression, right: Expression) -> Self {
2543        Self {
2544            left,
2545            right,
2546            escape: None,
2547            quantifier: None,
2548        }
2549    }
2550
2551    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
2552        Self {
2553            left,
2554            right,
2555            escape: Some(escape),
2556            quantifier: None,
2557        }
2558    }
2559}
2560
2561/// Represent a unary operation (single operand with a prefix operator).
2562///
2563/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
2564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2565#[cfg_attr(feature = "bindings", derive(TS))]
2566pub struct UnaryOp {
2567    /// The operand expression.
2568    pub this: Expression,
2569}
2570
2571impl UnaryOp {
2572    pub fn new(this: Expression) -> Self {
2573        Self { this }
2574    }
2575}
2576
2577/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
2578///
2579/// Either `expressions` (a value list) or `query` (a subquery) is populated,
2580/// but not both. When `not` is true, the predicate is `NOT IN`.
2581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2582#[cfg_attr(feature = "bindings", derive(TS))]
2583pub struct In {
2584    /// The expression being tested.
2585    pub this: Expression,
2586    /// The value list (mutually exclusive with `query`).
2587    pub expressions: Vec<Expression>,
2588    /// A subquery (mutually exclusive with `expressions`).
2589    pub query: Option<Expression>,
2590    /// Whether this is NOT IN.
2591    pub not: bool,
2592    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2593    pub global: bool,
2594    /// BigQuery: IN UNNEST(expr)
2595    #[serde(default, skip_serializing_if = "Option::is_none")]
2596    pub unnest: Option<Box<Expression>>,
2597}
2598
2599/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
2600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2601#[cfg_attr(feature = "bindings", derive(TS))]
2602pub struct Between {
2603    /// The expression being tested.
2604    pub this: Expression,
2605    /// The lower bound.
2606    pub low: Expression,
2607    /// The upper bound.
2608    pub high: Expression,
2609    /// Whether this is NOT BETWEEN.
2610    pub not: bool,
2611}
2612
2613/// IS NULL predicate
2614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2615#[cfg_attr(feature = "bindings", derive(TS))]
2616pub struct IsNull {
2617    pub this: Expression,
2618    pub not: bool,
2619    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
2620    #[serde(default)]
2621    pub postfix_form: bool,
2622}
2623
2624/// IS TRUE / IS FALSE predicate
2625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2626#[cfg_attr(feature = "bindings", derive(TS))]
2627pub struct IsTrueFalse {
2628    pub this: Expression,
2629    pub not: bool,
2630}
2631
2632/// IS JSON predicate (SQL standard)
2633/// Checks if a value is valid JSON
2634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2635#[cfg_attr(feature = "bindings", derive(TS))]
2636pub struct IsJson {
2637    pub this: Expression,
2638    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
2639    pub json_type: Option<String>,
2640    /// Key uniqueness constraint
2641    pub unique_keys: Option<JsonUniqueKeys>,
2642    /// Whether IS NOT JSON
2643    pub negated: bool,
2644}
2645
2646/// JSON unique keys constraint variants
2647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2648#[cfg_attr(feature = "bindings", derive(TS))]
2649pub enum JsonUniqueKeys {
2650    /// WITH UNIQUE KEYS
2651    With,
2652    /// WITHOUT UNIQUE KEYS
2653    Without,
2654    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
2655    Shorthand,
2656}
2657
2658/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
2659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2660#[cfg_attr(feature = "bindings", derive(TS))]
2661pub struct Exists {
2662    /// The subquery expression.
2663    pub this: Expression,
2664    /// Whether this is NOT EXISTS.
2665    pub not: bool,
2666}
2667
2668/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
2669///
2670/// This is the generic function node. Well-known aggregates, window functions,
2671/// and built-in functions each have their own dedicated `Expression` variants
2672/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
2673/// not recognize as built-ins are represented with this struct.
2674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2675#[cfg_attr(feature = "bindings", derive(TS))]
2676pub struct Function {
2677    /// The function name, as originally written (may be schema-qualified).
2678    pub name: String,
2679    /// Positional arguments to the function.
2680    pub args: Vec<Expression>,
2681    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
2682    pub distinct: bool,
2683    #[serde(default)]
2684    pub trailing_comments: Vec<String>,
2685    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
2686    #[serde(default)]
2687    pub use_bracket_syntax: bool,
2688    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
2689    #[serde(default)]
2690    pub no_parens: bool,
2691    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
2692    #[serde(default)]
2693    pub quoted: bool,
2694}
2695
2696impl Default for Function {
2697    fn default() -> Self {
2698        Self {
2699            name: String::new(),
2700            args: Vec::new(),
2701            distinct: false,
2702            trailing_comments: Vec::new(),
2703            use_bracket_syntax: false,
2704            no_parens: false,
2705            quoted: false,
2706        }
2707    }
2708}
2709
2710impl Function {
2711    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
2712        Self {
2713            name: name.into(),
2714            args,
2715            distinct: false,
2716            trailing_comments: Vec::new(),
2717            use_bracket_syntax: false,
2718            no_parens: false,
2719            quoted: false,
2720        }
2721    }
2722}
2723
2724/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
2725///
2726/// This struct is used for aggregate function calls that are not covered by
2727/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
2728/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
2729/// IGNORE NULLS / RESPECT NULLS modifiers.
2730#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2731#[cfg_attr(feature = "bindings", derive(TS))]
2732pub struct AggregateFunction {
2733    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
2734    pub name: String,
2735    /// Positional arguments.
2736    pub args: Vec<Expression>,
2737    /// Whether DISTINCT was specified.
2738    pub distinct: bool,
2739    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
2740    pub filter: Option<Expression>,
2741    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
2742    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2743    pub order_by: Vec<Ordered>,
2744    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
2745    #[serde(default, skip_serializing_if = "Option::is_none")]
2746    pub limit: Option<Box<Expression>>,
2747    /// IGNORE NULLS / RESPECT NULLS
2748    #[serde(default, skip_serializing_if = "Option::is_none")]
2749    pub ignore_nulls: Option<bool>,
2750}
2751
2752/// Represent a window function call with its OVER clause.
2753///
2754/// The inner `this` expression is typically a window-specific expression
2755/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
2756/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
2757/// frame specification.
2758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2759#[cfg_attr(feature = "bindings", derive(TS))]
2760pub struct WindowFunction {
2761    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
2762    pub this: Expression,
2763    /// The OVER clause defining the window partitioning, ordering, and frame.
2764    pub over: Over,
2765    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
2766    #[serde(default, skip_serializing_if = "Option::is_none")]
2767    pub keep: Option<Keep>,
2768}
2769
2770/// Oracle KEEP clause for aggregate functions
2771/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
2772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2773#[cfg_attr(feature = "bindings", derive(TS))]
2774pub struct Keep {
2775    /// true = FIRST, false = LAST
2776    pub first: bool,
2777    /// ORDER BY clause inside KEEP
2778    pub order_by: Vec<Ordered>,
2779}
2780
2781/// WITHIN GROUP clause (for ordered-set aggregate functions)
2782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2783#[cfg_attr(feature = "bindings", derive(TS))]
2784pub struct WithinGroup {
2785    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
2786    pub this: Expression,
2787    /// The ORDER BY clause within the group
2788    pub order_by: Vec<Ordered>,
2789}
2790
2791/// Represent the FROM clause of a SELECT statement.
2792///
2793/// Contains one or more table sources (tables, subqueries, table-valued
2794/// functions, etc.). Multiple entries represent comma-separated implicit joins.
2795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2796#[cfg_attr(feature = "bindings", derive(TS))]
2797pub struct From {
2798    /// The table source expressions.
2799    pub expressions: Vec<Expression>,
2800}
2801
2802/// Represent a JOIN clause between two table sources.
2803///
2804/// The join condition can be specified via `on` (ON predicate) or `using`
2805/// (USING column list), but not both. The `kind` field determines the join
2806/// type (INNER, LEFT, CROSS, etc.).
2807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2808#[cfg_attr(feature = "bindings", derive(TS))]
2809pub struct Join {
2810    /// The right-hand table expression being joined.
2811    pub this: Expression,
2812    /// The ON condition (mutually exclusive with `using`).
2813    pub on: Option<Expression>,
2814    /// The USING column list (mutually exclusive with `on`).
2815    pub using: Vec<Identifier>,
2816    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
2817    pub kind: JoinKind,
2818    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
2819    pub use_inner_keyword: bool,
2820    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
2821    pub use_outer_keyword: bool,
2822    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
2823    pub deferred_condition: bool,
2824    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
2825    #[serde(default, skip_serializing_if = "Option::is_none")]
2826    pub join_hint: Option<String>,
2827    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
2828    #[serde(default, skip_serializing_if = "Option::is_none")]
2829    pub match_condition: Option<Expression>,
2830    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
2831    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2832    pub pivots: Vec<Expression>,
2833}
2834
2835/// Enumerate all supported SQL join types.
2836///
2837/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
2838/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
2839/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
2840/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
2841#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2842#[cfg_attr(feature = "bindings", derive(TS))]
2843pub enum JoinKind {
2844    Inner,
2845    Left,
2846    Right,
2847    Full,
2848    Outer,  // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
2849    Cross,
2850    Natural,
2851    NaturalLeft,
2852    NaturalRight,
2853    NaturalFull,
2854    Semi,
2855    Anti,
2856    // Directional SEMI/ANTI joins
2857    LeftSemi,
2858    LeftAnti,
2859    RightSemi,
2860    RightAnti,
2861    // SQL Server specific
2862    CrossApply,
2863    OuterApply,
2864    // Time-series specific
2865    AsOf,
2866    AsOfLeft,
2867    AsOfRight,
2868    // Lateral join
2869    Lateral,
2870    LeftLateral,
2871    // MySQL specific
2872    Straight,
2873    // Implicit join (comma-separated tables: FROM a, b)
2874    Implicit,
2875    // ClickHouse ARRAY JOIN
2876    Array,
2877    LeftArray,
2878}
2879
2880impl Default for JoinKind {
2881    fn default() -> Self {
2882        JoinKind::Inner
2883    }
2884}
2885
2886/// Parenthesized table expression with joins
2887/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
2888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2889#[cfg_attr(feature = "bindings", derive(TS))]
2890pub struct JoinedTable {
2891    /// The left-hand side table expression
2892    pub left: Expression,
2893    /// The joins applied to the left table
2894    pub joins: Vec<Join>,
2895    /// LATERAL VIEW clauses (Hive/Spark)
2896    pub lateral_views: Vec<LateralView>,
2897    /// Optional alias for the joined table expression
2898    pub alias: Option<Identifier>,
2899}
2900
2901/// Represent a WHERE clause containing a boolean filter predicate.
2902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2903#[cfg_attr(feature = "bindings", derive(TS))]
2904pub struct Where {
2905    /// The filter predicate expression.
2906    pub this: Expression,
2907}
2908
2909/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
2910///
2911/// The `expressions` list may contain plain columns, ordinal positions,
2912/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
2913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2914#[cfg_attr(feature = "bindings", derive(TS))]
2915pub struct GroupBy {
2916    /// The grouping expressions.
2917    pub expressions: Vec<Expression>,
2918    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
2919    #[serde(default)]
2920    pub all: Option<bool>,
2921    /// ClickHouse: WITH TOTALS modifier
2922    #[serde(default)]
2923    pub totals: bool,
2924}
2925
2926/// Represent a HAVING clause containing a predicate over aggregate results.
2927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2928#[cfg_attr(feature = "bindings", derive(TS))]
2929pub struct Having {
2930    /// The filter predicate, typically involving aggregate functions.
2931    pub this: Expression,
2932}
2933
2934/// Represent an ORDER BY clause containing one or more sort specifications.
2935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2936#[cfg_attr(feature = "bindings", derive(TS))]
2937pub struct OrderBy {
2938    /// The sort specifications, each with direction and null ordering.
2939    pub expressions: Vec<Ordered>,
2940    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
2941    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2942    pub siblings: bool,
2943}
2944
2945/// Represent an expression with sort direction and null ordering.
2946///
2947/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
2948/// When `desc` is false the sort is ascending. The `nulls_first` field
2949/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
2950/// (database default).
2951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2952#[cfg_attr(feature = "bindings", derive(TS))]
2953pub struct Ordered {
2954    /// The expression to sort by.
2955    pub this: Expression,
2956    /// Whether the sort direction is descending (true) or ascending (false).
2957    pub desc: bool,
2958    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
2959    pub nulls_first: Option<bool>,
2960    /// Whether ASC was explicitly written (not just implied)
2961    #[serde(default)]
2962    pub explicit_asc: bool,
2963    /// ClickHouse WITH FILL clause
2964    #[serde(default, skip_serializing_if = "Option::is_none")]
2965    pub with_fill: Option<Box<WithFill>>,
2966}
2967
2968impl Ordered {
2969    pub fn asc(expr: Expression) -> Self {
2970        Self {
2971            this: expr,
2972            desc: false,
2973            nulls_first: None,
2974            explicit_asc: false,
2975            with_fill: None,
2976        }
2977    }
2978
2979    pub fn desc(expr: Expression) -> Self {
2980        Self {
2981            this: expr,
2982            desc: true,
2983            nulls_first: None,
2984            explicit_asc: false,
2985            with_fill: None,
2986        }
2987    }
2988}
2989
2990/// DISTRIBUTE BY clause (Hive/Spark)
2991/// Controls how rows are distributed across reducers
2992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2993#[cfg_attr(feature = "bindings", derive(TS))]
2994#[cfg_attr(feature = "bindings", ts(export))]
2995pub struct DistributeBy {
2996    pub expressions: Vec<Expression>,
2997}
2998
2999/// CLUSTER BY clause (Hive/Spark)
3000/// Combines DISTRIBUTE BY and SORT BY on the same columns
3001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3002#[cfg_attr(feature = "bindings", derive(TS))]
3003#[cfg_attr(feature = "bindings", ts(export))]
3004pub struct ClusterBy {
3005    pub expressions: Vec<Ordered>,
3006}
3007
3008/// SORT BY clause (Hive/Spark)
3009/// Sorts data within each reducer (local sort, not global)
3010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3011#[cfg_attr(feature = "bindings", derive(TS))]
3012#[cfg_attr(feature = "bindings", ts(export))]
3013pub struct SortBy {
3014    pub expressions: Vec<Ordered>,
3015}
3016
3017/// LATERAL VIEW clause (Hive/Spark)
3018/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3020#[cfg_attr(feature = "bindings", derive(TS))]
3021#[cfg_attr(feature = "bindings", ts(export))]
3022pub struct LateralView {
3023    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3024    pub this: Expression,
3025    /// Table alias for the generated table
3026    pub table_alias: Option<Identifier>,
3027    /// Column aliases for the generated columns
3028    pub column_aliases: Vec<Identifier>,
3029    /// OUTER keyword - preserve nulls when input is empty/null
3030    pub outer: bool,
3031}
3032
3033/// Query hint
3034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3035#[cfg_attr(feature = "bindings", derive(TS))]
3036#[cfg_attr(feature = "bindings", ts(export))]
3037pub struct Hint {
3038    pub expressions: Vec<HintExpression>,
3039}
3040
3041/// Individual hint expression
3042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3043#[cfg_attr(feature = "bindings", derive(TS))]
3044#[cfg_attr(feature = "bindings", ts(export))]
3045pub enum HintExpression {
3046    /// Function-style hint: USE_HASH(table)
3047    Function { name: String, args: Vec<Expression> },
3048    /// Simple identifier hint: PARALLEL
3049    Identifier(String),
3050    /// Raw hint text (unparsed)
3051    Raw(String),
3052}
3053
3054/// Pseudocolumn type
3055#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3056#[cfg_attr(feature = "bindings", derive(TS))]
3057#[cfg_attr(feature = "bindings", ts(export))]
3058pub enum PseudocolumnType {
3059    Rownum,      // Oracle ROWNUM
3060    Rowid,       // Oracle ROWID
3061    Level,       // Oracle LEVEL (for CONNECT BY)
3062    Sysdate,     // Oracle SYSDATE
3063    ObjectId,    // Oracle OBJECT_ID
3064    ObjectValue, // Oracle OBJECT_VALUE
3065}
3066
3067impl PseudocolumnType {
3068    pub fn as_str(&self) -> &'static str {
3069        match self {
3070            PseudocolumnType::Rownum => "ROWNUM",
3071            PseudocolumnType::Rowid => "ROWID",
3072            PseudocolumnType::Level => "LEVEL",
3073            PseudocolumnType::Sysdate => "SYSDATE",
3074            PseudocolumnType::ObjectId => "OBJECT_ID",
3075            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3076        }
3077    }
3078
3079    pub fn from_str(s: &str) -> Option<Self> {
3080        match s.to_uppercase().as_str() {
3081            "ROWNUM" => Some(PseudocolumnType::Rownum),
3082            "ROWID" => Some(PseudocolumnType::Rowid),
3083            "LEVEL" => Some(PseudocolumnType::Level),
3084            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3085            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3086            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3087            _ => None,
3088        }
3089    }
3090}
3091
3092/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3093/// These are special identifiers that should not be quoted
3094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3095#[cfg_attr(feature = "bindings", derive(TS))]
3096#[cfg_attr(feature = "bindings", ts(export))]
3097pub struct Pseudocolumn {
3098    pub kind: PseudocolumnType,
3099}
3100
3101impl Pseudocolumn {
3102    pub fn rownum() -> Self {
3103        Self { kind: PseudocolumnType::Rownum }
3104    }
3105
3106    pub fn rowid() -> Self {
3107        Self { kind: PseudocolumnType::Rowid }
3108    }
3109
3110    pub fn level() -> Self {
3111        Self { kind: PseudocolumnType::Level }
3112    }
3113}
3114
3115/// Oracle CONNECT BY clause for hierarchical queries
3116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3117#[cfg_attr(feature = "bindings", derive(TS))]
3118#[cfg_attr(feature = "bindings", ts(export))]
3119pub struct Connect {
3120    /// START WITH condition (optional, can come before or after CONNECT BY)
3121    pub start: Option<Expression>,
3122    /// CONNECT BY condition (required, contains PRIOR references)
3123    pub connect: Expression,
3124    /// NOCYCLE keyword to prevent infinite loops
3125    pub nocycle: bool,
3126}
3127
3128/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3130#[cfg_attr(feature = "bindings", derive(TS))]
3131#[cfg_attr(feature = "bindings", ts(export))]
3132pub struct Prior {
3133    pub this: Expression,
3134}
3135
3136/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3138#[cfg_attr(feature = "bindings", derive(TS))]
3139#[cfg_attr(feature = "bindings", ts(export))]
3140pub struct ConnectByRoot {
3141    pub this: Expression,
3142}
3143
3144/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3146#[cfg_attr(feature = "bindings", derive(TS))]
3147#[cfg_attr(feature = "bindings", ts(export))]
3148pub struct MatchRecognize {
3149    /// Source table/expression
3150    pub this: Option<Box<Expression>>,
3151    /// PARTITION BY expressions
3152    pub partition_by: Option<Vec<Expression>>,
3153    /// ORDER BY expressions
3154    pub order_by: Option<Vec<Ordered>>,
3155    /// MEASURES definitions
3156    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3157    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3158    pub rows: Option<MatchRecognizeRows>,
3159    /// AFTER MATCH SKIP behavior
3160    pub after: Option<MatchRecognizeAfter>,
3161    /// PATTERN definition (stored as raw string for complex regex patterns)
3162    pub pattern: Option<String>,
3163    /// DEFINE clauses (pattern variable definitions)
3164    pub define: Option<Vec<(Identifier, Expression)>>,
3165    /// Optional alias for the result
3166    pub alias: Option<Identifier>,
3167    /// Whether AS keyword was explicitly present before alias
3168    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3169    pub alias_explicit_as: bool,
3170}
3171
3172/// MEASURES expression with optional RUNNING/FINAL semantics
3173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3174#[cfg_attr(feature = "bindings", derive(TS))]
3175#[cfg_attr(feature = "bindings", ts(export))]
3176pub struct MatchRecognizeMeasure {
3177    /// The measure expression
3178    pub this: Expression,
3179    /// RUNNING or FINAL semantics (Snowflake-specific)
3180    pub window_frame: Option<MatchRecognizeSemantics>,
3181}
3182
3183/// Semantics for MEASURES in MATCH_RECOGNIZE
3184#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3185#[cfg_attr(feature = "bindings", derive(TS))]
3186#[cfg_attr(feature = "bindings", ts(export))]
3187pub enum MatchRecognizeSemantics {
3188    Running,
3189    Final,
3190}
3191
3192/// Row output semantics for MATCH_RECOGNIZE
3193#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3194#[cfg_attr(feature = "bindings", derive(TS))]
3195#[cfg_attr(feature = "bindings", ts(export))]
3196pub enum MatchRecognizeRows {
3197    OneRowPerMatch,
3198    AllRowsPerMatch,
3199    AllRowsPerMatchShowEmptyMatches,
3200    AllRowsPerMatchOmitEmptyMatches,
3201    AllRowsPerMatchWithUnmatchedRows,
3202}
3203
3204/// AFTER MATCH SKIP behavior
3205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3206#[cfg_attr(feature = "bindings", derive(TS))]
3207#[cfg_attr(feature = "bindings", ts(export))]
3208pub enum MatchRecognizeAfter {
3209    PastLastRow,
3210    ToNextRow,
3211    ToFirst(Identifier),
3212    ToLast(Identifier),
3213}
3214
3215/// Represent a LIMIT clause that restricts the number of returned rows.
3216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3217#[cfg_attr(feature = "bindings", derive(TS))]
3218pub struct Limit {
3219    /// The limit count expression.
3220    pub this: Expression,
3221    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3222    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3223    pub percent: bool,
3224}
3225
3226/// OFFSET clause
3227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3228#[cfg_attr(feature = "bindings", derive(TS))]
3229pub struct Offset {
3230    pub this: Expression,
3231    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3232    #[serde(skip_serializing_if = "Option::is_none", default)]
3233    pub rows: Option<bool>,
3234}
3235
3236/// TOP clause (SQL Server)
3237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3238#[cfg_attr(feature = "bindings", derive(TS))]
3239pub struct Top {
3240    pub this: Expression,
3241    pub percent: bool,
3242    pub with_ties: bool,
3243    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3244    #[serde(default)]
3245    pub parenthesized: bool,
3246}
3247
3248/// FETCH FIRST/NEXT clause (SQL standard)
3249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3250#[cfg_attr(feature = "bindings", derive(TS))]
3251pub struct Fetch {
3252    /// FIRST or NEXT
3253    pub direction: String,
3254    /// Count expression (optional)
3255    pub count: Option<Expression>,
3256    /// PERCENT modifier
3257    pub percent: bool,
3258    /// ROWS or ROW keyword present
3259    pub rows: bool,
3260    /// WITH TIES modifier
3261    pub with_ties: bool,
3262}
3263
3264/// Represent a QUALIFY clause for filtering on window function results.
3265///
3266/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3267/// typically references a window function (e.g.
3268/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3270#[cfg_attr(feature = "bindings", derive(TS))]
3271pub struct Qualify {
3272    /// The filter predicate over window function results.
3273    pub this: Expression,
3274}
3275
3276/// SAMPLE / TABLESAMPLE clause
3277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3278#[cfg_attr(feature = "bindings", derive(TS))]
3279pub struct Sample {
3280    pub method: SampleMethod,
3281    pub size: Expression,
3282    pub seed: Option<Expression>,
3283    /// ClickHouse OFFSET expression after SAMPLE size
3284    #[serde(default)]
3285    pub offset: Option<Expression>,
3286    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3287    pub unit_after_size: bool,
3288    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3289    #[serde(default)]
3290    pub use_sample_keyword: bool,
3291    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3292    #[serde(default)]
3293    pub explicit_method: bool,
3294    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3295    #[serde(default)]
3296    pub method_before_size: bool,
3297    /// Whether SEED keyword was used (true) or REPEATABLE (false)
3298    #[serde(default)]
3299    pub use_seed_keyword: bool,
3300    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
3301    pub bucket_numerator: Option<Box<Expression>>,
3302    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
3303    pub bucket_denominator: Option<Box<Expression>>,
3304    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
3305    pub bucket_field: Option<Box<Expression>>,
3306    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
3307    #[serde(default)]
3308    pub is_using_sample: bool,
3309    /// Whether the unit was explicitly PERCENT (vs ROWS)
3310    #[serde(default)]
3311    pub is_percent: bool,
3312    /// Whether to suppress method output (for cross-dialect transpilation)
3313    #[serde(default)]
3314    pub suppress_method_output: bool,
3315}
3316
3317/// Sample method
3318#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3319#[cfg_attr(feature = "bindings", derive(TS))]
3320pub enum SampleMethod {
3321    Bernoulli,
3322    System,
3323    Block,
3324    Row,
3325    Percent,
3326    /// Hive bucket sampling
3327    Bucket,
3328    /// DuckDB reservoir sampling
3329    Reservoir,
3330}
3331
3332/// Named window definition (WINDOW w AS (...))
3333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3334#[cfg_attr(feature = "bindings", derive(TS))]
3335pub struct NamedWindow {
3336    pub name: Identifier,
3337    pub spec: Over,
3338}
3339
3340/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
3341///
3342/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
3343/// that reference themselves. Each CTE is defined in the `ctes` vector and
3344/// can be referenced by name in subsequent CTEs and in the main query body.
3345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3346#[cfg_attr(feature = "bindings", derive(TS))]
3347pub struct With {
3348    /// The list of CTE definitions, in order.
3349    pub ctes: Vec<Cte>,
3350    /// Whether the WITH RECURSIVE keyword was used.
3351    pub recursive: bool,
3352    /// Leading comments before the statement
3353    #[serde(default)]
3354    pub leading_comments: Vec<String>,
3355    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
3356    #[serde(default, skip_serializing_if = "Option::is_none")]
3357    pub search: Option<Box<Expression>>,
3358}
3359
3360/// Represent a single Common Table Expression definition.
3361///
3362/// A CTE has a name (`alias`), an optional column list, and a body query.
3363/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
3364/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
3365/// the expression comes before the alias (`alias_first`).
3366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3367#[cfg_attr(feature = "bindings", derive(TS))]
3368pub struct Cte {
3369    /// The CTE name.
3370    pub alias: Identifier,
3371    /// The CTE body (typically a SELECT, UNION, etc.).
3372    pub this: Expression,
3373    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
3374    pub columns: Vec<Identifier>,
3375    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
3376    pub materialized: Option<bool>,
3377    /// USING KEY (columns) for DuckDB recursive CTEs
3378    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3379    pub key_expressions: Vec<Identifier>,
3380    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
3381    #[serde(default)]
3382    pub alias_first: bool,
3383}
3384
3385/// Window specification
3386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3387#[cfg_attr(feature = "bindings", derive(TS))]
3388pub struct WindowSpec {
3389    pub partition_by: Vec<Expression>,
3390    pub order_by: Vec<Ordered>,
3391    pub frame: Option<WindowFrame>,
3392}
3393
3394/// OVER clause
3395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3396#[cfg_attr(feature = "bindings", derive(TS))]
3397pub struct Over {
3398    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
3399    pub window_name: Option<Identifier>,
3400    pub partition_by: Vec<Expression>,
3401    pub order_by: Vec<Ordered>,
3402    pub frame: Option<WindowFrame>,
3403    pub alias: Option<Identifier>,
3404}
3405
3406/// Window frame
3407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3408#[cfg_attr(feature = "bindings", derive(TS))]
3409pub struct WindowFrame {
3410    pub kind: WindowFrameKind,
3411    pub start: WindowFrameBound,
3412    pub end: Option<WindowFrameBound>,
3413    pub exclude: Option<WindowFrameExclude>,
3414    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
3415    #[serde(default, skip_serializing_if = "Option::is_none")]
3416    pub kind_text: Option<String>,
3417    /// Original text of the start bound side keyword (e.g. "preceding")
3418    #[serde(default, skip_serializing_if = "Option::is_none")]
3419    pub start_side_text: Option<String>,
3420    /// Original text of the end bound side keyword
3421    #[serde(default, skip_serializing_if = "Option::is_none")]
3422    pub end_side_text: Option<String>,
3423}
3424
3425#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3426#[cfg_attr(feature = "bindings", derive(TS))]
3427pub enum WindowFrameKind {
3428    Rows,
3429    Range,
3430    Groups,
3431}
3432
3433/// EXCLUDE clause for window frames
3434#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3435#[cfg_attr(feature = "bindings", derive(TS))]
3436pub enum WindowFrameExclude {
3437    CurrentRow,
3438    Group,
3439    Ties,
3440    NoOthers,
3441}
3442
3443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3444#[cfg_attr(feature = "bindings", derive(TS))]
3445pub enum WindowFrameBound {
3446    CurrentRow,
3447    UnboundedPreceding,
3448    UnboundedFollowing,
3449    Preceding(Box<Expression>),
3450    Following(Box<Expression>),
3451    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
3452    BarePreceding,
3453    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
3454    BareFollowing,
3455    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
3456    Value(Box<Expression>),
3457}
3458
3459/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
3460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3461#[cfg_attr(feature = "bindings", derive(TS))]
3462pub struct StructField {
3463    pub name: String,
3464    pub data_type: DataType,
3465    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3466    pub options: Vec<Expression>,
3467    #[serde(default, skip_serializing_if = "Option::is_none")]
3468    pub comment: Option<String>,
3469}
3470
3471impl StructField {
3472    /// Create a new struct field without options
3473    pub fn new(name: String, data_type: DataType) -> Self {
3474        Self { name, data_type, options: Vec::new(), comment: None }
3475    }
3476
3477    /// Create a new struct field with options
3478    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
3479        Self { name, data_type, options, comment: None }
3480    }
3481
3482    /// Create a new struct field with options and comment
3483    pub fn with_options_and_comment(name: String, data_type: DataType, options: Vec<Expression>, comment: Option<String>) -> Self {
3484        Self { name, data_type, options, comment }
3485    }
3486}
3487
3488/// Enumerate all SQL data types recognized by the parser.
3489///
3490/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
3491/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
3492/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
3493///
3494/// This enum is used in CAST expressions, column definitions, function return
3495/// types, and anywhere a data type specification appears in SQL.
3496///
3497/// Types that do not match any known variant fall through to `Custom { name }`,
3498/// preserving the original type name for round-trip fidelity.
3499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3500#[cfg_attr(feature = "bindings", derive(TS))]
3501#[serde(tag = "data_type", rename_all = "snake_case")]
3502pub enum DataType {
3503    // Numeric
3504    Boolean,
3505    TinyInt { length: Option<u32> },
3506    SmallInt { length: Option<u32> },
3507    /// Int type with optional length. `integer_spelling` indicates whether the original
3508    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
3509    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
3510    Int { length: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] integer_spelling: bool },
3511    BigInt { length: Option<u32> },
3512    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
3513    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
3514    /// preserve the original spelling.
3515    Float { precision: Option<u32>, scale: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] real_spelling: bool },
3516    Double { precision: Option<u32>, scale: Option<u32> },
3517    Decimal { precision: Option<u32>, scale: Option<u32> },
3518
3519    // String
3520    Char { length: Option<u32> },
3521    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
3522    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
3523    VarChar { length: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] parenthesized_length: bool },
3524    /// String type with optional max length (BigQuery STRING(n))
3525    String { length: Option<u32> },
3526    Text,
3527
3528    // Binary
3529    Binary { length: Option<u32> },
3530    VarBinary { length: Option<u32> },
3531    Blob,
3532
3533    // Bit
3534    Bit { length: Option<u32> },
3535    VarBit { length: Option<u32> },
3536
3537    // Date/Time
3538    Date,
3539    Time { precision: Option<u32>, #[serde(default)] timezone: bool },
3540    Timestamp { precision: Option<u32>, timezone: bool },
3541    Interval {
3542        unit: Option<String>,
3543        /// For range intervals like INTERVAL DAY TO HOUR
3544        #[serde(default, skip_serializing_if = "Option::is_none")]
3545        to: Option<String>,
3546    },
3547
3548    // JSON
3549    Json,
3550    JsonB,
3551
3552    // UUID
3553    Uuid,
3554
3555    // Array
3556    Array {
3557        element_type: Box<DataType>,
3558        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3559        #[serde(default, skip_serializing_if = "Option::is_none")]
3560        dimension: Option<u32>,
3561    },
3562
3563    /// List type (Materialize): INT LIST, TEXT LIST LIST
3564    /// Uses postfix LIST syntax instead of ARRAY<T>
3565    List {
3566        element_type: Box<DataType>,
3567    },
3568
3569    // Struct/Map
3570    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3571    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3572    Struct { fields: Vec<StructField>, nested: bool },
3573    Map { key_type: Box<DataType>, value_type: Box<DataType> },
3574
3575    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3576    Enum { values: Vec<String>, #[serde(default, skip_serializing_if = "Vec::is_empty")] assignments: Vec<Option<String>> },
3577
3578    // Set type (MySQL): SET('a', 'b', 'c')
3579    Set { values: Vec<String> },
3580
3581    // Union type (DuckDB): UNION(num INT, str TEXT)
3582    Union { fields: Vec<(String, DataType)> },
3583
3584    // Vector (Snowflake / SingleStore)
3585    Vector { #[serde(default)] element_type: Option<Box<DataType>>, dimension: Option<u32> },
3586
3587    // Object (Snowflake structured type)
3588    // fields: Vec of (field_name, field_type, not_null)
3589    Object { fields: Vec<(String, DataType, bool)>, modifier: Option<String> },
3590
3591    // Custom/User-defined
3592    Custom { name: String },
3593
3594    // Spatial types
3595    Geometry {
3596        subtype: Option<String>,
3597        srid: Option<u32>,
3598    },
3599    Geography {
3600        subtype: Option<String>,
3601        srid: Option<u32>,
3602    },
3603
3604    // Character Set (for CONVERT USING in MySQL)
3605    // Renders as CHAR CHARACTER SET {name} in cast target
3606    CharacterSet { name: String },
3607
3608    // Unknown
3609    Unknown,
3610}
3611
3612/// Array expression
3613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3614#[cfg_attr(feature = "bindings", derive(TS))]
3615#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3616pub struct Array {
3617    pub expressions: Vec<Expression>,
3618}
3619
3620/// Struct expression
3621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3622#[cfg_attr(feature = "bindings", derive(TS))]
3623pub struct Struct {
3624    pub fields: Vec<(Option<String>, Expression)>,
3625}
3626
3627/// Tuple expression
3628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3629#[cfg_attr(feature = "bindings", derive(TS))]
3630pub struct Tuple {
3631    pub expressions: Vec<Expression>,
3632}
3633
3634/// Interval expression
3635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3636#[cfg_attr(feature = "bindings", derive(TS))]
3637pub struct Interval {
3638    /// The value expression (e.g., '1', 5, column_ref)
3639    pub this: Option<Expression>,
3640    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3641    pub unit: Option<IntervalUnitSpec>,
3642}
3643
3644/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3646#[cfg_attr(feature = "bindings", derive(TS))]
3647#[serde(tag = "type", rename_all = "snake_case")]
3648pub enum IntervalUnitSpec {
3649    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3650    Simple {
3651        unit: IntervalUnit,
3652        /// Whether to use plural form (e.g., DAYS vs DAY)
3653        use_plural: bool,
3654    },
3655    /// Interval span (e.g., HOUR TO SECOND)
3656    Span(IntervalSpan),
3657    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3658    /// The start and end can be expressions like function calls with precision
3659    ExprSpan(IntervalSpanExpr),
3660    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3661    Expr(Box<Expression>),
3662}
3663
3664/// Interval span for ranges like HOUR TO SECOND
3665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3666#[cfg_attr(feature = "bindings", derive(TS))]
3667pub struct IntervalSpan {
3668    /// Start unit (e.g., HOUR)
3669    pub this: IntervalUnit,
3670    /// End unit (e.g., SECOND)
3671    pub expression: IntervalUnit,
3672}
3673
3674/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3675/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3677#[cfg_attr(feature = "bindings", derive(TS))]
3678pub struct IntervalSpanExpr {
3679    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3680    pub this: Box<Expression>,
3681    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
3682    pub expression: Box<Expression>,
3683}
3684
3685#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3686#[cfg_attr(feature = "bindings", derive(TS))]
3687pub enum IntervalUnit {
3688    Year,
3689    Quarter,
3690    Month,
3691    Week,
3692    Day,
3693    Hour,
3694    Minute,
3695    Second,
3696    Millisecond,
3697    Microsecond,
3698}
3699
3700/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
3701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3702#[cfg_attr(feature = "bindings", derive(TS))]
3703pub struct Command {
3704    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
3705    pub this: String,
3706}
3707
3708/// EXEC/EXECUTE statement (TSQL stored procedure call)
3709/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
3710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3711#[cfg_attr(feature = "bindings", derive(TS))]
3712pub struct ExecuteStatement {
3713    /// The procedure name (can be qualified: schema.proc_name)
3714    pub this: Expression,
3715    /// Named parameters: @param=value pairs
3716    #[serde(default)]
3717    pub parameters: Vec<ExecuteParameter>,
3718}
3719
3720/// Named parameter in EXEC statement: @name=value
3721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3722#[cfg_attr(feature = "bindings", derive(TS))]
3723pub struct ExecuteParameter {
3724    /// Parameter name (including @)
3725    pub name: String,
3726    /// Parameter value
3727    pub value: Expression,
3728}
3729
3730/// KILL statement (MySQL/MariaDB)
3731/// KILL [CONNECTION | QUERY] <id>
3732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3733#[cfg_attr(feature = "bindings", derive(TS))]
3734pub struct Kill {
3735    /// The target (process ID or connection ID)
3736    pub this: Expression,
3737    /// Optional kind: "CONNECTION" or "QUERY"
3738    pub kind: Option<String>,
3739}
3740
3741/// Raw/unparsed SQL
3742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3743#[cfg_attr(feature = "bindings", derive(TS))]
3744pub struct Raw {
3745    pub sql: String,
3746}
3747
3748// ============================================================================
3749// Function expression types
3750// ============================================================================
3751
3752/// Generic unary function (takes a single argument)
3753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3754#[cfg_attr(feature = "bindings", derive(TS))]
3755pub struct UnaryFunc {
3756    pub this: Expression,
3757    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
3758    #[serde(skip_serializing_if = "Option::is_none", default)]
3759    pub original_name: Option<String>,
3760}
3761
3762impl UnaryFunc {
3763    /// Create a new UnaryFunc with no original_name
3764    pub fn new(this: Expression) -> Self {
3765        Self { this, original_name: None }
3766    }
3767
3768    /// Create a new UnaryFunc with an original name for round-trip preservation
3769    pub fn with_name(this: Expression, name: String) -> Self {
3770        Self { this, original_name: Some(name) }
3771    }
3772}
3773
3774/// CHAR/CHR function with multiple args and optional USING charset
3775/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
3776/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
3777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3778#[cfg_attr(feature = "bindings", derive(TS))]
3779pub struct CharFunc {
3780    pub args: Vec<Expression>,
3781    #[serde(skip_serializing_if = "Option::is_none", default)]
3782    pub charset: Option<String>,
3783    /// Original function name (CHAR or CHR), defaults to CHAR
3784    #[serde(skip_serializing_if = "Option::is_none", default)]
3785    pub name: Option<String>,
3786}
3787
3788/// Generic binary function (takes two arguments)
3789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3790#[cfg_attr(feature = "bindings", derive(TS))]
3791pub struct BinaryFunc {
3792    pub this: Expression,
3793    pub expression: Expression,
3794    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
3795    #[serde(skip_serializing_if = "Option::is_none", default)]
3796    pub original_name: Option<String>,
3797}
3798
3799/// Variable argument function
3800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3801#[cfg_attr(feature = "bindings", derive(TS))]
3802pub struct VarArgFunc {
3803    pub expressions: Vec<Expression>,
3804    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
3805    #[serde(skip_serializing_if = "Option::is_none", default)]
3806    pub original_name: Option<String>,
3807}
3808
3809/// CONCAT_WS function
3810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3811#[cfg_attr(feature = "bindings", derive(TS))]
3812pub struct ConcatWs {
3813    pub separator: Expression,
3814    pub expressions: Vec<Expression>,
3815}
3816
3817/// SUBSTRING function
3818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3819#[cfg_attr(feature = "bindings", derive(TS))]
3820pub struct SubstringFunc {
3821    pub this: Expression,
3822    pub start: Expression,
3823    pub length: Option<Expression>,
3824    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
3825    #[serde(default)]
3826    pub from_for_syntax: bool,
3827}
3828
3829/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
3830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3831#[cfg_attr(feature = "bindings", derive(TS))]
3832pub struct OverlayFunc {
3833    pub this: Expression,
3834    pub replacement: Expression,
3835    pub from: Expression,
3836    pub length: Option<Expression>,
3837}
3838
3839/// TRIM function
3840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3841#[cfg_attr(feature = "bindings", derive(TS))]
3842pub struct TrimFunc {
3843    pub this: Expression,
3844    pub characters: Option<Expression>,
3845    pub position: TrimPosition,
3846    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
3847    #[serde(default)]
3848    pub sql_standard_syntax: bool,
3849    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
3850    #[serde(default)]
3851    pub position_explicit: bool,
3852}
3853
3854#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3855#[cfg_attr(feature = "bindings", derive(TS))]
3856pub enum TrimPosition {
3857    Both,
3858    Leading,
3859    Trailing,
3860}
3861
3862/// REPLACE function
3863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3864#[cfg_attr(feature = "bindings", derive(TS))]
3865pub struct ReplaceFunc {
3866    pub this: Expression,
3867    pub old: Expression,
3868    pub new: Expression,
3869}
3870
3871/// LEFT/RIGHT function
3872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3873#[cfg_attr(feature = "bindings", derive(TS))]
3874pub struct LeftRightFunc {
3875    pub this: Expression,
3876    pub length: Expression,
3877}
3878
3879/// REPEAT function
3880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3881#[cfg_attr(feature = "bindings", derive(TS))]
3882pub struct RepeatFunc {
3883    pub this: Expression,
3884    pub times: Expression,
3885}
3886
3887/// LPAD/RPAD function
3888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3889#[cfg_attr(feature = "bindings", derive(TS))]
3890pub struct PadFunc {
3891    pub this: Expression,
3892    pub length: Expression,
3893    pub fill: Option<Expression>,
3894}
3895
3896/// SPLIT function
3897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3898#[cfg_attr(feature = "bindings", derive(TS))]
3899pub struct SplitFunc {
3900    pub this: Expression,
3901    pub delimiter: Expression,
3902}
3903
3904/// REGEXP_LIKE function
3905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3906#[cfg_attr(feature = "bindings", derive(TS))]
3907pub struct RegexpFunc {
3908    pub this: Expression,
3909    pub pattern: Expression,
3910    pub flags: Option<Expression>,
3911}
3912
3913/// REGEXP_REPLACE function
3914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3915#[cfg_attr(feature = "bindings", derive(TS))]
3916pub struct RegexpReplaceFunc {
3917    pub this: Expression,
3918    pub pattern: Expression,
3919    pub replacement: Expression,
3920    pub flags: Option<Expression>,
3921}
3922
3923/// REGEXP_EXTRACT function
3924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3925#[cfg_attr(feature = "bindings", derive(TS))]
3926pub struct RegexpExtractFunc {
3927    pub this: Expression,
3928    pub pattern: Expression,
3929    pub group: Option<Expression>,
3930}
3931
3932/// ROUND function
3933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3934#[cfg_attr(feature = "bindings", derive(TS))]
3935pub struct RoundFunc {
3936    pub this: Expression,
3937    pub decimals: Option<Expression>,
3938}
3939
3940/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
3941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3942#[cfg_attr(feature = "bindings", derive(TS))]
3943pub struct FloorFunc {
3944    pub this: Expression,
3945    pub scale: Option<Expression>,
3946    /// Time unit for Druid-style FLOOR(time TO unit) syntax
3947    #[serde(skip_serializing_if = "Option::is_none", default)]
3948    pub to: Option<Expression>,
3949}
3950
3951/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
3952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3953#[cfg_attr(feature = "bindings", derive(TS))]
3954pub struct CeilFunc {
3955    pub this: Expression,
3956    #[serde(skip_serializing_if = "Option::is_none", default)]
3957    pub decimals: Option<Expression>,
3958    /// Time unit for Druid-style CEIL(time TO unit) syntax
3959    #[serde(skip_serializing_if = "Option::is_none", default)]
3960    pub to: Option<Expression>,
3961}
3962
3963/// LOG function
3964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3965#[cfg_attr(feature = "bindings", derive(TS))]
3966pub struct LogFunc {
3967    pub this: Expression,
3968    pub base: Option<Expression>,
3969}
3970
3971/// CURRENT_DATE (no arguments)
3972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3973#[cfg_attr(feature = "bindings", derive(TS))]
3974pub struct CurrentDate;
3975
3976/// CURRENT_TIME
3977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3978#[cfg_attr(feature = "bindings", derive(TS))]
3979pub struct CurrentTime {
3980    pub precision: Option<u32>,
3981}
3982
3983/// CURRENT_TIMESTAMP
3984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3985#[cfg_attr(feature = "bindings", derive(TS))]
3986pub struct CurrentTimestamp {
3987    pub precision: Option<u32>,
3988    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
3989    #[serde(default)]
3990    pub sysdate: bool,
3991}
3992
3993/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
3994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3995#[cfg_attr(feature = "bindings", derive(TS))]
3996pub struct CurrentTimestampLTZ {
3997    pub precision: Option<u32>,
3998}
3999
4000/// AT TIME ZONE expression for timezone conversion
4001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4002#[cfg_attr(feature = "bindings", derive(TS))]
4003pub struct AtTimeZone {
4004    /// The expression to convert
4005    pub this: Expression,
4006    /// The target timezone
4007    pub zone: Expression,
4008}
4009
4010/// DATE_ADD / DATE_SUB function
4011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4012#[cfg_attr(feature = "bindings", derive(TS))]
4013pub struct DateAddFunc {
4014    pub this: Expression,
4015    pub interval: Expression,
4016    pub unit: IntervalUnit,
4017}
4018
4019/// DATEDIFF function
4020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4021#[cfg_attr(feature = "bindings", derive(TS))]
4022pub struct DateDiffFunc {
4023    pub this: Expression,
4024    pub expression: Expression,
4025    pub unit: Option<IntervalUnit>,
4026}
4027
4028/// DATE_TRUNC function
4029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4030#[cfg_attr(feature = "bindings", derive(TS))]
4031pub struct DateTruncFunc {
4032    pub this: Expression,
4033    pub unit: DateTimeField,
4034}
4035
4036/// EXTRACT function
4037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4038#[cfg_attr(feature = "bindings", derive(TS))]
4039pub struct ExtractFunc {
4040    pub this: Expression,
4041    pub field: DateTimeField,
4042}
4043
4044#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4045#[cfg_attr(feature = "bindings", derive(TS))]
4046pub enum DateTimeField {
4047    Year,
4048    Month,
4049    Day,
4050    Hour,
4051    Minute,
4052    Second,
4053    Millisecond,
4054    Microsecond,
4055    DayOfWeek,
4056    DayOfYear,
4057    Week,
4058    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4059    WeekWithModifier(String),
4060    Quarter,
4061    Epoch,
4062    Timezone,
4063    TimezoneHour,
4064    TimezoneMinute,
4065    Date,
4066    Time,
4067    /// Custom datetime field for dialect-specific or arbitrary fields
4068    Custom(String),
4069}
4070
4071/// TO_DATE function
4072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4073#[cfg_attr(feature = "bindings", derive(TS))]
4074pub struct ToDateFunc {
4075    pub this: Expression,
4076    pub format: Option<Expression>,
4077}
4078
4079/// TO_TIMESTAMP function
4080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4081#[cfg_attr(feature = "bindings", derive(TS))]
4082pub struct ToTimestampFunc {
4083    pub this: Expression,
4084    pub format: Option<Expression>,
4085}
4086
4087/// IF function
4088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4089#[cfg_attr(feature = "bindings", derive(TS))]
4090pub struct IfFunc {
4091    pub condition: Expression,
4092    pub true_value: Expression,
4093    pub false_value: Option<Expression>,
4094    /// Original function name (IF, IFF, IIF) for round-trip preservation
4095    #[serde(skip_serializing_if = "Option::is_none", default)]
4096    pub original_name: Option<String>,
4097}
4098
4099/// NVL2 function
4100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4101#[cfg_attr(feature = "bindings", derive(TS))]
4102pub struct Nvl2Func {
4103    pub this: Expression,
4104    pub true_value: Expression,
4105    pub false_value: Expression,
4106}
4107
4108// ============================================================================
4109// Typed Aggregate Function types
4110// ============================================================================
4111
4112/// Generic aggregate function base type
4113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4114#[cfg_attr(feature = "bindings", derive(TS))]
4115pub struct AggFunc {
4116    pub this: Expression,
4117    pub distinct: bool,
4118    pub filter: Option<Expression>,
4119    pub order_by: Vec<Ordered>,
4120    /// Original function name (case-preserving) when parsed from SQL
4121    #[serde(skip_serializing_if = "Option::is_none", default)]
4122    pub name: Option<String>,
4123    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4124    #[serde(skip_serializing_if = "Option::is_none", default)]
4125    pub ignore_nulls: Option<bool>,
4126    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4127    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4128    #[serde(skip_serializing_if = "Option::is_none", default)]
4129    pub having_max: Option<(Box<Expression>, bool)>,
4130    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4131    #[serde(skip_serializing_if = "Option::is_none", default)]
4132    pub limit: Option<Box<Expression>>,
4133}
4134
4135/// COUNT function with optional star
4136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4137#[cfg_attr(feature = "bindings", derive(TS))]
4138pub struct CountFunc {
4139    pub this: Option<Expression>,
4140    pub star: bool,
4141    pub distinct: bool,
4142    pub filter: Option<Expression>,
4143    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4144    #[serde(default, skip_serializing_if = "Option::is_none")]
4145    pub ignore_nulls: Option<bool>,
4146    /// Original function name for case preservation (e.g., "count" or "COUNT")
4147    #[serde(default, skip_serializing_if = "Option::is_none")]
4148    pub original_name: Option<String>,
4149}
4150
4151/// GROUP_CONCAT function (MySQL style)
4152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4153#[cfg_attr(feature = "bindings", derive(TS))]
4154pub struct GroupConcatFunc {
4155    pub this: Expression,
4156    pub separator: Option<Expression>,
4157    pub order_by: Option<Vec<Ordered>>,
4158    pub distinct: bool,
4159    pub filter: Option<Expression>,
4160}
4161
4162/// STRING_AGG function (PostgreSQL/Standard SQL)
4163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4164#[cfg_attr(feature = "bindings", derive(TS))]
4165pub struct StringAggFunc {
4166    pub this: Expression,
4167    #[serde(default)]
4168    pub separator: Option<Expression>,
4169    #[serde(default)]
4170    pub order_by: Option<Vec<Ordered>>,
4171    #[serde(default)]
4172    pub distinct: bool,
4173    #[serde(default)]
4174    pub filter: Option<Expression>,
4175    /// BigQuery LIMIT inside STRING_AGG
4176    #[serde(default, skip_serializing_if = "Option::is_none")]
4177    pub limit: Option<Box<Expression>>,
4178}
4179
4180/// LISTAGG function (Oracle style)
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct ListAggFunc {
4184    pub this: Expression,
4185    pub separator: Option<Expression>,
4186    pub on_overflow: Option<ListAggOverflow>,
4187    pub order_by: Option<Vec<Ordered>>,
4188    pub distinct: bool,
4189    pub filter: Option<Expression>,
4190}
4191
4192/// LISTAGG ON OVERFLOW behavior
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub enum ListAggOverflow {
4196    Error,
4197    Truncate {
4198        filler: Option<Expression>,
4199        with_count: bool,
4200    },
4201}
4202
4203/// SUM_IF / COUNT_IF function
4204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4205#[cfg_attr(feature = "bindings", derive(TS))]
4206pub struct SumIfFunc {
4207    pub this: Expression,
4208    pub condition: Expression,
4209    pub filter: Option<Expression>,
4210}
4211
4212/// APPROX_PERCENTILE function
4213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4214#[cfg_attr(feature = "bindings", derive(TS))]
4215pub struct ApproxPercentileFunc {
4216    pub this: Expression,
4217    pub percentile: Expression,
4218    pub accuracy: Option<Expression>,
4219    pub filter: Option<Expression>,
4220}
4221
4222/// PERCENTILE_CONT / PERCENTILE_DISC function
4223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4224#[cfg_attr(feature = "bindings", derive(TS))]
4225pub struct PercentileFunc {
4226    pub this: Expression,
4227    pub percentile: Expression,
4228    pub order_by: Option<Vec<Ordered>>,
4229    pub filter: Option<Expression>,
4230}
4231
4232// ============================================================================
4233// Typed Window Function types
4234// ============================================================================
4235
4236/// ROW_NUMBER function (no arguments)
4237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4238#[cfg_attr(feature = "bindings", derive(TS))]
4239pub struct RowNumber;
4240
4241/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4243#[cfg_attr(feature = "bindings", derive(TS))]
4244pub struct Rank {
4245    /// DuckDB: RANK(ORDER BY col) - order by inside function
4246    #[serde(default, skip_serializing_if = "Option::is_none")]
4247    pub order_by: Option<Vec<Ordered>>,
4248    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4249    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4250    pub args: Vec<Expression>,
4251}
4252
4253/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4255#[cfg_attr(feature = "bindings", derive(TS))]
4256pub struct DenseRank {
4257    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4258    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4259    pub args: Vec<Expression>,
4260}
4261
4262/// NTILE function (DuckDB allows ORDER BY inside)
4263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4264#[cfg_attr(feature = "bindings", derive(TS))]
4265pub struct NTileFunc {
4266    /// num_buckets is optional to support Databricks NTILE() without arguments
4267    #[serde(default, skip_serializing_if = "Option::is_none")]
4268    pub num_buckets: Option<Expression>,
4269    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4270    #[serde(default, skip_serializing_if = "Option::is_none")]
4271    pub order_by: Option<Vec<Ordered>>,
4272}
4273
4274/// LEAD / LAG function
4275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4276#[cfg_attr(feature = "bindings", derive(TS))]
4277pub struct LeadLagFunc {
4278    pub this: Expression,
4279    pub offset: Option<Expression>,
4280    pub default: Option<Expression>,
4281    pub ignore_nulls: bool,
4282}
4283
4284/// FIRST_VALUE / LAST_VALUE function
4285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4286#[cfg_attr(feature = "bindings", derive(TS))]
4287pub struct ValueFunc {
4288    pub this: Expression,
4289    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4290    #[serde(default, skip_serializing_if = "Option::is_none")]
4291    pub ignore_nulls: Option<bool>,
4292}
4293
4294/// NTH_VALUE function
4295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4296#[cfg_attr(feature = "bindings", derive(TS))]
4297pub struct NthValueFunc {
4298    pub this: Expression,
4299    pub offset: Expression,
4300    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4301    #[serde(default, skip_serializing_if = "Option::is_none")]
4302    pub ignore_nulls: Option<bool>,
4303}
4304
4305/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4307#[cfg_attr(feature = "bindings", derive(TS))]
4308pub struct PercentRank {
4309    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4310    #[serde(default, skip_serializing_if = "Option::is_none")]
4311    pub order_by: Option<Vec<Ordered>>,
4312    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4313    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4314    pub args: Vec<Expression>,
4315}
4316
4317/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4319#[cfg_attr(feature = "bindings", derive(TS))]
4320pub struct CumeDist {
4321    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4322    #[serde(default, skip_serializing_if = "Option::is_none")]
4323    pub order_by: Option<Vec<Ordered>>,
4324    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4325    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4326    pub args: Vec<Expression>,
4327}
4328
4329// ============================================================================
4330// Additional String Function types
4331// ============================================================================
4332
4333/// POSITION/INSTR function
4334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4335#[cfg_attr(feature = "bindings", derive(TS))]
4336pub struct PositionFunc {
4337    pub substring: Expression,
4338    pub string: Expression,
4339    pub start: Option<Expression>,
4340}
4341
4342// ============================================================================
4343// Additional Math Function types
4344// ============================================================================
4345
4346/// RANDOM function (no arguments)
4347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4348#[cfg_attr(feature = "bindings", derive(TS))]
4349pub struct Random;
4350
4351/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4353#[cfg_attr(feature = "bindings", derive(TS))]
4354pub struct Rand {
4355    pub seed: Option<Box<Expression>>,
4356    /// Teradata RANDOM lower bound
4357    #[serde(default)]
4358    pub lower: Option<Box<Expression>>,
4359    /// Teradata RANDOM upper bound
4360    #[serde(default)]
4361    pub upper: Option<Box<Expression>>,
4362}
4363
4364/// TRUNCATE / TRUNC function
4365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4366#[cfg_attr(feature = "bindings", derive(TS))]
4367pub struct TruncateFunc {
4368    pub this: Expression,
4369    pub decimals: Option<Expression>,
4370}
4371
4372/// PI function (no arguments)
4373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4374#[cfg_attr(feature = "bindings", derive(TS))]
4375pub struct Pi;
4376
4377// ============================================================================
4378// Control Flow Function types
4379// ============================================================================
4380
4381/// DECODE function (Oracle style)
4382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4383#[cfg_attr(feature = "bindings", derive(TS))]
4384pub struct DecodeFunc {
4385    pub this: Expression,
4386    pub search_results: Vec<(Expression, Expression)>,
4387    pub default: Option<Expression>,
4388}
4389
4390// ============================================================================
4391// Additional Date/Time Function types
4392// ============================================================================
4393
4394/// DATE_FORMAT / FORMAT_DATE function
4395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4396#[cfg_attr(feature = "bindings", derive(TS))]
4397pub struct DateFormatFunc {
4398    pub this: Expression,
4399    pub format: Expression,
4400}
4401
4402/// FROM_UNIXTIME function
4403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4404#[cfg_attr(feature = "bindings", derive(TS))]
4405pub struct FromUnixtimeFunc {
4406    pub this: Expression,
4407    pub format: Option<Expression>,
4408}
4409
4410/// UNIX_TIMESTAMP function
4411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4412#[cfg_attr(feature = "bindings", derive(TS))]
4413pub struct UnixTimestampFunc {
4414    pub this: Option<Expression>,
4415    pub format: Option<Expression>,
4416}
4417
4418/// MAKE_DATE function
4419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4420#[cfg_attr(feature = "bindings", derive(TS))]
4421pub struct MakeDateFunc {
4422    pub year: Expression,
4423    pub month: Expression,
4424    pub day: Expression,
4425}
4426
4427/// MAKE_TIMESTAMP function
4428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4429#[cfg_attr(feature = "bindings", derive(TS))]
4430pub struct MakeTimestampFunc {
4431    pub year: Expression,
4432    pub month: Expression,
4433    pub day: Expression,
4434    pub hour: Expression,
4435    pub minute: Expression,
4436    pub second: Expression,
4437    pub timezone: Option<Expression>,
4438}
4439
4440/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4442#[cfg_attr(feature = "bindings", derive(TS))]
4443pub struct LastDayFunc {
4444    pub this: Expression,
4445    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4446    #[serde(skip_serializing_if = "Option::is_none", default)]
4447    pub unit: Option<DateTimeField>,
4448}
4449
4450// ============================================================================
4451// Array Function types
4452// ============================================================================
4453
4454/// ARRAY constructor
4455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4456#[cfg_attr(feature = "bindings", derive(TS))]
4457pub struct ArrayConstructor {
4458    pub expressions: Vec<Expression>,
4459    pub bracket_notation: bool,
4460    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4461    pub use_list_keyword: bool,
4462}
4463
4464/// ARRAY_SORT function
4465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4466#[cfg_attr(feature = "bindings", derive(TS))]
4467pub struct ArraySortFunc {
4468    pub this: Expression,
4469    pub comparator: Option<Expression>,
4470    pub desc: bool,
4471    pub nulls_first: Option<bool>,
4472}
4473
4474/// ARRAY_JOIN / ARRAY_TO_STRING function
4475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4476#[cfg_attr(feature = "bindings", derive(TS))]
4477pub struct ArrayJoinFunc {
4478    pub this: Expression,
4479    pub separator: Expression,
4480    pub null_replacement: Option<Expression>,
4481}
4482
4483/// UNNEST function
4484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4485#[cfg_attr(feature = "bindings", derive(TS))]
4486pub struct UnnestFunc {
4487    pub this: Expression,
4488    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4489    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4490    pub expressions: Vec<Expression>,
4491    pub with_ordinality: bool,
4492    pub alias: Option<Identifier>,
4493    /// BigQuery: offset alias for WITH OFFSET AS <name>
4494    #[serde(default, skip_serializing_if = "Option::is_none")]
4495    pub offset_alias: Option<Identifier>,
4496}
4497
4498/// ARRAY_FILTER function (with lambda)
4499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4500#[cfg_attr(feature = "bindings", derive(TS))]
4501pub struct ArrayFilterFunc {
4502    pub this: Expression,
4503    pub filter: Expression,
4504}
4505
4506/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct ArrayTransformFunc {
4510    pub this: Expression,
4511    pub transform: Expression,
4512}
4513
4514/// SEQUENCE / GENERATE_SERIES function
4515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4516#[cfg_attr(feature = "bindings", derive(TS))]
4517pub struct SequenceFunc {
4518    pub start: Expression,
4519    pub stop: Expression,
4520    pub step: Option<Expression>,
4521}
4522
4523// ============================================================================
4524// Struct Function types
4525// ============================================================================
4526
4527/// STRUCT constructor
4528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4529#[cfg_attr(feature = "bindings", derive(TS))]
4530pub struct StructConstructor {
4531    pub fields: Vec<(Option<Identifier>, Expression)>,
4532}
4533
4534/// STRUCT_EXTRACT function
4535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4536#[cfg_attr(feature = "bindings", derive(TS))]
4537pub struct StructExtractFunc {
4538    pub this: Expression,
4539    pub field: Identifier,
4540}
4541
4542/// NAMED_STRUCT function
4543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4544#[cfg_attr(feature = "bindings", derive(TS))]
4545pub struct NamedStructFunc {
4546    pub pairs: Vec<(Expression, Expression)>,
4547}
4548
4549// ============================================================================
4550// Map Function types
4551// ============================================================================
4552
4553/// MAP constructor
4554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4555#[cfg_attr(feature = "bindings", derive(TS))]
4556pub struct MapConstructor {
4557    pub keys: Vec<Expression>,
4558    pub values: Vec<Expression>,
4559    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4560    #[serde(default)]
4561    pub curly_brace_syntax: bool,
4562    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4563    #[serde(default)]
4564    pub with_map_keyword: bool,
4565}
4566
4567/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4569#[cfg_attr(feature = "bindings", derive(TS))]
4570pub struct TransformFunc {
4571    pub this: Expression,
4572    pub transform: Expression,
4573}
4574
4575// ============================================================================
4576// JSON Function types
4577// ============================================================================
4578
4579/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4581#[cfg_attr(feature = "bindings", derive(TS))]
4582pub struct JsonExtractFunc {
4583    pub this: Expression,
4584    pub path: Expression,
4585    pub returning: Option<DataType>,
4586    /// True if parsed from -> or ->> operator syntax
4587    #[serde(default)]
4588    pub arrow_syntax: bool,
4589    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4590    #[serde(default)]
4591    pub hash_arrow_syntax: bool,
4592    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4593    #[serde(default)]
4594    pub wrapper_option: Option<String>,
4595    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4596    #[serde(default)]
4597    pub quotes_option: Option<String>,
4598    /// ON SCALAR STRING flag
4599    #[serde(default)]
4600    pub on_scalar_string: bool,
4601    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4602    #[serde(default)]
4603    pub on_error: Option<String>,
4604}
4605
4606/// JSON path extraction
4607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4608#[cfg_attr(feature = "bindings", derive(TS))]
4609pub struct JsonPathFunc {
4610    pub this: Expression,
4611    pub paths: Vec<Expression>,
4612}
4613
4614/// JSON_OBJECT function
4615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4616#[cfg_attr(feature = "bindings", derive(TS))]
4617pub struct JsonObjectFunc {
4618    pub pairs: Vec<(Expression, Expression)>,
4619    pub null_handling: Option<JsonNullHandling>,
4620    #[serde(default)]
4621    pub with_unique_keys: bool,
4622    #[serde(default)]
4623    pub returning_type: Option<DataType>,
4624    #[serde(default)]
4625    pub format_json: bool,
4626    #[serde(default)]
4627    pub encoding: Option<String>,
4628    /// For JSON_OBJECT(*) syntax
4629    #[serde(default)]
4630    pub star: bool,
4631}
4632
4633/// JSON null handling options
4634#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4635#[cfg_attr(feature = "bindings", derive(TS))]
4636pub enum JsonNullHandling {
4637    NullOnNull,
4638    AbsentOnNull,
4639}
4640
4641/// JSON_SET / JSON_INSERT function
4642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4643#[cfg_attr(feature = "bindings", derive(TS))]
4644pub struct JsonModifyFunc {
4645    pub this: Expression,
4646    pub path_values: Vec<(Expression, Expression)>,
4647}
4648
4649/// JSON_ARRAYAGG function
4650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4651#[cfg_attr(feature = "bindings", derive(TS))]
4652pub struct JsonArrayAggFunc {
4653    pub this: Expression,
4654    pub order_by: Option<Vec<Ordered>>,
4655    pub null_handling: Option<JsonNullHandling>,
4656    pub filter: Option<Expression>,
4657}
4658
4659/// JSON_OBJECTAGG function
4660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4661#[cfg_attr(feature = "bindings", derive(TS))]
4662pub struct JsonObjectAggFunc {
4663    pub key: Expression,
4664    pub value: Expression,
4665    pub null_handling: Option<JsonNullHandling>,
4666    pub filter: Option<Expression>,
4667}
4668
4669// ============================================================================
4670// Type Casting Function types
4671// ============================================================================
4672
4673/// CONVERT function (SQL Server style)
4674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4675#[cfg_attr(feature = "bindings", derive(TS))]
4676pub struct ConvertFunc {
4677    pub this: Expression,
4678    pub to: DataType,
4679    pub style: Option<Expression>,
4680}
4681
4682// ============================================================================
4683// Additional Expression types
4684// ============================================================================
4685
4686/// Lambda expression
4687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4688#[cfg_attr(feature = "bindings", derive(TS))]
4689pub struct LambdaExpr {
4690    pub parameters: Vec<Identifier>,
4691    pub body: Expression,
4692    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
4693    #[serde(default)]
4694    pub colon: bool,
4695    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
4696    /// Maps parameter index to data type
4697    #[serde(default)]
4698    pub parameter_types: Vec<Option<DataType>>,
4699}
4700
4701/// Parameter (parameterized queries)
4702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4703#[cfg_attr(feature = "bindings", derive(TS))]
4704pub struct Parameter {
4705    pub name: Option<String>,
4706    pub index: Option<u32>,
4707    pub style: ParameterStyle,
4708    /// Whether the name was quoted (e.g., @"x" vs @x)
4709    #[serde(default)]
4710    pub quoted: bool,
4711    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
4712    #[serde(default)]
4713    pub expression: Option<String>,
4714}
4715
4716/// Parameter placeholder styles
4717#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4718#[cfg_attr(feature = "bindings", derive(TS))]
4719pub enum ParameterStyle {
4720    Question,        // ?
4721    Dollar,          // $1, $2
4722    DollarBrace,     // ${name} (Databricks, Hive template variables)
4723    Brace,           // {name} (Spark/Databricks widget/template variables)
4724    Colon,           // :name
4725    At,              // @name
4726    DoubleAt,        // @@name (system variables in MySQL/SQL Server)
4727    DoubleDollar,    // $$name
4728    Percent,         // %s, %(name)s (PostgreSQL psycopg2 style)
4729}
4730
4731/// Placeholder expression
4732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4733#[cfg_attr(feature = "bindings", derive(TS))]
4734pub struct Placeholder {
4735    pub index: Option<u32>,
4736}
4737
4738/// Named argument in function call: name => value or name := value
4739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4740#[cfg_attr(feature = "bindings", derive(TS))]
4741pub struct NamedArgument {
4742    pub name: Identifier,
4743    pub value: Expression,
4744    /// The separator used: `=>`, `:=`, or `=`
4745    pub separator: NamedArgSeparator,
4746}
4747
4748/// Separator style for named arguments
4749#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4750#[cfg_attr(feature = "bindings", derive(TS))]
4751pub enum NamedArgSeparator {
4752    /// `=>` (standard SQL, Snowflake, BigQuery)
4753    DArrow,
4754    /// `:=` (Oracle, MySQL)
4755    ColonEq,
4756    /// `=` (simple equals, some dialects)
4757    Eq,
4758}
4759
4760/// TABLE ref or MODEL ref used as a function argument (BigQuery)
4761/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
4762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4763#[cfg_attr(feature = "bindings", derive(TS))]
4764pub struct TableArgument {
4765    /// The keyword prefix: "TABLE" or "MODEL"
4766    pub prefix: String,
4767    /// The table/model reference expression
4768    pub this: Expression,
4769}
4770
4771/// SQL Comment preservation
4772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4773#[cfg_attr(feature = "bindings", derive(TS))]
4774pub struct SqlComment {
4775    pub text: String,
4776    pub is_block: bool,
4777}
4778
4779// ============================================================================
4780// Additional Predicate types
4781// ============================================================================
4782
4783/// SIMILAR TO expression
4784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4785#[cfg_attr(feature = "bindings", derive(TS))]
4786pub struct SimilarToExpr {
4787    pub this: Expression,
4788    pub pattern: Expression,
4789    pub escape: Option<Expression>,
4790    pub not: bool,
4791}
4792
4793/// ANY / ALL quantified expression
4794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4795#[cfg_attr(feature = "bindings", derive(TS))]
4796pub struct QuantifiedExpr {
4797    pub this: Expression,
4798    pub subquery: Expression,
4799    pub op: Option<QuantifiedOp>,
4800}
4801
4802/// Comparison operator for quantified expressions
4803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4804#[cfg_attr(feature = "bindings", derive(TS))]
4805pub enum QuantifiedOp {
4806    Eq,
4807    Neq,
4808    Lt,
4809    Lte,
4810    Gt,
4811    Gte,
4812}
4813
4814/// OVERLAPS expression
4815/// Supports two forms:
4816/// 1. Simple binary: a OVERLAPS b (this, expression are set)
4817/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
4818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4819#[cfg_attr(feature = "bindings", derive(TS))]
4820pub struct OverlapsExpr {
4821    /// Left operand for simple binary form
4822    #[serde(skip_serializing_if = "Option::is_none")]
4823    pub this: Option<Expression>,
4824    /// Right operand for simple binary form
4825    #[serde(skip_serializing_if = "Option::is_none")]
4826    pub expression: Option<Expression>,
4827    /// Left range start for full ANSI form
4828    #[serde(skip_serializing_if = "Option::is_none")]
4829    pub left_start: Option<Expression>,
4830    /// Left range end for full ANSI form
4831    #[serde(skip_serializing_if = "Option::is_none")]
4832    pub left_end: Option<Expression>,
4833    /// Right range start for full ANSI form
4834    #[serde(skip_serializing_if = "Option::is_none")]
4835    pub right_start: Option<Expression>,
4836    /// Right range end for full ANSI form
4837    #[serde(skip_serializing_if = "Option::is_none")]
4838    pub right_end: Option<Expression>,
4839}
4840
4841// ============================================================================
4842// Array/Struct/Map access
4843// ============================================================================
4844
4845/// Subscript access (array[index] or map[key])
4846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4847#[cfg_attr(feature = "bindings", derive(TS))]
4848pub struct Subscript {
4849    pub this: Expression,
4850    pub index: Expression,
4851}
4852
4853/// Dot access (struct.field)
4854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4855#[cfg_attr(feature = "bindings", derive(TS))]
4856pub struct DotAccess {
4857    pub this: Expression,
4858    pub field: Identifier,
4859}
4860
4861/// Method call (expr.method(args))
4862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4863#[cfg_attr(feature = "bindings", derive(TS))]
4864pub struct MethodCall {
4865    pub this: Expression,
4866    pub method: Identifier,
4867    pub args: Vec<Expression>,
4868}
4869
4870/// Array slice (array[start:end])
4871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4872#[cfg_attr(feature = "bindings", derive(TS))]
4873pub struct ArraySlice {
4874    pub this: Expression,
4875    pub start: Option<Expression>,
4876    pub end: Option<Expression>,
4877}
4878
4879// ============================================================================
4880// DDL (Data Definition Language) Statements
4881// ============================================================================
4882
4883/// ON COMMIT behavior for temporary tables
4884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4885#[cfg_attr(feature = "bindings", derive(TS))]
4886pub enum OnCommit {
4887    /// ON COMMIT PRESERVE ROWS
4888    PreserveRows,
4889    /// ON COMMIT DELETE ROWS
4890    DeleteRows,
4891}
4892
4893/// CREATE TABLE statement
4894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4895#[cfg_attr(feature = "bindings", derive(TS))]
4896pub struct CreateTable {
4897    pub name: TableRef,
4898    /// ClickHouse: ON CLUSTER clause for distributed DDL
4899    #[serde(default, skip_serializing_if = "Option::is_none")]
4900    pub on_cluster: Option<OnCluster>,
4901    pub columns: Vec<ColumnDef>,
4902    pub constraints: Vec<TableConstraint>,
4903    pub if_not_exists: bool,
4904    pub temporary: bool,
4905    pub or_replace: bool,
4906    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
4907    #[serde(default, skip_serializing_if = "Option::is_none")]
4908    pub table_modifier: Option<String>,
4909    pub as_select: Option<Expression>,
4910    /// Whether the AS SELECT was wrapped in parentheses
4911    #[serde(default)]
4912    pub as_select_parenthesized: bool,
4913    /// ON COMMIT behavior for temporary tables
4914    #[serde(default)]
4915    pub on_commit: Option<OnCommit>,
4916    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
4917    #[serde(default)]
4918    pub clone_source: Option<TableRef>,
4919    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
4920    #[serde(default, skip_serializing_if = "Option::is_none")]
4921    pub clone_at_clause: Option<Expression>,
4922    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
4923    #[serde(default)]
4924    pub is_copy: bool,
4925    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
4926    #[serde(default)]
4927    pub shallow_clone: bool,
4928    /// Leading comments before the statement
4929    #[serde(default)]
4930    pub leading_comments: Vec<String>,
4931    /// WITH properties (e.g., WITH (FORMAT='parquet'))
4932    #[serde(default)]
4933    pub with_properties: Vec<(String, String)>,
4934    /// Teradata: table options after name before columns (comma-separated)
4935    #[serde(default)]
4936    pub teradata_post_name_options: Vec<String>,
4937    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
4938    #[serde(default)]
4939    pub with_data: Option<bool>,
4940    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
4941    #[serde(default)]
4942    pub with_statistics: Option<bool>,
4943    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
4944    #[serde(default)]
4945    pub teradata_indexes: Vec<TeradataIndex>,
4946    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
4947    #[serde(default)]
4948    pub with_cte: Option<With>,
4949    /// Table properties like DEFAULT COLLATE (BigQuery)
4950    #[serde(default)]
4951    pub properties: Vec<Expression>,
4952    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
4953    #[serde(default, skip_serializing_if = "Option::is_none")]
4954    pub partition_of: Option<Expression>,
4955    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
4956    #[serde(default)]
4957    pub post_table_properties: Vec<Expression>,
4958    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
4959    #[serde(default)]
4960    pub mysql_table_options: Vec<(String, String)>,
4961    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
4962    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4963    pub inherits: Vec<TableRef>,
4964    /// TSQL ON filegroup or ON filegroup (partition_column) clause
4965    #[serde(default, skip_serializing_if = "Option::is_none")]
4966    pub on_property: Option<OnProperty>,
4967    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
4968    #[serde(default)]
4969    pub copy_grants: bool,
4970    /// Snowflake: USING TEMPLATE expression for schema inference
4971    #[serde(default, skip_serializing_if = "Option::is_none")]
4972    pub using_template: Option<Box<Expression>>,
4973    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
4974    #[serde(default, skip_serializing_if = "Option::is_none")]
4975    pub rollup: Option<RollupProperty>,
4976}
4977
4978/// Teradata index specification for CREATE TABLE
4979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4980#[cfg_attr(feature = "bindings", derive(TS))]
4981pub struct TeradataIndex {
4982    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
4983    pub kind: TeradataIndexKind,
4984    /// Optional index name
4985    pub name: Option<String>,
4986    /// Optional column list
4987    pub columns: Vec<String>,
4988}
4989
4990/// Kind of Teradata index
4991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4992#[cfg_attr(feature = "bindings", derive(TS))]
4993pub enum TeradataIndexKind {
4994    /// NO PRIMARY INDEX
4995    NoPrimary,
4996    /// PRIMARY INDEX
4997    Primary,
4998    /// PRIMARY AMP INDEX
4999    PrimaryAmp,
5000    /// UNIQUE INDEX
5001    Unique,
5002    /// UNIQUE PRIMARY INDEX
5003    UniquePrimary,
5004    /// INDEX (secondary, non-primary)
5005    Secondary,
5006}
5007
5008impl CreateTable {
5009    pub fn new(name: impl Into<String>) -> Self {
5010        Self {
5011            name: TableRef::new(name),
5012            on_cluster: None,
5013            columns: Vec::new(),
5014            constraints: Vec::new(),
5015            if_not_exists: false,
5016            temporary: false,
5017            or_replace: false,
5018            table_modifier: None,
5019            as_select: None,
5020            as_select_parenthesized: false,
5021            on_commit: None,
5022            clone_source: None,
5023            clone_at_clause: None,
5024            shallow_clone: false, is_copy: false,
5025            leading_comments: Vec::new(),
5026            with_properties: Vec::new(),
5027            teradata_post_name_options: Vec::new(),
5028            with_data: None,
5029            with_statistics: None,
5030            teradata_indexes: Vec::new(),
5031            with_cte: None,
5032            properties: Vec::new(),
5033            partition_of: None,
5034            post_table_properties: Vec::new(),
5035            mysql_table_options: Vec::new(),
5036            inherits: Vec::new(),
5037            on_property: None,
5038            copy_grants: false,
5039            using_template: None,
5040            rollup: None,
5041        }
5042    }
5043}
5044
5045/// Sort order for PRIMARY KEY ASC/DESC
5046#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5047#[cfg_attr(feature = "bindings", derive(TS))]
5048pub enum SortOrder {
5049    Asc,
5050    Desc,
5051}
5052
5053/// Type of column constraint for tracking order
5054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5055#[cfg_attr(feature = "bindings", derive(TS))]
5056pub enum ConstraintType {
5057    NotNull,
5058    Null,
5059    PrimaryKey,
5060    Unique,
5061    Default,
5062    AutoIncrement,
5063    Collate,
5064    Comment,
5065    References,
5066    Check,
5067    GeneratedAsIdentity,
5068    /// Snowflake: TAG (key='value', ...)
5069    Tags,
5070    /// Computed/generated column
5071    ComputedColumn,
5072    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5073    GeneratedAsRow,
5074    /// MySQL: ON UPDATE expression
5075    OnUpdate,
5076    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5077    Path,
5078    /// Redshift: ENCODE encoding_type
5079    Encode,
5080}
5081
5082/// Column definition in CREATE TABLE
5083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5084#[cfg_attr(feature = "bindings", derive(TS))]
5085pub struct ColumnDef {
5086    pub name: Identifier,
5087    pub data_type: DataType,
5088    pub nullable: Option<bool>,
5089    pub default: Option<Expression>,
5090    pub primary_key: bool,
5091    /// Sort order for PRIMARY KEY (ASC/DESC)
5092    #[serde(default)]
5093    pub primary_key_order: Option<SortOrder>,
5094    pub unique: bool,
5095    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5096    #[serde(default)]
5097    pub unique_nulls_not_distinct: bool,
5098    pub auto_increment: bool,
5099    pub comment: Option<String>,
5100    pub constraints: Vec<ColumnConstraint>,
5101    /// Track original order of constraints for accurate regeneration
5102    #[serde(default)]
5103    pub constraint_order: Vec<ConstraintType>,
5104    /// Teradata: FORMAT 'pattern'
5105    #[serde(default)]
5106    pub format: Option<String>,
5107    /// Teradata: TITLE 'title'
5108    #[serde(default)]
5109    pub title: Option<String>,
5110    /// Teradata: INLINE LENGTH n
5111    #[serde(default)]
5112    pub inline_length: Option<u64>,
5113    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5114    #[serde(default)]
5115    pub compress: Option<Vec<Expression>>,
5116    /// Teradata: CHARACTER SET name
5117    #[serde(default)]
5118    pub character_set: Option<String>,
5119    /// Teradata: UPPERCASE
5120    #[serde(default)]
5121    pub uppercase: bool,
5122    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5123    #[serde(default)]
5124    pub casespecific: Option<bool>,
5125    /// Snowflake: AUTOINCREMENT START value
5126    #[serde(default)]
5127    pub auto_increment_start: Option<Box<Expression>>,
5128    /// Snowflake: AUTOINCREMENT INCREMENT value
5129    #[serde(default)]
5130    pub auto_increment_increment: Option<Box<Expression>>,
5131    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5132    #[serde(default)]
5133    pub auto_increment_order: Option<bool>,
5134    /// MySQL: UNSIGNED modifier
5135    #[serde(default)]
5136    pub unsigned: bool,
5137    /// MySQL: ZEROFILL modifier
5138    #[serde(default)]
5139    pub zerofill: bool,
5140    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5141    #[serde(default, skip_serializing_if = "Option::is_none")]
5142    pub on_update: Option<Expression>,
5143    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5144    #[serde(default, skip_serializing_if = "Option::is_none")]
5145    pub unique_constraint_name: Option<String>,
5146    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5147    #[serde(default, skip_serializing_if = "Option::is_none")]
5148    pub not_null_constraint_name: Option<String>,
5149    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5150    #[serde(default, skip_serializing_if = "Option::is_none")]
5151    pub primary_key_constraint_name: Option<String>,
5152    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5153    #[serde(default, skip_serializing_if = "Option::is_none")]
5154    pub check_constraint_name: Option<String>,
5155    /// BigQuery: OPTIONS (key=value, ...) on column
5156    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5157    pub options: Vec<Expression>,
5158    /// SQLite: Column definition without explicit type
5159    #[serde(default)]
5160    pub no_type: bool,
5161    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5162    #[serde(default, skip_serializing_if = "Option::is_none")]
5163    pub encoding: Option<String>,
5164    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5165    #[serde(default, skip_serializing_if = "Option::is_none")]
5166    pub codec: Option<String>,
5167    /// ClickHouse: EPHEMERAL [expr] modifier
5168    #[serde(default, skip_serializing_if = "Option::is_none")]
5169    pub ephemeral: Option<Option<Box<Expression>>>,
5170    /// ClickHouse: MATERIALIZED expr modifier
5171    #[serde(default, skip_serializing_if = "Option::is_none")]
5172    pub materialized_expr: Option<Box<Expression>>,
5173    /// ClickHouse: ALIAS expr modifier
5174    #[serde(default, skip_serializing_if = "Option::is_none")]
5175    pub alias_expr: Option<Box<Expression>>,
5176    /// ClickHouse: TTL expr modifier on columns
5177    #[serde(default, skip_serializing_if = "Option::is_none")]
5178    pub ttl_expr: Option<Box<Expression>>,
5179    /// TSQL: NOT FOR REPLICATION
5180    #[serde(default)]
5181    pub not_for_replication: bool,
5182}
5183
5184impl ColumnDef {
5185    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5186        Self {
5187            name: Identifier::new(name),
5188            data_type,
5189            nullable: None,
5190            default: None,
5191            primary_key: false,
5192            primary_key_order: None,
5193            unique: false,
5194            unique_nulls_not_distinct: false,
5195            auto_increment: false,
5196            comment: None,
5197            constraints: Vec::new(),
5198            constraint_order: Vec::new(),
5199            format: None,
5200            title: None,
5201            inline_length: None,
5202            compress: None,
5203            character_set: None,
5204            uppercase: false,
5205            casespecific: None,
5206            auto_increment_start: None,
5207            auto_increment_increment: None,
5208            auto_increment_order: None,
5209            unsigned: false,
5210            zerofill: false,
5211            on_update: None,
5212            unique_constraint_name: None,
5213            not_null_constraint_name: None,
5214            primary_key_constraint_name: None,
5215            check_constraint_name: None,
5216            options: Vec::new(),
5217            no_type: false,
5218            encoding: None,
5219            codec: None,
5220            ephemeral: None,
5221            materialized_expr: None,
5222            alias_expr: None,
5223            ttl_expr: None,
5224            not_for_replication: false,
5225        }
5226    }
5227}
5228
5229/// Column-level constraint
5230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5231#[cfg_attr(feature = "bindings", derive(TS))]
5232pub enum ColumnConstraint {
5233    NotNull,
5234    Null,
5235    Unique,
5236    PrimaryKey,
5237    Default(Expression),
5238    Check(Expression),
5239    References(ForeignKeyRef),
5240    GeneratedAsIdentity(GeneratedAsIdentity),
5241    Collate(Identifier),
5242    Comment(String),
5243    /// Snowflake: TAG (key='value', ...)
5244    Tags(Tags),
5245    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5246    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5247    ComputedColumn(ComputedColumn),
5248    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5249    GeneratedAsRow(GeneratedAsRow),
5250    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5251    Path(Expression),
5252}
5253
5254/// Computed/generated column constraint
5255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5256#[cfg_attr(feature = "bindings", derive(TS))]
5257pub struct ComputedColumn {
5258    /// The expression that computes the column value
5259    pub expression: Box<Expression>,
5260    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5261    #[serde(default)]
5262    pub persisted: bool,
5263    /// NOT NULL (TSQL computed columns)
5264    #[serde(default)]
5265    pub not_null: bool,
5266    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5267    /// When None, defaults to dialect-appropriate output
5268    #[serde(default)]
5269    pub persistence_kind: Option<String>,
5270    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5271    #[serde(default, skip_serializing_if = "Option::is_none")]
5272    pub data_type: Option<DataType>,
5273}
5274
5275/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5277#[cfg_attr(feature = "bindings", derive(TS))]
5278pub struct GeneratedAsRow {
5279    /// true = ROW START, false = ROW END
5280    pub start: bool,
5281    /// HIDDEN modifier
5282    #[serde(default)]
5283    pub hidden: bool,
5284}
5285
5286/// Generated identity column constraint
5287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5288#[cfg_attr(feature = "bindings", derive(TS))]
5289pub struct GeneratedAsIdentity {
5290    /// True for ALWAYS, False for BY DEFAULT
5291    pub always: bool,
5292    /// ON NULL (only valid with BY DEFAULT)
5293    pub on_null: bool,
5294    /// START WITH value
5295    pub start: Option<Box<Expression>>,
5296    /// INCREMENT BY value
5297    pub increment: Option<Box<Expression>>,
5298    /// MINVALUE
5299    pub minvalue: Option<Box<Expression>>,
5300    /// MAXVALUE
5301    pub maxvalue: Option<Box<Expression>>,
5302    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5303    pub cycle: Option<bool>,
5304}
5305
5306/// Constraint modifiers (shared between table-level constraints)
5307#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5308#[cfg_attr(feature = "bindings", derive(TS))]
5309pub struct ConstraintModifiers {
5310    /// ENFORCED / NOT ENFORCED
5311    pub enforced: Option<bool>,
5312    /// DEFERRABLE / NOT DEFERRABLE
5313    pub deferrable: Option<bool>,
5314    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5315    pub initially_deferred: Option<bool>,
5316    /// NORELY (Oracle)
5317    pub norely: bool,
5318    /// RELY (Oracle)
5319    pub rely: bool,
5320    /// USING index type (MySQL): BTREE or HASH
5321    #[serde(default)]
5322    pub using: Option<String>,
5323    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5324    #[serde(default)]
5325    pub using_before_columns: bool,
5326    /// MySQL index COMMENT 'text'
5327    #[serde(default, skip_serializing_if = "Option::is_none")]
5328    pub comment: Option<String>,
5329    /// MySQL index VISIBLE/INVISIBLE
5330    #[serde(default, skip_serializing_if = "Option::is_none")]
5331    pub visible: Option<bool>,
5332    /// MySQL ENGINE_ATTRIBUTE = 'value'
5333    #[serde(default, skip_serializing_if = "Option::is_none")]
5334    pub engine_attribute: Option<String>,
5335    /// MySQL WITH PARSER name
5336    #[serde(default, skip_serializing_if = "Option::is_none")]
5337    pub with_parser: Option<String>,
5338    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5339    #[serde(default)]
5340    pub not_valid: bool,
5341    /// TSQL CLUSTERED/NONCLUSTERED modifier
5342    #[serde(default, skip_serializing_if = "Option::is_none")]
5343    pub clustered: Option<String>,
5344    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5345    #[serde(default, skip_serializing_if = "Option::is_none")]
5346    pub on_conflict: Option<String>,
5347    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5348    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5349    pub with_options: Vec<(String, String)>,
5350    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5351    #[serde(default, skip_serializing_if = "Option::is_none")]
5352    pub on_filegroup: Option<Identifier>,
5353}
5354
5355/// Table-level constraint
5356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5357#[cfg_attr(feature = "bindings", derive(TS))]
5358pub enum TableConstraint {
5359    PrimaryKey {
5360        name: Option<Identifier>,
5361        columns: Vec<Identifier>,
5362        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5363        #[serde(default)]
5364        include_columns: Vec<Identifier>,
5365        #[serde(default)]
5366        modifiers: ConstraintModifiers,
5367        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5368        #[serde(default)]
5369        has_constraint_keyword: bool,
5370    },
5371    Unique {
5372        name: Option<Identifier>,
5373        columns: Vec<Identifier>,
5374        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5375        #[serde(default)]
5376        columns_parenthesized: bool,
5377        #[serde(default)]
5378        modifiers: ConstraintModifiers,
5379        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5380        #[serde(default)]
5381        has_constraint_keyword: bool,
5382        /// PostgreSQL 15+: NULLS NOT DISTINCT
5383        #[serde(default)]
5384        nulls_not_distinct: bool,
5385    },
5386    ForeignKey {
5387        name: Option<Identifier>,
5388        columns: Vec<Identifier>,
5389        #[serde(default)]
5390        references: Option<ForeignKeyRef>,
5391        /// ON DELETE action when REFERENCES is absent
5392        #[serde(default)]
5393        on_delete: Option<ReferentialAction>,
5394        /// ON UPDATE action when REFERENCES is absent
5395        #[serde(default)]
5396        on_update: Option<ReferentialAction>,
5397        #[serde(default)]
5398        modifiers: ConstraintModifiers,
5399    },
5400    Check {
5401        name: Option<Identifier>,
5402        expression: Expression,
5403        #[serde(default)]
5404        modifiers: ConstraintModifiers,
5405    },
5406    /// INDEX / KEY constraint (MySQL)
5407    Index {
5408        name: Option<Identifier>,
5409        columns: Vec<Identifier>,
5410        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5411        #[serde(default)]
5412        kind: Option<String>,
5413        #[serde(default)]
5414        modifiers: ConstraintModifiers,
5415        /// True if KEY keyword was used instead of INDEX
5416        #[serde(default)]
5417        use_key_keyword: bool,
5418        /// ClickHouse: indexed expression (instead of columns)
5419        #[serde(default, skip_serializing_if = "Option::is_none")]
5420        expression: Option<Box<Expression>>,
5421        /// ClickHouse: TYPE type_func(args)
5422        #[serde(default, skip_serializing_if = "Option::is_none")]
5423        index_type: Option<Box<Expression>>,
5424        /// ClickHouse: GRANULARITY n
5425        #[serde(default, skip_serializing_if = "Option::is_none")]
5426        granularity: Option<Box<Expression>>,
5427    },
5428    /// ClickHouse PROJECTION definition
5429    Projection {
5430        name: Identifier,
5431        expression: Expression,
5432    },
5433    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5434    Like {
5435        source: TableRef,
5436        /// Options as (INCLUDING|EXCLUDING, property) pairs
5437        options: Vec<(LikeOptionAction, String)>,
5438    },
5439    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5440    PeriodForSystemTime {
5441        start_col: Identifier,
5442        end_col: Identifier,
5443    },
5444    /// PostgreSQL EXCLUDE constraint
5445    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5446    Exclude {
5447        name: Option<Identifier>,
5448        /// Index access method (gist, btree, etc.)
5449        #[serde(default)]
5450        using: Option<String>,
5451        /// Elements: (expression, operator) pairs
5452        elements: Vec<ExcludeElement>,
5453        /// INCLUDE columns
5454        #[serde(default)]
5455        include_columns: Vec<Identifier>,
5456        /// WHERE predicate
5457        #[serde(default)]
5458        where_clause: Option<Box<Expression>>,
5459        /// WITH (storage_parameters)
5460        #[serde(default)]
5461        with_params: Vec<(String, String)>,
5462        /// USING INDEX TABLESPACE tablespace_name
5463        #[serde(default)]
5464        using_index_tablespace: Option<String>,
5465        #[serde(default)]
5466        modifiers: ConstraintModifiers,
5467    },
5468    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5469    Tags(Tags),
5470    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5471    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5472    /// for all deferrable constraints in the table
5473    InitiallyDeferred {
5474        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5475        deferred: bool,
5476    },
5477}
5478
5479/// Element in an EXCLUDE constraint: expression WITH operator
5480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5481#[cfg_attr(feature = "bindings", derive(TS))]
5482pub struct ExcludeElement {
5483    /// The column expression (may include operator class, ordering, nulls)
5484    pub expression: String,
5485    /// The operator (e.g., &&, =)
5486    pub operator: String,
5487}
5488
5489/// Action for LIKE clause options
5490#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5491#[cfg_attr(feature = "bindings", derive(TS))]
5492pub enum LikeOptionAction {
5493    Including,
5494    Excluding,
5495}
5496
5497/// MATCH type for foreign keys
5498#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5499#[cfg_attr(feature = "bindings", derive(TS))]
5500pub enum MatchType {
5501    Full,
5502    Partial,
5503    Simple,
5504}
5505
5506/// Foreign key reference
5507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5508#[cfg_attr(feature = "bindings", derive(TS))]
5509pub struct ForeignKeyRef {
5510    pub table: TableRef,
5511    pub columns: Vec<Identifier>,
5512    pub on_delete: Option<ReferentialAction>,
5513    pub on_update: Option<ReferentialAction>,
5514    /// True if ON UPDATE appears before ON DELETE in the original SQL
5515    #[serde(default)]
5516    pub on_update_first: bool,
5517    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5518    #[serde(default)]
5519    pub match_type: Option<MatchType>,
5520    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5521    #[serde(default)]
5522    pub match_after_actions: bool,
5523    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5524    #[serde(default)]
5525    pub constraint_name: Option<String>,
5526    /// DEFERRABLE / NOT DEFERRABLE
5527    #[serde(default)]
5528    pub deferrable: Option<bool>,
5529    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5530    #[serde(default)]
5531    pub has_foreign_key_keywords: bool,
5532}
5533
5534/// Referential action for foreign keys
5535#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5536#[cfg_attr(feature = "bindings", derive(TS))]
5537pub enum ReferentialAction {
5538    Cascade,
5539    SetNull,
5540    SetDefault,
5541    Restrict,
5542    NoAction,
5543}
5544
5545/// DROP TABLE statement
5546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5547#[cfg_attr(feature = "bindings", derive(TS))]
5548pub struct DropTable {
5549    pub names: Vec<TableRef>,
5550    pub if_exists: bool,
5551    pub cascade: bool,
5552    /// Oracle: CASCADE CONSTRAINTS
5553    #[serde(default)]
5554    pub cascade_constraints: bool,
5555    /// Oracle: PURGE
5556    #[serde(default)]
5557    pub purge: bool,
5558}
5559
5560impl DropTable {
5561    pub fn new(name: impl Into<String>) -> Self {
5562        Self {
5563            names: vec![TableRef::new(name)],
5564            if_exists: false,
5565            cascade: false,
5566            cascade_constraints: false,
5567            purge: false,
5568        }
5569    }
5570}
5571
5572/// ALTER TABLE statement
5573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5574#[cfg_attr(feature = "bindings", derive(TS))]
5575pub struct AlterTable {
5576    pub name: TableRef,
5577    pub actions: Vec<AlterTableAction>,
5578    /// IF EXISTS clause
5579    #[serde(default)]
5580    pub if_exists: bool,
5581    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5582    #[serde(default, skip_serializing_if = "Option::is_none")]
5583    pub algorithm: Option<String>,
5584    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5585    #[serde(default, skip_serializing_if = "Option::is_none")]
5586    pub lock: Option<String>,
5587    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5588    #[serde(default, skip_serializing_if = "Option::is_none")]
5589    pub with_check: Option<String>,
5590    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5591    #[serde(default, skip_serializing_if = "Option::is_none")]
5592    pub partition: Option<Vec<(Identifier, Expression)>>,
5593    /// ClickHouse: ON CLUSTER clause for distributed DDL
5594    #[serde(default, skip_serializing_if = "Option::is_none")]
5595    pub on_cluster: Option<OnCluster>,
5596}
5597
5598impl AlterTable {
5599    pub fn new(name: impl Into<String>) -> Self {
5600        Self {
5601            name: TableRef::new(name),
5602            actions: Vec::new(),
5603            if_exists: false,
5604            algorithm: None,
5605            lock: None,
5606            with_check: None,
5607            partition: None,
5608            on_cluster: None,
5609        }
5610    }
5611}
5612
5613/// Column position for ADD COLUMN (MySQL/MariaDB)
5614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5615#[cfg_attr(feature = "bindings", derive(TS))]
5616pub enum ColumnPosition {
5617    First,
5618    After(Identifier),
5619}
5620
5621/// Actions for ALTER TABLE
5622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5623#[cfg_attr(feature = "bindings", derive(TS))]
5624pub enum AlterTableAction {
5625    AddColumn {
5626        column: ColumnDef,
5627        if_not_exists: bool,
5628        position: Option<ColumnPosition>,
5629    },
5630    DropColumn {
5631        name: Identifier,
5632        if_exists: bool,
5633        cascade: bool,
5634    },
5635    RenameColumn {
5636        old_name: Identifier,
5637        new_name: Identifier,
5638        if_exists: bool,
5639    },
5640    AlterColumn {
5641        name: Identifier,
5642        action: AlterColumnAction,
5643        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5644        #[serde(default)]
5645        use_modify_keyword: bool,
5646    },
5647    RenameTable(TableRef),
5648    AddConstraint(TableConstraint),
5649    DropConstraint {
5650        name: Identifier,
5651        if_exists: bool,
5652    },
5653    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5654    DropForeignKey {
5655        name: Identifier,
5656    },
5657    /// DROP PARTITION action (Hive/BigQuery)
5658    DropPartition {
5659        /// List of partitions to drop (each partition is a list of key=value pairs)
5660        partitions: Vec<Vec<(Identifier, Expression)>>,
5661        if_exists: bool,
5662    },
5663    /// ADD PARTITION action (Hive/Spark)
5664    AddPartition {
5665        /// The partition expression
5666        partition: Expression,
5667        if_not_exists: bool,
5668        location: Option<Expression>,
5669    },
5670    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
5671    Delete {
5672        where_clause: Expression,
5673    },
5674    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
5675    SwapWith(TableRef),
5676    /// SET property action (Snowflake): ALTER TABLE t SET property=value
5677    SetProperty {
5678        properties: Vec<(String, Expression)>,
5679    },
5680    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
5681    UnsetProperty {
5682        properties: Vec<String>,
5683    },
5684    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
5685    ClusterBy {
5686        expressions: Vec<Expression>,
5687    },
5688    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
5689    SetTag {
5690        expressions: Vec<(String, Expression)>,
5691    },
5692    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
5693    UnsetTag {
5694        names: Vec<String>,
5695    },
5696    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
5697    SetOptions {
5698        expressions: Vec<Expression>,
5699    },
5700    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
5701    AlterIndex {
5702        name: Identifier,
5703        visible: bool,
5704    },
5705    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
5706    SetAttribute {
5707        attribute: String,
5708    },
5709    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
5710    SetStageFileFormat {
5711        options: Option<Expression>,
5712    },
5713    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
5714    SetStageCopyOptions {
5715        options: Option<Expression>,
5716    },
5717    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
5718    AddColumns {
5719        columns: Vec<ColumnDef>,
5720        cascade: bool,
5721    },
5722    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
5723    DropColumns {
5724        names: Vec<Identifier>,
5725    },
5726    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
5727    /// In SingleStore, data_type can be omitted for simple column renames
5728    ChangeColumn {
5729        old_name: Identifier,
5730        new_name: Identifier,
5731        #[serde(default, skip_serializing_if = "Option::is_none")]
5732        data_type: Option<DataType>,
5733        comment: Option<String>,
5734        #[serde(default)]
5735        cascade: bool,
5736    },
5737    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
5738    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
5739    AlterSortKey {
5740        /// AUTO or NONE keyword
5741        this: Option<String>,
5742        /// Column list for (col1, col2) syntax
5743        expressions: Vec<Expression>,
5744        /// Whether COMPOUND keyword was present
5745        compound: bool,
5746    },
5747    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
5748    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
5749    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
5750    AlterDistStyle {
5751        /// Distribution style: ALL, EVEN, AUTO, or KEY
5752        style: String,
5753        /// DISTKEY column (only when style is KEY)
5754        distkey: Option<Identifier>,
5755    },
5756    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
5757    SetTableProperties {
5758        properties: Vec<(Expression, Expression)>,
5759    },
5760    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
5761    SetLocation {
5762        location: String,
5763    },
5764    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
5765    SetFileFormat {
5766        format: String,
5767    },
5768    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
5769    ReplacePartition {
5770        partition: Expression,
5771        source: Option<Box<Expression>>,
5772    },
5773}
5774
5775/// Actions for ALTER COLUMN
5776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5777#[cfg_attr(feature = "bindings", derive(TS))]
5778pub enum AlterColumnAction {
5779    SetDataType {
5780        data_type: DataType,
5781        /// USING expression for type conversion (PostgreSQL)
5782        using: Option<Expression>,
5783        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
5784        #[serde(default, skip_serializing_if = "Option::is_none")]
5785        collate: Option<String>,
5786    },
5787    SetDefault(Expression),
5788    DropDefault,
5789    SetNotNull,
5790    DropNotNull,
5791    /// Set column comment
5792    Comment(String),
5793    /// MySQL: SET VISIBLE
5794    SetVisible,
5795    /// MySQL: SET INVISIBLE
5796    SetInvisible,
5797}
5798
5799/// CREATE INDEX statement
5800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5801#[cfg_attr(feature = "bindings", derive(TS))]
5802pub struct CreateIndex {
5803    pub name: Identifier,
5804    pub table: TableRef,
5805    pub columns: Vec<IndexColumn>,
5806    pub unique: bool,
5807    pub if_not_exists: bool,
5808    pub using: Option<String>,
5809    /// TSQL CLUSTERED/NONCLUSTERED modifier
5810    #[serde(default)]
5811    pub clustered: Option<String>,
5812    /// PostgreSQL CONCURRENTLY modifier
5813    #[serde(default)]
5814    pub concurrently: bool,
5815    /// PostgreSQL WHERE clause for partial indexes
5816    #[serde(default)]
5817    pub where_clause: Option<Box<Expression>>,
5818    /// PostgreSQL INCLUDE columns
5819    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5820    pub include_columns: Vec<Identifier>,
5821    /// TSQL WITH options (e.g., allow_page_locks=on)
5822    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5823    pub with_options: Vec<(String, String)>,
5824    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
5825    #[serde(default)]
5826    pub on_filegroup: Option<String>,
5827}
5828
5829impl CreateIndex {
5830    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
5831        Self {
5832            name: Identifier::new(name),
5833            table: TableRef::new(table),
5834            columns: Vec::new(),
5835            unique: false,
5836            if_not_exists: false,
5837            using: None,
5838            clustered: None,
5839            concurrently: false,
5840            where_clause: None,
5841            include_columns: Vec::new(),
5842            with_options: Vec::new(),
5843            on_filegroup: None,
5844        }
5845    }
5846}
5847
5848/// Index column specification
5849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5850#[cfg_attr(feature = "bindings", derive(TS))]
5851pub struct IndexColumn {
5852    pub column: Identifier,
5853    pub desc: bool,
5854    /// Explicit ASC keyword was present
5855    #[serde(default)]
5856    pub asc: bool,
5857    pub nulls_first: Option<bool>,
5858    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
5859    #[serde(default, skip_serializing_if = "Option::is_none")]
5860    pub opclass: Option<String>,
5861}
5862
5863/// DROP INDEX statement
5864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5865#[cfg_attr(feature = "bindings", derive(TS))]
5866pub struct DropIndex {
5867    pub name: Identifier,
5868    pub table: Option<TableRef>,
5869    pub if_exists: bool,
5870    /// PostgreSQL CONCURRENTLY modifier
5871    #[serde(default)]
5872    pub concurrently: bool,
5873}
5874
5875impl DropIndex {
5876    pub fn new(name: impl Into<String>) -> Self {
5877        Self {
5878            name: Identifier::new(name),
5879            table: None,
5880            if_exists: false,
5881            concurrently: false,
5882        }
5883    }
5884}
5885
5886/// View column definition with optional COMMENT and OPTIONS (BigQuery)
5887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5888#[cfg_attr(feature = "bindings", derive(TS))]
5889pub struct ViewColumn {
5890    pub name: Identifier,
5891    pub comment: Option<String>,
5892    /// BigQuery: OPTIONS (key=value, ...) on column
5893    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5894    pub options: Vec<Expression>,
5895}
5896
5897impl ViewColumn {
5898    pub fn new(name: impl Into<String>) -> Self {
5899        Self {
5900            name: Identifier::new(name),
5901            comment: None,
5902            options: Vec::new(),
5903        }
5904    }
5905
5906    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
5907        Self {
5908            name: Identifier::new(name),
5909            comment: Some(comment.into()),
5910            options: Vec::new(),
5911        }
5912    }
5913}
5914
5915/// CREATE VIEW statement
5916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5917#[cfg_attr(feature = "bindings", derive(TS))]
5918pub struct CreateView {
5919    pub name: TableRef,
5920    pub columns: Vec<ViewColumn>,
5921    pub query: Expression,
5922    pub or_replace: bool,
5923    pub if_not_exists: bool,
5924    pub materialized: bool,
5925    pub temporary: bool,
5926    /// Snowflake: SECURE VIEW
5927    #[serde(default)]
5928    pub secure: bool,
5929    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
5930    #[serde(skip_serializing_if = "Option::is_none")]
5931    pub algorithm: Option<String>,
5932    /// MySQL: DEFINER=user@host
5933    #[serde(skip_serializing_if = "Option::is_none")]
5934    pub definer: Option<String>,
5935    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
5936    #[serde(skip_serializing_if = "Option::is_none")]
5937    pub security: Option<FunctionSecurity>,
5938    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
5939    #[serde(default = "default_true")]
5940    pub security_sql_style: bool,
5941    /// Whether the query was parenthesized: AS (SELECT ...)
5942    #[serde(default)]
5943    pub query_parenthesized: bool,
5944    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
5945    #[serde(skip_serializing_if = "Option::is_none")]
5946    pub locking_mode: Option<String>,
5947    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
5948    #[serde(skip_serializing_if = "Option::is_none")]
5949    pub locking_access: Option<String>,
5950    /// Snowflake: COPY GRANTS
5951    #[serde(default)]
5952    pub copy_grants: bool,
5953    /// Snowflake: COMMENT = 'text'
5954    #[serde(skip_serializing_if = "Option::is_none", default)]
5955    pub comment: Option<String>,
5956    /// Snowflake: TAG (name='value', ...)
5957    #[serde(default)]
5958    pub tags: Vec<(String, String)>,
5959    /// BigQuery: OPTIONS (key=value, ...)
5960    #[serde(default)]
5961    pub options: Vec<Expression>,
5962    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
5963    #[serde(skip_serializing_if = "Option::is_none", default)]
5964    pub build: Option<String>,
5965    /// Doris: REFRESH property for materialized views
5966    #[serde(skip_serializing_if = "Option::is_none", default)]
5967    pub refresh: Option<Box<RefreshTriggerProperty>>,
5968    /// Doris: Schema with typed column definitions for materialized views
5969    /// This is used instead of `columns` when the view has typed column definitions
5970    #[serde(skip_serializing_if = "Option::is_none", default)]
5971    pub schema: Option<Box<Schema>>,
5972    /// Doris: KEY (columns) for materialized views
5973    #[serde(skip_serializing_if = "Option::is_none", default)]
5974    pub unique_key: Option<Box<UniqueKeyProperty>>,
5975    /// Redshift: WITH NO SCHEMA BINDING
5976    #[serde(default)]
5977    pub no_schema_binding: bool,
5978    /// Redshift: AUTO REFRESH YES|NO for materialized views
5979    #[serde(skip_serializing_if = "Option::is_none", default)]
5980    pub auto_refresh: Option<bool>,
5981    /// ClickHouse: ON CLUSTER clause
5982    #[serde(default, skip_serializing_if = "Option::is_none")]
5983    pub on_cluster: Option<OnCluster>,
5984    /// ClickHouse: TO destination_table
5985    #[serde(default, skip_serializing_if = "Option::is_none")]
5986    pub to_table: Option<TableRef>,
5987    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
5988    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5989    pub table_properties: Vec<Expression>,
5990}
5991
5992impl CreateView {
5993    pub fn new(name: impl Into<String>, query: Expression) -> Self {
5994        Self {
5995            name: TableRef::new(name),
5996            columns: Vec::new(),
5997            query,
5998            or_replace: false,
5999            if_not_exists: false,
6000            materialized: false,
6001            temporary: false,
6002            secure: false,
6003            algorithm: None,
6004            definer: None,
6005            security: None,
6006            security_sql_style: true,
6007            query_parenthesized: false,
6008            locking_mode: None,
6009            locking_access: None,
6010            copy_grants: false,
6011            comment: None,
6012            tags: Vec::new(),
6013            options: Vec::new(),
6014            build: None,
6015            refresh: None,
6016            schema: None,
6017            unique_key: None,
6018            no_schema_binding: false,
6019            auto_refresh: None,
6020            on_cluster: None,
6021            to_table: None,
6022            table_properties: Vec::new(),
6023        }
6024    }
6025}
6026
6027/// DROP VIEW statement
6028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6029#[cfg_attr(feature = "bindings", derive(TS))]
6030pub struct DropView {
6031    pub name: TableRef,
6032    pub if_exists: bool,
6033    pub materialized: bool,
6034}
6035
6036impl DropView {
6037    pub fn new(name: impl Into<String>) -> Self {
6038        Self {
6039            name: TableRef::new(name),
6040            if_exists: false,
6041            materialized: false,
6042        }
6043    }
6044}
6045
6046/// TRUNCATE TABLE statement
6047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6048#[cfg_attr(feature = "bindings", derive(TS))]
6049pub struct Truncate {
6050    /// Target of TRUNCATE (TABLE vs DATABASE)
6051    #[serde(default)]
6052    pub target: TruncateTarget,
6053    pub table: TableRef,
6054    /// ClickHouse: ON CLUSTER clause for distributed DDL
6055    #[serde(default, skip_serializing_if = "Option::is_none")]
6056    pub on_cluster: Option<OnCluster>,
6057    pub cascade: bool,
6058    /// Additional tables for multi-table TRUNCATE
6059    #[serde(default)]
6060    pub extra_tables: Vec<TruncateTableEntry>,
6061    /// RESTART IDENTITY or CONTINUE IDENTITY
6062    #[serde(default)]
6063    pub identity: Option<TruncateIdentity>,
6064    /// RESTRICT option (alternative to CASCADE)
6065    #[serde(default)]
6066    pub restrict: bool,
6067    /// Hive PARTITION clause: PARTITION(key=value, ...)
6068    #[serde(default, skip_serializing_if = "Option::is_none")]
6069    pub partition: Option<Box<Expression>>,
6070}
6071
6072/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6074#[cfg_attr(feature = "bindings", derive(TS))]
6075pub struct TruncateTableEntry {
6076    pub table: TableRef,
6077    /// Whether the table has a * suffix (inherit children)
6078    #[serde(default)]
6079    pub star: bool,
6080}
6081
6082/// TRUNCATE target type
6083#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6084#[cfg_attr(feature = "bindings", derive(TS))]
6085pub enum TruncateTarget {
6086    Table,
6087    Database,
6088}
6089
6090impl Default for TruncateTarget {
6091    fn default() -> Self {
6092        TruncateTarget::Table
6093    }
6094}
6095
6096/// TRUNCATE identity option
6097#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6098#[cfg_attr(feature = "bindings", derive(TS))]
6099pub enum TruncateIdentity {
6100    Restart,
6101    Continue,
6102}
6103
6104impl Truncate {
6105    pub fn new(table: impl Into<String>) -> Self {
6106        Self {
6107            target: TruncateTarget::Table,
6108            table: TableRef::new(table),
6109            on_cluster: None,
6110            cascade: false,
6111            extra_tables: Vec::new(),
6112            identity: None,
6113            restrict: false,
6114            partition: None,
6115        }
6116    }
6117}
6118
6119/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6121#[cfg_attr(feature = "bindings", derive(TS))]
6122pub struct Use {
6123    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6124    pub kind: Option<UseKind>,
6125    /// The name of the object
6126    pub this: Identifier,
6127}
6128
6129/// Kind of USE statement
6130#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6131#[cfg_attr(feature = "bindings", derive(TS))]
6132pub enum UseKind {
6133    Database,
6134    Schema,
6135    Role,
6136    Warehouse,
6137    Catalog,
6138    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6139    SecondaryRoles,
6140}
6141
6142/// SET variable statement
6143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6144#[cfg_attr(feature = "bindings", derive(TS))]
6145pub struct SetStatement {
6146    /// The items being set
6147    pub items: Vec<SetItem>,
6148}
6149
6150/// A single SET item (variable assignment)
6151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6152#[cfg_attr(feature = "bindings", derive(TS))]
6153pub struct SetItem {
6154    /// The variable name
6155    pub name: Expression,
6156    /// The value to set
6157    pub value: Expression,
6158    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6159    pub kind: Option<String>,
6160    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6161    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6162    pub no_equals: bool,
6163}
6164
6165/// CACHE TABLE statement (Spark)
6166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6167#[cfg_attr(feature = "bindings", derive(TS))]
6168pub struct Cache {
6169    /// The table to cache
6170    pub table: Identifier,
6171    /// LAZY keyword - defer caching until first use
6172    pub lazy: bool,
6173    /// Optional OPTIONS clause (key-value pairs)
6174    pub options: Vec<(Expression, Expression)>,
6175    /// Optional AS clause with query
6176    pub query: Option<Expression>,
6177}
6178
6179/// UNCACHE TABLE statement (Spark)
6180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6181#[cfg_attr(feature = "bindings", derive(TS))]
6182pub struct Uncache {
6183    /// The table to uncache
6184    pub table: Identifier,
6185    /// IF EXISTS clause
6186    pub if_exists: bool,
6187}
6188
6189/// LOAD DATA statement (Hive)
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct LoadData {
6193    /// LOCAL keyword - load from local filesystem
6194    pub local: bool,
6195    /// The path to load data from (INPATH value)
6196    pub inpath: String,
6197    /// Whether to overwrite existing data
6198    pub overwrite: bool,
6199    /// The target table
6200    pub table: Expression,
6201    /// Optional PARTITION clause with key-value pairs
6202    pub partition: Vec<(Identifier, Expression)>,
6203    /// Optional INPUTFORMAT clause
6204    pub input_format: Option<String>,
6205    /// Optional SERDE clause
6206    pub serde: Option<String>,
6207}
6208
6209/// PRAGMA statement (SQLite)
6210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6211#[cfg_attr(feature = "bindings", derive(TS))]
6212pub struct Pragma {
6213    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6214    pub schema: Option<Identifier>,
6215    /// The pragma name
6216    pub name: Identifier,
6217    /// Optional value for assignment (PRAGMA name = value)
6218    pub value: Option<Expression>,
6219    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6220    pub args: Vec<Expression>,
6221}
6222
6223/// A privilege with optional column list for GRANT/REVOKE
6224/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub struct Privilege {
6228    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6229    pub name: String,
6230    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6231    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6232    pub columns: Vec<String>,
6233}
6234
6235/// Principal in GRANT/REVOKE (user, role, etc.)
6236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6237#[cfg_attr(feature = "bindings", derive(TS))]
6238pub struct GrantPrincipal {
6239    /// The name of the principal
6240    pub name: Identifier,
6241    /// Whether prefixed with ROLE keyword
6242    pub is_role: bool,
6243    /// Whether prefixed with GROUP keyword (Redshift)
6244    #[serde(default)]
6245    pub is_group: bool,
6246}
6247
6248/// GRANT statement
6249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6250#[cfg_attr(feature = "bindings", derive(TS))]
6251pub struct Grant {
6252    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6253    pub privileges: Vec<Privilege>,
6254    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6255    pub kind: Option<String>,
6256    /// The object to grant on
6257    pub securable: Identifier,
6258    /// Function parameter types (for FUNCTION kind)
6259    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6260    pub function_params: Vec<String>,
6261    /// The grantees
6262    pub principals: Vec<GrantPrincipal>,
6263    /// WITH GRANT OPTION
6264    pub grant_option: bool,
6265    /// TSQL: AS principal (the grantor role)
6266    #[serde(default, skip_serializing_if = "Option::is_none")]
6267    pub as_principal: Option<Identifier>,
6268}
6269
6270/// REVOKE statement
6271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6272#[cfg_attr(feature = "bindings", derive(TS))]
6273pub struct Revoke {
6274    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6275    pub privileges: Vec<Privilege>,
6276    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6277    pub kind: Option<String>,
6278    /// The object to revoke from
6279    pub securable: Identifier,
6280    /// Function parameter types (for FUNCTION kind)
6281    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6282    pub function_params: Vec<String>,
6283    /// The grantees
6284    pub principals: Vec<GrantPrincipal>,
6285    /// GRANT OPTION FOR
6286    pub grant_option: bool,
6287    /// CASCADE
6288    pub cascade: bool,
6289    /// RESTRICT
6290    #[serde(default)]
6291    pub restrict: bool,
6292}
6293
6294/// COMMENT ON statement
6295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6296#[cfg_attr(feature = "bindings", derive(TS))]
6297pub struct Comment {
6298    /// The object being commented on
6299    pub this: Expression,
6300    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6301    pub kind: String,
6302    /// The comment text expression
6303    pub expression: Expression,
6304    /// IF EXISTS clause
6305    pub exists: bool,
6306    /// MATERIALIZED keyword
6307    pub materialized: bool,
6308}
6309
6310// ============================================================================
6311// Phase 4: Additional DDL Statements
6312// ============================================================================
6313
6314/// ALTER VIEW statement
6315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6316#[cfg_attr(feature = "bindings", derive(TS))]
6317pub struct AlterView {
6318    pub name: TableRef,
6319    pub actions: Vec<AlterViewAction>,
6320    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6321    #[serde(default, skip_serializing_if = "Option::is_none")]
6322    pub algorithm: Option<String>,
6323    /// MySQL: DEFINER = 'user'@'host'
6324    #[serde(default, skip_serializing_if = "Option::is_none")]
6325    pub definer: Option<String>,
6326    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6327    #[serde(default, skip_serializing_if = "Option::is_none")]
6328    pub sql_security: Option<String>,
6329    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6330    #[serde(default, skip_serializing_if = "Option::is_none")]
6331    pub with_option: Option<String>,
6332    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6333    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6334    pub columns: Vec<ViewColumn>,
6335}
6336
6337/// Actions for ALTER VIEW
6338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6339#[cfg_attr(feature = "bindings", derive(TS))]
6340pub enum AlterViewAction {
6341    /// Rename the view
6342    Rename(TableRef),
6343    /// Change owner
6344    OwnerTo(Identifier),
6345    /// Set schema
6346    SetSchema(Identifier),
6347    /// Set authorization (Trino/Presto)
6348    SetAuthorization(String),
6349    /// Alter column
6350    AlterColumn {
6351        name: Identifier,
6352        action: AlterColumnAction,
6353    },
6354    /// Redefine view as query (SELECT, UNION, etc.)
6355    AsSelect(Box<Expression>),
6356    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6357    SetTblproperties(Vec<(String, String)>),
6358    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6359    UnsetTblproperties(Vec<String>),
6360}
6361
6362impl AlterView {
6363    pub fn new(name: impl Into<String>) -> Self {
6364        Self {
6365            name: TableRef::new(name),
6366            actions: Vec::new(),
6367            algorithm: None,
6368            definer: None,
6369            sql_security: None,
6370            with_option: None,
6371            columns: Vec::new(),
6372        }
6373    }
6374}
6375
6376/// ALTER INDEX statement
6377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6378#[cfg_attr(feature = "bindings", derive(TS))]
6379pub struct AlterIndex {
6380    pub name: Identifier,
6381    pub table: Option<TableRef>,
6382    pub actions: Vec<AlterIndexAction>,
6383}
6384
6385/// Actions for ALTER INDEX
6386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6387#[cfg_attr(feature = "bindings", derive(TS))]
6388pub enum AlterIndexAction {
6389    /// Rename the index
6390    Rename(Identifier),
6391    /// Set tablespace
6392    SetTablespace(Identifier),
6393    /// Set visibility (MySQL)
6394    Visible(bool),
6395}
6396
6397impl AlterIndex {
6398    pub fn new(name: impl Into<String>) -> Self {
6399        Self {
6400            name: Identifier::new(name),
6401            table: None,
6402            actions: Vec::new(),
6403        }
6404    }
6405}
6406
6407/// CREATE SCHEMA statement
6408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6409#[cfg_attr(feature = "bindings", derive(TS))]
6410pub struct CreateSchema {
6411    pub name: Identifier,
6412    pub if_not_exists: bool,
6413    pub authorization: Option<Identifier>,
6414    #[serde(default)]
6415    pub clone_from: Option<Identifier>,
6416    /// AT/BEFORE clause for time travel (Snowflake)
6417    #[serde(default)]
6418    pub at_clause: Option<Expression>,
6419    /// Schema properties like DEFAULT COLLATE
6420    #[serde(default)]
6421    pub properties: Vec<Expression>,
6422    /// Leading comments before the statement
6423    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6424    pub leading_comments: Vec<String>,
6425}
6426
6427impl CreateSchema {
6428    pub fn new(name: impl Into<String>) -> Self {
6429        Self {
6430            name: Identifier::new(name),
6431            if_not_exists: false,
6432            authorization: None,
6433            clone_from: None,
6434            at_clause: None,
6435            properties: Vec::new(),
6436            leading_comments: Vec::new(),
6437        }
6438    }
6439}
6440
6441/// DROP SCHEMA statement
6442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6443#[cfg_attr(feature = "bindings", derive(TS))]
6444pub struct DropSchema {
6445    pub name: Identifier,
6446    pub if_exists: bool,
6447    pub cascade: bool,
6448}
6449
6450impl DropSchema {
6451    pub fn new(name: impl Into<String>) -> Self {
6452        Self {
6453            name: Identifier::new(name),
6454            if_exists: false,
6455            cascade: false,
6456        }
6457    }
6458}
6459
6460/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6462#[cfg_attr(feature = "bindings", derive(TS))]
6463pub struct DropNamespace {
6464    pub name: Identifier,
6465    pub if_exists: bool,
6466    pub cascade: bool,
6467}
6468
6469impl DropNamespace {
6470    pub fn new(name: impl Into<String>) -> Self {
6471        Self {
6472            name: Identifier::new(name),
6473            if_exists: false,
6474            cascade: false,
6475        }
6476    }
6477}
6478
6479/// CREATE DATABASE statement
6480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6481#[cfg_attr(feature = "bindings", derive(TS))]
6482pub struct CreateDatabase {
6483    pub name: Identifier,
6484    pub if_not_exists: bool,
6485    pub options: Vec<DatabaseOption>,
6486    /// Snowflake CLONE source
6487    #[serde(default)]
6488    pub clone_from: Option<Identifier>,
6489    /// AT/BEFORE clause for time travel (Snowflake)
6490    #[serde(default)]
6491    pub at_clause: Option<Expression>,
6492}
6493
6494/// Database option
6495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6496#[cfg_attr(feature = "bindings", derive(TS))]
6497pub enum DatabaseOption {
6498    CharacterSet(String),
6499    Collate(String),
6500    Owner(Identifier),
6501    Template(Identifier),
6502    Encoding(String),
6503    Location(String),
6504}
6505
6506impl CreateDatabase {
6507    pub fn new(name: impl Into<String>) -> Self {
6508        Self {
6509            name: Identifier::new(name),
6510            if_not_exists: false,
6511            options: Vec::new(),
6512            clone_from: None,
6513            at_clause: None,
6514        }
6515    }
6516}
6517
6518/// DROP DATABASE statement
6519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6520#[cfg_attr(feature = "bindings", derive(TS))]
6521pub struct DropDatabase {
6522    pub name: Identifier,
6523    pub if_exists: bool,
6524}
6525
6526impl DropDatabase {
6527    pub fn new(name: impl Into<String>) -> Self {
6528        Self {
6529            name: Identifier::new(name),
6530            if_exists: false,
6531        }
6532    }
6533}
6534
6535/// CREATE FUNCTION statement
6536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6537#[cfg_attr(feature = "bindings", derive(TS))]
6538pub struct CreateFunction {
6539    pub name: TableRef,
6540    pub parameters: Vec<FunctionParameter>,
6541    pub return_type: Option<DataType>,
6542    pub body: Option<FunctionBody>,
6543    pub or_replace: bool,
6544    pub if_not_exists: bool,
6545    pub temporary: bool,
6546    pub language: Option<String>,
6547    pub deterministic: Option<bool>,
6548    pub returns_null_on_null_input: Option<bool>,
6549    pub security: Option<FunctionSecurity>,
6550    /// Whether parentheses were present in the original syntax
6551    #[serde(default = "default_true")]
6552    pub has_parens: bool,
6553    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6554    #[serde(default)]
6555    pub sql_data_access: Option<SqlDataAccess>,
6556    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6557    #[serde(default, skip_serializing_if = "Option::is_none")]
6558    pub returns_table_body: Option<String>,
6559    /// True if LANGUAGE clause appears before RETURNS clause
6560    #[serde(default)]
6561    pub language_first: bool,
6562    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6563    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6564    pub set_options: Vec<FunctionSetOption>,
6565    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6566    #[serde(default)]
6567    pub strict: bool,
6568    /// BigQuery: OPTIONS (key=value, ...)
6569    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6570    pub options: Vec<Expression>,
6571    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6572    #[serde(default)]
6573    pub is_table_function: bool,
6574    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6575    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6576    pub property_order: Vec<FunctionPropertyKind>,
6577    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6578    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6579    pub environment: Vec<Expression>,
6580}
6581
6582/// A SET option in CREATE FUNCTION (PostgreSQL)
6583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6584#[cfg_attr(feature = "bindings", derive(TS))]
6585pub struct FunctionSetOption {
6586    pub name: String,
6587    pub value: FunctionSetValue,
6588}
6589
6590/// The value of a SET option
6591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6592#[cfg_attr(feature = "bindings", derive(TS))]
6593pub enum FunctionSetValue {
6594    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6595    Value { value: String, use_to: bool },
6596    /// SET key FROM CURRENT
6597    FromCurrent,
6598}
6599
6600/// SQL data access characteristics for functions
6601#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6602#[cfg_attr(feature = "bindings", derive(TS))]
6603pub enum SqlDataAccess {
6604    /// NO SQL
6605    NoSql,
6606    /// CONTAINS SQL
6607    ContainsSql,
6608    /// READS SQL DATA
6609    ReadsSqlData,
6610    /// MODIFIES SQL DATA
6611    ModifiesSqlData,
6612}
6613
6614/// Types of properties in CREATE FUNCTION for tracking their original order
6615#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6616#[cfg_attr(feature = "bindings", derive(TS))]
6617pub enum FunctionPropertyKind {
6618    /// SET option
6619    Set,
6620    /// AS body
6621    As,
6622    /// LANGUAGE clause
6623    Language,
6624    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6625    Determinism,
6626    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6627    NullInput,
6628    /// SECURITY DEFINER/INVOKER
6629    Security,
6630    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6631    SqlDataAccess,
6632    /// OPTIONS clause (BigQuery)
6633    Options,
6634    /// ENVIRONMENT clause (Databricks)
6635    Environment,
6636}
6637
6638/// Function parameter
6639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6640#[cfg_attr(feature = "bindings", derive(TS))]
6641pub struct FunctionParameter {
6642    pub name: Option<Identifier>,
6643    pub data_type: DataType,
6644    pub mode: Option<ParameterMode>,
6645    pub default: Option<Expression>,
6646}
6647
6648/// Parameter mode (IN, OUT, INOUT)
6649#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub enum ParameterMode {
6652    In,
6653    Out,
6654    InOut,
6655}
6656
6657/// Function body
6658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6659#[cfg_attr(feature = "bindings", derive(TS))]
6660pub enum FunctionBody {
6661    /// AS $$ ... $$ (dollar-quoted)
6662    Block(String),
6663    /// AS 'string' (single-quoted string literal body)
6664    StringLiteral(String),
6665    /// AS 'expression'
6666    Expression(Expression),
6667    /// EXTERNAL NAME 'library'
6668    External(String),
6669    /// RETURN expression
6670    Return(Expression),
6671    /// BEGIN ... END block with parsed statements
6672    Statements(Vec<Expression>),
6673    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
6674    /// Stores (content, optional_tag)
6675    DollarQuoted {
6676        content: String,
6677        tag: Option<String>,
6678    },
6679}
6680
6681/// Function security (DEFINER, INVOKER, or NONE)
6682#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6683#[cfg_attr(feature = "bindings", derive(TS))]
6684pub enum FunctionSecurity {
6685    Definer,
6686    Invoker,
6687    /// StarRocks/MySQL: SECURITY NONE
6688    None,
6689}
6690
6691impl CreateFunction {
6692    pub fn new(name: impl Into<String>) -> Self {
6693        Self {
6694            name: TableRef::new(name),
6695            parameters: Vec::new(),
6696            return_type: None,
6697            body: None,
6698            or_replace: false,
6699            if_not_exists: false,
6700            temporary: false,
6701            language: None,
6702            deterministic: None,
6703            returns_null_on_null_input: None,
6704            security: None,
6705            has_parens: true,
6706            sql_data_access: None,
6707            returns_table_body: None,
6708            language_first: false,
6709            set_options: Vec::new(),
6710            strict: false,
6711            options: Vec::new(),
6712            is_table_function: false,
6713            property_order: Vec::new(),
6714            environment: Vec::new(),
6715        }
6716    }
6717}
6718
6719/// DROP FUNCTION statement
6720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6721#[cfg_attr(feature = "bindings", derive(TS))]
6722pub struct DropFunction {
6723    pub name: TableRef,
6724    pub parameters: Option<Vec<DataType>>,
6725    pub if_exists: bool,
6726    pub cascade: bool,
6727}
6728
6729impl DropFunction {
6730    pub fn new(name: impl Into<String>) -> Self {
6731        Self {
6732            name: TableRef::new(name),
6733            parameters: None,
6734            if_exists: false,
6735            cascade: false,
6736        }
6737    }
6738}
6739
6740/// CREATE PROCEDURE statement
6741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6742#[cfg_attr(feature = "bindings", derive(TS))]
6743pub struct CreateProcedure {
6744    pub name: TableRef,
6745    pub parameters: Vec<FunctionParameter>,
6746    pub body: Option<FunctionBody>,
6747    pub or_replace: bool,
6748    pub if_not_exists: bool,
6749    pub language: Option<String>,
6750    pub security: Option<FunctionSecurity>,
6751    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
6752    #[serde(default)]
6753    pub return_type: Option<DataType>,
6754    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
6755    #[serde(default)]
6756    pub execute_as: Option<String>,
6757    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
6758    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6759    pub with_options: Vec<String>,
6760    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
6761    #[serde(default = "default_true", skip_serializing_if = "is_true")]
6762    pub has_parens: bool,
6763    /// Whether the short form PROC was used (instead of PROCEDURE)
6764    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6765    pub use_proc_keyword: bool,
6766}
6767
6768impl CreateProcedure {
6769    pub fn new(name: impl Into<String>) -> Self {
6770        Self {
6771            name: TableRef::new(name),
6772            parameters: Vec::new(),
6773            body: None,
6774            or_replace: false,
6775            if_not_exists: false,
6776            language: None,
6777            security: None,
6778            return_type: None,
6779            execute_as: None,
6780            with_options: Vec::new(),
6781            has_parens: true,
6782            use_proc_keyword: false,
6783        }
6784    }
6785}
6786
6787/// DROP PROCEDURE statement
6788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6789#[cfg_attr(feature = "bindings", derive(TS))]
6790pub struct DropProcedure {
6791    pub name: TableRef,
6792    pub parameters: Option<Vec<DataType>>,
6793    pub if_exists: bool,
6794    pub cascade: bool,
6795}
6796
6797impl DropProcedure {
6798    pub fn new(name: impl Into<String>) -> Self {
6799        Self {
6800            name: TableRef::new(name),
6801            parameters: None,
6802            if_exists: false,
6803            cascade: false,
6804        }
6805    }
6806}
6807
6808/// Sequence property tag for ordering
6809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6810#[cfg_attr(feature = "bindings", derive(TS))]
6811pub enum SeqPropKind {
6812    Start,
6813    Increment,
6814    Minvalue,
6815    Maxvalue,
6816    Cache,
6817    Cycle,
6818    NoCycle,
6819    OwnedBy,
6820    Order,
6821    NoOrder,
6822    Comment,
6823}
6824
6825/// CREATE SEQUENCE statement
6826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6827#[cfg_attr(feature = "bindings", derive(TS))]
6828pub struct CreateSequence {
6829    pub name: TableRef,
6830    pub if_not_exists: bool,
6831    pub temporary: bool,
6832    pub increment: Option<i64>,
6833    pub minvalue: Option<SequenceBound>,
6834    pub maxvalue: Option<SequenceBound>,
6835    pub start: Option<i64>,
6836    pub cache: Option<i64>,
6837    pub cycle: bool,
6838    pub owned_by: Option<TableRef>,
6839    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
6840    #[serde(default)]
6841    pub order: Option<bool>,
6842    /// Snowflake: COMMENT = 'value'
6843    #[serde(default)]
6844    pub comment: Option<String>,
6845    /// Tracks the order in which properties appeared in the source
6846    #[serde(default)]
6847    pub property_order: Vec<SeqPropKind>,
6848}
6849
6850/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
6851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6852#[cfg_attr(feature = "bindings", derive(TS))]
6853pub enum SequenceBound {
6854    Value(i64),
6855    None,
6856}
6857
6858impl CreateSequence {
6859    pub fn new(name: impl Into<String>) -> Self {
6860        Self {
6861            name: TableRef::new(name),
6862            if_not_exists: false,
6863            temporary: false,
6864            increment: None,
6865            minvalue: None,
6866            maxvalue: None,
6867            start: None,
6868            cache: None,
6869            cycle: false,
6870            owned_by: None,
6871            order: None,
6872            comment: None,
6873            property_order: Vec::new(),
6874        }
6875    }
6876}
6877
6878/// DROP SEQUENCE statement
6879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6880#[cfg_attr(feature = "bindings", derive(TS))]
6881pub struct DropSequence {
6882    pub name: TableRef,
6883    pub if_exists: bool,
6884    pub cascade: bool,
6885}
6886
6887impl DropSequence {
6888    pub fn new(name: impl Into<String>) -> Self {
6889        Self {
6890            name: TableRef::new(name),
6891            if_exists: false,
6892            cascade: false,
6893        }
6894    }
6895}
6896
6897/// ALTER SEQUENCE statement
6898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6899#[cfg_attr(feature = "bindings", derive(TS))]
6900pub struct AlterSequence {
6901    pub name: TableRef,
6902    pub if_exists: bool,
6903    pub increment: Option<i64>,
6904    pub minvalue: Option<SequenceBound>,
6905    pub maxvalue: Option<SequenceBound>,
6906    pub start: Option<i64>,
6907    pub restart: Option<Option<i64>>,
6908    pub cache: Option<i64>,
6909    pub cycle: Option<bool>,
6910    pub owned_by: Option<Option<TableRef>>,
6911}
6912
6913impl AlterSequence {
6914    pub fn new(name: impl Into<String>) -> Self {
6915        Self {
6916            name: TableRef::new(name),
6917            if_exists: false,
6918            increment: None,
6919            minvalue: None,
6920            maxvalue: None,
6921            start: None,
6922            restart: None,
6923            cache: None,
6924            cycle: None,
6925            owned_by: None,
6926        }
6927    }
6928}
6929
6930/// CREATE TRIGGER statement
6931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6932#[cfg_attr(feature = "bindings", derive(TS))]
6933pub struct CreateTrigger {
6934    pub name: Identifier,
6935    pub table: TableRef,
6936    pub timing: TriggerTiming,
6937    pub events: Vec<TriggerEvent>,
6938    pub for_each: TriggerForEach,
6939    pub when: Option<Expression>,
6940    pub body: TriggerBody,
6941    pub or_replace: bool,
6942    pub constraint: bool,
6943    pub deferrable: Option<bool>,
6944    pub initially_deferred: Option<bool>,
6945    pub referencing: Option<TriggerReferencing>,
6946}
6947
6948/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
6949#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6950#[cfg_attr(feature = "bindings", derive(TS))]
6951pub enum TriggerTiming {
6952    Before,
6953    After,
6954    InsteadOf,
6955}
6956
6957/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
6958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6959#[cfg_attr(feature = "bindings", derive(TS))]
6960pub enum TriggerEvent {
6961    Insert,
6962    Update(Option<Vec<Identifier>>),
6963    Delete,
6964    Truncate,
6965}
6966
6967/// Trigger FOR EACH clause
6968#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6969#[cfg_attr(feature = "bindings", derive(TS))]
6970pub enum TriggerForEach {
6971    Row,
6972    Statement,
6973}
6974
6975/// Trigger body
6976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6977#[cfg_attr(feature = "bindings", derive(TS))]
6978pub enum TriggerBody {
6979    /// EXECUTE FUNCTION/PROCEDURE name(args)
6980    Execute {
6981        function: TableRef,
6982        args: Vec<Expression>,
6983    },
6984    /// BEGIN ... END block
6985    Block(String),
6986}
6987
6988/// Trigger REFERENCING clause
6989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6990#[cfg_attr(feature = "bindings", derive(TS))]
6991pub struct TriggerReferencing {
6992    pub old_table: Option<Identifier>,
6993    pub new_table: Option<Identifier>,
6994    pub old_row: Option<Identifier>,
6995    pub new_row: Option<Identifier>,
6996}
6997
6998impl CreateTrigger {
6999    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7000        Self {
7001            name: Identifier::new(name),
7002            table: TableRef::new(table),
7003            timing: TriggerTiming::Before,
7004            events: Vec::new(),
7005            for_each: TriggerForEach::Row,
7006            when: None,
7007            body: TriggerBody::Execute {
7008                function: TableRef::new(""),
7009                args: Vec::new(),
7010            },
7011            or_replace: false,
7012            constraint: false,
7013            deferrable: None,
7014            initially_deferred: None,
7015            referencing: None,
7016        }
7017    }
7018}
7019
7020/// DROP TRIGGER statement
7021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7022#[cfg_attr(feature = "bindings", derive(TS))]
7023pub struct DropTrigger {
7024    pub name: Identifier,
7025    pub table: Option<TableRef>,
7026    pub if_exists: bool,
7027    pub cascade: bool,
7028}
7029
7030impl DropTrigger {
7031    pub fn new(name: impl Into<String>) -> Self {
7032        Self {
7033            name: Identifier::new(name),
7034            table: None,
7035            if_exists: false,
7036            cascade: false,
7037        }
7038    }
7039}
7040
7041/// CREATE TYPE statement
7042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7043#[cfg_attr(feature = "bindings", derive(TS))]
7044pub struct CreateType {
7045    pub name: TableRef,
7046    pub definition: TypeDefinition,
7047    pub if_not_exists: bool,
7048}
7049
7050/// Type definition
7051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7052#[cfg_attr(feature = "bindings", derive(TS))]
7053pub enum TypeDefinition {
7054    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7055    Enum(Vec<String>),
7056    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7057    Composite(Vec<TypeAttribute>),
7058    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7059    Range {
7060        subtype: DataType,
7061        subtype_diff: Option<String>,
7062        canonical: Option<String>,
7063    },
7064    /// Base type (for advanced usage)
7065    Base {
7066        input: String,
7067        output: String,
7068        internallength: Option<i32>,
7069    },
7070    /// Domain type
7071    Domain {
7072        base_type: DataType,
7073        default: Option<Expression>,
7074        constraints: Vec<DomainConstraint>,
7075    },
7076}
7077
7078/// Type attribute for composite types
7079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7080#[cfg_attr(feature = "bindings", derive(TS))]
7081pub struct TypeAttribute {
7082    pub name: Identifier,
7083    pub data_type: DataType,
7084    pub collate: Option<Identifier>,
7085}
7086
7087/// Domain constraint
7088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7089#[cfg_attr(feature = "bindings", derive(TS))]
7090pub struct DomainConstraint {
7091    pub name: Option<Identifier>,
7092    pub check: Expression,
7093}
7094
7095impl CreateType {
7096    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7097        Self {
7098            name: TableRef::new(name),
7099            definition: TypeDefinition::Enum(values),
7100            if_not_exists: false,
7101        }
7102    }
7103
7104    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7105        Self {
7106            name: TableRef::new(name),
7107            definition: TypeDefinition::Composite(attributes),
7108            if_not_exists: false,
7109        }
7110    }
7111}
7112
7113/// DROP TYPE statement
7114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7115#[cfg_attr(feature = "bindings", derive(TS))]
7116pub struct DropType {
7117    pub name: TableRef,
7118    pub if_exists: bool,
7119    pub cascade: bool,
7120}
7121
7122impl DropType {
7123    pub fn new(name: impl Into<String>) -> Self {
7124        Self {
7125            name: TableRef::new(name),
7126            if_exists: false,
7127            cascade: false,
7128        }
7129    }
7130}
7131
7132/// DESCRIBE statement - shows table structure or query plan
7133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7134#[cfg_attr(feature = "bindings", derive(TS))]
7135pub struct Describe {
7136    /// The target to describe (table name or query)
7137    pub target: Expression,
7138    /// EXTENDED format
7139    pub extended: bool,
7140    /// FORMATTED format
7141    pub formatted: bool,
7142    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7143    #[serde(default)]
7144    pub kind: Option<String>,
7145    /// Properties like type=stage
7146    #[serde(default)]
7147    pub properties: Vec<(String, String)>,
7148    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7149    #[serde(default, skip_serializing_if = "Option::is_none")]
7150    pub style: Option<String>,
7151    /// Partition specification for DESCRIBE PARTITION
7152    #[serde(default)]
7153    pub partition: Option<Box<Expression>>,
7154    /// Leading comments before the statement
7155    #[serde(default)]
7156    pub leading_comments: Vec<String>,
7157}
7158
7159impl Describe {
7160    pub fn new(target: Expression) -> Self {
7161        Self {
7162            target,
7163            extended: false,
7164            formatted: false,
7165            kind: None,
7166            properties: Vec::new(),
7167            style: None,
7168            partition: None,
7169            leading_comments: Vec::new(),
7170        }
7171    }
7172}
7173
7174/// SHOW statement - displays database objects
7175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7176#[cfg_attr(feature = "bindings", derive(TS))]
7177pub struct Show {
7178    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7179    pub this: String,
7180    /// Whether TERSE was specified
7181    #[serde(default)]
7182    pub terse: bool,
7183    /// Whether HISTORY was specified
7184    #[serde(default)]
7185    pub history: bool,
7186    /// LIKE pattern
7187    pub like: Option<Expression>,
7188    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7189    pub scope_kind: Option<String>,
7190    /// IN scope object
7191    pub scope: Option<Expression>,
7192    /// STARTS WITH pattern
7193    pub starts_with: Option<Expression>,
7194    /// LIMIT clause
7195    pub limit: Option<Box<Limit>>,
7196    /// FROM clause (for specific object)
7197    pub from: Option<Expression>,
7198    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7199    #[serde(default, skip_serializing_if = "Option::is_none")]
7200    pub where_clause: Option<Expression>,
7201    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7202    #[serde(default, skip_serializing_if = "Option::is_none")]
7203    pub for_target: Option<Expression>,
7204    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7205    #[serde(default, skip_serializing_if = "Option::is_none")]
7206    pub db: Option<Expression>,
7207    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7208    #[serde(default, skip_serializing_if = "Option::is_none")]
7209    pub target: Option<Expression>,
7210    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7211    #[serde(default, skip_serializing_if = "Option::is_none")]
7212    pub mutex: Option<bool>,
7213    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7214    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7215    pub privileges: Vec<String>,
7216}
7217
7218impl Show {
7219    pub fn new(this: impl Into<String>) -> Self {
7220        Self {
7221            this: this.into(),
7222            terse: false,
7223            history: false,
7224            like: None,
7225            scope_kind: None,
7226            scope: None,
7227            starts_with: None,
7228            limit: None,
7229            from: None,
7230            where_clause: None,
7231            for_target: None,
7232            db: None,
7233            target: None,
7234            mutex: None,
7235            privileges: Vec::new(),
7236        }
7237    }
7238}
7239
7240/// Represent an explicit parenthesized expression for grouping precedence.
7241///
7242/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7243/// correctly instead of being flattened to `a + b * c`.
7244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7245#[cfg_attr(feature = "bindings", derive(TS))]
7246pub struct Paren {
7247    /// The inner expression wrapped by parentheses.
7248    pub this: Expression,
7249    #[serde(default)]
7250    pub trailing_comments: Vec<String>,
7251}
7252
7253/// Expression annotated with trailing comments (for round-trip preservation)
7254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7255#[cfg_attr(feature = "bindings", derive(TS))]
7256pub struct Annotated {
7257    pub this: Expression,
7258    pub trailing_comments: Vec<String>,
7259}
7260
7261
7262// === BATCH GENERATED STRUCT DEFINITIONS ===
7263// Generated from Python sqlglot expressions.py
7264
7265/// Refresh
7266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7267#[cfg_attr(feature = "bindings", derive(TS))]
7268pub struct Refresh {
7269    pub this: Box<Expression>,
7270    pub kind: String,
7271}
7272
7273/// LockingStatement
7274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7275#[cfg_attr(feature = "bindings", derive(TS))]
7276pub struct LockingStatement {
7277    pub this: Box<Expression>,
7278    pub expression: Box<Expression>,
7279}
7280
7281/// SequenceProperties
7282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7283#[cfg_attr(feature = "bindings", derive(TS))]
7284pub struct SequenceProperties {
7285    #[serde(default)]
7286    pub increment: Option<Box<Expression>>,
7287    #[serde(default)]
7288    pub minvalue: Option<Box<Expression>>,
7289    #[serde(default)]
7290    pub maxvalue: Option<Box<Expression>>,
7291    #[serde(default)]
7292    pub cache: Option<Box<Expression>>,
7293    #[serde(default)]
7294    pub start: Option<Box<Expression>>,
7295    #[serde(default)]
7296    pub owned: Option<Box<Expression>>,
7297    #[serde(default)]
7298    pub options: Vec<Expression>,
7299}
7300
7301/// TruncateTable
7302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7303#[cfg_attr(feature = "bindings", derive(TS))]
7304pub struct TruncateTable {
7305    #[serde(default)]
7306    pub expressions: Vec<Expression>,
7307    #[serde(default)]
7308    pub is_database: Option<Box<Expression>>,
7309    #[serde(default)]
7310    pub exists: bool,
7311    #[serde(default)]
7312    pub only: Option<Box<Expression>>,
7313    #[serde(default)]
7314    pub cluster: Option<Box<Expression>>,
7315    #[serde(default)]
7316    pub identity: Option<Box<Expression>>,
7317    #[serde(default)]
7318    pub option: Option<Box<Expression>>,
7319    #[serde(default)]
7320    pub partition: Option<Box<Expression>>,
7321}
7322
7323/// Clone
7324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7325#[cfg_attr(feature = "bindings", derive(TS))]
7326pub struct Clone {
7327    pub this: Box<Expression>,
7328    #[serde(default)]
7329    pub shallow: Option<Box<Expression>>,
7330    #[serde(default)]
7331    pub copy: Option<Box<Expression>>,
7332}
7333
7334/// Attach
7335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7336#[cfg_attr(feature = "bindings", derive(TS))]
7337pub struct Attach {
7338    pub this: Box<Expression>,
7339    #[serde(default)]
7340    pub exists: bool,
7341    #[serde(default)]
7342    pub expressions: Vec<Expression>,
7343}
7344
7345/// Detach
7346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7347#[cfg_attr(feature = "bindings", derive(TS))]
7348pub struct Detach {
7349    pub this: Box<Expression>,
7350    #[serde(default)]
7351    pub exists: bool,
7352}
7353
7354/// Install
7355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7356#[cfg_attr(feature = "bindings", derive(TS))]
7357pub struct Install {
7358    pub this: Box<Expression>,
7359    #[serde(default)]
7360    pub from_: Option<Box<Expression>>,
7361    #[serde(default)]
7362    pub force: Option<Box<Expression>>,
7363}
7364
7365/// Summarize
7366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7367#[cfg_attr(feature = "bindings", derive(TS))]
7368pub struct Summarize {
7369    pub this: Box<Expression>,
7370    #[serde(default)]
7371    pub table: Option<Box<Expression>>,
7372}
7373
7374/// Declare
7375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7376#[cfg_attr(feature = "bindings", derive(TS))]
7377pub struct Declare {
7378    #[serde(default)]
7379    pub expressions: Vec<Expression>,
7380}
7381
7382/// DeclareItem
7383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7384#[cfg_attr(feature = "bindings", derive(TS))]
7385pub struct DeclareItem {
7386    pub this: Box<Expression>,
7387    #[serde(default)]
7388    pub kind: Option<String>,
7389    #[serde(default)]
7390    pub default: Option<Box<Expression>>,
7391    #[serde(default)]
7392    pub has_as: bool,
7393    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7394    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7395    pub additional_names: Vec<Expression>,
7396}
7397
7398/// Set
7399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7400#[cfg_attr(feature = "bindings", derive(TS))]
7401pub struct Set {
7402    #[serde(default)]
7403    pub expressions: Vec<Expression>,
7404    #[serde(default)]
7405    pub unset: Option<Box<Expression>>,
7406    #[serde(default)]
7407    pub tag: Option<Box<Expression>>,
7408}
7409
7410/// Heredoc
7411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7412#[cfg_attr(feature = "bindings", derive(TS))]
7413pub struct Heredoc {
7414    pub this: Box<Expression>,
7415    #[serde(default)]
7416    pub tag: Option<Box<Expression>>,
7417}
7418
7419/// QueryBand
7420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7421#[cfg_attr(feature = "bindings", derive(TS))]
7422pub struct QueryBand {
7423    pub this: Box<Expression>,
7424    #[serde(default)]
7425    pub scope: Option<Box<Expression>>,
7426    #[serde(default)]
7427    pub update: Option<Box<Expression>>,
7428}
7429
7430/// UserDefinedFunction
7431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7432#[cfg_attr(feature = "bindings", derive(TS))]
7433pub struct UserDefinedFunction {
7434    pub this: Box<Expression>,
7435    #[serde(default)]
7436    pub expressions: Vec<Expression>,
7437    #[serde(default)]
7438    pub wrapped: Option<Box<Expression>>,
7439}
7440
7441/// RecursiveWithSearch
7442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7443#[cfg_attr(feature = "bindings", derive(TS))]
7444pub struct RecursiveWithSearch {
7445    pub kind: String,
7446    pub this: Box<Expression>,
7447    pub expression: Box<Expression>,
7448    #[serde(default)]
7449    pub using: Option<Box<Expression>>,
7450}
7451
7452/// ProjectionDef
7453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7454#[cfg_attr(feature = "bindings", derive(TS))]
7455pub struct ProjectionDef {
7456    pub this: Box<Expression>,
7457    pub expression: Box<Expression>,
7458}
7459
7460/// TableAlias
7461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7462#[cfg_attr(feature = "bindings", derive(TS))]
7463pub struct TableAlias {
7464    #[serde(default)]
7465    pub this: Option<Box<Expression>>,
7466    #[serde(default)]
7467    pub columns: Vec<Expression>,
7468}
7469
7470/// ByteString
7471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7472#[cfg_attr(feature = "bindings", derive(TS))]
7473pub struct ByteString {
7474    pub this: Box<Expression>,
7475    #[serde(default)]
7476    pub is_bytes: Option<Box<Expression>>,
7477}
7478
7479/// HexStringExpr - Hex string expression (not literal)
7480/// BigQuery: converts to FROM_HEX(this)
7481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7482#[cfg_attr(feature = "bindings", derive(TS))]
7483pub struct HexStringExpr {
7484    pub this: Box<Expression>,
7485    #[serde(default)]
7486    pub is_integer: Option<bool>,
7487}
7488
7489/// UnicodeString
7490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7491#[cfg_attr(feature = "bindings", derive(TS))]
7492pub struct UnicodeString {
7493    pub this: Box<Expression>,
7494    #[serde(default)]
7495    pub escape: Option<Box<Expression>>,
7496}
7497
7498/// AlterColumn
7499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7500#[cfg_attr(feature = "bindings", derive(TS))]
7501pub struct AlterColumn {
7502    pub this: Box<Expression>,
7503    #[serde(default)]
7504    pub dtype: Option<Box<Expression>>,
7505    #[serde(default)]
7506    pub collate: Option<Box<Expression>>,
7507    #[serde(default)]
7508    pub using: Option<Box<Expression>>,
7509    #[serde(default)]
7510    pub default: Option<Box<Expression>>,
7511    #[serde(default)]
7512    pub drop: Option<Box<Expression>>,
7513    #[serde(default)]
7514    pub comment: Option<Box<Expression>>,
7515    #[serde(default)]
7516    pub allow_null: Option<Box<Expression>>,
7517    #[serde(default)]
7518    pub visible: Option<Box<Expression>>,
7519    #[serde(default)]
7520    pub rename_to: Option<Box<Expression>>,
7521}
7522
7523/// AlterSortKey
7524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7525#[cfg_attr(feature = "bindings", derive(TS))]
7526pub struct AlterSortKey {
7527    #[serde(default)]
7528    pub this: Option<Box<Expression>>,
7529    #[serde(default)]
7530    pub expressions: Vec<Expression>,
7531    #[serde(default)]
7532    pub compound: Option<Box<Expression>>,
7533}
7534
7535/// AlterSet
7536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7537#[cfg_attr(feature = "bindings", derive(TS))]
7538pub struct AlterSet {
7539    #[serde(default)]
7540    pub expressions: Vec<Expression>,
7541    #[serde(default)]
7542    pub option: Option<Box<Expression>>,
7543    #[serde(default)]
7544    pub tablespace: Option<Box<Expression>>,
7545    #[serde(default)]
7546    pub access_method: Option<Box<Expression>>,
7547    #[serde(default)]
7548    pub file_format: Option<Box<Expression>>,
7549    #[serde(default)]
7550    pub copy_options: Option<Box<Expression>>,
7551    #[serde(default)]
7552    pub tag: Option<Box<Expression>>,
7553    #[serde(default)]
7554    pub location: Option<Box<Expression>>,
7555    #[serde(default)]
7556    pub serde: Option<Box<Expression>>,
7557}
7558
7559/// RenameColumn
7560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7561#[cfg_attr(feature = "bindings", derive(TS))]
7562pub struct RenameColumn {
7563    pub this: Box<Expression>,
7564    #[serde(default)]
7565    pub to: Option<Box<Expression>>,
7566    #[serde(default)]
7567    pub exists: bool,
7568}
7569
7570/// Comprehension
7571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7572#[cfg_attr(feature = "bindings", derive(TS))]
7573pub struct Comprehension {
7574    pub this: Box<Expression>,
7575    pub expression: Box<Expression>,
7576    #[serde(default)]
7577    pub position: Option<Box<Expression>>,
7578    #[serde(default)]
7579    pub iterator: Option<Box<Expression>>,
7580    #[serde(default)]
7581    pub condition: Option<Box<Expression>>,
7582}
7583
7584/// MergeTreeTTLAction
7585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7586#[cfg_attr(feature = "bindings", derive(TS))]
7587pub struct MergeTreeTTLAction {
7588    pub this: Box<Expression>,
7589    #[serde(default)]
7590    pub delete: Option<Box<Expression>>,
7591    #[serde(default)]
7592    pub recompress: Option<Box<Expression>>,
7593    #[serde(default)]
7594    pub to_disk: Option<Box<Expression>>,
7595    #[serde(default)]
7596    pub to_volume: Option<Box<Expression>>,
7597}
7598
7599/// MergeTreeTTL
7600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7601#[cfg_attr(feature = "bindings", derive(TS))]
7602pub struct MergeTreeTTL {
7603    #[serde(default)]
7604    pub expressions: Vec<Expression>,
7605    #[serde(default)]
7606    pub where_: Option<Box<Expression>>,
7607    #[serde(default)]
7608    pub group: Option<Box<Expression>>,
7609    #[serde(default)]
7610    pub aggregates: Option<Box<Expression>>,
7611}
7612
7613/// IndexConstraintOption
7614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7615#[cfg_attr(feature = "bindings", derive(TS))]
7616pub struct IndexConstraintOption {
7617    #[serde(default)]
7618    pub key_block_size: Option<Box<Expression>>,
7619    #[serde(default)]
7620    pub using: Option<Box<Expression>>,
7621    #[serde(default)]
7622    pub parser: Option<Box<Expression>>,
7623    #[serde(default)]
7624    pub comment: Option<Box<Expression>>,
7625    #[serde(default)]
7626    pub visible: Option<Box<Expression>>,
7627    #[serde(default)]
7628    pub engine_attr: Option<Box<Expression>>,
7629    #[serde(default)]
7630    pub secondary_engine_attr: Option<Box<Expression>>,
7631}
7632
7633/// PeriodForSystemTimeConstraint
7634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7635#[cfg_attr(feature = "bindings", derive(TS))]
7636pub struct PeriodForSystemTimeConstraint {
7637    pub this: Box<Expression>,
7638    pub expression: Box<Expression>,
7639}
7640
7641/// CaseSpecificColumnConstraint
7642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7643#[cfg_attr(feature = "bindings", derive(TS))]
7644pub struct CaseSpecificColumnConstraint {
7645    #[serde(default)]
7646    pub not_: Option<Box<Expression>>,
7647}
7648
7649/// CharacterSetColumnConstraint
7650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7651#[cfg_attr(feature = "bindings", derive(TS))]
7652pub struct CharacterSetColumnConstraint {
7653    pub this: Box<Expression>,
7654}
7655
7656/// CheckColumnConstraint
7657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7658#[cfg_attr(feature = "bindings", derive(TS))]
7659pub struct CheckColumnConstraint {
7660    pub this: Box<Expression>,
7661    #[serde(default)]
7662    pub enforced: Option<Box<Expression>>,
7663}
7664
7665/// CompressColumnConstraint
7666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7667#[cfg_attr(feature = "bindings", derive(TS))]
7668pub struct CompressColumnConstraint {
7669    #[serde(default)]
7670    pub this: Option<Box<Expression>>,
7671}
7672
7673/// DateFormatColumnConstraint
7674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7675#[cfg_attr(feature = "bindings", derive(TS))]
7676pub struct DateFormatColumnConstraint {
7677    pub this: Box<Expression>,
7678}
7679
7680/// EphemeralColumnConstraint
7681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7682#[cfg_attr(feature = "bindings", derive(TS))]
7683pub struct EphemeralColumnConstraint {
7684    #[serde(default)]
7685    pub this: Option<Box<Expression>>,
7686}
7687
7688/// WithOperator
7689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7690#[cfg_attr(feature = "bindings", derive(TS))]
7691pub struct WithOperator {
7692    pub this: Box<Expression>,
7693    pub op: String,
7694}
7695
7696/// GeneratedAsIdentityColumnConstraint
7697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7698#[cfg_attr(feature = "bindings", derive(TS))]
7699pub struct GeneratedAsIdentityColumnConstraint {
7700    #[serde(default)]
7701    pub this: Option<Box<Expression>>,
7702    #[serde(default)]
7703    pub expression: Option<Box<Expression>>,
7704    #[serde(default)]
7705    pub on_null: Option<Box<Expression>>,
7706    #[serde(default)]
7707    pub start: Option<Box<Expression>>,
7708    #[serde(default)]
7709    pub increment: Option<Box<Expression>>,
7710    #[serde(default)]
7711    pub minvalue: Option<Box<Expression>>,
7712    #[serde(default)]
7713    pub maxvalue: Option<Box<Expression>>,
7714    #[serde(default)]
7715    pub cycle: Option<Box<Expression>>,
7716    #[serde(default)]
7717    pub order: Option<Box<Expression>>,
7718}
7719
7720/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
7721/// TSQL: outputs "IDENTITY"
7722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7723#[cfg_attr(feature = "bindings", derive(TS))]
7724pub struct AutoIncrementColumnConstraint;
7725
7726/// CommentColumnConstraint - Column comment marker
7727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7728#[cfg_attr(feature = "bindings", derive(TS))]
7729pub struct CommentColumnConstraint;
7730
7731/// GeneratedAsRowColumnConstraint
7732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7733#[cfg_attr(feature = "bindings", derive(TS))]
7734pub struct GeneratedAsRowColumnConstraint {
7735    #[serde(default)]
7736    pub start: Option<Box<Expression>>,
7737    #[serde(default)]
7738    pub hidden: Option<Box<Expression>>,
7739}
7740
7741/// IndexColumnConstraint
7742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7743#[cfg_attr(feature = "bindings", derive(TS))]
7744pub struct IndexColumnConstraint {
7745    #[serde(default)]
7746    pub this: Option<Box<Expression>>,
7747    #[serde(default)]
7748    pub expressions: Vec<Expression>,
7749    #[serde(default)]
7750    pub kind: Option<String>,
7751    #[serde(default)]
7752    pub index_type: Option<Box<Expression>>,
7753    #[serde(default)]
7754    pub options: Vec<Expression>,
7755    #[serde(default)]
7756    pub expression: Option<Box<Expression>>,
7757    #[serde(default)]
7758    pub granularity: Option<Box<Expression>>,
7759}
7760
7761/// MaskingPolicyColumnConstraint
7762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7763#[cfg_attr(feature = "bindings", derive(TS))]
7764pub struct MaskingPolicyColumnConstraint {
7765    pub this: Box<Expression>,
7766    #[serde(default)]
7767    pub expressions: Vec<Expression>,
7768}
7769
7770/// NotNullColumnConstraint
7771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7772#[cfg_attr(feature = "bindings", derive(TS))]
7773pub struct NotNullColumnConstraint {
7774    #[serde(default)]
7775    pub allow_null: Option<Box<Expression>>,
7776}
7777
7778/// DefaultColumnConstraint - DEFAULT value for a column
7779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7780#[cfg_attr(feature = "bindings", derive(TS))]
7781pub struct DefaultColumnConstraint {
7782    pub this: Box<Expression>,
7783}
7784
7785/// PrimaryKeyColumnConstraint
7786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7787#[cfg_attr(feature = "bindings", derive(TS))]
7788pub struct PrimaryKeyColumnConstraint {
7789    #[serde(default)]
7790    pub desc: Option<Box<Expression>>,
7791    #[serde(default)]
7792    pub options: Vec<Expression>,
7793}
7794
7795/// UniqueColumnConstraint
7796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7797#[cfg_attr(feature = "bindings", derive(TS))]
7798pub struct UniqueColumnConstraint {
7799    #[serde(default)]
7800    pub this: Option<Box<Expression>>,
7801    #[serde(default)]
7802    pub index_type: Option<Box<Expression>>,
7803    #[serde(default)]
7804    pub on_conflict: Option<Box<Expression>>,
7805    #[serde(default)]
7806    pub nulls: Option<Box<Expression>>,
7807    #[serde(default)]
7808    pub options: Vec<Expression>,
7809}
7810
7811/// WatermarkColumnConstraint
7812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7813#[cfg_attr(feature = "bindings", derive(TS))]
7814pub struct WatermarkColumnConstraint {
7815    pub this: Box<Expression>,
7816    pub expression: Box<Expression>,
7817}
7818
7819/// ComputedColumnConstraint
7820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7821#[cfg_attr(feature = "bindings", derive(TS))]
7822pub struct ComputedColumnConstraint {
7823    pub this: Box<Expression>,
7824    #[serde(default)]
7825    pub persisted: Option<Box<Expression>>,
7826    #[serde(default)]
7827    pub not_null: Option<Box<Expression>>,
7828    #[serde(default)]
7829    pub data_type: Option<Box<Expression>>,
7830}
7831
7832/// InOutColumnConstraint
7833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7834#[cfg_attr(feature = "bindings", derive(TS))]
7835pub struct InOutColumnConstraint {
7836    #[serde(default)]
7837    pub input_: Option<Box<Expression>>,
7838    #[serde(default)]
7839    pub output: Option<Box<Expression>>,
7840}
7841
7842/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
7843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7844#[cfg_attr(feature = "bindings", derive(TS))]
7845pub struct PathColumnConstraint {
7846    pub this: Box<Expression>,
7847}
7848
7849/// Constraint
7850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7851#[cfg_attr(feature = "bindings", derive(TS))]
7852pub struct Constraint {
7853    pub this: Box<Expression>,
7854    #[serde(default)]
7855    pub expressions: Vec<Expression>,
7856}
7857
7858/// Export
7859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7860#[cfg_attr(feature = "bindings", derive(TS))]
7861pub struct Export {
7862    pub this: Box<Expression>,
7863    #[serde(default)]
7864    pub connection: Option<Box<Expression>>,
7865    #[serde(default)]
7866    pub options: Vec<Expression>,
7867}
7868
7869/// Filter
7870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7871#[cfg_attr(feature = "bindings", derive(TS))]
7872pub struct Filter {
7873    pub this: Box<Expression>,
7874    pub expression: Box<Expression>,
7875}
7876
7877/// Changes
7878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7879#[cfg_attr(feature = "bindings", derive(TS))]
7880pub struct Changes {
7881    #[serde(default)]
7882    pub information: Option<Box<Expression>>,
7883    #[serde(default)]
7884    pub at_before: Option<Box<Expression>>,
7885    #[serde(default)]
7886    pub end: Option<Box<Expression>>,
7887}
7888
7889/// Directory
7890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7891#[cfg_attr(feature = "bindings", derive(TS))]
7892pub struct Directory {
7893    pub this: Box<Expression>,
7894    #[serde(default)]
7895    pub local: Option<Box<Expression>>,
7896    #[serde(default)]
7897    pub row_format: Option<Box<Expression>>,
7898}
7899
7900/// ForeignKey
7901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7902#[cfg_attr(feature = "bindings", derive(TS))]
7903pub struct ForeignKey {
7904    #[serde(default)]
7905    pub expressions: Vec<Expression>,
7906    #[serde(default)]
7907    pub reference: Option<Box<Expression>>,
7908    #[serde(default)]
7909    pub delete: Option<Box<Expression>>,
7910    #[serde(default)]
7911    pub update: Option<Box<Expression>>,
7912    #[serde(default)]
7913    pub options: Vec<Expression>,
7914}
7915
7916/// ColumnPrefix
7917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7918#[cfg_attr(feature = "bindings", derive(TS))]
7919pub struct ColumnPrefix {
7920    pub this: Box<Expression>,
7921    pub expression: Box<Expression>,
7922}
7923
7924/// PrimaryKey
7925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7926#[cfg_attr(feature = "bindings", derive(TS))]
7927pub struct PrimaryKey {
7928    #[serde(default)]
7929    pub this: Option<Box<Expression>>,
7930    #[serde(default)]
7931    pub expressions: Vec<Expression>,
7932    #[serde(default)]
7933    pub options: Vec<Expression>,
7934    #[serde(default)]
7935    pub include: Option<Box<Expression>>,
7936}
7937
7938/// Into
7939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7940#[cfg_attr(feature = "bindings", derive(TS))]
7941pub struct IntoClause {
7942    #[serde(default)]
7943    pub this: Option<Box<Expression>>,
7944    #[serde(default)]
7945    pub temporary: bool,
7946    #[serde(default)]
7947    pub unlogged: Option<Box<Expression>>,
7948    #[serde(default)]
7949    pub bulk_collect: Option<Box<Expression>>,
7950    #[serde(default)]
7951    pub expressions: Vec<Expression>,
7952}
7953
7954/// JoinHint
7955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7956#[cfg_attr(feature = "bindings", derive(TS))]
7957pub struct JoinHint {
7958    pub this: Box<Expression>,
7959    #[serde(default)]
7960    pub expressions: Vec<Expression>,
7961}
7962
7963/// Opclass
7964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7965#[cfg_attr(feature = "bindings", derive(TS))]
7966pub struct Opclass {
7967    pub this: Box<Expression>,
7968    pub expression: Box<Expression>,
7969}
7970
7971/// Index
7972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7973#[cfg_attr(feature = "bindings", derive(TS))]
7974pub struct Index {
7975    #[serde(default)]
7976    pub this: Option<Box<Expression>>,
7977    #[serde(default)]
7978    pub table: Option<Box<Expression>>,
7979    #[serde(default)]
7980    pub unique: bool,
7981    #[serde(default)]
7982    pub primary: Option<Box<Expression>>,
7983    #[serde(default)]
7984    pub amp: Option<Box<Expression>>,
7985    #[serde(default)]
7986    pub params: Vec<Expression>,
7987}
7988
7989/// IndexParameters
7990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7991#[cfg_attr(feature = "bindings", derive(TS))]
7992pub struct IndexParameters {
7993    #[serde(default)]
7994    pub using: Option<Box<Expression>>,
7995    #[serde(default)]
7996    pub include: Option<Box<Expression>>,
7997    #[serde(default)]
7998    pub columns: Vec<Expression>,
7999    #[serde(default)]
8000    pub with_storage: Option<Box<Expression>>,
8001    #[serde(default)]
8002    pub partition_by: Option<Box<Expression>>,
8003    #[serde(default)]
8004    pub tablespace: Option<Box<Expression>>,
8005    #[serde(default)]
8006    pub where_: Option<Box<Expression>>,
8007    #[serde(default)]
8008    pub on: Option<Box<Expression>>,
8009}
8010
8011/// ConditionalInsert
8012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8013#[cfg_attr(feature = "bindings", derive(TS))]
8014pub struct ConditionalInsert {
8015    pub this: Box<Expression>,
8016    #[serde(default)]
8017    pub expression: Option<Box<Expression>>,
8018    #[serde(default)]
8019    pub else_: Option<Box<Expression>>,
8020}
8021
8022/// MultitableInserts
8023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8024#[cfg_attr(feature = "bindings", derive(TS))]
8025pub struct MultitableInserts {
8026    #[serde(default)]
8027    pub expressions: Vec<Expression>,
8028    pub kind: String,
8029    #[serde(default)]
8030    pub source: Option<Box<Expression>>,
8031    /// Leading comments before the statement
8032    #[serde(default)]
8033    pub leading_comments: Vec<String>,
8034}
8035
8036/// OnConflict
8037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8038#[cfg_attr(feature = "bindings", derive(TS))]
8039pub struct OnConflict {
8040    #[serde(default)]
8041    pub duplicate: Option<Box<Expression>>,
8042    #[serde(default)]
8043    pub expressions: Vec<Expression>,
8044    #[serde(default)]
8045    pub action: Option<Box<Expression>>,
8046    #[serde(default)]
8047    pub conflict_keys: Option<Box<Expression>>,
8048    #[serde(default)]
8049    pub index_predicate: Option<Box<Expression>>,
8050    #[serde(default)]
8051    pub constraint: Option<Box<Expression>>,
8052    #[serde(default)]
8053    pub where_: Option<Box<Expression>>,
8054}
8055
8056/// OnCondition
8057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8058#[cfg_attr(feature = "bindings", derive(TS))]
8059pub struct OnCondition {
8060    #[serde(default)]
8061    pub error: Option<Box<Expression>>,
8062    #[serde(default)]
8063    pub empty: Option<Box<Expression>>,
8064    #[serde(default)]
8065    pub null: Option<Box<Expression>>,
8066}
8067
8068/// Returning
8069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8070#[cfg_attr(feature = "bindings", derive(TS))]
8071pub struct Returning {
8072    #[serde(default)]
8073    pub expressions: Vec<Expression>,
8074    #[serde(default)]
8075    pub into: Option<Box<Expression>>,
8076}
8077
8078/// Introducer
8079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8080#[cfg_attr(feature = "bindings", derive(TS))]
8081pub struct Introducer {
8082    pub this: Box<Expression>,
8083    pub expression: Box<Expression>,
8084}
8085
8086/// PartitionRange
8087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8088#[cfg_attr(feature = "bindings", derive(TS))]
8089pub struct PartitionRange {
8090    pub this: Box<Expression>,
8091    #[serde(default)]
8092    pub expression: Option<Box<Expression>>,
8093    #[serde(default)]
8094    pub expressions: Vec<Expression>,
8095}
8096
8097/// Group
8098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8099#[cfg_attr(feature = "bindings", derive(TS))]
8100pub struct Group {
8101    #[serde(default)]
8102    pub expressions: Vec<Expression>,
8103    #[serde(default)]
8104    pub grouping_sets: Option<Box<Expression>>,
8105    #[serde(default)]
8106    pub cube: Option<Box<Expression>>,
8107    #[serde(default)]
8108    pub rollup: Option<Box<Expression>>,
8109    #[serde(default)]
8110    pub totals: Option<Box<Expression>>,
8111    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8112    #[serde(default)]
8113    pub all: Option<bool>,
8114}
8115
8116/// Cube
8117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8118#[cfg_attr(feature = "bindings", derive(TS))]
8119pub struct Cube {
8120    #[serde(default)]
8121    pub expressions: Vec<Expression>,
8122}
8123
8124/// Rollup
8125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8126#[cfg_attr(feature = "bindings", derive(TS))]
8127pub struct Rollup {
8128    #[serde(default)]
8129    pub expressions: Vec<Expression>,
8130}
8131
8132/// GroupingSets
8133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8134#[cfg_attr(feature = "bindings", derive(TS))]
8135pub struct GroupingSets {
8136    #[serde(default)]
8137    pub expressions: Vec<Expression>,
8138}
8139
8140/// LimitOptions
8141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8142#[cfg_attr(feature = "bindings", derive(TS))]
8143pub struct LimitOptions {
8144    #[serde(default)]
8145    pub percent: Option<Box<Expression>>,
8146    #[serde(default)]
8147    pub rows: Option<Box<Expression>>,
8148    #[serde(default)]
8149    pub with_ties: Option<Box<Expression>>,
8150}
8151
8152/// Lateral
8153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8154#[cfg_attr(feature = "bindings", derive(TS))]
8155pub struct Lateral {
8156    pub this: Box<Expression>,
8157    #[serde(default)]
8158    pub view: Option<Box<Expression>>,
8159    #[serde(default)]
8160    pub outer: Option<Box<Expression>>,
8161    #[serde(default)]
8162    pub alias: Option<String>,
8163    /// Whether the alias was originally quoted (backtick/double-quote)
8164    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8165    pub alias_quoted: bool,
8166    #[serde(default)]
8167    pub cross_apply: Option<Box<Expression>>,
8168    #[serde(default)]
8169    pub ordinality: Option<Box<Expression>>,
8170    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8171    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8172    pub column_aliases: Vec<String>,
8173}
8174
8175/// TableFromRows
8176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8177#[cfg_attr(feature = "bindings", derive(TS))]
8178pub struct TableFromRows {
8179    pub this: Box<Expression>,
8180    #[serde(default)]
8181    pub alias: Option<String>,
8182    #[serde(default)]
8183    pub joins: Vec<Expression>,
8184    #[serde(default)]
8185    pub pivots: Option<Box<Expression>>,
8186    #[serde(default)]
8187    pub sample: Option<Box<Expression>>,
8188}
8189
8190/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8191/// Used for set-returning functions with typed column definitions
8192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8193#[cfg_attr(feature = "bindings", derive(TS))]
8194pub struct RowsFrom {
8195    /// List of function expressions, each potentially with an alias and typed columns
8196    pub expressions: Vec<Expression>,
8197    /// WITH ORDINALITY modifier
8198    #[serde(default)]
8199    pub ordinality: bool,
8200    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8201    #[serde(default)]
8202    pub alias: Option<Box<Expression>>,
8203}
8204
8205/// WithFill
8206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8207#[cfg_attr(feature = "bindings", derive(TS))]
8208pub struct WithFill {
8209    #[serde(default)]
8210    pub from_: Option<Box<Expression>>,
8211    #[serde(default)]
8212    pub to: Option<Box<Expression>>,
8213    #[serde(default)]
8214    pub step: Option<Box<Expression>>,
8215    #[serde(default)]
8216    pub interpolate: Option<Box<Expression>>,
8217}
8218
8219/// Property
8220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8221#[cfg_attr(feature = "bindings", derive(TS))]
8222pub struct Property {
8223    pub this: Box<Expression>,
8224    #[serde(default)]
8225    pub value: Option<Box<Expression>>,
8226}
8227
8228/// GrantPrivilege
8229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8230#[cfg_attr(feature = "bindings", derive(TS))]
8231pub struct GrantPrivilege {
8232    pub this: Box<Expression>,
8233    #[serde(default)]
8234    pub expressions: Vec<Expression>,
8235}
8236
8237/// AllowedValuesProperty
8238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8239#[cfg_attr(feature = "bindings", derive(TS))]
8240pub struct AllowedValuesProperty {
8241    #[serde(default)]
8242    pub expressions: Vec<Expression>,
8243}
8244
8245/// AlgorithmProperty
8246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8247#[cfg_attr(feature = "bindings", derive(TS))]
8248pub struct AlgorithmProperty {
8249    pub this: Box<Expression>,
8250}
8251
8252/// AutoIncrementProperty
8253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8254#[cfg_attr(feature = "bindings", derive(TS))]
8255pub struct AutoIncrementProperty {
8256    pub this: Box<Expression>,
8257}
8258
8259/// AutoRefreshProperty
8260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8261#[cfg_attr(feature = "bindings", derive(TS))]
8262pub struct AutoRefreshProperty {
8263    pub this: Box<Expression>,
8264}
8265
8266/// BackupProperty
8267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8268#[cfg_attr(feature = "bindings", derive(TS))]
8269pub struct BackupProperty {
8270    pub this: Box<Expression>,
8271}
8272
8273/// BuildProperty
8274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8275#[cfg_attr(feature = "bindings", derive(TS))]
8276pub struct BuildProperty {
8277    pub this: Box<Expression>,
8278}
8279
8280/// BlockCompressionProperty
8281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8282#[cfg_attr(feature = "bindings", derive(TS))]
8283pub struct BlockCompressionProperty {
8284    #[serde(default)]
8285    pub autotemp: Option<Box<Expression>>,
8286    #[serde(default)]
8287    pub always: Option<Box<Expression>>,
8288    #[serde(default)]
8289    pub default: Option<Box<Expression>>,
8290    #[serde(default)]
8291    pub manual: Option<Box<Expression>>,
8292    #[serde(default)]
8293    pub never: Option<Box<Expression>>,
8294}
8295
8296/// CharacterSetProperty
8297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8298#[cfg_attr(feature = "bindings", derive(TS))]
8299pub struct CharacterSetProperty {
8300    pub this: Box<Expression>,
8301    #[serde(default)]
8302    pub default: Option<Box<Expression>>,
8303}
8304
8305/// ChecksumProperty
8306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8307#[cfg_attr(feature = "bindings", derive(TS))]
8308pub struct ChecksumProperty {
8309    #[serde(default)]
8310    pub on: Option<Box<Expression>>,
8311    #[serde(default)]
8312    pub default: Option<Box<Expression>>,
8313}
8314
8315/// CollateProperty
8316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8317#[cfg_attr(feature = "bindings", derive(TS))]
8318pub struct CollateProperty {
8319    pub this: Box<Expression>,
8320    #[serde(default)]
8321    pub default: Option<Box<Expression>>,
8322}
8323
8324/// DataBlocksizeProperty
8325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8326#[cfg_attr(feature = "bindings", derive(TS))]
8327pub struct DataBlocksizeProperty {
8328    #[serde(default)]
8329    pub size: Option<i64>,
8330    #[serde(default)]
8331    pub units: Option<Box<Expression>>,
8332    #[serde(default)]
8333    pub minimum: Option<Box<Expression>>,
8334    #[serde(default)]
8335    pub maximum: Option<Box<Expression>>,
8336    #[serde(default)]
8337    pub default: Option<Box<Expression>>,
8338}
8339
8340/// DataDeletionProperty
8341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8342#[cfg_attr(feature = "bindings", derive(TS))]
8343pub struct DataDeletionProperty {
8344    pub on: Box<Expression>,
8345    #[serde(default)]
8346    pub filter_column: Option<Box<Expression>>,
8347    #[serde(default)]
8348    pub retention_period: Option<Box<Expression>>,
8349}
8350
8351/// DefinerProperty
8352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8353#[cfg_attr(feature = "bindings", derive(TS))]
8354pub struct DefinerProperty {
8355    pub this: Box<Expression>,
8356}
8357
8358/// DistKeyProperty
8359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8360#[cfg_attr(feature = "bindings", derive(TS))]
8361pub struct DistKeyProperty {
8362    pub this: Box<Expression>,
8363}
8364
8365/// DistributedByProperty
8366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8367#[cfg_attr(feature = "bindings", derive(TS))]
8368pub struct DistributedByProperty {
8369    #[serde(default)]
8370    pub expressions: Vec<Expression>,
8371    pub kind: String,
8372    #[serde(default)]
8373    pub buckets: Option<Box<Expression>>,
8374    #[serde(default)]
8375    pub order: Option<Box<Expression>>,
8376}
8377
8378/// DistStyleProperty
8379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8380#[cfg_attr(feature = "bindings", derive(TS))]
8381pub struct DistStyleProperty {
8382    pub this: Box<Expression>,
8383}
8384
8385/// DuplicateKeyProperty
8386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8387#[cfg_attr(feature = "bindings", derive(TS))]
8388pub struct DuplicateKeyProperty {
8389    #[serde(default)]
8390    pub expressions: Vec<Expression>,
8391}
8392
8393/// EngineProperty
8394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8395#[cfg_attr(feature = "bindings", derive(TS))]
8396pub struct EngineProperty {
8397    pub this: Box<Expression>,
8398}
8399
8400/// ToTableProperty
8401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8402#[cfg_attr(feature = "bindings", derive(TS))]
8403pub struct ToTableProperty {
8404    pub this: Box<Expression>,
8405}
8406
8407/// ExecuteAsProperty
8408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8409#[cfg_attr(feature = "bindings", derive(TS))]
8410pub struct ExecuteAsProperty {
8411    pub this: Box<Expression>,
8412}
8413
8414/// ExternalProperty
8415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8416#[cfg_attr(feature = "bindings", derive(TS))]
8417pub struct ExternalProperty {
8418    #[serde(default)]
8419    pub this: Option<Box<Expression>>,
8420}
8421
8422/// FallbackProperty
8423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8424#[cfg_attr(feature = "bindings", derive(TS))]
8425pub struct FallbackProperty {
8426    #[serde(default)]
8427    pub no: Option<Box<Expression>>,
8428    #[serde(default)]
8429    pub protection: Option<Box<Expression>>,
8430}
8431
8432/// FileFormatProperty
8433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8434#[cfg_attr(feature = "bindings", derive(TS))]
8435pub struct FileFormatProperty {
8436    #[serde(default)]
8437    pub this: Option<Box<Expression>>,
8438    #[serde(default)]
8439    pub expressions: Vec<Expression>,
8440    #[serde(default)]
8441    pub hive_format: Option<Box<Expression>>,
8442}
8443
8444/// CredentialsProperty
8445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8446#[cfg_attr(feature = "bindings", derive(TS))]
8447pub struct CredentialsProperty {
8448    #[serde(default)]
8449    pub expressions: Vec<Expression>,
8450}
8451
8452/// FreespaceProperty
8453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8454#[cfg_attr(feature = "bindings", derive(TS))]
8455pub struct FreespaceProperty {
8456    pub this: Box<Expression>,
8457    #[serde(default)]
8458    pub percent: Option<Box<Expression>>,
8459}
8460
8461/// InheritsProperty
8462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8463#[cfg_attr(feature = "bindings", derive(TS))]
8464pub struct InheritsProperty {
8465    #[serde(default)]
8466    pub expressions: Vec<Expression>,
8467}
8468
8469/// InputModelProperty
8470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8471#[cfg_attr(feature = "bindings", derive(TS))]
8472pub struct InputModelProperty {
8473    pub this: Box<Expression>,
8474}
8475
8476/// OutputModelProperty
8477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8478#[cfg_attr(feature = "bindings", derive(TS))]
8479pub struct OutputModelProperty {
8480    pub this: Box<Expression>,
8481}
8482
8483/// IsolatedLoadingProperty
8484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8485#[cfg_attr(feature = "bindings", derive(TS))]
8486pub struct IsolatedLoadingProperty {
8487    #[serde(default)]
8488    pub no: Option<Box<Expression>>,
8489    #[serde(default)]
8490    pub concurrent: Option<Box<Expression>>,
8491    #[serde(default)]
8492    pub target: Option<Box<Expression>>,
8493}
8494
8495/// JournalProperty
8496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8497#[cfg_attr(feature = "bindings", derive(TS))]
8498pub struct JournalProperty {
8499    #[serde(default)]
8500    pub no: Option<Box<Expression>>,
8501    #[serde(default)]
8502    pub dual: Option<Box<Expression>>,
8503    #[serde(default)]
8504    pub before: Option<Box<Expression>>,
8505    #[serde(default)]
8506    pub local: Option<Box<Expression>>,
8507    #[serde(default)]
8508    pub after: Option<Box<Expression>>,
8509}
8510
8511/// LanguageProperty
8512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8513#[cfg_attr(feature = "bindings", derive(TS))]
8514pub struct LanguageProperty {
8515    pub this: Box<Expression>,
8516}
8517
8518/// EnviromentProperty
8519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8520#[cfg_attr(feature = "bindings", derive(TS))]
8521pub struct EnviromentProperty {
8522    #[serde(default)]
8523    pub expressions: Vec<Expression>,
8524}
8525
8526/// ClusteredByProperty
8527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8528#[cfg_attr(feature = "bindings", derive(TS))]
8529pub struct ClusteredByProperty {
8530    #[serde(default)]
8531    pub expressions: Vec<Expression>,
8532    #[serde(default)]
8533    pub sorted_by: Option<Box<Expression>>,
8534    #[serde(default)]
8535    pub buckets: Option<Box<Expression>>,
8536}
8537
8538/// DictProperty
8539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8540#[cfg_attr(feature = "bindings", derive(TS))]
8541pub struct DictProperty {
8542    pub this: Box<Expression>,
8543    pub kind: String,
8544    #[serde(default)]
8545    pub settings: Option<Box<Expression>>,
8546}
8547
8548/// DictRange
8549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8550#[cfg_attr(feature = "bindings", derive(TS))]
8551pub struct DictRange {
8552    pub this: Box<Expression>,
8553    #[serde(default)]
8554    pub min: Option<Box<Expression>>,
8555    #[serde(default)]
8556    pub max: Option<Box<Expression>>,
8557}
8558
8559/// OnCluster
8560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8561#[cfg_attr(feature = "bindings", derive(TS))]
8562pub struct OnCluster {
8563    pub this: Box<Expression>,
8564}
8565
8566/// LikeProperty
8567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8568#[cfg_attr(feature = "bindings", derive(TS))]
8569pub struct LikeProperty {
8570    pub this: Box<Expression>,
8571    #[serde(default)]
8572    pub expressions: Vec<Expression>,
8573}
8574
8575/// LocationProperty
8576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8577#[cfg_attr(feature = "bindings", derive(TS))]
8578pub struct LocationProperty {
8579    pub this: Box<Expression>,
8580}
8581
8582/// LockProperty
8583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8584#[cfg_attr(feature = "bindings", derive(TS))]
8585pub struct LockProperty {
8586    pub this: Box<Expression>,
8587}
8588
8589/// LockingProperty
8590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8591#[cfg_attr(feature = "bindings", derive(TS))]
8592pub struct LockingProperty {
8593    #[serde(default)]
8594    pub this: Option<Box<Expression>>,
8595    pub kind: String,
8596    #[serde(default)]
8597    pub for_or_in: Option<Box<Expression>>,
8598    #[serde(default)]
8599    pub lock_type: Option<Box<Expression>>,
8600    #[serde(default)]
8601    pub override_: Option<Box<Expression>>,
8602}
8603
8604/// LogProperty
8605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8606#[cfg_attr(feature = "bindings", derive(TS))]
8607pub struct LogProperty {
8608    #[serde(default)]
8609    pub no: Option<Box<Expression>>,
8610}
8611
8612/// MaterializedProperty
8613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8614#[cfg_attr(feature = "bindings", derive(TS))]
8615pub struct MaterializedProperty {
8616    #[serde(default)]
8617    pub this: Option<Box<Expression>>,
8618}
8619
8620/// MergeBlockRatioProperty
8621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8622#[cfg_attr(feature = "bindings", derive(TS))]
8623pub struct MergeBlockRatioProperty {
8624    #[serde(default)]
8625    pub this: Option<Box<Expression>>,
8626    #[serde(default)]
8627    pub no: Option<Box<Expression>>,
8628    #[serde(default)]
8629    pub default: Option<Box<Expression>>,
8630    #[serde(default)]
8631    pub percent: Option<Box<Expression>>,
8632}
8633
8634/// OnProperty
8635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8636#[cfg_attr(feature = "bindings", derive(TS))]
8637pub struct OnProperty {
8638    pub this: Box<Expression>,
8639}
8640
8641/// OnCommitProperty
8642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8643#[cfg_attr(feature = "bindings", derive(TS))]
8644pub struct OnCommitProperty {
8645    #[serde(default)]
8646    pub delete: Option<Box<Expression>>,
8647}
8648
8649/// PartitionedByProperty
8650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8651#[cfg_attr(feature = "bindings", derive(TS))]
8652pub struct PartitionedByProperty {
8653    pub this: Box<Expression>,
8654}
8655
8656/// PartitionedByBucket
8657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8658#[cfg_attr(feature = "bindings", derive(TS))]
8659pub struct PartitionedByBucket {
8660    pub this: Box<Expression>,
8661    pub expression: Box<Expression>,
8662}
8663
8664/// PartitionByTruncate
8665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8666#[cfg_attr(feature = "bindings", derive(TS))]
8667pub struct PartitionByTruncate {
8668    pub this: Box<Expression>,
8669    pub expression: Box<Expression>,
8670}
8671
8672/// PartitionByRangeProperty
8673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8674#[cfg_attr(feature = "bindings", derive(TS))]
8675pub struct PartitionByRangeProperty {
8676    #[serde(default)]
8677    pub partition_expressions: Option<Box<Expression>>,
8678    #[serde(default)]
8679    pub create_expressions: Option<Box<Expression>>,
8680}
8681
8682/// PartitionByRangePropertyDynamic
8683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8684#[cfg_attr(feature = "bindings", derive(TS))]
8685pub struct PartitionByRangePropertyDynamic {
8686    #[serde(default)]
8687    pub this: Option<Box<Expression>>,
8688    #[serde(default)]
8689    pub start: Option<Box<Expression>>,
8690    #[serde(default)]
8691    pub end: Option<Box<Expression>>,
8692    #[serde(default)]
8693    pub every: Option<Box<Expression>>,
8694}
8695
8696/// PartitionByListProperty
8697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8698#[cfg_attr(feature = "bindings", derive(TS))]
8699pub struct PartitionByListProperty {
8700    #[serde(default)]
8701    pub partition_expressions: Option<Box<Expression>>,
8702    #[serde(default)]
8703    pub create_expressions: Option<Box<Expression>>,
8704}
8705
8706/// PartitionList
8707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8708#[cfg_attr(feature = "bindings", derive(TS))]
8709pub struct PartitionList {
8710    pub this: Box<Expression>,
8711    #[serde(default)]
8712    pub expressions: Vec<Expression>,
8713}
8714
8715/// Partition - represents PARTITION/SUBPARTITION clause
8716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8717#[cfg_attr(feature = "bindings", derive(TS))]
8718pub struct Partition {
8719    pub expressions: Vec<Expression>,
8720    #[serde(default)]
8721    pub subpartition: bool,
8722}
8723
8724/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
8725/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
8726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8727#[cfg_attr(feature = "bindings", derive(TS))]
8728pub struct RefreshTriggerProperty {
8729    /// Method: COMPLETE or AUTO
8730    pub method: String,
8731    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
8732    #[serde(default)]
8733    pub kind: Option<String>,
8734    /// For SCHEDULE: EVERY n (the number)
8735    #[serde(default)]
8736    pub every: Option<Box<Expression>>,
8737    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
8738    #[serde(default)]
8739    pub unit: Option<String>,
8740    /// For SCHEDULE: STARTS 'datetime'
8741    #[serde(default)]
8742    pub starts: Option<Box<Expression>>,
8743}
8744
8745/// UniqueKeyProperty
8746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8747#[cfg_attr(feature = "bindings", derive(TS))]
8748pub struct UniqueKeyProperty {
8749    #[serde(default)]
8750    pub expressions: Vec<Expression>,
8751}
8752
8753/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
8754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8755#[cfg_attr(feature = "bindings", derive(TS))]
8756pub struct RollupProperty {
8757    pub expressions: Vec<RollupIndex>,
8758}
8759
8760/// RollupIndex - A single rollup index: name(col1, col2)
8761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8762#[cfg_attr(feature = "bindings", derive(TS))]
8763pub struct RollupIndex {
8764    pub name: Identifier,
8765    pub expressions: Vec<Identifier>,
8766}
8767
8768/// PartitionBoundSpec
8769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8770#[cfg_attr(feature = "bindings", derive(TS))]
8771pub struct PartitionBoundSpec {
8772    #[serde(default)]
8773    pub this: Option<Box<Expression>>,
8774    #[serde(default)]
8775    pub expression: Option<Box<Expression>>,
8776    #[serde(default)]
8777    pub from_expressions: Option<Box<Expression>>,
8778    #[serde(default)]
8779    pub to_expressions: Option<Box<Expression>>,
8780}
8781
8782/// PartitionedOfProperty
8783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8784#[cfg_attr(feature = "bindings", derive(TS))]
8785pub struct PartitionedOfProperty {
8786    pub this: Box<Expression>,
8787    pub expression: Box<Expression>,
8788}
8789
8790/// RemoteWithConnectionModelProperty
8791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8792#[cfg_attr(feature = "bindings", derive(TS))]
8793pub struct RemoteWithConnectionModelProperty {
8794    pub this: Box<Expression>,
8795}
8796
8797/// ReturnsProperty
8798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8799#[cfg_attr(feature = "bindings", derive(TS))]
8800pub struct ReturnsProperty {
8801    #[serde(default)]
8802    pub this: Option<Box<Expression>>,
8803    #[serde(default)]
8804    pub is_table: Option<Box<Expression>>,
8805    #[serde(default)]
8806    pub table: Option<Box<Expression>>,
8807    #[serde(default)]
8808    pub null: Option<Box<Expression>>,
8809}
8810
8811/// RowFormatProperty
8812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8813#[cfg_attr(feature = "bindings", derive(TS))]
8814pub struct RowFormatProperty {
8815    pub this: Box<Expression>,
8816}
8817
8818/// RowFormatDelimitedProperty
8819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8820#[cfg_attr(feature = "bindings", derive(TS))]
8821pub struct RowFormatDelimitedProperty {
8822    #[serde(default)]
8823    pub fields: Option<Box<Expression>>,
8824    #[serde(default)]
8825    pub escaped: Option<Box<Expression>>,
8826    #[serde(default)]
8827    pub collection_items: Option<Box<Expression>>,
8828    #[serde(default)]
8829    pub map_keys: Option<Box<Expression>>,
8830    #[serde(default)]
8831    pub lines: Option<Box<Expression>>,
8832    #[serde(default)]
8833    pub null: Option<Box<Expression>>,
8834    #[serde(default)]
8835    pub serde: Option<Box<Expression>>,
8836}
8837
8838/// RowFormatSerdeProperty
8839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8840#[cfg_attr(feature = "bindings", derive(TS))]
8841pub struct RowFormatSerdeProperty {
8842    pub this: Box<Expression>,
8843    #[serde(default)]
8844    pub serde_properties: Option<Box<Expression>>,
8845}
8846
8847/// QueryTransform
8848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8849#[cfg_attr(feature = "bindings", derive(TS))]
8850pub struct QueryTransform {
8851    #[serde(default)]
8852    pub expressions: Vec<Expression>,
8853    #[serde(default)]
8854    pub command_script: Option<Box<Expression>>,
8855    #[serde(default)]
8856    pub schema: Option<Box<Expression>>,
8857    #[serde(default)]
8858    pub row_format_before: Option<Box<Expression>>,
8859    #[serde(default)]
8860    pub record_writer: Option<Box<Expression>>,
8861    #[serde(default)]
8862    pub row_format_after: Option<Box<Expression>>,
8863    #[serde(default)]
8864    pub record_reader: Option<Box<Expression>>,
8865}
8866
8867/// SampleProperty
8868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8869#[cfg_attr(feature = "bindings", derive(TS))]
8870pub struct SampleProperty {
8871    pub this: Box<Expression>,
8872}
8873
8874/// SecurityProperty
8875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8876#[cfg_attr(feature = "bindings", derive(TS))]
8877pub struct SecurityProperty {
8878    pub this: Box<Expression>,
8879}
8880
8881/// SchemaCommentProperty
8882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8883#[cfg_attr(feature = "bindings", derive(TS))]
8884pub struct SchemaCommentProperty {
8885    pub this: Box<Expression>,
8886}
8887
8888/// SemanticView
8889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8890#[cfg_attr(feature = "bindings", derive(TS))]
8891pub struct SemanticView {
8892    pub this: Box<Expression>,
8893    #[serde(default)]
8894    pub metrics: Option<Box<Expression>>,
8895    #[serde(default)]
8896    pub dimensions: Option<Box<Expression>>,
8897    #[serde(default)]
8898    pub facts: Option<Box<Expression>>,
8899    #[serde(default)]
8900    pub where_: Option<Box<Expression>>,
8901}
8902
8903/// SerdeProperties
8904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8905#[cfg_attr(feature = "bindings", derive(TS))]
8906pub struct SerdeProperties {
8907    #[serde(default)]
8908    pub expressions: Vec<Expression>,
8909    #[serde(default)]
8910    pub with_: Option<Box<Expression>>,
8911}
8912
8913/// SetProperty
8914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8915#[cfg_attr(feature = "bindings", derive(TS))]
8916pub struct SetProperty {
8917    #[serde(default)]
8918    pub multi: Option<Box<Expression>>,
8919}
8920
8921/// SharingProperty
8922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8923#[cfg_attr(feature = "bindings", derive(TS))]
8924pub struct SharingProperty {
8925    #[serde(default)]
8926    pub this: Option<Box<Expression>>,
8927}
8928
8929/// SetConfigProperty
8930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8931#[cfg_attr(feature = "bindings", derive(TS))]
8932pub struct SetConfigProperty {
8933    pub this: Box<Expression>,
8934}
8935
8936/// SettingsProperty
8937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8938#[cfg_attr(feature = "bindings", derive(TS))]
8939pub struct SettingsProperty {
8940    #[serde(default)]
8941    pub expressions: Vec<Expression>,
8942}
8943
8944/// SortKeyProperty
8945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8946#[cfg_attr(feature = "bindings", derive(TS))]
8947pub struct SortKeyProperty {
8948    pub this: Box<Expression>,
8949    #[serde(default)]
8950    pub compound: Option<Box<Expression>>,
8951}
8952
8953/// SqlReadWriteProperty
8954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8955#[cfg_attr(feature = "bindings", derive(TS))]
8956pub struct SqlReadWriteProperty {
8957    pub this: Box<Expression>,
8958}
8959
8960/// SqlSecurityProperty
8961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8962#[cfg_attr(feature = "bindings", derive(TS))]
8963pub struct SqlSecurityProperty {
8964    pub this: Box<Expression>,
8965}
8966
8967/// StabilityProperty
8968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8969#[cfg_attr(feature = "bindings", derive(TS))]
8970pub struct StabilityProperty {
8971    pub this: Box<Expression>,
8972}
8973
8974/// StorageHandlerProperty
8975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8976#[cfg_attr(feature = "bindings", derive(TS))]
8977pub struct StorageHandlerProperty {
8978    pub this: Box<Expression>,
8979}
8980
8981/// TemporaryProperty
8982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8983#[cfg_attr(feature = "bindings", derive(TS))]
8984pub struct TemporaryProperty {
8985    #[serde(default)]
8986    pub this: Option<Box<Expression>>,
8987}
8988
8989/// Tags
8990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8991#[cfg_attr(feature = "bindings", derive(TS))]
8992pub struct Tags {
8993    #[serde(default)]
8994    pub expressions: Vec<Expression>,
8995}
8996
8997/// TransformModelProperty
8998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8999#[cfg_attr(feature = "bindings", derive(TS))]
9000pub struct TransformModelProperty {
9001    #[serde(default)]
9002    pub expressions: Vec<Expression>,
9003}
9004
9005/// TransientProperty
9006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9007#[cfg_attr(feature = "bindings", derive(TS))]
9008pub struct TransientProperty {
9009    #[serde(default)]
9010    pub this: Option<Box<Expression>>,
9011}
9012
9013/// UsingTemplateProperty
9014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9015#[cfg_attr(feature = "bindings", derive(TS))]
9016pub struct UsingTemplateProperty {
9017    pub this: Box<Expression>,
9018}
9019
9020/// ViewAttributeProperty
9021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9022#[cfg_attr(feature = "bindings", derive(TS))]
9023pub struct ViewAttributeProperty {
9024    pub this: Box<Expression>,
9025}
9026
9027/// VolatileProperty
9028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9029#[cfg_attr(feature = "bindings", derive(TS))]
9030pub struct VolatileProperty {
9031    #[serde(default)]
9032    pub this: Option<Box<Expression>>,
9033}
9034
9035/// WithDataProperty
9036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9037#[cfg_attr(feature = "bindings", derive(TS))]
9038pub struct WithDataProperty {
9039    #[serde(default)]
9040    pub no: Option<Box<Expression>>,
9041    #[serde(default)]
9042    pub statistics: Option<Box<Expression>>,
9043}
9044
9045/// WithJournalTableProperty
9046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9047#[cfg_attr(feature = "bindings", derive(TS))]
9048pub struct WithJournalTableProperty {
9049    pub this: Box<Expression>,
9050}
9051
9052/// WithSchemaBindingProperty
9053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9054#[cfg_attr(feature = "bindings", derive(TS))]
9055pub struct WithSchemaBindingProperty {
9056    pub this: Box<Expression>,
9057}
9058
9059/// WithSystemVersioningProperty
9060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9061#[cfg_attr(feature = "bindings", derive(TS))]
9062pub struct WithSystemVersioningProperty {
9063    #[serde(default)]
9064    pub on: Option<Box<Expression>>,
9065    #[serde(default)]
9066    pub this: Option<Box<Expression>>,
9067    #[serde(default)]
9068    pub data_consistency: Option<Box<Expression>>,
9069    #[serde(default)]
9070    pub retention_period: Option<Box<Expression>>,
9071    #[serde(default)]
9072    pub with_: Option<Box<Expression>>,
9073}
9074
9075/// WithProcedureOptions
9076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9077#[cfg_attr(feature = "bindings", derive(TS))]
9078pub struct WithProcedureOptions {
9079    #[serde(default)]
9080    pub expressions: Vec<Expression>,
9081}
9082
9083/// EncodeProperty
9084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9085#[cfg_attr(feature = "bindings", derive(TS))]
9086pub struct EncodeProperty {
9087    pub this: Box<Expression>,
9088    #[serde(default)]
9089    pub properties: Vec<Expression>,
9090    #[serde(default)]
9091    pub key: Option<Box<Expression>>,
9092}
9093
9094/// IncludeProperty
9095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9096#[cfg_attr(feature = "bindings", derive(TS))]
9097pub struct IncludeProperty {
9098    pub this: Box<Expression>,
9099    #[serde(default)]
9100    pub alias: Option<String>,
9101    #[serde(default)]
9102    pub column_def: Option<Box<Expression>>,
9103}
9104
9105/// Properties
9106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9107#[cfg_attr(feature = "bindings", derive(TS))]
9108pub struct Properties {
9109    #[serde(default)]
9110    pub expressions: Vec<Expression>,
9111}
9112
9113/// InputOutputFormat
9114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9115#[cfg_attr(feature = "bindings", derive(TS))]
9116pub struct InputOutputFormat {
9117    #[serde(default)]
9118    pub input_format: Option<Box<Expression>>,
9119    #[serde(default)]
9120    pub output_format: Option<Box<Expression>>,
9121}
9122
9123/// Reference
9124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9125#[cfg_attr(feature = "bindings", derive(TS))]
9126pub struct Reference {
9127    pub this: Box<Expression>,
9128    #[serde(default)]
9129    pub expressions: Vec<Expression>,
9130    #[serde(default)]
9131    pub options: Vec<Expression>,
9132}
9133
9134/// QueryOption
9135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9136#[cfg_attr(feature = "bindings", derive(TS))]
9137pub struct QueryOption {
9138    pub this: Box<Expression>,
9139    #[serde(default)]
9140    pub expression: Option<Box<Expression>>,
9141}
9142
9143/// WithTableHint
9144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9145#[cfg_attr(feature = "bindings", derive(TS))]
9146pub struct WithTableHint {
9147    #[serde(default)]
9148    pub expressions: Vec<Expression>,
9149}
9150
9151/// IndexTableHint
9152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9153#[cfg_attr(feature = "bindings", derive(TS))]
9154pub struct IndexTableHint {
9155    pub this: Box<Expression>,
9156    #[serde(default)]
9157    pub expressions: Vec<Expression>,
9158    #[serde(default)]
9159    pub target: Option<Box<Expression>>,
9160}
9161
9162/// Get
9163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9164#[cfg_attr(feature = "bindings", derive(TS))]
9165pub struct Get {
9166    pub this: Box<Expression>,
9167    #[serde(default)]
9168    pub target: Option<Box<Expression>>,
9169    #[serde(default)]
9170    pub properties: Vec<Expression>,
9171}
9172
9173/// SetOperation
9174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9175#[cfg_attr(feature = "bindings", derive(TS))]
9176pub struct SetOperation {
9177    #[serde(default)]
9178    pub with_: Option<Box<Expression>>,
9179    pub this: Box<Expression>,
9180    pub expression: Box<Expression>,
9181    #[serde(default)]
9182    pub distinct: bool,
9183    #[serde(default)]
9184    pub by_name: Option<Box<Expression>>,
9185    #[serde(default)]
9186    pub side: Option<Box<Expression>>,
9187    #[serde(default)]
9188    pub kind: Option<String>,
9189    #[serde(default)]
9190    pub on: Option<Box<Expression>>,
9191}
9192
9193/// Var - Simple variable reference (for SQL variables, keywords as values)
9194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9195#[cfg_attr(feature = "bindings", derive(TS))]
9196pub struct Var {
9197    pub this: String,
9198}
9199
9200/// Version
9201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9202#[cfg_attr(feature = "bindings", derive(TS))]
9203pub struct Version {
9204    pub this: Box<Expression>,
9205    pub kind: String,
9206    #[serde(default)]
9207    pub expression: Option<Box<Expression>>,
9208}
9209
9210/// Schema
9211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9212#[cfg_attr(feature = "bindings", derive(TS))]
9213pub struct Schema {
9214    #[serde(default)]
9215    pub this: Option<Box<Expression>>,
9216    #[serde(default)]
9217    pub expressions: Vec<Expression>,
9218}
9219
9220/// Lock
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct Lock {
9224    #[serde(default)]
9225    pub update: Option<Box<Expression>>,
9226    #[serde(default)]
9227    pub expressions: Vec<Expression>,
9228    #[serde(default)]
9229    pub wait: Option<Box<Expression>>,
9230    #[serde(default)]
9231    pub key: Option<Box<Expression>>,
9232}
9233
9234/// TableSample - wraps an expression with a TABLESAMPLE clause
9235/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9237#[cfg_attr(feature = "bindings", derive(TS))]
9238pub struct TableSample {
9239    /// The expression being sampled (subquery, function, etc.)
9240    #[serde(default, skip_serializing_if = "Option::is_none")]
9241    pub this: Option<Box<Expression>>,
9242    /// The sample specification
9243    #[serde(default, skip_serializing_if = "Option::is_none")]
9244    pub sample: Option<Box<Sample>>,
9245    #[serde(default)]
9246    pub expressions: Vec<Expression>,
9247    #[serde(default)]
9248    pub method: Option<String>,
9249    #[serde(default)]
9250    pub bucket_numerator: Option<Box<Expression>>,
9251    #[serde(default)]
9252    pub bucket_denominator: Option<Box<Expression>>,
9253    #[serde(default)]
9254    pub bucket_field: Option<Box<Expression>>,
9255    #[serde(default)]
9256    pub percent: Option<Box<Expression>>,
9257    #[serde(default)]
9258    pub rows: Option<Box<Expression>>,
9259    #[serde(default)]
9260    pub size: Option<i64>,
9261    #[serde(default)]
9262    pub seed: Option<Box<Expression>>,
9263}
9264
9265/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9267#[cfg_attr(feature = "bindings", derive(TS))]
9268pub struct Tag {
9269    #[serde(default)]
9270    pub this: Option<Box<Expression>>,
9271    #[serde(default)]
9272    pub prefix: Option<Box<Expression>>,
9273    #[serde(default)]
9274    pub postfix: Option<Box<Expression>>,
9275}
9276
9277/// UnpivotColumns
9278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9279#[cfg_attr(feature = "bindings", derive(TS))]
9280pub struct UnpivotColumns {
9281    pub this: Box<Expression>,
9282    #[serde(default)]
9283    pub expressions: Vec<Expression>,
9284}
9285
9286/// SessionParameter
9287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9288#[cfg_attr(feature = "bindings", derive(TS))]
9289pub struct SessionParameter {
9290    pub this: Box<Expression>,
9291    #[serde(default)]
9292    pub kind: Option<String>,
9293}
9294
9295/// PseudoType
9296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9297#[cfg_attr(feature = "bindings", derive(TS))]
9298pub struct PseudoType {
9299    pub this: Box<Expression>,
9300}
9301
9302/// ObjectIdentifier
9303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9304#[cfg_attr(feature = "bindings", derive(TS))]
9305pub struct ObjectIdentifier {
9306    pub this: Box<Expression>,
9307}
9308
9309/// Transaction
9310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9311#[cfg_attr(feature = "bindings", derive(TS))]
9312pub struct Transaction {
9313    #[serde(default)]
9314    pub this: Option<Box<Expression>>,
9315    #[serde(default)]
9316    pub modes: Option<Box<Expression>>,
9317    #[serde(default)]
9318    pub mark: Option<Box<Expression>>,
9319}
9320
9321/// Commit
9322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9323#[cfg_attr(feature = "bindings", derive(TS))]
9324pub struct Commit {
9325    #[serde(default)]
9326    pub chain: Option<Box<Expression>>,
9327    #[serde(default)]
9328    pub this: Option<Box<Expression>>,
9329    #[serde(default)]
9330    pub durability: Option<Box<Expression>>,
9331}
9332
9333/// Rollback
9334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9335#[cfg_attr(feature = "bindings", derive(TS))]
9336pub struct Rollback {
9337    #[serde(default)]
9338    pub savepoint: Option<Box<Expression>>,
9339    #[serde(default)]
9340    pub this: Option<Box<Expression>>,
9341}
9342
9343/// AlterSession
9344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9345#[cfg_attr(feature = "bindings", derive(TS))]
9346pub struct AlterSession {
9347    #[serde(default)]
9348    pub expressions: Vec<Expression>,
9349    #[serde(default)]
9350    pub unset: Option<Box<Expression>>,
9351}
9352
9353/// Analyze
9354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9355#[cfg_attr(feature = "bindings", derive(TS))]
9356pub struct Analyze {
9357    #[serde(default)]
9358    pub kind: Option<String>,
9359    #[serde(default)]
9360    pub this: Option<Box<Expression>>,
9361    #[serde(default)]
9362    pub options: Vec<Expression>,
9363    #[serde(default)]
9364    pub mode: Option<Box<Expression>>,
9365    #[serde(default)]
9366    pub partition: Option<Box<Expression>>,
9367    #[serde(default)]
9368    pub expression: Option<Box<Expression>>,
9369    #[serde(default)]
9370    pub properties: Vec<Expression>,
9371    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9372    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9373    pub columns: Vec<String>,
9374}
9375
9376/// AnalyzeStatistics
9377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9378#[cfg_attr(feature = "bindings", derive(TS))]
9379pub struct AnalyzeStatistics {
9380    pub kind: String,
9381    #[serde(default)]
9382    pub option: Option<Box<Expression>>,
9383    #[serde(default)]
9384    pub this: Option<Box<Expression>>,
9385    #[serde(default)]
9386    pub expressions: Vec<Expression>,
9387}
9388
9389/// AnalyzeHistogram
9390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9391#[cfg_attr(feature = "bindings", derive(TS))]
9392pub struct AnalyzeHistogram {
9393    pub this: Box<Expression>,
9394    #[serde(default)]
9395    pub expressions: Vec<Expression>,
9396    #[serde(default)]
9397    pub expression: Option<Box<Expression>>,
9398    #[serde(default)]
9399    pub update_options: Option<Box<Expression>>,
9400}
9401
9402/// AnalyzeSample
9403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9404#[cfg_attr(feature = "bindings", derive(TS))]
9405pub struct AnalyzeSample {
9406    pub kind: String,
9407    #[serde(default)]
9408    pub sample: Option<Box<Expression>>,
9409}
9410
9411/// AnalyzeListChainedRows
9412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9413#[cfg_attr(feature = "bindings", derive(TS))]
9414pub struct AnalyzeListChainedRows {
9415    #[serde(default)]
9416    pub expression: Option<Box<Expression>>,
9417}
9418
9419/// AnalyzeDelete
9420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9421#[cfg_attr(feature = "bindings", derive(TS))]
9422pub struct AnalyzeDelete {
9423    #[serde(default)]
9424    pub kind: Option<String>,
9425}
9426
9427/// AnalyzeWith
9428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9429#[cfg_attr(feature = "bindings", derive(TS))]
9430pub struct AnalyzeWith {
9431    #[serde(default)]
9432    pub expressions: Vec<Expression>,
9433}
9434
9435/// AnalyzeValidate
9436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9437#[cfg_attr(feature = "bindings", derive(TS))]
9438pub struct AnalyzeValidate {
9439    pub kind: String,
9440    #[serde(default)]
9441    pub this: Option<Box<Expression>>,
9442    #[serde(default)]
9443    pub expression: Option<Box<Expression>>,
9444}
9445
9446/// AddPartition
9447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9448#[cfg_attr(feature = "bindings", derive(TS))]
9449pub struct AddPartition {
9450    pub this: Box<Expression>,
9451    #[serde(default)]
9452    pub exists: bool,
9453    #[serde(default)]
9454    pub location: Option<Box<Expression>>,
9455}
9456
9457/// AttachOption
9458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9459#[cfg_attr(feature = "bindings", derive(TS))]
9460pub struct AttachOption {
9461    pub this: Box<Expression>,
9462    #[serde(default)]
9463    pub expression: Option<Box<Expression>>,
9464}
9465
9466/// DropPartition
9467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9468#[cfg_attr(feature = "bindings", derive(TS))]
9469pub struct DropPartition {
9470    #[serde(default)]
9471    pub expressions: Vec<Expression>,
9472    #[serde(default)]
9473    pub exists: bool,
9474}
9475
9476/// ReplacePartition
9477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9478#[cfg_attr(feature = "bindings", derive(TS))]
9479pub struct ReplacePartition {
9480    pub expression: Box<Expression>,
9481    #[serde(default)]
9482    pub source: Option<Box<Expression>>,
9483}
9484
9485/// DPipe
9486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9487#[cfg_attr(feature = "bindings", derive(TS))]
9488pub struct DPipe {
9489    pub this: Box<Expression>,
9490    pub expression: Box<Expression>,
9491    #[serde(default)]
9492    pub safe: Option<Box<Expression>>,
9493}
9494
9495/// Operator
9496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9497#[cfg_attr(feature = "bindings", derive(TS))]
9498pub struct Operator {
9499    pub this: Box<Expression>,
9500    #[serde(default)]
9501    pub operator: Option<Box<Expression>>,
9502    pub expression: Box<Expression>,
9503}
9504
9505/// PivotAny
9506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9507#[cfg_attr(feature = "bindings", derive(TS))]
9508pub struct PivotAny {
9509    #[serde(default)]
9510    pub this: Option<Box<Expression>>,
9511}
9512
9513/// Aliases
9514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9515#[cfg_attr(feature = "bindings", derive(TS))]
9516pub struct Aliases {
9517    pub this: Box<Expression>,
9518    #[serde(default)]
9519    pub expressions: Vec<Expression>,
9520}
9521
9522/// AtIndex
9523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9524#[cfg_attr(feature = "bindings", derive(TS))]
9525pub struct AtIndex {
9526    pub this: Box<Expression>,
9527    pub expression: Box<Expression>,
9528}
9529
9530/// FromTimeZone
9531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9532#[cfg_attr(feature = "bindings", derive(TS))]
9533pub struct FromTimeZone {
9534    pub this: Box<Expression>,
9535    #[serde(default)]
9536    pub zone: Option<Box<Expression>>,
9537}
9538
9539/// Format override for a column in Teradata
9540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9541#[cfg_attr(feature = "bindings", derive(TS))]
9542pub struct FormatPhrase {
9543    pub this: Box<Expression>,
9544    pub format: String,
9545}
9546
9547/// ForIn
9548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9549#[cfg_attr(feature = "bindings", derive(TS))]
9550pub struct ForIn {
9551    pub this: Box<Expression>,
9552    pub expression: Box<Expression>,
9553}
9554
9555/// Automatically converts unit arg into a var.
9556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9557#[cfg_attr(feature = "bindings", derive(TS))]
9558pub struct TimeUnit {
9559    #[serde(default)]
9560    pub unit: Option<String>,
9561}
9562
9563/// IntervalOp
9564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9565#[cfg_attr(feature = "bindings", derive(TS))]
9566pub struct IntervalOp {
9567    #[serde(default)]
9568    pub unit: Option<String>,
9569    pub expression: Box<Expression>,
9570}
9571
9572/// HavingMax
9573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9574#[cfg_attr(feature = "bindings", derive(TS))]
9575pub struct HavingMax {
9576    pub this: Box<Expression>,
9577    pub expression: Box<Expression>,
9578    #[serde(default)]
9579    pub max: Option<Box<Expression>>,
9580}
9581
9582/// CosineDistance
9583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9584#[cfg_attr(feature = "bindings", derive(TS))]
9585pub struct CosineDistance {
9586    pub this: Box<Expression>,
9587    pub expression: Box<Expression>,
9588}
9589
9590/// DotProduct
9591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9592#[cfg_attr(feature = "bindings", derive(TS))]
9593pub struct DotProduct {
9594    pub this: Box<Expression>,
9595    pub expression: Box<Expression>,
9596}
9597
9598/// EuclideanDistance
9599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9600#[cfg_attr(feature = "bindings", derive(TS))]
9601pub struct EuclideanDistance {
9602    pub this: Box<Expression>,
9603    pub expression: Box<Expression>,
9604}
9605
9606/// ManhattanDistance
9607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9608#[cfg_attr(feature = "bindings", derive(TS))]
9609pub struct ManhattanDistance {
9610    pub this: Box<Expression>,
9611    pub expression: Box<Expression>,
9612}
9613
9614/// JarowinklerSimilarity
9615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9616#[cfg_attr(feature = "bindings", derive(TS))]
9617pub struct JarowinklerSimilarity {
9618    pub this: Box<Expression>,
9619    pub expression: Box<Expression>,
9620}
9621
9622/// Booland
9623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9624#[cfg_attr(feature = "bindings", derive(TS))]
9625pub struct Booland {
9626    pub this: Box<Expression>,
9627    pub expression: Box<Expression>,
9628}
9629
9630/// Boolor
9631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9632#[cfg_attr(feature = "bindings", derive(TS))]
9633pub struct Boolor {
9634    pub this: Box<Expression>,
9635    pub expression: Box<Expression>,
9636}
9637
9638/// ParameterizedAgg
9639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9640#[cfg_attr(feature = "bindings", derive(TS))]
9641pub struct ParameterizedAgg {
9642    pub this: Box<Expression>,
9643    #[serde(default)]
9644    pub expressions: Vec<Expression>,
9645    #[serde(default)]
9646    pub params: Vec<Expression>,
9647}
9648
9649/// ArgMax
9650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9651#[cfg_attr(feature = "bindings", derive(TS))]
9652pub struct ArgMax {
9653    pub this: Box<Expression>,
9654    pub expression: Box<Expression>,
9655    #[serde(default)]
9656    pub count: Option<Box<Expression>>,
9657}
9658
9659/// ArgMin
9660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9661#[cfg_attr(feature = "bindings", derive(TS))]
9662pub struct ArgMin {
9663    pub this: Box<Expression>,
9664    pub expression: Box<Expression>,
9665    #[serde(default)]
9666    pub count: Option<Box<Expression>>,
9667}
9668
9669/// ApproxTopK
9670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9671#[cfg_attr(feature = "bindings", derive(TS))]
9672pub struct ApproxTopK {
9673    pub this: Box<Expression>,
9674    #[serde(default)]
9675    pub expression: Option<Box<Expression>>,
9676    #[serde(default)]
9677    pub counters: Option<Box<Expression>>,
9678}
9679
9680/// ApproxTopKAccumulate
9681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9682#[cfg_attr(feature = "bindings", derive(TS))]
9683pub struct ApproxTopKAccumulate {
9684    pub this: Box<Expression>,
9685    #[serde(default)]
9686    pub expression: Option<Box<Expression>>,
9687}
9688
9689/// ApproxTopKCombine
9690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9691#[cfg_attr(feature = "bindings", derive(TS))]
9692pub struct ApproxTopKCombine {
9693    pub this: Box<Expression>,
9694    #[serde(default)]
9695    pub expression: Option<Box<Expression>>,
9696}
9697
9698/// ApproxTopKEstimate
9699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9700#[cfg_attr(feature = "bindings", derive(TS))]
9701pub struct ApproxTopKEstimate {
9702    pub this: Box<Expression>,
9703    #[serde(default)]
9704    pub expression: Option<Box<Expression>>,
9705}
9706
9707/// ApproxTopSum
9708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9709#[cfg_attr(feature = "bindings", derive(TS))]
9710pub struct ApproxTopSum {
9711    pub this: Box<Expression>,
9712    pub expression: Box<Expression>,
9713    #[serde(default)]
9714    pub count: Option<Box<Expression>>,
9715}
9716
9717/// ApproxQuantiles
9718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9719#[cfg_attr(feature = "bindings", derive(TS))]
9720pub struct ApproxQuantiles {
9721    pub this: Box<Expression>,
9722    #[serde(default)]
9723    pub expression: Option<Box<Expression>>,
9724}
9725
9726/// Minhash
9727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9728#[cfg_attr(feature = "bindings", derive(TS))]
9729pub struct Minhash {
9730    pub this: Box<Expression>,
9731    #[serde(default)]
9732    pub expressions: Vec<Expression>,
9733}
9734
9735/// FarmFingerprint
9736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9737#[cfg_attr(feature = "bindings", derive(TS))]
9738pub struct FarmFingerprint {
9739    #[serde(default)]
9740    pub expressions: Vec<Expression>,
9741}
9742
9743/// Float64
9744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9745#[cfg_attr(feature = "bindings", derive(TS))]
9746pub struct Float64 {
9747    pub this: Box<Expression>,
9748    #[serde(default)]
9749    pub expression: Option<Box<Expression>>,
9750}
9751
9752/// Transform
9753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9754#[cfg_attr(feature = "bindings", derive(TS))]
9755pub struct Transform {
9756    pub this: Box<Expression>,
9757    pub expression: Box<Expression>,
9758}
9759
9760/// Translate
9761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9762#[cfg_attr(feature = "bindings", derive(TS))]
9763pub struct Translate {
9764    pub this: Box<Expression>,
9765    #[serde(default)]
9766    pub from_: Option<Box<Expression>>,
9767    #[serde(default)]
9768    pub to: Option<Box<Expression>>,
9769}
9770
9771/// Grouping
9772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9773#[cfg_attr(feature = "bindings", derive(TS))]
9774pub struct Grouping {
9775    #[serde(default)]
9776    pub expressions: Vec<Expression>,
9777}
9778
9779/// GroupingId
9780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9781#[cfg_attr(feature = "bindings", derive(TS))]
9782pub struct GroupingId {
9783    #[serde(default)]
9784    pub expressions: Vec<Expression>,
9785}
9786
9787/// Anonymous
9788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9789#[cfg_attr(feature = "bindings", derive(TS))]
9790pub struct Anonymous {
9791    pub this: Box<Expression>,
9792    #[serde(default)]
9793    pub expressions: Vec<Expression>,
9794}
9795
9796/// AnonymousAggFunc
9797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9798#[cfg_attr(feature = "bindings", derive(TS))]
9799pub struct AnonymousAggFunc {
9800    pub this: Box<Expression>,
9801    #[serde(default)]
9802    pub expressions: Vec<Expression>,
9803}
9804
9805/// CombinedAggFunc
9806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9807#[cfg_attr(feature = "bindings", derive(TS))]
9808pub struct CombinedAggFunc {
9809    pub this: Box<Expression>,
9810    #[serde(default)]
9811    pub expressions: Vec<Expression>,
9812}
9813
9814/// CombinedParameterizedAgg
9815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9816#[cfg_attr(feature = "bindings", derive(TS))]
9817pub struct CombinedParameterizedAgg {
9818    pub this: Box<Expression>,
9819    #[serde(default)]
9820    pub expressions: Vec<Expression>,
9821    #[serde(default)]
9822    pub params: Vec<Expression>,
9823}
9824
9825/// HashAgg
9826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9827#[cfg_attr(feature = "bindings", derive(TS))]
9828pub struct HashAgg {
9829    pub this: Box<Expression>,
9830    #[serde(default)]
9831    pub expressions: Vec<Expression>,
9832}
9833
9834/// Hll
9835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9836#[cfg_attr(feature = "bindings", derive(TS))]
9837pub struct Hll {
9838    pub this: Box<Expression>,
9839    #[serde(default)]
9840    pub expressions: Vec<Expression>,
9841}
9842
9843/// Apply
9844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9845#[cfg_attr(feature = "bindings", derive(TS))]
9846pub struct Apply {
9847    pub this: Box<Expression>,
9848    pub expression: Box<Expression>,
9849}
9850
9851/// ToBoolean
9852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9853#[cfg_attr(feature = "bindings", derive(TS))]
9854pub struct ToBoolean {
9855    pub this: Box<Expression>,
9856    #[serde(default)]
9857    pub safe: Option<Box<Expression>>,
9858}
9859
9860/// List
9861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9862#[cfg_attr(feature = "bindings", derive(TS))]
9863pub struct List {
9864    #[serde(default)]
9865    pub expressions: Vec<Expression>,
9866}
9867
9868/// ToMap - Materialize-style map constructor
9869/// Can hold either:
9870/// - A SELECT subquery (MAP(SELECT 'a', 1))
9871/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
9872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9873#[cfg_attr(feature = "bindings", derive(TS))]
9874pub struct ToMap {
9875    /// Either a Select subquery or a Struct containing PropertyEQ entries
9876    pub this: Box<Expression>,
9877}
9878
9879/// Pad
9880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9881#[cfg_attr(feature = "bindings", derive(TS))]
9882pub struct Pad {
9883    pub this: Box<Expression>,
9884    pub expression: Box<Expression>,
9885    #[serde(default)]
9886    pub fill_pattern: Option<Box<Expression>>,
9887    #[serde(default)]
9888    pub is_left: Option<Box<Expression>>,
9889}
9890
9891/// ToChar
9892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9893#[cfg_attr(feature = "bindings", derive(TS))]
9894pub struct ToChar {
9895    pub this: Box<Expression>,
9896    #[serde(default)]
9897    pub format: Option<String>,
9898    #[serde(default)]
9899    pub nlsparam: Option<Box<Expression>>,
9900    #[serde(default)]
9901    pub is_numeric: Option<Box<Expression>>,
9902}
9903
9904/// StringFunc - String type conversion function (BigQuery STRING)
9905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9906#[cfg_attr(feature = "bindings", derive(TS))]
9907pub struct StringFunc {
9908    pub this: Box<Expression>,
9909    #[serde(default)]
9910    pub zone: Option<Box<Expression>>,
9911}
9912
9913/// ToNumber
9914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9915#[cfg_attr(feature = "bindings", derive(TS))]
9916pub struct ToNumber {
9917    pub this: Box<Expression>,
9918    #[serde(default)]
9919    pub format: Option<Box<Expression>>,
9920    #[serde(default)]
9921    pub nlsparam: Option<Box<Expression>>,
9922    #[serde(default)]
9923    pub precision: Option<Box<Expression>>,
9924    #[serde(default)]
9925    pub scale: Option<Box<Expression>>,
9926    #[serde(default)]
9927    pub safe: Option<Box<Expression>>,
9928    #[serde(default)]
9929    pub safe_name: Option<Box<Expression>>,
9930}
9931
9932/// ToDouble
9933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9934#[cfg_attr(feature = "bindings", derive(TS))]
9935pub struct ToDouble {
9936    pub this: Box<Expression>,
9937    #[serde(default)]
9938    pub format: Option<String>,
9939    #[serde(default)]
9940    pub safe: Option<Box<Expression>>,
9941}
9942
9943/// ToDecfloat
9944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9945#[cfg_attr(feature = "bindings", derive(TS))]
9946pub struct ToDecfloat {
9947    pub this: Box<Expression>,
9948    #[serde(default)]
9949    pub format: Option<String>,
9950}
9951
9952/// TryToDecfloat
9953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9954#[cfg_attr(feature = "bindings", derive(TS))]
9955pub struct TryToDecfloat {
9956    pub this: Box<Expression>,
9957    #[serde(default)]
9958    pub format: Option<String>,
9959}
9960
9961/// ToFile
9962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9963#[cfg_attr(feature = "bindings", derive(TS))]
9964pub struct ToFile {
9965    pub this: Box<Expression>,
9966    #[serde(default)]
9967    pub path: Option<Box<Expression>>,
9968    #[serde(default)]
9969    pub safe: Option<Box<Expression>>,
9970}
9971
9972/// Columns
9973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9974#[cfg_attr(feature = "bindings", derive(TS))]
9975pub struct Columns {
9976    pub this: Box<Expression>,
9977    #[serde(default)]
9978    pub unpack: Option<Box<Expression>>,
9979}
9980
9981/// ConvertToCharset
9982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9983#[cfg_attr(feature = "bindings", derive(TS))]
9984pub struct ConvertToCharset {
9985    pub this: Box<Expression>,
9986    #[serde(default)]
9987    pub dest: Option<Box<Expression>>,
9988    #[serde(default)]
9989    pub source: Option<Box<Expression>>,
9990}
9991
9992/// ConvertTimezone
9993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9994#[cfg_attr(feature = "bindings", derive(TS))]
9995pub struct ConvertTimezone {
9996    #[serde(default)]
9997    pub source_tz: Option<Box<Expression>>,
9998    #[serde(default)]
9999    pub target_tz: Option<Box<Expression>>,
10000    #[serde(default)]
10001    pub timestamp: Option<Box<Expression>>,
10002    #[serde(default)]
10003    pub options: Vec<Expression>,
10004}
10005
10006/// GenerateSeries
10007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10008#[cfg_attr(feature = "bindings", derive(TS))]
10009pub struct GenerateSeries {
10010    #[serde(default)]
10011    pub start: Option<Box<Expression>>,
10012    #[serde(default)]
10013    pub end: Option<Box<Expression>>,
10014    #[serde(default)]
10015    pub step: Option<Box<Expression>>,
10016    #[serde(default)]
10017    pub is_end_exclusive: Option<Box<Expression>>,
10018}
10019
10020/// AIAgg
10021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10022#[cfg_attr(feature = "bindings", derive(TS))]
10023pub struct AIAgg {
10024    pub this: Box<Expression>,
10025    pub expression: Box<Expression>,
10026}
10027
10028/// AIClassify
10029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10030#[cfg_attr(feature = "bindings", derive(TS))]
10031pub struct AIClassify {
10032    pub this: Box<Expression>,
10033    #[serde(default)]
10034    pub categories: Option<Box<Expression>>,
10035    #[serde(default)]
10036    pub config: Option<Box<Expression>>,
10037}
10038
10039/// ArrayAll
10040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10041#[cfg_attr(feature = "bindings", derive(TS))]
10042pub struct ArrayAll {
10043    pub this: Box<Expression>,
10044    pub expression: Box<Expression>,
10045}
10046
10047/// ArrayAny
10048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10049#[cfg_attr(feature = "bindings", derive(TS))]
10050pub struct ArrayAny {
10051    pub this: Box<Expression>,
10052    pub expression: Box<Expression>,
10053}
10054
10055/// ArrayConstructCompact
10056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10057#[cfg_attr(feature = "bindings", derive(TS))]
10058pub struct ArrayConstructCompact {
10059    #[serde(default)]
10060    pub expressions: Vec<Expression>,
10061}
10062
10063/// StPoint
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct StPoint {
10067    pub this: Box<Expression>,
10068    pub expression: Box<Expression>,
10069    #[serde(default)]
10070    pub null: Option<Box<Expression>>,
10071}
10072
10073/// StDistance
10074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10075#[cfg_attr(feature = "bindings", derive(TS))]
10076pub struct StDistance {
10077    pub this: Box<Expression>,
10078    pub expression: Box<Expression>,
10079    #[serde(default)]
10080    pub use_spheroid: Option<Box<Expression>>,
10081}
10082
10083/// StringToArray
10084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10085#[cfg_attr(feature = "bindings", derive(TS))]
10086pub struct StringToArray {
10087    pub this: Box<Expression>,
10088    #[serde(default)]
10089    pub expression: Option<Box<Expression>>,
10090    #[serde(default)]
10091    pub null: Option<Box<Expression>>,
10092}
10093
10094/// ArraySum
10095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10096#[cfg_attr(feature = "bindings", derive(TS))]
10097pub struct ArraySum {
10098    pub this: Box<Expression>,
10099    #[serde(default)]
10100    pub expression: Option<Box<Expression>>,
10101}
10102
10103/// ObjectAgg
10104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10105#[cfg_attr(feature = "bindings", derive(TS))]
10106pub struct ObjectAgg {
10107    pub this: Box<Expression>,
10108    pub expression: Box<Expression>,
10109}
10110
10111/// CastToStrType
10112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10113#[cfg_attr(feature = "bindings", derive(TS))]
10114pub struct CastToStrType {
10115    pub this: Box<Expression>,
10116    #[serde(default)]
10117    pub to: Option<Box<Expression>>,
10118}
10119
10120/// CheckJson
10121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10122#[cfg_attr(feature = "bindings", derive(TS))]
10123pub struct CheckJson {
10124    pub this: Box<Expression>,
10125}
10126
10127/// CheckXml
10128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10129#[cfg_attr(feature = "bindings", derive(TS))]
10130pub struct CheckXml {
10131    pub this: Box<Expression>,
10132    #[serde(default)]
10133    pub disable_auto_convert: Option<Box<Expression>>,
10134}
10135
10136/// TranslateCharacters
10137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10138#[cfg_attr(feature = "bindings", derive(TS))]
10139pub struct TranslateCharacters {
10140    pub this: Box<Expression>,
10141    pub expression: Box<Expression>,
10142    #[serde(default)]
10143    pub with_error: Option<Box<Expression>>,
10144}
10145
10146/// CurrentSchemas
10147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10148#[cfg_attr(feature = "bindings", derive(TS))]
10149pub struct CurrentSchemas {
10150    #[serde(default)]
10151    pub this: Option<Box<Expression>>,
10152}
10153
10154/// CurrentDatetime
10155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10156#[cfg_attr(feature = "bindings", derive(TS))]
10157pub struct CurrentDatetime {
10158    #[serde(default)]
10159    pub this: Option<Box<Expression>>,
10160}
10161
10162/// Localtime
10163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10164#[cfg_attr(feature = "bindings", derive(TS))]
10165pub struct Localtime {
10166    #[serde(default)]
10167    pub this: Option<Box<Expression>>,
10168}
10169
10170/// Localtimestamp
10171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10172#[cfg_attr(feature = "bindings", derive(TS))]
10173pub struct Localtimestamp {
10174    #[serde(default)]
10175    pub this: Option<Box<Expression>>,
10176}
10177
10178/// Systimestamp
10179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10180#[cfg_attr(feature = "bindings", derive(TS))]
10181pub struct Systimestamp {
10182    #[serde(default)]
10183    pub this: Option<Box<Expression>>,
10184}
10185
10186/// CurrentSchema
10187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10188#[cfg_attr(feature = "bindings", derive(TS))]
10189pub struct CurrentSchema {
10190    #[serde(default)]
10191    pub this: Option<Box<Expression>>,
10192}
10193
10194/// CurrentUser
10195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10196#[cfg_attr(feature = "bindings", derive(TS))]
10197pub struct CurrentUser {
10198    #[serde(default)]
10199    pub this: Option<Box<Expression>>,
10200}
10201
10202/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10204#[cfg_attr(feature = "bindings", derive(TS))]
10205pub struct SessionUser;
10206
10207/// JSONPathRoot - Represents $ in JSON path expressions
10208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10209#[cfg_attr(feature = "bindings", derive(TS))]
10210pub struct JSONPathRoot;
10211
10212/// UtcTime
10213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10214#[cfg_attr(feature = "bindings", derive(TS))]
10215pub struct UtcTime {
10216    #[serde(default)]
10217    pub this: Option<Box<Expression>>,
10218}
10219
10220/// UtcTimestamp
10221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10222#[cfg_attr(feature = "bindings", derive(TS))]
10223pub struct UtcTimestamp {
10224    #[serde(default)]
10225    pub this: Option<Box<Expression>>,
10226}
10227
10228/// TimestampFunc - TIMESTAMP constructor function
10229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10230#[cfg_attr(feature = "bindings", derive(TS))]
10231pub struct TimestampFunc {
10232    #[serde(default)]
10233    pub this: Option<Box<Expression>>,
10234    #[serde(default)]
10235    pub zone: Option<Box<Expression>>,
10236    #[serde(default)]
10237    pub with_tz: Option<bool>,
10238    #[serde(default)]
10239    pub safe: Option<bool>,
10240}
10241
10242/// DateBin
10243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10244#[cfg_attr(feature = "bindings", derive(TS))]
10245pub struct DateBin {
10246    pub this: Box<Expression>,
10247    pub expression: Box<Expression>,
10248    #[serde(default)]
10249    pub unit: Option<String>,
10250    #[serde(default)]
10251    pub zone: Option<Box<Expression>>,
10252    #[serde(default)]
10253    pub origin: Option<Box<Expression>>,
10254}
10255
10256/// Datetime
10257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10258#[cfg_attr(feature = "bindings", derive(TS))]
10259pub struct Datetime {
10260    pub this: Box<Expression>,
10261    #[serde(default)]
10262    pub expression: Option<Box<Expression>>,
10263}
10264
10265/// DatetimeAdd
10266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10267#[cfg_attr(feature = "bindings", derive(TS))]
10268pub struct DatetimeAdd {
10269    pub this: Box<Expression>,
10270    pub expression: Box<Expression>,
10271    #[serde(default)]
10272    pub unit: Option<String>,
10273}
10274
10275/// DatetimeSub
10276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10277#[cfg_attr(feature = "bindings", derive(TS))]
10278pub struct DatetimeSub {
10279    pub this: Box<Expression>,
10280    pub expression: Box<Expression>,
10281    #[serde(default)]
10282    pub unit: Option<String>,
10283}
10284
10285/// DatetimeDiff
10286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10287#[cfg_attr(feature = "bindings", derive(TS))]
10288pub struct DatetimeDiff {
10289    pub this: Box<Expression>,
10290    pub expression: Box<Expression>,
10291    #[serde(default)]
10292    pub unit: Option<String>,
10293}
10294
10295/// DatetimeTrunc
10296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10297#[cfg_attr(feature = "bindings", derive(TS))]
10298pub struct DatetimeTrunc {
10299    pub this: Box<Expression>,
10300    pub unit: String,
10301    #[serde(default)]
10302    pub zone: Option<Box<Expression>>,
10303}
10304
10305/// Dayname
10306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10307#[cfg_attr(feature = "bindings", derive(TS))]
10308pub struct Dayname {
10309    pub this: Box<Expression>,
10310    #[serde(default)]
10311    pub abbreviated: Option<Box<Expression>>,
10312}
10313
10314/// MakeInterval
10315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10316#[cfg_attr(feature = "bindings", derive(TS))]
10317pub struct MakeInterval {
10318    #[serde(default)]
10319    pub year: Option<Box<Expression>>,
10320    #[serde(default)]
10321    pub month: Option<Box<Expression>>,
10322    #[serde(default)]
10323    pub week: Option<Box<Expression>>,
10324    #[serde(default)]
10325    pub day: Option<Box<Expression>>,
10326    #[serde(default)]
10327    pub hour: Option<Box<Expression>>,
10328    #[serde(default)]
10329    pub minute: Option<Box<Expression>>,
10330    #[serde(default)]
10331    pub second: Option<Box<Expression>>,
10332}
10333
10334/// PreviousDay
10335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10336#[cfg_attr(feature = "bindings", derive(TS))]
10337pub struct PreviousDay {
10338    pub this: Box<Expression>,
10339    pub expression: Box<Expression>,
10340}
10341
10342/// Elt
10343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10344#[cfg_attr(feature = "bindings", derive(TS))]
10345pub struct Elt {
10346    pub this: Box<Expression>,
10347    #[serde(default)]
10348    pub expressions: Vec<Expression>,
10349}
10350
10351/// TimestampAdd
10352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10353#[cfg_attr(feature = "bindings", derive(TS))]
10354pub struct TimestampAdd {
10355    pub this: Box<Expression>,
10356    pub expression: Box<Expression>,
10357    #[serde(default)]
10358    pub unit: Option<String>,
10359}
10360
10361/// TimestampSub
10362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10363#[cfg_attr(feature = "bindings", derive(TS))]
10364pub struct TimestampSub {
10365    pub this: Box<Expression>,
10366    pub expression: Box<Expression>,
10367    #[serde(default)]
10368    pub unit: Option<String>,
10369}
10370
10371/// TimestampDiff
10372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10373#[cfg_attr(feature = "bindings", derive(TS))]
10374pub struct TimestampDiff {
10375    pub this: Box<Expression>,
10376    pub expression: Box<Expression>,
10377    #[serde(default)]
10378    pub unit: Option<String>,
10379}
10380
10381/// TimeSlice
10382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10383#[cfg_attr(feature = "bindings", derive(TS))]
10384pub struct TimeSlice {
10385    pub this: Box<Expression>,
10386    pub expression: Box<Expression>,
10387    pub unit: String,
10388    #[serde(default)]
10389    pub kind: Option<String>,
10390}
10391
10392/// TimeAdd
10393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10394#[cfg_attr(feature = "bindings", derive(TS))]
10395pub struct TimeAdd {
10396    pub this: Box<Expression>,
10397    pub expression: Box<Expression>,
10398    #[serde(default)]
10399    pub unit: Option<String>,
10400}
10401
10402/// TimeSub
10403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10404#[cfg_attr(feature = "bindings", derive(TS))]
10405pub struct TimeSub {
10406    pub this: Box<Expression>,
10407    pub expression: Box<Expression>,
10408    #[serde(default)]
10409    pub unit: Option<String>,
10410}
10411
10412/// TimeDiff
10413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10414#[cfg_attr(feature = "bindings", derive(TS))]
10415pub struct TimeDiff {
10416    pub this: Box<Expression>,
10417    pub expression: Box<Expression>,
10418    #[serde(default)]
10419    pub unit: Option<String>,
10420}
10421
10422/// TimeTrunc
10423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10424#[cfg_attr(feature = "bindings", derive(TS))]
10425pub struct TimeTrunc {
10426    pub this: Box<Expression>,
10427    pub unit: String,
10428    #[serde(default)]
10429    pub zone: Option<Box<Expression>>,
10430}
10431
10432/// DateFromParts
10433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10434#[cfg_attr(feature = "bindings", derive(TS))]
10435pub struct DateFromParts {
10436    #[serde(default)]
10437    pub year: Option<Box<Expression>>,
10438    #[serde(default)]
10439    pub month: Option<Box<Expression>>,
10440    #[serde(default)]
10441    pub day: Option<Box<Expression>>,
10442    #[serde(default)]
10443    pub allow_overflow: Option<Box<Expression>>,
10444}
10445
10446/// TimeFromParts
10447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10448#[cfg_attr(feature = "bindings", derive(TS))]
10449pub struct TimeFromParts {
10450    #[serde(default)]
10451    pub hour: Option<Box<Expression>>,
10452    #[serde(default)]
10453    pub min: Option<Box<Expression>>,
10454    #[serde(default)]
10455    pub sec: Option<Box<Expression>>,
10456    #[serde(default)]
10457    pub nano: Option<Box<Expression>>,
10458    #[serde(default)]
10459    pub fractions: Option<Box<Expression>>,
10460    #[serde(default)]
10461    pub precision: Option<i64>,
10462}
10463
10464/// DecodeCase
10465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10466#[cfg_attr(feature = "bindings", derive(TS))]
10467pub struct DecodeCase {
10468    #[serde(default)]
10469    pub expressions: Vec<Expression>,
10470}
10471
10472/// Decrypt
10473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10474#[cfg_attr(feature = "bindings", derive(TS))]
10475pub struct Decrypt {
10476    pub this: Box<Expression>,
10477    #[serde(default)]
10478    pub passphrase: Option<Box<Expression>>,
10479    #[serde(default)]
10480    pub aad: Option<Box<Expression>>,
10481    #[serde(default)]
10482    pub encryption_method: Option<Box<Expression>>,
10483    #[serde(default)]
10484    pub safe: Option<Box<Expression>>,
10485}
10486
10487/// DecryptRaw
10488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10489#[cfg_attr(feature = "bindings", derive(TS))]
10490pub struct DecryptRaw {
10491    pub this: Box<Expression>,
10492    #[serde(default)]
10493    pub key: Option<Box<Expression>>,
10494    #[serde(default)]
10495    pub iv: Option<Box<Expression>>,
10496    #[serde(default)]
10497    pub aad: Option<Box<Expression>>,
10498    #[serde(default)]
10499    pub encryption_method: Option<Box<Expression>>,
10500    #[serde(default)]
10501    pub aead: Option<Box<Expression>>,
10502    #[serde(default)]
10503    pub safe: Option<Box<Expression>>,
10504}
10505
10506/// Encode
10507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10508#[cfg_attr(feature = "bindings", derive(TS))]
10509pub struct Encode {
10510    pub this: Box<Expression>,
10511    #[serde(default)]
10512    pub charset: Option<Box<Expression>>,
10513}
10514
10515/// Encrypt
10516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10517#[cfg_attr(feature = "bindings", derive(TS))]
10518pub struct Encrypt {
10519    pub this: Box<Expression>,
10520    #[serde(default)]
10521    pub passphrase: Option<Box<Expression>>,
10522    #[serde(default)]
10523    pub aad: Option<Box<Expression>>,
10524    #[serde(default)]
10525    pub encryption_method: Option<Box<Expression>>,
10526}
10527
10528/// EncryptRaw
10529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10530#[cfg_attr(feature = "bindings", derive(TS))]
10531pub struct EncryptRaw {
10532    pub this: Box<Expression>,
10533    #[serde(default)]
10534    pub key: Option<Box<Expression>>,
10535    #[serde(default)]
10536    pub iv: Option<Box<Expression>>,
10537    #[serde(default)]
10538    pub aad: Option<Box<Expression>>,
10539    #[serde(default)]
10540    pub encryption_method: Option<Box<Expression>>,
10541}
10542
10543/// EqualNull
10544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10545#[cfg_attr(feature = "bindings", derive(TS))]
10546pub struct EqualNull {
10547    pub this: Box<Expression>,
10548    pub expression: Box<Expression>,
10549}
10550
10551/// ToBinary
10552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10553#[cfg_attr(feature = "bindings", derive(TS))]
10554pub struct ToBinary {
10555    pub this: Box<Expression>,
10556    #[serde(default)]
10557    pub format: Option<String>,
10558    #[serde(default)]
10559    pub safe: Option<Box<Expression>>,
10560}
10561
10562/// Base64DecodeBinary
10563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10564#[cfg_attr(feature = "bindings", derive(TS))]
10565pub struct Base64DecodeBinary {
10566    pub this: Box<Expression>,
10567    #[serde(default)]
10568    pub alphabet: Option<Box<Expression>>,
10569}
10570
10571/// Base64DecodeString
10572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10573#[cfg_attr(feature = "bindings", derive(TS))]
10574pub struct Base64DecodeString {
10575    pub this: Box<Expression>,
10576    #[serde(default)]
10577    pub alphabet: Option<Box<Expression>>,
10578}
10579
10580/// Base64Encode
10581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10582#[cfg_attr(feature = "bindings", derive(TS))]
10583pub struct Base64Encode {
10584    pub this: Box<Expression>,
10585    #[serde(default)]
10586    pub max_line_length: Option<Box<Expression>>,
10587    #[serde(default)]
10588    pub alphabet: Option<Box<Expression>>,
10589}
10590
10591/// TryBase64DecodeBinary
10592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10593#[cfg_attr(feature = "bindings", derive(TS))]
10594pub struct TryBase64DecodeBinary {
10595    pub this: Box<Expression>,
10596    #[serde(default)]
10597    pub alphabet: Option<Box<Expression>>,
10598}
10599
10600/// TryBase64DecodeString
10601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10602#[cfg_attr(feature = "bindings", derive(TS))]
10603pub struct TryBase64DecodeString {
10604    pub this: Box<Expression>,
10605    #[serde(default)]
10606    pub alphabet: Option<Box<Expression>>,
10607}
10608
10609/// GapFill
10610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10611#[cfg_attr(feature = "bindings", derive(TS))]
10612pub struct GapFill {
10613    pub this: Box<Expression>,
10614    #[serde(default)]
10615    pub ts_column: Option<Box<Expression>>,
10616    #[serde(default)]
10617    pub bucket_width: Option<Box<Expression>>,
10618    #[serde(default)]
10619    pub partitioning_columns: Option<Box<Expression>>,
10620    #[serde(default)]
10621    pub value_columns: Option<Box<Expression>>,
10622    #[serde(default)]
10623    pub origin: Option<Box<Expression>>,
10624    #[serde(default)]
10625    pub ignore_nulls: Option<Box<Expression>>,
10626}
10627
10628/// GenerateDateArray
10629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10630#[cfg_attr(feature = "bindings", derive(TS))]
10631pub struct GenerateDateArray {
10632    #[serde(default)]
10633    pub start: Option<Box<Expression>>,
10634    #[serde(default)]
10635    pub end: Option<Box<Expression>>,
10636    #[serde(default)]
10637    pub step: Option<Box<Expression>>,
10638}
10639
10640/// GenerateTimestampArray
10641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10642#[cfg_attr(feature = "bindings", derive(TS))]
10643pub struct GenerateTimestampArray {
10644    #[serde(default)]
10645    pub start: Option<Box<Expression>>,
10646    #[serde(default)]
10647    pub end: Option<Box<Expression>>,
10648    #[serde(default)]
10649    pub step: Option<Box<Expression>>,
10650}
10651
10652/// GetExtract
10653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10654#[cfg_attr(feature = "bindings", derive(TS))]
10655pub struct GetExtract {
10656    pub this: Box<Expression>,
10657    pub expression: Box<Expression>,
10658}
10659
10660/// Getbit
10661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10662#[cfg_attr(feature = "bindings", derive(TS))]
10663pub struct Getbit {
10664    pub this: Box<Expression>,
10665    pub expression: Box<Expression>,
10666    #[serde(default)]
10667    pub zero_is_msb: Option<Box<Expression>>,
10668}
10669
10670/// OverflowTruncateBehavior
10671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10672#[cfg_attr(feature = "bindings", derive(TS))]
10673pub struct OverflowTruncateBehavior {
10674    #[serde(default)]
10675    pub this: Option<Box<Expression>>,
10676    #[serde(default)]
10677    pub with_count: Option<Box<Expression>>,
10678}
10679
10680/// HexEncode
10681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10682#[cfg_attr(feature = "bindings", derive(TS))]
10683pub struct HexEncode {
10684    pub this: Box<Expression>,
10685    #[serde(default)]
10686    pub case: Option<Box<Expression>>,
10687}
10688
10689/// Compress
10690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10691#[cfg_attr(feature = "bindings", derive(TS))]
10692pub struct Compress {
10693    pub this: Box<Expression>,
10694    #[serde(default)]
10695    pub method: Option<String>,
10696}
10697
10698/// DecompressBinary
10699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10700#[cfg_attr(feature = "bindings", derive(TS))]
10701pub struct DecompressBinary {
10702    pub this: Box<Expression>,
10703    pub method: String,
10704}
10705
10706/// DecompressString
10707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10708#[cfg_attr(feature = "bindings", derive(TS))]
10709pub struct DecompressString {
10710    pub this: Box<Expression>,
10711    pub method: String,
10712}
10713
10714/// Xor
10715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10716#[cfg_attr(feature = "bindings", derive(TS))]
10717pub struct Xor {
10718    #[serde(default)]
10719    pub this: Option<Box<Expression>>,
10720    #[serde(default)]
10721    pub expression: Option<Box<Expression>>,
10722    #[serde(default)]
10723    pub expressions: Vec<Expression>,
10724}
10725
10726/// Nullif
10727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10728#[cfg_attr(feature = "bindings", derive(TS))]
10729pub struct Nullif {
10730    pub this: Box<Expression>,
10731    pub expression: Box<Expression>,
10732}
10733
10734/// JSON
10735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10736#[cfg_attr(feature = "bindings", derive(TS))]
10737pub struct JSON {
10738    #[serde(default)]
10739    pub this: Option<Box<Expression>>,
10740    #[serde(default)]
10741    pub with_: Option<Box<Expression>>,
10742    #[serde(default)]
10743    pub unique: bool,
10744}
10745
10746/// JSONPath
10747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10748#[cfg_attr(feature = "bindings", derive(TS))]
10749pub struct JSONPath {
10750    #[serde(default)]
10751    pub expressions: Vec<Expression>,
10752    #[serde(default)]
10753    pub escape: Option<Box<Expression>>,
10754}
10755
10756/// JSONPathFilter
10757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10758#[cfg_attr(feature = "bindings", derive(TS))]
10759pub struct JSONPathFilter {
10760    pub this: Box<Expression>,
10761}
10762
10763/// JSONPathKey
10764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10765#[cfg_attr(feature = "bindings", derive(TS))]
10766pub struct JSONPathKey {
10767    pub this: Box<Expression>,
10768}
10769
10770/// JSONPathRecursive
10771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10772#[cfg_attr(feature = "bindings", derive(TS))]
10773pub struct JSONPathRecursive {
10774    #[serde(default)]
10775    pub this: Option<Box<Expression>>,
10776}
10777
10778/// JSONPathScript
10779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10780#[cfg_attr(feature = "bindings", derive(TS))]
10781pub struct JSONPathScript {
10782    pub this: Box<Expression>,
10783}
10784
10785/// JSONPathSlice
10786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10787#[cfg_attr(feature = "bindings", derive(TS))]
10788pub struct JSONPathSlice {
10789    #[serde(default)]
10790    pub start: Option<Box<Expression>>,
10791    #[serde(default)]
10792    pub end: Option<Box<Expression>>,
10793    #[serde(default)]
10794    pub step: Option<Box<Expression>>,
10795}
10796
10797/// JSONPathSelector
10798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10799#[cfg_attr(feature = "bindings", derive(TS))]
10800pub struct JSONPathSelector {
10801    pub this: Box<Expression>,
10802}
10803
10804/// JSONPathSubscript
10805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10806#[cfg_attr(feature = "bindings", derive(TS))]
10807pub struct JSONPathSubscript {
10808    pub this: Box<Expression>,
10809}
10810
10811/// JSONPathUnion
10812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10813#[cfg_attr(feature = "bindings", derive(TS))]
10814pub struct JSONPathUnion {
10815    #[serde(default)]
10816    pub expressions: Vec<Expression>,
10817}
10818
10819/// Format
10820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10821#[cfg_attr(feature = "bindings", derive(TS))]
10822pub struct Format {
10823    pub this: Box<Expression>,
10824    #[serde(default)]
10825    pub expressions: Vec<Expression>,
10826}
10827
10828/// JSONKeys
10829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10830#[cfg_attr(feature = "bindings", derive(TS))]
10831pub struct JSONKeys {
10832    pub this: Box<Expression>,
10833    #[serde(default)]
10834    pub expression: Option<Box<Expression>>,
10835    #[serde(default)]
10836    pub expressions: Vec<Expression>,
10837}
10838
10839/// JSONKeyValue
10840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10841#[cfg_attr(feature = "bindings", derive(TS))]
10842pub struct JSONKeyValue {
10843    pub this: Box<Expression>,
10844    pub expression: Box<Expression>,
10845}
10846
10847/// JSONKeysAtDepth
10848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10849#[cfg_attr(feature = "bindings", derive(TS))]
10850pub struct JSONKeysAtDepth {
10851    pub this: Box<Expression>,
10852    #[serde(default)]
10853    pub expression: Option<Box<Expression>>,
10854    #[serde(default)]
10855    pub mode: Option<Box<Expression>>,
10856}
10857
10858/// JSONObject
10859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10860#[cfg_attr(feature = "bindings", derive(TS))]
10861pub struct JSONObject {
10862    #[serde(default)]
10863    pub expressions: Vec<Expression>,
10864    #[serde(default)]
10865    pub null_handling: Option<Box<Expression>>,
10866    #[serde(default)]
10867    pub unique_keys: Option<Box<Expression>>,
10868    #[serde(default)]
10869    pub return_type: Option<Box<Expression>>,
10870    #[serde(default)]
10871    pub encoding: Option<Box<Expression>>,
10872}
10873
10874/// JSONObjectAgg
10875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10876#[cfg_attr(feature = "bindings", derive(TS))]
10877pub struct JSONObjectAgg {
10878    #[serde(default)]
10879    pub expressions: Vec<Expression>,
10880    #[serde(default)]
10881    pub null_handling: Option<Box<Expression>>,
10882    #[serde(default)]
10883    pub unique_keys: Option<Box<Expression>>,
10884    #[serde(default)]
10885    pub return_type: Option<Box<Expression>>,
10886    #[serde(default)]
10887    pub encoding: Option<Box<Expression>>,
10888}
10889
10890/// JSONBObjectAgg
10891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10892#[cfg_attr(feature = "bindings", derive(TS))]
10893pub struct JSONBObjectAgg {
10894    pub this: Box<Expression>,
10895    pub expression: Box<Expression>,
10896}
10897
10898/// JSONArray
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct JSONArray {
10902    #[serde(default)]
10903    pub expressions: Vec<Expression>,
10904    #[serde(default)]
10905    pub null_handling: Option<Box<Expression>>,
10906    #[serde(default)]
10907    pub return_type: Option<Box<Expression>>,
10908    #[serde(default)]
10909    pub strict: Option<Box<Expression>>,
10910}
10911
10912/// JSONArrayAgg
10913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10914#[cfg_attr(feature = "bindings", derive(TS))]
10915pub struct JSONArrayAgg {
10916    pub this: Box<Expression>,
10917    #[serde(default)]
10918    pub order: Option<Box<Expression>>,
10919    #[serde(default)]
10920    pub null_handling: Option<Box<Expression>>,
10921    #[serde(default)]
10922    pub return_type: Option<Box<Expression>>,
10923    #[serde(default)]
10924    pub strict: Option<Box<Expression>>,
10925}
10926
10927/// JSONExists
10928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10929#[cfg_attr(feature = "bindings", derive(TS))]
10930pub struct JSONExists {
10931    pub this: Box<Expression>,
10932    #[serde(default)]
10933    pub path: Option<Box<Expression>>,
10934    #[serde(default)]
10935    pub passing: Option<Box<Expression>>,
10936    #[serde(default)]
10937    pub on_condition: Option<Box<Expression>>,
10938    #[serde(default)]
10939    pub from_dcolonqmark: Option<Box<Expression>>,
10940}
10941
10942/// JSONColumnDef
10943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10944#[cfg_attr(feature = "bindings", derive(TS))]
10945pub struct JSONColumnDef {
10946    #[serde(default)]
10947    pub this: Option<Box<Expression>>,
10948    #[serde(default)]
10949    pub kind: Option<String>,
10950    #[serde(default)]
10951    pub path: Option<Box<Expression>>,
10952    #[serde(default)]
10953    pub nested_schema: Option<Box<Expression>>,
10954    #[serde(default)]
10955    pub ordinality: Option<Box<Expression>>,
10956}
10957
10958/// JSONSchema
10959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10960#[cfg_attr(feature = "bindings", derive(TS))]
10961pub struct JSONSchema {
10962    #[serde(default)]
10963    pub expressions: Vec<Expression>,
10964}
10965
10966/// JSONSet
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct JSONSet {
10970    pub this: Box<Expression>,
10971    #[serde(default)]
10972    pub expressions: Vec<Expression>,
10973}
10974
10975/// JSONStripNulls
10976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10977#[cfg_attr(feature = "bindings", derive(TS))]
10978pub struct JSONStripNulls {
10979    pub this: Box<Expression>,
10980    #[serde(default)]
10981    pub expression: Option<Box<Expression>>,
10982    #[serde(default)]
10983    pub include_arrays: Option<Box<Expression>>,
10984    #[serde(default)]
10985    pub remove_empty: Option<Box<Expression>>,
10986}
10987
10988/// JSONValue
10989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10990#[cfg_attr(feature = "bindings", derive(TS))]
10991pub struct JSONValue {
10992    pub this: Box<Expression>,
10993    #[serde(default)]
10994    pub path: Option<Box<Expression>>,
10995    #[serde(default)]
10996    pub returning: Option<Box<Expression>>,
10997    #[serde(default)]
10998    pub on_condition: Option<Box<Expression>>,
10999}
11000
11001/// JSONValueArray
11002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11003#[cfg_attr(feature = "bindings", derive(TS))]
11004pub struct JSONValueArray {
11005    pub this: Box<Expression>,
11006    #[serde(default)]
11007    pub expression: Option<Box<Expression>>,
11008}
11009
11010/// JSONRemove
11011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11012#[cfg_attr(feature = "bindings", derive(TS))]
11013pub struct JSONRemove {
11014    pub this: Box<Expression>,
11015    #[serde(default)]
11016    pub expressions: Vec<Expression>,
11017}
11018
11019/// JSONTable
11020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11021#[cfg_attr(feature = "bindings", derive(TS))]
11022pub struct JSONTable {
11023    pub this: Box<Expression>,
11024    #[serde(default)]
11025    pub schema: Option<Box<Expression>>,
11026    #[serde(default)]
11027    pub path: Option<Box<Expression>>,
11028    #[serde(default)]
11029    pub error_handling: Option<Box<Expression>>,
11030    #[serde(default)]
11031    pub empty_handling: Option<Box<Expression>>,
11032}
11033
11034/// JSONType
11035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11036#[cfg_attr(feature = "bindings", derive(TS))]
11037pub struct JSONType {
11038    pub this: Box<Expression>,
11039    #[serde(default)]
11040    pub expression: Option<Box<Expression>>,
11041}
11042
11043/// ObjectInsert
11044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11045#[cfg_attr(feature = "bindings", derive(TS))]
11046pub struct ObjectInsert {
11047    pub this: Box<Expression>,
11048    #[serde(default)]
11049    pub key: Option<Box<Expression>>,
11050    #[serde(default)]
11051    pub value: Option<Box<Expression>>,
11052    #[serde(default)]
11053    pub update_flag: Option<Box<Expression>>,
11054}
11055
11056/// OpenJSONColumnDef
11057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11058#[cfg_attr(feature = "bindings", derive(TS))]
11059pub struct OpenJSONColumnDef {
11060    pub this: Box<Expression>,
11061    pub kind: String,
11062    #[serde(default)]
11063    pub path: Option<Box<Expression>>,
11064    #[serde(default)]
11065    pub as_json: Option<Box<Expression>>,
11066    /// The parsed data type for proper generation
11067    #[serde(default, skip_serializing_if = "Option::is_none")]
11068    pub data_type: Option<DataType>,
11069}
11070
11071/// OpenJSON
11072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11073#[cfg_attr(feature = "bindings", derive(TS))]
11074pub struct OpenJSON {
11075    pub this: Box<Expression>,
11076    #[serde(default)]
11077    pub path: Option<Box<Expression>>,
11078    #[serde(default)]
11079    pub expressions: Vec<Expression>,
11080}
11081
11082/// JSONBExists
11083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11084#[cfg_attr(feature = "bindings", derive(TS))]
11085pub struct JSONBExists {
11086    pub this: Box<Expression>,
11087    #[serde(default)]
11088    pub path: Option<Box<Expression>>,
11089}
11090
11091/// JSONCast
11092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11093#[cfg_attr(feature = "bindings", derive(TS))]
11094pub struct JSONCast {
11095    pub this: Box<Expression>,
11096    pub to: DataType,
11097}
11098
11099/// JSONExtract
11100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11101#[cfg_attr(feature = "bindings", derive(TS))]
11102pub struct JSONExtract {
11103    pub this: Box<Expression>,
11104    pub expression: Box<Expression>,
11105    #[serde(default)]
11106    pub only_json_types: Option<Box<Expression>>,
11107    #[serde(default)]
11108    pub expressions: Vec<Expression>,
11109    #[serde(default)]
11110    pub variant_extract: Option<Box<Expression>>,
11111    #[serde(default)]
11112    pub json_query: Option<Box<Expression>>,
11113    #[serde(default)]
11114    pub option: Option<Box<Expression>>,
11115    #[serde(default)]
11116    pub quote: Option<Box<Expression>>,
11117    #[serde(default)]
11118    pub on_condition: Option<Box<Expression>>,
11119    #[serde(default)]
11120    pub requires_json: Option<Box<Expression>>,
11121}
11122
11123/// JSONExtractQuote
11124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11125#[cfg_attr(feature = "bindings", derive(TS))]
11126pub struct JSONExtractQuote {
11127    #[serde(default)]
11128    pub option: Option<Box<Expression>>,
11129    #[serde(default)]
11130    pub scalar: Option<Box<Expression>>,
11131}
11132
11133/// JSONExtractArray
11134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11135#[cfg_attr(feature = "bindings", derive(TS))]
11136pub struct JSONExtractArray {
11137    pub this: Box<Expression>,
11138    #[serde(default)]
11139    pub expression: Option<Box<Expression>>,
11140}
11141
11142/// JSONExtractScalar
11143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11144#[cfg_attr(feature = "bindings", derive(TS))]
11145pub struct JSONExtractScalar {
11146    pub this: Box<Expression>,
11147    pub expression: Box<Expression>,
11148    #[serde(default)]
11149    pub only_json_types: Option<Box<Expression>>,
11150    #[serde(default)]
11151    pub expressions: Vec<Expression>,
11152    #[serde(default)]
11153    pub json_type: Option<Box<Expression>>,
11154    #[serde(default)]
11155    pub scalar_only: Option<Box<Expression>>,
11156}
11157
11158/// JSONBExtractScalar
11159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11160#[cfg_attr(feature = "bindings", derive(TS))]
11161pub struct JSONBExtractScalar {
11162    pub this: Box<Expression>,
11163    pub expression: Box<Expression>,
11164    #[serde(default)]
11165    pub json_type: Option<Box<Expression>>,
11166}
11167
11168/// JSONFormat
11169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11170#[cfg_attr(feature = "bindings", derive(TS))]
11171pub struct JSONFormat {
11172    #[serde(default)]
11173    pub this: Option<Box<Expression>>,
11174    #[serde(default)]
11175    pub options: Vec<Expression>,
11176    #[serde(default)]
11177    pub is_json: Option<Box<Expression>>,
11178    #[serde(default)]
11179    pub to_json: Option<Box<Expression>>,
11180}
11181
11182/// JSONArrayAppend
11183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11184#[cfg_attr(feature = "bindings", derive(TS))]
11185pub struct JSONArrayAppend {
11186    pub this: Box<Expression>,
11187    #[serde(default)]
11188    pub expressions: Vec<Expression>,
11189}
11190
11191/// JSONArrayContains
11192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11193#[cfg_attr(feature = "bindings", derive(TS))]
11194pub struct JSONArrayContains {
11195    pub this: Box<Expression>,
11196    pub expression: Box<Expression>,
11197    #[serde(default)]
11198    pub json_type: Option<Box<Expression>>,
11199}
11200
11201/// JSONArrayInsert
11202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11203#[cfg_attr(feature = "bindings", derive(TS))]
11204pub struct JSONArrayInsert {
11205    pub this: Box<Expression>,
11206    #[serde(default)]
11207    pub expressions: Vec<Expression>,
11208}
11209
11210/// ParseJSON
11211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11212#[cfg_attr(feature = "bindings", derive(TS))]
11213pub struct ParseJSON {
11214    pub this: Box<Expression>,
11215    #[serde(default)]
11216    pub expression: Option<Box<Expression>>,
11217    #[serde(default)]
11218    pub safe: Option<Box<Expression>>,
11219}
11220
11221/// ParseUrl
11222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11223#[cfg_attr(feature = "bindings", derive(TS))]
11224pub struct ParseUrl {
11225    pub this: Box<Expression>,
11226    #[serde(default)]
11227    pub part_to_extract: Option<Box<Expression>>,
11228    #[serde(default)]
11229    pub key: Option<Box<Expression>>,
11230    #[serde(default)]
11231    pub permissive: Option<Box<Expression>>,
11232}
11233
11234/// ParseIp
11235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11236#[cfg_attr(feature = "bindings", derive(TS))]
11237pub struct ParseIp {
11238    pub this: Box<Expression>,
11239    #[serde(default)]
11240    pub type_: Option<Box<Expression>>,
11241    #[serde(default)]
11242    pub permissive: Option<Box<Expression>>,
11243}
11244
11245/// ParseTime
11246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11247#[cfg_attr(feature = "bindings", derive(TS))]
11248pub struct ParseTime {
11249    pub this: Box<Expression>,
11250    pub format: String,
11251}
11252
11253/// ParseDatetime
11254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11255#[cfg_attr(feature = "bindings", derive(TS))]
11256pub struct ParseDatetime {
11257    pub this: Box<Expression>,
11258    #[serde(default)]
11259    pub format: Option<String>,
11260    #[serde(default)]
11261    pub zone: Option<Box<Expression>>,
11262}
11263
11264/// Map
11265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11266#[cfg_attr(feature = "bindings", derive(TS))]
11267pub struct Map {
11268    #[serde(default)]
11269    pub keys: Vec<Expression>,
11270    #[serde(default)]
11271    pub values: Vec<Expression>,
11272}
11273
11274/// MapCat
11275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11276#[cfg_attr(feature = "bindings", derive(TS))]
11277pub struct MapCat {
11278    pub this: Box<Expression>,
11279    pub expression: Box<Expression>,
11280}
11281
11282/// MapDelete
11283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11284#[cfg_attr(feature = "bindings", derive(TS))]
11285pub struct MapDelete {
11286    pub this: Box<Expression>,
11287    #[serde(default)]
11288    pub expressions: Vec<Expression>,
11289}
11290
11291/// MapInsert
11292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11293#[cfg_attr(feature = "bindings", derive(TS))]
11294pub struct MapInsert {
11295    pub this: Box<Expression>,
11296    #[serde(default)]
11297    pub key: Option<Box<Expression>>,
11298    #[serde(default)]
11299    pub value: Option<Box<Expression>>,
11300    #[serde(default)]
11301    pub update_flag: Option<Box<Expression>>,
11302}
11303
11304/// MapPick
11305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11306#[cfg_attr(feature = "bindings", derive(TS))]
11307pub struct MapPick {
11308    pub this: Box<Expression>,
11309    #[serde(default)]
11310    pub expressions: Vec<Expression>,
11311}
11312
11313/// ScopeResolution
11314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11315#[cfg_attr(feature = "bindings", derive(TS))]
11316pub struct ScopeResolution {
11317    #[serde(default)]
11318    pub this: Option<Box<Expression>>,
11319    pub expression: Box<Expression>,
11320}
11321
11322/// Slice
11323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11324#[cfg_attr(feature = "bindings", derive(TS))]
11325pub struct Slice {
11326    #[serde(default)]
11327    pub this: Option<Box<Expression>>,
11328    #[serde(default)]
11329    pub expression: Option<Box<Expression>>,
11330    #[serde(default)]
11331    pub step: Option<Box<Expression>>,
11332}
11333
11334/// VarMap
11335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11336#[cfg_attr(feature = "bindings", derive(TS))]
11337pub struct VarMap {
11338    #[serde(default)]
11339    pub keys: Vec<Expression>,
11340    #[serde(default)]
11341    pub values: Vec<Expression>,
11342}
11343
11344/// MatchAgainst
11345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11346#[cfg_attr(feature = "bindings", derive(TS))]
11347pub struct MatchAgainst {
11348    pub this: Box<Expression>,
11349    #[serde(default)]
11350    pub expressions: Vec<Expression>,
11351    #[serde(default)]
11352    pub modifier: Option<Box<Expression>>,
11353}
11354
11355/// MD5Digest
11356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11357#[cfg_attr(feature = "bindings", derive(TS))]
11358pub struct MD5Digest {
11359    pub this: Box<Expression>,
11360    #[serde(default)]
11361    pub expressions: Vec<Expression>,
11362}
11363
11364/// Monthname
11365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11366#[cfg_attr(feature = "bindings", derive(TS))]
11367pub struct Monthname {
11368    pub this: Box<Expression>,
11369    #[serde(default)]
11370    pub abbreviated: Option<Box<Expression>>,
11371}
11372
11373/// Ntile
11374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11375#[cfg_attr(feature = "bindings", derive(TS))]
11376pub struct Ntile {
11377    #[serde(default)]
11378    pub this: Option<Box<Expression>>,
11379}
11380
11381/// Normalize
11382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11383#[cfg_attr(feature = "bindings", derive(TS))]
11384pub struct Normalize {
11385    pub this: Box<Expression>,
11386    #[serde(default)]
11387    pub form: Option<Box<Expression>>,
11388    #[serde(default)]
11389    pub is_casefold: Option<Box<Expression>>,
11390}
11391
11392/// Normal
11393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11394#[cfg_attr(feature = "bindings", derive(TS))]
11395pub struct Normal {
11396    pub this: Box<Expression>,
11397    #[serde(default)]
11398    pub stddev: Option<Box<Expression>>,
11399    #[serde(default)]
11400    pub gen: Option<Box<Expression>>,
11401}
11402
11403/// Predict
11404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11405#[cfg_attr(feature = "bindings", derive(TS))]
11406pub struct Predict {
11407    pub this: Box<Expression>,
11408    pub expression: Box<Expression>,
11409    #[serde(default)]
11410    pub params_struct: Option<Box<Expression>>,
11411}
11412
11413/// MLTranslate
11414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11415#[cfg_attr(feature = "bindings", derive(TS))]
11416pub struct MLTranslate {
11417    pub this: Box<Expression>,
11418    pub expression: Box<Expression>,
11419    #[serde(default)]
11420    pub params_struct: Option<Box<Expression>>,
11421}
11422
11423/// FeaturesAtTime
11424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11425#[cfg_attr(feature = "bindings", derive(TS))]
11426pub struct FeaturesAtTime {
11427    pub this: Box<Expression>,
11428    #[serde(default)]
11429    pub time: Option<Box<Expression>>,
11430    #[serde(default)]
11431    pub num_rows: Option<Box<Expression>>,
11432    #[serde(default)]
11433    pub ignore_feature_nulls: Option<Box<Expression>>,
11434}
11435
11436/// GenerateEmbedding
11437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11438#[cfg_attr(feature = "bindings", derive(TS))]
11439pub struct GenerateEmbedding {
11440    pub this: Box<Expression>,
11441    pub expression: Box<Expression>,
11442    #[serde(default)]
11443    pub params_struct: Option<Box<Expression>>,
11444    #[serde(default)]
11445    pub is_text: Option<Box<Expression>>,
11446}
11447
11448/// MLForecast
11449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11450#[cfg_attr(feature = "bindings", derive(TS))]
11451pub struct MLForecast {
11452    pub this: Box<Expression>,
11453    #[serde(default)]
11454    pub expression: Option<Box<Expression>>,
11455    #[serde(default)]
11456    pub params_struct: Option<Box<Expression>>,
11457}
11458
11459/// ModelAttribute
11460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11461#[cfg_attr(feature = "bindings", derive(TS))]
11462pub struct ModelAttribute {
11463    pub this: Box<Expression>,
11464    pub expression: Box<Expression>,
11465}
11466
11467/// VectorSearch
11468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11469#[cfg_attr(feature = "bindings", derive(TS))]
11470pub struct VectorSearch {
11471    pub this: Box<Expression>,
11472    #[serde(default)]
11473    pub column_to_search: Option<Box<Expression>>,
11474    #[serde(default)]
11475    pub query_table: Option<Box<Expression>>,
11476    #[serde(default)]
11477    pub query_column_to_search: Option<Box<Expression>>,
11478    #[serde(default)]
11479    pub top_k: Option<Box<Expression>>,
11480    #[serde(default)]
11481    pub distance_type: Option<Box<Expression>>,
11482    #[serde(default)]
11483    pub options: Vec<Expression>,
11484}
11485
11486/// Quantile
11487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11488#[cfg_attr(feature = "bindings", derive(TS))]
11489pub struct Quantile {
11490    pub this: Box<Expression>,
11491    #[serde(default)]
11492    pub quantile: Option<Box<Expression>>,
11493}
11494
11495/// ApproxQuantile
11496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11497#[cfg_attr(feature = "bindings", derive(TS))]
11498pub struct ApproxQuantile {
11499    pub this: Box<Expression>,
11500    #[serde(default)]
11501    pub quantile: Option<Box<Expression>>,
11502    #[serde(default)]
11503    pub accuracy: Option<Box<Expression>>,
11504    #[serde(default)]
11505    pub weight: Option<Box<Expression>>,
11506    #[serde(default)]
11507    pub error_tolerance: Option<Box<Expression>>,
11508}
11509
11510/// ApproxPercentileEstimate
11511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11512#[cfg_attr(feature = "bindings", derive(TS))]
11513pub struct ApproxPercentileEstimate {
11514    pub this: Box<Expression>,
11515    #[serde(default)]
11516    pub percentile: Option<Box<Expression>>,
11517}
11518
11519/// Randn
11520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11521#[cfg_attr(feature = "bindings", derive(TS))]
11522pub struct Randn {
11523    #[serde(default)]
11524    pub this: Option<Box<Expression>>,
11525}
11526
11527/// Randstr
11528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11529#[cfg_attr(feature = "bindings", derive(TS))]
11530pub struct Randstr {
11531    pub this: Box<Expression>,
11532    #[serde(default)]
11533    pub generator: Option<Box<Expression>>,
11534}
11535
11536/// RangeN
11537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11538#[cfg_attr(feature = "bindings", derive(TS))]
11539pub struct RangeN {
11540    pub this: Box<Expression>,
11541    #[serde(default)]
11542    pub expressions: Vec<Expression>,
11543    #[serde(default)]
11544    pub each: Option<Box<Expression>>,
11545}
11546
11547/// RangeBucket
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct RangeBucket {
11551    pub this: Box<Expression>,
11552    pub expression: Box<Expression>,
11553}
11554
11555/// ReadCSV
11556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11557#[cfg_attr(feature = "bindings", derive(TS))]
11558pub struct ReadCSV {
11559    pub this: Box<Expression>,
11560    #[serde(default)]
11561    pub expressions: Vec<Expression>,
11562}
11563
11564/// ReadParquet
11565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11566#[cfg_attr(feature = "bindings", derive(TS))]
11567pub struct ReadParquet {
11568    #[serde(default)]
11569    pub expressions: Vec<Expression>,
11570}
11571
11572/// Reduce
11573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11574#[cfg_attr(feature = "bindings", derive(TS))]
11575pub struct Reduce {
11576    pub this: Box<Expression>,
11577    #[serde(default)]
11578    pub initial: Option<Box<Expression>>,
11579    #[serde(default)]
11580    pub merge: Option<Box<Expression>>,
11581    #[serde(default)]
11582    pub finish: Option<Box<Expression>>,
11583}
11584
11585/// RegexpExtractAll
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct RegexpExtractAll {
11589    pub this: Box<Expression>,
11590    pub expression: Box<Expression>,
11591    #[serde(default)]
11592    pub group: Option<Box<Expression>>,
11593    #[serde(default)]
11594    pub parameters: Option<Box<Expression>>,
11595    #[serde(default)]
11596    pub position: Option<Box<Expression>>,
11597    #[serde(default)]
11598    pub occurrence: Option<Box<Expression>>,
11599}
11600
11601/// RegexpILike
11602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11603#[cfg_attr(feature = "bindings", derive(TS))]
11604pub struct RegexpILike {
11605    pub this: Box<Expression>,
11606    pub expression: Box<Expression>,
11607    #[serde(default)]
11608    pub flag: Option<Box<Expression>>,
11609}
11610
11611/// RegexpFullMatch
11612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11613#[cfg_attr(feature = "bindings", derive(TS))]
11614pub struct RegexpFullMatch {
11615    pub this: Box<Expression>,
11616    pub expression: Box<Expression>,
11617    #[serde(default)]
11618    pub options: Vec<Expression>,
11619}
11620
11621/// RegexpInstr
11622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11623#[cfg_attr(feature = "bindings", derive(TS))]
11624pub struct RegexpInstr {
11625    pub this: Box<Expression>,
11626    pub expression: Box<Expression>,
11627    #[serde(default)]
11628    pub position: Option<Box<Expression>>,
11629    #[serde(default)]
11630    pub occurrence: Option<Box<Expression>>,
11631    #[serde(default)]
11632    pub option: Option<Box<Expression>>,
11633    #[serde(default)]
11634    pub parameters: Option<Box<Expression>>,
11635    #[serde(default)]
11636    pub group: Option<Box<Expression>>,
11637}
11638
11639/// RegexpSplit
11640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11641#[cfg_attr(feature = "bindings", derive(TS))]
11642pub struct RegexpSplit {
11643    pub this: Box<Expression>,
11644    pub expression: Box<Expression>,
11645    #[serde(default)]
11646    pub limit: Option<Box<Expression>>,
11647}
11648
11649/// RegexpCount
11650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11651#[cfg_attr(feature = "bindings", derive(TS))]
11652pub struct RegexpCount {
11653    pub this: Box<Expression>,
11654    pub expression: Box<Expression>,
11655    #[serde(default)]
11656    pub position: Option<Box<Expression>>,
11657    #[serde(default)]
11658    pub parameters: Option<Box<Expression>>,
11659}
11660
11661/// RegrValx
11662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11663#[cfg_attr(feature = "bindings", derive(TS))]
11664pub struct RegrValx {
11665    pub this: Box<Expression>,
11666    pub expression: Box<Expression>,
11667}
11668
11669/// RegrValy
11670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11671#[cfg_attr(feature = "bindings", derive(TS))]
11672pub struct RegrValy {
11673    pub this: Box<Expression>,
11674    pub expression: Box<Expression>,
11675}
11676
11677/// RegrAvgy
11678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11679#[cfg_attr(feature = "bindings", derive(TS))]
11680pub struct RegrAvgy {
11681    pub this: Box<Expression>,
11682    pub expression: Box<Expression>,
11683}
11684
11685/// RegrAvgx
11686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11687#[cfg_attr(feature = "bindings", derive(TS))]
11688pub struct RegrAvgx {
11689    pub this: Box<Expression>,
11690    pub expression: Box<Expression>,
11691}
11692
11693/// RegrCount
11694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11695#[cfg_attr(feature = "bindings", derive(TS))]
11696pub struct RegrCount {
11697    pub this: Box<Expression>,
11698    pub expression: Box<Expression>,
11699}
11700
11701/// RegrIntercept
11702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11703#[cfg_attr(feature = "bindings", derive(TS))]
11704pub struct RegrIntercept {
11705    pub this: Box<Expression>,
11706    pub expression: Box<Expression>,
11707}
11708
11709/// RegrR2
11710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11711#[cfg_attr(feature = "bindings", derive(TS))]
11712pub struct RegrR2 {
11713    pub this: Box<Expression>,
11714    pub expression: Box<Expression>,
11715}
11716
11717/// RegrSxx
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct RegrSxx {
11721    pub this: Box<Expression>,
11722    pub expression: Box<Expression>,
11723}
11724
11725/// RegrSxy
11726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11727#[cfg_attr(feature = "bindings", derive(TS))]
11728pub struct RegrSxy {
11729    pub this: Box<Expression>,
11730    pub expression: Box<Expression>,
11731}
11732
11733/// RegrSyy
11734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11735#[cfg_attr(feature = "bindings", derive(TS))]
11736pub struct RegrSyy {
11737    pub this: Box<Expression>,
11738    pub expression: Box<Expression>,
11739}
11740
11741/// RegrSlope
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct RegrSlope {
11745    pub this: Box<Expression>,
11746    pub expression: Box<Expression>,
11747}
11748
11749/// SafeAdd
11750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11751#[cfg_attr(feature = "bindings", derive(TS))]
11752pub struct SafeAdd {
11753    pub this: Box<Expression>,
11754    pub expression: Box<Expression>,
11755}
11756
11757/// SafeDivide
11758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11759#[cfg_attr(feature = "bindings", derive(TS))]
11760pub struct SafeDivide {
11761    pub this: Box<Expression>,
11762    pub expression: Box<Expression>,
11763}
11764
11765/// SafeMultiply
11766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11767#[cfg_attr(feature = "bindings", derive(TS))]
11768pub struct SafeMultiply {
11769    pub this: Box<Expression>,
11770    pub expression: Box<Expression>,
11771}
11772
11773/// SafeSubtract
11774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11775#[cfg_attr(feature = "bindings", derive(TS))]
11776pub struct SafeSubtract {
11777    pub this: Box<Expression>,
11778    pub expression: Box<Expression>,
11779}
11780
11781/// SHA2
11782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11783#[cfg_attr(feature = "bindings", derive(TS))]
11784pub struct SHA2 {
11785    pub this: Box<Expression>,
11786    #[serde(default)]
11787    pub length: Option<i64>,
11788}
11789
11790/// SHA2Digest
11791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11792#[cfg_attr(feature = "bindings", derive(TS))]
11793pub struct SHA2Digest {
11794    pub this: Box<Expression>,
11795    #[serde(default)]
11796    pub length: Option<i64>,
11797}
11798
11799/// SortArray
11800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11801#[cfg_attr(feature = "bindings", derive(TS))]
11802pub struct SortArray {
11803    pub this: Box<Expression>,
11804    #[serde(default)]
11805    pub asc: Option<Box<Expression>>,
11806    #[serde(default)]
11807    pub nulls_first: Option<Box<Expression>>,
11808}
11809
11810/// SplitPart
11811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11812#[cfg_attr(feature = "bindings", derive(TS))]
11813pub struct SplitPart {
11814    pub this: Box<Expression>,
11815    #[serde(default)]
11816    pub delimiter: Option<Box<Expression>>,
11817    #[serde(default)]
11818    pub part_index: Option<Box<Expression>>,
11819}
11820
11821/// SUBSTRING_INDEX(str, delim, count)
11822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11823#[cfg_attr(feature = "bindings", derive(TS))]
11824pub struct SubstringIndex {
11825    pub this: Box<Expression>,
11826    #[serde(default)]
11827    pub delimiter: Option<Box<Expression>>,
11828    #[serde(default)]
11829    pub count: Option<Box<Expression>>,
11830}
11831
11832/// StandardHash
11833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11834#[cfg_attr(feature = "bindings", derive(TS))]
11835pub struct StandardHash {
11836    pub this: Box<Expression>,
11837    #[serde(default)]
11838    pub expression: Option<Box<Expression>>,
11839}
11840
11841/// StrPosition
11842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11843#[cfg_attr(feature = "bindings", derive(TS))]
11844pub struct StrPosition {
11845    pub this: Box<Expression>,
11846    #[serde(default)]
11847    pub substr: Option<Box<Expression>>,
11848    #[serde(default)]
11849    pub position: Option<Box<Expression>>,
11850    #[serde(default)]
11851    pub occurrence: Option<Box<Expression>>,
11852}
11853
11854/// Search
11855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11856#[cfg_attr(feature = "bindings", derive(TS))]
11857pub struct Search {
11858    pub this: Box<Expression>,
11859    pub expression: Box<Expression>,
11860    #[serde(default)]
11861    pub json_scope: Option<Box<Expression>>,
11862    #[serde(default)]
11863    pub analyzer: Option<Box<Expression>>,
11864    #[serde(default)]
11865    pub analyzer_options: Option<Box<Expression>>,
11866    #[serde(default)]
11867    pub search_mode: Option<Box<Expression>>,
11868}
11869
11870/// SearchIp
11871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11872#[cfg_attr(feature = "bindings", derive(TS))]
11873pub struct SearchIp {
11874    pub this: Box<Expression>,
11875    pub expression: Box<Expression>,
11876}
11877
11878/// StrToDate
11879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11880#[cfg_attr(feature = "bindings", derive(TS))]
11881pub struct StrToDate {
11882    pub this: Box<Expression>,
11883    #[serde(default)]
11884    pub format: Option<String>,
11885    #[serde(default)]
11886    pub safe: Option<Box<Expression>>,
11887}
11888
11889/// StrToTime
11890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11891#[cfg_attr(feature = "bindings", derive(TS))]
11892pub struct StrToTime {
11893    pub this: Box<Expression>,
11894    pub format: String,
11895    #[serde(default)]
11896    pub zone: Option<Box<Expression>>,
11897    #[serde(default)]
11898    pub safe: Option<Box<Expression>>,
11899    #[serde(default)]
11900    pub target_type: Option<Box<Expression>>,
11901}
11902
11903/// StrToUnix
11904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11905#[cfg_attr(feature = "bindings", derive(TS))]
11906pub struct StrToUnix {
11907    #[serde(default)]
11908    pub this: Option<Box<Expression>>,
11909    #[serde(default)]
11910    pub format: Option<String>,
11911}
11912
11913/// StrToMap
11914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11915#[cfg_attr(feature = "bindings", derive(TS))]
11916pub struct StrToMap {
11917    pub this: Box<Expression>,
11918    #[serde(default)]
11919    pub pair_delim: Option<Box<Expression>>,
11920    #[serde(default)]
11921    pub key_value_delim: Option<Box<Expression>>,
11922    #[serde(default)]
11923    pub duplicate_resolution_callback: Option<Box<Expression>>,
11924}
11925
11926/// NumberToStr
11927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11928#[cfg_attr(feature = "bindings", derive(TS))]
11929pub struct NumberToStr {
11930    pub this: Box<Expression>,
11931    pub format: String,
11932    #[serde(default)]
11933    pub culture: Option<Box<Expression>>,
11934}
11935
11936/// FromBase
11937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11938#[cfg_attr(feature = "bindings", derive(TS))]
11939pub struct FromBase {
11940    pub this: Box<Expression>,
11941    pub expression: Box<Expression>,
11942}
11943
11944/// Stuff
11945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11946#[cfg_attr(feature = "bindings", derive(TS))]
11947pub struct Stuff {
11948    pub this: Box<Expression>,
11949    #[serde(default)]
11950    pub start: Option<Box<Expression>>,
11951    #[serde(default)]
11952    pub length: Option<i64>,
11953    pub expression: Box<Expression>,
11954}
11955
11956/// TimeToStr
11957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11958#[cfg_attr(feature = "bindings", derive(TS))]
11959pub struct TimeToStr {
11960    pub this: Box<Expression>,
11961    pub format: String,
11962    #[serde(default)]
11963    pub culture: Option<Box<Expression>>,
11964    #[serde(default)]
11965    pub zone: Option<Box<Expression>>,
11966}
11967
11968/// TimeStrToTime
11969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11970#[cfg_attr(feature = "bindings", derive(TS))]
11971pub struct TimeStrToTime {
11972    pub this: Box<Expression>,
11973    #[serde(default)]
11974    pub zone: Option<Box<Expression>>,
11975}
11976
11977/// TsOrDsAdd
11978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11979#[cfg_attr(feature = "bindings", derive(TS))]
11980pub struct TsOrDsAdd {
11981    pub this: Box<Expression>,
11982    pub expression: Box<Expression>,
11983    #[serde(default)]
11984    pub unit: Option<String>,
11985    #[serde(default)]
11986    pub return_type: Option<Box<Expression>>,
11987}
11988
11989/// TsOrDsDiff
11990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11991#[cfg_attr(feature = "bindings", derive(TS))]
11992pub struct TsOrDsDiff {
11993    pub this: Box<Expression>,
11994    pub expression: Box<Expression>,
11995    #[serde(default)]
11996    pub unit: Option<String>,
11997}
11998
11999/// TsOrDsToDate
12000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12001#[cfg_attr(feature = "bindings", derive(TS))]
12002pub struct TsOrDsToDate {
12003    pub this: Box<Expression>,
12004    #[serde(default)]
12005    pub format: Option<String>,
12006    #[serde(default)]
12007    pub safe: Option<Box<Expression>>,
12008}
12009
12010/// TsOrDsToTime
12011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12012#[cfg_attr(feature = "bindings", derive(TS))]
12013pub struct TsOrDsToTime {
12014    pub this: Box<Expression>,
12015    #[serde(default)]
12016    pub format: Option<String>,
12017    #[serde(default)]
12018    pub safe: Option<Box<Expression>>,
12019}
12020
12021/// Unhex
12022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12023#[cfg_attr(feature = "bindings", derive(TS))]
12024pub struct Unhex {
12025    pub this: Box<Expression>,
12026    #[serde(default)]
12027    pub expression: Option<Box<Expression>>,
12028}
12029
12030/// Uniform
12031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12032#[cfg_attr(feature = "bindings", derive(TS))]
12033pub struct Uniform {
12034    pub this: Box<Expression>,
12035    pub expression: Box<Expression>,
12036    #[serde(default)]
12037    pub gen: Option<Box<Expression>>,
12038    #[serde(default)]
12039    pub seed: Option<Box<Expression>>,
12040}
12041
12042/// UnixToStr
12043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12044#[cfg_attr(feature = "bindings", derive(TS))]
12045pub struct UnixToStr {
12046    pub this: Box<Expression>,
12047    #[serde(default)]
12048    pub format: Option<String>,
12049}
12050
12051/// UnixToTime
12052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12053#[cfg_attr(feature = "bindings", derive(TS))]
12054pub struct UnixToTime {
12055    pub this: Box<Expression>,
12056    #[serde(default)]
12057    pub scale: Option<i64>,
12058    #[serde(default)]
12059    pub zone: Option<Box<Expression>>,
12060    #[serde(default)]
12061    pub hours: Option<Box<Expression>>,
12062    #[serde(default)]
12063    pub minutes: Option<Box<Expression>>,
12064    #[serde(default)]
12065    pub format: Option<String>,
12066    #[serde(default)]
12067    pub target_type: Option<Box<Expression>>,
12068}
12069
12070/// Uuid
12071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12072#[cfg_attr(feature = "bindings", derive(TS))]
12073pub struct Uuid {
12074    #[serde(default)]
12075    pub this: Option<Box<Expression>>,
12076    #[serde(default)]
12077    pub name: Option<String>,
12078    #[serde(default)]
12079    pub is_string: Option<Box<Expression>>,
12080}
12081
12082/// TimestampFromParts
12083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12084#[cfg_attr(feature = "bindings", derive(TS))]
12085pub struct TimestampFromParts {
12086    #[serde(default)]
12087    pub zone: Option<Box<Expression>>,
12088    #[serde(default)]
12089    pub milli: Option<Box<Expression>>,
12090    #[serde(default)]
12091    pub this: Option<Box<Expression>>,
12092    #[serde(default)]
12093    pub expression: Option<Box<Expression>>,
12094}
12095
12096/// TimestampTzFromParts
12097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12098#[cfg_attr(feature = "bindings", derive(TS))]
12099pub struct TimestampTzFromParts {
12100    #[serde(default)]
12101    pub zone: Option<Box<Expression>>,
12102}
12103
12104/// Corr
12105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12106#[cfg_attr(feature = "bindings", derive(TS))]
12107pub struct Corr {
12108    pub this: Box<Expression>,
12109    pub expression: Box<Expression>,
12110    #[serde(default)]
12111    pub null_on_zero_variance: Option<Box<Expression>>,
12112}
12113
12114/// WidthBucket
12115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12116#[cfg_attr(feature = "bindings", derive(TS))]
12117pub struct WidthBucket {
12118    pub this: Box<Expression>,
12119    #[serde(default)]
12120    pub min_value: Option<Box<Expression>>,
12121    #[serde(default)]
12122    pub max_value: Option<Box<Expression>>,
12123    #[serde(default)]
12124    pub num_buckets: Option<Box<Expression>>,
12125    #[serde(default)]
12126    pub threshold: Option<Box<Expression>>,
12127}
12128
12129/// CovarSamp
12130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12131#[cfg_attr(feature = "bindings", derive(TS))]
12132pub struct CovarSamp {
12133    pub this: Box<Expression>,
12134    pub expression: Box<Expression>,
12135}
12136
12137/// CovarPop
12138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12139#[cfg_attr(feature = "bindings", derive(TS))]
12140pub struct CovarPop {
12141    pub this: Box<Expression>,
12142    pub expression: Box<Expression>,
12143}
12144
12145/// Week
12146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12147#[cfg_attr(feature = "bindings", derive(TS))]
12148pub struct Week {
12149    pub this: Box<Expression>,
12150    #[serde(default)]
12151    pub mode: Option<Box<Expression>>,
12152}
12153
12154/// XMLElement
12155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12156#[cfg_attr(feature = "bindings", derive(TS))]
12157pub struct XMLElement {
12158    pub this: Box<Expression>,
12159    #[serde(default)]
12160    pub expressions: Vec<Expression>,
12161    #[serde(default)]
12162    pub evalname: Option<Box<Expression>>,
12163}
12164
12165/// XMLGet
12166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12167#[cfg_attr(feature = "bindings", derive(TS))]
12168pub struct XMLGet {
12169    pub this: Box<Expression>,
12170    pub expression: Box<Expression>,
12171    #[serde(default)]
12172    pub instance: Option<Box<Expression>>,
12173}
12174
12175/// XMLTable
12176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12177#[cfg_attr(feature = "bindings", derive(TS))]
12178pub struct XMLTable {
12179    pub this: Box<Expression>,
12180    #[serde(default)]
12181    pub namespaces: Option<Box<Expression>>,
12182    #[serde(default)]
12183    pub passing: Option<Box<Expression>>,
12184    #[serde(default)]
12185    pub columns: Vec<Expression>,
12186    #[serde(default)]
12187    pub by_ref: Option<Box<Expression>>,
12188}
12189
12190/// XMLKeyValueOption
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct XMLKeyValueOption {
12194    pub this: Box<Expression>,
12195    #[serde(default)]
12196    pub expression: Option<Box<Expression>>,
12197}
12198
12199/// Zipf
12200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12201#[cfg_attr(feature = "bindings", derive(TS))]
12202pub struct Zipf {
12203    pub this: Box<Expression>,
12204    #[serde(default)]
12205    pub elementcount: Option<Box<Expression>>,
12206    #[serde(default)]
12207    pub gen: Option<Box<Expression>>,
12208}
12209
12210/// Merge
12211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12212#[cfg_attr(feature = "bindings", derive(TS))]
12213pub struct Merge {
12214    pub this: Box<Expression>,
12215    pub using: Box<Expression>,
12216    #[serde(default)]
12217    pub on: Option<Box<Expression>>,
12218    #[serde(default)]
12219    pub using_cond: Option<Box<Expression>>,
12220    #[serde(default)]
12221    pub whens: Option<Box<Expression>>,
12222    #[serde(default)]
12223    pub with_: Option<Box<Expression>>,
12224    #[serde(default)]
12225    pub returning: Option<Box<Expression>>,
12226}
12227
12228/// When
12229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12230#[cfg_attr(feature = "bindings", derive(TS))]
12231pub struct When {
12232    #[serde(default)]
12233    pub matched: Option<Box<Expression>>,
12234    #[serde(default)]
12235    pub source: Option<Box<Expression>>,
12236    #[serde(default)]
12237    pub condition: Option<Box<Expression>>,
12238    pub then: Box<Expression>,
12239}
12240
12241/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12243#[cfg_attr(feature = "bindings", derive(TS))]
12244pub struct Whens {
12245    #[serde(default)]
12246    pub expressions: Vec<Expression>,
12247}
12248
12249/// NextValueFor
12250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12251#[cfg_attr(feature = "bindings", derive(TS))]
12252pub struct NextValueFor {
12253    pub this: Box<Expression>,
12254    #[serde(default)]
12255    pub order: Option<Box<Expression>>,
12256}
12257
12258
12259#[cfg(test)]
12260mod tests {
12261    use super::*;
12262
12263    #[test]
12264    #[cfg(feature = "bindings")]
12265    fn export_typescript_types() {
12266        // This test exports TypeScript types to the generated directory
12267        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12268        Expression::export_all(&ts_rs::Config::default()).expect("Failed to export Expression types");
12269    }
12270
12271    #[test]
12272    fn test_simple_select_builder() {
12273        let select = Select::new()
12274            .column(Expression::star())
12275            .from(Expression::Table(TableRef::new("users")));
12276
12277        assert_eq!(select.expressions.len(), 1);
12278        assert!(select.from.is_some());
12279    }
12280
12281    #[test]
12282    fn test_expression_alias() {
12283        let expr = Expression::column("id").alias("user_id");
12284
12285        match expr {
12286            Expression::Alias(a) => {
12287                assert_eq!(a.alias.name, "user_id");
12288            }
12289            _ => panic!("Expected Alias"),
12290        }
12291    }
12292
12293    #[test]
12294    fn test_literal_creation() {
12295        let num = Expression::number(42);
12296        let str = Expression::string("hello");
12297
12298        match num {
12299            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12300            _ => panic!("Expected Number"),
12301        }
12302
12303        match str {
12304            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12305            _ => panic!("Expected String"),
12306        }
12307    }
12308
12309    #[test]
12310    fn test_expression_sql() {
12311        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12312        assert_eq!(expr.sql(), "SELECT 1 + 2");
12313    }
12314
12315    #[test]
12316    fn test_expression_sql_for() {
12317        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12318        let sql = expr.sql_for(crate::DialectType::Generic);
12319        assert!(sql.contains("IF"));
12320    }
12321}