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    PipeOperator(Box<PipeOperator>),
100    Pivot(Box<Pivot>),
101    PivotAlias(Box<PivotAlias>),
102    Unpivot(Box<Unpivot>),
103    Values(Box<Values>),
104    PreWhere(Box<PreWhere>),
105    Stream(Box<Stream>),
106    UsingData(Box<UsingData>),
107    XmlNamespace(Box<XmlNamespace>),
108
109    // DML
110    Insert(Box<Insert>),
111    Update(Box<Update>),
112    Delete(Box<Delete>),
113    Copy(Box<CopyStmt>),
114    Put(Box<PutStmt>),
115    StageReference(Box<StageReference>),
116
117    // Expressions
118    Alias(Box<Alias>),
119    Cast(Box<Cast>),
120    Collation(Box<CollationExpr>),
121    Case(Box<Case>),
122
123    // Binary operations
124    And(Box<BinaryOp>),
125    Or(Box<BinaryOp>),
126    Add(Box<BinaryOp>),
127    Sub(Box<BinaryOp>),
128    Mul(Box<BinaryOp>),
129    Div(Box<BinaryOp>),
130    Mod(Box<BinaryOp>),
131    Eq(Box<BinaryOp>),
132    Neq(Box<BinaryOp>),
133    Lt(Box<BinaryOp>),
134    Lte(Box<BinaryOp>),
135    Gt(Box<BinaryOp>),
136    Gte(Box<BinaryOp>),
137    Like(Box<LikeOp>),
138    ILike(Box<LikeOp>),
139    /// SQLite MATCH operator (FTS)
140    Match(Box<BinaryOp>),
141    BitwiseAnd(Box<BinaryOp>),
142    BitwiseOr(Box<BinaryOp>),
143    BitwiseXor(Box<BinaryOp>),
144    Concat(Box<BinaryOp>),
145    Adjacent(Box<BinaryOp>),  // PostgreSQL range adjacency operator (-|-)
146    TsMatch(Box<BinaryOp>),   // PostgreSQL text search match operator (@@)
147    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
148
149    // PostgreSQL array/JSONB operators
150    ArrayContainsAll(Box<BinaryOp>),       // @> operator (array contains all)
151    ArrayContainedBy(Box<BinaryOp>),       // <@ operator (array contained by)
152    ArrayOverlaps(Box<BinaryOp>),          // && operator (array overlaps)
153    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
154    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
155    JSONBDeleteAtPath(Box<BinaryOp>),      // #- operator (JSONB delete at path)
156    ExtendsLeft(Box<BinaryOp>),            // &< operator (PostgreSQL range extends left)
157    ExtendsRight(Box<BinaryOp>),           // &> operator (PostgreSQL range extends right)
158
159    // Unary operations
160    Not(Box<UnaryOp>),
161    Neg(Box<UnaryOp>),
162    BitwiseNot(Box<UnaryOp>),
163
164    // Predicates
165    In(Box<In>),
166    Between(Box<Between>),
167    IsNull(Box<IsNull>),
168    IsTrue(Box<IsTrueFalse>),
169    IsFalse(Box<IsTrueFalse>),
170    IsJson(Box<IsJson>),
171    Is(Box<BinaryOp>),  // General IS expression (e.g., a IS ?)
172    Exists(Box<Exists>),
173    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
174    MemberOf(Box<BinaryOp>),
175
176    // Functions
177    Function(Box<Function>),
178    AggregateFunction(Box<AggregateFunction>),
179    WindowFunction(Box<WindowFunction>),
180
181    // Clauses
182    From(Box<From>),
183    Join(Box<Join>),
184    JoinedTable(Box<JoinedTable>),
185    Where(Box<Where>),
186    GroupBy(Box<GroupBy>),
187    Having(Box<Having>),
188    OrderBy(Box<OrderBy>),
189    Limit(Box<Limit>),
190    Offset(Box<Offset>),
191    Qualify(Box<Qualify>),
192    With(Box<With>),
193    Cte(Box<Cte>),
194    DistributeBy(Box<DistributeBy>),
195    ClusterBy(Box<ClusterBy>),
196    SortBy(Box<SortBy>),
197    LateralView(Box<LateralView>),
198    Hint(Box<Hint>),
199    Pseudocolumn(Pseudocolumn),
200
201    // Oracle hierarchical queries (CONNECT BY)
202    Connect(Box<Connect>),
203    Prior(Box<Prior>),
204    ConnectByRoot(Box<ConnectByRoot>),
205
206    // Pattern matching (MATCH_RECOGNIZE)
207    MatchRecognize(Box<MatchRecognize>),
208
209    // Order expressions
210    Ordered(Box<Ordered>),
211
212    // Window specifications
213    Window(Box<WindowSpec>),
214    Over(Box<Over>),
215    WithinGroup(Box<WithinGroup>),
216
217    // Data types
218    DataType(DataType),
219
220    // Arrays and structs
221    Array(Box<Array>),
222    Struct(Box<Struct>),
223    Tuple(Box<Tuple>),
224
225    // Interval
226    Interval(Box<Interval>),
227
228    // String functions
229    ConcatWs(Box<ConcatWs>),
230    Substring(Box<SubstringFunc>),
231    Upper(Box<UnaryFunc>),
232    Lower(Box<UnaryFunc>),
233    Length(Box<UnaryFunc>),
234    Trim(Box<TrimFunc>),
235    LTrim(Box<UnaryFunc>),
236    RTrim(Box<UnaryFunc>),
237    Replace(Box<ReplaceFunc>),
238    Reverse(Box<UnaryFunc>),
239    Left(Box<LeftRightFunc>),
240    Right(Box<LeftRightFunc>),
241    Repeat(Box<RepeatFunc>),
242    Lpad(Box<PadFunc>),
243    Rpad(Box<PadFunc>),
244    Split(Box<SplitFunc>),
245    RegexpLike(Box<RegexpFunc>),
246    RegexpReplace(Box<RegexpReplaceFunc>),
247    RegexpExtract(Box<RegexpExtractFunc>),
248    Overlay(Box<OverlayFunc>),
249
250    // Math functions
251    Abs(Box<UnaryFunc>),
252    Round(Box<RoundFunc>),
253    Floor(Box<FloorFunc>),
254    Ceil(Box<CeilFunc>),
255    Power(Box<BinaryFunc>),
256    Sqrt(Box<UnaryFunc>),
257    Cbrt(Box<UnaryFunc>),
258    Ln(Box<UnaryFunc>),
259    Log(Box<LogFunc>),
260    Exp(Box<UnaryFunc>),
261    Sign(Box<UnaryFunc>),
262    Greatest(Box<VarArgFunc>),
263    Least(Box<VarArgFunc>),
264
265    // Date/time functions
266    CurrentDate(CurrentDate),
267    CurrentTime(CurrentTime),
268    CurrentTimestamp(CurrentTimestamp),
269    CurrentTimestampLTZ(CurrentTimestampLTZ),
270    AtTimeZone(Box<AtTimeZone>),
271    DateAdd(Box<DateAddFunc>),
272    DateSub(Box<DateAddFunc>),
273    DateDiff(Box<DateDiffFunc>),
274    DateTrunc(Box<DateTruncFunc>),
275    Extract(Box<ExtractFunc>),
276    ToDate(Box<ToDateFunc>),
277    ToTimestamp(Box<ToTimestampFunc>),
278    Date(Box<UnaryFunc>),
279    Time(Box<UnaryFunc>),
280    DateFromUnixDate(Box<UnaryFunc>),
281    UnixDate(Box<UnaryFunc>),
282    UnixSeconds(Box<UnaryFunc>),
283    UnixMillis(Box<UnaryFunc>),
284    UnixMicros(Box<UnaryFunc>),
285    UnixToTimeStr(Box<BinaryFunc>),
286    TimeStrToDate(Box<UnaryFunc>),
287    DateToDi(Box<UnaryFunc>),
288    DiToDate(Box<UnaryFunc>),
289    TsOrDiToDi(Box<UnaryFunc>),
290    TsOrDsToDatetime(Box<UnaryFunc>),
291    TsOrDsToTimestamp(Box<UnaryFunc>),
292    YearOfWeek(Box<UnaryFunc>),
293    YearOfWeekIso(Box<UnaryFunc>),
294
295    // Control flow functions
296    Coalesce(Box<VarArgFunc>),
297    NullIf(Box<BinaryFunc>),
298    IfFunc(Box<IfFunc>),
299    IfNull(Box<BinaryFunc>),
300    Nvl(Box<BinaryFunc>),
301    Nvl2(Box<Nvl2Func>),
302
303    // Type conversion
304    TryCast(Box<Cast>),
305    SafeCast(Box<Cast>),
306
307    // Typed aggregate functions
308    Count(Box<CountFunc>),
309    Sum(Box<AggFunc>),
310    Avg(Box<AggFunc>),
311    Min(Box<AggFunc>),
312    Max(Box<AggFunc>),
313    GroupConcat(Box<GroupConcatFunc>),
314    StringAgg(Box<StringAggFunc>),
315    ListAgg(Box<ListAggFunc>),
316    ArrayAgg(Box<AggFunc>),
317    CountIf(Box<AggFunc>),
318    SumIf(Box<SumIfFunc>),
319    Stddev(Box<AggFunc>),
320    StddevPop(Box<AggFunc>),
321    StddevSamp(Box<AggFunc>),
322    Variance(Box<AggFunc>),
323    VarPop(Box<AggFunc>),
324    VarSamp(Box<AggFunc>),
325    Median(Box<AggFunc>),
326    Mode(Box<AggFunc>),
327    First(Box<AggFunc>),
328    Last(Box<AggFunc>),
329    AnyValue(Box<AggFunc>),
330    ApproxDistinct(Box<AggFunc>),
331    ApproxCountDistinct(Box<AggFunc>),
332    ApproxPercentile(Box<ApproxPercentileFunc>),
333    Percentile(Box<PercentileFunc>),
334    LogicalAnd(Box<AggFunc>),
335    LogicalOr(Box<AggFunc>),
336    Skewness(Box<AggFunc>),
337    BitwiseCount(Box<UnaryFunc>),
338    ArrayConcatAgg(Box<AggFunc>),
339    ArrayUniqueAgg(Box<AggFunc>),
340    BoolXorAgg(Box<AggFunc>),
341
342    // Typed window functions
343    RowNumber(RowNumber),
344    Rank(Rank),
345    DenseRank(DenseRank),
346    NTile(Box<NTileFunc>),
347    Lead(Box<LeadLagFunc>),
348    Lag(Box<LeadLagFunc>),
349    FirstValue(Box<ValueFunc>),
350    LastValue(Box<ValueFunc>),
351    NthValue(Box<NthValueFunc>),
352    PercentRank(PercentRank),
353    CumeDist(CumeDist),
354    PercentileCont(Box<PercentileFunc>),
355    PercentileDisc(Box<PercentileFunc>),
356
357    // Additional string functions
358    Contains(Box<BinaryFunc>),
359    StartsWith(Box<BinaryFunc>),
360    EndsWith(Box<BinaryFunc>),
361    Position(Box<PositionFunc>),
362    Initcap(Box<UnaryFunc>),
363    Ascii(Box<UnaryFunc>),
364    Chr(Box<UnaryFunc>),
365    /// MySQL CHAR function with multiple args and optional USING charset
366    CharFunc(Box<CharFunc>),
367    Soundex(Box<UnaryFunc>),
368    Levenshtein(Box<BinaryFunc>),
369    ByteLength(Box<UnaryFunc>),
370    Hex(Box<UnaryFunc>),
371    LowerHex(Box<UnaryFunc>),
372    Unicode(Box<UnaryFunc>),
373
374    // Additional math functions
375    ModFunc(Box<BinaryFunc>),
376    Random(Random),
377    Rand(Box<Rand>),
378    TruncFunc(Box<TruncateFunc>),
379    Pi(Pi),
380    Radians(Box<UnaryFunc>),
381    Degrees(Box<UnaryFunc>),
382    Sin(Box<UnaryFunc>),
383    Cos(Box<UnaryFunc>),
384    Tan(Box<UnaryFunc>),
385    Asin(Box<UnaryFunc>),
386    Acos(Box<UnaryFunc>),
387    Atan(Box<UnaryFunc>),
388    Atan2(Box<BinaryFunc>),
389    IsNan(Box<UnaryFunc>),
390    IsInf(Box<UnaryFunc>),
391    IntDiv(Box<BinaryFunc>),
392
393    // Control flow
394    Decode(Box<DecodeFunc>),
395
396    // Additional date/time functions
397    DateFormat(Box<DateFormatFunc>),
398    FormatDate(Box<DateFormatFunc>),
399    Year(Box<UnaryFunc>),
400    Month(Box<UnaryFunc>),
401    Day(Box<UnaryFunc>),
402    Hour(Box<UnaryFunc>),
403    Minute(Box<UnaryFunc>),
404    Second(Box<UnaryFunc>),
405    DayOfWeek(Box<UnaryFunc>),
406    DayOfWeekIso(Box<UnaryFunc>),
407    DayOfMonth(Box<UnaryFunc>),
408    DayOfYear(Box<UnaryFunc>),
409    WeekOfYear(Box<UnaryFunc>),
410    Quarter(Box<UnaryFunc>),
411    AddMonths(Box<BinaryFunc>),
412    MonthsBetween(Box<BinaryFunc>),
413    LastDay(Box<LastDayFunc>),
414    NextDay(Box<BinaryFunc>),
415    Epoch(Box<UnaryFunc>),
416    EpochMs(Box<UnaryFunc>),
417    FromUnixtime(Box<FromUnixtimeFunc>),
418    UnixTimestamp(Box<UnixTimestampFunc>),
419    MakeDate(Box<MakeDateFunc>),
420    MakeTimestamp(Box<MakeTimestampFunc>),
421    TimestampTrunc(Box<DateTruncFunc>),
422    TimeStrToUnix(Box<UnaryFunc>),
423
424    // Session/User functions
425    SessionUser(SessionUser),
426
427    // Hash/Crypto functions
428    SHA(Box<UnaryFunc>),
429    SHA1Digest(Box<UnaryFunc>),
430
431    // Time conversion functions
432    TimeToUnix(Box<UnaryFunc>),
433
434    // Array functions
435    ArrayFunc(Box<ArrayConstructor>),
436    ArrayLength(Box<UnaryFunc>),
437    ArraySize(Box<UnaryFunc>),
438    Cardinality(Box<UnaryFunc>),
439    ArrayContains(Box<BinaryFunc>),
440    ArrayPosition(Box<BinaryFunc>),
441    ArrayAppend(Box<BinaryFunc>),
442    ArrayPrepend(Box<BinaryFunc>),
443    ArrayConcat(Box<VarArgFunc>),
444    ArraySort(Box<ArraySortFunc>),
445    ArrayReverse(Box<UnaryFunc>),
446    ArrayDistinct(Box<UnaryFunc>),
447    ArrayJoin(Box<ArrayJoinFunc>),
448    ArrayToString(Box<ArrayJoinFunc>),
449    Unnest(Box<UnnestFunc>),
450    Explode(Box<UnaryFunc>),
451    ExplodeOuter(Box<UnaryFunc>),
452    ArrayFilter(Box<ArrayFilterFunc>),
453    ArrayTransform(Box<ArrayTransformFunc>),
454    ArrayFlatten(Box<UnaryFunc>),
455    ArrayCompact(Box<UnaryFunc>),
456    ArrayIntersect(Box<BinaryFunc>),
457    ArrayUnion(Box<BinaryFunc>),
458    ArrayExcept(Box<BinaryFunc>),
459    ArrayRemove(Box<BinaryFunc>),
460    ArrayZip(Box<VarArgFunc>),
461    Sequence(Box<SequenceFunc>),
462    Generate(Box<SequenceFunc>),
463    ExplodingGenerateSeries(Box<SequenceFunc>),
464    ToArray(Box<UnaryFunc>),
465    StarMap(Box<BinaryFunc>),
466
467    // Struct functions
468    StructFunc(Box<StructConstructor>),
469    StructExtract(Box<StructExtractFunc>),
470    NamedStruct(Box<NamedStructFunc>),
471
472    // Map functions
473    MapFunc(Box<MapConstructor>),
474    MapFromEntries(Box<UnaryFunc>),
475    MapFromArrays(Box<BinaryFunc>),
476    MapKeys(Box<UnaryFunc>),
477    MapValues(Box<UnaryFunc>),
478    MapContainsKey(Box<BinaryFunc>),
479    MapConcat(Box<VarArgFunc>),
480    ElementAt(Box<BinaryFunc>),
481    TransformKeys(Box<TransformFunc>),
482    TransformValues(Box<TransformFunc>),
483
484    // JSON functions
485    JsonExtract(Box<JsonExtractFunc>),
486    JsonExtractScalar(Box<JsonExtractFunc>),
487    JsonExtractPath(Box<JsonPathFunc>),
488    JsonArray(Box<VarArgFunc>),
489    JsonObject(Box<JsonObjectFunc>),
490    JsonQuery(Box<JsonExtractFunc>),
491    JsonValue(Box<JsonExtractFunc>),
492    JsonArrayLength(Box<UnaryFunc>),
493    JsonKeys(Box<UnaryFunc>),
494    JsonType(Box<UnaryFunc>),
495    ParseJson(Box<UnaryFunc>),
496    ToJson(Box<UnaryFunc>),
497    JsonSet(Box<JsonModifyFunc>),
498    JsonInsert(Box<JsonModifyFunc>),
499    JsonRemove(Box<JsonPathFunc>),
500    JsonMergePatch(Box<BinaryFunc>),
501    JsonArrayAgg(Box<JsonArrayAggFunc>),
502    JsonObjectAgg(Box<JsonObjectAggFunc>),
503
504    // Type casting/conversion
505    Convert(Box<ConvertFunc>),
506    Typeof(Box<UnaryFunc>),
507
508    // Additional expressions
509    Lambda(Box<LambdaExpr>),
510    Parameter(Box<Parameter>),
511    Placeholder(Placeholder),
512    NamedArgument(Box<NamedArgument>),
513    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
514    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
515    TableArgument(Box<TableArgument>),
516    SqlComment(Box<SqlComment>),
517
518    // Additional predicates
519    NullSafeEq(Box<BinaryOp>),
520    NullSafeNeq(Box<BinaryOp>),
521    Glob(Box<BinaryOp>),
522    SimilarTo(Box<SimilarToExpr>),
523    Any(Box<QuantifiedExpr>),
524    All(Box<QuantifiedExpr>),
525    Overlaps(Box<OverlapsExpr>),
526
527    // Bitwise operations
528    BitwiseLeftShift(Box<BinaryOp>),
529    BitwiseRightShift(Box<BinaryOp>),
530    BitwiseAndAgg(Box<AggFunc>),
531    BitwiseOrAgg(Box<AggFunc>),
532    BitwiseXorAgg(Box<AggFunc>),
533
534    // Array/struct/map access
535    Subscript(Box<Subscript>),
536    Dot(Box<DotAccess>),
537    MethodCall(Box<MethodCall>),
538    ArraySlice(Box<ArraySlice>),
539
540    // DDL statements
541    CreateTable(Box<CreateTable>),
542    DropTable(Box<DropTable>),
543    AlterTable(Box<AlterTable>),
544    CreateIndex(Box<CreateIndex>),
545    DropIndex(Box<DropIndex>),
546    CreateView(Box<CreateView>),
547    DropView(Box<DropView>),
548    AlterView(Box<AlterView>),
549    AlterIndex(Box<AlterIndex>),
550    Truncate(Box<Truncate>),
551    Use(Box<Use>),
552    Cache(Box<Cache>),
553    Uncache(Box<Uncache>),
554    LoadData(Box<LoadData>),
555    Pragma(Box<Pragma>),
556    Grant(Box<Grant>),
557    Revoke(Box<Revoke>),
558    Comment(Box<Comment>),
559    SetStatement(Box<SetStatement>),
560    // Phase 4: Additional DDL statements
561    CreateSchema(Box<CreateSchema>),
562    DropSchema(Box<DropSchema>),
563    DropNamespace(Box<DropNamespace>),
564    CreateDatabase(Box<CreateDatabase>),
565    DropDatabase(Box<DropDatabase>),
566    CreateFunction(Box<CreateFunction>),
567    DropFunction(Box<DropFunction>),
568    CreateProcedure(Box<CreateProcedure>),
569    DropProcedure(Box<DropProcedure>),
570    CreateSequence(Box<CreateSequence>),
571    DropSequence(Box<DropSequence>),
572    AlterSequence(Box<AlterSequence>),
573    CreateTrigger(Box<CreateTrigger>),
574    DropTrigger(Box<DropTrigger>),
575    CreateType(Box<CreateType>),
576    DropType(Box<DropType>),
577    Describe(Box<Describe>),
578    Show(Box<Show>),
579
580    // Transaction and other commands
581    Command(Box<Command>),
582    Kill(Box<Kill>),
583    /// EXEC/EXECUTE statement (TSQL stored procedure call)
584    Execute(Box<ExecuteStatement>),
585
586    // Placeholder for unparsed/raw SQL
587    Raw(Raw),
588
589    // Paren for grouping
590    Paren(Box<Paren>),
591
592    // Expression with trailing comments (for round-trip preservation)
593    Annotated(Box<Annotated>),
594
595    // === BATCH GENERATED EXPRESSION TYPES ===
596    // Generated from Python sqlglot expressions.py
597    Refresh(Box<Refresh>),
598    LockingStatement(Box<LockingStatement>),
599    SequenceProperties(Box<SequenceProperties>),
600    TruncateTable(Box<TruncateTable>),
601    Clone(Box<Clone>),
602    Attach(Box<Attach>),
603    Detach(Box<Detach>),
604    Install(Box<Install>),
605    Summarize(Box<Summarize>),
606    Declare(Box<Declare>),
607    DeclareItem(Box<DeclareItem>),
608    Set(Box<Set>),
609    Heredoc(Box<Heredoc>),
610    SetItem(Box<SetItem>),
611    QueryBand(Box<QueryBand>),
612    UserDefinedFunction(Box<UserDefinedFunction>),
613    RecursiveWithSearch(Box<RecursiveWithSearch>),
614    ProjectionDef(Box<ProjectionDef>),
615    TableAlias(Box<TableAlias>),
616    ByteString(Box<ByteString>),
617    HexStringExpr(Box<HexStringExpr>),
618    UnicodeString(Box<UnicodeString>),
619    ColumnPosition(Box<ColumnPosition>),
620    ColumnDef(Box<ColumnDef>),
621    AlterColumn(Box<AlterColumn>),
622    AlterSortKey(Box<AlterSortKey>),
623    AlterSet(Box<AlterSet>),
624    RenameColumn(Box<RenameColumn>),
625    Comprehension(Box<Comprehension>),
626    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
627    MergeTreeTTL(Box<MergeTreeTTL>),
628    IndexConstraintOption(Box<IndexConstraintOption>),
629    ColumnConstraint(Box<ColumnConstraint>),
630    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
631    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
632    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
633    CheckColumnConstraint(Box<CheckColumnConstraint>),
634    CompressColumnConstraint(Box<CompressColumnConstraint>),
635    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
636    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
637    WithOperator(Box<WithOperator>),
638    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
639    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
640    CommentColumnConstraint(CommentColumnConstraint),
641    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
642    IndexColumnConstraint(Box<IndexColumnConstraint>),
643    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
644    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
645    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
646    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
647    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
648    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
649    InOutColumnConstraint(Box<InOutColumnConstraint>),
650    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
651    PathColumnConstraint(Box<PathColumnConstraint>),
652    Constraint(Box<Constraint>),
653    Export(Box<Export>),
654    Filter(Box<Filter>),
655    Changes(Box<Changes>),
656    CopyParameter(Box<CopyParameter>),
657    Credentials(Box<Credentials>),
658    Directory(Box<Directory>),
659    ForeignKey(Box<ForeignKey>),
660    ColumnPrefix(Box<ColumnPrefix>),
661    PrimaryKey(Box<PrimaryKey>),
662    IntoClause(Box<IntoClause>),
663    JoinHint(Box<JoinHint>),
664    Opclass(Box<Opclass>),
665    Index(Box<Index>),
666    IndexParameters(Box<IndexParameters>),
667    ConditionalInsert(Box<ConditionalInsert>),
668    MultitableInserts(Box<MultitableInserts>),
669    OnConflict(Box<OnConflict>),
670    OnCondition(Box<OnCondition>),
671    Returning(Box<Returning>),
672    Introducer(Box<Introducer>),
673    PartitionRange(Box<PartitionRange>),
674    Fetch(Box<Fetch>),
675    Group(Box<Group>),
676    Cube(Box<Cube>),
677    Rollup(Box<Rollup>),
678    GroupingSets(Box<GroupingSets>),
679    LimitOptions(Box<LimitOptions>),
680    Lateral(Box<Lateral>),
681    TableFromRows(Box<TableFromRows>),
682    RowsFrom(Box<RowsFrom>),
683    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
684    WithFill(Box<WithFill>),
685    Property(Box<Property>),
686    GrantPrivilege(Box<GrantPrivilege>),
687    GrantPrincipal(Box<GrantPrincipal>),
688    AllowedValuesProperty(Box<AllowedValuesProperty>),
689    AlgorithmProperty(Box<AlgorithmProperty>),
690    AutoIncrementProperty(Box<AutoIncrementProperty>),
691    AutoRefreshProperty(Box<AutoRefreshProperty>),
692    BackupProperty(Box<BackupProperty>),
693    BuildProperty(Box<BuildProperty>),
694    BlockCompressionProperty(Box<BlockCompressionProperty>),
695    CharacterSetProperty(Box<CharacterSetProperty>),
696    ChecksumProperty(Box<ChecksumProperty>),
697    CollateProperty(Box<CollateProperty>),
698    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
699    DataDeletionProperty(Box<DataDeletionProperty>),
700    DefinerProperty(Box<DefinerProperty>),
701    DistKeyProperty(Box<DistKeyProperty>),
702    DistributedByProperty(Box<DistributedByProperty>),
703    DistStyleProperty(Box<DistStyleProperty>),
704    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
705    EngineProperty(Box<EngineProperty>),
706    ToTableProperty(Box<ToTableProperty>),
707    ExecuteAsProperty(Box<ExecuteAsProperty>),
708    ExternalProperty(Box<ExternalProperty>),
709    FallbackProperty(Box<FallbackProperty>),
710    FileFormatProperty(Box<FileFormatProperty>),
711    CredentialsProperty(Box<CredentialsProperty>),
712    FreespaceProperty(Box<FreespaceProperty>),
713    InheritsProperty(Box<InheritsProperty>),
714    InputModelProperty(Box<InputModelProperty>),
715    OutputModelProperty(Box<OutputModelProperty>),
716    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
717    JournalProperty(Box<JournalProperty>),
718    LanguageProperty(Box<LanguageProperty>),
719    EnviromentProperty(Box<EnviromentProperty>),
720    ClusteredByProperty(Box<ClusteredByProperty>),
721    DictProperty(Box<DictProperty>),
722    DictRange(Box<DictRange>),
723    OnCluster(Box<OnCluster>),
724    LikeProperty(Box<LikeProperty>),
725    LocationProperty(Box<LocationProperty>),
726    LockProperty(Box<LockProperty>),
727    LockingProperty(Box<LockingProperty>),
728    LogProperty(Box<LogProperty>),
729    MaterializedProperty(Box<MaterializedProperty>),
730    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
731    OnProperty(Box<OnProperty>),
732    OnCommitProperty(Box<OnCommitProperty>),
733    PartitionedByProperty(Box<PartitionedByProperty>),
734    PartitionedByBucket(Box<PartitionedByBucket>),
735    PartitionByTruncate(Box<PartitionByTruncate>),
736    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
737    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
738    PartitionByListProperty(Box<PartitionByListProperty>),
739    PartitionList(Box<PartitionList>),
740    Partition(Box<Partition>),
741    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
742    UniqueKeyProperty(Box<UniqueKeyProperty>),
743    RollupProperty(Box<RollupProperty>),
744    PartitionBoundSpec(Box<PartitionBoundSpec>),
745    PartitionedOfProperty(Box<PartitionedOfProperty>),
746    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
747    ReturnsProperty(Box<ReturnsProperty>),
748    RowFormatProperty(Box<RowFormatProperty>),
749    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
750    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
751    QueryTransform(Box<QueryTransform>),
752    SampleProperty(Box<SampleProperty>),
753    SecurityProperty(Box<SecurityProperty>),
754    SchemaCommentProperty(Box<SchemaCommentProperty>),
755    SemanticView(Box<SemanticView>),
756    SerdeProperties(Box<SerdeProperties>),
757    SetProperty(Box<SetProperty>),
758    SharingProperty(Box<SharingProperty>),
759    SetConfigProperty(Box<SetConfigProperty>),
760    SettingsProperty(Box<SettingsProperty>),
761    SortKeyProperty(Box<SortKeyProperty>),
762    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
763    SqlSecurityProperty(Box<SqlSecurityProperty>),
764    StabilityProperty(Box<StabilityProperty>),
765    StorageHandlerProperty(Box<StorageHandlerProperty>),
766    TemporaryProperty(Box<TemporaryProperty>),
767    Tags(Box<Tags>),
768    TransformModelProperty(Box<TransformModelProperty>),
769    TransientProperty(Box<TransientProperty>),
770    UsingTemplateProperty(Box<UsingTemplateProperty>),
771    ViewAttributeProperty(Box<ViewAttributeProperty>),
772    VolatileProperty(Box<VolatileProperty>),
773    WithDataProperty(Box<WithDataProperty>),
774    WithJournalTableProperty(Box<WithJournalTableProperty>),
775    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
776    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
777    WithProcedureOptions(Box<WithProcedureOptions>),
778    EncodeProperty(Box<EncodeProperty>),
779    IncludeProperty(Box<IncludeProperty>),
780    Properties(Box<Properties>),
781    InputOutputFormat(Box<InputOutputFormat>),
782    Reference(Box<Reference>),
783    QueryOption(Box<QueryOption>),
784    WithTableHint(Box<WithTableHint>),
785    IndexTableHint(Box<IndexTableHint>),
786    HistoricalData(Box<HistoricalData>),
787    Get(Box<Get>),
788    SetOperation(Box<SetOperation>),
789    Var(Box<Var>),
790    Version(Box<Version>),
791    Schema(Box<Schema>),
792    Lock(Box<Lock>),
793    TableSample(Box<TableSample>),
794    Tag(Box<Tag>),
795    UnpivotColumns(Box<UnpivotColumns>),
796    WindowSpec(Box<WindowSpec>),
797    SessionParameter(Box<SessionParameter>),
798    PseudoType(Box<PseudoType>),
799    ObjectIdentifier(Box<ObjectIdentifier>),
800    Transaction(Box<Transaction>),
801    Commit(Box<Commit>),
802    Rollback(Box<Rollback>),
803    AlterSession(Box<AlterSession>),
804    Analyze(Box<Analyze>),
805    AnalyzeStatistics(Box<AnalyzeStatistics>),
806    AnalyzeHistogram(Box<AnalyzeHistogram>),
807    AnalyzeSample(Box<AnalyzeSample>),
808    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
809    AnalyzeDelete(Box<AnalyzeDelete>),
810    AnalyzeWith(Box<AnalyzeWith>),
811    AnalyzeValidate(Box<AnalyzeValidate>),
812    AddPartition(Box<AddPartition>),
813    AttachOption(Box<AttachOption>),
814    DropPartition(Box<DropPartition>),
815    ReplacePartition(Box<ReplacePartition>),
816    DPipe(Box<DPipe>),
817    Operator(Box<Operator>),
818    PivotAny(Box<PivotAny>),
819    Aliases(Box<Aliases>),
820    AtIndex(Box<AtIndex>),
821    FromTimeZone(Box<FromTimeZone>),
822    FormatPhrase(Box<FormatPhrase>),
823    ForIn(Box<ForIn>),
824    TimeUnit(Box<TimeUnit>),
825    IntervalOp(Box<IntervalOp>),
826    IntervalSpan(Box<IntervalSpan>),
827    HavingMax(Box<HavingMax>),
828    CosineDistance(Box<CosineDistance>),
829    DotProduct(Box<DotProduct>),
830    EuclideanDistance(Box<EuclideanDistance>),
831    ManhattanDistance(Box<ManhattanDistance>),
832    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
833    Booland(Box<Booland>),
834    Boolor(Box<Boolor>),
835    ParameterizedAgg(Box<ParameterizedAgg>),
836    ArgMax(Box<ArgMax>),
837    ArgMin(Box<ArgMin>),
838    ApproxTopK(Box<ApproxTopK>),
839    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
840    ApproxTopKCombine(Box<ApproxTopKCombine>),
841    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
842    ApproxTopSum(Box<ApproxTopSum>),
843    ApproxQuantiles(Box<ApproxQuantiles>),
844    Minhash(Box<Minhash>),
845    FarmFingerprint(Box<FarmFingerprint>),
846    Float64(Box<Float64>),
847    Transform(Box<Transform>),
848    Translate(Box<Translate>),
849    Grouping(Box<Grouping>),
850    GroupingId(Box<GroupingId>),
851    Anonymous(Box<Anonymous>),
852    AnonymousAggFunc(Box<AnonymousAggFunc>),
853    CombinedAggFunc(Box<CombinedAggFunc>),
854    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
855    HashAgg(Box<HashAgg>),
856    Hll(Box<Hll>),
857    Apply(Box<Apply>),
858    ToBoolean(Box<ToBoolean>),
859    List(Box<List>),
860    ToMap(Box<ToMap>),
861    Pad(Box<Pad>),
862    ToChar(Box<ToChar>),
863    ToNumber(Box<ToNumber>),
864    ToDouble(Box<ToDouble>),
865    Int64(Box<UnaryFunc>),
866    StringFunc(Box<StringFunc>),
867    ToDecfloat(Box<ToDecfloat>),
868    TryToDecfloat(Box<TryToDecfloat>),
869    ToFile(Box<ToFile>),
870    Columns(Box<Columns>),
871    ConvertToCharset(Box<ConvertToCharset>),
872    ConvertTimezone(Box<ConvertTimezone>),
873    GenerateSeries(Box<GenerateSeries>),
874    AIAgg(Box<AIAgg>),
875    AIClassify(Box<AIClassify>),
876    ArrayAll(Box<ArrayAll>),
877    ArrayAny(Box<ArrayAny>),
878    ArrayConstructCompact(Box<ArrayConstructCompact>),
879    StPoint(Box<StPoint>),
880    StDistance(Box<StDistance>),
881    StringToArray(Box<StringToArray>),
882    ArraySum(Box<ArraySum>),
883    ObjectAgg(Box<ObjectAgg>),
884    CastToStrType(Box<CastToStrType>),
885    CheckJson(Box<CheckJson>),
886    CheckXml(Box<CheckXml>),
887    TranslateCharacters(Box<TranslateCharacters>),
888    CurrentSchemas(Box<CurrentSchemas>),
889    CurrentDatetime(Box<CurrentDatetime>),
890    Localtime(Box<Localtime>),
891    Localtimestamp(Box<Localtimestamp>),
892    Systimestamp(Box<Systimestamp>),
893    CurrentSchema(Box<CurrentSchema>),
894    CurrentUser(Box<CurrentUser>),
895    UtcTime(Box<UtcTime>),
896    UtcTimestamp(Box<UtcTimestamp>),
897    Timestamp(Box<TimestampFunc>),
898    DateBin(Box<DateBin>),
899    Datetime(Box<Datetime>),
900    DatetimeAdd(Box<DatetimeAdd>),
901    DatetimeSub(Box<DatetimeSub>),
902    DatetimeDiff(Box<DatetimeDiff>),
903    DatetimeTrunc(Box<DatetimeTrunc>),
904    Dayname(Box<Dayname>),
905    MakeInterval(Box<MakeInterval>),
906    PreviousDay(Box<PreviousDay>),
907    Elt(Box<Elt>),
908    TimestampAdd(Box<TimestampAdd>),
909    TimestampSub(Box<TimestampSub>),
910    TimestampDiff(Box<TimestampDiff>),
911    TimeSlice(Box<TimeSlice>),
912    TimeAdd(Box<TimeAdd>),
913    TimeSub(Box<TimeSub>),
914    TimeDiff(Box<TimeDiff>),
915    TimeTrunc(Box<TimeTrunc>),
916    DateFromParts(Box<DateFromParts>),
917    TimeFromParts(Box<TimeFromParts>),
918    DecodeCase(Box<DecodeCase>),
919    Decrypt(Box<Decrypt>),
920    DecryptRaw(Box<DecryptRaw>),
921    Encode(Box<Encode>),
922    Encrypt(Box<Encrypt>),
923    EncryptRaw(Box<EncryptRaw>),
924    EqualNull(Box<EqualNull>),
925    ToBinary(Box<ToBinary>),
926    Base64DecodeBinary(Box<Base64DecodeBinary>),
927    Base64DecodeString(Box<Base64DecodeString>),
928    Base64Encode(Box<Base64Encode>),
929    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
930    TryBase64DecodeString(Box<TryBase64DecodeString>),
931    GapFill(Box<GapFill>),
932    GenerateDateArray(Box<GenerateDateArray>),
933    GenerateTimestampArray(Box<GenerateTimestampArray>),
934    GetExtract(Box<GetExtract>),
935    Getbit(Box<Getbit>),
936    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
937    HexEncode(Box<HexEncode>),
938    Compress(Box<Compress>),
939    DecompressBinary(Box<DecompressBinary>),
940    DecompressString(Box<DecompressString>),
941    Xor(Box<Xor>),
942    Nullif(Box<Nullif>),
943    JSON(Box<JSON>),
944    JSONPath(Box<JSONPath>),
945    JSONPathFilter(Box<JSONPathFilter>),
946    JSONPathKey(Box<JSONPathKey>),
947    JSONPathRecursive(Box<JSONPathRecursive>),
948    JSONPathScript(Box<JSONPathScript>),
949    JSONPathSlice(Box<JSONPathSlice>),
950    JSONPathSelector(Box<JSONPathSelector>),
951    JSONPathSubscript(Box<JSONPathSubscript>),
952    JSONPathUnion(Box<JSONPathUnion>),
953    Format(Box<Format>),
954    JSONKeys(Box<JSONKeys>),
955    JSONKeyValue(Box<JSONKeyValue>),
956    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
957    JSONObject(Box<JSONObject>),
958    JSONObjectAgg(Box<JSONObjectAgg>),
959    JSONBObjectAgg(Box<JSONBObjectAgg>),
960    JSONArray(Box<JSONArray>),
961    JSONArrayAgg(Box<JSONArrayAgg>),
962    JSONExists(Box<JSONExists>),
963    JSONColumnDef(Box<JSONColumnDef>),
964    JSONSchema(Box<JSONSchema>),
965    JSONSet(Box<JSONSet>),
966    JSONStripNulls(Box<JSONStripNulls>),
967    JSONValue(Box<JSONValue>),
968    JSONValueArray(Box<JSONValueArray>),
969    JSONRemove(Box<JSONRemove>),
970    JSONTable(Box<JSONTable>),
971    JSONType(Box<JSONType>),
972    ObjectInsert(Box<ObjectInsert>),
973    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
974    OpenJSON(Box<OpenJSON>),
975    JSONBExists(Box<JSONBExists>),
976    JSONBContains(Box<BinaryFunc>),
977    JSONBExtract(Box<BinaryFunc>),
978    JSONCast(Box<JSONCast>),
979    JSONExtract(Box<JSONExtract>),
980    JSONExtractQuote(Box<JSONExtractQuote>),
981    JSONExtractArray(Box<JSONExtractArray>),
982    JSONExtractScalar(Box<JSONExtractScalar>),
983    JSONBExtractScalar(Box<JSONBExtractScalar>),
984    JSONFormat(Box<JSONFormat>),
985    JSONBool(Box<UnaryFunc>),
986    JSONPathRoot(JSONPathRoot),
987    JSONArrayAppend(Box<JSONArrayAppend>),
988    JSONArrayContains(Box<JSONArrayContains>),
989    JSONArrayInsert(Box<JSONArrayInsert>),
990    ParseJSON(Box<ParseJSON>),
991    ParseUrl(Box<ParseUrl>),
992    ParseIp(Box<ParseIp>),
993    ParseTime(Box<ParseTime>),
994    ParseDatetime(Box<ParseDatetime>),
995    Map(Box<Map>),
996    MapCat(Box<MapCat>),
997    MapDelete(Box<MapDelete>),
998    MapInsert(Box<MapInsert>),
999    MapPick(Box<MapPick>),
1000    ScopeResolution(Box<ScopeResolution>),
1001    Slice(Box<Slice>),
1002    VarMap(Box<VarMap>),
1003    MatchAgainst(Box<MatchAgainst>),
1004    MD5Digest(Box<MD5Digest>),
1005    MD5NumberLower64(Box<UnaryFunc>),
1006    MD5NumberUpper64(Box<UnaryFunc>),
1007    Monthname(Box<Monthname>),
1008    Ntile(Box<Ntile>),
1009    Normalize(Box<Normalize>),
1010    Normal(Box<Normal>),
1011    Predict(Box<Predict>),
1012    MLTranslate(Box<MLTranslate>),
1013    FeaturesAtTime(Box<FeaturesAtTime>),
1014    GenerateEmbedding(Box<GenerateEmbedding>),
1015    MLForecast(Box<MLForecast>),
1016    ModelAttribute(Box<ModelAttribute>),
1017    VectorSearch(Box<VectorSearch>),
1018    Quantile(Box<Quantile>),
1019    ApproxQuantile(Box<ApproxQuantile>),
1020    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1021    Randn(Box<Randn>),
1022    Randstr(Box<Randstr>),
1023    RangeN(Box<RangeN>),
1024    RangeBucket(Box<RangeBucket>),
1025    ReadCSV(Box<ReadCSV>),
1026    ReadParquet(Box<ReadParquet>),
1027    Reduce(Box<Reduce>),
1028    RegexpExtractAll(Box<RegexpExtractAll>),
1029    RegexpILike(Box<RegexpILike>),
1030    RegexpFullMatch(Box<RegexpFullMatch>),
1031    RegexpInstr(Box<RegexpInstr>),
1032    RegexpSplit(Box<RegexpSplit>),
1033    RegexpCount(Box<RegexpCount>),
1034    RegrValx(Box<RegrValx>),
1035    RegrValy(Box<RegrValy>),
1036    RegrAvgy(Box<RegrAvgy>),
1037    RegrAvgx(Box<RegrAvgx>),
1038    RegrCount(Box<RegrCount>),
1039    RegrIntercept(Box<RegrIntercept>),
1040    RegrR2(Box<RegrR2>),
1041    RegrSxx(Box<RegrSxx>),
1042    RegrSxy(Box<RegrSxy>),
1043    RegrSyy(Box<RegrSyy>),
1044    RegrSlope(Box<RegrSlope>),
1045    SafeAdd(Box<SafeAdd>),
1046    SafeDivide(Box<SafeDivide>),
1047    SafeMultiply(Box<SafeMultiply>),
1048    SafeSubtract(Box<SafeSubtract>),
1049    SHA2(Box<SHA2>),
1050    SHA2Digest(Box<SHA2Digest>),
1051    SortArray(Box<SortArray>),
1052    SplitPart(Box<SplitPart>),
1053    SubstringIndex(Box<SubstringIndex>),
1054    StandardHash(Box<StandardHash>),
1055    StrPosition(Box<StrPosition>),
1056    Search(Box<Search>),
1057    SearchIp(Box<SearchIp>),
1058    StrToDate(Box<StrToDate>),
1059    DateStrToDate(Box<UnaryFunc>),
1060    DateToDateStr(Box<UnaryFunc>),
1061    StrToTime(Box<StrToTime>),
1062    StrToUnix(Box<StrToUnix>),
1063    StrToMap(Box<StrToMap>),
1064    NumberToStr(Box<NumberToStr>),
1065    FromBase(Box<FromBase>),
1066    Stuff(Box<Stuff>),
1067    TimeToStr(Box<TimeToStr>),
1068    TimeStrToTime(Box<TimeStrToTime>),
1069    TsOrDsAdd(Box<TsOrDsAdd>),
1070    TsOrDsDiff(Box<TsOrDsDiff>),
1071    TsOrDsToDate(Box<TsOrDsToDate>),
1072    TsOrDsToTime(Box<TsOrDsToTime>),
1073    Unhex(Box<Unhex>),
1074    Uniform(Box<Uniform>),
1075    UnixToStr(Box<UnixToStr>),
1076    UnixToTime(Box<UnixToTime>),
1077    Uuid(Box<Uuid>),
1078    TimestampFromParts(Box<TimestampFromParts>),
1079    TimestampTzFromParts(Box<TimestampTzFromParts>),
1080    Corr(Box<Corr>),
1081    WidthBucket(Box<WidthBucket>),
1082    CovarSamp(Box<CovarSamp>),
1083    CovarPop(Box<CovarPop>),
1084    Week(Box<Week>),
1085    XMLElement(Box<XMLElement>),
1086    XMLGet(Box<XMLGet>),
1087    XMLTable(Box<XMLTable>),
1088    XMLKeyValueOption(Box<XMLKeyValueOption>),
1089    Zipf(Box<Zipf>),
1090    Merge(Box<Merge>),
1091    When(Box<When>),
1092    Whens(Box<Whens>),
1093    NextValueFor(Box<NextValueFor>),
1094    /// RETURN statement (DuckDB stored procedures)
1095    ReturnStmt(Box<Expression>),
1096}
1097
1098impl Expression {
1099    /// Returns `true` if this expression is a valid top-level SQL statement.
1100    ///
1101    /// Bare expressions like identifiers, literals, and function calls are not
1102    /// valid statements. This is used by `validate()` to reject inputs like
1103    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1104    /// plus the bare identifier `doo`.
1105    pub fn is_statement(&self) -> bool {
1106        match self {
1107            // Queries
1108            Expression::Select(_)
1109            | Expression::Union(_)
1110            | Expression::Intersect(_)
1111            | Expression::Except(_)
1112            | Expression::Subquery(_)
1113            | Expression::Values(_)
1114            | Expression::PipeOperator(_)
1115
1116            // DML
1117            | Expression::Insert(_)
1118            | Expression::Update(_)
1119            | Expression::Delete(_)
1120            | Expression::Copy(_)
1121            | Expression::Put(_)
1122            | Expression::Merge(_)
1123
1124            // DDL
1125            | Expression::CreateTable(_)
1126            | Expression::DropTable(_)
1127            | Expression::AlterTable(_)
1128            | Expression::CreateIndex(_)
1129            | Expression::DropIndex(_)
1130            | Expression::CreateView(_)
1131            | Expression::DropView(_)
1132            | Expression::AlterView(_)
1133            | Expression::AlterIndex(_)
1134            | Expression::Truncate(_)
1135            | Expression::TruncateTable(_)
1136            | Expression::CreateSchema(_)
1137            | Expression::DropSchema(_)
1138            | Expression::DropNamespace(_)
1139            | Expression::CreateDatabase(_)
1140            | Expression::DropDatabase(_)
1141            | Expression::CreateFunction(_)
1142            | Expression::DropFunction(_)
1143            | Expression::CreateProcedure(_)
1144            | Expression::DropProcedure(_)
1145            | Expression::CreateSequence(_)
1146            | Expression::DropSequence(_)
1147            | Expression::AlterSequence(_)
1148            | Expression::CreateTrigger(_)
1149            | Expression::DropTrigger(_)
1150            | Expression::CreateType(_)
1151            | Expression::DropType(_)
1152            | Expression::Comment(_)
1153
1154            // Session/Transaction/Control
1155            | Expression::Use(_)
1156            | Expression::Set(_)
1157            | Expression::SetStatement(_)
1158            | Expression::Transaction(_)
1159            | Expression::Commit(_)
1160            | Expression::Rollback(_)
1161            | Expression::Grant(_)
1162            | Expression::Revoke(_)
1163            | Expression::Cache(_)
1164            | Expression::Uncache(_)
1165            | Expression::LoadData(_)
1166            | Expression::Pragma(_)
1167            | Expression::Describe(_)
1168            | Expression::Show(_)
1169            | Expression::Kill(_)
1170            | Expression::Execute(_)
1171            | Expression::Declare(_)
1172            | Expression::Refresh(_)
1173            | Expression::AlterSession(_)
1174            | Expression::LockingStatement(_)
1175
1176            // Analyze
1177            | Expression::Analyze(_)
1178            | Expression::AnalyzeStatistics(_)
1179            | Expression::AnalyzeHistogram(_)
1180            | Expression::AnalyzeSample(_)
1181            | Expression::AnalyzeListChainedRows(_)
1182            | Expression::AnalyzeDelete(_)
1183
1184            // Attach/Detach/Install/Summarize
1185            | Expression::Attach(_)
1186            | Expression::Detach(_)
1187            | Expression::Install(_)
1188            | Expression::Summarize(_)
1189
1190            // Pivot at statement level
1191            | Expression::Pivot(_)
1192            | Expression::Unpivot(_)
1193
1194            // Command (raw/unparsed statements)
1195            | Expression::Command(_)
1196            | Expression::Raw(_)
1197
1198            // Return statement
1199            | Expression::ReturnStmt(_) => true,
1200
1201            // Annotated wraps another expression with comments — check inner
1202            Expression::Annotated(a) => a.this.is_statement(),
1203
1204            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1205            Expression::Alias(a) => a.this.is_statement(),
1206
1207            // Everything else (identifiers, literals, operators, functions, etc.)
1208            _ => false,
1209        }
1210    }
1211
1212    /// Create a literal number expression from an integer.
1213    pub fn number(n: i64) -> Self {
1214        Expression::Literal(Literal::Number(n.to_string()))
1215    }
1216
1217    /// Create a single-quoted literal string expression.
1218    pub fn string(s: impl Into<String>) -> Self {
1219        Expression::Literal(Literal::String(s.into()))
1220    }
1221
1222    /// Create a literal number expression from a float.
1223    pub fn float(f: f64) -> Self {
1224        Expression::Literal(Literal::Number(f.to_string()))
1225    }
1226
1227    /// Create an unqualified column reference (e.g. `name`).
1228    pub fn column(name: impl Into<String>) -> Self {
1229        Expression::Column(Column {
1230            name: Identifier::new(name),
1231            table: None,
1232            join_mark: false,
1233            trailing_comments: Vec::new(),
1234        })
1235    }
1236
1237    /// Create a qualified column reference (`table.column`).
1238    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1239        Expression::Column(Column {
1240            name: Identifier::new(column),
1241            table: Some(Identifier::new(table)),
1242            join_mark: false,
1243            trailing_comments: Vec::new(),
1244        })
1245    }
1246
1247    /// Create a bare identifier expression (not a column reference).
1248    pub fn identifier(name: impl Into<String>) -> Self {
1249        Expression::Identifier(Identifier::new(name))
1250    }
1251
1252    /// Create a NULL expression
1253    pub fn null() -> Self {
1254        Expression::Null(Null)
1255    }
1256
1257    /// Create a TRUE expression
1258    pub fn true_() -> Self {
1259        Expression::Boolean(BooleanLiteral { value: true })
1260    }
1261
1262    /// Create a FALSE expression
1263    pub fn false_() -> Self {
1264        Expression::Boolean(BooleanLiteral { value: false })
1265    }
1266
1267    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1268    pub fn star() -> Self {
1269        Expression::Star(Star {
1270            table: None,
1271            except: None,
1272            replace: None,
1273            rename: None,
1274            trailing_comments: Vec::new(),
1275        })
1276    }
1277
1278    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1279    pub fn alias(self, name: impl Into<String>) -> Self {
1280        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1281    }
1282
1283    /// Check if this is a SELECT expression
1284    pub fn is_select(&self) -> bool {
1285        matches!(self, Expression::Select(_))
1286    }
1287
1288    /// Try to get as a Select
1289    pub fn as_select(&self) -> Option<&Select> {
1290        match self {
1291            Expression::Select(s) => Some(s),
1292            _ => None,
1293        }
1294    }
1295
1296    /// Try to get as a mutable Select
1297    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1298        match self {
1299            Expression::Select(s) => Some(s),
1300            _ => None,
1301        }
1302    }
1303
1304    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1305    ///
1306    /// Returns an empty string if generation fails. For dialect-specific output,
1307    /// use [`sql_for()`](Self::sql_for) instead.
1308    pub fn sql(&self) -> String {
1309        crate::generator::Generator::sql(self).unwrap_or_default()
1310    }
1311
1312    /// Generate a SQL string for this expression targeting a specific dialect.
1313    ///
1314    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1315    /// syntax variations) are applied automatically.  Returns an empty string if
1316    /// generation fails.
1317    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1318        crate::generate(self, dialect).unwrap_or_default()
1319    }
1320
1321}
1322
1323impl fmt::Display for Expression {
1324    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1325        // Basic display - full SQL generation is in generator module
1326        match self {
1327            Expression::Literal(lit) => write!(f, "{}", lit),
1328            Expression::Identifier(id) => write!(f, "{}", id),
1329            Expression::Column(col) => write!(f, "{}", col),
1330            Expression::Star(_) => write!(f, "*"),
1331            Expression::Null(_) => write!(f, "NULL"),
1332            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1333            Expression::Select(_) => write!(f, "SELECT ..."),
1334            _ => write!(f, "{:?}", self),
1335        }
1336    }
1337}
1338
1339/// Represent a SQL literal value.
1340///
1341/// Numeric values are stored as their original text representation (not parsed
1342/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1343/// preserved across round-trips.
1344///
1345/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1346/// strings, raw strings, etc.) each have a dedicated variant so that the
1347/// generator can emit them with the correct syntax.
1348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1349#[cfg_attr(feature = "bindings", derive(TS))]
1350#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1351pub enum Literal {
1352    /// Single-quoted string literal: `'hello'`
1353    String(String),
1354    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1355    Number(String),
1356    /// Hex string literal: `X'FF'`
1357    HexString(String),
1358    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1359    HexNumber(String),
1360    BitString(String),
1361    /// Byte string: b"..." (BigQuery style)
1362    ByteString(String),
1363    /// National string: N'abc'
1364    NationalString(String),
1365    /// DATE literal: DATE '2024-01-15'
1366    Date(String),
1367    /// TIME literal: TIME '10:30:00'
1368    Time(String),
1369    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1370    Timestamp(String),
1371    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1372    Datetime(String),
1373    /// Triple-quoted string: """...""" or '''...'''
1374    /// Contains (content, quote_char) where quote_char is '"' or '\''
1375    TripleQuotedString(String, char),
1376    /// Escape string: E'...' (PostgreSQL)
1377    EscapeString(String),
1378    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1379    DollarString(String),
1380    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1381    /// In raw strings, backslashes are literal and not escape characters.
1382    /// When converting to a regular string, backslashes must be doubled.
1383    RawString(String),
1384}
1385
1386impl fmt::Display for Literal {
1387    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1388        match self {
1389            Literal::String(s) => write!(f, "'{}'", s),
1390            Literal::Number(n) => write!(f, "{}", n),
1391            Literal::HexString(h) => write!(f, "X'{}'", h),
1392            Literal::HexNumber(h) => write!(f, "0x{}", h),
1393            Literal::BitString(b) => write!(f, "B'{}'", b),
1394            Literal::ByteString(b) => write!(f, "b'{}'", b),
1395            Literal::NationalString(s) => write!(f, "N'{}'", s),
1396            Literal::Date(d) => write!(f, "DATE '{}'", d),
1397            Literal::Time(t) => write!(f, "TIME '{}'", t),
1398            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1399            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1400            Literal::TripleQuotedString(s, q) => {
1401                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1402            }
1403            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1404            Literal::DollarString(s) => write!(f, "$${}$$", s),
1405            Literal::RawString(s) => write!(f, "r'{}'", s),
1406        }
1407    }
1408}
1409
1410/// Boolean literal
1411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1412#[cfg_attr(feature = "bindings", derive(TS))]
1413pub struct BooleanLiteral {
1414    pub value: bool,
1415}
1416
1417/// NULL literal
1418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1419#[cfg_attr(feature = "bindings", derive(TS))]
1420pub struct Null;
1421
1422/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1423///
1424/// The `quoted` flag indicates whether the identifier was originally delimited
1425/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1426/// dialect). The generator uses this flag to decide whether to emit quoting
1427/// characters.
1428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1429#[cfg_attr(feature = "bindings", derive(TS))]
1430pub struct Identifier {
1431    /// The raw text of the identifier, without any quoting characters.
1432    pub name: String,
1433    /// Whether the identifier was quoted in the source SQL.
1434    pub quoted: bool,
1435    #[serde(default)]
1436    pub trailing_comments: Vec<String>,
1437}
1438
1439impl Identifier {
1440    pub fn new(name: impl Into<String>) -> Self {
1441        Self {
1442            name: name.into(),
1443            quoted: false,
1444            trailing_comments: Vec::new(),
1445        }
1446    }
1447
1448    pub fn quoted(name: impl Into<String>) -> Self {
1449        Self {
1450            name: name.into(),
1451            quoted: true,
1452            trailing_comments: Vec::new(),
1453        }
1454    }
1455
1456    pub fn empty() -> Self {
1457        Self {
1458            name: String::new(),
1459            quoted: false,
1460            trailing_comments: Vec::new(),
1461        }
1462    }
1463
1464    pub fn is_empty(&self) -> bool {
1465        self.name.is_empty()
1466    }
1467}
1468
1469impl fmt::Display for Identifier {
1470    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1471        if self.quoted {
1472            write!(f, "\"{}\"", self.name)
1473        } else {
1474            write!(f, "{}", self.name)
1475        }
1476    }
1477}
1478
1479/// Represent a column reference, optionally qualified by a table name.
1480///
1481/// Renders as `name` when unqualified, or `table.name` when qualified.
1482/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1483/// convenient construction.
1484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1485#[cfg_attr(feature = "bindings", derive(TS))]
1486pub struct Column {
1487    /// The column name.
1488    pub name: Identifier,
1489    /// Optional table qualifier (e.g. `t` in `t.col`).
1490    pub table: Option<Identifier>,
1491    /// Oracle-style join marker (+) for outer joins
1492    #[serde(default)]
1493    pub join_mark: bool,
1494    /// Trailing comments that appeared after this column reference
1495    #[serde(default)]
1496    pub trailing_comments: Vec<String>,
1497}
1498
1499impl fmt::Display for Column {
1500    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1501        if let Some(table) = &self.table {
1502            write!(f, "{}.{}", table, self.name)
1503        } else {
1504            write!(f, "{}", self.name)
1505        }
1506    }
1507}
1508
1509/// Represent a table reference with optional schema and catalog qualifiers.
1510///
1511/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1512/// which qualifiers are present. Supports aliases, column alias lists,
1513/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1514/// several other dialect-specific extensions.
1515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1516#[cfg_attr(feature = "bindings", derive(TS))]
1517pub struct TableRef {
1518    /// The unqualified table name.
1519    pub name: Identifier,
1520    /// Optional schema qualifier (e.g. `public` in `public.users`).
1521    pub schema: Option<Identifier>,
1522    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
1523    pub catalog: Option<Identifier>,
1524    /// Optional table alias (e.g. `t` in `FROM users AS t`).
1525    pub alias: Option<Identifier>,
1526    /// Whether AS keyword was explicitly used for the alias
1527    #[serde(default)]
1528    pub alias_explicit_as: bool,
1529    /// Column aliases for table alias: AS t(c1, c2)
1530    #[serde(default)]
1531    pub column_aliases: Vec<Identifier>,
1532    /// Trailing comments that appeared after this table reference
1533    #[serde(default)]
1534    pub trailing_comments: Vec<String>,
1535    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
1536    #[serde(default)]
1537    pub when: Option<Box<HistoricalData>>,
1538    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
1539    #[serde(default)]
1540    pub only: bool,
1541    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
1542    #[serde(default)]
1543    pub final_: bool,
1544    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
1545    #[serde(default, skip_serializing_if = "Option::is_none")]
1546    pub table_sample: Option<Box<Sample>>,
1547    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
1548    #[serde(default)]
1549    pub hints: Vec<Expression>,
1550    /// TSQL: FOR SYSTEM_TIME temporal clause
1551    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
1552    #[serde(default, skip_serializing_if = "Option::is_none")]
1553    pub system_time: Option<String>,
1554    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
1555    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1556    pub partitions: Vec<Identifier>,
1557    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
1558    /// When set, this is used instead of the name field
1559    #[serde(default, skip_serializing_if = "Option::is_none")]
1560    pub identifier_func: Option<Box<Expression>>,
1561    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
1562    #[serde(default, skip_serializing_if = "Option::is_none")]
1563    pub changes: Option<Box<Changes>>,
1564    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
1565    #[serde(default, skip_serializing_if = "Option::is_none")]
1566    pub version: Option<Box<Version>>,
1567}
1568
1569impl TableRef {
1570    pub fn new(name: impl Into<String>) -> Self {
1571        Self {
1572            name: Identifier::new(name),
1573            schema: None,
1574            catalog: None,
1575            alias: None,
1576            alias_explicit_as: false,
1577            column_aliases: Vec::new(),
1578            trailing_comments: Vec::new(),
1579            when: None,
1580            only: false,
1581            final_: false,
1582            table_sample: None,
1583            hints: Vec::new(),
1584            system_time: None,
1585            partitions: Vec::new(),
1586            identifier_func: None,
1587            changes: None,
1588            version: None,
1589        }
1590    }
1591
1592    /// Create with a schema qualifier.
1593    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
1594        let mut t = Self::new(name);
1595        t.schema = Some(Identifier::new(schema));
1596        t
1597    }
1598
1599    /// Create with catalog and schema qualifiers.
1600    pub fn new_with_catalog(
1601        name: impl Into<String>,
1602        schema: impl Into<String>,
1603        catalog: impl Into<String>,
1604    ) -> Self {
1605        let mut t = Self::new(name);
1606        t.schema = Some(Identifier::new(schema));
1607        t.catalog = Some(Identifier::new(catalog));
1608        t
1609    }
1610
1611    /// Create from an Identifier, preserving the quoted flag
1612    pub fn from_identifier(name: Identifier) -> Self {
1613        Self {
1614            name,
1615            schema: None,
1616            catalog: None,
1617            alias: None,
1618            alias_explicit_as: false,
1619            column_aliases: Vec::new(),
1620            trailing_comments: Vec::new(),
1621            when: None,
1622            only: false,
1623            final_: false,
1624            table_sample: None,
1625            hints: Vec::new(),
1626            system_time: None,
1627            partitions: Vec::new(),
1628            identifier_func: None,
1629            changes: None,
1630            version: None,
1631        }
1632    }
1633
1634    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
1635        self.alias = Some(Identifier::new(alias));
1636        self
1637    }
1638
1639    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
1640        self.schema = Some(Identifier::new(schema));
1641        self
1642    }
1643}
1644
1645/// Represent a wildcard star expression (`*`, `table.*`).
1646///
1647/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
1648/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
1649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1650#[cfg_attr(feature = "bindings", derive(TS))]
1651pub struct Star {
1652    /// Optional table qualifier (e.g. `t` in `t.*`).
1653    pub table: Option<Identifier>,
1654    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
1655    pub except: Option<Vec<Identifier>>,
1656    /// REPLACE expressions (BigQuery, Snowflake)
1657    pub replace: Option<Vec<Alias>>,
1658    /// RENAME columns (Snowflake)
1659    pub rename: Option<Vec<(Identifier, Identifier)>>,
1660    /// Trailing comments that appeared after the star
1661    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1662    pub trailing_comments: Vec<String>,
1663}
1664
1665/// Represent a complete SELECT statement.
1666///
1667/// This is the most feature-rich AST node, covering the full surface area of
1668/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
1669/// `Vec` are omitted from the generated SQL when absent.
1670///
1671/// # Key Fields
1672///
1673/// - `expressions` -- the select-list (columns, `*`, computed expressions).
1674/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
1675/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
1676/// - `where_clause` -- the WHERE predicate.
1677/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
1678/// - `having` -- HAVING predicate.
1679/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
1680/// - `limit` / `offset` / `fetch` -- result set limiting.
1681/// - `with` -- Common Table Expressions (CTEs).
1682/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
1683/// - `windows` -- named window definitions (WINDOW w AS ...).
1684///
1685/// Dialect-specific extensions are supported via fields like `prewhere`
1686/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
1687/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
1688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1689#[cfg_attr(feature = "bindings", derive(TS))]
1690pub struct Select {
1691    /// The select-list: columns, expressions, aliases, and wildcards.
1692    pub expressions: Vec<Expression>,
1693    /// The FROM clause, containing one or more table sources.
1694    pub from: Option<From>,
1695    /// JOIN clauses applied after the FROM source.
1696    pub joins: Vec<Join>,
1697    pub lateral_views: Vec<LateralView>,
1698    /// ClickHouse PREWHERE clause
1699    #[serde(default, skip_serializing_if = "Option::is_none")]
1700    pub prewhere: Option<Expression>,
1701    pub where_clause: Option<Where>,
1702    pub group_by: Option<GroupBy>,
1703    pub having: Option<Having>,
1704    pub qualify: Option<Qualify>,
1705    pub order_by: Option<OrderBy>,
1706    pub distribute_by: Option<DistributeBy>,
1707    pub cluster_by: Option<ClusterBy>,
1708    pub sort_by: Option<SortBy>,
1709    pub limit: Option<Limit>,
1710    pub offset: Option<Offset>,
1711    /// ClickHouse LIMIT BY clause expressions
1712    #[serde(default, skip_serializing_if = "Option::is_none")]
1713    pub limit_by: Option<Vec<Expression>>,
1714    pub fetch: Option<Fetch>,
1715    pub distinct: bool,
1716    pub distinct_on: Option<Vec<Expression>>,
1717    pub top: Option<Top>,
1718    pub with: Option<With>,
1719    pub sample: Option<Sample>,
1720    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
1721    #[serde(default, skip_serializing_if = "Option::is_none")]
1722    pub settings: Option<Vec<Expression>>,
1723    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
1724    #[serde(default, skip_serializing_if = "Option::is_none")]
1725    pub format: Option<Expression>,
1726    pub windows: Option<Vec<NamedWindow>>,
1727    pub hint: Option<Hint>,
1728    /// Oracle CONNECT BY clause for hierarchical queries
1729    pub connect: Option<Connect>,
1730    /// SELECT ... INTO table_name for creating tables
1731    pub into: Option<SelectInto>,
1732    /// FOR UPDATE/SHARE locking clauses
1733    #[serde(default)]
1734    pub locks: Vec<Lock>,
1735    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
1736    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1737    pub for_xml: Vec<Expression>,
1738    /// Leading comments before the statement
1739    #[serde(default)]
1740    pub leading_comments: Vec<String>,
1741    /// Comments that appear after SELECT keyword (before expressions)
1742    /// e.g., SELECT /*hint*/ col -> post_select_comments: ["/*hint*/"]
1743    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1744    pub post_select_comments: Vec<String>,
1745    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
1746    #[serde(default, skip_serializing_if = "Option::is_none")]
1747    pub kind: Option<String>,
1748    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
1749    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1750    pub operation_modifiers: Vec<String>,
1751    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
1752    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1753    pub qualify_after_window: bool,
1754    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
1755    #[serde(default, skip_serializing_if = "Option::is_none")]
1756    pub option: Option<String>,
1757}
1758
1759impl Select {
1760    pub fn new() -> Self {
1761        Self {
1762            expressions: Vec::new(),
1763            from: None,
1764            joins: Vec::new(),
1765            lateral_views: Vec::new(),
1766            prewhere: None,
1767            where_clause: None,
1768            group_by: None,
1769            having: None,
1770            qualify: None,
1771            order_by: None,
1772            distribute_by: None,
1773            cluster_by: None,
1774            sort_by: None,
1775            limit: None,
1776            offset: None,
1777            limit_by: None,
1778            fetch: None,
1779            distinct: false,
1780            distinct_on: None,
1781            top: None,
1782            with: None,
1783            sample: None,
1784            settings: None,
1785            format: None,
1786            windows: None,
1787            hint: None,
1788            connect: None,
1789            into: None,
1790            locks: Vec::new(),
1791            for_xml: Vec::new(),
1792            leading_comments: Vec::new(),
1793            post_select_comments: Vec::new(),
1794            kind: None,
1795            operation_modifiers: Vec::new(),
1796            qualify_after_window: false,
1797            option: None,
1798        }
1799    }
1800
1801    /// Add a column to select
1802    pub fn column(mut self, expr: Expression) -> Self {
1803        self.expressions.push(expr);
1804        self
1805    }
1806
1807    /// Set the FROM clause
1808    pub fn from(mut self, table: Expression) -> Self {
1809        self.from = Some(From {
1810            expressions: vec![table],
1811        });
1812        self
1813    }
1814
1815    /// Add a WHERE clause
1816    pub fn where_(mut self, condition: Expression) -> Self {
1817        self.where_clause = Some(Where { this: condition });
1818        self
1819    }
1820
1821    /// Set DISTINCT
1822    pub fn distinct(mut self) -> Self {
1823        self.distinct = true;
1824        self
1825    }
1826
1827    /// Add a JOIN
1828    pub fn join(mut self, join: Join) -> Self {
1829        self.joins.push(join);
1830        self
1831    }
1832
1833    /// Set ORDER BY
1834    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
1835        self.order_by = Some(OrderBy { expressions, siblings: false });
1836        self
1837    }
1838
1839    /// Set LIMIT
1840    pub fn limit(mut self, n: Expression) -> Self {
1841        self.limit = Some(Limit { this: n, percent: false });
1842        self
1843    }
1844
1845    /// Set OFFSET
1846    pub fn offset(mut self, n: Expression) -> Self {
1847        self.offset = Some(Offset { this: n, rows: None });
1848        self
1849    }
1850}
1851
1852impl Default for Select {
1853    fn default() -> Self {
1854        Self::new()
1855    }
1856}
1857
1858/// Represent a UNION set operation between two query expressions.
1859///
1860/// When `all` is true, duplicate rows are preserved (UNION ALL).
1861/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
1862/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
1863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1864#[cfg_attr(feature = "bindings", derive(TS))]
1865pub struct Union {
1866    /// The left-hand query operand.
1867    pub left: Expression,
1868    /// The right-hand query operand.
1869    pub right: Expression,
1870    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
1871    pub all: bool,
1872    /// Whether DISTINCT was explicitly specified
1873    #[serde(default)]
1874    pub distinct: bool,
1875    /// Optional WITH clause
1876    pub with: Option<With>,
1877    /// ORDER BY applied to entire UNION result
1878    pub order_by: Option<OrderBy>,
1879    /// LIMIT applied to entire UNION result
1880    pub limit: Option<Box<Expression>>,
1881    /// OFFSET applied to entire UNION result
1882    pub offset: Option<Box<Expression>>,
1883    /// DISTRIBUTE BY clause (Hive/Spark)
1884    #[serde(default, skip_serializing_if = "Option::is_none")]
1885    pub distribute_by: Option<DistributeBy>,
1886    /// SORT BY clause (Hive/Spark)
1887    #[serde(default, skip_serializing_if = "Option::is_none")]
1888    pub sort_by: Option<SortBy>,
1889    /// CLUSTER BY clause (Hive/Spark)
1890    #[serde(default, skip_serializing_if = "Option::is_none")]
1891    pub cluster_by: Option<ClusterBy>,
1892    /// DuckDB BY NAME modifier
1893    #[serde(default)]
1894    pub by_name: bool,
1895    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1896    #[serde(default, skip_serializing_if = "Option::is_none")]
1897    pub side: Option<String>,
1898    /// BigQuery: Set operation kind (INNER)
1899    #[serde(default, skip_serializing_if = "Option::is_none")]
1900    pub kind: Option<String>,
1901    /// BigQuery: CORRESPONDING modifier
1902    #[serde(default)]
1903    pub corresponding: bool,
1904    /// BigQuery: STRICT modifier (before CORRESPONDING)
1905    #[serde(default)]
1906    pub strict: bool,
1907    /// BigQuery: BY (columns) after CORRESPONDING
1908    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1909    pub on_columns: Vec<Expression>,
1910}
1911
1912/// Represent an INTERSECT set operation between two query expressions.
1913///
1914/// Returns only rows that appear in both operands. When `all` is true,
1915/// duplicates are preserved according to their multiplicity.
1916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1917#[cfg_attr(feature = "bindings", derive(TS))]
1918pub struct Intersect {
1919    /// The left-hand query operand.
1920    pub left: Expression,
1921    /// The right-hand query operand.
1922    pub right: Expression,
1923    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
1924    pub all: bool,
1925    /// Whether DISTINCT was explicitly specified
1926    #[serde(default)]
1927    pub distinct: bool,
1928    /// Optional WITH clause
1929    pub with: Option<With>,
1930    /// ORDER BY applied to entire INTERSECT result
1931    pub order_by: Option<OrderBy>,
1932    /// LIMIT applied to entire INTERSECT result
1933    pub limit: Option<Box<Expression>>,
1934    /// OFFSET applied to entire INTERSECT result
1935    pub offset: Option<Box<Expression>>,
1936    /// DISTRIBUTE BY clause (Hive/Spark)
1937    #[serde(default, skip_serializing_if = "Option::is_none")]
1938    pub distribute_by: Option<DistributeBy>,
1939    /// SORT BY clause (Hive/Spark)
1940    #[serde(default, skip_serializing_if = "Option::is_none")]
1941    pub sort_by: Option<SortBy>,
1942    /// CLUSTER BY clause (Hive/Spark)
1943    #[serde(default, skip_serializing_if = "Option::is_none")]
1944    pub cluster_by: Option<ClusterBy>,
1945    /// DuckDB BY NAME modifier
1946    #[serde(default)]
1947    pub by_name: bool,
1948    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1949    #[serde(default, skip_serializing_if = "Option::is_none")]
1950    pub side: Option<String>,
1951    /// BigQuery: Set operation kind (INNER)
1952    #[serde(default, skip_serializing_if = "Option::is_none")]
1953    pub kind: Option<String>,
1954    /// BigQuery: CORRESPONDING modifier
1955    #[serde(default)]
1956    pub corresponding: bool,
1957    /// BigQuery: STRICT modifier (before CORRESPONDING)
1958    #[serde(default)]
1959    pub strict: bool,
1960    /// BigQuery: BY (columns) after CORRESPONDING
1961    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1962    pub on_columns: Vec<Expression>,
1963}
1964
1965/// Represent an EXCEPT (MINUS) set operation between two query expressions.
1966///
1967/// Returns rows from the left operand that do not appear in the right operand.
1968/// When `all` is true, duplicates are subtracted according to their multiplicity.
1969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1970#[cfg_attr(feature = "bindings", derive(TS))]
1971pub struct Except {
1972    /// The left-hand query operand.
1973    pub left: Expression,
1974    /// The right-hand query operand (rows to subtract).
1975    pub right: Expression,
1976    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
1977    pub all: bool,
1978    /// Whether DISTINCT was explicitly specified
1979    #[serde(default)]
1980    pub distinct: bool,
1981    /// Optional WITH clause
1982    pub with: Option<With>,
1983    /// ORDER BY applied to entire EXCEPT result
1984    pub order_by: Option<OrderBy>,
1985    /// LIMIT applied to entire EXCEPT result
1986    pub limit: Option<Box<Expression>>,
1987    /// OFFSET applied to entire EXCEPT result
1988    pub offset: Option<Box<Expression>>,
1989    /// DISTRIBUTE BY clause (Hive/Spark)
1990    #[serde(default, skip_serializing_if = "Option::is_none")]
1991    pub distribute_by: Option<DistributeBy>,
1992    /// SORT BY clause (Hive/Spark)
1993    #[serde(default, skip_serializing_if = "Option::is_none")]
1994    pub sort_by: Option<SortBy>,
1995    /// CLUSTER BY clause (Hive/Spark)
1996    #[serde(default, skip_serializing_if = "Option::is_none")]
1997    pub cluster_by: Option<ClusterBy>,
1998    /// DuckDB BY NAME modifier
1999    #[serde(default)]
2000    pub by_name: bool,
2001    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2002    #[serde(default, skip_serializing_if = "Option::is_none")]
2003    pub side: Option<String>,
2004    /// BigQuery: Set operation kind (INNER)
2005    #[serde(default, skip_serializing_if = "Option::is_none")]
2006    pub kind: Option<String>,
2007    /// BigQuery: CORRESPONDING modifier
2008    #[serde(default)]
2009    pub corresponding: bool,
2010    /// BigQuery: STRICT modifier (before CORRESPONDING)
2011    #[serde(default)]
2012    pub strict: bool,
2013    /// BigQuery: BY (columns) after CORRESPONDING
2014    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2015    pub on_columns: Vec<Expression>,
2016}
2017
2018/// INTO clause for SELECT INTO statements
2019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2020#[cfg_attr(feature = "bindings", derive(TS))]
2021pub struct SelectInto {
2022    /// Target table or variable (used when single target)
2023    pub this: Expression,
2024    /// Whether TEMPORARY keyword was used
2025    #[serde(default)]
2026    pub temporary: bool,
2027    /// Whether UNLOGGED keyword was used (PostgreSQL)
2028    #[serde(default)]
2029    pub unlogged: bool,
2030    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2031    #[serde(default)]
2032    pub bulk_collect: bool,
2033    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2034    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2035    pub expressions: Vec<Expression>,
2036}
2037
2038/// Represent a parenthesized subquery expression.
2039///
2040/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2041/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2042/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2043/// modifiers are rendered inside or outside the parentheses.
2044///
2045/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2046/// scalar subqueries in select-lists, and derived tables.
2047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2048#[cfg_attr(feature = "bindings", derive(TS))]
2049pub struct Subquery {
2050    /// The inner query expression.
2051    pub this: Expression,
2052    /// Optional alias for the derived table.
2053    pub alias: Option<Identifier>,
2054    /// Optional column aliases: AS t(c1, c2)
2055    pub column_aliases: Vec<Identifier>,
2056    /// ORDER BY clause (for parenthesized queries)
2057    pub order_by: Option<OrderBy>,
2058    /// LIMIT clause
2059    pub limit: Option<Limit>,
2060    /// OFFSET clause
2061    pub offset: Option<Offset>,
2062    /// DISTRIBUTE BY clause (Hive/Spark)
2063    #[serde(default, skip_serializing_if = "Option::is_none")]
2064    pub distribute_by: Option<DistributeBy>,
2065    /// SORT BY clause (Hive/Spark)
2066    #[serde(default, skip_serializing_if = "Option::is_none")]
2067    pub sort_by: Option<SortBy>,
2068    /// CLUSTER BY clause (Hive/Spark)
2069    #[serde(default, skip_serializing_if = "Option::is_none")]
2070    pub cluster_by: Option<ClusterBy>,
2071    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2072    #[serde(default)]
2073    pub lateral: bool,
2074    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2075    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2076    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2077    #[serde(default)]
2078    pub modifiers_inside: bool,
2079    /// Trailing comments after the closing paren
2080    #[serde(default)]
2081    pub trailing_comments: Vec<String>,
2082}
2083
2084/// Pipe operator expression: query |> transform
2085///
2086/// Used in DataFusion and BigQuery pipe syntax:
2087///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2089#[cfg_attr(feature = "bindings", derive(TS))]
2090pub struct PipeOperator {
2091    /// The input query/expression (left side of |>)
2092    pub this: Expression,
2093    /// The piped operation (right side of |>)
2094    pub expression: Expression,
2095}
2096
2097/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2099#[cfg_attr(feature = "bindings", derive(TS))]
2100pub struct Values {
2101    /// The rows of values
2102    pub expressions: Vec<Tuple>,
2103    /// Optional alias for the table
2104    pub alias: Option<Identifier>,
2105    /// Optional column aliases: AS t(c1, c2)
2106    pub column_aliases: Vec<Identifier>,
2107}
2108
2109/// PIVOT operation - supports both standard and DuckDB simplified syntax
2110///
2111/// Standard syntax (in FROM clause):
2112///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2113///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2114///
2115/// DuckDB simplified syntax (statement-level):
2116///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2117///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2119#[cfg_attr(feature = "bindings", derive(TS))]
2120pub struct Pivot {
2121    /// Source table/expression
2122    pub this: Expression,
2123    /// For standard PIVOT: the aggregation function(s) (first is primary)
2124    /// For DuckDB simplified: unused (use `using` instead)
2125    #[serde(default)]
2126    pub expressions: Vec<Expression>,
2127    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2128    #[serde(default)]
2129    pub fields: Vec<Expression>,
2130    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2131    #[serde(default)]
2132    pub using: Vec<Expression>,
2133    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2134    #[serde(default)]
2135    pub group: Option<Box<Expression>>,
2136    /// Whether this is an UNPIVOT (vs PIVOT)
2137    #[serde(default)]
2138    pub unpivot: bool,
2139    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2140    #[serde(default)]
2141    pub into: Option<Box<Expression>>,
2142    /// Optional alias
2143    #[serde(default)]
2144    pub alias: Option<Identifier>,
2145    /// Include/exclude nulls (for UNPIVOT)
2146    #[serde(default)]
2147    pub include_nulls: Option<bool>,
2148    /// Default on null value (Snowflake)
2149    #[serde(default)]
2150    pub default_on_null: Option<Box<Expression>>,
2151    /// WITH clause (CTEs)
2152    #[serde(default, skip_serializing_if = "Option::is_none")]
2153    pub with: Option<With>,
2154}
2155
2156/// UNPIVOT operation
2157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2158#[cfg_attr(feature = "bindings", derive(TS))]
2159pub struct Unpivot {
2160    pub this: Expression,
2161    pub value_column: Identifier,
2162    pub name_column: Identifier,
2163    pub columns: Vec<Expression>,
2164    pub alias: Option<Identifier>,
2165    /// Whether the value_column was parenthesized in the original SQL
2166    #[serde(default)]
2167    pub value_column_parenthesized: bool,
2168    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2169    #[serde(default)]
2170    pub include_nulls: Option<bool>,
2171    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2172    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2173    pub extra_value_columns: Vec<Identifier>,
2174}
2175
2176/// PIVOT alias for aliasing pivot expressions
2177/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2179#[cfg_attr(feature = "bindings", derive(TS))]
2180pub struct PivotAlias {
2181    pub this: Expression,
2182    pub alias: Expression,
2183}
2184
2185/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2187#[cfg_attr(feature = "bindings", derive(TS))]
2188pub struct PreWhere {
2189    pub this: Expression,
2190}
2191
2192/// STREAM definition (Snowflake) - for change data capture
2193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2194#[cfg_attr(feature = "bindings", derive(TS))]
2195pub struct Stream {
2196    pub this: Expression,
2197    #[serde(skip_serializing_if = "Option::is_none")]
2198    pub on: Option<Expression>,
2199    #[serde(skip_serializing_if = "Option::is_none")]
2200    pub show_initial_rows: Option<bool>,
2201}
2202
2203/// USING DATA clause for data import statements
2204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2205#[cfg_attr(feature = "bindings", derive(TS))]
2206pub struct UsingData {
2207    pub this: Expression,
2208}
2209
2210/// XML Namespace declaration
2211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2212#[cfg_attr(feature = "bindings", derive(TS))]
2213pub struct XmlNamespace {
2214    pub this: Expression,
2215    #[serde(skip_serializing_if = "Option::is_none")]
2216    pub alias: Option<Identifier>,
2217}
2218
2219/// ROW FORMAT clause for Hive/Spark
2220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2221#[cfg_attr(feature = "bindings", derive(TS))]
2222pub struct RowFormat {
2223    pub delimited: bool,
2224    pub fields_terminated_by: Option<String>,
2225    pub collection_items_terminated_by: Option<String>,
2226    pub map_keys_terminated_by: Option<String>,
2227    pub lines_terminated_by: Option<String>,
2228    pub null_defined_as: Option<String>,
2229}
2230
2231/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2233#[cfg_attr(feature = "bindings", derive(TS))]
2234pub struct DirectoryInsert {
2235    pub local: bool,
2236    pub path: String,
2237    pub row_format: Option<RowFormat>,
2238    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2239    #[serde(default)]
2240    pub stored_as: Option<String>,
2241}
2242
2243/// INSERT statement
2244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2245#[cfg_attr(feature = "bindings", derive(TS))]
2246pub struct Insert {
2247    pub table: TableRef,
2248    pub columns: Vec<Identifier>,
2249    pub values: Vec<Vec<Expression>>,
2250    pub query: Option<Expression>,
2251    /// INSERT OVERWRITE for Hive/Spark
2252    pub overwrite: bool,
2253    /// PARTITION clause for Hive/Spark
2254    pub partition: Vec<(Identifier, Option<Expression>)>,
2255    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2256    #[serde(default)]
2257    pub directory: Option<DirectoryInsert>,
2258    /// RETURNING clause (PostgreSQL, SQLite)
2259    #[serde(default)]
2260    pub returning: Vec<Expression>,
2261    /// OUTPUT clause (TSQL)
2262    #[serde(default)]
2263    pub output: Option<OutputClause>,
2264    /// ON CONFLICT clause (PostgreSQL, SQLite)
2265    #[serde(default)]
2266    pub on_conflict: Option<Box<Expression>>,
2267    /// Leading comments before the statement
2268    #[serde(default)]
2269    pub leading_comments: Vec<String>,
2270    /// IF EXISTS clause (Hive)
2271    #[serde(default)]
2272    pub if_exists: bool,
2273    /// WITH clause (CTEs)
2274    #[serde(default)]
2275    pub with: Option<With>,
2276    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2277    #[serde(default)]
2278    pub ignore: bool,
2279    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2280    #[serde(default)]
2281    pub source_alias: Option<Identifier>,
2282    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2283    #[serde(default)]
2284    pub alias: Option<Identifier>,
2285    /// Whether the alias uses explicit AS keyword
2286    #[serde(default)]
2287    pub alias_explicit_as: bool,
2288    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2289    #[serde(default)]
2290    pub default_values: bool,
2291    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2292    #[serde(default)]
2293    pub by_name: bool,
2294    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2295    #[serde(default, skip_serializing_if = "Option::is_none")]
2296    pub conflict_action: Option<String>,
2297    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2298    #[serde(default)]
2299    pub is_replace: bool,
2300    /// Oracle-style hint: INSERT /*+ APPEND */ INTO ...
2301    #[serde(default, skip_serializing_if = "Option::is_none")]
2302    pub hint: Option<Hint>,
2303    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2304    #[serde(default)]
2305    pub replace_where: Option<Box<Expression>>,
2306    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2307    #[serde(default)]
2308    pub source: Option<Box<Expression>>,
2309    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2310    #[serde(default, skip_serializing_if = "Option::is_none")]
2311    pub function_target: Option<Box<Expression>>,
2312    /// ClickHouse: PARTITION BY expr
2313    #[serde(default, skip_serializing_if = "Option::is_none")]
2314    pub partition_by: Option<Box<Expression>>,
2315    /// ClickHouse: SETTINGS key = val, ...
2316    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2317    pub settings: Vec<Expression>,
2318}
2319
2320/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2322#[cfg_attr(feature = "bindings", derive(TS))]
2323pub struct OutputClause {
2324    /// Columns/expressions to output
2325    pub columns: Vec<Expression>,
2326    /// Optional INTO target table or table variable
2327    #[serde(default)]
2328    pub into_table: Option<Expression>,
2329}
2330
2331/// UPDATE statement
2332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2333#[cfg_attr(feature = "bindings", derive(TS))]
2334pub struct Update {
2335    pub table: TableRef,
2336    /// Additional tables for multi-table UPDATE (MySQL syntax)
2337    #[serde(default)]
2338    pub extra_tables: Vec<TableRef>,
2339    /// JOINs attached to the table list (MySQL multi-table syntax)
2340    #[serde(default)]
2341    pub table_joins: Vec<Join>,
2342    pub set: Vec<(Identifier, Expression)>,
2343    pub from_clause: Option<From>,
2344    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2345    #[serde(default)]
2346    pub from_joins: Vec<Join>,
2347    pub where_clause: Option<Where>,
2348    /// RETURNING clause (PostgreSQL, SQLite)
2349    #[serde(default)]
2350    pub returning: Vec<Expression>,
2351    /// OUTPUT clause (TSQL)
2352    #[serde(default)]
2353    pub output: Option<OutputClause>,
2354    /// WITH clause (CTEs)
2355    #[serde(default)]
2356    pub with: Option<With>,
2357    /// Leading comments before the statement
2358    #[serde(default)]
2359    pub leading_comments: Vec<String>,
2360    /// LIMIT clause (MySQL)
2361    #[serde(default)]
2362    pub limit: Option<Expression>,
2363    /// ORDER BY clause (MySQL)
2364    #[serde(default)]
2365    pub order_by: Option<OrderBy>,
2366    /// Whether FROM clause appears before SET (Snowflake syntax)
2367    #[serde(default)]
2368    pub from_before_set: bool,
2369}
2370
2371/// DELETE statement
2372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2373#[cfg_attr(feature = "bindings", derive(TS))]
2374pub struct Delete {
2375    pub table: TableRef,
2376    /// ClickHouse: ON CLUSTER clause for distributed DDL
2377    #[serde(default, skip_serializing_if = "Option::is_none")]
2378    pub on_cluster: Option<OnCluster>,
2379    /// Optional alias for the table
2380    pub alias: Option<Identifier>,
2381    /// Whether the alias was declared with explicit AS keyword
2382    #[serde(default)]
2383    pub alias_explicit_as: bool,
2384    /// PostgreSQL/DuckDB USING clause - additional tables to join
2385    pub using: Vec<TableRef>,
2386    pub where_clause: Option<Where>,
2387    /// OUTPUT clause (TSQL)
2388    #[serde(default)]
2389    pub output: Option<OutputClause>,
2390    /// Leading comments before the statement
2391    #[serde(default)]
2392    pub leading_comments: Vec<String>,
2393    /// WITH clause (CTEs)
2394    #[serde(default)]
2395    pub with: Option<With>,
2396    /// LIMIT clause (MySQL)
2397    #[serde(default)]
2398    pub limit: Option<Expression>,
2399    /// ORDER BY clause (MySQL)
2400    #[serde(default)]
2401    pub order_by: Option<OrderBy>,
2402    /// RETURNING clause (PostgreSQL)
2403    #[serde(default)]
2404    pub returning: Vec<Expression>,
2405    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2406    /// These are the target tables to delete from
2407    #[serde(default)]
2408    pub tables: Vec<TableRef>,
2409    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2410    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2411    #[serde(default)]
2412    pub tables_from_using: bool,
2413    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2414    #[serde(default)]
2415    pub joins: Vec<Join>,
2416    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2417    #[serde(default)]
2418    pub force_index: Option<String>,
2419    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2420    #[serde(default)]
2421    pub no_from: bool,
2422}
2423
2424/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2426#[cfg_attr(feature = "bindings", derive(TS))]
2427pub struct CopyStmt {
2428    /// Target table or query
2429    pub this: Expression,
2430    /// True for FROM (loading into table), false for TO (exporting)
2431    pub kind: bool,
2432    /// Source/destination file(s) or stage
2433    pub files: Vec<Expression>,
2434    /// Copy parameters
2435    #[serde(default)]
2436    pub params: Vec<CopyParameter>,
2437    /// Credentials for external access
2438    #[serde(default)]
2439    pub credentials: Option<Box<Credentials>>,
2440    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2441    #[serde(default)]
2442    pub is_into: bool,
2443    /// Whether parameters are wrapped in WITH (...) syntax
2444    #[serde(default)]
2445    pub with_wrapped: bool,
2446}
2447
2448/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2450#[cfg_attr(feature = "bindings", derive(TS))]
2451pub struct CopyParameter {
2452    pub name: String,
2453    pub value: Option<Expression>,
2454    pub values: Vec<Expression>,
2455    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2456    #[serde(default)]
2457    pub eq: bool,
2458}
2459
2460/// Credentials for external access (S3, Azure, etc.)
2461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2462#[cfg_attr(feature = "bindings", derive(TS))]
2463pub struct Credentials {
2464    pub credentials: Vec<(String, String)>,
2465    pub encryption: Option<String>,
2466    pub storage: Option<String>,
2467}
2468
2469/// PUT statement (Snowflake)
2470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2471#[cfg_attr(feature = "bindings", derive(TS))]
2472pub struct PutStmt {
2473    /// Source file path
2474    pub source: String,
2475    /// Whether source was quoted in the original SQL
2476    #[serde(default)]
2477    pub source_quoted: bool,
2478    /// Target stage
2479    pub target: Expression,
2480    /// PUT parameters
2481    #[serde(default)]
2482    pub params: Vec<CopyParameter>,
2483}
2484
2485/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2487#[cfg_attr(feature = "bindings", derive(TS))]
2488pub struct StageReference {
2489    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2490    pub name: String,
2491    /// Optional path within the stage (e.g., "/path/to/file.csv")
2492    #[serde(default)]
2493    pub path: Option<String>,
2494    /// Optional FILE_FORMAT parameter
2495    #[serde(default)]
2496    pub file_format: Option<Expression>,
2497    /// Optional PATTERN parameter
2498    #[serde(default)]
2499    pub pattern: Option<String>,
2500    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2501    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2502    pub quoted: bool,
2503}
2504
2505/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2507#[cfg_attr(feature = "bindings", derive(TS))]
2508pub struct HistoricalData {
2509    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
2510    pub this: Box<Expression>,
2511    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
2512    pub kind: String,
2513    /// The expression value (e.g., the statement ID or timestamp)
2514    pub expression: Box<Expression>,
2515}
2516
2517/// Represent an aliased expression (`expr AS name`).
2518///
2519/// Used for column aliases in select-lists, table aliases on subqueries,
2520/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
2521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2522#[cfg_attr(feature = "bindings", derive(TS))]
2523pub struct Alias {
2524    /// The expression being aliased.
2525    pub this: Expression,
2526    /// The alias name (required for simple aliases, optional when only column aliases provided)
2527    pub alias: Identifier,
2528    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
2529    #[serde(default)]
2530    pub column_aliases: Vec<Identifier>,
2531    /// Comments that appeared between the expression and AS keyword
2532    #[serde(default)]
2533    pub pre_alias_comments: Vec<String>,
2534    /// Trailing comments that appeared after the alias
2535    #[serde(default)]
2536    pub trailing_comments: Vec<String>,
2537}
2538
2539impl Alias {
2540    /// Create a simple alias
2541    pub fn new(this: Expression, alias: Identifier) -> Self {
2542        Self {
2543            this,
2544            alias,
2545            column_aliases: Vec::new(),
2546            pre_alias_comments: Vec::new(),
2547            trailing_comments: Vec::new(),
2548        }
2549    }
2550
2551    /// Create an alias with column aliases only (no table alias name)
2552    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
2553        Self {
2554            this,
2555            alias: Identifier::empty(),
2556            column_aliases,
2557            pre_alias_comments: Vec::new(),
2558            trailing_comments: Vec::new(),
2559        }
2560    }
2561}
2562
2563/// Represent a type cast expression.
2564///
2565/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
2566/// shorthand `expr::type`. Also used as the payload for `TryCast` and
2567/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
2568/// CONVERSION ERROR (Oracle) clauses.
2569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2570#[cfg_attr(feature = "bindings", derive(TS))]
2571pub struct Cast {
2572    /// The expression being cast.
2573    pub this: Expression,
2574    /// The target data type.
2575    pub to: DataType,
2576    #[serde(default)]
2577    pub trailing_comments: Vec<String>,
2578    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
2579    #[serde(default)]
2580    pub double_colon_syntax: bool,
2581    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
2582    #[serde(skip_serializing_if = "Option::is_none", default)]
2583    pub format: Option<Box<Expression>>,
2584    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
2585    #[serde(skip_serializing_if = "Option::is_none", default)]
2586    pub default: Option<Box<Expression>>,
2587}
2588
2589///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
2590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2591#[cfg_attr(feature = "bindings", derive(TS))]
2592pub struct CollationExpr {
2593    pub this: Expression,
2594    pub collation: String,
2595    /// True if the collation was single-quoted in the original SQL (string literal)
2596    #[serde(default)]
2597    pub quoted: bool,
2598    /// True if the collation was double-quoted in the original SQL (identifier)
2599    #[serde(default)]
2600    pub double_quoted: bool,
2601}
2602
2603/// Represent a CASE expression (both simple and searched forms).
2604///
2605/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
2606/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
2607/// Each entry in `whens` is a `(condition, result)` pair.
2608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2609#[cfg_attr(feature = "bindings", derive(TS))]
2610pub struct Case {
2611    /// The operand for simple CASE, or `None` for searched CASE.
2612    pub operand: Option<Expression>,
2613    /// Pairs of (WHEN condition, THEN result).
2614    pub whens: Vec<(Expression, Expression)>,
2615    /// Optional ELSE result.
2616    pub else_: Option<Expression>,
2617}
2618
2619/// Represent a binary operation (two operands separated by an operator).
2620///
2621/// This is the shared payload struct for all binary operator variants in the
2622/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
2623/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
2624/// bitwise, and dialect-specific operators. Comment fields enable round-trip
2625/// preservation of inline comments around operators.
2626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2627#[cfg_attr(feature = "bindings", derive(TS))]
2628pub struct BinaryOp {
2629    pub left: Expression,
2630    pub right: Expression,
2631    /// Comments after the left operand (before the operator)
2632    #[serde(default)]
2633    pub left_comments: Vec<String>,
2634    /// Comments after the operator (before the right operand)
2635    #[serde(default)]
2636    pub operator_comments: Vec<String>,
2637    /// Comments after the right operand
2638    #[serde(default)]
2639    pub trailing_comments: Vec<String>,
2640}
2641
2642impl BinaryOp {
2643    pub fn new(left: Expression, right: Expression) -> Self {
2644        Self {
2645            left,
2646            right,
2647            left_comments: Vec::new(),
2648            operator_comments: Vec::new(),
2649            trailing_comments: Vec::new(),
2650        }
2651    }
2652}
2653
2654/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
2655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2656#[cfg_attr(feature = "bindings", derive(TS))]
2657pub struct LikeOp {
2658    pub left: Expression,
2659    pub right: Expression,
2660    /// ESCAPE character/expression
2661    #[serde(default)]
2662    pub escape: Option<Expression>,
2663    /// Quantifier: ANY, ALL, or SOME
2664    #[serde(default)]
2665    pub quantifier: Option<String>,
2666}
2667
2668impl LikeOp {
2669    pub fn new(left: Expression, right: Expression) -> Self {
2670        Self {
2671            left,
2672            right,
2673            escape: None,
2674            quantifier: None,
2675        }
2676    }
2677
2678    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
2679        Self {
2680            left,
2681            right,
2682            escape: Some(escape),
2683            quantifier: None,
2684        }
2685    }
2686}
2687
2688/// Represent a unary operation (single operand with a prefix operator).
2689///
2690/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
2691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2692#[cfg_attr(feature = "bindings", derive(TS))]
2693pub struct UnaryOp {
2694    /// The operand expression.
2695    pub this: Expression,
2696}
2697
2698impl UnaryOp {
2699    pub fn new(this: Expression) -> Self {
2700        Self { this }
2701    }
2702}
2703
2704/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
2705///
2706/// Either `expressions` (a value list) or `query` (a subquery) is populated,
2707/// but not both. When `not` is true, the predicate is `NOT IN`.
2708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2709#[cfg_attr(feature = "bindings", derive(TS))]
2710pub struct In {
2711    /// The expression being tested.
2712    pub this: Expression,
2713    /// The value list (mutually exclusive with `query`).
2714    pub expressions: Vec<Expression>,
2715    /// A subquery (mutually exclusive with `expressions`).
2716    pub query: Option<Expression>,
2717    /// Whether this is NOT IN.
2718    pub not: bool,
2719    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2720    pub global: bool,
2721    /// BigQuery: IN UNNEST(expr)
2722    #[serde(default, skip_serializing_if = "Option::is_none")]
2723    pub unnest: Option<Box<Expression>>,
2724}
2725
2726/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
2727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2728#[cfg_attr(feature = "bindings", derive(TS))]
2729pub struct Between {
2730    /// The expression being tested.
2731    pub this: Expression,
2732    /// The lower bound.
2733    pub low: Expression,
2734    /// The upper bound.
2735    pub high: Expression,
2736    /// Whether this is NOT BETWEEN.
2737    pub not: bool,
2738}
2739
2740/// IS NULL predicate
2741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2742#[cfg_attr(feature = "bindings", derive(TS))]
2743pub struct IsNull {
2744    pub this: Expression,
2745    pub not: bool,
2746    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
2747    #[serde(default)]
2748    pub postfix_form: bool,
2749}
2750
2751/// IS TRUE / IS FALSE predicate
2752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2753#[cfg_attr(feature = "bindings", derive(TS))]
2754pub struct IsTrueFalse {
2755    pub this: Expression,
2756    pub not: bool,
2757}
2758
2759/// IS JSON predicate (SQL standard)
2760/// Checks if a value is valid JSON
2761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2762#[cfg_attr(feature = "bindings", derive(TS))]
2763pub struct IsJson {
2764    pub this: Expression,
2765    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
2766    pub json_type: Option<String>,
2767    /// Key uniqueness constraint
2768    pub unique_keys: Option<JsonUniqueKeys>,
2769    /// Whether IS NOT JSON
2770    pub negated: bool,
2771}
2772
2773/// JSON unique keys constraint variants
2774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2775#[cfg_attr(feature = "bindings", derive(TS))]
2776pub enum JsonUniqueKeys {
2777    /// WITH UNIQUE KEYS
2778    With,
2779    /// WITHOUT UNIQUE KEYS
2780    Without,
2781    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
2782    Shorthand,
2783}
2784
2785/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
2786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2787#[cfg_attr(feature = "bindings", derive(TS))]
2788pub struct Exists {
2789    /// The subquery expression.
2790    pub this: Expression,
2791    /// Whether this is NOT EXISTS.
2792    pub not: bool,
2793}
2794
2795/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
2796///
2797/// This is the generic function node. Well-known aggregates, window functions,
2798/// and built-in functions each have their own dedicated `Expression` variants
2799/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
2800/// not recognize as built-ins are represented with this struct.
2801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2802#[cfg_attr(feature = "bindings", derive(TS))]
2803pub struct Function {
2804    /// The function name, as originally written (may be schema-qualified).
2805    pub name: String,
2806    /// Positional arguments to the function.
2807    pub args: Vec<Expression>,
2808    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
2809    pub distinct: bool,
2810    #[serde(default)]
2811    pub trailing_comments: Vec<String>,
2812    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
2813    #[serde(default)]
2814    pub use_bracket_syntax: bool,
2815    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
2816    #[serde(default)]
2817    pub no_parens: bool,
2818    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
2819    #[serde(default)]
2820    pub quoted: bool,
2821}
2822
2823impl Default for Function {
2824    fn default() -> Self {
2825        Self {
2826            name: String::new(),
2827            args: Vec::new(),
2828            distinct: false,
2829            trailing_comments: Vec::new(),
2830            use_bracket_syntax: false,
2831            no_parens: false,
2832            quoted: false,
2833        }
2834    }
2835}
2836
2837impl Function {
2838    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
2839        Self {
2840            name: name.into(),
2841            args,
2842            distinct: false,
2843            trailing_comments: Vec::new(),
2844            use_bracket_syntax: false,
2845            no_parens: false,
2846            quoted: false,
2847        }
2848    }
2849}
2850
2851/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
2852///
2853/// This struct is used for aggregate function calls that are not covered by
2854/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
2855/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
2856/// IGNORE NULLS / RESPECT NULLS modifiers.
2857#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2858#[cfg_attr(feature = "bindings", derive(TS))]
2859pub struct AggregateFunction {
2860    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
2861    pub name: String,
2862    /// Positional arguments.
2863    pub args: Vec<Expression>,
2864    /// Whether DISTINCT was specified.
2865    pub distinct: bool,
2866    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
2867    pub filter: Option<Expression>,
2868    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
2869    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2870    pub order_by: Vec<Ordered>,
2871    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
2872    #[serde(default, skip_serializing_if = "Option::is_none")]
2873    pub limit: Option<Box<Expression>>,
2874    /// IGNORE NULLS / RESPECT NULLS
2875    #[serde(default, skip_serializing_if = "Option::is_none")]
2876    pub ignore_nulls: Option<bool>,
2877}
2878
2879/// Represent a window function call with its OVER clause.
2880///
2881/// The inner `this` expression is typically a window-specific expression
2882/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
2883/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
2884/// frame specification.
2885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2886#[cfg_attr(feature = "bindings", derive(TS))]
2887pub struct WindowFunction {
2888    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
2889    pub this: Expression,
2890    /// The OVER clause defining the window partitioning, ordering, and frame.
2891    pub over: Over,
2892    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
2893    #[serde(default, skip_serializing_if = "Option::is_none")]
2894    pub keep: Option<Keep>,
2895}
2896
2897/// Oracle KEEP clause for aggregate functions
2898/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
2899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2900#[cfg_attr(feature = "bindings", derive(TS))]
2901pub struct Keep {
2902    /// true = FIRST, false = LAST
2903    pub first: bool,
2904    /// ORDER BY clause inside KEEP
2905    pub order_by: Vec<Ordered>,
2906}
2907
2908/// WITHIN GROUP clause (for ordered-set aggregate functions)
2909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2910#[cfg_attr(feature = "bindings", derive(TS))]
2911pub struct WithinGroup {
2912    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
2913    pub this: Expression,
2914    /// The ORDER BY clause within the group
2915    pub order_by: Vec<Ordered>,
2916}
2917
2918/// Represent the FROM clause of a SELECT statement.
2919///
2920/// Contains one or more table sources (tables, subqueries, table-valued
2921/// functions, etc.). Multiple entries represent comma-separated implicit joins.
2922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2923#[cfg_attr(feature = "bindings", derive(TS))]
2924pub struct From {
2925    /// The table source expressions.
2926    pub expressions: Vec<Expression>,
2927}
2928
2929/// Represent a JOIN clause between two table sources.
2930///
2931/// The join condition can be specified via `on` (ON predicate) or `using`
2932/// (USING column list), but not both. The `kind` field determines the join
2933/// type (INNER, LEFT, CROSS, etc.).
2934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2935#[cfg_attr(feature = "bindings", derive(TS))]
2936pub struct Join {
2937    /// The right-hand table expression being joined.
2938    pub this: Expression,
2939    /// The ON condition (mutually exclusive with `using`).
2940    pub on: Option<Expression>,
2941    /// The USING column list (mutually exclusive with `on`).
2942    pub using: Vec<Identifier>,
2943    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
2944    pub kind: JoinKind,
2945    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
2946    pub use_inner_keyword: bool,
2947    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
2948    pub use_outer_keyword: bool,
2949    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
2950    pub deferred_condition: bool,
2951    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
2952    #[serde(default, skip_serializing_if = "Option::is_none")]
2953    pub join_hint: Option<String>,
2954    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
2955    #[serde(default, skip_serializing_if = "Option::is_none")]
2956    pub match_condition: Option<Expression>,
2957    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
2958    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2959    pub pivots: Vec<Expression>,
2960}
2961
2962/// Enumerate all supported SQL join types.
2963///
2964/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
2965/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
2966/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
2967/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
2968#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2969#[cfg_attr(feature = "bindings", derive(TS))]
2970pub enum JoinKind {
2971    Inner,
2972    Left,
2973    Right,
2974    Full,
2975    Outer,  // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
2976    Cross,
2977    Natural,
2978    NaturalLeft,
2979    NaturalRight,
2980    NaturalFull,
2981    Semi,
2982    Anti,
2983    // Directional SEMI/ANTI joins
2984    LeftSemi,
2985    LeftAnti,
2986    RightSemi,
2987    RightAnti,
2988    // SQL Server specific
2989    CrossApply,
2990    OuterApply,
2991    // Time-series specific
2992    AsOf,
2993    AsOfLeft,
2994    AsOfRight,
2995    // Lateral join
2996    Lateral,
2997    LeftLateral,
2998    // MySQL specific
2999    Straight,
3000    // Implicit join (comma-separated tables: FROM a, b)
3001    Implicit,
3002    // ClickHouse ARRAY JOIN
3003    Array,
3004    LeftArray,
3005}
3006
3007impl Default for JoinKind {
3008    fn default() -> Self {
3009        JoinKind::Inner
3010    }
3011}
3012
3013/// Parenthesized table expression with joins
3014/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3016#[cfg_attr(feature = "bindings", derive(TS))]
3017pub struct JoinedTable {
3018    /// The left-hand side table expression
3019    pub left: Expression,
3020    /// The joins applied to the left table
3021    pub joins: Vec<Join>,
3022    /// LATERAL VIEW clauses (Hive/Spark)
3023    pub lateral_views: Vec<LateralView>,
3024    /// Optional alias for the joined table expression
3025    pub alias: Option<Identifier>,
3026}
3027
3028/// Represent a WHERE clause containing a boolean filter predicate.
3029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3030#[cfg_attr(feature = "bindings", derive(TS))]
3031pub struct Where {
3032    /// The filter predicate expression.
3033    pub this: Expression,
3034}
3035
3036/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3037///
3038/// The `expressions` list may contain plain columns, ordinal positions,
3039/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3041#[cfg_attr(feature = "bindings", derive(TS))]
3042pub struct GroupBy {
3043    /// The grouping expressions.
3044    pub expressions: Vec<Expression>,
3045    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3046    #[serde(default)]
3047    pub all: Option<bool>,
3048    /// ClickHouse: WITH TOTALS modifier
3049    #[serde(default)]
3050    pub totals: bool,
3051}
3052
3053/// Represent a HAVING clause containing a predicate over aggregate results.
3054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3055#[cfg_attr(feature = "bindings", derive(TS))]
3056pub struct Having {
3057    /// The filter predicate, typically involving aggregate functions.
3058    pub this: Expression,
3059}
3060
3061/// Represent an ORDER BY clause containing one or more sort specifications.
3062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3063#[cfg_attr(feature = "bindings", derive(TS))]
3064pub struct OrderBy {
3065    /// The sort specifications, each with direction and null ordering.
3066    pub expressions: Vec<Ordered>,
3067    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3068    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3069    pub siblings: bool,
3070}
3071
3072/// Represent an expression with sort direction and null ordering.
3073///
3074/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3075/// When `desc` is false the sort is ascending. The `nulls_first` field
3076/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3077/// (database default).
3078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3079#[cfg_attr(feature = "bindings", derive(TS))]
3080pub struct Ordered {
3081    /// The expression to sort by.
3082    pub this: Expression,
3083    /// Whether the sort direction is descending (true) or ascending (false).
3084    pub desc: bool,
3085    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3086    pub nulls_first: Option<bool>,
3087    /// Whether ASC was explicitly written (not just implied)
3088    #[serde(default)]
3089    pub explicit_asc: bool,
3090    /// ClickHouse WITH FILL clause
3091    #[serde(default, skip_serializing_if = "Option::is_none")]
3092    pub with_fill: Option<Box<WithFill>>,
3093}
3094
3095impl Ordered {
3096    pub fn asc(expr: Expression) -> Self {
3097        Self {
3098            this: expr,
3099            desc: false,
3100            nulls_first: None,
3101            explicit_asc: false,
3102            with_fill: None,
3103        }
3104    }
3105
3106    pub fn desc(expr: Expression) -> Self {
3107        Self {
3108            this: expr,
3109            desc: true,
3110            nulls_first: None,
3111            explicit_asc: false,
3112            with_fill: None,
3113        }
3114    }
3115}
3116
3117/// DISTRIBUTE BY clause (Hive/Spark)
3118/// Controls how rows are distributed across reducers
3119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3120#[cfg_attr(feature = "bindings", derive(TS))]
3121#[cfg_attr(feature = "bindings", ts(export))]
3122pub struct DistributeBy {
3123    pub expressions: Vec<Expression>,
3124}
3125
3126/// CLUSTER BY clause (Hive/Spark)
3127/// Combines DISTRIBUTE BY and SORT BY on the same columns
3128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3129#[cfg_attr(feature = "bindings", derive(TS))]
3130#[cfg_attr(feature = "bindings", ts(export))]
3131pub struct ClusterBy {
3132    pub expressions: Vec<Ordered>,
3133}
3134
3135/// SORT BY clause (Hive/Spark)
3136/// Sorts data within each reducer (local sort, not global)
3137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3138#[cfg_attr(feature = "bindings", derive(TS))]
3139#[cfg_attr(feature = "bindings", ts(export))]
3140pub struct SortBy {
3141    pub expressions: Vec<Ordered>,
3142}
3143
3144/// LATERAL VIEW clause (Hive/Spark)
3145/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3147#[cfg_attr(feature = "bindings", derive(TS))]
3148#[cfg_attr(feature = "bindings", ts(export))]
3149pub struct LateralView {
3150    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3151    pub this: Expression,
3152    /// Table alias for the generated table
3153    pub table_alias: Option<Identifier>,
3154    /// Column aliases for the generated columns
3155    pub column_aliases: Vec<Identifier>,
3156    /// OUTER keyword - preserve nulls when input is empty/null
3157    pub outer: bool,
3158}
3159
3160/// Query hint
3161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3162#[cfg_attr(feature = "bindings", derive(TS))]
3163#[cfg_attr(feature = "bindings", ts(export))]
3164pub struct Hint {
3165    pub expressions: Vec<HintExpression>,
3166}
3167
3168/// Individual hint expression
3169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3170#[cfg_attr(feature = "bindings", derive(TS))]
3171#[cfg_attr(feature = "bindings", ts(export))]
3172pub enum HintExpression {
3173    /// Function-style hint: USE_HASH(table)
3174    Function { name: String, args: Vec<Expression> },
3175    /// Simple identifier hint: PARALLEL
3176    Identifier(String),
3177    /// Raw hint text (unparsed)
3178    Raw(String),
3179}
3180
3181/// Pseudocolumn type
3182#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3183#[cfg_attr(feature = "bindings", derive(TS))]
3184#[cfg_attr(feature = "bindings", ts(export))]
3185pub enum PseudocolumnType {
3186    Rownum,      // Oracle ROWNUM
3187    Rowid,       // Oracle ROWID
3188    Level,       // Oracle LEVEL (for CONNECT BY)
3189    Sysdate,     // Oracle SYSDATE
3190    ObjectId,    // Oracle OBJECT_ID
3191    ObjectValue, // Oracle OBJECT_VALUE
3192}
3193
3194impl PseudocolumnType {
3195    pub fn as_str(&self) -> &'static str {
3196        match self {
3197            PseudocolumnType::Rownum => "ROWNUM",
3198            PseudocolumnType::Rowid => "ROWID",
3199            PseudocolumnType::Level => "LEVEL",
3200            PseudocolumnType::Sysdate => "SYSDATE",
3201            PseudocolumnType::ObjectId => "OBJECT_ID",
3202            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3203        }
3204    }
3205
3206    pub fn from_str(s: &str) -> Option<Self> {
3207        match s.to_uppercase().as_str() {
3208            "ROWNUM" => Some(PseudocolumnType::Rownum),
3209            "ROWID" => Some(PseudocolumnType::Rowid),
3210            "LEVEL" => Some(PseudocolumnType::Level),
3211            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3212            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3213            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3214            _ => None,
3215        }
3216    }
3217}
3218
3219/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3220/// These are special identifiers that should not be quoted
3221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3222#[cfg_attr(feature = "bindings", derive(TS))]
3223#[cfg_attr(feature = "bindings", ts(export))]
3224pub struct Pseudocolumn {
3225    pub kind: PseudocolumnType,
3226}
3227
3228impl Pseudocolumn {
3229    pub fn rownum() -> Self {
3230        Self { kind: PseudocolumnType::Rownum }
3231    }
3232
3233    pub fn rowid() -> Self {
3234        Self { kind: PseudocolumnType::Rowid }
3235    }
3236
3237    pub fn level() -> Self {
3238        Self { kind: PseudocolumnType::Level }
3239    }
3240}
3241
3242/// Oracle CONNECT BY clause for hierarchical queries
3243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3244#[cfg_attr(feature = "bindings", derive(TS))]
3245#[cfg_attr(feature = "bindings", ts(export))]
3246pub struct Connect {
3247    /// START WITH condition (optional, can come before or after CONNECT BY)
3248    pub start: Option<Expression>,
3249    /// CONNECT BY condition (required, contains PRIOR references)
3250    pub connect: Expression,
3251    /// NOCYCLE keyword to prevent infinite loops
3252    pub nocycle: bool,
3253}
3254
3255/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3257#[cfg_attr(feature = "bindings", derive(TS))]
3258#[cfg_attr(feature = "bindings", ts(export))]
3259pub struct Prior {
3260    pub this: Expression,
3261}
3262
3263/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3265#[cfg_attr(feature = "bindings", derive(TS))]
3266#[cfg_attr(feature = "bindings", ts(export))]
3267pub struct ConnectByRoot {
3268    pub this: Expression,
3269}
3270
3271/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3273#[cfg_attr(feature = "bindings", derive(TS))]
3274#[cfg_attr(feature = "bindings", ts(export))]
3275pub struct MatchRecognize {
3276    /// Source table/expression
3277    pub this: Option<Box<Expression>>,
3278    /// PARTITION BY expressions
3279    pub partition_by: Option<Vec<Expression>>,
3280    /// ORDER BY expressions
3281    pub order_by: Option<Vec<Ordered>>,
3282    /// MEASURES definitions
3283    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3284    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3285    pub rows: Option<MatchRecognizeRows>,
3286    /// AFTER MATCH SKIP behavior
3287    pub after: Option<MatchRecognizeAfter>,
3288    /// PATTERN definition (stored as raw string for complex regex patterns)
3289    pub pattern: Option<String>,
3290    /// DEFINE clauses (pattern variable definitions)
3291    pub define: Option<Vec<(Identifier, Expression)>>,
3292    /// Optional alias for the result
3293    pub alias: Option<Identifier>,
3294    /// Whether AS keyword was explicitly present before alias
3295    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3296    pub alias_explicit_as: bool,
3297}
3298
3299/// MEASURES expression with optional RUNNING/FINAL semantics
3300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3301#[cfg_attr(feature = "bindings", derive(TS))]
3302#[cfg_attr(feature = "bindings", ts(export))]
3303pub struct MatchRecognizeMeasure {
3304    /// The measure expression
3305    pub this: Expression,
3306    /// RUNNING or FINAL semantics (Snowflake-specific)
3307    pub window_frame: Option<MatchRecognizeSemantics>,
3308}
3309
3310/// Semantics for MEASURES in MATCH_RECOGNIZE
3311#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3312#[cfg_attr(feature = "bindings", derive(TS))]
3313#[cfg_attr(feature = "bindings", ts(export))]
3314pub enum MatchRecognizeSemantics {
3315    Running,
3316    Final,
3317}
3318
3319/// Row output semantics for MATCH_RECOGNIZE
3320#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3321#[cfg_attr(feature = "bindings", derive(TS))]
3322#[cfg_attr(feature = "bindings", ts(export))]
3323pub enum MatchRecognizeRows {
3324    OneRowPerMatch,
3325    AllRowsPerMatch,
3326    AllRowsPerMatchShowEmptyMatches,
3327    AllRowsPerMatchOmitEmptyMatches,
3328    AllRowsPerMatchWithUnmatchedRows,
3329}
3330
3331/// AFTER MATCH SKIP behavior
3332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3333#[cfg_attr(feature = "bindings", derive(TS))]
3334#[cfg_attr(feature = "bindings", ts(export))]
3335pub enum MatchRecognizeAfter {
3336    PastLastRow,
3337    ToNextRow,
3338    ToFirst(Identifier),
3339    ToLast(Identifier),
3340}
3341
3342/// Represent a LIMIT clause that restricts the number of returned rows.
3343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3344#[cfg_attr(feature = "bindings", derive(TS))]
3345pub struct Limit {
3346    /// The limit count expression.
3347    pub this: Expression,
3348    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3349    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3350    pub percent: bool,
3351}
3352
3353/// OFFSET clause
3354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3355#[cfg_attr(feature = "bindings", derive(TS))]
3356pub struct Offset {
3357    pub this: Expression,
3358    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3359    #[serde(skip_serializing_if = "Option::is_none", default)]
3360    pub rows: Option<bool>,
3361}
3362
3363/// TOP clause (SQL Server)
3364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3365#[cfg_attr(feature = "bindings", derive(TS))]
3366pub struct Top {
3367    pub this: Expression,
3368    pub percent: bool,
3369    pub with_ties: bool,
3370    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3371    #[serde(default)]
3372    pub parenthesized: bool,
3373}
3374
3375/// FETCH FIRST/NEXT clause (SQL standard)
3376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3377#[cfg_attr(feature = "bindings", derive(TS))]
3378pub struct Fetch {
3379    /// FIRST or NEXT
3380    pub direction: String,
3381    /// Count expression (optional)
3382    pub count: Option<Expression>,
3383    /// PERCENT modifier
3384    pub percent: bool,
3385    /// ROWS or ROW keyword present
3386    pub rows: bool,
3387    /// WITH TIES modifier
3388    pub with_ties: bool,
3389}
3390
3391/// Represent a QUALIFY clause for filtering on window function results.
3392///
3393/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3394/// typically references a window function (e.g.
3395/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3397#[cfg_attr(feature = "bindings", derive(TS))]
3398pub struct Qualify {
3399    /// The filter predicate over window function results.
3400    pub this: Expression,
3401}
3402
3403/// SAMPLE / TABLESAMPLE clause
3404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3405#[cfg_attr(feature = "bindings", derive(TS))]
3406pub struct Sample {
3407    pub method: SampleMethod,
3408    pub size: Expression,
3409    pub seed: Option<Expression>,
3410    /// ClickHouse OFFSET expression after SAMPLE size
3411    #[serde(default)]
3412    pub offset: Option<Expression>,
3413    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3414    pub unit_after_size: bool,
3415    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3416    #[serde(default)]
3417    pub use_sample_keyword: bool,
3418    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3419    #[serde(default)]
3420    pub explicit_method: bool,
3421    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3422    #[serde(default)]
3423    pub method_before_size: bool,
3424    /// Whether SEED keyword was used (true) or REPEATABLE (false)
3425    #[serde(default)]
3426    pub use_seed_keyword: bool,
3427    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
3428    pub bucket_numerator: Option<Box<Expression>>,
3429    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
3430    pub bucket_denominator: Option<Box<Expression>>,
3431    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
3432    pub bucket_field: Option<Box<Expression>>,
3433    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
3434    #[serde(default)]
3435    pub is_using_sample: bool,
3436    /// Whether the unit was explicitly PERCENT (vs ROWS)
3437    #[serde(default)]
3438    pub is_percent: bool,
3439    /// Whether to suppress method output (for cross-dialect transpilation)
3440    #[serde(default)]
3441    pub suppress_method_output: bool,
3442}
3443
3444/// Sample method
3445#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3446#[cfg_attr(feature = "bindings", derive(TS))]
3447pub enum SampleMethod {
3448    Bernoulli,
3449    System,
3450    Block,
3451    Row,
3452    Percent,
3453    /// Hive bucket sampling
3454    Bucket,
3455    /// DuckDB reservoir sampling
3456    Reservoir,
3457}
3458
3459/// Named window definition (WINDOW w AS (...))
3460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3461#[cfg_attr(feature = "bindings", derive(TS))]
3462pub struct NamedWindow {
3463    pub name: Identifier,
3464    pub spec: Over,
3465}
3466
3467/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
3468///
3469/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
3470/// that reference themselves. Each CTE is defined in the `ctes` vector and
3471/// can be referenced by name in subsequent CTEs and in the main query body.
3472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3473#[cfg_attr(feature = "bindings", derive(TS))]
3474pub struct With {
3475    /// The list of CTE definitions, in order.
3476    pub ctes: Vec<Cte>,
3477    /// Whether the WITH RECURSIVE keyword was used.
3478    pub recursive: bool,
3479    /// Leading comments before the statement
3480    #[serde(default)]
3481    pub leading_comments: Vec<String>,
3482    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
3483    #[serde(default, skip_serializing_if = "Option::is_none")]
3484    pub search: Option<Box<Expression>>,
3485}
3486
3487/// Represent a single Common Table Expression definition.
3488///
3489/// A CTE has a name (`alias`), an optional column list, and a body query.
3490/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
3491/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
3492/// the expression comes before the alias (`alias_first`).
3493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3494#[cfg_attr(feature = "bindings", derive(TS))]
3495pub struct Cte {
3496    /// The CTE name.
3497    pub alias: Identifier,
3498    /// The CTE body (typically a SELECT, UNION, etc.).
3499    pub this: Expression,
3500    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
3501    pub columns: Vec<Identifier>,
3502    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
3503    pub materialized: Option<bool>,
3504    /// USING KEY (columns) for DuckDB recursive CTEs
3505    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3506    pub key_expressions: Vec<Identifier>,
3507    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
3508    #[serde(default)]
3509    pub alias_first: bool,
3510}
3511
3512/// Window specification
3513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3514#[cfg_attr(feature = "bindings", derive(TS))]
3515pub struct WindowSpec {
3516    pub partition_by: Vec<Expression>,
3517    pub order_by: Vec<Ordered>,
3518    pub frame: Option<WindowFrame>,
3519}
3520
3521/// OVER clause
3522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3523#[cfg_attr(feature = "bindings", derive(TS))]
3524pub struct Over {
3525    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
3526    pub window_name: Option<Identifier>,
3527    pub partition_by: Vec<Expression>,
3528    pub order_by: Vec<Ordered>,
3529    pub frame: Option<WindowFrame>,
3530    pub alias: Option<Identifier>,
3531}
3532
3533/// Window frame
3534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3535#[cfg_attr(feature = "bindings", derive(TS))]
3536pub struct WindowFrame {
3537    pub kind: WindowFrameKind,
3538    pub start: WindowFrameBound,
3539    pub end: Option<WindowFrameBound>,
3540    pub exclude: Option<WindowFrameExclude>,
3541    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
3542    #[serde(default, skip_serializing_if = "Option::is_none")]
3543    pub kind_text: Option<String>,
3544    /// Original text of the start bound side keyword (e.g. "preceding")
3545    #[serde(default, skip_serializing_if = "Option::is_none")]
3546    pub start_side_text: Option<String>,
3547    /// Original text of the end bound side keyword
3548    #[serde(default, skip_serializing_if = "Option::is_none")]
3549    pub end_side_text: Option<String>,
3550}
3551
3552#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3553#[cfg_attr(feature = "bindings", derive(TS))]
3554pub enum WindowFrameKind {
3555    Rows,
3556    Range,
3557    Groups,
3558}
3559
3560/// EXCLUDE clause for window frames
3561#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3562#[cfg_attr(feature = "bindings", derive(TS))]
3563pub enum WindowFrameExclude {
3564    CurrentRow,
3565    Group,
3566    Ties,
3567    NoOthers,
3568}
3569
3570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3571#[cfg_attr(feature = "bindings", derive(TS))]
3572pub enum WindowFrameBound {
3573    CurrentRow,
3574    UnboundedPreceding,
3575    UnboundedFollowing,
3576    Preceding(Box<Expression>),
3577    Following(Box<Expression>),
3578    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
3579    BarePreceding,
3580    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
3581    BareFollowing,
3582    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
3583    Value(Box<Expression>),
3584}
3585
3586/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
3587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3588#[cfg_attr(feature = "bindings", derive(TS))]
3589pub struct StructField {
3590    pub name: String,
3591    pub data_type: DataType,
3592    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3593    pub options: Vec<Expression>,
3594    #[serde(default, skip_serializing_if = "Option::is_none")]
3595    pub comment: Option<String>,
3596}
3597
3598impl StructField {
3599    /// Create a new struct field without options
3600    pub fn new(name: String, data_type: DataType) -> Self {
3601        Self { name, data_type, options: Vec::new(), comment: None }
3602    }
3603
3604    /// Create a new struct field with options
3605    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
3606        Self { name, data_type, options, comment: None }
3607    }
3608
3609    /// Create a new struct field with options and comment
3610    pub fn with_options_and_comment(name: String, data_type: DataType, options: Vec<Expression>, comment: Option<String>) -> Self {
3611        Self { name, data_type, options, comment }
3612    }
3613}
3614
3615/// Enumerate all SQL data types recognized by the parser.
3616///
3617/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
3618/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
3619/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
3620///
3621/// This enum is used in CAST expressions, column definitions, function return
3622/// types, and anywhere a data type specification appears in SQL.
3623///
3624/// Types that do not match any known variant fall through to `Custom { name }`,
3625/// preserving the original type name for round-trip fidelity.
3626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3627#[cfg_attr(feature = "bindings", derive(TS))]
3628#[serde(tag = "data_type", rename_all = "snake_case")]
3629pub enum DataType {
3630    // Numeric
3631    Boolean,
3632    TinyInt { length: Option<u32> },
3633    SmallInt { length: Option<u32> },
3634    /// Int type with optional length. `integer_spelling` indicates whether the original
3635    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
3636    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
3637    Int { length: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] integer_spelling: bool },
3638    BigInt { length: Option<u32> },
3639    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
3640    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
3641    /// preserve the original spelling.
3642    Float { precision: Option<u32>, scale: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] real_spelling: bool },
3643    Double { precision: Option<u32>, scale: Option<u32> },
3644    Decimal { precision: Option<u32>, scale: Option<u32> },
3645
3646    // String
3647    Char { length: Option<u32> },
3648    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
3649    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
3650    VarChar { length: Option<u32>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] parenthesized_length: bool },
3651    /// String type with optional max length (BigQuery STRING(n))
3652    String { length: Option<u32> },
3653    Text,
3654
3655    // Binary
3656    Binary { length: Option<u32> },
3657    VarBinary { length: Option<u32> },
3658    Blob,
3659
3660    // Bit
3661    Bit { length: Option<u32> },
3662    VarBit { length: Option<u32> },
3663
3664    // Date/Time
3665    Date,
3666    Time { precision: Option<u32>, #[serde(default)] timezone: bool },
3667    Timestamp { precision: Option<u32>, timezone: bool },
3668    Interval {
3669        unit: Option<String>,
3670        /// For range intervals like INTERVAL DAY TO HOUR
3671        #[serde(default, skip_serializing_if = "Option::is_none")]
3672        to: Option<String>,
3673    },
3674
3675    // JSON
3676    Json,
3677    JsonB,
3678
3679    // UUID
3680    Uuid,
3681
3682    // Array
3683    Array {
3684        element_type: Box<DataType>,
3685        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3686        #[serde(default, skip_serializing_if = "Option::is_none")]
3687        dimension: Option<u32>,
3688    },
3689
3690    /// List type (Materialize): INT LIST, TEXT LIST LIST
3691    /// Uses postfix LIST syntax instead of ARRAY<T>
3692    List {
3693        element_type: Box<DataType>,
3694    },
3695
3696    // Struct/Map
3697    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3698    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3699    Struct { fields: Vec<StructField>, nested: bool },
3700    Map { key_type: Box<DataType>, value_type: Box<DataType> },
3701
3702    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3703    Enum { values: Vec<String>, #[serde(default, skip_serializing_if = "Vec::is_empty")] assignments: Vec<Option<String>> },
3704
3705    // Set type (MySQL): SET('a', 'b', 'c')
3706    Set { values: Vec<String> },
3707
3708    // Union type (DuckDB): UNION(num INT, str TEXT)
3709    Union { fields: Vec<(String, DataType)> },
3710
3711    // Vector (Snowflake / SingleStore)
3712    Vector { #[serde(default)] element_type: Option<Box<DataType>>, dimension: Option<u32> },
3713
3714    // Object (Snowflake structured type)
3715    // fields: Vec of (field_name, field_type, not_null)
3716    Object { fields: Vec<(String, DataType, bool)>, modifier: Option<String> },
3717
3718    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
3719    Nullable { inner: Box<DataType> },
3720
3721    // Custom/User-defined
3722    Custom { name: String },
3723
3724    // Spatial types
3725    Geometry {
3726        subtype: Option<String>,
3727        srid: Option<u32>,
3728    },
3729    Geography {
3730        subtype: Option<String>,
3731        srid: Option<u32>,
3732    },
3733
3734    // Character Set (for CONVERT USING in MySQL)
3735    // Renders as CHAR CHARACTER SET {name} in cast target
3736    CharacterSet { name: String },
3737
3738    // Unknown
3739    Unknown,
3740}
3741
3742/// Array expression
3743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3744#[cfg_attr(feature = "bindings", derive(TS))]
3745#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3746pub struct Array {
3747    pub expressions: Vec<Expression>,
3748}
3749
3750/// Struct expression
3751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3752#[cfg_attr(feature = "bindings", derive(TS))]
3753pub struct Struct {
3754    pub fields: Vec<(Option<String>, Expression)>,
3755}
3756
3757/// Tuple expression
3758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3759#[cfg_attr(feature = "bindings", derive(TS))]
3760pub struct Tuple {
3761    pub expressions: Vec<Expression>,
3762}
3763
3764/// Interval expression
3765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3766#[cfg_attr(feature = "bindings", derive(TS))]
3767pub struct Interval {
3768    /// The value expression (e.g., '1', 5, column_ref)
3769    pub this: Option<Expression>,
3770    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3771    pub unit: Option<IntervalUnitSpec>,
3772}
3773
3774/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3776#[cfg_attr(feature = "bindings", derive(TS))]
3777#[serde(tag = "type", rename_all = "snake_case")]
3778pub enum IntervalUnitSpec {
3779    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3780    Simple {
3781        unit: IntervalUnit,
3782        /// Whether to use plural form (e.g., DAYS vs DAY)
3783        use_plural: bool,
3784    },
3785    /// Interval span (e.g., HOUR TO SECOND)
3786    Span(IntervalSpan),
3787    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3788    /// The start and end can be expressions like function calls with precision
3789    ExprSpan(IntervalSpanExpr),
3790    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3791    Expr(Box<Expression>),
3792}
3793
3794/// Interval span for ranges like HOUR TO SECOND
3795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3796#[cfg_attr(feature = "bindings", derive(TS))]
3797pub struct IntervalSpan {
3798    /// Start unit (e.g., HOUR)
3799    pub this: IntervalUnit,
3800    /// End unit (e.g., SECOND)
3801    pub expression: IntervalUnit,
3802}
3803
3804/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3805/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3807#[cfg_attr(feature = "bindings", derive(TS))]
3808pub struct IntervalSpanExpr {
3809    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3810    pub this: Box<Expression>,
3811    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
3812    pub expression: Box<Expression>,
3813}
3814
3815#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3816#[cfg_attr(feature = "bindings", derive(TS))]
3817pub enum IntervalUnit {
3818    Year,
3819    Quarter,
3820    Month,
3821    Week,
3822    Day,
3823    Hour,
3824    Minute,
3825    Second,
3826    Millisecond,
3827    Microsecond,
3828}
3829
3830/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
3831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3832#[cfg_attr(feature = "bindings", derive(TS))]
3833pub struct Command {
3834    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
3835    pub this: String,
3836}
3837
3838/// EXEC/EXECUTE statement (TSQL stored procedure call)
3839/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
3840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3841#[cfg_attr(feature = "bindings", derive(TS))]
3842pub struct ExecuteStatement {
3843    /// The procedure name (can be qualified: schema.proc_name)
3844    pub this: Expression,
3845    /// Named parameters: @param=value pairs
3846    #[serde(default)]
3847    pub parameters: Vec<ExecuteParameter>,
3848}
3849
3850/// Named parameter in EXEC statement: @name=value
3851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3852#[cfg_attr(feature = "bindings", derive(TS))]
3853pub struct ExecuteParameter {
3854    /// Parameter name (including @)
3855    pub name: String,
3856    /// Parameter value
3857    pub value: Expression,
3858}
3859
3860/// KILL statement (MySQL/MariaDB)
3861/// KILL [CONNECTION | QUERY] <id>
3862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3863#[cfg_attr(feature = "bindings", derive(TS))]
3864pub struct Kill {
3865    /// The target (process ID or connection ID)
3866    pub this: Expression,
3867    /// Optional kind: "CONNECTION" or "QUERY"
3868    pub kind: Option<String>,
3869}
3870
3871/// Raw/unparsed SQL
3872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3873#[cfg_attr(feature = "bindings", derive(TS))]
3874pub struct Raw {
3875    pub sql: String,
3876}
3877
3878// ============================================================================
3879// Function expression types
3880// ============================================================================
3881
3882/// Generic unary function (takes a single argument)
3883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3884#[cfg_attr(feature = "bindings", derive(TS))]
3885pub struct UnaryFunc {
3886    pub this: Expression,
3887    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
3888    #[serde(skip_serializing_if = "Option::is_none", default)]
3889    pub original_name: Option<String>,
3890}
3891
3892impl UnaryFunc {
3893    /// Create a new UnaryFunc with no original_name
3894    pub fn new(this: Expression) -> Self {
3895        Self { this, original_name: None }
3896    }
3897
3898    /// Create a new UnaryFunc with an original name for round-trip preservation
3899    pub fn with_name(this: Expression, name: String) -> Self {
3900        Self { this, original_name: Some(name) }
3901    }
3902}
3903
3904/// CHAR/CHR function with multiple args and optional USING charset
3905/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
3906/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
3907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3908#[cfg_attr(feature = "bindings", derive(TS))]
3909pub struct CharFunc {
3910    pub args: Vec<Expression>,
3911    #[serde(skip_serializing_if = "Option::is_none", default)]
3912    pub charset: Option<String>,
3913    /// Original function name (CHAR or CHR), defaults to CHAR
3914    #[serde(skip_serializing_if = "Option::is_none", default)]
3915    pub name: Option<String>,
3916}
3917
3918/// Generic binary function (takes two arguments)
3919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3920#[cfg_attr(feature = "bindings", derive(TS))]
3921pub struct BinaryFunc {
3922    pub this: Expression,
3923    pub expression: Expression,
3924    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
3925    #[serde(skip_serializing_if = "Option::is_none", default)]
3926    pub original_name: Option<String>,
3927}
3928
3929/// Variable argument function
3930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3931#[cfg_attr(feature = "bindings", derive(TS))]
3932pub struct VarArgFunc {
3933    pub expressions: Vec<Expression>,
3934    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
3935    #[serde(skip_serializing_if = "Option::is_none", default)]
3936    pub original_name: Option<String>,
3937}
3938
3939/// CONCAT_WS function
3940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3941#[cfg_attr(feature = "bindings", derive(TS))]
3942pub struct ConcatWs {
3943    pub separator: Expression,
3944    pub expressions: Vec<Expression>,
3945}
3946
3947/// SUBSTRING function
3948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3949#[cfg_attr(feature = "bindings", derive(TS))]
3950pub struct SubstringFunc {
3951    pub this: Expression,
3952    pub start: Expression,
3953    pub length: Option<Expression>,
3954    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
3955    #[serde(default)]
3956    pub from_for_syntax: bool,
3957}
3958
3959/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
3960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3961#[cfg_attr(feature = "bindings", derive(TS))]
3962pub struct OverlayFunc {
3963    pub this: Expression,
3964    pub replacement: Expression,
3965    pub from: Expression,
3966    pub length: Option<Expression>,
3967}
3968
3969/// TRIM function
3970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3971#[cfg_attr(feature = "bindings", derive(TS))]
3972pub struct TrimFunc {
3973    pub this: Expression,
3974    pub characters: Option<Expression>,
3975    pub position: TrimPosition,
3976    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
3977    #[serde(default)]
3978    pub sql_standard_syntax: bool,
3979    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
3980    #[serde(default)]
3981    pub position_explicit: bool,
3982}
3983
3984#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3985#[cfg_attr(feature = "bindings", derive(TS))]
3986pub enum TrimPosition {
3987    Both,
3988    Leading,
3989    Trailing,
3990}
3991
3992/// REPLACE function
3993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3994#[cfg_attr(feature = "bindings", derive(TS))]
3995pub struct ReplaceFunc {
3996    pub this: Expression,
3997    pub old: Expression,
3998    pub new: Expression,
3999}
4000
4001/// LEFT/RIGHT function
4002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4003#[cfg_attr(feature = "bindings", derive(TS))]
4004pub struct LeftRightFunc {
4005    pub this: Expression,
4006    pub length: Expression,
4007}
4008
4009/// REPEAT function
4010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4011#[cfg_attr(feature = "bindings", derive(TS))]
4012pub struct RepeatFunc {
4013    pub this: Expression,
4014    pub times: Expression,
4015}
4016
4017/// LPAD/RPAD function
4018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4019#[cfg_attr(feature = "bindings", derive(TS))]
4020pub struct PadFunc {
4021    pub this: Expression,
4022    pub length: Expression,
4023    pub fill: Option<Expression>,
4024}
4025
4026/// SPLIT function
4027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4028#[cfg_attr(feature = "bindings", derive(TS))]
4029pub struct SplitFunc {
4030    pub this: Expression,
4031    pub delimiter: Expression,
4032}
4033
4034/// REGEXP_LIKE function
4035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4036#[cfg_attr(feature = "bindings", derive(TS))]
4037pub struct RegexpFunc {
4038    pub this: Expression,
4039    pub pattern: Expression,
4040    pub flags: Option<Expression>,
4041}
4042
4043/// REGEXP_REPLACE function
4044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4045#[cfg_attr(feature = "bindings", derive(TS))]
4046pub struct RegexpReplaceFunc {
4047    pub this: Expression,
4048    pub pattern: Expression,
4049    pub replacement: Expression,
4050    pub flags: Option<Expression>,
4051}
4052
4053/// REGEXP_EXTRACT function
4054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4055#[cfg_attr(feature = "bindings", derive(TS))]
4056pub struct RegexpExtractFunc {
4057    pub this: Expression,
4058    pub pattern: Expression,
4059    pub group: Option<Expression>,
4060}
4061
4062/// ROUND function
4063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4064#[cfg_attr(feature = "bindings", derive(TS))]
4065pub struct RoundFunc {
4066    pub this: Expression,
4067    pub decimals: Option<Expression>,
4068}
4069
4070/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4072#[cfg_attr(feature = "bindings", derive(TS))]
4073pub struct FloorFunc {
4074    pub this: Expression,
4075    pub scale: Option<Expression>,
4076    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4077    #[serde(skip_serializing_if = "Option::is_none", default)]
4078    pub to: Option<Expression>,
4079}
4080
4081/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4083#[cfg_attr(feature = "bindings", derive(TS))]
4084pub struct CeilFunc {
4085    pub this: Expression,
4086    #[serde(skip_serializing_if = "Option::is_none", default)]
4087    pub decimals: Option<Expression>,
4088    /// Time unit for Druid-style CEIL(time TO unit) syntax
4089    #[serde(skip_serializing_if = "Option::is_none", default)]
4090    pub to: Option<Expression>,
4091}
4092
4093/// LOG function
4094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4095#[cfg_attr(feature = "bindings", derive(TS))]
4096pub struct LogFunc {
4097    pub this: Expression,
4098    pub base: Option<Expression>,
4099}
4100
4101/// CURRENT_DATE (no arguments)
4102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4103#[cfg_attr(feature = "bindings", derive(TS))]
4104pub struct CurrentDate;
4105
4106/// CURRENT_TIME
4107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4108#[cfg_attr(feature = "bindings", derive(TS))]
4109pub struct CurrentTime {
4110    pub precision: Option<u32>,
4111}
4112
4113/// CURRENT_TIMESTAMP
4114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4115#[cfg_attr(feature = "bindings", derive(TS))]
4116pub struct CurrentTimestamp {
4117    pub precision: Option<u32>,
4118    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4119    #[serde(default)]
4120    pub sysdate: bool,
4121}
4122
4123/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4125#[cfg_attr(feature = "bindings", derive(TS))]
4126pub struct CurrentTimestampLTZ {
4127    pub precision: Option<u32>,
4128}
4129
4130/// AT TIME ZONE expression for timezone conversion
4131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4132#[cfg_attr(feature = "bindings", derive(TS))]
4133pub struct AtTimeZone {
4134    /// The expression to convert
4135    pub this: Expression,
4136    /// The target timezone
4137    pub zone: Expression,
4138}
4139
4140/// DATE_ADD / DATE_SUB function
4141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4142#[cfg_attr(feature = "bindings", derive(TS))]
4143pub struct DateAddFunc {
4144    pub this: Expression,
4145    pub interval: Expression,
4146    pub unit: IntervalUnit,
4147}
4148
4149/// DATEDIFF function
4150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4151#[cfg_attr(feature = "bindings", derive(TS))]
4152pub struct DateDiffFunc {
4153    pub this: Expression,
4154    pub expression: Expression,
4155    pub unit: Option<IntervalUnit>,
4156}
4157
4158/// DATE_TRUNC function
4159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4160#[cfg_attr(feature = "bindings", derive(TS))]
4161pub struct DateTruncFunc {
4162    pub this: Expression,
4163    pub unit: DateTimeField,
4164}
4165
4166/// EXTRACT function
4167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4168#[cfg_attr(feature = "bindings", derive(TS))]
4169pub struct ExtractFunc {
4170    pub this: Expression,
4171    pub field: DateTimeField,
4172}
4173
4174#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4175#[cfg_attr(feature = "bindings", derive(TS))]
4176pub enum DateTimeField {
4177    Year,
4178    Month,
4179    Day,
4180    Hour,
4181    Minute,
4182    Second,
4183    Millisecond,
4184    Microsecond,
4185    DayOfWeek,
4186    DayOfYear,
4187    Week,
4188    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4189    WeekWithModifier(String),
4190    Quarter,
4191    Epoch,
4192    Timezone,
4193    TimezoneHour,
4194    TimezoneMinute,
4195    Date,
4196    Time,
4197    /// Custom datetime field for dialect-specific or arbitrary fields
4198    Custom(String),
4199}
4200
4201/// TO_DATE function
4202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4203#[cfg_attr(feature = "bindings", derive(TS))]
4204pub struct ToDateFunc {
4205    pub this: Expression,
4206    pub format: Option<Expression>,
4207}
4208
4209/// TO_TIMESTAMP function
4210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4211#[cfg_attr(feature = "bindings", derive(TS))]
4212pub struct ToTimestampFunc {
4213    pub this: Expression,
4214    pub format: Option<Expression>,
4215}
4216
4217/// IF function
4218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4219#[cfg_attr(feature = "bindings", derive(TS))]
4220pub struct IfFunc {
4221    pub condition: Expression,
4222    pub true_value: Expression,
4223    pub false_value: Option<Expression>,
4224    /// Original function name (IF, IFF, IIF) for round-trip preservation
4225    #[serde(skip_serializing_if = "Option::is_none", default)]
4226    pub original_name: Option<String>,
4227}
4228
4229/// NVL2 function
4230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4231#[cfg_attr(feature = "bindings", derive(TS))]
4232pub struct Nvl2Func {
4233    pub this: Expression,
4234    pub true_value: Expression,
4235    pub false_value: Expression,
4236}
4237
4238// ============================================================================
4239// Typed Aggregate Function types
4240// ============================================================================
4241
4242/// Generic aggregate function base type
4243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4244#[cfg_attr(feature = "bindings", derive(TS))]
4245pub struct AggFunc {
4246    pub this: Expression,
4247    pub distinct: bool,
4248    pub filter: Option<Expression>,
4249    pub order_by: Vec<Ordered>,
4250    /// Original function name (case-preserving) when parsed from SQL
4251    #[serde(skip_serializing_if = "Option::is_none", default)]
4252    pub name: Option<String>,
4253    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4254    #[serde(skip_serializing_if = "Option::is_none", default)]
4255    pub ignore_nulls: Option<bool>,
4256    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4257    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4258    #[serde(skip_serializing_if = "Option::is_none", default)]
4259    pub having_max: Option<(Box<Expression>, bool)>,
4260    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4261    #[serde(skip_serializing_if = "Option::is_none", default)]
4262    pub limit: Option<Box<Expression>>,
4263}
4264
4265/// COUNT function with optional star
4266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4267#[cfg_attr(feature = "bindings", derive(TS))]
4268pub struct CountFunc {
4269    pub this: Option<Expression>,
4270    pub star: bool,
4271    pub distinct: bool,
4272    pub filter: Option<Expression>,
4273    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4274    #[serde(default, skip_serializing_if = "Option::is_none")]
4275    pub ignore_nulls: Option<bool>,
4276    /// Original function name for case preservation (e.g., "count" or "COUNT")
4277    #[serde(default, skip_serializing_if = "Option::is_none")]
4278    pub original_name: Option<String>,
4279}
4280
4281/// GROUP_CONCAT function (MySQL style)
4282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4283#[cfg_attr(feature = "bindings", derive(TS))]
4284pub struct GroupConcatFunc {
4285    pub this: Expression,
4286    pub separator: Option<Expression>,
4287    pub order_by: Option<Vec<Ordered>>,
4288    pub distinct: bool,
4289    pub filter: Option<Expression>,
4290}
4291
4292/// STRING_AGG function (PostgreSQL/Standard SQL)
4293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4294#[cfg_attr(feature = "bindings", derive(TS))]
4295pub struct StringAggFunc {
4296    pub this: Expression,
4297    #[serde(default)]
4298    pub separator: Option<Expression>,
4299    #[serde(default)]
4300    pub order_by: Option<Vec<Ordered>>,
4301    #[serde(default)]
4302    pub distinct: bool,
4303    #[serde(default)]
4304    pub filter: Option<Expression>,
4305    /// BigQuery LIMIT inside STRING_AGG
4306    #[serde(default, skip_serializing_if = "Option::is_none")]
4307    pub limit: Option<Box<Expression>>,
4308}
4309
4310/// LISTAGG function (Oracle style)
4311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4312#[cfg_attr(feature = "bindings", derive(TS))]
4313pub struct ListAggFunc {
4314    pub this: Expression,
4315    pub separator: Option<Expression>,
4316    pub on_overflow: Option<ListAggOverflow>,
4317    pub order_by: Option<Vec<Ordered>>,
4318    pub distinct: bool,
4319    pub filter: Option<Expression>,
4320}
4321
4322/// LISTAGG ON OVERFLOW behavior
4323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4324#[cfg_attr(feature = "bindings", derive(TS))]
4325pub enum ListAggOverflow {
4326    Error,
4327    Truncate {
4328        filler: Option<Expression>,
4329        with_count: bool,
4330    },
4331}
4332
4333/// SUM_IF / COUNT_IF function
4334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4335#[cfg_attr(feature = "bindings", derive(TS))]
4336pub struct SumIfFunc {
4337    pub this: Expression,
4338    pub condition: Expression,
4339    pub filter: Option<Expression>,
4340}
4341
4342/// APPROX_PERCENTILE function
4343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4344#[cfg_attr(feature = "bindings", derive(TS))]
4345pub struct ApproxPercentileFunc {
4346    pub this: Expression,
4347    pub percentile: Expression,
4348    pub accuracy: Option<Expression>,
4349    pub filter: Option<Expression>,
4350}
4351
4352/// PERCENTILE_CONT / PERCENTILE_DISC function
4353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4354#[cfg_attr(feature = "bindings", derive(TS))]
4355pub struct PercentileFunc {
4356    pub this: Expression,
4357    pub percentile: Expression,
4358    pub order_by: Option<Vec<Ordered>>,
4359    pub filter: Option<Expression>,
4360}
4361
4362// ============================================================================
4363// Typed Window Function types
4364// ============================================================================
4365
4366/// ROW_NUMBER function (no arguments)
4367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4368#[cfg_attr(feature = "bindings", derive(TS))]
4369pub struct RowNumber;
4370
4371/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4373#[cfg_attr(feature = "bindings", derive(TS))]
4374pub struct Rank {
4375    /// DuckDB: RANK(ORDER BY col) - order by inside function
4376    #[serde(default, skip_serializing_if = "Option::is_none")]
4377    pub order_by: Option<Vec<Ordered>>,
4378    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4379    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4380    pub args: Vec<Expression>,
4381}
4382
4383/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4385#[cfg_attr(feature = "bindings", derive(TS))]
4386pub struct DenseRank {
4387    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4388    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4389    pub args: Vec<Expression>,
4390}
4391
4392/// NTILE function (DuckDB allows ORDER BY inside)
4393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4394#[cfg_attr(feature = "bindings", derive(TS))]
4395pub struct NTileFunc {
4396    /// num_buckets is optional to support Databricks NTILE() without arguments
4397    #[serde(default, skip_serializing_if = "Option::is_none")]
4398    pub num_buckets: Option<Expression>,
4399    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4400    #[serde(default, skip_serializing_if = "Option::is_none")]
4401    pub order_by: Option<Vec<Ordered>>,
4402}
4403
4404/// LEAD / LAG function
4405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4406#[cfg_attr(feature = "bindings", derive(TS))]
4407pub struct LeadLagFunc {
4408    pub this: Expression,
4409    pub offset: Option<Expression>,
4410    pub default: Option<Expression>,
4411    pub ignore_nulls: bool,
4412}
4413
4414/// FIRST_VALUE / LAST_VALUE function
4415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4416#[cfg_attr(feature = "bindings", derive(TS))]
4417pub struct ValueFunc {
4418    pub this: Expression,
4419    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4420    #[serde(default, skip_serializing_if = "Option::is_none")]
4421    pub ignore_nulls: Option<bool>,
4422}
4423
4424/// NTH_VALUE function
4425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4426#[cfg_attr(feature = "bindings", derive(TS))]
4427pub struct NthValueFunc {
4428    pub this: Expression,
4429    pub offset: Expression,
4430    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4431    #[serde(default, skip_serializing_if = "Option::is_none")]
4432    pub ignore_nulls: Option<bool>,
4433}
4434
4435/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4437#[cfg_attr(feature = "bindings", derive(TS))]
4438pub struct PercentRank {
4439    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4440    #[serde(default, skip_serializing_if = "Option::is_none")]
4441    pub order_by: Option<Vec<Ordered>>,
4442    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4443    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4444    pub args: Vec<Expression>,
4445}
4446
4447/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4449#[cfg_attr(feature = "bindings", derive(TS))]
4450pub struct CumeDist {
4451    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4452    #[serde(default, skip_serializing_if = "Option::is_none")]
4453    pub order_by: Option<Vec<Ordered>>,
4454    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4455    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4456    pub args: Vec<Expression>,
4457}
4458
4459// ============================================================================
4460// Additional String Function types
4461// ============================================================================
4462
4463/// POSITION/INSTR function
4464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4465#[cfg_attr(feature = "bindings", derive(TS))]
4466pub struct PositionFunc {
4467    pub substring: Expression,
4468    pub string: Expression,
4469    pub start: Option<Expression>,
4470}
4471
4472// ============================================================================
4473// Additional Math Function types
4474// ============================================================================
4475
4476/// RANDOM function (no arguments)
4477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4478#[cfg_attr(feature = "bindings", derive(TS))]
4479pub struct Random;
4480
4481/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4483#[cfg_attr(feature = "bindings", derive(TS))]
4484pub struct Rand {
4485    pub seed: Option<Box<Expression>>,
4486    /// Teradata RANDOM lower bound
4487    #[serde(default)]
4488    pub lower: Option<Box<Expression>>,
4489    /// Teradata RANDOM upper bound
4490    #[serde(default)]
4491    pub upper: Option<Box<Expression>>,
4492}
4493
4494/// TRUNCATE / TRUNC function
4495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4496#[cfg_attr(feature = "bindings", derive(TS))]
4497pub struct TruncateFunc {
4498    pub this: Expression,
4499    pub decimals: Option<Expression>,
4500}
4501
4502/// PI function (no arguments)
4503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4504#[cfg_attr(feature = "bindings", derive(TS))]
4505pub struct Pi;
4506
4507// ============================================================================
4508// Control Flow Function types
4509// ============================================================================
4510
4511/// DECODE function (Oracle style)
4512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4513#[cfg_attr(feature = "bindings", derive(TS))]
4514pub struct DecodeFunc {
4515    pub this: Expression,
4516    pub search_results: Vec<(Expression, Expression)>,
4517    pub default: Option<Expression>,
4518}
4519
4520// ============================================================================
4521// Additional Date/Time Function types
4522// ============================================================================
4523
4524/// DATE_FORMAT / FORMAT_DATE function
4525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4526#[cfg_attr(feature = "bindings", derive(TS))]
4527pub struct DateFormatFunc {
4528    pub this: Expression,
4529    pub format: Expression,
4530}
4531
4532/// FROM_UNIXTIME function
4533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4534#[cfg_attr(feature = "bindings", derive(TS))]
4535pub struct FromUnixtimeFunc {
4536    pub this: Expression,
4537    pub format: Option<Expression>,
4538}
4539
4540/// UNIX_TIMESTAMP function
4541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4542#[cfg_attr(feature = "bindings", derive(TS))]
4543pub struct UnixTimestampFunc {
4544    pub this: Option<Expression>,
4545    pub format: Option<Expression>,
4546}
4547
4548/// MAKE_DATE function
4549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4550#[cfg_attr(feature = "bindings", derive(TS))]
4551pub struct MakeDateFunc {
4552    pub year: Expression,
4553    pub month: Expression,
4554    pub day: Expression,
4555}
4556
4557/// MAKE_TIMESTAMP function
4558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4559#[cfg_attr(feature = "bindings", derive(TS))]
4560pub struct MakeTimestampFunc {
4561    pub year: Expression,
4562    pub month: Expression,
4563    pub day: Expression,
4564    pub hour: Expression,
4565    pub minute: Expression,
4566    pub second: Expression,
4567    pub timezone: Option<Expression>,
4568}
4569
4570/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4572#[cfg_attr(feature = "bindings", derive(TS))]
4573pub struct LastDayFunc {
4574    pub this: Expression,
4575    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4576    #[serde(skip_serializing_if = "Option::is_none", default)]
4577    pub unit: Option<DateTimeField>,
4578}
4579
4580// ============================================================================
4581// Array Function types
4582// ============================================================================
4583
4584/// ARRAY constructor
4585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4586#[cfg_attr(feature = "bindings", derive(TS))]
4587pub struct ArrayConstructor {
4588    pub expressions: Vec<Expression>,
4589    pub bracket_notation: bool,
4590    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4591    pub use_list_keyword: bool,
4592}
4593
4594/// ARRAY_SORT function
4595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4596#[cfg_attr(feature = "bindings", derive(TS))]
4597pub struct ArraySortFunc {
4598    pub this: Expression,
4599    pub comparator: Option<Expression>,
4600    pub desc: bool,
4601    pub nulls_first: Option<bool>,
4602}
4603
4604/// ARRAY_JOIN / ARRAY_TO_STRING function
4605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4606#[cfg_attr(feature = "bindings", derive(TS))]
4607pub struct ArrayJoinFunc {
4608    pub this: Expression,
4609    pub separator: Expression,
4610    pub null_replacement: Option<Expression>,
4611}
4612
4613/// UNNEST function
4614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4615#[cfg_attr(feature = "bindings", derive(TS))]
4616pub struct UnnestFunc {
4617    pub this: Expression,
4618    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4619    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4620    pub expressions: Vec<Expression>,
4621    pub with_ordinality: bool,
4622    pub alias: Option<Identifier>,
4623    /// BigQuery: offset alias for WITH OFFSET AS <name>
4624    #[serde(default, skip_serializing_if = "Option::is_none")]
4625    pub offset_alias: Option<Identifier>,
4626}
4627
4628/// ARRAY_FILTER function (with lambda)
4629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4630#[cfg_attr(feature = "bindings", derive(TS))]
4631pub struct ArrayFilterFunc {
4632    pub this: Expression,
4633    pub filter: Expression,
4634}
4635
4636/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4638#[cfg_attr(feature = "bindings", derive(TS))]
4639pub struct ArrayTransformFunc {
4640    pub this: Expression,
4641    pub transform: Expression,
4642}
4643
4644/// SEQUENCE / GENERATE_SERIES function
4645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4646#[cfg_attr(feature = "bindings", derive(TS))]
4647pub struct SequenceFunc {
4648    pub start: Expression,
4649    pub stop: Expression,
4650    pub step: Option<Expression>,
4651}
4652
4653// ============================================================================
4654// Struct Function types
4655// ============================================================================
4656
4657/// STRUCT constructor
4658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4659#[cfg_attr(feature = "bindings", derive(TS))]
4660pub struct StructConstructor {
4661    pub fields: Vec<(Option<Identifier>, Expression)>,
4662}
4663
4664/// STRUCT_EXTRACT function
4665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4666#[cfg_attr(feature = "bindings", derive(TS))]
4667pub struct StructExtractFunc {
4668    pub this: Expression,
4669    pub field: Identifier,
4670}
4671
4672/// NAMED_STRUCT function
4673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4674#[cfg_attr(feature = "bindings", derive(TS))]
4675pub struct NamedStructFunc {
4676    pub pairs: Vec<(Expression, Expression)>,
4677}
4678
4679// ============================================================================
4680// Map Function types
4681// ============================================================================
4682
4683/// MAP constructor
4684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4685#[cfg_attr(feature = "bindings", derive(TS))]
4686pub struct MapConstructor {
4687    pub keys: Vec<Expression>,
4688    pub values: Vec<Expression>,
4689    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4690    #[serde(default)]
4691    pub curly_brace_syntax: bool,
4692    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4693    #[serde(default)]
4694    pub with_map_keyword: bool,
4695}
4696
4697/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4699#[cfg_attr(feature = "bindings", derive(TS))]
4700pub struct TransformFunc {
4701    pub this: Expression,
4702    pub transform: Expression,
4703}
4704
4705// ============================================================================
4706// JSON Function types
4707// ============================================================================
4708
4709/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4711#[cfg_attr(feature = "bindings", derive(TS))]
4712pub struct JsonExtractFunc {
4713    pub this: Expression,
4714    pub path: Expression,
4715    pub returning: Option<DataType>,
4716    /// True if parsed from -> or ->> operator syntax
4717    #[serde(default)]
4718    pub arrow_syntax: bool,
4719    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4720    #[serde(default)]
4721    pub hash_arrow_syntax: bool,
4722    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4723    #[serde(default)]
4724    pub wrapper_option: Option<String>,
4725    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4726    #[serde(default)]
4727    pub quotes_option: Option<String>,
4728    /// ON SCALAR STRING flag
4729    #[serde(default)]
4730    pub on_scalar_string: bool,
4731    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4732    #[serde(default)]
4733    pub on_error: Option<String>,
4734}
4735
4736/// JSON path extraction
4737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4738#[cfg_attr(feature = "bindings", derive(TS))]
4739pub struct JsonPathFunc {
4740    pub this: Expression,
4741    pub paths: Vec<Expression>,
4742}
4743
4744/// JSON_OBJECT function
4745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4746#[cfg_attr(feature = "bindings", derive(TS))]
4747pub struct JsonObjectFunc {
4748    pub pairs: Vec<(Expression, Expression)>,
4749    pub null_handling: Option<JsonNullHandling>,
4750    #[serde(default)]
4751    pub with_unique_keys: bool,
4752    #[serde(default)]
4753    pub returning_type: Option<DataType>,
4754    #[serde(default)]
4755    pub format_json: bool,
4756    #[serde(default)]
4757    pub encoding: Option<String>,
4758    /// For JSON_OBJECT(*) syntax
4759    #[serde(default)]
4760    pub star: bool,
4761}
4762
4763/// JSON null handling options
4764#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4765#[cfg_attr(feature = "bindings", derive(TS))]
4766pub enum JsonNullHandling {
4767    NullOnNull,
4768    AbsentOnNull,
4769}
4770
4771/// JSON_SET / JSON_INSERT function
4772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4773#[cfg_attr(feature = "bindings", derive(TS))]
4774pub struct JsonModifyFunc {
4775    pub this: Expression,
4776    pub path_values: Vec<(Expression, Expression)>,
4777}
4778
4779/// JSON_ARRAYAGG function
4780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4781#[cfg_attr(feature = "bindings", derive(TS))]
4782pub struct JsonArrayAggFunc {
4783    pub this: Expression,
4784    pub order_by: Option<Vec<Ordered>>,
4785    pub null_handling: Option<JsonNullHandling>,
4786    pub filter: Option<Expression>,
4787}
4788
4789/// JSON_OBJECTAGG function
4790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4791#[cfg_attr(feature = "bindings", derive(TS))]
4792pub struct JsonObjectAggFunc {
4793    pub key: Expression,
4794    pub value: Expression,
4795    pub null_handling: Option<JsonNullHandling>,
4796    pub filter: Option<Expression>,
4797}
4798
4799// ============================================================================
4800// Type Casting Function types
4801// ============================================================================
4802
4803/// CONVERT function (SQL Server style)
4804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4805#[cfg_attr(feature = "bindings", derive(TS))]
4806pub struct ConvertFunc {
4807    pub this: Expression,
4808    pub to: DataType,
4809    pub style: Option<Expression>,
4810}
4811
4812// ============================================================================
4813// Additional Expression types
4814// ============================================================================
4815
4816/// Lambda expression
4817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4818#[cfg_attr(feature = "bindings", derive(TS))]
4819pub struct LambdaExpr {
4820    pub parameters: Vec<Identifier>,
4821    pub body: Expression,
4822    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
4823    #[serde(default)]
4824    pub colon: bool,
4825    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
4826    /// Maps parameter index to data type
4827    #[serde(default)]
4828    pub parameter_types: Vec<Option<DataType>>,
4829}
4830
4831/// Parameter (parameterized queries)
4832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4833#[cfg_attr(feature = "bindings", derive(TS))]
4834pub struct Parameter {
4835    pub name: Option<String>,
4836    pub index: Option<u32>,
4837    pub style: ParameterStyle,
4838    /// Whether the name was quoted (e.g., @"x" vs @x)
4839    #[serde(default)]
4840    pub quoted: bool,
4841    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
4842    #[serde(default)]
4843    pub expression: Option<String>,
4844}
4845
4846/// Parameter placeholder styles
4847#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4848#[cfg_attr(feature = "bindings", derive(TS))]
4849pub enum ParameterStyle {
4850    Question,        // ?
4851    Dollar,          // $1, $2
4852    DollarBrace,     // ${name} (Databricks, Hive template variables)
4853    Brace,           // {name} (Spark/Databricks widget/template variables)
4854    Colon,           // :name
4855    At,              // @name
4856    DoubleAt,        // @@name (system variables in MySQL/SQL Server)
4857    DoubleDollar,    // $$name
4858    Percent,         // %s, %(name)s (PostgreSQL psycopg2 style)
4859}
4860
4861/// Placeholder expression
4862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4863#[cfg_attr(feature = "bindings", derive(TS))]
4864pub struct Placeholder {
4865    pub index: Option<u32>,
4866}
4867
4868/// Named argument in function call: name => value or name := value
4869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4870#[cfg_attr(feature = "bindings", derive(TS))]
4871pub struct NamedArgument {
4872    pub name: Identifier,
4873    pub value: Expression,
4874    /// The separator used: `=>`, `:=`, or `=`
4875    pub separator: NamedArgSeparator,
4876}
4877
4878/// Separator style for named arguments
4879#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4880#[cfg_attr(feature = "bindings", derive(TS))]
4881pub enum NamedArgSeparator {
4882    /// `=>` (standard SQL, Snowflake, BigQuery)
4883    DArrow,
4884    /// `:=` (Oracle, MySQL)
4885    ColonEq,
4886    /// `=` (simple equals, some dialects)
4887    Eq,
4888}
4889
4890/// TABLE ref or MODEL ref used as a function argument (BigQuery)
4891/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
4892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4893#[cfg_attr(feature = "bindings", derive(TS))]
4894pub struct TableArgument {
4895    /// The keyword prefix: "TABLE" or "MODEL"
4896    pub prefix: String,
4897    /// The table/model reference expression
4898    pub this: Expression,
4899}
4900
4901/// SQL Comment preservation
4902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4903#[cfg_attr(feature = "bindings", derive(TS))]
4904pub struct SqlComment {
4905    pub text: String,
4906    pub is_block: bool,
4907}
4908
4909// ============================================================================
4910// Additional Predicate types
4911// ============================================================================
4912
4913/// SIMILAR TO expression
4914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4915#[cfg_attr(feature = "bindings", derive(TS))]
4916pub struct SimilarToExpr {
4917    pub this: Expression,
4918    pub pattern: Expression,
4919    pub escape: Option<Expression>,
4920    pub not: bool,
4921}
4922
4923/// ANY / ALL quantified expression
4924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4925#[cfg_attr(feature = "bindings", derive(TS))]
4926pub struct QuantifiedExpr {
4927    pub this: Expression,
4928    pub subquery: Expression,
4929    pub op: Option<QuantifiedOp>,
4930}
4931
4932/// Comparison operator for quantified expressions
4933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4934#[cfg_attr(feature = "bindings", derive(TS))]
4935pub enum QuantifiedOp {
4936    Eq,
4937    Neq,
4938    Lt,
4939    Lte,
4940    Gt,
4941    Gte,
4942}
4943
4944/// OVERLAPS expression
4945/// Supports two forms:
4946/// 1. Simple binary: a OVERLAPS b (this, expression are set)
4947/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
4948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4949#[cfg_attr(feature = "bindings", derive(TS))]
4950pub struct OverlapsExpr {
4951    /// Left operand for simple binary form
4952    #[serde(skip_serializing_if = "Option::is_none")]
4953    pub this: Option<Expression>,
4954    /// Right operand for simple binary form
4955    #[serde(skip_serializing_if = "Option::is_none")]
4956    pub expression: Option<Expression>,
4957    /// Left range start for full ANSI form
4958    #[serde(skip_serializing_if = "Option::is_none")]
4959    pub left_start: Option<Expression>,
4960    /// Left range end for full ANSI form
4961    #[serde(skip_serializing_if = "Option::is_none")]
4962    pub left_end: Option<Expression>,
4963    /// Right range start for full ANSI form
4964    #[serde(skip_serializing_if = "Option::is_none")]
4965    pub right_start: Option<Expression>,
4966    /// Right range end for full ANSI form
4967    #[serde(skip_serializing_if = "Option::is_none")]
4968    pub right_end: Option<Expression>,
4969}
4970
4971// ============================================================================
4972// Array/Struct/Map access
4973// ============================================================================
4974
4975/// Subscript access (array[index] or map[key])
4976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4977#[cfg_attr(feature = "bindings", derive(TS))]
4978pub struct Subscript {
4979    pub this: Expression,
4980    pub index: Expression,
4981}
4982
4983/// Dot access (struct.field)
4984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4985#[cfg_attr(feature = "bindings", derive(TS))]
4986pub struct DotAccess {
4987    pub this: Expression,
4988    pub field: Identifier,
4989}
4990
4991/// Method call (expr.method(args))
4992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4993#[cfg_attr(feature = "bindings", derive(TS))]
4994pub struct MethodCall {
4995    pub this: Expression,
4996    pub method: Identifier,
4997    pub args: Vec<Expression>,
4998}
4999
5000/// Array slice (array[start:end])
5001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5002#[cfg_attr(feature = "bindings", derive(TS))]
5003pub struct ArraySlice {
5004    pub this: Expression,
5005    pub start: Option<Expression>,
5006    pub end: Option<Expression>,
5007}
5008
5009// ============================================================================
5010// DDL (Data Definition Language) Statements
5011// ============================================================================
5012
5013/// ON COMMIT behavior for temporary tables
5014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5015#[cfg_attr(feature = "bindings", derive(TS))]
5016pub enum OnCommit {
5017    /// ON COMMIT PRESERVE ROWS
5018    PreserveRows,
5019    /// ON COMMIT DELETE ROWS
5020    DeleteRows,
5021}
5022
5023/// CREATE TABLE statement
5024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5025#[cfg_attr(feature = "bindings", derive(TS))]
5026pub struct CreateTable {
5027    pub name: TableRef,
5028    /// ClickHouse: ON CLUSTER clause for distributed DDL
5029    #[serde(default, skip_serializing_if = "Option::is_none")]
5030    pub on_cluster: Option<OnCluster>,
5031    pub columns: Vec<ColumnDef>,
5032    pub constraints: Vec<TableConstraint>,
5033    pub if_not_exists: bool,
5034    pub temporary: bool,
5035    pub or_replace: bool,
5036    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5037    #[serde(default, skip_serializing_if = "Option::is_none")]
5038    pub table_modifier: Option<String>,
5039    pub as_select: Option<Expression>,
5040    /// Whether the AS SELECT was wrapped in parentheses
5041    #[serde(default)]
5042    pub as_select_parenthesized: bool,
5043    /// ON COMMIT behavior for temporary tables
5044    #[serde(default)]
5045    pub on_commit: Option<OnCommit>,
5046    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5047    #[serde(default)]
5048    pub clone_source: Option<TableRef>,
5049    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5050    #[serde(default, skip_serializing_if = "Option::is_none")]
5051    pub clone_at_clause: Option<Expression>,
5052    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5053    #[serde(default)]
5054    pub is_copy: bool,
5055    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5056    #[serde(default)]
5057    pub shallow_clone: bool,
5058    /// Leading comments before the statement
5059    #[serde(default)]
5060    pub leading_comments: Vec<String>,
5061    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5062    #[serde(default)]
5063    pub with_properties: Vec<(String, String)>,
5064    /// Teradata: table options after name before columns (comma-separated)
5065    #[serde(default)]
5066    pub teradata_post_name_options: Vec<String>,
5067    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5068    #[serde(default)]
5069    pub with_data: Option<bool>,
5070    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5071    #[serde(default)]
5072    pub with_statistics: Option<bool>,
5073    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5074    #[serde(default)]
5075    pub teradata_indexes: Vec<TeradataIndex>,
5076    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5077    #[serde(default)]
5078    pub with_cte: Option<With>,
5079    /// Table properties like DEFAULT COLLATE (BigQuery)
5080    #[serde(default)]
5081    pub properties: Vec<Expression>,
5082    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5083    #[serde(default, skip_serializing_if = "Option::is_none")]
5084    pub partition_of: Option<Expression>,
5085    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5086    #[serde(default)]
5087    pub post_table_properties: Vec<Expression>,
5088    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5089    #[serde(default)]
5090    pub mysql_table_options: Vec<(String, String)>,
5091    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5092    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5093    pub inherits: Vec<TableRef>,
5094    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5095    #[serde(default, skip_serializing_if = "Option::is_none")]
5096    pub on_property: Option<OnProperty>,
5097    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5098    #[serde(default)]
5099    pub copy_grants: bool,
5100    /// Snowflake: USING TEMPLATE expression for schema inference
5101    #[serde(default, skip_serializing_if = "Option::is_none")]
5102    pub using_template: Option<Box<Expression>>,
5103    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5104    #[serde(default, skip_serializing_if = "Option::is_none")]
5105    pub rollup: Option<RollupProperty>,
5106}
5107
5108/// Teradata index specification for CREATE TABLE
5109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5110#[cfg_attr(feature = "bindings", derive(TS))]
5111pub struct TeradataIndex {
5112    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5113    pub kind: TeradataIndexKind,
5114    /// Optional index name
5115    pub name: Option<String>,
5116    /// Optional column list
5117    pub columns: Vec<String>,
5118}
5119
5120/// Kind of Teradata index
5121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5122#[cfg_attr(feature = "bindings", derive(TS))]
5123pub enum TeradataIndexKind {
5124    /// NO PRIMARY INDEX
5125    NoPrimary,
5126    /// PRIMARY INDEX
5127    Primary,
5128    /// PRIMARY AMP INDEX
5129    PrimaryAmp,
5130    /// UNIQUE INDEX
5131    Unique,
5132    /// UNIQUE PRIMARY INDEX
5133    UniquePrimary,
5134    /// INDEX (secondary, non-primary)
5135    Secondary,
5136}
5137
5138impl CreateTable {
5139    pub fn new(name: impl Into<String>) -> Self {
5140        Self {
5141            name: TableRef::new(name),
5142            on_cluster: None,
5143            columns: Vec::new(),
5144            constraints: Vec::new(),
5145            if_not_exists: false,
5146            temporary: false,
5147            or_replace: false,
5148            table_modifier: None,
5149            as_select: None,
5150            as_select_parenthesized: false,
5151            on_commit: None,
5152            clone_source: None,
5153            clone_at_clause: None,
5154            shallow_clone: false, is_copy: false,
5155            leading_comments: Vec::new(),
5156            with_properties: Vec::new(),
5157            teradata_post_name_options: Vec::new(),
5158            with_data: None,
5159            with_statistics: None,
5160            teradata_indexes: Vec::new(),
5161            with_cte: None,
5162            properties: Vec::new(),
5163            partition_of: None,
5164            post_table_properties: Vec::new(),
5165            mysql_table_options: Vec::new(),
5166            inherits: Vec::new(),
5167            on_property: None,
5168            copy_grants: false,
5169            using_template: None,
5170            rollup: None,
5171        }
5172    }
5173}
5174
5175/// Sort order for PRIMARY KEY ASC/DESC
5176#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5177#[cfg_attr(feature = "bindings", derive(TS))]
5178pub enum SortOrder {
5179    Asc,
5180    Desc,
5181}
5182
5183/// Type of column constraint for tracking order
5184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5185#[cfg_attr(feature = "bindings", derive(TS))]
5186pub enum ConstraintType {
5187    NotNull,
5188    Null,
5189    PrimaryKey,
5190    Unique,
5191    Default,
5192    AutoIncrement,
5193    Collate,
5194    Comment,
5195    References,
5196    Check,
5197    GeneratedAsIdentity,
5198    /// Snowflake: TAG (key='value', ...)
5199    Tags,
5200    /// Computed/generated column
5201    ComputedColumn,
5202    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5203    GeneratedAsRow,
5204    /// MySQL: ON UPDATE expression
5205    OnUpdate,
5206    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5207    Path,
5208    /// Redshift: ENCODE encoding_type
5209    Encode,
5210}
5211
5212/// Column definition in CREATE TABLE
5213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5214#[cfg_attr(feature = "bindings", derive(TS))]
5215pub struct ColumnDef {
5216    pub name: Identifier,
5217    pub data_type: DataType,
5218    pub nullable: Option<bool>,
5219    pub default: Option<Expression>,
5220    pub primary_key: bool,
5221    /// Sort order for PRIMARY KEY (ASC/DESC)
5222    #[serde(default)]
5223    pub primary_key_order: Option<SortOrder>,
5224    pub unique: bool,
5225    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5226    #[serde(default)]
5227    pub unique_nulls_not_distinct: bool,
5228    pub auto_increment: bool,
5229    pub comment: Option<String>,
5230    pub constraints: Vec<ColumnConstraint>,
5231    /// Track original order of constraints for accurate regeneration
5232    #[serde(default)]
5233    pub constraint_order: Vec<ConstraintType>,
5234    /// Teradata: FORMAT 'pattern'
5235    #[serde(default)]
5236    pub format: Option<String>,
5237    /// Teradata: TITLE 'title'
5238    #[serde(default)]
5239    pub title: Option<String>,
5240    /// Teradata: INLINE LENGTH n
5241    #[serde(default)]
5242    pub inline_length: Option<u64>,
5243    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5244    #[serde(default)]
5245    pub compress: Option<Vec<Expression>>,
5246    /// Teradata: CHARACTER SET name
5247    #[serde(default)]
5248    pub character_set: Option<String>,
5249    /// Teradata: UPPERCASE
5250    #[serde(default)]
5251    pub uppercase: bool,
5252    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5253    #[serde(default)]
5254    pub casespecific: Option<bool>,
5255    /// Snowflake: AUTOINCREMENT START value
5256    #[serde(default)]
5257    pub auto_increment_start: Option<Box<Expression>>,
5258    /// Snowflake: AUTOINCREMENT INCREMENT value
5259    #[serde(default)]
5260    pub auto_increment_increment: Option<Box<Expression>>,
5261    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5262    #[serde(default)]
5263    pub auto_increment_order: Option<bool>,
5264    /// MySQL: UNSIGNED modifier
5265    #[serde(default)]
5266    pub unsigned: bool,
5267    /// MySQL: ZEROFILL modifier
5268    #[serde(default)]
5269    pub zerofill: bool,
5270    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5271    #[serde(default, skip_serializing_if = "Option::is_none")]
5272    pub on_update: Option<Expression>,
5273    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5274    #[serde(default, skip_serializing_if = "Option::is_none")]
5275    pub unique_constraint_name: Option<String>,
5276    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5277    #[serde(default, skip_serializing_if = "Option::is_none")]
5278    pub not_null_constraint_name: Option<String>,
5279    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5280    #[serde(default, skip_serializing_if = "Option::is_none")]
5281    pub primary_key_constraint_name: Option<String>,
5282    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5283    #[serde(default, skip_serializing_if = "Option::is_none")]
5284    pub check_constraint_name: Option<String>,
5285    /// BigQuery: OPTIONS (key=value, ...) on column
5286    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5287    pub options: Vec<Expression>,
5288    /// SQLite: Column definition without explicit type
5289    #[serde(default)]
5290    pub no_type: bool,
5291    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5292    #[serde(default, skip_serializing_if = "Option::is_none")]
5293    pub encoding: Option<String>,
5294    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5295    #[serde(default, skip_serializing_if = "Option::is_none")]
5296    pub codec: Option<String>,
5297    /// ClickHouse: EPHEMERAL [expr] modifier
5298    #[serde(default, skip_serializing_if = "Option::is_none")]
5299    pub ephemeral: Option<Option<Box<Expression>>>,
5300    /// ClickHouse: MATERIALIZED expr modifier
5301    #[serde(default, skip_serializing_if = "Option::is_none")]
5302    pub materialized_expr: Option<Box<Expression>>,
5303    /// ClickHouse: ALIAS expr modifier
5304    #[serde(default, skip_serializing_if = "Option::is_none")]
5305    pub alias_expr: Option<Box<Expression>>,
5306    /// ClickHouse: TTL expr modifier on columns
5307    #[serde(default, skip_serializing_if = "Option::is_none")]
5308    pub ttl_expr: Option<Box<Expression>>,
5309    /// TSQL: NOT FOR REPLICATION
5310    #[serde(default)]
5311    pub not_for_replication: bool,
5312}
5313
5314impl ColumnDef {
5315    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5316        Self {
5317            name: Identifier::new(name),
5318            data_type,
5319            nullable: None,
5320            default: None,
5321            primary_key: false,
5322            primary_key_order: None,
5323            unique: false,
5324            unique_nulls_not_distinct: false,
5325            auto_increment: false,
5326            comment: None,
5327            constraints: Vec::new(),
5328            constraint_order: Vec::new(),
5329            format: None,
5330            title: None,
5331            inline_length: None,
5332            compress: None,
5333            character_set: None,
5334            uppercase: false,
5335            casespecific: None,
5336            auto_increment_start: None,
5337            auto_increment_increment: None,
5338            auto_increment_order: None,
5339            unsigned: false,
5340            zerofill: false,
5341            on_update: None,
5342            unique_constraint_name: None,
5343            not_null_constraint_name: None,
5344            primary_key_constraint_name: None,
5345            check_constraint_name: None,
5346            options: Vec::new(),
5347            no_type: false,
5348            encoding: None,
5349            codec: None,
5350            ephemeral: None,
5351            materialized_expr: None,
5352            alias_expr: None,
5353            ttl_expr: None,
5354            not_for_replication: false,
5355        }
5356    }
5357}
5358
5359/// Column-level constraint
5360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5361#[cfg_attr(feature = "bindings", derive(TS))]
5362pub enum ColumnConstraint {
5363    NotNull,
5364    Null,
5365    Unique,
5366    PrimaryKey,
5367    Default(Expression),
5368    Check(Expression),
5369    References(ForeignKeyRef),
5370    GeneratedAsIdentity(GeneratedAsIdentity),
5371    Collate(Identifier),
5372    Comment(String),
5373    /// Snowflake: TAG (key='value', ...)
5374    Tags(Tags),
5375    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5376    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5377    ComputedColumn(ComputedColumn),
5378    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5379    GeneratedAsRow(GeneratedAsRow),
5380    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5381    Path(Expression),
5382}
5383
5384/// Computed/generated column constraint
5385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5386#[cfg_attr(feature = "bindings", derive(TS))]
5387pub struct ComputedColumn {
5388    /// The expression that computes the column value
5389    pub expression: Box<Expression>,
5390    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5391    #[serde(default)]
5392    pub persisted: bool,
5393    /// NOT NULL (TSQL computed columns)
5394    #[serde(default)]
5395    pub not_null: bool,
5396    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5397    /// When None, defaults to dialect-appropriate output
5398    #[serde(default)]
5399    pub persistence_kind: Option<String>,
5400    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5401    #[serde(default, skip_serializing_if = "Option::is_none")]
5402    pub data_type: Option<DataType>,
5403}
5404
5405/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5407#[cfg_attr(feature = "bindings", derive(TS))]
5408pub struct GeneratedAsRow {
5409    /// true = ROW START, false = ROW END
5410    pub start: bool,
5411    /// HIDDEN modifier
5412    #[serde(default)]
5413    pub hidden: bool,
5414}
5415
5416/// Generated identity column constraint
5417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5418#[cfg_attr(feature = "bindings", derive(TS))]
5419pub struct GeneratedAsIdentity {
5420    /// True for ALWAYS, False for BY DEFAULT
5421    pub always: bool,
5422    /// ON NULL (only valid with BY DEFAULT)
5423    pub on_null: bool,
5424    /// START WITH value
5425    pub start: Option<Box<Expression>>,
5426    /// INCREMENT BY value
5427    pub increment: Option<Box<Expression>>,
5428    /// MINVALUE
5429    pub minvalue: Option<Box<Expression>>,
5430    /// MAXVALUE
5431    pub maxvalue: Option<Box<Expression>>,
5432    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5433    pub cycle: Option<bool>,
5434}
5435
5436/// Constraint modifiers (shared between table-level constraints)
5437#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5438#[cfg_attr(feature = "bindings", derive(TS))]
5439pub struct ConstraintModifiers {
5440    /// ENFORCED / NOT ENFORCED
5441    pub enforced: Option<bool>,
5442    /// DEFERRABLE / NOT DEFERRABLE
5443    pub deferrable: Option<bool>,
5444    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5445    pub initially_deferred: Option<bool>,
5446    /// NORELY (Oracle)
5447    pub norely: bool,
5448    /// RELY (Oracle)
5449    pub rely: bool,
5450    /// USING index type (MySQL): BTREE or HASH
5451    #[serde(default)]
5452    pub using: Option<String>,
5453    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5454    #[serde(default)]
5455    pub using_before_columns: bool,
5456    /// MySQL index COMMENT 'text'
5457    #[serde(default, skip_serializing_if = "Option::is_none")]
5458    pub comment: Option<String>,
5459    /// MySQL index VISIBLE/INVISIBLE
5460    #[serde(default, skip_serializing_if = "Option::is_none")]
5461    pub visible: Option<bool>,
5462    /// MySQL ENGINE_ATTRIBUTE = 'value'
5463    #[serde(default, skip_serializing_if = "Option::is_none")]
5464    pub engine_attribute: Option<String>,
5465    /// MySQL WITH PARSER name
5466    #[serde(default, skip_serializing_if = "Option::is_none")]
5467    pub with_parser: Option<String>,
5468    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5469    #[serde(default)]
5470    pub not_valid: bool,
5471    /// TSQL CLUSTERED/NONCLUSTERED modifier
5472    #[serde(default, skip_serializing_if = "Option::is_none")]
5473    pub clustered: Option<String>,
5474    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5475    #[serde(default, skip_serializing_if = "Option::is_none")]
5476    pub on_conflict: Option<String>,
5477    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5478    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5479    pub with_options: Vec<(String, String)>,
5480    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5481    #[serde(default, skip_serializing_if = "Option::is_none")]
5482    pub on_filegroup: Option<Identifier>,
5483}
5484
5485/// Table-level constraint
5486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5487#[cfg_attr(feature = "bindings", derive(TS))]
5488pub enum TableConstraint {
5489    PrimaryKey {
5490        name: Option<Identifier>,
5491        columns: Vec<Identifier>,
5492        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5493        #[serde(default)]
5494        include_columns: Vec<Identifier>,
5495        #[serde(default)]
5496        modifiers: ConstraintModifiers,
5497        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5498        #[serde(default)]
5499        has_constraint_keyword: bool,
5500    },
5501    Unique {
5502        name: Option<Identifier>,
5503        columns: Vec<Identifier>,
5504        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5505        #[serde(default)]
5506        columns_parenthesized: bool,
5507        #[serde(default)]
5508        modifiers: ConstraintModifiers,
5509        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5510        #[serde(default)]
5511        has_constraint_keyword: bool,
5512        /// PostgreSQL 15+: NULLS NOT DISTINCT
5513        #[serde(default)]
5514        nulls_not_distinct: bool,
5515    },
5516    ForeignKey {
5517        name: Option<Identifier>,
5518        columns: Vec<Identifier>,
5519        #[serde(default)]
5520        references: Option<ForeignKeyRef>,
5521        /// ON DELETE action when REFERENCES is absent
5522        #[serde(default)]
5523        on_delete: Option<ReferentialAction>,
5524        /// ON UPDATE action when REFERENCES is absent
5525        #[serde(default)]
5526        on_update: Option<ReferentialAction>,
5527        #[serde(default)]
5528        modifiers: ConstraintModifiers,
5529    },
5530    Check {
5531        name: Option<Identifier>,
5532        expression: Expression,
5533        #[serde(default)]
5534        modifiers: ConstraintModifiers,
5535    },
5536    /// INDEX / KEY constraint (MySQL)
5537    Index {
5538        name: Option<Identifier>,
5539        columns: Vec<Identifier>,
5540        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5541        #[serde(default)]
5542        kind: Option<String>,
5543        #[serde(default)]
5544        modifiers: ConstraintModifiers,
5545        /// True if KEY keyword was used instead of INDEX
5546        #[serde(default)]
5547        use_key_keyword: bool,
5548        /// ClickHouse: indexed expression (instead of columns)
5549        #[serde(default, skip_serializing_if = "Option::is_none")]
5550        expression: Option<Box<Expression>>,
5551        /// ClickHouse: TYPE type_func(args)
5552        #[serde(default, skip_serializing_if = "Option::is_none")]
5553        index_type: Option<Box<Expression>>,
5554        /// ClickHouse: GRANULARITY n
5555        #[serde(default, skip_serializing_if = "Option::is_none")]
5556        granularity: Option<Box<Expression>>,
5557    },
5558    /// ClickHouse PROJECTION definition
5559    Projection {
5560        name: Identifier,
5561        expression: Expression,
5562    },
5563    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5564    Like {
5565        source: TableRef,
5566        /// Options as (INCLUDING|EXCLUDING, property) pairs
5567        options: Vec<(LikeOptionAction, String)>,
5568    },
5569    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5570    PeriodForSystemTime {
5571        start_col: Identifier,
5572        end_col: Identifier,
5573    },
5574    /// PostgreSQL EXCLUDE constraint
5575    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5576    Exclude {
5577        name: Option<Identifier>,
5578        /// Index access method (gist, btree, etc.)
5579        #[serde(default)]
5580        using: Option<String>,
5581        /// Elements: (expression, operator) pairs
5582        elements: Vec<ExcludeElement>,
5583        /// INCLUDE columns
5584        #[serde(default)]
5585        include_columns: Vec<Identifier>,
5586        /// WHERE predicate
5587        #[serde(default)]
5588        where_clause: Option<Box<Expression>>,
5589        /// WITH (storage_parameters)
5590        #[serde(default)]
5591        with_params: Vec<(String, String)>,
5592        /// USING INDEX TABLESPACE tablespace_name
5593        #[serde(default)]
5594        using_index_tablespace: Option<String>,
5595        #[serde(default)]
5596        modifiers: ConstraintModifiers,
5597    },
5598    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5599    Tags(Tags),
5600    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5601    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5602    /// for all deferrable constraints in the table
5603    InitiallyDeferred {
5604        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5605        deferred: bool,
5606    },
5607}
5608
5609/// Element in an EXCLUDE constraint: expression WITH operator
5610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5611#[cfg_attr(feature = "bindings", derive(TS))]
5612pub struct ExcludeElement {
5613    /// The column expression (may include operator class, ordering, nulls)
5614    pub expression: String,
5615    /// The operator (e.g., &&, =)
5616    pub operator: String,
5617}
5618
5619/// Action for LIKE clause options
5620#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5621#[cfg_attr(feature = "bindings", derive(TS))]
5622pub enum LikeOptionAction {
5623    Including,
5624    Excluding,
5625}
5626
5627/// MATCH type for foreign keys
5628#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5629#[cfg_attr(feature = "bindings", derive(TS))]
5630pub enum MatchType {
5631    Full,
5632    Partial,
5633    Simple,
5634}
5635
5636/// Foreign key reference
5637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5638#[cfg_attr(feature = "bindings", derive(TS))]
5639pub struct ForeignKeyRef {
5640    pub table: TableRef,
5641    pub columns: Vec<Identifier>,
5642    pub on_delete: Option<ReferentialAction>,
5643    pub on_update: Option<ReferentialAction>,
5644    /// True if ON UPDATE appears before ON DELETE in the original SQL
5645    #[serde(default)]
5646    pub on_update_first: bool,
5647    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5648    #[serde(default)]
5649    pub match_type: Option<MatchType>,
5650    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5651    #[serde(default)]
5652    pub match_after_actions: bool,
5653    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5654    #[serde(default)]
5655    pub constraint_name: Option<String>,
5656    /// DEFERRABLE / NOT DEFERRABLE
5657    #[serde(default)]
5658    pub deferrable: Option<bool>,
5659    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5660    #[serde(default)]
5661    pub has_foreign_key_keywords: bool,
5662}
5663
5664/// Referential action for foreign keys
5665#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5666#[cfg_attr(feature = "bindings", derive(TS))]
5667pub enum ReferentialAction {
5668    Cascade,
5669    SetNull,
5670    SetDefault,
5671    Restrict,
5672    NoAction,
5673}
5674
5675/// DROP TABLE statement
5676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5677#[cfg_attr(feature = "bindings", derive(TS))]
5678pub struct DropTable {
5679    pub names: Vec<TableRef>,
5680    pub if_exists: bool,
5681    pub cascade: bool,
5682    /// Oracle: CASCADE CONSTRAINTS
5683    #[serde(default)]
5684    pub cascade_constraints: bool,
5685    /// Oracle: PURGE
5686    #[serde(default)]
5687    pub purge: bool,
5688}
5689
5690impl DropTable {
5691    pub fn new(name: impl Into<String>) -> Self {
5692        Self {
5693            names: vec![TableRef::new(name)],
5694            if_exists: false,
5695            cascade: false,
5696            cascade_constraints: false,
5697            purge: false,
5698        }
5699    }
5700}
5701
5702/// ALTER TABLE statement
5703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5704#[cfg_attr(feature = "bindings", derive(TS))]
5705pub struct AlterTable {
5706    pub name: TableRef,
5707    pub actions: Vec<AlterTableAction>,
5708    /// IF EXISTS clause
5709    #[serde(default)]
5710    pub if_exists: bool,
5711    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5712    #[serde(default, skip_serializing_if = "Option::is_none")]
5713    pub algorithm: Option<String>,
5714    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5715    #[serde(default, skip_serializing_if = "Option::is_none")]
5716    pub lock: Option<String>,
5717    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5718    #[serde(default, skip_serializing_if = "Option::is_none")]
5719    pub with_check: Option<String>,
5720    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5721    #[serde(default, skip_serializing_if = "Option::is_none")]
5722    pub partition: Option<Vec<(Identifier, Expression)>>,
5723    /// ClickHouse: ON CLUSTER clause for distributed DDL
5724    #[serde(default, skip_serializing_if = "Option::is_none")]
5725    pub on_cluster: Option<OnCluster>,
5726}
5727
5728impl AlterTable {
5729    pub fn new(name: impl Into<String>) -> Self {
5730        Self {
5731            name: TableRef::new(name),
5732            actions: Vec::new(),
5733            if_exists: false,
5734            algorithm: None,
5735            lock: None,
5736            with_check: None,
5737            partition: None,
5738            on_cluster: None,
5739        }
5740    }
5741}
5742
5743/// Column position for ADD COLUMN (MySQL/MariaDB)
5744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5745#[cfg_attr(feature = "bindings", derive(TS))]
5746pub enum ColumnPosition {
5747    First,
5748    After(Identifier),
5749}
5750
5751/// Actions for ALTER TABLE
5752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5753#[cfg_attr(feature = "bindings", derive(TS))]
5754pub enum AlterTableAction {
5755    AddColumn {
5756        column: ColumnDef,
5757        if_not_exists: bool,
5758        position: Option<ColumnPosition>,
5759    },
5760    DropColumn {
5761        name: Identifier,
5762        if_exists: bool,
5763        cascade: bool,
5764    },
5765    RenameColumn {
5766        old_name: Identifier,
5767        new_name: Identifier,
5768        if_exists: bool,
5769    },
5770    AlterColumn {
5771        name: Identifier,
5772        action: AlterColumnAction,
5773        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5774        #[serde(default)]
5775        use_modify_keyword: bool,
5776    },
5777    RenameTable(TableRef),
5778    AddConstraint(TableConstraint),
5779    DropConstraint {
5780        name: Identifier,
5781        if_exists: bool,
5782    },
5783    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5784    DropForeignKey {
5785        name: Identifier,
5786    },
5787    /// DROP PARTITION action (Hive/BigQuery)
5788    DropPartition {
5789        /// List of partitions to drop (each partition is a list of key=value pairs)
5790        partitions: Vec<Vec<(Identifier, Expression)>>,
5791        if_exists: bool,
5792    },
5793    /// ADD PARTITION action (Hive/Spark)
5794    AddPartition {
5795        /// The partition expression
5796        partition: Expression,
5797        if_not_exists: bool,
5798        location: Option<Expression>,
5799    },
5800    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
5801    Delete {
5802        where_clause: Expression,
5803    },
5804    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
5805    SwapWith(TableRef),
5806    /// SET property action (Snowflake): ALTER TABLE t SET property=value
5807    SetProperty {
5808        properties: Vec<(String, Expression)>,
5809    },
5810    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
5811    UnsetProperty {
5812        properties: Vec<String>,
5813    },
5814    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
5815    ClusterBy {
5816        expressions: Vec<Expression>,
5817    },
5818    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
5819    SetTag {
5820        expressions: Vec<(String, Expression)>,
5821    },
5822    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
5823    UnsetTag {
5824        names: Vec<String>,
5825    },
5826    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
5827    SetOptions {
5828        expressions: Vec<Expression>,
5829    },
5830    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
5831    AlterIndex {
5832        name: Identifier,
5833        visible: bool,
5834    },
5835    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
5836    SetAttribute {
5837        attribute: String,
5838    },
5839    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
5840    SetStageFileFormat {
5841        options: Option<Expression>,
5842    },
5843    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
5844    SetStageCopyOptions {
5845        options: Option<Expression>,
5846    },
5847    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
5848    AddColumns {
5849        columns: Vec<ColumnDef>,
5850        cascade: bool,
5851    },
5852    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
5853    DropColumns {
5854        names: Vec<Identifier>,
5855    },
5856    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
5857    /// In SingleStore, data_type can be omitted for simple column renames
5858    ChangeColumn {
5859        old_name: Identifier,
5860        new_name: Identifier,
5861        #[serde(default, skip_serializing_if = "Option::is_none")]
5862        data_type: Option<DataType>,
5863        comment: Option<String>,
5864        #[serde(default)]
5865        cascade: bool,
5866    },
5867    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
5868    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
5869    AlterSortKey {
5870        /// AUTO or NONE keyword
5871        this: Option<String>,
5872        /// Column list for (col1, col2) syntax
5873        expressions: Vec<Expression>,
5874        /// Whether COMPOUND keyword was present
5875        compound: bool,
5876    },
5877    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
5878    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
5879    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
5880    AlterDistStyle {
5881        /// Distribution style: ALL, EVEN, AUTO, or KEY
5882        style: String,
5883        /// DISTKEY column (only when style is KEY)
5884        distkey: Option<Identifier>,
5885    },
5886    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
5887    SetTableProperties {
5888        properties: Vec<(Expression, Expression)>,
5889    },
5890    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
5891    SetLocation {
5892        location: String,
5893    },
5894    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
5895    SetFileFormat {
5896        format: String,
5897    },
5898    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
5899    ReplacePartition {
5900        partition: Expression,
5901        source: Option<Box<Expression>>,
5902    },
5903}
5904
5905/// Actions for ALTER COLUMN
5906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5907#[cfg_attr(feature = "bindings", derive(TS))]
5908pub enum AlterColumnAction {
5909    SetDataType {
5910        data_type: DataType,
5911        /// USING expression for type conversion (PostgreSQL)
5912        using: Option<Expression>,
5913        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
5914        #[serde(default, skip_serializing_if = "Option::is_none")]
5915        collate: Option<String>,
5916    },
5917    SetDefault(Expression),
5918    DropDefault,
5919    SetNotNull,
5920    DropNotNull,
5921    /// Set column comment
5922    Comment(String),
5923    /// MySQL: SET VISIBLE
5924    SetVisible,
5925    /// MySQL: SET INVISIBLE
5926    SetInvisible,
5927}
5928
5929/// CREATE INDEX statement
5930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5931#[cfg_attr(feature = "bindings", derive(TS))]
5932pub struct CreateIndex {
5933    pub name: Identifier,
5934    pub table: TableRef,
5935    pub columns: Vec<IndexColumn>,
5936    pub unique: bool,
5937    pub if_not_exists: bool,
5938    pub using: Option<String>,
5939    /// TSQL CLUSTERED/NONCLUSTERED modifier
5940    #[serde(default)]
5941    pub clustered: Option<String>,
5942    /// PostgreSQL CONCURRENTLY modifier
5943    #[serde(default)]
5944    pub concurrently: bool,
5945    /// PostgreSQL WHERE clause for partial indexes
5946    #[serde(default)]
5947    pub where_clause: Option<Box<Expression>>,
5948    /// PostgreSQL INCLUDE columns
5949    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5950    pub include_columns: Vec<Identifier>,
5951    /// TSQL WITH options (e.g., allow_page_locks=on)
5952    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5953    pub with_options: Vec<(String, String)>,
5954    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
5955    #[serde(default)]
5956    pub on_filegroup: Option<String>,
5957}
5958
5959impl CreateIndex {
5960    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
5961        Self {
5962            name: Identifier::new(name),
5963            table: TableRef::new(table),
5964            columns: Vec::new(),
5965            unique: false,
5966            if_not_exists: false,
5967            using: None,
5968            clustered: None,
5969            concurrently: false,
5970            where_clause: None,
5971            include_columns: Vec::new(),
5972            with_options: Vec::new(),
5973            on_filegroup: None,
5974        }
5975    }
5976}
5977
5978/// Index column specification
5979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5980#[cfg_attr(feature = "bindings", derive(TS))]
5981pub struct IndexColumn {
5982    pub column: Identifier,
5983    pub desc: bool,
5984    /// Explicit ASC keyword was present
5985    #[serde(default)]
5986    pub asc: bool,
5987    pub nulls_first: Option<bool>,
5988    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
5989    #[serde(default, skip_serializing_if = "Option::is_none")]
5990    pub opclass: Option<String>,
5991}
5992
5993/// DROP INDEX statement
5994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5995#[cfg_attr(feature = "bindings", derive(TS))]
5996pub struct DropIndex {
5997    pub name: Identifier,
5998    pub table: Option<TableRef>,
5999    pub if_exists: bool,
6000    /// PostgreSQL CONCURRENTLY modifier
6001    #[serde(default)]
6002    pub concurrently: bool,
6003}
6004
6005impl DropIndex {
6006    pub fn new(name: impl Into<String>) -> Self {
6007        Self {
6008            name: Identifier::new(name),
6009            table: None,
6010            if_exists: false,
6011            concurrently: false,
6012        }
6013    }
6014}
6015
6016/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6018#[cfg_attr(feature = "bindings", derive(TS))]
6019pub struct ViewColumn {
6020    pub name: Identifier,
6021    pub comment: Option<String>,
6022    /// BigQuery: OPTIONS (key=value, ...) on column
6023    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6024    pub options: Vec<Expression>,
6025}
6026
6027impl ViewColumn {
6028    pub fn new(name: impl Into<String>) -> Self {
6029        Self {
6030            name: Identifier::new(name),
6031            comment: None,
6032            options: Vec::new(),
6033        }
6034    }
6035
6036    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6037        Self {
6038            name: Identifier::new(name),
6039            comment: Some(comment.into()),
6040            options: Vec::new(),
6041        }
6042    }
6043}
6044
6045/// CREATE VIEW statement
6046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6047#[cfg_attr(feature = "bindings", derive(TS))]
6048pub struct CreateView {
6049    pub name: TableRef,
6050    pub columns: Vec<ViewColumn>,
6051    pub query: Expression,
6052    pub or_replace: bool,
6053    pub if_not_exists: bool,
6054    pub materialized: bool,
6055    pub temporary: bool,
6056    /// Snowflake: SECURE VIEW
6057    #[serde(default)]
6058    pub secure: bool,
6059    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6060    #[serde(skip_serializing_if = "Option::is_none")]
6061    pub algorithm: Option<String>,
6062    /// MySQL: DEFINER=user@host
6063    #[serde(skip_serializing_if = "Option::is_none")]
6064    pub definer: Option<String>,
6065    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6066    #[serde(skip_serializing_if = "Option::is_none")]
6067    pub security: Option<FunctionSecurity>,
6068    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6069    #[serde(default = "default_true")]
6070    pub security_sql_style: bool,
6071    /// Whether the query was parenthesized: AS (SELECT ...)
6072    #[serde(default)]
6073    pub query_parenthesized: bool,
6074    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6075    #[serde(skip_serializing_if = "Option::is_none")]
6076    pub locking_mode: Option<String>,
6077    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6078    #[serde(skip_serializing_if = "Option::is_none")]
6079    pub locking_access: Option<String>,
6080    /// Snowflake: COPY GRANTS
6081    #[serde(default)]
6082    pub copy_grants: bool,
6083    /// Snowflake: COMMENT = 'text'
6084    #[serde(skip_serializing_if = "Option::is_none", default)]
6085    pub comment: Option<String>,
6086    /// Snowflake: TAG (name='value', ...)
6087    #[serde(default)]
6088    pub tags: Vec<(String, String)>,
6089    /// BigQuery: OPTIONS (key=value, ...)
6090    #[serde(default)]
6091    pub options: Vec<Expression>,
6092    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6093    #[serde(skip_serializing_if = "Option::is_none", default)]
6094    pub build: Option<String>,
6095    /// Doris: REFRESH property for materialized views
6096    #[serde(skip_serializing_if = "Option::is_none", default)]
6097    pub refresh: Option<Box<RefreshTriggerProperty>>,
6098    /// Doris: Schema with typed column definitions for materialized views
6099    /// This is used instead of `columns` when the view has typed column definitions
6100    #[serde(skip_serializing_if = "Option::is_none", default)]
6101    pub schema: Option<Box<Schema>>,
6102    /// Doris: KEY (columns) for materialized views
6103    #[serde(skip_serializing_if = "Option::is_none", default)]
6104    pub unique_key: Option<Box<UniqueKeyProperty>>,
6105    /// Redshift: WITH NO SCHEMA BINDING
6106    #[serde(default)]
6107    pub no_schema_binding: bool,
6108    /// Redshift: AUTO REFRESH YES|NO for materialized views
6109    #[serde(skip_serializing_if = "Option::is_none", default)]
6110    pub auto_refresh: Option<bool>,
6111    /// ClickHouse: ON CLUSTER clause
6112    #[serde(default, skip_serializing_if = "Option::is_none")]
6113    pub on_cluster: Option<OnCluster>,
6114    /// ClickHouse: TO destination_table
6115    #[serde(default, skip_serializing_if = "Option::is_none")]
6116    pub to_table: Option<TableRef>,
6117    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6118    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6119    pub table_properties: Vec<Expression>,
6120}
6121
6122impl CreateView {
6123    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6124        Self {
6125            name: TableRef::new(name),
6126            columns: Vec::new(),
6127            query,
6128            or_replace: false,
6129            if_not_exists: false,
6130            materialized: false,
6131            temporary: false,
6132            secure: false,
6133            algorithm: None,
6134            definer: None,
6135            security: None,
6136            security_sql_style: true,
6137            query_parenthesized: false,
6138            locking_mode: None,
6139            locking_access: None,
6140            copy_grants: false,
6141            comment: None,
6142            tags: Vec::new(),
6143            options: Vec::new(),
6144            build: None,
6145            refresh: None,
6146            schema: None,
6147            unique_key: None,
6148            no_schema_binding: false,
6149            auto_refresh: None,
6150            on_cluster: None,
6151            to_table: None,
6152            table_properties: Vec::new(),
6153        }
6154    }
6155}
6156
6157/// DROP VIEW statement
6158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6159#[cfg_attr(feature = "bindings", derive(TS))]
6160pub struct DropView {
6161    pub name: TableRef,
6162    pub if_exists: bool,
6163    pub materialized: bool,
6164}
6165
6166impl DropView {
6167    pub fn new(name: impl Into<String>) -> Self {
6168        Self {
6169            name: TableRef::new(name),
6170            if_exists: false,
6171            materialized: false,
6172        }
6173    }
6174}
6175
6176/// TRUNCATE TABLE statement
6177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6178#[cfg_attr(feature = "bindings", derive(TS))]
6179pub struct Truncate {
6180    /// Target of TRUNCATE (TABLE vs DATABASE)
6181    #[serde(default)]
6182    pub target: TruncateTarget,
6183    pub table: TableRef,
6184    /// ClickHouse: ON CLUSTER clause for distributed DDL
6185    #[serde(default, skip_serializing_if = "Option::is_none")]
6186    pub on_cluster: Option<OnCluster>,
6187    pub cascade: bool,
6188    /// Additional tables for multi-table TRUNCATE
6189    #[serde(default)]
6190    pub extra_tables: Vec<TruncateTableEntry>,
6191    /// RESTART IDENTITY or CONTINUE IDENTITY
6192    #[serde(default)]
6193    pub identity: Option<TruncateIdentity>,
6194    /// RESTRICT option (alternative to CASCADE)
6195    #[serde(default)]
6196    pub restrict: bool,
6197    /// Hive PARTITION clause: PARTITION(key=value, ...)
6198    #[serde(default, skip_serializing_if = "Option::is_none")]
6199    pub partition: Option<Box<Expression>>,
6200}
6201
6202/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6204#[cfg_attr(feature = "bindings", derive(TS))]
6205pub struct TruncateTableEntry {
6206    pub table: TableRef,
6207    /// Whether the table has a * suffix (inherit children)
6208    #[serde(default)]
6209    pub star: bool,
6210}
6211
6212/// TRUNCATE target type
6213#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6214#[cfg_attr(feature = "bindings", derive(TS))]
6215pub enum TruncateTarget {
6216    Table,
6217    Database,
6218}
6219
6220impl Default for TruncateTarget {
6221    fn default() -> Self {
6222        TruncateTarget::Table
6223    }
6224}
6225
6226/// TRUNCATE identity option
6227#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6228#[cfg_attr(feature = "bindings", derive(TS))]
6229pub enum TruncateIdentity {
6230    Restart,
6231    Continue,
6232}
6233
6234impl Truncate {
6235    pub fn new(table: impl Into<String>) -> Self {
6236        Self {
6237            target: TruncateTarget::Table,
6238            table: TableRef::new(table),
6239            on_cluster: None,
6240            cascade: false,
6241            extra_tables: Vec::new(),
6242            identity: None,
6243            restrict: false,
6244            partition: None,
6245        }
6246    }
6247}
6248
6249/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6251#[cfg_attr(feature = "bindings", derive(TS))]
6252pub struct Use {
6253    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6254    pub kind: Option<UseKind>,
6255    /// The name of the object
6256    pub this: Identifier,
6257}
6258
6259/// Kind of USE statement
6260#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6261#[cfg_attr(feature = "bindings", derive(TS))]
6262pub enum UseKind {
6263    Database,
6264    Schema,
6265    Role,
6266    Warehouse,
6267    Catalog,
6268    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6269    SecondaryRoles,
6270}
6271
6272/// SET variable statement
6273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6274#[cfg_attr(feature = "bindings", derive(TS))]
6275pub struct SetStatement {
6276    /// The items being set
6277    pub items: Vec<SetItem>,
6278}
6279
6280/// A single SET item (variable assignment)
6281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6282#[cfg_attr(feature = "bindings", derive(TS))]
6283pub struct SetItem {
6284    /// The variable name
6285    pub name: Expression,
6286    /// The value to set
6287    pub value: Expression,
6288    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6289    pub kind: Option<String>,
6290    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6291    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6292    pub no_equals: bool,
6293}
6294
6295/// CACHE TABLE statement (Spark)
6296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6297#[cfg_attr(feature = "bindings", derive(TS))]
6298pub struct Cache {
6299    /// The table to cache
6300    pub table: Identifier,
6301    /// LAZY keyword - defer caching until first use
6302    pub lazy: bool,
6303    /// Optional OPTIONS clause (key-value pairs)
6304    pub options: Vec<(Expression, Expression)>,
6305    /// Optional AS clause with query
6306    pub query: Option<Expression>,
6307}
6308
6309/// UNCACHE TABLE statement (Spark)
6310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6311#[cfg_attr(feature = "bindings", derive(TS))]
6312pub struct Uncache {
6313    /// The table to uncache
6314    pub table: Identifier,
6315    /// IF EXISTS clause
6316    pub if_exists: bool,
6317}
6318
6319/// LOAD DATA statement (Hive)
6320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6321#[cfg_attr(feature = "bindings", derive(TS))]
6322pub struct LoadData {
6323    /// LOCAL keyword - load from local filesystem
6324    pub local: bool,
6325    /// The path to load data from (INPATH value)
6326    pub inpath: String,
6327    /// Whether to overwrite existing data
6328    pub overwrite: bool,
6329    /// The target table
6330    pub table: Expression,
6331    /// Optional PARTITION clause with key-value pairs
6332    pub partition: Vec<(Identifier, Expression)>,
6333    /// Optional INPUTFORMAT clause
6334    pub input_format: Option<String>,
6335    /// Optional SERDE clause
6336    pub serde: Option<String>,
6337}
6338
6339/// PRAGMA statement (SQLite)
6340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6341#[cfg_attr(feature = "bindings", derive(TS))]
6342pub struct Pragma {
6343    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6344    pub schema: Option<Identifier>,
6345    /// The pragma name
6346    pub name: Identifier,
6347    /// Optional value for assignment (PRAGMA name = value)
6348    pub value: Option<Expression>,
6349    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6350    pub args: Vec<Expression>,
6351}
6352
6353/// A privilege with optional column list for GRANT/REVOKE
6354/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6356#[cfg_attr(feature = "bindings", derive(TS))]
6357pub struct Privilege {
6358    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6359    pub name: String,
6360    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6361    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6362    pub columns: Vec<String>,
6363}
6364
6365/// Principal in GRANT/REVOKE (user, role, etc.)
6366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6367#[cfg_attr(feature = "bindings", derive(TS))]
6368pub struct GrantPrincipal {
6369    /// The name of the principal
6370    pub name: Identifier,
6371    /// Whether prefixed with ROLE keyword
6372    pub is_role: bool,
6373    /// Whether prefixed with GROUP keyword (Redshift)
6374    #[serde(default)]
6375    pub is_group: bool,
6376}
6377
6378/// GRANT statement
6379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6380#[cfg_attr(feature = "bindings", derive(TS))]
6381pub struct Grant {
6382    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6383    pub privileges: Vec<Privilege>,
6384    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6385    pub kind: Option<String>,
6386    /// The object to grant on
6387    pub securable: Identifier,
6388    /// Function parameter types (for FUNCTION kind)
6389    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6390    pub function_params: Vec<String>,
6391    /// The grantees
6392    pub principals: Vec<GrantPrincipal>,
6393    /// WITH GRANT OPTION
6394    pub grant_option: bool,
6395    /// TSQL: AS principal (the grantor role)
6396    #[serde(default, skip_serializing_if = "Option::is_none")]
6397    pub as_principal: Option<Identifier>,
6398}
6399
6400/// REVOKE statement
6401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6402#[cfg_attr(feature = "bindings", derive(TS))]
6403pub struct Revoke {
6404    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6405    pub privileges: Vec<Privilege>,
6406    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6407    pub kind: Option<String>,
6408    /// The object to revoke from
6409    pub securable: Identifier,
6410    /// Function parameter types (for FUNCTION kind)
6411    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6412    pub function_params: Vec<String>,
6413    /// The grantees
6414    pub principals: Vec<GrantPrincipal>,
6415    /// GRANT OPTION FOR
6416    pub grant_option: bool,
6417    /// CASCADE
6418    pub cascade: bool,
6419    /// RESTRICT
6420    #[serde(default)]
6421    pub restrict: bool,
6422}
6423
6424/// COMMENT ON statement
6425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6426#[cfg_attr(feature = "bindings", derive(TS))]
6427pub struct Comment {
6428    /// The object being commented on
6429    pub this: Expression,
6430    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6431    pub kind: String,
6432    /// The comment text expression
6433    pub expression: Expression,
6434    /// IF EXISTS clause
6435    pub exists: bool,
6436    /// MATERIALIZED keyword
6437    pub materialized: bool,
6438}
6439
6440// ============================================================================
6441// Phase 4: Additional DDL Statements
6442// ============================================================================
6443
6444/// ALTER VIEW statement
6445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6446#[cfg_attr(feature = "bindings", derive(TS))]
6447pub struct AlterView {
6448    pub name: TableRef,
6449    pub actions: Vec<AlterViewAction>,
6450    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6451    #[serde(default, skip_serializing_if = "Option::is_none")]
6452    pub algorithm: Option<String>,
6453    /// MySQL: DEFINER = 'user'@'host'
6454    #[serde(default, skip_serializing_if = "Option::is_none")]
6455    pub definer: Option<String>,
6456    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6457    #[serde(default, skip_serializing_if = "Option::is_none")]
6458    pub sql_security: Option<String>,
6459    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6460    #[serde(default, skip_serializing_if = "Option::is_none")]
6461    pub with_option: Option<String>,
6462    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6463    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6464    pub columns: Vec<ViewColumn>,
6465}
6466
6467/// Actions for ALTER VIEW
6468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6469#[cfg_attr(feature = "bindings", derive(TS))]
6470pub enum AlterViewAction {
6471    /// Rename the view
6472    Rename(TableRef),
6473    /// Change owner
6474    OwnerTo(Identifier),
6475    /// Set schema
6476    SetSchema(Identifier),
6477    /// Set authorization (Trino/Presto)
6478    SetAuthorization(String),
6479    /// Alter column
6480    AlterColumn {
6481        name: Identifier,
6482        action: AlterColumnAction,
6483    },
6484    /// Redefine view as query (SELECT, UNION, etc.)
6485    AsSelect(Box<Expression>),
6486    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6487    SetTblproperties(Vec<(String, String)>),
6488    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6489    UnsetTblproperties(Vec<String>),
6490}
6491
6492impl AlterView {
6493    pub fn new(name: impl Into<String>) -> Self {
6494        Self {
6495            name: TableRef::new(name),
6496            actions: Vec::new(),
6497            algorithm: None,
6498            definer: None,
6499            sql_security: None,
6500            with_option: None,
6501            columns: Vec::new(),
6502        }
6503    }
6504}
6505
6506/// ALTER INDEX statement
6507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6508#[cfg_attr(feature = "bindings", derive(TS))]
6509pub struct AlterIndex {
6510    pub name: Identifier,
6511    pub table: Option<TableRef>,
6512    pub actions: Vec<AlterIndexAction>,
6513}
6514
6515/// Actions for ALTER INDEX
6516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6517#[cfg_attr(feature = "bindings", derive(TS))]
6518pub enum AlterIndexAction {
6519    /// Rename the index
6520    Rename(Identifier),
6521    /// Set tablespace
6522    SetTablespace(Identifier),
6523    /// Set visibility (MySQL)
6524    Visible(bool),
6525}
6526
6527impl AlterIndex {
6528    pub fn new(name: impl Into<String>) -> Self {
6529        Self {
6530            name: Identifier::new(name),
6531            table: None,
6532            actions: Vec::new(),
6533        }
6534    }
6535}
6536
6537/// CREATE SCHEMA statement
6538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6539#[cfg_attr(feature = "bindings", derive(TS))]
6540pub struct CreateSchema {
6541    pub name: Identifier,
6542    pub if_not_exists: bool,
6543    pub authorization: Option<Identifier>,
6544    #[serde(default)]
6545    pub clone_from: Option<Identifier>,
6546    /// AT/BEFORE clause for time travel (Snowflake)
6547    #[serde(default)]
6548    pub at_clause: Option<Expression>,
6549    /// Schema properties like DEFAULT COLLATE
6550    #[serde(default)]
6551    pub properties: Vec<Expression>,
6552    /// Leading comments before the statement
6553    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6554    pub leading_comments: Vec<String>,
6555}
6556
6557impl CreateSchema {
6558    pub fn new(name: impl Into<String>) -> Self {
6559        Self {
6560            name: Identifier::new(name),
6561            if_not_exists: false,
6562            authorization: None,
6563            clone_from: None,
6564            at_clause: None,
6565            properties: Vec::new(),
6566            leading_comments: Vec::new(),
6567        }
6568    }
6569}
6570
6571/// DROP SCHEMA statement
6572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6573#[cfg_attr(feature = "bindings", derive(TS))]
6574pub struct DropSchema {
6575    pub name: Identifier,
6576    pub if_exists: bool,
6577    pub cascade: bool,
6578}
6579
6580impl DropSchema {
6581    pub fn new(name: impl Into<String>) -> Self {
6582        Self {
6583            name: Identifier::new(name),
6584            if_exists: false,
6585            cascade: false,
6586        }
6587    }
6588}
6589
6590/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6592#[cfg_attr(feature = "bindings", derive(TS))]
6593pub struct DropNamespace {
6594    pub name: Identifier,
6595    pub if_exists: bool,
6596    pub cascade: bool,
6597}
6598
6599impl DropNamespace {
6600    pub fn new(name: impl Into<String>) -> Self {
6601        Self {
6602            name: Identifier::new(name),
6603            if_exists: false,
6604            cascade: false,
6605        }
6606    }
6607}
6608
6609/// CREATE DATABASE statement
6610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6611#[cfg_attr(feature = "bindings", derive(TS))]
6612pub struct CreateDatabase {
6613    pub name: Identifier,
6614    pub if_not_exists: bool,
6615    pub options: Vec<DatabaseOption>,
6616    /// Snowflake CLONE source
6617    #[serde(default)]
6618    pub clone_from: Option<Identifier>,
6619    /// AT/BEFORE clause for time travel (Snowflake)
6620    #[serde(default)]
6621    pub at_clause: Option<Expression>,
6622}
6623
6624/// Database option
6625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6626#[cfg_attr(feature = "bindings", derive(TS))]
6627pub enum DatabaseOption {
6628    CharacterSet(String),
6629    Collate(String),
6630    Owner(Identifier),
6631    Template(Identifier),
6632    Encoding(String),
6633    Location(String),
6634}
6635
6636impl CreateDatabase {
6637    pub fn new(name: impl Into<String>) -> Self {
6638        Self {
6639            name: Identifier::new(name),
6640            if_not_exists: false,
6641            options: Vec::new(),
6642            clone_from: None,
6643            at_clause: None,
6644        }
6645    }
6646}
6647
6648/// DROP DATABASE statement
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub struct DropDatabase {
6652    pub name: Identifier,
6653    pub if_exists: bool,
6654}
6655
6656impl DropDatabase {
6657    pub fn new(name: impl Into<String>) -> Self {
6658        Self {
6659            name: Identifier::new(name),
6660            if_exists: false,
6661        }
6662    }
6663}
6664
6665/// CREATE FUNCTION statement
6666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6667#[cfg_attr(feature = "bindings", derive(TS))]
6668pub struct CreateFunction {
6669    pub name: TableRef,
6670    pub parameters: Vec<FunctionParameter>,
6671    pub return_type: Option<DataType>,
6672    pub body: Option<FunctionBody>,
6673    pub or_replace: bool,
6674    pub if_not_exists: bool,
6675    pub temporary: bool,
6676    pub language: Option<String>,
6677    pub deterministic: Option<bool>,
6678    pub returns_null_on_null_input: Option<bool>,
6679    pub security: Option<FunctionSecurity>,
6680    /// Whether parentheses were present in the original syntax
6681    #[serde(default = "default_true")]
6682    pub has_parens: bool,
6683    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6684    #[serde(default)]
6685    pub sql_data_access: Option<SqlDataAccess>,
6686    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6687    #[serde(default, skip_serializing_if = "Option::is_none")]
6688    pub returns_table_body: Option<String>,
6689    /// True if LANGUAGE clause appears before RETURNS clause
6690    #[serde(default)]
6691    pub language_first: bool,
6692    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6693    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6694    pub set_options: Vec<FunctionSetOption>,
6695    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6696    #[serde(default)]
6697    pub strict: bool,
6698    /// BigQuery: OPTIONS (key=value, ...)
6699    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6700    pub options: Vec<Expression>,
6701    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6702    #[serde(default)]
6703    pub is_table_function: bool,
6704    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6705    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6706    pub property_order: Vec<FunctionPropertyKind>,
6707    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6708    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6709    pub environment: Vec<Expression>,
6710}
6711
6712/// A SET option in CREATE FUNCTION (PostgreSQL)
6713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6714#[cfg_attr(feature = "bindings", derive(TS))]
6715pub struct FunctionSetOption {
6716    pub name: String,
6717    pub value: FunctionSetValue,
6718}
6719
6720/// The value of a SET option
6721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6722#[cfg_attr(feature = "bindings", derive(TS))]
6723pub enum FunctionSetValue {
6724    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6725    Value { value: String, use_to: bool },
6726    /// SET key FROM CURRENT
6727    FromCurrent,
6728}
6729
6730/// SQL data access characteristics for functions
6731#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6732#[cfg_attr(feature = "bindings", derive(TS))]
6733pub enum SqlDataAccess {
6734    /// NO SQL
6735    NoSql,
6736    /// CONTAINS SQL
6737    ContainsSql,
6738    /// READS SQL DATA
6739    ReadsSqlData,
6740    /// MODIFIES SQL DATA
6741    ModifiesSqlData,
6742}
6743
6744/// Types of properties in CREATE FUNCTION for tracking their original order
6745#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6746#[cfg_attr(feature = "bindings", derive(TS))]
6747pub enum FunctionPropertyKind {
6748    /// SET option
6749    Set,
6750    /// AS body
6751    As,
6752    /// LANGUAGE clause
6753    Language,
6754    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6755    Determinism,
6756    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6757    NullInput,
6758    /// SECURITY DEFINER/INVOKER
6759    Security,
6760    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6761    SqlDataAccess,
6762    /// OPTIONS clause (BigQuery)
6763    Options,
6764    /// ENVIRONMENT clause (Databricks)
6765    Environment,
6766}
6767
6768/// Function parameter
6769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6770#[cfg_attr(feature = "bindings", derive(TS))]
6771pub struct FunctionParameter {
6772    pub name: Option<Identifier>,
6773    pub data_type: DataType,
6774    pub mode: Option<ParameterMode>,
6775    pub default: Option<Expression>,
6776}
6777
6778/// Parameter mode (IN, OUT, INOUT)
6779#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6780#[cfg_attr(feature = "bindings", derive(TS))]
6781pub enum ParameterMode {
6782    In,
6783    Out,
6784    InOut,
6785}
6786
6787/// Function body
6788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6789#[cfg_attr(feature = "bindings", derive(TS))]
6790pub enum FunctionBody {
6791    /// AS $$ ... $$ (dollar-quoted)
6792    Block(String),
6793    /// AS 'string' (single-quoted string literal body)
6794    StringLiteral(String),
6795    /// AS 'expression'
6796    Expression(Expression),
6797    /// EXTERNAL NAME 'library'
6798    External(String),
6799    /// RETURN expression
6800    Return(Expression),
6801    /// BEGIN ... END block with parsed statements
6802    Statements(Vec<Expression>),
6803    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
6804    /// Stores (content, optional_tag)
6805    DollarQuoted {
6806        content: String,
6807        tag: Option<String>,
6808    },
6809}
6810
6811/// Function security (DEFINER, INVOKER, or NONE)
6812#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6813#[cfg_attr(feature = "bindings", derive(TS))]
6814pub enum FunctionSecurity {
6815    Definer,
6816    Invoker,
6817    /// StarRocks/MySQL: SECURITY NONE
6818    None,
6819}
6820
6821impl CreateFunction {
6822    pub fn new(name: impl Into<String>) -> Self {
6823        Self {
6824            name: TableRef::new(name),
6825            parameters: Vec::new(),
6826            return_type: None,
6827            body: None,
6828            or_replace: false,
6829            if_not_exists: false,
6830            temporary: false,
6831            language: None,
6832            deterministic: None,
6833            returns_null_on_null_input: None,
6834            security: None,
6835            has_parens: true,
6836            sql_data_access: None,
6837            returns_table_body: None,
6838            language_first: false,
6839            set_options: Vec::new(),
6840            strict: false,
6841            options: Vec::new(),
6842            is_table_function: false,
6843            property_order: Vec::new(),
6844            environment: Vec::new(),
6845        }
6846    }
6847}
6848
6849/// DROP FUNCTION statement
6850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6851#[cfg_attr(feature = "bindings", derive(TS))]
6852pub struct DropFunction {
6853    pub name: TableRef,
6854    pub parameters: Option<Vec<DataType>>,
6855    pub if_exists: bool,
6856    pub cascade: bool,
6857}
6858
6859impl DropFunction {
6860    pub fn new(name: impl Into<String>) -> Self {
6861        Self {
6862            name: TableRef::new(name),
6863            parameters: None,
6864            if_exists: false,
6865            cascade: false,
6866        }
6867    }
6868}
6869
6870/// CREATE PROCEDURE statement
6871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6872#[cfg_attr(feature = "bindings", derive(TS))]
6873pub struct CreateProcedure {
6874    pub name: TableRef,
6875    pub parameters: Vec<FunctionParameter>,
6876    pub body: Option<FunctionBody>,
6877    pub or_replace: bool,
6878    pub if_not_exists: bool,
6879    pub language: Option<String>,
6880    pub security: Option<FunctionSecurity>,
6881    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
6882    #[serde(default)]
6883    pub return_type: Option<DataType>,
6884    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
6885    #[serde(default)]
6886    pub execute_as: Option<String>,
6887    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
6888    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6889    pub with_options: Vec<String>,
6890    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
6891    #[serde(default = "default_true", skip_serializing_if = "is_true")]
6892    pub has_parens: bool,
6893    /// Whether the short form PROC was used (instead of PROCEDURE)
6894    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6895    pub use_proc_keyword: bool,
6896}
6897
6898impl CreateProcedure {
6899    pub fn new(name: impl Into<String>) -> Self {
6900        Self {
6901            name: TableRef::new(name),
6902            parameters: Vec::new(),
6903            body: None,
6904            or_replace: false,
6905            if_not_exists: false,
6906            language: None,
6907            security: None,
6908            return_type: None,
6909            execute_as: None,
6910            with_options: Vec::new(),
6911            has_parens: true,
6912            use_proc_keyword: false,
6913        }
6914    }
6915}
6916
6917/// DROP PROCEDURE statement
6918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6919#[cfg_attr(feature = "bindings", derive(TS))]
6920pub struct DropProcedure {
6921    pub name: TableRef,
6922    pub parameters: Option<Vec<DataType>>,
6923    pub if_exists: bool,
6924    pub cascade: bool,
6925}
6926
6927impl DropProcedure {
6928    pub fn new(name: impl Into<String>) -> Self {
6929        Self {
6930            name: TableRef::new(name),
6931            parameters: None,
6932            if_exists: false,
6933            cascade: false,
6934        }
6935    }
6936}
6937
6938/// Sequence property tag for ordering
6939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6940#[cfg_attr(feature = "bindings", derive(TS))]
6941pub enum SeqPropKind {
6942    Start,
6943    Increment,
6944    Minvalue,
6945    Maxvalue,
6946    Cache,
6947    Cycle,
6948    NoCycle,
6949    OwnedBy,
6950    Order,
6951    NoOrder,
6952    Comment,
6953}
6954
6955/// CREATE SEQUENCE statement
6956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6957#[cfg_attr(feature = "bindings", derive(TS))]
6958pub struct CreateSequence {
6959    pub name: TableRef,
6960    pub if_not_exists: bool,
6961    pub temporary: bool,
6962    pub increment: Option<i64>,
6963    pub minvalue: Option<SequenceBound>,
6964    pub maxvalue: Option<SequenceBound>,
6965    pub start: Option<i64>,
6966    pub cache: Option<i64>,
6967    pub cycle: bool,
6968    pub owned_by: Option<TableRef>,
6969    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
6970    #[serde(default)]
6971    pub order: Option<bool>,
6972    /// Snowflake: COMMENT = 'value'
6973    #[serde(default)]
6974    pub comment: Option<String>,
6975    /// Tracks the order in which properties appeared in the source
6976    #[serde(default)]
6977    pub property_order: Vec<SeqPropKind>,
6978}
6979
6980/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
6981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6982#[cfg_attr(feature = "bindings", derive(TS))]
6983pub enum SequenceBound {
6984    Value(i64),
6985    None,
6986}
6987
6988impl CreateSequence {
6989    pub fn new(name: impl Into<String>) -> Self {
6990        Self {
6991            name: TableRef::new(name),
6992            if_not_exists: false,
6993            temporary: false,
6994            increment: None,
6995            minvalue: None,
6996            maxvalue: None,
6997            start: None,
6998            cache: None,
6999            cycle: false,
7000            owned_by: None,
7001            order: None,
7002            comment: None,
7003            property_order: Vec::new(),
7004        }
7005    }
7006}
7007
7008/// DROP SEQUENCE statement
7009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7010#[cfg_attr(feature = "bindings", derive(TS))]
7011pub struct DropSequence {
7012    pub name: TableRef,
7013    pub if_exists: bool,
7014    pub cascade: bool,
7015}
7016
7017impl DropSequence {
7018    pub fn new(name: impl Into<String>) -> Self {
7019        Self {
7020            name: TableRef::new(name),
7021            if_exists: false,
7022            cascade: false,
7023        }
7024    }
7025}
7026
7027/// ALTER SEQUENCE statement
7028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7029#[cfg_attr(feature = "bindings", derive(TS))]
7030pub struct AlterSequence {
7031    pub name: TableRef,
7032    pub if_exists: bool,
7033    pub increment: Option<i64>,
7034    pub minvalue: Option<SequenceBound>,
7035    pub maxvalue: Option<SequenceBound>,
7036    pub start: Option<i64>,
7037    pub restart: Option<Option<i64>>,
7038    pub cache: Option<i64>,
7039    pub cycle: Option<bool>,
7040    pub owned_by: Option<Option<TableRef>>,
7041}
7042
7043impl AlterSequence {
7044    pub fn new(name: impl Into<String>) -> Self {
7045        Self {
7046            name: TableRef::new(name),
7047            if_exists: false,
7048            increment: None,
7049            minvalue: None,
7050            maxvalue: None,
7051            start: None,
7052            restart: None,
7053            cache: None,
7054            cycle: None,
7055            owned_by: None,
7056        }
7057    }
7058}
7059
7060/// CREATE TRIGGER statement
7061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7062#[cfg_attr(feature = "bindings", derive(TS))]
7063pub struct CreateTrigger {
7064    pub name: Identifier,
7065    pub table: TableRef,
7066    pub timing: TriggerTiming,
7067    pub events: Vec<TriggerEvent>,
7068    pub for_each: TriggerForEach,
7069    pub when: Option<Expression>,
7070    pub body: TriggerBody,
7071    pub or_replace: bool,
7072    pub constraint: bool,
7073    pub deferrable: Option<bool>,
7074    pub initially_deferred: Option<bool>,
7075    pub referencing: Option<TriggerReferencing>,
7076}
7077
7078/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7079#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7080#[cfg_attr(feature = "bindings", derive(TS))]
7081pub enum TriggerTiming {
7082    Before,
7083    After,
7084    InsteadOf,
7085}
7086
7087/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7089#[cfg_attr(feature = "bindings", derive(TS))]
7090pub enum TriggerEvent {
7091    Insert,
7092    Update(Option<Vec<Identifier>>),
7093    Delete,
7094    Truncate,
7095}
7096
7097/// Trigger FOR EACH clause
7098#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7099#[cfg_attr(feature = "bindings", derive(TS))]
7100pub enum TriggerForEach {
7101    Row,
7102    Statement,
7103}
7104
7105/// Trigger body
7106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7107#[cfg_attr(feature = "bindings", derive(TS))]
7108pub enum TriggerBody {
7109    /// EXECUTE FUNCTION/PROCEDURE name(args)
7110    Execute {
7111        function: TableRef,
7112        args: Vec<Expression>,
7113    },
7114    /// BEGIN ... END block
7115    Block(String),
7116}
7117
7118/// Trigger REFERENCING clause
7119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7120#[cfg_attr(feature = "bindings", derive(TS))]
7121pub struct TriggerReferencing {
7122    pub old_table: Option<Identifier>,
7123    pub new_table: Option<Identifier>,
7124    pub old_row: Option<Identifier>,
7125    pub new_row: Option<Identifier>,
7126}
7127
7128impl CreateTrigger {
7129    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7130        Self {
7131            name: Identifier::new(name),
7132            table: TableRef::new(table),
7133            timing: TriggerTiming::Before,
7134            events: Vec::new(),
7135            for_each: TriggerForEach::Row,
7136            when: None,
7137            body: TriggerBody::Execute {
7138                function: TableRef::new(""),
7139                args: Vec::new(),
7140            },
7141            or_replace: false,
7142            constraint: false,
7143            deferrable: None,
7144            initially_deferred: None,
7145            referencing: None,
7146        }
7147    }
7148}
7149
7150/// DROP TRIGGER statement
7151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7152#[cfg_attr(feature = "bindings", derive(TS))]
7153pub struct DropTrigger {
7154    pub name: Identifier,
7155    pub table: Option<TableRef>,
7156    pub if_exists: bool,
7157    pub cascade: bool,
7158}
7159
7160impl DropTrigger {
7161    pub fn new(name: impl Into<String>) -> Self {
7162        Self {
7163            name: Identifier::new(name),
7164            table: None,
7165            if_exists: false,
7166            cascade: false,
7167        }
7168    }
7169}
7170
7171/// CREATE TYPE statement
7172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7173#[cfg_attr(feature = "bindings", derive(TS))]
7174pub struct CreateType {
7175    pub name: TableRef,
7176    pub definition: TypeDefinition,
7177    pub if_not_exists: bool,
7178}
7179
7180/// Type definition
7181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7182#[cfg_attr(feature = "bindings", derive(TS))]
7183pub enum TypeDefinition {
7184    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7185    Enum(Vec<String>),
7186    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7187    Composite(Vec<TypeAttribute>),
7188    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7189    Range {
7190        subtype: DataType,
7191        subtype_diff: Option<String>,
7192        canonical: Option<String>,
7193    },
7194    /// Base type (for advanced usage)
7195    Base {
7196        input: String,
7197        output: String,
7198        internallength: Option<i32>,
7199    },
7200    /// Domain type
7201    Domain {
7202        base_type: DataType,
7203        default: Option<Expression>,
7204        constraints: Vec<DomainConstraint>,
7205    },
7206}
7207
7208/// Type attribute for composite types
7209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7210#[cfg_attr(feature = "bindings", derive(TS))]
7211pub struct TypeAttribute {
7212    pub name: Identifier,
7213    pub data_type: DataType,
7214    pub collate: Option<Identifier>,
7215}
7216
7217/// Domain constraint
7218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7219#[cfg_attr(feature = "bindings", derive(TS))]
7220pub struct DomainConstraint {
7221    pub name: Option<Identifier>,
7222    pub check: Expression,
7223}
7224
7225impl CreateType {
7226    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7227        Self {
7228            name: TableRef::new(name),
7229            definition: TypeDefinition::Enum(values),
7230            if_not_exists: false,
7231        }
7232    }
7233
7234    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7235        Self {
7236            name: TableRef::new(name),
7237            definition: TypeDefinition::Composite(attributes),
7238            if_not_exists: false,
7239        }
7240    }
7241}
7242
7243/// DROP TYPE statement
7244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7245#[cfg_attr(feature = "bindings", derive(TS))]
7246pub struct DropType {
7247    pub name: TableRef,
7248    pub if_exists: bool,
7249    pub cascade: bool,
7250}
7251
7252impl DropType {
7253    pub fn new(name: impl Into<String>) -> Self {
7254        Self {
7255            name: TableRef::new(name),
7256            if_exists: false,
7257            cascade: false,
7258        }
7259    }
7260}
7261
7262/// DESCRIBE statement - shows table structure or query plan
7263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7264#[cfg_attr(feature = "bindings", derive(TS))]
7265pub struct Describe {
7266    /// The target to describe (table name or query)
7267    pub target: Expression,
7268    /// EXTENDED format
7269    pub extended: bool,
7270    /// FORMATTED format
7271    pub formatted: bool,
7272    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7273    #[serde(default)]
7274    pub kind: Option<String>,
7275    /// Properties like type=stage
7276    #[serde(default)]
7277    pub properties: Vec<(String, String)>,
7278    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7279    #[serde(default, skip_serializing_if = "Option::is_none")]
7280    pub style: Option<String>,
7281    /// Partition specification for DESCRIBE PARTITION
7282    #[serde(default)]
7283    pub partition: Option<Box<Expression>>,
7284    /// Leading comments before the statement
7285    #[serde(default)]
7286    pub leading_comments: Vec<String>,
7287}
7288
7289impl Describe {
7290    pub fn new(target: Expression) -> Self {
7291        Self {
7292            target,
7293            extended: false,
7294            formatted: false,
7295            kind: None,
7296            properties: Vec::new(),
7297            style: None,
7298            partition: None,
7299            leading_comments: Vec::new(),
7300        }
7301    }
7302}
7303
7304/// SHOW statement - displays database objects
7305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7306#[cfg_attr(feature = "bindings", derive(TS))]
7307pub struct Show {
7308    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7309    pub this: String,
7310    /// Whether TERSE was specified
7311    #[serde(default)]
7312    pub terse: bool,
7313    /// Whether HISTORY was specified
7314    #[serde(default)]
7315    pub history: bool,
7316    /// LIKE pattern
7317    pub like: Option<Expression>,
7318    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7319    pub scope_kind: Option<String>,
7320    /// IN scope object
7321    pub scope: Option<Expression>,
7322    /// STARTS WITH pattern
7323    pub starts_with: Option<Expression>,
7324    /// LIMIT clause
7325    pub limit: Option<Box<Limit>>,
7326    /// FROM clause (for specific object)
7327    pub from: Option<Expression>,
7328    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7329    #[serde(default, skip_serializing_if = "Option::is_none")]
7330    pub where_clause: Option<Expression>,
7331    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7332    #[serde(default, skip_serializing_if = "Option::is_none")]
7333    pub for_target: Option<Expression>,
7334    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7335    #[serde(default, skip_serializing_if = "Option::is_none")]
7336    pub db: Option<Expression>,
7337    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7338    #[serde(default, skip_serializing_if = "Option::is_none")]
7339    pub target: Option<Expression>,
7340    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7341    #[serde(default, skip_serializing_if = "Option::is_none")]
7342    pub mutex: Option<bool>,
7343    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7344    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7345    pub privileges: Vec<String>,
7346}
7347
7348impl Show {
7349    pub fn new(this: impl Into<String>) -> Self {
7350        Self {
7351            this: this.into(),
7352            terse: false,
7353            history: false,
7354            like: None,
7355            scope_kind: None,
7356            scope: None,
7357            starts_with: None,
7358            limit: None,
7359            from: None,
7360            where_clause: None,
7361            for_target: None,
7362            db: None,
7363            target: None,
7364            mutex: None,
7365            privileges: Vec::new(),
7366        }
7367    }
7368}
7369
7370/// Represent an explicit parenthesized expression for grouping precedence.
7371///
7372/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7373/// correctly instead of being flattened to `a + b * c`.
7374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7375#[cfg_attr(feature = "bindings", derive(TS))]
7376pub struct Paren {
7377    /// The inner expression wrapped by parentheses.
7378    pub this: Expression,
7379    #[serde(default)]
7380    pub trailing_comments: Vec<String>,
7381}
7382
7383/// Expression annotated with trailing comments (for round-trip preservation)
7384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7385#[cfg_attr(feature = "bindings", derive(TS))]
7386pub struct Annotated {
7387    pub this: Expression,
7388    pub trailing_comments: Vec<String>,
7389}
7390
7391
7392// === BATCH GENERATED STRUCT DEFINITIONS ===
7393// Generated from Python sqlglot expressions.py
7394
7395/// Refresh
7396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7397#[cfg_attr(feature = "bindings", derive(TS))]
7398pub struct Refresh {
7399    pub this: Box<Expression>,
7400    pub kind: String,
7401}
7402
7403/// LockingStatement
7404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7405#[cfg_attr(feature = "bindings", derive(TS))]
7406pub struct LockingStatement {
7407    pub this: Box<Expression>,
7408    pub expression: Box<Expression>,
7409}
7410
7411/// SequenceProperties
7412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7413#[cfg_attr(feature = "bindings", derive(TS))]
7414pub struct SequenceProperties {
7415    #[serde(default)]
7416    pub increment: Option<Box<Expression>>,
7417    #[serde(default)]
7418    pub minvalue: Option<Box<Expression>>,
7419    #[serde(default)]
7420    pub maxvalue: Option<Box<Expression>>,
7421    #[serde(default)]
7422    pub cache: Option<Box<Expression>>,
7423    #[serde(default)]
7424    pub start: Option<Box<Expression>>,
7425    #[serde(default)]
7426    pub owned: Option<Box<Expression>>,
7427    #[serde(default)]
7428    pub options: Vec<Expression>,
7429}
7430
7431/// TruncateTable
7432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7433#[cfg_attr(feature = "bindings", derive(TS))]
7434pub struct TruncateTable {
7435    #[serde(default)]
7436    pub expressions: Vec<Expression>,
7437    #[serde(default)]
7438    pub is_database: Option<Box<Expression>>,
7439    #[serde(default)]
7440    pub exists: bool,
7441    #[serde(default)]
7442    pub only: Option<Box<Expression>>,
7443    #[serde(default)]
7444    pub cluster: Option<Box<Expression>>,
7445    #[serde(default)]
7446    pub identity: Option<Box<Expression>>,
7447    #[serde(default)]
7448    pub option: Option<Box<Expression>>,
7449    #[serde(default)]
7450    pub partition: Option<Box<Expression>>,
7451}
7452
7453/// Clone
7454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7455#[cfg_attr(feature = "bindings", derive(TS))]
7456pub struct Clone {
7457    pub this: Box<Expression>,
7458    #[serde(default)]
7459    pub shallow: Option<Box<Expression>>,
7460    #[serde(default)]
7461    pub copy: Option<Box<Expression>>,
7462}
7463
7464/// Attach
7465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7466#[cfg_attr(feature = "bindings", derive(TS))]
7467pub struct Attach {
7468    pub this: Box<Expression>,
7469    #[serde(default)]
7470    pub exists: bool,
7471    #[serde(default)]
7472    pub expressions: Vec<Expression>,
7473}
7474
7475/// Detach
7476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7477#[cfg_attr(feature = "bindings", derive(TS))]
7478pub struct Detach {
7479    pub this: Box<Expression>,
7480    #[serde(default)]
7481    pub exists: bool,
7482}
7483
7484/// Install
7485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7486#[cfg_attr(feature = "bindings", derive(TS))]
7487pub struct Install {
7488    pub this: Box<Expression>,
7489    #[serde(default)]
7490    pub from_: Option<Box<Expression>>,
7491    #[serde(default)]
7492    pub force: Option<Box<Expression>>,
7493}
7494
7495/// Summarize
7496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7497#[cfg_attr(feature = "bindings", derive(TS))]
7498pub struct Summarize {
7499    pub this: Box<Expression>,
7500    #[serde(default)]
7501    pub table: Option<Box<Expression>>,
7502}
7503
7504/// Declare
7505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7506#[cfg_attr(feature = "bindings", derive(TS))]
7507pub struct Declare {
7508    #[serde(default)]
7509    pub expressions: Vec<Expression>,
7510}
7511
7512/// DeclareItem
7513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7514#[cfg_attr(feature = "bindings", derive(TS))]
7515pub struct DeclareItem {
7516    pub this: Box<Expression>,
7517    #[serde(default)]
7518    pub kind: Option<String>,
7519    #[serde(default)]
7520    pub default: Option<Box<Expression>>,
7521    #[serde(default)]
7522    pub has_as: bool,
7523    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7524    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7525    pub additional_names: Vec<Expression>,
7526}
7527
7528/// Set
7529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7530#[cfg_attr(feature = "bindings", derive(TS))]
7531pub struct Set {
7532    #[serde(default)]
7533    pub expressions: Vec<Expression>,
7534    #[serde(default)]
7535    pub unset: Option<Box<Expression>>,
7536    #[serde(default)]
7537    pub tag: Option<Box<Expression>>,
7538}
7539
7540/// Heredoc
7541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7542#[cfg_attr(feature = "bindings", derive(TS))]
7543pub struct Heredoc {
7544    pub this: Box<Expression>,
7545    #[serde(default)]
7546    pub tag: Option<Box<Expression>>,
7547}
7548
7549/// QueryBand
7550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7551#[cfg_attr(feature = "bindings", derive(TS))]
7552pub struct QueryBand {
7553    pub this: Box<Expression>,
7554    #[serde(default)]
7555    pub scope: Option<Box<Expression>>,
7556    #[serde(default)]
7557    pub update: Option<Box<Expression>>,
7558}
7559
7560/// UserDefinedFunction
7561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7562#[cfg_attr(feature = "bindings", derive(TS))]
7563pub struct UserDefinedFunction {
7564    pub this: Box<Expression>,
7565    #[serde(default)]
7566    pub expressions: Vec<Expression>,
7567    #[serde(default)]
7568    pub wrapped: Option<Box<Expression>>,
7569}
7570
7571/// RecursiveWithSearch
7572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7573#[cfg_attr(feature = "bindings", derive(TS))]
7574pub struct RecursiveWithSearch {
7575    pub kind: String,
7576    pub this: Box<Expression>,
7577    pub expression: Box<Expression>,
7578    #[serde(default)]
7579    pub using: Option<Box<Expression>>,
7580}
7581
7582/// ProjectionDef
7583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7584#[cfg_attr(feature = "bindings", derive(TS))]
7585pub struct ProjectionDef {
7586    pub this: Box<Expression>,
7587    pub expression: Box<Expression>,
7588}
7589
7590/// TableAlias
7591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7592#[cfg_attr(feature = "bindings", derive(TS))]
7593pub struct TableAlias {
7594    #[serde(default)]
7595    pub this: Option<Box<Expression>>,
7596    #[serde(default)]
7597    pub columns: Vec<Expression>,
7598}
7599
7600/// ByteString
7601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7602#[cfg_attr(feature = "bindings", derive(TS))]
7603pub struct ByteString {
7604    pub this: Box<Expression>,
7605    #[serde(default)]
7606    pub is_bytes: Option<Box<Expression>>,
7607}
7608
7609/// HexStringExpr - Hex string expression (not literal)
7610/// BigQuery: converts to FROM_HEX(this)
7611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7612#[cfg_attr(feature = "bindings", derive(TS))]
7613pub struct HexStringExpr {
7614    pub this: Box<Expression>,
7615    #[serde(default)]
7616    pub is_integer: Option<bool>,
7617}
7618
7619/// UnicodeString
7620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7621#[cfg_attr(feature = "bindings", derive(TS))]
7622pub struct UnicodeString {
7623    pub this: Box<Expression>,
7624    #[serde(default)]
7625    pub escape: Option<Box<Expression>>,
7626}
7627
7628/// AlterColumn
7629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7630#[cfg_attr(feature = "bindings", derive(TS))]
7631pub struct AlterColumn {
7632    pub this: Box<Expression>,
7633    #[serde(default)]
7634    pub dtype: Option<Box<Expression>>,
7635    #[serde(default)]
7636    pub collate: Option<Box<Expression>>,
7637    #[serde(default)]
7638    pub using: Option<Box<Expression>>,
7639    #[serde(default)]
7640    pub default: Option<Box<Expression>>,
7641    #[serde(default)]
7642    pub drop: Option<Box<Expression>>,
7643    #[serde(default)]
7644    pub comment: Option<Box<Expression>>,
7645    #[serde(default)]
7646    pub allow_null: Option<Box<Expression>>,
7647    #[serde(default)]
7648    pub visible: Option<Box<Expression>>,
7649    #[serde(default)]
7650    pub rename_to: Option<Box<Expression>>,
7651}
7652
7653/// AlterSortKey
7654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7655#[cfg_attr(feature = "bindings", derive(TS))]
7656pub struct AlterSortKey {
7657    #[serde(default)]
7658    pub this: Option<Box<Expression>>,
7659    #[serde(default)]
7660    pub expressions: Vec<Expression>,
7661    #[serde(default)]
7662    pub compound: Option<Box<Expression>>,
7663}
7664
7665/// AlterSet
7666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7667#[cfg_attr(feature = "bindings", derive(TS))]
7668pub struct AlterSet {
7669    #[serde(default)]
7670    pub expressions: Vec<Expression>,
7671    #[serde(default)]
7672    pub option: Option<Box<Expression>>,
7673    #[serde(default)]
7674    pub tablespace: Option<Box<Expression>>,
7675    #[serde(default)]
7676    pub access_method: Option<Box<Expression>>,
7677    #[serde(default)]
7678    pub file_format: Option<Box<Expression>>,
7679    #[serde(default)]
7680    pub copy_options: Option<Box<Expression>>,
7681    #[serde(default)]
7682    pub tag: Option<Box<Expression>>,
7683    #[serde(default)]
7684    pub location: Option<Box<Expression>>,
7685    #[serde(default)]
7686    pub serde: Option<Box<Expression>>,
7687}
7688
7689/// RenameColumn
7690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7691#[cfg_attr(feature = "bindings", derive(TS))]
7692pub struct RenameColumn {
7693    pub this: Box<Expression>,
7694    #[serde(default)]
7695    pub to: Option<Box<Expression>>,
7696    #[serde(default)]
7697    pub exists: bool,
7698}
7699
7700/// Comprehension
7701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7702#[cfg_attr(feature = "bindings", derive(TS))]
7703pub struct Comprehension {
7704    pub this: Box<Expression>,
7705    pub expression: Box<Expression>,
7706    #[serde(default)]
7707    pub position: Option<Box<Expression>>,
7708    #[serde(default)]
7709    pub iterator: Option<Box<Expression>>,
7710    #[serde(default)]
7711    pub condition: Option<Box<Expression>>,
7712}
7713
7714/// MergeTreeTTLAction
7715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7716#[cfg_attr(feature = "bindings", derive(TS))]
7717pub struct MergeTreeTTLAction {
7718    pub this: Box<Expression>,
7719    #[serde(default)]
7720    pub delete: Option<Box<Expression>>,
7721    #[serde(default)]
7722    pub recompress: Option<Box<Expression>>,
7723    #[serde(default)]
7724    pub to_disk: Option<Box<Expression>>,
7725    #[serde(default)]
7726    pub to_volume: Option<Box<Expression>>,
7727}
7728
7729/// MergeTreeTTL
7730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7731#[cfg_attr(feature = "bindings", derive(TS))]
7732pub struct MergeTreeTTL {
7733    #[serde(default)]
7734    pub expressions: Vec<Expression>,
7735    #[serde(default)]
7736    pub where_: Option<Box<Expression>>,
7737    #[serde(default)]
7738    pub group: Option<Box<Expression>>,
7739    #[serde(default)]
7740    pub aggregates: Option<Box<Expression>>,
7741}
7742
7743/// IndexConstraintOption
7744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7745#[cfg_attr(feature = "bindings", derive(TS))]
7746pub struct IndexConstraintOption {
7747    #[serde(default)]
7748    pub key_block_size: Option<Box<Expression>>,
7749    #[serde(default)]
7750    pub using: Option<Box<Expression>>,
7751    #[serde(default)]
7752    pub parser: Option<Box<Expression>>,
7753    #[serde(default)]
7754    pub comment: Option<Box<Expression>>,
7755    #[serde(default)]
7756    pub visible: Option<Box<Expression>>,
7757    #[serde(default)]
7758    pub engine_attr: Option<Box<Expression>>,
7759    #[serde(default)]
7760    pub secondary_engine_attr: Option<Box<Expression>>,
7761}
7762
7763/// PeriodForSystemTimeConstraint
7764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7765#[cfg_attr(feature = "bindings", derive(TS))]
7766pub struct PeriodForSystemTimeConstraint {
7767    pub this: Box<Expression>,
7768    pub expression: Box<Expression>,
7769}
7770
7771/// CaseSpecificColumnConstraint
7772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7773#[cfg_attr(feature = "bindings", derive(TS))]
7774pub struct CaseSpecificColumnConstraint {
7775    #[serde(default)]
7776    pub not_: Option<Box<Expression>>,
7777}
7778
7779/// CharacterSetColumnConstraint
7780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7781#[cfg_attr(feature = "bindings", derive(TS))]
7782pub struct CharacterSetColumnConstraint {
7783    pub this: Box<Expression>,
7784}
7785
7786/// CheckColumnConstraint
7787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7788#[cfg_attr(feature = "bindings", derive(TS))]
7789pub struct CheckColumnConstraint {
7790    pub this: Box<Expression>,
7791    #[serde(default)]
7792    pub enforced: Option<Box<Expression>>,
7793}
7794
7795/// CompressColumnConstraint
7796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7797#[cfg_attr(feature = "bindings", derive(TS))]
7798pub struct CompressColumnConstraint {
7799    #[serde(default)]
7800    pub this: Option<Box<Expression>>,
7801}
7802
7803/// DateFormatColumnConstraint
7804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7805#[cfg_attr(feature = "bindings", derive(TS))]
7806pub struct DateFormatColumnConstraint {
7807    pub this: Box<Expression>,
7808}
7809
7810/// EphemeralColumnConstraint
7811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7812#[cfg_attr(feature = "bindings", derive(TS))]
7813pub struct EphemeralColumnConstraint {
7814    #[serde(default)]
7815    pub this: Option<Box<Expression>>,
7816}
7817
7818/// WithOperator
7819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7820#[cfg_attr(feature = "bindings", derive(TS))]
7821pub struct WithOperator {
7822    pub this: Box<Expression>,
7823    pub op: String,
7824}
7825
7826/// GeneratedAsIdentityColumnConstraint
7827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7828#[cfg_attr(feature = "bindings", derive(TS))]
7829pub struct GeneratedAsIdentityColumnConstraint {
7830    #[serde(default)]
7831    pub this: Option<Box<Expression>>,
7832    #[serde(default)]
7833    pub expression: Option<Box<Expression>>,
7834    #[serde(default)]
7835    pub on_null: Option<Box<Expression>>,
7836    #[serde(default)]
7837    pub start: Option<Box<Expression>>,
7838    #[serde(default)]
7839    pub increment: Option<Box<Expression>>,
7840    #[serde(default)]
7841    pub minvalue: Option<Box<Expression>>,
7842    #[serde(default)]
7843    pub maxvalue: Option<Box<Expression>>,
7844    #[serde(default)]
7845    pub cycle: Option<Box<Expression>>,
7846    #[serde(default)]
7847    pub order: Option<Box<Expression>>,
7848}
7849
7850/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
7851/// TSQL: outputs "IDENTITY"
7852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7853#[cfg_attr(feature = "bindings", derive(TS))]
7854pub struct AutoIncrementColumnConstraint;
7855
7856/// CommentColumnConstraint - Column comment marker
7857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7858#[cfg_attr(feature = "bindings", derive(TS))]
7859pub struct CommentColumnConstraint;
7860
7861/// GeneratedAsRowColumnConstraint
7862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7863#[cfg_attr(feature = "bindings", derive(TS))]
7864pub struct GeneratedAsRowColumnConstraint {
7865    #[serde(default)]
7866    pub start: Option<Box<Expression>>,
7867    #[serde(default)]
7868    pub hidden: Option<Box<Expression>>,
7869}
7870
7871/// IndexColumnConstraint
7872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7873#[cfg_attr(feature = "bindings", derive(TS))]
7874pub struct IndexColumnConstraint {
7875    #[serde(default)]
7876    pub this: Option<Box<Expression>>,
7877    #[serde(default)]
7878    pub expressions: Vec<Expression>,
7879    #[serde(default)]
7880    pub kind: Option<String>,
7881    #[serde(default)]
7882    pub index_type: Option<Box<Expression>>,
7883    #[serde(default)]
7884    pub options: Vec<Expression>,
7885    #[serde(default)]
7886    pub expression: Option<Box<Expression>>,
7887    #[serde(default)]
7888    pub granularity: Option<Box<Expression>>,
7889}
7890
7891/// MaskingPolicyColumnConstraint
7892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7893#[cfg_attr(feature = "bindings", derive(TS))]
7894pub struct MaskingPolicyColumnConstraint {
7895    pub this: Box<Expression>,
7896    #[serde(default)]
7897    pub expressions: Vec<Expression>,
7898}
7899
7900/// NotNullColumnConstraint
7901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7902#[cfg_attr(feature = "bindings", derive(TS))]
7903pub struct NotNullColumnConstraint {
7904    #[serde(default)]
7905    pub allow_null: Option<Box<Expression>>,
7906}
7907
7908/// DefaultColumnConstraint - DEFAULT value for a column
7909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7910#[cfg_attr(feature = "bindings", derive(TS))]
7911pub struct DefaultColumnConstraint {
7912    pub this: Box<Expression>,
7913}
7914
7915/// PrimaryKeyColumnConstraint
7916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7917#[cfg_attr(feature = "bindings", derive(TS))]
7918pub struct PrimaryKeyColumnConstraint {
7919    #[serde(default)]
7920    pub desc: Option<Box<Expression>>,
7921    #[serde(default)]
7922    pub options: Vec<Expression>,
7923}
7924
7925/// UniqueColumnConstraint
7926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7927#[cfg_attr(feature = "bindings", derive(TS))]
7928pub struct UniqueColumnConstraint {
7929    #[serde(default)]
7930    pub this: Option<Box<Expression>>,
7931    #[serde(default)]
7932    pub index_type: Option<Box<Expression>>,
7933    #[serde(default)]
7934    pub on_conflict: Option<Box<Expression>>,
7935    #[serde(default)]
7936    pub nulls: Option<Box<Expression>>,
7937    #[serde(default)]
7938    pub options: Vec<Expression>,
7939}
7940
7941/// WatermarkColumnConstraint
7942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7943#[cfg_attr(feature = "bindings", derive(TS))]
7944pub struct WatermarkColumnConstraint {
7945    pub this: Box<Expression>,
7946    pub expression: Box<Expression>,
7947}
7948
7949/// ComputedColumnConstraint
7950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7951#[cfg_attr(feature = "bindings", derive(TS))]
7952pub struct ComputedColumnConstraint {
7953    pub this: Box<Expression>,
7954    #[serde(default)]
7955    pub persisted: Option<Box<Expression>>,
7956    #[serde(default)]
7957    pub not_null: Option<Box<Expression>>,
7958    #[serde(default)]
7959    pub data_type: Option<Box<Expression>>,
7960}
7961
7962/// InOutColumnConstraint
7963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7964#[cfg_attr(feature = "bindings", derive(TS))]
7965pub struct InOutColumnConstraint {
7966    #[serde(default)]
7967    pub input_: Option<Box<Expression>>,
7968    #[serde(default)]
7969    pub output: Option<Box<Expression>>,
7970}
7971
7972/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
7973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7974#[cfg_attr(feature = "bindings", derive(TS))]
7975pub struct PathColumnConstraint {
7976    pub this: Box<Expression>,
7977}
7978
7979/// Constraint
7980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7981#[cfg_attr(feature = "bindings", derive(TS))]
7982pub struct Constraint {
7983    pub this: Box<Expression>,
7984    #[serde(default)]
7985    pub expressions: Vec<Expression>,
7986}
7987
7988/// Export
7989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7990#[cfg_attr(feature = "bindings", derive(TS))]
7991pub struct Export {
7992    pub this: Box<Expression>,
7993    #[serde(default)]
7994    pub connection: Option<Box<Expression>>,
7995    #[serde(default)]
7996    pub options: Vec<Expression>,
7997}
7998
7999/// Filter
8000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8001#[cfg_attr(feature = "bindings", derive(TS))]
8002pub struct Filter {
8003    pub this: Box<Expression>,
8004    pub expression: Box<Expression>,
8005}
8006
8007/// Changes
8008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8009#[cfg_attr(feature = "bindings", derive(TS))]
8010pub struct Changes {
8011    #[serde(default)]
8012    pub information: Option<Box<Expression>>,
8013    #[serde(default)]
8014    pub at_before: Option<Box<Expression>>,
8015    #[serde(default)]
8016    pub end: Option<Box<Expression>>,
8017}
8018
8019/// Directory
8020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8021#[cfg_attr(feature = "bindings", derive(TS))]
8022pub struct Directory {
8023    pub this: Box<Expression>,
8024    #[serde(default)]
8025    pub local: Option<Box<Expression>>,
8026    #[serde(default)]
8027    pub row_format: Option<Box<Expression>>,
8028}
8029
8030/// ForeignKey
8031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8032#[cfg_attr(feature = "bindings", derive(TS))]
8033pub struct ForeignKey {
8034    #[serde(default)]
8035    pub expressions: Vec<Expression>,
8036    #[serde(default)]
8037    pub reference: Option<Box<Expression>>,
8038    #[serde(default)]
8039    pub delete: Option<Box<Expression>>,
8040    #[serde(default)]
8041    pub update: Option<Box<Expression>>,
8042    #[serde(default)]
8043    pub options: Vec<Expression>,
8044}
8045
8046/// ColumnPrefix
8047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8048#[cfg_attr(feature = "bindings", derive(TS))]
8049pub struct ColumnPrefix {
8050    pub this: Box<Expression>,
8051    pub expression: Box<Expression>,
8052}
8053
8054/// PrimaryKey
8055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8056#[cfg_attr(feature = "bindings", derive(TS))]
8057pub struct PrimaryKey {
8058    #[serde(default)]
8059    pub this: Option<Box<Expression>>,
8060    #[serde(default)]
8061    pub expressions: Vec<Expression>,
8062    #[serde(default)]
8063    pub options: Vec<Expression>,
8064    #[serde(default)]
8065    pub include: Option<Box<Expression>>,
8066}
8067
8068/// Into
8069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8070#[cfg_attr(feature = "bindings", derive(TS))]
8071pub struct IntoClause {
8072    #[serde(default)]
8073    pub this: Option<Box<Expression>>,
8074    #[serde(default)]
8075    pub temporary: bool,
8076    #[serde(default)]
8077    pub unlogged: Option<Box<Expression>>,
8078    #[serde(default)]
8079    pub bulk_collect: Option<Box<Expression>>,
8080    #[serde(default)]
8081    pub expressions: Vec<Expression>,
8082}
8083
8084/// JoinHint
8085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8086#[cfg_attr(feature = "bindings", derive(TS))]
8087pub struct JoinHint {
8088    pub this: Box<Expression>,
8089    #[serde(default)]
8090    pub expressions: Vec<Expression>,
8091}
8092
8093/// Opclass
8094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8095#[cfg_attr(feature = "bindings", derive(TS))]
8096pub struct Opclass {
8097    pub this: Box<Expression>,
8098    pub expression: Box<Expression>,
8099}
8100
8101/// Index
8102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8103#[cfg_attr(feature = "bindings", derive(TS))]
8104pub struct Index {
8105    #[serde(default)]
8106    pub this: Option<Box<Expression>>,
8107    #[serde(default)]
8108    pub table: Option<Box<Expression>>,
8109    #[serde(default)]
8110    pub unique: bool,
8111    #[serde(default)]
8112    pub primary: Option<Box<Expression>>,
8113    #[serde(default)]
8114    pub amp: Option<Box<Expression>>,
8115    #[serde(default)]
8116    pub params: Vec<Expression>,
8117}
8118
8119/// IndexParameters
8120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8121#[cfg_attr(feature = "bindings", derive(TS))]
8122pub struct IndexParameters {
8123    #[serde(default)]
8124    pub using: Option<Box<Expression>>,
8125    #[serde(default)]
8126    pub include: Option<Box<Expression>>,
8127    #[serde(default)]
8128    pub columns: Vec<Expression>,
8129    #[serde(default)]
8130    pub with_storage: Option<Box<Expression>>,
8131    #[serde(default)]
8132    pub partition_by: Option<Box<Expression>>,
8133    #[serde(default)]
8134    pub tablespace: Option<Box<Expression>>,
8135    #[serde(default)]
8136    pub where_: Option<Box<Expression>>,
8137    #[serde(default)]
8138    pub on: Option<Box<Expression>>,
8139}
8140
8141/// ConditionalInsert
8142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8143#[cfg_attr(feature = "bindings", derive(TS))]
8144pub struct ConditionalInsert {
8145    pub this: Box<Expression>,
8146    #[serde(default)]
8147    pub expression: Option<Box<Expression>>,
8148    #[serde(default)]
8149    pub else_: Option<Box<Expression>>,
8150}
8151
8152/// MultitableInserts
8153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8154#[cfg_attr(feature = "bindings", derive(TS))]
8155pub struct MultitableInserts {
8156    #[serde(default)]
8157    pub expressions: Vec<Expression>,
8158    pub kind: String,
8159    #[serde(default)]
8160    pub source: Option<Box<Expression>>,
8161    /// Leading comments before the statement
8162    #[serde(default)]
8163    pub leading_comments: Vec<String>,
8164}
8165
8166/// OnConflict
8167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8168#[cfg_attr(feature = "bindings", derive(TS))]
8169pub struct OnConflict {
8170    #[serde(default)]
8171    pub duplicate: Option<Box<Expression>>,
8172    #[serde(default)]
8173    pub expressions: Vec<Expression>,
8174    #[serde(default)]
8175    pub action: Option<Box<Expression>>,
8176    #[serde(default)]
8177    pub conflict_keys: Option<Box<Expression>>,
8178    #[serde(default)]
8179    pub index_predicate: Option<Box<Expression>>,
8180    #[serde(default)]
8181    pub constraint: Option<Box<Expression>>,
8182    #[serde(default)]
8183    pub where_: Option<Box<Expression>>,
8184}
8185
8186/// OnCondition
8187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8188#[cfg_attr(feature = "bindings", derive(TS))]
8189pub struct OnCondition {
8190    #[serde(default)]
8191    pub error: Option<Box<Expression>>,
8192    #[serde(default)]
8193    pub empty: Option<Box<Expression>>,
8194    #[serde(default)]
8195    pub null: Option<Box<Expression>>,
8196}
8197
8198/// Returning
8199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8200#[cfg_attr(feature = "bindings", derive(TS))]
8201pub struct Returning {
8202    #[serde(default)]
8203    pub expressions: Vec<Expression>,
8204    #[serde(default)]
8205    pub into: Option<Box<Expression>>,
8206}
8207
8208/// Introducer
8209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8210#[cfg_attr(feature = "bindings", derive(TS))]
8211pub struct Introducer {
8212    pub this: Box<Expression>,
8213    pub expression: Box<Expression>,
8214}
8215
8216/// PartitionRange
8217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8218#[cfg_attr(feature = "bindings", derive(TS))]
8219pub struct PartitionRange {
8220    pub this: Box<Expression>,
8221    #[serde(default)]
8222    pub expression: Option<Box<Expression>>,
8223    #[serde(default)]
8224    pub expressions: Vec<Expression>,
8225}
8226
8227/// Group
8228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8229#[cfg_attr(feature = "bindings", derive(TS))]
8230pub struct Group {
8231    #[serde(default)]
8232    pub expressions: Vec<Expression>,
8233    #[serde(default)]
8234    pub grouping_sets: Option<Box<Expression>>,
8235    #[serde(default)]
8236    pub cube: Option<Box<Expression>>,
8237    #[serde(default)]
8238    pub rollup: Option<Box<Expression>>,
8239    #[serde(default)]
8240    pub totals: Option<Box<Expression>>,
8241    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8242    #[serde(default)]
8243    pub all: Option<bool>,
8244}
8245
8246/// Cube
8247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8248#[cfg_attr(feature = "bindings", derive(TS))]
8249pub struct Cube {
8250    #[serde(default)]
8251    pub expressions: Vec<Expression>,
8252}
8253
8254/// Rollup
8255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8256#[cfg_attr(feature = "bindings", derive(TS))]
8257pub struct Rollup {
8258    #[serde(default)]
8259    pub expressions: Vec<Expression>,
8260}
8261
8262/// GroupingSets
8263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8264#[cfg_attr(feature = "bindings", derive(TS))]
8265pub struct GroupingSets {
8266    #[serde(default)]
8267    pub expressions: Vec<Expression>,
8268}
8269
8270/// LimitOptions
8271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8272#[cfg_attr(feature = "bindings", derive(TS))]
8273pub struct LimitOptions {
8274    #[serde(default)]
8275    pub percent: Option<Box<Expression>>,
8276    #[serde(default)]
8277    pub rows: Option<Box<Expression>>,
8278    #[serde(default)]
8279    pub with_ties: Option<Box<Expression>>,
8280}
8281
8282/// Lateral
8283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8284#[cfg_attr(feature = "bindings", derive(TS))]
8285pub struct Lateral {
8286    pub this: Box<Expression>,
8287    #[serde(default)]
8288    pub view: Option<Box<Expression>>,
8289    #[serde(default)]
8290    pub outer: Option<Box<Expression>>,
8291    #[serde(default)]
8292    pub alias: Option<String>,
8293    /// Whether the alias was originally quoted (backtick/double-quote)
8294    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8295    pub alias_quoted: bool,
8296    #[serde(default)]
8297    pub cross_apply: Option<Box<Expression>>,
8298    #[serde(default)]
8299    pub ordinality: Option<Box<Expression>>,
8300    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8301    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8302    pub column_aliases: Vec<String>,
8303}
8304
8305/// TableFromRows
8306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8307#[cfg_attr(feature = "bindings", derive(TS))]
8308pub struct TableFromRows {
8309    pub this: Box<Expression>,
8310    #[serde(default)]
8311    pub alias: Option<String>,
8312    #[serde(default)]
8313    pub joins: Vec<Expression>,
8314    #[serde(default)]
8315    pub pivots: Option<Box<Expression>>,
8316    #[serde(default)]
8317    pub sample: Option<Box<Expression>>,
8318}
8319
8320/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8321/// Used for set-returning functions with typed column definitions
8322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8323#[cfg_attr(feature = "bindings", derive(TS))]
8324pub struct RowsFrom {
8325    /// List of function expressions, each potentially with an alias and typed columns
8326    pub expressions: Vec<Expression>,
8327    /// WITH ORDINALITY modifier
8328    #[serde(default)]
8329    pub ordinality: bool,
8330    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8331    #[serde(default)]
8332    pub alias: Option<Box<Expression>>,
8333}
8334
8335/// WithFill
8336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8337#[cfg_attr(feature = "bindings", derive(TS))]
8338pub struct WithFill {
8339    #[serde(default)]
8340    pub from_: Option<Box<Expression>>,
8341    #[serde(default)]
8342    pub to: Option<Box<Expression>>,
8343    #[serde(default)]
8344    pub step: Option<Box<Expression>>,
8345    #[serde(default)]
8346    pub interpolate: Option<Box<Expression>>,
8347}
8348
8349/// Property
8350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8351#[cfg_attr(feature = "bindings", derive(TS))]
8352pub struct Property {
8353    pub this: Box<Expression>,
8354    #[serde(default)]
8355    pub value: Option<Box<Expression>>,
8356}
8357
8358/// GrantPrivilege
8359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8360#[cfg_attr(feature = "bindings", derive(TS))]
8361pub struct GrantPrivilege {
8362    pub this: Box<Expression>,
8363    #[serde(default)]
8364    pub expressions: Vec<Expression>,
8365}
8366
8367/// AllowedValuesProperty
8368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8369#[cfg_attr(feature = "bindings", derive(TS))]
8370pub struct AllowedValuesProperty {
8371    #[serde(default)]
8372    pub expressions: Vec<Expression>,
8373}
8374
8375/// AlgorithmProperty
8376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8377#[cfg_attr(feature = "bindings", derive(TS))]
8378pub struct AlgorithmProperty {
8379    pub this: Box<Expression>,
8380}
8381
8382/// AutoIncrementProperty
8383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8384#[cfg_attr(feature = "bindings", derive(TS))]
8385pub struct AutoIncrementProperty {
8386    pub this: Box<Expression>,
8387}
8388
8389/// AutoRefreshProperty
8390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8391#[cfg_attr(feature = "bindings", derive(TS))]
8392pub struct AutoRefreshProperty {
8393    pub this: Box<Expression>,
8394}
8395
8396/// BackupProperty
8397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8398#[cfg_attr(feature = "bindings", derive(TS))]
8399pub struct BackupProperty {
8400    pub this: Box<Expression>,
8401}
8402
8403/// BuildProperty
8404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8405#[cfg_attr(feature = "bindings", derive(TS))]
8406pub struct BuildProperty {
8407    pub this: Box<Expression>,
8408}
8409
8410/// BlockCompressionProperty
8411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8412#[cfg_attr(feature = "bindings", derive(TS))]
8413pub struct BlockCompressionProperty {
8414    #[serde(default)]
8415    pub autotemp: Option<Box<Expression>>,
8416    #[serde(default)]
8417    pub always: Option<Box<Expression>>,
8418    #[serde(default)]
8419    pub default: Option<Box<Expression>>,
8420    #[serde(default)]
8421    pub manual: Option<Box<Expression>>,
8422    #[serde(default)]
8423    pub never: Option<Box<Expression>>,
8424}
8425
8426/// CharacterSetProperty
8427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8428#[cfg_attr(feature = "bindings", derive(TS))]
8429pub struct CharacterSetProperty {
8430    pub this: Box<Expression>,
8431    #[serde(default)]
8432    pub default: Option<Box<Expression>>,
8433}
8434
8435/// ChecksumProperty
8436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8437#[cfg_attr(feature = "bindings", derive(TS))]
8438pub struct ChecksumProperty {
8439    #[serde(default)]
8440    pub on: Option<Box<Expression>>,
8441    #[serde(default)]
8442    pub default: Option<Box<Expression>>,
8443}
8444
8445/// CollateProperty
8446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8447#[cfg_attr(feature = "bindings", derive(TS))]
8448pub struct CollateProperty {
8449    pub this: Box<Expression>,
8450    #[serde(default)]
8451    pub default: Option<Box<Expression>>,
8452}
8453
8454/// DataBlocksizeProperty
8455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8456#[cfg_attr(feature = "bindings", derive(TS))]
8457pub struct DataBlocksizeProperty {
8458    #[serde(default)]
8459    pub size: Option<i64>,
8460    #[serde(default)]
8461    pub units: Option<Box<Expression>>,
8462    #[serde(default)]
8463    pub minimum: Option<Box<Expression>>,
8464    #[serde(default)]
8465    pub maximum: Option<Box<Expression>>,
8466    #[serde(default)]
8467    pub default: Option<Box<Expression>>,
8468}
8469
8470/// DataDeletionProperty
8471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8472#[cfg_attr(feature = "bindings", derive(TS))]
8473pub struct DataDeletionProperty {
8474    pub on: Box<Expression>,
8475    #[serde(default)]
8476    pub filter_column: Option<Box<Expression>>,
8477    #[serde(default)]
8478    pub retention_period: Option<Box<Expression>>,
8479}
8480
8481/// DefinerProperty
8482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8483#[cfg_attr(feature = "bindings", derive(TS))]
8484pub struct DefinerProperty {
8485    pub this: Box<Expression>,
8486}
8487
8488/// DistKeyProperty
8489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8490#[cfg_attr(feature = "bindings", derive(TS))]
8491pub struct DistKeyProperty {
8492    pub this: Box<Expression>,
8493}
8494
8495/// DistributedByProperty
8496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8497#[cfg_attr(feature = "bindings", derive(TS))]
8498pub struct DistributedByProperty {
8499    #[serde(default)]
8500    pub expressions: Vec<Expression>,
8501    pub kind: String,
8502    #[serde(default)]
8503    pub buckets: Option<Box<Expression>>,
8504    #[serde(default)]
8505    pub order: Option<Box<Expression>>,
8506}
8507
8508/// DistStyleProperty
8509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8510#[cfg_attr(feature = "bindings", derive(TS))]
8511pub struct DistStyleProperty {
8512    pub this: Box<Expression>,
8513}
8514
8515/// DuplicateKeyProperty
8516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8517#[cfg_attr(feature = "bindings", derive(TS))]
8518pub struct DuplicateKeyProperty {
8519    #[serde(default)]
8520    pub expressions: Vec<Expression>,
8521}
8522
8523/// EngineProperty
8524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8525#[cfg_attr(feature = "bindings", derive(TS))]
8526pub struct EngineProperty {
8527    pub this: Box<Expression>,
8528}
8529
8530/// ToTableProperty
8531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8532#[cfg_attr(feature = "bindings", derive(TS))]
8533pub struct ToTableProperty {
8534    pub this: Box<Expression>,
8535}
8536
8537/// ExecuteAsProperty
8538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8539#[cfg_attr(feature = "bindings", derive(TS))]
8540pub struct ExecuteAsProperty {
8541    pub this: Box<Expression>,
8542}
8543
8544/// ExternalProperty
8545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8546#[cfg_attr(feature = "bindings", derive(TS))]
8547pub struct ExternalProperty {
8548    #[serde(default)]
8549    pub this: Option<Box<Expression>>,
8550}
8551
8552/// FallbackProperty
8553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8554#[cfg_attr(feature = "bindings", derive(TS))]
8555pub struct FallbackProperty {
8556    #[serde(default)]
8557    pub no: Option<Box<Expression>>,
8558    #[serde(default)]
8559    pub protection: Option<Box<Expression>>,
8560}
8561
8562/// FileFormatProperty
8563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8564#[cfg_attr(feature = "bindings", derive(TS))]
8565pub struct FileFormatProperty {
8566    #[serde(default)]
8567    pub this: Option<Box<Expression>>,
8568    #[serde(default)]
8569    pub expressions: Vec<Expression>,
8570    #[serde(default)]
8571    pub hive_format: Option<Box<Expression>>,
8572}
8573
8574/// CredentialsProperty
8575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8576#[cfg_attr(feature = "bindings", derive(TS))]
8577pub struct CredentialsProperty {
8578    #[serde(default)]
8579    pub expressions: Vec<Expression>,
8580}
8581
8582/// FreespaceProperty
8583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8584#[cfg_attr(feature = "bindings", derive(TS))]
8585pub struct FreespaceProperty {
8586    pub this: Box<Expression>,
8587    #[serde(default)]
8588    pub percent: Option<Box<Expression>>,
8589}
8590
8591/// InheritsProperty
8592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8593#[cfg_attr(feature = "bindings", derive(TS))]
8594pub struct InheritsProperty {
8595    #[serde(default)]
8596    pub expressions: Vec<Expression>,
8597}
8598
8599/// InputModelProperty
8600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8601#[cfg_attr(feature = "bindings", derive(TS))]
8602pub struct InputModelProperty {
8603    pub this: Box<Expression>,
8604}
8605
8606/// OutputModelProperty
8607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8608#[cfg_attr(feature = "bindings", derive(TS))]
8609pub struct OutputModelProperty {
8610    pub this: Box<Expression>,
8611}
8612
8613/// IsolatedLoadingProperty
8614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8615#[cfg_attr(feature = "bindings", derive(TS))]
8616pub struct IsolatedLoadingProperty {
8617    #[serde(default)]
8618    pub no: Option<Box<Expression>>,
8619    #[serde(default)]
8620    pub concurrent: Option<Box<Expression>>,
8621    #[serde(default)]
8622    pub target: Option<Box<Expression>>,
8623}
8624
8625/// JournalProperty
8626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8627#[cfg_attr(feature = "bindings", derive(TS))]
8628pub struct JournalProperty {
8629    #[serde(default)]
8630    pub no: Option<Box<Expression>>,
8631    #[serde(default)]
8632    pub dual: Option<Box<Expression>>,
8633    #[serde(default)]
8634    pub before: Option<Box<Expression>>,
8635    #[serde(default)]
8636    pub local: Option<Box<Expression>>,
8637    #[serde(default)]
8638    pub after: Option<Box<Expression>>,
8639}
8640
8641/// LanguageProperty
8642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8643#[cfg_attr(feature = "bindings", derive(TS))]
8644pub struct LanguageProperty {
8645    pub this: Box<Expression>,
8646}
8647
8648/// EnviromentProperty
8649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8650#[cfg_attr(feature = "bindings", derive(TS))]
8651pub struct EnviromentProperty {
8652    #[serde(default)]
8653    pub expressions: Vec<Expression>,
8654}
8655
8656/// ClusteredByProperty
8657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8658#[cfg_attr(feature = "bindings", derive(TS))]
8659pub struct ClusteredByProperty {
8660    #[serde(default)]
8661    pub expressions: Vec<Expression>,
8662    #[serde(default)]
8663    pub sorted_by: Option<Box<Expression>>,
8664    #[serde(default)]
8665    pub buckets: Option<Box<Expression>>,
8666}
8667
8668/// DictProperty
8669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8670#[cfg_attr(feature = "bindings", derive(TS))]
8671pub struct DictProperty {
8672    pub this: Box<Expression>,
8673    pub kind: String,
8674    #[serde(default)]
8675    pub settings: Option<Box<Expression>>,
8676}
8677
8678/// DictRange
8679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8680#[cfg_attr(feature = "bindings", derive(TS))]
8681pub struct DictRange {
8682    pub this: Box<Expression>,
8683    #[serde(default)]
8684    pub min: Option<Box<Expression>>,
8685    #[serde(default)]
8686    pub max: Option<Box<Expression>>,
8687}
8688
8689/// OnCluster
8690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8691#[cfg_attr(feature = "bindings", derive(TS))]
8692pub struct OnCluster {
8693    pub this: Box<Expression>,
8694}
8695
8696/// LikeProperty
8697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8698#[cfg_attr(feature = "bindings", derive(TS))]
8699pub struct LikeProperty {
8700    pub this: Box<Expression>,
8701    #[serde(default)]
8702    pub expressions: Vec<Expression>,
8703}
8704
8705/// LocationProperty
8706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8707#[cfg_attr(feature = "bindings", derive(TS))]
8708pub struct LocationProperty {
8709    pub this: Box<Expression>,
8710}
8711
8712/// LockProperty
8713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8714#[cfg_attr(feature = "bindings", derive(TS))]
8715pub struct LockProperty {
8716    pub this: Box<Expression>,
8717}
8718
8719/// LockingProperty
8720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8721#[cfg_attr(feature = "bindings", derive(TS))]
8722pub struct LockingProperty {
8723    #[serde(default)]
8724    pub this: Option<Box<Expression>>,
8725    pub kind: String,
8726    #[serde(default)]
8727    pub for_or_in: Option<Box<Expression>>,
8728    #[serde(default)]
8729    pub lock_type: Option<Box<Expression>>,
8730    #[serde(default)]
8731    pub override_: Option<Box<Expression>>,
8732}
8733
8734/// LogProperty
8735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8736#[cfg_attr(feature = "bindings", derive(TS))]
8737pub struct LogProperty {
8738    #[serde(default)]
8739    pub no: Option<Box<Expression>>,
8740}
8741
8742/// MaterializedProperty
8743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8744#[cfg_attr(feature = "bindings", derive(TS))]
8745pub struct MaterializedProperty {
8746    #[serde(default)]
8747    pub this: Option<Box<Expression>>,
8748}
8749
8750/// MergeBlockRatioProperty
8751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8752#[cfg_attr(feature = "bindings", derive(TS))]
8753pub struct MergeBlockRatioProperty {
8754    #[serde(default)]
8755    pub this: Option<Box<Expression>>,
8756    #[serde(default)]
8757    pub no: Option<Box<Expression>>,
8758    #[serde(default)]
8759    pub default: Option<Box<Expression>>,
8760    #[serde(default)]
8761    pub percent: Option<Box<Expression>>,
8762}
8763
8764/// OnProperty
8765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8766#[cfg_attr(feature = "bindings", derive(TS))]
8767pub struct OnProperty {
8768    pub this: Box<Expression>,
8769}
8770
8771/// OnCommitProperty
8772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8773#[cfg_attr(feature = "bindings", derive(TS))]
8774pub struct OnCommitProperty {
8775    #[serde(default)]
8776    pub delete: Option<Box<Expression>>,
8777}
8778
8779/// PartitionedByProperty
8780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8781#[cfg_attr(feature = "bindings", derive(TS))]
8782pub struct PartitionedByProperty {
8783    pub this: Box<Expression>,
8784}
8785
8786/// PartitionedByBucket
8787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8788#[cfg_attr(feature = "bindings", derive(TS))]
8789pub struct PartitionedByBucket {
8790    pub this: Box<Expression>,
8791    pub expression: Box<Expression>,
8792}
8793
8794/// PartitionByTruncate
8795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8796#[cfg_attr(feature = "bindings", derive(TS))]
8797pub struct PartitionByTruncate {
8798    pub this: Box<Expression>,
8799    pub expression: Box<Expression>,
8800}
8801
8802/// PartitionByRangeProperty
8803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8804#[cfg_attr(feature = "bindings", derive(TS))]
8805pub struct PartitionByRangeProperty {
8806    #[serde(default)]
8807    pub partition_expressions: Option<Box<Expression>>,
8808    #[serde(default)]
8809    pub create_expressions: Option<Box<Expression>>,
8810}
8811
8812/// PartitionByRangePropertyDynamic
8813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8814#[cfg_attr(feature = "bindings", derive(TS))]
8815pub struct PartitionByRangePropertyDynamic {
8816    #[serde(default)]
8817    pub this: Option<Box<Expression>>,
8818    #[serde(default)]
8819    pub start: Option<Box<Expression>>,
8820    #[serde(default)]
8821    pub end: Option<Box<Expression>>,
8822    #[serde(default)]
8823    pub every: Option<Box<Expression>>,
8824}
8825
8826/// PartitionByListProperty
8827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8828#[cfg_attr(feature = "bindings", derive(TS))]
8829pub struct PartitionByListProperty {
8830    #[serde(default)]
8831    pub partition_expressions: Option<Box<Expression>>,
8832    #[serde(default)]
8833    pub create_expressions: Option<Box<Expression>>,
8834}
8835
8836/// PartitionList
8837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8838#[cfg_attr(feature = "bindings", derive(TS))]
8839pub struct PartitionList {
8840    pub this: Box<Expression>,
8841    #[serde(default)]
8842    pub expressions: Vec<Expression>,
8843}
8844
8845/// Partition - represents PARTITION/SUBPARTITION clause
8846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8847#[cfg_attr(feature = "bindings", derive(TS))]
8848pub struct Partition {
8849    pub expressions: Vec<Expression>,
8850    #[serde(default)]
8851    pub subpartition: bool,
8852}
8853
8854/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
8855/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
8856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8857#[cfg_attr(feature = "bindings", derive(TS))]
8858pub struct RefreshTriggerProperty {
8859    /// Method: COMPLETE or AUTO
8860    pub method: String,
8861    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
8862    #[serde(default)]
8863    pub kind: Option<String>,
8864    /// For SCHEDULE: EVERY n (the number)
8865    #[serde(default)]
8866    pub every: Option<Box<Expression>>,
8867    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
8868    #[serde(default)]
8869    pub unit: Option<String>,
8870    /// For SCHEDULE: STARTS 'datetime'
8871    #[serde(default)]
8872    pub starts: Option<Box<Expression>>,
8873}
8874
8875/// UniqueKeyProperty
8876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8877#[cfg_attr(feature = "bindings", derive(TS))]
8878pub struct UniqueKeyProperty {
8879    #[serde(default)]
8880    pub expressions: Vec<Expression>,
8881}
8882
8883/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
8884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8885#[cfg_attr(feature = "bindings", derive(TS))]
8886pub struct RollupProperty {
8887    pub expressions: Vec<RollupIndex>,
8888}
8889
8890/// RollupIndex - A single rollup index: name(col1, col2)
8891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8892#[cfg_attr(feature = "bindings", derive(TS))]
8893pub struct RollupIndex {
8894    pub name: Identifier,
8895    pub expressions: Vec<Identifier>,
8896}
8897
8898/// PartitionBoundSpec
8899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8900#[cfg_attr(feature = "bindings", derive(TS))]
8901pub struct PartitionBoundSpec {
8902    #[serde(default)]
8903    pub this: Option<Box<Expression>>,
8904    #[serde(default)]
8905    pub expression: Option<Box<Expression>>,
8906    #[serde(default)]
8907    pub from_expressions: Option<Box<Expression>>,
8908    #[serde(default)]
8909    pub to_expressions: Option<Box<Expression>>,
8910}
8911
8912/// PartitionedOfProperty
8913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8914#[cfg_attr(feature = "bindings", derive(TS))]
8915pub struct PartitionedOfProperty {
8916    pub this: Box<Expression>,
8917    pub expression: Box<Expression>,
8918}
8919
8920/// RemoteWithConnectionModelProperty
8921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8922#[cfg_attr(feature = "bindings", derive(TS))]
8923pub struct RemoteWithConnectionModelProperty {
8924    pub this: Box<Expression>,
8925}
8926
8927/// ReturnsProperty
8928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8929#[cfg_attr(feature = "bindings", derive(TS))]
8930pub struct ReturnsProperty {
8931    #[serde(default)]
8932    pub this: Option<Box<Expression>>,
8933    #[serde(default)]
8934    pub is_table: Option<Box<Expression>>,
8935    #[serde(default)]
8936    pub table: Option<Box<Expression>>,
8937    #[serde(default)]
8938    pub null: Option<Box<Expression>>,
8939}
8940
8941/// RowFormatProperty
8942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8943#[cfg_attr(feature = "bindings", derive(TS))]
8944pub struct RowFormatProperty {
8945    pub this: Box<Expression>,
8946}
8947
8948/// RowFormatDelimitedProperty
8949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8950#[cfg_attr(feature = "bindings", derive(TS))]
8951pub struct RowFormatDelimitedProperty {
8952    #[serde(default)]
8953    pub fields: Option<Box<Expression>>,
8954    #[serde(default)]
8955    pub escaped: Option<Box<Expression>>,
8956    #[serde(default)]
8957    pub collection_items: Option<Box<Expression>>,
8958    #[serde(default)]
8959    pub map_keys: Option<Box<Expression>>,
8960    #[serde(default)]
8961    pub lines: Option<Box<Expression>>,
8962    #[serde(default)]
8963    pub null: Option<Box<Expression>>,
8964    #[serde(default)]
8965    pub serde: Option<Box<Expression>>,
8966}
8967
8968/// RowFormatSerdeProperty
8969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8970#[cfg_attr(feature = "bindings", derive(TS))]
8971pub struct RowFormatSerdeProperty {
8972    pub this: Box<Expression>,
8973    #[serde(default)]
8974    pub serde_properties: Option<Box<Expression>>,
8975}
8976
8977/// QueryTransform
8978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8979#[cfg_attr(feature = "bindings", derive(TS))]
8980pub struct QueryTransform {
8981    #[serde(default)]
8982    pub expressions: Vec<Expression>,
8983    #[serde(default)]
8984    pub command_script: Option<Box<Expression>>,
8985    #[serde(default)]
8986    pub schema: Option<Box<Expression>>,
8987    #[serde(default)]
8988    pub row_format_before: Option<Box<Expression>>,
8989    #[serde(default)]
8990    pub record_writer: Option<Box<Expression>>,
8991    #[serde(default)]
8992    pub row_format_after: Option<Box<Expression>>,
8993    #[serde(default)]
8994    pub record_reader: Option<Box<Expression>>,
8995}
8996
8997/// SampleProperty
8998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8999#[cfg_attr(feature = "bindings", derive(TS))]
9000pub struct SampleProperty {
9001    pub this: Box<Expression>,
9002}
9003
9004/// SecurityProperty
9005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9006#[cfg_attr(feature = "bindings", derive(TS))]
9007pub struct SecurityProperty {
9008    pub this: Box<Expression>,
9009}
9010
9011/// SchemaCommentProperty
9012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9013#[cfg_attr(feature = "bindings", derive(TS))]
9014pub struct SchemaCommentProperty {
9015    pub this: Box<Expression>,
9016}
9017
9018/// SemanticView
9019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9020#[cfg_attr(feature = "bindings", derive(TS))]
9021pub struct SemanticView {
9022    pub this: Box<Expression>,
9023    #[serde(default)]
9024    pub metrics: Option<Box<Expression>>,
9025    #[serde(default)]
9026    pub dimensions: Option<Box<Expression>>,
9027    #[serde(default)]
9028    pub facts: Option<Box<Expression>>,
9029    #[serde(default)]
9030    pub where_: Option<Box<Expression>>,
9031}
9032
9033/// SerdeProperties
9034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9035#[cfg_attr(feature = "bindings", derive(TS))]
9036pub struct SerdeProperties {
9037    #[serde(default)]
9038    pub expressions: Vec<Expression>,
9039    #[serde(default)]
9040    pub with_: Option<Box<Expression>>,
9041}
9042
9043/// SetProperty
9044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9045#[cfg_attr(feature = "bindings", derive(TS))]
9046pub struct SetProperty {
9047    #[serde(default)]
9048    pub multi: Option<Box<Expression>>,
9049}
9050
9051/// SharingProperty
9052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9053#[cfg_attr(feature = "bindings", derive(TS))]
9054pub struct SharingProperty {
9055    #[serde(default)]
9056    pub this: Option<Box<Expression>>,
9057}
9058
9059/// SetConfigProperty
9060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9061#[cfg_attr(feature = "bindings", derive(TS))]
9062pub struct SetConfigProperty {
9063    pub this: Box<Expression>,
9064}
9065
9066/// SettingsProperty
9067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9068#[cfg_attr(feature = "bindings", derive(TS))]
9069pub struct SettingsProperty {
9070    #[serde(default)]
9071    pub expressions: Vec<Expression>,
9072}
9073
9074/// SortKeyProperty
9075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9076#[cfg_attr(feature = "bindings", derive(TS))]
9077pub struct SortKeyProperty {
9078    pub this: Box<Expression>,
9079    #[serde(default)]
9080    pub compound: Option<Box<Expression>>,
9081}
9082
9083/// SqlReadWriteProperty
9084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9085#[cfg_attr(feature = "bindings", derive(TS))]
9086pub struct SqlReadWriteProperty {
9087    pub this: Box<Expression>,
9088}
9089
9090/// SqlSecurityProperty
9091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9092#[cfg_attr(feature = "bindings", derive(TS))]
9093pub struct SqlSecurityProperty {
9094    pub this: Box<Expression>,
9095}
9096
9097/// StabilityProperty
9098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9099#[cfg_attr(feature = "bindings", derive(TS))]
9100pub struct StabilityProperty {
9101    pub this: Box<Expression>,
9102}
9103
9104/// StorageHandlerProperty
9105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9106#[cfg_attr(feature = "bindings", derive(TS))]
9107pub struct StorageHandlerProperty {
9108    pub this: Box<Expression>,
9109}
9110
9111/// TemporaryProperty
9112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9113#[cfg_attr(feature = "bindings", derive(TS))]
9114pub struct TemporaryProperty {
9115    #[serde(default)]
9116    pub this: Option<Box<Expression>>,
9117}
9118
9119/// Tags
9120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9121#[cfg_attr(feature = "bindings", derive(TS))]
9122pub struct Tags {
9123    #[serde(default)]
9124    pub expressions: Vec<Expression>,
9125}
9126
9127/// TransformModelProperty
9128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9129#[cfg_attr(feature = "bindings", derive(TS))]
9130pub struct TransformModelProperty {
9131    #[serde(default)]
9132    pub expressions: Vec<Expression>,
9133}
9134
9135/// TransientProperty
9136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9137#[cfg_attr(feature = "bindings", derive(TS))]
9138pub struct TransientProperty {
9139    #[serde(default)]
9140    pub this: Option<Box<Expression>>,
9141}
9142
9143/// UsingTemplateProperty
9144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9145#[cfg_attr(feature = "bindings", derive(TS))]
9146pub struct UsingTemplateProperty {
9147    pub this: Box<Expression>,
9148}
9149
9150/// ViewAttributeProperty
9151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9152#[cfg_attr(feature = "bindings", derive(TS))]
9153pub struct ViewAttributeProperty {
9154    pub this: Box<Expression>,
9155}
9156
9157/// VolatileProperty
9158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9159#[cfg_attr(feature = "bindings", derive(TS))]
9160pub struct VolatileProperty {
9161    #[serde(default)]
9162    pub this: Option<Box<Expression>>,
9163}
9164
9165/// WithDataProperty
9166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9167#[cfg_attr(feature = "bindings", derive(TS))]
9168pub struct WithDataProperty {
9169    #[serde(default)]
9170    pub no: Option<Box<Expression>>,
9171    #[serde(default)]
9172    pub statistics: Option<Box<Expression>>,
9173}
9174
9175/// WithJournalTableProperty
9176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9177#[cfg_attr(feature = "bindings", derive(TS))]
9178pub struct WithJournalTableProperty {
9179    pub this: Box<Expression>,
9180}
9181
9182/// WithSchemaBindingProperty
9183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9184#[cfg_attr(feature = "bindings", derive(TS))]
9185pub struct WithSchemaBindingProperty {
9186    pub this: Box<Expression>,
9187}
9188
9189/// WithSystemVersioningProperty
9190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9191#[cfg_attr(feature = "bindings", derive(TS))]
9192pub struct WithSystemVersioningProperty {
9193    #[serde(default)]
9194    pub on: Option<Box<Expression>>,
9195    #[serde(default)]
9196    pub this: Option<Box<Expression>>,
9197    #[serde(default)]
9198    pub data_consistency: Option<Box<Expression>>,
9199    #[serde(default)]
9200    pub retention_period: Option<Box<Expression>>,
9201    #[serde(default)]
9202    pub with_: Option<Box<Expression>>,
9203}
9204
9205/// WithProcedureOptions
9206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9207#[cfg_attr(feature = "bindings", derive(TS))]
9208pub struct WithProcedureOptions {
9209    #[serde(default)]
9210    pub expressions: Vec<Expression>,
9211}
9212
9213/// EncodeProperty
9214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9215#[cfg_attr(feature = "bindings", derive(TS))]
9216pub struct EncodeProperty {
9217    pub this: Box<Expression>,
9218    #[serde(default)]
9219    pub properties: Vec<Expression>,
9220    #[serde(default)]
9221    pub key: Option<Box<Expression>>,
9222}
9223
9224/// IncludeProperty
9225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9226#[cfg_attr(feature = "bindings", derive(TS))]
9227pub struct IncludeProperty {
9228    pub this: Box<Expression>,
9229    #[serde(default)]
9230    pub alias: Option<String>,
9231    #[serde(default)]
9232    pub column_def: Option<Box<Expression>>,
9233}
9234
9235/// Properties
9236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9237#[cfg_attr(feature = "bindings", derive(TS))]
9238pub struct Properties {
9239    #[serde(default)]
9240    pub expressions: Vec<Expression>,
9241}
9242
9243/// InputOutputFormat
9244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9245#[cfg_attr(feature = "bindings", derive(TS))]
9246pub struct InputOutputFormat {
9247    #[serde(default)]
9248    pub input_format: Option<Box<Expression>>,
9249    #[serde(default)]
9250    pub output_format: Option<Box<Expression>>,
9251}
9252
9253/// Reference
9254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9255#[cfg_attr(feature = "bindings", derive(TS))]
9256pub struct Reference {
9257    pub this: Box<Expression>,
9258    #[serde(default)]
9259    pub expressions: Vec<Expression>,
9260    #[serde(default)]
9261    pub options: Vec<Expression>,
9262}
9263
9264/// QueryOption
9265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9266#[cfg_attr(feature = "bindings", derive(TS))]
9267pub struct QueryOption {
9268    pub this: Box<Expression>,
9269    #[serde(default)]
9270    pub expression: Option<Box<Expression>>,
9271}
9272
9273/// WithTableHint
9274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9275#[cfg_attr(feature = "bindings", derive(TS))]
9276pub struct WithTableHint {
9277    #[serde(default)]
9278    pub expressions: Vec<Expression>,
9279}
9280
9281/// IndexTableHint
9282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9283#[cfg_attr(feature = "bindings", derive(TS))]
9284pub struct IndexTableHint {
9285    pub this: Box<Expression>,
9286    #[serde(default)]
9287    pub expressions: Vec<Expression>,
9288    #[serde(default)]
9289    pub target: Option<Box<Expression>>,
9290}
9291
9292/// Get
9293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9294#[cfg_attr(feature = "bindings", derive(TS))]
9295pub struct Get {
9296    pub this: Box<Expression>,
9297    #[serde(default)]
9298    pub target: Option<Box<Expression>>,
9299    #[serde(default)]
9300    pub properties: Vec<Expression>,
9301}
9302
9303/// SetOperation
9304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9305#[cfg_attr(feature = "bindings", derive(TS))]
9306pub struct SetOperation {
9307    #[serde(default)]
9308    pub with_: Option<Box<Expression>>,
9309    pub this: Box<Expression>,
9310    pub expression: Box<Expression>,
9311    #[serde(default)]
9312    pub distinct: bool,
9313    #[serde(default)]
9314    pub by_name: Option<Box<Expression>>,
9315    #[serde(default)]
9316    pub side: Option<Box<Expression>>,
9317    #[serde(default)]
9318    pub kind: Option<String>,
9319    #[serde(default)]
9320    pub on: Option<Box<Expression>>,
9321}
9322
9323/// Var - Simple variable reference (for SQL variables, keywords as values)
9324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9325#[cfg_attr(feature = "bindings", derive(TS))]
9326pub struct Var {
9327    pub this: String,
9328}
9329
9330/// Version
9331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9332#[cfg_attr(feature = "bindings", derive(TS))]
9333pub struct Version {
9334    pub this: Box<Expression>,
9335    pub kind: String,
9336    #[serde(default)]
9337    pub expression: Option<Box<Expression>>,
9338}
9339
9340/// Schema
9341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9342#[cfg_attr(feature = "bindings", derive(TS))]
9343pub struct Schema {
9344    #[serde(default)]
9345    pub this: Option<Box<Expression>>,
9346    #[serde(default)]
9347    pub expressions: Vec<Expression>,
9348}
9349
9350/// Lock
9351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9352#[cfg_attr(feature = "bindings", derive(TS))]
9353pub struct Lock {
9354    #[serde(default)]
9355    pub update: Option<Box<Expression>>,
9356    #[serde(default)]
9357    pub expressions: Vec<Expression>,
9358    #[serde(default)]
9359    pub wait: Option<Box<Expression>>,
9360    #[serde(default)]
9361    pub key: Option<Box<Expression>>,
9362}
9363
9364/// TableSample - wraps an expression with a TABLESAMPLE clause
9365/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9367#[cfg_attr(feature = "bindings", derive(TS))]
9368pub struct TableSample {
9369    /// The expression being sampled (subquery, function, etc.)
9370    #[serde(default, skip_serializing_if = "Option::is_none")]
9371    pub this: Option<Box<Expression>>,
9372    /// The sample specification
9373    #[serde(default, skip_serializing_if = "Option::is_none")]
9374    pub sample: Option<Box<Sample>>,
9375    #[serde(default)]
9376    pub expressions: Vec<Expression>,
9377    #[serde(default)]
9378    pub method: Option<String>,
9379    #[serde(default)]
9380    pub bucket_numerator: Option<Box<Expression>>,
9381    #[serde(default)]
9382    pub bucket_denominator: Option<Box<Expression>>,
9383    #[serde(default)]
9384    pub bucket_field: Option<Box<Expression>>,
9385    #[serde(default)]
9386    pub percent: Option<Box<Expression>>,
9387    #[serde(default)]
9388    pub rows: Option<Box<Expression>>,
9389    #[serde(default)]
9390    pub size: Option<i64>,
9391    #[serde(default)]
9392    pub seed: Option<Box<Expression>>,
9393}
9394
9395/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9397#[cfg_attr(feature = "bindings", derive(TS))]
9398pub struct Tag {
9399    #[serde(default)]
9400    pub this: Option<Box<Expression>>,
9401    #[serde(default)]
9402    pub prefix: Option<Box<Expression>>,
9403    #[serde(default)]
9404    pub postfix: Option<Box<Expression>>,
9405}
9406
9407/// UnpivotColumns
9408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9409#[cfg_attr(feature = "bindings", derive(TS))]
9410pub struct UnpivotColumns {
9411    pub this: Box<Expression>,
9412    #[serde(default)]
9413    pub expressions: Vec<Expression>,
9414}
9415
9416/// SessionParameter
9417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9418#[cfg_attr(feature = "bindings", derive(TS))]
9419pub struct SessionParameter {
9420    pub this: Box<Expression>,
9421    #[serde(default)]
9422    pub kind: Option<String>,
9423}
9424
9425/// PseudoType
9426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9427#[cfg_attr(feature = "bindings", derive(TS))]
9428pub struct PseudoType {
9429    pub this: Box<Expression>,
9430}
9431
9432/// ObjectIdentifier
9433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9434#[cfg_attr(feature = "bindings", derive(TS))]
9435pub struct ObjectIdentifier {
9436    pub this: Box<Expression>,
9437}
9438
9439/// Transaction
9440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9441#[cfg_attr(feature = "bindings", derive(TS))]
9442pub struct Transaction {
9443    #[serde(default)]
9444    pub this: Option<Box<Expression>>,
9445    #[serde(default)]
9446    pub modes: Option<Box<Expression>>,
9447    #[serde(default)]
9448    pub mark: Option<Box<Expression>>,
9449}
9450
9451/// Commit
9452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9453#[cfg_attr(feature = "bindings", derive(TS))]
9454pub struct Commit {
9455    #[serde(default)]
9456    pub chain: Option<Box<Expression>>,
9457    #[serde(default)]
9458    pub this: Option<Box<Expression>>,
9459    #[serde(default)]
9460    pub durability: Option<Box<Expression>>,
9461}
9462
9463/// Rollback
9464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9465#[cfg_attr(feature = "bindings", derive(TS))]
9466pub struct Rollback {
9467    #[serde(default)]
9468    pub savepoint: Option<Box<Expression>>,
9469    #[serde(default)]
9470    pub this: Option<Box<Expression>>,
9471}
9472
9473/// AlterSession
9474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9475#[cfg_attr(feature = "bindings", derive(TS))]
9476pub struct AlterSession {
9477    #[serde(default)]
9478    pub expressions: Vec<Expression>,
9479    #[serde(default)]
9480    pub unset: Option<Box<Expression>>,
9481}
9482
9483/// Analyze
9484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9485#[cfg_attr(feature = "bindings", derive(TS))]
9486pub struct Analyze {
9487    #[serde(default)]
9488    pub kind: Option<String>,
9489    #[serde(default)]
9490    pub this: Option<Box<Expression>>,
9491    #[serde(default)]
9492    pub options: Vec<Expression>,
9493    #[serde(default)]
9494    pub mode: Option<Box<Expression>>,
9495    #[serde(default)]
9496    pub partition: Option<Box<Expression>>,
9497    #[serde(default)]
9498    pub expression: Option<Box<Expression>>,
9499    #[serde(default)]
9500    pub properties: Vec<Expression>,
9501    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9502    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9503    pub columns: Vec<String>,
9504}
9505
9506/// AnalyzeStatistics
9507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9508#[cfg_attr(feature = "bindings", derive(TS))]
9509pub struct AnalyzeStatistics {
9510    pub kind: String,
9511    #[serde(default)]
9512    pub option: Option<Box<Expression>>,
9513    #[serde(default)]
9514    pub this: Option<Box<Expression>>,
9515    #[serde(default)]
9516    pub expressions: Vec<Expression>,
9517}
9518
9519/// AnalyzeHistogram
9520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9521#[cfg_attr(feature = "bindings", derive(TS))]
9522pub struct AnalyzeHistogram {
9523    pub this: Box<Expression>,
9524    #[serde(default)]
9525    pub expressions: Vec<Expression>,
9526    #[serde(default)]
9527    pub expression: Option<Box<Expression>>,
9528    #[serde(default)]
9529    pub update_options: Option<Box<Expression>>,
9530}
9531
9532/// AnalyzeSample
9533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9534#[cfg_attr(feature = "bindings", derive(TS))]
9535pub struct AnalyzeSample {
9536    pub kind: String,
9537    #[serde(default)]
9538    pub sample: Option<Box<Expression>>,
9539}
9540
9541/// AnalyzeListChainedRows
9542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9543#[cfg_attr(feature = "bindings", derive(TS))]
9544pub struct AnalyzeListChainedRows {
9545    #[serde(default)]
9546    pub expression: Option<Box<Expression>>,
9547}
9548
9549/// AnalyzeDelete
9550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9551#[cfg_attr(feature = "bindings", derive(TS))]
9552pub struct AnalyzeDelete {
9553    #[serde(default)]
9554    pub kind: Option<String>,
9555}
9556
9557/// AnalyzeWith
9558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9559#[cfg_attr(feature = "bindings", derive(TS))]
9560pub struct AnalyzeWith {
9561    #[serde(default)]
9562    pub expressions: Vec<Expression>,
9563}
9564
9565/// AnalyzeValidate
9566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9567#[cfg_attr(feature = "bindings", derive(TS))]
9568pub struct AnalyzeValidate {
9569    pub kind: String,
9570    #[serde(default)]
9571    pub this: Option<Box<Expression>>,
9572    #[serde(default)]
9573    pub expression: Option<Box<Expression>>,
9574}
9575
9576/// AddPartition
9577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9578#[cfg_attr(feature = "bindings", derive(TS))]
9579pub struct AddPartition {
9580    pub this: Box<Expression>,
9581    #[serde(default)]
9582    pub exists: bool,
9583    #[serde(default)]
9584    pub location: Option<Box<Expression>>,
9585}
9586
9587/// AttachOption
9588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9589#[cfg_attr(feature = "bindings", derive(TS))]
9590pub struct AttachOption {
9591    pub this: Box<Expression>,
9592    #[serde(default)]
9593    pub expression: Option<Box<Expression>>,
9594}
9595
9596/// DropPartition
9597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9598#[cfg_attr(feature = "bindings", derive(TS))]
9599pub struct DropPartition {
9600    #[serde(default)]
9601    pub expressions: Vec<Expression>,
9602    #[serde(default)]
9603    pub exists: bool,
9604}
9605
9606/// ReplacePartition
9607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9608#[cfg_attr(feature = "bindings", derive(TS))]
9609pub struct ReplacePartition {
9610    pub expression: Box<Expression>,
9611    #[serde(default)]
9612    pub source: Option<Box<Expression>>,
9613}
9614
9615/// DPipe
9616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9617#[cfg_attr(feature = "bindings", derive(TS))]
9618pub struct DPipe {
9619    pub this: Box<Expression>,
9620    pub expression: Box<Expression>,
9621    #[serde(default)]
9622    pub safe: Option<Box<Expression>>,
9623}
9624
9625/// Operator
9626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9627#[cfg_attr(feature = "bindings", derive(TS))]
9628pub struct Operator {
9629    pub this: Box<Expression>,
9630    #[serde(default)]
9631    pub operator: Option<Box<Expression>>,
9632    pub expression: Box<Expression>,
9633}
9634
9635/// PivotAny
9636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9637#[cfg_attr(feature = "bindings", derive(TS))]
9638pub struct PivotAny {
9639    #[serde(default)]
9640    pub this: Option<Box<Expression>>,
9641}
9642
9643/// Aliases
9644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9645#[cfg_attr(feature = "bindings", derive(TS))]
9646pub struct Aliases {
9647    pub this: Box<Expression>,
9648    #[serde(default)]
9649    pub expressions: Vec<Expression>,
9650}
9651
9652/// AtIndex
9653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9654#[cfg_attr(feature = "bindings", derive(TS))]
9655pub struct AtIndex {
9656    pub this: Box<Expression>,
9657    pub expression: Box<Expression>,
9658}
9659
9660/// FromTimeZone
9661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9662#[cfg_attr(feature = "bindings", derive(TS))]
9663pub struct FromTimeZone {
9664    pub this: Box<Expression>,
9665    #[serde(default)]
9666    pub zone: Option<Box<Expression>>,
9667}
9668
9669/// Format override for a column in Teradata
9670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9671#[cfg_attr(feature = "bindings", derive(TS))]
9672pub struct FormatPhrase {
9673    pub this: Box<Expression>,
9674    pub format: String,
9675}
9676
9677/// ForIn
9678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9679#[cfg_attr(feature = "bindings", derive(TS))]
9680pub struct ForIn {
9681    pub this: Box<Expression>,
9682    pub expression: Box<Expression>,
9683}
9684
9685/// Automatically converts unit arg into a var.
9686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9687#[cfg_attr(feature = "bindings", derive(TS))]
9688pub struct TimeUnit {
9689    #[serde(default)]
9690    pub unit: Option<String>,
9691}
9692
9693/// IntervalOp
9694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9695#[cfg_attr(feature = "bindings", derive(TS))]
9696pub struct IntervalOp {
9697    #[serde(default)]
9698    pub unit: Option<String>,
9699    pub expression: Box<Expression>,
9700}
9701
9702/// HavingMax
9703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9704#[cfg_attr(feature = "bindings", derive(TS))]
9705pub struct HavingMax {
9706    pub this: Box<Expression>,
9707    pub expression: Box<Expression>,
9708    #[serde(default)]
9709    pub max: Option<Box<Expression>>,
9710}
9711
9712/// CosineDistance
9713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9714#[cfg_attr(feature = "bindings", derive(TS))]
9715pub struct CosineDistance {
9716    pub this: Box<Expression>,
9717    pub expression: Box<Expression>,
9718}
9719
9720/// DotProduct
9721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9722#[cfg_attr(feature = "bindings", derive(TS))]
9723pub struct DotProduct {
9724    pub this: Box<Expression>,
9725    pub expression: Box<Expression>,
9726}
9727
9728/// EuclideanDistance
9729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9730#[cfg_attr(feature = "bindings", derive(TS))]
9731pub struct EuclideanDistance {
9732    pub this: Box<Expression>,
9733    pub expression: Box<Expression>,
9734}
9735
9736/// ManhattanDistance
9737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9738#[cfg_attr(feature = "bindings", derive(TS))]
9739pub struct ManhattanDistance {
9740    pub this: Box<Expression>,
9741    pub expression: Box<Expression>,
9742}
9743
9744/// JarowinklerSimilarity
9745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9746#[cfg_attr(feature = "bindings", derive(TS))]
9747pub struct JarowinklerSimilarity {
9748    pub this: Box<Expression>,
9749    pub expression: Box<Expression>,
9750}
9751
9752/// Booland
9753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9754#[cfg_attr(feature = "bindings", derive(TS))]
9755pub struct Booland {
9756    pub this: Box<Expression>,
9757    pub expression: Box<Expression>,
9758}
9759
9760/// Boolor
9761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9762#[cfg_attr(feature = "bindings", derive(TS))]
9763pub struct Boolor {
9764    pub this: Box<Expression>,
9765    pub expression: Box<Expression>,
9766}
9767
9768/// ParameterizedAgg
9769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9770#[cfg_attr(feature = "bindings", derive(TS))]
9771pub struct ParameterizedAgg {
9772    pub this: Box<Expression>,
9773    #[serde(default)]
9774    pub expressions: Vec<Expression>,
9775    #[serde(default)]
9776    pub params: Vec<Expression>,
9777}
9778
9779/// ArgMax
9780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9781#[cfg_attr(feature = "bindings", derive(TS))]
9782pub struct ArgMax {
9783    pub this: Box<Expression>,
9784    pub expression: Box<Expression>,
9785    #[serde(default)]
9786    pub count: Option<Box<Expression>>,
9787}
9788
9789/// ArgMin
9790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9791#[cfg_attr(feature = "bindings", derive(TS))]
9792pub struct ArgMin {
9793    pub this: Box<Expression>,
9794    pub expression: Box<Expression>,
9795    #[serde(default)]
9796    pub count: Option<Box<Expression>>,
9797}
9798
9799/// ApproxTopK
9800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9801#[cfg_attr(feature = "bindings", derive(TS))]
9802pub struct ApproxTopK {
9803    pub this: Box<Expression>,
9804    #[serde(default)]
9805    pub expression: Option<Box<Expression>>,
9806    #[serde(default)]
9807    pub counters: Option<Box<Expression>>,
9808}
9809
9810/// ApproxTopKAccumulate
9811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9812#[cfg_attr(feature = "bindings", derive(TS))]
9813pub struct ApproxTopKAccumulate {
9814    pub this: Box<Expression>,
9815    #[serde(default)]
9816    pub expression: Option<Box<Expression>>,
9817}
9818
9819/// ApproxTopKCombine
9820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9821#[cfg_attr(feature = "bindings", derive(TS))]
9822pub struct ApproxTopKCombine {
9823    pub this: Box<Expression>,
9824    #[serde(default)]
9825    pub expression: Option<Box<Expression>>,
9826}
9827
9828/// ApproxTopKEstimate
9829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9830#[cfg_attr(feature = "bindings", derive(TS))]
9831pub struct ApproxTopKEstimate {
9832    pub this: Box<Expression>,
9833    #[serde(default)]
9834    pub expression: Option<Box<Expression>>,
9835}
9836
9837/// ApproxTopSum
9838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9839#[cfg_attr(feature = "bindings", derive(TS))]
9840pub struct ApproxTopSum {
9841    pub this: Box<Expression>,
9842    pub expression: Box<Expression>,
9843    #[serde(default)]
9844    pub count: Option<Box<Expression>>,
9845}
9846
9847/// ApproxQuantiles
9848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9849#[cfg_attr(feature = "bindings", derive(TS))]
9850pub struct ApproxQuantiles {
9851    pub this: Box<Expression>,
9852    #[serde(default)]
9853    pub expression: Option<Box<Expression>>,
9854}
9855
9856/// Minhash
9857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9858#[cfg_attr(feature = "bindings", derive(TS))]
9859pub struct Minhash {
9860    pub this: Box<Expression>,
9861    #[serde(default)]
9862    pub expressions: Vec<Expression>,
9863}
9864
9865/// FarmFingerprint
9866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9867#[cfg_attr(feature = "bindings", derive(TS))]
9868pub struct FarmFingerprint {
9869    #[serde(default)]
9870    pub expressions: Vec<Expression>,
9871}
9872
9873/// Float64
9874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9875#[cfg_attr(feature = "bindings", derive(TS))]
9876pub struct Float64 {
9877    pub this: Box<Expression>,
9878    #[serde(default)]
9879    pub expression: Option<Box<Expression>>,
9880}
9881
9882/// Transform
9883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9884#[cfg_attr(feature = "bindings", derive(TS))]
9885pub struct Transform {
9886    pub this: Box<Expression>,
9887    pub expression: Box<Expression>,
9888}
9889
9890/// Translate
9891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9892#[cfg_attr(feature = "bindings", derive(TS))]
9893pub struct Translate {
9894    pub this: Box<Expression>,
9895    #[serde(default)]
9896    pub from_: Option<Box<Expression>>,
9897    #[serde(default)]
9898    pub to: Option<Box<Expression>>,
9899}
9900
9901/// Grouping
9902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9903#[cfg_attr(feature = "bindings", derive(TS))]
9904pub struct Grouping {
9905    #[serde(default)]
9906    pub expressions: Vec<Expression>,
9907}
9908
9909/// GroupingId
9910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9911#[cfg_attr(feature = "bindings", derive(TS))]
9912pub struct GroupingId {
9913    #[serde(default)]
9914    pub expressions: Vec<Expression>,
9915}
9916
9917/// Anonymous
9918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9919#[cfg_attr(feature = "bindings", derive(TS))]
9920pub struct Anonymous {
9921    pub this: Box<Expression>,
9922    #[serde(default)]
9923    pub expressions: Vec<Expression>,
9924}
9925
9926/// AnonymousAggFunc
9927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9928#[cfg_attr(feature = "bindings", derive(TS))]
9929pub struct AnonymousAggFunc {
9930    pub this: Box<Expression>,
9931    #[serde(default)]
9932    pub expressions: Vec<Expression>,
9933}
9934
9935/// CombinedAggFunc
9936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9937#[cfg_attr(feature = "bindings", derive(TS))]
9938pub struct CombinedAggFunc {
9939    pub this: Box<Expression>,
9940    #[serde(default)]
9941    pub expressions: Vec<Expression>,
9942}
9943
9944/// CombinedParameterizedAgg
9945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9946#[cfg_attr(feature = "bindings", derive(TS))]
9947pub struct CombinedParameterizedAgg {
9948    pub this: Box<Expression>,
9949    #[serde(default)]
9950    pub expressions: Vec<Expression>,
9951    #[serde(default)]
9952    pub params: Vec<Expression>,
9953}
9954
9955/// HashAgg
9956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9957#[cfg_attr(feature = "bindings", derive(TS))]
9958pub struct HashAgg {
9959    pub this: Box<Expression>,
9960    #[serde(default)]
9961    pub expressions: Vec<Expression>,
9962}
9963
9964/// Hll
9965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9966#[cfg_attr(feature = "bindings", derive(TS))]
9967pub struct Hll {
9968    pub this: Box<Expression>,
9969    #[serde(default)]
9970    pub expressions: Vec<Expression>,
9971}
9972
9973/// Apply
9974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9975#[cfg_attr(feature = "bindings", derive(TS))]
9976pub struct Apply {
9977    pub this: Box<Expression>,
9978    pub expression: Box<Expression>,
9979}
9980
9981/// ToBoolean
9982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9983#[cfg_attr(feature = "bindings", derive(TS))]
9984pub struct ToBoolean {
9985    pub this: Box<Expression>,
9986    #[serde(default)]
9987    pub safe: Option<Box<Expression>>,
9988}
9989
9990/// List
9991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9992#[cfg_attr(feature = "bindings", derive(TS))]
9993pub struct List {
9994    #[serde(default)]
9995    pub expressions: Vec<Expression>,
9996}
9997
9998/// ToMap - Materialize-style map constructor
9999/// Can hold either:
10000/// - A SELECT subquery (MAP(SELECT 'a', 1))
10001/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10003#[cfg_attr(feature = "bindings", derive(TS))]
10004pub struct ToMap {
10005    /// Either a Select subquery or a Struct containing PropertyEQ entries
10006    pub this: Box<Expression>,
10007}
10008
10009/// Pad
10010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10011#[cfg_attr(feature = "bindings", derive(TS))]
10012pub struct Pad {
10013    pub this: Box<Expression>,
10014    pub expression: Box<Expression>,
10015    #[serde(default)]
10016    pub fill_pattern: Option<Box<Expression>>,
10017    #[serde(default)]
10018    pub is_left: Option<Box<Expression>>,
10019}
10020
10021/// ToChar
10022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10023#[cfg_attr(feature = "bindings", derive(TS))]
10024pub struct ToChar {
10025    pub this: Box<Expression>,
10026    #[serde(default)]
10027    pub format: Option<String>,
10028    #[serde(default)]
10029    pub nlsparam: Option<Box<Expression>>,
10030    #[serde(default)]
10031    pub is_numeric: Option<Box<Expression>>,
10032}
10033
10034/// StringFunc - String type conversion function (BigQuery STRING)
10035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10036#[cfg_attr(feature = "bindings", derive(TS))]
10037pub struct StringFunc {
10038    pub this: Box<Expression>,
10039    #[serde(default)]
10040    pub zone: Option<Box<Expression>>,
10041}
10042
10043/// ToNumber
10044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10045#[cfg_attr(feature = "bindings", derive(TS))]
10046pub struct ToNumber {
10047    pub this: Box<Expression>,
10048    #[serde(default)]
10049    pub format: Option<Box<Expression>>,
10050    #[serde(default)]
10051    pub nlsparam: Option<Box<Expression>>,
10052    #[serde(default)]
10053    pub precision: Option<Box<Expression>>,
10054    #[serde(default)]
10055    pub scale: Option<Box<Expression>>,
10056    #[serde(default)]
10057    pub safe: Option<Box<Expression>>,
10058    #[serde(default)]
10059    pub safe_name: Option<Box<Expression>>,
10060}
10061
10062/// ToDouble
10063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10064#[cfg_attr(feature = "bindings", derive(TS))]
10065pub struct ToDouble {
10066    pub this: Box<Expression>,
10067    #[serde(default)]
10068    pub format: Option<String>,
10069    #[serde(default)]
10070    pub safe: Option<Box<Expression>>,
10071}
10072
10073/// ToDecfloat
10074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10075#[cfg_attr(feature = "bindings", derive(TS))]
10076pub struct ToDecfloat {
10077    pub this: Box<Expression>,
10078    #[serde(default)]
10079    pub format: Option<String>,
10080}
10081
10082/// TryToDecfloat
10083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10084#[cfg_attr(feature = "bindings", derive(TS))]
10085pub struct TryToDecfloat {
10086    pub this: Box<Expression>,
10087    #[serde(default)]
10088    pub format: Option<String>,
10089}
10090
10091/// ToFile
10092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10093#[cfg_attr(feature = "bindings", derive(TS))]
10094pub struct ToFile {
10095    pub this: Box<Expression>,
10096    #[serde(default)]
10097    pub path: Option<Box<Expression>>,
10098    #[serde(default)]
10099    pub safe: Option<Box<Expression>>,
10100}
10101
10102/// Columns
10103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10104#[cfg_attr(feature = "bindings", derive(TS))]
10105pub struct Columns {
10106    pub this: Box<Expression>,
10107    #[serde(default)]
10108    pub unpack: Option<Box<Expression>>,
10109}
10110
10111/// ConvertToCharset
10112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10113#[cfg_attr(feature = "bindings", derive(TS))]
10114pub struct ConvertToCharset {
10115    pub this: Box<Expression>,
10116    #[serde(default)]
10117    pub dest: Option<Box<Expression>>,
10118    #[serde(default)]
10119    pub source: Option<Box<Expression>>,
10120}
10121
10122/// ConvertTimezone
10123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10124#[cfg_attr(feature = "bindings", derive(TS))]
10125pub struct ConvertTimezone {
10126    #[serde(default)]
10127    pub source_tz: Option<Box<Expression>>,
10128    #[serde(default)]
10129    pub target_tz: Option<Box<Expression>>,
10130    #[serde(default)]
10131    pub timestamp: Option<Box<Expression>>,
10132    #[serde(default)]
10133    pub options: Vec<Expression>,
10134}
10135
10136/// GenerateSeries
10137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10138#[cfg_attr(feature = "bindings", derive(TS))]
10139pub struct GenerateSeries {
10140    #[serde(default)]
10141    pub start: Option<Box<Expression>>,
10142    #[serde(default)]
10143    pub end: Option<Box<Expression>>,
10144    #[serde(default)]
10145    pub step: Option<Box<Expression>>,
10146    #[serde(default)]
10147    pub is_end_exclusive: Option<Box<Expression>>,
10148}
10149
10150/// AIAgg
10151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10152#[cfg_attr(feature = "bindings", derive(TS))]
10153pub struct AIAgg {
10154    pub this: Box<Expression>,
10155    pub expression: Box<Expression>,
10156}
10157
10158/// AIClassify
10159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10160#[cfg_attr(feature = "bindings", derive(TS))]
10161pub struct AIClassify {
10162    pub this: Box<Expression>,
10163    #[serde(default)]
10164    pub categories: Option<Box<Expression>>,
10165    #[serde(default)]
10166    pub config: Option<Box<Expression>>,
10167}
10168
10169/// ArrayAll
10170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10171#[cfg_attr(feature = "bindings", derive(TS))]
10172pub struct ArrayAll {
10173    pub this: Box<Expression>,
10174    pub expression: Box<Expression>,
10175}
10176
10177/// ArrayAny
10178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10179#[cfg_attr(feature = "bindings", derive(TS))]
10180pub struct ArrayAny {
10181    pub this: Box<Expression>,
10182    pub expression: Box<Expression>,
10183}
10184
10185/// ArrayConstructCompact
10186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10187#[cfg_attr(feature = "bindings", derive(TS))]
10188pub struct ArrayConstructCompact {
10189    #[serde(default)]
10190    pub expressions: Vec<Expression>,
10191}
10192
10193/// StPoint
10194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10195#[cfg_attr(feature = "bindings", derive(TS))]
10196pub struct StPoint {
10197    pub this: Box<Expression>,
10198    pub expression: Box<Expression>,
10199    #[serde(default)]
10200    pub null: Option<Box<Expression>>,
10201}
10202
10203/// StDistance
10204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10205#[cfg_attr(feature = "bindings", derive(TS))]
10206pub struct StDistance {
10207    pub this: Box<Expression>,
10208    pub expression: Box<Expression>,
10209    #[serde(default)]
10210    pub use_spheroid: Option<Box<Expression>>,
10211}
10212
10213/// StringToArray
10214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10215#[cfg_attr(feature = "bindings", derive(TS))]
10216pub struct StringToArray {
10217    pub this: Box<Expression>,
10218    #[serde(default)]
10219    pub expression: Option<Box<Expression>>,
10220    #[serde(default)]
10221    pub null: Option<Box<Expression>>,
10222}
10223
10224/// ArraySum
10225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10226#[cfg_attr(feature = "bindings", derive(TS))]
10227pub struct ArraySum {
10228    pub this: Box<Expression>,
10229    #[serde(default)]
10230    pub expression: Option<Box<Expression>>,
10231}
10232
10233/// ObjectAgg
10234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10235#[cfg_attr(feature = "bindings", derive(TS))]
10236pub struct ObjectAgg {
10237    pub this: Box<Expression>,
10238    pub expression: Box<Expression>,
10239}
10240
10241/// CastToStrType
10242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10243#[cfg_attr(feature = "bindings", derive(TS))]
10244pub struct CastToStrType {
10245    pub this: Box<Expression>,
10246    #[serde(default)]
10247    pub to: Option<Box<Expression>>,
10248}
10249
10250/// CheckJson
10251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10252#[cfg_attr(feature = "bindings", derive(TS))]
10253pub struct CheckJson {
10254    pub this: Box<Expression>,
10255}
10256
10257/// CheckXml
10258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10259#[cfg_attr(feature = "bindings", derive(TS))]
10260pub struct CheckXml {
10261    pub this: Box<Expression>,
10262    #[serde(default)]
10263    pub disable_auto_convert: Option<Box<Expression>>,
10264}
10265
10266/// TranslateCharacters
10267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10268#[cfg_attr(feature = "bindings", derive(TS))]
10269pub struct TranslateCharacters {
10270    pub this: Box<Expression>,
10271    pub expression: Box<Expression>,
10272    #[serde(default)]
10273    pub with_error: Option<Box<Expression>>,
10274}
10275
10276/// CurrentSchemas
10277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10278#[cfg_attr(feature = "bindings", derive(TS))]
10279pub struct CurrentSchemas {
10280    #[serde(default)]
10281    pub this: Option<Box<Expression>>,
10282}
10283
10284/// CurrentDatetime
10285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10286#[cfg_attr(feature = "bindings", derive(TS))]
10287pub struct CurrentDatetime {
10288    #[serde(default)]
10289    pub this: Option<Box<Expression>>,
10290}
10291
10292/// Localtime
10293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10294#[cfg_attr(feature = "bindings", derive(TS))]
10295pub struct Localtime {
10296    #[serde(default)]
10297    pub this: Option<Box<Expression>>,
10298}
10299
10300/// Localtimestamp
10301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10302#[cfg_attr(feature = "bindings", derive(TS))]
10303pub struct Localtimestamp {
10304    #[serde(default)]
10305    pub this: Option<Box<Expression>>,
10306}
10307
10308/// Systimestamp
10309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10310#[cfg_attr(feature = "bindings", derive(TS))]
10311pub struct Systimestamp {
10312    #[serde(default)]
10313    pub this: Option<Box<Expression>>,
10314}
10315
10316/// CurrentSchema
10317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10318#[cfg_attr(feature = "bindings", derive(TS))]
10319pub struct CurrentSchema {
10320    #[serde(default)]
10321    pub this: Option<Box<Expression>>,
10322}
10323
10324/// CurrentUser
10325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10326#[cfg_attr(feature = "bindings", derive(TS))]
10327pub struct CurrentUser {
10328    #[serde(default)]
10329    pub this: Option<Box<Expression>>,
10330}
10331
10332/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10334#[cfg_attr(feature = "bindings", derive(TS))]
10335pub struct SessionUser;
10336
10337/// JSONPathRoot - Represents $ in JSON path expressions
10338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10339#[cfg_attr(feature = "bindings", derive(TS))]
10340pub struct JSONPathRoot;
10341
10342/// UtcTime
10343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10344#[cfg_attr(feature = "bindings", derive(TS))]
10345pub struct UtcTime {
10346    #[serde(default)]
10347    pub this: Option<Box<Expression>>,
10348}
10349
10350/// UtcTimestamp
10351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10352#[cfg_attr(feature = "bindings", derive(TS))]
10353pub struct UtcTimestamp {
10354    #[serde(default)]
10355    pub this: Option<Box<Expression>>,
10356}
10357
10358/// TimestampFunc - TIMESTAMP constructor function
10359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10360#[cfg_attr(feature = "bindings", derive(TS))]
10361pub struct TimestampFunc {
10362    #[serde(default)]
10363    pub this: Option<Box<Expression>>,
10364    #[serde(default)]
10365    pub zone: Option<Box<Expression>>,
10366    #[serde(default)]
10367    pub with_tz: Option<bool>,
10368    #[serde(default)]
10369    pub safe: Option<bool>,
10370}
10371
10372/// DateBin
10373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10374#[cfg_attr(feature = "bindings", derive(TS))]
10375pub struct DateBin {
10376    pub this: Box<Expression>,
10377    pub expression: Box<Expression>,
10378    #[serde(default)]
10379    pub unit: Option<String>,
10380    #[serde(default)]
10381    pub zone: Option<Box<Expression>>,
10382    #[serde(default)]
10383    pub origin: Option<Box<Expression>>,
10384}
10385
10386/// Datetime
10387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10388#[cfg_attr(feature = "bindings", derive(TS))]
10389pub struct Datetime {
10390    pub this: Box<Expression>,
10391    #[serde(default)]
10392    pub expression: Option<Box<Expression>>,
10393}
10394
10395/// DatetimeAdd
10396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10397#[cfg_attr(feature = "bindings", derive(TS))]
10398pub struct DatetimeAdd {
10399    pub this: Box<Expression>,
10400    pub expression: Box<Expression>,
10401    #[serde(default)]
10402    pub unit: Option<String>,
10403}
10404
10405/// DatetimeSub
10406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10407#[cfg_attr(feature = "bindings", derive(TS))]
10408pub struct DatetimeSub {
10409    pub this: Box<Expression>,
10410    pub expression: Box<Expression>,
10411    #[serde(default)]
10412    pub unit: Option<String>,
10413}
10414
10415/// DatetimeDiff
10416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10417#[cfg_attr(feature = "bindings", derive(TS))]
10418pub struct DatetimeDiff {
10419    pub this: Box<Expression>,
10420    pub expression: Box<Expression>,
10421    #[serde(default)]
10422    pub unit: Option<String>,
10423}
10424
10425/// DatetimeTrunc
10426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10427#[cfg_attr(feature = "bindings", derive(TS))]
10428pub struct DatetimeTrunc {
10429    pub this: Box<Expression>,
10430    pub unit: String,
10431    #[serde(default)]
10432    pub zone: Option<Box<Expression>>,
10433}
10434
10435/// Dayname
10436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10437#[cfg_attr(feature = "bindings", derive(TS))]
10438pub struct Dayname {
10439    pub this: Box<Expression>,
10440    #[serde(default)]
10441    pub abbreviated: Option<Box<Expression>>,
10442}
10443
10444/// MakeInterval
10445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10446#[cfg_attr(feature = "bindings", derive(TS))]
10447pub struct MakeInterval {
10448    #[serde(default)]
10449    pub year: Option<Box<Expression>>,
10450    #[serde(default)]
10451    pub month: Option<Box<Expression>>,
10452    #[serde(default)]
10453    pub week: Option<Box<Expression>>,
10454    #[serde(default)]
10455    pub day: Option<Box<Expression>>,
10456    #[serde(default)]
10457    pub hour: Option<Box<Expression>>,
10458    #[serde(default)]
10459    pub minute: Option<Box<Expression>>,
10460    #[serde(default)]
10461    pub second: Option<Box<Expression>>,
10462}
10463
10464/// PreviousDay
10465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10466#[cfg_attr(feature = "bindings", derive(TS))]
10467pub struct PreviousDay {
10468    pub this: Box<Expression>,
10469    pub expression: Box<Expression>,
10470}
10471
10472/// Elt
10473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10474#[cfg_attr(feature = "bindings", derive(TS))]
10475pub struct Elt {
10476    pub this: Box<Expression>,
10477    #[serde(default)]
10478    pub expressions: Vec<Expression>,
10479}
10480
10481/// TimestampAdd
10482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10483#[cfg_attr(feature = "bindings", derive(TS))]
10484pub struct TimestampAdd {
10485    pub this: Box<Expression>,
10486    pub expression: Box<Expression>,
10487    #[serde(default)]
10488    pub unit: Option<String>,
10489}
10490
10491/// TimestampSub
10492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10493#[cfg_attr(feature = "bindings", derive(TS))]
10494pub struct TimestampSub {
10495    pub this: Box<Expression>,
10496    pub expression: Box<Expression>,
10497    #[serde(default)]
10498    pub unit: Option<String>,
10499}
10500
10501/// TimestampDiff
10502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10503#[cfg_attr(feature = "bindings", derive(TS))]
10504pub struct TimestampDiff {
10505    pub this: Box<Expression>,
10506    pub expression: Box<Expression>,
10507    #[serde(default)]
10508    pub unit: Option<String>,
10509}
10510
10511/// TimeSlice
10512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10513#[cfg_attr(feature = "bindings", derive(TS))]
10514pub struct TimeSlice {
10515    pub this: Box<Expression>,
10516    pub expression: Box<Expression>,
10517    pub unit: String,
10518    #[serde(default)]
10519    pub kind: Option<String>,
10520}
10521
10522/// TimeAdd
10523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10524#[cfg_attr(feature = "bindings", derive(TS))]
10525pub struct TimeAdd {
10526    pub this: Box<Expression>,
10527    pub expression: Box<Expression>,
10528    #[serde(default)]
10529    pub unit: Option<String>,
10530}
10531
10532/// TimeSub
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct TimeSub {
10536    pub this: Box<Expression>,
10537    pub expression: Box<Expression>,
10538    #[serde(default)]
10539    pub unit: Option<String>,
10540}
10541
10542/// TimeDiff
10543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10544#[cfg_attr(feature = "bindings", derive(TS))]
10545pub struct TimeDiff {
10546    pub this: Box<Expression>,
10547    pub expression: Box<Expression>,
10548    #[serde(default)]
10549    pub unit: Option<String>,
10550}
10551
10552/// TimeTrunc
10553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10554#[cfg_attr(feature = "bindings", derive(TS))]
10555pub struct TimeTrunc {
10556    pub this: Box<Expression>,
10557    pub unit: String,
10558    #[serde(default)]
10559    pub zone: Option<Box<Expression>>,
10560}
10561
10562/// DateFromParts
10563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10564#[cfg_attr(feature = "bindings", derive(TS))]
10565pub struct DateFromParts {
10566    #[serde(default)]
10567    pub year: Option<Box<Expression>>,
10568    #[serde(default)]
10569    pub month: Option<Box<Expression>>,
10570    #[serde(default)]
10571    pub day: Option<Box<Expression>>,
10572    #[serde(default)]
10573    pub allow_overflow: Option<Box<Expression>>,
10574}
10575
10576/// TimeFromParts
10577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10578#[cfg_attr(feature = "bindings", derive(TS))]
10579pub struct TimeFromParts {
10580    #[serde(default)]
10581    pub hour: Option<Box<Expression>>,
10582    #[serde(default)]
10583    pub min: Option<Box<Expression>>,
10584    #[serde(default)]
10585    pub sec: Option<Box<Expression>>,
10586    #[serde(default)]
10587    pub nano: Option<Box<Expression>>,
10588    #[serde(default)]
10589    pub fractions: Option<Box<Expression>>,
10590    #[serde(default)]
10591    pub precision: Option<i64>,
10592}
10593
10594/// DecodeCase
10595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10596#[cfg_attr(feature = "bindings", derive(TS))]
10597pub struct DecodeCase {
10598    #[serde(default)]
10599    pub expressions: Vec<Expression>,
10600}
10601
10602/// Decrypt
10603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10604#[cfg_attr(feature = "bindings", derive(TS))]
10605pub struct Decrypt {
10606    pub this: Box<Expression>,
10607    #[serde(default)]
10608    pub passphrase: Option<Box<Expression>>,
10609    #[serde(default)]
10610    pub aad: Option<Box<Expression>>,
10611    #[serde(default)]
10612    pub encryption_method: Option<Box<Expression>>,
10613    #[serde(default)]
10614    pub safe: Option<Box<Expression>>,
10615}
10616
10617/// DecryptRaw
10618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10619#[cfg_attr(feature = "bindings", derive(TS))]
10620pub struct DecryptRaw {
10621    pub this: Box<Expression>,
10622    #[serde(default)]
10623    pub key: Option<Box<Expression>>,
10624    #[serde(default)]
10625    pub iv: Option<Box<Expression>>,
10626    #[serde(default)]
10627    pub aad: Option<Box<Expression>>,
10628    #[serde(default)]
10629    pub encryption_method: Option<Box<Expression>>,
10630    #[serde(default)]
10631    pub aead: Option<Box<Expression>>,
10632    #[serde(default)]
10633    pub safe: Option<Box<Expression>>,
10634}
10635
10636/// Encode
10637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10638#[cfg_attr(feature = "bindings", derive(TS))]
10639pub struct Encode {
10640    pub this: Box<Expression>,
10641    #[serde(default)]
10642    pub charset: Option<Box<Expression>>,
10643}
10644
10645/// Encrypt
10646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10647#[cfg_attr(feature = "bindings", derive(TS))]
10648pub struct Encrypt {
10649    pub this: Box<Expression>,
10650    #[serde(default)]
10651    pub passphrase: Option<Box<Expression>>,
10652    #[serde(default)]
10653    pub aad: Option<Box<Expression>>,
10654    #[serde(default)]
10655    pub encryption_method: Option<Box<Expression>>,
10656}
10657
10658/// EncryptRaw
10659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10660#[cfg_attr(feature = "bindings", derive(TS))]
10661pub struct EncryptRaw {
10662    pub this: Box<Expression>,
10663    #[serde(default)]
10664    pub key: Option<Box<Expression>>,
10665    #[serde(default)]
10666    pub iv: Option<Box<Expression>>,
10667    #[serde(default)]
10668    pub aad: Option<Box<Expression>>,
10669    #[serde(default)]
10670    pub encryption_method: Option<Box<Expression>>,
10671}
10672
10673/// EqualNull
10674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10675#[cfg_attr(feature = "bindings", derive(TS))]
10676pub struct EqualNull {
10677    pub this: Box<Expression>,
10678    pub expression: Box<Expression>,
10679}
10680
10681/// ToBinary
10682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10683#[cfg_attr(feature = "bindings", derive(TS))]
10684pub struct ToBinary {
10685    pub this: Box<Expression>,
10686    #[serde(default)]
10687    pub format: Option<String>,
10688    #[serde(default)]
10689    pub safe: Option<Box<Expression>>,
10690}
10691
10692/// Base64DecodeBinary
10693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10694#[cfg_attr(feature = "bindings", derive(TS))]
10695pub struct Base64DecodeBinary {
10696    pub this: Box<Expression>,
10697    #[serde(default)]
10698    pub alphabet: Option<Box<Expression>>,
10699}
10700
10701/// Base64DecodeString
10702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10703#[cfg_attr(feature = "bindings", derive(TS))]
10704pub struct Base64DecodeString {
10705    pub this: Box<Expression>,
10706    #[serde(default)]
10707    pub alphabet: Option<Box<Expression>>,
10708}
10709
10710/// Base64Encode
10711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10712#[cfg_attr(feature = "bindings", derive(TS))]
10713pub struct Base64Encode {
10714    pub this: Box<Expression>,
10715    #[serde(default)]
10716    pub max_line_length: Option<Box<Expression>>,
10717    #[serde(default)]
10718    pub alphabet: Option<Box<Expression>>,
10719}
10720
10721/// TryBase64DecodeBinary
10722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10723#[cfg_attr(feature = "bindings", derive(TS))]
10724pub struct TryBase64DecodeBinary {
10725    pub this: Box<Expression>,
10726    #[serde(default)]
10727    pub alphabet: Option<Box<Expression>>,
10728}
10729
10730/// TryBase64DecodeString
10731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10732#[cfg_attr(feature = "bindings", derive(TS))]
10733pub struct TryBase64DecodeString {
10734    pub this: Box<Expression>,
10735    #[serde(default)]
10736    pub alphabet: Option<Box<Expression>>,
10737}
10738
10739/// GapFill
10740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10741#[cfg_attr(feature = "bindings", derive(TS))]
10742pub struct GapFill {
10743    pub this: Box<Expression>,
10744    #[serde(default)]
10745    pub ts_column: Option<Box<Expression>>,
10746    #[serde(default)]
10747    pub bucket_width: Option<Box<Expression>>,
10748    #[serde(default)]
10749    pub partitioning_columns: Option<Box<Expression>>,
10750    #[serde(default)]
10751    pub value_columns: Option<Box<Expression>>,
10752    #[serde(default)]
10753    pub origin: Option<Box<Expression>>,
10754    #[serde(default)]
10755    pub ignore_nulls: Option<Box<Expression>>,
10756}
10757
10758/// GenerateDateArray
10759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10760#[cfg_attr(feature = "bindings", derive(TS))]
10761pub struct GenerateDateArray {
10762    #[serde(default)]
10763    pub start: Option<Box<Expression>>,
10764    #[serde(default)]
10765    pub end: Option<Box<Expression>>,
10766    #[serde(default)]
10767    pub step: Option<Box<Expression>>,
10768}
10769
10770/// GenerateTimestampArray
10771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10772#[cfg_attr(feature = "bindings", derive(TS))]
10773pub struct GenerateTimestampArray {
10774    #[serde(default)]
10775    pub start: Option<Box<Expression>>,
10776    #[serde(default)]
10777    pub end: Option<Box<Expression>>,
10778    #[serde(default)]
10779    pub step: Option<Box<Expression>>,
10780}
10781
10782/// GetExtract
10783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10784#[cfg_attr(feature = "bindings", derive(TS))]
10785pub struct GetExtract {
10786    pub this: Box<Expression>,
10787    pub expression: Box<Expression>,
10788}
10789
10790/// Getbit
10791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10792#[cfg_attr(feature = "bindings", derive(TS))]
10793pub struct Getbit {
10794    pub this: Box<Expression>,
10795    pub expression: Box<Expression>,
10796    #[serde(default)]
10797    pub zero_is_msb: Option<Box<Expression>>,
10798}
10799
10800/// OverflowTruncateBehavior
10801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10802#[cfg_attr(feature = "bindings", derive(TS))]
10803pub struct OverflowTruncateBehavior {
10804    #[serde(default)]
10805    pub this: Option<Box<Expression>>,
10806    #[serde(default)]
10807    pub with_count: Option<Box<Expression>>,
10808}
10809
10810/// HexEncode
10811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10812#[cfg_attr(feature = "bindings", derive(TS))]
10813pub struct HexEncode {
10814    pub this: Box<Expression>,
10815    #[serde(default)]
10816    pub case: Option<Box<Expression>>,
10817}
10818
10819/// Compress
10820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10821#[cfg_attr(feature = "bindings", derive(TS))]
10822pub struct Compress {
10823    pub this: Box<Expression>,
10824    #[serde(default)]
10825    pub method: Option<String>,
10826}
10827
10828/// DecompressBinary
10829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10830#[cfg_attr(feature = "bindings", derive(TS))]
10831pub struct DecompressBinary {
10832    pub this: Box<Expression>,
10833    pub method: String,
10834}
10835
10836/// DecompressString
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct DecompressString {
10840    pub this: Box<Expression>,
10841    pub method: String,
10842}
10843
10844/// Xor
10845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10846#[cfg_attr(feature = "bindings", derive(TS))]
10847pub struct Xor {
10848    #[serde(default)]
10849    pub this: Option<Box<Expression>>,
10850    #[serde(default)]
10851    pub expression: Option<Box<Expression>>,
10852    #[serde(default)]
10853    pub expressions: Vec<Expression>,
10854}
10855
10856/// Nullif
10857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10858#[cfg_attr(feature = "bindings", derive(TS))]
10859pub struct Nullif {
10860    pub this: Box<Expression>,
10861    pub expression: Box<Expression>,
10862}
10863
10864/// JSON
10865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10866#[cfg_attr(feature = "bindings", derive(TS))]
10867pub struct JSON {
10868    #[serde(default)]
10869    pub this: Option<Box<Expression>>,
10870    #[serde(default)]
10871    pub with_: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub unique: bool,
10874}
10875
10876/// JSONPath
10877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10878#[cfg_attr(feature = "bindings", derive(TS))]
10879pub struct JSONPath {
10880    #[serde(default)]
10881    pub expressions: Vec<Expression>,
10882    #[serde(default)]
10883    pub escape: Option<Box<Expression>>,
10884}
10885
10886/// JSONPathFilter
10887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10888#[cfg_attr(feature = "bindings", derive(TS))]
10889pub struct JSONPathFilter {
10890    pub this: Box<Expression>,
10891}
10892
10893/// JSONPathKey
10894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10895#[cfg_attr(feature = "bindings", derive(TS))]
10896pub struct JSONPathKey {
10897    pub this: Box<Expression>,
10898}
10899
10900/// JSONPathRecursive
10901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10902#[cfg_attr(feature = "bindings", derive(TS))]
10903pub struct JSONPathRecursive {
10904    #[serde(default)]
10905    pub this: Option<Box<Expression>>,
10906}
10907
10908/// JSONPathScript
10909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10910#[cfg_attr(feature = "bindings", derive(TS))]
10911pub struct JSONPathScript {
10912    pub this: Box<Expression>,
10913}
10914
10915/// JSONPathSlice
10916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10917#[cfg_attr(feature = "bindings", derive(TS))]
10918pub struct JSONPathSlice {
10919    #[serde(default)]
10920    pub start: Option<Box<Expression>>,
10921    #[serde(default)]
10922    pub end: Option<Box<Expression>>,
10923    #[serde(default)]
10924    pub step: Option<Box<Expression>>,
10925}
10926
10927/// JSONPathSelector
10928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10929#[cfg_attr(feature = "bindings", derive(TS))]
10930pub struct JSONPathSelector {
10931    pub this: Box<Expression>,
10932}
10933
10934/// JSONPathSubscript
10935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10936#[cfg_attr(feature = "bindings", derive(TS))]
10937pub struct JSONPathSubscript {
10938    pub this: Box<Expression>,
10939}
10940
10941/// JSONPathUnion
10942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10943#[cfg_attr(feature = "bindings", derive(TS))]
10944pub struct JSONPathUnion {
10945    #[serde(default)]
10946    pub expressions: Vec<Expression>,
10947}
10948
10949/// Format
10950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10951#[cfg_attr(feature = "bindings", derive(TS))]
10952pub struct Format {
10953    pub this: Box<Expression>,
10954    #[serde(default)]
10955    pub expressions: Vec<Expression>,
10956}
10957
10958/// JSONKeys
10959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10960#[cfg_attr(feature = "bindings", derive(TS))]
10961pub struct JSONKeys {
10962    pub this: Box<Expression>,
10963    #[serde(default)]
10964    pub expression: Option<Box<Expression>>,
10965    #[serde(default)]
10966    pub expressions: Vec<Expression>,
10967}
10968
10969/// JSONKeyValue
10970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10971#[cfg_attr(feature = "bindings", derive(TS))]
10972pub struct JSONKeyValue {
10973    pub this: Box<Expression>,
10974    pub expression: Box<Expression>,
10975}
10976
10977/// JSONKeysAtDepth
10978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10979#[cfg_attr(feature = "bindings", derive(TS))]
10980pub struct JSONKeysAtDepth {
10981    pub this: Box<Expression>,
10982    #[serde(default)]
10983    pub expression: Option<Box<Expression>>,
10984    #[serde(default)]
10985    pub mode: Option<Box<Expression>>,
10986}
10987
10988/// JSONObject
10989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10990#[cfg_attr(feature = "bindings", derive(TS))]
10991pub struct JSONObject {
10992    #[serde(default)]
10993    pub expressions: Vec<Expression>,
10994    #[serde(default)]
10995    pub null_handling: Option<Box<Expression>>,
10996    #[serde(default)]
10997    pub unique_keys: Option<Box<Expression>>,
10998    #[serde(default)]
10999    pub return_type: Option<Box<Expression>>,
11000    #[serde(default)]
11001    pub encoding: Option<Box<Expression>>,
11002}
11003
11004/// JSONObjectAgg
11005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11006#[cfg_attr(feature = "bindings", derive(TS))]
11007pub struct JSONObjectAgg {
11008    #[serde(default)]
11009    pub expressions: Vec<Expression>,
11010    #[serde(default)]
11011    pub null_handling: Option<Box<Expression>>,
11012    #[serde(default)]
11013    pub unique_keys: Option<Box<Expression>>,
11014    #[serde(default)]
11015    pub return_type: Option<Box<Expression>>,
11016    #[serde(default)]
11017    pub encoding: Option<Box<Expression>>,
11018}
11019
11020/// JSONBObjectAgg
11021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11022#[cfg_attr(feature = "bindings", derive(TS))]
11023pub struct JSONBObjectAgg {
11024    pub this: Box<Expression>,
11025    pub expression: Box<Expression>,
11026}
11027
11028/// JSONArray
11029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11030#[cfg_attr(feature = "bindings", derive(TS))]
11031pub struct JSONArray {
11032    #[serde(default)]
11033    pub expressions: Vec<Expression>,
11034    #[serde(default)]
11035    pub null_handling: Option<Box<Expression>>,
11036    #[serde(default)]
11037    pub return_type: Option<Box<Expression>>,
11038    #[serde(default)]
11039    pub strict: Option<Box<Expression>>,
11040}
11041
11042/// JSONArrayAgg
11043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11044#[cfg_attr(feature = "bindings", derive(TS))]
11045pub struct JSONArrayAgg {
11046    pub this: Box<Expression>,
11047    #[serde(default)]
11048    pub order: Option<Box<Expression>>,
11049    #[serde(default)]
11050    pub null_handling: Option<Box<Expression>>,
11051    #[serde(default)]
11052    pub return_type: Option<Box<Expression>>,
11053    #[serde(default)]
11054    pub strict: Option<Box<Expression>>,
11055}
11056
11057/// JSONExists
11058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11059#[cfg_attr(feature = "bindings", derive(TS))]
11060pub struct JSONExists {
11061    pub this: Box<Expression>,
11062    #[serde(default)]
11063    pub path: Option<Box<Expression>>,
11064    #[serde(default)]
11065    pub passing: Option<Box<Expression>>,
11066    #[serde(default)]
11067    pub on_condition: Option<Box<Expression>>,
11068    #[serde(default)]
11069    pub from_dcolonqmark: Option<Box<Expression>>,
11070}
11071
11072/// JSONColumnDef
11073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11074#[cfg_attr(feature = "bindings", derive(TS))]
11075pub struct JSONColumnDef {
11076    #[serde(default)]
11077    pub this: Option<Box<Expression>>,
11078    #[serde(default)]
11079    pub kind: Option<String>,
11080    #[serde(default)]
11081    pub path: Option<Box<Expression>>,
11082    #[serde(default)]
11083    pub nested_schema: Option<Box<Expression>>,
11084    #[serde(default)]
11085    pub ordinality: Option<Box<Expression>>,
11086}
11087
11088/// JSONSchema
11089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11090#[cfg_attr(feature = "bindings", derive(TS))]
11091pub struct JSONSchema {
11092    #[serde(default)]
11093    pub expressions: Vec<Expression>,
11094}
11095
11096/// JSONSet
11097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11098#[cfg_attr(feature = "bindings", derive(TS))]
11099pub struct JSONSet {
11100    pub this: Box<Expression>,
11101    #[serde(default)]
11102    pub expressions: Vec<Expression>,
11103}
11104
11105/// JSONStripNulls
11106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11107#[cfg_attr(feature = "bindings", derive(TS))]
11108pub struct JSONStripNulls {
11109    pub this: Box<Expression>,
11110    #[serde(default)]
11111    pub expression: Option<Box<Expression>>,
11112    #[serde(default)]
11113    pub include_arrays: Option<Box<Expression>>,
11114    #[serde(default)]
11115    pub remove_empty: Option<Box<Expression>>,
11116}
11117
11118/// JSONValue
11119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11120#[cfg_attr(feature = "bindings", derive(TS))]
11121pub struct JSONValue {
11122    pub this: Box<Expression>,
11123    #[serde(default)]
11124    pub path: Option<Box<Expression>>,
11125    #[serde(default)]
11126    pub returning: Option<Box<Expression>>,
11127    #[serde(default)]
11128    pub on_condition: Option<Box<Expression>>,
11129}
11130
11131/// JSONValueArray
11132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11133#[cfg_attr(feature = "bindings", derive(TS))]
11134pub struct JSONValueArray {
11135    pub this: Box<Expression>,
11136    #[serde(default)]
11137    pub expression: Option<Box<Expression>>,
11138}
11139
11140/// JSONRemove
11141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11142#[cfg_attr(feature = "bindings", derive(TS))]
11143pub struct JSONRemove {
11144    pub this: Box<Expression>,
11145    #[serde(default)]
11146    pub expressions: Vec<Expression>,
11147}
11148
11149/// JSONTable
11150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11151#[cfg_attr(feature = "bindings", derive(TS))]
11152pub struct JSONTable {
11153    pub this: Box<Expression>,
11154    #[serde(default)]
11155    pub schema: Option<Box<Expression>>,
11156    #[serde(default)]
11157    pub path: Option<Box<Expression>>,
11158    #[serde(default)]
11159    pub error_handling: Option<Box<Expression>>,
11160    #[serde(default)]
11161    pub empty_handling: Option<Box<Expression>>,
11162}
11163
11164/// JSONType
11165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11166#[cfg_attr(feature = "bindings", derive(TS))]
11167pub struct JSONType {
11168    pub this: Box<Expression>,
11169    #[serde(default)]
11170    pub expression: Option<Box<Expression>>,
11171}
11172
11173/// ObjectInsert
11174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11175#[cfg_attr(feature = "bindings", derive(TS))]
11176pub struct ObjectInsert {
11177    pub this: Box<Expression>,
11178    #[serde(default)]
11179    pub key: Option<Box<Expression>>,
11180    #[serde(default)]
11181    pub value: Option<Box<Expression>>,
11182    #[serde(default)]
11183    pub update_flag: Option<Box<Expression>>,
11184}
11185
11186/// OpenJSONColumnDef
11187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11188#[cfg_attr(feature = "bindings", derive(TS))]
11189pub struct OpenJSONColumnDef {
11190    pub this: Box<Expression>,
11191    pub kind: String,
11192    #[serde(default)]
11193    pub path: Option<Box<Expression>>,
11194    #[serde(default)]
11195    pub as_json: Option<Box<Expression>>,
11196    /// The parsed data type for proper generation
11197    #[serde(default, skip_serializing_if = "Option::is_none")]
11198    pub data_type: Option<DataType>,
11199}
11200
11201/// OpenJSON
11202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11203#[cfg_attr(feature = "bindings", derive(TS))]
11204pub struct OpenJSON {
11205    pub this: Box<Expression>,
11206    #[serde(default)]
11207    pub path: Option<Box<Expression>>,
11208    #[serde(default)]
11209    pub expressions: Vec<Expression>,
11210}
11211
11212/// JSONBExists
11213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11214#[cfg_attr(feature = "bindings", derive(TS))]
11215pub struct JSONBExists {
11216    pub this: Box<Expression>,
11217    #[serde(default)]
11218    pub path: Option<Box<Expression>>,
11219}
11220
11221/// JSONCast
11222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11223#[cfg_attr(feature = "bindings", derive(TS))]
11224pub struct JSONCast {
11225    pub this: Box<Expression>,
11226    pub to: DataType,
11227}
11228
11229/// JSONExtract
11230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11231#[cfg_attr(feature = "bindings", derive(TS))]
11232pub struct JSONExtract {
11233    pub this: Box<Expression>,
11234    pub expression: Box<Expression>,
11235    #[serde(default)]
11236    pub only_json_types: Option<Box<Expression>>,
11237    #[serde(default)]
11238    pub expressions: Vec<Expression>,
11239    #[serde(default)]
11240    pub variant_extract: Option<Box<Expression>>,
11241    #[serde(default)]
11242    pub json_query: Option<Box<Expression>>,
11243    #[serde(default)]
11244    pub option: Option<Box<Expression>>,
11245    #[serde(default)]
11246    pub quote: Option<Box<Expression>>,
11247    #[serde(default)]
11248    pub on_condition: Option<Box<Expression>>,
11249    #[serde(default)]
11250    pub requires_json: Option<Box<Expression>>,
11251}
11252
11253/// JSONExtractQuote
11254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11255#[cfg_attr(feature = "bindings", derive(TS))]
11256pub struct JSONExtractQuote {
11257    #[serde(default)]
11258    pub option: Option<Box<Expression>>,
11259    #[serde(default)]
11260    pub scalar: Option<Box<Expression>>,
11261}
11262
11263/// JSONExtractArray
11264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11265#[cfg_attr(feature = "bindings", derive(TS))]
11266pub struct JSONExtractArray {
11267    pub this: Box<Expression>,
11268    #[serde(default)]
11269    pub expression: Option<Box<Expression>>,
11270}
11271
11272/// JSONExtractScalar
11273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11274#[cfg_attr(feature = "bindings", derive(TS))]
11275pub struct JSONExtractScalar {
11276    pub this: Box<Expression>,
11277    pub expression: Box<Expression>,
11278    #[serde(default)]
11279    pub only_json_types: Option<Box<Expression>>,
11280    #[serde(default)]
11281    pub expressions: Vec<Expression>,
11282    #[serde(default)]
11283    pub json_type: Option<Box<Expression>>,
11284    #[serde(default)]
11285    pub scalar_only: Option<Box<Expression>>,
11286}
11287
11288/// JSONBExtractScalar
11289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11290#[cfg_attr(feature = "bindings", derive(TS))]
11291pub struct JSONBExtractScalar {
11292    pub this: Box<Expression>,
11293    pub expression: Box<Expression>,
11294    #[serde(default)]
11295    pub json_type: Option<Box<Expression>>,
11296}
11297
11298/// JSONFormat
11299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11300#[cfg_attr(feature = "bindings", derive(TS))]
11301pub struct JSONFormat {
11302    #[serde(default)]
11303    pub this: Option<Box<Expression>>,
11304    #[serde(default)]
11305    pub options: Vec<Expression>,
11306    #[serde(default)]
11307    pub is_json: Option<Box<Expression>>,
11308    #[serde(default)]
11309    pub to_json: Option<Box<Expression>>,
11310}
11311
11312/// JSONArrayAppend
11313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11314#[cfg_attr(feature = "bindings", derive(TS))]
11315pub struct JSONArrayAppend {
11316    pub this: Box<Expression>,
11317    #[serde(default)]
11318    pub expressions: Vec<Expression>,
11319}
11320
11321/// JSONArrayContains
11322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11323#[cfg_attr(feature = "bindings", derive(TS))]
11324pub struct JSONArrayContains {
11325    pub this: Box<Expression>,
11326    pub expression: Box<Expression>,
11327    #[serde(default)]
11328    pub json_type: Option<Box<Expression>>,
11329}
11330
11331/// JSONArrayInsert
11332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11333#[cfg_attr(feature = "bindings", derive(TS))]
11334pub struct JSONArrayInsert {
11335    pub this: Box<Expression>,
11336    #[serde(default)]
11337    pub expressions: Vec<Expression>,
11338}
11339
11340/// ParseJSON
11341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11342#[cfg_attr(feature = "bindings", derive(TS))]
11343pub struct ParseJSON {
11344    pub this: Box<Expression>,
11345    #[serde(default)]
11346    pub expression: Option<Box<Expression>>,
11347    #[serde(default)]
11348    pub safe: Option<Box<Expression>>,
11349}
11350
11351/// ParseUrl
11352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11353#[cfg_attr(feature = "bindings", derive(TS))]
11354pub struct ParseUrl {
11355    pub this: Box<Expression>,
11356    #[serde(default)]
11357    pub part_to_extract: Option<Box<Expression>>,
11358    #[serde(default)]
11359    pub key: Option<Box<Expression>>,
11360    #[serde(default)]
11361    pub permissive: Option<Box<Expression>>,
11362}
11363
11364/// ParseIp
11365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11366#[cfg_attr(feature = "bindings", derive(TS))]
11367pub struct ParseIp {
11368    pub this: Box<Expression>,
11369    #[serde(default)]
11370    pub type_: Option<Box<Expression>>,
11371    #[serde(default)]
11372    pub permissive: Option<Box<Expression>>,
11373}
11374
11375/// ParseTime
11376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11377#[cfg_attr(feature = "bindings", derive(TS))]
11378pub struct ParseTime {
11379    pub this: Box<Expression>,
11380    pub format: String,
11381}
11382
11383/// ParseDatetime
11384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11385#[cfg_attr(feature = "bindings", derive(TS))]
11386pub struct ParseDatetime {
11387    pub this: Box<Expression>,
11388    #[serde(default)]
11389    pub format: Option<String>,
11390    #[serde(default)]
11391    pub zone: Option<Box<Expression>>,
11392}
11393
11394/// Map
11395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11396#[cfg_attr(feature = "bindings", derive(TS))]
11397pub struct Map {
11398    #[serde(default)]
11399    pub keys: Vec<Expression>,
11400    #[serde(default)]
11401    pub values: Vec<Expression>,
11402}
11403
11404/// MapCat
11405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11406#[cfg_attr(feature = "bindings", derive(TS))]
11407pub struct MapCat {
11408    pub this: Box<Expression>,
11409    pub expression: Box<Expression>,
11410}
11411
11412/// MapDelete
11413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11414#[cfg_attr(feature = "bindings", derive(TS))]
11415pub struct MapDelete {
11416    pub this: Box<Expression>,
11417    #[serde(default)]
11418    pub expressions: Vec<Expression>,
11419}
11420
11421/// MapInsert
11422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11423#[cfg_attr(feature = "bindings", derive(TS))]
11424pub struct MapInsert {
11425    pub this: Box<Expression>,
11426    #[serde(default)]
11427    pub key: Option<Box<Expression>>,
11428    #[serde(default)]
11429    pub value: Option<Box<Expression>>,
11430    #[serde(default)]
11431    pub update_flag: Option<Box<Expression>>,
11432}
11433
11434/// MapPick
11435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11436#[cfg_attr(feature = "bindings", derive(TS))]
11437pub struct MapPick {
11438    pub this: Box<Expression>,
11439    #[serde(default)]
11440    pub expressions: Vec<Expression>,
11441}
11442
11443/// ScopeResolution
11444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11445#[cfg_attr(feature = "bindings", derive(TS))]
11446pub struct ScopeResolution {
11447    #[serde(default)]
11448    pub this: Option<Box<Expression>>,
11449    pub expression: Box<Expression>,
11450}
11451
11452/// Slice
11453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11454#[cfg_attr(feature = "bindings", derive(TS))]
11455pub struct Slice {
11456    #[serde(default)]
11457    pub this: Option<Box<Expression>>,
11458    #[serde(default)]
11459    pub expression: Option<Box<Expression>>,
11460    #[serde(default)]
11461    pub step: Option<Box<Expression>>,
11462}
11463
11464/// VarMap
11465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11466#[cfg_attr(feature = "bindings", derive(TS))]
11467pub struct VarMap {
11468    #[serde(default)]
11469    pub keys: Vec<Expression>,
11470    #[serde(default)]
11471    pub values: Vec<Expression>,
11472}
11473
11474/// MatchAgainst
11475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11476#[cfg_attr(feature = "bindings", derive(TS))]
11477pub struct MatchAgainst {
11478    pub this: Box<Expression>,
11479    #[serde(default)]
11480    pub expressions: Vec<Expression>,
11481    #[serde(default)]
11482    pub modifier: Option<Box<Expression>>,
11483}
11484
11485/// MD5Digest
11486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11487#[cfg_attr(feature = "bindings", derive(TS))]
11488pub struct MD5Digest {
11489    pub this: Box<Expression>,
11490    #[serde(default)]
11491    pub expressions: Vec<Expression>,
11492}
11493
11494/// Monthname
11495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11496#[cfg_attr(feature = "bindings", derive(TS))]
11497pub struct Monthname {
11498    pub this: Box<Expression>,
11499    #[serde(default)]
11500    pub abbreviated: Option<Box<Expression>>,
11501}
11502
11503/// Ntile
11504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11505#[cfg_attr(feature = "bindings", derive(TS))]
11506pub struct Ntile {
11507    #[serde(default)]
11508    pub this: Option<Box<Expression>>,
11509}
11510
11511/// Normalize
11512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11513#[cfg_attr(feature = "bindings", derive(TS))]
11514pub struct Normalize {
11515    pub this: Box<Expression>,
11516    #[serde(default)]
11517    pub form: Option<Box<Expression>>,
11518    #[serde(default)]
11519    pub is_casefold: Option<Box<Expression>>,
11520}
11521
11522/// Normal
11523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11524#[cfg_attr(feature = "bindings", derive(TS))]
11525pub struct Normal {
11526    pub this: Box<Expression>,
11527    #[serde(default)]
11528    pub stddev: Option<Box<Expression>>,
11529    #[serde(default)]
11530    pub gen: Option<Box<Expression>>,
11531}
11532
11533/// Predict
11534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11535#[cfg_attr(feature = "bindings", derive(TS))]
11536pub struct Predict {
11537    pub this: Box<Expression>,
11538    pub expression: Box<Expression>,
11539    #[serde(default)]
11540    pub params_struct: Option<Box<Expression>>,
11541}
11542
11543/// MLTranslate
11544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11545#[cfg_attr(feature = "bindings", derive(TS))]
11546pub struct MLTranslate {
11547    pub this: Box<Expression>,
11548    pub expression: Box<Expression>,
11549    #[serde(default)]
11550    pub params_struct: Option<Box<Expression>>,
11551}
11552
11553/// FeaturesAtTime
11554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11555#[cfg_attr(feature = "bindings", derive(TS))]
11556pub struct FeaturesAtTime {
11557    pub this: Box<Expression>,
11558    #[serde(default)]
11559    pub time: Option<Box<Expression>>,
11560    #[serde(default)]
11561    pub num_rows: Option<Box<Expression>>,
11562    #[serde(default)]
11563    pub ignore_feature_nulls: Option<Box<Expression>>,
11564}
11565
11566/// GenerateEmbedding
11567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11568#[cfg_attr(feature = "bindings", derive(TS))]
11569pub struct GenerateEmbedding {
11570    pub this: Box<Expression>,
11571    pub expression: Box<Expression>,
11572    #[serde(default)]
11573    pub params_struct: Option<Box<Expression>>,
11574    #[serde(default)]
11575    pub is_text: Option<Box<Expression>>,
11576}
11577
11578/// MLForecast
11579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11580#[cfg_attr(feature = "bindings", derive(TS))]
11581pub struct MLForecast {
11582    pub this: Box<Expression>,
11583    #[serde(default)]
11584    pub expression: Option<Box<Expression>>,
11585    #[serde(default)]
11586    pub params_struct: Option<Box<Expression>>,
11587}
11588
11589/// ModelAttribute
11590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11591#[cfg_attr(feature = "bindings", derive(TS))]
11592pub struct ModelAttribute {
11593    pub this: Box<Expression>,
11594    pub expression: Box<Expression>,
11595}
11596
11597/// VectorSearch
11598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11599#[cfg_attr(feature = "bindings", derive(TS))]
11600pub struct VectorSearch {
11601    pub this: Box<Expression>,
11602    #[serde(default)]
11603    pub column_to_search: Option<Box<Expression>>,
11604    #[serde(default)]
11605    pub query_table: Option<Box<Expression>>,
11606    #[serde(default)]
11607    pub query_column_to_search: Option<Box<Expression>>,
11608    #[serde(default)]
11609    pub top_k: Option<Box<Expression>>,
11610    #[serde(default)]
11611    pub distance_type: Option<Box<Expression>>,
11612    #[serde(default)]
11613    pub options: Vec<Expression>,
11614}
11615
11616/// Quantile
11617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11618#[cfg_attr(feature = "bindings", derive(TS))]
11619pub struct Quantile {
11620    pub this: Box<Expression>,
11621    #[serde(default)]
11622    pub quantile: Option<Box<Expression>>,
11623}
11624
11625/// ApproxQuantile
11626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11627#[cfg_attr(feature = "bindings", derive(TS))]
11628pub struct ApproxQuantile {
11629    pub this: Box<Expression>,
11630    #[serde(default)]
11631    pub quantile: Option<Box<Expression>>,
11632    #[serde(default)]
11633    pub accuracy: Option<Box<Expression>>,
11634    #[serde(default)]
11635    pub weight: Option<Box<Expression>>,
11636    #[serde(default)]
11637    pub error_tolerance: Option<Box<Expression>>,
11638}
11639
11640/// ApproxPercentileEstimate
11641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11642#[cfg_attr(feature = "bindings", derive(TS))]
11643pub struct ApproxPercentileEstimate {
11644    pub this: Box<Expression>,
11645    #[serde(default)]
11646    pub percentile: Option<Box<Expression>>,
11647}
11648
11649/// Randn
11650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11651#[cfg_attr(feature = "bindings", derive(TS))]
11652pub struct Randn {
11653    #[serde(default)]
11654    pub this: Option<Box<Expression>>,
11655}
11656
11657/// Randstr
11658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11659#[cfg_attr(feature = "bindings", derive(TS))]
11660pub struct Randstr {
11661    pub this: Box<Expression>,
11662    #[serde(default)]
11663    pub generator: Option<Box<Expression>>,
11664}
11665
11666/// RangeN
11667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11668#[cfg_attr(feature = "bindings", derive(TS))]
11669pub struct RangeN {
11670    pub this: Box<Expression>,
11671    #[serde(default)]
11672    pub expressions: Vec<Expression>,
11673    #[serde(default)]
11674    pub each: Option<Box<Expression>>,
11675}
11676
11677/// RangeBucket
11678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11679#[cfg_attr(feature = "bindings", derive(TS))]
11680pub struct RangeBucket {
11681    pub this: Box<Expression>,
11682    pub expression: Box<Expression>,
11683}
11684
11685/// ReadCSV
11686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11687#[cfg_attr(feature = "bindings", derive(TS))]
11688pub struct ReadCSV {
11689    pub this: Box<Expression>,
11690    #[serde(default)]
11691    pub expressions: Vec<Expression>,
11692}
11693
11694/// ReadParquet
11695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11696#[cfg_attr(feature = "bindings", derive(TS))]
11697pub struct ReadParquet {
11698    #[serde(default)]
11699    pub expressions: Vec<Expression>,
11700}
11701
11702/// Reduce
11703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11704#[cfg_attr(feature = "bindings", derive(TS))]
11705pub struct Reduce {
11706    pub this: Box<Expression>,
11707    #[serde(default)]
11708    pub initial: Option<Box<Expression>>,
11709    #[serde(default)]
11710    pub merge: Option<Box<Expression>>,
11711    #[serde(default)]
11712    pub finish: Option<Box<Expression>>,
11713}
11714
11715/// RegexpExtractAll
11716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11717#[cfg_attr(feature = "bindings", derive(TS))]
11718pub struct RegexpExtractAll {
11719    pub this: Box<Expression>,
11720    pub expression: Box<Expression>,
11721    #[serde(default)]
11722    pub group: Option<Box<Expression>>,
11723    #[serde(default)]
11724    pub parameters: Option<Box<Expression>>,
11725    #[serde(default)]
11726    pub position: Option<Box<Expression>>,
11727    #[serde(default)]
11728    pub occurrence: Option<Box<Expression>>,
11729}
11730
11731/// RegexpILike
11732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11733#[cfg_attr(feature = "bindings", derive(TS))]
11734pub struct RegexpILike {
11735    pub this: Box<Expression>,
11736    pub expression: Box<Expression>,
11737    #[serde(default)]
11738    pub flag: Option<Box<Expression>>,
11739}
11740
11741/// RegexpFullMatch
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct RegexpFullMatch {
11745    pub this: Box<Expression>,
11746    pub expression: Box<Expression>,
11747    #[serde(default)]
11748    pub options: Vec<Expression>,
11749}
11750
11751/// RegexpInstr
11752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11753#[cfg_attr(feature = "bindings", derive(TS))]
11754pub struct RegexpInstr {
11755    pub this: Box<Expression>,
11756    pub expression: Box<Expression>,
11757    #[serde(default)]
11758    pub position: Option<Box<Expression>>,
11759    #[serde(default)]
11760    pub occurrence: Option<Box<Expression>>,
11761    #[serde(default)]
11762    pub option: Option<Box<Expression>>,
11763    #[serde(default)]
11764    pub parameters: Option<Box<Expression>>,
11765    #[serde(default)]
11766    pub group: Option<Box<Expression>>,
11767}
11768
11769/// RegexpSplit
11770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11771#[cfg_attr(feature = "bindings", derive(TS))]
11772pub struct RegexpSplit {
11773    pub this: Box<Expression>,
11774    pub expression: Box<Expression>,
11775    #[serde(default)]
11776    pub limit: Option<Box<Expression>>,
11777}
11778
11779/// RegexpCount
11780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11781#[cfg_attr(feature = "bindings", derive(TS))]
11782pub struct RegexpCount {
11783    pub this: Box<Expression>,
11784    pub expression: Box<Expression>,
11785    #[serde(default)]
11786    pub position: Option<Box<Expression>>,
11787    #[serde(default)]
11788    pub parameters: Option<Box<Expression>>,
11789}
11790
11791/// RegrValx
11792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11793#[cfg_attr(feature = "bindings", derive(TS))]
11794pub struct RegrValx {
11795    pub this: Box<Expression>,
11796    pub expression: Box<Expression>,
11797}
11798
11799/// RegrValy
11800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11801#[cfg_attr(feature = "bindings", derive(TS))]
11802pub struct RegrValy {
11803    pub this: Box<Expression>,
11804    pub expression: Box<Expression>,
11805}
11806
11807/// RegrAvgy
11808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11809#[cfg_attr(feature = "bindings", derive(TS))]
11810pub struct RegrAvgy {
11811    pub this: Box<Expression>,
11812    pub expression: Box<Expression>,
11813}
11814
11815/// RegrAvgx
11816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11817#[cfg_attr(feature = "bindings", derive(TS))]
11818pub struct RegrAvgx {
11819    pub this: Box<Expression>,
11820    pub expression: Box<Expression>,
11821}
11822
11823/// RegrCount
11824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11825#[cfg_attr(feature = "bindings", derive(TS))]
11826pub struct RegrCount {
11827    pub this: Box<Expression>,
11828    pub expression: Box<Expression>,
11829}
11830
11831/// RegrIntercept
11832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11833#[cfg_attr(feature = "bindings", derive(TS))]
11834pub struct RegrIntercept {
11835    pub this: Box<Expression>,
11836    pub expression: Box<Expression>,
11837}
11838
11839/// RegrR2
11840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11841#[cfg_attr(feature = "bindings", derive(TS))]
11842pub struct RegrR2 {
11843    pub this: Box<Expression>,
11844    pub expression: Box<Expression>,
11845}
11846
11847/// RegrSxx
11848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11849#[cfg_attr(feature = "bindings", derive(TS))]
11850pub struct RegrSxx {
11851    pub this: Box<Expression>,
11852    pub expression: Box<Expression>,
11853}
11854
11855/// RegrSxy
11856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11857#[cfg_attr(feature = "bindings", derive(TS))]
11858pub struct RegrSxy {
11859    pub this: Box<Expression>,
11860    pub expression: Box<Expression>,
11861}
11862
11863/// RegrSyy
11864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11865#[cfg_attr(feature = "bindings", derive(TS))]
11866pub struct RegrSyy {
11867    pub this: Box<Expression>,
11868    pub expression: Box<Expression>,
11869}
11870
11871/// RegrSlope
11872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11873#[cfg_attr(feature = "bindings", derive(TS))]
11874pub struct RegrSlope {
11875    pub this: Box<Expression>,
11876    pub expression: Box<Expression>,
11877}
11878
11879/// SafeAdd
11880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11881#[cfg_attr(feature = "bindings", derive(TS))]
11882pub struct SafeAdd {
11883    pub this: Box<Expression>,
11884    pub expression: Box<Expression>,
11885}
11886
11887/// SafeDivide
11888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11889#[cfg_attr(feature = "bindings", derive(TS))]
11890pub struct SafeDivide {
11891    pub this: Box<Expression>,
11892    pub expression: Box<Expression>,
11893}
11894
11895/// SafeMultiply
11896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11897#[cfg_attr(feature = "bindings", derive(TS))]
11898pub struct SafeMultiply {
11899    pub this: Box<Expression>,
11900    pub expression: Box<Expression>,
11901}
11902
11903/// SafeSubtract
11904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11905#[cfg_attr(feature = "bindings", derive(TS))]
11906pub struct SafeSubtract {
11907    pub this: Box<Expression>,
11908    pub expression: Box<Expression>,
11909}
11910
11911/// SHA2
11912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11913#[cfg_attr(feature = "bindings", derive(TS))]
11914pub struct SHA2 {
11915    pub this: Box<Expression>,
11916    #[serde(default)]
11917    pub length: Option<i64>,
11918}
11919
11920/// SHA2Digest
11921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11922#[cfg_attr(feature = "bindings", derive(TS))]
11923pub struct SHA2Digest {
11924    pub this: Box<Expression>,
11925    #[serde(default)]
11926    pub length: Option<i64>,
11927}
11928
11929/// SortArray
11930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11931#[cfg_attr(feature = "bindings", derive(TS))]
11932pub struct SortArray {
11933    pub this: Box<Expression>,
11934    #[serde(default)]
11935    pub asc: Option<Box<Expression>>,
11936    #[serde(default)]
11937    pub nulls_first: Option<Box<Expression>>,
11938}
11939
11940/// SplitPart
11941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11942#[cfg_attr(feature = "bindings", derive(TS))]
11943pub struct SplitPart {
11944    pub this: Box<Expression>,
11945    #[serde(default)]
11946    pub delimiter: Option<Box<Expression>>,
11947    #[serde(default)]
11948    pub part_index: Option<Box<Expression>>,
11949}
11950
11951/// SUBSTRING_INDEX(str, delim, count)
11952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11953#[cfg_attr(feature = "bindings", derive(TS))]
11954pub struct SubstringIndex {
11955    pub this: Box<Expression>,
11956    #[serde(default)]
11957    pub delimiter: Option<Box<Expression>>,
11958    #[serde(default)]
11959    pub count: Option<Box<Expression>>,
11960}
11961
11962/// StandardHash
11963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11964#[cfg_attr(feature = "bindings", derive(TS))]
11965pub struct StandardHash {
11966    pub this: Box<Expression>,
11967    #[serde(default)]
11968    pub expression: Option<Box<Expression>>,
11969}
11970
11971/// StrPosition
11972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11973#[cfg_attr(feature = "bindings", derive(TS))]
11974pub struct StrPosition {
11975    pub this: Box<Expression>,
11976    #[serde(default)]
11977    pub substr: Option<Box<Expression>>,
11978    #[serde(default)]
11979    pub position: Option<Box<Expression>>,
11980    #[serde(default)]
11981    pub occurrence: Option<Box<Expression>>,
11982}
11983
11984/// Search
11985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11986#[cfg_attr(feature = "bindings", derive(TS))]
11987pub struct Search {
11988    pub this: Box<Expression>,
11989    pub expression: Box<Expression>,
11990    #[serde(default)]
11991    pub json_scope: Option<Box<Expression>>,
11992    #[serde(default)]
11993    pub analyzer: Option<Box<Expression>>,
11994    #[serde(default)]
11995    pub analyzer_options: Option<Box<Expression>>,
11996    #[serde(default)]
11997    pub search_mode: Option<Box<Expression>>,
11998}
11999
12000/// SearchIp
12001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12002#[cfg_attr(feature = "bindings", derive(TS))]
12003pub struct SearchIp {
12004    pub this: Box<Expression>,
12005    pub expression: Box<Expression>,
12006}
12007
12008/// StrToDate
12009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12010#[cfg_attr(feature = "bindings", derive(TS))]
12011pub struct StrToDate {
12012    pub this: Box<Expression>,
12013    #[serde(default)]
12014    pub format: Option<String>,
12015    #[serde(default)]
12016    pub safe: Option<Box<Expression>>,
12017}
12018
12019/// StrToTime
12020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12021#[cfg_attr(feature = "bindings", derive(TS))]
12022pub struct StrToTime {
12023    pub this: Box<Expression>,
12024    pub format: String,
12025    #[serde(default)]
12026    pub zone: Option<Box<Expression>>,
12027    #[serde(default)]
12028    pub safe: Option<Box<Expression>>,
12029    #[serde(default)]
12030    pub target_type: Option<Box<Expression>>,
12031}
12032
12033/// StrToUnix
12034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12035#[cfg_attr(feature = "bindings", derive(TS))]
12036pub struct StrToUnix {
12037    #[serde(default)]
12038    pub this: Option<Box<Expression>>,
12039    #[serde(default)]
12040    pub format: Option<String>,
12041}
12042
12043/// StrToMap
12044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12045#[cfg_attr(feature = "bindings", derive(TS))]
12046pub struct StrToMap {
12047    pub this: Box<Expression>,
12048    #[serde(default)]
12049    pub pair_delim: Option<Box<Expression>>,
12050    #[serde(default)]
12051    pub key_value_delim: Option<Box<Expression>>,
12052    #[serde(default)]
12053    pub duplicate_resolution_callback: Option<Box<Expression>>,
12054}
12055
12056/// NumberToStr
12057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12058#[cfg_attr(feature = "bindings", derive(TS))]
12059pub struct NumberToStr {
12060    pub this: Box<Expression>,
12061    pub format: String,
12062    #[serde(default)]
12063    pub culture: Option<Box<Expression>>,
12064}
12065
12066/// FromBase
12067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12068#[cfg_attr(feature = "bindings", derive(TS))]
12069pub struct FromBase {
12070    pub this: Box<Expression>,
12071    pub expression: Box<Expression>,
12072}
12073
12074/// Stuff
12075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12076#[cfg_attr(feature = "bindings", derive(TS))]
12077pub struct Stuff {
12078    pub this: Box<Expression>,
12079    #[serde(default)]
12080    pub start: Option<Box<Expression>>,
12081    #[serde(default)]
12082    pub length: Option<i64>,
12083    pub expression: Box<Expression>,
12084}
12085
12086/// TimeToStr
12087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12088#[cfg_attr(feature = "bindings", derive(TS))]
12089pub struct TimeToStr {
12090    pub this: Box<Expression>,
12091    pub format: String,
12092    #[serde(default)]
12093    pub culture: Option<Box<Expression>>,
12094    #[serde(default)]
12095    pub zone: Option<Box<Expression>>,
12096}
12097
12098/// TimeStrToTime
12099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12100#[cfg_attr(feature = "bindings", derive(TS))]
12101pub struct TimeStrToTime {
12102    pub this: Box<Expression>,
12103    #[serde(default)]
12104    pub zone: Option<Box<Expression>>,
12105}
12106
12107/// TsOrDsAdd
12108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12109#[cfg_attr(feature = "bindings", derive(TS))]
12110pub struct TsOrDsAdd {
12111    pub this: Box<Expression>,
12112    pub expression: Box<Expression>,
12113    #[serde(default)]
12114    pub unit: Option<String>,
12115    #[serde(default)]
12116    pub return_type: Option<Box<Expression>>,
12117}
12118
12119/// TsOrDsDiff
12120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12121#[cfg_attr(feature = "bindings", derive(TS))]
12122pub struct TsOrDsDiff {
12123    pub this: Box<Expression>,
12124    pub expression: Box<Expression>,
12125    #[serde(default)]
12126    pub unit: Option<String>,
12127}
12128
12129/// TsOrDsToDate
12130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12131#[cfg_attr(feature = "bindings", derive(TS))]
12132pub struct TsOrDsToDate {
12133    pub this: Box<Expression>,
12134    #[serde(default)]
12135    pub format: Option<String>,
12136    #[serde(default)]
12137    pub safe: Option<Box<Expression>>,
12138}
12139
12140/// TsOrDsToTime
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct TsOrDsToTime {
12144    pub this: Box<Expression>,
12145    #[serde(default)]
12146    pub format: Option<String>,
12147    #[serde(default)]
12148    pub safe: Option<Box<Expression>>,
12149}
12150
12151/// Unhex
12152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12153#[cfg_attr(feature = "bindings", derive(TS))]
12154pub struct Unhex {
12155    pub this: Box<Expression>,
12156    #[serde(default)]
12157    pub expression: Option<Box<Expression>>,
12158}
12159
12160/// Uniform
12161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12162#[cfg_attr(feature = "bindings", derive(TS))]
12163pub struct Uniform {
12164    pub this: Box<Expression>,
12165    pub expression: Box<Expression>,
12166    #[serde(default)]
12167    pub gen: Option<Box<Expression>>,
12168    #[serde(default)]
12169    pub seed: Option<Box<Expression>>,
12170}
12171
12172/// UnixToStr
12173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12174#[cfg_attr(feature = "bindings", derive(TS))]
12175pub struct UnixToStr {
12176    pub this: Box<Expression>,
12177    #[serde(default)]
12178    pub format: Option<String>,
12179}
12180
12181/// UnixToTime
12182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12183#[cfg_attr(feature = "bindings", derive(TS))]
12184pub struct UnixToTime {
12185    pub this: Box<Expression>,
12186    #[serde(default)]
12187    pub scale: Option<i64>,
12188    #[serde(default)]
12189    pub zone: Option<Box<Expression>>,
12190    #[serde(default)]
12191    pub hours: Option<Box<Expression>>,
12192    #[serde(default)]
12193    pub minutes: Option<Box<Expression>>,
12194    #[serde(default)]
12195    pub format: Option<String>,
12196    #[serde(default)]
12197    pub target_type: Option<Box<Expression>>,
12198}
12199
12200/// Uuid
12201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12202#[cfg_attr(feature = "bindings", derive(TS))]
12203pub struct Uuid {
12204    #[serde(default)]
12205    pub this: Option<Box<Expression>>,
12206    #[serde(default)]
12207    pub name: Option<String>,
12208    #[serde(default)]
12209    pub is_string: Option<Box<Expression>>,
12210}
12211
12212/// TimestampFromParts
12213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12214#[cfg_attr(feature = "bindings", derive(TS))]
12215pub struct TimestampFromParts {
12216    #[serde(default)]
12217    pub zone: Option<Box<Expression>>,
12218    #[serde(default)]
12219    pub milli: Option<Box<Expression>>,
12220    #[serde(default)]
12221    pub this: Option<Box<Expression>>,
12222    #[serde(default)]
12223    pub expression: Option<Box<Expression>>,
12224}
12225
12226/// TimestampTzFromParts
12227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12228#[cfg_attr(feature = "bindings", derive(TS))]
12229pub struct TimestampTzFromParts {
12230    #[serde(default)]
12231    pub zone: Option<Box<Expression>>,
12232}
12233
12234/// Corr
12235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12236#[cfg_attr(feature = "bindings", derive(TS))]
12237pub struct Corr {
12238    pub this: Box<Expression>,
12239    pub expression: Box<Expression>,
12240    #[serde(default)]
12241    pub null_on_zero_variance: Option<Box<Expression>>,
12242}
12243
12244/// WidthBucket
12245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12246#[cfg_attr(feature = "bindings", derive(TS))]
12247pub struct WidthBucket {
12248    pub this: Box<Expression>,
12249    #[serde(default)]
12250    pub min_value: Option<Box<Expression>>,
12251    #[serde(default)]
12252    pub max_value: Option<Box<Expression>>,
12253    #[serde(default)]
12254    pub num_buckets: Option<Box<Expression>>,
12255    #[serde(default)]
12256    pub threshold: Option<Box<Expression>>,
12257}
12258
12259/// CovarSamp
12260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12261#[cfg_attr(feature = "bindings", derive(TS))]
12262pub struct CovarSamp {
12263    pub this: Box<Expression>,
12264    pub expression: Box<Expression>,
12265}
12266
12267/// CovarPop
12268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12269#[cfg_attr(feature = "bindings", derive(TS))]
12270pub struct CovarPop {
12271    pub this: Box<Expression>,
12272    pub expression: Box<Expression>,
12273}
12274
12275/// Week
12276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12277#[cfg_attr(feature = "bindings", derive(TS))]
12278pub struct Week {
12279    pub this: Box<Expression>,
12280    #[serde(default)]
12281    pub mode: Option<Box<Expression>>,
12282}
12283
12284/// XMLElement
12285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12286#[cfg_attr(feature = "bindings", derive(TS))]
12287pub struct XMLElement {
12288    pub this: Box<Expression>,
12289    #[serde(default)]
12290    pub expressions: Vec<Expression>,
12291    #[serde(default)]
12292    pub evalname: Option<Box<Expression>>,
12293}
12294
12295/// XMLGet
12296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12297#[cfg_attr(feature = "bindings", derive(TS))]
12298pub struct XMLGet {
12299    pub this: Box<Expression>,
12300    pub expression: Box<Expression>,
12301    #[serde(default)]
12302    pub instance: Option<Box<Expression>>,
12303}
12304
12305/// XMLTable
12306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12307#[cfg_attr(feature = "bindings", derive(TS))]
12308pub struct XMLTable {
12309    pub this: Box<Expression>,
12310    #[serde(default)]
12311    pub namespaces: Option<Box<Expression>>,
12312    #[serde(default)]
12313    pub passing: Option<Box<Expression>>,
12314    #[serde(default)]
12315    pub columns: Vec<Expression>,
12316    #[serde(default)]
12317    pub by_ref: Option<Box<Expression>>,
12318}
12319
12320/// XMLKeyValueOption
12321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12322#[cfg_attr(feature = "bindings", derive(TS))]
12323pub struct XMLKeyValueOption {
12324    pub this: Box<Expression>,
12325    #[serde(default)]
12326    pub expression: Option<Box<Expression>>,
12327}
12328
12329/// Zipf
12330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12331#[cfg_attr(feature = "bindings", derive(TS))]
12332pub struct Zipf {
12333    pub this: Box<Expression>,
12334    #[serde(default)]
12335    pub elementcount: Option<Box<Expression>>,
12336    #[serde(default)]
12337    pub gen: Option<Box<Expression>>,
12338}
12339
12340/// Merge
12341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12342#[cfg_attr(feature = "bindings", derive(TS))]
12343pub struct Merge {
12344    pub this: Box<Expression>,
12345    pub using: Box<Expression>,
12346    #[serde(default)]
12347    pub on: Option<Box<Expression>>,
12348    #[serde(default)]
12349    pub using_cond: Option<Box<Expression>>,
12350    #[serde(default)]
12351    pub whens: Option<Box<Expression>>,
12352    #[serde(default)]
12353    pub with_: Option<Box<Expression>>,
12354    #[serde(default)]
12355    pub returning: Option<Box<Expression>>,
12356}
12357
12358/// When
12359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12360#[cfg_attr(feature = "bindings", derive(TS))]
12361pub struct When {
12362    #[serde(default)]
12363    pub matched: Option<Box<Expression>>,
12364    #[serde(default)]
12365    pub source: Option<Box<Expression>>,
12366    #[serde(default)]
12367    pub condition: Option<Box<Expression>>,
12368    pub then: Box<Expression>,
12369}
12370
12371/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct Whens {
12375    #[serde(default)]
12376    pub expressions: Vec<Expression>,
12377}
12378
12379/// NextValueFor
12380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12381#[cfg_attr(feature = "bindings", derive(TS))]
12382pub struct NextValueFor {
12383    pub this: Box<Expression>,
12384    #[serde(default)]
12385    pub order: Option<Box<Expression>>,
12386}
12387
12388
12389#[cfg(test)]
12390mod tests {
12391    use super::*;
12392
12393    #[test]
12394    #[cfg(feature = "bindings")]
12395    fn export_typescript_types() {
12396        // This test exports TypeScript types to the generated directory
12397        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12398        Expression::export_all(&ts_rs::Config::default()).expect("Failed to export Expression types");
12399    }
12400
12401    #[test]
12402    fn test_simple_select_builder() {
12403        let select = Select::new()
12404            .column(Expression::star())
12405            .from(Expression::Table(TableRef::new("users")));
12406
12407        assert_eq!(select.expressions.len(), 1);
12408        assert!(select.from.is_some());
12409    }
12410
12411    #[test]
12412    fn test_expression_alias() {
12413        let expr = Expression::column("id").alias("user_id");
12414
12415        match expr {
12416            Expression::Alias(a) => {
12417                assert_eq!(a.alias.name, "user_id");
12418            }
12419            _ => panic!("Expected Alias"),
12420        }
12421    }
12422
12423    #[test]
12424    fn test_literal_creation() {
12425        let num = Expression::number(42);
12426        let str = Expression::string("hello");
12427
12428        match num {
12429            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12430            _ => panic!("Expected Number"),
12431        }
12432
12433        match str {
12434            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12435            _ => panic!("Expected String"),
12436        }
12437    }
12438
12439    #[test]
12440    fn test_expression_sql() {
12441        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12442        assert_eq!(expr.sql(), "SELECT 1 + 2");
12443    }
12444
12445    #[test]
12446    fn test_expression_sql_for() {
12447        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12448        let sql = expr.sql_for(crate::DialectType::Generic);
12449        assert!(sql.contains("IF"));
12450    }
12451}