Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // Exasol: function call with EMITS clause
486    FunctionEmits(Box<FunctionEmits>),
487
488    // JSON functions
489    JsonExtract(Box<JsonExtractFunc>),
490    JsonExtractScalar(Box<JsonExtractFunc>),
491    JsonExtractPath(Box<JsonPathFunc>),
492    JsonArray(Box<VarArgFunc>),
493    JsonObject(Box<JsonObjectFunc>),
494    JsonQuery(Box<JsonExtractFunc>),
495    JsonValue(Box<JsonExtractFunc>),
496    JsonArrayLength(Box<UnaryFunc>),
497    JsonKeys(Box<UnaryFunc>),
498    JsonType(Box<UnaryFunc>),
499    ParseJson(Box<UnaryFunc>),
500    ToJson(Box<UnaryFunc>),
501    JsonSet(Box<JsonModifyFunc>),
502    JsonInsert(Box<JsonModifyFunc>),
503    JsonRemove(Box<JsonPathFunc>),
504    JsonMergePatch(Box<BinaryFunc>),
505    JsonArrayAgg(Box<JsonArrayAggFunc>),
506    JsonObjectAgg(Box<JsonObjectAggFunc>),
507
508    // Type casting/conversion
509    Convert(Box<ConvertFunc>),
510    Typeof(Box<UnaryFunc>),
511
512    // Additional expressions
513    Lambda(Box<LambdaExpr>),
514    Parameter(Box<Parameter>),
515    Placeholder(Placeholder),
516    NamedArgument(Box<NamedArgument>),
517    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
518    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
519    TableArgument(Box<TableArgument>),
520    SqlComment(Box<SqlComment>),
521
522    // Additional predicates
523    NullSafeEq(Box<BinaryOp>),
524    NullSafeNeq(Box<BinaryOp>),
525    Glob(Box<BinaryOp>),
526    SimilarTo(Box<SimilarToExpr>),
527    Any(Box<QuantifiedExpr>),
528    All(Box<QuantifiedExpr>),
529    Overlaps(Box<OverlapsExpr>),
530
531    // Bitwise operations
532    BitwiseLeftShift(Box<BinaryOp>),
533    BitwiseRightShift(Box<BinaryOp>),
534    BitwiseAndAgg(Box<AggFunc>),
535    BitwiseOrAgg(Box<AggFunc>),
536    BitwiseXorAgg(Box<AggFunc>),
537
538    // Array/struct/map access
539    Subscript(Box<Subscript>),
540    Dot(Box<DotAccess>),
541    MethodCall(Box<MethodCall>),
542    ArraySlice(Box<ArraySlice>),
543
544    // DDL statements
545    CreateTable(Box<CreateTable>),
546    DropTable(Box<DropTable>),
547    AlterTable(Box<AlterTable>),
548    CreateIndex(Box<CreateIndex>),
549    DropIndex(Box<DropIndex>),
550    CreateView(Box<CreateView>),
551    DropView(Box<DropView>),
552    AlterView(Box<AlterView>),
553    AlterIndex(Box<AlterIndex>),
554    Truncate(Box<Truncate>),
555    Use(Box<Use>),
556    Cache(Box<Cache>),
557    Uncache(Box<Uncache>),
558    LoadData(Box<LoadData>),
559    Pragma(Box<Pragma>),
560    Grant(Box<Grant>),
561    Revoke(Box<Revoke>),
562    Comment(Box<Comment>),
563    SetStatement(Box<SetStatement>),
564    // Phase 4: Additional DDL statements
565    CreateSchema(Box<CreateSchema>),
566    DropSchema(Box<DropSchema>),
567    DropNamespace(Box<DropNamespace>),
568    CreateDatabase(Box<CreateDatabase>),
569    DropDatabase(Box<DropDatabase>),
570    CreateFunction(Box<CreateFunction>),
571    DropFunction(Box<DropFunction>),
572    CreateProcedure(Box<CreateProcedure>),
573    DropProcedure(Box<DropProcedure>),
574    CreateSequence(Box<CreateSequence>),
575    DropSequence(Box<DropSequence>),
576    AlterSequence(Box<AlterSequence>),
577    CreateTrigger(Box<CreateTrigger>),
578    DropTrigger(Box<DropTrigger>),
579    CreateType(Box<CreateType>),
580    DropType(Box<DropType>),
581    Describe(Box<Describe>),
582    Show(Box<Show>),
583
584    // Transaction and other commands
585    Command(Box<Command>),
586    Kill(Box<Kill>),
587    /// EXEC/EXECUTE statement (TSQL stored procedure call)
588    Execute(Box<ExecuteStatement>),
589
590    // Placeholder for unparsed/raw SQL
591    Raw(Raw),
592
593    // Paren for grouping
594    Paren(Box<Paren>),
595
596    // Expression with trailing comments (for round-trip preservation)
597    Annotated(Box<Annotated>),
598
599    // === BATCH GENERATED EXPRESSION TYPES ===
600    // Generated from Python sqlglot expressions.py
601    Refresh(Box<Refresh>),
602    LockingStatement(Box<LockingStatement>),
603    SequenceProperties(Box<SequenceProperties>),
604    TruncateTable(Box<TruncateTable>),
605    Clone(Box<Clone>),
606    Attach(Box<Attach>),
607    Detach(Box<Detach>),
608    Install(Box<Install>),
609    Summarize(Box<Summarize>),
610    Declare(Box<Declare>),
611    DeclareItem(Box<DeclareItem>),
612    Set(Box<Set>),
613    Heredoc(Box<Heredoc>),
614    SetItem(Box<SetItem>),
615    QueryBand(Box<QueryBand>),
616    UserDefinedFunction(Box<UserDefinedFunction>),
617    RecursiveWithSearch(Box<RecursiveWithSearch>),
618    ProjectionDef(Box<ProjectionDef>),
619    TableAlias(Box<TableAlias>),
620    ByteString(Box<ByteString>),
621    HexStringExpr(Box<HexStringExpr>),
622    UnicodeString(Box<UnicodeString>),
623    ColumnPosition(Box<ColumnPosition>),
624    ColumnDef(Box<ColumnDef>),
625    AlterColumn(Box<AlterColumn>),
626    AlterSortKey(Box<AlterSortKey>),
627    AlterSet(Box<AlterSet>),
628    RenameColumn(Box<RenameColumn>),
629    Comprehension(Box<Comprehension>),
630    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
631    MergeTreeTTL(Box<MergeTreeTTL>),
632    IndexConstraintOption(Box<IndexConstraintOption>),
633    ColumnConstraint(Box<ColumnConstraint>),
634    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
635    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
636    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
637    CheckColumnConstraint(Box<CheckColumnConstraint>),
638    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
639    CompressColumnConstraint(Box<CompressColumnConstraint>),
640    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
641    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
642    WithOperator(Box<WithOperator>),
643    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
644    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
645    CommentColumnConstraint(CommentColumnConstraint),
646    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
647    IndexColumnConstraint(Box<IndexColumnConstraint>),
648    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
649    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
650    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
651    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
652    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
653    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
654    InOutColumnConstraint(Box<InOutColumnConstraint>),
655    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
656    PathColumnConstraint(Box<PathColumnConstraint>),
657    Constraint(Box<Constraint>),
658    Export(Box<Export>),
659    Filter(Box<Filter>),
660    Changes(Box<Changes>),
661    CopyParameter(Box<CopyParameter>),
662    Credentials(Box<Credentials>),
663    Directory(Box<Directory>),
664    ForeignKey(Box<ForeignKey>),
665    ColumnPrefix(Box<ColumnPrefix>),
666    PrimaryKey(Box<PrimaryKey>),
667    IntoClause(Box<IntoClause>),
668    JoinHint(Box<JoinHint>),
669    Opclass(Box<Opclass>),
670    Index(Box<Index>),
671    IndexParameters(Box<IndexParameters>),
672    ConditionalInsert(Box<ConditionalInsert>),
673    MultitableInserts(Box<MultitableInserts>),
674    OnConflict(Box<OnConflict>),
675    OnCondition(Box<OnCondition>),
676    Returning(Box<Returning>),
677    Introducer(Box<Introducer>),
678    PartitionRange(Box<PartitionRange>),
679    Fetch(Box<Fetch>),
680    Group(Box<Group>),
681    Cube(Box<Cube>),
682    Rollup(Box<Rollup>),
683    GroupingSets(Box<GroupingSets>),
684    LimitOptions(Box<LimitOptions>),
685    Lateral(Box<Lateral>),
686    TableFromRows(Box<TableFromRows>),
687    RowsFrom(Box<RowsFrom>),
688    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
689    WithFill(Box<WithFill>),
690    Property(Box<Property>),
691    GrantPrivilege(Box<GrantPrivilege>),
692    GrantPrincipal(Box<GrantPrincipal>),
693    AllowedValuesProperty(Box<AllowedValuesProperty>),
694    AlgorithmProperty(Box<AlgorithmProperty>),
695    AutoIncrementProperty(Box<AutoIncrementProperty>),
696    AutoRefreshProperty(Box<AutoRefreshProperty>),
697    BackupProperty(Box<BackupProperty>),
698    BuildProperty(Box<BuildProperty>),
699    BlockCompressionProperty(Box<BlockCompressionProperty>),
700    CharacterSetProperty(Box<CharacterSetProperty>),
701    ChecksumProperty(Box<ChecksumProperty>),
702    CollateProperty(Box<CollateProperty>),
703    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
704    DataDeletionProperty(Box<DataDeletionProperty>),
705    DefinerProperty(Box<DefinerProperty>),
706    DistKeyProperty(Box<DistKeyProperty>),
707    DistributedByProperty(Box<DistributedByProperty>),
708    DistStyleProperty(Box<DistStyleProperty>),
709    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
710    EngineProperty(Box<EngineProperty>),
711    ToTableProperty(Box<ToTableProperty>),
712    ExecuteAsProperty(Box<ExecuteAsProperty>),
713    ExternalProperty(Box<ExternalProperty>),
714    FallbackProperty(Box<FallbackProperty>),
715    FileFormatProperty(Box<FileFormatProperty>),
716    CredentialsProperty(Box<CredentialsProperty>),
717    FreespaceProperty(Box<FreespaceProperty>),
718    InheritsProperty(Box<InheritsProperty>),
719    InputModelProperty(Box<InputModelProperty>),
720    OutputModelProperty(Box<OutputModelProperty>),
721    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
722    JournalProperty(Box<JournalProperty>),
723    LanguageProperty(Box<LanguageProperty>),
724    EnviromentProperty(Box<EnviromentProperty>),
725    ClusteredByProperty(Box<ClusteredByProperty>),
726    DictProperty(Box<DictProperty>),
727    DictRange(Box<DictRange>),
728    OnCluster(Box<OnCluster>),
729    LikeProperty(Box<LikeProperty>),
730    LocationProperty(Box<LocationProperty>),
731    LockProperty(Box<LockProperty>),
732    LockingProperty(Box<LockingProperty>),
733    LogProperty(Box<LogProperty>),
734    MaterializedProperty(Box<MaterializedProperty>),
735    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
736    OnProperty(Box<OnProperty>),
737    OnCommitProperty(Box<OnCommitProperty>),
738    PartitionedByProperty(Box<PartitionedByProperty>),
739    PartitionByProperty(Box<PartitionByProperty>),
740    PartitionedByBucket(Box<PartitionedByBucket>),
741    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
742    PartitionByTruncate(Box<PartitionByTruncate>),
743    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
744    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
745    PartitionByListProperty(Box<PartitionByListProperty>),
746    PartitionList(Box<PartitionList>),
747    Partition(Box<Partition>),
748    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
749    UniqueKeyProperty(Box<UniqueKeyProperty>),
750    RollupProperty(Box<RollupProperty>),
751    PartitionBoundSpec(Box<PartitionBoundSpec>),
752    PartitionedOfProperty(Box<PartitionedOfProperty>),
753    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
754    ReturnsProperty(Box<ReturnsProperty>),
755    RowFormatProperty(Box<RowFormatProperty>),
756    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
757    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
758    QueryTransform(Box<QueryTransform>),
759    SampleProperty(Box<SampleProperty>),
760    SecurityProperty(Box<SecurityProperty>),
761    SchemaCommentProperty(Box<SchemaCommentProperty>),
762    SemanticView(Box<SemanticView>),
763    SerdeProperties(Box<SerdeProperties>),
764    SetProperty(Box<SetProperty>),
765    SharingProperty(Box<SharingProperty>),
766    SetConfigProperty(Box<SetConfigProperty>),
767    SettingsProperty(Box<SettingsProperty>),
768    SortKeyProperty(Box<SortKeyProperty>),
769    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
770    SqlSecurityProperty(Box<SqlSecurityProperty>),
771    StabilityProperty(Box<StabilityProperty>),
772    StorageHandlerProperty(Box<StorageHandlerProperty>),
773    TemporaryProperty(Box<TemporaryProperty>),
774    Tags(Box<Tags>),
775    TransformModelProperty(Box<TransformModelProperty>),
776    TransientProperty(Box<TransientProperty>),
777    UsingTemplateProperty(Box<UsingTemplateProperty>),
778    ViewAttributeProperty(Box<ViewAttributeProperty>),
779    VolatileProperty(Box<VolatileProperty>),
780    WithDataProperty(Box<WithDataProperty>),
781    WithJournalTableProperty(Box<WithJournalTableProperty>),
782    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
783    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
784    WithProcedureOptions(Box<WithProcedureOptions>),
785    EncodeProperty(Box<EncodeProperty>),
786    IncludeProperty(Box<IncludeProperty>),
787    Properties(Box<Properties>),
788    OptionsProperty(Box<OptionsProperty>),
789    InputOutputFormat(Box<InputOutputFormat>),
790    Reference(Box<Reference>),
791    QueryOption(Box<QueryOption>),
792    WithTableHint(Box<WithTableHint>),
793    IndexTableHint(Box<IndexTableHint>),
794    HistoricalData(Box<HistoricalData>),
795    Get(Box<Get>),
796    SetOperation(Box<SetOperation>),
797    Var(Box<Var>),
798    Variadic(Box<Variadic>),
799    Version(Box<Version>),
800    Schema(Box<Schema>),
801    Lock(Box<Lock>),
802    TableSample(Box<TableSample>),
803    Tag(Box<Tag>),
804    UnpivotColumns(Box<UnpivotColumns>),
805    WindowSpec(Box<WindowSpec>),
806    SessionParameter(Box<SessionParameter>),
807    PseudoType(Box<PseudoType>),
808    ObjectIdentifier(Box<ObjectIdentifier>),
809    Transaction(Box<Transaction>),
810    Commit(Box<Commit>),
811    Rollback(Box<Rollback>),
812    AlterSession(Box<AlterSession>),
813    Analyze(Box<Analyze>),
814    AnalyzeStatistics(Box<AnalyzeStatistics>),
815    AnalyzeHistogram(Box<AnalyzeHistogram>),
816    AnalyzeSample(Box<AnalyzeSample>),
817    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
818    AnalyzeDelete(Box<AnalyzeDelete>),
819    AnalyzeWith(Box<AnalyzeWith>),
820    AnalyzeValidate(Box<AnalyzeValidate>),
821    AddPartition(Box<AddPartition>),
822    AttachOption(Box<AttachOption>),
823    DropPartition(Box<DropPartition>),
824    ReplacePartition(Box<ReplacePartition>),
825    DPipe(Box<DPipe>),
826    Operator(Box<Operator>),
827    PivotAny(Box<PivotAny>),
828    Aliases(Box<Aliases>),
829    AtIndex(Box<AtIndex>),
830    FromTimeZone(Box<FromTimeZone>),
831    FormatPhrase(Box<FormatPhrase>),
832    ForIn(Box<ForIn>),
833    TimeUnit(Box<TimeUnit>),
834    IntervalOp(Box<IntervalOp>),
835    IntervalSpan(Box<IntervalSpan>),
836    HavingMax(Box<HavingMax>),
837    CosineDistance(Box<CosineDistance>),
838    DotProduct(Box<DotProduct>),
839    EuclideanDistance(Box<EuclideanDistance>),
840    ManhattanDistance(Box<ManhattanDistance>),
841    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
842    Booland(Box<Booland>),
843    Boolor(Box<Boolor>),
844    ParameterizedAgg(Box<ParameterizedAgg>),
845    ArgMax(Box<ArgMax>),
846    ArgMin(Box<ArgMin>),
847    ApproxTopK(Box<ApproxTopK>),
848    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
849    ApproxTopKCombine(Box<ApproxTopKCombine>),
850    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
851    ApproxTopSum(Box<ApproxTopSum>),
852    ApproxQuantiles(Box<ApproxQuantiles>),
853    Minhash(Box<Minhash>),
854    FarmFingerprint(Box<FarmFingerprint>),
855    Float64(Box<Float64>),
856    Transform(Box<Transform>),
857    Translate(Box<Translate>),
858    Grouping(Box<Grouping>),
859    GroupingId(Box<GroupingId>),
860    Anonymous(Box<Anonymous>),
861    AnonymousAggFunc(Box<AnonymousAggFunc>),
862    CombinedAggFunc(Box<CombinedAggFunc>),
863    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
864    HashAgg(Box<HashAgg>),
865    Hll(Box<Hll>),
866    Apply(Box<Apply>),
867    ToBoolean(Box<ToBoolean>),
868    List(Box<List>),
869    ToMap(Box<ToMap>),
870    Pad(Box<Pad>),
871    ToChar(Box<ToChar>),
872    ToNumber(Box<ToNumber>),
873    ToDouble(Box<ToDouble>),
874    Int64(Box<UnaryFunc>),
875    StringFunc(Box<StringFunc>),
876    ToDecfloat(Box<ToDecfloat>),
877    TryToDecfloat(Box<TryToDecfloat>),
878    ToFile(Box<ToFile>),
879    Columns(Box<Columns>),
880    ConvertToCharset(Box<ConvertToCharset>),
881    ConvertTimezone(Box<ConvertTimezone>),
882    GenerateSeries(Box<GenerateSeries>),
883    AIAgg(Box<AIAgg>),
884    AIClassify(Box<AIClassify>),
885    ArrayAll(Box<ArrayAll>),
886    ArrayAny(Box<ArrayAny>),
887    ArrayConstructCompact(Box<ArrayConstructCompact>),
888    StPoint(Box<StPoint>),
889    StDistance(Box<StDistance>),
890    StringToArray(Box<StringToArray>),
891    ArraySum(Box<ArraySum>),
892    ObjectAgg(Box<ObjectAgg>),
893    CastToStrType(Box<CastToStrType>),
894    CheckJson(Box<CheckJson>),
895    CheckXml(Box<CheckXml>),
896    TranslateCharacters(Box<TranslateCharacters>),
897    CurrentSchemas(Box<CurrentSchemas>),
898    CurrentDatetime(Box<CurrentDatetime>),
899    Localtime(Box<Localtime>),
900    Localtimestamp(Box<Localtimestamp>),
901    Systimestamp(Box<Systimestamp>),
902    CurrentSchema(Box<CurrentSchema>),
903    CurrentUser(Box<CurrentUser>),
904    UtcTime(Box<UtcTime>),
905    UtcTimestamp(Box<UtcTimestamp>),
906    Timestamp(Box<TimestampFunc>),
907    DateBin(Box<DateBin>),
908    Datetime(Box<Datetime>),
909    DatetimeAdd(Box<DatetimeAdd>),
910    DatetimeSub(Box<DatetimeSub>),
911    DatetimeDiff(Box<DatetimeDiff>),
912    DatetimeTrunc(Box<DatetimeTrunc>),
913    Dayname(Box<Dayname>),
914    MakeInterval(Box<MakeInterval>),
915    PreviousDay(Box<PreviousDay>),
916    Elt(Box<Elt>),
917    TimestampAdd(Box<TimestampAdd>),
918    TimestampSub(Box<TimestampSub>),
919    TimestampDiff(Box<TimestampDiff>),
920    TimeSlice(Box<TimeSlice>),
921    TimeAdd(Box<TimeAdd>),
922    TimeSub(Box<TimeSub>),
923    TimeDiff(Box<TimeDiff>),
924    TimeTrunc(Box<TimeTrunc>),
925    DateFromParts(Box<DateFromParts>),
926    TimeFromParts(Box<TimeFromParts>),
927    DecodeCase(Box<DecodeCase>),
928    Decrypt(Box<Decrypt>),
929    DecryptRaw(Box<DecryptRaw>),
930    Encode(Box<Encode>),
931    Encrypt(Box<Encrypt>),
932    EncryptRaw(Box<EncryptRaw>),
933    EqualNull(Box<EqualNull>),
934    ToBinary(Box<ToBinary>),
935    Base64DecodeBinary(Box<Base64DecodeBinary>),
936    Base64DecodeString(Box<Base64DecodeString>),
937    Base64Encode(Box<Base64Encode>),
938    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
939    TryBase64DecodeString(Box<TryBase64DecodeString>),
940    GapFill(Box<GapFill>),
941    GenerateDateArray(Box<GenerateDateArray>),
942    GenerateTimestampArray(Box<GenerateTimestampArray>),
943    GetExtract(Box<GetExtract>),
944    Getbit(Box<Getbit>),
945    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
946    HexEncode(Box<HexEncode>),
947    Compress(Box<Compress>),
948    DecompressBinary(Box<DecompressBinary>),
949    DecompressString(Box<DecompressString>),
950    Xor(Box<Xor>),
951    Nullif(Box<Nullif>),
952    JSON(Box<JSON>),
953    JSONPath(Box<JSONPath>),
954    JSONPathFilter(Box<JSONPathFilter>),
955    JSONPathKey(Box<JSONPathKey>),
956    JSONPathRecursive(Box<JSONPathRecursive>),
957    JSONPathScript(Box<JSONPathScript>),
958    JSONPathSlice(Box<JSONPathSlice>),
959    JSONPathSelector(Box<JSONPathSelector>),
960    JSONPathSubscript(Box<JSONPathSubscript>),
961    JSONPathUnion(Box<JSONPathUnion>),
962    Format(Box<Format>),
963    JSONKeys(Box<JSONKeys>),
964    JSONKeyValue(Box<JSONKeyValue>),
965    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
966    JSONObject(Box<JSONObject>),
967    JSONObjectAgg(Box<JSONObjectAgg>),
968    JSONBObjectAgg(Box<JSONBObjectAgg>),
969    JSONArray(Box<JSONArray>),
970    JSONArrayAgg(Box<JSONArrayAgg>),
971    JSONExists(Box<JSONExists>),
972    JSONColumnDef(Box<JSONColumnDef>),
973    JSONSchema(Box<JSONSchema>),
974    JSONSet(Box<JSONSet>),
975    JSONStripNulls(Box<JSONStripNulls>),
976    JSONValue(Box<JSONValue>),
977    JSONValueArray(Box<JSONValueArray>),
978    JSONRemove(Box<JSONRemove>),
979    JSONTable(Box<JSONTable>),
980    JSONType(Box<JSONType>),
981    ObjectInsert(Box<ObjectInsert>),
982    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
983    OpenJSON(Box<OpenJSON>),
984    JSONBExists(Box<JSONBExists>),
985    JSONBContains(Box<BinaryFunc>),
986    JSONBExtract(Box<BinaryFunc>),
987    JSONCast(Box<JSONCast>),
988    JSONExtract(Box<JSONExtract>),
989    JSONExtractQuote(Box<JSONExtractQuote>),
990    JSONExtractArray(Box<JSONExtractArray>),
991    JSONExtractScalar(Box<JSONExtractScalar>),
992    JSONBExtractScalar(Box<JSONBExtractScalar>),
993    JSONFormat(Box<JSONFormat>),
994    JSONBool(Box<UnaryFunc>),
995    JSONPathRoot(JSONPathRoot),
996    JSONArrayAppend(Box<JSONArrayAppend>),
997    JSONArrayContains(Box<JSONArrayContains>),
998    JSONArrayInsert(Box<JSONArrayInsert>),
999    ParseJSON(Box<ParseJSON>),
1000    ParseUrl(Box<ParseUrl>),
1001    ParseIp(Box<ParseIp>),
1002    ParseTime(Box<ParseTime>),
1003    ParseDatetime(Box<ParseDatetime>),
1004    Map(Box<Map>),
1005    MapCat(Box<MapCat>),
1006    MapDelete(Box<MapDelete>),
1007    MapInsert(Box<MapInsert>),
1008    MapPick(Box<MapPick>),
1009    ScopeResolution(Box<ScopeResolution>),
1010    Slice(Box<Slice>),
1011    VarMap(Box<VarMap>),
1012    MatchAgainst(Box<MatchAgainst>),
1013    MD5Digest(Box<MD5Digest>),
1014    MD5NumberLower64(Box<UnaryFunc>),
1015    MD5NumberUpper64(Box<UnaryFunc>),
1016    Monthname(Box<Monthname>),
1017    Ntile(Box<Ntile>),
1018    Normalize(Box<Normalize>),
1019    Normal(Box<Normal>),
1020    Predict(Box<Predict>),
1021    MLTranslate(Box<MLTranslate>),
1022    FeaturesAtTime(Box<FeaturesAtTime>),
1023    GenerateEmbedding(Box<GenerateEmbedding>),
1024    MLForecast(Box<MLForecast>),
1025    ModelAttribute(Box<ModelAttribute>),
1026    VectorSearch(Box<VectorSearch>),
1027    Quantile(Box<Quantile>),
1028    ApproxQuantile(Box<ApproxQuantile>),
1029    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1030    Randn(Box<Randn>),
1031    Randstr(Box<Randstr>),
1032    RangeN(Box<RangeN>),
1033    RangeBucket(Box<RangeBucket>),
1034    ReadCSV(Box<ReadCSV>),
1035    ReadParquet(Box<ReadParquet>),
1036    Reduce(Box<Reduce>),
1037    RegexpExtractAll(Box<RegexpExtractAll>),
1038    RegexpILike(Box<RegexpILike>),
1039    RegexpFullMatch(Box<RegexpFullMatch>),
1040    RegexpInstr(Box<RegexpInstr>),
1041    RegexpSplit(Box<RegexpSplit>),
1042    RegexpCount(Box<RegexpCount>),
1043    RegrValx(Box<RegrValx>),
1044    RegrValy(Box<RegrValy>),
1045    RegrAvgy(Box<RegrAvgy>),
1046    RegrAvgx(Box<RegrAvgx>),
1047    RegrCount(Box<RegrCount>),
1048    RegrIntercept(Box<RegrIntercept>),
1049    RegrR2(Box<RegrR2>),
1050    RegrSxx(Box<RegrSxx>),
1051    RegrSxy(Box<RegrSxy>),
1052    RegrSyy(Box<RegrSyy>),
1053    RegrSlope(Box<RegrSlope>),
1054    SafeAdd(Box<SafeAdd>),
1055    SafeDivide(Box<SafeDivide>),
1056    SafeMultiply(Box<SafeMultiply>),
1057    SafeSubtract(Box<SafeSubtract>),
1058    SHA2(Box<SHA2>),
1059    SHA2Digest(Box<SHA2Digest>),
1060    SortArray(Box<SortArray>),
1061    SplitPart(Box<SplitPart>),
1062    SubstringIndex(Box<SubstringIndex>),
1063    StandardHash(Box<StandardHash>),
1064    StrPosition(Box<StrPosition>),
1065    Search(Box<Search>),
1066    SearchIp(Box<SearchIp>),
1067    StrToDate(Box<StrToDate>),
1068    DateStrToDate(Box<UnaryFunc>),
1069    DateToDateStr(Box<UnaryFunc>),
1070    StrToTime(Box<StrToTime>),
1071    StrToUnix(Box<StrToUnix>),
1072    StrToMap(Box<StrToMap>),
1073    NumberToStr(Box<NumberToStr>),
1074    FromBase(Box<FromBase>),
1075    Stuff(Box<Stuff>),
1076    TimeToStr(Box<TimeToStr>),
1077    TimeStrToTime(Box<TimeStrToTime>),
1078    TsOrDsAdd(Box<TsOrDsAdd>),
1079    TsOrDsDiff(Box<TsOrDsDiff>),
1080    TsOrDsToDate(Box<TsOrDsToDate>),
1081    TsOrDsToTime(Box<TsOrDsToTime>),
1082    Unhex(Box<Unhex>),
1083    Uniform(Box<Uniform>),
1084    UnixToStr(Box<UnixToStr>),
1085    UnixToTime(Box<UnixToTime>),
1086    Uuid(Box<Uuid>),
1087    TimestampFromParts(Box<TimestampFromParts>),
1088    TimestampTzFromParts(Box<TimestampTzFromParts>),
1089    Corr(Box<Corr>),
1090    WidthBucket(Box<WidthBucket>),
1091    CovarSamp(Box<CovarSamp>),
1092    CovarPop(Box<CovarPop>),
1093    Week(Box<Week>),
1094    XMLElement(Box<XMLElement>),
1095    XMLGet(Box<XMLGet>),
1096    XMLTable(Box<XMLTable>),
1097    XMLKeyValueOption(Box<XMLKeyValueOption>),
1098    Zipf(Box<Zipf>),
1099    Merge(Box<Merge>),
1100    When(Box<When>),
1101    Whens(Box<Whens>),
1102    NextValueFor(Box<NextValueFor>),
1103    /// RETURN statement (DuckDB stored procedures)
1104    ReturnStmt(Box<Expression>),
1105}
1106
1107impl Expression {
1108    /// Create a `Column` variant, boxing the value automatically.
1109    #[inline]
1110    pub fn boxed_column(col: Column) -> Self {
1111        Expression::Column(Box::new(col))
1112    }
1113
1114    /// Create a `Table` variant, boxing the value automatically.
1115    #[inline]
1116    pub fn boxed_table(t: TableRef) -> Self {
1117        Expression::Table(Box::new(t))
1118    }
1119
1120    /// Returns `true` if this expression is a valid top-level SQL statement.
1121    ///
1122    /// Bare expressions like identifiers, literals, and function calls are not
1123    /// valid statements. This is used by `validate()` to reject inputs like
1124    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1125    /// plus the bare identifier `doo`.
1126    pub fn is_statement(&self) -> bool {
1127        match self {
1128            // Queries
1129            Expression::Select(_)
1130            | Expression::Union(_)
1131            | Expression::Intersect(_)
1132            | Expression::Except(_)
1133            | Expression::Subquery(_)
1134            | Expression::Values(_)
1135            | Expression::PipeOperator(_)
1136
1137            // DML
1138            | Expression::Insert(_)
1139            | Expression::Update(_)
1140            | Expression::Delete(_)
1141            | Expression::Copy(_)
1142            | Expression::Put(_)
1143            | Expression::Merge(_)
1144
1145            // DDL
1146            | Expression::CreateTable(_)
1147            | Expression::DropTable(_)
1148            | Expression::AlterTable(_)
1149            | Expression::CreateIndex(_)
1150            | Expression::DropIndex(_)
1151            | Expression::CreateView(_)
1152            | Expression::DropView(_)
1153            | Expression::AlterView(_)
1154            | Expression::AlterIndex(_)
1155            | Expression::Truncate(_)
1156            | Expression::TruncateTable(_)
1157            | Expression::CreateSchema(_)
1158            | Expression::DropSchema(_)
1159            | Expression::DropNamespace(_)
1160            | Expression::CreateDatabase(_)
1161            | Expression::DropDatabase(_)
1162            | Expression::CreateFunction(_)
1163            | Expression::DropFunction(_)
1164            | Expression::CreateProcedure(_)
1165            | Expression::DropProcedure(_)
1166            | Expression::CreateSequence(_)
1167            | Expression::DropSequence(_)
1168            | Expression::AlterSequence(_)
1169            | Expression::CreateTrigger(_)
1170            | Expression::DropTrigger(_)
1171            | Expression::CreateType(_)
1172            | Expression::DropType(_)
1173            | Expression::Comment(_)
1174
1175            // Session/Transaction/Control
1176            | Expression::Use(_)
1177            | Expression::Set(_)
1178            | Expression::SetStatement(_)
1179            | Expression::Transaction(_)
1180            | Expression::Commit(_)
1181            | Expression::Rollback(_)
1182            | Expression::Grant(_)
1183            | Expression::Revoke(_)
1184            | Expression::Cache(_)
1185            | Expression::Uncache(_)
1186            | Expression::LoadData(_)
1187            | Expression::Pragma(_)
1188            | Expression::Describe(_)
1189            | Expression::Show(_)
1190            | Expression::Kill(_)
1191            | Expression::Execute(_)
1192            | Expression::Declare(_)
1193            | Expression::Refresh(_)
1194            | Expression::AlterSession(_)
1195            | Expression::LockingStatement(_)
1196
1197            // Analyze
1198            | Expression::Analyze(_)
1199            | Expression::AnalyzeStatistics(_)
1200            | Expression::AnalyzeHistogram(_)
1201            | Expression::AnalyzeSample(_)
1202            | Expression::AnalyzeListChainedRows(_)
1203            | Expression::AnalyzeDelete(_)
1204
1205            // Attach/Detach/Install/Summarize
1206            | Expression::Attach(_)
1207            | Expression::Detach(_)
1208            | Expression::Install(_)
1209            | Expression::Summarize(_)
1210
1211            // Pivot at statement level
1212            | Expression::Pivot(_)
1213            | Expression::Unpivot(_)
1214
1215            // Command (raw/unparsed statements)
1216            | Expression::Command(_)
1217            | Expression::Raw(_)
1218
1219            // Return statement
1220            | Expression::ReturnStmt(_) => true,
1221
1222            // Annotated wraps another expression with comments — check inner
1223            Expression::Annotated(a) => a.this.is_statement(),
1224
1225            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1226            Expression::Alias(a) => a.this.is_statement(),
1227
1228            // Everything else (identifiers, literals, operators, functions, etc.)
1229            _ => false,
1230        }
1231    }
1232
1233    /// Create a literal number expression from an integer.
1234    pub fn number(n: i64) -> Self {
1235        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1236    }
1237
1238    /// Create a single-quoted literal string expression.
1239    pub fn string(s: impl Into<String>) -> Self {
1240        Expression::Literal(Box::new(Literal::String(s.into())))
1241    }
1242
1243    /// Create a literal number expression from a float.
1244    pub fn float(f: f64) -> Self {
1245        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1246    }
1247
1248    /// Get the inferred type annotation, if present.
1249    ///
1250    /// For value-producing expressions with an `inferred_type` field, returns
1251    /// the stored type. For literals and boolean constants, computes the type
1252    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1253    pub fn inferred_type(&self) -> Option<&DataType> {
1254        match self {
1255            // Structs with inferred_type field
1256            Expression::And(op)
1257            | Expression::Or(op)
1258            | Expression::Add(op)
1259            | Expression::Sub(op)
1260            | Expression::Mul(op)
1261            | Expression::Div(op)
1262            | Expression::Mod(op)
1263            | Expression::Eq(op)
1264            | Expression::Neq(op)
1265            | Expression::Lt(op)
1266            | Expression::Lte(op)
1267            | Expression::Gt(op)
1268            | Expression::Gte(op)
1269            | Expression::Concat(op)
1270            | Expression::BitwiseAnd(op)
1271            | Expression::BitwiseOr(op)
1272            | Expression::BitwiseXor(op)
1273            | Expression::Adjacent(op)
1274            | Expression::TsMatch(op)
1275            | Expression::PropertyEQ(op)
1276            | Expression::ArrayContainsAll(op)
1277            | Expression::ArrayContainedBy(op)
1278            | Expression::ArrayOverlaps(op)
1279            | Expression::JSONBContainsAllTopKeys(op)
1280            | Expression::JSONBContainsAnyTopKeys(op)
1281            | Expression::JSONBDeleteAtPath(op)
1282            | Expression::ExtendsLeft(op)
1283            | Expression::ExtendsRight(op)
1284            | Expression::Is(op)
1285            | Expression::MemberOf(op)
1286            | Expression::Match(op)
1287            | Expression::NullSafeEq(op)
1288            | Expression::NullSafeNeq(op)
1289            | Expression::Glob(op)
1290            | Expression::BitwiseLeftShift(op)
1291            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1292
1293            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1294                op.inferred_type.as_ref()
1295            }
1296
1297            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1298
1299            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1300                c.inferred_type.as_ref()
1301            }
1302
1303            Expression::Column(c) => c.inferred_type.as_ref(),
1304            Expression::Function(f) => f.inferred_type.as_ref(),
1305            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1306            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1307            Expression::Case(c) => c.inferred_type.as_ref(),
1308            Expression::Subquery(s) => s.inferred_type.as_ref(),
1309            Expression::Alias(a) => a.inferred_type.as_ref(),
1310            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1311            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1312            Expression::Count(f) => f.inferred_type.as_ref(),
1313            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1314            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1315            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1316            Expression::SumIf(f) => f.inferred_type.as_ref(),
1317
1318            // UnaryFunc variants
1319            Expression::Upper(f)
1320            | Expression::Lower(f)
1321            | Expression::Length(f)
1322            | Expression::LTrim(f)
1323            | Expression::RTrim(f)
1324            | Expression::Reverse(f)
1325            | Expression::Abs(f)
1326            | Expression::Sqrt(f)
1327            | Expression::Cbrt(f)
1328            | Expression::Ln(f)
1329            | Expression::Exp(f)
1330            | Expression::Sign(f)
1331            | Expression::Date(f)
1332            | Expression::Time(f)
1333            | Expression::Initcap(f)
1334            | Expression::Ascii(f)
1335            | Expression::Chr(f)
1336            | Expression::Soundex(f)
1337            | Expression::ByteLength(f)
1338            | Expression::Hex(f)
1339            | Expression::LowerHex(f)
1340            | Expression::Unicode(f)
1341            | Expression::Typeof(f)
1342            | Expression::Explode(f)
1343            | Expression::ExplodeOuter(f)
1344            | Expression::MapFromEntries(f)
1345            | Expression::MapKeys(f)
1346            | Expression::MapValues(f)
1347            | Expression::ArrayLength(f)
1348            | Expression::ArraySize(f)
1349            | Expression::Cardinality(f)
1350            | Expression::ArrayReverse(f)
1351            | Expression::ArrayDistinct(f)
1352            | Expression::ArrayFlatten(f)
1353            | Expression::ArrayCompact(f)
1354            | Expression::ToArray(f)
1355            | Expression::JsonArrayLength(f)
1356            | Expression::JsonKeys(f)
1357            | Expression::JsonType(f)
1358            | Expression::ParseJson(f)
1359            | Expression::ToJson(f)
1360            | Expression::Radians(f)
1361            | Expression::Degrees(f)
1362            | Expression::Sin(f)
1363            | Expression::Cos(f)
1364            | Expression::Tan(f)
1365            | Expression::Asin(f)
1366            | Expression::Acos(f)
1367            | Expression::Atan(f)
1368            | Expression::IsNan(f)
1369            | Expression::IsInf(f)
1370            | Expression::Year(f)
1371            | Expression::Month(f)
1372            | Expression::Day(f)
1373            | Expression::Hour(f)
1374            | Expression::Minute(f)
1375            | Expression::Second(f)
1376            | Expression::DayOfWeek(f)
1377            | Expression::DayOfWeekIso(f)
1378            | Expression::DayOfMonth(f)
1379            | Expression::DayOfYear(f)
1380            | Expression::WeekOfYear(f)
1381            | Expression::Quarter(f)
1382            | Expression::Epoch(f)
1383            | Expression::EpochMs(f)
1384            | Expression::BitwiseCount(f)
1385            | Expression::DateFromUnixDate(f)
1386            | Expression::UnixDate(f)
1387            | Expression::UnixSeconds(f)
1388            | Expression::UnixMillis(f)
1389            | Expression::UnixMicros(f)
1390            | Expression::TimeStrToDate(f)
1391            | Expression::DateToDi(f)
1392            | Expression::DiToDate(f)
1393            | Expression::TsOrDiToDi(f)
1394            | Expression::TsOrDsToDatetime(f)
1395            | Expression::TsOrDsToTimestamp(f)
1396            | Expression::YearOfWeek(f)
1397            | Expression::YearOfWeekIso(f)
1398            | Expression::SHA(f)
1399            | Expression::SHA1Digest(f)
1400            | Expression::TimeToUnix(f)
1401            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1402
1403            // BinaryFunc variants
1404            Expression::Power(f)
1405            | Expression::NullIf(f)
1406            | Expression::IfNull(f)
1407            | Expression::Nvl(f)
1408            | Expression::Contains(f)
1409            | Expression::StartsWith(f)
1410            | Expression::EndsWith(f)
1411            | Expression::Levenshtein(f)
1412            | Expression::ModFunc(f)
1413            | Expression::IntDiv(f)
1414            | Expression::Atan2(f)
1415            | Expression::AddMonths(f)
1416            | Expression::MonthsBetween(f)
1417            | Expression::NextDay(f)
1418            | Expression::UnixToTimeStr(f)
1419            | Expression::ArrayContains(f)
1420            | Expression::ArrayPosition(f)
1421            | Expression::ArrayAppend(f)
1422            | Expression::ArrayPrepend(f)
1423            | Expression::ArrayUnion(f)
1424            | Expression::ArrayExcept(f)
1425            | Expression::ArrayRemove(f)
1426            | Expression::StarMap(f)
1427            | Expression::MapFromArrays(f)
1428            | Expression::MapContainsKey(f)
1429            | Expression::ElementAt(f)
1430            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1431
1432            // VarArgFunc variants
1433            Expression::Coalesce(f)
1434            | Expression::Greatest(f)
1435            | Expression::Least(f)
1436            | Expression::ArrayConcat(f)
1437            | Expression::ArrayIntersect(f)
1438            | Expression::ArrayZip(f)
1439            | Expression::MapConcat(f)
1440            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1441
1442            // AggFunc variants
1443            Expression::Sum(f)
1444            | Expression::Avg(f)
1445            | Expression::Min(f)
1446            | Expression::Max(f)
1447            | Expression::ArrayAgg(f)
1448            | Expression::CountIf(f)
1449            | Expression::Stddev(f)
1450            | Expression::StddevPop(f)
1451            | Expression::StddevSamp(f)
1452            | Expression::Variance(f)
1453            | Expression::VarPop(f)
1454            | Expression::VarSamp(f)
1455            | Expression::Median(f)
1456            | Expression::Mode(f)
1457            | Expression::First(f)
1458            | Expression::Last(f)
1459            | Expression::AnyValue(f)
1460            | Expression::ApproxDistinct(f)
1461            | Expression::ApproxCountDistinct(f)
1462            | Expression::LogicalAnd(f)
1463            | Expression::LogicalOr(f)
1464            | Expression::Skewness(f)
1465            | Expression::ArrayConcatAgg(f)
1466            | Expression::ArrayUniqueAgg(f)
1467            | Expression::BoolXorAgg(f)
1468            | Expression::BitwiseAndAgg(f)
1469            | Expression::BitwiseOrAgg(f)
1470            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1471
1472            // Everything else: no inferred_type field
1473            _ => None,
1474        }
1475    }
1476
1477    /// Set the inferred type annotation on this expression.
1478    ///
1479    /// Only has an effect on value-producing expressions with an `inferred_type`
1480    /// field. For other expression types, this is a no-op.
1481    pub fn set_inferred_type(&mut self, dt: DataType) {
1482        match self {
1483            Expression::And(op)
1484            | Expression::Or(op)
1485            | Expression::Add(op)
1486            | Expression::Sub(op)
1487            | Expression::Mul(op)
1488            | Expression::Div(op)
1489            | Expression::Mod(op)
1490            | Expression::Eq(op)
1491            | Expression::Neq(op)
1492            | Expression::Lt(op)
1493            | Expression::Lte(op)
1494            | Expression::Gt(op)
1495            | Expression::Gte(op)
1496            | Expression::Concat(op)
1497            | Expression::BitwiseAnd(op)
1498            | Expression::BitwiseOr(op)
1499            | Expression::BitwiseXor(op)
1500            | Expression::Adjacent(op)
1501            | Expression::TsMatch(op)
1502            | Expression::PropertyEQ(op)
1503            | Expression::ArrayContainsAll(op)
1504            | Expression::ArrayContainedBy(op)
1505            | Expression::ArrayOverlaps(op)
1506            | Expression::JSONBContainsAllTopKeys(op)
1507            | Expression::JSONBContainsAnyTopKeys(op)
1508            | Expression::JSONBDeleteAtPath(op)
1509            | Expression::ExtendsLeft(op)
1510            | Expression::ExtendsRight(op)
1511            | Expression::Is(op)
1512            | Expression::MemberOf(op)
1513            | Expression::Match(op)
1514            | Expression::NullSafeEq(op)
1515            | Expression::NullSafeNeq(op)
1516            | Expression::Glob(op)
1517            | Expression::BitwiseLeftShift(op)
1518            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1519
1520            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1521                op.inferred_type = Some(dt)
1522            }
1523
1524            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1525
1526            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1527                c.inferred_type = Some(dt)
1528            }
1529
1530            Expression::Column(c) => c.inferred_type = Some(dt),
1531            Expression::Function(f) => f.inferred_type = Some(dt),
1532            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1533            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1534            Expression::Case(c) => c.inferred_type = Some(dt),
1535            Expression::Subquery(s) => s.inferred_type = Some(dt),
1536            Expression::Alias(a) => a.inferred_type = Some(dt),
1537            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1538            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1539            Expression::Count(f) => f.inferred_type = Some(dt),
1540            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1541            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1542            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1543            Expression::SumIf(f) => f.inferred_type = Some(dt),
1544
1545            // UnaryFunc variants
1546            Expression::Upper(f)
1547            | Expression::Lower(f)
1548            | Expression::Length(f)
1549            | Expression::LTrim(f)
1550            | Expression::RTrim(f)
1551            | Expression::Reverse(f)
1552            | Expression::Abs(f)
1553            | Expression::Sqrt(f)
1554            | Expression::Cbrt(f)
1555            | Expression::Ln(f)
1556            | Expression::Exp(f)
1557            | Expression::Sign(f)
1558            | Expression::Date(f)
1559            | Expression::Time(f)
1560            | Expression::Initcap(f)
1561            | Expression::Ascii(f)
1562            | Expression::Chr(f)
1563            | Expression::Soundex(f)
1564            | Expression::ByteLength(f)
1565            | Expression::Hex(f)
1566            | Expression::LowerHex(f)
1567            | Expression::Unicode(f)
1568            | Expression::Typeof(f)
1569            | Expression::Explode(f)
1570            | Expression::ExplodeOuter(f)
1571            | Expression::MapFromEntries(f)
1572            | Expression::MapKeys(f)
1573            | Expression::MapValues(f)
1574            | Expression::ArrayLength(f)
1575            | Expression::ArraySize(f)
1576            | Expression::Cardinality(f)
1577            | Expression::ArrayReverse(f)
1578            | Expression::ArrayDistinct(f)
1579            | Expression::ArrayFlatten(f)
1580            | Expression::ArrayCompact(f)
1581            | Expression::ToArray(f)
1582            | Expression::JsonArrayLength(f)
1583            | Expression::JsonKeys(f)
1584            | Expression::JsonType(f)
1585            | Expression::ParseJson(f)
1586            | Expression::ToJson(f)
1587            | Expression::Radians(f)
1588            | Expression::Degrees(f)
1589            | Expression::Sin(f)
1590            | Expression::Cos(f)
1591            | Expression::Tan(f)
1592            | Expression::Asin(f)
1593            | Expression::Acos(f)
1594            | Expression::Atan(f)
1595            | Expression::IsNan(f)
1596            | Expression::IsInf(f)
1597            | Expression::Year(f)
1598            | Expression::Month(f)
1599            | Expression::Day(f)
1600            | Expression::Hour(f)
1601            | Expression::Minute(f)
1602            | Expression::Second(f)
1603            | Expression::DayOfWeek(f)
1604            | Expression::DayOfWeekIso(f)
1605            | Expression::DayOfMonth(f)
1606            | Expression::DayOfYear(f)
1607            | Expression::WeekOfYear(f)
1608            | Expression::Quarter(f)
1609            | Expression::Epoch(f)
1610            | Expression::EpochMs(f)
1611            | Expression::BitwiseCount(f)
1612            | Expression::DateFromUnixDate(f)
1613            | Expression::UnixDate(f)
1614            | Expression::UnixSeconds(f)
1615            | Expression::UnixMillis(f)
1616            | Expression::UnixMicros(f)
1617            | Expression::TimeStrToDate(f)
1618            | Expression::DateToDi(f)
1619            | Expression::DiToDate(f)
1620            | Expression::TsOrDiToDi(f)
1621            | Expression::TsOrDsToDatetime(f)
1622            | Expression::TsOrDsToTimestamp(f)
1623            | Expression::YearOfWeek(f)
1624            | Expression::YearOfWeekIso(f)
1625            | Expression::SHA(f)
1626            | Expression::SHA1Digest(f)
1627            | Expression::TimeToUnix(f)
1628            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1629
1630            // BinaryFunc variants
1631            Expression::Power(f)
1632            | Expression::NullIf(f)
1633            | Expression::IfNull(f)
1634            | Expression::Nvl(f)
1635            | Expression::Contains(f)
1636            | Expression::StartsWith(f)
1637            | Expression::EndsWith(f)
1638            | Expression::Levenshtein(f)
1639            | Expression::ModFunc(f)
1640            | Expression::IntDiv(f)
1641            | Expression::Atan2(f)
1642            | Expression::AddMonths(f)
1643            | Expression::MonthsBetween(f)
1644            | Expression::NextDay(f)
1645            | Expression::UnixToTimeStr(f)
1646            | Expression::ArrayContains(f)
1647            | Expression::ArrayPosition(f)
1648            | Expression::ArrayAppend(f)
1649            | Expression::ArrayPrepend(f)
1650            | Expression::ArrayUnion(f)
1651            | Expression::ArrayExcept(f)
1652            | Expression::ArrayRemove(f)
1653            | Expression::StarMap(f)
1654            | Expression::MapFromArrays(f)
1655            | Expression::MapContainsKey(f)
1656            | Expression::ElementAt(f)
1657            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1658
1659            // VarArgFunc variants
1660            Expression::Coalesce(f)
1661            | Expression::Greatest(f)
1662            | Expression::Least(f)
1663            | Expression::ArrayConcat(f)
1664            | Expression::ArrayIntersect(f)
1665            | Expression::ArrayZip(f)
1666            | Expression::MapConcat(f)
1667            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1668
1669            // AggFunc variants
1670            Expression::Sum(f)
1671            | Expression::Avg(f)
1672            | Expression::Min(f)
1673            | Expression::Max(f)
1674            | Expression::ArrayAgg(f)
1675            | Expression::CountIf(f)
1676            | Expression::Stddev(f)
1677            | Expression::StddevPop(f)
1678            | Expression::StddevSamp(f)
1679            | Expression::Variance(f)
1680            | Expression::VarPop(f)
1681            | Expression::VarSamp(f)
1682            | Expression::Median(f)
1683            | Expression::Mode(f)
1684            | Expression::First(f)
1685            | Expression::Last(f)
1686            | Expression::AnyValue(f)
1687            | Expression::ApproxDistinct(f)
1688            | Expression::ApproxCountDistinct(f)
1689            | Expression::LogicalAnd(f)
1690            | Expression::LogicalOr(f)
1691            | Expression::Skewness(f)
1692            | Expression::ArrayConcatAgg(f)
1693            | Expression::ArrayUniqueAgg(f)
1694            | Expression::BoolXorAgg(f)
1695            | Expression::BitwiseAndAgg(f)
1696            | Expression::BitwiseOrAgg(f)
1697            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1698
1699            // Expressions without inferred_type field - no-op
1700            _ => {}
1701        }
1702    }
1703
1704    /// Create an unqualified column reference (e.g. `name`).
1705    pub fn column(name: impl Into<String>) -> Self {
1706        Expression::Column(Box::new(Column {
1707            name: Identifier::new(name),
1708            table: None,
1709            join_mark: false,
1710            trailing_comments: Vec::new(),
1711            span: None,
1712            inferred_type: None,
1713        }))
1714    }
1715
1716    /// Create a qualified column reference (`table.column`).
1717    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1718        Expression::Column(Box::new(Column {
1719            name: Identifier::new(column),
1720            table: Some(Identifier::new(table)),
1721            join_mark: false,
1722            trailing_comments: Vec::new(),
1723            span: None,
1724            inferred_type: None,
1725        }))
1726    }
1727
1728    /// Create a bare identifier expression (not a column reference).
1729    pub fn identifier(name: impl Into<String>) -> Self {
1730        Expression::Identifier(Identifier::new(name))
1731    }
1732
1733    /// Create a NULL expression
1734    pub fn null() -> Self {
1735        Expression::Null(Null)
1736    }
1737
1738    /// Create a TRUE expression
1739    pub fn true_() -> Self {
1740        Expression::Boolean(BooleanLiteral { value: true })
1741    }
1742
1743    /// Create a FALSE expression
1744    pub fn false_() -> Self {
1745        Expression::Boolean(BooleanLiteral { value: false })
1746    }
1747
1748    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1749    pub fn star() -> Self {
1750        Expression::Star(Star {
1751            table: None,
1752            except: None,
1753            replace: None,
1754            rename: None,
1755            trailing_comments: Vec::new(),
1756            span: None,
1757        })
1758    }
1759
1760    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1761    pub fn alias(self, name: impl Into<String>) -> Self {
1762        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1763    }
1764
1765    /// Check if this is a SELECT expression
1766    pub fn is_select(&self) -> bool {
1767        matches!(self, Expression::Select(_))
1768    }
1769
1770    /// Try to get as a Select
1771    pub fn as_select(&self) -> Option<&Select> {
1772        match self {
1773            Expression::Select(s) => Some(s),
1774            _ => None,
1775        }
1776    }
1777
1778    /// Try to get as a mutable Select
1779    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1780        match self {
1781            Expression::Select(s) => Some(s),
1782            _ => None,
1783        }
1784    }
1785
1786    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1787    ///
1788    /// Returns an empty string if generation fails. For dialect-specific output,
1789    /// use [`sql_for()`](Self::sql_for) instead.
1790    pub fn sql(&self) -> String {
1791        crate::generator::Generator::sql(self).unwrap_or_default()
1792    }
1793
1794    /// Generate a SQL string for this expression targeting a specific dialect.
1795    ///
1796    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1797    /// syntax variations) are applied automatically.  Returns an empty string if
1798    /// generation fails.
1799    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1800        crate::generate(self, dialect).unwrap_or_default()
1801    }
1802}
1803
1804// === Python API accessor methods ===
1805
1806impl Expression {
1807    /// Returns the serde-compatible snake_case variant name without serialization.
1808    /// This is much faster than serializing to JSON and extracting the key.
1809    pub fn variant_name(&self) -> &'static str {
1810        match self {
1811            Expression::Literal(_) => "literal",
1812            Expression::Boolean(_) => "boolean",
1813            Expression::Null(_) => "null",
1814            Expression::Identifier(_) => "identifier",
1815            Expression::Column(_) => "column",
1816            Expression::Table(_) => "table",
1817            Expression::Star(_) => "star",
1818            Expression::BracedWildcard(_) => "braced_wildcard",
1819            Expression::Select(_) => "select",
1820            Expression::Union(_) => "union",
1821            Expression::Intersect(_) => "intersect",
1822            Expression::Except(_) => "except",
1823            Expression::Subquery(_) => "subquery",
1824            Expression::PipeOperator(_) => "pipe_operator",
1825            Expression::Pivot(_) => "pivot",
1826            Expression::PivotAlias(_) => "pivot_alias",
1827            Expression::Unpivot(_) => "unpivot",
1828            Expression::Values(_) => "values",
1829            Expression::PreWhere(_) => "pre_where",
1830            Expression::Stream(_) => "stream",
1831            Expression::UsingData(_) => "using_data",
1832            Expression::XmlNamespace(_) => "xml_namespace",
1833            Expression::Insert(_) => "insert",
1834            Expression::Update(_) => "update",
1835            Expression::Delete(_) => "delete",
1836            Expression::Copy(_) => "copy",
1837            Expression::Put(_) => "put",
1838            Expression::StageReference(_) => "stage_reference",
1839            Expression::Alias(_) => "alias",
1840            Expression::Cast(_) => "cast",
1841            Expression::Collation(_) => "collation",
1842            Expression::Case(_) => "case",
1843            Expression::And(_) => "and",
1844            Expression::Or(_) => "or",
1845            Expression::Add(_) => "add",
1846            Expression::Sub(_) => "sub",
1847            Expression::Mul(_) => "mul",
1848            Expression::Div(_) => "div",
1849            Expression::Mod(_) => "mod",
1850            Expression::Eq(_) => "eq",
1851            Expression::Neq(_) => "neq",
1852            Expression::Lt(_) => "lt",
1853            Expression::Lte(_) => "lte",
1854            Expression::Gt(_) => "gt",
1855            Expression::Gte(_) => "gte",
1856            Expression::Like(_) => "like",
1857            Expression::ILike(_) => "i_like",
1858            Expression::Match(_) => "match",
1859            Expression::BitwiseAnd(_) => "bitwise_and",
1860            Expression::BitwiseOr(_) => "bitwise_or",
1861            Expression::BitwiseXor(_) => "bitwise_xor",
1862            Expression::Concat(_) => "concat",
1863            Expression::Adjacent(_) => "adjacent",
1864            Expression::TsMatch(_) => "ts_match",
1865            Expression::PropertyEQ(_) => "property_e_q",
1866            Expression::ArrayContainsAll(_) => "array_contains_all",
1867            Expression::ArrayContainedBy(_) => "array_contained_by",
1868            Expression::ArrayOverlaps(_) => "array_overlaps",
1869            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1870            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1871            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1872            Expression::ExtendsLeft(_) => "extends_left",
1873            Expression::ExtendsRight(_) => "extends_right",
1874            Expression::Not(_) => "not",
1875            Expression::Neg(_) => "neg",
1876            Expression::BitwiseNot(_) => "bitwise_not",
1877            Expression::In(_) => "in",
1878            Expression::Between(_) => "between",
1879            Expression::IsNull(_) => "is_null",
1880            Expression::IsTrue(_) => "is_true",
1881            Expression::IsFalse(_) => "is_false",
1882            Expression::IsJson(_) => "is_json",
1883            Expression::Is(_) => "is",
1884            Expression::Exists(_) => "exists",
1885            Expression::MemberOf(_) => "member_of",
1886            Expression::Function(_) => "function",
1887            Expression::AggregateFunction(_) => "aggregate_function",
1888            Expression::WindowFunction(_) => "window_function",
1889            Expression::From(_) => "from",
1890            Expression::Join(_) => "join",
1891            Expression::JoinedTable(_) => "joined_table",
1892            Expression::Where(_) => "where",
1893            Expression::GroupBy(_) => "group_by",
1894            Expression::Having(_) => "having",
1895            Expression::OrderBy(_) => "order_by",
1896            Expression::Limit(_) => "limit",
1897            Expression::Offset(_) => "offset",
1898            Expression::Qualify(_) => "qualify",
1899            Expression::With(_) => "with",
1900            Expression::Cte(_) => "cte",
1901            Expression::DistributeBy(_) => "distribute_by",
1902            Expression::ClusterBy(_) => "cluster_by",
1903            Expression::SortBy(_) => "sort_by",
1904            Expression::LateralView(_) => "lateral_view",
1905            Expression::Hint(_) => "hint",
1906            Expression::Pseudocolumn(_) => "pseudocolumn",
1907            Expression::Connect(_) => "connect",
1908            Expression::Prior(_) => "prior",
1909            Expression::ConnectByRoot(_) => "connect_by_root",
1910            Expression::MatchRecognize(_) => "match_recognize",
1911            Expression::Ordered(_) => "ordered",
1912            Expression::Window(_) => "window",
1913            Expression::Over(_) => "over",
1914            Expression::WithinGroup(_) => "within_group",
1915            Expression::DataType(_) => "data_type",
1916            Expression::Array(_) => "array",
1917            Expression::Struct(_) => "struct",
1918            Expression::Tuple(_) => "tuple",
1919            Expression::Interval(_) => "interval",
1920            Expression::ConcatWs(_) => "concat_ws",
1921            Expression::Substring(_) => "substring",
1922            Expression::Upper(_) => "upper",
1923            Expression::Lower(_) => "lower",
1924            Expression::Length(_) => "length",
1925            Expression::Trim(_) => "trim",
1926            Expression::LTrim(_) => "l_trim",
1927            Expression::RTrim(_) => "r_trim",
1928            Expression::Replace(_) => "replace",
1929            Expression::Reverse(_) => "reverse",
1930            Expression::Left(_) => "left",
1931            Expression::Right(_) => "right",
1932            Expression::Repeat(_) => "repeat",
1933            Expression::Lpad(_) => "lpad",
1934            Expression::Rpad(_) => "rpad",
1935            Expression::Split(_) => "split",
1936            Expression::RegexpLike(_) => "regexp_like",
1937            Expression::RegexpReplace(_) => "regexp_replace",
1938            Expression::RegexpExtract(_) => "regexp_extract",
1939            Expression::Overlay(_) => "overlay",
1940            Expression::Abs(_) => "abs",
1941            Expression::Round(_) => "round",
1942            Expression::Floor(_) => "floor",
1943            Expression::Ceil(_) => "ceil",
1944            Expression::Power(_) => "power",
1945            Expression::Sqrt(_) => "sqrt",
1946            Expression::Cbrt(_) => "cbrt",
1947            Expression::Ln(_) => "ln",
1948            Expression::Log(_) => "log",
1949            Expression::Exp(_) => "exp",
1950            Expression::Sign(_) => "sign",
1951            Expression::Greatest(_) => "greatest",
1952            Expression::Least(_) => "least",
1953            Expression::CurrentDate(_) => "current_date",
1954            Expression::CurrentTime(_) => "current_time",
1955            Expression::CurrentTimestamp(_) => "current_timestamp",
1956            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1957            Expression::AtTimeZone(_) => "at_time_zone",
1958            Expression::DateAdd(_) => "date_add",
1959            Expression::DateSub(_) => "date_sub",
1960            Expression::DateDiff(_) => "date_diff",
1961            Expression::DateTrunc(_) => "date_trunc",
1962            Expression::Extract(_) => "extract",
1963            Expression::ToDate(_) => "to_date",
1964            Expression::ToTimestamp(_) => "to_timestamp",
1965            Expression::Date(_) => "date",
1966            Expression::Time(_) => "time",
1967            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1968            Expression::UnixDate(_) => "unix_date",
1969            Expression::UnixSeconds(_) => "unix_seconds",
1970            Expression::UnixMillis(_) => "unix_millis",
1971            Expression::UnixMicros(_) => "unix_micros",
1972            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1973            Expression::TimeStrToDate(_) => "time_str_to_date",
1974            Expression::DateToDi(_) => "date_to_di",
1975            Expression::DiToDate(_) => "di_to_date",
1976            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1977            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1978            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1979            Expression::YearOfWeek(_) => "year_of_week",
1980            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1981            Expression::Coalesce(_) => "coalesce",
1982            Expression::NullIf(_) => "null_if",
1983            Expression::IfFunc(_) => "if_func",
1984            Expression::IfNull(_) => "if_null",
1985            Expression::Nvl(_) => "nvl",
1986            Expression::Nvl2(_) => "nvl2",
1987            Expression::TryCast(_) => "try_cast",
1988            Expression::SafeCast(_) => "safe_cast",
1989            Expression::Count(_) => "count",
1990            Expression::Sum(_) => "sum",
1991            Expression::Avg(_) => "avg",
1992            Expression::Min(_) => "min",
1993            Expression::Max(_) => "max",
1994            Expression::GroupConcat(_) => "group_concat",
1995            Expression::StringAgg(_) => "string_agg",
1996            Expression::ListAgg(_) => "list_agg",
1997            Expression::ArrayAgg(_) => "array_agg",
1998            Expression::CountIf(_) => "count_if",
1999            Expression::SumIf(_) => "sum_if",
2000            Expression::Stddev(_) => "stddev",
2001            Expression::StddevPop(_) => "stddev_pop",
2002            Expression::StddevSamp(_) => "stddev_samp",
2003            Expression::Variance(_) => "variance",
2004            Expression::VarPop(_) => "var_pop",
2005            Expression::VarSamp(_) => "var_samp",
2006            Expression::Median(_) => "median",
2007            Expression::Mode(_) => "mode",
2008            Expression::First(_) => "first",
2009            Expression::Last(_) => "last",
2010            Expression::AnyValue(_) => "any_value",
2011            Expression::ApproxDistinct(_) => "approx_distinct",
2012            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2013            Expression::ApproxPercentile(_) => "approx_percentile",
2014            Expression::Percentile(_) => "percentile",
2015            Expression::LogicalAnd(_) => "logical_and",
2016            Expression::LogicalOr(_) => "logical_or",
2017            Expression::Skewness(_) => "skewness",
2018            Expression::BitwiseCount(_) => "bitwise_count",
2019            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2020            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2021            Expression::BoolXorAgg(_) => "bool_xor_agg",
2022            Expression::RowNumber(_) => "row_number",
2023            Expression::Rank(_) => "rank",
2024            Expression::DenseRank(_) => "dense_rank",
2025            Expression::NTile(_) => "n_tile",
2026            Expression::Lead(_) => "lead",
2027            Expression::Lag(_) => "lag",
2028            Expression::FirstValue(_) => "first_value",
2029            Expression::LastValue(_) => "last_value",
2030            Expression::NthValue(_) => "nth_value",
2031            Expression::PercentRank(_) => "percent_rank",
2032            Expression::CumeDist(_) => "cume_dist",
2033            Expression::PercentileCont(_) => "percentile_cont",
2034            Expression::PercentileDisc(_) => "percentile_disc",
2035            Expression::Contains(_) => "contains",
2036            Expression::StartsWith(_) => "starts_with",
2037            Expression::EndsWith(_) => "ends_with",
2038            Expression::Position(_) => "position",
2039            Expression::Initcap(_) => "initcap",
2040            Expression::Ascii(_) => "ascii",
2041            Expression::Chr(_) => "chr",
2042            Expression::CharFunc(_) => "char_func",
2043            Expression::Soundex(_) => "soundex",
2044            Expression::Levenshtein(_) => "levenshtein",
2045            Expression::ByteLength(_) => "byte_length",
2046            Expression::Hex(_) => "hex",
2047            Expression::LowerHex(_) => "lower_hex",
2048            Expression::Unicode(_) => "unicode",
2049            Expression::ModFunc(_) => "mod_func",
2050            Expression::Random(_) => "random",
2051            Expression::Rand(_) => "rand",
2052            Expression::TruncFunc(_) => "trunc_func",
2053            Expression::Pi(_) => "pi",
2054            Expression::Radians(_) => "radians",
2055            Expression::Degrees(_) => "degrees",
2056            Expression::Sin(_) => "sin",
2057            Expression::Cos(_) => "cos",
2058            Expression::Tan(_) => "tan",
2059            Expression::Asin(_) => "asin",
2060            Expression::Acos(_) => "acos",
2061            Expression::Atan(_) => "atan",
2062            Expression::Atan2(_) => "atan2",
2063            Expression::IsNan(_) => "is_nan",
2064            Expression::IsInf(_) => "is_inf",
2065            Expression::IntDiv(_) => "int_div",
2066            Expression::Decode(_) => "decode",
2067            Expression::DateFormat(_) => "date_format",
2068            Expression::FormatDate(_) => "format_date",
2069            Expression::Year(_) => "year",
2070            Expression::Month(_) => "month",
2071            Expression::Day(_) => "day",
2072            Expression::Hour(_) => "hour",
2073            Expression::Minute(_) => "minute",
2074            Expression::Second(_) => "second",
2075            Expression::DayOfWeek(_) => "day_of_week",
2076            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2077            Expression::DayOfMonth(_) => "day_of_month",
2078            Expression::DayOfYear(_) => "day_of_year",
2079            Expression::WeekOfYear(_) => "week_of_year",
2080            Expression::Quarter(_) => "quarter",
2081            Expression::AddMonths(_) => "add_months",
2082            Expression::MonthsBetween(_) => "months_between",
2083            Expression::LastDay(_) => "last_day",
2084            Expression::NextDay(_) => "next_day",
2085            Expression::Epoch(_) => "epoch",
2086            Expression::EpochMs(_) => "epoch_ms",
2087            Expression::FromUnixtime(_) => "from_unixtime",
2088            Expression::UnixTimestamp(_) => "unix_timestamp",
2089            Expression::MakeDate(_) => "make_date",
2090            Expression::MakeTimestamp(_) => "make_timestamp",
2091            Expression::TimestampTrunc(_) => "timestamp_trunc",
2092            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2093            Expression::SessionUser(_) => "session_user",
2094            Expression::SHA(_) => "s_h_a",
2095            Expression::SHA1Digest(_) => "s_h_a1_digest",
2096            Expression::TimeToUnix(_) => "time_to_unix",
2097            Expression::ArrayFunc(_) => "array_func",
2098            Expression::ArrayLength(_) => "array_length",
2099            Expression::ArraySize(_) => "array_size",
2100            Expression::Cardinality(_) => "cardinality",
2101            Expression::ArrayContains(_) => "array_contains",
2102            Expression::ArrayPosition(_) => "array_position",
2103            Expression::ArrayAppend(_) => "array_append",
2104            Expression::ArrayPrepend(_) => "array_prepend",
2105            Expression::ArrayConcat(_) => "array_concat",
2106            Expression::ArraySort(_) => "array_sort",
2107            Expression::ArrayReverse(_) => "array_reverse",
2108            Expression::ArrayDistinct(_) => "array_distinct",
2109            Expression::ArrayJoin(_) => "array_join",
2110            Expression::ArrayToString(_) => "array_to_string",
2111            Expression::Unnest(_) => "unnest",
2112            Expression::Explode(_) => "explode",
2113            Expression::ExplodeOuter(_) => "explode_outer",
2114            Expression::ArrayFilter(_) => "array_filter",
2115            Expression::ArrayTransform(_) => "array_transform",
2116            Expression::ArrayFlatten(_) => "array_flatten",
2117            Expression::ArrayCompact(_) => "array_compact",
2118            Expression::ArrayIntersect(_) => "array_intersect",
2119            Expression::ArrayUnion(_) => "array_union",
2120            Expression::ArrayExcept(_) => "array_except",
2121            Expression::ArrayRemove(_) => "array_remove",
2122            Expression::ArrayZip(_) => "array_zip",
2123            Expression::Sequence(_) => "sequence",
2124            Expression::Generate(_) => "generate",
2125            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2126            Expression::ToArray(_) => "to_array",
2127            Expression::StarMap(_) => "star_map",
2128            Expression::StructFunc(_) => "struct_func",
2129            Expression::StructExtract(_) => "struct_extract",
2130            Expression::NamedStruct(_) => "named_struct",
2131            Expression::MapFunc(_) => "map_func",
2132            Expression::MapFromEntries(_) => "map_from_entries",
2133            Expression::MapFromArrays(_) => "map_from_arrays",
2134            Expression::MapKeys(_) => "map_keys",
2135            Expression::MapValues(_) => "map_values",
2136            Expression::MapContainsKey(_) => "map_contains_key",
2137            Expression::MapConcat(_) => "map_concat",
2138            Expression::ElementAt(_) => "element_at",
2139            Expression::TransformKeys(_) => "transform_keys",
2140            Expression::TransformValues(_) => "transform_values",
2141            Expression::FunctionEmits(_) => "function_emits",
2142            Expression::JsonExtract(_) => "json_extract",
2143            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2144            Expression::JsonExtractPath(_) => "json_extract_path",
2145            Expression::JsonArray(_) => "json_array",
2146            Expression::JsonObject(_) => "json_object",
2147            Expression::JsonQuery(_) => "json_query",
2148            Expression::JsonValue(_) => "json_value",
2149            Expression::JsonArrayLength(_) => "json_array_length",
2150            Expression::JsonKeys(_) => "json_keys",
2151            Expression::JsonType(_) => "json_type",
2152            Expression::ParseJson(_) => "parse_json",
2153            Expression::ToJson(_) => "to_json",
2154            Expression::JsonSet(_) => "json_set",
2155            Expression::JsonInsert(_) => "json_insert",
2156            Expression::JsonRemove(_) => "json_remove",
2157            Expression::JsonMergePatch(_) => "json_merge_patch",
2158            Expression::JsonArrayAgg(_) => "json_array_agg",
2159            Expression::JsonObjectAgg(_) => "json_object_agg",
2160            Expression::Convert(_) => "convert",
2161            Expression::Typeof(_) => "typeof",
2162            Expression::Lambda(_) => "lambda",
2163            Expression::Parameter(_) => "parameter",
2164            Expression::Placeholder(_) => "placeholder",
2165            Expression::NamedArgument(_) => "named_argument",
2166            Expression::TableArgument(_) => "table_argument",
2167            Expression::SqlComment(_) => "sql_comment",
2168            Expression::NullSafeEq(_) => "null_safe_eq",
2169            Expression::NullSafeNeq(_) => "null_safe_neq",
2170            Expression::Glob(_) => "glob",
2171            Expression::SimilarTo(_) => "similar_to",
2172            Expression::Any(_) => "any",
2173            Expression::All(_) => "all",
2174            Expression::Overlaps(_) => "overlaps",
2175            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2176            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2177            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2178            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2179            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2180            Expression::Subscript(_) => "subscript",
2181            Expression::Dot(_) => "dot",
2182            Expression::MethodCall(_) => "method_call",
2183            Expression::ArraySlice(_) => "array_slice",
2184            Expression::CreateTable(_) => "create_table",
2185            Expression::DropTable(_) => "drop_table",
2186            Expression::AlterTable(_) => "alter_table",
2187            Expression::CreateIndex(_) => "create_index",
2188            Expression::DropIndex(_) => "drop_index",
2189            Expression::CreateView(_) => "create_view",
2190            Expression::DropView(_) => "drop_view",
2191            Expression::AlterView(_) => "alter_view",
2192            Expression::AlterIndex(_) => "alter_index",
2193            Expression::Truncate(_) => "truncate",
2194            Expression::Use(_) => "use",
2195            Expression::Cache(_) => "cache",
2196            Expression::Uncache(_) => "uncache",
2197            Expression::LoadData(_) => "load_data",
2198            Expression::Pragma(_) => "pragma",
2199            Expression::Grant(_) => "grant",
2200            Expression::Revoke(_) => "revoke",
2201            Expression::Comment(_) => "comment",
2202            Expression::SetStatement(_) => "set_statement",
2203            Expression::CreateSchema(_) => "create_schema",
2204            Expression::DropSchema(_) => "drop_schema",
2205            Expression::DropNamespace(_) => "drop_namespace",
2206            Expression::CreateDatabase(_) => "create_database",
2207            Expression::DropDatabase(_) => "drop_database",
2208            Expression::CreateFunction(_) => "create_function",
2209            Expression::DropFunction(_) => "drop_function",
2210            Expression::CreateProcedure(_) => "create_procedure",
2211            Expression::DropProcedure(_) => "drop_procedure",
2212            Expression::CreateSequence(_) => "create_sequence",
2213            Expression::DropSequence(_) => "drop_sequence",
2214            Expression::AlterSequence(_) => "alter_sequence",
2215            Expression::CreateTrigger(_) => "create_trigger",
2216            Expression::DropTrigger(_) => "drop_trigger",
2217            Expression::CreateType(_) => "create_type",
2218            Expression::DropType(_) => "drop_type",
2219            Expression::Describe(_) => "describe",
2220            Expression::Show(_) => "show",
2221            Expression::Command(_) => "command",
2222            Expression::Kill(_) => "kill",
2223            Expression::Execute(_) => "execute",
2224            Expression::Raw(_) => "raw",
2225            Expression::Paren(_) => "paren",
2226            Expression::Annotated(_) => "annotated",
2227            Expression::Refresh(_) => "refresh",
2228            Expression::LockingStatement(_) => "locking_statement",
2229            Expression::SequenceProperties(_) => "sequence_properties",
2230            Expression::TruncateTable(_) => "truncate_table",
2231            Expression::Clone(_) => "clone",
2232            Expression::Attach(_) => "attach",
2233            Expression::Detach(_) => "detach",
2234            Expression::Install(_) => "install",
2235            Expression::Summarize(_) => "summarize",
2236            Expression::Declare(_) => "declare",
2237            Expression::DeclareItem(_) => "declare_item",
2238            Expression::Set(_) => "set",
2239            Expression::Heredoc(_) => "heredoc",
2240            Expression::SetItem(_) => "set_item",
2241            Expression::QueryBand(_) => "query_band",
2242            Expression::UserDefinedFunction(_) => "user_defined_function",
2243            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2244            Expression::ProjectionDef(_) => "projection_def",
2245            Expression::TableAlias(_) => "table_alias",
2246            Expression::ByteString(_) => "byte_string",
2247            Expression::HexStringExpr(_) => "hex_string_expr",
2248            Expression::UnicodeString(_) => "unicode_string",
2249            Expression::ColumnPosition(_) => "column_position",
2250            Expression::ColumnDef(_) => "column_def",
2251            Expression::AlterColumn(_) => "alter_column",
2252            Expression::AlterSortKey(_) => "alter_sort_key",
2253            Expression::AlterSet(_) => "alter_set",
2254            Expression::RenameColumn(_) => "rename_column",
2255            Expression::Comprehension(_) => "comprehension",
2256            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2257            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2258            Expression::IndexConstraintOption(_) => "index_constraint_option",
2259            Expression::ColumnConstraint(_) => "column_constraint",
2260            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2261            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2262            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2263            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2264            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2265            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2266            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2267            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2268            Expression::WithOperator(_) => "with_operator",
2269            Expression::GeneratedAsIdentityColumnConstraint(_) => "generated_as_identity_column_constraint",
2270            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2271            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2272            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2273            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2274            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2275            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2276            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2277            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2278            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2279            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2280            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2281            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2282            Expression::PathColumnConstraint(_) => "path_column_constraint",
2283            Expression::Constraint(_) => "constraint",
2284            Expression::Export(_) => "export",
2285            Expression::Filter(_) => "filter",
2286            Expression::Changes(_) => "changes",
2287            Expression::CopyParameter(_) => "copy_parameter",
2288            Expression::Credentials(_) => "credentials",
2289            Expression::Directory(_) => "directory",
2290            Expression::ForeignKey(_) => "foreign_key",
2291            Expression::ColumnPrefix(_) => "column_prefix",
2292            Expression::PrimaryKey(_) => "primary_key",
2293            Expression::IntoClause(_) => "into_clause",
2294            Expression::JoinHint(_) => "join_hint",
2295            Expression::Opclass(_) => "opclass",
2296            Expression::Index(_) => "index",
2297            Expression::IndexParameters(_) => "index_parameters",
2298            Expression::ConditionalInsert(_) => "conditional_insert",
2299            Expression::MultitableInserts(_) => "multitable_inserts",
2300            Expression::OnConflict(_) => "on_conflict",
2301            Expression::OnCondition(_) => "on_condition",
2302            Expression::Returning(_) => "returning",
2303            Expression::Introducer(_) => "introducer",
2304            Expression::PartitionRange(_) => "partition_range",
2305            Expression::Fetch(_) => "fetch",
2306            Expression::Group(_) => "group",
2307            Expression::Cube(_) => "cube",
2308            Expression::Rollup(_) => "rollup",
2309            Expression::GroupingSets(_) => "grouping_sets",
2310            Expression::LimitOptions(_) => "limit_options",
2311            Expression::Lateral(_) => "lateral",
2312            Expression::TableFromRows(_) => "table_from_rows",
2313            Expression::RowsFrom(_) => "rows_from",
2314            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2315            Expression::WithFill(_) => "with_fill",
2316            Expression::Property(_) => "property",
2317            Expression::GrantPrivilege(_) => "grant_privilege",
2318            Expression::GrantPrincipal(_) => "grant_principal",
2319            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2320            Expression::AlgorithmProperty(_) => "algorithm_property",
2321            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2322            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2323            Expression::BackupProperty(_) => "backup_property",
2324            Expression::BuildProperty(_) => "build_property",
2325            Expression::BlockCompressionProperty(_) => "block_compression_property",
2326            Expression::CharacterSetProperty(_) => "character_set_property",
2327            Expression::ChecksumProperty(_) => "checksum_property",
2328            Expression::CollateProperty(_) => "collate_property",
2329            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2330            Expression::DataDeletionProperty(_) => "data_deletion_property",
2331            Expression::DefinerProperty(_) => "definer_property",
2332            Expression::DistKeyProperty(_) => "dist_key_property",
2333            Expression::DistributedByProperty(_) => "distributed_by_property",
2334            Expression::DistStyleProperty(_) => "dist_style_property",
2335            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2336            Expression::EngineProperty(_) => "engine_property",
2337            Expression::ToTableProperty(_) => "to_table_property",
2338            Expression::ExecuteAsProperty(_) => "execute_as_property",
2339            Expression::ExternalProperty(_) => "external_property",
2340            Expression::FallbackProperty(_) => "fallback_property",
2341            Expression::FileFormatProperty(_) => "file_format_property",
2342            Expression::CredentialsProperty(_) => "credentials_property",
2343            Expression::FreespaceProperty(_) => "freespace_property",
2344            Expression::InheritsProperty(_) => "inherits_property",
2345            Expression::InputModelProperty(_) => "input_model_property",
2346            Expression::OutputModelProperty(_) => "output_model_property",
2347            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2348            Expression::JournalProperty(_) => "journal_property",
2349            Expression::LanguageProperty(_) => "language_property",
2350            Expression::EnviromentProperty(_) => "enviroment_property",
2351            Expression::ClusteredByProperty(_) => "clustered_by_property",
2352            Expression::DictProperty(_) => "dict_property",
2353            Expression::DictRange(_) => "dict_range",
2354            Expression::OnCluster(_) => "on_cluster",
2355            Expression::LikeProperty(_) => "like_property",
2356            Expression::LocationProperty(_) => "location_property",
2357            Expression::LockProperty(_) => "lock_property",
2358            Expression::LockingProperty(_) => "locking_property",
2359            Expression::LogProperty(_) => "log_property",
2360            Expression::MaterializedProperty(_) => "materialized_property",
2361            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2362            Expression::OnProperty(_) => "on_property",
2363            Expression::OnCommitProperty(_) => "on_commit_property",
2364            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2365            Expression::PartitionByProperty(_) => "partition_by_property",
2366            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2367            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2368            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2369            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2370            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2371            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2372            Expression::PartitionList(_) => "partition_list",
2373            Expression::Partition(_) => "partition",
2374            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2375            Expression::UniqueKeyProperty(_) => "unique_key_property",
2376            Expression::RollupProperty(_) => "rollup_property",
2377            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2378            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2379            Expression::RemoteWithConnectionModelProperty(_) => "remote_with_connection_model_property",
2380            Expression::ReturnsProperty(_) => "returns_property",
2381            Expression::RowFormatProperty(_) => "row_format_property",
2382            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2383            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2384            Expression::QueryTransform(_) => "query_transform",
2385            Expression::SampleProperty(_) => "sample_property",
2386            Expression::SecurityProperty(_) => "security_property",
2387            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2388            Expression::SemanticView(_) => "semantic_view",
2389            Expression::SerdeProperties(_) => "serde_properties",
2390            Expression::SetProperty(_) => "set_property",
2391            Expression::SharingProperty(_) => "sharing_property",
2392            Expression::SetConfigProperty(_) => "set_config_property",
2393            Expression::SettingsProperty(_) => "settings_property",
2394            Expression::SortKeyProperty(_) => "sort_key_property",
2395            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2396            Expression::SqlSecurityProperty(_) => "sql_security_property",
2397            Expression::StabilityProperty(_) => "stability_property",
2398            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2399            Expression::TemporaryProperty(_) => "temporary_property",
2400            Expression::Tags(_) => "tags",
2401            Expression::TransformModelProperty(_) => "transform_model_property",
2402            Expression::TransientProperty(_) => "transient_property",
2403            Expression::UsingTemplateProperty(_) => "using_template_property",
2404            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2405            Expression::VolatileProperty(_) => "volatile_property",
2406            Expression::WithDataProperty(_) => "with_data_property",
2407            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2408            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2409            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2410            Expression::WithProcedureOptions(_) => "with_procedure_options",
2411            Expression::EncodeProperty(_) => "encode_property",
2412            Expression::IncludeProperty(_) => "include_property",
2413            Expression::Properties(_) => "properties",
2414            Expression::OptionsProperty(_) => "options_property",
2415            Expression::InputOutputFormat(_) => "input_output_format",
2416            Expression::Reference(_) => "reference",
2417            Expression::QueryOption(_) => "query_option",
2418            Expression::WithTableHint(_) => "with_table_hint",
2419            Expression::IndexTableHint(_) => "index_table_hint",
2420            Expression::HistoricalData(_) => "historical_data",
2421            Expression::Get(_) => "get",
2422            Expression::SetOperation(_) => "set_operation",
2423            Expression::Var(_) => "var",
2424            Expression::Variadic(_) => "variadic",
2425            Expression::Version(_) => "version",
2426            Expression::Schema(_) => "schema",
2427            Expression::Lock(_) => "lock",
2428            Expression::TableSample(_) => "table_sample",
2429            Expression::Tag(_) => "tag",
2430            Expression::UnpivotColumns(_) => "unpivot_columns",
2431            Expression::WindowSpec(_) => "window_spec",
2432            Expression::SessionParameter(_) => "session_parameter",
2433            Expression::PseudoType(_) => "pseudo_type",
2434            Expression::ObjectIdentifier(_) => "object_identifier",
2435            Expression::Transaction(_) => "transaction",
2436            Expression::Commit(_) => "commit",
2437            Expression::Rollback(_) => "rollback",
2438            Expression::AlterSession(_) => "alter_session",
2439            Expression::Analyze(_) => "analyze",
2440            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2441            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2442            Expression::AnalyzeSample(_) => "analyze_sample",
2443            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2444            Expression::AnalyzeDelete(_) => "analyze_delete",
2445            Expression::AnalyzeWith(_) => "analyze_with",
2446            Expression::AnalyzeValidate(_) => "analyze_validate",
2447            Expression::AddPartition(_) => "add_partition",
2448            Expression::AttachOption(_) => "attach_option",
2449            Expression::DropPartition(_) => "drop_partition",
2450            Expression::ReplacePartition(_) => "replace_partition",
2451            Expression::DPipe(_) => "d_pipe",
2452            Expression::Operator(_) => "operator",
2453            Expression::PivotAny(_) => "pivot_any",
2454            Expression::Aliases(_) => "aliases",
2455            Expression::AtIndex(_) => "at_index",
2456            Expression::FromTimeZone(_) => "from_time_zone",
2457            Expression::FormatPhrase(_) => "format_phrase",
2458            Expression::ForIn(_) => "for_in",
2459            Expression::TimeUnit(_) => "time_unit",
2460            Expression::IntervalOp(_) => "interval_op",
2461            Expression::IntervalSpan(_) => "interval_span",
2462            Expression::HavingMax(_) => "having_max",
2463            Expression::CosineDistance(_) => "cosine_distance",
2464            Expression::DotProduct(_) => "dot_product",
2465            Expression::EuclideanDistance(_) => "euclidean_distance",
2466            Expression::ManhattanDistance(_) => "manhattan_distance",
2467            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2468            Expression::Booland(_) => "booland",
2469            Expression::Boolor(_) => "boolor",
2470            Expression::ParameterizedAgg(_) => "parameterized_agg",
2471            Expression::ArgMax(_) => "arg_max",
2472            Expression::ArgMin(_) => "arg_min",
2473            Expression::ApproxTopK(_) => "approx_top_k",
2474            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2475            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2476            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2477            Expression::ApproxTopSum(_) => "approx_top_sum",
2478            Expression::ApproxQuantiles(_) => "approx_quantiles",
2479            Expression::Minhash(_) => "minhash",
2480            Expression::FarmFingerprint(_) => "farm_fingerprint",
2481            Expression::Float64(_) => "float64",
2482            Expression::Transform(_) => "transform",
2483            Expression::Translate(_) => "translate",
2484            Expression::Grouping(_) => "grouping",
2485            Expression::GroupingId(_) => "grouping_id",
2486            Expression::Anonymous(_) => "anonymous",
2487            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2488            Expression::CombinedAggFunc(_) => "combined_agg_func",
2489            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2490            Expression::HashAgg(_) => "hash_agg",
2491            Expression::Hll(_) => "hll",
2492            Expression::Apply(_) => "apply",
2493            Expression::ToBoolean(_) => "to_boolean",
2494            Expression::List(_) => "list",
2495            Expression::ToMap(_) => "to_map",
2496            Expression::Pad(_) => "pad",
2497            Expression::ToChar(_) => "to_char",
2498            Expression::ToNumber(_) => "to_number",
2499            Expression::ToDouble(_) => "to_double",
2500            Expression::Int64(_) => "int64",
2501            Expression::StringFunc(_) => "string_func",
2502            Expression::ToDecfloat(_) => "to_decfloat",
2503            Expression::TryToDecfloat(_) => "try_to_decfloat",
2504            Expression::ToFile(_) => "to_file",
2505            Expression::Columns(_) => "columns",
2506            Expression::ConvertToCharset(_) => "convert_to_charset",
2507            Expression::ConvertTimezone(_) => "convert_timezone",
2508            Expression::GenerateSeries(_) => "generate_series",
2509            Expression::AIAgg(_) => "a_i_agg",
2510            Expression::AIClassify(_) => "a_i_classify",
2511            Expression::ArrayAll(_) => "array_all",
2512            Expression::ArrayAny(_) => "array_any",
2513            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2514            Expression::StPoint(_) => "st_point",
2515            Expression::StDistance(_) => "st_distance",
2516            Expression::StringToArray(_) => "string_to_array",
2517            Expression::ArraySum(_) => "array_sum",
2518            Expression::ObjectAgg(_) => "object_agg",
2519            Expression::CastToStrType(_) => "cast_to_str_type",
2520            Expression::CheckJson(_) => "check_json",
2521            Expression::CheckXml(_) => "check_xml",
2522            Expression::TranslateCharacters(_) => "translate_characters",
2523            Expression::CurrentSchemas(_) => "current_schemas",
2524            Expression::CurrentDatetime(_) => "current_datetime",
2525            Expression::Localtime(_) => "localtime",
2526            Expression::Localtimestamp(_) => "localtimestamp",
2527            Expression::Systimestamp(_) => "systimestamp",
2528            Expression::CurrentSchema(_) => "current_schema",
2529            Expression::CurrentUser(_) => "current_user",
2530            Expression::UtcTime(_) => "utc_time",
2531            Expression::UtcTimestamp(_) => "utc_timestamp",
2532            Expression::Timestamp(_) => "timestamp",
2533            Expression::DateBin(_) => "date_bin",
2534            Expression::Datetime(_) => "datetime",
2535            Expression::DatetimeAdd(_) => "datetime_add",
2536            Expression::DatetimeSub(_) => "datetime_sub",
2537            Expression::DatetimeDiff(_) => "datetime_diff",
2538            Expression::DatetimeTrunc(_) => "datetime_trunc",
2539            Expression::Dayname(_) => "dayname",
2540            Expression::MakeInterval(_) => "make_interval",
2541            Expression::PreviousDay(_) => "previous_day",
2542            Expression::Elt(_) => "elt",
2543            Expression::TimestampAdd(_) => "timestamp_add",
2544            Expression::TimestampSub(_) => "timestamp_sub",
2545            Expression::TimestampDiff(_) => "timestamp_diff",
2546            Expression::TimeSlice(_) => "time_slice",
2547            Expression::TimeAdd(_) => "time_add",
2548            Expression::TimeSub(_) => "time_sub",
2549            Expression::TimeDiff(_) => "time_diff",
2550            Expression::TimeTrunc(_) => "time_trunc",
2551            Expression::DateFromParts(_) => "date_from_parts",
2552            Expression::TimeFromParts(_) => "time_from_parts",
2553            Expression::DecodeCase(_) => "decode_case",
2554            Expression::Decrypt(_) => "decrypt",
2555            Expression::DecryptRaw(_) => "decrypt_raw",
2556            Expression::Encode(_) => "encode",
2557            Expression::Encrypt(_) => "encrypt",
2558            Expression::EncryptRaw(_) => "encrypt_raw",
2559            Expression::EqualNull(_) => "equal_null",
2560            Expression::ToBinary(_) => "to_binary",
2561            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2562            Expression::Base64DecodeString(_) => "base64_decode_string",
2563            Expression::Base64Encode(_) => "base64_encode",
2564            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2565            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2566            Expression::GapFill(_) => "gap_fill",
2567            Expression::GenerateDateArray(_) => "generate_date_array",
2568            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2569            Expression::GetExtract(_) => "get_extract",
2570            Expression::Getbit(_) => "getbit",
2571            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2572            Expression::HexEncode(_) => "hex_encode",
2573            Expression::Compress(_) => "compress",
2574            Expression::DecompressBinary(_) => "decompress_binary",
2575            Expression::DecompressString(_) => "decompress_string",
2576            Expression::Xor(_) => "xor",
2577            Expression::Nullif(_) => "nullif",
2578            Expression::JSON(_) => "j_s_o_n",
2579            Expression::JSONPath(_) => "j_s_o_n_path",
2580            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2581            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2582            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2583            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2584            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2585            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2586            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2587            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2588            Expression::Format(_) => "format",
2589            Expression::JSONKeys(_) => "j_s_o_n_keys",
2590            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2591            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2592            Expression::JSONObject(_) => "j_s_o_n_object",
2593            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2594            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2595            Expression::JSONArray(_) => "j_s_o_n_array",
2596            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2597            Expression::JSONExists(_) => "j_s_o_n_exists",
2598            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2599            Expression::JSONSchema(_) => "j_s_o_n_schema",
2600            Expression::JSONSet(_) => "j_s_o_n_set",
2601            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2602            Expression::JSONValue(_) => "j_s_o_n_value",
2603            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2604            Expression::JSONRemove(_) => "j_s_o_n_remove",
2605            Expression::JSONTable(_) => "j_s_o_n_table",
2606            Expression::JSONType(_) => "j_s_o_n_type",
2607            Expression::ObjectInsert(_) => "object_insert",
2608            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2609            Expression::OpenJSON(_) => "open_j_s_o_n",
2610            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2611            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2612            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2613            Expression::JSONCast(_) => "j_s_o_n_cast",
2614            Expression::JSONExtract(_) => "j_s_o_n_extract",
2615            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2616            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2617            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2618            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2619            Expression::JSONFormat(_) => "j_s_o_n_format",
2620            Expression::JSONBool(_) => "j_s_o_n_bool",
2621            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2622            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2623            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2624            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2625            Expression::ParseJSON(_) => "parse_j_s_o_n",
2626            Expression::ParseUrl(_) => "parse_url",
2627            Expression::ParseIp(_) => "parse_ip",
2628            Expression::ParseTime(_) => "parse_time",
2629            Expression::ParseDatetime(_) => "parse_datetime",
2630            Expression::Map(_) => "map",
2631            Expression::MapCat(_) => "map_cat",
2632            Expression::MapDelete(_) => "map_delete",
2633            Expression::MapInsert(_) => "map_insert",
2634            Expression::MapPick(_) => "map_pick",
2635            Expression::ScopeResolution(_) => "scope_resolution",
2636            Expression::Slice(_) => "slice",
2637            Expression::VarMap(_) => "var_map",
2638            Expression::MatchAgainst(_) => "match_against",
2639            Expression::MD5Digest(_) => "m_d5_digest",
2640            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2641            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2642            Expression::Monthname(_) => "monthname",
2643            Expression::Ntile(_) => "ntile",
2644            Expression::Normalize(_) => "normalize",
2645            Expression::Normal(_) => "normal",
2646            Expression::Predict(_) => "predict",
2647            Expression::MLTranslate(_) => "m_l_translate",
2648            Expression::FeaturesAtTime(_) => "features_at_time",
2649            Expression::GenerateEmbedding(_) => "generate_embedding",
2650            Expression::MLForecast(_) => "m_l_forecast",
2651            Expression::ModelAttribute(_) => "model_attribute",
2652            Expression::VectorSearch(_) => "vector_search",
2653            Expression::Quantile(_) => "quantile",
2654            Expression::ApproxQuantile(_) => "approx_quantile",
2655            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2656            Expression::Randn(_) => "randn",
2657            Expression::Randstr(_) => "randstr",
2658            Expression::RangeN(_) => "range_n",
2659            Expression::RangeBucket(_) => "range_bucket",
2660            Expression::ReadCSV(_) => "read_c_s_v",
2661            Expression::ReadParquet(_) => "read_parquet",
2662            Expression::Reduce(_) => "reduce",
2663            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2664            Expression::RegexpILike(_) => "regexp_i_like",
2665            Expression::RegexpFullMatch(_) => "regexp_full_match",
2666            Expression::RegexpInstr(_) => "regexp_instr",
2667            Expression::RegexpSplit(_) => "regexp_split",
2668            Expression::RegexpCount(_) => "regexp_count",
2669            Expression::RegrValx(_) => "regr_valx",
2670            Expression::RegrValy(_) => "regr_valy",
2671            Expression::RegrAvgy(_) => "regr_avgy",
2672            Expression::RegrAvgx(_) => "regr_avgx",
2673            Expression::RegrCount(_) => "regr_count",
2674            Expression::RegrIntercept(_) => "regr_intercept",
2675            Expression::RegrR2(_) => "regr_r2",
2676            Expression::RegrSxx(_) => "regr_sxx",
2677            Expression::RegrSxy(_) => "regr_sxy",
2678            Expression::RegrSyy(_) => "regr_syy",
2679            Expression::RegrSlope(_) => "regr_slope",
2680            Expression::SafeAdd(_) => "safe_add",
2681            Expression::SafeDivide(_) => "safe_divide",
2682            Expression::SafeMultiply(_) => "safe_multiply",
2683            Expression::SafeSubtract(_) => "safe_subtract",
2684            Expression::SHA2(_) => "s_h_a2",
2685            Expression::SHA2Digest(_) => "s_h_a2_digest",
2686            Expression::SortArray(_) => "sort_array",
2687            Expression::SplitPart(_) => "split_part",
2688            Expression::SubstringIndex(_) => "substring_index",
2689            Expression::StandardHash(_) => "standard_hash",
2690            Expression::StrPosition(_) => "str_position",
2691            Expression::Search(_) => "search",
2692            Expression::SearchIp(_) => "search_ip",
2693            Expression::StrToDate(_) => "str_to_date",
2694            Expression::DateStrToDate(_) => "date_str_to_date",
2695            Expression::DateToDateStr(_) => "date_to_date_str",
2696            Expression::StrToTime(_) => "str_to_time",
2697            Expression::StrToUnix(_) => "str_to_unix",
2698            Expression::StrToMap(_) => "str_to_map",
2699            Expression::NumberToStr(_) => "number_to_str",
2700            Expression::FromBase(_) => "from_base",
2701            Expression::Stuff(_) => "stuff",
2702            Expression::TimeToStr(_) => "time_to_str",
2703            Expression::TimeStrToTime(_) => "time_str_to_time",
2704            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2705            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2706            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2707            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2708            Expression::Unhex(_) => "unhex",
2709            Expression::Uniform(_) => "uniform",
2710            Expression::UnixToStr(_) => "unix_to_str",
2711            Expression::UnixToTime(_) => "unix_to_time",
2712            Expression::Uuid(_) => "uuid",
2713            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2714            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2715            Expression::Corr(_) => "corr",
2716            Expression::WidthBucket(_) => "width_bucket",
2717            Expression::CovarSamp(_) => "covar_samp",
2718            Expression::CovarPop(_) => "covar_pop",
2719            Expression::Week(_) => "week",
2720            Expression::XMLElement(_) => "x_m_l_element",
2721            Expression::XMLGet(_) => "x_m_l_get",
2722            Expression::XMLTable(_) => "x_m_l_table",
2723            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2724            Expression::Zipf(_) => "zipf",
2725            Expression::Merge(_) => "merge",
2726            Expression::When(_) => "when",
2727            Expression::Whens(_) => "whens",
2728            Expression::NextValueFor(_) => "next_value_for",
2729            Expression::ReturnStmt(_) => "return_stmt",
2730        }
2731    }
2732
2733    /// Returns the primary child expression (".this" in sqlglot).
2734    pub fn get_this(&self) -> Option<&Expression> {
2735        match self {
2736            // Unary ops
2737            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2738            // UnaryFunc variants
2739            Expression::Upper(f) | Expression::Lower(f) | Expression::Length(f)
2740            | Expression::LTrim(f) | Expression::RTrim(f) | Expression::Reverse(f)
2741            | Expression::Abs(f) | Expression::Sqrt(f) | Expression::Cbrt(f)
2742            | Expression::Ln(f) | Expression::Exp(f) | Expression::Sign(f)
2743            | Expression::Date(f) | Expression::Time(f) | Expression::Initcap(f)
2744            | Expression::Ascii(f) | Expression::Chr(f) | Expression::Soundex(f)
2745            | Expression::ByteLength(f) | Expression::Hex(f) | Expression::LowerHex(f)
2746            | Expression::Unicode(f) | Expression::Typeof(f)
2747            | Expression::Explode(f) | Expression::ExplodeOuter(f)
2748            | Expression::MapFromEntries(f) | Expression::MapKeys(f) | Expression::MapValues(f)
2749            | Expression::ArrayLength(f) | Expression::ArraySize(f) | Expression::Cardinality(f)
2750            | Expression::ArrayReverse(f) | Expression::ArrayDistinct(f)
2751            | Expression::ArrayFlatten(f) | Expression::ArrayCompact(f) | Expression::ToArray(f)
2752            | Expression::JsonArrayLength(f) | Expression::JsonKeys(f) | Expression::JsonType(f)
2753            | Expression::ParseJson(f) | Expression::ToJson(f)
2754            | Expression::Radians(f) | Expression::Degrees(f)
2755            | Expression::Sin(f) | Expression::Cos(f) | Expression::Tan(f)
2756            | Expression::Asin(f) | Expression::Acos(f) | Expression::Atan(f)
2757            | Expression::IsNan(f) | Expression::IsInf(f)
2758            | Expression::Year(f) | Expression::Month(f) | Expression::Day(f)
2759            | Expression::Hour(f) | Expression::Minute(f) | Expression::Second(f)
2760            | Expression::DayOfWeek(f) | Expression::DayOfWeekIso(f)
2761            | Expression::DayOfMonth(f) | Expression::DayOfYear(f)
2762            | Expression::WeekOfYear(f) | Expression::Quarter(f)
2763            | Expression::Epoch(f) | Expression::EpochMs(f)
2764            | Expression::BitwiseCount(f)
2765            | Expression::DateFromUnixDate(f) | Expression::UnixDate(f)
2766            | Expression::UnixSeconds(f) | Expression::UnixMillis(f) | Expression::UnixMicros(f)
2767            | Expression::TimeStrToDate(f) | Expression::DateToDi(f) | Expression::DiToDate(f)
2768            | Expression::TsOrDiToDi(f) | Expression::TsOrDsToDatetime(f) | Expression::TsOrDsToTimestamp(f)
2769            | Expression::YearOfWeek(f) | Expression::YearOfWeekIso(f)
2770            | Expression::SHA(f) | Expression::SHA1Digest(f)
2771            | Expression::TimeToUnix(f) | Expression::TimeStrToUnix(f)
2772            | Expression::Int64(f) | Expression::JSONBool(f)
2773            | Expression::MD5NumberLower64(f) | Expression::MD5NumberUpper64(f)
2774            | Expression::DateStrToDate(f) | Expression::DateToDateStr(f)
2775            => Some(&f.this),
2776            // BinaryFunc - this is the primary child
2777            Expression::Power(f) | Expression::NullIf(f) | Expression::IfNull(f)
2778            | Expression::Nvl(f) | Expression::Contains(f)
2779            | Expression::StartsWith(f) | Expression::EndsWith(f)
2780            | Expression::Levenshtein(f) | Expression::ModFunc(f) | Expression::IntDiv(f)
2781            | Expression::Atan2(f) | Expression::AddMonths(f) | Expression::MonthsBetween(f)
2782            | Expression::NextDay(f) | Expression::UnixToTimeStr(f)
2783            | Expression::ArrayContains(f) | Expression::ArrayPosition(f)
2784            | Expression::ArrayAppend(f) | Expression::ArrayPrepend(f)
2785            | Expression::ArrayUnion(f) | Expression::ArrayExcept(f)
2786            | Expression::ArrayRemove(f) | Expression::StarMap(f)
2787            | Expression::MapFromArrays(f) | Expression::MapContainsKey(f)
2788            | Expression::ElementAt(f) | Expression::JsonMergePatch(f)
2789            | Expression::JSONBContains(f) | Expression::JSONBExtract(f)
2790            => Some(&f.this),
2791            // AggFunc - this is the primary child
2792            Expression::Sum(af) | Expression::Avg(af) | Expression::Min(af) | Expression::Max(af)
2793            | Expression::ArrayAgg(af) | Expression::CountIf(af)
2794            | Expression::Stddev(af) | Expression::StddevPop(af) | Expression::StddevSamp(af)
2795            | Expression::Variance(af) | Expression::VarPop(af) | Expression::VarSamp(af)
2796            | Expression::Median(af) | Expression::Mode(af)
2797            | Expression::First(af) | Expression::Last(af) | Expression::AnyValue(af)
2798            | Expression::ApproxDistinct(af) | Expression::ApproxCountDistinct(af)
2799            | Expression::LogicalAnd(af) | Expression::LogicalOr(af) | Expression::Skewness(af)
2800            | Expression::ArrayConcatAgg(af) | Expression::ArrayUniqueAgg(af) | Expression::BoolXorAgg(af)
2801            | Expression::BitwiseAndAgg(af) | Expression::BitwiseOrAgg(af) | Expression::BitwiseXorAgg(af)
2802            => Some(&af.this),
2803            // Binary operations - left is "this" in sqlglot
2804            Expression::And(op) | Expression::Or(op) | Expression::Add(op)
2805            | Expression::Sub(op) | Expression::Mul(op) | Expression::Div(op)
2806            | Expression::Mod(op) | Expression::Eq(op) | Expression::Neq(op)
2807            | Expression::Lt(op) | Expression::Lte(op) | Expression::Gt(op)
2808            | Expression::Gte(op) | Expression::BitwiseAnd(op) | Expression::BitwiseOr(op)
2809            | Expression::BitwiseXor(op) | Expression::Concat(op)
2810            | Expression::Adjacent(op) | Expression::TsMatch(op) | Expression::PropertyEQ(op)
2811            | Expression::ArrayContainsAll(op) | Expression::ArrayContainedBy(op)
2812            | Expression::ArrayOverlaps(op) | Expression::JSONBContainsAllTopKeys(op)
2813            | Expression::JSONBContainsAnyTopKeys(op) | Expression::JSONBDeleteAtPath(op)
2814            | Expression::ExtendsLeft(op) | Expression::ExtendsRight(op)
2815            | Expression::Is(op) | Expression::MemberOf(op) | Expression::Match(op)
2816            | Expression::NullSafeEq(op) | Expression::NullSafeNeq(op) | Expression::Glob(op)
2817            | Expression::BitwiseLeftShift(op) | Expression::BitwiseRightShift(op)
2818            => Some(&op.left),
2819            // Like operations - left is "this"
2820            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2821            // Structural types with .this
2822            Expression::Alias(a) => Some(&a.this),
2823            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2824            Expression::Paren(p) => Some(&p.this),
2825            Expression::Annotated(a) => Some(&a.this),
2826            Expression::Subquery(s) => Some(&s.this),
2827            Expression::Where(w) => Some(&w.this),
2828            Expression::Having(h) => Some(&h.this),
2829            Expression::Qualify(q) => Some(&q.this),
2830            Expression::IsNull(i) => Some(&i.this),
2831            Expression::Exists(e) => Some(&e.this),
2832            Expression::Ordered(o) => Some(&o.this),
2833            Expression::WindowFunction(wf) => Some(&wf.this),
2834            Expression::Cte(cte) => Some(&cte.this),
2835            Expression::Between(b) => Some(&b.this),
2836            Expression::In(i) => Some(&i.this),
2837            Expression::ReturnStmt(e) => Some(e),
2838            _ => None,
2839        }
2840    }
2841
2842    /// Returns the secondary child expression (".expression" in sqlglot).
2843    pub fn get_expression(&self) -> Option<&Expression> {
2844        match self {
2845            // Binary operations - right is "expression"
2846            Expression::And(op) | Expression::Or(op) | Expression::Add(op)
2847            | Expression::Sub(op) | Expression::Mul(op) | Expression::Div(op)
2848            | Expression::Mod(op) | Expression::Eq(op) | Expression::Neq(op)
2849            | Expression::Lt(op) | Expression::Lte(op) | Expression::Gt(op)
2850            | Expression::Gte(op) | Expression::BitwiseAnd(op) | Expression::BitwiseOr(op)
2851            | Expression::BitwiseXor(op) | Expression::Concat(op)
2852            | Expression::Adjacent(op) | Expression::TsMatch(op) | Expression::PropertyEQ(op)
2853            | Expression::ArrayContainsAll(op) | Expression::ArrayContainedBy(op)
2854            | Expression::ArrayOverlaps(op) | Expression::JSONBContainsAllTopKeys(op)
2855            | Expression::JSONBContainsAnyTopKeys(op) | Expression::JSONBDeleteAtPath(op)
2856            | Expression::ExtendsLeft(op) | Expression::ExtendsRight(op)
2857            | Expression::Is(op) | Expression::MemberOf(op) | Expression::Match(op)
2858            | Expression::NullSafeEq(op) | Expression::NullSafeNeq(op) | Expression::Glob(op)
2859            | Expression::BitwiseLeftShift(op) | Expression::BitwiseRightShift(op)
2860            => Some(&op.right),
2861            // Like operations - right is "expression"
2862            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
2863            // BinaryFunc - expression is the secondary
2864            Expression::Power(f) | Expression::NullIf(f) | Expression::IfNull(f)
2865            | Expression::Nvl(f) | Expression::Contains(f)
2866            | Expression::StartsWith(f) | Expression::EndsWith(f)
2867            | Expression::Levenshtein(f) | Expression::ModFunc(f) | Expression::IntDiv(f)
2868            | Expression::Atan2(f) | Expression::AddMonths(f) | Expression::MonthsBetween(f)
2869            | Expression::NextDay(f) | Expression::UnixToTimeStr(f)
2870            | Expression::ArrayContains(f) | Expression::ArrayPosition(f)
2871            | Expression::ArrayAppend(f) | Expression::ArrayPrepend(f)
2872            | Expression::ArrayUnion(f) | Expression::ArrayExcept(f)
2873            | Expression::ArrayRemove(f) | Expression::StarMap(f)
2874            | Expression::MapFromArrays(f) | Expression::MapContainsKey(f)
2875            | Expression::ElementAt(f) | Expression::JsonMergePatch(f)
2876            | Expression::JSONBContains(f) | Expression::JSONBExtract(f)
2877            => Some(&f.expression),
2878            _ => None,
2879        }
2880    }
2881
2882    /// Returns the list of child expressions (".expressions" in sqlglot).
2883    pub fn get_expressions(&self) -> &[Expression] {
2884        match self {
2885            Expression::Select(s) => &s.expressions,
2886            Expression::Function(f) => &f.args,
2887            Expression::AggregateFunction(f) => &f.args,
2888            Expression::From(f) => &f.expressions,
2889            Expression::GroupBy(g) => &g.expressions,
2890            Expression::In(i) => &i.expressions,
2891            Expression::Array(a) => &a.expressions,
2892            Expression::Tuple(t) => &t.expressions,
2893            Expression::Coalesce(f) | Expression::Greatest(f) | Expression::Least(f)
2894            | Expression::ArrayConcat(f) | Expression::ArrayIntersect(f)
2895            | Expression::ArrayZip(f) | Expression::MapConcat(f)
2896            | Expression::JsonArray(f) => &f.expressions,
2897            _ => &[],
2898        }
2899    }
2900
2901    /// Returns the name of this expression as a string slice.
2902    pub fn get_name(&self) -> &str {
2903        match self {
2904            Expression::Identifier(id) => &id.name,
2905            Expression::Column(col) => &col.name.name,
2906            Expression::Table(t) => &t.name.name,
2907            Expression::Literal(lit) => lit.value_str(),
2908            Expression::Star(_) => "*",
2909            Expression::Function(f) => &f.name,
2910            Expression::AggregateFunction(f) => &f.name,
2911            Expression::Alias(a) => a.this.get_name(),
2912            Expression::Boolean(b) => if b.value { "TRUE" } else { "FALSE" },
2913            Expression::Null(_) => "NULL",
2914            _ => "",
2915        }
2916    }
2917
2918    /// Returns the alias name if this expression has one.
2919    pub fn get_alias(&self) -> &str {
2920        match self {
2921            Expression::Alias(a) => &a.alias.name,
2922            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
2923            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
2924            _ => "",
2925        }
2926    }
2927
2928    /// Returns the output name of this expression (what it shows up as in a SELECT).
2929    pub fn get_output_name(&self) -> &str {
2930        match self {
2931            Expression::Alias(a) => &a.alias.name,
2932            Expression::Column(c) => &c.name.name,
2933            Expression::Identifier(id) => &id.name,
2934            Expression::Literal(lit) => lit.value_str(),
2935            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
2936            Expression::Star(_) => "*",
2937            _ => "",
2938        }
2939    }
2940
2941    /// Returns comments attached to this expression.
2942    pub fn get_comments(&self) -> Vec<&str> {
2943        match self {
2944            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
2945            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
2946            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
2947            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
2948            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
2949            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
2950            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
2951            Expression::And(op) | Expression::Or(op) | Expression::Add(op)
2952            | Expression::Sub(op) | Expression::Mul(op) | Expression::Div(op)
2953            | Expression::Mod(op) | Expression::Eq(op) | Expression::Neq(op)
2954            | Expression::Lt(op) | Expression::Lte(op) | Expression::Gt(op)
2955            | Expression::Gte(op) | Expression::Concat(op)
2956            | Expression::BitwiseAnd(op) | Expression::BitwiseOr(op) | Expression::BitwiseXor(op)
2957            => op.trailing_comments.iter().map(|s| s.as_str()).collect(),
2958            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
2959            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
2960            _ => Vec::new(),
2961        }
2962    }
2963}
2964
2965impl fmt::Display for Expression {
2966    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2967        // Basic display - full SQL generation is in generator module
2968        match self {
2969            Expression::Literal(lit) => write!(f, "{}", lit),
2970            Expression::Identifier(id) => write!(f, "{}", id),
2971            Expression::Column(col) => write!(f, "{}", col),
2972            Expression::Star(_) => write!(f, "*"),
2973            Expression::Null(_) => write!(f, "NULL"),
2974            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
2975            Expression::Select(_) => write!(f, "SELECT ..."),
2976            _ => write!(f, "{:?}", self),
2977        }
2978    }
2979}
2980
2981/// Represent a SQL literal value.
2982///
2983/// Numeric values are stored as their original text representation (not parsed
2984/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
2985/// preserved across round-trips.
2986///
2987/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
2988/// strings, raw strings, etc.) each have a dedicated variant so that the
2989/// generator can emit them with the correct syntax.
2990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2991#[cfg_attr(feature = "bindings", derive(TS))]
2992#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
2993pub enum Literal {
2994    /// Single-quoted string literal: `'hello'`
2995    String(String),
2996    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
2997    Number(String),
2998    /// Hex string literal: `X'FF'`
2999    HexString(String),
3000    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3001    HexNumber(String),
3002    BitString(String),
3003    /// Byte string: b"..." (BigQuery style)
3004    ByteString(String),
3005    /// National string: N'abc'
3006    NationalString(String),
3007    /// DATE literal: DATE '2024-01-15'
3008    Date(String),
3009    /// TIME literal: TIME '10:30:00'
3010    Time(String),
3011    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3012    Timestamp(String),
3013    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3014    Datetime(String),
3015    /// Triple-quoted string: """...""" or '''...'''
3016    /// Contains (content, quote_char) where quote_char is '"' or '\''
3017    TripleQuotedString(String, char),
3018    /// Escape string: E'...' (PostgreSQL)
3019    EscapeString(String),
3020    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3021    DollarString(String),
3022    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3023    /// In raw strings, backslashes are literal and not escape characters.
3024    /// When converting to a regular string, backslashes must be doubled.
3025    RawString(String),
3026}
3027
3028impl Literal {
3029    /// Returns the inner value as a string slice, regardless of literal type.
3030    pub fn value_str(&self) -> &str {
3031        match self {
3032            Literal::String(s)
3033            | Literal::Number(s)
3034            | Literal::HexString(s)
3035            | Literal::HexNumber(s)
3036            | Literal::BitString(s)
3037            | Literal::ByteString(s)
3038            | Literal::NationalString(s)
3039            | Literal::Date(s)
3040            | Literal::Time(s)
3041            | Literal::Timestamp(s)
3042            | Literal::Datetime(s)
3043            | Literal::EscapeString(s)
3044            | Literal::DollarString(s)
3045            | Literal::RawString(s) => s.as_str(),
3046            Literal::TripleQuotedString(s, _) => s.as_str(),
3047        }
3048    }
3049
3050    /// Returns `true` if this is a string-type literal.
3051    pub fn is_string(&self) -> bool {
3052        matches!(
3053            self,
3054            Literal::String(_)
3055                | Literal::NationalString(_)
3056                | Literal::EscapeString(_)
3057                | Literal::DollarString(_)
3058                | Literal::RawString(_)
3059                | Literal::TripleQuotedString(_, _)
3060        )
3061    }
3062
3063    /// Returns `true` if this is a numeric literal.
3064    pub fn is_number(&self) -> bool {
3065        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3066    }
3067}
3068
3069impl fmt::Display for Literal {
3070    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3071        match self {
3072            Literal::String(s) => write!(f, "'{}'", s),
3073            Literal::Number(n) => write!(f, "{}", n),
3074            Literal::HexString(h) => write!(f, "X'{}'", h),
3075            Literal::HexNumber(h) => write!(f, "0x{}", h),
3076            Literal::BitString(b) => write!(f, "B'{}'", b),
3077            Literal::ByteString(b) => write!(f, "b'{}'", b),
3078            Literal::NationalString(s) => write!(f, "N'{}'", s),
3079            Literal::Date(d) => write!(f, "DATE '{}'", d),
3080            Literal::Time(t) => write!(f, "TIME '{}'", t),
3081            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3082            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3083            Literal::TripleQuotedString(s, q) => {
3084                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3085            }
3086            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3087            Literal::DollarString(s) => write!(f, "$${}$$", s),
3088            Literal::RawString(s) => write!(f, "r'{}'", s),
3089        }
3090    }
3091}
3092
3093/// Boolean literal
3094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3095#[cfg_attr(feature = "bindings", derive(TS))]
3096pub struct BooleanLiteral {
3097    pub value: bool,
3098}
3099
3100/// NULL literal
3101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3102#[cfg_attr(feature = "bindings", derive(TS))]
3103pub struct Null;
3104
3105/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3106///
3107/// The `quoted` flag indicates whether the identifier was originally delimited
3108/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3109/// dialect). The generator uses this flag to decide whether to emit quoting
3110/// characters.
3111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3112#[cfg_attr(feature = "bindings", derive(TS))]
3113pub struct Identifier {
3114    /// The raw text of the identifier, without any quoting characters.
3115    pub name: String,
3116    /// Whether the identifier was quoted in the source SQL.
3117    pub quoted: bool,
3118    #[serde(default)]
3119    pub trailing_comments: Vec<String>,
3120    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3121    #[serde(default, skip_serializing_if = "Option::is_none")]
3122    pub span: Option<Span>,
3123}
3124
3125impl Identifier {
3126    pub fn new(name: impl Into<String>) -> Self {
3127        Self {
3128            name: name.into(),
3129            quoted: false,
3130            trailing_comments: Vec::new(),
3131            span: None,
3132        }
3133    }
3134
3135    pub fn quoted(name: impl Into<String>) -> Self {
3136        Self {
3137            name: name.into(),
3138            quoted: true,
3139            trailing_comments: Vec::new(),
3140            span: None,
3141        }
3142    }
3143
3144    pub fn empty() -> Self {
3145        Self {
3146            name: String::new(),
3147            quoted: false,
3148            trailing_comments: Vec::new(),
3149            span: None,
3150        }
3151    }
3152
3153    pub fn is_empty(&self) -> bool {
3154        self.name.is_empty()
3155    }
3156
3157    /// Set the source span on this identifier
3158    pub fn with_span(mut self, span: Span) -> Self {
3159        self.span = Some(span);
3160        self
3161    }
3162}
3163
3164impl fmt::Display for Identifier {
3165    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3166        if self.quoted {
3167            write!(f, "\"{}\"", self.name)
3168        } else {
3169            write!(f, "{}", self.name)
3170        }
3171    }
3172}
3173
3174/// Represent a column reference, optionally qualified by a table name.
3175///
3176/// Renders as `name` when unqualified, or `table.name` when qualified.
3177/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3178/// convenient construction.
3179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3180#[cfg_attr(feature = "bindings", derive(TS))]
3181pub struct Column {
3182    /// The column name.
3183    pub name: Identifier,
3184    /// Optional table qualifier (e.g. `t` in `t.col`).
3185    pub table: Option<Identifier>,
3186    /// Oracle-style join marker (+) for outer joins
3187    #[serde(default)]
3188    pub join_mark: bool,
3189    /// Trailing comments that appeared after this column reference
3190    #[serde(default)]
3191    pub trailing_comments: Vec<String>,
3192    /// Source position span
3193    #[serde(default, skip_serializing_if = "Option::is_none")]
3194    pub span: Option<Span>,
3195    /// Inferred data type from type annotation
3196    #[serde(default, skip_serializing_if = "Option::is_none")]
3197    pub inferred_type: Option<DataType>,
3198}
3199
3200impl fmt::Display for Column {
3201    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3202        if let Some(table) = &self.table {
3203            write!(f, "{}.{}", table, self.name)
3204        } else {
3205            write!(f, "{}", self.name)
3206        }
3207    }
3208}
3209
3210/// Represent a table reference with optional schema and catalog qualifiers.
3211///
3212/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3213/// which qualifiers are present. Supports aliases, column alias lists,
3214/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3215/// several other dialect-specific extensions.
3216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3217#[cfg_attr(feature = "bindings", derive(TS))]
3218pub struct TableRef {
3219    /// The unqualified table name.
3220    pub name: Identifier,
3221    /// Optional schema qualifier (e.g. `public` in `public.users`).
3222    pub schema: Option<Identifier>,
3223    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3224    pub catalog: Option<Identifier>,
3225    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3226    pub alias: Option<Identifier>,
3227    /// Whether AS keyword was explicitly used for the alias
3228    #[serde(default)]
3229    pub alias_explicit_as: bool,
3230    /// Column aliases for table alias: AS t(c1, c2)
3231    #[serde(default)]
3232    pub column_aliases: Vec<Identifier>,
3233    /// Trailing comments that appeared after this table reference
3234    #[serde(default)]
3235    pub trailing_comments: Vec<String>,
3236    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3237    #[serde(default)]
3238    pub when: Option<Box<HistoricalData>>,
3239    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3240    #[serde(default)]
3241    pub only: bool,
3242    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3243    #[serde(default)]
3244    pub final_: bool,
3245    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3246    #[serde(default, skip_serializing_if = "Option::is_none")]
3247    pub table_sample: Option<Box<Sample>>,
3248    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3249    #[serde(default)]
3250    pub hints: Vec<Expression>,
3251    /// TSQL: FOR SYSTEM_TIME temporal clause
3252    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3253    #[serde(default, skip_serializing_if = "Option::is_none")]
3254    pub system_time: Option<String>,
3255    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3256    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3257    pub partitions: Vec<Identifier>,
3258    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3259    /// When set, this is used instead of the name field
3260    #[serde(default, skip_serializing_if = "Option::is_none")]
3261    pub identifier_func: Option<Box<Expression>>,
3262    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3263    #[serde(default, skip_serializing_if = "Option::is_none")]
3264    pub changes: Option<Box<Changes>>,
3265    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3266    #[serde(default, skip_serializing_if = "Option::is_none")]
3267    pub version: Option<Box<Version>>,
3268    /// Source position span
3269    #[serde(default, skip_serializing_if = "Option::is_none")]
3270    pub span: Option<Span>,
3271}
3272
3273impl TableRef {
3274    pub fn new(name: impl Into<String>) -> Self {
3275        Self {
3276            name: Identifier::new(name),
3277            schema: None,
3278            catalog: None,
3279            alias: None,
3280            alias_explicit_as: false,
3281            column_aliases: Vec::new(),
3282            trailing_comments: Vec::new(),
3283            when: None,
3284            only: false,
3285            final_: false,
3286            table_sample: None,
3287            hints: Vec::new(),
3288            system_time: None,
3289            partitions: Vec::new(),
3290            identifier_func: None,
3291            changes: None,
3292            version: None,
3293            span: None,
3294        }
3295    }
3296
3297    /// Create with a schema qualifier.
3298    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3299        let mut t = Self::new(name);
3300        t.schema = Some(Identifier::new(schema));
3301        t
3302    }
3303
3304    /// Create with catalog and schema qualifiers.
3305    pub fn new_with_catalog(
3306        name: impl Into<String>,
3307        schema: impl Into<String>,
3308        catalog: impl Into<String>,
3309    ) -> Self {
3310        let mut t = Self::new(name);
3311        t.schema = Some(Identifier::new(schema));
3312        t.catalog = Some(Identifier::new(catalog));
3313        t
3314    }
3315
3316    /// Create from an Identifier, preserving the quoted flag
3317    pub fn from_identifier(name: Identifier) -> Self {
3318        Self {
3319            name,
3320            schema: None,
3321            catalog: None,
3322            alias: None,
3323            alias_explicit_as: false,
3324            column_aliases: Vec::new(),
3325            trailing_comments: Vec::new(),
3326            when: None,
3327            only: false,
3328            final_: false,
3329            table_sample: None,
3330            hints: Vec::new(),
3331            system_time: None,
3332            partitions: Vec::new(),
3333            identifier_func: None,
3334            changes: None,
3335            version: None,
3336            span: None,
3337        }
3338    }
3339
3340    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3341        self.alias = Some(Identifier::new(alias));
3342        self
3343    }
3344
3345    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3346        self.schema = Some(Identifier::new(schema));
3347        self
3348    }
3349}
3350
3351/// Represent a wildcard star expression (`*`, `table.*`).
3352///
3353/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3354/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3356#[cfg_attr(feature = "bindings", derive(TS))]
3357pub struct Star {
3358    /// Optional table qualifier (e.g. `t` in `t.*`).
3359    pub table: Option<Identifier>,
3360    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3361    pub except: Option<Vec<Identifier>>,
3362    /// REPLACE expressions (BigQuery, Snowflake)
3363    pub replace: Option<Vec<Alias>>,
3364    /// RENAME columns (Snowflake)
3365    pub rename: Option<Vec<(Identifier, Identifier)>>,
3366    /// Trailing comments that appeared after the star
3367    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3368    pub trailing_comments: Vec<String>,
3369    /// Source position span
3370    #[serde(default, skip_serializing_if = "Option::is_none")]
3371    pub span: Option<Span>,
3372}
3373
3374/// Represent a complete SELECT statement.
3375///
3376/// This is the most feature-rich AST node, covering the full surface area of
3377/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3378/// `Vec` are omitted from the generated SQL when absent.
3379///
3380/// # Key Fields
3381///
3382/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3383/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3384/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3385/// - `where_clause` -- the WHERE predicate.
3386/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3387/// - `having` -- HAVING predicate.
3388/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3389/// - `limit` / `offset` / `fetch` -- result set limiting.
3390/// - `with` -- Common Table Expressions (CTEs).
3391/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3392/// - `windows` -- named window definitions (WINDOW w AS ...).
3393///
3394/// Dialect-specific extensions are supported via fields like `prewhere`
3395/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3396/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3398#[cfg_attr(feature = "bindings", derive(TS))]
3399pub struct Select {
3400    /// The select-list: columns, expressions, aliases, and wildcards.
3401    pub expressions: Vec<Expression>,
3402    /// The FROM clause, containing one or more table sources.
3403    pub from: Option<From>,
3404    /// JOIN clauses applied after the FROM source.
3405    pub joins: Vec<Join>,
3406    pub lateral_views: Vec<LateralView>,
3407    /// ClickHouse PREWHERE clause
3408    #[serde(default, skip_serializing_if = "Option::is_none")]
3409    pub prewhere: Option<Expression>,
3410    pub where_clause: Option<Where>,
3411    pub group_by: Option<GroupBy>,
3412    pub having: Option<Having>,
3413    pub qualify: Option<Qualify>,
3414    pub order_by: Option<OrderBy>,
3415    pub distribute_by: Option<DistributeBy>,
3416    pub cluster_by: Option<ClusterBy>,
3417    pub sort_by: Option<SortBy>,
3418    pub limit: Option<Limit>,
3419    pub offset: Option<Offset>,
3420    /// ClickHouse LIMIT BY clause expressions
3421    #[serde(default, skip_serializing_if = "Option::is_none")]
3422    pub limit_by: Option<Vec<Expression>>,
3423    pub fetch: Option<Fetch>,
3424    pub distinct: bool,
3425    pub distinct_on: Option<Vec<Expression>>,
3426    pub top: Option<Top>,
3427    pub with: Option<With>,
3428    pub sample: Option<Sample>,
3429    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3430    #[serde(default, skip_serializing_if = "Option::is_none")]
3431    pub settings: Option<Vec<Expression>>,
3432    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3433    #[serde(default, skip_serializing_if = "Option::is_none")]
3434    pub format: Option<Expression>,
3435    pub windows: Option<Vec<NamedWindow>>,
3436    pub hint: Option<Hint>,
3437    /// Oracle CONNECT BY clause for hierarchical queries
3438    pub connect: Option<Connect>,
3439    /// SELECT ... INTO table_name for creating tables
3440    pub into: Option<SelectInto>,
3441    /// FOR UPDATE/SHARE locking clauses
3442    #[serde(default)]
3443    pub locks: Vec<Lock>,
3444    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3445    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3446    pub for_xml: Vec<Expression>,
3447    /// Leading comments before the statement
3448    #[serde(default)]
3449    pub leading_comments: Vec<String>,
3450    /// Comments that appear after SELECT keyword (before expressions)
3451    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3452    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3453    pub post_select_comments: Vec<String>,
3454    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3455    #[serde(default, skip_serializing_if = "Option::is_none")]
3456    pub kind: Option<String>,
3457    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3458    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3459    pub operation_modifiers: Vec<String>,
3460    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3461    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3462    pub qualify_after_window: bool,
3463    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3464    #[serde(default, skip_serializing_if = "Option::is_none")]
3465    pub option: Option<String>,
3466    /// Redshift-style EXCLUDE clause at the end of the projection list
3467    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3468    #[serde(default, skip_serializing_if = "Option::is_none")]
3469    pub exclude: Option<Vec<Expression>>,
3470}
3471
3472impl Select {
3473    pub fn new() -> Self {
3474        Self {
3475            expressions: Vec::new(),
3476            from: None,
3477            joins: Vec::new(),
3478            lateral_views: Vec::new(),
3479            prewhere: None,
3480            where_clause: None,
3481            group_by: None,
3482            having: None,
3483            qualify: None,
3484            order_by: None,
3485            distribute_by: None,
3486            cluster_by: None,
3487            sort_by: None,
3488            limit: None,
3489            offset: None,
3490            limit_by: None,
3491            fetch: None,
3492            distinct: false,
3493            distinct_on: None,
3494            top: None,
3495            with: None,
3496            sample: None,
3497            settings: None,
3498            format: None,
3499            windows: None,
3500            hint: None,
3501            connect: None,
3502            into: None,
3503            locks: Vec::new(),
3504            for_xml: Vec::new(),
3505            leading_comments: Vec::new(),
3506            post_select_comments: Vec::new(),
3507            kind: None,
3508            operation_modifiers: Vec::new(),
3509            qualify_after_window: false,
3510            option: None,
3511            exclude: None,
3512        }
3513    }
3514
3515    /// Add a column to select
3516    pub fn column(mut self, expr: Expression) -> Self {
3517        self.expressions.push(expr);
3518        self
3519    }
3520
3521    /// Set the FROM clause
3522    pub fn from(mut self, table: Expression) -> Self {
3523        self.from = Some(From {
3524            expressions: vec![table],
3525        });
3526        self
3527    }
3528
3529    /// Add a WHERE clause
3530    pub fn where_(mut self, condition: Expression) -> Self {
3531        self.where_clause = Some(Where { this: condition });
3532        self
3533    }
3534
3535    /// Set DISTINCT
3536    pub fn distinct(mut self) -> Self {
3537        self.distinct = true;
3538        self
3539    }
3540
3541    /// Add a JOIN
3542    pub fn join(mut self, join: Join) -> Self {
3543        self.joins.push(join);
3544        self
3545    }
3546
3547    /// Set ORDER BY
3548    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3549        self.order_by = Some(OrderBy {
3550            expressions,
3551            siblings: false,
3552            comments: Vec::new(),
3553        });
3554        self
3555    }
3556
3557    /// Set LIMIT
3558    pub fn limit(mut self, n: Expression) -> Self {
3559        self.limit = Some(Limit {
3560            this: n,
3561            percent: false,
3562            comments: Vec::new(),
3563        });
3564        self
3565    }
3566
3567    /// Set OFFSET
3568    pub fn offset(mut self, n: Expression) -> Self {
3569        self.offset = Some(Offset {
3570            this: n,
3571            rows: None,
3572        });
3573        self
3574    }
3575}
3576
3577impl Default for Select {
3578    fn default() -> Self {
3579        Self::new()
3580    }
3581}
3582
3583/// Represent a UNION set operation between two query expressions.
3584///
3585/// When `all` is true, duplicate rows are preserved (UNION ALL).
3586/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3587/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3589#[cfg_attr(feature = "bindings", derive(TS))]
3590pub struct Union {
3591    /// The left-hand query operand.
3592    pub left: Expression,
3593    /// The right-hand query operand.
3594    pub right: Expression,
3595    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3596    pub all: bool,
3597    /// Whether DISTINCT was explicitly specified
3598    #[serde(default)]
3599    pub distinct: bool,
3600    /// Optional WITH clause
3601    pub with: Option<With>,
3602    /// ORDER BY applied to entire UNION result
3603    pub order_by: Option<OrderBy>,
3604    /// LIMIT applied to entire UNION result
3605    pub limit: Option<Box<Expression>>,
3606    /// OFFSET applied to entire UNION result
3607    pub offset: Option<Box<Expression>>,
3608    /// DISTRIBUTE BY clause (Hive/Spark)
3609    #[serde(default, skip_serializing_if = "Option::is_none")]
3610    pub distribute_by: Option<DistributeBy>,
3611    /// SORT BY clause (Hive/Spark)
3612    #[serde(default, skip_serializing_if = "Option::is_none")]
3613    pub sort_by: Option<SortBy>,
3614    /// CLUSTER BY clause (Hive/Spark)
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub cluster_by: Option<ClusterBy>,
3617    /// DuckDB BY NAME modifier
3618    #[serde(default)]
3619    pub by_name: bool,
3620    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3621    #[serde(default, skip_serializing_if = "Option::is_none")]
3622    pub side: Option<String>,
3623    /// BigQuery: Set operation kind (INNER)
3624    #[serde(default, skip_serializing_if = "Option::is_none")]
3625    pub kind: Option<String>,
3626    /// BigQuery: CORRESPONDING modifier
3627    #[serde(default)]
3628    pub corresponding: bool,
3629    /// BigQuery: STRICT modifier (before CORRESPONDING)
3630    #[serde(default)]
3631    pub strict: bool,
3632    /// BigQuery: BY (columns) after CORRESPONDING
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub on_columns: Vec<Expression>,
3635}
3636
3637/// Represent an INTERSECT set operation between two query expressions.
3638///
3639/// Returns only rows that appear in both operands. When `all` is true,
3640/// duplicates are preserved according to their multiplicity.
3641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3642#[cfg_attr(feature = "bindings", derive(TS))]
3643pub struct Intersect {
3644    /// The left-hand query operand.
3645    pub left: Expression,
3646    /// The right-hand query operand.
3647    pub right: Expression,
3648    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3649    pub all: bool,
3650    /// Whether DISTINCT was explicitly specified
3651    #[serde(default)]
3652    pub distinct: bool,
3653    /// Optional WITH clause
3654    pub with: Option<With>,
3655    /// ORDER BY applied to entire INTERSECT result
3656    pub order_by: Option<OrderBy>,
3657    /// LIMIT applied to entire INTERSECT result
3658    pub limit: Option<Box<Expression>>,
3659    /// OFFSET applied to entire INTERSECT result
3660    pub offset: Option<Box<Expression>>,
3661    /// DISTRIBUTE BY clause (Hive/Spark)
3662    #[serde(default, skip_serializing_if = "Option::is_none")]
3663    pub distribute_by: Option<DistributeBy>,
3664    /// SORT BY clause (Hive/Spark)
3665    #[serde(default, skip_serializing_if = "Option::is_none")]
3666    pub sort_by: Option<SortBy>,
3667    /// CLUSTER BY clause (Hive/Spark)
3668    #[serde(default, skip_serializing_if = "Option::is_none")]
3669    pub cluster_by: Option<ClusterBy>,
3670    /// DuckDB BY NAME modifier
3671    #[serde(default)]
3672    pub by_name: bool,
3673    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3674    #[serde(default, skip_serializing_if = "Option::is_none")]
3675    pub side: Option<String>,
3676    /// BigQuery: Set operation kind (INNER)
3677    #[serde(default, skip_serializing_if = "Option::is_none")]
3678    pub kind: Option<String>,
3679    /// BigQuery: CORRESPONDING modifier
3680    #[serde(default)]
3681    pub corresponding: bool,
3682    /// BigQuery: STRICT modifier (before CORRESPONDING)
3683    #[serde(default)]
3684    pub strict: bool,
3685    /// BigQuery: BY (columns) after CORRESPONDING
3686    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3687    pub on_columns: Vec<Expression>,
3688}
3689
3690/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3691///
3692/// Returns rows from the left operand that do not appear in the right operand.
3693/// When `all` is true, duplicates are subtracted according to their multiplicity.
3694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3695#[cfg_attr(feature = "bindings", derive(TS))]
3696pub struct Except {
3697    /// The left-hand query operand.
3698    pub left: Expression,
3699    /// The right-hand query operand (rows to subtract).
3700    pub right: Expression,
3701    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3702    pub all: bool,
3703    /// Whether DISTINCT was explicitly specified
3704    #[serde(default)]
3705    pub distinct: bool,
3706    /// Optional WITH clause
3707    pub with: Option<With>,
3708    /// ORDER BY applied to entire EXCEPT result
3709    pub order_by: Option<OrderBy>,
3710    /// LIMIT applied to entire EXCEPT result
3711    pub limit: Option<Box<Expression>>,
3712    /// OFFSET applied to entire EXCEPT result
3713    pub offset: Option<Box<Expression>>,
3714    /// DISTRIBUTE BY clause (Hive/Spark)
3715    #[serde(default, skip_serializing_if = "Option::is_none")]
3716    pub distribute_by: Option<DistributeBy>,
3717    /// SORT BY clause (Hive/Spark)
3718    #[serde(default, skip_serializing_if = "Option::is_none")]
3719    pub sort_by: Option<SortBy>,
3720    /// CLUSTER BY clause (Hive/Spark)
3721    #[serde(default, skip_serializing_if = "Option::is_none")]
3722    pub cluster_by: Option<ClusterBy>,
3723    /// DuckDB BY NAME modifier
3724    #[serde(default)]
3725    pub by_name: bool,
3726    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3727    #[serde(default, skip_serializing_if = "Option::is_none")]
3728    pub side: Option<String>,
3729    /// BigQuery: Set operation kind (INNER)
3730    #[serde(default, skip_serializing_if = "Option::is_none")]
3731    pub kind: Option<String>,
3732    /// BigQuery: CORRESPONDING modifier
3733    #[serde(default)]
3734    pub corresponding: bool,
3735    /// BigQuery: STRICT modifier (before CORRESPONDING)
3736    #[serde(default)]
3737    pub strict: bool,
3738    /// BigQuery: BY (columns) after CORRESPONDING
3739    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3740    pub on_columns: Vec<Expression>,
3741}
3742
3743/// INTO clause for SELECT INTO statements
3744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3745#[cfg_attr(feature = "bindings", derive(TS))]
3746pub struct SelectInto {
3747    /// Target table or variable (used when single target)
3748    pub this: Expression,
3749    /// Whether TEMPORARY keyword was used
3750    #[serde(default)]
3751    pub temporary: bool,
3752    /// Whether UNLOGGED keyword was used (PostgreSQL)
3753    #[serde(default)]
3754    pub unlogged: bool,
3755    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3756    #[serde(default)]
3757    pub bulk_collect: bool,
3758    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3759    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3760    pub expressions: Vec<Expression>,
3761}
3762
3763/// Represent a parenthesized subquery expression.
3764///
3765/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3766/// parentheses and optionally applies an alias, column aliases, ORDER BY,
3767/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
3768/// modifiers are rendered inside or outside the parentheses.
3769///
3770/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
3771/// scalar subqueries in select-lists, and derived tables.
3772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3773#[cfg_attr(feature = "bindings", derive(TS))]
3774pub struct Subquery {
3775    /// The inner query expression.
3776    pub this: Expression,
3777    /// Optional alias for the derived table.
3778    pub alias: Option<Identifier>,
3779    /// Optional column aliases: AS t(c1, c2)
3780    pub column_aliases: Vec<Identifier>,
3781    /// ORDER BY clause (for parenthesized queries)
3782    pub order_by: Option<OrderBy>,
3783    /// LIMIT clause
3784    pub limit: Option<Limit>,
3785    /// OFFSET clause
3786    pub offset: Option<Offset>,
3787    /// DISTRIBUTE BY clause (Hive/Spark)
3788    #[serde(default, skip_serializing_if = "Option::is_none")]
3789    pub distribute_by: Option<DistributeBy>,
3790    /// SORT BY clause (Hive/Spark)
3791    #[serde(default, skip_serializing_if = "Option::is_none")]
3792    pub sort_by: Option<SortBy>,
3793    /// CLUSTER BY clause (Hive/Spark)
3794    #[serde(default, skip_serializing_if = "Option::is_none")]
3795    pub cluster_by: Option<ClusterBy>,
3796    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
3797    #[serde(default)]
3798    pub lateral: bool,
3799    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
3800    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
3801    /// false: (SELECT 1) LIMIT 1 - modifiers outside
3802    #[serde(default)]
3803    pub modifiers_inside: bool,
3804    /// Trailing comments after the closing paren
3805    #[serde(default)]
3806    pub trailing_comments: Vec<String>,
3807    /// Inferred data type from type annotation
3808    #[serde(default, skip_serializing_if = "Option::is_none")]
3809    pub inferred_type: Option<DataType>,
3810}
3811
3812/// Pipe operator expression: query |> transform
3813///
3814/// Used in DataFusion and BigQuery pipe syntax:
3815///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
3816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3817#[cfg_attr(feature = "bindings", derive(TS))]
3818pub struct PipeOperator {
3819    /// The input query/expression (left side of |>)
3820    pub this: Expression,
3821    /// The piped operation (right side of |>)
3822    pub expression: Expression,
3823}
3824
3825/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
3826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3827#[cfg_attr(feature = "bindings", derive(TS))]
3828pub struct Values {
3829    /// The rows of values
3830    pub expressions: Vec<Tuple>,
3831    /// Optional alias for the table
3832    pub alias: Option<Identifier>,
3833    /// Optional column aliases: AS t(c1, c2)
3834    pub column_aliases: Vec<Identifier>,
3835}
3836
3837/// PIVOT operation - supports both standard and DuckDB simplified syntax
3838///
3839/// Standard syntax (in FROM clause):
3840///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
3841///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
3842///
3843/// DuckDB simplified syntax (statement-level):
3844///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
3845///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
3846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3847#[cfg_attr(feature = "bindings", derive(TS))]
3848pub struct Pivot {
3849    /// Source table/expression
3850    pub this: Expression,
3851    /// For standard PIVOT: the aggregation function(s) (first is primary)
3852    /// For DuckDB simplified: unused (use `using` instead)
3853    #[serde(default)]
3854    pub expressions: Vec<Expression>,
3855    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
3856    #[serde(default)]
3857    pub fields: Vec<Expression>,
3858    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
3859    #[serde(default)]
3860    pub using: Vec<Expression>,
3861    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
3862    #[serde(default)]
3863    pub group: Option<Box<Expression>>,
3864    /// Whether this is an UNPIVOT (vs PIVOT)
3865    #[serde(default)]
3866    pub unpivot: bool,
3867    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
3868    #[serde(default)]
3869    pub into: Option<Box<Expression>>,
3870    /// Optional alias
3871    #[serde(default)]
3872    pub alias: Option<Identifier>,
3873    /// Include/exclude nulls (for UNPIVOT)
3874    #[serde(default)]
3875    pub include_nulls: Option<bool>,
3876    /// Default on null value (Snowflake)
3877    #[serde(default)]
3878    pub default_on_null: Option<Box<Expression>>,
3879    /// WITH clause (CTEs)
3880    #[serde(default, skip_serializing_if = "Option::is_none")]
3881    pub with: Option<With>,
3882}
3883
3884/// UNPIVOT operation
3885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3886#[cfg_attr(feature = "bindings", derive(TS))]
3887pub struct Unpivot {
3888    pub this: Expression,
3889    pub value_column: Identifier,
3890    pub name_column: Identifier,
3891    pub columns: Vec<Expression>,
3892    pub alias: Option<Identifier>,
3893    /// Whether the value_column was parenthesized in the original SQL
3894    #[serde(default)]
3895    pub value_column_parenthesized: bool,
3896    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
3897    #[serde(default)]
3898    pub include_nulls: Option<bool>,
3899    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
3900    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3901    pub extra_value_columns: Vec<Identifier>,
3902}
3903
3904/// PIVOT alias for aliasing pivot expressions
3905/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
3906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3907#[cfg_attr(feature = "bindings", derive(TS))]
3908pub struct PivotAlias {
3909    pub this: Expression,
3910    pub alias: Expression,
3911}
3912
3913/// PREWHERE clause (ClickHouse) - early filtering before WHERE
3914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3915#[cfg_attr(feature = "bindings", derive(TS))]
3916pub struct PreWhere {
3917    pub this: Expression,
3918}
3919
3920/// STREAM definition (Snowflake) - for change data capture
3921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3922#[cfg_attr(feature = "bindings", derive(TS))]
3923pub struct Stream {
3924    pub this: Expression,
3925    #[serde(skip_serializing_if = "Option::is_none")]
3926    pub on: Option<Expression>,
3927    #[serde(skip_serializing_if = "Option::is_none")]
3928    pub show_initial_rows: Option<bool>,
3929}
3930
3931/// USING DATA clause for data import statements
3932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3933#[cfg_attr(feature = "bindings", derive(TS))]
3934pub struct UsingData {
3935    pub this: Expression,
3936}
3937
3938/// XML Namespace declaration
3939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3940#[cfg_attr(feature = "bindings", derive(TS))]
3941pub struct XmlNamespace {
3942    pub this: Expression,
3943    #[serde(skip_serializing_if = "Option::is_none")]
3944    pub alias: Option<Identifier>,
3945}
3946
3947/// ROW FORMAT clause for Hive/Spark
3948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3949#[cfg_attr(feature = "bindings", derive(TS))]
3950pub struct RowFormat {
3951    pub delimited: bool,
3952    pub fields_terminated_by: Option<String>,
3953    pub collection_items_terminated_by: Option<String>,
3954    pub map_keys_terminated_by: Option<String>,
3955    pub lines_terminated_by: Option<String>,
3956    pub null_defined_as: Option<String>,
3957}
3958
3959/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
3960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3961#[cfg_attr(feature = "bindings", derive(TS))]
3962pub struct DirectoryInsert {
3963    pub local: bool,
3964    pub path: String,
3965    pub row_format: Option<RowFormat>,
3966    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
3967    #[serde(default)]
3968    pub stored_as: Option<String>,
3969}
3970
3971/// INSERT statement
3972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3973#[cfg_attr(feature = "bindings", derive(TS))]
3974pub struct Insert {
3975    pub table: TableRef,
3976    pub columns: Vec<Identifier>,
3977    pub values: Vec<Vec<Expression>>,
3978    pub query: Option<Expression>,
3979    /// INSERT OVERWRITE for Hive/Spark
3980    pub overwrite: bool,
3981    /// PARTITION clause for Hive/Spark
3982    pub partition: Vec<(Identifier, Option<Expression>)>,
3983    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
3984    #[serde(default)]
3985    pub directory: Option<DirectoryInsert>,
3986    /// RETURNING clause (PostgreSQL, SQLite)
3987    #[serde(default)]
3988    pub returning: Vec<Expression>,
3989    /// OUTPUT clause (TSQL)
3990    #[serde(default)]
3991    pub output: Option<OutputClause>,
3992    /// ON CONFLICT clause (PostgreSQL, SQLite)
3993    #[serde(default)]
3994    pub on_conflict: Option<Box<Expression>>,
3995    /// Leading comments before the statement
3996    #[serde(default)]
3997    pub leading_comments: Vec<String>,
3998    /// IF EXISTS clause (Hive)
3999    #[serde(default)]
4000    pub if_exists: bool,
4001    /// WITH clause (CTEs)
4002    #[serde(default)]
4003    pub with: Option<With>,
4004    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4005    #[serde(default)]
4006    pub ignore: bool,
4007    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4008    #[serde(default)]
4009    pub source_alias: Option<Identifier>,
4010    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4011    #[serde(default)]
4012    pub alias: Option<Identifier>,
4013    /// Whether the alias uses explicit AS keyword
4014    #[serde(default)]
4015    pub alias_explicit_as: bool,
4016    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4017    #[serde(default)]
4018    pub default_values: bool,
4019    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4020    #[serde(default)]
4021    pub by_name: bool,
4022    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4023    #[serde(default, skip_serializing_if = "Option::is_none")]
4024    pub conflict_action: Option<String>,
4025    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4026    #[serde(default)]
4027    pub is_replace: bool,
4028    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4029    #[serde(default, skip_serializing_if = "Option::is_none")]
4030    pub hint: Option<Hint>,
4031    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4032    #[serde(default)]
4033    pub replace_where: Option<Box<Expression>>,
4034    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4035    #[serde(default)]
4036    pub source: Option<Box<Expression>>,
4037    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4038    #[serde(default, skip_serializing_if = "Option::is_none")]
4039    pub function_target: Option<Box<Expression>>,
4040    /// ClickHouse: PARTITION BY expr
4041    #[serde(default, skip_serializing_if = "Option::is_none")]
4042    pub partition_by: Option<Box<Expression>>,
4043    /// ClickHouse: SETTINGS key = val, ...
4044    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4045    pub settings: Vec<Expression>,
4046}
4047
4048/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4050#[cfg_attr(feature = "bindings", derive(TS))]
4051pub struct OutputClause {
4052    /// Columns/expressions to output
4053    pub columns: Vec<Expression>,
4054    /// Optional INTO target table or table variable
4055    #[serde(default)]
4056    pub into_table: Option<Expression>,
4057}
4058
4059/// UPDATE statement
4060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4061#[cfg_attr(feature = "bindings", derive(TS))]
4062pub struct Update {
4063    pub table: TableRef,
4064    /// Additional tables for multi-table UPDATE (MySQL syntax)
4065    #[serde(default)]
4066    pub extra_tables: Vec<TableRef>,
4067    /// JOINs attached to the table list (MySQL multi-table syntax)
4068    #[serde(default)]
4069    pub table_joins: Vec<Join>,
4070    pub set: Vec<(Identifier, Expression)>,
4071    pub from_clause: Option<From>,
4072    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4073    #[serde(default)]
4074    pub from_joins: Vec<Join>,
4075    pub where_clause: Option<Where>,
4076    /// RETURNING clause (PostgreSQL, SQLite)
4077    #[serde(default)]
4078    pub returning: Vec<Expression>,
4079    /// OUTPUT clause (TSQL)
4080    #[serde(default)]
4081    pub output: Option<OutputClause>,
4082    /// WITH clause (CTEs)
4083    #[serde(default)]
4084    pub with: Option<With>,
4085    /// Leading comments before the statement
4086    #[serde(default)]
4087    pub leading_comments: Vec<String>,
4088    /// LIMIT clause (MySQL)
4089    #[serde(default)]
4090    pub limit: Option<Expression>,
4091    /// ORDER BY clause (MySQL)
4092    #[serde(default)]
4093    pub order_by: Option<OrderBy>,
4094    /// Whether FROM clause appears before SET (Snowflake syntax)
4095    #[serde(default)]
4096    pub from_before_set: bool,
4097}
4098
4099/// DELETE statement
4100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4101#[cfg_attr(feature = "bindings", derive(TS))]
4102pub struct Delete {
4103    pub table: TableRef,
4104    /// ClickHouse: ON CLUSTER clause for distributed DDL
4105    #[serde(default, skip_serializing_if = "Option::is_none")]
4106    pub on_cluster: Option<OnCluster>,
4107    /// Optional alias for the table
4108    pub alias: Option<Identifier>,
4109    /// Whether the alias was declared with explicit AS keyword
4110    #[serde(default)]
4111    pub alias_explicit_as: bool,
4112    /// PostgreSQL/DuckDB USING clause - additional tables to join
4113    pub using: Vec<TableRef>,
4114    pub where_clause: Option<Where>,
4115    /// OUTPUT clause (TSQL)
4116    #[serde(default)]
4117    pub output: Option<OutputClause>,
4118    /// Leading comments before the statement
4119    #[serde(default)]
4120    pub leading_comments: Vec<String>,
4121    /// WITH clause (CTEs)
4122    #[serde(default)]
4123    pub with: Option<With>,
4124    /// LIMIT clause (MySQL)
4125    #[serde(default)]
4126    pub limit: Option<Expression>,
4127    /// ORDER BY clause (MySQL)
4128    #[serde(default)]
4129    pub order_by: Option<OrderBy>,
4130    /// RETURNING clause (PostgreSQL)
4131    #[serde(default)]
4132    pub returning: Vec<Expression>,
4133    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4134    /// These are the target tables to delete from
4135    #[serde(default)]
4136    pub tables: Vec<TableRef>,
4137    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4138    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4139    #[serde(default)]
4140    pub tables_from_using: bool,
4141    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4142    #[serde(default)]
4143    pub joins: Vec<Join>,
4144    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4145    #[serde(default)]
4146    pub force_index: Option<String>,
4147    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4148    #[serde(default)]
4149    pub no_from: bool,
4150}
4151
4152/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4154#[cfg_attr(feature = "bindings", derive(TS))]
4155pub struct CopyStmt {
4156    /// Target table or query
4157    pub this: Expression,
4158    /// True for FROM (loading into table), false for TO (exporting)
4159    pub kind: bool,
4160    /// Source/destination file(s) or stage
4161    pub files: Vec<Expression>,
4162    /// Copy parameters
4163    #[serde(default)]
4164    pub params: Vec<CopyParameter>,
4165    /// Credentials for external access
4166    #[serde(default)]
4167    pub credentials: Option<Box<Credentials>>,
4168    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4169    #[serde(default)]
4170    pub is_into: bool,
4171    /// Whether parameters are wrapped in WITH (...) syntax
4172    #[serde(default)]
4173    pub with_wrapped: bool,
4174}
4175
4176/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4178#[cfg_attr(feature = "bindings", derive(TS))]
4179pub struct CopyParameter {
4180    pub name: String,
4181    pub value: Option<Expression>,
4182    pub values: Vec<Expression>,
4183    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4184    #[serde(default)]
4185    pub eq: bool,
4186}
4187
4188/// Credentials for external access (S3, Azure, etc.)
4189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4190#[cfg_attr(feature = "bindings", derive(TS))]
4191pub struct Credentials {
4192    pub credentials: Vec<(String, String)>,
4193    pub encryption: Option<String>,
4194    pub storage: Option<String>,
4195}
4196
4197/// PUT statement (Snowflake)
4198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4199#[cfg_attr(feature = "bindings", derive(TS))]
4200pub struct PutStmt {
4201    /// Source file path
4202    pub source: String,
4203    /// Whether source was quoted in the original SQL
4204    #[serde(default)]
4205    pub source_quoted: bool,
4206    /// Target stage
4207    pub target: Expression,
4208    /// PUT parameters
4209    #[serde(default)]
4210    pub params: Vec<CopyParameter>,
4211}
4212
4213/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4215#[cfg_attr(feature = "bindings", derive(TS))]
4216pub struct StageReference {
4217    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4218    pub name: String,
4219    /// Optional path within the stage (e.g., "/path/to/file.csv")
4220    #[serde(default)]
4221    pub path: Option<String>,
4222    /// Optional FILE_FORMAT parameter
4223    #[serde(default)]
4224    pub file_format: Option<Expression>,
4225    /// Optional PATTERN parameter
4226    #[serde(default)]
4227    pub pattern: Option<String>,
4228    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4229    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4230    pub quoted: bool,
4231}
4232
4233/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4235#[cfg_attr(feature = "bindings", derive(TS))]
4236pub struct HistoricalData {
4237    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4238    pub this: Box<Expression>,
4239    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4240    pub kind: String,
4241    /// The expression value (e.g., the statement ID or timestamp)
4242    pub expression: Box<Expression>,
4243}
4244
4245/// Represent an aliased expression (`expr AS name`).
4246///
4247/// Used for column aliases in select-lists, table aliases on subqueries,
4248/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4250#[cfg_attr(feature = "bindings", derive(TS))]
4251pub struct Alias {
4252    /// The expression being aliased.
4253    pub this: Expression,
4254    /// The alias name (required for simple aliases, optional when only column aliases provided)
4255    pub alias: Identifier,
4256    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4257    #[serde(default)]
4258    pub column_aliases: Vec<Identifier>,
4259    /// Comments that appeared between the expression and AS keyword
4260    #[serde(default)]
4261    pub pre_alias_comments: Vec<String>,
4262    /// Trailing comments that appeared after the alias
4263    #[serde(default)]
4264    pub trailing_comments: Vec<String>,
4265    /// Inferred data type from type annotation
4266    #[serde(default, skip_serializing_if = "Option::is_none")]
4267    pub inferred_type: Option<DataType>,
4268}
4269
4270impl Alias {
4271    /// Create a simple alias
4272    pub fn new(this: Expression, alias: Identifier) -> Self {
4273        Self {
4274            this,
4275            alias,
4276            column_aliases: Vec::new(),
4277            pre_alias_comments: Vec::new(),
4278            trailing_comments: Vec::new(),
4279            inferred_type: None,
4280        }
4281    }
4282
4283    /// Create an alias with column aliases only (no table alias name)
4284    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4285        Self {
4286            this,
4287            alias: Identifier::empty(),
4288            column_aliases,
4289            pre_alias_comments: Vec::new(),
4290            trailing_comments: Vec::new(),
4291            inferred_type: None,
4292        }
4293    }
4294}
4295
4296/// Represent a type cast expression.
4297///
4298/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4299/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4300/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4301/// CONVERSION ERROR (Oracle) clauses.
4302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4303#[cfg_attr(feature = "bindings", derive(TS))]
4304pub struct Cast {
4305    /// The expression being cast.
4306    pub this: Expression,
4307    /// The target data type.
4308    pub to: DataType,
4309    #[serde(default)]
4310    pub trailing_comments: Vec<String>,
4311    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4312    #[serde(default)]
4313    pub double_colon_syntax: bool,
4314    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4315    #[serde(skip_serializing_if = "Option::is_none", default)]
4316    pub format: Option<Box<Expression>>,
4317    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4318    #[serde(skip_serializing_if = "Option::is_none", default)]
4319    pub default: Option<Box<Expression>>,
4320    /// Inferred data type from type annotation
4321    #[serde(default, skip_serializing_if = "Option::is_none")]
4322    pub inferred_type: Option<DataType>,
4323}
4324
4325///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4327#[cfg_attr(feature = "bindings", derive(TS))]
4328pub struct CollationExpr {
4329    pub this: Expression,
4330    pub collation: String,
4331    /// True if the collation was single-quoted in the original SQL (string literal)
4332    #[serde(default)]
4333    pub quoted: bool,
4334    /// True if the collation was double-quoted in the original SQL (identifier)
4335    #[serde(default)]
4336    pub double_quoted: bool,
4337}
4338
4339/// Represent a CASE expression (both simple and searched forms).
4340///
4341/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4342/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4343/// Each entry in `whens` is a `(condition, result)` pair.
4344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4345#[cfg_attr(feature = "bindings", derive(TS))]
4346pub struct Case {
4347    /// The operand for simple CASE, or `None` for searched CASE.
4348    pub operand: Option<Expression>,
4349    /// Pairs of (WHEN condition, THEN result).
4350    pub whens: Vec<(Expression, Expression)>,
4351    /// Optional ELSE result.
4352    pub else_: Option<Expression>,
4353    /// Comments from the CASE keyword (emitted after END)
4354    #[serde(default)]
4355    #[serde(skip_serializing_if = "Vec::is_empty")]
4356    pub comments: Vec<String>,
4357    /// Inferred data type from type annotation
4358    #[serde(default, skip_serializing_if = "Option::is_none")]
4359    pub inferred_type: Option<DataType>,
4360}
4361
4362/// Represent a binary operation (two operands separated by an operator).
4363///
4364/// This is the shared payload struct for all binary operator variants in the
4365/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4366/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4367/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4368/// preservation of inline comments around operators.
4369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4370#[cfg_attr(feature = "bindings", derive(TS))]
4371pub struct BinaryOp {
4372    pub left: Expression,
4373    pub right: Expression,
4374    /// Comments after the left operand (before the operator)
4375    #[serde(default)]
4376    pub left_comments: Vec<String>,
4377    /// Comments after the operator (before the right operand)
4378    #[serde(default)]
4379    pub operator_comments: Vec<String>,
4380    /// Comments after the right operand
4381    #[serde(default)]
4382    pub trailing_comments: Vec<String>,
4383    /// Inferred data type from type annotation
4384    #[serde(default, skip_serializing_if = "Option::is_none")]
4385    pub inferred_type: Option<DataType>,
4386}
4387
4388impl BinaryOp {
4389    pub fn new(left: Expression, right: Expression) -> Self {
4390        Self {
4391            left,
4392            right,
4393            left_comments: Vec::new(),
4394            operator_comments: Vec::new(),
4395            trailing_comments: Vec::new(),
4396            inferred_type: None,
4397        }
4398    }
4399}
4400
4401/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4403#[cfg_attr(feature = "bindings", derive(TS))]
4404pub struct LikeOp {
4405    pub left: Expression,
4406    pub right: Expression,
4407    /// ESCAPE character/expression
4408    #[serde(default)]
4409    pub escape: Option<Expression>,
4410    /// Quantifier: ANY, ALL, or SOME
4411    #[serde(default)]
4412    pub quantifier: Option<String>,
4413    /// Inferred data type from type annotation
4414    #[serde(default, skip_serializing_if = "Option::is_none")]
4415    pub inferred_type: Option<DataType>,
4416}
4417
4418impl LikeOp {
4419    pub fn new(left: Expression, right: Expression) -> Self {
4420        Self {
4421            left,
4422            right,
4423            escape: None,
4424            quantifier: None,
4425            inferred_type: None,
4426        }
4427    }
4428
4429    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4430        Self {
4431            left,
4432            right,
4433            escape: Some(escape),
4434            quantifier: None,
4435            inferred_type: None,
4436        }
4437    }
4438}
4439
4440/// Represent a unary operation (single operand with a prefix operator).
4441///
4442/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4444#[cfg_attr(feature = "bindings", derive(TS))]
4445pub struct UnaryOp {
4446    /// The operand expression.
4447    pub this: Expression,
4448    /// Inferred data type from type annotation
4449    #[serde(default, skip_serializing_if = "Option::is_none")]
4450    pub inferred_type: Option<DataType>,
4451}
4452
4453impl UnaryOp {
4454    pub fn new(this: Expression) -> Self {
4455        Self {
4456            this,
4457            inferred_type: None,
4458        }
4459    }
4460}
4461
4462/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4463///
4464/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4465/// but not both. When `not` is true, the predicate is `NOT IN`.
4466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4467#[cfg_attr(feature = "bindings", derive(TS))]
4468pub struct In {
4469    /// The expression being tested.
4470    pub this: Expression,
4471    /// The value list (mutually exclusive with `query`).
4472    pub expressions: Vec<Expression>,
4473    /// A subquery (mutually exclusive with `expressions`).
4474    pub query: Option<Expression>,
4475    /// Whether this is NOT IN.
4476    pub not: bool,
4477    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4478    pub global: bool,
4479    /// BigQuery: IN UNNEST(expr)
4480    #[serde(default, skip_serializing_if = "Option::is_none")]
4481    pub unnest: Option<Box<Expression>>,
4482    /// Whether the right side is a bare field reference (no parentheses).
4483    /// Matches Python sqlglot's `field` attribute on `In` expression.
4484    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4485    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4486    pub is_field: bool,
4487}
4488
4489/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4491#[cfg_attr(feature = "bindings", derive(TS))]
4492pub struct Between {
4493    /// The expression being tested.
4494    pub this: Expression,
4495    /// The lower bound.
4496    pub low: Expression,
4497    /// The upper bound.
4498    pub high: Expression,
4499    /// Whether this is NOT BETWEEN.
4500    pub not: bool,
4501    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4502    #[serde(default)]
4503    pub symmetric: Option<bool>,
4504}
4505
4506/// IS NULL predicate
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct IsNull {
4510    pub this: Expression,
4511    pub not: bool,
4512    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4513    #[serde(default)]
4514    pub postfix_form: bool,
4515}
4516
4517/// IS TRUE / IS FALSE predicate
4518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4519#[cfg_attr(feature = "bindings", derive(TS))]
4520pub struct IsTrueFalse {
4521    pub this: Expression,
4522    pub not: bool,
4523}
4524
4525/// IS JSON predicate (SQL standard)
4526/// Checks if a value is valid JSON
4527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4528#[cfg_attr(feature = "bindings", derive(TS))]
4529pub struct IsJson {
4530    pub this: Expression,
4531    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4532    pub json_type: Option<String>,
4533    /// Key uniqueness constraint
4534    pub unique_keys: Option<JsonUniqueKeys>,
4535    /// Whether IS NOT JSON
4536    pub negated: bool,
4537}
4538
4539/// JSON unique keys constraint variants
4540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4541#[cfg_attr(feature = "bindings", derive(TS))]
4542pub enum JsonUniqueKeys {
4543    /// WITH UNIQUE KEYS
4544    With,
4545    /// WITHOUT UNIQUE KEYS
4546    Without,
4547    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4548    Shorthand,
4549}
4550
4551/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4553#[cfg_attr(feature = "bindings", derive(TS))]
4554pub struct Exists {
4555    /// The subquery expression.
4556    pub this: Expression,
4557    /// Whether this is NOT EXISTS.
4558    pub not: bool,
4559}
4560
4561/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4562///
4563/// This is the generic function node. Well-known aggregates, window functions,
4564/// and built-in functions each have their own dedicated `Expression` variants
4565/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4566/// not recognize as built-ins are represented with this struct.
4567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4568#[cfg_attr(feature = "bindings", derive(TS))]
4569pub struct Function {
4570    /// The function name, as originally written (may be schema-qualified).
4571    pub name: String,
4572    /// Positional arguments to the function.
4573    pub args: Vec<Expression>,
4574    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4575    pub distinct: bool,
4576    #[serde(default)]
4577    pub trailing_comments: Vec<String>,
4578    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4579    #[serde(default)]
4580    pub use_bracket_syntax: bool,
4581    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4582    #[serde(default)]
4583    pub no_parens: bool,
4584    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4585    #[serde(default)]
4586    pub quoted: bool,
4587    /// Source position span
4588    #[serde(default, skip_serializing_if = "Option::is_none")]
4589    pub span: Option<Span>,
4590    /// Inferred data type from type annotation
4591    #[serde(default, skip_serializing_if = "Option::is_none")]
4592    pub inferred_type: Option<DataType>,
4593}
4594
4595impl Default for Function {
4596    fn default() -> Self {
4597        Self {
4598            name: String::new(),
4599            args: Vec::new(),
4600            distinct: false,
4601            trailing_comments: Vec::new(),
4602            use_bracket_syntax: false,
4603            no_parens: false,
4604            quoted: false,
4605            span: None,
4606            inferred_type: None,
4607        }
4608    }
4609}
4610
4611impl Function {
4612    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4613        Self {
4614            name: name.into(),
4615            args,
4616            distinct: false,
4617            trailing_comments: Vec::new(),
4618            use_bracket_syntax: false,
4619            no_parens: false,
4620            quoted: false,
4621            span: None,
4622            inferred_type: None,
4623        }
4624    }
4625}
4626
4627/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4628///
4629/// This struct is used for aggregate function calls that are not covered by
4630/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4631/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4632/// IGNORE NULLS / RESPECT NULLS modifiers.
4633#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4634#[cfg_attr(feature = "bindings", derive(TS))]
4635pub struct AggregateFunction {
4636    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4637    pub name: String,
4638    /// Positional arguments.
4639    pub args: Vec<Expression>,
4640    /// Whether DISTINCT was specified.
4641    pub distinct: bool,
4642    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4643    pub filter: Option<Expression>,
4644    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4645    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4646    pub order_by: Vec<Ordered>,
4647    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4648    #[serde(default, skip_serializing_if = "Option::is_none")]
4649    pub limit: Option<Box<Expression>>,
4650    /// IGNORE NULLS / RESPECT NULLS
4651    #[serde(default, skip_serializing_if = "Option::is_none")]
4652    pub ignore_nulls: Option<bool>,
4653    /// Inferred data type from type annotation
4654    #[serde(default, skip_serializing_if = "Option::is_none")]
4655    pub inferred_type: Option<DataType>,
4656}
4657
4658/// Represent a window function call with its OVER clause.
4659///
4660/// The inner `this` expression is typically a window-specific expression
4661/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4662/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4663/// frame specification.
4664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4665#[cfg_attr(feature = "bindings", derive(TS))]
4666pub struct WindowFunction {
4667    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4668    pub this: Expression,
4669    /// The OVER clause defining the window partitioning, ordering, and frame.
4670    pub over: Over,
4671    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4672    #[serde(default, skip_serializing_if = "Option::is_none")]
4673    pub keep: Option<Keep>,
4674    /// Inferred data type from type annotation
4675    #[serde(default, skip_serializing_if = "Option::is_none")]
4676    pub inferred_type: Option<DataType>,
4677}
4678
4679/// Oracle KEEP clause for aggregate functions
4680/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4682#[cfg_attr(feature = "bindings", derive(TS))]
4683pub struct Keep {
4684    /// true = FIRST, false = LAST
4685    pub first: bool,
4686    /// ORDER BY clause inside KEEP
4687    pub order_by: Vec<Ordered>,
4688}
4689
4690/// WITHIN GROUP clause (for ordered-set aggregate functions)
4691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4692#[cfg_attr(feature = "bindings", derive(TS))]
4693pub struct WithinGroup {
4694    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4695    pub this: Expression,
4696    /// The ORDER BY clause within the group
4697    pub order_by: Vec<Ordered>,
4698}
4699
4700/// Represent the FROM clause of a SELECT statement.
4701///
4702/// Contains one or more table sources (tables, subqueries, table-valued
4703/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4705#[cfg_attr(feature = "bindings", derive(TS))]
4706pub struct From {
4707    /// The table source expressions.
4708    pub expressions: Vec<Expression>,
4709}
4710
4711/// Represent a JOIN clause between two table sources.
4712///
4713/// The join condition can be specified via `on` (ON predicate) or `using`
4714/// (USING column list), but not both. The `kind` field determines the join
4715/// type (INNER, LEFT, CROSS, etc.).
4716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4717#[cfg_attr(feature = "bindings", derive(TS))]
4718pub struct Join {
4719    /// The right-hand table expression being joined.
4720    pub this: Expression,
4721    /// The ON condition (mutually exclusive with `using`).
4722    pub on: Option<Expression>,
4723    /// The USING column list (mutually exclusive with `on`).
4724    pub using: Vec<Identifier>,
4725    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4726    pub kind: JoinKind,
4727    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4728    pub use_inner_keyword: bool,
4729    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4730    pub use_outer_keyword: bool,
4731    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4732    pub deferred_condition: bool,
4733    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4734    #[serde(default, skip_serializing_if = "Option::is_none")]
4735    pub join_hint: Option<String>,
4736    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4737    #[serde(default, skip_serializing_if = "Option::is_none")]
4738    pub match_condition: Option<Expression>,
4739    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4740    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4741    pub pivots: Vec<Expression>,
4742    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4743    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4744    pub comments: Vec<String>,
4745    /// Nesting group identifier for nested join pretty-printing.
4746    /// Joins in the same group were parsed together; group boundaries come from
4747    /// deferred condition resolution phases.
4748    #[serde(default)]
4749    pub nesting_group: usize,
4750    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4751    #[serde(default)]
4752    pub directed: bool,
4753}
4754
4755/// Enumerate all supported SQL join types.
4756///
4757/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4758/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4759/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4760/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4761#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4762#[cfg_attr(feature = "bindings", derive(TS))]
4763pub enum JoinKind {
4764    Inner,
4765    Left,
4766    Right,
4767    Full,
4768    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
4769    Cross,
4770    Natural,
4771    NaturalLeft,
4772    NaturalRight,
4773    NaturalFull,
4774    Semi,
4775    Anti,
4776    // Directional SEMI/ANTI joins
4777    LeftSemi,
4778    LeftAnti,
4779    RightSemi,
4780    RightAnti,
4781    // SQL Server specific
4782    CrossApply,
4783    OuterApply,
4784    // Time-series specific
4785    AsOf,
4786    AsOfLeft,
4787    AsOfRight,
4788    // Lateral join
4789    Lateral,
4790    LeftLateral,
4791    // MySQL specific
4792    Straight,
4793    // Implicit join (comma-separated tables: FROM a, b)
4794    Implicit,
4795    // ClickHouse ARRAY JOIN
4796    Array,
4797    LeftArray,
4798    // ClickHouse PASTE JOIN (positional join)
4799    Paste,
4800    // DuckDB POSITIONAL JOIN
4801    Positional,
4802}
4803
4804impl Default for JoinKind {
4805    fn default() -> Self {
4806        JoinKind::Inner
4807    }
4808}
4809
4810/// Parenthesized table expression with joins
4811/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
4812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4813#[cfg_attr(feature = "bindings", derive(TS))]
4814pub struct JoinedTable {
4815    /// The left-hand side table expression
4816    pub left: Expression,
4817    /// The joins applied to the left table
4818    pub joins: Vec<Join>,
4819    /// LATERAL VIEW clauses (Hive/Spark)
4820    pub lateral_views: Vec<LateralView>,
4821    /// Optional alias for the joined table expression
4822    pub alias: Option<Identifier>,
4823}
4824
4825/// Represent a WHERE clause containing a boolean filter predicate.
4826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4827#[cfg_attr(feature = "bindings", derive(TS))]
4828pub struct Where {
4829    /// The filter predicate expression.
4830    pub this: Expression,
4831}
4832
4833/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
4834///
4835/// The `expressions` list may contain plain columns, ordinal positions,
4836/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
4837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4838#[cfg_attr(feature = "bindings", derive(TS))]
4839pub struct GroupBy {
4840    /// The grouping expressions.
4841    pub expressions: Vec<Expression>,
4842    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
4843    #[serde(default)]
4844    pub all: Option<bool>,
4845    /// ClickHouse: WITH TOTALS modifier
4846    #[serde(default)]
4847    pub totals: bool,
4848    /// Leading comments that appeared before the GROUP BY keyword
4849    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4850    pub comments: Vec<String>,
4851}
4852
4853/// Represent a HAVING clause containing a predicate over aggregate results.
4854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4855#[cfg_attr(feature = "bindings", derive(TS))]
4856pub struct Having {
4857    /// The filter predicate, typically involving aggregate functions.
4858    pub this: Expression,
4859    /// Leading comments that appeared before the HAVING keyword
4860    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4861    pub comments: Vec<String>,
4862}
4863
4864/// Represent an ORDER BY clause containing one or more sort specifications.
4865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4866#[cfg_attr(feature = "bindings", derive(TS))]
4867pub struct OrderBy {
4868    /// The sort specifications, each with direction and null ordering.
4869    pub expressions: Vec<Ordered>,
4870    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
4871    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4872    pub siblings: bool,
4873    /// Leading comments that appeared before the ORDER BY keyword
4874    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4875    pub comments: Vec<String>,
4876}
4877
4878/// Represent an expression with sort direction and null ordering.
4879///
4880/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
4881/// When `desc` is false the sort is ascending. The `nulls_first` field
4882/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
4883/// (database default).
4884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4885#[cfg_attr(feature = "bindings", derive(TS))]
4886pub struct Ordered {
4887    /// The expression to sort by.
4888    pub this: Expression,
4889    /// Whether the sort direction is descending (true) or ascending (false).
4890    pub desc: bool,
4891    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
4892    pub nulls_first: Option<bool>,
4893    /// Whether ASC was explicitly written (not just implied)
4894    #[serde(default)]
4895    pub explicit_asc: bool,
4896    /// ClickHouse WITH FILL clause
4897    #[serde(default, skip_serializing_if = "Option::is_none")]
4898    pub with_fill: Option<Box<WithFill>>,
4899}
4900
4901impl Ordered {
4902    pub fn asc(expr: Expression) -> Self {
4903        Self {
4904            this: expr,
4905            desc: false,
4906            nulls_first: None,
4907            explicit_asc: false,
4908            with_fill: None,
4909        }
4910    }
4911
4912    pub fn desc(expr: Expression) -> Self {
4913        Self {
4914            this: expr,
4915            desc: true,
4916            nulls_first: None,
4917            explicit_asc: false,
4918            with_fill: None,
4919        }
4920    }
4921}
4922
4923/// DISTRIBUTE BY clause (Hive/Spark)
4924/// Controls how rows are distributed across reducers
4925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4926#[cfg_attr(feature = "bindings", derive(TS))]
4927#[cfg_attr(feature = "bindings", ts(export))]
4928pub struct DistributeBy {
4929    pub expressions: Vec<Expression>,
4930}
4931
4932/// CLUSTER BY clause (Hive/Spark)
4933/// Combines DISTRIBUTE BY and SORT BY on the same columns
4934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4935#[cfg_attr(feature = "bindings", derive(TS))]
4936#[cfg_attr(feature = "bindings", ts(export))]
4937pub struct ClusterBy {
4938    pub expressions: Vec<Ordered>,
4939}
4940
4941/// SORT BY clause (Hive/Spark)
4942/// Sorts data within each reducer (local sort, not global)
4943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4944#[cfg_attr(feature = "bindings", derive(TS))]
4945#[cfg_attr(feature = "bindings", ts(export))]
4946pub struct SortBy {
4947    pub expressions: Vec<Ordered>,
4948}
4949
4950/// LATERAL VIEW clause (Hive/Spark)
4951/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
4952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4953#[cfg_attr(feature = "bindings", derive(TS))]
4954#[cfg_attr(feature = "bindings", ts(export))]
4955pub struct LateralView {
4956    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
4957    pub this: Expression,
4958    /// Table alias for the generated table
4959    pub table_alias: Option<Identifier>,
4960    /// Column aliases for the generated columns
4961    pub column_aliases: Vec<Identifier>,
4962    /// OUTER keyword - preserve nulls when input is empty/null
4963    pub outer: bool,
4964}
4965
4966/// Query hint
4967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4968#[cfg_attr(feature = "bindings", derive(TS))]
4969#[cfg_attr(feature = "bindings", ts(export))]
4970pub struct Hint {
4971    pub expressions: Vec<HintExpression>,
4972}
4973
4974/// Individual hint expression
4975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4976#[cfg_attr(feature = "bindings", derive(TS))]
4977#[cfg_attr(feature = "bindings", ts(export))]
4978pub enum HintExpression {
4979    /// Function-style hint: USE_HASH(table)
4980    Function { name: String, args: Vec<Expression> },
4981    /// Simple identifier hint: PARALLEL
4982    Identifier(String),
4983    /// Raw hint text (unparsed)
4984    Raw(String),
4985}
4986
4987/// Pseudocolumn type
4988#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4989#[cfg_attr(feature = "bindings", derive(TS))]
4990#[cfg_attr(feature = "bindings", ts(export))]
4991pub enum PseudocolumnType {
4992    Rownum,      // Oracle ROWNUM
4993    Rowid,       // Oracle ROWID
4994    Level,       // Oracle LEVEL (for CONNECT BY)
4995    Sysdate,     // Oracle SYSDATE
4996    ObjectId,    // Oracle OBJECT_ID
4997    ObjectValue, // Oracle OBJECT_VALUE
4998}
4999
5000impl PseudocolumnType {
5001    pub fn as_str(&self) -> &'static str {
5002        match self {
5003            PseudocolumnType::Rownum => "ROWNUM",
5004            PseudocolumnType::Rowid => "ROWID",
5005            PseudocolumnType::Level => "LEVEL",
5006            PseudocolumnType::Sysdate => "SYSDATE",
5007            PseudocolumnType::ObjectId => "OBJECT_ID",
5008            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5009        }
5010    }
5011
5012    pub fn from_str(s: &str) -> Option<Self> {
5013        match s.to_uppercase().as_str() {
5014            "ROWNUM" => Some(PseudocolumnType::Rownum),
5015            "ROWID" => Some(PseudocolumnType::Rowid),
5016            "LEVEL" => Some(PseudocolumnType::Level),
5017            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5018            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5019            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5020            _ => None,
5021        }
5022    }
5023}
5024
5025/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5026/// These are special identifiers that should not be quoted
5027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5028#[cfg_attr(feature = "bindings", derive(TS))]
5029#[cfg_attr(feature = "bindings", ts(export))]
5030pub struct Pseudocolumn {
5031    pub kind: PseudocolumnType,
5032}
5033
5034impl Pseudocolumn {
5035    pub fn rownum() -> Self {
5036        Self {
5037            kind: PseudocolumnType::Rownum,
5038        }
5039    }
5040
5041    pub fn rowid() -> Self {
5042        Self {
5043            kind: PseudocolumnType::Rowid,
5044        }
5045    }
5046
5047    pub fn level() -> Self {
5048        Self {
5049            kind: PseudocolumnType::Level,
5050        }
5051    }
5052}
5053
5054/// Oracle CONNECT BY clause for hierarchical queries
5055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5056#[cfg_attr(feature = "bindings", derive(TS))]
5057#[cfg_attr(feature = "bindings", ts(export))]
5058pub struct Connect {
5059    /// START WITH condition (optional, can come before or after CONNECT BY)
5060    pub start: Option<Expression>,
5061    /// CONNECT BY condition (required, contains PRIOR references)
5062    pub connect: Expression,
5063    /// NOCYCLE keyword to prevent infinite loops
5064    pub nocycle: bool,
5065}
5066
5067/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5069#[cfg_attr(feature = "bindings", derive(TS))]
5070#[cfg_attr(feature = "bindings", ts(export))]
5071pub struct Prior {
5072    pub this: Expression,
5073}
5074
5075/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5077#[cfg_attr(feature = "bindings", derive(TS))]
5078#[cfg_attr(feature = "bindings", ts(export))]
5079pub struct ConnectByRoot {
5080    pub this: Expression,
5081}
5082
5083/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5085#[cfg_attr(feature = "bindings", derive(TS))]
5086#[cfg_attr(feature = "bindings", ts(export))]
5087pub struct MatchRecognize {
5088    /// Source table/expression
5089    pub this: Option<Box<Expression>>,
5090    /// PARTITION BY expressions
5091    pub partition_by: Option<Vec<Expression>>,
5092    /// ORDER BY expressions
5093    pub order_by: Option<Vec<Ordered>>,
5094    /// MEASURES definitions
5095    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5096    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5097    pub rows: Option<MatchRecognizeRows>,
5098    /// AFTER MATCH SKIP behavior
5099    pub after: Option<MatchRecognizeAfter>,
5100    /// PATTERN definition (stored as raw string for complex regex patterns)
5101    pub pattern: Option<String>,
5102    /// DEFINE clauses (pattern variable definitions)
5103    pub define: Option<Vec<(Identifier, Expression)>>,
5104    /// Optional alias for the result
5105    pub alias: Option<Identifier>,
5106    /// Whether AS keyword was explicitly present before alias
5107    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5108    pub alias_explicit_as: bool,
5109}
5110
5111/// MEASURES expression with optional RUNNING/FINAL semantics
5112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5113#[cfg_attr(feature = "bindings", derive(TS))]
5114#[cfg_attr(feature = "bindings", ts(export))]
5115pub struct MatchRecognizeMeasure {
5116    /// The measure expression
5117    pub this: Expression,
5118    /// RUNNING or FINAL semantics (Snowflake-specific)
5119    pub window_frame: Option<MatchRecognizeSemantics>,
5120}
5121
5122/// Semantics for MEASURES in MATCH_RECOGNIZE
5123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5124#[cfg_attr(feature = "bindings", derive(TS))]
5125#[cfg_attr(feature = "bindings", ts(export))]
5126pub enum MatchRecognizeSemantics {
5127    Running,
5128    Final,
5129}
5130
5131/// Row output semantics for MATCH_RECOGNIZE
5132#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5133#[cfg_attr(feature = "bindings", derive(TS))]
5134#[cfg_attr(feature = "bindings", ts(export))]
5135pub enum MatchRecognizeRows {
5136    OneRowPerMatch,
5137    AllRowsPerMatch,
5138    AllRowsPerMatchShowEmptyMatches,
5139    AllRowsPerMatchOmitEmptyMatches,
5140    AllRowsPerMatchWithUnmatchedRows,
5141}
5142
5143/// AFTER MATCH SKIP behavior
5144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5145#[cfg_attr(feature = "bindings", derive(TS))]
5146#[cfg_attr(feature = "bindings", ts(export))]
5147pub enum MatchRecognizeAfter {
5148    PastLastRow,
5149    ToNextRow,
5150    ToFirst(Identifier),
5151    ToLast(Identifier),
5152}
5153
5154/// Represent a LIMIT clause that restricts the number of returned rows.
5155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5156#[cfg_attr(feature = "bindings", derive(TS))]
5157pub struct Limit {
5158    /// The limit count expression.
5159    pub this: Expression,
5160    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5161    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5162    pub percent: bool,
5163    /// Comments from before the LIMIT keyword (emitted after the limit value)
5164    #[serde(default)]
5165    #[serde(skip_serializing_if = "Vec::is_empty")]
5166    pub comments: Vec<String>,
5167}
5168
5169/// OFFSET clause
5170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5171#[cfg_attr(feature = "bindings", derive(TS))]
5172pub struct Offset {
5173    pub this: Expression,
5174    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5175    #[serde(skip_serializing_if = "Option::is_none", default)]
5176    pub rows: Option<bool>,
5177}
5178
5179/// TOP clause (SQL Server)
5180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5181#[cfg_attr(feature = "bindings", derive(TS))]
5182pub struct Top {
5183    pub this: Expression,
5184    pub percent: bool,
5185    pub with_ties: bool,
5186    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5187    #[serde(default)]
5188    pub parenthesized: bool,
5189}
5190
5191/// FETCH FIRST/NEXT clause (SQL standard)
5192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5193#[cfg_attr(feature = "bindings", derive(TS))]
5194pub struct Fetch {
5195    /// FIRST or NEXT
5196    pub direction: String,
5197    /// Count expression (optional)
5198    pub count: Option<Expression>,
5199    /// PERCENT modifier
5200    pub percent: bool,
5201    /// ROWS or ROW keyword present
5202    pub rows: bool,
5203    /// WITH TIES modifier
5204    pub with_ties: bool,
5205}
5206
5207/// Represent a QUALIFY clause for filtering on window function results.
5208///
5209/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5210/// typically references a window function (e.g.
5211/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5213#[cfg_attr(feature = "bindings", derive(TS))]
5214pub struct Qualify {
5215    /// The filter predicate over window function results.
5216    pub this: Expression,
5217}
5218
5219/// SAMPLE / TABLESAMPLE clause
5220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5221#[cfg_attr(feature = "bindings", derive(TS))]
5222pub struct Sample {
5223    pub method: SampleMethod,
5224    pub size: Expression,
5225    pub seed: Option<Expression>,
5226    /// ClickHouse OFFSET expression after SAMPLE size
5227    #[serde(default)]
5228    pub offset: Option<Expression>,
5229    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5230    pub unit_after_size: bool,
5231    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5232    #[serde(default)]
5233    pub use_sample_keyword: bool,
5234    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5235    #[serde(default)]
5236    pub explicit_method: bool,
5237    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5238    #[serde(default)]
5239    pub method_before_size: bool,
5240    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5241    #[serde(default)]
5242    pub use_seed_keyword: bool,
5243    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5244    pub bucket_numerator: Option<Box<Expression>>,
5245    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5246    pub bucket_denominator: Option<Box<Expression>>,
5247    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5248    pub bucket_field: Option<Box<Expression>>,
5249    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5250    #[serde(default)]
5251    pub is_using_sample: bool,
5252    /// Whether the unit was explicitly PERCENT (vs ROWS)
5253    #[serde(default)]
5254    pub is_percent: bool,
5255    /// Whether to suppress method output (for cross-dialect transpilation)
5256    #[serde(default)]
5257    pub suppress_method_output: bool,
5258}
5259
5260/// Sample method
5261#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5262#[cfg_attr(feature = "bindings", derive(TS))]
5263pub enum SampleMethod {
5264    Bernoulli,
5265    System,
5266    Block,
5267    Row,
5268    Percent,
5269    /// Hive bucket sampling
5270    Bucket,
5271    /// DuckDB reservoir sampling
5272    Reservoir,
5273}
5274
5275/// Named window definition (WINDOW w AS (...))
5276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5277#[cfg_attr(feature = "bindings", derive(TS))]
5278pub struct NamedWindow {
5279    pub name: Identifier,
5280    pub spec: Over,
5281}
5282
5283/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5284///
5285/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5286/// that reference themselves. Each CTE is defined in the `ctes` vector and
5287/// can be referenced by name in subsequent CTEs and in the main query body.
5288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5289#[cfg_attr(feature = "bindings", derive(TS))]
5290pub struct With {
5291    /// The list of CTE definitions, in order.
5292    pub ctes: Vec<Cte>,
5293    /// Whether the WITH RECURSIVE keyword was used.
5294    pub recursive: bool,
5295    /// Leading comments before the statement
5296    #[serde(default)]
5297    pub leading_comments: Vec<String>,
5298    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5299    #[serde(default, skip_serializing_if = "Option::is_none")]
5300    pub search: Option<Box<Expression>>,
5301}
5302
5303/// Represent a single Common Table Expression definition.
5304///
5305/// A CTE has a name (`alias`), an optional column list, and a body query.
5306/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5307/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5308/// the expression comes before the alias (`alias_first`).
5309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5310#[cfg_attr(feature = "bindings", derive(TS))]
5311pub struct Cte {
5312    /// The CTE name.
5313    pub alias: Identifier,
5314    /// The CTE body (typically a SELECT, UNION, etc.).
5315    pub this: Expression,
5316    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5317    pub columns: Vec<Identifier>,
5318    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5319    pub materialized: Option<bool>,
5320    /// USING KEY (columns) for DuckDB recursive CTEs
5321    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5322    pub key_expressions: Vec<Identifier>,
5323    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5324    #[serde(default)]
5325    pub alias_first: bool,
5326    /// Comments associated with this CTE (placed after alias name, before AS)
5327    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5328    pub comments: Vec<String>,
5329}
5330
5331/// Window specification
5332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5333#[cfg_attr(feature = "bindings", derive(TS))]
5334pub struct WindowSpec {
5335    pub partition_by: Vec<Expression>,
5336    pub order_by: Vec<Ordered>,
5337    pub frame: Option<WindowFrame>,
5338}
5339
5340/// OVER clause
5341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5342#[cfg_attr(feature = "bindings", derive(TS))]
5343pub struct Over {
5344    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5345    pub window_name: Option<Identifier>,
5346    pub partition_by: Vec<Expression>,
5347    pub order_by: Vec<Ordered>,
5348    pub frame: Option<WindowFrame>,
5349    pub alias: Option<Identifier>,
5350}
5351
5352/// Window frame
5353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5354#[cfg_attr(feature = "bindings", derive(TS))]
5355pub struct WindowFrame {
5356    pub kind: WindowFrameKind,
5357    pub start: WindowFrameBound,
5358    pub end: Option<WindowFrameBound>,
5359    pub exclude: Option<WindowFrameExclude>,
5360    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5361    #[serde(default, skip_serializing_if = "Option::is_none")]
5362    pub kind_text: Option<String>,
5363    /// Original text of the start bound side keyword (e.g. "preceding")
5364    #[serde(default, skip_serializing_if = "Option::is_none")]
5365    pub start_side_text: Option<String>,
5366    /// Original text of the end bound side keyword
5367    #[serde(default, skip_serializing_if = "Option::is_none")]
5368    pub end_side_text: Option<String>,
5369}
5370
5371#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5372#[cfg_attr(feature = "bindings", derive(TS))]
5373pub enum WindowFrameKind {
5374    Rows,
5375    Range,
5376    Groups,
5377}
5378
5379/// EXCLUDE clause for window frames
5380#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5381#[cfg_attr(feature = "bindings", derive(TS))]
5382pub enum WindowFrameExclude {
5383    CurrentRow,
5384    Group,
5385    Ties,
5386    NoOthers,
5387}
5388
5389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5390#[cfg_attr(feature = "bindings", derive(TS))]
5391pub enum WindowFrameBound {
5392    CurrentRow,
5393    UnboundedPreceding,
5394    UnboundedFollowing,
5395    Preceding(Box<Expression>),
5396    Following(Box<Expression>),
5397    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5398    BarePreceding,
5399    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5400    BareFollowing,
5401    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5402    Value(Box<Expression>),
5403}
5404
5405/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5407#[cfg_attr(feature = "bindings", derive(TS))]
5408pub struct StructField {
5409    pub name: String,
5410    pub data_type: DataType,
5411    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5412    pub options: Vec<Expression>,
5413    #[serde(default, skip_serializing_if = "Option::is_none")]
5414    pub comment: Option<String>,
5415}
5416
5417impl StructField {
5418    /// Create a new struct field without options
5419    pub fn new(name: String, data_type: DataType) -> Self {
5420        Self {
5421            name,
5422            data_type,
5423            options: Vec::new(),
5424            comment: None,
5425        }
5426    }
5427
5428    /// Create a new struct field with options
5429    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5430        Self {
5431            name,
5432            data_type,
5433            options,
5434            comment: None,
5435        }
5436    }
5437
5438    /// Create a new struct field with options and comment
5439    pub fn with_options_and_comment(
5440        name: String,
5441        data_type: DataType,
5442        options: Vec<Expression>,
5443        comment: Option<String>,
5444    ) -> Self {
5445        Self {
5446            name,
5447            data_type,
5448            options,
5449            comment,
5450        }
5451    }
5452}
5453
5454/// Enumerate all SQL data types recognized by the parser.
5455///
5456/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5457/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5458/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5459///
5460/// This enum is used in CAST expressions, column definitions, function return
5461/// types, and anywhere a data type specification appears in SQL.
5462///
5463/// Types that do not match any known variant fall through to `Custom { name }`,
5464/// preserving the original type name for round-trip fidelity.
5465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5466#[cfg_attr(feature = "bindings", derive(TS))]
5467#[serde(tag = "data_type", rename_all = "snake_case")]
5468pub enum DataType {
5469    // Numeric
5470    Boolean,
5471    TinyInt {
5472        length: Option<u32>,
5473    },
5474    SmallInt {
5475        length: Option<u32>,
5476    },
5477    /// Int type with optional length. `integer_spelling` indicates whether the original
5478    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5479    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5480    Int {
5481        length: Option<u32>,
5482        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5483        integer_spelling: bool,
5484    },
5485    BigInt {
5486        length: Option<u32>,
5487    },
5488    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5489    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5490    /// preserve the original spelling.
5491    Float {
5492        precision: Option<u32>,
5493        scale: Option<u32>,
5494        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5495        real_spelling: bool,
5496    },
5497    Double {
5498        precision: Option<u32>,
5499        scale: Option<u32>,
5500    },
5501    Decimal {
5502        precision: Option<u32>,
5503        scale: Option<u32>,
5504    },
5505
5506    // String
5507    Char {
5508        length: Option<u32>,
5509    },
5510    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5511    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5512    VarChar {
5513        length: Option<u32>,
5514        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5515        parenthesized_length: bool,
5516    },
5517    /// String type with optional max length (BigQuery STRING(n))
5518    String {
5519        length: Option<u32>,
5520    },
5521    Text,
5522    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5523    TextWithLength {
5524        length: u32,
5525    },
5526
5527    // Binary
5528    Binary {
5529        length: Option<u32>,
5530    },
5531    VarBinary {
5532        length: Option<u32>,
5533    },
5534    Blob,
5535
5536    // Bit
5537    Bit {
5538        length: Option<u32>,
5539    },
5540    VarBit {
5541        length: Option<u32>,
5542    },
5543
5544    // Date/Time
5545    Date,
5546    Time {
5547        precision: Option<u32>,
5548        #[serde(default)]
5549        timezone: bool,
5550    },
5551    Timestamp {
5552        precision: Option<u32>,
5553        timezone: bool,
5554    },
5555    Interval {
5556        unit: Option<String>,
5557        /// For range intervals like INTERVAL DAY TO HOUR
5558        #[serde(default, skip_serializing_if = "Option::is_none")]
5559        to: Option<String>,
5560    },
5561
5562    // JSON
5563    Json,
5564    JsonB,
5565
5566    // UUID
5567    Uuid,
5568
5569    // Array
5570    Array {
5571        element_type: Box<DataType>,
5572        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5573        #[serde(default, skip_serializing_if = "Option::is_none")]
5574        dimension: Option<u32>,
5575    },
5576
5577    /// List type (Materialize): INT LIST, TEXT LIST LIST
5578    /// Uses postfix LIST syntax instead of ARRAY<T>
5579    List {
5580        element_type: Box<DataType>,
5581    },
5582
5583    // Struct/Map
5584    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5585    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5586    Struct {
5587        fields: Vec<StructField>,
5588        nested: bool,
5589    },
5590    Map {
5591        key_type: Box<DataType>,
5592        value_type: Box<DataType>,
5593    },
5594
5595    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5596    Enum {
5597        values: Vec<String>,
5598        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5599        assignments: Vec<Option<String>>,
5600    },
5601
5602    // Set type (MySQL): SET('a', 'b', 'c')
5603    Set {
5604        values: Vec<String>,
5605    },
5606
5607    // Union type (DuckDB): UNION(num INT, str TEXT)
5608    Union {
5609        fields: Vec<(String, DataType)>,
5610    },
5611
5612    // Vector (Snowflake / SingleStore)
5613    Vector {
5614        #[serde(default)]
5615        element_type: Option<Box<DataType>>,
5616        dimension: Option<u32>,
5617    },
5618
5619    // Object (Snowflake structured type)
5620    // fields: Vec of (field_name, field_type, not_null)
5621    Object {
5622        fields: Vec<(String, DataType, bool)>,
5623        modifier: Option<String>,
5624    },
5625
5626    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5627    Nullable {
5628        inner: Box<DataType>,
5629    },
5630
5631    // Custom/User-defined
5632    Custom {
5633        name: String,
5634    },
5635
5636    // Spatial types
5637    Geometry {
5638        subtype: Option<String>,
5639        srid: Option<u32>,
5640    },
5641    Geography {
5642        subtype: Option<String>,
5643        srid: Option<u32>,
5644    },
5645
5646    // Character Set (for CONVERT USING in MySQL)
5647    // Renders as CHAR CHARACTER SET {name} in cast target
5648    CharacterSet {
5649        name: String,
5650    },
5651
5652    // Unknown
5653    Unknown,
5654}
5655
5656/// Array expression
5657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5658#[cfg_attr(feature = "bindings", derive(TS))]
5659#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5660pub struct Array {
5661    pub expressions: Vec<Expression>,
5662}
5663
5664/// Struct expression
5665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5666#[cfg_attr(feature = "bindings", derive(TS))]
5667pub struct Struct {
5668    pub fields: Vec<(Option<String>, Expression)>,
5669}
5670
5671/// Tuple expression
5672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5673#[cfg_attr(feature = "bindings", derive(TS))]
5674pub struct Tuple {
5675    pub expressions: Vec<Expression>,
5676}
5677
5678/// Interval expression
5679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5680#[cfg_attr(feature = "bindings", derive(TS))]
5681pub struct Interval {
5682    /// The value expression (e.g., '1', 5, column_ref)
5683    pub this: Option<Expression>,
5684    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5685    pub unit: Option<IntervalUnitSpec>,
5686}
5687
5688/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5690#[cfg_attr(feature = "bindings", derive(TS))]
5691#[serde(tag = "type", rename_all = "snake_case")]
5692pub enum IntervalUnitSpec {
5693    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5694    Simple {
5695        unit: IntervalUnit,
5696        /// Whether to use plural form (e.g., DAYS vs DAY)
5697        use_plural: bool,
5698    },
5699    /// Interval span (e.g., HOUR TO SECOND)
5700    Span(IntervalSpan),
5701    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5702    /// The start and end can be expressions like function calls with precision
5703    ExprSpan(IntervalSpanExpr),
5704    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5705    Expr(Box<Expression>),
5706}
5707
5708/// Interval span for ranges like HOUR TO SECOND
5709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5710#[cfg_attr(feature = "bindings", derive(TS))]
5711pub struct IntervalSpan {
5712    /// Start unit (e.g., HOUR)
5713    pub this: IntervalUnit,
5714    /// End unit (e.g., SECOND)
5715    pub expression: IntervalUnit,
5716}
5717
5718/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5719/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5721#[cfg_attr(feature = "bindings", derive(TS))]
5722pub struct IntervalSpanExpr {
5723    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5724    pub this: Box<Expression>,
5725    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5726    pub expression: Box<Expression>,
5727}
5728
5729#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5730#[cfg_attr(feature = "bindings", derive(TS))]
5731pub enum IntervalUnit {
5732    Year,
5733    Quarter,
5734    Month,
5735    Week,
5736    Day,
5737    Hour,
5738    Minute,
5739    Second,
5740    Millisecond,
5741    Microsecond,
5742    Nanosecond,
5743}
5744
5745/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5747#[cfg_attr(feature = "bindings", derive(TS))]
5748pub struct Command {
5749    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5750    pub this: String,
5751}
5752
5753/// EXEC/EXECUTE statement (TSQL stored procedure call)
5754/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5756#[cfg_attr(feature = "bindings", derive(TS))]
5757pub struct ExecuteStatement {
5758    /// The procedure name (can be qualified: schema.proc_name)
5759    pub this: Expression,
5760    /// Named parameters: @param=value pairs
5761    #[serde(default)]
5762    pub parameters: Vec<ExecuteParameter>,
5763}
5764
5765/// Named parameter in EXEC statement: @name=value
5766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5767#[cfg_attr(feature = "bindings", derive(TS))]
5768pub struct ExecuteParameter {
5769    /// Parameter name (including @)
5770    pub name: String,
5771    /// Parameter value
5772    pub value: Expression,
5773    /// Whether this is a positional parameter (no = sign)
5774    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5775    pub positional: bool,
5776}
5777
5778/// KILL statement (MySQL/MariaDB)
5779/// KILL [CONNECTION | QUERY] <id>
5780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5781#[cfg_attr(feature = "bindings", derive(TS))]
5782pub struct Kill {
5783    /// The target (process ID or connection ID)
5784    pub this: Expression,
5785    /// Optional kind: "CONNECTION" or "QUERY"
5786    pub kind: Option<String>,
5787}
5788
5789/// Raw/unparsed SQL
5790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5791#[cfg_attr(feature = "bindings", derive(TS))]
5792pub struct Raw {
5793    pub sql: String,
5794}
5795
5796// ============================================================================
5797// Function expression types
5798// ============================================================================
5799
5800/// Generic unary function (takes a single argument)
5801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5802#[cfg_attr(feature = "bindings", derive(TS))]
5803pub struct UnaryFunc {
5804    pub this: Expression,
5805    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
5806    #[serde(skip_serializing_if = "Option::is_none", default)]
5807    pub original_name: Option<String>,
5808    /// Inferred data type from type annotation
5809    #[serde(default, skip_serializing_if = "Option::is_none")]
5810    pub inferred_type: Option<DataType>,
5811}
5812
5813impl UnaryFunc {
5814    /// Create a new UnaryFunc with no original_name
5815    pub fn new(this: Expression) -> Self {
5816        Self {
5817            this,
5818            original_name: None,
5819            inferred_type: None,
5820        }
5821    }
5822
5823    /// Create a new UnaryFunc with an original name for round-trip preservation
5824    pub fn with_name(this: Expression, name: String) -> Self {
5825        Self {
5826            this,
5827            original_name: Some(name),
5828            inferred_type: None,
5829        }
5830    }
5831}
5832
5833/// CHAR/CHR function with multiple args and optional USING charset
5834/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
5835/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
5836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5837#[cfg_attr(feature = "bindings", derive(TS))]
5838pub struct CharFunc {
5839    pub args: Vec<Expression>,
5840    #[serde(skip_serializing_if = "Option::is_none", default)]
5841    pub charset: Option<String>,
5842    /// Original function name (CHAR or CHR), defaults to CHAR
5843    #[serde(skip_serializing_if = "Option::is_none", default)]
5844    pub name: Option<String>,
5845}
5846
5847/// Generic binary function (takes two arguments)
5848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5849#[cfg_attr(feature = "bindings", derive(TS))]
5850pub struct BinaryFunc {
5851    pub this: Expression,
5852    pub expression: Expression,
5853    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
5854    #[serde(skip_serializing_if = "Option::is_none", default)]
5855    pub original_name: Option<String>,
5856    /// Inferred data type from type annotation
5857    #[serde(default, skip_serializing_if = "Option::is_none")]
5858    pub inferred_type: Option<DataType>,
5859}
5860
5861/// Variable argument function
5862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5863#[cfg_attr(feature = "bindings", derive(TS))]
5864pub struct VarArgFunc {
5865    pub expressions: Vec<Expression>,
5866    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
5867    #[serde(skip_serializing_if = "Option::is_none", default)]
5868    pub original_name: Option<String>,
5869    /// Inferred data type from type annotation
5870    #[serde(default, skip_serializing_if = "Option::is_none")]
5871    pub inferred_type: Option<DataType>,
5872}
5873
5874/// CONCAT_WS function
5875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5876#[cfg_attr(feature = "bindings", derive(TS))]
5877pub struct ConcatWs {
5878    pub separator: Expression,
5879    pub expressions: Vec<Expression>,
5880}
5881
5882/// SUBSTRING function
5883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5884#[cfg_attr(feature = "bindings", derive(TS))]
5885pub struct SubstringFunc {
5886    pub this: Expression,
5887    pub start: Expression,
5888    pub length: Option<Expression>,
5889    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
5890    #[serde(default)]
5891    pub from_for_syntax: bool,
5892}
5893
5894/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
5895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5896#[cfg_attr(feature = "bindings", derive(TS))]
5897pub struct OverlayFunc {
5898    pub this: Expression,
5899    pub replacement: Expression,
5900    pub from: Expression,
5901    pub length: Option<Expression>,
5902}
5903
5904/// TRIM function
5905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5906#[cfg_attr(feature = "bindings", derive(TS))]
5907pub struct TrimFunc {
5908    pub this: Expression,
5909    pub characters: Option<Expression>,
5910    pub position: TrimPosition,
5911    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
5912    #[serde(default)]
5913    pub sql_standard_syntax: bool,
5914    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
5915    #[serde(default)]
5916    pub position_explicit: bool,
5917}
5918
5919#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5920#[cfg_attr(feature = "bindings", derive(TS))]
5921pub enum TrimPosition {
5922    Both,
5923    Leading,
5924    Trailing,
5925}
5926
5927/// REPLACE function
5928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5929#[cfg_attr(feature = "bindings", derive(TS))]
5930pub struct ReplaceFunc {
5931    pub this: Expression,
5932    pub old: Expression,
5933    pub new: Expression,
5934}
5935
5936/// LEFT/RIGHT function
5937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5938#[cfg_attr(feature = "bindings", derive(TS))]
5939pub struct LeftRightFunc {
5940    pub this: Expression,
5941    pub length: Expression,
5942}
5943
5944/// REPEAT function
5945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5946#[cfg_attr(feature = "bindings", derive(TS))]
5947pub struct RepeatFunc {
5948    pub this: Expression,
5949    pub times: Expression,
5950}
5951
5952/// LPAD/RPAD function
5953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5954#[cfg_attr(feature = "bindings", derive(TS))]
5955pub struct PadFunc {
5956    pub this: Expression,
5957    pub length: Expression,
5958    pub fill: Option<Expression>,
5959}
5960
5961/// SPLIT function
5962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5963#[cfg_attr(feature = "bindings", derive(TS))]
5964pub struct SplitFunc {
5965    pub this: Expression,
5966    pub delimiter: Expression,
5967}
5968
5969/// REGEXP_LIKE function
5970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5971#[cfg_attr(feature = "bindings", derive(TS))]
5972pub struct RegexpFunc {
5973    pub this: Expression,
5974    pub pattern: Expression,
5975    pub flags: Option<Expression>,
5976}
5977
5978/// REGEXP_REPLACE function
5979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5980#[cfg_attr(feature = "bindings", derive(TS))]
5981pub struct RegexpReplaceFunc {
5982    pub this: Expression,
5983    pub pattern: Expression,
5984    pub replacement: Expression,
5985    pub flags: Option<Expression>,
5986}
5987
5988/// REGEXP_EXTRACT function
5989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5990#[cfg_attr(feature = "bindings", derive(TS))]
5991pub struct RegexpExtractFunc {
5992    pub this: Expression,
5993    pub pattern: Expression,
5994    pub group: Option<Expression>,
5995}
5996
5997/// ROUND function
5998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5999#[cfg_attr(feature = "bindings", derive(TS))]
6000pub struct RoundFunc {
6001    pub this: Expression,
6002    pub decimals: Option<Expression>,
6003}
6004
6005/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6007#[cfg_attr(feature = "bindings", derive(TS))]
6008pub struct FloorFunc {
6009    pub this: Expression,
6010    pub scale: Option<Expression>,
6011    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6012    #[serde(skip_serializing_if = "Option::is_none", default)]
6013    pub to: Option<Expression>,
6014}
6015
6016/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6018#[cfg_attr(feature = "bindings", derive(TS))]
6019pub struct CeilFunc {
6020    pub this: Expression,
6021    #[serde(skip_serializing_if = "Option::is_none", default)]
6022    pub decimals: Option<Expression>,
6023    /// Time unit for Druid-style CEIL(time TO unit) syntax
6024    #[serde(skip_serializing_if = "Option::is_none", default)]
6025    pub to: Option<Expression>,
6026}
6027
6028/// LOG function
6029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6030#[cfg_attr(feature = "bindings", derive(TS))]
6031pub struct LogFunc {
6032    pub this: Expression,
6033    pub base: Option<Expression>,
6034}
6035
6036/// CURRENT_DATE (no arguments)
6037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6038#[cfg_attr(feature = "bindings", derive(TS))]
6039pub struct CurrentDate;
6040
6041/// CURRENT_TIME
6042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6043#[cfg_attr(feature = "bindings", derive(TS))]
6044pub struct CurrentTime {
6045    pub precision: Option<u32>,
6046}
6047
6048/// CURRENT_TIMESTAMP
6049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6050#[cfg_attr(feature = "bindings", derive(TS))]
6051pub struct CurrentTimestamp {
6052    pub precision: Option<u32>,
6053    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6054    #[serde(default)]
6055    pub sysdate: bool,
6056}
6057
6058/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6060#[cfg_attr(feature = "bindings", derive(TS))]
6061pub struct CurrentTimestampLTZ {
6062    pub precision: Option<u32>,
6063}
6064
6065/// AT TIME ZONE expression for timezone conversion
6066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6067#[cfg_attr(feature = "bindings", derive(TS))]
6068pub struct AtTimeZone {
6069    /// The expression to convert
6070    pub this: Expression,
6071    /// The target timezone
6072    pub zone: Expression,
6073}
6074
6075/// DATE_ADD / DATE_SUB function
6076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6077#[cfg_attr(feature = "bindings", derive(TS))]
6078pub struct DateAddFunc {
6079    pub this: Expression,
6080    pub interval: Expression,
6081    pub unit: IntervalUnit,
6082}
6083
6084/// DATEDIFF function
6085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6086#[cfg_attr(feature = "bindings", derive(TS))]
6087pub struct DateDiffFunc {
6088    pub this: Expression,
6089    pub expression: Expression,
6090    pub unit: Option<IntervalUnit>,
6091}
6092
6093/// DATE_TRUNC function
6094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6095#[cfg_attr(feature = "bindings", derive(TS))]
6096pub struct DateTruncFunc {
6097    pub this: Expression,
6098    pub unit: DateTimeField,
6099}
6100
6101/// EXTRACT function
6102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6103#[cfg_attr(feature = "bindings", derive(TS))]
6104pub struct ExtractFunc {
6105    pub this: Expression,
6106    pub field: DateTimeField,
6107}
6108
6109#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6110#[cfg_attr(feature = "bindings", derive(TS))]
6111pub enum DateTimeField {
6112    Year,
6113    Month,
6114    Day,
6115    Hour,
6116    Minute,
6117    Second,
6118    Millisecond,
6119    Microsecond,
6120    DayOfWeek,
6121    DayOfYear,
6122    Week,
6123    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6124    WeekWithModifier(String),
6125    Quarter,
6126    Epoch,
6127    Timezone,
6128    TimezoneHour,
6129    TimezoneMinute,
6130    Date,
6131    Time,
6132    /// Custom datetime field for dialect-specific or arbitrary fields
6133    Custom(String),
6134}
6135
6136/// TO_DATE function
6137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6138#[cfg_attr(feature = "bindings", derive(TS))]
6139pub struct ToDateFunc {
6140    pub this: Expression,
6141    pub format: Option<Expression>,
6142}
6143
6144/// TO_TIMESTAMP function
6145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6146#[cfg_attr(feature = "bindings", derive(TS))]
6147pub struct ToTimestampFunc {
6148    pub this: Expression,
6149    pub format: Option<Expression>,
6150}
6151
6152/// IF function
6153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6154#[cfg_attr(feature = "bindings", derive(TS))]
6155pub struct IfFunc {
6156    pub condition: Expression,
6157    pub true_value: Expression,
6158    pub false_value: Option<Expression>,
6159    /// Original function name (IF, IFF, IIF) for round-trip preservation
6160    #[serde(skip_serializing_if = "Option::is_none", default)]
6161    pub original_name: Option<String>,
6162    /// Inferred data type from type annotation
6163    #[serde(default, skip_serializing_if = "Option::is_none")]
6164    pub inferred_type: Option<DataType>,
6165}
6166
6167/// NVL2 function
6168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6169#[cfg_attr(feature = "bindings", derive(TS))]
6170pub struct Nvl2Func {
6171    pub this: Expression,
6172    pub true_value: Expression,
6173    pub false_value: Expression,
6174    /// Inferred data type from type annotation
6175    #[serde(default, skip_serializing_if = "Option::is_none")]
6176    pub inferred_type: Option<DataType>,
6177}
6178
6179// ============================================================================
6180// Typed Aggregate Function types
6181// ============================================================================
6182
6183/// Generic aggregate function base type
6184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6185#[cfg_attr(feature = "bindings", derive(TS))]
6186pub struct AggFunc {
6187    pub this: Expression,
6188    pub distinct: bool,
6189    pub filter: Option<Expression>,
6190    pub order_by: Vec<Ordered>,
6191    /// Original function name (case-preserving) when parsed from SQL
6192    #[serde(skip_serializing_if = "Option::is_none", default)]
6193    pub name: Option<String>,
6194    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6195    #[serde(skip_serializing_if = "Option::is_none", default)]
6196    pub ignore_nulls: Option<bool>,
6197    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6198    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6199    #[serde(skip_serializing_if = "Option::is_none", default)]
6200    pub having_max: Option<(Box<Expression>, bool)>,
6201    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6202    #[serde(skip_serializing_if = "Option::is_none", default)]
6203    pub limit: Option<Box<Expression>>,
6204    /// Inferred data type from type annotation
6205    #[serde(default, skip_serializing_if = "Option::is_none")]
6206    pub inferred_type: Option<DataType>,
6207}
6208
6209/// COUNT function with optional star
6210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6211#[cfg_attr(feature = "bindings", derive(TS))]
6212pub struct CountFunc {
6213    pub this: Option<Expression>,
6214    pub star: bool,
6215    pub distinct: bool,
6216    pub filter: Option<Expression>,
6217    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6218    #[serde(default, skip_serializing_if = "Option::is_none")]
6219    pub ignore_nulls: Option<bool>,
6220    /// Original function name for case preservation (e.g., "count" or "COUNT")
6221    #[serde(default, skip_serializing_if = "Option::is_none")]
6222    pub original_name: Option<String>,
6223    /// Inferred data type from type annotation
6224    #[serde(default, skip_serializing_if = "Option::is_none")]
6225    pub inferred_type: Option<DataType>,
6226}
6227
6228/// GROUP_CONCAT function (MySQL style)
6229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6230#[cfg_attr(feature = "bindings", derive(TS))]
6231pub struct GroupConcatFunc {
6232    pub this: Expression,
6233    pub separator: Option<Expression>,
6234    pub order_by: Option<Vec<Ordered>>,
6235    pub distinct: bool,
6236    pub filter: Option<Expression>,
6237    /// Inferred data type from type annotation
6238    #[serde(default, skip_serializing_if = "Option::is_none")]
6239    pub inferred_type: Option<DataType>,
6240}
6241
6242/// STRING_AGG function (PostgreSQL/Standard SQL)
6243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6244#[cfg_attr(feature = "bindings", derive(TS))]
6245pub struct StringAggFunc {
6246    pub this: Expression,
6247    #[serde(default)]
6248    pub separator: Option<Expression>,
6249    #[serde(default)]
6250    pub order_by: Option<Vec<Ordered>>,
6251    #[serde(default)]
6252    pub distinct: bool,
6253    #[serde(default)]
6254    pub filter: Option<Expression>,
6255    /// BigQuery LIMIT inside STRING_AGG
6256    #[serde(default, skip_serializing_if = "Option::is_none")]
6257    pub limit: Option<Box<Expression>>,
6258    /// Inferred data type from type annotation
6259    #[serde(default, skip_serializing_if = "Option::is_none")]
6260    pub inferred_type: Option<DataType>,
6261}
6262
6263/// LISTAGG function (Oracle style)
6264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6265#[cfg_attr(feature = "bindings", derive(TS))]
6266pub struct ListAggFunc {
6267    pub this: Expression,
6268    pub separator: Option<Expression>,
6269    pub on_overflow: Option<ListAggOverflow>,
6270    pub order_by: Option<Vec<Ordered>>,
6271    pub distinct: bool,
6272    pub filter: Option<Expression>,
6273    /// Inferred data type from type annotation
6274    #[serde(default, skip_serializing_if = "Option::is_none")]
6275    pub inferred_type: Option<DataType>,
6276}
6277
6278/// LISTAGG ON OVERFLOW behavior
6279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6280#[cfg_attr(feature = "bindings", derive(TS))]
6281pub enum ListAggOverflow {
6282    Error,
6283    Truncate {
6284        filler: Option<Expression>,
6285        with_count: bool,
6286    },
6287}
6288
6289/// SUM_IF / COUNT_IF function
6290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6291#[cfg_attr(feature = "bindings", derive(TS))]
6292pub struct SumIfFunc {
6293    pub this: Expression,
6294    pub condition: Expression,
6295    pub filter: Option<Expression>,
6296    /// Inferred data type from type annotation
6297    #[serde(default, skip_serializing_if = "Option::is_none")]
6298    pub inferred_type: Option<DataType>,
6299}
6300
6301/// APPROX_PERCENTILE function
6302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6303#[cfg_attr(feature = "bindings", derive(TS))]
6304pub struct ApproxPercentileFunc {
6305    pub this: Expression,
6306    pub percentile: Expression,
6307    pub accuracy: Option<Expression>,
6308    pub filter: Option<Expression>,
6309}
6310
6311/// PERCENTILE_CONT / PERCENTILE_DISC function
6312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6313#[cfg_attr(feature = "bindings", derive(TS))]
6314pub struct PercentileFunc {
6315    pub this: Expression,
6316    pub percentile: Expression,
6317    pub order_by: Option<Vec<Ordered>>,
6318    pub filter: Option<Expression>,
6319}
6320
6321// ============================================================================
6322// Typed Window Function types
6323// ============================================================================
6324
6325/// ROW_NUMBER function (no arguments)
6326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6327#[cfg_attr(feature = "bindings", derive(TS))]
6328pub struct RowNumber;
6329
6330/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6332#[cfg_attr(feature = "bindings", derive(TS))]
6333pub struct Rank {
6334    /// DuckDB: RANK(ORDER BY col) - order by inside function
6335    #[serde(default, skip_serializing_if = "Option::is_none")]
6336    pub order_by: Option<Vec<Ordered>>,
6337    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6338    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6339    pub args: Vec<Expression>,
6340}
6341
6342/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6344#[cfg_attr(feature = "bindings", derive(TS))]
6345pub struct DenseRank {
6346    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6347    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6348    pub args: Vec<Expression>,
6349}
6350
6351/// NTILE function (DuckDB allows ORDER BY inside)
6352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6353#[cfg_attr(feature = "bindings", derive(TS))]
6354pub struct NTileFunc {
6355    /// num_buckets is optional to support Databricks NTILE() without arguments
6356    #[serde(default, skip_serializing_if = "Option::is_none")]
6357    pub num_buckets: Option<Expression>,
6358    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6359    #[serde(default, skip_serializing_if = "Option::is_none")]
6360    pub order_by: Option<Vec<Ordered>>,
6361}
6362
6363/// LEAD / LAG function
6364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6365#[cfg_attr(feature = "bindings", derive(TS))]
6366pub struct LeadLagFunc {
6367    pub this: Expression,
6368    pub offset: Option<Expression>,
6369    pub default: Option<Expression>,
6370    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6371    #[serde(default, skip_serializing_if = "Option::is_none")]
6372    pub ignore_nulls: Option<bool>,
6373}
6374
6375/// FIRST_VALUE / LAST_VALUE function
6376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6377#[cfg_attr(feature = "bindings", derive(TS))]
6378pub struct ValueFunc {
6379    pub this: Expression,
6380    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6381    #[serde(default, skip_serializing_if = "Option::is_none")]
6382    pub ignore_nulls: Option<bool>,
6383    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6384    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6385    pub order_by: Vec<Ordered>,
6386}
6387
6388/// NTH_VALUE function
6389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6390#[cfg_attr(feature = "bindings", derive(TS))]
6391pub struct NthValueFunc {
6392    pub this: Expression,
6393    pub offset: Expression,
6394    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6395    #[serde(default, skip_serializing_if = "Option::is_none")]
6396    pub ignore_nulls: Option<bool>,
6397    /// Snowflake FROM FIRST / FROM LAST clause
6398    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6399    #[serde(default, skip_serializing_if = "Option::is_none")]
6400    pub from_first: Option<bool>,
6401}
6402
6403/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6405#[cfg_attr(feature = "bindings", derive(TS))]
6406pub struct PercentRank {
6407    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6408    #[serde(default, skip_serializing_if = "Option::is_none")]
6409    pub order_by: Option<Vec<Ordered>>,
6410    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6411    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6412    pub args: Vec<Expression>,
6413}
6414
6415/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6417#[cfg_attr(feature = "bindings", derive(TS))]
6418pub struct CumeDist {
6419    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6420    #[serde(default, skip_serializing_if = "Option::is_none")]
6421    pub order_by: Option<Vec<Ordered>>,
6422    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6423    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6424    pub args: Vec<Expression>,
6425}
6426
6427// ============================================================================
6428// Additional String Function types
6429// ============================================================================
6430
6431/// POSITION/INSTR function
6432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6433#[cfg_attr(feature = "bindings", derive(TS))]
6434pub struct PositionFunc {
6435    pub substring: Expression,
6436    pub string: Expression,
6437    pub start: Option<Expression>,
6438}
6439
6440// ============================================================================
6441// Additional Math Function types
6442// ============================================================================
6443
6444/// RANDOM function (no arguments)
6445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6446#[cfg_attr(feature = "bindings", derive(TS))]
6447pub struct Random;
6448
6449/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6451#[cfg_attr(feature = "bindings", derive(TS))]
6452pub struct Rand {
6453    pub seed: Option<Box<Expression>>,
6454    /// Teradata RANDOM lower bound
6455    #[serde(default)]
6456    pub lower: Option<Box<Expression>>,
6457    /// Teradata RANDOM upper bound
6458    #[serde(default)]
6459    pub upper: Option<Box<Expression>>,
6460}
6461
6462/// TRUNCATE / TRUNC function
6463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6464#[cfg_attr(feature = "bindings", derive(TS))]
6465pub struct TruncateFunc {
6466    pub this: Expression,
6467    pub decimals: Option<Expression>,
6468}
6469
6470/// PI function (no arguments)
6471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6472#[cfg_attr(feature = "bindings", derive(TS))]
6473pub struct Pi;
6474
6475// ============================================================================
6476// Control Flow Function types
6477// ============================================================================
6478
6479/// DECODE function (Oracle style)
6480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6481#[cfg_attr(feature = "bindings", derive(TS))]
6482pub struct DecodeFunc {
6483    pub this: Expression,
6484    pub search_results: Vec<(Expression, Expression)>,
6485    pub default: Option<Expression>,
6486}
6487
6488// ============================================================================
6489// Additional Date/Time Function types
6490// ============================================================================
6491
6492/// DATE_FORMAT / FORMAT_DATE function
6493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6494#[cfg_attr(feature = "bindings", derive(TS))]
6495pub struct DateFormatFunc {
6496    pub this: Expression,
6497    pub format: Expression,
6498}
6499
6500/// FROM_UNIXTIME function
6501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6502#[cfg_attr(feature = "bindings", derive(TS))]
6503pub struct FromUnixtimeFunc {
6504    pub this: Expression,
6505    pub format: Option<Expression>,
6506}
6507
6508/// UNIX_TIMESTAMP function
6509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6510#[cfg_attr(feature = "bindings", derive(TS))]
6511pub struct UnixTimestampFunc {
6512    pub this: Option<Expression>,
6513    pub format: Option<Expression>,
6514}
6515
6516/// MAKE_DATE function
6517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6518#[cfg_attr(feature = "bindings", derive(TS))]
6519pub struct MakeDateFunc {
6520    pub year: Expression,
6521    pub month: Expression,
6522    pub day: Expression,
6523}
6524
6525/// MAKE_TIMESTAMP function
6526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6527#[cfg_attr(feature = "bindings", derive(TS))]
6528pub struct MakeTimestampFunc {
6529    pub year: Expression,
6530    pub month: Expression,
6531    pub day: Expression,
6532    pub hour: Expression,
6533    pub minute: Expression,
6534    pub second: Expression,
6535    pub timezone: Option<Expression>,
6536}
6537
6538/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6540#[cfg_attr(feature = "bindings", derive(TS))]
6541pub struct LastDayFunc {
6542    pub this: Expression,
6543    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6544    #[serde(skip_serializing_if = "Option::is_none", default)]
6545    pub unit: Option<DateTimeField>,
6546}
6547
6548// ============================================================================
6549// Array Function types
6550// ============================================================================
6551
6552/// ARRAY constructor
6553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6554#[cfg_attr(feature = "bindings", derive(TS))]
6555pub struct ArrayConstructor {
6556    pub expressions: Vec<Expression>,
6557    pub bracket_notation: bool,
6558    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6559    pub use_list_keyword: bool,
6560}
6561
6562/// ARRAY_SORT function
6563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6564#[cfg_attr(feature = "bindings", derive(TS))]
6565pub struct ArraySortFunc {
6566    pub this: Expression,
6567    pub comparator: Option<Expression>,
6568    pub desc: bool,
6569    pub nulls_first: Option<bool>,
6570}
6571
6572/// ARRAY_JOIN / ARRAY_TO_STRING function
6573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6574#[cfg_attr(feature = "bindings", derive(TS))]
6575pub struct ArrayJoinFunc {
6576    pub this: Expression,
6577    pub separator: Expression,
6578    pub null_replacement: Option<Expression>,
6579}
6580
6581/// UNNEST function
6582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6583#[cfg_attr(feature = "bindings", derive(TS))]
6584pub struct UnnestFunc {
6585    pub this: Expression,
6586    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6587    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6588    pub expressions: Vec<Expression>,
6589    pub with_ordinality: bool,
6590    pub alias: Option<Identifier>,
6591    /// BigQuery: offset alias for WITH OFFSET AS <name>
6592    #[serde(default, skip_serializing_if = "Option::is_none")]
6593    pub offset_alias: Option<Identifier>,
6594}
6595
6596/// ARRAY_FILTER function (with lambda)
6597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6598#[cfg_attr(feature = "bindings", derive(TS))]
6599pub struct ArrayFilterFunc {
6600    pub this: Expression,
6601    pub filter: Expression,
6602}
6603
6604/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6606#[cfg_attr(feature = "bindings", derive(TS))]
6607pub struct ArrayTransformFunc {
6608    pub this: Expression,
6609    pub transform: Expression,
6610}
6611
6612/// SEQUENCE / GENERATE_SERIES function
6613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6614#[cfg_attr(feature = "bindings", derive(TS))]
6615pub struct SequenceFunc {
6616    pub start: Expression,
6617    pub stop: Expression,
6618    pub step: Option<Expression>,
6619}
6620
6621// ============================================================================
6622// Struct Function types
6623// ============================================================================
6624
6625/// STRUCT constructor
6626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6627#[cfg_attr(feature = "bindings", derive(TS))]
6628pub struct StructConstructor {
6629    pub fields: Vec<(Option<Identifier>, Expression)>,
6630}
6631
6632/// STRUCT_EXTRACT function
6633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6634#[cfg_attr(feature = "bindings", derive(TS))]
6635pub struct StructExtractFunc {
6636    pub this: Expression,
6637    pub field: Identifier,
6638}
6639
6640/// NAMED_STRUCT function
6641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6642#[cfg_attr(feature = "bindings", derive(TS))]
6643pub struct NamedStructFunc {
6644    pub pairs: Vec<(Expression, Expression)>,
6645}
6646
6647// ============================================================================
6648// Map Function types
6649// ============================================================================
6650
6651/// MAP constructor
6652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6653#[cfg_attr(feature = "bindings", derive(TS))]
6654pub struct MapConstructor {
6655    pub keys: Vec<Expression>,
6656    pub values: Vec<Expression>,
6657    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6658    #[serde(default)]
6659    pub curly_brace_syntax: bool,
6660    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6661    #[serde(default)]
6662    pub with_map_keyword: bool,
6663}
6664
6665/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6667#[cfg_attr(feature = "bindings", derive(TS))]
6668pub struct TransformFunc {
6669    pub this: Expression,
6670    pub transform: Expression,
6671}
6672
6673/// Function call with EMITS clause (Exasol)
6674/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6676#[cfg_attr(feature = "bindings", derive(TS))]
6677pub struct FunctionEmits {
6678    /// The function call expression
6679    pub this: Expression,
6680    /// The EMITS schema definition
6681    pub emits: Expression,
6682}
6683
6684// ============================================================================
6685// JSON Function types
6686// ============================================================================
6687
6688/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6690#[cfg_attr(feature = "bindings", derive(TS))]
6691pub struct JsonExtractFunc {
6692    pub this: Expression,
6693    pub path: Expression,
6694    pub returning: Option<DataType>,
6695    /// True if parsed from -> or ->> operator syntax
6696    #[serde(default)]
6697    pub arrow_syntax: bool,
6698    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6699    #[serde(default)]
6700    pub hash_arrow_syntax: bool,
6701    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6702    #[serde(default)]
6703    pub wrapper_option: Option<String>,
6704    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6705    #[serde(default)]
6706    pub quotes_option: Option<String>,
6707    /// ON SCALAR STRING flag
6708    #[serde(default)]
6709    pub on_scalar_string: bool,
6710    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6711    #[serde(default)]
6712    pub on_error: Option<String>,
6713}
6714
6715/// JSON path extraction
6716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6717#[cfg_attr(feature = "bindings", derive(TS))]
6718pub struct JsonPathFunc {
6719    pub this: Expression,
6720    pub paths: Vec<Expression>,
6721}
6722
6723/// JSON_OBJECT function
6724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6725#[cfg_attr(feature = "bindings", derive(TS))]
6726pub struct JsonObjectFunc {
6727    pub pairs: Vec<(Expression, Expression)>,
6728    pub null_handling: Option<JsonNullHandling>,
6729    #[serde(default)]
6730    pub with_unique_keys: bool,
6731    #[serde(default)]
6732    pub returning_type: Option<DataType>,
6733    #[serde(default)]
6734    pub format_json: bool,
6735    #[serde(default)]
6736    pub encoding: Option<String>,
6737    /// For JSON_OBJECT(*) syntax
6738    #[serde(default)]
6739    pub star: bool,
6740}
6741
6742/// JSON null handling options
6743#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6744#[cfg_attr(feature = "bindings", derive(TS))]
6745pub enum JsonNullHandling {
6746    NullOnNull,
6747    AbsentOnNull,
6748}
6749
6750/// JSON_SET / JSON_INSERT function
6751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6752#[cfg_attr(feature = "bindings", derive(TS))]
6753pub struct JsonModifyFunc {
6754    pub this: Expression,
6755    pub path_values: Vec<(Expression, Expression)>,
6756}
6757
6758/// JSON_ARRAYAGG function
6759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6760#[cfg_attr(feature = "bindings", derive(TS))]
6761pub struct JsonArrayAggFunc {
6762    pub this: Expression,
6763    pub order_by: Option<Vec<Ordered>>,
6764    pub null_handling: Option<JsonNullHandling>,
6765    pub filter: Option<Expression>,
6766}
6767
6768/// JSON_OBJECTAGG function
6769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6770#[cfg_attr(feature = "bindings", derive(TS))]
6771pub struct JsonObjectAggFunc {
6772    pub key: Expression,
6773    pub value: Expression,
6774    pub null_handling: Option<JsonNullHandling>,
6775    pub filter: Option<Expression>,
6776}
6777
6778// ============================================================================
6779// Type Casting Function types
6780// ============================================================================
6781
6782/// CONVERT function (SQL Server style)
6783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6784#[cfg_attr(feature = "bindings", derive(TS))]
6785pub struct ConvertFunc {
6786    pub this: Expression,
6787    pub to: DataType,
6788    pub style: Option<Expression>,
6789}
6790
6791// ============================================================================
6792// Additional Expression types
6793// ============================================================================
6794
6795/// Lambda expression
6796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6797#[cfg_attr(feature = "bindings", derive(TS))]
6798pub struct LambdaExpr {
6799    pub parameters: Vec<Identifier>,
6800    pub body: Expression,
6801    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
6802    #[serde(default)]
6803    pub colon: bool,
6804    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
6805    /// Maps parameter index to data type
6806    #[serde(default)]
6807    pub parameter_types: Vec<Option<DataType>>,
6808}
6809
6810/// Parameter (parameterized queries)
6811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6812#[cfg_attr(feature = "bindings", derive(TS))]
6813pub struct Parameter {
6814    pub name: Option<String>,
6815    pub index: Option<u32>,
6816    pub style: ParameterStyle,
6817    /// Whether the name was quoted (e.g., @"x" vs @x)
6818    #[serde(default)]
6819    pub quoted: bool,
6820    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
6821    #[serde(default)]
6822    pub string_quoted: bool,
6823    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
6824    #[serde(default)]
6825    pub expression: Option<String>,
6826}
6827
6828/// Parameter placeholder styles
6829#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6830#[cfg_attr(feature = "bindings", derive(TS))]
6831pub enum ParameterStyle {
6832    Question,     // ?
6833    Dollar,       // $1, $2
6834    DollarBrace,  // ${name} (Databricks, Hive template variables)
6835    Brace,        // {name} (Spark/Databricks widget/template variables)
6836    Colon,        // :name
6837    At,           // @name
6838    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
6839    DoubleDollar, // $$name
6840    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
6841}
6842
6843/// Placeholder expression
6844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6845#[cfg_attr(feature = "bindings", derive(TS))]
6846pub struct Placeholder {
6847    pub index: Option<u32>,
6848}
6849
6850/// Named argument in function call: name => value or name := value
6851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6852#[cfg_attr(feature = "bindings", derive(TS))]
6853pub struct NamedArgument {
6854    pub name: Identifier,
6855    pub value: Expression,
6856    /// The separator used: `=>`, `:=`, or `=`
6857    pub separator: NamedArgSeparator,
6858}
6859
6860/// Separator style for named arguments
6861#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6862#[cfg_attr(feature = "bindings", derive(TS))]
6863pub enum NamedArgSeparator {
6864    /// `=>` (standard SQL, Snowflake, BigQuery)
6865    DArrow,
6866    /// `:=` (Oracle, MySQL)
6867    ColonEq,
6868    /// `=` (simple equals, some dialects)
6869    Eq,
6870}
6871
6872/// TABLE ref or MODEL ref used as a function argument (BigQuery)
6873/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
6874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6875#[cfg_attr(feature = "bindings", derive(TS))]
6876pub struct TableArgument {
6877    /// The keyword prefix: "TABLE" or "MODEL"
6878    pub prefix: String,
6879    /// The table/model reference expression
6880    pub this: Expression,
6881}
6882
6883/// SQL Comment preservation
6884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6885#[cfg_attr(feature = "bindings", derive(TS))]
6886pub struct SqlComment {
6887    pub text: String,
6888    pub is_block: bool,
6889}
6890
6891// ============================================================================
6892// Additional Predicate types
6893// ============================================================================
6894
6895/// SIMILAR TO expression
6896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6897#[cfg_attr(feature = "bindings", derive(TS))]
6898pub struct SimilarToExpr {
6899    pub this: Expression,
6900    pub pattern: Expression,
6901    pub escape: Option<Expression>,
6902    pub not: bool,
6903}
6904
6905/// ANY / ALL quantified expression
6906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6907#[cfg_attr(feature = "bindings", derive(TS))]
6908pub struct QuantifiedExpr {
6909    pub this: Expression,
6910    pub subquery: Expression,
6911    pub op: Option<QuantifiedOp>,
6912}
6913
6914/// Comparison operator for quantified expressions
6915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6916#[cfg_attr(feature = "bindings", derive(TS))]
6917pub enum QuantifiedOp {
6918    Eq,
6919    Neq,
6920    Lt,
6921    Lte,
6922    Gt,
6923    Gte,
6924}
6925
6926/// OVERLAPS expression
6927/// Supports two forms:
6928/// 1. Simple binary: a OVERLAPS b (this, expression are set)
6929/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
6930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6931#[cfg_attr(feature = "bindings", derive(TS))]
6932pub struct OverlapsExpr {
6933    /// Left operand for simple binary form
6934    #[serde(skip_serializing_if = "Option::is_none")]
6935    pub this: Option<Expression>,
6936    /// Right operand for simple binary form
6937    #[serde(skip_serializing_if = "Option::is_none")]
6938    pub expression: Option<Expression>,
6939    /// Left range start for full ANSI form
6940    #[serde(skip_serializing_if = "Option::is_none")]
6941    pub left_start: Option<Expression>,
6942    /// Left range end for full ANSI form
6943    #[serde(skip_serializing_if = "Option::is_none")]
6944    pub left_end: Option<Expression>,
6945    /// Right range start for full ANSI form
6946    #[serde(skip_serializing_if = "Option::is_none")]
6947    pub right_start: Option<Expression>,
6948    /// Right range end for full ANSI form
6949    #[serde(skip_serializing_if = "Option::is_none")]
6950    pub right_end: Option<Expression>,
6951}
6952
6953// ============================================================================
6954// Array/Struct/Map access
6955// ============================================================================
6956
6957/// Subscript access (array[index] or map[key])
6958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6959#[cfg_attr(feature = "bindings", derive(TS))]
6960pub struct Subscript {
6961    pub this: Expression,
6962    pub index: Expression,
6963}
6964
6965/// Dot access (struct.field)
6966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6967#[cfg_attr(feature = "bindings", derive(TS))]
6968pub struct DotAccess {
6969    pub this: Expression,
6970    pub field: Identifier,
6971}
6972
6973/// Method call (expr.method(args))
6974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6975#[cfg_attr(feature = "bindings", derive(TS))]
6976pub struct MethodCall {
6977    pub this: Expression,
6978    pub method: Identifier,
6979    pub args: Vec<Expression>,
6980}
6981
6982/// Array slice (array[start:end])
6983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6984#[cfg_attr(feature = "bindings", derive(TS))]
6985pub struct ArraySlice {
6986    pub this: Expression,
6987    pub start: Option<Expression>,
6988    pub end: Option<Expression>,
6989}
6990
6991// ============================================================================
6992// DDL (Data Definition Language) Statements
6993// ============================================================================
6994
6995/// ON COMMIT behavior for temporary tables
6996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6997#[cfg_attr(feature = "bindings", derive(TS))]
6998pub enum OnCommit {
6999    /// ON COMMIT PRESERVE ROWS
7000    PreserveRows,
7001    /// ON COMMIT DELETE ROWS
7002    DeleteRows,
7003}
7004
7005/// CREATE TABLE statement
7006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7007#[cfg_attr(feature = "bindings", derive(TS))]
7008pub struct CreateTable {
7009    pub name: TableRef,
7010    /// ClickHouse: ON CLUSTER clause for distributed DDL
7011    #[serde(default, skip_serializing_if = "Option::is_none")]
7012    pub on_cluster: Option<OnCluster>,
7013    pub columns: Vec<ColumnDef>,
7014    pub constraints: Vec<TableConstraint>,
7015    pub if_not_exists: bool,
7016    pub temporary: bool,
7017    pub or_replace: bool,
7018    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7019    #[serde(default, skip_serializing_if = "Option::is_none")]
7020    pub table_modifier: Option<String>,
7021    pub as_select: Option<Expression>,
7022    /// Whether the AS SELECT was wrapped in parentheses
7023    #[serde(default)]
7024    pub as_select_parenthesized: bool,
7025    /// ON COMMIT behavior for temporary tables
7026    #[serde(default)]
7027    pub on_commit: Option<OnCommit>,
7028    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7029    #[serde(default)]
7030    pub clone_source: Option<TableRef>,
7031    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7032    #[serde(default, skip_serializing_if = "Option::is_none")]
7033    pub clone_at_clause: Option<Expression>,
7034    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7035    #[serde(default)]
7036    pub is_copy: bool,
7037    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7038    #[serde(default)]
7039    pub shallow_clone: bool,
7040    /// Leading comments before the statement
7041    #[serde(default)]
7042    pub leading_comments: Vec<String>,
7043    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7044    #[serde(default)]
7045    pub with_properties: Vec<(String, String)>,
7046    /// Teradata: table options after name before columns (comma-separated)
7047    #[serde(default)]
7048    pub teradata_post_name_options: Vec<String>,
7049    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7050    #[serde(default)]
7051    pub with_data: Option<bool>,
7052    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7053    #[serde(default)]
7054    pub with_statistics: Option<bool>,
7055    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7056    #[serde(default)]
7057    pub teradata_indexes: Vec<TeradataIndex>,
7058    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7059    #[serde(default)]
7060    pub with_cte: Option<With>,
7061    /// Table properties like DEFAULT COLLATE (BigQuery)
7062    #[serde(default)]
7063    pub properties: Vec<Expression>,
7064    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7065    #[serde(default, skip_serializing_if = "Option::is_none")]
7066    pub partition_of: Option<Expression>,
7067    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7068    #[serde(default)]
7069    pub post_table_properties: Vec<Expression>,
7070    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7071    #[serde(default)]
7072    pub mysql_table_options: Vec<(String, String)>,
7073    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7074    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7075    pub inherits: Vec<TableRef>,
7076    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7077    #[serde(default, skip_serializing_if = "Option::is_none")]
7078    pub on_property: Option<OnProperty>,
7079    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7080    #[serde(default)]
7081    pub copy_grants: bool,
7082    /// Snowflake: USING TEMPLATE expression for schema inference
7083    #[serde(default, skip_serializing_if = "Option::is_none")]
7084    pub using_template: Option<Box<Expression>>,
7085    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7086    #[serde(default, skip_serializing_if = "Option::is_none")]
7087    pub rollup: Option<RollupProperty>,
7088}
7089
7090/// Teradata index specification for CREATE TABLE
7091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7092#[cfg_attr(feature = "bindings", derive(TS))]
7093pub struct TeradataIndex {
7094    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7095    pub kind: TeradataIndexKind,
7096    /// Optional index name
7097    pub name: Option<String>,
7098    /// Optional column list
7099    pub columns: Vec<String>,
7100}
7101
7102/// Kind of Teradata index
7103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7104#[cfg_attr(feature = "bindings", derive(TS))]
7105pub enum TeradataIndexKind {
7106    /// NO PRIMARY INDEX
7107    NoPrimary,
7108    /// PRIMARY INDEX
7109    Primary,
7110    /// PRIMARY AMP INDEX
7111    PrimaryAmp,
7112    /// UNIQUE INDEX
7113    Unique,
7114    /// UNIQUE PRIMARY INDEX
7115    UniquePrimary,
7116    /// INDEX (secondary, non-primary)
7117    Secondary,
7118}
7119
7120impl CreateTable {
7121    pub fn new(name: impl Into<String>) -> Self {
7122        Self {
7123            name: TableRef::new(name),
7124            on_cluster: None,
7125            columns: Vec::new(),
7126            constraints: Vec::new(),
7127            if_not_exists: false,
7128            temporary: false,
7129            or_replace: false,
7130            table_modifier: None,
7131            as_select: None,
7132            as_select_parenthesized: false,
7133            on_commit: None,
7134            clone_source: None,
7135            clone_at_clause: None,
7136            shallow_clone: false,
7137            is_copy: false,
7138            leading_comments: Vec::new(),
7139            with_properties: Vec::new(),
7140            teradata_post_name_options: Vec::new(),
7141            with_data: None,
7142            with_statistics: None,
7143            teradata_indexes: Vec::new(),
7144            with_cte: None,
7145            properties: Vec::new(),
7146            partition_of: None,
7147            post_table_properties: Vec::new(),
7148            mysql_table_options: Vec::new(),
7149            inherits: Vec::new(),
7150            on_property: None,
7151            copy_grants: false,
7152            using_template: None,
7153            rollup: None,
7154        }
7155    }
7156}
7157
7158/// Sort order for PRIMARY KEY ASC/DESC
7159#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7160#[cfg_attr(feature = "bindings", derive(TS))]
7161pub enum SortOrder {
7162    Asc,
7163    Desc,
7164}
7165
7166/// Type of column constraint for tracking order
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub enum ConstraintType {
7170    NotNull,
7171    Null,
7172    PrimaryKey,
7173    Unique,
7174    Default,
7175    AutoIncrement,
7176    Collate,
7177    Comment,
7178    References,
7179    Check,
7180    GeneratedAsIdentity,
7181    /// Snowflake: TAG (key='value', ...)
7182    Tags,
7183    /// Computed/generated column
7184    ComputedColumn,
7185    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7186    GeneratedAsRow,
7187    /// MySQL: ON UPDATE expression
7188    OnUpdate,
7189    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7190    Path,
7191    /// Redshift: ENCODE encoding_type
7192    Encode,
7193}
7194
7195/// Column definition in CREATE TABLE
7196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7197#[cfg_attr(feature = "bindings", derive(TS))]
7198pub struct ColumnDef {
7199    pub name: Identifier,
7200    pub data_type: DataType,
7201    pub nullable: Option<bool>,
7202    pub default: Option<Expression>,
7203    pub primary_key: bool,
7204    /// Sort order for PRIMARY KEY (ASC/DESC)
7205    #[serde(default)]
7206    pub primary_key_order: Option<SortOrder>,
7207    pub unique: bool,
7208    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7209    #[serde(default)]
7210    pub unique_nulls_not_distinct: bool,
7211    pub auto_increment: bool,
7212    pub comment: Option<String>,
7213    pub constraints: Vec<ColumnConstraint>,
7214    /// Track original order of constraints for accurate regeneration
7215    #[serde(default)]
7216    pub constraint_order: Vec<ConstraintType>,
7217    /// Teradata: FORMAT 'pattern'
7218    #[serde(default)]
7219    pub format: Option<String>,
7220    /// Teradata: TITLE 'title'
7221    #[serde(default)]
7222    pub title: Option<String>,
7223    /// Teradata: INLINE LENGTH n
7224    #[serde(default)]
7225    pub inline_length: Option<u64>,
7226    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7227    #[serde(default)]
7228    pub compress: Option<Vec<Expression>>,
7229    /// Teradata: CHARACTER SET name
7230    #[serde(default)]
7231    pub character_set: Option<String>,
7232    /// Teradata: UPPERCASE
7233    #[serde(default)]
7234    pub uppercase: bool,
7235    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7236    #[serde(default)]
7237    pub casespecific: Option<bool>,
7238    /// Snowflake: AUTOINCREMENT START value
7239    #[serde(default)]
7240    pub auto_increment_start: Option<Box<Expression>>,
7241    /// Snowflake: AUTOINCREMENT INCREMENT value
7242    #[serde(default)]
7243    pub auto_increment_increment: Option<Box<Expression>>,
7244    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7245    #[serde(default)]
7246    pub auto_increment_order: Option<bool>,
7247    /// MySQL: UNSIGNED modifier
7248    #[serde(default)]
7249    pub unsigned: bool,
7250    /// MySQL: ZEROFILL modifier
7251    #[serde(default)]
7252    pub zerofill: bool,
7253    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7254    #[serde(default, skip_serializing_if = "Option::is_none")]
7255    pub on_update: Option<Expression>,
7256    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7257    #[serde(default, skip_serializing_if = "Option::is_none")]
7258    pub unique_constraint_name: Option<String>,
7259    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7260    #[serde(default, skip_serializing_if = "Option::is_none")]
7261    pub not_null_constraint_name: Option<String>,
7262    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7263    #[serde(default, skip_serializing_if = "Option::is_none")]
7264    pub primary_key_constraint_name: Option<String>,
7265    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7266    #[serde(default, skip_serializing_if = "Option::is_none")]
7267    pub check_constraint_name: Option<String>,
7268    /// BigQuery: OPTIONS (key=value, ...) on column
7269    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7270    pub options: Vec<Expression>,
7271    /// SQLite: Column definition without explicit type
7272    #[serde(default)]
7273    pub no_type: bool,
7274    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7275    #[serde(default, skip_serializing_if = "Option::is_none")]
7276    pub encoding: Option<String>,
7277    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7278    #[serde(default, skip_serializing_if = "Option::is_none")]
7279    pub codec: Option<String>,
7280    /// ClickHouse: EPHEMERAL [expr] modifier
7281    #[serde(default, skip_serializing_if = "Option::is_none")]
7282    pub ephemeral: Option<Option<Box<Expression>>>,
7283    /// ClickHouse: MATERIALIZED expr modifier
7284    #[serde(default, skip_serializing_if = "Option::is_none")]
7285    pub materialized_expr: Option<Box<Expression>>,
7286    /// ClickHouse: ALIAS expr modifier
7287    #[serde(default, skip_serializing_if = "Option::is_none")]
7288    pub alias_expr: Option<Box<Expression>>,
7289    /// ClickHouse: TTL expr modifier on columns
7290    #[serde(default, skip_serializing_if = "Option::is_none")]
7291    pub ttl_expr: Option<Box<Expression>>,
7292    /// TSQL: NOT FOR REPLICATION
7293    #[serde(default)]
7294    pub not_for_replication: bool,
7295}
7296
7297impl ColumnDef {
7298    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7299        Self {
7300            name: Identifier::new(name),
7301            data_type,
7302            nullable: None,
7303            default: None,
7304            primary_key: false,
7305            primary_key_order: None,
7306            unique: false,
7307            unique_nulls_not_distinct: false,
7308            auto_increment: false,
7309            comment: None,
7310            constraints: Vec::new(),
7311            constraint_order: Vec::new(),
7312            format: None,
7313            title: None,
7314            inline_length: None,
7315            compress: None,
7316            character_set: None,
7317            uppercase: false,
7318            casespecific: None,
7319            auto_increment_start: None,
7320            auto_increment_increment: None,
7321            auto_increment_order: None,
7322            unsigned: false,
7323            zerofill: false,
7324            on_update: None,
7325            unique_constraint_name: None,
7326            not_null_constraint_name: None,
7327            primary_key_constraint_name: None,
7328            check_constraint_name: None,
7329            options: Vec::new(),
7330            no_type: false,
7331            encoding: None,
7332            codec: None,
7333            ephemeral: None,
7334            materialized_expr: None,
7335            alias_expr: None,
7336            ttl_expr: None,
7337            not_for_replication: false,
7338        }
7339    }
7340}
7341
7342/// Column-level constraint
7343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7344#[cfg_attr(feature = "bindings", derive(TS))]
7345pub enum ColumnConstraint {
7346    NotNull,
7347    Null,
7348    Unique,
7349    PrimaryKey,
7350    Default(Expression),
7351    Check(Expression),
7352    References(ForeignKeyRef),
7353    GeneratedAsIdentity(GeneratedAsIdentity),
7354    Collate(Identifier),
7355    Comment(String),
7356    /// Snowflake: TAG (key='value', ...)
7357    Tags(Tags),
7358    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7359    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7360    ComputedColumn(ComputedColumn),
7361    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7362    GeneratedAsRow(GeneratedAsRow),
7363    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7364    Path(Expression),
7365}
7366
7367/// Computed/generated column constraint
7368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7369#[cfg_attr(feature = "bindings", derive(TS))]
7370pub struct ComputedColumn {
7371    /// The expression that computes the column value
7372    pub expression: Box<Expression>,
7373    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7374    #[serde(default)]
7375    pub persisted: bool,
7376    /// NOT NULL (TSQL computed columns)
7377    #[serde(default)]
7378    pub not_null: bool,
7379    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7380    /// When None, defaults to dialect-appropriate output
7381    #[serde(default)]
7382    pub persistence_kind: Option<String>,
7383    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7384    #[serde(default, skip_serializing_if = "Option::is_none")]
7385    pub data_type: Option<DataType>,
7386}
7387
7388/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7390#[cfg_attr(feature = "bindings", derive(TS))]
7391pub struct GeneratedAsRow {
7392    /// true = ROW START, false = ROW END
7393    pub start: bool,
7394    /// HIDDEN modifier
7395    #[serde(default)]
7396    pub hidden: bool,
7397}
7398
7399/// Generated identity column constraint
7400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7401#[cfg_attr(feature = "bindings", derive(TS))]
7402pub struct GeneratedAsIdentity {
7403    /// True for ALWAYS, False for BY DEFAULT
7404    pub always: bool,
7405    /// ON NULL (only valid with BY DEFAULT)
7406    pub on_null: bool,
7407    /// START WITH value
7408    pub start: Option<Box<Expression>>,
7409    /// INCREMENT BY value
7410    pub increment: Option<Box<Expression>>,
7411    /// MINVALUE
7412    pub minvalue: Option<Box<Expression>>,
7413    /// MAXVALUE
7414    pub maxvalue: Option<Box<Expression>>,
7415    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7416    pub cycle: Option<bool>,
7417}
7418
7419/// Constraint modifiers (shared between table-level constraints)
7420#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7421#[cfg_attr(feature = "bindings", derive(TS))]
7422pub struct ConstraintModifiers {
7423    /// ENFORCED / NOT ENFORCED
7424    pub enforced: Option<bool>,
7425    /// DEFERRABLE / NOT DEFERRABLE
7426    pub deferrable: Option<bool>,
7427    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7428    pub initially_deferred: Option<bool>,
7429    /// NORELY (Oracle)
7430    pub norely: bool,
7431    /// RELY (Oracle)
7432    pub rely: bool,
7433    /// USING index type (MySQL): BTREE or HASH
7434    #[serde(default)]
7435    pub using: Option<String>,
7436    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7437    #[serde(default)]
7438    pub using_before_columns: bool,
7439    /// MySQL index COMMENT 'text'
7440    #[serde(default, skip_serializing_if = "Option::is_none")]
7441    pub comment: Option<String>,
7442    /// MySQL index VISIBLE/INVISIBLE
7443    #[serde(default, skip_serializing_if = "Option::is_none")]
7444    pub visible: Option<bool>,
7445    /// MySQL ENGINE_ATTRIBUTE = 'value'
7446    #[serde(default, skip_serializing_if = "Option::is_none")]
7447    pub engine_attribute: Option<String>,
7448    /// MySQL WITH PARSER name
7449    #[serde(default, skip_serializing_if = "Option::is_none")]
7450    pub with_parser: Option<String>,
7451    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7452    #[serde(default)]
7453    pub not_valid: bool,
7454    /// TSQL CLUSTERED/NONCLUSTERED modifier
7455    #[serde(default, skip_serializing_if = "Option::is_none")]
7456    pub clustered: Option<String>,
7457    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7458    #[serde(default, skip_serializing_if = "Option::is_none")]
7459    pub on_conflict: Option<String>,
7460    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7461    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7462    pub with_options: Vec<(String, String)>,
7463    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7464    #[serde(default, skip_serializing_if = "Option::is_none")]
7465    pub on_filegroup: Option<Identifier>,
7466}
7467
7468/// Table-level constraint
7469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7470#[cfg_attr(feature = "bindings", derive(TS))]
7471pub enum TableConstraint {
7472    PrimaryKey {
7473        name: Option<Identifier>,
7474        columns: Vec<Identifier>,
7475        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7476        #[serde(default)]
7477        include_columns: Vec<Identifier>,
7478        #[serde(default)]
7479        modifiers: ConstraintModifiers,
7480        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7481        #[serde(default)]
7482        has_constraint_keyword: bool,
7483    },
7484    Unique {
7485        name: Option<Identifier>,
7486        columns: Vec<Identifier>,
7487        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7488        #[serde(default)]
7489        columns_parenthesized: bool,
7490        #[serde(default)]
7491        modifiers: ConstraintModifiers,
7492        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7493        #[serde(default)]
7494        has_constraint_keyword: bool,
7495        /// PostgreSQL 15+: NULLS NOT DISTINCT
7496        #[serde(default)]
7497        nulls_not_distinct: bool,
7498    },
7499    ForeignKey {
7500        name: Option<Identifier>,
7501        columns: Vec<Identifier>,
7502        #[serde(default)]
7503        references: Option<ForeignKeyRef>,
7504        /// ON DELETE action when REFERENCES is absent
7505        #[serde(default)]
7506        on_delete: Option<ReferentialAction>,
7507        /// ON UPDATE action when REFERENCES is absent
7508        #[serde(default)]
7509        on_update: Option<ReferentialAction>,
7510        #[serde(default)]
7511        modifiers: ConstraintModifiers,
7512    },
7513    Check {
7514        name: Option<Identifier>,
7515        expression: Expression,
7516        #[serde(default)]
7517        modifiers: ConstraintModifiers,
7518    },
7519    /// ClickHouse ASSUME constraint (query optimization assumption)
7520    Assume {
7521        name: Option<Identifier>,
7522        expression: Expression,
7523    },
7524    /// INDEX / KEY constraint (MySQL)
7525    Index {
7526        name: Option<Identifier>,
7527        columns: Vec<Identifier>,
7528        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7529        #[serde(default)]
7530        kind: Option<String>,
7531        #[serde(default)]
7532        modifiers: ConstraintModifiers,
7533        /// True if KEY keyword was used instead of INDEX
7534        #[serde(default)]
7535        use_key_keyword: bool,
7536        /// ClickHouse: indexed expression (instead of columns)
7537        #[serde(default, skip_serializing_if = "Option::is_none")]
7538        expression: Option<Box<Expression>>,
7539        /// ClickHouse: TYPE type_func(args)
7540        #[serde(default, skip_serializing_if = "Option::is_none")]
7541        index_type: Option<Box<Expression>>,
7542        /// ClickHouse: GRANULARITY n
7543        #[serde(default, skip_serializing_if = "Option::is_none")]
7544        granularity: Option<Box<Expression>>,
7545    },
7546    /// ClickHouse PROJECTION definition
7547    Projection {
7548        name: Identifier,
7549        expression: Expression,
7550    },
7551    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7552    Like {
7553        source: TableRef,
7554        /// Options as (INCLUDING|EXCLUDING, property) pairs
7555        options: Vec<(LikeOptionAction, String)>,
7556    },
7557    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7558    PeriodForSystemTime {
7559        start_col: Identifier,
7560        end_col: Identifier,
7561    },
7562    /// PostgreSQL EXCLUDE constraint
7563    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7564    Exclude {
7565        name: Option<Identifier>,
7566        /// Index access method (gist, btree, etc.)
7567        #[serde(default)]
7568        using: Option<String>,
7569        /// Elements: (expression, operator) pairs
7570        elements: Vec<ExcludeElement>,
7571        /// INCLUDE columns
7572        #[serde(default)]
7573        include_columns: Vec<Identifier>,
7574        /// WHERE predicate
7575        #[serde(default)]
7576        where_clause: Option<Box<Expression>>,
7577        /// WITH (storage_parameters)
7578        #[serde(default)]
7579        with_params: Vec<(String, String)>,
7580        /// USING INDEX TABLESPACE tablespace_name
7581        #[serde(default)]
7582        using_index_tablespace: Option<String>,
7583        #[serde(default)]
7584        modifiers: ConstraintModifiers,
7585    },
7586    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7587    Tags(Tags),
7588    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7589    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7590    /// for all deferrable constraints in the table
7591    InitiallyDeferred {
7592        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7593        deferred: bool,
7594    },
7595}
7596
7597/// Element in an EXCLUDE constraint: expression WITH operator
7598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7599#[cfg_attr(feature = "bindings", derive(TS))]
7600pub struct ExcludeElement {
7601    /// The column expression (may include operator class, ordering, nulls)
7602    pub expression: String,
7603    /// The operator (e.g., &&, =)
7604    pub operator: String,
7605}
7606
7607/// Action for LIKE clause options
7608#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7609#[cfg_attr(feature = "bindings", derive(TS))]
7610pub enum LikeOptionAction {
7611    Including,
7612    Excluding,
7613}
7614
7615/// MATCH type for foreign keys
7616#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7617#[cfg_attr(feature = "bindings", derive(TS))]
7618pub enum MatchType {
7619    Full,
7620    Partial,
7621    Simple,
7622}
7623
7624/// Foreign key reference
7625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7626#[cfg_attr(feature = "bindings", derive(TS))]
7627pub struct ForeignKeyRef {
7628    pub table: TableRef,
7629    pub columns: Vec<Identifier>,
7630    pub on_delete: Option<ReferentialAction>,
7631    pub on_update: Option<ReferentialAction>,
7632    /// True if ON UPDATE appears before ON DELETE in the original SQL
7633    #[serde(default)]
7634    pub on_update_first: bool,
7635    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7636    #[serde(default)]
7637    pub match_type: Option<MatchType>,
7638    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7639    #[serde(default)]
7640    pub match_after_actions: bool,
7641    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7642    #[serde(default)]
7643    pub constraint_name: Option<String>,
7644    /// DEFERRABLE / NOT DEFERRABLE
7645    #[serde(default)]
7646    pub deferrable: Option<bool>,
7647    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7648    #[serde(default)]
7649    pub has_foreign_key_keywords: bool,
7650}
7651
7652/// Referential action for foreign keys
7653#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7654#[cfg_attr(feature = "bindings", derive(TS))]
7655pub enum ReferentialAction {
7656    Cascade,
7657    SetNull,
7658    SetDefault,
7659    Restrict,
7660    NoAction,
7661}
7662
7663/// DROP TABLE statement
7664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7665#[cfg_attr(feature = "bindings", derive(TS))]
7666pub struct DropTable {
7667    pub names: Vec<TableRef>,
7668    pub if_exists: bool,
7669    pub cascade: bool,
7670    /// Oracle: CASCADE CONSTRAINTS
7671    #[serde(default)]
7672    pub cascade_constraints: bool,
7673    /// Oracle: PURGE
7674    #[serde(default)]
7675    pub purge: bool,
7676    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7677    #[serde(default)]
7678    pub leading_comments: Vec<String>,
7679    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7680    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7681    #[serde(default, skip_serializing_if = "Option::is_none")]
7682    pub object_id_args: Option<String>,
7683    /// ClickHouse: SYNC modifier
7684    #[serde(default)]
7685    pub sync: bool,
7686}
7687
7688impl DropTable {
7689    pub fn new(name: impl Into<String>) -> Self {
7690        Self {
7691            names: vec![TableRef::new(name)],
7692            if_exists: false,
7693            cascade: false,
7694            cascade_constraints: false,
7695            purge: false,
7696            leading_comments: Vec::new(),
7697            object_id_args: None,
7698            sync: false,
7699        }
7700    }
7701}
7702
7703/// ALTER TABLE statement
7704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7705#[cfg_attr(feature = "bindings", derive(TS))]
7706pub struct AlterTable {
7707    pub name: TableRef,
7708    pub actions: Vec<AlterTableAction>,
7709    /// IF EXISTS clause
7710    #[serde(default)]
7711    pub if_exists: bool,
7712    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
7713    #[serde(default, skip_serializing_if = "Option::is_none")]
7714    pub algorithm: Option<String>,
7715    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
7716    #[serde(default, skip_serializing_if = "Option::is_none")]
7717    pub lock: Option<String>,
7718    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
7719    #[serde(default, skip_serializing_if = "Option::is_none")]
7720    pub with_check: Option<String>,
7721    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
7722    #[serde(default, skip_serializing_if = "Option::is_none")]
7723    pub partition: Option<Vec<(Identifier, Expression)>>,
7724    /// ClickHouse: ON CLUSTER clause for distributed DDL
7725    #[serde(default, skip_serializing_if = "Option::is_none")]
7726    pub on_cluster: Option<OnCluster>,
7727}
7728
7729impl AlterTable {
7730    pub fn new(name: impl Into<String>) -> Self {
7731        Self {
7732            name: TableRef::new(name),
7733            actions: Vec::new(),
7734            if_exists: false,
7735            algorithm: None,
7736            lock: None,
7737            with_check: None,
7738            partition: None,
7739            on_cluster: None,
7740        }
7741    }
7742}
7743
7744/// Column position for ADD COLUMN (MySQL/MariaDB)
7745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7746#[cfg_attr(feature = "bindings", derive(TS))]
7747pub enum ColumnPosition {
7748    First,
7749    After(Identifier),
7750}
7751
7752/// Actions for ALTER TABLE
7753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7754#[cfg_attr(feature = "bindings", derive(TS))]
7755pub enum AlterTableAction {
7756    AddColumn {
7757        column: ColumnDef,
7758        if_not_exists: bool,
7759        position: Option<ColumnPosition>,
7760    },
7761    DropColumn {
7762        name: Identifier,
7763        if_exists: bool,
7764        cascade: bool,
7765    },
7766    RenameColumn {
7767        old_name: Identifier,
7768        new_name: Identifier,
7769        if_exists: bool,
7770    },
7771    AlterColumn {
7772        name: Identifier,
7773        action: AlterColumnAction,
7774        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
7775        #[serde(default)]
7776        use_modify_keyword: bool,
7777    },
7778    RenameTable(TableRef),
7779    AddConstraint(TableConstraint),
7780    DropConstraint {
7781        name: Identifier,
7782        if_exists: bool,
7783    },
7784    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
7785    DropForeignKey {
7786        name: Identifier,
7787    },
7788    /// DROP PARTITION action (Hive/BigQuery)
7789    DropPartition {
7790        /// List of partitions to drop (each partition is a list of key=value pairs)
7791        partitions: Vec<Vec<(Identifier, Expression)>>,
7792        if_exists: bool,
7793    },
7794    /// ADD PARTITION action (Hive/Spark)
7795    AddPartition {
7796        /// The partition expression
7797        partition: Expression,
7798        if_not_exists: bool,
7799        location: Option<Expression>,
7800    },
7801    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
7802    Delete {
7803        where_clause: Expression,
7804    },
7805    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
7806    SwapWith(TableRef),
7807    /// SET property action (Snowflake): ALTER TABLE t SET property=value
7808    SetProperty {
7809        properties: Vec<(String, Expression)>,
7810    },
7811    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
7812    UnsetProperty {
7813        properties: Vec<String>,
7814    },
7815    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
7816    ClusterBy {
7817        expressions: Vec<Expression>,
7818    },
7819    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
7820    SetTag {
7821        expressions: Vec<(String, Expression)>,
7822    },
7823    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
7824    UnsetTag {
7825        names: Vec<String>,
7826    },
7827    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
7828    SetOptions {
7829        expressions: Vec<Expression>,
7830    },
7831    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
7832    AlterIndex {
7833        name: Identifier,
7834        visible: bool,
7835    },
7836    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
7837    SetAttribute {
7838        attribute: String,
7839    },
7840    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
7841    SetStageFileFormat {
7842        options: Option<Expression>,
7843    },
7844    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
7845    SetStageCopyOptions {
7846        options: Option<Expression>,
7847    },
7848    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
7849    AddColumns {
7850        columns: Vec<ColumnDef>,
7851        cascade: bool,
7852    },
7853    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
7854    DropColumns {
7855        names: Vec<Identifier>,
7856    },
7857    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
7858    /// In SingleStore, data_type can be omitted for simple column renames
7859    ChangeColumn {
7860        old_name: Identifier,
7861        new_name: Identifier,
7862        #[serde(default, skip_serializing_if = "Option::is_none")]
7863        data_type: Option<DataType>,
7864        comment: Option<String>,
7865        #[serde(default)]
7866        cascade: bool,
7867    },
7868    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
7869    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
7870    AlterSortKey {
7871        /// AUTO or NONE keyword
7872        this: Option<String>,
7873        /// Column list for (col1, col2) syntax
7874        expressions: Vec<Expression>,
7875        /// Whether COMPOUND keyword was present
7876        compound: bool,
7877    },
7878    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
7879    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
7880    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
7881    AlterDistStyle {
7882        /// Distribution style: ALL, EVEN, AUTO, or KEY
7883        style: String,
7884        /// DISTKEY column (only when style is KEY)
7885        distkey: Option<Identifier>,
7886    },
7887    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
7888    SetTableProperties {
7889        properties: Vec<(Expression, Expression)>,
7890    },
7891    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
7892    SetLocation {
7893        location: String,
7894    },
7895    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
7896    SetFileFormat {
7897        format: String,
7898    },
7899    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
7900    ReplacePartition {
7901        partition: Expression,
7902        source: Option<Box<Expression>>,
7903    },
7904    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
7905    Raw {
7906        sql: String,
7907    },
7908}
7909
7910/// Actions for ALTER COLUMN
7911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7912#[cfg_attr(feature = "bindings", derive(TS))]
7913pub enum AlterColumnAction {
7914    SetDataType {
7915        data_type: DataType,
7916        /// USING expression for type conversion (PostgreSQL)
7917        using: Option<Expression>,
7918        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
7919        #[serde(default, skip_serializing_if = "Option::is_none")]
7920        collate: Option<String>,
7921    },
7922    SetDefault(Expression),
7923    DropDefault,
7924    SetNotNull,
7925    DropNotNull,
7926    /// Set column comment
7927    Comment(String),
7928    /// MySQL: SET VISIBLE
7929    SetVisible,
7930    /// MySQL: SET INVISIBLE
7931    SetInvisible,
7932}
7933
7934/// CREATE INDEX statement
7935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7936#[cfg_attr(feature = "bindings", derive(TS))]
7937pub struct CreateIndex {
7938    pub name: Identifier,
7939    pub table: TableRef,
7940    pub columns: Vec<IndexColumn>,
7941    pub unique: bool,
7942    pub if_not_exists: bool,
7943    pub using: Option<String>,
7944    /// TSQL CLUSTERED/NONCLUSTERED modifier
7945    #[serde(default)]
7946    pub clustered: Option<String>,
7947    /// PostgreSQL CONCURRENTLY modifier
7948    #[serde(default)]
7949    pub concurrently: bool,
7950    /// PostgreSQL WHERE clause for partial indexes
7951    #[serde(default)]
7952    pub where_clause: Option<Box<Expression>>,
7953    /// PostgreSQL INCLUDE columns
7954    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7955    pub include_columns: Vec<Identifier>,
7956    /// TSQL WITH options (e.g., allow_page_locks=on)
7957    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7958    pub with_options: Vec<(String, String)>,
7959    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
7960    #[serde(default)]
7961    pub on_filegroup: Option<String>,
7962}
7963
7964impl CreateIndex {
7965    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7966        Self {
7967            name: Identifier::new(name),
7968            table: TableRef::new(table),
7969            columns: Vec::new(),
7970            unique: false,
7971            if_not_exists: false,
7972            using: None,
7973            clustered: None,
7974            concurrently: false,
7975            where_clause: None,
7976            include_columns: Vec::new(),
7977            with_options: Vec::new(),
7978            on_filegroup: None,
7979        }
7980    }
7981}
7982
7983/// Index column specification
7984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7985#[cfg_attr(feature = "bindings", derive(TS))]
7986pub struct IndexColumn {
7987    pub column: Identifier,
7988    pub desc: bool,
7989    /// Explicit ASC keyword was present
7990    #[serde(default)]
7991    pub asc: bool,
7992    pub nulls_first: Option<bool>,
7993    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
7994    #[serde(default, skip_serializing_if = "Option::is_none")]
7995    pub opclass: Option<String>,
7996}
7997
7998/// DROP INDEX statement
7999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8000#[cfg_attr(feature = "bindings", derive(TS))]
8001pub struct DropIndex {
8002    pub name: Identifier,
8003    pub table: Option<TableRef>,
8004    pub if_exists: bool,
8005    /// PostgreSQL CONCURRENTLY modifier
8006    #[serde(default)]
8007    pub concurrently: bool,
8008}
8009
8010impl DropIndex {
8011    pub fn new(name: impl Into<String>) -> Self {
8012        Self {
8013            name: Identifier::new(name),
8014            table: None,
8015            if_exists: false,
8016            concurrently: false,
8017        }
8018    }
8019}
8020
8021/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8023#[cfg_attr(feature = "bindings", derive(TS))]
8024pub struct ViewColumn {
8025    pub name: Identifier,
8026    pub comment: Option<String>,
8027    /// BigQuery: OPTIONS (key=value, ...) on column
8028    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8029    pub options: Vec<Expression>,
8030}
8031
8032impl ViewColumn {
8033    pub fn new(name: impl Into<String>) -> Self {
8034        Self {
8035            name: Identifier::new(name),
8036            comment: None,
8037            options: Vec::new(),
8038        }
8039    }
8040
8041    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8042        Self {
8043            name: Identifier::new(name),
8044            comment: Some(comment.into()),
8045            options: Vec::new(),
8046        }
8047    }
8048}
8049
8050/// CREATE VIEW statement
8051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8052#[cfg_attr(feature = "bindings", derive(TS))]
8053pub struct CreateView {
8054    pub name: TableRef,
8055    pub columns: Vec<ViewColumn>,
8056    pub query: Expression,
8057    pub or_replace: bool,
8058    pub if_not_exists: bool,
8059    pub materialized: bool,
8060    pub temporary: bool,
8061    /// Snowflake: SECURE VIEW
8062    #[serde(default)]
8063    pub secure: bool,
8064    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8065    #[serde(skip_serializing_if = "Option::is_none")]
8066    pub algorithm: Option<String>,
8067    /// MySQL: DEFINER=user@host
8068    #[serde(skip_serializing_if = "Option::is_none")]
8069    pub definer: Option<String>,
8070    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8071    #[serde(skip_serializing_if = "Option::is_none")]
8072    pub security: Option<FunctionSecurity>,
8073    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8074    #[serde(default = "default_true")]
8075    pub security_sql_style: bool,
8076    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8077    #[serde(default)]
8078    pub security_after_name: bool,
8079    /// Whether the query was parenthesized: AS (SELECT ...)
8080    #[serde(default)]
8081    pub query_parenthesized: bool,
8082    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8083    #[serde(skip_serializing_if = "Option::is_none")]
8084    pub locking_mode: Option<String>,
8085    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8086    #[serde(skip_serializing_if = "Option::is_none")]
8087    pub locking_access: Option<String>,
8088    /// Snowflake: COPY GRANTS
8089    #[serde(default)]
8090    pub copy_grants: bool,
8091    /// Snowflake: COMMENT = 'text'
8092    #[serde(skip_serializing_if = "Option::is_none", default)]
8093    pub comment: Option<String>,
8094    /// Snowflake: TAG (name='value', ...)
8095    #[serde(default)]
8096    pub tags: Vec<(String, String)>,
8097    /// BigQuery: OPTIONS (key=value, ...)
8098    #[serde(default)]
8099    pub options: Vec<Expression>,
8100    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8101    #[serde(skip_serializing_if = "Option::is_none", default)]
8102    pub build: Option<String>,
8103    /// Doris: REFRESH property for materialized views
8104    #[serde(skip_serializing_if = "Option::is_none", default)]
8105    pub refresh: Option<Box<RefreshTriggerProperty>>,
8106    /// Doris: Schema with typed column definitions for materialized views
8107    /// This is used instead of `columns` when the view has typed column definitions
8108    #[serde(skip_serializing_if = "Option::is_none", default)]
8109    pub schema: Option<Box<Schema>>,
8110    /// Doris: KEY (columns) for materialized views
8111    #[serde(skip_serializing_if = "Option::is_none", default)]
8112    pub unique_key: Option<Box<UniqueKeyProperty>>,
8113    /// Redshift: WITH NO SCHEMA BINDING
8114    #[serde(default)]
8115    pub no_schema_binding: bool,
8116    /// Redshift: AUTO REFRESH YES|NO for materialized views
8117    #[serde(skip_serializing_if = "Option::is_none", default)]
8118    pub auto_refresh: Option<bool>,
8119    /// ClickHouse: ON CLUSTER clause
8120    #[serde(default, skip_serializing_if = "Option::is_none")]
8121    pub on_cluster: Option<OnCluster>,
8122    /// ClickHouse: TO destination_table
8123    #[serde(default, skip_serializing_if = "Option::is_none")]
8124    pub to_table: Option<TableRef>,
8125    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8126    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8127    pub table_properties: Vec<Expression>,
8128}
8129
8130impl CreateView {
8131    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8132        Self {
8133            name: TableRef::new(name),
8134            columns: Vec::new(),
8135            query,
8136            or_replace: false,
8137            if_not_exists: false,
8138            materialized: false,
8139            temporary: false,
8140            secure: false,
8141            algorithm: None,
8142            definer: None,
8143            security: None,
8144            security_sql_style: true,
8145            security_after_name: false,
8146            query_parenthesized: false,
8147            locking_mode: None,
8148            locking_access: None,
8149            copy_grants: false,
8150            comment: None,
8151            tags: Vec::new(),
8152            options: Vec::new(),
8153            build: None,
8154            refresh: None,
8155            schema: None,
8156            unique_key: None,
8157            no_schema_binding: false,
8158            auto_refresh: None,
8159            on_cluster: None,
8160            to_table: None,
8161            table_properties: Vec::new(),
8162        }
8163    }
8164}
8165
8166/// DROP VIEW statement
8167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8168#[cfg_attr(feature = "bindings", derive(TS))]
8169pub struct DropView {
8170    pub name: TableRef,
8171    pub if_exists: bool,
8172    pub materialized: bool,
8173}
8174
8175impl DropView {
8176    pub fn new(name: impl Into<String>) -> Self {
8177        Self {
8178            name: TableRef::new(name),
8179            if_exists: false,
8180            materialized: false,
8181        }
8182    }
8183}
8184
8185/// TRUNCATE TABLE statement
8186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8187#[cfg_attr(feature = "bindings", derive(TS))]
8188pub struct Truncate {
8189    /// Target of TRUNCATE (TABLE vs DATABASE)
8190    #[serde(default)]
8191    pub target: TruncateTarget,
8192    /// IF EXISTS clause
8193    #[serde(default)]
8194    pub if_exists: bool,
8195    pub table: TableRef,
8196    /// ClickHouse: ON CLUSTER clause for distributed DDL
8197    #[serde(default, skip_serializing_if = "Option::is_none")]
8198    pub on_cluster: Option<OnCluster>,
8199    pub cascade: bool,
8200    /// Additional tables for multi-table TRUNCATE
8201    #[serde(default)]
8202    pub extra_tables: Vec<TruncateTableEntry>,
8203    /// RESTART IDENTITY or CONTINUE IDENTITY
8204    #[serde(default)]
8205    pub identity: Option<TruncateIdentity>,
8206    /// RESTRICT option (alternative to CASCADE)
8207    #[serde(default)]
8208    pub restrict: bool,
8209    /// Hive PARTITION clause: PARTITION(key=value, ...)
8210    #[serde(default, skip_serializing_if = "Option::is_none")]
8211    pub partition: Option<Box<Expression>>,
8212}
8213
8214/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8216#[cfg_attr(feature = "bindings", derive(TS))]
8217pub struct TruncateTableEntry {
8218    pub table: TableRef,
8219    /// Whether the table has a * suffix (inherit children)
8220    #[serde(default)]
8221    pub star: bool,
8222}
8223
8224/// TRUNCATE target type
8225#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8226#[cfg_attr(feature = "bindings", derive(TS))]
8227pub enum TruncateTarget {
8228    Table,
8229    Database,
8230}
8231
8232impl Default for TruncateTarget {
8233    fn default() -> Self {
8234        TruncateTarget::Table
8235    }
8236}
8237
8238/// TRUNCATE identity option
8239#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8240#[cfg_attr(feature = "bindings", derive(TS))]
8241pub enum TruncateIdentity {
8242    Restart,
8243    Continue,
8244}
8245
8246impl Truncate {
8247    pub fn new(table: impl Into<String>) -> Self {
8248        Self {
8249            target: TruncateTarget::Table,
8250            if_exists: false,
8251            table: TableRef::new(table),
8252            on_cluster: None,
8253            cascade: false,
8254            extra_tables: Vec::new(),
8255            identity: None,
8256            restrict: false,
8257            partition: None,
8258        }
8259    }
8260}
8261
8262/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8264#[cfg_attr(feature = "bindings", derive(TS))]
8265pub struct Use {
8266    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8267    pub kind: Option<UseKind>,
8268    /// The name of the object
8269    pub this: Identifier,
8270}
8271
8272/// Kind of USE statement
8273#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8274#[cfg_attr(feature = "bindings", derive(TS))]
8275pub enum UseKind {
8276    Database,
8277    Schema,
8278    Role,
8279    Warehouse,
8280    Catalog,
8281    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8282    SecondaryRoles,
8283}
8284
8285/// SET variable statement
8286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8287#[cfg_attr(feature = "bindings", derive(TS))]
8288pub struct SetStatement {
8289    /// The items being set
8290    pub items: Vec<SetItem>,
8291}
8292
8293/// A single SET item (variable assignment)
8294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8295#[cfg_attr(feature = "bindings", derive(TS))]
8296pub struct SetItem {
8297    /// The variable name
8298    pub name: Expression,
8299    /// The value to set
8300    pub value: Expression,
8301    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8302    pub kind: Option<String>,
8303    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8304    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8305    pub no_equals: bool,
8306}
8307
8308/// CACHE TABLE statement (Spark)
8309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8310#[cfg_attr(feature = "bindings", derive(TS))]
8311pub struct Cache {
8312    /// The table to cache
8313    pub table: Identifier,
8314    /// LAZY keyword - defer caching until first use
8315    pub lazy: bool,
8316    /// Optional OPTIONS clause (key-value pairs)
8317    pub options: Vec<(Expression, Expression)>,
8318    /// Optional AS clause with query
8319    pub query: Option<Expression>,
8320}
8321
8322/// UNCACHE TABLE statement (Spark)
8323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8324#[cfg_attr(feature = "bindings", derive(TS))]
8325pub struct Uncache {
8326    /// The table to uncache
8327    pub table: Identifier,
8328    /// IF EXISTS clause
8329    pub if_exists: bool,
8330}
8331
8332/// LOAD DATA statement (Hive)
8333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8334#[cfg_attr(feature = "bindings", derive(TS))]
8335pub struct LoadData {
8336    /// LOCAL keyword - load from local filesystem
8337    pub local: bool,
8338    /// The path to load data from (INPATH value)
8339    pub inpath: String,
8340    /// Whether to overwrite existing data
8341    pub overwrite: bool,
8342    /// The target table
8343    pub table: Expression,
8344    /// Optional PARTITION clause with key-value pairs
8345    pub partition: Vec<(Identifier, Expression)>,
8346    /// Optional INPUTFORMAT clause
8347    pub input_format: Option<String>,
8348    /// Optional SERDE clause
8349    pub serde: Option<String>,
8350}
8351
8352/// PRAGMA statement (SQLite)
8353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8354#[cfg_attr(feature = "bindings", derive(TS))]
8355pub struct Pragma {
8356    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8357    pub schema: Option<Identifier>,
8358    /// The pragma name
8359    pub name: Identifier,
8360    /// Optional value for assignment (PRAGMA name = value)
8361    pub value: Option<Expression>,
8362    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8363    pub args: Vec<Expression>,
8364}
8365
8366/// A privilege with optional column list for GRANT/REVOKE
8367/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8369#[cfg_attr(feature = "bindings", derive(TS))]
8370pub struct Privilege {
8371    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8372    pub name: String,
8373    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8374    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8375    pub columns: Vec<String>,
8376}
8377
8378/// Principal in GRANT/REVOKE (user, role, etc.)
8379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8380#[cfg_attr(feature = "bindings", derive(TS))]
8381pub struct GrantPrincipal {
8382    /// The name of the principal
8383    pub name: Identifier,
8384    /// Whether prefixed with ROLE keyword
8385    pub is_role: bool,
8386    /// Whether prefixed with GROUP keyword (Redshift)
8387    #[serde(default)]
8388    pub is_group: bool,
8389}
8390
8391/// GRANT statement
8392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8393#[cfg_attr(feature = "bindings", derive(TS))]
8394pub struct Grant {
8395    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8396    pub privileges: Vec<Privilege>,
8397    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8398    pub kind: Option<String>,
8399    /// The object to grant on
8400    pub securable: Identifier,
8401    /// Function parameter types (for FUNCTION kind)
8402    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8403    pub function_params: Vec<String>,
8404    /// The grantees
8405    pub principals: Vec<GrantPrincipal>,
8406    /// WITH GRANT OPTION
8407    pub grant_option: bool,
8408    /// TSQL: AS principal (the grantor role)
8409    #[serde(default, skip_serializing_if = "Option::is_none")]
8410    pub as_principal: Option<Identifier>,
8411}
8412
8413/// REVOKE statement
8414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8415#[cfg_attr(feature = "bindings", derive(TS))]
8416pub struct Revoke {
8417    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8418    pub privileges: Vec<Privilege>,
8419    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8420    pub kind: Option<String>,
8421    /// The object to revoke from
8422    pub securable: Identifier,
8423    /// Function parameter types (for FUNCTION kind)
8424    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8425    pub function_params: Vec<String>,
8426    /// The grantees
8427    pub principals: Vec<GrantPrincipal>,
8428    /// GRANT OPTION FOR
8429    pub grant_option: bool,
8430    /// CASCADE
8431    pub cascade: bool,
8432    /// RESTRICT
8433    #[serde(default)]
8434    pub restrict: bool,
8435}
8436
8437/// COMMENT ON statement
8438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8439#[cfg_attr(feature = "bindings", derive(TS))]
8440pub struct Comment {
8441    /// The object being commented on
8442    pub this: Expression,
8443    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8444    pub kind: String,
8445    /// The comment text expression
8446    pub expression: Expression,
8447    /// IF EXISTS clause
8448    pub exists: bool,
8449    /// MATERIALIZED keyword
8450    pub materialized: bool,
8451}
8452
8453// ============================================================================
8454// Phase 4: Additional DDL Statements
8455// ============================================================================
8456
8457/// ALTER VIEW statement
8458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8459#[cfg_attr(feature = "bindings", derive(TS))]
8460pub struct AlterView {
8461    pub name: TableRef,
8462    pub actions: Vec<AlterViewAction>,
8463    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8464    #[serde(default, skip_serializing_if = "Option::is_none")]
8465    pub algorithm: Option<String>,
8466    /// MySQL: DEFINER = 'user'@'host'
8467    #[serde(default, skip_serializing_if = "Option::is_none")]
8468    pub definer: Option<String>,
8469    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8470    #[serde(default, skip_serializing_if = "Option::is_none")]
8471    pub sql_security: Option<String>,
8472    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8473    #[serde(default, skip_serializing_if = "Option::is_none")]
8474    pub with_option: Option<String>,
8475    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8476    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8477    pub columns: Vec<ViewColumn>,
8478}
8479
8480/// Actions for ALTER VIEW
8481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8482#[cfg_attr(feature = "bindings", derive(TS))]
8483pub enum AlterViewAction {
8484    /// Rename the view
8485    Rename(TableRef),
8486    /// Change owner
8487    OwnerTo(Identifier),
8488    /// Set schema
8489    SetSchema(Identifier),
8490    /// Set authorization (Trino/Presto)
8491    SetAuthorization(String),
8492    /// Alter column
8493    AlterColumn {
8494        name: Identifier,
8495        action: AlterColumnAction,
8496    },
8497    /// Redefine view as query (SELECT, UNION, etc.)
8498    AsSelect(Box<Expression>),
8499    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8500    SetTblproperties(Vec<(String, String)>),
8501    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8502    UnsetTblproperties(Vec<String>),
8503}
8504
8505impl AlterView {
8506    pub fn new(name: impl Into<String>) -> Self {
8507        Self {
8508            name: TableRef::new(name),
8509            actions: Vec::new(),
8510            algorithm: None,
8511            definer: None,
8512            sql_security: None,
8513            with_option: None,
8514            columns: Vec::new(),
8515        }
8516    }
8517}
8518
8519/// ALTER INDEX statement
8520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8521#[cfg_attr(feature = "bindings", derive(TS))]
8522pub struct AlterIndex {
8523    pub name: Identifier,
8524    pub table: Option<TableRef>,
8525    pub actions: Vec<AlterIndexAction>,
8526}
8527
8528/// Actions for ALTER INDEX
8529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8530#[cfg_attr(feature = "bindings", derive(TS))]
8531pub enum AlterIndexAction {
8532    /// Rename the index
8533    Rename(Identifier),
8534    /// Set tablespace
8535    SetTablespace(Identifier),
8536    /// Set visibility (MySQL)
8537    Visible(bool),
8538}
8539
8540impl AlterIndex {
8541    pub fn new(name: impl Into<String>) -> Self {
8542        Self {
8543            name: Identifier::new(name),
8544            table: None,
8545            actions: Vec::new(),
8546        }
8547    }
8548}
8549
8550/// CREATE SCHEMA statement
8551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8552#[cfg_attr(feature = "bindings", derive(TS))]
8553pub struct CreateSchema {
8554    pub name: Identifier,
8555    pub if_not_exists: bool,
8556    pub authorization: Option<Identifier>,
8557    #[serde(default)]
8558    pub clone_from: Option<Identifier>,
8559    /// AT/BEFORE clause for time travel (Snowflake)
8560    #[serde(default)]
8561    pub at_clause: Option<Expression>,
8562    /// Schema properties like DEFAULT COLLATE
8563    #[serde(default)]
8564    pub properties: Vec<Expression>,
8565    /// Leading comments before the statement
8566    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8567    pub leading_comments: Vec<String>,
8568}
8569
8570impl CreateSchema {
8571    pub fn new(name: impl Into<String>) -> Self {
8572        Self {
8573            name: Identifier::new(name),
8574            if_not_exists: false,
8575            authorization: None,
8576            clone_from: None,
8577            at_clause: None,
8578            properties: Vec::new(),
8579            leading_comments: Vec::new(),
8580        }
8581    }
8582}
8583
8584/// DROP SCHEMA statement
8585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8586#[cfg_attr(feature = "bindings", derive(TS))]
8587pub struct DropSchema {
8588    pub name: Identifier,
8589    pub if_exists: bool,
8590    pub cascade: bool,
8591}
8592
8593impl DropSchema {
8594    pub fn new(name: impl Into<String>) -> Self {
8595        Self {
8596            name: Identifier::new(name),
8597            if_exists: false,
8598            cascade: false,
8599        }
8600    }
8601}
8602
8603/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8605#[cfg_attr(feature = "bindings", derive(TS))]
8606pub struct DropNamespace {
8607    pub name: Identifier,
8608    pub if_exists: bool,
8609    pub cascade: bool,
8610}
8611
8612impl DropNamespace {
8613    pub fn new(name: impl Into<String>) -> Self {
8614        Self {
8615            name: Identifier::new(name),
8616            if_exists: false,
8617            cascade: false,
8618        }
8619    }
8620}
8621
8622/// CREATE DATABASE statement
8623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8624#[cfg_attr(feature = "bindings", derive(TS))]
8625pub struct CreateDatabase {
8626    pub name: Identifier,
8627    pub if_not_exists: bool,
8628    pub options: Vec<DatabaseOption>,
8629    /// Snowflake CLONE source
8630    #[serde(default)]
8631    pub clone_from: Option<Identifier>,
8632    /// AT/BEFORE clause for time travel (Snowflake)
8633    #[serde(default)]
8634    pub at_clause: Option<Expression>,
8635}
8636
8637/// Database option
8638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8639#[cfg_attr(feature = "bindings", derive(TS))]
8640pub enum DatabaseOption {
8641    CharacterSet(String),
8642    Collate(String),
8643    Owner(Identifier),
8644    Template(Identifier),
8645    Encoding(String),
8646    Location(String),
8647}
8648
8649impl CreateDatabase {
8650    pub fn new(name: impl Into<String>) -> Self {
8651        Self {
8652            name: Identifier::new(name),
8653            if_not_exists: false,
8654            options: Vec::new(),
8655            clone_from: None,
8656            at_clause: None,
8657        }
8658    }
8659}
8660
8661/// DROP DATABASE statement
8662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8663#[cfg_attr(feature = "bindings", derive(TS))]
8664pub struct DropDatabase {
8665    pub name: Identifier,
8666    pub if_exists: bool,
8667    /// ClickHouse: SYNC modifier
8668    #[serde(default)]
8669    pub sync: bool,
8670}
8671
8672impl DropDatabase {
8673    pub fn new(name: impl Into<String>) -> Self {
8674        Self {
8675            name: Identifier::new(name),
8676            if_exists: false,
8677            sync: false,
8678        }
8679    }
8680}
8681
8682/// CREATE FUNCTION statement
8683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8684#[cfg_attr(feature = "bindings", derive(TS))]
8685pub struct CreateFunction {
8686    pub name: TableRef,
8687    pub parameters: Vec<FunctionParameter>,
8688    pub return_type: Option<DataType>,
8689    pub body: Option<FunctionBody>,
8690    pub or_replace: bool,
8691    pub if_not_exists: bool,
8692    pub temporary: bool,
8693    pub language: Option<String>,
8694    pub deterministic: Option<bool>,
8695    pub returns_null_on_null_input: Option<bool>,
8696    pub security: Option<FunctionSecurity>,
8697    /// Whether parentheses were present in the original syntax
8698    #[serde(default = "default_true")]
8699    pub has_parens: bool,
8700    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
8701    #[serde(default)]
8702    pub sql_data_access: Option<SqlDataAccess>,
8703    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
8704    #[serde(default, skip_serializing_if = "Option::is_none")]
8705    pub returns_table_body: Option<String>,
8706    /// True if LANGUAGE clause appears before RETURNS clause
8707    #[serde(default)]
8708    pub language_first: bool,
8709    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
8710    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8711    pub set_options: Vec<FunctionSetOption>,
8712    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
8713    #[serde(default)]
8714    pub strict: bool,
8715    /// BigQuery: OPTIONS (key=value, ...)
8716    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8717    pub options: Vec<Expression>,
8718    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
8719    #[serde(default)]
8720    pub is_table_function: bool,
8721    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
8722    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8723    pub property_order: Vec<FunctionPropertyKind>,
8724    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
8725    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8726    pub environment: Vec<Expression>,
8727    /// HANDLER 'handler_function' clause (Databricks)
8728    #[serde(default, skip_serializing_if = "Option::is_none")]
8729    pub handler: Option<String>,
8730    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
8731    #[serde(default, skip_serializing_if = "Option::is_none")]
8732    pub parameter_style: Option<String>,
8733}
8734
8735/// A SET option in CREATE FUNCTION (PostgreSQL)
8736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8737#[cfg_attr(feature = "bindings", derive(TS))]
8738pub struct FunctionSetOption {
8739    pub name: String,
8740    pub value: FunctionSetValue,
8741}
8742
8743/// The value of a SET option
8744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8745#[cfg_attr(feature = "bindings", derive(TS))]
8746pub enum FunctionSetValue {
8747    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
8748    Value { value: String, use_to: bool },
8749    /// SET key FROM CURRENT
8750    FromCurrent,
8751}
8752
8753/// SQL data access characteristics for functions
8754#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8755#[cfg_attr(feature = "bindings", derive(TS))]
8756pub enum SqlDataAccess {
8757    /// NO SQL
8758    NoSql,
8759    /// CONTAINS SQL
8760    ContainsSql,
8761    /// READS SQL DATA
8762    ReadsSqlData,
8763    /// MODIFIES SQL DATA
8764    ModifiesSqlData,
8765}
8766
8767/// Types of properties in CREATE FUNCTION for tracking their original order
8768#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8769#[cfg_attr(feature = "bindings", derive(TS))]
8770pub enum FunctionPropertyKind {
8771    /// SET option
8772    Set,
8773    /// AS body
8774    As,
8775    /// LANGUAGE clause
8776    Language,
8777    /// IMMUTABLE/VOLATILE/STABLE (determinism)
8778    Determinism,
8779    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
8780    NullInput,
8781    /// SECURITY DEFINER/INVOKER
8782    Security,
8783    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
8784    SqlDataAccess,
8785    /// OPTIONS clause (BigQuery)
8786    Options,
8787    /// ENVIRONMENT clause (Databricks)
8788    Environment,
8789    /// HANDLER clause (Databricks)
8790    Handler,
8791    /// PARAMETER STYLE clause (Databricks)
8792    ParameterStyle,
8793}
8794
8795/// Function parameter
8796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8797#[cfg_attr(feature = "bindings", derive(TS))]
8798pub struct FunctionParameter {
8799    pub name: Option<Identifier>,
8800    pub data_type: DataType,
8801    pub mode: Option<ParameterMode>,
8802    pub default: Option<Expression>,
8803    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
8804    #[serde(default, skip_serializing_if = "Option::is_none")]
8805    pub mode_text: Option<String>,
8806}
8807
8808/// Parameter mode (IN, OUT, INOUT, VARIADIC)
8809#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8810#[cfg_attr(feature = "bindings", derive(TS))]
8811pub enum ParameterMode {
8812    In,
8813    Out,
8814    InOut,
8815    Variadic,
8816}
8817
8818/// Function body
8819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8820#[cfg_attr(feature = "bindings", derive(TS))]
8821pub enum FunctionBody {
8822    /// AS $$ ... $$ (dollar-quoted)
8823    Block(String),
8824    /// AS 'string' (single-quoted string literal body)
8825    StringLiteral(String),
8826    /// AS 'expression'
8827    Expression(Expression),
8828    /// EXTERNAL NAME 'library'
8829    External(String),
8830    /// RETURN expression
8831    Return(Expression),
8832    /// BEGIN ... END block with parsed statements
8833    Statements(Vec<Expression>),
8834    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
8835    /// Stores (content, optional_tag)
8836    DollarQuoted {
8837        content: String,
8838        tag: Option<String>,
8839    },
8840}
8841
8842/// Function security (DEFINER, INVOKER, or NONE)
8843#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8844#[cfg_attr(feature = "bindings", derive(TS))]
8845pub enum FunctionSecurity {
8846    Definer,
8847    Invoker,
8848    /// StarRocks/MySQL: SECURITY NONE
8849    None,
8850}
8851
8852impl CreateFunction {
8853    pub fn new(name: impl Into<String>) -> Self {
8854        Self {
8855            name: TableRef::new(name),
8856            parameters: Vec::new(),
8857            return_type: None,
8858            body: None,
8859            or_replace: false,
8860            if_not_exists: false,
8861            temporary: false,
8862            language: None,
8863            deterministic: None,
8864            returns_null_on_null_input: None,
8865            security: None,
8866            has_parens: true,
8867            sql_data_access: None,
8868            returns_table_body: None,
8869            language_first: false,
8870            set_options: Vec::new(),
8871            strict: false,
8872            options: Vec::new(),
8873            is_table_function: false,
8874            property_order: Vec::new(),
8875            environment: Vec::new(),
8876            handler: None,
8877            parameter_style: None,
8878        }
8879    }
8880}
8881
8882/// DROP FUNCTION statement
8883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8884#[cfg_attr(feature = "bindings", derive(TS))]
8885pub struct DropFunction {
8886    pub name: TableRef,
8887    pub parameters: Option<Vec<DataType>>,
8888    pub if_exists: bool,
8889    pub cascade: bool,
8890}
8891
8892impl DropFunction {
8893    pub fn new(name: impl Into<String>) -> Self {
8894        Self {
8895            name: TableRef::new(name),
8896            parameters: None,
8897            if_exists: false,
8898            cascade: false,
8899        }
8900    }
8901}
8902
8903/// CREATE PROCEDURE statement
8904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8905#[cfg_attr(feature = "bindings", derive(TS))]
8906pub struct CreateProcedure {
8907    pub name: TableRef,
8908    pub parameters: Vec<FunctionParameter>,
8909    pub body: Option<FunctionBody>,
8910    pub or_replace: bool,
8911    pub if_not_exists: bool,
8912    pub language: Option<String>,
8913    pub security: Option<FunctionSecurity>,
8914    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
8915    #[serde(default)]
8916    pub return_type: Option<DataType>,
8917    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
8918    #[serde(default)]
8919    pub execute_as: Option<String>,
8920    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
8921    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8922    pub with_options: Vec<String>,
8923    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
8924    #[serde(default = "default_true", skip_serializing_if = "is_true")]
8925    pub has_parens: bool,
8926    /// Whether the short form PROC was used (instead of PROCEDURE)
8927    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8928    pub use_proc_keyword: bool,
8929}
8930
8931impl CreateProcedure {
8932    pub fn new(name: impl Into<String>) -> Self {
8933        Self {
8934            name: TableRef::new(name),
8935            parameters: Vec::new(),
8936            body: None,
8937            or_replace: false,
8938            if_not_exists: false,
8939            language: None,
8940            security: None,
8941            return_type: None,
8942            execute_as: None,
8943            with_options: Vec::new(),
8944            has_parens: true,
8945            use_proc_keyword: false,
8946        }
8947    }
8948}
8949
8950/// DROP PROCEDURE statement
8951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8952#[cfg_attr(feature = "bindings", derive(TS))]
8953pub struct DropProcedure {
8954    pub name: TableRef,
8955    pub parameters: Option<Vec<DataType>>,
8956    pub if_exists: bool,
8957    pub cascade: bool,
8958}
8959
8960impl DropProcedure {
8961    pub fn new(name: impl Into<String>) -> Self {
8962        Self {
8963            name: TableRef::new(name),
8964            parameters: None,
8965            if_exists: false,
8966            cascade: false,
8967        }
8968    }
8969}
8970
8971/// Sequence property tag for ordering
8972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8973#[cfg_attr(feature = "bindings", derive(TS))]
8974pub enum SeqPropKind {
8975    Start,
8976    Increment,
8977    Minvalue,
8978    Maxvalue,
8979    Cache,
8980    NoCache,
8981    Cycle,
8982    NoCycle,
8983    OwnedBy,
8984    Order,
8985    NoOrder,
8986    Comment,
8987    /// SHARING=<value> (Oracle)
8988    Sharing,
8989    /// KEEP (Oracle)
8990    Keep,
8991    /// NOKEEP (Oracle)
8992    NoKeep,
8993    /// SCALE [EXTEND|NOEXTEND] (Oracle)
8994    Scale,
8995    /// NOSCALE (Oracle)
8996    NoScale,
8997    /// SHARD [EXTEND|NOEXTEND] (Oracle)
8998    Shard,
8999    /// NOSHARD (Oracle)
9000    NoShard,
9001    /// SESSION (Oracle)
9002    Session,
9003    /// GLOBAL (Oracle)
9004    Global,
9005    /// NOCACHE (single word, Oracle)
9006    NoCacheWord,
9007    /// NOCYCLE (single word, Oracle)
9008    NoCycleWord,
9009    /// NOMINVALUE (single word, Oracle)
9010    NoMinvalueWord,
9011    /// NOMAXVALUE (single word, Oracle)
9012    NoMaxvalueWord,
9013}
9014
9015/// CREATE SEQUENCE statement
9016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9017#[cfg_attr(feature = "bindings", derive(TS))]
9018pub struct CreateSequence {
9019    pub name: TableRef,
9020    pub if_not_exists: bool,
9021    pub temporary: bool,
9022    #[serde(default)]
9023    pub or_replace: bool,
9024    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9025    #[serde(default, skip_serializing_if = "Option::is_none")]
9026    pub as_type: Option<DataType>,
9027    pub increment: Option<i64>,
9028    pub minvalue: Option<SequenceBound>,
9029    pub maxvalue: Option<SequenceBound>,
9030    pub start: Option<i64>,
9031    pub cache: Option<i64>,
9032    pub cycle: bool,
9033    pub owned_by: Option<TableRef>,
9034    /// Whether OWNED BY NONE was specified
9035    #[serde(default)]
9036    pub owned_by_none: bool,
9037    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9038    #[serde(default)]
9039    pub order: Option<bool>,
9040    /// Snowflake: COMMENT = 'value'
9041    #[serde(default)]
9042    pub comment: Option<String>,
9043    /// SHARING=<value> (Oracle)
9044    #[serde(default, skip_serializing_if = "Option::is_none")]
9045    pub sharing: Option<String>,
9046    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9047    #[serde(default, skip_serializing_if = "Option::is_none")]
9048    pub scale_modifier: Option<String>,
9049    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9050    #[serde(default, skip_serializing_if = "Option::is_none")]
9051    pub shard_modifier: Option<String>,
9052    /// Tracks the order in which properties appeared in the source
9053    #[serde(default)]
9054    pub property_order: Vec<SeqPropKind>,
9055}
9056
9057/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9059#[cfg_attr(feature = "bindings", derive(TS))]
9060pub enum SequenceBound {
9061    Value(i64),
9062    None,
9063}
9064
9065impl CreateSequence {
9066    pub fn new(name: impl Into<String>) -> Self {
9067        Self {
9068            name: TableRef::new(name),
9069            if_not_exists: false,
9070            temporary: false,
9071            or_replace: false,
9072            as_type: None,
9073            increment: None,
9074            minvalue: None,
9075            maxvalue: None,
9076            start: None,
9077            cache: None,
9078            cycle: false,
9079            owned_by: None,
9080            owned_by_none: false,
9081            order: None,
9082            comment: None,
9083            sharing: None,
9084            scale_modifier: None,
9085            shard_modifier: None,
9086            property_order: Vec::new(),
9087        }
9088    }
9089}
9090
9091/// DROP SEQUENCE statement
9092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9093#[cfg_attr(feature = "bindings", derive(TS))]
9094pub struct DropSequence {
9095    pub name: TableRef,
9096    pub if_exists: bool,
9097    pub cascade: bool,
9098}
9099
9100impl DropSequence {
9101    pub fn new(name: impl Into<String>) -> Self {
9102        Self {
9103            name: TableRef::new(name),
9104            if_exists: false,
9105            cascade: false,
9106        }
9107    }
9108}
9109
9110/// ALTER SEQUENCE statement
9111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9112#[cfg_attr(feature = "bindings", derive(TS))]
9113pub struct AlterSequence {
9114    pub name: TableRef,
9115    pub if_exists: bool,
9116    pub increment: Option<i64>,
9117    pub minvalue: Option<SequenceBound>,
9118    pub maxvalue: Option<SequenceBound>,
9119    pub start: Option<i64>,
9120    pub restart: Option<Option<i64>>,
9121    pub cache: Option<i64>,
9122    pub cycle: Option<bool>,
9123    pub owned_by: Option<Option<TableRef>>,
9124}
9125
9126impl AlterSequence {
9127    pub fn new(name: impl Into<String>) -> Self {
9128        Self {
9129            name: TableRef::new(name),
9130            if_exists: false,
9131            increment: None,
9132            minvalue: None,
9133            maxvalue: None,
9134            start: None,
9135            restart: None,
9136            cache: None,
9137            cycle: None,
9138            owned_by: None,
9139        }
9140    }
9141}
9142
9143/// CREATE TRIGGER statement
9144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9145#[cfg_attr(feature = "bindings", derive(TS))]
9146pub struct CreateTrigger {
9147    pub name: Identifier,
9148    pub table: TableRef,
9149    pub timing: TriggerTiming,
9150    pub events: Vec<TriggerEvent>,
9151    #[serde(default, skip_serializing_if = "Option::is_none")]
9152    pub for_each: Option<TriggerForEach>,
9153    pub when: Option<Expression>,
9154    /// Whether the WHEN clause was parenthesized in the original SQL
9155    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9156    pub when_paren: bool,
9157    pub body: TriggerBody,
9158    pub or_replace: bool,
9159    pub constraint: bool,
9160    pub deferrable: Option<bool>,
9161    pub initially_deferred: Option<bool>,
9162    pub referencing: Option<TriggerReferencing>,
9163}
9164
9165/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9166#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9167#[cfg_attr(feature = "bindings", derive(TS))]
9168pub enum TriggerTiming {
9169    Before,
9170    After,
9171    InsteadOf,
9172}
9173
9174/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9176#[cfg_attr(feature = "bindings", derive(TS))]
9177pub enum TriggerEvent {
9178    Insert,
9179    Update(Option<Vec<Identifier>>),
9180    Delete,
9181    Truncate,
9182}
9183
9184/// Trigger FOR EACH clause
9185#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9186#[cfg_attr(feature = "bindings", derive(TS))]
9187pub enum TriggerForEach {
9188    Row,
9189    Statement,
9190}
9191
9192/// Trigger body
9193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9194#[cfg_attr(feature = "bindings", derive(TS))]
9195pub enum TriggerBody {
9196    /// EXECUTE FUNCTION/PROCEDURE name(args)
9197    Execute {
9198        function: TableRef,
9199        args: Vec<Expression>,
9200    },
9201    /// BEGIN ... END block
9202    Block(String),
9203}
9204
9205/// Trigger REFERENCING clause
9206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9207#[cfg_attr(feature = "bindings", derive(TS))]
9208pub struct TriggerReferencing {
9209    pub old_table: Option<Identifier>,
9210    pub new_table: Option<Identifier>,
9211    pub old_row: Option<Identifier>,
9212    pub new_row: Option<Identifier>,
9213}
9214
9215impl CreateTrigger {
9216    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9217        Self {
9218            name: Identifier::new(name),
9219            table: TableRef::new(table),
9220            timing: TriggerTiming::Before,
9221            events: Vec::new(),
9222            for_each: Some(TriggerForEach::Row),
9223            when: None,
9224            when_paren: false,
9225            body: TriggerBody::Execute {
9226                function: TableRef::new(""),
9227                args: Vec::new(),
9228            },
9229            or_replace: false,
9230            constraint: false,
9231            deferrable: None,
9232            initially_deferred: None,
9233            referencing: None,
9234        }
9235    }
9236}
9237
9238/// DROP TRIGGER statement
9239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9240#[cfg_attr(feature = "bindings", derive(TS))]
9241pub struct DropTrigger {
9242    pub name: Identifier,
9243    pub table: Option<TableRef>,
9244    pub if_exists: bool,
9245    pub cascade: bool,
9246}
9247
9248impl DropTrigger {
9249    pub fn new(name: impl Into<String>) -> Self {
9250        Self {
9251            name: Identifier::new(name),
9252            table: None,
9253            if_exists: false,
9254            cascade: false,
9255        }
9256    }
9257}
9258
9259/// CREATE TYPE statement
9260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9261#[cfg_attr(feature = "bindings", derive(TS))]
9262pub struct CreateType {
9263    pub name: TableRef,
9264    pub definition: TypeDefinition,
9265    pub if_not_exists: bool,
9266}
9267
9268/// Type definition
9269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9270#[cfg_attr(feature = "bindings", derive(TS))]
9271pub enum TypeDefinition {
9272    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9273    Enum(Vec<String>),
9274    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9275    Composite(Vec<TypeAttribute>),
9276    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9277    Range {
9278        subtype: DataType,
9279        subtype_diff: Option<String>,
9280        canonical: Option<String>,
9281    },
9282    /// Base type (for advanced usage)
9283    Base {
9284        input: String,
9285        output: String,
9286        internallength: Option<i32>,
9287    },
9288    /// Domain type
9289    Domain {
9290        base_type: DataType,
9291        default: Option<Expression>,
9292        constraints: Vec<DomainConstraint>,
9293    },
9294}
9295
9296/// Type attribute for composite types
9297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9298#[cfg_attr(feature = "bindings", derive(TS))]
9299pub struct TypeAttribute {
9300    pub name: Identifier,
9301    pub data_type: DataType,
9302    pub collate: Option<Identifier>,
9303}
9304
9305/// Domain constraint
9306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9307#[cfg_attr(feature = "bindings", derive(TS))]
9308pub struct DomainConstraint {
9309    pub name: Option<Identifier>,
9310    pub check: Expression,
9311}
9312
9313impl CreateType {
9314    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9315        Self {
9316            name: TableRef::new(name),
9317            definition: TypeDefinition::Enum(values),
9318            if_not_exists: false,
9319        }
9320    }
9321
9322    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9323        Self {
9324            name: TableRef::new(name),
9325            definition: TypeDefinition::Composite(attributes),
9326            if_not_exists: false,
9327        }
9328    }
9329}
9330
9331/// DROP TYPE statement
9332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9333#[cfg_attr(feature = "bindings", derive(TS))]
9334pub struct DropType {
9335    pub name: TableRef,
9336    pub if_exists: bool,
9337    pub cascade: bool,
9338}
9339
9340impl DropType {
9341    pub fn new(name: impl Into<String>) -> Self {
9342        Self {
9343            name: TableRef::new(name),
9344            if_exists: false,
9345            cascade: false,
9346        }
9347    }
9348}
9349
9350/// DESCRIBE statement - shows table structure or query plan
9351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9352#[cfg_attr(feature = "bindings", derive(TS))]
9353pub struct Describe {
9354    /// The target to describe (table name or query)
9355    pub target: Expression,
9356    /// EXTENDED format
9357    pub extended: bool,
9358    /// FORMATTED format
9359    pub formatted: bool,
9360    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9361    #[serde(default)]
9362    pub kind: Option<String>,
9363    /// Properties like type=stage
9364    #[serde(default)]
9365    pub properties: Vec<(String, String)>,
9366    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9367    #[serde(default, skip_serializing_if = "Option::is_none")]
9368    pub style: Option<String>,
9369    /// Partition specification for DESCRIBE PARTITION
9370    #[serde(default)]
9371    pub partition: Option<Box<Expression>>,
9372    /// Leading comments before the statement
9373    #[serde(default)]
9374    pub leading_comments: Vec<String>,
9375    /// AS JSON suffix (Databricks)
9376    #[serde(default)]
9377    pub as_json: bool,
9378}
9379
9380impl Describe {
9381    pub fn new(target: Expression) -> Self {
9382        Self {
9383            target,
9384            extended: false,
9385            formatted: false,
9386            kind: None,
9387            properties: Vec::new(),
9388            style: None,
9389            partition: None,
9390            leading_comments: Vec::new(),
9391            as_json: false,
9392        }
9393    }
9394}
9395
9396/// SHOW statement - displays database objects
9397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9398#[cfg_attr(feature = "bindings", derive(TS))]
9399pub struct Show {
9400    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9401    pub this: String,
9402    /// Whether TERSE was specified
9403    #[serde(default)]
9404    pub terse: bool,
9405    /// Whether HISTORY was specified
9406    #[serde(default)]
9407    pub history: bool,
9408    /// LIKE pattern
9409    pub like: Option<Expression>,
9410    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9411    pub scope_kind: Option<String>,
9412    /// IN scope object
9413    pub scope: Option<Expression>,
9414    /// STARTS WITH pattern
9415    pub starts_with: Option<Expression>,
9416    /// LIMIT clause
9417    pub limit: Option<Box<Limit>>,
9418    /// FROM clause (for specific object)
9419    pub from: Option<Expression>,
9420    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9421    #[serde(default, skip_serializing_if = "Option::is_none")]
9422    pub where_clause: Option<Expression>,
9423    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9424    #[serde(default, skip_serializing_if = "Option::is_none")]
9425    pub for_target: Option<Expression>,
9426    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9427    #[serde(default, skip_serializing_if = "Option::is_none")]
9428    pub db: Option<Expression>,
9429    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9430    #[serde(default, skip_serializing_if = "Option::is_none")]
9431    pub target: Option<Expression>,
9432    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9433    #[serde(default, skip_serializing_if = "Option::is_none")]
9434    pub mutex: Option<bool>,
9435    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9436    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9437    pub privileges: Vec<String>,
9438}
9439
9440impl Show {
9441    pub fn new(this: impl Into<String>) -> Self {
9442        Self {
9443            this: this.into(),
9444            terse: false,
9445            history: false,
9446            like: None,
9447            scope_kind: None,
9448            scope: None,
9449            starts_with: None,
9450            limit: None,
9451            from: None,
9452            where_clause: None,
9453            for_target: None,
9454            db: None,
9455            target: None,
9456            mutex: None,
9457            privileges: Vec::new(),
9458        }
9459    }
9460}
9461
9462/// Represent an explicit parenthesized expression for grouping precedence.
9463///
9464/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9465/// correctly instead of being flattened to `a + b * c`.
9466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9467#[cfg_attr(feature = "bindings", derive(TS))]
9468pub struct Paren {
9469    /// The inner expression wrapped by parentheses.
9470    pub this: Expression,
9471    #[serde(default)]
9472    pub trailing_comments: Vec<String>,
9473}
9474
9475/// Expression annotated with trailing comments (for round-trip preservation)
9476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9477#[cfg_attr(feature = "bindings", derive(TS))]
9478pub struct Annotated {
9479    pub this: Expression,
9480    pub trailing_comments: Vec<String>,
9481}
9482
9483// === BATCH GENERATED STRUCT DEFINITIONS ===
9484// Generated from Python sqlglot expressions.py
9485
9486/// Refresh
9487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9488#[cfg_attr(feature = "bindings", derive(TS))]
9489pub struct Refresh {
9490    pub this: Box<Expression>,
9491    pub kind: String,
9492}
9493
9494/// LockingStatement
9495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9496#[cfg_attr(feature = "bindings", derive(TS))]
9497pub struct LockingStatement {
9498    pub this: Box<Expression>,
9499    pub expression: Box<Expression>,
9500}
9501
9502/// SequenceProperties
9503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9504#[cfg_attr(feature = "bindings", derive(TS))]
9505pub struct SequenceProperties {
9506    #[serde(default)]
9507    pub increment: Option<Box<Expression>>,
9508    #[serde(default)]
9509    pub minvalue: Option<Box<Expression>>,
9510    #[serde(default)]
9511    pub maxvalue: Option<Box<Expression>>,
9512    #[serde(default)]
9513    pub cache: Option<Box<Expression>>,
9514    #[serde(default)]
9515    pub start: Option<Box<Expression>>,
9516    #[serde(default)]
9517    pub owned: Option<Box<Expression>>,
9518    #[serde(default)]
9519    pub options: Vec<Expression>,
9520}
9521
9522/// TruncateTable
9523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9524#[cfg_attr(feature = "bindings", derive(TS))]
9525pub struct TruncateTable {
9526    #[serde(default)]
9527    pub expressions: Vec<Expression>,
9528    #[serde(default)]
9529    pub is_database: Option<Box<Expression>>,
9530    #[serde(default)]
9531    pub exists: bool,
9532    #[serde(default)]
9533    pub only: Option<Box<Expression>>,
9534    #[serde(default)]
9535    pub cluster: Option<Box<Expression>>,
9536    #[serde(default)]
9537    pub identity: Option<Box<Expression>>,
9538    #[serde(default)]
9539    pub option: Option<Box<Expression>>,
9540    #[serde(default)]
9541    pub partition: Option<Box<Expression>>,
9542}
9543
9544/// Clone
9545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub struct Clone {
9548    pub this: Box<Expression>,
9549    #[serde(default)]
9550    pub shallow: Option<Box<Expression>>,
9551    #[serde(default)]
9552    pub copy: Option<Box<Expression>>,
9553}
9554
9555/// Attach
9556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9557#[cfg_attr(feature = "bindings", derive(TS))]
9558pub struct Attach {
9559    pub this: Box<Expression>,
9560    #[serde(default)]
9561    pub exists: bool,
9562    #[serde(default)]
9563    pub expressions: Vec<Expression>,
9564}
9565
9566/// Detach
9567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9568#[cfg_attr(feature = "bindings", derive(TS))]
9569pub struct Detach {
9570    pub this: Box<Expression>,
9571    #[serde(default)]
9572    pub exists: bool,
9573}
9574
9575/// Install
9576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9577#[cfg_attr(feature = "bindings", derive(TS))]
9578pub struct Install {
9579    pub this: Box<Expression>,
9580    #[serde(default)]
9581    pub from_: Option<Box<Expression>>,
9582    #[serde(default)]
9583    pub force: Option<Box<Expression>>,
9584}
9585
9586/// Summarize
9587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9588#[cfg_attr(feature = "bindings", derive(TS))]
9589pub struct Summarize {
9590    pub this: Box<Expression>,
9591    #[serde(default)]
9592    pub table: Option<Box<Expression>>,
9593}
9594
9595/// Declare
9596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9597#[cfg_attr(feature = "bindings", derive(TS))]
9598pub struct Declare {
9599    #[serde(default)]
9600    pub expressions: Vec<Expression>,
9601    #[serde(default)]
9602    pub replace: bool,
9603}
9604
9605/// DeclareItem
9606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9607#[cfg_attr(feature = "bindings", derive(TS))]
9608pub struct DeclareItem {
9609    pub this: Box<Expression>,
9610    #[serde(default)]
9611    pub kind: Option<String>,
9612    #[serde(default)]
9613    pub default: Option<Box<Expression>>,
9614    #[serde(default)]
9615    pub has_as: bool,
9616    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
9617    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9618    pub additional_names: Vec<Expression>,
9619}
9620
9621/// Set
9622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9623#[cfg_attr(feature = "bindings", derive(TS))]
9624pub struct Set {
9625    #[serde(default)]
9626    pub expressions: Vec<Expression>,
9627    #[serde(default)]
9628    pub unset: Option<Box<Expression>>,
9629    #[serde(default)]
9630    pub tag: Option<Box<Expression>>,
9631}
9632
9633/// Heredoc
9634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9635#[cfg_attr(feature = "bindings", derive(TS))]
9636pub struct Heredoc {
9637    pub this: Box<Expression>,
9638    #[serde(default)]
9639    pub tag: Option<Box<Expression>>,
9640}
9641
9642/// QueryBand
9643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9644#[cfg_attr(feature = "bindings", derive(TS))]
9645pub struct QueryBand {
9646    pub this: Box<Expression>,
9647    #[serde(default)]
9648    pub scope: Option<Box<Expression>>,
9649    #[serde(default)]
9650    pub update: Option<Box<Expression>>,
9651}
9652
9653/// UserDefinedFunction
9654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9655#[cfg_attr(feature = "bindings", derive(TS))]
9656pub struct UserDefinedFunction {
9657    pub this: Box<Expression>,
9658    #[serde(default)]
9659    pub expressions: Vec<Expression>,
9660    #[serde(default)]
9661    pub wrapped: Option<Box<Expression>>,
9662}
9663
9664/// RecursiveWithSearch
9665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9666#[cfg_attr(feature = "bindings", derive(TS))]
9667pub struct RecursiveWithSearch {
9668    pub kind: String,
9669    pub this: Box<Expression>,
9670    pub expression: Box<Expression>,
9671    #[serde(default)]
9672    pub using: Option<Box<Expression>>,
9673}
9674
9675/// ProjectionDef
9676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9677#[cfg_attr(feature = "bindings", derive(TS))]
9678pub struct ProjectionDef {
9679    pub this: Box<Expression>,
9680    pub expression: Box<Expression>,
9681}
9682
9683/// TableAlias
9684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9685#[cfg_attr(feature = "bindings", derive(TS))]
9686pub struct TableAlias {
9687    #[serde(default)]
9688    pub this: Option<Box<Expression>>,
9689    #[serde(default)]
9690    pub columns: Vec<Expression>,
9691}
9692
9693/// ByteString
9694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9695#[cfg_attr(feature = "bindings", derive(TS))]
9696pub struct ByteString {
9697    pub this: Box<Expression>,
9698    #[serde(default)]
9699    pub is_bytes: Option<Box<Expression>>,
9700}
9701
9702/// HexStringExpr - Hex string expression (not literal)
9703/// BigQuery: converts to FROM_HEX(this)
9704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9705#[cfg_attr(feature = "bindings", derive(TS))]
9706pub struct HexStringExpr {
9707    pub this: Box<Expression>,
9708    #[serde(default)]
9709    pub is_integer: Option<bool>,
9710}
9711
9712/// UnicodeString
9713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9714#[cfg_attr(feature = "bindings", derive(TS))]
9715pub struct UnicodeString {
9716    pub this: Box<Expression>,
9717    #[serde(default)]
9718    pub escape: Option<Box<Expression>>,
9719}
9720
9721/// AlterColumn
9722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9723#[cfg_attr(feature = "bindings", derive(TS))]
9724pub struct AlterColumn {
9725    pub this: Box<Expression>,
9726    #[serde(default)]
9727    pub dtype: Option<Box<Expression>>,
9728    #[serde(default)]
9729    pub collate: Option<Box<Expression>>,
9730    #[serde(default)]
9731    pub using: Option<Box<Expression>>,
9732    #[serde(default)]
9733    pub default: Option<Box<Expression>>,
9734    #[serde(default)]
9735    pub drop: Option<Box<Expression>>,
9736    #[serde(default)]
9737    pub comment: Option<Box<Expression>>,
9738    #[serde(default)]
9739    pub allow_null: Option<Box<Expression>>,
9740    #[serde(default)]
9741    pub visible: Option<Box<Expression>>,
9742    #[serde(default)]
9743    pub rename_to: Option<Box<Expression>>,
9744}
9745
9746/// AlterSortKey
9747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9748#[cfg_attr(feature = "bindings", derive(TS))]
9749pub struct AlterSortKey {
9750    #[serde(default)]
9751    pub this: Option<Box<Expression>>,
9752    #[serde(default)]
9753    pub expressions: Vec<Expression>,
9754    #[serde(default)]
9755    pub compound: Option<Box<Expression>>,
9756}
9757
9758/// AlterSet
9759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9760#[cfg_attr(feature = "bindings", derive(TS))]
9761pub struct AlterSet {
9762    #[serde(default)]
9763    pub expressions: Vec<Expression>,
9764    #[serde(default)]
9765    pub option: Option<Box<Expression>>,
9766    #[serde(default)]
9767    pub tablespace: Option<Box<Expression>>,
9768    #[serde(default)]
9769    pub access_method: Option<Box<Expression>>,
9770    #[serde(default)]
9771    pub file_format: Option<Box<Expression>>,
9772    #[serde(default)]
9773    pub copy_options: Option<Box<Expression>>,
9774    #[serde(default)]
9775    pub tag: Option<Box<Expression>>,
9776    #[serde(default)]
9777    pub location: Option<Box<Expression>>,
9778    #[serde(default)]
9779    pub serde: Option<Box<Expression>>,
9780}
9781
9782/// RenameColumn
9783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9784#[cfg_attr(feature = "bindings", derive(TS))]
9785pub struct RenameColumn {
9786    pub this: Box<Expression>,
9787    #[serde(default)]
9788    pub to: Option<Box<Expression>>,
9789    #[serde(default)]
9790    pub exists: bool,
9791}
9792
9793/// Comprehension
9794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9795#[cfg_attr(feature = "bindings", derive(TS))]
9796pub struct Comprehension {
9797    pub this: Box<Expression>,
9798    pub expression: Box<Expression>,
9799    #[serde(default)]
9800    pub position: Option<Box<Expression>>,
9801    #[serde(default)]
9802    pub iterator: Option<Box<Expression>>,
9803    #[serde(default)]
9804    pub condition: Option<Box<Expression>>,
9805}
9806
9807/// MergeTreeTTLAction
9808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9809#[cfg_attr(feature = "bindings", derive(TS))]
9810pub struct MergeTreeTTLAction {
9811    pub this: Box<Expression>,
9812    #[serde(default)]
9813    pub delete: Option<Box<Expression>>,
9814    #[serde(default)]
9815    pub recompress: Option<Box<Expression>>,
9816    #[serde(default)]
9817    pub to_disk: Option<Box<Expression>>,
9818    #[serde(default)]
9819    pub to_volume: Option<Box<Expression>>,
9820}
9821
9822/// MergeTreeTTL
9823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9824#[cfg_attr(feature = "bindings", derive(TS))]
9825pub struct MergeTreeTTL {
9826    #[serde(default)]
9827    pub expressions: Vec<Expression>,
9828    #[serde(default)]
9829    pub where_: Option<Box<Expression>>,
9830    #[serde(default)]
9831    pub group: Option<Box<Expression>>,
9832    #[serde(default)]
9833    pub aggregates: Option<Box<Expression>>,
9834}
9835
9836/// IndexConstraintOption
9837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9838#[cfg_attr(feature = "bindings", derive(TS))]
9839pub struct IndexConstraintOption {
9840    #[serde(default)]
9841    pub key_block_size: Option<Box<Expression>>,
9842    #[serde(default)]
9843    pub using: Option<Box<Expression>>,
9844    #[serde(default)]
9845    pub parser: Option<Box<Expression>>,
9846    #[serde(default)]
9847    pub comment: Option<Box<Expression>>,
9848    #[serde(default)]
9849    pub visible: Option<Box<Expression>>,
9850    #[serde(default)]
9851    pub engine_attr: Option<Box<Expression>>,
9852    #[serde(default)]
9853    pub secondary_engine_attr: Option<Box<Expression>>,
9854}
9855
9856/// PeriodForSystemTimeConstraint
9857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9858#[cfg_attr(feature = "bindings", derive(TS))]
9859pub struct PeriodForSystemTimeConstraint {
9860    pub this: Box<Expression>,
9861    pub expression: Box<Expression>,
9862}
9863
9864/// CaseSpecificColumnConstraint
9865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9866#[cfg_attr(feature = "bindings", derive(TS))]
9867pub struct CaseSpecificColumnConstraint {
9868    #[serde(default)]
9869    pub not_: Option<Box<Expression>>,
9870}
9871
9872/// CharacterSetColumnConstraint
9873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9874#[cfg_attr(feature = "bindings", derive(TS))]
9875pub struct CharacterSetColumnConstraint {
9876    pub this: Box<Expression>,
9877}
9878
9879/// CheckColumnConstraint
9880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9881#[cfg_attr(feature = "bindings", derive(TS))]
9882pub struct CheckColumnConstraint {
9883    pub this: Box<Expression>,
9884    #[serde(default)]
9885    pub enforced: Option<Box<Expression>>,
9886}
9887
9888/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
9889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9890#[cfg_attr(feature = "bindings", derive(TS))]
9891pub struct AssumeColumnConstraint {
9892    pub this: Box<Expression>,
9893}
9894
9895/// CompressColumnConstraint
9896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9897#[cfg_attr(feature = "bindings", derive(TS))]
9898pub struct CompressColumnConstraint {
9899    #[serde(default)]
9900    pub this: Option<Box<Expression>>,
9901}
9902
9903/// DateFormatColumnConstraint
9904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9905#[cfg_attr(feature = "bindings", derive(TS))]
9906pub struct DateFormatColumnConstraint {
9907    pub this: Box<Expression>,
9908}
9909
9910/// EphemeralColumnConstraint
9911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9912#[cfg_attr(feature = "bindings", derive(TS))]
9913pub struct EphemeralColumnConstraint {
9914    #[serde(default)]
9915    pub this: Option<Box<Expression>>,
9916}
9917
9918/// WithOperator
9919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9920#[cfg_attr(feature = "bindings", derive(TS))]
9921pub struct WithOperator {
9922    pub this: Box<Expression>,
9923    pub op: String,
9924}
9925
9926/// GeneratedAsIdentityColumnConstraint
9927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9928#[cfg_attr(feature = "bindings", derive(TS))]
9929pub struct GeneratedAsIdentityColumnConstraint {
9930    #[serde(default)]
9931    pub this: Option<Box<Expression>>,
9932    #[serde(default)]
9933    pub expression: Option<Box<Expression>>,
9934    #[serde(default)]
9935    pub on_null: Option<Box<Expression>>,
9936    #[serde(default)]
9937    pub start: Option<Box<Expression>>,
9938    #[serde(default)]
9939    pub increment: Option<Box<Expression>>,
9940    #[serde(default)]
9941    pub minvalue: Option<Box<Expression>>,
9942    #[serde(default)]
9943    pub maxvalue: Option<Box<Expression>>,
9944    #[serde(default)]
9945    pub cycle: Option<Box<Expression>>,
9946    #[serde(default)]
9947    pub order: Option<Box<Expression>>,
9948}
9949
9950/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
9951/// TSQL: outputs "IDENTITY"
9952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9953#[cfg_attr(feature = "bindings", derive(TS))]
9954pub struct AutoIncrementColumnConstraint;
9955
9956/// CommentColumnConstraint - Column comment marker
9957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9958#[cfg_attr(feature = "bindings", derive(TS))]
9959pub struct CommentColumnConstraint;
9960
9961/// GeneratedAsRowColumnConstraint
9962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9963#[cfg_attr(feature = "bindings", derive(TS))]
9964pub struct GeneratedAsRowColumnConstraint {
9965    #[serde(default)]
9966    pub start: Option<Box<Expression>>,
9967    #[serde(default)]
9968    pub hidden: Option<Box<Expression>>,
9969}
9970
9971/// IndexColumnConstraint
9972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9973#[cfg_attr(feature = "bindings", derive(TS))]
9974pub struct IndexColumnConstraint {
9975    #[serde(default)]
9976    pub this: Option<Box<Expression>>,
9977    #[serde(default)]
9978    pub expressions: Vec<Expression>,
9979    #[serde(default)]
9980    pub kind: Option<String>,
9981    #[serde(default)]
9982    pub index_type: Option<Box<Expression>>,
9983    #[serde(default)]
9984    pub options: Vec<Expression>,
9985    #[serde(default)]
9986    pub expression: Option<Box<Expression>>,
9987    #[serde(default)]
9988    pub granularity: Option<Box<Expression>>,
9989}
9990
9991/// MaskingPolicyColumnConstraint
9992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9993#[cfg_attr(feature = "bindings", derive(TS))]
9994pub struct MaskingPolicyColumnConstraint {
9995    pub this: Box<Expression>,
9996    #[serde(default)]
9997    pub expressions: Vec<Expression>,
9998}
9999
10000/// NotNullColumnConstraint
10001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10002#[cfg_attr(feature = "bindings", derive(TS))]
10003pub struct NotNullColumnConstraint {
10004    #[serde(default)]
10005    pub allow_null: Option<Box<Expression>>,
10006}
10007
10008/// DefaultColumnConstraint - DEFAULT value for a column
10009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10010#[cfg_attr(feature = "bindings", derive(TS))]
10011pub struct DefaultColumnConstraint {
10012    pub this: Box<Expression>,
10013}
10014
10015/// PrimaryKeyColumnConstraint
10016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10017#[cfg_attr(feature = "bindings", derive(TS))]
10018pub struct PrimaryKeyColumnConstraint {
10019    #[serde(default)]
10020    pub desc: Option<Box<Expression>>,
10021    #[serde(default)]
10022    pub options: Vec<Expression>,
10023}
10024
10025/// UniqueColumnConstraint
10026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10027#[cfg_attr(feature = "bindings", derive(TS))]
10028pub struct UniqueColumnConstraint {
10029    #[serde(default)]
10030    pub this: Option<Box<Expression>>,
10031    #[serde(default)]
10032    pub index_type: Option<Box<Expression>>,
10033    #[serde(default)]
10034    pub on_conflict: Option<Box<Expression>>,
10035    #[serde(default)]
10036    pub nulls: Option<Box<Expression>>,
10037    #[serde(default)]
10038    pub options: Vec<Expression>,
10039}
10040
10041/// WatermarkColumnConstraint
10042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10043#[cfg_attr(feature = "bindings", derive(TS))]
10044pub struct WatermarkColumnConstraint {
10045    pub this: Box<Expression>,
10046    pub expression: Box<Expression>,
10047}
10048
10049/// ComputedColumnConstraint
10050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10051#[cfg_attr(feature = "bindings", derive(TS))]
10052pub struct ComputedColumnConstraint {
10053    pub this: Box<Expression>,
10054    #[serde(default)]
10055    pub persisted: Option<Box<Expression>>,
10056    #[serde(default)]
10057    pub not_null: Option<Box<Expression>>,
10058    #[serde(default)]
10059    pub data_type: Option<Box<Expression>>,
10060}
10061
10062/// InOutColumnConstraint
10063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10064#[cfg_attr(feature = "bindings", derive(TS))]
10065pub struct InOutColumnConstraint {
10066    #[serde(default)]
10067    pub input_: Option<Box<Expression>>,
10068    #[serde(default)]
10069    pub output: Option<Box<Expression>>,
10070}
10071
10072/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10074#[cfg_attr(feature = "bindings", derive(TS))]
10075pub struct PathColumnConstraint {
10076    pub this: Box<Expression>,
10077}
10078
10079/// Constraint
10080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10081#[cfg_attr(feature = "bindings", derive(TS))]
10082pub struct Constraint {
10083    pub this: Box<Expression>,
10084    #[serde(default)]
10085    pub expressions: Vec<Expression>,
10086}
10087
10088/// Export
10089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10090#[cfg_attr(feature = "bindings", derive(TS))]
10091pub struct Export {
10092    pub this: Box<Expression>,
10093    #[serde(default)]
10094    pub connection: Option<Box<Expression>>,
10095    #[serde(default)]
10096    pub options: Vec<Expression>,
10097}
10098
10099/// Filter
10100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10101#[cfg_attr(feature = "bindings", derive(TS))]
10102pub struct Filter {
10103    pub this: Box<Expression>,
10104    pub expression: Box<Expression>,
10105}
10106
10107/// Changes
10108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10109#[cfg_attr(feature = "bindings", derive(TS))]
10110pub struct Changes {
10111    #[serde(default)]
10112    pub information: Option<Box<Expression>>,
10113    #[serde(default)]
10114    pub at_before: Option<Box<Expression>>,
10115    #[serde(default)]
10116    pub end: Option<Box<Expression>>,
10117}
10118
10119/// Directory
10120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10121#[cfg_attr(feature = "bindings", derive(TS))]
10122pub struct Directory {
10123    pub this: Box<Expression>,
10124    #[serde(default)]
10125    pub local: Option<Box<Expression>>,
10126    #[serde(default)]
10127    pub row_format: Option<Box<Expression>>,
10128}
10129
10130/// ForeignKey
10131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10132#[cfg_attr(feature = "bindings", derive(TS))]
10133pub struct ForeignKey {
10134    #[serde(default)]
10135    pub expressions: Vec<Expression>,
10136    #[serde(default)]
10137    pub reference: Option<Box<Expression>>,
10138    #[serde(default)]
10139    pub delete: Option<Box<Expression>>,
10140    #[serde(default)]
10141    pub update: Option<Box<Expression>>,
10142    #[serde(default)]
10143    pub options: Vec<Expression>,
10144}
10145
10146/// ColumnPrefix
10147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10148#[cfg_attr(feature = "bindings", derive(TS))]
10149pub struct ColumnPrefix {
10150    pub this: Box<Expression>,
10151    pub expression: Box<Expression>,
10152}
10153
10154/// PrimaryKey
10155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10156#[cfg_attr(feature = "bindings", derive(TS))]
10157pub struct PrimaryKey {
10158    #[serde(default)]
10159    pub this: Option<Box<Expression>>,
10160    #[serde(default)]
10161    pub expressions: Vec<Expression>,
10162    #[serde(default)]
10163    pub options: Vec<Expression>,
10164    #[serde(default)]
10165    pub include: Option<Box<Expression>>,
10166}
10167
10168/// Into
10169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10170#[cfg_attr(feature = "bindings", derive(TS))]
10171pub struct IntoClause {
10172    #[serde(default)]
10173    pub this: Option<Box<Expression>>,
10174    #[serde(default)]
10175    pub temporary: bool,
10176    #[serde(default)]
10177    pub unlogged: Option<Box<Expression>>,
10178    #[serde(default)]
10179    pub bulk_collect: Option<Box<Expression>>,
10180    #[serde(default)]
10181    pub expressions: Vec<Expression>,
10182}
10183
10184/// JoinHint
10185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10186#[cfg_attr(feature = "bindings", derive(TS))]
10187pub struct JoinHint {
10188    pub this: Box<Expression>,
10189    #[serde(default)]
10190    pub expressions: Vec<Expression>,
10191}
10192
10193/// Opclass
10194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10195#[cfg_attr(feature = "bindings", derive(TS))]
10196pub struct Opclass {
10197    pub this: Box<Expression>,
10198    pub expression: Box<Expression>,
10199}
10200
10201/// Index
10202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10203#[cfg_attr(feature = "bindings", derive(TS))]
10204pub struct Index {
10205    #[serde(default)]
10206    pub this: Option<Box<Expression>>,
10207    #[serde(default)]
10208    pub table: Option<Box<Expression>>,
10209    #[serde(default)]
10210    pub unique: bool,
10211    #[serde(default)]
10212    pub primary: Option<Box<Expression>>,
10213    #[serde(default)]
10214    pub amp: Option<Box<Expression>>,
10215    #[serde(default)]
10216    pub params: Vec<Expression>,
10217}
10218
10219/// IndexParameters
10220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10221#[cfg_attr(feature = "bindings", derive(TS))]
10222pub struct IndexParameters {
10223    #[serde(default)]
10224    pub using: Option<Box<Expression>>,
10225    #[serde(default)]
10226    pub include: Option<Box<Expression>>,
10227    #[serde(default)]
10228    pub columns: Vec<Expression>,
10229    #[serde(default)]
10230    pub with_storage: Option<Box<Expression>>,
10231    #[serde(default)]
10232    pub partition_by: Option<Box<Expression>>,
10233    #[serde(default)]
10234    pub tablespace: Option<Box<Expression>>,
10235    #[serde(default)]
10236    pub where_: Option<Box<Expression>>,
10237    #[serde(default)]
10238    pub on: Option<Box<Expression>>,
10239}
10240
10241/// ConditionalInsert
10242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10243#[cfg_attr(feature = "bindings", derive(TS))]
10244pub struct ConditionalInsert {
10245    pub this: Box<Expression>,
10246    #[serde(default)]
10247    pub expression: Option<Box<Expression>>,
10248    #[serde(default)]
10249    pub else_: Option<Box<Expression>>,
10250}
10251
10252/// MultitableInserts
10253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10254#[cfg_attr(feature = "bindings", derive(TS))]
10255pub struct MultitableInserts {
10256    #[serde(default)]
10257    pub expressions: Vec<Expression>,
10258    pub kind: String,
10259    #[serde(default)]
10260    pub source: Option<Box<Expression>>,
10261    /// Leading comments before the statement
10262    #[serde(default)]
10263    pub leading_comments: Vec<String>,
10264}
10265
10266/// OnConflict
10267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10268#[cfg_attr(feature = "bindings", derive(TS))]
10269pub struct OnConflict {
10270    #[serde(default)]
10271    pub duplicate: Option<Box<Expression>>,
10272    #[serde(default)]
10273    pub expressions: Vec<Expression>,
10274    #[serde(default)]
10275    pub action: Option<Box<Expression>>,
10276    #[serde(default)]
10277    pub conflict_keys: Option<Box<Expression>>,
10278    #[serde(default)]
10279    pub index_predicate: Option<Box<Expression>>,
10280    #[serde(default)]
10281    pub constraint: Option<Box<Expression>>,
10282    #[serde(default)]
10283    pub where_: Option<Box<Expression>>,
10284}
10285
10286/// OnCondition
10287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10288#[cfg_attr(feature = "bindings", derive(TS))]
10289pub struct OnCondition {
10290    #[serde(default)]
10291    pub error: Option<Box<Expression>>,
10292    #[serde(default)]
10293    pub empty: Option<Box<Expression>>,
10294    #[serde(default)]
10295    pub null: Option<Box<Expression>>,
10296}
10297
10298/// Returning
10299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10300#[cfg_attr(feature = "bindings", derive(TS))]
10301pub struct Returning {
10302    #[serde(default)]
10303    pub expressions: Vec<Expression>,
10304    #[serde(default)]
10305    pub into: Option<Box<Expression>>,
10306}
10307
10308/// Introducer
10309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10310#[cfg_attr(feature = "bindings", derive(TS))]
10311pub struct Introducer {
10312    pub this: Box<Expression>,
10313    pub expression: Box<Expression>,
10314}
10315
10316/// PartitionRange
10317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10318#[cfg_attr(feature = "bindings", derive(TS))]
10319pub struct PartitionRange {
10320    pub this: Box<Expression>,
10321    #[serde(default)]
10322    pub expression: Option<Box<Expression>>,
10323    #[serde(default)]
10324    pub expressions: Vec<Expression>,
10325}
10326
10327/// Group
10328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10329#[cfg_attr(feature = "bindings", derive(TS))]
10330pub struct Group {
10331    #[serde(default)]
10332    pub expressions: Vec<Expression>,
10333    #[serde(default)]
10334    pub grouping_sets: Option<Box<Expression>>,
10335    #[serde(default)]
10336    pub cube: Option<Box<Expression>>,
10337    #[serde(default)]
10338    pub rollup: Option<Box<Expression>>,
10339    #[serde(default)]
10340    pub totals: Option<Box<Expression>>,
10341    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10342    #[serde(default)]
10343    pub all: Option<bool>,
10344}
10345
10346/// Cube
10347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10348#[cfg_attr(feature = "bindings", derive(TS))]
10349pub struct Cube {
10350    #[serde(default)]
10351    pub expressions: Vec<Expression>,
10352}
10353
10354/// Rollup
10355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10356#[cfg_attr(feature = "bindings", derive(TS))]
10357pub struct Rollup {
10358    #[serde(default)]
10359    pub expressions: Vec<Expression>,
10360}
10361
10362/// GroupingSets
10363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10364#[cfg_attr(feature = "bindings", derive(TS))]
10365pub struct GroupingSets {
10366    #[serde(default)]
10367    pub expressions: Vec<Expression>,
10368}
10369
10370/// LimitOptions
10371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10372#[cfg_attr(feature = "bindings", derive(TS))]
10373pub struct LimitOptions {
10374    #[serde(default)]
10375    pub percent: Option<Box<Expression>>,
10376    #[serde(default)]
10377    pub rows: Option<Box<Expression>>,
10378    #[serde(default)]
10379    pub with_ties: Option<Box<Expression>>,
10380}
10381
10382/// Lateral
10383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10384#[cfg_attr(feature = "bindings", derive(TS))]
10385pub struct Lateral {
10386    pub this: Box<Expression>,
10387    #[serde(default)]
10388    pub view: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub outer: Option<Box<Expression>>,
10391    #[serde(default)]
10392    pub alias: Option<String>,
10393    /// Whether the alias was originally quoted (backtick/double-quote)
10394    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10395    pub alias_quoted: bool,
10396    #[serde(default)]
10397    pub cross_apply: Option<Box<Expression>>,
10398    #[serde(default)]
10399    pub ordinality: Option<Box<Expression>>,
10400    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10401    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10402    pub column_aliases: Vec<String>,
10403}
10404
10405/// TableFromRows
10406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10407#[cfg_attr(feature = "bindings", derive(TS))]
10408pub struct TableFromRows {
10409    pub this: Box<Expression>,
10410    #[serde(default)]
10411    pub alias: Option<String>,
10412    #[serde(default)]
10413    pub joins: Vec<Expression>,
10414    #[serde(default)]
10415    pub pivots: Option<Box<Expression>>,
10416    #[serde(default)]
10417    pub sample: Option<Box<Expression>>,
10418}
10419
10420/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10421/// Used for set-returning functions with typed column definitions
10422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10423#[cfg_attr(feature = "bindings", derive(TS))]
10424pub struct RowsFrom {
10425    /// List of function expressions, each potentially with an alias and typed columns
10426    pub expressions: Vec<Expression>,
10427    /// WITH ORDINALITY modifier
10428    #[serde(default)]
10429    pub ordinality: bool,
10430    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10431    #[serde(default)]
10432    pub alias: Option<Box<Expression>>,
10433}
10434
10435/// WithFill
10436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10437#[cfg_attr(feature = "bindings", derive(TS))]
10438pub struct WithFill {
10439    #[serde(default)]
10440    pub from_: Option<Box<Expression>>,
10441    #[serde(default)]
10442    pub to: Option<Box<Expression>>,
10443    #[serde(default)]
10444    pub step: Option<Box<Expression>>,
10445    #[serde(default)]
10446    pub staleness: Option<Box<Expression>>,
10447    #[serde(default)]
10448    pub interpolate: Option<Box<Expression>>,
10449}
10450
10451/// Property
10452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10453#[cfg_attr(feature = "bindings", derive(TS))]
10454pub struct Property {
10455    pub this: Box<Expression>,
10456    #[serde(default)]
10457    pub value: Option<Box<Expression>>,
10458}
10459
10460/// GrantPrivilege
10461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10462#[cfg_attr(feature = "bindings", derive(TS))]
10463pub struct GrantPrivilege {
10464    pub this: Box<Expression>,
10465    #[serde(default)]
10466    pub expressions: Vec<Expression>,
10467}
10468
10469/// AllowedValuesProperty
10470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10471#[cfg_attr(feature = "bindings", derive(TS))]
10472pub struct AllowedValuesProperty {
10473    #[serde(default)]
10474    pub expressions: Vec<Expression>,
10475}
10476
10477/// AlgorithmProperty
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct AlgorithmProperty {
10481    pub this: Box<Expression>,
10482}
10483
10484/// AutoIncrementProperty
10485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10486#[cfg_attr(feature = "bindings", derive(TS))]
10487pub struct AutoIncrementProperty {
10488    pub this: Box<Expression>,
10489}
10490
10491/// AutoRefreshProperty
10492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10493#[cfg_attr(feature = "bindings", derive(TS))]
10494pub struct AutoRefreshProperty {
10495    pub this: Box<Expression>,
10496}
10497
10498/// BackupProperty
10499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10500#[cfg_attr(feature = "bindings", derive(TS))]
10501pub struct BackupProperty {
10502    pub this: Box<Expression>,
10503}
10504
10505/// BuildProperty
10506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10507#[cfg_attr(feature = "bindings", derive(TS))]
10508pub struct BuildProperty {
10509    pub this: Box<Expression>,
10510}
10511
10512/// BlockCompressionProperty
10513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10514#[cfg_attr(feature = "bindings", derive(TS))]
10515pub struct BlockCompressionProperty {
10516    #[serde(default)]
10517    pub autotemp: Option<Box<Expression>>,
10518    #[serde(default)]
10519    pub always: Option<Box<Expression>>,
10520    #[serde(default)]
10521    pub default: Option<Box<Expression>>,
10522    #[serde(default)]
10523    pub manual: Option<Box<Expression>>,
10524    #[serde(default)]
10525    pub never: Option<Box<Expression>>,
10526}
10527
10528/// CharacterSetProperty
10529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10530#[cfg_attr(feature = "bindings", derive(TS))]
10531pub struct CharacterSetProperty {
10532    pub this: Box<Expression>,
10533    #[serde(default)]
10534    pub default: Option<Box<Expression>>,
10535}
10536
10537/// ChecksumProperty
10538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10539#[cfg_attr(feature = "bindings", derive(TS))]
10540pub struct ChecksumProperty {
10541    #[serde(default)]
10542    pub on: Option<Box<Expression>>,
10543    #[serde(default)]
10544    pub default: Option<Box<Expression>>,
10545}
10546
10547/// CollateProperty
10548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10549#[cfg_attr(feature = "bindings", derive(TS))]
10550pub struct CollateProperty {
10551    pub this: Box<Expression>,
10552    #[serde(default)]
10553    pub default: Option<Box<Expression>>,
10554}
10555
10556/// DataBlocksizeProperty
10557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10558#[cfg_attr(feature = "bindings", derive(TS))]
10559pub struct DataBlocksizeProperty {
10560    #[serde(default)]
10561    pub size: Option<i64>,
10562    #[serde(default)]
10563    pub units: Option<Box<Expression>>,
10564    #[serde(default)]
10565    pub minimum: Option<Box<Expression>>,
10566    #[serde(default)]
10567    pub maximum: Option<Box<Expression>>,
10568    #[serde(default)]
10569    pub default: Option<Box<Expression>>,
10570}
10571
10572/// DataDeletionProperty
10573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10574#[cfg_attr(feature = "bindings", derive(TS))]
10575pub struct DataDeletionProperty {
10576    pub on: Box<Expression>,
10577    #[serde(default)]
10578    pub filter_column: Option<Box<Expression>>,
10579    #[serde(default)]
10580    pub retention_period: Option<Box<Expression>>,
10581}
10582
10583/// DefinerProperty
10584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10585#[cfg_attr(feature = "bindings", derive(TS))]
10586pub struct DefinerProperty {
10587    pub this: Box<Expression>,
10588}
10589
10590/// DistKeyProperty
10591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10592#[cfg_attr(feature = "bindings", derive(TS))]
10593pub struct DistKeyProperty {
10594    pub this: Box<Expression>,
10595}
10596
10597/// DistributedByProperty
10598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10599#[cfg_attr(feature = "bindings", derive(TS))]
10600pub struct DistributedByProperty {
10601    #[serde(default)]
10602    pub expressions: Vec<Expression>,
10603    pub kind: String,
10604    #[serde(default)]
10605    pub buckets: Option<Box<Expression>>,
10606    #[serde(default)]
10607    pub order: Option<Box<Expression>>,
10608}
10609
10610/// DistStyleProperty
10611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10612#[cfg_attr(feature = "bindings", derive(TS))]
10613pub struct DistStyleProperty {
10614    pub this: Box<Expression>,
10615}
10616
10617/// DuplicateKeyProperty
10618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10619#[cfg_attr(feature = "bindings", derive(TS))]
10620pub struct DuplicateKeyProperty {
10621    #[serde(default)]
10622    pub expressions: Vec<Expression>,
10623}
10624
10625/// EngineProperty
10626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10627#[cfg_attr(feature = "bindings", derive(TS))]
10628pub struct EngineProperty {
10629    pub this: Box<Expression>,
10630}
10631
10632/// ToTableProperty
10633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10634#[cfg_attr(feature = "bindings", derive(TS))]
10635pub struct ToTableProperty {
10636    pub this: Box<Expression>,
10637}
10638
10639/// ExecuteAsProperty
10640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10641#[cfg_attr(feature = "bindings", derive(TS))]
10642pub struct ExecuteAsProperty {
10643    pub this: Box<Expression>,
10644}
10645
10646/// ExternalProperty
10647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10648#[cfg_attr(feature = "bindings", derive(TS))]
10649pub struct ExternalProperty {
10650    #[serde(default)]
10651    pub this: Option<Box<Expression>>,
10652}
10653
10654/// FallbackProperty
10655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10656#[cfg_attr(feature = "bindings", derive(TS))]
10657pub struct FallbackProperty {
10658    #[serde(default)]
10659    pub no: Option<Box<Expression>>,
10660    #[serde(default)]
10661    pub protection: Option<Box<Expression>>,
10662}
10663
10664/// FileFormatProperty
10665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10666#[cfg_attr(feature = "bindings", derive(TS))]
10667pub struct FileFormatProperty {
10668    #[serde(default)]
10669    pub this: Option<Box<Expression>>,
10670    #[serde(default)]
10671    pub expressions: Vec<Expression>,
10672    #[serde(default)]
10673    pub hive_format: Option<Box<Expression>>,
10674}
10675
10676/// CredentialsProperty
10677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10678#[cfg_attr(feature = "bindings", derive(TS))]
10679pub struct CredentialsProperty {
10680    #[serde(default)]
10681    pub expressions: Vec<Expression>,
10682}
10683
10684/// FreespaceProperty
10685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10686#[cfg_attr(feature = "bindings", derive(TS))]
10687pub struct FreespaceProperty {
10688    pub this: Box<Expression>,
10689    #[serde(default)]
10690    pub percent: Option<Box<Expression>>,
10691}
10692
10693/// InheritsProperty
10694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10695#[cfg_attr(feature = "bindings", derive(TS))]
10696pub struct InheritsProperty {
10697    #[serde(default)]
10698    pub expressions: Vec<Expression>,
10699}
10700
10701/// InputModelProperty
10702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10703#[cfg_attr(feature = "bindings", derive(TS))]
10704pub struct InputModelProperty {
10705    pub this: Box<Expression>,
10706}
10707
10708/// OutputModelProperty
10709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10710#[cfg_attr(feature = "bindings", derive(TS))]
10711pub struct OutputModelProperty {
10712    pub this: Box<Expression>,
10713}
10714
10715/// IsolatedLoadingProperty
10716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10717#[cfg_attr(feature = "bindings", derive(TS))]
10718pub struct IsolatedLoadingProperty {
10719    #[serde(default)]
10720    pub no: Option<Box<Expression>>,
10721    #[serde(default)]
10722    pub concurrent: Option<Box<Expression>>,
10723    #[serde(default)]
10724    pub target: Option<Box<Expression>>,
10725}
10726
10727/// JournalProperty
10728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10729#[cfg_attr(feature = "bindings", derive(TS))]
10730pub struct JournalProperty {
10731    #[serde(default)]
10732    pub no: Option<Box<Expression>>,
10733    #[serde(default)]
10734    pub dual: Option<Box<Expression>>,
10735    #[serde(default)]
10736    pub before: Option<Box<Expression>>,
10737    #[serde(default)]
10738    pub local: Option<Box<Expression>>,
10739    #[serde(default)]
10740    pub after: Option<Box<Expression>>,
10741}
10742
10743/// LanguageProperty
10744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10745#[cfg_attr(feature = "bindings", derive(TS))]
10746pub struct LanguageProperty {
10747    pub this: Box<Expression>,
10748}
10749
10750/// EnviromentProperty
10751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10752#[cfg_attr(feature = "bindings", derive(TS))]
10753pub struct EnviromentProperty {
10754    #[serde(default)]
10755    pub expressions: Vec<Expression>,
10756}
10757
10758/// ClusteredByProperty
10759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10760#[cfg_attr(feature = "bindings", derive(TS))]
10761pub struct ClusteredByProperty {
10762    #[serde(default)]
10763    pub expressions: Vec<Expression>,
10764    #[serde(default)]
10765    pub sorted_by: Option<Box<Expression>>,
10766    #[serde(default)]
10767    pub buckets: Option<Box<Expression>>,
10768}
10769
10770/// DictProperty
10771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10772#[cfg_attr(feature = "bindings", derive(TS))]
10773pub struct DictProperty {
10774    pub this: Box<Expression>,
10775    pub kind: String,
10776    #[serde(default)]
10777    pub settings: Option<Box<Expression>>,
10778}
10779
10780/// DictRange
10781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10782#[cfg_attr(feature = "bindings", derive(TS))]
10783pub struct DictRange {
10784    pub this: Box<Expression>,
10785    #[serde(default)]
10786    pub min: Option<Box<Expression>>,
10787    #[serde(default)]
10788    pub max: Option<Box<Expression>>,
10789}
10790
10791/// OnCluster
10792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10793#[cfg_attr(feature = "bindings", derive(TS))]
10794pub struct OnCluster {
10795    pub this: Box<Expression>,
10796}
10797
10798/// LikeProperty
10799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10800#[cfg_attr(feature = "bindings", derive(TS))]
10801pub struct LikeProperty {
10802    pub this: Box<Expression>,
10803    #[serde(default)]
10804    pub expressions: Vec<Expression>,
10805}
10806
10807/// LocationProperty
10808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10809#[cfg_attr(feature = "bindings", derive(TS))]
10810pub struct LocationProperty {
10811    pub this: Box<Expression>,
10812}
10813
10814/// LockProperty
10815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10816#[cfg_attr(feature = "bindings", derive(TS))]
10817pub struct LockProperty {
10818    pub this: Box<Expression>,
10819}
10820
10821/// LockingProperty
10822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10823#[cfg_attr(feature = "bindings", derive(TS))]
10824pub struct LockingProperty {
10825    #[serde(default)]
10826    pub this: Option<Box<Expression>>,
10827    pub kind: String,
10828    #[serde(default)]
10829    pub for_or_in: Option<Box<Expression>>,
10830    #[serde(default)]
10831    pub lock_type: Option<Box<Expression>>,
10832    #[serde(default)]
10833    pub override_: Option<Box<Expression>>,
10834}
10835
10836/// LogProperty
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct LogProperty {
10840    #[serde(default)]
10841    pub no: Option<Box<Expression>>,
10842}
10843
10844/// MaterializedProperty
10845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10846#[cfg_attr(feature = "bindings", derive(TS))]
10847pub struct MaterializedProperty {
10848    #[serde(default)]
10849    pub this: Option<Box<Expression>>,
10850}
10851
10852/// MergeBlockRatioProperty
10853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10854#[cfg_attr(feature = "bindings", derive(TS))]
10855pub struct MergeBlockRatioProperty {
10856    #[serde(default)]
10857    pub this: Option<Box<Expression>>,
10858    #[serde(default)]
10859    pub no: Option<Box<Expression>>,
10860    #[serde(default)]
10861    pub default: Option<Box<Expression>>,
10862    #[serde(default)]
10863    pub percent: Option<Box<Expression>>,
10864}
10865
10866/// OnProperty
10867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10868#[cfg_attr(feature = "bindings", derive(TS))]
10869pub struct OnProperty {
10870    pub this: Box<Expression>,
10871}
10872
10873/// OnCommitProperty
10874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10875#[cfg_attr(feature = "bindings", derive(TS))]
10876pub struct OnCommitProperty {
10877    #[serde(default)]
10878    pub delete: Option<Box<Expression>>,
10879}
10880
10881/// PartitionedByProperty
10882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10883#[cfg_attr(feature = "bindings", derive(TS))]
10884pub struct PartitionedByProperty {
10885    pub this: Box<Expression>,
10886}
10887
10888/// BigQuery PARTITION BY property in CREATE TABLE statements.
10889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10890#[cfg_attr(feature = "bindings", derive(TS))]
10891pub struct PartitionByProperty {
10892    #[serde(default)]
10893    pub expressions: Vec<Expression>,
10894}
10895
10896/// PartitionedByBucket
10897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10898#[cfg_attr(feature = "bindings", derive(TS))]
10899pub struct PartitionedByBucket {
10900    pub this: Box<Expression>,
10901    pub expression: Box<Expression>,
10902}
10903
10904/// BigQuery CLUSTER BY property in CREATE TABLE statements.
10905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10906#[cfg_attr(feature = "bindings", derive(TS))]
10907pub struct ClusterByColumnsProperty {
10908    #[serde(default)]
10909    pub columns: Vec<Identifier>,
10910}
10911
10912/// PartitionByTruncate
10913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10914#[cfg_attr(feature = "bindings", derive(TS))]
10915pub struct PartitionByTruncate {
10916    pub this: Box<Expression>,
10917    pub expression: Box<Expression>,
10918}
10919
10920/// PartitionByRangeProperty
10921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10922#[cfg_attr(feature = "bindings", derive(TS))]
10923pub struct PartitionByRangeProperty {
10924    #[serde(default)]
10925    pub partition_expressions: Option<Box<Expression>>,
10926    #[serde(default)]
10927    pub create_expressions: Option<Box<Expression>>,
10928}
10929
10930/// PartitionByRangePropertyDynamic
10931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10932#[cfg_attr(feature = "bindings", derive(TS))]
10933pub struct PartitionByRangePropertyDynamic {
10934    #[serde(default)]
10935    pub this: Option<Box<Expression>>,
10936    #[serde(default)]
10937    pub start: Option<Box<Expression>>,
10938    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
10939    #[serde(default)]
10940    pub use_start_end: bool,
10941    #[serde(default)]
10942    pub end: Option<Box<Expression>>,
10943    #[serde(default)]
10944    pub every: Option<Box<Expression>>,
10945}
10946
10947/// PartitionByListProperty
10948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10949#[cfg_attr(feature = "bindings", derive(TS))]
10950pub struct PartitionByListProperty {
10951    #[serde(default)]
10952    pub partition_expressions: Option<Box<Expression>>,
10953    #[serde(default)]
10954    pub create_expressions: Option<Box<Expression>>,
10955}
10956
10957/// PartitionList
10958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10959#[cfg_attr(feature = "bindings", derive(TS))]
10960pub struct PartitionList {
10961    pub this: Box<Expression>,
10962    #[serde(default)]
10963    pub expressions: Vec<Expression>,
10964}
10965
10966/// Partition - represents PARTITION/SUBPARTITION clause
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct Partition {
10970    pub expressions: Vec<Expression>,
10971    #[serde(default)]
10972    pub subpartition: bool,
10973}
10974
10975/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
10976/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
10977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10978#[cfg_attr(feature = "bindings", derive(TS))]
10979pub struct RefreshTriggerProperty {
10980    /// Method: COMPLETE or AUTO
10981    pub method: String,
10982    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
10983    #[serde(default)]
10984    pub kind: Option<String>,
10985    /// For SCHEDULE: EVERY n (the number)
10986    #[serde(default)]
10987    pub every: Option<Box<Expression>>,
10988    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
10989    #[serde(default)]
10990    pub unit: Option<String>,
10991    /// For SCHEDULE: STARTS 'datetime'
10992    #[serde(default)]
10993    pub starts: Option<Box<Expression>>,
10994}
10995
10996/// UniqueKeyProperty
10997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10998#[cfg_attr(feature = "bindings", derive(TS))]
10999pub struct UniqueKeyProperty {
11000    #[serde(default)]
11001    pub expressions: Vec<Expression>,
11002}
11003
11004/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11006#[cfg_attr(feature = "bindings", derive(TS))]
11007pub struct RollupProperty {
11008    pub expressions: Vec<RollupIndex>,
11009}
11010
11011/// RollupIndex - A single rollup index: name(col1, col2)
11012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11013#[cfg_attr(feature = "bindings", derive(TS))]
11014pub struct RollupIndex {
11015    pub name: Identifier,
11016    pub expressions: Vec<Identifier>,
11017}
11018
11019/// PartitionBoundSpec
11020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11021#[cfg_attr(feature = "bindings", derive(TS))]
11022pub struct PartitionBoundSpec {
11023    #[serde(default)]
11024    pub this: Option<Box<Expression>>,
11025    #[serde(default)]
11026    pub expression: Option<Box<Expression>>,
11027    #[serde(default)]
11028    pub from_expressions: Option<Box<Expression>>,
11029    #[serde(default)]
11030    pub to_expressions: Option<Box<Expression>>,
11031}
11032
11033/// PartitionedOfProperty
11034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11035#[cfg_attr(feature = "bindings", derive(TS))]
11036pub struct PartitionedOfProperty {
11037    pub this: Box<Expression>,
11038    pub expression: Box<Expression>,
11039}
11040
11041/// RemoteWithConnectionModelProperty
11042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11043#[cfg_attr(feature = "bindings", derive(TS))]
11044pub struct RemoteWithConnectionModelProperty {
11045    pub this: Box<Expression>,
11046}
11047
11048/// ReturnsProperty
11049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11050#[cfg_attr(feature = "bindings", derive(TS))]
11051pub struct ReturnsProperty {
11052    #[serde(default)]
11053    pub this: Option<Box<Expression>>,
11054    #[serde(default)]
11055    pub is_table: Option<Box<Expression>>,
11056    #[serde(default)]
11057    pub table: Option<Box<Expression>>,
11058    #[serde(default)]
11059    pub null: Option<Box<Expression>>,
11060}
11061
11062/// RowFormatProperty
11063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11064#[cfg_attr(feature = "bindings", derive(TS))]
11065pub struct RowFormatProperty {
11066    pub this: Box<Expression>,
11067}
11068
11069/// RowFormatDelimitedProperty
11070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11071#[cfg_attr(feature = "bindings", derive(TS))]
11072pub struct RowFormatDelimitedProperty {
11073    #[serde(default)]
11074    pub fields: Option<Box<Expression>>,
11075    #[serde(default)]
11076    pub escaped: Option<Box<Expression>>,
11077    #[serde(default)]
11078    pub collection_items: Option<Box<Expression>>,
11079    #[serde(default)]
11080    pub map_keys: Option<Box<Expression>>,
11081    #[serde(default)]
11082    pub lines: Option<Box<Expression>>,
11083    #[serde(default)]
11084    pub null: Option<Box<Expression>>,
11085    #[serde(default)]
11086    pub serde: Option<Box<Expression>>,
11087}
11088
11089/// RowFormatSerdeProperty
11090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11091#[cfg_attr(feature = "bindings", derive(TS))]
11092pub struct RowFormatSerdeProperty {
11093    pub this: Box<Expression>,
11094    #[serde(default)]
11095    pub serde_properties: Option<Box<Expression>>,
11096}
11097
11098/// QueryTransform
11099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11100#[cfg_attr(feature = "bindings", derive(TS))]
11101pub struct QueryTransform {
11102    #[serde(default)]
11103    pub expressions: Vec<Expression>,
11104    #[serde(default)]
11105    pub command_script: Option<Box<Expression>>,
11106    #[serde(default)]
11107    pub schema: Option<Box<Expression>>,
11108    #[serde(default)]
11109    pub row_format_before: Option<Box<Expression>>,
11110    #[serde(default)]
11111    pub record_writer: Option<Box<Expression>>,
11112    #[serde(default)]
11113    pub row_format_after: Option<Box<Expression>>,
11114    #[serde(default)]
11115    pub record_reader: Option<Box<Expression>>,
11116}
11117
11118/// SampleProperty
11119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11120#[cfg_attr(feature = "bindings", derive(TS))]
11121pub struct SampleProperty {
11122    pub this: Box<Expression>,
11123}
11124
11125/// SecurityProperty
11126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11127#[cfg_attr(feature = "bindings", derive(TS))]
11128pub struct SecurityProperty {
11129    pub this: Box<Expression>,
11130}
11131
11132/// SchemaCommentProperty
11133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11134#[cfg_attr(feature = "bindings", derive(TS))]
11135pub struct SchemaCommentProperty {
11136    pub this: Box<Expression>,
11137}
11138
11139/// SemanticView
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct SemanticView {
11143    pub this: Box<Expression>,
11144    #[serde(default)]
11145    pub metrics: Option<Box<Expression>>,
11146    #[serde(default)]
11147    pub dimensions: Option<Box<Expression>>,
11148    #[serde(default)]
11149    pub facts: Option<Box<Expression>>,
11150    #[serde(default)]
11151    pub where_: Option<Box<Expression>>,
11152}
11153
11154/// SerdeProperties
11155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11156#[cfg_attr(feature = "bindings", derive(TS))]
11157pub struct SerdeProperties {
11158    #[serde(default)]
11159    pub expressions: Vec<Expression>,
11160    #[serde(default)]
11161    pub with_: Option<Box<Expression>>,
11162}
11163
11164/// SetProperty
11165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11166#[cfg_attr(feature = "bindings", derive(TS))]
11167pub struct SetProperty {
11168    #[serde(default)]
11169    pub multi: Option<Box<Expression>>,
11170}
11171
11172/// SharingProperty
11173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11174#[cfg_attr(feature = "bindings", derive(TS))]
11175pub struct SharingProperty {
11176    #[serde(default)]
11177    pub this: Option<Box<Expression>>,
11178}
11179
11180/// SetConfigProperty
11181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11182#[cfg_attr(feature = "bindings", derive(TS))]
11183pub struct SetConfigProperty {
11184    pub this: Box<Expression>,
11185}
11186
11187/// SettingsProperty
11188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11189#[cfg_attr(feature = "bindings", derive(TS))]
11190pub struct SettingsProperty {
11191    #[serde(default)]
11192    pub expressions: Vec<Expression>,
11193}
11194
11195/// SortKeyProperty
11196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11197#[cfg_attr(feature = "bindings", derive(TS))]
11198pub struct SortKeyProperty {
11199    pub this: Box<Expression>,
11200    #[serde(default)]
11201    pub compound: Option<Box<Expression>>,
11202}
11203
11204/// SqlReadWriteProperty
11205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11206#[cfg_attr(feature = "bindings", derive(TS))]
11207pub struct SqlReadWriteProperty {
11208    pub this: Box<Expression>,
11209}
11210
11211/// SqlSecurityProperty
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct SqlSecurityProperty {
11215    pub this: Box<Expression>,
11216}
11217
11218/// StabilityProperty
11219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11220#[cfg_attr(feature = "bindings", derive(TS))]
11221pub struct StabilityProperty {
11222    pub this: Box<Expression>,
11223}
11224
11225/// StorageHandlerProperty
11226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11227#[cfg_attr(feature = "bindings", derive(TS))]
11228pub struct StorageHandlerProperty {
11229    pub this: Box<Expression>,
11230}
11231
11232/// TemporaryProperty
11233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11234#[cfg_attr(feature = "bindings", derive(TS))]
11235pub struct TemporaryProperty {
11236    #[serde(default)]
11237    pub this: Option<Box<Expression>>,
11238}
11239
11240/// Tags
11241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11242#[cfg_attr(feature = "bindings", derive(TS))]
11243pub struct Tags {
11244    #[serde(default)]
11245    pub expressions: Vec<Expression>,
11246}
11247
11248/// TransformModelProperty
11249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11250#[cfg_attr(feature = "bindings", derive(TS))]
11251pub struct TransformModelProperty {
11252    #[serde(default)]
11253    pub expressions: Vec<Expression>,
11254}
11255
11256/// TransientProperty
11257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11258#[cfg_attr(feature = "bindings", derive(TS))]
11259pub struct TransientProperty {
11260    #[serde(default)]
11261    pub this: Option<Box<Expression>>,
11262}
11263
11264/// UsingTemplateProperty
11265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11266#[cfg_attr(feature = "bindings", derive(TS))]
11267pub struct UsingTemplateProperty {
11268    pub this: Box<Expression>,
11269}
11270
11271/// ViewAttributeProperty
11272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11273#[cfg_attr(feature = "bindings", derive(TS))]
11274pub struct ViewAttributeProperty {
11275    pub this: Box<Expression>,
11276}
11277
11278/// VolatileProperty
11279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11280#[cfg_attr(feature = "bindings", derive(TS))]
11281pub struct VolatileProperty {
11282    #[serde(default)]
11283    pub this: Option<Box<Expression>>,
11284}
11285
11286/// WithDataProperty
11287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11288#[cfg_attr(feature = "bindings", derive(TS))]
11289pub struct WithDataProperty {
11290    #[serde(default)]
11291    pub no: Option<Box<Expression>>,
11292    #[serde(default)]
11293    pub statistics: Option<Box<Expression>>,
11294}
11295
11296/// WithJournalTableProperty
11297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11298#[cfg_attr(feature = "bindings", derive(TS))]
11299pub struct WithJournalTableProperty {
11300    pub this: Box<Expression>,
11301}
11302
11303/// WithSchemaBindingProperty
11304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11305#[cfg_attr(feature = "bindings", derive(TS))]
11306pub struct WithSchemaBindingProperty {
11307    pub this: Box<Expression>,
11308}
11309
11310/// WithSystemVersioningProperty
11311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11312#[cfg_attr(feature = "bindings", derive(TS))]
11313pub struct WithSystemVersioningProperty {
11314    #[serde(default)]
11315    pub on: Option<Box<Expression>>,
11316    #[serde(default)]
11317    pub this: Option<Box<Expression>>,
11318    #[serde(default)]
11319    pub data_consistency: Option<Box<Expression>>,
11320    #[serde(default)]
11321    pub retention_period: Option<Box<Expression>>,
11322    #[serde(default)]
11323    pub with_: Option<Box<Expression>>,
11324}
11325
11326/// WithProcedureOptions
11327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11328#[cfg_attr(feature = "bindings", derive(TS))]
11329pub struct WithProcedureOptions {
11330    #[serde(default)]
11331    pub expressions: Vec<Expression>,
11332}
11333
11334/// EncodeProperty
11335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11336#[cfg_attr(feature = "bindings", derive(TS))]
11337pub struct EncodeProperty {
11338    pub this: Box<Expression>,
11339    #[serde(default)]
11340    pub properties: Vec<Expression>,
11341    #[serde(default)]
11342    pub key: Option<Box<Expression>>,
11343}
11344
11345/// IncludeProperty
11346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11347#[cfg_attr(feature = "bindings", derive(TS))]
11348pub struct IncludeProperty {
11349    pub this: Box<Expression>,
11350    #[serde(default)]
11351    pub alias: Option<String>,
11352    #[serde(default)]
11353    pub column_def: Option<Box<Expression>>,
11354}
11355
11356/// Properties
11357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11358#[cfg_attr(feature = "bindings", derive(TS))]
11359pub struct Properties {
11360    #[serde(default)]
11361    pub expressions: Vec<Expression>,
11362}
11363
11364/// Key/value pair in a BigQuery OPTIONS (...) clause.
11365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11366#[cfg_attr(feature = "bindings", derive(TS))]
11367pub struct OptionEntry {
11368    pub key: Identifier,
11369    pub value: Expression,
11370}
11371
11372/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11374#[cfg_attr(feature = "bindings", derive(TS))]
11375pub struct OptionsProperty {
11376    #[serde(default)]
11377    pub entries: Vec<OptionEntry>,
11378}
11379
11380/// InputOutputFormat
11381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11382#[cfg_attr(feature = "bindings", derive(TS))]
11383pub struct InputOutputFormat {
11384    #[serde(default)]
11385    pub input_format: Option<Box<Expression>>,
11386    #[serde(default)]
11387    pub output_format: Option<Box<Expression>>,
11388}
11389
11390/// Reference
11391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11392#[cfg_attr(feature = "bindings", derive(TS))]
11393pub struct Reference {
11394    pub this: Box<Expression>,
11395    #[serde(default)]
11396    pub expressions: Vec<Expression>,
11397    #[serde(default)]
11398    pub options: Vec<Expression>,
11399}
11400
11401/// QueryOption
11402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11403#[cfg_attr(feature = "bindings", derive(TS))]
11404pub struct QueryOption {
11405    pub this: Box<Expression>,
11406    #[serde(default)]
11407    pub expression: Option<Box<Expression>>,
11408}
11409
11410/// WithTableHint
11411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11412#[cfg_attr(feature = "bindings", derive(TS))]
11413pub struct WithTableHint {
11414    #[serde(default)]
11415    pub expressions: Vec<Expression>,
11416}
11417
11418/// IndexTableHint
11419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11420#[cfg_attr(feature = "bindings", derive(TS))]
11421pub struct IndexTableHint {
11422    pub this: Box<Expression>,
11423    #[serde(default)]
11424    pub expressions: Vec<Expression>,
11425    #[serde(default)]
11426    pub target: Option<Box<Expression>>,
11427}
11428
11429/// Get
11430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11431#[cfg_attr(feature = "bindings", derive(TS))]
11432pub struct Get {
11433    pub this: Box<Expression>,
11434    #[serde(default)]
11435    pub target: Option<Box<Expression>>,
11436    #[serde(default)]
11437    pub properties: Vec<Expression>,
11438}
11439
11440/// SetOperation
11441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11442#[cfg_attr(feature = "bindings", derive(TS))]
11443pub struct SetOperation {
11444    #[serde(default)]
11445    pub with_: Option<Box<Expression>>,
11446    pub this: Box<Expression>,
11447    pub expression: Box<Expression>,
11448    #[serde(default)]
11449    pub distinct: bool,
11450    #[serde(default)]
11451    pub by_name: Option<Box<Expression>>,
11452    #[serde(default)]
11453    pub side: Option<Box<Expression>>,
11454    #[serde(default)]
11455    pub kind: Option<String>,
11456    #[serde(default)]
11457    pub on: Option<Box<Expression>>,
11458}
11459
11460/// Var - Simple variable reference (for SQL variables, keywords as values)
11461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11462#[cfg_attr(feature = "bindings", derive(TS))]
11463pub struct Var {
11464    pub this: String,
11465}
11466
11467/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11469#[cfg_attr(feature = "bindings", derive(TS))]
11470pub struct Variadic {
11471    pub this: Box<Expression>,
11472}
11473
11474/// Version
11475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11476#[cfg_attr(feature = "bindings", derive(TS))]
11477pub struct Version {
11478    pub this: Box<Expression>,
11479    pub kind: String,
11480    #[serde(default)]
11481    pub expression: Option<Box<Expression>>,
11482}
11483
11484/// Schema
11485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11486#[cfg_attr(feature = "bindings", derive(TS))]
11487pub struct Schema {
11488    #[serde(default)]
11489    pub this: Option<Box<Expression>>,
11490    #[serde(default)]
11491    pub expressions: Vec<Expression>,
11492}
11493
11494/// Lock
11495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11496#[cfg_attr(feature = "bindings", derive(TS))]
11497pub struct Lock {
11498    #[serde(default)]
11499    pub update: Option<Box<Expression>>,
11500    #[serde(default)]
11501    pub expressions: Vec<Expression>,
11502    #[serde(default)]
11503    pub wait: Option<Box<Expression>>,
11504    #[serde(default)]
11505    pub key: Option<Box<Expression>>,
11506}
11507
11508/// TableSample - wraps an expression with a TABLESAMPLE clause
11509/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11511#[cfg_attr(feature = "bindings", derive(TS))]
11512pub struct TableSample {
11513    /// The expression being sampled (subquery, function, etc.)
11514    #[serde(default, skip_serializing_if = "Option::is_none")]
11515    pub this: Option<Box<Expression>>,
11516    /// The sample specification
11517    #[serde(default, skip_serializing_if = "Option::is_none")]
11518    pub sample: Option<Box<Sample>>,
11519    #[serde(default)]
11520    pub expressions: Vec<Expression>,
11521    #[serde(default)]
11522    pub method: Option<String>,
11523    #[serde(default)]
11524    pub bucket_numerator: Option<Box<Expression>>,
11525    #[serde(default)]
11526    pub bucket_denominator: Option<Box<Expression>>,
11527    #[serde(default)]
11528    pub bucket_field: Option<Box<Expression>>,
11529    #[serde(default)]
11530    pub percent: Option<Box<Expression>>,
11531    #[serde(default)]
11532    pub rows: Option<Box<Expression>>,
11533    #[serde(default)]
11534    pub size: Option<i64>,
11535    #[serde(default)]
11536    pub seed: Option<Box<Expression>>,
11537}
11538
11539/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11541#[cfg_attr(feature = "bindings", derive(TS))]
11542pub struct Tag {
11543    #[serde(default)]
11544    pub this: Option<Box<Expression>>,
11545    #[serde(default)]
11546    pub prefix: Option<Box<Expression>>,
11547    #[serde(default)]
11548    pub postfix: Option<Box<Expression>>,
11549}
11550
11551/// UnpivotColumns
11552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11553#[cfg_attr(feature = "bindings", derive(TS))]
11554pub struct UnpivotColumns {
11555    pub this: Box<Expression>,
11556    #[serde(default)]
11557    pub expressions: Vec<Expression>,
11558}
11559
11560/// SessionParameter
11561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11562#[cfg_attr(feature = "bindings", derive(TS))]
11563pub struct SessionParameter {
11564    pub this: Box<Expression>,
11565    #[serde(default)]
11566    pub kind: Option<String>,
11567}
11568
11569/// PseudoType
11570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11571#[cfg_attr(feature = "bindings", derive(TS))]
11572pub struct PseudoType {
11573    pub this: Box<Expression>,
11574}
11575
11576/// ObjectIdentifier
11577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11578#[cfg_attr(feature = "bindings", derive(TS))]
11579pub struct ObjectIdentifier {
11580    pub this: Box<Expression>,
11581}
11582
11583/// Transaction
11584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11585#[cfg_attr(feature = "bindings", derive(TS))]
11586pub struct Transaction {
11587    #[serde(default)]
11588    pub this: Option<Box<Expression>>,
11589    #[serde(default)]
11590    pub modes: Option<Box<Expression>>,
11591    #[serde(default)]
11592    pub mark: Option<Box<Expression>>,
11593}
11594
11595/// Commit
11596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11597#[cfg_attr(feature = "bindings", derive(TS))]
11598pub struct Commit {
11599    #[serde(default)]
11600    pub chain: Option<Box<Expression>>,
11601    #[serde(default)]
11602    pub this: Option<Box<Expression>>,
11603    #[serde(default)]
11604    pub durability: Option<Box<Expression>>,
11605}
11606
11607/// Rollback
11608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11609#[cfg_attr(feature = "bindings", derive(TS))]
11610pub struct Rollback {
11611    #[serde(default)]
11612    pub savepoint: Option<Box<Expression>>,
11613    #[serde(default)]
11614    pub this: Option<Box<Expression>>,
11615}
11616
11617/// AlterSession
11618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11619#[cfg_attr(feature = "bindings", derive(TS))]
11620pub struct AlterSession {
11621    #[serde(default)]
11622    pub expressions: Vec<Expression>,
11623    #[serde(default)]
11624    pub unset: Option<Box<Expression>>,
11625}
11626
11627/// Analyze
11628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11629#[cfg_attr(feature = "bindings", derive(TS))]
11630pub struct Analyze {
11631    #[serde(default)]
11632    pub kind: Option<String>,
11633    #[serde(default)]
11634    pub this: Option<Box<Expression>>,
11635    #[serde(default)]
11636    pub options: Vec<Expression>,
11637    #[serde(default)]
11638    pub mode: Option<Box<Expression>>,
11639    #[serde(default)]
11640    pub partition: Option<Box<Expression>>,
11641    #[serde(default)]
11642    pub expression: Option<Box<Expression>>,
11643    #[serde(default)]
11644    pub properties: Vec<Expression>,
11645    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
11646    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11647    pub columns: Vec<String>,
11648}
11649
11650/// AnalyzeStatistics
11651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11652#[cfg_attr(feature = "bindings", derive(TS))]
11653pub struct AnalyzeStatistics {
11654    pub kind: String,
11655    #[serde(default)]
11656    pub option: Option<Box<Expression>>,
11657    #[serde(default)]
11658    pub this: Option<Box<Expression>>,
11659    #[serde(default)]
11660    pub expressions: Vec<Expression>,
11661}
11662
11663/// AnalyzeHistogram
11664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11665#[cfg_attr(feature = "bindings", derive(TS))]
11666pub struct AnalyzeHistogram {
11667    pub this: Box<Expression>,
11668    #[serde(default)]
11669    pub expressions: Vec<Expression>,
11670    #[serde(default)]
11671    pub expression: Option<Box<Expression>>,
11672    #[serde(default)]
11673    pub update_options: Option<Box<Expression>>,
11674}
11675
11676/// AnalyzeSample
11677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11678#[cfg_attr(feature = "bindings", derive(TS))]
11679pub struct AnalyzeSample {
11680    pub kind: String,
11681    #[serde(default)]
11682    pub sample: Option<Box<Expression>>,
11683}
11684
11685/// AnalyzeListChainedRows
11686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11687#[cfg_attr(feature = "bindings", derive(TS))]
11688pub struct AnalyzeListChainedRows {
11689    #[serde(default)]
11690    pub expression: Option<Box<Expression>>,
11691}
11692
11693/// AnalyzeDelete
11694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11695#[cfg_attr(feature = "bindings", derive(TS))]
11696pub struct AnalyzeDelete {
11697    #[serde(default)]
11698    pub kind: Option<String>,
11699}
11700
11701/// AnalyzeWith
11702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11703#[cfg_attr(feature = "bindings", derive(TS))]
11704pub struct AnalyzeWith {
11705    #[serde(default)]
11706    pub expressions: Vec<Expression>,
11707}
11708
11709/// AnalyzeValidate
11710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11711#[cfg_attr(feature = "bindings", derive(TS))]
11712pub struct AnalyzeValidate {
11713    pub kind: String,
11714    #[serde(default)]
11715    pub this: Option<Box<Expression>>,
11716    #[serde(default)]
11717    pub expression: Option<Box<Expression>>,
11718}
11719
11720/// AddPartition
11721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11722#[cfg_attr(feature = "bindings", derive(TS))]
11723pub struct AddPartition {
11724    pub this: Box<Expression>,
11725    #[serde(default)]
11726    pub exists: bool,
11727    #[serde(default)]
11728    pub location: Option<Box<Expression>>,
11729}
11730
11731/// AttachOption
11732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11733#[cfg_attr(feature = "bindings", derive(TS))]
11734pub struct AttachOption {
11735    pub this: Box<Expression>,
11736    #[serde(default)]
11737    pub expression: Option<Box<Expression>>,
11738}
11739
11740/// DropPartition
11741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11742#[cfg_attr(feature = "bindings", derive(TS))]
11743pub struct DropPartition {
11744    #[serde(default)]
11745    pub expressions: Vec<Expression>,
11746    #[serde(default)]
11747    pub exists: bool,
11748}
11749
11750/// ReplacePartition
11751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11752#[cfg_attr(feature = "bindings", derive(TS))]
11753pub struct ReplacePartition {
11754    pub expression: Box<Expression>,
11755    #[serde(default)]
11756    pub source: Option<Box<Expression>>,
11757}
11758
11759/// DPipe
11760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11761#[cfg_attr(feature = "bindings", derive(TS))]
11762pub struct DPipe {
11763    pub this: Box<Expression>,
11764    pub expression: Box<Expression>,
11765    #[serde(default)]
11766    pub safe: Option<Box<Expression>>,
11767}
11768
11769/// Operator
11770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11771#[cfg_attr(feature = "bindings", derive(TS))]
11772pub struct Operator {
11773    pub this: Box<Expression>,
11774    #[serde(default)]
11775    pub operator: Option<Box<Expression>>,
11776    pub expression: Box<Expression>,
11777    /// Comments between OPERATOR() and the RHS expression
11778    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11779    pub comments: Vec<String>,
11780}
11781
11782/// PivotAny
11783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11784#[cfg_attr(feature = "bindings", derive(TS))]
11785pub struct PivotAny {
11786    #[serde(default)]
11787    pub this: Option<Box<Expression>>,
11788}
11789
11790/// Aliases
11791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11792#[cfg_attr(feature = "bindings", derive(TS))]
11793pub struct Aliases {
11794    pub this: Box<Expression>,
11795    #[serde(default)]
11796    pub expressions: Vec<Expression>,
11797}
11798
11799/// AtIndex
11800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11801#[cfg_attr(feature = "bindings", derive(TS))]
11802pub struct AtIndex {
11803    pub this: Box<Expression>,
11804    pub expression: Box<Expression>,
11805}
11806
11807/// FromTimeZone
11808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11809#[cfg_attr(feature = "bindings", derive(TS))]
11810pub struct FromTimeZone {
11811    pub this: Box<Expression>,
11812    #[serde(default)]
11813    pub zone: Option<Box<Expression>>,
11814}
11815
11816/// Format override for a column in Teradata
11817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11818#[cfg_attr(feature = "bindings", derive(TS))]
11819pub struct FormatPhrase {
11820    pub this: Box<Expression>,
11821    pub format: String,
11822}
11823
11824/// ForIn
11825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11826#[cfg_attr(feature = "bindings", derive(TS))]
11827pub struct ForIn {
11828    pub this: Box<Expression>,
11829    pub expression: Box<Expression>,
11830}
11831
11832/// Automatically converts unit arg into a var.
11833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11834#[cfg_attr(feature = "bindings", derive(TS))]
11835pub struct TimeUnit {
11836    #[serde(default)]
11837    pub unit: Option<String>,
11838}
11839
11840/// IntervalOp
11841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11842#[cfg_attr(feature = "bindings", derive(TS))]
11843pub struct IntervalOp {
11844    #[serde(default)]
11845    pub unit: Option<String>,
11846    pub expression: Box<Expression>,
11847}
11848
11849/// HavingMax
11850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11851#[cfg_attr(feature = "bindings", derive(TS))]
11852pub struct HavingMax {
11853    pub this: Box<Expression>,
11854    pub expression: Box<Expression>,
11855    #[serde(default)]
11856    pub max: Option<Box<Expression>>,
11857}
11858
11859/// CosineDistance
11860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11861#[cfg_attr(feature = "bindings", derive(TS))]
11862pub struct CosineDistance {
11863    pub this: Box<Expression>,
11864    pub expression: Box<Expression>,
11865}
11866
11867/// DotProduct
11868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11869#[cfg_attr(feature = "bindings", derive(TS))]
11870pub struct DotProduct {
11871    pub this: Box<Expression>,
11872    pub expression: Box<Expression>,
11873}
11874
11875/// EuclideanDistance
11876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11877#[cfg_attr(feature = "bindings", derive(TS))]
11878pub struct EuclideanDistance {
11879    pub this: Box<Expression>,
11880    pub expression: Box<Expression>,
11881}
11882
11883/// ManhattanDistance
11884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11885#[cfg_attr(feature = "bindings", derive(TS))]
11886pub struct ManhattanDistance {
11887    pub this: Box<Expression>,
11888    pub expression: Box<Expression>,
11889}
11890
11891/// JarowinklerSimilarity
11892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11893#[cfg_attr(feature = "bindings", derive(TS))]
11894pub struct JarowinklerSimilarity {
11895    pub this: Box<Expression>,
11896    pub expression: Box<Expression>,
11897}
11898
11899/// Booland
11900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11901#[cfg_attr(feature = "bindings", derive(TS))]
11902pub struct Booland {
11903    pub this: Box<Expression>,
11904    pub expression: Box<Expression>,
11905}
11906
11907/// Boolor
11908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11909#[cfg_attr(feature = "bindings", derive(TS))]
11910pub struct Boolor {
11911    pub this: Box<Expression>,
11912    pub expression: Box<Expression>,
11913}
11914
11915/// ParameterizedAgg
11916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11917#[cfg_attr(feature = "bindings", derive(TS))]
11918pub struct ParameterizedAgg {
11919    pub this: Box<Expression>,
11920    #[serde(default)]
11921    pub expressions: Vec<Expression>,
11922    #[serde(default)]
11923    pub params: Vec<Expression>,
11924}
11925
11926/// ArgMax
11927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11928#[cfg_attr(feature = "bindings", derive(TS))]
11929pub struct ArgMax {
11930    pub this: Box<Expression>,
11931    pub expression: Box<Expression>,
11932    #[serde(default)]
11933    pub count: Option<Box<Expression>>,
11934}
11935
11936/// ArgMin
11937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11938#[cfg_attr(feature = "bindings", derive(TS))]
11939pub struct ArgMin {
11940    pub this: Box<Expression>,
11941    pub expression: Box<Expression>,
11942    #[serde(default)]
11943    pub count: Option<Box<Expression>>,
11944}
11945
11946/// ApproxTopK
11947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11948#[cfg_attr(feature = "bindings", derive(TS))]
11949pub struct ApproxTopK {
11950    pub this: Box<Expression>,
11951    #[serde(default)]
11952    pub expression: Option<Box<Expression>>,
11953    #[serde(default)]
11954    pub counters: Option<Box<Expression>>,
11955}
11956
11957/// ApproxTopKAccumulate
11958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11959#[cfg_attr(feature = "bindings", derive(TS))]
11960pub struct ApproxTopKAccumulate {
11961    pub this: Box<Expression>,
11962    #[serde(default)]
11963    pub expression: Option<Box<Expression>>,
11964}
11965
11966/// ApproxTopKCombine
11967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11968#[cfg_attr(feature = "bindings", derive(TS))]
11969pub struct ApproxTopKCombine {
11970    pub this: Box<Expression>,
11971    #[serde(default)]
11972    pub expression: Option<Box<Expression>>,
11973}
11974
11975/// ApproxTopKEstimate
11976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11977#[cfg_attr(feature = "bindings", derive(TS))]
11978pub struct ApproxTopKEstimate {
11979    pub this: Box<Expression>,
11980    #[serde(default)]
11981    pub expression: Option<Box<Expression>>,
11982}
11983
11984/// ApproxTopSum
11985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11986#[cfg_attr(feature = "bindings", derive(TS))]
11987pub struct ApproxTopSum {
11988    pub this: Box<Expression>,
11989    pub expression: Box<Expression>,
11990    #[serde(default)]
11991    pub count: Option<Box<Expression>>,
11992}
11993
11994/// ApproxQuantiles
11995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11996#[cfg_attr(feature = "bindings", derive(TS))]
11997pub struct ApproxQuantiles {
11998    pub this: Box<Expression>,
11999    #[serde(default)]
12000    pub expression: Option<Box<Expression>>,
12001}
12002
12003/// Minhash
12004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12005#[cfg_attr(feature = "bindings", derive(TS))]
12006pub struct Minhash {
12007    pub this: Box<Expression>,
12008    #[serde(default)]
12009    pub expressions: Vec<Expression>,
12010}
12011
12012/// FarmFingerprint
12013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12014#[cfg_attr(feature = "bindings", derive(TS))]
12015pub struct FarmFingerprint {
12016    #[serde(default)]
12017    pub expressions: Vec<Expression>,
12018}
12019
12020/// Float64
12021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12022#[cfg_attr(feature = "bindings", derive(TS))]
12023pub struct Float64 {
12024    pub this: Box<Expression>,
12025    #[serde(default)]
12026    pub expression: Option<Box<Expression>>,
12027}
12028
12029/// Transform
12030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12031#[cfg_attr(feature = "bindings", derive(TS))]
12032pub struct Transform {
12033    pub this: Box<Expression>,
12034    pub expression: Box<Expression>,
12035}
12036
12037/// Translate
12038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12039#[cfg_attr(feature = "bindings", derive(TS))]
12040pub struct Translate {
12041    pub this: Box<Expression>,
12042    #[serde(default)]
12043    pub from_: Option<Box<Expression>>,
12044    #[serde(default)]
12045    pub to: Option<Box<Expression>>,
12046}
12047
12048/// Grouping
12049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12050#[cfg_attr(feature = "bindings", derive(TS))]
12051pub struct Grouping {
12052    #[serde(default)]
12053    pub expressions: Vec<Expression>,
12054}
12055
12056/// GroupingId
12057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12058#[cfg_attr(feature = "bindings", derive(TS))]
12059pub struct GroupingId {
12060    #[serde(default)]
12061    pub expressions: Vec<Expression>,
12062}
12063
12064/// Anonymous
12065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12066#[cfg_attr(feature = "bindings", derive(TS))]
12067pub struct Anonymous {
12068    pub this: Box<Expression>,
12069    #[serde(default)]
12070    pub expressions: Vec<Expression>,
12071}
12072
12073/// AnonymousAggFunc
12074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12075#[cfg_attr(feature = "bindings", derive(TS))]
12076pub struct AnonymousAggFunc {
12077    pub this: Box<Expression>,
12078    #[serde(default)]
12079    pub expressions: Vec<Expression>,
12080}
12081
12082/// CombinedAggFunc
12083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12084#[cfg_attr(feature = "bindings", derive(TS))]
12085pub struct CombinedAggFunc {
12086    pub this: Box<Expression>,
12087    #[serde(default)]
12088    pub expressions: Vec<Expression>,
12089}
12090
12091/// CombinedParameterizedAgg
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct CombinedParameterizedAgg {
12095    pub this: Box<Expression>,
12096    #[serde(default)]
12097    pub expressions: Vec<Expression>,
12098    #[serde(default)]
12099    pub params: Vec<Expression>,
12100}
12101
12102/// HashAgg
12103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12104#[cfg_attr(feature = "bindings", derive(TS))]
12105pub struct HashAgg {
12106    pub this: Box<Expression>,
12107    #[serde(default)]
12108    pub expressions: Vec<Expression>,
12109}
12110
12111/// Hll
12112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12113#[cfg_attr(feature = "bindings", derive(TS))]
12114pub struct Hll {
12115    pub this: Box<Expression>,
12116    #[serde(default)]
12117    pub expressions: Vec<Expression>,
12118}
12119
12120/// Apply
12121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12122#[cfg_attr(feature = "bindings", derive(TS))]
12123pub struct Apply {
12124    pub this: Box<Expression>,
12125    pub expression: Box<Expression>,
12126}
12127
12128/// ToBoolean
12129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12130#[cfg_attr(feature = "bindings", derive(TS))]
12131pub struct ToBoolean {
12132    pub this: Box<Expression>,
12133    #[serde(default)]
12134    pub safe: Option<Box<Expression>>,
12135}
12136
12137/// List
12138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12139#[cfg_attr(feature = "bindings", derive(TS))]
12140pub struct List {
12141    #[serde(default)]
12142    pub expressions: Vec<Expression>,
12143}
12144
12145/// ToMap - Materialize-style map constructor
12146/// Can hold either:
12147/// - A SELECT subquery (MAP(SELECT 'a', 1))
12148/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12150#[cfg_attr(feature = "bindings", derive(TS))]
12151pub struct ToMap {
12152    /// Either a Select subquery or a Struct containing PropertyEQ entries
12153    pub this: Box<Expression>,
12154}
12155
12156/// Pad
12157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12158#[cfg_attr(feature = "bindings", derive(TS))]
12159pub struct Pad {
12160    pub this: Box<Expression>,
12161    pub expression: Box<Expression>,
12162    #[serde(default)]
12163    pub fill_pattern: Option<Box<Expression>>,
12164    #[serde(default)]
12165    pub is_left: Option<Box<Expression>>,
12166}
12167
12168/// ToChar
12169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12170#[cfg_attr(feature = "bindings", derive(TS))]
12171pub struct ToChar {
12172    pub this: Box<Expression>,
12173    #[serde(default)]
12174    pub format: Option<String>,
12175    #[serde(default)]
12176    pub nlsparam: Option<Box<Expression>>,
12177    #[serde(default)]
12178    pub is_numeric: Option<Box<Expression>>,
12179}
12180
12181/// StringFunc - String type conversion function (BigQuery STRING)
12182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12183#[cfg_attr(feature = "bindings", derive(TS))]
12184pub struct StringFunc {
12185    pub this: Box<Expression>,
12186    #[serde(default)]
12187    pub zone: Option<Box<Expression>>,
12188}
12189
12190/// ToNumber
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct ToNumber {
12194    pub this: Box<Expression>,
12195    #[serde(default)]
12196    pub format: Option<Box<Expression>>,
12197    #[serde(default)]
12198    pub nlsparam: Option<Box<Expression>>,
12199    #[serde(default)]
12200    pub precision: Option<Box<Expression>>,
12201    #[serde(default)]
12202    pub scale: Option<Box<Expression>>,
12203    #[serde(default)]
12204    pub safe: Option<Box<Expression>>,
12205    #[serde(default)]
12206    pub safe_name: Option<Box<Expression>>,
12207}
12208
12209/// ToDouble
12210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12211#[cfg_attr(feature = "bindings", derive(TS))]
12212pub struct ToDouble {
12213    pub this: Box<Expression>,
12214    #[serde(default)]
12215    pub format: Option<String>,
12216    #[serde(default)]
12217    pub safe: Option<Box<Expression>>,
12218}
12219
12220/// ToDecfloat
12221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12222#[cfg_attr(feature = "bindings", derive(TS))]
12223pub struct ToDecfloat {
12224    pub this: Box<Expression>,
12225    #[serde(default)]
12226    pub format: Option<String>,
12227}
12228
12229/// TryToDecfloat
12230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12231#[cfg_attr(feature = "bindings", derive(TS))]
12232pub struct TryToDecfloat {
12233    pub this: Box<Expression>,
12234    #[serde(default)]
12235    pub format: Option<String>,
12236}
12237
12238/// ToFile
12239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12240#[cfg_attr(feature = "bindings", derive(TS))]
12241pub struct ToFile {
12242    pub this: Box<Expression>,
12243    #[serde(default)]
12244    pub path: Option<Box<Expression>>,
12245    #[serde(default)]
12246    pub safe: Option<Box<Expression>>,
12247}
12248
12249/// Columns
12250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12251#[cfg_attr(feature = "bindings", derive(TS))]
12252pub struct Columns {
12253    pub this: Box<Expression>,
12254    #[serde(default)]
12255    pub unpack: Option<Box<Expression>>,
12256}
12257
12258/// ConvertToCharset
12259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12260#[cfg_attr(feature = "bindings", derive(TS))]
12261pub struct ConvertToCharset {
12262    pub this: Box<Expression>,
12263    #[serde(default)]
12264    pub dest: Option<Box<Expression>>,
12265    #[serde(default)]
12266    pub source: Option<Box<Expression>>,
12267}
12268
12269/// ConvertTimezone
12270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12271#[cfg_attr(feature = "bindings", derive(TS))]
12272pub struct ConvertTimezone {
12273    #[serde(default)]
12274    pub source_tz: Option<Box<Expression>>,
12275    #[serde(default)]
12276    pub target_tz: Option<Box<Expression>>,
12277    #[serde(default)]
12278    pub timestamp: Option<Box<Expression>>,
12279    #[serde(default)]
12280    pub options: Vec<Expression>,
12281}
12282
12283/// GenerateSeries
12284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12285#[cfg_attr(feature = "bindings", derive(TS))]
12286pub struct GenerateSeries {
12287    #[serde(default)]
12288    pub start: Option<Box<Expression>>,
12289    #[serde(default)]
12290    pub end: Option<Box<Expression>>,
12291    #[serde(default)]
12292    pub step: Option<Box<Expression>>,
12293    #[serde(default)]
12294    pub is_end_exclusive: Option<Box<Expression>>,
12295}
12296
12297/// AIAgg
12298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12299#[cfg_attr(feature = "bindings", derive(TS))]
12300pub struct AIAgg {
12301    pub this: Box<Expression>,
12302    pub expression: Box<Expression>,
12303}
12304
12305/// AIClassify
12306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12307#[cfg_attr(feature = "bindings", derive(TS))]
12308pub struct AIClassify {
12309    pub this: Box<Expression>,
12310    #[serde(default)]
12311    pub categories: Option<Box<Expression>>,
12312    #[serde(default)]
12313    pub config: Option<Box<Expression>>,
12314}
12315
12316/// ArrayAll
12317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12318#[cfg_attr(feature = "bindings", derive(TS))]
12319pub struct ArrayAll {
12320    pub this: Box<Expression>,
12321    pub expression: Box<Expression>,
12322}
12323
12324/// ArrayAny
12325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12326#[cfg_attr(feature = "bindings", derive(TS))]
12327pub struct ArrayAny {
12328    pub this: Box<Expression>,
12329    pub expression: Box<Expression>,
12330}
12331
12332/// ArrayConstructCompact
12333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12334#[cfg_attr(feature = "bindings", derive(TS))]
12335pub struct ArrayConstructCompact {
12336    #[serde(default)]
12337    pub expressions: Vec<Expression>,
12338}
12339
12340/// StPoint
12341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12342#[cfg_attr(feature = "bindings", derive(TS))]
12343pub struct StPoint {
12344    pub this: Box<Expression>,
12345    pub expression: Box<Expression>,
12346    #[serde(default)]
12347    pub null: Option<Box<Expression>>,
12348}
12349
12350/// StDistance
12351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12352#[cfg_attr(feature = "bindings", derive(TS))]
12353pub struct StDistance {
12354    pub this: Box<Expression>,
12355    pub expression: Box<Expression>,
12356    #[serde(default)]
12357    pub use_spheroid: Option<Box<Expression>>,
12358}
12359
12360/// StringToArray
12361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12362#[cfg_attr(feature = "bindings", derive(TS))]
12363pub struct StringToArray {
12364    pub this: Box<Expression>,
12365    #[serde(default)]
12366    pub expression: Option<Box<Expression>>,
12367    #[serde(default)]
12368    pub null: Option<Box<Expression>>,
12369}
12370
12371/// ArraySum
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct ArraySum {
12375    pub this: Box<Expression>,
12376    #[serde(default)]
12377    pub expression: Option<Box<Expression>>,
12378}
12379
12380/// ObjectAgg
12381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12382#[cfg_attr(feature = "bindings", derive(TS))]
12383pub struct ObjectAgg {
12384    pub this: Box<Expression>,
12385    pub expression: Box<Expression>,
12386}
12387
12388/// CastToStrType
12389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12390#[cfg_attr(feature = "bindings", derive(TS))]
12391pub struct CastToStrType {
12392    pub this: Box<Expression>,
12393    #[serde(default)]
12394    pub to: Option<Box<Expression>>,
12395}
12396
12397/// CheckJson
12398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12399#[cfg_attr(feature = "bindings", derive(TS))]
12400pub struct CheckJson {
12401    pub this: Box<Expression>,
12402}
12403
12404/// CheckXml
12405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12406#[cfg_attr(feature = "bindings", derive(TS))]
12407pub struct CheckXml {
12408    pub this: Box<Expression>,
12409    #[serde(default)]
12410    pub disable_auto_convert: Option<Box<Expression>>,
12411}
12412
12413/// TranslateCharacters
12414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12415#[cfg_attr(feature = "bindings", derive(TS))]
12416pub struct TranslateCharacters {
12417    pub this: Box<Expression>,
12418    pub expression: Box<Expression>,
12419    #[serde(default)]
12420    pub with_error: Option<Box<Expression>>,
12421}
12422
12423/// CurrentSchemas
12424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12425#[cfg_attr(feature = "bindings", derive(TS))]
12426pub struct CurrentSchemas {
12427    #[serde(default)]
12428    pub this: Option<Box<Expression>>,
12429}
12430
12431/// CurrentDatetime
12432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12433#[cfg_attr(feature = "bindings", derive(TS))]
12434pub struct CurrentDatetime {
12435    #[serde(default)]
12436    pub this: Option<Box<Expression>>,
12437}
12438
12439/// Localtime
12440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12441#[cfg_attr(feature = "bindings", derive(TS))]
12442pub struct Localtime {
12443    #[serde(default)]
12444    pub this: Option<Box<Expression>>,
12445}
12446
12447/// Localtimestamp
12448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12449#[cfg_attr(feature = "bindings", derive(TS))]
12450pub struct Localtimestamp {
12451    #[serde(default)]
12452    pub this: Option<Box<Expression>>,
12453}
12454
12455/// Systimestamp
12456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12457#[cfg_attr(feature = "bindings", derive(TS))]
12458pub struct Systimestamp {
12459    #[serde(default)]
12460    pub this: Option<Box<Expression>>,
12461}
12462
12463/// CurrentSchema
12464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12465#[cfg_attr(feature = "bindings", derive(TS))]
12466pub struct CurrentSchema {
12467    #[serde(default)]
12468    pub this: Option<Box<Expression>>,
12469}
12470
12471/// CurrentUser
12472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12473#[cfg_attr(feature = "bindings", derive(TS))]
12474pub struct CurrentUser {
12475    #[serde(default)]
12476    pub this: Option<Box<Expression>>,
12477}
12478
12479/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct SessionUser;
12483
12484/// JSONPathRoot - Represents $ in JSON path expressions
12485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12486#[cfg_attr(feature = "bindings", derive(TS))]
12487pub struct JSONPathRoot;
12488
12489/// UtcTime
12490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12491#[cfg_attr(feature = "bindings", derive(TS))]
12492pub struct UtcTime {
12493    #[serde(default)]
12494    pub this: Option<Box<Expression>>,
12495}
12496
12497/// UtcTimestamp
12498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12499#[cfg_attr(feature = "bindings", derive(TS))]
12500pub struct UtcTimestamp {
12501    #[serde(default)]
12502    pub this: Option<Box<Expression>>,
12503}
12504
12505/// TimestampFunc - TIMESTAMP constructor function
12506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12507#[cfg_attr(feature = "bindings", derive(TS))]
12508pub struct TimestampFunc {
12509    #[serde(default)]
12510    pub this: Option<Box<Expression>>,
12511    #[serde(default)]
12512    pub zone: Option<Box<Expression>>,
12513    #[serde(default)]
12514    pub with_tz: Option<bool>,
12515    #[serde(default)]
12516    pub safe: Option<bool>,
12517}
12518
12519/// DateBin
12520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12521#[cfg_attr(feature = "bindings", derive(TS))]
12522pub struct DateBin {
12523    pub this: Box<Expression>,
12524    pub expression: Box<Expression>,
12525    #[serde(default)]
12526    pub unit: Option<String>,
12527    #[serde(default)]
12528    pub zone: Option<Box<Expression>>,
12529    #[serde(default)]
12530    pub origin: Option<Box<Expression>>,
12531}
12532
12533/// Datetime
12534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12535#[cfg_attr(feature = "bindings", derive(TS))]
12536pub struct Datetime {
12537    pub this: Box<Expression>,
12538    #[serde(default)]
12539    pub expression: Option<Box<Expression>>,
12540}
12541
12542/// DatetimeAdd
12543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12544#[cfg_attr(feature = "bindings", derive(TS))]
12545pub struct DatetimeAdd {
12546    pub this: Box<Expression>,
12547    pub expression: Box<Expression>,
12548    #[serde(default)]
12549    pub unit: Option<String>,
12550}
12551
12552/// DatetimeSub
12553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12554#[cfg_attr(feature = "bindings", derive(TS))]
12555pub struct DatetimeSub {
12556    pub this: Box<Expression>,
12557    pub expression: Box<Expression>,
12558    #[serde(default)]
12559    pub unit: Option<String>,
12560}
12561
12562/// DatetimeDiff
12563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12564#[cfg_attr(feature = "bindings", derive(TS))]
12565pub struct DatetimeDiff {
12566    pub this: Box<Expression>,
12567    pub expression: Box<Expression>,
12568    #[serde(default)]
12569    pub unit: Option<String>,
12570}
12571
12572/// DatetimeTrunc
12573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12574#[cfg_attr(feature = "bindings", derive(TS))]
12575pub struct DatetimeTrunc {
12576    pub this: Box<Expression>,
12577    pub unit: String,
12578    #[serde(default)]
12579    pub zone: Option<Box<Expression>>,
12580}
12581
12582/// Dayname
12583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12584#[cfg_attr(feature = "bindings", derive(TS))]
12585pub struct Dayname {
12586    pub this: Box<Expression>,
12587    #[serde(default)]
12588    pub abbreviated: Option<Box<Expression>>,
12589}
12590
12591/// MakeInterval
12592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12593#[cfg_attr(feature = "bindings", derive(TS))]
12594pub struct MakeInterval {
12595    #[serde(default)]
12596    pub year: Option<Box<Expression>>,
12597    #[serde(default)]
12598    pub month: Option<Box<Expression>>,
12599    #[serde(default)]
12600    pub week: Option<Box<Expression>>,
12601    #[serde(default)]
12602    pub day: Option<Box<Expression>>,
12603    #[serde(default)]
12604    pub hour: Option<Box<Expression>>,
12605    #[serde(default)]
12606    pub minute: Option<Box<Expression>>,
12607    #[serde(default)]
12608    pub second: Option<Box<Expression>>,
12609}
12610
12611/// PreviousDay
12612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12613#[cfg_attr(feature = "bindings", derive(TS))]
12614pub struct PreviousDay {
12615    pub this: Box<Expression>,
12616    pub expression: Box<Expression>,
12617}
12618
12619/// Elt
12620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12621#[cfg_attr(feature = "bindings", derive(TS))]
12622pub struct Elt {
12623    pub this: Box<Expression>,
12624    #[serde(default)]
12625    pub expressions: Vec<Expression>,
12626}
12627
12628/// TimestampAdd
12629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12630#[cfg_attr(feature = "bindings", derive(TS))]
12631pub struct TimestampAdd {
12632    pub this: Box<Expression>,
12633    pub expression: Box<Expression>,
12634    #[serde(default)]
12635    pub unit: Option<String>,
12636}
12637
12638/// TimestampSub
12639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12640#[cfg_attr(feature = "bindings", derive(TS))]
12641pub struct TimestampSub {
12642    pub this: Box<Expression>,
12643    pub expression: Box<Expression>,
12644    #[serde(default)]
12645    pub unit: Option<String>,
12646}
12647
12648/// TimestampDiff
12649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12650#[cfg_attr(feature = "bindings", derive(TS))]
12651pub struct TimestampDiff {
12652    pub this: Box<Expression>,
12653    pub expression: Box<Expression>,
12654    #[serde(default)]
12655    pub unit: Option<String>,
12656}
12657
12658/// TimeSlice
12659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12660#[cfg_attr(feature = "bindings", derive(TS))]
12661pub struct TimeSlice {
12662    pub this: Box<Expression>,
12663    pub expression: Box<Expression>,
12664    pub unit: String,
12665    #[serde(default)]
12666    pub kind: Option<String>,
12667}
12668
12669/// TimeAdd
12670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12671#[cfg_attr(feature = "bindings", derive(TS))]
12672pub struct TimeAdd {
12673    pub this: Box<Expression>,
12674    pub expression: Box<Expression>,
12675    #[serde(default)]
12676    pub unit: Option<String>,
12677}
12678
12679/// TimeSub
12680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12681#[cfg_attr(feature = "bindings", derive(TS))]
12682pub struct TimeSub {
12683    pub this: Box<Expression>,
12684    pub expression: Box<Expression>,
12685    #[serde(default)]
12686    pub unit: Option<String>,
12687}
12688
12689/// TimeDiff
12690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12691#[cfg_attr(feature = "bindings", derive(TS))]
12692pub struct TimeDiff {
12693    pub this: Box<Expression>,
12694    pub expression: Box<Expression>,
12695    #[serde(default)]
12696    pub unit: Option<String>,
12697}
12698
12699/// TimeTrunc
12700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12701#[cfg_attr(feature = "bindings", derive(TS))]
12702pub struct TimeTrunc {
12703    pub this: Box<Expression>,
12704    pub unit: String,
12705    #[serde(default)]
12706    pub zone: Option<Box<Expression>>,
12707}
12708
12709/// DateFromParts
12710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12711#[cfg_attr(feature = "bindings", derive(TS))]
12712pub struct DateFromParts {
12713    #[serde(default)]
12714    pub year: Option<Box<Expression>>,
12715    #[serde(default)]
12716    pub month: Option<Box<Expression>>,
12717    #[serde(default)]
12718    pub day: Option<Box<Expression>>,
12719    #[serde(default)]
12720    pub allow_overflow: Option<Box<Expression>>,
12721}
12722
12723/// TimeFromParts
12724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12725#[cfg_attr(feature = "bindings", derive(TS))]
12726pub struct TimeFromParts {
12727    #[serde(default)]
12728    pub hour: Option<Box<Expression>>,
12729    #[serde(default)]
12730    pub min: Option<Box<Expression>>,
12731    #[serde(default)]
12732    pub sec: Option<Box<Expression>>,
12733    #[serde(default)]
12734    pub nano: Option<Box<Expression>>,
12735    #[serde(default)]
12736    pub fractions: Option<Box<Expression>>,
12737    #[serde(default)]
12738    pub precision: Option<i64>,
12739}
12740
12741/// DecodeCase
12742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12743#[cfg_attr(feature = "bindings", derive(TS))]
12744pub struct DecodeCase {
12745    #[serde(default)]
12746    pub expressions: Vec<Expression>,
12747}
12748
12749/// Decrypt
12750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12751#[cfg_attr(feature = "bindings", derive(TS))]
12752pub struct Decrypt {
12753    pub this: Box<Expression>,
12754    #[serde(default)]
12755    pub passphrase: Option<Box<Expression>>,
12756    #[serde(default)]
12757    pub aad: Option<Box<Expression>>,
12758    #[serde(default)]
12759    pub encryption_method: Option<Box<Expression>>,
12760    #[serde(default)]
12761    pub safe: Option<Box<Expression>>,
12762}
12763
12764/// DecryptRaw
12765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12766#[cfg_attr(feature = "bindings", derive(TS))]
12767pub struct DecryptRaw {
12768    pub this: Box<Expression>,
12769    #[serde(default)]
12770    pub key: Option<Box<Expression>>,
12771    #[serde(default)]
12772    pub iv: Option<Box<Expression>>,
12773    #[serde(default)]
12774    pub aad: Option<Box<Expression>>,
12775    #[serde(default)]
12776    pub encryption_method: Option<Box<Expression>>,
12777    #[serde(default)]
12778    pub aead: Option<Box<Expression>>,
12779    #[serde(default)]
12780    pub safe: Option<Box<Expression>>,
12781}
12782
12783/// Encode
12784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12785#[cfg_attr(feature = "bindings", derive(TS))]
12786pub struct Encode {
12787    pub this: Box<Expression>,
12788    #[serde(default)]
12789    pub charset: Option<Box<Expression>>,
12790}
12791
12792/// Encrypt
12793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12794#[cfg_attr(feature = "bindings", derive(TS))]
12795pub struct Encrypt {
12796    pub this: Box<Expression>,
12797    #[serde(default)]
12798    pub passphrase: Option<Box<Expression>>,
12799    #[serde(default)]
12800    pub aad: Option<Box<Expression>>,
12801    #[serde(default)]
12802    pub encryption_method: Option<Box<Expression>>,
12803}
12804
12805/// EncryptRaw
12806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12807#[cfg_attr(feature = "bindings", derive(TS))]
12808pub struct EncryptRaw {
12809    pub this: Box<Expression>,
12810    #[serde(default)]
12811    pub key: Option<Box<Expression>>,
12812    #[serde(default)]
12813    pub iv: Option<Box<Expression>>,
12814    #[serde(default)]
12815    pub aad: Option<Box<Expression>>,
12816    #[serde(default)]
12817    pub encryption_method: Option<Box<Expression>>,
12818}
12819
12820/// EqualNull
12821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12822#[cfg_attr(feature = "bindings", derive(TS))]
12823pub struct EqualNull {
12824    pub this: Box<Expression>,
12825    pub expression: Box<Expression>,
12826}
12827
12828/// ToBinary
12829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12830#[cfg_attr(feature = "bindings", derive(TS))]
12831pub struct ToBinary {
12832    pub this: Box<Expression>,
12833    #[serde(default)]
12834    pub format: Option<String>,
12835    #[serde(default)]
12836    pub safe: Option<Box<Expression>>,
12837}
12838
12839/// Base64DecodeBinary
12840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12841#[cfg_attr(feature = "bindings", derive(TS))]
12842pub struct Base64DecodeBinary {
12843    pub this: Box<Expression>,
12844    #[serde(default)]
12845    pub alphabet: Option<Box<Expression>>,
12846}
12847
12848/// Base64DecodeString
12849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12850#[cfg_attr(feature = "bindings", derive(TS))]
12851pub struct Base64DecodeString {
12852    pub this: Box<Expression>,
12853    #[serde(default)]
12854    pub alphabet: Option<Box<Expression>>,
12855}
12856
12857/// Base64Encode
12858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12859#[cfg_attr(feature = "bindings", derive(TS))]
12860pub struct Base64Encode {
12861    pub this: Box<Expression>,
12862    #[serde(default)]
12863    pub max_line_length: Option<Box<Expression>>,
12864    #[serde(default)]
12865    pub alphabet: Option<Box<Expression>>,
12866}
12867
12868/// TryBase64DecodeBinary
12869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12870#[cfg_attr(feature = "bindings", derive(TS))]
12871pub struct TryBase64DecodeBinary {
12872    pub this: Box<Expression>,
12873    #[serde(default)]
12874    pub alphabet: Option<Box<Expression>>,
12875}
12876
12877/// TryBase64DecodeString
12878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12879#[cfg_attr(feature = "bindings", derive(TS))]
12880pub struct TryBase64DecodeString {
12881    pub this: Box<Expression>,
12882    #[serde(default)]
12883    pub alphabet: Option<Box<Expression>>,
12884}
12885
12886/// GapFill
12887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12888#[cfg_attr(feature = "bindings", derive(TS))]
12889pub struct GapFill {
12890    pub this: Box<Expression>,
12891    #[serde(default)]
12892    pub ts_column: Option<Box<Expression>>,
12893    #[serde(default)]
12894    pub bucket_width: Option<Box<Expression>>,
12895    #[serde(default)]
12896    pub partitioning_columns: Option<Box<Expression>>,
12897    #[serde(default)]
12898    pub value_columns: Option<Box<Expression>>,
12899    #[serde(default)]
12900    pub origin: Option<Box<Expression>>,
12901    #[serde(default)]
12902    pub ignore_nulls: Option<Box<Expression>>,
12903}
12904
12905/// GenerateDateArray
12906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12907#[cfg_attr(feature = "bindings", derive(TS))]
12908pub struct GenerateDateArray {
12909    #[serde(default)]
12910    pub start: Option<Box<Expression>>,
12911    #[serde(default)]
12912    pub end: Option<Box<Expression>>,
12913    #[serde(default)]
12914    pub step: Option<Box<Expression>>,
12915}
12916
12917/// GenerateTimestampArray
12918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12919#[cfg_attr(feature = "bindings", derive(TS))]
12920pub struct GenerateTimestampArray {
12921    #[serde(default)]
12922    pub start: Option<Box<Expression>>,
12923    #[serde(default)]
12924    pub end: Option<Box<Expression>>,
12925    #[serde(default)]
12926    pub step: Option<Box<Expression>>,
12927}
12928
12929/// GetExtract
12930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12931#[cfg_attr(feature = "bindings", derive(TS))]
12932pub struct GetExtract {
12933    pub this: Box<Expression>,
12934    pub expression: Box<Expression>,
12935}
12936
12937/// Getbit
12938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12939#[cfg_attr(feature = "bindings", derive(TS))]
12940pub struct Getbit {
12941    pub this: Box<Expression>,
12942    pub expression: Box<Expression>,
12943    #[serde(default)]
12944    pub zero_is_msb: Option<Box<Expression>>,
12945}
12946
12947/// OverflowTruncateBehavior
12948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12949#[cfg_attr(feature = "bindings", derive(TS))]
12950pub struct OverflowTruncateBehavior {
12951    #[serde(default)]
12952    pub this: Option<Box<Expression>>,
12953    #[serde(default)]
12954    pub with_count: Option<Box<Expression>>,
12955}
12956
12957/// HexEncode
12958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12959#[cfg_attr(feature = "bindings", derive(TS))]
12960pub struct HexEncode {
12961    pub this: Box<Expression>,
12962    #[serde(default)]
12963    pub case: Option<Box<Expression>>,
12964}
12965
12966/// Compress
12967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12968#[cfg_attr(feature = "bindings", derive(TS))]
12969pub struct Compress {
12970    pub this: Box<Expression>,
12971    #[serde(default)]
12972    pub method: Option<String>,
12973}
12974
12975/// DecompressBinary
12976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12977#[cfg_attr(feature = "bindings", derive(TS))]
12978pub struct DecompressBinary {
12979    pub this: Box<Expression>,
12980    pub method: String,
12981}
12982
12983/// DecompressString
12984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12985#[cfg_attr(feature = "bindings", derive(TS))]
12986pub struct DecompressString {
12987    pub this: Box<Expression>,
12988    pub method: String,
12989}
12990
12991/// Xor
12992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12993#[cfg_attr(feature = "bindings", derive(TS))]
12994pub struct Xor {
12995    #[serde(default)]
12996    pub this: Option<Box<Expression>>,
12997    #[serde(default)]
12998    pub expression: Option<Box<Expression>>,
12999    #[serde(default)]
13000    pub expressions: Vec<Expression>,
13001}
13002
13003/// Nullif
13004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13005#[cfg_attr(feature = "bindings", derive(TS))]
13006pub struct Nullif {
13007    pub this: Box<Expression>,
13008    pub expression: Box<Expression>,
13009}
13010
13011/// JSON
13012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13013#[cfg_attr(feature = "bindings", derive(TS))]
13014pub struct JSON {
13015    #[serde(default)]
13016    pub this: Option<Box<Expression>>,
13017    #[serde(default)]
13018    pub with_: Option<Box<Expression>>,
13019    #[serde(default)]
13020    pub unique: bool,
13021}
13022
13023/// JSONPath
13024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13025#[cfg_attr(feature = "bindings", derive(TS))]
13026pub struct JSONPath {
13027    #[serde(default)]
13028    pub expressions: Vec<Expression>,
13029    #[serde(default)]
13030    pub escape: Option<Box<Expression>>,
13031}
13032
13033/// JSONPathFilter
13034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13035#[cfg_attr(feature = "bindings", derive(TS))]
13036pub struct JSONPathFilter {
13037    pub this: Box<Expression>,
13038}
13039
13040/// JSONPathKey
13041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13042#[cfg_attr(feature = "bindings", derive(TS))]
13043pub struct JSONPathKey {
13044    pub this: Box<Expression>,
13045}
13046
13047/// JSONPathRecursive
13048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13049#[cfg_attr(feature = "bindings", derive(TS))]
13050pub struct JSONPathRecursive {
13051    #[serde(default)]
13052    pub this: Option<Box<Expression>>,
13053}
13054
13055/// JSONPathScript
13056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13057#[cfg_attr(feature = "bindings", derive(TS))]
13058pub struct JSONPathScript {
13059    pub this: Box<Expression>,
13060}
13061
13062/// JSONPathSlice
13063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13064#[cfg_attr(feature = "bindings", derive(TS))]
13065pub struct JSONPathSlice {
13066    #[serde(default)]
13067    pub start: Option<Box<Expression>>,
13068    #[serde(default)]
13069    pub end: Option<Box<Expression>>,
13070    #[serde(default)]
13071    pub step: Option<Box<Expression>>,
13072}
13073
13074/// JSONPathSelector
13075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13076#[cfg_attr(feature = "bindings", derive(TS))]
13077pub struct JSONPathSelector {
13078    pub this: Box<Expression>,
13079}
13080
13081/// JSONPathSubscript
13082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13083#[cfg_attr(feature = "bindings", derive(TS))]
13084pub struct JSONPathSubscript {
13085    pub this: Box<Expression>,
13086}
13087
13088/// JSONPathUnion
13089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13090#[cfg_attr(feature = "bindings", derive(TS))]
13091pub struct JSONPathUnion {
13092    #[serde(default)]
13093    pub expressions: Vec<Expression>,
13094}
13095
13096/// Format
13097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13098#[cfg_attr(feature = "bindings", derive(TS))]
13099pub struct Format {
13100    pub this: Box<Expression>,
13101    #[serde(default)]
13102    pub expressions: Vec<Expression>,
13103}
13104
13105/// JSONKeys
13106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13107#[cfg_attr(feature = "bindings", derive(TS))]
13108pub struct JSONKeys {
13109    pub this: Box<Expression>,
13110    #[serde(default)]
13111    pub expression: Option<Box<Expression>>,
13112    #[serde(default)]
13113    pub expressions: Vec<Expression>,
13114}
13115
13116/// JSONKeyValue
13117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13118#[cfg_attr(feature = "bindings", derive(TS))]
13119pub struct JSONKeyValue {
13120    pub this: Box<Expression>,
13121    pub expression: Box<Expression>,
13122}
13123
13124/// JSONKeysAtDepth
13125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13126#[cfg_attr(feature = "bindings", derive(TS))]
13127pub struct JSONKeysAtDepth {
13128    pub this: Box<Expression>,
13129    #[serde(default)]
13130    pub expression: Option<Box<Expression>>,
13131    #[serde(default)]
13132    pub mode: Option<Box<Expression>>,
13133}
13134
13135/// JSONObject
13136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13137#[cfg_attr(feature = "bindings", derive(TS))]
13138pub struct JSONObject {
13139    #[serde(default)]
13140    pub expressions: Vec<Expression>,
13141    #[serde(default)]
13142    pub null_handling: Option<Box<Expression>>,
13143    #[serde(default)]
13144    pub unique_keys: Option<Box<Expression>>,
13145    #[serde(default)]
13146    pub return_type: Option<Box<Expression>>,
13147    #[serde(default)]
13148    pub encoding: Option<Box<Expression>>,
13149}
13150
13151/// JSONObjectAgg
13152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13153#[cfg_attr(feature = "bindings", derive(TS))]
13154pub struct JSONObjectAgg {
13155    #[serde(default)]
13156    pub expressions: Vec<Expression>,
13157    #[serde(default)]
13158    pub null_handling: Option<Box<Expression>>,
13159    #[serde(default)]
13160    pub unique_keys: Option<Box<Expression>>,
13161    #[serde(default)]
13162    pub return_type: Option<Box<Expression>>,
13163    #[serde(default)]
13164    pub encoding: Option<Box<Expression>>,
13165}
13166
13167/// JSONBObjectAgg
13168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13169#[cfg_attr(feature = "bindings", derive(TS))]
13170pub struct JSONBObjectAgg {
13171    pub this: Box<Expression>,
13172    pub expression: Box<Expression>,
13173}
13174
13175/// JSONArray
13176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13177#[cfg_attr(feature = "bindings", derive(TS))]
13178pub struct JSONArray {
13179    #[serde(default)]
13180    pub expressions: Vec<Expression>,
13181    #[serde(default)]
13182    pub null_handling: Option<Box<Expression>>,
13183    #[serde(default)]
13184    pub return_type: Option<Box<Expression>>,
13185    #[serde(default)]
13186    pub strict: Option<Box<Expression>>,
13187}
13188
13189/// JSONArrayAgg
13190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13191#[cfg_attr(feature = "bindings", derive(TS))]
13192pub struct JSONArrayAgg {
13193    pub this: Box<Expression>,
13194    #[serde(default)]
13195    pub order: Option<Box<Expression>>,
13196    #[serde(default)]
13197    pub null_handling: Option<Box<Expression>>,
13198    #[serde(default)]
13199    pub return_type: Option<Box<Expression>>,
13200    #[serde(default)]
13201    pub strict: Option<Box<Expression>>,
13202}
13203
13204/// JSONExists
13205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13206#[cfg_attr(feature = "bindings", derive(TS))]
13207pub struct JSONExists {
13208    pub this: Box<Expression>,
13209    #[serde(default)]
13210    pub path: Option<Box<Expression>>,
13211    #[serde(default)]
13212    pub passing: Option<Box<Expression>>,
13213    #[serde(default)]
13214    pub on_condition: Option<Box<Expression>>,
13215    #[serde(default)]
13216    pub from_dcolonqmark: Option<Box<Expression>>,
13217}
13218
13219/// JSONColumnDef
13220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13221#[cfg_attr(feature = "bindings", derive(TS))]
13222pub struct JSONColumnDef {
13223    #[serde(default)]
13224    pub this: Option<Box<Expression>>,
13225    #[serde(default)]
13226    pub kind: Option<String>,
13227    #[serde(default)]
13228    pub path: Option<Box<Expression>>,
13229    #[serde(default)]
13230    pub nested_schema: Option<Box<Expression>>,
13231    #[serde(default)]
13232    pub ordinality: Option<Box<Expression>>,
13233}
13234
13235/// JSONSchema
13236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13237#[cfg_attr(feature = "bindings", derive(TS))]
13238pub struct JSONSchema {
13239    #[serde(default)]
13240    pub expressions: Vec<Expression>,
13241}
13242
13243/// JSONSet
13244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13245#[cfg_attr(feature = "bindings", derive(TS))]
13246pub struct JSONSet {
13247    pub this: Box<Expression>,
13248    #[serde(default)]
13249    pub expressions: Vec<Expression>,
13250}
13251
13252/// JSONStripNulls
13253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13254#[cfg_attr(feature = "bindings", derive(TS))]
13255pub struct JSONStripNulls {
13256    pub this: Box<Expression>,
13257    #[serde(default)]
13258    pub expression: Option<Box<Expression>>,
13259    #[serde(default)]
13260    pub include_arrays: Option<Box<Expression>>,
13261    #[serde(default)]
13262    pub remove_empty: Option<Box<Expression>>,
13263}
13264
13265/// JSONValue
13266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13267#[cfg_attr(feature = "bindings", derive(TS))]
13268pub struct JSONValue {
13269    pub this: Box<Expression>,
13270    #[serde(default)]
13271    pub path: Option<Box<Expression>>,
13272    #[serde(default)]
13273    pub returning: Option<Box<Expression>>,
13274    #[serde(default)]
13275    pub on_condition: Option<Box<Expression>>,
13276}
13277
13278/// JSONValueArray
13279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13280#[cfg_attr(feature = "bindings", derive(TS))]
13281pub struct JSONValueArray {
13282    pub this: Box<Expression>,
13283    #[serde(default)]
13284    pub expression: Option<Box<Expression>>,
13285}
13286
13287/// JSONRemove
13288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13289#[cfg_attr(feature = "bindings", derive(TS))]
13290pub struct JSONRemove {
13291    pub this: Box<Expression>,
13292    #[serde(default)]
13293    pub expressions: Vec<Expression>,
13294}
13295
13296/// JSONTable
13297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13298#[cfg_attr(feature = "bindings", derive(TS))]
13299pub struct JSONTable {
13300    pub this: Box<Expression>,
13301    #[serde(default)]
13302    pub schema: Option<Box<Expression>>,
13303    #[serde(default)]
13304    pub path: Option<Box<Expression>>,
13305    #[serde(default)]
13306    pub error_handling: Option<Box<Expression>>,
13307    #[serde(default)]
13308    pub empty_handling: Option<Box<Expression>>,
13309}
13310
13311/// JSONType
13312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13313#[cfg_attr(feature = "bindings", derive(TS))]
13314pub struct JSONType {
13315    pub this: Box<Expression>,
13316    #[serde(default)]
13317    pub expression: Option<Box<Expression>>,
13318}
13319
13320/// ObjectInsert
13321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13322#[cfg_attr(feature = "bindings", derive(TS))]
13323pub struct ObjectInsert {
13324    pub this: Box<Expression>,
13325    #[serde(default)]
13326    pub key: Option<Box<Expression>>,
13327    #[serde(default)]
13328    pub value: Option<Box<Expression>>,
13329    #[serde(default)]
13330    pub update_flag: Option<Box<Expression>>,
13331}
13332
13333/// OpenJSONColumnDef
13334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13335#[cfg_attr(feature = "bindings", derive(TS))]
13336pub struct OpenJSONColumnDef {
13337    pub this: Box<Expression>,
13338    pub kind: String,
13339    #[serde(default)]
13340    pub path: Option<Box<Expression>>,
13341    #[serde(default)]
13342    pub as_json: Option<Box<Expression>>,
13343    /// The parsed data type for proper generation
13344    #[serde(default, skip_serializing_if = "Option::is_none")]
13345    pub data_type: Option<DataType>,
13346}
13347
13348/// OpenJSON
13349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13350#[cfg_attr(feature = "bindings", derive(TS))]
13351pub struct OpenJSON {
13352    pub this: Box<Expression>,
13353    #[serde(default)]
13354    pub path: Option<Box<Expression>>,
13355    #[serde(default)]
13356    pub expressions: Vec<Expression>,
13357}
13358
13359/// JSONBExists
13360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13361#[cfg_attr(feature = "bindings", derive(TS))]
13362pub struct JSONBExists {
13363    pub this: Box<Expression>,
13364    #[serde(default)]
13365    pub path: Option<Box<Expression>>,
13366}
13367
13368/// JSONCast
13369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13370#[cfg_attr(feature = "bindings", derive(TS))]
13371pub struct JSONCast {
13372    pub this: Box<Expression>,
13373    pub to: DataType,
13374}
13375
13376/// JSONExtract
13377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13378#[cfg_attr(feature = "bindings", derive(TS))]
13379pub struct JSONExtract {
13380    pub this: Box<Expression>,
13381    pub expression: Box<Expression>,
13382    #[serde(default)]
13383    pub only_json_types: Option<Box<Expression>>,
13384    #[serde(default)]
13385    pub expressions: Vec<Expression>,
13386    #[serde(default)]
13387    pub variant_extract: Option<Box<Expression>>,
13388    #[serde(default)]
13389    pub json_query: Option<Box<Expression>>,
13390    #[serde(default)]
13391    pub option: Option<Box<Expression>>,
13392    #[serde(default)]
13393    pub quote: Option<Box<Expression>>,
13394    #[serde(default)]
13395    pub on_condition: Option<Box<Expression>>,
13396    #[serde(default)]
13397    pub requires_json: Option<Box<Expression>>,
13398}
13399
13400/// JSONExtractQuote
13401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13402#[cfg_attr(feature = "bindings", derive(TS))]
13403pub struct JSONExtractQuote {
13404    #[serde(default)]
13405    pub option: Option<Box<Expression>>,
13406    #[serde(default)]
13407    pub scalar: Option<Box<Expression>>,
13408}
13409
13410/// JSONExtractArray
13411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13412#[cfg_attr(feature = "bindings", derive(TS))]
13413pub struct JSONExtractArray {
13414    pub this: Box<Expression>,
13415    #[serde(default)]
13416    pub expression: Option<Box<Expression>>,
13417}
13418
13419/// JSONExtractScalar
13420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13421#[cfg_attr(feature = "bindings", derive(TS))]
13422pub struct JSONExtractScalar {
13423    pub this: Box<Expression>,
13424    pub expression: Box<Expression>,
13425    #[serde(default)]
13426    pub only_json_types: Option<Box<Expression>>,
13427    #[serde(default)]
13428    pub expressions: Vec<Expression>,
13429    #[serde(default)]
13430    pub json_type: Option<Box<Expression>>,
13431    #[serde(default)]
13432    pub scalar_only: Option<Box<Expression>>,
13433}
13434
13435/// JSONBExtractScalar
13436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13437#[cfg_attr(feature = "bindings", derive(TS))]
13438pub struct JSONBExtractScalar {
13439    pub this: Box<Expression>,
13440    pub expression: Box<Expression>,
13441    #[serde(default)]
13442    pub json_type: Option<Box<Expression>>,
13443}
13444
13445/// JSONFormat
13446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13447#[cfg_attr(feature = "bindings", derive(TS))]
13448pub struct JSONFormat {
13449    #[serde(default)]
13450    pub this: Option<Box<Expression>>,
13451    #[serde(default)]
13452    pub options: Vec<Expression>,
13453    #[serde(default)]
13454    pub is_json: Option<Box<Expression>>,
13455    #[serde(default)]
13456    pub to_json: Option<Box<Expression>>,
13457}
13458
13459/// JSONArrayAppend
13460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13461#[cfg_attr(feature = "bindings", derive(TS))]
13462pub struct JSONArrayAppend {
13463    pub this: Box<Expression>,
13464    #[serde(default)]
13465    pub expressions: Vec<Expression>,
13466}
13467
13468/// JSONArrayContains
13469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13470#[cfg_attr(feature = "bindings", derive(TS))]
13471pub struct JSONArrayContains {
13472    pub this: Box<Expression>,
13473    pub expression: Box<Expression>,
13474    #[serde(default)]
13475    pub json_type: Option<Box<Expression>>,
13476}
13477
13478/// JSONArrayInsert
13479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13480#[cfg_attr(feature = "bindings", derive(TS))]
13481pub struct JSONArrayInsert {
13482    pub this: Box<Expression>,
13483    #[serde(default)]
13484    pub expressions: Vec<Expression>,
13485}
13486
13487/// ParseJSON
13488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13489#[cfg_attr(feature = "bindings", derive(TS))]
13490pub struct ParseJSON {
13491    pub this: Box<Expression>,
13492    #[serde(default)]
13493    pub expression: Option<Box<Expression>>,
13494    #[serde(default)]
13495    pub safe: Option<Box<Expression>>,
13496}
13497
13498/// ParseUrl
13499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13500#[cfg_attr(feature = "bindings", derive(TS))]
13501pub struct ParseUrl {
13502    pub this: Box<Expression>,
13503    #[serde(default)]
13504    pub part_to_extract: Option<Box<Expression>>,
13505    #[serde(default)]
13506    pub key: Option<Box<Expression>>,
13507    #[serde(default)]
13508    pub permissive: Option<Box<Expression>>,
13509}
13510
13511/// ParseIp
13512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13513#[cfg_attr(feature = "bindings", derive(TS))]
13514pub struct ParseIp {
13515    pub this: Box<Expression>,
13516    #[serde(default)]
13517    pub type_: Option<Box<Expression>>,
13518    #[serde(default)]
13519    pub permissive: Option<Box<Expression>>,
13520}
13521
13522/// ParseTime
13523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13524#[cfg_attr(feature = "bindings", derive(TS))]
13525pub struct ParseTime {
13526    pub this: Box<Expression>,
13527    pub format: String,
13528}
13529
13530/// ParseDatetime
13531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13532#[cfg_attr(feature = "bindings", derive(TS))]
13533pub struct ParseDatetime {
13534    pub this: Box<Expression>,
13535    #[serde(default)]
13536    pub format: Option<String>,
13537    #[serde(default)]
13538    pub zone: Option<Box<Expression>>,
13539}
13540
13541/// Map
13542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13543#[cfg_attr(feature = "bindings", derive(TS))]
13544pub struct Map {
13545    #[serde(default)]
13546    pub keys: Vec<Expression>,
13547    #[serde(default)]
13548    pub values: Vec<Expression>,
13549}
13550
13551/// MapCat
13552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13553#[cfg_attr(feature = "bindings", derive(TS))]
13554pub struct MapCat {
13555    pub this: Box<Expression>,
13556    pub expression: Box<Expression>,
13557}
13558
13559/// MapDelete
13560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13561#[cfg_attr(feature = "bindings", derive(TS))]
13562pub struct MapDelete {
13563    pub this: Box<Expression>,
13564    #[serde(default)]
13565    pub expressions: Vec<Expression>,
13566}
13567
13568/// MapInsert
13569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13570#[cfg_attr(feature = "bindings", derive(TS))]
13571pub struct MapInsert {
13572    pub this: Box<Expression>,
13573    #[serde(default)]
13574    pub key: Option<Box<Expression>>,
13575    #[serde(default)]
13576    pub value: Option<Box<Expression>>,
13577    #[serde(default)]
13578    pub update_flag: Option<Box<Expression>>,
13579}
13580
13581/// MapPick
13582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13583#[cfg_attr(feature = "bindings", derive(TS))]
13584pub struct MapPick {
13585    pub this: Box<Expression>,
13586    #[serde(default)]
13587    pub expressions: Vec<Expression>,
13588}
13589
13590/// ScopeResolution
13591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13592#[cfg_attr(feature = "bindings", derive(TS))]
13593pub struct ScopeResolution {
13594    #[serde(default)]
13595    pub this: Option<Box<Expression>>,
13596    pub expression: Box<Expression>,
13597}
13598
13599/// Slice
13600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13601#[cfg_attr(feature = "bindings", derive(TS))]
13602pub struct Slice {
13603    #[serde(default)]
13604    pub this: Option<Box<Expression>>,
13605    #[serde(default)]
13606    pub expression: Option<Box<Expression>>,
13607    #[serde(default)]
13608    pub step: Option<Box<Expression>>,
13609}
13610
13611/// VarMap
13612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13613#[cfg_attr(feature = "bindings", derive(TS))]
13614pub struct VarMap {
13615    #[serde(default)]
13616    pub keys: Vec<Expression>,
13617    #[serde(default)]
13618    pub values: Vec<Expression>,
13619}
13620
13621/// MatchAgainst
13622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13623#[cfg_attr(feature = "bindings", derive(TS))]
13624pub struct MatchAgainst {
13625    pub this: Box<Expression>,
13626    #[serde(default)]
13627    pub expressions: Vec<Expression>,
13628    #[serde(default)]
13629    pub modifier: Option<Box<Expression>>,
13630}
13631
13632/// MD5Digest
13633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13634#[cfg_attr(feature = "bindings", derive(TS))]
13635pub struct MD5Digest {
13636    pub this: Box<Expression>,
13637    #[serde(default)]
13638    pub expressions: Vec<Expression>,
13639}
13640
13641/// Monthname
13642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13643#[cfg_attr(feature = "bindings", derive(TS))]
13644pub struct Monthname {
13645    pub this: Box<Expression>,
13646    #[serde(default)]
13647    pub abbreviated: Option<Box<Expression>>,
13648}
13649
13650/// Ntile
13651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13652#[cfg_attr(feature = "bindings", derive(TS))]
13653pub struct Ntile {
13654    #[serde(default)]
13655    pub this: Option<Box<Expression>>,
13656}
13657
13658/// Normalize
13659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13660#[cfg_attr(feature = "bindings", derive(TS))]
13661pub struct Normalize {
13662    pub this: Box<Expression>,
13663    #[serde(default)]
13664    pub form: Option<Box<Expression>>,
13665    #[serde(default)]
13666    pub is_casefold: Option<Box<Expression>>,
13667}
13668
13669/// Normal
13670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13671#[cfg_attr(feature = "bindings", derive(TS))]
13672pub struct Normal {
13673    pub this: Box<Expression>,
13674    #[serde(default)]
13675    pub stddev: Option<Box<Expression>>,
13676    #[serde(default)]
13677    pub gen: Option<Box<Expression>>,
13678}
13679
13680/// Predict
13681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13682#[cfg_attr(feature = "bindings", derive(TS))]
13683pub struct Predict {
13684    pub this: Box<Expression>,
13685    pub expression: Box<Expression>,
13686    #[serde(default)]
13687    pub params_struct: Option<Box<Expression>>,
13688}
13689
13690/// MLTranslate
13691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13692#[cfg_attr(feature = "bindings", derive(TS))]
13693pub struct MLTranslate {
13694    pub this: Box<Expression>,
13695    pub expression: Box<Expression>,
13696    #[serde(default)]
13697    pub params_struct: Option<Box<Expression>>,
13698}
13699
13700/// FeaturesAtTime
13701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13702#[cfg_attr(feature = "bindings", derive(TS))]
13703pub struct FeaturesAtTime {
13704    pub this: Box<Expression>,
13705    #[serde(default)]
13706    pub time: Option<Box<Expression>>,
13707    #[serde(default)]
13708    pub num_rows: Option<Box<Expression>>,
13709    #[serde(default)]
13710    pub ignore_feature_nulls: Option<Box<Expression>>,
13711}
13712
13713/// GenerateEmbedding
13714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13715#[cfg_attr(feature = "bindings", derive(TS))]
13716pub struct GenerateEmbedding {
13717    pub this: Box<Expression>,
13718    pub expression: Box<Expression>,
13719    #[serde(default)]
13720    pub params_struct: Option<Box<Expression>>,
13721    #[serde(default)]
13722    pub is_text: Option<Box<Expression>>,
13723}
13724
13725/// MLForecast
13726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13727#[cfg_attr(feature = "bindings", derive(TS))]
13728pub struct MLForecast {
13729    pub this: Box<Expression>,
13730    #[serde(default)]
13731    pub expression: Option<Box<Expression>>,
13732    #[serde(default)]
13733    pub params_struct: Option<Box<Expression>>,
13734}
13735
13736/// ModelAttribute
13737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13738#[cfg_attr(feature = "bindings", derive(TS))]
13739pub struct ModelAttribute {
13740    pub this: Box<Expression>,
13741    pub expression: Box<Expression>,
13742}
13743
13744/// VectorSearch
13745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13746#[cfg_attr(feature = "bindings", derive(TS))]
13747pub struct VectorSearch {
13748    pub this: Box<Expression>,
13749    #[serde(default)]
13750    pub column_to_search: Option<Box<Expression>>,
13751    #[serde(default)]
13752    pub query_table: Option<Box<Expression>>,
13753    #[serde(default)]
13754    pub query_column_to_search: Option<Box<Expression>>,
13755    #[serde(default)]
13756    pub top_k: Option<Box<Expression>>,
13757    #[serde(default)]
13758    pub distance_type: Option<Box<Expression>>,
13759    #[serde(default)]
13760    pub options: Vec<Expression>,
13761}
13762
13763/// Quantile
13764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13765#[cfg_attr(feature = "bindings", derive(TS))]
13766pub struct Quantile {
13767    pub this: Box<Expression>,
13768    #[serde(default)]
13769    pub quantile: Option<Box<Expression>>,
13770}
13771
13772/// ApproxQuantile
13773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13774#[cfg_attr(feature = "bindings", derive(TS))]
13775pub struct ApproxQuantile {
13776    pub this: Box<Expression>,
13777    #[serde(default)]
13778    pub quantile: Option<Box<Expression>>,
13779    #[serde(default)]
13780    pub accuracy: Option<Box<Expression>>,
13781    #[serde(default)]
13782    pub weight: Option<Box<Expression>>,
13783    #[serde(default)]
13784    pub error_tolerance: Option<Box<Expression>>,
13785}
13786
13787/// ApproxPercentileEstimate
13788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13789#[cfg_attr(feature = "bindings", derive(TS))]
13790pub struct ApproxPercentileEstimate {
13791    pub this: Box<Expression>,
13792    #[serde(default)]
13793    pub percentile: Option<Box<Expression>>,
13794}
13795
13796/// Randn
13797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13798#[cfg_attr(feature = "bindings", derive(TS))]
13799pub struct Randn {
13800    #[serde(default)]
13801    pub this: Option<Box<Expression>>,
13802}
13803
13804/// Randstr
13805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13806#[cfg_attr(feature = "bindings", derive(TS))]
13807pub struct Randstr {
13808    pub this: Box<Expression>,
13809    #[serde(default)]
13810    pub generator: Option<Box<Expression>>,
13811}
13812
13813/// RangeN
13814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13815#[cfg_attr(feature = "bindings", derive(TS))]
13816pub struct RangeN {
13817    pub this: Box<Expression>,
13818    #[serde(default)]
13819    pub expressions: Vec<Expression>,
13820    #[serde(default)]
13821    pub each: Option<Box<Expression>>,
13822}
13823
13824/// RangeBucket
13825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13826#[cfg_attr(feature = "bindings", derive(TS))]
13827pub struct RangeBucket {
13828    pub this: Box<Expression>,
13829    pub expression: Box<Expression>,
13830}
13831
13832/// ReadCSV
13833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13834#[cfg_attr(feature = "bindings", derive(TS))]
13835pub struct ReadCSV {
13836    pub this: Box<Expression>,
13837    #[serde(default)]
13838    pub expressions: Vec<Expression>,
13839}
13840
13841/// ReadParquet
13842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13843#[cfg_attr(feature = "bindings", derive(TS))]
13844pub struct ReadParquet {
13845    #[serde(default)]
13846    pub expressions: Vec<Expression>,
13847}
13848
13849/// Reduce
13850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13851#[cfg_attr(feature = "bindings", derive(TS))]
13852pub struct Reduce {
13853    pub this: Box<Expression>,
13854    #[serde(default)]
13855    pub initial: Option<Box<Expression>>,
13856    #[serde(default)]
13857    pub merge: Option<Box<Expression>>,
13858    #[serde(default)]
13859    pub finish: Option<Box<Expression>>,
13860}
13861
13862/// RegexpExtractAll
13863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13864#[cfg_attr(feature = "bindings", derive(TS))]
13865pub struct RegexpExtractAll {
13866    pub this: Box<Expression>,
13867    pub expression: Box<Expression>,
13868    #[serde(default)]
13869    pub group: Option<Box<Expression>>,
13870    #[serde(default)]
13871    pub parameters: Option<Box<Expression>>,
13872    #[serde(default)]
13873    pub position: Option<Box<Expression>>,
13874    #[serde(default)]
13875    pub occurrence: Option<Box<Expression>>,
13876}
13877
13878/// RegexpILike
13879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13880#[cfg_attr(feature = "bindings", derive(TS))]
13881pub struct RegexpILike {
13882    pub this: Box<Expression>,
13883    pub expression: Box<Expression>,
13884    #[serde(default)]
13885    pub flag: Option<Box<Expression>>,
13886}
13887
13888/// RegexpFullMatch
13889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13890#[cfg_attr(feature = "bindings", derive(TS))]
13891pub struct RegexpFullMatch {
13892    pub this: Box<Expression>,
13893    pub expression: Box<Expression>,
13894    #[serde(default)]
13895    pub options: Vec<Expression>,
13896}
13897
13898/// RegexpInstr
13899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13900#[cfg_attr(feature = "bindings", derive(TS))]
13901pub struct RegexpInstr {
13902    pub this: Box<Expression>,
13903    pub expression: Box<Expression>,
13904    #[serde(default)]
13905    pub position: Option<Box<Expression>>,
13906    #[serde(default)]
13907    pub occurrence: Option<Box<Expression>>,
13908    #[serde(default)]
13909    pub option: Option<Box<Expression>>,
13910    #[serde(default)]
13911    pub parameters: Option<Box<Expression>>,
13912    #[serde(default)]
13913    pub group: Option<Box<Expression>>,
13914}
13915
13916/// RegexpSplit
13917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13918#[cfg_attr(feature = "bindings", derive(TS))]
13919pub struct RegexpSplit {
13920    pub this: Box<Expression>,
13921    pub expression: Box<Expression>,
13922    #[serde(default)]
13923    pub limit: Option<Box<Expression>>,
13924}
13925
13926/// RegexpCount
13927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13928#[cfg_attr(feature = "bindings", derive(TS))]
13929pub struct RegexpCount {
13930    pub this: Box<Expression>,
13931    pub expression: Box<Expression>,
13932    #[serde(default)]
13933    pub position: Option<Box<Expression>>,
13934    #[serde(default)]
13935    pub parameters: Option<Box<Expression>>,
13936}
13937
13938/// RegrValx
13939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13940#[cfg_attr(feature = "bindings", derive(TS))]
13941pub struct RegrValx {
13942    pub this: Box<Expression>,
13943    pub expression: Box<Expression>,
13944}
13945
13946/// RegrValy
13947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13948#[cfg_attr(feature = "bindings", derive(TS))]
13949pub struct RegrValy {
13950    pub this: Box<Expression>,
13951    pub expression: Box<Expression>,
13952}
13953
13954/// RegrAvgy
13955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13956#[cfg_attr(feature = "bindings", derive(TS))]
13957pub struct RegrAvgy {
13958    pub this: Box<Expression>,
13959    pub expression: Box<Expression>,
13960}
13961
13962/// RegrAvgx
13963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13964#[cfg_attr(feature = "bindings", derive(TS))]
13965pub struct RegrAvgx {
13966    pub this: Box<Expression>,
13967    pub expression: Box<Expression>,
13968}
13969
13970/// RegrCount
13971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13972#[cfg_attr(feature = "bindings", derive(TS))]
13973pub struct RegrCount {
13974    pub this: Box<Expression>,
13975    pub expression: Box<Expression>,
13976}
13977
13978/// RegrIntercept
13979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13980#[cfg_attr(feature = "bindings", derive(TS))]
13981pub struct RegrIntercept {
13982    pub this: Box<Expression>,
13983    pub expression: Box<Expression>,
13984}
13985
13986/// RegrR2
13987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13988#[cfg_attr(feature = "bindings", derive(TS))]
13989pub struct RegrR2 {
13990    pub this: Box<Expression>,
13991    pub expression: Box<Expression>,
13992}
13993
13994/// RegrSxx
13995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13996#[cfg_attr(feature = "bindings", derive(TS))]
13997pub struct RegrSxx {
13998    pub this: Box<Expression>,
13999    pub expression: Box<Expression>,
14000}
14001
14002/// RegrSxy
14003#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14004#[cfg_attr(feature = "bindings", derive(TS))]
14005pub struct RegrSxy {
14006    pub this: Box<Expression>,
14007    pub expression: Box<Expression>,
14008}
14009
14010/// RegrSyy
14011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14012#[cfg_attr(feature = "bindings", derive(TS))]
14013pub struct RegrSyy {
14014    pub this: Box<Expression>,
14015    pub expression: Box<Expression>,
14016}
14017
14018/// RegrSlope
14019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14020#[cfg_attr(feature = "bindings", derive(TS))]
14021pub struct RegrSlope {
14022    pub this: Box<Expression>,
14023    pub expression: Box<Expression>,
14024}
14025
14026/// SafeAdd
14027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14028#[cfg_attr(feature = "bindings", derive(TS))]
14029pub struct SafeAdd {
14030    pub this: Box<Expression>,
14031    pub expression: Box<Expression>,
14032}
14033
14034/// SafeDivide
14035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14036#[cfg_attr(feature = "bindings", derive(TS))]
14037pub struct SafeDivide {
14038    pub this: Box<Expression>,
14039    pub expression: Box<Expression>,
14040}
14041
14042/// SafeMultiply
14043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14044#[cfg_attr(feature = "bindings", derive(TS))]
14045pub struct SafeMultiply {
14046    pub this: Box<Expression>,
14047    pub expression: Box<Expression>,
14048}
14049
14050/// SafeSubtract
14051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14052#[cfg_attr(feature = "bindings", derive(TS))]
14053pub struct SafeSubtract {
14054    pub this: Box<Expression>,
14055    pub expression: Box<Expression>,
14056}
14057
14058/// SHA2
14059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14060#[cfg_attr(feature = "bindings", derive(TS))]
14061pub struct SHA2 {
14062    pub this: Box<Expression>,
14063    #[serde(default)]
14064    pub length: Option<i64>,
14065}
14066
14067/// SHA2Digest
14068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14069#[cfg_attr(feature = "bindings", derive(TS))]
14070pub struct SHA2Digest {
14071    pub this: Box<Expression>,
14072    #[serde(default)]
14073    pub length: Option<i64>,
14074}
14075
14076/// SortArray
14077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14078#[cfg_attr(feature = "bindings", derive(TS))]
14079pub struct SortArray {
14080    pub this: Box<Expression>,
14081    #[serde(default)]
14082    pub asc: Option<Box<Expression>>,
14083    #[serde(default)]
14084    pub nulls_first: Option<Box<Expression>>,
14085}
14086
14087/// SplitPart
14088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14089#[cfg_attr(feature = "bindings", derive(TS))]
14090pub struct SplitPart {
14091    pub this: Box<Expression>,
14092    #[serde(default)]
14093    pub delimiter: Option<Box<Expression>>,
14094    #[serde(default)]
14095    pub part_index: Option<Box<Expression>>,
14096}
14097
14098/// SUBSTRING_INDEX(str, delim, count)
14099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14100#[cfg_attr(feature = "bindings", derive(TS))]
14101pub struct SubstringIndex {
14102    pub this: Box<Expression>,
14103    #[serde(default)]
14104    pub delimiter: Option<Box<Expression>>,
14105    #[serde(default)]
14106    pub count: Option<Box<Expression>>,
14107}
14108
14109/// StandardHash
14110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14111#[cfg_attr(feature = "bindings", derive(TS))]
14112pub struct StandardHash {
14113    pub this: Box<Expression>,
14114    #[serde(default)]
14115    pub expression: Option<Box<Expression>>,
14116}
14117
14118/// StrPosition
14119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14120#[cfg_attr(feature = "bindings", derive(TS))]
14121pub struct StrPosition {
14122    pub this: Box<Expression>,
14123    #[serde(default)]
14124    pub substr: Option<Box<Expression>>,
14125    #[serde(default)]
14126    pub position: Option<Box<Expression>>,
14127    #[serde(default)]
14128    pub occurrence: Option<Box<Expression>>,
14129}
14130
14131/// Search
14132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14133#[cfg_attr(feature = "bindings", derive(TS))]
14134pub struct Search {
14135    pub this: Box<Expression>,
14136    pub expression: Box<Expression>,
14137    #[serde(default)]
14138    pub json_scope: Option<Box<Expression>>,
14139    #[serde(default)]
14140    pub analyzer: Option<Box<Expression>>,
14141    #[serde(default)]
14142    pub analyzer_options: Option<Box<Expression>>,
14143    #[serde(default)]
14144    pub search_mode: Option<Box<Expression>>,
14145}
14146
14147/// SearchIp
14148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14149#[cfg_attr(feature = "bindings", derive(TS))]
14150pub struct SearchIp {
14151    pub this: Box<Expression>,
14152    pub expression: Box<Expression>,
14153}
14154
14155/// StrToDate
14156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14157#[cfg_attr(feature = "bindings", derive(TS))]
14158pub struct StrToDate {
14159    pub this: Box<Expression>,
14160    #[serde(default)]
14161    pub format: Option<String>,
14162    #[serde(default)]
14163    pub safe: Option<Box<Expression>>,
14164}
14165
14166/// StrToTime
14167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14168#[cfg_attr(feature = "bindings", derive(TS))]
14169pub struct StrToTime {
14170    pub this: Box<Expression>,
14171    pub format: String,
14172    #[serde(default)]
14173    pub zone: Option<Box<Expression>>,
14174    #[serde(default)]
14175    pub safe: Option<Box<Expression>>,
14176    #[serde(default)]
14177    pub target_type: Option<Box<Expression>>,
14178}
14179
14180/// StrToUnix
14181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14182#[cfg_attr(feature = "bindings", derive(TS))]
14183pub struct StrToUnix {
14184    #[serde(default)]
14185    pub this: Option<Box<Expression>>,
14186    #[serde(default)]
14187    pub format: Option<String>,
14188}
14189
14190/// StrToMap
14191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14192#[cfg_attr(feature = "bindings", derive(TS))]
14193pub struct StrToMap {
14194    pub this: Box<Expression>,
14195    #[serde(default)]
14196    pub pair_delim: Option<Box<Expression>>,
14197    #[serde(default)]
14198    pub key_value_delim: Option<Box<Expression>>,
14199    #[serde(default)]
14200    pub duplicate_resolution_callback: Option<Box<Expression>>,
14201}
14202
14203/// NumberToStr
14204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14205#[cfg_attr(feature = "bindings", derive(TS))]
14206pub struct NumberToStr {
14207    pub this: Box<Expression>,
14208    pub format: String,
14209    #[serde(default)]
14210    pub culture: Option<Box<Expression>>,
14211}
14212
14213/// FromBase
14214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14215#[cfg_attr(feature = "bindings", derive(TS))]
14216pub struct FromBase {
14217    pub this: Box<Expression>,
14218    pub expression: Box<Expression>,
14219}
14220
14221/// Stuff
14222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14223#[cfg_attr(feature = "bindings", derive(TS))]
14224pub struct Stuff {
14225    pub this: Box<Expression>,
14226    #[serde(default)]
14227    pub start: Option<Box<Expression>>,
14228    #[serde(default)]
14229    pub length: Option<i64>,
14230    pub expression: Box<Expression>,
14231}
14232
14233/// TimeToStr
14234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14235#[cfg_attr(feature = "bindings", derive(TS))]
14236pub struct TimeToStr {
14237    pub this: Box<Expression>,
14238    pub format: String,
14239    #[serde(default)]
14240    pub culture: Option<Box<Expression>>,
14241    #[serde(default)]
14242    pub zone: Option<Box<Expression>>,
14243}
14244
14245/// TimeStrToTime
14246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14247#[cfg_attr(feature = "bindings", derive(TS))]
14248pub struct TimeStrToTime {
14249    pub this: Box<Expression>,
14250    #[serde(default)]
14251    pub zone: Option<Box<Expression>>,
14252}
14253
14254/// TsOrDsAdd
14255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14256#[cfg_attr(feature = "bindings", derive(TS))]
14257pub struct TsOrDsAdd {
14258    pub this: Box<Expression>,
14259    pub expression: Box<Expression>,
14260    #[serde(default)]
14261    pub unit: Option<String>,
14262    #[serde(default)]
14263    pub return_type: Option<Box<Expression>>,
14264}
14265
14266/// TsOrDsDiff
14267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14268#[cfg_attr(feature = "bindings", derive(TS))]
14269pub struct TsOrDsDiff {
14270    pub this: Box<Expression>,
14271    pub expression: Box<Expression>,
14272    #[serde(default)]
14273    pub unit: Option<String>,
14274}
14275
14276/// TsOrDsToDate
14277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14278#[cfg_attr(feature = "bindings", derive(TS))]
14279pub struct TsOrDsToDate {
14280    pub this: Box<Expression>,
14281    #[serde(default)]
14282    pub format: Option<String>,
14283    #[serde(default)]
14284    pub safe: Option<Box<Expression>>,
14285}
14286
14287/// TsOrDsToTime
14288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14289#[cfg_attr(feature = "bindings", derive(TS))]
14290pub struct TsOrDsToTime {
14291    pub this: Box<Expression>,
14292    #[serde(default)]
14293    pub format: Option<String>,
14294    #[serde(default)]
14295    pub safe: Option<Box<Expression>>,
14296}
14297
14298/// Unhex
14299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14300#[cfg_attr(feature = "bindings", derive(TS))]
14301pub struct Unhex {
14302    pub this: Box<Expression>,
14303    #[serde(default)]
14304    pub expression: Option<Box<Expression>>,
14305}
14306
14307/// Uniform
14308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14309#[cfg_attr(feature = "bindings", derive(TS))]
14310pub struct Uniform {
14311    pub this: Box<Expression>,
14312    pub expression: Box<Expression>,
14313    #[serde(default)]
14314    pub gen: Option<Box<Expression>>,
14315    #[serde(default)]
14316    pub seed: Option<Box<Expression>>,
14317}
14318
14319/// UnixToStr
14320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14321#[cfg_attr(feature = "bindings", derive(TS))]
14322pub struct UnixToStr {
14323    pub this: Box<Expression>,
14324    #[serde(default)]
14325    pub format: Option<String>,
14326}
14327
14328/// UnixToTime
14329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14330#[cfg_attr(feature = "bindings", derive(TS))]
14331pub struct UnixToTime {
14332    pub this: Box<Expression>,
14333    #[serde(default)]
14334    pub scale: Option<i64>,
14335    #[serde(default)]
14336    pub zone: Option<Box<Expression>>,
14337    #[serde(default)]
14338    pub hours: Option<Box<Expression>>,
14339    #[serde(default)]
14340    pub minutes: Option<Box<Expression>>,
14341    #[serde(default)]
14342    pub format: Option<String>,
14343    #[serde(default)]
14344    pub target_type: Option<Box<Expression>>,
14345}
14346
14347/// Uuid
14348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14349#[cfg_attr(feature = "bindings", derive(TS))]
14350pub struct Uuid {
14351    #[serde(default)]
14352    pub this: Option<Box<Expression>>,
14353    #[serde(default)]
14354    pub name: Option<String>,
14355    #[serde(default)]
14356    pub is_string: Option<Box<Expression>>,
14357}
14358
14359/// TimestampFromParts
14360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14361#[cfg_attr(feature = "bindings", derive(TS))]
14362pub struct TimestampFromParts {
14363    #[serde(default)]
14364    pub zone: Option<Box<Expression>>,
14365    #[serde(default)]
14366    pub milli: Option<Box<Expression>>,
14367    #[serde(default)]
14368    pub this: Option<Box<Expression>>,
14369    #[serde(default)]
14370    pub expression: Option<Box<Expression>>,
14371}
14372
14373/// TimestampTzFromParts
14374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14375#[cfg_attr(feature = "bindings", derive(TS))]
14376pub struct TimestampTzFromParts {
14377    #[serde(default)]
14378    pub zone: Option<Box<Expression>>,
14379}
14380
14381/// Corr
14382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14383#[cfg_attr(feature = "bindings", derive(TS))]
14384pub struct Corr {
14385    pub this: Box<Expression>,
14386    pub expression: Box<Expression>,
14387    #[serde(default)]
14388    pub null_on_zero_variance: Option<Box<Expression>>,
14389}
14390
14391/// WidthBucket
14392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14393#[cfg_attr(feature = "bindings", derive(TS))]
14394pub struct WidthBucket {
14395    pub this: Box<Expression>,
14396    #[serde(default)]
14397    pub min_value: Option<Box<Expression>>,
14398    #[serde(default)]
14399    pub max_value: Option<Box<Expression>>,
14400    #[serde(default)]
14401    pub num_buckets: Option<Box<Expression>>,
14402    #[serde(default)]
14403    pub threshold: Option<Box<Expression>>,
14404}
14405
14406/// CovarSamp
14407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14408#[cfg_attr(feature = "bindings", derive(TS))]
14409pub struct CovarSamp {
14410    pub this: Box<Expression>,
14411    pub expression: Box<Expression>,
14412}
14413
14414/// CovarPop
14415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14416#[cfg_attr(feature = "bindings", derive(TS))]
14417pub struct CovarPop {
14418    pub this: Box<Expression>,
14419    pub expression: Box<Expression>,
14420}
14421
14422/// Week
14423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14424#[cfg_attr(feature = "bindings", derive(TS))]
14425pub struct Week {
14426    pub this: Box<Expression>,
14427    #[serde(default)]
14428    pub mode: Option<Box<Expression>>,
14429}
14430
14431/// XMLElement
14432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14433#[cfg_attr(feature = "bindings", derive(TS))]
14434pub struct XMLElement {
14435    pub this: Box<Expression>,
14436    #[serde(default)]
14437    pub expressions: Vec<Expression>,
14438    #[serde(default)]
14439    pub evalname: Option<Box<Expression>>,
14440}
14441
14442/// XMLGet
14443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14444#[cfg_attr(feature = "bindings", derive(TS))]
14445pub struct XMLGet {
14446    pub this: Box<Expression>,
14447    pub expression: Box<Expression>,
14448    #[serde(default)]
14449    pub instance: Option<Box<Expression>>,
14450}
14451
14452/// XMLTable
14453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14454#[cfg_attr(feature = "bindings", derive(TS))]
14455pub struct XMLTable {
14456    pub this: Box<Expression>,
14457    #[serde(default)]
14458    pub namespaces: Option<Box<Expression>>,
14459    #[serde(default)]
14460    pub passing: Option<Box<Expression>>,
14461    #[serde(default)]
14462    pub columns: Vec<Expression>,
14463    #[serde(default)]
14464    pub by_ref: Option<Box<Expression>>,
14465}
14466
14467/// XMLKeyValueOption
14468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14469#[cfg_attr(feature = "bindings", derive(TS))]
14470pub struct XMLKeyValueOption {
14471    pub this: Box<Expression>,
14472    #[serde(default)]
14473    pub expression: Option<Box<Expression>>,
14474}
14475
14476/// Zipf
14477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14478#[cfg_attr(feature = "bindings", derive(TS))]
14479pub struct Zipf {
14480    pub this: Box<Expression>,
14481    #[serde(default)]
14482    pub elementcount: Option<Box<Expression>>,
14483    #[serde(default)]
14484    pub gen: Option<Box<Expression>>,
14485}
14486
14487/// Merge
14488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14489#[cfg_attr(feature = "bindings", derive(TS))]
14490pub struct Merge {
14491    pub this: Box<Expression>,
14492    pub using: Box<Expression>,
14493    #[serde(default)]
14494    pub on: Option<Box<Expression>>,
14495    #[serde(default)]
14496    pub using_cond: Option<Box<Expression>>,
14497    #[serde(default)]
14498    pub whens: Option<Box<Expression>>,
14499    #[serde(default)]
14500    pub with_: Option<Box<Expression>>,
14501    #[serde(default)]
14502    pub returning: Option<Box<Expression>>,
14503}
14504
14505/// When
14506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14507#[cfg_attr(feature = "bindings", derive(TS))]
14508pub struct When {
14509    #[serde(default)]
14510    pub matched: Option<Box<Expression>>,
14511    #[serde(default)]
14512    pub source: Option<Box<Expression>>,
14513    #[serde(default)]
14514    pub condition: Option<Box<Expression>>,
14515    pub then: Box<Expression>,
14516}
14517
14518/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14520#[cfg_attr(feature = "bindings", derive(TS))]
14521pub struct Whens {
14522    #[serde(default)]
14523    pub expressions: Vec<Expression>,
14524}
14525
14526/// NextValueFor
14527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14528#[cfg_attr(feature = "bindings", derive(TS))]
14529pub struct NextValueFor {
14530    pub this: Box<Expression>,
14531    #[serde(default)]
14532    pub order: Option<Box<Expression>>,
14533}
14534
14535#[cfg(test)]
14536mod tests {
14537    use super::*;
14538
14539    #[test]
14540    #[cfg(feature = "bindings")]
14541    fn export_typescript_types() {
14542        // This test exports TypeScript types to the generated directory
14543        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14544        Expression::export_all(&ts_rs::Config::default())
14545            .expect("Failed to export Expression types");
14546    }
14547
14548    #[test]
14549    fn test_simple_select_builder() {
14550        let select = Select::new()
14551            .column(Expression::star())
14552            .from(Expression::Table(Box::new(TableRef::new("users"))));
14553
14554        assert_eq!(select.expressions.len(), 1);
14555        assert!(select.from.is_some());
14556    }
14557
14558    #[test]
14559    fn test_expression_alias() {
14560        let expr = Expression::column("id").alias("user_id");
14561
14562        match expr {
14563            Expression::Alias(a) => {
14564                assert_eq!(a.alias.name, "user_id");
14565            }
14566            _ => panic!("Expected Alias"),
14567        }
14568    }
14569
14570    #[test]
14571    fn test_literal_creation() {
14572        let num = Expression::number(42);
14573        let str = Expression::string("hello");
14574
14575        match num {
14576            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => { let Literal::Number(n) = lit.as_ref() else { unreachable!() }; assert_eq!(n, "42") },
14577            _ => panic!("Expected Number"),
14578        }
14579
14580        match str {
14581            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => { let Literal::String(s) = lit.as_ref() else { unreachable!() }; assert_eq!(s, "hello") },
14582            _ => panic!("Expected String"),
14583        }
14584    }
14585
14586    #[test]
14587    fn test_expression_sql() {
14588        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14589        assert_eq!(expr.sql(), "SELECT 1 + 2");
14590    }
14591
14592    #[test]
14593    fn test_expression_sql_for() {
14594        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14595        let sql = expr.sql_for(crate::DialectType::Generic);
14596        // Generic mode normalizes IF() to CASE WHEN
14597        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14598    }
14599}