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/// Iteratively flatten the left-recursive chain to prevent stack overflow
3819/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3820impl Drop for Union {
3821    fn drop(&mut self) {
3822        loop {
3823            if let Expression::Union(ref mut inner) = self.left {
3824                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3825                let old_left = std::mem::replace(&mut self.left, next_left);
3826                drop(old_left);
3827            } else {
3828                break;
3829            }
3830        }
3831    }
3832}
3833
3834/// Represent an INTERSECT set operation between two query expressions.
3835///
3836/// Returns only rows that appear in both operands. When `all` is true,
3837/// duplicates are preserved according to their multiplicity.
3838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3839#[cfg_attr(feature = "bindings", derive(TS))]
3840pub struct Intersect {
3841    /// The left-hand query operand.
3842    pub left: Expression,
3843    /// The right-hand query operand.
3844    pub right: Expression,
3845    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3846    pub all: bool,
3847    /// Whether DISTINCT was explicitly specified
3848    #[serde(default)]
3849    pub distinct: bool,
3850    /// Optional WITH clause
3851    pub with: Option<With>,
3852    /// ORDER BY applied to entire INTERSECT result
3853    pub order_by: Option<OrderBy>,
3854    /// LIMIT applied to entire INTERSECT result
3855    pub limit: Option<Box<Expression>>,
3856    /// OFFSET applied to entire INTERSECT result
3857    pub offset: Option<Box<Expression>>,
3858    /// DISTRIBUTE BY clause (Hive/Spark)
3859    #[serde(default, skip_serializing_if = "Option::is_none")]
3860    pub distribute_by: Option<DistributeBy>,
3861    /// SORT BY clause (Hive/Spark)
3862    #[serde(default, skip_serializing_if = "Option::is_none")]
3863    pub sort_by: Option<SortBy>,
3864    /// CLUSTER BY clause (Hive/Spark)
3865    #[serde(default, skip_serializing_if = "Option::is_none")]
3866    pub cluster_by: Option<ClusterBy>,
3867    /// DuckDB BY NAME modifier
3868    #[serde(default)]
3869    pub by_name: bool,
3870    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3871    #[serde(default, skip_serializing_if = "Option::is_none")]
3872    pub side: Option<String>,
3873    /// BigQuery: Set operation kind (INNER)
3874    #[serde(default, skip_serializing_if = "Option::is_none")]
3875    pub kind: Option<String>,
3876    /// BigQuery: CORRESPONDING modifier
3877    #[serde(default)]
3878    pub corresponding: bool,
3879    /// BigQuery: STRICT modifier (before CORRESPONDING)
3880    #[serde(default)]
3881    pub strict: bool,
3882    /// BigQuery: BY (columns) after CORRESPONDING
3883    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3884    pub on_columns: Vec<Expression>,
3885}
3886
3887impl Drop for Intersect {
3888    fn drop(&mut self) {
3889        loop {
3890            if let Expression::Intersect(ref mut inner) = self.left {
3891                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3892                let old_left = std::mem::replace(&mut self.left, next_left);
3893                drop(old_left);
3894            } else {
3895                break;
3896            }
3897        }
3898    }
3899}
3900
3901/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3902///
3903/// Returns rows from the left operand that do not appear in the right operand.
3904/// When `all` is true, duplicates are subtracted according to their multiplicity.
3905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3906#[cfg_attr(feature = "bindings", derive(TS))]
3907pub struct Except {
3908    /// The left-hand query operand.
3909    pub left: Expression,
3910    /// The right-hand query operand (rows to subtract).
3911    pub right: Expression,
3912    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3913    pub all: bool,
3914    /// Whether DISTINCT was explicitly specified
3915    #[serde(default)]
3916    pub distinct: bool,
3917    /// Optional WITH clause
3918    pub with: Option<With>,
3919    /// ORDER BY applied to entire EXCEPT result
3920    pub order_by: Option<OrderBy>,
3921    /// LIMIT applied to entire EXCEPT result
3922    pub limit: Option<Box<Expression>>,
3923    /// OFFSET applied to entire EXCEPT result
3924    pub offset: Option<Box<Expression>>,
3925    /// DISTRIBUTE BY clause (Hive/Spark)
3926    #[serde(default, skip_serializing_if = "Option::is_none")]
3927    pub distribute_by: Option<DistributeBy>,
3928    /// SORT BY clause (Hive/Spark)
3929    #[serde(default, skip_serializing_if = "Option::is_none")]
3930    pub sort_by: Option<SortBy>,
3931    /// CLUSTER BY clause (Hive/Spark)
3932    #[serde(default, skip_serializing_if = "Option::is_none")]
3933    pub cluster_by: Option<ClusterBy>,
3934    /// DuckDB BY NAME modifier
3935    #[serde(default)]
3936    pub by_name: bool,
3937    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3938    #[serde(default, skip_serializing_if = "Option::is_none")]
3939    pub side: Option<String>,
3940    /// BigQuery: Set operation kind (INNER)
3941    #[serde(default, skip_serializing_if = "Option::is_none")]
3942    pub kind: Option<String>,
3943    /// BigQuery: CORRESPONDING modifier
3944    #[serde(default)]
3945    pub corresponding: bool,
3946    /// BigQuery: STRICT modifier (before CORRESPONDING)
3947    #[serde(default)]
3948    pub strict: bool,
3949    /// BigQuery: BY (columns) after CORRESPONDING
3950    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3951    pub on_columns: Vec<Expression>,
3952}
3953
3954impl Drop for Except {
3955    fn drop(&mut self) {
3956        loop {
3957            if let Expression::Except(ref mut inner) = self.left {
3958                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3959                let old_left = std::mem::replace(&mut self.left, next_left);
3960                drop(old_left);
3961            } else {
3962                break;
3963            }
3964        }
3965    }
3966}
3967
3968/// INTO clause for SELECT INTO statements
3969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3970#[cfg_attr(feature = "bindings", derive(TS))]
3971pub struct SelectInto {
3972    /// Target table or variable (used when single target)
3973    pub this: Expression,
3974    /// Whether TEMPORARY keyword was used
3975    #[serde(default)]
3976    pub temporary: bool,
3977    /// Whether UNLOGGED keyword was used (PostgreSQL)
3978    #[serde(default)]
3979    pub unlogged: bool,
3980    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3981    #[serde(default)]
3982    pub bulk_collect: bool,
3983    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3984    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3985    pub expressions: Vec<Expression>,
3986}
3987
3988/// Represent a parenthesized subquery expression.
3989///
3990/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3991/// parentheses and optionally applies an alias, column aliases, ORDER BY,
3992/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
3993/// modifiers are rendered inside or outside the parentheses.
3994///
3995/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
3996/// scalar subqueries in select-lists, and derived tables.
3997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3998#[cfg_attr(feature = "bindings", derive(TS))]
3999pub struct Subquery {
4000    /// The inner query expression.
4001    pub this: Expression,
4002    /// Optional alias for the derived table.
4003    pub alias: Option<Identifier>,
4004    /// Optional column aliases: AS t(c1, c2)
4005    pub column_aliases: Vec<Identifier>,
4006    /// ORDER BY clause (for parenthesized queries)
4007    pub order_by: Option<OrderBy>,
4008    /// LIMIT clause
4009    pub limit: Option<Limit>,
4010    /// OFFSET clause
4011    pub offset: Option<Offset>,
4012    /// DISTRIBUTE BY clause (Hive/Spark)
4013    #[serde(default, skip_serializing_if = "Option::is_none")]
4014    pub distribute_by: Option<DistributeBy>,
4015    /// SORT BY clause (Hive/Spark)
4016    #[serde(default, skip_serializing_if = "Option::is_none")]
4017    pub sort_by: Option<SortBy>,
4018    /// CLUSTER BY clause (Hive/Spark)
4019    #[serde(default, skip_serializing_if = "Option::is_none")]
4020    pub cluster_by: Option<ClusterBy>,
4021    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4022    #[serde(default)]
4023    pub lateral: bool,
4024    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4025    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4026    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4027    #[serde(default)]
4028    pub modifiers_inside: bool,
4029    /// Trailing comments after the closing paren
4030    #[serde(default)]
4031    pub trailing_comments: Vec<String>,
4032    /// Inferred data type from type annotation
4033    #[serde(default, skip_serializing_if = "Option::is_none")]
4034    pub inferred_type: Option<DataType>,
4035}
4036
4037/// Pipe operator expression: query |> transform
4038///
4039/// Used in DataFusion and BigQuery pipe syntax:
4040///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4042#[cfg_attr(feature = "bindings", derive(TS))]
4043pub struct PipeOperator {
4044    /// The input query/expression (left side of |>)
4045    pub this: Expression,
4046    /// The piped operation (right side of |>)
4047    pub expression: Expression,
4048}
4049
4050/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4052#[cfg_attr(feature = "bindings", derive(TS))]
4053pub struct Values {
4054    /// The rows of values
4055    pub expressions: Vec<Tuple>,
4056    /// Optional alias for the table
4057    pub alias: Option<Identifier>,
4058    /// Optional column aliases: AS t(c1, c2)
4059    pub column_aliases: Vec<Identifier>,
4060}
4061
4062/// PIVOT operation - supports both standard and DuckDB simplified syntax
4063///
4064/// Standard syntax (in FROM clause):
4065///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4066///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4067///
4068/// DuckDB simplified syntax (statement-level):
4069///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4070///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4072#[cfg_attr(feature = "bindings", derive(TS))]
4073pub struct Pivot {
4074    /// Source table/expression
4075    pub this: Expression,
4076    /// For standard PIVOT: the aggregation function(s) (first is primary)
4077    /// For DuckDB simplified: unused (use `using` instead)
4078    #[serde(default)]
4079    pub expressions: Vec<Expression>,
4080    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4081    #[serde(default)]
4082    pub fields: Vec<Expression>,
4083    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4084    #[serde(default)]
4085    pub using: Vec<Expression>,
4086    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4087    #[serde(default)]
4088    pub group: Option<Box<Expression>>,
4089    /// Whether this is an UNPIVOT (vs PIVOT)
4090    #[serde(default)]
4091    pub unpivot: bool,
4092    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4093    #[serde(default)]
4094    pub into: Option<Box<Expression>>,
4095    /// Optional alias
4096    #[serde(default)]
4097    pub alias: Option<Identifier>,
4098    /// Include/exclude nulls (for UNPIVOT)
4099    #[serde(default)]
4100    pub include_nulls: Option<bool>,
4101    /// Default on null value (Snowflake)
4102    #[serde(default)]
4103    pub default_on_null: Option<Box<Expression>>,
4104    /// WITH clause (CTEs)
4105    #[serde(default, skip_serializing_if = "Option::is_none")]
4106    pub with: Option<With>,
4107}
4108
4109/// UNPIVOT operation
4110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4111#[cfg_attr(feature = "bindings", derive(TS))]
4112pub struct Unpivot {
4113    pub this: Expression,
4114    pub value_column: Identifier,
4115    pub name_column: Identifier,
4116    pub columns: Vec<Expression>,
4117    pub alias: Option<Identifier>,
4118    /// Whether the value_column was parenthesized in the original SQL
4119    #[serde(default)]
4120    pub value_column_parenthesized: bool,
4121    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4122    #[serde(default)]
4123    pub include_nulls: Option<bool>,
4124    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4125    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4126    pub extra_value_columns: Vec<Identifier>,
4127}
4128
4129/// PIVOT alias for aliasing pivot expressions
4130/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4132#[cfg_attr(feature = "bindings", derive(TS))]
4133pub struct PivotAlias {
4134    pub this: Expression,
4135    pub alias: Expression,
4136}
4137
4138/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4140#[cfg_attr(feature = "bindings", derive(TS))]
4141pub struct PreWhere {
4142    pub this: Expression,
4143}
4144
4145/// STREAM definition (Snowflake) - for change data capture
4146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4147#[cfg_attr(feature = "bindings", derive(TS))]
4148pub struct Stream {
4149    pub this: Expression,
4150    #[serde(skip_serializing_if = "Option::is_none")]
4151    pub on: Option<Expression>,
4152    #[serde(skip_serializing_if = "Option::is_none")]
4153    pub show_initial_rows: Option<bool>,
4154}
4155
4156/// USING DATA clause for data import statements
4157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4158#[cfg_attr(feature = "bindings", derive(TS))]
4159pub struct UsingData {
4160    pub this: Expression,
4161}
4162
4163/// XML Namespace declaration
4164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4165#[cfg_attr(feature = "bindings", derive(TS))]
4166pub struct XmlNamespace {
4167    pub this: Expression,
4168    #[serde(skip_serializing_if = "Option::is_none")]
4169    pub alias: Option<Identifier>,
4170}
4171
4172/// ROW FORMAT clause for Hive/Spark
4173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4174#[cfg_attr(feature = "bindings", derive(TS))]
4175pub struct RowFormat {
4176    pub delimited: bool,
4177    pub fields_terminated_by: Option<String>,
4178    pub collection_items_terminated_by: Option<String>,
4179    pub map_keys_terminated_by: Option<String>,
4180    pub lines_terminated_by: Option<String>,
4181    pub null_defined_as: Option<String>,
4182}
4183
4184/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4186#[cfg_attr(feature = "bindings", derive(TS))]
4187pub struct DirectoryInsert {
4188    pub local: bool,
4189    pub path: String,
4190    pub row_format: Option<RowFormat>,
4191    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4192    #[serde(default)]
4193    pub stored_as: Option<String>,
4194}
4195
4196/// INSERT statement
4197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4198#[cfg_attr(feature = "bindings", derive(TS))]
4199pub struct Insert {
4200    pub table: TableRef,
4201    pub columns: Vec<Identifier>,
4202    pub values: Vec<Vec<Expression>>,
4203    pub query: Option<Expression>,
4204    /// INSERT OVERWRITE for Hive/Spark
4205    pub overwrite: bool,
4206    /// PARTITION clause for Hive/Spark
4207    pub partition: Vec<(Identifier, Option<Expression>)>,
4208    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4209    #[serde(default)]
4210    pub directory: Option<DirectoryInsert>,
4211    /// RETURNING clause (PostgreSQL, SQLite)
4212    #[serde(default)]
4213    pub returning: Vec<Expression>,
4214    /// OUTPUT clause (TSQL)
4215    #[serde(default)]
4216    pub output: Option<OutputClause>,
4217    /// ON CONFLICT clause (PostgreSQL, SQLite)
4218    #[serde(default)]
4219    pub on_conflict: Option<Box<Expression>>,
4220    /// Leading comments before the statement
4221    #[serde(default)]
4222    pub leading_comments: Vec<String>,
4223    /// IF EXISTS clause (Hive)
4224    #[serde(default)]
4225    pub if_exists: bool,
4226    /// WITH clause (CTEs)
4227    #[serde(default)]
4228    pub with: Option<With>,
4229    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4230    #[serde(default)]
4231    pub ignore: bool,
4232    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4233    #[serde(default)]
4234    pub source_alias: Option<Identifier>,
4235    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4236    #[serde(default)]
4237    pub alias: Option<Identifier>,
4238    /// Whether the alias uses explicit AS keyword
4239    #[serde(default)]
4240    pub alias_explicit_as: bool,
4241    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4242    #[serde(default)]
4243    pub default_values: bool,
4244    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4245    #[serde(default)]
4246    pub by_name: bool,
4247    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4248    #[serde(default, skip_serializing_if = "Option::is_none")]
4249    pub conflict_action: Option<String>,
4250    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4251    #[serde(default)]
4252    pub is_replace: bool,
4253    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4254    #[serde(default, skip_serializing_if = "Option::is_none")]
4255    pub hint: Option<Hint>,
4256    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4257    #[serde(default)]
4258    pub replace_where: Option<Box<Expression>>,
4259    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4260    #[serde(default)]
4261    pub source: Option<Box<Expression>>,
4262    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4263    #[serde(default, skip_serializing_if = "Option::is_none")]
4264    pub function_target: Option<Box<Expression>>,
4265    /// ClickHouse: PARTITION BY expr
4266    #[serde(default, skip_serializing_if = "Option::is_none")]
4267    pub partition_by: Option<Box<Expression>>,
4268    /// ClickHouse: SETTINGS key = val, ...
4269    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4270    pub settings: Vec<Expression>,
4271}
4272
4273/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4275#[cfg_attr(feature = "bindings", derive(TS))]
4276pub struct OutputClause {
4277    /// Columns/expressions to output
4278    pub columns: Vec<Expression>,
4279    /// Optional INTO target table or table variable
4280    #[serde(default)]
4281    pub into_table: Option<Expression>,
4282}
4283
4284/// UPDATE statement
4285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4286#[cfg_attr(feature = "bindings", derive(TS))]
4287pub struct Update {
4288    pub table: TableRef,
4289    /// Additional tables for multi-table UPDATE (MySQL syntax)
4290    #[serde(default)]
4291    pub extra_tables: Vec<TableRef>,
4292    /// JOINs attached to the table list (MySQL multi-table syntax)
4293    #[serde(default)]
4294    pub table_joins: Vec<Join>,
4295    pub set: Vec<(Identifier, Expression)>,
4296    pub from_clause: Option<From>,
4297    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4298    #[serde(default)]
4299    pub from_joins: Vec<Join>,
4300    pub where_clause: Option<Where>,
4301    /// RETURNING clause (PostgreSQL, SQLite)
4302    #[serde(default)]
4303    pub returning: Vec<Expression>,
4304    /// OUTPUT clause (TSQL)
4305    #[serde(default)]
4306    pub output: Option<OutputClause>,
4307    /// WITH clause (CTEs)
4308    #[serde(default)]
4309    pub with: Option<With>,
4310    /// Leading comments before the statement
4311    #[serde(default)]
4312    pub leading_comments: Vec<String>,
4313    /// LIMIT clause (MySQL)
4314    #[serde(default)]
4315    pub limit: Option<Expression>,
4316    /// ORDER BY clause (MySQL)
4317    #[serde(default)]
4318    pub order_by: Option<OrderBy>,
4319    /// Whether FROM clause appears before SET (Snowflake syntax)
4320    #[serde(default)]
4321    pub from_before_set: bool,
4322}
4323
4324/// DELETE statement
4325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4326#[cfg_attr(feature = "bindings", derive(TS))]
4327pub struct Delete {
4328    pub table: TableRef,
4329    /// ClickHouse: ON CLUSTER clause for distributed DDL
4330    #[serde(default, skip_serializing_if = "Option::is_none")]
4331    pub on_cluster: Option<OnCluster>,
4332    /// Optional alias for the table
4333    pub alias: Option<Identifier>,
4334    /// Whether the alias was declared with explicit AS keyword
4335    #[serde(default)]
4336    pub alias_explicit_as: bool,
4337    /// PostgreSQL/DuckDB USING clause - additional tables to join
4338    pub using: Vec<TableRef>,
4339    pub where_clause: Option<Where>,
4340    /// OUTPUT clause (TSQL)
4341    #[serde(default)]
4342    pub output: Option<OutputClause>,
4343    /// Leading comments before the statement
4344    #[serde(default)]
4345    pub leading_comments: Vec<String>,
4346    /// WITH clause (CTEs)
4347    #[serde(default)]
4348    pub with: Option<With>,
4349    /// LIMIT clause (MySQL)
4350    #[serde(default)]
4351    pub limit: Option<Expression>,
4352    /// ORDER BY clause (MySQL)
4353    #[serde(default)]
4354    pub order_by: Option<OrderBy>,
4355    /// RETURNING clause (PostgreSQL)
4356    #[serde(default)]
4357    pub returning: Vec<Expression>,
4358    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4359    /// These are the target tables to delete from
4360    #[serde(default)]
4361    pub tables: Vec<TableRef>,
4362    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4363    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4364    #[serde(default)]
4365    pub tables_from_using: bool,
4366    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4367    #[serde(default)]
4368    pub joins: Vec<Join>,
4369    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4370    #[serde(default)]
4371    pub force_index: Option<String>,
4372    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4373    #[serde(default)]
4374    pub no_from: bool,
4375}
4376
4377/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4379#[cfg_attr(feature = "bindings", derive(TS))]
4380pub struct CopyStmt {
4381    /// Target table or query
4382    pub this: Expression,
4383    /// True for FROM (loading into table), false for TO (exporting)
4384    pub kind: bool,
4385    /// Source/destination file(s) or stage
4386    pub files: Vec<Expression>,
4387    /// Copy parameters
4388    #[serde(default)]
4389    pub params: Vec<CopyParameter>,
4390    /// Credentials for external access
4391    #[serde(default)]
4392    pub credentials: Option<Box<Credentials>>,
4393    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4394    #[serde(default)]
4395    pub is_into: bool,
4396    /// Whether parameters are wrapped in WITH (...) syntax
4397    #[serde(default)]
4398    pub with_wrapped: bool,
4399}
4400
4401/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4403#[cfg_attr(feature = "bindings", derive(TS))]
4404pub struct CopyParameter {
4405    pub name: String,
4406    pub value: Option<Expression>,
4407    pub values: Vec<Expression>,
4408    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4409    #[serde(default)]
4410    pub eq: bool,
4411}
4412
4413/// Credentials for external access (S3, Azure, etc.)
4414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4415#[cfg_attr(feature = "bindings", derive(TS))]
4416pub struct Credentials {
4417    pub credentials: Vec<(String, String)>,
4418    pub encryption: Option<String>,
4419    pub storage: Option<String>,
4420}
4421
4422/// PUT statement (Snowflake)
4423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4424#[cfg_attr(feature = "bindings", derive(TS))]
4425pub struct PutStmt {
4426    /// Source file path
4427    pub source: String,
4428    /// Whether source was quoted in the original SQL
4429    #[serde(default)]
4430    pub source_quoted: bool,
4431    /// Target stage
4432    pub target: Expression,
4433    /// PUT parameters
4434    #[serde(default)]
4435    pub params: Vec<CopyParameter>,
4436}
4437
4438/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4440#[cfg_attr(feature = "bindings", derive(TS))]
4441pub struct StageReference {
4442    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4443    pub name: String,
4444    /// Optional path within the stage (e.g., "/path/to/file.csv")
4445    #[serde(default)]
4446    pub path: Option<String>,
4447    /// Optional FILE_FORMAT parameter
4448    #[serde(default)]
4449    pub file_format: Option<Expression>,
4450    /// Optional PATTERN parameter
4451    #[serde(default)]
4452    pub pattern: Option<String>,
4453    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4454    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4455    pub quoted: bool,
4456}
4457
4458/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4460#[cfg_attr(feature = "bindings", derive(TS))]
4461pub struct HistoricalData {
4462    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4463    pub this: Box<Expression>,
4464    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4465    pub kind: String,
4466    /// The expression value (e.g., the statement ID or timestamp)
4467    pub expression: Box<Expression>,
4468}
4469
4470/// Represent an aliased expression (`expr AS name`).
4471///
4472/// Used for column aliases in select-lists, table aliases on subqueries,
4473/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4475#[cfg_attr(feature = "bindings", derive(TS))]
4476pub struct Alias {
4477    /// The expression being aliased.
4478    pub this: Expression,
4479    /// The alias name (required for simple aliases, optional when only column aliases provided)
4480    pub alias: Identifier,
4481    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4482    #[serde(default)]
4483    pub column_aliases: Vec<Identifier>,
4484    /// Comments that appeared between the expression and AS keyword
4485    #[serde(default)]
4486    pub pre_alias_comments: Vec<String>,
4487    /// Trailing comments that appeared after the alias
4488    #[serde(default)]
4489    pub trailing_comments: Vec<String>,
4490    /// Inferred data type from type annotation
4491    #[serde(default, skip_serializing_if = "Option::is_none")]
4492    pub inferred_type: Option<DataType>,
4493}
4494
4495impl Alias {
4496    /// Create a simple alias
4497    pub fn new(this: Expression, alias: Identifier) -> Self {
4498        Self {
4499            this,
4500            alias,
4501            column_aliases: Vec::new(),
4502            pre_alias_comments: Vec::new(),
4503            trailing_comments: Vec::new(),
4504            inferred_type: None,
4505        }
4506    }
4507
4508    /// Create an alias with column aliases only (no table alias name)
4509    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4510        Self {
4511            this,
4512            alias: Identifier::empty(),
4513            column_aliases,
4514            pre_alias_comments: Vec::new(),
4515            trailing_comments: Vec::new(),
4516            inferred_type: None,
4517        }
4518    }
4519}
4520
4521/// Represent a type cast expression.
4522///
4523/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4524/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4525/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4526/// CONVERSION ERROR (Oracle) clauses.
4527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4528#[cfg_attr(feature = "bindings", derive(TS))]
4529pub struct Cast {
4530    /// The expression being cast.
4531    pub this: Expression,
4532    /// The target data type.
4533    pub to: DataType,
4534    #[serde(default)]
4535    pub trailing_comments: Vec<String>,
4536    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4537    #[serde(default)]
4538    pub double_colon_syntax: bool,
4539    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4540    #[serde(skip_serializing_if = "Option::is_none", default)]
4541    pub format: Option<Box<Expression>>,
4542    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4543    #[serde(skip_serializing_if = "Option::is_none", default)]
4544    pub default: Option<Box<Expression>>,
4545    /// Inferred data type from type annotation
4546    #[serde(default, skip_serializing_if = "Option::is_none")]
4547    pub inferred_type: Option<DataType>,
4548}
4549
4550///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4552#[cfg_attr(feature = "bindings", derive(TS))]
4553pub struct CollationExpr {
4554    pub this: Expression,
4555    pub collation: String,
4556    /// True if the collation was single-quoted in the original SQL (string literal)
4557    #[serde(default)]
4558    pub quoted: bool,
4559    /// True if the collation was double-quoted in the original SQL (identifier)
4560    #[serde(default)]
4561    pub double_quoted: bool,
4562}
4563
4564/// Represent a CASE expression (both simple and searched forms).
4565///
4566/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4567/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4568/// Each entry in `whens` is a `(condition, result)` pair.
4569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4570#[cfg_attr(feature = "bindings", derive(TS))]
4571pub struct Case {
4572    /// The operand for simple CASE, or `None` for searched CASE.
4573    pub operand: Option<Expression>,
4574    /// Pairs of (WHEN condition, THEN result).
4575    pub whens: Vec<(Expression, Expression)>,
4576    /// Optional ELSE result.
4577    pub else_: Option<Expression>,
4578    /// Comments from the CASE keyword (emitted after END)
4579    #[serde(default)]
4580    #[serde(skip_serializing_if = "Vec::is_empty")]
4581    pub comments: Vec<String>,
4582    /// Inferred data type from type annotation
4583    #[serde(default, skip_serializing_if = "Option::is_none")]
4584    pub inferred_type: Option<DataType>,
4585}
4586
4587/// Represent a binary operation (two operands separated by an operator).
4588///
4589/// This is the shared payload struct for all binary operator variants in the
4590/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4591/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4592/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4593/// preservation of inline comments around operators.
4594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4595#[cfg_attr(feature = "bindings", derive(TS))]
4596pub struct BinaryOp {
4597    pub left: Expression,
4598    pub right: Expression,
4599    /// Comments after the left operand (before the operator)
4600    #[serde(default)]
4601    pub left_comments: Vec<String>,
4602    /// Comments after the operator (before the right operand)
4603    #[serde(default)]
4604    pub operator_comments: Vec<String>,
4605    /// Comments after the right operand
4606    #[serde(default)]
4607    pub trailing_comments: Vec<String>,
4608    /// Inferred data type from type annotation
4609    #[serde(default, skip_serializing_if = "Option::is_none")]
4610    pub inferred_type: Option<DataType>,
4611}
4612
4613impl BinaryOp {
4614    pub fn new(left: Expression, right: Expression) -> Self {
4615        Self {
4616            left,
4617            right,
4618            left_comments: Vec::new(),
4619            operator_comments: Vec::new(),
4620            trailing_comments: Vec::new(),
4621            inferred_type: None,
4622        }
4623    }
4624}
4625
4626/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4628#[cfg_attr(feature = "bindings", derive(TS))]
4629pub struct LikeOp {
4630    pub left: Expression,
4631    pub right: Expression,
4632    /// ESCAPE character/expression
4633    #[serde(default)]
4634    pub escape: Option<Expression>,
4635    /// Quantifier: ANY, ALL, or SOME
4636    #[serde(default)]
4637    pub quantifier: Option<String>,
4638    /// Inferred data type from type annotation
4639    #[serde(default, skip_serializing_if = "Option::is_none")]
4640    pub inferred_type: Option<DataType>,
4641}
4642
4643impl LikeOp {
4644    pub fn new(left: Expression, right: Expression) -> Self {
4645        Self {
4646            left,
4647            right,
4648            escape: None,
4649            quantifier: None,
4650            inferred_type: None,
4651        }
4652    }
4653
4654    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4655        Self {
4656            left,
4657            right,
4658            escape: Some(escape),
4659            quantifier: None,
4660            inferred_type: None,
4661        }
4662    }
4663}
4664
4665/// Represent a unary operation (single operand with a prefix operator).
4666///
4667/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4669#[cfg_attr(feature = "bindings", derive(TS))]
4670pub struct UnaryOp {
4671    /// The operand expression.
4672    pub this: Expression,
4673    /// Inferred data type from type annotation
4674    #[serde(default, skip_serializing_if = "Option::is_none")]
4675    pub inferred_type: Option<DataType>,
4676}
4677
4678impl UnaryOp {
4679    pub fn new(this: Expression) -> Self {
4680        Self {
4681            this,
4682            inferred_type: None,
4683        }
4684    }
4685}
4686
4687/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4688///
4689/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4690/// but not both. When `not` is true, the predicate is `NOT IN`.
4691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4692#[cfg_attr(feature = "bindings", derive(TS))]
4693pub struct In {
4694    /// The expression being tested.
4695    pub this: Expression,
4696    /// The value list (mutually exclusive with `query`).
4697    pub expressions: Vec<Expression>,
4698    /// A subquery (mutually exclusive with `expressions`).
4699    pub query: Option<Expression>,
4700    /// Whether this is NOT IN.
4701    pub not: bool,
4702    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4703    pub global: bool,
4704    /// BigQuery: IN UNNEST(expr)
4705    #[serde(default, skip_serializing_if = "Option::is_none")]
4706    pub unnest: Option<Box<Expression>>,
4707    /// Whether the right side is a bare field reference (no parentheses).
4708    /// Matches Python sqlglot's `field` attribute on `In` expression.
4709    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4710    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4711    pub is_field: bool,
4712}
4713
4714/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4716#[cfg_attr(feature = "bindings", derive(TS))]
4717pub struct Between {
4718    /// The expression being tested.
4719    pub this: Expression,
4720    /// The lower bound.
4721    pub low: Expression,
4722    /// The upper bound.
4723    pub high: Expression,
4724    /// Whether this is NOT BETWEEN.
4725    pub not: bool,
4726    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4727    #[serde(default)]
4728    pub symmetric: Option<bool>,
4729}
4730
4731/// IS NULL predicate
4732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4733#[cfg_attr(feature = "bindings", derive(TS))]
4734pub struct IsNull {
4735    pub this: Expression,
4736    pub not: bool,
4737    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4738    #[serde(default)]
4739    pub postfix_form: bool,
4740}
4741
4742/// IS TRUE / IS FALSE predicate
4743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4744#[cfg_attr(feature = "bindings", derive(TS))]
4745pub struct IsTrueFalse {
4746    pub this: Expression,
4747    pub not: bool,
4748}
4749
4750/// IS JSON predicate (SQL standard)
4751/// Checks if a value is valid JSON
4752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4753#[cfg_attr(feature = "bindings", derive(TS))]
4754pub struct IsJson {
4755    pub this: Expression,
4756    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4757    pub json_type: Option<String>,
4758    /// Key uniqueness constraint
4759    pub unique_keys: Option<JsonUniqueKeys>,
4760    /// Whether IS NOT JSON
4761    pub negated: bool,
4762}
4763
4764/// JSON unique keys constraint variants
4765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4766#[cfg_attr(feature = "bindings", derive(TS))]
4767pub enum JsonUniqueKeys {
4768    /// WITH UNIQUE KEYS
4769    With,
4770    /// WITHOUT UNIQUE KEYS
4771    Without,
4772    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4773    Shorthand,
4774}
4775
4776/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4778#[cfg_attr(feature = "bindings", derive(TS))]
4779pub struct Exists {
4780    /// The subquery expression.
4781    pub this: Expression,
4782    /// Whether this is NOT EXISTS.
4783    pub not: bool,
4784}
4785
4786/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4787///
4788/// This is the generic function node. Well-known aggregates, window functions,
4789/// and built-in functions each have their own dedicated `Expression` variants
4790/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4791/// not recognize as built-ins are represented with this struct.
4792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4793#[cfg_attr(feature = "bindings", derive(TS))]
4794pub struct Function {
4795    /// The function name, as originally written (may be schema-qualified).
4796    pub name: String,
4797    /// Positional arguments to the function.
4798    pub args: Vec<Expression>,
4799    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4800    pub distinct: bool,
4801    #[serde(default)]
4802    pub trailing_comments: Vec<String>,
4803    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4804    #[serde(default)]
4805    pub use_bracket_syntax: bool,
4806    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4807    #[serde(default)]
4808    pub no_parens: bool,
4809    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4810    #[serde(default)]
4811    pub quoted: bool,
4812    /// Source position span
4813    #[serde(default, skip_serializing_if = "Option::is_none")]
4814    pub span: Option<Span>,
4815    /// Inferred data type from type annotation
4816    #[serde(default, skip_serializing_if = "Option::is_none")]
4817    pub inferred_type: Option<DataType>,
4818}
4819
4820impl Default for Function {
4821    fn default() -> Self {
4822        Self {
4823            name: String::new(),
4824            args: Vec::new(),
4825            distinct: false,
4826            trailing_comments: Vec::new(),
4827            use_bracket_syntax: false,
4828            no_parens: false,
4829            quoted: false,
4830            span: None,
4831            inferred_type: None,
4832        }
4833    }
4834}
4835
4836impl Function {
4837    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4838        Self {
4839            name: name.into(),
4840            args,
4841            distinct: false,
4842            trailing_comments: Vec::new(),
4843            use_bracket_syntax: false,
4844            no_parens: false,
4845            quoted: false,
4846            span: None,
4847            inferred_type: None,
4848        }
4849    }
4850}
4851
4852/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4853///
4854/// This struct is used for aggregate function calls that are not covered by
4855/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4856/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4857/// IGNORE NULLS / RESPECT NULLS modifiers.
4858#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4859#[cfg_attr(feature = "bindings", derive(TS))]
4860pub struct AggregateFunction {
4861    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4862    pub name: String,
4863    /// Positional arguments.
4864    pub args: Vec<Expression>,
4865    /// Whether DISTINCT was specified.
4866    pub distinct: bool,
4867    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4868    pub filter: Option<Expression>,
4869    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4870    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4871    pub order_by: Vec<Ordered>,
4872    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4873    #[serde(default, skip_serializing_if = "Option::is_none")]
4874    pub limit: Option<Box<Expression>>,
4875    /// IGNORE NULLS / RESPECT NULLS
4876    #[serde(default, skip_serializing_if = "Option::is_none")]
4877    pub ignore_nulls: Option<bool>,
4878    /// Inferred data type from type annotation
4879    #[serde(default, skip_serializing_if = "Option::is_none")]
4880    pub inferred_type: Option<DataType>,
4881}
4882
4883/// Represent a window function call with its OVER clause.
4884///
4885/// The inner `this` expression is typically a window-specific expression
4886/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4887/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4888/// frame specification.
4889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4890#[cfg_attr(feature = "bindings", derive(TS))]
4891pub struct WindowFunction {
4892    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4893    pub this: Expression,
4894    /// The OVER clause defining the window partitioning, ordering, and frame.
4895    pub over: Over,
4896    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4897    #[serde(default, skip_serializing_if = "Option::is_none")]
4898    pub keep: Option<Keep>,
4899    /// Inferred data type from type annotation
4900    #[serde(default, skip_serializing_if = "Option::is_none")]
4901    pub inferred_type: Option<DataType>,
4902}
4903
4904/// Oracle KEEP clause for aggregate functions
4905/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4907#[cfg_attr(feature = "bindings", derive(TS))]
4908pub struct Keep {
4909    /// true = FIRST, false = LAST
4910    pub first: bool,
4911    /// ORDER BY clause inside KEEP
4912    pub order_by: Vec<Ordered>,
4913}
4914
4915/// WITHIN GROUP clause (for ordered-set aggregate functions)
4916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4917#[cfg_attr(feature = "bindings", derive(TS))]
4918pub struct WithinGroup {
4919    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4920    pub this: Expression,
4921    /// The ORDER BY clause within the group
4922    pub order_by: Vec<Ordered>,
4923}
4924
4925/// Represent the FROM clause of a SELECT statement.
4926///
4927/// Contains one or more table sources (tables, subqueries, table-valued
4928/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4930#[cfg_attr(feature = "bindings", derive(TS))]
4931pub struct From {
4932    /// The table source expressions.
4933    pub expressions: Vec<Expression>,
4934}
4935
4936/// Represent a JOIN clause between two table sources.
4937///
4938/// The join condition can be specified via `on` (ON predicate) or `using`
4939/// (USING column list), but not both. The `kind` field determines the join
4940/// type (INNER, LEFT, CROSS, etc.).
4941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4942#[cfg_attr(feature = "bindings", derive(TS))]
4943pub struct Join {
4944    /// The right-hand table expression being joined.
4945    pub this: Expression,
4946    /// The ON condition (mutually exclusive with `using`).
4947    pub on: Option<Expression>,
4948    /// The USING column list (mutually exclusive with `on`).
4949    pub using: Vec<Identifier>,
4950    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4951    pub kind: JoinKind,
4952    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4953    pub use_inner_keyword: bool,
4954    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4955    pub use_outer_keyword: bool,
4956    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4957    pub deferred_condition: bool,
4958    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4959    #[serde(default, skip_serializing_if = "Option::is_none")]
4960    pub join_hint: Option<String>,
4961    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4962    #[serde(default, skip_serializing_if = "Option::is_none")]
4963    pub match_condition: Option<Expression>,
4964    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4965    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4966    pub pivots: Vec<Expression>,
4967    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4968    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4969    pub comments: Vec<String>,
4970    /// Nesting group identifier for nested join pretty-printing.
4971    /// Joins in the same group were parsed together; group boundaries come from
4972    /// deferred condition resolution phases.
4973    #[serde(default)]
4974    pub nesting_group: usize,
4975    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4976    #[serde(default)]
4977    pub directed: bool,
4978}
4979
4980/// Enumerate all supported SQL join types.
4981///
4982/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4983/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4984/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4985/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4986#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4987#[cfg_attr(feature = "bindings", derive(TS))]
4988pub enum JoinKind {
4989    Inner,
4990    Left,
4991    Right,
4992    Full,
4993    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
4994    Cross,
4995    Natural,
4996    NaturalLeft,
4997    NaturalRight,
4998    NaturalFull,
4999    Semi,
5000    Anti,
5001    // Directional SEMI/ANTI joins
5002    LeftSemi,
5003    LeftAnti,
5004    RightSemi,
5005    RightAnti,
5006    // SQL Server specific
5007    CrossApply,
5008    OuterApply,
5009    // Time-series specific
5010    AsOf,
5011    AsOfLeft,
5012    AsOfRight,
5013    // Lateral join
5014    Lateral,
5015    LeftLateral,
5016    // MySQL specific
5017    Straight,
5018    // Implicit join (comma-separated tables: FROM a, b)
5019    Implicit,
5020    // ClickHouse ARRAY JOIN
5021    Array,
5022    LeftArray,
5023    // ClickHouse PASTE JOIN (positional join)
5024    Paste,
5025    // DuckDB POSITIONAL JOIN
5026    Positional,
5027}
5028
5029impl Default for JoinKind {
5030    fn default() -> Self {
5031        JoinKind::Inner
5032    }
5033}
5034
5035/// Parenthesized table expression with joins
5036/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5038#[cfg_attr(feature = "bindings", derive(TS))]
5039pub struct JoinedTable {
5040    /// The left-hand side table expression
5041    pub left: Expression,
5042    /// The joins applied to the left table
5043    pub joins: Vec<Join>,
5044    /// LATERAL VIEW clauses (Hive/Spark)
5045    pub lateral_views: Vec<LateralView>,
5046    /// Optional alias for the joined table expression
5047    pub alias: Option<Identifier>,
5048}
5049
5050/// Represent a WHERE clause containing a boolean filter predicate.
5051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5052#[cfg_attr(feature = "bindings", derive(TS))]
5053pub struct Where {
5054    /// The filter predicate expression.
5055    pub this: Expression,
5056}
5057
5058/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5059///
5060/// The `expressions` list may contain plain columns, ordinal positions,
5061/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5063#[cfg_attr(feature = "bindings", derive(TS))]
5064pub struct GroupBy {
5065    /// The grouping expressions.
5066    pub expressions: Vec<Expression>,
5067    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5068    #[serde(default)]
5069    pub all: Option<bool>,
5070    /// ClickHouse: WITH TOTALS modifier
5071    #[serde(default)]
5072    pub totals: bool,
5073    /// Leading comments that appeared before the GROUP BY keyword
5074    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5075    pub comments: Vec<String>,
5076}
5077
5078/// Represent a HAVING clause containing a predicate over aggregate results.
5079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5080#[cfg_attr(feature = "bindings", derive(TS))]
5081pub struct Having {
5082    /// The filter predicate, typically involving aggregate functions.
5083    pub this: Expression,
5084    /// Leading comments that appeared before the HAVING keyword
5085    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5086    pub comments: Vec<String>,
5087}
5088
5089/// Represent an ORDER BY clause containing one or more sort specifications.
5090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5091#[cfg_attr(feature = "bindings", derive(TS))]
5092pub struct OrderBy {
5093    /// The sort specifications, each with direction and null ordering.
5094    pub expressions: Vec<Ordered>,
5095    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5096    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5097    pub siblings: bool,
5098    /// Leading comments that appeared before the ORDER BY keyword
5099    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5100    pub comments: Vec<String>,
5101}
5102
5103/// Represent an expression with sort direction and null ordering.
5104///
5105/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5106/// When `desc` is false the sort is ascending. The `nulls_first` field
5107/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5108/// (database default).
5109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5110#[cfg_attr(feature = "bindings", derive(TS))]
5111pub struct Ordered {
5112    /// The expression to sort by.
5113    pub this: Expression,
5114    /// Whether the sort direction is descending (true) or ascending (false).
5115    pub desc: bool,
5116    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5117    pub nulls_first: Option<bool>,
5118    /// Whether ASC was explicitly written (not just implied)
5119    #[serde(default)]
5120    pub explicit_asc: bool,
5121    /// ClickHouse WITH FILL clause
5122    #[serde(default, skip_serializing_if = "Option::is_none")]
5123    pub with_fill: Option<Box<WithFill>>,
5124}
5125
5126impl Ordered {
5127    pub fn asc(expr: Expression) -> Self {
5128        Self {
5129            this: expr,
5130            desc: false,
5131            nulls_first: None,
5132            explicit_asc: false,
5133            with_fill: None,
5134        }
5135    }
5136
5137    pub fn desc(expr: Expression) -> Self {
5138        Self {
5139            this: expr,
5140            desc: true,
5141            nulls_first: None,
5142            explicit_asc: false,
5143            with_fill: None,
5144        }
5145    }
5146}
5147
5148/// DISTRIBUTE BY clause (Hive/Spark)
5149/// Controls how rows are distributed across reducers
5150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5151#[cfg_attr(feature = "bindings", derive(TS))]
5152#[cfg_attr(feature = "bindings", ts(export))]
5153pub struct DistributeBy {
5154    pub expressions: Vec<Expression>,
5155}
5156
5157/// CLUSTER BY clause (Hive/Spark)
5158/// Combines DISTRIBUTE BY and SORT BY on the same columns
5159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5160#[cfg_attr(feature = "bindings", derive(TS))]
5161#[cfg_attr(feature = "bindings", ts(export))]
5162pub struct ClusterBy {
5163    pub expressions: Vec<Ordered>,
5164}
5165
5166/// SORT BY clause (Hive/Spark)
5167/// Sorts data within each reducer (local sort, not global)
5168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5169#[cfg_attr(feature = "bindings", derive(TS))]
5170#[cfg_attr(feature = "bindings", ts(export))]
5171pub struct SortBy {
5172    pub expressions: Vec<Ordered>,
5173}
5174
5175/// LATERAL VIEW clause (Hive/Spark)
5176/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5178#[cfg_attr(feature = "bindings", derive(TS))]
5179#[cfg_attr(feature = "bindings", ts(export))]
5180pub struct LateralView {
5181    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5182    pub this: Expression,
5183    /// Table alias for the generated table
5184    pub table_alias: Option<Identifier>,
5185    /// Column aliases for the generated columns
5186    pub column_aliases: Vec<Identifier>,
5187    /// OUTER keyword - preserve nulls when input is empty/null
5188    pub outer: bool,
5189}
5190
5191/// Query hint
5192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5193#[cfg_attr(feature = "bindings", derive(TS))]
5194#[cfg_attr(feature = "bindings", ts(export))]
5195pub struct Hint {
5196    pub expressions: Vec<HintExpression>,
5197}
5198
5199/// Individual hint expression
5200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5201#[cfg_attr(feature = "bindings", derive(TS))]
5202#[cfg_attr(feature = "bindings", ts(export))]
5203pub enum HintExpression {
5204    /// Function-style hint: USE_HASH(table)
5205    Function { name: String, args: Vec<Expression> },
5206    /// Simple identifier hint: PARALLEL
5207    Identifier(String),
5208    /// Raw hint text (unparsed)
5209    Raw(String),
5210}
5211
5212/// Pseudocolumn type
5213#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5214#[cfg_attr(feature = "bindings", derive(TS))]
5215#[cfg_attr(feature = "bindings", ts(export))]
5216pub enum PseudocolumnType {
5217    Rownum,      // Oracle ROWNUM
5218    Rowid,       // Oracle ROWID
5219    Level,       // Oracle LEVEL (for CONNECT BY)
5220    Sysdate,     // Oracle SYSDATE
5221    ObjectId,    // Oracle OBJECT_ID
5222    ObjectValue, // Oracle OBJECT_VALUE
5223}
5224
5225impl PseudocolumnType {
5226    pub fn as_str(&self) -> &'static str {
5227        match self {
5228            PseudocolumnType::Rownum => "ROWNUM",
5229            PseudocolumnType::Rowid => "ROWID",
5230            PseudocolumnType::Level => "LEVEL",
5231            PseudocolumnType::Sysdate => "SYSDATE",
5232            PseudocolumnType::ObjectId => "OBJECT_ID",
5233            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5234        }
5235    }
5236
5237    pub fn from_str(s: &str) -> Option<Self> {
5238        match s.to_uppercase().as_str() {
5239            "ROWNUM" => Some(PseudocolumnType::Rownum),
5240            "ROWID" => Some(PseudocolumnType::Rowid),
5241            "LEVEL" => Some(PseudocolumnType::Level),
5242            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5243            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5244            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5245            _ => None,
5246        }
5247    }
5248}
5249
5250/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5251/// These are special identifiers that should not be quoted
5252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5253#[cfg_attr(feature = "bindings", derive(TS))]
5254#[cfg_attr(feature = "bindings", ts(export))]
5255pub struct Pseudocolumn {
5256    pub kind: PseudocolumnType,
5257}
5258
5259impl Pseudocolumn {
5260    pub fn rownum() -> Self {
5261        Self {
5262            kind: PseudocolumnType::Rownum,
5263        }
5264    }
5265
5266    pub fn rowid() -> Self {
5267        Self {
5268            kind: PseudocolumnType::Rowid,
5269        }
5270    }
5271
5272    pub fn level() -> Self {
5273        Self {
5274            kind: PseudocolumnType::Level,
5275        }
5276    }
5277}
5278
5279/// Oracle CONNECT BY clause for hierarchical queries
5280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5281#[cfg_attr(feature = "bindings", derive(TS))]
5282#[cfg_attr(feature = "bindings", ts(export))]
5283pub struct Connect {
5284    /// START WITH condition (optional, can come before or after CONNECT BY)
5285    pub start: Option<Expression>,
5286    /// CONNECT BY condition (required, contains PRIOR references)
5287    pub connect: Expression,
5288    /// NOCYCLE keyword to prevent infinite loops
5289    pub nocycle: bool,
5290}
5291
5292/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5294#[cfg_attr(feature = "bindings", derive(TS))]
5295#[cfg_attr(feature = "bindings", ts(export))]
5296pub struct Prior {
5297    pub this: Expression,
5298}
5299
5300/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5302#[cfg_attr(feature = "bindings", derive(TS))]
5303#[cfg_attr(feature = "bindings", ts(export))]
5304pub struct ConnectByRoot {
5305    pub this: Expression,
5306}
5307
5308/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5310#[cfg_attr(feature = "bindings", derive(TS))]
5311#[cfg_attr(feature = "bindings", ts(export))]
5312pub struct MatchRecognize {
5313    /// Source table/expression
5314    pub this: Option<Box<Expression>>,
5315    /// PARTITION BY expressions
5316    pub partition_by: Option<Vec<Expression>>,
5317    /// ORDER BY expressions
5318    pub order_by: Option<Vec<Ordered>>,
5319    /// MEASURES definitions
5320    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5321    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5322    pub rows: Option<MatchRecognizeRows>,
5323    /// AFTER MATCH SKIP behavior
5324    pub after: Option<MatchRecognizeAfter>,
5325    /// PATTERN definition (stored as raw string for complex regex patterns)
5326    pub pattern: Option<String>,
5327    /// DEFINE clauses (pattern variable definitions)
5328    pub define: Option<Vec<(Identifier, Expression)>>,
5329    /// Optional alias for the result
5330    pub alias: Option<Identifier>,
5331    /// Whether AS keyword was explicitly present before alias
5332    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5333    pub alias_explicit_as: bool,
5334}
5335
5336/// MEASURES expression with optional RUNNING/FINAL semantics
5337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5338#[cfg_attr(feature = "bindings", derive(TS))]
5339#[cfg_attr(feature = "bindings", ts(export))]
5340pub struct MatchRecognizeMeasure {
5341    /// The measure expression
5342    pub this: Expression,
5343    /// RUNNING or FINAL semantics (Snowflake-specific)
5344    pub window_frame: Option<MatchRecognizeSemantics>,
5345}
5346
5347/// Semantics for MEASURES in MATCH_RECOGNIZE
5348#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5349#[cfg_attr(feature = "bindings", derive(TS))]
5350#[cfg_attr(feature = "bindings", ts(export))]
5351pub enum MatchRecognizeSemantics {
5352    Running,
5353    Final,
5354}
5355
5356/// Row output semantics for MATCH_RECOGNIZE
5357#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5358#[cfg_attr(feature = "bindings", derive(TS))]
5359#[cfg_attr(feature = "bindings", ts(export))]
5360pub enum MatchRecognizeRows {
5361    OneRowPerMatch,
5362    AllRowsPerMatch,
5363    AllRowsPerMatchShowEmptyMatches,
5364    AllRowsPerMatchOmitEmptyMatches,
5365    AllRowsPerMatchWithUnmatchedRows,
5366}
5367
5368/// AFTER MATCH SKIP behavior
5369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5370#[cfg_attr(feature = "bindings", derive(TS))]
5371#[cfg_attr(feature = "bindings", ts(export))]
5372pub enum MatchRecognizeAfter {
5373    PastLastRow,
5374    ToNextRow,
5375    ToFirst(Identifier),
5376    ToLast(Identifier),
5377}
5378
5379/// Represent a LIMIT clause that restricts the number of returned rows.
5380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5381#[cfg_attr(feature = "bindings", derive(TS))]
5382pub struct Limit {
5383    /// The limit count expression.
5384    pub this: Expression,
5385    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5386    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5387    pub percent: bool,
5388    /// Comments from before the LIMIT keyword (emitted after the limit value)
5389    #[serde(default)]
5390    #[serde(skip_serializing_if = "Vec::is_empty")]
5391    pub comments: Vec<String>,
5392}
5393
5394/// OFFSET clause
5395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5396#[cfg_attr(feature = "bindings", derive(TS))]
5397pub struct Offset {
5398    pub this: Expression,
5399    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5400    #[serde(skip_serializing_if = "Option::is_none", default)]
5401    pub rows: Option<bool>,
5402}
5403
5404/// TOP clause (SQL Server)
5405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5406#[cfg_attr(feature = "bindings", derive(TS))]
5407pub struct Top {
5408    pub this: Expression,
5409    pub percent: bool,
5410    pub with_ties: bool,
5411    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5412    #[serde(default)]
5413    pub parenthesized: bool,
5414}
5415
5416/// FETCH FIRST/NEXT clause (SQL standard)
5417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5418#[cfg_attr(feature = "bindings", derive(TS))]
5419pub struct Fetch {
5420    /// FIRST or NEXT
5421    pub direction: String,
5422    /// Count expression (optional)
5423    pub count: Option<Expression>,
5424    /// PERCENT modifier
5425    pub percent: bool,
5426    /// ROWS or ROW keyword present
5427    pub rows: bool,
5428    /// WITH TIES modifier
5429    pub with_ties: bool,
5430}
5431
5432/// Represent a QUALIFY clause for filtering on window function results.
5433///
5434/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5435/// typically references a window function (e.g.
5436/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5438#[cfg_attr(feature = "bindings", derive(TS))]
5439pub struct Qualify {
5440    /// The filter predicate over window function results.
5441    pub this: Expression,
5442}
5443
5444/// SAMPLE / TABLESAMPLE clause
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct Sample {
5448    pub method: SampleMethod,
5449    pub size: Expression,
5450    pub seed: Option<Expression>,
5451    /// ClickHouse OFFSET expression after SAMPLE size
5452    #[serde(default)]
5453    pub offset: Option<Expression>,
5454    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5455    pub unit_after_size: bool,
5456    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5457    #[serde(default)]
5458    pub use_sample_keyword: bool,
5459    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5460    #[serde(default)]
5461    pub explicit_method: bool,
5462    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5463    #[serde(default)]
5464    pub method_before_size: bool,
5465    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5466    #[serde(default)]
5467    pub use_seed_keyword: bool,
5468    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5469    pub bucket_numerator: Option<Box<Expression>>,
5470    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5471    pub bucket_denominator: Option<Box<Expression>>,
5472    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5473    pub bucket_field: Option<Box<Expression>>,
5474    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5475    #[serde(default)]
5476    pub is_using_sample: bool,
5477    /// Whether the unit was explicitly PERCENT (vs ROWS)
5478    #[serde(default)]
5479    pub is_percent: bool,
5480    /// Whether to suppress method output (for cross-dialect transpilation)
5481    #[serde(default)]
5482    pub suppress_method_output: bool,
5483}
5484
5485/// Sample method
5486#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5487#[cfg_attr(feature = "bindings", derive(TS))]
5488pub enum SampleMethod {
5489    Bernoulli,
5490    System,
5491    Block,
5492    Row,
5493    Percent,
5494    /// Hive bucket sampling
5495    Bucket,
5496    /// DuckDB reservoir sampling
5497    Reservoir,
5498}
5499
5500/// Named window definition (WINDOW w AS (...))
5501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5502#[cfg_attr(feature = "bindings", derive(TS))]
5503pub struct NamedWindow {
5504    pub name: Identifier,
5505    pub spec: Over,
5506}
5507
5508/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5509///
5510/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5511/// that reference themselves. Each CTE is defined in the `ctes` vector and
5512/// can be referenced by name in subsequent CTEs and in the main query body.
5513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5514#[cfg_attr(feature = "bindings", derive(TS))]
5515pub struct With {
5516    /// The list of CTE definitions, in order.
5517    pub ctes: Vec<Cte>,
5518    /// Whether the WITH RECURSIVE keyword was used.
5519    pub recursive: bool,
5520    /// Leading comments before the statement
5521    #[serde(default)]
5522    pub leading_comments: Vec<String>,
5523    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5524    #[serde(default, skip_serializing_if = "Option::is_none")]
5525    pub search: Option<Box<Expression>>,
5526}
5527
5528/// Represent a single Common Table Expression definition.
5529///
5530/// A CTE has a name (`alias`), an optional column list, and a body query.
5531/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5532/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5533/// the expression comes before the alias (`alias_first`).
5534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5535#[cfg_attr(feature = "bindings", derive(TS))]
5536pub struct Cte {
5537    /// The CTE name.
5538    pub alias: Identifier,
5539    /// The CTE body (typically a SELECT, UNION, etc.).
5540    pub this: Expression,
5541    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5542    pub columns: Vec<Identifier>,
5543    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5544    pub materialized: Option<bool>,
5545    /// USING KEY (columns) for DuckDB recursive CTEs
5546    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5547    pub key_expressions: Vec<Identifier>,
5548    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5549    #[serde(default)]
5550    pub alias_first: bool,
5551    /// Comments associated with this CTE (placed after alias name, before AS)
5552    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5553    pub comments: Vec<String>,
5554}
5555
5556/// Window specification
5557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5558#[cfg_attr(feature = "bindings", derive(TS))]
5559pub struct WindowSpec {
5560    pub partition_by: Vec<Expression>,
5561    pub order_by: Vec<Ordered>,
5562    pub frame: Option<WindowFrame>,
5563}
5564
5565/// OVER clause
5566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5567#[cfg_attr(feature = "bindings", derive(TS))]
5568pub struct Over {
5569    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5570    pub window_name: Option<Identifier>,
5571    pub partition_by: Vec<Expression>,
5572    pub order_by: Vec<Ordered>,
5573    pub frame: Option<WindowFrame>,
5574    pub alias: Option<Identifier>,
5575}
5576
5577/// Window frame
5578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5579#[cfg_attr(feature = "bindings", derive(TS))]
5580pub struct WindowFrame {
5581    pub kind: WindowFrameKind,
5582    pub start: WindowFrameBound,
5583    pub end: Option<WindowFrameBound>,
5584    pub exclude: Option<WindowFrameExclude>,
5585    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5586    #[serde(default, skip_serializing_if = "Option::is_none")]
5587    pub kind_text: Option<String>,
5588    /// Original text of the start bound side keyword (e.g. "preceding")
5589    #[serde(default, skip_serializing_if = "Option::is_none")]
5590    pub start_side_text: Option<String>,
5591    /// Original text of the end bound side keyword
5592    #[serde(default, skip_serializing_if = "Option::is_none")]
5593    pub end_side_text: Option<String>,
5594}
5595
5596#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5597#[cfg_attr(feature = "bindings", derive(TS))]
5598pub enum WindowFrameKind {
5599    Rows,
5600    Range,
5601    Groups,
5602}
5603
5604/// EXCLUDE clause for window frames
5605#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5606#[cfg_attr(feature = "bindings", derive(TS))]
5607pub enum WindowFrameExclude {
5608    CurrentRow,
5609    Group,
5610    Ties,
5611    NoOthers,
5612}
5613
5614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5615#[cfg_attr(feature = "bindings", derive(TS))]
5616pub enum WindowFrameBound {
5617    CurrentRow,
5618    UnboundedPreceding,
5619    UnboundedFollowing,
5620    Preceding(Box<Expression>),
5621    Following(Box<Expression>),
5622    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5623    BarePreceding,
5624    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5625    BareFollowing,
5626    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5627    Value(Box<Expression>),
5628}
5629
5630/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5632#[cfg_attr(feature = "bindings", derive(TS))]
5633pub struct StructField {
5634    pub name: String,
5635    pub data_type: DataType,
5636    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5637    pub options: Vec<Expression>,
5638    #[serde(default, skip_serializing_if = "Option::is_none")]
5639    pub comment: Option<String>,
5640}
5641
5642impl StructField {
5643    /// Create a new struct field without options
5644    pub fn new(name: String, data_type: DataType) -> Self {
5645        Self {
5646            name,
5647            data_type,
5648            options: Vec::new(),
5649            comment: None,
5650        }
5651    }
5652
5653    /// Create a new struct field with options
5654    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5655        Self {
5656            name,
5657            data_type,
5658            options,
5659            comment: None,
5660        }
5661    }
5662
5663    /// Create a new struct field with options and comment
5664    pub fn with_options_and_comment(
5665        name: String,
5666        data_type: DataType,
5667        options: Vec<Expression>,
5668        comment: Option<String>,
5669    ) -> Self {
5670        Self {
5671            name,
5672            data_type,
5673            options,
5674            comment,
5675        }
5676    }
5677}
5678
5679/// Enumerate all SQL data types recognized by the parser.
5680///
5681/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5682/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5683/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5684///
5685/// This enum is used in CAST expressions, column definitions, function return
5686/// types, and anywhere a data type specification appears in SQL.
5687///
5688/// Types that do not match any known variant fall through to `Custom { name }`,
5689/// preserving the original type name for round-trip fidelity.
5690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5691#[cfg_attr(feature = "bindings", derive(TS))]
5692#[serde(tag = "data_type", rename_all = "snake_case")]
5693pub enum DataType {
5694    // Numeric
5695    Boolean,
5696    TinyInt {
5697        length: Option<u32>,
5698    },
5699    SmallInt {
5700        length: Option<u32>,
5701    },
5702    /// Int type with optional length. `integer_spelling` indicates whether the original
5703    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5704    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5705    Int {
5706        length: Option<u32>,
5707        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5708        integer_spelling: bool,
5709    },
5710    BigInt {
5711        length: Option<u32>,
5712    },
5713    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5714    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5715    /// preserve the original spelling.
5716    Float {
5717        precision: Option<u32>,
5718        scale: Option<u32>,
5719        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5720        real_spelling: bool,
5721    },
5722    Double {
5723        precision: Option<u32>,
5724        scale: Option<u32>,
5725    },
5726    Decimal {
5727        precision: Option<u32>,
5728        scale: Option<u32>,
5729    },
5730
5731    // String
5732    Char {
5733        length: Option<u32>,
5734    },
5735    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5736    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5737    VarChar {
5738        length: Option<u32>,
5739        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5740        parenthesized_length: bool,
5741    },
5742    /// String type with optional max length (BigQuery STRING(n))
5743    String {
5744        length: Option<u32>,
5745    },
5746    Text,
5747    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5748    TextWithLength {
5749        length: u32,
5750    },
5751
5752    // Binary
5753    Binary {
5754        length: Option<u32>,
5755    },
5756    VarBinary {
5757        length: Option<u32>,
5758    },
5759    Blob,
5760
5761    // Bit
5762    Bit {
5763        length: Option<u32>,
5764    },
5765    VarBit {
5766        length: Option<u32>,
5767    },
5768
5769    // Date/Time
5770    Date,
5771    Time {
5772        precision: Option<u32>,
5773        #[serde(default)]
5774        timezone: bool,
5775    },
5776    Timestamp {
5777        precision: Option<u32>,
5778        timezone: bool,
5779    },
5780    Interval {
5781        unit: Option<String>,
5782        /// For range intervals like INTERVAL DAY TO HOUR
5783        #[serde(default, skip_serializing_if = "Option::is_none")]
5784        to: Option<String>,
5785    },
5786
5787    // JSON
5788    Json,
5789    JsonB,
5790
5791    // UUID
5792    Uuid,
5793
5794    // Array
5795    Array {
5796        element_type: Box<DataType>,
5797        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5798        #[serde(default, skip_serializing_if = "Option::is_none")]
5799        dimension: Option<u32>,
5800    },
5801
5802    /// List type (Materialize): INT LIST, TEXT LIST LIST
5803    /// Uses postfix LIST syntax instead of ARRAY<T>
5804    List {
5805        element_type: Box<DataType>,
5806    },
5807
5808    // Struct/Map
5809    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5810    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5811    Struct {
5812        fields: Vec<StructField>,
5813        nested: bool,
5814    },
5815    Map {
5816        key_type: Box<DataType>,
5817        value_type: Box<DataType>,
5818    },
5819
5820    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5821    Enum {
5822        values: Vec<String>,
5823        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5824        assignments: Vec<Option<String>>,
5825    },
5826
5827    // Set type (MySQL): SET('a', 'b', 'c')
5828    Set {
5829        values: Vec<String>,
5830    },
5831
5832    // Union type (DuckDB): UNION(num INT, str TEXT)
5833    Union {
5834        fields: Vec<(String, DataType)>,
5835    },
5836
5837    // Vector (Snowflake / SingleStore)
5838    Vector {
5839        #[serde(default)]
5840        element_type: Option<Box<DataType>>,
5841        dimension: Option<u32>,
5842    },
5843
5844    // Object (Snowflake structured type)
5845    // fields: Vec of (field_name, field_type, not_null)
5846    Object {
5847        fields: Vec<(String, DataType, bool)>,
5848        modifier: Option<String>,
5849    },
5850
5851    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5852    Nullable {
5853        inner: Box<DataType>,
5854    },
5855
5856    // Custom/User-defined
5857    Custom {
5858        name: String,
5859    },
5860
5861    // Spatial types
5862    Geometry {
5863        subtype: Option<String>,
5864        srid: Option<u32>,
5865    },
5866    Geography {
5867        subtype: Option<String>,
5868        srid: Option<u32>,
5869    },
5870
5871    // Character Set (for CONVERT USING in MySQL)
5872    // Renders as CHAR CHARACTER SET {name} in cast target
5873    CharacterSet {
5874        name: String,
5875    },
5876
5877    // Unknown
5878    Unknown,
5879}
5880
5881/// Array expression
5882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5883#[cfg_attr(feature = "bindings", derive(TS))]
5884#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5885pub struct Array {
5886    pub expressions: Vec<Expression>,
5887}
5888
5889/// Struct expression
5890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5891#[cfg_attr(feature = "bindings", derive(TS))]
5892pub struct Struct {
5893    pub fields: Vec<(Option<String>, Expression)>,
5894}
5895
5896/// Tuple expression
5897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5898#[cfg_attr(feature = "bindings", derive(TS))]
5899pub struct Tuple {
5900    pub expressions: Vec<Expression>,
5901}
5902
5903/// Interval expression
5904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5905#[cfg_attr(feature = "bindings", derive(TS))]
5906pub struct Interval {
5907    /// The value expression (e.g., '1', 5, column_ref)
5908    pub this: Option<Expression>,
5909    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5910    pub unit: Option<IntervalUnitSpec>,
5911}
5912
5913/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5915#[cfg_attr(feature = "bindings", derive(TS))]
5916#[serde(tag = "type", rename_all = "snake_case")]
5917pub enum IntervalUnitSpec {
5918    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5919    Simple {
5920        unit: IntervalUnit,
5921        /// Whether to use plural form (e.g., DAYS vs DAY)
5922        use_plural: bool,
5923    },
5924    /// Interval span (e.g., HOUR TO SECOND)
5925    Span(IntervalSpan),
5926    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5927    /// The start and end can be expressions like function calls with precision
5928    ExprSpan(IntervalSpanExpr),
5929    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5930    Expr(Box<Expression>),
5931}
5932
5933/// Interval span for ranges like HOUR TO SECOND
5934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5935#[cfg_attr(feature = "bindings", derive(TS))]
5936pub struct IntervalSpan {
5937    /// Start unit (e.g., HOUR)
5938    pub this: IntervalUnit,
5939    /// End unit (e.g., SECOND)
5940    pub expression: IntervalUnit,
5941}
5942
5943/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5944/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5946#[cfg_attr(feature = "bindings", derive(TS))]
5947pub struct IntervalSpanExpr {
5948    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5949    pub this: Box<Expression>,
5950    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5951    pub expression: Box<Expression>,
5952}
5953
5954#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5955#[cfg_attr(feature = "bindings", derive(TS))]
5956pub enum IntervalUnit {
5957    Year,
5958    Quarter,
5959    Month,
5960    Week,
5961    Day,
5962    Hour,
5963    Minute,
5964    Second,
5965    Millisecond,
5966    Microsecond,
5967    Nanosecond,
5968}
5969
5970/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5972#[cfg_attr(feature = "bindings", derive(TS))]
5973pub struct Command {
5974    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5975    pub this: String,
5976}
5977
5978/// EXEC/EXECUTE statement (TSQL stored procedure call)
5979/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5981#[cfg_attr(feature = "bindings", derive(TS))]
5982pub struct ExecuteStatement {
5983    /// The procedure name (can be qualified: schema.proc_name)
5984    pub this: Expression,
5985    /// Named parameters: @param=value pairs
5986    #[serde(default)]
5987    pub parameters: Vec<ExecuteParameter>,
5988    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
5989    #[serde(default, skip_serializing_if = "Option::is_none")]
5990    pub suffix: Option<String>,
5991}
5992
5993/// Named parameter in EXEC statement: @name=value
5994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5995#[cfg_attr(feature = "bindings", derive(TS))]
5996pub struct ExecuteParameter {
5997    /// Parameter name (including @)
5998    pub name: String,
5999    /// Parameter value
6000    pub value: Expression,
6001    /// Whether this is a positional parameter (no = sign)
6002    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6003    pub positional: bool,
6004    /// TSQL OUTPUT modifier on parameter
6005    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6006    pub output: bool,
6007}
6008
6009/// KILL statement (MySQL/MariaDB)
6010/// KILL [CONNECTION | QUERY] <id>
6011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6012#[cfg_attr(feature = "bindings", derive(TS))]
6013pub struct Kill {
6014    /// The target (process ID or connection ID)
6015    pub this: Expression,
6016    /// Optional kind: "CONNECTION" or "QUERY"
6017    pub kind: Option<String>,
6018}
6019
6020/// Snowflake CREATE TASK statement
6021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6022#[cfg_attr(feature = "bindings", derive(TS))]
6023pub struct CreateTask {
6024    pub or_replace: bool,
6025    pub if_not_exists: bool,
6026    /// Task name (possibly qualified: db.schema.task)
6027    pub name: String,
6028    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6029    pub properties: String,
6030    /// The SQL statement body after AS
6031    pub body: Expression,
6032}
6033
6034/// Raw/unparsed SQL
6035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6036#[cfg_attr(feature = "bindings", derive(TS))]
6037pub struct Raw {
6038    pub sql: String,
6039}
6040
6041// ============================================================================
6042// Function expression types
6043// ============================================================================
6044
6045/// Generic unary function (takes a single argument)
6046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6047#[cfg_attr(feature = "bindings", derive(TS))]
6048pub struct UnaryFunc {
6049    pub this: Expression,
6050    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6051    #[serde(skip_serializing_if = "Option::is_none", default)]
6052    pub original_name: Option<String>,
6053    /// Inferred data type from type annotation
6054    #[serde(default, skip_serializing_if = "Option::is_none")]
6055    pub inferred_type: Option<DataType>,
6056}
6057
6058impl UnaryFunc {
6059    /// Create a new UnaryFunc with no original_name
6060    pub fn new(this: Expression) -> Self {
6061        Self {
6062            this,
6063            original_name: None,
6064            inferred_type: None,
6065        }
6066    }
6067
6068    /// Create a new UnaryFunc with an original name for round-trip preservation
6069    pub fn with_name(this: Expression, name: String) -> Self {
6070        Self {
6071            this,
6072            original_name: Some(name),
6073            inferred_type: None,
6074        }
6075    }
6076}
6077
6078/// CHAR/CHR function with multiple args and optional USING charset
6079/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6080/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6082#[cfg_attr(feature = "bindings", derive(TS))]
6083pub struct CharFunc {
6084    pub args: Vec<Expression>,
6085    #[serde(skip_serializing_if = "Option::is_none", default)]
6086    pub charset: Option<String>,
6087    /// Original function name (CHAR or CHR), defaults to CHAR
6088    #[serde(skip_serializing_if = "Option::is_none", default)]
6089    pub name: Option<String>,
6090}
6091
6092/// Generic binary function (takes two arguments)
6093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6094#[cfg_attr(feature = "bindings", derive(TS))]
6095pub struct BinaryFunc {
6096    pub this: Expression,
6097    pub expression: Expression,
6098    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6099    #[serde(skip_serializing_if = "Option::is_none", default)]
6100    pub original_name: Option<String>,
6101    /// Inferred data type from type annotation
6102    #[serde(default, skip_serializing_if = "Option::is_none")]
6103    pub inferred_type: Option<DataType>,
6104}
6105
6106/// Variable argument function
6107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6108#[cfg_attr(feature = "bindings", derive(TS))]
6109pub struct VarArgFunc {
6110    pub expressions: Vec<Expression>,
6111    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6112    #[serde(skip_serializing_if = "Option::is_none", default)]
6113    pub original_name: Option<String>,
6114    /// Inferred data type from type annotation
6115    #[serde(default, skip_serializing_if = "Option::is_none")]
6116    pub inferred_type: Option<DataType>,
6117}
6118
6119/// CONCAT_WS function
6120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6121#[cfg_attr(feature = "bindings", derive(TS))]
6122pub struct ConcatWs {
6123    pub separator: Expression,
6124    pub expressions: Vec<Expression>,
6125}
6126
6127/// SUBSTRING function
6128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6129#[cfg_attr(feature = "bindings", derive(TS))]
6130pub struct SubstringFunc {
6131    pub this: Expression,
6132    pub start: Expression,
6133    pub length: Option<Expression>,
6134    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6135    #[serde(default)]
6136    pub from_for_syntax: bool,
6137}
6138
6139/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6141#[cfg_attr(feature = "bindings", derive(TS))]
6142pub struct OverlayFunc {
6143    pub this: Expression,
6144    pub replacement: Expression,
6145    pub from: Expression,
6146    pub length: Option<Expression>,
6147}
6148
6149/// TRIM function
6150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6151#[cfg_attr(feature = "bindings", derive(TS))]
6152pub struct TrimFunc {
6153    pub this: Expression,
6154    pub characters: Option<Expression>,
6155    pub position: TrimPosition,
6156    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6157    #[serde(default)]
6158    pub sql_standard_syntax: bool,
6159    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6160    #[serde(default)]
6161    pub position_explicit: bool,
6162}
6163
6164#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6165#[cfg_attr(feature = "bindings", derive(TS))]
6166pub enum TrimPosition {
6167    Both,
6168    Leading,
6169    Trailing,
6170}
6171
6172/// REPLACE function
6173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6174#[cfg_attr(feature = "bindings", derive(TS))]
6175pub struct ReplaceFunc {
6176    pub this: Expression,
6177    pub old: Expression,
6178    pub new: Expression,
6179}
6180
6181/// LEFT/RIGHT function
6182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6183#[cfg_attr(feature = "bindings", derive(TS))]
6184pub struct LeftRightFunc {
6185    pub this: Expression,
6186    pub length: Expression,
6187}
6188
6189/// REPEAT function
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct RepeatFunc {
6193    pub this: Expression,
6194    pub times: Expression,
6195}
6196
6197/// LPAD/RPAD function
6198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6199#[cfg_attr(feature = "bindings", derive(TS))]
6200pub struct PadFunc {
6201    pub this: Expression,
6202    pub length: Expression,
6203    pub fill: Option<Expression>,
6204}
6205
6206/// SPLIT function
6207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6208#[cfg_attr(feature = "bindings", derive(TS))]
6209pub struct SplitFunc {
6210    pub this: Expression,
6211    pub delimiter: Expression,
6212}
6213
6214/// REGEXP_LIKE function
6215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6216#[cfg_attr(feature = "bindings", derive(TS))]
6217pub struct RegexpFunc {
6218    pub this: Expression,
6219    pub pattern: Expression,
6220    pub flags: Option<Expression>,
6221}
6222
6223/// REGEXP_REPLACE function
6224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6225#[cfg_attr(feature = "bindings", derive(TS))]
6226pub struct RegexpReplaceFunc {
6227    pub this: Expression,
6228    pub pattern: Expression,
6229    pub replacement: Expression,
6230    pub flags: Option<Expression>,
6231}
6232
6233/// REGEXP_EXTRACT function
6234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6235#[cfg_attr(feature = "bindings", derive(TS))]
6236pub struct RegexpExtractFunc {
6237    pub this: Expression,
6238    pub pattern: Expression,
6239    pub group: Option<Expression>,
6240}
6241
6242/// ROUND function
6243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6244#[cfg_attr(feature = "bindings", derive(TS))]
6245pub struct RoundFunc {
6246    pub this: Expression,
6247    pub decimals: Option<Expression>,
6248}
6249
6250/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6252#[cfg_attr(feature = "bindings", derive(TS))]
6253pub struct FloorFunc {
6254    pub this: Expression,
6255    pub scale: Option<Expression>,
6256    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6257    #[serde(skip_serializing_if = "Option::is_none", default)]
6258    pub to: Option<Expression>,
6259}
6260
6261/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6263#[cfg_attr(feature = "bindings", derive(TS))]
6264pub struct CeilFunc {
6265    pub this: Expression,
6266    #[serde(skip_serializing_if = "Option::is_none", default)]
6267    pub decimals: Option<Expression>,
6268    /// Time unit for Druid-style CEIL(time TO unit) syntax
6269    #[serde(skip_serializing_if = "Option::is_none", default)]
6270    pub to: Option<Expression>,
6271}
6272
6273/// LOG function
6274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6275#[cfg_attr(feature = "bindings", derive(TS))]
6276pub struct LogFunc {
6277    pub this: Expression,
6278    pub base: Option<Expression>,
6279}
6280
6281/// CURRENT_DATE (no arguments)
6282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6283#[cfg_attr(feature = "bindings", derive(TS))]
6284pub struct CurrentDate;
6285
6286/// CURRENT_TIME
6287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6288#[cfg_attr(feature = "bindings", derive(TS))]
6289pub struct CurrentTime {
6290    pub precision: Option<u32>,
6291}
6292
6293/// CURRENT_TIMESTAMP
6294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6295#[cfg_attr(feature = "bindings", derive(TS))]
6296pub struct CurrentTimestamp {
6297    pub precision: Option<u32>,
6298    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6299    #[serde(default)]
6300    pub sysdate: bool,
6301}
6302
6303/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6305#[cfg_attr(feature = "bindings", derive(TS))]
6306pub struct CurrentTimestampLTZ {
6307    pub precision: Option<u32>,
6308}
6309
6310/// AT TIME ZONE expression for timezone conversion
6311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6312#[cfg_attr(feature = "bindings", derive(TS))]
6313pub struct AtTimeZone {
6314    /// The expression to convert
6315    pub this: Expression,
6316    /// The target timezone
6317    pub zone: Expression,
6318}
6319
6320/// DATE_ADD / DATE_SUB function
6321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6322#[cfg_attr(feature = "bindings", derive(TS))]
6323pub struct DateAddFunc {
6324    pub this: Expression,
6325    pub interval: Expression,
6326    pub unit: IntervalUnit,
6327}
6328
6329/// DATEDIFF function
6330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6331#[cfg_attr(feature = "bindings", derive(TS))]
6332pub struct DateDiffFunc {
6333    pub this: Expression,
6334    pub expression: Expression,
6335    pub unit: Option<IntervalUnit>,
6336}
6337
6338/// DATE_TRUNC function
6339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6340#[cfg_attr(feature = "bindings", derive(TS))]
6341pub struct DateTruncFunc {
6342    pub this: Expression,
6343    pub unit: DateTimeField,
6344}
6345
6346/// EXTRACT function
6347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6348#[cfg_attr(feature = "bindings", derive(TS))]
6349pub struct ExtractFunc {
6350    pub this: Expression,
6351    pub field: DateTimeField,
6352}
6353
6354#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6355#[cfg_attr(feature = "bindings", derive(TS))]
6356pub enum DateTimeField {
6357    Year,
6358    Month,
6359    Day,
6360    Hour,
6361    Minute,
6362    Second,
6363    Millisecond,
6364    Microsecond,
6365    DayOfWeek,
6366    DayOfYear,
6367    Week,
6368    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6369    WeekWithModifier(String),
6370    Quarter,
6371    Epoch,
6372    Timezone,
6373    TimezoneHour,
6374    TimezoneMinute,
6375    Date,
6376    Time,
6377    /// Custom datetime field for dialect-specific or arbitrary fields
6378    Custom(String),
6379}
6380
6381/// TO_DATE function
6382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6383#[cfg_attr(feature = "bindings", derive(TS))]
6384pub struct ToDateFunc {
6385    pub this: Expression,
6386    pub format: Option<Expression>,
6387}
6388
6389/// TO_TIMESTAMP function
6390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6391#[cfg_attr(feature = "bindings", derive(TS))]
6392pub struct ToTimestampFunc {
6393    pub this: Expression,
6394    pub format: Option<Expression>,
6395}
6396
6397/// IF function
6398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6399#[cfg_attr(feature = "bindings", derive(TS))]
6400pub struct IfFunc {
6401    pub condition: Expression,
6402    pub true_value: Expression,
6403    pub false_value: Option<Expression>,
6404    /// Original function name (IF, IFF, IIF) for round-trip preservation
6405    #[serde(skip_serializing_if = "Option::is_none", default)]
6406    pub original_name: Option<String>,
6407    /// Inferred data type from type annotation
6408    #[serde(default, skip_serializing_if = "Option::is_none")]
6409    pub inferred_type: Option<DataType>,
6410}
6411
6412/// NVL2 function
6413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6414#[cfg_attr(feature = "bindings", derive(TS))]
6415pub struct Nvl2Func {
6416    pub this: Expression,
6417    pub true_value: Expression,
6418    pub false_value: Expression,
6419    /// Inferred data type from type annotation
6420    #[serde(default, skip_serializing_if = "Option::is_none")]
6421    pub inferred_type: Option<DataType>,
6422}
6423
6424// ============================================================================
6425// Typed Aggregate Function types
6426// ============================================================================
6427
6428/// Generic aggregate function base type
6429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6430#[cfg_attr(feature = "bindings", derive(TS))]
6431pub struct AggFunc {
6432    pub this: Expression,
6433    pub distinct: bool,
6434    pub filter: Option<Expression>,
6435    pub order_by: Vec<Ordered>,
6436    /// Original function name (case-preserving) when parsed from SQL
6437    #[serde(skip_serializing_if = "Option::is_none", default)]
6438    pub name: Option<String>,
6439    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6440    #[serde(skip_serializing_if = "Option::is_none", default)]
6441    pub ignore_nulls: Option<bool>,
6442    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6443    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6444    #[serde(skip_serializing_if = "Option::is_none", default)]
6445    pub having_max: Option<(Box<Expression>, bool)>,
6446    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6447    #[serde(skip_serializing_if = "Option::is_none", default)]
6448    pub limit: Option<Box<Expression>>,
6449    /// Inferred data type from type annotation
6450    #[serde(default, skip_serializing_if = "Option::is_none")]
6451    pub inferred_type: Option<DataType>,
6452}
6453
6454/// COUNT function with optional star
6455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6456#[cfg_attr(feature = "bindings", derive(TS))]
6457pub struct CountFunc {
6458    pub this: Option<Expression>,
6459    pub star: bool,
6460    pub distinct: bool,
6461    pub filter: Option<Expression>,
6462    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6463    #[serde(default, skip_serializing_if = "Option::is_none")]
6464    pub ignore_nulls: Option<bool>,
6465    /// Original function name for case preservation (e.g., "count" or "COUNT")
6466    #[serde(default, skip_serializing_if = "Option::is_none")]
6467    pub original_name: Option<String>,
6468    /// Inferred data type from type annotation
6469    #[serde(default, skip_serializing_if = "Option::is_none")]
6470    pub inferred_type: Option<DataType>,
6471}
6472
6473/// GROUP_CONCAT function (MySQL style)
6474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6475#[cfg_attr(feature = "bindings", derive(TS))]
6476pub struct GroupConcatFunc {
6477    pub this: Expression,
6478    pub separator: Option<Expression>,
6479    pub order_by: Option<Vec<Ordered>>,
6480    pub distinct: bool,
6481    pub filter: Option<Expression>,
6482    /// Inferred data type from type annotation
6483    #[serde(default, skip_serializing_if = "Option::is_none")]
6484    pub inferred_type: Option<DataType>,
6485}
6486
6487/// STRING_AGG function (PostgreSQL/Standard SQL)
6488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6489#[cfg_attr(feature = "bindings", derive(TS))]
6490pub struct StringAggFunc {
6491    pub this: Expression,
6492    #[serde(default)]
6493    pub separator: Option<Expression>,
6494    #[serde(default)]
6495    pub order_by: Option<Vec<Ordered>>,
6496    #[serde(default)]
6497    pub distinct: bool,
6498    #[serde(default)]
6499    pub filter: Option<Expression>,
6500    /// BigQuery LIMIT inside STRING_AGG
6501    #[serde(default, skip_serializing_if = "Option::is_none")]
6502    pub limit: Option<Box<Expression>>,
6503    /// Inferred data type from type annotation
6504    #[serde(default, skip_serializing_if = "Option::is_none")]
6505    pub inferred_type: Option<DataType>,
6506}
6507
6508/// LISTAGG function (Oracle style)
6509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6510#[cfg_attr(feature = "bindings", derive(TS))]
6511pub struct ListAggFunc {
6512    pub this: Expression,
6513    pub separator: Option<Expression>,
6514    pub on_overflow: Option<ListAggOverflow>,
6515    pub order_by: Option<Vec<Ordered>>,
6516    pub distinct: bool,
6517    pub filter: Option<Expression>,
6518    /// Inferred data type from type annotation
6519    #[serde(default, skip_serializing_if = "Option::is_none")]
6520    pub inferred_type: Option<DataType>,
6521}
6522
6523/// LISTAGG ON OVERFLOW behavior
6524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6525#[cfg_attr(feature = "bindings", derive(TS))]
6526pub enum ListAggOverflow {
6527    Error,
6528    Truncate {
6529        filler: Option<Expression>,
6530        with_count: bool,
6531    },
6532}
6533
6534/// SUM_IF / COUNT_IF function
6535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6536#[cfg_attr(feature = "bindings", derive(TS))]
6537pub struct SumIfFunc {
6538    pub this: Expression,
6539    pub condition: Expression,
6540    pub filter: Option<Expression>,
6541    /// Inferred data type from type annotation
6542    #[serde(default, skip_serializing_if = "Option::is_none")]
6543    pub inferred_type: Option<DataType>,
6544}
6545
6546/// APPROX_PERCENTILE function
6547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6548#[cfg_attr(feature = "bindings", derive(TS))]
6549pub struct ApproxPercentileFunc {
6550    pub this: Expression,
6551    pub percentile: Expression,
6552    pub accuracy: Option<Expression>,
6553    pub filter: Option<Expression>,
6554}
6555
6556/// PERCENTILE_CONT / PERCENTILE_DISC function
6557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6558#[cfg_attr(feature = "bindings", derive(TS))]
6559pub struct PercentileFunc {
6560    pub this: Expression,
6561    pub percentile: Expression,
6562    pub order_by: Option<Vec<Ordered>>,
6563    pub filter: Option<Expression>,
6564}
6565
6566// ============================================================================
6567// Typed Window Function types
6568// ============================================================================
6569
6570/// ROW_NUMBER function (no arguments)
6571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6572#[cfg_attr(feature = "bindings", derive(TS))]
6573pub struct RowNumber;
6574
6575/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6577#[cfg_attr(feature = "bindings", derive(TS))]
6578pub struct Rank {
6579    /// DuckDB: RANK(ORDER BY col) - order by inside function
6580    #[serde(default, skip_serializing_if = "Option::is_none")]
6581    pub order_by: Option<Vec<Ordered>>,
6582    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6583    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6584    pub args: Vec<Expression>,
6585}
6586
6587/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6589#[cfg_attr(feature = "bindings", derive(TS))]
6590pub struct DenseRank {
6591    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6592    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6593    pub args: Vec<Expression>,
6594}
6595
6596/// NTILE function (DuckDB allows ORDER BY inside)
6597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6598#[cfg_attr(feature = "bindings", derive(TS))]
6599pub struct NTileFunc {
6600    /// num_buckets is optional to support Databricks NTILE() without arguments
6601    #[serde(default, skip_serializing_if = "Option::is_none")]
6602    pub num_buckets: Option<Expression>,
6603    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6604    #[serde(default, skip_serializing_if = "Option::is_none")]
6605    pub order_by: Option<Vec<Ordered>>,
6606}
6607
6608/// LEAD / LAG function
6609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6610#[cfg_attr(feature = "bindings", derive(TS))]
6611pub struct LeadLagFunc {
6612    pub this: Expression,
6613    pub offset: Option<Expression>,
6614    pub default: Option<Expression>,
6615    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6616    #[serde(default, skip_serializing_if = "Option::is_none")]
6617    pub ignore_nulls: Option<bool>,
6618}
6619
6620/// FIRST_VALUE / LAST_VALUE function
6621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6622#[cfg_attr(feature = "bindings", derive(TS))]
6623pub struct ValueFunc {
6624    pub this: Expression,
6625    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6626    #[serde(default, skip_serializing_if = "Option::is_none")]
6627    pub ignore_nulls: Option<bool>,
6628    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6629    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6630    pub order_by: Vec<Ordered>,
6631}
6632
6633/// NTH_VALUE function
6634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6635#[cfg_attr(feature = "bindings", derive(TS))]
6636pub struct NthValueFunc {
6637    pub this: Expression,
6638    pub offset: Expression,
6639    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6640    #[serde(default, skip_serializing_if = "Option::is_none")]
6641    pub ignore_nulls: Option<bool>,
6642    /// Snowflake FROM FIRST / FROM LAST clause
6643    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6644    #[serde(default, skip_serializing_if = "Option::is_none")]
6645    pub from_first: Option<bool>,
6646}
6647
6648/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub struct PercentRank {
6652    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6653    #[serde(default, skip_serializing_if = "Option::is_none")]
6654    pub order_by: Option<Vec<Ordered>>,
6655    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6656    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6657    pub args: Vec<Expression>,
6658}
6659
6660/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6662#[cfg_attr(feature = "bindings", derive(TS))]
6663pub struct CumeDist {
6664    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6665    #[serde(default, skip_serializing_if = "Option::is_none")]
6666    pub order_by: Option<Vec<Ordered>>,
6667    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6668    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6669    pub args: Vec<Expression>,
6670}
6671
6672// ============================================================================
6673// Additional String Function types
6674// ============================================================================
6675
6676/// POSITION/INSTR function
6677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6678#[cfg_attr(feature = "bindings", derive(TS))]
6679pub struct PositionFunc {
6680    pub substring: Expression,
6681    pub string: Expression,
6682    pub start: Option<Expression>,
6683}
6684
6685// ============================================================================
6686// Additional Math Function types
6687// ============================================================================
6688
6689/// RANDOM function (no arguments)
6690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6691#[cfg_attr(feature = "bindings", derive(TS))]
6692pub struct Random;
6693
6694/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6696#[cfg_attr(feature = "bindings", derive(TS))]
6697pub struct Rand {
6698    pub seed: Option<Box<Expression>>,
6699    /// Teradata RANDOM lower bound
6700    #[serde(default)]
6701    pub lower: Option<Box<Expression>>,
6702    /// Teradata RANDOM upper bound
6703    #[serde(default)]
6704    pub upper: Option<Box<Expression>>,
6705}
6706
6707/// TRUNCATE / TRUNC function
6708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6709#[cfg_attr(feature = "bindings", derive(TS))]
6710pub struct TruncateFunc {
6711    pub this: Expression,
6712    pub decimals: Option<Expression>,
6713}
6714
6715/// PI function (no arguments)
6716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6717#[cfg_attr(feature = "bindings", derive(TS))]
6718pub struct Pi;
6719
6720// ============================================================================
6721// Control Flow Function types
6722// ============================================================================
6723
6724/// DECODE function (Oracle style)
6725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6726#[cfg_attr(feature = "bindings", derive(TS))]
6727pub struct DecodeFunc {
6728    pub this: Expression,
6729    pub search_results: Vec<(Expression, Expression)>,
6730    pub default: Option<Expression>,
6731}
6732
6733// ============================================================================
6734// Additional Date/Time Function types
6735// ============================================================================
6736
6737/// DATE_FORMAT / FORMAT_DATE function
6738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6739#[cfg_attr(feature = "bindings", derive(TS))]
6740pub struct DateFormatFunc {
6741    pub this: Expression,
6742    pub format: Expression,
6743}
6744
6745/// FROM_UNIXTIME function
6746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6747#[cfg_attr(feature = "bindings", derive(TS))]
6748pub struct FromUnixtimeFunc {
6749    pub this: Expression,
6750    pub format: Option<Expression>,
6751}
6752
6753/// UNIX_TIMESTAMP function
6754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6755#[cfg_attr(feature = "bindings", derive(TS))]
6756pub struct UnixTimestampFunc {
6757    pub this: Option<Expression>,
6758    pub format: Option<Expression>,
6759}
6760
6761/// MAKE_DATE function
6762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6763#[cfg_attr(feature = "bindings", derive(TS))]
6764pub struct MakeDateFunc {
6765    pub year: Expression,
6766    pub month: Expression,
6767    pub day: Expression,
6768}
6769
6770/// MAKE_TIMESTAMP function
6771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6772#[cfg_attr(feature = "bindings", derive(TS))]
6773pub struct MakeTimestampFunc {
6774    pub year: Expression,
6775    pub month: Expression,
6776    pub day: Expression,
6777    pub hour: Expression,
6778    pub minute: Expression,
6779    pub second: Expression,
6780    pub timezone: Option<Expression>,
6781}
6782
6783/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6785#[cfg_attr(feature = "bindings", derive(TS))]
6786pub struct LastDayFunc {
6787    pub this: Expression,
6788    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6789    #[serde(skip_serializing_if = "Option::is_none", default)]
6790    pub unit: Option<DateTimeField>,
6791}
6792
6793// ============================================================================
6794// Array Function types
6795// ============================================================================
6796
6797/// ARRAY constructor
6798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6799#[cfg_attr(feature = "bindings", derive(TS))]
6800pub struct ArrayConstructor {
6801    pub expressions: Vec<Expression>,
6802    pub bracket_notation: bool,
6803    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6804    pub use_list_keyword: bool,
6805}
6806
6807/// ARRAY_SORT function
6808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6809#[cfg_attr(feature = "bindings", derive(TS))]
6810pub struct ArraySortFunc {
6811    pub this: Expression,
6812    pub comparator: Option<Expression>,
6813    pub desc: bool,
6814    pub nulls_first: Option<bool>,
6815}
6816
6817/// ARRAY_JOIN / ARRAY_TO_STRING function
6818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6819#[cfg_attr(feature = "bindings", derive(TS))]
6820pub struct ArrayJoinFunc {
6821    pub this: Expression,
6822    pub separator: Expression,
6823    pub null_replacement: Option<Expression>,
6824}
6825
6826/// UNNEST function
6827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6828#[cfg_attr(feature = "bindings", derive(TS))]
6829pub struct UnnestFunc {
6830    pub this: Expression,
6831    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6832    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6833    pub expressions: Vec<Expression>,
6834    pub with_ordinality: bool,
6835    pub alias: Option<Identifier>,
6836    /// BigQuery: offset alias for WITH OFFSET AS <name>
6837    #[serde(default, skip_serializing_if = "Option::is_none")]
6838    pub offset_alias: Option<Identifier>,
6839}
6840
6841/// ARRAY_FILTER function (with lambda)
6842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6843#[cfg_attr(feature = "bindings", derive(TS))]
6844pub struct ArrayFilterFunc {
6845    pub this: Expression,
6846    pub filter: Expression,
6847}
6848
6849/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6851#[cfg_attr(feature = "bindings", derive(TS))]
6852pub struct ArrayTransformFunc {
6853    pub this: Expression,
6854    pub transform: Expression,
6855}
6856
6857/// SEQUENCE / GENERATE_SERIES function
6858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6859#[cfg_attr(feature = "bindings", derive(TS))]
6860pub struct SequenceFunc {
6861    pub start: Expression,
6862    pub stop: Expression,
6863    pub step: Option<Expression>,
6864}
6865
6866// ============================================================================
6867// Struct Function types
6868// ============================================================================
6869
6870/// STRUCT constructor
6871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6872#[cfg_attr(feature = "bindings", derive(TS))]
6873pub struct StructConstructor {
6874    pub fields: Vec<(Option<Identifier>, Expression)>,
6875}
6876
6877/// STRUCT_EXTRACT function
6878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6879#[cfg_attr(feature = "bindings", derive(TS))]
6880pub struct StructExtractFunc {
6881    pub this: Expression,
6882    pub field: Identifier,
6883}
6884
6885/// NAMED_STRUCT function
6886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6887#[cfg_attr(feature = "bindings", derive(TS))]
6888pub struct NamedStructFunc {
6889    pub pairs: Vec<(Expression, Expression)>,
6890}
6891
6892// ============================================================================
6893// Map Function types
6894// ============================================================================
6895
6896/// MAP constructor
6897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6898#[cfg_attr(feature = "bindings", derive(TS))]
6899pub struct MapConstructor {
6900    pub keys: Vec<Expression>,
6901    pub values: Vec<Expression>,
6902    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6903    #[serde(default)]
6904    pub curly_brace_syntax: bool,
6905    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6906    #[serde(default)]
6907    pub with_map_keyword: bool,
6908}
6909
6910/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6912#[cfg_attr(feature = "bindings", derive(TS))]
6913pub struct TransformFunc {
6914    pub this: Expression,
6915    pub transform: Expression,
6916}
6917
6918/// Function call with EMITS clause (Exasol)
6919/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6921#[cfg_attr(feature = "bindings", derive(TS))]
6922pub struct FunctionEmits {
6923    /// The function call expression
6924    pub this: Expression,
6925    /// The EMITS schema definition
6926    pub emits: Expression,
6927}
6928
6929// ============================================================================
6930// JSON Function types
6931// ============================================================================
6932
6933/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6935#[cfg_attr(feature = "bindings", derive(TS))]
6936pub struct JsonExtractFunc {
6937    pub this: Expression,
6938    pub path: Expression,
6939    pub returning: Option<DataType>,
6940    /// True if parsed from -> or ->> operator syntax
6941    #[serde(default)]
6942    pub arrow_syntax: bool,
6943    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6944    #[serde(default)]
6945    pub hash_arrow_syntax: bool,
6946    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6947    #[serde(default)]
6948    pub wrapper_option: Option<String>,
6949    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6950    #[serde(default)]
6951    pub quotes_option: Option<String>,
6952    /// ON SCALAR STRING flag
6953    #[serde(default)]
6954    pub on_scalar_string: bool,
6955    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6956    #[serde(default)]
6957    pub on_error: Option<String>,
6958}
6959
6960/// JSON path extraction
6961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6962#[cfg_attr(feature = "bindings", derive(TS))]
6963pub struct JsonPathFunc {
6964    pub this: Expression,
6965    pub paths: Vec<Expression>,
6966}
6967
6968/// JSON_OBJECT function
6969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6970#[cfg_attr(feature = "bindings", derive(TS))]
6971pub struct JsonObjectFunc {
6972    pub pairs: Vec<(Expression, Expression)>,
6973    pub null_handling: Option<JsonNullHandling>,
6974    #[serde(default)]
6975    pub with_unique_keys: bool,
6976    #[serde(default)]
6977    pub returning_type: Option<DataType>,
6978    #[serde(default)]
6979    pub format_json: bool,
6980    #[serde(default)]
6981    pub encoding: Option<String>,
6982    /// For JSON_OBJECT(*) syntax
6983    #[serde(default)]
6984    pub star: bool,
6985}
6986
6987/// JSON null handling options
6988#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6989#[cfg_attr(feature = "bindings", derive(TS))]
6990pub enum JsonNullHandling {
6991    NullOnNull,
6992    AbsentOnNull,
6993}
6994
6995/// JSON_SET / JSON_INSERT function
6996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6997#[cfg_attr(feature = "bindings", derive(TS))]
6998pub struct JsonModifyFunc {
6999    pub this: Expression,
7000    pub path_values: Vec<(Expression, Expression)>,
7001}
7002
7003/// JSON_ARRAYAGG function
7004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7005#[cfg_attr(feature = "bindings", derive(TS))]
7006pub struct JsonArrayAggFunc {
7007    pub this: Expression,
7008    pub order_by: Option<Vec<Ordered>>,
7009    pub null_handling: Option<JsonNullHandling>,
7010    pub filter: Option<Expression>,
7011}
7012
7013/// JSON_OBJECTAGG function
7014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7015#[cfg_attr(feature = "bindings", derive(TS))]
7016pub struct JsonObjectAggFunc {
7017    pub key: Expression,
7018    pub value: Expression,
7019    pub null_handling: Option<JsonNullHandling>,
7020    pub filter: Option<Expression>,
7021}
7022
7023// ============================================================================
7024// Type Casting Function types
7025// ============================================================================
7026
7027/// CONVERT function (SQL Server style)
7028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7029#[cfg_attr(feature = "bindings", derive(TS))]
7030pub struct ConvertFunc {
7031    pub this: Expression,
7032    pub to: DataType,
7033    pub style: Option<Expression>,
7034}
7035
7036// ============================================================================
7037// Additional Expression types
7038// ============================================================================
7039
7040/// Lambda expression
7041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7042#[cfg_attr(feature = "bindings", derive(TS))]
7043pub struct LambdaExpr {
7044    pub parameters: Vec<Identifier>,
7045    pub body: Expression,
7046    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7047    #[serde(default)]
7048    pub colon: bool,
7049    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7050    /// Maps parameter index to data type
7051    #[serde(default)]
7052    pub parameter_types: Vec<Option<DataType>>,
7053}
7054
7055/// Parameter (parameterized queries)
7056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7057#[cfg_attr(feature = "bindings", derive(TS))]
7058pub struct Parameter {
7059    pub name: Option<String>,
7060    pub index: Option<u32>,
7061    pub style: ParameterStyle,
7062    /// Whether the name was quoted (e.g., @"x" vs @x)
7063    #[serde(default)]
7064    pub quoted: bool,
7065    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7066    #[serde(default)]
7067    pub string_quoted: bool,
7068    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7069    #[serde(default)]
7070    pub expression: Option<String>,
7071}
7072
7073/// Parameter placeholder styles
7074#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7075#[cfg_attr(feature = "bindings", derive(TS))]
7076pub enum ParameterStyle {
7077    Question,     // ?
7078    Dollar,       // $1, $2
7079    DollarBrace,  // ${name} (Databricks, Hive template variables)
7080    Brace,        // {name} (Spark/Databricks widget/template variables)
7081    Colon,        // :name
7082    At,           // @name
7083    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7084    DoubleDollar, // $$name
7085    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7086}
7087
7088/// Placeholder expression
7089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7090#[cfg_attr(feature = "bindings", derive(TS))]
7091pub struct Placeholder {
7092    pub index: Option<u32>,
7093}
7094
7095/// Named argument in function call: name => value or name := value
7096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7097#[cfg_attr(feature = "bindings", derive(TS))]
7098pub struct NamedArgument {
7099    pub name: Identifier,
7100    pub value: Expression,
7101    /// The separator used: `=>`, `:=`, or `=`
7102    pub separator: NamedArgSeparator,
7103}
7104
7105/// Separator style for named arguments
7106#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7107#[cfg_attr(feature = "bindings", derive(TS))]
7108pub enum NamedArgSeparator {
7109    /// `=>` (standard SQL, Snowflake, BigQuery)
7110    DArrow,
7111    /// `:=` (Oracle, MySQL)
7112    ColonEq,
7113    /// `=` (simple equals, some dialects)
7114    Eq,
7115}
7116
7117/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7118/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7120#[cfg_attr(feature = "bindings", derive(TS))]
7121pub struct TableArgument {
7122    /// The keyword prefix: "TABLE" or "MODEL"
7123    pub prefix: String,
7124    /// The table/model reference expression
7125    pub this: Expression,
7126}
7127
7128/// SQL Comment preservation
7129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7130#[cfg_attr(feature = "bindings", derive(TS))]
7131pub struct SqlComment {
7132    pub text: String,
7133    pub is_block: bool,
7134}
7135
7136// ============================================================================
7137// Additional Predicate types
7138// ============================================================================
7139
7140/// SIMILAR TO expression
7141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7142#[cfg_attr(feature = "bindings", derive(TS))]
7143pub struct SimilarToExpr {
7144    pub this: Expression,
7145    pub pattern: Expression,
7146    pub escape: Option<Expression>,
7147    pub not: bool,
7148}
7149
7150/// ANY / ALL quantified expression
7151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7152#[cfg_attr(feature = "bindings", derive(TS))]
7153pub struct QuantifiedExpr {
7154    pub this: Expression,
7155    pub subquery: Expression,
7156    pub op: Option<QuantifiedOp>,
7157}
7158
7159/// Comparison operator for quantified expressions
7160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7161#[cfg_attr(feature = "bindings", derive(TS))]
7162pub enum QuantifiedOp {
7163    Eq,
7164    Neq,
7165    Lt,
7166    Lte,
7167    Gt,
7168    Gte,
7169}
7170
7171/// OVERLAPS expression
7172/// Supports two forms:
7173/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7174/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7176#[cfg_attr(feature = "bindings", derive(TS))]
7177pub struct OverlapsExpr {
7178    /// Left operand for simple binary form
7179    #[serde(skip_serializing_if = "Option::is_none")]
7180    pub this: Option<Expression>,
7181    /// Right operand for simple binary form
7182    #[serde(skip_serializing_if = "Option::is_none")]
7183    pub expression: Option<Expression>,
7184    /// Left range start for full ANSI form
7185    #[serde(skip_serializing_if = "Option::is_none")]
7186    pub left_start: Option<Expression>,
7187    /// Left range end for full ANSI form
7188    #[serde(skip_serializing_if = "Option::is_none")]
7189    pub left_end: Option<Expression>,
7190    /// Right range start for full ANSI form
7191    #[serde(skip_serializing_if = "Option::is_none")]
7192    pub right_start: Option<Expression>,
7193    /// Right range end for full ANSI form
7194    #[serde(skip_serializing_if = "Option::is_none")]
7195    pub right_end: Option<Expression>,
7196}
7197
7198// ============================================================================
7199// Array/Struct/Map access
7200// ============================================================================
7201
7202/// Subscript access (array[index] or map[key])
7203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7204#[cfg_attr(feature = "bindings", derive(TS))]
7205pub struct Subscript {
7206    pub this: Expression,
7207    pub index: Expression,
7208}
7209
7210/// Dot access (struct.field)
7211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7212#[cfg_attr(feature = "bindings", derive(TS))]
7213pub struct DotAccess {
7214    pub this: Expression,
7215    pub field: Identifier,
7216}
7217
7218/// Method call (expr.method(args))
7219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7220#[cfg_attr(feature = "bindings", derive(TS))]
7221pub struct MethodCall {
7222    pub this: Expression,
7223    pub method: Identifier,
7224    pub args: Vec<Expression>,
7225}
7226
7227/// Array slice (array[start:end])
7228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7229#[cfg_attr(feature = "bindings", derive(TS))]
7230pub struct ArraySlice {
7231    pub this: Expression,
7232    pub start: Option<Expression>,
7233    pub end: Option<Expression>,
7234}
7235
7236// ============================================================================
7237// DDL (Data Definition Language) Statements
7238// ============================================================================
7239
7240/// ON COMMIT behavior for temporary tables
7241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7242#[cfg_attr(feature = "bindings", derive(TS))]
7243pub enum OnCommit {
7244    /// ON COMMIT PRESERVE ROWS
7245    PreserveRows,
7246    /// ON COMMIT DELETE ROWS
7247    DeleteRows,
7248}
7249
7250/// CREATE TABLE statement
7251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7252#[cfg_attr(feature = "bindings", derive(TS))]
7253pub struct CreateTable {
7254    pub name: TableRef,
7255    /// ClickHouse: ON CLUSTER clause for distributed DDL
7256    #[serde(default, skip_serializing_if = "Option::is_none")]
7257    pub on_cluster: Option<OnCluster>,
7258    pub columns: Vec<ColumnDef>,
7259    pub constraints: Vec<TableConstraint>,
7260    pub if_not_exists: bool,
7261    pub temporary: bool,
7262    pub or_replace: bool,
7263    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7264    #[serde(default, skip_serializing_if = "Option::is_none")]
7265    pub table_modifier: Option<String>,
7266    pub as_select: Option<Expression>,
7267    /// Whether the AS SELECT was wrapped in parentheses
7268    #[serde(default)]
7269    pub as_select_parenthesized: bool,
7270    /// ON COMMIT behavior for temporary tables
7271    #[serde(default)]
7272    pub on_commit: Option<OnCommit>,
7273    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7274    #[serde(default)]
7275    pub clone_source: Option<TableRef>,
7276    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7277    #[serde(default, skip_serializing_if = "Option::is_none")]
7278    pub clone_at_clause: Option<Expression>,
7279    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7280    #[serde(default)]
7281    pub is_copy: bool,
7282    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7283    #[serde(default)]
7284    pub shallow_clone: bool,
7285    /// Leading comments before the statement
7286    #[serde(default)]
7287    pub leading_comments: Vec<String>,
7288    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7289    #[serde(default)]
7290    pub with_properties: Vec<(String, String)>,
7291    /// Teradata: table options after name before columns (comma-separated)
7292    #[serde(default)]
7293    pub teradata_post_name_options: Vec<String>,
7294    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7295    #[serde(default)]
7296    pub with_data: Option<bool>,
7297    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7298    #[serde(default)]
7299    pub with_statistics: Option<bool>,
7300    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7301    #[serde(default)]
7302    pub teradata_indexes: Vec<TeradataIndex>,
7303    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7304    #[serde(default)]
7305    pub with_cte: Option<With>,
7306    /// Table properties like DEFAULT COLLATE (BigQuery)
7307    #[serde(default)]
7308    pub properties: Vec<Expression>,
7309    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7310    #[serde(default, skip_serializing_if = "Option::is_none")]
7311    pub partition_of: Option<Expression>,
7312    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7313    #[serde(default)]
7314    pub post_table_properties: Vec<Expression>,
7315    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7316    #[serde(default)]
7317    pub mysql_table_options: Vec<(String, String)>,
7318    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7319    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7320    pub inherits: Vec<TableRef>,
7321    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7322    #[serde(default, skip_serializing_if = "Option::is_none")]
7323    pub on_property: Option<OnProperty>,
7324    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7325    #[serde(default)]
7326    pub copy_grants: bool,
7327    /// Snowflake: USING TEMPLATE expression for schema inference
7328    #[serde(default, skip_serializing_if = "Option::is_none")]
7329    pub using_template: Option<Box<Expression>>,
7330    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7331    #[serde(default, skip_serializing_if = "Option::is_none")]
7332    pub rollup: Option<RollupProperty>,
7333    /// ClickHouse: UUID 'xxx' clause after table name
7334    #[serde(default, skip_serializing_if = "Option::is_none")]
7335    pub uuid: Option<String>,
7336}
7337
7338/// Teradata index specification for CREATE TABLE
7339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7340#[cfg_attr(feature = "bindings", derive(TS))]
7341pub struct TeradataIndex {
7342    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7343    pub kind: TeradataIndexKind,
7344    /// Optional index name
7345    pub name: Option<String>,
7346    /// Optional column list
7347    pub columns: Vec<String>,
7348}
7349
7350/// Kind of Teradata index
7351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7352#[cfg_attr(feature = "bindings", derive(TS))]
7353pub enum TeradataIndexKind {
7354    /// NO PRIMARY INDEX
7355    NoPrimary,
7356    /// PRIMARY INDEX
7357    Primary,
7358    /// PRIMARY AMP INDEX
7359    PrimaryAmp,
7360    /// UNIQUE INDEX
7361    Unique,
7362    /// UNIQUE PRIMARY INDEX
7363    UniquePrimary,
7364    /// INDEX (secondary, non-primary)
7365    Secondary,
7366}
7367
7368impl CreateTable {
7369    pub fn new(name: impl Into<String>) -> Self {
7370        Self {
7371            name: TableRef::new(name),
7372            on_cluster: None,
7373            columns: Vec::new(),
7374            constraints: Vec::new(),
7375            if_not_exists: false,
7376            temporary: false,
7377            or_replace: false,
7378            table_modifier: None,
7379            as_select: None,
7380            as_select_parenthesized: false,
7381            on_commit: None,
7382            clone_source: None,
7383            clone_at_clause: None,
7384            shallow_clone: false,
7385            is_copy: false,
7386            leading_comments: Vec::new(),
7387            with_properties: Vec::new(),
7388            teradata_post_name_options: Vec::new(),
7389            with_data: None,
7390            with_statistics: None,
7391            teradata_indexes: Vec::new(),
7392            with_cte: None,
7393            properties: Vec::new(),
7394            partition_of: None,
7395            post_table_properties: Vec::new(),
7396            mysql_table_options: Vec::new(),
7397            inherits: Vec::new(),
7398            on_property: None,
7399            copy_grants: false,
7400            using_template: None,
7401            rollup: None,
7402            uuid: None,
7403        }
7404    }
7405}
7406
7407/// Sort order for PRIMARY KEY ASC/DESC
7408#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7409#[cfg_attr(feature = "bindings", derive(TS))]
7410pub enum SortOrder {
7411    Asc,
7412    Desc,
7413}
7414
7415/// Type of column constraint for tracking order
7416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7417#[cfg_attr(feature = "bindings", derive(TS))]
7418pub enum ConstraintType {
7419    NotNull,
7420    Null,
7421    PrimaryKey,
7422    Unique,
7423    Default,
7424    AutoIncrement,
7425    Collate,
7426    Comment,
7427    References,
7428    Check,
7429    GeneratedAsIdentity,
7430    /// Snowflake: TAG (key='value', ...)
7431    Tags,
7432    /// Computed/generated column
7433    ComputedColumn,
7434    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7435    GeneratedAsRow,
7436    /// MySQL: ON UPDATE expression
7437    OnUpdate,
7438    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7439    Path,
7440    /// Redshift: ENCODE encoding_type
7441    Encode,
7442}
7443
7444/// Column definition in CREATE TABLE
7445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7446#[cfg_attr(feature = "bindings", derive(TS))]
7447pub struct ColumnDef {
7448    pub name: Identifier,
7449    pub data_type: DataType,
7450    pub nullable: Option<bool>,
7451    pub default: Option<Expression>,
7452    pub primary_key: bool,
7453    /// Sort order for PRIMARY KEY (ASC/DESC)
7454    #[serde(default)]
7455    pub primary_key_order: Option<SortOrder>,
7456    pub unique: bool,
7457    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7458    #[serde(default)]
7459    pub unique_nulls_not_distinct: bool,
7460    pub auto_increment: bool,
7461    pub comment: Option<String>,
7462    pub constraints: Vec<ColumnConstraint>,
7463    /// Track original order of constraints for accurate regeneration
7464    #[serde(default)]
7465    pub constraint_order: Vec<ConstraintType>,
7466    /// Teradata: FORMAT 'pattern'
7467    #[serde(default)]
7468    pub format: Option<String>,
7469    /// Teradata: TITLE 'title'
7470    #[serde(default)]
7471    pub title: Option<String>,
7472    /// Teradata: INLINE LENGTH n
7473    #[serde(default)]
7474    pub inline_length: Option<u64>,
7475    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7476    #[serde(default)]
7477    pub compress: Option<Vec<Expression>>,
7478    /// Teradata: CHARACTER SET name
7479    #[serde(default)]
7480    pub character_set: Option<String>,
7481    /// Teradata: UPPERCASE
7482    #[serde(default)]
7483    pub uppercase: bool,
7484    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7485    #[serde(default)]
7486    pub casespecific: Option<bool>,
7487    /// Snowflake: AUTOINCREMENT START value
7488    #[serde(default)]
7489    pub auto_increment_start: Option<Box<Expression>>,
7490    /// Snowflake: AUTOINCREMENT INCREMENT value
7491    #[serde(default)]
7492    pub auto_increment_increment: Option<Box<Expression>>,
7493    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7494    #[serde(default)]
7495    pub auto_increment_order: Option<bool>,
7496    /// MySQL: UNSIGNED modifier
7497    #[serde(default)]
7498    pub unsigned: bool,
7499    /// MySQL: ZEROFILL modifier
7500    #[serde(default)]
7501    pub zerofill: bool,
7502    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7503    #[serde(default, skip_serializing_if = "Option::is_none")]
7504    pub on_update: Option<Expression>,
7505    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7506    #[serde(default, skip_serializing_if = "Option::is_none")]
7507    pub unique_constraint_name: Option<String>,
7508    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7509    #[serde(default, skip_serializing_if = "Option::is_none")]
7510    pub not_null_constraint_name: Option<String>,
7511    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7512    #[serde(default, skip_serializing_if = "Option::is_none")]
7513    pub primary_key_constraint_name: Option<String>,
7514    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7515    #[serde(default, skip_serializing_if = "Option::is_none")]
7516    pub check_constraint_name: Option<String>,
7517    /// BigQuery: OPTIONS (key=value, ...) on column
7518    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7519    pub options: Vec<Expression>,
7520    /// SQLite: Column definition without explicit type
7521    #[serde(default)]
7522    pub no_type: bool,
7523    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7524    #[serde(default, skip_serializing_if = "Option::is_none")]
7525    pub encoding: Option<String>,
7526    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7527    #[serde(default, skip_serializing_if = "Option::is_none")]
7528    pub codec: Option<String>,
7529    /// ClickHouse: EPHEMERAL [expr] modifier
7530    #[serde(default, skip_serializing_if = "Option::is_none")]
7531    pub ephemeral: Option<Option<Box<Expression>>>,
7532    /// ClickHouse: MATERIALIZED expr modifier
7533    #[serde(default, skip_serializing_if = "Option::is_none")]
7534    pub materialized_expr: Option<Box<Expression>>,
7535    /// ClickHouse: ALIAS expr modifier
7536    #[serde(default, skip_serializing_if = "Option::is_none")]
7537    pub alias_expr: Option<Box<Expression>>,
7538    /// ClickHouse: TTL expr modifier on columns
7539    #[serde(default, skip_serializing_if = "Option::is_none")]
7540    pub ttl_expr: Option<Box<Expression>>,
7541    /// TSQL: NOT FOR REPLICATION
7542    #[serde(default)]
7543    pub not_for_replication: bool,
7544}
7545
7546impl ColumnDef {
7547    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7548        Self {
7549            name: Identifier::new(name),
7550            data_type,
7551            nullable: None,
7552            default: None,
7553            primary_key: false,
7554            primary_key_order: None,
7555            unique: false,
7556            unique_nulls_not_distinct: false,
7557            auto_increment: false,
7558            comment: None,
7559            constraints: Vec::new(),
7560            constraint_order: Vec::new(),
7561            format: None,
7562            title: None,
7563            inline_length: None,
7564            compress: None,
7565            character_set: None,
7566            uppercase: false,
7567            casespecific: None,
7568            auto_increment_start: None,
7569            auto_increment_increment: None,
7570            auto_increment_order: None,
7571            unsigned: false,
7572            zerofill: false,
7573            on_update: None,
7574            unique_constraint_name: None,
7575            not_null_constraint_name: None,
7576            primary_key_constraint_name: None,
7577            check_constraint_name: None,
7578            options: Vec::new(),
7579            no_type: false,
7580            encoding: None,
7581            codec: None,
7582            ephemeral: None,
7583            materialized_expr: None,
7584            alias_expr: None,
7585            ttl_expr: None,
7586            not_for_replication: false,
7587        }
7588    }
7589}
7590
7591/// Column-level constraint
7592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7593#[cfg_attr(feature = "bindings", derive(TS))]
7594pub enum ColumnConstraint {
7595    NotNull,
7596    Null,
7597    Unique,
7598    PrimaryKey,
7599    Default(Expression),
7600    Check(Expression),
7601    References(ForeignKeyRef),
7602    GeneratedAsIdentity(GeneratedAsIdentity),
7603    Collate(Identifier),
7604    Comment(String),
7605    /// Snowflake: TAG (key='value', ...)
7606    Tags(Tags),
7607    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7608    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7609    ComputedColumn(ComputedColumn),
7610    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7611    GeneratedAsRow(GeneratedAsRow),
7612    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7613    Path(Expression),
7614}
7615
7616/// Computed/generated column constraint
7617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7618#[cfg_attr(feature = "bindings", derive(TS))]
7619pub struct ComputedColumn {
7620    /// The expression that computes the column value
7621    pub expression: Box<Expression>,
7622    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7623    #[serde(default)]
7624    pub persisted: bool,
7625    /// NOT NULL (TSQL computed columns)
7626    #[serde(default)]
7627    pub not_null: bool,
7628    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7629    /// When None, defaults to dialect-appropriate output
7630    #[serde(default)]
7631    pub persistence_kind: Option<String>,
7632    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7633    #[serde(default, skip_serializing_if = "Option::is_none")]
7634    pub data_type: Option<DataType>,
7635}
7636
7637/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7639#[cfg_attr(feature = "bindings", derive(TS))]
7640pub struct GeneratedAsRow {
7641    /// true = ROW START, false = ROW END
7642    pub start: bool,
7643    /// HIDDEN modifier
7644    #[serde(default)]
7645    pub hidden: bool,
7646}
7647
7648/// Generated identity column constraint
7649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7650#[cfg_attr(feature = "bindings", derive(TS))]
7651pub struct GeneratedAsIdentity {
7652    /// True for ALWAYS, False for BY DEFAULT
7653    pub always: bool,
7654    /// ON NULL (only valid with BY DEFAULT)
7655    pub on_null: bool,
7656    /// START WITH value
7657    pub start: Option<Box<Expression>>,
7658    /// INCREMENT BY value
7659    pub increment: Option<Box<Expression>>,
7660    /// MINVALUE
7661    pub minvalue: Option<Box<Expression>>,
7662    /// MAXVALUE
7663    pub maxvalue: Option<Box<Expression>>,
7664    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7665    pub cycle: Option<bool>,
7666}
7667
7668/// Constraint modifiers (shared between table-level constraints)
7669#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7670#[cfg_attr(feature = "bindings", derive(TS))]
7671pub struct ConstraintModifiers {
7672    /// ENFORCED / NOT ENFORCED
7673    pub enforced: Option<bool>,
7674    /// DEFERRABLE / NOT DEFERRABLE
7675    pub deferrable: Option<bool>,
7676    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7677    pub initially_deferred: Option<bool>,
7678    /// NORELY (Oracle)
7679    pub norely: bool,
7680    /// RELY (Oracle)
7681    pub rely: bool,
7682    /// USING index type (MySQL): BTREE or HASH
7683    #[serde(default)]
7684    pub using: Option<String>,
7685    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7686    #[serde(default)]
7687    pub using_before_columns: bool,
7688    /// MySQL index COMMENT 'text'
7689    #[serde(default, skip_serializing_if = "Option::is_none")]
7690    pub comment: Option<String>,
7691    /// MySQL index VISIBLE/INVISIBLE
7692    #[serde(default, skip_serializing_if = "Option::is_none")]
7693    pub visible: Option<bool>,
7694    /// MySQL ENGINE_ATTRIBUTE = 'value'
7695    #[serde(default, skip_serializing_if = "Option::is_none")]
7696    pub engine_attribute: Option<String>,
7697    /// MySQL WITH PARSER name
7698    #[serde(default, skip_serializing_if = "Option::is_none")]
7699    pub with_parser: Option<String>,
7700    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7701    #[serde(default)]
7702    pub not_valid: bool,
7703    /// TSQL CLUSTERED/NONCLUSTERED modifier
7704    #[serde(default, skip_serializing_if = "Option::is_none")]
7705    pub clustered: Option<String>,
7706    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7707    #[serde(default, skip_serializing_if = "Option::is_none")]
7708    pub on_conflict: Option<String>,
7709    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7710    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7711    pub with_options: Vec<(String, String)>,
7712    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7713    #[serde(default, skip_serializing_if = "Option::is_none")]
7714    pub on_filegroup: Option<Identifier>,
7715}
7716
7717/// Table-level constraint
7718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7719#[cfg_attr(feature = "bindings", derive(TS))]
7720pub enum TableConstraint {
7721    PrimaryKey {
7722        name: Option<Identifier>,
7723        columns: Vec<Identifier>,
7724        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7725        #[serde(default)]
7726        include_columns: Vec<Identifier>,
7727        #[serde(default)]
7728        modifiers: ConstraintModifiers,
7729        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7730        #[serde(default)]
7731        has_constraint_keyword: bool,
7732    },
7733    Unique {
7734        name: Option<Identifier>,
7735        columns: Vec<Identifier>,
7736        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7737        #[serde(default)]
7738        columns_parenthesized: bool,
7739        #[serde(default)]
7740        modifiers: ConstraintModifiers,
7741        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7742        #[serde(default)]
7743        has_constraint_keyword: bool,
7744        /// PostgreSQL 15+: NULLS NOT DISTINCT
7745        #[serde(default)]
7746        nulls_not_distinct: bool,
7747    },
7748    ForeignKey {
7749        name: Option<Identifier>,
7750        columns: Vec<Identifier>,
7751        #[serde(default)]
7752        references: Option<ForeignKeyRef>,
7753        /// ON DELETE action when REFERENCES is absent
7754        #[serde(default)]
7755        on_delete: Option<ReferentialAction>,
7756        /// ON UPDATE action when REFERENCES is absent
7757        #[serde(default)]
7758        on_update: Option<ReferentialAction>,
7759        #[serde(default)]
7760        modifiers: ConstraintModifiers,
7761    },
7762    Check {
7763        name: Option<Identifier>,
7764        expression: Expression,
7765        #[serde(default)]
7766        modifiers: ConstraintModifiers,
7767    },
7768    /// ClickHouse ASSUME constraint (query optimization assumption)
7769    Assume {
7770        name: Option<Identifier>,
7771        expression: Expression,
7772    },
7773    /// INDEX / KEY constraint (MySQL)
7774    Index {
7775        name: Option<Identifier>,
7776        columns: Vec<Identifier>,
7777        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7778        #[serde(default)]
7779        kind: Option<String>,
7780        #[serde(default)]
7781        modifiers: ConstraintModifiers,
7782        /// True if KEY keyword was used instead of INDEX
7783        #[serde(default)]
7784        use_key_keyword: bool,
7785        /// ClickHouse: indexed expression (instead of columns)
7786        #[serde(default, skip_serializing_if = "Option::is_none")]
7787        expression: Option<Box<Expression>>,
7788        /// ClickHouse: TYPE type_func(args)
7789        #[serde(default, skip_serializing_if = "Option::is_none")]
7790        index_type: Option<Box<Expression>>,
7791        /// ClickHouse: GRANULARITY n
7792        #[serde(default, skip_serializing_if = "Option::is_none")]
7793        granularity: Option<Box<Expression>>,
7794    },
7795    /// ClickHouse PROJECTION definition
7796    Projection {
7797        name: Identifier,
7798        expression: Expression,
7799    },
7800    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7801    Like {
7802        source: TableRef,
7803        /// Options as (INCLUDING|EXCLUDING, property) pairs
7804        options: Vec<(LikeOptionAction, String)>,
7805    },
7806    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7807    PeriodForSystemTime {
7808        start_col: Identifier,
7809        end_col: Identifier,
7810    },
7811    /// PostgreSQL EXCLUDE constraint
7812    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7813    Exclude {
7814        name: Option<Identifier>,
7815        /// Index access method (gist, btree, etc.)
7816        #[serde(default)]
7817        using: Option<String>,
7818        /// Elements: (expression, operator) pairs
7819        elements: Vec<ExcludeElement>,
7820        /// INCLUDE columns
7821        #[serde(default)]
7822        include_columns: Vec<Identifier>,
7823        /// WHERE predicate
7824        #[serde(default)]
7825        where_clause: Option<Box<Expression>>,
7826        /// WITH (storage_parameters)
7827        #[serde(default)]
7828        with_params: Vec<(String, String)>,
7829        /// USING INDEX TABLESPACE tablespace_name
7830        #[serde(default)]
7831        using_index_tablespace: Option<String>,
7832        #[serde(default)]
7833        modifiers: ConstraintModifiers,
7834    },
7835    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7836    Tags(Tags),
7837    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7838    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7839    /// for all deferrable constraints in the table
7840    InitiallyDeferred {
7841        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7842        deferred: bool,
7843    },
7844}
7845
7846/// Element in an EXCLUDE constraint: expression WITH operator
7847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7848#[cfg_attr(feature = "bindings", derive(TS))]
7849pub struct ExcludeElement {
7850    /// The column expression (may include operator class, ordering, nulls)
7851    pub expression: String,
7852    /// The operator (e.g., &&, =)
7853    pub operator: String,
7854}
7855
7856/// Action for LIKE clause options
7857#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7858#[cfg_attr(feature = "bindings", derive(TS))]
7859pub enum LikeOptionAction {
7860    Including,
7861    Excluding,
7862}
7863
7864/// MATCH type for foreign keys
7865#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7866#[cfg_attr(feature = "bindings", derive(TS))]
7867pub enum MatchType {
7868    Full,
7869    Partial,
7870    Simple,
7871}
7872
7873/// Foreign key reference
7874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7875#[cfg_attr(feature = "bindings", derive(TS))]
7876pub struct ForeignKeyRef {
7877    pub table: TableRef,
7878    pub columns: Vec<Identifier>,
7879    pub on_delete: Option<ReferentialAction>,
7880    pub on_update: Option<ReferentialAction>,
7881    /// True if ON UPDATE appears before ON DELETE in the original SQL
7882    #[serde(default)]
7883    pub on_update_first: bool,
7884    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7885    #[serde(default)]
7886    pub match_type: Option<MatchType>,
7887    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7888    #[serde(default)]
7889    pub match_after_actions: bool,
7890    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7891    #[serde(default)]
7892    pub constraint_name: Option<String>,
7893    /// DEFERRABLE / NOT DEFERRABLE
7894    #[serde(default)]
7895    pub deferrable: Option<bool>,
7896    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7897    #[serde(default)]
7898    pub has_foreign_key_keywords: bool,
7899}
7900
7901/// Referential action for foreign keys
7902#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7903#[cfg_attr(feature = "bindings", derive(TS))]
7904pub enum ReferentialAction {
7905    Cascade,
7906    SetNull,
7907    SetDefault,
7908    Restrict,
7909    NoAction,
7910}
7911
7912/// DROP TABLE statement
7913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7914#[cfg_attr(feature = "bindings", derive(TS))]
7915pub struct DropTable {
7916    pub names: Vec<TableRef>,
7917    pub if_exists: bool,
7918    pub cascade: bool,
7919    /// Oracle: CASCADE CONSTRAINTS
7920    #[serde(default)]
7921    pub cascade_constraints: bool,
7922    /// Oracle: PURGE
7923    #[serde(default)]
7924    pub purge: bool,
7925    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7926    #[serde(default)]
7927    pub leading_comments: Vec<String>,
7928    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7929    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7930    #[serde(default, skip_serializing_if = "Option::is_none")]
7931    pub object_id_args: Option<String>,
7932    /// ClickHouse: SYNC modifier
7933    #[serde(default)]
7934    pub sync: bool,
7935    /// Snowflake: DROP ICEBERG TABLE
7936    #[serde(default)]
7937    pub iceberg: bool,
7938    /// RESTRICT modifier (opposite of CASCADE)
7939    #[serde(default)]
7940    pub restrict: bool,
7941}
7942
7943impl DropTable {
7944    pub fn new(name: impl Into<String>) -> Self {
7945        Self {
7946            names: vec![TableRef::new(name)],
7947            if_exists: false,
7948            cascade: false,
7949            cascade_constraints: false,
7950            purge: false,
7951            leading_comments: Vec::new(),
7952            object_id_args: None,
7953            sync: false,
7954            iceberg: false,
7955            restrict: false,
7956        }
7957    }
7958}
7959
7960/// ALTER TABLE statement
7961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7962#[cfg_attr(feature = "bindings", derive(TS))]
7963pub struct AlterTable {
7964    pub name: TableRef,
7965    pub actions: Vec<AlterTableAction>,
7966    /// IF EXISTS clause
7967    #[serde(default)]
7968    pub if_exists: bool,
7969    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
7970    #[serde(default, skip_serializing_if = "Option::is_none")]
7971    pub algorithm: Option<String>,
7972    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
7973    #[serde(default, skip_serializing_if = "Option::is_none")]
7974    pub lock: Option<String>,
7975    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
7976    #[serde(default, skip_serializing_if = "Option::is_none")]
7977    pub with_check: Option<String>,
7978    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
7979    #[serde(default, skip_serializing_if = "Option::is_none")]
7980    pub partition: Option<Vec<(Identifier, Expression)>>,
7981    /// ClickHouse: ON CLUSTER clause for distributed DDL
7982    #[serde(default, skip_serializing_if = "Option::is_none")]
7983    pub on_cluster: Option<OnCluster>,
7984    /// Snowflake: ALTER ICEBERG TABLE
7985    #[serde(default, skip_serializing_if = "Option::is_none")]
7986    pub table_modifier: Option<String>,
7987}
7988
7989impl AlterTable {
7990    pub fn new(name: impl Into<String>) -> Self {
7991        Self {
7992            name: TableRef::new(name),
7993            actions: Vec::new(),
7994            if_exists: false,
7995            algorithm: None,
7996            lock: None,
7997            with_check: None,
7998            partition: None,
7999            on_cluster: None,
8000            table_modifier: None,
8001        }
8002    }
8003}
8004
8005/// Column position for ADD COLUMN (MySQL/MariaDB)
8006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8007#[cfg_attr(feature = "bindings", derive(TS))]
8008pub enum ColumnPosition {
8009    First,
8010    After(Identifier),
8011}
8012
8013/// Actions for ALTER TABLE
8014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8015#[cfg_attr(feature = "bindings", derive(TS))]
8016pub enum AlterTableAction {
8017    AddColumn {
8018        column: ColumnDef,
8019        if_not_exists: bool,
8020        position: Option<ColumnPosition>,
8021    },
8022    DropColumn {
8023        name: Identifier,
8024        if_exists: bool,
8025        cascade: bool,
8026    },
8027    RenameColumn {
8028        old_name: Identifier,
8029        new_name: Identifier,
8030        if_exists: bool,
8031    },
8032    AlterColumn {
8033        name: Identifier,
8034        action: AlterColumnAction,
8035        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8036        #[serde(default)]
8037        use_modify_keyword: bool,
8038    },
8039    RenameTable(TableRef),
8040    AddConstraint(TableConstraint),
8041    DropConstraint {
8042        name: Identifier,
8043        if_exists: bool,
8044    },
8045    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8046    DropForeignKey {
8047        name: Identifier,
8048    },
8049    /// DROP PARTITION action (Hive/BigQuery)
8050    DropPartition {
8051        /// List of partitions to drop (each partition is a list of key=value pairs)
8052        partitions: Vec<Vec<(Identifier, Expression)>>,
8053        if_exists: bool,
8054    },
8055    /// ADD PARTITION action (Hive/Spark)
8056    AddPartition {
8057        /// The partition expression
8058        partition: Expression,
8059        if_not_exists: bool,
8060        location: Option<Expression>,
8061    },
8062    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8063    Delete {
8064        where_clause: Expression,
8065    },
8066    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8067    SwapWith(TableRef),
8068    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8069    SetProperty {
8070        properties: Vec<(String, Expression)>,
8071    },
8072    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8073    UnsetProperty {
8074        properties: Vec<String>,
8075    },
8076    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8077    ClusterBy {
8078        expressions: Vec<Expression>,
8079    },
8080    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8081    SetTag {
8082        expressions: Vec<(String, Expression)>,
8083    },
8084    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8085    UnsetTag {
8086        names: Vec<String>,
8087    },
8088    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8089    SetOptions {
8090        expressions: Vec<Expression>,
8091    },
8092    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8093    AlterIndex {
8094        name: Identifier,
8095        visible: bool,
8096    },
8097    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8098    SetAttribute {
8099        attribute: String,
8100    },
8101    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8102    SetStageFileFormat {
8103        options: Option<Expression>,
8104    },
8105    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8106    SetStageCopyOptions {
8107        options: Option<Expression>,
8108    },
8109    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8110    AddColumns {
8111        columns: Vec<ColumnDef>,
8112        cascade: bool,
8113    },
8114    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8115    DropColumns {
8116        names: Vec<Identifier>,
8117    },
8118    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8119    /// In SingleStore, data_type can be omitted for simple column renames
8120    ChangeColumn {
8121        old_name: Identifier,
8122        new_name: Identifier,
8123        #[serde(default, skip_serializing_if = "Option::is_none")]
8124        data_type: Option<DataType>,
8125        comment: Option<String>,
8126        #[serde(default)]
8127        cascade: bool,
8128    },
8129    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8130    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8131    AlterSortKey {
8132        /// AUTO or NONE keyword
8133        this: Option<String>,
8134        /// Column list for (col1, col2) syntax
8135        expressions: Vec<Expression>,
8136        /// Whether COMPOUND keyword was present
8137        compound: bool,
8138    },
8139    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8140    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8141    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8142    AlterDistStyle {
8143        /// Distribution style: ALL, EVEN, AUTO, or KEY
8144        style: String,
8145        /// DISTKEY column (only when style is KEY)
8146        distkey: Option<Identifier>,
8147    },
8148    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8149    SetTableProperties {
8150        properties: Vec<(Expression, Expression)>,
8151    },
8152    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8153    SetLocation {
8154        location: String,
8155    },
8156    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8157    SetFileFormat {
8158        format: String,
8159    },
8160    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8161    ReplacePartition {
8162        partition: Expression,
8163        source: Option<Box<Expression>>,
8164    },
8165    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8166    Raw {
8167        sql: String,
8168    },
8169}
8170
8171/// Actions for ALTER COLUMN
8172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8173#[cfg_attr(feature = "bindings", derive(TS))]
8174pub enum AlterColumnAction {
8175    SetDataType {
8176        data_type: DataType,
8177        /// USING expression for type conversion (PostgreSQL)
8178        using: Option<Expression>,
8179        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8180        #[serde(default, skip_serializing_if = "Option::is_none")]
8181        collate: Option<String>,
8182    },
8183    SetDefault(Expression),
8184    DropDefault,
8185    SetNotNull,
8186    DropNotNull,
8187    /// Set column comment
8188    Comment(String),
8189    /// MySQL: SET VISIBLE
8190    SetVisible,
8191    /// MySQL: SET INVISIBLE
8192    SetInvisible,
8193}
8194
8195/// CREATE INDEX statement
8196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8197#[cfg_attr(feature = "bindings", derive(TS))]
8198pub struct CreateIndex {
8199    pub name: Identifier,
8200    pub table: TableRef,
8201    pub columns: Vec<IndexColumn>,
8202    pub unique: bool,
8203    pub if_not_exists: bool,
8204    pub using: Option<String>,
8205    /// TSQL CLUSTERED/NONCLUSTERED modifier
8206    #[serde(default)]
8207    pub clustered: Option<String>,
8208    /// PostgreSQL CONCURRENTLY modifier
8209    #[serde(default)]
8210    pub concurrently: bool,
8211    /// PostgreSQL WHERE clause for partial indexes
8212    #[serde(default)]
8213    pub where_clause: Option<Box<Expression>>,
8214    /// PostgreSQL INCLUDE columns
8215    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8216    pub include_columns: Vec<Identifier>,
8217    /// TSQL WITH options (e.g., allow_page_locks=on)
8218    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8219    pub with_options: Vec<(String, String)>,
8220    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8221    #[serde(default)]
8222    pub on_filegroup: Option<String>,
8223}
8224
8225impl CreateIndex {
8226    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8227        Self {
8228            name: Identifier::new(name),
8229            table: TableRef::new(table),
8230            columns: Vec::new(),
8231            unique: false,
8232            if_not_exists: false,
8233            using: None,
8234            clustered: None,
8235            concurrently: false,
8236            where_clause: None,
8237            include_columns: Vec::new(),
8238            with_options: Vec::new(),
8239            on_filegroup: None,
8240        }
8241    }
8242}
8243
8244/// Index column specification
8245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8246#[cfg_attr(feature = "bindings", derive(TS))]
8247pub struct IndexColumn {
8248    pub column: Identifier,
8249    pub desc: bool,
8250    /// Explicit ASC keyword was present
8251    #[serde(default)]
8252    pub asc: bool,
8253    pub nulls_first: Option<bool>,
8254    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8255    #[serde(default, skip_serializing_if = "Option::is_none")]
8256    pub opclass: Option<String>,
8257}
8258
8259/// DROP INDEX statement
8260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8261#[cfg_attr(feature = "bindings", derive(TS))]
8262pub struct DropIndex {
8263    pub name: Identifier,
8264    pub table: Option<TableRef>,
8265    pub if_exists: bool,
8266    /// PostgreSQL CONCURRENTLY modifier
8267    #[serde(default)]
8268    pub concurrently: bool,
8269}
8270
8271impl DropIndex {
8272    pub fn new(name: impl Into<String>) -> Self {
8273        Self {
8274            name: Identifier::new(name),
8275            table: None,
8276            if_exists: false,
8277            concurrently: false,
8278        }
8279    }
8280}
8281
8282/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8284#[cfg_attr(feature = "bindings", derive(TS))]
8285pub struct ViewColumn {
8286    pub name: Identifier,
8287    pub comment: Option<String>,
8288    /// BigQuery: OPTIONS (key=value, ...) on column
8289    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8290    pub options: Vec<Expression>,
8291}
8292
8293impl ViewColumn {
8294    pub fn new(name: impl Into<String>) -> Self {
8295        Self {
8296            name: Identifier::new(name),
8297            comment: None,
8298            options: Vec::new(),
8299        }
8300    }
8301
8302    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8303        Self {
8304            name: Identifier::new(name),
8305            comment: Some(comment.into()),
8306            options: Vec::new(),
8307        }
8308    }
8309}
8310
8311/// CREATE VIEW statement
8312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8313#[cfg_attr(feature = "bindings", derive(TS))]
8314pub struct CreateView {
8315    pub name: TableRef,
8316    pub columns: Vec<ViewColumn>,
8317    pub query: Expression,
8318    pub or_replace: bool,
8319    /// TSQL: CREATE OR ALTER
8320    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8321    pub or_alter: bool,
8322    pub if_not_exists: bool,
8323    pub materialized: bool,
8324    pub temporary: bool,
8325    /// Snowflake: SECURE VIEW
8326    #[serde(default)]
8327    pub secure: bool,
8328    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8329    #[serde(skip_serializing_if = "Option::is_none")]
8330    pub algorithm: Option<String>,
8331    /// MySQL: DEFINER=user@host
8332    #[serde(skip_serializing_if = "Option::is_none")]
8333    pub definer: Option<String>,
8334    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8335    #[serde(skip_serializing_if = "Option::is_none")]
8336    pub security: Option<FunctionSecurity>,
8337    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8338    #[serde(default = "default_true")]
8339    pub security_sql_style: bool,
8340    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8341    #[serde(default)]
8342    pub security_after_name: bool,
8343    /// Whether the query was parenthesized: AS (SELECT ...)
8344    #[serde(default)]
8345    pub query_parenthesized: bool,
8346    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8347    #[serde(skip_serializing_if = "Option::is_none")]
8348    pub locking_mode: Option<String>,
8349    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8350    #[serde(skip_serializing_if = "Option::is_none")]
8351    pub locking_access: Option<String>,
8352    /// Snowflake: COPY GRANTS
8353    #[serde(default)]
8354    pub copy_grants: bool,
8355    /// Snowflake: COMMENT = 'text'
8356    #[serde(skip_serializing_if = "Option::is_none", default)]
8357    pub comment: Option<String>,
8358    /// Snowflake: TAG (name='value', ...)
8359    #[serde(default)]
8360    pub tags: Vec<(String, String)>,
8361    /// BigQuery: OPTIONS (key=value, ...)
8362    #[serde(default)]
8363    pub options: Vec<Expression>,
8364    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8365    #[serde(skip_serializing_if = "Option::is_none", default)]
8366    pub build: Option<String>,
8367    /// Doris: REFRESH property for materialized views
8368    #[serde(skip_serializing_if = "Option::is_none", default)]
8369    pub refresh: Option<Box<RefreshTriggerProperty>>,
8370    /// Doris: Schema with typed column definitions for materialized views
8371    /// This is used instead of `columns` when the view has typed column definitions
8372    #[serde(skip_serializing_if = "Option::is_none", default)]
8373    pub schema: Option<Box<Schema>>,
8374    /// Doris: KEY (columns) for materialized views
8375    #[serde(skip_serializing_if = "Option::is_none", default)]
8376    pub unique_key: Option<Box<UniqueKeyProperty>>,
8377    /// Redshift: WITH NO SCHEMA BINDING
8378    #[serde(default)]
8379    pub no_schema_binding: bool,
8380    /// Redshift: AUTO REFRESH YES|NO for materialized views
8381    #[serde(skip_serializing_if = "Option::is_none", default)]
8382    pub auto_refresh: Option<bool>,
8383    /// ClickHouse: ON CLUSTER clause
8384    #[serde(default, skip_serializing_if = "Option::is_none")]
8385    pub on_cluster: Option<OnCluster>,
8386    /// ClickHouse: TO destination_table
8387    #[serde(default, skip_serializing_if = "Option::is_none")]
8388    pub to_table: Option<TableRef>,
8389    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8390    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8391    pub table_properties: Vec<Expression>,
8392}
8393
8394impl CreateView {
8395    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8396        Self {
8397            name: TableRef::new(name),
8398            columns: Vec::new(),
8399            query,
8400            or_replace: false,
8401            or_alter: false,
8402            if_not_exists: false,
8403            materialized: false,
8404            temporary: false,
8405            secure: false,
8406            algorithm: None,
8407            definer: None,
8408            security: None,
8409            security_sql_style: true,
8410            security_after_name: false,
8411            query_parenthesized: false,
8412            locking_mode: None,
8413            locking_access: None,
8414            copy_grants: false,
8415            comment: None,
8416            tags: Vec::new(),
8417            options: Vec::new(),
8418            build: None,
8419            refresh: None,
8420            schema: None,
8421            unique_key: None,
8422            no_schema_binding: false,
8423            auto_refresh: None,
8424            on_cluster: None,
8425            to_table: None,
8426            table_properties: Vec::new(),
8427        }
8428    }
8429}
8430
8431/// DROP VIEW statement
8432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8433#[cfg_attr(feature = "bindings", derive(TS))]
8434pub struct DropView {
8435    pub name: TableRef,
8436    pub if_exists: bool,
8437    pub materialized: bool,
8438}
8439
8440impl DropView {
8441    pub fn new(name: impl Into<String>) -> Self {
8442        Self {
8443            name: TableRef::new(name),
8444            if_exists: false,
8445            materialized: false,
8446        }
8447    }
8448}
8449
8450/// TRUNCATE TABLE statement
8451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8452#[cfg_attr(feature = "bindings", derive(TS))]
8453pub struct Truncate {
8454    /// Target of TRUNCATE (TABLE vs DATABASE)
8455    #[serde(default)]
8456    pub target: TruncateTarget,
8457    /// IF EXISTS clause
8458    #[serde(default)]
8459    pub if_exists: bool,
8460    pub table: TableRef,
8461    /// ClickHouse: ON CLUSTER clause for distributed DDL
8462    #[serde(default, skip_serializing_if = "Option::is_none")]
8463    pub on_cluster: Option<OnCluster>,
8464    pub cascade: bool,
8465    /// Additional tables for multi-table TRUNCATE
8466    #[serde(default)]
8467    pub extra_tables: Vec<TruncateTableEntry>,
8468    /// RESTART IDENTITY or CONTINUE IDENTITY
8469    #[serde(default)]
8470    pub identity: Option<TruncateIdentity>,
8471    /// RESTRICT option (alternative to CASCADE)
8472    #[serde(default)]
8473    pub restrict: bool,
8474    /// Hive PARTITION clause: PARTITION(key=value, ...)
8475    #[serde(default, skip_serializing_if = "Option::is_none")]
8476    pub partition: Option<Box<Expression>>,
8477}
8478
8479/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8481#[cfg_attr(feature = "bindings", derive(TS))]
8482pub struct TruncateTableEntry {
8483    pub table: TableRef,
8484    /// Whether the table has a * suffix (inherit children)
8485    #[serde(default)]
8486    pub star: bool,
8487}
8488
8489/// TRUNCATE target type
8490#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8491#[cfg_attr(feature = "bindings", derive(TS))]
8492pub enum TruncateTarget {
8493    Table,
8494    Database,
8495}
8496
8497impl Default for TruncateTarget {
8498    fn default() -> Self {
8499        TruncateTarget::Table
8500    }
8501}
8502
8503/// TRUNCATE identity option
8504#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8505#[cfg_attr(feature = "bindings", derive(TS))]
8506pub enum TruncateIdentity {
8507    Restart,
8508    Continue,
8509}
8510
8511impl Truncate {
8512    pub fn new(table: impl Into<String>) -> Self {
8513        Self {
8514            target: TruncateTarget::Table,
8515            if_exists: false,
8516            table: TableRef::new(table),
8517            on_cluster: None,
8518            cascade: false,
8519            extra_tables: Vec::new(),
8520            identity: None,
8521            restrict: false,
8522            partition: None,
8523        }
8524    }
8525}
8526
8527/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8529#[cfg_attr(feature = "bindings", derive(TS))]
8530pub struct Use {
8531    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8532    pub kind: Option<UseKind>,
8533    /// The name of the object
8534    pub this: Identifier,
8535}
8536
8537/// Kind of USE statement
8538#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8539#[cfg_attr(feature = "bindings", derive(TS))]
8540pub enum UseKind {
8541    Database,
8542    Schema,
8543    Role,
8544    Warehouse,
8545    Catalog,
8546    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8547    SecondaryRoles,
8548}
8549
8550/// SET variable statement
8551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8552#[cfg_attr(feature = "bindings", derive(TS))]
8553pub struct SetStatement {
8554    /// The items being set
8555    pub items: Vec<SetItem>,
8556}
8557
8558/// A single SET item (variable assignment)
8559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8560#[cfg_attr(feature = "bindings", derive(TS))]
8561pub struct SetItem {
8562    /// The variable name
8563    pub name: Expression,
8564    /// The value to set
8565    pub value: Expression,
8566    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8567    pub kind: Option<String>,
8568    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8569    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8570    pub no_equals: bool,
8571}
8572
8573/// CACHE TABLE statement (Spark)
8574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8575#[cfg_attr(feature = "bindings", derive(TS))]
8576pub struct Cache {
8577    /// The table to cache
8578    pub table: Identifier,
8579    /// LAZY keyword - defer caching until first use
8580    pub lazy: bool,
8581    /// Optional OPTIONS clause (key-value pairs)
8582    pub options: Vec<(Expression, Expression)>,
8583    /// Optional AS clause with query
8584    pub query: Option<Expression>,
8585}
8586
8587/// UNCACHE TABLE statement (Spark)
8588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8589#[cfg_attr(feature = "bindings", derive(TS))]
8590pub struct Uncache {
8591    /// The table to uncache
8592    pub table: Identifier,
8593    /// IF EXISTS clause
8594    pub if_exists: bool,
8595}
8596
8597/// LOAD DATA statement (Hive)
8598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8599#[cfg_attr(feature = "bindings", derive(TS))]
8600pub struct LoadData {
8601    /// LOCAL keyword - load from local filesystem
8602    pub local: bool,
8603    /// The path to load data from (INPATH value)
8604    pub inpath: String,
8605    /// Whether to overwrite existing data
8606    pub overwrite: bool,
8607    /// The target table
8608    pub table: Expression,
8609    /// Optional PARTITION clause with key-value pairs
8610    pub partition: Vec<(Identifier, Expression)>,
8611    /// Optional INPUTFORMAT clause
8612    pub input_format: Option<String>,
8613    /// Optional SERDE clause
8614    pub serde: Option<String>,
8615}
8616
8617/// PRAGMA statement (SQLite)
8618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8619#[cfg_attr(feature = "bindings", derive(TS))]
8620pub struct Pragma {
8621    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8622    pub schema: Option<Identifier>,
8623    /// The pragma name
8624    pub name: Identifier,
8625    /// Optional value for assignment (PRAGMA name = value)
8626    pub value: Option<Expression>,
8627    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8628    pub args: Vec<Expression>,
8629}
8630
8631/// A privilege with optional column list for GRANT/REVOKE
8632/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8634#[cfg_attr(feature = "bindings", derive(TS))]
8635pub struct Privilege {
8636    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8637    pub name: String,
8638    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8639    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8640    pub columns: Vec<String>,
8641}
8642
8643/// Principal in GRANT/REVOKE (user, role, etc.)
8644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8645#[cfg_attr(feature = "bindings", derive(TS))]
8646pub struct GrantPrincipal {
8647    /// The name of the principal
8648    pub name: Identifier,
8649    /// Whether prefixed with ROLE keyword
8650    pub is_role: bool,
8651    /// Whether prefixed with GROUP keyword (Redshift)
8652    #[serde(default)]
8653    pub is_group: bool,
8654    /// Whether prefixed with SHARE keyword (Snowflake)
8655    #[serde(default)]
8656    pub is_share: bool,
8657}
8658
8659/// GRANT statement
8660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8661#[cfg_attr(feature = "bindings", derive(TS))]
8662pub struct Grant {
8663    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8664    pub privileges: Vec<Privilege>,
8665    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8666    pub kind: Option<String>,
8667    /// The object to grant on
8668    pub securable: Identifier,
8669    /// Function parameter types (for FUNCTION kind)
8670    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8671    pub function_params: Vec<String>,
8672    /// The grantees
8673    pub principals: Vec<GrantPrincipal>,
8674    /// WITH GRANT OPTION
8675    pub grant_option: bool,
8676    /// TSQL: AS principal (the grantor role)
8677    #[serde(default, skip_serializing_if = "Option::is_none")]
8678    pub as_principal: Option<Identifier>,
8679}
8680
8681/// REVOKE statement
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct Revoke {
8685    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8686    pub privileges: Vec<Privilege>,
8687    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8688    pub kind: Option<String>,
8689    /// The object to revoke from
8690    pub securable: Identifier,
8691    /// Function parameter types (for FUNCTION kind)
8692    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8693    pub function_params: Vec<String>,
8694    /// The grantees
8695    pub principals: Vec<GrantPrincipal>,
8696    /// GRANT OPTION FOR
8697    pub grant_option: bool,
8698    /// CASCADE
8699    pub cascade: bool,
8700    /// RESTRICT
8701    #[serde(default)]
8702    pub restrict: bool,
8703}
8704
8705/// COMMENT ON statement
8706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8707#[cfg_attr(feature = "bindings", derive(TS))]
8708pub struct Comment {
8709    /// The object being commented on
8710    pub this: Expression,
8711    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8712    pub kind: String,
8713    /// The comment text expression
8714    pub expression: Expression,
8715    /// IF EXISTS clause
8716    pub exists: bool,
8717    /// MATERIALIZED keyword
8718    pub materialized: bool,
8719}
8720
8721// ============================================================================
8722// Phase 4: Additional DDL Statements
8723// ============================================================================
8724
8725/// ALTER VIEW statement
8726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8727#[cfg_attr(feature = "bindings", derive(TS))]
8728pub struct AlterView {
8729    pub name: TableRef,
8730    pub actions: Vec<AlterViewAction>,
8731    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8732    #[serde(default, skip_serializing_if = "Option::is_none")]
8733    pub algorithm: Option<String>,
8734    /// MySQL: DEFINER = 'user'@'host'
8735    #[serde(default, skip_serializing_if = "Option::is_none")]
8736    pub definer: Option<String>,
8737    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8738    #[serde(default, skip_serializing_if = "Option::is_none")]
8739    pub sql_security: Option<String>,
8740    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8741    #[serde(default, skip_serializing_if = "Option::is_none")]
8742    pub with_option: Option<String>,
8743    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8744    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8745    pub columns: Vec<ViewColumn>,
8746}
8747
8748/// Actions for ALTER VIEW
8749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8750#[cfg_attr(feature = "bindings", derive(TS))]
8751pub enum AlterViewAction {
8752    /// Rename the view
8753    Rename(TableRef),
8754    /// Change owner
8755    OwnerTo(Identifier),
8756    /// Set schema
8757    SetSchema(Identifier),
8758    /// Set authorization (Trino/Presto)
8759    SetAuthorization(String),
8760    /// Alter column
8761    AlterColumn {
8762        name: Identifier,
8763        action: AlterColumnAction,
8764    },
8765    /// Redefine view as query (SELECT, UNION, etc.)
8766    AsSelect(Box<Expression>),
8767    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8768    SetTblproperties(Vec<(String, String)>),
8769    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8770    UnsetTblproperties(Vec<String>),
8771}
8772
8773impl AlterView {
8774    pub fn new(name: impl Into<String>) -> Self {
8775        Self {
8776            name: TableRef::new(name),
8777            actions: Vec::new(),
8778            algorithm: None,
8779            definer: None,
8780            sql_security: None,
8781            with_option: None,
8782            columns: Vec::new(),
8783        }
8784    }
8785}
8786
8787/// ALTER INDEX statement
8788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8789#[cfg_attr(feature = "bindings", derive(TS))]
8790pub struct AlterIndex {
8791    pub name: Identifier,
8792    pub table: Option<TableRef>,
8793    pub actions: Vec<AlterIndexAction>,
8794}
8795
8796/// Actions for ALTER INDEX
8797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8798#[cfg_attr(feature = "bindings", derive(TS))]
8799pub enum AlterIndexAction {
8800    /// Rename the index
8801    Rename(Identifier),
8802    /// Set tablespace
8803    SetTablespace(Identifier),
8804    /// Set visibility (MySQL)
8805    Visible(bool),
8806}
8807
8808impl AlterIndex {
8809    pub fn new(name: impl Into<String>) -> Self {
8810        Self {
8811            name: Identifier::new(name),
8812            table: None,
8813            actions: Vec::new(),
8814        }
8815    }
8816}
8817
8818/// CREATE SCHEMA statement
8819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8820#[cfg_attr(feature = "bindings", derive(TS))]
8821pub struct CreateSchema {
8822    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8823    pub name: Vec<Identifier>,
8824    pub if_not_exists: bool,
8825    pub authorization: Option<Identifier>,
8826    /// CLONE source parts, possibly dot-qualified
8827    #[serde(default)]
8828    pub clone_from: Option<Vec<Identifier>>,
8829    /// AT/BEFORE clause for time travel (Snowflake)
8830    #[serde(default)]
8831    pub at_clause: Option<Expression>,
8832    /// Schema properties like DEFAULT COLLATE
8833    #[serde(default)]
8834    pub properties: Vec<Expression>,
8835    /// Leading comments before the statement
8836    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8837    pub leading_comments: Vec<String>,
8838}
8839
8840impl CreateSchema {
8841    pub fn new(name: impl Into<String>) -> Self {
8842        Self {
8843            name: vec![Identifier::new(name)],
8844            if_not_exists: false,
8845            authorization: None,
8846            clone_from: None,
8847            at_clause: None,
8848            properties: Vec::new(),
8849            leading_comments: Vec::new(),
8850        }
8851    }
8852}
8853
8854/// DROP SCHEMA statement
8855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8856#[cfg_attr(feature = "bindings", derive(TS))]
8857pub struct DropSchema {
8858    pub name: Identifier,
8859    pub if_exists: bool,
8860    pub cascade: bool,
8861}
8862
8863impl DropSchema {
8864    pub fn new(name: impl Into<String>) -> Self {
8865        Self {
8866            name: Identifier::new(name),
8867            if_exists: false,
8868            cascade: false,
8869        }
8870    }
8871}
8872
8873/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8875#[cfg_attr(feature = "bindings", derive(TS))]
8876pub struct DropNamespace {
8877    pub name: Identifier,
8878    pub if_exists: bool,
8879    pub cascade: bool,
8880}
8881
8882impl DropNamespace {
8883    pub fn new(name: impl Into<String>) -> Self {
8884        Self {
8885            name: Identifier::new(name),
8886            if_exists: false,
8887            cascade: false,
8888        }
8889    }
8890}
8891
8892/// CREATE DATABASE statement
8893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8894#[cfg_attr(feature = "bindings", derive(TS))]
8895pub struct CreateDatabase {
8896    pub name: Identifier,
8897    pub if_not_exists: bool,
8898    pub options: Vec<DatabaseOption>,
8899    /// Snowflake CLONE source
8900    #[serde(default)]
8901    pub clone_from: Option<Identifier>,
8902    /// AT/BEFORE clause for time travel (Snowflake)
8903    #[serde(default)]
8904    pub at_clause: Option<Expression>,
8905}
8906
8907/// Database option
8908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8909#[cfg_attr(feature = "bindings", derive(TS))]
8910pub enum DatabaseOption {
8911    CharacterSet(String),
8912    Collate(String),
8913    Owner(Identifier),
8914    Template(Identifier),
8915    Encoding(String),
8916    Location(String),
8917}
8918
8919impl CreateDatabase {
8920    pub fn new(name: impl Into<String>) -> Self {
8921        Self {
8922            name: Identifier::new(name),
8923            if_not_exists: false,
8924            options: Vec::new(),
8925            clone_from: None,
8926            at_clause: None,
8927        }
8928    }
8929}
8930
8931/// DROP DATABASE statement
8932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8933#[cfg_attr(feature = "bindings", derive(TS))]
8934pub struct DropDatabase {
8935    pub name: Identifier,
8936    pub if_exists: bool,
8937    /// ClickHouse: SYNC modifier
8938    #[serde(default)]
8939    pub sync: bool,
8940}
8941
8942impl DropDatabase {
8943    pub fn new(name: impl Into<String>) -> Self {
8944        Self {
8945            name: Identifier::new(name),
8946            if_exists: false,
8947            sync: false,
8948        }
8949    }
8950}
8951
8952/// CREATE FUNCTION statement
8953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8954#[cfg_attr(feature = "bindings", derive(TS))]
8955pub struct CreateFunction {
8956    pub name: TableRef,
8957    pub parameters: Vec<FunctionParameter>,
8958    pub return_type: Option<DataType>,
8959    pub body: Option<FunctionBody>,
8960    pub or_replace: bool,
8961    /// TSQL: CREATE OR ALTER
8962    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8963    pub or_alter: bool,
8964    pub if_not_exists: bool,
8965    pub temporary: bool,
8966    pub language: Option<String>,
8967    pub deterministic: Option<bool>,
8968    pub returns_null_on_null_input: Option<bool>,
8969    pub security: Option<FunctionSecurity>,
8970    /// Whether parentheses were present in the original syntax
8971    #[serde(default = "default_true")]
8972    pub has_parens: bool,
8973    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
8974    #[serde(default)]
8975    pub sql_data_access: Option<SqlDataAccess>,
8976    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
8977    #[serde(default, skip_serializing_if = "Option::is_none")]
8978    pub returns_table_body: Option<String>,
8979    /// True if LANGUAGE clause appears before RETURNS clause
8980    #[serde(default)]
8981    pub language_first: bool,
8982    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
8983    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8984    pub set_options: Vec<FunctionSetOption>,
8985    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
8986    #[serde(default)]
8987    pub strict: bool,
8988    /// BigQuery: OPTIONS (key=value, ...)
8989    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8990    pub options: Vec<Expression>,
8991    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
8992    #[serde(default)]
8993    pub is_table_function: bool,
8994    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
8995    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8996    pub property_order: Vec<FunctionPropertyKind>,
8997    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
8998    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8999    pub environment: Vec<Expression>,
9000    /// HANDLER 'handler_function' clause (Databricks)
9001    #[serde(default, skip_serializing_if = "Option::is_none")]
9002    pub handler: Option<String>,
9003    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9004    #[serde(default, skip_serializing_if = "Option::is_none")]
9005    pub parameter_style: Option<String>,
9006}
9007
9008/// A SET option in CREATE FUNCTION (PostgreSQL)
9009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9010#[cfg_attr(feature = "bindings", derive(TS))]
9011pub struct FunctionSetOption {
9012    pub name: String,
9013    pub value: FunctionSetValue,
9014}
9015
9016/// The value of a SET option
9017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9018#[cfg_attr(feature = "bindings", derive(TS))]
9019pub enum FunctionSetValue {
9020    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9021    Value { value: String, use_to: bool },
9022    /// SET key FROM CURRENT
9023    FromCurrent,
9024}
9025
9026/// SQL data access characteristics for functions
9027#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9028#[cfg_attr(feature = "bindings", derive(TS))]
9029pub enum SqlDataAccess {
9030    /// NO SQL
9031    NoSql,
9032    /// CONTAINS SQL
9033    ContainsSql,
9034    /// READS SQL DATA
9035    ReadsSqlData,
9036    /// MODIFIES SQL DATA
9037    ModifiesSqlData,
9038}
9039
9040/// Types of properties in CREATE FUNCTION for tracking their original order
9041#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9042#[cfg_attr(feature = "bindings", derive(TS))]
9043pub enum FunctionPropertyKind {
9044    /// SET option
9045    Set,
9046    /// AS body
9047    As,
9048    /// LANGUAGE clause
9049    Language,
9050    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9051    Determinism,
9052    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9053    NullInput,
9054    /// SECURITY DEFINER/INVOKER
9055    Security,
9056    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9057    SqlDataAccess,
9058    /// OPTIONS clause (BigQuery)
9059    Options,
9060    /// ENVIRONMENT clause (Databricks)
9061    Environment,
9062    /// HANDLER clause (Databricks)
9063    Handler,
9064    /// PARAMETER STYLE clause (Databricks)
9065    ParameterStyle,
9066}
9067
9068/// Function parameter
9069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9070#[cfg_attr(feature = "bindings", derive(TS))]
9071pub struct FunctionParameter {
9072    pub name: Option<Identifier>,
9073    pub data_type: DataType,
9074    pub mode: Option<ParameterMode>,
9075    pub default: Option<Expression>,
9076    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9077    #[serde(default, skip_serializing_if = "Option::is_none")]
9078    pub mode_text: Option<String>,
9079}
9080
9081/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9082#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9083#[cfg_attr(feature = "bindings", derive(TS))]
9084pub enum ParameterMode {
9085    In,
9086    Out,
9087    InOut,
9088    Variadic,
9089}
9090
9091/// Function body
9092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9093#[cfg_attr(feature = "bindings", derive(TS))]
9094pub enum FunctionBody {
9095    /// AS $$ ... $$ (dollar-quoted)
9096    Block(String),
9097    /// AS 'string' (single-quoted string literal body)
9098    StringLiteral(String),
9099    /// AS 'expression'
9100    Expression(Expression),
9101    /// EXTERNAL NAME 'library'
9102    External(String),
9103    /// RETURN expression
9104    Return(Expression),
9105    /// BEGIN ... END block with parsed statements
9106    Statements(Vec<Expression>),
9107    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9108    /// Stores (content, optional_tag)
9109    DollarQuoted {
9110        content: String,
9111        tag: Option<String>,
9112    },
9113}
9114
9115/// Function security (DEFINER, INVOKER, or NONE)
9116#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9117#[cfg_attr(feature = "bindings", derive(TS))]
9118pub enum FunctionSecurity {
9119    Definer,
9120    Invoker,
9121    /// StarRocks/MySQL: SECURITY NONE
9122    None,
9123}
9124
9125impl CreateFunction {
9126    pub fn new(name: impl Into<String>) -> Self {
9127        Self {
9128            name: TableRef::new(name),
9129            parameters: Vec::new(),
9130            return_type: None,
9131            body: None,
9132            or_replace: false,
9133            or_alter: false,
9134            if_not_exists: false,
9135            temporary: false,
9136            language: None,
9137            deterministic: None,
9138            returns_null_on_null_input: None,
9139            security: None,
9140            has_parens: true,
9141            sql_data_access: None,
9142            returns_table_body: None,
9143            language_first: false,
9144            set_options: Vec::new(),
9145            strict: false,
9146            options: Vec::new(),
9147            is_table_function: false,
9148            property_order: Vec::new(),
9149            environment: Vec::new(),
9150            handler: None,
9151            parameter_style: None,
9152        }
9153    }
9154}
9155
9156/// DROP FUNCTION statement
9157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9158#[cfg_attr(feature = "bindings", derive(TS))]
9159pub struct DropFunction {
9160    pub name: TableRef,
9161    pub parameters: Option<Vec<DataType>>,
9162    pub if_exists: bool,
9163    pub cascade: bool,
9164}
9165
9166impl DropFunction {
9167    pub fn new(name: impl Into<String>) -> Self {
9168        Self {
9169            name: TableRef::new(name),
9170            parameters: None,
9171            if_exists: false,
9172            cascade: false,
9173        }
9174    }
9175}
9176
9177/// CREATE PROCEDURE statement
9178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9179#[cfg_attr(feature = "bindings", derive(TS))]
9180pub struct CreateProcedure {
9181    pub name: TableRef,
9182    pub parameters: Vec<FunctionParameter>,
9183    pub body: Option<FunctionBody>,
9184    pub or_replace: bool,
9185    /// TSQL: CREATE OR ALTER
9186    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9187    pub or_alter: bool,
9188    pub if_not_exists: bool,
9189    pub language: Option<String>,
9190    pub security: Option<FunctionSecurity>,
9191    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9192    #[serde(default)]
9193    pub return_type: Option<DataType>,
9194    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9195    #[serde(default)]
9196    pub execute_as: Option<String>,
9197    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9198    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9199    pub with_options: Vec<String>,
9200    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9201    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9202    pub has_parens: bool,
9203    /// Whether the short form PROC was used (instead of PROCEDURE)
9204    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9205    pub use_proc_keyword: bool,
9206}
9207
9208impl CreateProcedure {
9209    pub fn new(name: impl Into<String>) -> Self {
9210        Self {
9211            name: TableRef::new(name),
9212            parameters: Vec::new(),
9213            body: None,
9214            or_replace: false,
9215            or_alter: false,
9216            if_not_exists: false,
9217            language: None,
9218            security: None,
9219            return_type: None,
9220            execute_as: None,
9221            with_options: Vec::new(),
9222            has_parens: true,
9223            use_proc_keyword: false,
9224        }
9225    }
9226}
9227
9228/// DROP PROCEDURE statement
9229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9230#[cfg_attr(feature = "bindings", derive(TS))]
9231pub struct DropProcedure {
9232    pub name: TableRef,
9233    pub parameters: Option<Vec<DataType>>,
9234    pub if_exists: bool,
9235    pub cascade: bool,
9236}
9237
9238impl DropProcedure {
9239    pub fn new(name: impl Into<String>) -> Self {
9240        Self {
9241            name: TableRef::new(name),
9242            parameters: None,
9243            if_exists: false,
9244            cascade: false,
9245        }
9246    }
9247}
9248
9249/// Sequence property tag for ordering
9250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9251#[cfg_attr(feature = "bindings", derive(TS))]
9252pub enum SeqPropKind {
9253    Start,
9254    Increment,
9255    Minvalue,
9256    Maxvalue,
9257    Cache,
9258    NoCache,
9259    Cycle,
9260    NoCycle,
9261    OwnedBy,
9262    Order,
9263    NoOrder,
9264    Comment,
9265    /// SHARING=<value> (Oracle)
9266    Sharing,
9267    /// KEEP (Oracle)
9268    Keep,
9269    /// NOKEEP (Oracle)
9270    NoKeep,
9271    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9272    Scale,
9273    /// NOSCALE (Oracle)
9274    NoScale,
9275    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9276    Shard,
9277    /// NOSHARD (Oracle)
9278    NoShard,
9279    /// SESSION (Oracle)
9280    Session,
9281    /// GLOBAL (Oracle)
9282    Global,
9283    /// NOCACHE (single word, Oracle)
9284    NoCacheWord,
9285    /// NOCYCLE (single word, Oracle)
9286    NoCycleWord,
9287    /// NOMINVALUE (single word, Oracle)
9288    NoMinvalueWord,
9289    /// NOMAXVALUE (single word, Oracle)
9290    NoMaxvalueWord,
9291}
9292
9293/// CREATE SYNONYM statement (TSQL)
9294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9295#[cfg_attr(feature = "bindings", derive(TS))]
9296pub struct CreateSynonym {
9297    /// The synonym name (can be qualified: schema.synonym_name)
9298    pub name: TableRef,
9299    /// The target object the synonym refers to
9300    pub target: TableRef,
9301}
9302
9303/// CREATE SEQUENCE statement
9304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9305#[cfg_attr(feature = "bindings", derive(TS))]
9306pub struct CreateSequence {
9307    pub name: TableRef,
9308    pub if_not_exists: bool,
9309    pub temporary: bool,
9310    #[serde(default)]
9311    pub or_replace: bool,
9312    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9313    #[serde(default, skip_serializing_if = "Option::is_none")]
9314    pub as_type: Option<DataType>,
9315    pub increment: Option<i64>,
9316    pub minvalue: Option<SequenceBound>,
9317    pub maxvalue: Option<SequenceBound>,
9318    pub start: Option<i64>,
9319    pub cache: Option<i64>,
9320    pub cycle: bool,
9321    pub owned_by: Option<TableRef>,
9322    /// Whether OWNED BY NONE was specified
9323    #[serde(default)]
9324    pub owned_by_none: bool,
9325    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9326    #[serde(default)]
9327    pub order: Option<bool>,
9328    /// Snowflake: COMMENT = 'value'
9329    #[serde(default)]
9330    pub comment: Option<String>,
9331    /// SHARING=<value> (Oracle)
9332    #[serde(default, skip_serializing_if = "Option::is_none")]
9333    pub sharing: Option<String>,
9334    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9335    #[serde(default, skip_serializing_if = "Option::is_none")]
9336    pub scale_modifier: Option<String>,
9337    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9338    #[serde(default, skip_serializing_if = "Option::is_none")]
9339    pub shard_modifier: Option<String>,
9340    /// Tracks the order in which properties appeared in the source
9341    #[serde(default)]
9342    pub property_order: Vec<SeqPropKind>,
9343}
9344
9345/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9347#[cfg_attr(feature = "bindings", derive(TS))]
9348pub enum SequenceBound {
9349    Value(i64),
9350    None,
9351}
9352
9353impl CreateSequence {
9354    pub fn new(name: impl Into<String>) -> Self {
9355        Self {
9356            name: TableRef::new(name),
9357            if_not_exists: false,
9358            temporary: false,
9359            or_replace: false,
9360            as_type: None,
9361            increment: None,
9362            minvalue: None,
9363            maxvalue: None,
9364            start: None,
9365            cache: None,
9366            cycle: false,
9367            owned_by: None,
9368            owned_by_none: false,
9369            order: None,
9370            comment: None,
9371            sharing: None,
9372            scale_modifier: None,
9373            shard_modifier: None,
9374            property_order: Vec::new(),
9375        }
9376    }
9377}
9378
9379/// DROP SEQUENCE statement
9380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9381#[cfg_attr(feature = "bindings", derive(TS))]
9382pub struct DropSequence {
9383    pub name: TableRef,
9384    pub if_exists: bool,
9385    pub cascade: bool,
9386}
9387
9388impl DropSequence {
9389    pub fn new(name: impl Into<String>) -> Self {
9390        Self {
9391            name: TableRef::new(name),
9392            if_exists: false,
9393            cascade: false,
9394        }
9395    }
9396}
9397
9398/// ALTER SEQUENCE statement
9399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9400#[cfg_attr(feature = "bindings", derive(TS))]
9401pub struct AlterSequence {
9402    pub name: TableRef,
9403    pub if_exists: bool,
9404    pub increment: Option<i64>,
9405    pub minvalue: Option<SequenceBound>,
9406    pub maxvalue: Option<SequenceBound>,
9407    pub start: Option<i64>,
9408    pub restart: Option<Option<i64>>,
9409    pub cache: Option<i64>,
9410    pub cycle: Option<bool>,
9411    pub owned_by: Option<Option<TableRef>>,
9412}
9413
9414impl AlterSequence {
9415    pub fn new(name: impl Into<String>) -> Self {
9416        Self {
9417            name: TableRef::new(name),
9418            if_exists: false,
9419            increment: None,
9420            minvalue: None,
9421            maxvalue: None,
9422            start: None,
9423            restart: None,
9424            cache: None,
9425            cycle: None,
9426            owned_by: None,
9427        }
9428    }
9429}
9430
9431/// CREATE TRIGGER statement
9432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub struct CreateTrigger {
9435    pub name: Identifier,
9436    pub table: TableRef,
9437    pub timing: TriggerTiming,
9438    pub events: Vec<TriggerEvent>,
9439    #[serde(default, skip_serializing_if = "Option::is_none")]
9440    pub for_each: Option<TriggerForEach>,
9441    pub when: Option<Expression>,
9442    /// Whether the WHEN clause was parenthesized in the original SQL
9443    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9444    pub when_paren: bool,
9445    pub body: TriggerBody,
9446    pub or_replace: bool,
9447    /// TSQL: CREATE OR ALTER
9448    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9449    pub or_alter: bool,
9450    pub constraint: bool,
9451    pub deferrable: Option<bool>,
9452    pub initially_deferred: Option<bool>,
9453    pub referencing: Option<TriggerReferencing>,
9454}
9455
9456/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9457#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9458#[cfg_attr(feature = "bindings", derive(TS))]
9459pub enum TriggerTiming {
9460    Before,
9461    After,
9462    InsteadOf,
9463}
9464
9465/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9467#[cfg_attr(feature = "bindings", derive(TS))]
9468pub enum TriggerEvent {
9469    Insert,
9470    Update(Option<Vec<Identifier>>),
9471    Delete,
9472    Truncate,
9473}
9474
9475/// Trigger FOR EACH clause
9476#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9477#[cfg_attr(feature = "bindings", derive(TS))]
9478pub enum TriggerForEach {
9479    Row,
9480    Statement,
9481}
9482
9483/// Trigger body
9484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9485#[cfg_attr(feature = "bindings", derive(TS))]
9486pub enum TriggerBody {
9487    /// EXECUTE FUNCTION/PROCEDURE name(args)
9488    Execute {
9489        function: TableRef,
9490        args: Vec<Expression>,
9491    },
9492    /// BEGIN ... END block
9493    Block(String),
9494}
9495
9496/// Trigger REFERENCING clause
9497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9498#[cfg_attr(feature = "bindings", derive(TS))]
9499pub struct TriggerReferencing {
9500    pub old_table: Option<Identifier>,
9501    pub new_table: Option<Identifier>,
9502    pub old_row: Option<Identifier>,
9503    pub new_row: Option<Identifier>,
9504}
9505
9506impl CreateTrigger {
9507    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9508        Self {
9509            name: Identifier::new(name),
9510            table: TableRef::new(table),
9511            timing: TriggerTiming::Before,
9512            events: Vec::new(),
9513            for_each: Some(TriggerForEach::Row),
9514            when: None,
9515            when_paren: false,
9516            body: TriggerBody::Execute {
9517                function: TableRef::new(""),
9518                args: Vec::new(),
9519            },
9520            or_replace: false,
9521            or_alter: false,
9522            constraint: false,
9523            deferrable: None,
9524            initially_deferred: None,
9525            referencing: None,
9526        }
9527    }
9528}
9529
9530/// DROP TRIGGER statement
9531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9532#[cfg_attr(feature = "bindings", derive(TS))]
9533pub struct DropTrigger {
9534    pub name: Identifier,
9535    pub table: Option<TableRef>,
9536    pub if_exists: bool,
9537    pub cascade: bool,
9538}
9539
9540impl DropTrigger {
9541    pub fn new(name: impl Into<String>) -> Self {
9542        Self {
9543            name: Identifier::new(name),
9544            table: None,
9545            if_exists: false,
9546            cascade: false,
9547        }
9548    }
9549}
9550
9551/// CREATE TYPE statement
9552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9553#[cfg_attr(feature = "bindings", derive(TS))]
9554pub struct CreateType {
9555    pub name: TableRef,
9556    pub definition: TypeDefinition,
9557    pub if_not_exists: bool,
9558}
9559
9560/// Type definition
9561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9562#[cfg_attr(feature = "bindings", derive(TS))]
9563pub enum TypeDefinition {
9564    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9565    Enum(Vec<String>),
9566    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9567    Composite(Vec<TypeAttribute>),
9568    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9569    Range {
9570        subtype: DataType,
9571        subtype_diff: Option<String>,
9572        canonical: Option<String>,
9573    },
9574    /// Base type (for advanced usage)
9575    Base {
9576        input: String,
9577        output: String,
9578        internallength: Option<i32>,
9579    },
9580    /// Domain type
9581    Domain {
9582        base_type: DataType,
9583        default: Option<Expression>,
9584        constraints: Vec<DomainConstraint>,
9585    },
9586}
9587
9588/// Type attribute for composite types
9589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9590#[cfg_attr(feature = "bindings", derive(TS))]
9591pub struct TypeAttribute {
9592    pub name: Identifier,
9593    pub data_type: DataType,
9594    pub collate: Option<Identifier>,
9595}
9596
9597/// Domain constraint
9598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9599#[cfg_attr(feature = "bindings", derive(TS))]
9600pub struct DomainConstraint {
9601    pub name: Option<Identifier>,
9602    pub check: Expression,
9603}
9604
9605impl CreateType {
9606    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9607        Self {
9608            name: TableRef::new(name),
9609            definition: TypeDefinition::Enum(values),
9610            if_not_exists: false,
9611        }
9612    }
9613
9614    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9615        Self {
9616            name: TableRef::new(name),
9617            definition: TypeDefinition::Composite(attributes),
9618            if_not_exists: false,
9619        }
9620    }
9621}
9622
9623/// DROP TYPE statement
9624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9625#[cfg_attr(feature = "bindings", derive(TS))]
9626pub struct DropType {
9627    pub name: TableRef,
9628    pub if_exists: bool,
9629    pub cascade: bool,
9630}
9631
9632impl DropType {
9633    pub fn new(name: impl Into<String>) -> Self {
9634        Self {
9635            name: TableRef::new(name),
9636            if_exists: false,
9637            cascade: false,
9638        }
9639    }
9640}
9641
9642/// DESCRIBE statement - shows table structure or query plan
9643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9644#[cfg_attr(feature = "bindings", derive(TS))]
9645pub struct Describe {
9646    /// The target to describe (table name or query)
9647    pub target: Expression,
9648    /// EXTENDED format
9649    pub extended: bool,
9650    /// FORMATTED format
9651    pub formatted: bool,
9652    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9653    #[serde(default)]
9654    pub kind: Option<String>,
9655    /// Properties like type=stage
9656    #[serde(default)]
9657    pub properties: Vec<(String, String)>,
9658    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9659    #[serde(default, skip_serializing_if = "Option::is_none")]
9660    pub style: Option<String>,
9661    /// Partition specification for DESCRIBE PARTITION
9662    #[serde(default)]
9663    pub partition: Option<Box<Expression>>,
9664    /// Leading comments before the statement
9665    #[serde(default)]
9666    pub leading_comments: Vec<String>,
9667    /// AS JSON suffix (Databricks)
9668    #[serde(default)]
9669    pub as_json: bool,
9670    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9671    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9672    pub params: Vec<String>,
9673}
9674
9675impl Describe {
9676    pub fn new(target: Expression) -> Self {
9677        Self {
9678            target,
9679            extended: false,
9680            formatted: false,
9681            kind: None,
9682            properties: Vec::new(),
9683            style: None,
9684            partition: None,
9685            leading_comments: Vec::new(),
9686            as_json: false,
9687            params: Vec::new(),
9688        }
9689    }
9690}
9691
9692/// SHOW statement - displays database objects
9693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9694#[cfg_attr(feature = "bindings", derive(TS))]
9695pub struct Show {
9696    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9697    pub this: String,
9698    /// Whether TERSE was specified
9699    #[serde(default)]
9700    pub terse: bool,
9701    /// Whether HISTORY was specified
9702    #[serde(default)]
9703    pub history: bool,
9704    /// LIKE pattern
9705    pub like: Option<Expression>,
9706    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9707    pub scope_kind: Option<String>,
9708    /// IN scope object
9709    pub scope: Option<Expression>,
9710    /// STARTS WITH pattern
9711    pub starts_with: Option<Expression>,
9712    /// LIMIT clause
9713    pub limit: Option<Box<Limit>>,
9714    /// FROM clause (for specific object)
9715    pub from: Option<Expression>,
9716    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9717    #[serde(default, skip_serializing_if = "Option::is_none")]
9718    pub where_clause: Option<Expression>,
9719    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9720    #[serde(default, skip_serializing_if = "Option::is_none")]
9721    pub for_target: Option<Expression>,
9722    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9723    #[serde(default, skip_serializing_if = "Option::is_none")]
9724    pub db: Option<Expression>,
9725    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9726    #[serde(default, skip_serializing_if = "Option::is_none")]
9727    pub target: Option<Expression>,
9728    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9729    #[serde(default, skip_serializing_if = "Option::is_none")]
9730    pub mutex: Option<bool>,
9731    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9732    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9733    pub privileges: Vec<String>,
9734}
9735
9736impl Show {
9737    pub fn new(this: impl Into<String>) -> Self {
9738        Self {
9739            this: this.into(),
9740            terse: false,
9741            history: false,
9742            like: None,
9743            scope_kind: None,
9744            scope: None,
9745            starts_with: None,
9746            limit: None,
9747            from: None,
9748            where_clause: None,
9749            for_target: None,
9750            db: None,
9751            target: None,
9752            mutex: None,
9753            privileges: Vec::new(),
9754        }
9755    }
9756}
9757
9758/// Represent an explicit parenthesized expression for grouping precedence.
9759///
9760/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9761/// correctly instead of being flattened to `a + b * c`.
9762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9763#[cfg_attr(feature = "bindings", derive(TS))]
9764pub struct Paren {
9765    /// The inner expression wrapped by parentheses.
9766    pub this: Expression,
9767    #[serde(default)]
9768    pub trailing_comments: Vec<String>,
9769}
9770
9771/// Expression annotated with trailing comments (for round-trip preservation)
9772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9773#[cfg_attr(feature = "bindings", derive(TS))]
9774pub struct Annotated {
9775    pub this: Expression,
9776    pub trailing_comments: Vec<String>,
9777}
9778
9779// === BATCH GENERATED STRUCT DEFINITIONS ===
9780// Generated from Python sqlglot expressions.py
9781
9782/// Refresh
9783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9784#[cfg_attr(feature = "bindings", derive(TS))]
9785pub struct Refresh {
9786    pub this: Box<Expression>,
9787    pub kind: String,
9788}
9789
9790/// LockingStatement
9791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9792#[cfg_attr(feature = "bindings", derive(TS))]
9793pub struct LockingStatement {
9794    pub this: Box<Expression>,
9795    pub expression: Box<Expression>,
9796}
9797
9798/// SequenceProperties
9799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9800#[cfg_attr(feature = "bindings", derive(TS))]
9801pub struct SequenceProperties {
9802    #[serde(default)]
9803    pub increment: Option<Box<Expression>>,
9804    #[serde(default)]
9805    pub minvalue: Option<Box<Expression>>,
9806    #[serde(default)]
9807    pub maxvalue: Option<Box<Expression>>,
9808    #[serde(default)]
9809    pub cache: Option<Box<Expression>>,
9810    #[serde(default)]
9811    pub start: Option<Box<Expression>>,
9812    #[serde(default)]
9813    pub owned: Option<Box<Expression>>,
9814    #[serde(default)]
9815    pub options: Vec<Expression>,
9816}
9817
9818/// TruncateTable
9819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9820#[cfg_attr(feature = "bindings", derive(TS))]
9821pub struct TruncateTable {
9822    #[serde(default)]
9823    pub expressions: Vec<Expression>,
9824    #[serde(default)]
9825    pub is_database: Option<Box<Expression>>,
9826    #[serde(default)]
9827    pub exists: bool,
9828    #[serde(default)]
9829    pub only: Option<Box<Expression>>,
9830    #[serde(default)]
9831    pub cluster: Option<Box<Expression>>,
9832    #[serde(default)]
9833    pub identity: Option<Box<Expression>>,
9834    #[serde(default)]
9835    pub option: Option<Box<Expression>>,
9836    #[serde(default)]
9837    pub partition: Option<Box<Expression>>,
9838}
9839
9840/// Clone
9841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9842#[cfg_attr(feature = "bindings", derive(TS))]
9843pub struct Clone {
9844    pub this: Box<Expression>,
9845    #[serde(default)]
9846    pub shallow: Option<Box<Expression>>,
9847    #[serde(default)]
9848    pub copy: Option<Box<Expression>>,
9849}
9850
9851/// Attach
9852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9853#[cfg_attr(feature = "bindings", derive(TS))]
9854pub struct Attach {
9855    pub this: Box<Expression>,
9856    #[serde(default)]
9857    pub exists: bool,
9858    #[serde(default)]
9859    pub expressions: Vec<Expression>,
9860}
9861
9862/// Detach
9863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9864#[cfg_attr(feature = "bindings", derive(TS))]
9865pub struct Detach {
9866    pub this: Box<Expression>,
9867    #[serde(default)]
9868    pub exists: bool,
9869}
9870
9871/// Install
9872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9873#[cfg_attr(feature = "bindings", derive(TS))]
9874pub struct Install {
9875    pub this: Box<Expression>,
9876    #[serde(default)]
9877    pub from_: Option<Box<Expression>>,
9878    #[serde(default)]
9879    pub force: Option<Box<Expression>>,
9880}
9881
9882/// Summarize
9883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9884#[cfg_attr(feature = "bindings", derive(TS))]
9885pub struct Summarize {
9886    pub this: Box<Expression>,
9887    #[serde(default)]
9888    pub table: Option<Box<Expression>>,
9889}
9890
9891/// Declare
9892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9893#[cfg_attr(feature = "bindings", derive(TS))]
9894pub struct Declare {
9895    #[serde(default)]
9896    pub expressions: Vec<Expression>,
9897    #[serde(default)]
9898    pub replace: bool,
9899}
9900
9901/// DeclareItem
9902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9903#[cfg_attr(feature = "bindings", derive(TS))]
9904pub struct DeclareItem {
9905    pub this: Box<Expression>,
9906    #[serde(default)]
9907    pub kind: Option<String>,
9908    #[serde(default)]
9909    pub default: Option<Box<Expression>>,
9910    #[serde(default)]
9911    pub has_as: bool,
9912    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
9913    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9914    pub additional_names: Vec<Expression>,
9915}
9916
9917/// Set
9918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9919#[cfg_attr(feature = "bindings", derive(TS))]
9920pub struct Set {
9921    #[serde(default)]
9922    pub expressions: Vec<Expression>,
9923    #[serde(default)]
9924    pub unset: Option<Box<Expression>>,
9925    #[serde(default)]
9926    pub tag: Option<Box<Expression>>,
9927}
9928
9929/// Heredoc
9930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9931#[cfg_attr(feature = "bindings", derive(TS))]
9932pub struct Heredoc {
9933    pub this: Box<Expression>,
9934    #[serde(default)]
9935    pub tag: Option<Box<Expression>>,
9936}
9937
9938/// QueryBand
9939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9940#[cfg_attr(feature = "bindings", derive(TS))]
9941pub struct QueryBand {
9942    pub this: Box<Expression>,
9943    #[serde(default)]
9944    pub scope: Option<Box<Expression>>,
9945    #[serde(default)]
9946    pub update: Option<Box<Expression>>,
9947}
9948
9949/// UserDefinedFunction
9950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9951#[cfg_attr(feature = "bindings", derive(TS))]
9952pub struct UserDefinedFunction {
9953    pub this: Box<Expression>,
9954    #[serde(default)]
9955    pub expressions: Vec<Expression>,
9956    #[serde(default)]
9957    pub wrapped: Option<Box<Expression>>,
9958}
9959
9960/// RecursiveWithSearch
9961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9962#[cfg_attr(feature = "bindings", derive(TS))]
9963pub struct RecursiveWithSearch {
9964    pub kind: String,
9965    pub this: Box<Expression>,
9966    pub expression: Box<Expression>,
9967    #[serde(default)]
9968    pub using: Option<Box<Expression>>,
9969}
9970
9971/// ProjectionDef
9972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9973#[cfg_attr(feature = "bindings", derive(TS))]
9974pub struct ProjectionDef {
9975    pub this: Box<Expression>,
9976    pub expression: Box<Expression>,
9977}
9978
9979/// TableAlias
9980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9981#[cfg_attr(feature = "bindings", derive(TS))]
9982pub struct TableAlias {
9983    #[serde(default)]
9984    pub this: Option<Box<Expression>>,
9985    #[serde(default)]
9986    pub columns: Vec<Expression>,
9987}
9988
9989/// ByteString
9990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9991#[cfg_attr(feature = "bindings", derive(TS))]
9992pub struct ByteString {
9993    pub this: Box<Expression>,
9994    #[serde(default)]
9995    pub is_bytes: Option<Box<Expression>>,
9996}
9997
9998/// HexStringExpr - Hex string expression (not literal)
9999/// BigQuery: converts to FROM_HEX(this)
10000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10001#[cfg_attr(feature = "bindings", derive(TS))]
10002pub struct HexStringExpr {
10003    pub this: Box<Expression>,
10004    #[serde(default)]
10005    pub is_integer: Option<bool>,
10006}
10007
10008/// UnicodeString
10009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10010#[cfg_attr(feature = "bindings", derive(TS))]
10011pub struct UnicodeString {
10012    pub this: Box<Expression>,
10013    #[serde(default)]
10014    pub escape: Option<Box<Expression>>,
10015}
10016
10017/// AlterColumn
10018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10019#[cfg_attr(feature = "bindings", derive(TS))]
10020pub struct AlterColumn {
10021    pub this: Box<Expression>,
10022    #[serde(default)]
10023    pub dtype: Option<Box<Expression>>,
10024    #[serde(default)]
10025    pub collate: Option<Box<Expression>>,
10026    #[serde(default)]
10027    pub using: Option<Box<Expression>>,
10028    #[serde(default)]
10029    pub default: Option<Box<Expression>>,
10030    #[serde(default)]
10031    pub drop: Option<Box<Expression>>,
10032    #[serde(default)]
10033    pub comment: Option<Box<Expression>>,
10034    #[serde(default)]
10035    pub allow_null: Option<Box<Expression>>,
10036    #[serde(default)]
10037    pub visible: Option<Box<Expression>>,
10038    #[serde(default)]
10039    pub rename_to: Option<Box<Expression>>,
10040}
10041
10042/// AlterSortKey
10043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10044#[cfg_attr(feature = "bindings", derive(TS))]
10045pub struct AlterSortKey {
10046    #[serde(default)]
10047    pub this: Option<Box<Expression>>,
10048    #[serde(default)]
10049    pub expressions: Vec<Expression>,
10050    #[serde(default)]
10051    pub compound: Option<Box<Expression>>,
10052}
10053
10054/// AlterSet
10055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10056#[cfg_attr(feature = "bindings", derive(TS))]
10057pub struct AlterSet {
10058    #[serde(default)]
10059    pub expressions: Vec<Expression>,
10060    #[serde(default)]
10061    pub option: Option<Box<Expression>>,
10062    #[serde(default)]
10063    pub tablespace: Option<Box<Expression>>,
10064    #[serde(default)]
10065    pub access_method: Option<Box<Expression>>,
10066    #[serde(default)]
10067    pub file_format: Option<Box<Expression>>,
10068    #[serde(default)]
10069    pub copy_options: Option<Box<Expression>>,
10070    #[serde(default)]
10071    pub tag: Option<Box<Expression>>,
10072    #[serde(default)]
10073    pub location: Option<Box<Expression>>,
10074    #[serde(default)]
10075    pub serde: Option<Box<Expression>>,
10076}
10077
10078/// RenameColumn
10079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10080#[cfg_attr(feature = "bindings", derive(TS))]
10081pub struct RenameColumn {
10082    pub this: Box<Expression>,
10083    #[serde(default)]
10084    pub to: Option<Box<Expression>>,
10085    #[serde(default)]
10086    pub exists: bool,
10087}
10088
10089/// Comprehension
10090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10091#[cfg_attr(feature = "bindings", derive(TS))]
10092pub struct Comprehension {
10093    pub this: Box<Expression>,
10094    pub expression: Box<Expression>,
10095    #[serde(default)]
10096    pub position: Option<Box<Expression>>,
10097    #[serde(default)]
10098    pub iterator: Option<Box<Expression>>,
10099    #[serde(default)]
10100    pub condition: Option<Box<Expression>>,
10101}
10102
10103/// MergeTreeTTLAction
10104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10105#[cfg_attr(feature = "bindings", derive(TS))]
10106pub struct MergeTreeTTLAction {
10107    pub this: Box<Expression>,
10108    #[serde(default)]
10109    pub delete: Option<Box<Expression>>,
10110    #[serde(default)]
10111    pub recompress: Option<Box<Expression>>,
10112    #[serde(default)]
10113    pub to_disk: Option<Box<Expression>>,
10114    #[serde(default)]
10115    pub to_volume: Option<Box<Expression>>,
10116}
10117
10118/// MergeTreeTTL
10119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10120#[cfg_attr(feature = "bindings", derive(TS))]
10121pub struct MergeTreeTTL {
10122    #[serde(default)]
10123    pub expressions: Vec<Expression>,
10124    #[serde(default)]
10125    pub where_: Option<Box<Expression>>,
10126    #[serde(default)]
10127    pub group: Option<Box<Expression>>,
10128    #[serde(default)]
10129    pub aggregates: Option<Box<Expression>>,
10130}
10131
10132/// IndexConstraintOption
10133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10134#[cfg_attr(feature = "bindings", derive(TS))]
10135pub struct IndexConstraintOption {
10136    #[serde(default)]
10137    pub key_block_size: Option<Box<Expression>>,
10138    #[serde(default)]
10139    pub using: Option<Box<Expression>>,
10140    #[serde(default)]
10141    pub parser: Option<Box<Expression>>,
10142    #[serde(default)]
10143    pub comment: Option<Box<Expression>>,
10144    #[serde(default)]
10145    pub visible: Option<Box<Expression>>,
10146    #[serde(default)]
10147    pub engine_attr: Option<Box<Expression>>,
10148    #[serde(default)]
10149    pub secondary_engine_attr: Option<Box<Expression>>,
10150}
10151
10152/// PeriodForSystemTimeConstraint
10153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10154#[cfg_attr(feature = "bindings", derive(TS))]
10155pub struct PeriodForSystemTimeConstraint {
10156    pub this: Box<Expression>,
10157    pub expression: Box<Expression>,
10158}
10159
10160/// CaseSpecificColumnConstraint
10161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10162#[cfg_attr(feature = "bindings", derive(TS))]
10163pub struct CaseSpecificColumnConstraint {
10164    #[serde(default)]
10165    pub not_: Option<Box<Expression>>,
10166}
10167
10168/// CharacterSetColumnConstraint
10169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10170#[cfg_attr(feature = "bindings", derive(TS))]
10171pub struct CharacterSetColumnConstraint {
10172    pub this: Box<Expression>,
10173}
10174
10175/// CheckColumnConstraint
10176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10177#[cfg_attr(feature = "bindings", derive(TS))]
10178pub struct CheckColumnConstraint {
10179    pub this: Box<Expression>,
10180    #[serde(default)]
10181    pub enforced: Option<Box<Expression>>,
10182}
10183
10184/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10186#[cfg_attr(feature = "bindings", derive(TS))]
10187pub struct AssumeColumnConstraint {
10188    pub this: Box<Expression>,
10189}
10190
10191/// CompressColumnConstraint
10192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10193#[cfg_attr(feature = "bindings", derive(TS))]
10194pub struct CompressColumnConstraint {
10195    #[serde(default)]
10196    pub this: Option<Box<Expression>>,
10197}
10198
10199/// DateFormatColumnConstraint
10200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10201#[cfg_attr(feature = "bindings", derive(TS))]
10202pub struct DateFormatColumnConstraint {
10203    pub this: Box<Expression>,
10204}
10205
10206/// EphemeralColumnConstraint
10207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10208#[cfg_attr(feature = "bindings", derive(TS))]
10209pub struct EphemeralColumnConstraint {
10210    #[serde(default)]
10211    pub this: Option<Box<Expression>>,
10212}
10213
10214/// WithOperator
10215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10216#[cfg_attr(feature = "bindings", derive(TS))]
10217pub struct WithOperator {
10218    pub this: Box<Expression>,
10219    pub op: String,
10220}
10221
10222/// GeneratedAsIdentityColumnConstraint
10223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10224#[cfg_attr(feature = "bindings", derive(TS))]
10225pub struct GeneratedAsIdentityColumnConstraint {
10226    #[serde(default)]
10227    pub this: Option<Box<Expression>>,
10228    #[serde(default)]
10229    pub expression: Option<Box<Expression>>,
10230    #[serde(default)]
10231    pub on_null: Option<Box<Expression>>,
10232    #[serde(default)]
10233    pub start: Option<Box<Expression>>,
10234    #[serde(default)]
10235    pub increment: Option<Box<Expression>>,
10236    #[serde(default)]
10237    pub minvalue: Option<Box<Expression>>,
10238    #[serde(default)]
10239    pub maxvalue: Option<Box<Expression>>,
10240    #[serde(default)]
10241    pub cycle: Option<Box<Expression>>,
10242    #[serde(default)]
10243    pub order: Option<Box<Expression>>,
10244}
10245
10246/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10247/// TSQL: outputs "IDENTITY"
10248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10249#[cfg_attr(feature = "bindings", derive(TS))]
10250pub struct AutoIncrementColumnConstraint;
10251
10252/// CommentColumnConstraint - Column comment marker
10253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10254#[cfg_attr(feature = "bindings", derive(TS))]
10255pub struct CommentColumnConstraint;
10256
10257/// GeneratedAsRowColumnConstraint
10258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10259#[cfg_attr(feature = "bindings", derive(TS))]
10260pub struct GeneratedAsRowColumnConstraint {
10261    #[serde(default)]
10262    pub start: Option<Box<Expression>>,
10263    #[serde(default)]
10264    pub hidden: Option<Box<Expression>>,
10265}
10266
10267/// IndexColumnConstraint
10268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10269#[cfg_attr(feature = "bindings", derive(TS))]
10270pub struct IndexColumnConstraint {
10271    #[serde(default)]
10272    pub this: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub expressions: Vec<Expression>,
10275    #[serde(default)]
10276    pub kind: Option<String>,
10277    #[serde(default)]
10278    pub index_type: Option<Box<Expression>>,
10279    #[serde(default)]
10280    pub options: Vec<Expression>,
10281    #[serde(default)]
10282    pub expression: Option<Box<Expression>>,
10283    #[serde(default)]
10284    pub granularity: Option<Box<Expression>>,
10285}
10286
10287/// MaskingPolicyColumnConstraint
10288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10289#[cfg_attr(feature = "bindings", derive(TS))]
10290pub struct MaskingPolicyColumnConstraint {
10291    pub this: Box<Expression>,
10292    #[serde(default)]
10293    pub expressions: Vec<Expression>,
10294}
10295
10296/// NotNullColumnConstraint
10297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10298#[cfg_attr(feature = "bindings", derive(TS))]
10299pub struct NotNullColumnConstraint {
10300    #[serde(default)]
10301    pub allow_null: Option<Box<Expression>>,
10302}
10303
10304/// DefaultColumnConstraint - DEFAULT value for a column
10305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10306#[cfg_attr(feature = "bindings", derive(TS))]
10307pub struct DefaultColumnConstraint {
10308    pub this: Box<Expression>,
10309    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10310    #[serde(default, skip_serializing_if = "Option::is_none")]
10311    pub for_column: Option<Identifier>,
10312}
10313
10314/// PrimaryKeyColumnConstraint
10315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10316#[cfg_attr(feature = "bindings", derive(TS))]
10317pub struct PrimaryKeyColumnConstraint {
10318    #[serde(default)]
10319    pub desc: Option<Box<Expression>>,
10320    #[serde(default)]
10321    pub options: Vec<Expression>,
10322}
10323
10324/// UniqueColumnConstraint
10325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10326#[cfg_attr(feature = "bindings", derive(TS))]
10327pub struct UniqueColumnConstraint {
10328    #[serde(default)]
10329    pub this: Option<Box<Expression>>,
10330    #[serde(default)]
10331    pub index_type: Option<Box<Expression>>,
10332    #[serde(default)]
10333    pub on_conflict: Option<Box<Expression>>,
10334    #[serde(default)]
10335    pub nulls: Option<Box<Expression>>,
10336    #[serde(default)]
10337    pub options: Vec<Expression>,
10338}
10339
10340/// WatermarkColumnConstraint
10341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10342#[cfg_attr(feature = "bindings", derive(TS))]
10343pub struct WatermarkColumnConstraint {
10344    pub this: Box<Expression>,
10345    pub expression: Box<Expression>,
10346}
10347
10348/// ComputedColumnConstraint
10349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10350#[cfg_attr(feature = "bindings", derive(TS))]
10351pub struct ComputedColumnConstraint {
10352    pub this: Box<Expression>,
10353    #[serde(default)]
10354    pub persisted: Option<Box<Expression>>,
10355    #[serde(default)]
10356    pub not_null: Option<Box<Expression>>,
10357    #[serde(default)]
10358    pub data_type: Option<Box<Expression>>,
10359}
10360
10361/// InOutColumnConstraint
10362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10363#[cfg_attr(feature = "bindings", derive(TS))]
10364pub struct InOutColumnConstraint {
10365    #[serde(default)]
10366    pub input_: Option<Box<Expression>>,
10367    #[serde(default)]
10368    pub output: Option<Box<Expression>>,
10369}
10370
10371/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10373#[cfg_attr(feature = "bindings", derive(TS))]
10374pub struct PathColumnConstraint {
10375    pub this: Box<Expression>,
10376}
10377
10378/// Constraint
10379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10380#[cfg_attr(feature = "bindings", derive(TS))]
10381pub struct Constraint {
10382    pub this: Box<Expression>,
10383    #[serde(default)]
10384    pub expressions: Vec<Expression>,
10385}
10386
10387/// Export
10388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10389#[cfg_attr(feature = "bindings", derive(TS))]
10390pub struct Export {
10391    pub this: Box<Expression>,
10392    #[serde(default)]
10393    pub connection: Option<Box<Expression>>,
10394    #[serde(default)]
10395    pub options: Vec<Expression>,
10396}
10397
10398/// Filter
10399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10400#[cfg_attr(feature = "bindings", derive(TS))]
10401pub struct Filter {
10402    pub this: Box<Expression>,
10403    pub expression: Box<Expression>,
10404}
10405
10406/// Changes
10407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10408#[cfg_attr(feature = "bindings", derive(TS))]
10409pub struct Changes {
10410    #[serde(default)]
10411    pub information: Option<Box<Expression>>,
10412    #[serde(default)]
10413    pub at_before: Option<Box<Expression>>,
10414    #[serde(default)]
10415    pub end: Option<Box<Expression>>,
10416}
10417
10418/// Directory
10419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10420#[cfg_attr(feature = "bindings", derive(TS))]
10421pub struct Directory {
10422    pub this: Box<Expression>,
10423    #[serde(default)]
10424    pub local: Option<Box<Expression>>,
10425    #[serde(default)]
10426    pub row_format: Option<Box<Expression>>,
10427}
10428
10429/// ForeignKey
10430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10431#[cfg_attr(feature = "bindings", derive(TS))]
10432pub struct ForeignKey {
10433    #[serde(default)]
10434    pub expressions: Vec<Expression>,
10435    #[serde(default)]
10436    pub reference: Option<Box<Expression>>,
10437    #[serde(default)]
10438    pub delete: Option<Box<Expression>>,
10439    #[serde(default)]
10440    pub update: Option<Box<Expression>>,
10441    #[serde(default)]
10442    pub options: Vec<Expression>,
10443}
10444
10445/// ColumnPrefix
10446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10447#[cfg_attr(feature = "bindings", derive(TS))]
10448pub struct ColumnPrefix {
10449    pub this: Box<Expression>,
10450    pub expression: Box<Expression>,
10451}
10452
10453/// PrimaryKey
10454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10455#[cfg_attr(feature = "bindings", derive(TS))]
10456pub struct PrimaryKey {
10457    #[serde(default)]
10458    pub this: Option<Box<Expression>>,
10459    #[serde(default)]
10460    pub expressions: Vec<Expression>,
10461    #[serde(default)]
10462    pub options: Vec<Expression>,
10463    #[serde(default)]
10464    pub include: Option<Box<Expression>>,
10465}
10466
10467/// Into
10468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10469#[cfg_attr(feature = "bindings", derive(TS))]
10470pub struct IntoClause {
10471    #[serde(default)]
10472    pub this: Option<Box<Expression>>,
10473    #[serde(default)]
10474    pub temporary: bool,
10475    #[serde(default)]
10476    pub unlogged: Option<Box<Expression>>,
10477    #[serde(default)]
10478    pub bulk_collect: Option<Box<Expression>>,
10479    #[serde(default)]
10480    pub expressions: Vec<Expression>,
10481}
10482
10483/// JoinHint
10484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10485#[cfg_attr(feature = "bindings", derive(TS))]
10486pub struct JoinHint {
10487    pub this: Box<Expression>,
10488    #[serde(default)]
10489    pub expressions: Vec<Expression>,
10490}
10491
10492/// Opclass
10493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10494#[cfg_attr(feature = "bindings", derive(TS))]
10495pub struct Opclass {
10496    pub this: Box<Expression>,
10497    pub expression: Box<Expression>,
10498}
10499
10500/// Index
10501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10502#[cfg_attr(feature = "bindings", derive(TS))]
10503pub struct Index {
10504    #[serde(default)]
10505    pub this: Option<Box<Expression>>,
10506    #[serde(default)]
10507    pub table: Option<Box<Expression>>,
10508    #[serde(default)]
10509    pub unique: bool,
10510    #[serde(default)]
10511    pub primary: Option<Box<Expression>>,
10512    #[serde(default)]
10513    pub amp: Option<Box<Expression>>,
10514    #[serde(default)]
10515    pub params: Vec<Expression>,
10516}
10517
10518/// IndexParameters
10519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10520#[cfg_attr(feature = "bindings", derive(TS))]
10521pub struct IndexParameters {
10522    #[serde(default)]
10523    pub using: Option<Box<Expression>>,
10524    #[serde(default)]
10525    pub include: Option<Box<Expression>>,
10526    #[serde(default)]
10527    pub columns: Vec<Expression>,
10528    #[serde(default)]
10529    pub with_storage: Option<Box<Expression>>,
10530    #[serde(default)]
10531    pub partition_by: Option<Box<Expression>>,
10532    #[serde(default)]
10533    pub tablespace: Option<Box<Expression>>,
10534    #[serde(default)]
10535    pub where_: Option<Box<Expression>>,
10536    #[serde(default)]
10537    pub on: Option<Box<Expression>>,
10538}
10539
10540/// ConditionalInsert
10541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10542#[cfg_attr(feature = "bindings", derive(TS))]
10543pub struct ConditionalInsert {
10544    pub this: Box<Expression>,
10545    #[serde(default)]
10546    pub expression: Option<Box<Expression>>,
10547    #[serde(default)]
10548    pub else_: Option<Box<Expression>>,
10549}
10550
10551/// MultitableInserts
10552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10553#[cfg_attr(feature = "bindings", derive(TS))]
10554pub struct MultitableInserts {
10555    #[serde(default)]
10556    pub expressions: Vec<Expression>,
10557    pub kind: String,
10558    #[serde(default)]
10559    pub source: Option<Box<Expression>>,
10560    /// Leading comments before the statement
10561    #[serde(default)]
10562    pub leading_comments: Vec<String>,
10563}
10564
10565/// OnConflict
10566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10567#[cfg_attr(feature = "bindings", derive(TS))]
10568pub struct OnConflict {
10569    #[serde(default)]
10570    pub duplicate: Option<Box<Expression>>,
10571    #[serde(default)]
10572    pub expressions: Vec<Expression>,
10573    #[serde(default)]
10574    pub action: Option<Box<Expression>>,
10575    #[serde(default)]
10576    pub conflict_keys: Option<Box<Expression>>,
10577    #[serde(default)]
10578    pub index_predicate: Option<Box<Expression>>,
10579    #[serde(default)]
10580    pub constraint: Option<Box<Expression>>,
10581    #[serde(default)]
10582    pub where_: Option<Box<Expression>>,
10583}
10584
10585/// OnCondition
10586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10587#[cfg_attr(feature = "bindings", derive(TS))]
10588pub struct OnCondition {
10589    #[serde(default)]
10590    pub error: Option<Box<Expression>>,
10591    #[serde(default)]
10592    pub empty: Option<Box<Expression>>,
10593    #[serde(default)]
10594    pub null: Option<Box<Expression>>,
10595}
10596
10597/// Returning
10598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10599#[cfg_attr(feature = "bindings", derive(TS))]
10600pub struct Returning {
10601    #[serde(default)]
10602    pub expressions: Vec<Expression>,
10603    #[serde(default)]
10604    pub into: Option<Box<Expression>>,
10605}
10606
10607/// Introducer
10608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10609#[cfg_attr(feature = "bindings", derive(TS))]
10610pub struct Introducer {
10611    pub this: Box<Expression>,
10612    pub expression: Box<Expression>,
10613}
10614
10615/// PartitionRange
10616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10617#[cfg_attr(feature = "bindings", derive(TS))]
10618pub struct PartitionRange {
10619    pub this: Box<Expression>,
10620    #[serde(default)]
10621    pub expression: Option<Box<Expression>>,
10622    #[serde(default)]
10623    pub expressions: Vec<Expression>,
10624}
10625
10626/// Group
10627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10628#[cfg_attr(feature = "bindings", derive(TS))]
10629pub struct Group {
10630    #[serde(default)]
10631    pub expressions: Vec<Expression>,
10632    #[serde(default)]
10633    pub grouping_sets: Option<Box<Expression>>,
10634    #[serde(default)]
10635    pub cube: Option<Box<Expression>>,
10636    #[serde(default)]
10637    pub rollup: Option<Box<Expression>>,
10638    #[serde(default)]
10639    pub totals: Option<Box<Expression>>,
10640    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10641    #[serde(default)]
10642    pub all: Option<bool>,
10643}
10644
10645/// Cube
10646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10647#[cfg_attr(feature = "bindings", derive(TS))]
10648pub struct Cube {
10649    #[serde(default)]
10650    pub expressions: Vec<Expression>,
10651}
10652
10653/// Rollup
10654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10655#[cfg_attr(feature = "bindings", derive(TS))]
10656pub struct Rollup {
10657    #[serde(default)]
10658    pub expressions: Vec<Expression>,
10659}
10660
10661/// GroupingSets
10662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10663#[cfg_attr(feature = "bindings", derive(TS))]
10664pub struct GroupingSets {
10665    #[serde(default)]
10666    pub expressions: Vec<Expression>,
10667}
10668
10669/// LimitOptions
10670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10671#[cfg_attr(feature = "bindings", derive(TS))]
10672pub struct LimitOptions {
10673    #[serde(default)]
10674    pub percent: Option<Box<Expression>>,
10675    #[serde(default)]
10676    pub rows: Option<Box<Expression>>,
10677    #[serde(default)]
10678    pub with_ties: Option<Box<Expression>>,
10679}
10680
10681/// Lateral
10682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10683#[cfg_attr(feature = "bindings", derive(TS))]
10684pub struct Lateral {
10685    pub this: Box<Expression>,
10686    #[serde(default)]
10687    pub view: Option<Box<Expression>>,
10688    #[serde(default)]
10689    pub outer: Option<Box<Expression>>,
10690    #[serde(default)]
10691    pub alias: Option<String>,
10692    /// Whether the alias was originally quoted (backtick/double-quote)
10693    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10694    pub alias_quoted: bool,
10695    #[serde(default)]
10696    pub cross_apply: Option<Box<Expression>>,
10697    #[serde(default)]
10698    pub ordinality: Option<Box<Expression>>,
10699    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10700    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10701    pub column_aliases: Vec<String>,
10702}
10703
10704/// TableFromRows
10705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10706#[cfg_attr(feature = "bindings", derive(TS))]
10707pub struct TableFromRows {
10708    pub this: Box<Expression>,
10709    #[serde(default)]
10710    pub alias: Option<String>,
10711    #[serde(default)]
10712    pub joins: Vec<Expression>,
10713    #[serde(default)]
10714    pub pivots: Option<Box<Expression>>,
10715    #[serde(default)]
10716    pub sample: Option<Box<Expression>>,
10717}
10718
10719/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10720/// Used for set-returning functions with typed column definitions
10721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10722#[cfg_attr(feature = "bindings", derive(TS))]
10723pub struct RowsFrom {
10724    /// List of function expressions, each potentially with an alias and typed columns
10725    pub expressions: Vec<Expression>,
10726    /// WITH ORDINALITY modifier
10727    #[serde(default)]
10728    pub ordinality: bool,
10729    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10730    #[serde(default)]
10731    pub alias: Option<Box<Expression>>,
10732}
10733
10734/// WithFill
10735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10736#[cfg_attr(feature = "bindings", derive(TS))]
10737pub struct WithFill {
10738    #[serde(default)]
10739    pub from_: Option<Box<Expression>>,
10740    #[serde(default)]
10741    pub to: Option<Box<Expression>>,
10742    #[serde(default)]
10743    pub step: Option<Box<Expression>>,
10744    #[serde(default)]
10745    pub staleness: Option<Box<Expression>>,
10746    #[serde(default)]
10747    pub interpolate: Option<Box<Expression>>,
10748}
10749
10750/// Property
10751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10752#[cfg_attr(feature = "bindings", derive(TS))]
10753pub struct Property {
10754    pub this: Box<Expression>,
10755    #[serde(default)]
10756    pub value: Option<Box<Expression>>,
10757}
10758
10759/// GrantPrivilege
10760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10761#[cfg_attr(feature = "bindings", derive(TS))]
10762pub struct GrantPrivilege {
10763    pub this: Box<Expression>,
10764    #[serde(default)]
10765    pub expressions: Vec<Expression>,
10766}
10767
10768/// AllowedValuesProperty
10769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10770#[cfg_attr(feature = "bindings", derive(TS))]
10771pub struct AllowedValuesProperty {
10772    #[serde(default)]
10773    pub expressions: Vec<Expression>,
10774}
10775
10776/// AlgorithmProperty
10777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10778#[cfg_attr(feature = "bindings", derive(TS))]
10779pub struct AlgorithmProperty {
10780    pub this: Box<Expression>,
10781}
10782
10783/// AutoIncrementProperty
10784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10785#[cfg_attr(feature = "bindings", derive(TS))]
10786pub struct AutoIncrementProperty {
10787    pub this: Box<Expression>,
10788}
10789
10790/// AutoRefreshProperty
10791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10792#[cfg_attr(feature = "bindings", derive(TS))]
10793pub struct AutoRefreshProperty {
10794    pub this: Box<Expression>,
10795}
10796
10797/// BackupProperty
10798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10799#[cfg_attr(feature = "bindings", derive(TS))]
10800pub struct BackupProperty {
10801    pub this: Box<Expression>,
10802}
10803
10804/// BuildProperty
10805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10806#[cfg_attr(feature = "bindings", derive(TS))]
10807pub struct BuildProperty {
10808    pub this: Box<Expression>,
10809}
10810
10811/// BlockCompressionProperty
10812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10813#[cfg_attr(feature = "bindings", derive(TS))]
10814pub struct BlockCompressionProperty {
10815    #[serde(default)]
10816    pub autotemp: Option<Box<Expression>>,
10817    #[serde(default)]
10818    pub always: Option<Box<Expression>>,
10819    #[serde(default)]
10820    pub default: Option<Box<Expression>>,
10821    #[serde(default)]
10822    pub manual: Option<Box<Expression>>,
10823    #[serde(default)]
10824    pub never: Option<Box<Expression>>,
10825}
10826
10827/// CharacterSetProperty
10828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10829#[cfg_attr(feature = "bindings", derive(TS))]
10830pub struct CharacterSetProperty {
10831    pub this: Box<Expression>,
10832    #[serde(default)]
10833    pub default: Option<Box<Expression>>,
10834}
10835
10836/// ChecksumProperty
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct ChecksumProperty {
10840    #[serde(default)]
10841    pub on: Option<Box<Expression>>,
10842    #[serde(default)]
10843    pub default: Option<Box<Expression>>,
10844}
10845
10846/// CollateProperty
10847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10848#[cfg_attr(feature = "bindings", derive(TS))]
10849pub struct CollateProperty {
10850    pub this: Box<Expression>,
10851    #[serde(default)]
10852    pub default: Option<Box<Expression>>,
10853}
10854
10855/// DataBlocksizeProperty
10856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10857#[cfg_attr(feature = "bindings", derive(TS))]
10858pub struct DataBlocksizeProperty {
10859    #[serde(default)]
10860    pub size: Option<i64>,
10861    #[serde(default)]
10862    pub units: Option<Box<Expression>>,
10863    #[serde(default)]
10864    pub minimum: Option<Box<Expression>>,
10865    #[serde(default)]
10866    pub maximum: Option<Box<Expression>>,
10867    #[serde(default)]
10868    pub default: Option<Box<Expression>>,
10869}
10870
10871/// DataDeletionProperty
10872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10873#[cfg_attr(feature = "bindings", derive(TS))]
10874pub struct DataDeletionProperty {
10875    pub on: Box<Expression>,
10876    #[serde(default)]
10877    pub filter_column: Option<Box<Expression>>,
10878    #[serde(default)]
10879    pub retention_period: Option<Box<Expression>>,
10880}
10881
10882/// DefinerProperty
10883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10884#[cfg_attr(feature = "bindings", derive(TS))]
10885pub struct DefinerProperty {
10886    pub this: Box<Expression>,
10887}
10888
10889/// DistKeyProperty
10890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10891#[cfg_attr(feature = "bindings", derive(TS))]
10892pub struct DistKeyProperty {
10893    pub this: Box<Expression>,
10894}
10895
10896/// DistributedByProperty
10897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10898#[cfg_attr(feature = "bindings", derive(TS))]
10899pub struct DistributedByProperty {
10900    #[serde(default)]
10901    pub expressions: Vec<Expression>,
10902    pub kind: String,
10903    #[serde(default)]
10904    pub buckets: Option<Box<Expression>>,
10905    #[serde(default)]
10906    pub order: Option<Box<Expression>>,
10907}
10908
10909/// DistStyleProperty
10910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10911#[cfg_attr(feature = "bindings", derive(TS))]
10912pub struct DistStyleProperty {
10913    pub this: Box<Expression>,
10914}
10915
10916/// DuplicateKeyProperty
10917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10918#[cfg_attr(feature = "bindings", derive(TS))]
10919pub struct DuplicateKeyProperty {
10920    #[serde(default)]
10921    pub expressions: Vec<Expression>,
10922}
10923
10924/// EngineProperty
10925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10926#[cfg_attr(feature = "bindings", derive(TS))]
10927pub struct EngineProperty {
10928    pub this: Box<Expression>,
10929}
10930
10931/// ToTableProperty
10932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10933#[cfg_attr(feature = "bindings", derive(TS))]
10934pub struct ToTableProperty {
10935    pub this: Box<Expression>,
10936}
10937
10938/// ExecuteAsProperty
10939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10940#[cfg_attr(feature = "bindings", derive(TS))]
10941pub struct ExecuteAsProperty {
10942    pub this: Box<Expression>,
10943}
10944
10945/// ExternalProperty
10946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10947#[cfg_attr(feature = "bindings", derive(TS))]
10948pub struct ExternalProperty {
10949    #[serde(default)]
10950    pub this: Option<Box<Expression>>,
10951}
10952
10953/// FallbackProperty
10954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10955#[cfg_attr(feature = "bindings", derive(TS))]
10956pub struct FallbackProperty {
10957    #[serde(default)]
10958    pub no: Option<Box<Expression>>,
10959    #[serde(default)]
10960    pub protection: Option<Box<Expression>>,
10961}
10962
10963/// FileFormatProperty
10964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10965#[cfg_attr(feature = "bindings", derive(TS))]
10966pub struct FileFormatProperty {
10967    #[serde(default)]
10968    pub this: Option<Box<Expression>>,
10969    #[serde(default)]
10970    pub expressions: Vec<Expression>,
10971    #[serde(default)]
10972    pub hive_format: Option<Box<Expression>>,
10973}
10974
10975/// CredentialsProperty
10976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10977#[cfg_attr(feature = "bindings", derive(TS))]
10978pub struct CredentialsProperty {
10979    #[serde(default)]
10980    pub expressions: Vec<Expression>,
10981}
10982
10983/// FreespaceProperty
10984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10985#[cfg_attr(feature = "bindings", derive(TS))]
10986pub struct FreespaceProperty {
10987    pub this: Box<Expression>,
10988    #[serde(default)]
10989    pub percent: Option<Box<Expression>>,
10990}
10991
10992/// InheritsProperty
10993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10994#[cfg_attr(feature = "bindings", derive(TS))]
10995pub struct InheritsProperty {
10996    #[serde(default)]
10997    pub expressions: Vec<Expression>,
10998}
10999
11000/// InputModelProperty
11001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11002#[cfg_attr(feature = "bindings", derive(TS))]
11003pub struct InputModelProperty {
11004    pub this: Box<Expression>,
11005}
11006
11007/// OutputModelProperty
11008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11009#[cfg_attr(feature = "bindings", derive(TS))]
11010pub struct OutputModelProperty {
11011    pub this: Box<Expression>,
11012}
11013
11014/// IsolatedLoadingProperty
11015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11016#[cfg_attr(feature = "bindings", derive(TS))]
11017pub struct IsolatedLoadingProperty {
11018    #[serde(default)]
11019    pub no: Option<Box<Expression>>,
11020    #[serde(default)]
11021    pub concurrent: Option<Box<Expression>>,
11022    #[serde(default)]
11023    pub target: Option<Box<Expression>>,
11024}
11025
11026/// JournalProperty
11027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11028#[cfg_attr(feature = "bindings", derive(TS))]
11029pub struct JournalProperty {
11030    #[serde(default)]
11031    pub no: Option<Box<Expression>>,
11032    #[serde(default)]
11033    pub dual: Option<Box<Expression>>,
11034    #[serde(default)]
11035    pub before: Option<Box<Expression>>,
11036    #[serde(default)]
11037    pub local: Option<Box<Expression>>,
11038    #[serde(default)]
11039    pub after: Option<Box<Expression>>,
11040}
11041
11042/// LanguageProperty
11043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11044#[cfg_attr(feature = "bindings", derive(TS))]
11045pub struct LanguageProperty {
11046    pub this: Box<Expression>,
11047}
11048
11049/// EnviromentProperty
11050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11051#[cfg_attr(feature = "bindings", derive(TS))]
11052pub struct EnviromentProperty {
11053    #[serde(default)]
11054    pub expressions: Vec<Expression>,
11055}
11056
11057/// ClusteredByProperty
11058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11059#[cfg_attr(feature = "bindings", derive(TS))]
11060pub struct ClusteredByProperty {
11061    #[serde(default)]
11062    pub expressions: Vec<Expression>,
11063    #[serde(default)]
11064    pub sorted_by: Option<Box<Expression>>,
11065    #[serde(default)]
11066    pub buckets: Option<Box<Expression>>,
11067}
11068
11069/// DictProperty
11070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11071#[cfg_attr(feature = "bindings", derive(TS))]
11072pub struct DictProperty {
11073    pub this: Box<Expression>,
11074    pub kind: String,
11075    #[serde(default)]
11076    pub settings: Option<Box<Expression>>,
11077}
11078
11079/// DictRange
11080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11081#[cfg_attr(feature = "bindings", derive(TS))]
11082pub struct DictRange {
11083    pub this: Box<Expression>,
11084    #[serde(default)]
11085    pub min: Option<Box<Expression>>,
11086    #[serde(default)]
11087    pub max: Option<Box<Expression>>,
11088}
11089
11090/// OnCluster
11091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11092#[cfg_attr(feature = "bindings", derive(TS))]
11093pub struct OnCluster {
11094    pub this: Box<Expression>,
11095}
11096
11097/// LikeProperty
11098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11099#[cfg_attr(feature = "bindings", derive(TS))]
11100pub struct LikeProperty {
11101    pub this: Box<Expression>,
11102    #[serde(default)]
11103    pub expressions: Vec<Expression>,
11104}
11105
11106/// LocationProperty
11107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11108#[cfg_attr(feature = "bindings", derive(TS))]
11109pub struct LocationProperty {
11110    pub this: Box<Expression>,
11111}
11112
11113/// LockProperty
11114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11115#[cfg_attr(feature = "bindings", derive(TS))]
11116pub struct LockProperty {
11117    pub this: Box<Expression>,
11118}
11119
11120/// LockingProperty
11121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11122#[cfg_attr(feature = "bindings", derive(TS))]
11123pub struct LockingProperty {
11124    #[serde(default)]
11125    pub this: Option<Box<Expression>>,
11126    pub kind: String,
11127    #[serde(default)]
11128    pub for_or_in: Option<Box<Expression>>,
11129    #[serde(default)]
11130    pub lock_type: Option<Box<Expression>>,
11131    #[serde(default)]
11132    pub override_: Option<Box<Expression>>,
11133}
11134
11135/// LogProperty
11136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11137#[cfg_attr(feature = "bindings", derive(TS))]
11138pub struct LogProperty {
11139    #[serde(default)]
11140    pub no: Option<Box<Expression>>,
11141}
11142
11143/// MaterializedProperty
11144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11145#[cfg_attr(feature = "bindings", derive(TS))]
11146pub struct MaterializedProperty {
11147    #[serde(default)]
11148    pub this: Option<Box<Expression>>,
11149}
11150
11151/// MergeBlockRatioProperty
11152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11153#[cfg_attr(feature = "bindings", derive(TS))]
11154pub struct MergeBlockRatioProperty {
11155    #[serde(default)]
11156    pub this: Option<Box<Expression>>,
11157    #[serde(default)]
11158    pub no: Option<Box<Expression>>,
11159    #[serde(default)]
11160    pub default: Option<Box<Expression>>,
11161    #[serde(default)]
11162    pub percent: Option<Box<Expression>>,
11163}
11164
11165/// OnProperty
11166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11167#[cfg_attr(feature = "bindings", derive(TS))]
11168pub struct OnProperty {
11169    pub this: Box<Expression>,
11170}
11171
11172/// OnCommitProperty
11173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11174#[cfg_attr(feature = "bindings", derive(TS))]
11175pub struct OnCommitProperty {
11176    #[serde(default)]
11177    pub delete: Option<Box<Expression>>,
11178}
11179
11180/// PartitionedByProperty
11181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11182#[cfg_attr(feature = "bindings", derive(TS))]
11183pub struct PartitionedByProperty {
11184    pub this: Box<Expression>,
11185}
11186
11187/// BigQuery PARTITION BY property in CREATE TABLE statements.
11188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11189#[cfg_attr(feature = "bindings", derive(TS))]
11190pub struct PartitionByProperty {
11191    #[serde(default)]
11192    pub expressions: Vec<Expression>,
11193}
11194
11195/// PartitionedByBucket
11196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11197#[cfg_attr(feature = "bindings", derive(TS))]
11198pub struct PartitionedByBucket {
11199    pub this: Box<Expression>,
11200    pub expression: Box<Expression>,
11201}
11202
11203/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11205#[cfg_attr(feature = "bindings", derive(TS))]
11206pub struct ClusterByColumnsProperty {
11207    #[serde(default)]
11208    pub columns: Vec<Identifier>,
11209}
11210
11211/// PartitionByTruncate
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct PartitionByTruncate {
11215    pub this: Box<Expression>,
11216    pub expression: Box<Expression>,
11217}
11218
11219/// PartitionByRangeProperty
11220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11221#[cfg_attr(feature = "bindings", derive(TS))]
11222pub struct PartitionByRangeProperty {
11223    #[serde(default)]
11224    pub partition_expressions: Option<Box<Expression>>,
11225    #[serde(default)]
11226    pub create_expressions: Option<Box<Expression>>,
11227}
11228
11229/// PartitionByRangePropertyDynamic
11230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11231#[cfg_attr(feature = "bindings", derive(TS))]
11232pub struct PartitionByRangePropertyDynamic {
11233    #[serde(default)]
11234    pub this: Option<Box<Expression>>,
11235    #[serde(default)]
11236    pub start: Option<Box<Expression>>,
11237    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11238    #[serde(default)]
11239    pub use_start_end: bool,
11240    #[serde(default)]
11241    pub end: Option<Box<Expression>>,
11242    #[serde(default)]
11243    pub every: Option<Box<Expression>>,
11244}
11245
11246/// PartitionByListProperty
11247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11248#[cfg_attr(feature = "bindings", derive(TS))]
11249pub struct PartitionByListProperty {
11250    #[serde(default)]
11251    pub partition_expressions: Option<Box<Expression>>,
11252    #[serde(default)]
11253    pub create_expressions: Option<Box<Expression>>,
11254}
11255
11256/// PartitionList
11257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11258#[cfg_attr(feature = "bindings", derive(TS))]
11259pub struct PartitionList {
11260    pub this: Box<Expression>,
11261    #[serde(default)]
11262    pub expressions: Vec<Expression>,
11263}
11264
11265/// Partition - represents PARTITION/SUBPARTITION clause
11266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11267#[cfg_attr(feature = "bindings", derive(TS))]
11268pub struct Partition {
11269    pub expressions: Vec<Expression>,
11270    #[serde(default)]
11271    pub subpartition: bool,
11272}
11273
11274/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11275/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11277#[cfg_attr(feature = "bindings", derive(TS))]
11278pub struct RefreshTriggerProperty {
11279    /// Method: COMPLETE or AUTO
11280    pub method: String,
11281    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11282    #[serde(default)]
11283    pub kind: Option<String>,
11284    /// For SCHEDULE: EVERY n (the number)
11285    #[serde(default)]
11286    pub every: Option<Box<Expression>>,
11287    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11288    #[serde(default)]
11289    pub unit: Option<String>,
11290    /// For SCHEDULE: STARTS 'datetime'
11291    #[serde(default)]
11292    pub starts: Option<Box<Expression>>,
11293}
11294
11295/// UniqueKeyProperty
11296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11297#[cfg_attr(feature = "bindings", derive(TS))]
11298pub struct UniqueKeyProperty {
11299    #[serde(default)]
11300    pub expressions: Vec<Expression>,
11301}
11302
11303/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11305#[cfg_attr(feature = "bindings", derive(TS))]
11306pub struct RollupProperty {
11307    pub expressions: Vec<RollupIndex>,
11308}
11309
11310/// RollupIndex - A single rollup index: name(col1, col2)
11311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11312#[cfg_attr(feature = "bindings", derive(TS))]
11313pub struct RollupIndex {
11314    pub name: Identifier,
11315    pub expressions: Vec<Identifier>,
11316}
11317
11318/// PartitionBoundSpec
11319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11320#[cfg_attr(feature = "bindings", derive(TS))]
11321pub struct PartitionBoundSpec {
11322    #[serde(default)]
11323    pub this: Option<Box<Expression>>,
11324    #[serde(default)]
11325    pub expression: Option<Box<Expression>>,
11326    #[serde(default)]
11327    pub from_expressions: Option<Box<Expression>>,
11328    #[serde(default)]
11329    pub to_expressions: Option<Box<Expression>>,
11330}
11331
11332/// PartitionedOfProperty
11333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11334#[cfg_attr(feature = "bindings", derive(TS))]
11335pub struct PartitionedOfProperty {
11336    pub this: Box<Expression>,
11337    pub expression: Box<Expression>,
11338}
11339
11340/// RemoteWithConnectionModelProperty
11341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11342#[cfg_attr(feature = "bindings", derive(TS))]
11343pub struct RemoteWithConnectionModelProperty {
11344    pub this: Box<Expression>,
11345}
11346
11347/// ReturnsProperty
11348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11349#[cfg_attr(feature = "bindings", derive(TS))]
11350pub struct ReturnsProperty {
11351    #[serde(default)]
11352    pub this: Option<Box<Expression>>,
11353    #[serde(default)]
11354    pub is_table: Option<Box<Expression>>,
11355    #[serde(default)]
11356    pub table: Option<Box<Expression>>,
11357    #[serde(default)]
11358    pub null: Option<Box<Expression>>,
11359}
11360
11361/// RowFormatProperty
11362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11363#[cfg_attr(feature = "bindings", derive(TS))]
11364pub struct RowFormatProperty {
11365    pub this: Box<Expression>,
11366}
11367
11368/// RowFormatDelimitedProperty
11369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11370#[cfg_attr(feature = "bindings", derive(TS))]
11371pub struct RowFormatDelimitedProperty {
11372    #[serde(default)]
11373    pub fields: Option<Box<Expression>>,
11374    #[serde(default)]
11375    pub escaped: Option<Box<Expression>>,
11376    #[serde(default)]
11377    pub collection_items: Option<Box<Expression>>,
11378    #[serde(default)]
11379    pub map_keys: Option<Box<Expression>>,
11380    #[serde(default)]
11381    pub lines: Option<Box<Expression>>,
11382    #[serde(default)]
11383    pub null: Option<Box<Expression>>,
11384    #[serde(default)]
11385    pub serde: Option<Box<Expression>>,
11386}
11387
11388/// RowFormatSerdeProperty
11389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11390#[cfg_attr(feature = "bindings", derive(TS))]
11391pub struct RowFormatSerdeProperty {
11392    pub this: Box<Expression>,
11393    #[serde(default)]
11394    pub serde_properties: Option<Box<Expression>>,
11395}
11396
11397/// QueryTransform
11398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11399#[cfg_attr(feature = "bindings", derive(TS))]
11400pub struct QueryTransform {
11401    #[serde(default)]
11402    pub expressions: Vec<Expression>,
11403    #[serde(default)]
11404    pub command_script: Option<Box<Expression>>,
11405    #[serde(default)]
11406    pub schema: Option<Box<Expression>>,
11407    #[serde(default)]
11408    pub row_format_before: Option<Box<Expression>>,
11409    #[serde(default)]
11410    pub record_writer: Option<Box<Expression>>,
11411    #[serde(default)]
11412    pub row_format_after: Option<Box<Expression>>,
11413    #[serde(default)]
11414    pub record_reader: Option<Box<Expression>>,
11415}
11416
11417/// SampleProperty
11418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11419#[cfg_attr(feature = "bindings", derive(TS))]
11420pub struct SampleProperty {
11421    pub this: Box<Expression>,
11422}
11423
11424/// SecurityProperty
11425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11426#[cfg_attr(feature = "bindings", derive(TS))]
11427pub struct SecurityProperty {
11428    pub this: Box<Expression>,
11429}
11430
11431/// SchemaCommentProperty
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct SchemaCommentProperty {
11435    pub this: Box<Expression>,
11436}
11437
11438/// SemanticView
11439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11440#[cfg_attr(feature = "bindings", derive(TS))]
11441pub struct SemanticView {
11442    pub this: Box<Expression>,
11443    #[serde(default)]
11444    pub metrics: Option<Box<Expression>>,
11445    #[serde(default)]
11446    pub dimensions: Option<Box<Expression>>,
11447    #[serde(default)]
11448    pub facts: Option<Box<Expression>>,
11449    #[serde(default)]
11450    pub where_: Option<Box<Expression>>,
11451}
11452
11453/// SerdeProperties
11454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11455#[cfg_attr(feature = "bindings", derive(TS))]
11456pub struct SerdeProperties {
11457    #[serde(default)]
11458    pub expressions: Vec<Expression>,
11459    #[serde(default)]
11460    pub with_: Option<Box<Expression>>,
11461}
11462
11463/// SetProperty
11464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11465#[cfg_attr(feature = "bindings", derive(TS))]
11466pub struct SetProperty {
11467    #[serde(default)]
11468    pub multi: Option<Box<Expression>>,
11469}
11470
11471/// SharingProperty
11472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11473#[cfg_attr(feature = "bindings", derive(TS))]
11474pub struct SharingProperty {
11475    #[serde(default)]
11476    pub this: Option<Box<Expression>>,
11477}
11478
11479/// SetConfigProperty
11480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11481#[cfg_attr(feature = "bindings", derive(TS))]
11482pub struct SetConfigProperty {
11483    pub this: Box<Expression>,
11484}
11485
11486/// SettingsProperty
11487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11488#[cfg_attr(feature = "bindings", derive(TS))]
11489pub struct SettingsProperty {
11490    #[serde(default)]
11491    pub expressions: Vec<Expression>,
11492}
11493
11494/// SortKeyProperty
11495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11496#[cfg_attr(feature = "bindings", derive(TS))]
11497pub struct SortKeyProperty {
11498    pub this: Box<Expression>,
11499    #[serde(default)]
11500    pub compound: Option<Box<Expression>>,
11501}
11502
11503/// SqlReadWriteProperty
11504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11505#[cfg_attr(feature = "bindings", derive(TS))]
11506pub struct SqlReadWriteProperty {
11507    pub this: Box<Expression>,
11508}
11509
11510/// SqlSecurityProperty
11511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11512#[cfg_attr(feature = "bindings", derive(TS))]
11513pub struct SqlSecurityProperty {
11514    pub this: Box<Expression>,
11515}
11516
11517/// StabilityProperty
11518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11519#[cfg_attr(feature = "bindings", derive(TS))]
11520pub struct StabilityProperty {
11521    pub this: Box<Expression>,
11522}
11523
11524/// StorageHandlerProperty
11525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11526#[cfg_attr(feature = "bindings", derive(TS))]
11527pub struct StorageHandlerProperty {
11528    pub this: Box<Expression>,
11529}
11530
11531/// TemporaryProperty
11532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11533#[cfg_attr(feature = "bindings", derive(TS))]
11534pub struct TemporaryProperty {
11535    #[serde(default)]
11536    pub this: Option<Box<Expression>>,
11537}
11538
11539/// Tags
11540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11541#[cfg_attr(feature = "bindings", derive(TS))]
11542pub struct Tags {
11543    #[serde(default)]
11544    pub expressions: Vec<Expression>,
11545}
11546
11547/// TransformModelProperty
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct TransformModelProperty {
11551    #[serde(default)]
11552    pub expressions: Vec<Expression>,
11553}
11554
11555/// TransientProperty
11556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11557#[cfg_attr(feature = "bindings", derive(TS))]
11558pub struct TransientProperty {
11559    #[serde(default)]
11560    pub this: Option<Box<Expression>>,
11561}
11562
11563/// UsingTemplateProperty
11564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11565#[cfg_attr(feature = "bindings", derive(TS))]
11566pub struct UsingTemplateProperty {
11567    pub this: Box<Expression>,
11568}
11569
11570/// ViewAttributeProperty
11571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11572#[cfg_attr(feature = "bindings", derive(TS))]
11573pub struct ViewAttributeProperty {
11574    pub this: Box<Expression>,
11575}
11576
11577/// VolatileProperty
11578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11579#[cfg_attr(feature = "bindings", derive(TS))]
11580pub struct VolatileProperty {
11581    #[serde(default)]
11582    pub this: Option<Box<Expression>>,
11583}
11584
11585/// WithDataProperty
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct WithDataProperty {
11589    #[serde(default)]
11590    pub no: Option<Box<Expression>>,
11591    #[serde(default)]
11592    pub statistics: Option<Box<Expression>>,
11593}
11594
11595/// WithJournalTableProperty
11596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11597#[cfg_attr(feature = "bindings", derive(TS))]
11598pub struct WithJournalTableProperty {
11599    pub this: Box<Expression>,
11600}
11601
11602/// WithSchemaBindingProperty
11603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11604#[cfg_attr(feature = "bindings", derive(TS))]
11605pub struct WithSchemaBindingProperty {
11606    pub this: Box<Expression>,
11607}
11608
11609/// WithSystemVersioningProperty
11610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11611#[cfg_attr(feature = "bindings", derive(TS))]
11612pub struct WithSystemVersioningProperty {
11613    #[serde(default)]
11614    pub on: Option<Box<Expression>>,
11615    #[serde(default)]
11616    pub this: Option<Box<Expression>>,
11617    #[serde(default)]
11618    pub data_consistency: Option<Box<Expression>>,
11619    #[serde(default)]
11620    pub retention_period: Option<Box<Expression>>,
11621    #[serde(default)]
11622    pub with_: Option<Box<Expression>>,
11623}
11624
11625/// WithProcedureOptions
11626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11627#[cfg_attr(feature = "bindings", derive(TS))]
11628pub struct WithProcedureOptions {
11629    #[serde(default)]
11630    pub expressions: Vec<Expression>,
11631}
11632
11633/// EncodeProperty
11634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11635#[cfg_attr(feature = "bindings", derive(TS))]
11636pub struct EncodeProperty {
11637    pub this: Box<Expression>,
11638    #[serde(default)]
11639    pub properties: Vec<Expression>,
11640    #[serde(default)]
11641    pub key: Option<Box<Expression>>,
11642}
11643
11644/// IncludeProperty
11645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11646#[cfg_attr(feature = "bindings", derive(TS))]
11647pub struct IncludeProperty {
11648    pub this: Box<Expression>,
11649    #[serde(default)]
11650    pub alias: Option<String>,
11651    #[serde(default)]
11652    pub column_def: Option<Box<Expression>>,
11653}
11654
11655/// Properties
11656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11657#[cfg_attr(feature = "bindings", derive(TS))]
11658pub struct Properties {
11659    #[serde(default)]
11660    pub expressions: Vec<Expression>,
11661}
11662
11663/// Key/value pair in a BigQuery OPTIONS (...) clause.
11664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11665#[cfg_attr(feature = "bindings", derive(TS))]
11666pub struct OptionEntry {
11667    pub key: Identifier,
11668    pub value: Expression,
11669}
11670
11671/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11673#[cfg_attr(feature = "bindings", derive(TS))]
11674pub struct OptionsProperty {
11675    #[serde(default)]
11676    pub entries: Vec<OptionEntry>,
11677}
11678
11679/// InputOutputFormat
11680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11681#[cfg_attr(feature = "bindings", derive(TS))]
11682pub struct InputOutputFormat {
11683    #[serde(default)]
11684    pub input_format: Option<Box<Expression>>,
11685    #[serde(default)]
11686    pub output_format: Option<Box<Expression>>,
11687}
11688
11689/// Reference
11690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11691#[cfg_attr(feature = "bindings", derive(TS))]
11692pub struct Reference {
11693    pub this: Box<Expression>,
11694    #[serde(default)]
11695    pub expressions: Vec<Expression>,
11696    #[serde(default)]
11697    pub options: Vec<Expression>,
11698}
11699
11700/// QueryOption
11701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11702#[cfg_attr(feature = "bindings", derive(TS))]
11703pub struct QueryOption {
11704    pub this: Box<Expression>,
11705    #[serde(default)]
11706    pub expression: Option<Box<Expression>>,
11707}
11708
11709/// WithTableHint
11710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11711#[cfg_attr(feature = "bindings", derive(TS))]
11712pub struct WithTableHint {
11713    #[serde(default)]
11714    pub expressions: Vec<Expression>,
11715}
11716
11717/// IndexTableHint
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct IndexTableHint {
11721    pub this: Box<Expression>,
11722    #[serde(default)]
11723    pub expressions: Vec<Expression>,
11724    #[serde(default)]
11725    pub target: Option<Box<Expression>>,
11726}
11727
11728/// Get
11729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11730#[cfg_attr(feature = "bindings", derive(TS))]
11731pub struct Get {
11732    pub this: Box<Expression>,
11733    #[serde(default)]
11734    pub target: Option<Box<Expression>>,
11735    #[serde(default)]
11736    pub properties: Vec<Expression>,
11737}
11738
11739/// SetOperation
11740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11741#[cfg_attr(feature = "bindings", derive(TS))]
11742pub struct SetOperation {
11743    #[serde(default)]
11744    pub with_: Option<Box<Expression>>,
11745    pub this: Box<Expression>,
11746    pub expression: Box<Expression>,
11747    #[serde(default)]
11748    pub distinct: bool,
11749    #[serde(default)]
11750    pub by_name: Option<Box<Expression>>,
11751    #[serde(default)]
11752    pub side: Option<Box<Expression>>,
11753    #[serde(default)]
11754    pub kind: Option<String>,
11755    #[serde(default)]
11756    pub on: Option<Box<Expression>>,
11757}
11758
11759/// Var - Simple variable reference (for SQL variables, keywords as values)
11760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11761#[cfg_attr(feature = "bindings", derive(TS))]
11762pub struct Var {
11763    pub this: String,
11764}
11765
11766/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11768#[cfg_attr(feature = "bindings", derive(TS))]
11769pub struct Variadic {
11770    pub this: Box<Expression>,
11771}
11772
11773/// Version
11774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11775#[cfg_attr(feature = "bindings", derive(TS))]
11776pub struct Version {
11777    pub this: Box<Expression>,
11778    pub kind: String,
11779    #[serde(default)]
11780    pub expression: Option<Box<Expression>>,
11781}
11782
11783/// Schema
11784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11785#[cfg_attr(feature = "bindings", derive(TS))]
11786pub struct Schema {
11787    #[serde(default)]
11788    pub this: Option<Box<Expression>>,
11789    #[serde(default)]
11790    pub expressions: Vec<Expression>,
11791}
11792
11793/// Lock
11794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11795#[cfg_attr(feature = "bindings", derive(TS))]
11796pub struct Lock {
11797    #[serde(default)]
11798    pub update: Option<Box<Expression>>,
11799    #[serde(default)]
11800    pub expressions: Vec<Expression>,
11801    #[serde(default)]
11802    pub wait: Option<Box<Expression>>,
11803    #[serde(default)]
11804    pub key: Option<Box<Expression>>,
11805}
11806
11807/// TableSample - wraps an expression with a TABLESAMPLE clause
11808/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11810#[cfg_attr(feature = "bindings", derive(TS))]
11811pub struct TableSample {
11812    /// The expression being sampled (subquery, function, etc.)
11813    #[serde(default, skip_serializing_if = "Option::is_none")]
11814    pub this: Option<Box<Expression>>,
11815    /// The sample specification
11816    #[serde(default, skip_serializing_if = "Option::is_none")]
11817    pub sample: Option<Box<Sample>>,
11818    #[serde(default)]
11819    pub expressions: Vec<Expression>,
11820    #[serde(default)]
11821    pub method: Option<String>,
11822    #[serde(default)]
11823    pub bucket_numerator: Option<Box<Expression>>,
11824    #[serde(default)]
11825    pub bucket_denominator: Option<Box<Expression>>,
11826    #[serde(default)]
11827    pub bucket_field: Option<Box<Expression>>,
11828    #[serde(default)]
11829    pub percent: Option<Box<Expression>>,
11830    #[serde(default)]
11831    pub rows: Option<Box<Expression>>,
11832    #[serde(default)]
11833    pub size: Option<i64>,
11834    #[serde(default)]
11835    pub seed: Option<Box<Expression>>,
11836}
11837
11838/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11840#[cfg_attr(feature = "bindings", derive(TS))]
11841pub struct Tag {
11842    #[serde(default)]
11843    pub this: Option<Box<Expression>>,
11844    #[serde(default)]
11845    pub prefix: Option<Box<Expression>>,
11846    #[serde(default)]
11847    pub postfix: Option<Box<Expression>>,
11848}
11849
11850/// UnpivotColumns
11851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11852#[cfg_attr(feature = "bindings", derive(TS))]
11853pub struct UnpivotColumns {
11854    pub this: Box<Expression>,
11855    #[serde(default)]
11856    pub expressions: Vec<Expression>,
11857}
11858
11859/// SessionParameter
11860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11861#[cfg_attr(feature = "bindings", derive(TS))]
11862pub struct SessionParameter {
11863    pub this: Box<Expression>,
11864    #[serde(default)]
11865    pub kind: Option<String>,
11866}
11867
11868/// PseudoType
11869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11870#[cfg_attr(feature = "bindings", derive(TS))]
11871pub struct PseudoType {
11872    pub this: Box<Expression>,
11873}
11874
11875/// ObjectIdentifier
11876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11877#[cfg_attr(feature = "bindings", derive(TS))]
11878pub struct ObjectIdentifier {
11879    pub this: Box<Expression>,
11880}
11881
11882/// Transaction
11883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11884#[cfg_attr(feature = "bindings", derive(TS))]
11885pub struct Transaction {
11886    #[serde(default)]
11887    pub this: Option<Box<Expression>>,
11888    #[serde(default)]
11889    pub modes: Option<Box<Expression>>,
11890    #[serde(default)]
11891    pub mark: Option<Box<Expression>>,
11892}
11893
11894/// Commit
11895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11896#[cfg_attr(feature = "bindings", derive(TS))]
11897pub struct Commit {
11898    #[serde(default)]
11899    pub chain: Option<Box<Expression>>,
11900    #[serde(default)]
11901    pub this: Option<Box<Expression>>,
11902    #[serde(default)]
11903    pub durability: Option<Box<Expression>>,
11904}
11905
11906/// Rollback
11907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11908#[cfg_attr(feature = "bindings", derive(TS))]
11909pub struct Rollback {
11910    #[serde(default)]
11911    pub savepoint: Option<Box<Expression>>,
11912    #[serde(default)]
11913    pub this: Option<Box<Expression>>,
11914}
11915
11916/// AlterSession
11917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11918#[cfg_attr(feature = "bindings", derive(TS))]
11919pub struct AlterSession {
11920    #[serde(default)]
11921    pub expressions: Vec<Expression>,
11922    #[serde(default)]
11923    pub unset: Option<Box<Expression>>,
11924}
11925
11926/// Analyze
11927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11928#[cfg_attr(feature = "bindings", derive(TS))]
11929pub struct Analyze {
11930    #[serde(default)]
11931    pub kind: Option<String>,
11932    #[serde(default)]
11933    pub this: Option<Box<Expression>>,
11934    #[serde(default)]
11935    pub options: Vec<Expression>,
11936    #[serde(default)]
11937    pub mode: Option<Box<Expression>>,
11938    #[serde(default)]
11939    pub partition: Option<Box<Expression>>,
11940    #[serde(default)]
11941    pub expression: Option<Box<Expression>>,
11942    #[serde(default)]
11943    pub properties: Vec<Expression>,
11944    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
11945    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11946    pub columns: Vec<String>,
11947}
11948
11949/// AnalyzeStatistics
11950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11951#[cfg_attr(feature = "bindings", derive(TS))]
11952pub struct AnalyzeStatistics {
11953    pub kind: String,
11954    #[serde(default)]
11955    pub option: Option<Box<Expression>>,
11956    #[serde(default)]
11957    pub this: Option<Box<Expression>>,
11958    #[serde(default)]
11959    pub expressions: Vec<Expression>,
11960}
11961
11962/// AnalyzeHistogram
11963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11964#[cfg_attr(feature = "bindings", derive(TS))]
11965pub struct AnalyzeHistogram {
11966    pub this: Box<Expression>,
11967    #[serde(default)]
11968    pub expressions: Vec<Expression>,
11969    #[serde(default)]
11970    pub expression: Option<Box<Expression>>,
11971    #[serde(default)]
11972    pub update_options: Option<Box<Expression>>,
11973}
11974
11975/// AnalyzeSample
11976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11977#[cfg_attr(feature = "bindings", derive(TS))]
11978pub struct AnalyzeSample {
11979    pub kind: String,
11980    #[serde(default)]
11981    pub sample: Option<Box<Expression>>,
11982}
11983
11984/// AnalyzeListChainedRows
11985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11986#[cfg_attr(feature = "bindings", derive(TS))]
11987pub struct AnalyzeListChainedRows {
11988    #[serde(default)]
11989    pub expression: Option<Box<Expression>>,
11990}
11991
11992/// AnalyzeDelete
11993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11994#[cfg_attr(feature = "bindings", derive(TS))]
11995pub struct AnalyzeDelete {
11996    #[serde(default)]
11997    pub kind: Option<String>,
11998}
11999
12000/// AnalyzeWith
12001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12002#[cfg_attr(feature = "bindings", derive(TS))]
12003pub struct AnalyzeWith {
12004    #[serde(default)]
12005    pub expressions: Vec<Expression>,
12006}
12007
12008/// AnalyzeValidate
12009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12010#[cfg_attr(feature = "bindings", derive(TS))]
12011pub struct AnalyzeValidate {
12012    pub kind: String,
12013    #[serde(default)]
12014    pub this: Option<Box<Expression>>,
12015    #[serde(default)]
12016    pub expression: Option<Box<Expression>>,
12017}
12018
12019/// AddPartition
12020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12021#[cfg_attr(feature = "bindings", derive(TS))]
12022pub struct AddPartition {
12023    pub this: Box<Expression>,
12024    #[serde(default)]
12025    pub exists: bool,
12026    #[serde(default)]
12027    pub location: Option<Box<Expression>>,
12028}
12029
12030/// AttachOption
12031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12032#[cfg_attr(feature = "bindings", derive(TS))]
12033pub struct AttachOption {
12034    pub this: Box<Expression>,
12035    #[serde(default)]
12036    pub expression: Option<Box<Expression>>,
12037}
12038
12039/// DropPartition
12040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12041#[cfg_attr(feature = "bindings", derive(TS))]
12042pub struct DropPartition {
12043    #[serde(default)]
12044    pub expressions: Vec<Expression>,
12045    #[serde(default)]
12046    pub exists: bool,
12047}
12048
12049/// ReplacePartition
12050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12051#[cfg_attr(feature = "bindings", derive(TS))]
12052pub struct ReplacePartition {
12053    pub expression: Box<Expression>,
12054    #[serde(default)]
12055    pub source: Option<Box<Expression>>,
12056}
12057
12058/// DPipe
12059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12060#[cfg_attr(feature = "bindings", derive(TS))]
12061pub struct DPipe {
12062    pub this: Box<Expression>,
12063    pub expression: Box<Expression>,
12064    #[serde(default)]
12065    pub safe: Option<Box<Expression>>,
12066}
12067
12068/// Operator
12069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12070#[cfg_attr(feature = "bindings", derive(TS))]
12071pub struct Operator {
12072    pub this: Box<Expression>,
12073    #[serde(default)]
12074    pub operator: Option<Box<Expression>>,
12075    pub expression: Box<Expression>,
12076    /// Comments between OPERATOR() and the RHS expression
12077    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12078    pub comments: Vec<String>,
12079}
12080
12081/// PivotAny
12082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12083#[cfg_attr(feature = "bindings", derive(TS))]
12084pub struct PivotAny {
12085    #[serde(default)]
12086    pub this: Option<Box<Expression>>,
12087}
12088
12089/// Aliases
12090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12091#[cfg_attr(feature = "bindings", derive(TS))]
12092pub struct Aliases {
12093    pub this: Box<Expression>,
12094    #[serde(default)]
12095    pub expressions: Vec<Expression>,
12096}
12097
12098/// AtIndex
12099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12100#[cfg_attr(feature = "bindings", derive(TS))]
12101pub struct AtIndex {
12102    pub this: Box<Expression>,
12103    pub expression: Box<Expression>,
12104}
12105
12106/// FromTimeZone
12107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12108#[cfg_attr(feature = "bindings", derive(TS))]
12109pub struct FromTimeZone {
12110    pub this: Box<Expression>,
12111    #[serde(default)]
12112    pub zone: Option<Box<Expression>>,
12113}
12114
12115/// Format override for a column in Teradata
12116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12117#[cfg_attr(feature = "bindings", derive(TS))]
12118pub struct FormatPhrase {
12119    pub this: Box<Expression>,
12120    pub format: String,
12121}
12122
12123/// ForIn
12124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12125#[cfg_attr(feature = "bindings", derive(TS))]
12126pub struct ForIn {
12127    pub this: Box<Expression>,
12128    pub expression: Box<Expression>,
12129}
12130
12131/// Automatically converts unit arg into a var.
12132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12133#[cfg_attr(feature = "bindings", derive(TS))]
12134pub struct TimeUnit {
12135    #[serde(default)]
12136    pub unit: Option<String>,
12137}
12138
12139/// IntervalOp
12140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12141#[cfg_attr(feature = "bindings", derive(TS))]
12142pub struct IntervalOp {
12143    #[serde(default)]
12144    pub unit: Option<String>,
12145    pub expression: Box<Expression>,
12146}
12147
12148/// HavingMax
12149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12150#[cfg_attr(feature = "bindings", derive(TS))]
12151pub struct HavingMax {
12152    pub this: Box<Expression>,
12153    pub expression: Box<Expression>,
12154    #[serde(default)]
12155    pub max: Option<Box<Expression>>,
12156}
12157
12158/// CosineDistance
12159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12160#[cfg_attr(feature = "bindings", derive(TS))]
12161pub struct CosineDistance {
12162    pub this: Box<Expression>,
12163    pub expression: Box<Expression>,
12164}
12165
12166/// DotProduct
12167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12168#[cfg_attr(feature = "bindings", derive(TS))]
12169pub struct DotProduct {
12170    pub this: Box<Expression>,
12171    pub expression: Box<Expression>,
12172}
12173
12174/// EuclideanDistance
12175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12176#[cfg_attr(feature = "bindings", derive(TS))]
12177pub struct EuclideanDistance {
12178    pub this: Box<Expression>,
12179    pub expression: Box<Expression>,
12180}
12181
12182/// ManhattanDistance
12183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12184#[cfg_attr(feature = "bindings", derive(TS))]
12185pub struct ManhattanDistance {
12186    pub this: Box<Expression>,
12187    pub expression: Box<Expression>,
12188}
12189
12190/// JarowinklerSimilarity
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct JarowinklerSimilarity {
12194    pub this: Box<Expression>,
12195    pub expression: Box<Expression>,
12196}
12197
12198/// Booland
12199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12200#[cfg_attr(feature = "bindings", derive(TS))]
12201pub struct Booland {
12202    pub this: Box<Expression>,
12203    pub expression: Box<Expression>,
12204}
12205
12206/// Boolor
12207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12208#[cfg_attr(feature = "bindings", derive(TS))]
12209pub struct Boolor {
12210    pub this: Box<Expression>,
12211    pub expression: Box<Expression>,
12212}
12213
12214/// ParameterizedAgg
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct ParameterizedAgg {
12218    pub this: Box<Expression>,
12219    #[serde(default)]
12220    pub expressions: Vec<Expression>,
12221    #[serde(default)]
12222    pub params: Vec<Expression>,
12223}
12224
12225/// ArgMax
12226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12227#[cfg_attr(feature = "bindings", derive(TS))]
12228pub struct ArgMax {
12229    pub this: Box<Expression>,
12230    pub expression: Box<Expression>,
12231    #[serde(default)]
12232    pub count: Option<Box<Expression>>,
12233}
12234
12235/// ArgMin
12236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12237#[cfg_attr(feature = "bindings", derive(TS))]
12238pub struct ArgMin {
12239    pub this: Box<Expression>,
12240    pub expression: Box<Expression>,
12241    #[serde(default)]
12242    pub count: Option<Box<Expression>>,
12243}
12244
12245/// ApproxTopK
12246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12247#[cfg_attr(feature = "bindings", derive(TS))]
12248pub struct ApproxTopK {
12249    pub this: Box<Expression>,
12250    #[serde(default)]
12251    pub expression: Option<Box<Expression>>,
12252    #[serde(default)]
12253    pub counters: Option<Box<Expression>>,
12254}
12255
12256/// ApproxTopKAccumulate
12257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12258#[cfg_attr(feature = "bindings", derive(TS))]
12259pub struct ApproxTopKAccumulate {
12260    pub this: Box<Expression>,
12261    #[serde(default)]
12262    pub expression: Option<Box<Expression>>,
12263}
12264
12265/// ApproxTopKCombine
12266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12267#[cfg_attr(feature = "bindings", derive(TS))]
12268pub struct ApproxTopKCombine {
12269    pub this: Box<Expression>,
12270    #[serde(default)]
12271    pub expression: Option<Box<Expression>>,
12272}
12273
12274/// ApproxTopKEstimate
12275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12276#[cfg_attr(feature = "bindings", derive(TS))]
12277pub struct ApproxTopKEstimate {
12278    pub this: Box<Expression>,
12279    #[serde(default)]
12280    pub expression: Option<Box<Expression>>,
12281}
12282
12283/// ApproxTopSum
12284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12285#[cfg_attr(feature = "bindings", derive(TS))]
12286pub struct ApproxTopSum {
12287    pub this: Box<Expression>,
12288    pub expression: Box<Expression>,
12289    #[serde(default)]
12290    pub count: Option<Box<Expression>>,
12291}
12292
12293/// ApproxQuantiles
12294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12295#[cfg_attr(feature = "bindings", derive(TS))]
12296pub struct ApproxQuantiles {
12297    pub this: Box<Expression>,
12298    #[serde(default)]
12299    pub expression: Option<Box<Expression>>,
12300}
12301
12302/// Minhash
12303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12304#[cfg_attr(feature = "bindings", derive(TS))]
12305pub struct Minhash {
12306    pub this: Box<Expression>,
12307    #[serde(default)]
12308    pub expressions: Vec<Expression>,
12309}
12310
12311/// FarmFingerprint
12312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12313#[cfg_attr(feature = "bindings", derive(TS))]
12314pub struct FarmFingerprint {
12315    #[serde(default)]
12316    pub expressions: Vec<Expression>,
12317}
12318
12319/// Float64
12320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12321#[cfg_attr(feature = "bindings", derive(TS))]
12322pub struct Float64 {
12323    pub this: Box<Expression>,
12324    #[serde(default)]
12325    pub expression: Option<Box<Expression>>,
12326}
12327
12328/// Transform
12329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12330#[cfg_attr(feature = "bindings", derive(TS))]
12331pub struct Transform {
12332    pub this: Box<Expression>,
12333    pub expression: Box<Expression>,
12334}
12335
12336/// Translate
12337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12338#[cfg_attr(feature = "bindings", derive(TS))]
12339pub struct Translate {
12340    pub this: Box<Expression>,
12341    #[serde(default)]
12342    pub from_: Option<Box<Expression>>,
12343    #[serde(default)]
12344    pub to: Option<Box<Expression>>,
12345}
12346
12347/// Grouping
12348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12349#[cfg_attr(feature = "bindings", derive(TS))]
12350pub struct Grouping {
12351    #[serde(default)]
12352    pub expressions: Vec<Expression>,
12353}
12354
12355/// GroupingId
12356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12357#[cfg_attr(feature = "bindings", derive(TS))]
12358pub struct GroupingId {
12359    #[serde(default)]
12360    pub expressions: Vec<Expression>,
12361}
12362
12363/// Anonymous
12364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12365#[cfg_attr(feature = "bindings", derive(TS))]
12366pub struct Anonymous {
12367    pub this: Box<Expression>,
12368    #[serde(default)]
12369    pub expressions: Vec<Expression>,
12370}
12371
12372/// AnonymousAggFunc
12373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12374#[cfg_attr(feature = "bindings", derive(TS))]
12375pub struct AnonymousAggFunc {
12376    pub this: Box<Expression>,
12377    #[serde(default)]
12378    pub expressions: Vec<Expression>,
12379}
12380
12381/// CombinedAggFunc
12382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12383#[cfg_attr(feature = "bindings", derive(TS))]
12384pub struct CombinedAggFunc {
12385    pub this: Box<Expression>,
12386    #[serde(default)]
12387    pub expressions: Vec<Expression>,
12388}
12389
12390/// CombinedParameterizedAgg
12391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12392#[cfg_attr(feature = "bindings", derive(TS))]
12393pub struct CombinedParameterizedAgg {
12394    pub this: Box<Expression>,
12395    #[serde(default)]
12396    pub expressions: Vec<Expression>,
12397    #[serde(default)]
12398    pub params: Vec<Expression>,
12399}
12400
12401/// HashAgg
12402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12403#[cfg_attr(feature = "bindings", derive(TS))]
12404pub struct HashAgg {
12405    pub this: Box<Expression>,
12406    #[serde(default)]
12407    pub expressions: Vec<Expression>,
12408}
12409
12410/// Hll
12411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12412#[cfg_attr(feature = "bindings", derive(TS))]
12413pub struct Hll {
12414    pub this: Box<Expression>,
12415    #[serde(default)]
12416    pub expressions: Vec<Expression>,
12417}
12418
12419/// Apply
12420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12421#[cfg_attr(feature = "bindings", derive(TS))]
12422pub struct Apply {
12423    pub this: Box<Expression>,
12424    pub expression: Box<Expression>,
12425}
12426
12427/// ToBoolean
12428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12429#[cfg_attr(feature = "bindings", derive(TS))]
12430pub struct ToBoolean {
12431    pub this: Box<Expression>,
12432    #[serde(default)]
12433    pub safe: Option<Box<Expression>>,
12434}
12435
12436/// List
12437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12438#[cfg_attr(feature = "bindings", derive(TS))]
12439pub struct List {
12440    #[serde(default)]
12441    pub expressions: Vec<Expression>,
12442}
12443
12444/// ToMap - Materialize-style map constructor
12445/// Can hold either:
12446/// - A SELECT subquery (MAP(SELECT 'a', 1))
12447/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12449#[cfg_attr(feature = "bindings", derive(TS))]
12450pub struct ToMap {
12451    /// Either a Select subquery or a Struct containing PropertyEQ entries
12452    pub this: Box<Expression>,
12453}
12454
12455/// Pad
12456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12457#[cfg_attr(feature = "bindings", derive(TS))]
12458pub struct Pad {
12459    pub this: Box<Expression>,
12460    pub expression: Box<Expression>,
12461    #[serde(default)]
12462    pub fill_pattern: Option<Box<Expression>>,
12463    #[serde(default)]
12464    pub is_left: Option<Box<Expression>>,
12465}
12466
12467/// ToChar
12468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12469#[cfg_attr(feature = "bindings", derive(TS))]
12470pub struct ToChar {
12471    pub this: Box<Expression>,
12472    #[serde(default)]
12473    pub format: Option<String>,
12474    #[serde(default)]
12475    pub nlsparam: Option<Box<Expression>>,
12476    #[serde(default)]
12477    pub is_numeric: Option<Box<Expression>>,
12478}
12479
12480/// StringFunc - String type conversion function (BigQuery STRING)
12481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12482#[cfg_attr(feature = "bindings", derive(TS))]
12483pub struct StringFunc {
12484    pub this: Box<Expression>,
12485    #[serde(default)]
12486    pub zone: Option<Box<Expression>>,
12487}
12488
12489/// ToNumber
12490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12491#[cfg_attr(feature = "bindings", derive(TS))]
12492pub struct ToNumber {
12493    pub this: Box<Expression>,
12494    #[serde(default)]
12495    pub format: Option<Box<Expression>>,
12496    #[serde(default)]
12497    pub nlsparam: Option<Box<Expression>>,
12498    #[serde(default)]
12499    pub precision: Option<Box<Expression>>,
12500    #[serde(default)]
12501    pub scale: Option<Box<Expression>>,
12502    #[serde(default)]
12503    pub safe: Option<Box<Expression>>,
12504    #[serde(default)]
12505    pub safe_name: Option<Box<Expression>>,
12506}
12507
12508/// ToDouble
12509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12510#[cfg_attr(feature = "bindings", derive(TS))]
12511pub struct ToDouble {
12512    pub this: Box<Expression>,
12513    #[serde(default)]
12514    pub format: Option<String>,
12515    #[serde(default)]
12516    pub safe: Option<Box<Expression>>,
12517}
12518
12519/// ToDecfloat
12520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12521#[cfg_attr(feature = "bindings", derive(TS))]
12522pub struct ToDecfloat {
12523    pub this: Box<Expression>,
12524    #[serde(default)]
12525    pub format: Option<String>,
12526}
12527
12528/// TryToDecfloat
12529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12530#[cfg_attr(feature = "bindings", derive(TS))]
12531pub struct TryToDecfloat {
12532    pub this: Box<Expression>,
12533    #[serde(default)]
12534    pub format: Option<String>,
12535}
12536
12537/// ToFile
12538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12539#[cfg_attr(feature = "bindings", derive(TS))]
12540pub struct ToFile {
12541    pub this: Box<Expression>,
12542    #[serde(default)]
12543    pub path: Option<Box<Expression>>,
12544    #[serde(default)]
12545    pub safe: Option<Box<Expression>>,
12546}
12547
12548/// Columns
12549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12550#[cfg_attr(feature = "bindings", derive(TS))]
12551pub struct Columns {
12552    pub this: Box<Expression>,
12553    #[serde(default)]
12554    pub unpack: Option<Box<Expression>>,
12555}
12556
12557/// ConvertToCharset
12558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12559#[cfg_attr(feature = "bindings", derive(TS))]
12560pub struct ConvertToCharset {
12561    pub this: Box<Expression>,
12562    #[serde(default)]
12563    pub dest: Option<Box<Expression>>,
12564    #[serde(default)]
12565    pub source: Option<Box<Expression>>,
12566}
12567
12568/// ConvertTimezone
12569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12570#[cfg_attr(feature = "bindings", derive(TS))]
12571pub struct ConvertTimezone {
12572    #[serde(default)]
12573    pub source_tz: Option<Box<Expression>>,
12574    #[serde(default)]
12575    pub target_tz: Option<Box<Expression>>,
12576    #[serde(default)]
12577    pub timestamp: Option<Box<Expression>>,
12578    #[serde(default)]
12579    pub options: Vec<Expression>,
12580}
12581
12582/// GenerateSeries
12583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12584#[cfg_attr(feature = "bindings", derive(TS))]
12585pub struct GenerateSeries {
12586    #[serde(default)]
12587    pub start: Option<Box<Expression>>,
12588    #[serde(default)]
12589    pub end: Option<Box<Expression>>,
12590    #[serde(default)]
12591    pub step: Option<Box<Expression>>,
12592    #[serde(default)]
12593    pub is_end_exclusive: Option<Box<Expression>>,
12594}
12595
12596/// AIAgg
12597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12598#[cfg_attr(feature = "bindings", derive(TS))]
12599pub struct AIAgg {
12600    pub this: Box<Expression>,
12601    pub expression: Box<Expression>,
12602}
12603
12604/// AIClassify
12605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12606#[cfg_attr(feature = "bindings", derive(TS))]
12607pub struct AIClassify {
12608    pub this: Box<Expression>,
12609    #[serde(default)]
12610    pub categories: Option<Box<Expression>>,
12611    #[serde(default)]
12612    pub config: Option<Box<Expression>>,
12613}
12614
12615/// ArrayAll
12616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12617#[cfg_attr(feature = "bindings", derive(TS))]
12618pub struct ArrayAll {
12619    pub this: Box<Expression>,
12620    pub expression: Box<Expression>,
12621}
12622
12623/// ArrayAny
12624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12625#[cfg_attr(feature = "bindings", derive(TS))]
12626pub struct ArrayAny {
12627    pub this: Box<Expression>,
12628    pub expression: Box<Expression>,
12629}
12630
12631/// ArrayConstructCompact
12632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12633#[cfg_attr(feature = "bindings", derive(TS))]
12634pub struct ArrayConstructCompact {
12635    #[serde(default)]
12636    pub expressions: Vec<Expression>,
12637}
12638
12639/// StPoint
12640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12641#[cfg_attr(feature = "bindings", derive(TS))]
12642pub struct StPoint {
12643    pub this: Box<Expression>,
12644    pub expression: Box<Expression>,
12645    #[serde(default)]
12646    pub null: Option<Box<Expression>>,
12647}
12648
12649/// StDistance
12650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12651#[cfg_attr(feature = "bindings", derive(TS))]
12652pub struct StDistance {
12653    pub this: Box<Expression>,
12654    pub expression: Box<Expression>,
12655    #[serde(default)]
12656    pub use_spheroid: Option<Box<Expression>>,
12657}
12658
12659/// StringToArray
12660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12661#[cfg_attr(feature = "bindings", derive(TS))]
12662pub struct StringToArray {
12663    pub this: Box<Expression>,
12664    #[serde(default)]
12665    pub expression: Option<Box<Expression>>,
12666    #[serde(default)]
12667    pub null: Option<Box<Expression>>,
12668}
12669
12670/// ArraySum
12671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12672#[cfg_attr(feature = "bindings", derive(TS))]
12673pub struct ArraySum {
12674    pub this: Box<Expression>,
12675    #[serde(default)]
12676    pub expression: Option<Box<Expression>>,
12677}
12678
12679/// ObjectAgg
12680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12681#[cfg_attr(feature = "bindings", derive(TS))]
12682pub struct ObjectAgg {
12683    pub this: Box<Expression>,
12684    pub expression: Box<Expression>,
12685}
12686
12687/// CastToStrType
12688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12689#[cfg_attr(feature = "bindings", derive(TS))]
12690pub struct CastToStrType {
12691    pub this: Box<Expression>,
12692    #[serde(default)]
12693    pub to: Option<Box<Expression>>,
12694}
12695
12696/// CheckJson
12697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12698#[cfg_attr(feature = "bindings", derive(TS))]
12699pub struct CheckJson {
12700    pub this: Box<Expression>,
12701}
12702
12703/// CheckXml
12704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12705#[cfg_attr(feature = "bindings", derive(TS))]
12706pub struct CheckXml {
12707    pub this: Box<Expression>,
12708    #[serde(default)]
12709    pub disable_auto_convert: Option<Box<Expression>>,
12710}
12711
12712/// TranslateCharacters
12713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12714#[cfg_attr(feature = "bindings", derive(TS))]
12715pub struct TranslateCharacters {
12716    pub this: Box<Expression>,
12717    pub expression: Box<Expression>,
12718    #[serde(default)]
12719    pub with_error: Option<Box<Expression>>,
12720}
12721
12722/// CurrentSchemas
12723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12724#[cfg_attr(feature = "bindings", derive(TS))]
12725pub struct CurrentSchemas {
12726    #[serde(default)]
12727    pub this: Option<Box<Expression>>,
12728}
12729
12730/// CurrentDatetime
12731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12732#[cfg_attr(feature = "bindings", derive(TS))]
12733pub struct CurrentDatetime {
12734    #[serde(default)]
12735    pub this: Option<Box<Expression>>,
12736}
12737
12738/// Localtime
12739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12740#[cfg_attr(feature = "bindings", derive(TS))]
12741pub struct Localtime {
12742    #[serde(default)]
12743    pub this: Option<Box<Expression>>,
12744}
12745
12746/// Localtimestamp
12747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12748#[cfg_attr(feature = "bindings", derive(TS))]
12749pub struct Localtimestamp {
12750    #[serde(default)]
12751    pub this: Option<Box<Expression>>,
12752}
12753
12754/// Systimestamp
12755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12756#[cfg_attr(feature = "bindings", derive(TS))]
12757pub struct Systimestamp {
12758    #[serde(default)]
12759    pub this: Option<Box<Expression>>,
12760}
12761
12762/// CurrentSchema
12763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12764#[cfg_attr(feature = "bindings", derive(TS))]
12765pub struct CurrentSchema {
12766    #[serde(default)]
12767    pub this: Option<Box<Expression>>,
12768}
12769
12770/// CurrentUser
12771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12772#[cfg_attr(feature = "bindings", derive(TS))]
12773pub struct CurrentUser {
12774    #[serde(default)]
12775    pub this: Option<Box<Expression>>,
12776}
12777
12778/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12780#[cfg_attr(feature = "bindings", derive(TS))]
12781pub struct SessionUser;
12782
12783/// JSONPathRoot - Represents $ in JSON path expressions
12784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12785#[cfg_attr(feature = "bindings", derive(TS))]
12786pub struct JSONPathRoot;
12787
12788/// UtcTime
12789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12790#[cfg_attr(feature = "bindings", derive(TS))]
12791pub struct UtcTime {
12792    #[serde(default)]
12793    pub this: Option<Box<Expression>>,
12794}
12795
12796/// UtcTimestamp
12797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12798#[cfg_attr(feature = "bindings", derive(TS))]
12799pub struct UtcTimestamp {
12800    #[serde(default)]
12801    pub this: Option<Box<Expression>>,
12802}
12803
12804/// TimestampFunc - TIMESTAMP constructor function
12805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12806#[cfg_attr(feature = "bindings", derive(TS))]
12807pub struct TimestampFunc {
12808    #[serde(default)]
12809    pub this: Option<Box<Expression>>,
12810    #[serde(default)]
12811    pub zone: Option<Box<Expression>>,
12812    #[serde(default)]
12813    pub with_tz: Option<bool>,
12814    #[serde(default)]
12815    pub safe: Option<bool>,
12816}
12817
12818/// DateBin
12819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12820#[cfg_attr(feature = "bindings", derive(TS))]
12821pub struct DateBin {
12822    pub this: Box<Expression>,
12823    pub expression: Box<Expression>,
12824    #[serde(default)]
12825    pub unit: Option<String>,
12826    #[serde(default)]
12827    pub zone: Option<Box<Expression>>,
12828    #[serde(default)]
12829    pub origin: Option<Box<Expression>>,
12830}
12831
12832/// Datetime
12833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12834#[cfg_attr(feature = "bindings", derive(TS))]
12835pub struct Datetime {
12836    pub this: Box<Expression>,
12837    #[serde(default)]
12838    pub expression: Option<Box<Expression>>,
12839}
12840
12841/// DatetimeAdd
12842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12843#[cfg_attr(feature = "bindings", derive(TS))]
12844pub struct DatetimeAdd {
12845    pub this: Box<Expression>,
12846    pub expression: Box<Expression>,
12847    #[serde(default)]
12848    pub unit: Option<String>,
12849}
12850
12851/// DatetimeSub
12852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12853#[cfg_attr(feature = "bindings", derive(TS))]
12854pub struct DatetimeSub {
12855    pub this: Box<Expression>,
12856    pub expression: Box<Expression>,
12857    #[serde(default)]
12858    pub unit: Option<String>,
12859}
12860
12861/// DatetimeDiff
12862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12863#[cfg_attr(feature = "bindings", derive(TS))]
12864pub struct DatetimeDiff {
12865    pub this: Box<Expression>,
12866    pub expression: Box<Expression>,
12867    #[serde(default)]
12868    pub unit: Option<String>,
12869}
12870
12871/// DatetimeTrunc
12872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12873#[cfg_attr(feature = "bindings", derive(TS))]
12874pub struct DatetimeTrunc {
12875    pub this: Box<Expression>,
12876    pub unit: String,
12877    #[serde(default)]
12878    pub zone: Option<Box<Expression>>,
12879}
12880
12881/// Dayname
12882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12883#[cfg_attr(feature = "bindings", derive(TS))]
12884pub struct Dayname {
12885    pub this: Box<Expression>,
12886    #[serde(default)]
12887    pub abbreviated: Option<Box<Expression>>,
12888}
12889
12890/// MakeInterval
12891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12892#[cfg_attr(feature = "bindings", derive(TS))]
12893pub struct MakeInterval {
12894    #[serde(default)]
12895    pub year: Option<Box<Expression>>,
12896    #[serde(default)]
12897    pub month: Option<Box<Expression>>,
12898    #[serde(default)]
12899    pub week: Option<Box<Expression>>,
12900    #[serde(default)]
12901    pub day: Option<Box<Expression>>,
12902    #[serde(default)]
12903    pub hour: Option<Box<Expression>>,
12904    #[serde(default)]
12905    pub minute: Option<Box<Expression>>,
12906    #[serde(default)]
12907    pub second: Option<Box<Expression>>,
12908}
12909
12910/// PreviousDay
12911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12912#[cfg_attr(feature = "bindings", derive(TS))]
12913pub struct PreviousDay {
12914    pub this: Box<Expression>,
12915    pub expression: Box<Expression>,
12916}
12917
12918/// Elt
12919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12920#[cfg_attr(feature = "bindings", derive(TS))]
12921pub struct Elt {
12922    pub this: Box<Expression>,
12923    #[serde(default)]
12924    pub expressions: Vec<Expression>,
12925}
12926
12927/// TimestampAdd
12928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12929#[cfg_attr(feature = "bindings", derive(TS))]
12930pub struct TimestampAdd {
12931    pub this: Box<Expression>,
12932    pub expression: Box<Expression>,
12933    #[serde(default)]
12934    pub unit: Option<String>,
12935}
12936
12937/// TimestampSub
12938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12939#[cfg_attr(feature = "bindings", derive(TS))]
12940pub struct TimestampSub {
12941    pub this: Box<Expression>,
12942    pub expression: Box<Expression>,
12943    #[serde(default)]
12944    pub unit: Option<String>,
12945}
12946
12947/// TimestampDiff
12948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12949#[cfg_attr(feature = "bindings", derive(TS))]
12950pub struct TimestampDiff {
12951    pub this: Box<Expression>,
12952    pub expression: Box<Expression>,
12953    #[serde(default)]
12954    pub unit: Option<String>,
12955}
12956
12957/// TimeSlice
12958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12959#[cfg_attr(feature = "bindings", derive(TS))]
12960pub struct TimeSlice {
12961    pub this: Box<Expression>,
12962    pub expression: Box<Expression>,
12963    pub unit: String,
12964    #[serde(default)]
12965    pub kind: Option<String>,
12966}
12967
12968/// TimeAdd
12969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12970#[cfg_attr(feature = "bindings", derive(TS))]
12971pub struct TimeAdd {
12972    pub this: Box<Expression>,
12973    pub expression: Box<Expression>,
12974    #[serde(default)]
12975    pub unit: Option<String>,
12976}
12977
12978/// TimeSub
12979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12980#[cfg_attr(feature = "bindings", derive(TS))]
12981pub struct TimeSub {
12982    pub this: Box<Expression>,
12983    pub expression: Box<Expression>,
12984    #[serde(default)]
12985    pub unit: Option<String>,
12986}
12987
12988/// TimeDiff
12989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12990#[cfg_attr(feature = "bindings", derive(TS))]
12991pub struct TimeDiff {
12992    pub this: Box<Expression>,
12993    pub expression: Box<Expression>,
12994    #[serde(default)]
12995    pub unit: Option<String>,
12996}
12997
12998/// TimeTrunc
12999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13000#[cfg_attr(feature = "bindings", derive(TS))]
13001pub struct TimeTrunc {
13002    pub this: Box<Expression>,
13003    pub unit: String,
13004    #[serde(default)]
13005    pub zone: Option<Box<Expression>>,
13006}
13007
13008/// DateFromParts
13009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13010#[cfg_attr(feature = "bindings", derive(TS))]
13011pub struct DateFromParts {
13012    #[serde(default)]
13013    pub year: Option<Box<Expression>>,
13014    #[serde(default)]
13015    pub month: Option<Box<Expression>>,
13016    #[serde(default)]
13017    pub day: Option<Box<Expression>>,
13018    #[serde(default)]
13019    pub allow_overflow: Option<Box<Expression>>,
13020}
13021
13022/// TimeFromParts
13023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13024#[cfg_attr(feature = "bindings", derive(TS))]
13025pub struct TimeFromParts {
13026    #[serde(default)]
13027    pub hour: Option<Box<Expression>>,
13028    #[serde(default)]
13029    pub min: Option<Box<Expression>>,
13030    #[serde(default)]
13031    pub sec: Option<Box<Expression>>,
13032    #[serde(default)]
13033    pub nano: Option<Box<Expression>>,
13034    #[serde(default)]
13035    pub fractions: Option<Box<Expression>>,
13036    #[serde(default)]
13037    pub precision: Option<i64>,
13038}
13039
13040/// DecodeCase
13041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13042#[cfg_attr(feature = "bindings", derive(TS))]
13043pub struct DecodeCase {
13044    #[serde(default)]
13045    pub expressions: Vec<Expression>,
13046}
13047
13048/// Decrypt
13049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13050#[cfg_attr(feature = "bindings", derive(TS))]
13051pub struct Decrypt {
13052    pub this: Box<Expression>,
13053    #[serde(default)]
13054    pub passphrase: Option<Box<Expression>>,
13055    #[serde(default)]
13056    pub aad: Option<Box<Expression>>,
13057    #[serde(default)]
13058    pub encryption_method: Option<Box<Expression>>,
13059    #[serde(default)]
13060    pub safe: Option<Box<Expression>>,
13061}
13062
13063/// DecryptRaw
13064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13065#[cfg_attr(feature = "bindings", derive(TS))]
13066pub struct DecryptRaw {
13067    pub this: Box<Expression>,
13068    #[serde(default)]
13069    pub key: Option<Box<Expression>>,
13070    #[serde(default)]
13071    pub iv: Option<Box<Expression>>,
13072    #[serde(default)]
13073    pub aad: Option<Box<Expression>>,
13074    #[serde(default)]
13075    pub encryption_method: Option<Box<Expression>>,
13076    #[serde(default)]
13077    pub aead: Option<Box<Expression>>,
13078    #[serde(default)]
13079    pub safe: Option<Box<Expression>>,
13080}
13081
13082/// Encode
13083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13084#[cfg_attr(feature = "bindings", derive(TS))]
13085pub struct Encode {
13086    pub this: Box<Expression>,
13087    #[serde(default)]
13088    pub charset: Option<Box<Expression>>,
13089}
13090
13091/// Encrypt
13092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13093#[cfg_attr(feature = "bindings", derive(TS))]
13094pub struct Encrypt {
13095    pub this: Box<Expression>,
13096    #[serde(default)]
13097    pub passphrase: Option<Box<Expression>>,
13098    #[serde(default)]
13099    pub aad: Option<Box<Expression>>,
13100    #[serde(default)]
13101    pub encryption_method: Option<Box<Expression>>,
13102}
13103
13104/// EncryptRaw
13105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13106#[cfg_attr(feature = "bindings", derive(TS))]
13107pub struct EncryptRaw {
13108    pub this: Box<Expression>,
13109    #[serde(default)]
13110    pub key: Option<Box<Expression>>,
13111    #[serde(default)]
13112    pub iv: Option<Box<Expression>>,
13113    #[serde(default)]
13114    pub aad: Option<Box<Expression>>,
13115    #[serde(default)]
13116    pub encryption_method: Option<Box<Expression>>,
13117}
13118
13119/// EqualNull
13120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13121#[cfg_attr(feature = "bindings", derive(TS))]
13122pub struct EqualNull {
13123    pub this: Box<Expression>,
13124    pub expression: Box<Expression>,
13125}
13126
13127/// ToBinary
13128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13129#[cfg_attr(feature = "bindings", derive(TS))]
13130pub struct ToBinary {
13131    pub this: Box<Expression>,
13132    #[serde(default)]
13133    pub format: Option<String>,
13134    #[serde(default)]
13135    pub safe: Option<Box<Expression>>,
13136}
13137
13138/// Base64DecodeBinary
13139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13140#[cfg_attr(feature = "bindings", derive(TS))]
13141pub struct Base64DecodeBinary {
13142    pub this: Box<Expression>,
13143    #[serde(default)]
13144    pub alphabet: Option<Box<Expression>>,
13145}
13146
13147/// Base64DecodeString
13148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13149#[cfg_attr(feature = "bindings", derive(TS))]
13150pub struct Base64DecodeString {
13151    pub this: Box<Expression>,
13152    #[serde(default)]
13153    pub alphabet: Option<Box<Expression>>,
13154}
13155
13156/// Base64Encode
13157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13158#[cfg_attr(feature = "bindings", derive(TS))]
13159pub struct Base64Encode {
13160    pub this: Box<Expression>,
13161    #[serde(default)]
13162    pub max_line_length: Option<Box<Expression>>,
13163    #[serde(default)]
13164    pub alphabet: Option<Box<Expression>>,
13165}
13166
13167/// TryBase64DecodeBinary
13168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13169#[cfg_attr(feature = "bindings", derive(TS))]
13170pub struct TryBase64DecodeBinary {
13171    pub this: Box<Expression>,
13172    #[serde(default)]
13173    pub alphabet: Option<Box<Expression>>,
13174}
13175
13176/// TryBase64DecodeString
13177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13178#[cfg_attr(feature = "bindings", derive(TS))]
13179pub struct TryBase64DecodeString {
13180    pub this: Box<Expression>,
13181    #[serde(default)]
13182    pub alphabet: Option<Box<Expression>>,
13183}
13184
13185/// GapFill
13186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13187#[cfg_attr(feature = "bindings", derive(TS))]
13188pub struct GapFill {
13189    pub this: Box<Expression>,
13190    #[serde(default)]
13191    pub ts_column: Option<Box<Expression>>,
13192    #[serde(default)]
13193    pub bucket_width: Option<Box<Expression>>,
13194    #[serde(default)]
13195    pub partitioning_columns: Option<Box<Expression>>,
13196    #[serde(default)]
13197    pub value_columns: Option<Box<Expression>>,
13198    #[serde(default)]
13199    pub origin: Option<Box<Expression>>,
13200    #[serde(default)]
13201    pub ignore_nulls: Option<Box<Expression>>,
13202}
13203
13204/// GenerateDateArray
13205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13206#[cfg_attr(feature = "bindings", derive(TS))]
13207pub struct GenerateDateArray {
13208    #[serde(default)]
13209    pub start: Option<Box<Expression>>,
13210    #[serde(default)]
13211    pub end: Option<Box<Expression>>,
13212    #[serde(default)]
13213    pub step: Option<Box<Expression>>,
13214}
13215
13216/// GenerateTimestampArray
13217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13218#[cfg_attr(feature = "bindings", derive(TS))]
13219pub struct GenerateTimestampArray {
13220    #[serde(default)]
13221    pub start: Option<Box<Expression>>,
13222    #[serde(default)]
13223    pub end: Option<Box<Expression>>,
13224    #[serde(default)]
13225    pub step: Option<Box<Expression>>,
13226}
13227
13228/// GetExtract
13229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13230#[cfg_attr(feature = "bindings", derive(TS))]
13231pub struct GetExtract {
13232    pub this: Box<Expression>,
13233    pub expression: Box<Expression>,
13234}
13235
13236/// Getbit
13237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13238#[cfg_attr(feature = "bindings", derive(TS))]
13239pub struct Getbit {
13240    pub this: Box<Expression>,
13241    pub expression: Box<Expression>,
13242    #[serde(default)]
13243    pub zero_is_msb: Option<Box<Expression>>,
13244}
13245
13246/// OverflowTruncateBehavior
13247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13248#[cfg_attr(feature = "bindings", derive(TS))]
13249pub struct OverflowTruncateBehavior {
13250    #[serde(default)]
13251    pub this: Option<Box<Expression>>,
13252    #[serde(default)]
13253    pub with_count: Option<Box<Expression>>,
13254}
13255
13256/// HexEncode
13257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13258#[cfg_attr(feature = "bindings", derive(TS))]
13259pub struct HexEncode {
13260    pub this: Box<Expression>,
13261    #[serde(default)]
13262    pub case: Option<Box<Expression>>,
13263}
13264
13265/// Compress
13266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13267#[cfg_attr(feature = "bindings", derive(TS))]
13268pub struct Compress {
13269    pub this: Box<Expression>,
13270    #[serde(default)]
13271    pub method: Option<String>,
13272}
13273
13274/// DecompressBinary
13275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13276#[cfg_attr(feature = "bindings", derive(TS))]
13277pub struct DecompressBinary {
13278    pub this: Box<Expression>,
13279    pub method: String,
13280}
13281
13282/// DecompressString
13283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13284#[cfg_attr(feature = "bindings", derive(TS))]
13285pub struct DecompressString {
13286    pub this: Box<Expression>,
13287    pub method: String,
13288}
13289
13290/// Xor
13291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13292#[cfg_attr(feature = "bindings", derive(TS))]
13293pub struct Xor {
13294    #[serde(default)]
13295    pub this: Option<Box<Expression>>,
13296    #[serde(default)]
13297    pub expression: Option<Box<Expression>>,
13298    #[serde(default)]
13299    pub expressions: Vec<Expression>,
13300}
13301
13302/// Nullif
13303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13304#[cfg_attr(feature = "bindings", derive(TS))]
13305pub struct Nullif {
13306    pub this: Box<Expression>,
13307    pub expression: Box<Expression>,
13308}
13309
13310/// JSON
13311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13312#[cfg_attr(feature = "bindings", derive(TS))]
13313pub struct JSON {
13314    #[serde(default)]
13315    pub this: Option<Box<Expression>>,
13316    #[serde(default)]
13317    pub with_: Option<Box<Expression>>,
13318    #[serde(default)]
13319    pub unique: bool,
13320}
13321
13322/// JSONPath
13323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13324#[cfg_attr(feature = "bindings", derive(TS))]
13325pub struct JSONPath {
13326    #[serde(default)]
13327    pub expressions: Vec<Expression>,
13328    #[serde(default)]
13329    pub escape: Option<Box<Expression>>,
13330}
13331
13332/// JSONPathFilter
13333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13334#[cfg_attr(feature = "bindings", derive(TS))]
13335pub struct JSONPathFilter {
13336    pub this: Box<Expression>,
13337}
13338
13339/// JSONPathKey
13340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13341#[cfg_attr(feature = "bindings", derive(TS))]
13342pub struct JSONPathKey {
13343    pub this: Box<Expression>,
13344}
13345
13346/// JSONPathRecursive
13347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13348#[cfg_attr(feature = "bindings", derive(TS))]
13349pub struct JSONPathRecursive {
13350    #[serde(default)]
13351    pub this: Option<Box<Expression>>,
13352}
13353
13354/// JSONPathScript
13355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13356#[cfg_attr(feature = "bindings", derive(TS))]
13357pub struct JSONPathScript {
13358    pub this: Box<Expression>,
13359}
13360
13361/// JSONPathSlice
13362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13363#[cfg_attr(feature = "bindings", derive(TS))]
13364pub struct JSONPathSlice {
13365    #[serde(default)]
13366    pub start: Option<Box<Expression>>,
13367    #[serde(default)]
13368    pub end: Option<Box<Expression>>,
13369    #[serde(default)]
13370    pub step: Option<Box<Expression>>,
13371}
13372
13373/// JSONPathSelector
13374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13375#[cfg_attr(feature = "bindings", derive(TS))]
13376pub struct JSONPathSelector {
13377    pub this: Box<Expression>,
13378}
13379
13380/// JSONPathSubscript
13381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13382#[cfg_attr(feature = "bindings", derive(TS))]
13383pub struct JSONPathSubscript {
13384    pub this: Box<Expression>,
13385}
13386
13387/// JSONPathUnion
13388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13389#[cfg_attr(feature = "bindings", derive(TS))]
13390pub struct JSONPathUnion {
13391    #[serde(default)]
13392    pub expressions: Vec<Expression>,
13393}
13394
13395/// Format
13396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13397#[cfg_attr(feature = "bindings", derive(TS))]
13398pub struct Format {
13399    pub this: Box<Expression>,
13400    #[serde(default)]
13401    pub expressions: Vec<Expression>,
13402}
13403
13404/// JSONKeys
13405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13406#[cfg_attr(feature = "bindings", derive(TS))]
13407pub struct JSONKeys {
13408    pub this: Box<Expression>,
13409    #[serde(default)]
13410    pub expression: Option<Box<Expression>>,
13411    #[serde(default)]
13412    pub expressions: Vec<Expression>,
13413}
13414
13415/// JSONKeyValue
13416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13417#[cfg_attr(feature = "bindings", derive(TS))]
13418pub struct JSONKeyValue {
13419    pub this: Box<Expression>,
13420    pub expression: Box<Expression>,
13421}
13422
13423/// JSONKeysAtDepth
13424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13425#[cfg_attr(feature = "bindings", derive(TS))]
13426pub struct JSONKeysAtDepth {
13427    pub this: Box<Expression>,
13428    #[serde(default)]
13429    pub expression: Option<Box<Expression>>,
13430    #[serde(default)]
13431    pub mode: Option<Box<Expression>>,
13432}
13433
13434/// JSONObject
13435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13436#[cfg_attr(feature = "bindings", derive(TS))]
13437pub struct JSONObject {
13438    #[serde(default)]
13439    pub expressions: Vec<Expression>,
13440    #[serde(default)]
13441    pub null_handling: Option<Box<Expression>>,
13442    #[serde(default)]
13443    pub unique_keys: Option<Box<Expression>>,
13444    #[serde(default)]
13445    pub return_type: Option<Box<Expression>>,
13446    #[serde(default)]
13447    pub encoding: Option<Box<Expression>>,
13448}
13449
13450/// JSONObjectAgg
13451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13452#[cfg_attr(feature = "bindings", derive(TS))]
13453pub struct JSONObjectAgg {
13454    #[serde(default)]
13455    pub expressions: Vec<Expression>,
13456    #[serde(default)]
13457    pub null_handling: Option<Box<Expression>>,
13458    #[serde(default)]
13459    pub unique_keys: Option<Box<Expression>>,
13460    #[serde(default)]
13461    pub return_type: Option<Box<Expression>>,
13462    #[serde(default)]
13463    pub encoding: Option<Box<Expression>>,
13464}
13465
13466/// JSONBObjectAgg
13467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13468#[cfg_attr(feature = "bindings", derive(TS))]
13469pub struct JSONBObjectAgg {
13470    pub this: Box<Expression>,
13471    pub expression: Box<Expression>,
13472}
13473
13474/// JSONArray
13475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13476#[cfg_attr(feature = "bindings", derive(TS))]
13477pub struct JSONArray {
13478    #[serde(default)]
13479    pub expressions: Vec<Expression>,
13480    #[serde(default)]
13481    pub null_handling: Option<Box<Expression>>,
13482    #[serde(default)]
13483    pub return_type: Option<Box<Expression>>,
13484    #[serde(default)]
13485    pub strict: Option<Box<Expression>>,
13486}
13487
13488/// JSONArrayAgg
13489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13490#[cfg_attr(feature = "bindings", derive(TS))]
13491pub struct JSONArrayAgg {
13492    pub this: Box<Expression>,
13493    #[serde(default)]
13494    pub order: Option<Box<Expression>>,
13495    #[serde(default)]
13496    pub null_handling: Option<Box<Expression>>,
13497    #[serde(default)]
13498    pub return_type: Option<Box<Expression>>,
13499    #[serde(default)]
13500    pub strict: Option<Box<Expression>>,
13501}
13502
13503/// JSONExists
13504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13505#[cfg_attr(feature = "bindings", derive(TS))]
13506pub struct JSONExists {
13507    pub this: Box<Expression>,
13508    #[serde(default)]
13509    pub path: Option<Box<Expression>>,
13510    #[serde(default)]
13511    pub passing: Option<Box<Expression>>,
13512    #[serde(default)]
13513    pub on_condition: Option<Box<Expression>>,
13514    #[serde(default)]
13515    pub from_dcolonqmark: Option<Box<Expression>>,
13516}
13517
13518/// JSONColumnDef
13519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13520#[cfg_attr(feature = "bindings", derive(TS))]
13521pub struct JSONColumnDef {
13522    #[serde(default)]
13523    pub this: Option<Box<Expression>>,
13524    #[serde(default)]
13525    pub kind: Option<String>,
13526    #[serde(default)]
13527    pub path: Option<Box<Expression>>,
13528    #[serde(default)]
13529    pub nested_schema: Option<Box<Expression>>,
13530    #[serde(default)]
13531    pub ordinality: Option<Box<Expression>>,
13532}
13533
13534/// JSONSchema
13535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13536#[cfg_attr(feature = "bindings", derive(TS))]
13537pub struct JSONSchema {
13538    #[serde(default)]
13539    pub expressions: Vec<Expression>,
13540}
13541
13542/// JSONSet
13543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13544#[cfg_attr(feature = "bindings", derive(TS))]
13545pub struct JSONSet {
13546    pub this: Box<Expression>,
13547    #[serde(default)]
13548    pub expressions: Vec<Expression>,
13549}
13550
13551/// JSONStripNulls
13552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13553#[cfg_attr(feature = "bindings", derive(TS))]
13554pub struct JSONStripNulls {
13555    pub this: Box<Expression>,
13556    #[serde(default)]
13557    pub expression: Option<Box<Expression>>,
13558    #[serde(default)]
13559    pub include_arrays: Option<Box<Expression>>,
13560    #[serde(default)]
13561    pub remove_empty: Option<Box<Expression>>,
13562}
13563
13564/// JSONValue
13565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13566#[cfg_attr(feature = "bindings", derive(TS))]
13567pub struct JSONValue {
13568    pub this: Box<Expression>,
13569    #[serde(default)]
13570    pub path: Option<Box<Expression>>,
13571    #[serde(default)]
13572    pub returning: Option<Box<Expression>>,
13573    #[serde(default)]
13574    pub on_condition: Option<Box<Expression>>,
13575}
13576
13577/// JSONValueArray
13578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13579#[cfg_attr(feature = "bindings", derive(TS))]
13580pub struct JSONValueArray {
13581    pub this: Box<Expression>,
13582    #[serde(default)]
13583    pub expression: Option<Box<Expression>>,
13584}
13585
13586/// JSONRemove
13587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13588#[cfg_attr(feature = "bindings", derive(TS))]
13589pub struct JSONRemove {
13590    pub this: Box<Expression>,
13591    #[serde(default)]
13592    pub expressions: Vec<Expression>,
13593}
13594
13595/// JSONTable
13596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13597#[cfg_attr(feature = "bindings", derive(TS))]
13598pub struct JSONTable {
13599    pub this: Box<Expression>,
13600    #[serde(default)]
13601    pub schema: Option<Box<Expression>>,
13602    #[serde(default)]
13603    pub path: Option<Box<Expression>>,
13604    #[serde(default)]
13605    pub error_handling: Option<Box<Expression>>,
13606    #[serde(default)]
13607    pub empty_handling: Option<Box<Expression>>,
13608}
13609
13610/// JSONType
13611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13612#[cfg_attr(feature = "bindings", derive(TS))]
13613pub struct JSONType {
13614    pub this: Box<Expression>,
13615    #[serde(default)]
13616    pub expression: Option<Box<Expression>>,
13617}
13618
13619/// ObjectInsert
13620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13621#[cfg_attr(feature = "bindings", derive(TS))]
13622pub struct ObjectInsert {
13623    pub this: Box<Expression>,
13624    #[serde(default)]
13625    pub key: Option<Box<Expression>>,
13626    #[serde(default)]
13627    pub value: Option<Box<Expression>>,
13628    #[serde(default)]
13629    pub update_flag: Option<Box<Expression>>,
13630}
13631
13632/// OpenJSONColumnDef
13633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13634#[cfg_attr(feature = "bindings", derive(TS))]
13635pub struct OpenJSONColumnDef {
13636    pub this: Box<Expression>,
13637    pub kind: String,
13638    #[serde(default)]
13639    pub path: Option<Box<Expression>>,
13640    #[serde(default)]
13641    pub as_json: Option<Box<Expression>>,
13642    /// The parsed data type for proper generation
13643    #[serde(default, skip_serializing_if = "Option::is_none")]
13644    pub data_type: Option<DataType>,
13645}
13646
13647/// OpenJSON
13648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13649#[cfg_attr(feature = "bindings", derive(TS))]
13650pub struct OpenJSON {
13651    pub this: Box<Expression>,
13652    #[serde(default)]
13653    pub path: Option<Box<Expression>>,
13654    #[serde(default)]
13655    pub expressions: Vec<Expression>,
13656}
13657
13658/// JSONBExists
13659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13660#[cfg_attr(feature = "bindings", derive(TS))]
13661pub struct JSONBExists {
13662    pub this: Box<Expression>,
13663    #[serde(default)]
13664    pub path: Option<Box<Expression>>,
13665}
13666
13667/// JSONCast
13668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13669#[cfg_attr(feature = "bindings", derive(TS))]
13670pub struct JSONCast {
13671    pub this: Box<Expression>,
13672    pub to: DataType,
13673}
13674
13675/// JSONExtract
13676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13677#[cfg_attr(feature = "bindings", derive(TS))]
13678pub struct JSONExtract {
13679    pub this: Box<Expression>,
13680    pub expression: Box<Expression>,
13681    #[serde(default)]
13682    pub only_json_types: Option<Box<Expression>>,
13683    #[serde(default)]
13684    pub expressions: Vec<Expression>,
13685    #[serde(default)]
13686    pub variant_extract: Option<Box<Expression>>,
13687    #[serde(default)]
13688    pub json_query: Option<Box<Expression>>,
13689    #[serde(default)]
13690    pub option: Option<Box<Expression>>,
13691    #[serde(default)]
13692    pub quote: Option<Box<Expression>>,
13693    #[serde(default)]
13694    pub on_condition: Option<Box<Expression>>,
13695    #[serde(default)]
13696    pub requires_json: Option<Box<Expression>>,
13697}
13698
13699/// JSONExtractQuote
13700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13701#[cfg_attr(feature = "bindings", derive(TS))]
13702pub struct JSONExtractQuote {
13703    #[serde(default)]
13704    pub option: Option<Box<Expression>>,
13705    #[serde(default)]
13706    pub scalar: Option<Box<Expression>>,
13707}
13708
13709/// JSONExtractArray
13710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13711#[cfg_attr(feature = "bindings", derive(TS))]
13712pub struct JSONExtractArray {
13713    pub this: Box<Expression>,
13714    #[serde(default)]
13715    pub expression: Option<Box<Expression>>,
13716}
13717
13718/// JSONExtractScalar
13719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13720#[cfg_attr(feature = "bindings", derive(TS))]
13721pub struct JSONExtractScalar {
13722    pub this: Box<Expression>,
13723    pub expression: Box<Expression>,
13724    #[serde(default)]
13725    pub only_json_types: Option<Box<Expression>>,
13726    #[serde(default)]
13727    pub expressions: Vec<Expression>,
13728    #[serde(default)]
13729    pub json_type: Option<Box<Expression>>,
13730    #[serde(default)]
13731    pub scalar_only: Option<Box<Expression>>,
13732}
13733
13734/// JSONBExtractScalar
13735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13736#[cfg_attr(feature = "bindings", derive(TS))]
13737pub struct JSONBExtractScalar {
13738    pub this: Box<Expression>,
13739    pub expression: Box<Expression>,
13740    #[serde(default)]
13741    pub json_type: Option<Box<Expression>>,
13742}
13743
13744/// JSONFormat
13745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13746#[cfg_attr(feature = "bindings", derive(TS))]
13747pub struct JSONFormat {
13748    #[serde(default)]
13749    pub this: Option<Box<Expression>>,
13750    #[serde(default)]
13751    pub options: Vec<Expression>,
13752    #[serde(default)]
13753    pub is_json: Option<Box<Expression>>,
13754    #[serde(default)]
13755    pub to_json: Option<Box<Expression>>,
13756}
13757
13758/// JSONArrayAppend
13759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13760#[cfg_attr(feature = "bindings", derive(TS))]
13761pub struct JSONArrayAppend {
13762    pub this: Box<Expression>,
13763    #[serde(default)]
13764    pub expressions: Vec<Expression>,
13765}
13766
13767/// JSONArrayContains
13768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13769#[cfg_attr(feature = "bindings", derive(TS))]
13770pub struct JSONArrayContains {
13771    pub this: Box<Expression>,
13772    pub expression: Box<Expression>,
13773    #[serde(default)]
13774    pub json_type: Option<Box<Expression>>,
13775}
13776
13777/// JSONArrayInsert
13778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13779#[cfg_attr(feature = "bindings", derive(TS))]
13780pub struct JSONArrayInsert {
13781    pub this: Box<Expression>,
13782    #[serde(default)]
13783    pub expressions: Vec<Expression>,
13784}
13785
13786/// ParseJSON
13787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13788#[cfg_attr(feature = "bindings", derive(TS))]
13789pub struct ParseJSON {
13790    pub this: Box<Expression>,
13791    #[serde(default)]
13792    pub expression: Option<Box<Expression>>,
13793    #[serde(default)]
13794    pub safe: Option<Box<Expression>>,
13795}
13796
13797/// ParseUrl
13798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13799#[cfg_attr(feature = "bindings", derive(TS))]
13800pub struct ParseUrl {
13801    pub this: Box<Expression>,
13802    #[serde(default)]
13803    pub part_to_extract: Option<Box<Expression>>,
13804    #[serde(default)]
13805    pub key: Option<Box<Expression>>,
13806    #[serde(default)]
13807    pub permissive: Option<Box<Expression>>,
13808}
13809
13810/// ParseIp
13811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13812#[cfg_attr(feature = "bindings", derive(TS))]
13813pub struct ParseIp {
13814    pub this: Box<Expression>,
13815    #[serde(default)]
13816    pub type_: Option<Box<Expression>>,
13817    #[serde(default)]
13818    pub permissive: Option<Box<Expression>>,
13819}
13820
13821/// ParseTime
13822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13823#[cfg_attr(feature = "bindings", derive(TS))]
13824pub struct ParseTime {
13825    pub this: Box<Expression>,
13826    pub format: String,
13827}
13828
13829/// ParseDatetime
13830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13831#[cfg_attr(feature = "bindings", derive(TS))]
13832pub struct ParseDatetime {
13833    pub this: Box<Expression>,
13834    #[serde(default)]
13835    pub format: Option<String>,
13836    #[serde(default)]
13837    pub zone: Option<Box<Expression>>,
13838}
13839
13840/// Map
13841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13842#[cfg_attr(feature = "bindings", derive(TS))]
13843pub struct Map {
13844    #[serde(default)]
13845    pub keys: Vec<Expression>,
13846    #[serde(default)]
13847    pub values: Vec<Expression>,
13848}
13849
13850/// MapCat
13851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13852#[cfg_attr(feature = "bindings", derive(TS))]
13853pub struct MapCat {
13854    pub this: Box<Expression>,
13855    pub expression: Box<Expression>,
13856}
13857
13858/// MapDelete
13859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13860#[cfg_attr(feature = "bindings", derive(TS))]
13861pub struct MapDelete {
13862    pub this: Box<Expression>,
13863    #[serde(default)]
13864    pub expressions: Vec<Expression>,
13865}
13866
13867/// MapInsert
13868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13869#[cfg_attr(feature = "bindings", derive(TS))]
13870pub struct MapInsert {
13871    pub this: Box<Expression>,
13872    #[serde(default)]
13873    pub key: Option<Box<Expression>>,
13874    #[serde(default)]
13875    pub value: Option<Box<Expression>>,
13876    #[serde(default)]
13877    pub update_flag: Option<Box<Expression>>,
13878}
13879
13880/// MapPick
13881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13882#[cfg_attr(feature = "bindings", derive(TS))]
13883pub struct MapPick {
13884    pub this: Box<Expression>,
13885    #[serde(default)]
13886    pub expressions: Vec<Expression>,
13887}
13888
13889/// ScopeResolution
13890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13891#[cfg_attr(feature = "bindings", derive(TS))]
13892pub struct ScopeResolution {
13893    #[serde(default)]
13894    pub this: Option<Box<Expression>>,
13895    pub expression: Box<Expression>,
13896}
13897
13898/// Slice
13899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13900#[cfg_attr(feature = "bindings", derive(TS))]
13901pub struct Slice {
13902    #[serde(default)]
13903    pub this: Option<Box<Expression>>,
13904    #[serde(default)]
13905    pub expression: Option<Box<Expression>>,
13906    #[serde(default)]
13907    pub step: Option<Box<Expression>>,
13908}
13909
13910/// VarMap
13911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13912#[cfg_attr(feature = "bindings", derive(TS))]
13913pub struct VarMap {
13914    #[serde(default)]
13915    pub keys: Vec<Expression>,
13916    #[serde(default)]
13917    pub values: Vec<Expression>,
13918}
13919
13920/// MatchAgainst
13921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13922#[cfg_attr(feature = "bindings", derive(TS))]
13923pub struct MatchAgainst {
13924    pub this: Box<Expression>,
13925    #[serde(default)]
13926    pub expressions: Vec<Expression>,
13927    #[serde(default)]
13928    pub modifier: Option<Box<Expression>>,
13929}
13930
13931/// MD5Digest
13932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13933#[cfg_attr(feature = "bindings", derive(TS))]
13934pub struct MD5Digest {
13935    pub this: Box<Expression>,
13936    #[serde(default)]
13937    pub expressions: Vec<Expression>,
13938}
13939
13940/// Monthname
13941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13942#[cfg_attr(feature = "bindings", derive(TS))]
13943pub struct Monthname {
13944    pub this: Box<Expression>,
13945    #[serde(default)]
13946    pub abbreviated: Option<Box<Expression>>,
13947}
13948
13949/// Ntile
13950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13951#[cfg_attr(feature = "bindings", derive(TS))]
13952pub struct Ntile {
13953    #[serde(default)]
13954    pub this: Option<Box<Expression>>,
13955}
13956
13957/// Normalize
13958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13959#[cfg_attr(feature = "bindings", derive(TS))]
13960pub struct Normalize {
13961    pub this: Box<Expression>,
13962    #[serde(default)]
13963    pub form: Option<Box<Expression>>,
13964    #[serde(default)]
13965    pub is_casefold: Option<Box<Expression>>,
13966}
13967
13968/// Normal
13969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13970#[cfg_attr(feature = "bindings", derive(TS))]
13971pub struct Normal {
13972    pub this: Box<Expression>,
13973    #[serde(default)]
13974    pub stddev: Option<Box<Expression>>,
13975    #[serde(default)]
13976    pub gen: Option<Box<Expression>>,
13977}
13978
13979/// Predict
13980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13981#[cfg_attr(feature = "bindings", derive(TS))]
13982pub struct Predict {
13983    pub this: Box<Expression>,
13984    pub expression: Box<Expression>,
13985    #[serde(default)]
13986    pub params_struct: Option<Box<Expression>>,
13987}
13988
13989/// MLTranslate
13990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13991#[cfg_attr(feature = "bindings", derive(TS))]
13992pub struct MLTranslate {
13993    pub this: Box<Expression>,
13994    pub expression: Box<Expression>,
13995    #[serde(default)]
13996    pub params_struct: Option<Box<Expression>>,
13997}
13998
13999/// FeaturesAtTime
14000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14001#[cfg_attr(feature = "bindings", derive(TS))]
14002pub struct FeaturesAtTime {
14003    pub this: Box<Expression>,
14004    #[serde(default)]
14005    pub time: Option<Box<Expression>>,
14006    #[serde(default)]
14007    pub num_rows: Option<Box<Expression>>,
14008    #[serde(default)]
14009    pub ignore_feature_nulls: Option<Box<Expression>>,
14010}
14011
14012/// GenerateEmbedding
14013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14014#[cfg_attr(feature = "bindings", derive(TS))]
14015pub struct GenerateEmbedding {
14016    pub this: Box<Expression>,
14017    pub expression: Box<Expression>,
14018    #[serde(default)]
14019    pub params_struct: Option<Box<Expression>>,
14020    #[serde(default)]
14021    pub is_text: Option<Box<Expression>>,
14022}
14023
14024/// MLForecast
14025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14026#[cfg_attr(feature = "bindings", derive(TS))]
14027pub struct MLForecast {
14028    pub this: Box<Expression>,
14029    #[serde(default)]
14030    pub expression: Option<Box<Expression>>,
14031    #[serde(default)]
14032    pub params_struct: Option<Box<Expression>>,
14033}
14034
14035/// ModelAttribute
14036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14037#[cfg_attr(feature = "bindings", derive(TS))]
14038pub struct ModelAttribute {
14039    pub this: Box<Expression>,
14040    pub expression: Box<Expression>,
14041}
14042
14043/// VectorSearch
14044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14045#[cfg_attr(feature = "bindings", derive(TS))]
14046pub struct VectorSearch {
14047    pub this: Box<Expression>,
14048    #[serde(default)]
14049    pub column_to_search: Option<Box<Expression>>,
14050    #[serde(default)]
14051    pub query_table: Option<Box<Expression>>,
14052    #[serde(default)]
14053    pub query_column_to_search: Option<Box<Expression>>,
14054    #[serde(default)]
14055    pub top_k: Option<Box<Expression>>,
14056    #[serde(default)]
14057    pub distance_type: Option<Box<Expression>>,
14058    #[serde(default)]
14059    pub options: Vec<Expression>,
14060}
14061
14062/// Quantile
14063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14064#[cfg_attr(feature = "bindings", derive(TS))]
14065pub struct Quantile {
14066    pub this: Box<Expression>,
14067    #[serde(default)]
14068    pub quantile: Option<Box<Expression>>,
14069}
14070
14071/// ApproxQuantile
14072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14073#[cfg_attr(feature = "bindings", derive(TS))]
14074pub struct ApproxQuantile {
14075    pub this: Box<Expression>,
14076    #[serde(default)]
14077    pub quantile: Option<Box<Expression>>,
14078    #[serde(default)]
14079    pub accuracy: Option<Box<Expression>>,
14080    #[serde(default)]
14081    pub weight: Option<Box<Expression>>,
14082    #[serde(default)]
14083    pub error_tolerance: Option<Box<Expression>>,
14084}
14085
14086/// ApproxPercentileEstimate
14087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14088#[cfg_attr(feature = "bindings", derive(TS))]
14089pub struct ApproxPercentileEstimate {
14090    pub this: Box<Expression>,
14091    #[serde(default)]
14092    pub percentile: Option<Box<Expression>>,
14093}
14094
14095/// Randn
14096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14097#[cfg_attr(feature = "bindings", derive(TS))]
14098pub struct Randn {
14099    #[serde(default)]
14100    pub this: Option<Box<Expression>>,
14101}
14102
14103/// Randstr
14104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14105#[cfg_attr(feature = "bindings", derive(TS))]
14106pub struct Randstr {
14107    pub this: Box<Expression>,
14108    #[serde(default)]
14109    pub generator: Option<Box<Expression>>,
14110}
14111
14112/// RangeN
14113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14114#[cfg_attr(feature = "bindings", derive(TS))]
14115pub struct RangeN {
14116    pub this: Box<Expression>,
14117    #[serde(default)]
14118    pub expressions: Vec<Expression>,
14119    #[serde(default)]
14120    pub each: Option<Box<Expression>>,
14121}
14122
14123/// RangeBucket
14124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14125#[cfg_attr(feature = "bindings", derive(TS))]
14126pub struct RangeBucket {
14127    pub this: Box<Expression>,
14128    pub expression: Box<Expression>,
14129}
14130
14131/// ReadCSV
14132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14133#[cfg_attr(feature = "bindings", derive(TS))]
14134pub struct ReadCSV {
14135    pub this: Box<Expression>,
14136    #[serde(default)]
14137    pub expressions: Vec<Expression>,
14138}
14139
14140/// ReadParquet
14141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14142#[cfg_attr(feature = "bindings", derive(TS))]
14143pub struct ReadParquet {
14144    #[serde(default)]
14145    pub expressions: Vec<Expression>,
14146}
14147
14148/// Reduce
14149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14150#[cfg_attr(feature = "bindings", derive(TS))]
14151pub struct Reduce {
14152    pub this: Box<Expression>,
14153    #[serde(default)]
14154    pub initial: Option<Box<Expression>>,
14155    #[serde(default)]
14156    pub merge: Option<Box<Expression>>,
14157    #[serde(default)]
14158    pub finish: Option<Box<Expression>>,
14159}
14160
14161/// RegexpExtractAll
14162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14163#[cfg_attr(feature = "bindings", derive(TS))]
14164pub struct RegexpExtractAll {
14165    pub this: Box<Expression>,
14166    pub expression: Box<Expression>,
14167    #[serde(default)]
14168    pub group: Option<Box<Expression>>,
14169    #[serde(default)]
14170    pub parameters: Option<Box<Expression>>,
14171    #[serde(default)]
14172    pub position: Option<Box<Expression>>,
14173    #[serde(default)]
14174    pub occurrence: Option<Box<Expression>>,
14175}
14176
14177/// RegexpILike
14178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14179#[cfg_attr(feature = "bindings", derive(TS))]
14180pub struct RegexpILike {
14181    pub this: Box<Expression>,
14182    pub expression: Box<Expression>,
14183    #[serde(default)]
14184    pub flag: Option<Box<Expression>>,
14185}
14186
14187/// RegexpFullMatch
14188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14189#[cfg_attr(feature = "bindings", derive(TS))]
14190pub struct RegexpFullMatch {
14191    pub this: Box<Expression>,
14192    pub expression: Box<Expression>,
14193    #[serde(default)]
14194    pub options: Vec<Expression>,
14195}
14196
14197/// RegexpInstr
14198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14199#[cfg_attr(feature = "bindings", derive(TS))]
14200pub struct RegexpInstr {
14201    pub this: Box<Expression>,
14202    pub expression: Box<Expression>,
14203    #[serde(default)]
14204    pub position: Option<Box<Expression>>,
14205    #[serde(default)]
14206    pub occurrence: Option<Box<Expression>>,
14207    #[serde(default)]
14208    pub option: Option<Box<Expression>>,
14209    #[serde(default)]
14210    pub parameters: Option<Box<Expression>>,
14211    #[serde(default)]
14212    pub group: Option<Box<Expression>>,
14213}
14214
14215/// RegexpSplit
14216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14217#[cfg_attr(feature = "bindings", derive(TS))]
14218pub struct RegexpSplit {
14219    pub this: Box<Expression>,
14220    pub expression: Box<Expression>,
14221    #[serde(default)]
14222    pub limit: Option<Box<Expression>>,
14223}
14224
14225/// RegexpCount
14226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14227#[cfg_attr(feature = "bindings", derive(TS))]
14228pub struct RegexpCount {
14229    pub this: Box<Expression>,
14230    pub expression: Box<Expression>,
14231    #[serde(default)]
14232    pub position: Option<Box<Expression>>,
14233    #[serde(default)]
14234    pub parameters: Option<Box<Expression>>,
14235}
14236
14237/// RegrValx
14238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14239#[cfg_attr(feature = "bindings", derive(TS))]
14240pub struct RegrValx {
14241    pub this: Box<Expression>,
14242    pub expression: Box<Expression>,
14243}
14244
14245/// RegrValy
14246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14247#[cfg_attr(feature = "bindings", derive(TS))]
14248pub struct RegrValy {
14249    pub this: Box<Expression>,
14250    pub expression: Box<Expression>,
14251}
14252
14253/// RegrAvgy
14254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14255#[cfg_attr(feature = "bindings", derive(TS))]
14256pub struct RegrAvgy {
14257    pub this: Box<Expression>,
14258    pub expression: Box<Expression>,
14259}
14260
14261/// RegrAvgx
14262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14263#[cfg_attr(feature = "bindings", derive(TS))]
14264pub struct RegrAvgx {
14265    pub this: Box<Expression>,
14266    pub expression: Box<Expression>,
14267}
14268
14269/// RegrCount
14270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14271#[cfg_attr(feature = "bindings", derive(TS))]
14272pub struct RegrCount {
14273    pub this: Box<Expression>,
14274    pub expression: Box<Expression>,
14275}
14276
14277/// RegrIntercept
14278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14279#[cfg_attr(feature = "bindings", derive(TS))]
14280pub struct RegrIntercept {
14281    pub this: Box<Expression>,
14282    pub expression: Box<Expression>,
14283}
14284
14285/// RegrR2
14286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14287#[cfg_attr(feature = "bindings", derive(TS))]
14288pub struct RegrR2 {
14289    pub this: Box<Expression>,
14290    pub expression: Box<Expression>,
14291}
14292
14293/// RegrSxx
14294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14295#[cfg_attr(feature = "bindings", derive(TS))]
14296pub struct RegrSxx {
14297    pub this: Box<Expression>,
14298    pub expression: Box<Expression>,
14299}
14300
14301/// RegrSxy
14302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14303#[cfg_attr(feature = "bindings", derive(TS))]
14304pub struct RegrSxy {
14305    pub this: Box<Expression>,
14306    pub expression: Box<Expression>,
14307}
14308
14309/// RegrSyy
14310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14311#[cfg_attr(feature = "bindings", derive(TS))]
14312pub struct RegrSyy {
14313    pub this: Box<Expression>,
14314    pub expression: Box<Expression>,
14315}
14316
14317/// RegrSlope
14318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14319#[cfg_attr(feature = "bindings", derive(TS))]
14320pub struct RegrSlope {
14321    pub this: Box<Expression>,
14322    pub expression: Box<Expression>,
14323}
14324
14325/// SafeAdd
14326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14327#[cfg_attr(feature = "bindings", derive(TS))]
14328pub struct SafeAdd {
14329    pub this: Box<Expression>,
14330    pub expression: Box<Expression>,
14331}
14332
14333/// SafeDivide
14334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14335#[cfg_attr(feature = "bindings", derive(TS))]
14336pub struct SafeDivide {
14337    pub this: Box<Expression>,
14338    pub expression: Box<Expression>,
14339}
14340
14341/// SafeMultiply
14342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14343#[cfg_attr(feature = "bindings", derive(TS))]
14344pub struct SafeMultiply {
14345    pub this: Box<Expression>,
14346    pub expression: Box<Expression>,
14347}
14348
14349/// SafeSubtract
14350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14351#[cfg_attr(feature = "bindings", derive(TS))]
14352pub struct SafeSubtract {
14353    pub this: Box<Expression>,
14354    pub expression: Box<Expression>,
14355}
14356
14357/// SHA2
14358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14359#[cfg_attr(feature = "bindings", derive(TS))]
14360pub struct SHA2 {
14361    pub this: Box<Expression>,
14362    #[serde(default)]
14363    pub length: Option<i64>,
14364}
14365
14366/// SHA2Digest
14367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14368#[cfg_attr(feature = "bindings", derive(TS))]
14369pub struct SHA2Digest {
14370    pub this: Box<Expression>,
14371    #[serde(default)]
14372    pub length: Option<i64>,
14373}
14374
14375/// SortArray
14376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14377#[cfg_attr(feature = "bindings", derive(TS))]
14378pub struct SortArray {
14379    pub this: Box<Expression>,
14380    #[serde(default)]
14381    pub asc: Option<Box<Expression>>,
14382    #[serde(default)]
14383    pub nulls_first: Option<Box<Expression>>,
14384}
14385
14386/// SplitPart
14387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14388#[cfg_attr(feature = "bindings", derive(TS))]
14389pub struct SplitPart {
14390    pub this: Box<Expression>,
14391    #[serde(default)]
14392    pub delimiter: Option<Box<Expression>>,
14393    #[serde(default)]
14394    pub part_index: Option<Box<Expression>>,
14395}
14396
14397/// SUBSTRING_INDEX(str, delim, count)
14398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14399#[cfg_attr(feature = "bindings", derive(TS))]
14400pub struct SubstringIndex {
14401    pub this: Box<Expression>,
14402    #[serde(default)]
14403    pub delimiter: Option<Box<Expression>>,
14404    #[serde(default)]
14405    pub count: Option<Box<Expression>>,
14406}
14407
14408/// StandardHash
14409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14410#[cfg_attr(feature = "bindings", derive(TS))]
14411pub struct StandardHash {
14412    pub this: Box<Expression>,
14413    #[serde(default)]
14414    pub expression: Option<Box<Expression>>,
14415}
14416
14417/// StrPosition
14418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14419#[cfg_attr(feature = "bindings", derive(TS))]
14420pub struct StrPosition {
14421    pub this: Box<Expression>,
14422    #[serde(default)]
14423    pub substr: Option<Box<Expression>>,
14424    #[serde(default)]
14425    pub position: Option<Box<Expression>>,
14426    #[serde(default)]
14427    pub occurrence: Option<Box<Expression>>,
14428}
14429
14430/// Search
14431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14432#[cfg_attr(feature = "bindings", derive(TS))]
14433pub struct Search {
14434    pub this: Box<Expression>,
14435    pub expression: Box<Expression>,
14436    #[serde(default)]
14437    pub json_scope: Option<Box<Expression>>,
14438    #[serde(default)]
14439    pub analyzer: Option<Box<Expression>>,
14440    #[serde(default)]
14441    pub analyzer_options: Option<Box<Expression>>,
14442    #[serde(default)]
14443    pub search_mode: Option<Box<Expression>>,
14444}
14445
14446/// SearchIp
14447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14448#[cfg_attr(feature = "bindings", derive(TS))]
14449pub struct SearchIp {
14450    pub this: Box<Expression>,
14451    pub expression: Box<Expression>,
14452}
14453
14454/// StrToDate
14455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14456#[cfg_attr(feature = "bindings", derive(TS))]
14457pub struct StrToDate {
14458    pub this: Box<Expression>,
14459    #[serde(default)]
14460    pub format: Option<String>,
14461    #[serde(default)]
14462    pub safe: Option<Box<Expression>>,
14463}
14464
14465/// StrToTime
14466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14467#[cfg_attr(feature = "bindings", derive(TS))]
14468pub struct StrToTime {
14469    pub this: Box<Expression>,
14470    pub format: String,
14471    #[serde(default)]
14472    pub zone: Option<Box<Expression>>,
14473    #[serde(default)]
14474    pub safe: Option<Box<Expression>>,
14475    #[serde(default)]
14476    pub target_type: Option<Box<Expression>>,
14477}
14478
14479/// StrToUnix
14480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14481#[cfg_attr(feature = "bindings", derive(TS))]
14482pub struct StrToUnix {
14483    #[serde(default)]
14484    pub this: Option<Box<Expression>>,
14485    #[serde(default)]
14486    pub format: Option<String>,
14487}
14488
14489/// StrToMap
14490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14491#[cfg_attr(feature = "bindings", derive(TS))]
14492pub struct StrToMap {
14493    pub this: Box<Expression>,
14494    #[serde(default)]
14495    pub pair_delim: Option<Box<Expression>>,
14496    #[serde(default)]
14497    pub key_value_delim: Option<Box<Expression>>,
14498    #[serde(default)]
14499    pub duplicate_resolution_callback: Option<Box<Expression>>,
14500}
14501
14502/// NumberToStr
14503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14504#[cfg_attr(feature = "bindings", derive(TS))]
14505pub struct NumberToStr {
14506    pub this: Box<Expression>,
14507    pub format: String,
14508    #[serde(default)]
14509    pub culture: Option<Box<Expression>>,
14510}
14511
14512/// FromBase
14513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14514#[cfg_attr(feature = "bindings", derive(TS))]
14515pub struct FromBase {
14516    pub this: Box<Expression>,
14517    pub expression: Box<Expression>,
14518}
14519
14520/// Stuff
14521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14522#[cfg_attr(feature = "bindings", derive(TS))]
14523pub struct Stuff {
14524    pub this: Box<Expression>,
14525    #[serde(default)]
14526    pub start: Option<Box<Expression>>,
14527    #[serde(default)]
14528    pub length: Option<i64>,
14529    pub expression: Box<Expression>,
14530}
14531
14532/// TimeToStr
14533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14534#[cfg_attr(feature = "bindings", derive(TS))]
14535pub struct TimeToStr {
14536    pub this: Box<Expression>,
14537    pub format: String,
14538    #[serde(default)]
14539    pub culture: Option<Box<Expression>>,
14540    #[serde(default)]
14541    pub zone: Option<Box<Expression>>,
14542}
14543
14544/// TimeStrToTime
14545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14546#[cfg_attr(feature = "bindings", derive(TS))]
14547pub struct TimeStrToTime {
14548    pub this: Box<Expression>,
14549    #[serde(default)]
14550    pub zone: Option<Box<Expression>>,
14551}
14552
14553/// TsOrDsAdd
14554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14555#[cfg_attr(feature = "bindings", derive(TS))]
14556pub struct TsOrDsAdd {
14557    pub this: Box<Expression>,
14558    pub expression: Box<Expression>,
14559    #[serde(default)]
14560    pub unit: Option<String>,
14561    #[serde(default)]
14562    pub return_type: Option<Box<Expression>>,
14563}
14564
14565/// TsOrDsDiff
14566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14567#[cfg_attr(feature = "bindings", derive(TS))]
14568pub struct TsOrDsDiff {
14569    pub this: Box<Expression>,
14570    pub expression: Box<Expression>,
14571    #[serde(default)]
14572    pub unit: Option<String>,
14573}
14574
14575/// TsOrDsToDate
14576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14577#[cfg_attr(feature = "bindings", derive(TS))]
14578pub struct TsOrDsToDate {
14579    pub this: Box<Expression>,
14580    #[serde(default)]
14581    pub format: Option<String>,
14582    #[serde(default)]
14583    pub safe: Option<Box<Expression>>,
14584}
14585
14586/// TsOrDsToTime
14587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14588#[cfg_attr(feature = "bindings", derive(TS))]
14589pub struct TsOrDsToTime {
14590    pub this: Box<Expression>,
14591    #[serde(default)]
14592    pub format: Option<String>,
14593    #[serde(default)]
14594    pub safe: Option<Box<Expression>>,
14595}
14596
14597/// Unhex
14598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14599#[cfg_attr(feature = "bindings", derive(TS))]
14600pub struct Unhex {
14601    pub this: Box<Expression>,
14602    #[serde(default)]
14603    pub expression: Option<Box<Expression>>,
14604}
14605
14606/// Uniform
14607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14608#[cfg_attr(feature = "bindings", derive(TS))]
14609pub struct Uniform {
14610    pub this: Box<Expression>,
14611    pub expression: Box<Expression>,
14612    #[serde(default)]
14613    pub gen: Option<Box<Expression>>,
14614    #[serde(default)]
14615    pub seed: Option<Box<Expression>>,
14616}
14617
14618/// UnixToStr
14619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14620#[cfg_attr(feature = "bindings", derive(TS))]
14621pub struct UnixToStr {
14622    pub this: Box<Expression>,
14623    #[serde(default)]
14624    pub format: Option<String>,
14625}
14626
14627/// UnixToTime
14628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14629#[cfg_attr(feature = "bindings", derive(TS))]
14630pub struct UnixToTime {
14631    pub this: Box<Expression>,
14632    #[serde(default)]
14633    pub scale: Option<i64>,
14634    #[serde(default)]
14635    pub zone: Option<Box<Expression>>,
14636    #[serde(default)]
14637    pub hours: Option<Box<Expression>>,
14638    #[serde(default)]
14639    pub minutes: Option<Box<Expression>>,
14640    #[serde(default)]
14641    pub format: Option<String>,
14642    #[serde(default)]
14643    pub target_type: Option<Box<Expression>>,
14644}
14645
14646/// Uuid
14647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14648#[cfg_attr(feature = "bindings", derive(TS))]
14649pub struct Uuid {
14650    #[serde(default)]
14651    pub this: Option<Box<Expression>>,
14652    #[serde(default)]
14653    pub name: Option<String>,
14654    #[serde(default)]
14655    pub is_string: Option<Box<Expression>>,
14656}
14657
14658/// TimestampFromParts
14659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14660#[cfg_attr(feature = "bindings", derive(TS))]
14661pub struct TimestampFromParts {
14662    #[serde(default)]
14663    pub zone: Option<Box<Expression>>,
14664    #[serde(default)]
14665    pub milli: Option<Box<Expression>>,
14666    #[serde(default)]
14667    pub this: Option<Box<Expression>>,
14668    #[serde(default)]
14669    pub expression: Option<Box<Expression>>,
14670}
14671
14672/// TimestampTzFromParts
14673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14674#[cfg_attr(feature = "bindings", derive(TS))]
14675pub struct TimestampTzFromParts {
14676    #[serde(default)]
14677    pub zone: Option<Box<Expression>>,
14678}
14679
14680/// Corr
14681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14682#[cfg_attr(feature = "bindings", derive(TS))]
14683pub struct Corr {
14684    pub this: Box<Expression>,
14685    pub expression: Box<Expression>,
14686    #[serde(default)]
14687    pub null_on_zero_variance: Option<Box<Expression>>,
14688}
14689
14690/// WidthBucket
14691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14692#[cfg_attr(feature = "bindings", derive(TS))]
14693pub struct WidthBucket {
14694    pub this: Box<Expression>,
14695    #[serde(default)]
14696    pub min_value: Option<Box<Expression>>,
14697    #[serde(default)]
14698    pub max_value: Option<Box<Expression>>,
14699    #[serde(default)]
14700    pub num_buckets: Option<Box<Expression>>,
14701    #[serde(default)]
14702    pub threshold: Option<Box<Expression>>,
14703}
14704
14705/// CovarSamp
14706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14707#[cfg_attr(feature = "bindings", derive(TS))]
14708pub struct CovarSamp {
14709    pub this: Box<Expression>,
14710    pub expression: Box<Expression>,
14711}
14712
14713/// CovarPop
14714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14715#[cfg_attr(feature = "bindings", derive(TS))]
14716pub struct CovarPop {
14717    pub this: Box<Expression>,
14718    pub expression: Box<Expression>,
14719}
14720
14721/// Week
14722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14723#[cfg_attr(feature = "bindings", derive(TS))]
14724pub struct Week {
14725    pub this: Box<Expression>,
14726    #[serde(default)]
14727    pub mode: Option<Box<Expression>>,
14728}
14729
14730/// XMLElement
14731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14732#[cfg_attr(feature = "bindings", derive(TS))]
14733pub struct XMLElement {
14734    pub this: Box<Expression>,
14735    #[serde(default)]
14736    pub expressions: Vec<Expression>,
14737    #[serde(default)]
14738    pub evalname: Option<Box<Expression>>,
14739}
14740
14741/// XMLGet
14742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14743#[cfg_attr(feature = "bindings", derive(TS))]
14744pub struct XMLGet {
14745    pub this: Box<Expression>,
14746    pub expression: Box<Expression>,
14747    #[serde(default)]
14748    pub instance: Option<Box<Expression>>,
14749}
14750
14751/// XMLTable
14752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14753#[cfg_attr(feature = "bindings", derive(TS))]
14754pub struct XMLTable {
14755    pub this: Box<Expression>,
14756    #[serde(default)]
14757    pub namespaces: Option<Box<Expression>>,
14758    #[serde(default)]
14759    pub passing: Option<Box<Expression>>,
14760    #[serde(default)]
14761    pub columns: Vec<Expression>,
14762    #[serde(default)]
14763    pub by_ref: Option<Box<Expression>>,
14764}
14765
14766/// XMLKeyValueOption
14767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14768#[cfg_attr(feature = "bindings", derive(TS))]
14769pub struct XMLKeyValueOption {
14770    pub this: Box<Expression>,
14771    #[serde(default)]
14772    pub expression: Option<Box<Expression>>,
14773}
14774
14775/// Zipf
14776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14777#[cfg_attr(feature = "bindings", derive(TS))]
14778pub struct Zipf {
14779    pub this: Box<Expression>,
14780    #[serde(default)]
14781    pub elementcount: Option<Box<Expression>>,
14782    #[serde(default)]
14783    pub gen: Option<Box<Expression>>,
14784}
14785
14786/// Merge
14787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14788#[cfg_attr(feature = "bindings", derive(TS))]
14789pub struct Merge {
14790    pub this: Box<Expression>,
14791    pub using: Box<Expression>,
14792    #[serde(default)]
14793    pub on: Option<Box<Expression>>,
14794    #[serde(default)]
14795    pub using_cond: Option<Box<Expression>>,
14796    #[serde(default)]
14797    pub whens: Option<Box<Expression>>,
14798    #[serde(default)]
14799    pub with_: Option<Box<Expression>>,
14800    #[serde(default)]
14801    pub returning: Option<Box<Expression>>,
14802}
14803
14804/// When
14805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14806#[cfg_attr(feature = "bindings", derive(TS))]
14807pub struct When {
14808    #[serde(default)]
14809    pub matched: Option<Box<Expression>>,
14810    #[serde(default)]
14811    pub source: Option<Box<Expression>>,
14812    #[serde(default)]
14813    pub condition: Option<Box<Expression>>,
14814    pub then: Box<Expression>,
14815}
14816
14817/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14819#[cfg_attr(feature = "bindings", derive(TS))]
14820pub struct Whens {
14821    #[serde(default)]
14822    pub expressions: Vec<Expression>,
14823}
14824
14825/// NextValueFor
14826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14827#[cfg_attr(feature = "bindings", derive(TS))]
14828pub struct NextValueFor {
14829    pub this: Box<Expression>,
14830    #[serde(default)]
14831    pub order: Option<Box<Expression>>,
14832}
14833
14834#[cfg(test)]
14835mod tests {
14836    use super::*;
14837
14838    #[test]
14839    #[cfg(feature = "bindings")]
14840    fn export_typescript_types() {
14841        // This test exports TypeScript types to the generated directory
14842        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14843        Expression::export_all(&ts_rs::Config::default())
14844            .expect("Failed to export Expression types");
14845    }
14846
14847    #[test]
14848    fn test_simple_select_builder() {
14849        let select = Select::new()
14850            .column(Expression::star())
14851            .from(Expression::Table(Box::new(TableRef::new("users"))));
14852
14853        assert_eq!(select.expressions.len(), 1);
14854        assert!(select.from.is_some());
14855    }
14856
14857    #[test]
14858    fn test_expression_alias() {
14859        let expr = Expression::column("id").alias("user_id");
14860
14861        match expr {
14862            Expression::Alias(a) => {
14863                assert_eq!(a.alias.name, "user_id");
14864            }
14865            _ => panic!("Expected Alias"),
14866        }
14867    }
14868
14869    #[test]
14870    fn test_literal_creation() {
14871        let num = Expression::number(42);
14872        let str = Expression::string("hello");
14873
14874        match num {
14875            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
14876                let Literal::Number(n) = lit.as_ref() else {
14877                    unreachable!()
14878                };
14879                assert_eq!(n, "42")
14880            }
14881            _ => panic!("Expected Number"),
14882        }
14883
14884        match str {
14885            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
14886                let Literal::String(s) = lit.as_ref() else {
14887                    unreachable!()
14888                };
14889                assert_eq!(s, "hello")
14890            }
14891            _ => panic!("Expected String"),
14892        }
14893    }
14894
14895    #[test]
14896    fn test_expression_sql() {
14897        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14898        assert_eq!(expr.sql(), "SELECT 1 + 2");
14899    }
14900
14901    #[test]
14902    fn test_expression_sql_for() {
14903        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14904        let sql = expr.sql_for(crate::DialectType::Generic);
14905        // Generic mode normalizes IF() to CASE WHEN
14906        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14907    }
14908}