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    CreateSynonym(Box<CreateSynonym>),
576    DropSequence(Box<DropSequence>),
577    AlterSequence(Box<AlterSequence>),
578    CreateTrigger(Box<CreateTrigger>),
579    DropTrigger(Box<DropTrigger>),
580    CreateType(Box<CreateType>),
581    DropType(Box<DropType>),
582    Describe(Box<Describe>),
583    Show(Box<Show>),
584
585    // Transaction and other commands
586    Command(Box<Command>),
587    Kill(Box<Kill>),
588    /// EXEC/EXECUTE statement (TSQL stored procedure call)
589    Execute(Box<ExecuteStatement>),
590
591    /// Snowflake CREATE TASK statement
592    CreateTask(Box<CreateTask>),
593
594    // Placeholder for unparsed/raw SQL
595    Raw(Raw),
596
597    // Paren for grouping
598    Paren(Box<Paren>),
599
600    // Expression with trailing comments (for round-trip preservation)
601    Annotated(Box<Annotated>),
602
603    // === BATCH GENERATED EXPRESSION TYPES ===
604    // Generated from Python sqlglot expressions.py
605    Refresh(Box<Refresh>),
606    LockingStatement(Box<LockingStatement>),
607    SequenceProperties(Box<SequenceProperties>),
608    TruncateTable(Box<TruncateTable>),
609    Clone(Box<Clone>),
610    Attach(Box<Attach>),
611    Detach(Box<Detach>),
612    Install(Box<Install>),
613    Summarize(Box<Summarize>),
614    Declare(Box<Declare>),
615    DeclareItem(Box<DeclareItem>),
616    Set(Box<Set>),
617    Heredoc(Box<Heredoc>),
618    SetItem(Box<SetItem>),
619    QueryBand(Box<QueryBand>),
620    UserDefinedFunction(Box<UserDefinedFunction>),
621    RecursiveWithSearch(Box<RecursiveWithSearch>),
622    ProjectionDef(Box<ProjectionDef>),
623    TableAlias(Box<TableAlias>),
624    ByteString(Box<ByteString>),
625    HexStringExpr(Box<HexStringExpr>),
626    UnicodeString(Box<UnicodeString>),
627    ColumnPosition(Box<ColumnPosition>),
628    ColumnDef(Box<ColumnDef>),
629    AlterColumn(Box<AlterColumn>),
630    AlterSortKey(Box<AlterSortKey>),
631    AlterSet(Box<AlterSet>),
632    RenameColumn(Box<RenameColumn>),
633    Comprehension(Box<Comprehension>),
634    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
635    MergeTreeTTL(Box<MergeTreeTTL>),
636    IndexConstraintOption(Box<IndexConstraintOption>),
637    ColumnConstraint(Box<ColumnConstraint>),
638    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
639    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
640    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
641    CheckColumnConstraint(Box<CheckColumnConstraint>),
642    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
643    CompressColumnConstraint(Box<CompressColumnConstraint>),
644    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
645    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
646    WithOperator(Box<WithOperator>),
647    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
648    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
649    CommentColumnConstraint(CommentColumnConstraint),
650    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
651    IndexColumnConstraint(Box<IndexColumnConstraint>),
652    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
653    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
654    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
655    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
656    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
657    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
658    InOutColumnConstraint(Box<InOutColumnConstraint>),
659    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
660    PathColumnConstraint(Box<PathColumnConstraint>),
661    Constraint(Box<Constraint>),
662    Export(Box<Export>),
663    Filter(Box<Filter>),
664    Changes(Box<Changes>),
665    CopyParameter(Box<CopyParameter>),
666    Credentials(Box<Credentials>),
667    Directory(Box<Directory>),
668    ForeignKey(Box<ForeignKey>),
669    ColumnPrefix(Box<ColumnPrefix>),
670    PrimaryKey(Box<PrimaryKey>),
671    IntoClause(Box<IntoClause>),
672    JoinHint(Box<JoinHint>),
673    Opclass(Box<Opclass>),
674    Index(Box<Index>),
675    IndexParameters(Box<IndexParameters>),
676    ConditionalInsert(Box<ConditionalInsert>),
677    MultitableInserts(Box<MultitableInserts>),
678    OnConflict(Box<OnConflict>),
679    OnCondition(Box<OnCondition>),
680    Returning(Box<Returning>),
681    Introducer(Box<Introducer>),
682    PartitionRange(Box<PartitionRange>),
683    Fetch(Box<Fetch>),
684    Group(Box<Group>),
685    Cube(Box<Cube>),
686    Rollup(Box<Rollup>),
687    GroupingSets(Box<GroupingSets>),
688    LimitOptions(Box<LimitOptions>),
689    Lateral(Box<Lateral>),
690    TableFromRows(Box<TableFromRows>),
691    RowsFrom(Box<RowsFrom>),
692    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
693    WithFill(Box<WithFill>),
694    Property(Box<Property>),
695    GrantPrivilege(Box<GrantPrivilege>),
696    GrantPrincipal(Box<GrantPrincipal>),
697    AllowedValuesProperty(Box<AllowedValuesProperty>),
698    AlgorithmProperty(Box<AlgorithmProperty>),
699    AutoIncrementProperty(Box<AutoIncrementProperty>),
700    AutoRefreshProperty(Box<AutoRefreshProperty>),
701    BackupProperty(Box<BackupProperty>),
702    BuildProperty(Box<BuildProperty>),
703    BlockCompressionProperty(Box<BlockCompressionProperty>),
704    CharacterSetProperty(Box<CharacterSetProperty>),
705    ChecksumProperty(Box<ChecksumProperty>),
706    CollateProperty(Box<CollateProperty>),
707    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
708    DataDeletionProperty(Box<DataDeletionProperty>),
709    DefinerProperty(Box<DefinerProperty>),
710    DistKeyProperty(Box<DistKeyProperty>),
711    DistributedByProperty(Box<DistributedByProperty>),
712    DistStyleProperty(Box<DistStyleProperty>),
713    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
714    EngineProperty(Box<EngineProperty>),
715    ToTableProperty(Box<ToTableProperty>),
716    ExecuteAsProperty(Box<ExecuteAsProperty>),
717    ExternalProperty(Box<ExternalProperty>),
718    FallbackProperty(Box<FallbackProperty>),
719    FileFormatProperty(Box<FileFormatProperty>),
720    CredentialsProperty(Box<CredentialsProperty>),
721    FreespaceProperty(Box<FreespaceProperty>),
722    InheritsProperty(Box<InheritsProperty>),
723    InputModelProperty(Box<InputModelProperty>),
724    OutputModelProperty(Box<OutputModelProperty>),
725    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
726    JournalProperty(Box<JournalProperty>),
727    LanguageProperty(Box<LanguageProperty>),
728    EnviromentProperty(Box<EnviromentProperty>),
729    ClusteredByProperty(Box<ClusteredByProperty>),
730    DictProperty(Box<DictProperty>),
731    DictRange(Box<DictRange>),
732    OnCluster(Box<OnCluster>),
733    LikeProperty(Box<LikeProperty>),
734    LocationProperty(Box<LocationProperty>),
735    LockProperty(Box<LockProperty>),
736    LockingProperty(Box<LockingProperty>),
737    LogProperty(Box<LogProperty>),
738    MaterializedProperty(Box<MaterializedProperty>),
739    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
740    OnProperty(Box<OnProperty>),
741    OnCommitProperty(Box<OnCommitProperty>),
742    PartitionedByProperty(Box<PartitionedByProperty>),
743    PartitionByProperty(Box<PartitionByProperty>),
744    PartitionedByBucket(Box<PartitionedByBucket>),
745    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
746    PartitionByTruncate(Box<PartitionByTruncate>),
747    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
748    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
749    PartitionByListProperty(Box<PartitionByListProperty>),
750    PartitionList(Box<PartitionList>),
751    Partition(Box<Partition>),
752    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
753    UniqueKeyProperty(Box<UniqueKeyProperty>),
754    RollupProperty(Box<RollupProperty>),
755    PartitionBoundSpec(Box<PartitionBoundSpec>),
756    PartitionedOfProperty(Box<PartitionedOfProperty>),
757    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
758    ReturnsProperty(Box<ReturnsProperty>),
759    RowFormatProperty(Box<RowFormatProperty>),
760    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
761    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
762    QueryTransform(Box<QueryTransform>),
763    SampleProperty(Box<SampleProperty>),
764    SecurityProperty(Box<SecurityProperty>),
765    SchemaCommentProperty(Box<SchemaCommentProperty>),
766    SemanticView(Box<SemanticView>),
767    SerdeProperties(Box<SerdeProperties>),
768    SetProperty(Box<SetProperty>),
769    SharingProperty(Box<SharingProperty>),
770    SetConfigProperty(Box<SetConfigProperty>),
771    SettingsProperty(Box<SettingsProperty>),
772    SortKeyProperty(Box<SortKeyProperty>),
773    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
774    SqlSecurityProperty(Box<SqlSecurityProperty>),
775    StabilityProperty(Box<StabilityProperty>),
776    StorageHandlerProperty(Box<StorageHandlerProperty>),
777    TemporaryProperty(Box<TemporaryProperty>),
778    Tags(Box<Tags>),
779    TransformModelProperty(Box<TransformModelProperty>),
780    TransientProperty(Box<TransientProperty>),
781    UsingTemplateProperty(Box<UsingTemplateProperty>),
782    ViewAttributeProperty(Box<ViewAttributeProperty>),
783    VolatileProperty(Box<VolatileProperty>),
784    WithDataProperty(Box<WithDataProperty>),
785    WithJournalTableProperty(Box<WithJournalTableProperty>),
786    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
787    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
788    WithProcedureOptions(Box<WithProcedureOptions>),
789    EncodeProperty(Box<EncodeProperty>),
790    IncludeProperty(Box<IncludeProperty>),
791    Properties(Box<Properties>),
792    OptionsProperty(Box<OptionsProperty>),
793    InputOutputFormat(Box<InputOutputFormat>),
794    Reference(Box<Reference>),
795    QueryOption(Box<QueryOption>),
796    WithTableHint(Box<WithTableHint>),
797    IndexTableHint(Box<IndexTableHint>),
798    HistoricalData(Box<HistoricalData>),
799    Get(Box<Get>),
800    SetOperation(Box<SetOperation>),
801    Var(Box<Var>),
802    Variadic(Box<Variadic>),
803    Version(Box<Version>),
804    Schema(Box<Schema>),
805    Lock(Box<Lock>),
806    TableSample(Box<TableSample>),
807    Tag(Box<Tag>),
808    UnpivotColumns(Box<UnpivotColumns>),
809    WindowSpec(Box<WindowSpec>),
810    SessionParameter(Box<SessionParameter>),
811    PseudoType(Box<PseudoType>),
812    ObjectIdentifier(Box<ObjectIdentifier>),
813    Transaction(Box<Transaction>),
814    Commit(Box<Commit>),
815    Rollback(Box<Rollback>),
816    AlterSession(Box<AlterSession>),
817    Analyze(Box<Analyze>),
818    AnalyzeStatistics(Box<AnalyzeStatistics>),
819    AnalyzeHistogram(Box<AnalyzeHistogram>),
820    AnalyzeSample(Box<AnalyzeSample>),
821    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
822    AnalyzeDelete(Box<AnalyzeDelete>),
823    AnalyzeWith(Box<AnalyzeWith>),
824    AnalyzeValidate(Box<AnalyzeValidate>),
825    AddPartition(Box<AddPartition>),
826    AttachOption(Box<AttachOption>),
827    DropPartition(Box<DropPartition>),
828    ReplacePartition(Box<ReplacePartition>),
829    DPipe(Box<DPipe>),
830    Operator(Box<Operator>),
831    PivotAny(Box<PivotAny>),
832    Aliases(Box<Aliases>),
833    AtIndex(Box<AtIndex>),
834    FromTimeZone(Box<FromTimeZone>),
835    FormatPhrase(Box<FormatPhrase>),
836    ForIn(Box<ForIn>),
837    TimeUnit(Box<TimeUnit>),
838    IntervalOp(Box<IntervalOp>),
839    IntervalSpan(Box<IntervalSpan>),
840    HavingMax(Box<HavingMax>),
841    CosineDistance(Box<CosineDistance>),
842    DotProduct(Box<DotProduct>),
843    EuclideanDistance(Box<EuclideanDistance>),
844    ManhattanDistance(Box<ManhattanDistance>),
845    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
846    Booland(Box<Booland>),
847    Boolor(Box<Boolor>),
848    ParameterizedAgg(Box<ParameterizedAgg>),
849    ArgMax(Box<ArgMax>),
850    ArgMin(Box<ArgMin>),
851    ApproxTopK(Box<ApproxTopK>),
852    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
853    ApproxTopKCombine(Box<ApproxTopKCombine>),
854    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
855    ApproxTopSum(Box<ApproxTopSum>),
856    ApproxQuantiles(Box<ApproxQuantiles>),
857    Minhash(Box<Minhash>),
858    FarmFingerprint(Box<FarmFingerprint>),
859    Float64(Box<Float64>),
860    Transform(Box<Transform>),
861    Translate(Box<Translate>),
862    Grouping(Box<Grouping>),
863    GroupingId(Box<GroupingId>),
864    Anonymous(Box<Anonymous>),
865    AnonymousAggFunc(Box<AnonymousAggFunc>),
866    CombinedAggFunc(Box<CombinedAggFunc>),
867    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
868    HashAgg(Box<HashAgg>),
869    Hll(Box<Hll>),
870    Apply(Box<Apply>),
871    ToBoolean(Box<ToBoolean>),
872    List(Box<List>),
873    ToMap(Box<ToMap>),
874    Pad(Box<Pad>),
875    ToChar(Box<ToChar>),
876    ToNumber(Box<ToNumber>),
877    ToDouble(Box<ToDouble>),
878    Int64(Box<UnaryFunc>),
879    StringFunc(Box<StringFunc>),
880    ToDecfloat(Box<ToDecfloat>),
881    TryToDecfloat(Box<TryToDecfloat>),
882    ToFile(Box<ToFile>),
883    Columns(Box<Columns>),
884    ConvertToCharset(Box<ConvertToCharset>),
885    ConvertTimezone(Box<ConvertTimezone>),
886    GenerateSeries(Box<GenerateSeries>),
887    AIAgg(Box<AIAgg>),
888    AIClassify(Box<AIClassify>),
889    ArrayAll(Box<ArrayAll>),
890    ArrayAny(Box<ArrayAny>),
891    ArrayConstructCompact(Box<ArrayConstructCompact>),
892    StPoint(Box<StPoint>),
893    StDistance(Box<StDistance>),
894    StringToArray(Box<StringToArray>),
895    ArraySum(Box<ArraySum>),
896    ObjectAgg(Box<ObjectAgg>),
897    CastToStrType(Box<CastToStrType>),
898    CheckJson(Box<CheckJson>),
899    CheckXml(Box<CheckXml>),
900    TranslateCharacters(Box<TranslateCharacters>),
901    CurrentSchemas(Box<CurrentSchemas>),
902    CurrentDatetime(Box<CurrentDatetime>),
903    Localtime(Box<Localtime>),
904    Localtimestamp(Box<Localtimestamp>),
905    Systimestamp(Box<Systimestamp>),
906    CurrentSchema(Box<CurrentSchema>),
907    CurrentUser(Box<CurrentUser>),
908    UtcTime(Box<UtcTime>),
909    UtcTimestamp(Box<UtcTimestamp>),
910    Timestamp(Box<TimestampFunc>),
911    DateBin(Box<DateBin>),
912    Datetime(Box<Datetime>),
913    DatetimeAdd(Box<DatetimeAdd>),
914    DatetimeSub(Box<DatetimeSub>),
915    DatetimeDiff(Box<DatetimeDiff>),
916    DatetimeTrunc(Box<DatetimeTrunc>),
917    Dayname(Box<Dayname>),
918    MakeInterval(Box<MakeInterval>),
919    PreviousDay(Box<PreviousDay>),
920    Elt(Box<Elt>),
921    TimestampAdd(Box<TimestampAdd>),
922    TimestampSub(Box<TimestampSub>),
923    TimestampDiff(Box<TimestampDiff>),
924    TimeSlice(Box<TimeSlice>),
925    TimeAdd(Box<TimeAdd>),
926    TimeSub(Box<TimeSub>),
927    TimeDiff(Box<TimeDiff>),
928    TimeTrunc(Box<TimeTrunc>),
929    DateFromParts(Box<DateFromParts>),
930    TimeFromParts(Box<TimeFromParts>),
931    DecodeCase(Box<DecodeCase>),
932    Decrypt(Box<Decrypt>),
933    DecryptRaw(Box<DecryptRaw>),
934    Encode(Box<Encode>),
935    Encrypt(Box<Encrypt>),
936    EncryptRaw(Box<EncryptRaw>),
937    EqualNull(Box<EqualNull>),
938    ToBinary(Box<ToBinary>),
939    Base64DecodeBinary(Box<Base64DecodeBinary>),
940    Base64DecodeString(Box<Base64DecodeString>),
941    Base64Encode(Box<Base64Encode>),
942    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
943    TryBase64DecodeString(Box<TryBase64DecodeString>),
944    GapFill(Box<GapFill>),
945    GenerateDateArray(Box<GenerateDateArray>),
946    GenerateTimestampArray(Box<GenerateTimestampArray>),
947    GetExtract(Box<GetExtract>),
948    Getbit(Box<Getbit>),
949    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
950    HexEncode(Box<HexEncode>),
951    Compress(Box<Compress>),
952    DecompressBinary(Box<DecompressBinary>),
953    DecompressString(Box<DecompressString>),
954    Xor(Box<Xor>),
955    Nullif(Box<Nullif>),
956    JSON(Box<JSON>),
957    JSONPath(Box<JSONPath>),
958    JSONPathFilter(Box<JSONPathFilter>),
959    JSONPathKey(Box<JSONPathKey>),
960    JSONPathRecursive(Box<JSONPathRecursive>),
961    JSONPathScript(Box<JSONPathScript>),
962    JSONPathSlice(Box<JSONPathSlice>),
963    JSONPathSelector(Box<JSONPathSelector>),
964    JSONPathSubscript(Box<JSONPathSubscript>),
965    JSONPathUnion(Box<JSONPathUnion>),
966    Format(Box<Format>),
967    JSONKeys(Box<JSONKeys>),
968    JSONKeyValue(Box<JSONKeyValue>),
969    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
970    JSONObject(Box<JSONObject>),
971    JSONObjectAgg(Box<JSONObjectAgg>),
972    JSONBObjectAgg(Box<JSONBObjectAgg>),
973    JSONArray(Box<JSONArray>),
974    JSONArrayAgg(Box<JSONArrayAgg>),
975    JSONExists(Box<JSONExists>),
976    JSONColumnDef(Box<JSONColumnDef>),
977    JSONSchema(Box<JSONSchema>),
978    JSONSet(Box<JSONSet>),
979    JSONStripNulls(Box<JSONStripNulls>),
980    JSONValue(Box<JSONValue>),
981    JSONValueArray(Box<JSONValueArray>),
982    JSONRemove(Box<JSONRemove>),
983    JSONTable(Box<JSONTable>),
984    JSONType(Box<JSONType>),
985    ObjectInsert(Box<ObjectInsert>),
986    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
987    OpenJSON(Box<OpenJSON>),
988    JSONBExists(Box<JSONBExists>),
989    JSONBContains(Box<BinaryFunc>),
990    JSONBExtract(Box<BinaryFunc>),
991    JSONCast(Box<JSONCast>),
992    JSONExtract(Box<JSONExtract>),
993    JSONExtractQuote(Box<JSONExtractQuote>),
994    JSONExtractArray(Box<JSONExtractArray>),
995    JSONExtractScalar(Box<JSONExtractScalar>),
996    JSONBExtractScalar(Box<JSONBExtractScalar>),
997    JSONFormat(Box<JSONFormat>),
998    JSONBool(Box<UnaryFunc>),
999    JSONPathRoot(JSONPathRoot),
1000    JSONArrayAppend(Box<JSONArrayAppend>),
1001    JSONArrayContains(Box<JSONArrayContains>),
1002    JSONArrayInsert(Box<JSONArrayInsert>),
1003    ParseJSON(Box<ParseJSON>),
1004    ParseUrl(Box<ParseUrl>),
1005    ParseIp(Box<ParseIp>),
1006    ParseTime(Box<ParseTime>),
1007    ParseDatetime(Box<ParseDatetime>),
1008    Map(Box<Map>),
1009    MapCat(Box<MapCat>),
1010    MapDelete(Box<MapDelete>),
1011    MapInsert(Box<MapInsert>),
1012    MapPick(Box<MapPick>),
1013    ScopeResolution(Box<ScopeResolution>),
1014    Slice(Box<Slice>),
1015    VarMap(Box<VarMap>),
1016    MatchAgainst(Box<MatchAgainst>),
1017    MD5Digest(Box<MD5Digest>),
1018    MD5NumberLower64(Box<UnaryFunc>),
1019    MD5NumberUpper64(Box<UnaryFunc>),
1020    Monthname(Box<Monthname>),
1021    Ntile(Box<Ntile>),
1022    Normalize(Box<Normalize>),
1023    Normal(Box<Normal>),
1024    Predict(Box<Predict>),
1025    MLTranslate(Box<MLTranslate>),
1026    FeaturesAtTime(Box<FeaturesAtTime>),
1027    GenerateEmbedding(Box<GenerateEmbedding>),
1028    MLForecast(Box<MLForecast>),
1029    ModelAttribute(Box<ModelAttribute>),
1030    VectorSearch(Box<VectorSearch>),
1031    Quantile(Box<Quantile>),
1032    ApproxQuantile(Box<ApproxQuantile>),
1033    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1034    Randn(Box<Randn>),
1035    Randstr(Box<Randstr>),
1036    RangeN(Box<RangeN>),
1037    RangeBucket(Box<RangeBucket>),
1038    ReadCSV(Box<ReadCSV>),
1039    ReadParquet(Box<ReadParquet>),
1040    Reduce(Box<Reduce>),
1041    RegexpExtractAll(Box<RegexpExtractAll>),
1042    RegexpILike(Box<RegexpILike>),
1043    RegexpFullMatch(Box<RegexpFullMatch>),
1044    RegexpInstr(Box<RegexpInstr>),
1045    RegexpSplit(Box<RegexpSplit>),
1046    RegexpCount(Box<RegexpCount>),
1047    RegrValx(Box<RegrValx>),
1048    RegrValy(Box<RegrValy>),
1049    RegrAvgy(Box<RegrAvgy>),
1050    RegrAvgx(Box<RegrAvgx>),
1051    RegrCount(Box<RegrCount>),
1052    RegrIntercept(Box<RegrIntercept>),
1053    RegrR2(Box<RegrR2>),
1054    RegrSxx(Box<RegrSxx>),
1055    RegrSxy(Box<RegrSxy>),
1056    RegrSyy(Box<RegrSyy>),
1057    RegrSlope(Box<RegrSlope>),
1058    SafeAdd(Box<SafeAdd>),
1059    SafeDivide(Box<SafeDivide>),
1060    SafeMultiply(Box<SafeMultiply>),
1061    SafeSubtract(Box<SafeSubtract>),
1062    SHA2(Box<SHA2>),
1063    SHA2Digest(Box<SHA2Digest>),
1064    SortArray(Box<SortArray>),
1065    SplitPart(Box<SplitPart>),
1066    SubstringIndex(Box<SubstringIndex>),
1067    StandardHash(Box<StandardHash>),
1068    StrPosition(Box<StrPosition>),
1069    Search(Box<Search>),
1070    SearchIp(Box<SearchIp>),
1071    StrToDate(Box<StrToDate>),
1072    DateStrToDate(Box<UnaryFunc>),
1073    DateToDateStr(Box<UnaryFunc>),
1074    StrToTime(Box<StrToTime>),
1075    StrToUnix(Box<StrToUnix>),
1076    StrToMap(Box<StrToMap>),
1077    NumberToStr(Box<NumberToStr>),
1078    FromBase(Box<FromBase>),
1079    Stuff(Box<Stuff>),
1080    TimeToStr(Box<TimeToStr>),
1081    TimeStrToTime(Box<TimeStrToTime>),
1082    TsOrDsAdd(Box<TsOrDsAdd>),
1083    TsOrDsDiff(Box<TsOrDsDiff>),
1084    TsOrDsToDate(Box<TsOrDsToDate>),
1085    TsOrDsToTime(Box<TsOrDsToTime>),
1086    Unhex(Box<Unhex>),
1087    Uniform(Box<Uniform>),
1088    UnixToStr(Box<UnixToStr>),
1089    UnixToTime(Box<UnixToTime>),
1090    Uuid(Box<Uuid>),
1091    TimestampFromParts(Box<TimestampFromParts>),
1092    TimestampTzFromParts(Box<TimestampTzFromParts>),
1093    Corr(Box<Corr>),
1094    WidthBucket(Box<WidthBucket>),
1095    CovarSamp(Box<CovarSamp>),
1096    CovarPop(Box<CovarPop>),
1097    Week(Box<Week>),
1098    XMLElement(Box<XMLElement>),
1099    XMLGet(Box<XMLGet>),
1100    XMLTable(Box<XMLTable>),
1101    XMLKeyValueOption(Box<XMLKeyValueOption>),
1102    Zipf(Box<Zipf>),
1103    Merge(Box<Merge>),
1104    When(Box<When>),
1105    Whens(Box<Whens>),
1106    NextValueFor(Box<NextValueFor>),
1107    /// RETURN statement (DuckDB stored procedures)
1108    ReturnStmt(Box<Expression>),
1109}
1110
1111impl Expression {
1112    /// Create a `Column` variant, boxing the value automatically.
1113    #[inline]
1114    pub fn boxed_column(col: Column) -> Self {
1115        Expression::Column(Box::new(col))
1116    }
1117
1118    /// Create a `Table` variant, boxing the value automatically.
1119    #[inline]
1120    pub fn boxed_table(t: TableRef) -> Self {
1121        Expression::Table(Box::new(t))
1122    }
1123
1124    /// Returns `true` if this expression is a valid top-level SQL statement.
1125    ///
1126    /// Bare expressions like identifiers, literals, and function calls are not
1127    /// valid statements. This is used by `validate()` to reject inputs like
1128    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1129    /// plus the bare identifier `doo`.
1130    pub fn is_statement(&self) -> bool {
1131        match self {
1132            // Queries
1133            Expression::Select(_)
1134            | Expression::Union(_)
1135            | Expression::Intersect(_)
1136            | Expression::Except(_)
1137            | Expression::Subquery(_)
1138            | Expression::Values(_)
1139            | Expression::PipeOperator(_)
1140
1141            // DML
1142            | Expression::Insert(_)
1143            | Expression::Update(_)
1144            | Expression::Delete(_)
1145            | Expression::Copy(_)
1146            | Expression::Put(_)
1147            | Expression::Merge(_)
1148
1149            // DDL
1150            | Expression::CreateTable(_)
1151            | Expression::DropTable(_)
1152            | Expression::AlterTable(_)
1153            | Expression::CreateIndex(_)
1154            | Expression::DropIndex(_)
1155            | Expression::CreateView(_)
1156            | Expression::DropView(_)
1157            | Expression::AlterView(_)
1158            | Expression::AlterIndex(_)
1159            | Expression::Truncate(_)
1160            | Expression::TruncateTable(_)
1161            | Expression::CreateSchema(_)
1162            | Expression::DropSchema(_)
1163            | Expression::DropNamespace(_)
1164            | Expression::CreateDatabase(_)
1165            | Expression::DropDatabase(_)
1166            | Expression::CreateFunction(_)
1167            | Expression::DropFunction(_)
1168            | Expression::CreateProcedure(_)
1169            | Expression::DropProcedure(_)
1170            | Expression::CreateSequence(_)
1171            | Expression::DropSequence(_)
1172            | Expression::AlterSequence(_)
1173            | Expression::CreateTrigger(_)
1174            | Expression::DropTrigger(_)
1175            | Expression::CreateType(_)
1176            | Expression::DropType(_)
1177            | Expression::Comment(_)
1178
1179            // Session/Transaction/Control
1180            | Expression::Use(_)
1181            | Expression::Set(_)
1182            | Expression::SetStatement(_)
1183            | Expression::Transaction(_)
1184            | Expression::Commit(_)
1185            | Expression::Rollback(_)
1186            | Expression::Grant(_)
1187            | Expression::Revoke(_)
1188            | Expression::Cache(_)
1189            | Expression::Uncache(_)
1190            | Expression::LoadData(_)
1191            | Expression::Pragma(_)
1192            | Expression::Describe(_)
1193            | Expression::Show(_)
1194            | Expression::Kill(_)
1195            | Expression::Execute(_)
1196            | Expression::Declare(_)
1197            | Expression::Refresh(_)
1198            | Expression::AlterSession(_)
1199            | Expression::LockingStatement(_)
1200
1201            // Analyze
1202            | Expression::Analyze(_)
1203            | Expression::AnalyzeStatistics(_)
1204            | Expression::AnalyzeHistogram(_)
1205            | Expression::AnalyzeSample(_)
1206            | Expression::AnalyzeListChainedRows(_)
1207            | Expression::AnalyzeDelete(_)
1208
1209            // Attach/Detach/Install/Summarize
1210            | Expression::Attach(_)
1211            | Expression::Detach(_)
1212            | Expression::Install(_)
1213            | Expression::Summarize(_)
1214
1215            // Pivot at statement level
1216            | Expression::Pivot(_)
1217            | Expression::Unpivot(_)
1218
1219            // Command (raw/unparsed statements)
1220            | Expression::Command(_)
1221            | Expression::Raw(_)
1222            | Expression::CreateTask(_)
1223
1224            // Return statement
1225            | Expression::ReturnStmt(_) => true,
1226
1227            // Annotated wraps another expression with comments — check inner
1228            Expression::Annotated(a) => a.this.is_statement(),
1229
1230            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1231            Expression::Alias(a) => a.this.is_statement(),
1232
1233            // Everything else (identifiers, literals, operators, functions, etc.)
1234            _ => false,
1235        }
1236    }
1237
1238    /// Create a literal number expression from an integer.
1239    pub fn number(n: i64) -> Self {
1240        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1241    }
1242
1243    /// Create a single-quoted literal string expression.
1244    pub fn string(s: impl Into<String>) -> Self {
1245        Expression::Literal(Box::new(Literal::String(s.into())))
1246    }
1247
1248    /// Create a literal number expression from a float.
1249    pub fn float(f: f64) -> Self {
1250        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1251    }
1252
1253    /// Get the inferred type annotation, if present.
1254    ///
1255    /// For value-producing expressions with an `inferred_type` field, returns
1256    /// the stored type. For literals and boolean constants, computes the type
1257    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1258    pub fn inferred_type(&self) -> Option<&DataType> {
1259        match self {
1260            // Structs with inferred_type field
1261            Expression::And(op)
1262            | Expression::Or(op)
1263            | Expression::Add(op)
1264            | Expression::Sub(op)
1265            | Expression::Mul(op)
1266            | Expression::Div(op)
1267            | Expression::Mod(op)
1268            | Expression::Eq(op)
1269            | Expression::Neq(op)
1270            | Expression::Lt(op)
1271            | Expression::Lte(op)
1272            | Expression::Gt(op)
1273            | Expression::Gte(op)
1274            | Expression::Concat(op)
1275            | Expression::BitwiseAnd(op)
1276            | Expression::BitwiseOr(op)
1277            | Expression::BitwiseXor(op)
1278            | Expression::Adjacent(op)
1279            | Expression::TsMatch(op)
1280            | Expression::PropertyEQ(op)
1281            | Expression::ArrayContainsAll(op)
1282            | Expression::ArrayContainedBy(op)
1283            | Expression::ArrayOverlaps(op)
1284            | Expression::JSONBContainsAllTopKeys(op)
1285            | Expression::JSONBContainsAnyTopKeys(op)
1286            | Expression::JSONBDeleteAtPath(op)
1287            | Expression::ExtendsLeft(op)
1288            | Expression::ExtendsRight(op)
1289            | Expression::Is(op)
1290            | Expression::MemberOf(op)
1291            | Expression::Match(op)
1292            | Expression::NullSafeEq(op)
1293            | Expression::NullSafeNeq(op)
1294            | Expression::Glob(op)
1295            | Expression::BitwiseLeftShift(op)
1296            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1297
1298            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1299                op.inferred_type.as_ref()
1300            }
1301
1302            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1303
1304            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1305                c.inferred_type.as_ref()
1306            }
1307
1308            Expression::Column(c) => c.inferred_type.as_ref(),
1309            Expression::Function(f) => f.inferred_type.as_ref(),
1310            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1311            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1312            Expression::Case(c) => c.inferred_type.as_ref(),
1313            Expression::Subquery(s) => s.inferred_type.as_ref(),
1314            Expression::Alias(a) => a.inferred_type.as_ref(),
1315            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1316            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1317            Expression::Count(f) => f.inferred_type.as_ref(),
1318            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1319            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1320            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1321            Expression::SumIf(f) => f.inferred_type.as_ref(),
1322
1323            // UnaryFunc variants
1324            Expression::Upper(f)
1325            | Expression::Lower(f)
1326            | Expression::Length(f)
1327            | Expression::LTrim(f)
1328            | Expression::RTrim(f)
1329            | Expression::Reverse(f)
1330            | Expression::Abs(f)
1331            | Expression::Sqrt(f)
1332            | Expression::Cbrt(f)
1333            | Expression::Ln(f)
1334            | Expression::Exp(f)
1335            | Expression::Sign(f)
1336            | Expression::Date(f)
1337            | Expression::Time(f)
1338            | Expression::Initcap(f)
1339            | Expression::Ascii(f)
1340            | Expression::Chr(f)
1341            | Expression::Soundex(f)
1342            | Expression::ByteLength(f)
1343            | Expression::Hex(f)
1344            | Expression::LowerHex(f)
1345            | Expression::Unicode(f)
1346            | Expression::Typeof(f)
1347            | Expression::Explode(f)
1348            | Expression::ExplodeOuter(f)
1349            | Expression::MapFromEntries(f)
1350            | Expression::MapKeys(f)
1351            | Expression::MapValues(f)
1352            | Expression::ArrayLength(f)
1353            | Expression::ArraySize(f)
1354            | Expression::Cardinality(f)
1355            | Expression::ArrayReverse(f)
1356            | Expression::ArrayDistinct(f)
1357            | Expression::ArrayFlatten(f)
1358            | Expression::ArrayCompact(f)
1359            | Expression::ToArray(f)
1360            | Expression::JsonArrayLength(f)
1361            | Expression::JsonKeys(f)
1362            | Expression::JsonType(f)
1363            | Expression::ParseJson(f)
1364            | Expression::ToJson(f)
1365            | Expression::Radians(f)
1366            | Expression::Degrees(f)
1367            | Expression::Sin(f)
1368            | Expression::Cos(f)
1369            | Expression::Tan(f)
1370            | Expression::Asin(f)
1371            | Expression::Acos(f)
1372            | Expression::Atan(f)
1373            | Expression::IsNan(f)
1374            | Expression::IsInf(f)
1375            | Expression::Year(f)
1376            | Expression::Month(f)
1377            | Expression::Day(f)
1378            | Expression::Hour(f)
1379            | Expression::Minute(f)
1380            | Expression::Second(f)
1381            | Expression::DayOfWeek(f)
1382            | Expression::DayOfWeekIso(f)
1383            | Expression::DayOfMonth(f)
1384            | Expression::DayOfYear(f)
1385            | Expression::WeekOfYear(f)
1386            | Expression::Quarter(f)
1387            | Expression::Epoch(f)
1388            | Expression::EpochMs(f)
1389            | Expression::BitwiseCount(f)
1390            | Expression::DateFromUnixDate(f)
1391            | Expression::UnixDate(f)
1392            | Expression::UnixSeconds(f)
1393            | Expression::UnixMillis(f)
1394            | Expression::UnixMicros(f)
1395            | Expression::TimeStrToDate(f)
1396            | Expression::DateToDi(f)
1397            | Expression::DiToDate(f)
1398            | Expression::TsOrDiToDi(f)
1399            | Expression::TsOrDsToDatetime(f)
1400            | Expression::TsOrDsToTimestamp(f)
1401            | Expression::YearOfWeek(f)
1402            | Expression::YearOfWeekIso(f)
1403            | Expression::SHA(f)
1404            | Expression::SHA1Digest(f)
1405            | Expression::TimeToUnix(f)
1406            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1407
1408            // BinaryFunc variants
1409            Expression::Power(f)
1410            | Expression::NullIf(f)
1411            | Expression::IfNull(f)
1412            | Expression::Nvl(f)
1413            | Expression::Contains(f)
1414            | Expression::StartsWith(f)
1415            | Expression::EndsWith(f)
1416            | Expression::Levenshtein(f)
1417            | Expression::ModFunc(f)
1418            | Expression::IntDiv(f)
1419            | Expression::Atan2(f)
1420            | Expression::AddMonths(f)
1421            | Expression::MonthsBetween(f)
1422            | Expression::NextDay(f)
1423            | Expression::UnixToTimeStr(f)
1424            | Expression::ArrayContains(f)
1425            | Expression::ArrayPosition(f)
1426            | Expression::ArrayAppend(f)
1427            | Expression::ArrayPrepend(f)
1428            | Expression::ArrayUnion(f)
1429            | Expression::ArrayExcept(f)
1430            | Expression::ArrayRemove(f)
1431            | Expression::StarMap(f)
1432            | Expression::MapFromArrays(f)
1433            | Expression::MapContainsKey(f)
1434            | Expression::ElementAt(f)
1435            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1436
1437            // VarArgFunc variants
1438            Expression::Coalesce(f)
1439            | Expression::Greatest(f)
1440            | Expression::Least(f)
1441            | Expression::ArrayConcat(f)
1442            | Expression::ArrayIntersect(f)
1443            | Expression::ArrayZip(f)
1444            | Expression::MapConcat(f)
1445            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1446
1447            // AggFunc variants
1448            Expression::Sum(f)
1449            | Expression::Avg(f)
1450            | Expression::Min(f)
1451            | Expression::Max(f)
1452            | Expression::ArrayAgg(f)
1453            | Expression::CountIf(f)
1454            | Expression::Stddev(f)
1455            | Expression::StddevPop(f)
1456            | Expression::StddevSamp(f)
1457            | Expression::Variance(f)
1458            | Expression::VarPop(f)
1459            | Expression::VarSamp(f)
1460            | Expression::Median(f)
1461            | Expression::Mode(f)
1462            | Expression::First(f)
1463            | Expression::Last(f)
1464            | Expression::AnyValue(f)
1465            | Expression::ApproxDistinct(f)
1466            | Expression::ApproxCountDistinct(f)
1467            | Expression::LogicalAnd(f)
1468            | Expression::LogicalOr(f)
1469            | Expression::Skewness(f)
1470            | Expression::ArrayConcatAgg(f)
1471            | Expression::ArrayUniqueAgg(f)
1472            | Expression::BoolXorAgg(f)
1473            | Expression::BitwiseAndAgg(f)
1474            | Expression::BitwiseOrAgg(f)
1475            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1476
1477            // Everything else: no inferred_type field
1478            _ => None,
1479        }
1480    }
1481
1482    /// Set the inferred type annotation on this expression.
1483    ///
1484    /// Only has an effect on value-producing expressions with an `inferred_type`
1485    /// field. For other expression types, this is a no-op.
1486    pub fn set_inferred_type(&mut self, dt: DataType) {
1487        match self {
1488            Expression::And(op)
1489            | Expression::Or(op)
1490            | Expression::Add(op)
1491            | Expression::Sub(op)
1492            | Expression::Mul(op)
1493            | Expression::Div(op)
1494            | Expression::Mod(op)
1495            | Expression::Eq(op)
1496            | Expression::Neq(op)
1497            | Expression::Lt(op)
1498            | Expression::Lte(op)
1499            | Expression::Gt(op)
1500            | Expression::Gte(op)
1501            | Expression::Concat(op)
1502            | Expression::BitwiseAnd(op)
1503            | Expression::BitwiseOr(op)
1504            | Expression::BitwiseXor(op)
1505            | Expression::Adjacent(op)
1506            | Expression::TsMatch(op)
1507            | Expression::PropertyEQ(op)
1508            | Expression::ArrayContainsAll(op)
1509            | Expression::ArrayContainedBy(op)
1510            | Expression::ArrayOverlaps(op)
1511            | Expression::JSONBContainsAllTopKeys(op)
1512            | Expression::JSONBContainsAnyTopKeys(op)
1513            | Expression::JSONBDeleteAtPath(op)
1514            | Expression::ExtendsLeft(op)
1515            | Expression::ExtendsRight(op)
1516            | Expression::Is(op)
1517            | Expression::MemberOf(op)
1518            | Expression::Match(op)
1519            | Expression::NullSafeEq(op)
1520            | Expression::NullSafeNeq(op)
1521            | Expression::Glob(op)
1522            | Expression::BitwiseLeftShift(op)
1523            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1524
1525            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1526                op.inferred_type = Some(dt)
1527            }
1528
1529            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1530
1531            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1532                c.inferred_type = Some(dt)
1533            }
1534
1535            Expression::Column(c) => c.inferred_type = Some(dt),
1536            Expression::Function(f) => f.inferred_type = Some(dt),
1537            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1538            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1539            Expression::Case(c) => c.inferred_type = Some(dt),
1540            Expression::Subquery(s) => s.inferred_type = Some(dt),
1541            Expression::Alias(a) => a.inferred_type = Some(dt),
1542            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1543            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1544            Expression::Count(f) => f.inferred_type = Some(dt),
1545            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1546            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1547            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1548            Expression::SumIf(f) => f.inferred_type = Some(dt),
1549
1550            // UnaryFunc variants
1551            Expression::Upper(f)
1552            | Expression::Lower(f)
1553            | Expression::Length(f)
1554            | Expression::LTrim(f)
1555            | Expression::RTrim(f)
1556            | Expression::Reverse(f)
1557            | Expression::Abs(f)
1558            | Expression::Sqrt(f)
1559            | Expression::Cbrt(f)
1560            | Expression::Ln(f)
1561            | Expression::Exp(f)
1562            | Expression::Sign(f)
1563            | Expression::Date(f)
1564            | Expression::Time(f)
1565            | Expression::Initcap(f)
1566            | Expression::Ascii(f)
1567            | Expression::Chr(f)
1568            | Expression::Soundex(f)
1569            | Expression::ByteLength(f)
1570            | Expression::Hex(f)
1571            | Expression::LowerHex(f)
1572            | Expression::Unicode(f)
1573            | Expression::Typeof(f)
1574            | Expression::Explode(f)
1575            | Expression::ExplodeOuter(f)
1576            | Expression::MapFromEntries(f)
1577            | Expression::MapKeys(f)
1578            | Expression::MapValues(f)
1579            | Expression::ArrayLength(f)
1580            | Expression::ArraySize(f)
1581            | Expression::Cardinality(f)
1582            | Expression::ArrayReverse(f)
1583            | Expression::ArrayDistinct(f)
1584            | Expression::ArrayFlatten(f)
1585            | Expression::ArrayCompact(f)
1586            | Expression::ToArray(f)
1587            | Expression::JsonArrayLength(f)
1588            | Expression::JsonKeys(f)
1589            | Expression::JsonType(f)
1590            | Expression::ParseJson(f)
1591            | Expression::ToJson(f)
1592            | Expression::Radians(f)
1593            | Expression::Degrees(f)
1594            | Expression::Sin(f)
1595            | Expression::Cos(f)
1596            | Expression::Tan(f)
1597            | Expression::Asin(f)
1598            | Expression::Acos(f)
1599            | Expression::Atan(f)
1600            | Expression::IsNan(f)
1601            | Expression::IsInf(f)
1602            | Expression::Year(f)
1603            | Expression::Month(f)
1604            | Expression::Day(f)
1605            | Expression::Hour(f)
1606            | Expression::Minute(f)
1607            | Expression::Second(f)
1608            | Expression::DayOfWeek(f)
1609            | Expression::DayOfWeekIso(f)
1610            | Expression::DayOfMonth(f)
1611            | Expression::DayOfYear(f)
1612            | Expression::WeekOfYear(f)
1613            | Expression::Quarter(f)
1614            | Expression::Epoch(f)
1615            | Expression::EpochMs(f)
1616            | Expression::BitwiseCount(f)
1617            | Expression::DateFromUnixDate(f)
1618            | Expression::UnixDate(f)
1619            | Expression::UnixSeconds(f)
1620            | Expression::UnixMillis(f)
1621            | Expression::UnixMicros(f)
1622            | Expression::TimeStrToDate(f)
1623            | Expression::DateToDi(f)
1624            | Expression::DiToDate(f)
1625            | Expression::TsOrDiToDi(f)
1626            | Expression::TsOrDsToDatetime(f)
1627            | Expression::TsOrDsToTimestamp(f)
1628            | Expression::YearOfWeek(f)
1629            | Expression::YearOfWeekIso(f)
1630            | Expression::SHA(f)
1631            | Expression::SHA1Digest(f)
1632            | Expression::TimeToUnix(f)
1633            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1634
1635            // BinaryFunc variants
1636            Expression::Power(f)
1637            | Expression::NullIf(f)
1638            | Expression::IfNull(f)
1639            | Expression::Nvl(f)
1640            | Expression::Contains(f)
1641            | Expression::StartsWith(f)
1642            | Expression::EndsWith(f)
1643            | Expression::Levenshtein(f)
1644            | Expression::ModFunc(f)
1645            | Expression::IntDiv(f)
1646            | Expression::Atan2(f)
1647            | Expression::AddMonths(f)
1648            | Expression::MonthsBetween(f)
1649            | Expression::NextDay(f)
1650            | Expression::UnixToTimeStr(f)
1651            | Expression::ArrayContains(f)
1652            | Expression::ArrayPosition(f)
1653            | Expression::ArrayAppend(f)
1654            | Expression::ArrayPrepend(f)
1655            | Expression::ArrayUnion(f)
1656            | Expression::ArrayExcept(f)
1657            | Expression::ArrayRemove(f)
1658            | Expression::StarMap(f)
1659            | Expression::MapFromArrays(f)
1660            | Expression::MapContainsKey(f)
1661            | Expression::ElementAt(f)
1662            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1663
1664            // VarArgFunc variants
1665            Expression::Coalesce(f)
1666            | Expression::Greatest(f)
1667            | Expression::Least(f)
1668            | Expression::ArrayConcat(f)
1669            | Expression::ArrayIntersect(f)
1670            | Expression::ArrayZip(f)
1671            | Expression::MapConcat(f)
1672            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1673
1674            // AggFunc variants
1675            Expression::Sum(f)
1676            | Expression::Avg(f)
1677            | Expression::Min(f)
1678            | Expression::Max(f)
1679            | Expression::ArrayAgg(f)
1680            | Expression::CountIf(f)
1681            | Expression::Stddev(f)
1682            | Expression::StddevPop(f)
1683            | Expression::StddevSamp(f)
1684            | Expression::Variance(f)
1685            | Expression::VarPop(f)
1686            | Expression::VarSamp(f)
1687            | Expression::Median(f)
1688            | Expression::Mode(f)
1689            | Expression::First(f)
1690            | Expression::Last(f)
1691            | Expression::AnyValue(f)
1692            | Expression::ApproxDistinct(f)
1693            | Expression::ApproxCountDistinct(f)
1694            | Expression::LogicalAnd(f)
1695            | Expression::LogicalOr(f)
1696            | Expression::Skewness(f)
1697            | Expression::ArrayConcatAgg(f)
1698            | Expression::ArrayUniqueAgg(f)
1699            | Expression::BoolXorAgg(f)
1700            | Expression::BitwiseAndAgg(f)
1701            | Expression::BitwiseOrAgg(f)
1702            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1703
1704            // Expressions without inferred_type field - no-op
1705            _ => {}
1706        }
1707    }
1708
1709    /// Create an unqualified column reference (e.g. `name`).
1710    pub fn column(name: impl Into<String>) -> Self {
1711        Expression::Column(Box::new(Column {
1712            name: Identifier::new(name),
1713            table: None,
1714            join_mark: false,
1715            trailing_comments: Vec::new(),
1716            span: None,
1717            inferred_type: None,
1718        }))
1719    }
1720
1721    /// Create a qualified column reference (`table.column`).
1722    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1723        Expression::Column(Box::new(Column {
1724            name: Identifier::new(column),
1725            table: Some(Identifier::new(table)),
1726            join_mark: false,
1727            trailing_comments: Vec::new(),
1728            span: None,
1729            inferred_type: None,
1730        }))
1731    }
1732
1733    /// Create a bare identifier expression (not a column reference).
1734    pub fn identifier(name: impl Into<String>) -> Self {
1735        Expression::Identifier(Identifier::new(name))
1736    }
1737
1738    /// Create a NULL expression
1739    pub fn null() -> Self {
1740        Expression::Null(Null)
1741    }
1742
1743    /// Create a TRUE expression
1744    pub fn true_() -> Self {
1745        Expression::Boolean(BooleanLiteral { value: true })
1746    }
1747
1748    /// Create a FALSE expression
1749    pub fn false_() -> Self {
1750        Expression::Boolean(BooleanLiteral { value: false })
1751    }
1752
1753    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1754    pub fn star() -> Self {
1755        Expression::Star(Star {
1756            table: None,
1757            except: None,
1758            replace: None,
1759            rename: None,
1760            trailing_comments: Vec::new(),
1761            span: None,
1762        })
1763    }
1764
1765    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1766    pub fn alias(self, name: impl Into<String>) -> Self {
1767        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1768    }
1769
1770    /// Check if this is a SELECT expression
1771    pub fn is_select(&self) -> bool {
1772        matches!(self, Expression::Select(_))
1773    }
1774
1775    /// Try to get as a Select
1776    pub fn as_select(&self) -> Option<&Select> {
1777        match self {
1778            Expression::Select(s) => Some(s),
1779            _ => None,
1780        }
1781    }
1782
1783    /// Try to get as a mutable Select
1784    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1785        match self {
1786            Expression::Select(s) => Some(s),
1787            _ => None,
1788        }
1789    }
1790
1791    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1792    ///
1793    /// Returns an empty string if generation fails. For dialect-specific output,
1794    /// use [`sql_for()`](Self::sql_for) instead.
1795    pub fn sql(&self) -> String {
1796        crate::generator::Generator::sql(self).unwrap_or_default()
1797    }
1798
1799    /// Generate a SQL string for this expression targeting a specific dialect.
1800    ///
1801    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1802    /// syntax variations) are applied automatically.  Returns an empty string if
1803    /// generation fails.
1804    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1805        crate::generate(self, dialect).unwrap_or_default()
1806    }
1807}
1808
1809// === Python API accessor methods ===
1810
1811impl Expression {
1812    /// Returns the serde-compatible snake_case variant name without serialization.
1813    /// This is much faster than serializing to JSON and extracting the key.
1814    pub fn variant_name(&self) -> &'static str {
1815        match self {
1816            Expression::Literal(_) => "literal",
1817            Expression::Boolean(_) => "boolean",
1818            Expression::Null(_) => "null",
1819            Expression::Identifier(_) => "identifier",
1820            Expression::Column(_) => "column",
1821            Expression::Table(_) => "table",
1822            Expression::Star(_) => "star",
1823            Expression::BracedWildcard(_) => "braced_wildcard",
1824            Expression::Select(_) => "select",
1825            Expression::Union(_) => "union",
1826            Expression::Intersect(_) => "intersect",
1827            Expression::Except(_) => "except",
1828            Expression::Subquery(_) => "subquery",
1829            Expression::PipeOperator(_) => "pipe_operator",
1830            Expression::Pivot(_) => "pivot",
1831            Expression::PivotAlias(_) => "pivot_alias",
1832            Expression::Unpivot(_) => "unpivot",
1833            Expression::Values(_) => "values",
1834            Expression::PreWhere(_) => "pre_where",
1835            Expression::Stream(_) => "stream",
1836            Expression::UsingData(_) => "using_data",
1837            Expression::XmlNamespace(_) => "xml_namespace",
1838            Expression::Insert(_) => "insert",
1839            Expression::Update(_) => "update",
1840            Expression::Delete(_) => "delete",
1841            Expression::Copy(_) => "copy",
1842            Expression::Put(_) => "put",
1843            Expression::StageReference(_) => "stage_reference",
1844            Expression::Alias(_) => "alias",
1845            Expression::Cast(_) => "cast",
1846            Expression::Collation(_) => "collation",
1847            Expression::Case(_) => "case",
1848            Expression::And(_) => "and",
1849            Expression::Or(_) => "or",
1850            Expression::Add(_) => "add",
1851            Expression::Sub(_) => "sub",
1852            Expression::Mul(_) => "mul",
1853            Expression::Div(_) => "div",
1854            Expression::Mod(_) => "mod",
1855            Expression::Eq(_) => "eq",
1856            Expression::Neq(_) => "neq",
1857            Expression::Lt(_) => "lt",
1858            Expression::Lte(_) => "lte",
1859            Expression::Gt(_) => "gt",
1860            Expression::Gte(_) => "gte",
1861            Expression::Like(_) => "like",
1862            Expression::ILike(_) => "i_like",
1863            Expression::Match(_) => "match",
1864            Expression::BitwiseAnd(_) => "bitwise_and",
1865            Expression::BitwiseOr(_) => "bitwise_or",
1866            Expression::BitwiseXor(_) => "bitwise_xor",
1867            Expression::Concat(_) => "concat",
1868            Expression::Adjacent(_) => "adjacent",
1869            Expression::TsMatch(_) => "ts_match",
1870            Expression::PropertyEQ(_) => "property_e_q",
1871            Expression::ArrayContainsAll(_) => "array_contains_all",
1872            Expression::ArrayContainedBy(_) => "array_contained_by",
1873            Expression::ArrayOverlaps(_) => "array_overlaps",
1874            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1875            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1876            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1877            Expression::ExtendsLeft(_) => "extends_left",
1878            Expression::ExtendsRight(_) => "extends_right",
1879            Expression::Not(_) => "not",
1880            Expression::Neg(_) => "neg",
1881            Expression::BitwiseNot(_) => "bitwise_not",
1882            Expression::In(_) => "in",
1883            Expression::Between(_) => "between",
1884            Expression::IsNull(_) => "is_null",
1885            Expression::IsTrue(_) => "is_true",
1886            Expression::IsFalse(_) => "is_false",
1887            Expression::IsJson(_) => "is_json",
1888            Expression::Is(_) => "is",
1889            Expression::Exists(_) => "exists",
1890            Expression::MemberOf(_) => "member_of",
1891            Expression::Function(_) => "function",
1892            Expression::AggregateFunction(_) => "aggregate_function",
1893            Expression::WindowFunction(_) => "window_function",
1894            Expression::From(_) => "from",
1895            Expression::Join(_) => "join",
1896            Expression::JoinedTable(_) => "joined_table",
1897            Expression::Where(_) => "where",
1898            Expression::GroupBy(_) => "group_by",
1899            Expression::Having(_) => "having",
1900            Expression::OrderBy(_) => "order_by",
1901            Expression::Limit(_) => "limit",
1902            Expression::Offset(_) => "offset",
1903            Expression::Qualify(_) => "qualify",
1904            Expression::With(_) => "with",
1905            Expression::Cte(_) => "cte",
1906            Expression::DistributeBy(_) => "distribute_by",
1907            Expression::ClusterBy(_) => "cluster_by",
1908            Expression::SortBy(_) => "sort_by",
1909            Expression::LateralView(_) => "lateral_view",
1910            Expression::Hint(_) => "hint",
1911            Expression::Pseudocolumn(_) => "pseudocolumn",
1912            Expression::Connect(_) => "connect",
1913            Expression::Prior(_) => "prior",
1914            Expression::ConnectByRoot(_) => "connect_by_root",
1915            Expression::MatchRecognize(_) => "match_recognize",
1916            Expression::Ordered(_) => "ordered",
1917            Expression::Window(_) => "window",
1918            Expression::Over(_) => "over",
1919            Expression::WithinGroup(_) => "within_group",
1920            Expression::DataType(_) => "data_type",
1921            Expression::Array(_) => "array",
1922            Expression::Struct(_) => "struct",
1923            Expression::Tuple(_) => "tuple",
1924            Expression::Interval(_) => "interval",
1925            Expression::ConcatWs(_) => "concat_ws",
1926            Expression::Substring(_) => "substring",
1927            Expression::Upper(_) => "upper",
1928            Expression::Lower(_) => "lower",
1929            Expression::Length(_) => "length",
1930            Expression::Trim(_) => "trim",
1931            Expression::LTrim(_) => "l_trim",
1932            Expression::RTrim(_) => "r_trim",
1933            Expression::Replace(_) => "replace",
1934            Expression::Reverse(_) => "reverse",
1935            Expression::Left(_) => "left",
1936            Expression::Right(_) => "right",
1937            Expression::Repeat(_) => "repeat",
1938            Expression::Lpad(_) => "lpad",
1939            Expression::Rpad(_) => "rpad",
1940            Expression::Split(_) => "split",
1941            Expression::RegexpLike(_) => "regexp_like",
1942            Expression::RegexpReplace(_) => "regexp_replace",
1943            Expression::RegexpExtract(_) => "regexp_extract",
1944            Expression::Overlay(_) => "overlay",
1945            Expression::Abs(_) => "abs",
1946            Expression::Round(_) => "round",
1947            Expression::Floor(_) => "floor",
1948            Expression::Ceil(_) => "ceil",
1949            Expression::Power(_) => "power",
1950            Expression::Sqrt(_) => "sqrt",
1951            Expression::Cbrt(_) => "cbrt",
1952            Expression::Ln(_) => "ln",
1953            Expression::Log(_) => "log",
1954            Expression::Exp(_) => "exp",
1955            Expression::Sign(_) => "sign",
1956            Expression::Greatest(_) => "greatest",
1957            Expression::Least(_) => "least",
1958            Expression::CurrentDate(_) => "current_date",
1959            Expression::CurrentTime(_) => "current_time",
1960            Expression::CurrentTimestamp(_) => "current_timestamp",
1961            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1962            Expression::AtTimeZone(_) => "at_time_zone",
1963            Expression::DateAdd(_) => "date_add",
1964            Expression::DateSub(_) => "date_sub",
1965            Expression::DateDiff(_) => "date_diff",
1966            Expression::DateTrunc(_) => "date_trunc",
1967            Expression::Extract(_) => "extract",
1968            Expression::ToDate(_) => "to_date",
1969            Expression::ToTimestamp(_) => "to_timestamp",
1970            Expression::Date(_) => "date",
1971            Expression::Time(_) => "time",
1972            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1973            Expression::UnixDate(_) => "unix_date",
1974            Expression::UnixSeconds(_) => "unix_seconds",
1975            Expression::UnixMillis(_) => "unix_millis",
1976            Expression::UnixMicros(_) => "unix_micros",
1977            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1978            Expression::TimeStrToDate(_) => "time_str_to_date",
1979            Expression::DateToDi(_) => "date_to_di",
1980            Expression::DiToDate(_) => "di_to_date",
1981            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1982            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1983            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1984            Expression::YearOfWeek(_) => "year_of_week",
1985            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1986            Expression::Coalesce(_) => "coalesce",
1987            Expression::NullIf(_) => "null_if",
1988            Expression::IfFunc(_) => "if_func",
1989            Expression::IfNull(_) => "if_null",
1990            Expression::Nvl(_) => "nvl",
1991            Expression::Nvl2(_) => "nvl2",
1992            Expression::TryCast(_) => "try_cast",
1993            Expression::SafeCast(_) => "safe_cast",
1994            Expression::Count(_) => "count",
1995            Expression::Sum(_) => "sum",
1996            Expression::Avg(_) => "avg",
1997            Expression::Min(_) => "min",
1998            Expression::Max(_) => "max",
1999            Expression::GroupConcat(_) => "group_concat",
2000            Expression::StringAgg(_) => "string_agg",
2001            Expression::ListAgg(_) => "list_agg",
2002            Expression::ArrayAgg(_) => "array_agg",
2003            Expression::CountIf(_) => "count_if",
2004            Expression::SumIf(_) => "sum_if",
2005            Expression::Stddev(_) => "stddev",
2006            Expression::StddevPop(_) => "stddev_pop",
2007            Expression::StddevSamp(_) => "stddev_samp",
2008            Expression::Variance(_) => "variance",
2009            Expression::VarPop(_) => "var_pop",
2010            Expression::VarSamp(_) => "var_samp",
2011            Expression::Median(_) => "median",
2012            Expression::Mode(_) => "mode",
2013            Expression::First(_) => "first",
2014            Expression::Last(_) => "last",
2015            Expression::AnyValue(_) => "any_value",
2016            Expression::ApproxDistinct(_) => "approx_distinct",
2017            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2018            Expression::ApproxPercentile(_) => "approx_percentile",
2019            Expression::Percentile(_) => "percentile",
2020            Expression::LogicalAnd(_) => "logical_and",
2021            Expression::LogicalOr(_) => "logical_or",
2022            Expression::Skewness(_) => "skewness",
2023            Expression::BitwiseCount(_) => "bitwise_count",
2024            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2025            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2026            Expression::BoolXorAgg(_) => "bool_xor_agg",
2027            Expression::RowNumber(_) => "row_number",
2028            Expression::Rank(_) => "rank",
2029            Expression::DenseRank(_) => "dense_rank",
2030            Expression::NTile(_) => "n_tile",
2031            Expression::Lead(_) => "lead",
2032            Expression::Lag(_) => "lag",
2033            Expression::FirstValue(_) => "first_value",
2034            Expression::LastValue(_) => "last_value",
2035            Expression::NthValue(_) => "nth_value",
2036            Expression::PercentRank(_) => "percent_rank",
2037            Expression::CumeDist(_) => "cume_dist",
2038            Expression::PercentileCont(_) => "percentile_cont",
2039            Expression::PercentileDisc(_) => "percentile_disc",
2040            Expression::Contains(_) => "contains",
2041            Expression::StartsWith(_) => "starts_with",
2042            Expression::EndsWith(_) => "ends_with",
2043            Expression::Position(_) => "position",
2044            Expression::Initcap(_) => "initcap",
2045            Expression::Ascii(_) => "ascii",
2046            Expression::Chr(_) => "chr",
2047            Expression::CharFunc(_) => "char_func",
2048            Expression::Soundex(_) => "soundex",
2049            Expression::Levenshtein(_) => "levenshtein",
2050            Expression::ByteLength(_) => "byte_length",
2051            Expression::Hex(_) => "hex",
2052            Expression::LowerHex(_) => "lower_hex",
2053            Expression::Unicode(_) => "unicode",
2054            Expression::ModFunc(_) => "mod_func",
2055            Expression::Random(_) => "random",
2056            Expression::Rand(_) => "rand",
2057            Expression::TruncFunc(_) => "trunc_func",
2058            Expression::Pi(_) => "pi",
2059            Expression::Radians(_) => "radians",
2060            Expression::Degrees(_) => "degrees",
2061            Expression::Sin(_) => "sin",
2062            Expression::Cos(_) => "cos",
2063            Expression::Tan(_) => "tan",
2064            Expression::Asin(_) => "asin",
2065            Expression::Acos(_) => "acos",
2066            Expression::Atan(_) => "atan",
2067            Expression::Atan2(_) => "atan2",
2068            Expression::IsNan(_) => "is_nan",
2069            Expression::IsInf(_) => "is_inf",
2070            Expression::IntDiv(_) => "int_div",
2071            Expression::Decode(_) => "decode",
2072            Expression::DateFormat(_) => "date_format",
2073            Expression::FormatDate(_) => "format_date",
2074            Expression::Year(_) => "year",
2075            Expression::Month(_) => "month",
2076            Expression::Day(_) => "day",
2077            Expression::Hour(_) => "hour",
2078            Expression::Minute(_) => "minute",
2079            Expression::Second(_) => "second",
2080            Expression::DayOfWeek(_) => "day_of_week",
2081            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2082            Expression::DayOfMonth(_) => "day_of_month",
2083            Expression::DayOfYear(_) => "day_of_year",
2084            Expression::WeekOfYear(_) => "week_of_year",
2085            Expression::Quarter(_) => "quarter",
2086            Expression::AddMonths(_) => "add_months",
2087            Expression::MonthsBetween(_) => "months_between",
2088            Expression::LastDay(_) => "last_day",
2089            Expression::NextDay(_) => "next_day",
2090            Expression::Epoch(_) => "epoch",
2091            Expression::EpochMs(_) => "epoch_ms",
2092            Expression::FromUnixtime(_) => "from_unixtime",
2093            Expression::UnixTimestamp(_) => "unix_timestamp",
2094            Expression::MakeDate(_) => "make_date",
2095            Expression::MakeTimestamp(_) => "make_timestamp",
2096            Expression::TimestampTrunc(_) => "timestamp_trunc",
2097            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2098            Expression::SessionUser(_) => "session_user",
2099            Expression::SHA(_) => "s_h_a",
2100            Expression::SHA1Digest(_) => "s_h_a1_digest",
2101            Expression::TimeToUnix(_) => "time_to_unix",
2102            Expression::ArrayFunc(_) => "array_func",
2103            Expression::ArrayLength(_) => "array_length",
2104            Expression::ArraySize(_) => "array_size",
2105            Expression::Cardinality(_) => "cardinality",
2106            Expression::ArrayContains(_) => "array_contains",
2107            Expression::ArrayPosition(_) => "array_position",
2108            Expression::ArrayAppend(_) => "array_append",
2109            Expression::ArrayPrepend(_) => "array_prepend",
2110            Expression::ArrayConcat(_) => "array_concat",
2111            Expression::ArraySort(_) => "array_sort",
2112            Expression::ArrayReverse(_) => "array_reverse",
2113            Expression::ArrayDistinct(_) => "array_distinct",
2114            Expression::ArrayJoin(_) => "array_join",
2115            Expression::ArrayToString(_) => "array_to_string",
2116            Expression::Unnest(_) => "unnest",
2117            Expression::Explode(_) => "explode",
2118            Expression::ExplodeOuter(_) => "explode_outer",
2119            Expression::ArrayFilter(_) => "array_filter",
2120            Expression::ArrayTransform(_) => "array_transform",
2121            Expression::ArrayFlatten(_) => "array_flatten",
2122            Expression::ArrayCompact(_) => "array_compact",
2123            Expression::ArrayIntersect(_) => "array_intersect",
2124            Expression::ArrayUnion(_) => "array_union",
2125            Expression::ArrayExcept(_) => "array_except",
2126            Expression::ArrayRemove(_) => "array_remove",
2127            Expression::ArrayZip(_) => "array_zip",
2128            Expression::Sequence(_) => "sequence",
2129            Expression::Generate(_) => "generate",
2130            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2131            Expression::ToArray(_) => "to_array",
2132            Expression::StarMap(_) => "star_map",
2133            Expression::StructFunc(_) => "struct_func",
2134            Expression::StructExtract(_) => "struct_extract",
2135            Expression::NamedStruct(_) => "named_struct",
2136            Expression::MapFunc(_) => "map_func",
2137            Expression::MapFromEntries(_) => "map_from_entries",
2138            Expression::MapFromArrays(_) => "map_from_arrays",
2139            Expression::MapKeys(_) => "map_keys",
2140            Expression::MapValues(_) => "map_values",
2141            Expression::MapContainsKey(_) => "map_contains_key",
2142            Expression::MapConcat(_) => "map_concat",
2143            Expression::ElementAt(_) => "element_at",
2144            Expression::TransformKeys(_) => "transform_keys",
2145            Expression::TransformValues(_) => "transform_values",
2146            Expression::FunctionEmits(_) => "function_emits",
2147            Expression::JsonExtract(_) => "json_extract",
2148            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2149            Expression::JsonExtractPath(_) => "json_extract_path",
2150            Expression::JsonArray(_) => "json_array",
2151            Expression::JsonObject(_) => "json_object",
2152            Expression::JsonQuery(_) => "json_query",
2153            Expression::JsonValue(_) => "json_value",
2154            Expression::JsonArrayLength(_) => "json_array_length",
2155            Expression::JsonKeys(_) => "json_keys",
2156            Expression::JsonType(_) => "json_type",
2157            Expression::ParseJson(_) => "parse_json",
2158            Expression::ToJson(_) => "to_json",
2159            Expression::JsonSet(_) => "json_set",
2160            Expression::JsonInsert(_) => "json_insert",
2161            Expression::JsonRemove(_) => "json_remove",
2162            Expression::JsonMergePatch(_) => "json_merge_patch",
2163            Expression::JsonArrayAgg(_) => "json_array_agg",
2164            Expression::JsonObjectAgg(_) => "json_object_agg",
2165            Expression::Convert(_) => "convert",
2166            Expression::Typeof(_) => "typeof",
2167            Expression::Lambda(_) => "lambda",
2168            Expression::Parameter(_) => "parameter",
2169            Expression::Placeholder(_) => "placeholder",
2170            Expression::NamedArgument(_) => "named_argument",
2171            Expression::TableArgument(_) => "table_argument",
2172            Expression::SqlComment(_) => "sql_comment",
2173            Expression::NullSafeEq(_) => "null_safe_eq",
2174            Expression::NullSafeNeq(_) => "null_safe_neq",
2175            Expression::Glob(_) => "glob",
2176            Expression::SimilarTo(_) => "similar_to",
2177            Expression::Any(_) => "any",
2178            Expression::All(_) => "all",
2179            Expression::Overlaps(_) => "overlaps",
2180            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2181            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2182            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2183            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2184            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2185            Expression::Subscript(_) => "subscript",
2186            Expression::Dot(_) => "dot",
2187            Expression::MethodCall(_) => "method_call",
2188            Expression::ArraySlice(_) => "array_slice",
2189            Expression::CreateTable(_) => "create_table",
2190            Expression::DropTable(_) => "drop_table",
2191            Expression::AlterTable(_) => "alter_table",
2192            Expression::CreateIndex(_) => "create_index",
2193            Expression::DropIndex(_) => "drop_index",
2194            Expression::CreateView(_) => "create_view",
2195            Expression::DropView(_) => "drop_view",
2196            Expression::AlterView(_) => "alter_view",
2197            Expression::AlterIndex(_) => "alter_index",
2198            Expression::Truncate(_) => "truncate",
2199            Expression::Use(_) => "use",
2200            Expression::Cache(_) => "cache",
2201            Expression::Uncache(_) => "uncache",
2202            Expression::LoadData(_) => "load_data",
2203            Expression::Pragma(_) => "pragma",
2204            Expression::Grant(_) => "grant",
2205            Expression::Revoke(_) => "revoke",
2206            Expression::Comment(_) => "comment",
2207            Expression::SetStatement(_) => "set_statement",
2208            Expression::CreateSchema(_) => "create_schema",
2209            Expression::DropSchema(_) => "drop_schema",
2210            Expression::DropNamespace(_) => "drop_namespace",
2211            Expression::CreateDatabase(_) => "create_database",
2212            Expression::DropDatabase(_) => "drop_database",
2213            Expression::CreateFunction(_) => "create_function",
2214            Expression::DropFunction(_) => "drop_function",
2215            Expression::CreateProcedure(_) => "create_procedure",
2216            Expression::DropProcedure(_) => "drop_procedure",
2217            Expression::CreateSequence(_) => "create_sequence",
2218            Expression::CreateSynonym(_) => "create_synonym",
2219            Expression::DropSequence(_) => "drop_sequence",
2220            Expression::AlterSequence(_) => "alter_sequence",
2221            Expression::CreateTrigger(_) => "create_trigger",
2222            Expression::DropTrigger(_) => "drop_trigger",
2223            Expression::CreateType(_) => "create_type",
2224            Expression::DropType(_) => "drop_type",
2225            Expression::Describe(_) => "describe",
2226            Expression::Show(_) => "show",
2227            Expression::Command(_) => "command",
2228            Expression::Kill(_) => "kill",
2229            Expression::Execute(_) => "execute",
2230            Expression::Raw(_) => "raw",
2231            Expression::CreateTask(_) => "create_task",
2232            Expression::Paren(_) => "paren",
2233            Expression::Annotated(_) => "annotated",
2234            Expression::Refresh(_) => "refresh",
2235            Expression::LockingStatement(_) => "locking_statement",
2236            Expression::SequenceProperties(_) => "sequence_properties",
2237            Expression::TruncateTable(_) => "truncate_table",
2238            Expression::Clone(_) => "clone",
2239            Expression::Attach(_) => "attach",
2240            Expression::Detach(_) => "detach",
2241            Expression::Install(_) => "install",
2242            Expression::Summarize(_) => "summarize",
2243            Expression::Declare(_) => "declare",
2244            Expression::DeclareItem(_) => "declare_item",
2245            Expression::Set(_) => "set",
2246            Expression::Heredoc(_) => "heredoc",
2247            Expression::SetItem(_) => "set_item",
2248            Expression::QueryBand(_) => "query_band",
2249            Expression::UserDefinedFunction(_) => "user_defined_function",
2250            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2251            Expression::ProjectionDef(_) => "projection_def",
2252            Expression::TableAlias(_) => "table_alias",
2253            Expression::ByteString(_) => "byte_string",
2254            Expression::HexStringExpr(_) => "hex_string_expr",
2255            Expression::UnicodeString(_) => "unicode_string",
2256            Expression::ColumnPosition(_) => "column_position",
2257            Expression::ColumnDef(_) => "column_def",
2258            Expression::AlterColumn(_) => "alter_column",
2259            Expression::AlterSortKey(_) => "alter_sort_key",
2260            Expression::AlterSet(_) => "alter_set",
2261            Expression::RenameColumn(_) => "rename_column",
2262            Expression::Comprehension(_) => "comprehension",
2263            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2264            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2265            Expression::IndexConstraintOption(_) => "index_constraint_option",
2266            Expression::ColumnConstraint(_) => "column_constraint",
2267            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2268            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2269            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2270            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2271            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2272            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2273            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2274            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2275            Expression::WithOperator(_) => "with_operator",
2276            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2277                "generated_as_identity_column_constraint"
2278            }
2279            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2280            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2281            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2282            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2283            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2284            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2285            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2286            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2287            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2288            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2289            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2290            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2291            Expression::PathColumnConstraint(_) => "path_column_constraint",
2292            Expression::Constraint(_) => "constraint",
2293            Expression::Export(_) => "export",
2294            Expression::Filter(_) => "filter",
2295            Expression::Changes(_) => "changes",
2296            Expression::CopyParameter(_) => "copy_parameter",
2297            Expression::Credentials(_) => "credentials",
2298            Expression::Directory(_) => "directory",
2299            Expression::ForeignKey(_) => "foreign_key",
2300            Expression::ColumnPrefix(_) => "column_prefix",
2301            Expression::PrimaryKey(_) => "primary_key",
2302            Expression::IntoClause(_) => "into_clause",
2303            Expression::JoinHint(_) => "join_hint",
2304            Expression::Opclass(_) => "opclass",
2305            Expression::Index(_) => "index",
2306            Expression::IndexParameters(_) => "index_parameters",
2307            Expression::ConditionalInsert(_) => "conditional_insert",
2308            Expression::MultitableInserts(_) => "multitable_inserts",
2309            Expression::OnConflict(_) => "on_conflict",
2310            Expression::OnCondition(_) => "on_condition",
2311            Expression::Returning(_) => "returning",
2312            Expression::Introducer(_) => "introducer",
2313            Expression::PartitionRange(_) => "partition_range",
2314            Expression::Fetch(_) => "fetch",
2315            Expression::Group(_) => "group",
2316            Expression::Cube(_) => "cube",
2317            Expression::Rollup(_) => "rollup",
2318            Expression::GroupingSets(_) => "grouping_sets",
2319            Expression::LimitOptions(_) => "limit_options",
2320            Expression::Lateral(_) => "lateral",
2321            Expression::TableFromRows(_) => "table_from_rows",
2322            Expression::RowsFrom(_) => "rows_from",
2323            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2324            Expression::WithFill(_) => "with_fill",
2325            Expression::Property(_) => "property",
2326            Expression::GrantPrivilege(_) => "grant_privilege",
2327            Expression::GrantPrincipal(_) => "grant_principal",
2328            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2329            Expression::AlgorithmProperty(_) => "algorithm_property",
2330            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2331            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2332            Expression::BackupProperty(_) => "backup_property",
2333            Expression::BuildProperty(_) => "build_property",
2334            Expression::BlockCompressionProperty(_) => "block_compression_property",
2335            Expression::CharacterSetProperty(_) => "character_set_property",
2336            Expression::ChecksumProperty(_) => "checksum_property",
2337            Expression::CollateProperty(_) => "collate_property",
2338            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2339            Expression::DataDeletionProperty(_) => "data_deletion_property",
2340            Expression::DefinerProperty(_) => "definer_property",
2341            Expression::DistKeyProperty(_) => "dist_key_property",
2342            Expression::DistributedByProperty(_) => "distributed_by_property",
2343            Expression::DistStyleProperty(_) => "dist_style_property",
2344            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2345            Expression::EngineProperty(_) => "engine_property",
2346            Expression::ToTableProperty(_) => "to_table_property",
2347            Expression::ExecuteAsProperty(_) => "execute_as_property",
2348            Expression::ExternalProperty(_) => "external_property",
2349            Expression::FallbackProperty(_) => "fallback_property",
2350            Expression::FileFormatProperty(_) => "file_format_property",
2351            Expression::CredentialsProperty(_) => "credentials_property",
2352            Expression::FreespaceProperty(_) => "freespace_property",
2353            Expression::InheritsProperty(_) => "inherits_property",
2354            Expression::InputModelProperty(_) => "input_model_property",
2355            Expression::OutputModelProperty(_) => "output_model_property",
2356            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2357            Expression::JournalProperty(_) => "journal_property",
2358            Expression::LanguageProperty(_) => "language_property",
2359            Expression::EnviromentProperty(_) => "enviroment_property",
2360            Expression::ClusteredByProperty(_) => "clustered_by_property",
2361            Expression::DictProperty(_) => "dict_property",
2362            Expression::DictRange(_) => "dict_range",
2363            Expression::OnCluster(_) => "on_cluster",
2364            Expression::LikeProperty(_) => "like_property",
2365            Expression::LocationProperty(_) => "location_property",
2366            Expression::LockProperty(_) => "lock_property",
2367            Expression::LockingProperty(_) => "locking_property",
2368            Expression::LogProperty(_) => "log_property",
2369            Expression::MaterializedProperty(_) => "materialized_property",
2370            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2371            Expression::OnProperty(_) => "on_property",
2372            Expression::OnCommitProperty(_) => "on_commit_property",
2373            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2374            Expression::PartitionByProperty(_) => "partition_by_property",
2375            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2376            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2377            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2378            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2379            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2380            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2381            Expression::PartitionList(_) => "partition_list",
2382            Expression::Partition(_) => "partition",
2383            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2384            Expression::UniqueKeyProperty(_) => "unique_key_property",
2385            Expression::RollupProperty(_) => "rollup_property",
2386            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2387            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2388            Expression::RemoteWithConnectionModelProperty(_) => {
2389                "remote_with_connection_model_property"
2390            }
2391            Expression::ReturnsProperty(_) => "returns_property",
2392            Expression::RowFormatProperty(_) => "row_format_property",
2393            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2394            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2395            Expression::QueryTransform(_) => "query_transform",
2396            Expression::SampleProperty(_) => "sample_property",
2397            Expression::SecurityProperty(_) => "security_property",
2398            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2399            Expression::SemanticView(_) => "semantic_view",
2400            Expression::SerdeProperties(_) => "serde_properties",
2401            Expression::SetProperty(_) => "set_property",
2402            Expression::SharingProperty(_) => "sharing_property",
2403            Expression::SetConfigProperty(_) => "set_config_property",
2404            Expression::SettingsProperty(_) => "settings_property",
2405            Expression::SortKeyProperty(_) => "sort_key_property",
2406            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2407            Expression::SqlSecurityProperty(_) => "sql_security_property",
2408            Expression::StabilityProperty(_) => "stability_property",
2409            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2410            Expression::TemporaryProperty(_) => "temporary_property",
2411            Expression::Tags(_) => "tags",
2412            Expression::TransformModelProperty(_) => "transform_model_property",
2413            Expression::TransientProperty(_) => "transient_property",
2414            Expression::UsingTemplateProperty(_) => "using_template_property",
2415            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2416            Expression::VolatileProperty(_) => "volatile_property",
2417            Expression::WithDataProperty(_) => "with_data_property",
2418            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2419            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2420            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2421            Expression::WithProcedureOptions(_) => "with_procedure_options",
2422            Expression::EncodeProperty(_) => "encode_property",
2423            Expression::IncludeProperty(_) => "include_property",
2424            Expression::Properties(_) => "properties",
2425            Expression::OptionsProperty(_) => "options_property",
2426            Expression::InputOutputFormat(_) => "input_output_format",
2427            Expression::Reference(_) => "reference",
2428            Expression::QueryOption(_) => "query_option",
2429            Expression::WithTableHint(_) => "with_table_hint",
2430            Expression::IndexTableHint(_) => "index_table_hint",
2431            Expression::HistoricalData(_) => "historical_data",
2432            Expression::Get(_) => "get",
2433            Expression::SetOperation(_) => "set_operation",
2434            Expression::Var(_) => "var",
2435            Expression::Variadic(_) => "variadic",
2436            Expression::Version(_) => "version",
2437            Expression::Schema(_) => "schema",
2438            Expression::Lock(_) => "lock",
2439            Expression::TableSample(_) => "table_sample",
2440            Expression::Tag(_) => "tag",
2441            Expression::UnpivotColumns(_) => "unpivot_columns",
2442            Expression::WindowSpec(_) => "window_spec",
2443            Expression::SessionParameter(_) => "session_parameter",
2444            Expression::PseudoType(_) => "pseudo_type",
2445            Expression::ObjectIdentifier(_) => "object_identifier",
2446            Expression::Transaction(_) => "transaction",
2447            Expression::Commit(_) => "commit",
2448            Expression::Rollback(_) => "rollback",
2449            Expression::AlterSession(_) => "alter_session",
2450            Expression::Analyze(_) => "analyze",
2451            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2452            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2453            Expression::AnalyzeSample(_) => "analyze_sample",
2454            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2455            Expression::AnalyzeDelete(_) => "analyze_delete",
2456            Expression::AnalyzeWith(_) => "analyze_with",
2457            Expression::AnalyzeValidate(_) => "analyze_validate",
2458            Expression::AddPartition(_) => "add_partition",
2459            Expression::AttachOption(_) => "attach_option",
2460            Expression::DropPartition(_) => "drop_partition",
2461            Expression::ReplacePartition(_) => "replace_partition",
2462            Expression::DPipe(_) => "d_pipe",
2463            Expression::Operator(_) => "operator",
2464            Expression::PivotAny(_) => "pivot_any",
2465            Expression::Aliases(_) => "aliases",
2466            Expression::AtIndex(_) => "at_index",
2467            Expression::FromTimeZone(_) => "from_time_zone",
2468            Expression::FormatPhrase(_) => "format_phrase",
2469            Expression::ForIn(_) => "for_in",
2470            Expression::TimeUnit(_) => "time_unit",
2471            Expression::IntervalOp(_) => "interval_op",
2472            Expression::IntervalSpan(_) => "interval_span",
2473            Expression::HavingMax(_) => "having_max",
2474            Expression::CosineDistance(_) => "cosine_distance",
2475            Expression::DotProduct(_) => "dot_product",
2476            Expression::EuclideanDistance(_) => "euclidean_distance",
2477            Expression::ManhattanDistance(_) => "manhattan_distance",
2478            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2479            Expression::Booland(_) => "booland",
2480            Expression::Boolor(_) => "boolor",
2481            Expression::ParameterizedAgg(_) => "parameterized_agg",
2482            Expression::ArgMax(_) => "arg_max",
2483            Expression::ArgMin(_) => "arg_min",
2484            Expression::ApproxTopK(_) => "approx_top_k",
2485            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2486            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2487            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2488            Expression::ApproxTopSum(_) => "approx_top_sum",
2489            Expression::ApproxQuantiles(_) => "approx_quantiles",
2490            Expression::Minhash(_) => "minhash",
2491            Expression::FarmFingerprint(_) => "farm_fingerprint",
2492            Expression::Float64(_) => "float64",
2493            Expression::Transform(_) => "transform",
2494            Expression::Translate(_) => "translate",
2495            Expression::Grouping(_) => "grouping",
2496            Expression::GroupingId(_) => "grouping_id",
2497            Expression::Anonymous(_) => "anonymous",
2498            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2499            Expression::CombinedAggFunc(_) => "combined_agg_func",
2500            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2501            Expression::HashAgg(_) => "hash_agg",
2502            Expression::Hll(_) => "hll",
2503            Expression::Apply(_) => "apply",
2504            Expression::ToBoolean(_) => "to_boolean",
2505            Expression::List(_) => "list",
2506            Expression::ToMap(_) => "to_map",
2507            Expression::Pad(_) => "pad",
2508            Expression::ToChar(_) => "to_char",
2509            Expression::ToNumber(_) => "to_number",
2510            Expression::ToDouble(_) => "to_double",
2511            Expression::Int64(_) => "int64",
2512            Expression::StringFunc(_) => "string_func",
2513            Expression::ToDecfloat(_) => "to_decfloat",
2514            Expression::TryToDecfloat(_) => "try_to_decfloat",
2515            Expression::ToFile(_) => "to_file",
2516            Expression::Columns(_) => "columns",
2517            Expression::ConvertToCharset(_) => "convert_to_charset",
2518            Expression::ConvertTimezone(_) => "convert_timezone",
2519            Expression::GenerateSeries(_) => "generate_series",
2520            Expression::AIAgg(_) => "a_i_agg",
2521            Expression::AIClassify(_) => "a_i_classify",
2522            Expression::ArrayAll(_) => "array_all",
2523            Expression::ArrayAny(_) => "array_any",
2524            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2525            Expression::StPoint(_) => "st_point",
2526            Expression::StDistance(_) => "st_distance",
2527            Expression::StringToArray(_) => "string_to_array",
2528            Expression::ArraySum(_) => "array_sum",
2529            Expression::ObjectAgg(_) => "object_agg",
2530            Expression::CastToStrType(_) => "cast_to_str_type",
2531            Expression::CheckJson(_) => "check_json",
2532            Expression::CheckXml(_) => "check_xml",
2533            Expression::TranslateCharacters(_) => "translate_characters",
2534            Expression::CurrentSchemas(_) => "current_schemas",
2535            Expression::CurrentDatetime(_) => "current_datetime",
2536            Expression::Localtime(_) => "localtime",
2537            Expression::Localtimestamp(_) => "localtimestamp",
2538            Expression::Systimestamp(_) => "systimestamp",
2539            Expression::CurrentSchema(_) => "current_schema",
2540            Expression::CurrentUser(_) => "current_user",
2541            Expression::UtcTime(_) => "utc_time",
2542            Expression::UtcTimestamp(_) => "utc_timestamp",
2543            Expression::Timestamp(_) => "timestamp",
2544            Expression::DateBin(_) => "date_bin",
2545            Expression::Datetime(_) => "datetime",
2546            Expression::DatetimeAdd(_) => "datetime_add",
2547            Expression::DatetimeSub(_) => "datetime_sub",
2548            Expression::DatetimeDiff(_) => "datetime_diff",
2549            Expression::DatetimeTrunc(_) => "datetime_trunc",
2550            Expression::Dayname(_) => "dayname",
2551            Expression::MakeInterval(_) => "make_interval",
2552            Expression::PreviousDay(_) => "previous_day",
2553            Expression::Elt(_) => "elt",
2554            Expression::TimestampAdd(_) => "timestamp_add",
2555            Expression::TimestampSub(_) => "timestamp_sub",
2556            Expression::TimestampDiff(_) => "timestamp_diff",
2557            Expression::TimeSlice(_) => "time_slice",
2558            Expression::TimeAdd(_) => "time_add",
2559            Expression::TimeSub(_) => "time_sub",
2560            Expression::TimeDiff(_) => "time_diff",
2561            Expression::TimeTrunc(_) => "time_trunc",
2562            Expression::DateFromParts(_) => "date_from_parts",
2563            Expression::TimeFromParts(_) => "time_from_parts",
2564            Expression::DecodeCase(_) => "decode_case",
2565            Expression::Decrypt(_) => "decrypt",
2566            Expression::DecryptRaw(_) => "decrypt_raw",
2567            Expression::Encode(_) => "encode",
2568            Expression::Encrypt(_) => "encrypt",
2569            Expression::EncryptRaw(_) => "encrypt_raw",
2570            Expression::EqualNull(_) => "equal_null",
2571            Expression::ToBinary(_) => "to_binary",
2572            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2573            Expression::Base64DecodeString(_) => "base64_decode_string",
2574            Expression::Base64Encode(_) => "base64_encode",
2575            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2576            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2577            Expression::GapFill(_) => "gap_fill",
2578            Expression::GenerateDateArray(_) => "generate_date_array",
2579            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2580            Expression::GetExtract(_) => "get_extract",
2581            Expression::Getbit(_) => "getbit",
2582            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2583            Expression::HexEncode(_) => "hex_encode",
2584            Expression::Compress(_) => "compress",
2585            Expression::DecompressBinary(_) => "decompress_binary",
2586            Expression::DecompressString(_) => "decompress_string",
2587            Expression::Xor(_) => "xor",
2588            Expression::Nullif(_) => "nullif",
2589            Expression::JSON(_) => "j_s_o_n",
2590            Expression::JSONPath(_) => "j_s_o_n_path",
2591            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2592            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2593            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2594            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2595            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2596            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2597            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2598            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2599            Expression::Format(_) => "format",
2600            Expression::JSONKeys(_) => "j_s_o_n_keys",
2601            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2602            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2603            Expression::JSONObject(_) => "j_s_o_n_object",
2604            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2605            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2606            Expression::JSONArray(_) => "j_s_o_n_array",
2607            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2608            Expression::JSONExists(_) => "j_s_o_n_exists",
2609            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2610            Expression::JSONSchema(_) => "j_s_o_n_schema",
2611            Expression::JSONSet(_) => "j_s_o_n_set",
2612            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2613            Expression::JSONValue(_) => "j_s_o_n_value",
2614            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2615            Expression::JSONRemove(_) => "j_s_o_n_remove",
2616            Expression::JSONTable(_) => "j_s_o_n_table",
2617            Expression::JSONType(_) => "j_s_o_n_type",
2618            Expression::ObjectInsert(_) => "object_insert",
2619            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2620            Expression::OpenJSON(_) => "open_j_s_o_n",
2621            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2622            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2623            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2624            Expression::JSONCast(_) => "j_s_o_n_cast",
2625            Expression::JSONExtract(_) => "j_s_o_n_extract",
2626            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2627            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2628            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2629            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2630            Expression::JSONFormat(_) => "j_s_o_n_format",
2631            Expression::JSONBool(_) => "j_s_o_n_bool",
2632            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2633            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2634            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2635            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2636            Expression::ParseJSON(_) => "parse_j_s_o_n",
2637            Expression::ParseUrl(_) => "parse_url",
2638            Expression::ParseIp(_) => "parse_ip",
2639            Expression::ParseTime(_) => "parse_time",
2640            Expression::ParseDatetime(_) => "parse_datetime",
2641            Expression::Map(_) => "map",
2642            Expression::MapCat(_) => "map_cat",
2643            Expression::MapDelete(_) => "map_delete",
2644            Expression::MapInsert(_) => "map_insert",
2645            Expression::MapPick(_) => "map_pick",
2646            Expression::ScopeResolution(_) => "scope_resolution",
2647            Expression::Slice(_) => "slice",
2648            Expression::VarMap(_) => "var_map",
2649            Expression::MatchAgainst(_) => "match_against",
2650            Expression::MD5Digest(_) => "m_d5_digest",
2651            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2652            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2653            Expression::Monthname(_) => "monthname",
2654            Expression::Ntile(_) => "ntile",
2655            Expression::Normalize(_) => "normalize",
2656            Expression::Normal(_) => "normal",
2657            Expression::Predict(_) => "predict",
2658            Expression::MLTranslate(_) => "m_l_translate",
2659            Expression::FeaturesAtTime(_) => "features_at_time",
2660            Expression::GenerateEmbedding(_) => "generate_embedding",
2661            Expression::MLForecast(_) => "m_l_forecast",
2662            Expression::ModelAttribute(_) => "model_attribute",
2663            Expression::VectorSearch(_) => "vector_search",
2664            Expression::Quantile(_) => "quantile",
2665            Expression::ApproxQuantile(_) => "approx_quantile",
2666            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2667            Expression::Randn(_) => "randn",
2668            Expression::Randstr(_) => "randstr",
2669            Expression::RangeN(_) => "range_n",
2670            Expression::RangeBucket(_) => "range_bucket",
2671            Expression::ReadCSV(_) => "read_c_s_v",
2672            Expression::ReadParquet(_) => "read_parquet",
2673            Expression::Reduce(_) => "reduce",
2674            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2675            Expression::RegexpILike(_) => "regexp_i_like",
2676            Expression::RegexpFullMatch(_) => "regexp_full_match",
2677            Expression::RegexpInstr(_) => "regexp_instr",
2678            Expression::RegexpSplit(_) => "regexp_split",
2679            Expression::RegexpCount(_) => "regexp_count",
2680            Expression::RegrValx(_) => "regr_valx",
2681            Expression::RegrValy(_) => "regr_valy",
2682            Expression::RegrAvgy(_) => "regr_avgy",
2683            Expression::RegrAvgx(_) => "regr_avgx",
2684            Expression::RegrCount(_) => "regr_count",
2685            Expression::RegrIntercept(_) => "regr_intercept",
2686            Expression::RegrR2(_) => "regr_r2",
2687            Expression::RegrSxx(_) => "regr_sxx",
2688            Expression::RegrSxy(_) => "regr_sxy",
2689            Expression::RegrSyy(_) => "regr_syy",
2690            Expression::RegrSlope(_) => "regr_slope",
2691            Expression::SafeAdd(_) => "safe_add",
2692            Expression::SafeDivide(_) => "safe_divide",
2693            Expression::SafeMultiply(_) => "safe_multiply",
2694            Expression::SafeSubtract(_) => "safe_subtract",
2695            Expression::SHA2(_) => "s_h_a2",
2696            Expression::SHA2Digest(_) => "s_h_a2_digest",
2697            Expression::SortArray(_) => "sort_array",
2698            Expression::SplitPart(_) => "split_part",
2699            Expression::SubstringIndex(_) => "substring_index",
2700            Expression::StandardHash(_) => "standard_hash",
2701            Expression::StrPosition(_) => "str_position",
2702            Expression::Search(_) => "search",
2703            Expression::SearchIp(_) => "search_ip",
2704            Expression::StrToDate(_) => "str_to_date",
2705            Expression::DateStrToDate(_) => "date_str_to_date",
2706            Expression::DateToDateStr(_) => "date_to_date_str",
2707            Expression::StrToTime(_) => "str_to_time",
2708            Expression::StrToUnix(_) => "str_to_unix",
2709            Expression::StrToMap(_) => "str_to_map",
2710            Expression::NumberToStr(_) => "number_to_str",
2711            Expression::FromBase(_) => "from_base",
2712            Expression::Stuff(_) => "stuff",
2713            Expression::TimeToStr(_) => "time_to_str",
2714            Expression::TimeStrToTime(_) => "time_str_to_time",
2715            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2716            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2717            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2718            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2719            Expression::Unhex(_) => "unhex",
2720            Expression::Uniform(_) => "uniform",
2721            Expression::UnixToStr(_) => "unix_to_str",
2722            Expression::UnixToTime(_) => "unix_to_time",
2723            Expression::Uuid(_) => "uuid",
2724            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2725            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2726            Expression::Corr(_) => "corr",
2727            Expression::WidthBucket(_) => "width_bucket",
2728            Expression::CovarSamp(_) => "covar_samp",
2729            Expression::CovarPop(_) => "covar_pop",
2730            Expression::Week(_) => "week",
2731            Expression::XMLElement(_) => "x_m_l_element",
2732            Expression::XMLGet(_) => "x_m_l_get",
2733            Expression::XMLTable(_) => "x_m_l_table",
2734            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2735            Expression::Zipf(_) => "zipf",
2736            Expression::Merge(_) => "merge",
2737            Expression::When(_) => "when",
2738            Expression::Whens(_) => "whens",
2739            Expression::NextValueFor(_) => "next_value_for",
2740            Expression::ReturnStmt(_) => "return_stmt",
2741        }
2742    }
2743
2744    /// Returns the primary child expression (".this" in sqlglot).
2745    pub fn get_this(&self) -> Option<&Expression> {
2746        match self {
2747            // Unary ops
2748            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2749            // UnaryFunc variants
2750            Expression::Upper(f)
2751            | Expression::Lower(f)
2752            | Expression::Length(f)
2753            | Expression::LTrim(f)
2754            | Expression::RTrim(f)
2755            | Expression::Reverse(f)
2756            | Expression::Abs(f)
2757            | Expression::Sqrt(f)
2758            | Expression::Cbrt(f)
2759            | Expression::Ln(f)
2760            | Expression::Exp(f)
2761            | Expression::Sign(f)
2762            | Expression::Date(f)
2763            | Expression::Time(f)
2764            | Expression::Initcap(f)
2765            | Expression::Ascii(f)
2766            | Expression::Chr(f)
2767            | Expression::Soundex(f)
2768            | Expression::ByteLength(f)
2769            | Expression::Hex(f)
2770            | Expression::LowerHex(f)
2771            | Expression::Unicode(f)
2772            | Expression::Typeof(f)
2773            | Expression::Explode(f)
2774            | Expression::ExplodeOuter(f)
2775            | Expression::MapFromEntries(f)
2776            | Expression::MapKeys(f)
2777            | Expression::MapValues(f)
2778            | Expression::ArrayLength(f)
2779            | Expression::ArraySize(f)
2780            | Expression::Cardinality(f)
2781            | Expression::ArrayReverse(f)
2782            | Expression::ArrayDistinct(f)
2783            | Expression::ArrayFlatten(f)
2784            | Expression::ArrayCompact(f)
2785            | Expression::ToArray(f)
2786            | Expression::JsonArrayLength(f)
2787            | Expression::JsonKeys(f)
2788            | Expression::JsonType(f)
2789            | Expression::ParseJson(f)
2790            | Expression::ToJson(f)
2791            | Expression::Radians(f)
2792            | Expression::Degrees(f)
2793            | Expression::Sin(f)
2794            | Expression::Cos(f)
2795            | Expression::Tan(f)
2796            | Expression::Asin(f)
2797            | Expression::Acos(f)
2798            | Expression::Atan(f)
2799            | Expression::IsNan(f)
2800            | Expression::IsInf(f)
2801            | Expression::Year(f)
2802            | Expression::Month(f)
2803            | Expression::Day(f)
2804            | Expression::Hour(f)
2805            | Expression::Minute(f)
2806            | Expression::Second(f)
2807            | Expression::DayOfWeek(f)
2808            | Expression::DayOfWeekIso(f)
2809            | Expression::DayOfMonth(f)
2810            | Expression::DayOfYear(f)
2811            | Expression::WeekOfYear(f)
2812            | Expression::Quarter(f)
2813            | Expression::Epoch(f)
2814            | Expression::EpochMs(f)
2815            | Expression::BitwiseCount(f)
2816            | Expression::DateFromUnixDate(f)
2817            | Expression::UnixDate(f)
2818            | Expression::UnixSeconds(f)
2819            | Expression::UnixMillis(f)
2820            | Expression::UnixMicros(f)
2821            | Expression::TimeStrToDate(f)
2822            | Expression::DateToDi(f)
2823            | Expression::DiToDate(f)
2824            | Expression::TsOrDiToDi(f)
2825            | Expression::TsOrDsToDatetime(f)
2826            | Expression::TsOrDsToTimestamp(f)
2827            | Expression::YearOfWeek(f)
2828            | Expression::YearOfWeekIso(f)
2829            | Expression::SHA(f)
2830            | Expression::SHA1Digest(f)
2831            | Expression::TimeToUnix(f)
2832            | Expression::TimeStrToUnix(f)
2833            | Expression::Int64(f)
2834            | Expression::JSONBool(f)
2835            | Expression::MD5NumberLower64(f)
2836            | Expression::MD5NumberUpper64(f)
2837            | Expression::DateStrToDate(f)
2838            | Expression::DateToDateStr(f) => Some(&f.this),
2839            // BinaryFunc - this is the primary child
2840            Expression::Power(f)
2841            | Expression::NullIf(f)
2842            | Expression::IfNull(f)
2843            | Expression::Nvl(f)
2844            | Expression::Contains(f)
2845            | Expression::StartsWith(f)
2846            | Expression::EndsWith(f)
2847            | Expression::Levenshtein(f)
2848            | Expression::ModFunc(f)
2849            | Expression::IntDiv(f)
2850            | Expression::Atan2(f)
2851            | Expression::AddMonths(f)
2852            | Expression::MonthsBetween(f)
2853            | Expression::NextDay(f)
2854            | Expression::UnixToTimeStr(f)
2855            | Expression::ArrayContains(f)
2856            | Expression::ArrayPosition(f)
2857            | Expression::ArrayAppend(f)
2858            | Expression::ArrayPrepend(f)
2859            | Expression::ArrayUnion(f)
2860            | Expression::ArrayExcept(f)
2861            | Expression::ArrayRemove(f)
2862            | Expression::StarMap(f)
2863            | Expression::MapFromArrays(f)
2864            | Expression::MapContainsKey(f)
2865            | Expression::ElementAt(f)
2866            | Expression::JsonMergePatch(f)
2867            | Expression::JSONBContains(f)
2868            | Expression::JSONBExtract(f) => Some(&f.this),
2869            // AggFunc - this is the primary child
2870            Expression::Sum(af)
2871            | Expression::Avg(af)
2872            | Expression::Min(af)
2873            | Expression::Max(af)
2874            | Expression::ArrayAgg(af)
2875            | Expression::CountIf(af)
2876            | Expression::Stddev(af)
2877            | Expression::StddevPop(af)
2878            | Expression::StddevSamp(af)
2879            | Expression::Variance(af)
2880            | Expression::VarPop(af)
2881            | Expression::VarSamp(af)
2882            | Expression::Median(af)
2883            | Expression::Mode(af)
2884            | Expression::First(af)
2885            | Expression::Last(af)
2886            | Expression::AnyValue(af)
2887            | Expression::ApproxDistinct(af)
2888            | Expression::ApproxCountDistinct(af)
2889            | Expression::LogicalAnd(af)
2890            | Expression::LogicalOr(af)
2891            | Expression::Skewness(af)
2892            | Expression::ArrayConcatAgg(af)
2893            | Expression::ArrayUniqueAgg(af)
2894            | Expression::BoolXorAgg(af)
2895            | Expression::BitwiseAndAgg(af)
2896            | Expression::BitwiseOrAgg(af)
2897            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2898            // Binary operations - left is "this" in sqlglot
2899            Expression::And(op)
2900            | Expression::Or(op)
2901            | Expression::Add(op)
2902            | Expression::Sub(op)
2903            | Expression::Mul(op)
2904            | Expression::Div(op)
2905            | Expression::Mod(op)
2906            | Expression::Eq(op)
2907            | Expression::Neq(op)
2908            | Expression::Lt(op)
2909            | Expression::Lte(op)
2910            | Expression::Gt(op)
2911            | Expression::Gte(op)
2912            | Expression::BitwiseAnd(op)
2913            | Expression::BitwiseOr(op)
2914            | Expression::BitwiseXor(op)
2915            | Expression::Concat(op)
2916            | Expression::Adjacent(op)
2917            | Expression::TsMatch(op)
2918            | Expression::PropertyEQ(op)
2919            | Expression::ArrayContainsAll(op)
2920            | Expression::ArrayContainedBy(op)
2921            | Expression::ArrayOverlaps(op)
2922            | Expression::JSONBContainsAllTopKeys(op)
2923            | Expression::JSONBContainsAnyTopKeys(op)
2924            | Expression::JSONBDeleteAtPath(op)
2925            | Expression::ExtendsLeft(op)
2926            | Expression::ExtendsRight(op)
2927            | Expression::Is(op)
2928            | Expression::MemberOf(op)
2929            | Expression::Match(op)
2930            | Expression::NullSafeEq(op)
2931            | Expression::NullSafeNeq(op)
2932            | Expression::Glob(op)
2933            | Expression::BitwiseLeftShift(op)
2934            | Expression::BitwiseRightShift(op) => Some(&op.left),
2935            // Like operations - left is "this"
2936            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2937            // Structural types with .this
2938            Expression::Alias(a) => Some(&a.this),
2939            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2940            Expression::Paren(p) => Some(&p.this),
2941            Expression::Annotated(a) => Some(&a.this),
2942            Expression::Subquery(s) => Some(&s.this),
2943            Expression::Where(w) => Some(&w.this),
2944            Expression::Having(h) => Some(&h.this),
2945            Expression::Qualify(q) => Some(&q.this),
2946            Expression::IsNull(i) => Some(&i.this),
2947            Expression::Exists(e) => Some(&e.this),
2948            Expression::Ordered(o) => Some(&o.this),
2949            Expression::WindowFunction(wf) => Some(&wf.this),
2950            Expression::Cte(cte) => Some(&cte.this),
2951            Expression::Between(b) => Some(&b.this),
2952            Expression::In(i) => Some(&i.this),
2953            Expression::ReturnStmt(e) => Some(e),
2954            _ => None,
2955        }
2956    }
2957
2958    /// Returns the secondary child expression (".expression" in sqlglot).
2959    pub fn get_expression(&self) -> Option<&Expression> {
2960        match self {
2961            // Binary operations - right is "expression"
2962            Expression::And(op)
2963            | Expression::Or(op)
2964            | Expression::Add(op)
2965            | Expression::Sub(op)
2966            | Expression::Mul(op)
2967            | Expression::Div(op)
2968            | Expression::Mod(op)
2969            | Expression::Eq(op)
2970            | Expression::Neq(op)
2971            | Expression::Lt(op)
2972            | Expression::Lte(op)
2973            | Expression::Gt(op)
2974            | Expression::Gte(op)
2975            | Expression::BitwiseAnd(op)
2976            | Expression::BitwiseOr(op)
2977            | Expression::BitwiseXor(op)
2978            | Expression::Concat(op)
2979            | Expression::Adjacent(op)
2980            | Expression::TsMatch(op)
2981            | Expression::PropertyEQ(op)
2982            | Expression::ArrayContainsAll(op)
2983            | Expression::ArrayContainedBy(op)
2984            | Expression::ArrayOverlaps(op)
2985            | Expression::JSONBContainsAllTopKeys(op)
2986            | Expression::JSONBContainsAnyTopKeys(op)
2987            | Expression::JSONBDeleteAtPath(op)
2988            | Expression::ExtendsLeft(op)
2989            | Expression::ExtendsRight(op)
2990            | Expression::Is(op)
2991            | Expression::MemberOf(op)
2992            | Expression::Match(op)
2993            | Expression::NullSafeEq(op)
2994            | Expression::NullSafeNeq(op)
2995            | Expression::Glob(op)
2996            | Expression::BitwiseLeftShift(op)
2997            | Expression::BitwiseRightShift(op) => Some(&op.right),
2998            // Like operations - right is "expression"
2999            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3000            // BinaryFunc - expression is the secondary
3001            Expression::Power(f)
3002            | Expression::NullIf(f)
3003            | Expression::IfNull(f)
3004            | Expression::Nvl(f)
3005            | Expression::Contains(f)
3006            | Expression::StartsWith(f)
3007            | Expression::EndsWith(f)
3008            | Expression::Levenshtein(f)
3009            | Expression::ModFunc(f)
3010            | Expression::IntDiv(f)
3011            | Expression::Atan2(f)
3012            | Expression::AddMonths(f)
3013            | Expression::MonthsBetween(f)
3014            | Expression::NextDay(f)
3015            | Expression::UnixToTimeStr(f)
3016            | Expression::ArrayContains(f)
3017            | Expression::ArrayPosition(f)
3018            | Expression::ArrayAppend(f)
3019            | Expression::ArrayPrepend(f)
3020            | Expression::ArrayUnion(f)
3021            | Expression::ArrayExcept(f)
3022            | Expression::ArrayRemove(f)
3023            | Expression::StarMap(f)
3024            | Expression::MapFromArrays(f)
3025            | Expression::MapContainsKey(f)
3026            | Expression::ElementAt(f)
3027            | Expression::JsonMergePatch(f)
3028            | Expression::JSONBContains(f)
3029            | Expression::JSONBExtract(f) => Some(&f.expression),
3030            _ => None,
3031        }
3032    }
3033
3034    /// Returns the list of child expressions (".expressions" in sqlglot).
3035    pub fn get_expressions(&self) -> &[Expression] {
3036        match self {
3037            Expression::Select(s) => &s.expressions,
3038            Expression::Function(f) => &f.args,
3039            Expression::AggregateFunction(f) => &f.args,
3040            Expression::From(f) => &f.expressions,
3041            Expression::GroupBy(g) => &g.expressions,
3042            Expression::In(i) => &i.expressions,
3043            Expression::Array(a) => &a.expressions,
3044            Expression::Tuple(t) => &t.expressions,
3045            Expression::Coalesce(f)
3046            | Expression::Greatest(f)
3047            | Expression::Least(f)
3048            | Expression::ArrayConcat(f)
3049            | Expression::ArrayIntersect(f)
3050            | Expression::ArrayZip(f)
3051            | Expression::MapConcat(f)
3052            | Expression::JsonArray(f) => &f.expressions,
3053            _ => &[],
3054        }
3055    }
3056
3057    /// Returns the name of this expression as a string slice.
3058    pub fn get_name(&self) -> &str {
3059        match self {
3060            Expression::Identifier(id) => &id.name,
3061            Expression::Column(col) => &col.name.name,
3062            Expression::Table(t) => &t.name.name,
3063            Expression::Literal(lit) => lit.value_str(),
3064            Expression::Star(_) => "*",
3065            Expression::Function(f) => &f.name,
3066            Expression::AggregateFunction(f) => &f.name,
3067            Expression::Alias(a) => a.this.get_name(),
3068            Expression::Boolean(b) => {
3069                if b.value {
3070                    "TRUE"
3071                } else {
3072                    "FALSE"
3073                }
3074            }
3075            Expression::Null(_) => "NULL",
3076            _ => "",
3077        }
3078    }
3079
3080    /// Returns the alias name if this expression has one.
3081    pub fn get_alias(&self) -> &str {
3082        match self {
3083            Expression::Alias(a) => &a.alias.name,
3084            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3085            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3086            _ => "",
3087        }
3088    }
3089
3090    /// Returns the output name of this expression (what it shows up as in a SELECT).
3091    pub fn get_output_name(&self) -> &str {
3092        match self {
3093            Expression::Alias(a) => &a.alias.name,
3094            Expression::Column(c) => &c.name.name,
3095            Expression::Identifier(id) => &id.name,
3096            Expression::Literal(lit) => lit.value_str(),
3097            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3098            Expression::Star(_) => "*",
3099            _ => "",
3100        }
3101    }
3102
3103    /// Returns comments attached to this expression.
3104    pub fn get_comments(&self) -> Vec<&str> {
3105        match self {
3106            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3107            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3108            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3109            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3110            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3111            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3112            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3113                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3114            }
3115            Expression::And(op)
3116            | Expression::Or(op)
3117            | Expression::Add(op)
3118            | Expression::Sub(op)
3119            | Expression::Mul(op)
3120            | Expression::Div(op)
3121            | Expression::Mod(op)
3122            | Expression::Eq(op)
3123            | Expression::Neq(op)
3124            | Expression::Lt(op)
3125            | Expression::Lte(op)
3126            | Expression::Gt(op)
3127            | Expression::Gte(op)
3128            | Expression::Concat(op)
3129            | Expression::BitwiseAnd(op)
3130            | Expression::BitwiseOr(op)
3131            | Expression::BitwiseXor(op) => {
3132                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3133            }
3134            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3135            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3136            _ => Vec::new(),
3137        }
3138    }
3139}
3140
3141impl fmt::Display for Expression {
3142    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3143        // Basic display - full SQL generation is in generator module
3144        match self {
3145            Expression::Literal(lit) => write!(f, "{}", lit),
3146            Expression::Identifier(id) => write!(f, "{}", id),
3147            Expression::Column(col) => write!(f, "{}", col),
3148            Expression::Star(_) => write!(f, "*"),
3149            Expression::Null(_) => write!(f, "NULL"),
3150            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3151            Expression::Select(_) => write!(f, "SELECT ..."),
3152            _ => write!(f, "{:?}", self),
3153        }
3154    }
3155}
3156
3157/// Represent a SQL literal value.
3158///
3159/// Numeric values are stored as their original text representation (not parsed
3160/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3161/// preserved across round-trips.
3162///
3163/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3164/// strings, raw strings, etc.) each have a dedicated variant so that the
3165/// generator can emit them with the correct syntax.
3166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3167#[cfg_attr(feature = "bindings", derive(TS))]
3168#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3169pub enum Literal {
3170    /// Single-quoted string literal: `'hello'`
3171    String(String),
3172    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3173    Number(String),
3174    /// Hex string literal: `X'FF'`
3175    HexString(String),
3176    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3177    HexNumber(String),
3178    BitString(String),
3179    /// Byte string: b"..." (BigQuery style)
3180    ByteString(String),
3181    /// National string: N'abc'
3182    NationalString(String),
3183    /// DATE literal: DATE '2024-01-15'
3184    Date(String),
3185    /// TIME literal: TIME '10:30:00'
3186    Time(String),
3187    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3188    Timestamp(String),
3189    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3190    Datetime(String),
3191    /// Triple-quoted string: """...""" or '''...'''
3192    /// Contains (content, quote_char) where quote_char is '"' or '\''
3193    TripleQuotedString(String, char),
3194    /// Escape string: E'...' (PostgreSQL)
3195    EscapeString(String),
3196    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3197    DollarString(String),
3198    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3199    /// In raw strings, backslashes are literal and not escape characters.
3200    /// When converting to a regular string, backslashes must be doubled.
3201    RawString(String),
3202}
3203
3204impl Literal {
3205    /// Returns the inner value as a string slice, regardless of literal type.
3206    pub fn value_str(&self) -> &str {
3207        match self {
3208            Literal::String(s)
3209            | Literal::Number(s)
3210            | Literal::HexString(s)
3211            | Literal::HexNumber(s)
3212            | Literal::BitString(s)
3213            | Literal::ByteString(s)
3214            | Literal::NationalString(s)
3215            | Literal::Date(s)
3216            | Literal::Time(s)
3217            | Literal::Timestamp(s)
3218            | Literal::Datetime(s)
3219            | Literal::EscapeString(s)
3220            | Literal::DollarString(s)
3221            | Literal::RawString(s) => s.as_str(),
3222            Literal::TripleQuotedString(s, _) => s.as_str(),
3223        }
3224    }
3225
3226    /// Returns `true` if this is a string-type literal.
3227    pub fn is_string(&self) -> bool {
3228        matches!(
3229            self,
3230            Literal::String(_)
3231                | Literal::NationalString(_)
3232                | Literal::EscapeString(_)
3233                | Literal::DollarString(_)
3234                | Literal::RawString(_)
3235                | Literal::TripleQuotedString(_, _)
3236        )
3237    }
3238
3239    /// Returns `true` if this is a numeric literal.
3240    pub fn is_number(&self) -> bool {
3241        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3242    }
3243}
3244
3245impl fmt::Display for Literal {
3246    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3247        match self {
3248            Literal::String(s) => write!(f, "'{}'", s),
3249            Literal::Number(n) => write!(f, "{}", n),
3250            Literal::HexString(h) => write!(f, "X'{}'", h),
3251            Literal::HexNumber(h) => write!(f, "0x{}", h),
3252            Literal::BitString(b) => write!(f, "B'{}'", b),
3253            Literal::ByteString(b) => write!(f, "b'{}'", b),
3254            Literal::NationalString(s) => write!(f, "N'{}'", s),
3255            Literal::Date(d) => write!(f, "DATE '{}'", d),
3256            Literal::Time(t) => write!(f, "TIME '{}'", t),
3257            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3258            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3259            Literal::TripleQuotedString(s, q) => {
3260                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3261            }
3262            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3263            Literal::DollarString(s) => write!(f, "$${}$$", s),
3264            Literal::RawString(s) => write!(f, "r'{}'", s),
3265        }
3266    }
3267}
3268
3269/// Boolean literal
3270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3271#[cfg_attr(feature = "bindings", derive(TS))]
3272pub struct BooleanLiteral {
3273    pub value: bool,
3274}
3275
3276/// NULL literal
3277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3278#[cfg_attr(feature = "bindings", derive(TS))]
3279pub struct Null;
3280
3281/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3282///
3283/// The `quoted` flag indicates whether the identifier was originally delimited
3284/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3285/// dialect). The generator uses this flag to decide whether to emit quoting
3286/// characters.
3287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3288#[cfg_attr(feature = "bindings", derive(TS))]
3289pub struct Identifier {
3290    /// The raw text of the identifier, without any quoting characters.
3291    pub name: String,
3292    /// Whether the identifier was quoted in the source SQL.
3293    pub quoted: bool,
3294    #[serde(default)]
3295    pub trailing_comments: Vec<String>,
3296    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3297    #[serde(default, skip_serializing_if = "Option::is_none")]
3298    pub span: Option<Span>,
3299}
3300
3301impl Identifier {
3302    pub fn new(name: impl Into<String>) -> Self {
3303        Self {
3304            name: name.into(),
3305            quoted: false,
3306            trailing_comments: Vec::new(),
3307            span: None,
3308        }
3309    }
3310
3311    pub fn quoted(name: impl Into<String>) -> Self {
3312        Self {
3313            name: name.into(),
3314            quoted: true,
3315            trailing_comments: Vec::new(),
3316            span: None,
3317        }
3318    }
3319
3320    pub fn empty() -> Self {
3321        Self {
3322            name: String::new(),
3323            quoted: false,
3324            trailing_comments: Vec::new(),
3325            span: None,
3326        }
3327    }
3328
3329    pub fn is_empty(&self) -> bool {
3330        self.name.is_empty()
3331    }
3332
3333    /// Set the source span on this identifier
3334    pub fn with_span(mut self, span: Span) -> Self {
3335        self.span = Some(span);
3336        self
3337    }
3338}
3339
3340impl fmt::Display for Identifier {
3341    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3342        if self.quoted {
3343            write!(f, "\"{}\"", self.name)
3344        } else {
3345            write!(f, "{}", self.name)
3346        }
3347    }
3348}
3349
3350/// Represent a column reference, optionally qualified by a table name.
3351///
3352/// Renders as `name` when unqualified, or `table.name` when qualified.
3353/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3354/// convenient construction.
3355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3356#[cfg_attr(feature = "bindings", derive(TS))]
3357pub struct Column {
3358    /// The column name.
3359    pub name: Identifier,
3360    /// Optional table qualifier (e.g. `t` in `t.col`).
3361    pub table: Option<Identifier>,
3362    /// Oracle-style join marker (+) for outer joins
3363    #[serde(default)]
3364    pub join_mark: bool,
3365    /// Trailing comments that appeared after this column reference
3366    #[serde(default)]
3367    pub trailing_comments: Vec<String>,
3368    /// Source position span
3369    #[serde(default, skip_serializing_if = "Option::is_none")]
3370    pub span: Option<Span>,
3371    /// Inferred data type from type annotation
3372    #[serde(default, skip_serializing_if = "Option::is_none")]
3373    pub inferred_type: Option<DataType>,
3374}
3375
3376impl fmt::Display for Column {
3377    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3378        if let Some(table) = &self.table {
3379            write!(f, "{}.{}", table, self.name)
3380        } else {
3381            write!(f, "{}", self.name)
3382        }
3383    }
3384}
3385
3386/// Represent a table reference with optional schema and catalog qualifiers.
3387///
3388/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3389/// which qualifiers are present. Supports aliases, column alias lists,
3390/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3391/// several other dialect-specific extensions.
3392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3393#[cfg_attr(feature = "bindings", derive(TS))]
3394pub struct TableRef {
3395    /// The unqualified table name.
3396    pub name: Identifier,
3397    /// Optional schema qualifier (e.g. `public` in `public.users`).
3398    pub schema: Option<Identifier>,
3399    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3400    pub catalog: Option<Identifier>,
3401    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3402    pub alias: Option<Identifier>,
3403    /// Whether AS keyword was explicitly used for the alias
3404    #[serde(default)]
3405    pub alias_explicit_as: bool,
3406    /// Column aliases for table alias: AS t(c1, c2)
3407    #[serde(default)]
3408    pub column_aliases: Vec<Identifier>,
3409    /// Leading comments that appeared before this table reference in a FROM clause
3410    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3411    pub leading_comments: Vec<String>,
3412    /// Trailing comments that appeared after this table reference
3413    #[serde(default)]
3414    pub trailing_comments: Vec<String>,
3415    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3416    #[serde(default)]
3417    pub when: Option<Box<HistoricalData>>,
3418    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3419    #[serde(default)]
3420    pub only: bool,
3421    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3422    #[serde(default)]
3423    pub final_: bool,
3424    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3425    #[serde(default, skip_serializing_if = "Option::is_none")]
3426    pub table_sample: Option<Box<Sample>>,
3427    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3428    #[serde(default)]
3429    pub hints: Vec<Expression>,
3430    /// TSQL: FOR SYSTEM_TIME temporal clause
3431    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3432    #[serde(default, skip_serializing_if = "Option::is_none")]
3433    pub system_time: Option<String>,
3434    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3435    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3436    pub partitions: Vec<Identifier>,
3437    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3438    /// When set, this is used instead of the name field
3439    #[serde(default, skip_serializing_if = "Option::is_none")]
3440    pub identifier_func: Option<Box<Expression>>,
3441    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3442    #[serde(default, skip_serializing_if = "Option::is_none")]
3443    pub changes: Option<Box<Changes>>,
3444    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3445    #[serde(default, skip_serializing_if = "Option::is_none")]
3446    pub version: Option<Box<Version>>,
3447    /// Source position span
3448    #[serde(default, skip_serializing_if = "Option::is_none")]
3449    pub span: Option<Span>,
3450}
3451
3452impl TableRef {
3453    pub fn new(name: impl Into<String>) -> Self {
3454        Self {
3455            name: Identifier::new(name),
3456            schema: None,
3457            catalog: None,
3458            alias: None,
3459            alias_explicit_as: false,
3460            column_aliases: Vec::new(),
3461            leading_comments: Vec::new(),
3462            trailing_comments: Vec::new(),
3463            when: None,
3464            only: false,
3465            final_: false,
3466            table_sample: None,
3467            hints: Vec::new(),
3468            system_time: None,
3469            partitions: Vec::new(),
3470            identifier_func: None,
3471            changes: None,
3472            version: None,
3473            span: None,
3474        }
3475    }
3476
3477    /// Create with a schema qualifier.
3478    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3479        let mut t = Self::new(name);
3480        t.schema = Some(Identifier::new(schema));
3481        t
3482    }
3483
3484    /// Create with catalog and schema qualifiers.
3485    pub fn new_with_catalog(
3486        name: impl Into<String>,
3487        schema: impl Into<String>,
3488        catalog: impl Into<String>,
3489    ) -> Self {
3490        let mut t = Self::new(name);
3491        t.schema = Some(Identifier::new(schema));
3492        t.catalog = Some(Identifier::new(catalog));
3493        t
3494    }
3495
3496    /// Create from an Identifier, preserving the quoted flag
3497    pub fn from_identifier(name: Identifier) -> Self {
3498        Self {
3499            name,
3500            schema: None,
3501            catalog: None,
3502            alias: None,
3503            alias_explicit_as: false,
3504            column_aliases: Vec::new(),
3505            leading_comments: Vec::new(),
3506            trailing_comments: Vec::new(),
3507            when: None,
3508            only: false,
3509            final_: false,
3510            table_sample: None,
3511            hints: Vec::new(),
3512            system_time: None,
3513            partitions: Vec::new(),
3514            identifier_func: None,
3515            changes: None,
3516            version: None,
3517            span: None,
3518        }
3519    }
3520
3521    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3522        self.alias = Some(Identifier::new(alias));
3523        self
3524    }
3525
3526    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3527        self.schema = Some(Identifier::new(schema));
3528        self
3529    }
3530}
3531
3532/// Represent a wildcard star expression (`*`, `table.*`).
3533///
3534/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3535/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3537#[cfg_attr(feature = "bindings", derive(TS))]
3538pub struct Star {
3539    /// Optional table qualifier (e.g. `t` in `t.*`).
3540    pub table: Option<Identifier>,
3541    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3542    pub except: Option<Vec<Identifier>>,
3543    /// REPLACE expressions (BigQuery, Snowflake)
3544    pub replace: Option<Vec<Alias>>,
3545    /// RENAME columns (Snowflake)
3546    pub rename: Option<Vec<(Identifier, Identifier)>>,
3547    /// Trailing comments that appeared after the star
3548    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3549    pub trailing_comments: Vec<String>,
3550    /// Source position span
3551    #[serde(default, skip_serializing_if = "Option::is_none")]
3552    pub span: Option<Span>,
3553}
3554
3555/// Represent a complete SELECT statement.
3556///
3557/// This is the most feature-rich AST node, covering the full surface area of
3558/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3559/// `Vec` are omitted from the generated SQL when absent.
3560///
3561/// # Key Fields
3562///
3563/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3564/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3565/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3566/// - `where_clause` -- the WHERE predicate.
3567/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3568/// - `having` -- HAVING predicate.
3569/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3570/// - `limit` / `offset` / `fetch` -- result set limiting.
3571/// - `with` -- Common Table Expressions (CTEs).
3572/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3573/// - `windows` -- named window definitions (WINDOW w AS ...).
3574///
3575/// Dialect-specific extensions are supported via fields like `prewhere`
3576/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3577/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3579#[cfg_attr(feature = "bindings", derive(TS))]
3580pub struct Select {
3581    /// The select-list: columns, expressions, aliases, and wildcards.
3582    pub expressions: Vec<Expression>,
3583    /// The FROM clause, containing one or more table sources.
3584    pub from: Option<From>,
3585    /// JOIN clauses applied after the FROM source.
3586    pub joins: Vec<Join>,
3587    pub lateral_views: Vec<LateralView>,
3588    /// ClickHouse PREWHERE clause
3589    #[serde(default, skip_serializing_if = "Option::is_none")]
3590    pub prewhere: Option<Expression>,
3591    pub where_clause: Option<Where>,
3592    pub group_by: Option<GroupBy>,
3593    pub having: Option<Having>,
3594    pub qualify: Option<Qualify>,
3595    pub order_by: Option<OrderBy>,
3596    pub distribute_by: Option<DistributeBy>,
3597    pub cluster_by: Option<ClusterBy>,
3598    pub sort_by: Option<SortBy>,
3599    pub limit: Option<Limit>,
3600    pub offset: Option<Offset>,
3601    /// ClickHouse LIMIT BY clause expressions
3602    #[serde(default, skip_serializing_if = "Option::is_none")]
3603    pub limit_by: Option<Vec<Expression>>,
3604    pub fetch: Option<Fetch>,
3605    pub distinct: bool,
3606    pub distinct_on: Option<Vec<Expression>>,
3607    pub top: Option<Top>,
3608    pub with: Option<With>,
3609    pub sample: Option<Sample>,
3610    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3611    #[serde(default, skip_serializing_if = "Option::is_none")]
3612    pub settings: Option<Vec<Expression>>,
3613    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3614    #[serde(default, skip_serializing_if = "Option::is_none")]
3615    pub format: Option<Expression>,
3616    pub windows: Option<Vec<NamedWindow>>,
3617    pub hint: Option<Hint>,
3618    /// Oracle CONNECT BY clause for hierarchical queries
3619    pub connect: Option<Connect>,
3620    /// SELECT ... INTO table_name for creating tables
3621    pub into: Option<SelectInto>,
3622    /// FOR UPDATE/SHARE locking clauses
3623    #[serde(default)]
3624    pub locks: Vec<Lock>,
3625    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3626    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3627    pub for_xml: Vec<Expression>,
3628    /// Leading comments before the statement
3629    #[serde(default)]
3630    pub leading_comments: Vec<String>,
3631    /// Comments that appear after SELECT keyword (before expressions)
3632    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub post_select_comments: Vec<String>,
3635    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3636    #[serde(default, skip_serializing_if = "Option::is_none")]
3637    pub kind: Option<String>,
3638    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3639    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3640    pub operation_modifiers: Vec<String>,
3641    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3642    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3643    pub qualify_after_window: bool,
3644    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3645    #[serde(default, skip_serializing_if = "Option::is_none")]
3646    pub option: Option<String>,
3647    /// Redshift-style EXCLUDE clause at the end of the projection list
3648    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3649    #[serde(default, skip_serializing_if = "Option::is_none")]
3650    pub exclude: Option<Vec<Expression>>,
3651}
3652
3653impl Select {
3654    pub fn new() -> Self {
3655        Self {
3656            expressions: Vec::new(),
3657            from: None,
3658            joins: Vec::new(),
3659            lateral_views: Vec::new(),
3660            prewhere: None,
3661            where_clause: None,
3662            group_by: None,
3663            having: None,
3664            qualify: None,
3665            order_by: None,
3666            distribute_by: None,
3667            cluster_by: None,
3668            sort_by: None,
3669            limit: None,
3670            offset: None,
3671            limit_by: None,
3672            fetch: None,
3673            distinct: false,
3674            distinct_on: None,
3675            top: None,
3676            with: None,
3677            sample: None,
3678            settings: None,
3679            format: None,
3680            windows: None,
3681            hint: None,
3682            connect: None,
3683            into: None,
3684            locks: Vec::new(),
3685            for_xml: Vec::new(),
3686            leading_comments: Vec::new(),
3687            post_select_comments: Vec::new(),
3688            kind: None,
3689            operation_modifiers: Vec::new(),
3690            qualify_after_window: false,
3691            option: None,
3692            exclude: None,
3693        }
3694    }
3695
3696    /// Add a column to select
3697    pub fn column(mut self, expr: Expression) -> Self {
3698        self.expressions.push(expr);
3699        self
3700    }
3701
3702    /// Set the FROM clause
3703    pub fn from(mut self, table: Expression) -> Self {
3704        self.from = Some(From {
3705            expressions: vec![table],
3706        });
3707        self
3708    }
3709
3710    /// Add a WHERE clause
3711    pub fn where_(mut self, condition: Expression) -> Self {
3712        self.where_clause = Some(Where { this: condition });
3713        self
3714    }
3715
3716    /// Set DISTINCT
3717    pub fn distinct(mut self) -> Self {
3718        self.distinct = true;
3719        self
3720    }
3721
3722    /// Add a JOIN
3723    pub fn join(mut self, join: Join) -> Self {
3724        self.joins.push(join);
3725        self
3726    }
3727
3728    /// Set ORDER BY
3729    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3730        self.order_by = Some(OrderBy {
3731            expressions,
3732            siblings: false,
3733            comments: Vec::new(),
3734        });
3735        self
3736    }
3737
3738    /// Set LIMIT
3739    pub fn limit(mut self, n: Expression) -> Self {
3740        self.limit = Some(Limit {
3741            this: n,
3742            percent: false,
3743            comments: Vec::new(),
3744        });
3745        self
3746    }
3747
3748    /// Set OFFSET
3749    pub fn offset(mut self, n: Expression) -> Self {
3750        self.offset = Some(Offset {
3751            this: n,
3752            rows: None,
3753        });
3754        self
3755    }
3756}
3757
3758impl Default for Select {
3759    fn default() -> Self {
3760        Self::new()
3761    }
3762}
3763
3764/// Represent a UNION set operation between two query expressions.
3765///
3766/// When `all` is true, duplicate rows are preserved (UNION ALL).
3767/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3768/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3770#[cfg_attr(feature = "bindings", derive(TS))]
3771pub struct Union {
3772    /// The left-hand query operand.
3773    pub left: Expression,
3774    /// The right-hand query operand.
3775    pub right: Expression,
3776    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3777    pub all: bool,
3778    /// Whether DISTINCT was explicitly specified
3779    #[serde(default)]
3780    pub distinct: bool,
3781    /// Optional WITH clause
3782    pub with: Option<With>,
3783    /// ORDER BY applied to entire UNION result
3784    pub order_by: Option<OrderBy>,
3785    /// LIMIT applied to entire UNION result
3786    pub limit: Option<Box<Expression>>,
3787    /// OFFSET applied to entire UNION result
3788    pub offset: Option<Box<Expression>>,
3789    /// DISTRIBUTE BY clause (Hive/Spark)
3790    #[serde(default, skip_serializing_if = "Option::is_none")]
3791    pub distribute_by: Option<DistributeBy>,
3792    /// SORT BY clause (Hive/Spark)
3793    #[serde(default, skip_serializing_if = "Option::is_none")]
3794    pub sort_by: Option<SortBy>,
3795    /// CLUSTER BY clause (Hive/Spark)
3796    #[serde(default, skip_serializing_if = "Option::is_none")]
3797    pub cluster_by: Option<ClusterBy>,
3798    /// DuckDB BY NAME modifier
3799    #[serde(default)]
3800    pub by_name: bool,
3801    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3802    #[serde(default, skip_serializing_if = "Option::is_none")]
3803    pub side: Option<String>,
3804    /// BigQuery: Set operation kind (INNER)
3805    #[serde(default, skip_serializing_if = "Option::is_none")]
3806    pub kind: Option<String>,
3807    /// BigQuery: CORRESPONDING modifier
3808    #[serde(default)]
3809    pub corresponding: bool,
3810    /// BigQuery: STRICT modifier (before CORRESPONDING)
3811    #[serde(default)]
3812    pub strict: bool,
3813    /// BigQuery: BY (columns) after CORRESPONDING
3814    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3815    pub on_columns: Vec<Expression>,
3816}
3817
3818/// Represent an INTERSECT set operation between two query expressions.
3819///
3820/// Returns only rows that appear in both operands. When `all` is true,
3821/// duplicates are preserved according to their multiplicity.
3822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3823#[cfg_attr(feature = "bindings", derive(TS))]
3824pub struct Intersect {
3825    /// The left-hand query operand.
3826    pub left: Expression,
3827    /// The right-hand query operand.
3828    pub right: Expression,
3829    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3830    pub all: bool,
3831    /// Whether DISTINCT was explicitly specified
3832    #[serde(default)]
3833    pub distinct: bool,
3834    /// Optional WITH clause
3835    pub with: Option<With>,
3836    /// ORDER BY applied to entire INTERSECT result
3837    pub order_by: Option<OrderBy>,
3838    /// LIMIT applied to entire INTERSECT result
3839    pub limit: Option<Box<Expression>>,
3840    /// OFFSET applied to entire INTERSECT result
3841    pub offset: Option<Box<Expression>>,
3842    /// DISTRIBUTE BY clause (Hive/Spark)
3843    #[serde(default, skip_serializing_if = "Option::is_none")]
3844    pub distribute_by: Option<DistributeBy>,
3845    /// SORT BY clause (Hive/Spark)
3846    #[serde(default, skip_serializing_if = "Option::is_none")]
3847    pub sort_by: Option<SortBy>,
3848    /// CLUSTER BY clause (Hive/Spark)
3849    #[serde(default, skip_serializing_if = "Option::is_none")]
3850    pub cluster_by: Option<ClusterBy>,
3851    /// DuckDB BY NAME modifier
3852    #[serde(default)]
3853    pub by_name: bool,
3854    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3855    #[serde(default, skip_serializing_if = "Option::is_none")]
3856    pub side: Option<String>,
3857    /// BigQuery: Set operation kind (INNER)
3858    #[serde(default, skip_serializing_if = "Option::is_none")]
3859    pub kind: Option<String>,
3860    /// BigQuery: CORRESPONDING modifier
3861    #[serde(default)]
3862    pub corresponding: bool,
3863    /// BigQuery: STRICT modifier (before CORRESPONDING)
3864    #[serde(default)]
3865    pub strict: bool,
3866    /// BigQuery: BY (columns) after CORRESPONDING
3867    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3868    pub on_columns: Vec<Expression>,
3869}
3870
3871/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3872///
3873/// Returns rows from the left operand that do not appear in the right operand.
3874/// When `all` is true, duplicates are subtracted according to their multiplicity.
3875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3876#[cfg_attr(feature = "bindings", derive(TS))]
3877pub struct Except {
3878    /// The left-hand query operand.
3879    pub left: Expression,
3880    /// The right-hand query operand (rows to subtract).
3881    pub right: Expression,
3882    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3883    pub all: bool,
3884    /// Whether DISTINCT was explicitly specified
3885    #[serde(default)]
3886    pub distinct: bool,
3887    /// Optional WITH clause
3888    pub with: Option<With>,
3889    /// ORDER BY applied to entire EXCEPT result
3890    pub order_by: Option<OrderBy>,
3891    /// LIMIT applied to entire EXCEPT result
3892    pub limit: Option<Box<Expression>>,
3893    /// OFFSET applied to entire EXCEPT result
3894    pub offset: Option<Box<Expression>>,
3895    /// DISTRIBUTE BY clause (Hive/Spark)
3896    #[serde(default, skip_serializing_if = "Option::is_none")]
3897    pub distribute_by: Option<DistributeBy>,
3898    /// SORT BY clause (Hive/Spark)
3899    #[serde(default, skip_serializing_if = "Option::is_none")]
3900    pub sort_by: Option<SortBy>,
3901    /// CLUSTER BY clause (Hive/Spark)
3902    #[serde(default, skip_serializing_if = "Option::is_none")]
3903    pub cluster_by: Option<ClusterBy>,
3904    /// DuckDB BY NAME modifier
3905    #[serde(default)]
3906    pub by_name: bool,
3907    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3908    #[serde(default, skip_serializing_if = "Option::is_none")]
3909    pub side: Option<String>,
3910    /// BigQuery: Set operation kind (INNER)
3911    #[serde(default, skip_serializing_if = "Option::is_none")]
3912    pub kind: Option<String>,
3913    /// BigQuery: CORRESPONDING modifier
3914    #[serde(default)]
3915    pub corresponding: bool,
3916    /// BigQuery: STRICT modifier (before CORRESPONDING)
3917    #[serde(default)]
3918    pub strict: bool,
3919    /// BigQuery: BY (columns) after CORRESPONDING
3920    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3921    pub on_columns: Vec<Expression>,
3922}
3923
3924/// INTO clause for SELECT INTO statements
3925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3926#[cfg_attr(feature = "bindings", derive(TS))]
3927pub struct SelectInto {
3928    /// Target table or variable (used when single target)
3929    pub this: Expression,
3930    /// Whether TEMPORARY keyword was used
3931    #[serde(default)]
3932    pub temporary: bool,
3933    /// Whether UNLOGGED keyword was used (PostgreSQL)
3934    #[serde(default)]
3935    pub unlogged: bool,
3936    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3937    #[serde(default)]
3938    pub bulk_collect: bool,
3939    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3940    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3941    pub expressions: Vec<Expression>,
3942}
3943
3944/// Represent a parenthesized subquery expression.
3945///
3946/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3947/// parentheses and optionally applies an alias, column aliases, ORDER BY,
3948/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
3949/// modifiers are rendered inside or outside the parentheses.
3950///
3951/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
3952/// scalar subqueries in select-lists, and derived tables.
3953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3954#[cfg_attr(feature = "bindings", derive(TS))]
3955pub struct Subquery {
3956    /// The inner query expression.
3957    pub this: Expression,
3958    /// Optional alias for the derived table.
3959    pub alias: Option<Identifier>,
3960    /// Optional column aliases: AS t(c1, c2)
3961    pub column_aliases: Vec<Identifier>,
3962    /// ORDER BY clause (for parenthesized queries)
3963    pub order_by: Option<OrderBy>,
3964    /// LIMIT clause
3965    pub limit: Option<Limit>,
3966    /// OFFSET clause
3967    pub offset: Option<Offset>,
3968    /// DISTRIBUTE BY clause (Hive/Spark)
3969    #[serde(default, skip_serializing_if = "Option::is_none")]
3970    pub distribute_by: Option<DistributeBy>,
3971    /// SORT BY clause (Hive/Spark)
3972    #[serde(default, skip_serializing_if = "Option::is_none")]
3973    pub sort_by: Option<SortBy>,
3974    /// CLUSTER BY clause (Hive/Spark)
3975    #[serde(default, skip_serializing_if = "Option::is_none")]
3976    pub cluster_by: Option<ClusterBy>,
3977    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
3978    #[serde(default)]
3979    pub lateral: bool,
3980    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
3981    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
3982    /// false: (SELECT 1) LIMIT 1 - modifiers outside
3983    #[serde(default)]
3984    pub modifiers_inside: bool,
3985    /// Trailing comments after the closing paren
3986    #[serde(default)]
3987    pub trailing_comments: Vec<String>,
3988    /// Inferred data type from type annotation
3989    #[serde(default, skip_serializing_if = "Option::is_none")]
3990    pub inferred_type: Option<DataType>,
3991}
3992
3993/// Pipe operator expression: query |> transform
3994///
3995/// Used in DataFusion and BigQuery pipe syntax:
3996///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
3997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3998#[cfg_attr(feature = "bindings", derive(TS))]
3999pub struct PipeOperator {
4000    /// The input query/expression (left side of |>)
4001    pub this: Expression,
4002    /// The piped operation (right side of |>)
4003    pub expression: Expression,
4004}
4005
4006/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4008#[cfg_attr(feature = "bindings", derive(TS))]
4009pub struct Values {
4010    /// The rows of values
4011    pub expressions: Vec<Tuple>,
4012    /// Optional alias for the table
4013    pub alias: Option<Identifier>,
4014    /// Optional column aliases: AS t(c1, c2)
4015    pub column_aliases: Vec<Identifier>,
4016}
4017
4018/// PIVOT operation - supports both standard and DuckDB simplified syntax
4019///
4020/// Standard syntax (in FROM clause):
4021///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4022///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4023///
4024/// DuckDB simplified syntax (statement-level):
4025///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4026///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4028#[cfg_attr(feature = "bindings", derive(TS))]
4029pub struct Pivot {
4030    /// Source table/expression
4031    pub this: Expression,
4032    /// For standard PIVOT: the aggregation function(s) (first is primary)
4033    /// For DuckDB simplified: unused (use `using` instead)
4034    #[serde(default)]
4035    pub expressions: Vec<Expression>,
4036    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4037    #[serde(default)]
4038    pub fields: Vec<Expression>,
4039    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4040    #[serde(default)]
4041    pub using: Vec<Expression>,
4042    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4043    #[serde(default)]
4044    pub group: Option<Box<Expression>>,
4045    /// Whether this is an UNPIVOT (vs PIVOT)
4046    #[serde(default)]
4047    pub unpivot: bool,
4048    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4049    #[serde(default)]
4050    pub into: Option<Box<Expression>>,
4051    /// Optional alias
4052    #[serde(default)]
4053    pub alias: Option<Identifier>,
4054    /// Include/exclude nulls (for UNPIVOT)
4055    #[serde(default)]
4056    pub include_nulls: Option<bool>,
4057    /// Default on null value (Snowflake)
4058    #[serde(default)]
4059    pub default_on_null: Option<Box<Expression>>,
4060    /// WITH clause (CTEs)
4061    #[serde(default, skip_serializing_if = "Option::is_none")]
4062    pub with: Option<With>,
4063}
4064
4065/// UNPIVOT operation
4066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4067#[cfg_attr(feature = "bindings", derive(TS))]
4068pub struct Unpivot {
4069    pub this: Expression,
4070    pub value_column: Identifier,
4071    pub name_column: Identifier,
4072    pub columns: Vec<Expression>,
4073    pub alias: Option<Identifier>,
4074    /// Whether the value_column was parenthesized in the original SQL
4075    #[serde(default)]
4076    pub value_column_parenthesized: bool,
4077    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4078    #[serde(default)]
4079    pub include_nulls: Option<bool>,
4080    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4081    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4082    pub extra_value_columns: Vec<Identifier>,
4083}
4084
4085/// PIVOT alias for aliasing pivot expressions
4086/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4088#[cfg_attr(feature = "bindings", derive(TS))]
4089pub struct PivotAlias {
4090    pub this: Expression,
4091    pub alias: Expression,
4092}
4093
4094/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4096#[cfg_attr(feature = "bindings", derive(TS))]
4097pub struct PreWhere {
4098    pub this: Expression,
4099}
4100
4101/// STREAM definition (Snowflake) - for change data capture
4102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4103#[cfg_attr(feature = "bindings", derive(TS))]
4104pub struct Stream {
4105    pub this: Expression,
4106    #[serde(skip_serializing_if = "Option::is_none")]
4107    pub on: Option<Expression>,
4108    #[serde(skip_serializing_if = "Option::is_none")]
4109    pub show_initial_rows: Option<bool>,
4110}
4111
4112/// USING DATA clause for data import statements
4113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4114#[cfg_attr(feature = "bindings", derive(TS))]
4115pub struct UsingData {
4116    pub this: Expression,
4117}
4118
4119/// XML Namespace declaration
4120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4121#[cfg_attr(feature = "bindings", derive(TS))]
4122pub struct XmlNamespace {
4123    pub this: Expression,
4124    #[serde(skip_serializing_if = "Option::is_none")]
4125    pub alias: Option<Identifier>,
4126}
4127
4128/// ROW FORMAT clause for Hive/Spark
4129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4130#[cfg_attr(feature = "bindings", derive(TS))]
4131pub struct RowFormat {
4132    pub delimited: bool,
4133    pub fields_terminated_by: Option<String>,
4134    pub collection_items_terminated_by: Option<String>,
4135    pub map_keys_terminated_by: Option<String>,
4136    pub lines_terminated_by: Option<String>,
4137    pub null_defined_as: Option<String>,
4138}
4139
4140/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4142#[cfg_attr(feature = "bindings", derive(TS))]
4143pub struct DirectoryInsert {
4144    pub local: bool,
4145    pub path: String,
4146    pub row_format: Option<RowFormat>,
4147    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4148    #[serde(default)]
4149    pub stored_as: Option<String>,
4150}
4151
4152/// INSERT statement
4153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4154#[cfg_attr(feature = "bindings", derive(TS))]
4155pub struct Insert {
4156    pub table: TableRef,
4157    pub columns: Vec<Identifier>,
4158    pub values: Vec<Vec<Expression>>,
4159    pub query: Option<Expression>,
4160    /// INSERT OVERWRITE for Hive/Spark
4161    pub overwrite: bool,
4162    /// PARTITION clause for Hive/Spark
4163    pub partition: Vec<(Identifier, Option<Expression>)>,
4164    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4165    #[serde(default)]
4166    pub directory: Option<DirectoryInsert>,
4167    /// RETURNING clause (PostgreSQL, SQLite)
4168    #[serde(default)]
4169    pub returning: Vec<Expression>,
4170    /// OUTPUT clause (TSQL)
4171    #[serde(default)]
4172    pub output: Option<OutputClause>,
4173    /// ON CONFLICT clause (PostgreSQL, SQLite)
4174    #[serde(default)]
4175    pub on_conflict: Option<Box<Expression>>,
4176    /// Leading comments before the statement
4177    #[serde(default)]
4178    pub leading_comments: Vec<String>,
4179    /// IF EXISTS clause (Hive)
4180    #[serde(default)]
4181    pub if_exists: bool,
4182    /// WITH clause (CTEs)
4183    #[serde(default)]
4184    pub with: Option<With>,
4185    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4186    #[serde(default)]
4187    pub ignore: bool,
4188    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4189    #[serde(default)]
4190    pub source_alias: Option<Identifier>,
4191    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4192    #[serde(default)]
4193    pub alias: Option<Identifier>,
4194    /// Whether the alias uses explicit AS keyword
4195    #[serde(default)]
4196    pub alias_explicit_as: bool,
4197    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4198    #[serde(default)]
4199    pub default_values: bool,
4200    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4201    #[serde(default)]
4202    pub by_name: bool,
4203    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4204    #[serde(default, skip_serializing_if = "Option::is_none")]
4205    pub conflict_action: Option<String>,
4206    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4207    #[serde(default)]
4208    pub is_replace: bool,
4209    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4210    #[serde(default, skip_serializing_if = "Option::is_none")]
4211    pub hint: Option<Hint>,
4212    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4213    #[serde(default)]
4214    pub replace_where: Option<Box<Expression>>,
4215    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4216    #[serde(default)]
4217    pub source: Option<Box<Expression>>,
4218    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4219    #[serde(default, skip_serializing_if = "Option::is_none")]
4220    pub function_target: Option<Box<Expression>>,
4221    /// ClickHouse: PARTITION BY expr
4222    #[serde(default, skip_serializing_if = "Option::is_none")]
4223    pub partition_by: Option<Box<Expression>>,
4224    /// ClickHouse: SETTINGS key = val, ...
4225    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4226    pub settings: Vec<Expression>,
4227}
4228
4229/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4231#[cfg_attr(feature = "bindings", derive(TS))]
4232pub struct OutputClause {
4233    /// Columns/expressions to output
4234    pub columns: Vec<Expression>,
4235    /// Optional INTO target table or table variable
4236    #[serde(default)]
4237    pub into_table: Option<Expression>,
4238}
4239
4240/// UPDATE statement
4241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4242#[cfg_attr(feature = "bindings", derive(TS))]
4243pub struct Update {
4244    pub table: TableRef,
4245    /// Additional tables for multi-table UPDATE (MySQL syntax)
4246    #[serde(default)]
4247    pub extra_tables: Vec<TableRef>,
4248    /// JOINs attached to the table list (MySQL multi-table syntax)
4249    #[serde(default)]
4250    pub table_joins: Vec<Join>,
4251    pub set: Vec<(Identifier, Expression)>,
4252    pub from_clause: Option<From>,
4253    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4254    #[serde(default)]
4255    pub from_joins: Vec<Join>,
4256    pub where_clause: Option<Where>,
4257    /// RETURNING clause (PostgreSQL, SQLite)
4258    #[serde(default)]
4259    pub returning: Vec<Expression>,
4260    /// OUTPUT clause (TSQL)
4261    #[serde(default)]
4262    pub output: Option<OutputClause>,
4263    /// WITH clause (CTEs)
4264    #[serde(default)]
4265    pub with: Option<With>,
4266    /// Leading comments before the statement
4267    #[serde(default)]
4268    pub leading_comments: Vec<String>,
4269    /// LIMIT clause (MySQL)
4270    #[serde(default)]
4271    pub limit: Option<Expression>,
4272    /// ORDER BY clause (MySQL)
4273    #[serde(default)]
4274    pub order_by: Option<OrderBy>,
4275    /// Whether FROM clause appears before SET (Snowflake syntax)
4276    #[serde(default)]
4277    pub from_before_set: bool,
4278}
4279
4280/// DELETE statement
4281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4282#[cfg_attr(feature = "bindings", derive(TS))]
4283pub struct Delete {
4284    pub table: TableRef,
4285    /// ClickHouse: ON CLUSTER clause for distributed DDL
4286    #[serde(default, skip_serializing_if = "Option::is_none")]
4287    pub on_cluster: Option<OnCluster>,
4288    /// Optional alias for the table
4289    pub alias: Option<Identifier>,
4290    /// Whether the alias was declared with explicit AS keyword
4291    #[serde(default)]
4292    pub alias_explicit_as: bool,
4293    /// PostgreSQL/DuckDB USING clause - additional tables to join
4294    pub using: Vec<TableRef>,
4295    pub where_clause: Option<Where>,
4296    /// OUTPUT clause (TSQL)
4297    #[serde(default)]
4298    pub output: Option<OutputClause>,
4299    /// Leading comments before the statement
4300    #[serde(default)]
4301    pub leading_comments: Vec<String>,
4302    /// WITH clause (CTEs)
4303    #[serde(default)]
4304    pub with: Option<With>,
4305    /// LIMIT clause (MySQL)
4306    #[serde(default)]
4307    pub limit: Option<Expression>,
4308    /// ORDER BY clause (MySQL)
4309    #[serde(default)]
4310    pub order_by: Option<OrderBy>,
4311    /// RETURNING clause (PostgreSQL)
4312    #[serde(default)]
4313    pub returning: Vec<Expression>,
4314    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4315    /// These are the target tables to delete from
4316    #[serde(default)]
4317    pub tables: Vec<TableRef>,
4318    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4319    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4320    #[serde(default)]
4321    pub tables_from_using: bool,
4322    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4323    #[serde(default)]
4324    pub joins: Vec<Join>,
4325    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4326    #[serde(default)]
4327    pub force_index: Option<String>,
4328    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4329    #[serde(default)]
4330    pub no_from: bool,
4331}
4332
4333/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4335#[cfg_attr(feature = "bindings", derive(TS))]
4336pub struct CopyStmt {
4337    /// Target table or query
4338    pub this: Expression,
4339    /// True for FROM (loading into table), false for TO (exporting)
4340    pub kind: bool,
4341    /// Source/destination file(s) or stage
4342    pub files: Vec<Expression>,
4343    /// Copy parameters
4344    #[serde(default)]
4345    pub params: Vec<CopyParameter>,
4346    /// Credentials for external access
4347    #[serde(default)]
4348    pub credentials: Option<Box<Credentials>>,
4349    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4350    #[serde(default)]
4351    pub is_into: bool,
4352    /// Whether parameters are wrapped in WITH (...) syntax
4353    #[serde(default)]
4354    pub with_wrapped: bool,
4355}
4356
4357/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4359#[cfg_attr(feature = "bindings", derive(TS))]
4360pub struct CopyParameter {
4361    pub name: String,
4362    pub value: Option<Expression>,
4363    pub values: Vec<Expression>,
4364    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4365    #[serde(default)]
4366    pub eq: bool,
4367}
4368
4369/// Credentials for external access (S3, Azure, etc.)
4370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4371#[cfg_attr(feature = "bindings", derive(TS))]
4372pub struct Credentials {
4373    pub credentials: Vec<(String, String)>,
4374    pub encryption: Option<String>,
4375    pub storage: Option<String>,
4376}
4377
4378/// PUT statement (Snowflake)
4379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4380#[cfg_attr(feature = "bindings", derive(TS))]
4381pub struct PutStmt {
4382    /// Source file path
4383    pub source: String,
4384    /// Whether source was quoted in the original SQL
4385    #[serde(default)]
4386    pub source_quoted: bool,
4387    /// Target stage
4388    pub target: Expression,
4389    /// PUT parameters
4390    #[serde(default)]
4391    pub params: Vec<CopyParameter>,
4392}
4393
4394/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4396#[cfg_attr(feature = "bindings", derive(TS))]
4397pub struct StageReference {
4398    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4399    pub name: String,
4400    /// Optional path within the stage (e.g., "/path/to/file.csv")
4401    #[serde(default)]
4402    pub path: Option<String>,
4403    /// Optional FILE_FORMAT parameter
4404    #[serde(default)]
4405    pub file_format: Option<Expression>,
4406    /// Optional PATTERN parameter
4407    #[serde(default)]
4408    pub pattern: Option<String>,
4409    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4410    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4411    pub quoted: bool,
4412}
4413
4414/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4416#[cfg_attr(feature = "bindings", derive(TS))]
4417pub struct HistoricalData {
4418    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4419    pub this: Box<Expression>,
4420    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4421    pub kind: String,
4422    /// The expression value (e.g., the statement ID or timestamp)
4423    pub expression: Box<Expression>,
4424}
4425
4426/// Represent an aliased expression (`expr AS name`).
4427///
4428/// Used for column aliases in select-lists, table aliases on subqueries,
4429/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4431#[cfg_attr(feature = "bindings", derive(TS))]
4432pub struct Alias {
4433    /// The expression being aliased.
4434    pub this: Expression,
4435    /// The alias name (required for simple aliases, optional when only column aliases provided)
4436    pub alias: Identifier,
4437    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4438    #[serde(default)]
4439    pub column_aliases: Vec<Identifier>,
4440    /// Comments that appeared between the expression and AS keyword
4441    #[serde(default)]
4442    pub pre_alias_comments: Vec<String>,
4443    /// Trailing comments that appeared after the alias
4444    #[serde(default)]
4445    pub trailing_comments: Vec<String>,
4446    /// Inferred data type from type annotation
4447    #[serde(default, skip_serializing_if = "Option::is_none")]
4448    pub inferred_type: Option<DataType>,
4449}
4450
4451impl Alias {
4452    /// Create a simple alias
4453    pub fn new(this: Expression, alias: Identifier) -> Self {
4454        Self {
4455            this,
4456            alias,
4457            column_aliases: Vec::new(),
4458            pre_alias_comments: Vec::new(),
4459            trailing_comments: Vec::new(),
4460            inferred_type: None,
4461        }
4462    }
4463
4464    /// Create an alias with column aliases only (no table alias name)
4465    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4466        Self {
4467            this,
4468            alias: Identifier::empty(),
4469            column_aliases,
4470            pre_alias_comments: Vec::new(),
4471            trailing_comments: Vec::new(),
4472            inferred_type: None,
4473        }
4474    }
4475}
4476
4477/// Represent a type cast expression.
4478///
4479/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4480/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4481/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4482/// CONVERSION ERROR (Oracle) clauses.
4483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4484#[cfg_attr(feature = "bindings", derive(TS))]
4485pub struct Cast {
4486    /// The expression being cast.
4487    pub this: Expression,
4488    /// The target data type.
4489    pub to: DataType,
4490    #[serde(default)]
4491    pub trailing_comments: Vec<String>,
4492    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4493    #[serde(default)]
4494    pub double_colon_syntax: bool,
4495    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4496    #[serde(skip_serializing_if = "Option::is_none", default)]
4497    pub format: Option<Box<Expression>>,
4498    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4499    #[serde(skip_serializing_if = "Option::is_none", default)]
4500    pub default: Option<Box<Expression>>,
4501    /// Inferred data type from type annotation
4502    #[serde(default, skip_serializing_if = "Option::is_none")]
4503    pub inferred_type: Option<DataType>,
4504}
4505
4506///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct CollationExpr {
4510    pub this: Expression,
4511    pub collation: String,
4512    /// True if the collation was single-quoted in the original SQL (string literal)
4513    #[serde(default)]
4514    pub quoted: bool,
4515    /// True if the collation was double-quoted in the original SQL (identifier)
4516    #[serde(default)]
4517    pub double_quoted: bool,
4518}
4519
4520/// Represent a CASE expression (both simple and searched forms).
4521///
4522/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4523/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4524/// Each entry in `whens` is a `(condition, result)` pair.
4525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4526#[cfg_attr(feature = "bindings", derive(TS))]
4527pub struct Case {
4528    /// The operand for simple CASE, or `None` for searched CASE.
4529    pub operand: Option<Expression>,
4530    /// Pairs of (WHEN condition, THEN result).
4531    pub whens: Vec<(Expression, Expression)>,
4532    /// Optional ELSE result.
4533    pub else_: Option<Expression>,
4534    /// Comments from the CASE keyword (emitted after END)
4535    #[serde(default)]
4536    #[serde(skip_serializing_if = "Vec::is_empty")]
4537    pub comments: Vec<String>,
4538    /// Inferred data type from type annotation
4539    #[serde(default, skip_serializing_if = "Option::is_none")]
4540    pub inferred_type: Option<DataType>,
4541}
4542
4543/// Represent a binary operation (two operands separated by an operator).
4544///
4545/// This is the shared payload struct for all binary operator variants in the
4546/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4547/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4548/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4549/// preservation of inline comments around operators.
4550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4551#[cfg_attr(feature = "bindings", derive(TS))]
4552pub struct BinaryOp {
4553    pub left: Expression,
4554    pub right: Expression,
4555    /// Comments after the left operand (before the operator)
4556    #[serde(default)]
4557    pub left_comments: Vec<String>,
4558    /// Comments after the operator (before the right operand)
4559    #[serde(default)]
4560    pub operator_comments: Vec<String>,
4561    /// Comments after the right operand
4562    #[serde(default)]
4563    pub trailing_comments: Vec<String>,
4564    /// Inferred data type from type annotation
4565    #[serde(default, skip_serializing_if = "Option::is_none")]
4566    pub inferred_type: Option<DataType>,
4567}
4568
4569impl BinaryOp {
4570    pub fn new(left: Expression, right: Expression) -> Self {
4571        Self {
4572            left,
4573            right,
4574            left_comments: Vec::new(),
4575            operator_comments: Vec::new(),
4576            trailing_comments: Vec::new(),
4577            inferred_type: None,
4578        }
4579    }
4580}
4581
4582/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4584#[cfg_attr(feature = "bindings", derive(TS))]
4585pub struct LikeOp {
4586    pub left: Expression,
4587    pub right: Expression,
4588    /// ESCAPE character/expression
4589    #[serde(default)]
4590    pub escape: Option<Expression>,
4591    /// Quantifier: ANY, ALL, or SOME
4592    #[serde(default)]
4593    pub quantifier: Option<String>,
4594    /// Inferred data type from type annotation
4595    #[serde(default, skip_serializing_if = "Option::is_none")]
4596    pub inferred_type: Option<DataType>,
4597}
4598
4599impl LikeOp {
4600    pub fn new(left: Expression, right: Expression) -> Self {
4601        Self {
4602            left,
4603            right,
4604            escape: None,
4605            quantifier: None,
4606            inferred_type: None,
4607        }
4608    }
4609
4610    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4611        Self {
4612            left,
4613            right,
4614            escape: Some(escape),
4615            quantifier: None,
4616            inferred_type: None,
4617        }
4618    }
4619}
4620
4621/// Represent a unary operation (single operand with a prefix operator).
4622///
4623/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4625#[cfg_attr(feature = "bindings", derive(TS))]
4626pub struct UnaryOp {
4627    /// The operand expression.
4628    pub this: Expression,
4629    /// Inferred data type from type annotation
4630    #[serde(default, skip_serializing_if = "Option::is_none")]
4631    pub inferred_type: Option<DataType>,
4632}
4633
4634impl UnaryOp {
4635    pub fn new(this: Expression) -> Self {
4636        Self {
4637            this,
4638            inferred_type: None,
4639        }
4640    }
4641}
4642
4643/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4644///
4645/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4646/// but not both. When `not` is true, the predicate is `NOT IN`.
4647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4648#[cfg_attr(feature = "bindings", derive(TS))]
4649pub struct In {
4650    /// The expression being tested.
4651    pub this: Expression,
4652    /// The value list (mutually exclusive with `query`).
4653    pub expressions: Vec<Expression>,
4654    /// A subquery (mutually exclusive with `expressions`).
4655    pub query: Option<Expression>,
4656    /// Whether this is NOT IN.
4657    pub not: bool,
4658    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4659    pub global: bool,
4660    /// BigQuery: IN UNNEST(expr)
4661    #[serde(default, skip_serializing_if = "Option::is_none")]
4662    pub unnest: Option<Box<Expression>>,
4663    /// Whether the right side is a bare field reference (no parentheses).
4664    /// Matches Python sqlglot's `field` attribute on `In` expression.
4665    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4666    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4667    pub is_field: bool,
4668}
4669
4670/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4672#[cfg_attr(feature = "bindings", derive(TS))]
4673pub struct Between {
4674    /// The expression being tested.
4675    pub this: Expression,
4676    /// The lower bound.
4677    pub low: Expression,
4678    /// The upper bound.
4679    pub high: Expression,
4680    /// Whether this is NOT BETWEEN.
4681    pub not: bool,
4682    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4683    #[serde(default)]
4684    pub symmetric: Option<bool>,
4685}
4686
4687/// IS NULL predicate
4688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4689#[cfg_attr(feature = "bindings", derive(TS))]
4690pub struct IsNull {
4691    pub this: Expression,
4692    pub not: bool,
4693    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4694    #[serde(default)]
4695    pub postfix_form: bool,
4696}
4697
4698/// IS TRUE / IS FALSE predicate
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct IsTrueFalse {
4702    pub this: Expression,
4703    pub not: bool,
4704}
4705
4706/// IS JSON predicate (SQL standard)
4707/// Checks if a value is valid JSON
4708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4709#[cfg_attr(feature = "bindings", derive(TS))]
4710pub struct IsJson {
4711    pub this: Expression,
4712    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4713    pub json_type: Option<String>,
4714    /// Key uniqueness constraint
4715    pub unique_keys: Option<JsonUniqueKeys>,
4716    /// Whether IS NOT JSON
4717    pub negated: bool,
4718}
4719
4720/// JSON unique keys constraint variants
4721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4722#[cfg_attr(feature = "bindings", derive(TS))]
4723pub enum JsonUniqueKeys {
4724    /// WITH UNIQUE KEYS
4725    With,
4726    /// WITHOUT UNIQUE KEYS
4727    Without,
4728    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4729    Shorthand,
4730}
4731
4732/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4734#[cfg_attr(feature = "bindings", derive(TS))]
4735pub struct Exists {
4736    /// The subquery expression.
4737    pub this: Expression,
4738    /// Whether this is NOT EXISTS.
4739    pub not: bool,
4740}
4741
4742/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4743///
4744/// This is the generic function node. Well-known aggregates, window functions,
4745/// and built-in functions each have their own dedicated `Expression` variants
4746/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4747/// not recognize as built-ins are represented with this struct.
4748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4749#[cfg_attr(feature = "bindings", derive(TS))]
4750pub struct Function {
4751    /// The function name, as originally written (may be schema-qualified).
4752    pub name: String,
4753    /// Positional arguments to the function.
4754    pub args: Vec<Expression>,
4755    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4756    pub distinct: bool,
4757    #[serde(default)]
4758    pub trailing_comments: Vec<String>,
4759    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4760    #[serde(default)]
4761    pub use_bracket_syntax: bool,
4762    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4763    #[serde(default)]
4764    pub no_parens: bool,
4765    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4766    #[serde(default)]
4767    pub quoted: bool,
4768    /// Source position span
4769    #[serde(default, skip_serializing_if = "Option::is_none")]
4770    pub span: Option<Span>,
4771    /// Inferred data type from type annotation
4772    #[serde(default, skip_serializing_if = "Option::is_none")]
4773    pub inferred_type: Option<DataType>,
4774}
4775
4776impl Default for Function {
4777    fn default() -> Self {
4778        Self {
4779            name: String::new(),
4780            args: Vec::new(),
4781            distinct: false,
4782            trailing_comments: Vec::new(),
4783            use_bracket_syntax: false,
4784            no_parens: false,
4785            quoted: false,
4786            span: None,
4787            inferred_type: None,
4788        }
4789    }
4790}
4791
4792impl Function {
4793    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4794        Self {
4795            name: name.into(),
4796            args,
4797            distinct: false,
4798            trailing_comments: Vec::new(),
4799            use_bracket_syntax: false,
4800            no_parens: false,
4801            quoted: false,
4802            span: None,
4803            inferred_type: None,
4804        }
4805    }
4806}
4807
4808/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4809///
4810/// This struct is used for aggregate function calls that are not covered by
4811/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4812/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4813/// IGNORE NULLS / RESPECT NULLS modifiers.
4814#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4815#[cfg_attr(feature = "bindings", derive(TS))]
4816pub struct AggregateFunction {
4817    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4818    pub name: String,
4819    /// Positional arguments.
4820    pub args: Vec<Expression>,
4821    /// Whether DISTINCT was specified.
4822    pub distinct: bool,
4823    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4824    pub filter: Option<Expression>,
4825    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4826    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4827    pub order_by: Vec<Ordered>,
4828    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4829    #[serde(default, skip_serializing_if = "Option::is_none")]
4830    pub limit: Option<Box<Expression>>,
4831    /// IGNORE NULLS / RESPECT NULLS
4832    #[serde(default, skip_serializing_if = "Option::is_none")]
4833    pub ignore_nulls: Option<bool>,
4834    /// Inferred data type from type annotation
4835    #[serde(default, skip_serializing_if = "Option::is_none")]
4836    pub inferred_type: Option<DataType>,
4837}
4838
4839/// Represent a window function call with its OVER clause.
4840///
4841/// The inner `this` expression is typically a window-specific expression
4842/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4843/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4844/// frame specification.
4845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4846#[cfg_attr(feature = "bindings", derive(TS))]
4847pub struct WindowFunction {
4848    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4849    pub this: Expression,
4850    /// The OVER clause defining the window partitioning, ordering, and frame.
4851    pub over: Over,
4852    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4853    #[serde(default, skip_serializing_if = "Option::is_none")]
4854    pub keep: Option<Keep>,
4855    /// Inferred data type from type annotation
4856    #[serde(default, skip_serializing_if = "Option::is_none")]
4857    pub inferred_type: Option<DataType>,
4858}
4859
4860/// Oracle KEEP clause for aggregate functions
4861/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4863#[cfg_attr(feature = "bindings", derive(TS))]
4864pub struct Keep {
4865    /// true = FIRST, false = LAST
4866    pub first: bool,
4867    /// ORDER BY clause inside KEEP
4868    pub order_by: Vec<Ordered>,
4869}
4870
4871/// WITHIN GROUP clause (for ordered-set aggregate functions)
4872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4873#[cfg_attr(feature = "bindings", derive(TS))]
4874pub struct WithinGroup {
4875    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4876    pub this: Expression,
4877    /// The ORDER BY clause within the group
4878    pub order_by: Vec<Ordered>,
4879}
4880
4881/// Represent the FROM clause of a SELECT statement.
4882///
4883/// Contains one or more table sources (tables, subqueries, table-valued
4884/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4886#[cfg_attr(feature = "bindings", derive(TS))]
4887pub struct From {
4888    /// The table source expressions.
4889    pub expressions: Vec<Expression>,
4890}
4891
4892/// Represent a JOIN clause between two table sources.
4893///
4894/// The join condition can be specified via `on` (ON predicate) or `using`
4895/// (USING column list), but not both. The `kind` field determines the join
4896/// type (INNER, LEFT, CROSS, etc.).
4897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4898#[cfg_attr(feature = "bindings", derive(TS))]
4899pub struct Join {
4900    /// The right-hand table expression being joined.
4901    pub this: Expression,
4902    /// The ON condition (mutually exclusive with `using`).
4903    pub on: Option<Expression>,
4904    /// The USING column list (mutually exclusive with `on`).
4905    pub using: Vec<Identifier>,
4906    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4907    pub kind: JoinKind,
4908    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4909    pub use_inner_keyword: bool,
4910    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4911    pub use_outer_keyword: bool,
4912    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4913    pub deferred_condition: bool,
4914    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4915    #[serde(default, skip_serializing_if = "Option::is_none")]
4916    pub join_hint: Option<String>,
4917    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4918    #[serde(default, skip_serializing_if = "Option::is_none")]
4919    pub match_condition: Option<Expression>,
4920    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4921    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4922    pub pivots: Vec<Expression>,
4923    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4924    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4925    pub comments: Vec<String>,
4926    /// Nesting group identifier for nested join pretty-printing.
4927    /// Joins in the same group were parsed together; group boundaries come from
4928    /// deferred condition resolution phases.
4929    #[serde(default)]
4930    pub nesting_group: usize,
4931    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4932    #[serde(default)]
4933    pub directed: bool,
4934}
4935
4936/// Enumerate all supported SQL join types.
4937///
4938/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4939/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4940/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4941/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4942#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4943#[cfg_attr(feature = "bindings", derive(TS))]
4944pub enum JoinKind {
4945    Inner,
4946    Left,
4947    Right,
4948    Full,
4949    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
4950    Cross,
4951    Natural,
4952    NaturalLeft,
4953    NaturalRight,
4954    NaturalFull,
4955    Semi,
4956    Anti,
4957    // Directional SEMI/ANTI joins
4958    LeftSemi,
4959    LeftAnti,
4960    RightSemi,
4961    RightAnti,
4962    // SQL Server specific
4963    CrossApply,
4964    OuterApply,
4965    // Time-series specific
4966    AsOf,
4967    AsOfLeft,
4968    AsOfRight,
4969    // Lateral join
4970    Lateral,
4971    LeftLateral,
4972    // MySQL specific
4973    Straight,
4974    // Implicit join (comma-separated tables: FROM a, b)
4975    Implicit,
4976    // ClickHouse ARRAY JOIN
4977    Array,
4978    LeftArray,
4979    // ClickHouse PASTE JOIN (positional join)
4980    Paste,
4981    // DuckDB POSITIONAL JOIN
4982    Positional,
4983}
4984
4985impl Default for JoinKind {
4986    fn default() -> Self {
4987        JoinKind::Inner
4988    }
4989}
4990
4991/// Parenthesized table expression with joins
4992/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
4993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4994#[cfg_attr(feature = "bindings", derive(TS))]
4995pub struct JoinedTable {
4996    /// The left-hand side table expression
4997    pub left: Expression,
4998    /// The joins applied to the left table
4999    pub joins: Vec<Join>,
5000    /// LATERAL VIEW clauses (Hive/Spark)
5001    pub lateral_views: Vec<LateralView>,
5002    /// Optional alias for the joined table expression
5003    pub alias: Option<Identifier>,
5004}
5005
5006/// Represent a WHERE clause containing a boolean filter predicate.
5007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5008#[cfg_attr(feature = "bindings", derive(TS))]
5009pub struct Where {
5010    /// The filter predicate expression.
5011    pub this: Expression,
5012}
5013
5014/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5015///
5016/// The `expressions` list may contain plain columns, ordinal positions,
5017/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5019#[cfg_attr(feature = "bindings", derive(TS))]
5020pub struct GroupBy {
5021    /// The grouping expressions.
5022    pub expressions: Vec<Expression>,
5023    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5024    #[serde(default)]
5025    pub all: Option<bool>,
5026    /// ClickHouse: WITH TOTALS modifier
5027    #[serde(default)]
5028    pub totals: bool,
5029    /// Leading comments that appeared before the GROUP BY keyword
5030    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5031    pub comments: Vec<String>,
5032}
5033
5034/// Represent a HAVING clause containing a predicate over aggregate results.
5035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5036#[cfg_attr(feature = "bindings", derive(TS))]
5037pub struct Having {
5038    /// The filter predicate, typically involving aggregate functions.
5039    pub this: Expression,
5040    /// Leading comments that appeared before the HAVING keyword
5041    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5042    pub comments: Vec<String>,
5043}
5044
5045/// Represent an ORDER BY clause containing one or more sort specifications.
5046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5047#[cfg_attr(feature = "bindings", derive(TS))]
5048pub struct OrderBy {
5049    /// The sort specifications, each with direction and null ordering.
5050    pub expressions: Vec<Ordered>,
5051    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5052    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5053    pub siblings: bool,
5054    /// Leading comments that appeared before the ORDER BY keyword
5055    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5056    pub comments: Vec<String>,
5057}
5058
5059/// Represent an expression with sort direction and null ordering.
5060///
5061/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5062/// When `desc` is false the sort is ascending. The `nulls_first` field
5063/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5064/// (database default).
5065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5066#[cfg_attr(feature = "bindings", derive(TS))]
5067pub struct Ordered {
5068    /// The expression to sort by.
5069    pub this: Expression,
5070    /// Whether the sort direction is descending (true) or ascending (false).
5071    pub desc: bool,
5072    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5073    pub nulls_first: Option<bool>,
5074    /// Whether ASC was explicitly written (not just implied)
5075    #[serde(default)]
5076    pub explicit_asc: bool,
5077    /// ClickHouse WITH FILL clause
5078    #[serde(default, skip_serializing_if = "Option::is_none")]
5079    pub with_fill: Option<Box<WithFill>>,
5080}
5081
5082impl Ordered {
5083    pub fn asc(expr: Expression) -> Self {
5084        Self {
5085            this: expr,
5086            desc: false,
5087            nulls_first: None,
5088            explicit_asc: false,
5089            with_fill: None,
5090        }
5091    }
5092
5093    pub fn desc(expr: Expression) -> Self {
5094        Self {
5095            this: expr,
5096            desc: true,
5097            nulls_first: None,
5098            explicit_asc: false,
5099            with_fill: None,
5100        }
5101    }
5102}
5103
5104/// DISTRIBUTE BY clause (Hive/Spark)
5105/// Controls how rows are distributed across reducers
5106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5107#[cfg_attr(feature = "bindings", derive(TS))]
5108#[cfg_attr(feature = "bindings", ts(export))]
5109pub struct DistributeBy {
5110    pub expressions: Vec<Expression>,
5111}
5112
5113/// CLUSTER BY clause (Hive/Spark)
5114/// Combines DISTRIBUTE BY and SORT BY on the same columns
5115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5116#[cfg_attr(feature = "bindings", derive(TS))]
5117#[cfg_attr(feature = "bindings", ts(export))]
5118pub struct ClusterBy {
5119    pub expressions: Vec<Ordered>,
5120}
5121
5122/// SORT BY clause (Hive/Spark)
5123/// Sorts data within each reducer (local sort, not global)
5124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5125#[cfg_attr(feature = "bindings", derive(TS))]
5126#[cfg_attr(feature = "bindings", ts(export))]
5127pub struct SortBy {
5128    pub expressions: Vec<Ordered>,
5129}
5130
5131/// LATERAL VIEW clause (Hive/Spark)
5132/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5134#[cfg_attr(feature = "bindings", derive(TS))]
5135#[cfg_attr(feature = "bindings", ts(export))]
5136pub struct LateralView {
5137    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5138    pub this: Expression,
5139    /// Table alias for the generated table
5140    pub table_alias: Option<Identifier>,
5141    /// Column aliases for the generated columns
5142    pub column_aliases: Vec<Identifier>,
5143    /// OUTER keyword - preserve nulls when input is empty/null
5144    pub outer: bool,
5145}
5146
5147/// Query hint
5148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5149#[cfg_attr(feature = "bindings", derive(TS))]
5150#[cfg_attr(feature = "bindings", ts(export))]
5151pub struct Hint {
5152    pub expressions: Vec<HintExpression>,
5153}
5154
5155/// Individual hint expression
5156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5157#[cfg_attr(feature = "bindings", derive(TS))]
5158#[cfg_attr(feature = "bindings", ts(export))]
5159pub enum HintExpression {
5160    /// Function-style hint: USE_HASH(table)
5161    Function { name: String, args: Vec<Expression> },
5162    /// Simple identifier hint: PARALLEL
5163    Identifier(String),
5164    /// Raw hint text (unparsed)
5165    Raw(String),
5166}
5167
5168/// Pseudocolumn type
5169#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5170#[cfg_attr(feature = "bindings", derive(TS))]
5171#[cfg_attr(feature = "bindings", ts(export))]
5172pub enum PseudocolumnType {
5173    Rownum,      // Oracle ROWNUM
5174    Rowid,       // Oracle ROWID
5175    Level,       // Oracle LEVEL (for CONNECT BY)
5176    Sysdate,     // Oracle SYSDATE
5177    ObjectId,    // Oracle OBJECT_ID
5178    ObjectValue, // Oracle OBJECT_VALUE
5179}
5180
5181impl PseudocolumnType {
5182    pub fn as_str(&self) -> &'static str {
5183        match self {
5184            PseudocolumnType::Rownum => "ROWNUM",
5185            PseudocolumnType::Rowid => "ROWID",
5186            PseudocolumnType::Level => "LEVEL",
5187            PseudocolumnType::Sysdate => "SYSDATE",
5188            PseudocolumnType::ObjectId => "OBJECT_ID",
5189            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5190        }
5191    }
5192
5193    pub fn from_str(s: &str) -> Option<Self> {
5194        match s.to_uppercase().as_str() {
5195            "ROWNUM" => Some(PseudocolumnType::Rownum),
5196            "ROWID" => Some(PseudocolumnType::Rowid),
5197            "LEVEL" => Some(PseudocolumnType::Level),
5198            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5199            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5200            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5201            _ => None,
5202        }
5203    }
5204}
5205
5206/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5207/// These are special identifiers that should not be quoted
5208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5209#[cfg_attr(feature = "bindings", derive(TS))]
5210#[cfg_attr(feature = "bindings", ts(export))]
5211pub struct Pseudocolumn {
5212    pub kind: PseudocolumnType,
5213}
5214
5215impl Pseudocolumn {
5216    pub fn rownum() -> Self {
5217        Self {
5218            kind: PseudocolumnType::Rownum,
5219        }
5220    }
5221
5222    pub fn rowid() -> Self {
5223        Self {
5224            kind: PseudocolumnType::Rowid,
5225        }
5226    }
5227
5228    pub fn level() -> Self {
5229        Self {
5230            kind: PseudocolumnType::Level,
5231        }
5232    }
5233}
5234
5235/// Oracle CONNECT BY clause for hierarchical queries
5236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5237#[cfg_attr(feature = "bindings", derive(TS))]
5238#[cfg_attr(feature = "bindings", ts(export))]
5239pub struct Connect {
5240    /// START WITH condition (optional, can come before or after CONNECT BY)
5241    pub start: Option<Expression>,
5242    /// CONNECT BY condition (required, contains PRIOR references)
5243    pub connect: Expression,
5244    /// NOCYCLE keyword to prevent infinite loops
5245    pub nocycle: bool,
5246}
5247
5248/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5250#[cfg_attr(feature = "bindings", derive(TS))]
5251#[cfg_attr(feature = "bindings", ts(export))]
5252pub struct Prior {
5253    pub this: Expression,
5254}
5255
5256/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5258#[cfg_attr(feature = "bindings", derive(TS))]
5259#[cfg_attr(feature = "bindings", ts(export))]
5260pub struct ConnectByRoot {
5261    pub this: Expression,
5262}
5263
5264/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5266#[cfg_attr(feature = "bindings", derive(TS))]
5267#[cfg_attr(feature = "bindings", ts(export))]
5268pub struct MatchRecognize {
5269    /// Source table/expression
5270    pub this: Option<Box<Expression>>,
5271    /// PARTITION BY expressions
5272    pub partition_by: Option<Vec<Expression>>,
5273    /// ORDER BY expressions
5274    pub order_by: Option<Vec<Ordered>>,
5275    /// MEASURES definitions
5276    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5277    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5278    pub rows: Option<MatchRecognizeRows>,
5279    /// AFTER MATCH SKIP behavior
5280    pub after: Option<MatchRecognizeAfter>,
5281    /// PATTERN definition (stored as raw string for complex regex patterns)
5282    pub pattern: Option<String>,
5283    /// DEFINE clauses (pattern variable definitions)
5284    pub define: Option<Vec<(Identifier, Expression)>>,
5285    /// Optional alias for the result
5286    pub alias: Option<Identifier>,
5287    /// Whether AS keyword was explicitly present before alias
5288    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5289    pub alias_explicit_as: bool,
5290}
5291
5292/// MEASURES expression with optional RUNNING/FINAL semantics
5293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5294#[cfg_attr(feature = "bindings", derive(TS))]
5295#[cfg_attr(feature = "bindings", ts(export))]
5296pub struct MatchRecognizeMeasure {
5297    /// The measure expression
5298    pub this: Expression,
5299    /// RUNNING or FINAL semantics (Snowflake-specific)
5300    pub window_frame: Option<MatchRecognizeSemantics>,
5301}
5302
5303/// Semantics for MEASURES in MATCH_RECOGNIZE
5304#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5305#[cfg_attr(feature = "bindings", derive(TS))]
5306#[cfg_attr(feature = "bindings", ts(export))]
5307pub enum MatchRecognizeSemantics {
5308    Running,
5309    Final,
5310}
5311
5312/// Row output semantics for MATCH_RECOGNIZE
5313#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5314#[cfg_attr(feature = "bindings", derive(TS))]
5315#[cfg_attr(feature = "bindings", ts(export))]
5316pub enum MatchRecognizeRows {
5317    OneRowPerMatch,
5318    AllRowsPerMatch,
5319    AllRowsPerMatchShowEmptyMatches,
5320    AllRowsPerMatchOmitEmptyMatches,
5321    AllRowsPerMatchWithUnmatchedRows,
5322}
5323
5324/// AFTER MATCH SKIP behavior
5325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5326#[cfg_attr(feature = "bindings", derive(TS))]
5327#[cfg_attr(feature = "bindings", ts(export))]
5328pub enum MatchRecognizeAfter {
5329    PastLastRow,
5330    ToNextRow,
5331    ToFirst(Identifier),
5332    ToLast(Identifier),
5333}
5334
5335/// Represent a LIMIT clause that restricts the number of returned rows.
5336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5337#[cfg_attr(feature = "bindings", derive(TS))]
5338pub struct Limit {
5339    /// The limit count expression.
5340    pub this: Expression,
5341    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5342    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5343    pub percent: bool,
5344    /// Comments from before the LIMIT keyword (emitted after the limit value)
5345    #[serde(default)]
5346    #[serde(skip_serializing_if = "Vec::is_empty")]
5347    pub comments: Vec<String>,
5348}
5349
5350/// OFFSET clause
5351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5352#[cfg_attr(feature = "bindings", derive(TS))]
5353pub struct Offset {
5354    pub this: Expression,
5355    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5356    #[serde(skip_serializing_if = "Option::is_none", default)]
5357    pub rows: Option<bool>,
5358}
5359
5360/// TOP clause (SQL Server)
5361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5362#[cfg_attr(feature = "bindings", derive(TS))]
5363pub struct Top {
5364    pub this: Expression,
5365    pub percent: bool,
5366    pub with_ties: bool,
5367    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5368    #[serde(default)]
5369    pub parenthesized: bool,
5370}
5371
5372/// FETCH FIRST/NEXT clause (SQL standard)
5373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5374#[cfg_attr(feature = "bindings", derive(TS))]
5375pub struct Fetch {
5376    /// FIRST or NEXT
5377    pub direction: String,
5378    /// Count expression (optional)
5379    pub count: Option<Expression>,
5380    /// PERCENT modifier
5381    pub percent: bool,
5382    /// ROWS or ROW keyword present
5383    pub rows: bool,
5384    /// WITH TIES modifier
5385    pub with_ties: bool,
5386}
5387
5388/// Represent a QUALIFY clause for filtering on window function results.
5389///
5390/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5391/// typically references a window function (e.g.
5392/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5394#[cfg_attr(feature = "bindings", derive(TS))]
5395pub struct Qualify {
5396    /// The filter predicate over window function results.
5397    pub this: Expression,
5398}
5399
5400/// SAMPLE / TABLESAMPLE clause
5401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5402#[cfg_attr(feature = "bindings", derive(TS))]
5403pub struct Sample {
5404    pub method: SampleMethod,
5405    pub size: Expression,
5406    pub seed: Option<Expression>,
5407    /// ClickHouse OFFSET expression after SAMPLE size
5408    #[serde(default)]
5409    pub offset: Option<Expression>,
5410    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5411    pub unit_after_size: bool,
5412    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5413    #[serde(default)]
5414    pub use_sample_keyword: bool,
5415    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5416    #[serde(default)]
5417    pub explicit_method: bool,
5418    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5419    #[serde(default)]
5420    pub method_before_size: bool,
5421    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5422    #[serde(default)]
5423    pub use_seed_keyword: bool,
5424    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5425    pub bucket_numerator: Option<Box<Expression>>,
5426    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5427    pub bucket_denominator: Option<Box<Expression>>,
5428    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5429    pub bucket_field: Option<Box<Expression>>,
5430    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5431    #[serde(default)]
5432    pub is_using_sample: bool,
5433    /// Whether the unit was explicitly PERCENT (vs ROWS)
5434    #[serde(default)]
5435    pub is_percent: bool,
5436    /// Whether to suppress method output (for cross-dialect transpilation)
5437    #[serde(default)]
5438    pub suppress_method_output: bool,
5439}
5440
5441/// Sample method
5442#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5443#[cfg_attr(feature = "bindings", derive(TS))]
5444pub enum SampleMethod {
5445    Bernoulli,
5446    System,
5447    Block,
5448    Row,
5449    Percent,
5450    /// Hive bucket sampling
5451    Bucket,
5452    /// DuckDB reservoir sampling
5453    Reservoir,
5454}
5455
5456/// Named window definition (WINDOW w AS (...))
5457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5458#[cfg_attr(feature = "bindings", derive(TS))]
5459pub struct NamedWindow {
5460    pub name: Identifier,
5461    pub spec: Over,
5462}
5463
5464/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5465///
5466/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5467/// that reference themselves. Each CTE is defined in the `ctes` vector and
5468/// can be referenced by name in subsequent CTEs and in the main query body.
5469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5470#[cfg_attr(feature = "bindings", derive(TS))]
5471pub struct With {
5472    /// The list of CTE definitions, in order.
5473    pub ctes: Vec<Cte>,
5474    /// Whether the WITH RECURSIVE keyword was used.
5475    pub recursive: bool,
5476    /// Leading comments before the statement
5477    #[serde(default)]
5478    pub leading_comments: Vec<String>,
5479    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5480    #[serde(default, skip_serializing_if = "Option::is_none")]
5481    pub search: Option<Box<Expression>>,
5482}
5483
5484/// Represent a single Common Table Expression definition.
5485///
5486/// A CTE has a name (`alias`), an optional column list, and a body query.
5487/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5488/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5489/// the expression comes before the alias (`alias_first`).
5490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5491#[cfg_attr(feature = "bindings", derive(TS))]
5492pub struct Cte {
5493    /// The CTE name.
5494    pub alias: Identifier,
5495    /// The CTE body (typically a SELECT, UNION, etc.).
5496    pub this: Expression,
5497    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5498    pub columns: Vec<Identifier>,
5499    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5500    pub materialized: Option<bool>,
5501    /// USING KEY (columns) for DuckDB recursive CTEs
5502    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5503    pub key_expressions: Vec<Identifier>,
5504    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5505    #[serde(default)]
5506    pub alias_first: bool,
5507    /// Comments associated with this CTE (placed after alias name, before AS)
5508    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5509    pub comments: Vec<String>,
5510}
5511
5512/// Window specification
5513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5514#[cfg_attr(feature = "bindings", derive(TS))]
5515pub struct WindowSpec {
5516    pub partition_by: Vec<Expression>,
5517    pub order_by: Vec<Ordered>,
5518    pub frame: Option<WindowFrame>,
5519}
5520
5521/// OVER clause
5522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5523#[cfg_attr(feature = "bindings", derive(TS))]
5524pub struct Over {
5525    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5526    pub window_name: Option<Identifier>,
5527    pub partition_by: Vec<Expression>,
5528    pub order_by: Vec<Ordered>,
5529    pub frame: Option<WindowFrame>,
5530    pub alias: Option<Identifier>,
5531}
5532
5533/// Window frame
5534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5535#[cfg_attr(feature = "bindings", derive(TS))]
5536pub struct WindowFrame {
5537    pub kind: WindowFrameKind,
5538    pub start: WindowFrameBound,
5539    pub end: Option<WindowFrameBound>,
5540    pub exclude: Option<WindowFrameExclude>,
5541    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5542    #[serde(default, skip_serializing_if = "Option::is_none")]
5543    pub kind_text: Option<String>,
5544    /// Original text of the start bound side keyword (e.g. "preceding")
5545    #[serde(default, skip_serializing_if = "Option::is_none")]
5546    pub start_side_text: Option<String>,
5547    /// Original text of the end bound side keyword
5548    #[serde(default, skip_serializing_if = "Option::is_none")]
5549    pub end_side_text: Option<String>,
5550}
5551
5552#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5553#[cfg_attr(feature = "bindings", derive(TS))]
5554pub enum WindowFrameKind {
5555    Rows,
5556    Range,
5557    Groups,
5558}
5559
5560/// EXCLUDE clause for window frames
5561#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5562#[cfg_attr(feature = "bindings", derive(TS))]
5563pub enum WindowFrameExclude {
5564    CurrentRow,
5565    Group,
5566    Ties,
5567    NoOthers,
5568}
5569
5570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5571#[cfg_attr(feature = "bindings", derive(TS))]
5572pub enum WindowFrameBound {
5573    CurrentRow,
5574    UnboundedPreceding,
5575    UnboundedFollowing,
5576    Preceding(Box<Expression>),
5577    Following(Box<Expression>),
5578    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5579    BarePreceding,
5580    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5581    BareFollowing,
5582    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5583    Value(Box<Expression>),
5584}
5585
5586/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5588#[cfg_attr(feature = "bindings", derive(TS))]
5589pub struct StructField {
5590    pub name: String,
5591    pub data_type: DataType,
5592    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5593    pub options: Vec<Expression>,
5594    #[serde(default, skip_serializing_if = "Option::is_none")]
5595    pub comment: Option<String>,
5596}
5597
5598impl StructField {
5599    /// Create a new struct field without options
5600    pub fn new(name: String, data_type: DataType) -> Self {
5601        Self {
5602            name,
5603            data_type,
5604            options: Vec::new(),
5605            comment: None,
5606        }
5607    }
5608
5609    /// Create a new struct field with options
5610    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5611        Self {
5612            name,
5613            data_type,
5614            options,
5615            comment: None,
5616        }
5617    }
5618
5619    /// Create a new struct field with options and comment
5620    pub fn with_options_and_comment(
5621        name: String,
5622        data_type: DataType,
5623        options: Vec<Expression>,
5624        comment: Option<String>,
5625    ) -> Self {
5626        Self {
5627            name,
5628            data_type,
5629            options,
5630            comment,
5631        }
5632    }
5633}
5634
5635/// Enumerate all SQL data types recognized by the parser.
5636///
5637/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5638/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5639/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5640///
5641/// This enum is used in CAST expressions, column definitions, function return
5642/// types, and anywhere a data type specification appears in SQL.
5643///
5644/// Types that do not match any known variant fall through to `Custom { name }`,
5645/// preserving the original type name for round-trip fidelity.
5646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5647#[cfg_attr(feature = "bindings", derive(TS))]
5648#[serde(tag = "data_type", rename_all = "snake_case")]
5649pub enum DataType {
5650    // Numeric
5651    Boolean,
5652    TinyInt {
5653        length: Option<u32>,
5654    },
5655    SmallInt {
5656        length: Option<u32>,
5657    },
5658    /// Int type with optional length. `integer_spelling` indicates whether the original
5659    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5660    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5661    Int {
5662        length: Option<u32>,
5663        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5664        integer_spelling: bool,
5665    },
5666    BigInt {
5667        length: Option<u32>,
5668    },
5669    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5670    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5671    /// preserve the original spelling.
5672    Float {
5673        precision: Option<u32>,
5674        scale: Option<u32>,
5675        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5676        real_spelling: bool,
5677    },
5678    Double {
5679        precision: Option<u32>,
5680        scale: Option<u32>,
5681    },
5682    Decimal {
5683        precision: Option<u32>,
5684        scale: Option<u32>,
5685    },
5686
5687    // String
5688    Char {
5689        length: Option<u32>,
5690    },
5691    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5692    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5693    VarChar {
5694        length: Option<u32>,
5695        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5696        parenthesized_length: bool,
5697    },
5698    /// String type with optional max length (BigQuery STRING(n))
5699    String {
5700        length: Option<u32>,
5701    },
5702    Text,
5703    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5704    TextWithLength {
5705        length: u32,
5706    },
5707
5708    // Binary
5709    Binary {
5710        length: Option<u32>,
5711    },
5712    VarBinary {
5713        length: Option<u32>,
5714    },
5715    Blob,
5716
5717    // Bit
5718    Bit {
5719        length: Option<u32>,
5720    },
5721    VarBit {
5722        length: Option<u32>,
5723    },
5724
5725    // Date/Time
5726    Date,
5727    Time {
5728        precision: Option<u32>,
5729        #[serde(default)]
5730        timezone: bool,
5731    },
5732    Timestamp {
5733        precision: Option<u32>,
5734        timezone: bool,
5735    },
5736    Interval {
5737        unit: Option<String>,
5738        /// For range intervals like INTERVAL DAY TO HOUR
5739        #[serde(default, skip_serializing_if = "Option::is_none")]
5740        to: Option<String>,
5741    },
5742
5743    // JSON
5744    Json,
5745    JsonB,
5746
5747    // UUID
5748    Uuid,
5749
5750    // Array
5751    Array {
5752        element_type: Box<DataType>,
5753        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5754        #[serde(default, skip_serializing_if = "Option::is_none")]
5755        dimension: Option<u32>,
5756    },
5757
5758    /// List type (Materialize): INT LIST, TEXT LIST LIST
5759    /// Uses postfix LIST syntax instead of ARRAY<T>
5760    List {
5761        element_type: Box<DataType>,
5762    },
5763
5764    // Struct/Map
5765    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5766    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5767    Struct {
5768        fields: Vec<StructField>,
5769        nested: bool,
5770    },
5771    Map {
5772        key_type: Box<DataType>,
5773        value_type: Box<DataType>,
5774    },
5775
5776    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5777    Enum {
5778        values: Vec<String>,
5779        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5780        assignments: Vec<Option<String>>,
5781    },
5782
5783    // Set type (MySQL): SET('a', 'b', 'c')
5784    Set {
5785        values: Vec<String>,
5786    },
5787
5788    // Union type (DuckDB): UNION(num INT, str TEXT)
5789    Union {
5790        fields: Vec<(String, DataType)>,
5791    },
5792
5793    // Vector (Snowflake / SingleStore)
5794    Vector {
5795        #[serde(default)]
5796        element_type: Option<Box<DataType>>,
5797        dimension: Option<u32>,
5798    },
5799
5800    // Object (Snowflake structured type)
5801    // fields: Vec of (field_name, field_type, not_null)
5802    Object {
5803        fields: Vec<(String, DataType, bool)>,
5804        modifier: Option<String>,
5805    },
5806
5807    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5808    Nullable {
5809        inner: Box<DataType>,
5810    },
5811
5812    // Custom/User-defined
5813    Custom {
5814        name: String,
5815    },
5816
5817    // Spatial types
5818    Geometry {
5819        subtype: Option<String>,
5820        srid: Option<u32>,
5821    },
5822    Geography {
5823        subtype: Option<String>,
5824        srid: Option<u32>,
5825    },
5826
5827    // Character Set (for CONVERT USING in MySQL)
5828    // Renders as CHAR CHARACTER SET {name} in cast target
5829    CharacterSet {
5830        name: String,
5831    },
5832
5833    // Unknown
5834    Unknown,
5835}
5836
5837/// Array expression
5838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5839#[cfg_attr(feature = "bindings", derive(TS))]
5840#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5841pub struct Array {
5842    pub expressions: Vec<Expression>,
5843}
5844
5845/// Struct expression
5846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5847#[cfg_attr(feature = "bindings", derive(TS))]
5848pub struct Struct {
5849    pub fields: Vec<(Option<String>, Expression)>,
5850}
5851
5852/// Tuple expression
5853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5854#[cfg_attr(feature = "bindings", derive(TS))]
5855pub struct Tuple {
5856    pub expressions: Vec<Expression>,
5857}
5858
5859/// Interval expression
5860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5861#[cfg_attr(feature = "bindings", derive(TS))]
5862pub struct Interval {
5863    /// The value expression (e.g., '1', 5, column_ref)
5864    pub this: Option<Expression>,
5865    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5866    pub unit: Option<IntervalUnitSpec>,
5867}
5868
5869/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5871#[cfg_attr(feature = "bindings", derive(TS))]
5872#[serde(tag = "type", rename_all = "snake_case")]
5873pub enum IntervalUnitSpec {
5874    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5875    Simple {
5876        unit: IntervalUnit,
5877        /// Whether to use plural form (e.g., DAYS vs DAY)
5878        use_plural: bool,
5879    },
5880    /// Interval span (e.g., HOUR TO SECOND)
5881    Span(IntervalSpan),
5882    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5883    /// The start and end can be expressions like function calls with precision
5884    ExprSpan(IntervalSpanExpr),
5885    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5886    Expr(Box<Expression>),
5887}
5888
5889/// Interval span for ranges like HOUR TO SECOND
5890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5891#[cfg_attr(feature = "bindings", derive(TS))]
5892pub struct IntervalSpan {
5893    /// Start unit (e.g., HOUR)
5894    pub this: IntervalUnit,
5895    /// End unit (e.g., SECOND)
5896    pub expression: IntervalUnit,
5897}
5898
5899/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5900/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5902#[cfg_attr(feature = "bindings", derive(TS))]
5903pub struct IntervalSpanExpr {
5904    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5905    pub this: Box<Expression>,
5906    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5907    pub expression: Box<Expression>,
5908}
5909
5910#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5911#[cfg_attr(feature = "bindings", derive(TS))]
5912pub enum IntervalUnit {
5913    Year,
5914    Quarter,
5915    Month,
5916    Week,
5917    Day,
5918    Hour,
5919    Minute,
5920    Second,
5921    Millisecond,
5922    Microsecond,
5923    Nanosecond,
5924}
5925
5926/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5928#[cfg_attr(feature = "bindings", derive(TS))]
5929pub struct Command {
5930    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5931    pub this: String,
5932}
5933
5934/// EXEC/EXECUTE statement (TSQL stored procedure call)
5935/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5937#[cfg_attr(feature = "bindings", derive(TS))]
5938pub struct ExecuteStatement {
5939    /// The procedure name (can be qualified: schema.proc_name)
5940    pub this: Expression,
5941    /// Named parameters: @param=value pairs
5942    #[serde(default)]
5943    pub parameters: Vec<ExecuteParameter>,
5944    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
5945    #[serde(default, skip_serializing_if = "Option::is_none")]
5946    pub suffix: Option<String>,
5947}
5948
5949/// Named parameter in EXEC statement: @name=value
5950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5951#[cfg_attr(feature = "bindings", derive(TS))]
5952pub struct ExecuteParameter {
5953    /// Parameter name (including @)
5954    pub name: String,
5955    /// Parameter value
5956    pub value: Expression,
5957    /// Whether this is a positional parameter (no = sign)
5958    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5959    pub positional: bool,
5960    /// TSQL OUTPUT modifier on parameter
5961    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5962    pub output: bool,
5963}
5964
5965/// KILL statement (MySQL/MariaDB)
5966/// KILL [CONNECTION | QUERY] <id>
5967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5968#[cfg_attr(feature = "bindings", derive(TS))]
5969pub struct Kill {
5970    /// The target (process ID or connection ID)
5971    pub this: Expression,
5972    /// Optional kind: "CONNECTION" or "QUERY"
5973    pub kind: Option<String>,
5974}
5975
5976/// Snowflake CREATE TASK statement
5977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5978#[cfg_attr(feature = "bindings", derive(TS))]
5979pub struct CreateTask {
5980    pub or_replace: bool,
5981    pub if_not_exists: bool,
5982    /// Task name (possibly qualified: db.schema.task)
5983    pub name: String,
5984    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
5985    pub properties: String,
5986    /// The SQL statement body after AS
5987    pub body: Expression,
5988}
5989
5990/// Raw/unparsed SQL
5991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5992#[cfg_attr(feature = "bindings", derive(TS))]
5993pub struct Raw {
5994    pub sql: String,
5995}
5996
5997// ============================================================================
5998// Function expression types
5999// ============================================================================
6000
6001/// Generic unary function (takes a single argument)
6002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6003#[cfg_attr(feature = "bindings", derive(TS))]
6004pub struct UnaryFunc {
6005    pub this: Expression,
6006    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6007    #[serde(skip_serializing_if = "Option::is_none", default)]
6008    pub original_name: Option<String>,
6009    /// Inferred data type from type annotation
6010    #[serde(default, skip_serializing_if = "Option::is_none")]
6011    pub inferred_type: Option<DataType>,
6012}
6013
6014impl UnaryFunc {
6015    /// Create a new UnaryFunc with no original_name
6016    pub fn new(this: Expression) -> Self {
6017        Self {
6018            this,
6019            original_name: None,
6020            inferred_type: None,
6021        }
6022    }
6023
6024    /// Create a new UnaryFunc with an original name for round-trip preservation
6025    pub fn with_name(this: Expression, name: String) -> Self {
6026        Self {
6027            this,
6028            original_name: Some(name),
6029            inferred_type: None,
6030        }
6031    }
6032}
6033
6034/// CHAR/CHR function with multiple args and optional USING charset
6035/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6036/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6038#[cfg_attr(feature = "bindings", derive(TS))]
6039pub struct CharFunc {
6040    pub args: Vec<Expression>,
6041    #[serde(skip_serializing_if = "Option::is_none", default)]
6042    pub charset: Option<String>,
6043    /// Original function name (CHAR or CHR), defaults to CHAR
6044    #[serde(skip_serializing_if = "Option::is_none", default)]
6045    pub name: Option<String>,
6046}
6047
6048/// Generic binary function (takes two arguments)
6049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6050#[cfg_attr(feature = "bindings", derive(TS))]
6051pub struct BinaryFunc {
6052    pub this: Expression,
6053    pub expression: Expression,
6054    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6055    #[serde(skip_serializing_if = "Option::is_none", default)]
6056    pub original_name: Option<String>,
6057    /// Inferred data type from type annotation
6058    #[serde(default, skip_serializing_if = "Option::is_none")]
6059    pub inferred_type: Option<DataType>,
6060}
6061
6062/// Variable argument function
6063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6064#[cfg_attr(feature = "bindings", derive(TS))]
6065pub struct VarArgFunc {
6066    pub expressions: Vec<Expression>,
6067    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6068    #[serde(skip_serializing_if = "Option::is_none", default)]
6069    pub original_name: Option<String>,
6070    /// Inferred data type from type annotation
6071    #[serde(default, skip_serializing_if = "Option::is_none")]
6072    pub inferred_type: Option<DataType>,
6073}
6074
6075/// CONCAT_WS function
6076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6077#[cfg_attr(feature = "bindings", derive(TS))]
6078pub struct ConcatWs {
6079    pub separator: Expression,
6080    pub expressions: Vec<Expression>,
6081}
6082
6083/// SUBSTRING function
6084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6085#[cfg_attr(feature = "bindings", derive(TS))]
6086pub struct SubstringFunc {
6087    pub this: Expression,
6088    pub start: Expression,
6089    pub length: Option<Expression>,
6090    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6091    #[serde(default)]
6092    pub from_for_syntax: bool,
6093}
6094
6095/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6097#[cfg_attr(feature = "bindings", derive(TS))]
6098pub struct OverlayFunc {
6099    pub this: Expression,
6100    pub replacement: Expression,
6101    pub from: Expression,
6102    pub length: Option<Expression>,
6103}
6104
6105/// TRIM function
6106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6107#[cfg_attr(feature = "bindings", derive(TS))]
6108pub struct TrimFunc {
6109    pub this: Expression,
6110    pub characters: Option<Expression>,
6111    pub position: TrimPosition,
6112    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6113    #[serde(default)]
6114    pub sql_standard_syntax: bool,
6115    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6116    #[serde(default)]
6117    pub position_explicit: bool,
6118}
6119
6120#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6121#[cfg_attr(feature = "bindings", derive(TS))]
6122pub enum TrimPosition {
6123    Both,
6124    Leading,
6125    Trailing,
6126}
6127
6128/// REPLACE function
6129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6130#[cfg_attr(feature = "bindings", derive(TS))]
6131pub struct ReplaceFunc {
6132    pub this: Expression,
6133    pub old: Expression,
6134    pub new: Expression,
6135}
6136
6137/// LEFT/RIGHT function
6138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6139#[cfg_attr(feature = "bindings", derive(TS))]
6140pub struct LeftRightFunc {
6141    pub this: Expression,
6142    pub length: Expression,
6143}
6144
6145/// REPEAT function
6146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6147#[cfg_attr(feature = "bindings", derive(TS))]
6148pub struct RepeatFunc {
6149    pub this: Expression,
6150    pub times: Expression,
6151}
6152
6153/// LPAD/RPAD function
6154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6155#[cfg_attr(feature = "bindings", derive(TS))]
6156pub struct PadFunc {
6157    pub this: Expression,
6158    pub length: Expression,
6159    pub fill: Option<Expression>,
6160}
6161
6162/// SPLIT function
6163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6164#[cfg_attr(feature = "bindings", derive(TS))]
6165pub struct SplitFunc {
6166    pub this: Expression,
6167    pub delimiter: Expression,
6168}
6169
6170/// REGEXP_LIKE function
6171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6172#[cfg_attr(feature = "bindings", derive(TS))]
6173pub struct RegexpFunc {
6174    pub this: Expression,
6175    pub pattern: Expression,
6176    pub flags: Option<Expression>,
6177}
6178
6179/// REGEXP_REPLACE function
6180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6181#[cfg_attr(feature = "bindings", derive(TS))]
6182pub struct RegexpReplaceFunc {
6183    pub this: Expression,
6184    pub pattern: Expression,
6185    pub replacement: Expression,
6186    pub flags: Option<Expression>,
6187}
6188
6189/// REGEXP_EXTRACT function
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct RegexpExtractFunc {
6193    pub this: Expression,
6194    pub pattern: Expression,
6195    pub group: Option<Expression>,
6196}
6197
6198/// ROUND function
6199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6200#[cfg_attr(feature = "bindings", derive(TS))]
6201pub struct RoundFunc {
6202    pub this: Expression,
6203    pub decimals: Option<Expression>,
6204}
6205
6206/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6208#[cfg_attr(feature = "bindings", derive(TS))]
6209pub struct FloorFunc {
6210    pub this: Expression,
6211    pub scale: Option<Expression>,
6212    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6213    #[serde(skip_serializing_if = "Option::is_none", default)]
6214    pub to: Option<Expression>,
6215}
6216
6217/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6219#[cfg_attr(feature = "bindings", derive(TS))]
6220pub struct CeilFunc {
6221    pub this: Expression,
6222    #[serde(skip_serializing_if = "Option::is_none", default)]
6223    pub decimals: Option<Expression>,
6224    /// Time unit for Druid-style CEIL(time TO unit) syntax
6225    #[serde(skip_serializing_if = "Option::is_none", default)]
6226    pub to: Option<Expression>,
6227}
6228
6229/// LOG function
6230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6231#[cfg_attr(feature = "bindings", derive(TS))]
6232pub struct LogFunc {
6233    pub this: Expression,
6234    pub base: Option<Expression>,
6235}
6236
6237/// CURRENT_DATE (no arguments)
6238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6239#[cfg_attr(feature = "bindings", derive(TS))]
6240pub struct CurrentDate;
6241
6242/// CURRENT_TIME
6243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6244#[cfg_attr(feature = "bindings", derive(TS))]
6245pub struct CurrentTime {
6246    pub precision: Option<u32>,
6247}
6248
6249/// CURRENT_TIMESTAMP
6250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6251#[cfg_attr(feature = "bindings", derive(TS))]
6252pub struct CurrentTimestamp {
6253    pub precision: Option<u32>,
6254    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6255    #[serde(default)]
6256    pub sysdate: bool,
6257}
6258
6259/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6261#[cfg_attr(feature = "bindings", derive(TS))]
6262pub struct CurrentTimestampLTZ {
6263    pub precision: Option<u32>,
6264}
6265
6266/// AT TIME ZONE expression for timezone conversion
6267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6268#[cfg_attr(feature = "bindings", derive(TS))]
6269pub struct AtTimeZone {
6270    /// The expression to convert
6271    pub this: Expression,
6272    /// The target timezone
6273    pub zone: Expression,
6274}
6275
6276/// DATE_ADD / DATE_SUB function
6277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6278#[cfg_attr(feature = "bindings", derive(TS))]
6279pub struct DateAddFunc {
6280    pub this: Expression,
6281    pub interval: Expression,
6282    pub unit: IntervalUnit,
6283}
6284
6285/// DATEDIFF function
6286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6287#[cfg_attr(feature = "bindings", derive(TS))]
6288pub struct DateDiffFunc {
6289    pub this: Expression,
6290    pub expression: Expression,
6291    pub unit: Option<IntervalUnit>,
6292}
6293
6294/// DATE_TRUNC function
6295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6296#[cfg_attr(feature = "bindings", derive(TS))]
6297pub struct DateTruncFunc {
6298    pub this: Expression,
6299    pub unit: DateTimeField,
6300}
6301
6302/// EXTRACT function
6303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6304#[cfg_attr(feature = "bindings", derive(TS))]
6305pub struct ExtractFunc {
6306    pub this: Expression,
6307    pub field: DateTimeField,
6308}
6309
6310#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6311#[cfg_attr(feature = "bindings", derive(TS))]
6312pub enum DateTimeField {
6313    Year,
6314    Month,
6315    Day,
6316    Hour,
6317    Minute,
6318    Second,
6319    Millisecond,
6320    Microsecond,
6321    DayOfWeek,
6322    DayOfYear,
6323    Week,
6324    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6325    WeekWithModifier(String),
6326    Quarter,
6327    Epoch,
6328    Timezone,
6329    TimezoneHour,
6330    TimezoneMinute,
6331    Date,
6332    Time,
6333    /// Custom datetime field for dialect-specific or arbitrary fields
6334    Custom(String),
6335}
6336
6337/// TO_DATE function
6338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6339#[cfg_attr(feature = "bindings", derive(TS))]
6340pub struct ToDateFunc {
6341    pub this: Expression,
6342    pub format: Option<Expression>,
6343}
6344
6345/// TO_TIMESTAMP function
6346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6347#[cfg_attr(feature = "bindings", derive(TS))]
6348pub struct ToTimestampFunc {
6349    pub this: Expression,
6350    pub format: Option<Expression>,
6351}
6352
6353/// IF function
6354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6355#[cfg_attr(feature = "bindings", derive(TS))]
6356pub struct IfFunc {
6357    pub condition: Expression,
6358    pub true_value: Expression,
6359    pub false_value: Option<Expression>,
6360    /// Original function name (IF, IFF, IIF) for round-trip preservation
6361    #[serde(skip_serializing_if = "Option::is_none", default)]
6362    pub original_name: Option<String>,
6363    /// Inferred data type from type annotation
6364    #[serde(default, skip_serializing_if = "Option::is_none")]
6365    pub inferred_type: Option<DataType>,
6366}
6367
6368/// NVL2 function
6369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6370#[cfg_attr(feature = "bindings", derive(TS))]
6371pub struct Nvl2Func {
6372    pub this: Expression,
6373    pub true_value: Expression,
6374    pub false_value: Expression,
6375    /// Inferred data type from type annotation
6376    #[serde(default, skip_serializing_if = "Option::is_none")]
6377    pub inferred_type: Option<DataType>,
6378}
6379
6380// ============================================================================
6381// Typed Aggregate Function types
6382// ============================================================================
6383
6384/// Generic aggregate function base type
6385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6386#[cfg_attr(feature = "bindings", derive(TS))]
6387pub struct AggFunc {
6388    pub this: Expression,
6389    pub distinct: bool,
6390    pub filter: Option<Expression>,
6391    pub order_by: Vec<Ordered>,
6392    /// Original function name (case-preserving) when parsed from SQL
6393    #[serde(skip_serializing_if = "Option::is_none", default)]
6394    pub name: Option<String>,
6395    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6396    #[serde(skip_serializing_if = "Option::is_none", default)]
6397    pub ignore_nulls: Option<bool>,
6398    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6399    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6400    #[serde(skip_serializing_if = "Option::is_none", default)]
6401    pub having_max: Option<(Box<Expression>, bool)>,
6402    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6403    #[serde(skip_serializing_if = "Option::is_none", default)]
6404    pub limit: Option<Box<Expression>>,
6405    /// Inferred data type from type annotation
6406    #[serde(default, skip_serializing_if = "Option::is_none")]
6407    pub inferred_type: Option<DataType>,
6408}
6409
6410/// COUNT function with optional star
6411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6412#[cfg_attr(feature = "bindings", derive(TS))]
6413pub struct CountFunc {
6414    pub this: Option<Expression>,
6415    pub star: bool,
6416    pub distinct: bool,
6417    pub filter: Option<Expression>,
6418    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6419    #[serde(default, skip_serializing_if = "Option::is_none")]
6420    pub ignore_nulls: Option<bool>,
6421    /// Original function name for case preservation (e.g., "count" or "COUNT")
6422    #[serde(default, skip_serializing_if = "Option::is_none")]
6423    pub original_name: Option<String>,
6424    /// Inferred data type from type annotation
6425    #[serde(default, skip_serializing_if = "Option::is_none")]
6426    pub inferred_type: Option<DataType>,
6427}
6428
6429/// GROUP_CONCAT function (MySQL style)
6430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6431#[cfg_attr(feature = "bindings", derive(TS))]
6432pub struct GroupConcatFunc {
6433    pub this: Expression,
6434    pub separator: Option<Expression>,
6435    pub order_by: Option<Vec<Ordered>>,
6436    pub distinct: bool,
6437    pub filter: Option<Expression>,
6438    /// Inferred data type from type annotation
6439    #[serde(default, skip_serializing_if = "Option::is_none")]
6440    pub inferred_type: Option<DataType>,
6441}
6442
6443/// STRING_AGG function (PostgreSQL/Standard SQL)
6444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6445#[cfg_attr(feature = "bindings", derive(TS))]
6446pub struct StringAggFunc {
6447    pub this: Expression,
6448    #[serde(default)]
6449    pub separator: Option<Expression>,
6450    #[serde(default)]
6451    pub order_by: Option<Vec<Ordered>>,
6452    #[serde(default)]
6453    pub distinct: bool,
6454    #[serde(default)]
6455    pub filter: Option<Expression>,
6456    /// BigQuery LIMIT inside STRING_AGG
6457    #[serde(default, skip_serializing_if = "Option::is_none")]
6458    pub limit: Option<Box<Expression>>,
6459    /// Inferred data type from type annotation
6460    #[serde(default, skip_serializing_if = "Option::is_none")]
6461    pub inferred_type: Option<DataType>,
6462}
6463
6464/// LISTAGG function (Oracle style)
6465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6466#[cfg_attr(feature = "bindings", derive(TS))]
6467pub struct ListAggFunc {
6468    pub this: Expression,
6469    pub separator: Option<Expression>,
6470    pub on_overflow: Option<ListAggOverflow>,
6471    pub order_by: Option<Vec<Ordered>>,
6472    pub distinct: bool,
6473    pub filter: Option<Expression>,
6474    /// Inferred data type from type annotation
6475    #[serde(default, skip_serializing_if = "Option::is_none")]
6476    pub inferred_type: Option<DataType>,
6477}
6478
6479/// LISTAGG ON OVERFLOW behavior
6480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6481#[cfg_attr(feature = "bindings", derive(TS))]
6482pub enum ListAggOverflow {
6483    Error,
6484    Truncate {
6485        filler: Option<Expression>,
6486        with_count: bool,
6487    },
6488}
6489
6490/// SUM_IF / COUNT_IF function
6491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6492#[cfg_attr(feature = "bindings", derive(TS))]
6493pub struct SumIfFunc {
6494    pub this: Expression,
6495    pub condition: Expression,
6496    pub filter: Option<Expression>,
6497    /// Inferred data type from type annotation
6498    #[serde(default, skip_serializing_if = "Option::is_none")]
6499    pub inferred_type: Option<DataType>,
6500}
6501
6502/// APPROX_PERCENTILE function
6503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6504#[cfg_attr(feature = "bindings", derive(TS))]
6505pub struct ApproxPercentileFunc {
6506    pub this: Expression,
6507    pub percentile: Expression,
6508    pub accuracy: Option<Expression>,
6509    pub filter: Option<Expression>,
6510}
6511
6512/// PERCENTILE_CONT / PERCENTILE_DISC function
6513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6514#[cfg_attr(feature = "bindings", derive(TS))]
6515pub struct PercentileFunc {
6516    pub this: Expression,
6517    pub percentile: Expression,
6518    pub order_by: Option<Vec<Ordered>>,
6519    pub filter: Option<Expression>,
6520}
6521
6522// ============================================================================
6523// Typed Window Function types
6524// ============================================================================
6525
6526/// ROW_NUMBER function (no arguments)
6527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6528#[cfg_attr(feature = "bindings", derive(TS))]
6529pub struct RowNumber;
6530
6531/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6533#[cfg_attr(feature = "bindings", derive(TS))]
6534pub struct Rank {
6535    /// DuckDB: RANK(ORDER BY col) - order by inside function
6536    #[serde(default, skip_serializing_if = "Option::is_none")]
6537    pub order_by: Option<Vec<Ordered>>,
6538    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6539    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6540    pub args: Vec<Expression>,
6541}
6542
6543/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6545#[cfg_attr(feature = "bindings", derive(TS))]
6546pub struct DenseRank {
6547    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6548    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6549    pub args: Vec<Expression>,
6550}
6551
6552/// NTILE function (DuckDB allows ORDER BY inside)
6553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6554#[cfg_attr(feature = "bindings", derive(TS))]
6555pub struct NTileFunc {
6556    /// num_buckets is optional to support Databricks NTILE() without arguments
6557    #[serde(default, skip_serializing_if = "Option::is_none")]
6558    pub num_buckets: Option<Expression>,
6559    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6560    #[serde(default, skip_serializing_if = "Option::is_none")]
6561    pub order_by: Option<Vec<Ordered>>,
6562}
6563
6564/// LEAD / LAG function
6565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6566#[cfg_attr(feature = "bindings", derive(TS))]
6567pub struct LeadLagFunc {
6568    pub this: Expression,
6569    pub offset: Option<Expression>,
6570    pub default: Option<Expression>,
6571    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6572    #[serde(default, skip_serializing_if = "Option::is_none")]
6573    pub ignore_nulls: Option<bool>,
6574}
6575
6576/// FIRST_VALUE / LAST_VALUE function
6577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6578#[cfg_attr(feature = "bindings", derive(TS))]
6579pub struct ValueFunc {
6580    pub this: Expression,
6581    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6582    #[serde(default, skip_serializing_if = "Option::is_none")]
6583    pub ignore_nulls: Option<bool>,
6584    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6585    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6586    pub order_by: Vec<Ordered>,
6587}
6588
6589/// NTH_VALUE function
6590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6591#[cfg_attr(feature = "bindings", derive(TS))]
6592pub struct NthValueFunc {
6593    pub this: Expression,
6594    pub offset: Expression,
6595    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6596    #[serde(default, skip_serializing_if = "Option::is_none")]
6597    pub ignore_nulls: Option<bool>,
6598    /// Snowflake FROM FIRST / FROM LAST clause
6599    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6600    #[serde(default, skip_serializing_if = "Option::is_none")]
6601    pub from_first: Option<bool>,
6602}
6603
6604/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6606#[cfg_attr(feature = "bindings", derive(TS))]
6607pub struct PercentRank {
6608    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6609    #[serde(default, skip_serializing_if = "Option::is_none")]
6610    pub order_by: Option<Vec<Ordered>>,
6611    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6612    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6613    pub args: Vec<Expression>,
6614}
6615
6616/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6618#[cfg_attr(feature = "bindings", derive(TS))]
6619pub struct CumeDist {
6620    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6621    #[serde(default, skip_serializing_if = "Option::is_none")]
6622    pub order_by: Option<Vec<Ordered>>,
6623    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6624    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6625    pub args: Vec<Expression>,
6626}
6627
6628// ============================================================================
6629// Additional String Function types
6630// ============================================================================
6631
6632/// POSITION/INSTR function
6633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6634#[cfg_attr(feature = "bindings", derive(TS))]
6635pub struct PositionFunc {
6636    pub substring: Expression,
6637    pub string: Expression,
6638    pub start: Option<Expression>,
6639}
6640
6641// ============================================================================
6642// Additional Math Function types
6643// ============================================================================
6644
6645/// RANDOM function (no arguments)
6646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6647#[cfg_attr(feature = "bindings", derive(TS))]
6648pub struct Random;
6649
6650/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6652#[cfg_attr(feature = "bindings", derive(TS))]
6653pub struct Rand {
6654    pub seed: Option<Box<Expression>>,
6655    /// Teradata RANDOM lower bound
6656    #[serde(default)]
6657    pub lower: Option<Box<Expression>>,
6658    /// Teradata RANDOM upper bound
6659    #[serde(default)]
6660    pub upper: Option<Box<Expression>>,
6661}
6662
6663/// TRUNCATE / TRUNC function
6664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6665#[cfg_attr(feature = "bindings", derive(TS))]
6666pub struct TruncateFunc {
6667    pub this: Expression,
6668    pub decimals: Option<Expression>,
6669}
6670
6671/// PI function (no arguments)
6672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6673#[cfg_attr(feature = "bindings", derive(TS))]
6674pub struct Pi;
6675
6676// ============================================================================
6677// Control Flow Function types
6678// ============================================================================
6679
6680/// DECODE function (Oracle style)
6681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6682#[cfg_attr(feature = "bindings", derive(TS))]
6683pub struct DecodeFunc {
6684    pub this: Expression,
6685    pub search_results: Vec<(Expression, Expression)>,
6686    pub default: Option<Expression>,
6687}
6688
6689// ============================================================================
6690// Additional Date/Time Function types
6691// ============================================================================
6692
6693/// DATE_FORMAT / FORMAT_DATE function
6694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6695#[cfg_attr(feature = "bindings", derive(TS))]
6696pub struct DateFormatFunc {
6697    pub this: Expression,
6698    pub format: Expression,
6699}
6700
6701/// FROM_UNIXTIME function
6702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6703#[cfg_attr(feature = "bindings", derive(TS))]
6704pub struct FromUnixtimeFunc {
6705    pub this: Expression,
6706    pub format: Option<Expression>,
6707}
6708
6709/// UNIX_TIMESTAMP function
6710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6711#[cfg_attr(feature = "bindings", derive(TS))]
6712pub struct UnixTimestampFunc {
6713    pub this: Option<Expression>,
6714    pub format: Option<Expression>,
6715}
6716
6717/// MAKE_DATE function
6718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6719#[cfg_attr(feature = "bindings", derive(TS))]
6720pub struct MakeDateFunc {
6721    pub year: Expression,
6722    pub month: Expression,
6723    pub day: Expression,
6724}
6725
6726/// MAKE_TIMESTAMP function
6727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6728#[cfg_attr(feature = "bindings", derive(TS))]
6729pub struct MakeTimestampFunc {
6730    pub year: Expression,
6731    pub month: Expression,
6732    pub day: Expression,
6733    pub hour: Expression,
6734    pub minute: Expression,
6735    pub second: Expression,
6736    pub timezone: Option<Expression>,
6737}
6738
6739/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6741#[cfg_attr(feature = "bindings", derive(TS))]
6742pub struct LastDayFunc {
6743    pub this: Expression,
6744    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6745    #[serde(skip_serializing_if = "Option::is_none", default)]
6746    pub unit: Option<DateTimeField>,
6747}
6748
6749// ============================================================================
6750// Array Function types
6751// ============================================================================
6752
6753/// ARRAY constructor
6754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6755#[cfg_attr(feature = "bindings", derive(TS))]
6756pub struct ArrayConstructor {
6757    pub expressions: Vec<Expression>,
6758    pub bracket_notation: bool,
6759    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6760    pub use_list_keyword: bool,
6761}
6762
6763/// ARRAY_SORT function
6764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6765#[cfg_attr(feature = "bindings", derive(TS))]
6766pub struct ArraySortFunc {
6767    pub this: Expression,
6768    pub comparator: Option<Expression>,
6769    pub desc: bool,
6770    pub nulls_first: Option<bool>,
6771}
6772
6773/// ARRAY_JOIN / ARRAY_TO_STRING function
6774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6775#[cfg_attr(feature = "bindings", derive(TS))]
6776pub struct ArrayJoinFunc {
6777    pub this: Expression,
6778    pub separator: Expression,
6779    pub null_replacement: Option<Expression>,
6780}
6781
6782/// UNNEST function
6783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6784#[cfg_attr(feature = "bindings", derive(TS))]
6785pub struct UnnestFunc {
6786    pub this: Expression,
6787    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6788    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6789    pub expressions: Vec<Expression>,
6790    pub with_ordinality: bool,
6791    pub alias: Option<Identifier>,
6792    /// BigQuery: offset alias for WITH OFFSET AS <name>
6793    #[serde(default, skip_serializing_if = "Option::is_none")]
6794    pub offset_alias: Option<Identifier>,
6795}
6796
6797/// ARRAY_FILTER function (with lambda)
6798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6799#[cfg_attr(feature = "bindings", derive(TS))]
6800pub struct ArrayFilterFunc {
6801    pub this: Expression,
6802    pub filter: Expression,
6803}
6804
6805/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6807#[cfg_attr(feature = "bindings", derive(TS))]
6808pub struct ArrayTransformFunc {
6809    pub this: Expression,
6810    pub transform: Expression,
6811}
6812
6813/// SEQUENCE / GENERATE_SERIES function
6814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6815#[cfg_attr(feature = "bindings", derive(TS))]
6816pub struct SequenceFunc {
6817    pub start: Expression,
6818    pub stop: Expression,
6819    pub step: Option<Expression>,
6820}
6821
6822// ============================================================================
6823// Struct Function types
6824// ============================================================================
6825
6826/// STRUCT constructor
6827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6828#[cfg_attr(feature = "bindings", derive(TS))]
6829pub struct StructConstructor {
6830    pub fields: Vec<(Option<Identifier>, Expression)>,
6831}
6832
6833/// STRUCT_EXTRACT function
6834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6835#[cfg_attr(feature = "bindings", derive(TS))]
6836pub struct StructExtractFunc {
6837    pub this: Expression,
6838    pub field: Identifier,
6839}
6840
6841/// NAMED_STRUCT function
6842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6843#[cfg_attr(feature = "bindings", derive(TS))]
6844pub struct NamedStructFunc {
6845    pub pairs: Vec<(Expression, Expression)>,
6846}
6847
6848// ============================================================================
6849// Map Function types
6850// ============================================================================
6851
6852/// MAP constructor
6853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6854#[cfg_attr(feature = "bindings", derive(TS))]
6855pub struct MapConstructor {
6856    pub keys: Vec<Expression>,
6857    pub values: Vec<Expression>,
6858    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6859    #[serde(default)]
6860    pub curly_brace_syntax: bool,
6861    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6862    #[serde(default)]
6863    pub with_map_keyword: bool,
6864}
6865
6866/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6868#[cfg_attr(feature = "bindings", derive(TS))]
6869pub struct TransformFunc {
6870    pub this: Expression,
6871    pub transform: Expression,
6872}
6873
6874/// Function call with EMITS clause (Exasol)
6875/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6877#[cfg_attr(feature = "bindings", derive(TS))]
6878pub struct FunctionEmits {
6879    /// The function call expression
6880    pub this: Expression,
6881    /// The EMITS schema definition
6882    pub emits: Expression,
6883}
6884
6885// ============================================================================
6886// JSON Function types
6887// ============================================================================
6888
6889/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6891#[cfg_attr(feature = "bindings", derive(TS))]
6892pub struct JsonExtractFunc {
6893    pub this: Expression,
6894    pub path: Expression,
6895    pub returning: Option<DataType>,
6896    /// True if parsed from -> or ->> operator syntax
6897    #[serde(default)]
6898    pub arrow_syntax: bool,
6899    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6900    #[serde(default)]
6901    pub hash_arrow_syntax: bool,
6902    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6903    #[serde(default)]
6904    pub wrapper_option: Option<String>,
6905    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6906    #[serde(default)]
6907    pub quotes_option: Option<String>,
6908    /// ON SCALAR STRING flag
6909    #[serde(default)]
6910    pub on_scalar_string: bool,
6911    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6912    #[serde(default)]
6913    pub on_error: Option<String>,
6914}
6915
6916/// JSON path extraction
6917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6918#[cfg_attr(feature = "bindings", derive(TS))]
6919pub struct JsonPathFunc {
6920    pub this: Expression,
6921    pub paths: Vec<Expression>,
6922}
6923
6924/// JSON_OBJECT function
6925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6926#[cfg_attr(feature = "bindings", derive(TS))]
6927pub struct JsonObjectFunc {
6928    pub pairs: Vec<(Expression, Expression)>,
6929    pub null_handling: Option<JsonNullHandling>,
6930    #[serde(default)]
6931    pub with_unique_keys: bool,
6932    #[serde(default)]
6933    pub returning_type: Option<DataType>,
6934    #[serde(default)]
6935    pub format_json: bool,
6936    #[serde(default)]
6937    pub encoding: Option<String>,
6938    /// For JSON_OBJECT(*) syntax
6939    #[serde(default)]
6940    pub star: bool,
6941}
6942
6943/// JSON null handling options
6944#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6945#[cfg_attr(feature = "bindings", derive(TS))]
6946pub enum JsonNullHandling {
6947    NullOnNull,
6948    AbsentOnNull,
6949}
6950
6951/// JSON_SET / JSON_INSERT function
6952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6953#[cfg_attr(feature = "bindings", derive(TS))]
6954pub struct JsonModifyFunc {
6955    pub this: Expression,
6956    pub path_values: Vec<(Expression, Expression)>,
6957}
6958
6959/// JSON_ARRAYAGG function
6960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6961#[cfg_attr(feature = "bindings", derive(TS))]
6962pub struct JsonArrayAggFunc {
6963    pub this: Expression,
6964    pub order_by: Option<Vec<Ordered>>,
6965    pub null_handling: Option<JsonNullHandling>,
6966    pub filter: Option<Expression>,
6967}
6968
6969/// JSON_OBJECTAGG function
6970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6971#[cfg_attr(feature = "bindings", derive(TS))]
6972pub struct JsonObjectAggFunc {
6973    pub key: Expression,
6974    pub value: Expression,
6975    pub null_handling: Option<JsonNullHandling>,
6976    pub filter: Option<Expression>,
6977}
6978
6979// ============================================================================
6980// Type Casting Function types
6981// ============================================================================
6982
6983/// CONVERT function (SQL Server style)
6984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6985#[cfg_attr(feature = "bindings", derive(TS))]
6986pub struct ConvertFunc {
6987    pub this: Expression,
6988    pub to: DataType,
6989    pub style: Option<Expression>,
6990}
6991
6992// ============================================================================
6993// Additional Expression types
6994// ============================================================================
6995
6996/// Lambda expression
6997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6998#[cfg_attr(feature = "bindings", derive(TS))]
6999pub struct LambdaExpr {
7000    pub parameters: Vec<Identifier>,
7001    pub body: Expression,
7002    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7003    #[serde(default)]
7004    pub colon: bool,
7005    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7006    /// Maps parameter index to data type
7007    #[serde(default)]
7008    pub parameter_types: Vec<Option<DataType>>,
7009}
7010
7011/// Parameter (parameterized queries)
7012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7013#[cfg_attr(feature = "bindings", derive(TS))]
7014pub struct Parameter {
7015    pub name: Option<String>,
7016    pub index: Option<u32>,
7017    pub style: ParameterStyle,
7018    /// Whether the name was quoted (e.g., @"x" vs @x)
7019    #[serde(default)]
7020    pub quoted: bool,
7021    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7022    #[serde(default)]
7023    pub string_quoted: bool,
7024    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7025    #[serde(default)]
7026    pub expression: Option<String>,
7027}
7028
7029/// Parameter placeholder styles
7030#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7031#[cfg_attr(feature = "bindings", derive(TS))]
7032pub enum ParameterStyle {
7033    Question,     // ?
7034    Dollar,       // $1, $2
7035    DollarBrace,  // ${name} (Databricks, Hive template variables)
7036    Brace,        // {name} (Spark/Databricks widget/template variables)
7037    Colon,        // :name
7038    At,           // @name
7039    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7040    DoubleDollar, // $$name
7041    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7042}
7043
7044/// Placeholder expression
7045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7046#[cfg_attr(feature = "bindings", derive(TS))]
7047pub struct Placeholder {
7048    pub index: Option<u32>,
7049}
7050
7051/// Named argument in function call: name => value or name := value
7052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7053#[cfg_attr(feature = "bindings", derive(TS))]
7054pub struct NamedArgument {
7055    pub name: Identifier,
7056    pub value: Expression,
7057    /// The separator used: `=>`, `:=`, or `=`
7058    pub separator: NamedArgSeparator,
7059}
7060
7061/// Separator style for named arguments
7062#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7063#[cfg_attr(feature = "bindings", derive(TS))]
7064pub enum NamedArgSeparator {
7065    /// `=>` (standard SQL, Snowflake, BigQuery)
7066    DArrow,
7067    /// `:=` (Oracle, MySQL)
7068    ColonEq,
7069    /// `=` (simple equals, some dialects)
7070    Eq,
7071}
7072
7073/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7074/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7076#[cfg_attr(feature = "bindings", derive(TS))]
7077pub struct TableArgument {
7078    /// The keyword prefix: "TABLE" or "MODEL"
7079    pub prefix: String,
7080    /// The table/model reference expression
7081    pub this: Expression,
7082}
7083
7084/// SQL Comment preservation
7085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7086#[cfg_attr(feature = "bindings", derive(TS))]
7087pub struct SqlComment {
7088    pub text: String,
7089    pub is_block: bool,
7090}
7091
7092// ============================================================================
7093// Additional Predicate types
7094// ============================================================================
7095
7096/// SIMILAR TO expression
7097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7098#[cfg_attr(feature = "bindings", derive(TS))]
7099pub struct SimilarToExpr {
7100    pub this: Expression,
7101    pub pattern: Expression,
7102    pub escape: Option<Expression>,
7103    pub not: bool,
7104}
7105
7106/// ANY / ALL quantified expression
7107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7108#[cfg_attr(feature = "bindings", derive(TS))]
7109pub struct QuantifiedExpr {
7110    pub this: Expression,
7111    pub subquery: Expression,
7112    pub op: Option<QuantifiedOp>,
7113}
7114
7115/// Comparison operator for quantified expressions
7116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7117#[cfg_attr(feature = "bindings", derive(TS))]
7118pub enum QuantifiedOp {
7119    Eq,
7120    Neq,
7121    Lt,
7122    Lte,
7123    Gt,
7124    Gte,
7125}
7126
7127/// OVERLAPS expression
7128/// Supports two forms:
7129/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7130/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7132#[cfg_attr(feature = "bindings", derive(TS))]
7133pub struct OverlapsExpr {
7134    /// Left operand for simple binary form
7135    #[serde(skip_serializing_if = "Option::is_none")]
7136    pub this: Option<Expression>,
7137    /// Right operand for simple binary form
7138    #[serde(skip_serializing_if = "Option::is_none")]
7139    pub expression: Option<Expression>,
7140    /// Left range start for full ANSI form
7141    #[serde(skip_serializing_if = "Option::is_none")]
7142    pub left_start: Option<Expression>,
7143    /// Left range end for full ANSI form
7144    #[serde(skip_serializing_if = "Option::is_none")]
7145    pub left_end: Option<Expression>,
7146    /// Right range start for full ANSI form
7147    #[serde(skip_serializing_if = "Option::is_none")]
7148    pub right_start: Option<Expression>,
7149    /// Right range end for full ANSI form
7150    #[serde(skip_serializing_if = "Option::is_none")]
7151    pub right_end: Option<Expression>,
7152}
7153
7154// ============================================================================
7155// Array/Struct/Map access
7156// ============================================================================
7157
7158/// Subscript access (array[index] or map[key])
7159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7160#[cfg_attr(feature = "bindings", derive(TS))]
7161pub struct Subscript {
7162    pub this: Expression,
7163    pub index: Expression,
7164}
7165
7166/// Dot access (struct.field)
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub struct DotAccess {
7170    pub this: Expression,
7171    pub field: Identifier,
7172}
7173
7174/// Method call (expr.method(args))
7175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7176#[cfg_attr(feature = "bindings", derive(TS))]
7177pub struct MethodCall {
7178    pub this: Expression,
7179    pub method: Identifier,
7180    pub args: Vec<Expression>,
7181}
7182
7183/// Array slice (array[start:end])
7184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7185#[cfg_attr(feature = "bindings", derive(TS))]
7186pub struct ArraySlice {
7187    pub this: Expression,
7188    pub start: Option<Expression>,
7189    pub end: Option<Expression>,
7190}
7191
7192// ============================================================================
7193// DDL (Data Definition Language) Statements
7194// ============================================================================
7195
7196/// ON COMMIT behavior for temporary tables
7197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7198#[cfg_attr(feature = "bindings", derive(TS))]
7199pub enum OnCommit {
7200    /// ON COMMIT PRESERVE ROWS
7201    PreserveRows,
7202    /// ON COMMIT DELETE ROWS
7203    DeleteRows,
7204}
7205
7206/// CREATE TABLE statement
7207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7208#[cfg_attr(feature = "bindings", derive(TS))]
7209pub struct CreateTable {
7210    pub name: TableRef,
7211    /// ClickHouse: ON CLUSTER clause for distributed DDL
7212    #[serde(default, skip_serializing_if = "Option::is_none")]
7213    pub on_cluster: Option<OnCluster>,
7214    pub columns: Vec<ColumnDef>,
7215    pub constraints: Vec<TableConstraint>,
7216    pub if_not_exists: bool,
7217    pub temporary: bool,
7218    pub or_replace: bool,
7219    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7220    #[serde(default, skip_serializing_if = "Option::is_none")]
7221    pub table_modifier: Option<String>,
7222    pub as_select: Option<Expression>,
7223    /// Whether the AS SELECT was wrapped in parentheses
7224    #[serde(default)]
7225    pub as_select_parenthesized: bool,
7226    /// ON COMMIT behavior for temporary tables
7227    #[serde(default)]
7228    pub on_commit: Option<OnCommit>,
7229    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7230    #[serde(default)]
7231    pub clone_source: Option<TableRef>,
7232    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7233    #[serde(default, skip_serializing_if = "Option::is_none")]
7234    pub clone_at_clause: Option<Expression>,
7235    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7236    #[serde(default)]
7237    pub is_copy: bool,
7238    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7239    #[serde(default)]
7240    pub shallow_clone: bool,
7241    /// Leading comments before the statement
7242    #[serde(default)]
7243    pub leading_comments: Vec<String>,
7244    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7245    #[serde(default)]
7246    pub with_properties: Vec<(String, String)>,
7247    /// Teradata: table options after name before columns (comma-separated)
7248    #[serde(default)]
7249    pub teradata_post_name_options: Vec<String>,
7250    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7251    #[serde(default)]
7252    pub with_data: Option<bool>,
7253    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7254    #[serde(default)]
7255    pub with_statistics: Option<bool>,
7256    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7257    #[serde(default)]
7258    pub teradata_indexes: Vec<TeradataIndex>,
7259    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7260    #[serde(default)]
7261    pub with_cte: Option<With>,
7262    /// Table properties like DEFAULT COLLATE (BigQuery)
7263    #[serde(default)]
7264    pub properties: Vec<Expression>,
7265    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7266    #[serde(default, skip_serializing_if = "Option::is_none")]
7267    pub partition_of: Option<Expression>,
7268    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7269    #[serde(default)]
7270    pub post_table_properties: Vec<Expression>,
7271    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7272    #[serde(default)]
7273    pub mysql_table_options: Vec<(String, String)>,
7274    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7275    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7276    pub inherits: Vec<TableRef>,
7277    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7278    #[serde(default, skip_serializing_if = "Option::is_none")]
7279    pub on_property: Option<OnProperty>,
7280    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7281    #[serde(default)]
7282    pub copy_grants: bool,
7283    /// Snowflake: USING TEMPLATE expression for schema inference
7284    #[serde(default, skip_serializing_if = "Option::is_none")]
7285    pub using_template: Option<Box<Expression>>,
7286    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7287    #[serde(default, skip_serializing_if = "Option::is_none")]
7288    pub rollup: Option<RollupProperty>,
7289    /// ClickHouse: UUID 'xxx' clause after table name
7290    #[serde(default, skip_serializing_if = "Option::is_none")]
7291    pub uuid: Option<String>,
7292}
7293
7294/// Teradata index specification for CREATE TABLE
7295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7296#[cfg_attr(feature = "bindings", derive(TS))]
7297pub struct TeradataIndex {
7298    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7299    pub kind: TeradataIndexKind,
7300    /// Optional index name
7301    pub name: Option<String>,
7302    /// Optional column list
7303    pub columns: Vec<String>,
7304}
7305
7306/// Kind of Teradata index
7307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7308#[cfg_attr(feature = "bindings", derive(TS))]
7309pub enum TeradataIndexKind {
7310    /// NO PRIMARY INDEX
7311    NoPrimary,
7312    /// PRIMARY INDEX
7313    Primary,
7314    /// PRIMARY AMP INDEX
7315    PrimaryAmp,
7316    /// UNIQUE INDEX
7317    Unique,
7318    /// UNIQUE PRIMARY INDEX
7319    UniquePrimary,
7320    /// INDEX (secondary, non-primary)
7321    Secondary,
7322}
7323
7324impl CreateTable {
7325    pub fn new(name: impl Into<String>) -> Self {
7326        Self {
7327            name: TableRef::new(name),
7328            on_cluster: None,
7329            columns: Vec::new(),
7330            constraints: Vec::new(),
7331            if_not_exists: false,
7332            temporary: false,
7333            or_replace: false,
7334            table_modifier: None,
7335            as_select: None,
7336            as_select_parenthesized: false,
7337            on_commit: None,
7338            clone_source: None,
7339            clone_at_clause: None,
7340            shallow_clone: false,
7341            is_copy: false,
7342            leading_comments: Vec::new(),
7343            with_properties: Vec::new(),
7344            teradata_post_name_options: Vec::new(),
7345            with_data: None,
7346            with_statistics: None,
7347            teradata_indexes: Vec::new(),
7348            with_cte: None,
7349            properties: Vec::new(),
7350            partition_of: None,
7351            post_table_properties: Vec::new(),
7352            mysql_table_options: Vec::new(),
7353            inherits: Vec::new(),
7354            on_property: None,
7355            copy_grants: false,
7356            using_template: None,
7357            rollup: None,
7358            uuid: None,
7359        }
7360    }
7361}
7362
7363/// Sort order for PRIMARY KEY ASC/DESC
7364#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7365#[cfg_attr(feature = "bindings", derive(TS))]
7366pub enum SortOrder {
7367    Asc,
7368    Desc,
7369}
7370
7371/// Type of column constraint for tracking order
7372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7373#[cfg_attr(feature = "bindings", derive(TS))]
7374pub enum ConstraintType {
7375    NotNull,
7376    Null,
7377    PrimaryKey,
7378    Unique,
7379    Default,
7380    AutoIncrement,
7381    Collate,
7382    Comment,
7383    References,
7384    Check,
7385    GeneratedAsIdentity,
7386    /// Snowflake: TAG (key='value', ...)
7387    Tags,
7388    /// Computed/generated column
7389    ComputedColumn,
7390    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7391    GeneratedAsRow,
7392    /// MySQL: ON UPDATE expression
7393    OnUpdate,
7394    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7395    Path,
7396    /// Redshift: ENCODE encoding_type
7397    Encode,
7398}
7399
7400/// Column definition in CREATE TABLE
7401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7402#[cfg_attr(feature = "bindings", derive(TS))]
7403pub struct ColumnDef {
7404    pub name: Identifier,
7405    pub data_type: DataType,
7406    pub nullable: Option<bool>,
7407    pub default: Option<Expression>,
7408    pub primary_key: bool,
7409    /// Sort order for PRIMARY KEY (ASC/DESC)
7410    #[serde(default)]
7411    pub primary_key_order: Option<SortOrder>,
7412    pub unique: bool,
7413    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7414    #[serde(default)]
7415    pub unique_nulls_not_distinct: bool,
7416    pub auto_increment: bool,
7417    pub comment: Option<String>,
7418    pub constraints: Vec<ColumnConstraint>,
7419    /// Track original order of constraints for accurate regeneration
7420    #[serde(default)]
7421    pub constraint_order: Vec<ConstraintType>,
7422    /// Teradata: FORMAT 'pattern'
7423    #[serde(default)]
7424    pub format: Option<String>,
7425    /// Teradata: TITLE 'title'
7426    #[serde(default)]
7427    pub title: Option<String>,
7428    /// Teradata: INLINE LENGTH n
7429    #[serde(default)]
7430    pub inline_length: Option<u64>,
7431    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7432    #[serde(default)]
7433    pub compress: Option<Vec<Expression>>,
7434    /// Teradata: CHARACTER SET name
7435    #[serde(default)]
7436    pub character_set: Option<String>,
7437    /// Teradata: UPPERCASE
7438    #[serde(default)]
7439    pub uppercase: bool,
7440    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7441    #[serde(default)]
7442    pub casespecific: Option<bool>,
7443    /// Snowflake: AUTOINCREMENT START value
7444    #[serde(default)]
7445    pub auto_increment_start: Option<Box<Expression>>,
7446    /// Snowflake: AUTOINCREMENT INCREMENT value
7447    #[serde(default)]
7448    pub auto_increment_increment: Option<Box<Expression>>,
7449    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7450    #[serde(default)]
7451    pub auto_increment_order: Option<bool>,
7452    /// MySQL: UNSIGNED modifier
7453    #[serde(default)]
7454    pub unsigned: bool,
7455    /// MySQL: ZEROFILL modifier
7456    #[serde(default)]
7457    pub zerofill: bool,
7458    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7459    #[serde(default, skip_serializing_if = "Option::is_none")]
7460    pub on_update: Option<Expression>,
7461    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7462    #[serde(default, skip_serializing_if = "Option::is_none")]
7463    pub unique_constraint_name: Option<String>,
7464    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7465    #[serde(default, skip_serializing_if = "Option::is_none")]
7466    pub not_null_constraint_name: Option<String>,
7467    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7468    #[serde(default, skip_serializing_if = "Option::is_none")]
7469    pub primary_key_constraint_name: Option<String>,
7470    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7471    #[serde(default, skip_serializing_if = "Option::is_none")]
7472    pub check_constraint_name: Option<String>,
7473    /// BigQuery: OPTIONS (key=value, ...) on column
7474    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7475    pub options: Vec<Expression>,
7476    /// SQLite: Column definition without explicit type
7477    #[serde(default)]
7478    pub no_type: bool,
7479    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7480    #[serde(default, skip_serializing_if = "Option::is_none")]
7481    pub encoding: Option<String>,
7482    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7483    #[serde(default, skip_serializing_if = "Option::is_none")]
7484    pub codec: Option<String>,
7485    /// ClickHouse: EPHEMERAL [expr] modifier
7486    #[serde(default, skip_serializing_if = "Option::is_none")]
7487    pub ephemeral: Option<Option<Box<Expression>>>,
7488    /// ClickHouse: MATERIALIZED expr modifier
7489    #[serde(default, skip_serializing_if = "Option::is_none")]
7490    pub materialized_expr: Option<Box<Expression>>,
7491    /// ClickHouse: ALIAS expr modifier
7492    #[serde(default, skip_serializing_if = "Option::is_none")]
7493    pub alias_expr: Option<Box<Expression>>,
7494    /// ClickHouse: TTL expr modifier on columns
7495    #[serde(default, skip_serializing_if = "Option::is_none")]
7496    pub ttl_expr: Option<Box<Expression>>,
7497    /// TSQL: NOT FOR REPLICATION
7498    #[serde(default)]
7499    pub not_for_replication: bool,
7500}
7501
7502impl ColumnDef {
7503    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7504        Self {
7505            name: Identifier::new(name),
7506            data_type,
7507            nullable: None,
7508            default: None,
7509            primary_key: false,
7510            primary_key_order: None,
7511            unique: false,
7512            unique_nulls_not_distinct: false,
7513            auto_increment: false,
7514            comment: None,
7515            constraints: Vec::new(),
7516            constraint_order: Vec::new(),
7517            format: None,
7518            title: None,
7519            inline_length: None,
7520            compress: None,
7521            character_set: None,
7522            uppercase: false,
7523            casespecific: None,
7524            auto_increment_start: None,
7525            auto_increment_increment: None,
7526            auto_increment_order: None,
7527            unsigned: false,
7528            zerofill: false,
7529            on_update: None,
7530            unique_constraint_name: None,
7531            not_null_constraint_name: None,
7532            primary_key_constraint_name: None,
7533            check_constraint_name: None,
7534            options: Vec::new(),
7535            no_type: false,
7536            encoding: None,
7537            codec: None,
7538            ephemeral: None,
7539            materialized_expr: None,
7540            alias_expr: None,
7541            ttl_expr: None,
7542            not_for_replication: false,
7543        }
7544    }
7545}
7546
7547/// Column-level constraint
7548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7549#[cfg_attr(feature = "bindings", derive(TS))]
7550pub enum ColumnConstraint {
7551    NotNull,
7552    Null,
7553    Unique,
7554    PrimaryKey,
7555    Default(Expression),
7556    Check(Expression),
7557    References(ForeignKeyRef),
7558    GeneratedAsIdentity(GeneratedAsIdentity),
7559    Collate(Identifier),
7560    Comment(String),
7561    /// Snowflake: TAG (key='value', ...)
7562    Tags(Tags),
7563    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7564    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7565    ComputedColumn(ComputedColumn),
7566    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7567    GeneratedAsRow(GeneratedAsRow),
7568    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7569    Path(Expression),
7570}
7571
7572/// Computed/generated column constraint
7573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7574#[cfg_attr(feature = "bindings", derive(TS))]
7575pub struct ComputedColumn {
7576    /// The expression that computes the column value
7577    pub expression: Box<Expression>,
7578    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7579    #[serde(default)]
7580    pub persisted: bool,
7581    /// NOT NULL (TSQL computed columns)
7582    #[serde(default)]
7583    pub not_null: bool,
7584    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7585    /// When None, defaults to dialect-appropriate output
7586    #[serde(default)]
7587    pub persistence_kind: Option<String>,
7588    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7589    #[serde(default, skip_serializing_if = "Option::is_none")]
7590    pub data_type: Option<DataType>,
7591}
7592
7593/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7595#[cfg_attr(feature = "bindings", derive(TS))]
7596pub struct GeneratedAsRow {
7597    /// true = ROW START, false = ROW END
7598    pub start: bool,
7599    /// HIDDEN modifier
7600    #[serde(default)]
7601    pub hidden: bool,
7602}
7603
7604/// Generated identity column constraint
7605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7606#[cfg_attr(feature = "bindings", derive(TS))]
7607pub struct GeneratedAsIdentity {
7608    /// True for ALWAYS, False for BY DEFAULT
7609    pub always: bool,
7610    /// ON NULL (only valid with BY DEFAULT)
7611    pub on_null: bool,
7612    /// START WITH value
7613    pub start: Option<Box<Expression>>,
7614    /// INCREMENT BY value
7615    pub increment: Option<Box<Expression>>,
7616    /// MINVALUE
7617    pub minvalue: Option<Box<Expression>>,
7618    /// MAXVALUE
7619    pub maxvalue: Option<Box<Expression>>,
7620    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7621    pub cycle: Option<bool>,
7622}
7623
7624/// Constraint modifiers (shared between table-level constraints)
7625#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7626#[cfg_attr(feature = "bindings", derive(TS))]
7627pub struct ConstraintModifiers {
7628    /// ENFORCED / NOT ENFORCED
7629    pub enforced: Option<bool>,
7630    /// DEFERRABLE / NOT DEFERRABLE
7631    pub deferrable: Option<bool>,
7632    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7633    pub initially_deferred: Option<bool>,
7634    /// NORELY (Oracle)
7635    pub norely: bool,
7636    /// RELY (Oracle)
7637    pub rely: bool,
7638    /// USING index type (MySQL): BTREE or HASH
7639    #[serde(default)]
7640    pub using: Option<String>,
7641    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7642    #[serde(default)]
7643    pub using_before_columns: bool,
7644    /// MySQL index COMMENT 'text'
7645    #[serde(default, skip_serializing_if = "Option::is_none")]
7646    pub comment: Option<String>,
7647    /// MySQL index VISIBLE/INVISIBLE
7648    #[serde(default, skip_serializing_if = "Option::is_none")]
7649    pub visible: Option<bool>,
7650    /// MySQL ENGINE_ATTRIBUTE = 'value'
7651    #[serde(default, skip_serializing_if = "Option::is_none")]
7652    pub engine_attribute: Option<String>,
7653    /// MySQL WITH PARSER name
7654    #[serde(default, skip_serializing_if = "Option::is_none")]
7655    pub with_parser: Option<String>,
7656    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7657    #[serde(default)]
7658    pub not_valid: bool,
7659    /// TSQL CLUSTERED/NONCLUSTERED modifier
7660    #[serde(default, skip_serializing_if = "Option::is_none")]
7661    pub clustered: Option<String>,
7662    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7663    #[serde(default, skip_serializing_if = "Option::is_none")]
7664    pub on_conflict: Option<String>,
7665    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7666    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7667    pub with_options: Vec<(String, String)>,
7668    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7669    #[serde(default, skip_serializing_if = "Option::is_none")]
7670    pub on_filegroup: Option<Identifier>,
7671}
7672
7673/// Table-level constraint
7674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7675#[cfg_attr(feature = "bindings", derive(TS))]
7676pub enum TableConstraint {
7677    PrimaryKey {
7678        name: Option<Identifier>,
7679        columns: Vec<Identifier>,
7680        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7681        #[serde(default)]
7682        include_columns: Vec<Identifier>,
7683        #[serde(default)]
7684        modifiers: ConstraintModifiers,
7685        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7686        #[serde(default)]
7687        has_constraint_keyword: bool,
7688    },
7689    Unique {
7690        name: Option<Identifier>,
7691        columns: Vec<Identifier>,
7692        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7693        #[serde(default)]
7694        columns_parenthesized: bool,
7695        #[serde(default)]
7696        modifiers: ConstraintModifiers,
7697        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7698        #[serde(default)]
7699        has_constraint_keyword: bool,
7700        /// PostgreSQL 15+: NULLS NOT DISTINCT
7701        #[serde(default)]
7702        nulls_not_distinct: bool,
7703    },
7704    ForeignKey {
7705        name: Option<Identifier>,
7706        columns: Vec<Identifier>,
7707        #[serde(default)]
7708        references: Option<ForeignKeyRef>,
7709        /// ON DELETE action when REFERENCES is absent
7710        #[serde(default)]
7711        on_delete: Option<ReferentialAction>,
7712        /// ON UPDATE action when REFERENCES is absent
7713        #[serde(default)]
7714        on_update: Option<ReferentialAction>,
7715        #[serde(default)]
7716        modifiers: ConstraintModifiers,
7717    },
7718    Check {
7719        name: Option<Identifier>,
7720        expression: Expression,
7721        #[serde(default)]
7722        modifiers: ConstraintModifiers,
7723    },
7724    /// ClickHouse ASSUME constraint (query optimization assumption)
7725    Assume {
7726        name: Option<Identifier>,
7727        expression: Expression,
7728    },
7729    /// INDEX / KEY constraint (MySQL)
7730    Index {
7731        name: Option<Identifier>,
7732        columns: Vec<Identifier>,
7733        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7734        #[serde(default)]
7735        kind: Option<String>,
7736        #[serde(default)]
7737        modifiers: ConstraintModifiers,
7738        /// True if KEY keyword was used instead of INDEX
7739        #[serde(default)]
7740        use_key_keyword: bool,
7741        /// ClickHouse: indexed expression (instead of columns)
7742        #[serde(default, skip_serializing_if = "Option::is_none")]
7743        expression: Option<Box<Expression>>,
7744        /// ClickHouse: TYPE type_func(args)
7745        #[serde(default, skip_serializing_if = "Option::is_none")]
7746        index_type: Option<Box<Expression>>,
7747        /// ClickHouse: GRANULARITY n
7748        #[serde(default, skip_serializing_if = "Option::is_none")]
7749        granularity: Option<Box<Expression>>,
7750    },
7751    /// ClickHouse PROJECTION definition
7752    Projection {
7753        name: Identifier,
7754        expression: Expression,
7755    },
7756    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7757    Like {
7758        source: TableRef,
7759        /// Options as (INCLUDING|EXCLUDING, property) pairs
7760        options: Vec<(LikeOptionAction, String)>,
7761    },
7762    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7763    PeriodForSystemTime {
7764        start_col: Identifier,
7765        end_col: Identifier,
7766    },
7767    /// PostgreSQL EXCLUDE constraint
7768    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7769    Exclude {
7770        name: Option<Identifier>,
7771        /// Index access method (gist, btree, etc.)
7772        #[serde(default)]
7773        using: Option<String>,
7774        /// Elements: (expression, operator) pairs
7775        elements: Vec<ExcludeElement>,
7776        /// INCLUDE columns
7777        #[serde(default)]
7778        include_columns: Vec<Identifier>,
7779        /// WHERE predicate
7780        #[serde(default)]
7781        where_clause: Option<Box<Expression>>,
7782        /// WITH (storage_parameters)
7783        #[serde(default)]
7784        with_params: Vec<(String, String)>,
7785        /// USING INDEX TABLESPACE tablespace_name
7786        #[serde(default)]
7787        using_index_tablespace: Option<String>,
7788        #[serde(default)]
7789        modifiers: ConstraintModifiers,
7790    },
7791    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7792    Tags(Tags),
7793    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7794    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7795    /// for all deferrable constraints in the table
7796    InitiallyDeferred {
7797        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7798        deferred: bool,
7799    },
7800}
7801
7802/// Element in an EXCLUDE constraint: expression WITH operator
7803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7804#[cfg_attr(feature = "bindings", derive(TS))]
7805pub struct ExcludeElement {
7806    /// The column expression (may include operator class, ordering, nulls)
7807    pub expression: String,
7808    /// The operator (e.g., &&, =)
7809    pub operator: String,
7810}
7811
7812/// Action for LIKE clause options
7813#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7814#[cfg_attr(feature = "bindings", derive(TS))]
7815pub enum LikeOptionAction {
7816    Including,
7817    Excluding,
7818}
7819
7820/// MATCH type for foreign keys
7821#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7822#[cfg_attr(feature = "bindings", derive(TS))]
7823pub enum MatchType {
7824    Full,
7825    Partial,
7826    Simple,
7827}
7828
7829/// Foreign key reference
7830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7831#[cfg_attr(feature = "bindings", derive(TS))]
7832pub struct ForeignKeyRef {
7833    pub table: TableRef,
7834    pub columns: Vec<Identifier>,
7835    pub on_delete: Option<ReferentialAction>,
7836    pub on_update: Option<ReferentialAction>,
7837    /// True if ON UPDATE appears before ON DELETE in the original SQL
7838    #[serde(default)]
7839    pub on_update_first: bool,
7840    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7841    #[serde(default)]
7842    pub match_type: Option<MatchType>,
7843    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7844    #[serde(default)]
7845    pub match_after_actions: bool,
7846    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7847    #[serde(default)]
7848    pub constraint_name: Option<String>,
7849    /// DEFERRABLE / NOT DEFERRABLE
7850    #[serde(default)]
7851    pub deferrable: Option<bool>,
7852    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7853    #[serde(default)]
7854    pub has_foreign_key_keywords: bool,
7855}
7856
7857/// Referential action for foreign keys
7858#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7859#[cfg_attr(feature = "bindings", derive(TS))]
7860pub enum ReferentialAction {
7861    Cascade,
7862    SetNull,
7863    SetDefault,
7864    Restrict,
7865    NoAction,
7866}
7867
7868/// DROP TABLE statement
7869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7870#[cfg_attr(feature = "bindings", derive(TS))]
7871pub struct DropTable {
7872    pub names: Vec<TableRef>,
7873    pub if_exists: bool,
7874    pub cascade: bool,
7875    /// Oracle: CASCADE CONSTRAINTS
7876    #[serde(default)]
7877    pub cascade_constraints: bool,
7878    /// Oracle: PURGE
7879    #[serde(default)]
7880    pub purge: bool,
7881    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7882    #[serde(default)]
7883    pub leading_comments: Vec<String>,
7884    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7885    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7886    #[serde(default, skip_serializing_if = "Option::is_none")]
7887    pub object_id_args: Option<String>,
7888    /// ClickHouse: SYNC modifier
7889    #[serde(default)]
7890    pub sync: bool,
7891    /// Snowflake: DROP ICEBERG TABLE
7892    #[serde(default)]
7893    pub iceberg: bool,
7894    /// RESTRICT modifier (opposite of CASCADE)
7895    #[serde(default)]
7896    pub restrict: bool,
7897}
7898
7899impl DropTable {
7900    pub fn new(name: impl Into<String>) -> Self {
7901        Self {
7902            names: vec![TableRef::new(name)],
7903            if_exists: false,
7904            cascade: false,
7905            cascade_constraints: false,
7906            purge: false,
7907            leading_comments: Vec::new(),
7908            object_id_args: None,
7909            sync: false,
7910            iceberg: false,
7911            restrict: false,
7912        }
7913    }
7914}
7915
7916/// ALTER TABLE statement
7917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7918#[cfg_attr(feature = "bindings", derive(TS))]
7919pub struct AlterTable {
7920    pub name: TableRef,
7921    pub actions: Vec<AlterTableAction>,
7922    /// IF EXISTS clause
7923    #[serde(default)]
7924    pub if_exists: bool,
7925    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
7926    #[serde(default, skip_serializing_if = "Option::is_none")]
7927    pub algorithm: Option<String>,
7928    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
7929    #[serde(default, skip_serializing_if = "Option::is_none")]
7930    pub lock: Option<String>,
7931    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
7932    #[serde(default, skip_serializing_if = "Option::is_none")]
7933    pub with_check: Option<String>,
7934    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
7935    #[serde(default, skip_serializing_if = "Option::is_none")]
7936    pub partition: Option<Vec<(Identifier, Expression)>>,
7937    /// ClickHouse: ON CLUSTER clause for distributed DDL
7938    #[serde(default, skip_serializing_if = "Option::is_none")]
7939    pub on_cluster: Option<OnCluster>,
7940    /// Snowflake: ALTER ICEBERG TABLE
7941    #[serde(default, skip_serializing_if = "Option::is_none")]
7942    pub table_modifier: Option<String>,
7943}
7944
7945impl AlterTable {
7946    pub fn new(name: impl Into<String>) -> Self {
7947        Self {
7948            name: TableRef::new(name),
7949            actions: Vec::new(),
7950            if_exists: false,
7951            algorithm: None,
7952            lock: None,
7953            with_check: None,
7954            partition: None,
7955            on_cluster: None,
7956            table_modifier: None,
7957        }
7958    }
7959}
7960
7961/// Column position for ADD COLUMN (MySQL/MariaDB)
7962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7963#[cfg_attr(feature = "bindings", derive(TS))]
7964pub enum ColumnPosition {
7965    First,
7966    After(Identifier),
7967}
7968
7969/// Actions for ALTER TABLE
7970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7971#[cfg_attr(feature = "bindings", derive(TS))]
7972pub enum AlterTableAction {
7973    AddColumn {
7974        column: ColumnDef,
7975        if_not_exists: bool,
7976        position: Option<ColumnPosition>,
7977    },
7978    DropColumn {
7979        name: Identifier,
7980        if_exists: bool,
7981        cascade: bool,
7982    },
7983    RenameColumn {
7984        old_name: Identifier,
7985        new_name: Identifier,
7986        if_exists: bool,
7987    },
7988    AlterColumn {
7989        name: Identifier,
7990        action: AlterColumnAction,
7991        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
7992        #[serde(default)]
7993        use_modify_keyword: bool,
7994    },
7995    RenameTable(TableRef),
7996    AddConstraint(TableConstraint),
7997    DropConstraint {
7998        name: Identifier,
7999        if_exists: bool,
8000    },
8001    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8002    DropForeignKey {
8003        name: Identifier,
8004    },
8005    /// DROP PARTITION action (Hive/BigQuery)
8006    DropPartition {
8007        /// List of partitions to drop (each partition is a list of key=value pairs)
8008        partitions: Vec<Vec<(Identifier, Expression)>>,
8009        if_exists: bool,
8010    },
8011    /// ADD PARTITION action (Hive/Spark)
8012    AddPartition {
8013        /// The partition expression
8014        partition: Expression,
8015        if_not_exists: bool,
8016        location: Option<Expression>,
8017    },
8018    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8019    Delete {
8020        where_clause: Expression,
8021    },
8022    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8023    SwapWith(TableRef),
8024    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8025    SetProperty {
8026        properties: Vec<(String, Expression)>,
8027    },
8028    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8029    UnsetProperty {
8030        properties: Vec<String>,
8031    },
8032    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8033    ClusterBy {
8034        expressions: Vec<Expression>,
8035    },
8036    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8037    SetTag {
8038        expressions: Vec<(String, Expression)>,
8039    },
8040    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8041    UnsetTag {
8042        names: Vec<String>,
8043    },
8044    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8045    SetOptions {
8046        expressions: Vec<Expression>,
8047    },
8048    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8049    AlterIndex {
8050        name: Identifier,
8051        visible: bool,
8052    },
8053    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8054    SetAttribute {
8055        attribute: String,
8056    },
8057    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8058    SetStageFileFormat {
8059        options: Option<Expression>,
8060    },
8061    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8062    SetStageCopyOptions {
8063        options: Option<Expression>,
8064    },
8065    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8066    AddColumns {
8067        columns: Vec<ColumnDef>,
8068        cascade: bool,
8069    },
8070    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8071    DropColumns {
8072        names: Vec<Identifier>,
8073    },
8074    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8075    /// In SingleStore, data_type can be omitted for simple column renames
8076    ChangeColumn {
8077        old_name: Identifier,
8078        new_name: Identifier,
8079        #[serde(default, skip_serializing_if = "Option::is_none")]
8080        data_type: Option<DataType>,
8081        comment: Option<String>,
8082        #[serde(default)]
8083        cascade: bool,
8084    },
8085    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8086    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8087    AlterSortKey {
8088        /// AUTO or NONE keyword
8089        this: Option<String>,
8090        /// Column list for (col1, col2) syntax
8091        expressions: Vec<Expression>,
8092        /// Whether COMPOUND keyword was present
8093        compound: bool,
8094    },
8095    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8096    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8097    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8098    AlterDistStyle {
8099        /// Distribution style: ALL, EVEN, AUTO, or KEY
8100        style: String,
8101        /// DISTKEY column (only when style is KEY)
8102        distkey: Option<Identifier>,
8103    },
8104    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8105    SetTableProperties {
8106        properties: Vec<(Expression, Expression)>,
8107    },
8108    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8109    SetLocation {
8110        location: String,
8111    },
8112    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8113    SetFileFormat {
8114        format: String,
8115    },
8116    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8117    ReplacePartition {
8118        partition: Expression,
8119        source: Option<Box<Expression>>,
8120    },
8121    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8122    Raw {
8123        sql: String,
8124    },
8125}
8126
8127/// Actions for ALTER COLUMN
8128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8129#[cfg_attr(feature = "bindings", derive(TS))]
8130pub enum AlterColumnAction {
8131    SetDataType {
8132        data_type: DataType,
8133        /// USING expression for type conversion (PostgreSQL)
8134        using: Option<Expression>,
8135        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8136        #[serde(default, skip_serializing_if = "Option::is_none")]
8137        collate: Option<String>,
8138    },
8139    SetDefault(Expression),
8140    DropDefault,
8141    SetNotNull,
8142    DropNotNull,
8143    /// Set column comment
8144    Comment(String),
8145    /// MySQL: SET VISIBLE
8146    SetVisible,
8147    /// MySQL: SET INVISIBLE
8148    SetInvisible,
8149}
8150
8151/// CREATE INDEX statement
8152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8153#[cfg_attr(feature = "bindings", derive(TS))]
8154pub struct CreateIndex {
8155    pub name: Identifier,
8156    pub table: TableRef,
8157    pub columns: Vec<IndexColumn>,
8158    pub unique: bool,
8159    pub if_not_exists: bool,
8160    pub using: Option<String>,
8161    /// TSQL CLUSTERED/NONCLUSTERED modifier
8162    #[serde(default)]
8163    pub clustered: Option<String>,
8164    /// PostgreSQL CONCURRENTLY modifier
8165    #[serde(default)]
8166    pub concurrently: bool,
8167    /// PostgreSQL WHERE clause for partial indexes
8168    #[serde(default)]
8169    pub where_clause: Option<Box<Expression>>,
8170    /// PostgreSQL INCLUDE columns
8171    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8172    pub include_columns: Vec<Identifier>,
8173    /// TSQL WITH options (e.g., allow_page_locks=on)
8174    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8175    pub with_options: Vec<(String, String)>,
8176    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8177    #[serde(default)]
8178    pub on_filegroup: Option<String>,
8179}
8180
8181impl CreateIndex {
8182    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8183        Self {
8184            name: Identifier::new(name),
8185            table: TableRef::new(table),
8186            columns: Vec::new(),
8187            unique: false,
8188            if_not_exists: false,
8189            using: None,
8190            clustered: None,
8191            concurrently: false,
8192            where_clause: None,
8193            include_columns: Vec::new(),
8194            with_options: Vec::new(),
8195            on_filegroup: None,
8196        }
8197    }
8198}
8199
8200/// Index column specification
8201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8202#[cfg_attr(feature = "bindings", derive(TS))]
8203pub struct IndexColumn {
8204    pub column: Identifier,
8205    pub desc: bool,
8206    /// Explicit ASC keyword was present
8207    #[serde(default)]
8208    pub asc: bool,
8209    pub nulls_first: Option<bool>,
8210    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8211    #[serde(default, skip_serializing_if = "Option::is_none")]
8212    pub opclass: Option<String>,
8213}
8214
8215/// DROP INDEX statement
8216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8217#[cfg_attr(feature = "bindings", derive(TS))]
8218pub struct DropIndex {
8219    pub name: Identifier,
8220    pub table: Option<TableRef>,
8221    pub if_exists: bool,
8222    /// PostgreSQL CONCURRENTLY modifier
8223    #[serde(default)]
8224    pub concurrently: bool,
8225}
8226
8227impl DropIndex {
8228    pub fn new(name: impl Into<String>) -> Self {
8229        Self {
8230            name: Identifier::new(name),
8231            table: None,
8232            if_exists: false,
8233            concurrently: false,
8234        }
8235    }
8236}
8237
8238/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8240#[cfg_attr(feature = "bindings", derive(TS))]
8241pub struct ViewColumn {
8242    pub name: Identifier,
8243    pub comment: Option<String>,
8244    /// BigQuery: OPTIONS (key=value, ...) on column
8245    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8246    pub options: Vec<Expression>,
8247}
8248
8249impl ViewColumn {
8250    pub fn new(name: impl Into<String>) -> Self {
8251        Self {
8252            name: Identifier::new(name),
8253            comment: None,
8254            options: Vec::new(),
8255        }
8256    }
8257
8258    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8259        Self {
8260            name: Identifier::new(name),
8261            comment: Some(comment.into()),
8262            options: Vec::new(),
8263        }
8264    }
8265}
8266
8267/// CREATE VIEW statement
8268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8269#[cfg_attr(feature = "bindings", derive(TS))]
8270pub struct CreateView {
8271    pub name: TableRef,
8272    pub columns: Vec<ViewColumn>,
8273    pub query: Expression,
8274    pub or_replace: bool,
8275    /// TSQL: CREATE OR ALTER
8276    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8277    pub or_alter: bool,
8278    pub if_not_exists: bool,
8279    pub materialized: bool,
8280    pub temporary: bool,
8281    /// Snowflake: SECURE VIEW
8282    #[serde(default)]
8283    pub secure: bool,
8284    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8285    #[serde(skip_serializing_if = "Option::is_none")]
8286    pub algorithm: Option<String>,
8287    /// MySQL: DEFINER=user@host
8288    #[serde(skip_serializing_if = "Option::is_none")]
8289    pub definer: Option<String>,
8290    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8291    #[serde(skip_serializing_if = "Option::is_none")]
8292    pub security: Option<FunctionSecurity>,
8293    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8294    #[serde(default = "default_true")]
8295    pub security_sql_style: bool,
8296    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8297    #[serde(default)]
8298    pub security_after_name: bool,
8299    /// Whether the query was parenthesized: AS (SELECT ...)
8300    #[serde(default)]
8301    pub query_parenthesized: bool,
8302    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8303    #[serde(skip_serializing_if = "Option::is_none")]
8304    pub locking_mode: Option<String>,
8305    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8306    #[serde(skip_serializing_if = "Option::is_none")]
8307    pub locking_access: Option<String>,
8308    /// Snowflake: COPY GRANTS
8309    #[serde(default)]
8310    pub copy_grants: bool,
8311    /// Snowflake: COMMENT = 'text'
8312    #[serde(skip_serializing_if = "Option::is_none", default)]
8313    pub comment: Option<String>,
8314    /// Snowflake: TAG (name='value', ...)
8315    #[serde(default)]
8316    pub tags: Vec<(String, String)>,
8317    /// BigQuery: OPTIONS (key=value, ...)
8318    #[serde(default)]
8319    pub options: Vec<Expression>,
8320    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8321    #[serde(skip_serializing_if = "Option::is_none", default)]
8322    pub build: Option<String>,
8323    /// Doris: REFRESH property for materialized views
8324    #[serde(skip_serializing_if = "Option::is_none", default)]
8325    pub refresh: Option<Box<RefreshTriggerProperty>>,
8326    /// Doris: Schema with typed column definitions for materialized views
8327    /// This is used instead of `columns` when the view has typed column definitions
8328    #[serde(skip_serializing_if = "Option::is_none", default)]
8329    pub schema: Option<Box<Schema>>,
8330    /// Doris: KEY (columns) for materialized views
8331    #[serde(skip_serializing_if = "Option::is_none", default)]
8332    pub unique_key: Option<Box<UniqueKeyProperty>>,
8333    /// Redshift: WITH NO SCHEMA BINDING
8334    #[serde(default)]
8335    pub no_schema_binding: bool,
8336    /// Redshift: AUTO REFRESH YES|NO for materialized views
8337    #[serde(skip_serializing_if = "Option::is_none", default)]
8338    pub auto_refresh: Option<bool>,
8339    /// ClickHouse: ON CLUSTER clause
8340    #[serde(default, skip_serializing_if = "Option::is_none")]
8341    pub on_cluster: Option<OnCluster>,
8342    /// ClickHouse: TO destination_table
8343    #[serde(default, skip_serializing_if = "Option::is_none")]
8344    pub to_table: Option<TableRef>,
8345    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8346    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8347    pub table_properties: Vec<Expression>,
8348}
8349
8350impl CreateView {
8351    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8352        Self {
8353            name: TableRef::new(name),
8354            columns: Vec::new(),
8355            query,
8356            or_replace: false,
8357            or_alter: false,
8358            if_not_exists: false,
8359            materialized: false,
8360            temporary: false,
8361            secure: false,
8362            algorithm: None,
8363            definer: None,
8364            security: None,
8365            security_sql_style: true,
8366            security_after_name: false,
8367            query_parenthesized: false,
8368            locking_mode: None,
8369            locking_access: None,
8370            copy_grants: false,
8371            comment: None,
8372            tags: Vec::new(),
8373            options: Vec::new(),
8374            build: None,
8375            refresh: None,
8376            schema: None,
8377            unique_key: None,
8378            no_schema_binding: false,
8379            auto_refresh: None,
8380            on_cluster: None,
8381            to_table: None,
8382            table_properties: Vec::new(),
8383        }
8384    }
8385}
8386
8387/// DROP VIEW statement
8388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8389#[cfg_attr(feature = "bindings", derive(TS))]
8390pub struct DropView {
8391    pub name: TableRef,
8392    pub if_exists: bool,
8393    pub materialized: bool,
8394}
8395
8396impl DropView {
8397    pub fn new(name: impl Into<String>) -> Self {
8398        Self {
8399            name: TableRef::new(name),
8400            if_exists: false,
8401            materialized: false,
8402        }
8403    }
8404}
8405
8406/// TRUNCATE TABLE statement
8407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8408#[cfg_attr(feature = "bindings", derive(TS))]
8409pub struct Truncate {
8410    /// Target of TRUNCATE (TABLE vs DATABASE)
8411    #[serde(default)]
8412    pub target: TruncateTarget,
8413    /// IF EXISTS clause
8414    #[serde(default)]
8415    pub if_exists: bool,
8416    pub table: TableRef,
8417    /// ClickHouse: ON CLUSTER clause for distributed DDL
8418    #[serde(default, skip_serializing_if = "Option::is_none")]
8419    pub on_cluster: Option<OnCluster>,
8420    pub cascade: bool,
8421    /// Additional tables for multi-table TRUNCATE
8422    #[serde(default)]
8423    pub extra_tables: Vec<TruncateTableEntry>,
8424    /// RESTART IDENTITY or CONTINUE IDENTITY
8425    #[serde(default)]
8426    pub identity: Option<TruncateIdentity>,
8427    /// RESTRICT option (alternative to CASCADE)
8428    #[serde(default)]
8429    pub restrict: bool,
8430    /// Hive PARTITION clause: PARTITION(key=value, ...)
8431    #[serde(default, skip_serializing_if = "Option::is_none")]
8432    pub partition: Option<Box<Expression>>,
8433}
8434
8435/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8437#[cfg_attr(feature = "bindings", derive(TS))]
8438pub struct TruncateTableEntry {
8439    pub table: TableRef,
8440    /// Whether the table has a * suffix (inherit children)
8441    #[serde(default)]
8442    pub star: bool,
8443}
8444
8445/// TRUNCATE target type
8446#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8447#[cfg_attr(feature = "bindings", derive(TS))]
8448pub enum TruncateTarget {
8449    Table,
8450    Database,
8451}
8452
8453impl Default for TruncateTarget {
8454    fn default() -> Self {
8455        TruncateTarget::Table
8456    }
8457}
8458
8459/// TRUNCATE identity option
8460#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8461#[cfg_attr(feature = "bindings", derive(TS))]
8462pub enum TruncateIdentity {
8463    Restart,
8464    Continue,
8465}
8466
8467impl Truncate {
8468    pub fn new(table: impl Into<String>) -> Self {
8469        Self {
8470            target: TruncateTarget::Table,
8471            if_exists: false,
8472            table: TableRef::new(table),
8473            on_cluster: None,
8474            cascade: false,
8475            extra_tables: Vec::new(),
8476            identity: None,
8477            restrict: false,
8478            partition: None,
8479        }
8480    }
8481}
8482
8483/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8485#[cfg_attr(feature = "bindings", derive(TS))]
8486pub struct Use {
8487    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8488    pub kind: Option<UseKind>,
8489    /// The name of the object
8490    pub this: Identifier,
8491}
8492
8493/// Kind of USE statement
8494#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8495#[cfg_attr(feature = "bindings", derive(TS))]
8496pub enum UseKind {
8497    Database,
8498    Schema,
8499    Role,
8500    Warehouse,
8501    Catalog,
8502    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8503    SecondaryRoles,
8504}
8505
8506/// SET variable statement
8507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8508#[cfg_attr(feature = "bindings", derive(TS))]
8509pub struct SetStatement {
8510    /// The items being set
8511    pub items: Vec<SetItem>,
8512}
8513
8514/// A single SET item (variable assignment)
8515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8516#[cfg_attr(feature = "bindings", derive(TS))]
8517pub struct SetItem {
8518    /// The variable name
8519    pub name: Expression,
8520    /// The value to set
8521    pub value: Expression,
8522    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8523    pub kind: Option<String>,
8524    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8525    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8526    pub no_equals: bool,
8527}
8528
8529/// CACHE TABLE statement (Spark)
8530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8531#[cfg_attr(feature = "bindings", derive(TS))]
8532pub struct Cache {
8533    /// The table to cache
8534    pub table: Identifier,
8535    /// LAZY keyword - defer caching until first use
8536    pub lazy: bool,
8537    /// Optional OPTIONS clause (key-value pairs)
8538    pub options: Vec<(Expression, Expression)>,
8539    /// Optional AS clause with query
8540    pub query: Option<Expression>,
8541}
8542
8543/// UNCACHE TABLE statement (Spark)
8544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8545#[cfg_attr(feature = "bindings", derive(TS))]
8546pub struct Uncache {
8547    /// The table to uncache
8548    pub table: Identifier,
8549    /// IF EXISTS clause
8550    pub if_exists: bool,
8551}
8552
8553/// LOAD DATA statement (Hive)
8554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8555#[cfg_attr(feature = "bindings", derive(TS))]
8556pub struct LoadData {
8557    /// LOCAL keyword - load from local filesystem
8558    pub local: bool,
8559    /// The path to load data from (INPATH value)
8560    pub inpath: String,
8561    /// Whether to overwrite existing data
8562    pub overwrite: bool,
8563    /// The target table
8564    pub table: Expression,
8565    /// Optional PARTITION clause with key-value pairs
8566    pub partition: Vec<(Identifier, Expression)>,
8567    /// Optional INPUTFORMAT clause
8568    pub input_format: Option<String>,
8569    /// Optional SERDE clause
8570    pub serde: Option<String>,
8571}
8572
8573/// PRAGMA statement (SQLite)
8574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8575#[cfg_attr(feature = "bindings", derive(TS))]
8576pub struct Pragma {
8577    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8578    pub schema: Option<Identifier>,
8579    /// The pragma name
8580    pub name: Identifier,
8581    /// Optional value for assignment (PRAGMA name = value)
8582    pub value: Option<Expression>,
8583    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8584    pub args: Vec<Expression>,
8585}
8586
8587/// A privilege with optional column list for GRANT/REVOKE
8588/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8590#[cfg_attr(feature = "bindings", derive(TS))]
8591pub struct Privilege {
8592    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8593    pub name: String,
8594    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8595    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8596    pub columns: Vec<String>,
8597}
8598
8599/// Principal in GRANT/REVOKE (user, role, etc.)
8600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8601#[cfg_attr(feature = "bindings", derive(TS))]
8602pub struct GrantPrincipal {
8603    /// The name of the principal
8604    pub name: Identifier,
8605    /// Whether prefixed with ROLE keyword
8606    pub is_role: bool,
8607    /// Whether prefixed with GROUP keyword (Redshift)
8608    #[serde(default)]
8609    pub is_group: bool,
8610    /// Whether prefixed with SHARE keyword (Snowflake)
8611    #[serde(default)]
8612    pub is_share: bool,
8613}
8614
8615/// GRANT statement
8616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8617#[cfg_attr(feature = "bindings", derive(TS))]
8618pub struct Grant {
8619    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8620    pub privileges: Vec<Privilege>,
8621    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8622    pub kind: Option<String>,
8623    /// The object to grant on
8624    pub securable: Identifier,
8625    /// Function parameter types (for FUNCTION kind)
8626    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8627    pub function_params: Vec<String>,
8628    /// The grantees
8629    pub principals: Vec<GrantPrincipal>,
8630    /// WITH GRANT OPTION
8631    pub grant_option: bool,
8632    /// TSQL: AS principal (the grantor role)
8633    #[serde(default, skip_serializing_if = "Option::is_none")]
8634    pub as_principal: Option<Identifier>,
8635}
8636
8637/// REVOKE statement
8638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8639#[cfg_attr(feature = "bindings", derive(TS))]
8640pub struct Revoke {
8641    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8642    pub privileges: Vec<Privilege>,
8643    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8644    pub kind: Option<String>,
8645    /// The object to revoke from
8646    pub securable: Identifier,
8647    /// Function parameter types (for FUNCTION kind)
8648    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8649    pub function_params: Vec<String>,
8650    /// The grantees
8651    pub principals: Vec<GrantPrincipal>,
8652    /// GRANT OPTION FOR
8653    pub grant_option: bool,
8654    /// CASCADE
8655    pub cascade: bool,
8656    /// RESTRICT
8657    #[serde(default)]
8658    pub restrict: bool,
8659}
8660
8661/// COMMENT ON statement
8662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8663#[cfg_attr(feature = "bindings", derive(TS))]
8664pub struct Comment {
8665    /// The object being commented on
8666    pub this: Expression,
8667    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8668    pub kind: String,
8669    /// The comment text expression
8670    pub expression: Expression,
8671    /// IF EXISTS clause
8672    pub exists: bool,
8673    /// MATERIALIZED keyword
8674    pub materialized: bool,
8675}
8676
8677// ============================================================================
8678// Phase 4: Additional DDL Statements
8679// ============================================================================
8680
8681/// ALTER VIEW statement
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct AlterView {
8685    pub name: TableRef,
8686    pub actions: Vec<AlterViewAction>,
8687    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8688    #[serde(default, skip_serializing_if = "Option::is_none")]
8689    pub algorithm: Option<String>,
8690    /// MySQL: DEFINER = 'user'@'host'
8691    #[serde(default, skip_serializing_if = "Option::is_none")]
8692    pub definer: Option<String>,
8693    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8694    #[serde(default, skip_serializing_if = "Option::is_none")]
8695    pub sql_security: Option<String>,
8696    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8697    #[serde(default, skip_serializing_if = "Option::is_none")]
8698    pub with_option: Option<String>,
8699    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8700    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8701    pub columns: Vec<ViewColumn>,
8702}
8703
8704/// Actions for ALTER VIEW
8705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8706#[cfg_attr(feature = "bindings", derive(TS))]
8707pub enum AlterViewAction {
8708    /// Rename the view
8709    Rename(TableRef),
8710    /// Change owner
8711    OwnerTo(Identifier),
8712    /// Set schema
8713    SetSchema(Identifier),
8714    /// Set authorization (Trino/Presto)
8715    SetAuthorization(String),
8716    /// Alter column
8717    AlterColumn {
8718        name: Identifier,
8719        action: AlterColumnAction,
8720    },
8721    /// Redefine view as query (SELECT, UNION, etc.)
8722    AsSelect(Box<Expression>),
8723    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8724    SetTblproperties(Vec<(String, String)>),
8725    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8726    UnsetTblproperties(Vec<String>),
8727}
8728
8729impl AlterView {
8730    pub fn new(name: impl Into<String>) -> Self {
8731        Self {
8732            name: TableRef::new(name),
8733            actions: Vec::new(),
8734            algorithm: None,
8735            definer: None,
8736            sql_security: None,
8737            with_option: None,
8738            columns: Vec::new(),
8739        }
8740    }
8741}
8742
8743/// ALTER INDEX statement
8744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8745#[cfg_attr(feature = "bindings", derive(TS))]
8746pub struct AlterIndex {
8747    pub name: Identifier,
8748    pub table: Option<TableRef>,
8749    pub actions: Vec<AlterIndexAction>,
8750}
8751
8752/// Actions for ALTER INDEX
8753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8754#[cfg_attr(feature = "bindings", derive(TS))]
8755pub enum AlterIndexAction {
8756    /// Rename the index
8757    Rename(Identifier),
8758    /// Set tablespace
8759    SetTablespace(Identifier),
8760    /// Set visibility (MySQL)
8761    Visible(bool),
8762}
8763
8764impl AlterIndex {
8765    pub fn new(name: impl Into<String>) -> Self {
8766        Self {
8767            name: Identifier::new(name),
8768            table: None,
8769            actions: Vec::new(),
8770        }
8771    }
8772}
8773
8774/// CREATE SCHEMA statement
8775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8776#[cfg_attr(feature = "bindings", derive(TS))]
8777pub struct CreateSchema {
8778    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8779    pub name: Vec<Identifier>,
8780    pub if_not_exists: bool,
8781    pub authorization: Option<Identifier>,
8782    /// CLONE source parts, possibly dot-qualified
8783    #[serde(default)]
8784    pub clone_from: Option<Vec<Identifier>>,
8785    /// AT/BEFORE clause for time travel (Snowflake)
8786    #[serde(default)]
8787    pub at_clause: Option<Expression>,
8788    /// Schema properties like DEFAULT COLLATE
8789    #[serde(default)]
8790    pub properties: Vec<Expression>,
8791    /// Leading comments before the statement
8792    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8793    pub leading_comments: Vec<String>,
8794}
8795
8796impl CreateSchema {
8797    pub fn new(name: impl Into<String>) -> Self {
8798        Self {
8799            name: vec![Identifier::new(name)],
8800            if_not_exists: false,
8801            authorization: None,
8802            clone_from: None,
8803            at_clause: None,
8804            properties: Vec::new(),
8805            leading_comments: Vec::new(),
8806        }
8807    }
8808}
8809
8810/// DROP SCHEMA statement
8811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8812#[cfg_attr(feature = "bindings", derive(TS))]
8813pub struct DropSchema {
8814    pub name: Identifier,
8815    pub if_exists: bool,
8816    pub cascade: bool,
8817}
8818
8819impl DropSchema {
8820    pub fn new(name: impl Into<String>) -> Self {
8821        Self {
8822            name: Identifier::new(name),
8823            if_exists: false,
8824            cascade: false,
8825        }
8826    }
8827}
8828
8829/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8831#[cfg_attr(feature = "bindings", derive(TS))]
8832pub struct DropNamespace {
8833    pub name: Identifier,
8834    pub if_exists: bool,
8835    pub cascade: bool,
8836}
8837
8838impl DropNamespace {
8839    pub fn new(name: impl Into<String>) -> Self {
8840        Self {
8841            name: Identifier::new(name),
8842            if_exists: false,
8843            cascade: false,
8844        }
8845    }
8846}
8847
8848/// CREATE DATABASE statement
8849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8850#[cfg_attr(feature = "bindings", derive(TS))]
8851pub struct CreateDatabase {
8852    pub name: Identifier,
8853    pub if_not_exists: bool,
8854    pub options: Vec<DatabaseOption>,
8855    /// Snowflake CLONE source
8856    #[serde(default)]
8857    pub clone_from: Option<Identifier>,
8858    /// AT/BEFORE clause for time travel (Snowflake)
8859    #[serde(default)]
8860    pub at_clause: Option<Expression>,
8861}
8862
8863/// Database option
8864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8865#[cfg_attr(feature = "bindings", derive(TS))]
8866pub enum DatabaseOption {
8867    CharacterSet(String),
8868    Collate(String),
8869    Owner(Identifier),
8870    Template(Identifier),
8871    Encoding(String),
8872    Location(String),
8873}
8874
8875impl CreateDatabase {
8876    pub fn new(name: impl Into<String>) -> Self {
8877        Self {
8878            name: Identifier::new(name),
8879            if_not_exists: false,
8880            options: Vec::new(),
8881            clone_from: None,
8882            at_clause: None,
8883        }
8884    }
8885}
8886
8887/// DROP DATABASE statement
8888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8889#[cfg_attr(feature = "bindings", derive(TS))]
8890pub struct DropDatabase {
8891    pub name: Identifier,
8892    pub if_exists: bool,
8893    /// ClickHouse: SYNC modifier
8894    #[serde(default)]
8895    pub sync: bool,
8896}
8897
8898impl DropDatabase {
8899    pub fn new(name: impl Into<String>) -> Self {
8900        Self {
8901            name: Identifier::new(name),
8902            if_exists: false,
8903            sync: false,
8904        }
8905    }
8906}
8907
8908/// CREATE FUNCTION statement
8909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8910#[cfg_attr(feature = "bindings", derive(TS))]
8911pub struct CreateFunction {
8912    pub name: TableRef,
8913    pub parameters: Vec<FunctionParameter>,
8914    pub return_type: Option<DataType>,
8915    pub body: Option<FunctionBody>,
8916    pub or_replace: bool,
8917    /// TSQL: CREATE OR ALTER
8918    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8919    pub or_alter: bool,
8920    pub if_not_exists: bool,
8921    pub temporary: bool,
8922    pub language: Option<String>,
8923    pub deterministic: Option<bool>,
8924    pub returns_null_on_null_input: Option<bool>,
8925    pub security: Option<FunctionSecurity>,
8926    /// Whether parentheses were present in the original syntax
8927    #[serde(default = "default_true")]
8928    pub has_parens: bool,
8929    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
8930    #[serde(default)]
8931    pub sql_data_access: Option<SqlDataAccess>,
8932    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
8933    #[serde(default, skip_serializing_if = "Option::is_none")]
8934    pub returns_table_body: Option<String>,
8935    /// True if LANGUAGE clause appears before RETURNS clause
8936    #[serde(default)]
8937    pub language_first: bool,
8938    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
8939    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8940    pub set_options: Vec<FunctionSetOption>,
8941    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
8942    #[serde(default)]
8943    pub strict: bool,
8944    /// BigQuery: OPTIONS (key=value, ...)
8945    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8946    pub options: Vec<Expression>,
8947    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
8948    #[serde(default)]
8949    pub is_table_function: bool,
8950    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
8951    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8952    pub property_order: Vec<FunctionPropertyKind>,
8953    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
8954    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8955    pub environment: Vec<Expression>,
8956    /// HANDLER 'handler_function' clause (Databricks)
8957    #[serde(default, skip_serializing_if = "Option::is_none")]
8958    pub handler: Option<String>,
8959    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
8960    #[serde(default, skip_serializing_if = "Option::is_none")]
8961    pub parameter_style: Option<String>,
8962}
8963
8964/// A SET option in CREATE FUNCTION (PostgreSQL)
8965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8966#[cfg_attr(feature = "bindings", derive(TS))]
8967pub struct FunctionSetOption {
8968    pub name: String,
8969    pub value: FunctionSetValue,
8970}
8971
8972/// The value of a SET option
8973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8974#[cfg_attr(feature = "bindings", derive(TS))]
8975pub enum FunctionSetValue {
8976    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
8977    Value { value: String, use_to: bool },
8978    /// SET key FROM CURRENT
8979    FromCurrent,
8980}
8981
8982/// SQL data access characteristics for functions
8983#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8984#[cfg_attr(feature = "bindings", derive(TS))]
8985pub enum SqlDataAccess {
8986    /// NO SQL
8987    NoSql,
8988    /// CONTAINS SQL
8989    ContainsSql,
8990    /// READS SQL DATA
8991    ReadsSqlData,
8992    /// MODIFIES SQL DATA
8993    ModifiesSqlData,
8994}
8995
8996/// Types of properties in CREATE FUNCTION for tracking their original order
8997#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8998#[cfg_attr(feature = "bindings", derive(TS))]
8999pub enum FunctionPropertyKind {
9000    /// SET option
9001    Set,
9002    /// AS body
9003    As,
9004    /// LANGUAGE clause
9005    Language,
9006    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9007    Determinism,
9008    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9009    NullInput,
9010    /// SECURITY DEFINER/INVOKER
9011    Security,
9012    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9013    SqlDataAccess,
9014    /// OPTIONS clause (BigQuery)
9015    Options,
9016    /// ENVIRONMENT clause (Databricks)
9017    Environment,
9018    /// HANDLER clause (Databricks)
9019    Handler,
9020    /// PARAMETER STYLE clause (Databricks)
9021    ParameterStyle,
9022}
9023
9024/// Function parameter
9025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9026#[cfg_attr(feature = "bindings", derive(TS))]
9027pub struct FunctionParameter {
9028    pub name: Option<Identifier>,
9029    pub data_type: DataType,
9030    pub mode: Option<ParameterMode>,
9031    pub default: Option<Expression>,
9032    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9033    #[serde(default, skip_serializing_if = "Option::is_none")]
9034    pub mode_text: Option<String>,
9035}
9036
9037/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9038#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9039#[cfg_attr(feature = "bindings", derive(TS))]
9040pub enum ParameterMode {
9041    In,
9042    Out,
9043    InOut,
9044    Variadic,
9045}
9046
9047/// Function body
9048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9049#[cfg_attr(feature = "bindings", derive(TS))]
9050pub enum FunctionBody {
9051    /// AS $$ ... $$ (dollar-quoted)
9052    Block(String),
9053    /// AS 'string' (single-quoted string literal body)
9054    StringLiteral(String),
9055    /// AS 'expression'
9056    Expression(Expression),
9057    /// EXTERNAL NAME 'library'
9058    External(String),
9059    /// RETURN expression
9060    Return(Expression),
9061    /// BEGIN ... END block with parsed statements
9062    Statements(Vec<Expression>),
9063    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9064    /// Stores (content, optional_tag)
9065    DollarQuoted {
9066        content: String,
9067        tag: Option<String>,
9068    },
9069}
9070
9071/// Function security (DEFINER, INVOKER, or NONE)
9072#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9073#[cfg_attr(feature = "bindings", derive(TS))]
9074pub enum FunctionSecurity {
9075    Definer,
9076    Invoker,
9077    /// StarRocks/MySQL: SECURITY NONE
9078    None,
9079}
9080
9081impl CreateFunction {
9082    pub fn new(name: impl Into<String>) -> Self {
9083        Self {
9084            name: TableRef::new(name),
9085            parameters: Vec::new(),
9086            return_type: None,
9087            body: None,
9088            or_replace: false,
9089            or_alter: false,
9090            if_not_exists: false,
9091            temporary: false,
9092            language: None,
9093            deterministic: None,
9094            returns_null_on_null_input: None,
9095            security: None,
9096            has_parens: true,
9097            sql_data_access: None,
9098            returns_table_body: None,
9099            language_first: false,
9100            set_options: Vec::new(),
9101            strict: false,
9102            options: Vec::new(),
9103            is_table_function: false,
9104            property_order: Vec::new(),
9105            environment: Vec::new(),
9106            handler: None,
9107            parameter_style: None,
9108        }
9109    }
9110}
9111
9112/// DROP FUNCTION statement
9113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9114#[cfg_attr(feature = "bindings", derive(TS))]
9115pub struct DropFunction {
9116    pub name: TableRef,
9117    pub parameters: Option<Vec<DataType>>,
9118    pub if_exists: bool,
9119    pub cascade: bool,
9120}
9121
9122impl DropFunction {
9123    pub fn new(name: impl Into<String>) -> Self {
9124        Self {
9125            name: TableRef::new(name),
9126            parameters: None,
9127            if_exists: false,
9128            cascade: false,
9129        }
9130    }
9131}
9132
9133/// CREATE PROCEDURE statement
9134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9135#[cfg_attr(feature = "bindings", derive(TS))]
9136pub struct CreateProcedure {
9137    pub name: TableRef,
9138    pub parameters: Vec<FunctionParameter>,
9139    pub body: Option<FunctionBody>,
9140    pub or_replace: bool,
9141    /// TSQL: CREATE OR ALTER
9142    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9143    pub or_alter: bool,
9144    pub if_not_exists: bool,
9145    pub language: Option<String>,
9146    pub security: Option<FunctionSecurity>,
9147    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9148    #[serde(default)]
9149    pub return_type: Option<DataType>,
9150    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9151    #[serde(default)]
9152    pub execute_as: Option<String>,
9153    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9154    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9155    pub with_options: Vec<String>,
9156    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9157    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9158    pub has_parens: bool,
9159    /// Whether the short form PROC was used (instead of PROCEDURE)
9160    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9161    pub use_proc_keyword: bool,
9162}
9163
9164impl CreateProcedure {
9165    pub fn new(name: impl Into<String>) -> Self {
9166        Self {
9167            name: TableRef::new(name),
9168            parameters: Vec::new(),
9169            body: None,
9170            or_replace: false,
9171            or_alter: false,
9172            if_not_exists: false,
9173            language: None,
9174            security: None,
9175            return_type: None,
9176            execute_as: None,
9177            with_options: Vec::new(),
9178            has_parens: true,
9179            use_proc_keyword: false,
9180        }
9181    }
9182}
9183
9184/// DROP PROCEDURE statement
9185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9186#[cfg_attr(feature = "bindings", derive(TS))]
9187pub struct DropProcedure {
9188    pub name: TableRef,
9189    pub parameters: Option<Vec<DataType>>,
9190    pub if_exists: bool,
9191    pub cascade: bool,
9192}
9193
9194impl DropProcedure {
9195    pub fn new(name: impl Into<String>) -> Self {
9196        Self {
9197            name: TableRef::new(name),
9198            parameters: None,
9199            if_exists: false,
9200            cascade: false,
9201        }
9202    }
9203}
9204
9205/// Sequence property tag for ordering
9206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9207#[cfg_attr(feature = "bindings", derive(TS))]
9208pub enum SeqPropKind {
9209    Start,
9210    Increment,
9211    Minvalue,
9212    Maxvalue,
9213    Cache,
9214    NoCache,
9215    Cycle,
9216    NoCycle,
9217    OwnedBy,
9218    Order,
9219    NoOrder,
9220    Comment,
9221    /// SHARING=<value> (Oracle)
9222    Sharing,
9223    /// KEEP (Oracle)
9224    Keep,
9225    /// NOKEEP (Oracle)
9226    NoKeep,
9227    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9228    Scale,
9229    /// NOSCALE (Oracle)
9230    NoScale,
9231    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9232    Shard,
9233    /// NOSHARD (Oracle)
9234    NoShard,
9235    /// SESSION (Oracle)
9236    Session,
9237    /// GLOBAL (Oracle)
9238    Global,
9239    /// NOCACHE (single word, Oracle)
9240    NoCacheWord,
9241    /// NOCYCLE (single word, Oracle)
9242    NoCycleWord,
9243    /// NOMINVALUE (single word, Oracle)
9244    NoMinvalueWord,
9245    /// NOMAXVALUE (single word, Oracle)
9246    NoMaxvalueWord,
9247}
9248
9249/// CREATE SYNONYM statement (TSQL)
9250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9251#[cfg_attr(feature = "bindings", derive(TS))]
9252pub struct CreateSynonym {
9253    /// The synonym name (can be qualified: schema.synonym_name)
9254    pub name: TableRef,
9255    /// The target object the synonym refers to
9256    pub target: TableRef,
9257}
9258
9259/// CREATE SEQUENCE statement
9260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9261#[cfg_attr(feature = "bindings", derive(TS))]
9262pub struct CreateSequence {
9263    pub name: TableRef,
9264    pub if_not_exists: bool,
9265    pub temporary: bool,
9266    #[serde(default)]
9267    pub or_replace: bool,
9268    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9269    #[serde(default, skip_serializing_if = "Option::is_none")]
9270    pub as_type: Option<DataType>,
9271    pub increment: Option<i64>,
9272    pub minvalue: Option<SequenceBound>,
9273    pub maxvalue: Option<SequenceBound>,
9274    pub start: Option<i64>,
9275    pub cache: Option<i64>,
9276    pub cycle: bool,
9277    pub owned_by: Option<TableRef>,
9278    /// Whether OWNED BY NONE was specified
9279    #[serde(default)]
9280    pub owned_by_none: bool,
9281    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9282    #[serde(default)]
9283    pub order: Option<bool>,
9284    /// Snowflake: COMMENT = 'value'
9285    #[serde(default)]
9286    pub comment: Option<String>,
9287    /// SHARING=<value> (Oracle)
9288    #[serde(default, skip_serializing_if = "Option::is_none")]
9289    pub sharing: Option<String>,
9290    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9291    #[serde(default, skip_serializing_if = "Option::is_none")]
9292    pub scale_modifier: Option<String>,
9293    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9294    #[serde(default, skip_serializing_if = "Option::is_none")]
9295    pub shard_modifier: Option<String>,
9296    /// Tracks the order in which properties appeared in the source
9297    #[serde(default)]
9298    pub property_order: Vec<SeqPropKind>,
9299}
9300
9301/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9303#[cfg_attr(feature = "bindings", derive(TS))]
9304pub enum SequenceBound {
9305    Value(i64),
9306    None,
9307}
9308
9309impl CreateSequence {
9310    pub fn new(name: impl Into<String>) -> Self {
9311        Self {
9312            name: TableRef::new(name),
9313            if_not_exists: false,
9314            temporary: false,
9315            or_replace: false,
9316            as_type: None,
9317            increment: None,
9318            minvalue: None,
9319            maxvalue: None,
9320            start: None,
9321            cache: None,
9322            cycle: false,
9323            owned_by: None,
9324            owned_by_none: false,
9325            order: None,
9326            comment: None,
9327            sharing: None,
9328            scale_modifier: None,
9329            shard_modifier: None,
9330            property_order: Vec::new(),
9331        }
9332    }
9333}
9334
9335/// DROP SEQUENCE statement
9336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9337#[cfg_attr(feature = "bindings", derive(TS))]
9338pub struct DropSequence {
9339    pub name: TableRef,
9340    pub if_exists: bool,
9341    pub cascade: bool,
9342}
9343
9344impl DropSequence {
9345    pub fn new(name: impl Into<String>) -> Self {
9346        Self {
9347            name: TableRef::new(name),
9348            if_exists: false,
9349            cascade: false,
9350        }
9351    }
9352}
9353
9354/// ALTER SEQUENCE statement
9355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9356#[cfg_attr(feature = "bindings", derive(TS))]
9357pub struct AlterSequence {
9358    pub name: TableRef,
9359    pub if_exists: bool,
9360    pub increment: Option<i64>,
9361    pub minvalue: Option<SequenceBound>,
9362    pub maxvalue: Option<SequenceBound>,
9363    pub start: Option<i64>,
9364    pub restart: Option<Option<i64>>,
9365    pub cache: Option<i64>,
9366    pub cycle: Option<bool>,
9367    pub owned_by: Option<Option<TableRef>>,
9368}
9369
9370impl AlterSequence {
9371    pub fn new(name: impl Into<String>) -> Self {
9372        Self {
9373            name: TableRef::new(name),
9374            if_exists: false,
9375            increment: None,
9376            minvalue: None,
9377            maxvalue: None,
9378            start: None,
9379            restart: None,
9380            cache: None,
9381            cycle: None,
9382            owned_by: None,
9383        }
9384    }
9385}
9386
9387/// CREATE TRIGGER statement
9388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9389#[cfg_attr(feature = "bindings", derive(TS))]
9390pub struct CreateTrigger {
9391    pub name: Identifier,
9392    pub table: TableRef,
9393    pub timing: TriggerTiming,
9394    pub events: Vec<TriggerEvent>,
9395    #[serde(default, skip_serializing_if = "Option::is_none")]
9396    pub for_each: Option<TriggerForEach>,
9397    pub when: Option<Expression>,
9398    /// Whether the WHEN clause was parenthesized in the original SQL
9399    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9400    pub when_paren: bool,
9401    pub body: TriggerBody,
9402    pub or_replace: bool,
9403    /// TSQL: CREATE OR ALTER
9404    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9405    pub or_alter: bool,
9406    pub constraint: bool,
9407    pub deferrable: Option<bool>,
9408    pub initially_deferred: Option<bool>,
9409    pub referencing: Option<TriggerReferencing>,
9410}
9411
9412/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9413#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9414#[cfg_attr(feature = "bindings", derive(TS))]
9415pub enum TriggerTiming {
9416    Before,
9417    After,
9418    InsteadOf,
9419}
9420
9421/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9423#[cfg_attr(feature = "bindings", derive(TS))]
9424pub enum TriggerEvent {
9425    Insert,
9426    Update(Option<Vec<Identifier>>),
9427    Delete,
9428    Truncate,
9429}
9430
9431/// Trigger FOR EACH clause
9432#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub enum TriggerForEach {
9435    Row,
9436    Statement,
9437}
9438
9439/// Trigger body
9440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9441#[cfg_attr(feature = "bindings", derive(TS))]
9442pub enum TriggerBody {
9443    /// EXECUTE FUNCTION/PROCEDURE name(args)
9444    Execute {
9445        function: TableRef,
9446        args: Vec<Expression>,
9447    },
9448    /// BEGIN ... END block
9449    Block(String),
9450}
9451
9452/// Trigger REFERENCING clause
9453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9454#[cfg_attr(feature = "bindings", derive(TS))]
9455pub struct TriggerReferencing {
9456    pub old_table: Option<Identifier>,
9457    pub new_table: Option<Identifier>,
9458    pub old_row: Option<Identifier>,
9459    pub new_row: Option<Identifier>,
9460}
9461
9462impl CreateTrigger {
9463    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9464        Self {
9465            name: Identifier::new(name),
9466            table: TableRef::new(table),
9467            timing: TriggerTiming::Before,
9468            events: Vec::new(),
9469            for_each: Some(TriggerForEach::Row),
9470            when: None,
9471            when_paren: false,
9472            body: TriggerBody::Execute {
9473                function: TableRef::new(""),
9474                args: Vec::new(),
9475            },
9476            or_replace: false,
9477            or_alter: false,
9478            constraint: false,
9479            deferrable: None,
9480            initially_deferred: None,
9481            referencing: None,
9482        }
9483    }
9484}
9485
9486/// DROP TRIGGER statement
9487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9488#[cfg_attr(feature = "bindings", derive(TS))]
9489pub struct DropTrigger {
9490    pub name: Identifier,
9491    pub table: Option<TableRef>,
9492    pub if_exists: bool,
9493    pub cascade: bool,
9494}
9495
9496impl DropTrigger {
9497    pub fn new(name: impl Into<String>) -> Self {
9498        Self {
9499            name: Identifier::new(name),
9500            table: None,
9501            if_exists: false,
9502            cascade: false,
9503        }
9504    }
9505}
9506
9507/// CREATE TYPE statement
9508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9509#[cfg_attr(feature = "bindings", derive(TS))]
9510pub struct CreateType {
9511    pub name: TableRef,
9512    pub definition: TypeDefinition,
9513    pub if_not_exists: bool,
9514}
9515
9516/// Type definition
9517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9518#[cfg_attr(feature = "bindings", derive(TS))]
9519pub enum TypeDefinition {
9520    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9521    Enum(Vec<String>),
9522    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9523    Composite(Vec<TypeAttribute>),
9524    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9525    Range {
9526        subtype: DataType,
9527        subtype_diff: Option<String>,
9528        canonical: Option<String>,
9529    },
9530    /// Base type (for advanced usage)
9531    Base {
9532        input: String,
9533        output: String,
9534        internallength: Option<i32>,
9535    },
9536    /// Domain type
9537    Domain {
9538        base_type: DataType,
9539        default: Option<Expression>,
9540        constraints: Vec<DomainConstraint>,
9541    },
9542}
9543
9544/// Type attribute for composite types
9545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub struct TypeAttribute {
9548    pub name: Identifier,
9549    pub data_type: DataType,
9550    pub collate: Option<Identifier>,
9551}
9552
9553/// Domain constraint
9554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9555#[cfg_attr(feature = "bindings", derive(TS))]
9556pub struct DomainConstraint {
9557    pub name: Option<Identifier>,
9558    pub check: Expression,
9559}
9560
9561impl CreateType {
9562    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9563        Self {
9564            name: TableRef::new(name),
9565            definition: TypeDefinition::Enum(values),
9566            if_not_exists: false,
9567        }
9568    }
9569
9570    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9571        Self {
9572            name: TableRef::new(name),
9573            definition: TypeDefinition::Composite(attributes),
9574            if_not_exists: false,
9575        }
9576    }
9577}
9578
9579/// DROP TYPE statement
9580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9581#[cfg_attr(feature = "bindings", derive(TS))]
9582pub struct DropType {
9583    pub name: TableRef,
9584    pub if_exists: bool,
9585    pub cascade: bool,
9586}
9587
9588impl DropType {
9589    pub fn new(name: impl Into<String>) -> Self {
9590        Self {
9591            name: TableRef::new(name),
9592            if_exists: false,
9593            cascade: false,
9594        }
9595    }
9596}
9597
9598/// DESCRIBE statement - shows table structure or query plan
9599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9600#[cfg_attr(feature = "bindings", derive(TS))]
9601pub struct Describe {
9602    /// The target to describe (table name or query)
9603    pub target: Expression,
9604    /// EXTENDED format
9605    pub extended: bool,
9606    /// FORMATTED format
9607    pub formatted: bool,
9608    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9609    #[serde(default)]
9610    pub kind: Option<String>,
9611    /// Properties like type=stage
9612    #[serde(default)]
9613    pub properties: Vec<(String, String)>,
9614    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9615    #[serde(default, skip_serializing_if = "Option::is_none")]
9616    pub style: Option<String>,
9617    /// Partition specification for DESCRIBE PARTITION
9618    #[serde(default)]
9619    pub partition: Option<Box<Expression>>,
9620    /// Leading comments before the statement
9621    #[serde(default)]
9622    pub leading_comments: Vec<String>,
9623    /// AS JSON suffix (Databricks)
9624    #[serde(default)]
9625    pub as_json: bool,
9626}
9627
9628impl Describe {
9629    pub fn new(target: Expression) -> Self {
9630        Self {
9631            target,
9632            extended: false,
9633            formatted: false,
9634            kind: None,
9635            properties: Vec::new(),
9636            style: None,
9637            partition: None,
9638            leading_comments: Vec::new(),
9639            as_json: false,
9640        }
9641    }
9642}
9643
9644/// SHOW statement - displays database objects
9645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9646#[cfg_attr(feature = "bindings", derive(TS))]
9647pub struct Show {
9648    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9649    pub this: String,
9650    /// Whether TERSE was specified
9651    #[serde(default)]
9652    pub terse: bool,
9653    /// Whether HISTORY was specified
9654    #[serde(default)]
9655    pub history: bool,
9656    /// LIKE pattern
9657    pub like: Option<Expression>,
9658    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9659    pub scope_kind: Option<String>,
9660    /// IN scope object
9661    pub scope: Option<Expression>,
9662    /// STARTS WITH pattern
9663    pub starts_with: Option<Expression>,
9664    /// LIMIT clause
9665    pub limit: Option<Box<Limit>>,
9666    /// FROM clause (for specific object)
9667    pub from: Option<Expression>,
9668    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9669    #[serde(default, skip_serializing_if = "Option::is_none")]
9670    pub where_clause: Option<Expression>,
9671    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9672    #[serde(default, skip_serializing_if = "Option::is_none")]
9673    pub for_target: Option<Expression>,
9674    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9675    #[serde(default, skip_serializing_if = "Option::is_none")]
9676    pub db: Option<Expression>,
9677    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9678    #[serde(default, skip_serializing_if = "Option::is_none")]
9679    pub target: Option<Expression>,
9680    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9681    #[serde(default, skip_serializing_if = "Option::is_none")]
9682    pub mutex: Option<bool>,
9683    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9684    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9685    pub privileges: Vec<String>,
9686}
9687
9688impl Show {
9689    pub fn new(this: impl Into<String>) -> Self {
9690        Self {
9691            this: this.into(),
9692            terse: false,
9693            history: false,
9694            like: None,
9695            scope_kind: None,
9696            scope: None,
9697            starts_with: None,
9698            limit: None,
9699            from: None,
9700            where_clause: None,
9701            for_target: None,
9702            db: None,
9703            target: None,
9704            mutex: None,
9705            privileges: Vec::new(),
9706        }
9707    }
9708}
9709
9710/// Represent an explicit parenthesized expression for grouping precedence.
9711///
9712/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9713/// correctly instead of being flattened to `a + b * c`.
9714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9715#[cfg_attr(feature = "bindings", derive(TS))]
9716pub struct Paren {
9717    /// The inner expression wrapped by parentheses.
9718    pub this: Expression,
9719    #[serde(default)]
9720    pub trailing_comments: Vec<String>,
9721}
9722
9723/// Expression annotated with trailing comments (for round-trip preservation)
9724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9725#[cfg_attr(feature = "bindings", derive(TS))]
9726pub struct Annotated {
9727    pub this: Expression,
9728    pub trailing_comments: Vec<String>,
9729}
9730
9731// === BATCH GENERATED STRUCT DEFINITIONS ===
9732// Generated from Python sqlglot expressions.py
9733
9734/// Refresh
9735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9736#[cfg_attr(feature = "bindings", derive(TS))]
9737pub struct Refresh {
9738    pub this: Box<Expression>,
9739    pub kind: String,
9740}
9741
9742/// LockingStatement
9743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9744#[cfg_attr(feature = "bindings", derive(TS))]
9745pub struct LockingStatement {
9746    pub this: Box<Expression>,
9747    pub expression: Box<Expression>,
9748}
9749
9750/// SequenceProperties
9751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9752#[cfg_attr(feature = "bindings", derive(TS))]
9753pub struct SequenceProperties {
9754    #[serde(default)]
9755    pub increment: Option<Box<Expression>>,
9756    #[serde(default)]
9757    pub minvalue: Option<Box<Expression>>,
9758    #[serde(default)]
9759    pub maxvalue: Option<Box<Expression>>,
9760    #[serde(default)]
9761    pub cache: Option<Box<Expression>>,
9762    #[serde(default)]
9763    pub start: Option<Box<Expression>>,
9764    #[serde(default)]
9765    pub owned: Option<Box<Expression>>,
9766    #[serde(default)]
9767    pub options: Vec<Expression>,
9768}
9769
9770/// TruncateTable
9771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9772#[cfg_attr(feature = "bindings", derive(TS))]
9773pub struct TruncateTable {
9774    #[serde(default)]
9775    pub expressions: Vec<Expression>,
9776    #[serde(default)]
9777    pub is_database: Option<Box<Expression>>,
9778    #[serde(default)]
9779    pub exists: bool,
9780    #[serde(default)]
9781    pub only: Option<Box<Expression>>,
9782    #[serde(default)]
9783    pub cluster: Option<Box<Expression>>,
9784    #[serde(default)]
9785    pub identity: Option<Box<Expression>>,
9786    #[serde(default)]
9787    pub option: Option<Box<Expression>>,
9788    #[serde(default)]
9789    pub partition: Option<Box<Expression>>,
9790}
9791
9792/// Clone
9793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9794#[cfg_attr(feature = "bindings", derive(TS))]
9795pub struct Clone {
9796    pub this: Box<Expression>,
9797    #[serde(default)]
9798    pub shallow: Option<Box<Expression>>,
9799    #[serde(default)]
9800    pub copy: Option<Box<Expression>>,
9801}
9802
9803/// Attach
9804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9805#[cfg_attr(feature = "bindings", derive(TS))]
9806pub struct Attach {
9807    pub this: Box<Expression>,
9808    #[serde(default)]
9809    pub exists: bool,
9810    #[serde(default)]
9811    pub expressions: Vec<Expression>,
9812}
9813
9814/// Detach
9815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9816#[cfg_attr(feature = "bindings", derive(TS))]
9817pub struct Detach {
9818    pub this: Box<Expression>,
9819    #[serde(default)]
9820    pub exists: bool,
9821}
9822
9823/// Install
9824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9825#[cfg_attr(feature = "bindings", derive(TS))]
9826pub struct Install {
9827    pub this: Box<Expression>,
9828    #[serde(default)]
9829    pub from_: Option<Box<Expression>>,
9830    #[serde(default)]
9831    pub force: Option<Box<Expression>>,
9832}
9833
9834/// Summarize
9835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9836#[cfg_attr(feature = "bindings", derive(TS))]
9837pub struct Summarize {
9838    pub this: Box<Expression>,
9839    #[serde(default)]
9840    pub table: Option<Box<Expression>>,
9841}
9842
9843/// Declare
9844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9845#[cfg_attr(feature = "bindings", derive(TS))]
9846pub struct Declare {
9847    #[serde(default)]
9848    pub expressions: Vec<Expression>,
9849    #[serde(default)]
9850    pub replace: bool,
9851}
9852
9853/// DeclareItem
9854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9855#[cfg_attr(feature = "bindings", derive(TS))]
9856pub struct DeclareItem {
9857    pub this: Box<Expression>,
9858    #[serde(default)]
9859    pub kind: Option<String>,
9860    #[serde(default)]
9861    pub default: Option<Box<Expression>>,
9862    #[serde(default)]
9863    pub has_as: bool,
9864    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
9865    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9866    pub additional_names: Vec<Expression>,
9867}
9868
9869/// Set
9870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9871#[cfg_attr(feature = "bindings", derive(TS))]
9872pub struct Set {
9873    #[serde(default)]
9874    pub expressions: Vec<Expression>,
9875    #[serde(default)]
9876    pub unset: Option<Box<Expression>>,
9877    #[serde(default)]
9878    pub tag: Option<Box<Expression>>,
9879}
9880
9881/// Heredoc
9882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9883#[cfg_attr(feature = "bindings", derive(TS))]
9884pub struct Heredoc {
9885    pub this: Box<Expression>,
9886    #[serde(default)]
9887    pub tag: Option<Box<Expression>>,
9888}
9889
9890/// QueryBand
9891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9892#[cfg_attr(feature = "bindings", derive(TS))]
9893pub struct QueryBand {
9894    pub this: Box<Expression>,
9895    #[serde(default)]
9896    pub scope: Option<Box<Expression>>,
9897    #[serde(default)]
9898    pub update: Option<Box<Expression>>,
9899}
9900
9901/// UserDefinedFunction
9902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9903#[cfg_attr(feature = "bindings", derive(TS))]
9904pub struct UserDefinedFunction {
9905    pub this: Box<Expression>,
9906    #[serde(default)]
9907    pub expressions: Vec<Expression>,
9908    #[serde(default)]
9909    pub wrapped: Option<Box<Expression>>,
9910}
9911
9912/// RecursiveWithSearch
9913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9914#[cfg_attr(feature = "bindings", derive(TS))]
9915pub struct RecursiveWithSearch {
9916    pub kind: String,
9917    pub this: Box<Expression>,
9918    pub expression: Box<Expression>,
9919    #[serde(default)]
9920    pub using: Option<Box<Expression>>,
9921}
9922
9923/// ProjectionDef
9924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9925#[cfg_attr(feature = "bindings", derive(TS))]
9926pub struct ProjectionDef {
9927    pub this: Box<Expression>,
9928    pub expression: Box<Expression>,
9929}
9930
9931/// TableAlias
9932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9933#[cfg_attr(feature = "bindings", derive(TS))]
9934pub struct TableAlias {
9935    #[serde(default)]
9936    pub this: Option<Box<Expression>>,
9937    #[serde(default)]
9938    pub columns: Vec<Expression>,
9939}
9940
9941/// ByteString
9942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9943#[cfg_attr(feature = "bindings", derive(TS))]
9944pub struct ByteString {
9945    pub this: Box<Expression>,
9946    #[serde(default)]
9947    pub is_bytes: Option<Box<Expression>>,
9948}
9949
9950/// HexStringExpr - Hex string expression (not literal)
9951/// BigQuery: converts to FROM_HEX(this)
9952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9953#[cfg_attr(feature = "bindings", derive(TS))]
9954pub struct HexStringExpr {
9955    pub this: Box<Expression>,
9956    #[serde(default)]
9957    pub is_integer: Option<bool>,
9958}
9959
9960/// UnicodeString
9961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9962#[cfg_attr(feature = "bindings", derive(TS))]
9963pub struct UnicodeString {
9964    pub this: Box<Expression>,
9965    #[serde(default)]
9966    pub escape: Option<Box<Expression>>,
9967}
9968
9969/// AlterColumn
9970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9971#[cfg_attr(feature = "bindings", derive(TS))]
9972pub struct AlterColumn {
9973    pub this: Box<Expression>,
9974    #[serde(default)]
9975    pub dtype: Option<Box<Expression>>,
9976    #[serde(default)]
9977    pub collate: Option<Box<Expression>>,
9978    #[serde(default)]
9979    pub using: Option<Box<Expression>>,
9980    #[serde(default)]
9981    pub default: Option<Box<Expression>>,
9982    #[serde(default)]
9983    pub drop: Option<Box<Expression>>,
9984    #[serde(default)]
9985    pub comment: Option<Box<Expression>>,
9986    #[serde(default)]
9987    pub allow_null: Option<Box<Expression>>,
9988    #[serde(default)]
9989    pub visible: Option<Box<Expression>>,
9990    #[serde(default)]
9991    pub rename_to: Option<Box<Expression>>,
9992}
9993
9994/// AlterSortKey
9995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9996#[cfg_attr(feature = "bindings", derive(TS))]
9997pub struct AlterSortKey {
9998    #[serde(default)]
9999    pub this: Option<Box<Expression>>,
10000    #[serde(default)]
10001    pub expressions: Vec<Expression>,
10002    #[serde(default)]
10003    pub compound: Option<Box<Expression>>,
10004}
10005
10006/// AlterSet
10007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10008#[cfg_attr(feature = "bindings", derive(TS))]
10009pub struct AlterSet {
10010    #[serde(default)]
10011    pub expressions: Vec<Expression>,
10012    #[serde(default)]
10013    pub option: Option<Box<Expression>>,
10014    #[serde(default)]
10015    pub tablespace: Option<Box<Expression>>,
10016    #[serde(default)]
10017    pub access_method: Option<Box<Expression>>,
10018    #[serde(default)]
10019    pub file_format: Option<Box<Expression>>,
10020    #[serde(default)]
10021    pub copy_options: Option<Box<Expression>>,
10022    #[serde(default)]
10023    pub tag: Option<Box<Expression>>,
10024    #[serde(default)]
10025    pub location: Option<Box<Expression>>,
10026    #[serde(default)]
10027    pub serde: Option<Box<Expression>>,
10028}
10029
10030/// RenameColumn
10031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10032#[cfg_attr(feature = "bindings", derive(TS))]
10033pub struct RenameColumn {
10034    pub this: Box<Expression>,
10035    #[serde(default)]
10036    pub to: Option<Box<Expression>>,
10037    #[serde(default)]
10038    pub exists: bool,
10039}
10040
10041/// Comprehension
10042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10043#[cfg_attr(feature = "bindings", derive(TS))]
10044pub struct Comprehension {
10045    pub this: Box<Expression>,
10046    pub expression: Box<Expression>,
10047    #[serde(default)]
10048    pub position: Option<Box<Expression>>,
10049    #[serde(default)]
10050    pub iterator: Option<Box<Expression>>,
10051    #[serde(default)]
10052    pub condition: Option<Box<Expression>>,
10053}
10054
10055/// MergeTreeTTLAction
10056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10057#[cfg_attr(feature = "bindings", derive(TS))]
10058pub struct MergeTreeTTLAction {
10059    pub this: Box<Expression>,
10060    #[serde(default)]
10061    pub delete: Option<Box<Expression>>,
10062    #[serde(default)]
10063    pub recompress: Option<Box<Expression>>,
10064    #[serde(default)]
10065    pub to_disk: Option<Box<Expression>>,
10066    #[serde(default)]
10067    pub to_volume: Option<Box<Expression>>,
10068}
10069
10070/// MergeTreeTTL
10071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10072#[cfg_attr(feature = "bindings", derive(TS))]
10073pub struct MergeTreeTTL {
10074    #[serde(default)]
10075    pub expressions: Vec<Expression>,
10076    #[serde(default)]
10077    pub where_: Option<Box<Expression>>,
10078    #[serde(default)]
10079    pub group: Option<Box<Expression>>,
10080    #[serde(default)]
10081    pub aggregates: Option<Box<Expression>>,
10082}
10083
10084/// IndexConstraintOption
10085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10086#[cfg_attr(feature = "bindings", derive(TS))]
10087pub struct IndexConstraintOption {
10088    #[serde(default)]
10089    pub key_block_size: Option<Box<Expression>>,
10090    #[serde(default)]
10091    pub using: Option<Box<Expression>>,
10092    #[serde(default)]
10093    pub parser: Option<Box<Expression>>,
10094    #[serde(default)]
10095    pub comment: Option<Box<Expression>>,
10096    #[serde(default)]
10097    pub visible: Option<Box<Expression>>,
10098    #[serde(default)]
10099    pub engine_attr: Option<Box<Expression>>,
10100    #[serde(default)]
10101    pub secondary_engine_attr: Option<Box<Expression>>,
10102}
10103
10104/// PeriodForSystemTimeConstraint
10105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10106#[cfg_attr(feature = "bindings", derive(TS))]
10107pub struct PeriodForSystemTimeConstraint {
10108    pub this: Box<Expression>,
10109    pub expression: Box<Expression>,
10110}
10111
10112/// CaseSpecificColumnConstraint
10113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10114#[cfg_attr(feature = "bindings", derive(TS))]
10115pub struct CaseSpecificColumnConstraint {
10116    #[serde(default)]
10117    pub not_: Option<Box<Expression>>,
10118}
10119
10120/// CharacterSetColumnConstraint
10121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10122#[cfg_attr(feature = "bindings", derive(TS))]
10123pub struct CharacterSetColumnConstraint {
10124    pub this: Box<Expression>,
10125}
10126
10127/// CheckColumnConstraint
10128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10129#[cfg_attr(feature = "bindings", derive(TS))]
10130pub struct CheckColumnConstraint {
10131    pub this: Box<Expression>,
10132    #[serde(default)]
10133    pub enforced: Option<Box<Expression>>,
10134}
10135
10136/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10138#[cfg_attr(feature = "bindings", derive(TS))]
10139pub struct AssumeColumnConstraint {
10140    pub this: Box<Expression>,
10141}
10142
10143/// CompressColumnConstraint
10144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10145#[cfg_attr(feature = "bindings", derive(TS))]
10146pub struct CompressColumnConstraint {
10147    #[serde(default)]
10148    pub this: Option<Box<Expression>>,
10149}
10150
10151/// DateFormatColumnConstraint
10152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10153#[cfg_attr(feature = "bindings", derive(TS))]
10154pub struct DateFormatColumnConstraint {
10155    pub this: Box<Expression>,
10156}
10157
10158/// EphemeralColumnConstraint
10159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10160#[cfg_attr(feature = "bindings", derive(TS))]
10161pub struct EphemeralColumnConstraint {
10162    #[serde(default)]
10163    pub this: Option<Box<Expression>>,
10164}
10165
10166/// WithOperator
10167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10168#[cfg_attr(feature = "bindings", derive(TS))]
10169pub struct WithOperator {
10170    pub this: Box<Expression>,
10171    pub op: String,
10172}
10173
10174/// GeneratedAsIdentityColumnConstraint
10175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10176#[cfg_attr(feature = "bindings", derive(TS))]
10177pub struct GeneratedAsIdentityColumnConstraint {
10178    #[serde(default)]
10179    pub this: Option<Box<Expression>>,
10180    #[serde(default)]
10181    pub expression: Option<Box<Expression>>,
10182    #[serde(default)]
10183    pub on_null: Option<Box<Expression>>,
10184    #[serde(default)]
10185    pub start: Option<Box<Expression>>,
10186    #[serde(default)]
10187    pub increment: Option<Box<Expression>>,
10188    #[serde(default)]
10189    pub minvalue: Option<Box<Expression>>,
10190    #[serde(default)]
10191    pub maxvalue: Option<Box<Expression>>,
10192    #[serde(default)]
10193    pub cycle: Option<Box<Expression>>,
10194    #[serde(default)]
10195    pub order: Option<Box<Expression>>,
10196}
10197
10198/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10199/// TSQL: outputs "IDENTITY"
10200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10201#[cfg_attr(feature = "bindings", derive(TS))]
10202pub struct AutoIncrementColumnConstraint;
10203
10204/// CommentColumnConstraint - Column comment marker
10205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10206#[cfg_attr(feature = "bindings", derive(TS))]
10207pub struct CommentColumnConstraint;
10208
10209/// GeneratedAsRowColumnConstraint
10210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10211#[cfg_attr(feature = "bindings", derive(TS))]
10212pub struct GeneratedAsRowColumnConstraint {
10213    #[serde(default)]
10214    pub start: Option<Box<Expression>>,
10215    #[serde(default)]
10216    pub hidden: Option<Box<Expression>>,
10217}
10218
10219/// IndexColumnConstraint
10220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10221#[cfg_attr(feature = "bindings", derive(TS))]
10222pub struct IndexColumnConstraint {
10223    #[serde(default)]
10224    pub this: Option<Box<Expression>>,
10225    #[serde(default)]
10226    pub expressions: Vec<Expression>,
10227    #[serde(default)]
10228    pub kind: Option<String>,
10229    #[serde(default)]
10230    pub index_type: Option<Box<Expression>>,
10231    #[serde(default)]
10232    pub options: Vec<Expression>,
10233    #[serde(default)]
10234    pub expression: Option<Box<Expression>>,
10235    #[serde(default)]
10236    pub granularity: Option<Box<Expression>>,
10237}
10238
10239/// MaskingPolicyColumnConstraint
10240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10241#[cfg_attr(feature = "bindings", derive(TS))]
10242pub struct MaskingPolicyColumnConstraint {
10243    pub this: Box<Expression>,
10244    #[serde(default)]
10245    pub expressions: Vec<Expression>,
10246}
10247
10248/// NotNullColumnConstraint
10249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10250#[cfg_attr(feature = "bindings", derive(TS))]
10251pub struct NotNullColumnConstraint {
10252    #[serde(default)]
10253    pub allow_null: Option<Box<Expression>>,
10254}
10255
10256/// DefaultColumnConstraint - DEFAULT value for a column
10257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10258#[cfg_attr(feature = "bindings", derive(TS))]
10259pub struct DefaultColumnConstraint {
10260    pub this: Box<Expression>,
10261    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10262    #[serde(default, skip_serializing_if = "Option::is_none")]
10263    pub for_column: Option<Identifier>,
10264}
10265
10266/// PrimaryKeyColumnConstraint
10267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10268#[cfg_attr(feature = "bindings", derive(TS))]
10269pub struct PrimaryKeyColumnConstraint {
10270    #[serde(default)]
10271    pub desc: Option<Box<Expression>>,
10272    #[serde(default)]
10273    pub options: Vec<Expression>,
10274}
10275
10276/// UniqueColumnConstraint
10277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10278#[cfg_attr(feature = "bindings", derive(TS))]
10279pub struct UniqueColumnConstraint {
10280    #[serde(default)]
10281    pub this: Option<Box<Expression>>,
10282    #[serde(default)]
10283    pub index_type: Option<Box<Expression>>,
10284    #[serde(default)]
10285    pub on_conflict: Option<Box<Expression>>,
10286    #[serde(default)]
10287    pub nulls: Option<Box<Expression>>,
10288    #[serde(default)]
10289    pub options: Vec<Expression>,
10290}
10291
10292/// WatermarkColumnConstraint
10293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10294#[cfg_attr(feature = "bindings", derive(TS))]
10295pub struct WatermarkColumnConstraint {
10296    pub this: Box<Expression>,
10297    pub expression: Box<Expression>,
10298}
10299
10300/// ComputedColumnConstraint
10301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10302#[cfg_attr(feature = "bindings", derive(TS))]
10303pub struct ComputedColumnConstraint {
10304    pub this: Box<Expression>,
10305    #[serde(default)]
10306    pub persisted: Option<Box<Expression>>,
10307    #[serde(default)]
10308    pub not_null: Option<Box<Expression>>,
10309    #[serde(default)]
10310    pub data_type: Option<Box<Expression>>,
10311}
10312
10313/// InOutColumnConstraint
10314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10315#[cfg_attr(feature = "bindings", derive(TS))]
10316pub struct InOutColumnConstraint {
10317    #[serde(default)]
10318    pub input_: Option<Box<Expression>>,
10319    #[serde(default)]
10320    pub output: Option<Box<Expression>>,
10321}
10322
10323/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10325#[cfg_attr(feature = "bindings", derive(TS))]
10326pub struct PathColumnConstraint {
10327    pub this: Box<Expression>,
10328}
10329
10330/// Constraint
10331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10332#[cfg_attr(feature = "bindings", derive(TS))]
10333pub struct Constraint {
10334    pub this: Box<Expression>,
10335    #[serde(default)]
10336    pub expressions: Vec<Expression>,
10337}
10338
10339/// Export
10340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10341#[cfg_attr(feature = "bindings", derive(TS))]
10342pub struct Export {
10343    pub this: Box<Expression>,
10344    #[serde(default)]
10345    pub connection: Option<Box<Expression>>,
10346    #[serde(default)]
10347    pub options: Vec<Expression>,
10348}
10349
10350/// Filter
10351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10352#[cfg_attr(feature = "bindings", derive(TS))]
10353pub struct Filter {
10354    pub this: Box<Expression>,
10355    pub expression: Box<Expression>,
10356}
10357
10358/// Changes
10359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10360#[cfg_attr(feature = "bindings", derive(TS))]
10361pub struct Changes {
10362    #[serde(default)]
10363    pub information: Option<Box<Expression>>,
10364    #[serde(default)]
10365    pub at_before: Option<Box<Expression>>,
10366    #[serde(default)]
10367    pub end: Option<Box<Expression>>,
10368}
10369
10370/// Directory
10371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10372#[cfg_attr(feature = "bindings", derive(TS))]
10373pub struct Directory {
10374    pub this: Box<Expression>,
10375    #[serde(default)]
10376    pub local: Option<Box<Expression>>,
10377    #[serde(default)]
10378    pub row_format: Option<Box<Expression>>,
10379}
10380
10381/// ForeignKey
10382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10383#[cfg_attr(feature = "bindings", derive(TS))]
10384pub struct ForeignKey {
10385    #[serde(default)]
10386    pub expressions: Vec<Expression>,
10387    #[serde(default)]
10388    pub reference: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub delete: Option<Box<Expression>>,
10391    #[serde(default)]
10392    pub update: Option<Box<Expression>>,
10393    #[serde(default)]
10394    pub options: Vec<Expression>,
10395}
10396
10397/// ColumnPrefix
10398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10399#[cfg_attr(feature = "bindings", derive(TS))]
10400pub struct ColumnPrefix {
10401    pub this: Box<Expression>,
10402    pub expression: Box<Expression>,
10403}
10404
10405/// PrimaryKey
10406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10407#[cfg_attr(feature = "bindings", derive(TS))]
10408pub struct PrimaryKey {
10409    #[serde(default)]
10410    pub this: Option<Box<Expression>>,
10411    #[serde(default)]
10412    pub expressions: Vec<Expression>,
10413    #[serde(default)]
10414    pub options: Vec<Expression>,
10415    #[serde(default)]
10416    pub include: Option<Box<Expression>>,
10417}
10418
10419/// Into
10420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10421#[cfg_attr(feature = "bindings", derive(TS))]
10422pub struct IntoClause {
10423    #[serde(default)]
10424    pub this: Option<Box<Expression>>,
10425    #[serde(default)]
10426    pub temporary: bool,
10427    #[serde(default)]
10428    pub unlogged: Option<Box<Expression>>,
10429    #[serde(default)]
10430    pub bulk_collect: Option<Box<Expression>>,
10431    #[serde(default)]
10432    pub expressions: Vec<Expression>,
10433}
10434
10435/// JoinHint
10436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10437#[cfg_attr(feature = "bindings", derive(TS))]
10438pub struct JoinHint {
10439    pub this: Box<Expression>,
10440    #[serde(default)]
10441    pub expressions: Vec<Expression>,
10442}
10443
10444/// Opclass
10445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10446#[cfg_attr(feature = "bindings", derive(TS))]
10447pub struct Opclass {
10448    pub this: Box<Expression>,
10449    pub expression: Box<Expression>,
10450}
10451
10452/// Index
10453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10454#[cfg_attr(feature = "bindings", derive(TS))]
10455pub struct Index {
10456    #[serde(default)]
10457    pub this: Option<Box<Expression>>,
10458    #[serde(default)]
10459    pub table: Option<Box<Expression>>,
10460    #[serde(default)]
10461    pub unique: bool,
10462    #[serde(default)]
10463    pub primary: Option<Box<Expression>>,
10464    #[serde(default)]
10465    pub amp: Option<Box<Expression>>,
10466    #[serde(default)]
10467    pub params: Vec<Expression>,
10468}
10469
10470/// IndexParameters
10471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10472#[cfg_attr(feature = "bindings", derive(TS))]
10473pub struct IndexParameters {
10474    #[serde(default)]
10475    pub using: Option<Box<Expression>>,
10476    #[serde(default)]
10477    pub include: Option<Box<Expression>>,
10478    #[serde(default)]
10479    pub columns: Vec<Expression>,
10480    #[serde(default)]
10481    pub with_storage: Option<Box<Expression>>,
10482    #[serde(default)]
10483    pub partition_by: Option<Box<Expression>>,
10484    #[serde(default)]
10485    pub tablespace: Option<Box<Expression>>,
10486    #[serde(default)]
10487    pub where_: Option<Box<Expression>>,
10488    #[serde(default)]
10489    pub on: Option<Box<Expression>>,
10490}
10491
10492/// ConditionalInsert
10493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10494#[cfg_attr(feature = "bindings", derive(TS))]
10495pub struct ConditionalInsert {
10496    pub this: Box<Expression>,
10497    #[serde(default)]
10498    pub expression: Option<Box<Expression>>,
10499    #[serde(default)]
10500    pub else_: Option<Box<Expression>>,
10501}
10502
10503/// MultitableInserts
10504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10505#[cfg_attr(feature = "bindings", derive(TS))]
10506pub struct MultitableInserts {
10507    #[serde(default)]
10508    pub expressions: Vec<Expression>,
10509    pub kind: String,
10510    #[serde(default)]
10511    pub source: Option<Box<Expression>>,
10512    /// Leading comments before the statement
10513    #[serde(default)]
10514    pub leading_comments: Vec<String>,
10515}
10516
10517/// OnConflict
10518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10519#[cfg_attr(feature = "bindings", derive(TS))]
10520pub struct OnConflict {
10521    #[serde(default)]
10522    pub duplicate: Option<Box<Expression>>,
10523    #[serde(default)]
10524    pub expressions: Vec<Expression>,
10525    #[serde(default)]
10526    pub action: Option<Box<Expression>>,
10527    #[serde(default)]
10528    pub conflict_keys: Option<Box<Expression>>,
10529    #[serde(default)]
10530    pub index_predicate: Option<Box<Expression>>,
10531    #[serde(default)]
10532    pub constraint: Option<Box<Expression>>,
10533    #[serde(default)]
10534    pub where_: Option<Box<Expression>>,
10535}
10536
10537/// OnCondition
10538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10539#[cfg_attr(feature = "bindings", derive(TS))]
10540pub struct OnCondition {
10541    #[serde(default)]
10542    pub error: Option<Box<Expression>>,
10543    #[serde(default)]
10544    pub empty: Option<Box<Expression>>,
10545    #[serde(default)]
10546    pub null: Option<Box<Expression>>,
10547}
10548
10549/// Returning
10550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10551#[cfg_attr(feature = "bindings", derive(TS))]
10552pub struct Returning {
10553    #[serde(default)]
10554    pub expressions: Vec<Expression>,
10555    #[serde(default)]
10556    pub into: Option<Box<Expression>>,
10557}
10558
10559/// Introducer
10560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10561#[cfg_attr(feature = "bindings", derive(TS))]
10562pub struct Introducer {
10563    pub this: Box<Expression>,
10564    pub expression: Box<Expression>,
10565}
10566
10567/// PartitionRange
10568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10569#[cfg_attr(feature = "bindings", derive(TS))]
10570pub struct PartitionRange {
10571    pub this: Box<Expression>,
10572    #[serde(default)]
10573    pub expression: Option<Box<Expression>>,
10574    #[serde(default)]
10575    pub expressions: Vec<Expression>,
10576}
10577
10578/// Group
10579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10580#[cfg_attr(feature = "bindings", derive(TS))]
10581pub struct Group {
10582    #[serde(default)]
10583    pub expressions: Vec<Expression>,
10584    #[serde(default)]
10585    pub grouping_sets: Option<Box<Expression>>,
10586    #[serde(default)]
10587    pub cube: Option<Box<Expression>>,
10588    #[serde(default)]
10589    pub rollup: Option<Box<Expression>>,
10590    #[serde(default)]
10591    pub totals: Option<Box<Expression>>,
10592    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10593    #[serde(default)]
10594    pub all: Option<bool>,
10595}
10596
10597/// Cube
10598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10599#[cfg_attr(feature = "bindings", derive(TS))]
10600pub struct Cube {
10601    #[serde(default)]
10602    pub expressions: Vec<Expression>,
10603}
10604
10605/// Rollup
10606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10607#[cfg_attr(feature = "bindings", derive(TS))]
10608pub struct Rollup {
10609    #[serde(default)]
10610    pub expressions: Vec<Expression>,
10611}
10612
10613/// GroupingSets
10614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10615#[cfg_attr(feature = "bindings", derive(TS))]
10616pub struct GroupingSets {
10617    #[serde(default)]
10618    pub expressions: Vec<Expression>,
10619}
10620
10621/// LimitOptions
10622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10623#[cfg_attr(feature = "bindings", derive(TS))]
10624pub struct LimitOptions {
10625    #[serde(default)]
10626    pub percent: Option<Box<Expression>>,
10627    #[serde(default)]
10628    pub rows: Option<Box<Expression>>,
10629    #[serde(default)]
10630    pub with_ties: Option<Box<Expression>>,
10631}
10632
10633/// Lateral
10634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10635#[cfg_attr(feature = "bindings", derive(TS))]
10636pub struct Lateral {
10637    pub this: Box<Expression>,
10638    #[serde(default)]
10639    pub view: Option<Box<Expression>>,
10640    #[serde(default)]
10641    pub outer: Option<Box<Expression>>,
10642    #[serde(default)]
10643    pub alias: Option<String>,
10644    /// Whether the alias was originally quoted (backtick/double-quote)
10645    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10646    pub alias_quoted: bool,
10647    #[serde(default)]
10648    pub cross_apply: Option<Box<Expression>>,
10649    #[serde(default)]
10650    pub ordinality: Option<Box<Expression>>,
10651    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10652    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10653    pub column_aliases: Vec<String>,
10654}
10655
10656/// TableFromRows
10657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10658#[cfg_attr(feature = "bindings", derive(TS))]
10659pub struct TableFromRows {
10660    pub this: Box<Expression>,
10661    #[serde(default)]
10662    pub alias: Option<String>,
10663    #[serde(default)]
10664    pub joins: Vec<Expression>,
10665    #[serde(default)]
10666    pub pivots: Option<Box<Expression>>,
10667    #[serde(default)]
10668    pub sample: Option<Box<Expression>>,
10669}
10670
10671/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10672/// Used for set-returning functions with typed column definitions
10673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10674#[cfg_attr(feature = "bindings", derive(TS))]
10675pub struct RowsFrom {
10676    /// List of function expressions, each potentially with an alias and typed columns
10677    pub expressions: Vec<Expression>,
10678    /// WITH ORDINALITY modifier
10679    #[serde(default)]
10680    pub ordinality: bool,
10681    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10682    #[serde(default)]
10683    pub alias: Option<Box<Expression>>,
10684}
10685
10686/// WithFill
10687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10688#[cfg_attr(feature = "bindings", derive(TS))]
10689pub struct WithFill {
10690    #[serde(default)]
10691    pub from_: Option<Box<Expression>>,
10692    #[serde(default)]
10693    pub to: Option<Box<Expression>>,
10694    #[serde(default)]
10695    pub step: Option<Box<Expression>>,
10696    #[serde(default)]
10697    pub staleness: Option<Box<Expression>>,
10698    #[serde(default)]
10699    pub interpolate: Option<Box<Expression>>,
10700}
10701
10702/// Property
10703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10704#[cfg_attr(feature = "bindings", derive(TS))]
10705pub struct Property {
10706    pub this: Box<Expression>,
10707    #[serde(default)]
10708    pub value: Option<Box<Expression>>,
10709}
10710
10711/// GrantPrivilege
10712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10713#[cfg_attr(feature = "bindings", derive(TS))]
10714pub struct GrantPrivilege {
10715    pub this: Box<Expression>,
10716    #[serde(default)]
10717    pub expressions: Vec<Expression>,
10718}
10719
10720/// AllowedValuesProperty
10721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10722#[cfg_attr(feature = "bindings", derive(TS))]
10723pub struct AllowedValuesProperty {
10724    #[serde(default)]
10725    pub expressions: Vec<Expression>,
10726}
10727
10728/// AlgorithmProperty
10729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10730#[cfg_attr(feature = "bindings", derive(TS))]
10731pub struct AlgorithmProperty {
10732    pub this: Box<Expression>,
10733}
10734
10735/// AutoIncrementProperty
10736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10737#[cfg_attr(feature = "bindings", derive(TS))]
10738pub struct AutoIncrementProperty {
10739    pub this: Box<Expression>,
10740}
10741
10742/// AutoRefreshProperty
10743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10744#[cfg_attr(feature = "bindings", derive(TS))]
10745pub struct AutoRefreshProperty {
10746    pub this: Box<Expression>,
10747}
10748
10749/// BackupProperty
10750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10751#[cfg_attr(feature = "bindings", derive(TS))]
10752pub struct BackupProperty {
10753    pub this: Box<Expression>,
10754}
10755
10756/// BuildProperty
10757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10758#[cfg_attr(feature = "bindings", derive(TS))]
10759pub struct BuildProperty {
10760    pub this: Box<Expression>,
10761}
10762
10763/// BlockCompressionProperty
10764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10765#[cfg_attr(feature = "bindings", derive(TS))]
10766pub struct BlockCompressionProperty {
10767    #[serde(default)]
10768    pub autotemp: Option<Box<Expression>>,
10769    #[serde(default)]
10770    pub always: Option<Box<Expression>>,
10771    #[serde(default)]
10772    pub default: Option<Box<Expression>>,
10773    #[serde(default)]
10774    pub manual: Option<Box<Expression>>,
10775    #[serde(default)]
10776    pub never: Option<Box<Expression>>,
10777}
10778
10779/// CharacterSetProperty
10780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10781#[cfg_attr(feature = "bindings", derive(TS))]
10782pub struct CharacterSetProperty {
10783    pub this: Box<Expression>,
10784    #[serde(default)]
10785    pub default: Option<Box<Expression>>,
10786}
10787
10788/// ChecksumProperty
10789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10790#[cfg_attr(feature = "bindings", derive(TS))]
10791pub struct ChecksumProperty {
10792    #[serde(default)]
10793    pub on: Option<Box<Expression>>,
10794    #[serde(default)]
10795    pub default: Option<Box<Expression>>,
10796}
10797
10798/// CollateProperty
10799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10800#[cfg_attr(feature = "bindings", derive(TS))]
10801pub struct CollateProperty {
10802    pub this: Box<Expression>,
10803    #[serde(default)]
10804    pub default: Option<Box<Expression>>,
10805}
10806
10807/// DataBlocksizeProperty
10808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10809#[cfg_attr(feature = "bindings", derive(TS))]
10810pub struct DataBlocksizeProperty {
10811    #[serde(default)]
10812    pub size: Option<i64>,
10813    #[serde(default)]
10814    pub units: Option<Box<Expression>>,
10815    #[serde(default)]
10816    pub minimum: Option<Box<Expression>>,
10817    #[serde(default)]
10818    pub maximum: Option<Box<Expression>>,
10819    #[serde(default)]
10820    pub default: Option<Box<Expression>>,
10821}
10822
10823/// DataDeletionProperty
10824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10825#[cfg_attr(feature = "bindings", derive(TS))]
10826pub struct DataDeletionProperty {
10827    pub on: Box<Expression>,
10828    #[serde(default)]
10829    pub filter_column: Option<Box<Expression>>,
10830    #[serde(default)]
10831    pub retention_period: Option<Box<Expression>>,
10832}
10833
10834/// DefinerProperty
10835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10836#[cfg_attr(feature = "bindings", derive(TS))]
10837pub struct DefinerProperty {
10838    pub this: Box<Expression>,
10839}
10840
10841/// DistKeyProperty
10842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10843#[cfg_attr(feature = "bindings", derive(TS))]
10844pub struct DistKeyProperty {
10845    pub this: Box<Expression>,
10846}
10847
10848/// DistributedByProperty
10849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10850#[cfg_attr(feature = "bindings", derive(TS))]
10851pub struct DistributedByProperty {
10852    #[serde(default)]
10853    pub expressions: Vec<Expression>,
10854    pub kind: String,
10855    #[serde(default)]
10856    pub buckets: Option<Box<Expression>>,
10857    #[serde(default)]
10858    pub order: Option<Box<Expression>>,
10859}
10860
10861/// DistStyleProperty
10862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10863#[cfg_attr(feature = "bindings", derive(TS))]
10864pub struct DistStyleProperty {
10865    pub this: Box<Expression>,
10866}
10867
10868/// DuplicateKeyProperty
10869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10870#[cfg_attr(feature = "bindings", derive(TS))]
10871pub struct DuplicateKeyProperty {
10872    #[serde(default)]
10873    pub expressions: Vec<Expression>,
10874}
10875
10876/// EngineProperty
10877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10878#[cfg_attr(feature = "bindings", derive(TS))]
10879pub struct EngineProperty {
10880    pub this: Box<Expression>,
10881}
10882
10883/// ToTableProperty
10884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10885#[cfg_attr(feature = "bindings", derive(TS))]
10886pub struct ToTableProperty {
10887    pub this: Box<Expression>,
10888}
10889
10890/// ExecuteAsProperty
10891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10892#[cfg_attr(feature = "bindings", derive(TS))]
10893pub struct ExecuteAsProperty {
10894    pub this: Box<Expression>,
10895}
10896
10897/// ExternalProperty
10898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10899#[cfg_attr(feature = "bindings", derive(TS))]
10900pub struct ExternalProperty {
10901    #[serde(default)]
10902    pub this: Option<Box<Expression>>,
10903}
10904
10905/// FallbackProperty
10906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10907#[cfg_attr(feature = "bindings", derive(TS))]
10908pub struct FallbackProperty {
10909    #[serde(default)]
10910    pub no: Option<Box<Expression>>,
10911    #[serde(default)]
10912    pub protection: Option<Box<Expression>>,
10913}
10914
10915/// FileFormatProperty
10916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10917#[cfg_attr(feature = "bindings", derive(TS))]
10918pub struct FileFormatProperty {
10919    #[serde(default)]
10920    pub this: Option<Box<Expression>>,
10921    #[serde(default)]
10922    pub expressions: Vec<Expression>,
10923    #[serde(default)]
10924    pub hive_format: Option<Box<Expression>>,
10925}
10926
10927/// CredentialsProperty
10928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10929#[cfg_attr(feature = "bindings", derive(TS))]
10930pub struct CredentialsProperty {
10931    #[serde(default)]
10932    pub expressions: Vec<Expression>,
10933}
10934
10935/// FreespaceProperty
10936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10937#[cfg_attr(feature = "bindings", derive(TS))]
10938pub struct FreespaceProperty {
10939    pub this: Box<Expression>,
10940    #[serde(default)]
10941    pub percent: Option<Box<Expression>>,
10942}
10943
10944/// InheritsProperty
10945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10946#[cfg_attr(feature = "bindings", derive(TS))]
10947pub struct InheritsProperty {
10948    #[serde(default)]
10949    pub expressions: Vec<Expression>,
10950}
10951
10952/// InputModelProperty
10953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10954#[cfg_attr(feature = "bindings", derive(TS))]
10955pub struct InputModelProperty {
10956    pub this: Box<Expression>,
10957}
10958
10959/// OutputModelProperty
10960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10961#[cfg_attr(feature = "bindings", derive(TS))]
10962pub struct OutputModelProperty {
10963    pub this: Box<Expression>,
10964}
10965
10966/// IsolatedLoadingProperty
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct IsolatedLoadingProperty {
10970    #[serde(default)]
10971    pub no: Option<Box<Expression>>,
10972    #[serde(default)]
10973    pub concurrent: Option<Box<Expression>>,
10974    #[serde(default)]
10975    pub target: Option<Box<Expression>>,
10976}
10977
10978/// JournalProperty
10979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10980#[cfg_attr(feature = "bindings", derive(TS))]
10981pub struct JournalProperty {
10982    #[serde(default)]
10983    pub no: Option<Box<Expression>>,
10984    #[serde(default)]
10985    pub dual: Option<Box<Expression>>,
10986    #[serde(default)]
10987    pub before: Option<Box<Expression>>,
10988    #[serde(default)]
10989    pub local: Option<Box<Expression>>,
10990    #[serde(default)]
10991    pub after: Option<Box<Expression>>,
10992}
10993
10994/// LanguageProperty
10995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10996#[cfg_attr(feature = "bindings", derive(TS))]
10997pub struct LanguageProperty {
10998    pub this: Box<Expression>,
10999}
11000
11001/// EnviromentProperty
11002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11003#[cfg_attr(feature = "bindings", derive(TS))]
11004pub struct EnviromentProperty {
11005    #[serde(default)]
11006    pub expressions: Vec<Expression>,
11007}
11008
11009/// ClusteredByProperty
11010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11011#[cfg_attr(feature = "bindings", derive(TS))]
11012pub struct ClusteredByProperty {
11013    #[serde(default)]
11014    pub expressions: Vec<Expression>,
11015    #[serde(default)]
11016    pub sorted_by: Option<Box<Expression>>,
11017    #[serde(default)]
11018    pub buckets: Option<Box<Expression>>,
11019}
11020
11021/// DictProperty
11022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11023#[cfg_attr(feature = "bindings", derive(TS))]
11024pub struct DictProperty {
11025    pub this: Box<Expression>,
11026    pub kind: String,
11027    #[serde(default)]
11028    pub settings: Option<Box<Expression>>,
11029}
11030
11031/// DictRange
11032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11033#[cfg_attr(feature = "bindings", derive(TS))]
11034pub struct DictRange {
11035    pub this: Box<Expression>,
11036    #[serde(default)]
11037    pub min: Option<Box<Expression>>,
11038    #[serde(default)]
11039    pub max: Option<Box<Expression>>,
11040}
11041
11042/// OnCluster
11043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11044#[cfg_attr(feature = "bindings", derive(TS))]
11045pub struct OnCluster {
11046    pub this: Box<Expression>,
11047}
11048
11049/// LikeProperty
11050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11051#[cfg_attr(feature = "bindings", derive(TS))]
11052pub struct LikeProperty {
11053    pub this: Box<Expression>,
11054    #[serde(default)]
11055    pub expressions: Vec<Expression>,
11056}
11057
11058/// LocationProperty
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct LocationProperty {
11062    pub this: Box<Expression>,
11063}
11064
11065/// LockProperty
11066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11067#[cfg_attr(feature = "bindings", derive(TS))]
11068pub struct LockProperty {
11069    pub this: Box<Expression>,
11070}
11071
11072/// LockingProperty
11073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11074#[cfg_attr(feature = "bindings", derive(TS))]
11075pub struct LockingProperty {
11076    #[serde(default)]
11077    pub this: Option<Box<Expression>>,
11078    pub kind: String,
11079    #[serde(default)]
11080    pub for_or_in: Option<Box<Expression>>,
11081    #[serde(default)]
11082    pub lock_type: Option<Box<Expression>>,
11083    #[serde(default)]
11084    pub override_: Option<Box<Expression>>,
11085}
11086
11087/// LogProperty
11088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11089#[cfg_attr(feature = "bindings", derive(TS))]
11090pub struct LogProperty {
11091    #[serde(default)]
11092    pub no: Option<Box<Expression>>,
11093}
11094
11095/// MaterializedProperty
11096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11097#[cfg_attr(feature = "bindings", derive(TS))]
11098pub struct MaterializedProperty {
11099    #[serde(default)]
11100    pub this: Option<Box<Expression>>,
11101}
11102
11103/// MergeBlockRatioProperty
11104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11105#[cfg_attr(feature = "bindings", derive(TS))]
11106pub struct MergeBlockRatioProperty {
11107    #[serde(default)]
11108    pub this: Option<Box<Expression>>,
11109    #[serde(default)]
11110    pub no: Option<Box<Expression>>,
11111    #[serde(default)]
11112    pub default: Option<Box<Expression>>,
11113    #[serde(default)]
11114    pub percent: Option<Box<Expression>>,
11115}
11116
11117/// OnProperty
11118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11119#[cfg_attr(feature = "bindings", derive(TS))]
11120pub struct OnProperty {
11121    pub this: Box<Expression>,
11122}
11123
11124/// OnCommitProperty
11125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11126#[cfg_attr(feature = "bindings", derive(TS))]
11127pub struct OnCommitProperty {
11128    #[serde(default)]
11129    pub delete: Option<Box<Expression>>,
11130}
11131
11132/// PartitionedByProperty
11133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11134#[cfg_attr(feature = "bindings", derive(TS))]
11135pub struct PartitionedByProperty {
11136    pub this: Box<Expression>,
11137}
11138
11139/// BigQuery PARTITION BY property in CREATE TABLE statements.
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct PartitionByProperty {
11143    #[serde(default)]
11144    pub expressions: Vec<Expression>,
11145}
11146
11147/// PartitionedByBucket
11148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11149#[cfg_attr(feature = "bindings", derive(TS))]
11150pub struct PartitionedByBucket {
11151    pub this: Box<Expression>,
11152    pub expression: Box<Expression>,
11153}
11154
11155/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11157#[cfg_attr(feature = "bindings", derive(TS))]
11158pub struct ClusterByColumnsProperty {
11159    #[serde(default)]
11160    pub columns: Vec<Identifier>,
11161}
11162
11163/// PartitionByTruncate
11164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11165#[cfg_attr(feature = "bindings", derive(TS))]
11166pub struct PartitionByTruncate {
11167    pub this: Box<Expression>,
11168    pub expression: Box<Expression>,
11169}
11170
11171/// PartitionByRangeProperty
11172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11173#[cfg_attr(feature = "bindings", derive(TS))]
11174pub struct PartitionByRangeProperty {
11175    #[serde(default)]
11176    pub partition_expressions: Option<Box<Expression>>,
11177    #[serde(default)]
11178    pub create_expressions: Option<Box<Expression>>,
11179}
11180
11181/// PartitionByRangePropertyDynamic
11182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11183#[cfg_attr(feature = "bindings", derive(TS))]
11184pub struct PartitionByRangePropertyDynamic {
11185    #[serde(default)]
11186    pub this: Option<Box<Expression>>,
11187    #[serde(default)]
11188    pub start: Option<Box<Expression>>,
11189    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11190    #[serde(default)]
11191    pub use_start_end: bool,
11192    #[serde(default)]
11193    pub end: Option<Box<Expression>>,
11194    #[serde(default)]
11195    pub every: Option<Box<Expression>>,
11196}
11197
11198/// PartitionByListProperty
11199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11200#[cfg_attr(feature = "bindings", derive(TS))]
11201pub struct PartitionByListProperty {
11202    #[serde(default)]
11203    pub partition_expressions: Option<Box<Expression>>,
11204    #[serde(default)]
11205    pub create_expressions: Option<Box<Expression>>,
11206}
11207
11208/// PartitionList
11209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11210#[cfg_attr(feature = "bindings", derive(TS))]
11211pub struct PartitionList {
11212    pub this: Box<Expression>,
11213    #[serde(default)]
11214    pub expressions: Vec<Expression>,
11215}
11216
11217/// Partition - represents PARTITION/SUBPARTITION clause
11218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11219#[cfg_attr(feature = "bindings", derive(TS))]
11220pub struct Partition {
11221    pub expressions: Vec<Expression>,
11222    #[serde(default)]
11223    pub subpartition: bool,
11224}
11225
11226/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11227/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct RefreshTriggerProperty {
11231    /// Method: COMPLETE or AUTO
11232    pub method: String,
11233    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11234    #[serde(default)]
11235    pub kind: Option<String>,
11236    /// For SCHEDULE: EVERY n (the number)
11237    #[serde(default)]
11238    pub every: Option<Box<Expression>>,
11239    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11240    #[serde(default)]
11241    pub unit: Option<String>,
11242    /// For SCHEDULE: STARTS 'datetime'
11243    #[serde(default)]
11244    pub starts: Option<Box<Expression>>,
11245}
11246
11247/// UniqueKeyProperty
11248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11249#[cfg_attr(feature = "bindings", derive(TS))]
11250pub struct UniqueKeyProperty {
11251    #[serde(default)]
11252    pub expressions: Vec<Expression>,
11253}
11254
11255/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11257#[cfg_attr(feature = "bindings", derive(TS))]
11258pub struct RollupProperty {
11259    pub expressions: Vec<RollupIndex>,
11260}
11261
11262/// RollupIndex - A single rollup index: name(col1, col2)
11263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11264#[cfg_attr(feature = "bindings", derive(TS))]
11265pub struct RollupIndex {
11266    pub name: Identifier,
11267    pub expressions: Vec<Identifier>,
11268}
11269
11270/// PartitionBoundSpec
11271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11272#[cfg_attr(feature = "bindings", derive(TS))]
11273pub struct PartitionBoundSpec {
11274    #[serde(default)]
11275    pub this: Option<Box<Expression>>,
11276    #[serde(default)]
11277    pub expression: Option<Box<Expression>>,
11278    #[serde(default)]
11279    pub from_expressions: Option<Box<Expression>>,
11280    #[serde(default)]
11281    pub to_expressions: Option<Box<Expression>>,
11282}
11283
11284/// PartitionedOfProperty
11285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11286#[cfg_attr(feature = "bindings", derive(TS))]
11287pub struct PartitionedOfProperty {
11288    pub this: Box<Expression>,
11289    pub expression: Box<Expression>,
11290}
11291
11292/// RemoteWithConnectionModelProperty
11293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11294#[cfg_attr(feature = "bindings", derive(TS))]
11295pub struct RemoteWithConnectionModelProperty {
11296    pub this: Box<Expression>,
11297}
11298
11299/// ReturnsProperty
11300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11301#[cfg_attr(feature = "bindings", derive(TS))]
11302pub struct ReturnsProperty {
11303    #[serde(default)]
11304    pub this: Option<Box<Expression>>,
11305    #[serde(default)]
11306    pub is_table: Option<Box<Expression>>,
11307    #[serde(default)]
11308    pub table: Option<Box<Expression>>,
11309    #[serde(default)]
11310    pub null: Option<Box<Expression>>,
11311}
11312
11313/// RowFormatProperty
11314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11315#[cfg_attr(feature = "bindings", derive(TS))]
11316pub struct RowFormatProperty {
11317    pub this: Box<Expression>,
11318}
11319
11320/// RowFormatDelimitedProperty
11321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11322#[cfg_attr(feature = "bindings", derive(TS))]
11323pub struct RowFormatDelimitedProperty {
11324    #[serde(default)]
11325    pub fields: Option<Box<Expression>>,
11326    #[serde(default)]
11327    pub escaped: Option<Box<Expression>>,
11328    #[serde(default)]
11329    pub collection_items: Option<Box<Expression>>,
11330    #[serde(default)]
11331    pub map_keys: Option<Box<Expression>>,
11332    #[serde(default)]
11333    pub lines: Option<Box<Expression>>,
11334    #[serde(default)]
11335    pub null: Option<Box<Expression>>,
11336    #[serde(default)]
11337    pub serde: Option<Box<Expression>>,
11338}
11339
11340/// RowFormatSerdeProperty
11341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11342#[cfg_attr(feature = "bindings", derive(TS))]
11343pub struct RowFormatSerdeProperty {
11344    pub this: Box<Expression>,
11345    #[serde(default)]
11346    pub serde_properties: Option<Box<Expression>>,
11347}
11348
11349/// QueryTransform
11350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11351#[cfg_attr(feature = "bindings", derive(TS))]
11352pub struct QueryTransform {
11353    #[serde(default)]
11354    pub expressions: Vec<Expression>,
11355    #[serde(default)]
11356    pub command_script: Option<Box<Expression>>,
11357    #[serde(default)]
11358    pub schema: Option<Box<Expression>>,
11359    #[serde(default)]
11360    pub row_format_before: Option<Box<Expression>>,
11361    #[serde(default)]
11362    pub record_writer: Option<Box<Expression>>,
11363    #[serde(default)]
11364    pub row_format_after: Option<Box<Expression>>,
11365    #[serde(default)]
11366    pub record_reader: Option<Box<Expression>>,
11367}
11368
11369/// SampleProperty
11370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11371#[cfg_attr(feature = "bindings", derive(TS))]
11372pub struct SampleProperty {
11373    pub this: Box<Expression>,
11374}
11375
11376/// SecurityProperty
11377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11378#[cfg_attr(feature = "bindings", derive(TS))]
11379pub struct SecurityProperty {
11380    pub this: Box<Expression>,
11381}
11382
11383/// SchemaCommentProperty
11384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11385#[cfg_attr(feature = "bindings", derive(TS))]
11386pub struct SchemaCommentProperty {
11387    pub this: Box<Expression>,
11388}
11389
11390/// SemanticView
11391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11392#[cfg_attr(feature = "bindings", derive(TS))]
11393pub struct SemanticView {
11394    pub this: Box<Expression>,
11395    #[serde(default)]
11396    pub metrics: Option<Box<Expression>>,
11397    #[serde(default)]
11398    pub dimensions: Option<Box<Expression>>,
11399    #[serde(default)]
11400    pub facts: Option<Box<Expression>>,
11401    #[serde(default)]
11402    pub where_: Option<Box<Expression>>,
11403}
11404
11405/// SerdeProperties
11406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11407#[cfg_attr(feature = "bindings", derive(TS))]
11408pub struct SerdeProperties {
11409    #[serde(default)]
11410    pub expressions: Vec<Expression>,
11411    #[serde(default)]
11412    pub with_: Option<Box<Expression>>,
11413}
11414
11415/// SetProperty
11416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11417#[cfg_attr(feature = "bindings", derive(TS))]
11418pub struct SetProperty {
11419    #[serde(default)]
11420    pub multi: Option<Box<Expression>>,
11421}
11422
11423/// SharingProperty
11424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11425#[cfg_attr(feature = "bindings", derive(TS))]
11426pub struct SharingProperty {
11427    #[serde(default)]
11428    pub this: Option<Box<Expression>>,
11429}
11430
11431/// SetConfigProperty
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct SetConfigProperty {
11435    pub this: Box<Expression>,
11436}
11437
11438/// SettingsProperty
11439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11440#[cfg_attr(feature = "bindings", derive(TS))]
11441pub struct SettingsProperty {
11442    #[serde(default)]
11443    pub expressions: Vec<Expression>,
11444}
11445
11446/// SortKeyProperty
11447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11448#[cfg_attr(feature = "bindings", derive(TS))]
11449pub struct SortKeyProperty {
11450    pub this: Box<Expression>,
11451    #[serde(default)]
11452    pub compound: Option<Box<Expression>>,
11453}
11454
11455/// SqlReadWriteProperty
11456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11457#[cfg_attr(feature = "bindings", derive(TS))]
11458pub struct SqlReadWriteProperty {
11459    pub this: Box<Expression>,
11460}
11461
11462/// SqlSecurityProperty
11463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11464#[cfg_attr(feature = "bindings", derive(TS))]
11465pub struct SqlSecurityProperty {
11466    pub this: Box<Expression>,
11467}
11468
11469/// StabilityProperty
11470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11471#[cfg_attr(feature = "bindings", derive(TS))]
11472pub struct StabilityProperty {
11473    pub this: Box<Expression>,
11474}
11475
11476/// StorageHandlerProperty
11477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11478#[cfg_attr(feature = "bindings", derive(TS))]
11479pub struct StorageHandlerProperty {
11480    pub this: Box<Expression>,
11481}
11482
11483/// TemporaryProperty
11484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11485#[cfg_attr(feature = "bindings", derive(TS))]
11486pub struct TemporaryProperty {
11487    #[serde(default)]
11488    pub this: Option<Box<Expression>>,
11489}
11490
11491/// Tags
11492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11493#[cfg_attr(feature = "bindings", derive(TS))]
11494pub struct Tags {
11495    #[serde(default)]
11496    pub expressions: Vec<Expression>,
11497}
11498
11499/// TransformModelProperty
11500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11501#[cfg_attr(feature = "bindings", derive(TS))]
11502pub struct TransformModelProperty {
11503    #[serde(default)]
11504    pub expressions: Vec<Expression>,
11505}
11506
11507/// TransientProperty
11508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11509#[cfg_attr(feature = "bindings", derive(TS))]
11510pub struct TransientProperty {
11511    #[serde(default)]
11512    pub this: Option<Box<Expression>>,
11513}
11514
11515/// UsingTemplateProperty
11516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11517#[cfg_attr(feature = "bindings", derive(TS))]
11518pub struct UsingTemplateProperty {
11519    pub this: Box<Expression>,
11520}
11521
11522/// ViewAttributeProperty
11523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11524#[cfg_attr(feature = "bindings", derive(TS))]
11525pub struct ViewAttributeProperty {
11526    pub this: Box<Expression>,
11527}
11528
11529/// VolatileProperty
11530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11531#[cfg_attr(feature = "bindings", derive(TS))]
11532pub struct VolatileProperty {
11533    #[serde(default)]
11534    pub this: Option<Box<Expression>>,
11535}
11536
11537/// WithDataProperty
11538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11539#[cfg_attr(feature = "bindings", derive(TS))]
11540pub struct WithDataProperty {
11541    #[serde(default)]
11542    pub no: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub statistics: Option<Box<Expression>>,
11545}
11546
11547/// WithJournalTableProperty
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct WithJournalTableProperty {
11551    pub this: Box<Expression>,
11552}
11553
11554/// WithSchemaBindingProperty
11555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11556#[cfg_attr(feature = "bindings", derive(TS))]
11557pub struct WithSchemaBindingProperty {
11558    pub this: Box<Expression>,
11559}
11560
11561/// WithSystemVersioningProperty
11562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11563#[cfg_attr(feature = "bindings", derive(TS))]
11564pub struct WithSystemVersioningProperty {
11565    #[serde(default)]
11566    pub on: Option<Box<Expression>>,
11567    #[serde(default)]
11568    pub this: Option<Box<Expression>>,
11569    #[serde(default)]
11570    pub data_consistency: Option<Box<Expression>>,
11571    #[serde(default)]
11572    pub retention_period: Option<Box<Expression>>,
11573    #[serde(default)]
11574    pub with_: Option<Box<Expression>>,
11575}
11576
11577/// WithProcedureOptions
11578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11579#[cfg_attr(feature = "bindings", derive(TS))]
11580pub struct WithProcedureOptions {
11581    #[serde(default)]
11582    pub expressions: Vec<Expression>,
11583}
11584
11585/// EncodeProperty
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct EncodeProperty {
11589    pub this: Box<Expression>,
11590    #[serde(default)]
11591    pub properties: Vec<Expression>,
11592    #[serde(default)]
11593    pub key: Option<Box<Expression>>,
11594}
11595
11596/// IncludeProperty
11597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11598#[cfg_attr(feature = "bindings", derive(TS))]
11599pub struct IncludeProperty {
11600    pub this: Box<Expression>,
11601    #[serde(default)]
11602    pub alias: Option<String>,
11603    #[serde(default)]
11604    pub column_def: Option<Box<Expression>>,
11605}
11606
11607/// Properties
11608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11609#[cfg_attr(feature = "bindings", derive(TS))]
11610pub struct Properties {
11611    #[serde(default)]
11612    pub expressions: Vec<Expression>,
11613}
11614
11615/// Key/value pair in a BigQuery OPTIONS (...) clause.
11616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11617#[cfg_attr(feature = "bindings", derive(TS))]
11618pub struct OptionEntry {
11619    pub key: Identifier,
11620    pub value: Expression,
11621}
11622
11623/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11625#[cfg_attr(feature = "bindings", derive(TS))]
11626pub struct OptionsProperty {
11627    #[serde(default)]
11628    pub entries: Vec<OptionEntry>,
11629}
11630
11631/// InputOutputFormat
11632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11633#[cfg_attr(feature = "bindings", derive(TS))]
11634pub struct InputOutputFormat {
11635    #[serde(default)]
11636    pub input_format: Option<Box<Expression>>,
11637    #[serde(default)]
11638    pub output_format: Option<Box<Expression>>,
11639}
11640
11641/// Reference
11642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11643#[cfg_attr(feature = "bindings", derive(TS))]
11644pub struct Reference {
11645    pub this: Box<Expression>,
11646    #[serde(default)]
11647    pub expressions: Vec<Expression>,
11648    #[serde(default)]
11649    pub options: Vec<Expression>,
11650}
11651
11652/// QueryOption
11653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11654#[cfg_attr(feature = "bindings", derive(TS))]
11655pub struct QueryOption {
11656    pub this: Box<Expression>,
11657    #[serde(default)]
11658    pub expression: Option<Box<Expression>>,
11659}
11660
11661/// WithTableHint
11662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11663#[cfg_attr(feature = "bindings", derive(TS))]
11664pub struct WithTableHint {
11665    #[serde(default)]
11666    pub expressions: Vec<Expression>,
11667}
11668
11669/// IndexTableHint
11670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11671#[cfg_attr(feature = "bindings", derive(TS))]
11672pub struct IndexTableHint {
11673    pub this: Box<Expression>,
11674    #[serde(default)]
11675    pub expressions: Vec<Expression>,
11676    #[serde(default)]
11677    pub target: Option<Box<Expression>>,
11678}
11679
11680/// Get
11681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11682#[cfg_attr(feature = "bindings", derive(TS))]
11683pub struct Get {
11684    pub this: Box<Expression>,
11685    #[serde(default)]
11686    pub target: Option<Box<Expression>>,
11687    #[serde(default)]
11688    pub properties: Vec<Expression>,
11689}
11690
11691/// SetOperation
11692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11693#[cfg_attr(feature = "bindings", derive(TS))]
11694pub struct SetOperation {
11695    #[serde(default)]
11696    pub with_: Option<Box<Expression>>,
11697    pub this: Box<Expression>,
11698    pub expression: Box<Expression>,
11699    #[serde(default)]
11700    pub distinct: bool,
11701    #[serde(default)]
11702    pub by_name: Option<Box<Expression>>,
11703    #[serde(default)]
11704    pub side: Option<Box<Expression>>,
11705    #[serde(default)]
11706    pub kind: Option<String>,
11707    #[serde(default)]
11708    pub on: Option<Box<Expression>>,
11709}
11710
11711/// Var - Simple variable reference (for SQL variables, keywords as values)
11712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11713#[cfg_attr(feature = "bindings", derive(TS))]
11714pub struct Var {
11715    pub this: String,
11716}
11717
11718/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11720#[cfg_attr(feature = "bindings", derive(TS))]
11721pub struct Variadic {
11722    pub this: Box<Expression>,
11723}
11724
11725/// Version
11726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11727#[cfg_attr(feature = "bindings", derive(TS))]
11728pub struct Version {
11729    pub this: Box<Expression>,
11730    pub kind: String,
11731    #[serde(default)]
11732    pub expression: Option<Box<Expression>>,
11733}
11734
11735/// Schema
11736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11737#[cfg_attr(feature = "bindings", derive(TS))]
11738pub struct Schema {
11739    #[serde(default)]
11740    pub this: Option<Box<Expression>>,
11741    #[serde(default)]
11742    pub expressions: Vec<Expression>,
11743}
11744
11745/// Lock
11746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11747#[cfg_attr(feature = "bindings", derive(TS))]
11748pub struct Lock {
11749    #[serde(default)]
11750    pub update: Option<Box<Expression>>,
11751    #[serde(default)]
11752    pub expressions: Vec<Expression>,
11753    #[serde(default)]
11754    pub wait: Option<Box<Expression>>,
11755    #[serde(default)]
11756    pub key: Option<Box<Expression>>,
11757}
11758
11759/// TableSample - wraps an expression with a TABLESAMPLE clause
11760/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11762#[cfg_attr(feature = "bindings", derive(TS))]
11763pub struct TableSample {
11764    /// The expression being sampled (subquery, function, etc.)
11765    #[serde(default, skip_serializing_if = "Option::is_none")]
11766    pub this: Option<Box<Expression>>,
11767    /// The sample specification
11768    #[serde(default, skip_serializing_if = "Option::is_none")]
11769    pub sample: Option<Box<Sample>>,
11770    #[serde(default)]
11771    pub expressions: Vec<Expression>,
11772    #[serde(default)]
11773    pub method: Option<String>,
11774    #[serde(default)]
11775    pub bucket_numerator: Option<Box<Expression>>,
11776    #[serde(default)]
11777    pub bucket_denominator: Option<Box<Expression>>,
11778    #[serde(default)]
11779    pub bucket_field: Option<Box<Expression>>,
11780    #[serde(default)]
11781    pub percent: Option<Box<Expression>>,
11782    #[serde(default)]
11783    pub rows: Option<Box<Expression>>,
11784    #[serde(default)]
11785    pub size: Option<i64>,
11786    #[serde(default)]
11787    pub seed: Option<Box<Expression>>,
11788}
11789
11790/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11792#[cfg_attr(feature = "bindings", derive(TS))]
11793pub struct Tag {
11794    #[serde(default)]
11795    pub this: Option<Box<Expression>>,
11796    #[serde(default)]
11797    pub prefix: Option<Box<Expression>>,
11798    #[serde(default)]
11799    pub postfix: Option<Box<Expression>>,
11800}
11801
11802/// UnpivotColumns
11803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11804#[cfg_attr(feature = "bindings", derive(TS))]
11805pub struct UnpivotColumns {
11806    pub this: Box<Expression>,
11807    #[serde(default)]
11808    pub expressions: Vec<Expression>,
11809}
11810
11811/// SessionParameter
11812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11813#[cfg_attr(feature = "bindings", derive(TS))]
11814pub struct SessionParameter {
11815    pub this: Box<Expression>,
11816    #[serde(default)]
11817    pub kind: Option<String>,
11818}
11819
11820/// PseudoType
11821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11822#[cfg_attr(feature = "bindings", derive(TS))]
11823pub struct PseudoType {
11824    pub this: Box<Expression>,
11825}
11826
11827/// ObjectIdentifier
11828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11829#[cfg_attr(feature = "bindings", derive(TS))]
11830pub struct ObjectIdentifier {
11831    pub this: Box<Expression>,
11832}
11833
11834/// Transaction
11835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11836#[cfg_attr(feature = "bindings", derive(TS))]
11837pub struct Transaction {
11838    #[serde(default)]
11839    pub this: Option<Box<Expression>>,
11840    #[serde(default)]
11841    pub modes: Option<Box<Expression>>,
11842    #[serde(default)]
11843    pub mark: Option<Box<Expression>>,
11844}
11845
11846/// Commit
11847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11848#[cfg_attr(feature = "bindings", derive(TS))]
11849pub struct Commit {
11850    #[serde(default)]
11851    pub chain: Option<Box<Expression>>,
11852    #[serde(default)]
11853    pub this: Option<Box<Expression>>,
11854    #[serde(default)]
11855    pub durability: Option<Box<Expression>>,
11856}
11857
11858/// Rollback
11859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11860#[cfg_attr(feature = "bindings", derive(TS))]
11861pub struct Rollback {
11862    #[serde(default)]
11863    pub savepoint: Option<Box<Expression>>,
11864    #[serde(default)]
11865    pub this: Option<Box<Expression>>,
11866}
11867
11868/// AlterSession
11869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11870#[cfg_attr(feature = "bindings", derive(TS))]
11871pub struct AlterSession {
11872    #[serde(default)]
11873    pub expressions: Vec<Expression>,
11874    #[serde(default)]
11875    pub unset: Option<Box<Expression>>,
11876}
11877
11878/// Analyze
11879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11880#[cfg_attr(feature = "bindings", derive(TS))]
11881pub struct Analyze {
11882    #[serde(default)]
11883    pub kind: Option<String>,
11884    #[serde(default)]
11885    pub this: Option<Box<Expression>>,
11886    #[serde(default)]
11887    pub options: Vec<Expression>,
11888    #[serde(default)]
11889    pub mode: Option<Box<Expression>>,
11890    #[serde(default)]
11891    pub partition: Option<Box<Expression>>,
11892    #[serde(default)]
11893    pub expression: Option<Box<Expression>>,
11894    #[serde(default)]
11895    pub properties: Vec<Expression>,
11896    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
11897    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11898    pub columns: Vec<String>,
11899}
11900
11901/// AnalyzeStatistics
11902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11903#[cfg_attr(feature = "bindings", derive(TS))]
11904pub struct AnalyzeStatistics {
11905    pub kind: String,
11906    #[serde(default)]
11907    pub option: Option<Box<Expression>>,
11908    #[serde(default)]
11909    pub this: Option<Box<Expression>>,
11910    #[serde(default)]
11911    pub expressions: Vec<Expression>,
11912}
11913
11914/// AnalyzeHistogram
11915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11916#[cfg_attr(feature = "bindings", derive(TS))]
11917pub struct AnalyzeHistogram {
11918    pub this: Box<Expression>,
11919    #[serde(default)]
11920    pub expressions: Vec<Expression>,
11921    #[serde(default)]
11922    pub expression: Option<Box<Expression>>,
11923    #[serde(default)]
11924    pub update_options: Option<Box<Expression>>,
11925}
11926
11927/// AnalyzeSample
11928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11929#[cfg_attr(feature = "bindings", derive(TS))]
11930pub struct AnalyzeSample {
11931    pub kind: String,
11932    #[serde(default)]
11933    pub sample: Option<Box<Expression>>,
11934}
11935
11936/// AnalyzeListChainedRows
11937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11938#[cfg_attr(feature = "bindings", derive(TS))]
11939pub struct AnalyzeListChainedRows {
11940    #[serde(default)]
11941    pub expression: Option<Box<Expression>>,
11942}
11943
11944/// AnalyzeDelete
11945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11946#[cfg_attr(feature = "bindings", derive(TS))]
11947pub struct AnalyzeDelete {
11948    #[serde(default)]
11949    pub kind: Option<String>,
11950}
11951
11952/// AnalyzeWith
11953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11954#[cfg_attr(feature = "bindings", derive(TS))]
11955pub struct AnalyzeWith {
11956    #[serde(default)]
11957    pub expressions: Vec<Expression>,
11958}
11959
11960/// AnalyzeValidate
11961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11962#[cfg_attr(feature = "bindings", derive(TS))]
11963pub struct AnalyzeValidate {
11964    pub kind: String,
11965    #[serde(default)]
11966    pub this: Option<Box<Expression>>,
11967    #[serde(default)]
11968    pub expression: Option<Box<Expression>>,
11969}
11970
11971/// AddPartition
11972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11973#[cfg_attr(feature = "bindings", derive(TS))]
11974pub struct AddPartition {
11975    pub this: Box<Expression>,
11976    #[serde(default)]
11977    pub exists: bool,
11978    #[serde(default)]
11979    pub location: Option<Box<Expression>>,
11980}
11981
11982/// AttachOption
11983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11984#[cfg_attr(feature = "bindings", derive(TS))]
11985pub struct AttachOption {
11986    pub this: Box<Expression>,
11987    #[serde(default)]
11988    pub expression: Option<Box<Expression>>,
11989}
11990
11991/// DropPartition
11992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11993#[cfg_attr(feature = "bindings", derive(TS))]
11994pub struct DropPartition {
11995    #[serde(default)]
11996    pub expressions: Vec<Expression>,
11997    #[serde(default)]
11998    pub exists: bool,
11999}
12000
12001/// ReplacePartition
12002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12003#[cfg_attr(feature = "bindings", derive(TS))]
12004pub struct ReplacePartition {
12005    pub expression: Box<Expression>,
12006    #[serde(default)]
12007    pub source: Option<Box<Expression>>,
12008}
12009
12010/// DPipe
12011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12012#[cfg_attr(feature = "bindings", derive(TS))]
12013pub struct DPipe {
12014    pub this: Box<Expression>,
12015    pub expression: Box<Expression>,
12016    #[serde(default)]
12017    pub safe: Option<Box<Expression>>,
12018}
12019
12020/// Operator
12021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12022#[cfg_attr(feature = "bindings", derive(TS))]
12023pub struct Operator {
12024    pub this: Box<Expression>,
12025    #[serde(default)]
12026    pub operator: Option<Box<Expression>>,
12027    pub expression: Box<Expression>,
12028    /// Comments between OPERATOR() and the RHS expression
12029    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12030    pub comments: Vec<String>,
12031}
12032
12033/// PivotAny
12034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12035#[cfg_attr(feature = "bindings", derive(TS))]
12036pub struct PivotAny {
12037    #[serde(default)]
12038    pub this: Option<Box<Expression>>,
12039}
12040
12041/// Aliases
12042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12043#[cfg_attr(feature = "bindings", derive(TS))]
12044pub struct Aliases {
12045    pub this: Box<Expression>,
12046    #[serde(default)]
12047    pub expressions: Vec<Expression>,
12048}
12049
12050/// AtIndex
12051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12052#[cfg_attr(feature = "bindings", derive(TS))]
12053pub struct AtIndex {
12054    pub this: Box<Expression>,
12055    pub expression: Box<Expression>,
12056}
12057
12058/// FromTimeZone
12059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12060#[cfg_attr(feature = "bindings", derive(TS))]
12061pub struct FromTimeZone {
12062    pub this: Box<Expression>,
12063    #[serde(default)]
12064    pub zone: Option<Box<Expression>>,
12065}
12066
12067/// Format override for a column in Teradata
12068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12069#[cfg_attr(feature = "bindings", derive(TS))]
12070pub struct FormatPhrase {
12071    pub this: Box<Expression>,
12072    pub format: String,
12073}
12074
12075/// ForIn
12076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12077#[cfg_attr(feature = "bindings", derive(TS))]
12078pub struct ForIn {
12079    pub this: Box<Expression>,
12080    pub expression: Box<Expression>,
12081}
12082
12083/// Automatically converts unit arg into a var.
12084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12085#[cfg_attr(feature = "bindings", derive(TS))]
12086pub struct TimeUnit {
12087    #[serde(default)]
12088    pub unit: Option<String>,
12089}
12090
12091/// IntervalOp
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct IntervalOp {
12095    #[serde(default)]
12096    pub unit: Option<String>,
12097    pub expression: Box<Expression>,
12098}
12099
12100/// HavingMax
12101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12102#[cfg_attr(feature = "bindings", derive(TS))]
12103pub struct HavingMax {
12104    pub this: Box<Expression>,
12105    pub expression: Box<Expression>,
12106    #[serde(default)]
12107    pub max: Option<Box<Expression>>,
12108}
12109
12110/// CosineDistance
12111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12112#[cfg_attr(feature = "bindings", derive(TS))]
12113pub struct CosineDistance {
12114    pub this: Box<Expression>,
12115    pub expression: Box<Expression>,
12116}
12117
12118/// DotProduct
12119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12120#[cfg_attr(feature = "bindings", derive(TS))]
12121pub struct DotProduct {
12122    pub this: Box<Expression>,
12123    pub expression: Box<Expression>,
12124}
12125
12126/// EuclideanDistance
12127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12128#[cfg_attr(feature = "bindings", derive(TS))]
12129pub struct EuclideanDistance {
12130    pub this: Box<Expression>,
12131    pub expression: Box<Expression>,
12132}
12133
12134/// ManhattanDistance
12135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12136#[cfg_attr(feature = "bindings", derive(TS))]
12137pub struct ManhattanDistance {
12138    pub this: Box<Expression>,
12139    pub expression: Box<Expression>,
12140}
12141
12142/// JarowinklerSimilarity
12143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12144#[cfg_attr(feature = "bindings", derive(TS))]
12145pub struct JarowinklerSimilarity {
12146    pub this: Box<Expression>,
12147    pub expression: Box<Expression>,
12148}
12149
12150/// Booland
12151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12152#[cfg_attr(feature = "bindings", derive(TS))]
12153pub struct Booland {
12154    pub this: Box<Expression>,
12155    pub expression: Box<Expression>,
12156}
12157
12158/// Boolor
12159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12160#[cfg_attr(feature = "bindings", derive(TS))]
12161pub struct Boolor {
12162    pub this: Box<Expression>,
12163    pub expression: Box<Expression>,
12164}
12165
12166/// ParameterizedAgg
12167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12168#[cfg_attr(feature = "bindings", derive(TS))]
12169pub struct ParameterizedAgg {
12170    pub this: Box<Expression>,
12171    #[serde(default)]
12172    pub expressions: Vec<Expression>,
12173    #[serde(default)]
12174    pub params: Vec<Expression>,
12175}
12176
12177/// ArgMax
12178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12179#[cfg_attr(feature = "bindings", derive(TS))]
12180pub struct ArgMax {
12181    pub this: Box<Expression>,
12182    pub expression: Box<Expression>,
12183    #[serde(default)]
12184    pub count: Option<Box<Expression>>,
12185}
12186
12187/// ArgMin
12188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12189#[cfg_attr(feature = "bindings", derive(TS))]
12190pub struct ArgMin {
12191    pub this: Box<Expression>,
12192    pub expression: Box<Expression>,
12193    #[serde(default)]
12194    pub count: Option<Box<Expression>>,
12195}
12196
12197/// ApproxTopK
12198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12199#[cfg_attr(feature = "bindings", derive(TS))]
12200pub struct ApproxTopK {
12201    pub this: Box<Expression>,
12202    #[serde(default)]
12203    pub expression: Option<Box<Expression>>,
12204    #[serde(default)]
12205    pub counters: Option<Box<Expression>>,
12206}
12207
12208/// ApproxTopKAccumulate
12209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12210#[cfg_attr(feature = "bindings", derive(TS))]
12211pub struct ApproxTopKAccumulate {
12212    pub this: Box<Expression>,
12213    #[serde(default)]
12214    pub expression: Option<Box<Expression>>,
12215}
12216
12217/// ApproxTopKCombine
12218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12219#[cfg_attr(feature = "bindings", derive(TS))]
12220pub struct ApproxTopKCombine {
12221    pub this: Box<Expression>,
12222    #[serde(default)]
12223    pub expression: Option<Box<Expression>>,
12224}
12225
12226/// ApproxTopKEstimate
12227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12228#[cfg_attr(feature = "bindings", derive(TS))]
12229pub struct ApproxTopKEstimate {
12230    pub this: Box<Expression>,
12231    #[serde(default)]
12232    pub expression: Option<Box<Expression>>,
12233}
12234
12235/// ApproxTopSum
12236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12237#[cfg_attr(feature = "bindings", derive(TS))]
12238pub struct ApproxTopSum {
12239    pub this: Box<Expression>,
12240    pub expression: Box<Expression>,
12241    #[serde(default)]
12242    pub count: Option<Box<Expression>>,
12243}
12244
12245/// ApproxQuantiles
12246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12247#[cfg_attr(feature = "bindings", derive(TS))]
12248pub struct ApproxQuantiles {
12249    pub this: Box<Expression>,
12250    #[serde(default)]
12251    pub expression: Option<Box<Expression>>,
12252}
12253
12254/// Minhash
12255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12256#[cfg_attr(feature = "bindings", derive(TS))]
12257pub struct Minhash {
12258    pub this: Box<Expression>,
12259    #[serde(default)]
12260    pub expressions: Vec<Expression>,
12261}
12262
12263/// FarmFingerprint
12264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12265#[cfg_attr(feature = "bindings", derive(TS))]
12266pub struct FarmFingerprint {
12267    #[serde(default)]
12268    pub expressions: Vec<Expression>,
12269}
12270
12271/// Float64
12272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12273#[cfg_attr(feature = "bindings", derive(TS))]
12274pub struct Float64 {
12275    pub this: Box<Expression>,
12276    #[serde(default)]
12277    pub expression: Option<Box<Expression>>,
12278}
12279
12280/// Transform
12281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12282#[cfg_attr(feature = "bindings", derive(TS))]
12283pub struct Transform {
12284    pub this: Box<Expression>,
12285    pub expression: Box<Expression>,
12286}
12287
12288/// Translate
12289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12290#[cfg_attr(feature = "bindings", derive(TS))]
12291pub struct Translate {
12292    pub this: Box<Expression>,
12293    #[serde(default)]
12294    pub from_: Option<Box<Expression>>,
12295    #[serde(default)]
12296    pub to: Option<Box<Expression>>,
12297}
12298
12299/// Grouping
12300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12301#[cfg_attr(feature = "bindings", derive(TS))]
12302pub struct Grouping {
12303    #[serde(default)]
12304    pub expressions: Vec<Expression>,
12305}
12306
12307/// GroupingId
12308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12309#[cfg_attr(feature = "bindings", derive(TS))]
12310pub struct GroupingId {
12311    #[serde(default)]
12312    pub expressions: Vec<Expression>,
12313}
12314
12315/// Anonymous
12316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12317#[cfg_attr(feature = "bindings", derive(TS))]
12318pub struct Anonymous {
12319    pub this: Box<Expression>,
12320    #[serde(default)]
12321    pub expressions: Vec<Expression>,
12322}
12323
12324/// AnonymousAggFunc
12325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12326#[cfg_attr(feature = "bindings", derive(TS))]
12327pub struct AnonymousAggFunc {
12328    pub this: Box<Expression>,
12329    #[serde(default)]
12330    pub expressions: Vec<Expression>,
12331}
12332
12333/// CombinedAggFunc
12334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12335#[cfg_attr(feature = "bindings", derive(TS))]
12336pub struct CombinedAggFunc {
12337    pub this: Box<Expression>,
12338    #[serde(default)]
12339    pub expressions: Vec<Expression>,
12340}
12341
12342/// CombinedParameterizedAgg
12343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12344#[cfg_attr(feature = "bindings", derive(TS))]
12345pub struct CombinedParameterizedAgg {
12346    pub this: Box<Expression>,
12347    #[serde(default)]
12348    pub expressions: Vec<Expression>,
12349    #[serde(default)]
12350    pub params: Vec<Expression>,
12351}
12352
12353/// HashAgg
12354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12355#[cfg_attr(feature = "bindings", derive(TS))]
12356pub struct HashAgg {
12357    pub this: Box<Expression>,
12358    #[serde(default)]
12359    pub expressions: Vec<Expression>,
12360}
12361
12362/// Hll
12363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12364#[cfg_attr(feature = "bindings", derive(TS))]
12365pub struct Hll {
12366    pub this: Box<Expression>,
12367    #[serde(default)]
12368    pub expressions: Vec<Expression>,
12369}
12370
12371/// Apply
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct Apply {
12375    pub this: Box<Expression>,
12376    pub expression: Box<Expression>,
12377}
12378
12379/// ToBoolean
12380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12381#[cfg_attr(feature = "bindings", derive(TS))]
12382pub struct ToBoolean {
12383    pub this: Box<Expression>,
12384    #[serde(default)]
12385    pub safe: Option<Box<Expression>>,
12386}
12387
12388/// List
12389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12390#[cfg_attr(feature = "bindings", derive(TS))]
12391pub struct List {
12392    #[serde(default)]
12393    pub expressions: Vec<Expression>,
12394}
12395
12396/// ToMap - Materialize-style map constructor
12397/// Can hold either:
12398/// - A SELECT subquery (MAP(SELECT 'a', 1))
12399/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12401#[cfg_attr(feature = "bindings", derive(TS))]
12402pub struct ToMap {
12403    /// Either a Select subquery or a Struct containing PropertyEQ entries
12404    pub this: Box<Expression>,
12405}
12406
12407/// Pad
12408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12409#[cfg_attr(feature = "bindings", derive(TS))]
12410pub struct Pad {
12411    pub this: Box<Expression>,
12412    pub expression: Box<Expression>,
12413    #[serde(default)]
12414    pub fill_pattern: Option<Box<Expression>>,
12415    #[serde(default)]
12416    pub is_left: Option<Box<Expression>>,
12417}
12418
12419/// ToChar
12420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12421#[cfg_attr(feature = "bindings", derive(TS))]
12422pub struct ToChar {
12423    pub this: Box<Expression>,
12424    #[serde(default)]
12425    pub format: Option<String>,
12426    #[serde(default)]
12427    pub nlsparam: Option<Box<Expression>>,
12428    #[serde(default)]
12429    pub is_numeric: Option<Box<Expression>>,
12430}
12431
12432/// StringFunc - String type conversion function (BigQuery STRING)
12433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12434#[cfg_attr(feature = "bindings", derive(TS))]
12435pub struct StringFunc {
12436    pub this: Box<Expression>,
12437    #[serde(default)]
12438    pub zone: Option<Box<Expression>>,
12439}
12440
12441/// ToNumber
12442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12443#[cfg_attr(feature = "bindings", derive(TS))]
12444pub struct ToNumber {
12445    pub this: Box<Expression>,
12446    #[serde(default)]
12447    pub format: Option<Box<Expression>>,
12448    #[serde(default)]
12449    pub nlsparam: Option<Box<Expression>>,
12450    #[serde(default)]
12451    pub precision: Option<Box<Expression>>,
12452    #[serde(default)]
12453    pub scale: Option<Box<Expression>>,
12454    #[serde(default)]
12455    pub safe: Option<Box<Expression>>,
12456    #[serde(default)]
12457    pub safe_name: Option<Box<Expression>>,
12458}
12459
12460/// ToDouble
12461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12462#[cfg_attr(feature = "bindings", derive(TS))]
12463pub struct ToDouble {
12464    pub this: Box<Expression>,
12465    #[serde(default)]
12466    pub format: Option<String>,
12467    #[serde(default)]
12468    pub safe: Option<Box<Expression>>,
12469}
12470
12471/// ToDecfloat
12472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12473#[cfg_attr(feature = "bindings", derive(TS))]
12474pub struct ToDecfloat {
12475    pub this: Box<Expression>,
12476    #[serde(default)]
12477    pub format: Option<String>,
12478}
12479
12480/// TryToDecfloat
12481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12482#[cfg_attr(feature = "bindings", derive(TS))]
12483pub struct TryToDecfloat {
12484    pub this: Box<Expression>,
12485    #[serde(default)]
12486    pub format: Option<String>,
12487}
12488
12489/// ToFile
12490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12491#[cfg_attr(feature = "bindings", derive(TS))]
12492pub struct ToFile {
12493    pub this: Box<Expression>,
12494    #[serde(default)]
12495    pub path: Option<Box<Expression>>,
12496    #[serde(default)]
12497    pub safe: Option<Box<Expression>>,
12498}
12499
12500/// Columns
12501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12502#[cfg_attr(feature = "bindings", derive(TS))]
12503pub struct Columns {
12504    pub this: Box<Expression>,
12505    #[serde(default)]
12506    pub unpack: Option<Box<Expression>>,
12507}
12508
12509/// ConvertToCharset
12510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12511#[cfg_attr(feature = "bindings", derive(TS))]
12512pub struct ConvertToCharset {
12513    pub this: Box<Expression>,
12514    #[serde(default)]
12515    pub dest: Option<Box<Expression>>,
12516    #[serde(default)]
12517    pub source: Option<Box<Expression>>,
12518}
12519
12520/// ConvertTimezone
12521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12522#[cfg_attr(feature = "bindings", derive(TS))]
12523pub struct ConvertTimezone {
12524    #[serde(default)]
12525    pub source_tz: Option<Box<Expression>>,
12526    #[serde(default)]
12527    pub target_tz: Option<Box<Expression>>,
12528    #[serde(default)]
12529    pub timestamp: Option<Box<Expression>>,
12530    #[serde(default)]
12531    pub options: Vec<Expression>,
12532}
12533
12534/// GenerateSeries
12535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12536#[cfg_attr(feature = "bindings", derive(TS))]
12537pub struct GenerateSeries {
12538    #[serde(default)]
12539    pub start: Option<Box<Expression>>,
12540    #[serde(default)]
12541    pub end: Option<Box<Expression>>,
12542    #[serde(default)]
12543    pub step: Option<Box<Expression>>,
12544    #[serde(default)]
12545    pub is_end_exclusive: Option<Box<Expression>>,
12546}
12547
12548/// AIAgg
12549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12550#[cfg_attr(feature = "bindings", derive(TS))]
12551pub struct AIAgg {
12552    pub this: Box<Expression>,
12553    pub expression: Box<Expression>,
12554}
12555
12556/// AIClassify
12557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12558#[cfg_attr(feature = "bindings", derive(TS))]
12559pub struct AIClassify {
12560    pub this: Box<Expression>,
12561    #[serde(default)]
12562    pub categories: Option<Box<Expression>>,
12563    #[serde(default)]
12564    pub config: Option<Box<Expression>>,
12565}
12566
12567/// ArrayAll
12568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12569#[cfg_attr(feature = "bindings", derive(TS))]
12570pub struct ArrayAll {
12571    pub this: Box<Expression>,
12572    pub expression: Box<Expression>,
12573}
12574
12575/// ArrayAny
12576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12577#[cfg_attr(feature = "bindings", derive(TS))]
12578pub struct ArrayAny {
12579    pub this: Box<Expression>,
12580    pub expression: Box<Expression>,
12581}
12582
12583/// ArrayConstructCompact
12584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12585#[cfg_attr(feature = "bindings", derive(TS))]
12586pub struct ArrayConstructCompact {
12587    #[serde(default)]
12588    pub expressions: Vec<Expression>,
12589}
12590
12591/// StPoint
12592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12593#[cfg_attr(feature = "bindings", derive(TS))]
12594pub struct StPoint {
12595    pub this: Box<Expression>,
12596    pub expression: Box<Expression>,
12597    #[serde(default)]
12598    pub null: Option<Box<Expression>>,
12599}
12600
12601/// StDistance
12602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12603#[cfg_attr(feature = "bindings", derive(TS))]
12604pub struct StDistance {
12605    pub this: Box<Expression>,
12606    pub expression: Box<Expression>,
12607    #[serde(default)]
12608    pub use_spheroid: Option<Box<Expression>>,
12609}
12610
12611/// StringToArray
12612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12613#[cfg_attr(feature = "bindings", derive(TS))]
12614pub struct StringToArray {
12615    pub this: Box<Expression>,
12616    #[serde(default)]
12617    pub expression: Option<Box<Expression>>,
12618    #[serde(default)]
12619    pub null: Option<Box<Expression>>,
12620}
12621
12622/// ArraySum
12623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12624#[cfg_attr(feature = "bindings", derive(TS))]
12625pub struct ArraySum {
12626    pub this: Box<Expression>,
12627    #[serde(default)]
12628    pub expression: Option<Box<Expression>>,
12629}
12630
12631/// ObjectAgg
12632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12633#[cfg_attr(feature = "bindings", derive(TS))]
12634pub struct ObjectAgg {
12635    pub this: Box<Expression>,
12636    pub expression: Box<Expression>,
12637}
12638
12639/// CastToStrType
12640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12641#[cfg_attr(feature = "bindings", derive(TS))]
12642pub struct CastToStrType {
12643    pub this: Box<Expression>,
12644    #[serde(default)]
12645    pub to: Option<Box<Expression>>,
12646}
12647
12648/// CheckJson
12649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12650#[cfg_attr(feature = "bindings", derive(TS))]
12651pub struct CheckJson {
12652    pub this: Box<Expression>,
12653}
12654
12655/// CheckXml
12656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12657#[cfg_attr(feature = "bindings", derive(TS))]
12658pub struct CheckXml {
12659    pub this: Box<Expression>,
12660    #[serde(default)]
12661    pub disable_auto_convert: Option<Box<Expression>>,
12662}
12663
12664/// TranslateCharacters
12665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12666#[cfg_attr(feature = "bindings", derive(TS))]
12667pub struct TranslateCharacters {
12668    pub this: Box<Expression>,
12669    pub expression: Box<Expression>,
12670    #[serde(default)]
12671    pub with_error: Option<Box<Expression>>,
12672}
12673
12674/// CurrentSchemas
12675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12676#[cfg_attr(feature = "bindings", derive(TS))]
12677pub struct CurrentSchemas {
12678    #[serde(default)]
12679    pub this: Option<Box<Expression>>,
12680}
12681
12682/// CurrentDatetime
12683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12684#[cfg_attr(feature = "bindings", derive(TS))]
12685pub struct CurrentDatetime {
12686    #[serde(default)]
12687    pub this: Option<Box<Expression>>,
12688}
12689
12690/// Localtime
12691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12692#[cfg_attr(feature = "bindings", derive(TS))]
12693pub struct Localtime {
12694    #[serde(default)]
12695    pub this: Option<Box<Expression>>,
12696}
12697
12698/// Localtimestamp
12699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12700#[cfg_attr(feature = "bindings", derive(TS))]
12701pub struct Localtimestamp {
12702    #[serde(default)]
12703    pub this: Option<Box<Expression>>,
12704}
12705
12706/// Systimestamp
12707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12708#[cfg_attr(feature = "bindings", derive(TS))]
12709pub struct Systimestamp {
12710    #[serde(default)]
12711    pub this: Option<Box<Expression>>,
12712}
12713
12714/// CurrentSchema
12715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12716#[cfg_attr(feature = "bindings", derive(TS))]
12717pub struct CurrentSchema {
12718    #[serde(default)]
12719    pub this: Option<Box<Expression>>,
12720}
12721
12722/// CurrentUser
12723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12724#[cfg_attr(feature = "bindings", derive(TS))]
12725pub struct CurrentUser {
12726    #[serde(default)]
12727    pub this: Option<Box<Expression>>,
12728}
12729
12730/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12732#[cfg_attr(feature = "bindings", derive(TS))]
12733pub struct SessionUser;
12734
12735/// JSONPathRoot - Represents $ in JSON path expressions
12736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12737#[cfg_attr(feature = "bindings", derive(TS))]
12738pub struct JSONPathRoot;
12739
12740/// UtcTime
12741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12742#[cfg_attr(feature = "bindings", derive(TS))]
12743pub struct UtcTime {
12744    #[serde(default)]
12745    pub this: Option<Box<Expression>>,
12746}
12747
12748/// UtcTimestamp
12749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12750#[cfg_attr(feature = "bindings", derive(TS))]
12751pub struct UtcTimestamp {
12752    #[serde(default)]
12753    pub this: Option<Box<Expression>>,
12754}
12755
12756/// TimestampFunc - TIMESTAMP constructor function
12757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12758#[cfg_attr(feature = "bindings", derive(TS))]
12759pub struct TimestampFunc {
12760    #[serde(default)]
12761    pub this: Option<Box<Expression>>,
12762    #[serde(default)]
12763    pub zone: Option<Box<Expression>>,
12764    #[serde(default)]
12765    pub with_tz: Option<bool>,
12766    #[serde(default)]
12767    pub safe: Option<bool>,
12768}
12769
12770/// DateBin
12771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12772#[cfg_attr(feature = "bindings", derive(TS))]
12773pub struct DateBin {
12774    pub this: Box<Expression>,
12775    pub expression: Box<Expression>,
12776    #[serde(default)]
12777    pub unit: Option<String>,
12778    #[serde(default)]
12779    pub zone: Option<Box<Expression>>,
12780    #[serde(default)]
12781    pub origin: Option<Box<Expression>>,
12782}
12783
12784/// Datetime
12785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12786#[cfg_attr(feature = "bindings", derive(TS))]
12787pub struct Datetime {
12788    pub this: Box<Expression>,
12789    #[serde(default)]
12790    pub expression: Option<Box<Expression>>,
12791}
12792
12793/// DatetimeAdd
12794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12795#[cfg_attr(feature = "bindings", derive(TS))]
12796pub struct DatetimeAdd {
12797    pub this: Box<Expression>,
12798    pub expression: Box<Expression>,
12799    #[serde(default)]
12800    pub unit: Option<String>,
12801}
12802
12803/// DatetimeSub
12804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12805#[cfg_attr(feature = "bindings", derive(TS))]
12806pub struct DatetimeSub {
12807    pub this: Box<Expression>,
12808    pub expression: Box<Expression>,
12809    #[serde(default)]
12810    pub unit: Option<String>,
12811}
12812
12813/// DatetimeDiff
12814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12815#[cfg_attr(feature = "bindings", derive(TS))]
12816pub struct DatetimeDiff {
12817    pub this: Box<Expression>,
12818    pub expression: Box<Expression>,
12819    #[serde(default)]
12820    pub unit: Option<String>,
12821}
12822
12823/// DatetimeTrunc
12824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12825#[cfg_attr(feature = "bindings", derive(TS))]
12826pub struct DatetimeTrunc {
12827    pub this: Box<Expression>,
12828    pub unit: String,
12829    #[serde(default)]
12830    pub zone: Option<Box<Expression>>,
12831}
12832
12833/// Dayname
12834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12835#[cfg_attr(feature = "bindings", derive(TS))]
12836pub struct Dayname {
12837    pub this: Box<Expression>,
12838    #[serde(default)]
12839    pub abbreviated: Option<Box<Expression>>,
12840}
12841
12842/// MakeInterval
12843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12844#[cfg_attr(feature = "bindings", derive(TS))]
12845pub struct MakeInterval {
12846    #[serde(default)]
12847    pub year: Option<Box<Expression>>,
12848    #[serde(default)]
12849    pub month: Option<Box<Expression>>,
12850    #[serde(default)]
12851    pub week: Option<Box<Expression>>,
12852    #[serde(default)]
12853    pub day: Option<Box<Expression>>,
12854    #[serde(default)]
12855    pub hour: Option<Box<Expression>>,
12856    #[serde(default)]
12857    pub minute: Option<Box<Expression>>,
12858    #[serde(default)]
12859    pub second: Option<Box<Expression>>,
12860}
12861
12862/// PreviousDay
12863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12864#[cfg_attr(feature = "bindings", derive(TS))]
12865pub struct PreviousDay {
12866    pub this: Box<Expression>,
12867    pub expression: Box<Expression>,
12868}
12869
12870/// Elt
12871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12872#[cfg_attr(feature = "bindings", derive(TS))]
12873pub struct Elt {
12874    pub this: Box<Expression>,
12875    #[serde(default)]
12876    pub expressions: Vec<Expression>,
12877}
12878
12879/// TimestampAdd
12880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12881#[cfg_attr(feature = "bindings", derive(TS))]
12882pub struct TimestampAdd {
12883    pub this: Box<Expression>,
12884    pub expression: Box<Expression>,
12885    #[serde(default)]
12886    pub unit: Option<String>,
12887}
12888
12889/// TimestampSub
12890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12891#[cfg_attr(feature = "bindings", derive(TS))]
12892pub struct TimestampSub {
12893    pub this: Box<Expression>,
12894    pub expression: Box<Expression>,
12895    #[serde(default)]
12896    pub unit: Option<String>,
12897}
12898
12899/// TimestampDiff
12900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12901#[cfg_attr(feature = "bindings", derive(TS))]
12902pub struct TimestampDiff {
12903    pub this: Box<Expression>,
12904    pub expression: Box<Expression>,
12905    #[serde(default)]
12906    pub unit: Option<String>,
12907}
12908
12909/// TimeSlice
12910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12911#[cfg_attr(feature = "bindings", derive(TS))]
12912pub struct TimeSlice {
12913    pub this: Box<Expression>,
12914    pub expression: Box<Expression>,
12915    pub unit: String,
12916    #[serde(default)]
12917    pub kind: Option<String>,
12918}
12919
12920/// TimeAdd
12921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12922#[cfg_attr(feature = "bindings", derive(TS))]
12923pub struct TimeAdd {
12924    pub this: Box<Expression>,
12925    pub expression: Box<Expression>,
12926    #[serde(default)]
12927    pub unit: Option<String>,
12928}
12929
12930/// TimeSub
12931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12932#[cfg_attr(feature = "bindings", derive(TS))]
12933pub struct TimeSub {
12934    pub this: Box<Expression>,
12935    pub expression: Box<Expression>,
12936    #[serde(default)]
12937    pub unit: Option<String>,
12938}
12939
12940/// TimeDiff
12941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12942#[cfg_attr(feature = "bindings", derive(TS))]
12943pub struct TimeDiff {
12944    pub this: Box<Expression>,
12945    pub expression: Box<Expression>,
12946    #[serde(default)]
12947    pub unit: Option<String>,
12948}
12949
12950/// TimeTrunc
12951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12952#[cfg_attr(feature = "bindings", derive(TS))]
12953pub struct TimeTrunc {
12954    pub this: Box<Expression>,
12955    pub unit: String,
12956    #[serde(default)]
12957    pub zone: Option<Box<Expression>>,
12958}
12959
12960/// DateFromParts
12961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12962#[cfg_attr(feature = "bindings", derive(TS))]
12963pub struct DateFromParts {
12964    #[serde(default)]
12965    pub year: Option<Box<Expression>>,
12966    #[serde(default)]
12967    pub month: Option<Box<Expression>>,
12968    #[serde(default)]
12969    pub day: Option<Box<Expression>>,
12970    #[serde(default)]
12971    pub allow_overflow: Option<Box<Expression>>,
12972}
12973
12974/// TimeFromParts
12975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12976#[cfg_attr(feature = "bindings", derive(TS))]
12977pub struct TimeFromParts {
12978    #[serde(default)]
12979    pub hour: Option<Box<Expression>>,
12980    #[serde(default)]
12981    pub min: Option<Box<Expression>>,
12982    #[serde(default)]
12983    pub sec: Option<Box<Expression>>,
12984    #[serde(default)]
12985    pub nano: Option<Box<Expression>>,
12986    #[serde(default)]
12987    pub fractions: Option<Box<Expression>>,
12988    #[serde(default)]
12989    pub precision: Option<i64>,
12990}
12991
12992/// DecodeCase
12993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12994#[cfg_attr(feature = "bindings", derive(TS))]
12995pub struct DecodeCase {
12996    #[serde(default)]
12997    pub expressions: Vec<Expression>,
12998}
12999
13000/// Decrypt
13001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13002#[cfg_attr(feature = "bindings", derive(TS))]
13003pub struct Decrypt {
13004    pub this: Box<Expression>,
13005    #[serde(default)]
13006    pub passphrase: Option<Box<Expression>>,
13007    #[serde(default)]
13008    pub aad: Option<Box<Expression>>,
13009    #[serde(default)]
13010    pub encryption_method: Option<Box<Expression>>,
13011    #[serde(default)]
13012    pub safe: Option<Box<Expression>>,
13013}
13014
13015/// DecryptRaw
13016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13017#[cfg_attr(feature = "bindings", derive(TS))]
13018pub struct DecryptRaw {
13019    pub this: Box<Expression>,
13020    #[serde(default)]
13021    pub key: Option<Box<Expression>>,
13022    #[serde(default)]
13023    pub iv: Option<Box<Expression>>,
13024    #[serde(default)]
13025    pub aad: Option<Box<Expression>>,
13026    #[serde(default)]
13027    pub encryption_method: Option<Box<Expression>>,
13028    #[serde(default)]
13029    pub aead: Option<Box<Expression>>,
13030    #[serde(default)]
13031    pub safe: Option<Box<Expression>>,
13032}
13033
13034/// Encode
13035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13036#[cfg_attr(feature = "bindings", derive(TS))]
13037pub struct Encode {
13038    pub this: Box<Expression>,
13039    #[serde(default)]
13040    pub charset: Option<Box<Expression>>,
13041}
13042
13043/// Encrypt
13044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13045#[cfg_attr(feature = "bindings", derive(TS))]
13046pub struct Encrypt {
13047    pub this: Box<Expression>,
13048    #[serde(default)]
13049    pub passphrase: Option<Box<Expression>>,
13050    #[serde(default)]
13051    pub aad: Option<Box<Expression>>,
13052    #[serde(default)]
13053    pub encryption_method: Option<Box<Expression>>,
13054}
13055
13056/// EncryptRaw
13057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13058#[cfg_attr(feature = "bindings", derive(TS))]
13059pub struct EncryptRaw {
13060    pub this: Box<Expression>,
13061    #[serde(default)]
13062    pub key: Option<Box<Expression>>,
13063    #[serde(default)]
13064    pub iv: Option<Box<Expression>>,
13065    #[serde(default)]
13066    pub aad: Option<Box<Expression>>,
13067    #[serde(default)]
13068    pub encryption_method: Option<Box<Expression>>,
13069}
13070
13071/// EqualNull
13072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13073#[cfg_attr(feature = "bindings", derive(TS))]
13074pub struct EqualNull {
13075    pub this: Box<Expression>,
13076    pub expression: Box<Expression>,
13077}
13078
13079/// ToBinary
13080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13081#[cfg_attr(feature = "bindings", derive(TS))]
13082pub struct ToBinary {
13083    pub this: Box<Expression>,
13084    #[serde(default)]
13085    pub format: Option<String>,
13086    #[serde(default)]
13087    pub safe: Option<Box<Expression>>,
13088}
13089
13090/// Base64DecodeBinary
13091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13092#[cfg_attr(feature = "bindings", derive(TS))]
13093pub struct Base64DecodeBinary {
13094    pub this: Box<Expression>,
13095    #[serde(default)]
13096    pub alphabet: Option<Box<Expression>>,
13097}
13098
13099/// Base64DecodeString
13100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13101#[cfg_attr(feature = "bindings", derive(TS))]
13102pub struct Base64DecodeString {
13103    pub this: Box<Expression>,
13104    #[serde(default)]
13105    pub alphabet: Option<Box<Expression>>,
13106}
13107
13108/// Base64Encode
13109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13110#[cfg_attr(feature = "bindings", derive(TS))]
13111pub struct Base64Encode {
13112    pub this: Box<Expression>,
13113    #[serde(default)]
13114    pub max_line_length: Option<Box<Expression>>,
13115    #[serde(default)]
13116    pub alphabet: Option<Box<Expression>>,
13117}
13118
13119/// TryBase64DecodeBinary
13120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13121#[cfg_attr(feature = "bindings", derive(TS))]
13122pub struct TryBase64DecodeBinary {
13123    pub this: Box<Expression>,
13124    #[serde(default)]
13125    pub alphabet: Option<Box<Expression>>,
13126}
13127
13128/// TryBase64DecodeString
13129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13130#[cfg_attr(feature = "bindings", derive(TS))]
13131pub struct TryBase64DecodeString {
13132    pub this: Box<Expression>,
13133    #[serde(default)]
13134    pub alphabet: Option<Box<Expression>>,
13135}
13136
13137/// GapFill
13138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13139#[cfg_attr(feature = "bindings", derive(TS))]
13140pub struct GapFill {
13141    pub this: Box<Expression>,
13142    #[serde(default)]
13143    pub ts_column: Option<Box<Expression>>,
13144    #[serde(default)]
13145    pub bucket_width: Option<Box<Expression>>,
13146    #[serde(default)]
13147    pub partitioning_columns: Option<Box<Expression>>,
13148    #[serde(default)]
13149    pub value_columns: Option<Box<Expression>>,
13150    #[serde(default)]
13151    pub origin: Option<Box<Expression>>,
13152    #[serde(default)]
13153    pub ignore_nulls: Option<Box<Expression>>,
13154}
13155
13156/// GenerateDateArray
13157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13158#[cfg_attr(feature = "bindings", derive(TS))]
13159pub struct GenerateDateArray {
13160    #[serde(default)]
13161    pub start: Option<Box<Expression>>,
13162    #[serde(default)]
13163    pub end: Option<Box<Expression>>,
13164    #[serde(default)]
13165    pub step: Option<Box<Expression>>,
13166}
13167
13168/// GenerateTimestampArray
13169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13170#[cfg_attr(feature = "bindings", derive(TS))]
13171pub struct GenerateTimestampArray {
13172    #[serde(default)]
13173    pub start: Option<Box<Expression>>,
13174    #[serde(default)]
13175    pub end: Option<Box<Expression>>,
13176    #[serde(default)]
13177    pub step: Option<Box<Expression>>,
13178}
13179
13180/// GetExtract
13181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13182#[cfg_attr(feature = "bindings", derive(TS))]
13183pub struct GetExtract {
13184    pub this: Box<Expression>,
13185    pub expression: Box<Expression>,
13186}
13187
13188/// Getbit
13189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13190#[cfg_attr(feature = "bindings", derive(TS))]
13191pub struct Getbit {
13192    pub this: Box<Expression>,
13193    pub expression: Box<Expression>,
13194    #[serde(default)]
13195    pub zero_is_msb: Option<Box<Expression>>,
13196}
13197
13198/// OverflowTruncateBehavior
13199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13200#[cfg_attr(feature = "bindings", derive(TS))]
13201pub struct OverflowTruncateBehavior {
13202    #[serde(default)]
13203    pub this: Option<Box<Expression>>,
13204    #[serde(default)]
13205    pub with_count: Option<Box<Expression>>,
13206}
13207
13208/// HexEncode
13209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13210#[cfg_attr(feature = "bindings", derive(TS))]
13211pub struct HexEncode {
13212    pub this: Box<Expression>,
13213    #[serde(default)]
13214    pub case: Option<Box<Expression>>,
13215}
13216
13217/// Compress
13218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13219#[cfg_attr(feature = "bindings", derive(TS))]
13220pub struct Compress {
13221    pub this: Box<Expression>,
13222    #[serde(default)]
13223    pub method: Option<String>,
13224}
13225
13226/// DecompressBinary
13227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13228#[cfg_attr(feature = "bindings", derive(TS))]
13229pub struct DecompressBinary {
13230    pub this: Box<Expression>,
13231    pub method: String,
13232}
13233
13234/// DecompressString
13235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13236#[cfg_attr(feature = "bindings", derive(TS))]
13237pub struct DecompressString {
13238    pub this: Box<Expression>,
13239    pub method: String,
13240}
13241
13242/// Xor
13243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13244#[cfg_attr(feature = "bindings", derive(TS))]
13245pub struct Xor {
13246    #[serde(default)]
13247    pub this: Option<Box<Expression>>,
13248    #[serde(default)]
13249    pub expression: Option<Box<Expression>>,
13250    #[serde(default)]
13251    pub expressions: Vec<Expression>,
13252}
13253
13254/// Nullif
13255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13256#[cfg_attr(feature = "bindings", derive(TS))]
13257pub struct Nullif {
13258    pub this: Box<Expression>,
13259    pub expression: Box<Expression>,
13260}
13261
13262/// JSON
13263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13264#[cfg_attr(feature = "bindings", derive(TS))]
13265pub struct JSON {
13266    #[serde(default)]
13267    pub this: Option<Box<Expression>>,
13268    #[serde(default)]
13269    pub with_: Option<Box<Expression>>,
13270    #[serde(default)]
13271    pub unique: bool,
13272}
13273
13274/// JSONPath
13275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13276#[cfg_attr(feature = "bindings", derive(TS))]
13277pub struct JSONPath {
13278    #[serde(default)]
13279    pub expressions: Vec<Expression>,
13280    #[serde(default)]
13281    pub escape: Option<Box<Expression>>,
13282}
13283
13284/// JSONPathFilter
13285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13286#[cfg_attr(feature = "bindings", derive(TS))]
13287pub struct JSONPathFilter {
13288    pub this: Box<Expression>,
13289}
13290
13291/// JSONPathKey
13292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13293#[cfg_attr(feature = "bindings", derive(TS))]
13294pub struct JSONPathKey {
13295    pub this: Box<Expression>,
13296}
13297
13298/// JSONPathRecursive
13299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13300#[cfg_attr(feature = "bindings", derive(TS))]
13301pub struct JSONPathRecursive {
13302    #[serde(default)]
13303    pub this: Option<Box<Expression>>,
13304}
13305
13306/// JSONPathScript
13307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13308#[cfg_attr(feature = "bindings", derive(TS))]
13309pub struct JSONPathScript {
13310    pub this: Box<Expression>,
13311}
13312
13313/// JSONPathSlice
13314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13315#[cfg_attr(feature = "bindings", derive(TS))]
13316pub struct JSONPathSlice {
13317    #[serde(default)]
13318    pub start: Option<Box<Expression>>,
13319    #[serde(default)]
13320    pub end: Option<Box<Expression>>,
13321    #[serde(default)]
13322    pub step: Option<Box<Expression>>,
13323}
13324
13325/// JSONPathSelector
13326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13327#[cfg_attr(feature = "bindings", derive(TS))]
13328pub struct JSONPathSelector {
13329    pub this: Box<Expression>,
13330}
13331
13332/// JSONPathSubscript
13333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13334#[cfg_attr(feature = "bindings", derive(TS))]
13335pub struct JSONPathSubscript {
13336    pub this: Box<Expression>,
13337}
13338
13339/// JSONPathUnion
13340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13341#[cfg_attr(feature = "bindings", derive(TS))]
13342pub struct JSONPathUnion {
13343    #[serde(default)]
13344    pub expressions: Vec<Expression>,
13345}
13346
13347/// Format
13348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13349#[cfg_attr(feature = "bindings", derive(TS))]
13350pub struct Format {
13351    pub this: Box<Expression>,
13352    #[serde(default)]
13353    pub expressions: Vec<Expression>,
13354}
13355
13356/// JSONKeys
13357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13358#[cfg_attr(feature = "bindings", derive(TS))]
13359pub struct JSONKeys {
13360    pub this: Box<Expression>,
13361    #[serde(default)]
13362    pub expression: Option<Box<Expression>>,
13363    #[serde(default)]
13364    pub expressions: Vec<Expression>,
13365}
13366
13367/// JSONKeyValue
13368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13369#[cfg_attr(feature = "bindings", derive(TS))]
13370pub struct JSONKeyValue {
13371    pub this: Box<Expression>,
13372    pub expression: Box<Expression>,
13373}
13374
13375/// JSONKeysAtDepth
13376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13377#[cfg_attr(feature = "bindings", derive(TS))]
13378pub struct JSONKeysAtDepth {
13379    pub this: Box<Expression>,
13380    #[serde(default)]
13381    pub expression: Option<Box<Expression>>,
13382    #[serde(default)]
13383    pub mode: Option<Box<Expression>>,
13384}
13385
13386/// JSONObject
13387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13388#[cfg_attr(feature = "bindings", derive(TS))]
13389pub struct JSONObject {
13390    #[serde(default)]
13391    pub expressions: Vec<Expression>,
13392    #[serde(default)]
13393    pub null_handling: Option<Box<Expression>>,
13394    #[serde(default)]
13395    pub unique_keys: Option<Box<Expression>>,
13396    #[serde(default)]
13397    pub return_type: Option<Box<Expression>>,
13398    #[serde(default)]
13399    pub encoding: Option<Box<Expression>>,
13400}
13401
13402/// JSONObjectAgg
13403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13404#[cfg_attr(feature = "bindings", derive(TS))]
13405pub struct JSONObjectAgg {
13406    #[serde(default)]
13407    pub expressions: Vec<Expression>,
13408    #[serde(default)]
13409    pub null_handling: Option<Box<Expression>>,
13410    #[serde(default)]
13411    pub unique_keys: Option<Box<Expression>>,
13412    #[serde(default)]
13413    pub return_type: Option<Box<Expression>>,
13414    #[serde(default)]
13415    pub encoding: Option<Box<Expression>>,
13416}
13417
13418/// JSONBObjectAgg
13419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13420#[cfg_attr(feature = "bindings", derive(TS))]
13421pub struct JSONBObjectAgg {
13422    pub this: Box<Expression>,
13423    pub expression: Box<Expression>,
13424}
13425
13426/// JSONArray
13427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13428#[cfg_attr(feature = "bindings", derive(TS))]
13429pub struct JSONArray {
13430    #[serde(default)]
13431    pub expressions: Vec<Expression>,
13432    #[serde(default)]
13433    pub null_handling: Option<Box<Expression>>,
13434    #[serde(default)]
13435    pub return_type: Option<Box<Expression>>,
13436    #[serde(default)]
13437    pub strict: Option<Box<Expression>>,
13438}
13439
13440/// JSONArrayAgg
13441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13442#[cfg_attr(feature = "bindings", derive(TS))]
13443pub struct JSONArrayAgg {
13444    pub this: Box<Expression>,
13445    #[serde(default)]
13446    pub order: Option<Box<Expression>>,
13447    #[serde(default)]
13448    pub null_handling: Option<Box<Expression>>,
13449    #[serde(default)]
13450    pub return_type: Option<Box<Expression>>,
13451    #[serde(default)]
13452    pub strict: Option<Box<Expression>>,
13453}
13454
13455/// JSONExists
13456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13457#[cfg_attr(feature = "bindings", derive(TS))]
13458pub struct JSONExists {
13459    pub this: Box<Expression>,
13460    #[serde(default)]
13461    pub path: Option<Box<Expression>>,
13462    #[serde(default)]
13463    pub passing: Option<Box<Expression>>,
13464    #[serde(default)]
13465    pub on_condition: Option<Box<Expression>>,
13466    #[serde(default)]
13467    pub from_dcolonqmark: Option<Box<Expression>>,
13468}
13469
13470/// JSONColumnDef
13471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13472#[cfg_attr(feature = "bindings", derive(TS))]
13473pub struct JSONColumnDef {
13474    #[serde(default)]
13475    pub this: Option<Box<Expression>>,
13476    #[serde(default)]
13477    pub kind: Option<String>,
13478    #[serde(default)]
13479    pub path: Option<Box<Expression>>,
13480    #[serde(default)]
13481    pub nested_schema: Option<Box<Expression>>,
13482    #[serde(default)]
13483    pub ordinality: Option<Box<Expression>>,
13484}
13485
13486/// JSONSchema
13487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13488#[cfg_attr(feature = "bindings", derive(TS))]
13489pub struct JSONSchema {
13490    #[serde(default)]
13491    pub expressions: Vec<Expression>,
13492}
13493
13494/// JSONSet
13495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13496#[cfg_attr(feature = "bindings", derive(TS))]
13497pub struct JSONSet {
13498    pub this: Box<Expression>,
13499    #[serde(default)]
13500    pub expressions: Vec<Expression>,
13501}
13502
13503/// JSONStripNulls
13504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13505#[cfg_attr(feature = "bindings", derive(TS))]
13506pub struct JSONStripNulls {
13507    pub this: Box<Expression>,
13508    #[serde(default)]
13509    pub expression: Option<Box<Expression>>,
13510    #[serde(default)]
13511    pub include_arrays: Option<Box<Expression>>,
13512    #[serde(default)]
13513    pub remove_empty: Option<Box<Expression>>,
13514}
13515
13516/// JSONValue
13517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13518#[cfg_attr(feature = "bindings", derive(TS))]
13519pub struct JSONValue {
13520    pub this: Box<Expression>,
13521    #[serde(default)]
13522    pub path: Option<Box<Expression>>,
13523    #[serde(default)]
13524    pub returning: Option<Box<Expression>>,
13525    #[serde(default)]
13526    pub on_condition: Option<Box<Expression>>,
13527}
13528
13529/// JSONValueArray
13530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13531#[cfg_attr(feature = "bindings", derive(TS))]
13532pub struct JSONValueArray {
13533    pub this: Box<Expression>,
13534    #[serde(default)]
13535    pub expression: Option<Box<Expression>>,
13536}
13537
13538/// JSONRemove
13539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13540#[cfg_attr(feature = "bindings", derive(TS))]
13541pub struct JSONRemove {
13542    pub this: Box<Expression>,
13543    #[serde(default)]
13544    pub expressions: Vec<Expression>,
13545}
13546
13547/// JSONTable
13548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13549#[cfg_attr(feature = "bindings", derive(TS))]
13550pub struct JSONTable {
13551    pub this: Box<Expression>,
13552    #[serde(default)]
13553    pub schema: Option<Box<Expression>>,
13554    #[serde(default)]
13555    pub path: Option<Box<Expression>>,
13556    #[serde(default)]
13557    pub error_handling: Option<Box<Expression>>,
13558    #[serde(default)]
13559    pub empty_handling: Option<Box<Expression>>,
13560}
13561
13562/// JSONType
13563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13564#[cfg_attr(feature = "bindings", derive(TS))]
13565pub struct JSONType {
13566    pub this: Box<Expression>,
13567    #[serde(default)]
13568    pub expression: Option<Box<Expression>>,
13569}
13570
13571/// ObjectInsert
13572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13573#[cfg_attr(feature = "bindings", derive(TS))]
13574pub struct ObjectInsert {
13575    pub this: Box<Expression>,
13576    #[serde(default)]
13577    pub key: Option<Box<Expression>>,
13578    #[serde(default)]
13579    pub value: Option<Box<Expression>>,
13580    #[serde(default)]
13581    pub update_flag: Option<Box<Expression>>,
13582}
13583
13584/// OpenJSONColumnDef
13585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13586#[cfg_attr(feature = "bindings", derive(TS))]
13587pub struct OpenJSONColumnDef {
13588    pub this: Box<Expression>,
13589    pub kind: String,
13590    #[serde(default)]
13591    pub path: Option<Box<Expression>>,
13592    #[serde(default)]
13593    pub as_json: Option<Box<Expression>>,
13594    /// The parsed data type for proper generation
13595    #[serde(default, skip_serializing_if = "Option::is_none")]
13596    pub data_type: Option<DataType>,
13597}
13598
13599/// OpenJSON
13600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13601#[cfg_attr(feature = "bindings", derive(TS))]
13602pub struct OpenJSON {
13603    pub this: Box<Expression>,
13604    #[serde(default)]
13605    pub path: Option<Box<Expression>>,
13606    #[serde(default)]
13607    pub expressions: Vec<Expression>,
13608}
13609
13610/// JSONBExists
13611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13612#[cfg_attr(feature = "bindings", derive(TS))]
13613pub struct JSONBExists {
13614    pub this: Box<Expression>,
13615    #[serde(default)]
13616    pub path: Option<Box<Expression>>,
13617}
13618
13619/// JSONCast
13620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13621#[cfg_attr(feature = "bindings", derive(TS))]
13622pub struct JSONCast {
13623    pub this: Box<Expression>,
13624    pub to: DataType,
13625}
13626
13627/// JSONExtract
13628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13629#[cfg_attr(feature = "bindings", derive(TS))]
13630pub struct JSONExtract {
13631    pub this: Box<Expression>,
13632    pub expression: Box<Expression>,
13633    #[serde(default)]
13634    pub only_json_types: Option<Box<Expression>>,
13635    #[serde(default)]
13636    pub expressions: Vec<Expression>,
13637    #[serde(default)]
13638    pub variant_extract: Option<Box<Expression>>,
13639    #[serde(default)]
13640    pub json_query: Option<Box<Expression>>,
13641    #[serde(default)]
13642    pub option: Option<Box<Expression>>,
13643    #[serde(default)]
13644    pub quote: Option<Box<Expression>>,
13645    #[serde(default)]
13646    pub on_condition: Option<Box<Expression>>,
13647    #[serde(default)]
13648    pub requires_json: Option<Box<Expression>>,
13649}
13650
13651/// JSONExtractQuote
13652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13653#[cfg_attr(feature = "bindings", derive(TS))]
13654pub struct JSONExtractQuote {
13655    #[serde(default)]
13656    pub option: Option<Box<Expression>>,
13657    #[serde(default)]
13658    pub scalar: Option<Box<Expression>>,
13659}
13660
13661/// JSONExtractArray
13662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13663#[cfg_attr(feature = "bindings", derive(TS))]
13664pub struct JSONExtractArray {
13665    pub this: Box<Expression>,
13666    #[serde(default)]
13667    pub expression: Option<Box<Expression>>,
13668}
13669
13670/// JSONExtractScalar
13671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13672#[cfg_attr(feature = "bindings", derive(TS))]
13673pub struct JSONExtractScalar {
13674    pub this: Box<Expression>,
13675    pub expression: Box<Expression>,
13676    #[serde(default)]
13677    pub only_json_types: Option<Box<Expression>>,
13678    #[serde(default)]
13679    pub expressions: Vec<Expression>,
13680    #[serde(default)]
13681    pub json_type: Option<Box<Expression>>,
13682    #[serde(default)]
13683    pub scalar_only: Option<Box<Expression>>,
13684}
13685
13686/// JSONBExtractScalar
13687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13688#[cfg_attr(feature = "bindings", derive(TS))]
13689pub struct JSONBExtractScalar {
13690    pub this: Box<Expression>,
13691    pub expression: Box<Expression>,
13692    #[serde(default)]
13693    pub json_type: Option<Box<Expression>>,
13694}
13695
13696/// JSONFormat
13697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13698#[cfg_attr(feature = "bindings", derive(TS))]
13699pub struct JSONFormat {
13700    #[serde(default)]
13701    pub this: Option<Box<Expression>>,
13702    #[serde(default)]
13703    pub options: Vec<Expression>,
13704    #[serde(default)]
13705    pub is_json: Option<Box<Expression>>,
13706    #[serde(default)]
13707    pub to_json: Option<Box<Expression>>,
13708}
13709
13710/// JSONArrayAppend
13711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13712#[cfg_attr(feature = "bindings", derive(TS))]
13713pub struct JSONArrayAppend {
13714    pub this: Box<Expression>,
13715    #[serde(default)]
13716    pub expressions: Vec<Expression>,
13717}
13718
13719/// JSONArrayContains
13720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13721#[cfg_attr(feature = "bindings", derive(TS))]
13722pub struct JSONArrayContains {
13723    pub this: Box<Expression>,
13724    pub expression: Box<Expression>,
13725    #[serde(default)]
13726    pub json_type: Option<Box<Expression>>,
13727}
13728
13729/// JSONArrayInsert
13730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13731#[cfg_attr(feature = "bindings", derive(TS))]
13732pub struct JSONArrayInsert {
13733    pub this: Box<Expression>,
13734    #[serde(default)]
13735    pub expressions: Vec<Expression>,
13736}
13737
13738/// ParseJSON
13739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13740#[cfg_attr(feature = "bindings", derive(TS))]
13741pub struct ParseJSON {
13742    pub this: Box<Expression>,
13743    #[serde(default)]
13744    pub expression: Option<Box<Expression>>,
13745    #[serde(default)]
13746    pub safe: Option<Box<Expression>>,
13747}
13748
13749/// ParseUrl
13750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13751#[cfg_attr(feature = "bindings", derive(TS))]
13752pub struct ParseUrl {
13753    pub this: Box<Expression>,
13754    #[serde(default)]
13755    pub part_to_extract: Option<Box<Expression>>,
13756    #[serde(default)]
13757    pub key: Option<Box<Expression>>,
13758    #[serde(default)]
13759    pub permissive: Option<Box<Expression>>,
13760}
13761
13762/// ParseIp
13763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13764#[cfg_attr(feature = "bindings", derive(TS))]
13765pub struct ParseIp {
13766    pub this: Box<Expression>,
13767    #[serde(default)]
13768    pub type_: Option<Box<Expression>>,
13769    #[serde(default)]
13770    pub permissive: Option<Box<Expression>>,
13771}
13772
13773/// ParseTime
13774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13775#[cfg_attr(feature = "bindings", derive(TS))]
13776pub struct ParseTime {
13777    pub this: Box<Expression>,
13778    pub format: String,
13779}
13780
13781/// ParseDatetime
13782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13783#[cfg_attr(feature = "bindings", derive(TS))]
13784pub struct ParseDatetime {
13785    pub this: Box<Expression>,
13786    #[serde(default)]
13787    pub format: Option<String>,
13788    #[serde(default)]
13789    pub zone: Option<Box<Expression>>,
13790}
13791
13792/// Map
13793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13794#[cfg_attr(feature = "bindings", derive(TS))]
13795pub struct Map {
13796    #[serde(default)]
13797    pub keys: Vec<Expression>,
13798    #[serde(default)]
13799    pub values: Vec<Expression>,
13800}
13801
13802/// MapCat
13803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13804#[cfg_attr(feature = "bindings", derive(TS))]
13805pub struct MapCat {
13806    pub this: Box<Expression>,
13807    pub expression: Box<Expression>,
13808}
13809
13810/// MapDelete
13811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13812#[cfg_attr(feature = "bindings", derive(TS))]
13813pub struct MapDelete {
13814    pub this: Box<Expression>,
13815    #[serde(default)]
13816    pub expressions: Vec<Expression>,
13817}
13818
13819/// MapInsert
13820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13821#[cfg_attr(feature = "bindings", derive(TS))]
13822pub struct MapInsert {
13823    pub this: Box<Expression>,
13824    #[serde(default)]
13825    pub key: Option<Box<Expression>>,
13826    #[serde(default)]
13827    pub value: Option<Box<Expression>>,
13828    #[serde(default)]
13829    pub update_flag: Option<Box<Expression>>,
13830}
13831
13832/// MapPick
13833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13834#[cfg_attr(feature = "bindings", derive(TS))]
13835pub struct MapPick {
13836    pub this: Box<Expression>,
13837    #[serde(default)]
13838    pub expressions: Vec<Expression>,
13839}
13840
13841/// ScopeResolution
13842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13843#[cfg_attr(feature = "bindings", derive(TS))]
13844pub struct ScopeResolution {
13845    #[serde(default)]
13846    pub this: Option<Box<Expression>>,
13847    pub expression: Box<Expression>,
13848}
13849
13850/// Slice
13851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13852#[cfg_attr(feature = "bindings", derive(TS))]
13853pub struct Slice {
13854    #[serde(default)]
13855    pub this: Option<Box<Expression>>,
13856    #[serde(default)]
13857    pub expression: Option<Box<Expression>>,
13858    #[serde(default)]
13859    pub step: Option<Box<Expression>>,
13860}
13861
13862/// VarMap
13863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13864#[cfg_attr(feature = "bindings", derive(TS))]
13865pub struct VarMap {
13866    #[serde(default)]
13867    pub keys: Vec<Expression>,
13868    #[serde(default)]
13869    pub values: Vec<Expression>,
13870}
13871
13872/// MatchAgainst
13873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13874#[cfg_attr(feature = "bindings", derive(TS))]
13875pub struct MatchAgainst {
13876    pub this: Box<Expression>,
13877    #[serde(default)]
13878    pub expressions: Vec<Expression>,
13879    #[serde(default)]
13880    pub modifier: Option<Box<Expression>>,
13881}
13882
13883/// MD5Digest
13884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13885#[cfg_attr(feature = "bindings", derive(TS))]
13886pub struct MD5Digest {
13887    pub this: Box<Expression>,
13888    #[serde(default)]
13889    pub expressions: Vec<Expression>,
13890}
13891
13892/// Monthname
13893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13894#[cfg_attr(feature = "bindings", derive(TS))]
13895pub struct Monthname {
13896    pub this: Box<Expression>,
13897    #[serde(default)]
13898    pub abbreviated: Option<Box<Expression>>,
13899}
13900
13901/// Ntile
13902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13903#[cfg_attr(feature = "bindings", derive(TS))]
13904pub struct Ntile {
13905    #[serde(default)]
13906    pub this: Option<Box<Expression>>,
13907}
13908
13909/// Normalize
13910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13911#[cfg_attr(feature = "bindings", derive(TS))]
13912pub struct Normalize {
13913    pub this: Box<Expression>,
13914    #[serde(default)]
13915    pub form: Option<Box<Expression>>,
13916    #[serde(default)]
13917    pub is_casefold: Option<Box<Expression>>,
13918}
13919
13920/// Normal
13921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13922#[cfg_attr(feature = "bindings", derive(TS))]
13923pub struct Normal {
13924    pub this: Box<Expression>,
13925    #[serde(default)]
13926    pub stddev: Option<Box<Expression>>,
13927    #[serde(default)]
13928    pub gen: Option<Box<Expression>>,
13929}
13930
13931/// Predict
13932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13933#[cfg_attr(feature = "bindings", derive(TS))]
13934pub struct Predict {
13935    pub this: Box<Expression>,
13936    pub expression: Box<Expression>,
13937    #[serde(default)]
13938    pub params_struct: Option<Box<Expression>>,
13939}
13940
13941/// MLTranslate
13942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13943#[cfg_attr(feature = "bindings", derive(TS))]
13944pub struct MLTranslate {
13945    pub this: Box<Expression>,
13946    pub expression: Box<Expression>,
13947    #[serde(default)]
13948    pub params_struct: Option<Box<Expression>>,
13949}
13950
13951/// FeaturesAtTime
13952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13953#[cfg_attr(feature = "bindings", derive(TS))]
13954pub struct FeaturesAtTime {
13955    pub this: Box<Expression>,
13956    #[serde(default)]
13957    pub time: Option<Box<Expression>>,
13958    #[serde(default)]
13959    pub num_rows: Option<Box<Expression>>,
13960    #[serde(default)]
13961    pub ignore_feature_nulls: Option<Box<Expression>>,
13962}
13963
13964/// GenerateEmbedding
13965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13966#[cfg_attr(feature = "bindings", derive(TS))]
13967pub struct GenerateEmbedding {
13968    pub this: Box<Expression>,
13969    pub expression: Box<Expression>,
13970    #[serde(default)]
13971    pub params_struct: Option<Box<Expression>>,
13972    #[serde(default)]
13973    pub is_text: Option<Box<Expression>>,
13974}
13975
13976/// MLForecast
13977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13978#[cfg_attr(feature = "bindings", derive(TS))]
13979pub struct MLForecast {
13980    pub this: Box<Expression>,
13981    #[serde(default)]
13982    pub expression: Option<Box<Expression>>,
13983    #[serde(default)]
13984    pub params_struct: Option<Box<Expression>>,
13985}
13986
13987/// ModelAttribute
13988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13989#[cfg_attr(feature = "bindings", derive(TS))]
13990pub struct ModelAttribute {
13991    pub this: Box<Expression>,
13992    pub expression: Box<Expression>,
13993}
13994
13995/// VectorSearch
13996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13997#[cfg_attr(feature = "bindings", derive(TS))]
13998pub struct VectorSearch {
13999    pub this: Box<Expression>,
14000    #[serde(default)]
14001    pub column_to_search: Option<Box<Expression>>,
14002    #[serde(default)]
14003    pub query_table: Option<Box<Expression>>,
14004    #[serde(default)]
14005    pub query_column_to_search: Option<Box<Expression>>,
14006    #[serde(default)]
14007    pub top_k: Option<Box<Expression>>,
14008    #[serde(default)]
14009    pub distance_type: Option<Box<Expression>>,
14010    #[serde(default)]
14011    pub options: Vec<Expression>,
14012}
14013
14014/// Quantile
14015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14016#[cfg_attr(feature = "bindings", derive(TS))]
14017pub struct Quantile {
14018    pub this: Box<Expression>,
14019    #[serde(default)]
14020    pub quantile: Option<Box<Expression>>,
14021}
14022
14023/// ApproxQuantile
14024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14025#[cfg_attr(feature = "bindings", derive(TS))]
14026pub struct ApproxQuantile {
14027    pub this: Box<Expression>,
14028    #[serde(default)]
14029    pub quantile: Option<Box<Expression>>,
14030    #[serde(default)]
14031    pub accuracy: Option<Box<Expression>>,
14032    #[serde(default)]
14033    pub weight: Option<Box<Expression>>,
14034    #[serde(default)]
14035    pub error_tolerance: Option<Box<Expression>>,
14036}
14037
14038/// ApproxPercentileEstimate
14039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14040#[cfg_attr(feature = "bindings", derive(TS))]
14041pub struct ApproxPercentileEstimate {
14042    pub this: Box<Expression>,
14043    #[serde(default)]
14044    pub percentile: Option<Box<Expression>>,
14045}
14046
14047/// Randn
14048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14049#[cfg_attr(feature = "bindings", derive(TS))]
14050pub struct Randn {
14051    #[serde(default)]
14052    pub this: Option<Box<Expression>>,
14053}
14054
14055/// Randstr
14056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14057#[cfg_attr(feature = "bindings", derive(TS))]
14058pub struct Randstr {
14059    pub this: Box<Expression>,
14060    #[serde(default)]
14061    pub generator: Option<Box<Expression>>,
14062}
14063
14064/// RangeN
14065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14066#[cfg_attr(feature = "bindings", derive(TS))]
14067pub struct RangeN {
14068    pub this: Box<Expression>,
14069    #[serde(default)]
14070    pub expressions: Vec<Expression>,
14071    #[serde(default)]
14072    pub each: Option<Box<Expression>>,
14073}
14074
14075/// RangeBucket
14076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14077#[cfg_attr(feature = "bindings", derive(TS))]
14078pub struct RangeBucket {
14079    pub this: Box<Expression>,
14080    pub expression: Box<Expression>,
14081}
14082
14083/// ReadCSV
14084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14085#[cfg_attr(feature = "bindings", derive(TS))]
14086pub struct ReadCSV {
14087    pub this: Box<Expression>,
14088    #[serde(default)]
14089    pub expressions: Vec<Expression>,
14090}
14091
14092/// ReadParquet
14093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14094#[cfg_attr(feature = "bindings", derive(TS))]
14095pub struct ReadParquet {
14096    #[serde(default)]
14097    pub expressions: Vec<Expression>,
14098}
14099
14100/// Reduce
14101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14102#[cfg_attr(feature = "bindings", derive(TS))]
14103pub struct Reduce {
14104    pub this: Box<Expression>,
14105    #[serde(default)]
14106    pub initial: Option<Box<Expression>>,
14107    #[serde(default)]
14108    pub merge: Option<Box<Expression>>,
14109    #[serde(default)]
14110    pub finish: Option<Box<Expression>>,
14111}
14112
14113/// RegexpExtractAll
14114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14115#[cfg_attr(feature = "bindings", derive(TS))]
14116pub struct RegexpExtractAll {
14117    pub this: Box<Expression>,
14118    pub expression: Box<Expression>,
14119    #[serde(default)]
14120    pub group: Option<Box<Expression>>,
14121    #[serde(default)]
14122    pub parameters: Option<Box<Expression>>,
14123    #[serde(default)]
14124    pub position: Option<Box<Expression>>,
14125    #[serde(default)]
14126    pub occurrence: Option<Box<Expression>>,
14127}
14128
14129/// RegexpILike
14130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14131#[cfg_attr(feature = "bindings", derive(TS))]
14132pub struct RegexpILike {
14133    pub this: Box<Expression>,
14134    pub expression: Box<Expression>,
14135    #[serde(default)]
14136    pub flag: Option<Box<Expression>>,
14137}
14138
14139/// RegexpFullMatch
14140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14141#[cfg_attr(feature = "bindings", derive(TS))]
14142pub struct RegexpFullMatch {
14143    pub this: Box<Expression>,
14144    pub expression: Box<Expression>,
14145    #[serde(default)]
14146    pub options: Vec<Expression>,
14147}
14148
14149/// RegexpInstr
14150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14151#[cfg_attr(feature = "bindings", derive(TS))]
14152pub struct RegexpInstr {
14153    pub this: Box<Expression>,
14154    pub expression: Box<Expression>,
14155    #[serde(default)]
14156    pub position: Option<Box<Expression>>,
14157    #[serde(default)]
14158    pub occurrence: Option<Box<Expression>>,
14159    #[serde(default)]
14160    pub option: Option<Box<Expression>>,
14161    #[serde(default)]
14162    pub parameters: Option<Box<Expression>>,
14163    #[serde(default)]
14164    pub group: Option<Box<Expression>>,
14165}
14166
14167/// RegexpSplit
14168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14169#[cfg_attr(feature = "bindings", derive(TS))]
14170pub struct RegexpSplit {
14171    pub this: Box<Expression>,
14172    pub expression: Box<Expression>,
14173    #[serde(default)]
14174    pub limit: Option<Box<Expression>>,
14175}
14176
14177/// RegexpCount
14178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14179#[cfg_attr(feature = "bindings", derive(TS))]
14180pub struct RegexpCount {
14181    pub this: Box<Expression>,
14182    pub expression: Box<Expression>,
14183    #[serde(default)]
14184    pub position: Option<Box<Expression>>,
14185    #[serde(default)]
14186    pub parameters: Option<Box<Expression>>,
14187}
14188
14189/// RegrValx
14190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14191#[cfg_attr(feature = "bindings", derive(TS))]
14192pub struct RegrValx {
14193    pub this: Box<Expression>,
14194    pub expression: Box<Expression>,
14195}
14196
14197/// RegrValy
14198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14199#[cfg_attr(feature = "bindings", derive(TS))]
14200pub struct RegrValy {
14201    pub this: Box<Expression>,
14202    pub expression: Box<Expression>,
14203}
14204
14205/// RegrAvgy
14206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14207#[cfg_attr(feature = "bindings", derive(TS))]
14208pub struct RegrAvgy {
14209    pub this: Box<Expression>,
14210    pub expression: Box<Expression>,
14211}
14212
14213/// RegrAvgx
14214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14215#[cfg_attr(feature = "bindings", derive(TS))]
14216pub struct RegrAvgx {
14217    pub this: Box<Expression>,
14218    pub expression: Box<Expression>,
14219}
14220
14221/// RegrCount
14222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14223#[cfg_attr(feature = "bindings", derive(TS))]
14224pub struct RegrCount {
14225    pub this: Box<Expression>,
14226    pub expression: Box<Expression>,
14227}
14228
14229/// RegrIntercept
14230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14231#[cfg_attr(feature = "bindings", derive(TS))]
14232pub struct RegrIntercept {
14233    pub this: Box<Expression>,
14234    pub expression: Box<Expression>,
14235}
14236
14237/// RegrR2
14238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14239#[cfg_attr(feature = "bindings", derive(TS))]
14240pub struct RegrR2 {
14241    pub this: Box<Expression>,
14242    pub expression: Box<Expression>,
14243}
14244
14245/// RegrSxx
14246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14247#[cfg_attr(feature = "bindings", derive(TS))]
14248pub struct RegrSxx {
14249    pub this: Box<Expression>,
14250    pub expression: Box<Expression>,
14251}
14252
14253/// RegrSxy
14254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14255#[cfg_attr(feature = "bindings", derive(TS))]
14256pub struct RegrSxy {
14257    pub this: Box<Expression>,
14258    pub expression: Box<Expression>,
14259}
14260
14261/// RegrSyy
14262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14263#[cfg_attr(feature = "bindings", derive(TS))]
14264pub struct RegrSyy {
14265    pub this: Box<Expression>,
14266    pub expression: Box<Expression>,
14267}
14268
14269/// RegrSlope
14270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14271#[cfg_attr(feature = "bindings", derive(TS))]
14272pub struct RegrSlope {
14273    pub this: Box<Expression>,
14274    pub expression: Box<Expression>,
14275}
14276
14277/// SafeAdd
14278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14279#[cfg_attr(feature = "bindings", derive(TS))]
14280pub struct SafeAdd {
14281    pub this: Box<Expression>,
14282    pub expression: Box<Expression>,
14283}
14284
14285/// SafeDivide
14286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14287#[cfg_attr(feature = "bindings", derive(TS))]
14288pub struct SafeDivide {
14289    pub this: Box<Expression>,
14290    pub expression: Box<Expression>,
14291}
14292
14293/// SafeMultiply
14294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14295#[cfg_attr(feature = "bindings", derive(TS))]
14296pub struct SafeMultiply {
14297    pub this: Box<Expression>,
14298    pub expression: Box<Expression>,
14299}
14300
14301/// SafeSubtract
14302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14303#[cfg_attr(feature = "bindings", derive(TS))]
14304pub struct SafeSubtract {
14305    pub this: Box<Expression>,
14306    pub expression: Box<Expression>,
14307}
14308
14309/// SHA2
14310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14311#[cfg_attr(feature = "bindings", derive(TS))]
14312pub struct SHA2 {
14313    pub this: Box<Expression>,
14314    #[serde(default)]
14315    pub length: Option<i64>,
14316}
14317
14318/// SHA2Digest
14319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14320#[cfg_attr(feature = "bindings", derive(TS))]
14321pub struct SHA2Digest {
14322    pub this: Box<Expression>,
14323    #[serde(default)]
14324    pub length: Option<i64>,
14325}
14326
14327/// SortArray
14328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14329#[cfg_attr(feature = "bindings", derive(TS))]
14330pub struct SortArray {
14331    pub this: Box<Expression>,
14332    #[serde(default)]
14333    pub asc: Option<Box<Expression>>,
14334    #[serde(default)]
14335    pub nulls_first: Option<Box<Expression>>,
14336}
14337
14338/// SplitPart
14339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14340#[cfg_attr(feature = "bindings", derive(TS))]
14341pub struct SplitPart {
14342    pub this: Box<Expression>,
14343    #[serde(default)]
14344    pub delimiter: Option<Box<Expression>>,
14345    #[serde(default)]
14346    pub part_index: Option<Box<Expression>>,
14347}
14348
14349/// SUBSTRING_INDEX(str, delim, count)
14350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14351#[cfg_attr(feature = "bindings", derive(TS))]
14352pub struct SubstringIndex {
14353    pub this: Box<Expression>,
14354    #[serde(default)]
14355    pub delimiter: Option<Box<Expression>>,
14356    #[serde(default)]
14357    pub count: Option<Box<Expression>>,
14358}
14359
14360/// StandardHash
14361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14362#[cfg_attr(feature = "bindings", derive(TS))]
14363pub struct StandardHash {
14364    pub this: Box<Expression>,
14365    #[serde(default)]
14366    pub expression: Option<Box<Expression>>,
14367}
14368
14369/// StrPosition
14370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14371#[cfg_attr(feature = "bindings", derive(TS))]
14372pub struct StrPosition {
14373    pub this: Box<Expression>,
14374    #[serde(default)]
14375    pub substr: Option<Box<Expression>>,
14376    #[serde(default)]
14377    pub position: Option<Box<Expression>>,
14378    #[serde(default)]
14379    pub occurrence: Option<Box<Expression>>,
14380}
14381
14382/// Search
14383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14384#[cfg_attr(feature = "bindings", derive(TS))]
14385pub struct Search {
14386    pub this: Box<Expression>,
14387    pub expression: Box<Expression>,
14388    #[serde(default)]
14389    pub json_scope: Option<Box<Expression>>,
14390    #[serde(default)]
14391    pub analyzer: Option<Box<Expression>>,
14392    #[serde(default)]
14393    pub analyzer_options: Option<Box<Expression>>,
14394    #[serde(default)]
14395    pub search_mode: Option<Box<Expression>>,
14396}
14397
14398/// SearchIp
14399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14400#[cfg_attr(feature = "bindings", derive(TS))]
14401pub struct SearchIp {
14402    pub this: Box<Expression>,
14403    pub expression: Box<Expression>,
14404}
14405
14406/// StrToDate
14407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14408#[cfg_attr(feature = "bindings", derive(TS))]
14409pub struct StrToDate {
14410    pub this: Box<Expression>,
14411    #[serde(default)]
14412    pub format: Option<String>,
14413    #[serde(default)]
14414    pub safe: Option<Box<Expression>>,
14415}
14416
14417/// StrToTime
14418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14419#[cfg_attr(feature = "bindings", derive(TS))]
14420pub struct StrToTime {
14421    pub this: Box<Expression>,
14422    pub format: String,
14423    #[serde(default)]
14424    pub zone: Option<Box<Expression>>,
14425    #[serde(default)]
14426    pub safe: Option<Box<Expression>>,
14427    #[serde(default)]
14428    pub target_type: Option<Box<Expression>>,
14429}
14430
14431/// StrToUnix
14432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14433#[cfg_attr(feature = "bindings", derive(TS))]
14434pub struct StrToUnix {
14435    #[serde(default)]
14436    pub this: Option<Box<Expression>>,
14437    #[serde(default)]
14438    pub format: Option<String>,
14439}
14440
14441/// StrToMap
14442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14443#[cfg_attr(feature = "bindings", derive(TS))]
14444pub struct StrToMap {
14445    pub this: Box<Expression>,
14446    #[serde(default)]
14447    pub pair_delim: Option<Box<Expression>>,
14448    #[serde(default)]
14449    pub key_value_delim: Option<Box<Expression>>,
14450    #[serde(default)]
14451    pub duplicate_resolution_callback: Option<Box<Expression>>,
14452}
14453
14454/// NumberToStr
14455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14456#[cfg_attr(feature = "bindings", derive(TS))]
14457pub struct NumberToStr {
14458    pub this: Box<Expression>,
14459    pub format: String,
14460    #[serde(default)]
14461    pub culture: Option<Box<Expression>>,
14462}
14463
14464/// FromBase
14465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14466#[cfg_attr(feature = "bindings", derive(TS))]
14467pub struct FromBase {
14468    pub this: Box<Expression>,
14469    pub expression: Box<Expression>,
14470}
14471
14472/// Stuff
14473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14474#[cfg_attr(feature = "bindings", derive(TS))]
14475pub struct Stuff {
14476    pub this: Box<Expression>,
14477    #[serde(default)]
14478    pub start: Option<Box<Expression>>,
14479    #[serde(default)]
14480    pub length: Option<i64>,
14481    pub expression: Box<Expression>,
14482}
14483
14484/// TimeToStr
14485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14486#[cfg_attr(feature = "bindings", derive(TS))]
14487pub struct TimeToStr {
14488    pub this: Box<Expression>,
14489    pub format: String,
14490    #[serde(default)]
14491    pub culture: Option<Box<Expression>>,
14492    #[serde(default)]
14493    pub zone: Option<Box<Expression>>,
14494}
14495
14496/// TimeStrToTime
14497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14498#[cfg_attr(feature = "bindings", derive(TS))]
14499pub struct TimeStrToTime {
14500    pub this: Box<Expression>,
14501    #[serde(default)]
14502    pub zone: Option<Box<Expression>>,
14503}
14504
14505/// TsOrDsAdd
14506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14507#[cfg_attr(feature = "bindings", derive(TS))]
14508pub struct TsOrDsAdd {
14509    pub this: Box<Expression>,
14510    pub expression: Box<Expression>,
14511    #[serde(default)]
14512    pub unit: Option<String>,
14513    #[serde(default)]
14514    pub return_type: Option<Box<Expression>>,
14515}
14516
14517/// TsOrDsDiff
14518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14519#[cfg_attr(feature = "bindings", derive(TS))]
14520pub struct TsOrDsDiff {
14521    pub this: Box<Expression>,
14522    pub expression: Box<Expression>,
14523    #[serde(default)]
14524    pub unit: Option<String>,
14525}
14526
14527/// TsOrDsToDate
14528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14529#[cfg_attr(feature = "bindings", derive(TS))]
14530pub struct TsOrDsToDate {
14531    pub this: Box<Expression>,
14532    #[serde(default)]
14533    pub format: Option<String>,
14534    #[serde(default)]
14535    pub safe: Option<Box<Expression>>,
14536}
14537
14538/// TsOrDsToTime
14539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14540#[cfg_attr(feature = "bindings", derive(TS))]
14541pub struct TsOrDsToTime {
14542    pub this: Box<Expression>,
14543    #[serde(default)]
14544    pub format: Option<String>,
14545    #[serde(default)]
14546    pub safe: Option<Box<Expression>>,
14547}
14548
14549/// Unhex
14550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14551#[cfg_attr(feature = "bindings", derive(TS))]
14552pub struct Unhex {
14553    pub this: Box<Expression>,
14554    #[serde(default)]
14555    pub expression: Option<Box<Expression>>,
14556}
14557
14558/// Uniform
14559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14560#[cfg_attr(feature = "bindings", derive(TS))]
14561pub struct Uniform {
14562    pub this: Box<Expression>,
14563    pub expression: Box<Expression>,
14564    #[serde(default)]
14565    pub gen: Option<Box<Expression>>,
14566    #[serde(default)]
14567    pub seed: Option<Box<Expression>>,
14568}
14569
14570/// UnixToStr
14571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14572#[cfg_attr(feature = "bindings", derive(TS))]
14573pub struct UnixToStr {
14574    pub this: Box<Expression>,
14575    #[serde(default)]
14576    pub format: Option<String>,
14577}
14578
14579/// UnixToTime
14580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14581#[cfg_attr(feature = "bindings", derive(TS))]
14582pub struct UnixToTime {
14583    pub this: Box<Expression>,
14584    #[serde(default)]
14585    pub scale: Option<i64>,
14586    #[serde(default)]
14587    pub zone: Option<Box<Expression>>,
14588    #[serde(default)]
14589    pub hours: Option<Box<Expression>>,
14590    #[serde(default)]
14591    pub minutes: Option<Box<Expression>>,
14592    #[serde(default)]
14593    pub format: Option<String>,
14594    #[serde(default)]
14595    pub target_type: Option<Box<Expression>>,
14596}
14597
14598/// Uuid
14599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14600#[cfg_attr(feature = "bindings", derive(TS))]
14601pub struct Uuid {
14602    #[serde(default)]
14603    pub this: Option<Box<Expression>>,
14604    #[serde(default)]
14605    pub name: Option<String>,
14606    #[serde(default)]
14607    pub is_string: Option<Box<Expression>>,
14608}
14609
14610/// TimestampFromParts
14611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14612#[cfg_attr(feature = "bindings", derive(TS))]
14613pub struct TimestampFromParts {
14614    #[serde(default)]
14615    pub zone: Option<Box<Expression>>,
14616    #[serde(default)]
14617    pub milli: Option<Box<Expression>>,
14618    #[serde(default)]
14619    pub this: Option<Box<Expression>>,
14620    #[serde(default)]
14621    pub expression: Option<Box<Expression>>,
14622}
14623
14624/// TimestampTzFromParts
14625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14626#[cfg_attr(feature = "bindings", derive(TS))]
14627pub struct TimestampTzFromParts {
14628    #[serde(default)]
14629    pub zone: Option<Box<Expression>>,
14630}
14631
14632/// Corr
14633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14634#[cfg_attr(feature = "bindings", derive(TS))]
14635pub struct Corr {
14636    pub this: Box<Expression>,
14637    pub expression: Box<Expression>,
14638    #[serde(default)]
14639    pub null_on_zero_variance: Option<Box<Expression>>,
14640}
14641
14642/// WidthBucket
14643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14644#[cfg_attr(feature = "bindings", derive(TS))]
14645pub struct WidthBucket {
14646    pub this: Box<Expression>,
14647    #[serde(default)]
14648    pub min_value: Option<Box<Expression>>,
14649    #[serde(default)]
14650    pub max_value: Option<Box<Expression>>,
14651    #[serde(default)]
14652    pub num_buckets: Option<Box<Expression>>,
14653    #[serde(default)]
14654    pub threshold: Option<Box<Expression>>,
14655}
14656
14657/// CovarSamp
14658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14659#[cfg_attr(feature = "bindings", derive(TS))]
14660pub struct CovarSamp {
14661    pub this: Box<Expression>,
14662    pub expression: Box<Expression>,
14663}
14664
14665/// CovarPop
14666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14667#[cfg_attr(feature = "bindings", derive(TS))]
14668pub struct CovarPop {
14669    pub this: Box<Expression>,
14670    pub expression: Box<Expression>,
14671}
14672
14673/// Week
14674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14675#[cfg_attr(feature = "bindings", derive(TS))]
14676pub struct Week {
14677    pub this: Box<Expression>,
14678    #[serde(default)]
14679    pub mode: Option<Box<Expression>>,
14680}
14681
14682/// XMLElement
14683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14684#[cfg_attr(feature = "bindings", derive(TS))]
14685pub struct XMLElement {
14686    pub this: Box<Expression>,
14687    #[serde(default)]
14688    pub expressions: Vec<Expression>,
14689    #[serde(default)]
14690    pub evalname: Option<Box<Expression>>,
14691}
14692
14693/// XMLGet
14694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14695#[cfg_attr(feature = "bindings", derive(TS))]
14696pub struct XMLGet {
14697    pub this: Box<Expression>,
14698    pub expression: Box<Expression>,
14699    #[serde(default)]
14700    pub instance: Option<Box<Expression>>,
14701}
14702
14703/// XMLTable
14704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14705#[cfg_attr(feature = "bindings", derive(TS))]
14706pub struct XMLTable {
14707    pub this: Box<Expression>,
14708    #[serde(default)]
14709    pub namespaces: Option<Box<Expression>>,
14710    #[serde(default)]
14711    pub passing: Option<Box<Expression>>,
14712    #[serde(default)]
14713    pub columns: Vec<Expression>,
14714    #[serde(default)]
14715    pub by_ref: Option<Box<Expression>>,
14716}
14717
14718/// XMLKeyValueOption
14719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14720#[cfg_attr(feature = "bindings", derive(TS))]
14721pub struct XMLKeyValueOption {
14722    pub this: Box<Expression>,
14723    #[serde(default)]
14724    pub expression: Option<Box<Expression>>,
14725}
14726
14727/// Zipf
14728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14729#[cfg_attr(feature = "bindings", derive(TS))]
14730pub struct Zipf {
14731    pub this: Box<Expression>,
14732    #[serde(default)]
14733    pub elementcount: Option<Box<Expression>>,
14734    #[serde(default)]
14735    pub gen: Option<Box<Expression>>,
14736}
14737
14738/// Merge
14739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14740#[cfg_attr(feature = "bindings", derive(TS))]
14741pub struct Merge {
14742    pub this: Box<Expression>,
14743    pub using: Box<Expression>,
14744    #[serde(default)]
14745    pub on: Option<Box<Expression>>,
14746    #[serde(default)]
14747    pub using_cond: Option<Box<Expression>>,
14748    #[serde(default)]
14749    pub whens: Option<Box<Expression>>,
14750    #[serde(default)]
14751    pub with_: Option<Box<Expression>>,
14752    #[serde(default)]
14753    pub returning: Option<Box<Expression>>,
14754}
14755
14756/// When
14757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14758#[cfg_attr(feature = "bindings", derive(TS))]
14759pub struct When {
14760    #[serde(default)]
14761    pub matched: Option<Box<Expression>>,
14762    #[serde(default)]
14763    pub source: Option<Box<Expression>>,
14764    #[serde(default)]
14765    pub condition: Option<Box<Expression>>,
14766    pub then: Box<Expression>,
14767}
14768
14769/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14771#[cfg_attr(feature = "bindings", derive(TS))]
14772pub struct Whens {
14773    #[serde(default)]
14774    pub expressions: Vec<Expression>,
14775}
14776
14777/// NextValueFor
14778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14779#[cfg_attr(feature = "bindings", derive(TS))]
14780pub struct NextValueFor {
14781    pub this: Box<Expression>,
14782    #[serde(default)]
14783    pub order: Option<Box<Expression>>,
14784}
14785
14786#[cfg(test)]
14787mod tests {
14788    use super::*;
14789
14790    #[test]
14791    #[cfg(feature = "bindings")]
14792    fn export_typescript_types() {
14793        // This test exports TypeScript types to the generated directory
14794        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14795        Expression::export_all(&ts_rs::Config::default())
14796            .expect("Failed to export Expression types");
14797    }
14798
14799    #[test]
14800    fn test_simple_select_builder() {
14801        let select = Select::new()
14802            .column(Expression::star())
14803            .from(Expression::Table(Box::new(TableRef::new("users"))));
14804
14805        assert_eq!(select.expressions.len(), 1);
14806        assert!(select.from.is_some());
14807    }
14808
14809    #[test]
14810    fn test_expression_alias() {
14811        let expr = Expression::column("id").alias("user_id");
14812
14813        match expr {
14814            Expression::Alias(a) => {
14815                assert_eq!(a.alias.name, "user_id");
14816            }
14817            _ => panic!("Expected Alias"),
14818        }
14819    }
14820
14821    #[test]
14822    fn test_literal_creation() {
14823        let num = Expression::number(42);
14824        let str = Expression::string("hello");
14825
14826        match num {
14827            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
14828                let Literal::Number(n) = lit.as_ref() else {
14829                    unreachable!()
14830                };
14831                assert_eq!(n, "42")
14832            }
14833            _ => panic!("Expected Number"),
14834        }
14835
14836        match str {
14837            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
14838                let Literal::String(s) = lit.as_ref() else {
14839                    unreachable!()
14840                };
14841                assert_eq!(s, "hello")
14842            }
14843            _ => panic!("Expected String"),
14844        }
14845    }
14846
14847    #[test]
14848    fn test_expression_sql() {
14849        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14850        assert_eq!(expr.sql(), "SELECT 1 + 2");
14851    }
14852
14853    #[test]
14854    fn test_expression_sql_for() {
14855        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14856        let sql = expr.sql_for(crate::DialectType::Generic);
14857        // Generic mode normalizes IF() to CASE WHEN
14858        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14859    }
14860}