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<VarArgFunc>),
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    Variadic(Box<Variadic>),
791    Version(Box<Version>),
792    Schema(Box<Schema>),
793    Lock(Box<Lock>),
794    TableSample(Box<TableSample>),
795    Tag(Box<Tag>),
796    UnpivotColumns(Box<UnpivotColumns>),
797    WindowSpec(Box<WindowSpec>),
798    SessionParameter(Box<SessionParameter>),
799    PseudoType(Box<PseudoType>),
800    ObjectIdentifier(Box<ObjectIdentifier>),
801    Transaction(Box<Transaction>),
802    Commit(Box<Commit>),
803    Rollback(Box<Rollback>),
804    AlterSession(Box<AlterSession>),
805    Analyze(Box<Analyze>),
806    AnalyzeStatistics(Box<AnalyzeStatistics>),
807    AnalyzeHistogram(Box<AnalyzeHistogram>),
808    AnalyzeSample(Box<AnalyzeSample>),
809    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
810    AnalyzeDelete(Box<AnalyzeDelete>),
811    AnalyzeWith(Box<AnalyzeWith>),
812    AnalyzeValidate(Box<AnalyzeValidate>),
813    AddPartition(Box<AddPartition>),
814    AttachOption(Box<AttachOption>),
815    DropPartition(Box<DropPartition>),
816    ReplacePartition(Box<ReplacePartition>),
817    DPipe(Box<DPipe>),
818    Operator(Box<Operator>),
819    PivotAny(Box<PivotAny>),
820    Aliases(Box<Aliases>),
821    AtIndex(Box<AtIndex>),
822    FromTimeZone(Box<FromTimeZone>),
823    FormatPhrase(Box<FormatPhrase>),
824    ForIn(Box<ForIn>),
825    TimeUnit(Box<TimeUnit>),
826    IntervalOp(Box<IntervalOp>),
827    IntervalSpan(Box<IntervalSpan>),
828    HavingMax(Box<HavingMax>),
829    CosineDistance(Box<CosineDistance>),
830    DotProduct(Box<DotProduct>),
831    EuclideanDistance(Box<EuclideanDistance>),
832    ManhattanDistance(Box<ManhattanDistance>),
833    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
834    Booland(Box<Booland>),
835    Boolor(Box<Boolor>),
836    ParameterizedAgg(Box<ParameterizedAgg>),
837    ArgMax(Box<ArgMax>),
838    ArgMin(Box<ArgMin>),
839    ApproxTopK(Box<ApproxTopK>),
840    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
841    ApproxTopKCombine(Box<ApproxTopKCombine>),
842    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
843    ApproxTopSum(Box<ApproxTopSum>),
844    ApproxQuantiles(Box<ApproxQuantiles>),
845    Minhash(Box<Minhash>),
846    FarmFingerprint(Box<FarmFingerprint>),
847    Float64(Box<Float64>),
848    Transform(Box<Transform>),
849    Translate(Box<Translate>),
850    Grouping(Box<Grouping>),
851    GroupingId(Box<GroupingId>),
852    Anonymous(Box<Anonymous>),
853    AnonymousAggFunc(Box<AnonymousAggFunc>),
854    CombinedAggFunc(Box<CombinedAggFunc>),
855    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
856    HashAgg(Box<HashAgg>),
857    Hll(Box<Hll>),
858    Apply(Box<Apply>),
859    ToBoolean(Box<ToBoolean>),
860    List(Box<List>),
861    ToMap(Box<ToMap>),
862    Pad(Box<Pad>),
863    ToChar(Box<ToChar>),
864    ToNumber(Box<ToNumber>),
865    ToDouble(Box<ToDouble>),
866    Int64(Box<UnaryFunc>),
867    StringFunc(Box<StringFunc>),
868    ToDecfloat(Box<ToDecfloat>),
869    TryToDecfloat(Box<TryToDecfloat>),
870    ToFile(Box<ToFile>),
871    Columns(Box<Columns>),
872    ConvertToCharset(Box<ConvertToCharset>),
873    ConvertTimezone(Box<ConvertTimezone>),
874    GenerateSeries(Box<GenerateSeries>),
875    AIAgg(Box<AIAgg>),
876    AIClassify(Box<AIClassify>),
877    ArrayAll(Box<ArrayAll>),
878    ArrayAny(Box<ArrayAny>),
879    ArrayConstructCompact(Box<ArrayConstructCompact>),
880    StPoint(Box<StPoint>),
881    StDistance(Box<StDistance>),
882    StringToArray(Box<StringToArray>),
883    ArraySum(Box<ArraySum>),
884    ObjectAgg(Box<ObjectAgg>),
885    CastToStrType(Box<CastToStrType>),
886    CheckJson(Box<CheckJson>),
887    CheckXml(Box<CheckXml>),
888    TranslateCharacters(Box<TranslateCharacters>),
889    CurrentSchemas(Box<CurrentSchemas>),
890    CurrentDatetime(Box<CurrentDatetime>),
891    Localtime(Box<Localtime>),
892    Localtimestamp(Box<Localtimestamp>),
893    Systimestamp(Box<Systimestamp>),
894    CurrentSchema(Box<CurrentSchema>),
895    CurrentUser(Box<CurrentUser>),
896    UtcTime(Box<UtcTime>),
897    UtcTimestamp(Box<UtcTimestamp>),
898    Timestamp(Box<TimestampFunc>),
899    DateBin(Box<DateBin>),
900    Datetime(Box<Datetime>),
901    DatetimeAdd(Box<DatetimeAdd>),
902    DatetimeSub(Box<DatetimeSub>),
903    DatetimeDiff(Box<DatetimeDiff>),
904    DatetimeTrunc(Box<DatetimeTrunc>),
905    Dayname(Box<Dayname>),
906    MakeInterval(Box<MakeInterval>),
907    PreviousDay(Box<PreviousDay>),
908    Elt(Box<Elt>),
909    TimestampAdd(Box<TimestampAdd>),
910    TimestampSub(Box<TimestampSub>),
911    TimestampDiff(Box<TimestampDiff>),
912    TimeSlice(Box<TimeSlice>),
913    TimeAdd(Box<TimeAdd>),
914    TimeSub(Box<TimeSub>),
915    TimeDiff(Box<TimeDiff>),
916    TimeTrunc(Box<TimeTrunc>),
917    DateFromParts(Box<DateFromParts>),
918    TimeFromParts(Box<TimeFromParts>),
919    DecodeCase(Box<DecodeCase>),
920    Decrypt(Box<Decrypt>),
921    DecryptRaw(Box<DecryptRaw>),
922    Encode(Box<Encode>),
923    Encrypt(Box<Encrypt>),
924    EncryptRaw(Box<EncryptRaw>),
925    EqualNull(Box<EqualNull>),
926    ToBinary(Box<ToBinary>),
927    Base64DecodeBinary(Box<Base64DecodeBinary>),
928    Base64DecodeString(Box<Base64DecodeString>),
929    Base64Encode(Box<Base64Encode>),
930    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
931    TryBase64DecodeString(Box<TryBase64DecodeString>),
932    GapFill(Box<GapFill>),
933    GenerateDateArray(Box<GenerateDateArray>),
934    GenerateTimestampArray(Box<GenerateTimestampArray>),
935    GetExtract(Box<GetExtract>),
936    Getbit(Box<Getbit>),
937    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
938    HexEncode(Box<HexEncode>),
939    Compress(Box<Compress>),
940    DecompressBinary(Box<DecompressBinary>),
941    DecompressString(Box<DecompressString>),
942    Xor(Box<Xor>),
943    Nullif(Box<Nullif>),
944    JSON(Box<JSON>),
945    JSONPath(Box<JSONPath>),
946    JSONPathFilter(Box<JSONPathFilter>),
947    JSONPathKey(Box<JSONPathKey>),
948    JSONPathRecursive(Box<JSONPathRecursive>),
949    JSONPathScript(Box<JSONPathScript>),
950    JSONPathSlice(Box<JSONPathSlice>),
951    JSONPathSelector(Box<JSONPathSelector>),
952    JSONPathSubscript(Box<JSONPathSubscript>),
953    JSONPathUnion(Box<JSONPathUnion>),
954    Format(Box<Format>),
955    JSONKeys(Box<JSONKeys>),
956    JSONKeyValue(Box<JSONKeyValue>),
957    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
958    JSONObject(Box<JSONObject>),
959    JSONObjectAgg(Box<JSONObjectAgg>),
960    JSONBObjectAgg(Box<JSONBObjectAgg>),
961    JSONArray(Box<JSONArray>),
962    JSONArrayAgg(Box<JSONArrayAgg>),
963    JSONExists(Box<JSONExists>),
964    JSONColumnDef(Box<JSONColumnDef>),
965    JSONSchema(Box<JSONSchema>),
966    JSONSet(Box<JSONSet>),
967    JSONStripNulls(Box<JSONStripNulls>),
968    JSONValue(Box<JSONValue>),
969    JSONValueArray(Box<JSONValueArray>),
970    JSONRemove(Box<JSONRemove>),
971    JSONTable(Box<JSONTable>),
972    JSONType(Box<JSONType>),
973    ObjectInsert(Box<ObjectInsert>),
974    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
975    OpenJSON(Box<OpenJSON>),
976    JSONBExists(Box<JSONBExists>),
977    JSONBContains(Box<BinaryFunc>),
978    JSONBExtract(Box<BinaryFunc>),
979    JSONCast(Box<JSONCast>),
980    JSONExtract(Box<JSONExtract>),
981    JSONExtractQuote(Box<JSONExtractQuote>),
982    JSONExtractArray(Box<JSONExtractArray>),
983    JSONExtractScalar(Box<JSONExtractScalar>),
984    JSONBExtractScalar(Box<JSONBExtractScalar>),
985    JSONFormat(Box<JSONFormat>),
986    JSONBool(Box<UnaryFunc>),
987    JSONPathRoot(JSONPathRoot),
988    JSONArrayAppend(Box<JSONArrayAppend>),
989    JSONArrayContains(Box<JSONArrayContains>),
990    JSONArrayInsert(Box<JSONArrayInsert>),
991    ParseJSON(Box<ParseJSON>),
992    ParseUrl(Box<ParseUrl>),
993    ParseIp(Box<ParseIp>),
994    ParseTime(Box<ParseTime>),
995    ParseDatetime(Box<ParseDatetime>),
996    Map(Box<Map>),
997    MapCat(Box<MapCat>),
998    MapDelete(Box<MapDelete>),
999    MapInsert(Box<MapInsert>),
1000    MapPick(Box<MapPick>),
1001    ScopeResolution(Box<ScopeResolution>),
1002    Slice(Box<Slice>),
1003    VarMap(Box<VarMap>),
1004    MatchAgainst(Box<MatchAgainst>),
1005    MD5Digest(Box<MD5Digest>),
1006    MD5NumberLower64(Box<UnaryFunc>),
1007    MD5NumberUpper64(Box<UnaryFunc>),
1008    Monthname(Box<Monthname>),
1009    Ntile(Box<Ntile>),
1010    Normalize(Box<Normalize>),
1011    Normal(Box<Normal>),
1012    Predict(Box<Predict>),
1013    MLTranslate(Box<MLTranslate>),
1014    FeaturesAtTime(Box<FeaturesAtTime>),
1015    GenerateEmbedding(Box<GenerateEmbedding>),
1016    MLForecast(Box<MLForecast>),
1017    ModelAttribute(Box<ModelAttribute>),
1018    VectorSearch(Box<VectorSearch>),
1019    Quantile(Box<Quantile>),
1020    ApproxQuantile(Box<ApproxQuantile>),
1021    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1022    Randn(Box<Randn>),
1023    Randstr(Box<Randstr>),
1024    RangeN(Box<RangeN>),
1025    RangeBucket(Box<RangeBucket>),
1026    ReadCSV(Box<ReadCSV>),
1027    ReadParquet(Box<ReadParquet>),
1028    Reduce(Box<Reduce>),
1029    RegexpExtractAll(Box<RegexpExtractAll>),
1030    RegexpILike(Box<RegexpILike>),
1031    RegexpFullMatch(Box<RegexpFullMatch>),
1032    RegexpInstr(Box<RegexpInstr>),
1033    RegexpSplit(Box<RegexpSplit>),
1034    RegexpCount(Box<RegexpCount>),
1035    RegrValx(Box<RegrValx>),
1036    RegrValy(Box<RegrValy>),
1037    RegrAvgy(Box<RegrAvgy>),
1038    RegrAvgx(Box<RegrAvgx>),
1039    RegrCount(Box<RegrCount>),
1040    RegrIntercept(Box<RegrIntercept>),
1041    RegrR2(Box<RegrR2>),
1042    RegrSxx(Box<RegrSxx>),
1043    RegrSxy(Box<RegrSxy>),
1044    RegrSyy(Box<RegrSyy>),
1045    RegrSlope(Box<RegrSlope>),
1046    SafeAdd(Box<SafeAdd>),
1047    SafeDivide(Box<SafeDivide>),
1048    SafeMultiply(Box<SafeMultiply>),
1049    SafeSubtract(Box<SafeSubtract>),
1050    SHA2(Box<SHA2>),
1051    SHA2Digest(Box<SHA2Digest>),
1052    SortArray(Box<SortArray>),
1053    SplitPart(Box<SplitPart>),
1054    SubstringIndex(Box<SubstringIndex>),
1055    StandardHash(Box<StandardHash>),
1056    StrPosition(Box<StrPosition>),
1057    Search(Box<Search>),
1058    SearchIp(Box<SearchIp>),
1059    StrToDate(Box<StrToDate>),
1060    DateStrToDate(Box<UnaryFunc>),
1061    DateToDateStr(Box<UnaryFunc>),
1062    StrToTime(Box<StrToTime>),
1063    StrToUnix(Box<StrToUnix>),
1064    StrToMap(Box<StrToMap>),
1065    NumberToStr(Box<NumberToStr>),
1066    FromBase(Box<FromBase>),
1067    Stuff(Box<Stuff>),
1068    TimeToStr(Box<TimeToStr>),
1069    TimeStrToTime(Box<TimeStrToTime>),
1070    TsOrDsAdd(Box<TsOrDsAdd>),
1071    TsOrDsDiff(Box<TsOrDsDiff>),
1072    TsOrDsToDate(Box<TsOrDsToDate>),
1073    TsOrDsToTime(Box<TsOrDsToTime>),
1074    Unhex(Box<Unhex>),
1075    Uniform(Box<Uniform>),
1076    UnixToStr(Box<UnixToStr>),
1077    UnixToTime(Box<UnixToTime>),
1078    Uuid(Box<Uuid>),
1079    TimestampFromParts(Box<TimestampFromParts>),
1080    TimestampTzFromParts(Box<TimestampTzFromParts>),
1081    Corr(Box<Corr>),
1082    WidthBucket(Box<WidthBucket>),
1083    CovarSamp(Box<CovarSamp>),
1084    CovarPop(Box<CovarPop>),
1085    Week(Box<Week>),
1086    XMLElement(Box<XMLElement>),
1087    XMLGet(Box<XMLGet>),
1088    XMLTable(Box<XMLTable>),
1089    XMLKeyValueOption(Box<XMLKeyValueOption>),
1090    Zipf(Box<Zipf>),
1091    Merge(Box<Merge>),
1092    When(Box<When>),
1093    Whens(Box<Whens>),
1094    NextValueFor(Box<NextValueFor>),
1095    /// RETURN statement (DuckDB stored procedures)
1096    ReturnStmt(Box<Expression>),
1097}
1098
1099impl Expression {
1100    /// Returns `true` if this expression is a valid top-level SQL statement.
1101    ///
1102    /// Bare expressions like identifiers, literals, and function calls are not
1103    /// valid statements. This is used by `validate()` to reject inputs like
1104    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1105    /// plus the bare identifier `doo`.
1106    pub fn is_statement(&self) -> bool {
1107        match self {
1108            // Queries
1109            Expression::Select(_)
1110            | Expression::Union(_)
1111            | Expression::Intersect(_)
1112            | Expression::Except(_)
1113            | Expression::Subquery(_)
1114            | Expression::Values(_)
1115            | Expression::PipeOperator(_)
1116
1117            // DML
1118            | Expression::Insert(_)
1119            | Expression::Update(_)
1120            | Expression::Delete(_)
1121            | Expression::Copy(_)
1122            | Expression::Put(_)
1123            | Expression::Merge(_)
1124
1125            // DDL
1126            | Expression::CreateTable(_)
1127            | Expression::DropTable(_)
1128            | Expression::AlterTable(_)
1129            | Expression::CreateIndex(_)
1130            | Expression::DropIndex(_)
1131            | Expression::CreateView(_)
1132            | Expression::DropView(_)
1133            | Expression::AlterView(_)
1134            | Expression::AlterIndex(_)
1135            | Expression::Truncate(_)
1136            | Expression::TruncateTable(_)
1137            | Expression::CreateSchema(_)
1138            | Expression::DropSchema(_)
1139            | Expression::DropNamespace(_)
1140            | Expression::CreateDatabase(_)
1141            | Expression::DropDatabase(_)
1142            | Expression::CreateFunction(_)
1143            | Expression::DropFunction(_)
1144            | Expression::CreateProcedure(_)
1145            | Expression::DropProcedure(_)
1146            | Expression::CreateSequence(_)
1147            | Expression::DropSequence(_)
1148            | Expression::AlterSequence(_)
1149            | Expression::CreateTrigger(_)
1150            | Expression::DropTrigger(_)
1151            | Expression::CreateType(_)
1152            | Expression::DropType(_)
1153            | Expression::Comment(_)
1154
1155            // Session/Transaction/Control
1156            | Expression::Use(_)
1157            | Expression::Set(_)
1158            | Expression::SetStatement(_)
1159            | Expression::Transaction(_)
1160            | Expression::Commit(_)
1161            | Expression::Rollback(_)
1162            | Expression::Grant(_)
1163            | Expression::Revoke(_)
1164            | Expression::Cache(_)
1165            | Expression::Uncache(_)
1166            | Expression::LoadData(_)
1167            | Expression::Pragma(_)
1168            | Expression::Describe(_)
1169            | Expression::Show(_)
1170            | Expression::Kill(_)
1171            | Expression::Execute(_)
1172            | Expression::Declare(_)
1173            | Expression::Refresh(_)
1174            | Expression::AlterSession(_)
1175            | Expression::LockingStatement(_)
1176
1177            // Analyze
1178            | Expression::Analyze(_)
1179            | Expression::AnalyzeStatistics(_)
1180            | Expression::AnalyzeHistogram(_)
1181            | Expression::AnalyzeSample(_)
1182            | Expression::AnalyzeListChainedRows(_)
1183            | Expression::AnalyzeDelete(_)
1184
1185            // Attach/Detach/Install/Summarize
1186            | Expression::Attach(_)
1187            | Expression::Detach(_)
1188            | Expression::Install(_)
1189            | Expression::Summarize(_)
1190
1191            // Pivot at statement level
1192            | Expression::Pivot(_)
1193            | Expression::Unpivot(_)
1194
1195            // Command (raw/unparsed statements)
1196            | Expression::Command(_)
1197            | Expression::Raw(_)
1198
1199            // Return statement
1200            | Expression::ReturnStmt(_) => true,
1201
1202            // Annotated wraps another expression with comments — check inner
1203            Expression::Annotated(a) => a.this.is_statement(),
1204
1205            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1206            Expression::Alias(a) => a.this.is_statement(),
1207
1208            // Everything else (identifiers, literals, operators, functions, etc.)
1209            _ => false,
1210        }
1211    }
1212
1213    /// Create a literal number expression from an integer.
1214    pub fn number(n: i64) -> Self {
1215        Expression::Literal(Literal::Number(n.to_string()))
1216    }
1217
1218    /// Create a single-quoted literal string expression.
1219    pub fn string(s: impl Into<String>) -> Self {
1220        Expression::Literal(Literal::String(s.into()))
1221    }
1222
1223    /// Create a literal number expression from a float.
1224    pub fn float(f: f64) -> Self {
1225        Expression::Literal(Literal::Number(f.to_string()))
1226    }
1227
1228    /// Create an unqualified column reference (e.g. `name`).
1229    pub fn column(name: impl Into<String>) -> Self {
1230        Expression::Column(Column {
1231            name: Identifier::new(name),
1232            table: None,
1233            join_mark: false,
1234            trailing_comments: Vec::new(),
1235        })
1236    }
1237
1238    /// Create a qualified column reference (`table.column`).
1239    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1240        Expression::Column(Column {
1241            name: Identifier::new(column),
1242            table: Some(Identifier::new(table)),
1243            join_mark: false,
1244            trailing_comments: Vec::new(),
1245        })
1246    }
1247
1248    /// Create a bare identifier expression (not a column reference).
1249    pub fn identifier(name: impl Into<String>) -> Self {
1250        Expression::Identifier(Identifier::new(name))
1251    }
1252
1253    /// Create a NULL expression
1254    pub fn null() -> Self {
1255        Expression::Null(Null)
1256    }
1257
1258    /// Create a TRUE expression
1259    pub fn true_() -> Self {
1260        Expression::Boolean(BooleanLiteral { value: true })
1261    }
1262
1263    /// Create a FALSE expression
1264    pub fn false_() -> Self {
1265        Expression::Boolean(BooleanLiteral { value: false })
1266    }
1267
1268    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1269    pub fn star() -> Self {
1270        Expression::Star(Star {
1271            table: None,
1272            except: None,
1273            replace: None,
1274            rename: None,
1275            trailing_comments: Vec::new(),
1276        })
1277    }
1278
1279    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1280    pub fn alias(self, name: impl Into<String>) -> Self {
1281        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1282    }
1283
1284    /// Check if this is a SELECT expression
1285    pub fn is_select(&self) -> bool {
1286        matches!(self, Expression::Select(_))
1287    }
1288
1289    /// Try to get as a Select
1290    pub fn as_select(&self) -> Option<&Select> {
1291        match self {
1292            Expression::Select(s) => Some(s),
1293            _ => None,
1294        }
1295    }
1296
1297    /// Try to get as a mutable Select
1298    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1299        match self {
1300            Expression::Select(s) => Some(s),
1301            _ => None,
1302        }
1303    }
1304
1305    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1306    ///
1307    /// Returns an empty string if generation fails. For dialect-specific output,
1308    /// use [`sql_for()`](Self::sql_for) instead.
1309    pub fn sql(&self) -> String {
1310        crate::generator::Generator::sql(self).unwrap_or_default()
1311    }
1312
1313    /// Generate a SQL string for this expression targeting a specific dialect.
1314    ///
1315    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1316    /// syntax variations) are applied automatically.  Returns an empty string if
1317    /// generation fails.
1318    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1319        crate::generate(self, dialect).unwrap_or_default()
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 {
1836            expressions,
1837            siblings: false,
1838            comments: Vec::new(),
1839        });
1840        self
1841    }
1842
1843    /// Set LIMIT
1844    pub fn limit(mut self, n: Expression) -> Self {
1845        self.limit = Some(Limit {
1846            this: n,
1847            percent: false,
1848            comments: Vec::new(),
1849        });
1850        self
1851    }
1852
1853    /// Set OFFSET
1854    pub fn offset(mut self, n: Expression) -> Self {
1855        self.offset = Some(Offset {
1856            this: n,
1857            rows: None,
1858        });
1859        self
1860    }
1861}
1862
1863impl Default for Select {
1864    fn default() -> Self {
1865        Self::new()
1866    }
1867}
1868
1869/// Represent a UNION set operation between two query expressions.
1870///
1871/// When `all` is true, duplicate rows are preserved (UNION ALL).
1872/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
1873/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
1874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1875#[cfg_attr(feature = "bindings", derive(TS))]
1876pub struct Union {
1877    /// The left-hand query operand.
1878    pub left: Expression,
1879    /// The right-hand query operand.
1880    pub right: Expression,
1881    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
1882    pub all: bool,
1883    /// Whether DISTINCT was explicitly specified
1884    #[serde(default)]
1885    pub distinct: bool,
1886    /// Optional WITH clause
1887    pub with: Option<With>,
1888    /// ORDER BY applied to entire UNION result
1889    pub order_by: Option<OrderBy>,
1890    /// LIMIT applied to entire UNION result
1891    pub limit: Option<Box<Expression>>,
1892    /// OFFSET applied to entire UNION result
1893    pub offset: Option<Box<Expression>>,
1894    /// DISTRIBUTE BY clause (Hive/Spark)
1895    #[serde(default, skip_serializing_if = "Option::is_none")]
1896    pub distribute_by: Option<DistributeBy>,
1897    /// SORT BY clause (Hive/Spark)
1898    #[serde(default, skip_serializing_if = "Option::is_none")]
1899    pub sort_by: Option<SortBy>,
1900    /// CLUSTER BY clause (Hive/Spark)
1901    #[serde(default, skip_serializing_if = "Option::is_none")]
1902    pub cluster_by: Option<ClusterBy>,
1903    /// DuckDB BY NAME modifier
1904    #[serde(default)]
1905    pub by_name: bool,
1906    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1907    #[serde(default, skip_serializing_if = "Option::is_none")]
1908    pub side: Option<String>,
1909    /// BigQuery: Set operation kind (INNER)
1910    #[serde(default, skip_serializing_if = "Option::is_none")]
1911    pub kind: Option<String>,
1912    /// BigQuery: CORRESPONDING modifier
1913    #[serde(default)]
1914    pub corresponding: bool,
1915    /// BigQuery: STRICT modifier (before CORRESPONDING)
1916    #[serde(default)]
1917    pub strict: bool,
1918    /// BigQuery: BY (columns) after CORRESPONDING
1919    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1920    pub on_columns: Vec<Expression>,
1921}
1922
1923/// Represent an INTERSECT set operation between two query expressions.
1924///
1925/// Returns only rows that appear in both operands. When `all` is true,
1926/// duplicates are preserved according to their multiplicity.
1927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1928#[cfg_attr(feature = "bindings", derive(TS))]
1929pub struct Intersect {
1930    /// The left-hand query operand.
1931    pub left: Expression,
1932    /// The right-hand query operand.
1933    pub right: Expression,
1934    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
1935    pub all: bool,
1936    /// Whether DISTINCT was explicitly specified
1937    #[serde(default)]
1938    pub distinct: bool,
1939    /// Optional WITH clause
1940    pub with: Option<With>,
1941    /// ORDER BY applied to entire INTERSECT result
1942    pub order_by: Option<OrderBy>,
1943    /// LIMIT applied to entire INTERSECT result
1944    pub limit: Option<Box<Expression>>,
1945    /// OFFSET applied to entire INTERSECT result
1946    pub offset: Option<Box<Expression>>,
1947    /// DISTRIBUTE BY clause (Hive/Spark)
1948    #[serde(default, skip_serializing_if = "Option::is_none")]
1949    pub distribute_by: Option<DistributeBy>,
1950    /// SORT BY clause (Hive/Spark)
1951    #[serde(default, skip_serializing_if = "Option::is_none")]
1952    pub sort_by: Option<SortBy>,
1953    /// CLUSTER BY clause (Hive/Spark)
1954    #[serde(default, skip_serializing_if = "Option::is_none")]
1955    pub cluster_by: Option<ClusterBy>,
1956    /// DuckDB BY NAME modifier
1957    #[serde(default)]
1958    pub by_name: bool,
1959    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1960    #[serde(default, skip_serializing_if = "Option::is_none")]
1961    pub side: Option<String>,
1962    /// BigQuery: Set operation kind (INNER)
1963    #[serde(default, skip_serializing_if = "Option::is_none")]
1964    pub kind: Option<String>,
1965    /// BigQuery: CORRESPONDING modifier
1966    #[serde(default)]
1967    pub corresponding: bool,
1968    /// BigQuery: STRICT modifier (before CORRESPONDING)
1969    #[serde(default)]
1970    pub strict: bool,
1971    /// BigQuery: BY (columns) after CORRESPONDING
1972    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1973    pub on_columns: Vec<Expression>,
1974}
1975
1976/// Represent an EXCEPT (MINUS) set operation between two query expressions.
1977///
1978/// Returns rows from the left operand that do not appear in the right operand.
1979/// When `all` is true, duplicates are subtracted according to their multiplicity.
1980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1981#[cfg_attr(feature = "bindings", derive(TS))]
1982pub struct Except {
1983    /// The left-hand query operand.
1984    pub left: Expression,
1985    /// The right-hand query operand (rows to subtract).
1986    pub right: Expression,
1987    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
1988    pub all: bool,
1989    /// Whether DISTINCT was explicitly specified
1990    #[serde(default)]
1991    pub distinct: bool,
1992    /// Optional WITH clause
1993    pub with: Option<With>,
1994    /// ORDER BY applied to entire EXCEPT result
1995    pub order_by: Option<OrderBy>,
1996    /// LIMIT applied to entire EXCEPT result
1997    pub limit: Option<Box<Expression>>,
1998    /// OFFSET applied to entire EXCEPT result
1999    pub offset: Option<Box<Expression>>,
2000    /// DISTRIBUTE BY clause (Hive/Spark)
2001    #[serde(default, skip_serializing_if = "Option::is_none")]
2002    pub distribute_by: Option<DistributeBy>,
2003    /// SORT BY clause (Hive/Spark)
2004    #[serde(default, skip_serializing_if = "Option::is_none")]
2005    pub sort_by: Option<SortBy>,
2006    /// CLUSTER BY clause (Hive/Spark)
2007    #[serde(default, skip_serializing_if = "Option::is_none")]
2008    pub cluster_by: Option<ClusterBy>,
2009    /// DuckDB BY NAME modifier
2010    #[serde(default)]
2011    pub by_name: bool,
2012    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2013    #[serde(default, skip_serializing_if = "Option::is_none")]
2014    pub side: Option<String>,
2015    /// BigQuery: Set operation kind (INNER)
2016    #[serde(default, skip_serializing_if = "Option::is_none")]
2017    pub kind: Option<String>,
2018    /// BigQuery: CORRESPONDING modifier
2019    #[serde(default)]
2020    pub corresponding: bool,
2021    /// BigQuery: STRICT modifier (before CORRESPONDING)
2022    #[serde(default)]
2023    pub strict: bool,
2024    /// BigQuery: BY (columns) after CORRESPONDING
2025    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2026    pub on_columns: Vec<Expression>,
2027}
2028
2029/// INTO clause for SELECT INTO statements
2030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2031#[cfg_attr(feature = "bindings", derive(TS))]
2032pub struct SelectInto {
2033    /// Target table or variable (used when single target)
2034    pub this: Expression,
2035    /// Whether TEMPORARY keyword was used
2036    #[serde(default)]
2037    pub temporary: bool,
2038    /// Whether UNLOGGED keyword was used (PostgreSQL)
2039    #[serde(default)]
2040    pub unlogged: bool,
2041    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2042    #[serde(default)]
2043    pub bulk_collect: bool,
2044    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2045    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2046    pub expressions: Vec<Expression>,
2047}
2048
2049/// Represent a parenthesized subquery expression.
2050///
2051/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2052/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2053/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2054/// modifiers are rendered inside or outside the parentheses.
2055///
2056/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2057/// scalar subqueries in select-lists, and derived tables.
2058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2059#[cfg_attr(feature = "bindings", derive(TS))]
2060pub struct Subquery {
2061    /// The inner query expression.
2062    pub this: Expression,
2063    /// Optional alias for the derived table.
2064    pub alias: Option<Identifier>,
2065    /// Optional column aliases: AS t(c1, c2)
2066    pub column_aliases: Vec<Identifier>,
2067    /// ORDER BY clause (for parenthesized queries)
2068    pub order_by: Option<OrderBy>,
2069    /// LIMIT clause
2070    pub limit: Option<Limit>,
2071    /// OFFSET clause
2072    pub offset: Option<Offset>,
2073    /// DISTRIBUTE BY clause (Hive/Spark)
2074    #[serde(default, skip_serializing_if = "Option::is_none")]
2075    pub distribute_by: Option<DistributeBy>,
2076    /// SORT BY clause (Hive/Spark)
2077    #[serde(default, skip_serializing_if = "Option::is_none")]
2078    pub sort_by: Option<SortBy>,
2079    /// CLUSTER BY clause (Hive/Spark)
2080    #[serde(default, skip_serializing_if = "Option::is_none")]
2081    pub cluster_by: Option<ClusterBy>,
2082    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2083    #[serde(default)]
2084    pub lateral: bool,
2085    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2086    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2087    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2088    #[serde(default)]
2089    pub modifiers_inside: bool,
2090    /// Trailing comments after the closing paren
2091    #[serde(default)]
2092    pub trailing_comments: Vec<String>,
2093}
2094
2095/// Pipe operator expression: query |> transform
2096///
2097/// Used in DataFusion and BigQuery pipe syntax:
2098///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2100#[cfg_attr(feature = "bindings", derive(TS))]
2101pub struct PipeOperator {
2102    /// The input query/expression (left side of |>)
2103    pub this: Expression,
2104    /// The piped operation (right side of |>)
2105    pub expression: Expression,
2106}
2107
2108/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2110#[cfg_attr(feature = "bindings", derive(TS))]
2111pub struct Values {
2112    /// The rows of values
2113    pub expressions: Vec<Tuple>,
2114    /// Optional alias for the table
2115    pub alias: Option<Identifier>,
2116    /// Optional column aliases: AS t(c1, c2)
2117    pub column_aliases: Vec<Identifier>,
2118}
2119
2120/// PIVOT operation - supports both standard and DuckDB simplified syntax
2121///
2122/// Standard syntax (in FROM clause):
2123///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2124///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2125///
2126/// DuckDB simplified syntax (statement-level):
2127///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2128///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2130#[cfg_attr(feature = "bindings", derive(TS))]
2131pub struct Pivot {
2132    /// Source table/expression
2133    pub this: Expression,
2134    /// For standard PIVOT: the aggregation function(s) (first is primary)
2135    /// For DuckDB simplified: unused (use `using` instead)
2136    #[serde(default)]
2137    pub expressions: Vec<Expression>,
2138    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2139    #[serde(default)]
2140    pub fields: Vec<Expression>,
2141    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2142    #[serde(default)]
2143    pub using: Vec<Expression>,
2144    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2145    #[serde(default)]
2146    pub group: Option<Box<Expression>>,
2147    /// Whether this is an UNPIVOT (vs PIVOT)
2148    #[serde(default)]
2149    pub unpivot: bool,
2150    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2151    #[serde(default)]
2152    pub into: Option<Box<Expression>>,
2153    /// Optional alias
2154    #[serde(default)]
2155    pub alias: Option<Identifier>,
2156    /// Include/exclude nulls (for UNPIVOT)
2157    #[serde(default)]
2158    pub include_nulls: Option<bool>,
2159    /// Default on null value (Snowflake)
2160    #[serde(default)]
2161    pub default_on_null: Option<Box<Expression>>,
2162    /// WITH clause (CTEs)
2163    #[serde(default, skip_serializing_if = "Option::is_none")]
2164    pub with: Option<With>,
2165}
2166
2167/// UNPIVOT operation
2168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2169#[cfg_attr(feature = "bindings", derive(TS))]
2170pub struct Unpivot {
2171    pub this: Expression,
2172    pub value_column: Identifier,
2173    pub name_column: Identifier,
2174    pub columns: Vec<Expression>,
2175    pub alias: Option<Identifier>,
2176    /// Whether the value_column was parenthesized in the original SQL
2177    #[serde(default)]
2178    pub value_column_parenthesized: bool,
2179    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2180    #[serde(default)]
2181    pub include_nulls: Option<bool>,
2182    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2183    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2184    pub extra_value_columns: Vec<Identifier>,
2185}
2186
2187/// PIVOT alias for aliasing pivot expressions
2188/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2190#[cfg_attr(feature = "bindings", derive(TS))]
2191pub struct PivotAlias {
2192    pub this: Expression,
2193    pub alias: Expression,
2194}
2195
2196/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2198#[cfg_attr(feature = "bindings", derive(TS))]
2199pub struct PreWhere {
2200    pub this: Expression,
2201}
2202
2203/// STREAM definition (Snowflake) - for change data capture
2204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2205#[cfg_attr(feature = "bindings", derive(TS))]
2206pub struct Stream {
2207    pub this: Expression,
2208    #[serde(skip_serializing_if = "Option::is_none")]
2209    pub on: Option<Expression>,
2210    #[serde(skip_serializing_if = "Option::is_none")]
2211    pub show_initial_rows: Option<bool>,
2212}
2213
2214/// USING DATA clause for data import statements
2215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2216#[cfg_attr(feature = "bindings", derive(TS))]
2217pub struct UsingData {
2218    pub this: Expression,
2219}
2220
2221/// XML Namespace declaration
2222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2223#[cfg_attr(feature = "bindings", derive(TS))]
2224pub struct XmlNamespace {
2225    pub this: Expression,
2226    #[serde(skip_serializing_if = "Option::is_none")]
2227    pub alias: Option<Identifier>,
2228}
2229
2230/// ROW FORMAT clause for Hive/Spark
2231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2232#[cfg_attr(feature = "bindings", derive(TS))]
2233pub struct RowFormat {
2234    pub delimited: bool,
2235    pub fields_terminated_by: Option<String>,
2236    pub collection_items_terminated_by: Option<String>,
2237    pub map_keys_terminated_by: Option<String>,
2238    pub lines_terminated_by: Option<String>,
2239    pub null_defined_as: Option<String>,
2240}
2241
2242/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2244#[cfg_attr(feature = "bindings", derive(TS))]
2245pub struct DirectoryInsert {
2246    pub local: bool,
2247    pub path: String,
2248    pub row_format: Option<RowFormat>,
2249    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2250    #[serde(default)]
2251    pub stored_as: Option<String>,
2252}
2253
2254/// INSERT statement
2255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2256#[cfg_attr(feature = "bindings", derive(TS))]
2257pub struct Insert {
2258    pub table: TableRef,
2259    pub columns: Vec<Identifier>,
2260    pub values: Vec<Vec<Expression>>,
2261    pub query: Option<Expression>,
2262    /// INSERT OVERWRITE for Hive/Spark
2263    pub overwrite: bool,
2264    /// PARTITION clause for Hive/Spark
2265    pub partition: Vec<(Identifier, Option<Expression>)>,
2266    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2267    #[serde(default)]
2268    pub directory: Option<DirectoryInsert>,
2269    /// RETURNING clause (PostgreSQL, SQLite)
2270    #[serde(default)]
2271    pub returning: Vec<Expression>,
2272    /// OUTPUT clause (TSQL)
2273    #[serde(default)]
2274    pub output: Option<OutputClause>,
2275    /// ON CONFLICT clause (PostgreSQL, SQLite)
2276    #[serde(default)]
2277    pub on_conflict: Option<Box<Expression>>,
2278    /// Leading comments before the statement
2279    #[serde(default)]
2280    pub leading_comments: Vec<String>,
2281    /// IF EXISTS clause (Hive)
2282    #[serde(default)]
2283    pub if_exists: bool,
2284    /// WITH clause (CTEs)
2285    #[serde(default)]
2286    pub with: Option<With>,
2287    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2288    #[serde(default)]
2289    pub ignore: bool,
2290    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2291    #[serde(default)]
2292    pub source_alias: Option<Identifier>,
2293    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2294    #[serde(default)]
2295    pub alias: Option<Identifier>,
2296    /// Whether the alias uses explicit AS keyword
2297    #[serde(default)]
2298    pub alias_explicit_as: bool,
2299    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2300    #[serde(default)]
2301    pub default_values: bool,
2302    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2303    #[serde(default)]
2304    pub by_name: bool,
2305    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2306    #[serde(default, skip_serializing_if = "Option::is_none")]
2307    pub conflict_action: Option<String>,
2308    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2309    #[serde(default)]
2310    pub is_replace: bool,
2311    /// Oracle-style hint: INSERT /*+ APPEND */ INTO ...
2312    #[serde(default, skip_serializing_if = "Option::is_none")]
2313    pub hint: Option<Hint>,
2314    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2315    #[serde(default)]
2316    pub replace_where: Option<Box<Expression>>,
2317    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2318    #[serde(default)]
2319    pub source: Option<Box<Expression>>,
2320    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2321    #[serde(default, skip_serializing_if = "Option::is_none")]
2322    pub function_target: Option<Box<Expression>>,
2323    /// ClickHouse: PARTITION BY expr
2324    #[serde(default, skip_serializing_if = "Option::is_none")]
2325    pub partition_by: Option<Box<Expression>>,
2326    /// ClickHouse: SETTINGS key = val, ...
2327    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2328    pub settings: Vec<Expression>,
2329}
2330
2331/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2333#[cfg_attr(feature = "bindings", derive(TS))]
2334pub struct OutputClause {
2335    /// Columns/expressions to output
2336    pub columns: Vec<Expression>,
2337    /// Optional INTO target table or table variable
2338    #[serde(default)]
2339    pub into_table: Option<Expression>,
2340}
2341
2342/// UPDATE statement
2343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2344#[cfg_attr(feature = "bindings", derive(TS))]
2345pub struct Update {
2346    pub table: TableRef,
2347    /// Additional tables for multi-table UPDATE (MySQL syntax)
2348    #[serde(default)]
2349    pub extra_tables: Vec<TableRef>,
2350    /// JOINs attached to the table list (MySQL multi-table syntax)
2351    #[serde(default)]
2352    pub table_joins: Vec<Join>,
2353    pub set: Vec<(Identifier, Expression)>,
2354    pub from_clause: Option<From>,
2355    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2356    #[serde(default)]
2357    pub from_joins: Vec<Join>,
2358    pub where_clause: Option<Where>,
2359    /// RETURNING clause (PostgreSQL, SQLite)
2360    #[serde(default)]
2361    pub returning: Vec<Expression>,
2362    /// OUTPUT clause (TSQL)
2363    #[serde(default)]
2364    pub output: Option<OutputClause>,
2365    /// WITH clause (CTEs)
2366    #[serde(default)]
2367    pub with: Option<With>,
2368    /// Leading comments before the statement
2369    #[serde(default)]
2370    pub leading_comments: Vec<String>,
2371    /// LIMIT clause (MySQL)
2372    #[serde(default)]
2373    pub limit: Option<Expression>,
2374    /// ORDER BY clause (MySQL)
2375    #[serde(default)]
2376    pub order_by: Option<OrderBy>,
2377    /// Whether FROM clause appears before SET (Snowflake syntax)
2378    #[serde(default)]
2379    pub from_before_set: bool,
2380}
2381
2382/// DELETE statement
2383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2384#[cfg_attr(feature = "bindings", derive(TS))]
2385pub struct Delete {
2386    pub table: TableRef,
2387    /// ClickHouse: ON CLUSTER clause for distributed DDL
2388    #[serde(default, skip_serializing_if = "Option::is_none")]
2389    pub on_cluster: Option<OnCluster>,
2390    /// Optional alias for the table
2391    pub alias: Option<Identifier>,
2392    /// Whether the alias was declared with explicit AS keyword
2393    #[serde(default)]
2394    pub alias_explicit_as: bool,
2395    /// PostgreSQL/DuckDB USING clause - additional tables to join
2396    pub using: Vec<TableRef>,
2397    pub where_clause: Option<Where>,
2398    /// OUTPUT clause (TSQL)
2399    #[serde(default)]
2400    pub output: Option<OutputClause>,
2401    /// Leading comments before the statement
2402    #[serde(default)]
2403    pub leading_comments: Vec<String>,
2404    /// WITH clause (CTEs)
2405    #[serde(default)]
2406    pub with: Option<With>,
2407    /// LIMIT clause (MySQL)
2408    #[serde(default)]
2409    pub limit: Option<Expression>,
2410    /// ORDER BY clause (MySQL)
2411    #[serde(default)]
2412    pub order_by: Option<OrderBy>,
2413    /// RETURNING clause (PostgreSQL)
2414    #[serde(default)]
2415    pub returning: Vec<Expression>,
2416    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2417    /// These are the target tables to delete from
2418    #[serde(default)]
2419    pub tables: Vec<TableRef>,
2420    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2421    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2422    #[serde(default)]
2423    pub tables_from_using: bool,
2424    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2425    #[serde(default)]
2426    pub joins: Vec<Join>,
2427    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2428    #[serde(default)]
2429    pub force_index: Option<String>,
2430    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2431    #[serde(default)]
2432    pub no_from: bool,
2433}
2434
2435/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2437#[cfg_attr(feature = "bindings", derive(TS))]
2438pub struct CopyStmt {
2439    /// Target table or query
2440    pub this: Expression,
2441    /// True for FROM (loading into table), false for TO (exporting)
2442    pub kind: bool,
2443    /// Source/destination file(s) or stage
2444    pub files: Vec<Expression>,
2445    /// Copy parameters
2446    #[serde(default)]
2447    pub params: Vec<CopyParameter>,
2448    /// Credentials for external access
2449    #[serde(default)]
2450    pub credentials: Option<Box<Credentials>>,
2451    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2452    #[serde(default)]
2453    pub is_into: bool,
2454    /// Whether parameters are wrapped in WITH (...) syntax
2455    #[serde(default)]
2456    pub with_wrapped: bool,
2457}
2458
2459/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2461#[cfg_attr(feature = "bindings", derive(TS))]
2462pub struct CopyParameter {
2463    pub name: String,
2464    pub value: Option<Expression>,
2465    pub values: Vec<Expression>,
2466    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2467    #[serde(default)]
2468    pub eq: bool,
2469}
2470
2471/// Credentials for external access (S3, Azure, etc.)
2472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2473#[cfg_attr(feature = "bindings", derive(TS))]
2474pub struct Credentials {
2475    pub credentials: Vec<(String, String)>,
2476    pub encryption: Option<String>,
2477    pub storage: Option<String>,
2478}
2479
2480/// PUT statement (Snowflake)
2481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2482#[cfg_attr(feature = "bindings", derive(TS))]
2483pub struct PutStmt {
2484    /// Source file path
2485    pub source: String,
2486    /// Whether source was quoted in the original SQL
2487    #[serde(default)]
2488    pub source_quoted: bool,
2489    /// Target stage
2490    pub target: Expression,
2491    /// PUT parameters
2492    #[serde(default)]
2493    pub params: Vec<CopyParameter>,
2494}
2495
2496/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2498#[cfg_attr(feature = "bindings", derive(TS))]
2499pub struct StageReference {
2500    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2501    pub name: String,
2502    /// Optional path within the stage (e.g., "/path/to/file.csv")
2503    #[serde(default)]
2504    pub path: Option<String>,
2505    /// Optional FILE_FORMAT parameter
2506    #[serde(default)]
2507    pub file_format: Option<Expression>,
2508    /// Optional PATTERN parameter
2509    #[serde(default)]
2510    pub pattern: Option<String>,
2511    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2512    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2513    pub quoted: bool,
2514}
2515
2516/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2518#[cfg_attr(feature = "bindings", derive(TS))]
2519pub struct HistoricalData {
2520    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
2521    pub this: Box<Expression>,
2522    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
2523    pub kind: String,
2524    /// The expression value (e.g., the statement ID or timestamp)
2525    pub expression: Box<Expression>,
2526}
2527
2528/// Represent an aliased expression (`expr AS name`).
2529///
2530/// Used for column aliases in select-lists, table aliases on subqueries,
2531/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
2532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2533#[cfg_attr(feature = "bindings", derive(TS))]
2534pub struct Alias {
2535    /// The expression being aliased.
2536    pub this: Expression,
2537    /// The alias name (required for simple aliases, optional when only column aliases provided)
2538    pub alias: Identifier,
2539    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
2540    #[serde(default)]
2541    pub column_aliases: Vec<Identifier>,
2542    /// Comments that appeared between the expression and AS keyword
2543    #[serde(default)]
2544    pub pre_alias_comments: Vec<String>,
2545    /// Trailing comments that appeared after the alias
2546    #[serde(default)]
2547    pub trailing_comments: Vec<String>,
2548}
2549
2550impl Alias {
2551    /// Create a simple alias
2552    pub fn new(this: Expression, alias: Identifier) -> Self {
2553        Self {
2554            this,
2555            alias,
2556            column_aliases: Vec::new(),
2557            pre_alias_comments: Vec::new(),
2558            trailing_comments: Vec::new(),
2559        }
2560    }
2561
2562    /// Create an alias with column aliases only (no table alias name)
2563    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
2564        Self {
2565            this,
2566            alias: Identifier::empty(),
2567            column_aliases,
2568            pre_alias_comments: Vec::new(),
2569            trailing_comments: Vec::new(),
2570        }
2571    }
2572}
2573
2574/// Represent a type cast expression.
2575///
2576/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
2577/// shorthand `expr::type`. Also used as the payload for `TryCast` and
2578/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
2579/// CONVERSION ERROR (Oracle) clauses.
2580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2581#[cfg_attr(feature = "bindings", derive(TS))]
2582pub struct Cast {
2583    /// The expression being cast.
2584    pub this: Expression,
2585    /// The target data type.
2586    pub to: DataType,
2587    #[serde(default)]
2588    pub trailing_comments: Vec<String>,
2589    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
2590    #[serde(default)]
2591    pub double_colon_syntax: bool,
2592    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
2593    #[serde(skip_serializing_if = "Option::is_none", default)]
2594    pub format: Option<Box<Expression>>,
2595    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
2596    #[serde(skip_serializing_if = "Option::is_none", default)]
2597    pub default: Option<Box<Expression>>,
2598}
2599
2600///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
2601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2602#[cfg_attr(feature = "bindings", derive(TS))]
2603pub struct CollationExpr {
2604    pub this: Expression,
2605    pub collation: String,
2606    /// True if the collation was single-quoted in the original SQL (string literal)
2607    #[serde(default)]
2608    pub quoted: bool,
2609    /// True if the collation was double-quoted in the original SQL (identifier)
2610    #[serde(default)]
2611    pub double_quoted: bool,
2612}
2613
2614/// Represent a CASE expression (both simple and searched forms).
2615///
2616/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
2617/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
2618/// Each entry in `whens` is a `(condition, result)` pair.
2619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2620#[cfg_attr(feature = "bindings", derive(TS))]
2621pub struct Case {
2622    /// The operand for simple CASE, or `None` for searched CASE.
2623    pub operand: Option<Expression>,
2624    /// Pairs of (WHEN condition, THEN result).
2625    pub whens: Vec<(Expression, Expression)>,
2626    /// Optional ELSE result.
2627    pub else_: Option<Expression>,
2628    /// Comments from the CASE keyword (emitted after END)
2629    #[serde(default)]
2630    #[serde(skip_serializing_if = "Vec::is_empty")]
2631    pub comments: Vec<String>,
2632}
2633
2634/// Represent a binary operation (two operands separated by an operator).
2635///
2636/// This is the shared payload struct for all binary operator variants in the
2637/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
2638/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
2639/// bitwise, and dialect-specific operators. Comment fields enable round-trip
2640/// preservation of inline comments around operators.
2641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2642#[cfg_attr(feature = "bindings", derive(TS))]
2643pub struct BinaryOp {
2644    pub left: Expression,
2645    pub right: Expression,
2646    /// Comments after the left operand (before the operator)
2647    #[serde(default)]
2648    pub left_comments: Vec<String>,
2649    /// Comments after the operator (before the right operand)
2650    #[serde(default)]
2651    pub operator_comments: Vec<String>,
2652    /// Comments after the right operand
2653    #[serde(default)]
2654    pub trailing_comments: Vec<String>,
2655}
2656
2657impl BinaryOp {
2658    pub fn new(left: Expression, right: Expression) -> Self {
2659        Self {
2660            left,
2661            right,
2662            left_comments: Vec::new(),
2663            operator_comments: Vec::new(),
2664            trailing_comments: Vec::new(),
2665        }
2666    }
2667}
2668
2669/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
2670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2671#[cfg_attr(feature = "bindings", derive(TS))]
2672pub struct LikeOp {
2673    pub left: Expression,
2674    pub right: Expression,
2675    /// ESCAPE character/expression
2676    #[serde(default)]
2677    pub escape: Option<Expression>,
2678    /// Quantifier: ANY, ALL, or SOME
2679    #[serde(default)]
2680    pub quantifier: Option<String>,
2681}
2682
2683impl LikeOp {
2684    pub fn new(left: Expression, right: Expression) -> Self {
2685        Self {
2686            left,
2687            right,
2688            escape: None,
2689            quantifier: None,
2690        }
2691    }
2692
2693    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
2694        Self {
2695            left,
2696            right,
2697            escape: Some(escape),
2698            quantifier: None,
2699        }
2700    }
2701}
2702
2703/// Represent a unary operation (single operand with a prefix operator).
2704///
2705/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
2706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2707#[cfg_attr(feature = "bindings", derive(TS))]
2708pub struct UnaryOp {
2709    /// The operand expression.
2710    pub this: Expression,
2711}
2712
2713impl UnaryOp {
2714    pub fn new(this: Expression) -> Self {
2715        Self { this }
2716    }
2717}
2718
2719/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
2720///
2721/// Either `expressions` (a value list) or `query` (a subquery) is populated,
2722/// but not both. When `not` is true, the predicate is `NOT IN`.
2723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2724#[cfg_attr(feature = "bindings", derive(TS))]
2725pub struct In {
2726    /// The expression being tested.
2727    pub this: Expression,
2728    /// The value list (mutually exclusive with `query`).
2729    pub expressions: Vec<Expression>,
2730    /// A subquery (mutually exclusive with `expressions`).
2731    pub query: Option<Expression>,
2732    /// Whether this is NOT IN.
2733    pub not: bool,
2734    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2735    pub global: bool,
2736    /// BigQuery: IN UNNEST(expr)
2737    #[serde(default, skip_serializing_if = "Option::is_none")]
2738    pub unnest: Option<Box<Expression>>,
2739    /// Whether the right side is a bare field reference (no parentheses).
2740    /// Matches Python sqlglot's `field` attribute on `In` expression.
2741    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
2742    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2743    pub is_field: bool,
2744}
2745
2746/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
2747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2748#[cfg_attr(feature = "bindings", derive(TS))]
2749pub struct Between {
2750    /// The expression being tested.
2751    pub this: Expression,
2752    /// The lower bound.
2753    pub low: Expression,
2754    /// The upper bound.
2755    pub high: Expression,
2756    /// Whether this is NOT BETWEEN.
2757    pub not: bool,
2758    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
2759    #[serde(default)]
2760    pub symmetric: Option<bool>,
2761}
2762
2763/// IS NULL predicate
2764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2765#[cfg_attr(feature = "bindings", derive(TS))]
2766pub struct IsNull {
2767    pub this: Expression,
2768    pub not: bool,
2769    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
2770    #[serde(default)]
2771    pub postfix_form: bool,
2772}
2773
2774/// IS TRUE / IS FALSE predicate
2775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2776#[cfg_attr(feature = "bindings", derive(TS))]
2777pub struct IsTrueFalse {
2778    pub this: Expression,
2779    pub not: bool,
2780}
2781
2782/// IS JSON predicate (SQL standard)
2783/// Checks if a value is valid JSON
2784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2785#[cfg_attr(feature = "bindings", derive(TS))]
2786pub struct IsJson {
2787    pub this: Expression,
2788    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
2789    pub json_type: Option<String>,
2790    /// Key uniqueness constraint
2791    pub unique_keys: Option<JsonUniqueKeys>,
2792    /// Whether IS NOT JSON
2793    pub negated: bool,
2794}
2795
2796/// JSON unique keys constraint variants
2797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2798#[cfg_attr(feature = "bindings", derive(TS))]
2799pub enum JsonUniqueKeys {
2800    /// WITH UNIQUE KEYS
2801    With,
2802    /// WITHOUT UNIQUE KEYS
2803    Without,
2804    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
2805    Shorthand,
2806}
2807
2808/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
2809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2810#[cfg_attr(feature = "bindings", derive(TS))]
2811pub struct Exists {
2812    /// The subquery expression.
2813    pub this: Expression,
2814    /// Whether this is NOT EXISTS.
2815    pub not: bool,
2816}
2817
2818/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
2819///
2820/// This is the generic function node. Well-known aggregates, window functions,
2821/// and built-in functions each have their own dedicated `Expression` variants
2822/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
2823/// not recognize as built-ins are represented with this struct.
2824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2825#[cfg_attr(feature = "bindings", derive(TS))]
2826pub struct Function {
2827    /// The function name, as originally written (may be schema-qualified).
2828    pub name: String,
2829    /// Positional arguments to the function.
2830    pub args: Vec<Expression>,
2831    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
2832    pub distinct: bool,
2833    #[serde(default)]
2834    pub trailing_comments: Vec<String>,
2835    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
2836    #[serde(default)]
2837    pub use_bracket_syntax: bool,
2838    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
2839    #[serde(default)]
2840    pub no_parens: bool,
2841    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
2842    #[serde(default)]
2843    pub quoted: bool,
2844}
2845
2846impl Default for Function {
2847    fn default() -> Self {
2848        Self {
2849            name: String::new(),
2850            args: Vec::new(),
2851            distinct: false,
2852            trailing_comments: Vec::new(),
2853            use_bracket_syntax: false,
2854            no_parens: false,
2855            quoted: false,
2856        }
2857    }
2858}
2859
2860impl Function {
2861    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
2862        Self {
2863            name: name.into(),
2864            args,
2865            distinct: false,
2866            trailing_comments: Vec::new(),
2867            use_bracket_syntax: false,
2868            no_parens: false,
2869            quoted: false,
2870        }
2871    }
2872}
2873
2874/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
2875///
2876/// This struct is used for aggregate function calls that are not covered by
2877/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
2878/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
2879/// IGNORE NULLS / RESPECT NULLS modifiers.
2880#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2881#[cfg_attr(feature = "bindings", derive(TS))]
2882pub struct AggregateFunction {
2883    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
2884    pub name: String,
2885    /// Positional arguments.
2886    pub args: Vec<Expression>,
2887    /// Whether DISTINCT was specified.
2888    pub distinct: bool,
2889    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
2890    pub filter: Option<Expression>,
2891    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
2892    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2893    pub order_by: Vec<Ordered>,
2894    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
2895    #[serde(default, skip_serializing_if = "Option::is_none")]
2896    pub limit: Option<Box<Expression>>,
2897    /// IGNORE NULLS / RESPECT NULLS
2898    #[serde(default, skip_serializing_if = "Option::is_none")]
2899    pub ignore_nulls: Option<bool>,
2900}
2901
2902/// Represent a window function call with its OVER clause.
2903///
2904/// The inner `this` expression is typically a window-specific expression
2905/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
2906/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
2907/// frame specification.
2908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2909#[cfg_attr(feature = "bindings", derive(TS))]
2910pub struct WindowFunction {
2911    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
2912    pub this: Expression,
2913    /// The OVER clause defining the window partitioning, ordering, and frame.
2914    pub over: Over,
2915    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
2916    #[serde(default, skip_serializing_if = "Option::is_none")]
2917    pub keep: Option<Keep>,
2918}
2919
2920/// Oracle KEEP clause for aggregate functions
2921/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
2922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2923#[cfg_attr(feature = "bindings", derive(TS))]
2924pub struct Keep {
2925    /// true = FIRST, false = LAST
2926    pub first: bool,
2927    /// ORDER BY clause inside KEEP
2928    pub order_by: Vec<Ordered>,
2929}
2930
2931/// WITHIN GROUP clause (for ordered-set aggregate functions)
2932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2933#[cfg_attr(feature = "bindings", derive(TS))]
2934pub struct WithinGroup {
2935    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
2936    pub this: Expression,
2937    /// The ORDER BY clause within the group
2938    pub order_by: Vec<Ordered>,
2939}
2940
2941/// Represent the FROM clause of a SELECT statement.
2942///
2943/// Contains one or more table sources (tables, subqueries, table-valued
2944/// functions, etc.). Multiple entries represent comma-separated implicit joins.
2945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2946#[cfg_attr(feature = "bindings", derive(TS))]
2947pub struct From {
2948    /// The table source expressions.
2949    pub expressions: Vec<Expression>,
2950}
2951
2952/// Represent a JOIN clause between two table sources.
2953///
2954/// The join condition can be specified via `on` (ON predicate) or `using`
2955/// (USING column list), but not both. The `kind` field determines the join
2956/// type (INNER, LEFT, CROSS, etc.).
2957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2958#[cfg_attr(feature = "bindings", derive(TS))]
2959pub struct Join {
2960    /// The right-hand table expression being joined.
2961    pub this: Expression,
2962    /// The ON condition (mutually exclusive with `using`).
2963    pub on: Option<Expression>,
2964    /// The USING column list (mutually exclusive with `on`).
2965    pub using: Vec<Identifier>,
2966    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
2967    pub kind: JoinKind,
2968    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
2969    pub use_inner_keyword: bool,
2970    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
2971    pub use_outer_keyword: bool,
2972    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
2973    pub deferred_condition: bool,
2974    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
2975    #[serde(default, skip_serializing_if = "Option::is_none")]
2976    pub join_hint: Option<String>,
2977    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
2978    #[serde(default, skip_serializing_if = "Option::is_none")]
2979    pub match_condition: Option<Expression>,
2980    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
2981    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2982    pub pivots: Vec<Expression>,
2983    /// Comments collected from between join-kind keywords (e.g., INNER /* comment */ JOIN)
2984    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2985    pub comments: Vec<String>,
2986    /// Nesting group identifier for nested join pretty-printing.
2987    /// Joins in the same group were parsed together; group boundaries come from
2988    /// deferred condition resolution phases.
2989    #[serde(default)]
2990    pub nesting_group: usize,
2991    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
2992    #[serde(default)]
2993    pub directed: bool,
2994}
2995
2996/// Enumerate all supported SQL join types.
2997///
2998/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
2999/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3000/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3001/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3002#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3003#[cfg_attr(feature = "bindings", derive(TS))]
3004pub enum JoinKind {
3005    Inner,
3006    Left,
3007    Right,
3008    Full,
3009    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3010    Cross,
3011    Natural,
3012    NaturalLeft,
3013    NaturalRight,
3014    NaturalFull,
3015    Semi,
3016    Anti,
3017    // Directional SEMI/ANTI joins
3018    LeftSemi,
3019    LeftAnti,
3020    RightSemi,
3021    RightAnti,
3022    // SQL Server specific
3023    CrossApply,
3024    OuterApply,
3025    // Time-series specific
3026    AsOf,
3027    AsOfLeft,
3028    AsOfRight,
3029    // Lateral join
3030    Lateral,
3031    LeftLateral,
3032    // MySQL specific
3033    Straight,
3034    // Implicit join (comma-separated tables: FROM a, b)
3035    Implicit,
3036    // ClickHouse ARRAY JOIN
3037    Array,
3038    LeftArray,
3039    // ClickHouse PASTE JOIN (positional join)
3040    Paste,
3041}
3042
3043impl Default for JoinKind {
3044    fn default() -> Self {
3045        JoinKind::Inner
3046    }
3047}
3048
3049/// Parenthesized table expression with joins
3050/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3052#[cfg_attr(feature = "bindings", derive(TS))]
3053pub struct JoinedTable {
3054    /// The left-hand side table expression
3055    pub left: Expression,
3056    /// The joins applied to the left table
3057    pub joins: Vec<Join>,
3058    /// LATERAL VIEW clauses (Hive/Spark)
3059    pub lateral_views: Vec<LateralView>,
3060    /// Optional alias for the joined table expression
3061    pub alias: Option<Identifier>,
3062}
3063
3064/// Represent a WHERE clause containing a boolean filter predicate.
3065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3066#[cfg_attr(feature = "bindings", derive(TS))]
3067pub struct Where {
3068    /// The filter predicate expression.
3069    pub this: Expression,
3070}
3071
3072/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3073///
3074/// The `expressions` list may contain plain columns, ordinal positions,
3075/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3077#[cfg_attr(feature = "bindings", derive(TS))]
3078pub struct GroupBy {
3079    /// The grouping expressions.
3080    pub expressions: Vec<Expression>,
3081    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3082    #[serde(default)]
3083    pub all: Option<bool>,
3084    /// ClickHouse: WITH TOTALS modifier
3085    #[serde(default)]
3086    pub totals: bool,
3087    /// Leading comments that appeared before the GROUP BY keyword
3088    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3089    pub comments: Vec<String>,
3090}
3091
3092/// Represent a HAVING clause containing a predicate over aggregate results.
3093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3094#[cfg_attr(feature = "bindings", derive(TS))]
3095pub struct Having {
3096    /// The filter predicate, typically involving aggregate functions.
3097    pub this: Expression,
3098    /// Leading comments that appeared before the HAVING keyword
3099    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3100    pub comments: Vec<String>,
3101}
3102
3103/// Represent an ORDER BY clause containing one or more sort specifications.
3104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3105#[cfg_attr(feature = "bindings", derive(TS))]
3106pub struct OrderBy {
3107    /// The sort specifications, each with direction and null ordering.
3108    pub expressions: Vec<Ordered>,
3109    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3110    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3111    pub siblings: bool,
3112    /// Leading comments that appeared before the ORDER BY keyword
3113    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3114    pub comments: Vec<String>,
3115}
3116
3117/// Represent an expression with sort direction and null ordering.
3118///
3119/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3120/// When `desc` is false the sort is ascending. The `nulls_first` field
3121/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3122/// (database default).
3123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3124#[cfg_attr(feature = "bindings", derive(TS))]
3125pub struct Ordered {
3126    /// The expression to sort by.
3127    pub this: Expression,
3128    /// Whether the sort direction is descending (true) or ascending (false).
3129    pub desc: bool,
3130    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3131    pub nulls_first: Option<bool>,
3132    /// Whether ASC was explicitly written (not just implied)
3133    #[serde(default)]
3134    pub explicit_asc: bool,
3135    /// ClickHouse WITH FILL clause
3136    #[serde(default, skip_serializing_if = "Option::is_none")]
3137    pub with_fill: Option<Box<WithFill>>,
3138}
3139
3140impl Ordered {
3141    pub fn asc(expr: Expression) -> Self {
3142        Self {
3143            this: expr,
3144            desc: false,
3145            nulls_first: None,
3146            explicit_asc: false,
3147            with_fill: None,
3148        }
3149    }
3150
3151    pub fn desc(expr: Expression) -> Self {
3152        Self {
3153            this: expr,
3154            desc: true,
3155            nulls_first: None,
3156            explicit_asc: false,
3157            with_fill: None,
3158        }
3159    }
3160}
3161
3162/// DISTRIBUTE BY clause (Hive/Spark)
3163/// Controls how rows are distributed across reducers
3164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3165#[cfg_attr(feature = "bindings", derive(TS))]
3166#[cfg_attr(feature = "bindings", ts(export))]
3167pub struct DistributeBy {
3168    pub expressions: Vec<Expression>,
3169}
3170
3171/// CLUSTER BY clause (Hive/Spark)
3172/// Combines DISTRIBUTE BY and SORT BY on the same columns
3173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3174#[cfg_attr(feature = "bindings", derive(TS))]
3175#[cfg_attr(feature = "bindings", ts(export))]
3176pub struct ClusterBy {
3177    pub expressions: Vec<Ordered>,
3178}
3179
3180/// SORT BY clause (Hive/Spark)
3181/// Sorts data within each reducer (local sort, not global)
3182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3183#[cfg_attr(feature = "bindings", derive(TS))]
3184#[cfg_attr(feature = "bindings", ts(export))]
3185pub struct SortBy {
3186    pub expressions: Vec<Ordered>,
3187}
3188
3189/// LATERAL VIEW clause (Hive/Spark)
3190/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3192#[cfg_attr(feature = "bindings", derive(TS))]
3193#[cfg_attr(feature = "bindings", ts(export))]
3194pub struct LateralView {
3195    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3196    pub this: Expression,
3197    /// Table alias for the generated table
3198    pub table_alias: Option<Identifier>,
3199    /// Column aliases for the generated columns
3200    pub column_aliases: Vec<Identifier>,
3201    /// OUTER keyword - preserve nulls when input is empty/null
3202    pub outer: bool,
3203}
3204
3205/// Query hint
3206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3207#[cfg_attr(feature = "bindings", derive(TS))]
3208#[cfg_attr(feature = "bindings", ts(export))]
3209pub struct Hint {
3210    pub expressions: Vec<HintExpression>,
3211}
3212
3213/// Individual hint expression
3214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3215#[cfg_attr(feature = "bindings", derive(TS))]
3216#[cfg_attr(feature = "bindings", ts(export))]
3217pub enum HintExpression {
3218    /// Function-style hint: USE_HASH(table)
3219    Function { name: String, args: Vec<Expression> },
3220    /// Simple identifier hint: PARALLEL
3221    Identifier(String),
3222    /// Raw hint text (unparsed)
3223    Raw(String),
3224}
3225
3226/// Pseudocolumn type
3227#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3228#[cfg_attr(feature = "bindings", derive(TS))]
3229#[cfg_attr(feature = "bindings", ts(export))]
3230pub enum PseudocolumnType {
3231    Rownum,      // Oracle ROWNUM
3232    Rowid,       // Oracle ROWID
3233    Level,       // Oracle LEVEL (for CONNECT BY)
3234    Sysdate,     // Oracle SYSDATE
3235    ObjectId,    // Oracle OBJECT_ID
3236    ObjectValue, // Oracle OBJECT_VALUE
3237}
3238
3239impl PseudocolumnType {
3240    pub fn as_str(&self) -> &'static str {
3241        match self {
3242            PseudocolumnType::Rownum => "ROWNUM",
3243            PseudocolumnType::Rowid => "ROWID",
3244            PseudocolumnType::Level => "LEVEL",
3245            PseudocolumnType::Sysdate => "SYSDATE",
3246            PseudocolumnType::ObjectId => "OBJECT_ID",
3247            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3248        }
3249    }
3250
3251    pub fn from_str(s: &str) -> Option<Self> {
3252        match s.to_uppercase().as_str() {
3253            "ROWNUM" => Some(PseudocolumnType::Rownum),
3254            "ROWID" => Some(PseudocolumnType::Rowid),
3255            "LEVEL" => Some(PseudocolumnType::Level),
3256            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3257            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3258            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3259            _ => None,
3260        }
3261    }
3262}
3263
3264/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3265/// These are special identifiers that should not be quoted
3266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3267#[cfg_attr(feature = "bindings", derive(TS))]
3268#[cfg_attr(feature = "bindings", ts(export))]
3269pub struct Pseudocolumn {
3270    pub kind: PseudocolumnType,
3271}
3272
3273impl Pseudocolumn {
3274    pub fn rownum() -> Self {
3275        Self {
3276            kind: PseudocolumnType::Rownum,
3277        }
3278    }
3279
3280    pub fn rowid() -> Self {
3281        Self {
3282            kind: PseudocolumnType::Rowid,
3283        }
3284    }
3285
3286    pub fn level() -> Self {
3287        Self {
3288            kind: PseudocolumnType::Level,
3289        }
3290    }
3291}
3292
3293/// Oracle CONNECT BY clause for hierarchical queries
3294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3295#[cfg_attr(feature = "bindings", derive(TS))]
3296#[cfg_attr(feature = "bindings", ts(export))]
3297pub struct Connect {
3298    /// START WITH condition (optional, can come before or after CONNECT BY)
3299    pub start: Option<Expression>,
3300    /// CONNECT BY condition (required, contains PRIOR references)
3301    pub connect: Expression,
3302    /// NOCYCLE keyword to prevent infinite loops
3303    pub nocycle: bool,
3304}
3305
3306/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3308#[cfg_attr(feature = "bindings", derive(TS))]
3309#[cfg_attr(feature = "bindings", ts(export))]
3310pub struct Prior {
3311    pub this: Expression,
3312}
3313
3314/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3316#[cfg_attr(feature = "bindings", derive(TS))]
3317#[cfg_attr(feature = "bindings", ts(export))]
3318pub struct ConnectByRoot {
3319    pub this: Expression,
3320}
3321
3322/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3324#[cfg_attr(feature = "bindings", derive(TS))]
3325#[cfg_attr(feature = "bindings", ts(export))]
3326pub struct MatchRecognize {
3327    /// Source table/expression
3328    pub this: Option<Box<Expression>>,
3329    /// PARTITION BY expressions
3330    pub partition_by: Option<Vec<Expression>>,
3331    /// ORDER BY expressions
3332    pub order_by: Option<Vec<Ordered>>,
3333    /// MEASURES definitions
3334    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3335    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3336    pub rows: Option<MatchRecognizeRows>,
3337    /// AFTER MATCH SKIP behavior
3338    pub after: Option<MatchRecognizeAfter>,
3339    /// PATTERN definition (stored as raw string for complex regex patterns)
3340    pub pattern: Option<String>,
3341    /// DEFINE clauses (pattern variable definitions)
3342    pub define: Option<Vec<(Identifier, Expression)>>,
3343    /// Optional alias for the result
3344    pub alias: Option<Identifier>,
3345    /// Whether AS keyword was explicitly present before alias
3346    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3347    pub alias_explicit_as: bool,
3348}
3349
3350/// MEASURES expression with optional RUNNING/FINAL semantics
3351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3352#[cfg_attr(feature = "bindings", derive(TS))]
3353#[cfg_attr(feature = "bindings", ts(export))]
3354pub struct MatchRecognizeMeasure {
3355    /// The measure expression
3356    pub this: Expression,
3357    /// RUNNING or FINAL semantics (Snowflake-specific)
3358    pub window_frame: Option<MatchRecognizeSemantics>,
3359}
3360
3361/// Semantics for MEASURES in MATCH_RECOGNIZE
3362#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3363#[cfg_attr(feature = "bindings", derive(TS))]
3364#[cfg_attr(feature = "bindings", ts(export))]
3365pub enum MatchRecognizeSemantics {
3366    Running,
3367    Final,
3368}
3369
3370/// Row output semantics for MATCH_RECOGNIZE
3371#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3372#[cfg_attr(feature = "bindings", derive(TS))]
3373#[cfg_attr(feature = "bindings", ts(export))]
3374pub enum MatchRecognizeRows {
3375    OneRowPerMatch,
3376    AllRowsPerMatch,
3377    AllRowsPerMatchShowEmptyMatches,
3378    AllRowsPerMatchOmitEmptyMatches,
3379    AllRowsPerMatchWithUnmatchedRows,
3380}
3381
3382/// AFTER MATCH SKIP behavior
3383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3384#[cfg_attr(feature = "bindings", derive(TS))]
3385#[cfg_attr(feature = "bindings", ts(export))]
3386pub enum MatchRecognizeAfter {
3387    PastLastRow,
3388    ToNextRow,
3389    ToFirst(Identifier),
3390    ToLast(Identifier),
3391}
3392
3393/// Represent a LIMIT clause that restricts the number of returned rows.
3394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3395#[cfg_attr(feature = "bindings", derive(TS))]
3396pub struct Limit {
3397    /// The limit count expression.
3398    pub this: Expression,
3399    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3400    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3401    pub percent: bool,
3402    /// Comments from before the LIMIT keyword (emitted after the limit value)
3403    #[serde(default)]
3404    #[serde(skip_serializing_if = "Vec::is_empty")]
3405    pub comments: Vec<String>,
3406}
3407
3408/// OFFSET clause
3409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3410#[cfg_attr(feature = "bindings", derive(TS))]
3411pub struct Offset {
3412    pub this: Expression,
3413    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3414    #[serde(skip_serializing_if = "Option::is_none", default)]
3415    pub rows: Option<bool>,
3416}
3417
3418/// TOP clause (SQL Server)
3419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3420#[cfg_attr(feature = "bindings", derive(TS))]
3421pub struct Top {
3422    pub this: Expression,
3423    pub percent: bool,
3424    pub with_ties: bool,
3425    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3426    #[serde(default)]
3427    pub parenthesized: bool,
3428}
3429
3430/// FETCH FIRST/NEXT clause (SQL standard)
3431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3432#[cfg_attr(feature = "bindings", derive(TS))]
3433pub struct Fetch {
3434    /// FIRST or NEXT
3435    pub direction: String,
3436    /// Count expression (optional)
3437    pub count: Option<Expression>,
3438    /// PERCENT modifier
3439    pub percent: bool,
3440    /// ROWS or ROW keyword present
3441    pub rows: bool,
3442    /// WITH TIES modifier
3443    pub with_ties: bool,
3444}
3445
3446/// Represent a QUALIFY clause for filtering on window function results.
3447///
3448/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3449/// typically references a window function (e.g.
3450/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3452#[cfg_attr(feature = "bindings", derive(TS))]
3453pub struct Qualify {
3454    /// The filter predicate over window function results.
3455    pub this: Expression,
3456}
3457
3458/// SAMPLE / TABLESAMPLE clause
3459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3460#[cfg_attr(feature = "bindings", derive(TS))]
3461pub struct Sample {
3462    pub method: SampleMethod,
3463    pub size: Expression,
3464    pub seed: Option<Expression>,
3465    /// ClickHouse OFFSET expression after SAMPLE size
3466    #[serde(default)]
3467    pub offset: Option<Expression>,
3468    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3469    pub unit_after_size: bool,
3470    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3471    #[serde(default)]
3472    pub use_sample_keyword: bool,
3473    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3474    #[serde(default)]
3475    pub explicit_method: bool,
3476    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3477    #[serde(default)]
3478    pub method_before_size: bool,
3479    /// Whether SEED keyword was used (true) or REPEATABLE (false)
3480    #[serde(default)]
3481    pub use_seed_keyword: bool,
3482    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
3483    pub bucket_numerator: Option<Box<Expression>>,
3484    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
3485    pub bucket_denominator: Option<Box<Expression>>,
3486    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
3487    pub bucket_field: Option<Box<Expression>>,
3488    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
3489    #[serde(default)]
3490    pub is_using_sample: bool,
3491    /// Whether the unit was explicitly PERCENT (vs ROWS)
3492    #[serde(default)]
3493    pub is_percent: bool,
3494    /// Whether to suppress method output (for cross-dialect transpilation)
3495    #[serde(default)]
3496    pub suppress_method_output: bool,
3497}
3498
3499/// Sample method
3500#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3501#[cfg_attr(feature = "bindings", derive(TS))]
3502pub enum SampleMethod {
3503    Bernoulli,
3504    System,
3505    Block,
3506    Row,
3507    Percent,
3508    /// Hive bucket sampling
3509    Bucket,
3510    /// DuckDB reservoir sampling
3511    Reservoir,
3512}
3513
3514/// Named window definition (WINDOW w AS (...))
3515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3516#[cfg_attr(feature = "bindings", derive(TS))]
3517pub struct NamedWindow {
3518    pub name: Identifier,
3519    pub spec: Over,
3520}
3521
3522/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
3523///
3524/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
3525/// that reference themselves. Each CTE is defined in the `ctes` vector and
3526/// can be referenced by name in subsequent CTEs and in the main query body.
3527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3528#[cfg_attr(feature = "bindings", derive(TS))]
3529pub struct With {
3530    /// The list of CTE definitions, in order.
3531    pub ctes: Vec<Cte>,
3532    /// Whether the WITH RECURSIVE keyword was used.
3533    pub recursive: bool,
3534    /// Leading comments before the statement
3535    #[serde(default)]
3536    pub leading_comments: Vec<String>,
3537    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
3538    #[serde(default, skip_serializing_if = "Option::is_none")]
3539    pub search: Option<Box<Expression>>,
3540}
3541
3542/// Represent a single Common Table Expression definition.
3543///
3544/// A CTE has a name (`alias`), an optional column list, and a body query.
3545/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
3546/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
3547/// the expression comes before the alias (`alias_first`).
3548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3549#[cfg_attr(feature = "bindings", derive(TS))]
3550pub struct Cte {
3551    /// The CTE name.
3552    pub alias: Identifier,
3553    /// The CTE body (typically a SELECT, UNION, etc.).
3554    pub this: Expression,
3555    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
3556    pub columns: Vec<Identifier>,
3557    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
3558    pub materialized: Option<bool>,
3559    /// USING KEY (columns) for DuckDB recursive CTEs
3560    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3561    pub key_expressions: Vec<Identifier>,
3562    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
3563    #[serde(default)]
3564    pub alias_first: bool,
3565    /// Comments associated with this CTE (placed after alias name, before AS)
3566    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3567    pub comments: Vec<String>,
3568}
3569
3570/// Window specification
3571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3572#[cfg_attr(feature = "bindings", derive(TS))]
3573pub struct WindowSpec {
3574    pub partition_by: Vec<Expression>,
3575    pub order_by: Vec<Ordered>,
3576    pub frame: Option<WindowFrame>,
3577}
3578
3579/// OVER clause
3580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3581#[cfg_attr(feature = "bindings", derive(TS))]
3582pub struct Over {
3583    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
3584    pub window_name: Option<Identifier>,
3585    pub partition_by: Vec<Expression>,
3586    pub order_by: Vec<Ordered>,
3587    pub frame: Option<WindowFrame>,
3588    pub alias: Option<Identifier>,
3589}
3590
3591/// Window frame
3592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3593#[cfg_attr(feature = "bindings", derive(TS))]
3594pub struct WindowFrame {
3595    pub kind: WindowFrameKind,
3596    pub start: WindowFrameBound,
3597    pub end: Option<WindowFrameBound>,
3598    pub exclude: Option<WindowFrameExclude>,
3599    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
3600    #[serde(default, skip_serializing_if = "Option::is_none")]
3601    pub kind_text: Option<String>,
3602    /// Original text of the start bound side keyword (e.g. "preceding")
3603    #[serde(default, skip_serializing_if = "Option::is_none")]
3604    pub start_side_text: Option<String>,
3605    /// Original text of the end bound side keyword
3606    #[serde(default, skip_serializing_if = "Option::is_none")]
3607    pub end_side_text: Option<String>,
3608}
3609
3610#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3611#[cfg_attr(feature = "bindings", derive(TS))]
3612pub enum WindowFrameKind {
3613    Rows,
3614    Range,
3615    Groups,
3616}
3617
3618/// EXCLUDE clause for window frames
3619#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3620#[cfg_attr(feature = "bindings", derive(TS))]
3621pub enum WindowFrameExclude {
3622    CurrentRow,
3623    Group,
3624    Ties,
3625    NoOthers,
3626}
3627
3628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3629#[cfg_attr(feature = "bindings", derive(TS))]
3630pub enum WindowFrameBound {
3631    CurrentRow,
3632    UnboundedPreceding,
3633    UnboundedFollowing,
3634    Preceding(Box<Expression>),
3635    Following(Box<Expression>),
3636    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
3637    BarePreceding,
3638    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
3639    BareFollowing,
3640    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
3641    Value(Box<Expression>),
3642}
3643
3644/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
3645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3646#[cfg_attr(feature = "bindings", derive(TS))]
3647pub struct StructField {
3648    pub name: String,
3649    pub data_type: DataType,
3650    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3651    pub options: Vec<Expression>,
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub comment: Option<String>,
3654}
3655
3656impl StructField {
3657    /// Create a new struct field without options
3658    pub fn new(name: String, data_type: DataType) -> Self {
3659        Self {
3660            name,
3661            data_type,
3662            options: Vec::new(),
3663            comment: None,
3664        }
3665    }
3666
3667    /// Create a new struct field with options
3668    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
3669        Self {
3670            name,
3671            data_type,
3672            options,
3673            comment: None,
3674        }
3675    }
3676
3677    /// Create a new struct field with options and comment
3678    pub fn with_options_and_comment(
3679        name: String,
3680        data_type: DataType,
3681        options: Vec<Expression>,
3682        comment: Option<String>,
3683    ) -> Self {
3684        Self {
3685            name,
3686            data_type,
3687            options,
3688            comment,
3689        }
3690    }
3691}
3692
3693/// Enumerate all SQL data types recognized by the parser.
3694///
3695/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
3696/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
3697/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
3698///
3699/// This enum is used in CAST expressions, column definitions, function return
3700/// types, and anywhere a data type specification appears in SQL.
3701///
3702/// Types that do not match any known variant fall through to `Custom { name }`,
3703/// preserving the original type name for round-trip fidelity.
3704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3705#[cfg_attr(feature = "bindings", derive(TS))]
3706#[serde(tag = "data_type", rename_all = "snake_case")]
3707pub enum DataType {
3708    // Numeric
3709    Boolean,
3710    TinyInt {
3711        length: Option<u32>,
3712    },
3713    SmallInt {
3714        length: Option<u32>,
3715    },
3716    /// Int type with optional length. `integer_spelling` indicates whether the original
3717    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
3718    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
3719    Int {
3720        length: Option<u32>,
3721        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3722        integer_spelling: bool,
3723    },
3724    BigInt {
3725        length: Option<u32>,
3726    },
3727    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
3728    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
3729    /// preserve the original spelling.
3730    Float {
3731        precision: Option<u32>,
3732        scale: Option<u32>,
3733        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3734        real_spelling: bool,
3735    },
3736    Double {
3737        precision: Option<u32>,
3738        scale: Option<u32>,
3739    },
3740    Decimal {
3741        precision: Option<u32>,
3742        scale: Option<u32>,
3743    },
3744
3745    // String
3746    Char {
3747        length: Option<u32>,
3748    },
3749    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
3750    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
3751    VarChar {
3752        length: Option<u32>,
3753        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3754        parenthesized_length: bool,
3755    },
3756    /// String type with optional max length (BigQuery STRING(n))
3757    String {
3758        length: Option<u32>,
3759    },
3760    Text,
3761    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
3762    #[serde(alias = "TextWithLength")]
3763    TextWithLength {
3764        length: u32,
3765    },
3766
3767    // Binary
3768    Binary {
3769        length: Option<u32>,
3770    },
3771    VarBinary {
3772        length: Option<u32>,
3773    },
3774    Blob,
3775
3776    // Bit
3777    Bit {
3778        length: Option<u32>,
3779    },
3780    VarBit {
3781        length: Option<u32>,
3782    },
3783
3784    // Date/Time
3785    Date,
3786    Time {
3787        precision: Option<u32>,
3788        #[serde(default)]
3789        timezone: bool,
3790    },
3791    Timestamp {
3792        precision: Option<u32>,
3793        timezone: bool,
3794    },
3795    Interval {
3796        unit: Option<String>,
3797        /// For range intervals like INTERVAL DAY TO HOUR
3798        #[serde(default, skip_serializing_if = "Option::is_none")]
3799        to: Option<String>,
3800    },
3801
3802    // JSON
3803    Json,
3804    JsonB,
3805
3806    // UUID
3807    Uuid,
3808
3809    // Array
3810    Array {
3811        element_type: Box<DataType>,
3812        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3813        #[serde(default, skip_serializing_if = "Option::is_none")]
3814        dimension: Option<u32>,
3815    },
3816
3817    /// List type (Materialize): INT LIST, TEXT LIST LIST
3818    /// Uses postfix LIST syntax instead of ARRAY<T>
3819    List {
3820        element_type: Box<DataType>,
3821    },
3822
3823    // Struct/Map
3824    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3825    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3826    Struct {
3827        fields: Vec<StructField>,
3828        nested: bool,
3829    },
3830    Map {
3831        key_type: Box<DataType>,
3832        value_type: Box<DataType>,
3833    },
3834
3835    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3836    Enum {
3837        values: Vec<String>,
3838        #[serde(default, skip_serializing_if = "Vec::is_empty")]
3839        assignments: Vec<Option<String>>,
3840    },
3841
3842    // Set type (MySQL): SET('a', 'b', 'c')
3843    Set {
3844        values: Vec<String>,
3845    },
3846
3847    // Union type (DuckDB): UNION(num INT, str TEXT)
3848    Union {
3849        fields: Vec<(String, DataType)>,
3850    },
3851
3852    // Vector (Snowflake / SingleStore)
3853    Vector {
3854        #[serde(default)]
3855        element_type: Option<Box<DataType>>,
3856        dimension: Option<u32>,
3857    },
3858
3859    // Object (Snowflake structured type)
3860    // fields: Vec of (field_name, field_type, not_null)
3861    Object {
3862        fields: Vec<(String, DataType, bool)>,
3863        modifier: Option<String>,
3864    },
3865
3866    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
3867    Nullable {
3868        inner: Box<DataType>,
3869    },
3870
3871    // Custom/User-defined
3872    Custom {
3873        name: String,
3874    },
3875
3876    // Spatial types
3877    Geometry {
3878        subtype: Option<String>,
3879        srid: Option<u32>,
3880    },
3881    Geography {
3882        subtype: Option<String>,
3883        srid: Option<u32>,
3884    },
3885
3886    // Character Set (for CONVERT USING in MySQL)
3887    // Renders as CHAR CHARACTER SET {name} in cast target
3888    CharacterSet {
3889        name: String,
3890    },
3891
3892    // Unknown
3893    Unknown,
3894}
3895
3896/// Array expression
3897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3898#[cfg_attr(feature = "bindings", derive(TS))]
3899#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3900pub struct Array {
3901    pub expressions: Vec<Expression>,
3902}
3903
3904/// Struct expression
3905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3906#[cfg_attr(feature = "bindings", derive(TS))]
3907pub struct Struct {
3908    pub fields: Vec<(Option<String>, Expression)>,
3909}
3910
3911/// Tuple expression
3912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3913#[cfg_attr(feature = "bindings", derive(TS))]
3914pub struct Tuple {
3915    pub expressions: Vec<Expression>,
3916}
3917
3918/// Interval expression
3919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3920#[cfg_attr(feature = "bindings", derive(TS))]
3921pub struct Interval {
3922    /// The value expression (e.g., '1', 5, column_ref)
3923    pub this: Option<Expression>,
3924    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3925    pub unit: Option<IntervalUnitSpec>,
3926}
3927
3928/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3930#[cfg_attr(feature = "bindings", derive(TS))]
3931#[serde(tag = "type", rename_all = "snake_case")]
3932pub enum IntervalUnitSpec {
3933    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3934    Simple {
3935        unit: IntervalUnit,
3936        /// Whether to use plural form (e.g., DAYS vs DAY)
3937        use_plural: bool,
3938    },
3939    /// Interval span (e.g., HOUR TO SECOND)
3940    Span(IntervalSpan),
3941    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3942    /// The start and end can be expressions like function calls with precision
3943    ExprSpan(IntervalSpanExpr),
3944    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3945    Expr(Box<Expression>),
3946}
3947
3948/// Interval span for ranges like HOUR TO SECOND
3949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3950#[cfg_attr(feature = "bindings", derive(TS))]
3951pub struct IntervalSpan {
3952    /// Start unit (e.g., HOUR)
3953    pub this: IntervalUnit,
3954    /// End unit (e.g., SECOND)
3955    pub expression: IntervalUnit,
3956}
3957
3958/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3959/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3961#[cfg_attr(feature = "bindings", derive(TS))]
3962pub struct IntervalSpanExpr {
3963    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3964    pub this: Box<Expression>,
3965    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
3966    pub expression: Box<Expression>,
3967}
3968
3969#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3970#[cfg_attr(feature = "bindings", derive(TS))]
3971pub enum IntervalUnit {
3972    Year,
3973    Quarter,
3974    Month,
3975    Week,
3976    Day,
3977    Hour,
3978    Minute,
3979    Second,
3980    Millisecond,
3981    Microsecond,
3982    Nanosecond,
3983}
3984
3985/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
3986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3987#[cfg_attr(feature = "bindings", derive(TS))]
3988pub struct Command {
3989    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
3990    pub this: String,
3991}
3992
3993/// EXEC/EXECUTE statement (TSQL stored procedure call)
3994/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
3995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3996#[cfg_attr(feature = "bindings", derive(TS))]
3997pub struct ExecuteStatement {
3998    /// The procedure name (can be qualified: schema.proc_name)
3999    pub this: Expression,
4000    /// Named parameters: @param=value pairs
4001    #[serde(default)]
4002    pub parameters: Vec<ExecuteParameter>,
4003}
4004
4005/// Named parameter in EXEC statement: @name=value
4006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4007#[cfg_attr(feature = "bindings", derive(TS))]
4008pub struct ExecuteParameter {
4009    /// Parameter name (including @)
4010    pub name: String,
4011    /// Parameter value
4012    pub value: Expression,
4013}
4014
4015/// KILL statement (MySQL/MariaDB)
4016/// KILL [CONNECTION | QUERY] <id>
4017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4018#[cfg_attr(feature = "bindings", derive(TS))]
4019pub struct Kill {
4020    /// The target (process ID or connection ID)
4021    pub this: Expression,
4022    /// Optional kind: "CONNECTION" or "QUERY"
4023    pub kind: Option<String>,
4024}
4025
4026/// Raw/unparsed SQL
4027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4028#[cfg_attr(feature = "bindings", derive(TS))]
4029pub struct Raw {
4030    pub sql: String,
4031}
4032
4033// ============================================================================
4034// Function expression types
4035// ============================================================================
4036
4037/// Generic unary function (takes a single argument)
4038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4039#[cfg_attr(feature = "bindings", derive(TS))]
4040pub struct UnaryFunc {
4041    pub this: Expression,
4042    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4043    #[serde(skip_serializing_if = "Option::is_none", default)]
4044    pub original_name: Option<String>,
4045}
4046
4047impl UnaryFunc {
4048    /// Create a new UnaryFunc with no original_name
4049    pub fn new(this: Expression) -> Self {
4050        Self {
4051            this,
4052            original_name: None,
4053        }
4054    }
4055
4056    /// Create a new UnaryFunc with an original name for round-trip preservation
4057    pub fn with_name(this: Expression, name: String) -> Self {
4058        Self {
4059            this,
4060            original_name: Some(name),
4061        }
4062    }
4063}
4064
4065/// CHAR/CHR function with multiple args and optional USING charset
4066/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4067/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4069#[cfg_attr(feature = "bindings", derive(TS))]
4070pub struct CharFunc {
4071    pub args: Vec<Expression>,
4072    #[serde(skip_serializing_if = "Option::is_none", default)]
4073    pub charset: Option<String>,
4074    /// Original function name (CHAR or CHR), defaults to CHAR
4075    #[serde(skip_serializing_if = "Option::is_none", default)]
4076    pub name: Option<String>,
4077}
4078
4079/// Generic binary function (takes two arguments)
4080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4081#[cfg_attr(feature = "bindings", derive(TS))]
4082pub struct BinaryFunc {
4083    pub this: Expression,
4084    pub expression: Expression,
4085    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4086    #[serde(skip_serializing_if = "Option::is_none", default)]
4087    pub original_name: Option<String>,
4088}
4089
4090/// Variable argument function
4091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4092#[cfg_attr(feature = "bindings", derive(TS))]
4093pub struct VarArgFunc {
4094    pub expressions: Vec<Expression>,
4095    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4096    #[serde(skip_serializing_if = "Option::is_none", default)]
4097    pub original_name: Option<String>,
4098}
4099
4100/// CONCAT_WS function
4101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4102#[cfg_attr(feature = "bindings", derive(TS))]
4103pub struct ConcatWs {
4104    pub separator: Expression,
4105    pub expressions: Vec<Expression>,
4106}
4107
4108/// SUBSTRING function
4109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4110#[cfg_attr(feature = "bindings", derive(TS))]
4111pub struct SubstringFunc {
4112    pub this: Expression,
4113    pub start: Expression,
4114    pub length: Option<Expression>,
4115    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4116    #[serde(default)]
4117    pub from_for_syntax: bool,
4118}
4119
4120/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4122#[cfg_attr(feature = "bindings", derive(TS))]
4123pub struct OverlayFunc {
4124    pub this: Expression,
4125    pub replacement: Expression,
4126    pub from: Expression,
4127    pub length: Option<Expression>,
4128}
4129
4130/// TRIM function
4131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4132#[cfg_attr(feature = "bindings", derive(TS))]
4133pub struct TrimFunc {
4134    pub this: Expression,
4135    pub characters: Option<Expression>,
4136    pub position: TrimPosition,
4137    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4138    #[serde(default)]
4139    pub sql_standard_syntax: bool,
4140    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4141    #[serde(default)]
4142    pub position_explicit: bool,
4143}
4144
4145#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4146#[cfg_attr(feature = "bindings", derive(TS))]
4147pub enum TrimPosition {
4148    Both,
4149    Leading,
4150    Trailing,
4151}
4152
4153/// REPLACE function
4154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4155#[cfg_attr(feature = "bindings", derive(TS))]
4156pub struct ReplaceFunc {
4157    pub this: Expression,
4158    pub old: Expression,
4159    pub new: Expression,
4160}
4161
4162/// LEFT/RIGHT function
4163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4164#[cfg_attr(feature = "bindings", derive(TS))]
4165pub struct LeftRightFunc {
4166    pub this: Expression,
4167    pub length: Expression,
4168}
4169
4170/// REPEAT function
4171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4172#[cfg_attr(feature = "bindings", derive(TS))]
4173pub struct RepeatFunc {
4174    pub this: Expression,
4175    pub times: Expression,
4176}
4177
4178/// LPAD/RPAD function
4179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4180#[cfg_attr(feature = "bindings", derive(TS))]
4181pub struct PadFunc {
4182    pub this: Expression,
4183    pub length: Expression,
4184    pub fill: Option<Expression>,
4185}
4186
4187/// SPLIT function
4188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4189#[cfg_attr(feature = "bindings", derive(TS))]
4190pub struct SplitFunc {
4191    pub this: Expression,
4192    pub delimiter: Expression,
4193}
4194
4195/// REGEXP_LIKE function
4196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4197#[cfg_attr(feature = "bindings", derive(TS))]
4198pub struct RegexpFunc {
4199    pub this: Expression,
4200    pub pattern: Expression,
4201    pub flags: Option<Expression>,
4202}
4203
4204/// REGEXP_REPLACE function
4205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4206#[cfg_attr(feature = "bindings", derive(TS))]
4207pub struct RegexpReplaceFunc {
4208    pub this: Expression,
4209    pub pattern: Expression,
4210    pub replacement: Expression,
4211    pub flags: Option<Expression>,
4212}
4213
4214/// REGEXP_EXTRACT function
4215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4216#[cfg_attr(feature = "bindings", derive(TS))]
4217pub struct RegexpExtractFunc {
4218    pub this: Expression,
4219    pub pattern: Expression,
4220    pub group: Option<Expression>,
4221}
4222
4223/// ROUND function
4224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4225#[cfg_attr(feature = "bindings", derive(TS))]
4226pub struct RoundFunc {
4227    pub this: Expression,
4228    pub decimals: Option<Expression>,
4229}
4230
4231/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4233#[cfg_attr(feature = "bindings", derive(TS))]
4234pub struct FloorFunc {
4235    pub this: Expression,
4236    pub scale: Option<Expression>,
4237    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4238    #[serde(skip_serializing_if = "Option::is_none", default)]
4239    pub to: Option<Expression>,
4240}
4241
4242/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4244#[cfg_attr(feature = "bindings", derive(TS))]
4245pub struct CeilFunc {
4246    pub this: Expression,
4247    #[serde(skip_serializing_if = "Option::is_none", default)]
4248    pub decimals: Option<Expression>,
4249    /// Time unit for Druid-style CEIL(time TO unit) syntax
4250    #[serde(skip_serializing_if = "Option::is_none", default)]
4251    pub to: Option<Expression>,
4252}
4253
4254/// LOG function
4255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4256#[cfg_attr(feature = "bindings", derive(TS))]
4257pub struct LogFunc {
4258    pub this: Expression,
4259    pub base: Option<Expression>,
4260}
4261
4262/// CURRENT_DATE (no arguments)
4263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4264#[cfg_attr(feature = "bindings", derive(TS))]
4265pub struct CurrentDate;
4266
4267/// CURRENT_TIME
4268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4269#[cfg_attr(feature = "bindings", derive(TS))]
4270pub struct CurrentTime {
4271    pub precision: Option<u32>,
4272}
4273
4274/// CURRENT_TIMESTAMP
4275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4276#[cfg_attr(feature = "bindings", derive(TS))]
4277pub struct CurrentTimestamp {
4278    pub precision: Option<u32>,
4279    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4280    #[serde(default)]
4281    pub sysdate: bool,
4282}
4283
4284/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4286#[cfg_attr(feature = "bindings", derive(TS))]
4287pub struct CurrentTimestampLTZ {
4288    pub precision: Option<u32>,
4289}
4290
4291/// AT TIME ZONE expression for timezone conversion
4292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4293#[cfg_attr(feature = "bindings", derive(TS))]
4294pub struct AtTimeZone {
4295    /// The expression to convert
4296    pub this: Expression,
4297    /// The target timezone
4298    pub zone: Expression,
4299}
4300
4301/// DATE_ADD / DATE_SUB function
4302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4303#[cfg_attr(feature = "bindings", derive(TS))]
4304pub struct DateAddFunc {
4305    pub this: Expression,
4306    pub interval: Expression,
4307    pub unit: IntervalUnit,
4308}
4309
4310/// DATEDIFF function
4311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4312#[cfg_attr(feature = "bindings", derive(TS))]
4313pub struct DateDiffFunc {
4314    pub this: Expression,
4315    pub expression: Expression,
4316    pub unit: Option<IntervalUnit>,
4317}
4318
4319/// DATE_TRUNC function
4320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4321#[cfg_attr(feature = "bindings", derive(TS))]
4322pub struct DateTruncFunc {
4323    pub this: Expression,
4324    pub unit: DateTimeField,
4325}
4326
4327/// EXTRACT function
4328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4329#[cfg_attr(feature = "bindings", derive(TS))]
4330pub struct ExtractFunc {
4331    pub this: Expression,
4332    pub field: DateTimeField,
4333}
4334
4335#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4336#[cfg_attr(feature = "bindings", derive(TS))]
4337pub enum DateTimeField {
4338    Year,
4339    Month,
4340    Day,
4341    Hour,
4342    Minute,
4343    Second,
4344    Millisecond,
4345    Microsecond,
4346    DayOfWeek,
4347    DayOfYear,
4348    Week,
4349    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4350    WeekWithModifier(String),
4351    Quarter,
4352    Epoch,
4353    Timezone,
4354    TimezoneHour,
4355    TimezoneMinute,
4356    Date,
4357    Time,
4358    /// Custom datetime field for dialect-specific or arbitrary fields
4359    Custom(String),
4360}
4361
4362/// TO_DATE function
4363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4364#[cfg_attr(feature = "bindings", derive(TS))]
4365pub struct ToDateFunc {
4366    pub this: Expression,
4367    pub format: Option<Expression>,
4368}
4369
4370/// TO_TIMESTAMP function
4371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4372#[cfg_attr(feature = "bindings", derive(TS))]
4373pub struct ToTimestampFunc {
4374    pub this: Expression,
4375    pub format: Option<Expression>,
4376}
4377
4378/// IF function
4379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4380#[cfg_attr(feature = "bindings", derive(TS))]
4381pub struct IfFunc {
4382    pub condition: Expression,
4383    pub true_value: Expression,
4384    pub false_value: Option<Expression>,
4385    /// Original function name (IF, IFF, IIF) for round-trip preservation
4386    #[serde(skip_serializing_if = "Option::is_none", default)]
4387    pub original_name: Option<String>,
4388}
4389
4390/// NVL2 function
4391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4392#[cfg_attr(feature = "bindings", derive(TS))]
4393pub struct Nvl2Func {
4394    pub this: Expression,
4395    pub true_value: Expression,
4396    pub false_value: Expression,
4397}
4398
4399// ============================================================================
4400// Typed Aggregate Function types
4401// ============================================================================
4402
4403/// Generic aggregate function base type
4404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4405#[cfg_attr(feature = "bindings", derive(TS))]
4406pub struct AggFunc {
4407    pub this: Expression,
4408    pub distinct: bool,
4409    pub filter: Option<Expression>,
4410    pub order_by: Vec<Ordered>,
4411    /// Original function name (case-preserving) when parsed from SQL
4412    #[serde(skip_serializing_if = "Option::is_none", default)]
4413    pub name: Option<String>,
4414    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4415    #[serde(skip_serializing_if = "Option::is_none", default)]
4416    pub ignore_nulls: Option<bool>,
4417    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4418    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4419    #[serde(skip_serializing_if = "Option::is_none", default)]
4420    pub having_max: Option<(Box<Expression>, bool)>,
4421    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4422    #[serde(skip_serializing_if = "Option::is_none", default)]
4423    pub limit: Option<Box<Expression>>,
4424}
4425
4426/// COUNT function with optional star
4427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4428#[cfg_attr(feature = "bindings", derive(TS))]
4429pub struct CountFunc {
4430    pub this: Option<Expression>,
4431    pub star: bool,
4432    pub distinct: bool,
4433    pub filter: Option<Expression>,
4434    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4435    #[serde(default, skip_serializing_if = "Option::is_none")]
4436    pub ignore_nulls: Option<bool>,
4437    /// Original function name for case preservation (e.g., "count" or "COUNT")
4438    #[serde(default, skip_serializing_if = "Option::is_none")]
4439    pub original_name: Option<String>,
4440}
4441
4442/// GROUP_CONCAT function (MySQL style)
4443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4444#[cfg_attr(feature = "bindings", derive(TS))]
4445pub struct GroupConcatFunc {
4446    pub this: Expression,
4447    pub separator: Option<Expression>,
4448    pub order_by: Option<Vec<Ordered>>,
4449    pub distinct: bool,
4450    pub filter: Option<Expression>,
4451}
4452
4453/// STRING_AGG function (PostgreSQL/Standard SQL)
4454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4455#[cfg_attr(feature = "bindings", derive(TS))]
4456pub struct StringAggFunc {
4457    pub this: Expression,
4458    #[serde(default)]
4459    pub separator: Option<Expression>,
4460    #[serde(default)]
4461    pub order_by: Option<Vec<Ordered>>,
4462    #[serde(default)]
4463    pub distinct: bool,
4464    #[serde(default)]
4465    pub filter: Option<Expression>,
4466    /// BigQuery LIMIT inside STRING_AGG
4467    #[serde(default, skip_serializing_if = "Option::is_none")]
4468    pub limit: Option<Box<Expression>>,
4469}
4470
4471/// LISTAGG function (Oracle style)
4472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4473#[cfg_attr(feature = "bindings", derive(TS))]
4474pub struct ListAggFunc {
4475    pub this: Expression,
4476    pub separator: Option<Expression>,
4477    pub on_overflow: Option<ListAggOverflow>,
4478    pub order_by: Option<Vec<Ordered>>,
4479    pub distinct: bool,
4480    pub filter: Option<Expression>,
4481}
4482
4483/// LISTAGG ON OVERFLOW behavior
4484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4485#[cfg_attr(feature = "bindings", derive(TS))]
4486pub enum ListAggOverflow {
4487    Error,
4488    Truncate {
4489        filler: Option<Expression>,
4490        with_count: bool,
4491    },
4492}
4493
4494/// SUM_IF / COUNT_IF function
4495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4496#[cfg_attr(feature = "bindings", derive(TS))]
4497pub struct SumIfFunc {
4498    pub this: Expression,
4499    pub condition: Expression,
4500    pub filter: Option<Expression>,
4501}
4502
4503/// APPROX_PERCENTILE function
4504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4505#[cfg_attr(feature = "bindings", derive(TS))]
4506pub struct ApproxPercentileFunc {
4507    pub this: Expression,
4508    pub percentile: Expression,
4509    pub accuracy: Option<Expression>,
4510    pub filter: Option<Expression>,
4511}
4512
4513/// PERCENTILE_CONT / PERCENTILE_DISC function
4514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4515#[cfg_attr(feature = "bindings", derive(TS))]
4516pub struct PercentileFunc {
4517    pub this: Expression,
4518    pub percentile: Expression,
4519    pub order_by: Option<Vec<Ordered>>,
4520    pub filter: Option<Expression>,
4521}
4522
4523// ============================================================================
4524// Typed Window Function types
4525// ============================================================================
4526
4527/// ROW_NUMBER function (no arguments)
4528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4529#[cfg_attr(feature = "bindings", derive(TS))]
4530pub struct RowNumber;
4531
4532/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4534#[cfg_attr(feature = "bindings", derive(TS))]
4535pub struct Rank {
4536    /// DuckDB: RANK(ORDER BY col) - order by inside function
4537    #[serde(default, skip_serializing_if = "Option::is_none")]
4538    pub order_by: Option<Vec<Ordered>>,
4539    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4540    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4541    pub args: Vec<Expression>,
4542}
4543
4544/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4546#[cfg_attr(feature = "bindings", derive(TS))]
4547pub struct DenseRank {
4548    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4549    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4550    pub args: Vec<Expression>,
4551}
4552
4553/// NTILE function (DuckDB allows ORDER BY inside)
4554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4555#[cfg_attr(feature = "bindings", derive(TS))]
4556pub struct NTileFunc {
4557    /// num_buckets is optional to support Databricks NTILE() without arguments
4558    #[serde(default, skip_serializing_if = "Option::is_none")]
4559    pub num_buckets: Option<Expression>,
4560    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4561    #[serde(default, skip_serializing_if = "Option::is_none")]
4562    pub order_by: Option<Vec<Ordered>>,
4563}
4564
4565/// LEAD / LAG function
4566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4567#[cfg_attr(feature = "bindings", derive(TS))]
4568pub struct LeadLagFunc {
4569    pub this: Expression,
4570    pub offset: Option<Expression>,
4571    pub default: Option<Expression>,
4572    pub ignore_nulls: bool,
4573}
4574
4575/// FIRST_VALUE / LAST_VALUE function
4576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4577#[cfg_attr(feature = "bindings", derive(TS))]
4578pub struct ValueFunc {
4579    pub this: Expression,
4580    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4581    #[serde(default, skip_serializing_if = "Option::is_none")]
4582    pub ignore_nulls: Option<bool>,
4583}
4584
4585/// NTH_VALUE function
4586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4587#[cfg_attr(feature = "bindings", derive(TS))]
4588pub struct NthValueFunc {
4589    pub this: Expression,
4590    pub offset: Expression,
4591    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4592    #[serde(default, skip_serializing_if = "Option::is_none")]
4593    pub ignore_nulls: Option<bool>,
4594    /// Snowflake FROM FIRST / FROM LAST clause
4595    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
4596    #[serde(default, skip_serializing_if = "Option::is_none")]
4597    pub from_first: Option<bool>,
4598}
4599
4600/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4602#[cfg_attr(feature = "bindings", derive(TS))]
4603pub struct PercentRank {
4604    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4605    #[serde(default, skip_serializing_if = "Option::is_none")]
4606    pub order_by: Option<Vec<Ordered>>,
4607    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4608    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4609    pub args: Vec<Expression>,
4610}
4611
4612/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4614#[cfg_attr(feature = "bindings", derive(TS))]
4615pub struct CumeDist {
4616    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4617    #[serde(default, skip_serializing_if = "Option::is_none")]
4618    pub order_by: Option<Vec<Ordered>>,
4619    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4620    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4621    pub args: Vec<Expression>,
4622}
4623
4624// ============================================================================
4625// Additional String Function types
4626// ============================================================================
4627
4628/// POSITION/INSTR function
4629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4630#[cfg_attr(feature = "bindings", derive(TS))]
4631pub struct PositionFunc {
4632    pub substring: Expression,
4633    pub string: Expression,
4634    pub start: Option<Expression>,
4635}
4636
4637// ============================================================================
4638// Additional Math Function types
4639// ============================================================================
4640
4641/// RANDOM function (no arguments)
4642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4643#[cfg_attr(feature = "bindings", derive(TS))]
4644pub struct Random;
4645
4646/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4648#[cfg_attr(feature = "bindings", derive(TS))]
4649pub struct Rand {
4650    pub seed: Option<Box<Expression>>,
4651    /// Teradata RANDOM lower bound
4652    #[serde(default)]
4653    pub lower: Option<Box<Expression>>,
4654    /// Teradata RANDOM upper bound
4655    #[serde(default)]
4656    pub upper: Option<Box<Expression>>,
4657}
4658
4659/// TRUNCATE / TRUNC function
4660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4661#[cfg_attr(feature = "bindings", derive(TS))]
4662pub struct TruncateFunc {
4663    pub this: Expression,
4664    pub decimals: Option<Expression>,
4665}
4666
4667/// PI function (no arguments)
4668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4669#[cfg_attr(feature = "bindings", derive(TS))]
4670pub struct Pi;
4671
4672// ============================================================================
4673// Control Flow Function types
4674// ============================================================================
4675
4676/// DECODE function (Oracle style)
4677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4678#[cfg_attr(feature = "bindings", derive(TS))]
4679pub struct DecodeFunc {
4680    pub this: Expression,
4681    pub search_results: Vec<(Expression, Expression)>,
4682    pub default: Option<Expression>,
4683}
4684
4685// ============================================================================
4686// Additional Date/Time Function types
4687// ============================================================================
4688
4689/// DATE_FORMAT / FORMAT_DATE function
4690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4691#[cfg_attr(feature = "bindings", derive(TS))]
4692pub struct DateFormatFunc {
4693    pub this: Expression,
4694    pub format: Expression,
4695}
4696
4697/// FROM_UNIXTIME function
4698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4699#[cfg_attr(feature = "bindings", derive(TS))]
4700pub struct FromUnixtimeFunc {
4701    pub this: Expression,
4702    pub format: Option<Expression>,
4703}
4704
4705/// UNIX_TIMESTAMP function
4706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4707#[cfg_attr(feature = "bindings", derive(TS))]
4708pub struct UnixTimestampFunc {
4709    pub this: Option<Expression>,
4710    pub format: Option<Expression>,
4711}
4712
4713/// MAKE_DATE function
4714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4715#[cfg_attr(feature = "bindings", derive(TS))]
4716pub struct MakeDateFunc {
4717    pub year: Expression,
4718    pub month: Expression,
4719    pub day: Expression,
4720}
4721
4722/// MAKE_TIMESTAMP function
4723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4724#[cfg_attr(feature = "bindings", derive(TS))]
4725pub struct MakeTimestampFunc {
4726    pub year: Expression,
4727    pub month: Expression,
4728    pub day: Expression,
4729    pub hour: Expression,
4730    pub minute: Expression,
4731    pub second: Expression,
4732    pub timezone: Option<Expression>,
4733}
4734
4735/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4737#[cfg_attr(feature = "bindings", derive(TS))]
4738pub struct LastDayFunc {
4739    pub this: Expression,
4740    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4741    #[serde(skip_serializing_if = "Option::is_none", default)]
4742    pub unit: Option<DateTimeField>,
4743}
4744
4745// ============================================================================
4746// Array Function types
4747// ============================================================================
4748
4749/// ARRAY constructor
4750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4751#[cfg_attr(feature = "bindings", derive(TS))]
4752pub struct ArrayConstructor {
4753    pub expressions: Vec<Expression>,
4754    pub bracket_notation: bool,
4755    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4756    pub use_list_keyword: bool,
4757}
4758
4759/// ARRAY_SORT function
4760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4761#[cfg_attr(feature = "bindings", derive(TS))]
4762pub struct ArraySortFunc {
4763    pub this: Expression,
4764    pub comparator: Option<Expression>,
4765    pub desc: bool,
4766    pub nulls_first: Option<bool>,
4767}
4768
4769/// ARRAY_JOIN / ARRAY_TO_STRING function
4770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4771#[cfg_attr(feature = "bindings", derive(TS))]
4772pub struct ArrayJoinFunc {
4773    pub this: Expression,
4774    pub separator: Expression,
4775    pub null_replacement: Option<Expression>,
4776}
4777
4778/// UNNEST function
4779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4780#[cfg_attr(feature = "bindings", derive(TS))]
4781pub struct UnnestFunc {
4782    pub this: Expression,
4783    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4784    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4785    pub expressions: Vec<Expression>,
4786    pub with_ordinality: bool,
4787    pub alias: Option<Identifier>,
4788    /// BigQuery: offset alias for WITH OFFSET AS <name>
4789    #[serde(default, skip_serializing_if = "Option::is_none")]
4790    pub offset_alias: Option<Identifier>,
4791}
4792
4793/// ARRAY_FILTER function (with lambda)
4794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4795#[cfg_attr(feature = "bindings", derive(TS))]
4796pub struct ArrayFilterFunc {
4797    pub this: Expression,
4798    pub filter: Expression,
4799}
4800
4801/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4803#[cfg_attr(feature = "bindings", derive(TS))]
4804pub struct ArrayTransformFunc {
4805    pub this: Expression,
4806    pub transform: Expression,
4807}
4808
4809/// SEQUENCE / GENERATE_SERIES function
4810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4811#[cfg_attr(feature = "bindings", derive(TS))]
4812pub struct SequenceFunc {
4813    pub start: Expression,
4814    pub stop: Expression,
4815    pub step: Option<Expression>,
4816}
4817
4818// ============================================================================
4819// Struct Function types
4820// ============================================================================
4821
4822/// STRUCT constructor
4823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4824#[cfg_attr(feature = "bindings", derive(TS))]
4825pub struct StructConstructor {
4826    pub fields: Vec<(Option<Identifier>, Expression)>,
4827}
4828
4829/// STRUCT_EXTRACT function
4830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4831#[cfg_attr(feature = "bindings", derive(TS))]
4832pub struct StructExtractFunc {
4833    pub this: Expression,
4834    pub field: Identifier,
4835}
4836
4837/// NAMED_STRUCT function
4838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4839#[cfg_attr(feature = "bindings", derive(TS))]
4840pub struct NamedStructFunc {
4841    pub pairs: Vec<(Expression, Expression)>,
4842}
4843
4844// ============================================================================
4845// Map Function types
4846// ============================================================================
4847
4848/// MAP constructor
4849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4850#[cfg_attr(feature = "bindings", derive(TS))]
4851pub struct MapConstructor {
4852    pub keys: Vec<Expression>,
4853    pub values: Vec<Expression>,
4854    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4855    #[serde(default)]
4856    pub curly_brace_syntax: bool,
4857    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4858    #[serde(default)]
4859    pub with_map_keyword: bool,
4860}
4861
4862/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4864#[cfg_attr(feature = "bindings", derive(TS))]
4865pub struct TransformFunc {
4866    pub this: Expression,
4867    pub transform: Expression,
4868}
4869
4870// ============================================================================
4871// JSON Function types
4872// ============================================================================
4873
4874/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4876#[cfg_attr(feature = "bindings", derive(TS))]
4877pub struct JsonExtractFunc {
4878    pub this: Expression,
4879    pub path: Expression,
4880    pub returning: Option<DataType>,
4881    /// True if parsed from -> or ->> operator syntax
4882    #[serde(default)]
4883    pub arrow_syntax: bool,
4884    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4885    #[serde(default)]
4886    pub hash_arrow_syntax: bool,
4887    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4888    #[serde(default)]
4889    pub wrapper_option: Option<String>,
4890    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4891    #[serde(default)]
4892    pub quotes_option: Option<String>,
4893    /// ON SCALAR STRING flag
4894    #[serde(default)]
4895    pub on_scalar_string: bool,
4896    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4897    #[serde(default)]
4898    pub on_error: Option<String>,
4899}
4900
4901/// JSON path extraction
4902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4903#[cfg_attr(feature = "bindings", derive(TS))]
4904pub struct JsonPathFunc {
4905    pub this: Expression,
4906    pub paths: Vec<Expression>,
4907}
4908
4909/// JSON_OBJECT function
4910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4911#[cfg_attr(feature = "bindings", derive(TS))]
4912pub struct JsonObjectFunc {
4913    pub pairs: Vec<(Expression, Expression)>,
4914    pub null_handling: Option<JsonNullHandling>,
4915    #[serde(default)]
4916    pub with_unique_keys: bool,
4917    #[serde(default)]
4918    pub returning_type: Option<DataType>,
4919    #[serde(default)]
4920    pub format_json: bool,
4921    #[serde(default)]
4922    pub encoding: Option<String>,
4923    /// For JSON_OBJECT(*) syntax
4924    #[serde(default)]
4925    pub star: bool,
4926}
4927
4928/// JSON null handling options
4929#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4930#[cfg_attr(feature = "bindings", derive(TS))]
4931pub enum JsonNullHandling {
4932    NullOnNull,
4933    AbsentOnNull,
4934}
4935
4936/// JSON_SET / JSON_INSERT function
4937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4938#[cfg_attr(feature = "bindings", derive(TS))]
4939pub struct JsonModifyFunc {
4940    pub this: Expression,
4941    pub path_values: Vec<(Expression, Expression)>,
4942}
4943
4944/// JSON_ARRAYAGG function
4945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4946#[cfg_attr(feature = "bindings", derive(TS))]
4947pub struct JsonArrayAggFunc {
4948    pub this: Expression,
4949    pub order_by: Option<Vec<Ordered>>,
4950    pub null_handling: Option<JsonNullHandling>,
4951    pub filter: Option<Expression>,
4952}
4953
4954/// JSON_OBJECTAGG function
4955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4956#[cfg_attr(feature = "bindings", derive(TS))]
4957pub struct JsonObjectAggFunc {
4958    pub key: Expression,
4959    pub value: Expression,
4960    pub null_handling: Option<JsonNullHandling>,
4961    pub filter: Option<Expression>,
4962}
4963
4964// ============================================================================
4965// Type Casting Function types
4966// ============================================================================
4967
4968/// CONVERT function (SQL Server style)
4969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4970#[cfg_attr(feature = "bindings", derive(TS))]
4971pub struct ConvertFunc {
4972    pub this: Expression,
4973    pub to: DataType,
4974    pub style: Option<Expression>,
4975}
4976
4977// ============================================================================
4978// Additional Expression types
4979// ============================================================================
4980
4981/// Lambda expression
4982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4983#[cfg_attr(feature = "bindings", derive(TS))]
4984pub struct LambdaExpr {
4985    pub parameters: Vec<Identifier>,
4986    pub body: Expression,
4987    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
4988    #[serde(default)]
4989    pub colon: bool,
4990    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
4991    /// Maps parameter index to data type
4992    #[serde(default)]
4993    pub parameter_types: Vec<Option<DataType>>,
4994}
4995
4996/// Parameter (parameterized queries)
4997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4998#[cfg_attr(feature = "bindings", derive(TS))]
4999pub struct Parameter {
5000    pub name: Option<String>,
5001    pub index: Option<u32>,
5002    pub style: ParameterStyle,
5003    /// Whether the name was quoted (e.g., @"x" vs @x)
5004    #[serde(default)]
5005    pub quoted: bool,
5006    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5007    #[serde(default)]
5008    pub string_quoted: bool,
5009    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5010    #[serde(default)]
5011    pub expression: Option<String>,
5012}
5013
5014/// Parameter placeholder styles
5015#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5016#[cfg_attr(feature = "bindings", derive(TS))]
5017pub enum ParameterStyle {
5018    Question,     // ?
5019    Dollar,       // $1, $2
5020    DollarBrace,  // ${name} (Databricks, Hive template variables)
5021    Brace,        // {name} (Spark/Databricks widget/template variables)
5022    Colon,        // :name
5023    At,           // @name
5024    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5025    DoubleDollar, // $$name
5026    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5027}
5028
5029/// Placeholder expression
5030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5031#[cfg_attr(feature = "bindings", derive(TS))]
5032pub struct Placeholder {
5033    pub index: Option<u32>,
5034}
5035
5036/// Named argument in function call: name => value or name := value
5037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5038#[cfg_attr(feature = "bindings", derive(TS))]
5039pub struct NamedArgument {
5040    pub name: Identifier,
5041    pub value: Expression,
5042    /// The separator used: `=>`, `:=`, or `=`
5043    pub separator: NamedArgSeparator,
5044}
5045
5046/// Separator style for named arguments
5047#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5048#[cfg_attr(feature = "bindings", derive(TS))]
5049pub enum NamedArgSeparator {
5050    /// `=>` (standard SQL, Snowflake, BigQuery)
5051    DArrow,
5052    /// `:=` (Oracle, MySQL)
5053    ColonEq,
5054    /// `=` (simple equals, some dialects)
5055    Eq,
5056}
5057
5058/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5059/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5061#[cfg_attr(feature = "bindings", derive(TS))]
5062pub struct TableArgument {
5063    /// The keyword prefix: "TABLE" or "MODEL"
5064    pub prefix: String,
5065    /// The table/model reference expression
5066    pub this: Expression,
5067}
5068
5069/// SQL Comment preservation
5070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5071#[cfg_attr(feature = "bindings", derive(TS))]
5072pub struct SqlComment {
5073    pub text: String,
5074    pub is_block: bool,
5075}
5076
5077// ============================================================================
5078// Additional Predicate types
5079// ============================================================================
5080
5081/// SIMILAR TO expression
5082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5083#[cfg_attr(feature = "bindings", derive(TS))]
5084pub struct SimilarToExpr {
5085    pub this: Expression,
5086    pub pattern: Expression,
5087    pub escape: Option<Expression>,
5088    pub not: bool,
5089}
5090
5091/// ANY / ALL quantified expression
5092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5093#[cfg_attr(feature = "bindings", derive(TS))]
5094pub struct QuantifiedExpr {
5095    pub this: Expression,
5096    pub subquery: Expression,
5097    pub op: Option<QuantifiedOp>,
5098}
5099
5100/// Comparison operator for quantified expressions
5101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5102#[cfg_attr(feature = "bindings", derive(TS))]
5103pub enum QuantifiedOp {
5104    Eq,
5105    Neq,
5106    Lt,
5107    Lte,
5108    Gt,
5109    Gte,
5110}
5111
5112/// OVERLAPS expression
5113/// Supports two forms:
5114/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5115/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5117#[cfg_attr(feature = "bindings", derive(TS))]
5118pub struct OverlapsExpr {
5119    /// Left operand for simple binary form
5120    #[serde(skip_serializing_if = "Option::is_none")]
5121    pub this: Option<Expression>,
5122    /// Right operand for simple binary form
5123    #[serde(skip_serializing_if = "Option::is_none")]
5124    pub expression: Option<Expression>,
5125    /// Left range start for full ANSI form
5126    #[serde(skip_serializing_if = "Option::is_none")]
5127    pub left_start: Option<Expression>,
5128    /// Left range end for full ANSI form
5129    #[serde(skip_serializing_if = "Option::is_none")]
5130    pub left_end: Option<Expression>,
5131    /// Right range start for full ANSI form
5132    #[serde(skip_serializing_if = "Option::is_none")]
5133    pub right_start: Option<Expression>,
5134    /// Right range end for full ANSI form
5135    #[serde(skip_serializing_if = "Option::is_none")]
5136    pub right_end: Option<Expression>,
5137}
5138
5139// ============================================================================
5140// Array/Struct/Map access
5141// ============================================================================
5142
5143/// Subscript access (array[index] or map[key])
5144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5145#[cfg_attr(feature = "bindings", derive(TS))]
5146pub struct Subscript {
5147    pub this: Expression,
5148    pub index: Expression,
5149}
5150
5151/// Dot access (struct.field)
5152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5153#[cfg_attr(feature = "bindings", derive(TS))]
5154pub struct DotAccess {
5155    pub this: Expression,
5156    pub field: Identifier,
5157}
5158
5159/// Method call (expr.method(args))
5160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5161#[cfg_attr(feature = "bindings", derive(TS))]
5162pub struct MethodCall {
5163    pub this: Expression,
5164    pub method: Identifier,
5165    pub args: Vec<Expression>,
5166}
5167
5168/// Array slice (array[start:end])
5169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5170#[cfg_attr(feature = "bindings", derive(TS))]
5171pub struct ArraySlice {
5172    pub this: Expression,
5173    pub start: Option<Expression>,
5174    pub end: Option<Expression>,
5175}
5176
5177// ============================================================================
5178// DDL (Data Definition Language) Statements
5179// ============================================================================
5180
5181/// ON COMMIT behavior for temporary tables
5182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5183#[cfg_attr(feature = "bindings", derive(TS))]
5184pub enum OnCommit {
5185    /// ON COMMIT PRESERVE ROWS
5186    PreserveRows,
5187    /// ON COMMIT DELETE ROWS
5188    DeleteRows,
5189}
5190
5191/// CREATE TABLE statement
5192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5193#[cfg_attr(feature = "bindings", derive(TS))]
5194pub struct CreateTable {
5195    pub name: TableRef,
5196    /// ClickHouse: ON CLUSTER clause for distributed DDL
5197    #[serde(default, skip_serializing_if = "Option::is_none")]
5198    pub on_cluster: Option<OnCluster>,
5199    pub columns: Vec<ColumnDef>,
5200    pub constraints: Vec<TableConstraint>,
5201    pub if_not_exists: bool,
5202    pub temporary: bool,
5203    pub or_replace: bool,
5204    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5205    #[serde(default, skip_serializing_if = "Option::is_none")]
5206    pub table_modifier: Option<String>,
5207    pub as_select: Option<Expression>,
5208    /// Whether the AS SELECT was wrapped in parentheses
5209    #[serde(default)]
5210    pub as_select_parenthesized: bool,
5211    /// ON COMMIT behavior for temporary tables
5212    #[serde(default)]
5213    pub on_commit: Option<OnCommit>,
5214    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5215    #[serde(default)]
5216    pub clone_source: Option<TableRef>,
5217    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5218    #[serde(default, skip_serializing_if = "Option::is_none")]
5219    pub clone_at_clause: Option<Expression>,
5220    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5221    #[serde(default)]
5222    pub is_copy: bool,
5223    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5224    #[serde(default)]
5225    pub shallow_clone: bool,
5226    /// Leading comments before the statement
5227    #[serde(default)]
5228    pub leading_comments: Vec<String>,
5229    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5230    #[serde(default)]
5231    pub with_properties: Vec<(String, String)>,
5232    /// Teradata: table options after name before columns (comma-separated)
5233    #[serde(default)]
5234    pub teradata_post_name_options: Vec<String>,
5235    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5236    #[serde(default)]
5237    pub with_data: Option<bool>,
5238    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5239    #[serde(default)]
5240    pub with_statistics: Option<bool>,
5241    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5242    #[serde(default)]
5243    pub teradata_indexes: Vec<TeradataIndex>,
5244    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5245    #[serde(default)]
5246    pub with_cte: Option<With>,
5247    /// Table properties like DEFAULT COLLATE (BigQuery)
5248    #[serde(default)]
5249    pub properties: Vec<Expression>,
5250    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5251    #[serde(default, skip_serializing_if = "Option::is_none")]
5252    pub partition_of: Option<Expression>,
5253    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5254    #[serde(default)]
5255    pub post_table_properties: Vec<Expression>,
5256    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5257    #[serde(default)]
5258    pub mysql_table_options: Vec<(String, String)>,
5259    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5260    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5261    pub inherits: Vec<TableRef>,
5262    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5263    #[serde(default, skip_serializing_if = "Option::is_none")]
5264    pub on_property: Option<OnProperty>,
5265    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5266    #[serde(default)]
5267    pub copy_grants: bool,
5268    /// Snowflake: USING TEMPLATE expression for schema inference
5269    #[serde(default, skip_serializing_if = "Option::is_none")]
5270    pub using_template: Option<Box<Expression>>,
5271    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5272    #[serde(default, skip_serializing_if = "Option::is_none")]
5273    pub rollup: Option<RollupProperty>,
5274}
5275
5276/// Teradata index specification for CREATE TABLE
5277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5278#[cfg_attr(feature = "bindings", derive(TS))]
5279pub struct TeradataIndex {
5280    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5281    pub kind: TeradataIndexKind,
5282    /// Optional index name
5283    pub name: Option<String>,
5284    /// Optional column list
5285    pub columns: Vec<String>,
5286}
5287
5288/// Kind of Teradata index
5289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5290#[cfg_attr(feature = "bindings", derive(TS))]
5291pub enum TeradataIndexKind {
5292    /// NO PRIMARY INDEX
5293    NoPrimary,
5294    /// PRIMARY INDEX
5295    Primary,
5296    /// PRIMARY AMP INDEX
5297    PrimaryAmp,
5298    /// UNIQUE INDEX
5299    Unique,
5300    /// UNIQUE PRIMARY INDEX
5301    UniquePrimary,
5302    /// INDEX (secondary, non-primary)
5303    Secondary,
5304}
5305
5306impl CreateTable {
5307    pub fn new(name: impl Into<String>) -> Self {
5308        Self {
5309            name: TableRef::new(name),
5310            on_cluster: None,
5311            columns: Vec::new(),
5312            constraints: Vec::new(),
5313            if_not_exists: false,
5314            temporary: false,
5315            or_replace: false,
5316            table_modifier: None,
5317            as_select: None,
5318            as_select_parenthesized: false,
5319            on_commit: None,
5320            clone_source: None,
5321            clone_at_clause: None,
5322            shallow_clone: false,
5323            is_copy: false,
5324            leading_comments: Vec::new(),
5325            with_properties: Vec::new(),
5326            teradata_post_name_options: Vec::new(),
5327            with_data: None,
5328            with_statistics: None,
5329            teradata_indexes: Vec::new(),
5330            with_cte: None,
5331            properties: Vec::new(),
5332            partition_of: None,
5333            post_table_properties: Vec::new(),
5334            mysql_table_options: Vec::new(),
5335            inherits: Vec::new(),
5336            on_property: None,
5337            copy_grants: false,
5338            using_template: None,
5339            rollup: None,
5340        }
5341    }
5342}
5343
5344/// Sort order for PRIMARY KEY ASC/DESC
5345#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5346#[cfg_attr(feature = "bindings", derive(TS))]
5347pub enum SortOrder {
5348    Asc,
5349    Desc,
5350}
5351
5352/// Type of column constraint for tracking order
5353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5354#[cfg_attr(feature = "bindings", derive(TS))]
5355pub enum ConstraintType {
5356    NotNull,
5357    Null,
5358    PrimaryKey,
5359    Unique,
5360    Default,
5361    AutoIncrement,
5362    Collate,
5363    Comment,
5364    References,
5365    Check,
5366    GeneratedAsIdentity,
5367    /// Snowflake: TAG (key='value', ...)
5368    Tags,
5369    /// Computed/generated column
5370    ComputedColumn,
5371    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5372    GeneratedAsRow,
5373    /// MySQL: ON UPDATE expression
5374    OnUpdate,
5375    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5376    Path,
5377    /// Redshift: ENCODE encoding_type
5378    Encode,
5379}
5380
5381/// Column definition in CREATE TABLE
5382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5383#[cfg_attr(feature = "bindings", derive(TS))]
5384pub struct ColumnDef {
5385    pub name: Identifier,
5386    pub data_type: DataType,
5387    pub nullable: Option<bool>,
5388    pub default: Option<Expression>,
5389    pub primary_key: bool,
5390    /// Sort order for PRIMARY KEY (ASC/DESC)
5391    #[serde(default)]
5392    pub primary_key_order: Option<SortOrder>,
5393    pub unique: bool,
5394    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5395    #[serde(default)]
5396    pub unique_nulls_not_distinct: bool,
5397    pub auto_increment: bool,
5398    pub comment: Option<String>,
5399    pub constraints: Vec<ColumnConstraint>,
5400    /// Track original order of constraints for accurate regeneration
5401    #[serde(default)]
5402    pub constraint_order: Vec<ConstraintType>,
5403    /// Teradata: FORMAT 'pattern'
5404    #[serde(default)]
5405    pub format: Option<String>,
5406    /// Teradata: TITLE 'title'
5407    #[serde(default)]
5408    pub title: Option<String>,
5409    /// Teradata: INLINE LENGTH n
5410    #[serde(default)]
5411    pub inline_length: Option<u64>,
5412    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5413    #[serde(default)]
5414    pub compress: Option<Vec<Expression>>,
5415    /// Teradata: CHARACTER SET name
5416    #[serde(default)]
5417    pub character_set: Option<String>,
5418    /// Teradata: UPPERCASE
5419    #[serde(default)]
5420    pub uppercase: bool,
5421    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5422    #[serde(default)]
5423    pub casespecific: Option<bool>,
5424    /// Snowflake: AUTOINCREMENT START value
5425    #[serde(default)]
5426    pub auto_increment_start: Option<Box<Expression>>,
5427    /// Snowflake: AUTOINCREMENT INCREMENT value
5428    #[serde(default)]
5429    pub auto_increment_increment: Option<Box<Expression>>,
5430    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5431    #[serde(default)]
5432    pub auto_increment_order: Option<bool>,
5433    /// MySQL: UNSIGNED modifier
5434    #[serde(default)]
5435    pub unsigned: bool,
5436    /// MySQL: ZEROFILL modifier
5437    #[serde(default)]
5438    pub zerofill: bool,
5439    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5440    #[serde(default, skip_serializing_if = "Option::is_none")]
5441    pub on_update: Option<Expression>,
5442    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5443    #[serde(default, skip_serializing_if = "Option::is_none")]
5444    pub unique_constraint_name: Option<String>,
5445    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5446    #[serde(default, skip_serializing_if = "Option::is_none")]
5447    pub not_null_constraint_name: Option<String>,
5448    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5449    #[serde(default, skip_serializing_if = "Option::is_none")]
5450    pub primary_key_constraint_name: Option<String>,
5451    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5452    #[serde(default, skip_serializing_if = "Option::is_none")]
5453    pub check_constraint_name: Option<String>,
5454    /// BigQuery: OPTIONS (key=value, ...) on column
5455    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5456    pub options: Vec<Expression>,
5457    /// SQLite: Column definition without explicit type
5458    #[serde(default)]
5459    pub no_type: bool,
5460    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5461    #[serde(default, skip_serializing_if = "Option::is_none")]
5462    pub encoding: Option<String>,
5463    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5464    #[serde(default, skip_serializing_if = "Option::is_none")]
5465    pub codec: Option<String>,
5466    /// ClickHouse: EPHEMERAL [expr] modifier
5467    #[serde(default, skip_serializing_if = "Option::is_none")]
5468    pub ephemeral: Option<Option<Box<Expression>>>,
5469    /// ClickHouse: MATERIALIZED expr modifier
5470    #[serde(default, skip_serializing_if = "Option::is_none")]
5471    pub materialized_expr: Option<Box<Expression>>,
5472    /// ClickHouse: ALIAS expr modifier
5473    #[serde(default, skip_serializing_if = "Option::is_none")]
5474    pub alias_expr: Option<Box<Expression>>,
5475    /// ClickHouse: TTL expr modifier on columns
5476    #[serde(default, skip_serializing_if = "Option::is_none")]
5477    pub ttl_expr: Option<Box<Expression>>,
5478    /// TSQL: NOT FOR REPLICATION
5479    #[serde(default)]
5480    pub not_for_replication: bool,
5481}
5482
5483impl ColumnDef {
5484    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5485        Self {
5486            name: Identifier::new(name),
5487            data_type,
5488            nullable: None,
5489            default: None,
5490            primary_key: false,
5491            primary_key_order: None,
5492            unique: false,
5493            unique_nulls_not_distinct: false,
5494            auto_increment: false,
5495            comment: None,
5496            constraints: Vec::new(),
5497            constraint_order: Vec::new(),
5498            format: None,
5499            title: None,
5500            inline_length: None,
5501            compress: None,
5502            character_set: None,
5503            uppercase: false,
5504            casespecific: None,
5505            auto_increment_start: None,
5506            auto_increment_increment: None,
5507            auto_increment_order: None,
5508            unsigned: false,
5509            zerofill: false,
5510            on_update: None,
5511            unique_constraint_name: None,
5512            not_null_constraint_name: None,
5513            primary_key_constraint_name: None,
5514            check_constraint_name: None,
5515            options: Vec::new(),
5516            no_type: false,
5517            encoding: None,
5518            codec: None,
5519            ephemeral: None,
5520            materialized_expr: None,
5521            alias_expr: None,
5522            ttl_expr: None,
5523            not_for_replication: false,
5524        }
5525    }
5526}
5527
5528/// Column-level constraint
5529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5530#[cfg_attr(feature = "bindings", derive(TS))]
5531pub enum ColumnConstraint {
5532    NotNull,
5533    Null,
5534    Unique,
5535    PrimaryKey,
5536    Default(Expression),
5537    Check(Expression),
5538    References(ForeignKeyRef),
5539    GeneratedAsIdentity(GeneratedAsIdentity),
5540    Collate(Identifier),
5541    Comment(String),
5542    /// Snowflake: TAG (key='value', ...)
5543    Tags(Tags),
5544    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5545    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5546    ComputedColumn(ComputedColumn),
5547    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5548    GeneratedAsRow(GeneratedAsRow),
5549    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5550    Path(Expression),
5551}
5552
5553/// Computed/generated column constraint
5554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5555#[cfg_attr(feature = "bindings", derive(TS))]
5556pub struct ComputedColumn {
5557    /// The expression that computes the column value
5558    pub expression: Box<Expression>,
5559    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5560    #[serde(default)]
5561    pub persisted: bool,
5562    /// NOT NULL (TSQL computed columns)
5563    #[serde(default)]
5564    pub not_null: bool,
5565    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5566    /// When None, defaults to dialect-appropriate output
5567    #[serde(default)]
5568    pub persistence_kind: Option<String>,
5569    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5570    #[serde(default, skip_serializing_if = "Option::is_none")]
5571    pub data_type: Option<DataType>,
5572}
5573
5574/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5576#[cfg_attr(feature = "bindings", derive(TS))]
5577pub struct GeneratedAsRow {
5578    /// true = ROW START, false = ROW END
5579    pub start: bool,
5580    /// HIDDEN modifier
5581    #[serde(default)]
5582    pub hidden: bool,
5583}
5584
5585/// Generated identity column constraint
5586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5587#[cfg_attr(feature = "bindings", derive(TS))]
5588pub struct GeneratedAsIdentity {
5589    /// True for ALWAYS, False for BY DEFAULT
5590    pub always: bool,
5591    /// ON NULL (only valid with BY DEFAULT)
5592    pub on_null: bool,
5593    /// START WITH value
5594    pub start: Option<Box<Expression>>,
5595    /// INCREMENT BY value
5596    pub increment: Option<Box<Expression>>,
5597    /// MINVALUE
5598    pub minvalue: Option<Box<Expression>>,
5599    /// MAXVALUE
5600    pub maxvalue: Option<Box<Expression>>,
5601    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5602    pub cycle: Option<bool>,
5603}
5604
5605/// Constraint modifiers (shared between table-level constraints)
5606#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5607#[cfg_attr(feature = "bindings", derive(TS))]
5608pub struct ConstraintModifiers {
5609    /// ENFORCED / NOT ENFORCED
5610    pub enforced: Option<bool>,
5611    /// DEFERRABLE / NOT DEFERRABLE
5612    pub deferrable: Option<bool>,
5613    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5614    pub initially_deferred: Option<bool>,
5615    /// NORELY (Oracle)
5616    pub norely: bool,
5617    /// RELY (Oracle)
5618    pub rely: bool,
5619    /// USING index type (MySQL): BTREE or HASH
5620    #[serde(default)]
5621    pub using: Option<String>,
5622    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5623    #[serde(default)]
5624    pub using_before_columns: bool,
5625    /// MySQL index COMMENT 'text'
5626    #[serde(default, skip_serializing_if = "Option::is_none")]
5627    pub comment: Option<String>,
5628    /// MySQL index VISIBLE/INVISIBLE
5629    #[serde(default, skip_serializing_if = "Option::is_none")]
5630    pub visible: Option<bool>,
5631    /// MySQL ENGINE_ATTRIBUTE = 'value'
5632    #[serde(default, skip_serializing_if = "Option::is_none")]
5633    pub engine_attribute: Option<String>,
5634    /// MySQL WITH PARSER name
5635    #[serde(default, skip_serializing_if = "Option::is_none")]
5636    pub with_parser: Option<String>,
5637    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5638    #[serde(default)]
5639    pub not_valid: bool,
5640    /// TSQL CLUSTERED/NONCLUSTERED modifier
5641    #[serde(default, skip_serializing_if = "Option::is_none")]
5642    pub clustered: Option<String>,
5643    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5644    #[serde(default, skip_serializing_if = "Option::is_none")]
5645    pub on_conflict: Option<String>,
5646    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5647    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5648    pub with_options: Vec<(String, String)>,
5649    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5650    #[serde(default, skip_serializing_if = "Option::is_none")]
5651    pub on_filegroup: Option<Identifier>,
5652}
5653
5654/// Table-level constraint
5655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5656#[cfg_attr(feature = "bindings", derive(TS))]
5657pub enum TableConstraint {
5658    PrimaryKey {
5659        name: Option<Identifier>,
5660        columns: Vec<Identifier>,
5661        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5662        #[serde(default)]
5663        include_columns: Vec<Identifier>,
5664        #[serde(default)]
5665        modifiers: ConstraintModifiers,
5666        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5667        #[serde(default)]
5668        has_constraint_keyword: bool,
5669    },
5670    Unique {
5671        name: Option<Identifier>,
5672        columns: Vec<Identifier>,
5673        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5674        #[serde(default)]
5675        columns_parenthesized: bool,
5676        #[serde(default)]
5677        modifiers: ConstraintModifiers,
5678        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5679        #[serde(default)]
5680        has_constraint_keyword: bool,
5681        /// PostgreSQL 15+: NULLS NOT DISTINCT
5682        #[serde(default)]
5683        nulls_not_distinct: bool,
5684    },
5685    ForeignKey {
5686        name: Option<Identifier>,
5687        columns: Vec<Identifier>,
5688        #[serde(default)]
5689        references: Option<ForeignKeyRef>,
5690        /// ON DELETE action when REFERENCES is absent
5691        #[serde(default)]
5692        on_delete: Option<ReferentialAction>,
5693        /// ON UPDATE action when REFERENCES is absent
5694        #[serde(default)]
5695        on_update: Option<ReferentialAction>,
5696        #[serde(default)]
5697        modifiers: ConstraintModifiers,
5698    },
5699    Check {
5700        name: Option<Identifier>,
5701        expression: Expression,
5702        #[serde(default)]
5703        modifiers: ConstraintModifiers,
5704    },
5705    /// INDEX / KEY constraint (MySQL)
5706    Index {
5707        name: Option<Identifier>,
5708        columns: Vec<Identifier>,
5709        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5710        #[serde(default)]
5711        kind: Option<String>,
5712        #[serde(default)]
5713        modifiers: ConstraintModifiers,
5714        /// True if KEY keyword was used instead of INDEX
5715        #[serde(default)]
5716        use_key_keyword: bool,
5717        /// ClickHouse: indexed expression (instead of columns)
5718        #[serde(default, skip_serializing_if = "Option::is_none")]
5719        expression: Option<Box<Expression>>,
5720        /// ClickHouse: TYPE type_func(args)
5721        #[serde(default, skip_serializing_if = "Option::is_none")]
5722        index_type: Option<Box<Expression>>,
5723        /// ClickHouse: GRANULARITY n
5724        #[serde(default, skip_serializing_if = "Option::is_none")]
5725        granularity: Option<Box<Expression>>,
5726    },
5727    /// ClickHouse PROJECTION definition
5728    Projection {
5729        name: Identifier,
5730        expression: Expression,
5731    },
5732    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5733    Like {
5734        source: TableRef,
5735        /// Options as (INCLUDING|EXCLUDING, property) pairs
5736        options: Vec<(LikeOptionAction, String)>,
5737    },
5738    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5739    PeriodForSystemTime {
5740        start_col: Identifier,
5741        end_col: Identifier,
5742    },
5743    /// PostgreSQL EXCLUDE constraint
5744    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5745    Exclude {
5746        name: Option<Identifier>,
5747        /// Index access method (gist, btree, etc.)
5748        #[serde(default)]
5749        using: Option<String>,
5750        /// Elements: (expression, operator) pairs
5751        elements: Vec<ExcludeElement>,
5752        /// INCLUDE columns
5753        #[serde(default)]
5754        include_columns: Vec<Identifier>,
5755        /// WHERE predicate
5756        #[serde(default)]
5757        where_clause: Option<Box<Expression>>,
5758        /// WITH (storage_parameters)
5759        #[serde(default)]
5760        with_params: Vec<(String, String)>,
5761        /// USING INDEX TABLESPACE tablespace_name
5762        #[serde(default)]
5763        using_index_tablespace: Option<String>,
5764        #[serde(default)]
5765        modifiers: ConstraintModifiers,
5766    },
5767    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5768    Tags(Tags),
5769    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5770    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5771    /// for all deferrable constraints in the table
5772    InitiallyDeferred {
5773        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5774        deferred: bool,
5775    },
5776}
5777
5778/// Element in an EXCLUDE constraint: expression WITH operator
5779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5780#[cfg_attr(feature = "bindings", derive(TS))]
5781pub struct ExcludeElement {
5782    /// The column expression (may include operator class, ordering, nulls)
5783    pub expression: String,
5784    /// The operator (e.g., &&, =)
5785    pub operator: String,
5786}
5787
5788/// Action for LIKE clause options
5789#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5790#[cfg_attr(feature = "bindings", derive(TS))]
5791pub enum LikeOptionAction {
5792    Including,
5793    Excluding,
5794}
5795
5796/// MATCH type for foreign keys
5797#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5798#[cfg_attr(feature = "bindings", derive(TS))]
5799pub enum MatchType {
5800    Full,
5801    Partial,
5802    Simple,
5803}
5804
5805/// Foreign key reference
5806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5807#[cfg_attr(feature = "bindings", derive(TS))]
5808pub struct ForeignKeyRef {
5809    pub table: TableRef,
5810    pub columns: Vec<Identifier>,
5811    pub on_delete: Option<ReferentialAction>,
5812    pub on_update: Option<ReferentialAction>,
5813    /// True if ON UPDATE appears before ON DELETE in the original SQL
5814    #[serde(default)]
5815    pub on_update_first: bool,
5816    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5817    #[serde(default)]
5818    pub match_type: Option<MatchType>,
5819    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5820    #[serde(default)]
5821    pub match_after_actions: bool,
5822    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5823    #[serde(default)]
5824    pub constraint_name: Option<String>,
5825    /// DEFERRABLE / NOT DEFERRABLE
5826    #[serde(default)]
5827    pub deferrable: Option<bool>,
5828    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5829    #[serde(default)]
5830    pub has_foreign_key_keywords: bool,
5831}
5832
5833/// Referential action for foreign keys
5834#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5835#[cfg_attr(feature = "bindings", derive(TS))]
5836pub enum ReferentialAction {
5837    Cascade,
5838    SetNull,
5839    SetDefault,
5840    Restrict,
5841    NoAction,
5842}
5843
5844/// DROP TABLE statement
5845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5846#[cfg_attr(feature = "bindings", derive(TS))]
5847pub struct DropTable {
5848    pub names: Vec<TableRef>,
5849    pub if_exists: bool,
5850    pub cascade: bool,
5851    /// Oracle: CASCADE CONSTRAINTS
5852    #[serde(default)]
5853    pub cascade_constraints: bool,
5854    /// Oracle: PURGE
5855    #[serde(default)]
5856    pub purge: bool,
5857    /// Comments that appear before the DROP keyword (e.g., leading line comments)
5858    #[serde(default)]
5859    pub leading_comments: Vec<String>,
5860}
5861
5862impl DropTable {
5863    pub fn new(name: impl Into<String>) -> Self {
5864        Self {
5865            names: vec![TableRef::new(name)],
5866            if_exists: false,
5867            cascade: false,
5868            cascade_constraints: false,
5869            purge: false,
5870            leading_comments: Vec::new(),
5871        }
5872    }
5873}
5874
5875/// ALTER TABLE statement
5876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5877#[cfg_attr(feature = "bindings", derive(TS))]
5878pub struct AlterTable {
5879    pub name: TableRef,
5880    pub actions: Vec<AlterTableAction>,
5881    /// IF EXISTS clause
5882    #[serde(default)]
5883    pub if_exists: bool,
5884    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5885    #[serde(default, skip_serializing_if = "Option::is_none")]
5886    pub algorithm: Option<String>,
5887    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5888    #[serde(default, skip_serializing_if = "Option::is_none")]
5889    pub lock: Option<String>,
5890    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5891    #[serde(default, skip_serializing_if = "Option::is_none")]
5892    pub with_check: Option<String>,
5893    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5894    #[serde(default, skip_serializing_if = "Option::is_none")]
5895    pub partition: Option<Vec<(Identifier, Expression)>>,
5896    /// ClickHouse: ON CLUSTER clause for distributed DDL
5897    #[serde(default, skip_serializing_if = "Option::is_none")]
5898    pub on_cluster: Option<OnCluster>,
5899}
5900
5901impl AlterTable {
5902    pub fn new(name: impl Into<String>) -> Self {
5903        Self {
5904            name: TableRef::new(name),
5905            actions: Vec::new(),
5906            if_exists: false,
5907            algorithm: None,
5908            lock: None,
5909            with_check: None,
5910            partition: None,
5911            on_cluster: None,
5912        }
5913    }
5914}
5915
5916/// Column position for ADD COLUMN (MySQL/MariaDB)
5917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5918#[cfg_attr(feature = "bindings", derive(TS))]
5919pub enum ColumnPosition {
5920    First,
5921    After(Identifier),
5922}
5923
5924/// Actions for ALTER TABLE
5925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5926#[cfg_attr(feature = "bindings", derive(TS))]
5927pub enum AlterTableAction {
5928    AddColumn {
5929        column: ColumnDef,
5930        if_not_exists: bool,
5931        position: Option<ColumnPosition>,
5932    },
5933    DropColumn {
5934        name: Identifier,
5935        if_exists: bool,
5936        cascade: bool,
5937    },
5938    RenameColumn {
5939        old_name: Identifier,
5940        new_name: Identifier,
5941        if_exists: bool,
5942    },
5943    AlterColumn {
5944        name: Identifier,
5945        action: AlterColumnAction,
5946        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5947        #[serde(default)]
5948        use_modify_keyword: bool,
5949    },
5950    RenameTable(TableRef),
5951    AddConstraint(TableConstraint),
5952    DropConstraint {
5953        name: Identifier,
5954        if_exists: bool,
5955    },
5956    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5957    DropForeignKey {
5958        name: Identifier,
5959    },
5960    /// DROP PARTITION action (Hive/BigQuery)
5961    DropPartition {
5962        /// List of partitions to drop (each partition is a list of key=value pairs)
5963        partitions: Vec<Vec<(Identifier, Expression)>>,
5964        if_exists: bool,
5965    },
5966    /// ADD PARTITION action (Hive/Spark)
5967    AddPartition {
5968        /// The partition expression
5969        partition: Expression,
5970        if_not_exists: bool,
5971        location: Option<Expression>,
5972    },
5973    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
5974    Delete {
5975        where_clause: Expression,
5976    },
5977    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
5978    SwapWith(TableRef),
5979    /// SET property action (Snowflake): ALTER TABLE t SET property=value
5980    SetProperty {
5981        properties: Vec<(String, Expression)>,
5982    },
5983    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
5984    UnsetProperty {
5985        properties: Vec<String>,
5986    },
5987    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
5988    ClusterBy {
5989        expressions: Vec<Expression>,
5990    },
5991    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
5992    SetTag {
5993        expressions: Vec<(String, Expression)>,
5994    },
5995    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
5996    UnsetTag {
5997        names: Vec<String>,
5998    },
5999    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6000    SetOptions {
6001        expressions: Vec<Expression>,
6002    },
6003    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6004    AlterIndex {
6005        name: Identifier,
6006        visible: bool,
6007    },
6008    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6009    SetAttribute {
6010        attribute: String,
6011    },
6012    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6013    SetStageFileFormat {
6014        options: Option<Expression>,
6015    },
6016    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6017    SetStageCopyOptions {
6018        options: Option<Expression>,
6019    },
6020    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6021    AddColumns {
6022        columns: Vec<ColumnDef>,
6023        cascade: bool,
6024    },
6025    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6026    DropColumns {
6027        names: Vec<Identifier>,
6028    },
6029    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6030    /// In SingleStore, data_type can be omitted for simple column renames
6031    ChangeColumn {
6032        old_name: Identifier,
6033        new_name: Identifier,
6034        #[serde(default, skip_serializing_if = "Option::is_none")]
6035        data_type: Option<DataType>,
6036        comment: Option<String>,
6037        #[serde(default)]
6038        cascade: bool,
6039    },
6040    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6041    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6042    AlterSortKey {
6043        /// AUTO or NONE keyword
6044        this: Option<String>,
6045        /// Column list for (col1, col2) syntax
6046        expressions: Vec<Expression>,
6047        /// Whether COMPOUND keyword was present
6048        compound: bool,
6049    },
6050    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6051    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6052    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6053    AlterDistStyle {
6054        /// Distribution style: ALL, EVEN, AUTO, or KEY
6055        style: String,
6056        /// DISTKEY column (only when style is KEY)
6057        distkey: Option<Identifier>,
6058    },
6059    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6060    SetTableProperties {
6061        properties: Vec<(Expression, Expression)>,
6062    },
6063    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6064    SetLocation {
6065        location: String,
6066    },
6067    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6068    SetFileFormat {
6069        format: String,
6070    },
6071    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6072    ReplacePartition {
6073        partition: Expression,
6074        source: Option<Box<Expression>>,
6075    },
6076    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6077    Raw {
6078        sql: String,
6079    },
6080}
6081
6082/// Actions for ALTER COLUMN
6083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6084#[cfg_attr(feature = "bindings", derive(TS))]
6085pub enum AlterColumnAction {
6086    SetDataType {
6087        data_type: DataType,
6088        /// USING expression for type conversion (PostgreSQL)
6089        using: Option<Expression>,
6090        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6091        #[serde(default, skip_serializing_if = "Option::is_none")]
6092        collate: Option<String>,
6093    },
6094    SetDefault(Expression),
6095    DropDefault,
6096    SetNotNull,
6097    DropNotNull,
6098    /// Set column comment
6099    Comment(String),
6100    /// MySQL: SET VISIBLE
6101    SetVisible,
6102    /// MySQL: SET INVISIBLE
6103    SetInvisible,
6104}
6105
6106/// CREATE INDEX statement
6107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6108#[cfg_attr(feature = "bindings", derive(TS))]
6109pub struct CreateIndex {
6110    pub name: Identifier,
6111    pub table: TableRef,
6112    pub columns: Vec<IndexColumn>,
6113    pub unique: bool,
6114    pub if_not_exists: bool,
6115    pub using: Option<String>,
6116    /// TSQL CLUSTERED/NONCLUSTERED modifier
6117    #[serde(default)]
6118    pub clustered: Option<String>,
6119    /// PostgreSQL CONCURRENTLY modifier
6120    #[serde(default)]
6121    pub concurrently: bool,
6122    /// PostgreSQL WHERE clause for partial indexes
6123    #[serde(default)]
6124    pub where_clause: Option<Box<Expression>>,
6125    /// PostgreSQL INCLUDE columns
6126    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6127    pub include_columns: Vec<Identifier>,
6128    /// TSQL WITH options (e.g., allow_page_locks=on)
6129    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6130    pub with_options: Vec<(String, String)>,
6131    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6132    #[serde(default)]
6133    pub on_filegroup: Option<String>,
6134}
6135
6136impl CreateIndex {
6137    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6138        Self {
6139            name: Identifier::new(name),
6140            table: TableRef::new(table),
6141            columns: Vec::new(),
6142            unique: false,
6143            if_not_exists: false,
6144            using: None,
6145            clustered: None,
6146            concurrently: false,
6147            where_clause: None,
6148            include_columns: Vec::new(),
6149            with_options: Vec::new(),
6150            on_filegroup: None,
6151        }
6152    }
6153}
6154
6155/// Index column specification
6156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6157#[cfg_attr(feature = "bindings", derive(TS))]
6158pub struct IndexColumn {
6159    pub column: Identifier,
6160    pub desc: bool,
6161    /// Explicit ASC keyword was present
6162    #[serde(default)]
6163    pub asc: bool,
6164    pub nulls_first: Option<bool>,
6165    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6166    #[serde(default, skip_serializing_if = "Option::is_none")]
6167    pub opclass: Option<String>,
6168}
6169
6170/// DROP INDEX statement
6171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6172#[cfg_attr(feature = "bindings", derive(TS))]
6173pub struct DropIndex {
6174    pub name: Identifier,
6175    pub table: Option<TableRef>,
6176    pub if_exists: bool,
6177    /// PostgreSQL CONCURRENTLY modifier
6178    #[serde(default)]
6179    pub concurrently: bool,
6180}
6181
6182impl DropIndex {
6183    pub fn new(name: impl Into<String>) -> Self {
6184        Self {
6185            name: Identifier::new(name),
6186            table: None,
6187            if_exists: false,
6188            concurrently: false,
6189        }
6190    }
6191}
6192
6193/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6195#[cfg_attr(feature = "bindings", derive(TS))]
6196pub struct ViewColumn {
6197    pub name: Identifier,
6198    pub comment: Option<String>,
6199    /// BigQuery: OPTIONS (key=value, ...) on column
6200    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6201    pub options: Vec<Expression>,
6202}
6203
6204impl ViewColumn {
6205    pub fn new(name: impl Into<String>) -> Self {
6206        Self {
6207            name: Identifier::new(name),
6208            comment: None,
6209            options: Vec::new(),
6210        }
6211    }
6212
6213    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6214        Self {
6215            name: Identifier::new(name),
6216            comment: Some(comment.into()),
6217            options: Vec::new(),
6218        }
6219    }
6220}
6221
6222/// CREATE VIEW statement
6223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6224#[cfg_attr(feature = "bindings", derive(TS))]
6225pub struct CreateView {
6226    pub name: TableRef,
6227    pub columns: Vec<ViewColumn>,
6228    pub query: Expression,
6229    pub or_replace: bool,
6230    pub if_not_exists: bool,
6231    pub materialized: bool,
6232    pub temporary: bool,
6233    /// Snowflake: SECURE VIEW
6234    #[serde(default)]
6235    pub secure: bool,
6236    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6237    #[serde(skip_serializing_if = "Option::is_none")]
6238    pub algorithm: Option<String>,
6239    /// MySQL: DEFINER=user@host
6240    #[serde(skip_serializing_if = "Option::is_none")]
6241    pub definer: Option<String>,
6242    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6243    #[serde(skip_serializing_if = "Option::is_none")]
6244    pub security: Option<FunctionSecurity>,
6245    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6246    #[serde(default = "default_true")]
6247    pub security_sql_style: bool,
6248    /// Whether the query was parenthesized: AS (SELECT ...)
6249    #[serde(default)]
6250    pub query_parenthesized: bool,
6251    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6252    #[serde(skip_serializing_if = "Option::is_none")]
6253    pub locking_mode: Option<String>,
6254    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6255    #[serde(skip_serializing_if = "Option::is_none")]
6256    pub locking_access: Option<String>,
6257    /// Snowflake: COPY GRANTS
6258    #[serde(default)]
6259    pub copy_grants: bool,
6260    /// Snowflake: COMMENT = 'text'
6261    #[serde(skip_serializing_if = "Option::is_none", default)]
6262    pub comment: Option<String>,
6263    /// Snowflake: TAG (name='value', ...)
6264    #[serde(default)]
6265    pub tags: Vec<(String, String)>,
6266    /// BigQuery: OPTIONS (key=value, ...)
6267    #[serde(default)]
6268    pub options: Vec<Expression>,
6269    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6270    #[serde(skip_serializing_if = "Option::is_none", default)]
6271    pub build: Option<String>,
6272    /// Doris: REFRESH property for materialized views
6273    #[serde(skip_serializing_if = "Option::is_none", default)]
6274    pub refresh: Option<Box<RefreshTriggerProperty>>,
6275    /// Doris: Schema with typed column definitions for materialized views
6276    /// This is used instead of `columns` when the view has typed column definitions
6277    #[serde(skip_serializing_if = "Option::is_none", default)]
6278    pub schema: Option<Box<Schema>>,
6279    /// Doris: KEY (columns) for materialized views
6280    #[serde(skip_serializing_if = "Option::is_none", default)]
6281    pub unique_key: Option<Box<UniqueKeyProperty>>,
6282    /// Redshift: WITH NO SCHEMA BINDING
6283    #[serde(default)]
6284    pub no_schema_binding: bool,
6285    /// Redshift: AUTO REFRESH YES|NO for materialized views
6286    #[serde(skip_serializing_if = "Option::is_none", default)]
6287    pub auto_refresh: Option<bool>,
6288    /// ClickHouse: ON CLUSTER clause
6289    #[serde(default, skip_serializing_if = "Option::is_none")]
6290    pub on_cluster: Option<OnCluster>,
6291    /// ClickHouse: TO destination_table
6292    #[serde(default, skip_serializing_if = "Option::is_none")]
6293    pub to_table: Option<TableRef>,
6294    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6295    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6296    pub table_properties: Vec<Expression>,
6297}
6298
6299impl CreateView {
6300    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6301        Self {
6302            name: TableRef::new(name),
6303            columns: Vec::new(),
6304            query,
6305            or_replace: false,
6306            if_not_exists: false,
6307            materialized: false,
6308            temporary: false,
6309            secure: false,
6310            algorithm: None,
6311            definer: None,
6312            security: None,
6313            security_sql_style: true,
6314            query_parenthesized: false,
6315            locking_mode: None,
6316            locking_access: None,
6317            copy_grants: false,
6318            comment: None,
6319            tags: Vec::new(),
6320            options: Vec::new(),
6321            build: None,
6322            refresh: None,
6323            schema: None,
6324            unique_key: None,
6325            no_schema_binding: false,
6326            auto_refresh: None,
6327            on_cluster: None,
6328            to_table: None,
6329            table_properties: Vec::new(),
6330        }
6331    }
6332}
6333
6334/// DROP VIEW statement
6335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6336#[cfg_attr(feature = "bindings", derive(TS))]
6337pub struct DropView {
6338    pub name: TableRef,
6339    pub if_exists: bool,
6340    pub materialized: bool,
6341}
6342
6343impl DropView {
6344    pub fn new(name: impl Into<String>) -> Self {
6345        Self {
6346            name: TableRef::new(name),
6347            if_exists: false,
6348            materialized: false,
6349        }
6350    }
6351}
6352
6353/// TRUNCATE TABLE statement
6354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6355#[cfg_attr(feature = "bindings", derive(TS))]
6356pub struct Truncate {
6357    /// Target of TRUNCATE (TABLE vs DATABASE)
6358    #[serde(default)]
6359    pub target: TruncateTarget,
6360    /// IF EXISTS clause
6361    #[serde(default)]
6362    pub if_exists: bool,
6363    pub table: TableRef,
6364    /// ClickHouse: ON CLUSTER clause for distributed DDL
6365    #[serde(default, skip_serializing_if = "Option::is_none")]
6366    pub on_cluster: Option<OnCluster>,
6367    pub cascade: bool,
6368    /// Additional tables for multi-table TRUNCATE
6369    #[serde(default)]
6370    pub extra_tables: Vec<TruncateTableEntry>,
6371    /// RESTART IDENTITY or CONTINUE IDENTITY
6372    #[serde(default)]
6373    pub identity: Option<TruncateIdentity>,
6374    /// RESTRICT option (alternative to CASCADE)
6375    #[serde(default)]
6376    pub restrict: bool,
6377    /// Hive PARTITION clause: PARTITION(key=value, ...)
6378    #[serde(default, skip_serializing_if = "Option::is_none")]
6379    pub partition: Option<Box<Expression>>,
6380}
6381
6382/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6384#[cfg_attr(feature = "bindings", derive(TS))]
6385pub struct TruncateTableEntry {
6386    pub table: TableRef,
6387    /// Whether the table has a * suffix (inherit children)
6388    #[serde(default)]
6389    pub star: bool,
6390}
6391
6392/// TRUNCATE target type
6393#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6394#[cfg_attr(feature = "bindings", derive(TS))]
6395pub enum TruncateTarget {
6396    Table,
6397    Database,
6398}
6399
6400impl Default for TruncateTarget {
6401    fn default() -> Self {
6402        TruncateTarget::Table
6403    }
6404}
6405
6406/// TRUNCATE identity option
6407#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6408#[cfg_attr(feature = "bindings", derive(TS))]
6409pub enum TruncateIdentity {
6410    Restart,
6411    Continue,
6412}
6413
6414impl Truncate {
6415    pub fn new(table: impl Into<String>) -> Self {
6416        Self {
6417            target: TruncateTarget::Table,
6418            if_exists: false,
6419            table: TableRef::new(table),
6420            on_cluster: None,
6421            cascade: false,
6422            extra_tables: Vec::new(),
6423            identity: None,
6424            restrict: false,
6425            partition: None,
6426        }
6427    }
6428}
6429
6430/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6432#[cfg_attr(feature = "bindings", derive(TS))]
6433pub struct Use {
6434    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6435    pub kind: Option<UseKind>,
6436    /// The name of the object
6437    pub this: Identifier,
6438}
6439
6440/// Kind of USE statement
6441#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6442#[cfg_attr(feature = "bindings", derive(TS))]
6443pub enum UseKind {
6444    Database,
6445    Schema,
6446    Role,
6447    Warehouse,
6448    Catalog,
6449    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6450    SecondaryRoles,
6451}
6452
6453/// SET variable statement
6454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6455#[cfg_attr(feature = "bindings", derive(TS))]
6456pub struct SetStatement {
6457    /// The items being set
6458    pub items: Vec<SetItem>,
6459}
6460
6461/// A single SET item (variable assignment)
6462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6463#[cfg_attr(feature = "bindings", derive(TS))]
6464pub struct SetItem {
6465    /// The variable name
6466    pub name: Expression,
6467    /// The value to set
6468    pub value: Expression,
6469    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6470    pub kind: Option<String>,
6471    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6472    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6473    pub no_equals: bool,
6474}
6475
6476/// CACHE TABLE statement (Spark)
6477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6478#[cfg_attr(feature = "bindings", derive(TS))]
6479pub struct Cache {
6480    /// The table to cache
6481    pub table: Identifier,
6482    /// LAZY keyword - defer caching until first use
6483    pub lazy: bool,
6484    /// Optional OPTIONS clause (key-value pairs)
6485    pub options: Vec<(Expression, Expression)>,
6486    /// Optional AS clause with query
6487    pub query: Option<Expression>,
6488}
6489
6490/// UNCACHE TABLE statement (Spark)
6491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6492#[cfg_attr(feature = "bindings", derive(TS))]
6493pub struct Uncache {
6494    /// The table to uncache
6495    pub table: Identifier,
6496    /// IF EXISTS clause
6497    pub if_exists: bool,
6498}
6499
6500/// LOAD DATA statement (Hive)
6501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6502#[cfg_attr(feature = "bindings", derive(TS))]
6503pub struct LoadData {
6504    /// LOCAL keyword - load from local filesystem
6505    pub local: bool,
6506    /// The path to load data from (INPATH value)
6507    pub inpath: String,
6508    /// Whether to overwrite existing data
6509    pub overwrite: bool,
6510    /// The target table
6511    pub table: Expression,
6512    /// Optional PARTITION clause with key-value pairs
6513    pub partition: Vec<(Identifier, Expression)>,
6514    /// Optional INPUTFORMAT clause
6515    pub input_format: Option<String>,
6516    /// Optional SERDE clause
6517    pub serde: Option<String>,
6518}
6519
6520/// PRAGMA statement (SQLite)
6521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6522#[cfg_attr(feature = "bindings", derive(TS))]
6523pub struct Pragma {
6524    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6525    pub schema: Option<Identifier>,
6526    /// The pragma name
6527    pub name: Identifier,
6528    /// Optional value for assignment (PRAGMA name = value)
6529    pub value: Option<Expression>,
6530    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6531    pub args: Vec<Expression>,
6532}
6533
6534/// A privilege with optional column list for GRANT/REVOKE
6535/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6537#[cfg_attr(feature = "bindings", derive(TS))]
6538pub struct Privilege {
6539    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6540    pub name: String,
6541    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6542    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6543    pub columns: Vec<String>,
6544}
6545
6546/// Principal in GRANT/REVOKE (user, role, etc.)
6547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6548#[cfg_attr(feature = "bindings", derive(TS))]
6549pub struct GrantPrincipal {
6550    /// The name of the principal
6551    pub name: Identifier,
6552    /// Whether prefixed with ROLE keyword
6553    pub is_role: bool,
6554    /// Whether prefixed with GROUP keyword (Redshift)
6555    #[serde(default)]
6556    pub is_group: bool,
6557}
6558
6559/// GRANT statement
6560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6561#[cfg_attr(feature = "bindings", derive(TS))]
6562pub struct Grant {
6563    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6564    pub privileges: Vec<Privilege>,
6565    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6566    pub kind: Option<String>,
6567    /// The object to grant on
6568    pub securable: Identifier,
6569    /// Function parameter types (for FUNCTION kind)
6570    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6571    pub function_params: Vec<String>,
6572    /// The grantees
6573    pub principals: Vec<GrantPrincipal>,
6574    /// WITH GRANT OPTION
6575    pub grant_option: bool,
6576    /// TSQL: AS principal (the grantor role)
6577    #[serde(default, skip_serializing_if = "Option::is_none")]
6578    pub as_principal: Option<Identifier>,
6579}
6580
6581/// REVOKE statement
6582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6583#[cfg_attr(feature = "bindings", derive(TS))]
6584pub struct Revoke {
6585    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6586    pub privileges: Vec<Privilege>,
6587    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6588    pub kind: Option<String>,
6589    /// The object to revoke from
6590    pub securable: Identifier,
6591    /// Function parameter types (for FUNCTION kind)
6592    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6593    pub function_params: Vec<String>,
6594    /// The grantees
6595    pub principals: Vec<GrantPrincipal>,
6596    /// GRANT OPTION FOR
6597    pub grant_option: bool,
6598    /// CASCADE
6599    pub cascade: bool,
6600    /// RESTRICT
6601    #[serde(default)]
6602    pub restrict: bool,
6603}
6604
6605/// COMMENT ON statement
6606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6607#[cfg_attr(feature = "bindings", derive(TS))]
6608pub struct Comment {
6609    /// The object being commented on
6610    pub this: Expression,
6611    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6612    pub kind: String,
6613    /// The comment text expression
6614    pub expression: Expression,
6615    /// IF EXISTS clause
6616    pub exists: bool,
6617    /// MATERIALIZED keyword
6618    pub materialized: bool,
6619}
6620
6621// ============================================================================
6622// Phase 4: Additional DDL Statements
6623// ============================================================================
6624
6625/// ALTER VIEW statement
6626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6627#[cfg_attr(feature = "bindings", derive(TS))]
6628pub struct AlterView {
6629    pub name: TableRef,
6630    pub actions: Vec<AlterViewAction>,
6631    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6632    #[serde(default, skip_serializing_if = "Option::is_none")]
6633    pub algorithm: Option<String>,
6634    /// MySQL: DEFINER = 'user'@'host'
6635    #[serde(default, skip_serializing_if = "Option::is_none")]
6636    pub definer: Option<String>,
6637    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6638    #[serde(default, skip_serializing_if = "Option::is_none")]
6639    pub sql_security: Option<String>,
6640    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6641    #[serde(default, skip_serializing_if = "Option::is_none")]
6642    pub with_option: Option<String>,
6643    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6644    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6645    pub columns: Vec<ViewColumn>,
6646}
6647
6648/// Actions for ALTER VIEW
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub enum AlterViewAction {
6652    /// Rename the view
6653    Rename(TableRef),
6654    /// Change owner
6655    OwnerTo(Identifier),
6656    /// Set schema
6657    SetSchema(Identifier),
6658    /// Set authorization (Trino/Presto)
6659    SetAuthorization(String),
6660    /// Alter column
6661    AlterColumn {
6662        name: Identifier,
6663        action: AlterColumnAction,
6664    },
6665    /// Redefine view as query (SELECT, UNION, etc.)
6666    AsSelect(Box<Expression>),
6667    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6668    SetTblproperties(Vec<(String, String)>),
6669    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6670    UnsetTblproperties(Vec<String>),
6671}
6672
6673impl AlterView {
6674    pub fn new(name: impl Into<String>) -> Self {
6675        Self {
6676            name: TableRef::new(name),
6677            actions: Vec::new(),
6678            algorithm: None,
6679            definer: None,
6680            sql_security: None,
6681            with_option: None,
6682            columns: Vec::new(),
6683        }
6684    }
6685}
6686
6687/// ALTER INDEX statement
6688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6689#[cfg_attr(feature = "bindings", derive(TS))]
6690pub struct AlterIndex {
6691    pub name: Identifier,
6692    pub table: Option<TableRef>,
6693    pub actions: Vec<AlterIndexAction>,
6694}
6695
6696/// Actions for ALTER INDEX
6697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6698#[cfg_attr(feature = "bindings", derive(TS))]
6699pub enum AlterIndexAction {
6700    /// Rename the index
6701    Rename(Identifier),
6702    /// Set tablespace
6703    SetTablespace(Identifier),
6704    /// Set visibility (MySQL)
6705    Visible(bool),
6706}
6707
6708impl AlterIndex {
6709    pub fn new(name: impl Into<String>) -> Self {
6710        Self {
6711            name: Identifier::new(name),
6712            table: None,
6713            actions: Vec::new(),
6714        }
6715    }
6716}
6717
6718/// CREATE SCHEMA statement
6719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6720#[cfg_attr(feature = "bindings", derive(TS))]
6721pub struct CreateSchema {
6722    pub name: Identifier,
6723    pub if_not_exists: bool,
6724    pub authorization: Option<Identifier>,
6725    #[serde(default)]
6726    pub clone_from: Option<Identifier>,
6727    /// AT/BEFORE clause for time travel (Snowflake)
6728    #[serde(default)]
6729    pub at_clause: Option<Expression>,
6730    /// Schema properties like DEFAULT COLLATE
6731    #[serde(default)]
6732    pub properties: Vec<Expression>,
6733    /// Leading comments before the statement
6734    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6735    pub leading_comments: Vec<String>,
6736}
6737
6738impl CreateSchema {
6739    pub fn new(name: impl Into<String>) -> Self {
6740        Self {
6741            name: Identifier::new(name),
6742            if_not_exists: false,
6743            authorization: None,
6744            clone_from: None,
6745            at_clause: None,
6746            properties: Vec::new(),
6747            leading_comments: Vec::new(),
6748        }
6749    }
6750}
6751
6752/// DROP SCHEMA statement
6753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6754#[cfg_attr(feature = "bindings", derive(TS))]
6755pub struct DropSchema {
6756    pub name: Identifier,
6757    pub if_exists: bool,
6758    pub cascade: bool,
6759}
6760
6761impl DropSchema {
6762    pub fn new(name: impl Into<String>) -> Self {
6763        Self {
6764            name: Identifier::new(name),
6765            if_exists: false,
6766            cascade: false,
6767        }
6768    }
6769}
6770
6771/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6773#[cfg_attr(feature = "bindings", derive(TS))]
6774pub struct DropNamespace {
6775    pub name: Identifier,
6776    pub if_exists: bool,
6777    pub cascade: bool,
6778}
6779
6780impl DropNamespace {
6781    pub fn new(name: impl Into<String>) -> Self {
6782        Self {
6783            name: Identifier::new(name),
6784            if_exists: false,
6785            cascade: false,
6786        }
6787    }
6788}
6789
6790/// CREATE DATABASE statement
6791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6792#[cfg_attr(feature = "bindings", derive(TS))]
6793pub struct CreateDatabase {
6794    pub name: Identifier,
6795    pub if_not_exists: bool,
6796    pub options: Vec<DatabaseOption>,
6797    /// Snowflake CLONE source
6798    #[serde(default)]
6799    pub clone_from: Option<Identifier>,
6800    /// AT/BEFORE clause for time travel (Snowflake)
6801    #[serde(default)]
6802    pub at_clause: Option<Expression>,
6803}
6804
6805/// Database option
6806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6807#[cfg_attr(feature = "bindings", derive(TS))]
6808pub enum DatabaseOption {
6809    CharacterSet(String),
6810    Collate(String),
6811    Owner(Identifier),
6812    Template(Identifier),
6813    Encoding(String),
6814    Location(String),
6815}
6816
6817impl CreateDatabase {
6818    pub fn new(name: impl Into<String>) -> Self {
6819        Self {
6820            name: Identifier::new(name),
6821            if_not_exists: false,
6822            options: Vec::new(),
6823            clone_from: None,
6824            at_clause: None,
6825        }
6826    }
6827}
6828
6829/// DROP DATABASE statement
6830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6831#[cfg_attr(feature = "bindings", derive(TS))]
6832pub struct DropDatabase {
6833    pub name: Identifier,
6834    pub if_exists: bool,
6835}
6836
6837impl DropDatabase {
6838    pub fn new(name: impl Into<String>) -> Self {
6839        Self {
6840            name: Identifier::new(name),
6841            if_exists: false,
6842        }
6843    }
6844}
6845
6846/// CREATE FUNCTION statement
6847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6848#[cfg_attr(feature = "bindings", derive(TS))]
6849pub struct CreateFunction {
6850    pub name: TableRef,
6851    pub parameters: Vec<FunctionParameter>,
6852    pub return_type: Option<DataType>,
6853    pub body: Option<FunctionBody>,
6854    pub or_replace: bool,
6855    pub if_not_exists: bool,
6856    pub temporary: bool,
6857    pub language: Option<String>,
6858    pub deterministic: Option<bool>,
6859    pub returns_null_on_null_input: Option<bool>,
6860    pub security: Option<FunctionSecurity>,
6861    /// Whether parentheses were present in the original syntax
6862    #[serde(default = "default_true")]
6863    pub has_parens: bool,
6864    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6865    #[serde(default)]
6866    pub sql_data_access: Option<SqlDataAccess>,
6867    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6868    #[serde(default, skip_serializing_if = "Option::is_none")]
6869    pub returns_table_body: Option<String>,
6870    /// True if LANGUAGE clause appears before RETURNS clause
6871    #[serde(default)]
6872    pub language_first: bool,
6873    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6874    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6875    pub set_options: Vec<FunctionSetOption>,
6876    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6877    #[serde(default)]
6878    pub strict: bool,
6879    /// BigQuery: OPTIONS (key=value, ...)
6880    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6881    pub options: Vec<Expression>,
6882    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6883    #[serde(default)]
6884    pub is_table_function: bool,
6885    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6886    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6887    pub property_order: Vec<FunctionPropertyKind>,
6888    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6889    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6890    pub environment: Vec<Expression>,
6891}
6892
6893/// A SET option in CREATE FUNCTION (PostgreSQL)
6894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6895#[cfg_attr(feature = "bindings", derive(TS))]
6896pub struct FunctionSetOption {
6897    pub name: String,
6898    pub value: FunctionSetValue,
6899}
6900
6901/// The value of a SET option
6902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6903#[cfg_attr(feature = "bindings", derive(TS))]
6904pub enum FunctionSetValue {
6905    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6906    Value { value: String, use_to: bool },
6907    /// SET key FROM CURRENT
6908    FromCurrent,
6909}
6910
6911/// SQL data access characteristics for functions
6912#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6913#[cfg_attr(feature = "bindings", derive(TS))]
6914pub enum SqlDataAccess {
6915    /// NO SQL
6916    NoSql,
6917    /// CONTAINS SQL
6918    ContainsSql,
6919    /// READS SQL DATA
6920    ReadsSqlData,
6921    /// MODIFIES SQL DATA
6922    ModifiesSqlData,
6923}
6924
6925/// Types of properties in CREATE FUNCTION for tracking their original order
6926#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6927#[cfg_attr(feature = "bindings", derive(TS))]
6928pub enum FunctionPropertyKind {
6929    /// SET option
6930    Set,
6931    /// AS body
6932    As,
6933    /// LANGUAGE clause
6934    Language,
6935    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6936    Determinism,
6937    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6938    NullInput,
6939    /// SECURITY DEFINER/INVOKER
6940    Security,
6941    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6942    SqlDataAccess,
6943    /// OPTIONS clause (BigQuery)
6944    Options,
6945    /// ENVIRONMENT clause (Databricks)
6946    Environment,
6947}
6948
6949/// Function parameter
6950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6951#[cfg_attr(feature = "bindings", derive(TS))]
6952pub struct FunctionParameter {
6953    pub name: Option<Identifier>,
6954    pub data_type: DataType,
6955    pub mode: Option<ParameterMode>,
6956    pub default: Option<Expression>,
6957    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
6958    #[serde(default, skip_serializing_if = "Option::is_none")]
6959    pub mode_text: Option<String>,
6960}
6961
6962/// Parameter mode (IN, OUT, INOUT, VARIADIC)
6963#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6964#[cfg_attr(feature = "bindings", derive(TS))]
6965pub enum ParameterMode {
6966    In,
6967    Out,
6968    InOut,
6969    Variadic,
6970}
6971
6972/// Function body
6973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6974#[cfg_attr(feature = "bindings", derive(TS))]
6975pub enum FunctionBody {
6976    /// AS $$ ... $$ (dollar-quoted)
6977    Block(String),
6978    /// AS 'string' (single-quoted string literal body)
6979    StringLiteral(String),
6980    /// AS 'expression'
6981    Expression(Expression),
6982    /// EXTERNAL NAME 'library'
6983    External(String),
6984    /// RETURN expression
6985    Return(Expression),
6986    /// BEGIN ... END block with parsed statements
6987    Statements(Vec<Expression>),
6988    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
6989    /// Stores (content, optional_tag)
6990    DollarQuoted {
6991        content: String,
6992        tag: Option<String>,
6993    },
6994}
6995
6996/// Function security (DEFINER, INVOKER, or NONE)
6997#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6998#[cfg_attr(feature = "bindings", derive(TS))]
6999pub enum FunctionSecurity {
7000    Definer,
7001    Invoker,
7002    /// StarRocks/MySQL: SECURITY NONE
7003    None,
7004}
7005
7006impl CreateFunction {
7007    pub fn new(name: impl Into<String>) -> Self {
7008        Self {
7009            name: TableRef::new(name),
7010            parameters: Vec::new(),
7011            return_type: None,
7012            body: None,
7013            or_replace: false,
7014            if_not_exists: false,
7015            temporary: false,
7016            language: None,
7017            deterministic: None,
7018            returns_null_on_null_input: None,
7019            security: None,
7020            has_parens: true,
7021            sql_data_access: None,
7022            returns_table_body: None,
7023            language_first: false,
7024            set_options: Vec::new(),
7025            strict: false,
7026            options: Vec::new(),
7027            is_table_function: false,
7028            property_order: Vec::new(),
7029            environment: Vec::new(),
7030        }
7031    }
7032}
7033
7034/// DROP FUNCTION statement
7035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7036#[cfg_attr(feature = "bindings", derive(TS))]
7037pub struct DropFunction {
7038    pub name: TableRef,
7039    pub parameters: Option<Vec<DataType>>,
7040    pub if_exists: bool,
7041    pub cascade: bool,
7042}
7043
7044impl DropFunction {
7045    pub fn new(name: impl Into<String>) -> Self {
7046        Self {
7047            name: TableRef::new(name),
7048            parameters: None,
7049            if_exists: false,
7050            cascade: false,
7051        }
7052    }
7053}
7054
7055/// CREATE PROCEDURE statement
7056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7057#[cfg_attr(feature = "bindings", derive(TS))]
7058pub struct CreateProcedure {
7059    pub name: TableRef,
7060    pub parameters: Vec<FunctionParameter>,
7061    pub body: Option<FunctionBody>,
7062    pub or_replace: bool,
7063    pub if_not_exists: bool,
7064    pub language: Option<String>,
7065    pub security: Option<FunctionSecurity>,
7066    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7067    #[serde(default)]
7068    pub return_type: Option<DataType>,
7069    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7070    #[serde(default)]
7071    pub execute_as: Option<String>,
7072    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7073    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7074    pub with_options: Vec<String>,
7075    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7076    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7077    pub has_parens: bool,
7078    /// Whether the short form PROC was used (instead of PROCEDURE)
7079    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7080    pub use_proc_keyword: bool,
7081}
7082
7083impl CreateProcedure {
7084    pub fn new(name: impl Into<String>) -> Self {
7085        Self {
7086            name: TableRef::new(name),
7087            parameters: Vec::new(),
7088            body: None,
7089            or_replace: false,
7090            if_not_exists: false,
7091            language: None,
7092            security: None,
7093            return_type: None,
7094            execute_as: None,
7095            with_options: Vec::new(),
7096            has_parens: true,
7097            use_proc_keyword: false,
7098        }
7099    }
7100}
7101
7102/// DROP PROCEDURE statement
7103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7104#[cfg_attr(feature = "bindings", derive(TS))]
7105pub struct DropProcedure {
7106    pub name: TableRef,
7107    pub parameters: Option<Vec<DataType>>,
7108    pub if_exists: bool,
7109    pub cascade: bool,
7110}
7111
7112impl DropProcedure {
7113    pub fn new(name: impl Into<String>) -> Self {
7114        Self {
7115            name: TableRef::new(name),
7116            parameters: None,
7117            if_exists: false,
7118            cascade: false,
7119        }
7120    }
7121}
7122
7123/// Sequence property tag for ordering
7124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7125#[cfg_attr(feature = "bindings", derive(TS))]
7126pub enum SeqPropKind {
7127    Start,
7128    Increment,
7129    Minvalue,
7130    Maxvalue,
7131    Cache,
7132    NoCache,
7133    Cycle,
7134    NoCycle,
7135    OwnedBy,
7136    Order,
7137    NoOrder,
7138    Comment,
7139    /// SHARING=<value> (Oracle)
7140    Sharing,
7141    /// KEEP (Oracle)
7142    Keep,
7143    /// NOKEEP (Oracle)
7144    NoKeep,
7145    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7146    Scale,
7147    /// NOSCALE (Oracle)
7148    NoScale,
7149    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7150    Shard,
7151    /// NOSHARD (Oracle)
7152    NoShard,
7153    /// SESSION (Oracle)
7154    Session,
7155    /// GLOBAL (Oracle)
7156    Global,
7157    /// NOCACHE (single word, Oracle)
7158    NoCacheWord,
7159    /// NOCYCLE (single word, Oracle)
7160    NoCycleWord,
7161    /// NOMINVALUE (single word, Oracle)
7162    NoMinvalueWord,
7163    /// NOMAXVALUE (single word, Oracle)
7164    NoMaxvalueWord,
7165}
7166
7167/// CREATE SEQUENCE statement
7168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7169#[cfg_attr(feature = "bindings", derive(TS))]
7170pub struct CreateSequence {
7171    pub name: TableRef,
7172    pub if_not_exists: bool,
7173    pub temporary: bool,
7174    #[serde(default)]
7175    pub or_replace: bool,
7176    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7177    #[serde(default, skip_serializing_if = "Option::is_none")]
7178    pub as_type: Option<DataType>,
7179    pub increment: Option<i64>,
7180    pub minvalue: Option<SequenceBound>,
7181    pub maxvalue: Option<SequenceBound>,
7182    pub start: Option<i64>,
7183    pub cache: Option<i64>,
7184    pub cycle: bool,
7185    pub owned_by: Option<TableRef>,
7186    /// Whether OWNED BY NONE was specified
7187    #[serde(default)]
7188    pub owned_by_none: bool,
7189    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7190    #[serde(default)]
7191    pub order: Option<bool>,
7192    /// Snowflake: COMMENT = 'value'
7193    #[serde(default)]
7194    pub comment: Option<String>,
7195    /// SHARING=<value> (Oracle)
7196    #[serde(default, skip_serializing_if = "Option::is_none")]
7197    pub sharing: Option<String>,
7198    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7199    #[serde(default, skip_serializing_if = "Option::is_none")]
7200    pub scale_modifier: Option<String>,
7201    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7202    #[serde(default, skip_serializing_if = "Option::is_none")]
7203    pub shard_modifier: Option<String>,
7204    /// Tracks the order in which properties appeared in the source
7205    #[serde(default)]
7206    pub property_order: Vec<SeqPropKind>,
7207}
7208
7209/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7211#[cfg_attr(feature = "bindings", derive(TS))]
7212pub enum SequenceBound {
7213    Value(i64),
7214    None,
7215}
7216
7217impl CreateSequence {
7218    pub fn new(name: impl Into<String>) -> Self {
7219        Self {
7220            name: TableRef::new(name),
7221            if_not_exists: false,
7222            temporary: false,
7223            or_replace: false,
7224            as_type: None,
7225            increment: None,
7226            minvalue: None,
7227            maxvalue: None,
7228            start: None,
7229            cache: None,
7230            cycle: false,
7231            owned_by: None,
7232            owned_by_none: false,
7233            order: None,
7234            comment: None,
7235            sharing: None,
7236            scale_modifier: None,
7237            shard_modifier: None,
7238            property_order: Vec::new(),
7239        }
7240    }
7241}
7242
7243/// DROP SEQUENCE statement
7244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7245#[cfg_attr(feature = "bindings", derive(TS))]
7246pub struct DropSequence {
7247    pub name: TableRef,
7248    pub if_exists: bool,
7249    pub cascade: bool,
7250}
7251
7252impl DropSequence {
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/// ALTER SEQUENCE statement
7263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7264#[cfg_attr(feature = "bindings", derive(TS))]
7265pub struct AlterSequence {
7266    pub name: TableRef,
7267    pub if_exists: bool,
7268    pub increment: Option<i64>,
7269    pub minvalue: Option<SequenceBound>,
7270    pub maxvalue: Option<SequenceBound>,
7271    pub start: Option<i64>,
7272    pub restart: Option<Option<i64>>,
7273    pub cache: Option<i64>,
7274    pub cycle: Option<bool>,
7275    pub owned_by: Option<Option<TableRef>>,
7276}
7277
7278impl AlterSequence {
7279    pub fn new(name: impl Into<String>) -> Self {
7280        Self {
7281            name: TableRef::new(name),
7282            if_exists: false,
7283            increment: None,
7284            minvalue: None,
7285            maxvalue: None,
7286            start: None,
7287            restart: None,
7288            cache: None,
7289            cycle: None,
7290            owned_by: None,
7291        }
7292    }
7293}
7294
7295/// CREATE TRIGGER statement
7296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7297#[cfg_attr(feature = "bindings", derive(TS))]
7298pub struct CreateTrigger {
7299    pub name: Identifier,
7300    pub table: TableRef,
7301    pub timing: TriggerTiming,
7302    pub events: Vec<TriggerEvent>,
7303    pub for_each: TriggerForEach,
7304    pub when: Option<Expression>,
7305    pub body: TriggerBody,
7306    pub or_replace: bool,
7307    pub constraint: bool,
7308    pub deferrable: Option<bool>,
7309    pub initially_deferred: Option<bool>,
7310    pub referencing: Option<TriggerReferencing>,
7311}
7312
7313/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7314#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7315#[cfg_attr(feature = "bindings", derive(TS))]
7316pub enum TriggerTiming {
7317    Before,
7318    After,
7319    InsteadOf,
7320}
7321
7322/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7324#[cfg_attr(feature = "bindings", derive(TS))]
7325pub enum TriggerEvent {
7326    Insert,
7327    Update(Option<Vec<Identifier>>),
7328    Delete,
7329    Truncate,
7330}
7331
7332/// Trigger FOR EACH clause
7333#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7334#[cfg_attr(feature = "bindings", derive(TS))]
7335pub enum TriggerForEach {
7336    Row,
7337    Statement,
7338}
7339
7340/// Trigger body
7341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7342#[cfg_attr(feature = "bindings", derive(TS))]
7343pub enum TriggerBody {
7344    /// EXECUTE FUNCTION/PROCEDURE name(args)
7345    Execute {
7346        function: TableRef,
7347        args: Vec<Expression>,
7348    },
7349    /// BEGIN ... END block
7350    Block(String),
7351}
7352
7353/// Trigger REFERENCING clause
7354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7355#[cfg_attr(feature = "bindings", derive(TS))]
7356pub struct TriggerReferencing {
7357    pub old_table: Option<Identifier>,
7358    pub new_table: Option<Identifier>,
7359    pub old_row: Option<Identifier>,
7360    pub new_row: Option<Identifier>,
7361}
7362
7363impl CreateTrigger {
7364    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7365        Self {
7366            name: Identifier::new(name),
7367            table: TableRef::new(table),
7368            timing: TriggerTiming::Before,
7369            events: Vec::new(),
7370            for_each: TriggerForEach::Row,
7371            when: None,
7372            body: TriggerBody::Execute {
7373                function: TableRef::new(""),
7374                args: Vec::new(),
7375            },
7376            or_replace: false,
7377            constraint: false,
7378            deferrable: None,
7379            initially_deferred: None,
7380            referencing: None,
7381        }
7382    }
7383}
7384
7385/// DROP TRIGGER statement
7386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7387#[cfg_attr(feature = "bindings", derive(TS))]
7388pub struct DropTrigger {
7389    pub name: Identifier,
7390    pub table: Option<TableRef>,
7391    pub if_exists: bool,
7392    pub cascade: bool,
7393}
7394
7395impl DropTrigger {
7396    pub fn new(name: impl Into<String>) -> Self {
7397        Self {
7398            name: Identifier::new(name),
7399            table: None,
7400            if_exists: false,
7401            cascade: false,
7402        }
7403    }
7404}
7405
7406/// CREATE TYPE statement
7407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7408#[cfg_attr(feature = "bindings", derive(TS))]
7409pub struct CreateType {
7410    pub name: TableRef,
7411    pub definition: TypeDefinition,
7412    pub if_not_exists: bool,
7413}
7414
7415/// Type definition
7416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7417#[cfg_attr(feature = "bindings", derive(TS))]
7418pub enum TypeDefinition {
7419    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7420    Enum(Vec<String>),
7421    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7422    Composite(Vec<TypeAttribute>),
7423    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7424    Range {
7425        subtype: DataType,
7426        subtype_diff: Option<String>,
7427        canonical: Option<String>,
7428    },
7429    /// Base type (for advanced usage)
7430    Base {
7431        input: String,
7432        output: String,
7433        internallength: Option<i32>,
7434    },
7435    /// Domain type
7436    Domain {
7437        base_type: DataType,
7438        default: Option<Expression>,
7439        constraints: Vec<DomainConstraint>,
7440    },
7441}
7442
7443/// Type attribute for composite types
7444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7445#[cfg_attr(feature = "bindings", derive(TS))]
7446pub struct TypeAttribute {
7447    pub name: Identifier,
7448    pub data_type: DataType,
7449    pub collate: Option<Identifier>,
7450}
7451
7452/// Domain constraint
7453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7454#[cfg_attr(feature = "bindings", derive(TS))]
7455pub struct DomainConstraint {
7456    pub name: Option<Identifier>,
7457    pub check: Expression,
7458}
7459
7460impl CreateType {
7461    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7462        Self {
7463            name: TableRef::new(name),
7464            definition: TypeDefinition::Enum(values),
7465            if_not_exists: false,
7466        }
7467    }
7468
7469    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7470        Self {
7471            name: TableRef::new(name),
7472            definition: TypeDefinition::Composite(attributes),
7473            if_not_exists: false,
7474        }
7475    }
7476}
7477
7478/// DROP TYPE statement
7479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7480#[cfg_attr(feature = "bindings", derive(TS))]
7481pub struct DropType {
7482    pub name: TableRef,
7483    pub if_exists: bool,
7484    pub cascade: bool,
7485}
7486
7487impl DropType {
7488    pub fn new(name: impl Into<String>) -> Self {
7489        Self {
7490            name: TableRef::new(name),
7491            if_exists: false,
7492            cascade: false,
7493        }
7494    }
7495}
7496
7497/// DESCRIBE statement - shows table structure or query plan
7498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7499#[cfg_attr(feature = "bindings", derive(TS))]
7500pub struct Describe {
7501    /// The target to describe (table name or query)
7502    pub target: Expression,
7503    /// EXTENDED format
7504    pub extended: bool,
7505    /// FORMATTED format
7506    pub formatted: bool,
7507    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7508    #[serde(default)]
7509    pub kind: Option<String>,
7510    /// Properties like type=stage
7511    #[serde(default)]
7512    pub properties: Vec<(String, String)>,
7513    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7514    #[serde(default, skip_serializing_if = "Option::is_none")]
7515    pub style: Option<String>,
7516    /// Partition specification for DESCRIBE PARTITION
7517    #[serde(default)]
7518    pub partition: Option<Box<Expression>>,
7519    /// Leading comments before the statement
7520    #[serde(default)]
7521    pub leading_comments: Vec<String>,
7522    /// AS JSON suffix (Databricks)
7523    #[serde(default)]
7524    pub as_json: bool,
7525}
7526
7527impl Describe {
7528    pub fn new(target: Expression) -> Self {
7529        Self {
7530            target,
7531            extended: false,
7532            formatted: false,
7533            kind: None,
7534            properties: Vec::new(),
7535            style: None,
7536            partition: None,
7537            leading_comments: Vec::new(),
7538            as_json: false,
7539        }
7540    }
7541}
7542
7543/// SHOW statement - displays database objects
7544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7545#[cfg_attr(feature = "bindings", derive(TS))]
7546pub struct Show {
7547    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7548    pub this: String,
7549    /// Whether TERSE was specified
7550    #[serde(default)]
7551    pub terse: bool,
7552    /// Whether HISTORY was specified
7553    #[serde(default)]
7554    pub history: bool,
7555    /// LIKE pattern
7556    pub like: Option<Expression>,
7557    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7558    pub scope_kind: Option<String>,
7559    /// IN scope object
7560    pub scope: Option<Expression>,
7561    /// STARTS WITH pattern
7562    pub starts_with: Option<Expression>,
7563    /// LIMIT clause
7564    pub limit: Option<Box<Limit>>,
7565    /// FROM clause (for specific object)
7566    pub from: Option<Expression>,
7567    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7568    #[serde(default, skip_serializing_if = "Option::is_none")]
7569    pub where_clause: Option<Expression>,
7570    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7571    #[serde(default, skip_serializing_if = "Option::is_none")]
7572    pub for_target: Option<Expression>,
7573    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7574    #[serde(default, skip_serializing_if = "Option::is_none")]
7575    pub db: Option<Expression>,
7576    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7577    #[serde(default, skip_serializing_if = "Option::is_none")]
7578    pub target: Option<Expression>,
7579    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7580    #[serde(default, skip_serializing_if = "Option::is_none")]
7581    pub mutex: Option<bool>,
7582    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7583    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7584    pub privileges: Vec<String>,
7585}
7586
7587impl Show {
7588    pub fn new(this: impl Into<String>) -> Self {
7589        Self {
7590            this: this.into(),
7591            terse: false,
7592            history: false,
7593            like: None,
7594            scope_kind: None,
7595            scope: None,
7596            starts_with: None,
7597            limit: None,
7598            from: None,
7599            where_clause: None,
7600            for_target: None,
7601            db: None,
7602            target: None,
7603            mutex: None,
7604            privileges: Vec::new(),
7605        }
7606    }
7607}
7608
7609/// Represent an explicit parenthesized expression for grouping precedence.
7610///
7611/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7612/// correctly instead of being flattened to `a + b * c`.
7613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7614#[cfg_attr(feature = "bindings", derive(TS))]
7615pub struct Paren {
7616    /// The inner expression wrapped by parentheses.
7617    pub this: Expression,
7618    #[serde(default)]
7619    pub trailing_comments: Vec<String>,
7620}
7621
7622/// Expression annotated with trailing comments (for round-trip preservation)
7623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7624#[cfg_attr(feature = "bindings", derive(TS))]
7625pub struct Annotated {
7626    pub this: Expression,
7627    pub trailing_comments: Vec<String>,
7628}
7629
7630// === BATCH GENERATED STRUCT DEFINITIONS ===
7631// Generated from Python sqlglot expressions.py
7632
7633/// Refresh
7634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7635#[cfg_attr(feature = "bindings", derive(TS))]
7636pub struct Refresh {
7637    pub this: Box<Expression>,
7638    pub kind: String,
7639}
7640
7641/// LockingStatement
7642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7643#[cfg_attr(feature = "bindings", derive(TS))]
7644pub struct LockingStatement {
7645    pub this: Box<Expression>,
7646    pub expression: Box<Expression>,
7647}
7648
7649/// SequenceProperties
7650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7651#[cfg_attr(feature = "bindings", derive(TS))]
7652pub struct SequenceProperties {
7653    #[serde(default)]
7654    pub increment: Option<Box<Expression>>,
7655    #[serde(default)]
7656    pub minvalue: Option<Box<Expression>>,
7657    #[serde(default)]
7658    pub maxvalue: Option<Box<Expression>>,
7659    #[serde(default)]
7660    pub cache: Option<Box<Expression>>,
7661    #[serde(default)]
7662    pub start: Option<Box<Expression>>,
7663    #[serde(default)]
7664    pub owned: Option<Box<Expression>>,
7665    #[serde(default)]
7666    pub options: Vec<Expression>,
7667}
7668
7669/// TruncateTable
7670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7671#[cfg_attr(feature = "bindings", derive(TS))]
7672pub struct TruncateTable {
7673    #[serde(default)]
7674    pub expressions: Vec<Expression>,
7675    #[serde(default)]
7676    pub is_database: Option<Box<Expression>>,
7677    #[serde(default)]
7678    pub exists: bool,
7679    #[serde(default)]
7680    pub only: Option<Box<Expression>>,
7681    #[serde(default)]
7682    pub cluster: Option<Box<Expression>>,
7683    #[serde(default)]
7684    pub identity: Option<Box<Expression>>,
7685    #[serde(default)]
7686    pub option: Option<Box<Expression>>,
7687    #[serde(default)]
7688    pub partition: Option<Box<Expression>>,
7689}
7690
7691/// Clone
7692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7693#[cfg_attr(feature = "bindings", derive(TS))]
7694pub struct Clone {
7695    pub this: Box<Expression>,
7696    #[serde(default)]
7697    pub shallow: Option<Box<Expression>>,
7698    #[serde(default)]
7699    pub copy: Option<Box<Expression>>,
7700}
7701
7702/// Attach
7703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7704#[cfg_attr(feature = "bindings", derive(TS))]
7705pub struct Attach {
7706    pub this: Box<Expression>,
7707    #[serde(default)]
7708    pub exists: bool,
7709    #[serde(default)]
7710    pub expressions: Vec<Expression>,
7711}
7712
7713/// Detach
7714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7715#[cfg_attr(feature = "bindings", derive(TS))]
7716pub struct Detach {
7717    pub this: Box<Expression>,
7718    #[serde(default)]
7719    pub exists: bool,
7720}
7721
7722/// Install
7723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7724#[cfg_attr(feature = "bindings", derive(TS))]
7725pub struct Install {
7726    pub this: Box<Expression>,
7727    #[serde(default)]
7728    pub from_: Option<Box<Expression>>,
7729    #[serde(default)]
7730    pub force: Option<Box<Expression>>,
7731}
7732
7733/// Summarize
7734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7735#[cfg_attr(feature = "bindings", derive(TS))]
7736pub struct Summarize {
7737    pub this: Box<Expression>,
7738    #[serde(default)]
7739    pub table: Option<Box<Expression>>,
7740}
7741
7742/// Declare
7743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7744#[cfg_attr(feature = "bindings", derive(TS))]
7745pub struct Declare {
7746    #[serde(default)]
7747    pub expressions: Vec<Expression>,
7748}
7749
7750/// DeclareItem
7751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7752#[cfg_attr(feature = "bindings", derive(TS))]
7753pub struct DeclareItem {
7754    pub this: Box<Expression>,
7755    #[serde(default)]
7756    pub kind: Option<String>,
7757    #[serde(default)]
7758    pub default: Option<Box<Expression>>,
7759    #[serde(default)]
7760    pub has_as: bool,
7761    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7762    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7763    pub additional_names: Vec<Expression>,
7764}
7765
7766/// Set
7767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7768#[cfg_attr(feature = "bindings", derive(TS))]
7769pub struct Set {
7770    #[serde(default)]
7771    pub expressions: Vec<Expression>,
7772    #[serde(default)]
7773    pub unset: Option<Box<Expression>>,
7774    #[serde(default)]
7775    pub tag: Option<Box<Expression>>,
7776}
7777
7778/// Heredoc
7779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7780#[cfg_attr(feature = "bindings", derive(TS))]
7781pub struct Heredoc {
7782    pub this: Box<Expression>,
7783    #[serde(default)]
7784    pub tag: Option<Box<Expression>>,
7785}
7786
7787/// QueryBand
7788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7789#[cfg_attr(feature = "bindings", derive(TS))]
7790pub struct QueryBand {
7791    pub this: Box<Expression>,
7792    #[serde(default)]
7793    pub scope: Option<Box<Expression>>,
7794    #[serde(default)]
7795    pub update: Option<Box<Expression>>,
7796}
7797
7798/// UserDefinedFunction
7799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7800#[cfg_attr(feature = "bindings", derive(TS))]
7801pub struct UserDefinedFunction {
7802    pub this: Box<Expression>,
7803    #[serde(default)]
7804    pub expressions: Vec<Expression>,
7805    #[serde(default)]
7806    pub wrapped: Option<Box<Expression>>,
7807}
7808
7809/// RecursiveWithSearch
7810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7811#[cfg_attr(feature = "bindings", derive(TS))]
7812pub struct RecursiveWithSearch {
7813    pub kind: String,
7814    pub this: Box<Expression>,
7815    pub expression: Box<Expression>,
7816    #[serde(default)]
7817    pub using: Option<Box<Expression>>,
7818}
7819
7820/// ProjectionDef
7821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7822#[cfg_attr(feature = "bindings", derive(TS))]
7823pub struct ProjectionDef {
7824    pub this: Box<Expression>,
7825    pub expression: Box<Expression>,
7826}
7827
7828/// TableAlias
7829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7830#[cfg_attr(feature = "bindings", derive(TS))]
7831pub struct TableAlias {
7832    #[serde(default)]
7833    pub this: Option<Box<Expression>>,
7834    #[serde(default)]
7835    pub columns: Vec<Expression>,
7836}
7837
7838/// ByteString
7839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7840#[cfg_attr(feature = "bindings", derive(TS))]
7841pub struct ByteString {
7842    pub this: Box<Expression>,
7843    #[serde(default)]
7844    pub is_bytes: Option<Box<Expression>>,
7845}
7846
7847/// HexStringExpr - Hex string expression (not literal)
7848/// BigQuery: converts to FROM_HEX(this)
7849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7850#[cfg_attr(feature = "bindings", derive(TS))]
7851pub struct HexStringExpr {
7852    pub this: Box<Expression>,
7853    #[serde(default)]
7854    pub is_integer: Option<bool>,
7855}
7856
7857/// UnicodeString
7858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7859#[cfg_attr(feature = "bindings", derive(TS))]
7860pub struct UnicodeString {
7861    pub this: Box<Expression>,
7862    #[serde(default)]
7863    pub escape: Option<Box<Expression>>,
7864}
7865
7866/// AlterColumn
7867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7868#[cfg_attr(feature = "bindings", derive(TS))]
7869pub struct AlterColumn {
7870    pub this: Box<Expression>,
7871    #[serde(default)]
7872    pub dtype: Option<Box<Expression>>,
7873    #[serde(default)]
7874    pub collate: Option<Box<Expression>>,
7875    #[serde(default)]
7876    pub using: Option<Box<Expression>>,
7877    #[serde(default)]
7878    pub default: Option<Box<Expression>>,
7879    #[serde(default)]
7880    pub drop: Option<Box<Expression>>,
7881    #[serde(default)]
7882    pub comment: Option<Box<Expression>>,
7883    #[serde(default)]
7884    pub allow_null: Option<Box<Expression>>,
7885    #[serde(default)]
7886    pub visible: Option<Box<Expression>>,
7887    #[serde(default)]
7888    pub rename_to: Option<Box<Expression>>,
7889}
7890
7891/// AlterSortKey
7892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7893#[cfg_attr(feature = "bindings", derive(TS))]
7894pub struct AlterSortKey {
7895    #[serde(default)]
7896    pub this: Option<Box<Expression>>,
7897    #[serde(default)]
7898    pub expressions: Vec<Expression>,
7899    #[serde(default)]
7900    pub compound: Option<Box<Expression>>,
7901}
7902
7903/// AlterSet
7904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7905#[cfg_attr(feature = "bindings", derive(TS))]
7906pub struct AlterSet {
7907    #[serde(default)]
7908    pub expressions: Vec<Expression>,
7909    #[serde(default)]
7910    pub option: Option<Box<Expression>>,
7911    #[serde(default)]
7912    pub tablespace: Option<Box<Expression>>,
7913    #[serde(default)]
7914    pub access_method: Option<Box<Expression>>,
7915    #[serde(default)]
7916    pub file_format: Option<Box<Expression>>,
7917    #[serde(default)]
7918    pub copy_options: Option<Box<Expression>>,
7919    #[serde(default)]
7920    pub tag: Option<Box<Expression>>,
7921    #[serde(default)]
7922    pub location: Option<Box<Expression>>,
7923    #[serde(default)]
7924    pub serde: Option<Box<Expression>>,
7925}
7926
7927/// RenameColumn
7928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7929#[cfg_attr(feature = "bindings", derive(TS))]
7930pub struct RenameColumn {
7931    pub this: Box<Expression>,
7932    #[serde(default)]
7933    pub to: Option<Box<Expression>>,
7934    #[serde(default)]
7935    pub exists: bool,
7936}
7937
7938/// Comprehension
7939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7940#[cfg_attr(feature = "bindings", derive(TS))]
7941pub struct Comprehension {
7942    pub this: Box<Expression>,
7943    pub expression: Box<Expression>,
7944    #[serde(default)]
7945    pub position: Option<Box<Expression>>,
7946    #[serde(default)]
7947    pub iterator: Option<Box<Expression>>,
7948    #[serde(default)]
7949    pub condition: Option<Box<Expression>>,
7950}
7951
7952/// MergeTreeTTLAction
7953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7954#[cfg_attr(feature = "bindings", derive(TS))]
7955pub struct MergeTreeTTLAction {
7956    pub this: Box<Expression>,
7957    #[serde(default)]
7958    pub delete: Option<Box<Expression>>,
7959    #[serde(default)]
7960    pub recompress: Option<Box<Expression>>,
7961    #[serde(default)]
7962    pub to_disk: Option<Box<Expression>>,
7963    #[serde(default)]
7964    pub to_volume: Option<Box<Expression>>,
7965}
7966
7967/// MergeTreeTTL
7968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7969#[cfg_attr(feature = "bindings", derive(TS))]
7970pub struct MergeTreeTTL {
7971    #[serde(default)]
7972    pub expressions: Vec<Expression>,
7973    #[serde(default)]
7974    pub where_: Option<Box<Expression>>,
7975    #[serde(default)]
7976    pub group: Option<Box<Expression>>,
7977    #[serde(default)]
7978    pub aggregates: Option<Box<Expression>>,
7979}
7980
7981/// IndexConstraintOption
7982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7983#[cfg_attr(feature = "bindings", derive(TS))]
7984pub struct IndexConstraintOption {
7985    #[serde(default)]
7986    pub key_block_size: Option<Box<Expression>>,
7987    #[serde(default)]
7988    pub using: Option<Box<Expression>>,
7989    #[serde(default)]
7990    pub parser: Option<Box<Expression>>,
7991    #[serde(default)]
7992    pub comment: Option<Box<Expression>>,
7993    #[serde(default)]
7994    pub visible: Option<Box<Expression>>,
7995    #[serde(default)]
7996    pub engine_attr: Option<Box<Expression>>,
7997    #[serde(default)]
7998    pub secondary_engine_attr: Option<Box<Expression>>,
7999}
8000
8001/// PeriodForSystemTimeConstraint
8002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8003#[cfg_attr(feature = "bindings", derive(TS))]
8004pub struct PeriodForSystemTimeConstraint {
8005    pub this: Box<Expression>,
8006    pub expression: Box<Expression>,
8007}
8008
8009/// CaseSpecificColumnConstraint
8010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8011#[cfg_attr(feature = "bindings", derive(TS))]
8012pub struct CaseSpecificColumnConstraint {
8013    #[serde(default)]
8014    pub not_: Option<Box<Expression>>,
8015}
8016
8017/// CharacterSetColumnConstraint
8018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8019#[cfg_attr(feature = "bindings", derive(TS))]
8020pub struct CharacterSetColumnConstraint {
8021    pub this: Box<Expression>,
8022}
8023
8024/// CheckColumnConstraint
8025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8026#[cfg_attr(feature = "bindings", derive(TS))]
8027pub struct CheckColumnConstraint {
8028    pub this: Box<Expression>,
8029    #[serde(default)]
8030    pub enforced: Option<Box<Expression>>,
8031}
8032
8033/// CompressColumnConstraint
8034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8035#[cfg_attr(feature = "bindings", derive(TS))]
8036pub struct CompressColumnConstraint {
8037    #[serde(default)]
8038    pub this: Option<Box<Expression>>,
8039}
8040
8041/// DateFormatColumnConstraint
8042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8043#[cfg_attr(feature = "bindings", derive(TS))]
8044pub struct DateFormatColumnConstraint {
8045    pub this: Box<Expression>,
8046}
8047
8048/// EphemeralColumnConstraint
8049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8050#[cfg_attr(feature = "bindings", derive(TS))]
8051pub struct EphemeralColumnConstraint {
8052    #[serde(default)]
8053    pub this: Option<Box<Expression>>,
8054}
8055
8056/// WithOperator
8057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8058#[cfg_attr(feature = "bindings", derive(TS))]
8059pub struct WithOperator {
8060    pub this: Box<Expression>,
8061    pub op: String,
8062}
8063
8064/// GeneratedAsIdentityColumnConstraint
8065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8066#[cfg_attr(feature = "bindings", derive(TS))]
8067pub struct GeneratedAsIdentityColumnConstraint {
8068    #[serde(default)]
8069    pub this: Option<Box<Expression>>,
8070    #[serde(default)]
8071    pub expression: Option<Box<Expression>>,
8072    #[serde(default)]
8073    pub on_null: Option<Box<Expression>>,
8074    #[serde(default)]
8075    pub start: Option<Box<Expression>>,
8076    #[serde(default)]
8077    pub increment: Option<Box<Expression>>,
8078    #[serde(default)]
8079    pub minvalue: Option<Box<Expression>>,
8080    #[serde(default)]
8081    pub maxvalue: Option<Box<Expression>>,
8082    #[serde(default)]
8083    pub cycle: Option<Box<Expression>>,
8084    #[serde(default)]
8085    pub order: Option<Box<Expression>>,
8086}
8087
8088/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8089/// TSQL: outputs "IDENTITY"
8090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8091#[cfg_attr(feature = "bindings", derive(TS))]
8092pub struct AutoIncrementColumnConstraint;
8093
8094/// CommentColumnConstraint - Column comment marker
8095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8096#[cfg_attr(feature = "bindings", derive(TS))]
8097pub struct CommentColumnConstraint;
8098
8099/// GeneratedAsRowColumnConstraint
8100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8101#[cfg_attr(feature = "bindings", derive(TS))]
8102pub struct GeneratedAsRowColumnConstraint {
8103    #[serde(default)]
8104    pub start: Option<Box<Expression>>,
8105    #[serde(default)]
8106    pub hidden: Option<Box<Expression>>,
8107}
8108
8109/// IndexColumnConstraint
8110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8111#[cfg_attr(feature = "bindings", derive(TS))]
8112pub struct IndexColumnConstraint {
8113    #[serde(default)]
8114    pub this: Option<Box<Expression>>,
8115    #[serde(default)]
8116    pub expressions: Vec<Expression>,
8117    #[serde(default)]
8118    pub kind: Option<String>,
8119    #[serde(default)]
8120    pub index_type: Option<Box<Expression>>,
8121    #[serde(default)]
8122    pub options: Vec<Expression>,
8123    #[serde(default)]
8124    pub expression: Option<Box<Expression>>,
8125    #[serde(default)]
8126    pub granularity: Option<Box<Expression>>,
8127}
8128
8129/// MaskingPolicyColumnConstraint
8130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8131#[cfg_attr(feature = "bindings", derive(TS))]
8132pub struct MaskingPolicyColumnConstraint {
8133    pub this: Box<Expression>,
8134    #[serde(default)]
8135    pub expressions: Vec<Expression>,
8136}
8137
8138/// NotNullColumnConstraint
8139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8140#[cfg_attr(feature = "bindings", derive(TS))]
8141pub struct NotNullColumnConstraint {
8142    #[serde(default)]
8143    pub allow_null: Option<Box<Expression>>,
8144}
8145
8146/// DefaultColumnConstraint - DEFAULT value for a column
8147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8148#[cfg_attr(feature = "bindings", derive(TS))]
8149pub struct DefaultColumnConstraint {
8150    pub this: Box<Expression>,
8151}
8152
8153/// PrimaryKeyColumnConstraint
8154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8155#[cfg_attr(feature = "bindings", derive(TS))]
8156pub struct PrimaryKeyColumnConstraint {
8157    #[serde(default)]
8158    pub desc: Option<Box<Expression>>,
8159    #[serde(default)]
8160    pub options: Vec<Expression>,
8161}
8162
8163/// UniqueColumnConstraint
8164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8165#[cfg_attr(feature = "bindings", derive(TS))]
8166pub struct UniqueColumnConstraint {
8167    #[serde(default)]
8168    pub this: Option<Box<Expression>>,
8169    #[serde(default)]
8170    pub index_type: Option<Box<Expression>>,
8171    #[serde(default)]
8172    pub on_conflict: Option<Box<Expression>>,
8173    #[serde(default)]
8174    pub nulls: Option<Box<Expression>>,
8175    #[serde(default)]
8176    pub options: Vec<Expression>,
8177}
8178
8179/// WatermarkColumnConstraint
8180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8181#[cfg_attr(feature = "bindings", derive(TS))]
8182pub struct WatermarkColumnConstraint {
8183    pub this: Box<Expression>,
8184    pub expression: Box<Expression>,
8185}
8186
8187/// ComputedColumnConstraint
8188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8189#[cfg_attr(feature = "bindings", derive(TS))]
8190pub struct ComputedColumnConstraint {
8191    pub this: Box<Expression>,
8192    #[serde(default)]
8193    pub persisted: Option<Box<Expression>>,
8194    #[serde(default)]
8195    pub not_null: Option<Box<Expression>>,
8196    #[serde(default)]
8197    pub data_type: Option<Box<Expression>>,
8198}
8199
8200/// InOutColumnConstraint
8201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8202#[cfg_attr(feature = "bindings", derive(TS))]
8203pub struct InOutColumnConstraint {
8204    #[serde(default)]
8205    pub input_: Option<Box<Expression>>,
8206    #[serde(default)]
8207    pub output: Option<Box<Expression>>,
8208}
8209
8210/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8212#[cfg_attr(feature = "bindings", derive(TS))]
8213pub struct PathColumnConstraint {
8214    pub this: Box<Expression>,
8215}
8216
8217/// Constraint
8218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8219#[cfg_attr(feature = "bindings", derive(TS))]
8220pub struct Constraint {
8221    pub this: Box<Expression>,
8222    #[serde(default)]
8223    pub expressions: Vec<Expression>,
8224}
8225
8226/// Export
8227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8228#[cfg_attr(feature = "bindings", derive(TS))]
8229pub struct Export {
8230    pub this: Box<Expression>,
8231    #[serde(default)]
8232    pub connection: Option<Box<Expression>>,
8233    #[serde(default)]
8234    pub options: Vec<Expression>,
8235}
8236
8237/// Filter
8238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8239#[cfg_attr(feature = "bindings", derive(TS))]
8240pub struct Filter {
8241    pub this: Box<Expression>,
8242    pub expression: Box<Expression>,
8243}
8244
8245/// Changes
8246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8247#[cfg_attr(feature = "bindings", derive(TS))]
8248pub struct Changes {
8249    #[serde(default)]
8250    pub information: Option<Box<Expression>>,
8251    #[serde(default)]
8252    pub at_before: Option<Box<Expression>>,
8253    #[serde(default)]
8254    pub end: Option<Box<Expression>>,
8255}
8256
8257/// Directory
8258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8259#[cfg_attr(feature = "bindings", derive(TS))]
8260pub struct Directory {
8261    pub this: Box<Expression>,
8262    #[serde(default)]
8263    pub local: Option<Box<Expression>>,
8264    #[serde(default)]
8265    pub row_format: Option<Box<Expression>>,
8266}
8267
8268/// ForeignKey
8269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8270#[cfg_attr(feature = "bindings", derive(TS))]
8271pub struct ForeignKey {
8272    #[serde(default)]
8273    pub expressions: Vec<Expression>,
8274    #[serde(default)]
8275    pub reference: Option<Box<Expression>>,
8276    #[serde(default)]
8277    pub delete: Option<Box<Expression>>,
8278    #[serde(default)]
8279    pub update: Option<Box<Expression>>,
8280    #[serde(default)]
8281    pub options: Vec<Expression>,
8282}
8283
8284/// ColumnPrefix
8285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8286#[cfg_attr(feature = "bindings", derive(TS))]
8287pub struct ColumnPrefix {
8288    pub this: Box<Expression>,
8289    pub expression: Box<Expression>,
8290}
8291
8292/// PrimaryKey
8293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8294#[cfg_attr(feature = "bindings", derive(TS))]
8295pub struct PrimaryKey {
8296    #[serde(default)]
8297    pub this: Option<Box<Expression>>,
8298    #[serde(default)]
8299    pub expressions: Vec<Expression>,
8300    #[serde(default)]
8301    pub options: Vec<Expression>,
8302    #[serde(default)]
8303    pub include: Option<Box<Expression>>,
8304}
8305
8306/// Into
8307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8308#[cfg_attr(feature = "bindings", derive(TS))]
8309pub struct IntoClause {
8310    #[serde(default)]
8311    pub this: Option<Box<Expression>>,
8312    #[serde(default)]
8313    pub temporary: bool,
8314    #[serde(default)]
8315    pub unlogged: Option<Box<Expression>>,
8316    #[serde(default)]
8317    pub bulk_collect: Option<Box<Expression>>,
8318    #[serde(default)]
8319    pub expressions: Vec<Expression>,
8320}
8321
8322/// JoinHint
8323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8324#[cfg_attr(feature = "bindings", derive(TS))]
8325pub struct JoinHint {
8326    pub this: Box<Expression>,
8327    #[serde(default)]
8328    pub expressions: Vec<Expression>,
8329}
8330
8331/// Opclass
8332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8333#[cfg_attr(feature = "bindings", derive(TS))]
8334pub struct Opclass {
8335    pub this: Box<Expression>,
8336    pub expression: Box<Expression>,
8337}
8338
8339/// Index
8340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8341#[cfg_attr(feature = "bindings", derive(TS))]
8342pub struct Index {
8343    #[serde(default)]
8344    pub this: Option<Box<Expression>>,
8345    #[serde(default)]
8346    pub table: Option<Box<Expression>>,
8347    #[serde(default)]
8348    pub unique: bool,
8349    #[serde(default)]
8350    pub primary: Option<Box<Expression>>,
8351    #[serde(default)]
8352    pub amp: Option<Box<Expression>>,
8353    #[serde(default)]
8354    pub params: Vec<Expression>,
8355}
8356
8357/// IndexParameters
8358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8359#[cfg_attr(feature = "bindings", derive(TS))]
8360pub struct IndexParameters {
8361    #[serde(default)]
8362    pub using: Option<Box<Expression>>,
8363    #[serde(default)]
8364    pub include: Option<Box<Expression>>,
8365    #[serde(default)]
8366    pub columns: Vec<Expression>,
8367    #[serde(default)]
8368    pub with_storage: Option<Box<Expression>>,
8369    #[serde(default)]
8370    pub partition_by: Option<Box<Expression>>,
8371    #[serde(default)]
8372    pub tablespace: Option<Box<Expression>>,
8373    #[serde(default)]
8374    pub where_: Option<Box<Expression>>,
8375    #[serde(default)]
8376    pub on: Option<Box<Expression>>,
8377}
8378
8379/// ConditionalInsert
8380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8381#[cfg_attr(feature = "bindings", derive(TS))]
8382pub struct ConditionalInsert {
8383    pub this: Box<Expression>,
8384    #[serde(default)]
8385    pub expression: Option<Box<Expression>>,
8386    #[serde(default)]
8387    pub else_: Option<Box<Expression>>,
8388}
8389
8390/// MultitableInserts
8391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8392#[cfg_attr(feature = "bindings", derive(TS))]
8393pub struct MultitableInserts {
8394    #[serde(default)]
8395    pub expressions: Vec<Expression>,
8396    pub kind: String,
8397    #[serde(default)]
8398    pub source: Option<Box<Expression>>,
8399    /// Leading comments before the statement
8400    #[serde(default)]
8401    pub leading_comments: Vec<String>,
8402}
8403
8404/// OnConflict
8405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8406#[cfg_attr(feature = "bindings", derive(TS))]
8407pub struct OnConflict {
8408    #[serde(default)]
8409    pub duplicate: Option<Box<Expression>>,
8410    #[serde(default)]
8411    pub expressions: Vec<Expression>,
8412    #[serde(default)]
8413    pub action: Option<Box<Expression>>,
8414    #[serde(default)]
8415    pub conflict_keys: Option<Box<Expression>>,
8416    #[serde(default)]
8417    pub index_predicate: Option<Box<Expression>>,
8418    #[serde(default)]
8419    pub constraint: Option<Box<Expression>>,
8420    #[serde(default)]
8421    pub where_: Option<Box<Expression>>,
8422}
8423
8424/// OnCondition
8425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8426#[cfg_attr(feature = "bindings", derive(TS))]
8427pub struct OnCondition {
8428    #[serde(default)]
8429    pub error: Option<Box<Expression>>,
8430    #[serde(default)]
8431    pub empty: Option<Box<Expression>>,
8432    #[serde(default)]
8433    pub null: Option<Box<Expression>>,
8434}
8435
8436/// Returning
8437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8438#[cfg_attr(feature = "bindings", derive(TS))]
8439pub struct Returning {
8440    #[serde(default)]
8441    pub expressions: Vec<Expression>,
8442    #[serde(default)]
8443    pub into: Option<Box<Expression>>,
8444}
8445
8446/// Introducer
8447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8448#[cfg_attr(feature = "bindings", derive(TS))]
8449pub struct Introducer {
8450    pub this: Box<Expression>,
8451    pub expression: Box<Expression>,
8452}
8453
8454/// PartitionRange
8455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8456#[cfg_attr(feature = "bindings", derive(TS))]
8457pub struct PartitionRange {
8458    pub this: Box<Expression>,
8459    #[serde(default)]
8460    pub expression: Option<Box<Expression>>,
8461    #[serde(default)]
8462    pub expressions: Vec<Expression>,
8463}
8464
8465/// Group
8466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8467#[cfg_attr(feature = "bindings", derive(TS))]
8468pub struct Group {
8469    #[serde(default)]
8470    pub expressions: Vec<Expression>,
8471    #[serde(default)]
8472    pub grouping_sets: Option<Box<Expression>>,
8473    #[serde(default)]
8474    pub cube: Option<Box<Expression>>,
8475    #[serde(default)]
8476    pub rollup: Option<Box<Expression>>,
8477    #[serde(default)]
8478    pub totals: Option<Box<Expression>>,
8479    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8480    #[serde(default)]
8481    pub all: Option<bool>,
8482}
8483
8484/// Cube
8485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8486#[cfg_attr(feature = "bindings", derive(TS))]
8487pub struct Cube {
8488    #[serde(default)]
8489    pub expressions: Vec<Expression>,
8490}
8491
8492/// Rollup
8493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8494#[cfg_attr(feature = "bindings", derive(TS))]
8495pub struct Rollup {
8496    #[serde(default)]
8497    pub expressions: Vec<Expression>,
8498}
8499
8500/// GroupingSets
8501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8502#[cfg_attr(feature = "bindings", derive(TS))]
8503pub struct GroupingSets {
8504    #[serde(default)]
8505    pub expressions: Vec<Expression>,
8506}
8507
8508/// LimitOptions
8509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8510#[cfg_attr(feature = "bindings", derive(TS))]
8511pub struct LimitOptions {
8512    #[serde(default)]
8513    pub percent: Option<Box<Expression>>,
8514    #[serde(default)]
8515    pub rows: Option<Box<Expression>>,
8516    #[serde(default)]
8517    pub with_ties: Option<Box<Expression>>,
8518}
8519
8520/// Lateral
8521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8522#[cfg_attr(feature = "bindings", derive(TS))]
8523pub struct Lateral {
8524    pub this: Box<Expression>,
8525    #[serde(default)]
8526    pub view: Option<Box<Expression>>,
8527    #[serde(default)]
8528    pub outer: Option<Box<Expression>>,
8529    #[serde(default)]
8530    pub alias: Option<String>,
8531    /// Whether the alias was originally quoted (backtick/double-quote)
8532    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8533    pub alias_quoted: bool,
8534    #[serde(default)]
8535    pub cross_apply: Option<Box<Expression>>,
8536    #[serde(default)]
8537    pub ordinality: Option<Box<Expression>>,
8538    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8539    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8540    pub column_aliases: Vec<String>,
8541}
8542
8543/// TableFromRows
8544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8545#[cfg_attr(feature = "bindings", derive(TS))]
8546pub struct TableFromRows {
8547    pub this: Box<Expression>,
8548    #[serde(default)]
8549    pub alias: Option<String>,
8550    #[serde(default)]
8551    pub joins: Vec<Expression>,
8552    #[serde(default)]
8553    pub pivots: Option<Box<Expression>>,
8554    #[serde(default)]
8555    pub sample: Option<Box<Expression>>,
8556}
8557
8558/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8559/// Used for set-returning functions with typed column definitions
8560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8561#[cfg_attr(feature = "bindings", derive(TS))]
8562pub struct RowsFrom {
8563    /// List of function expressions, each potentially with an alias and typed columns
8564    pub expressions: Vec<Expression>,
8565    /// WITH ORDINALITY modifier
8566    #[serde(default)]
8567    pub ordinality: bool,
8568    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8569    #[serde(default)]
8570    pub alias: Option<Box<Expression>>,
8571}
8572
8573/// WithFill
8574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8575#[cfg_attr(feature = "bindings", derive(TS))]
8576pub struct WithFill {
8577    #[serde(default)]
8578    pub from_: Option<Box<Expression>>,
8579    #[serde(default)]
8580    pub to: Option<Box<Expression>>,
8581    #[serde(default)]
8582    pub step: Option<Box<Expression>>,
8583    #[serde(default)]
8584    pub staleness: Option<Box<Expression>>,
8585    #[serde(default)]
8586    pub interpolate: Option<Box<Expression>>,
8587}
8588
8589/// Property
8590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8591#[cfg_attr(feature = "bindings", derive(TS))]
8592pub struct Property {
8593    pub this: Box<Expression>,
8594    #[serde(default)]
8595    pub value: Option<Box<Expression>>,
8596}
8597
8598/// GrantPrivilege
8599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8600#[cfg_attr(feature = "bindings", derive(TS))]
8601pub struct GrantPrivilege {
8602    pub this: Box<Expression>,
8603    #[serde(default)]
8604    pub expressions: Vec<Expression>,
8605}
8606
8607/// AllowedValuesProperty
8608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8609#[cfg_attr(feature = "bindings", derive(TS))]
8610pub struct AllowedValuesProperty {
8611    #[serde(default)]
8612    pub expressions: Vec<Expression>,
8613}
8614
8615/// AlgorithmProperty
8616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8617#[cfg_attr(feature = "bindings", derive(TS))]
8618pub struct AlgorithmProperty {
8619    pub this: Box<Expression>,
8620}
8621
8622/// AutoIncrementProperty
8623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8624#[cfg_attr(feature = "bindings", derive(TS))]
8625pub struct AutoIncrementProperty {
8626    pub this: Box<Expression>,
8627}
8628
8629/// AutoRefreshProperty
8630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8631#[cfg_attr(feature = "bindings", derive(TS))]
8632pub struct AutoRefreshProperty {
8633    pub this: Box<Expression>,
8634}
8635
8636/// BackupProperty
8637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8638#[cfg_attr(feature = "bindings", derive(TS))]
8639pub struct BackupProperty {
8640    pub this: Box<Expression>,
8641}
8642
8643/// BuildProperty
8644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8645#[cfg_attr(feature = "bindings", derive(TS))]
8646pub struct BuildProperty {
8647    pub this: Box<Expression>,
8648}
8649
8650/// BlockCompressionProperty
8651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8652#[cfg_attr(feature = "bindings", derive(TS))]
8653pub struct BlockCompressionProperty {
8654    #[serde(default)]
8655    pub autotemp: Option<Box<Expression>>,
8656    #[serde(default)]
8657    pub always: Option<Box<Expression>>,
8658    #[serde(default)]
8659    pub default: Option<Box<Expression>>,
8660    #[serde(default)]
8661    pub manual: Option<Box<Expression>>,
8662    #[serde(default)]
8663    pub never: Option<Box<Expression>>,
8664}
8665
8666/// CharacterSetProperty
8667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8668#[cfg_attr(feature = "bindings", derive(TS))]
8669pub struct CharacterSetProperty {
8670    pub this: Box<Expression>,
8671    #[serde(default)]
8672    pub default: Option<Box<Expression>>,
8673}
8674
8675/// ChecksumProperty
8676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8677#[cfg_attr(feature = "bindings", derive(TS))]
8678pub struct ChecksumProperty {
8679    #[serde(default)]
8680    pub on: Option<Box<Expression>>,
8681    #[serde(default)]
8682    pub default: Option<Box<Expression>>,
8683}
8684
8685/// CollateProperty
8686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8687#[cfg_attr(feature = "bindings", derive(TS))]
8688pub struct CollateProperty {
8689    pub this: Box<Expression>,
8690    #[serde(default)]
8691    pub default: Option<Box<Expression>>,
8692}
8693
8694/// DataBlocksizeProperty
8695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8696#[cfg_attr(feature = "bindings", derive(TS))]
8697pub struct DataBlocksizeProperty {
8698    #[serde(default)]
8699    pub size: Option<i64>,
8700    #[serde(default)]
8701    pub units: Option<Box<Expression>>,
8702    #[serde(default)]
8703    pub minimum: Option<Box<Expression>>,
8704    #[serde(default)]
8705    pub maximum: Option<Box<Expression>>,
8706    #[serde(default)]
8707    pub default: Option<Box<Expression>>,
8708}
8709
8710/// DataDeletionProperty
8711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8712#[cfg_attr(feature = "bindings", derive(TS))]
8713pub struct DataDeletionProperty {
8714    pub on: Box<Expression>,
8715    #[serde(default)]
8716    pub filter_column: Option<Box<Expression>>,
8717    #[serde(default)]
8718    pub retention_period: Option<Box<Expression>>,
8719}
8720
8721/// DefinerProperty
8722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8723#[cfg_attr(feature = "bindings", derive(TS))]
8724pub struct DefinerProperty {
8725    pub this: Box<Expression>,
8726}
8727
8728/// DistKeyProperty
8729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8730#[cfg_attr(feature = "bindings", derive(TS))]
8731pub struct DistKeyProperty {
8732    pub this: Box<Expression>,
8733}
8734
8735/// DistributedByProperty
8736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8737#[cfg_attr(feature = "bindings", derive(TS))]
8738pub struct DistributedByProperty {
8739    #[serde(default)]
8740    pub expressions: Vec<Expression>,
8741    pub kind: String,
8742    #[serde(default)]
8743    pub buckets: Option<Box<Expression>>,
8744    #[serde(default)]
8745    pub order: Option<Box<Expression>>,
8746}
8747
8748/// DistStyleProperty
8749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8750#[cfg_attr(feature = "bindings", derive(TS))]
8751pub struct DistStyleProperty {
8752    pub this: Box<Expression>,
8753}
8754
8755/// DuplicateKeyProperty
8756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8757#[cfg_attr(feature = "bindings", derive(TS))]
8758pub struct DuplicateKeyProperty {
8759    #[serde(default)]
8760    pub expressions: Vec<Expression>,
8761}
8762
8763/// EngineProperty
8764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8765#[cfg_attr(feature = "bindings", derive(TS))]
8766pub struct EngineProperty {
8767    pub this: Box<Expression>,
8768}
8769
8770/// ToTableProperty
8771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8772#[cfg_attr(feature = "bindings", derive(TS))]
8773pub struct ToTableProperty {
8774    pub this: Box<Expression>,
8775}
8776
8777/// ExecuteAsProperty
8778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8779#[cfg_attr(feature = "bindings", derive(TS))]
8780pub struct ExecuteAsProperty {
8781    pub this: Box<Expression>,
8782}
8783
8784/// ExternalProperty
8785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8786#[cfg_attr(feature = "bindings", derive(TS))]
8787pub struct ExternalProperty {
8788    #[serde(default)]
8789    pub this: Option<Box<Expression>>,
8790}
8791
8792/// FallbackProperty
8793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8794#[cfg_attr(feature = "bindings", derive(TS))]
8795pub struct FallbackProperty {
8796    #[serde(default)]
8797    pub no: Option<Box<Expression>>,
8798    #[serde(default)]
8799    pub protection: Option<Box<Expression>>,
8800}
8801
8802/// FileFormatProperty
8803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8804#[cfg_attr(feature = "bindings", derive(TS))]
8805pub struct FileFormatProperty {
8806    #[serde(default)]
8807    pub this: Option<Box<Expression>>,
8808    #[serde(default)]
8809    pub expressions: Vec<Expression>,
8810    #[serde(default)]
8811    pub hive_format: Option<Box<Expression>>,
8812}
8813
8814/// CredentialsProperty
8815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8816#[cfg_attr(feature = "bindings", derive(TS))]
8817pub struct CredentialsProperty {
8818    #[serde(default)]
8819    pub expressions: Vec<Expression>,
8820}
8821
8822/// FreespaceProperty
8823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8824#[cfg_attr(feature = "bindings", derive(TS))]
8825pub struct FreespaceProperty {
8826    pub this: Box<Expression>,
8827    #[serde(default)]
8828    pub percent: Option<Box<Expression>>,
8829}
8830
8831/// InheritsProperty
8832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8833#[cfg_attr(feature = "bindings", derive(TS))]
8834pub struct InheritsProperty {
8835    #[serde(default)]
8836    pub expressions: Vec<Expression>,
8837}
8838
8839/// InputModelProperty
8840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8841#[cfg_attr(feature = "bindings", derive(TS))]
8842pub struct InputModelProperty {
8843    pub this: Box<Expression>,
8844}
8845
8846/// OutputModelProperty
8847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8848#[cfg_attr(feature = "bindings", derive(TS))]
8849pub struct OutputModelProperty {
8850    pub this: Box<Expression>,
8851}
8852
8853/// IsolatedLoadingProperty
8854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8855#[cfg_attr(feature = "bindings", derive(TS))]
8856pub struct IsolatedLoadingProperty {
8857    #[serde(default)]
8858    pub no: Option<Box<Expression>>,
8859    #[serde(default)]
8860    pub concurrent: Option<Box<Expression>>,
8861    #[serde(default)]
8862    pub target: Option<Box<Expression>>,
8863}
8864
8865/// JournalProperty
8866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8867#[cfg_attr(feature = "bindings", derive(TS))]
8868pub struct JournalProperty {
8869    #[serde(default)]
8870    pub no: Option<Box<Expression>>,
8871    #[serde(default)]
8872    pub dual: Option<Box<Expression>>,
8873    #[serde(default)]
8874    pub before: Option<Box<Expression>>,
8875    #[serde(default)]
8876    pub local: Option<Box<Expression>>,
8877    #[serde(default)]
8878    pub after: Option<Box<Expression>>,
8879}
8880
8881/// LanguageProperty
8882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8883#[cfg_attr(feature = "bindings", derive(TS))]
8884pub struct LanguageProperty {
8885    pub this: Box<Expression>,
8886}
8887
8888/// EnviromentProperty
8889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8890#[cfg_attr(feature = "bindings", derive(TS))]
8891pub struct EnviromentProperty {
8892    #[serde(default)]
8893    pub expressions: Vec<Expression>,
8894}
8895
8896/// ClusteredByProperty
8897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8898#[cfg_attr(feature = "bindings", derive(TS))]
8899pub struct ClusteredByProperty {
8900    #[serde(default)]
8901    pub expressions: Vec<Expression>,
8902    #[serde(default)]
8903    pub sorted_by: Option<Box<Expression>>,
8904    #[serde(default)]
8905    pub buckets: Option<Box<Expression>>,
8906}
8907
8908/// DictProperty
8909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8910#[cfg_attr(feature = "bindings", derive(TS))]
8911pub struct DictProperty {
8912    pub this: Box<Expression>,
8913    pub kind: String,
8914    #[serde(default)]
8915    pub settings: Option<Box<Expression>>,
8916}
8917
8918/// DictRange
8919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8920#[cfg_attr(feature = "bindings", derive(TS))]
8921pub struct DictRange {
8922    pub this: Box<Expression>,
8923    #[serde(default)]
8924    pub min: Option<Box<Expression>>,
8925    #[serde(default)]
8926    pub max: Option<Box<Expression>>,
8927}
8928
8929/// OnCluster
8930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8931#[cfg_attr(feature = "bindings", derive(TS))]
8932pub struct OnCluster {
8933    pub this: Box<Expression>,
8934}
8935
8936/// LikeProperty
8937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8938#[cfg_attr(feature = "bindings", derive(TS))]
8939pub struct LikeProperty {
8940    pub this: Box<Expression>,
8941    #[serde(default)]
8942    pub expressions: Vec<Expression>,
8943}
8944
8945/// LocationProperty
8946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8947#[cfg_attr(feature = "bindings", derive(TS))]
8948pub struct LocationProperty {
8949    pub this: Box<Expression>,
8950}
8951
8952/// LockProperty
8953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8954#[cfg_attr(feature = "bindings", derive(TS))]
8955pub struct LockProperty {
8956    pub this: Box<Expression>,
8957}
8958
8959/// LockingProperty
8960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8961#[cfg_attr(feature = "bindings", derive(TS))]
8962pub struct LockingProperty {
8963    #[serde(default)]
8964    pub this: Option<Box<Expression>>,
8965    pub kind: String,
8966    #[serde(default)]
8967    pub for_or_in: Option<Box<Expression>>,
8968    #[serde(default)]
8969    pub lock_type: Option<Box<Expression>>,
8970    #[serde(default)]
8971    pub override_: Option<Box<Expression>>,
8972}
8973
8974/// LogProperty
8975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8976#[cfg_attr(feature = "bindings", derive(TS))]
8977pub struct LogProperty {
8978    #[serde(default)]
8979    pub no: Option<Box<Expression>>,
8980}
8981
8982/// MaterializedProperty
8983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8984#[cfg_attr(feature = "bindings", derive(TS))]
8985pub struct MaterializedProperty {
8986    #[serde(default)]
8987    pub this: Option<Box<Expression>>,
8988}
8989
8990/// MergeBlockRatioProperty
8991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8992#[cfg_attr(feature = "bindings", derive(TS))]
8993pub struct MergeBlockRatioProperty {
8994    #[serde(default)]
8995    pub this: Option<Box<Expression>>,
8996    #[serde(default)]
8997    pub no: Option<Box<Expression>>,
8998    #[serde(default)]
8999    pub default: Option<Box<Expression>>,
9000    #[serde(default)]
9001    pub percent: Option<Box<Expression>>,
9002}
9003
9004/// OnProperty
9005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9006#[cfg_attr(feature = "bindings", derive(TS))]
9007pub struct OnProperty {
9008    pub this: Box<Expression>,
9009}
9010
9011/// OnCommitProperty
9012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9013#[cfg_attr(feature = "bindings", derive(TS))]
9014pub struct OnCommitProperty {
9015    #[serde(default)]
9016    pub delete: Option<Box<Expression>>,
9017}
9018
9019/// PartitionedByProperty
9020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9021#[cfg_attr(feature = "bindings", derive(TS))]
9022pub struct PartitionedByProperty {
9023    pub this: Box<Expression>,
9024}
9025
9026/// PartitionedByBucket
9027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9028#[cfg_attr(feature = "bindings", derive(TS))]
9029pub struct PartitionedByBucket {
9030    pub this: Box<Expression>,
9031    pub expression: Box<Expression>,
9032}
9033
9034/// PartitionByTruncate
9035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9036#[cfg_attr(feature = "bindings", derive(TS))]
9037pub struct PartitionByTruncate {
9038    pub this: Box<Expression>,
9039    pub expression: Box<Expression>,
9040}
9041
9042/// PartitionByRangeProperty
9043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9044#[cfg_attr(feature = "bindings", derive(TS))]
9045pub struct PartitionByRangeProperty {
9046    #[serde(default)]
9047    pub partition_expressions: Option<Box<Expression>>,
9048    #[serde(default)]
9049    pub create_expressions: Option<Box<Expression>>,
9050}
9051
9052/// PartitionByRangePropertyDynamic
9053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9054#[cfg_attr(feature = "bindings", derive(TS))]
9055pub struct PartitionByRangePropertyDynamic {
9056    #[serde(default)]
9057    pub this: Option<Box<Expression>>,
9058    #[serde(default)]
9059    pub start: Option<Box<Expression>>,
9060    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9061    #[serde(default)]
9062    pub use_start_end: bool,
9063    #[serde(default)]
9064    pub end: Option<Box<Expression>>,
9065    #[serde(default)]
9066    pub every: Option<Box<Expression>>,
9067}
9068
9069/// PartitionByListProperty
9070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9071#[cfg_attr(feature = "bindings", derive(TS))]
9072pub struct PartitionByListProperty {
9073    #[serde(default)]
9074    pub partition_expressions: Option<Box<Expression>>,
9075    #[serde(default)]
9076    pub create_expressions: Option<Box<Expression>>,
9077}
9078
9079/// PartitionList
9080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9081#[cfg_attr(feature = "bindings", derive(TS))]
9082pub struct PartitionList {
9083    pub this: Box<Expression>,
9084    #[serde(default)]
9085    pub expressions: Vec<Expression>,
9086}
9087
9088/// Partition - represents PARTITION/SUBPARTITION clause
9089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9090#[cfg_attr(feature = "bindings", derive(TS))]
9091pub struct Partition {
9092    pub expressions: Vec<Expression>,
9093    #[serde(default)]
9094    pub subpartition: bool,
9095}
9096
9097/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9098/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9100#[cfg_attr(feature = "bindings", derive(TS))]
9101pub struct RefreshTriggerProperty {
9102    /// Method: COMPLETE or AUTO
9103    pub method: String,
9104    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9105    #[serde(default)]
9106    pub kind: Option<String>,
9107    /// For SCHEDULE: EVERY n (the number)
9108    #[serde(default)]
9109    pub every: Option<Box<Expression>>,
9110    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9111    #[serde(default)]
9112    pub unit: Option<String>,
9113    /// For SCHEDULE: STARTS 'datetime'
9114    #[serde(default)]
9115    pub starts: Option<Box<Expression>>,
9116}
9117
9118/// UniqueKeyProperty
9119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9120#[cfg_attr(feature = "bindings", derive(TS))]
9121pub struct UniqueKeyProperty {
9122    #[serde(default)]
9123    pub expressions: Vec<Expression>,
9124}
9125
9126/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9128#[cfg_attr(feature = "bindings", derive(TS))]
9129pub struct RollupProperty {
9130    pub expressions: Vec<RollupIndex>,
9131}
9132
9133/// RollupIndex - A single rollup index: name(col1, col2)
9134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9135#[cfg_attr(feature = "bindings", derive(TS))]
9136pub struct RollupIndex {
9137    pub name: Identifier,
9138    pub expressions: Vec<Identifier>,
9139}
9140
9141/// PartitionBoundSpec
9142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9143#[cfg_attr(feature = "bindings", derive(TS))]
9144pub struct PartitionBoundSpec {
9145    #[serde(default)]
9146    pub this: Option<Box<Expression>>,
9147    #[serde(default)]
9148    pub expression: Option<Box<Expression>>,
9149    #[serde(default)]
9150    pub from_expressions: Option<Box<Expression>>,
9151    #[serde(default)]
9152    pub to_expressions: Option<Box<Expression>>,
9153}
9154
9155/// PartitionedOfProperty
9156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9157#[cfg_attr(feature = "bindings", derive(TS))]
9158pub struct PartitionedOfProperty {
9159    pub this: Box<Expression>,
9160    pub expression: Box<Expression>,
9161}
9162
9163/// RemoteWithConnectionModelProperty
9164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9165#[cfg_attr(feature = "bindings", derive(TS))]
9166pub struct RemoteWithConnectionModelProperty {
9167    pub this: Box<Expression>,
9168}
9169
9170/// ReturnsProperty
9171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9172#[cfg_attr(feature = "bindings", derive(TS))]
9173pub struct ReturnsProperty {
9174    #[serde(default)]
9175    pub this: Option<Box<Expression>>,
9176    #[serde(default)]
9177    pub is_table: Option<Box<Expression>>,
9178    #[serde(default)]
9179    pub table: Option<Box<Expression>>,
9180    #[serde(default)]
9181    pub null: Option<Box<Expression>>,
9182}
9183
9184/// RowFormatProperty
9185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9186#[cfg_attr(feature = "bindings", derive(TS))]
9187pub struct RowFormatProperty {
9188    pub this: Box<Expression>,
9189}
9190
9191/// RowFormatDelimitedProperty
9192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9193#[cfg_attr(feature = "bindings", derive(TS))]
9194pub struct RowFormatDelimitedProperty {
9195    #[serde(default)]
9196    pub fields: Option<Box<Expression>>,
9197    #[serde(default)]
9198    pub escaped: Option<Box<Expression>>,
9199    #[serde(default)]
9200    pub collection_items: Option<Box<Expression>>,
9201    #[serde(default)]
9202    pub map_keys: Option<Box<Expression>>,
9203    #[serde(default)]
9204    pub lines: Option<Box<Expression>>,
9205    #[serde(default)]
9206    pub null: Option<Box<Expression>>,
9207    #[serde(default)]
9208    pub serde: Option<Box<Expression>>,
9209}
9210
9211/// RowFormatSerdeProperty
9212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9213#[cfg_attr(feature = "bindings", derive(TS))]
9214pub struct RowFormatSerdeProperty {
9215    pub this: Box<Expression>,
9216    #[serde(default)]
9217    pub serde_properties: Option<Box<Expression>>,
9218}
9219
9220/// QueryTransform
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct QueryTransform {
9224    #[serde(default)]
9225    pub expressions: Vec<Expression>,
9226    #[serde(default)]
9227    pub command_script: Option<Box<Expression>>,
9228    #[serde(default)]
9229    pub schema: Option<Box<Expression>>,
9230    #[serde(default)]
9231    pub row_format_before: Option<Box<Expression>>,
9232    #[serde(default)]
9233    pub record_writer: Option<Box<Expression>>,
9234    #[serde(default)]
9235    pub row_format_after: Option<Box<Expression>>,
9236    #[serde(default)]
9237    pub record_reader: Option<Box<Expression>>,
9238}
9239
9240/// SampleProperty
9241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9242#[cfg_attr(feature = "bindings", derive(TS))]
9243pub struct SampleProperty {
9244    pub this: Box<Expression>,
9245}
9246
9247/// SecurityProperty
9248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9249#[cfg_attr(feature = "bindings", derive(TS))]
9250pub struct SecurityProperty {
9251    pub this: Box<Expression>,
9252}
9253
9254/// SchemaCommentProperty
9255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9256#[cfg_attr(feature = "bindings", derive(TS))]
9257pub struct SchemaCommentProperty {
9258    pub this: Box<Expression>,
9259}
9260
9261/// SemanticView
9262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9263#[cfg_attr(feature = "bindings", derive(TS))]
9264pub struct SemanticView {
9265    pub this: Box<Expression>,
9266    #[serde(default)]
9267    pub metrics: Option<Box<Expression>>,
9268    #[serde(default)]
9269    pub dimensions: Option<Box<Expression>>,
9270    #[serde(default)]
9271    pub facts: Option<Box<Expression>>,
9272    #[serde(default)]
9273    pub where_: Option<Box<Expression>>,
9274}
9275
9276/// SerdeProperties
9277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9278#[cfg_attr(feature = "bindings", derive(TS))]
9279pub struct SerdeProperties {
9280    #[serde(default)]
9281    pub expressions: Vec<Expression>,
9282    #[serde(default)]
9283    pub with_: Option<Box<Expression>>,
9284}
9285
9286/// SetProperty
9287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9288#[cfg_attr(feature = "bindings", derive(TS))]
9289pub struct SetProperty {
9290    #[serde(default)]
9291    pub multi: Option<Box<Expression>>,
9292}
9293
9294/// SharingProperty
9295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9296#[cfg_attr(feature = "bindings", derive(TS))]
9297pub struct SharingProperty {
9298    #[serde(default)]
9299    pub this: Option<Box<Expression>>,
9300}
9301
9302/// SetConfigProperty
9303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9304#[cfg_attr(feature = "bindings", derive(TS))]
9305pub struct SetConfigProperty {
9306    pub this: Box<Expression>,
9307}
9308
9309/// SettingsProperty
9310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9311#[cfg_attr(feature = "bindings", derive(TS))]
9312pub struct SettingsProperty {
9313    #[serde(default)]
9314    pub expressions: Vec<Expression>,
9315}
9316
9317/// SortKeyProperty
9318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9319#[cfg_attr(feature = "bindings", derive(TS))]
9320pub struct SortKeyProperty {
9321    pub this: Box<Expression>,
9322    #[serde(default)]
9323    pub compound: Option<Box<Expression>>,
9324}
9325
9326/// SqlReadWriteProperty
9327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9328#[cfg_attr(feature = "bindings", derive(TS))]
9329pub struct SqlReadWriteProperty {
9330    pub this: Box<Expression>,
9331}
9332
9333/// SqlSecurityProperty
9334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9335#[cfg_attr(feature = "bindings", derive(TS))]
9336pub struct SqlSecurityProperty {
9337    pub this: Box<Expression>,
9338}
9339
9340/// StabilityProperty
9341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9342#[cfg_attr(feature = "bindings", derive(TS))]
9343pub struct StabilityProperty {
9344    pub this: Box<Expression>,
9345}
9346
9347/// StorageHandlerProperty
9348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9349#[cfg_attr(feature = "bindings", derive(TS))]
9350pub struct StorageHandlerProperty {
9351    pub this: Box<Expression>,
9352}
9353
9354/// TemporaryProperty
9355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9356#[cfg_attr(feature = "bindings", derive(TS))]
9357pub struct TemporaryProperty {
9358    #[serde(default)]
9359    pub this: Option<Box<Expression>>,
9360}
9361
9362/// Tags
9363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9364#[cfg_attr(feature = "bindings", derive(TS))]
9365pub struct Tags {
9366    #[serde(default)]
9367    pub expressions: Vec<Expression>,
9368}
9369
9370/// TransformModelProperty
9371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9372#[cfg_attr(feature = "bindings", derive(TS))]
9373pub struct TransformModelProperty {
9374    #[serde(default)]
9375    pub expressions: Vec<Expression>,
9376}
9377
9378/// TransientProperty
9379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9380#[cfg_attr(feature = "bindings", derive(TS))]
9381pub struct TransientProperty {
9382    #[serde(default)]
9383    pub this: Option<Box<Expression>>,
9384}
9385
9386/// UsingTemplateProperty
9387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9388#[cfg_attr(feature = "bindings", derive(TS))]
9389pub struct UsingTemplateProperty {
9390    pub this: Box<Expression>,
9391}
9392
9393/// ViewAttributeProperty
9394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9395#[cfg_attr(feature = "bindings", derive(TS))]
9396pub struct ViewAttributeProperty {
9397    pub this: Box<Expression>,
9398}
9399
9400/// VolatileProperty
9401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9402#[cfg_attr(feature = "bindings", derive(TS))]
9403pub struct VolatileProperty {
9404    #[serde(default)]
9405    pub this: Option<Box<Expression>>,
9406}
9407
9408/// WithDataProperty
9409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9410#[cfg_attr(feature = "bindings", derive(TS))]
9411pub struct WithDataProperty {
9412    #[serde(default)]
9413    pub no: Option<Box<Expression>>,
9414    #[serde(default)]
9415    pub statistics: Option<Box<Expression>>,
9416}
9417
9418/// WithJournalTableProperty
9419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9420#[cfg_attr(feature = "bindings", derive(TS))]
9421pub struct WithJournalTableProperty {
9422    pub this: Box<Expression>,
9423}
9424
9425/// WithSchemaBindingProperty
9426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9427#[cfg_attr(feature = "bindings", derive(TS))]
9428pub struct WithSchemaBindingProperty {
9429    pub this: Box<Expression>,
9430}
9431
9432/// WithSystemVersioningProperty
9433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9434#[cfg_attr(feature = "bindings", derive(TS))]
9435pub struct WithSystemVersioningProperty {
9436    #[serde(default)]
9437    pub on: Option<Box<Expression>>,
9438    #[serde(default)]
9439    pub this: Option<Box<Expression>>,
9440    #[serde(default)]
9441    pub data_consistency: Option<Box<Expression>>,
9442    #[serde(default)]
9443    pub retention_period: Option<Box<Expression>>,
9444    #[serde(default)]
9445    pub with_: Option<Box<Expression>>,
9446}
9447
9448/// WithProcedureOptions
9449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9450#[cfg_attr(feature = "bindings", derive(TS))]
9451pub struct WithProcedureOptions {
9452    #[serde(default)]
9453    pub expressions: Vec<Expression>,
9454}
9455
9456/// EncodeProperty
9457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9458#[cfg_attr(feature = "bindings", derive(TS))]
9459pub struct EncodeProperty {
9460    pub this: Box<Expression>,
9461    #[serde(default)]
9462    pub properties: Vec<Expression>,
9463    #[serde(default)]
9464    pub key: Option<Box<Expression>>,
9465}
9466
9467/// IncludeProperty
9468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9469#[cfg_attr(feature = "bindings", derive(TS))]
9470pub struct IncludeProperty {
9471    pub this: Box<Expression>,
9472    #[serde(default)]
9473    pub alias: Option<String>,
9474    #[serde(default)]
9475    pub column_def: Option<Box<Expression>>,
9476}
9477
9478/// Properties
9479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9480#[cfg_attr(feature = "bindings", derive(TS))]
9481pub struct Properties {
9482    #[serde(default)]
9483    pub expressions: Vec<Expression>,
9484}
9485
9486/// InputOutputFormat
9487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9488#[cfg_attr(feature = "bindings", derive(TS))]
9489pub struct InputOutputFormat {
9490    #[serde(default)]
9491    pub input_format: Option<Box<Expression>>,
9492    #[serde(default)]
9493    pub output_format: Option<Box<Expression>>,
9494}
9495
9496/// Reference
9497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9498#[cfg_attr(feature = "bindings", derive(TS))]
9499pub struct Reference {
9500    pub this: Box<Expression>,
9501    #[serde(default)]
9502    pub expressions: Vec<Expression>,
9503    #[serde(default)]
9504    pub options: Vec<Expression>,
9505}
9506
9507/// QueryOption
9508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9509#[cfg_attr(feature = "bindings", derive(TS))]
9510pub struct QueryOption {
9511    pub this: Box<Expression>,
9512    #[serde(default)]
9513    pub expression: Option<Box<Expression>>,
9514}
9515
9516/// WithTableHint
9517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9518#[cfg_attr(feature = "bindings", derive(TS))]
9519pub struct WithTableHint {
9520    #[serde(default)]
9521    pub expressions: Vec<Expression>,
9522}
9523
9524/// IndexTableHint
9525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9526#[cfg_attr(feature = "bindings", derive(TS))]
9527pub struct IndexTableHint {
9528    pub this: Box<Expression>,
9529    #[serde(default)]
9530    pub expressions: Vec<Expression>,
9531    #[serde(default)]
9532    pub target: Option<Box<Expression>>,
9533}
9534
9535/// Get
9536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9537#[cfg_attr(feature = "bindings", derive(TS))]
9538pub struct Get {
9539    pub this: Box<Expression>,
9540    #[serde(default)]
9541    pub target: Option<Box<Expression>>,
9542    #[serde(default)]
9543    pub properties: Vec<Expression>,
9544}
9545
9546/// SetOperation
9547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9548#[cfg_attr(feature = "bindings", derive(TS))]
9549pub struct SetOperation {
9550    #[serde(default)]
9551    pub with_: Option<Box<Expression>>,
9552    pub this: Box<Expression>,
9553    pub expression: Box<Expression>,
9554    #[serde(default)]
9555    pub distinct: bool,
9556    #[serde(default)]
9557    pub by_name: Option<Box<Expression>>,
9558    #[serde(default)]
9559    pub side: Option<Box<Expression>>,
9560    #[serde(default)]
9561    pub kind: Option<String>,
9562    #[serde(default)]
9563    pub on: Option<Box<Expression>>,
9564}
9565
9566/// Var - Simple variable reference (for SQL variables, keywords as values)
9567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9568#[cfg_attr(feature = "bindings", derive(TS))]
9569pub struct Var {
9570    pub this: String,
9571}
9572
9573/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
9574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9575#[cfg_attr(feature = "bindings", derive(TS))]
9576pub struct Variadic {
9577    pub this: Box<Expression>,
9578}
9579
9580/// Version
9581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9582#[cfg_attr(feature = "bindings", derive(TS))]
9583pub struct Version {
9584    pub this: Box<Expression>,
9585    pub kind: String,
9586    #[serde(default)]
9587    pub expression: Option<Box<Expression>>,
9588}
9589
9590/// Schema
9591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9592#[cfg_attr(feature = "bindings", derive(TS))]
9593pub struct Schema {
9594    #[serde(default)]
9595    pub this: Option<Box<Expression>>,
9596    #[serde(default)]
9597    pub expressions: Vec<Expression>,
9598}
9599
9600/// Lock
9601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9602#[cfg_attr(feature = "bindings", derive(TS))]
9603pub struct Lock {
9604    #[serde(default)]
9605    pub update: Option<Box<Expression>>,
9606    #[serde(default)]
9607    pub expressions: Vec<Expression>,
9608    #[serde(default)]
9609    pub wait: Option<Box<Expression>>,
9610    #[serde(default)]
9611    pub key: Option<Box<Expression>>,
9612}
9613
9614/// TableSample - wraps an expression with a TABLESAMPLE clause
9615/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9617#[cfg_attr(feature = "bindings", derive(TS))]
9618pub struct TableSample {
9619    /// The expression being sampled (subquery, function, etc.)
9620    #[serde(default, skip_serializing_if = "Option::is_none")]
9621    pub this: Option<Box<Expression>>,
9622    /// The sample specification
9623    #[serde(default, skip_serializing_if = "Option::is_none")]
9624    pub sample: Option<Box<Sample>>,
9625    #[serde(default)]
9626    pub expressions: Vec<Expression>,
9627    #[serde(default)]
9628    pub method: Option<String>,
9629    #[serde(default)]
9630    pub bucket_numerator: Option<Box<Expression>>,
9631    #[serde(default)]
9632    pub bucket_denominator: Option<Box<Expression>>,
9633    #[serde(default)]
9634    pub bucket_field: Option<Box<Expression>>,
9635    #[serde(default)]
9636    pub percent: Option<Box<Expression>>,
9637    #[serde(default)]
9638    pub rows: Option<Box<Expression>>,
9639    #[serde(default)]
9640    pub size: Option<i64>,
9641    #[serde(default)]
9642    pub seed: Option<Box<Expression>>,
9643}
9644
9645/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9647#[cfg_attr(feature = "bindings", derive(TS))]
9648pub struct Tag {
9649    #[serde(default)]
9650    pub this: Option<Box<Expression>>,
9651    #[serde(default)]
9652    pub prefix: Option<Box<Expression>>,
9653    #[serde(default)]
9654    pub postfix: Option<Box<Expression>>,
9655}
9656
9657/// UnpivotColumns
9658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9659#[cfg_attr(feature = "bindings", derive(TS))]
9660pub struct UnpivotColumns {
9661    pub this: Box<Expression>,
9662    #[serde(default)]
9663    pub expressions: Vec<Expression>,
9664}
9665
9666/// SessionParameter
9667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9668#[cfg_attr(feature = "bindings", derive(TS))]
9669pub struct SessionParameter {
9670    pub this: Box<Expression>,
9671    #[serde(default)]
9672    pub kind: Option<String>,
9673}
9674
9675/// PseudoType
9676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9677#[cfg_attr(feature = "bindings", derive(TS))]
9678pub struct PseudoType {
9679    pub this: Box<Expression>,
9680}
9681
9682/// ObjectIdentifier
9683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9684#[cfg_attr(feature = "bindings", derive(TS))]
9685pub struct ObjectIdentifier {
9686    pub this: Box<Expression>,
9687}
9688
9689/// Transaction
9690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9691#[cfg_attr(feature = "bindings", derive(TS))]
9692pub struct Transaction {
9693    #[serde(default)]
9694    pub this: Option<Box<Expression>>,
9695    #[serde(default)]
9696    pub modes: Option<Box<Expression>>,
9697    #[serde(default)]
9698    pub mark: Option<Box<Expression>>,
9699}
9700
9701/// Commit
9702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9703#[cfg_attr(feature = "bindings", derive(TS))]
9704pub struct Commit {
9705    #[serde(default)]
9706    pub chain: Option<Box<Expression>>,
9707    #[serde(default)]
9708    pub this: Option<Box<Expression>>,
9709    #[serde(default)]
9710    pub durability: Option<Box<Expression>>,
9711}
9712
9713/// Rollback
9714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9715#[cfg_attr(feature = "bindings", derive(TS))]
9716pub struct Rollback {
9717    #[serde(default)]
9718    pub savepoint: Option<Box<Expression>>,
9719    #[serde(default)]
9720    pub this: Option<Box<Expression>>,
9721}
9722
9723/// AlterSession
9724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9725#[cfg_attr(feature = "bindings", derive(TS))]
9726pub struct AlterSession {
9727    #[serde(default)]
9728    pub expressions: Vec<Expression>,
9729    #[serde(default)]
9730    pub unset: Option<Box<Expression>>,
9731}
9732
9733/// Analyze
9734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9735#[cfg_attr(feature = "bindings", derive(TS))]
9736pub struct Analyze {
9737    #[serde(default)]
9738    pub kind: Option<String>,
9739    #[serde(default)]
9740    pub this: Option<Box<Expression>>,
9741    #[serde(default)]
9742    pub options: Vec<Expression>,
9743    #[serde(default)]
9744    pub mode: Option<Box<Expression>>,
9745    #[serde(default)]
9746    pub partition: Option<Box<Expression>>,
9747    #[serde(default)]
9748    pub expression: Option<Box<Expression>>,
9749    #[serde(default)]
9750    pub properties: Vec<Expression>,
9751    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9752    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9753    pub columns: Vec<String>,
9754}
9755
9756/// AnalyzeStatistics
9757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9758#[cfg_attr(feature = "bindings", derive(TS))]
9759pub struct AnalyzeStatistics {
9760    pub kind: String,
9761    #[serde(default)]
9762    pub option: Option<Box<Expression>>,
9763    #[serde(default)]
9764    pub this: Option<Box<Expression>>,
9765    #[serde(default)]
9766    pub expressions: Vec<Expression>,
9767}
9768
9769/// AnalyzeHistogram
9770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9771#[cfg_attr(feature = "bindings", derive(TS))]
9772pub struct AnalyzeHistogram {
9773    pub this: Box<Expression>,
9774    #[serde(default)]
9775    pub expressions: Vec<Expression>,
9776    #[serde(default)]
9777    pub expression: Option<Box<Expression>>,
9778    #[serde(default)]
9779    pub update_options: Option<Box<Expression>>,
9780}
9781
9782/// AnalyzeSample
9783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9784#[cfg_attr(feature = "bindings", derive(TS))]
9785pub struct AnalyzeSample {
9786    pub kind: String,
9787    #[serde(default)]
9788    pub sample: Option<Box<Expression>>,
9789}
9790
9791/// AnalyzeListChainedRows
9792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9793#[cfg_attr(feature = "bindings", derive(TS))]
9794pub struct AnalyzeListChainedRows {
9795    #[serde(default)]
9796    pub expression: Option<Box<Expression>>,
9797}
9798
9799/// AnalyzeDelete
9800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9801#[cfg_attr(feature = "bindings", derive(TS))]
9802pub struct AnalyzeDelete {
9803    #[serde(default)]
9804    pub kind: Option<String>,
9805}
9806
9807/// AnalyzeWith
9808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9809#[cfg_attr(feature = "bindings", derive(TS))]
9810pub struct AnalyzeWith {
9811    #[serde(default)]
9812    pub expressions: Vec<Expression>,
9813}
9814
9815/// AnalyzeValidate
9816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9817#[cfg_attr(feature = "bindings", derive(TS))]
9818pub struct AnalyzeValidate {
9819    pub kind: String,
9820    #[serde(default)]
9821    pub this: Option<Box<Expression>>,
9822    #[serde(default)]
9823    pub expression: Option<Box<Expression>>,
9824}
9825
9826/// AddPartition
9827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9828#[cfg_attr(feature = "bindings", derive(TS))]
9829pub struct AddPartition {
9830    pub this: Box<Expression>,
9831    #[serde(default)]
9832    pub exists: bool,
9833    #[serde(default)]
9834    pub location: Option<Box<Expression>>,
9835}
9836
9837/// AttachOption
9838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9839#[cfg_attr(feature = "bindings", derive(TS))]
9840pub struct AttachOption {
9841    pub this: Box<Expression>,
9842    #[serde(default)]
9843    pub expression: Option<Box<Expression>>,
9844}
9845
9846/// DropPartition
9847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9848#[cfg_attr(feature = "bindings", derive(TS))]
9849pub struct DropPartition {
9850    #[serde(default)]
9851    pub expressions: Vec<Expression>,
9852    #[serde(default)]
9853    pub exists: bool,
9854}
9855
9856/// ReplacePartition
9857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9858#[cfg_attr(feature = "bindings", derive(TS))]
9859pub struct ReplacePartition {
9860    pub expression: Box<Expression>,
9861    #[serde(default)]
9862    pub source: Option<Box<Expression>>,
9863}
9864
9865/// DPipe
9866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9867#[cfg_attr(feature = "bindings", derive(TS))]
9868pub struct DPipe {
9869    pub this: Box<Expression>,
9870    pub expression: Box<Expression>,
9871    #[serde(default)]
9872    pub safe: Option<Box<Expression>>,
9873}
9874
9875/// Operator
9876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9877#[cfg_attr(feature = "bindings", derive(TS))]
9878pub struct Operator {
9879    pub this: Box<Expression>,
9880    #[serde(default)]
9881    pub operator: Option<Box<Expression>>,
9882    pub expression: Box<Expression>,
9883    /// Comments between OPERATOR() and the RHS expression
9884    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9885    pub comments: Vec<String>,
9886}
9887
9888/// PivotAny
9889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9890#[cfg_attr(feature = "bindings", derive(TS))]
9891pub struct PivotAny {
9892    #[serde(default)]
9893    pub this: Option<Box<Expression>>,
9894}
9895
9896/// Aliases
9897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9898#[cfg_attr(feature = "bindings", derive(TS))]
9899pub struct Aliases {
9900    pub this: Box<Expression>,
9901    #[serde(default)]
9902    pub expressions: Vec<Expression>,
9903}
9904
9905/// AtIndex
9906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9907#[cfg_attr(feature = "bindings", derive(TS))]
9908pub struct AtIndex {
9909    pub this: Box<Expression>,
9910    pub expression: Box<Expression>,
9911}
9912
9913/// FromTimeZone
9914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9915#[cfg_attr(feature = "bindings", derive(TS))]
9916pub struct FromTimeZone {
9917    pub this: Box<Expression>,
9918    #[serde(default)]
9919    pub zone: Option<Box<Expression>>,
9920}
9921
9922/// Format override for a column in Teradata
9923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9924#[cfg_attr(feature = "bindings", derive(TS))]
9925pub struct FormatPhrase {
9926    pub this: Box<Expression>,
9927    pub format: String,
9928}
9929
9930/// ForIn
9931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9932#[cfg_attr(feature = "bindings", derive(TS))]
9933pub struct ForIn {
9934    pub this: Box<Expression>,
9935    pub expression: Box<Expression>,
9936}
9937
9938/// Automatically converts unit arg into a var.
9939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9940#[cfg_attr(feature = "bindings", derive(TS))]
9941pub struct TimeUnit {
9942    #[serde(default)]
9943    pub unit: Option<String>,
9944}
9945
9946/// IntervalOp
9947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9948#[cfg_attr(feature = "bindings", derive(TS))]
9949pub struct IntervalOp {
9950    #[serde(default)]
9951    pub unit: Option<String>,
9952    pub expression: Box<Expression>,
9953}
9954
9955/// HavingMax
9956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9957#[cfg_attr(feature = "bindings", derive(TS))]
9958pub struct HavingMax {
9959    pub this: Box<Expression>,
9960    pub expression: Box<Expression>,
9961    #[serde(default)]
9962    pub max: Option<Box<Expression>>,
9963}
9964
9965/// CosineDistance
9966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9967#[cfg_attr(feature = "bindings", derive(TS))]
9968pub struct CosineDistance {
9969    pub this: Box<Expression>,
9970    pub expression: Box<Expression>,
9971}
9972
9973/// DotProduct
9974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9975#[cfg_attr(feature = "bindings", derive(TS))]
9976pub struct DotProduct {
9977    pub this: Box<Expression>,
9978    pub expression: Box<Expression>,
9979}
9980
9981/// EuclideanDistance
9982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9983#[cfg_attr(feature = "bindings", derive(TS))]
9984pub struct EuclideanDistance {
9985    pub this: Box<Expression>,
9986    pub expression: Box<Expression>,
9987}
9988
9989/// ManhattanDistance
9990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9991#[cfg_attr(feature = "bindings", derive(TS))]
9992pub struct ManhattanDistance {
9993    pub this: Box<Expression>,
9994    pub expression: Box<Expression>,
9995}
9996
9997/// JarowinklerSimilarity
9998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9999#[cfg_attr(feature = "bindings", derive(TS))]
10000pub struct JarowinklerSimilarity {
10001    pub this: Box<Expression>,
10002    pub expression: Box<Expression>,
10003}
10004
10005/// Booland
10006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10007#[cfg_attr(feature = "bindings", derive(TS))]
10008pub struct Booland {
10009    pub this: Box<Expression>,
10010    pub expression: Box<Expression>,
10011}
10012
10013/// Boolor
10014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10015#[cfg_attr(feature = "bindings", derive(TS))]
10016pub struct Boolor {
10017    pub this: Box<Expression>,
10018    pub expression: Box<Expression>,
10019}
10020
10021/// ParameterizedAgg
10022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10023#[cfg_attr(feature = "bindings", derive(TS))]
10024pub struct ParameterizedAgg {
10025    pub this: Box<Expression>,
10026    #[serde(default)]
10027    pub expressions: Vec<Expression>,
10028    #[serde(default)]
10029    pub params: Vec<Expression>,
10030}
10031
10032/// ArgMax
10033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10034#[cfg_attr(feature = "bindings", derive(TS))]
10035pub struct ArgMax {
10036    pub this: Box<Expression>,
10037    pub expression: Box<Expression>,
10038    #[serde(default)]
10039    pub count: Option<Box<Expression>>,
10040}
10041
10042/// ArgMin
10043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10044#[cfg_attr(feature = "bindings", derive(TS))]
10045pub struct ArgMin {
10046    pub this: Box<Expression>,
10047    pub expression: Box<Expression>,
10048    #[serde(default)]
10049    pub count: Option<Box<Expression>>,
10050}
10051
10052/// ApproxTopK
10053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10054#[cfg_attr(feature = "bindings", derive(TS))]
10055pub struct ApproxTopK {
10056    pub this: Box<Expression>,
10057    #[serde(default)]
10058    pub expression: Option<Box<Expression>>,
10059    #[serde(default)]
10060    pub counters: Option<Box<Expression>>,
10061}
10062
10063/// ApproxTopKAccumulate
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct ApproxTopKAccumulate {
10067    pub this: Box<Expression>,
10068    #[serde(default)]
10069    pub expression: Option<Box<Expression>>,
10070}
10071
10072/// ApproxTopKCombine
10073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10074#[cfg_attr(feature = "bindings", derive(TS))]
10075pub struct ApproxTopKCombine {
10076    pub this: Box<Expression>,
10077    #[serde(default)]
10078    pub expression: Option<Box<Expression>>,
10079}
10080
10081/// ApproxTopKEstimate
10082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10083#[cfg_attr(feature = "bindings", derive(TS))]
10084pub struct ApproxTopKEstimate {
10085    pub this: Box<Expression>,
10086    #[serde(default)]
10087    pub expression: Option<Box<Expression>>,
10088}
10089
10090/// ApproxTopSum
10091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10092#[cfg_attr(feature = "bindings", derive(TS))]
10093pub struct ApproxTopSum {
10094    pub this: Box<Expression>,
10095    pub expression: Box<Expression>,
10096    #[serde(default)]
10097    pub count: Option<Box<Expression>>,
10098}
10099
10100/// ApproxQuantiles
10101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10102#[cfg_attr(feature = "bindings", derive(TS))]
10103pub struct ApproxQuantiles {
10104    pub this: Box<Expression>,
10105    #[serde(default)]
10106    pub expression: Option<Box<Expression>>,
10107}
10108
10109/// Minhash
10110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10111#[cfg_attr(feature = "bindings", derive(TS))]
10112pub struct Minhash {
10113    pub this: Box<Expression>,
10114    #[serde(default)]
10115    pub expressions: Vec<Expression>,
10116}
10117
10118/// FarmFingerprint
10119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10120#[cfg_attr(feature = "bindings", derive(TS))]
10121pub struct FarmFingerprint {
10122    #[serde(default)]
10123    pub expressions: Vec<Expression>,
10124}
10125
10126/// Float64
10127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10128#[cfg_attr(feature = "bindings", derive(TS))]
10129pub struct Float64 {
10130    pub this: Box<Expression>,
10131    #[serde(default)]
10132    pub expression: Option<Box<Expression>>,
10133}
10134
10135/// Transform
10136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10137#[cfg_attr(feature = "bindings", derive(TS))]
10138pub struct Transform {
10139    pub this: Box<Expression>,
10140    pub expression: Box<Expression>,
10141}
10142
10143/// Translate
10144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10145#[cfg_attr(feature = "bindings", derive(TS))]
10146pub struct Translate {
10147    pub this: Box<Expression>,
10148    #[serde(default)]
10149    pub from_: Option<Box<Expression>>,
10150    #[serde(default)]
10151    pub to: Option<Box<Expression>>,
10152}
10153
10154/// Grouping
10155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10156#[cfg_attr(feature = "bindings", derive(TS))]
10157pub struct Grouping {
10158    #[serde(default)]
10159    pub expressions: Vec<Expression>,
10160}
10161
10162/// GroupingId
10163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10164#[cfg_attr(feature = "bindings", derive(TS))]
10165pub struct GroupingId {
10166    #[serde(default)]
10167    pub expressions: Vec<Expression>,
10168}
10169
10170/// Anonymous
10171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10172#[cfg_attr(feature = "bindings", derive(TS))]
10173pub struct Anonymous {
10174    pub this: Box<Expression>,
10175    #[serde(default)]
10176    pub expressions: Vec<Expression>,
10177}
10178
10179/// AnonymousAggFunc
10180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10181#[cfg_attr(feature = "bindings", derive(TS))]
10182pub struct AnonymousAggFunc {
10183    pub this: Box<Expression>,
10184    #[serde(default)]
10185    pub expressions: Vec<Expression>,
10186}
10187
10188/// CombinedAggFunc
10189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10190#[cfg_attr(feature = "bindings", derive(TS))]
10191pub struct CombinedAggFunc {
10192    pub this: Box<Expression>,
10193    #[serde(default)]
10194    pub expressions: Vec<Expression>,
10195}
10196
10197/// CombinedParameterizedAgg
10198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10199#[cfg_attr(feature = "bindings", derive(TS))]
10200pub struct CombinedParameterizedAgg {
10201    pub this: Box<Expression>,
10202    #[serde(default)]
10203    pub expressions: Vec<Expression>,
10204    #[serde(default)]
10205    pub params: Vec<Expression>,
10206}
10207
10208/// HashAgg
10209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10210#[cfg_attr(feature = "bindings", derive(TS))]
10211pub struct HashAgg {
10212    pub this: Box<Expression>,
10213    #[serde(default)]
10214    pub expressions: Vec<Expression>,
10215}
10216
10217/// Hll
10218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10219#[cfg_attr(feature = "bindings", derive(TS))]
10220pub struct Hll {
10221    pub this: Box<Expression>,
10222    #[serde(default)]
10223    pub expressions: Vec<Expression>,
10224}
10225
10226/// Apply
10227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10228#[cfg_attr(feature = "bindings", derive(TS))]
10229pub struct Apply {
10230    pub this: Box<Expression>,
10231    pub expression: Box<Expression>,
10232}
10233
10234/// ToBoolean
10235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10236#[cfg_attr(feature = "bindings", derive(TS))]
10237pub struct ToBoolean {
10238    pub this: Box<Expression>,
10239    #[serde(default)]
10240    pub safe: Option<Box<Expression>>,
10241}
10242
10243/// List
10244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10245#[cfg_attr(feature = "bindings", derive(TS))]
10246pub struct List {
10247    #[serde(default)]
10248    pub expressions: Vec<Expression>,
10249}
10250
10251/// ToMap - Materialize-style map constructor
10252/// Can hold either:
10253/// - A SELECT subquery (MAP(SELECT 'a', 1))
10254/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10256#[cfg_attr(feature = "bindings", derive(TS))]
10257pub struct ToMap {
10258    /// Either a Select subquery or a Struct containing PropertyEQ entries
10259    pub this: Box<Expression>,
10260}
10261
10262/// Pad
10263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10264#[cfg_attr(feature = "bindings", derive(TS))]
10265pub struct Pad {
10266    pub this: Box<Expression>,
10267    pub expression: Box<Expression>,
10268    #[serde(default)]
10269    pub fill_pattern: Option<Box<Expression>>,
10270    #[serde(default)]
10271    pub is_left: Option<Box<Expression>>,
10272}
10273
10274/// ToChar
10275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10276#[cfg_attr(feature = "bindings", derive(TS))]
10277pub struct ToChar {
10278    pub this: Box<Expression>,
10279    #[serde(default)]
10280    pub format: Option<String>,
10281    #[serde(default)]
10282    pub nlsparam: Option<Box<Expression>>,
10283    #[serde(default)]
10284    pub is_numeric: Option<Box<Expression>>,
10285}
10286
10287/// StringFunc - String type conversion function (BigQuery STRING)
10288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10289#[cfg_attr(feature = "bindings", derive(TS))]
10290pub struct StringFunc {
10291    pub this: Box<Expression>,
10292    #[serde(default)]
10293    pub zone: Option<Box<Expression>>,
10294}
10295
10296/// ToNumber
10297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10298#[cfg_attr(feature = "bindings", derive(TS))]
10299pub struct ToNumber {
10300    pub this: Box<Expression>,
10301    #[serde(default)]
10302    pub format: Option<Box<Expression>>,
10303    #[serde(default)]
10304    pub nlsparam: Option<Box<Expression>>,
10305    #[serde(default)]
10306    pub precision: Option<Box<Expression>>,
10307    #[serde(default)]
10308    pub scale: Option<Box<Expression>>,
10309    #[serde(default)]
10310    pub safe: Option<Box<Expression>>,
10311    #[serde(default)]
10312    pub safe_name: Option<Box<Expression>>,
10313}
10314
10315/// ToDouble
10316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10317#[cfg_attr(feature = "bindings", derive(TS))]
10318pub struct ToDouble {
10319    pub this: Box<Expression>,
10320    #[serde(default)]
10321    pub format: Option<String>,
10322    #[serde(default)]
10323    pub safe: Option<Box<Expression>>,
10324}
10325
10326/// ToDecfloat
10327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10328#[cfg_attr(feature = "bindings", derive(TS))]
10329pub struct ToDecfloat {
10330    pub this: Box<Expression>,
10331    #[serde(default)]
10332    pub format: Option<String>,
10333}
10334
10335/// TryToDecfloat
10336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10337#[cfg_attr(feature = "bindings", derive(TS))]
10338pub struct TryToDecfloat {
10339    pub this: Box<Expression>,
10340    #[serde(default)]
10341    pub format: Option<String>,
10342}
10343
10344/// ToFile
10345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10346#[cfg_attr(feature = "bindings", derive(TS))]
10347pub struct ToFile {
10348    pub this: Box<Expression>,
10349    #[serde(default)]
10350    pub path: Option<Box<Expression>>,
10351    #[serde(default)]
10352    pub safe: Option<Box<Expression>>,
10353}
10354
10355/// Columns
10356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10357#[cfg_attr(feature = "bindings", derive(TS))]
10358pub struct Columns {
10359    pub this: Box<Expression>,
10360    #[serde(default)]
10361    pub unpack: Option<Box<Expression>>,
10362}
10363
10364/// ConvertToCharset
10365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10366#[cfg_attr(feature = "bindings", derive(TS))]
10367pub struct ConvertToCharset {
10368    pub this: Box<Expression>,
10369    #[serde(default)]
10370    pub dest: Option<Box<Expression>>,
10371    #[serde(default)]
10372    pub source: Option<Box<Expression>>,
10373}
10374
10375/// ConvertTimezone
10376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10377#[cfg_attr(feature = "bindings", derive(TS))]
10378pub struct ConvertTimezone {
10379    #[serde(default)]
10380    pub source_tz: Option<Box<Expression>>,
10381    #[serde(default)]
10382    pub target_tz: Option<Box<Expression>>,
10383    #[serde(default)]
10384    pub timestamp: Option<Box<Expression>>,
10385    #[serde(default)]
10386    pub options: Vec<Expression>,
10387}
10388
10389/// GenerateSeries
10390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10391#[cfg_attr(feature = "bindings", derive(TS))]
10392pub struct GenerateSeries {
10393    #[serde(default)]
10394    pub start: Option<Box<Expression>>,
10395    #[serde(default)]
10396    pub end: Option<Box<Expression>>,
10397    #[serde(default)]
10398    pub step: Option<Box<Expression>>,
10399    #[serde(default)]
10400    pub is_end_exclusive: Option<Box<Expression>>,
10401}
10402
10403/// AIAgg
10404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10405#[cfg_attr(feature = "bindings", derive(TS))]
10406pub struct AIAgg {
10407    pub this: Box<Expression>,
10408    pub expression: Box<Expression>,
10409}
10410
10411/// AIClassify
10412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10413#[cfg_attr(feature = "bindings", derive(TS))]
10414pub struct AIClassify {
10415    pub this: Box<Expression>,
10416    #[serde(default)]
10417    pub categories: Option<Box<Expression>>,
10418    #[serde(default)]
10419    pub config: Option<Box<Expression>>,
10420}
10421
10422/// ArrayAll
10423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10424#[cfg_attr(feature = "bindings", derive(TS))]
10425pub struct ArrayAll {
10426    pub this: Box<Expression>,
10427    pub expression: Box<Expression>,
10428}
10429
10430/// ArrayAny
10431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10432#[cfg_attr(feature = "bindings", derive(TS))]
10433pub struct ArrayAny {
10434    pub this: Box<Expression>,
10435    pub expression: Box<Expression>,
10436}
10437
10438/// ArrayConstructCompact
10439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10440#[cfg_attr(feature = "bindings", derive(TS))]
10441pub struct ArrayConstructCompact {
10442    #[serde(default)]
10443    pub expressions: Vec<Expression>,
10444}
10445
10446/// StPoint
10447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10448#[cfg_attr(feature = "bindings", derive(TS))]
10449pub struct StPoint {
10450    pub this: Box<Expression>,
10451    pub expression: Box<Expression>,
10452    #[serde(default)]
10453    pub null: Option<Box<Expression>>,
10454}
10455
10456/// StDistance
10457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10458#[cfg_attr(feature = "bindings", derive(TS))]
10459pub struct StDistance {
10460    pub this: Box<Expression>,
10461    pub expression: Box<Expression>,
10462    #[serde(default)]
10463    pub use_spheroid: Option<Box<Expression>>,
10464}
10465
10466/// StringToArray
10467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10468#[cfg_attr(feature = "bindings", derive(TS))]
10469pub struct StringToArray {
10470    pub this: Box<Expression>,
10471    #[serde(default)]
10472    pub expression: Option<Box<Expression>>,
10473    #[serde(default)]
10474    pub null: Option<Box<Expression>>,
10475}
10476
10477/// ArraySum
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct ArraySum {
10481    pub this: Box<Expression>,
10482    #[serde(default)]
10483    pub expression: Option<Box<Expression>>,
10484}
10485
10486/// ObjectAgg
10487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10488#[cfg_attr(feature = "bindings", derive(TS))]
10489pub struct ObjectAgg {
10490    pub this: Box<Expression>,
10491    pub expression: Box<Expression>,
10492}
10493
10494/// CastToStrType
10495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10496#[cfg_attr(feature = "bindings", derive(TS))]
10497pub struct CastToStrType {
10498    pub this: Box<Expression>,
10499    #[serde(default)]
10500    pub to: Option<Box<Expression>>,
10501}
10502
10503/// CheckJson
10504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10505#[cfg_attr(feature = "bindings", derive(TS))]
10506pub struct CheckJson {
10507    pub this: Box<Expression>,
10508}
10509
10510/// CheckXml
10511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10512#[cfg_attr(feature = "bindings", derive(TS))]
10513pub struct CheckXml {
10514    pub this: Box<Expression>,
10515    #[serde(default)]
10516    pub disable_auto_convert: Option<Box<Expression>>,
10517}
10518
10519/// TranslateCharacters
10520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10521#[cfg_attr(feature = "bindings", derive(TS))]
10522pub struct TranslateCharacters {
10523    pub this: Box<Expression>,
10524    pub expression: Box<Expression>,
10525    #[serde(default)]
10526    pub with_error: Option<Box<Expression>>,
10527}
10528
10529/// CurrentSchemas
10530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10531#[cfg_attr(feature = "bindings", derive(TS))]
10532pub struct CurrentSchemas {
10533    #[serde(default)]
10534    pub this: Option<Box<Expression>>,
10535}
10536
10537/// CurrentDatetime
10538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10539#[cfg_attr(feature = "bindings", derive(TS))]
10540pub struct CurrentDatetime {
10541    #[serde(default)]
10542    pub this: Option<Box<Expression>>,
10543}
10544
10545/// Localtime
10546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10547#[cfg_attr(feature = "bindings", derive(TS))]
10548pub struct Localtime {
10549    #[serde(default)]
10550    pub this: Option<Box<Expression>>,
10551}
10552
10553/// Localtimestamp
10554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10555#[cfg_attr(feature = "bindings", derive(TS))]
10556pub struct Localtimestamp {
10557    #[serde(default)]
10558    pub this: Option<Box<Expression>>,
10559}
10560
10561/// Systimestamp
10562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10563#[cfg_attr(feature = "bindings", derive(TS))]
10564pub struct Systimestamp {
10565    #[serde(default)]
10566    pub this: Option<Box<Expression>>,
10567}
10568
10569/// CurrentSchema
10570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10571#[cfg_attr(feature = "bindings", derive(TS))]
10572pub struct CurrentSchema {
10573    #[serde(default)]
10574    pub this: Option<Box<Expression>>,
10575}
10576
10577/// CurrentUser
10578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10579#[cfg_attr(feature = "bindings", derive(TS))]
10580pub struct CurrentUser {
10581    #[serde(default)]
10582    pub this: Option<Box<Expression>>,
10583}
10584
10585/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10587#[cfg_attr(feature = "bindings", derive(TS))]
10588pub struct SessionUser;
10589
10590/// JSONPathRoot - Represents $ in JSON path expressions
10591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10592#[cfg_attr(feature = "bindings", derive(TS))]
10593pub struct JSONPathRoot;
10594
10595/// UtcTime
10596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10597#[cfg_attr(feature = "bindings", derive(TS))]
10598pub struct UtcTime {
10599    #[serde(default)]
10600    pub this: Option<Box<Expression>>,
10601}
10602
10603/// UtcTimestamp
10604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10605#[cfg_attr(feature = "bindings", derive(TS))]
10606pub struct UtcTimestamp {
10607    #[serde(default)]
10608    pub this: Option<Box<Expression>>,
10609}
10610
10611/// TimestampFunc - TIMESTAMP constructor function
10612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10613#[cfg_attr(feature = "bindings", derive(TS))]
10614pub struct TimestampFunc {
10615    #[serde(default)]
10616    pub this: Option<Box<Expression>>,
10617    #[serde(default)]
10618    pub zone: Option<Box<Expression>>,
10619    #[serde(default)]
10620    pub with_tz: Option<bool>,
10621    #[serde(default)]
10622    pub safe: Option<bool>,
10623}
10624
10625/// DateBin
10626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10627#[cfg_attr(feature = "bindings", derive(TS))]
10628pub struct DateBin {
10629    pub this: Box<Expression>,
10630    pub expression: Box<Expression>,
10631    #[serde(default)]
10632    pub unit: Option<String>,
10633    #[serde(default)]
10634    pub zone: Option<Box<Expression>>,
10635    #[serde(default)]
10636    pub origin: Option<Box<Expression>>,
10637}
10638
10639/// Datetime
10640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10641#[cfg_attr(feature = "bindings", derive(TS))]
10642pub struct Datetime {
10643    pub this: Box<Expression>,
10644    #[serde(default)]
10645    pub expression: Option<Box<Expression>>,
10646}
10647
10648/// DatetimeAdd
10649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10650#[cfg_attr(feature = "bindings", derive(TS))]
10651pub struct DatetimeAdd {
10652    pub this: Box<Expression>,
10653    pub expression: Box<Expression>,
10654    #[serde(default)]
10655    pub unit: Option<String>,
10656}
10657
10658/// DatetimeSub
10659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10660#[cfg_attr(feature = "bindings", derive(TS))]
10661pub struct DatetimeSub {
10662    pub this: Box<Expression>,
10663    pub expression: Box<Expression>,
10664    #[serde(default)]
10665    pub unit: Option<String>,
10666}
10667
10668/// DatetimeDiff
10669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10670#[cfg_attr(feature = "bindings", derive(TS))]
10671pub struct DatetimeDiff {
10672    pub this: Box<Expression>,
10673    pub expression: Box<Expression>,
10674    #[serde(default)]
10675    pub unit: Option<String>,
10676}
10677
10678/// DatetimeTrunc
10679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10680#[cfg_attr(feature = "bindings", derive(TS))]
10681pub struct DatetimeTrunc {
10682    pub this: Box<Expression>,
10683    pub unit: String,
10684    #[serde(default)]
10685    pub zone: Option<Box<Expression>>,
10686}
10687
10688/// Dayname
10689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10690#[cfg_attr(feature = "bindings", derive(TS))]
10691pub struct Dayname {
10692    pub this: Box<Expression>,
10693    #[serde(default)]
10694    pub abbreviated: Option<Box<Expression>>,
10695}
10696
10697/// MakeInterval
10698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10699#[cfg_attr(feature = "bindings", derive(TS))]
10700pub struct MakeInterval {
10701    #[serde(default)]
10702    pub year: Option<Box<Expression>>,
10703    #[serde(default)]
10704    pub month: Option<Box<Expression>>,
10705    #[serde(default)]
10706    pub week: Option<Box<Expression>>,
10707    #[serde(default)]
10708    pub day: Option<Box<Expression>>,
10709    #[serde(default)]
10710    pub hour: Option<Box<Expression>>,
10711    #[serde(default)]
10712    pub minute: Option<Box<Expression>>,
10713    #[serde(default)]
10714    pub second: Option<Box<Expression>>,
10715}
10716
10717/// PreviousDay
10718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10719#[cfg_attr(feature = "bindings", derive(TS))]
10720pub struct PreviousDay {
10721    pub this: Box<Expression>,
10722    pub expression: Box<Expression>,
10723}
10724
10725/// Elt
10726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10727#[cfg_attr(feature = "bindings", derive(TS))]
10728pub struct Elt {
10729    pub this: Box<Expression>,
10730    #[serde(default)]
10731    pub expressions: Vec<Expression>,
10732}
10733
10734/// TimestampAdd
10735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10736#[cfg_attr(feature = "bindings", derive(TS))]
10737pub struct TimestampAdd {
10738    pub this: Box<Expression>,
10739    pub expression: Box<Expression>,
10740    #[serde(default)]
10741    pub unit: Option<String>,
10742}
10743
10744/// TimestampSub
10745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10746#[cfg_attr(feature = "bindings", derive(TS))]
10747pub struct TimestampSub {
10748    pub this: Box<Expression>,
10749    pub expression: Box<Expression>,
10750    #[serde(default)]
10751    pub unit: Option<String>,
10752}
10753
10754/// TimestampDiff
10755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10756#[cfg_attr(feature = "bindings", derive(TS))]
10757pub struct TimestampDiff {
10758    pub this: Box<Expression>,
10759    pub expression: Box<Expression>,
10760    #[serde(default)]
10761    pub unit: Option<String>,
10762}
10763
10764/// TimeSlice
10765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10766#[cfg_attr(feature = "bindings", derive(TS))]
10767pub struct TimeSlice {
10768    pub this: Box<Expression>,
10769    pub expression: Box<Expression>,
10770    pub unit: String,
10771    #[serde(default)]
10772    pub kind: Option<String>,
10773}
10774
10775/// TimeAdd
10776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10777#[cfg_attr(feature = "bindings", derive(TS))]
10778pub struct TimeAdd {
10779    pub this: Box<Expression>,
10780    pub expression: Box<Expression>,
10781    #[serde(default)]
10782    pub unit: Option<String>,
10783}
10784
10785/// TimeSub
10786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10787#[cfg_attr(feature = "bindings", derive(TS))]
10788pub struct TimeSub {
10789    pub this: Box<Expression>,
10790    pub expression: Box<Expression>,
10791    #[serde(default)]
10792    pub unit: Option<String>,
10793}
10794
10795/// TimeDiff
10796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10797#[cfg_attr(feature = "bindings", derive(TS))]
10798pub struct TimeDiff {
10799    pub this: Box<Expression>,
10800    pub expression: Box<Expression>,
10801    #[serde(default)]
10802    pub unit: Option<String>,
10803}
10804
10805/// TimeTrunc
10806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10807#[cfg_attr(feature = "bindings", derive(TS))]
10808pub struct TimeTrunc {
10809    pub this: Box<Expression>,
10810    pub unit: String,
10811    #[serde(default)]
10812    pub zone: Option<Box<Expression>>,
10813}
10814
10815/// DateFromParts
10816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10817#[cfg_attr(feature = "bindings", derive(TS))]
10818pub struct DateFromParts {
10819    #[serde(default)]
10820    pub year: Option<Box<Expression>>,
10821    #[serde(default)]
10822    pub month: Option<Box<Expression>>,
10823    #[serde(default)]
10824    pub day: Option<Box<Expression>>,
10825    #[serde(default)]
10826    pub allow_overflow: Option<Box<Expression>>,
10827}
10828
10829/// TimeFromParts
10830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10831#[cfg_attr(feature = "bindings", derive(TS))]
10832pub struct TimeFromParts {
10833    #[serde(default)]
10834    pub hour: Option<Box<Expression>>,
10835    #[serde(default)]
10836    pub min: Option<Box<Expression>>,
10837    #[serde(default)]
10838    pub sec: Option<Box<Expression>>,
10839    #[serde(default)]
10840    pub nano: Option<Box<Expression>>,
10841    #[serde(default)]
10842    pub fractions: Option<Box<Expression>>,
10843    #[serde(default)]
10844    pub precision: Option<i64>,
10845}
10846
10847/// DecodeCase
10848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10849#[cfg_attr(feature = "bindings", derive(TS))]
10850pub struct DecodeCase {
10851    #[serde(default)]
10852    pub expressions: Vec<Expression>,
10853}
10854
10855/// Decrypt
10856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10857#[cfg_attr(feature = "bindings", derive(TS))]
10858pub struct Decrypt {
10859    pub this: Box<Expression>,
10860    #[serde(default)]
10861    pub passphrase: Option<Box<Expression>>,
10862    #[serde(default)]
10863    pub aad: Option<Box<Expression>>,
10864    #[serde(default)]
10865    pub encryption_method: Option<Box<Expression>>,
10866    #[serde(default)]
10867    pub safe: Option<Box<Expression>>,
10868}
10869
10870/// DecryptRaw
10871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10872#[cfg_attr(feature = "bindings", derive(TS))]
10873pub struct DecryptRaw {
10874    pub this: Box<Expression>,
10875    #[serde(default)]
10876    pub key: Option<Box<Expression>>,
10877    #[serde(default)]
10878    pub iv: Option<Box<Expression>>,
10879    #[serde(default)]
10880    pub aad: Option<Box<Expression>>,
10881    #[serde(default)]
10882    pub encryption_method: Option<Box<Expression>>,
10883    #[serde(default)]
10884    pub aead: Option<Box<Expression>>,
10885    #[serde(default)]
10886    pub safe: Option<Box<Expression>>,
10887}
10888
10889/// Encode
10890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10891#[cfg_attr(feature = "bindings", derive(TS))]
10892pub struct Encode {
10893    pub this: Box<Expression>,
10894    #[serde(default)]
10895    pub charset: Option<Box<Expression>>,
10896}
10897
10898/// Encrypt
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct Encrypt {
10902    pub this: Box<Expression>,
10903    #[serde(default)]
10904    pub passphrase: Option<Box<Expression>>,
10905    #[serde(default)]
10906    pub aad: Option<Box<Expression>>,
10907    #[serde(default)]
10908    pub encryption_method: Option<Box<Expression>>,
10909}
10910
10911/// EncryptRaw
10912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10913#[cfg_attr(feature = "bindings", derive(TS))]
10914pub struct EncryptRaw {
10915    pub this: Box<Expression>,
10916    #[serde(default)]
10917    pub key: Option<Box<Expression>>,
10918    #[serde(default)]
10919    pub iv: Option<Box<Expression>>,
10920    #[serde(default)]
10921    pub aad: Option<Box<Expression>>,
10922    #[serde(default)]
10923    pub encryption_method: Option<Box<Expression>>,
10924}
10925
10926/// EqualNull
10927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10928#[cfg_attr(feature = "bindings", derive(TS))]
10929pub struct EqualNull {
10930    pub this: Box<Expression>,
10931    pub expression: Box<Expression>,
10932}
10933
10934/// ToBinary
10935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10936#[cfg_attr(feature = "bindings", derive(TS))]
10937pub struct ToBinary {
10938    pub this: Box<Expression>,
10939    #[serde(default)]
10940    pub format: Option<String>,
10941    #[serde(default)]
10942    pub safe: Option<Box<Expression>>,
10943}
10944
10945/// Base64DecodeBinary
10946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10947#[cfg_attr(feature = "bindings", derive(TS))]
10948pub struct Base64DecodeBinary {
10949    pub this: Box<Expression>,
10950    #[serde(default)]
10951    pub alphabet: Option<Box<Expression>>,
10952}
10953
10954/// Base64DecodeString
10955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10956#[cfg_attr(feature = "bindings", derive(TS))]
10957pub struct Base64DecodeString {
10958    pub this: Box<Expression>,
10959    #[serde(default)]
10960    pub alphabet: Option<Box<Expression>>,
10961}
10962
10963/// Base64Encode
10964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10965#[cfg_attr(feature = "bindings", derive(TS))]
10966pub struct Base64Encode {
10967    pub this: Box<Expression>,
10968    #[serde(default)]
10969    pub max_line_length: Option<Box<Expression>>,
10970    #[serde(default)]
10971    pub alphabet: Option<Box<Expression>>,
10972}
10973
10974/// TryBase64DecodeBinary
10975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10976#[cfg_attr(feature = "bindings", derive(TS))]
10977pub struct TryBase64DecodeBinary {
10978    pub this: Box<Expression>,
10979    #[serde(default)]
10980    pub alphabet: Option<Box<Expression>>,
10981}
10982
10983/// TryBase64DecodeString
10984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10985#[cfg_attr(feature = "bindings", derive(TS))]
10986pub struct TryBase64DecodeString {
10987    pub this: Box<Expression>,
10988    #[serde(default)]
10989    pub alphabet: Option<Box<Expression>>,
10990}
10991
10992/// GapFill
10993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10994#[cfg_attr(feature = "bindings", derive(TS))]
10995pub struct GapFill {
10996    pub this: Box<Expression>,
10997    #[serde(default)]
10998    pub ts_column: Option<Box<Expression>>,
10999    #[serde(default)]
11000    pub bucket_width: Option<Box<Expression>>,
11001    #[serde(default)]
11002    pub partitioning_columns: Option<Box<Expression>>,
11003    #[serde(default)]
11004    pub value_columns: Option<Box<Expression>>,
11005    #[serde(default)]
11006    pub origin: Option<Box<Expression>>,
11007    #[serde(default)]
11008    pub ignore_nulls: Option<Box<Expression>>,
11009}
11010
11011/// GenerateDateArray
11012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11013#[cfg_attr(feature = "bindings", derive(TS))]
11014pub struct GenerateDateArray {
11015    #[serde(default)]
11016    pub start: Option<Box<Expression>>,
11017    #[serde(default)]
11018    pub end: Option<Box<Expression>>,
11019    #[serde(default)]
11020    pub step: Option<Box<Expression>>,
11021}
11022
11023/// GenerateTimestampArray
11024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11025#[cfg_attr(feature = "bindings", derive(TS))]
11026pub struct GenerateTimestampArray {
11027    #[serde(default)]
11028    pub start: Option<Box<Expression>>,
11029    #[serde(default)]
11030    pub end: Option<Box<Expression>>,
11031    #[serde(default)]
11032    pub step: Option<Box<Expression>>,
11033}
11034
11035/// GetExtract
11036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11037#[cfg_attr(feature = "bindings", derive(TS))]
11038pub struct GetExtract {
11039    pub this: Box<Expression>,
11040    pub expression: Box<Expression>,
11041}
11042
11043/// Getbit
11044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11045#[cfg_attr(feature = "bindings", derive(TS))]
11046pub struct Getbit {
11047    pub this: Box<Expression>,
11048    pub expression: Box<Expression>,
11049    #[serde(default)]
11050    pub zero_is_msb: Option<Box<Expression>>,
11051}
11052
11053/// OverflowTruncateBehavior
11054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11055#[cfg_attr(feature = "bindings", derive(TS))]
11056pub struct OverflowTruncateBehavior {
11057    #[serde(default)]
11058    pub this: Option<Box<Expression>>,
11059    #[serde(default)]
11060    pub with_count: Option<Box<Expression>>,
11061}
11062
11063/// HexEncode
11064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11065#[cfg_attr(feature = "bindings", derive(TS))]
11066pub struct HexEncode {
11067    pub this: Box<Expression>,
11068    #[serde(default)]
11069    pub case: Option<Box<Expression>>,
11070}
11071
11072/// Compress
11073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11074#[cfg_attr(feature = "bindings", derive(TS))]
11075pub struct Compress {
11076    pub this: Box<Expression>,
11077    #[serde(default)]
11078    pub method: Option<String>,
11079}
11080
11081/// DecompressBinary
11082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11083#[cfg_attr(feature = "bindings", derive(TS))]
11084pub struct DecompressBinary {
11085    pub this: Box<Expression>,
11086    pub method: String,
11087}
11088
11089/// DecompressString
11090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11091#[cfg_attr(feature = "bindings", derive(TS))]
11092pub struct DecompressString {
11093    pub this: Box<Expression>,
11094    pub method: String,
11095}
11096
11097/// Xor
11098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11099#[cfg_attr(feature = "bindings", derive(TS))]
11100pub struct Xor {
11101    #[serde(default)]
11102    pub this: Option<Box<Expression>>,
11103    #[serde(default)]
11104    pub expression: Option<Box<Expression>>,
11105    #[serde(default)]
11106    pub expressions: Vec<Expression>,
11107}
11108
11109/// Nullif
11110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11111#[cfg_attr(feature = "bindings", derive(TS))]
11112pub struct Nullif {
11113    pub this: Box<Expression>,
11114    pub expression: Box<Expression>,
11115}
11116
11117/// JSON
11118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11119#[cfg_attr(feature = "bindings", derive(TS))]
11120pub struct JSON {
11121    #[serde(default)]
11122    pub this: Option<Box<Expression>>,
11123    #[serde(default)]
11124    pub with_: Option<Box<Expression>>,
11125    #[serde(default)]
11126    pub unique: bool,
11127}
11128
11129/// JSONPath
11130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11131#[cfg_attr(feature = "bindings", derive(TS))]
11132pub struct JSONPath {
11133    #[serde(default)]
11134    pub expressions: Vec<Expression>,
11135    #[serde(default)]
11136    pub escape: Option<Box<Expression>>,
11137}
11138
11139/// JSONPathFilter
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct JSONPathFilter {
11143    pub this: Box<Expression>,
11144}
11145
11146/// JSONPathKey
11147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11148#[cfg_attr(feature = "bindings", derive(TS))]
11149pub struct JSONPathKey {
11150    pub this: Box<Expression>,
11151}
11152
11153/// JSONPathRecursive
11154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11155#[cfg_attr(feature = "bindings", derive(TS))]
11156pub struct JSONPathRecursive {
11157    #[serde(default)]
11158    pub this: Option<Box<Expression>>,
11159}
11160
11161/// JSONPathScript
11162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11163#[cfg_attr(feature = "bindings", derive(TS))]
11164pub struct JSONPathScript {
11165    pub this: Box<Expression>,
11166}
11167
11168/// JSONPathSlice
11169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11170#[cfg_attr(feature = "bindings", derive(TS))]
11171pub struct JSONPathSlice {
11172    #[serde(default)]
11173    pub start: Option<Box<Expression>>,
11174    #[serde(default)]
11175    pub end: Option<Box<Expression>>,
11176    #[serde(default)]
11177    pub step: Option<Box<Expression>>,
11178}
11179
11180/// JSONPathSelector
11181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11182#[cfg_attr(feature = "bindings", derive(TS))]
11183pub struct JSONPathSelector {
11184    pub this: Box<Expression>,
11185}
11186
11187/// JSONPathSubscript
11188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11189#[cfg_attr(feature = "bindings", derive(TS))]
11190pub struct JSONPathSubscript {
11191    pub this: Box<Expression>,
11192}
11193
11194/// JSONPathUnion
11195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11196#[cfg_attr(feature = "bindings", derive(TS))]
11197pub struct JSONPathUnion {
11198    #[serde(default)]
11199    pub expressions: Vec<Expression>,
11200}
11201
11202/// Format
11203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11204#[cfg_attr(feature = "bindings", derive(TS))]
11205pub struct Format {
11206    pub this: Box<Expression>,
11207    #[serde(default)]
11208    pub expressions: Vec<Expression>,
11209}
11210
11211/// JSONKeys
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct JSONKeys {
11215    pub this: Box<Expression>,
11216    #[serde(default)]
11217    pub expression: Option<Box<Expression>>,
11218    #[serde(default)]
11219    pub expressions: Vec<Expression>,
11220}
11221
11222/// JSONKeyValue
11223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11224#[cfg_attr(feature = "bindings", derive(TS))]
11225pub struct JSONKeyValue {
11226    pub this: Box<Expression>,
11227    pub expression: Box<Expression>,
11228}
11229
11230/// JSONKeysAtDepth
11231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11232#[cfg_attr(feature = "bindings", derive(TS))]
11233pub struct JSONKeysAtDepth {
11234    pub this: Box<Expression>,
11235    #[serde(default)]
11236    pub expression: Option<Box<Expression>>,
11237    #[serde(default)]
11238    pub mode: Option<Box<Expression>>,
11239}
11240
11241/// JSONObject
11242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11243#[cfg_attr(feature = "bindings", derive(TS))]
11244pub struct JSONObject {
11245    #[serde(default)]
11246    pub expressions: Vec<Expression>,
11247    #[serde(default)]
11248    pub null_handling: Option<Box<Expression>>,
11249    #[serde(default)]
11250    pub unique_keys: Option<Box<Expression>>,
11251    #[serde(default)]
11252    pub return_type: Option<Box<Expression>>,
11253    #[serde(default)]
11254    pub encoding: Option<Box<Expression>>,
11255}
11256
11257/// JSONObjectAgg
11258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11259#[cfg_attr(feature = "bindings", derive(TS))]
11260pub struct JSONObjectAgg {
11261    #[serde(default)]
11262    pub expressions: Vec<Expression>,
11263    #[serde(default)]
11264    pub null_handling: Option<Box<Expression>>,
11265    #[serde(default)]
11266    pub unique_keys: Option<Box<Expression>>,
11267    #[serde(default)]
11268    pub return_type: Option<Box<Expression>>,
11269    #[serde(default)]
11270    pub encoding: Option<Box<Expression>>,
11271}
11272
11273/// JSONBObjectAgg
11274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11275#[cfg_attr(feature = "bindings", derive(TS))]
11276pub struct JSONBObjectAgg {
11277    pub this: Box<Expression>,
11278    pub expression: Box<Expression>,
11279}
11280
11281/// JSONArray
11282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11283#[cfg_attr(feature = "bindings", derive(TS))]
11284pub struct JSONArray {
11285    #[serde(default)]
11286    pub expressions: Vec<Expression>,
11287    #[serde(default)]
11288    pub null_handling: Option<Box<Expression>>,
11289    #[serde(default)]
11290    pub return_type: Option<Box<Expression>>,
11291    #[serde(default)]
11292    pub strict: Option<Box<Expression>>,
11293}
11294
11295/// JSONArrayAgg
11296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11297#[cfg_attr(feature = "bindings", derive(TS))]
11298pub struct JSONArrayAgg {
11299    pub this: Box<Expression>,
11300    #[serde(default)]
11301    pub order: Option<Box<Expression>>,
11302    #[serde(default)]
11303    pub null_handling: Option<Box<Expression>>,
11304    #[serde(default)]
11305    pub return_type: Option<Box<Expression>>,
11306    #[serde(default)]
11307    pub strict: Option<Box<Expression>>,
11308}
11309
11310/// JSONExists
11311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11312#[cfg_attr(feature = "bindings", derive(TS))]
11313pub struct JSONExists {
11314    pub this: Box<Expression>,
11315    #[serde(default)]
11316    pub path: Option<Box<Expression>>,
11317    #[serde(default)]
11318    pub passing: Option<Box<Expression>>,
11319    #[serde(default)]
11320    pub on_condition: Option<Box<Expression>>,
11321    #[serde(default)]
11322    pub from_dcolonqmark: Option<Box<Expression>>,
11323}
11324
11325/// JSONColumnDef
11326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11327#[cfg_attr(feature = "bindings", derive(TS))]
11328pub struct JSONColumnDef {
11329    #[serde(default)]
11330    pub this: Option<Box<Expression>>,
11331    #[serde(default)]
11332    pub kind: Option<String>,
11333    #[serde(default)]
11334    pub path: Option<Box<Expression>>,
11335    #[serde(default)]
11336    pub nested_schema: Option<Box<Expression>>,
11337    #[serde(default)]
11338    pub ordinality: Option<Box<Expression>>,
11339}
11340
11341/// JSONSchema
11342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11343#[cfg_attr(feature = "bindings", derive(TS))]
11344pub struct JSONSchema {
11345    #[serde(default)]
11346    pub expressions: Vec<Expression>,
11347}
11348
11349/// JSONSet
11350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11351#[cfg_attr(feature = "bindings", derive(TS))]
11352pub struct JSONSet {
11353    pub this: Box<Expression>,
11354    #[serde(default)]
11355    pub expressions: Vec<Expression>,
11356}
11357
11358/// JSONStripNulls
11359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11360#[cfg_attr(feature = "bindings", derive(TS))]
11361pub struct JSONStripNulls {
11362    pub this: Box<Expression>,
11363    #[serde(default)]
11364    pub expression: Option<Box<Expression>>,
11365    #[serde(default)]
11366    pub include_arrays: Option<Box<Expression>>,
11367    #[serde(default)]
11368    pub remove_empty: Option<Box<Expression>>,
11369}
11370
11371/// JSONValue
11372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11373#[cfg_attr(feature = "bindings", derive(TS))]
11374pub struct JSONValue {
11375    pub this: Box<Expression>,
11376    #[serde(default)]
11377    pub path: Option<Box<Expression>>,
11378    #[serde(default)]
11379    pub returning: Option<Box<Expression>>,
11380    #[serde(default)]
11381    pub on_condition: Option<Box<Expression>>,
11382}
11383
11384/// JSONValueArray
11385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11386#[cfg_attr(feature = "bindings", derive(TS))]
11387pub struct JSONValueArray {
11388    pub this: Box<Expression>,
11389    #[serde(default)]
11390    pub expression: Option<Box<Expression>>,
11391}
11392
11393/// JSONRemove
11394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11395#[cfg_attr(feature = "bindings", derive(TS))]
11396pub struct JSONRemove {
11397    pub this: Box<Expression>,
11398    #[serde(default)]
11399    pub expressions: Vec<Expression>,
11400}
11401
11402/// JSONTable
11403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11404#[cfg_attr(feature = "bindings", derive(TS))]
11405pub struct JSONTable {
11406    pub this: Box<Expression>,
11407    #[serde(default)]
11408    pub schema: Option<Box<Expression>>,
11409    #[serde(default)]
11410    pub path: Option<Box<Expression>>,
11411    #[serde(default)]
11412    pub error_handling: Option<Box<Expression>>,
11413    #[serde(default)]
11414    pub empty_handling: Option<Box<Expression>>,
11415}
11416
11417/// JSONType
11418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11419#[cfg_attr(feature = "bindings", derive(TS))]
11420pub struct JSONType {
11421    pub this: Box<Expression>,
11422    #[serde(default)]
11423    pub expression: Option<Box<Expression>>,
11424}
11425
11426/// ObjectInsert
11427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11428#[cfg_attr(feature = "bindings", derive(TS))]
11429pub struct ObjectInsert {
11430    pub this: Box<Expression>,
11431    #[serde(default)]
11432    pub key: Option<Box<Expression>>,
11433    #[serde(default)]
11434    pub value: Option<Box<Expression>>,
11435    #[serde(default)]
11436    pub update_flag: Option<Box<Expression>>,
11437}
11438
11439/// OpenJSONColumnDef
11440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11441#[cfg_attr(feature = "bindings", derive(TS))]
11442pub struct OpenJSONColumnDef {
11443    pub this: Box<Expression>,
11444    pub kind: String,
11445    #[serde(default)]
11446    pub path: Option<Box<Expression>>,
11447    #[serde(default)]
11448    pub as_json: Option<Box<Expression>>,
11449    /// The parsed data type for proper generation
11450    #[serde(default, skip_serializing_if = "Option::is_none")]
11451    pub data_type: Option<DataType>,
11452}
11453
11454/// OpenJSON
11455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11456#[cfg_attr(feature = "bindings", derive(TS))]
11457pub struct OpenJSON {
11458    pub this: Box<Expression>,
11459    #[serde(default)]
11460    pub path: Option<Box<Expression>>,
11461    #[serde(default)]
11462    pub expressions: Vec<Expression>,
11463}
11464
11465/// JSONBExists
11466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11467#[cfg_attr(feature = "bindings", derive(TS))]
11468pub struct JSONBExists {
11469    pub this: Box<Expression>,
11470    #[serde(default)]
11471    pub path: Option<Box<Expression>>,
11472}
11473
11474/// JSONCast
11475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11476#[cfg_attr(feature = "bindings", derive(TS))]
11477pub struct JSONCast {
11478    pub this: Box<Expression>,
11479    pub to: DataType,
11480}
11481
11482/// JSONExtract
11483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11484#[cfg_attr(feature = "bindings", derive(TS))]
11485pub struct JSONExtract {
11486    pub this: Box<Expression>,
11487    pub expression: Box<Expression>,
11488    #[serde(default)]
11489    pub only_json_types: Option<Box<Expression>>,
11490    #[serde(default)]
11491    pub expressions: Vec<Expression>,
11492    #[serde(default)]
11493    pub variant_extract: Option<Box<Expression>>,
11494    #[serde(default)]
11495    pub json_query: Option<Box<Expression>>,
11496    #[serde(default)]
11497    pub option: Option<Box<Expression>>,
11498    #[serde(default)]
11499    pub quote: Option<Box<Expression>>,
11500    #[serde(default)]
11501    pub on_condition: Option<Box<Expression>>,
11502    #[serde(default)]
11503    pub requires_json: Option<Box<Expression>>,
11504}
11505
11506/// JSONExtractQuote
11507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11508#[cfg_attr(feature = "bindings", derive(TS))]
11509pub struct JSONExtractQuote {
11510    #[serde(default)]
11511    pub option: Option<Box<Expression>>,
11512    #[serde(default)]
11513    pub scalar: Option<Box<Expression>>,
11514}
11515
11516/// JSONExtractArray
11517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11518#[cfg_attr(feature = "bindings", derive(TS))]
11519pub struct JSONExtractArray {
11520    pub this: Box<Expression>,
11521    #[serde(default)]
11522    pub expression: Option<Box<Expression>>,
11523}
11524
11525/// JSONExtractScalar
11526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11527#[cfg_attr(feature = "bindings", derive(TS))]
11528pub struct JSONExtractScalar {
11529    pub this: Box<Expression>,
11530    pub expression: Box<Expression>,
11531    #[serde(default)]
11532    pub only_json_types: Option<Box<Expression>>,
11533    #[serde(default)]
11534    pub expressions: Vec<Expression>,
11535    #[serde(default)]
11536    pub json_type: Option<Box<Expression>>,
11537    #[serde(default)]
11538    pub scalar_only: Option<Box<Expression>>,
11539}
11540
11541/// JSONBExtractScalar
11542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11543#[cfg_attr(feature = "bindings", derive(TS))]
11544pub struct JSONBExtractScalar {
11545    pub this: Box<Expression>,
11546    pub expression: Box<Expression>,
11547    #[serde(default)]
11548    pub json_type: Option<Box<Expression>>,
11549}
11550
11551/// JSONFormat
11552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11553#[cfg_attr(feature = "bindings", derive(TS))]
11554pub struct JSONFormat {
11555    #[serde(default)]
11556    pub this: Option<Box<Expression>>,
11557    #[serde(default)]
11558    pub options: Vec<Expression>,
11559    #[serde(default)]
11560    pub is_json: Option<Box<Expression>>,
11561    #[serde(default)]
11562    pub to_json: Option<Box<Expression>>,
11563}
11564
11565/// JSONArrayAppend
11566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11567#[cfg_attr(feature = "bindings", derive(TS))]
11568pub struct JSONArrayAppend {
11569    pub this: Box<Expression>,
11570    #[serde(default)]
11571    pub expressions: Vec<Expression>,
11572}
11573
11574/// JSONArrayContains
11575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11576#[cfg_attr(feature = "bindings", derive(TS))]
11577pub struct JSONArrayContains {
11578    pub this: Box<Expression>,
11579    pub expression: Box<Expression>,
11580    #[serde(default)]
11581    pub json_type: Option<Box<Expression>>,
11582}
11583
11584/// JSONArrayInsert
11585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11586#[cfg_attr(feature = "bindings", derive(TS))]
11587pub struct JSONArrayInsert {
11588    pub this: Box<Expression>,
11589    #[serde(default)]
11590    pub expressions: Vec<Expression>,
11591}
11592
11593/// ParseJSON
11594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11595#[cfg_attr(feature = "bindings", derive(TS))]
11596pub struct ParseJSON {
11597    pub this: Box<Expression>,
11598    #[serde(default)]
11599    pub expression: Option<Box<Expression>>,
11600    #[serde(default)]
11601    pub safe: Option<Box<Expression>>,
11602}
11603
11604/// ParseUrl
11605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11606#[cfg_attr(feature = "bindings", derive(TS))]
11607pub struct ParseUrl {
11608    pub this: Box<Expression>,
11609    #[serde(default)]
11610    pub part_to_extract: Option<Box<Expression>>,
11611    #[serde(default)]
11612    pub key: Option<Box<Expression>>,
11613    #[serde(default)]
11614    pub permissive: Option<Box<Expression>>,
11615}
11616
11617/// ParseIp
11618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11619#[cfg_attr(feature = "bindings", derive(TS))]
11620pub struct ParseIp {
11621    pub this: Box<Expression>,
11622    #[serde(default)]
11623    pub type_: Option<Box<Expression>>,
11624    #[serde(default)]
11625    pub permissive: Option<Box<Expression>>,
11626}
11627
11628/// ParseTime
11629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11630#[cfg_attr(feature = "bindings", derive(TS))]
11631pub struct ParseTime {
11632    pub this: Box<Expression>,
11633    pub format: String,
11634}
11635
11636/// ParseDatetime
11637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11638#[cfg_attr(feature = "bindings", derive(TS))]
11639pub struct ParseDatetime {
11640    pub this: Box<Expression>,
11641    #[serde(default)]
11642    pub format: Option<String>,
11643    #[serde(default)]
11644    pub zone: Option<Box<Expression>>,
11645}
11646
11647/// Map
11648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11649#[cfg_attr(feature = "bindings", derive(TS))]
11650pub struct Map {
11651    #[serde(default)]
11652    pub keys: Vec<Expression>,
11653    #[serde(default)]
11654    pub values: Vec<Expression>,
11655}
11656
11657/// MapCat
11658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11659#[cfg_attr(feature = "bindings", derive(TS))]
11660pub struct MapCat {
11661    pub this: Box<Expression>,
11662    pub expression: Box<Expression>,
11663}
11664
11665/// MapDelete
11666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11667#[cfg_attr(feature = "bindings", derive(TS))]
11668pub struct MapDelete {
11669    pub this: Box<Expression>,
11670    #[serde(default)]
11671    pub expressions: Vec<Expression>,
11672}
11673
11674/// MapInsert
11675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11676#[cfg_attr(feature = "bindings", derive(TS))]
11677pub struct MapInsert {
11678    pub this: Box<Expression>,
11679    #[serde(default)]
11680    pub key: Option<Box<Expression>>,
11681    #[serde(default)]
11682    pub value: Option<Box<Expression>>,
11683    #[serde(default)]
11684    pub update_flag: Option<Box<Expression>>,
11685}
11686
11687/// MapPick
11688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11689#[cfg_attr(feature = "bindings", derive(TS))]
11690pub struct MapPick {
11691    pub this: Box<Expression>,
11692    #[serde(default)]
11693    pub expressions: Vec<Expression>,
11694}
11695
11696/// ScopeResolution
11697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11698#[cfg_attr(feature = "bindings", derive(TS))]
11699pub struct ScopeResolution {
11700    #[serde(default)]
11701    pub this: Option<Box<Expression>>,
11702    pub expression: Box<Expression>,
11703}
11704
11705/// Slice
11706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11707#[cfg_attr(feature = "bindings", derive(TS))]
11708pub struct Slice {
11709    #[serde(default)]
11710    pub this: Option<Box<Expression>>,
11711    #[serde(default)]
11712    pub expression: Option<Box<Expression>>,
11713    #[serde(default)]
11714    pub step: Option<Box<Expression>>,
11715}
11716
11717/// VarMap
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct VarMap {
11721    #[serde(default)]
11722    pub keys: Vec<Expression>,
11723    #[serde(default)]
11724    pub values: Vec<Expression>,
11725}
11726
11727/// MatchAgainst
11728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11729#[cfg_attr(feature = "bindings", derive(TS))]
11730pub struct MatchAgainst {
11731    pub this: Box<Expression>,
11732    #[serde(default)]
11733    pub expressions: Vec<Expression>,
11734    #[serde(default)]
11735    pub modifier: Option<Box<Expression>>,
11736}
11737
11738/// MD5Digest
11739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11740#[cfg_attr(feature = "bindings", derive(TS))]
11741pub struct MD5Digest {
11742    pub this: Box<Expression>,
11743    #[serde(default)]
11744    pub expressions: Vec<Expression>,
11745}
11746
11747/// Monthname
11748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11749#[cfg_attr(feature = "bindings", derive(TS))]
11750pub struct Monthname {
11751    pub this: Box<Expression>,
11752    #[serde(default)]
11753    pub abbreviated: Option<Box<Expression>>,
11754}
11755
11756/// Ntile
11757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11758#[cfg_attr(feature = "bindings", derive(TS))]
11759pub struct Ntile {
11760    #[serde(default)]
11761    pub this: Option<Box<Expression>>,
11762}
11763
11764/// Normalize
11765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11766#[cfg_attr(feature = "bindings", derive(TS))]
11767pub struct Normalize {
11768    pub this: Box<Expression>,
11769    #[serde(default)]
11770    pub form: Option<Box<Expression>>,
11771    #[serde(default)]
11772    pub is_casefold: Option<Box<Expression>>,
11773}
11774
11775/// Normal
11776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11777#[cfg_attr(feature = "bindings", derive(TS))]
11778pub struct Normal {
11779    pub this: Box<Expression>,
11780    #[serde(default)]
11781    pub stddev: Option<Box<Expression>>,
11782    #[serde(default)]
11783    pub gen: Option<Box<Expression>>,
11784}
11785
11786/// Predict
11787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11788#[cfg_attr(feature = "bindings", derive(TS))]
11789pub struct Predict {
11790    pub this: Box<Expression>,
11791    pub expression: Box<Expression>,
11792    #[serde(default)]
11793    pub params_struct: Option<Box<Expression>>,
11794}
11795
11796/// MLTranslate
11797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11798#[cfg_attr(feature = "bindings", derive(TS))]
11799pub struct MLTranslate {
11800    pub this: Box<Expression>,
11801    pub expression: Box<Expression>,
11802    #[serde(default)]
11803    pub params_struct: Option<Box<Expression>>,
11804}
11805
11806/// FeaturesAtTime
11807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11808#[cfg_attr(feature = "bindings", derive(TS))]
11809pub struct FeaturesAtTime {
11810    pub this: Box<Expression>,
11811    #[serde(default)]
11812    pub time: Option<Box<Expression>>,
11813    #[serde(default)]
11814    pub num_rows: Option<Box<Expression>>,
11815    #[serde(default)]
11816    pub ignore_feature_nulls: Option<Box<Expression>>,
11817}
11818
11819/// GenerateEmbedding
11820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11821#[cfg_attr(feature = "bindings", derive(TS))]
11822pub struct GenerateEmbedding {
11823    pub this: Box<Expression>,
11824    pub expression: Box<Expression>,
11825    #[serde(default)]
11826    pub params_struct: Option<Box<Expression>>,
11827    #[serde(default)]
11828    pub is_text: Option<Box<Expression>>,
11829}
11830
11831/// MLForecast
11832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11833#[cfg_attr(feature = "bindings", derive(TS))]
11834pub struct MLForecast {
11835    pub this: Box<Expression>,
11836    #[serde(default)]
11837    pub expression: Option<Box<Expression>>,
11838    #[serde(default)]
11839    pub params_struct: Option<Box<Expression>>,
11840}
11841
11842/// ModelAttribute
11843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11844#[cfg_attr(feature = "bindings", derive(TS))]
11845pub struct ModelAttribute {
11846    pub this: Box<Expression>,
11847    pub expression: Box<Expression>,
11848}
11849
11850/// VectorSearch
11851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11852#[cfg_attr(feature = "bindings", derive(TS))]
11853pub struct VectorSearch {
11854    pub this: Box<Expression>,
11855    #[serde(default)]
11856    pub column_to_search: Option<Box<Expression>>,
11857    #[serde(default)]
11858    pub query_table: Option<Box<Expression>>,
11859    #[serde(default)]
11860    pub query_column_to_search: Option<Box<Expression>>,
11861    #[serde(default)]
11862    pub top_k: Option<Box<Expression>>,
11863    #[serde(default)]
11864    pub distance_type: Option<Box<Expression>>,
11865    #[serde(default)]
11866    pub options: Vec<Expression>,
11867}
11868
11869/// Quantile
11870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11871#[cfg_attr(feature = "bindings", derive(TS))]
11872pub struct Quantile {
11873    pub this: Box<Expression>,
11874    #[serde(default)]
11875    pub quantile: Option<Box<Expression>>,
11876}
11877
11878/// ApproxQuantile
11879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11880#[cfg_attr(feature = "bindings", derive(TS))]
11881pub struct ApproxQuantile {
11882    pub this: Box<Expression>,
11883    #[serde(default)]
11884    pub quantile: Option<Box<Expression>>,
11885    #[serde(default)]
11886    pub accuracy: Option<Box<Expression>>,
11887    #[serde(default)]
11888    pub weight: Option<Box<Expression>>,
11889    #[serde(default)]
11890    pub error_tolerance: Option<Box<Expression>>,
11891}
11892
11893/// ApproxPercentileEstimate
11894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11895#[cfg_attr(feature = "bindings", derive(TS))]
11896pub struct ApproxPercentileEstimate {
11897    pub this: Box<Expression>,
11898    #[serde(default)]
11899    pub percentile: Option<Box<Expression>>,
11900}
11901
11902/// Randn
11903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11904#[cfg_attr(feature = "bindings", derive(TS))]
11905pub struct Randn {
11906    #[serde(default)]
11907    pub this: Option<Box<Expression>>,
11908}
11909
11910/// Randstr
11911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11912#[cfg_attr(feature = "bindings", derive(TS))]
11913pub struct Randstr {
11914    pub this: Box<Expression>,
11915    #[serde(default)]
11916    pub generator: Option<Box<Expression>>,
11917}
11918
11919/// RangeN
11920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11921#[cfg_attr(feature = "bindings", derive(TS))]
11922pub struct RangeN {
11923    pub this: Box<Expression>,
11924    #[serde(default)]
11925    pub expressions: Vec<Expression>,
11926    #[serde(default)]
11927    pub each: Option<Box<Expression>>,
11928}
11929
11930/// RangeBucket
11931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11932#[cfg_attr(feature = "bindings", derive(TS))]
11933pub struct RangeBucket {
11934    pub this: Box<Expression>,
11935    pub expression: Box<Expression>,
11936}
11937
11938/// ReadCSV
11939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11940#[cfg_attr(feature = "bindings", derive(TS))]
11941pub struct ReadCSV {
11942    pub this: Box<Expression>,
11943    #[serde(default)]
11944    pub expressions: Vec<Expression>,
11945}
11946
11947/// ReadParquet
11948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11949#[cfg_attr(feature = "bindings", derive(TS))]
11950pub struct ReadParquet {
11951    #[serde(default)]
11952    pub expressions: Vec<Expression>,
11953}
11954
11955/// Reduce
11956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11957#[cfg_attr(feature = "bindings", derive(TS))]
11958pub struct Reduce {
11959    pub this: Box<Expression>,
11960    #[serde(default)]
11961    pub initial: Option<Box<Expression>>,
11962    #[serde(default)]
11963    pub merge: Option<Box<Expression>>,
11964    #[serde(default)]
11965    pub finish: Option<Box<Expression>>,
11966}
11967
11968/// RegexpExtractAll
11969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11970#[cfg_attr(feature = "bindings", derive(TS))]
11971pub struct RegexpExtractAll {
11972    pub this: Box<Expression>,
11973    pub expression: Box<Expression>,
11974    #[serde(default)]
11975    pub group: Option<Box<Expression>>,
11976    #[serde(default)]
11977    pub parameters: Option<Box<Expression>>,
11978    #[serde(default)]
11979    pub position: Option<Box<Expression>>,
11980    #[serde(default)]
11981    pub occurrence: Option<Box<Expression>>,
11982}
11983
11984/// RegexpILike
11985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11986#[cfg_attr(feature = "bindings", derive(TS))]
11987pub struct RegexpILike {
11988    pub this: Box<Expression>,
11989    pub expression: Box<Expression>,
11990    #[serde(default)]
11991    pub flag: Option<Box<Expression>>,
11992}
11993
11994/// RegexpFullMatch
11995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11996#[cfg_attr(feature = "bindings", derive(TS))]
11997pub struct RegexpFullMatch {
11998    pub this: Box<Expression>,
11999    pub expression: Box<Expression>,
12000    #[serde(default)]
12001    pub options: Vec<Expression>,
12002}
12003
12004/// RegexpInstr
12005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12006#[cfg_attr(feature = "bindings", derive(TS))]
12007pub struct RegexpInstr {
12008    pub this: Box<Expression>,
12009    pub expression: Box<Expression>,
12010    #[serde(default)]
12011    pub position: Option<Box<Expression>>,
12012    #[serde(default)]
12013    pub occurrence: Option<Box<Expression>>,
12014    #[serde(default)]
12015    pub option: Option<Box<Expression>>,
12016    #[serde(default)]
12017    pub parameters: Option<Box<Expression>>,
12018    #[serde(default)]
12019    pub group: Option<Box<Expression>>,
12020}
12021
12022/// RegexpSplit
12023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12024#[cfg_attr(feature = "bindings", derive(TS))]
12025pub struct RegexpSplit {
12026    pub this: Box<Expression>,
12027    pub expression: Box<Expression>,
12028    #[serde(default)]
12029    pub limit: Option<Box<Expression>>,
12030}
12031
12032/// RegexpCount
12033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12034#[cfg_attr(feature = "bindings", derive(TS))]
12035pub struct RegexpCount {
12036    pub this: Box<Expression>,
12037    pub expression: Box<Expression>,
12038    #[serde(default)]
12039    pub position: Option<Box<Expression>>,
12040    #[serde(default)]
12041    pub parameters: Option<Box<Expression>>,
12042}
12043
12044/// RegrValx
12045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12046#[cfg_attr(feature = "bindings", derive(TS))]
12047pub struct RegrValx {
12048    pub this: Box<Expression>,
12049    pub expression: Box<Expression>,
12050}
12051
12052/// RegrValy
12053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12054#[cfg_attr(feature = "bindings", derive(TS))]
12055pub struct RegrValy {
12056    pub this: Box<Expression>,
12057    pub expression: Box<Expression>,
12058}
12059
12060/// RegrAvgy
12061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12062#[cfg_attr(feature = "bindings", derive(TS))]
12063pub struct RegrAvgy {
12064    pub this: Box<Expression>,
12065    pub expression: Box<Expression>,
12066}
12067
12068/// RegrAvgx
12069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12070#[cfg_attr(feature = "bindings", derive(TS))]
12071pub struct RegrAvgx {
12072    pub this: Box<Expression>,
12073    pub expression: Box<Expression>,
12074}
12075
12076/// RegrCount
12077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12078#[cfg_attr(feature = "bindings", derive(TS))]
12079pub struct RegrCount {
12080    pub this: Box<Expression>,
12081    pub expression: Box<Expression>,
12082}
12083
12084/// RegrIntercept
12085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12086#[cfg_attr(feature = "bindings", derive(TS))]
12087pub struct RegrIntercept {
12088    pub this: Box<Expression>,
12089    pub expression: Box<Expression>,
12090}
12091
12092/// RegrR2
12093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12094#[cfg_attr(feature = "bindings", derive(TS))]
12095pub struct RegrR2 {
12096    pub this: Box<Expression>,
12097    pub expression: Box<Expression>,
12098}
12099
12100/// RegrSxx
12101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12102#[cfg_attr(feature = "bindings", derive(TS))]
12103pub struct RegrSxx {
12104    pub this: Box<Expression>,
12105    pub expression: Box<Expression>,
12106}
12107
12108/// RegrSxy
12109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12110#[cfg_attr(feature = "bindings", derive(TS))]
12111pub struct RegrSxy {
12112    pub this: Box<Expression>,
12113    pub expression: Box<Expression>,
12114}
12115
12116/// RegrSyy
12117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12118#[cfg_attr(feature = "bindings", derive(TS))]
12119pub struct RegrSyy {
12120    pub this: Box<Expression>,
12121    pub expression: Box<Expression>,
12122}
12123
12124/// RegrSlope
12125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12126#[cfg_attr(feature = "bindings", derive(TS))]
12127pub struct RegrSlope {
12128    pub this: Box<Expression>,
12129    pub expression: Box<Expression>,
12130}
12131
12132/// SafeAdd
12133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12134#[cfg_attr(feature = "bindings", derive(TS))]
12135pub struct SafeAdd {
12136    pub this: Box<Expression>,
12137    pub expression: Box<Expression>,
12138}
12139
12140/// SafeDivide
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct SafeDivide {
12144    pub this: Box<Expression>,
12145    pub expression: Box<Expression>,
12146}
12147
12148/// SafeMultiply
12149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12150#[cfg_attr(feature = "bindings", derive(TS))]
12151pub struct SafeMultiply {
12152    pub this: Box<Expression>,
12153    pub expression: Box<Expression>,
12154}
12155
12156/// SafeSubtract
12157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12158#[cfg_attr(feature = "bindings", derive(TS))]
12159pub struct SafeSubtract {
12160    pub this: Box<Expression>,
12161    pub expression: Box<Expression>,
12162}
12163
12164/// SHA2
12165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12166#[cfg_attr(feature = "bindings", derive(TS))]
12167pub struct SHA2 {
12168    pub this: Box<Expression>,
12169    #[serde(default)]
12170    pub length: Option<i64>,
12171}
12172
12173/// SHA2Digest
12174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12175#[cfg_attr(feature = "bindings", derive(TS))]
12176pub struct SHA2Digest {
12177    pub this: Box<Expression>,
12178    #[serde(default)]
12179    pub length: Option<i64>,
12180}
12181
12182/// SortArray
12183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12184#[cfg_attr(feature = "bindings", derive(TS))]
12185pub struct SortArray {
12186    pub this: Box<Expression>,
12187    #[serde(default)]
12188    pub asc: Option<Box<Expression>>,
12189    #[serde(default)]
12190    pub nulls_first: Option<Box<Expression>>,
12191}
12192
12193/// SplitPart
12194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12195#[cfg_attr(feature = "bindings", derive(TS))]
12196pub struct SplitPart {
12197    pub this: Box<Expression>,
12198    #[serde(default)]
12199    pub delimiter: Option<Box<Expression>>,
12200    #[serde(default)]
12201    pub part_index: Option<Box<Expression>>,
12202}
12203
12204/// SUBSTRING_INDEX(str, delim, count)
12205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12206#[cfg_attr(feature = "bindings", derive(TS))]
12207pub struct SubstringIndex {
12208    pub this: Box<Expression>,
12209    #[serde(default)]
12210    pub delimiter: Option<Box<Expression>>,
12211    #[serde(default)]
12212    pub count: Option<Box<Expression>>,
12213}
12214
12215/// StandardHash
12216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12217#[cfg_attr(feature = "bindings", derive(TS))]
12218pub struct StandardHash {
12219    pub this: Box<Expression>,
12220    #[serde(default)]
12221    pub expression: Option<Box<Expression>>,
12222}
12223
12224/// StrPosition
12225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12226#[cfg_attr(feature = "bindings", derive(TS))]
12227pub struct StrPosition {
12228    pub this: Box<Expression>,
12229    #[serde(default)]
12230    pub substr: Option<Box<Expression>>,
12231    #[serde(default)]
12232    pub position: Option<Box<Expression>>,
12233    #[serde(default)]
12234    pub occurrence: Option<Box<Expression>>,
12235}
12236
12237/// Search
12238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12239#[cfg_attr(feature = "bindings", derive(TS))]
12240pub struct Search {
12241    pub this: Box<Expression>,
12242    pub expression: Box<Expression>,
12243    #[serde(default)]
12244    pub json_scope: Option<Box<Expression>>,
12245    #[serde(default)]
12246    pub analyzer: Option<Box<Expression>>,
12247    #[serde(default)]
12248    pub analyzer_options: Option<Box<Expression>>,
12249    #[serde(default)]
12250    pub search_mode: Option<Box<Expression>>,
12251}
12252
12253/// SearchIp
12254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12255#[cfg_attr(feature = "bindings", derive(TS))]
12256pub struct SearchIp {
12257    pub this: Box<Expression>,
12258    pub expression: Box<Expression>,
12259}
12260
12261/// StrToDate
12262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12263#[cfg_attr(feature = "bindings", derive(TS))]
12264pub struct StrToDate {
12265    pub this: Box<Expression>,
12266    #[serde(default)]
12267    pub format: Option<String>,
12268    #[serde(default)]
12269    pub safe: Option<Box<Expression>>,
12270}
12271
12272/// StrToTime
12273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12274#[cfg_attr(feature = "bindings", derive(TS))]
12275pub struct StrToTime {
12276    pub this: Box<Expression>,
12277    pub format: String,
12278    #[serde(default)]
12279    pub zone: Option<Box<Expression>>,
12280    #[serde(default)]
12281    pub safe: Option<Box<Expression>>,
12282    #[serde(default)]
12283    pub target_type: Option<Box<Expression>>,
12284}
12285
12286/// StrToUnix
12287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12288#[cfg_attr(feature = "bindings", derive(TS))]
12289pub struct StrToUnix {
12290    #[serde(default)]
12291    pub this: Option<Box<Expression>>,
12292    #[serde(default)]
12293    pub format: Option<String>,
12294}
12295
12296/// StrToMap
12297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12298#[cfg_attr(feature = "bindings", derive(TS))]
12299pub struct StrToMap {
12300    pub this: Box<Expression>,
12301    #[serde(default)]
12302    pub pair_delim: Option<Box<Expression>>,
12303    #[serde(default)]
12304    pub key_value_delim: Option<Box<Expression>>,
12305    #[serde(default)]
12306    pub duplicate_resolution_callback: Option<Box<Expression>>,
12307}
12308
12309/// NumberToStr
12310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12311#[cfg_attr(feature = "bindings", derive(TS))]
12312pub struct NumberToStr {
12313    pub this: Box<Expression>,
12314    pub format: String,
12315    #[serde(default)]
12316    pub culture: Option<Box<Expression>>,
12317}
12318
12319/// FromBase
12320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12321#[cfg_attr(feature = "bindings", derive(TS))]
12322pub struct FromBase {
12323    pub this: Box<Expression>,
12324    pub expression: Box<Expression>,
12325}
12326
12327/// Stuff
12328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12329#[cfg_attr(feature = "bindings", derive(TS))]
12330pub struct Stuff {
12331    pub this: Box<Expression>,
12332    #[serde(default)]
12333    pub start: Option<Box<Expression>>,
12334    #[serde(default)]
12335    pub length: Option<i64>,
12336    pub expression: Box<Expression>,
12337}
12338
12339/// TimeToStr
12340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12341#[cfg_attr(feature = "bindings", derive(TS))]
12342pub struct TimeToStr {
12343    pub this: Box<Expression>,
12344    pub format: String,
12345    #[serde(default)]
12346    pub culture: Option<Box<Expression>>,
12347    #[serde(default)]
12348    pub zone: Option<Box<Expression>>,
12349}
12350
12351/// TimeStrToTime
12352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12353#[cfg_attr(feature = "bindings", derive(TS))]
12354pub struct TimeStrToTime {
12355    pub this: Box<Expression>,
12356    #[serde(default)]
12357    pub zone: Option<Box<Expression>>,
12358}
12359
12360/// TsOrDsAdd
12361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12362#[cfg_attr(feature = "bindings", derive(TS))]
12363pub struct TsOrDsAdd {
12364    pub this: Box<Expression>,
12365    pub expression: Box<Expression>,
12366    #[serde(default)]
12367    pub unit: Option<String>,
12368    #[serde(default)]
12369    pub return_type: Option<Box<Expression>>,
12370}
12371
12372/// TsOrDsDiff
12373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12374#[cfg_attr(feature = "bindings", derive(TS))]
12375pub struct TsOrDsDiff {
12376    pub this: Box<Expression>,
12377    pub expression: Box<Expression>,
12378    #[serde(default)]
12379    pub unit: Option<String>,
12380}
12381
12382/// TsOrDsToDate
12383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12384#[cfg_attr(feature = "bindings", derive(TS))]
12385pub struct TsOrDsToDate {
12386    pub this: Box<Expression>,
12387    #[serde(default)]
12388    pub format: Option<String>,
12389    #[serde(default)]
12390    pub safe: Option<Box<Expression>>,
12391}
12392
12393/// TsOrDsToTime
12394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12395#[cfg_attr(feature = "bindings", derive(TS))]
12396pub struct TsOrDsToTime {
12397    pub this: Box<Expression>,
12398    #[serde(default)]
12399    pub format: Option<String>,
12400    #[serde(default)]
12401    pub safe: Option<Box<Expression>>,
12402}
12403
12404/// Unhex
12405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12406#[cfg_attr(feature = "bindings", derive(TS))]
12407pub struct Unhex {
12408    pub this: Box<Expression>,
12409    #[serde(default)]
12410    pub expression: Option<Box<Expression>>,
12411}
12412
12413/// Uniform
12414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12415#[cfg_attr(feature = "bindings", derive(TS))]
12416pub struct Uniform {
12417    pub this: Box<Expression>,
12418    pub expression: Box<Expression>,
12419    #[serde(default)]
12420    pub gen: Option<Box<Expression>>,
12421    #[serde(default)]
12422    pub seed: Option<Box<Expression>>,
12423}
12424
12425/// UnixToStr
12426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12427#[cfg_attr(feature = "bindings", derive(TS))]
12428pub struct UnixToStr {
12429    pub this: Box<Expression>,
12430    #[serde(default)]
12431    pub format: Option<String>,
12432}
12433
12434/// UnixToTime
12435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12436#[cfg_attr(feature = "bindings", derive(TS))]
12437pub struct UnixToTime {
12438    pub this: Box<Expression>,
12439    #[serde(default)]
12440    pub scale: Option<i64>,
12441    #[serde(default)]
12442    pub zone: Option<Box<Expression>>,
12443    #[serde(default)]
12444    pub hours: Option<Box<Expression>>,
12445    #[serde(default)]
12446    pub minutes: Option<Box<Expression>>,
12447    #[serde(default)]
12448    pub format: Option<String>,
12449    #[serde(default)]
12450    pub target_type: Option<Box<Expression>>,
12451}
12452
12453/// Uuid
12454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12455#[cfg_attr(feature = "bindings", derive(TS))]
12456pub struct Uuid {
12457    #[serde(default)]
12458    pub this: Option<Box<Expression>>,
12459    #[serde(default)]
12460    pub name: Option<String>,
12461    #[serde(default)]
12462    pub is_string: Option<Box<Expression>>,
12463}
12464
12465/// TimestampFromParts
12466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12467#[cfg_attr(feature = "bindings", derive(TS))]
12468pub struct TimestampFromParts {
12469    #[serde(default)]
12470    pub zone: Option<Box<Expression>>,
12471    #[serde(default)]
12472    pub milli: Option<Box<Expression>>,
12473    #[serde(default)]
12474    pub this: Option<Box<Expression>>,
12475    #[serde(default)]
12476    pub expression: Option<Box<Expression>>,
12477}
12478
12479/// TimestampTzFromParts
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct TimestampTzFromParts {
12483    #[serde(default)]
12484    pub zone: Option<Box<Expression>>,
12485}
12486
12487/// Corr
12488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12489#[cfg_attr(feature = "bindings", derive(TS))]
12490pub struct Corr {
12491    pub this: Box<Expression>,
12492    pub expression: Box<Expression>,
12493    #[serde(default)]
12494    pub null_on_zero_variance: Option<Box<Expression>>,
12495}
12496
12497/// WidthBucket
12498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12499#[cfg_attr(feature = "bindings", derive(TS))]
12500pub struct WidthBucket {
12501    pub this: Box<Expression>,
12502    #[serde(default)]
12503    pub min_value: Option<Box<Expression>>,
12504    #[serde(default)]
12505    pub max_value: Option<Box<Expression>>,
12506    #[serde(default)]
12507    pub num_buckets: Option<Box<Expression>>,
12508    #[serde(default)]
12509    pub threshold: Option<Box<Expression>>,
12510}
12511
12512/// CovarSamp
12513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12514#[cfg_attr(feature = "bindings", derive(TS))]
12515pub struct CovarSamp {
12516    pub this: Box<Expression>,
12517    pub expression: Box<Expression>,
12518}
12519
12520/// CovarPop
12521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12522#[cfg_attr(feature = "bindings", derive(TS))]
12523pub struct CovarPop {
12524    pub this: Box<Expression>,
12525    pub expression: Box<Expression>,
12526}
12527
12528/// Week
12529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12530#[cfg_attr(feature = "bindings", derive(TS))]
12531pub struct Week {
12532    pub this: Box<Expression>,
12533    #[serde(default)]
12534    pub mode: Option<Box<Expression>>,
12535}
12536
12537/// XMLElement
12538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12539#[cfg_attr(feature = "bindings", derive(TS))]
12540pub struct XMLElement {
12541    pub this: Box<Expression>,
12542    #[serde(default)]
12543    pub expressions: Vec<Expression>,
12544    #[serde(default)]
12545    pub evalname: Option<Box<Expression>>,
12546}
12547
12548/// XMLGet
12549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12550#[cfg_attr(feature = "bindings", derive(TS))]
12551pub struct XMLGet {
12552    pub this: Box<Expression>,
12553    pub expression: Box<Expression>,
12554    #[serde(default)]
12555    pub instance: Option<Box<Expression>>,
12556}
12557
12558/// XMLTable
12559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12560#[cfg_attr(feature = "bindings", derive(TS))]
12561pub struct XMLTable {
12562    pub this: Box<Expression>,
12563    #[serde(default)]
12564    pub namespaces: Option<Box<Expression>>,
12565    #[serde(default)]
12566    pub passing: Option<Box<Expression>>,
12567    #[serde(default)]
12568    pub columns: Vec<Expression>,
12569    #[serde(default)]
12570    pub by_ref: Option<Box<Expression>>,
12571}
12572
12573/// XMLKeyValueOption
12574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12575#[cfg_attr(feature = "bindings", derive(TS))]
12576pub struct XMLKeyValueOption {
12577    pub this: Box<Expression>,
12578    #[serde(default)]
12579    pub expression: Option<Box<Expression>>,
12580}
12581
12582/// Zipf
12583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12584#[cfg_attr(feature = "bindings", derive(TS))]
12585pub struct Zipf {
12586    pub this: Box<Expression>,
12587    #[serde(default)]
12588    pub elementcount: Option<Box<Expression>>,
12589    #[serde(default)]
12590    pub gen: Option<Box<Expression>>,
12591}
12592
12593/// Merge
12594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12595#[cfg_attr(feature = "bindings", derive(TS))]
12596pub struct Merge {
12597    pub this: Box<Expression>,
12598    pub using: Box<Expression>,
12599    #[serde(default)]
12600    pub on: Option<Box<Expression>>,
12601    #[serde(default)]
12602    pub using_cond: Option<Box<Expression>>,
12603    #[serde(default)]
12604    pub whens: Option<Box<Expression>>,
12605    #[serde(default)]
12606    pub with_: Option<Box<Expression>>,
12607    #[serde(default)]
12608    pub returning: Option<Box<Expression>>,
12609}
12610
12611/// When
12612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12613#[cfg_attr(feature = "bindings", derive(TS))]
12614pub struct When {
12615    #[serde(default)]
12616    pub matched: Option<Box<Expression>>,
12617    #[serde(default)]
12618    pub source: Option<Box<Expression>>,
12619    #[serde(default)]
12620    pub condition: Option<Box<Expression>>,
12621    pub then: Box<Expression>,
12622}
12623
12624/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12626#[cfg_attr(feature = "bindings", derive(TS))]
12627pub struct Whens {
12628    #[serde(default)]
12629    pub expressions: Vec<Expression>,
12630}
12631
12632/// NextValueFor
12633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12634#[cfg_attr(feature = "bindings", derive(TS))]
12635pub struct NextValueFor {
12636    pub this: Box<Expression>,
12637    #[serde(default)]
12638    pub order: Option<Box<Expression>>,
12639}
12640
12641#[cfg(test)]
12642mod tests {
12643    use super::*;
12644
12645    #[test]
12646    #[cfg(feature = "bindings")]
12647    fn export_typescript_types() {
12648        // This test exports TypeScript types to the generated directory
12649        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12650        Expression::export_all(&ts_rs::Config::default())
12651            .expect("Failed to export Expression types");
12652    }
12653
12654    #[test]
12655    fn test_simple_select_builder() {
12656        let select = Select::new()
12657            .column(Expression::star())
12658            .from(Expression::Table(TableRef::new("users")));
12659
12660        assert_eq!(select.expressions.len(), 1);
12661        assert!(select.from.is_some());
12662    }
12663
12664    #[test]
12665    fn test_expression_alias() {
12666        let expr = Expression::column("id").alias("user_id");
12667
12668        match expr {
12669            Expression::Alias(a) => {
12670                assert_eq!(a.alias.name, "user_id");
12671            }
12672            _ => panic!("Expected Alias"),
12673        }
12674    }
12675
12676    #[test]
12677    fn test_literal_creation() {
12678        let num = Expression::number(42);
12679        let str = Expression::string("hello");
12680
12681        match num {
12682            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12683            _ => panic!("Expected Number"),
12684        }
12685
12686        match str {
12687            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12688            _ => panic!("Expected String"),
12689        }
12690    }
12691
12692    #[test]
12693    fn test_expression_sql() {
12694        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12695        assert_eq!(expr.sql(), "SELECT 1 + 2");
12696    }
12697
12698    #[test]
12699    fn test_expression_sql_for() {
12700        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12701        let sql = expr.sql_for(crate::DialectType::Generic);
12702        // Generic mode normalizes IF() to CASE WHEN
12703        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
12704    }
12705}