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    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
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 <hint> INTO ...` (for example Oracle APPEND hints)
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 between join-kind keywords (for example `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    TextWithLength {
3763        length: u32,
3764    },
3765
3766    // Binary
3767    Binary {
3768        length: Option<u32>,
3769    },
3770    VarBinary {
3771        length: Option<u32>,
3772    },
3773    Blob,
3774
3775    // Bit
3776    Bit {
3777        length: Option<u32>,
3778    },
3779    VarBit {
3780        length: Option<u32>,
3781    },
3782
3783    // Date/Time
3784    Date,
3785    Time {
3786        precision: Option<u32>,
3787        #[serde(default)]
3788        timezone: bool,
3789    },
3790    Timestamp {
3791        precision: Option<u32>,
3792        timezone: bool,
3793    },
3794    Interval {
3795        unit: Option<String>,
3796        /// For range intervals like INTERVAL DAY TO HOUR
3797        #[serde(default, skip_serializing_if = "Option::is_none")]
3798        to: Option<String>,
3799    },
3800
3801    // JSON
3802    Json,
3803    JsonB,
3804
3805    // UUID
3806    Uuid,
3807
3808    // Array
3809    Array {
3810        element_type: Box<DataType>,
3811        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3812        #[serde(default, skip_serializing_if = "Option::is_none")]
3813        dimension: Option<u32>,
3814    },
3815
3816    /// List type (Materialize): INT LIST, TEXT LIST LIST
3817    /// Uses postfix LIST syntax instead of ARRAY<T>
3818    List {
3819        element_type: Box<DataType>,
3820    },
3821
3822    // Struct/Map
3823    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3824    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3825    Struct {
3826        fields: Vec<StructField>,
3827        nested: bool,
3828    },
3829    Map {
3830        key_type: Box<DataType>,
3831        value_type: Box<DataType>,
3832    },
3833
3834    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3835    Enum {
3836        values: Vec<String>,
3837        #[serde(default, skip_serializing_if = "Vec::is_empty")]
3838        assignments: Vec<Option<String>>,
3839    },
3840
3841    // Set type (MySQL): SET('a', 'b', 'c')
3842    Set {
3843        values: Vec<String>,
3844    },
3845
3846    // Union type (DuckDB): UNION(num INT, str TEXT)
3847    Union {
3848        fields: Vec<(String, DataType)>,
3849    },
3850
3851    // Vector (Snowflake / SingleStore)
3852    Vector {
3853        #[serde(default)]
3854        element_type: Option<Box<DataType>>,
3855        dimension: Option<u32>,
3856    },
3857
3858    // Object (Snowflake structured type)
3859    // fields: Vec of (field_name, field_type, not_null)
3860    Object {
3861        fields: Vec<(String, DataType, bool)>,
3862        modifier: Option<String>,
3863    },
3864
3865    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
3866    Nullable {
3867        inner: Box<DataType>,
3868    },
3869
3870    // Custom/User-defined
3871    Custom {
3872        name: String,
3873    },
3874
3875    // Spatial types
3876    Geometry {
3877        subtype: Option<String>,
3878        srid: Option<u32>,
3879    },
3880    Geography {
3881        subtype: Option<String>,
3882        srid: Option<u32>,
3883    },
3884
3885    // Character Set (for CONVERT USING in MySQL)
3886    // Renders as CHAR CHARACTER SET {name} in cast target
3887    CharacterSet {
3888        name: String,
3889    },
3890
3891    // Unknown
3892    Unknown,
3893}
3894
3895/// Array expression
3896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3897#[cfg_attr(feature = "bindings", derive(TS))]
3898#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3899pub struct Array {
3900    pub expressions: Vec<Expression>,
3901}
3902
3903/// Struct expression
3904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3905#[cfg_attr(feature = "bindings", derive(TS))]
3906pub struct Struct {
3907    pub fields: Vec<(Option<String>, Expression)>,
3908}
3909
3910/// Tuple expression
3911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3912#[cfg_attr(feature = "bindings", derive(TS))]
3913pub struct Tuple {
3914    pub expressions: Vec<Expression>,
3915}
3916
3917/// Interval expression
3918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3919#[cfg_attr(feature = "bindings", derive(TS))]
3920pub struct Interval {
3921    /// The value expression (e.g., '1', 5, column_ref)
3922    pub this: Option<Expression>,
3923    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3924    pub unit: Option<IntervalUnitSpec>,
3925}
3926
3927/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3929#[cfg_attr(feature = "bindings", derive(TS))]
3930#[serde(tag = "type", rename_all = "snake_case")]
3931pub enum IntervalUnitSpec {
3932    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3933    Simple {
3934        unit: IntervalUnit,
3935        /// Whether to use plural form (e.g., DAYS vs DAY)
3936        use_plural: bool,
3937    },
3938    /// Interval span (e.g., HOUR TO SECOND)
3939    Span(IntervalSpan),
3940    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3941    /// The start and end can be expressions like function calls with precision
3942    ExprSpan(IntervalSpanExpr),
3943    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3944    Expr(Box<Expression>),
3945}
3946
3947/// Interval span for ranges like HOUR TO SECOND
3948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3949#[cfg_attr(feature = "bindings", derive(TS))]
3950pub struct IntervalSpan {
3951    /// Start unit (e.g., HOUR)
3952    pub this: IntervalUnit,
3953    /// End unit (e.g., SECOND)
3954    pub expression: IntervalUnit,
3955}
3956
3957/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3958/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3960#[cfg_attr(feature = "bindings", derive(TS))]
3961pub struct IntervalSpanExpr {
3962    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3963    pub this: Box<Expression>,
3964    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
3965    pub expression: Box<Expression>,
3966}
3967
3968#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3969#[cfg_attr(feature = "bindings", derive(TS))]
3970pub enum IntervalUnit {
3971    Year,
3972    Quarter,
3973    Month,
3974    Week,
3975    Day,
3976    Hour,
3977    Minute,
3978    Second,
3979    Millisecond,
3980    Microsecond,
3981    Nanosecond,
3982}
3983
3984/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
3985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3986#[cfg_attr(feature = "bindings", derive(TS))]
3987pub struct Command {
3988    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
3989    pub this: String,
3990}
3991
3992/// EXEC/EXECUTE statement (TSQL stored procedure call)
3993/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
3994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3995#[cfg_attr(feature = "bindings", derive(TS))]
3996pub struct ExecuteStatement {
3997    /// The procedure name (can be qualified: schema.proc_name)
3998    pub this: Expression,
3999    /// Named parameters: @param=value pairs
4000    #[serde(default)]
4001    pub parameters: Vec<ExecuteParameter>,
4002}
4003
4004/// Named parameter in EXEC statement: @name=value
4005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4006#[cfg_attr(feature = "bindings", derive(TS))]
4007pub struct ExecuteParameter {
4008    /// Parameter name (including @)
4009    pub name: String,
4010    /// Parameter value
4011    pub value: Expression,
4012}
4013
4014/// KILL statement (MySQL/MariaDB)
4015/// KILL [CONNECTION | QUERY] <id>
4016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4017#[cfg_attr(feature = "bindings", derive(TS))]
4018pub struct Kill {
4019    /// The target (process ID or connection ID)
4020    pub this: Expression,
4021    /// Optional kind: "CONNECTION" or "QUERY"
4022    pub kind: Option<String>,
4023}
4024
4025/// Raw/unparsed SQL
4026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4027#[cfg_attr(feature = "bindings", derive(TS))]
4028pub struct Raw {
4029    pub sql: String,
4030}
4031
4032// ============================================================================
4033// Function expression types
4034// ============================================================================
4035
4036/// Generic unary function (takes a single argument)
4037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4038#[cfg_attr(feature = "bindings", derive(TS))]
4039pub struct UnaryFunc {
4040    pub this: Expression,
4041    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4042    #[serde(skip_serializing_if = "Option::is_none", default)]
4043    pub original_name: Option<String>,
4044}
4045
4046impl UnaryFunc {
4047    /// Create a new UnaryFunc with no original_name
4048    pub fn new(this: Expression) -> Self {
4049        Self {
4050            this,
4051            original_name: None,
4052        }
4053    }
4054
4055    /// Create a new UnaryFunc with an original name for round-trip preservation
4056    pub fn with_name(this: Expression, name: String) -> Self {
4057        Self {
4058            this,
4059            original_name: Some(name),
4060        }
4061    }
4062}
4063
4064/// CHAR/CHR function with multiple args and optional USING charset
4065/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4066/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4068#[cfg_attr(feature = "bindings", derive(TS))]
4069pub struct CharFunc {
4070    pub args: Vec<Expression>,
4071    #[serde(skip_serializing_if = "Option::is_none", default)]
4072    pub charset: Option<String>,
4073    /// Original function name (CHAR or CHR), defaults to CHAR
4074    #[serde(skip_serializing_if = "Option::is_none", default)]
4075    pub name: Option<String>,
4076}
4077
4078/// Generic binary function (takes two arguments)
4079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4080#[cfg_attr(feature = "bindings", derive(TS))]
4081pub struct BinaryFunc {
4082    pub this: Expression,
4083    pub expression: Expression,
4084    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4085    #[serde(skip_serializing_if = "Option::is_none", default)]
4086    pub original_name: Option<String>,
4087}
4088
4089/// Variable argument function
4090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4091#[cfg_attr(feature = "bindings", derive(TS))]
4092pub struct VarArgFunc {
4093    pub expressions: Vec<Expression>,
4094    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4095    #[serde(skip_serializing_if = "Option::is_none", default)]
4096    pub original_name: Option<String>,
4097}
4098
4099/// CONCAT_WS function
4100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4101#[cfg_attr(feature = "bindings", derive(TS))]
4102pub struct ConcatWs {
4103    pub separator: Expression,
4104    pub expressions: Vec<Expression>,
4105}
4106
4107/// SUBSTRING function
4108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4109#[cfg_attr(feature = "bindings", derive(TS))]
4110pub struct SubstringFunc {
4111    pub this: Expression,
4112    pub start: Expression,
4113    pub length: Option<Expression>,
4114    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4115    #[serde(default)]
4116    pub from_for_syntax: bool,
4117}
4118
4119/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4121#[cfg_attr(feature = "bindings", derive(TS))]
4122pub struct OverlayFunc {
4123    pub this: Expression,
4124    pub replacement: Expression,
4125    pub from: Expression,
4126    pub length: Option<Expression>,
4127}
4128
4129/// TRIM function
4130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4131#[cfg_attr(feature = "bindings", derive(TS))]
4132pub struct TrimFunc {
4133    pub this: Expression,
4134    pub characters: Option<Expression>,
4135    pub position: TrimPosition,
4136    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4137    #[serde(default)]
4138    pub sql_standard_syntax: bool,
4139    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4140    #[serde(default)]
4141    pub position_explicit: bool,
4142}
4143
4144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4145#[cfg_attr(feature = "bindings", derive(TS))]
4146pub enum TrimPosition {
4147    Both,
4148    Leading,
4149    Trailing,
4150}
4151
4152/// REPLACE function
4153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4154#[cfg_attr(feature = "bindings", derive(TS))]
4155pub struct ReplaceFunc {
4156    pub this: Expression,
4157    pub old: Expression,
4158    pub new: Expression,
4159}
4160
4161/// LEFT/RIGHT function
4162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4163#[cfg_attr(feature = "bindings", derive(TS))]
4164pub struct LeftRightFunc {
4165    pub this: Expression,
4166    pub length: Expression,
4167}
4168
4169/// REPEAT function
4170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4171#[cfg_attr(feature = "bindings", derive(TS))]
4172pub struct RepeatFunc {
4173    pub this: Expression,
4174    pub times: Expression,
4175}
4176
4177/// LPAD/RPAD function
4178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4179#[cfg_attr(feature = "bindings", derive(TS))]
4180pub struct PadFunc {
4181    pub this: Expression,
4182    pub length: Expression,
4183    pub fill: Option<Expression>,
4184}
4185
4186/// SPLIT function
4187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4188#[cfg_attr(feature = "bindings", derive(TS))]
4189pub struct SplitFunc {
4190    pub this: Expression,
4191    pub delimiter: Expression,
4192}
4193
4194/// REGEXP_LIKE function
4195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4196#[cfg_attr(feature = "bindings", derive(TS))]
4197pub struct RegexpFunc {
4198    pub this: Expression,
4199    pub pattern: Expression,
4200    pub flags: Option<Expression>,
4201}
4202
4203/// REGEXP_REPLACE function
4204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4205#[cfg_attr(feature = "bindings", derive(TS))]
4206pub struct RegexpReplaceFunc {
4207    pub this: Expression,
4208    pub pattern: Expression,
4209    pub replacement: Expression,
4210    pub flags: Option<Expression>,
4211}
4212
4213/// REGEXP_EXTRACT function
4214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4215#[cfg_attr(feature = "bindings", derive(TS))]
4216pub struct RegexpExtractFunc {
4217    pub this: Expression,
4218    pub pattern: Expression,
4219    pub group: Option<Expression>,
4220}
4221
4222/// ROUND function
4223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4224#[cfg_attr(feature = "bindings", derive(TS))]
4225pub struct RoundFunc {
4226    pub this: Expression,
4227    pub decimals: Option<Expression>,
4228}
4229
4230/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4232#[cfg_attr(feature = "bindings", derive(TS))]
4233pub struct FloorFunc {
4234    pub this: Expression,
4235    pub scale: Option<Expression>,
4236    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4237    #[serde(skip_serializing_if = "Option::is_none", default)]
4238    pub to: Option<Expression>,
4239}
4240
4241/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4243#[cfg_attr(feature = "bindings", derive(TS))]
4244pub struct CeilFunc {
4245    pub this: Expression,
4246    #[serde(skip_serializing_if = "Option::is_none", default)]
4247    pub decimals: Option<Expression>,
4248    /// Time unit for Druid-style CEIL(time TO unit) syntax
4249    #[serde(skip_serializing_if = "Option::is_none", default)]
4250    pub to: Option<Expression>,
4251}
4252
4253/// LOG function
4254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4255#[cfg_attr(feature = "bindings", derive(TS))]
4256pub struct LogFunc {
4257    pub this: Expression,
4258    pub base: Option<Expression>,
4259}
4260
4261/// CURRENT_DATE (no arguments)
4262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4263#[cfg_attr(feature = "bindings", derive(TS))]
4264pub struct CurrentDate;
4265
4266/// CURRENT_TIME
4267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4268#[cfg_attr(feature = "bindings", derive(TS))]
4269pub struct CurrentTime {
4270    pub precision: Option<u32>,
4271}
4272
4273/// CURRENT_TIMESTAMP
4274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4275#[cfg_attr(feature = "bindings", derive(TS))]
4276pub struct CurrentTimestamp {
4277    pub precision: Option<u32>,
4278    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4279    #[serde(default)]
4280    pub sysdate: bool,
4281}
4282
4283/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4285#[cfg_attr(feature = "bindings", derive(TS))]
4286pub struct CurrentTimestampLTZ {
4287    pub precision: Option<u32>,
4288}
4289
4290/// AT TIME ZONE expression for timezone conversion
4291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4292#[cfg_attr(feature = "bindings", derive(TS))]
4293pub struct AtTimeZone {
4294    /// The expression to convert
4295    pub this: Expression,
4296    /// The target timezone
4297    pub zone: Expression,
4298}
4299
4300/// DATE_ADD / DATE_SUB function
4301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4302#[cfg_attr(feature = "bindings", derive(TS))]
4303pub struct DateAddFunc {
4304    pub this: Expression,
4305    pub interval: Expression,
4306    pub unit: IntervalUnit,
4307}
4308
4309/// DATEDIFF function
4310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4311#[cfg_attr(feature = "bindings", derive(TS))]
4312pub struct DateDiffFunc {
4313    pub this: Expression,
4314    pub expression: Expression,
4315    pub unit: Option<IntervalUnit>,
4316}
4317
4318/// DATE_TRUNC function
4319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4320#[cfg_attr(feature = "bindings", derive(TS))]
4321pub struct DateTruncFunc {
4322    pub this: Expression,
4323    pub unit: DateTimeField,
4324}
4325
4326/// EXTRACT function
4327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4328#[cfg_attr(feature = "bindings", derive(TS))]
4329pub struct ExtractFunc {
4330    pub this: Expression,
4331    pub field: DateTimeField,
4332}
4333
4334#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4335#[cfg_attr(feature = "bindings", derive(TS))]
4336pub enum DateTimeField {
4337    Year,
4338    Month,
4339    Day,
4340    Hour,
4341    Minute,
4342    Second,
4343    Millisecond,
4344    Microsecond,
4345    DayOfWeek,
4346    DayOfYear,
4347    Week,
4348    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4349    WeekWithModifier(String),
4350    Quarter,
4351    Epoch,
4352    Timezone,
4353    TimezoneHour,
4354    TimezoneMinute,
4355    Date,
4356    Time,
4357    /// Custom datetime field for dialect-specific or arbitrary fields
4358    Custom(String),
4359}
4360
4361/// TO_DATE function
4362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4363#[cfg_attr(feature = "bindings", derive(TS))]
4364pub struct ToDateFunc {
4365    pub this: Expression,
4366    pub format: Option<Expression>,
4367}
4368
4369/// TO_TIMESTAMP function
4370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4371#[cfg_attr(feature = "bindings", derive(TS))]
4372pub struct ToTimestampFunc {
4373    pub this: Expression,
4374    pub format: Option<Expression>,
4375}
4376
4377/// IF function
4378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4379#[cfg_attr(feature = "bindings", derive(TS))]
4380pub struct IfFunc {
4381    pub condition: Expression,
4382    pub true_value: Expression,
4383    pub false_value: Option<Expression>,
4384    /// Original function name (IF, IFF, IIF) for round-trip preservation
4385    #[serde(skip_serializing_if = "Option::is_none", default)]
4386    pub original_name: Option<String>,
4387}
4388
4389/// NVL2 function
4390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4391#[cfg_attr(feature = "bindings", derive(TS))]
4392pub struct Nvl2Func {
4393    pub this: Expression,
4394    pub true_value: Expression,
4395    pub false_value: Expression,
4396}
4397
4398// ============================================================================
4399// Typed Aggregate Function types
4400// ============================================================================
4401
4402/// Generic aggregate function base type
4403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4404#[cfg_attr(feature = "bindings", derive(TS))]
4405pub struct AggFunc {
4406    pub this: Expression,
4407    pub distinct: bool,
4408    pub filter: Option<Expression>,
4409    pub order_by: Vec<Ordered>,
4410    /// Original function name (case-preserving) when parsed from SQL
4411    #[serde(skip_serializing_if = "Option::is_none", default)]
4412    pub name: Option<String>,
4413    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4414    #[serde(skip_serializing_if = "Option::is_none", default)]
4415    pub ignore_nulls: Option<bool>,
4416    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4417    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4418    #[serde(skip_serializing_if = "Option::is_none", default)]
4419    pub having_max: Option<(Box<Expression>, bool)>,
4420    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4421    #[serde(skip_serializing_if = "Option::is_none", default)]
4422    pub limit: Option<Box<Expression>>,
4423}
4424
4425/// COUNT function with optional star
4426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4427#[cfg_attr(feature = "bindings", derive(TS))]
4428pub struct CountFunc {
4429    pub this: Option<Expression>,
4430    pub star: bool,
4431    pub distinct: bool,
4432    pub filter: Option<Expression>,
4433    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4434    #[serde(default, skip_serializing_if = "Option::is_none")]
4435    pub ignore_nulls: Option<bool>,
4436    /// Original function name for case preservation (e.g., "count" or "COUNT")
4437    #[serde(default, skip_serializing_if = "Option::is_none")]
4438    pub original_name: Option<String>,
4439}
4440
4441/// GROUP_CONCAT function (MySQL style)
4442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4443#[cfg_attr(feature = "bindings", derive(TS))]
4444pub struct GroupConcatFunc {
4445    pub this: Expression,
4446    pub separator: Option<Expression>,
4447    pub order_by: Option<Vec<Ordered>>,
4448    pub distinct: bool,
4449    pub filter: Option<Expression>,
4450}
4451
4452/// STRING_AGG function (PostgreSQL/Standard SQL)
4453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4454#[cfg_attr(feature = "bindings", derive(TS))]
4455pub struct StringAggFunc {
4456    pub this: Expression,
4457    #[serde(default)]
4458    pub separator: Option<Expression>,
4459    #[serde(default)]
4460    pub order_by: Option<Vec<Ordered>>,
4461    #[serde(default)]
4462    pub distinct: bool,
4463    #[serde(default)]
4464    pub filter: Option<Expression>,
4465    /// BigQuery LIMIT inside STRING_AGG
4466    #[serde(default, skip_serializing_if = "Option::is_none")]
4467    pub limit: Option<Box<Expression>>,
4468}
4469
4470/// LISTAGG function (Oracle style)
4471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4472#[cfg_attr(feature = "bindings", derive(TS))]
4473pub struct ListAggFunc {
4474    pub this: Expression,
4475    pub separator: Option<Expression>,
4476    pub on_overflow: Option<ListAggOverflow>,
4477    pub order_by: Option<Vec<Ordered>>,
4478    pub distinct: bool,
4479    pub filter: Option<Expression>,
4480}
4481
4482/// LISTAGG ON OVERFLOW behavior
4483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4484#[cfg_attr(feature = "bindings", derive(TS))]
4485pub enum ListAggOverflow {
4486    Error,
4487    Truncate {
4488        filler: Option<Expression>,
4489        with_count: bool,
4490    },
4491}
4492
4493/// SUM_IF / COUNT_IF function
4494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4495#[cfg_attr(feature = "bindings", derive(TS))]
4496pub struct SumIfFunc {
4497    pub this: Expression,
4498    pub condition: Expression,
4499    pub filter: Option<Expression>,
4500}
4501
4502/// APPROX_PERCENTILE function
4503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4504#[cfg_attr(feature = "bindings", derive(TS))]
4505pub struct ApproxPercentileFunc {
4506    pub this: Expression,
4507    pub percentile: Expression,
4508    pub accuracy: Option<Expression>,
4509    pub filter: Option<Expression>,
4510}
4511
4512/// PERCENTILE_CONT / PERCENTILE_DISC function
4513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4514#[cfg_attr(feature = "bindings", derive(TS))]
4515pub struct PercentileFunc {
4516    pub this: Expression,
4517    pub percentile: Expression,
4518    pub order_by: Option<Vec<Ordered>>,
4519    pub filter: Option<Expression>,
4520}
4521
4522// ============================================================================
4523// Typed Window Function types
4524// ============================================================================
4525
4526/// ROW_NUMBER function (no arguments)
4527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4528#[cfg_attr(feature = "bindings", derive(TS))]
4529pub struct RowNumber;
4530
4531/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4533#[cfg_attr(feature = "bindings", derive(TS))]
4534pub struct Rank {
4535    /// DuckDB: RANK(ORDER BY col) - order by inside function
4536    #[serde(default, skip_serializing_if = "Option::is_none")]
4537    pub order_by: Option<Vec<Ordered>>,
4538    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4539    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4540    pub args: Vec<Expression>,
4541}
4542
4543/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4545#[cfg_attr(feature = "bindings", derive(TS))]
4546pub struct DenseRank {
4547    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4548    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4549    pub args: Vec<Expression>,
4550}
4551
4552/// NTILE function (DuckDB allows ORDER BY inside)
4553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4554#[cfg_attr(feature = "bindings", derive(TS))]
4555pub struct NTileFunc {
4556    /// num_buckets is optional to support Databricks NTILE() without arguments
4557    #[serde(default, skip_serializing_if = "Option::is_none")]
4558    pub num_buckets: Option<Expression>,
4559    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4560    #[serde(default, skip_serializing_if = "Option::is_none")]
4561    pub order_by: Option<Vec<Ordered>>,
4562}
4563
4564/// LEAD / LAG function
4565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4566#[cfg_attr(feature = "bindings", derive(TS))]
4567pub struct LeadLagFunc {
4568    pub this: Expression,
4569    pub offset: Option<Expression>,
4570    pub default: Option<Expression>,
4571    pub ignore_nulls: bool,
4572}
4573
4574/// FIRST_VALUE / LAST_VALUE function
4575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4576#[cfg_attr(feature = "bindings", derive(TS))]
4577pub struct ValueFunc {
4578    pub this: Expression,
4579    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4580    #[serde(default, skip_serializing_if = "Option::is_none")]
4581    pub ignore_nulls: Option<bool>,
4582}
4583
4584/// NTH_VALUE function
4585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4586#[cfg_attr(feature = "bindings", derive(TS))]
4587pub struct NthValueFunc {
4588    pub this: Expression,
4589    pub offset: Expression,
4590    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4591    #[serde(default, skip_serializing_if = "Option::is_none")]
4592    pub ignore_nulls: Option<bool>,
4593    /// Snowflake FROM FIRST / FROM LAST clause
4594    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
4595    #[serde(default, skip_serializing_if = "Option::is_none")]
4596    pub from_first: Option<bool>,
4597}
4598
4599/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4601#[cfg_attr(feature = "bindings", derive(TS))]
4602pub struct PercentRank {
4603    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4604    #[serde(default, skip_serializing_if = "Option::is_none")]
4605    pub order_by: Option<Vec<Ordered>>,
4606    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4607    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4608    pub args: Vec<Expression>,
4609}
4610
4611/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4613#[cfg_attr(feature = "bindings", derive(TS))]
4614pub struct CumeDist {
4615    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4616    #[serde(default, skip_serializing_if = "Option::is_none")]
4617    pub order_by: Option<Vec<Ordered>>,
4618    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4619    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4620    pub args: Vec<Expression>,
4621}
4622
4623// ============================================================================
4624// Additional String Function types
4625// ============================================================================
4626
4627/// POSITION/INSTR function
4628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4629#[cfg_attr(feature = "bindings", derive(TS))]
4630pub struct PositionFunc {
4631    pub substring: Expression,
4632    pub string: Expression,
4633    pub start: Option<Expression>,
4634}
4635
4636// ============================================================================
4637// Additional Math Function types
4638// ============================================================================
4639
4640/// RANDOM function (no arguments)
4641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4642#[cfg_attr(feature = "bindings", derive(TS))]
4643pub struct Random;
4644
4645/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4647#[cfg_attr(feature = "bindings", derive(TS))]
4648pub struct Rand {
4649    pub seed: Option<Box<Expression>>,
4650    /// Teradata RANDOM lower bound
4651    #[serde(default)]
4652    pub lower: Option<Box<Expression>>,
4653    /// Teradata RANDOM upper bound
4654    #[serde(default)]
4655    pub upper: Option<Box<Expression>>,
4656}
4657
4658/// TRUNCATE / TRUNC function
4659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4660#[cfg_attr(feature = "bindings", derive(TS))]
4661pub struct TruncateFunc {
4662    pub this: Expression,
4663    pub decimals: Option<Expression>,
4664}
4665
4666/// PI function (no arguments)
4667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4668#[cfg_attr(feature = "bindings", derive(TS))]
4669pub struct Pi;
4670
4671// ============================================================================
4672// Control Flow Function types
4673// ============================================================================
4674
4675/// DECODE function (Oracle style)
4676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4677#[cfg_attr(feature = "bindings", derive(TS))]
4678pub struct DecodeFunc {
4679    pub this: Expression,
4680    pub search_results: Vec<(Expression, Expression)>,
4681    pub default: Option<Expression>,
4682}
4683
4684// ============================================================================
4685// Additional Date/Time Function types
4686// ============================================================================
4687
4688/// DATE_FORMAT / FORMAT_DATE function
4689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4690#[cfg_attr(feature = "bindings", derive(TS))]
4691pub struct DateFormatFunc {
4692    pub this: Expression,
4693    pub format: Expression,
4694}
4695
4696/// FROM_UNIXTIME function
4697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4698#[cfg_attr(feature = "bindings", derive(TS))]
4699pub struct FromUnixtimeFunc {
4700    pub this: Expression,
4701    pub format: Option<Expression>,
4702}
4703
4704/// UNIX_TIMESTAMP function
4705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4706#[cfg_attr(feature = "bindings", derive(TS))]
4707pub struct UnixTimestampFunc {
4708    pub this: Option<Expression>,
4709    pub format: Option<Expression>,
4710}
4711
4712/// MAKE_DATE function
4713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4714#[cfg_attr(feature = "bindings", derive(TS))]
4715pub struct MakeDateFunc {
4716    pub year: Expression,
4717    pub month: Expression,
4718    pub day: Expression,
4719}
4720
4721/// MAKE_TIMESTAMP function
4722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4723#[cfg_attr(feature = "bindings", derive(TS))]
4724pub struct MakeTimestampFunc {
4725    pub year: Expression,
4726    pub month: Expression,
4727    pub day: Expression,
4728    pub hour: Expression,
4729    pub minute: Expression,
4730    pub second: Expression,
4731    pub timezone: Option<Expression>,
4732}
4733
4734/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4736#[cfg_attr(feature = "bindings", derive(TS))]
4737pub struct LastDayFunc {
4738    pub this: Expression,
4739    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4740    #[serde(skip_serializing_if = "Option::is_none", default)]
4741    pub unit: Option<DateTimeField>,
4742}
4743
4744// ============================================================================
4745// Array Function types
4746// ============================================================================
4747
4748/// ARRAY constructor
4749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4750#[cfg_attr(feature = "bindings", derive(TS))]
4751pub struct ArrayConstructor {
4752    pub expressions: Vec<Expression>,
4753    pub bracket_notation: bool,
4754    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4755    pub use_list_keyword: bool,
4756}
4757
4758/// ARRAY_SORT function
4759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4760#[cfg_attr(feature = "bindings", derive(TS))]
4761pub struct ArraySortFunc {
4762    pub this: Expression,
4763    pub comparator: Option<Expression>,
4764    pub desc: bool,
4765    pub nulls_first: Option<bool>,
4766}
4767
4768/// ARRAY_JOIN / ARRAY_TO_STRING function
4769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4770#[cfg_attr(feature = "bindings", derive(TS))]
4771pub struct ArrayJoinFunc {
4772    pub this: Expression,
4773    pub separator: Expression,
4774    pub null_replacement: Option<Expression>,
4775}
4776
4777/// UNNEST function
4778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4779#[cfg_attr(feature = "bindings", derive(TS))]
4780pub struct UnnestFunc {
4781    pub this: Expression,
4782    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4783    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4784    pub expressions: Vec<Expression>,
4785    pub with_ordinality: bool,
4786    pub alias: Option<Identifier>,
4787    /// BigQuery: offset alias for WITH OFFSET AS <name>
4788    #[serde(default, skip_serializing_if = "Option::is_none")]
4789    pub offset_alias: Option<Identifier>,
4790}
4791
4792/// ARRAY_FILTER function (with lambda)
4793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4794#[cfg_attr(feature = "bindings", derive(TS))]
4795pub struct ArrayFilterFunc {
4796    pub this: Expression,
4797    pub filter: Expression,
4798}
4799
4800/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4802#[cfg_attr(feature = "bindings", derive(TS))]
4803pub struct ArrayTransformFunc {
4804    pub this: Expression,
4805    pub transform: Expression,
4806}
4807
4808/// SEQUENCE / GENERATE_SERIES function
4809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4810#[cfg_attr(feature = "bindings", derive(TS))]
4811pub struct SequenceFunc {
4812    pub start: Expression,
4813    pub stop: Expression,
4814    pub step: Option<Expression>,
4815}
4816
4817// ============================================================================
4818// Struct Function types
4819// ============================================================================
4820
4821/// STRUCT constructor
4822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4823#[cfg_attr(feature = "bindings", derive(TS))]
4824pub struct StructConstructor {
4825    pub fields: Vec<(Option<Identifier>, Expression)>,
4826}
4827
4828/// STRUCT_EXTRACT function
4829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4830#[cfg_attr(feature = "bindings", derive(TS))]
4831pub struct StructExtractFunc {
4832    pub this: Expression,
4833    pub field: Identifier,
4834}
4835
4836/// NAMED_STRUCT function
4837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4838#[cfg_attr(feature = "bindings", derive(TS))]
4839pub struct NamedStructFunc {
4840    pub pairs: Vec<(Expression, Expression)>,
4841}
4842
4843// ============================================================================
4844// Map Function types
4845// ============================================================================
4846
4847/// MAP constructor
4848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4849#[cfg_attr(feature = "bindings", derive(TS))]
4850pub struct MapConstructor {
4851    pub keys: Vec<Expression>,
4852    pub values: Vec<Expression>,
4853    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4854    #[serde(default)]
4855    pub curly_brace_syntax: bool,
4856    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4857    #[serde(default)]
4858    pub with_map_keyword: bool,
4859}
4860
4861/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4863#[cfg_attr(feature = "bindings", derive(TS))]
4864pub struct TransformFunc {
4865    pub this: Expression,
4866    pub transform: Expression,
4867}
4868
4869// ============================================================================
4870// JSON Function types
4871// ============================================================================
4872
4873/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4875#[cfg_attr(feature = "bindings", derive(TS))]
4876pub struct JsonExtractFunc {
4877    pub this: Expression,
4878    pub path: Expression,
4879    pub returning: Option<DataType>,
4880    /// True if parsed from -> or ->> operator syntax
4881    #[serde(default)]
4882    pub arrow_syntax: bool,
4883    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4884    #[serde(default)]
4885    pub hash_arrow_syntax: bool,
4886    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4887    #[serde(default)]
4888    pub wrapper_option: Option<String>,
4889    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4890    #[serde(default)]
4891    pub quotes_option: Option<String>,
4892    /// ON SCALAR STRING flag
4893    #[serde(default)]
4894    pub on_scalar_string: bool,
4895    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4896    #[serde(default)]
4897    pub on_error: Option<String>,
4898}
4899
4900/// JSON path extraction
4901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4902#[cfg_attr(feature = "bindings", derive(TS))]
4903pub struct JsonPathFunc {
4904    pub this: Expression,
4905    pub paths: Vec<Expression>,
4906}
4907
4908/// JSON_OBJECT function
4909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4910#[cfg_attr(feature = "bindings", derive(TS))]
4911pub struct JsonObjectFunc {
4912    pub pairs: Vec<(Expression, Expression)>,
4913    pub null_handling: Option<JsonNullHandling>,
4914    #[serde(default)]
4915    pub with_unique_keys: bool,
4916    #[serde(default)]
4917    pub returning_type: Option<DataType>,
4918    #[serde(default)]
4919    pub format_json: bool,
4920    #[serde(default)]
4921    pub encoding: Option<String>,
4922    /// For JSON_OBJECT(*) syntax
4923    #[serde(default)]
4924    pub star: bool,
4925}
4926
4927/// JSON null handling options
4928#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4929#[cfg_attr(feature = "bindings", derive(TS))]
4930pub enum JsonNullHandling {
4931    NullOnNull,
4932    AbsentOnNull,
4933}
4934
4935/// JSON_SET / JSON_INSERT function
4936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4937#[cfg_attr(feature = "bindings", derive(TS))]
4938pub struct JsonModifyFunc {
4939    pub this: Expression,
4940    pub path_values: Vec<(Expression, Expression)>,
4941}
4942
4943/// JSON_ARRAYAGG function
4944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4945#[cfg_attr(feature = "bindings", derive(TS))]
4946pub struct JsonArrayAggFunc {
4947    pub this: Expression,
4948    pub order_by: Option<Vec<Ordered>>,
4949    pub null_handling: Option<JsonNullHandling>,
4950    pub filter: Option<Expression>,
4951}
4952
4953/// JSON_OBJECTAGG function
4954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4955#[cfg_attr(feature = "bindings", derive(TS))]
4956pub struct JsonObjectAggFunc {
4957    pub key: Expression,
4958    pub value: Expression,
4959    pub null_handling: Option<JsonNullHandling>,
4960    pub filter: Option<Expression>,
4961}
4962
4963// ============================================================================
4964// Type Casting Function types
4965// ============================================================================
4966
4967/// CONVERT function (SQL Server style)
4968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4969#[cfg_attr(feature = "bindings", derive(TS))]
4970pub struct ConvertFunc {
4971    pub this: Expression,
4972    pub to: DataType,
4973    pub style: Option<Expression>,
4974}
4975
4976// ============================================================================
4977// Additional Expression types
4978// ============================================================================
4979
4980/// Lambda expression
4981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4982#[cfg_attr(feature = "bindings", derive(TS))]
4983pub struct LambdaExpr {
4984    pub parameters: Vec<Identifier>,
4985    pub body: Expression,
4986    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
4987    #[serde(default)]
4988    pub colon: bool,
4989    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
4990    /// Maps parameter index to data type
4991    #[serde(default)]
4992    pub parameter_types: Vec<Option<DataType>>,
4993}
4994
4995/// Parameter (parameterized queries)
4996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4997#[cfg_attr(feature = "bindings", derive(TS))]
4998pub struct Parameter {
4999    pub name: Option<String>,
5000    pub index: Option<u32>,
5001    pub style: ParameterStyle,
5002    /// Whether the name was quoted (e.g., @"x" vs @x)
5003    #[serde(default)]
5004    pub quoted: bool,
5005    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5006    #[serde(default)]
5007    pub string_quoted: bool,
5008    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5009    #[serde(default)]
5010    pub expression: Option<String>,
5011}
5012
5013/// Parameter placeholder styles
5014#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5015#[cfg_attr(feature = "bindings", derive(TS))]
5016pub enum ParameterStyle {
5017    Question,     // ?
5018    Dollar,       // $1, $2
5019    DollarBrace,  // ${name} (Databricks, Hive template variables)
5020    Brace,        // {name} (Spark/Databricks widget/template variables)
5021    Colon,        // :name
5022    At,           // @name
5023    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5024    DoubleDollar, // $$name
5025    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5026}
5027
5028/// Placeholder expression
5029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5030#[cfg_attr(feature = "bindings", derive(TS))]
5031pub struct Placeholder {
5032    pub index: Option<u32>,
5033}
5034
5035/// Named argument in function call: name => value or name := value
5036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5037#[cfg_attr(feature = "bindings", derive(TS))]
5038pub struct NamedArgument {
5039    pub name: Identifier,
5040    pub value: Expression,
5041    /// The separator used: `=>`, `:=`, or `=`
5042    pub separator: NamedArgSeparator,
5043}
5044
5045/// Separator style for named arguments
5046#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5047#[cfg_attr(feature = "bindings", derive(TS))]
5048pub enum NamedArgSeparator {
5049    /// `=>` (standard SQL, Snowflake, BigQuery)
5050    DArrow,
5051    /// `:=` (Oracle, MySQL)
5052    ColonEq,
5053    /// `=` (simple equals, some dialects)
5054    Eq,
5055}
5056
5057/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5058/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5060#[cfg_attr(feature = "bindings", derive(TS))]
5061pub struct TableArgument {
5062    /// The keyword prefix: "TABLE" or "MODEL"
5063    pub prefix: String,
5064    /// The table/model reference expression
5065    pub this: Expression,
5066}
5067
5068/// SQL Comment preservation
5069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5070#[cfg_attr(feature = "bindings", derive(TS))]
5071pub struct SqlComment {
5072    pub text: String,
5073    pub is_block: bool,
5074}
5075
5076// ============================================================================
5077// Additional Predicate types
5078// ============================================================================
5079
5080/// SIMILAR TO expression
5081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5082#[cfg_attr(feature = "bindings", derive(TS))]
5083pub struct SimilarToExpr {
5084    pub this: Expression,
5085    pub pattern: Expression,
5086    pub escape: Option<Expression>,
5087    pub not: bool,
5088}
5089
5090/// ANY / ALL quantified expression
5091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5092#[cfg_attr(feature = "bindings", derive(TS))]
5093pub struct QuantifiedExpr {
5094    pub this: Expression,
5095    pub subquery: Expression,
5096    pub op: Option<QuantifiedOp>,
5097}
5098
5099/// Comparison operator for quantified expressions
5100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5101#[cfg_attr(feature = "bindings", derive(TS))]
5102pub enum QuantifiedOp {
5103    Eq,
5104    Neq,
5105    Lt,
5106    Lte,
5107    Gt,
5108    Gte,
5109}
5110
5111/// OVERLAPS expression
5112/// Supports two forms:
5113/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5114/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5116#[cfg_attr(feature = "bindings", derive(TS))]
5117pub struct OverlapsExpr {
5118    /// Left operand for simple binary form
5119    #[serde(skip_serializing_if = "Option::is_none")]
5120    pub this: Option<Expression>,
5121    /// Right operand for simple binary form
5122    #[serde(skip_serializing_if = "Option::is_none")]
5123    pub expression: Option<Expression>,
5124    /// Left range start for full ANSI form
5125    #[serde(skip_serializing_if = "Option::is_none")]
5126    pub left_start: Option<Expression>,
5127    /// Left range end for full ANSI form
5128    #[serde(skip_serializing_if = "Option::is_none")]
5129    pub left_end: Option<Expression>,
5130    /// Right range start for full ANSI form
5131    #[serde(skip_serializing_if = "Option::is_none")]
5132    pub right_start: Option<Expression>,
5133    /// Right range end for full ANSI form
5134    #[serde(skip_serializing_if = "Option::is_none")]
5135    pub right_end: Option<Expression>,
5136}
5137
5138// ============================================================================
5139// Array/Struct/Map access
5140// ============================================================================
5141
5142/// Subscript access (array[index] or map[key])
5143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5144#[cfg_attr(feature = "bindings", derive(TS))]
5145pub struct Subscript {
5146    pub this: Expression,
5147    pub index: Expression,
5148}
5149
5150/// Dot access (struct.field)
5151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5152#[cfg_attr(feature = "bindings", derive(TS))]
5153pub struct DotAccess {
5154    pub this: Expression,
5155    pub field: Identifier,
5156}
5157
5158/// Method call (expr.method(args))
5159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5160#[cfg_attr(feature = "bindings", derive(TS))]
5161pub struct MethodCall {
5162    pub this: Expression,
5163    pub method: Identifier,
5164    pub args: Vec<Expression>,
5165}
5166
5167/// Array slice (array[start:end])
5168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5169#[cfg_attr(feature = "bindings", derive(TS))]
5170pub struct ArraySlice {
5171    pub this: Expression,
5172    pub start: Option<Expression>,
5173    pub end: Option<Expression>,
5174}
5175
5176// ============================================================================
5177// DDL (Data Definition Language) Statements
5178// ============================================================================
5179
5180/// ON COMMIT behavior for temporary tables
5181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5182#[cfg_attr(feature = "bindings", derive(TS))]
5183pub enum OnCommit {
5184    /// ON COMMIT PRESERVE ROWS
5185    PreserveRows,
5186    /// ON COMMIT DELETE ROWS
5187    DeleteRows,
5188}
5189
5190/// CREATE TABLE statement
5191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5192#[cfg_attr(feature = "bindings", derive(TS))]
5193pub struct CreateTable {
5194    pub name: TableRef,
5195    /// ClickHouse: ON CLUSTER clause for distributed DDL
5196    #[serde(default, skip_serializing_if = "Option::is_none")]
5197    pub on_cluster: Option<OnCluster>,
5198    pub columns: Vec<ColumnDef>,
5199    pub constraints: Vec<TableConstraint>,
5200    pub if_not_exists: bool,
5201    pub temporary: bool,
5202    pub or_replace: bool,
5203    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5204    #[serde(default, skip_serializing_if = "Option::is_none")]
5205    pub table_modifier: Option<String>,
5206    pub as_select: Option<Expression>,
5207    /// Whether the AS SELECT was wrapped in parentheses
5208    #[serde(default)]
5209    pub as_select_parenthesized: bool,
5210    /// ON COMMIT behavior for temporary tables
5211    #[serde(default)]
5212    pub on_commit: Option<OnCommit>,
5213    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5214    #[serde(default)]
5215    pub clone_source: Option<TableRef>,
5216    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5217    #[serde(default, skip_serializing_if = "Option::is_none")]
5218    pub clone_at_clause: Option<Expression>,
5219    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5220    #[serde(default)]
5221    pub is_copy: bool,
5222    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5223    #[serde(default)]
5224    pub shallow_clone: bool,
5225    /// Leading comments before the statement
5226    #[serde(default)]
5227    pub leading_comments: Vec<String>,
5228    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5229    #[serde(default)]
5230    pub with_properties: Vec<(String, String)>,
5231    /// Teradata: table options after name before columns (comma-separated)
5232    #[serde(default)]
5233    pub teradata_post_name_options: Vec<String>,
5234    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5235    #[serde(default)]
5236    pub with_data: Option<bool>,
5237    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5238    #[serde(default)]
5239    pub with_statistics: Option<bool>,
5240    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5241    #[serde(default)]
5242    pub teradata_indexes: Vec<TeradataIndex>,
5243    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5244    #[serde(default)]
5245    pub with_cte: Option<With>,
5246    /// Table properties like DEFAULT COLLATE (BigQuery)
5247    #[serde(default)]
5248    pub properties: Vec<Expression>,
5249    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5250    #[serde(default, skip_serializing_if = "Option::is_none")]
5251    pub partition_of: Option<Expression>,
5252    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5253    #[serde(default)]
5254    pub post_table_properties: Vec<Expression>,
5255    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5256    #[serde(default)]
5257    pub mysql_table_options: Vec<(String, String)>,
5258    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5259    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5260    pub inherits: Vec<TableRef>,
5261    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5262    #[serde(default, skip_serializing_if = "Option::is_none")]
5263    pub on_property: Option<OnProperty>,
5264    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5265    #[serde(default)]
5266    pub copy_grants: bool,
5267    /// Snowflake: USING TEMPLATE expression for schema inference
5268    #[serde(default, skip_serializing_if = "Option::is_none")]
5269    pub using_template: Option<Box<Expression>>,
5270    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5271    #[serde(default, skip_serializing_if = "Option::is_none")]
5272    pub rollup: Option<RollupProperty>,
5273}
5274
5275/// Teradata index specification for CREATE TABLE
5276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5277#[cfg_attr(feature = "bindings", derive(TS))]
5278pub struct TeradataIndex {
5279    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5280    pub kind: TeradataIndexKind,
5281    /// Optional index name
5282    pub name: Option<String>,
5283    /// Optional column list
5284    pub columns: Vec<String>,
5285}
5286
5287/// Kind of Teradata index
5288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5289#[cfg_attr(feature = "bindings", derive(TS))]
5290pub enum TeradataIndexKind {
5291    /// NO PRIMARY INDEX
5292    NoPrimary,
5293    /// PRIMARY INDEX
5294    Primary,
5295    /// PRIMARY AMP INDEX
5296    PrimaryAmp,
5297    /// UNIQUE INDEX
5298    Unique,
5299    /// UNIQUE PRIMARY INDEX
5300    UniquePrimary,
5301    /// INDEX (secondary, non-primary)
5302    Secondary,
5303}
5304
5305impl CreateTable {
5306    pub fn new(name: impl Into<String>) -> Self {
5307        Self {
5308            name: TableRef::new(name),
5309            on_cluster: None,
5310            columns: Vec::new(),
5311            constraints: Vec::new(),
5312            if_not_exists: false,
5313            temporary: false,
5314            or_replace: false,
5315            table_modifier: None,
5316            as_select: None,
5317            as_select_parenthesized: false,
5318            on_commit: None,
5319            clone_source: None,
5320            clone_at_clause: None,
5321            shallow_clone: false,
5322            is_copy: false,
5323            leading_comments: Vec::new(),
5324            with_properties: Vec::new(),
5325            teradata_post_name_options: Vec::new(),
5326            with_data: None,
5327            with_statistics: None,
5328            teradata_indexes: Vec::new(),
5329            with_cte: None,
5330            properties: Vec::new(),
5331            partition_of: None,
5332            post_table_properties: Vec::new(),
5333            mysql_table_options: Vec::new(),
5334            inherits: Vec::new(),
5335            on_property: None,
5336            copy_grants: false,
5337            using_template: None,
5338            rollup: None,
5339        }
5340    }
5341}
5342
5343/// Sort order for PRIMARY KEY ASC/DESC
5344#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5345#[cfg_attr(feature = "bindings", derive(TS))]
5346pub enum SortOrder {
5347    Asc,
5348    Desc,
5349}
5350
5351/// Type of column constraint for tracking order
5352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5353#[cfg_attr(feature = "bindings", derive(TS))]
5354pub enum ConstraintType {
5355    NotNull,
5356    Null,
5357    PrimaryKey,
5358    Unique,
5359    Default,
5360    AutoIncrement,
5361    Collate,
5362    Comment,
5363    References,
5364    Check,
5365    GeneratedAsIdentity,
5366    /// Snowflake: TAG (key='value', ...)
5367    Tags,
5368    /// Computed/generated column
5369    ComputedColumn,
5370    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5371    GeneratedAsRow,
5372    /// MySQL: ON UPDATE expression
5373    OnUpdate,
5374    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5375    Path,
5376    /// Redshift: ENCODE encoding_type
5377    Encode,
5378}
5379
5380/// Column definition in CREATE TABLE
5381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5382#[cfg_attr(feature = "bindings", derive(TS))]
5383pub struct ColumnDef {
5384    pub name: Identifier,
5385    pub data_type: DataType,
5386    pub nullable: Option<bool>,
5387    pub default: Option<Expression>,
5388    pub primary_key: bool,
5389    /// Sort order for PRIMARY KEY (ASC/DESC)
5390    #[serde(default)]
5391    pub primary_key_order: Option<SortOrder>,
5392    pub unique: bool,
5393    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5394    #[serde(default)]
5395    pub unique_nulls_not_distinct: bool,
5396    pub auto_increment: bool,
5397    pub comment: Option<String>,
5398    pub constraints: Vec<ColumnConstraint>,
5399    /// Track original order of constraints for accurate regeneration
5400    #[serde(default)]
5401    pub constraint_order: Vec<ConstraintType>,
5402    /// Teradata: FORMAT 'pattern'
5403    #[serde(default)]
5404    pub format: Option<String>,
5405    /// Teradata: TITLE 'title'
5406    #[serde(default)]
5407    pub title: Option<String>,
5408    /// Teradata: INLINE LENGTH n
5409    #[serde(default)]
5410    pub inline_length: Option<u64>,
5411    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5412    #[serde(default)]
5413    pub compress: Option<Vec<Expression>>,
5414    /// Teradata: CHARACTER SET name
5415    #[serde(default)]
5416    pub character_set: Option<String>,
5417    /// Teradata: UPPERCASE
5418    #[serde(default)]
5419    pub uppercase: bool,
5420    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5421    #[serde(default)]
5422    pub casespecific: Option<bool>,
5423    /// Snowflake: AUTOINCREMENT START value
5424    #[serde(default)]
5425    pub auto_increment_start: Option<Box<Expression>>,
5426    /// Snowflake: AUTOINCREMENT INCREMENT value
5427    #[serde(default)]
5428    pub auto_increment_increment: Option<Box<Expression>>,
5429    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5430    #[serde(default)]
5431    pub auto_increment_order: Option<bool>,
5432    /// MySQL: UNSIGNED modifier
5433    #[serde(default)]
5434    pub unsigned: bool,
5435    /// MySQL: ZEROFILL modifier
5436    #[serde(default)]
5437    pub zerofill: bool,
5438    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5439    #[serde(default, skip_serializing_if = "Option::is_none")]
5440    pub on_update: Option<Expression>,
5441    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5442    #[serde(default, skip_serializing_if = "Option::is_none")]
5443    pub unique_constraint_name: Option<String>,
5444    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5445    #[serde(default, skip_serializing_if = "Option::is_none")]
5446    pub not_null_constraint_name: Option<String>,
5447    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5448    #[serde(default, skip_serializing_if = "Option::is_none")]
5449    pub primary_key_constraint_name: Option<String>,
5450    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5451    #[serde(default, skip_serializing_if = "Option::is_none")]
5452    pub check_constraint_name: Option<String>,
5453    /// BigQuery: OPTIONS (key=value, ...) on column
5454    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5455    pub options: Vec<Expression>,
5456    /// SQLite: Column definition without explicit type
5457    #[serde(default)]
5458    pub no_type: bool,
5459    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5460    #[serde(default, skip_serializing_if = "Option::is_none")]
5461    pub encoding: Option<String>,
5462    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5463    #[serde(default, skip_serializing_if = "Option::is_none")]
5464    pub codec: Option<String>,
5465    /// ClickHouse: EPHEMERAL [expr] modifier
5466    #[serde(default, skip_serializing_if = "Option::is_none")]
5467    pub ephemeral: Option<Option<Box<Expression>>>,
5468    /// ClickHouse: MATERIALIZED expr modifier
5469    #[serde(default, skip_serializing_if = "Option::is_none")]
5470    pub materialized_expr: Option<Box<Expression>>,
5471    /// ClickHouse: ALIAS expr modifier
5472    #[serde(default, skip_serializing_if = "Option::is_none")]
5473    pub alias_expr: Option<Box<Expression>>,
5474    /// ClickHouse: TTL expr modifier on columns
5475    #[serde(default, skip_serializing_if = "Option::is_none")]
5476    pub ttl_expr: Option<Box<Expression>>,
5477    /// TSQL: NOT FOR REPLICATION
5478    #[serde(default)]
5479    pub not_for_replication: bool,
5480}
5481
5482impl ColumnDef {
5483    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5484        Self {
5485            name: Identifier::new(name),
5486            data_type,
5487            nullable: None,
5488            default: None,
5489            primary_key: false,
5490            primary_key_order: None,
5491            unique: false,
5492            unique_nulls_not_distinct: false,
5493            auto_increment: false,
5494            comment: None,
5495            constraints: Vec::new(),
5496            constraint_order: Vec::new(),
5497            format: None,
5498            title: None,
5499            inline_length: None,
5500            compress: None,
5501            character_set: None,
5502            uppercase: false,
5503            casespecific: None,
5504            auto_increment_start: None,
5505            auto_increment_increment: None,
5506            auto_increment_order: None,
5507            unsigned: false,
5508            zerofill: false,
5509            on_update: None,
5510            unique_constraint_name: None,
5511            not_null_constraint_name: None,
5512            primary_key_constraint_name: None,
5513            check_constraint_name: None,
5514            options: Vec::new(),
5515            no_type: false,
5516            encoding: None,
5517            codec: None,
5518            ephemeral: None,
5519            materialized_expr: None,
5520            alias_expr: None,
5521            ttl_expr: None,
5522            not_for_replication: false,
5523        }
5524    }
5525}
5526
5527/// Column-level constraint
5528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5529#[cfg_attr(feature = "bindings", derive(TS))]
5530pub enum ColumnConstraint {
5531    NotNull,
5532    Null,
5533    Unique,
5534    PrimaryKey,
5535    Default(Expression),
5536    Check(Expression),
5537    References(ForeignKeyRef),
5538    GeneratedAsIdentity(GeneratedAsIdentity),
5539    Collate(Identifier),
5540    Comment(String),
5541    /// Snowflake: TAG (key='value', ...)
5542    Tags(Tags),
5543    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5544    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5545    ComputedColumn(ComputedColumn),
5546    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5547    GeneratedAsRow(GeneratedAsRow),
5548    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5549    Path(Expression),
5550}
5551
5552/// Computed/generated column constraint
5553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5554#[cfg_attr(feature = "bindings", derive(TS))]
5555pub struct ComputedColumn {
5556    /// The expression that computes the column value
5557    pub expression: Box<Expression>,
5558    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5559    #[serde(default)]
5560    pub persisted: bool,
5561    /// NOT NULL (TSQL computed columns)
5562    #[serde(default)]
5563    pub not_null: bool,
5564    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5565    /// When None, defaults to dialect-appropriate output
5566    #[serde(default)]
5567    pub persistence_kind: Option<String>,
5568    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5569    #[serde(default, skip_serializing_if = "Option::is_none")]
5570    pub data_type: Option<DataType>,
5571}
5572
5573/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5575#[cfg_attr(feature = "bindings", derive(TS))]
5576pub struct GeneratedAsRow {
5577    /// true = ROW START, false = ROW END
5578    pub start: bool,
5579    /// HIDDEN modifier
5580    #[serde(default)]
5581    pub hidden: bool,
5582}
5583
5584/// Generated identity column constraint
5585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5586#[cfg_attr(feature = "bindings", derive(TS))]
5587pub struct GeneratedAsIdentity {
5588    /// True for ALWAYS, False for BY DEFAULT
5589    pub always: bool,
5590    /// ON NULL (only valid with BY DEFAULT)
5591    pub on_null: bool,
5592    /// START WITH value
5593    pub start: Option<Box<Expression>>,
5594    /// INCREMENT BY value
5595    pub increment: Option<Box<Expression>>,
5596    /// MINVALUE
5597    pub minvalue: Option<Box<Expression>>,
5598    /// MAXVALUE
5599    pub maxvalue: Option<Box<Expression>>,
5600    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5601    pub cycle: Option<bool>,
5602}
5603
5604/// Constraint modifiers (shared between table-level constraints)
5605#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5606#[cfg_attr(feature = "bindings", derive(TS))]
5607pub struct ConstraintModifiers {
5608    /// ENFORCED / NOT ENFORCED
5609    pub enforced: Option<bool>,
5610    /// DEFERRABLE / NOT DEFERRABLE
5611    pub deferrable: Option<bool>,
5612    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5613    pub initially_deferred: Option<bool>,
5614    /// NORELY (Oracle)
5615    pub norely: bool,
5616    /// RELY (Oracle)
5617    pub rely: bool,
5618    /// USING index type (MySQL): BTREE or HASH
5619    #[serde(default)]
5620    pub using: Option<String>,
5621    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5622    #[serde(default)]
5623    pub using_before_columns: bool,
5624    /// MySQL index COMMENT 'text'
5625    #[serde(default, skip_serializing_if = "Option::is_none")]
5626    pub comment: Option<String>,
5627    /// MySQL index VISIBLE/INVISIBLE
5628    #[serde(default, skip_serializing_if = "Option::is_none")]
5629    pub visible: Option<bool>,
5630    /// MySQL ENGINE_ATTRIBUTE = 'value'
5631    #[serde(default, skip_serializing_if = "Option::is_none")]
5632    pub engine_attribute: Option<String>,
5633    /// MySQL WITH PARSER name
5634    #[serde(default, skip_serializing_if = "Option::is_none")]
5635    pub with_parser: Option<String>,
5636    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5637    #[serde(default)]
5638    pub not_valid: bool,
5639    /// TSQL CLUSTERED/NONCLUSTERED modifier
5640    #[serde(default, skip_serializing_if = "Option::is_none")]
5641    pub clustered: Option<String>,
5642    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5643    #[serde(default, skip_serializing_if = "Option::is_none")]
5644    pub on_conflict: Option<String>,
5645    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5646    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5647    pub with_options: Vec<(String, String)>,
5648    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5649    #[serde(default, skip_serializing_if = "Option::is_none")]
5650    pub on_filegroup: Option<Identifier>,
5651}
5652
5653/// Table-level constraint
5654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5655#[cfg_attr(feature = "bindings", derive(TS))]
5656pub enum TableConstraint {
5657    PrimaryKey {
5658        name: Option<Identifier>,
5659        columns: Vec<Identifier>,
5660        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5661        #[serde(default)]
5662        include_columns: Vec<Identifier>,
5663        #[serde(default)]
5664        modifiers: ConstraintModifiers,
5665        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5666        #[serde(default)]
5667        has_constraint_keyword: bool,
5668    },
5669    Unique {
5670        name: Option<Identifier>,
5671        columns: Vec<Identifier>,
5672        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5673        #[serde(default)]
5674        columns_parenthesized: bool,
5675        #[serde(default)]
5676        modifiers: ConstraintModifiers,
5677        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5678        #[serde(default)]
5679        has_constraint_keyword: bool,
5680        /// PostgreSQL 15+: NULLS NOT DISTINCT
5681        #[serde(default)]
5682        nulls_not_distinct: bool,
5683    },
5684    ForeignKey {
5685        name: Option<Identifier>,
5686        columns: Vec<Identifier>,
5687        #[serde(default)]
5688        references: Option<ForeignKeyRef>,
5689        /// ON DELETE action when REFERENCES is absent
5690        #[serde(default)]
5691        on_delete: Option<ReferentialAction>,
5692        /// ON UPDATE action when REFERENCES is absent
5693        #[serde(default)]
5694        on_update: Option<ReferentialAction>,
5695        #[serde(default)]
5696        modifiers: ConstraintModifiers,
5697    },
5698    Check {
5699        name: Option<Identifier>,
5700        expression: Expression,
5701        #[serde(default)]
5702        modifiers: ConstraintModifiers,
5703    },
5704    /// INDEX / KEY constraint (MySQL)
5705    Index {
5706        name: Option<Identifier>,
5707        columns: Vec<Identifier>,
5708        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5709        #[serde(default)]
5710        kind: Option<String>,
5711        #[serde(default)]
5712        modifiers: ConstraintModifiers,
5713        /// True if KEY keyword was used instead of INDEX
5714        #[serde(default)]
5715        use_key_keyword: bool,
5716        /// ClickHouse: indexed expression (instead of columns)
5717        #[serde(default, skip_serializing_if = "Option::is_none")]
5718        expression: Option<Box<Expression>>,
5719        /// ClickHouse: TYPE type_func(args)
5720        #[serde(default, skip_serializing_if = "Option::is_none")]
5721        index_type: Option<Box<Expression>>,
5722        /// ClickHouse: GRANULARITY n
5723        #[serde(default, skip_serializing_if = "Option::is_none")]
5724        granularity: Option<Box<Expression>>,
5725    },
5726    /// ClickHouse PROJECTION definition
5727    Projection {
5728        name: Identifier,
5729        expression: Expression,
5730    },
5731    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5732    Like {
5733        source: TableRef,
5734        /// Options as (INCLUDING|EXCLUDING, property) pairs
5735        options: Vec<(LikeOptionAction, String)>,
5736    },
5737    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5738    PeriodForSystemTime {
5739        start_col: Identifier,
5740        end_col: Identifier,
5741    },
5742    /// PostgreSQL EXCLUDE constraint
5743    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5744    Exclude {
5745        name: Option<Identifier>,
5746        /// Index access method (gist, btree, etc.)
5747        #[serde(default)]
5748        using: Option<String>,
5749        /// Elements: (expression, operator) pairs
5750        elements: Vec<ExcludeElement>,
5751        /// INCLUDE columns
5752        #[serde(default)]
5753        include_columns: Vec<Identifier>,
5754        /// WHERE predicate
5755        #[serde(default)]
5756        where_clause: Option<Box<Expression>>,
5757        /// WITH (storage_parameters)
5758        #[serde(default)]
5759        with_params: Vec<(String, String)>,
5760        /// USING INDEX TABLESPACE tablespace_name
5761        #[serde(default)]
5762        using_index_tablespace: Option<String>,
5763        #[serde(default)]
5764        modifiers: ConstraintModifiers,
5765    },
5766    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5767    Tags(Tags),
5768    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5769    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5770    /// for all deferrable constraints in the table
5771    InitiallyDeferred {
5772        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5773        deferred: bool,
5774    },
5775}
5776
5777/// Element in an EXCLUDE constraint: expression WITH operator
5778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5779#[cfg_attr(feature = "bindings", derive(TS))]
5780pub struct ExcludeElement {
5781    /// The column expression (may include operator class, ordering, nulls)
5782    pub expression: String,
5783    /// The operator (e.g., &&, =)
5784    pub operator: String,
5785}
5786
5787/// Action for LIKE clause options
5788#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5789#[cfg_attr(feature = "bindings", derive(TS))]
5790pub enum LikeOptionAction {
5791    Including,
5792    Excluding,
5793}
5794
5795/// MATCH type for foreign keys
5796#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5797#[cfg_attr(feature = "bindings", derive(TS))]
5798pub enum MatchType {
5799    Full,
5800    Partial,
5801    Simple,
5802}
5803
5804/// Foreign key reference
5805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5806#[cfg_attr(feature = "bindings", derive(TS))]
5807pub struct ForeignKeyRef {
5808    pub table: TableRef,
5809    pub columns: Vec<Identifier>,
5810    pub on_delete: Option<ReferentialAction>,
5811    pub on_update: Option<ReferentialAction>,
5812    /// True if ON UPDATE appears before ON DELETE in the original SQL
5813    #[serde(default)]
5814    pub on_update_first: bool,
5815    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5816    #[serde(default)]
5817    pub match_type: Option<MatchType>,
5818    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5819    #[serde(default)]
5820    pub match_after_actions: bool,
5821    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5822    #[serde(default)]
5823    pub constraint_name: Option<String>,
5824    /// DEFERRABLE / NOT DEFERRABLE
5825    #[serde(default)]
5826    pub deferrable: Option<bool>,
5827    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5828    #[serde(default)]
5829    pub has_foreign_key_keywords: bool,
5830}
5831
5832/// Referential action for foreign keys
5833#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5834#[cfg_attr(feature = "bindings", derive(TS))]
5835pub enum ReferentialAction {
5836    Cascade,
5837    SetNull,
5838    SetDefault,
5839    Restrict,
5840    NoAction,
5841}
5842
5843/// DROP TABLE statement
5844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5845#[cfg_attr(feature = "bindings", derive(TS))]
5846pub struct DropTable {
5847    pub names: Vec<TableRef>,
5848    pub if_exists: bool,
5849    pub cascade: bool,
5850    /// Oracle: CASCADE CONSTRAINTS
5851    #[serde(default)]
5852    pub cascade_constraints: bool,
5853    /// Oracle: PURGE
5854    #[serde(default)]
5855    pub purge: bool,
5856    /// Comments that appear before the DROP keyword (e.g., leading line comments)
5857    #[serde(default)]
5858    pub leading_comments: Vec<String>,
5859}
5860
5861impl DropTable {
5862    pub fn new(name: impl Into<String>) -> Self {
5863        Self {
5864            names: vec![TableRef::new(name)],
5865            if_exists: false,
5866            cascade: false,
5867            cascade_constraints: false,
5868            purge: false,
5869            leading_comments: Vec::new(),
5870        }
5871    }
5872}
5873
5874/// ALTER TABLE statement
5875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5876#[cfg_attr(feature = "bindings", derive(TS))]
5877pub struct AlterTable {
5878    pub name: TableRef,
5879    pub actions: Vec<AlterTableAction>,
5880    /// IF EXISTS clause
5881    #[serde(default)]
5882    pub if_exists: bool,
5883    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5884    #[serde(default, skip_serializing_if = "Option::is_none")]
5885    pub algorithm: Option<String>,
5886    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5887    #[serde(default, skip_serializing_if = "Option::is_none")]
5888    pub lock: Option<String>,
5889    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5890    #[serde(default, skip_serializing_if = "Option::is_none")]
5891    pub with_check: Option<String>,
5892    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5893    #[serde(default, skip_serializing_if = "Option::is_none")]
5894    pub partition: Option<Vec<(Identifier, Expression)>>,
5895    /// ClickHouse: ON CLUSTER clause for distributed DDL
5896    #[serde(default, skip_serializing_if = "Option::is_none")]
5897    pub on_cluster: Option<OnCluster>,
5898}
5899
5900impl AlterTable {
5901    pub fn new(name: impl Into<String>) -> Self {
5902        Self {
5903            name: TableRef::new(name),
5904            actions: Vec::new(),
5905            if_exists: false,
5906            algorithm: None,
5907            lock: None,
5908            with_check: None,
5909            partition: None,
5910            on_cluster: None,
5911        }
5912    }
5913}
5914
5915/// Column position for ADD COLUMN (MySQL/MariaDB)
5916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5917#[cfg_attr(feature = "bindings", derive(TS))]
5918pub enum ColumnPosition {
5919    First,
5920    After(Identifier),
5921}
5922
5923/// Actions for ALTER TABLE
5924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5925#[cfg_attr(feature = "bindings", derive(TS))]
5926pub enum AlterTableAction {
5927    AddColumn {
5928        column: ColumnDef,
5929        if_not_exists: bool,
5930        position: Option<ColumnPosition>,
5931    },
5932    DropColumn {
5933        name: Identifier,
5934        if_exists: bool,
5935        cascade: bool,
5936    },
5937    RenameColumn {
5938        old_name: Identifier,
5939        new_name: Identifier,
5940        if_exists: bool,
5941    },
5942    AlterColumn {
5943        name: Identifier,
5944        action: AlterColumnAction,
5945        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5946        #[serde(default)]
5947        use_modify_keyword: bool,
5948    },
5949    RenameTable(TableRef),
5950    AddConstraint(TableConstraint),
5951    DropConstraint {
5952        name: Identifier,
5953        if_exists: bool,
5954    },
5955    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5956    DropForeignKey {
5957        name: Identifier,
5958    },
5959    /// DROP PARTITION action (Hive/BigQuery)
5960    DropPartition {
5961        /// List of partitions to drop (each partition is a list of key=value pairs)
5962        partitions: Vec<Vec<(Identifier, Expression)>>,
5963        if_exists: bool,
5964    },
5965    /// ADD PARTITION action (Hive/Spark)
5966    AddPartition {
5967        /// The partition expression
5968        partition: Expression,
5969        if_not_exists: bool,
5970        location: Option<Expression>,
5971    },
5972    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
5973    Delete {
5974        where_clause: Expression,
5975    },
5976    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
5977    SwapWith(TableRef),
5978    /// SET property action (Snowflake): ALTER TABLE t SET property=value
5979    SetProperty {
5980        properties: Vec<(String, Expression)>,
5981    },
5982    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
5983    UnsetProperty {
5984        properties: Vec<String>,
5985    },
5986    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
5987    ClusterBy {
5988        expressions: Vec<Expression>,
5989    },
5990    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
5991    SetTag {
5992        expressions: Vec<(String, Expression)>,
5993    },
5994    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
5995    UnsetTag {
5996        names: Vec<String>,
5997    },
5998    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
5999    SetOptions {
6000        expressions: Vec<Expression>,
6001    },
6002    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6003    AlterIndex {
6004        name: Identifier,
6005        visible: bool,
6006    },
6007    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6008    SetAttribute {
6009        attribute: String,
6010    },
6011    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6012    SetStageFileFormat {
6013        options: Option<Expression>,
6014    },
6015    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6016    SetStageCopyOptions {
6017        options: Option<Expression>,
6018    },
6019    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6020    AddColumns {
6021        columns: Vec<ColumnDef>,
6022        cascade: bool,
6023    },
6024    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6025    DropColumns {
6026        names: Vec<Identifier>,
6027    },
6028    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6029    /// In SingleStore, data_type can be omitted for simple column renames
6030    ChangeColumn {
6031        old_name: Identifier,
6032        new_name: Identifier,
6033        #[serde(default, skip_serializing_if = "Option::is_none")]
6034        data_type: Option<DataType>,
6035        comment: Option<String>,
6036        #[serde(default)]
6037        cascade: bool,
6038    },
6039    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6040    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6041    AlterSortKey {
6042        /// AUTO or NONE keyword
6043        this: Option<String>,
6044        /// Column list for (col1, col2) syntax
6045        expressions: Vec<Expression>,
6046        /// Whether COMPOUND keyword was present
6047        compound: bool,
6048    },
6049    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6050    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6051    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6052    AlterDistStyle {
6053        /// Distribution style: ALL, EVEN, AUTO, or KEY
6054        style: String,
6055        /// DISTKEY column (only when style is KEY)
6056        distkey: Option<Identifier>,
6057    },
6058    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6059    SetTableProperties {
6060        properties: Vec<(Expression, Expression)>,
6061    },
6062    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6063    SetLocation {
6064        location: String,
6065    },
6066    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6067    SetFileFormat {
6068        format: String,
6069    },
6070    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6071    ReplacePartition {
6072        partition: Expression,
6073        source: Option<Box<Expression>>,
6074    },
6075    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6076    Raw {
6077        sql: String,
6078    },
6079}
6080
6081/// Actions for ALTER COLUMN
6082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6083#[cfg_attr(feature = "bindings", derive(TS))]
6084pub enum AlterColumnAction {
6085    SetDataType {
6086        data_type: DataType,
6087        /// USING expression for type conversion (PostgreSQL)
6088        using: Option<Expression>,
6089        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6090        #[serde(default, skip_serializing_if = "Option::is_none")]
6091        collate: Option<String>,
6092    },
6093    SetDefault(Expression),
6094    DropDefault,
6095    SetNotNull,
6096    DropNotNull,
6097    /// Set column comment
6098    Comment(String),
6099    /// MySQL: SET VISIBLE
6100    SetVisible,
6101    /// MySQL: SET INVISIBLE
6102    SetInvisible,
6103}
6104
6105/// CREATE INDEX statement
6106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6107#[cfg_attr(feature = "bindings", derive(TS))]
6108pub struct CreateIndex {
6109    pub name: Identifier,
6110    pub table: TableRef,
6111    pub columns: Vec<IndexColumn>,
6112    pub unique: bool,
6113    pub if_not_exists: bool,
6114    pub using: Option<String>,
6115    /// TSQL CLUSTERED/NONCLUSTERED modifier
6116    #[serde(default)]
6117    pub clustered: Option<String>,
6118    /// PostgreSQL CONCURRENTLY modifier
6119    #[serde(default)]
6120    pub concurrently: bool,
6121    /// PostgreSQL WHERE clause for partial indexes
6122    #[serde(default)]
6123    pub where_clause: Option<Box<Expression>>,
6124    /// PostgreSQL INCLUDE columns
6125    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6126    pub include_columns: Vec<Identifier>,
6127    /// TSQL WITH options (e.g., allow_page_locks=on)
6128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6129    pub with_options: Vec<(String, String)>,
6130    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6131    #[serde(default)]
6132    pub on_filegroup: Option<String>,
6133}
6134
6135impl CreateIndex {
6136    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6137        Self {
6138            name: Identifier::new(name),
6139            table: TableRef::new(table),
6140            columns: Vec::new(),
6141            unique: false,
6142            if_not_exists: false,
6143            using: None,
6144            clustered: None,
6145            concurrently: false,
6146            where_clause: None,
6147            include_columns: Vec::new(),
6148            with_options: Vec::new(),
6149            on_filegroup: None,
6150        }
6151    }
6152}
6153
6154/// Index column specification
6155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6156#[cfg_attr(feature = "bindings", derive(TS))]
6157pub struct IndexColumn {
6158    pub column: Identifier,
6159    pub desc: bool,
6160    /// Explicit ASC keyword was present
6161    #[serde(default)]
6162    pub asc: bool,
6163    pub nulls_first: Option<bool>,
6164    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6165    #[serde(default, skip_serializing_if = "Option::is_none")]
6166    pub opclass: Option<String>,
6167}
6168
6169/// DROP INDEX statement
6170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6171#[cfg_attr(feature = "bindings", derive(TS))]
6172pub struct DropIndex {
6173    pub name: Identifier,
6174    pub table: Option<TableRef>,
6175    pub if_exists: bool,
6176    /// PostgreSQL CONCURRENTLY modifier
6177    #[serde(default)]
6178    pub concurrently: bool,
6179}
6180
6181impl DropIndex {
6182    pub fn new(name: impl Into<String>) -> Self {
6183        Self {
6184            name: Identifier::new(name),
6185            table: None,
6186            if_exists: false,
6187            concurrently: false,
6188        }
6189    }
6190}
6191
6192/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6194#[cfg_attr(feature = "bindings", derive(TS))]
6195pub struct ViewColumn {
6196    pub name: Identifier,
6197    pub comment: Option<String>,
6198    /// BigQuery: OPTIONS (key=value, ...) on column
6199    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6200    pub options: Vec<Expression>,
6201}
6202
6203impl ViewColumn {
6204    pub fn new(name: impl Into<String>) -> Self {
6205        Self {
6206            name: Identifier::new(name),
6207            comment: None,
6208            options: Vec::new(),
6209        }
6210    }
6211
6212    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6213        Self {
6214            name: Identifier::new(name),
6215            comment: Some(comment.into()),
6216            options: Vec::new(),
6217        }
6218    }
6219}
6220
6221/// CREATE VIEW statement
6222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6223#[cfg_attr(feature = "bindings", derive(TS))]
6224pub struct CreateView {
6225    pub name: TableRef,
6226    pub columns: Vec<ViewColumn>,
6227    pub query: Expression,
6228    pub or_replace: bool,
6229    pub if_not_exists: bool,
6230    pub materialized: bool,
6231    pub temporary: bool,
6232    /// Snowflake: SECURE VIEW
6233    #[serde(default)]
6234    pub secure: bool,
6235    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6236    #[serde(skip_serializing_if = "Option::is_none")]
6237    pub algorithm: Option<String>,
6238    /// MySQL: DEFINER=user@host
6239    #[serde(skip_serializing_if = "Option::is_none")]
6240    pub definer: Option<String>,
6241    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6242    #[serde(skip_serializing_if = "Option::is_none")]
6243    pub security: Option<FunctionSecurity>,
6244    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6245    #[serde(default = "default_true")]
6246    pub security_sql_style: bool,
6247    /// Whether the query was parenthesized: AS (SELECT ...)
6248    #[serde(default)]
6249    pub query_parenthesized: bool,
6250    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6251    #[serde(skip_serializing_if = "Option::is_none")]
6252    pub locking_mode: Option<String>,
6253    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6254    #[serde(skip_serializing_if = "Option::is_none")]
6255    pub locking_access: Option<String>,
6256    /// Snowflake: COPY GRANTS
6257    #[serde(default)]
6258    pub copy_grants: bool,
6259    /// Snowflake: COMMENT = 'text'
6260    #[serde(skip_serializing_if = "Option::is_none", default)]
6261    pub comment: Option<String>,
6262    /// Snowflake: TAG (name='value', ...)
6263    #[serde(default)]
6264    pub tags: Vec<(String, String)>,
6265    /// BigQuery: OPTIONS (key=value, ...)
6266    #[serde(default)]
6267    pub options: Vec<Expression>,
6268    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6269    #[serde(skip_serializing_if = "Option::is_none", default)]
6270    pub build: Option<String>,
6271    /// Doris: REFRESH property for materialized views
6272    #[serde(skip_serializing_if = "Option::is_none", default)]
6273    pub refresh: Option<Box<RefreshTriggerProperty>>,
6274    /// Doris: Schema with typed column definitions for materialized views
6275    /// This is used instead of `columns` when the view has typed column definitions
6276    #[serde(skip_serializing_if = "Option::is_none", default)]
6277    pub schema: Option<Box<Schema>>,
6278    /// Doris: KEY (columns) for materialized views
6279    #[serde(skip_serializing_if = "Option::is_none", default)]
6280    pub unique_key: Option<Box<UniqueKeyProperty>>,
6281    /// Redshift: WITH NO SCHEMA BINDING
6282    #[serde(default)]
6283    pub no_schema_binding: bool,
6284    /// Redshift: AUTO REFRESH YES|NO for materialized views
6285    #[serde(skip_serializing_if = "Option::is_none", default)]
6286    pub auto_refresh: Option<bool>,
6287    /// ClickHouse: ON CLUSTER clause
6288    #[serde(default, skip_serializing_if = "Option::is_none")]
6289    pub on_cluster: Option<OnCluster>,
6290    /// ClickHouse: TO destination_table
6291    #[serde(default, skip_serializing_if = "Option::is_none")]
6292    pub to_table: Option<TableRef>,
6293    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6294    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6295    pub table_properties: Vec<Expression>,
6296}
6297
6298impl CreateView {
6299    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6300        Self {
6301            name: TableRef::new(name),
6302            columns: Vec::new(),
6303            query,
6304            or_replace: false,
6305            if_not_exists: false,
6306            materialized: false,
6307            temporary: false,
6308            secure: false,
6309            algorithm: None,
6310            definer: None,
6311            security: None,
6312            security_sql_style: true,
6313            query_parenthesized: false,
6314            locking_mode: None,
6315            locking_access: None,
6316            copy_grants: false,
6317            comment: None,
6318            tags: Vec::new(),
6319            options: Vec::new(),
6320            build: None,
6321            refresh: None,
6322            schema: None,
6323            unique_key: None,
6324            no_schema_binding: false,
6325            auto_refresh: None,
6326            on_cluster: None,
6327            to_table: None,
6328            table_properties: Vec::new(),
6329        }
6330    }
6331}
6332
6333/// DROP VIEW statement
6334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6335#[cfg_attr(feature = "bindings", derive(TS))]
6336pub struct DropView {
6337    pub name: TableRef,
6338    pub if_exists: bool,
6339    pub materialized: bool,
6340}
6341
6342impl DropView {
6343    pub fn new(name: impl Into<String>) -> Self {
6344        Self {
6345            name: TableRef::new(name),
6346            if_exists: false,
6347            materialized: false,
6348        }
6349    }
6350}
6351
6352/// TRUNCATE TABLE statement
6353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6354#[cfg_attr(feature = "bindings", derive(TS))]
6355pub struct Truncate {
6356    /// Target of TRUNCATE (TABLE vs DATABASE)
6357    #[serde(default)]
6358    pub target: TruncateTarget,
6359    /// IF EXISTS clause
6360    #[serde(default)]
6361    pub if_exists: bool,
6362    pub table: TableRef,
6363    /// ClickHouse: ON CLUSTER clause for distributed DDL
6364    #[serde(default, skip_serializing_if = "Option::is_none")]
6365    pub on_cluster: Option<OnCluster>,
6366    pub cascade: bool,
6367    /// Additional tables for multi-table TRUNCATE
6368    #[serde(default)]
6369    pub extra_tables: Vec<TruncateTableEntry>,
6370    /// RESTART IDENTITY or CONTINUE IDENTITY
6371    #[serde(default)]
6372    pub identity: Option<TruncateIdentity>,
6373    /// RESTRICT option (alternative to CASCADE)
6374    #[serde(default)]
6375    pub restrict: bool,
6376    /// Hive PARTITION clause: PARTITION(key=value, ...)
6377    #[serde(default, skip_serializing_if = "Option::is_none")]
6378    pub partition: Option<Box<Expression>>,
6379}
6380
6381/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6383#[cfg_attr(feature = "bindings", derive(TS))]
6384pub struct TruncateTableEntry {
6385    pub table: TableRef,
6386    /// Whether the table has a * suffix (inherit children)
6387    #[serde(default)]
6388    pub star: bool,
6389}
6390
6391/// TRUNCATE target type
6392#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6393#[cfg_attr(feature = "bindings", derive(TS))]
6394pub enum TruncateTarget {
6395    Table,
6396    Database,
6397}
6398
6399impl Default for TruncateTarget {
6400    fn default() -> Self {
6401        TruncateTarget::Table
6402    }
6403}
6404
6405/// TRUNCATE identity option
6406#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6407#[cfg_attr(feature = "bindings", derive(TS))]
6408pub enum TruncateIdentity {
6409    Restart,
6410    Continue,
6411}
6412
6413impl Truncate {
6414    pub fn new(table: impl Into<String>) -> Self {
6415        Self {
6416            target: TruncateTarget::Table,
6417            if_exists: false,
6418            table: TableRef::new(table),
6419            on_cluster: None,
6420            cascade: false,
6421            extra_tables: Vec::new(),
6422            identity: None,
6423            restrict: false,
6424            partition: None,
6425        }
6426    }
6427}
6428
6429/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6431#[cfg_attr(feature = "bindings", derive(TS))]
6432pub struct Use {
6433    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6434    pub kind: Option<UseKind>,
6435    /// The name of the object
6436    pub this: Identifier,
6437}
6438
6439/// Kind of USE statement
6440#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6441#[cfg_attr(feature = "bindings", derive(TS))]
6442pub enum UseKind {
6443    Database,
6444    Schema,
6445    Role,
6446    Warehouse,
6447    Catalog,
6448    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6449    SecondaryRoles,
6450}
6451
6452/// SET variable statement
6453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6454#[cfg_attr(feature = "bindings", derive(TS))]
6455pub struct SetStatement {
6456    /// The items being set
6457    pub items: Vec<SetItem>,
6458}
6459
6460/// A single SET item (variable assignment)
6461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6462#[cfg_attr(feature = "bindings", derive(TS))]
6463pub struct SetItem {
6464    /// The variable name
6465    pub name: Expression,
6466    /// The value to set
6467    pub value: Expression,
6468    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6469    pub kind: Option<String>,
6470    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6471    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6472    pub no_equals: bool,
6473}
6474
6475/// CACHE TABLE statement (Spark)
6476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6477#[cfg_attr(feature = "bindings", derive(TS))]
6478pub struct Cache {
6479    /// The table to cache
6480    pub table: Identifier,
6481    /// LAZY keyword - defer caching until first use
6482    pub lazy: bool,
6483    /// Optional OPTIONS clause (key-value pairs)
6484    pub options: Vec<(Expression, Expression)>,
6485    /// Optional AS clause with query
6486    pub query: Option<Expression>,
6487}
6488
6489/// UNCACHE TABLE statement (Spark)
6490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6491#[cfg_attr(feature = "bindings", derive(TS))]
6492pub struct Uncache {
6493    /// The table to uncache
6494    pub table: Identifier,
6495    /// IF EXISTS clause
6496    pub if_exists: bool,
6497}
6498
6499/// LOAD DATA statement (Hive)
6500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6501#[cfg_attr(feature = "bindings", derive(TS))]
6502pub struct LoadData {
6503    /// LOCAL keyword - load from local filesystem
6504    pub local: bool,
6505    /// The path to load data from (INPATH value)
6506    pub inpath: String,
6507    /// Whether to overwrite existing data
6508    pub overwrite: bool,
6509    /// The target table
6510    pub table: Expression,
6511    /// Optional PARTITION clause with key-value pairs
6512    pub partition: Vec<(Identifier, Expression)>,
6513    /// Optional INPUTFORMAT clause
6514    pub input_format: Option<String>,
6515    /// Optional SERDE clause
6516    pub serde: Option<String>,
6517}
6518
6519/// PRAGMA statement (SQLite)
6520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6521#[cfg_attr(feature = "bindings", derive(TS))]
6522pub struct Pragma {
6523    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6524    pub schema: Option<Identifier>,
6525    /// The pragma name
6526    pub name: Identifier,
6527    /// Optional value for assignment (PRAGMA name = value)
6528    pub value: Option<Expression>,
6529    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6530    pub args: Vec<Expression>,
6531}
6532
6533/// A privilege with optional column list for GRANT/REVOKE
6534/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6536#[cfg_attr(feature = "bindings", derive(TS))]
6537pub struct Privilege {
6538    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6539    pub name: String,
6540    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6541    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6542    pub columns: Vec<String>,
6543}
6544
6545/// Principal in GRANT/REVOKE (user, role, etc.)
6546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6547#[cfg_attr(feature = "bindings", derive(TS))]
6548pub struct GrantPrincipal {
6549    /// The name of the principal
6550    pub name: Identifier,
6551    /// Whether prefixed with ROLE keyword
6552    pub is_role: bool,
6553    /// Whether prefixed with GROUP keyword (Redshift)
6554    #[serde(default)]
6555    pub is_group: bool,
6556}
6557
6558/// GRANT statement
6559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6560#[cfg_attr(feature = "bindings", derive(TS))]
6561pub struct Grant {
6562    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6563    pub privileges: Vec<Privilege>,
6564    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6565    pub kind: Option<String>,
6566    /// The object to grant on
6567    pub securable: Identifier,
6568    /// Function parameter types (for FUNCTION kind)
6569    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6570    pub function_params: Vec<String>,
6571    /// The grantees
6572    pub principals: Vec<GrantPrincipal>,
6573    /// WITH GRANT OPTION
6574    pub grant_option: bool,
6575    /// TSQL: AS principal (the grantor role)
6576    #[serde(default, skip_serializing_if = "Option::is_none")]
6577    pub as_principal: Option<Identifier>,
6578}
6579
6580/// REVOKE statement
6581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6582#[cfg_attr(feature = "bindings", derive(TS))]
6583pub struct Revoke {
6584    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6585    pub privileges: Vec<Privilege>,
6586    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6587    pub kind: Option<String>,
6588    /// The object to revoke from
6589    pub securable: Identifier,
6590    /// Function parameter types (for FUNCTION kind)
6591    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6592    pub function_params: Vec<String>,
6593    /// The grantees
6594    pub principals: Vec<GrantPrincipal>,
6595    /// GRANT OPTION FOR
6596    pub grant_option: bool,
6597    /// CASCADE
6598    pub cascade: bool,
6599    /// RESTRICT
6600    #[serde(default)]
6601    pub restrict: bool,
6602}
6603
6604/// COMMENT ON statement
6605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6606#[cfg_attr(feature = "bindings", derive(TS))]
6607pub struct Comment {
6608    /// The object being commented on
6609    pub this: Expression,
6610    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6611    pub kind: String,
6612    /// The comment text expression
6613    pub expression: Expression,
6614    /// IF EXISTS clause
6615    pub exists: bool,
6616    /// MATERIALIZED keyword
6617    pub materialized: bool,
6618}
6619
6620// ============================================================================
6621// Phase 4: Additional DDL Statements
6622// ============================================================================
6623
6624/// ALTER VIEW statement
6625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6626#[cfg_attr(feature = "bindings", derive(TS))]
6627pub struct AlterView {
6628    pub name: TableRef,
6629    pub actions: Vec<AlterViewAction>,
6630    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6631    #[serde(default, skip_serializing_if = "Option::is_none")]
6632    pub algorithm: Option<String>,
6633    /// MySQL: DEFINER = 'user'@'host'
6634    #[serde(default, skip_serializing_if = "Option::is_none")]
6635    pub definer: Option<String>,
6636    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6637    #[serde(default, skip_serializing_if = "Option::is_none")]
6638    pub sql_security: Option<String>,
6639    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6640    #[serde(default, skip_serializing_if = "Option::is_none")]
6641    pub with_option: Option<String>,
6642    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6643    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6644    pub columns: Vec<ViewColumn>,
6645}
6646
6647/// Actions for ALTER VIEW
6648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6649#[cfg_attr(feature = "bindings", derive(TS))]
6650pub enum AlterViewAction {
6651    /// Rename the view
6652    Rename(TableRef),
6653    /// Change owner
6654    OwnerTo(Identifier),
6655    /// Set schema
6656    SetSchema(Identifier),
6657    /// Set authorization (Trino/Presto)
6658    SetAuthorization(String),
6659    /// Alter column
6660    AlterColumn {
6661        name: Identifier,
6662        action: AlterColumnAction,
6663    },
6664    /// Redefine view as query (SELECT, UNION, etc.)
6665    AsSelect(Box<Expression>),
6666    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6667    SetTblproperties(Vec<(String, String)>),
6668    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6669    UnsetTblproperties(Vec<String>),
6670}
6671
6672impl AlterView {
6673    pub fn new(name: impl Into<String>) -> Self {
6674        Self {
6675            name: TableRef::new(name),
6676            actions: Vec::new(),
6677            algorithm: None,
6678            definer: None,
6679            sql_security: None,
6680            with_option: None,
6681            columns: Vec::new(),
6682        }
6683    }
6684}
6685
6686/// ALTER INDEX statement
6687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6688#[cfg_attr(feature = "bindings", derive(TS))]
6689pub struct AlterIndex {
6690    pub name: Identifier,
6691    pub table: Option<TableRef>,
6692    pub actions: Vec<AlterIndexAction>,
6693}
6694
6695/// Actions for ALTER INDEX
6696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6697#[cfg_attr(feature = "bindings", derive(TS))]
6698pub enum AlterIndexAction {
6699    /// Rename the index
6700    Rename(Identifier),
6701    /// Set tablespace
6702    SetTablespace(Identifier),
6703    /// Set visibility (MySQL)
6704    Visible(bool),
6705}
6706
6707impl AlterIndex {
6708    pub fn new(name: impl Into<String>) -> Self {
6709        Self {
6710            name: Identifier::new(name),
6711            table: None,
6712            actions: Vec::new(),
6713        }
6714    }
6715}
6716
6717/// CREATE SCHEMA statement
6718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6719#[cfg_attr(feature = "bindings", derive(TS))]
6720pub struct CreateSchema {
6721    pub name: Identifier,
6722    pub if_not_exists: bool,
6723    pub authorization: Option<Identifier>,
6724    #[serde(default)]
6725    pub clone_from: Option<Identifier>,
6726    /// AT/BEFORE clause for time travel (Snowflake)
6727    #[serde(default)]
6728    pub at_clause: Option<Expression>,
6729    /// Schema properties like DEFAULT COLLATE
6730    #[serde(default)]
6731    pub properties: Vec<Expression>,
6732    /// Leading comments before the statement
6733    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6734    pub leading_comments: Vec<String>,
6735}
6736
6737impl CreateSchema {
6738    pub fn new(name: impl Into<String>) -> Self {
6739        Self {
6740            name: Identifier::new(name),
6741            if_not_exists: false,
6742            authorization: None,
6743            clone_from: None,
6744            at_clause: None,
6745            properties: Vec::new(),
6746            leading_comments: Vec::new(),
6747        }
6748    }
6749}
6750
6751/// DROP SCHEMA statement
6752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6753#[cfg_attr(feature = "bindings", derive(TS))]
6754pub struct DropSchema {
6755    pub name: Identifier,
6756    pub if_exists: bool,
6757    pub cascade: bool,
6758}
6759
6760impl DropSchema {
6761    pub fn new(name: impl Into<String>) -> Self {
6762        Self {
6763            name: Identifier::new(name),
6764            if_exists: false,
6765            cascade: false,
6766        }
6767    }
6768}
6769
6770/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6772#[cfg_attr(feature = "bindings", derive(TS))]
6773pub struct DropNamespace {
6774    pub name: Identifier,
6775    pub if_exists: bool,
6776    pub cascade: bool,
6777}
6778
6779impl DropNamespace {
6780    pub fn new(name: impl Into<String>) -> Self {
6781        Self {
6782            name: Identifier::new(name),
6783            if_exists: false,
6784            cascade: false,
6785        }
6786    }
6787}
6788
6789/// CREATE DATABASE statement
6790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6791#[cfg_attr(feature = "bindings", derive(TS))]
6792pub struct CreateDatabase {
6793    pub name: Identifier,
6794    pub if_not_exists: bool,
6795    pub options: Vec<DatabaseOption>,
6796    /// Snowflake CLONE source
6797    #[serde(default)]
6798    pub clone_from: Option<Identifier>,
6799    /// AT/BEFORE clause for time travel (Snowflake)
6800    #[serde(default)]
6801    pub at_clause: Option<Expression>,
6802}
6803
6804/// Database option
6805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6806#[cfg_attr(feature = "bindings", derive(TS))]
6807pub enum DatabaseOption {
6808    CharacterSet(String),
6809    Collate(String),
6810    Owner(Identifier),
6811    Template(Identifier),
6812    Encoding(String),
6813    Location(String),
6814}
6815
6816impl CreateDatabase {
6817    pub fn new(name: impl Into<String>) -> Self {
6818        Self {
6819            name: Identifier::new(name),
6820            if_not_exists: false,
6821            options: Vec::new(),
6822            clone_from: None,
6823            at_clause: None,
6824        }
6825    }
6826}
6827
6828/// DROP DATABASE statement
6829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6830#[cfg_attr(feature = "bindings", derive(TS))]
6831pub struct DropDatabase {
6832    pub name: Identifier,
6833    pub if_exists: bool,
6834}
6835
6836impl DropDatabase {
6837    pub fn new(name: impl Into<String>) -> Self {
6838        Self {
6839            name: Identifier::new(name),
6840            if_exists: false,
6841        }
6842    }
6843}
6844
6845/// CREATE FUNCTION statement
6846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6847#[cfg_attr(feature = "bindings", derive(TS))]
6848pub struct CreateFunction {
6849    pub name: TableRef,
6850    pub parameters: Vec<FunctionParameter>,
6851    pub return_type: Option<DataType>,
6852    pub body: Option<FunctionBody>,
6853    pub or_replace: bool,
6854    pub if_not_exists: bool,
6855    pub temporary: bool,
6856    pub language: Option<String>,
6857    pub deterministic: Option<bool>,
6858    pub returns_null_on_null_input: Option<bool>,
6859    pub security: Option<FunctionSecurity>,
6860    /// Whether parentheses were present in the original syntax
6861    #[serde(default = "default_true")]
6862    pub has_parens: bool,
6863    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6864    #[serde(default)]
6865    pub sql_data_access: Option<SqlDataAccess>,
6866    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6867    #[serde(default, skip_serializing_if = "Option::is_none")]
6868    pub returns_table_body: Option<String>,
6869    /// True if LANGUAGE clause appears before RETURNS clause
6870    #[serde(default)]
6871    pub language_first: bool,
6872    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6873    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6874    pub set_options: Vec<FunctionSetOption>,
6875    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6876    #[serde(default)]
6877    pub strict: bool,
6878    /// BigQuery: OPTIONS (key=value, ...)
6879    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6880    pub options: Vec<Expression>,
6881    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6882    #[serde(default)]
6883    pub is_table_function: bool,
6884    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6885    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6886    pub property_order: Vec<FunctionPropertyKind>,
6887    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6888    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6889    pub environment: Vec<Expression>,
6890}
6891
6892/// A SET option in CREATE FUNCTION (PostgreSQL)
6893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6894#[cfg_attr(feature = "bindings", derive(TS))]
6895pub struct FunctionSetOption {
6896    pub name: String,
6897    pub value: FunctionSetValue,
6898}
6899
6900/// The value of a SET option
6901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6902#[cfg_attr(feature = "bindings", derive(TS))]
6903pub enum FunctionSetValue {
6904    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6905    Value { value: String, use_to: bool },
6906    /// SET key FROM CURRENT
6907    FromCurrent,
6908}
6909
6910/// SQL data access characteristics for functions
6911#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6912#[cfg_attr(feature = "bindings", derive(TS))]
6913pub enum SqlDataAccess {
6914    /// NO SQL
6915    NoSql,
6916    /// CONTAINS SQL
6917    ContainsSql,
6918    /// READS SQL DATA
6919    ReadsSqlData,
6920    /// MODIFIES SQL DATA
6921    ModifiesSqlData,
6922}
6923
6924/// Types of properties in CREATE FUNCTION for tracking their original order
6925#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6926#[cfg_attr(feature = "bindings", derive(TS))]
6927pub enum FunctionPropertyKind {
6928    /// SET option
6929    Set,
6930    /// AS body
6931    As,
6932    /// LANGUAGE clause
6933    Language,
6934    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6935    Determinism,
6936    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6937    NullInput,
6938    /// SECURITY DEFINER/INVOKER
6939    Security,
6940    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6941    SqlDataAccess,
6942    /// OPTIONS clause (BigQuery)
6943    Options,
6944    /// ENVIRONMENT clause (Databricks)
6945    Environment,
6946}
6947
6948/// Function parameter
6949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6950#[cfg_attr(feature = "bindings", derive(TS))]
6951pub struct FunctionParameter {
6952    pub name: Option<Identifier>,
6953    pub data_type: DataType,
6954    pub mode: Option<ParameterMode>,
6955    pub default: Option<Expression>,
6956    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
6957    #[serde(default, skip_serializing_if = "Option::is_none")]
6958    pub mode_text: Option<String>,
6959}
6960
6961/// Parameter mode (IN, OUT, INOUT, VARIADIC)
6962#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6963#[cfg_attr(feature = "bindings", derive(TS))]
6964pub enum ParameterMode {
6965    In,
6966    Out,
6967    InOut,
6968    Variadic,
6969}
6970
6971/// Function body
6972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6973#[cfg_attr(feature = "bindings", derive(TS))]
6974pub enum FunctionBody {
6975    /// AS $$ ... $$ (dollar-quoted)
6976    Block(String),
6977    /// AS 'string' (single-quoted string literal body)
6978    StringLiteral(String),
6979    /// AS 'expression'
6980    Expression(Expression),
6981    /// EXTERNAL NAME 'library'
6982    External(String),
6983    /// RETURN expression
6984    Return(Expression),
6985    /// BEGIN ... END block with parsed statements
6986    Statements(Vec<Expression>),
6987    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
6988    /// Stores (content, optional_tag)
6989    DollarQuoted {
6990        content: String,
6991        tag: Option<String>,
6992    },
6993}
6994
6995/// Function security (DEFINER, INVOKER, or NONE)
6996#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6997#[cfg_attr(feature = "bindings", derive(TS))]
6998pub enum FunctionSecurity {
6999    Definer,
7000    Invoker,
7001    /// StarRocks/MySQL: SECURITY NONE
7002    None,
7003}
7004
7005impl CreateFunction {
7006    pub fn new(name: impl Into<String>) -> Self {
7007        Self {
7008            name: TableRef::new(name),
7009            parameters: Vec::new(),
7010            return_type: None,
7011            body: None,
7012            or_replace: false,
7013            if_not_exists: false,
7014            temporary: false,
7015            language: None,
7016            deterministic: None,
7017            returns_null_on_null_input: None,
7018            security: None,
7019            has_parens: true,
7020            sql_data_access: None,
7021            returns_table_body: None,
7022            language_first: false,
7023            set_options: Vec::new(),
7024            strict: false,
7025            options: Vec::new(),
7026            is_table_function: false,
7027            property_order: Vec::new(),
7028            environment: Vec::new(),
7029        }
7030    }
7031}
7032
7033/// DROP FUNCTION statement
7034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7035#[cfg_attr(feature = "bindings", derive(TS))]
7036pub struct DropFunction {
7037    pub name: TableRef,
7038    pub parameters: Option<Vec<DataType>>,
7039    pub if_exists: bool,
7040    pub cascade: bool,
7041}
7042
7043impl DropFunction {
7044    pub fn new(name: impl Into<String>) -> Self {
7045        Self {
7046            name: TableRef::new(name),
7047            parameters: None,
7048            if_exists: false,
7049            cascade: false,
7050        }
7051    }
7052}
7053
7054/// CREATE PROCEDURE statement
7055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7056#[cfg_attr(feature = "bindings", derive(TS))]
7057pub struct CreateProcedure {
7058    pub name: TableRef,
7059    pub parameters: Vec<FunctionParameter>,
7060    pub body: Option<FunctionBody>,
7061    pub or_replace: bool,
7062    pub if_not_exists: bool,
7063    pub language: Option<String>,
7064    pub security: Option<FunctionSecurity>,
7065    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7066    #[serde(default)]
7067    pub return_type: Option<DataType>,
7068    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7069    #[serde(default)]
7070    pub execute_as: Option<String>,
7071    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7072    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7073    pub with_options: Vec<String>,
7074    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7075    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7076    pub has_parens: bool,
7077    /// Whether the short form PROC was used (instead of PROCEDURE)
7078    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7079    pub use_proc_keyword: bool,
7080}
7081
7082impl CreateProcedure {
7083    pub fn new(name: impl Into<String>) -> Self {
7084        Self {
7085            name: TableRef::new(name),
7086            parameters: Vec::new(),
7087            body: None,
7088            or_replace: false,
7089            if_not_exists: false,
7090            language: None,
7091            security: None,
7092            return_type: None,
7093            execute_as: None,
7094            with_options: Vec::new(),
7095            has_parens: true,
7096            use_proc_keyword: false,
7097        }
7098    }
7099}
7100
7101/// DROP PROCEDURE statement
7102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7103#[cfg_attr(feature = "bindings", derive(TS))]
7104pub struct DropProcedure {
7105    pub name: TableRef,
7106    pub parameters: Option<Vec<DataType>>,
7107    pub if_exists: bool,
7108    pub cascade: bool,
7109}
7110
7111impl DropProcedure {
7112    pub fn new(name: impl Into<String>) -> Self {
7113        Self {
7114            name: TableRef::new(name),
7115            parameters: None,
7116            if_exists: false,
7117            cascade: false,
7118        }
7119    }
7120}
7121
7122/// Sequence property tag for ordering
7123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7124#[cfg_attr(feature = "bindings", derive(TS))]
7125pub enum SeqPropKind {
7126    Start,
7127    Increment,
7128    Minvalue,
7129    Maxvalue,
7130    Cache,
7131    NoCache,
7132    Cycle,
7133    NoCycle,
7134    OwnedBy,
7135    Order,
7136    NoOrder,
7137    Comment,
7138    /// SHARING=<value> (Oracle)
7139    Sharing,
7140    /// KEEP (Oracle)
7141    Keep,
7142    /// NOKEEP (Oracle)
7143    NoKeep,
7144    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7145    Scale,
7146    /// NOSCALE (Oracle)
7147    NoScale,
7148    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7149    Shard,
7150    /// NOSHARD (Oracle)
7151    NoShard,
7152    /// SESSION (Oracle)
7153    Session,
7154    /// GLOBAL (Oracle)
7155    Global,
7156    /// NOCACHE (single word, Oracle)
7157    NoCacheWord,
7158    /// NOCYCLE (single word, Oracle)
7159    NoCycleWord,
7160    /// NOMINVALUE (single word, Oracle)
7161    NoMinvalueWord,
7162    /// NOMAXVALUE (single word, Oracle)
7163    NoMaxvalueWord,
7164}
7165
7166/// CREATE SEQUENCE statement
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub struct CreateSequence {
7170    pub name: TableRef,
7171    pub if_not_exists: bool,
7172    pub temporary: bool,
7173    #[serde(default)]
7174    pub or_replace: bool,
7175    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7176    #[serde(default, skip_serializing_if = "Option::is_none")]
7177    pub as_type: Option<DataType>,
7178    pub increment: Option<i64>,
7179    pub minvalue: Option<SequenceBound>,
7180    pub maxvalue: Option<SequenceBound>,
7181    pub start: Option<i64>,
7182    pub cache: Option<i64>,
7183    pub cycle: bool,
7184    pub owned_by: Option<TableRef>,
7185    /// Whether OWNED BY NONE was specified
7186    #[serde(default)]
7187    pub owned_by_none: bool,
7188    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7189    #[serde(default)]
7190    pub order: Option<bool>,
7191    /// Snowflake: COMMENT = 'value'
7192    #[serde(default)]
7193    pub comment: Option<String>,
7194    /// SHARING=<value> (Oracle)
7195    #[serde(default, skip_serializing_if = "Option::is_none")]
7196    pub sharing: Option<String>,
7197    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7198    #[serde(default, skip_serializing_if = "Option::is_none")]
7199    pub scale_modifier: Option<String>,
7200    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7201    #[serde(default, skip_serializing_if = "Option::is_none")]
7202    pub shard_modifier: Option<String>,
7203    /// Tracks the order in which properties appeared in the source
7204    #[serde(default)]
7205    pub property_order: Vec<SeqPropKind>,
7206}
7207
7208/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7210#[cfg_attr(feature = "bindings", derive(TS))]
7211pub enum SequenceBound {
7212    Value(i64),
7213    None,
7214}
7215
7216impl CreateSequence {
7217    pub fn new(name: impl Into<String>) -> Self {
7218        Self {
7219            name: TableRef::new(name),
7220            if_not_exists: false,
7221            temporary: false,
7222            or_replace: false,
7223            as_type: None,
7224            increment: None,
7225            minvalue: None,
7226            maxvalue: None,
7227            start: None,
7228            cache: None,
7229            cycle: false,
7230            owned_by: None,
7231            owned_by_none: false,
7232            order: None,
7233            comment: None,
7234            sharing: None,
7235            scale_modifier: None,
7236            shard_modifier: None,
7237            property_order: Vec::new(),
7238        }
7239    }
7240}
7241
7242/// DROP SEQUENCE statement
7243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7244#[cfg_attr(feature = "bindings", derive(TS))]
7245pub struct DropSequence {
7246    pub name: TableRef,
7247    pub if_exists: bool,
7248    pub cascade: bool,
7249}
7250
7251impl DropSequence {
7252    pub fn new(name: impl Into<String>) -> Self {
7253        Self {
7254            name: TableRef::new(name),
7255            if_exists: false,
7256            cascade: false,
7257        }
7258    }
7259}
7260
7261/// ALTER SEQUENCE statement
7262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7263#[cfg_attr(feature = "bindings", derive(TS))]
7264pub struct AlterSequence {
7265    pub name: TableRef,
7266    pub if_exists: bool,
7267    pub increment: Option<i64>,
7268    pub minvalue: Option<SequenceBound>,
7269    pub maxvalue: Option<SequenceBound>,
7270    pub start: Option<i64>,
7271    pub restart: Option<Option<i64>>,
7272    pub cache: Option<i64>,
7273    pub cycle: Option<bool>,
7274    pub owned_by: Option<Option<TableRef>>,
7275}
7276
7277impl AlterSequence {
7278    pub fn new(name: impl Into<String>) -> Self {
7279        Self {
7280            name: TableRef::new(name),
7281            if_exists: false,
7282            increment: None,
7283            minvalue: None,
7284            maxvalue: None,
7285            start: None,
7286            restart: None,
7287            cache: None,
7288            cycle: None,
7289            owned_by: None,
7290        }
7291    }
7292}
7293
7294/// CREATE TRIGGER statement
7295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7296#[cfg_attr(feature = "bindings", derive(TS))]
7297pub struct CreateTrigger {
7298    pub name: Identifier,
7299    pub table: TableRef,
7300    pub timing: TriggerTiming,
7301    pub events: Vec<TriggerEvent>,
7302    pub for_each: TriggerForEach,
7303    pub when: Option<Expression>,
7304    pub body: TriggerBody,
7305    pub or_replace: bool,
7306    pub constraint: bool,
7307    pub deferrable: Option<bool>,
7308    pub initially_deferred: Option<bool>,
7309    pub referencing: Option<TriggerReferencing>,
7310}
7311
7312/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7313#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7314#[cfg_attr(feature = "bindings", derive(TS))]
7315pub enum TriggerTiming {
7316    Before,
7317    After,
7318    InsteadOf,
7319}
7320
7321/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7323#[cfg_attr(feature = "bindings", derive(TS))]
7324pub enum TriggerEvent {
7325    Insert,
7326    Update(Option<Vec<Identifier>>),
7327    Delete,
7328    Truncate,
7329}
7330
7331/// Trigger FOR EACH clause
7332#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7333#[cfg_attr(feature = "bindings", derive(TS))]
7334pub enum TriggerForEach {
7335    Row,
7336    Statement,
7337}
7338
7339/// Trigger body
7340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7341#[cfg_attr(feature = "bindings", derive(TS))]
7342pub enum TriggerBody {
7343    /// EXECUTE FUNCTION/PROCEDURE name(args)
7344    Execute {
7345        function: TableRef,
7346        args: Vec<Expression>,
7347    },
7348    /// BEGIN ... END block
7349    Block(String),
7350}
7351
7352/// Trigger REFERENCING clause
7353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7354#[cfg_attr(feature = "bindings", derive(TS))]
7355pub struct TriggerReferencing {
7356    pub old_table: Option<Identifier>,
7357    pub new_table: Option<Identifier>,
7358    pub old_row: Option<Identifier>,
7359    pub new_row: Option<Identifier>,
7360}
7361
7362impl CreateTrigger {
7363    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7364        Self {
7365            name: Identifier::new(name),
7366            table: TableRef::new(table),
7367            timing: TriggerTiming::Before,
7368            events: Vec::new(),
7369            for_each: TriggerForEach::Row,
7370            when: None,
7371            body: TriggerBody::Execute {
7372                function: TableRef::new(""),
7373                args: Vec::new(),
7374            },
7375            or_replace: false,
7376            constraint: false,
7377            deferrable: None,
7378            initially_deferred: None,
7379            referencing: None,
7380        }
7381    }
7382}
7383
7384/// DROP TRIGGER statement
7385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7386#[cfg_attr(feature = "bindings", derive(TS))]
7387pub struct DropTrigger {
7388    pub name: Identifier,
7389    pub table: Option<TableRef>,
7390    pub if_exists: bool,
7391    pub cascade: bool,
7392}
7393
7394impl DropTrigger {
7395    pub fn new(name: impl Into<String>) -> Self {
7396        Self {
7397            name: Identifier::new(name),
7398            table: None,
7399            if_exists: false,
7400            cascade: false,
7401        }
7402    }
7403}
7404
7405/// CREATE TYPE statement
7406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7407#[cfg_attr(feature = "bindings", derive(TS))]
7408pub struct CreateType {
7409    pub name: TableRef,
7410    pub definition: TypeDefinition,
7411    pub if_not_exists: bool,
7412}
7413
7414/// Type definition
7415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7416#[cfg_attr(feature = "bindings", derive(TS))]
7417pub enum TypeDefinition {
7418    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7419    Enum(Vec<String>),
7420    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7421    Composite(Vec<TypeAttribute>),
7422    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7423    Range {
7424        subtype: DataType,
7425        subtype_diff: Option<String>,
7426        canonical: Option<String>,
7427    },
7428    /// Base type (for advanced usage)
7429    Base {
7430        input: String,
7431        output: String,
7432        internallength: Option<i32>,
7433    },
7434    /// Domain type
7435    Domain {
7436        base_type: DataType,
7437        default: Option<Expression>,
7438        constraints: Vec<DomainConstraint>,
7439    },
7440}
7441
7442/// Type attribute for composite types
7443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7444#[cfg_attr(feature = "bindings", derive(TS))]
7445pub struct TypeAttribute {
7446    pub name: Identifier,
7447    pub data_type: DataType,
7448    pub collate: Option<Identifier>,
7449}
7450
7451/// Domain constraint
7452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7453#[cfg_attr(feature = "bindings", derive(TS))]
7454pub struct DomainConstraint {
7455    pub name: Option<Identifier>,
7456    pub check: Expression,
7457}
7458
7459impl CreateType {
7460    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7461        Self {
7462            name: TableRef::new(name),
7463            definition: TypeDefinition::Enum(values),
7464            if_not_exists: false,
7465        }
7466    }
7467
7468    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7469        Self {
7470            name: TableRef::new(name),
7471            definition: TypeDefinition::Composite(attributes),
7472            if_not_exists: false,
7473        }
7474    }
7475}
7476
7477/// DROP TYPE statement
7478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7479#[cfg_attr(feature = "bindings", derive(TS))]
7480pub struct DropType {
7481    pub name: TableRef,
7482    pub if_exists: bool,
7483    pub cascade: bool,
7484}
7485
7486impl DropType {
7487    pub fn new(name: impl Into<String>) -> Self {
7488        Self {
7489            name: TableRef::new(name),
7490            if_exists: false,
7491            cascade: false,
7492        }
7493    }
7494}
7495
7496/// DESCRIBE statement - shows table structure or query plan
7497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7498#[cfg_attr(feature = "bindings", derive(TS))]
7499pub struct Describe {
7500    /// The target to describe (table name or query)
7501    pub target: Expression,
7502    /// EXTENDED format
7503    pub extended: bool,
7504    /// FORMATTED format
7505    pub formatted: bool,
7506    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7507    #[serde(default)]
7508    pub kind: Option<String>,
7509    /// Properties like type=stage
7510    #[serde(default)]
7511    pub properties: Vec<(String, String)>,
7512    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7513    #[serde(default, skip_serializing_if = "Option::is_none")]
7514    pub style: Option<String>,
7515    /// Partition specification for DESCRIBE PARTITION
7516    #[serde(default)]
7517    pub partition: Option<Box<Expression>>,
7518    /// Leading comments before the statement
7519    #[serde(default)]
7520    pub leading_comments: Vec<String>,
7521    /// AS JSON suffix (Databricks)
7522    #[serde(default)]
7523    pub as_json: bool,
7524}
7525
7526impl Describe {
7527    pub fn new(target: Expression) -> Self {
7528        Self {
7529            target,
7530            extended: false,
7531            formatted: false,
7532            kind: None,
7533            properties: Vec::new(),
7534            style: None,
7535            partition: None,
7536            leading_comments: Vec::new(),
7537            as_json: false,
7538        }
7539    }
7540}
7541
7542/// SHOW statement - displays database objects
7543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7544#[cfg_attr(feature = "bindings", derive(TS))]
7545pub struct Show {
7546    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7547    pub this: String,
7548    /// Whether TERSE was specified
7549    #[serde(default)]
7550    pub terse: bool,
7551    /// Whether HISTORY was specified
7552    #[serde(default)]
7553    pub history: bool,
7554    /// LIKE pattern
7555    pub like: Option<Expression>,
7556    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7557    pub scope_kind: Option<String>,
7558    /// IN scope object
7559    pub scope: Option<Expression>,
7560    /// STARTS WITH pattern
7561    pub starts_with: Option<Expression>,
7562    /// LIMIT clause
7563    pub limit: Option<Box<Limit>>,
7564    /// FROM clause (for specific object)
7565    pub from: Option<Expression>,
7566    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7567    #[serde(default, skip_serializing_if = "Option::is_none")]
7568    pub where_clause: Option<Expression>,
7569    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7570    #[serde(default, skip_serializing_if = "Option::is_none")]
7571    pub for_target: Option<Expression>,
7572    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7573    #[serde(default, skip_serializing_if = "Option::is_none")]
7574    pub db: Option<Expression>,
7575    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7576    #[serde(default, skip_serializing_if = "Option::is_none")]
7577    pub target: Option<Expression>,
7578    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7579    #[serde(default, skip_serializing_if = "Option::is_none")]
7580    pub mutex: Option<bool>,
7581    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7582    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7583    pub privileges: Vec<String>,
7584}
7585
7586impl Show {
7587    pub fn new(this: impl Into<String>) -> Self {
7588        Self {
7589            this: this.into(),
7590            terse: false,
7591            history: false,
7592            like: None,
7593            scope_kind: None,
7594            scope: None,
7595            starts_with: None,
7596            limit: None,
7597            from: None,
7598            where_clause: None,
7599            for_target: None,
7600            db: None,
7601            target: None,
7602            mutex: None,
7603            privileges: Vec::new(),
7604        }
7605    }
7606}
7607
7608/// Represent an explicit parenthesized expression for grouping precedence.
7609///
7610/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7611/// correctly instead of being flattened to `a + b * c`.
7612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7613#[cfg_attr(feature = "bindings", derive(TS))]
7614pub struct Paren {
7615    /// The inner expression wrapped by parentheses.
7616    pub this: Expression,
7617    #[serde(default)]
7618    pub trailing_comments: Vec<String>,
7619}
7620
7621/// Expression annotated with trailing comments (for round-trip preservation)
7622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7623#[cfg_attr(feature = "bindings", derive(TS))]
7624pub struct Annotated {
7625    pub this: Expression,
7626    pub trailing_comments: Vec<String>,
7627}
7628
7629// === BATCH GENERATED STRUCT DEFINITIONS ===
7630// Generated from Python sqlglot expressions.py
7631
7632/// Refresh
7633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7634#[cfg_attr(feature = "bindings", derive(TS))]
7635pub struct Refresh {
7636    pub this: Box<Expression>,
7637    pub kind: String,
7638}
7639
7640/// LockingStatement
7641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7642#[cfg_attr(feature = "bindings", derive(TS))]
7643pub struct LockingStatement {
7644    pub this: Box<Expression>,
7645    pub expression: Box<Expression>,
7646}
7647
7648/// SequenceProperties
7649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7650#[cfg_attr(feature = "bindings", derive(TS))]
7651pub struct SequenceProperties {
7652    #[serde(default)]
7653    pub increment: Option<Box<Expression>>,
7654    #[serde(default)]
7655    pub minvalue: Option<Box<Expression>>,
7656    #[serde(default)]
7657    pub maxvalue: Option<Box<Expression>>,
7658    #[serde(default)]
7659    pub cache: Option<Box<Expression>>,
7660    #[serde(default)]
7661    pub start: Option<Box<Expression>>,
7662    #[serde(default)]
7663    pub owned: Option<Box<Expression>>,
7664    #[serde(default)]
7665    pub options: Vec<Expression>,
7666}
7667
7668/// TruncateTable
7669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7670#[cfg_attr(feature = "bindings", derive(TS))]
7671pub struct TruncateTable {
7672    #[serde(default)]
7673    pub expressions: Vec<Expression>,
7674    #[serde(default)]
7675    pub is_database: Option<Box<Expression>>,
7676    #[serde(default)]
7677    pub exists: bool,
7678    #[serde(default)]
7679    pub only: Option<Box<Expression>>,
7680    #[serde(default)]
7681    pub cluster: Option<Box<Expression>>,
7682    #[serde(default)]
7683    pub identity: Option<Box<Expression>>,
7684    #[serde(default)]
7685    pub option: Option<Box<Expression>>,
7686    #[serde(default)]
7687    pub partition: Option<Box<Expression>>,
7688}
7689
7690/// Clone
7691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7692#[cfg_attr(feature = "bindings", derive(TS))]
7693pub struct Clone {
7694    pub this: Box<Expression>,
7695    #[serde(default)]
7696    pub shallow: Option<Box<Expression>>,
7697    #[serde(default)]
7698    pub copy: Option<Box<Expression>>,
7699}
7700
7701/// Attach
7702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7703#[cfg_attr(feature = "bindings", derive(TS))]
7704pub struct Attach {
7705    pub this: Box<Expression>,
7706    #[serde(default)]
7707    pub exists: bool,
7708    #[serde(default)]
7709    pub expressions: Vec<Expression>,
7710}
7711
7712/// Detach
7713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7714#[cfg_attr(feature = "bindings", derive(TS))]
7715pub struct Detach {
7716    pub this: Box<Expression>,
7717    #[serde(default)]
7718    pub exists: bool,
7719}
7720
7721/// Install
7722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7723#[cfg_attr(feature = "bindings", derive(TS))]
7724pub struct Install {
7725    pub this: Box<Expression>,
7726    #[serde(default)]
7727    pub from_: Option<Box<Expression>>,
7728    #[serde(default)]
7729    pub force: Option<Box<Expression>>,
7730}
7731
7732/// Summarize
7733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7734#[cfg_attr(feature = "bindings", derive(TS))]
7735pub struct Summarize {
7736    pub this: Box<Expression>,
7737    #[serde(default)]
7738    pub table: Option<Box<Expression>>,
7739}
7740
7741/// Declare
7742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7743#[cfg_attr(feature = "bindings", derive(TS))]
7744pub struct Declare {
7745    #[serde(default)]
7746    pub expressions: Vec<Expression>,
7747}
7748
7749/// DeclareItem
7750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7751#[cfg_attr(feature = "bindings", derive(TS))]
7752pub struct DeclareItem {
7753    pub this: Box<Expression>,
7754    #[serde(default)]
7755    pub kind: Option<String>,
7756    #[serde(default)]
7757    pub default: Option<Box<Expression>>,
7758    #[serde(default)]
7759    pub has_as: bool,
7760    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7761    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7762    pub additional_names: Vec<Expression>,
7763}
7764
7765/// Set
7766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7767#[cfg_attr(feature = "bindings", derive(TS))]
7768pub struct Set {
7769    #[serde(default)]
7770    pub expressions: Vec<Expression>,
7771    #[serde(default)]
7772    pub unset: Option<Box<Expression>>,
7773    #[serde(default)]
7774    pub tag: Option<Box<Expression>>,
7775}
7776
7777/// Heredoc
7778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7779#[cfg_attr(feature = "bindings", derive(TS))]
7780pub struct Heredoc {
7781    pub this: Box<Expression>,
7782    #[serde(default)]
7783    pub tag: Option<Box<Expression>>,
7784}
7785
7786/// QueryBand
7787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7788#[cfg_attr(feature = "bindings", derive(TS))]
7789pub struct QueryBand {
7790    pub this: Box<Expression>,
7791    #[serde(default)]
7792    pub scope: Option<Box<Expression>>,
7793    #[serde(default)]
7794    pub update: Option<Box<Expression>>,
7795}
7796
7797/// UserDefinedFunction
7798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7799#[cfg_attr(feature = "bindings", derive(TS))]
7800pub struct UserDefinedFunction {
7801    pub this: Box<Expression>,
7802    #[serde(default)]
7803    pub expressions: Vec<Expression>,
7804    #[serde(default)]
7805    pub wrapped: Option<Box<Expression>>,
7806}
7807
7808/// RecursiveWithSearch
7809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7810#[cfg_attr(feature = "bindings", derive(TS))]
7811pub struct RecursiveWithSearch {
7812    pub kind: String,
7813    pub this: Box<Expression>,
7814    pub expression: Box<Expression>,
7815    #[serde(default)]
7816    pub using: Option<Box<Expression>>,
7817}
7818
7819/// ProjectionDef
7820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7821#[cfg_attr(feature = "bindings", derive(TS))]
7822pub struct ProjectionDef {
7823    pub this: Box<Expression>,
7824    pub expression: Box<Expression>,
7825}
7826
7827/// TableAlias
7828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7829#[cfg_attr(feature = "bindings", derive(TS))]
7830pub struct TableAlias {
7831    #[serde(default)]
7832    pub this: Option<Box<Expression>>,
7833    #[serde(default)]
7834    pub columns: Vec<Expression>,
7835}
7836
7837/// ByteString
7838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7839#[cfg_attr(feature = "bindings", derive(TS))]
7840pub struct ByteString {
7841    pub this: Box<Expression>,
7842    #[serde(default)]
7843    pub is_bytes: Option<Box<Expression>>,
7844}
7845
7846/// HexStringExpr - Hex string expression (not literal)
7847/// BigQuery: converts to FROM_HEX(this)
7848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7849#[cfg_attr(feature = "bindings", derive(TS))]
7850pub struct HexStringExpr {
7851    pub this: Box<Expression>,
7852    #[serde(default)]
7853    pub is_integer: Option<bool>,
7854}
7855
7856/// UnicodeString
7857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7858#[cfg_attr(feature = "bindings", derive(TS))]
7859pub struct UnicodeString {
7860    pub this: Box<Expression>,
7861    #[serde(default)]
7862    pub escape: Option<Box<Expression>>,
7863}
7864
7865/// AlterColumn
7866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7867#[cfg_attr(feature = "bindings", derive(TS))]
7868pub struct AlterColumn {
7869    pub this: Box<Expression>,
7870    #[serde(default)]
7871    pub dtype: Option<Box<Expression>>,
7872    #[serde(default)]
7873    pub collate: Option<Box<Expression>>,
7874    #[serde(default)]
7875    pub using: Option<Box<Expression>>,
7876    #[serde(default)]
7877    pub default: Option<Box<Expression>>,
7878    #[serde(default)]
7879    pub drop: Option<Box<Expression>>,
7880    #[serde(default)]
7881    pub comment: Option<Box<Expression>>,
7882    #[serde(default)]
7883    pub allow_null: Option<Box<Expression>>,
7884    #[serde(default)]
7885    pub visible: Option<Box<Expression>>,
7886    #[serde(default)]
7887    pub rename_to: Option<Box<Expression>>,
7888}
7889
7890/// AlterSortKey
7891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7892#[cfg_attr(feature = "bindings", derive(TS))]
7893pub struct AlterSortKey {
7894    #[serde(default)]
7895    pub this: Option<Box<Expression>>,
7896    #[serde(default)]
7897    pub expressions: Vec<Expression>,
7898    #[serde(default)]
7899    pub compound: Option<Box<Expression>>,
7900}
7901
7902/// AlterSet
7903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7904#[cfg_attr(feature = "bindings", derive(TS))]
7905pub struct AlterSet {
7906    #[serde(default)]
7907    pub expressions: Vec<Expression>,
7908    #[serde(default)]
7909    pub option: Option<Box<Expression>>,
7910    #[serde(default)]
7911    pub tablespace: Option<Box<Expression>>,
7912    #[serde(default)]
7913    pub access_method: Option<Box<Expression>>,
7914    #[serde(default)]
7915    pub file_format: Option<Box<Expression>>,
7916    #[serde(default)]
7917    pub copy_options: Option<Box<Expression>>,
7918    #[serde(default)]
7919    pub tag: Option<Box<Expression>>,
7920    #[serde(default)]
7921    pub location: Option<Box<Expression>>,
7922    #[serde(default)]
7923    pub serde: Option<Box<Expression>>,
7924}
7925
7926/// RenameColumn
7927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7928#[cfg_attr(feature = "bindings", derive(TS))]
7929pub struct RenameColumn {
7930    pub this: Box<Expression>,
7931    #[serde(default)]
7932    pub to: Option<Box<Expression>>,
7933    #[serde(default)]
7934    pub exists: bool,
7935}
7936
7937/// Comprehension
7938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7939#[cfg_attr(feature = "bindings", derive(TS))]
7940pub struct Comprehension {
7941    pub this: Box<Expression>,
7942    pub expression: Box<Expression>,
7943    #[serde(default)]
7944    pub position: Option<Box<Expression>>,
7945    #[serde(default)]
7946    pub iterator: Option<Box<Expression>>,
7947    #[serde(default)]
7948    pub condition: Option<Box<Expression>>,
7949}
7950
7951/// MergeTreeTTLAction
7952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7953#[cfg_attr(feature = "bindings", derive(TS))]
7954pub struct MergeTreeTTLAction {
7955    pub this: Box<Expression>,
7956    #[serde(default)]
7957    pub delete: Option<Box<Expression>>,
7958    #[serde(default)]
7959    pub recompress: Option<Box<Expression>>,
7960    #[serde(default)]
7961    pub to_disk: Option<Box<Expression>>,
7962    #[serde(default)]
7963    pub to_volume: Option<Box<Expression>>,
7964}
7965
7966/// MergeTreeTTL
7967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7968#[cfg_attr(feature = "bindings", derive(TS))]
7969pub struct MergeTreeTTL {
7970    #[serde(default)]
7971    pub expressions: Vec<Expression>,
7972    #[serde(default)]
7973    pub where_: Option<Box<Expression>>,
7974    #[serde(default)]
7975    pub group: Option<Box<Expression>>,
7976    #[serde(default)]
7977    pub aggregates: Option<Box<Expression>>,
7978}
7979
7980/// IndexConstraintOption
7981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7982#[cfg_attr(feature = "bindings", derive(TS))]
7983pub struct IndexConstraintOption {
7984    #[serde(default)]
7985    pub key_block_size: Option<Box<Expression>>,
7986    #[serde(default)]
7987    pub using: Option<Box<Expression>>,
7988    #[serde(default)]
7989    pub parser: Option<Box<Expression>>,
7990    #[serde(default)]
7991    pub comment: Option<Box<Expression>>,
7992    #[serde(default)]
7993    pub visible: Option<Box<Expression>>,
7994    #[serde(default)]
7995    pub engine_attr: Option<Box<Expression>>,
7996    #[serde(default)]
7997    pub secondary_engine_attr: Option<Box<Expression>>,
7998}
7999
8000/// PeriodForSystemTimeConstraint
8001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8002#[cfg_attr(feature = "bindings", derive(TS))]
8003pub struct PeriodForSystemTimeConstraint {
8004    pub this: Box<Expression>,
8005    pub expression: Box<Expression>,
8006}
8007
8008/// CaseSpecificColumnConstraint
8009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8010#[cfg_attr(feature = "bindings", derive(TS))]
8011pub struct CaseSpecificColumnConstraint {
8012    #[serde(default)]
8013    pub not_: Option<Box<Expression>>,
8014}
8015
8016/// CharacterSetColumnConstraint
8017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8018#[cfg_attr(feature = "bindings", derive(TS))]
8019pub struct CharacterSetColumnConstraint {
8020    pub this: Box<Expression>,
8021}
8022
8023/// CheckColumnConstraint
8024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8025#[cfg_attr(feature = "bindings", derive(TS))]
8026pub struct CheckColumnConstraint {
8027    pub this: Box<Expression>,
8028    #[serde(default)]
8029    pub enforced: Option<Box<Expression>>,
8030}
8031
8032/// CompressColumnConstraint
8033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8034#[cfg_attr(feature = "bindings", derive(TS))]
8035pub struct CompressColumnConstraint {
8036    #[serde(default)]
8037    pub this: Option<Box<Expression>>,
8038}
8039
8040/// DateFormatColumnConstraint
8041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8042#[cfg_attr(feature = "bindings", derive(TS))]
8043pub struct DateFormatColumnConstraint {
8044    pub this: Box<Expression>,
8045}
8046
8047/// EphemeralColumnConstraint
8048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8049#[cfg_attr(feature = "bindings", derive(TS))]
8050pub struct EphemeralColumnConstraint {
8051    #[serde(default)]
8052    pub this: Option<Box<Expression>>,
8053}
8054
8055/// WithOperator
8056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8057#[cfg_attr(feature = "bindings", derive(TS))]
8058pub struct WithOperator {
8059    pub this: Box<Expression>,
8060    pub op: String,
8061}
8062
8063/// GeneratedAsIdentityColumnConstraint
8064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8065#[cfg_attr(feature = "bindings", derive(TS))]
8066pub struct GeneratedAsIdentityColumnConstraint {
8067    #[serde(default)]
8068    pub this: Option<Box<Expression>>,
8069    #[serde(default)]
8070    pub expression: Option<Box<Expression>>,
8071    #[serde(default)]
8072    pub on_null: Option<Box<Expression>>,
8073    #[serde(default)]
8074    pub start: Option<Box<Expression>>,
8075    #[serde(default)]
8076    pub increment: Option<Box<Expression>>,
8077    #[serde(default)]
8078    pub minvalue: Option<Box<Expression>>,
8079    #[serde(default)]
8080    pub maxvalue: Option<Box<Expression>>,
8081    #[serde(default)]
8082    pub cycle: Option<Box<Expression>>,
8083    #[serde(default)]
8084    pub order: Option<Box<Expression>>,
8085}
8086
8087/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8088/// TSQL: outputs "IDENTITY"
8089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8090#[cfg_attr(feature = "bindings", derive(TS))]
8091pub struct AutoIncrementColumnConstraint;
8092
8093/// CommentColumnConstraint - Column comment marker
8094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8095#[cfg_attr(feature = "bindings", derive(TS))]
8096pub struct CommentColumnConstraint;
8097
8098/// GeneratedAsRowColumnConstraint
8099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8100#[cfg_attr(feature = "bindings", derive(TS))]
8101pub struct GeneratedAsRowColumnConstraint {
8102    #[serde(default)]
8103    pub start: Option<Box<Expression>>,
8104    #[serde(default)]
8105    pub hidden: Option<Box<Expression>>,
8106}
8107
8108/// IndexColumnConstraint
8109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8110#[cfg_attr(feature = "bindings", derive(TS))]
8111pub struct IndexColumnConstraint {
8112    #[serde(default)]
8113    pub this: Option<Box<Expression>>,
8114    #[serde(default)]
8115    pub expressions: Vec<Expression>,
8116    #[serde(default)]
8117    pub kind: Option<String>,
8118    #[serde(default)]
8119    pub index_type: Option<Box<Expression>>,
8120    #[serde(default)]
8121    pub options: Vec<Expression>,
8122    #[serde(default)]
8123    pub expression: Option<Box<Expression>>,
8124    #[serde(default)]
8125    pub granularity: Option<Box<Expression>>,
8126}
8127
8128/// MaskingPolicyColumnConstraint
8129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8130#[cfg_attr(feature = "bindings", derive(TS))]
8131pub struct MaskingPolicyColumnConstraint {
8132    pub this: Box<Expression>,
8133    #[serde(default)]
8134    pub expressions: Vec<Expression>,
8135}
8136
8137/// NotNullColumnConstraint
8138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8139#[cfg_attr(feature = "bindings", derive(TS))]
8140pub struct NotNullColumnConstraint {
8141    #[serde(default)]
8142    pub allow_null: Option<Box<Expression>>,
8143}
8144
8145/// DefaultColumnConstraint - DEFAULT value for a column
8146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8147#[cfg_attr(feature = "bindings", derive(TS))]
8148pub struct DefaultColumnConstraint {
8149    pub this: Box<Expression>,
8150}
8151
8152/// PrimaryKeyColumnConstraint
8153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8154#[cfg_attr(feature = "bindings", derive(TS))]
8155pub struct PrimaryKeyColumnConstraint {
8156    #[serde(default)]
8157    pub desc: Option<Box<Expression>>,
8158    #[serde(default)]
8159    pub options: Vec<Expression>,
8160}
8161
8162/// UniqueColumnConstraint
8163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8164#[cfg_attr(feature = "bindings", derive(TS))]
8165pub struct UniqueColumnConstraint {
8166    #[serde(default)]
8167    pub this: Option<Box<Expression>>,
8168    #[serde(default)]
8169    pub index_type: Option<Box<Expression>>,
8170    #[serde(default)]
8171    pub on_conflict: Option<Box<Expression>>,
8172    #[serde(default)]
8173    pub nulls: Option<Box<Expression>>,
8174    #[serde(default)]
8175    pub options: Vec<Expression>,
8176}
8177
8178/// WatermarkColumnConstraint
8179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8180#[cfg_attr(feature = "bindings", derive(TS))]
8181pub struct WatermarkColumnConstraint {
8182    pub this: Box<Expression>,
8183    pub expression: Box<Expression>,
8184}
8185
8186/// ComputedColumnConstraint
8187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8188#[cfg_attr(feature = "bindings", derive(TS))]
8189pub struct ComputedColumnConstraint {
8190    pub this: Box<Expression>,
8191    #[serde(default)]
8192    pub persisted: Option<Box<Expression>>,
8193    #[serde(default)]
8194    pub not_null: Option<Box<Expression>>,
8195    #[serde(default)]
8196    pub data_type: Option<Box<Expression>>,
8197}
8198
8199/// InOutColumnConstraint
8200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8201#[cfg_attr(feature = "bindings", derive(TS))]
8202pub struct InOutColumnConstraint {
8203    #[serde(default)]
8204    pub input_: Option<Box<Expression>>,
8205    #[serde(default)]
8206    pub output: Option<Box<Expression>>,
8207}
8208
8209/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8211#[cfg_attr(feature = "bindings", derive(TS))]
8212pub struct PathColumnConstraint {
8213    pub this: Box<Expression>,
8214}
8215
8216/// Constraint
8217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8218#[cfg_attr(feature = "bindings", derive(TS))]
8219pub struct Constraint {
8220    pub this: Box<Expression>,
8221    #[serde(default)]
8222    pub expressions: Vec<Expression>,
8223}
8224
8225/// Export
8226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8227#[cfg_attr(feature = "bindings", derive(TS))]
8228pub struct Export {
8229    pub this: Box<Expression>,
8230    #[serde(default)]
8231    pub connection: Option<Box<Expression>>,
8232    #[serde(default)]
8233    pub options: Vec<Expression>,
8234}
8235
8236/// Filter
8237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8238#[cfg_attr(feature = "bindings", derive(TS))]
8239pub struct Filter {
8240    pub this: Box<Expression>,
8241    pub expression: Box<Expression>,
8242}
8243
8244/// Changes
8245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8246#[cfg_attr(feature = "bindings", derive(TS))]
8247pub struct Changes {
8248    #[serde(default)]
8249    pub information: Option<Box<Expression>>,
8250    #[serde(default)]
8251    pub at_before: Option<Box<Expression>>,
8252    #[serde(default)]
8253    pub end: Option<Box<Expression>>,
8254}
8255
8256/// Directory
8257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8258#[cfg_attr(feature = "bindings", derive(TS))]
8259pub struct Directory {
8260    pub this: Box<Expression>,
8261    #[serde(default)]
8262    pub local: Option<Box<Expression>>,
8263    #[serde(default)]
8264    pub row_format: Option<Box<Expression>>,
8265}
8266
8267/// ForeignKey
8268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8269#[cfg_attr(feature = "bindings", derive(TS))]
8270pub struct ForeignKey {
8271    #[serde(default)]
8272    pub expressions: Vec<Expression>,
8273    #[serde(default)]
8274    pub reference: Option<Box<Expression>>,
8275    #[serde(default)]
8276    pub delete: Option<Box<Expression>>,
8277    #[serde(default)]
8278    pub update: Option<Box<Expression>>,
8279    #[serde(default)]
8280    pub options: Vec<Expression>,
8281}
8282
8283/// ColumnPrefix
8284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8285#[cfg_attr(feature = "bindings", derive(TS))]
8286pub struct ColumnPrefix {
8287    pub this: Box<Expression>,
8288    pub expression: Box<Expression>,
8289}
8290
8291/// PrimaryKey
8292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8293#[cfg_attr(feature = "bindings", derive(TS))]
8294pub struct PrimaryKey {
8295    #[serde(default)]
8296    pub this: Option<Box<Expression>>,
8297    #[serde(default)]
8298    pub expressions: Vec<Expression>,
8299    #[serde(default)]
8300    pub options: Vec<Expression>,
8301    #[serde(default)]
8302    pub include: Option<Box<Expression>>,
8303}
8304
8305/// Into
8306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8307#[cfg_attr(feature = "bindings", derive(TS))]
8308pub struct IntoClause {
8309    #[serde(default)]
8310    pub this: Option<Box<Expression>>,
8311    #[serde(default)]
8312    pub temporary: bool,
8313    #[serde(default)]
8314    pub unlogged: Option<Box<Expression>>,
8315    #[serde(default)]
8316    pub bulk_collect: Option<Box<Expression>>,
8317    #[serde(default)]
8318    pub expressions: Vec<Expression>,
8319}
8320
8321/// JoinHint
8322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8323#[cfg_attr(feature = "bindings", derive(TS))]
8324pub struct JoinHint {
8325    pub this: Box<Expression>,
8326    #[serde(default)]
8327    pub expressions: Vec<Expression>,
8328}
8329
8330/// Opclass
8331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8332#[cfg_attr(feature = "bindings", derive(TS))]
8333pub struct Opclass {
8334    pub this: Box<Expression>,
8335    pub expression: Box<Expression>,
8336}
8337
8338/// Index
8339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8340#[cfg_attr(feature = "bindings", derive(TS))]
8341pub struct Index {
8342    #[serde(default)]
8343    pub this: Option<Box<Expression>>,
8344    #[serde(default)]
8345    pub table: Option<Box<Expression>>,
8346    #[serde(default)]
8347    pub unique: bool,
8348    #[serde(default)]
8349    pub primary: Option<Box<Expression>>,
8350    #[serde(default)]
8351    pub amp: Option<Box<Expression>>,
8352    #[serde(default)]
8353    pub params: Vec<Expression>,
8354}
8355
8356/// IndexParameters
8357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8358#[cfg_attr(feature = "bindings", derive(TS))]
8359pub struct IndexParameters {
8360    #[serde(default)]
8361    pub using: Option<Box<Expression>>,
8362    #[serde(default)]
8363    pub include: Option<Box<Expression>>,
8364    #[serde(default)]
8365    pub columns: Vec<Expression>,
8366    #[serde(default)]
8367    pub with_storage: Option<Box<Expression>>,
8368    #[serde(default)]
8369    pub partition_by: Option<Box<Expression>>,
8370    #[serde(default)]
8371    pub tablespace: Option<Box<Expression>>,
8372    #[serde(default)]
8373    pub where_: Option<Box<Expression>>,
8374    #[serde(default)]
8375    pub on: Option<Box<Expression>>,
8376}
8377
8378/// ConditionalInsert
8379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8380#[cfg_attr(feature = "bindings", derive(TS))]
8381pub struct ConditionalInsert {
8382    pub this: Box<Expression>,
8383    #[serde(default)]
8384    pub expression: Option<Box<Expression>>,
8385    #[serde(default)]
8386    pub else_: Option<Box<Expression>>,
8387}
8388
8389/// MultitableInserts
8390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8391#[cfg_attr(feature = "bindings", derive(TS))]
8392pub struct MultitableInserts {
8393    #[serde(default)]
8394    pub expressions: Vec<Expression>,
8395    pub kind: String,
8396    #[serde(default)]
8397    pub source: Option<Box<Expression>>,
8398    /// Leading comments before the statement
8399    #[serde(default)]
8400    pub leading_comments: Vec<String>,
8401}
8402
8403/// OnConflict
8404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8405#[cfg_attr(feature = "bindings", derive(TS))]
8406pub struct OnConflict {
8407    #[serde(default)]
8408    pub duplicate: Option<Box<Expression>>,
8409    #[serde(default)]
8410    pub expressions: Vec<Expression>,
8411    #[serde(default)]
8412    pub action: Option<Box<Expression>>,
8413    #[serde(default)]
8414    pub conflict_keys: Option<Box<Expression>>,
8415    #[serde(default)]
8416    pub index_predicate: Option<Box<Expression>>,
8417    #[serde(default)]
8418    pub constraint: Option<Box<Expression>>,
8419    #[serde(default)]
8420    pub where_: Option<Box<Expression>>,
8421}
8422
8423/// OnCondition
8424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8425#[cfg_attr(feature = "bindings", derive(TS))]
8426pub struct OnCondition {
8427    #[serde(default)]
8428    pub error: Option<Box<Expression>>,
8429    #[serde(default)]
8430    pub empty: Option<Box<Expression>>,
8431    #[serde(default)]
8432    pub null: Option<Box<Expression>>,
8433}
8434
8435/// Returning
8436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8437#[cfg_attr(feature = "bindings", derive(TS))]
8438pub struct Returning {
8439    #[serde(default)]
8440    pub expressions: Vec<Expression>,
8441    #[serde(default)]
8442    pub into: Option<Box<Expression>>,
8443}
8444
8445/// Introducer
8446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8447#[cfg_attr(feature = "bindings", derive(TS))]
8448pub struct Introducer {
8449    pub this: Box<Expression>,
8450    pub expression: Box<Expression>,
8451}
8452
8453/// PartitionRange
8454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8455#[cfg_attr(feature = "bindings", derive(TS))]
8456pub struct PartitionRange {
8457    pub this: Box<Expression>,
8458    #[serde(default)]
8459    pub expression: Option<Box<Expression>>,
8460    #[serde(default)]
8461    pub expressions: Vec<Expression>,
8462}
8463
8464/// Group
8465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8466#[cfg_attr(feature = "bindings", derive(TS))]
8467pub struct Group {
8468    #[serde(default)]
8469    pub expressions: Vec<Expression>,
8470    #[serde(default)]
8471    pub grouping_sets: Option<Box<Expression>>,
8472    #[serde(default)]
8473    pub cube: Option<Box<Expression>>,
8474    #[serde(default)]
8475    pub rollup: Option<Box<Expression>>,
8476    #[serde(default)]
8477    pub totals: Option<Box<Expression>>,
8478    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8479    #[serde(default)]
8480    pub all: Option<bool>,
8481}
8482
8483/// Cube
8484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8485#[cfg_attr(feature = "bindings", derive(TS))]
8486pub struct Cube {
8487    #[serde(default)]
8488    pub expressions: Vec<Expression>,
8489}
8490
8491/// Rollup
8492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8493#[cfg_attr(feature = "bindings", derive(TS))]
8494pub struct Rollup {
8495    #[serde(default)]
8496    pub expressions: Vec<Expression>,
8497}
8498
8499/// GroupingSets
8500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8501#[cfg_attr(feature = "bindings", derive(TS))]
8502pub struct GroupingSets {
8503    #[serde(default)]
8504    pub expressions: Vec<Expression>,
8505}
8506
8507/// LimitOptions
8508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8509#[cfg_attr(feature = "bindings", derive(TS))]
8510pub struct LimitOptions {
8511    #[serde(default)]
8512    pub percent: Option<Box<Expression>>,
8513    #[serde(default)]
8514    pub rows: Option<Box<Expression>>,
8515    #[serde(default)]
8516    pub with_ties: Option<Box<Expression>>,
8517}
8518
8519/// Lateral
8520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8521#[cfg_attr(feature = "bindings", derive(TS))]
8522pub struct Lateral {
8523    pub this: Box<Expression>,
8524    #[serde(default)]
8525    pub view: Option<Box<Expression>>,
8526    #[serde(default)]
8527    pub outer: Option<Box<Expression>>,
8528    #[serde(default)]
8529    pub alias: Option<String>,
8530    /// Whether the alias was originally quoted (backtick/double-quote)
8531    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8532    pub alias_quoted: bool,
8533    #[serde(default)]
8534    pub cross_apply: Option<Box<Expression>>,
8535    #[serde(default)]
8536    pub ordinality: Option<Box<Expression>>,
8537    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8538    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8539    pub column_aliases: Vec<String>,
8540}
8541
8542/// TableFromRows
8543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8544#[cfg_attr(feature = "bindings", derive(TS))]
8545pub struct TableFromRows {
8546    pub this: Box<Expression>,
8547    #[serde(default)]
8548    pub alias: Option<String>,
8549    #[serde(default)]
8550    pub joins: Vec<Expression>,
8551    #[serde(default)]
8552    pub pivots: Option<Box<Expression>>,
8553    #[serde(default)]
8554    pub sample: Option<Box<Expression>>,
8555}
8556
8557/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8558/// Used for set-returning functions with typed column definitions
8559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8560#[cfg_attr(feature = "bindings", derive(TS))]
8561pub struct RowsFrom {
8562    /// List of function expressions, each potentially with an alias and typed columns
8563    pub expressions: Vec<Expression>,
8564    /// WITH ORDINALITY modifier
8565    #[serde(default)]
8566    pub ordinality: bool,
8567    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8568    #[serde(default)]
8569    pub alias: Option<Box<Expression>>,
8570}
8571
8572/// WithFill
8573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8574#[cfg_attr(feature = "bindings", derive(TS))]
8575pub struct WithFill {
8576    #[serde(default)]
8577    pub from_: Option<Box<Expression>>,
8578    #[serde(default)]
8579    pub to: Option<Box<Expression>>,
8580    #[serde(default)]
8581    pub step: Option<Box<Expression>>,
8582    #[serde(default)]
8583    pub staleness: Option<Box<Expression>>,
8584    #[serde(default)]
8585    pub interpolate: Option<Box<Expression>>,
8586}
8587
8588/// Property
8589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8590#[cfg_attr(feature = "bindings", derive(TS))]
8591pub struct Property {
8592    pub this: Box<Expression>,
8593    #[serde(default)]
8594    pub value: Option<Box<Expression>>,
8595}
8596
8597/// GrantPrivilege
8598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8599#[cfg_attr(feature = "bindings", derive(TS))]
8600pub struct GrantPrivilege {
8601    pub this: Box<Expression>,
8602    #[serde(default)]
8603    pub expressions: Vec<Expression>,
8604}
8605
8606/// AllowedValuesProperty
8607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8608#[cfg_attr(feature = "bindings", derive(TS))]
8609pub struct AllowedValuesProperty {
8610    #[serde(default)]
8611    pub expressions: Vec<Expression>,
8612}
8613
8614/// AlgorithmProperty
8615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8616#[cfg_attr(feature = "bindings", derive(TS))]
8617pub struct AlgorithmProperty {
8618    pub this: Box<Expression>,
8619}
8620
8621/// AutoIncrementProperty
8622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8623#[cfg_attr(feature = "bindings", derive(TS))]
8624pub struct AutoIncrementProperty {
8625    pub this: Box<Expression>,
8626}
8627
8628/// AutoRefreshProperty
8629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8630#[cfg_attr(feature = "bindings", derive(TS))]
8631pub struct AutoRefreshProperty {
8632    pub this: Box<Expression>,
8633}
8634
8635/// BackupProperty
8636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8637#[cfg_attr(feature = "bindings", derive(TS))]
8638pub struct BackupProperty {
8639    pub this: Box<Expression>,
8640}
8641
8642/// BuildProperty
8643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8644#[cfg_attr(feature = "bindings", derive(TS))]
8645pub struct BuildProperty {
8646    pub this: Box<Expression>,
8647}
8648
8649/// BlockCompressionProperty
8650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8651#[cfg_attr(feature = "bindings", derive(TS))]
8652pub struct BlockCompressionProperty {
8653    #[serde(default)]
8654    pub autotemp: Option<Box<Expression>>,
8655    #[serde(default)]
8656    pub always: Option<Box<Expression>>,
8657    #[serde(default)]
8658    pub default: Option<Box<Expression>>,
8659    #[serde(default)]
8660    pub manual: Option<Box<Expression>>,
8661    #[serde(default)]
8662    pub never: Option<Box<Expression>>,
8663}
8664
8665/// CharacterSetProperty
8666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8667#[cfg_attr(feature = "bindings", derive(TS))]
8668pub struct CharacterSetProperty {
8669    pub this: Box<Expression>,
8670    #[serde(default)]
8671    pub default: Option<Box<Expression>>,
8672}
8673
8674/// ChecksumProperty
8675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8676#[cfg_attr(feature = "bindings", derive(TS))]
8677pub struct ChecksumProperty {
8678    #[serde(default)]
8679    pub on: Option<Box<Expression>>,
8680    #[serde(default)]
8681    pub default: Option<Box<Expression>>,
8682}
8683
8684/// CollateProperty
8685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8686#[cfg_attr(feature = "bindings", derive(TS))]
8687pub struct CollateProperty {
8688    pub this: Box<Expression>,
8689    #[serde(default)]
8690    pub default: Option<Box<Expression>>,
8691}
8692
8693/// DataBlocksizeProperty
8694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8695#[cfg_attr(feature = "bindings", derive(TS))]
8696pub struct DataBlocksizeProperty {
8697    #[serde(default)]
8698    pub size: Option<i64>,
8699    #[serde(default)]
8700    pub units: Option<Box<Expression>>,
8701    #[serde(default)]
8702    pub minimum: Option<Box<Expression>>,
8703    #[serde(default)]
8704    pub maximum: Option<Box<Expression>>,
8705    #[serde(default)]
8706    pub default: Option<Box<Expression>>,
8707}
8708
8709/// DataDeletionProperty
8710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8711#[cfg_attr(feature = "bindings", derive(TS))]
8712pub struct DataDeletionProperty {
8713    pub on: Box<Expression>,
8714    #[serde(default)]
8715    pub filter_column: Option<Box<Expression>>,
8716    #[serde(default)]
8717    pub retention_period: Option<Box<Expression>>,
8718}
8719
8720/// DefinerProperty
8721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8722#[cfg_attr(feature = "bindings", derive(TS))]
8723pub struct DefinerProperty {
8724    pub this: Box<Expression>,
8725}
8726
8727/// DistKeyProperty
8728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8729#[cfg_attr(feature = "bindings", derive(TS))]
8730pub struct DistKeyProperty {
8731    pub this: Box<Expression>,
8732}
8733
8734/// DistributedByProperty
8735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8736#[cfg_attr(feature = "bindings", derive(TS))]
8737pub struct DistributedByProperty {
8738    #[serde(default)]
8739    pub expressions: Vec<Expression>,
8740    pub kind: String,
8741    #[serde(default)]
8742    pub buckets: Option<Box<Expression>>,
8743    #[serde(default)]
8744    pub order: Option<Box<Expression>>,
8745}
8746
8747/// DistStyleProperty
8748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8749#[cfg_attr(feature = "bindings", derive(TS))]
8750pub struct DistStyleProperty {
8751    pub this: Box<Expression>,
8752}
8753
8754/// DuplicateKeyProperty
8755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8756#[cfg_attr(feature = "bindings", derive(TS))]
8757pub struct DuplicateKeyProperty {
8758    #[serde(default)]
8759    pub expressions: Vec<Expression>,
8760}
8761
8762/// EngineProperty
8763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8764#[cfg_attr(feature = "bindings", derive(TS))]
8765pub struct EngineProperty {
8766    pub this: Box<Expression>,
8767}
8768
8769/// ToTableProperty
8770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8771#[cfg_attr(feature = "bindings", derive(TS))]
8772pub struct ToTableProperty {
8773    pub this: Box<Expression>,
8774}
8775
8776/// ExecuteAsProperty
8777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8778#[cfg_attr(feature = "bindings", derive(TS))]
8779pub struct ExecuteAsProperty {
8780    pub this: Box<Expression>,
8781}
8782
8783/// ExternalProperty
8784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8785#[cfg_attr(feature = "bindings", derive(TS))]
8786pub struct ExternalProperty {
8787    #[serde(default)]
8788    pub this: Option<Box<Expression>>,
8789}
8790
8791/// FallbackProperty
8792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8793#[cfg_attr(feature = "bindings", derive(TS))]
8794pub struct FallbackProperty {
8795    #[serde(default)]
8796    pub no: Option<Box<Expression>>,
8797    #[serde(default)]
8798    pub protection: Option<Box<Expression>>,
8799}
8800
8801/// FileFormatProperty
8802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8803#[cfg_attr(feature = "bindings", derive(TS))]
8804pub struct FileFormatProperty {
8805    #[serde(default)]
8806    pub this: Option<Box<Expression>>,
8807    #[serde(default)]
8808    pub expressions: Vec<Expression>,
8809    #[serde(default)]
8810    pub hive_format: Option<Box<Expression>>,
8811}
8812
8813/// CredentialsProperty
8814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8815#[cfg_attr(feature = "bindings", derive(TS))]
8816pub struct CredentialsProperty {
8817    #[serde(default)]
8818    pub expressions: Vec<Expression>,
8819}
8820
8821/// FreespaceProperty
8822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8823#[cfg_attr(feature = "bindings", derive(TS))]
8824pub struct FreespaceProperty {
8825    pub this: Box<Expression>,
8826    #[serde(default)]
8827    pub percent: Option<Box<Expression>>,
8828}
8829
8830/// InheritsProperty
8831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8832#[cfg_attr(feature = "bindings", derive(TS))]
8833pub struct InheritsProperty {
8834    #[serde(default)]
8835    pub expressions: Vec<Expression>,
8836}
8837
8838/// InputModelProperty
8839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8840#[cfg_attr(feature = "bindings", derive(TS))]
8841pub struct InputModelProperty {
8842    pub this: Box<Expression>,
8843}
8844
8845/// OutputModelProperty
8846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8847#[cfg_attr(feature = "bindings", derive(TS))]
8848pub struct OutputModelProperty {
8849    pub this: Box<Expression>,
8850}
8851
8852/// IsolatedLoadingProperty
8853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8854#[cfg_attr(feature = "bindings", derive(TS))]
8855pub struct IsolatedLoadingProperty {
8856    #[serde(default)]
8857    pub no: Option<Box<Expression>>,
8858    #[serde(default)]
8859    pub concurrent: Option<Box<Expression>>,
8860    #[serde(default)]
8861    pub target: Option<Box<Expression>>,
8862}
8863
8864/// JournalProperty
8865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8866#[cfg_attr(feature = "bindings", derive(TS))]
8867pub struct JournalProperty {
8868    #[serde(default)]
8869    pub no: Option<Box<Expression>>,
8870    #[serde(default)]
8871    pub dual: Option<Box<Expression>>,
8872    #[serde(default)]
8873    pub before: Option<Box<Expression>>,
8874    #[serde(default)]
8875    pub local: Option<Box<Expression>>,
8876    #[serde(default)]
8877    pub after: Option<Box<Expression>>,
8878}
8879
8880/// LanguageProperty
8881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8882#[cfg_attr(feature = "bindings", derive(TS))]
8883pub struct LanguageProperty {
8884    pub this: Box<Expression>,
8885}
8886
8887/// EnviromentProperty
8888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8889#[cfg_attr(feature = "bindings", derive(TS))]
8890pub struct EnviromentProperty {
8891    #[serde(default)]
8892    pub expressions: Vec<Expression>,
8893}
8894
8895/// ClusteredByProperty
8896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8897#[cfg_attr(feature = "bindings", derive(TS))]
8898pub struct ClusteredByProperty {
8899    #[serde(default)]
8900    pub expressions: Vec<Expression>,
8901    #[serde(default)]
8902    pub sorted_by: Option<Box<Expression>>,
8903    #[serde(default)]
8904    pub buckets: Option<Box<Expression>>,
8905}
8906
8907/// DictProperty
8908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8909#[cfg_attr(feature = "bindings", derive(TS))]
8910pub struct DictProperty {
8911    pub this: Box<Expression>,
8912    pub kind: String,
8913    #[serde(default)]
8914    pub settings: Option<Box<Expression>>,
8915}
8916
8917/// DictRange
8918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8919#[cfg_attr(feature = "bindings", derive(TS))]
8920pub struct DictRange {
8921    pub this: Box<Expression>,
8922    #[serde(default)]
8923    pub min: Option<Box<Expression>>,
8924    #[serde(default)]
8925    pub max: Option<Box<Expression>>,
8926}
8927
8928/// OnCluster
8929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8930#[cfg_attr(feature = "bindings", derive(TS))]
8931pub struct OnCluster {
8932    pub this: Box<Expression>,
8933}
8934
8935/// LikeProperty
8936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8937#[cfg_attr(feature = "bindings", derive(TS))]
8938pub struct LikeProperty {
8939    pub this: Box<Expression>,
8940    #[serde(default)]
8941    pub expressions: Vec<Expression>,
8942}
8943
8944/// LocationProperty
8945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8946#[cfg_attr(feature = "bindings", derive(TS))]
8947pub struct LocationProperty {
8948    pub this: Box<Expression>,
8949}
8950
8951/// LockProperty
8952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8953#[cfg_attr(feature = "bindings", derive(TS))]
8954pub struct LockProperty {
8955    pub this: Box<Expression>,
8956}
8957
8958/// LockingProperty
8959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8960#[cfg_attr(feature = "bindings", derive(TS))]
8961pub struct LockingProperty {
8962    #[serde(default)]
8963    pub this: Option<Box<Expression>>,
8964    pub kind: String,
8965    #[serde(default)]
8966    pub for_or_in: Option<Box<Expression>>,
8967    #[serde(default)]
8968    pub lock_type: Option<Box<Expression>>,
8969    #[serde(default)]
8970    pub override_: Option<Box<Expression>>,
8971}
8972
8973/// LogProperty
8974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8975#[cfg_attr(feature = "bindings", derive(TS))]
8976pub struct LogProperty {
8977    #[serde(default)]
8978    pub no: Option<Box<Expression>>,
8979}
8980
8981/// MaterializedProperty
8982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8983#[cfg_attr(feature = "bindings", derive(TS))]
8984pub struct MaterializedProperty {
8985    #[serde(default)]
8986    pub this: Option<Box<Expression>>,
8987}
8988
8989/// MergeBlockRatioProperty
8990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8991#[cfg_attr(feature = "bindings", derive(TS))]
8992pub struct MergeBlockRatioProperty {
8993    #[serde(default)]
8994    pub this: Option<Box<Expression>>,
8995    #[serde(default)]
8996    pub no: Option<Box<Expression>>,
8997    #[serde(default)]
8998    pub default: Option<Box<Expression>>,
8999    #[serde(default)]
9000    pub percent: Option<Box<Expression>>,
9001}
9002
9003/// OnProperty
9004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9005#[cfg_attr(feature = "bindings", derive(TS))]
9006pub struct OnProperty {
9007    pub this: Box<Expression>,
9008}
9009
9010/// OnCommitProperty
9011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9012#[cfg_attr(feature = "bindings", derive(TS))]
9013pub struct OnCommitProperty {
9014    #[serde(default)]
9015    pub delete: Option<Box<Expression>>,
9016}
9017
9018/// PartitionedByProperty
9019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9020#[cfg_attr(feature = "bindings", derive(TS))]
9021pub struct PartitionedByProperty {
9022    pub this: Box<Expression>,
9023}
9024
9025/// PartitionedByBucket
9026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9027#[cfg_attr(feature = "bindings", derive(TS))]
9028pub struct PartitionedByBucket {
9029    pub this: Box<Expression>,
9030    pub expression: Box<Expression>,
9031}
9032
9033/// PartitionByTruncate
9034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9035#[cfg_attr(feature = "bindings", derive(TS))]
9036pub struct PartitionByTruncate {
9037    pub this: Box<Expression>,
9038    pub expression: Box<Expression>,
9039}
9040
9041/// PartitionByRangeProperty
9042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9043#[cfg_attr(feature = "bindings", derive(TS))]
9044pub struct PartitionByRangeProperty {
9045    #[serde(default)]
9046    pub partition_expressions: Option<Box<Expression>>,
9047    #[serde(default)]
9048    pub create_expressions: Option<Box<Expression>>,
9049}
9050
9051/// PartitionByRangePropertyDynamic
9052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9053#[cfg_attr(feature = "bindings", derive(TS))]
9054pub struct PartitionByRangePropertyDynamic {
9055    #[serde(default)]
9056    pub this: Option<Box<Expression>>,
9057    #[serde(default)]
9058    pub start: Option<Box<Expression>>,
9059    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9060    #[serde(default)]
9061    pub use_start_end: bool,
9062    #[serde(default)]
9063    pub end: Option<Box<Expression>>,
9064    #[serde(default)]
9065    pub every: Option<Box<Expression>>,
9066}
9067
9068/// PartitionByListProperty
9069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9070#[cfg_attr(feature = "bindings", derive(TS))]
9071pub struct PartitionByListProperty {
9072    #[serde(default)]
9073    pub partition_expressions: Option<Box<Expression>>,
9074    #[serde(default)]
9075    pub create_expressions: Option<Box<Expression>>,
9076}
9077
9078/// PartitionList
9079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9080#[cfg_attr(feature = "bindings", derive(TS))]
9081pub struct PartitionList {
9082    pub this: Box<Expression>,
9083    #[serde(default)]
9084    pub expressions: Vec<Expression>,
9085}
9086
9087/// Partition - represents PARTITION/SUBPARTITION clause
9088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9089#[cfg_attr(feature = "bindings", derive(TS))]
9090pub struct Partition {
9091    pub expressions: Vec<Expression>,
9092    #[serde(default)]
9093    pub subpartition: bool,
9094}
9095
9096/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9097/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9099#[cfg_attr(feature = "bindings", derive(TS))]
9100pub struct RefreshTriggerProperty {
9101    /// Method: COMPLETE or AUTO
9102    pub method: String,
9103    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9104    #[serde(default)]
9105    pub kind: Option<String>,
9106    /// For SCHEDULE: EVERY n (the number)
9107    #[serde(default)]
9108    pub every: Option<Box<Expression>>,
9109    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9110    #[serde(default)]
9111    pub unit: Option<String>,
9112    /// For SCHEDULE: STARTS 'datetime'
9113    #[serde(default)]
9114    pub starts: Option<Box<Expression>>,
9115}
9116
9117/// UniqueKeyProperty
9118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9119#[cfg_attr(feature = "bindings", derive(TS))]
9120pub struct UniqueKeyProperty {
9121    #[serde(default)]
9122    pub expressions: Vec<Expression>,
9123}
9124
9125/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9127#[cfg_attr(feature = "bindings", derive(TS))]
9128pub struct RollupProperty {
9129    pub expressions: Vec<RollupIndex>,
9130}
9131
9132/// RollupIndex - A single rollup index: name(col1, col2)
9133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9134#[cfg_attr(feature = "bindings", derive(TS))]
9135pub struct RollupIndex {
9136    pub name: Identifier,
9137    pub expressions: Vec<Identifier>,
9138}
9139
9140/// PartitionBoundSpec
9141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9142#[cfg_attr(feature = "bindings", derive(TS))]
9143pub struct PartitionBoundSpec {
9144    #[serde(default)]
9145    pub this: Option<Box<Expression>>,
9146    #[serde(default)]
9147    pub expression: Option<Box<Expression>>,
9148    #[serde(default)]
9149    pub from_expressions: Option<Box<Expression>>,
9150    #[serde(default)]
9151    pub to_expressions: Option<Box<Expression>>,
9152}
9153
9154/// PartitionedOfProperty
9155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9156#[cfg_attr(feature = "bindings", derive(TS))]
9157pub struct PartitionedOfProperty {
9158    pub this: Box<Expression>,
9159    pub expression: Box<Expression>,
9160}
9161
9162/// RemoteWithConnectionModelProperty
9163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9164#[cfg_attr(feature = "bindings", derive(TS))]
9165pub struct RemoteWithConnectionModelProperty {
9166    pub this: Box<Expression>,
9167}
9168
9169/// ReturnsProperty
9170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9171#[cfg_attr(feature = "bindings", derive(TS))]
9172pub struct ReturnsProperty {
9173    #[serde(default)]
9174    pub this: Option<Box<Expression>>,
9175    #[serde(default)]
9176    pub is_table: Option<Box<Expression>>,
9177    #[serde(default)]
9178    pub table: Option<Box<Expression>>,
9179    #[serde(default)]
9180    pub null: Option<Box<Expression>>,
9181}
9182
9183/// RowFormatProperty
9184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9185#[cfg_attr(feature = "bindings", derive(TS))]
9186pub struct RowFormatProperty {
9187    pub this: Box<Expression>,
9188}
9189
9190/// RowFormatDelimitedProperty
9191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9192#[cfg_attr(feature = "bindings", derive(TS))]
9193pub struct RowFormatDelimitedProperty {
9194    #[serde(default)]
9195    pub fields: Option<Box<Expression>>,
9196    #[serde(default)]
9197    pub escaped: Option<Box<Expression>>,
9198    #[serde(default)]
9199    pub collection_items: Option<Box<Expression>>,
9200    #[serde(default)]
9201    pub map_keys: Option<Box<Expression>>,
9202    #[serde(default)]
9203    pub lines: Option<Box<Expression>>,
9204    #[serde(default)]
9205    pub null: Option<Box<Expression>>,
9206    #[serde(default)]
9207    pub serde: Option<Box<Expression>>,
9208}
9209
9210/// RowFormatSerdeProperty
9211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9212#[cfg_attr(feature = "bindings", derive(TS))]
9213pub struct RowFormatSerdeProperty {
9214    pub this: Box<Expression>,
9215    #[serde(default)]
9216    pub serde_properties: Option<Box<Expression>>,
9217}
9218
9219/// QueryTransform
9220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9221#[cfg_attr(feature = "bindings", derive(TS))]
9222pub struct QueryTransform {
9223    #[serde(default)]
9224    pub expressions: Vec<Expression>,
9225    #[serde(default)]
9226    pub command_script: Option<Box<Expression>>,
9227    #[serde(default)]
9228    pub schema: Option<Box<Expression>>,
9229    #[serde(default)]
9230    pub row_format_before: Option<Box<Expression>>,
9231    #[serde(default)]
9232    pub record_writer: Option<Box<Expression>>,
9233    #[serde(default)]
9234    pub row_format_after: Option<Box<Expression>>,
9235    #[serde(default)]
9236    pub record_reader: Option<Box<Expression>>,
9237}
9238
9239/// SampleProperty
9240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9241#[cfg_attr(feature = "bindings", derive(TS))]
9242pub struct SampleProperty {
9243    pub this: Box<Expression>,
9244}
9245
9246/// SecurityProperty
9247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9248#[cfg_attr(feature = "bindings", derive(TS))]
9249pub struct SecurityProperty {
9250    pub this: Box<Expression>,
9251}
9252
9253/// SchemaCommentProperty
9254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9255#[cfg_attr(feature = "bindings", derive(TS))]
9256pub struct SchemaCommentProperty {
9257    pub this: Box<Expression>,
9258}
9259
9260/// SemanticView
9261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9262#[cfg_attr(feature = "bindings", derive(TS))]
9263pub struct SemanticView {
9264    pub this: Box<Expression>,
9265    #[serde(default)]
9266    pub metrics: Option<Box<Expression>>,
9267    #[serde(default)]
9268    pub dimensions: Option<Box<Expression>>,
9269    #[serde(default)]
9270    pub facts: Option<Box<Expression>>,
9271    #[serde(default)]
9272    pub where_: Option<Box<Expression>>,
9273}
9274
9275/// SerdeProperties
9276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9277#[cfg_attr(feature = "bindings", derive(TS))]
9278pub struct SerdeProperties {
9279    #[serde(default)]
9280    pub expressions: Vec<Expression>,
9281    #[serde(default)]
9282    pub with_: Option<Box<Expression>>,
9283}
9284
9285/// SetProperty
9286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9287#[cfg_attr(feature = "bindings", derive(TS))]
9288pub struct SetProperty {
9289    #[serde(default)]
9290    pub multi: Option<Box<Expression>>,
9291}
9292
9293/// SharingProperty
9294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9295#[cfg_attr(feature = "bindings", derive(TS))]
9296pub struct SharingProperty {
9297    #[serde(default)]
9298    pub this: Option<Box<Expression>>,
9299}
9300
9301/// SetConfigProperty
9302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9303#[cfg_attr(feature = "bindings", derive(TS))]
9304pub struct SetConfigProperty {
9305    pub this: Box<Expression>,
9306}
9307
9308/// SettingsProperty
9309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9310#[cfg_attr(feature = "bindings", derive(TS))]
9311pub struct SettingsProperty {
9312    #[serde(default)]
9313    pub expressions: Vec<Expression>,
9314}
9315
9316/// SortKeyProperty
9317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9318#[cfg_attr(feature = "bindings", derive(TS))]
9319pub struct SortKeyProperty {
9320    pub this: Box<Expression>,
9321    #[serde(default)]
9322    pub compound: Option<Box<Expression>>,
9323}
9324
9325/// SqlReadWriteProperty
9326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9327#[cfg_attr(feature = "bindings", derive(TS))]
9328pub struct SqlReadWriteProperty {
9329    pub this: Box<Expression>,
9330}
9331
9332/// SqlSecurityProperty
9333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9334#[cfg_attr(feature = "bindings", derive(TS))]
9335pub struct SqlSecurityProperty {
9336    pub this: Box<Expression>,
9337}
9338
9339/// StabilityProperty
9340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9341#[cfg_attr(feature = "bindings", derive(TS))]
9342pub struct StabilityProperty {
9343    pub this: Box<Expression>,
9344}
9345
9346/// StorageHandlerProperty
9347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9348#[cfg_attr(feature = "bindings", derive(TS))]
9349pub struct StorageHandlerProperty {
9350    pub this: Box<Expression>,
9351}
9352
9353/// TemporaryProperty
9354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9355#[cfg_attr(feature = "bindings", derive(TS))]
9356pub struct TemporaryProperty {
9357    #[serde(default)]
9358    pub this: Option<Box<Expression>>,
9359}
9360
9361/// Tags
9362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9363#[cfg_attr(feature = "bindings", derive(TS))]
9364pub struct Tags {
9365    #[serde(default)]
9366    pub expressions: Vec<Expression>,
9367}
9368
9369/// TransformModelProperty
9370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9371#[cfg_attr(feature = "bindings", derive(TS))]
9372pub struct TransformModelProperty {
9373    #[serde(default)]
9374    pub expressions: Vec<Expression>,
9375}
9376
9377/// TransientProperty
9378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9379#[cfg_attr(feature = "bindings", derive(TS))]
9380pub struct TransientProperty {
9381    #[serde(default)]
9382    pub this: Option<Box<Expression>>,
9383}
9384
9385/// UsingTemplateProperty
9386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9387#[cfg_attr(feature = "bindings", derive(TS))]
9388pub struct UsingTemplateProperty {
9389    pub this: Box<Expression>,
9390}
9391
9392/// ViewAttributeProperty
9393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9394#[cfg_attr(feature = "bindings", derive(TS))]
9395pub struct ViewAttributeProperty {
9396    pub this: Box<Expression>,
9397}
9398
9399/// VolatileProperty
9400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9401#[cfg_attr(feature = "bindings", derive(TS))]
9402pub struct VolatileProperty {
9403    #[serde(default)]
9404    pub this: Option<Box<Expression>>,
9405}
9406
9407/// WithDataProperty
9408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9409#[cfg_attr(feature = "bindings", derive(TS))]
9410pub struct WithDataProperty {
9411    #[serde(default)]
9412    pub no: Option<Box<Expression>>,
9413    #[serde(default)]
9414    pub statistics: Option<Box<Expression>>,
9415}
9416
9417/// WithJournalTableProperty
9418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9419#[cfg_attr(feature = "bindings", derive(TS))]
9420pub struct WithJournalTableProperty {
9421    pub this: Box<Expression>,
9422}
9423
9424/// WithSchemaBindingProperty
9425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9426#[cfg_attr(feature = "bindings", derive(TS))]
9427pub struct WithSchemaBindingProperty {
9428    pub this: Box<Expression>,
9429}
9430
9431/// WithSystemVersioningProperty
9432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub struct WithSystemVersioningProperty {
9435    #[serde(default)]
9436    pub on: Option<Box<Expression>>,
9437    #[serde(default)]
9438    pub this: Option<Box<Expression>>,
9439    #[serde(default)]
9440    pub data_consistency: Option<Box<Expression>>,
9441    #[serde(default)]
9442    pub retention_period: Option<Box<Expression>>,
9443    #[serde(default)]
9444    pub with_: Option<Box<Expression>>,
9445}
9446
9447/// WithProcedureOptions
9448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9449#[cfg_attr(feature = "bindings", derive(TS))]
9450pub struct WithProcedureOptions {
9451    #[serde(default)]
9452    pub expressions: Vec<Expression>,
9453}
9454
9455/// EncodeProperty
9456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9457#[cfg_attr(feature = "bindings", derive(TS))]
9458pub struct EncodeProperty {
9459    pub this: Box<Expression>,
9460    #[serde(default)]
9461    pub properties: Vec<Expression>,
9462    #[serde(default)]
9463    pub key: Option<Box<Expression>>,
9464}
9465
9466/// IncludeProperty
9467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9468#[cfg_attr(feature = "bindings", derive(TS))]
9469pub struct IncludeProperty {
9470    pub this: Box<Expression>,
9471    #[serde(default)]
9472    pub alias: Option<String>,
9473    #[serde(default)]
9474    pub column_def: Option<Box<Expression>>,
9475}
9476
9477/// Properties
9478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9479#[cfg_attr(feature = "bindings", derive(TS))]
9480pub struct Properties {
9481    #[serde(default)]
9482    pub expressions: Vec<Expression>,
9483}
9484
9485/// InputOutputFormat
9486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9487#[cfg_attr(feature = "bindings", derive(TS))]
9488pub struct InputOutputFormat {
9489    #[serde(default)]
9490    pub input_format: Option<Box<Expression>>,
9491    #[serde(default)]
9492    pub output_format: Option<Box<Expression>>,
9493}
9494
9495/// Reference
9496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9497#[cfg_attr(feature = "bindings", derive(TS))]
9498pub struct Reference {
9499    pub this: Box<Expression>,
9500    #[serde(default)]
9501    pub expressions: Vec<Expression>,
9502    #[serde(default)]
9503    pub options: Vec<Expression>,
9504}
9505
9506/// QueryOption
9507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9508#[cfg_attr(feature = "bindings", derive(TS))]
9509pub struct QueryOption {
9510    pub this: Box<Expression>,
9511    #[serde(default)]
9512    pub expression: Option<Box<Expression>>,
9513}
9514
9515/// WithTableHint
9516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9517#[cfg_attr(feature = "bindings", derive(TS))]
9518pub struct WithTableHint {
9519    #[serde(default)]
9520    pub expressions: Vec<Expression>,
9521}
9522
9523/// IndexTableHint
9524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9525#[cfg_attr(feature = "bindings", derive(TS))]
9526pub struct IndexTableHint {
9527    pub this: Box<Expression>,
9528    #[serde(default)]
9529    pub expressions: Vec<Expression>,
9530    #[serde(default)]
9531    pub target: Option<Box<Expression>>,
9532}
9533
9534/// Get
9535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9536#[cfg_attr(feature = "bindings", derive(TS))]
9537pub struct Get {
9538    pub this: Box<Expression>,
9539    #[serde(default)]
9540    pub target: Option<Box<Expression>>,
9541    #[serde(default)]
9542    pub properties: Vec<Expression>,
9543}
9544
9545/// SetOperation
9546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9547#[cfg_attr(feature = "bindings", derive(TS))]
9548pub struct SetOperation {
9549    #[serde(default)]
9550    pub with_: Option<Box<Expression>>,
9551    pub this: Box<Expression>,
9552    pub expression: Box<Expression>,
9553    #[serde(default)]
9554    pub distinct: bool,
9555    #[serde(default)]
9556    pub by_name: Option<Box<Expression>>,
9557    #[serde(default)]
9558    pub side: Option<Box<Expression>>,
9559    #[serde(default)]
9560    pub kind: Option<String>,
9561    #[serde(default)]
9562    pub on: Option<Box<Expression>>,
9563}
9564
9565/// Var - Simple variable reference (for SQL variables, keywords as values)
9566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9567#[cfg_attr(feature = "bindings", derive(TS))]
9568pub struct Var {
9569    pub this: String,
9570}
9571
9572/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
9573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9574#[cfg_attr(feature = "bindings", derive(TS))]
9575pub struct Variadic {
9576    pub this: Box<Expression>,
9577}
9578
9579/// Version
9580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9581#[cfg_attr(feature = "bindings", derive(TS))]
9582pub struct Version {
9583    pub this: Box<Expression>,
9584    pub kind: String,
9585    #[serde(default)]
9586    pub expression: Option<Box<Expression>>,
9587}
9588
9589/// Schema
9590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9591#[cfg_attr(feature = "bindings", derive(TS))]
9592pub struct Schema {
9593    #[serde(default)]
9594    pub this: Option<Box<Expression>>,
9595    #[serde(default)]
9596    pub expressions: Vec<Expression>,
9597}
9598
9599/// Lock
9600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9601#[cfg_attr(feature = "bindings", derive(TS))]
9602pub struct Lock {
9603    #[serde(default)]
9604    pub update: Option<Box<Expression>>,
9605    #[serde(default)]
9606    pub expressions: Vec<Expression>,
9607    #[serde(default)]
9608    pub wait: Option<Box<Expression>>,
9609    #[serde(default)]
9610    pub key: Option<Box<Expression>>,
9611}
9612
9613/// TableSample - wraps an expression with a TABLESAMPLE clause
9614/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9616#[cfg_attr(feature = "bindings", derive(TS))]
9617pub struct TableSample {
9618    /// The expression being sampled (subquery, function, etc.)
9619    #[serde(default, skip_serializing_if = "Option::is_none")]
9620    pub this: Option<Box<Expression>>,
9621    /// The sample specification
9622    #[serde(default, skip_serializing_if = "Option::is_none")]
9623    pub sample: Option<Box<Sample>>,
9624    #[serde(default)]
9625    pub expressions: Vec<Expression>,
9626    #[serde(default)]
9627    pub method: Option<String>,
9628    #[serde(default)]
9629    pub bucket_numerator: Option<Box<Expression>>,
9630    #[serde(default)]
9631    pub bucket_denominator: Option<Box<Expression>>,
9632    #[serde(default)]
9633    pub bucket_field: Option<Box<Expression>>,
9634    #[serde(default)]
9635    pub percent: Option<Box<Expression>>,
9636    #[serde(default)]
9637    pub rows: Option<Box<Expression>>,
9638    #[serde(default)]
9639    pub size: Option<i64>,
9640    #[serde(default)]
9641    pub seed: Option<Box<Expression>>,
9642}
9643
9644/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9646#[cfg_attr(feature = "bindings", derive(TS))]
9647pub struct Tag {
9648    #[serde(default)]
9649    pub this: Option<Box<Expression>>,
9650    #[serde(default)]
9651    pub prefix: Option<Box<Expression>>,
9652    #[serde(default)]
9653    pub postfix: Option<Box<Expression>>,
9654}
9655
9656/// UnpivotColumns
9657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9658#[cfg_attr(feature = "bindings", derive(TS))]
9659pub struct UnpivotColumns {
9660    pub this: Box<Expression>,
9661    #[serde(default)]
9662    pub expressions: Vec<Expression>,
9663}
9664
9665/// SessionParameter
9666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9667#[cfg_attr(feature = "bindings", derive(TS))]
9668pub struct SessionParameter {
9669    pub this: Box<Expression>,
9670    #[serde(default)]
9671    pub kind: Option<String>,
9672}
9673
9674/// PseudoType
9675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9676#[cfg_attr(feature = "bindings", derive(TS))]
9677pub struct PseudoType {
9678    pub this: Box<Expression>,
9679}
9680
9681/// ObjectIdentifier
9682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9683#[cfg_attr(feature = "bindings", derive(TS))]
9684pub struct ObjectIdentifier {
9685    pub this: Box<Expression>,
9686}
9687
9688/// Transaction
9689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9690#[cfg_attr(feature = "bindings", derive(TS))]
9691pub struct Transaction {
9692    #[serde(default)]
9693    pub this: Option<Box<Expression>>,
9694    #[serde(default)]
9695    pub modes: Option<Box<Expression>>,
9696    #[serde(default)]
9697    pub mark: Option<Box<Expression>>,
9698}
9699
9700/// Commit
9701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9702#[cfg_attr(feature = "bindings", derive(TS))]
9703pub struct Commit {
9704    #[serde(default)]
9705    pub chain: Option<Box<Expression>>,
9706    #[serde(default)]
9707    pub this: Option<Box<Expression>>,
9708    #[serde(default)]
9709    pub durability: Option<Box<Expression>>,
9710}
9711
9712/// Rollback
9713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9714#[cfg_attr(feature = "bindings", derive(TS))]
9715pub struct Rollback {
9716    #[serde(default)]
9717    pub savepoint: Option<Box<Expression>>,
9718    #[serde(default)]
9719    pub this: Option<Box<Expression>>,
9720}
9721
9722/// AlterSession
9723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9724#[cfg_attr(feature = "bindings", derive(TS))]
9725pub struct AlterSession {
9726    #[serde(default)]
9727    pub expressions: Vec<Expression>,
9728    #[serde(default)]
9729    pub unset: Option<Box<Expression>>,
9730}
9731
9732/// Analyze
9733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9734#[cfg_attr(feature = "bindings", derive(TS))]
9735pub struct Analyze {
9736    #[serde(default)]
9737    pub kind: Option<String>,
9738    #[serde(default)]
9739    pub this: Option<Box<Expression>>,
9740    #[serde(default)]
9741    pub options: Vec<Expression>,
9742    #[serde(default)]
9743    pub mode: Option<Box<Expression>>,
9744    #[serde(default)]
9745    pub partition: Option<Box<Expression>>,
9746    #[serde(default)]
9747    pub expression: Option<Box<Expression>>,
9748    #[serde(default)]
9749    pub properties: Vec<Expression>,
9750    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9751    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9752    pub columns: Vec<String>,
9753}
9754
9755/// AnalyzeStatistics
9756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9757#[cfg_attr(feature = "bindings", derive(TS))]
9758pub struct AnalyzeStatistics {
9759    pub kind: String,
9760    #[serde(default)]
9761    pub option: Option<Box<Expression>>,
9762    #[serde(default)]
9763    pub this: Option<Box<Expression>>,
9764    #[serde(default)]
9765    pub expressions: Vec<Expression>,
9766}
9767
9768/// AnalyzeHistogram
9769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9770#[cfg_attr(feature = "bindings", derive(TS))]
9771pub struct AnalyzeHistogram {
9772    pub this: Box<Expression>,
9773    #[serde(default)]
9774    pub expressions: Vec<Expression>,
9775    #[serde(default)]
9776    pub expression: Option<Box<Expression>>,
9777    #[serde(default)]
9778    pub update_options: Option<Box<Expression>>,
9779}
9780
9781/// AnalyzeSample
9782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9783#[cfg_attr(feature = "bindings", derive(TS))]
9784pub struct AnalyzeSample {
9785    pub kind: String,
9786    #[serde(default)]
9787    pub sample: Option<Box<Expression>>,
9788}
9789
9790/// AnalyzeListChainedRows
9791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9792#[cfg_attr(feature = "bindings", derive(TS))]
9793pub struct AnalyzeListChainedRows {
9794    #[serde(default)]
9795    pub expression: Option<Box<Expression>>,
9796}
9797
9798/// AnalyzeDelete
9799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9800#[cfg_attr(feature = "bindings", derive(TS))]
9801pub struct AnalyzeDelete {
9802    #[serde(default)]
9803    pub kind: Option<String>,
9804}
9805
9806/// AnalyzeWith
9807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9808#[cfg_attr(feature = "bindings", derive(TS))]
9809pub struct AnalyzeWith {
9810    #[serde(default)]
9811    pub expressions: Vec<Expression>,
9812}
9813
9814/// AnalyzeValidate
9815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9816#[cfg_attr(feature = "bindings", derive(TS))]
9817pub struct AnalyzeValidate {
9818    pub kind: String,
9819    #[serde(default)]
9820    pub this: Option<Box<Expression>>,
9821    #[serde(default)]
9822    pub expression: Option<Box<Expression>>,
9823}
9824
9825/// AddPartition
9826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9827#[cfg_attr(feature = "bindings", derive(TS))]
9828pub struct AddPartition {
9829    pub this: Box<Expression>,
9830    #[serde(default)]
9831    pub exists: bool,
9832    #[serde(default)]
9833    pub location: Option<Box<Expression>>,
9834}
9835
9836/// AttachOption
9837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9838#[cfg_attr(feature = "bindings", derive(TS))]
9839pub struct AttachOption {
9840    pub this: Box<Expression>,
9841    #[serde(default)]
9842    pub expression: Option<Box<Expression>>,
9843}
9844
9845/// DropPartition
9846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9847#[cfg_attr(feature = "bindings", derive(TS))]
9848pub struct DropPartition {
9849    #[serde(default)]
9850    pub expressions: Vec<Expression>,
9851    #[serde(default)]
9852    pub exists: bool,
9853}
9854
9855/// ReplacePartition
9856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9857#[cfg_attr(feature = "bindings", derive(TS))]
9858pub struct ReplacePartition {
9859    pub expression: Box<Expression>,
9860    #[serde(default)]
9861    pub source: Option<Box<Expression>>,
9862}
9863
9864/// DPipe
9865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9866#[cfg_attr(feature = "bindings", derive(TS))]
9867pub struct DPipe {
9868    pub this: Box<Expression>,
9869    pub expression: Box<Expression>,
9870    #[serde(default)]
9871    pub safe: Option<Box<Expression>>,
9872}
9873
9874/// Operator
9875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9876#[cfg_attr(feature = "bindings", derive(TS))]
9877pub struct Operator {
9878    pub this: Box<Expression>,
9879    #[serde(default)]
9880    pub operator: Option<Box<Expression>>,
9881    pub expression: Box<Expression>,
9882    /// Comments between OPERATOR() and the RHS expression
9883    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9884    pub comments: Vec<String>,
9885}
9886
9887/// PivotAny
9888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9889#[cfg_attr(feature = "bindings", derive(TS))]
9890pub struct PivotAny {
9891    #[serde(default)]
9892    pub this: Option<Box<Expression>>,
9893}
9894
9895/// Aliases
9896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9897#[cfg_attr(feature = "bindings", derive(TS))]
9898pub struct Aliases {
9899    pub this: Box<Expression>,
9900    #[serde(default)]
9901    pub expressions: Vec<Expression>,
9902}
9903
9904/// AtIndex
9905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9906#[cfg_attr(feature = "bindings", derive(TS))]
9907pub struct AtIndex {
9908    pub this: Box<Expression>,
9909    pub expression: Box<Expression>,
9910}
9911
9912/// FromTimeZone
9913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9914#[cfg_attr(feature = "bindings", derive(TS))]
9915pub struct FromTimeZone {
9916    pub this: Box<Expression>,
9917    #[serde(default)]
9918    pub zone: Option<Box<Expression>>,
9919}
9920
9921/// Format override for a column in Teradata
9922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9923#[cfg_attr(feature = "bindings", derive(TS))]
9924pub struct FormatPhrase {
9925    pub this: Box<Expression>,
9926    pub format: String,
9927}
9928
9929/// ForIn
9930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9931#[cfg_attr(feature = "bindings", derive(TS))]
9932pub struct ForIn {
9933    pub this: Box<Expression>,
9934    pub expression: Box<Expression>,
9935}
9936
9937/// Automatically converts unit arg into a var.
9938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9939#[cfg_attr(feature = "bindings", derive(TS))]
9940pub struct TimeUnit {
9941    #[serde(default)]
9942    pub unit: Option<String>,
9943}
9944
9945/// IntervalOp
9946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9947#[cfg_attr(feature = "bindings", derive(TS))]
9948pub struct IntervalOp {
9949    #[serde(default)]
9950    pub unit: Option<String>,
9951    pub expression: Box<Expression>,
9952}
9953
9954/// HavingMax
9955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9956#[cfg_attr(feature = "bindings", derive(TS))]
9957pub struct HavingMax {
9958    pub this: Box<Expression>,
9959    pub expression: Box<Expression>,
9960    #[serde(default)]
9961    pub max: Option<Box<Expression>>,
9962}
9963
9964/// CosineDistance
9965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9966#[cfg_attr(feature = "bindings", derive(TS))]
9967pub struct CosineDistance {
9968    pub this: Box<Expression>,
9969    pub expression: Box<Expression>,
9970}
9971
9972/// DotProduct
9973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9974#[cfg_attr(feature = "bindings", derive(TS))]
9975pub struct DotProduct {
9976    pub this: Box<Expression>,
9977    pub expression: Box<Expression>,
9978}
9979
9980/// EuclideanDistance
9981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9982#[cfg_attr(feature = "bindings", derive(TS))]
9983pub struct EuclideanDistance {
9984    pub this: Box<Expression>,
9985    pub expression: Box<Expression>,
9986}
9987
9988/// ManhattanDistance
9989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9990#[cfg_attr(feature = "bindings", derive(TS))]
9991pub struct ManhattanDistance {
9992    pub this: Box<Expression>,
9993    pub expression: Box<Expression>,
9994}
9995
9996/// JarowinklerSimilarity
9997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9998#[cfg_attr(feature = "bindings", derive(TS))]
9999pub struct JarowinklerSimilarity {
10000    pub this: Box<Expression>,
10001    pub expression: Box<Expression>,
10002}
10003
10004/// Booland
10005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10006#[cfg_attr(feature = "bindings", derive(TS))]
10007pub struct Booland {
10008    pub this: Box<Expression>,
10009    pub expression: Box<Expression>,
10010}
10011
10012/// Boolor
10013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10014#[cfg_attr(feature = "bindings", derive(TS))]
10015pub struct Boolor {
10016    pub this: Box<Expression>,
10017    pub expression: Box<Expression>,
10018}
10019
10020/// ParameterizedAgg
10021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10022#[cfg_attr(feature = "bindings", derive(TS))]
10023pub struct ParameterizedAgg {
10024    pub this: Box<Expression>,
10025    #[serde(default)]
10026    pub expressions: Vec<Expression>,
10027    #[serde(default)]
10028    pub params: Vec<Expression>,
10029}
10030
10031/// ArgMax
10032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10033#[cfg_attr(feature = "bindings", derive(TS))]
10034pub struct ArgMax {
10035    pub this: Box<Expression>,
10036    pub expression: Box<Expression>,
10037    #[serde(default)]
10038    pub count: Option<Box<Expression>>,
10039}
10040
10041/// ArgMin
10042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10043#[cfg_attr(feature = "bindings", derive(TS))]
10044pub struct ArgMin {
10045    pub this: Box<Expression>,
10046    pub expression: Box<Expression>,
10047    #[serde(default)]
10048    pub count: Option<Box<Expression>>,
10049}
10050
10051/// ApproxTopK
10052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10053#[cfg_attr(feature = "bindings", derive(TS))]
10054pub struct ApproxTopK {
10055    pub this: Box<Expression>,
10056    #[serde(default)]
10057    pub expression: Option<Box<Expression>>,
10058    #[serde(default)]
10059    pub counters: Option<Box<Expression>>,
10060}
10061
10062/// ApproxTopKAccumulate
10063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10064#[cfg_attr(feature = "bindings", derive(TS))]
10065pub struct ApproxTopKAccumulate {
10066    pub this: Box<Expression>,
10067    #[serde(default)]
10068    pub expression: Option<Box<Expression>>,
10069}
10070
10071/// ApproxTopKCombine
10072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10073#[cfg_attr(feature = "bindings", derive(TS))]
10074pub struct ApproxTopKCombine {
10075    pub this: Box<Expression>,
10076    #[serde(default)]
10077    pub expression: Option<Box<Expression>>,
10078}
10079
10080/// ApproxTopKEstimate
10081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10082#[cfg_attr(feature = "bindings", derive(TS))]
10083pub struct ApproxTopKEstimate {
10084    pub this: Box<Expression>,
10085    #[serde(default)]
10086    pub expression: Option<Box<Expression>>,
10087}
10088
10089/// ApproxTopSum
10090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10091#[cfg_attr(feature = "bindings", derive(TS))]
10092pub struct ApproxTopSum {
10093    pub this: Box<Expression>,
10094    pub expression: Box<Expression>,
10095    #[serde(default)]
10096    pub count: Option<Box<Expression>>,
10097}
10098
10099/// ApproxQuantiles
10100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10101#[cfg_attr(feature = "bindings", derive(TS))]
10102pub struct ApproxQuantiles {
10103    pub this: Box<Expression>,
10104    #[serde(default)]
10105    pub expression: Option<Box<Expression>>,
10106}
10107
10108/// Minhash
10109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10110#[cfg_attr(feature = "bindings", derive(TS))]
10111pub struct Minhash {
10112    pub this: Box<Expression>,
10113    #[serde(default)]
10114    pub expressions: Vec<Expression>,
10115}
10116
10117/// FarmFingerprint
10118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10119#[cfg_attr(feature = "bindings", derive(TS))]
10120pub struct FarmFingerprint {
10121    #[serde(default)]
10122    pub expressions: Vec<Expression>,
10123}
10124
10125/// Float64
10126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10127#[cfg_attr(feature = "bindings", derive(TS))]
10128pub struct Float64 {
10129    pub this: Box<Expression>,
10130    #[serde(default)]
10131    pub expression: Option<Box<Expression>>,
10132}
10133
10134/// Transform
10135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10136#[cfg_attr(feature = "bindings", derive(TS))]
10137pub struct Transform {
10138    pub this: Box<Expression>,
10139    pub expression: Box<Expression>,
10140}
10141
10142/// Translate
10143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10144#[cfg_attr(feature = "bindings", derive(TS))]
10145pub struct Translate {
10146    pub this: Box<Expression>,
10147    #[serde(default)]
10148    pub from_: Option<Box<Expression>>,
10149    #[serde(default)]
10150    pub to: Option<Box<Expression>>,
10151}
10152
10153/// Grouping
10154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10155#[cfg_attr(feature = "bindings", derive(TS))]
10156pub struct Grouping {
10157    #[serde(default)]
10158    pub expressions: Vec<Expression>,
10159}
10160
10161/// GroupingId
10162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10163#[cfg_attr(feature = "bindings", derive(TS))]
10164pub struct GroupingId {
10165    #[serde(default)]
10166    pub expressions: Vec<Expression>,
10167}
10168
10169/// Anonymous
10170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10171#[cfg_attr(feature = "bindings", derive(TS))]
10172pub struct Anonymous {
10173    pub this: Box<Expression>,
10174    #[serde(default)]
10175    pub expressions: Vec<Expression>,
10176}
10177
10178/// AnonymousAggFunc
10179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10180#[cfg_attr(feature = "bindings", derive(TS))]
10181pub struct AnonymousAggFunc {
10182    pub this: Box<Expression>,
10183    #[serde(default)]
10184    pub expressions: Vec<Expression>,
10185}
10186
10187/// CombinedAggFunc
10188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10189#[cfg_attr(feature = "bindings", derive(TS))]
10190pub struct CombinedAggFunc {
10191    pub this: Box<Expression>,
10192    #[serde(default)]
10193    pub expressions: Vec<Expression>,
10194}
10195
10196/// CombinedParameterizedAgg
10197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10198#[cfg_attr(feature = "bindings", derive(TS))]
10199pub struct CombinedParameterizedAgg {
10200    pub this: Box<Expression>,
10201    #[serde(default)]
10202    pub expressions: Vec<Expression>,
10203    #[serde(default)]
10204    pub params: Vec<Expression>,
10205}
10206
10207/// HashAgg
10208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10209#[cfg_attr(feature = "bindings", derive(TS))]
10210pub struct HashAgg {
10211    pub this: Box<Expression>,
10212    #[serde(default)]
10213    pub expressions: Vec<Expression>,
10214}
10215
10216/// Hll
10217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10218#[cfg_attr(feature = "bindings", derive(TS))]
10219pub struct Hll {
10220    pub this: Box<Expression>,
10221    #[serde(default)]
10222    pub expressions: Vec<Expression>,
10223}
10224
10225/// Apply
10226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10227#[cfg_attr(feature = "bindings", derive(TS))]
10228pub struct Apply {
10229    pub this: Box<Expression>,
10230    pub expression: Box<Expression>,
10231}
10232
10233/// ToBoolean
10234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10235#[cfg_attr(feature = "bindings", derive(TS))]
10236pub struct ToBoolean {
10237    pub this: Box<Expression>,
10238    #[serde(default)]
10239    pub safe: Option<Box<Expression>>,
10240}
10241
10242/// List
10243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10244#[cfg_attr(feature = "bindings", derive(TS))]
10245pub struct List {
10246    #[serde(default)]
10247    pub expressions: Vec<Expression>,
10248}
10249
10250/// ToMap - Materialize-style map constructor
10251/// Can hold either:
10252/// - A SELECT subquery (MAP(SELECT 'a', 1))
10253/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10255#[cfg_attr(feature = "bindings", derive(TS))]
10256pub struct ToMap {
10257    /// Either a Select subquery or a Struct containing PropertyEQ entries
10258    pub this: Box<Expression>,
10259}
10260
10261/// Pad
10262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10263#[cfg_attr(feature = "bindings", derive(TS))]
10264pub struct Pad {
10265    pub this: Box<Expression>,
10266    pub expression: Box<Expression>,
10267    #[serde(default)]
10268    pub fill_pattern: Option<Box<Expression>>,
10269    #[serde(default)]
10270    pub is_left: Option<Box<Expression>>,
10271}
10272
10273/// ToChar
10274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10275#[cfg_attr(feature = "bindings", derive(TS))]
10276pub struct ToChar {
10277    pub this: Box<Expression>,
10278    #[serde(default)]
10279    pub format: Option<String>,
10280    #[serde(default)]
10281    pub nlsparam: Option<Box<Expression>>,
10282    #[serde(default)]
10283    pub is_numeric: Option<Box<Expression>>,
10284}
10285
10286/// StringFunc - String type conversion function (BigQuery STRING)
10287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10288#[cfg_attr(feature = "bindings", derive(TS))]
10289pub struct StringFunc {
10290    pub this: Box<Expression>,
10291    #[serde(default)]
10292    pub zone: Option<Box<Expression>>,
10293}
10294
10295/// ToNumber
10296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10297#[cfg_attr(feature = "bindings", derive(TS))]
10298pub struct ToNumber {
10299    pub this: Box<Expression>,
10300    #[serde(default)]
10301    pub format: Option<Box<Expression>>,
10302    #[serde(default)]
10303    pub nlsparam: Option<Box<Expression>>,
10304    #[serde(default)]
10305    pub precision: Option<Box<Expression>>,
10306    #[serde(default)]
10307    pub scale: Option<Box<Expression>>,
10308    #[serde(default)]
10309    pub safe: Option<Box<Expression>>,
10310    #[serde(default)]
10311    pub safe_name: Option<Box<Expression>>,
10312}
10313
10314/// ToDouble
10315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10316#[cfg_attr(feature = "bindings", derive(TS))]
10317pub struct ToDouble {
10318    pub this: Box<Expression>,
10319    #[serde(default)]
10320    pub format: Option<String>,
10321    #[serde(default)]
10322    pub safe: Option<Box<Expression>>,
10323}
10324
10325/// ToDecfloat
10326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10327#[cfg_attr(feature = "bindings", derive(TS))]
10328pub struct ToDecfloat {
10329    pub this: Box<Expression>,
10330    #[serde(default)]
10331    pub format: Option<String>,
10332}
10333
10334/// TryToDecfloat
10335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10336#[cfg_attr(feature = "bindings", derive(TS))]
10337pub struct TryToDecfloat {
10338    pub this: Box<Expression>,
10339    #[serde(default)]
10340    pub format: Option<String>,
10341}
10342
10343/// ToFile
10344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10345#[cfg_attr(feature = "bindings", derive(TS))]
10346pub struct ToFile {
10347    pub this: Box<Expression>,
10348    #[serde(default)]
10349    pub path: Option<Box<Expression>>,
10350    #[serde(default)]
10351    pub safe: Option<Box<Expression>>,
10352}
10353
10354/// Columns
10355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10356#[cfg_attr(feature = "bindings", derive(TS))]
10357pub struct Columns {
10358    pub this: Box<Expression>,
10359    #[serde(default)]
10360    pub unpack: Option<Box<Expression>>,
10361}
10362
10363/// ConvertToCharset
10364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10365#[cfg_attr(feature = "bindings", derive(TS))]
10366pub struct ConvertToCharset {
10367    pub this: Box<Expression>,
10368    #[serde(default)]
10369    pub dest: Option<Box<Expression>>,
10370    #[serde(default)]
10371    pub source: Option<Box<Expression>>,
10372}
10373
10374/// ConvertTimezone
10375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10376#[cfg_attr(feature = "bindings", derive(TS))]
10377pub struct ConvertTimezone {
10378    #[serde(default)]
10379    pub source_tz: Option<Box<Expression>>,
10380    #[serde(default)]
10381    pub target_tz: Option<Box<Expression>>,
10382    #[serde(default)]
10383    pub timestamp: Option<Box<Expression>>,
10384    #[serde(default)]
10385    pub options: Vec<Expression>,
10386}
10387
10388/// GenerateSeries
10389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10390#[cfg_attr(feature = "bindings", derive(TS))]
10391pub struct GenerateSeries {
10392    #[serde(default)]
10393    pub start: Option<Box<Expression>>,
10394    #[serde(default)]
10395    pub end: Option<Box<Expression>>,
10396    #[serde(default)]
10397    pub step: Option<Box<Expression>>,
10398    #[serde(default)]
10399    pub is_end_exclusive: Option<Box<Expression>>,
10400}
10401
10402/// AIAgg
10403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10404#[cfg_attr(feature = "bindings", derive(TS))]
10405pub struct AIAgg {
10406    pub this: Box<Expression>,
10407    pub expression: Box<Expression>,
10408}
10409
10410/// AIClassify
10411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10412#[cfg_attr(feature = "bindings", derive(TS))]
10413pub struct AIClassify {
10414    pub this: Box<Expression>,
10415    #[serde(default)]
10416    pub categories: Option<Box<Expression>>,
10417    #[serde(default)]
10418    pub config: Option<Box<Expression>>,
10419}
10420
10421/// ArrayAll
10422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10423#[cfg_attr(feature = "bindings", derive(TS))]
10424pub struct ArrayAll {
10425    pub this: Box<Expression>,
10426    pub expression: Box<Expression>,
10427}
10428
10429/// ArrayAny
10430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10431#[cfg_attr(feature = "bindings", derive(TS))]
10432pub struct ArrayAny {
10433    pub this: Box<Expression>,
10434    pub expression: Box<Expression>,
10435}
10436
10437/// ArrayConstructCompact
10438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10439#[cfg_attr(feature = "bindings", derive(TS))]
10440pub struct ArrayConstructCompact {
10441    #[serde(default)]
10442    pub expressions: Vec<Expression>,
10443}
10444
10445/// StPoint
10446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10447#[cfg_attr(feature = "bindings", derive(TS))]
10448pub struct StPoint {
10449    pub this: Box<Expression>,
10450    pub expression: Box<Expression>,
10451    #[serde(default)]
10452    pub null: Option<Box<Expression>>,
10453}
10454
10455/// StDistance
10456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10457#[cfg_attr(feature = "bindings", derive(TS))]
10458pub struct StDistance {
10459    pub this: Box<Expression>,
10460    pub expression: Box<Expression>,
10461    #[serde(default)]
10462    pub use_spheroid: Option<Box<Expression>>,
10463}
10464
10465/// StringToArray
10466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10467#[cfg_attr(feature = "bindings", derive(TS))]
10468pub struct StringToArray {
10469    pub this: Box<Expression>,
10470    #[serde(default)]
10471    pub expression: Option<Box<Expression>>,
10472    #[serde(default)]
10473    pub null: Option<Box<Expression>>,
10474}
10475
10476/// ArraySum
10477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10478#[cfg_attr(feature = "bindings", derive(TS))]
10479pub struct ArraySum {
10480    pub this: Box<Expression>,
10481    #[serde(default)]
10482    pub expression: Option<Box<Expression>>,
10483}
10484
10485/// ObjectAgg
10486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10487#[cfg_attr(feature = "bindings", derive(TS))]
10488pub struct ObjectAgg {
10489    pub this: Box<Expression>,
10490    pub expression: Box<Expression>,
10491}
10492
10493/// CastToStrType
10494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10495#[cfg_attr(feature = "bindings", derive(TS))]
10496pub struct CastToStrType {
10497    pub this: Box<Expression>,
10498    #[serde(default)]
10499    pub to: Option<Box<Expression>>,
10500}
10501
10502/// CheckJson
10503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10504#[cfg_attr(feature = "bindings", derive(TS))]
10505pub struct CheckJson {
10506    pub this: Box<Expression>,
10507}
10508
10509/// CheckXml
10510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10511#[cfg_attr(feature = "bindings", derive(TS))]
10512pub struct CheckXml {
10513    pub this: Box<Expression>,
10514    #[serde(default)]
10515    pub disable_auto_convert: Option<Box<Expression>>,
10516}
10517
10518/// TranslateCharacters
10519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10520#[cfg_attr(feature = "bindings", derive(TS))]
10521pub struct TranslateCharacters {
10522    pub this: Box<Expression>,
10523    pub expression: Box<Expression>,
10524    #[serde(default)]
10525    pub with_error: Option<Box<Expression>>,
10526}
10527
10528/// CurrentSchemas
10529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10530#[cfg_attr(feature = "bindings", derive(TS))]
10531pub struct CurrentSchemas {
10532    #[serde(default)]
10533    pub this: Option<Box<Expression>>,
10534}
10535
10536/// CurrentDatetime
10537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10538#[cfg_attr(feature = "bindings", derive(TS))]
10539pub struct CurrentDatetime {
10540    #[serde(default)]
10541    pub this: Option<Box<Expression>>,
10542}
10543
10544/// Localtime
10545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10546#[cfg_attr(feature = "bindings", derive(TS))]
10547pub struct Localtime {
10548    #[serde(default)]
10549    pub this: Option<Box<Expression>>,
10550}
10551
10552/// Localtimestamp
10553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10554#[cfg_attr(feature = "bindings", derive(TS))]
10555pub struct Localtimestamp {
10556    #[serde(default)]
10557    pub this: Option<Box<Expression>>,
10558}
10559
10560/// Systimestamp
10561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10562#[cfg_attr(feature = "bindings", derive(TS))]
10563pub struct Systimestamp {
10564    #[serde(default)]
10565    pub this: Option<Box<Expression>>,
10566}
10567
10568/// CurrentSchema
10569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10570#[cfg_attr(feature = "bindings", derive(TS))]
10571pub struct CurrentSchema {
10572    #[serde(default)]
10573    pub this: Option<Box<Expression>>,
10574}
10575
10576/// CurrentUser
10577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10578#[cfg_attr(feature = "bindings", derive(TS))]
10579pub struct CurrentUser {
10580    #[serde(default)]
10581    pub this: Option<Box<Expression>>,
10582}
10583
10584/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10586#[cfg_attr(feature = "bindings", derive(TS))]
10587pub struct SessionUser;
10588
10589/// JSONPathRoot - Represents $ in JSON path expressions
10590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10591#[cfg_attr(feature = "bindings", derive(TS))]
10592pub struct JSONPathRoot;
10593
10594/// UtcTime
10595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10596#[cfg_attr(feature = "bindings", derive(TS))]
10597pub struct UtcTime {
10598    #[serde(default)]
10599    pub this: Option<Box<Expression>>,
10600}
10601
10602/// UtcTimestamp
10603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10604#[cfg_attr(feature = "bindings", derive(TS))]
10605pub struct UtcTimestamp {
10606    #[serde(default)]
10607    pub this: Option<Box<Expression>>,
10608}
10609
10610/// TimestampFunc - TIMESTAMP constructor function
10611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10612#[cfg_attr(feature = "bindings", derive(TS))]
10613pub struct TimestampFunc {
10614    #[serde(default)]
10615    pub this: Option<Box<Expression>>,
10616    #[serde(default)]
10617    pub zone: Option<Box<Expression>>,
10618    #[serde(default)]
10619    pub with_tz: Option<bool>,
10620    #[serde(default)]
10621    pub safe: Option<bool>,
10622}
10623
10624/// DateBin
10625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10626#[cfg_attr(feature = "bindings", derive(TS))]
10627pub struct DateBin {
10628    pub this: Box<Expression>,
10629    pub expression: Box<Expression>,
10630    #[serde(default)]
10631    pub unit: Option<String>,
10632    #[serde(default)]
10633    pub zone: Option<Box<Expression>>,
10634    #[serde(default)]
10635    pub origin: Option<Box<Expression>>,
10636}
10637
10638/// Datetime
10639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10640#[cfg_attr(feature = "bindings", derive(TS))]
10641pub struct Datetime {
10642    pub this: Box<Expression>,
10643    #[serde(default)]
10644    pub expression: Option<Box<Expression>>,
10645}
10646
10647/// DatetimeAdd
10648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10649#[cfg_attr(feature = "bindings", derive(TS))]
10650pub struct DatetimeAdd {
10651    pub this: Box<Expression>,
10652    pub expression: Box<Expression>,
10653    #[serde(default)]
10654    pub unit: Option<String>,
10655}
10656
10657/// DatetimeSub
10658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10659#[cfg_attr(feature = "bindings", derive(TS))]
10660pub struct DatetimeSub {
10661    pub this: Box<Expression>,
10662    pub expression: Box<Expression>,
10663    #[serde(default)]
10664    pub unit: Option<String>,
10665}
10666
10667/// DatetimeDiff
10668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10669#[cfg_attr(feature = "bindings", derive(TS))]
10670pub struct DatetimeDiff {
10671    pub this: Box<Expression>,
10672    pub expression: Box<Expression>,
10673    #[serde(default)]
10674    pub unit: Option<String>,
10675}
10676
10677/// DatetimeTrunc
10678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10679#[cfg_attr(feature = "bindings", derive(TS))]
10680pub struct DatetimeTrunc {
10681    pub this: Box<Expression>,
10682    pub unit: String,
10683    #[serde(default)]
10684    pub zone: Option<Box<Expression>>,
10685}
10686
10687/// Dayname
10688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10689#[cfg_attr(feature = "bindings", derive(TS))]
10690pub struct Dayname {
10691    pub this: Box<Expression>,
10692    #[serde(default)]
10693    pub abbreviated: Option<Box<Expression>>,
10694}
10695
10696/// MakeInterval
10697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10698#[cfg_attr(feature = "bindings", derive(TS))]
10699pub struct MakeInterval {
10700    #[serde(default)]
10701    pub year: Option<Box<Expression>>,
10702    #[serde(default)]
10703    pub month: Option<Box<Expression>>,
10704    #[serde(default)]
10705    pub week: Option<Box<Expression>>,
10706    #[serde(default)]
10707    pub day: Option<Box<Expression>>,
10708    #[serde(default)]
10709    pub hour: Option<Box<Expression>>,
10710    #[serde(default)]
10711    pub minute: Option<Box<Expression>>,
10712    #[serde(default)]
10713    pub second: Option<Box<Expression>>,
10714}
10715
10716/// PreviousDay
10717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10718#[cfg_attr(feature = "bindings", derive(TS))]
10719pub struct PreviousDay {
10720    pub this: Box<Expression>,
10721    pub expression: Box<Expression>,
10722}
10723
10724/// Elt
10725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10726#[cfg_attr(feature = "bindings", derive(TS))]
10727pub struct Elt {
10728    pub this: Box<Expression>,
10729    #[serde(default)]
10730    pub expressions: Vec<Expression>,
10731}
10732
10733/// TimestampAdd
10734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10735#[cfg_attr(feature = "bindings", derive(TS))]
10736pub struct TimestampAdd {
10737    pub this: Box<Expression>,
10738    pub expression: Box<Expression>,
10739    #[serde(default)]
10740    pub unit: Option<String>,
10741}
10742
10743/// TimestampSub
10744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10745#[cfg_attr(feature = "bindings", derive(TS))]
10746pub struct TimestampSub {
10747    pub this: Box<Expression>,
10748    pub expression: Box<Expression>,
10749    #[serde(default)]
10750    pub unit: Option<String>,
10751}
10752
10753/// TimestampDiff
10754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10755#[cfg_attr(feature = "bindings", derive(TS))]
10756pub struct TimestampDiff {
10757    pub this: Box<Expression>,
10758    pub expression: Box<Expression>,
10759    #[serde(default)]
10760    pub unit: Option<String>,
10761}
10762
10763/// TimeSlice
10764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10765#[cfg_attr(feature = "bindings", derive(TS))]
10766pub struct TimeSlice {
10767    pub this: Box<Expression>,
10768    pub expression: Box<Expression>,
10769    pub unit: String,
10770    #[serde(default)]
10771    pub kind: Option<String>,
10772}
10773
10774/// TimeAdd
10775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10776#[cfg_attr(feature = "bindings", derive(TS))]
10777pub struct TimeAdd {
10778    pub this: Box<Expression>,
10779    pub expression: Box<Expression>,
10780    #[serde(default)]
10781    pub unit: Option<String>,
10782}
10783
10784/// TimeSub
10785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10786#[cfg_attr(feature = "bindings", derive(TS))]
10787pub struct TimeSub {
10788    pub this: Box<Expression>,
10789    pub expression: Box<Expression>,
10790    #[serde(default)]
10791    pub unit: Option<String>,
10792}
10793
10794/// TimeDiff
10795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10796#[cfg_attr(feature = "bindings", derive(TS))]
10797pub struct TimeDiff {
10798    pub this: Box<Expression>,
10799    pub expression: Box<Expression>,
10800    #[serde(default)]
10801    pub unit: Option<String>,
10802}
10803
10804/// TimeTrunc
10805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10806#[cfg_attr(feature = "bindings", derive(TS))]
10807pub struct TimeTrunc {
10808    pub this: Box<Expression>,
10809    pub unit: String,
10810    #[serde(default)]
10811    pub zone: Option<Box<Expression>>,
10812}
10813
10814/// DateFromParts
10815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10816#[cfg_attr(feature = "bindings", derive(TS))]
10817pub struct DateFromParts {
10818    #[serde(default)]
10819    pub year: Option<Box<Expression>>,
10820    #[serde(default)]
10821    pub month: Option<Box<Expression>>,
10822    #[serde(default)]
10823    pub day: Option<Box<Expression>>,
10824    #[serde(default)]
10825    pub allow_overflow: Option<Box<Expression>>,
10826}
10827
10828/// TimeFromParts
10829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10830#[cfg_attr(feature = "bindings", derive(TS))]
10831pub struct TimeFromParts {
10832    #[serde(default)]
10833    pub hour: Option<Box<Expression>>,
10834    #[serde(default)]
10835    pub min: Option<Box<Expression>>,
10836    #[serde(default)]
10837    pub sec: Option<Box<Expression>>,
10838    #[serde(default)]
10839    pub nano: Option<Box<Expression>>,
10840    #[serde(default)]
10841    pub fractions: Option<Box<Expression>>,
10842    #[serde(default)]
10843    pub precision: Option<i64>,
10844}
10845
10846/// DecodeCase
10847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10848#[cfg_attr(feature = "bindings", derive(TS))]
10849pub struct DecodeCase {
10850    #[serde(default)]
10851    pub expressions: Vec<Expression>,
10852}
10853
10854/// Decrypt
10855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10856#[cfg_attr(feature = "bindings", derive(TS))]
10857pub struct Decrypt {
10858    pub this: Box<Expression>,
10859    #[serde(default)]
10860    pub passphrase: Option<Box<Expression>>,
10861    #[serde(default)]
10862    pub aad: Option<Box<Expression>>,
10863    #[serde(default)]
10864    pub encryption_method: Option<Box<Expression>>,
10865    #[serde(default)]
10866    pub safe: Option<Box<Expression>>,
10867}
10868
10869/// DecryptRaw
10870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10871#[cfg_attr(feature = "bindings", derive(TS))]
10872pub struct DecryptRaw {
10873    pub this: Box<Expression>,
10874    #[serde(default)]
10875    pub key: Option<Box<Expression>>,
10876    #[serde(default)]
10877    pub iv: Option<Box<Expression>>,
10878    #[serde(default)]
10879    pub aad: Option<Box<Expression>>,
10880    #[serde(default)]
10881    pub encryption_method: Option<Box<Expression>>,
10882    #[serde(default)]
10883    pub aead: Option<Box<Expression>>,
10884    #[serde(default)]
10885    pub safe: Option<Box<Expression>>,
10886}
10887
10888/// Encode
10889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10890#[cfg_attr(feature = "bindings", derive(TS))]
10891pub struct Encode {
10892    pub this: Box<Expression>,
10893    #[serde(default)]
10894    pub charset: Option<Box<Expression>>,
10895}
10896
10897/// Encrypt
10898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10899#[cfg_attr(feature = "bindings", derive(TS))]
10900pub struct Encrypt {
10901    pub this: Box<Expression>,
10902    #[serde(default)]
10903    pub passphrase: Option<Box<Expression>>,
10904    #[serde(default)]
10905    pub aad: Option<Box<Expression>>,
10906    #[serde(default)]
10907    pub encryption_method: Option<Box<Expression>>,
10908}
10909
10910/// EncryptRaw
10911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10912#[cfg_attr(feature = "bindings", derive(TS))]
10913pub struct EncryptRaw {
10914    pub this: Box<Expression>,
10915    #[serde(default)]
10916    pub key: Option<Box<Expression>>,
10917    #[serde(default)]
10918    pub iv: Option<Box<Expression>>,
10919    #[serde(default)]
10920    pub aad: Option<Box<Expression>>,
10921    #[serde(default)]
10922    pub encryption_method: Option<Box<Expression>>,
10923}
10924
10925/// EqualNull
10926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10927#[cfg_attr(feature = "bindings", derive(TS))]
10928pub struct EqualNull {
10929    pub this: Box<Expression>,
10930    pub expression: Box<Expression>,
10931}
10932
10933/// ToBinary
10934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10935#[cfg_attr(feature = "bindings", derive(TS))]
10936pub struct ToBinary {
10937    pub this: Box<Expression>,
10938    #[serde(default)]
10939    pub format: Option<String>,
10940    #[serde(default)]
10941    pub safe: Option<Box<Expression>>,
10942}
10943
10944/// Base64DecodeBinary
10945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10946#[cfg_attr(feature = "bindings", derive(TS))]
10947pub struct Base64DecodeBinary {
10948    pub this: Box<Expression>,
10949    #[serde(default)]
10950    pub alphabet: Option<Box<Expression>>,
10951}
10952
10953/// Base64DecodeString
10954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10955#[cfg_attr(feature = "bindings", derive(TS))]
10956pub struct Base64DecodeString {
10957    pub this: Box<Expression>,
10958    #[serde(default)]
10959    pub alphabet: Option<Box<Expression>>,
10960}
10961
10962/// Base64Encode
10963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10964#[cfg_attr(feature = "bindings", derive(TS))]
10965pub struct Base64Encode {
10966    pub this: Box<Expression>,
10967    #[serde(default)]
10968    pub max_line_length: Option<Box<Expression>>,
10969    #[serde(default)]
10970    pub alphabet: Option<Box<Expression>>,
10971}
10972
10973/// TryBase64DecodeBinary
10974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10975#[cfg_attr(feature = "bindings", derive(TS))]
10976pub struct TryBase64DecodeBinary {
10977    pub this: Box<Expression>,
10978    #[serde(default)]
10979    pub alphabet: Option<Box<Expression>>,
10980}
10981
10982/// TryBase64DecodeString
10983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10984#[cfg_attr(feature = "bindings", derive(TS))]
10985pub struct TryBase64DecodeString {
10986    pub this: Box<Expression>,
10987    #[serde(default)]
10988    pub alphabet: Option<Box<Expression>>,
10989}
10990
10991/// GapFill
10992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10993#[cfg_attr(feature = "bindings", derive(TS))]
10994pub struct GapFill {
10995    pub this: Box<Expression>,
10996    #[serde(default)]
10997    pub ts_column: Option<Box<Expression>>,
10998    #[serde(default)]
10999    pub bucket_width: Option<Box<Expression>>,
11000    #[serde(default)]
11001    pub partitioning_columns: Option<Box<Expression>>,
11002    #[serde(default)]
11003    pub value_columns: Option<Box<Expression>>,
11004    #[serde(default)]
11005    pub origin: Option<Box<Expression>>,
11006    #[serde(default)]
11007    pub ignore_nulls: Option<Box<Expression>>,
11008}
11009
11010/// GenerateDateArray
11011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11012#[cfg_attr(feature = "bindings", derive(TS))]
11013pub struct GenerateDateArray {
11014    #[serde(default)]
11015    pub start: Option<Box<Expression>>,
11016    #[serde(default)]
11017    pub end: Option<Box<Expression>>,
11018    #[serde(default)]
11019    pub step: Option<Box<Expression>>,
11020}
11021
11022/// GenerateTimestampArray
11023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11024#[cfg_attr(feature = "bindings", derive(TS))]
11025pub struct GenerateTimestampArray {
11026    #[serde(default)]
11027    pub start: Option<Box<Expression>>,
11028    #[serde(default)]
11029    pub end: Option<Box<Expression>>,
11030    #[serde(default)]
11031    pub step: Option<Box<Expression>>,
11032}
11033
11034/// GetExtract
11035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11036#[cfg_attr(feature = "bindings", derive(TS))]
11037pub struct GetExtract {
11038    pub this: Box<Expression>,
11039    pub expression: Box<Expression>,
11040}
11041
11042/// Getbit
11043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11044#[cfg_attr(feature = "bindings", derive(TS))]
11045pub struct Getbit {
11046    pub this: Box<Expression>,
11047    pub expression: Box<Expression>,
11048    #[serde(default)]
11049    pub zero_is_msb: Option<Box<Expression>>,
11050}
11051
11052/// OverflowTruncateBehavior
11053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11054#[cfg_attr(feature = "bindings", derive(TS))]
11055pub struct OverflowTruncateBehavior {
11056    #[serde(default)]
11057    pub this: Option<Box<Expression>>,
11058    #[serde(default)]
11059    pub with_count: Option<Box<Expression>>,
11060}
11061
11062/// HexEncode
11063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11064#[cfg_attr(feature = "bindings", derive(TS))]
11065pub struct HexEncode {
11066    pub this: Box<Expression>,
11067    #[serde(default)]
11068    pub case: Option<Box<Expression>>,
11069}
11070
11071/// Compress
11072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11073#[cfg_attr(feature = "bindings", derive(TS))]
11074pub struct Compress {
11075    pub this: Box<Expression>,
11076    #[serde(default)]
11077    pub method: Option<String>,
11078}
11079
11080/// DecompressBinary
11081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11082#[cfg_attr(feature = "bindings", derive(TS))]
11083pub struct DecompressBinary {
11084    pub this: Box<Expression>,
11085    pub method: String,
11086}
11087
11088/// DecompressString
11089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11090#[cfg_attr(feature = "bindings", derive(TS))]
11091pub struct DecompressString {
11092    pub this: Box<Expression>,
11093    pub method: String,
11094}
11095
11096/// Xor
11097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11098#[cfg_attr(feature = "bindings", derive(TS))]
11099pub struct Xor {
11100    #[serde(default)]
11101    pub this: Option<Box<Expression>>,
11102    #[serde(default)]
11103    pub expression: Option<Box<Expression>>,
11104    #[serde(default)]
11105    pub expressions: Vec<Expression>,
11106}
11107
11108/// Nullif
11109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11110#[cfg_attr(feature = "bindings", derive(TS))]
11111pub struct Nullif {
11112    pub this: Box<Expression>,
11113    pub expression: Box<Expression>,
11114}
11115
11116/// JSON
11117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11118#[cfg_attr(feature = "bindings", derive(TS))]
11119pub struct JSON {
11120    #[serde(default)]
11121    pub this: Option<Box<Expression>>,
11122    #[serde(default)]
11123    pub with_: Option<Box<Expression>>,
11124    #[serde(default)]
11125    pub unique: bool,
11126}
11127
11128/// JSONPath
11129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11130#[cfg_attr(feature = "bindings", derive(TS))]
11131pub struct JSONPath {
11132    #[serde(default)]
11133    pub expressions: Vec<Expression>,
11134    #[serde(default)]
11135    pub escape: Option<Box<Expression>>,
11136}
11137
11138/// JSONPathFilter
11139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11140#[cfg_attr(feature = "bindings", derive(TS))]
11141pub struct JSONPathFilter {
11142    pub this: Box<Expression>,
11143}
11144
11145/// JSONPathKey
11146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11147#[cfg_attr(feature = "bindings", derive(TS))]
11148pub struct JSONPathKey {
11149    pub this: Box<Expression>,
11150}
11151
11152/// JSONPathRecursive
11153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11154#[cfg_attr(feature = "bindings", derive(TS))]
11155pub struct JSONPathRecursive {
11156    #[serde(default)]
11157    pub this: Option<Box<Expression>>,
11158}
11159
11160/// JSONPathScript
11161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11162#[cfg_attr(feature = "bindings", derive(TS))]
11163pub struct JSONPathScript {
11164    pub this: Box<Expression>,
11165}
11166
11167/// JSONPathSlice
11168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11169#[cfg_attr(feature = "bindings", derive(TS))]
11170pub struct JSONPathSlice {
11171    #[serde(default)]
11172    pub start: Option<Box<Expression>>,
11173    #[serde(default)]
11174    pub end: Option<Box<Expression>>,
11175    #[serde(default)]
11176    pub step: Option<Box<Expression>>,
11177}
11178
11179/// JSONPathSelector
11180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11181#[cfg_attr(feature = "bindings", derive(TS))]
11182pub struct JSONPathSelector {
11183    pub this: Box<Expression>,
11184}
11185
11186/// JSONPathSubscript
11187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11188#[cfg_attr(feature = "bindings", derive(TS))]
11189pub struct JSONPathSubscript {
11190    pub this: Box<Expression>,
11191}
11192
11193/// JSONPathUnion
11194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11195#[cfg_attr(feature = "bindings", derive(TS))]
11196pub struct JSONPathUnion {
11197    #[serde(default)]
11198    pub expressions: Vec<Expression>,
11199}
11200
11201/// Format
11202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11203#[cfg_attr(feature = "bindings", derive(TS))]
11204pub struct Format {
11205    pub this: Box<Expression>,
11206    #[serde(default)]
11207    pub expressions: Vec<Expression>,
11208}
11209
11210/// JSONKeys
11211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11212#[cfg_attr(feature = "bindings", derive(TS))]
11213pub struct JSONKeys {
11214    pub this: Box<Expression>,
11215    #[serde(default)]
11216    pub expression: Option<Box<Expression>>,
11217    #[serde(default)]
11218    pub expressions: Vec<Expression>,
11219}
11220
11221/// JSONKeyValue
11222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11223#[cfg_attr(feature = "bindings", derive(TS))]
11224pub struct JSONKeyValue {
11225    pub this: Box<Expression>,
11226    pub expression: Box<Expression>,
11227}
11228
11229/// JSONKeysAtDepth
11230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11231#[cfg_attr(feature = "bindings", derive(TS))]
11232pub struct JSONKeysAtDepth {
11233    pub this: Box<Expression>,
11234    #[serde(default)]
11235    pub expression: Option<Box<Expression>>,
11236    #[serde(default)]
11237    pub mode: Option<Box<Expression>>,
11238}
11239
11240/// JSONObject
11241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11242#[cfg_attr(feature = "bindings", derive(TS))]
11243pub struct JSONObject {
11244    #[serde(default)]
11245    pub expressions: Vec<Expression>,
11246    #[serde(default)]
11247    pub null_handling: Option<Box<Expression>>,
11248    #[serde(default)]
11249    pub unique_keys: Option<Box<Expression>>,
11250    #[serde(default)]
11251    pub return_type: Option<Box<Expression>>,
11252    #[serde(default)]
11253    pub encoding: Option<Box<Expression>>,
11254}
11255
11256/// JSONObjectAgg
11257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11258#[cfg_attr(feature = "bindings", derive(TS))]
11259pub struct JSONObjectAgg {
11260    #[serde(default)]
11261    pub expressions: Vec<Expression>,
11262    #[serde(default)]
11263    pub null_handling: Option<Box<Expression>>,
11264    #[serde(default)]
11265    pub unique_keys: Option<Box<Expression>>,
11266    #[serde(default)]
11267    pub return_type: Option<Box<Expression>>,
11268    #[serde(default)]
11269    pub encoding: Option<Box<Expression>>,
11270}
11271
11272/// JSONBObjectAgg
11273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11274#[cfg_attr(feature = "bindings", derive(TS))]
11275pub struct JSONBObjectAgg {
11276    pub this: Box<Expression>,
11277    pub expression: Box<Expression>,
11278}
11279
11280/// JSONArray
11281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11282#[cfg_attr(feature = "bindings", derive(TS))]
11283pub struct JSONArray {
11284    #[serde(default)]
11285    pub expressions: Vec<Expression>,
11286    #[serde(default)]
11287    pub null_handling: Option<Box<Expression>>,
11288    #[serde(default)]
11289    pub return_type: Option<Box<Expression>>,
11290    #[serde(default)]
11291    pub strict: Option<Box<Expression>>,
11292}
11293
11294/// JSONArrayAgg
11295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11296#[cfg_attr(feature = "bindings", derive(TS))]
11297pub struct JSONArrayAgg {
11298    pub this: Box<Expression>,
11299    #[serde(default)]
11300    pub order: Option<Box<Expression>>,
11301    #[serde(default)]
11302    pub null_handling: Option<Box<Expression>>,
11303    #[serde(default)]
11304    pub return_type: Option<Box<Expression>>,
11305    #[serde(default)]
11306    pub strict: Option<Box<Expression>>,
11307}
11308
11309/// JSONExists
11310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11311#[cfg_attr(feature = "bindings", derive(TS))]
11312pub struct JSONExists {
11313    pub this: Box<Expression>,
11314    #[serde(default)]
11315    pub path: Option<Box<Expression>>,
11316    #[serde(default)]
11317    pub passing: Option<Box<Expression>>,
11318    #[serde(default)]
11319    pub on_condition: Option<Box<Expression>>,
11320    #[serde(default)]
11321    pub from_dcolonqmark: Option<Box<Expression>>,
11322}
11323
11324/// JSONColumnDef
11325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11326#[cfg_attr(feature = "bindings", derive(TS))]
11327pub struct JSONColumnDef {
11328    #[serde(default)]
11329    pub this: Option<Box<Expression>>,
11330    #[serde(default)]
11331    pub kind: Option<String>,
11332    #[serde(default)]
11333    pub path: Option<Box<Expression>>,
11334    #[serde(default)]
11335    pub nested_schema: Option<Box<Expression>>,
11336    #[serde(default)]
11337    pub ordinality: Option<Box<Expression>>,
11338}
11339
11340/// JSONSchema
11341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11342#[cfg_attr(feature = "bindings", derive(TS))]
11343pub struct JSONSchema {
11344    #[serde(default)]
11345    pub expressions: Vec<Expression>,
11346}
11347
11348/// JSONSet
11349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11350#[cfg_attr(feature = "bindings", derive(TS))]
11351pub struct JSONSet {
11352    pub this: Box<Expression>,
11353    #[serde(default)]
11354    pub expressions: Vec<Expression>,
11355}
11356
11357/// JSONStripNulls
11358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11359#[cfg_attr(feature = "bindings", derive(TS))]
11360pub struct JSONStripNulls {
11361    pub this: Box<Expression>,
11362    #[serde(default)]
11363    pub expression: Option<Box<Expression>>,
11364    #[serde(default)]
11365    pub include_arrays: Option<Box<Expression>>,
11366    #[serde(default)]
11367    pub remove_empty: Option<Box<Expression>>,
11368}
11369
11370/// JSONValue
11371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11372#[cfg_attr(feature = "bindings", derive(TS))]
11373pub struct JSONValue {
11374    pub this: Box<Expression>,
11375    #[serde(default)]
11376    pub path: Option<Box<Expression>>,
11377    #[serde(default)]
11378    pub returning: Option<Box<Expression>>,
11379    #[serde(default)]
11380    pub on_condition: Option<Box<Expression>>,
11381}
11382
11383/// JSONValueArray
11384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11385#[cfg_attr(feature = "bindings", derive(TS))]
11386pub struct JSONValueArray {
11387    pub this: Box<Expression>,
11388    #[serde(default)]
11389    pub expression: Option<Box<Expression>>,
11390}
11391
11392/// JSONRemove
11393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11394#[cfg_attr(feature = "bindings", derive(TS))]
11395pub struct JSONRemove {
11396    pub this: Box<Expression>,
11397    #[serde(default)]
11398    pub expressions: Vec<Expression>,
11399}
11400
11401/// JSONTable
11402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11403#[cfg_attr(feature = "bindings", derive(TS))]
11404pub struct JSONTable {
11405    pub this: Box<Expression>,
11406    #[serde(default)]
11407    pub schema: Option<Box<Expression>>,
11408    #[serde(default)]
11409    pub path: Option<Box<Expression>>,
11410    #[serde(default)]
11411    pub error_handling: Option<Box<Expression>>,
11412    #[serde(default)]
11413    pub empty_handling: Option<Box<Expression>>,
11414}
11415
11416/// JSONType
11417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11418#[cfg_attr(feature = "bindings", derive(TS))]
11419pub struct JSONType {
11420    pub this: Box<Expression>,
11421    #[serde(default)]
11422    pub expression: Option<Box<Expression>>,
11423}
11424
11425/// ObjectInsert
11426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11427#[cfg_attr(feature = "bindings", derive(TS))]
11428pub struct ObjectInsert {
11429    pub this: Box<Expression>,
11430    #[serde(default)]
11431    pub key: Option<Box<Expression>>,
11432    #[serde(default)]
11433    pub value: Option<Box<Expression>>,
11434    #[serde(default)]
11435    pub update_flag: Option<Box<Expression>>,
11436}
11437
11438/// OpenJSONColumnDef
11439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11440#[cfg_attr(feature = "bindings", derive(TS))]
11441pub struct OpenJSONColumnDef {
11442    pub this: Box<Expression>,
11443    pub kind: String,
11444    #[serde(default)]
11445    pub path: Option<Box<Expression>>,
11446    #[serde(default)]
11447    pub as_json: Option<Box<Expression>>,
11448    /// The parsed data type for proper generation
11449    #[serde(default, skip_serializing_if = "Option::is_none")]
11450    pub data_type: Option<DataType>,
11451}
11452
11453/// OpenJSON
11454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11455#[cfg_attr(feature = "bindings", derive(TS))]
11456pub struct OpenJSON {
11457    pub this: Box<Expression>,
11458    #[serde(default)]
11459    pub path: Option<Box<Expression>>,
11460    #[serde(default)]
11461    pub expressions: Vec<Expression>,
11462}
11463
11464/// JSONBExists
11465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11466#[cfg_attr(feature = "bindings", derive(TS))]
11467pub struct JSONBExists {
11468    pub this: Box<Expression>,
11469    #[serde(default)]
11470    pub path: Option<Box<Expression>>,
11471}
11472
11473/// JSONCast
11474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11475#[cfg_attr(feature = "bindings", derive(TS))]
11476pub struct JSONCast {
11477    pub this: Box<Expression>,
11478    pub to: DataType,
11479}
11480
11481/// JSONExtract
11482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11483#[cfg_attr(feature = "bindings", derive(TS))]
11484pub struct JSONExtract {
11485    pub this: Box<Expression>,
11486    pub expression: Box<Expression>,
11487    #[serde(default)]
11488    pub only_json_types: Option<Box<Expression>>,
11489    #[serde(default)]
11490    pub expressions: Vec<Expression>,
11491    #[serde(default)]
11492    pub variant_extract: Option<Box<Expression>>,
11493    #[serde(default)]
11494    pub json_query: Option<Box<Expression>>,
11495    #[serde(default)]
11496    pub option: Option<Box<Expression>>,
11497    #[serde(default)]
11498    pub quote: Option<Box<Expression>>,
11499    #[serde(default)]
11500    pub on_condition: Option<Box<Expression>>,
11501    #[serde(default)]
11502    pub requires_json: Option<Box<Expression>>,
11503}
11504
11505/// JSONExtractQuote
11506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11507#[cfg_attr(feature = "bindings", derive(TS))]
11508pub struct JSONExtractQuote {
11509    #[serde(default)]
11510    pub option: Option<Box<Expression>>,
11511    #[serde(default)]
11512    pub scalar: Option<Box<Expression>>,
11513}
11514
11515/// JSONExtractArray
11516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11517#[cfg_attr(feature = "bindings", derive(TS))]
11518pub struct JSONExtractArray {
11519    pub this: Box<Expression>,
11520    #[serde(default)]
11521    pub expression: Option<Box<Expression>>,
11522}
11523
11524/// JSONExtractScalar
11525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11526#[cfg_attr(feature = "bindings", derive(TS))]
11527pub struct JSONExtractScalar {
11528    pub this: Box<Expression>,
11529    pub expression: Box<Expression>,
11530    #[serde(default)]
11531    pub only_json_types: Option<Box<Expression>>,
11532    #[serde(default)]
11533    pub expressions: Vec<Expression>,
11534    #[serde(default)]
11535    pub json_type: Option<Box<Expression>>,
11536    #[serde(default)]
11537    pub scalar_only: Option<Box<Expression>>,
11538}
11539
11540/// JSONBExtractScalar
11541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11542#[cfg_attr(feature = "bindings", derive(TS))]
11543pub struct JSONBExtractScalar {
11544    pub this: Box<Expression>,
11545    pub expression: Box<Expression>,
11546    #[serde(default)]
11547    pub json_type: Option<Box<Expression>>,
11548}
11549
11550/// JSONFormat
11551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11552#[cfg_attr(feature = "bindings", derive(TS))]
11553pub struct JSONFormat {
11554    #[serde(default)]
11555    pub this: Option<Box<Expression>>,
11556    #[serde(default)]
11557    pub options: Vec<Expression>,
11558    #[serde(default)]
11559    pub is_json: Option<Box<Expression>>,
11560    #[serde(default)]
11561    pub to_json: Option<Box<Expression>>,
11562}
11563
11564/// JSONArrayAppend
11565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11566#[cfg_attr(feature = "bindings", derive(TS))]
11567pub struct JSONArrayAppend {
11568    pub this: Box<Expression>,
11569    #[serde(default)]
11570    pub expressions: Vec<Expression>,
11571}
11572
11573/// JSONArrayContains
11574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11575#[cfg_attr(feature = "bindings", derive(TS))]
11576pub struct JSONArrayContains {
11577    pub this: Box<Expression>,
11578    pub expression: Box<Expression>,
11579    #[serde(default)]
11580    pub json_type: Option<Box<Expression>>,
11581}
11582
11583/// JSONArrayInsert
11584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11585#[cfg_attr(feature = "bindings", derive(TS))]
11586pub struct JSONArrayInsert {
11587    pub this: Box<Expression>,
11588    #[serde(default)]
11589    pub expressions: Vec<Expression>,
11590}
11591
11592/// ParseJSON
11593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11594#[cfg_attr(feature = "bindings", derive(TS))]
11595pub struct ParseJSON {
11596    pub this: Box<Expression>,
11597    #[serde(default)]
11598    pub expression: Option<Box<Expression>>,
11599    #[serde(default)]
11600    pub safe: Option<Box<Expression>>,
11601}
11602
11603/// ParseUrl
11604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11605#[cfg_attr(feature = "bindings", derive(TS))]
11606pub struct ParseUrl {
11607    pub this: Box<Expression>,
11608    #[serde(default)]
11609    pub part_to_extract: Option<Box<Expression>>,
11610    #[serde(default)]
11611    pub key: Option<Box<Expression>>,
11612    #[serde(default)]
11613    pub permissive: Option<Box<Expression>>,
11614}
11615
11616/// ParseIp
11617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11618#[cfg_attr(feature = "bindings", derive(TS))]
11619pub struct ParseIp {
11620    pub this: Box<Expression>,
11621    #[serde(default)]
11622    pub type_: Option<Box<Expression>>,
11623    #[serde(default)]
11624    pub permissive: Option<Box<Expression>>,
11625}
11626
11627/// ParseTime
11628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11629#[cfg_attr(feature = "bindings", derive(TS))]
11630pub struct ParseTime {
11631    pub this: Box<Expression>,
11632    pub format: String,
11633}
11634
11635/// ParseDatetime
11636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11637#[cfg_attr(feature = "bindings", derive(TS))]
11638pub struct ParseDatetime {
11639    pub this: Box<Expression>,
11640    #[serde(default)]
11641    pub format: Option<String>,
11642    #[serde(default)]
11643    pub zone: Option<Box<Expression>>,
11644}
11645
11646/// Map
11647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11648#[cfg_attr(feature = "bindings", derive(TS))]
11649pub struct Map {
11650    #[serde(default)]
11651    pub keys: Vec<Expression>,
11652    #[serde(default)]
11653    pub values: Vec<Expression>,
11654}
11655
11656/// MapCat
11657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11658#[cfg_attr(feature = "bindings", derive(TS))]
11659pub struct MapCat {
11660    pub this: Box<Expression>,
11661    pub expression: Box<Expression>,
11662}
11663
11664/// MapDelete
11665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11666#[cfg_attr(feature = "bindings", derive(TS))]
11667pub struct MapDelete {
11668    pub this: Box<Expression>,
11669    #[serde(default)]
11670    pub expressions: Vec<Expression>,
11671}
11672
11673/// MapInsert
11674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11675#[cfg_attr(feature = "bindings", derive(TS))]
11676pub struct MapInsert {
11677    pub this: Box<Expression>,
11678    #[serde(default)]
11679    pub key: Option<Box<Expression>>,
11680    #[serde(default)]
11681    pub value: Option<Box<Expression>>,
11682    #[serde(default)]
11683    pub update_flag: Option<Box<Expression>>,
11684}
11685
11686/// MapPick
11687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11688#[cfg_attr(feature = "bindings", derive(TS))]
11689pub struct MapPick {
11690    pub this: Box<Expression>,
11691    #[serde(default)]
11692    pub expressions: Vec<Expression>,
11693}
11694
11695/// ScopeResolution
11696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11697#[cfg_attr(feature = "bindings", derive(TS))]
11698pub struct ScopeResolution {
11699    #[serde(default)]
11700    pub this: Option<Box<Expression>>,
11701    pub expression: Box<Expression>,
11702}
11703
11704/// Slice
11705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11706#[cfg_attr(feature = "bindings", derive(TS))]
11707pub struct Slice {
11708    #[serde(default)]
11709    pub this: Option<Box<Expression>>,
11710    #[serde(default)]
11711    pub expression: Option<Box<Expression>>,
11712    #[serde(default)]
11713    pub step: Option<Box<Expression>>,
11714}
11715
11716/// VarMap
11717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11718#[cfg_attr(feature = "bindings", derive(TS))]
11719pub struct VarMap {
11720    #[serde(default)]
11721    pub keys: Vec<Expression>,
11722    #[serde(default)]
11723    pub values: Vec<Expression>,
11724}
11725
11726/// MatchAgainst
11727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11728#[cfg_attr(feature = "bindings", derive(TS))]
11729pub struct MatchAgainst {
11730    pub this: Box<Expression>,
11731    #[serde(default)]
11732    pub expressions: Vec<Expression>,
11733    #[serde(default)]
11734    pub modifier: Option<Box<Expression>>,
11735}
11736
11737/// MD5Digest
11738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11739#[cfg_attr(feature = "bindings", derive(TS))]
11740pub struct MD5Digest {
11741    pub this: Box<Expression>,
11742    #[serde(default)]
11743    pub expressions: Vec<Expression>,
11744}
11745
11746/// Monthname
11747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11748#[cfg_attr(feature = "bindings", derive(TS))]
11749pub struct Monthname {
11750    pub this: Box<Expression>,
11751    #[serde(default)]
11752    pub abbreviated: Option<Box<Expression>>,
11753}
11754
11755/// Ntile
11756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11757#[cfg_attr(feature = "bindings", derive(TS))]
11758pub struct Ntile {
11759    #[serde(default)]
11760    pub this: Option<Box<Expression>>,
11761}
11762
11763/// Normalize
11764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11765#[cfg_attr(feature = "bindings", derive(TS))]
11766pub struct Normalize {
11767    pub this: Box<Expression>,
11768    #[serde(default)]
11769    pub form: Option<Box<Expression>>,
11770    #[serde(default)]
11771    pub is_casefold: Option<Box<Expression>>,
11772}
11773
11774/// Normal
11775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11776#[cfg_attr(feature = "bindings", derive(TS))]
11777pub struct Normal {
11778    pub this: Box<Expression>,
11779    #[serde(default)]
11780    pub stddev: Option<Box<Expression>>,
11781    #[serde(default)]
11782    pub gen: Option<Box<Expression>>,
11783}
11784
11785/// Predict
11786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11787#[cfg_attr(feature = "bindings", derive(TS))]
11788pub struct Predict {
11789    pub this: Box<Expression>,
11790    pub expression: Box<Expression>,
11791    #[serde(default)]
11792    pub params_struct: Option<Box<Expression>>,
11793}
11794
11795/// MLTranslate
11796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11797#[cfg_attr(feature = "bindings", derive(TS))]
11798pub struct MLTranslate {
11799    pub this: Box<Expression>,
11800    pub expression: Box<Expression>,
11801    #[serde(default)]
11802    pub params_struct: Option<Box<Expression>>,
11803}
11804
11805/// FeaturesAtTime
11806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11807#[cfg_attr(feature = "bindings", derive(TS))]
11808pub struct FeaturesAtTime {
11809    pub this: Box<Expression>,
11810    #[serde(default)]
11811    pub time: Option<Box<Expression>>,
11812    #[serde(default)]
11813    pub num_rows: Option<Box<Expression>>,
11814    #[serde(default)]
11815    pub ignore_feature_nulls: Option<Box<Expression>>,
11816}
11817
11818/// GenerateEmbedding
11819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11820#[cfg_attr(feature = "bindings", derive(TS))]
11821pub struct GenerateEmbedding {
11822    pub this: Box<Expression>,
11823    pub expression: Box<Expression>,
11824    #[serde(default)]
11825    pub params_struct: Option<Box<Expression>>,
11826    #[serde(default)]
11827    pub is_text: Option<Box<Expression>>,
11828}
11829
11830/// MLForecast
11831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11832#[cfg_attr(feature = "bindings", derive(TS))]
11833pub struct MLForecast {
11834    pub this: Box<Expression>,
11835    #[serde(default)]
11836    pub expression: Option<Box<Expression>>,
11837    #[serde(default)]
11838    pub params_struct: Option<Box<Expression>>,
11839}
11840
11841/// ModelAttribute
11842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11843#[cfg_attr(feature = "bindings", derive(TS))]
11844pub struct ModelAttribute {
11845    pub this: Box<Expression>,
11846    pub expression: Box<Expression>,
11847}
11848
11849/// VectorSearch
11850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11851#[cfg_attr(feature = "bindings", derive(TS))]
11852pub struct VectorSearch {
11853    pub this: Box<Expression>,
11854    #[serde(default)]
11855    pub column_to_search: Option<Box<Expression>>,
11856    #[serde(default)]
11857    pub query_table: Option<Box<Expression>>,
11858    #[serde(default)]
11859    pub query_column_to_search: Option<Box<Expression>>,
11860    #[serde(default)]
11861    pub top_k: Option<Box<Expression>>,
11862    #[serde(default)]
11863    pub distance_type: Option<Box<Expression>>,
11864    #[serde(default)]
11865    pub options: Vec<Expression>,
11866}
11867
11868/// Quantile
11869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11870#[cfg_attr(feature = "bindings", derive(TS))]
11871pub struct Quantile {
11872    pub this: Box<Expression>,
11873    #[serde(default)]
11874    pub quantile: Option<Box<Expression>>,
11875}
11876
11877/// ApproxQuantile
11878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11879#[cfg_attr(feature = "bindings", derive(TS))]
11880pub struct ApproxQuantile {
11881    pub this: Box<Expression>,
11882    #[serde(default)]
11883    pub quantile: Option<Box<Expression>>,
11884    #[serde(default)]
11885    pub accuracy: Option<Box<Expression>>,
11886    #[serde(default)]
11887    pub weight: Option<Box<Expression>>,
11888    #[serde(default)]
11889    pub error_tolerance: Option<Box<Expression>>,
11890}
11891
11892/// ApproxPercentileEstimate
11893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11894#[cfg_attr(feature = "bindings", derive(TS))]
11895pub struct ApproxPercentileEstimate {
11896    pub this: Box<Expression>,
11897    #[serde(default)]
11898    pub percentile: Option<Box<Expression>>,
11899}
11900
11901/// Randn
11902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11903#[cfg_attr(feature = "bindings", derive(TS))]
11904pub struct Randn {
11905    #[serde(default)]
11906    pub this: Option<Box<Expression>>,
11907}
11908
11909/// Randstr
11910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11911#[cfg_attr(feature = "bindings", derive(TS))]
11912pub struct Randstr {
11913    pub this: Box<Expression>,
11914    #[serde(default)]
11915    pub generator: Option<Box<Expression>>,
11916}
11917
11918/// RangeN
11919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11920#[cfg_attr(feature = "bindings", derive(TS))]
11921pub struct RangeN {
11922    pub this: Box<Expression>,
11923    #[serde(default)]
11924    pub expressions: Vec<Expression>,
11925    #[serde(default)]
11926    pub each: Option<Box<Expression>>,
11927}
11928
11929/// RangeBucket
11930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11931#[cfg_attr(feature = "bindings", derive(TS))]
11932pub struct RangeBucket {
11933    pub this: Box<Expression>,
11934    pub expression: Box<Expression>,
11935}
11936
11937/// ReadCSV
11938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11939#[cfg_attr(feature = "bindings", derive(TS))]
11940pub struct ReadCSV {
11941    pub this: Box<Expression>,
11942    #[serde(default)]
11943    pub expressions: Vec<Expression>,
11944}
11945
11946/// ReadParquet
11947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11948#[cfg_attr(feature = "bindings", derive(TS))]
11949pub struct ReadParquet {
11950    #[serde(default)]
11951    pub expressions: Vec<Expression>,
11952}
11953
11954/// Reduce
11955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11956#[cfg_attr(feature = "bindings", derive(TS))]
11957pub struct Reduce {
11958    pub this: Box<Expression>,
11959    #[serde(default)]
11960    pub initial: Option<Box<Expression>>,
11961    #[serde(default)]
11962    pub merge: Option<Box<Expression>>,
11963    #[serde(default)]
11964    pub finish: Option<Box<Expression>>,
11965}
11966
11967/// RegexpExtractAll
11968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11969#[cfg_attr(feature = "bindings", derive(TS))]
11970pub struct RegexpExtractAll {
11971    pub this: Box<Expression>,
11972    pub expression: Box<Expression>,
11973    #[serde(default)]
11974    pub group: Option<Box<Expression>>,
11975    #[serde(default)]
11976    pub parameters: Option<Box<Expression>>,
11977    #[serde(default)]
11978    pub position: Option<Box<Expression>>,
11979    #[serde(default)]
11980    pub occurrence: Option<Box<Expression>>,
11981}
11982
11983/// RegexpILike
11984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11985#[cfg_attr(feature = "bindings", derive(TS))]
11986pub struct RegexpILike {
11987    pub this: Box<Expression>,
11988    pub expression: Box<Expression>,
11989    #[serde(default)]
11990    pub flag: Option<Box<Expression>>,
11991}
11992
11993/// RegexpFullMatch
11994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11995#[cfg_attr(feature = "bindings", derive(TS))]
11996pub struct RegexpFullMatch {
11997    pub this: Box<Expression>,
11998    pub expression: Box<Expression>,
11999    #[serde(default)]
12000    pub options: Vec<Expression>,
12001}
12002
12003/// RegexpInstr
12004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12005#[cfg_attr(feature = "bindings", derive(TS))]
12006pub struct RegexpInstr {
12007    pub this: Box<Expression>,
12008    pub expression: Box<Expression>,
12009    #[serde(default)]
12010    pub position: Option<Box<Expression>>,
12011    #[serde(default)]
12012    pub occurrence: Option<Box<Expression>>,
12013    #[serde(default)]
12014    pub option: Option<Box<Expression>>,
12015    #[serde(default)]
12016    pub parameters: Option<Box<Expression>>,
12017    #[serde(default)]
12018    pub group: Option<Box<Expression>>,
12019}
12020
12021/// RegexpSplit
12022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12023#[cfg_attr(feature = "bindings", derive(TS))]
12024pub struct RegexpSplit {
12025    pub this: Box<Expression>,
12026    pub expression: Box<Expression>,
12027    #[serde(default)]
12028    pub limit: Option<Box<Expression>>,
12029}
12030
12031/// RegexpCount
12032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12033#[cfg_attr(feature = "bindings", derive(TS))]
12034pub struct RegexpCount {
12035    pub this: Box<Expression>,
12036    pub expression: Box<Expression>,
12037    #[serde(default)]
12038    pub position: Option<Box<Expression>>,
12039    #[serde(default)]
12040    pub parameters: Option<Box<Expression>>,
12041}
12042
12043/// RegrValx
12044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12045#[cfg_attr(feature = "bindings", derive(TS))]
12046pub struct RegrValx {
12047    pub this: Box<Expression>,
12048    pub expression: Box<Expression>,
12049}
12050
12051/// RegrValy
12052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12053#[cfg_attr(feature = "bindings", derive(TS))]
12054pub struct RegrValy {
12055    pub this: Box<Expression>,
12056    pub expression: Box<Expression>,
12057}
12058
12059/// RegrAvgy
12060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12061#[cfg_attr(feature = "bindings", derive(TS))]
12062pub struct RegrAvgy {
12063    pub this: Box<Expression>,
12064    pub expression: Box<Expression>,
12065}
12066
12067/// RegrAvgx
12068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12069#[cfg_attr(feature = "bindings", derive(TS))]
12070pub struct RegrAvgx {
12071    pub this: Box<Expression>,
12072    pub expression: Box<Expression>,
12073}
12074
12075/// RegrCount
12076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12077#[cfg_attr(feature = "bindings", derive(TS))]
12078pub struct RegrCount {
12079    pub this: Box<Expression>,
12080    pub expression: Box<Expression>,
12081}
12082
12083/// RegrIntercept
12084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12085#[cfg_attr(feature = "bindings", derive(TS))]
12086pub struct RegrIntercept {
12087    pub this: Box<Expression>,
12088    pub expression: Box<Expression>,
12089}
12090
12091/// RegrR2
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct RegrR2 {
12095    pub this: Box<Expression>,
12096    pub expression: Box<Expression>,
12097}
12098
12099/// RegrSxx
12100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12101#[cfg_attr(feature = "bindings", derive(TS))]
12102pub struct RegrSxx {
12103    pub this: Box<Expression>,
12104    pub expression: Box<Expression>,
12105}
12106
12107/// RegrSxy
12108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12109#[cfg_attr(feature = "bindings", derive(TS))]
12110pub struct RegrSxy {
12111    pub this: Box<Expression>,
12112    pub expression: Box<Expression>,
12113}
12114
12115/// RegrSyy
12116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12117#[cfg_attr(feature = "bindings", derive(TS))]
12118pub struct RegrSyy {
12119    pub this: Box<Expression>,
12120    pub expression: Box<Expression>,
12121}
12122
12123/// RegrSlope
12124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12125#[cfg_attr(feature = "bindings", derive(TS))]
12126pub struct RegrSlope {
12127    pub this: Box<Expression>,
12128    pub expression: Box<Expression>,
12129}
12130
12131/// SafeAdd
12132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12133#[cfg_attr(feature = "bindings", derive(TS))]
12134pub struct SafeAdd {
12135    pub this: Box<Expression>,
12136    pub expression: Box<Expression>,
12137}
12138
12139/// SafeDivide
12140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12141#[cfg_attr(feature = "bindings", derive(TS))]
12142pub struct SafeDivide {
12143    pub this: Box<Expression>,
12144    pub expression: Box<Expression>,
12145}
12146
12147/// SafeMultiply
12148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12149#[cfg_attr(feature = "bindings", derive(TS))]
12150pub struct SafeMultiply {
12151    pub this: Box<Expression>,
12152    pub expression: Box<Expression>,
12153}
12154
12155/// SafeSubtract
12156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12157#[cfg_attr(feature = "bindings", derive(TS))]
12158pub struct SafeSubtract {
12159    pub this: Box<Expression>,
12160    pub expression: Box<Expression>,
12161}
12162
12163/// SHA2
12164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12165#[cfg_attr(feature = "bindings", derive(TS))]
12166pub struct SHA2 {
12167    pub this: Box<Expression>,
12168    #[serde(default)]
12169    pub length: Option<i64>,
12170}
12171
12172/// SHA2Digest
12173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12174#[cfg_attr(feature = "bindings", derive(TS))]
12175pub struct SHA2Digest {
12176    pub this: Box<Expression>,
12177    #[serde(default)]
12178    pub length: Option<i64>,
12179}
12180
12181/// SortArray
12182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12183#[cfg_attr(feature = "bindings", derive(TS))]
12184pub struct SortArray {
12185    pub this: Box<Expression>,
12186    #[serde(default)]
12187    pub asc: Option<Box<Expression>>,
12188    #[serde(default)]
12189    pub nulls_first: Option<Box<Expression>>,
12190}
12191
12192/// SplitPart
12193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12194#[cfg_attr(feature = "bindings", derive(TS))]
12195pub struct SplitPart {
12196    pub this: Box<Expression>,
12197    #[serde(default)]
12198    pub delimiter: Option<Box<Expression>>,
12199    #[serde(default)]
12200    pub part_index: Option<Box<Expression>>,
12201}
12202
12203/// SUBSTRING_INDEX(str, delim, count)
12204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12205#[cfg_attr(feature = "bindings", derive(TS))]
12206pub struct SubstringIndex {
12207    pub this: Box<Expression>,
12208    #[serde(default)]
12209    pub delimiter: Option<Box<Expression>>,
12210    #[serde(default)]
12211    pub count: Option<Box<Expression>>,
12212}
12213
12214/// StandardHash
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct StandardHash {
12218    pub this: Box<Expression>,
12219    #[serde(default)]
12220    pub expression: Option<Box<Expression>>,
12221}
12222
12223/// StrPosition
12224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12225#[cfg_attr(feature = "bindings", derive(TS))]
12226pub struct StrPosition {
12227    pub this: Box<Expression>,
12228    #[serde(default)]
12229    pub substr: Option<Box<Expression>>,
12230    #[serde(default)]
12231    pub position: Option<Box<Expression>>,
12232    #[serde(default)]
12233    pub occurrence: Option<Box<Expression>>,
12234}
12235
12236/// Search
12237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12238#[cfg_attr(feature = "bindings", derive(TS))]
12239pub struct Search {
12240    pub this: Box<Expression>,
12241    pub expression: Box<Expression>,
12242    #[serde(default)]
12243    pub json_scope: Option<Box<Expression>>,
12244    #[serde(default)]
12245    pub analyzer: Option<Box<Expression>>,
12246    #[serde(default)]
12247    pub analyzer_options: Option<Box<Expression>>,
12248    #[serde(default)]
12249    pub search_mode: Option<Box<Expression>>,
12250}
12251
12252/// SearchIp
12253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12254#[cfg_attr(feature = "bindings", derive(TS))]
12255pub struct SearchIp {
12256    pub this: Box<Expression>,
12257    pub expression: Box<Expression>,
12258}
12259
12260/// StrToDate
12261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12262#[cfg_attr(feature = "bindings", derive(TS))]
12263pub struct StrToDate {
12264    pub this: Box<Expression>,
12265    #[serde(default)]
12266    pub format: Option<String>,
12267    #[serde(default)]
12268    pub safe: Option<Box<Expression>>,
12269}
12270
12271/// StrToTime
12272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12273#[cfg_attr(feature = "bindings", derive(TS))]
12274pub struct StrToTime {
12275    pub this: Box<Expression>,
12276    pub format: String,
12277    #[serde(default)]
12278    pub zone: Option<Box<Expression>>,
12279    #[serde(default)]
12280    pub safe: Option<Box<Expression>>,
12281    #[serde(default)]
12282    pub target_type: Option<Box<Expression>>,
12283}
12284
12285/// StrToUnix
12286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12287#[cfg_attr(feature = "bindings", derive(TS))]
12288pub struct StrToUnix {
12289    #[serde(default)]
12290    pub this: Option<Box<Expression>>,
12291    #[serde(default)]
12292    pub format: Option<String>,
12293}
12294
12295/// StrToMap
12296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12297#[cfg_attr(feature = "bindings", derive(TS))]
12298pub struct StrToMap {
12299    pub this: Box<Expression>,
12300    #[serde(default)]
12301    pub pair_delim: Option<Box<Expression>>,
12302    #[serde(default)]
12303    pub key_value_delim: Option<Box<Expression>>,
12304    #[serde(default)]
12305    pub duplicate_resolution_callback: Option<Box<Expression>>,
12306}
12307
12308/// NumberToStr
12309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12310#[cfg_attr(feature = "bindings", derive(TS))]
12311pub struct NumberToStr {
12312    pub this: Box<Expression>,
12313    pub format: String,
12314    #[serde(default)]
12315    pub culture: Option<Box<Expression>>,
12316}
12317
12318/// FromBase
12319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12320#[cfg_attr(feature = "bindings", derive(TS))]
12321pub struct FromBase {
12322    pub this: Box<Expression>,
12323    pub expression: Box<Expression>,
12324}
12325
12326/// Stuff
12327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12328#[cfg_attr(feature = "bindings", derive(TS))]
12329pub struct Stuff {
12330    pub this: Box<Expression>,
12331    #[serde(default)]
12332    pub start: Option<Box<Expression>>,
12333    #[serde(default)]
12334    pub length: Option<i64>,
12335    pub expression: Box<Expression>,
12336}
12337
12338/// TimeToStr
12339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12340#[cfg_attr(feature = "bindings", derive(TS))]
12341pub struct TimeToStr {
12342    pub this: Box<Expression>,
12343    pub format: String,
12344    #[serde(default)]
12345    pub culture: Option<Box<Expression>>,
12346    #[serde(default)]
12347    pub zone: Option<Box<Expression>>,
12348}
12349
12350/// TimeStrToTime
12351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12352#[cfg_attr(feature = "bindings", derive(TS))]
12353pub struct TimeStrToTime {
12354    pub this: Box<Expression>,
12355    #[serde(default)]
12356    pub zone: Option<Box<Expression>>,
12357}
12358
12359/// TsOrDsAdd
12360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12361#[cfg_attr(feature = "bindings", derive(TS))]
12362pub struct TsOrDsAdd {
12363    pub this: Box<Expression>,
12364    pub expression: Box<Expression>,
12365    #[serde(default)]
12366    pub unit: Option<String>,
12367    #[serde(default)]
12368    pub return_type: Option<Box<Expression>>,
12369}
12370
12371/// TsOrDsDiff
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct TsOrDsDiff {
12375    pub this: Box<Expression>,
12376    pub expression: Box<Expression>,
12377    #[serde(default)]
12378    pub unit: Option<String>,
12379}
12380
12381/// TsOrDsToDate
12382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12383#[cfg_attr(feature = "bindings", derive(TS))]
12384pub struct TsOrDsToDate {
12385    pub this: Box<Expression>,
12386    #[serde(default)]
12387    pub format: Option<String>,
12388    #[serde(default)]
12389    pub safe: Option<Box<Expression>>,
12390}
12391
12392/// TsOrDsToTime
12393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12394#[cfg_attr(feature = "bindings", derive(TS))]
12395pub struct TsOrDsToTime {
12396    pub this: Box<Expression>,
12397    #[serde(default)]
12398    pub format: Option<String>,
12399    #[serde(default)]
12400    pub safe: Option<Box<Expression>>,
12401}
12402
12403/// Unhex
12404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12405#[cfg_attr(feature = "bindings", derive(TS))]
12406pub struct Unhex {
12407    pub this: Box<Expression>,
12408    #[serde(default)]
12409    pub expression: Option<Box<Expression>>,
12410}
12411
12412/// Uniform
12413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12414#[cfg_attr(feature = "bindings", derive(TS))]
12415pub struct Uniform {
12416    pub this: Box<Expression>,
12417    pub expression: Box<Expression>,
12418    #[serde(default)]
12419    pub gen: Option<Box<Expression>>,
12420    #[serde(default)]
12421    pub seed: Option<Box<Expression>>,
12422}
12423
12424/// UnixToStr
12425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12426#[cfg_attr(feature = "bindings", derive(TS))]
12427pub struct UnixToStr {
12428    pub this: Box<Expression>,
12429    #[serde(default)]
12430    pub format: Option<String>,
12431}
12432
12433/// UnixToTime
12434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12435#[cfg_attr(feature = "bindings", derive(TS))]
12436pub struct UnixToTime {
12437    pub this: Box<Expression>,
12438    #[serde(default)]
12439    pub scale: Option<i64>,
12440    #[serde(default)]
12441    pub zone: Option<Box<Expression>>,
12442    #[serde(default)]
12443    pub hours: Option<Box<Expression>>,
12444    #[serde(default)]
12445    pub minutes: Option<Box<Expression>>,
12446    #[serde(default)]
12447    pub format: Option<String>,
12448    #[serde(default)]
12449    pub target_type: Option<Box<Expression>>,
12450}
12451
12452/// Uuid
12453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12454#[cfg_attr(feature = "bindings", derive(TS))]
12455pub struct Uuid {
12456    #[serde(default)]
12457    pub this: Option<Box<Expression>>,
12458    #[serde(default)]
12459    pub name: Option<String>,
12460    #[serde(default)]
12461    pub is_string: Option<Box<Expression>>,
12462}
12463
12464/// TimestampFromParts
12465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12466#[cfg_attr(feature = "bindings", derive(TS))]
12467pub struct TimestampFromParts {
12468    #[serde(default)]
12469    pub zone: Option<Box<Expression>>,
12470    #[serde(default)]
12471    pub milli: Option<Box<Expression>>,
12472    #[serde(default)]
12473    pub this: Option<Box<Expression>>,
12474    #[serde(default)]
12475    pub expression: Option<Box<Expression>>,
12476}
12477
12478/// TimestampTzFromParts
12479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12480#[cfg_attr(feature = "bindings", derive(TS))]
12481pub struct TimestampTzFromParts {
12482    #[serde(default)]
12483    pub zone: Option<Box<Expression>>,
12484}
12485
12486/// Corr
12487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12488#[cfg_attr(feature = "bindings", derive(TS))]
12489pub struct Corr {
12490    pub this: Box<Expression>,
12491    pub expression: Box<Expression>,
12492    #[serde(default)]
12493    pub null_on_zero_variance: Option<Box<Expression>>,
12494}
12495
12496/// WidthBucket
12497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12498#[cfg_attr(feature = "bindings", derive(TS))]
12499pub struct WidthBucket {
12500    pub this: Box<Expression>,
12501    #[serde(default)]
12502    pub min_value: Option<Box<Expression>>,
12503    #[serde(default)]
12504    pub max_value: Option<Box<Expression>>,
12505    #[serde(default)]
12506    pub num_buckets: Option<Box<Expression>>,
12507    #[serde(default)]
12508    pub threshold: Option<Box<Expression>>,
12509}
12510
12511/// CovarSamp
12512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12513#[cfg_attr(feature = "bindings", derive(TS))]
12514pub struct CovarSamp {
12515    pub this: Box<Expression>,
12516    pub expression: Box<Expression>,
12517}
12518
12519/// CovarPop
12520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12521#[cfg_attr(feature = "bindings", derive(TS))]
12522pub struct CovarPop {
12523    pub this: Box<Expression>,
12524    pub expression: Box<Expression>,
12525}
12526
12527/// Week
12528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12529#[cfg_attr(feature = "bindings", derive(TS))]
12530pub struct Week {
12531    pub this: Box<Expression>,
12532    #[serde(default)]
12533    pub mode: Option<Box<Expression>>,
12534}
12535
12536/// XMLElement
12537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12538#[cfg_attr(feature = "bindings", derive(TS))]
12539pub struct XMLElement {
12540    pub this: Box<Expression>,
12541    #[serde(default)]
12542    pub expressions: Vec<Expression>,
12543    #[serde(default)]
12544    pub evalname: Option<Box<Expression>>,
12545}
12546
12547/// XMLGet
12548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12549#[cfg_attr(feature = "bindings", derive(TS))]
12550pub struct XMLGet {
12551    pub this: Box<Expression>,
12552    pub expression: Box<Expression>,
12553    #[serde(default)]
12554    pub instance: Option<Box<Expression>>,
12555}
12556
12557/// XMLTable
12558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12559#[cfg_attr(feature = "bindings", derive(TS))]
12560pub struct XMLTable {
12561    pub this: Box<Expression>,
12562    #[serde(default)]
12563    pub namespaces: Option<Box<Expression>>,
12564    #[serde(default)]
12565    pub passing: Option<Box<Expression>>,
12566    #[serde(default)]
12567    pub columns: Vec<Expression>,
12568    #[serde(default)]
12569    pub by_ref: Option<Box<Expression>>,
12570}
12571
12572/// XMLKeyValueOption
12573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12574#[cfg_attr(feature = "bindings", derive(TS))]
12575pub struct XMLKeyValueOption {
12576    pub this: Box<Expression>,
12577    #[serde(default)]
12578    pub expression: Option<Box<Expression>>,
12579}
12580
12581/// Zipf
12582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12583#[cfg_attr(feature = "bindings", derive(TS))]
12584pub struct Zipf {
12585    pub this: Box<Expression>,
12586    #[serde(default)]
12587    pub elementcount: Option<Box<Expression>>,
12588    #[serde(default)]
12589    pub gen: Option<Box<Expression>>,
12590}
12591
12592/// Merge
12593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12594#[cfg_attr(feature = "bindings", derive(TS))]
12595pub struct Merge {
12596    pub this: Box<Expression>,
12597    pub using: Box<Expression>,
12598    #[serde(default)]
12599    pub on: Option<Box<Expression>>,
12600    #[serde(default)]
12601    pub using_cond: Option<Box<Expression>>,
12602    #[serde(default)]
12603    pub whens: Option<Box<Expression>>,
12604    #[serde(default)]
12605    pub with_: Option<Box<Expression>>,
12606    #[serde(default)]
12607    pub returning: Option<Box<Expression>>,
12608}
12609
12610/// When
12611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12612#[cfg_attr(feature = "bindings", derive(TS))]
12613pub struct When {
12614    #[serde(default)]
12615    pub matched: Option<Box<Expression>>,
12616    #[serde(default)]
12617    pub source: Option<Box<Expression>>,
12618    #[serde(default)]
12619    pub condition: Option<Box<Expression>>,
12620    pub then: Box<Expression>,
12621}
12622
12623/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12625#[cfg_attr(feature = "bindings", derive(TS))]
12626pub struct Whens {
12627    #[serde(default)]
12628    pub expressions: Vec<Expression>,
12629}
12630
12631/// NextValueFor
12632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12633#[cfg_attr(feature = "bindings", derive(TS))]
12634pub struct NextValueFor {
12635    pub this: Box<Expression>,
12636    #[serde(default)]
12637    pub order: Option<Box<Expression>>,
12638}
12639
12640#[cfg(test)]
12641mod tests {
12642    use super::*;
12643
12644    #[test]
12645    #[cfg(feature = "bindings")]
12646    fn export_typescript_types() {
12647        // This test exports TypeScript types to the generated directory
12648        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12649        Expression::export_all(&ts_rs::Config::default())
12650            .expect("Failed to export Expression types");
12651    }
12652
12653    #[test]
12654    fn test_simple_select_builder() {
12655        let select = Select::new()
12656            .column(Expression::star())
12657            .from(Expression::Table(TableRef::new("users")));
12658
12659        assert_eq!(select.expressions.len(), 1);
12660        assert!(select.from.is_some());
12661    }
12662
12663    #[test]
12664    fn test_expression_alias() {
12665        let expr = Expression::column("id").alias("user_id");
12666
12667        match expr {
12668            Expression::Alias(a) => {
12669                assert_eq!(a.alias.name, "user_id");
12670            }
12671            _ => panic!("Expected Alias"),
12672        }
12673    }
12674
12675    #[test]
12676    fn test_literal_creation() {
12677        let num = Expression::number(42);
12678        let str = Expression::string("hello");
12679
12680        match num {
12681            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12682            _ => panic!("Expected Number"),
12683        }
12684
12685        match str {
12686            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12687            _ => panic!("Expected String"),
12688        }
12689    }
12690
12691    #[test]
12692    fn test_expression_sql() {
12693        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12694        assert_eq!(expr.sql(), "SELECT 1 + 2");
12695    }
12696
12697    #[test]
12698    fn test_expression_sql_for() {
12699        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12700        let sql = expr.sql_for(crate::DialectType::Generic);
12701        // Generic mode normalizes IF() to CASE WHEN
12702        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
12703    }
12704}