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    TryCatch(Box<TryCatch>),
118
119    // Expressions
120    Alias(Box<Alias>),
121    Cast(Box<Cast>),
122    Collation(Box<CollationExpr>),
123    Case(Box<Case>),
124
125    // Binary operations
126    And(Box<BinaryOp>),
127    Or(Box<BinaryOp>),
128    Add(Box<BinaryOp>),
129    Sub(Box<BinaryOp>),
130    Mul(Box<BinaryOp>),
131    Div(Box<BinaryOp>),
132    Mod(Box<BinaryOp>),
133    Eq(Box<BinaryOp>),
134    Neq(Box<BinaryOp>),
135    Lt(Box<BinaryOp>),
136    Lte(Box<BinaryOp>),
137    Gt(Box<BinaryOp>),
138    Gte(Box<BinaryOp>),
139    Like(Box<LikeOp>),
140    ILike(Box<LikeOp>),
141    /// SQLite MATCH operator (FTS)
142    Match(Box<BinaryOp>),
143    BitwiseAnd(Box<BinaryOp>),
144    BitwiseOr(Box<BinaryOp>),
145    BitwiseXor(Box<BinaryOp>),
146    Concat(Box<BinaryOp>),
147    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
148    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
149    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
150
151    // PostgreSQL array/JSONB operators
152    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
153    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
154    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
155    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
156    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
157    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
158    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
159    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
160
161    // Unary operations
162    Not(Box<UnaryOp>),
163    Neg(Box<UnaryOp>),
164    BitwiseNot(Box<UnaryOp>),
165
166    // Predicates
167    In(Box<In>),
168    Between(Box<Between>),
169    IsNull(Box<IsNull>),
170    IsTrue(Box<IsTrueFalse>),
171    IsFalse(Box<IsTrueFalse>),
172    IsJson(Box<IsJson>),
173    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
174    Exists(Box<Exists>),
175    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
176    MemberOf(Box<BinaryOp>),
177
178    // Functions
179    Function(Box<Function>),
180    AggregateFunction(Box<AggregateFunction>),
181    WindowFunction(Box<WindowFunction>),
182
183    // Clauses
184    From(Box<From>),
185    Join(Box<Join>),
186    JoinedTable(Box<JoinedTable>),
187    Where(Box<Where>),
188    GroupBy(Box<GroupBy>),
189    Having(Box<Having>),
190    OrderBy(Box<OrderBy>),
191    Limit(Box<Limit>),
192    Offset(Box<Offset>),
193    Qualify(Box<Qualify>),
194    With(Box<With>),
195    Cte(Box<Cte>),
196    DistributeBy(Box<DistributeBy>),
197    ClusterBy(Box<ClusterBy>),
198    SortBy(Box<SortBy>),
199    LateralView(Box<LateralView>),
200    Hint(Box<Hint>),
201    Pseudocolumn(Pseudocolumn),
202
203    // Oracle hierarchical queries (CONNECT BY)
204    Connect(Box<Connect>),
205    Prior(Box<Prior>),
206    ConnectByRoot(Box<ConnectByRoot>),
207
208    // Pattern matching (MATCH_RECOGNIZE)
209    MatchRecognize(Box<MatchRecognize>),
210
211    // Order expressions
212    Ordered(Box<Ordered>),
213
214    // Window specifications
215    Window(Box<WindowSpec>),
216    Over(Box<Over>),
217    WithinGroup(Box<WithinGroup>),
218
219    // Data types
220    DataType(DataType),
221
222    // Arrays and structs
223    Array(Box<Array>),
224    Struct(Box<Struct>),
225    Tuple(Box<Tuple>),
226
227    // Interval
228    Interval(Box<Interval>),
229
230    // String functions
231    ConcatWs(Box<ConcatWs>),
232    Substring(Box<SubstringFunc>),
233    Upper(Box<UnaryFunc>),
234    Lower(Box<UnaryFunc>),
235    Length(Box<UnaryFunc>),
236    Trim(Box<TrimFunc>),
237    LTrim(Box<UnaryFunc>),
238    RTrim(Box<UnaryFunc>),
239    Replace(Box<ReplaceFunc>),
240    Reverse(Box<UnaryFunc>),
241    Left(Box<LeftRightFunc>),
242    Right(Box<LeftRightFunc>),
243    Repeat(Box<RepeatFunc>),
244    Lpad(Box<PadFunc>),
245    Rpad(Box<PadFunc>),
246    Split(Box<SplitFunc>),
247    RegexpLike(Box<RegexpFunc>),
248    RegexpReplace(Box<RegexpReplaceFunc>),
249    RegexpExtract(Box<RegexpExtractFunc>),
250    Overlay(Box<OverlayFunc>),
251
252    // Math functions
253    Abs(Box<UnaryFunc>),
254    Round(Box<RoundFunc>),
255    Floor(Box<FloorFunc>),
256    Ceil(Box<CeilFunc>),
257    Power(Box<BinaryFunc>),
258    Sqrt(Box<UnaryFunc>),
259    Cbrt(Box<UnaryFunc>),
260    Ln(Box<UnaryFunc>),
261    Log(Box<LogFunc>),
262    Exp(Box<UnaryFunc>),
263    Sign(Box<UnaryFunc>),
264    Greatest(Box<VarArgFunc>),
265    Least(Box<VarArgFunc>),
266
267    // Date/time functions
268    CurrentDate(CurrentDate),
269    CurrentTime(CurrentTime),
270    CurrentTimestamp(CurrentTimestamp),
271    CurrentTimestampLTZ(CurrentTimestampLTZ),
272    AtTimeZone(Box<AtTimeZone>),
273    DateAdd(Box<DateAddFunc>),
274    DateSub(Box<DateAddFunc>),
275    DateDiff(Box<DateDiffFunc>),
276    DateTrunc(Box<DateTruncFunc>),
277    Extract(Box<ExtractFunc>),
278    ToDate(Box<ToDateFunc>),
279    ToTimestamp(Box<ToTimestampFunc>),
280    Date(Box<UnaryFunc>),
281    Time(Box<UnaryFunc>),
282    DateFromUnixDate(Box<UnaryFunc>),
283    UnixDate(Box<UnaryFunc>),
284    UnixSeconds(Box<UnaryFunc>),
285    UnixMillis(Box<UnaryFunc>),
286    UnixMicros(Box<UnaryFunc>),
287    UnixToTimeStr(Box<BinaryFunc>),
288    TimeStrToDate(Box<UnaryFunc>),
289    DateToDi(Box<UnaryFunc>),
290    DiToDate(Box<UnaryFunc>),
291    TsOrDiToDi(Box<UnaryFunc>),
292    TsOrDsToDatetime(Box<UnaryFunc>),
293    TsOrDsToTimestamp(Box<UnaryFunc>),
294    YearOfWeek(Box<UnaryFunc>),
295    YearOfWeekIso(Box<UnaryFunc>),
296
297    // Control flow functions
298    Coalesce(Box<VarArgFunc>),
299    NullIf(Box<BinaryFunc>),
300    IfFunc(Box<IfFunc>),
301    IfNull(Box<BinaryFunc>),
302    Nvl(Box<BinaryFunc>),
303    Nvl2(Box<Nvl2Func>),
304
305    // Type conversion
306    TryCast(Box<Cast>),
307    SafeCast(Box<Cast>),
308
309    // Typed aggregate functions
310    Count(Box<CountFunc>),
311    Sum(Box<AggFunc>),
312    Avg(Box<AggFunc>),
313    Min(Box<AggFunc>),
314    Max(Box<AggFunc>),
315    GroupConcat(Box<GroupConcatFunc>),
316    StringAgg(Box<StringAggFunc>),
317    ListAgg(Box<ListAggFunc>),
318    ArrayAgg(Box<AggFunc>),
319    CountIf(Box<AggFunc>),
320    SumIf(Box<SumIfFunc>),
321    Stddev(Box<AggFunc>),
322    StddevPop(Box<AggFunc>),
323    StddevSamp(Box<AggFunc>),
324    Variance(Box<AggFunc>),
325    VarPop(Box<AggFunc>),
326    VarSamp(Box<AggFunc>),
327    Median(Box<AggFunc>),
328    Mode(Box<AggFunc>),
329    First(Box<AggFunc>),
330    Last(Box<AggFunc>),
331    AnyValue(Box<AggFunc>),
332    ApproxDistinct(Box<AggFunc>),
333    ApproxCountDistinct(Box<AggFunc>),
334    ApproxPercentile(Box<ApproxPercentileFunc>),
335    Percentile(Box<PercentileFunc>),
336    LogicalAnd(Box<AggFunc>),
337    LogicalOr(Box<AggFunc>),
338    Skewness(Box<AggFunc>),
339    BitwiseCount(Box<UnaryFunc>),
340    ArrayConcatAgg(Box<AggFunc>),
341    ArrayUniqueAgg(Box<AggFunc>),
342    BoolXorAgg(Box<AggFunc>),
343
344    // Typed window functions
345    RowNumber(RowNumber),
346    Rank(Rank),
347    DenseRank(DenseRank),
348    NTile(Box<NTileFunc>),
349    Lead(Box<LeadLagFunc>),
350    Lag(Box<LeadLagFunc>),
351    FirstValue(Box<ValueFunc>),
352    LastValue(Box<ValueFunc>),
353    NthValue(Box<NthValueFunc>),
354    PercentRank(PercentRank),
355    CumeDist(CumeDist),
356    PercentileCont(Box<PercentileFunc>),
357    PercentileDisc(Box<PercentileFunc>),
358
359    // Additional string functions
360    Contains(Box<BinaryFunc>),
361    StartsWith(Box<BinaryFunc>),
362    EndsWith(Box<BinaryFunc>),
363    Position(Box<PositionFunc>),
364    Initcap(Box<UnaryFunc>),
365    Ascii(Box<UnaryFunc>),
366    Chr(Box<UnaryFunc>),
367    /// MySQL CHAR function with multiple args and optional USING charset
368    CharFunc(Box<CharFunc>),
369    Soundex(Box<UnaryFunc>),
370    Levenshtein(Box<BinaryFunc>),
371    ByteLength(Box<UnaryFunc>),
372    Hex(Box<UnaryFunc>),
373    LowerHex(Box<UnaryFunc>),
374    Unicode(Box<UnaryFunc>),
375
376    // Additional math functions
377    ModFunc(Box<BinaryFunc>),
378    Random(Random),
379    Rand(Box<Rand>),
380    TruncFunc(Box<TruncateFunc>),
381    Pi(Pi),
382    Radians(Box<UnaryFunc>),
383    Degrees(Box<UnaryFunc>),
384    Sin(Box<UnaryFunc>),
385    Cos(Box<UnaryFunc>),
386    Tan(Box<UnaryFunc>),
387    Asin(Box<UnaryFunc>),
388    Acos(Box<UnaryFunc>),
389    Atan(Box<UnaryFunc>),
390    Atan2(Box<BinaryFunc>),
391    IsNan(Box<UnaryFunc>),
392    IsInf(Box<UnaryFunc>),
393    IntDiv(Box<BinaryFunc>),
394
395    // Control flow
396    Decode(Box<DecodeFunc>),
397
398    // Additional date/time functions
399    DateFormat(Box<DateFormatFunc>),
400    FormatDate(Box<DateFormatFunc>),
401    Year(Box<UnaryFunc>),
402    Month(Box<UnaryFunc>),
403    Day(Box<UnaryFunc>),
404    Hour(Box<UnaryFunc>),
405    Minute(Box<UnaryFunc>),
406    Second(Box<UnaryFunc>),
407    DayOfWeek(Box<UnaryFunc>),
408    DayOfWeekIso(Box<UnaryFunc>),
409    DayOfMonth(Box<UnaryFunc>),
410    DayOfYear(Box<UnaryFunc>),
411    WeekOfYear(Box<UnaryFunc>),
412    Quarter(Box<UnaryFunc>),
413    AddMonths(Box<BinaryFunc>),
414    MonthsBetween(Box<BinaryFunc>),
415    LastDay(Box<LastDayFunc>),
416    NextDay(Box<BinaryFunc>),
417    Epoch(Box<UnaryFunc>),
418    EpochMs(Box<UnaryFunc>),
419    FromUnixtime(Box<FromUnixtimeFunc>),
420    UnixTimestamp(Box<UnixTimestampFunc>),
421    MakeDate(Box<MakeDateFunc>),
422    MakeTimestamp(Box<MakeTimestampFunc>),
423    TimestampTrunc(Box<DateTruncFunc>),
424    TimeStrToUnix(Box<UnaryFunc>),
425
426    // Session/User functions
427    SessionUser(SessionUser),
428
429    // Hash/Crypto functions
430    SHA(Box<UnaryFunc>),
431    SHA1Digest(Box<UnaryFunc>),
432
433    // Time conversion functions
434    TimeToUnix(Box<UnaryFunc>),
435
436    // Array functions
437    ArrayFunc(Box<ArrayConstructor>),
438    ArrayLength(Box<UnaryFunc>),
439    ArraySize(Box<UnaryFunc>),
440    Cardinality(Box<UnaryFunc>),
441    ArrayContains(Box<BinaryFunc>),
442    ArrayPosition(Box<BinaryFunc>),
443    ArrayAppend(Box<BinaryFunc>),
444    ArrayPrepend(Box<BinaryFunc>),
445    ArrayConcat(Box<VarArgFunc>),
446    ArraySort(Box<ArraySortFunc>),
447    ArrayReverse(Box<UnaryFunc>),
448    ArrayDistinct(Box<UnaryFunc>),
449    ArrayJoin(Box<ArrayJoinFunc>),
450    ArrayToString(Box<ArrayJoinFunc>),
451    Unnest(Box<UnnestFunc>),
452    Explode(Box<UnaryFunc>),
453    ExplodeOuter(Box<UnaryFunc>),
454    ArrayFilter(Box<ArrayFilterFunc>),
455    ArrayTransform(Box<ArrayTransformFunc>),
456    ArrayFlatten(Box<UnaryFunc>),
457    ArrayCompact(Box<UnaryFunc>),
458    ArrayIntersect(Box<VarArgFunc>),
459    ArrayUnion(Box<BinaryFunc>),
460    ArrayExcept(Box<BinaryFunc>),
461    ArrayRemove(Box<BinaryFunc>),
462    ArrayZip(Box<VarArgFunc>),
463    Sequence(Box<SequenceFunc>),
464    Generate(Box<SequenceFunc>),
465    ExplodingGenerateSeries(Box<SequenceFunc>),
466    ToArray(Box<UnaryFunc>),
467    StarMap(Box<BinaryFunc>),
468
469    // Struct functions
470    StructFunc(Box<StructConstructor>),
471    StructExtract(Box<StructExtractFunc>),
472    NamedStruct(Box<NamedStructFunc>),
473
474    // Map functions
475    MapFunc(Box<MapConstructor>),
476    MapFromEntries(Box<UnaryFunc>),
477    MapFromArrays(Box<BinaryFunc>),
478    MapKeys(Box<UnaryFunc>),
479    MapValues(Box<UnaryFunc>),
480    MapContainsKey(Box<BinaryFunc>),
481    MapConcat(Box<VarArgFunc>),
482    ElementAt(Box<BinaryFunc>),
483    TransformKeys(Box<TransformFunc>),
484    TransformValues(Box<TransformFunc>),
485
486    // Exasol: function call with EMITS clause
487    FunctionEmits(Box<FunctionEmits>),
488
489    // JSON functions
490    JsonExtract(Box<JsonExtractFunc>),
491    JsonExtractScalar(Box<JsonExtractFunc>),
492    JsonExtractPath(Box<JsonPathFunc>),
493    JsonArray(Box<VarArgFunc>),
494    JsonObject(Box<JsonObjectFunc>),
495    JsonQuery(Box<JsonExtractFunc>),
496    JsonValue(Box<JsonExtractFunc>),
497    JsonArrayLength(Box<UnaryFunc>),
498    JsonKeys(Box<UnaryFunc>),
499    JsonType(Box<UnaryFunc>),
500    ParseJson(Box<UnaryFunc>),
501    ToJson(Box<UnaryFunc>),
502    JsonSet(Box<JsonModifyFunc>),
503    JsonInsert(Box<JsonModifyFunc>),
504    JsonRemove(Box<JsonPathFunc>),
505    JsonMergePatch(Box<BinaryFunc>),
506    JsonArrayAgg(Box<JsonArrayAggFunc>),
507    JsonObjectAgg(Box<JsonObjectAggFunc>),
508
509    // Type casting/conversion
510    Convert(Box<ConvertFunc>),
511    Typeof(Box<UnaryFunc>),
512
513    // Additional expressions
514    Lambda(Box<LambdaExpr>),
515    Parameter(Box<Parameter>),
516    Placeholder(Placeholder),
517    NamedArgument(Box<NamedArgument>),
518    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
519    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
520    TableArgument(Box<TableArgument>),
521    SqlComment(Box<SqlComment>),
522
523    // Additional predicates
524    NullSafeEq(Box<BinaryOp>),
525    NullSafeNeq(Box<BinaryOp>),
526    Glob(Box<BinaryOp>),
527    SimilarTo(Box<SimilarToExpr>),
528    Any(Box<QuantifiedExpr>),
529    All(Box<QuantifiedExpr>),
530    Overlaps(Box<OverlapsExpr>),
531
532    // Bitwise operations
533    BitwiseLeftShift(Box<BinaryOp>),
534    BitwiseRightShift(Box<BinaryOp>),
535    BitwiseAndAgg(Box<AggFunc>),
536    BitwiseOrAgg(Box<AggFunc>),
537    BitwiseXorAgg(Box<AggFunc>),
538
539    // Array/struct/map access
540    Subscript(Box<Subscript>),
541    Dot(Box<DotAccess>),
542    MethodCall(Box<MethodCall>),
543    ArraySlice(Box<ArraySlice>),
544
545    // DDL statements
546    CreateTable(Box<CreateTable>),
547    DropTable(Box<DropTable>),
548    Undrop(Box<Undrop>),
549    AlterTable(Box<AlterTable>),
550    CreateIndex(Box<CreateIndex>),
551    DropIndex(Box<DropIndex>),
552    CreateView(Box<CreateView>),
553    DropView(Box<DropView>),
554    AlterView(Box<AlterView>),
555    AlterIndex(Box<AlterIndex>),
556    Truncate(Box<Truncate>),
557    Use(Box<Use>),
558    Cache(Box<Cache>),
559    Uncache(Box<Uncache>),
560    LoadData(Box<LoadData>),
561    Pragma(Box<Pragma>),
562    Grant(Box<Grant>),
563    Revoke(Box<Revoke>),
564    Comment(Box<Comment>),
565    SetStatement(Box<SetStatement>),
566    // Phase 4: Additional DDL statements
567    CreateSchema(Box<CreateSchema>),
568    DropSchema(Box<DropSchema>),
569    DropNamespace(Box<DropNamespace>),
570    CreateDatabase(Box<CreateDatabase>),
571    DropDatabase(Box<DropDatabase>),
572    CreateFunction(Box<CreateFunction>),
573    DropFunction(Box<DropFunction>),
574    CreateProcedure(Box<CreateProcedure>),
575    DropProcedure(Box<DropProcedure>),
576    CreateSequence(Box<CreateSequence>),
577    CreateSynonym(Box<CreateSynonym>),
578    DropSequence(Box<DropSequence>),
579    AlterSequence(Box<AlterSequence>),
580    CreateTrigger(Box<CreateTrigger>),
581    DropTrigger(Box<DropTrigger>),
582    CreateType(Box<CreateType>),
583    DropType(Box<DropType>),
584    Describe(Box<Describe>),
585    Show(Box<Show>),
586
587    // Transaction and other commands
588    Command(Box<Command>),
589    Kill(Box<Kill>),
590    /// PREPARE statement (PostgreSQL/generic prepared statement definition)
591    Prepare(Box<PrepareStatement>),
592    /// EXEC/EXECUTE statement (TSQL stored procedure call)
593    Execute(Box<ExecuteStatement>),
594
595    /// Snowflake CREATE TASK statement
596    CreateTask(Box<CreateTask>),
597
598    // Placeholder for unparsed/raw SQL
599    Raw(Raw),
600
601    // Paren for grouping
602    Paren(Box<Paren>),
603
604    // Expression with trailing comments (for round-trip preservation)
605    Annotated(Box<Annotated>),
606
607    // === BATCH GENERATED EXPRESSION TYPES ===
608    // Generated from Python sqlglot expressions.py
609    Refresh(Box<Refresh>),
610    LockingStatement(Box<LockingStatement>),
611    SequenceProperties(Box<SequenceProperties>),
612    TruncateTable(Box<TruncateTable>),
613    Clone(Box<Clone>),
614    Attach(Box<Attach>),
615    Detach(Box<Detach>),
616    Install(Box<Install>),
617    Summarize(Box<Summarize>),
618    Declare(Box<Declare>),
619    DeclareItem(Box<DeclareItem>),
620    Set(Box<Set>),
621    Heredoc(Box<Heredoc>),
622    SetItem(Box<SetItem>),
623    QueryBand(Box<QueryBand>),
624    UserDefinedFunction(Box<UserDefinedFunction>),
625    RecursiveWithSearch(Box<RecursiveWithSearch>),
626    ProjectionDef(Box<ProjectionDef>),
627    TableAlias(Box<TableAlias>),
628    ByteString(Box<ByteString>),
629    HexStringExpr(Box<HexStringExpr>),
630    UnicodeString(Box<UnicodeString>),
631    ColumnPosition(Box<ColumnPosition>),
632    ColumnDef(Box<ColumnDef>),
633    AlterColumn(Box<AlterColumn>),
634    AlterSortKey(Box<AlterSortKey>),
635    AlterSet(Box<AlterSet>),
636    RenameColumn(Box<RenameColumn>),
637    Comprehension(Box<Comprehension>),
638    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
639    MergeTreeTTL(Box<MergeTreeTTL>),
640    IndexConstraintOption(Box<IndexConstraintOption>),
641    ColumnConstraint(Box<ColumnConstraint>),
642    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
643    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
644    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
645    CheckColumnConstraint(Box<CheckColumnConstraint>),
646    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
647    CompressColumnConstraint(Box<CompressColumnConstraint>),
648    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
649    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
650    WithOperator(Box<WithOperator>),
651    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
652    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
653    CommentColumnConstraint(CommentColumnConstraint),
654    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
655    IndexColumnConstraint(Box<IndexColumnConstraint>),
656    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
657    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
658    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
659    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
660    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
661    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
662    InOutColumnConstraint(Box<InOutColumnConstraint>),
663    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
664    PathColumnConstraint(Box<PathColumnConstraint>),
665    Constraint(Box<Constraint>),
666    Export(Box<Export>),
667    Filter(Box<Filter>),
668    Changes(Box<Changes>),
669    CopyParameter(Box<CopyParameter>),
670    Credentials(Box<Credentials>),
671    Directory(Box<Directory>),
672    ForeignKey(Box<ForeignKey>),
673    ColumnPrefix(Box<ColumnPrefix>),
674    PrimaryKey(Box<PrimaryKey>),
675    IntoClause(Box<IntoClause>),
676    JoinHint(Box<JoinHint>),
677    Opclass(Box<Opclass>),
678    Index(Box<Index>),
679    IndexParameters(Box<IndexParameters>),
680    ConditionalInsert(Box<ConditionalInsert>),
681    MultitableInserts(Box<MultitableInserts>),
682    OnConflict(Box<OnConflict>),
683    OnCondition(Box<OnCondition>),
684    Returning(Box<Returning>),
685    Introducer(Box<Introducer>),
686    PartitionRange(Box<PartitionRange>),
687    Fetch(Box<Fetch>),
688    Group(Box<Group>),
689    Cube(Box<Cube>),
690    Rollup(Box<Rollup>),
691    GroupingSets(Box<GroupingSets>),
692    LimitOptions(Box<LimitOptions>),
693    Lateral(Box<Lateral>),
694    TableFromRows(Box<TableFromRows>),
695    RowsFrom(Box<RowsFrom>),
696    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
697    WithFill(Box<WithFill>),
698    Property(Box<Property>),
699    GrantPrivilege(Box<GrantPrivilege>),
700    GrantPrincipal(Box<GrantPrincipal>),
701    AllowedValuesProperty(Box<AllowedValuesProperty>),
702    AlgorithmProperty(Box<AlgorithmProperty>),
703    AutoIncrementProperty(Box<AutoIncrementProperty>),
704    AutoRefreshProperty(Box<AutoRefreshProperty>),
705    BackupProperty(Box<BackupProperty>),
706    BuildProperty(Box<BuildProperty>),
707    BlockCompressionProperty(Box<BlockCompressionProperty>),
708    CharacterSetProperty(Box<CharacterSetProperty>),
709    ChecksumProperty(Box<ChecksumProperty>),
710    CollateProperty(Box<CollateProperty>),
711    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
712    DataDeletionProperty(Box<DataDeletionProperty>),
713    DefinerProperty(Box<DefinerProperty>),
714    DistKeyProperty(Box<DistKeyProperty>),
715    DistributedByProperty(Box<DistributedByProperty>),
716    DistStyleProperty(Box<DistStyleProperty>),
717    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
718    EngineProperty(Box<EngineProperty>),
719    ToTableProperty(Box<ToTableProperty>),
720    ExecuteAsProperty(Box<ExecuteAsProperty>),
721    ExternalProperty(Box<ExternalProperty>),
722    FallbackProperty(Box<FallbackProperty>),
723    FileFormatProperty(Box<FileFormatProperty>),
724    CredentialsProperty(Box<CredentialsProperty>),
725    FreespaceProperty(Box<FreespaceProperty>),
726    InheritsProperty(Box<InheritsProperty>),
727    InputModelProperty(Box<InputModelProperty>),
728    OutputModelProperty(Box<OutputModelProperty>),
729    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
730    JournalProperty(Box<JournalProperty>),
731    LanguageProperty(Box<LanguageProperty>),
732    EnviromentProperty(Box<EnviromentProperty>),
733    ClusteredByProperty(Box<ClusteredByProperty>),
734    DictProperty(Box<DictProperty>),
735    DictRange(Box<DictRange>),
736    OnCluster(Box<OnCluster>),
737    LikeProperty(Box<LikeProperty>),
738    LocationProperty(Box<LocationProperty>),
739    LockProperty(Box<LockProperty>),
740    LockingProperty(Box<LockingProperty>),
741    LogProperty(Box<LogProperty>),
742    MaterializedProperty(Box<MaterializedProperty>),
743    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
744    OnProperty(Box<OnProperty>),
745    OnCommitProperty(Box<OnCommitProperty>),
746    PartitionedByProperty(Box<PartitionedByProperty>),
747    PartitionByProperty(Box<PartitionByProperty>),
748    PartitionedByBucket(Box<PartitionedByBucket>),
749    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
750    PartitionByTruncate(Box<PartitionByTruncate>),
751    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
752    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
753    PartitionByListProperty(Box<PartitionByListProperty>),
754    PartitionList(Box<PartitionList>),
755    Partition(Box<Partition>),
756    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
757    UniqueKeyProperty(Box<UniqueKeyProperty>),
758    RollupProperty(Box<RollupProperty>),
759    PartitionBoundSpec(Box<PartitionBoundSpec>),
760    PartitionedOfProperty(Box<PartitionedOfProperty>),
761    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
762    ReturnsProperty(Box<ReturnsProperty>),
763    RowFormatProperty(Box<RowFormatProperty>),
764    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
765    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
766    QueryTransform(Box<QueryTransform>),
767    SampleProperty(Box<SampleProperty>),
768    SecurityProperty(Box<SecurityProperty>),
769    SchemaCommentProperty(Box<SchemaCommentProperty>),
770    SemanticView(Box<SemanticView>),
771    SerdeProperties(Box<SerdeProperties>),
772    SetProperty(Box<SetProperty>),
773    SharingProperty(Box<SharingProperty>),
774    SetConfigProperty(Box<SetConfigProperty>),
775    SettingsProperty(Box<SettingsProperty>),
776    SortKeyProperty(Box<SortKeyProperty>),
777    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
778    SqlSecurityProperty(Box<SqlSecurityProperty>),
779    StabilityProperty(Box<StabilityProperty>),
780    StorageHandlerProperty(Box<StorageHandlerProperty>),
781    TemporaryProperty(Box<TemporaryProperty>),
782    Tags(Box<Tags>),
783    TransformModelProperty(Box<TransformModelProperty>),
784    TransientProperty(Box<TransientProperty>),
785    UsingTemplateProperty(Box<UsingTemplateProperty>),
786    ViewAttributeProperty(Box<ViewAttributeProperty>),
787    VolatileProperty(Box<VolatileProperty>),
788    WithDataProperty(Box<WithDataProperty>),
789    WithJournalTableProperty(Box<WithJournalTableProperty>),
790    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
791    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
792    WithProcedureOptions(Box<WithProcedureOptions>),
793    EncodeProperty(Box<EncodeProperty>),
794    IncludeProperty(Box<IncludeProperty>),
795    Properties(Box<Properties>),
796    OptionsProperty(Box<OptionsProperty>),
797    InputOutputFormat(Box<InputOutputFormat>),
798    Reference(Box<Reference>),
799    QueryOption(Box<QueryOption>),
800    WithTableHint(Box<WithTableHint>),
801    IndexTableHint(Box<IndexTableHint>),
802    HistoricalData(Box<HistoricalData>),
803    Get(Box<Get>),
804    SetOperation(Box<SetOperation>),
805    Var(Box<Var>),
806    Variadic(Box<Variadic>),
807    Version(Box<Version>),
808    Schema(Box<Schema>),
809    Lock(Box<Lock>),
810    TableSample(Box<TableSample>),
811    Tag(Box<Tag>),
812    UnpivotColumns(Box<UnpivotColumns>),
813    WindowSpec(Box<WindowSpec>),
814    SessionParameter(Box<SessionParameter>),
815    PseudoType(Box<PseudoType>),
816    ObjectIdentifier(Box<ObjectIdentifier>),
817    Transaction(Box<Transaction>),
818    Commit(Box<Commit>),
819    Rollback(Box<Rollback>),
820    AlterSession(Box<AlterSession>),
821    Analyze(Box<Analyze>),
822    AnalyzeStatistics(Box<AnalyzeStatistics>),
823    AnalyzeHistogram(Box<AnalyzeHistogram>),
824    AnalyzeSample(Box<AnalyzeSample>),
825    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
826    AnalyzeDelete(Box<AnalyzeDelete>),
827    AnalyzeWith(Box<AnalyzeWith>),
828    AnalyzeValidate(Box<AnalyzeValidate>),
829    AddPartition(Box<AddPartition>),
830    AttachOption(Box<AttachOption>),
831    DropPartition(Box<DropPartition>),
832    ReplacePartition(Box<ReplacePartition>),
833    DPipe(Box<DPipe>),
834    Operator(Box<Operator>),
835    PivotAny(Box<PivotAny>),
836    Aliases(Box<Aliases>),
837    AtIndex(Box<AtIndex>),
838    FromTimeZone(Box<FromTimeZone>),
839    FormatPhrase(Box<FormatPhrase>),
840    ForIn(Box<ForIn>),
841    TimeUnit(Box<TimeUnit>),
842    IntervalOp(Box<IntervalOp>),
843    IntervalSpan(Box<IntervalSpan>),
844    HavingMax(Box<HavingMax>),
845    CosineDistance(Box<CosineDistance>),
846    DotProduct(Box<DotProduct>),
847    EuclideanDistance(Box<EuclideanDistance>),
848    ManhattanDistance(Box<ManhattanDistance>),
849    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
850    Booland(Box<Booland>),
851    Boolor(Box<Boolor>),
852    ParameterizedAgg(Box<ParameterizedAgg>),
853    ArgMax(Box<ArgMax>),
854    ArgMin(Box<ArgMin>),
855    ApproxTopK(Box<ApproxTopK>),
856    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
857    ApproxTopKCombine(Box<ApproxTopKCombine>),
858    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
859    ApproxTopSum(Box<ApproxTopSum>),
860    ApproxQuantiles(Box<ApproxQuantiles>),
861    Minhash(Box<Minhash>),
862    FarmFingerprint(Box<FarmFingerprint>),
863    Float64(Box<Float64>),
864    Transform(Box<Transform>),
865    Translate(Box<Translate>),
866    Grouping(Box<Grouping>),
867    GroupingId(Box<GroupingId>),
868    Anonymous(Box<Anonymous>),
869    AnonymousAggFunc(Box<AnonymousAggFunc>),
870    CombinedAggFunc(Box<CombinedAggFunc>),
871    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
872    HashAgg(Box<HashAgg>),
873    Hll(Box<Hll>),
874    Apply(Box<Apply>),
875    ToBoolean(Box<ToBoolean>),
876    List(Box<List>),
877    ToMap(Box<ToMap>),
878    Pad(Box<Pad>),
879    ToChar(Box<ToChar>),
880    ToNumber(Box<ToNumber>),
881    ToDouble(Box<ToDouble>),
882    Int64(Box<UnaryFunc>),
883    StringFunc(Box<StringFunc>),
884    ToDecfloat(Box<ToDecfloat>),
885    TryToDecfloat(Box<TryToDecfloat>),
886    ToFile(Box<ToFile>),
887    Columns(Box<Columns>),
888    ConvertToCharset(Box<ConvertToCharset>),
889    ConvertTimezone(Box<ConvertTimezone>),
890    GenerateSeries(Box<GenerateSeries>),
891    AIAgg(Box<AIAgg>),
892    AIClassify(Box<AIClassify>),
893    ArrayAll(Box<ArrayAll>),
894    ArrayAny(Box<ArrayAny>),
895    ArrayConstructCompact(Box<ArrayConstructCompact>),
896    StPoint(Box<StPoint>),
897    StDistance(Box<StDistance>),
898    StringToArray(Box<StringToArray>),
899    ArraySum(Box<ArraySum>),
900    ObjectAgg(Box<ObjectAgg>),
901    CastToStrType(Box<CastToStrType>),
902    CheckJson(Box<CheckJson>),
903    CheckXml(Box<CheckXml>),
904    TranslateCharacters(Box<TranslateCharacters>),
905    CurrentSchemas(Box<CurrentSchemas>),
906    CurrentDatetime(Box<CurrentDatetime>),
907    Localtime(Box<Localtime>),
908    Localtimestamp(Box<Localtimestamp>),
909    Systimestamp(Box<Systimestamp>),
910    CurrentSchema(Box<CurrentSchema>),
911    CurrentUser(Box<CurrentUser>),
912    UtcTime(Box<UtcTime>),
913    UtcTimestamp(Box<UtcTimestamp>),
914    Timestamp(Box<TimestampFunc>),
915    DateBin(Box<DateBin>),
916    Datetime(Box<Datetime>),
917    DatetimeAdd(Box<DatetimeAdd>),
918    DatetimeSub(Box<DatetimeSub>),
919    DatetimeDiff(Box<DatetimeDiff>),
920    DatetimeTrunc(Box<DatetimeTrunc>),
921    Dayname(Box<Dayname>),
922    MakeInterval(Box<MakeInterval>),
923    PreviousDay(Box<PreviousDay>),
924    Elt(Box<Elt>),
925    TimestampAdd(Box<TimestampAdd>),
926    TimestampSub(Box<TimestampSub>),
927    TimestampDiff(Box<TimestampDiff>),
928    TimeSlice(Box<TimeSlice>),
929    TimeAdd(Box<TimeAdd>),
930    TimeSub(Box<TimeSub>),
931    TimeDiff(Box<TimeDiff>),
932    TimeTrunc(Box<TimeTrunc>),
933    DateFromParts(Box<DateFromParts>),
934    TimeFromParts(Box<TimeFromParts>),
935    DecodeCase(Box<DecodeCase>),
936    Decrypt(Box<Decrypt>),
937    DecryptRaw(Box<DecryptRaw>),
938    Encode(Box<Encode>),
939    Encrypt(Box<Encrypt>),
940    EncryptRaw(Box<EncryptRaw>),
941    EqualNull(Box<EqualNull>),
942    ToBinary(Box<ToBinary>),
943    Base64DecodeBinary(Box<Base64DecodeBinary>),
944    Base64DecodeString(Box<Base64DecodeString>),
945    Base64Encode(Box<Base64Encode>),
946    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
947    TryBase64DecodeString(Box<TryBase64DecodeString>),
948    GapFill(Box<GapFill>),
949    GenerateDateArray(Box<GenerateDateArray>),
950    GenerateTimestampArray(Box<GenerateTimestampArray>),
951    GetExtract(Box<GetExtract>),
952    Getbit(Box<Getbit>),
953    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
954    HexEncode(Box<HexEncode>),
955    Compress(Box<Compress>),
956    DecompressBinary(Box<DecompressBinary>),
957    DecompressString(Box<DecompressString>),
958    Xor(Box<Xor>),
959    Nullif(Box<Nullif>),
960    JSON(Box<JSON>),
961    JSONPath(Box<JSONPath>),
962    JSONPathFilter(Box<JSONPathFilter>),
963    JSONPathKey(Box<JSONPathKey>),
964    JSONPathRecursive(Box<JSONPathRecursive>),
965    JSONPathScript(Box<JSONPathScript>),
966    JSONPathSlice(Box<JSONPathSlice>),
967    JSONPathSelector(Box<JSONPathSelector>),
968    JSONPathSubscript(Box<JSONPathSubscript>),
969    JSONPathUnion(Box<JSONPathUnion>),
970    Format(Box<Format>),
971    JSONKeys(Box<JSONKeys>),
972    JSONKeyValue(Box<JSONKeyValue>),
973    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
974    JSONObject(Box<JSONObject>),
975    JSONObjectAgg(Box<JSONObjectAgg>),
976    JSONBObjectAgg(Box<JSONBObjectAgg>),
977    JSONArray(Box<JSONArray>),
978    JSONArrayAgg(Box<JSONArrayAgg>),
979    JSONExists(Box<JSONExists>),
980    JSONColumnDef(Box<JSONColumnDef>),
981    JSONSchema(Box<JSONSchema>),
982    JSONSet(Box<JSONSet>),
983    JSONStripNulls(Box<JSONStripNulls>),
984    JSONValue(Box<JSONValue>),
985    JSONValueArray(Box<JSONValueArray>),
986    JSONRemove(Box<JSONRemove>),
987    JSONTable(Box<JSONTable>),
988    JSONType(Box<JSONType>),
989    ObjectInsert(Box<ObjectInsert>),
990    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
991    OpenJSON(Box<OpenJSON>),
992    JSONBExists(Box<JSONBExists>),
993    JSONBContains(Box<BinaryFunc>),
994    JSONBExtract(Box<BinaryFunc>),
995    JSONCast(Box<JSONCast>),
996    JSONExtract(Box<JSONExtract>),
997    JSONExtractQuote(Box<JSONExtractQuote>),
998    JSONExtractArray(Box<JSONExtractArray>),
999    JSONExtractScalar(Box<JSONExtractScalar>),
1000    JSONBExtractScalar(Box<JSONBExtractScalar>),
1001    JSONFormat(Box<JSONFormat>),
1002    JSONBool(Box<UnaryFunc>),
1003    JSONPathRoot(JSONPathRoot),
1004    JSONArrayAppend(Box<JSONArrayAppend>),
1005    JSONArrayContains(Box<JSONArrayContains>),
1006    JSONArrayInsert(Box<JSONArrayInsert>),
1007    ParseJSON(Box<ParseJSON>),
1008    ParseUrl(Box<ParseUrl>),
1009    ParseIp(Box<ParseIp>),
1010    ParseTime(Box<ParseTime>),
1011    ParseDatetime(Box<ParseDatetime>),
1012    Map(Box<Map>),
1013    MapCat(Box<MapCat>),
1014    MapDelete(Box<MapDelete>),
1015    MapInsert(Box<MapInsert>),
1016    MapPick(Box<MapPick>),
1017    ScopeResolution(Box<ScopeResolution>),
1018    Slice(Box<Slice>),
1019    VarMap(Box<VarMap>),
1020    MatchAgainst(Box<MatchAgainst>),
1021    MD5Digest(Box<MD5Digest>),
1022    MD5NumberLower64(Box<UnaryFunc>),
1023    MD5NumberUpper64(Box<UnaryFunc>),
1024    Monthname(Box<Monthname>),
1025    Ntile(Box<Ntile>),
1026    Normalize(Box<Normalize>),
1027    Normal(Box<Normal>),
1028    Predict(Box<Predict>),
1029    MLTranslate(Box<MLTranslate>),
1030    FeaturesAtTime(Box<FeaturesAtTime>),
1031    GenerateEmbedding(Box<GenerateEmbedding>),
1032    MLForecast(Box<MLForecast>),
1033    ModelAttribute(Box<ModelAttribute>),
1034    VectorSearch(Box<VectorSearch>),
1035    Quantile(Box<Quantile>),
1036    ApproxQuantile(Box<ApproxQuantile>),
1037    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1038    Randn(Box<Randn>),
1039    Randstr(Box<Randstr>),
1040    RangeN(Box<RangeN>),
1041    RangeBucket(Box<RangeBucket>),
1042    ReadCSV(Box<ReadCSV>),
1043    ReadParquet(Box<ReadParquet>),
1044    Reduce(Box<Reduce>),
1045    RegexpExtractAll(Box<RegexpExtractAll>),
1046    RegexpILike(Box<RegexpILike>),
1047    RegexpFullMatch(Box<RegexpFullMatch>),
1048    RegexpInstr(Box<RegexpInstr>),
1049    RegexpSplit(Box<RegexpSplit>),
1050    RegexpCount(Box<RegexpCount>),
1051    RegrValx(Box<RegrValx>),
1052    RegrValy(Box<RegrValy>),
1053    RegrAvgy(Box<RegrAvgy>),
1054    RegrAvgx(Box<RegrAvgx>),
1055    RegrCount(Box<RegrCount>),
1056    RegrIntercept(Box<RegrIntercept>),
1057    RegrR2(Box<RegrR2>),
1058    RegrSxx(Box<RegrSxx>),
1059    RegrSxy(Box<RegrSxy>),
1060    RegrSyy(Box<RegrSyy>),
1061    RegrSlope(Box<RegrSlope>),
1062    SafeAdd(Box<SafeAdd>),
1063    SafeDivide(Box<SafeDivide>),
1064    SafeMultiply(Box<SafeMultiply>),
1065    SafeSubtract(Box<SafeSubtract>),
1066    SHA2(Box<SHA2>),
1067    SHA2Digest(Box<SHA2Digest>),
1068    SortArray(Box<SortArray>),
1069    SplitPart(Box<SplitPart>),
1070    SubstringIndex(Box<SubstringIndex>),
1071    StandardHash(Box<StandardHash>),
1072    StrPosition(Box<StrPosition>),
1073    Search(Box<Search>),
1074    SearchIp(Box<SearchIp>),
1075    StrToDate(Box<StrToDate>),
1076    DateStrToDate(Box<UnaryFunc>),
1077    DateToDateStr(Box<UnaryFunc>),
1078    StrToTime(Box<StrToTime>),
1079    StrToUnix(Box<StrToUnix>),
1080    StrToMap(Box<StrToMap>),
1081    NumberToStr(Box<NumberToStr>),
1082    FromBase(Box<FromBase>),
1083    Stuff(Box<Stuff>),
1084    TimeToStr(Box<TimeToStr>),
1085    TimeStrToTime(Box<TimeStrToTime>),
1086    TsOrDsAdd(Box<TsOrDsAdd>),
1087    TsOrDsDiff(Box<TsOrDsDiff>),
1088    TsOrDsToDate(Box<TsOrDsToDate>),
1089    TsOrDsToTime(Box<TsOrDsToTime>),
1090    Unhex(Box<Unhex>),
1091    Uniform(Box<Uniform>),
1092    UnixToStr(Box<UnixToStr>),
1093    UnixToTime(Box<UnixToTime>),
1094    Uuid(Box<Uuid>),
1095    TimestampFromParts(Box<TimestampFromParts>),
1096    TimestampTzFromParts(Box<TimestampTzFromParts>),
1097    Corr(Box<Corr>),
1098    WidthBucket(Box<WidthBucket>),
1099    CovarSamp(Box<CovarSamp>),
1100    CovarPop(Box<CovarPop>),
1101    Week(Box<Week>),
1102    XMLElement(Box<XMLElement>),
1103    XMLGet(Box<XMLGet>),
1104    XMLTable(Box<XMLTable>),
1105    XMLKeyValueOption(Box<XMLKeyValueOption>),
1106    Zipf(Box<Zipf>),
1107    Merge(Box<Merge>),
1108    When(Box<When>),
1109    Whens(Box<Whens>),
1110    NextValueFor(Box<NextValueFor>),
1111    /// RETURN statement (DuckDB stored procedures)
1112    ReturnStmt(Box<Expression>),
1113}
1114
1115impl Expression {
1116    /// Create a `Column` variant, boxing the value automatically.
1117    #[inline]
1118    pub fn boxed_column(col: Column) -> Self {
1119        Expression::Column(Box::new(col))
1120    }
1121
1122    /// Create a `Table` variant, boxing the value automatically.
1123    #[inline]
1124    pub fn boxed_table(t: TableRef) -> Self {
1125        Expression::Table(Box::new(t))
1126    }
1127
1128    /// Returns `true` if this expression is a valid top-level SQL statement.
1129    ///
1130    /// Bare expressions like identifiers, literals, and function calls are not
1131    /// valid statements. This is used by `validate()` to reject inputs like
1132    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1133    /// plus the bare identifier `doo`.
1134    pub fn is_statement(&self) -> bool {
1135        match self {
1136            // Queries
1137            Expression::Select(_)
1138            | Expression::Union(_)
1139            | Expression::Intersect(_)
1140            | Expression::Except(_)
1141            | Expression::Subquery(_)
1142            | Expression::Values(_)
1143            | Expression::PipeOperator(_)
1144
1145            // DML
1146            | Expression::Insert(_)
1147            | Expression::Update(_)
1148            | Expression::Delete(_)
1149            | Expression::Copy(_)
1150            | Expression::Put(_)
1151            | Expression::Merge(_)
1152            | Expression::TryCatch(_)
1153
1154            // DDL
1155            | Expression::CreateTable(_)
1156            | Expression::DropTable(_)
1157            | Expression::Undrop(_)
1158            | Expression::AlterTable(_)
1159            | Expression::CreateIndex(_)
1160            | Expression::DropIndex(_)
1161            | Expression::CreateView(_)
1162            | Expression::DropView(_)
1163            | Expression::AlterView(_)
1164            | Expression::AlterIndex(_)
1165            | Expression::Truncate(_)
1166            | Expression::TruncateTable(_)
1167            | Expression::CreateSchema(_)
1168            | Expression::DropSchema(_)
1169            | Expression::DropNamespace(_)
1170            | Expression::CreateDatabase(_)
1171            | Expression::DropDatabase(_)
1172            | Expression::CreateFunction(_)
1173            | Expression::DropFunction(_)
1174            | Expression::CreateProcedure(_)
1175            | Expression::DropProcedure(_)
1176            | Expression::CreateSequence(_)
1177            | Expression::CreateSynonym(_)
1178            | Expression::DropSequence(_)
1179            | Expression::AlterSequence(_)
1180            | Expression::CreateTrigger(_)
1181            | Expression::DropTrigger(_)
1182            | Expression::CreateType(_)
1183            | Expression::DropType(_)
1184            | Expression::Comment(_)
1185
1186            // Session/Transaction/Control
1187            | Expression::Use(_)
1188            | Expression::Set(_)
1189            | Expression::SetStatement(_)
1190            | Expression::Transaction(_)
1191            | Expression::Commit(_)
1192            | Expression::Rollback(_)
1193            | Expression::Grant(_)
1194            | Expression::Revoke(_)
1195            | Expression::Cache(_)
1196            | Expression::Uncache(_)
1197            | Expression::LoadData(_)
1198            | Expression::Pragma(_)
1199            | Expression::Describe(_)
1200            | Expression::Show(_)
1201            | Expression::Kill(_)
1202            | Expression::Prepare(_)
1203            | Expression::Execute(_)
1204            | Expression::Declare(_)
1205            | Expression::Refresh(_)
1206            | Expression::AlterSession(_)
1207            | Expression::LockingStatement(_)
1208
1209            // Analyze
1210            | Expression::Analyze(_)
1211            | Expression::AnalyzeStatistics(_)
1212            | Expression::AnalyzeHistogram(_)
1213            | Expression::AnalyzeSample(_)
1214            | Expression::AnalyzeListChainedRows(_)
1215            | Expression::AnalyzeDelete(_)
1216
1217            // Attach/Detach/Install/Summarize
1218            | Expression::Attach(_)
1219            | Expression::Detach(_)
1220            | Expression::Install(_)
1221            | Expression::Summarize(_)
1222
1223            // Pivot at statement level
1224            | Expression::Pivot(_)
1225            | Expression::Unpivot(_)
1226
1227            // Command (raw/unparsed statements)
1228            | Expression::Command(_)
1229            | Expression::Raw(_)
1230            | Expression::CreateTask(_)
1231
1232            // Return statement
1233            | Expression::ReturnStmt(_) => true,
1234
1235            // Annotated wraps another expression with comments — check inner
1236            Expression::Annotated(a) => a.this.is_statement(),
1237
1238            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1239            Expression::Alias(a) => a.this.is_statement(),
1240
1241            // Everything else (identifiers, literals, operators, functions, etc.)
1242            _ => false,
1243        }
1244    }
1245
1246    /// Create a literal number expression from an integer.
1247    pub fn number(n: i64) -> Self {
1248        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1249    }
1250
1251    /// Create a single-quoted literal string expression.
1252    pub fn string(s: impl Into<String>) -> Self {
1253        Expression::Literal(Box::new(Literal::String(s.into())))
1254    }
1255
1256    /// Create a literal number expression from a float.
1257    pub fn float(f: f64) -> Self {
1258        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1259    }
1260
1261    /// Get the inferred type annotation, if present.
1262    ///
1263    /// For value-producing expressions with an `inferred_type` field, returns
1264    /// the stored type. For literals and boolean constants, computes the type
1265    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1266    pub fn inferred_type(&self) -> Option<&DataType> {
1267        match self {
1268            // Structs with inferred_type field
1269            Expression::And(op)
1270            | Expression::Or(op)
1271            | Expression::Add(op)
1272            | Expression::Sub(op)
1273            | Expression::Mul(op)
1274            | Expression::Div(op)
1275            | Expression::Mod(op)
1276            | Expression::Eq(op)
1277            | Expression::Neq(op)
1278            | Expression::Lt(op)
1279            | Expression::Lte(op)
1280            | Expression::Gt(op)
1281            | Expression::Gte(op)
1282            | Expression::Concat(op)
1283            | Expression::BitwiseAnd(op)
1284            | Expression::BitwiseOr(op)
1285            | Expression::BitwiseXor(op)
1286            | Expression::Adjacent(op)
1287            | Expression::TsMatch(op)
1288            | Expression::PropertyEQ(op)
1289            | Expression::ArrayContainsAll(op)
1290            | Expression::ArrayContainedBy(op)
1291            | Expression::ArrayOverlaps(op)
1292            | Expression::JSONBContainsAllTopKeys(op)
1293            | Expression::JSONBContainsAnyTopKeys(op)
1294            | Expression::JSONBDeleteAtPath(op)
1295            | Expression::ExtendsLeft(op)
1296            | Expression::ExtendsRight(op)
1297            | Expression::Is(op)
1298            | Expression::MemberOf(op)
1299            | Expression::Match(op)
1300            | Expression::NullSafeEq(op)
1301            | Expression::NullSafeNeq(op)
1302            | Expression::Glob(op)
1303            | Expression::BitwiseLeftShift(op)
1304            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1305
1306            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1307                op.inferred_type.as_ref()
1308            }
1309
1310            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1311
1312            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1313                c.inferred_type.as_ref()
1314            }
1315
1316            Expression::Column(c) => c.inferred_type.as_ref(),
1317            Expression::Function(f) => f.inferred_type.as_ref(),
1318            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1319            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1320            Expression::Case(c) => c.inferred_type.as_ref(),
1321            Expression::Subquery(s) => s.inferred_type.as_ref(),
1322            Expression::Alias(a) => a.inferred_type.as_ref(),
1323            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1324            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1325            Expression::Count(f) => f.inferred_type.as_ref(),
1326            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1327            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1328            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1329            Expression::SumIf(f) => f.inferred_type.as_ref(),
1330
1331            // UnaryFunc variants
1332            Expression::Upper(f)
1333            | Expression::Lower(f)
1334            | Expression::Length(f)
1335            | Expression::LTrim(f)
1336            | Expression::RTrim(f)
1337            | Expression::Reverse(f)
1338            | Expression::Abs(f)
1339            | Expression::Sqrt(f)
1340            | Expression::Cbrt(f)
1341            | Expression::Ln(f)
1342            | Expression::Exp(f)
1343            | Expression::Sign(f)
1344            | Expression::Date(f)
1345            | Expression::Time(f)
1346            | Expression::Initcap(f)
1347            | Expression::Ascii(f)
1348            | Expression::Chr(f)
1349            | Expression::Soundex(f)
1350            | Expression::ByteLength(f)
1351            | Expression::Hex(f)
1352            | Expression::LowerHex(f)
1353            | Expression::Unicode(f)
1354            | Expression::Typeof(f)
1355            | Expression::Explode(f)
1356            | Expression::ExplodeOuter(f)
1357            | Expression::MapFromEntries(f)
1358            | Expression::MapKeys(f)
1359            | Expression::MapValues(f)
1360            | Expression::ArrayLength(f)
1361            | Expression::ArraySize(f)
1362            | Expression::Cardinality(f)
1363            | Expression::ArrayReverse(f)
1364            | Expression::ArrayDistinct(f)
1365            | Expression::ArrayFlatten(f)
1366            | Expression::ArrayCompact(f)
1367            | Expression::ToArray(f)
1368            | Expression::JsonArrayLength(f)
1369            | Expression::JsonKeys(f)
1370            | Expression::JsonType(f)
1371            | Expression::ParseJson(f)
1372            | Expression::ToJson(f)
1373            | Expression::Radians(f)
1374            | Expression::Degrees(f)
1375            | Expression::Sin(f)
1376            | Expression::Cos(f)
1377            | Expression::Tan(f)
1378            | Expression::Asin(f)
1379            | Expression::Acos(f)
1380            | Expression::Atan(f)
1381            | Expression::IsNan(f)
1382            | Expression::IsInf(f)
1383            | Expression::Year(f)
1384            | Expression::Month(f)
1385            | Expression::Day(f)
1386            | Expression::Hour(f)
1387            | Expression::Minute(f)
1388            | Expression::Second(f)
1389            | Expression::DayOfWeek(f)
1390            | Expression::DayOfWeekIso(f)
1391            | Expression::DayOfMonth(f)
1392            | Expression::DayOfYear(f)
1393            | Expression::WeekOfYear(f)
1394            | Expression::Quarter(f)
1395            | Expression::Epoch(f)
1396            | Expression::EpochMs(f)
1397            | Expression::BitwiseCount(f)
1398            | Expression::DateFromUnixDate(f)
1399            | Expression::UnixDate(f)
1400            | Expression::UnixSeconds(f)
1401            | Expression::UnixMillis(f)
1402            | Expression::UnixMicros(f)
1403            | Expression::TimeStrToDate(f)
1404            | Expression::DateToDi(f)
1405            | Expression::DiToDate(f)
1406            | Expression::TsOrDiToDi(f)
1407            | Expression::TsOrDsToDatetime(f)
1408            | Expression::TsOrDsToTimestamp(f)
1409            | Expression::YearOfWeek(f)
1410            | Expression::YearOfWeekIso(f)
1411            | Expression::SHA(f)
1412            | Expression::SHA1Digest(f)
1413            | Expression::TimeToUnix(f)
1414            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1415
1416            // BinaryFunc variants
1417            Expression::Power(f)
1418            | Expression::NullIf(f)
1419            | Expression::IfNull(f)
1420            | Expression::Nvl(f)
1421            | Expression::Contains(f)
1422            | Expression::StartsWith(f)
1423            | Expression::EndsWith(f)
1424            | Expression::Levenshtein(f)
1425            | Expression::ModFunc(f)
1426            | Expression::IntDiv(f)
1427            | Expression::Atan2(f)
1428            | Expression::AddMonths(f)
1429            | Expression::MonthsBetween(f)
1430            | Expression::NextDay(f)
1431            | Expression::UnixToTimeStr(f)
1432            | Expression::ArrayContains(f)
1433            | Expression::ArrayPosition(f)
1434            | Expression::ArrayAppend(f)
1435            | Expression::ArrayPrepend(f)
1436            | Expression::ArrayUnion(f)
1437            | Expression::ArrayExcept(f)
1438            | Expression::ArrayRemove(f)
1439            | Expression::StarMap(f)
1440            | Expression::MapFromArrays(f)
1441            | Expression::MapContainsKey(f)
1442            | Expression::ElementAt(f)
1443            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1444
1445            // VarArgFunc variants
1446            Expression::Coalesce(f)
1447            | Expression::Greatest(f)
1448            | Expression::Least(f)
1449            | Expression::ArrayConcat(f)
1450            | Expression::ArrayIntersect(f)
1451            | Expression::ArrayZip(f)
1452            | Expression::MapConcat(f)
1453            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1454
1455            // AggFunc variants
1456            Expression::Sum(f)
1457            | Expression::Avg(f)
1458            | Expression::Min(f)
1459            | Expression::Max(f)
1460            | Expression::ArrayAgg(f)
1461            | Expression::CountIf(f)
1462            | Expression::Stddev(f)
1463            | Expression::StddevPop(f)
1464            | Expression::StddevSamp(f)
1465            | Expression::Variance(f)
1466            | Expression::VarPop(f)
1467            | Expression::VarSamp(f)
1468            | Expression::Median(f)
1469            | Expression::Mode(f)
1470            | Expression::First(f)
1471            | Expression::Last(f)
1472            | Expression::AnyValue(f)
1473            | Expression::ApproxDistinct(f)
1474            | Expression::ApproxCountDistinct(f)
1475            | Expression::LogicalAnd(f)
1476            | Expression::LogicalOr(f)
1477            | Expression::Skewness(f)
1478            | Expression::ArrayConcatAgg(f)
1479            | Expression::ArrayUniqueAgg(f)
1480            | Expression::BoolXorAgg(f)
1481            | Expression::BitwiseAndAgg(f)
1482            | Expression::BitwiseOrAgg(f)
1483            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1484
1485            // Everything else: no inferred_type field
1486            _ => None,
1487        }
1488    }
1489
1490    /// Set the inferred type annotation on this expression.
1491    ///
1492    /// Only has an effect on value-producing expressions with an `inferred_type`
1493    /// field. For other expression types, this is a no-op.
1494    pub fn set_inferred_type(&mut self, dt: DataType) {
1495        match self {
1496            Expression::And(op)
1497            | Expression::Or(op)
1498            | Expression::Add(op)
1499            | Expression::Sub(op)
1500            | Expression::Mul(op)
1501            | Expression::Div(op)
1502            | Expression::Mod(op)
1503            | Expression::Eq(op)
1504            | Expression::Neq(op)
1505            | Expression::Lt(op)
1506            | Expression::Lte(op)
1507            | Expression::Gt(op)
1508            | Expression::Gte(op)
1509            | Expression::Concat(op)
1510            | Expression::BitwiseAnd(op)
1511            | Expression::BitwiseOr(op)
1512            | Expression::BitwiseXor(op)
1513            | Expression::Adjacent(op)
1514            | Expression::TsMatch(op)
1515            | Expression::PropertyEQ(op)
1516            | Expression::ArrayContainsAll(op)
1517            | Expression::ArrayContainedBy(op)
1518            | Expression::ArrayOverlaps(op)
1519            | Expression::JSONBContainsAllTopKeys(op)
1520            | Expression::JSONBContainsAnyTopKeys(op)
1521            | Expression::JSONBDeleteAtPath(op)
1522            | Expression::ExtendsLeft(op)
1523            | Expression::ExtendsRight(op)
1524            | Expression::Is(op)
1525            | Expression::MemberOf(op)
1526            | Expression::Match(op)
1527            | Expression::NullSafeEq(op)
1528            | Expression::NullSafeNeq(op)
1529            | Expression::Glob(op)
1530            | Expression::BitwiseLeftShift(op)
1531            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1532
1533            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1534                op.inferred_type = Some(dt)
1535            }
1536
1537            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1538
1539            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1540                c.inferred_type = Some(dt)
1541            }
1542
1543            Expression::Column(c) => c.inferred_type = Some(dt),
1544            Expression::Function(f) => f.inferred_type = Some(dt),
1545            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1546            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1547            Expression::Case(c) => c.inferred_type = Some(dt),
1548            Expression::Subquery(s) => s.inferred_type = Some(dt),
1549            Expression::Alias(a) => a.inferred_type = Some(dt),
1550            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1551            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1552            Expression::Count(f) => f.inferred_type = Some(dt),
1553            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1554            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1555            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1556            Expression::SumIf(f) => f.inferred_type = Some(dt),
1557
1558            // UnaryFunc variants
1559            Expression::Upper(f)
1560            | Expression::Lower(f)
1561            | Expression::Length(f)
1562            | Expression::LTrim(f)
1563            | Expression::RTrim(f)
1564            | Expression::Reverse(f)
1565            | Expression::Abs(f)
1566            | Expression::Sqrt(f)
1567            | Expression::Cbrt(f)
1568            | Expression::Ln(f)
1569            | Expression::Exp(f)
1570            | Expression::Sign(f)
1571            | Expression::Date(f)
1572            | Expression::Time(f)
1573            | Expression::Initcap(f)
1574            | Expression::Ascii(f)
1575            | Expression::Chr(f)
1576            | Expression::Soundex(f)
1577            | Expression::ByteLength(f)
1578            | Expression::Hex(f)
1579            | Expression::LowerHex(f)
1580            | Expression::Unicode(f)
1581            | Expression::Typeof(f)
1582            | Expression::Explode(f)
1583            | Expression::ExplodeOuter(f)
1584            | Expression::MapFromEntries(f)
1585            | Expression::MapKeys(f)
1586            | Expression::MapValues(f)
1587            | Expression::ArrayLength(f)
1588            | Expression::ArraySize(f)
1589            | Expression::Cardinality(f)
1590            | Expression::ArrayReverse(f)
1591            | Expression::ArrayDistinct(f)
1592            | Expression::ArrayFlatten(f)
1593            | Expression::ArrayCompact(f)
1594            | Expression::ToArray(f)
1595            | Expression::JsonArrayLength(f)
1596            | Expression::JsonKeys(f)
1597            | Expression::JsonType(f)
1598            | Expression::ParseJson(f)
1599            | Expression::ToJson(f)
1600            | Expression::Radians(f)
1601            | Expression::Degrees(f)
1602            | Expression::Sin(f)
1603            | Expression::Cos(f)
1604            | Expression::Tan(f)
1605            | Expression::Asin(f)
1606            | Expression::Acos(f)
1607            | Expression::Atan(f)
1608            | Expression::IsNan(f)
1609            | Expression::IsInf(f)
1610            | Expression::Year(f)
1611            | Expression::Month(f)
1612            | Expression::Day(f)
1613            | Expression::Hour(f)
1614            | Expression::Minute(f)
1615            | Expression::Second(f)
1616            | Expression::DayOfWeek(f)
1617            | Expression::DayOfWeekIso(f)
1618            | Expression::DayOfMonth(f)
1619            | Expression::DayOfYear(f)
1620            | Expression::WeekOfYear(f)
1621            | Expression::Quarter(f)
1622            | Expression::Epoch(f)
1623            | Expression::EpochMs(f)
1624            | Expression::BitwiseCount(f)
1625            | Expression::DateFromUnixDate(f)
1626            | Expression::UnixDate(f)
1627            | Expression::UnixSeconds(f)
1628            | Expression::UnixMillis(f)
1629            | Expression::UnixMicros(f)
1630            | Expression::TimeStrToDate(f)
1631            | Expression::DateToDi(f)
1632            | Expression::DiToDate(f)
1633            | Expression::TsOrDiToDi(f)
1634            | Expression::TsOrDsToDatetime(f)
1635            | Expression::TsOrDsToTimestamp(f)
1636            | Expression::YearOfWeek(f)
1637            | Expression::YearOfWeekIso(f)
1638            | Expression::SHA(f)
1639            | Expression::SHA1Digest(f)
1640            | Expression::TimeToUnix(f)
1641            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1642
1643            // BinaryFunc variants
1644            Expression::Power(f)
1645            | Expression::NullIf(f)
1646            | Expression::IfNull(f)
1647            | Expression::Nvl(f)
1648            | Expression::Contains(f)
1649            | Expression::StartsWith(f)
1650            | Expression::EndsWith(f)
1651            | Expression::Levenshtein(f)
1652            | Expression::ModFunc(f)
1653            | Expression::IntDiv(f)
1654            | Expression::Atan2(f)
1655            | Expression::AddMonths(f)
1656            | Expression::MonthsBetween(f)
1657            | Expression::NextDay(f)
1658            | Expression::UnixToTimeStr(f)
1659            | Expression::ArrayContains(f)
1660            | Expression::ArrayPosition(f)
1661            | Expression::ArrayAppend(f)
1662            | Expression::ArrayPrepend(f)
1663            | Expression::ArrayUnion(f)
1664            | Expression::ArrayExcept(f)
1665            | Expression::ArrayRemove(f)
1666            | Expression::StarMap(f)
1667            | Expression::MapFromArrays(f)
1668            | Expression::MapContainsKey(f)
1669            | Expression::ElementAt(f)
1670            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1671
1672            // VarArgFunc variants
1673            Expression::Coalesce(f)
1674            | Expression::Greatest(f)
1675            | Expression::Least(f)
1676            | Expression::ArrayConcat(f)
1677            | Expression::ArrayIntersect(f)
1678            | Expression::ArrayZip(f)
1679            | Expression::MapConcat(f)
1680            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1681
1682            // AggFunc variants
1683            Expression::Sum(f)
1684            | Expression::Avg(f)
1685            | Expression::Min(f)
1686            | Expression::Max(f)
1687            | Expression::ArrayAgg(f)
1688            | Expression::CountIf(f)
1689            | Expression::Stddev(f)
1690            | Expression::StddevPop(f)
1691            | Expression::StddevSamp(f)
1692            | Expression::Variance(f)
1693            | Expression::VarPop(f)
1694            | Expression::VarSamp(f)
1695            | Expression::Median(f)
1696            | Expression::Mode(f)
1697            | Expression::First(f)
1698            | Expression::Last(f)
1699            | Expression::AnyValue(f)
1700            | Expression::ApproxDistinct(f)
1701            | Expression::ApproxCountDistinct(f)
1702            | Expression::LogicalAnd(f)
1703            | Expression::LogicalOr(f)
1704            | Expression::Skewness(f)
1705            | Expression::ArrayConcatAgg(f)
1706            | Expression::ArrayUniqueAgg(f)
1707            | Expression::BoolXorAgg(f)
1708            | Expression::BitwiseAndAgg(f)
1709            | Expression::BitwiseOrAgg(f)
1710            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1711
1712            // Expressions without inferred_type field - no-op
1713            _ => {}
1714        }
1715    }
1716
1717    /// Create an unqualified column reference (e.g. `name`).
1718    pub fn column(name: impl Into<String>) -> Self {
1719        Expression::Column(Box::new(Column {
1720            name: Identifier::new(name),
1721            table: None,
1722            join_mark: false,
1723            trailing_comments: Vec::new(),
1724            span: None,
1725            inferred_type: None,
1726        }))
1727    }
1728
1729    /// Create a qualified column reference (`table.column`).
1730    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1731        Expression::Column(Box::new(Column {
1732            name: Identifier::new(column),
1733            table: Some(Identifier::new(table)),
1734            join_mark: false,
1735            trailing_comments: Vec::new(),
1736            span: None,
1737            inferred_type: None,
1738        }))
1739    }
1740
1741    /// Create a bare identifier expression (not a column reference).
1742    pub fn identifier(name: impl Into<String>) -> Self {
1743        Expression::Identifier(Identifier::new(name))
1744    }
1745
1746    /// Create a NULL expression
1747    pub fn null() -> Self {
1748        Expression::Null(Null)
1749    }
1750
1751    /// Create a TRUE expression
1752    pub fn true_() -> Self {
1753        Expression::Boolean(BooleanLiteral { value: true })
1754    }
1755
1756    /// Create a FALSE expression
1757    pub fn false_() -> Self {
1758        Expression::Boolean(BooleanLiteral { value: false })
1759    }
1760
1761    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1762    pub fn star() -> Self {
1763        Expression::Star(Star {
1764            table: None,
1765            except: None,
1766            replace: None,
1767            rename: None,
1768            trailing_comments: Vec::new(),
1769            span: None,
1770        })
1771    }
1772
1773    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1774    pub fn alias(self, name: impl Into<String>) -> Self {
1775        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1776    }
1777
1778    /// Check if this is a SELECT expression
1779    pub fn is_select(&self) -> bool {
1780        matches!(self, Expression::Select(_))
1781    }
1782
1783    /// Try to get as a Select
1784    pub fn as_select(&self) -> Option<&Select> {
1785        match self {
1786            Expression::Select(s) => Some(s),
1787            _ => None,
1788        }
1789    }
1790
1791    /// Try to get as a mutable Select
1792    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1793        match self {
1794            Expression::Select(s) => Some(s),
1795            _ => None,
1796        }
1797    }
1798
1799    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1800    ///
1801    /// Returns an empty string if generation fails. For dialect-specific output,
1802    /// use [`sql_for()`](Self::sql_for) instead.
1803    #[cfg(feature = "generate")]
1804    pub fn sql(&self) -> String {
1805        crate::generator::Generator::sql(self).unwrap_or_default()
1806    }
1807
1808    /// Generate a SQL string for this expression targeting a specific dialect.
1809    ///
1810    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1811    /// syntax variations) are applied automatically.  Returns an empty string if
1812    /// generation fails.
1813    #[cfg(feature = "generate")]
1814    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1815        crate::generate(self, dialect).unwrap_or_default()
1816    }
1817}
1818
1819// === Python API accessor methods ===
1820
1821impl Expression {
1822    /// Returns the serde-compatible snake_case variant name without serialization.
1823    /// This is much faster than serializing to JSON and extracting the key.
1824    pub fn variant_name(&self) -> &'static str {
1825        match self {
1826            Expression::Literal(_) => "literal",
1827            Expression::Boolean(_) => "boolean",
1828            Expression::Null(_) => "null",
1829            Expression::Identifier(_) => "identifier",
1830            Expression::Column(_) => "column",
1831            Expression::Table(_) => "table",
1832            Expression::Star(_) => "star",
1833            Expression::BracedWildcard(_) => "braced_wildcard",
1834            Expression::Select(_) => "select",
1835            Expression::Union(_) => "union",
1836            Expression::Intersect(_) => "intersect",
1837            Expression::Except(_) => "except",
1838            Expression::Subquery(_) => "subquery",
1839            Expression::PipeOperator(_) => "pipe_operator",
1840            Expression::Pivot(_) => "pivot",
1841            Expression::PivotAlias(_) => "pivot_alias",
1842            Expression::Unpivot(_) => "unpivot",
1843            Expression::Values(_) => "values",
1844            Expression::PreWhere(_) => "pre_where",
1845            Expression::Stream(_) => "stream",
1846            Expression::UsingData(_) => "using_data",
1847            Expression::XmlNamespace(_) => "xml_namespace",
1848            Expression::Insert(_) => "insert",
1849            Expression::Update(_) => "update",
1850            Expression::Delete(_) => "delete",
1851            Expression::Copy(_) => "copy",
1852            Expression::Put(_) => "put",
1853            Expression::StageReference(_) => "stage_reference",
1854            Expression::Alias(_) => "alias",
1855            Expression::Cast(_) => "cast",
1856            Expression::Collation(_) => "collation",
1857            Expression::Case(_) => "case",
1858            Expression::And(_) => "and",
1859            Expression::Or(_) => "or",
1860            Expression::Add(_) => "add",
1861            Expression::Sub(_) => "sub",
1862            Expression::Mul(_) => "mul",
1863            Expression::Div(_) => "div",
1864            Expression::Mod(_) => "mod",
1865            Expression::Eq(_) => "eq",
1866            Expression::Neq(_) => "neq",
1867            Expression::Lt(_) => "lt",
1868            Expression::Lte(_) => "lte",
1869            Expression::Gt(_) => "gt",
1870            Expression::Gte(_) => "gte",
1871            Expression::Like(_) => "like",
1872            Expression::ILike(_) => "i_like",
1873            Expression::Match(_) => "match",
1874            Expression::BitwiseAnd(_) => "bitwise_and",
1875            Expression::BitwiseOr(_) => "bitwise_or",
1876            Expression::BitwiseXor(_) => "bitwise_xor",
1877            Expression::Concat(_) => "concat",
1878            Expression::Adjacent(_) => "adjacent",
1879            Expression::TsMatch(_) => "ts_match",
1880            Expression::PropertyEQ(_) => "property_e_q",
1881            Expression::ArrayContainsAll(_) => "array_contains_all",
1882            Expression::ArrayContainedBy(_) => "array_contained_by",
1883            Expression::ArrayOverlaps(_) => "array_overlaps",
1884            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1885            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1886            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1887            Expression::ExtendsLeft(_) => "extends_left",
1888            Expression::ExtendsRight(_) => "extends_right",
1889            Expression::Not(_) => "not",
1890            Expression::Neg(_) => "neg",
1891            Expression::BitwiseNot(_) => "bitwise_not",
1892            Expression::In(_) => "in",
1893            Expression::Between(_) => "between",
1894            Expression::IsNull(_) => "is_null",
1895            Expression::IsTrue(_) => "is_true",
1896            Expression::IsFalse(_) => "is_false",
1897            Expression::IsJson(_) => "is_json",
1898            Expression::Is(_) => "is",
1899            Expression::Exists(_) => "exists",
1900            Expression::MemberOf(_) => "member_of",
1901            Expression::Function(_) => "function",
1902            Expression::AggregateFunction(_) => "aggregate_function",
1903            Expression::WindowFunction(_) => "window_function",
1904            Expression::From(_) => "from",
1905            Expression::Join(_) => "join",
1906            Expression::JoinedTable(_) => "joined_table",
1907            Expression::Where(_) => "where",
1908            Expression::GroupBy(_) => "group_by",
1909            Expression::Having(_) => "having",
1910            Expression::OrderBy(_) => "order_by",
1911            Expression::Limit(_) => "limit",
1912            Expression::Offset(_) => "offset",
1913            Expression::Qualify(_) => "qualify",
1914            Expression::With(_) => "with",
1915            Expression::Cte(_) => "cte",
1916            Expression::DistributeBy(_) => "distribute_by",
1917            Expression::ClusterBy(_) => "cluster_by",
1918            Expression::SortBy(_) => "sort_by",
1919            Expression::LateralView(_) => "lateral_view",
1920            Expression::Hint(_) => "hint",
1921            Expression::Pseudocolumn(_) => "pseudocolumn",
1922            Expression::Connect(_) => "connect",
1923            Expression::Prior(_) => "prior",
1924            Expression::ConnectByRoot(_) => "connect_by_root",
1925            Expression::MatchRecognize(_) => "match_recognize",
1926            Expression::Ordered(_) => "ordered",
1927            Expression::Window(_) => "window",
1928            Expression::Over(_) => "over",
1929            Expression::WithinGroup(_) => "within_group",
1930            Expression::DataType(_) => "data_type",
1931            Expression::Array(_) => "array",
1932            Expression::Struct(_) => "struct",
1933            Expression::Tuple(_) => "tuple",
1934            Expression::Interval(_) => "interval",
1935            Expression::ConcatWs(_) => "concat_ws",
1936            Expression::Substring(_) => "substring",
1937            Expression::Upper(_) => "upper",
1938            Expression::Lower(_) => "lower",
1939            Expression::Length(_) => "length",
1940            Expression::Trim(_) => "trim",
1941            Expression::LTrim(_) => "l_trim",
1942            Expression::RTrim(_) => "r_trim",
1943            Expression::Replace(_) => "replace",
1944            Expression::Reverse(_) => "reverse",
1945            Expression::Left(_) => "left",
1946            Expression::Right(_) => "right",
1947            Expression::Repeat(_) => "repeat",
1948            Expression::Lpad(_) => "lpad",
1949            Expression::Rpad(_) => "rpad",
1950            Expression::Split(_) => "split",
1951            Expression::RegexpLike(_) => "regexp_like",
1952            Expression::RegexpReplace(_) => "regexp_replace",
1953            Expression::RegexpExtract(_) => "regexp_extract",
1954            Expression::Overlay(_) => "overlay",
1955            Expression::Abs(_) => "abs",
1956            Expression::Round(_) => "round",
1957            Expression::Floor(_) => "floor",
1958            Expression::Ceil(_) => "ceil",
1959            Expression::Power(_) => "power",
1960            Expression::Sqrt(_) => "sqrt",
1961            Expression::Cbrt(_) => "cbrt",
1962            Expression::Ln(_) => "ln",
1963            Expression::Log(_) => "log",
1964            Expression::Exp(_) => "exp",
1965            Expression::Sign(_) => "sign",
1966            Expression::Greatest(_) => "greatest",
1967            Expression::Least(_) => "least",
1968            Expression::CurrentDate(_) => "current_date",
1969            Expression::CurrentTime(_) => "current_time",
1970            Expression::CurrentTimestamp(_) => "current_timestamp",
1971            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1972            Expression::AtTimeZone(_) => "at_time_zone",
1973            Expression::DateAdd(_) => "date_add",
1974            Expression::DateSub(_) => "date_sub",
1975            Expression::DateDiff(_) => "date_diff",
1976            Expression::DateTrunc(_) => "date_trunc",
1977            Expression::Extract(_) => "extract",
1978            Expression::ToDate(_) => "to_date",
1979            Expression::ToTimestamp(_) => "to_timestamp",
1980            Expression::Date(_) => "date",
1981            Expression::Time(_) => "time",
1982            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1983            Expression::UnixDate(_) => "unix_date",
1984            Expression::UnixSeconds(_) => "unix_seconds",
1985            Expression::UnixMillis(_) => "unix_millis",
1986            Expression::UnixMicros(_) => "unix_micros",
1987            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1988            Expression::TimeStrToDate(_) => "time_str_to_date",
1989            Expression::DateToDi(_) => "date_to_di",
1990            Expression::DiToDate(_) => "di_to_date",
1991            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1992            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1993            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1994            Expression::YearOfWeek(_) => "year_of_week",
1995            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1996            Expression::Coalesce(_) => "coalesce",
1997            Expression::NullIf(_) => "null_if",
1998            Expression::IfFunc(_) => "if_func",
1999            Expression::IfNull(_) => "if_null",
2000            Expression::Nvl(_) => "nvl",
2001            Expression::Nvl2(_) => "nvl2",
2002            Expression::TryCast(_) => "try_cast",
2003            Expression::SafeCast(_) => "safe_cast",
2004            Expression::Count(_) => "count",
2005            Expression::Sum(_) => "sum",
2006            Expression::Avg(_) => "avg",
2007            Expression::Min(_) => "min",
2008            Expression::Max(_) => "max",
2009            Expression::GroupConcat(_) => "group_concat",
2010            Expression::StringAgg(_) => "string_agg",
2011            Expression::ListAgg(_) => "list_agg",
2012            Expression::ArrayAgg(_) => "array_agg",
2013            Expression::CountIf(_) => "count_if",
2014            Expression::SumIf(_) => "sum_if",
2015            Expression::Stddev(_) => "stddev",
2016            Expression::StddevPop(_) => "stddev_pop",
2017            Expression::StddevSamp(_) => "stddev_samp",
2018            Expression::Variance(_) => "variance",
2019            Expression::VarPop(_) => "var_pop",
2020            Expression::VarSamp(_) => "var_samp",
2021            Expression::Median(_) => "median",
2022            Expression::Mode(_) => "mode",
2023            Expression::First(_) => "first",
2024            Expression::Last(_) => "last",
2025            Expression::AnyValue(_) => "any_value",
2026            Expression::ApproxDistinct(_) => "approx_distinct",
2027            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2028            Expression::ApproxPercentile(_) => "approx_percentile",
2029            Expression::Percentile(_) => "percentile",
2030            Expression::LogicalAnd(_) => "logical_and",
2031            Expression::LogicalOr(_) => "logical_or",
2032            Expression::Skewness(_) => "skewness",
2033            Expression::BitwiseCount(_) => "bitwise_count",
2034            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2035            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2036            Expression::BoolXorAgg(_) => "bool_xor_agg",
2037            Expression::RowNumber(_) => "row_number",
2038            Expression::Rank(_) => "rank",
2039            Expression::DenseRank(_) => "dense_rank",
2040            Expression::NTile(_) => "n_tile",
2041            Expression::Lead(_) => "lead",
2042            Expression::Lag(_) => "lag",
2043            Expression::FirstValue(_) => "first_value",
2044            Expression::LastValue(_) => "last_value",
2045            Expression::NthValue(_) => "nth_value",
2046            Expression::PercentRank(_) => "percent_rank",
2047            Expression::CumeDist(_) => "cume_dist",
2048            Expression::PercentileCont(_) => "percentile_cont",
2049            Expression::PercentileDisc(_) => "percentile_disc",
2050            Expression::Contains(_) => "contains",
2051            Expression::StartsWith(_) => "starts_with",
2052            Expression::EndsWith(_) => "ends_with",
2053            Expression::Position(_) => "position",
2054            Expression::Initcap(_) => "initcap",
2055            Expression::Ascii(_) => "ascii",
2056            Expression::Chr(_) => "chr",
2057            Expression::CharFunc(_) => "char_func",
2058            Expression::Soundex(_) => "soundex",
2059            Expression::Levenshtein(_) => "levenshtein",
2060            Expression::ByteLength(_) => "byte_length",
2061            Expression::Hex(_) => "hex",
2062            Expression::LowerHex(_) => "lower_hex",
2063            Expression::Unicode(_) => "unicode",
2064            Expression::ModFunc(_) => "mod_func",
2065            Expression::Random(_) => "random",
2066            Expression::Rand(_) => "rand",
2067            Expression::TruncFunc(_) => "trunc_func",
2068            Expression::Pi(_) => "pi",
2069            Expression::Radians(_) => "radians",
2070            Expression::Degrees(_) => "degrees",
2071            Expression::Sin(_) => "sin",
2072            Expression::Cos(_) => "cos",
2073            Expression::Tan(_) => "tan",
2074            Expression::Asin(_) => "asin",
2075            Expression::Acos(_) => "acos",
2076            Expression::Atan(_) => "atan",
2077            Expression::Atan2(_) => "atan2",
2078            Expression::IsNan(_) => "is_nan",
2079            Expression::IsInf(_) => "is_inf",
2080            Expression::IntDiv(_) => "int_div",
2081            Expression::Decode(_) => "decode",
2082            Expression::DateFormat(_) => "date_format",
2083            Expression::FormatDate(_) => "format_date",
2084            Expression::Year(_) => "year",
2085            Expression::Month(_) => "month",
2086            Expression::Day(_) => "day",
2087            Expression::Hour(_) => "hour",
2088            Expression::Minute(_) => "minute",
2089            Expression::Second(_) => "second",
2090            Expression::DayOfWeek(_) => "day_of_week",
2091            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2092            Expression::DayOfMonth(_) => "day_of_month",
2093            Expression::DayOfYear(_) => "day_of_year",
2094            Expression::WeekOfYear(_) => "week_of_year",
2095            Expression::Quarter(_) => "quarter",
2096            Expression::AddMonths(_) => "add_months",
2097            Expression::MonthsBetween(_) => "months_between",
2098            Expression::LastDay(_) => "last_day",
2099            Expression::NextDay(_) => "next_day",
2100            Expression::Epoch(_) => "epoch",
2101            Expression::EpochMs(_) => "epoch_ms",
2102            Expression::FromUnixtime(_) => "from_unixtime",
2103            Expression::UnixTimestamp(_) => "unix_timestamp",
2104            Expression::MakeDate(_) => "make_date",
2105            Expression::MakeTimestamp(_) => "make_timestamp",
2106            Expression::TimestampTrunc(_) => "timestamp_trunc",
2107            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2108            Expression::SessionUser(_) => "session_user",
2109            Expression::SHA(_) => "s_h_a",
2110            Expression::SHA1Digest(_) => "s_h_a1_digest",
2111            Expression::TimeToUnix(_) => "time_to_unix",
2112            Expression::ArrayFunc(_) => "array_func",
2113            Expression::ArrayLength(_) => "array_length",
2114            Expression::ArraySize(_) => "array_size",
2115            Expression::Cardinality(_) => "cardinality",
2116            Expression::ArrayContains(_) => "array_contains",
2117            Expression::ArrayPosition(_) => "array_position",
2118            Expression::ArrayAppend(_) => "array_append",
2119            Expression::ArrayPrepend(_) => "array_prepend",
2120            Expression::ArrayConcat(_) => "array_concat",
2121            Expression::ArraySort(_) => "array_sort",
2122            Expression::ArrayReverse(_) => "array_reverse",
2123            Expression::ArrayDistinct(_) => "array_distinct",
2124            Expression::ArrayJoin(_) => "array_join",
2125            Expression::ArrayToString(_) => "array_to_string",
2126            Expression::Unnest(_) => "unnest",
2127            Expression::Explode(_) => "explode",
2128            Expression::ExplodeOuter(_) => "explode_outer",
2129            Expression::ArrayFilter(_) => "array_filter",
2130            Expression::ArrayTransform(_) => "array_transform",
2131            Expression::ArrayFlatten(_) => "array_flatten",
2132            Expression::ArrayCompact(_) => "array_compact",
2133            Expression::ArrayIntersect(_) => "array_intersect",
2134            Expression::ArrayUnion(_) => "array_union",
2135            Expression::ArrayExcept(_) => "array_except",
2136            Expression::ArrayRemove(_) => "array_remove",
2137            Expression::ArrayZip(_) => "array_zip",
2138            Expression::Sequence(_) => "sequence",
2139            Expression::Generate(_) => "generate",
2140            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2141            Expression::ToArray(_) => "to_array",
2142            Expression::StarMap(_) => "star_map",
2143            Expression::StructFunc(_) => "struct_func",
2144            Expression::StructExtract(_) => "struct_extract",
2145            Expression::NamedStruct(_) => "named_struct",
2146            Expression::MapFunc(_) => "map_func",
2147            Expression::MapFromEntries(_) => "map_from_entries",
2148            Expression::MapFromArrays(_) => "map_from_arrays",
2149            Expression::MapKeys(_) => "map_keys",
2150            Expression::MapValues(_) => "map_values",
2151            Expression::MapContainsKey(_) => "map_contains_key",
2152            Expression::MapConcat(_) => "map_concat",
2153            Expression::ElementAt(_) => "element_at",
2154            Expression::TransformKeys(_) => "transform_keys",
2155            Expression::TransformValues(_) => "transform_values",
2156            Expression::FunctionEmits(_) => "function_emits",
2157            Expression::JsonExtract(_) => "json_extract",
2158            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2159            Expression::JsonExtractPath(_) => "json_extract_path",
2160            Expression::JsonArray(_) => "json_array",
2161            Expression::JsonObject(_) => "json_object",
2162            Expression::JsonQuery(_) => "json_query",
2163            Expression::JsonValue(_) => "json_value",
2164            Expression::JsonArrayLength(_) => "json_array_length",
2165            Expression::JsonKeys(_) => "json_keys",
2166            Expression::JsonType(_) => "json_type",
2167            Expression::ParseJson(_) => "parse_json",
2168            Expression::ToJson(_) => "to_json",
2169            Expression::JsonSet(_) => "json_set",
2170            Expression::JsonInsert(_) => "json_insert",
2171            Expression::JsonRemove(_) => "json_remove",
2172            Expression::JsonMergePatch(_) => "json_merge_patch",
2173            Expression::JsonArrayAgg(_) => "json_array_agg",
2174            Expression::JsonObjectAgg(_) => "json_object_agg",
2175            Expression::Convert(_) => "convert",
2176            Expression::Typeof(_) => "typeof",
2177            Expression::Lambda(_) => "lambda",
2178            Expression::Parameter(_) => "parameter",
2179            Expression::Placeholder(_) => "placeholder",
2180            Expression::NamedArgument(_) => "named_argument",
2181            Expression::TableArgument(_) => "table_argument",
2182            Expression::SqlComment(_) => "sql_comment",
2183            Expression::NullSafeEq(_) => "null_safe_eq",
2184            Expression::NullSafeNeq(_) => "null_safe_neq",
2185            Expression::Glob(_) => "glob",
2186            Expression::SimilarTo(_) => "similar_to",
2187            Expression::Any(_) => "any",
2188            Expression::All(_) => "all",
2189            Expression::Overlaps(_) => "overlaps",
2190            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2191            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2192            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2193            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2194            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2195            Expression::Subscript(_) => "subscript",
2196            Expression::Dot(_) => "dot",
2197            Expression::MethodCall(_) => "method_call",
2198            Expression::ArraySlice(_) => "array_slice",
2199            Expression::CreateTable(_) => "create_table",
2200            Expression::DropTable(_) => "drop_table",
2201            Expression::Undrop(_) => "undrop",
2202            Expression::AlterTable(_) => "alter_table",
2203            Expression::CreateIndex(_) => "create_index",
2204            Expression::DropIndex(_) => "drop_index",
2205            Expression::CreateView(_) => "create_view",
2206            Expression::DropView(_) => "drop_view",
2207            Expression::AlterView(_) => "alter_view",
2208            Expression::AlterIndex(_) => "alter_index",
2209            Expression::Truncate(_) => "truncate",
2210            Expression::Use(_) => "use",
2211            Expression::Cache(_) => "cache",
2212            Expression::Uncache(_) => "uncache",
2213            Expression::LoadData(_) => "load_data",
2214            Expression::Pragma(_) => "pragma",
2215            Expression::Grant(_) => "grant",
2216            Expression::Revoke(_) => "revoke",
2217            Expression::Comment(_) => "comment",
2218            Expression::SetStatement(_) => "set_statement",
2219            Expression::CreateSchema(_) => "create_schema",
2220            Expression::DropSchema(_) => "drop_schema",
2221            Expression::DropNamespace(_) => "drop_namespace",
2222            Expression::CreateDatabase(_) => "create_database",
2223            Expression::DropDatabase(_) => "drop_database",
2224            Expression::CreateFunction(_) => "create_function",
2225            Expression::DropFunction(_) => "drop_function",
2226            Expression::CreateProcedure(_) => "create_procedure",
2227            Expression::DropProcedure(_) => "drop_procedure",
2228            Expression::CreateSequence(_) => "create_sequence",
2229            Expression::CreateSynonym(_) => "create_synonym",
2230            Expression::DropSequence(_) => "drop_sequence",
2231            Expression::AlterSequence(_) => "alter_sequence",
2232            Expression::CreateTrigger(_) => "create_trigger",
2233            Expression::DropTrigger(_) => "drop_trigger",
2234            Expression::CreateType(_) => "create_type",
2235            Expression::DropType(_) => "drop_type",
2236            Expression::Describe(_) => "describe",
2237            Expression::Show(_) => "show",
2238            Expression::Command(_) => "command",
2239            Expression::TryCatch(_) => "try_catch",
2240            Expression::Kill(_) => "kill",
2241            Expression::Prepare(_) => "prepare",
2242            Expression::Execute(_) => "execute",
2243            Expression::Raw(_) => "raw",
2244            Expression::CreateTask(_) => "create_task",
2245            Expression::Paren(_) => "paren",
2246            Expression::Annotated(_) => "annotated",
2247            Expression::Refresh(_) => "refresh",
2248            Expression::LockingStatement(_) => "locking_statement",
2249            Expression::SequenceProperties(_) => "sequence_properties",
2250            Expression::TruncateTable(_) => "truncate_table",
2251            Expression::Clone(_) => "clone",
2252            Expression::Attach(_) => "attach",
2253            Expression::Detach(_) => "detach",
2254            Expression::Install(_) => "install",
2255            Expression::Summarize(_) => "summarize",
2256            Expression::Declare(_) => "declare",
2257            Expression::DeclareItem(_) => "declare_item",
2258            Expression::Set(_) => "set",
2259            Expression::Heredoc(_) => "heredoc",
2260            Expression::SetItem(_) => "set_item",
2261            Expression::QueryBand(_) => "query_band",
2262            Expression::UserDefinedFunction(_) => "user_defined_function",
2263            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2264            Expression::ProjectionDef(_) => "projection_def",
2265            Expression::TableAlias(_) => "table_alias",
2266            Expression::ByteString(_) => "byte_string",
2267            Expression::HexStringExpr(_) => "hex_string_expr",
2268            Expression::UnicodeString(_) => "unicode_string",
2269            Expression::ColumnPosition(_) => "column_position",
2270            Expression::ColumnDef(_) => "column_def",
2271            Expression::AlterColumn(_) => "alter_column",
2272            Expression::AlterSortKey(_) => "alter_sort_key",
2273            Expression::AlterSet(_) => "alter_set",
2274            Expression::RenameColumn(_) => "rename_column",
2275            Expression::Comprehension(_) => "comprehension",
2276            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2277            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2278            Expression::IndexConstraintOption(_) => "index_constraint_option",
2279            Expression::ColumnConstraint(_) => "column_constraint",
2280            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2281            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2282            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2283            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2284            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2285            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2286            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2287            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2288            Expression::WithOperator(_) => "with_operator",
2289            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2290                "generated_as_identity_column_constraint"
2291            }
2292            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2293            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2294            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2295            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2296            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2297            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2298            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2299            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2300            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2301            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2302            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2303            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2304            Expression::PathColumnConstraint(_) => "path_column_constraint",
2305            Expression::Constraint(_) => "constraint",
2306            Expression::Export(_) => "export",
2307            Expression::Filter(_) => "filter",
2308            Expression::Changes(_) => "changes",
2309            Expression::CopyParameter(_) => "copy_parameter",
2310            Expression::Credentials(_) => "credentials",
2311            Expression::Directory(_) => "directory",
2312            Expression::ForeignKey(_) => "foreign_key",
2313            Expression::ColumnPrefix(_) => "column_prefix",
2314            Expression::PrimaryKey(_) => "primary_key",
2315            Expression::IntoClause(_) => "into_clause",
2316            Expression::JoinHint(_) => "join_hint",
2317            Expression::Opclass(_) => "opclass",
2318            Expression::Index(_) => "index",
2319            Expression::IndexParameters(_) => "index_parameters",
2320            Expression::ConditionalInsert(_) => "conditional_insert",
2321            Expression::MultitableInserts(_) => "multitable_inserts",
2322            Expression::OnConflict(_) => "on_conflict",
2323            Expression::OnCondition(_) => "on_condition",
2324            Expression::Returning(_) => "returning",
2325            Expression::Introducer(_) => "introducer",
2326            Expression::PartitionRange(_) => "partition_range",
2327            Expression::Fetch(_) => "fetch",
2328            Expression::Group(_) => "group",
2329            Expression::Cube(_) => "cube",
2330            Expression::Rollup(_) => "rollup",
2331            Expression::GroupingSets(_) => "grouping_sets",
2332            Expression::LimitOptions(_) => "limit_options",
2333            Expression::Lateral(_) => "lateral",
2334            Expression::TableFromRows(_) => "table_from_rows",
2335            Expression::RowsFrom(_) => "rows_from",
2336            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2337            Expression::WithFill(_) => "with_fill",
2338            Expression::Property(_) => "property",
2339            Expression::GrantPrivilege(_) => "grant_privilege",
2340            Expression::GrantPrincipal(_) => "grant_principal",
2341            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2342            Expression::AlgorithmProperty(_) => "algorithm_property",
2343            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2344            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2345            Expression::BackupProperty(_) => "backup_property",
2346            Expression::BuildProperty(_) => "build_property",
2347            Expression::BlockCompressionProperty(_) => "block_compression_property",
2348            Expression::CharacterSetProperty(_) => "character_set_property",
2349            Expression::ChecksumProperty(_) => "checksum_property",
2350            Expression::CollateProperty(_) => "collate_property",
2351            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2352            Expression::DataDeletionProperty(_) => "data_deletion_property",
2353            Expression::DefinerProperty(_) => "definer_property",
2354            Expression::DistKeyProperty(_) => "dist_key_property",
2355            Expression::DistributedByProperty(_) => "distributed_by_property",
2356            Expression::DistStyleProperty(_) => "dist_style_property",
2357            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2358            Expression::EngineProperty(_) => "engine_property",
2359            Expression::ToTableProperty(_) => "to_table_property",
2360            Expression::ExecuteAsProperty(_) => "execute_as_property",
2361            Expression::ExternalProperty(_) => "external_property",
2362            Expression::FallbackProperty(_) => "fallback_property",
2363            Expression::FileFormatProperty(_) => "file_format_property",
2364            Expression::CredentialsProperty(_) => "credentials_property",
2365            Expression::FreespaceProperty(_) => "freespace_property",
2366            Expression::InheritsProperty(_) => "inherits_property",
2367            Expression::InputModelProperty(_) => "input_model_property",
2368            Expression::OutputModelProperty(_) => "output_model_property",
2369            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2370            Expression::JournalProperty(_) => "journal_property",
2371            Expression::LanguageProperty(_) => "language_property",
2372            Expression::EnviromentProperty(_) => "enviroment_property",
2373            Expression::ClusteredByProperty(_) => "clustered_by_property",
2374            Expression::DictProperty(_) => "dict_property",
2375            Expression::DictRange(_) => "dict_range",
2376            Expression::OnCluster(_) => "on_cluster",
2377            Expression::LikeProperty(_) => "like_property",
2378            Expression::LocationProperty(_) => "location_property",
2379            Expression::LockProperty(_) => "lock_property",
2380            Expression::LockingProperty(_) => "locking_property",
2381            Expression::LogProperty(_) => "log_property",
2382            Expression::MaterializedProperty(_) => "materialized_property",
2383            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2384            Expression::OnProperty(_) => "on_property",
2385            Expression::OnCommitProperty(_) => "on_commit_property",
2386            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2387            Expression::PartitionByProperty(_) => "partition_by_property",
2388            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2389            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2390            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2391            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2392            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2393            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2394            Expression::PartitionList(_) => "partition_list",
2395            Expression::Partition(_) => "partition",
2396            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2397            Expression::UniqueKeyProperty(_) => "unique_key_property",
2398            Expression::RollupProperty(_) => "rollup_property",
2399            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2400            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2401            Expression::RemoteWithConnectionModelProperty(_) => {
2402                "remote_with_connection_model_property"
2403            }
2404            Expression::ReturnsProperty(_) => "returns_property",
2405            Expression::RowFormatProperty(_) => "row_format_property",
2406            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2407            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2408            Expression::QueryTransform(_) => "query_transform",
2409            Expression::SampleProperty(_) => "sample_property",
2410            Expression::SecurityProperty(_) => "security_property",
2411            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2412            Expression::SemanticView(_) => "semantic_view",
2413            Expression::SerdeProperties(_) => "serde_properties",
2414            Expression::SetProperty(_) => "set_property",
2415            Expression::SharingProperty(_) => "sharing_property",
2416            Expression::SetConfigProperty(_) => "set_config_property",
2417            Expression::SettingsProperty(_) => "settings_property",
2418            Expression::SortKeyProperty(_) => "sort_key_property",
2419            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2420            Expression::SqlSecurityProperty(_) => "sql_security_property",
2421            Expression::StabilityProperty(_) => "stability_property",
2422            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2423            Expression::TemporaryProperty(_) => "temporary_property",
2424            Expression::Tags(_) => "tags",
2425            Expression::TransformModelProperty(_) => "transform_model_property",
2426            Expression::TransientProperty(_) => "transient_property",
2427            Expression::UsingTemplateProperty(_) => "using_template_property",
2428            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2429            Expression::VolatileProperty(_) => "volatile_property",
2430            Expression::WithDataProperty(_) => "with_data_property",
2431            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2432            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2433            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2434            Expression::WithProcedureOptions(_) => "with_procedure_options",
2435            Expression::EncodeProperty(_) => "encode_property",
2436            Expression::IncludeProperty(_) => "include_property",
2437            Expression::Properties(_) => "properties",
2438            Expression::OptionsProperty(_) => "options_property",
2439            Expression::InputOutputFormat(_) => "input_output_format",
2440            Expression::Reference(_) => "reference",
2441            Expression::QueryOption(_) => "query_option",
2442            Expression::WithTableHint(_) => "with_table_hint",
2443            Expression::IndexTableHint(_) => "index_table_hint",
2444            Expression::HistoricalData(_) => "historical_data",
2445            Expression::Get(_) => "get",
2446            Expression::SetOperation(_) => "set_operation",
2447            Expression::Var(_) => "var",
2448            Expression::Variadic(_) => "variadic",
2449            Expression::Version(_) => "version",
2450            Expression::Schema(_) => "schema",
2451            Expression::Lock(_) => "lock",
2452            Expression::TableSample(_) => "table_sample",
2453            Expression::Tag(_) => "tag",
2454            Expression::UnpivotColumns(_) => "unpivot_columns",
2455            Expression::WindowSpec(_) => "window_spec",
2456            Expression::SessionParameter(_) => "session_parameter",
2457            Expression::PseudoType(_) => "pseudo_type",
2458            Expression::ObjectIdentifier(_) => "object_identifier",
2459            Expression::Transaction(_) => "transaction",
2460            Expression::Commit(_) => "commit",
2461            Expression::Rollback(_) => "rollback",
2462            Expression::AlterSession(_) => "alter_session",
2463            Expression::Analyze(_) => "analyze",
2464            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2465            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2466            Expression::AnalyzeSample(_) => "analyze_sample",
2467            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2468            Expression::AnalyzeDelete(_) => "analyze_delete",
2469            Expression::AnalyzeWith(_) => "analyze_with",
2470            Expression::AnalyzeValidate(_) => "analyze_validate",
2471            Expression::AddPartition(_) => "add_partition",
2472            Expression::AttachOption(_) => "attach_option",
2473            Expression::DropPartition(_) => "drop_partition",
2474            Expression::ReplacePartition(_) => "replace_partition",
2475            Expression::DPipe(_) => "d_pipe",
2476            Expression::Operator(_) => "operator",
2477            Expression::PivotAny(_) => "pivot_any",
2478            Expression::Aliases(_) => "aliases",
2479            Expression::AtIndex(_) => "at_index",
2480            Expression::FromTimeZone(_) => "from_time_zone",
2481            Expression::FormatPhrase(_) => "format_phrase",
2482            Expression::ForIn(_) => "for_in",
2483            Expression::TimeUnit(_) => "time_unit",
2484            Expression::IntervalOp(_) => "interval_op",
2485            Expression::IntervalSpan(_) => "interval_span",
2486            Expression::HavingMax(_) => "having_max",
2487            Expression::CosineDistance(_) => "cosine_distance",
2488            Expression::DotProduct(_) => "dot_product",
2489            Expression::EuclideanDistance(_) => "euclidean_distance",
2490            Expression::ManhattanDistance(_) => "manhattan_distance",
2491            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2492            Expression::Booland(_) => "booland",
2493            Expression::Boolor(_) => "boolor",
2494            Expression::ParameterizedAgg(_) => "parameterized_agg",
2495            Expression::ArgMax(_) => "arg_max",
2496            Expression::ArgMin(_) => "arg_min",
2497            Expression::ApproxTopK(_) => "approx_top_k",
2498            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2499            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2500            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2501            Expression::ApproxTopSum(_) => "approx_top_sum",
2502            Expression::ApproxQuantiles(_) => "approx_quantiles",
2503            Expression::Minhash(_) => "minhash",
2504            Expression::FarmFingerprint(_) => "farm_fingerprint",
2505            Expression::Float64(_) => "float64",
2506            Expression::Transform(_) => "transform",
2507            Expression::Translate(_) => "translate",
2508            Expression::Grouping(_) => "grouping",
2509            Expression::GroupingId(_) => "grouping_id",
2510            Expression::Anonymous(_) => "anonymous",
2511            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2512            Expression::CombinedAggFunc(_) => "combined_agg_func",
2513            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2514            Expression::HashAgg(_) => "hash_agg",
2515            Expression::Hll(_) => "hll",
2516            Expression::Apply(_) => "apply",
2517            Expression::ToBoolean(_) => "to_boolean",
2518            Expression::List(_) => "list",
2519            Expression::ToMap(_) => "to_map",
2520            Expression::Pad(_) => "pad",
2521            Expression::ToChar(_) => "to_char",
2522            Expression::ToNumber(_) => "to_number",
2523            Expression::ToDouble(_) => "to_double",
2524            Expression::Int64(_) => "int64",
2525            Expression::StringFunc(_) => "string_func",
2526            Expression::ToDecfloat(_) => "to_decfloat",
2527            Expression::TryToDecfloat(_) => "try_to_decfloat",
2528            Expression::ToFile(_) => "to_file",
2529            Expression::Columns(_) => "columns",
2530            Expression::ConvertToCharset(_) => "convert_to_charset",
2531            Expression::ConvertTimezone(_) => "convert_timezone",
2532            Expression::GenerateSeries(_) => "generate_series",
2533            Expression::AIAgg(_) => "a_i_agg",
2534            Expression::AIClassify(_) => "a_i_classify",
2535            Expression::ArrayAll(_) => "array_all",
2536            Expression::ArrayAny(_) => "array_any",
2537            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2538            Expression::StPoint(_) => "st_point",
2539            Expression::StDistance(_) => "st_distance",
2540            Expression::StringToArray(_) => "string_to_array",
2541            Expression::ArraySum(_) => "array_sum",
2542            Expression::ObjectAgg(_) => "object_agg",
2543            Expression::CastToStrType(_) => "cast_to_str_type",
2544            Expression::CheckJson(_) => "check_json",
2545            Expression::CheckXml(_) => "check_xml",
2546            Expression::TranslateCharacters(_) => "translate_characters",
2547            Expression::CurrentSchemas(_) => "current_schemas",
2548            Expression::CurrentDatetime(_) => "current_datetime",
2549            Expression::Localtime(_) => "localtime",
2550            Expression::Localtimestamp(_) => "localtimestamp",
2551            Expression::Systimestamp(_) => "systimestamp",
2552            Expression::CurrentSchema(_) => "current_schema",
2553            Expression::CurrentUser(_) => "current_user",
2554            Expression::UtcTime(_) => "utc_time",
2555            Expression::UtcTimestamp(_) => "utc_timestamp",
2556            Expression::Timestamp(_) => "timestamp",
2557            Expression::DateBin(_) => "date_bin",
2558            Expression::Datetime(_) => "datetime",
2559            Expression::DatetimeAdd(_) => "datetime_add",
2560            Expression::DatetimeSub(_) => "datetime_sub",
2561            Expression::DatetimeDiff(_) => "datetime_diff",
2562            Expression::DatetimeTrunc(_) => "datetime_trunc",
2563            Expression::Dayname(_) => "dayname",
2564            Expression::MakeInterval(_) => "make_interval",
2565            Expression::PreviousDay(_) => "previous_day",
2566            Expression::Elt(_) => "elt",
2567            Expression::TimestampAdd(_) => "timestamp_add",
2568            Expression::TimestampSub(_) => "timestamp_sub",
2569            Expression::TimestampDiff(_) => "timestamp_diff",
2570            Expression::TimeSlice(_) => "time_slice",
2571            Expression::TimeAdd(_) => "time_add",
2572            Expression::TimeSub(_) => "time_sub",
2573            Expression::TimeDiff(_) => "time_diff",
2574            Expression::TimeTrunc(_) => "time_trunc",
2575            Expression::DateFromParts(_) => "date_from_parts",
2576            Expression::TimeFromParts(_) => "time_from_parts",
2577            Expression::DecodeCase(_) => "decode_case",
2578            Expression::Decrypt(_) => "decrypt",
2579            Expression::DecryptRaw(_) => "decrypt_raw",
2580            Expression::Encode(_) => "encode",
2581            Expression::Encrypt(_) => "encrypt",
2582            Expression::EncryptRaw(_) => "encrypt_raw",
2583            Expression::EqualNull(_) => "equal_null",
2584            Expression::ToBinary(_) => "to_binary",
2585            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2586            Expression::Base64DecodeString(_) => "base64_decode_string",
2587            Expression::Base64Encode(_) => "base64_encode",
2588            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2589            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2590            Expression::GapFill(_) => "gap_fill",
2591            Expression::GenerateDateArray(_) => "generate_date_array",
2592            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2593            Expression::GetExtract(_) => "get_extract",
2594            Expression::Getbit(_) => "getbit",
2595            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2596            Expression::HexEncode(_) => "hex_encode",
2597            Expression::Compress(_) => "compress",
2598            Expression::DecompressBinary(_) => "decompress_binary",
2599            Expression::DecompressString(_) => "decompress_string",
2600            Expression::Xor(_) => "xor",
2601            Expression::Nullif(_) => "nullif",
2602            Expression::JSON(_) => "j_s_o_n",
2603            Expression::JSONPath(_) => "j_s_o_n_path",
2604            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2605            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2606            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2607            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2608            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2609            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2610            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2611            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2612            Expression::Format(_) => "format",
2613            Expression::JSONKeys(_) => "j_s_o_n_keys",
2614            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2615            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2616            Expression::JSONObject(_) => "j_s_o_n_object",
2617            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2618            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2619            Expression::JSONArray(_) => "j_s_o_n_array",
2620            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2621            Expression::JSONExists(_) => "j_s_o_n_exists",
2622            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2623            Expression::JSONSchema(_) => "j_s_o_n_schema",
2624            Expression::JSONSet(_) => "j_s_o_n_set",
2625            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2626            Expression::JSONValue(_) => "j_s_o_n_value",
2627            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2628            Expression::JSONRemove(_) => "j_s_o_n_remove",
2629            Expression::JSONTable(_) => "j_s_o_n_table",
2630            Expression::JSONType(_) => "j_s_o_n_type",
2631            Expression::ObjectInsert(_) => "object_insert",
2632            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2633            Expression::OpenJSON(_) => "open_j_s_o_n",
2634            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2635            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2636            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2637            Expression::JSONCast(_) => "j_s_o_n_cast",
2638            Expression::JSONExtract(_) => "j_s_o_n_extract",
2639            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2640            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2641            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2642            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2643            Expression::JSONFormat(_) => "j_s_o_n_format",
2644            Expression::JSONBool(_) => "j_s_o_n_bool",
2645            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2646            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2647            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2648            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2649            Expression::ParseJSON(_) => "parse_j_s_o_n",
2650            Expression::ParseUrl(_) => "parse_url",
2651            Expression::ParseIp(_) => "parse_ip",
2652            Expression::ParseTime(_) => "parse_time",
2653            Expression::ParseDatetime(_) => "parse_datetime",
2654            Expression::Map(_) => "map",
2655            Expression::MapCat(_) => "map_cat",
2656            Expression::MapDelete(_) => "map_delete",
2657            Expression::MapInsert(_) => "map_insert",
2658            Expression::MapPick(_) => "map_pick",
2659            Expression::ScopeResolution(_) => "scope_resolution",
2660            Expression::Slice(_) => "slice",
2661            Expression::VarMap(_) => "var_map",
2662            Expression::MatchAgainst(_) => "match_against",
2663            Expression::MD5Digest(_) => "m_d5_digest",
2664            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2665            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2666            Expression::Monthname(_) => "monthname",
2667            Expression::Ntile(_) => "ntile",
2668            Expression::Normalize(_) => "normalize",
2669            Expression::Normal(_) => "normal",
2670            Expression::Predict(_) => "predict",
2671            Expression::MLTranslate(_) => "m_l_translate",
2672            Expression::FeaturesAtTime(_) => "features_at_time",
2673            Expression::GenerateEmbedding(_) => "generate_embedding",
2674            Expression::MLForecast(_) => "m_l_forecast",
2675            Expression::ModelAttribute(_) => "model_attribute",
2676            Expression::VectorSearch(_) => "vector_search",
2677            Expression::Quantile(_) => "quantile",
2678            Expression::ApproxQuantile(_) => "approx_quantile",
2679            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2680            Expression::Randn(_) => "randn",
2681            Expression::Randstr(_) => "randstr",
2682            Expression::RangeN(_) => "range_n",
2683            Expression::RangeBucket(_) => "range_bucket",
2684            Expression::ReadCSV(_) => "read_c_s_v",
2685            Expression::ReadParquet(_) => "read_parquet",
2686            Expression::Reduce(_) => "reduce",
2687            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2688            Expression::RegexpILike(_) => "regexp_i_like",
2689            Expression::RegexpFullMatch(_) => "regexp_full_match",
2690            Expression::RegexpInstr(_) => "regexp_instr",
2691            Expression::RegexpSplit(_) => "regexp_split",
2692            Expression::RegexpCount(_) => "regexp_count",
2693            Expression::RegrValx(_) => "regr_valx",
2694            Expression::RegrValy(_) => "regr_valy",
2695            Expression::RegrAvgy(_) => "regr_avgy",
2696            Expression::RegrAvgx(_) => "regr_avgx",
2697            Expression::RegrCount(_) => "regr_count",
2698            Expression::RegrIntercept(_) => "regr_intercept",
2699            Expression::RegrR2(_) => "regr_r2",
2700            Expression::RegrSxx(_) => "regr_sxx",
2701            Expression::RegrSxy(_) => "regr_sxy",
2702            Expression::RegrSyy(_) => "regr_syy",
2703            Expression::RegrSlope(_) => "regr_slope",
2704            Expression::SafeAdd(_) => "safe_add",
2705            Expression::SafeDivide(_) => "safe_divide",
2706            Expression::SafeMultiply(_) => "safe_multiply",
2707            Expression::SafeSubtract(_) => "safe_subtract",
2708            Expression::SHA2(_) => "s_h_a2",
2709            Expression::SHA2Digest(_) => "s_h_a2_digest",
2710            Expression::SortArray(_) => "sort_array",
2711            Expression::SplitPart(_) => "split_part",
2712            Expression::SubstringIndex(_) => "substring_index",
2713            Expression::StandardHash(_) => "standard_hash",
2714            Expression::StrPosition(_) => "str_position",
2715            Expression::Search(_) => "search",
2716            Expression::SearchIp(_) => "search_ip",
2717            Expression::StrToDate(_) => "str_to_date",
2718            Expression::DateStrToDate(_) => "date_str_to_date",
2719            Expression::DateToDateStr(_) => "date_to_date_str",
2720            Expression::StrToTime(_) => "str_to_time",
2721            Expression::StrToUnix(_) => "str_to_unix",
2722            Expression::StrToMap(_) => "str_to_map",
2723            Expression::NumberToStr(_) => "number_to_str",
2724            Expression::FromBase(_) => "from_base",
2725            Expression::Stuff(_) => "stuff",
2726            Expression::TimeToStr(_) => "time_to_str",
2727            Expression::TimeStrToTime(_) => "time_str_to_time",
2728            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2729            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2730            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2731            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2732            Expression::Unhex(_) => "unhex",
2733            Expression::Uniform(_) => "uniform",
2734            Expression::UnixToStr(_) => "unix_to_str",
2735            Expression::UnixToTime(_) => "unix_to_time",
2736            Expression::Uuid(_) => "uuid",
2737            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2738            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2739            Expression::Corr(_) => "corr",
2740            Expression::WidthBucket(_) => "width_bucket",
2741            Expression::CovarSamp(_) => "covar_samp",
2742            Expression::CovarPop(_) => "covar_pop",
2743            Expression::Week(_) => "week",
2744            Expression::XMLElement(_) => "x_m_l_element",
2745            Expression::XMLGet(_) => "x_m_l_get",
2746            Expression::XMLTable(_) => "x_m_l_table",
2747            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2748            Expression::Zipf(_) => "zipf",
2749            Expression::Merge(_) => "merge",
2750            Expression::When(_) => "when",
2751            Expression::Whens(_) => "whens",
2752            Expression::NextValueFor(_) => "next_value_for",
2753            Expression::ReturnStmt(_) => "return_stmt",
2754        }
2755    }
2756
2757    /// Returns the primary child expression (".this" in sqlglot).
2758    pub fn get_this(&self) -> Option<&Expression> {
2759        match self {
2760            // Unary ops
2761            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2762            // UnaryFunc variants
2763            Expression::Upper(f)
2764            | Expression::Lower(f)
2765            | Expression::Length(f)
2766            | Expression::LTrim(f)
2767            | Expression::RTrim(f)
2768            | Expression::Reverse(f)
2769            | Expression::Abs(f)
2770            | Expression::Sqrt(f)
2771            | Expression::Cbrt(f)
2772            | Expression::Ln(f)
2773            | Expression::Exp(f)
2774            | Expression::Sign(f)
2775            | Expression::Date(f)
2776            | Expression::Time(f)
2777            | Expression::Initcap(f)
2778            | Expression::Ascii(f)
2779            | Expression::Chr(f)
2780            | Expression::Soundex(f)
2781            | Expression::ByteLength(f)
2782            | Expression::Hex(f)
2783            | Expression::LowerHex(f)
2784            | Expression::Unicode(f)
2785            | Expression::Typeof(f)
2786            | Expression::Explode(f)
2787            | Expression::ExplodeOuter(f)
2788            | Expression::MapFromEntries(f)
2789            | Expression::MapKeys(f)
2790            | Expression::MapValues(f)
2791            | Expression::ArrayLength(f)
2792            | Expression::ArraySize(f)
2793            | Expression::Cardinality(f)
2794            | Expression::ArrayReverse(f)
2795            | Expression::ArrayDistinct(f)
2796            | Expression::ArrayFlatten(f)
2797            | Expression::ArrayCompact(f)
2798            | Expression::ToArray(f)
2799            | Expression::JsonArrayLength(f)
2800            | Expression::JsonKeys(f)
2801            | Expression::JsonType(f)
2802            | Expression::ParseJson(f)
2803            | Expression::ToJson(f)
2804            | Expression::Radians(f)
2805            | Expression::Degrees(f)
2806            | Expression::Sin(f)
2807            | Expression::Cos(f)
2808            | Expression::Tan(f)
2809            | Expression::Asin(f)
2810            | Expression::Acos(f)
2811            | Expression::Atan(f)
2812            | Expression::IsNan(f)
2813            | Expression::IsInf(f)
2814            | Expression::Year(f)
2815            | Expression::Month(f)
2816            | Expression::Day(f)
2817            | Expression::Hour(f)
2818            | Expression::Minute(f)
2819            | Expression::Second(f)
2820            | Expression::DayOfWeek(f)
2821            | Expression::DayOfWeekIso(f)
2822            | Expression::DayOfMonth(f)
2823            | Expression::DayOfYear(f)
2824            | Expression::WeekOfYear(f)
2825            | Expression::Quarter(f)
2826            | Expression::Epoch(f)
2827            | Expression::EpochMs(f)
2828            | Expression::BitwiseCount(f)
2829            | Expression::DateFromUnixDate(f)
2830            | Expression::UnixDate(f)
2831            | Expression::UnixSeconds(f)
2832            | Expression::UnixMillis(f)
2833            | Expression::UnixMicros(f)
2834            | Expression::TimeStrToDate(f)
2835            | Expression::DateToDi(f)
2836            | Expression::DiToDate(f)
2837            | Expression::TsOrDiToDi(f)
2838            | Expression::TsOrDsToDatetime(f)
2839            | Expression::TsOrDsToTimestamp(f)
2840            | Expression::YearOfWeek(f)
2841            | Expression::YearOfWeekIso(f)
2842            | Expression::SHA(f)
2843            | Expression::SHA1Digest(f)
2844            | Expression::TimeToUnix(f)
2845            | Expression::TimeStrToUnix(f)
2846            | Expression::Int64(f)
2847            | Expression::JSONBool(f)
2848            | Expression::MD5NumberLower64(f)
2849            | Expression::MD5NumberUpper64(f)
2850            | Expression::DateStrToDate(f)
2851            | Expression::DateToDateStr(f) => Some(&f.this),
2852            // BinaryFunc - this is the primary child
2853            Expression::Power(f)
2854            | Expression::NullIf(f)
2855            | Expression::IfNull(f)
2856            | Expression::Nvl(f)
2857            | Expression::Contains(f)
2858            | Expression::StartsWith(f)
2859            | Expression::EndsWith(f)
2860            | Expression::Levenshtein(f)
2861            | Expression::ModFunc(f)
2862            | Expression::IntDiv(f)
2863            | Expression::Atan2(f)
2864            | Expression::AddMonths(f)
2865            | Expression::MonthsBetween(f)
2866            | Expression::NextDay(f)
2867            | Expression::UnixToTimeStr(f)
2868            | Expression::ArrayContains(f)
2869            | Expression::ArrayPosition(f)
2870            | Expression::ArrayAppend(f)
2871            | Expression::ArrayPrepend(f)
2872            | Expression::ArrayUnion(f)
2873            | Expression::ArrayExcept(f)
2874            | Expression::ArrayRemove(f)
2875            | Expression::StarMap(f)
2876            | Expression::MapFromArrays(f)
2877            | Expression::MapContainsKey(f)
2878            | Expression::ElementAt(f)
2879            | Expression::JsonMergePatch(f)
2880            | Expression::JSONBContains(f)
2881            | Expression::JSONBExtract(f) => Some(&f.this),
2882            // AggFunc - this is the primary child
2883            Expression::Sum(af)
2884            | Expression::Avg(af)
2885            | Expression::Min(af)
2886            | Expression::Max(af)
2887            | Expression::ArrayAgg(af)
2888            | Expression::CountIf(af)
2889            | Expression::Stddev(af)
2890            | Expression::StddevPop(af)
2891            | Expression::StddevSamp(af)
2892            | Expression::Variance(af)
2893            | Expression::VarPop(af)
2894            | Expression::VarSamp(af)
2895            | Expression::Median(af)
2896            | Expression::Mode(af)
2897            | Expression::First(af)
2898            | Expression::Last(af)
2899            | Expression::AnyValue(af)
2900            | Expression::ApproxDistinct(af)
2901            | Expression::ApproxCountDistinct(af)
2902            | Expression::LogicalAnd(af)
2903            | Expression::LogicalOr(af)
2904            | Expression::Skewness(af)
2905            | Expression::ArrayConcatAgg(af)
2906            | Expression::ArrayUniqueAgg(af)
2907            | Expression::BoolXorAgg(af)
2908            | Expression::BitwiseAndAgg(af)
2909            | Expression::BitwiseOrAgg(af)
2910            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2911            // Binary operations - left is "this" in sqlglot
2912            Expression::And(op)
2913            | Expression::Or(op)
2914            | Expression::Add(op)
2915            | Expression::Sub(op)
2916            | Expression::Mul(op)
2917            | Expression::Div(op)
2918            | Expression::Mod(op)
2919            | Expression::Eq(op)
2920            | Expression::Neq(op)
2921            | Expression::Lt(op)
2922            | Expression::Lte(op)
2923            | Expression::Gt(op)
2924            | Expression::Gte(op)
2925            | Expression::BitwiseAnd(op)
2926            | Expression::BitwiseOr(op)
2927            | Expression::BitwiseXor(op)
2928            | Expression::Concat(op)
2929            | Expression::Adjacent(op)
2930            | Expression::TsMatch(op)
2931            | Expression::PropertyEQ(op)
2932            | Expression::ArrayContainsAll(op)
2933            | Expression::ArrayContainedBy(op)
2934            | Expression::ArrayOverlaps(op)
2935            | Expression::JSONBContainsAllTopKeys(op)
2936            | Expression::JSONBContainsAnyTopKeys(op)
2937            | Expression::JSONBDeleteAtPath(op)
2938            | Expression::ExtendsLeft(op)
2939            | Expression::ExtendsRight(op)
2940            | Expression::Is(op)
2941            | Expression::MemberOf(op)
2942            | Expression::Match(op)
2943            | Expression::NullSafeEq(op)
2944            | Expression::NullSafeNeq(op)
2945            | Expression::Glob(op)
2946            | Expression::BitwiseLeftShift(op)
2947            | Expression::BitwiseRightShift(op) => Some(&op.left),
2948            // Like operations - left is "this"
2949            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2950            // Structural types with .this
2951            Expression::Alias(a) => Some(&a.this),
2952            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2953            Expression::Paren(p) => Some(&p.this),
2954            Expression::Annotated(a) => Some(&a.this),
2955            Expression::Subquery(s) => Some(&s.this),
2956            Expression::Where(w) => Some(&w.this),
2957            Expression::Having(h) => Some(&h.this),
2958            Expression::Qualify(q) => Some(&q.this),
2959            Expression::IsNull(i) => Some(&i.this),
2960            Expression::Exists(e) => Some(&e.this),
2961            Expression::Ordered(o) => Some(&o.this),
2962            Expression::WindowFunction(wf) => Some(&wf.this),
2963            Expression::Cte(cte) => Some(&cte.this),
2964            Expression::Between(b) => Some(&b.this),
2965            Expression::In(i) => Some(&i.this),
2966            Expression::ReturnStmt(e) => Some(e),
2967            _ => None,
2968        }
2969    }
2970
2971    /// Returns the secondary child expression (".expression" in sqlglot).
2972    pub fn get_expression(&self) -> Option<&Expression> {
2973        match self {
2974            // Binary operations - right is "expression"
2975            Expression::And(op)
2976            | Expression::Or(op)
2977            | Expression::Add(op)
2978            | Expression::Sub(op)
2979            | Expression::Mul(op)
2980            | Expression::Div(op)
2981            | Expression::Mod(op)
2982            | Expression::Eq(op)
2983            | Expression::Neq(op)
2984            | Expression::Lt(op)
2985            | Expression::Lte(op)
2986            | Expression::Gt(op)
2987            | Expression::Gte(op)
2988            | Expression::BitwiseAnd(op)
2989            | Expression::BitwiseOr(op)
2990            | Expression::BitwiseXor(op)
2991            | Expression::Concat(op)
2992            | Expression::Adjacent(op)
2993            | Expression::TsMatch(op)
2994            | Expression::PropertyEQ(op)
2995            | Expression::ArrayContainsAll(op)
2996            | Expression::ArrayContainedBy(op)
2997            | Expression::ArrayOverlaps(op)
2998            | Expression::JSONBContainsAllTopKeys(op)
2999            | Expression::JSONBContainsAnyTopKeys(op)
3000            | Expression::JSONBDeleteAtPath(op)
3001            | Expression::ExtendsLeft(op)
3002            | Expression::ExtendsRight(op)
3003            | Expression::Is(op)
3004            | Expression::MemberOf(op)
3005            | Expression::Match(op)
3006            | Expression::NullSafeEq(op)
3007            | Expression::NullSafeNeq(op)
3008            | Expression::Glob(op)
3009            | Expression::BitwiseLeftShift(op)
3010            | Expression::BitwiseRightShift(op) => Some(&op.right),
3011            // Like operations - right is "expression"
3012            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3013            // BinaryFunc - expression is the secondary
3014            Expression::Power(f)
3015            | Expression::NullIf(f)
3016            | Expression::IfNull(f)
3017            | Expression::Nvl(f)
3018            | Expression::Contains(f)
3019            | Expression::StartsWith(f)
3020            | Expression::EndsWith(f)
3021            | Expression::Levenshtein(f)
3022            | Expression::ModFunc(f)
3023            | Expression::IntDiv(f)
3024            | Expression::Atan2(f)
3025            | Expression::AddMonths(f)
3026            | Expression::MonthsBetween(f)
3027            | Expression::NextDay(f)
3028            | Expression::UnixToTimeStr(f)
3029            | Expression::ArrayContains(f)
3030            | Expression::ArrayPosition(f)
3031            | Expression::ArrayAppend(f)
3032            | Expression::ArrayPrepend(f)
3033            | Expression::ArrayUnion(f)
3034            | Expression::ArrayExcept(f)
3035            | Expression::ArrayRemove(f)
3036            | Expression::StarMap(f)
3037            | Expression::MapFromArrays(f)
3038            | Expression::MapContainsKey(f)
3039            | Expression::ElementAt(f)
3040            | Expression::JsonMergePatch(f)
3041            | Expression::JSONBContains(f)
3042            | Expression::JSONBExtract(f) => Some(&f.expression),
3043            _ => None,
3044        }
3045    }
3046
3047    /// Returns the list of child expressions (".expressions" in sqlglot).
3048    pub fn get_expressions(&self) -> &[Expression] {
3049        match self {
3050            Expression::Select(s) => &s.expressions,
3051            Expression::Function(f) => &f.args,
3052            Expression::AggregateFunction(f) => &f.args,
3053            Expression::From(f) => &f.expressions,
3054            Expression::GroupBy(g) => &g.expressions,
3055            Expression::In(i) => &i.expressions,
3056            Expression::Array(a) => &a.expressions,
3057            Expression::Tuple(t) => &t.expressions,
3058            Expression::Coalesce(f)
3059            | Expression::Greatest(f)
3060            | Expression::Least(f)
3061            | Expression::ArrayConcat(f)
3062            | Expression::ArrayIntersect(f)
3063            | Expression::ArrayZip(f)
3064            | Expression::MapConcat(f)
3065            | Expression::JsonArray(f) => &f.expressions,
3066            _ => &[],
3067        }
3068    }
3069
3070    /// Returns the name of this expression as a string slice.
3071    pub fn get_name(&self) -> &str {
3072        match self {
3073            Expression::Identifier(id) => &id.name,
3074            Expression::Column(col) => &col.name.name,
3075            Expression::Table(t) => &t.name.name,
3076            Expression::Literal(lit) => lit.value_str(),
3077            Expression::Star(_) => "*",
3078            Expression::Function(f) => &f.name,
3079            Expression::AggregateFunction(f) => &f.name,
3080            Expression::Alias(a) => a.this.get_name(),
3081            Expression::Boolean(b) => {
3082                if b.value {
3083                    "TRUE"
3084                } else {
3085                    "FALSE"
3086                }
3087            }
3088            Expression::Null(_) => "NULL",
3089            _ => "",
3090        }
3091    }
3092
3093    /// Returns the alias name if this expression has one.
3094    pub fn get_alias(&self) -> &str {
3095        match self {
3096            Expression::Alias(a) => &a.alias.name,
3097            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3098            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3099            _ => "",
3100        }
3101    }
3102
3103    /// Returns the output name of this expression (what it shows up as in a SELECT).
3104    pub fn get_output_name(&self) -> &str {
3105        match self {
3106            Expression::Alias(a) => &a.alias.name,
3107            Expression::Column(c) => &c.name.name,
3108            Expression::Identifier(id) => &id.name,
3109            Expression::Literal(lit) => lit.value_str(),
3110            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3111            Expression::Star(_) => "*",
3112            _ => "",
3113        }
3114    }
3115
3116    /// Returns comments attached to this expression.
3117    pub fn get_comments(&self) -> Vec<&str> {
3118        match self {
3119            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3120            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3121            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3122            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3123            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3124            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3125            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3126                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3127            }
3128            Expression::And(op)
3129            | Expression::Or(op)
3130            | Expression::Add(op)
3131            | Expression::Sub(op)
3132            | Expression::Mul(op)
3133            | Expression::Div(op)
3134            | Expression::Mod(op)
3135            | Expression::Eq(op)
3136            | Expression::Neq(op)
3137            | Expression::Lt(op)
3138            | Expression::Lte(op)
3139            | Expression::Gt(op)
3140            | Expression::Gte(op)
3141            | Expression::Concat(op)
3142            | Expression::BitwiseAnd(op)
3143            | Expression::BitwiseOr(op)
3144            | Expression::BitwiseXor(op) => {
3145                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3146            }
3147            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3148            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3149            _ => Vec::new(),
3150        }
3151    }
3152}
3153
3154impl fmt::Display for Expression {
3155    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3156        // Basic display - full SQL generation is in generator module
3157        match self {
3158            Expression::Literal(lit) => write!(f, "{}", lit),
3159            Expression::Identifier(id) => write!(f, "{}", id),
3160            Expression::Column(col) => write!(f, "{}", col),
3161            Expression::Star(_) => write!(f, "*"),
3162            Expression::Null(_) => write!(f, "NULL"),
3163            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3164            Expression::Select(_) => write!(f, "SELECT ..."),
3165            _ => write!(f, "{:?}", self),
3166        }
3167    }
3168}
3169
3170/// Represent a SQL literal value.
3171///
3172/// Numeric values are stored as their original text representation (not parsed
3173/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3174/// preserved across round-trips.
3175///
3176/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3177/// strings, raw strings, etc.) each have a dedicated variant so that the
3178/// generator can emit them with the correct syntax.
3179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3180#[cfg_attr(feature = "bindings", derive(TS))]
3181#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3182pub enum Literal {
3183    /// Single-quoted string literal: `'hello'`
3184    String(String),
3185    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3186    Number(String),
3187    /// Hex string literal: `X'FF'`
3188    HexString(String),
3189    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3190    HexNumber(String),
3191    BitString(String),
3192    /// Byte string: b"..." (BigQuery style)
3193    ByteString(String),
3194    /// National string: N'abc'
3195    NationalString(String),
3196    /// DATE literal: DATE '2024-01-15'
3197    Date(String),
3198    /// TIME literal: TIME '10:30:00'
3199    Time(String),
3200    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3201    Timestamp(String),
3202    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3203    Datetime(String),
3204    /// Triple-quoted string: """...""" or '''...'''
3205    /// Contains (content, quote_char) where quote_char is '"' or '\''
3206    TripleQuotedString(String, char),
3207    /// Escape string: E'...' (PostgreSQL)
3208    EscapeString(String),
3209    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3210    DollarString(String),
3211    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3212    /// In raw strings, backslashes are literal and not escape characters.
3213    /// When converting to a regular string, backslashes must be doubled.
3214    RawString(String),
3215}
3216
3217impl Literal {
3218    /// Returns the inner value as a string slice, regardless of literal type.
3219    pub fn value_str(&self) -> &str {
3220        match self {
3221            Literal::String(s)
3222            | Literal::Number(s)
3223            | Literal::HexString(s)
3224            | Literal::HexNumber(s)
3225            | Literal::BitString(s)
3226            | Literal::ByteString(s)
3227            | Literal::NationalString(s)
3228            | Literal::Date(s)
3229            | Literal::Time(s)
3230            | Literal::Timestamp(s)
3231            | Literal::Datetime(s)
3232            | Literal::EscapeString(s)
3233            | Literal::DollarString(s)
3234            | Literal::RawString(s) => s.as_str(),
3235            Literal::TripleQuotedString(s, _) => s.as_str(),
3236        }
3237    }
3238
3239    /// Returns `true` if this is a string-type literal.
3240    pub fn is_string(&self) -> bool {
3241        matches!(
3242            self,
3243            Literal::String(_)
3244                | Literal::NationalString(_)
3245                | Literal::EscapeString(_)
3246                | Literal::DollarString(_)
3247                | Literal::RawString(_)
3248                | Literal::TripleQuotedString(_, _)
3249        )
3250    }
3251
3252    /// Returns `true` if this is a numeric literal.
3253    pub fn is_number(&self) -> bool {
3254        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3255    }
3256}
3257
3258impl fmt::Display for Literal {
3259    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3260        match self {
3261            Literal::String(s) => write!(f, "'{}'", s),
3262            Literal::Number(n) => write!(f, "{}", n),
3263            Literal::HexString(h) => write!(f, "X'{}'", h),
3264            Literal::HexNumber(h) => write!(f, "0x{}", h),
3265            Literal::BitString(b) => write!(f, "B'{}'", b),
3266            Literal::ByteString(b) => write!(f, "b'{}'", b),
3267            Literal::NationalString(s) => write!(f, "N'{}'", s),
3268            Literal::Date(d) => write!(f, "DATE '{}'", d),
3269            Literal::Time(t) => write!(f, "TIME '{}'", t),
3270            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3271            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3272            Literal::TripleQuotedString(s, q) => {
3273                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3274            }
3275            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3276            Literal::DollarString(s) => write!(f, "$${}$$", s),
3277            Literal::RawString(s) => write!(f, "r'{}'", s),
3278        }
3279    }
3280}
3281
3282/// Boolean literal
3283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3284#[cfg_attr(feature = "bindings", derive(TS))]
3285pub struct BooleanLiteral {
3286    pub value: bool,
3287}
3288
3289/// NULL literal
3290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3291#[cfg_attr(feature = "bindings", derive(TS))]
3292pub struct Null;
3293
3294/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3295///
3296/// The `quoted` flag indicates whether the identifier was originally delimited
3297/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3298/// dialect). The generator uses this flag to decide whether to emit quoting
3299/// characters.
3300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3301#[cfg_attr(feature = "bindings", derive(TS))]
3302pub struct Identifier {
3303    /// The raw text of the identifier, without any quoting characters.
3304    pub name: String,
3305    /// Whether the identifier was quoted in the source SQL.
3306    pub quoted: bool,
3307    #[serde(default)]
3308    pub trailing_comments: Vec<String>,
3309    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3310    #[serde(default, skip_serializing_if = "Option::is_none")]
3311    pub span: Option<Span>,
3312}
3313
3314impl Identifier {
3315    pub fn new(name: impl Into<String>) -> Self {
3316        Self {
3317            name: name.into(),
3318            quoted: false,
3319            trailing_comments: Vec::new(),
3320            span: None,
3321        }
3322    }
3323
3324    pub fn quoted(name: impl Into<String>) -> Self {
3325        Self {
3326            name: name.into(),
3327            quoted: true,
3328            trailing_comments: Vec::new(),
3329            span: None,
3330        }
3331    }
3332
3333    pub fn empty() -> Self {
3334        Self {
3335            name: String::new(),
3336            quoted: false,
3337            trailing_comments: Vec::new(),
3338            span: None,
3339        }
3340    }
3341
3342    pub fn is_empty(&self) -> bool {
3343        self.name.is_empty()
3344    }
3345
3346    /// Set the source span on this identifier
3347    pub fn with_span(mut self, span: Span) -> Self {
3348        self.span = Some(span);
3349        self
3350    }
3351}
3352
3353impl fmt::Display for Identifier {
3354    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3355        if self.quoted {
3356            write!(f, "\"{}\"", self.name)
3357        } else {
3358            write!(f, "{}", self.name)
3359        }
3360    }
3361}
3362
3363/// Represent a column reference, optionally qualified by a table name.
3364///
3365/// Renders as `name` when unqualified, or `table.name` when qualified.
3366/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3367/// convenient construction.
3368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3369#[cfg_attr(feature = "bindings", derive(TS))]
3370pub struct Column {
3371    /// The column name.
3372    pub name: Identifier,
3373    /// Optional table qualifier (e.g. `t` in `t.col`).
3374    pub table: Option<Identifier>,
3375    /// Oracle-style join marker (+) for outer joins
3376    #[serde(default)]
3377    pub join_mark: bool,
3378    /// Trailing comments that appeared after this column reference
3379    #[serde(default)]
3380    pub trailing_comments: Vec<String>,
3381    /// Source position span
3382    #[serde(default, skip_serializing_if = "Option::is_none")]
3383    pub span: Option<Span>,
3384    /// Inferred data type from type annotation
3385    #[serde(default, skip_serializing_if = "Option::is_none")]
3386    pub inferred_type: Option<DataType>,
3387}
3388
3389impl fmt::Display for Column {
3390    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3391        if let Some(table) = &self.table {
3392            write!(f, "{}.{}", table, self.name)
3393        } else {
3394            write!(f, "{}", self.name)
3395        }
3396    }
3397}
3398
3399/// Represent a table reference with optional schema and catalog qualifiers.
3400///
3401/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3402/// which qualifiers are present. Supports aliases, column alias lists,
3403/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3404/// several other dialect-specific extensions.
3405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3406#[cfg_attr(feature = "bindings", derive(TS))]
3407pub struct TableRef {
3408    /// The unqualified table name.
3409    pub name: Identifier,
3410    /// Optional schema qualifier (e.g. `public` in `public.users`).
3411    pub schema: Option<Identifier>,
3412    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3413    pub catalog: Option<Identifier>,
3414    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3415    pub alias: Option<Identifier>,
3416    /// Whether AS keyword was explicitly used for the alias
3417    #[serde(default)]
3418    pub alias_explicit_as: bool,
3419    /// Column aliases for table alias: AS t(c1, c2)
3420    #[serde(default)]
3421    pub column_aliases: Vec<Identifier>,
3422    /// Leading comments that appeared before this table reference in a FROM clause
3423    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3424    pub leading_comments: Vec<String>,
3425    /// Trailing comments that appeared after this table reference
3426    #[serde(default)]
3427    pub trailing_comments: Vec<String>,
3428    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3429    #[serde(default)]
3430    pub when: Option<Box<HistoricalData>>,
3431    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3432    #[serde(default)]
3433    pub only: bool,
3434    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3435    #[serde(default)]
3436    pub final_: bool,
3437    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3438    #[serde(default, skip_serializing_if = "Option::is_none")]
3439    pub table_sample: Option<Box<Sample>>,
3440    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3441    #[serde(default)]
3442    pub hints: Vec<Expression>,
3443    /// TSQL: FOR SYSTEM_TIME temporal clause
3444    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3445    #[serde(default, skip_serializing_if = "Option::is_none")]
3446    pub system_time: Option<String>,
3447    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3448    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3449    pub partitions: Vec<Identifier>,
3450    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3451    /// When set, this is used instead of the name field
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub identifier_func: Option<Box<Expression>>,
3454    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3455    #[serde(default, skip_serializing_if = "Option::is_none")]
3456    pub changes: Option<Box<Changes>>,
3457    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3458    #[serde(default, skip_serializing_if = "Option::is_none")]
3459    pub version: Option<Box<Version>>,
3460    /// Source position span
3461    #[serde(default, skip_serializing_if = "Option::is_none")]
3462    pub span: Option<Span>,
3463}
3464
3465impl TableRef {
3466    pub fn new(name: impl Into<String>) -> Self {
3467        Self {
3468            name: Identifier::new(name),
3469            schema: None,
3470            catalog: None,
3471            alias: None,
3472            alias_explicit_as: false,
3473            column_aliases: Vec::new(),
3474            leading_comments: Vec::new(),
3475            trailing_comments: Vec::new(),
3476            when: None,
3477            only: false,
3478            final_: false,
3479            table_sample: None,
3480            hints: Vec::new(),
3481            system_time: None,
3482            partitions: Vec::new(),
3483            identifier_func: None,
3484            changes: None,
3485            version: None,
3486            span: None,
3487        }
3488    }
3489
3490    /// Create with a schema qualifier.
3491    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3492        let mut t = Self::new(name);
3493        t.schema = Some(Identifier::new(schema));
3494        t
3495    }
3496
3497    /// Create with catalog and schema qualifiers.
3498    pub fn new_with_catalog(
3499        name: impl Into<String>,
3500        schema: impl Into<String>,
3501        catalog: impl Into<String>,
3502    ) -> Self {
3503        let mut t = Self::new(name);
3504        t.schema = Some(Identifier::new(schema));
3505        t.catalog = Some(Identifier::new(catalog));
3506        t
3507    }
3508
3509    /// Create from an Identifier, preserving the quoted flag
3510    pub fn from_identifier(name: Identifier) -> Self {
3511        Self {
3512            name,
3513            schema: None,
3514            catalog: None,
3515            alias: None,
3516            alias_explicit_as: false,
3517            column_aliases: Vec::new(),
3518            leading_comments: Vec::new(),
3519            trailing_comments: Vec::new(),
3520            when: None,
3521            only: false,
3522            final_: false,
3523            table_sample: None,
3524            hints: Vec::new(),
3525            system_time: None,
3526            partitions: Vec::new(),
3527            identifier_func: None,
3528            changes: None,
3529            version: None,
3530            span: None,
3531        }
3532    }
3533
3534    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3535        self.alias = Some(Identifier::new(alias));
3536        self
3537    }
3538
3539    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3540        self.schema = Some(Identifier::new(schema));
3541        self
3542    }
3543}
3544
3545/// Represent a wildcard star expression (`*`, `table.*`).
3546///
3547/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3548/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3550#[cfg_attr(feature = "bindings", derive(TS))]
3551pub struct Star {
3552    /// Optional table qualifier (e.g. `t` in `t.*`).
3553    pub table: Option<Identifier>,
3554    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3555    pub except: Option<Vec<Identifier>>,
3556    /// REPLACE expressions (BigQuery, Snowflake)
3557    pub replace: Option<Vec<Alias>>,
3558    /// RENAME columns (Snowflake)
3559    pub rename: Option<Vec<(Identifier, Identifier)>>,
3560    /// Trailing comments that appeared after the star
3561    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3562    pub trailing_comments: Vec<String>,
3563    /// Source position span
3564    #[serde(default, skip_serializing_if = "Option::is_none")]
3565    pub span: Option<Span>,
3566}
3567
3568/// Represent a complete SELECT statement.
3569///
3570/// This is the most feature-rich AST node, covering the full surface area of
3571/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3572/// `Vec` are omitted from the generated SQL when absent.
3573///
3574/// # Key Fields
3575///
3576/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3577/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3578/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3579/// - `where_clause` -- the WHERE predicate.
3580/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3581/// - `having` -- HAVING predicate.
3582/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3583/// - `limit` / `offset` / `fetch` -- result set limiting.
3584/// - `with` -- Common Table Expressions (CTEs).
3585/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3586/// - `windows` -- named window definitions (WINDOW w AS ...).
3587///
3588/// Dialect-specific extensions are supported via fields like `prewhere`
3589/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3590/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3592#[cfg_attr(feature = "bindings", derive(TS))]
3593pub struct Select {
3594    /// The select-list: columns, expressions, aliases, and wildcards.
3595    pub expressions: Vec<Expression>,
3596    /// The FROM clause, containing one or more table sources.
3597    pub from: Option<From>,
3598    /// JOIN clauses applied after the FROM source.
3599    pub joins: Vec<Join>,
3600    pub lateral_views: Vec<LateralView>,
3601    /// ClickHouse PREWHERE clause
3602    #[serde(default, skip_serializing_if = "Option::is_none")]
3603    pub prewhere: Option<Expression>,
3604    pub where_clause: Option<Where>,
3605    pub group_by: Option<GroupBy>,
3606    pub having: Option<Having>,
3607    pub qualify: Option<Qualify>,
3608    pub order_by: Option<OrderBy>,
3609    pub distribute_by: Option<DistributeBy>,
3610    pub cluster_by: Option<ClusterBy>,
3611    pub sort_by: Option<SortBy>,
3612    pub limit: Option<Limit>,
3613    pub offset: Option<Offset>,
3614    /// ClickHouse LIMIT BY clause expressions
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub limit_by: Option<Vec<Expression>>,
3617    pub fetch: Option<Fetch>,
3618    pub distinct: bool,
3619    pub distinct_on: Option<Vec<Expression>>,
3620    pub top: Option<Top>,
3621    pub with: Option<With>,
3622    pub sample: Option<Sample>,
3623    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3624    #[serde(default, skip_serializing_if = "Option::is_none")]
3625    pub settings: Option<Vec<Expression>>,
3626    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3627    #[serde(default, skip_serializing_if = "Option::is_none")]
3628    pub format: Option<Expression>,
3629    pub windows: Option<Vec<NamedWindow>>,
3630    pub hint: Option<Hint>,
3631    /// Oracle CONNECT BY clause for hierarchical queries
3632    pub connect: Option<Connect>,
3633    /// SELECT ... INTO table_name for creating tables
3634    pub into: Option<SelectInto>,
3635    /// FOR UPDATE/SHARE locking clauses
3636    #[serde(default)]
3637    pub locks: Vec<Lock>,
3638    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3639    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3640    pub for_xml: Vec<Expression>,
3641    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3642    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3643    pub for_json: Vec<Expression>,
3644    /// Leading comments before the statement
3645    #[serde(default)]
3646    pub leading_comments: Vec<String>,
3647    /// Comments that appear after SELECT keyword (before expressions)
3648    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3649    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3650    pub post_select_comments: Vec<String>,
3651    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub kind: Option<String>,
3654    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3655    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3656    pub operation_modifiers: Vec<String>,
3657    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3658    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3659    pub qualify_after_window: bool,
3660    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3661    #[serde(default, skip_serializing_if = "Option::is_none")]
3662    pub option: Option<String>,
3663    /// Redshift-style EXCLUDE clause at the end of the projection list
3664    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3665    #[serde(default, skip_serializing_if = "Option::is_none")]
3666    pub exclude: Option<Vec<Expression>>,
3667}
3668
3669impl Select {
3670    pub fn new() -> Self {
3671        Self {
3672            expressions: Vec::new(),
3673            from: None,
3674            joins: Vec::new(),
3675            lateral_views: Vec::new(),
3676            prewhere: None,
3677            where_clause: None,
3678            group_by: None,
3679            having: None,
3680            qualify: None,
3681            order_by: None,
3682            distribute_by: None,
3683            cluster_by: None,
3684            sort_by: None,
3685            limit: None,
3686            offset: None,
3687            limit_by: None,
3688            fetch: None,
3689            distinct: false,
3690            distinct_on: None,
3691            top: None,
3692            with: None,
3693            sample: None,
3694            settings: None,
3695            format: None,
3696            windows: None,
3697            hint: None,
3698            connect: None,
3699            into: None,
3700            locks: Vec::new(),
3701            for_xml: Vec::new(),
3702            for_json: Vec::new(),
3703            leading_comments: Vec::new(),
3704            post_select_comments: Vec::new(),
3705            kind: None,
3706            operation_modifiers: Vec::new(),
3707            qualify_after_window: false,
3708            option: None,
3709            exclude: None,
3710        }
3711    }
3712
3713    /// Add a column to select
3714    pub fn column(mut self, expr: Expression) -> Self {
3715        self.expressions.push(expr);
3716        self
3717    }
3718
3719    /// Set the FROM clause
3720    pub fn from(mut self, table: Expression) -> Self {
3721        self.from = Some(From {
3722            expressions: vec![table],
3723        });
3724        self
3725    }
3726
3727    /// Add a WHERE clause
3728    pub fn where_(mut self, condition: Expression) -> Self {
3729        self.where_clause = Some(Where { this: condition });
3730        self
3731    }
3732
3733    /// Set DISTINCT
3734    pub fn distinct(mut self) -> Self {
3735        self.distinct = true;
3736        self
3737    }
3738
3739    /// Add a JOIN
3740    pub fn join(mut self, join: Join) -> Self {
3741        self.joins.push(join);
3742        self
3743    }
3744
3745    /// Set ORDER BY
3746    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3747        self.order_by = Some(OrderBy {
3748            expressions,
3749            siblings: false,
3750            comments: Vec::new(),
3751        });
3752        self
3753    }
3754
3755    /// Set LIMIT
3756    pub fn limit(mut self, n: Expression) -> Self {
3757        self.limit = Some(Limit {
3758            this: n,
3759            percent: false,
3760            comments: Vec::new(),
3761        });
3762        self
3763    }
3764
3765    /// Set OFFSET
3766    pub fn offset(mut self, n: Expression) -> Self {
3767        self.offset = Some(Offset {
3768            this: n,
3769            rows: None,
3770        });
3771        self
3772    }
3773}
3774
3775impl Default for Select {
3776    fn default() -> Self {
3777        Self::new()
3778    }
3779}
3780
3781/// Represent a UNION set operation between two query expressions.
3782///
3783/// When `all` is true, duplicate rows are preserved (UNION ALL).
3784/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3785/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3787#[cfg_attr(feature = "bindings", derive(TS))]
3788pub struct Union {
3789    /// The left-hand query operand.
3790    pub left: Expression,
3791    /// The right-hand query operand.
3792    pub right: Expression,
3793    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3794    pub all: bool,
3795    /// Whether DISTINCT was explicitly specified
3796    #[serde(default)]
3797    pub distinct: bool,
3798    /// Optional WITH clause
3799    pub with: Option<With>,
3800    /// ORDER BY applied to entire UNION result
3801    pub order_by: Option<OrderBy>,
3802    /// LIMIT applied to entire UNION result
3803    pub limit: Option<Box<Expression>>,
3804    /// OFFSET applied to entire UNION result
3805    pub offset: Option<Box<Expression>>,
3806    /// DISTRIBUTE BY clause (Hive/Spark)
3807    #[serde(default, skip_serializing_if = "Option::is_none")]
3808    pub distribute_by: Option<DistributeBy>,
3809    /// SORT BY clause (Hive/Spark)
3810    #[serde(default, skip_serializing_if = "Option::is_none")]
3811    pub sort_by: Option<SortBy>,
3812    /// CLUSTER BY clause (Hive/Spark)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub cluster_by: Option<ClusterBy>,
3815    /// DuckDB BY NAME modifier
3816    #[serde(default)]
3817    pub by_name: bool,
3818    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3819    #[serde(default, skip_serializing_if = "Option::is_none")]
3820    pub side: Option<String>,
3821    /// BigQuery: Set operation kind (INNER)
3822    #[serde(default, skip_serializing_if = "Option::is_none")]
3823    pub kind: Option<String>,
3824    /// BigQuery: CORRESPONDING modifier
3825    #[serde(default)]
3826    pub corresponding: bool,
3827    /// BigQuery: STRICT modifier (before CORRESPONDING)
3828    #[serde(default)]
3829    pub strict: bool,
3830    /// BigQuery: BY (columns) after CORRESPONDING
3831    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3832    pub on_columns: Vec<Expression>,
3833}
3834
3835/// Iteratively flatten the left-recursive chain to prevent stack overflow
3836/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3837impl Drop for Union {
3838    fn drop(&mut self) {
3839        loop {
3840            if let Expression::Union(ref mut inner) = self.left {
3841                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3842                let old_left = std::mem::replace(&mut self.left, next_left);
3843                drop(old_left);
3844            } else {
3845                break;
3846            }
3847        }
3848    }
3849}
3850
3851/// Represent an INTERSECT set operation between two query expressions.
3852///
3853/// Returns only rows that appear in both operands. When `all` is true,
3854/// duplicates are preserved according to their multiplicity.
3855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3856#[cfg_attr(feature = "bindings", derive(TS))]
3857pub struct Intersect {
3858    /// The left-hand query operand.
3859    pub left: Expression,
3860    /// The right-hand query operand.
3861    pub right: Expression,
3862    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3863    pub all: bool,
3864    /// Whether DISTINCT was explicitly specified
3865    #[serde(default)]
3866    pub distinct: bool,
3867    /// Optional WITH clause
3868    pub with: Option<With>,
3869    /// ORDER BY applied to entire INTERSECT result
3870    pub order_by: Option<OrderBy>,
3871    /// LIMIT applied to entire INTERSECT result
3872    pub limit: Option<Box<Expression>>,
3873    /// OFFSET applied to entire INTERSECT result
3874    pub offset: Option<Box<Expression>>,
3875    /// DISTRIBUTE BY clause (Hive/Spark)
3876    #[serde(default, skip_serializing_if = "Option::is_none")]
3877    pub distribute_by: Option<DistributeBy>,
3878    /// SORT BY clause (Hive/Spark)
3879    #[serde(default, skip_serializing_if = "Option::is_none")]
3880    pub sort_by: Option<SortBy>,
3881    /// CLUSTER BY clause (Hive/Spark)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub cluster_by: Option<ClusterBy>,
3884    /// DuckDB BY NAME modifier
3885    #[serde(default)]
3886    pub by_name: bool,
3887    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3888    #[serde(default, skip_serializing_if = "Option::is_none")]
3889    pub side: Option<String>,
3890    /// BigQuery: Set operation kind (INNER)
3891    #[serde(default, skip_serializing_if = "Option::is_none")]
3892    pub kind: Option<String>,
3893    /// BigQuery: CORRESPONDING modifier
3894    #[serde(default)]
3895    pub corresponding: bool,
3896    /// BigQuery: STRICT modifier (before CORRESPONDING)
3897    #[serde(default)]
3898    pub strict: bool,
3899    /// BigQuery: BY (columns) after CORRESPONDING
3900    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3901    pub on_columns: Vec<Expression>,
3902}
3903
3904impl Drop for Intersect {
3905    fn drop(&mut self) {
3906        loop {
3907            if let Expression::Intersect(ref mut inner) = self.left {
3908                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3909                let old_left = std::mem::replace(&mut self.left, next_left);
3910                drop(old_left);
3911            } else {
3912                break;
3913            }
3914        }
3915    }
3916}
3917
3918/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3919///
3920/// Returns rows from the left operand that do not appear in the right operand.
3921/// When `all` is true, duplicates are subtracted according to their multiplicity.
3922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3923#[cfg_attr(feature = "bindings", derive(TS))]
3924pub struct Except {
3925    /// The left-hand query operand.
3926    pub left: Expression,
3927    /// The right-hand query operand (rows to subtract).
3928    pub right: Expression,
3929    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3930    pub all: bool,
3931    /// Whether DISTINCT was explicitly specified
3932    #[serde(default)]
3933    pub distinct: bool,
3934    /// Optional WITH clause
3935    pub with: Option<With>,
3936    /// ORDER BY applied to entire EXCEPT result
3937    pub order_by: Option<OrderBy>,
3938    /// LIMIT applied to entire EXCEPT result
3939    pub limit: Option<Box<Expression>>,
3940    /// OFFSET applied to entire EXCEPT result
3941    pub offset: Option<Box<Expression>>,
3942    /// DISTRIBUTE BY clause (Hive/Spark)
3943    #[serde(default, skip_serializing_if = "Option::is_none")]
3944    pub distribute_by: Option<DistributeBy>,
3945    /// SORT BY clause (Hive/Spark)
3946    #[serde(default, skip_serializing_if = "Option::is_none")]
3947    pub sort_by: Option<SortBy>,
3948    /// CLUSTER BY clause (Hive/Spark)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub cluster_by: Option<ClusterBy>,
3951    /// DuckDB BY NAME modifier
3952    #[serde(default)]
3953    pub by_name: bool,
3954    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3955    #[serde(default, skip_serializing_if = "Option::is_none")]
3956    pub side: Option<String>,
3957    /// BigQuery: Set operation kind (INNER)
3958    #[serde(default, skip_serializing_if = "Option::is_none")]
3959    pub kind: Option<String>,
3960    /// BigQuery: CORRESPONDING modifier
3961    #[serde(default)]
3962    pub corresponding: bool,
3963    /// BigQuery: STRICT modifier (before CORRESPONDING)
3964    #[serde(default)]
3965    pub strict: bool,
3966    /// BigQuery: BY (columns) after CORRESPONDING
3967    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3968    pub on_columns: Vec<Expression>,
3969}
3970
3971impl Drop for Except {
3972    fn drop(&mut self) {
3973        loop {
3974            if let Expression::Except(ref mut inner) = self.left {
3975                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3976                let old_left = std::mem::replace(&mut self.left, next_left);
3977                drop(old_left);
3978            } else {
3979                break;
3980            }
3981        }
3982    }
3983}
3984
3985/// INTO clause for SELECT INTO statements
3986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3987#[cfg_attr(feature = "bindings", derive(TS))]
3988pub struct SelectInto {
3989    /// Target table or variable (used when single target)
3990    pub this: Expression,
3991    /// Whether TEMPORARY keyword was used
3992    #[serde(default)]
3993    pub temporary: bool,
3994    /// Whether UNLOGGED keyword was used (PostgreSQL)
3995    #[serde(default)]
3996    pub unlogged: bool,
3997    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3998    #[serde(default)]
3999    pub bulk_collect: bool,
4000    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
4001    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4002    pub expressions: Vec<Expression>,
4003}
4004
4005/// Represent a parenthesized subquery expression.
4006///
4007/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
4008/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4009/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4010/// modifiers are rendered inside or outside the parentheses.
4011///
4012/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4013/// scalar subqueries in select-lists, and derived tables.
4014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4015#[cfg_attr(feature = "bindings", derive(TS))]
4016pub struct Subquery {
4017    /// The inner query expression.
4018    pub this: Expression,
4019    /// Optional alias for the derived table.
4020    pub alias: Option<Identifier>,
4021    /// Optional column aliases: AS t(c1, c2)
4022    pub column_aliases: Vec<Identifier>,
4023    /// Whether AS keyword was explicitly used for the alias.
4024    #[serde(default)]
4025    pub alias_explicit_as: bool,
4026    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4027    #[serde(skip_serializing_if = "Option::is_none", default)]
4028    pub alias_keyword: Option<String>,
4029    /// ORDER BY clause (for parenthesized queries)
4030    pub order_by: Option<OrderBy>,
4031    /// LIMIT clause
4032    pub limit: Option<Limit>,
4033    /// OFFSET clause
4034    pub offset: Option<Offset>,
4035    /// DISTRIBUTE BY clause (Hive/Spark)
4036    #[serde(default, skip_serializing_if = "Option::is_none")]
4037    pub distribute_by: Option<DistributeBy>,
4038    /// SORT BY clause (Hive/Spark)
4039    #[serde(default, skip_serializing_if = "Option::is_none")]
4040    pub sort_by: Option<SortBy>,
4041    /// CLUSTER BY clause (Hive/Spark)
4042    #[serde(default, skip_serializing_if = "Option::is_none")]
4043    pub cluster_by: Option<ClusterBy>,
4044    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4045    #[serde(default)]
4046    pub lateral: bool,
4047    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4048    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4049    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4050    #[serde(default)]
4051    pub modifiers_inside: bool,
4052    /// Trailing comments after the closing paren
4053    #[serde(default)]
4054    pub trailing_comments: Vec<String>,
4055    /// Inferred data type from type annotation
4056    #[serde(default, skip_serializing_if = "Option::is_none")]
4057    pub inferred_type: Option<DataType>,
4058}
4059
4060/// Pipe operator expression: query |> transform
4061///
4062/// Used in DataFusion and BigQuery pipe syntax:
4063///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4065#[cfg_attr(feature = "bindings", derive(TS))]
4066pub struct PipeOperator {
4067    /// The input query/expression (left side of |>)
4068    pub this: Expression,
4069    /// The piped operation (right side of |>)
4070    pub expression: Expression,
4071}
4072
4073/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4075#[cfg_attr(feature = "bindings", derive(TS))]
4076pub struct Values {
4077    /// The rows of values
4078    pub expressions: Vec<Tuple>,
4079    /// Optional alias for the table
4080    pub alias: Option<Identifier>,
4081    /// Optional column aliases: AS t(c1, c2)
4082    pub column_aliases: Vec<Identifier>,
4083}
4084
4085/// PIVOT operation - supports both standard and DuckDB simplified syntax
4086///
4087/// Standard syntax (in FROM clause):
4088///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4089///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4090///
4091/// DuckDB simplified syntax (statement-level):
4092///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4093///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4095#[cfg_attr(feature = "bindings", derive(TS))]
4096pub struct Pivot {
4097    /// Source table/expression
4098    pub this: Expression,
4099    /// For standard PIVOT: the aggregation function(s) (first is primary)
4100    /// For DuckDB simplified: unused (use `using` instead)
4101    #[serde(default)]
4102    pub expressions: Vec<Expression>,
4103    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4104    #[serde(default)]
4105    pub fields: Vec<Expression>,
4106    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4107    #[serde(default)]
4108    pub using: Vec<Expression>,
4109    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4110    #[serde(default)]
4111    pub group: Option<Box<Expression>>,
4112    /// Whether this is an UNPIVOT (vs PIVOT)
4113    #[serde(default)]
4114    pub unpivot: bool,
4115    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4116    #[serde(default)]
4117    pub into: Option<Box<Expression>>,
4118    /// Optional alias
4119    #[serde(default)]
4120    pub alias: Option<Identifier>,
4121    /// Optional output column aliases from `PIVOT(...) AS alias(col1, col2, ...)`
4122    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4123    pub alias_columns: Vec<Identifier>,
4124    /// Include/exclude nulls (for UNPIVOT)
4125    #[serde(default)]
4126    pub include_nulls: Option<bool>,
4127    /// Default on null value (Snowflake)
4128    #[serde(default)]
4129    pub default_on_null: Option<Box<Expression>>,
4130    /// WITH clause (CTEs)
4131    #[serde(default, skip_serializing_if = "Option::is_none")]
4132    pub with: Option<With>,
4133}
4134
4135/// UNPIVOT operation
4136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4137#[cfg_attr(feature = "bindings", derive(TS))]
4138pub struct Unpivot {
4139    pub this: Expression,
4140    pub value_column: Identifier,
4141    pub name_column: Identifier,
4142    pub columns: Vec<Expression>,
4143    pub alias: Option<Identifier>,
4144    /// Optional output column aliases from `UNPIVOT(...) AS alias(col1, col2, ...)`
4145    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4146    pub alias_columns: Vec<Identifier>,
4147    /// Whether the value_column was parenthesized in the original SQL
4148    #[serde(default)]
4149    pub value_column_parenthesized: bool,
4150    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4151    #[serde(default)]
4152    pub include_nulls: Option<bool>,
4153    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4154    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4155    pub extra_value_columns: Vec<Identifier>,
4156}
4157
4158/// PIVOT alias for aliasing pivot expressions
4159/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4161#[cfg_attr(feature = "bindings", derive(TS))]
4162pub struct PivotAlias {
4163    pub this: Expression,
4164    pub alias: Expression,
4165}
4166
4167/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4169#[cfg_attr(feature = "bindings", derive(TS))]
4170pub struct PreWhere {
4171    pub this: Expression,
4172}
4173
4174/// STREAM definition (Snowflake) - for change data capture
4175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4176#[cfg_attr(feature = "bindings", derive(TS))]
4177pub struct Stream {
4178    pub this: Expression,
4179    #[serde(skip_serializing_if = "Option::is_none")]
4180    pub on: Option<Expression>,
4181    #[serde(skip_serializing_if = "Option::is_none")]
4182    pub show_initial_rows: Option<bool>,
4183}
4184
4185/// USING DATA clause for data import statements
4186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4187#[cfg_attr(feature = "bindings", derive(TS))]
4188pub struct UsingData {
4189    pub this: Expression,
4190}
4191
4192/// XML Namespace declaration
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub struct XmlNamespace {
4196    pub this: Expression,
4197    #[serde(skip_serializing_if = "Option::is_none")]
4198    pub alias: Option<Identifier>,
4199}
4200
4201/// ROW FORMAT clause for Hive/Spark
4202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4203#[cfg_attr(feature = "bindings", derive(TS))]
4204pub struct RowFormat {
4205    pub delimited: bool,
4206    pub fields_terminated_by: Option<String>,
4207    pub collection_items_terminated_by: Option<String>,
4208    pub map_keys_terminated_by: Option<String>,
4209    pub lines_terminated_by: Option<String>,
4210    pub null_defined_as: Option<String>,
4211}
4212
4213/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4215#[cfg_attr(feature = "bindings", derive(TS))]
4216pub struct DirectoryInsert {
4217    pub local: bool,
4218    pub path: String,
4219    pub row_format: Option<RowFormat>,
4220    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4221    #[serde(default)]
4222    pub stored_as: Option<String>,
4223}
4224
4225/// INSERT statement
4226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4227#[cfg_attr(feature = "bindings", derive(TS))]
4228pub struct Insert {
4229    pub table: TableRef,
4230    pub columns: Vec<Identifier>,
4231    pub values: Vec<Vec<Expression>>,
4232    pub query: Option<Expression>,
4233    /// INSERT OVERWRITE for Hive/Spark
4234    pub overwrite: bool,
4235    /// PARTITION clause for Hive/Spark
4236    pub partition: Vec<(Identifier, Option<Expression>)>,
4237    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4238    #[serde(default)]
4239    pub directory: Option<DirectoryInsert>,
4240    /// RETURNING clause (PostgreSQL, SQLite)
4241    #[serde(default)]
4242    pub returning: Vec<Expression>,
4243    /// OUTPUT clause (TSQL)
4244    #[serde(default)]
4245    pub output: Option<OutputClause>,
4246    /// ON CONFLICT clause (PostgreSQL, SQLite)
4247    #[serde(default)]
4248    pub on_conflict: Option<Box<Expression>>,
4249    /// Leading comments before the statement
4250    #[serde(default)]
4251    pub leading_comments: Vec<String>,
4252    /// IF EXISTS clause (Hive)
4253    #[serde(default)]
4254    pub if_exists: bool,
4255    /// WITH clause (CTEs)
4256    #[serde(default)]
4257    pub with: Option<With>,
4258    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4259    #[serde(default)]
4260    pub ignore: bool,
4261    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4262    #[serde(default)]
4263    pub source_alias: Option<Identifier>,
4264    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4265    #[serde(default)]
4266    pub alias: Option<Identifier>,
4267    /// Whether the alias uses explicit AS keyword
4268    #[serde(default)]
4269    pub alias_explicit_as: bool,
4270    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4271    #[serde(default)]
4272    pub default_values: bool,
4273    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4274    #[serde(default)]
4275    pub by_name: bool,
4276    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4277    #[serde(default, skip_serializing_if = "Option::is_none")]
4278    pub conflict_action: Option<String>,
4279    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4280    #[serde(default)]
4281    pub is_replace: bool,
4282    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4283    #[serde(default, skip_serializing_if = "Option::is_none")]
4284    pub hint: Option<Hint>,
4285    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4286    #[serde(default)]
4287    pub replace_where: Option<Box<Expression>>,
4288    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4289    #[serde(default)]
4290    pub source: Option<Box<Expression>>,
4291    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4292    #[serde(default, skip_serializing_if = "Option::is_none")]
4293    pub function_target: Option<Box<Expression>>,
4294    /// ClickHouse: PARTITION BY expr
4295    #[serde(default, skip_serializing_if = "Option::is_none")]
4296    pub partition_by: Option<Box<Expression>>,
4297    /// ClickHouse: SETTINGS key = val, ...
4298    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4299    pub settings: Vec<Expression>,
4300}
4301
4302/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4304#[cfg_attr(feature = "bindings", derive(TS))]
4305pub struct OutputClause {
4306    /// Columns/expressions to output
4307    pub columns: Vec<Expression>,
4308    /// Optional INTO target table or table variable
4309    #[serde(default)]
4310    pub into_table: Option<Expression>,
4311}
4312
4313/// UPDATE statement
4314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4315#[cfg_attr(feature = "bindings", derive(TS))]
4316pub struct Update {
4317    pub table: TableRef,
4318    #[serde(default)]
4319    pub hint: Option<Hint>,
4320    /// Additional tables for multi-table UPDATE (MySQL syntax)
4321    #[serde(default)]
4322    pub extra_tables: Vec<TableRef>,
4323    /// JOINs attached to the table list (MySQL multi-table syntax)
4324    #[serde(default)]
4325    pub table_joins: Vec<Join>,
4326    pub set: Vec<(Identifier, Expression)>,
4327    pub from_clause: Option<From>,
4328    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4329    #[serde(default)]
4330    pub from_joins: Vec<Join>,
4331    pub where_clause: Option<Where>,
4332    /// RETURNING clause (PostgreSQL, SQLite)
4333    #[serde(default)]
4334    pub returning: Vec<Expression>,
4335    /// OUTPUT clause (TSQL)
4336    #[serde(default)]
4337    pub output: Option<OutputClause>,
4338    /// WITH clause (CTEs)
4339    #[serde(default)]
4340    pub with: Option<With>,
4341    /// Leading comments before the statement
4342    #[serde(default)]
4343    pub leading_comments: Vec<String>,
4344    /// LIMIT clause (MySQL)
4345    #[serde(default)]
4346    pub limit: Option<Expression>,
4347    /// ORDER BY clause (MySQL)
4348    #[serde(default)]
4349    pub order_by: Option<OrderBy>,
4350    /// Whether FROM clause appears before SET (Snowflake syntax)
4351    #[serde(default)]
4352    pub from_before_set: bool,
4353}
4354
4355/// DELETE statement
4356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4357#[cfg_attr(feature = "bindings", derive(TS))]
4358pub struct Delete {
4359    pub table: TableRef,
4360    #[serde(default)]
4361    pub hint: Option<Hint>,
4362    /// ClickHouse: ON CLUSTER clause for distributed DDL
4363    #[serde(default, skip_serializing_if = "Option::is_none")]
4364    pub on_cluster: Option<OnCluster>,
4365    /// Optional alias for the table
4366    pub alias: Option<Identifier>,
4367    /// Whether the alias was declared with explicit AS keyword
4368    #[serde(default)]
4369    pub alias_explicit_as: bool,
4370    /// PostgreSQL/DuckDB USING clause - additional tables to join
4371    pub using: Vec<TableRef>,
4372    pub where_clause: Option<Where>,
4373    /// OUTPUT clause (TSQL)
4374    #[serde(default)]
4375    pub output: Option<OutputClause>,
4376    /// Leading comments before the statement
4377    #[serde(default)]
4378    pub leading_comments: Vec<String>,
4379    /// WITH clause (CTEs)
4380    #[serde(default)]
4381    pub with: Option<With>,
4382    /// LIMIT clause (MySQL)
4383    #[serde(default)]
4384    pub limit: Option<Expression>,
4385    /// ORDER BY clause (MySQL)
4386    #[serde(default)]
4387    pub order_by: Option<OrderBy>,
4388    /// RETURNING clause (PostgreSQL)
4389    #[serde(default)]
4390    pub returning: Vec<Expression>,
4391    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4392    /// These are the target tables to delete from
4393    #[serde(default)]
4394    pub tables: Vec<TableRef>,
4395    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4396    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4397    #[serde(default)]
4398    pub tables_from_using: bool,
4399    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4400    #[serde(default)]
4401    pub joins: Vec<Join>,
4402    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4403    #[serde(default)]
4404    pub force_index: Option<String>,
4405    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4406    #[serde(default)]
4407    pub no_from: bool,
4408}
4409
4410/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4412#[cfg_attr(feature = "bindings", derive(TS))]
4413pub struct CopyStmt {
4414    /// Target table or query
4415    pub this: Expression,
4416    /// True for FROM (loading into table), false for TO (exporting)
4417    pub kind: bool,
4418    /// Source/destination file(s) or stage
4419    pub files: Vec<Expression>,
4420    /// Copy parameters
4421    #[serde(default)]
4422    pub params: Vec<CopyParameter>,
4423    /// Credentials for external access
4424    #[serde(default)]
4425    pub credentials: Option<Box<Credentials>>,
4426    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4427    #[serde(default)]
4428    pub is_into: bool,
4429    /// Whether parameters are wrapped in WITH (...) syntax
4430    #[serde(default)]
4431    pub with_wrapped: bool,
4432}
4433
4434/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4436#[cfg_attr(feature = "bindings", derive(TS))]
4437pub struct CopyParameter {
4438    pub name: String,
4439    pub value: Option<Expression>,
4440    pub values: Vec<Expression>,
4441    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4442    #[serde(default)]
4443    pub eq: bool,
4444}
4445
4446/// Credentials for external access (S3, Azure, etc.)
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct Credentials {
4450    pub credentials: Vec<(String, String)>,
4451    pub encryption: Option<String>,
4452    pub storage: Option<String>,
4453}
4454
4455/// PUT statement (Snowflake)
4456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4457#[cfg_attr(feature = "bindings", derive(TS))]
4458pub struct PutStmt {
4459    /// Source file path
4460    pub source: String,
4461    /// Whether source was quoted in the original SQL
4462    #[serde(default)]
4463    pub source_quoted: bool,
4464    /// Target stage
4465    pub target: Expression,
4466    /// PUT parameters
4467    #[serde(default)]
4468    pub params: Vec<CopyParameter>,
4469}
4470
4471/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4473#[cfg_attr(feature = "bindings", derive(TS))]
4474pub struct StageReference {
4475    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4476    pub name: String,
4477    /// Optional path within the stage (e.g., "/path/to/file.csv")
4478    #[serde(default)]
4479    pub path: Option<String>,
4480    /// Optional FILE_FORMAT parameter
4481    #[serde(default)]
4482    pub file_format: Option<Expression>,
4483    /// Optional PATTERN parameter
4484    #[serde(default)]
4485    pub pattern: Option<String>,
4486    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4487    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4488    pub quoted: bool,
4489}
4490
4491/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4493#[cfg_attr(feature = "bindings", derive(TS))]
4494pub struct HistoricalData {
4495    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4496    pub this: Box<Expression>,
4497    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4498    pub kind: String,
4499    /// The expression value (e.g., the statement ID or timestamp)
4500    pub expression: Box<Expression>,
4501}
4502
4503/// Represent an aliased expression (`expr AS name`).
4504///
4505/// Used for column aliases in select-lists, table aliases on subqueries,
4506/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct Alias {
4510    /// The expression being aliased.
4511    pub this: Expression,
4512    /// The alias name (required for simple aliases, optional when only column aliases provided)
4513    pub alias: Identifier,
4514    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4515    #[serde(default)]
4516    pub column_aliases: Vec<Identifier>,
4517    /// Whether AS keyword was explicitly used for the alias.
4518    #[serde(default)]
4519    pub alias_explicit_as: bool,
4520    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4521    #[serde(skip_serializing_if = "Option::is_none", default)]
4522    pub alias_keyword: Option<String>,
4523    /// Comments that appeared between the expression and AS keyword
4524    #[serde(default)]
4525    pub pre_alias_comments: Vec<String>,
4526    /// Trailing comments that appeared after the alias
4527    #[serde(default)]
4528    pub trailing_comments: Vec<String>,
4529    /// Inferred data type from type annotation
4530    #[serde(default, skip_serializing_if = "Option::is_none")]
4531    pub inferred_type: Option<DataType>,
4532}
4533
4534impl Alias {
4535    /// Create a simple alias
4536    pub fn new(this: Expression, alias: Identifier) -> Self {
4537        Self {
4538            this,
4539            alias,
4540            column_aliases: Vec::new(),
4541            alias_explicit_as: false,
4542            alias_keyword: None,
4543            pre_alias_comments: Vec::new(),
4544            trailing_comments: Vec::new(),
4545            inferred_type: None,
4546        }
4547    }
4548
4549    /// Create an alias with column aliases only (no table alias name)
4550    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4551        Self {
4552            this,
4553            alias: Identifier::empty(),
4554            column_aliases,
4555            alias_explicit_as: false,
4556            alias_keyword: None,
4557            pre_alias_comments: Vec::new(),
4558            trailing_comments: Vec::new(),
4559            inferred_type: None,
4560        }
4561    }
4562}
4563
4564/// Represent a type cast expression.
4565///
4566/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4567/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4568/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4569/// CONVERSION ERROR (Oracle) clauses.
4570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4571#[cfg_attr(feature = "bindings", derive(TS))]
4572pub struct Cast {
4573    /// The expression being cast.
4574    pub this: Expression,
4575    /// The target data type.
4576    pub to: DataType,
4577    #[serde(default)]
4578    pub trailing_comments: Vec<String>,
4579    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4580    #[serde(default)]
4581    pub double_colon_syntax: bool,
4582    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4583    #[serde(skip_serializing_if = "Option::is_none", default)]
4584    pub format: Option<Box<Expression>>,
4585    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4586    #[serde(skip_serializing_if = "Option::is_none", default)]
4587    pub default: Option<Box<Expression>>,
4588    /// Inferred data type from type annotation
4589    #[serde(default, skip_serializing_if = "Option::is_none")]
4590    pub inferred_type: Option<DataType>,
4591}
4592
4593///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4595#[cfg_attr(feature = "bindings", derive(TS))]
4596pub struct CollationExpr {
4597    pub this: Expression,
4598    pub collation: String,
4599    /// True if the collation was single-quoted in the original SQL (string literal)
4600    #[serde(default)]
4601    pub quoted: bool,
4602    /// True if the collation was double-quoted in the original SQL (identifier)
4603    #[serde(default)]
4604    pub double_quoted: bool,
4605}
4606
4607/// Represent a CASE expression (both simple and searched forms).
4608///
4609/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4610/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4611/// Each entry in `whens` is a `(condition, result)` pair.
4612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4613#[cfg_attr(feature = "bindings", derive(TS))]
4614pub struct Case {
4615    /// The operand for simple CASE, or `None` for searched CASE.
4616    pub operand: Option<Expression>,
4617    /// Pairs of (WHEN condition, THEN result).
4618    pub whens: Vec<(Expression, Expression)>,
4619    /// Optional ELSE result.
4620    pub else_: Option<Expression>,
4621    /// Comments from the CASE keyword (emitted after END)
4622    #[serde(default)]
4623    #[serde(skip_serializing_if = "Vec::is_empty")]
4624    pub comments: Vec<String>,
4625    /// Inferred data type from type annotation
4626    #[serde(default, skip_serializing_if = "Option::is_none")]
4627    pub inferred_type: Option<DataType>,
4628}
4629
4630/// Represent a binary operation (two operands separated by an operator).
4631///
4632/// This is the shared payload struct for all binary operator variants in the
4633/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4634/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4635/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4636/// preservation of inline comments around operators.
4637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4638#[cfg_attr(feature = "bindings", derive(TS))]
4639pub struct BinaryOp {
4640    pub left: Expression,
4641    pub right: Expression,
4642    /// Comments after the left operand (before the operator)
4643    #[serde(default)]
4644    pub left_comments: Vec<String>,
4645    /// Comments after the operator (before the right operand)
4646    #[serde(default)]
4647    pub operator_comments: Vec<String>,
4648    /// Comments after the right operand
4649    #[serde(default)]
4650    pub trailing_comments: Vec<String>,
4651    /// Inferred data type from type annotation
4652    #[serde(default, skip_serializing_if = "Option::is_none")]
4653    pub inferred_type: Option<DataType>,
4654}
4655
4656impl BinaryOp {
4657    pub fn new(left: Expression, right: Expression) -> Self {
4658        Self {
4659            left,
4660            right,
4661            left_comments: Vec::new(),
4662            operator_comments: Vec::new(),
4663            trailing_comments: Vec::new(),
4664            inferred_type: None,
4665        }
4666    }
4667}
4668
4669/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4671#[cfg_attr(feature = "bindings", derive(TS))]
4672pub struct LikeOp {
4673    pub left: Expression,
4674    pub right: Expression,
4675    /// ESCAPE character/expression
4676    #[serde(default)]
4677    pub escape: Option<Expression>,
4678    /// Quantifier: ANY, ALL, or SOME
4679    #[serde(default)]
4680    pub quantifier: Option<String>,
4681    /// Inferred data type from type annotation
4682    #[serde(default, skip_serializing_if = "Option::is_none")]
4683    pub inferred_type: Option<DataType>,
4684}
4685
4686impl LikeOp {
4687    pub fn new(left: Expression, right: Expression) -> Self {
4688        Self {
4689            left,
4690            right,
4691            escape: None,
4692            quantifier: None,
4693            inferred_type: None,
4694        }
4695    }
4696
4697    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4698        Self {
4699            left,
4700            right,
4701            escape: Some(escape),
4702            quantifier: None,
4703            inferred_type: None,
4704        }
4705    }
4706}
4707
4708/// Represent a unary operation (single operand with a prefix operator).
4709///
4710/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4712#[cfg_attr(feature = "bindings", derive(TS))]
4713pub struct UnaryOp {
4714    /// The operand expression.
4715    pub this: Expression,
4716    /// Inferred data type from type annotation
4717    #[serde(default, skip_serializing_if = "Option::is_none")]
4718    pub inferred_type: Option<DataType>,
4719}
4720
4721impl UnaryOp {
4722    pub fn new(this: Expression) -> Self {
4723        Self {
4724            this,
4725            inferred_type: None,
4726        }
4727    }
4728}
4729
4730/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4731///
4732/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4733/// but not both. When `not` is true, the predicate is `NOT IN`.
4734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4735#[cfg_attr(feature = "bindings", derive(TS))]
4736pub struct In {
4737    /// The expression being tested.
4738    pub this: Expression,
4739    /// The value list (mutually exclusive with `query`).
4740    pub expressions: Vec<Expression>,
4741    /// A subquery (mutually exclusive with `expressions`).
4742    pub query: Option<Expression>,
4743    /// Whether this is NOT IN.
4744    pub not: bool,
4745    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4746    pub global: bool,
4747    /// BigQuery: IN UNNEST(expr)
4748    #[serde(default, skip_serializing_if = "Option::is_none")]
4749    pub unnest: Option<Box<Expression>>,
4750    /// Whether the right side is a bare field reference (no parentheses).
4751    /// Matches Python sqlglot's `field` attribute on `In` expression.
4752    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4753    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4754    pub is_field: bool,
4755}
4756
4757/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4759#[cfg_attr(feature = "bindings", derive(TS))]
4760pub struct Between {
4761    /// The expression being tested.
4762    pub this: Expression,
4763    /// The lower bound.
4764    pub low: Expression,
4765    /// The upper bound.
4766    pub high: Expression,
4767    /// Whether this is NOT BETWEEN.
4768    pub not: bool,
4769    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4770    #[serde(default)]
4771    pub symmetric: Option<bool>,
4772}
4773
4774/// IS NULL predicate
4775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4776#[cfg_attr(feature = "bindings", derive(TS))]
4777pub struct IsNull {
4778    pub this: Expression,
4779    pub not: bool,
4780    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4781    #[serde(default)]
4782    pub postfix_form: bool,
4783}
4784
4785/// IS TRUE / IS FALSE predicate
4786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4787#[cfg_attr(feature = "bindings", derive(TS))]
4788pub struct IsTrueFalse {
4789    pub this: Expression,
4790    pub not: bool,
4791}
4792
4793/// IS JSON predicate (SQL standard)
4794/// Checks if a value is valid JSON
4795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4796#[cfg_attr(feature = "bindings", derive(TS))]
4797pub struct IsJson {
4798    pub this: Expression,
4799    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4800    pub json_type: Option<String>,
4801    /// Key uniqueness constraint
4802    pub unique_keys: Option<JsonUniqueKeys>,
4803    /// Whether IS NOT JSON
4804    pub negated: bool,
4805}
4806
4807/// JSON unique keys constraint variants
4808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4809#[cfg_attr(feature = "bindings", derive(TS))]
4810pub enum JsonUniqueKeys {
4811    /// WITH UNIQUE KEYS
4812    With,
4813    /// WITHOUT UNIQUE KEYS
4814    Without,
4815    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4816    Shorthand,
4817}
4818
4819/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4821#[cfg_attr(feature = "bindings", derive(TS))]
4822pub struct Exists {
4823    /// The subquery expression.
4824    pub this: Expression,
4825    /// Whether this is NOT EXISTS.
4826    pub not: bool,
4827}
4828
4829/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4830///
4831/// This is the generic function node. Well-known aggregates, window functions,
4832/// and built-in functions each have their own dedicated `Expression` variants
4833/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4834/// not recognize as built-ins are represented with this struct.
4835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4836#[cfg_attr(feature = "bindings", derive(TS))]
4837pub struct Function {
4838    /// The function name, as originally written (may be schema-qualified).
4839    pub name: String,
4840    /// Positional arguments to the function.
4841    pub args: Vec<Expression>,
4842    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4843    pub distinct: bool,
4844    #[serde(default)]
4845    pub trailing_comments: Vec<String>,
4846    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4847    #[serde(default)]
4848    pub use_bracket_syntax: bool,
4849    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4850    #[serde(default)]
4851    pub no_parens: bool,
4852    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4853    #[serde(default)]
4854    pub quoted: bool,
4855    /// Source position span
4856    #[serde(default, skip_serializing_if = "Option::is_none")]
4857    pub span: Option<Span>,
4858    /// Inferred data type from type annotation
4859    #[serde(default, skip_serializing_if = "Option::is_none")]
4860    pub inferred_type: Option<DataType>,
4861}
4862
4863impl Default for Function {
4864    fn default() -> Self {
4865        Self {
4866            name: String::new(),
4867            args: Vec::new(),
4868            distinct: false,
4869            trailing_comments: Vec::new(),
4870            use_bracket_syntax: false,
4871            no_parens: false,
4872            quoted: false,
4873            span: None,
4874            inferred_type: None,
4875        }
4876    }
4877}
4878
4879impl Function {
4880    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4881        Self {
4882            name: name.into(),
4883            args,
4884            distinct: false,
4885            trailing_comments: Vec::new(),
4886            use_bracket_syntax: false,
4887            no_parens: false,
4888            quoted: false,
4889            span: None,
4890            inferred_type: None,
4891        }
4892    }
4893}
4894
4895/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4896///
4897/// This struct is used for aggregate function calls that are not covered by
4898/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4899/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4900/// IGNORE NULLS / RESPECT NULLS modifiers.
4901#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4902#[cfg_attr(feature = "bindings", derive(TS))]
4903pub struct AggregateFunction {
4904    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4905    pub name: String,
4906    /// Positional arguments.
4907    pub args: Vec<Expression>,
4908    /// Whether DISTINCT was specified.
4909    pub distinct: bool,
4910    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4911    pub filter: Option<Expression>,
4912    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4913    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4914    pub order_by: Vec<Ordered>,
4915    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4916    #[serde(default, skip_serializing_if = "Option::is_none")]
4917    pub limit: Option<Box<Expression>>,
4918    /// IGNORE NULLS / RESPECT NULLS
4919    #[serde(default, skip_serializing_if = "Option::is_none")]
4920    pub ignore_nulls: Option<bool>,
4921    /// Inferred data type from type annotation
4922    #[serde(default, skip_serializing_if = "Option::is_none")]
4923    pub inferred_type: Option<DataType>,
4924}
4925
4926/// Represent a window function call with its OVER clause.
4927///
4928/// The inner `this` expression is typically a window-specific expression
4929/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4930/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4931/// frame specification.
4932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4933#[cfg_attr(feature = "bindings", derive(TS))]
4934pub struct WindowFunction {
4935    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4936    pub this: Expression,
4937    /// The OVER clause defining the window partitioning, ordering, and frame.
4938    pub over: Over,
4939    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4940    #[serde(default, skip_serializing_if = "Option::is_none")]
4941    pub keep: Option<Keep>,
4942    /// Inferred data type from type annotation
4943    #[serde(default, skip_serializing_if = "Option::is_none")]
4944    pub inferred_type: Option<DataType>,
4945}
4946
4947/// Oracle KEEP clause for aggregate functions
4948/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4950#[cfg_attr(feature = "bindings", derive(TS))]
4951pub struct Keep {
4952    /// true = FIRST, false = LAST
4953    pub first: bool,
4954    /// ORDER BY clause inside KEEP
4955    pub order_by: Vec<Ordered>,
4956}
4957
4958/// WITHIN GROUP clause (for ordered-set aggregate functions)
4959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4960#[cfg_attr(feature = "bindings", derive(TS))]
4961pub struct WithinGroup {
4962    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4963    pub this: Expression,
4964    /// The ORDER BY clause within the group
4965    pub order_by: Vec<Ordered>,
4966}
4967
4968/// Represent the FROM clause of a SELECT statement.
4969///
4970/// Contains one or more table sources (tables, subqueries, table-valued
4971/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4973#[cfg_attr(feature = "bindings", derive(TS))]
4974pub struct From {
4975    /// The table source expressions.
4976    pub expressions: Vec<Expression>,
4977}
4978
4979/// Represent a JOIN clause between two table sources.
4980///
4981/// The join condition can be specified via `on` (ON predicate) or `using`
4982/// (USING column list), but not both. The `kind` field determines the join
4983/// type (INNER, LEFT, CROSS, etc.).
4984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4985#[cfg_attr(feature = "bindings", derive(TS))]
4986pub struct Join {
4987    /// The right-hand table expression being joined.
4988    pub this: Expression,
4989    /// The ON condition (mutually exclusive with `using`).
4990    pub on: Option<Expression>,
4991    /// The USING column list (mutually exclusive with `on`).
4992    pub using: Vec<Identifier>,
4993    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4994    pub kind: JoinKind,
4995    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4996    pub use_inner_keyword: bool,
4997    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4998    pub use_outer_keyword: bool,
4999    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
5000    pub deferred_condition: bool,
5001    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
5002    #[serde(default, skip_serializing_if = "Option::is_none")]
5003    pub join_hint: Option<String>,
5004    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
5005    #[serde(default, skip_serializing_if = "Option::is_none")]
5006    pub match_condition: Option<Expression>,
5007    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
5008    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5009    pub pivots: Vec<Expression>,
5010    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
5011    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5012    pub comments: Vec<String>,
5013    /// Nesting group identifier for nested join pretty-printing.
5014    /// Joins in the same group were parsed together; group boundaries come from
5015    /// deferred condition resolution phases.
5016    #[serde(default)]
5017    pub nesting_group: usize,
5018    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
5019    #[serde(default)]
5020    pub directed: bool,
5021}
5022
5023/// Enumerate all supported SQL join types.
5024///
5025/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
5026/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
5027/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
5028/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
5029#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5030#[cfg_attr(feature = "bindings", derive(TS))]
5031pub enum JoinKind {
5032    Inner,
5033    Left,
5034    Right,
5035    Full,
5036    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5037    Cross,
5038    Natural,
5039    NaturalLeft,
5040    NaturalRight,
5041    NaturalFull,
5042    Semi,
5043    Anti,
5044    // Directional SEMI/ANTI joins
5045    LeftSemi,
5046    LeftAnti,
5047    RightSemi,
5048    RightAnti,
5049    // SQL Server specific
5050    CrossApply,
5051    OuterApply,
5052    // Time-series specific
5053    AsOf,
5054    AsOfLeft,
5055    AsOfRight,
5056    // Lateral join
5057    Lateral,
5058    LeftLateral,
5059    // MySQL specific
5060    Straight,
5061    // Implicit join (comma-separated tables: FROM a, b)
5062    Implicit,
5063    // ClickHouse ARRAY JOIN
5064    Array,
5065    LeftArray,
5066    // ClickHouse PASTE JOIN (positional join)
5067    Paste,
5068    // DuckDB POSITIONAL JOIN
5069    Positional,
5070}
5071
5072impl Default for JoinKind {
5073    fn default() -> Self {
5074        JoinKind::Inner
5075    }
5076}
5077
5078/// Parenthesized table expression with joins
5079/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5081#[cfg_attr(feature = "bindings", derive(TS))]
5082pub struct JoinedTable {
5083    /// The left-hand side table expression
5084    pub left: Expression,
5085    /// The joins applied to the left table
5086    pub joins: Vec<Join>,
5087    /// LATERAL VIEW clauses (Hive/Spark)
5088    pub lateral_views: Vec<LateralView>,
5089    /// Optional alias for the joined table expression
5090    pub alias: Option<Identifier>,
5091}
5092
5093/// Represent a WHERE clause containing a boolean filter predicate.
5094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5095#[cfg_attr(feature = "bindings", derive(TS))]
5096pub struct Where {
5097    /// The filter predicate expression.
5098    pub this: Expression,
5099}
5100
5101/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5102///
5103/// The `expressions` list may contain plain columns, ordinal positions,
5104/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5106#[cfg_attr(feature = "bindings", derive(TS))]
5107pub struct GroupBy {
5108    /// The grouping expressions.
5109    pub expressions: Vec<Expression>,
5110    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5111    #[serde(default)]
5112    pub all: Option<bool>,
5113    /// ClickHouse: WITH TOTALS modifier
5114    #[serde(default)]
5115    pub totals: bool,
5116    /// Leading comments that appeared before the GROUP BY keyword
5117    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5118    pub comments: Vec<String>,
5119}
5120
5121/// Represent a HAVING clause containing a predicate over aggregate results.
5122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5123#[cfg_attr(feature = "bindings", derive(TS))]
5124pub struct Having {
5125    /// The filter predicate, typically involving aggregate functions.
5126    pub this: Expression,
5127    /// Leading comments that appeared before the HAVING keyword
5128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5129    pub comments: Vec<String>,
5130}
5131
5132/// Represent an ORDER BY clause containing one or more sort specifications.
5133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5134#[cfg_attr(feature = "bindings", derive(TS))]
5135pub struct OrderBy {
5136    /// The sort specifications, each with direction and null ordering.
5137    pub expressions: Vec<Ordered>,
5138    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5139    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5140    pub siblings: bool,
5141    /// Leading comments that appeared before the ORDER BY keyword
5142    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5143    pub comments: Vec<String>,
5144}
5145
5146/// Represent an expression with sort direction and null ordering.
5147///
5148/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5149/// When `desc` is false the sort is ascending. The `nulls_first` field
5150/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5151/// (database default).
5152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5153#[cfg_attr(feature = "bindings", derive(TS))]
5154pub struct Ordered {
5155    /// The expression to sort by.
5156    pub this: Expression,
5157    /// Whether the sort direction is descending (true) or ascending (false).
5158    pub desc: bool,
5159    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5160    pub nulls_first: Option<bool>,
5161    /// Whether ASC was explicitly written (not just implied)
5162    #[serde(default)]
5163    pub explicit_asc: bool,
5164    /// ClickHouse WITH FILL clause
5165    #[serde(default, skip_serializing_if = "Option::is_none")]
5166    pub with_fill: Option<Box<WithFill>>,
5167}
5168
5169impl Ordered {
5170    pub fn asc(expr: Expression) -> Self {
5171        Self {
5172            this: expr,
5173            desc: false,
5174            nulls_first: None,
5175            explicit_asc: false,
5176            with_fill: None,
5177        }
5178    }
5179
5180    pub fn desc(expr: Expression) -> Self {
5181        Self {
5182            this: expr,
5183            desc: true,
5184            nulls_first: None,
5185            explicit_asc: false,
5186            with_fill: None,
5187        }
5188    }
5189}
5190
5191/// DISTRIBUTE BY clause (Hive/Spark)
5192/// Controls how rows are distributed across reducers
5193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5194#[cfg_attr(feature = "bindings", derive(TS))]
5195#[cfg_attr(feature = "bindings", ts(export))]
5196pub struct DistributeBy {
5197    pub expressions: Vec<Expression>,
5198}
5199
5200/// CLUSTER BY clause (Hive/Spark)
5201/// Combines DISTRIBUTE BY and SORT BY on the same columns
5202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5203#[cfg_attr(feature = "bindings", derive(TS))]
5204#[cfg_attr(feature = "bindings", ts(export))]
5205pub struct ClusterBy {
5206    pub expressions: Vec<Ordered>,
5207}
5208
5209/// SORT BY clause (Hive/Spark)
5210/// Sorts data within each reducer (local sort, not global)
5211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5212#[cfg_attr(feature = "bindings", derive(TS))]
5213#[cfg_attr(feature = "bindings", ts(export))]
5214pub struct SortBy {
5215    pub expressions: Vec<Ordered>,
5216}
5217
5218/// LATERAL VIEW clause (Hive/Spark)
5219/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5221#[cfg_attr(feature = "bindings", derive(TS))]
5222#[cfg_attr(feature = "bindings", ts(export))]
5223pub struct LateralView {
5224    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5225    pub this: Expression,
5226    /// Table alias for the generated table
5227    pub table_alias: Option<Identifier>,
5228    /// Column aliases for the generated columns
5229    pub column_aliases: Vec<Identifier>,
5230    /// OUTER keyword - preserve nulls when input is empty/null
5231    pub outer: bool,
5232}
5233
5234/// Query hint
5235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5236#[cfg_attr(feature = "bindings", derive(TS))]
5237#[cfg_attr(feature = "bindings", ts(export))]
5238pub struct Hint {
5239    pub expressions: Vec<HintExpression>,
5240}
5241
5242/// Individual hint expression
5243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5244#[cfg_attr(feature = "bindings", derive(TS))]
5245#[cfg_attr(feature = "bindings", ts(export))]
5246pub enum HintExpression {
5247    /// Function-style hint: USE_HASH(table)
5248    Function { name: String, args: Vec<Expression> },
5249    /// Simple identifier hint: PARALLEL
5250    Identifier(String),
5251    /// Raw hint text (unparsed)
5252    Raw(String),
5253}
5254
5255/// Pseudocolumn type
5256#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5257#[cfg_attr(feature = "bindings", derive(TS))]
5258#[cfg_attr(feature = "bindings", ts(export))]
5259pub enum PseudocolumnType {
5260    Rownum,      // Oracle ROWNUM
5261    Rowid,       // Oracle ROWID
5262    Level,       // Oracle LEVEL (for CONNECT BY)
5263    Sysdate,     // Oracle SYSDATE
5264    ObjectId,    // Oracle OBJECT_ID
5265    ObjectValue, // Oracle OBJECT_VALUE
5266}
5267
5268impl PseudocolumnType {
5269    pub fn as_str(&self) -> &'static str {
5270        match self {
5271            PseudocolumnType::Rownum => "ROWNUM",
5272            PseudocolumnType::Rowid => "ROWID",
5273            PseudocolumnType::Level => "LEVEL",
5274            PseudocolumnType::Sysdate => "SYSDATE",
5275            PseudocolumnType::ObjectId => "OBJECT_ID",
5276            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5277        }
5278    }
5279
5280    pub fn from_str(s: &str) -> Option<Self> {
5281        match s.to_uppercase().as_str() {
5282            "ROWNUM" => Some(PseudocolumnType::Rownum),
5283            "ROWID" => Some(PseudocolumnType::Rowid),
5284            "LEVEL" => Some(PseudocolumnType::Level),
5285            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5286            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5287            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5288            _ => None,
5289        }
5290    }
5291}
5292
5293/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5294/// These are special identifiers that should not be quoted
5295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5296#[cfg_attr(feature = "bindings", derive(TS))]
5297#[cfg_attr(feature = "bindings", ts(export))]
5298pub struct Pseudocolumn {
5299    pub kind: PseudocolumnType,
5300}
5301
5302impl Pseudocolumn {
5303    pub fn rownum() -> Self {
5304        Self {
5305            kind: PseudocolumnType::Rownum,
5306        }
5307    }
5308
5309    pub fn rowid() -> Self {
5310        Self {
5311            kind: PseudocolumnType::Rowid,
5312        }
5313    }
5314
5315    pub fn level() -> Self {
5316        Self {
5317            kind: PseudocolumnType::Level,
5318        }
5319    }
5320}
5321
5322/// Oracle CONNECT BY clause for hierarchical queries
5323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5324#[cfg_attr(feature = "bindings", derive(TS))]
5325#[cfg_attr(feature = "bindings", ts(export))]
5326pub struct Connect {
5327    /// START WITH condition (optional, can come before or after CONNECT BY)
5328    pub start: Option<Expression>,
5329    /// CONNECT BY condition (required, contains PRIOR references)
5330    pub connect: Expression,
5331    /// NOCYCLE keyword to prevent infinite loops
5332    pub nocycle: bool,
5333}
5334
5335/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5337#[cfg_attr(feature = "bindings", derive(TS))]
5338#[cfg_attr(feature = "bindings", ts(export))]
5339pub struct Prior {
5340    pub this: Expression,
5341}
5342
5343/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5345#[cfg_attr(feature = "bindings", derive(TS))]
5346#[cfg_attr(feature = "bindings", ts(export))]
5347pub struct ConnectByRoot {
5348    pub this: Expression,
5349}
5350
5351/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5353#[cfg_attr(feature = "bindings", derive(TS))]
5354#[cfg_attr(feature = "bindings", ts(export))]
5355pub struct MatchRecognize {
5356    /// Source table/expression
5357    pub this: Option<Box<Expression>>,
5358    /// PARTITION BY expressions
5359    pub partition_by: Option<Vec<Expression>>,
5360    /// ORDER BY expressions
5361    pub order_by: Option<Vec<Ordered>>,
5362    /// MEASURES definitions
5363    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5364    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5365    pub rows: Option<MatchRecognizeRows>,
5366    /// AFTER MATCH SKIP behavior
5367    pub after: Option<MatchRecognizeAfter>,
5368    /// PATTERN definition (stored as raw string for complex regex patterns)
5369    pub pattern: Option<String>,
5370    /// DEFINE clauses (pattern variable definitions)
5371    pub define: Option<Vec<(Identifier, Expression)>>,
5372    /// Optional alias for the result
5373    pub alias: Option<Identifier>,
5374    /// Whether AS keyword was explicitly present before alias
5375    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5376    pub alias_explicit_as: bool,
5377}
5378
5379/// MEASURES expression with optional RUNNING/FINAL semantics
5380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5381#[cfg_attr(feature = "bindings", derive(TS))]
5382#[cfg_attr(feature = "bindings", ts(export))]
5383pub struct MatchRecognizeMeasure {
5384    /// The measure expression
5385    pub this: Expression,
5386    /// RUNNING or FINAL semantics (Snowflake-specific)
5387    pub window_frame: Option<MatchRecognizeSemantics>,
5388}
5389
5390/// Semantics for MEASURES in MATCH_RECOGNIZE
5391#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5392#[cfg_attr(feature = "bindings", derive(TS))]
5393#[cfg_attr(feature = "bindings", ts(export))]
5394pub enum MatchRecognizeSemantics {
5395    Running,
5396    Final,
5397}
5398
5399/// Row output semantics for MATCH_RECOGNIZE
5400#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5401#[cfg_attr(feature = "bindings", derive(TS))]
5402#[cfg_attr(feature = "bindings", ts(export))]
5403pub enum MatchRecognizeRows {
5404    OneRowPerMatch,
5405    AllRowsPerMatch,
5406    AllRowsPerMatchShowEmptyMatches,
5407    AllRowsPerMatchOmitEmptyMatches,
5408    AllRowsPerMatchWithUnmatchedRows,
5409}
5410
5411/// AFTER MATCH SKIP behavior
5412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5413#[cfg_attr(feature = "bindings", derive(TS))]
5414#[cfg_attr(feature = "bindings", ts(export))]
5415pub enum MatchRecognizeAfter {
5416    PastLastRow,
5417    ToNextRow,
5418    ToFirst(Identifier),
5419    ToLast(Identifier),
5420}
5421
5422/// Represent a LIMIT clause that restricts the number of returned rows.
5423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5424#[cfg_attr(feature = "bindings", derive(TS))]
5425pub struct Limit {
5426    /// The limit count expression.
5427    pub this: Expression,
5428    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5429    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5430    pub percent: bool,
5431    /// Comments from before the LIMIT keyword (emitted after the limit value)
5432    #[serde(default)]
5433    #[serde(skip_serializing_if = "Vec::is_empty")]
5434    pub comments: Vec<String>,
5435}
5436
5437/// OFFSET clause
5438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5439#[cfg_attr(feature = "bindings", derive(TS))]
5440pub struct Offset {
5441    pub this: Expression,
5442    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5443    #[serde(skip_serializing_if = "Option::is_none", default)]
5444    pub rows: Option<bool>,
5445}
5446
5447/// TOP clause (SQL Server)
5448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5449#[cfg_attr(feature = "bindings", derive(TS))]
5450pub struct Top {
5451    pub this: Expression,
5452    pub percent: bool,
5453    pub with_ties: bool,
5454    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5455    #[serde(default)]
5456    pub parenthesized: bool,
5457}
5458
5459/// FETCH FIRST/NEXT clause (SQL standard)
5460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5461#[cfg_attr(feature = "bindings", derive(TS))]
5462pub struct Fetch {
5463    /// FIRST or NEXT
5464    pub direction: String,
5465    /// Count expression (optional)
5466    pub count: Option<Expression>,
5467    /// PERCENT modifier
5468    pub percent: bool,
5469    /// ROWS or ROW keyword present
5470    pub rows: bool,
5471    /// WITH TIES modifier
5472    pub with_ties: bool,
5473}
5474
5475/// Represent a QUALIFY clause for filtering on window function results.
5476///
5477/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5478/// typically references a window function (e.g.
5479/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5481#[cfg_attr(feature = "bindings", derive(TS))]
5482pub struct Qualify {
5483    /// The filter predicate over window function results.
5484    pub this: Expression,
5485}
5486
5487/// SAMPLE / TABLESAMPLE clause
5488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5489#[cfg_attr(feature = "bindings", derive(TS))]
5490pub struct Sample {
5491    pub method: SampleMethod,
5492    pub size: Expression,
5493    pub seed: Option<Expression>,
5494    /// ClickHouse OFFSET expression after SAMPLE size
5495    #[serde(default)]
5496    pub offset: Option<Expression>,
5497    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5498    pub unit_after_size: bool,
5499    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5500    #[serde(default)]
5501    pub use_sample_keyword: bool,
5502    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5503    #[serde(default)]
5504    pub explicit_method: bool,
5505    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5506    #[serde(default)]
5507    pub method_before_size: bool,
5508    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5509    #[serde(default)]
5510    pub use_seed_keyword: bool,
5511    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5512    pub bucket_numerator: Option<Box<Expression>>,
5513    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5514    pub bucket_denominator: Option<Box<Expression>>,
5515    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5516    pub bucket_field: Option<Box<Expression>>,
5517    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5518    #[serde(default)]
5519    pub is_using_sample: bool,
5520    /// Whether the unit was explicitly PERCENT (vs ROWS)
5521    #[serde(default)]
5522    pub is_percent: bool,
5523    /// Whether to suppress method output (for cross-dialect transpilation)
5524    #[serde(default)]
5525    pub suppress_method_output: bool,
5526}
5527
5528/// Sample method
5529#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5530#[cfg_attr(feature = "bindings", derive(TS))]
5531pub enum SampleMethod {
5532    Bernoulli,
5533    System,
5534    Block,
5535    Row,
5536    Percent,
5537    /// Hive bucket sampling
5538    Bucket,
5539    /// DuckDB reservoir sampling
5540    Reservoir,
5541}
5542
5543/// Named window definition (WINDOW w AS (...))
5544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5545#[cfg_attr(feature = "bindings", derive(TS))]
5546pub struct NamedWindow {
5547    pub name: Identifier,
5548    pub spec: Over,
5549}
5550
5551/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5552///
5553/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5554/// that reference themselves. Each CTE is defined in the `ctes` vector and
5555/// can be referenced by name in subsequent CTEs and in the main query body.
5556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5557#[cfg_attr(feature = "bindings", derive(TS))]
5558pub struct With {
5559    /// The list of CTE definitions, in order.
5560    pub ctes: Vec<Cte>,
5561    /// Whether the WITH RECURSIVE keyword was used.
5562    pub recursive: bool,
5563    /// Leading comments before the statement
5564    #[serde(default)]
5565    pub leading_comments: Vec<String>,
5566    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5567    #[serde(default, skip_serializing_if = "Option::is_none")]
5568    pub search: Option<Box<Expression>>,
5569}
5570
5571/// Represent a single Common Table Expression definition.
5572///
5573/// A CTE has a name (`alias`), an optional column list, and a body query.
5574/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5575/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5576/// the expression comes before the alias (`alias_first`).
5577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5578#[cfg_attr(feature = "bindings", derive(TS))]
5579pub struct Cte {
5580    /// The CTE name.
5581    pub alias: Identifier,
5582    /// The CTE body (typically a SELECT, UNION, etc.).
5583    pub this: Expression,
5584    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5585    pub columns: Vec<Identifier>,
5586    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5587    pub materialized: Option<bool>,
5588    /// USING KEY (columns) for DuckDB recursive CTEs
5589    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5590    pub key_expressions: Vec<Identifier>,
5591    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5592    #[serde(default)]
5593    pub alias_first: bool,
5594    /// Comments associated with this CTE (placed after alias name, before AS)
5595    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5596    pub comments: Vec<String>,
5597}
5598
5599/// Window specification
5600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5601#[cfg_attr(feature = "bindings", derive(TS))]
5602pub struct WindowSpec {
5603    pub partition_by: Vec<Expression>,
5604    pub order_by: Vec<Ordered>,
5605    pub frame: Option<WindowFrame>,
5606}
5607
5608/// OVER clause
5609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5610#[cfg_attr(feature = "bindings", derive(TS))]
5611pub struct Over {
5612    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5613    pub window_name: Option<Identifier>,
5614    pub partition_by: Vec<Expression>,
5615    pub order_by: Vec<Ordered>,
5616    pub frame: Option<WindowFrame>,
5617    pub alias: Option<Identifier>,
5618}
5619
5620/// Window frame
5621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5622#[cfg_attr(feature = "bindings", derive(TS))]
5623pub struct WindowFrame {
5624    pub kind: WindowFrameKind,
5625    pub start: WindowFrameBound,
5626    pub end: Option<WindowFrameBound>,
5627    pub exclude: Option<WindowFrameExclude>,
5628    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5629    #[serde(default, skip_serializing_if = "Option::is_none")]
5630    pub kind_text: Option<String>,
5631    /// Original text of the start bound side keyword (e.g. "preceding")
5632    #[serde(default, skip_serializing_if = "Option::is_none")]
5633    pub start_side_text: Option<String>,
5634    /// Original text of the end bound side keyword
5635    #[serde(default, skip_serializing_if = "Option::is_none")]
5636    pub end_side_text: Option<String>,
5637}
5638
5639#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5640#[cfg_attr(feature = "bindings", derive(TS))]
5641pub enum WindowFrameKind {
5642    Rows,
5643    Range,
5644    Groups,
5645}
5646
5647/// EXCLUDE clause for window frames
5648#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5649#[cfg_attr(feature = "bindings", derive(TS))]
5650pub enum WindowFrameExclude {
5651    CurrentRow,
5652    Group,
5653    Ties,
5654    NoOthers,
5655}
5656
5657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5658#[cfg_attr(feature = "bindings", derive(TS))]
5659pub enum WindowFrameBound {
5660    CurrentRow,
5661    UnboundedPreceding,
5662    UnboundedFollowing,
5663    Preceding(Box<Expression>),
5664    Following(Box<Expression>),
5665    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5666    BarePreceding,
5667    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5668    BareFollowing,
5669    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5670    Value(Box<Expression>),
5671}
5672
5673/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5675#[cfg_attr(feature = "bindings", derive(TS))]
5676pub struct StructField {
5677    pub name: String,
5678    pub data_type: DataType,
5679    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5680    pub options: Vec<Expression>,
5681    #[serde(default, skip_serializing_if = "Option::is_none")]
5682    pub comment: Option<String>,
5683}
5684
5685impl StructField {
5686    /// Create a new struct field without options
5687    pub fn new(name: String, data_type: DataType) -> Self {
5688        Self {
5689            name,
5690            data_type,
5691            options: Vec::new(),
5692            comment: None,
5693        }
5694    }
5695
5696    /// Create a new struct field with options
5697    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5698        Self {
5699            name,
5700            data_type,
5701            options,
5702            comment: None,
5703        }
5704    }
5705
5706    /// Create a new struct field with options and comment
5707    pub fn with_options_and_comment(
5708        name: String,
5709        data_type: DataType,
5710        options: Vec<Expression>,
5711        comment: Option<String>,
5712    ) -> Self {
5713        Self {
5714            name,
5715            data_type,
5716            options,
5717            comment,
5718        }
5719    }
5720}
5721
5722/// Enumerate all SQL data types recognized by the parser.
5723///
5724/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5725/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5726/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5727///
5728/// This enum is used in CAST expressions, column definitions, function return
5729/// types, and anywhere a data type specification appears in SQL.
5730///
5731/// Types that do not match any known variant fall through to `Custom { name }`,
5732/// preserving the original type name for round-trip fidelity.
5733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5734#[cfg_attr(feature = "bindings", derive(TS))]
5735#[serde(tag = "data_type", rename_all = "snake_case")]
5736pub enum DataType {
5737    // Numeric
5738    Boolean,
5739    TinyInt {
5740        length: Option<u32>,
5741    },
5742    SmallInt {
5743        length: Option<u32>,
5744    },
5745    /// Int type with optional length. `integer_spelling` indicates whether the original
5746    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5747    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5748    Int {
5749        length: Option<u32>,
5750        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5751        integer_spelling: bool,
5752    },
5753    BigInt {
5754        length: Option<u32>,
5755    },
5756    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5757    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5758    /// preserve the original spelling.
5759    Float {
5760        precision: Option<u32>,
5761        scale: Option<u32>,
5762        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5763        real_spelling: bool,
5764    },
5765    Double {
5766        precision: Option<u32>,
5767        scale: Option<u32>,
5768    },
5769    Decimal {
5770        precision: Option<u32>,
5771        scale: Option<u32>,
5772    },
5773
5774    // String
5775    Char {
5776        length: Option<u32>,
5777    },
5778    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5779    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5780    VarChar {
5781        length: Option<u32>,
5782        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5783        parenthesized_length: bool,
5784    },
5785    /// String type with optional max length (BigQuery STRING(n))
5786    String {
5787        length: Option<u32>,
5788    },
5789    Text,
5790    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5791    TextWithLength {
5792        length: u32,
5793    },
5794
5795    // Binary
5796    Binary {
5797        length: Option<u32>,
5798    },
5799    VarBinary {
5800        length: Option<u32>,
5801    },
5802    Blob,
5803
5804    // Bit
5805    Bit {
5806        length: Option<u32>,
5807    },
5808    VarBit {
5809        length: Option<u32>,
5810    },
5811
5812    // Date/Time
5813    Date,
5814    Time {
5815        precision: Option<u32>,
5816        #[serde(default)]
5817        timezone: bool,
5818    },
5819    Timestamp {
5820        precision: Option<u32>,
5821        timezone: bool,
5822    },
5823    Interval {
5824        unit: Option<String>,
5825        /// For range intervals like INTERVAL DAY TO HOUR
5826        #[serde(default, skip_serializing_if = "Option::is_none")]
5827        to: Option<String>,
5828    },
5829
5830    // JSON
5831    Json,
5832    JsonB,
5833
5834    // UUID
5835    Uuid,
5836
5837    // Array
5838    Array {
5839        element_type: Box<DataType>,
5840        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5841        #[serde(default, skip_serializing_if = "Option::is_none")]
5842        dimension: Option<u32>,
5843    },
5844
5845    /// List type (Materialize): INT LIST, TEXT LIST LIST
5846    /// Uses postfix LIST syntax instead of ARRAY<T>
5847    List {
5848        element_type: Box<DataType>,
5849    },
5850
5851    // Struct/Map
5852    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5853    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5854    Struct {
5855        fields: Vec<StructField>,
5856        nested: bool,
5857    },
5858    Map {
5859        key_type: Box<DataType>,
5860        value_type: Box<DataType>,
5861    },
5862
5863    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5864    Enum {
5865        values: Vec<String>,
5866        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5867        assignments: Vec<Option<String>>,
5868    },
5869
5870    // Set type (MySQL): SET('a', 'b', 'c')
5871    Set {
5872        values: Vec<String>,
5873    },
5874
5875    // Union type (DuckDB): UNION(num INT, str TEXT)
5876    Union {
5877        fields: Vec<(String, DataType)>,
5878    },
5879
5880    // Vector (Snowflake / SingleStore)
5881    Vector {
5882        #[serde(default)]
5883        element_type: Option<Box<DataType>>,
5884        dimension: Option<u32>,
5885    },
5886
5887    // Object (Snowflake structured type)
5888    // fields: Vec of (field_name, field_type, not_null)
5889    Object {
5890        fields: Vec<(String, DataType, bool)>,
5891        modifier: Option<String>,
5892    },
5893
5894    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5895    Nullable {
5896        inner: Box<DataType>,
5897    },
5898
5899    // Custom/User-defined
5900    Custom {
5901        name: String,
5902    },
5903
5904    // Spatial types
5905    Geometry {
5906        subtype: Option<String>,
5907        srid: Option<u32>,
5908    },
5909    Geography {
5910        subtype: Option<String>,
5911        srid: Option<u32>,
5912    },
5913
5914    // Character Set (for CONVERT USING in MySQL)
5915    // Renders as CHAR CHARACTER SET {name} in cast target
5916    CharacterSet {
5917        name: String,
5918    },
5919
5920    // Unknown
5921    Unknown,
5922}
5923
5924/// Array expression
5925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5926#[cfg_attr(feature = "bindings", derive(TS))]
5927#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5928pub struct Array {
5929    pub expressions: Vec<Expression>,
5930}
5931
5932/// Struct expression
5933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5934#[cfg_attr(feature = "bindings", derive(TS))]
5935pub struct Struct {
5936    pub fields: Vec<(Option<String>, Expression)>,
5937}
5938
5939/// Tuple expression
5940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5941#[cfg_attr(feature = "bindings", derive(TS))]
5942pub struct Tuple {
5943    pub expressions: Vec<Expression>,
5944}
5945
5946/// Interval expression
5947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5948#[cfg_attr(feature = "bindings", derive(TS))]
5949pub struct Interval {
5950    /// The value expression (e.g., '1', 5, column_ref)
5951    pub this: Option<Expression>,
5952    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5953    pub unit: Option<IntervalUnitSpec>,
5954}
5955
5956/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5958#[cfg_attr(feature = "bindings", derive(TS))]
5959#[serde(tag = "type", rename_all = "snake_case")]
5960pub enum IntervalUnitSpec {
5961    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5962    Simple {
5963        unit: IntervalUnit,
5964        /// Whether to use plural form (e.g., DAYS vs DAY)
5965        use_plural: bool,
5966    },
5967    /// Interval span (e.g., HOUR TO SECOND)
5968    Span(IntervalSpan),
5969    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5970    /// The start and end can be expressions like function calls with precision
5971    ExprSpan(IntervalSpanExpr),
5972    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5973    Expr(Box<Expression>),
5974}
5975
5976/// Interval span for ranges like HOUR TO SECOND
5977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5978#[cfg_attr(feature = "bindings", derive(TS))]
5979pub struct IntervalSpan {
5980    /// Start unit (e.g., HOUR)
5981    pub this: IntervalUnit,
5982    /// End unit (e.g., SECOND)
5983    pub expression: IntervalUnit,
5984}
5985
5986/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5987/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5989#[cfg_attr(feature = "bindings", derive(TS))]
5990pub struct IntervalSpanExpr {
5991    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5992    pub this: Box<Expression>,
5993    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5994    pub expression: Box<Expression>,
5995}
5996
5997#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5998#[cfg_attr(feature = "bindings", derive(TS))]
5999pub enum IntervalUnit {
6000    Year,
6001    Quarter,
6002    Month,
6003    Week,
6004    Day,
6005    Hour,
6006    Minute,
6007    Second,
6008    Millisecond,
6009    Microsecond,
6010    Nanosecond,
6011}
6012
6013/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
6014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6015#[cfg_attr(feature = "bindings", derive(TS))]
6016pub struct Command {
6017    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
6018    pub this: String,
6019}
6020
6021/// PREPARE statement (PostgreSQL/generic prepared statement definition)
6022/// Syntax: PREPARE name [(type, ...)] AS statement
6023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6024#[cfg_attr(feature = "bindings", derive(TS))]
6025pub struct PrepareStatement {
6026    /// The prepared statement name.
6027    pub name: Identifier,
6028    /// Optional PostgreSQL parameter type list.
6029    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6030    pub parameter_types: Vec<DataType>,
6031    /// The statement to execute when the prepared statement is invoked.
6032    pub statement: Expression,
6033}
6034
6035/// T-SQL TRY/CATCH block.
6036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6037#[cfg_attr(feature = "bindings", derive(TS))]
6038pub struct TryCatch {
6039    /// Statements inside BEGIN TRY ... END TRY.
6040    #[serde(default)]
6041    pub try_body: Vec<Expression>,
6042    /// Statements inside BEGIN CATCH ... END CATCH, when present.
6043    #[serde(default, skip_serializing_if = "Option::is_none")]
6044    pub catch_body: Option<Vec<Expression>>,
6045}
6046
6047/// EXEC/EXECUTE statement (TSQL stored procedure call)
6048/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
6049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6050#[cfg_attr(feature = "bindings", derive(TS))]
6051pub struct ExecuteStatement {
6052    /// The procedure name (can be qualified: schema.proc_name)
6053    pub this: Expression,
6054    /// Named parameters: @param=value pairs
6055    #[serde(default)]
6056    pub parameters: Vec<ExecuteParameter>,
6057    /// Positional prepared statement arguments, used by PostgreSQL EXECUTE name(...).
6058    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6059    pub arguments: Vec<Expression>,
6060    /// Whether this statement represents PostgreSQL-style prepared statement execution.
6061    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6062    pub prepared: bool,
6063    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
6064    #[serde(default, skip_serializing_if = "Option::is_none")]
6065    pub suffix: Option<String>,
6066}
6067
6068/// Named parameter in EXEC statement: @name=value
6069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6070#[cfg_attr(feature = "bindings", derive(TS))]
6071pub struct ExecuteParameter {
6072    /// Parameter name (including @)
6073    pub name: String,
6074    /// Parameter value
6075    pub value: Expression,
6076    /// Whether this is a positional parameter (no = sign)
6077    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6078    pub positional: bool,
6079    /// TSQL OUTPUT modifier on parameter
6080    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6081    pub output: bool,
6082}
6083
6084/// KILL statement (MySQL/MariaDB)
6085/// KILL [CONNECTION | QUERY] <id>
6086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6087#[cfg_attr(feature = "bindings", derive(TS))]
6088pub struct Kill {
6089    /// The target (process ID or connection ID)
6090    pub this: Expression,
6091    /// Optional kind: "CONNECTION" or "QUERY"
6092    pub kind: Option<String>,
6093}
6094
6095/// Snowflake CREATE TASK statement
6096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6097#[cfg_attr(feature = "bindings", derive(TS))]
6098pub struct CreateTask {
6099    pub or_replace: bool,
6100    pub if_not_exists: bool,
6101    /// Task name (possibly qualified: db.schema.task)
6102    pub name: String,
6103    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6104    pub properties: String,
6105    /// The SQL statement body after AS
6106    pub body: Expression,
6107}
6108
6109/// Raw/unparsed SQL
6110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6111#[cfg_attr(feature = "bindings", derive(TS))]
6112pub struct Raw {
6113    pub sql: String,
6114}
6115
6116// ============================================================================
6117// Function expression types
6118// ============================================================================
6119
6120/// Generic unary function (takes a single argument)
6121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6122#[cfg_attr(feature = "bindings", derive(TS))]
6123pub struct UnaryFunc {
6124    pub this: Expression,
6125    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6126    #[serde(skip_serializing_if = "Option::is_none", default)]
6127    pub original_name: Option<String>,
6128    /// Inferred data type from type annotation
6129    #[serde(default, skip_serializing_if = "Option::is_none")]
6130    pub inferred_type: Option<DataType>,
6131}
6132
6133impl UnaryFunc {
6134    /// Create a new UnaryFunc with no original_name
6135    pub fn new(this: Expression) -> Self {
6136        Self {
6137            this,
6138            original_name: None,
6139            inferred_type: None,
6140        }
6141    }
6142
6143    /// Create a new UnaryFunc with an original name for round-trip preservation
6144    pub fn with_name(this: Expression, name: String) -> Self {
6145        Self {
6146            this,
6147            original_name: Some(name),
6148            inferred_type: None,
6149        }
6150    }
6151}
6152
6153/// CHAR/CHR function with multiple args and optional USING charset
6154/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6155/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6157#[cfg_attr(feature = "bindings", derive(TS))]
6158pub struct CharFunc {
6159    pub args: Vec<Expression>,
6160    #[serde(skip_serializing_if = "Option::is_none", default)]
6161    pub charset: Option<String>,
6162    /// Original function name (CHAR or CHR), defaults to CHAR
6163    #[serde(skip_serializing_if = "Option::is_none", default)]
6164    pub name: Option<String>,
6165}
6166
6167/// Generic binary function (takes two arguments)
6168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6169#[cfg_attr(feature = "bindings", derive(TS))]
6170pub struct BinaryFunc {
6171    pub this: Expression,
6172    pub expression: Expression,
6173    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6174    #[serde(skip_serializing_if = "Option::is_none", default)]
6175    pub original_name: Option<String>,
6176    /// Inferred data type from type annotation
6177    #[serde(default, skip_serializing_if = "Option::is_none")]
6178    pub inferred_type: Option<DataType>,
6179}
6180
6181/// Variable argument function
6182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6183#[cfg_attr(feature = "bindings", derive(TS))]
6184pub struct VarArgFunc {
6185    pub expressions: Vec<Expression>,
6186    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6187    #[serde(skip_serializing_if = "Option::is_none", default)]
6188    pub original_name: Option<String>,
6189    /// Inferred data type from type annotation
6190    #[serde(default, skip_serializing_if = "Option::is_none")]
6191    pub inferred_type: Option<DataType>,
6192}
6193
6194/// CONCAT_WS function
6195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6196#[cfg_attr(feature = "bindings", derive(TS))]
6197pub struct ConcatWs {
6198    pub separator: Expression,
6199    pub expressions: Vec<Expression>,
6200}
6201
6202/// SUBSTRING function
6203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6204#[cfg_attr(feature = "bindings", derive(TS))]
6205pub struct SubstringFunc {
6206    pub this: Expression,
6207    pub start: Expression,
6208    pub length: Option<Expression>,
6209    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6210    #[serde(default)]
6211    pub from_for_syntax: bool,
6212}
6213
6214/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6216#[cfg_attr(feature = "bindings", derive(TS))]
6217pub struct OverlayFunc {
6218    pub this: Expression,
6219    pub replacement: Expression,
6220    pub from: Expression,
6221    pub length: Option<Expression>,
6222}
6223
6224/// TRIM function
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub struct TrimFunc {
6228    pub this: Expression,
6229    pub characters: Option<Expression>,
6230    pub position: TrimPosition,
6231    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6232    #[serde(default)]
6233    pub sql_standard_syntax: bool,
6234    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6235    #[serde(default)]
6236    pub position_explicit: bool,
6237}
6238
6239#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6240#[cfg_attr(feature = "bindings", derive(TS))]
6241pub enum TrimPosition {
6242    Both,
6243    Leading,
6244    Trailing,
6245}
6246
6247/// REPLACE function
6248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6249#[cfg_attr(feature = "bindings", derive(TS))]
6250pub struct ReplaceFunc {
6251    pub this: Expression,
6252    pub old: Expression,
6253    pub new: Expression,
6254}
6255
6256/// LEFT/RIGHT function
6257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6258#[cfg_attr(feature = "bindings", derive(TS))]
6259pub struct LeftRightFunc {
6260    pub this: Expression,
6261    pub length: Expression,
6262}
6263
6264/// REPEAT function
6265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6266#[cfg_attr(feature = "bindings", derive(TS))]
6267pub struct RepeatFunc {
6268    pub this: Expression,
6269    pub times: Expression,
6270}
6271
6272/// LPAD/RPAD function
6273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6274#[cfg_attr(feature = "bindings", derive(TS))]
6275pub struct PadFunc {
6276    pub this: Expression,
6277    pub length: Expression,
6278    pub fill: Option<Expression>,
6279}
6280
6281/// SPLIT function
6282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6283#[cfg_attr(feature = "bindings", derive(TS))]
6284pub struct SplitFunc {
6285    pub this: Expression,
6286    pub delimiter: Expression,
6287}
6288
6289/// REGEXP_LIKE function
6290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6291#[cfg_attr(feature = "bindings", derive(TS))]
6292pub struct RegexpFunc {
6293    pub this: Expression,
6294    pub pattern: Expression,
6295    pub flags: Option<Expression>,
6296}
6297
6298/// REGEXP_REPLACE function
6299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6300#[cfg_attr(feature = "bindings", derive(TS))]
6301pub struct RegexpReplaceFunc {
6302    pub this: Expression,
6303    pub pattern: Expression,
6304    pub replacement: Expression,
6305    pub flags: Option<Expression>,
6306}
6307
6308/// REGEXP_EXTRACT function
6309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6310#[cfg_attr(feature = "bindings", derive(TS))]
6311pub struct RegexpExtractFunc {
6312    pub this: Expression,
6313    pub pattern: Expression,
6314    pub group: Option<Expression>,
6315}
6316
6317/// ROUND function
6318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6319#[cfg_attr(feature = "bindings", derive(TS))]
6320pub struct RoundFunc {
6321    pub this: Expression,
6322    pub decimals: Option<Expression>,
6323}
6324
6325/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6327#[cfg_attr(feature = "bindings", derive(TS))]
6328pub struct FloorFunc {
6329    pub this: Expression,
6330    pub scale: Option<Expression>,
6331    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6332    #[serde(skip_serializing_if = "Option::is_none", default)]
6333    pub to: Option<Expression>,
6334}
6335
6336/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6338#[cfg_attr(feature = "bindings", derive(TS))]
6339pub struct CeilFunc {
6340    pub this: Expression,
6341    #[serde(skip_serializing_if = "Option::is_none", default)]
6342    pub decimals: Option<Expression>,
6343    /// Time unit for Druid-style CEIL(time TO unit) syntax
6344    #[serde(skip_serializing_if = "Option::is_none", default)]
6345    pub to: Option<Expression>,
6346}
6347
6348/// LOG function
6349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6350#[cfg_attr(feature = "bindings", derive(TS))]
6351pub struct LogFunc {
6352    pub this: Expression,
6353    pub base: Option<Expression>,
6354}
6355
6356/// CURRENT_DATE (no arguments)
6357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6358#[cfg_attr(feature = "bindings", derive(TS))]
6359pub struct CurrentDate;
6360
6361/// CURRENT_TIME
6362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6363#[cfg_attr(feature = "bindings", derive(TS))]
6364pub struct CurrentTime {
6365    pub precision: Option<u32>,
6366}
6367
6368/// CURRENT_TIMESTAMP
6369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6370#[cfg_attr(feature = "bindings", derive(TS))]
6371pub struct CurrentTimestamp {
6372    pub precision: Option<u32>,
6373    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6374    #[serde(default)]
6375    pub sysdate: bool,
6376}
6377
6378/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6380#[cfg_attr(feature = "bindings", derive(TS))]
6381pub struct CurrentTimestampLTZ {
6382    pub precision: Option<u32>,
6383}
6384
6385/// AT TIME ZONE expression for timezone conversion
6386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6387#[cfg_attr(feature = "bindings", derive(TS))]
6388pub struct AtTimeZone {
6389    /// The expression to convert
6390    pub this: Expression,
6391    /// The target timezone
6392    pub zone: Expression,
6393}
6394
6395/// DATE_ADD / DATE_SUB function
6396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6397#[cfg_attr(feature = "bindings", derive(TS))]
6398pub struct DateAddFunc {
6399    pub this: Expression,
6400    pub interval: Expression,
6401    pub unit: IntervalUnit,
6402}
6403
6404/// DATEDIFF function
6405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6406#[cfg_attr(feature = "bindings", derive(TS))]
6407pub struct DateDiffFunc {
6408    pub this: Expression,
6409    pub expression: Expression,
6410    pub unit: Option<IntervalUnit>,
6411}
6412
6413/// DATE_TRUNC function
6414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6415#[cfg_attr(feature = "bindings", derive(TS))]
6416pub struct DateTruncFunc {
6417    pub this: Expression,
6418    pub unit: DateTimeField,
6419}
6420
6421/// EXTRACT function
6422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6423#[cfg_attr(feature = "bindings", derive(TS))]
6424pub struct ExtractFunc {
6425    pub this: Expression,
6426    pub field: DateTimeField,
6427}
6428
6429#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6430#[cfg_attr(feature = "bindings", derive(TS))]
6431pub enum DateTimeField {
6432    Year,
6433    Month,
6434    Day,
6435    Hour,
6436    Minute,
6437    Second,
6438    Millisecond,
6439    Microsecond,
6440    DayOfWeek,
6441    DayOfYear,
6442    Week,
6443    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6444    WeekWithModifier(String),
6445    Quarter,
6446    Epoch,
6447    Timezone,
6448    TimezoneHour,
6449    TimezoneMinute,
6450    Date,
6451    Time,
6452    /// Custom datetime field for dialect-specific or arbitrary fields
6453    Custom(String),
6454}
6455
6456/// TO_DATE function
6457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6458#[cfg_attr(feature = "bindings", derive(TS))]
6459pub struct ToDateFunc {
6460    pub this: Expression,
6461    pub format: Option<Expression>,
6462}
6463
6464/// TO_TIMESTAMP function
6465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6466#[cfg_attr(feature = "bindings", derive(TS))]
6467pub struct ToTimestampFunc {
6468    pub this: Expression,
6469    pub format: Option<Expression>,
6470}
6471
6472/// IF function
6473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6474#[cfg_attr(feature = "bindings", derive(TS))]
6475pub struct IfFunc {
6476    pub condition: Expression,
6477    pub true_value: Expression,
6478    pub false_value: Option<Expression>,
6479    /// Original function name (IF, IFF, IIF) for round-trip preservation
6480    #[serde(skip_serializing_if = "Option::is_none", default)]
6481    pub original_name: Option<String>,
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/// NVL2 function
6488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6489#[cfg_attr(feature = "bindings", derive(TS))]
6490pub struct Nvl2Func {
6491    pub this: Expression,
6492    pub true_value: Expression,
6493    pub false_value: Expression,
6494    /// Inferred data type from type annotation
6495    #[serde(default, skip_serializing_if = "Option::is_none")]
6496    pub inferred_type: Option<DataType>,
6497}
6498
6499// ============================================================================
6500// Typed Aggregate Function types
6501// ============================================================================
6502
6503/// Generic aggregate function base type
6504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6505#[cfg_attr(feature = "bindings", derive(TS))]
6506pub struct AggFunc {
6507    pub this: Expression,
6508    pub distinct: bool,
6509    pub filter: Option<Expression>,
6510    pub order_by: Vec<Ordered>,
6511    /// Original function name (case-preserving) when parsed from SQL
6512    #[serde(skip_serializing_if = "Option::is_none", default)]
6513    pub name: Option<String>,
6514    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6515    #[serde(skip_serializing_if = "Option::is_none", default)]
6516    pub ignore_nulls: Option<bool>,
6517    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6518    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6519    #[serde(skip_serializing_if = "Option::is_none", default)]
6520    pub having_max: Option<(Box<Expression>, bool)>,
6521    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6522    #[serde(skip_serializing_if = "Option::is_none", default)]
6523    pub limit: Option<Box<Expression>>,
6524    /// Inferred data type from type annotation
6525    #[serde(default, skip_serializing_if = "Option::is_none")]
6526    pub inferred_type: Option<DataType>,
6527}
6528
6529/// COUNT function with optional star
6530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6531#[cfg_attr(feature = "bindings", derive(TS))]
6532pub struct CountFunc {
6533    pub this: Option<Expression>,
6534    pub star: bool,
6535    pub distinct: bool,
6536    pub filter: Option<Expression>,
6537    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6538    #[serde(default, skip_serializing_if = "Option::is_none")]
6539    pub ignore_nulls: Option<bool>,
6540    /// Original function name for case preservation (e.g., "count" or "COUNT")
6541    #[serde(default, skip_serializing_if = "Option::is_none")]
6542    pub original_name: Option<String>,
6543    /// Inferred data type from type annotation
6544    #[serde(default, skip_serializing_if = "Option::is_none")]
6545    pub inferred_type: Option<DataType>,
6546}
6547
6548/// GROUP_CONCAT function (MySQL style)
6549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6550#[cfg_attr(feature = "bindings", derive(TS))]
6551pub struct GroupConcatFunc {
6552    pub this: Expression,
6553    pub separator: Option<Expression>,
6554    pub order_by: Option<Vec<Ordered>>,
6555    pub distinct: bool,
6556    pub filter: Option<Expression>,
6557    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6558    #[serde(default, skip_serializing_if = "Option::is_none")]
6559    pub limit: Option<Box<Expression>>,
6560    /// Inferred data type from type annotation
6561    #[serde(default, skip_serializing_if = "Option::is_none")]
6562    pub inferred_type: Option<DataType>,
6563}
6564
6565/// STRING_AGG function (PostgreSQL/Standard SQL)
6566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6567#[cfg_attr(feature = "bindings", derive(TS))]
6568pub struct StringAggFunc {
6569    pub this: Expression,
6570    #[serde(default)]
6571    pub separator: Option<Expression>,
6572    #[serde(default)]
6573    pub order_by: Option<Vec<Ordered>>,
6574    #[serde(default)]
6575    pub distinct: bool,
6576    #[serde(default)]
6577    pub filter: Option<Expression>,
6578    /// BigQuery LIMIT inside STRING_AGG
6579    #[serde(default, skip_serializing_if = "Option::is_none")]
6580    pub limit: Option<Box<Expression>>,
6581    /// Inferred data type from type annotation
6582    #[serde(default, skip_serializing_if = "Option::is_none")]
6583    pub inferred_type: Option<DataType>,
6584}
6585
6586/// LISTAGG function (Oracle style)
6587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6588#[cfg_attr(feature = "bindings", derive(TS))]
6589pub struct ListAggFunc {
6590    pub this: Expression,
6591    pub separator: Option<Expression>,
6592    pub on_overflow: Option<ListAggOverflow>,
6593    pub order_by: Option<Vec<Ordered>>,
6594    pub distinct: bool,
6595    pub filter: Option<Expression>,
6596    /// Inferred data type from type annotation
6597    #[serde(default, skip_serializing_if = "Option::is_none")]
6598    pub inferred_type: Option<DataType>,
6599}
6600
6601/// LISTAGG ON OVERFLOW behavior
6602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6603#[cfg_attr(feature = "bindings", derive(TS))]
6604pub enum ListAggOverflow {
6605    Error,
6606    Truncate {
6607        filler: Option<Expression>,
6608        with_count: bool,
6609    },
6610}
6611
6612/// SUM_IF / COUNT_IF function
6613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6614#[cfg_attr(feature = "bindings", derive(TS))]
6615pub struct SumIfFunc {
6616    pub this: Expression,
6617    pub condition: Expression,
6618    pub filter: Option<Expression>,
6619    /// Inferred data type from type annotation
6620    #[serde(default, skip_serializing_if = "Option::is_none")]
6621    pub inferred_type: Option<DataType>,
6622}
6623
6624/// APPROX_PERCENTILE function
6625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6626#[cfg_attr(feature = "bindings", derive(TS))]
6627pub struct ApproxPercentileFunc {
6628    pub this: Expression,
6629    pub percentile: Expression,
6630    pub accuracy: Option<Expression>,
6631    pub filter: Option<Expression>,
6632}
6633
6634/// PERCENTILE_CONT / PERCENTILE_DISC function
6635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6636#[cfg_attr(feature = "bindings", derive(TS))]
6637pub struct PercentileFunc {
6638    pub this: Expression,
6639    pub percentile: Expression,
6640    pub order_by: Option<Vec<Ordered>>,
6641    pub filter: Option<Expression>,
6642}
6643
6644// ============================================================================
6645// Typed Window Function types
6646// ============================================================================
6647
6648/// ROW_NUMBER function (no arguments)
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub struct RowNumber;
6652
6653/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6655#[cfg_attr(feature = "bindings", derive(TS))]
6656pub struct Rank {
6657    /// DuckDB: RANK(ORDER BY col) - order by inside function
6658    #[serde(default, skip_serializing_if = "Option::is_none")]
6659    pub order_by: Option<Vec<Ordered>>,
6660    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6661    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6662    pub args: Vec<Expression>,
6663}
6664
6665/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6667#[cfg_attr(feature = "bindings", derive(TS))]
6668pub struct DenseRank {
6669    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6670    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6671    pub args: Vec<Expression>,
6672}
6673
6674/// NTILE function (DuckDB allows ORDER BY inside)
6675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6676#[cfg_attr(feature = "bindings", derive(TS))]
6677pub struct NTileFunc {
6678    /// num_buckets is optional to support Databricks NTILE() without arguments
6679    #[serde(default, skip_serializing_if = "Option::is_none")]
6680    pub num_buckets: Option<Expression>,
6681    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6682    #[serde(default, skip_serializing_if = "Option::is_none")]
6683    pub order_by: Option<Vec<Ordered>>,
6684}
6685
6686/// LEAD / LAG function
6687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6688#[cfg_attr(feature = "bindings", derive(TS))]
6689pub struct LeadLagFunc {
6690    pub this: Expression,
6691    pub offset: Option<Expression>,
6692    pub default: Option<Expression>,
6693    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6694    #[serde(default, skip_serializing_if = "Option::is_none")]
6695    pub ignore_nulls: Option<bool>,
6696}
6697
6698/// FIRST_VALUE / LAST_VALUE function
6699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6700#[cfg_attr(feature = "bindings", derive(TS))]
6701pub struct ValueFunc {
6702    pub this: Expression,
6703    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6704    #[serde(default, skip_serializing_if = "Option::is_none")]
6705    pub ignore_nulls: Option<bool>,
6706    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6707    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6708    pub order_by: Vec<Ordered>,
6709}
6710
6711/// NTH_VALUE function
6712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6713#[cfg_attr(feature = "bindings", derive(TS))]
6714pub struct NthValueFunc {
6715    pub this: Expression,
6716    pub offset: Expression,
6717    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6718    #[serde(default, skip_serializing_if = "Option::is_none")]
6719    pub ignore_nulls: Option<bool>,
6720    /// Snowflake FROM FIRST / FROM LAST clause
6721    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6722    #[serde(default, skip_serializing_if = "Option::is_none")]
6723    pub from_first: Option<bool>,
6724}
6725
6726/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6728#[cfg_attr(feature = "bindings", derive(TS))]
6729pub struct PercentRank {
6730    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6731    #[serde(default, skip_serializing_if = "Option::is_none")]
6732    pub order_by: Option<Vec<Ordered>>,
6733    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6734    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6735    pub args: Vec<Expression>,
6736}
6737
6738/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6740#[cfg_attr(feature = "bindings", derive(TS))]
6741pub struct CumeDist {
6742    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6743    #[serde(default, skip_serializing_if = "Option::is_none")]
6744    pub order_by: Option<Vec<Ordered>>,
6745    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6746    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6747    pub args: Vec<Expression>,
6748}
6749
6750// ============================================================================
6751// Additional String Function types
6752// ============================================================================
6753
6754/// POSITION/INSTR function
6755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6756#[cfg_attr(feature = "bindings", derive(TS))]
6757pub struct PositionFunc {
6758    pub substring: Expression,
6759    pub string: Expression,
6760    pub start: Option<Expression>,
6761}
6762
6763// ============================================================================
6764// Additional Math Function types
6765// ============================================================================
6766
6767/// RANDOM function (no arguments)
6768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6769#[cfg_attr(feature = "bindings", derive(TS))]
6770pub struct Random;
6771
6772/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6774#[cfg_attr(feature = "bindings", derive(TS))]
6775pub struct Rand {
6776    pub seed: Option<Box<Expression>>,
6777    /// Teradata RANDOM lower bound
6778    #[serde(default)]
6779    pub lower: Option<Box<Expression>>,
6780    /// Teradata RANDOM upper bound
6781    #[serde(default)]
6782    pub upper: Option<Box<Expression>>,
6783}
6784
6785/// TRUNCATE / TRUNC function
6786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6787#[cfg_attr(feature = "bindings", derive(TS))]
6788pub struct TruncateFunc {
6789    pub this: Expression,
6790    pub decimals: Option<Expression>,
6791}
6792
6793/// PI function (no arguments)
6794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6795#[cfg_attr(feature = "bindings", derive(TS))]
6796pub struct Pi;
6797
6798// ============================================================================
6799// Control Flow Function types
6800// ============================================================================
6801
6802/// DECODE function (Oracle style)
6803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6804#[cfg_attr(feature = "bindings", derive(TS))]
6805pub struct DecodeFunc {
6806    pub this: Expression,
6807    pub search_results: Vec<(Expression, Expression)>,
6808    pub default: Option<Expression>,
6809}
6810
6811// ============================================================================
6812// Additional Date/Time Function types
6813// ============================================================================
6814
6815/// DATE_FORMAT / FORMAT_DATE function
6816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6817#[cfg_attr(feature = "bindings", derive(TS))]
6818pub struct DateFormatFunc {
6819    pub this: Expression,
6820    pub format: Expression,
6821}
6822
6823/// FROM_UNIXTIME function
6824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6825#[cfg_attr(feature = "bindings", derive(TS))]
6826pub struct FromUnixtimeFunc {
6827    pub this: Expression,
6828    pub format: Option<Expression>,
6829}
6830
6831/// UNIX_TIMESTAMP function
6832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6833#[cfg_attr(feature = "bindings", derive(TS))]
6834pub struct UnixTimestampFunc {
6835    pub this: Option<Expression>,
6836    pub format: Option<Expression>,
6837}
6838
6839/// MAKE_DATE function
6840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6841#[cfg_attr(feature = "bindings", derive(TS))]
6842pub struct MakeDateFunc {
6843    pub year: Expression,
6844    pub month: Expression,
6845    pub day: Expression,
6846}
6847
6848/// MAKE_TIMESTAMP function
6849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6850#[cfg_attr(feature = "bindings", derive(TS))]
6851pub struct MakeTimestampFunc {
6852    pub year: Expression,
6853    pub month: Expression,
6854    pub day: Expression,
6855    pub hour: Expression,
6856    pub minute: Expression,
6857    pub second: Expression,
6858    pub timezone: Option<Expression>,
6859}
6860
6861/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6863#[cfg_attr(feature = "bindings", derive(TS))]
6864pub struct LastDayFunc {
6865    pub this: Expression,
6866    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6867    #[serde(skip_serializing_if = "Option::is_none", default)]
6868    pub unit: Option<DateTimeField>,
6869}
6870
6871// ============================================================================
6872// Array Function types
6873// ============================================================================
6874
6875/// ARRAY constructor
6876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6877#[cfg_attr(feature = "bindings", derive(TS))]
6878pub struct ArrayConstructor {
6879    pub expressions: Vec<Expression>,
6880    pub bracket_notation: bool,
6881    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6882    pub use_list_keyword: bool,
6883}
6884
6885/// ARRAY_SORT function
6886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6887#[cfg_attr(feature = "bindings", derive(TS))]
6888pub struct ArraySortFunc {
6889    pub this: Expression,
6890    pub comparator: Option<Expression>,
6891    pub desc: bool,
6892    pub nulls_first: Option<bool>,
6893}
6894
6895/// ARRAY_JOIN / ARRAY_TO_STRING function
6896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6897#[cfg_attr(feature = "bindings", derive(TS))]
6898pub struct ArrayJoinFunc {
6899    pub this: Expression,
6900    pub separator: Expression,
6901    pub null_replacement: Option<Expression>,
6902}
6903
6904/// UNNEST function
6905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6906#[cfg_attr(feature = "bindings", derive(TS))]
6907pub struct UnnestFunc {
6908    pub this: Expression,
6909    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6910    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6911    pub expressions: Vec<Expression>,
6912    pub with_ordinality: bool,
6913    pub alias: Option<Identifier>,
6914    /// BigQuery: offset alias for WITH OFFSET AS <name>
6915    #[serde(default, skip_serializing_if = "Option::is_none")]
6916    pub offset_alias: Option<Identifier>,
6917}
6918
6919/// ARRAY_FILTER function (with lambda)
6920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6921#[cfg_attr(feature = "bindings", derive(TS))]
6922pub struct ArrayFilterFunc {
6923    pub this: Expression,
6924    pub filter: Expression,
6925}
6926
6927/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6929#[cfg_attr(feature = "bindings", derive(TS))]
6930pub struct ArrayTransformFunc {
6931    pub this: Expression,
6932    pub transform: Expression,
6933}
6934
6935/// SEQUENCE / GENERATE_SERIES function
6936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6937#[cfg_attr(feature = "bindings", derive(TS))]
6938pub struct SequenceFunc {
6939    pub start: Expression,
6940    pub stop: Expression,
6941    pub step: Option<Expression>,
6942}
6943
6944// ============================================================================
6945// Struct Function types
6946// ============================================================================
6947
6948/// STRUCT constructor
6949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6950#[cfg_attr(feature = "bindings", derive(TS))]
6951pub struct StructConstructor {
6952    pub fields: Vec<(Option<Identifier>, Expression)>,
6953}
6954
6955/// STRUCT_EXTRACT function
6956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6957#[cfg_attr(feature = "bindings", derive(TS))]
6958pub struct StructExtractFunc {
6959    pub this: Expression,
6960    pub field: Identifier,
6961}
6962
6963/// NAMED_STRUCT function
6964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6965#[cfg_attr(feature = "bindings", derive(TS))]
6966pub struct NamedStructFunc {
6967    pub pairs: Vec<(Expression, Expression)>,
6968}
6969
6970// ============================================================================
6971// Map Function types
6972// ============================================================================
6973
6974/// MAP constructor
6975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6976#[cfg_attr(feature = "bindings", derive(TS))]
6977pub struct MapConstructor {
6978    pub keys: Vec<Expression>,
6979    pub values: Vec<Expression>,
6980    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6981    #[serde(default)]
6982    pub curly_brace_syntax: bool,
6983    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6984    #[serde(default)]
6985    pub with_map_keyword: bool,
6986}
6987
6988/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6990#[cfg_attr(feature = "bindings", derive(TS))]
6991pub struct TransformFunc {
6992    pub this: Expression,
6993    pub transform: Expression,
6994}
6995
6996/// Function call with EMITS clause (Exasol)
6997/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6999#[cfg_attr(feature = "bindings", derive(TS))]
7000pub struct FunctionEmits {
7001    /// The function call expression
7002    pub this: Expression,
7003    /// The EMITS schema definition
7004    pub emits: Expression,
7005}
7006
7007// ============================================================================
7008// JSON Function types
7009// ============================================================================
7010
7011/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
7012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7013#[cfg_attr(feature = "bindings", derive(TS))]
7014pub struct JsonExtractFunc {
7015    pub this: Expression,
7016    pub path: Expression,
7017    pub returning: Option<DataType>,
7018    /// True if parsed from -> or ->> operator syntax
7019    #[serde(default)]
7020    pub arrow_syntax: bool,
7021    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
7022    #[serde(default)]
7023    pub hash_arrow_syntax: bool,
7024    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
7025    #[serde(default)]
7026    pub wrapper_option: Option<String>,
7027    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
7028    #[serde(default)]
7029    pub quotes_option: Option<String>,
7030    /// ON SCALAR STRING flag
7031    #[serde(default)]
7032    pub on_scalar_string: bool,
7033    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
7034    #[serde(default)]
7035    pub on_error: Option<String>,
7036}
7037
7038/// JSON path extraction
7039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7040#[cfg_attr(feature = "bindings", derive(TS))]
7041pub struct JsonPathFunc {
7042    pub this: Expression,
7043    pub paths: Vec<Expression>,
7044}
7045
7046/// JSON_OBJECT function
7047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7048#[cfg_attr(feature = "bindings", derive(TS))]
7049pub struct JsonObjectFunc {
7050    pub pairs: Vec<(Expression, Expression)>,
7051    pub null_handling: Option<JsonNullHandling>,
7052    #[serde(default)]
7053    pub with_unique_keys: bool,
7054    #[serde(default)]
7055    pub returning_type: Option<DataType>,
7056    #[serde(default)]
7057    pub format_json: bool,
7058    #[serde(default)]
7059    pub encoding: Option<String>,
7060    /// For JSON_OBJECT(*) syntax
7061    #[serde(default)]
7062    pub star: bool,
7063}
7064
7065/// JSON null handling options
7066#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7067#[cfg_attr(feature = "bindings", derive(TS))]
7068pub enum JsonNullHandling {
7069    NullOnNull,
7070    AbsentOnNull,
7071}
7072
7073/// JSON_SET / JSON_INSERT function
7074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7075#[cfg_attr(feature = "bindings", derive(TS))]
7076pub struct JsonModifyFunc {
7077    pub this: Expression,
7078    pub path_values: Vec<(Expression, Expression)>,
7079}
7080
7081/// JSON_ARRAYAGG function
7082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7083#[cfg_attr(feature = "bindings", derive(TS))]
7084pub struct JsonArrayAggFunc {
7085    pub this: Expression,
7086    pub order_by: Option<Vec<Ordered>>,
7087    pub null_handling: Option<JsonNullHandling>,
7088    pub filter: Option<Expression>,
7089}
7090
7091/// JSON_OBJECTAGG function
7092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7093#[cfg_attr(feature = "bindings", derive(TS))]
7094pub struct JsonObjectAggFunc {
7095    pub key: Expression,
7096    pub value: Expression,
7097    pub null_handling: Option<JsonNullHandling>,
7098    pub filter: Option<Expression>,
7099}
7100
7101// ============================================================================
7102// Type Casting Function types
7103// ============================================================================
7104
7105/// CONVERT function (SQL Server style)
7106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7107#[cfg_attr(feature = "bindings", derive(TS))]
7108pub struct ConvertFunc {
7109    pub this: Expression,
7110    pub to: DataType,
7111    pub style: Option<Expression>,
7112}
7113
7114// ============================================================================
7115// Additional Expression types
7116// ============================================================================
7117
7118/// Lambda expression
7119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7120#[cfg_attr(feature = "bindings", derive(TS))]
7121pub struct LambdaExpr {
7122    pub parameters: Vec<Identifier>,
7123    pub body: Expression,
7124    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7125    #[serde(default)]
7126    pub colon: bool,
7127    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7128    /// Maps parameter index to data type
7129    #[serde(default)]
7130    pub parameter_types: Vec<Option<DataType>>,
7131}
7132
7133/// Parameter (parameterized queries)
7134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7135#[cfg_attr(feature = "bindings", derive(TS))]
7136pub struct Parameter {
7137    pub name: Option<String>,
7138    pub index: Option<u32>,
7139    pub style: ParameterStyle,
7140    /// Whether the name was quoted (e.g., @"x" vs @x)
7141    #[serde(default)]
7142    pub quoted: bool,
7143    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7144    #[serde(default)]
7145    pub string_quoted: bool,
7146    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7147    #[serde(default)]
7148    pub expression: Option<String>,
7149}
7150
7151/// Parameter placeholder styles
7152#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub enum ParameterStyle {
7155    Question,     // ?
7156    Dollar,       // $1, $2
7157    DollarBrace,  // ${name} (Databricks, Hive template variables)
7158    Brace,        // {name} (Spark/Databricks widget/template variables)
7159    Colon,        // :name
7160    At,           // @name
7161    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7162    DoubleDollar, // $$name
7163    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7164}
7165
7166/// Placeholder expression
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub struct Placeholder {
7170    pub index: Option<u32>,
7171}
7172
7173/// Named argument in function call: name => value or name := value
7174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7175#[cfg_attr(feature = "bindings", derive(TS))]
7176pub struct NamedArgument {
7177    pub name: Identifier,
7178    pub value: Expression,
7179    /// The separator used: `=>`, `:=`, or `=`
7180    pub separator: NamedArgSeparator,
7181}
7182
7183/// Separator style for named arguments
7184#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7185#[cfg_attr(feature = "bindings", derive(TS))]
7186pub enum NamedArgSeparator {
7187    /// `=>` (standard SQL, Snowflake, BigQuery)
7188    DArrow,
7189    /// `:=` (Oracle, MySQL)
7190    ColonEq,
7191    /// `=` (simple equals, some dialects)
7192    Eq,
7193}
7194
7195/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7196/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7198#[cfg_attr(feature = "bindings", derive(TS))]
7199pub struct TableArgument {
7200    /// The keyword prefix: "TABLE" or "MODEL"
7201    pub prefix: String,
7202    /// The table/model reference expression
7203    pub this: Expression,
7204}
7205
7206/// SQL Comment preservation
7207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7208#[cfg_attr(feature = "bindings", derive(TS))]
7209pub struct SqlComment {
7210    pub text: String,
7211    pub is_block: bool,
7212}
7213
7214// ============================================================================
7215// Additional Predicate types
7216// ============================================================================
7217
7218/// SIMILAR TO expression
7219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7220#[cfg_attr(feature = "bindings", derive(TS))]
7221pub struct SimilarToExpr {
7222    pub this: Expression,
7223    pub pattern: Expression,
7224    pub escape: Option<Expression>,
7225    pub not: bool,
7226}
7227
7228/// ANY / ALL quantified expression
7229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7230#[cfg_attr(feature = "bindings", derive(TS))]
7231pub struct QuantifiedExpr {
7232    pub this: Expression,
7233    pub subquery: Expression,
7234    pub op: Option<QuantifiedOp>,
7235}
7236
7237/// Comparison operator for quantified expressions
7238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7239#[cfg_attr(feature = "bindings", derive(TS))]
7240pub enum QuantifiedOp {
7241    Eq,
7242    Neq,
7243    Lt,
7244    Lte,
7245    Gt,
7246    Gte,
7247}
7248
7249/// OVERLAPS expression
7250/// Supports two forms:
7251/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7252/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7254#[cfg_attr(feature = "bindings", derive(TS))]
7255pub struct OverlapsExpr {
7256    /// Left operand for simple binary form
7257    #[serde(skip_serializing_if = "Option::is_none")]
7258    pub this: Option<Expression>,
7259    /// Right operand for simple binary form
7260    #[serde(skip_serializing_if = "Option::is_none")]
7261    pub expression: Option<Expression>,
7262    /// Left range start for full ANSI form
7263    #[serde(skip_serializing_if = "Option::is_none")]
7264    pub left_start: Option<Expression>,
7265    /// Left range end for full ANSI form
7266    #[serde(skip_serializing_if = "Option::is_none")]
7267    pub left_end: Option<Expression>,
7268    /// Right range start for full ANSI form
7269    #[serde(skip_serializing_if = "Option::is_none")]
7270    pub right_start: Option<Expression>,
7271    /// Right range end for full ANSI form
7272    #[serde(skip_serializing_if = "Option::is_none")]
7273    pub right_end: Option<Expression>,
7274}
7275
7276// ============================================================================
7277// Array/Struct/Map access
7278// ============================================================================
7279
7280/// Subscript access (array[index] or map[key])
7281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7282#[cfg_attr(feature = "bindings", derive(TS))]
7283pub struct Subscript {
7284    pub this: Expression,
7285    pub index: Expression,
7286}
7287
7288/// Dot access (struct.field)
7289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7290#[cfg_attr(feature = "bindings", derive(TS))]
7291pub struct DotAccess {
7292    pub this: Expression,
7293    pub field: Identifier,
7294}
7295
7296/// Method call (expr.method(args))
7297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7298#[cfg_attr(feature = "bindings", derive(TS))]
7299pub struct MethodCall {
7300    pub this: Expression,
7301    pub method: Identifier,
7302    pub args: Vec<Expression>,
7303}
7304
7305/// Array slice (array[start:end])
7306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7307#[cfg_attr(feature = "bindings", derive(TS))]
7308pub struct ArraySlice {
7309    pub this: Expression,
7310    pub start: Option<Expression>,
7311    pub end: Option<Expression>,
7312}
7313
7314// ============================================================================
7315// DDL (Data Definition Language) Statements
7316// ============================================================================
7317
7318/// ON COMMIT behavior for temporary tables
7319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7320#[cfg_attr(feature = "bindings", derive(TS))]
7321pub enum OnCommit {
7322    /// ON COMMIT PRESERVE ROWS
7323    PreserveRows,
7324    /// ON COMMIT DELETE ROWS
7325    DeleteRows,
7326}
7327
7328/// CREATE TABLE statement
7329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7330#[cfg_attr(feature = "bindings", derive(TS))]
7331pub struct CreateTable {
7332    pub name: TableRef,
7333    /// ClickHouse: ON CLUSTER clause for distributed DDL
7334    #[serde(default, skip_serializing_if = "Option::is_none")]
7335    pub on_cluster: Option<OnCluster>,
7336    pub columns: Vec<ColumnDef>,
7337    pub constraints: Vec<TableConstraint>,
7338    pub if_not_exists: bool,
7339    pub temporary: bool,
7340    pub or_replace: bool,
7341    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7342    #[serde(default, skip_serializing_if = "Option::is_none")]
7343    pub table_modifier: Option<String>,
7344    pub as_select: Option<Expression>,
7345    /// Whether the AS SELECT was wrapped in parentheses
7346    #[serde(default)]
7347    pub as_select_parenthesized: bool,
7348    /// ON COMMIT behavior for temporary tables
7349    #[serde(default)]
7350    pub on_commit: Option<OnCommit>,
7351    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7352    #[serde(default)]
7353    pub clone_source: Option<TableRef>,
7354    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7355    #[serde(default, skip_serializing_if = "Option::is_none")]
7356    pub clone_at_clause: Option<Expression>,
7357    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7358    #[serde(default)]
7359    pub is_copy: bool,
7360    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7361    #[serde(default)]
7362    pub shallow_clone: bool,
7363    /// Whether this is an explicit DEEP CLONE (Databricks/Delta Lake)
7364    #[serde(default)]
7365    pub deep_clone: bool,
7366    /// Leading comments before the statement
7367    #[serde(default)]
7368    pub leading_comments: Vec<String>,
7369    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7370    #[serde(default)]
7371    pub with_properties: Vec<(String, String)>,
7372    /// Teradata: table options after name before columns (comma-separated)
7373    #[serde(default)]
7374    pub teradata_post_name_options: Vec<String>,
7375    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7376    #[serde(default)]
7377    pub with_data: Option<bool>,
7378    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7379    #[serde(default)]
7380    pub with_statistics: Option<bool>,
7381    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7382    #[serde(default)]
7383    pub teradata_indexes: Vec<TeradataIndex>,
7384    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7385    #[serde(default)]
7386    pub with_cte: Option<With>,
7387    /// Table properties like DEFAULT COLLATE (BigQuery)
7388    #[serde(default)]
7389    pub properties: Vec<Expression>,
7390    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7391    #[serde(default, skip_serializing_if = "Option::is_none")]
7392    pub partition_of: Option<Expression>,
7393    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7394    #[serde(default)]
7395    pub post_table_properties: Vec<Expression>,
7396    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7397    #[serde(default)]
7398    pub mysql_table_options: Vec<(String, String)>,
7399    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7400    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7401    pub inherits: Vec<TableRef>,
7402    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7403    #[serde(default, skip_serializing_if = "Option::is_none")]
7404    pub on_property: Option<OnProperty>,
7405    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7406    #[serde(default)]
7407    pub copy_grants: bool,
7408    /// Snowflake: USING TEMPLATE expression for schema inference
7409    #[serde(default, skip_serializing_if = "Option::is_none")]
7410    pub using_template: Option<Box<Expression>>,
7411    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7412    #[serde(default, skip_serializing_if = "Option::is_none")]
7413    pub rollup: Option<RollupProperty>,
7414    /// ClickHouse: UUID 'xxx' clause after table name
7415    #[serde(default, skip_serializing_if = "Option::is_none")]
7416    pub uuid: Option<String>,
7417    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7418    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7419    /// could appear in other engines.
7420    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7421    pub with_partition_columns: Vec<ColumnDef>,
7422    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7423    /// for external tables that reference a Cloud Resource connection.
7424    #[serde(default, skip_serializing_if = "Option::is_none")]
7425    pub with_connection: Option<TableRef>,
7426}
7427
7428/// Teradata index specification for CREATE TABLE
7429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7430#[cfg_attr(feature = "bindings", derive(TS))]
7431pub struct TeradataIndex {
7432    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7433    pub kind: TeradataIndexKind,
7434    /// Optional index name
7435    pub name: Option<String>,
7436    /// Optional column list
7437    pub columns: Vec<String>,
7438}
7439
7440/// Kind of Teradata index
7441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7442#[cfg_attr(feature = "bindings", derive(TS))]
7443pub enum TeradataIndexKind {
7444    /// NO PRIMARY INDEX
7445    NoPrimary,
7446    /// PRIMARY INDEX
7447    Primary,
7448    /// PRIMARY AMP INDEX
7449    PrimaryAmp,
7450    /// UNIQUE INDEX
7451    Unique,
7452    /// UNIQUE PRIMARY INDEX
7453    UniquePrimary,
7454    /// INDEX (secondary, non-primary)
7455    Secondary,
7456}
7457
7458impl CreateTable {
7459    pub fn new(name: impl Into<String>) -> Self {
7460        Self {
7461            name: TableRef::new(name),
7462            on_cluster: None,
7463            columns: Vec::new(),
7464            constraints: Vec::new(),
7465            if_not_exists: false,
7466            temporary: false,
7467            or_replace: false,
7468            table_modifier: None,
7469            as_select: None,
7470            as_select_parenthesized: false,
7471            on_commit: None,
7472            clone_source: None,
7473            clone_at_clause: None,
7474            shallow_clone: false,
7475            deep_clone: false,
7476            is_copy: false,
7477            leading_comments: Vec::new(),
7478            with_properties: Vec::new(),
7479            teradata_post_name_options: Vec::new(),
7480            with_data: None,
7481            with_statistics: None,
7482            teradata_indexes: Vec::new(),
7483            with_cte: None,
7484            properties: Vec::new(),
7485            partition_of: None,
7486            post_table_properties: Vec::new(),
7487            mysql_table_options: Vec::new(),
7488            inherits: Vec::new(),
7489            on_property: None,
7490            copy_grants: false,
7491            using_template: None,
7492            rollup: None,
7493            uuid: None,
7494            with_partition_columns: Vec::new(),
7495            with_connection: None,
7496        }
7497    }
7498}
7499
7500/// Sort order for PRIMARY KEY ASC/DESC
7501#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7502#[cfg_attr(feature = "bindings", derive(TS))]
7503pub enum SortOrder {
7504    Asc,
7505    Desc,
7506}
7507
7508/// Type of column constraint for tracking order
7509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7510#[cfg_attr(feature = "bindings", derive(TS))]
7511pub enum ConstraintType {
7512    NotNull,
7513    Null,
7514    PrimaryKey,
7515    Unique,
7516    Default,
7517    AutoIncrement,
7518    Collate,
7519    Comment,
7520    References,
7521    Check,
7522    GeneratedAsIdentity,
7523    /// Snowflake: TAG (key='value', ...)
7524    Tags,
7525    /// Computed/generated column
7526    ComputedColumn,
7527    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7528    GeneratedAsRow,
7529    /// MySQL: ON UPDATE expression
7530    OnUpdate,
7531    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7532    Path,
7533    /// Redshift: ENCODE encoding_type
7534    Encode,
7535}
7536
7537/// Column definition in CREATE TABLE
7538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7539#[cfg_attr(feature = "bindings", derive(TS))]
7540pub struct ColumnDef {
7541    pub name: Identifier,
7542    pub data_type: DataType,
7543    pub nullable: Option<bool>,
7544    pub default: Option<Expression>,
7545    pub primary_key: bool,
7546    /// Sort order for PRIMARY KEY (ASC/DESC)
7547    #[serde(default)]
7548    pub primary_key_order: Option<SortOrder>,
7549    pub unique: bool,
7550    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7551    #[serde(default)]
7552    pub unique_nulls_not_distinct: bool,
7553    pub auto_increment: bool,
7554    pub comment: Option<String>,
7555    pub constraints: Vec<ColumnConstraint>,
7556    /// Track original order of constraints for accurate regeneration
7557    #[serde(default)]
7558    pub constraint_order: Vec<ConstraintType>,
7559    /// Teradata: FORMAT 'pattern'
7560    #[serde(default)]
7561    pub format: Option<String>,
7562    /// Teradata: TITLE 'title'
7563    #[serde(default)]
7564    pub title: Option<String>,
7565    /// Teradata: INLINE LENGTH n
7566    #[serde(default)]
7567    pub inline_length: Option<u64>,
7568    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7569    #[serde(default)]
7570    pub compress: Option<Vec<Expression>>,
7571    /// Teradata: CHARACTER SET name
7572    #[serde(default)]
7573    pub character_set: Option<String>,
7574    /// Teradata: UPPERCASE
7575    #[serde(default)]
7576    pub uppercase: bool,
7577    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7578    #[serde(default)]
7579    pub casespecific: Option<bool>,
7580    /// Snowflake: AUTOINCREMENT START value
7581    #[serde(default)]
7582    pub auto_increment_start: Option<Box<Expression>>,
7583    /// Snowflake: AUTOINCREMENT INCREMENT value
7584    #[serde(default)]
7585    pub auto_increment_increment: Option<Box<Expression>>,
7586    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7587    #[serde(default)]
7588    pub auto_increment_order: Option<bool>,
7589    /// MySQL: UNSIGNED modifier
7590    #[serde(default)]
7591    pub unsigned: bool,
7592    /// MySQL: ZEROFILL modifier
7593    #[serde(default)]
7594    pub zerofill: bool,
7595    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7596    #[serde(default, skip_serializing_if = "Option::is_none")]
7597    pub on_update: Option<Expression>,
7598    /// MySQL: column VISIBLE/INVISIBLE modifier.
7599    #[serde(default, skip_serializing_if = "Option::is_none")]
7600    pub visible: Option<bool>,
7601    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7602    #[serde(default, skip_serializing_if = "Option::is_none")]
7603    pub unique_constraint_name: Option<String>,
7604    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7605    #[serde(default, skip_serializing_if = "Option::is_none")]
7606    pub not_null_constraint_name: Option<String>,
7607    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7608    #[serde(default, skip_serializing_if = "Option::is_none")]
7609    pub primary_key_constraint_name: Option<String>,
7610    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7611    #[serde(default, skip_serializing_if = "Option::is_none")]
7612    pub check_constraint_name: Option<String>,
7613    /// BigQuery: OPTIONS (key=value, ...) on column
7614    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7615    pub options: Vec<Expression>,
7616    /// SQLite: Column definition without explicit type
7617    #[serde(default)]
7618    pub no_type: bool,
7619    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7620    #[serde(default, skip_serializing_if = "Option::is_none")]
7621    pub encoding: Option<String>,
7622    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7623    #[serde(default, skip_serializing_if = "Option::is_none")]
7624    pub codec: Option<String>,
7625    /// ClickHouse: EPHEMERAL [expr] modifier
7626    #[serde(default, skip_serializing_if = "Option::is_none")]
7627    pub ephemeral: Option<Option<Box<Expression>>>,
7628    /// ClickHouse: MATERIALIZED expr modifier
7629    #[serde(default, skip_serializing_if = "Option::is_none")]
7630    pub materialized_expr: Option<Box<Expression>>,
7631    /// ClickHouse: ALIAS expr modifier
7632    #[serde(default, skip_serializing_if = "Option::is_none")]
7633    pub alias_expr: Option<Box<Expression>>,
7634    /// ClickHouse: TTL expr modifier on columns
7635    #[serde(default, skip_serializing_if = "Option::is_none")]
7636    pub ttl_expr: Option<Box<Expression>>,
7637    /// TSQL: NOT FOR REPLICATION
7638    #[serde(default)]
7639    pub not_for_replication: bool,
7640}
7641
7642impl ColumnDef {
7643    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7644        Self {
7645            name: Identifier::new(name),
7646            data_type,
7647            nullable: None,
7648            default: None,
7649            primary_key: false,
7650            primary_key_order: None,
7651            unique: false,
7652            unique_nulls_not_distinct: false,
7653            auto_increment: false,
7654            comment: None,
7655            constraints: Vec::new(),
7656            constraint_order: Vec::new(),
7657            format: None,
7658            title: None,
7659            inline_length: None,
7660            compress: None,
7661            character_set: None,
7662            uppercase: false,
7663            casespecific: None,
7664            auto_increment_start: None,
7665            auto_increment_increment: None,
7666            auto_increment_order: None,
7667            unsigned: false,
7668            zerofill: false,
7669            on_update: None,
7670            visible: None,
7671            unique_constraint_name: None,
7672            not_null_constraint_name: None,
7673            primary_key_constraint_name: None,
7674            check_constraint_name: None,
7675            options: Vec::new(),
7676            no_type: false,
7677            encoding: None,
7678            codec: None,
7679            ephemeral: None,
7680            materialized_expr: None,
7681            alias_expr: None,
7682            ttl_expr: None,
7683            not_for_replication: false,
7684        }
7685    }
7686}
7687
7688/// Column-level constraint
7689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7690#[cfg_attr(feature = "bindings", derive(TS))]
7691pub enum ColumnConstraint {
7692    NotNull,
7693    Null,
7694    Unique,
7695    PrimaryKey,
7696    Default(Expression),
7697    Check(Expression),
7698    References(ForeignKeyRef),
7699    GeneratedAsIdentity(GeneratedAsIdentity),
7700    Collate(Identifier),
7701    Comment(String),
7702    /// Snowflake: TAG (key='value', ...)
7703    Tags(Tags),
7704    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7705    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7706    ComputedColumn(ComputedColumn),
7707    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7708    GeneratedAsRow(GeneratedAsRow),
7709    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7710    Path(Expression),
7711}
7712
7713/// Computed/generated column constraint
7714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7715#[cfg_attr(feature = "bindings", derive(TS))]
7716pub struct ComputedColumn {
7717    /// The expression that computes the column value
7718    pub expression: Box<Expression>,
7719    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7720    #[serde(default)]
7721    pub persisted: bool,
7722    /// NOT NULL (TSQL computed columns)
7723    #[serde(default)]
7724    pub not_null: bool,
7725    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7726    /// When None, defaults to dialect-appropriate output
7727    #[serde(default)]
7728    pub persistence_kind: Option<String>,
7729    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7730    #[serde(default, skip_serializing_if = "Option::is_none")]
7731    pub data_type: Option<DataType>,
7732}
7733
7734/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7736#[cfg_attr(feature = "bindings", derive(TS))]
7737pub struct GeneratedAsRow {
7738    /// true = ROW START, false = ROW END
7739    pub start: bool,
7740    /// HIDDEN modifier
7741    #[serde(default)]
7742    pub hidden: bool,
7743}
7744
7745/// Generated identity column constraint
7746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7747#[cfg_attr(feature = "bindings", derive(TS))]
7748pub struct GeneratedAsIdentity {
7749    /// True for ALWAYS, False for BY DEFAULT
7750    pub always: bool,
7751    /// ON NULL (only valid with BY DEFAULT)
7752    pub on_null: bool,
7753    /// START WITH value
7754    pub start: Option<Box<Expression>>,
7755    /// INCREMENT BY value
7756    pub increment: Option<Box<Expression>>,
7757    /// MINVALUE
7758    pub minvalue: Option<Box<Expression>>,
7759    /// MAXVALUE
7760    pub maxvalue: Option<Box<Expression>>,
7761    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7762    pub cycle: Option<bool>,
7763}
7764
7765/// Constraint modifiers (shared between table-level constraints)
7766#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7767#[cfg_attr(feature = "bindings", derive(TS))]
7768pub struct ConstraintModifiers {
7769    /// ENFORCED / NOT ENFORCED
7770    pub enforced: Option<bool>,
7771    /// DEFERRABLE / NOT DEFERRABLE
7772    pub deferrable: Option<bool>,
7773    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7774    pub initially_deferred: Option<bool>,
7775    /// NORELY (Oracle)
7776    pub norely: bool,
7777    /// RELY (Oracle)
7778    pub rely: bool,
7779    /// USING index type (MySQL): BTREE or HASH
7780    #[serde(default)]
7781    pub using: Option<String>,
7782    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7783    #[serde(default)]
7784    pub using_before_columns: bool,
7785    /// MySQL index COMMENT 'text'
7786    #[serde(default, skip_serializing_if = "Option::is_none")]
7787    pub comment: Option<String>,
7788    /// MySQL index VISIBLE/INVISIBLE
7789    #[serde(default, skip_serializing_if = "Option::is_none")]
7790    pub visible: Option<bool>,
7791    /// MySQL ENGINE_ATTRIBUTE = 'value'
7792    #[serde(default, skip_serializing_if = "Option::is_none")]
7793    pub engine_attribute: Option<String>,
7794    /// MySQL WITH PARSER name
7795    #[serde(default, skip_serializing_if = "Option::is_none")]
7796    pub with_parser: Option<String>,
7797    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7798    #[serde(default)]
7799    pub not_valid: bool,
7800    /// TSQL CLUSTERED/NONCLUSTERED modifier
7801    #[serde(default, skip_serializing_if = "Option::is_none")]
7802    pub clustered: Option<String>,
7803    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7804    #[serde(default, skip_serializing_if = "Option::is_none")]
7805    pub on_conflict: Option<String>,
7806    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7807    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7808    pub with_options: Vec<(String, String)>,
7809    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7810    #[serde(default, skip_serializing_if = "Option::is_none")]
7811    pub on_filegroup: Option<Identifier>,
7812}
7813
7814/// Table-level constraint
7815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7816#[cfg_attr(feature = "bindings", derive(TS))]
7817pub enum TableConstraint {
7818    PrimaryKey {
7819        name: Option<Identifier>,
7820        columns: Vec<Identifier>,
7821        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7822        #[serde(default)]
7823        include_columns: Vec<Identifier>,
7824        #[serde(default)]
7825        modifiers: ConstraintModifiers,
7826        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7827        #[serde(default)]
7828        has_constraint_keyword: bool,
7829    },
7830    Unique {
7831        name: Option<Identifier>,
7832        columns: Vec<Identifier>,
7833        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7834        #[serde(default)]
7835        columns_parenthesized: bool,
7836        #[serde(default)]
7837        modifiers: ConstraintModifiers,
7838        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7839        #[serde(default)]
7840        has_constraint_keyword: bool,
7841        /// PostgreSQL 15+: NULLS NOT DISTINCT
7842        #[serde(default)]
7843        nulls_not_distinct: bool,
7844    },
7845    ForeignKey {
7846        name: Option<Identifier>,
7847        columns: Vec<Identifier>,
7848        #[serde(default)]
7849        references: Option<ForeignKeyRef>,
7850        /// ON DELETE action when REFERENCES is absent
7851        #[serde(default)]
7852        on_delete: Option<ReferentialAction>,
7853        /// ON UPDATE action when REFERENCES is absent
7854        #[serde(default)]
7855        on_update: Option<ReferentialAction>,
7856        #[serde(default)]
7857        modifiers: ConstraintModifiers,
7858    },
7859    Check {
7860        name: Option<Identifier>,
7861        expression: Expression,
7862        #[serde(default)]
7863        modifiers: ConstraintModifiers,
7864    },
7865    /// ClickHouse ASSUME constraint (query optimization assumption)
7866    Assume {
7867        name: Option<Identifier>,
7868        expression: Expression,
7869    },
7870    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7871    Default {
7872        name: Option<Identifier>,
7873        expression: Expression,
7874        column: Identifier,
7875    },
7876    /// INDEX / KEY constraint (MySQL)
7877    Index {
7878        name: Option<Identifier>,
7879        columns: Vec<Identifier>,
7880        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7881        #[serde(default)]
7882        kind: Option<String>,
7883        #[serde(default)]
7884        modifiers: ConstraintModifiers,
7885        /// True if KEY keyword was used instead of INDEX
7886        #[serde(default)]
7887        use_key_keyword: bool,
7888        /// ClickHouse: indexed expression (instead of columns)
7889        #[serde(default, skip_serializing_if = "Option::is_none")]
7890        expression: Option<Box<Expression>>,
7891        /// ClickHouse: TYPE type_func(args)
7892        #[serde(default, skip_serializing_if = "Option::is_none")]
7893        index_type: Option<Box<Expression>>,
7894        /// ClickHouse: GRANULARITY n
7895        #[serde(default, skip_serializing_if = "Option::is_none")]
7896        granularity: Option<Box<Expression>>,
7897    },
7898    /// ClickHouse PROJECTION definition
7899    Projection {
7900        name: Identifier,
7901        expression: Expression,
7902    },
7903    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7904    Like {
7905        source: TableRef,
7906        /// Options as (INCLUDING|EXCLUDING, property) pairs
7907        options: Vec<(LikeOptionAction, String)>,
7908    },
7909    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7910    PeriodForSystemTime {
7911        start_col: Identifier,
7912        end_col: Identifier,
7913    },
7914    /// PostgreSQL EXCLUDE constraint
7915    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7916    Exclude {
7917        name: Option<Identifier>,
7918        /// Index access method (gist, btree, etc.)
7919        #[serde(default)]
7920        using: Option<String>,
7921        /// Elements: (expression, operator) pairs
7922        elements: Vec<ExcludeElement>,
7923        /// INCLUDE columns
7924        #[serde(default)]
7925        include_columns: Vec<Identifier>,
7926        /// WHERE predicate
7927        #[serde(default)]
7928        where_clause: Option<Box<Expression>>,
7929        /// WITH (storage_parameters)
7930        #[serde(default)]
7931        with_params: Vec<(String, String)>,
7932        /// USING INDEX TABLESPACE tablespace_name
7933        #[serde(default)]
7934        using_index_tablespace: Option<String>,
7935        #[serde(default)]
7936        modifiers: ConstraintModifiers,
7937    },
7938    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7939    Tags(Tags),
7940    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7941    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7942    /// for all deferrable constraints in the table
7943    InitiallyDeferred {
7944        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7945        deferred: bool,
7946    },
7947}
7948
7949/// Element in an EXCLUDE constraint: expression WITH operator
7950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7951#[cfg_attr(feature = "bindings", derive(TS))]
7952pub struct ExcludeElement {
7953    /// The column expression (may include operator class, ordering, nulls)
7954    pub expression: String,
7955    /// The operator (e.g., &&, =)
7956    pub operator: String,
7957}
7958
7959/// Action for LIKE clause options
7960#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7961#[cfg_attr(feature = "bindings", derive(TS))]
7962pub enum LikeOptionAction {
7963    Including,
7964    Excluding,
7965}
7966
7967/// MATCH type for foreign keys
7968#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7969#[cfg_attr(feature = "bindings", derive(TS))]
7970pub enum MatchType {
7971    Full,
7972    Partial,
7973    Simple,
7974}
7975
7976/// Foreign key reference
7977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7978#[cfg_attr(feature = "bindings", derive(TS))]
7979pub struct ForeignKeyRef {
7980    pub table: TableRef,
7981    pub columns: Vec<Identifier>,
7982    pub on_delete: Option<ReferentialAction>,
7983    pub on_update: Option<ReferentialAction>,
7984    /// True if ON UPDATE appears before ON DELETE in the original SQL
7985    #[serde(default)]
7986    pub on_update_first: bool,
7987    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7988    #[serde(default)]
7989    pub match_type: Option<MatchType>,
7990    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7991    #[serde(default)]
7992    pub match_after_actions: bool,
7993    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7994    #[serde(default)]
7995    pub constraint_name: Option<String>,
7996    /// DEFERRABLE / NOT DEFERRABLE
7997    #[serde(default)]
7998    pub deferrable: Option<bool>,
7999    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
8000    #[serde(default)]
8001    pub has_foreign_key_keywords: bool,
8002}
8003
8004/// Referential action for foreign keys
8005#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8006#[cfg_attr(feature = "bindings", derive(TS))]
8007pub enum ReferentialAction {
8008    Cascade,
8009    SetNull,
8010    SetDefault,
8011    Restrict,
8012    NoAction,
8013}
8014
8015/// DROP TABLE statement
8016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8017#[cfg_attr(feature = "bindings", derive(TS))]
8018pub struct DropTable {
8019    pub names: Vec<TableRef>,
8020    pub if_exists: bool,
8021    pub cascade: bool,
8022    /// Oracle: CASCADE CONSTRAINTS
8023    #[serde(default)]
8024    pub cascade_constraints: bool,
8025    /// Oracle: PURGE
8026    #[serde(default)]
8027    pub purge: bool,
8028    /// Comments that appear before the DROP keyword (e.g., leading line comments)
8029    #[serde(default)]
8030    pub leading_comments: Vec<String>,
8031    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
8032    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
8033    #[serde(default, skip_serializing_if = "Option::is_none")]
8034    pub object_id_args: Option<String>,
8035    /// ClickHouse: SYNC modifier
8036    #[serde(default)]
8037    pub sync: bool,
8038    /// Snowflake: DROP ICEBERG TABLE
8039    #[serde(default)]
8040    pub iceberg: bool,
8041    /// RESTRICT modifier (opposite of CASCADE)
8042    #[serde(default)]
8043    pub restrict: bool,
8044}
8045
8046impl DropTable {
8047    pub fn new(name: impl Into<String>) -> Self {
8048        Self {
8049            names: vec![TableRef::new(name)],
8050            if_exists: false,
8051            cascade: false,
8052            cascade_constraints: false,
8053            purge: false,
8054            leading_comments: Vec::new(),
8055            object_id_args: None,
8056            sync: false,
8057            iceberg: false,
8058            restrict: false,
8059        }
8060    }
8061}
8062
8063/// UNDROP object statement (Snowflake, ClickHouse)
8064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8065#[cfg_attr(feature = "bindings", derive(TS))]
8066pub struct Undrop {
8067    /// The object kind, e.g. "TABLE", "SCHEMA", "DATABASE", "DYNAMIC TABLE"
8068    pub kind: String,
8069    /// The object name
8070    pub name: TableRef,
8071    /// IF EXISTS clause
8072    #[serde(default)]
8073    pub if_exists: bool,
8074    /// Snowflake: optional RENAME TO target
8075    #[serde(default, skip_serializing_if = "Option::is_none")]
8076    pub rename_to: Option<TableRef>,
8077}
8078
8079/// ALTER TABLE statement
8080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8081#[cfg_attr(feature = "bindings", derive(TS))]
8082pub struct AlterTable {
8083    pub name: TableRef,
8084    pub actions: Vec<AlterTableAction>,
8085    /// IF EXISTS clause
8086    #[serde(default)]
8087    pub if_exists: bool,
8088    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8089    #[serde(default, skip_serializing_if = "Option::is_none")]
8090    pub algorithm: Option<String>,
8091    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8092    #[serde(default, skip_serializing_if = "Option::is_none")]
8093    pub lock: Option<String>,
8094    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8095    #[serde(default, skip_serializing_if = "Option::is_none")]
8096    pub with_check: Option<String>,
8097    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8098    #[serde(default, skip_serializing_if = "Option::is_none")]
8099    pub partition: Option<Vec<(Identifier, Expression)>>,
8100    /// ClickHouse: ON CLUSTER clause for distributed DDL
8101    #[serde(default, skip_serializing_if = "Option::is_none")]
8102    pub on_cluster: Option<OnCluster>,
8103    /// Snowflake: ALTER ICEBERG TABLE
8104    #[serde(default, skip_serializing_if = "Option::is_none")]
8105    pub table_modifier: Option<String>,
8106}
8107
8108impl AlterTable {
8109    pub fn new(name: impl Into<String>) -> Self {
8110        Self {
8111            name: TableRef::new(name),
8112            actions: Vec::new(),
8113            if_exists: false,
8114            algorithm: None,
8115            lock: None,
8116            with_check: None,
8117            partition: None,
8118            on_cluster: None,
8119            table_modifier: None,
8120        }
8121    }
8122}
8123
8124/// Column position for ADD COLUMN (MySQL/MariaDB)
8125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8126#[cfg_attr(feature = "bindings", derive(TS))]
8127pub enum ColumnPosition {
8128    First,
8129    After(Identifier),
8130}
8131
8132/// Actions for ALTER TABLE
8133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8134#[cfg_attr(feature = "bindings", derive(TS))]
8135pub enum AlterTableAction {
8136    AddColumn {
8137        column: ColumnDef,
8138        if_not_exists: bool,
8139        position: Option<ColumnPosition>,
8140    },
8141    DropColumn {
8142        name: Identifier,
8143        if_exists: bool,
8144        cascade: bool,
8145    },
8146    RenameColumn {
8147        old_name: Identifier,
8148        new_name: Identifier,
8149        if_exists: bool,
8150    },
8151    AlterColumn {
8152        name: Identifier,
8153        action: AlterColumnAction,
8154        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8155        #[serde(default)]
8156        use_modify_keyword: bool,
8157    },
8158    RenameTable(TableRef),
8159    AddConstraint(TableConstraint),
8160    DropConstraint {
8161        name: Identifier,
8162        if_exists: bool,
8163    },
8164    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8165    DropForeignKey {
8166        name: Identifier,
8167    },
8168    /// DROP PARTITION action (Hive/BigQuery)
8169    DropPartition {
8170        /// List of partitions to drop (each partition is a list of key=value pairs)
8171        partitions: Vec<Vec<(Identifier, Expression)>>,
8172        if_exists: bool,
8173    },
8174    /// ADD PARTITION action (Hive/Spark)
8175    AddPartition {
8176        /// The partition expression
8177        partition: Expression,
8178        if_not_exists: bool,
8179        location: Option<Expression>,
8180    },
8181    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8182    Delete {
8183        where_clause: Expression,
8184    },
8185    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8186    SwapWith(TableRef),
8187    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8188    SetProperty {
8189        properties: Vec<(String, Expression)>,
8190    },
8191    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8192    UnsetProperty {
8193        properties: Vec<String>,
8194    },
8195    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8196    ClusterBy {
8197        expressions: Vec<Expression>,
8198    },
8199    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8200    SetTag {
8201        expressions: Vec<(String, Expression)>,
8202    },
8203    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8204    UnsetTag {
8205        names: Vec<String>,
8206    },
8207    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8208    SetOptions {
8209        expressions: Vec<Expression>,
8210    },
8211    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8212    AlterIndex {
8213        name: Identifier,
8214        visible: bool,
8215    },
8216    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8217    SetAttribute {
8218        attribute: String,
8219    },
8220    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8221    SetStageFileFormat {
8222        options: Option<Expression>,
8223    },
8224    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8225    SetStageCopyOptions {
8226        options: Option<Expression>,
8227    },
8228    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8229    AddColumns {
8230        columns: Vec<ColumnDef>,
8231        cascade: bool,
8232    },
8233    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8234    DropColumns {
8235        names: Vec<Identifier>,
8236    },
8237    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8238    /// In SingleStore, data_type can be omitted for simple column renames
8239    ChangeColumn {
8240        old_name: Identifier,
8241        new_name: Identifier,
8242        #[serde(default, skip_serializing_if = "Option::is_none")]
8243        data_type: Option<DataType>,
8244        comment: Option<String>,
8245        #[serde(default)]
8246        cascade: bool,
8247    },
8248    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8249    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8250    AlterSortKey {
8251        /// AUTO or NONE keyword
8252        this: Option<String>,
8253        /// Column list for (col1, col2) syntax
8254        expressions: Vec<Expression>,
8255        /// Whether COMPOUND keyword was present
8256        compound: bool,
8257    },
8258    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8259    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8260    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8261    AlterDistStyle {
8262        /// Distribution style: ALL, EVEN, AUTO, or KEY
8263        style: String,
8264        /// DISTKEY column (only when style is KEY)
8265        distkey: Option<Identifier>,
8266    },
8267    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8268    SetTableProperties {
8269        properties: Vec<(Expression, Expression)>,
8270    },
8271    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8272    SetLocation {
8273        location: String,
8274    },
8275    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8276    SetFileFormat {
8277        format: String,
8278    },
8279    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8280    ReplacePartition {
8281        partition: Expression,
8282        source: Option<Box<Expression>>,
8283    },
8284    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8285    Raw {
8286        sql: String,
8287    },
8288}
8289
8290/// Actions for ALTER COLUMN
8291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8292#[cfg_attr(feature = "bindings", derive(TS))]
8293pub enum AlterColumnAction {
8294    SetDataType {
8295        data_type: DataType,
8296        /// USING expression for type conversion (PostgreSQL)
8297        using: Option<Expression>,
8298        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8299        #[serde(default, skip_serializing_if = "Option::is_none")]
8300        collate: Option<String>,
8301    },
8302    SetDefault(Expression),
8303    DropDefault,
8304    SetNotNull,
8305    DropNotNull,
8306    /// Set column comment
8307    Comment(String),
8308    /// MySQL: SET VISIBLE
8309    SetVisible,
8310    /// MySQL: SET INVISIBLE
8311    SetInvisible,
8312}
8313
8314/// CREATE INDEX statement
8315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8316#[cfg_attr(feature = "bindings", derive(TS))]
8317pub struct CreateIndex {
8318    pub name: Identifier,
8319    pub table: TableRef,
8320    pub columns: Vec<IndexColumn>,
8321    pub unique: bool,
8322    pub if_not_exists: bool,
8323    pub using: Option<String>,
8324    /// TSQL CLUSTERED/NONCLUSTERED modifier
8325    #[serde(default)]
8326    pub clustered: Option<String>,
8327    /// PostgreSQL CONCURRENTLY modifier
8328    #[serde(default)]
8329    pub concurrently: bool,
8330    /// PostgreSQL WHERE clause for partial indexes
8331    #[serde(default)]
8332    pub where_clause: Option<Box<Expression>>,
8333    /// PostgreSQL INCLUDE columns
8334    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8335    pub include_columns: Vec<Identifier>,
8336    /// TSQL WITH options (e.g., allow_page_locks=on)
8337    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8338    pub with_options: Vec<(String, String)>,
8339    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8340    #[serde(default)]
8341    pub on_filegroup: Option<String>,
8342}
8343
8344impl CreateIndex {
8345    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8346        Self {
8347            name: Identifier::new(name),
8348            table: TableRef::new(table),
8349            columns: Vec::new(),
8350            unique: false,
8351            if_not_exists: false,
8352            using: None,
8353            clustered: None,
8354            concurrently: false,
8355            where_clause: None,
8356            include_columns: Vec::new(),
8357            with_options: Vec::new(),
8358            on_filegroup: None,
8359        }
8360    }
8361}
8362
8363/// Index column specification
8364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8365#[cfg_attr(feature = "bindings", derive(TS))]
8366pub struct IndexColumn {
8367    pub column: Identifier,
8368    pub desc: bool,
8369    /// Explicit ASC keyword was present
8370    #[serde(default)]
8371    pub asc: bool,
8372    pub nulls_first: Option<bool>,
8373    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8374    #[serde(default, skip_serializing_if = "Option::is_none")]
8375    pub opclass: Option<String>,
8376}
8377
8378/// DROP INDEX statement
8379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8380#[cfg_attr(feature = "bindings", derive(TS))]
8381pub struct DropIndex {
8382    pub name: TableRef,
8383    pub table: Option<TableRef>,
8384    pub if_exists: bool,
8385    /// PostgreSQL CONCURRENTLY modifier
8386    #[serde(default)]
8387    pub concurrently: bool,
8388}
8389
8390impl DropIndex {
8391    pub fn new(name: impl Into<String>) -> Self {
8392        Self {
8393            name: TableRef::new(name),
8394            table: None,
8395            if_exists: false,
8396            concurrently: false,
8397        }
8398    }
8399}
8400
8401/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8403#[cfg_attr(feature = "bindings", derive(TS))]
8404pub struct ViewColumn {
8405    pub name: Identifier,
8406    pub comment: Option<String>,
8407    /// BigQuery: OPTIONS (key=value, ...) on column
8408    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8409    pub options: Vec<Expression>,
8410}
8411
8412impl ViewColumn {
8413    pub fn new(name: impl Into<String>) -> Self {
8414        Self {
8415            name: Identifier::new(name),
8416            comment: None,
8417            options: Vec::new(),
8418        }
8419    }
8420
8421    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8422        Self {
8423            name: Identifier::new(name),
8424            comment: Some(comment.into()),
8425            options: Vec::new(),
8426        }
8427    }
8428}
8429
8430/// CREATE VIEW statement
8431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8432#[cfg_attr(feature = "bindings", derive(TS))]
8433pub struct CreateView {
8434    pub name: TableRef,
8435    pub columns: Vec<ViewColumn>,
8436    pub query: Expression,
8437    pub or_replace: bool,
8438    /// TSQL: CREATE OR ALTER
8439    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8440    pub or_alter: bool,
8441    pub if_not_exists: bool,
8442    pub materialized: bool,
8443    pub temporary: bool,
8444    /// Snowflake: SECURE VIEW
8445    #[serde(default)]
8446    pub secure: bool,
8447    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8448    #[serde(skip_serializing_if = "Option::is_none")]
8449    pub algorithm: Option<String>,
8450    /// MySQL: DEFINER=user@host
8451    #[serde(skip_serializing_if = "Option::is_none")]
8452    pub definer: Option<String>,
8453    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8454    #[serde(skip_serializing_if = "Option::is_none")]
8455    pub security: Option<FunctionSecurity>,
8456    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8457    #[serde(default = "default_true")]
8458    pub security_sql_style: bool,
8459    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8460    #[serde(default)]
8461    pub security_after_name: bool,
8462    /// Whether the query was parenthesized: AS (SELECT ...)
8463    #[serde(default)]
8464    pub query_parenthesized: bool,
8465    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8466    #[serde(skip_serializing_if = "Option::is_none")]
8467    pub locking_mode: Option<String>,
8468    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8469    #[serde(skip_serializing_if = "Option::is_none")]
8470    pub locking_access: Option<String>,
8471    /// Snowflake: COPY GRANTS
8472    #[serde(default)]
8473    pub copy_grants: bool,
8474    /// Snowflake: COMMENT = 'text'
8475    #[serde(skip_serializing_if = "Option::is_none", default)]
8476    pub comment: Option<String>,
8477    /// Snowflake: WITH ROW ACCESS POLICY ... clause
8478    #[serde(skip_serializing_if = "Option::is_none", default)]
8479    pub row_access_policy: Option<String>,
8480    /// Snowflake: TAG (name='value', ...)
8481    #[serde(default)]
8482    pub tags: Vec<(String, String)>,
8483    /// BigQuery: OPTIONS (key=value, ...)
8484    #[serde(default)]
8485    pub options: Vec<Expression>,
8486    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8487    #[serde(skip_serializing_if = "Option::is_none", default)]
8488    pub build: Option<String>,
8489    /// Doris: REFRESH property for materialized views
8490    #[serde(skip_serializing_if = "Option::is_none", default)]
8491    pub refresh: Option<Box<RefreshTriggerProperty>>,
8492    /// Doris: Schema with typed column definitions for materialized views
8493    /// This is used instead of `columns` when the view has typed column definitions
8494    #[serde(skip_serializing_if = "Option::is_none", default)]
8495    pub schema: Option<Box<Schema>>,
8496    /// Doris: KEY (columns) for materialized views
8497    #[serde(skip_serializing_if = "Option::is_none", default)]
8498    pub unique_key: Option<Box<UniqueKeyProperty>>,
8499    /// Redshift: WITH NO SCHEMA BINDING
8500    #[serde(default)]
8501    pub no_schema_binding: bool,
8502    /// Redshift: AUTO REFRESH YES|NO for materialized views
8503    #[serde(skip_serializing_if = "Option::is_none", default)]
8504    pub auto_refresh: Option<bool>,
8505    /// ClickHouse: POPULATE / EMPTY before AS in materialized views
8506    #[serde(skip_serializing_if = "Option::is_none", default)]
8507    pub clickhouse_population: Option<String>,
8508    /// ClickHouse: ON CLUSTER clause
8509    #[serde(default, skip_serializing_if = "Option::is_none")]
8510    pub on_cluster: Option<OnCluster>,
8511    /// ClickHouse: TO destination_table
8512    #[serde(default, skip_serializing_if = "Option::is_none")]
8513    pub to_table: Option<TableRef>,
8514    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8515    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8516    pub table_properties: Vec<Expression>,
8517}
8518
8519impl CreateView {
8520    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8521        Self {
8522            name: TableRef::new(name),
8523            columns: Vec::new(),
8524            query,
8525            or_replace: false,
8526            or_alter: false,
8527            if_not_exists: false,
8528            materialized: false,
8529            temporary: false,
8530            secure: false,
8531            algorithm: None,
8532            definer: None,
8533            security: None,
8534            security_sql_style: true,
8535            security_after_name: false,
8536            query_parenthesized: false,
8537            locking_mode: None,
8538            locking_access: None,
8539            copy_grants: false,
8540            comment: None,
8541            row_access_policy: None,
8542            tags: Vec::new(),
8543            options: Vec::new(),
8544            build: None,
8545            refresh: None,
8546            schema: None,
8547            unique_key: None,
8548            no_schema_binding: false,
8549            auto_refresh: None,
8550            clickhouse_population: None,
8551            on_cluster: None,
8552            to_table: None,
8553            table_properties: Vec::new(),
8554        }
8555    }
8556}
8557
8558/// DROP VIEW statement
8559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8560#[cfg_attr(feature = "bindings", derive(TS))]
8561pub struct DropView {
8562    pub name: TableRef,
8563    pub if_exists: bool,
8564    pub materialized: bool,
8565}
8566
8567impl DropView {
8568    pub fn new(name: impl Into<String>) -> Self {
8569        Self {
8570            name: TableRef::new(name),
8571            if_exists: false,
8572            materialized: false,
8573        }
8574    }
8575}
8576
8577/// TRUNCATE TABLE statement
8578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8579#[cfg_attr(feature = "bindings", derive(TS))]
8580pub struct Truncate {
8581    /// Target of TRUNCATE (TABLE vs DATABASE)
8582    #[serde(default)]
8583    pub target: TruncateTarget,
8584    /// IF EXISTS clause
8585    #[serde(default)]
8586    pub if_exists: bool,
8587    pub table: TableRef,
8588    /// ClickHouse: ON CLUSTER clause for distributed DDL
8589    #[serde(default, skip_serializing_if = "Option::is_none")]
8590    pub on_cluster: Option<OnCluster>,
8591    pub cascade: bool,
8592    /// Additional tables for multi-table TRUNCATE
8593    #[serde(default)]
8594    pub extra_tables: Vec<TruncateTableEntry>,
8595    /// RESTART IDENTITY or CONTINUE IDENTITY
8596    #[serde(default)]
8597    pub identity: Option<TruncateIdentity>,
8598    /// RESTRICT option (alternative to CASCADE)
8599    #[serde(default)]
8600    pub restrict: bool,
8601    /// Hive PARTITION clause: PARTITION(key=value, ...)
8602    #[serde(default, skip_serializing_if = "Option::is_none")]
8603    pub partition: Option<Box<Expression>>,
8604}
8605
8606/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8608#[cfg_attr(feature = "bindings", derive(TS))]
8609pub struct TruncateTableEntry {
8610    pub table: TableRef,
8611    /// Whether the table has a * suffix (inherit children)
8612    #[serde(default)]
8613    pub star: bool,
8614}
8615
8616/// TRUNCATE target type
8617#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8618#[cfg_attr(feature = "bindings", derive(TS))]
8619pub enum TruncateTarget {
8620    Table,
8621    Database,
8622}
8623
8624impl Default for TruncateTarget {
8625    fn default() -> Self {
8626        TruncateTarget::Table
8627    }
8628}
8629
8630/// TRUNCATE identity option
8631#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8632#[cfg_attr(feature = "bindings", derive(TS))]
8633pub enum TruncateIdentity {
8634    Restart,
8635    Continue,
8636}
8637
8638impl Truncate {
8639    pub fn new(table: impl Into<String>) -> Self {
8640        Self {
8641            target: TruncateTarget::Table,
8642            if_exists: false,
8643            table: TableRef::new(table),
8644            on_cluster: None,
8645            cascade: false,
8646            extra_tables: Vec::new(),
8647            identity: None,
8648            restrict: false,
8649            partition: None,
8650        }
8651    }
8652}
8653
8654/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8656#[cfg_attr(feature = "bindings", derive(TS))]
8657pub struct Use {
8658    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8659    pub kind: Option<UseKind>,
8660    /// The name of the object
8661    pub this: Identifier,
8662}
8663
8664/// Kind of USE statement
8665#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8666#[cfg_attr(feature = "bindings", derive(TS))]
8667pub enum UseKind {
8668    Database,
8669    Schema,
8670    Role,
8671    Warehouse,
8672    Catalog,
8673    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8674    SecondaryRoles,
8675}
8676
8677/// SET variable statement
8678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8679#[cfg_attr(feature = "bindings", derive(TS))]
8680pub struct SetStatement {
8681    /// The items being set
8682    pub items: Vec<SetItem>,
8683}
8684
8685/// A single SET item (variable assignment)
8686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8687#[cfg_attr(feature = "bindings", derive(TS))]
8688pub struct SetItem {
8689    /// The variable name
8690    pub name: Expression,
8691    /// The value to set
8692    pub value: Expression,
8693    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8694    pub kind: Option<String>,
8695    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8696    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8697    pub no_equals: bool,
8698}
8699
8700/// CACHE TABLE statement (Spark)
8701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8702#[cfg_attr(feature = "bindings", derive(TS))]
8703pub struct Cache {
8704    /// The table to cache
8705    pub table: Identifier,
8706    /// LAZY keyword - defer caching until first use
8707    pub lazy: bool,
8708    /// Optional OPTIONS clause (key-value pairs)
8709    pub options: Vec<(Expression, Expression)>,
8710    /// Optional AS clause with query
8711    pub query: Option<Expression>,
8712}
8713
8714/// UNCACHE TABLE statement (Spark)
8715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8716#[cfg_attr(feature = "bindings", derive(TS))]
8717pub struct Uncache {
8718    /// The table to uncache
8719    pub table: Identifier,
8720    /// IF EXISTS clause
8721    pub if_exists: bool,
8722}
8723
8724/// LOAD DATA statement (Hive)
8725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8726#[cfg_attr(feature = "bindings", derive(TS))]
8727pub struct LoadData {
8728    /// LOCAL keyword - load from local filesystem
8729    pub local: bool,
8730    /// The path to load data from (INPATH value)
8731    pub inpath: String,
8732    /// Whether to overwrite existing data
8733    pub overwrite: bool,
8734    /// The target table
8735    pub table: Expression,
8736    /// Optional PARTITION clause with key-value pairs
8737    pub partition: Vec<(Identifier, Expression)>,
8738    /// Optional INPUTFORMAT clause
8739    pub input_format: Option<String>,
8740    /// Optional SERDE clause
8741    pub serde: Option<String>,
8742}
8743
8744/// PRAGMA statement (SQLite)
8745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8746#[cfg_attr(feature = "bindings", derive(TS))]
8747pub struct Pragma {
8748    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8749    pub schema: Option<Identifier>,
8750    /// The pragma name
8751    pub name: Identifier,
8752    /// Optional value for assignment (PRAGMA name = value)
8753    pub value: Option<Expression>,
8754    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8755    pub args: Vec<Expression>,
8756    /// Whether this pragma should be generated using assignment syntax.
8757    #[serde(default)]
8758    pub use_assignment_syntax: bool,
8759}
8760
8761/// A privilege with optional column list for GRANT/REVOKE
8762/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8764#[cfg_attr(feature = "bindings", derive(TS))]
8765pub struct Privilege {
8766    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8767    pub name: String,
8768    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8769    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8770    pub columns: Vec<String>,
8771}
8772
8773/// Principal in GRANT/REVOKE (user, role, etc.)
8774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8775#[cfg_attr(feature = "bindings", derive(TS))]
8776pub struct GrantPrincipal {
8777    /// The name of the principal
8778    pub name: Identifier,
8779    /// Whether prefixed with ROLE keyword
8780    pub is_role: bool,
8781    /// Whether prefixed with GROUP keyword (Redshift)
8782    #[serde(default)]
8783    pub is_group: bool,
8784    /// Whether prefixed with SHARE keyword (Snowflake)
8785    #[serde(default)]
8786    pub is_share: bool,
8787}
8788
8789/// GRANT statement
8790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8791#[cfg_attr(feature = "bindings", derive(TS))]
8792pub struct Grant {
8793    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8794    pub privileges: Vec<Privilege>,
8795    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8796    pub kind: Option<String>,
8797    /// The object to grant on
8798    pub securable: Identifier,
8799    /// Function parameter types (for FUNCTION kind)
8800    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8801    pub function_params: Vec<String>,
8802    /// The grantees
8803    pub principals: Vec<GrantPrincipal>,
8804    /// WITH GRANT OPTION
8805    pub grant_option: bool,
8806    /// TSQL: AS principal (the grantor role)
8807    #[serde(default, skip_serializing_if = "Option::is_none")]
8808    pub as_principal: Option<Identifier>,
8809}
8810
8811/// REVOKE statement
8812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8813#[cfg_attr(feature = "bindings", derive(TS))]
8814pub struct Revoke {
8815    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8816    pub privileges: Vec<Privilege>,
8817    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8818    pub kind: Option<String>,
8819    /// The object to revoke from
8820    pub securable: Identifier,
8821    /// Function parameter types (for FUNCTION kind)
8822    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8823    pub function_params: Vec<String>,
8824    /// The grantees
8825    pub principals: Vec<GrantPrincipal>,
8826    /// GRANT OPTION FOR
8827    pub grant_option: bool,
8828    /// CASCADE
8829    pub cascade: bool,
8830    /// RESTRICT
8831    #[serde(default)]
8832    pub restrict: bool,
8833}
8834
8835/// COMMENT ON statement
8836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8837#[cfg_attr(feature = "bindings", derive(TS))]
8838pub struct Comment {
8839    /// The object being commented on
8840    pub this: Expression,
8841    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8842    pub kind: String,
8843    /// The comment text expression
8844    pub expression: Expression,
8845    /// IF EXISTS clause
8846    pub exists: bool,
8847    /// MATERIALIZED keyword
8848    pub materialized: bool,
8849}
8850
8851// ============================================================================
8852// Phase 4: Additional DDL Statements
8853// ============================================================================
8854
8855/// ALTER VIEW statement
8856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8857#[cfg_attr(feature = "bindings", derive(TS))]
8858pub struct AlterView {
8859    pub name: TableRef,
8860    pub actions: Vec<AlterViewAction>,
8861    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8862    #[serde(default, skip_serializing_if = "Option::is_none")]
8863    pub algorithm: Option<String>,
8864    /// MySQL: DEFINER = 'user'@'host'
8865    #[serde(default, skip_serializing_if = "Option::is_none")]
8866    pub definer: Option<String>,
8867    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8868    #[serde(default, skip_serializing_if = "Option::is_none")]
8869    pub sql_security: Option<String>,
8870    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8871    #[serde(default, skip_serializing_if = "Option::is_none")]
8872    pub with_option: Option<String>,
8873    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8874    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8875    pub columns: Vec<ViewColumn>,
8876}
8877
8878/// Actions for ALTER VIEW
8879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8880#[cfg_attr(feature = "bindings", derive(TS))]
8881pub enum AlterViewAction {
8882    /// Rename the view
8883    Rename(TableRef),
8884    /// Change owner
8885    OwnerTo(Identifier),
8886    /// Set schema
8887    SetSchema(Identifier),
8888    /// Set authorization (Trino/Presto)
8889    SetAuthorization(String),
8890    /// Alter column
8891    AlterColumn {
8892        name: Identifier,
8893        action: AlterColumnAction,
8894    },
8895    /// Redefine view as query (SELECT, UNION, etc.)
8896    AsSelect(Box<Expression>),
8897    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8898    SetTblproperties(Vec<(String, String)>),
8899    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8900    UnsetTblproperties(Vec<String>),
8901}
8902
8903impl AlterView {
8904    pub fn new(name: impl Into<String>) -> Self {
8905        Self {
8906            name: TableRef::new(name),
8907            actions: Vec::new(),
8908            algorithm: None,
8909            definer: None,
8910            sql_security: None,
8911            with_option: None,
8912            columns: Vec::new(),
8913        }
8914    }
8915}
8916
8917/// ALTER INDEX statement
8918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8919#[cfg_attr(feature = "bindings", derive(TS))]
8920pub struct AlterIndex {
8921    pub name: Identifier,
8922    pub table: Option<TableRef>,
8923    pub actions: Vec<AlterIndexAction>,
8924}
8925
8926/// Actions for ALTER INDEX
8927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8928#[cfg_attr(feature = "bindings", derive(TS))]
8929pub enum AlterIndexAction {
8930    /// Rename the index
8931    Rename(Identifier),
8932    /// Set tablespace
8933    SetTablespace(Identifier),
8934    /// Set visibility (MySQL)
8935    Visible(bool),
8936}
8937
8938impl AlterIndex {
8939    pub fn new(name: impl Into<String>) -> Self {
8940        Self {
8941            name: Identifier::new(name),
8942            table: None,
8943            actions: Vec::new(),
8944        }
8945    }
8946}
8947
8948/// CREATE SCHEMA statement
8949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8950#[cfg_attr(feature = "bindings", derive(TS))]
8951pub struct CreateSchema {
8952    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8953    pub name: Vec<Identifier>,
8954    pub if_not_exists: bool,
8955    pub authorization: Option<Identifier>,
8956    /// CLONE source parts, possibly dot-qualified
8957    #[serde(default)]
8958    pub clone_from: Option<Vec<Identifier>>,
8959    /// AT/BEFORE clause for time travel (Snowflake)
8960    #[serde(default)]
8961    pub at_clause: Option<Expression>,
8962    /// Schema properties like DEFAULT COLLATE
8963    #[serde(default)]
8964    pub properties: Vec<Expression>,
8965    /// Leading comments before the statement
8966    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8967    pub leading_comments: Vec<String>,
8968}
8969
8970impl CreateSchema {
8971    pub fn new(name: impl Into<String>) -> Self {
8972        Self {
8973            name: vec![Identifier::new(name)],
8974            if_not_exists: false,
8975            authorization: None,
8976            clone_from: None,
8977            at_clause: None,
8978            properties: Vec::new(),
8979            leading_comments: Vec::new(),
8980        }
8981    }
8982}
8983
8984/// DROP SCHEMA statement
8985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8986#[cfg_attr(feature = "bindings", derive(TS))]
8987pub struct DropSchema {
8988    pub name: Identifier,
8989    pub if_exists: bool,
8990    pub cascade: bool,
8991}
8992
8993impl DropSchema {
8994    pub fn new(name: impl Into<String>) -> Self {
8995        Self {
8996            name: Identifier::new(name),
8997            if_exists: false,
8998            cascade: false,
8999        }
9000    }
9001}
9002
9003/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
9004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9005#[cfg_attr(feature = "bindings", derive(TS))]
9006pub struct DropNamespace {
9007    pub name: Identifier,
9008    pub if_exists: bool,
9009    pub cascade: bool,
9010}
9011
9012impl DropNamespace {
9013    pub fn new(name: impl Into<String>) -> Self {
9014        Self {
9015            name: Identifier::new(name),
9016            if_exists: false,
9017            cascade: false,
9018        }
9019    }
9020}
9021
9022/// CREATE DATABASE statement
9023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9024#[cfg_attr(feature = "bindings", derive(TS))]
9025pub struct CreateDatabase {
9026    pub name: Identifier,
9027    pub if_not_exists: bool,
9028    pub options: Vec<DatabaseOption>,
9029    /// Snowflake CLONE source
9030    #[serde(default)]
9031    pub clone_from: Option<Identifier>,
9032    /// AT/BEFORE clause for time travel (Snowflake)
9033    #[serde(default)]
9034    pub at_clause: Option<Expression>,
9035}
9036
9037/// Database option
9038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9039#[cfg_attr(feature = "bindings", derive(TS))]
9040pub enum DatabaseOption {
9041    CharacterSet(String),
9042    Collate(String),
9043    Owner(Identifier),
9044    Template(Identifier),
9045    Encoding(String),
9046    Location(String),
9047}
9048
9049impl CreateDatabase {
9050    pub fn new(name: impl Into<String>) -> Self {
9051        Self {
9052            name: Identifier::new(name),
9053            if_not_exists: false,
9054            options: Vec::new(),
9055            clone_from: None,
9056            at_clause: None,
9057        }
9058    }
9059}
9060
9061/// DROP DATABASE statement
9062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9063#[cfg_attr(feature = "bindings", derive(TS))]
9064pub struct DropDatabase {
9065    pub name: Identifier,
9066    pub if_exists: bool,
9067    /// ClickHouse: SYNC modifier
9068    #[serde(default)]
9069    pub sync: bool,
9070}
9071
9072impl DropDatabase {
9073    pub fn new(name: impl Into<String>) -> Self {
9074        Self {
9075            name: Identifier::new(name),
9076            if_exists: false,
9077            sync: false,
9078        }
9079    }
9080}
9081
9082/// CREATE FUNCTION statement
9083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9084#[cfg_attr(feature = "bindings", derive(TS))]
9085pub struct CreateFunction {
9086    pub name: TableRef,
9087    pub parameters: Vec<FunctionParameter>,
9088    pub return_type: Option<DataType>,
9089    pub body: Option<FunctionBody>,
9090    pub or_replace: bool,
9091    /// TSQL: CREATE OR ALTER
9092    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9093    pub or_alter: bool,
9094    pub if_not_exists: bool,
9095    pub temporary: bool,
9096    pub language: Option<String>,
9097    pub deterministic: Option<bool>,
9098    pub returns_null_on_null_input: Option<bool>,
9099    pub security: Option<FunctionSecurity>,
9100    /// Whether parentheses were present in the original syntax
9101    #[serde(default = "default_true")]
9102    pub has_parens: bool,
9103    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9104    #[serde(default)]
9105    pub sql_data_access: Option<SqlDataAccess>,
9106    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9107    #[serde(default, skip_serializing_if = "Option::is_none")]
9108    pub returns_table_body: Option<String>,
9109    /// True if LANGUAGE clause appears before RETURNS clause
9110    #[serde(default)]
9111    pub language_first: bool,
9112    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9113    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9114    pub set_options: Vec<FunctionSetOption>,
9115    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9116    #[serde(default)]
9117    pub strict: bool,
9118    /// BigQuery: OPTIONS (key=value, ...)
9119    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9120    pub options: Vec<Expression>,
9121    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9122    #[serde(default)]
9123    pub is_table_function: bool,
9124    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9125    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9126    pub property_order: Vec<FunctionPropertyKind>,
9127    /// Hive: USING JAR|FILE|ARCHIVE '...'
9128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9129    pub using_resources: Vec<FunctionUsingResource>,
9130    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9131    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9132    pub environment: Vec<Expression>,
9133    /// HANDLER 'handler_function' clause (Databricks)
9134    #[serde(default, skip_serializing_if = "Option::is_none")]
9135    pub handler: Option<String>,
9136    /// True when the HANDLER clause used Snowflake-style `HANDLER = 'fn'`
9137    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9138    pub handler_uses_eq: bool,
9139    /// Snowflake: RUNTIME_VERSION='3.11'
9140    #[serde(default, skip_serializing_if = "Option::is_none")]
9141    pub runtime_version: Option<String>,
9142    /// Snowflake: PACKAGES=('pkg1', 'pkg2')
9143    #[serde(default, skip_serializing_if = "Option::is_none")]
9144    pub packages: Option<Vec<String>>,
9145    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9146    #[serde(default, skip_serializing_if = "Option::is_none")]
9147    pub parameter_style: Option<String>,
9148}
9149
9150/// A SET option in CREATE FUNCTION (PostgreSQL)
9151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9152#[cfg_attr(feature = "bindings", derive(TS))]
9153pub struct FunctionSetOption {
9154    pub name: String,
9155    pub value: FunctionSetValue,
9156}
9157
9158/// The value of a SET option
9159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9160#[cfg_attr(feature = "bindings", derive(TS))]
9161pub enum FunctionSetValue {
9162    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9163    Value { value: String, use_to: bool },
9164    /// SET key FROM CURRENT
9165    FromCurrent,
9166}
9167
9168/// SQL data access characteristics for functions
9169#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9170#[cfg_attr(feature = "bindings", derive(TS))]
9171pub enum SqlDataAccess {
9172    /// NO SQL
9173    NoSql,
9174    /// CONTAINS SQL
9175    ContainsSql,
9176    /// READS SQL DATA
9177    ReadsSqlData,
9178    /// MODIFIES SQL DATA
9179    ModifiesSqlData,
9180}
9181
9182/// Types of properties in CREATE FUNCTION for tracking their original order
9183#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9184#[cfg_attr(feature = "bindings", derive(TS))]
9185pub enum FunctionPropertyKind {
9186    /// SET option
9187    Set,
9188    /// AS body
9189    As,
9190    /// Hive: USING JAR|FILE|ARCHIVE ...
9191    Using,
9192    /// LANGUAGE clause
9193    Language,
9194    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9195    Determinism,
9196    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9197    NullInput,
9198    /// SECURITY DEFINER/INVOKER
9199    Security,
9200    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9201    SqlDataAccess,
9202    /// OPTIONS clause (BigQuery)
9203    Options,
9204    /// ENVIRONMENT clause (Databricks)
9205    Environment,
9206    /// HANDLER clause (Databricks)
9207    Handler,
9208    /// Snowflake: RUNTIME_VERSION='...'
9209    RuntimeVersion,
9210    /// Snowflake: PACKAGES=(...)
9211    Packages,
9212    /// PARAMETER STYLE clause (Databricks)
9213    ParameterStyle,
9214}
9215
9216/// Hive CREATE FUNCTION resource in a USING clause
9217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9218#[cfg_attr(feature = "bindings", derive(TS))]
9219pub struct FunctionUsingResource {
9220    pub kind: String,
9221    pub uri: String,
9222}
9223
9224/// Function parameter
9225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9226#[cfg_attr(feature = "bindings", derive(TS))]
9227pub struct FunctionParameter {
9228    pub name: Option<Identifier>,
9229    pub data_type: DataType,
9230    pub mode: Option<ParameterMode>,
9231    pub default: Option<Expression>,
9232    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9233    #[serde(default, skip_serializing_if = "Option::is_none")]
9234    pub mode_text: Option<String>,
9235}
9236
9237/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9238#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9239#[cfg_attr(feature = "bindings", derive(TS))]
9240pub enum ParameterMode {
9241    In,
9242    Out,
9243    InOut,
9244    Variadic,
9245}
9246
9247/// Function body
9248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9249#[cfg_attr(feature = "bindings", derive(TS))]
9250pub enum FunctionBody {
9251    /// AS $$ ... $$ (dollar-quoted)
9252    Block(String),
9253    /// AS 'string' (single-quoted string literal body)
9254    StringLiteral(String),
9255    /// AS 'expression'
9256    Expression(Expression),
9257    /// EXTERNAL NAME 'library'
9258    External(String),
9259    /// RETURN expression
9260    Return(Expression),
9261    /// BEGIN ... END block with parsed statements
9262    Statements(Vec<Expression>),
9263    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9264    /// Stores (content, optional_tag)
9265    DollarQuoted {
9266        content: String,
9267        tag: Option<String>,
9268    },
9269    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9270    RawBlock(String),
9271}
9272
9273/// Function security (DEFINER, INVOKER, or NONE)
9274#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9275#[cfg_attr(feature = "bindings", derive(TS))]
9276pub enum FunctionSecurity {
9277    Definer,
9278    Invoker,
9279    /// StarRocks/MySQL: SECURITY NONE
9280    None,
9281}
9282
9283impl CreateFunction {
9284    pub fn new(name: impl Into<String>) -> Self {
9285        Self {
9286            name: TableRef::new(name),
9287            parameters: Vec::new(),
9288            return_type: None,
9289            body: None,
9290            or_replace: false,
9291            or_alter: false,
9292            if_not_exists: false,
9293            temporary: false,
9294            language: None,
9295            deterministic: None,
9296            returns_null_on_null_input: None,
9297            security: None,
9298            has_parens: true,
9299            sql_data_access: None,
9300            returns_table_body: None,
9301            language_first: false,
9302            set_options: Vec::new(),
9303            strict: false,
9304            options: Vec::new(),
9305            is_table_function: false,
9306            property_order: Vec::new(),
9307            using_resources: Vec::new(),
9308            environment: Vec::new(),
9309            handler: None,
9310            handler_uses_eq: false,
9311            runtime_version: None,
9312            packages: None,
9313            parameter_style: None,
9314        }
9315    }
9316}
9317
9318/// DROP FUNCTION statement
9319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9320#[cfg_attr(feature = "bindings", derive(TS))]
9321pub struct DropFunction {
9322    pub name: TableRef,
9323    pub parameters: Option<Vec<DataType>>,
9324    pub if_exists: bool,
9325    pub cascade: bool,
9326}
9327
9328impl DropFunction {
9329    pub fn new(name: impl Into<String>) -> Self {
9330        Self {
9331            name: TableRef::new(name),
9332            parameters: None,
9333            if_exists: false,
9334            cascade: false,
9335        }
9336    }
9337}
9338
9339/// CREATE PROCEDURE statement
9340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9341#[cfg_attr(feature = "bindings", derive(TS))]
9342pub struct CreateProcedure {
9343    pub name: TableRef,
9344    pub parameters: Vec<FunctionParameter>,
9345    pub body: Option<FunctionBody>,
9346    pub or_replace: bool,
9347    /// TSQL: CREATE OR ALTER
9348    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9349    pub or_alter: bool,
9350    pub if_not_exists: bool,
9351    pub language: Option<String>,
9352    pub security: Option<FunctionSecurity>,
9353    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9354    #[serde(default)]
9355    pub return_type: Option<DataType>,
9356    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9357    #[serde(default)]
9358    pub execute_as: Option<String>,
9359    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9360    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9361    pub with_options: Vec<String>,
9362    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9363    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9364    pub has_parens: bool,
9365    /// Whether the short form PROC was used (instead of PROCEDURE)
9366    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9367    pub use_proc_keyword: bool,
9368}
9369
9370impl CreateProcedure {
9371    pub fn new(name: impl Into<String>) -> Self {
9372        Self {
9373            name: TableRef::new(name),
9374            parameters: Vec::new(),
9375            body: None,
9376            or_replace: false,
9377            or_alter: false,
9378            if_not_exists: false,
9379            language: None,
9380            security: None,
9381            return_type: None,
9382            execute_as: None,
9383            with_options: Vec::new(),
9384            has_parens: true,
9385            use_proc_keyword: false,
9386        }
9387    }
9388}
9389
9390/// DROP PROCEDURE statement
9391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9392#[cfg_attr(feature = "bindings", derive(TS))]
9393pub struct DropProcedure {
9394    pub name: TableRef,
9395    pub parameters: Option<Vec<DataType>>,
9396    pub if_exists: bool,
9397    pub cascade: bool,
9398}
9399
9400impl DropProcedure {
9401    pub fn new(name: impl Into<String>) -> Self {
9402        Self {
9403            name: TableRef::new(name),
9404            parameters: None,
9405            if_exists: false,
9406            cascade: false,
9407        }
9408    }
9409}
9410
9411/// Sequence property tag for ordering
9412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9413#[cfg_attr(feature = "bindings", derive(TS))]
9414pub enum SeqPropKind {
9415    Start,
9416    Increment,
9417    Minvalue,
9418    Maxvalue,
9419    Cache,
9420    NoCache,
9421    Cycle,
9422    NoCycle,
9423    OwnedBy,
9424    Order,
9425    NoOrder,
9426    Comment,
9427    /// SHARING=<value> (Oracle)
9428    Sharing,
9429    /// KEEP (Oracle)
9430    Keep,
9431    /// NOKEEP (Oracle)
9432    NoKeep,
9433    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9434    Scale,
9435    /// NOSCALE (Oracle)
9436    NoScale,
9437    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9438    Shard,
9439    /// NOSHARD (Oracle)
9440    NoShard,
9441    /// SESSION (Oracle)
9442    Session,
9443    /// GLOBAL (Oracle)
9444    Global,
9445    /// NOCACHE (single word, Oracle)
9446    NoCacheWord,
9447    /// NOCYCLE (single word, Oracle)
9448    NoCycleWord,
9449    /// NOMINVALUE (single word, Oracle)
9450    NoMinvalueWord,
9451    /// NOMAXVALUE (single word, Oracle)
9452    NoMaxvalueWord,
9453}
9454
9455/// CREATE SYNONYM statement (TSQL)
9456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9457#[cfg_attr(feature = "bindings", derive(TS))]
9458pub struct CreateSynonym {
9459    /// The synonym name (can be qualified: schema.synonym_name)
9460    pub name: TableRef,
9461    /// The target object the synonym refers to
9462    pub target: TableRef,
9463}
9464
9465/// CREATE SEQUENCE statement
9466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9467#[cfg_attr(feature = "bindings", derive(TS))]
9468pub struct CreateSequence {
9469    pub name: TableRef,
9470    pub if_not_exists: bool,
9471    pub temporary: bool,
9472    #[serde(default)]
9473    pub or_replace: bool,
9474    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9475    #[serde(default, skip_serializing_if = "Option::is_none")]
9476    pub as_type: Option<DataType>,
9477    pub increment: Option<i64>,
9478    pub minvalue: Option<SequenceBound>,
9479    pub maxvalue: Option<SequenceBound>,
9480    pub start: Option<i64>,
9481    pub cache: Option<i64>,
9482    pub cycle: bool,
9483    pub owned_by: Option<TableRef>,
9484    /// Whether OWNED BY NONE was specified
9485    #[serde(default)]
9486    pub owned_by_none: bool,
9487    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9488    #[serde(default)]
9489    pub order: Option<bool>,
9490    /// Snowflake: COMMENT = 'value'
9491    #[serde(default)]
9492    pub comment: Option<String>,
9493    /// SHARING=<value> (Oracle)
9494    #[serde(default, skip_serializing_if = "Option::is_none")]
9495    pub sharing: Option<String>,
9496    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9497    #[serde(default, skip_serializing_if = "Option::is_none")]
9498    pub scale_modifier: Option<String>,
9499    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9500    #[serde(default, skip_serializing_if = "Option::is_none")]
9501    pub shard_modifier: Option<String>,
9502    /// Tracks the order in which properties appeared in the source
9503    #[serde(default)]
9504    pub property_order: Vec<SeqPropKind>,
9505}
9506
9507/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9509#[cfg_attr(feature = "bindings", derive(TS))]
9510pub enum SequenceBound {
9511    Value(i64),
9512    None,
9513}
9514
9515impl CreateSequence {
9516    pub fn new(name: impl Into<String>) -> Self {
9517        Self {
9518            name: TableRef::new(name),
9519            if_not_exists: false,
9520            temporary: false,
9521            or_replace: false,
9522            as_type: None,
9523            increment: None,
9524            minvalue: None,
9525            maxvalue: None,
9526            start: None,
9527            cache: None,
9528            cycle: false,
9529            owned_by: None,
9530            owned_by_none: false,
9531            order: None,
9532            comment: None,
9533            sharing: None,
9534            scale_modifier: None,
9535            shard_modifier: None,
9536            property_order: Vec::new(),
9537        }
9538    }
9539}
9540
9541/// DROP SEQUENCE statement
9542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9543#[cfg_attr(feature = "bindings", derive(TS))]
9544pub struct DropSequence {
9545    pub name: TableRef,
9546    pub if_exists: bool,
9547    pub cascade: bool,
9548}
9549
9550impl DropSequence {
9551    pub fn new(name: impl Into<String>) -> Self {
9552        Self {
9553            name: TableRef::new(name),
9554            if_exists: false,
9555            cascade: false,
9556        }
9557    }
9558}
9559
9560/// ALTER SEQUENCE statement
9561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9562#[cfg_attr(feature = "bindings", derive(TS))]
9563pub struct AlterSequence {
9564    pub name: TableRef,
9565    pub if_exists: bool,
9566    pub increment: Option<i64>,
9567    pub minvalue: Option<SequenceBound>,
9568    pub maxvalue: Option<SequenceBound>,
9569    pub start: Option<i64>,
9570    pub restart: Option<Option<i64>>,
9571    pub cache: Option<i64>,
9572    pub cycle: Option<bool>,
9573    pub owned_by: Option<Option<TableRef>>,
9574}
9575
9576impl AlterSequence {
9577    pub fn new(name: impl Into<String>) -> Self {
9578        Self {
9579            name: TableRef::new(name),
9580            if_exists: false,
9581            increment: None,
9582            minvalue: None,
9583            maxvalue: None,
9584            start: None,
9585            restart: None,
9586            cache: None,
9587            cycle: None,
9588            owned_by: None,
9589        }
9590    }
9591}
9592
9593/// CREATE TRIGGER statement
9594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9595#[cfg_attr(feature = "bindings", derive(TS))]
9596pub struct CreateTrigger {
9597    pub name: Identifier,
9598    pub table: TableRef,
9599    pub timing: TriggerTiming,
9600    pub events: Vec<TriggerEvent>,
9601    #[serde(default, skip_serializing_if = "Option::is_none")]
9602    pub for_each: Option<TriggerForEach>,
9603    pub when: Option<Expression>,
9604    /// Whether the WHEN clause was parenthesized in the original SQL
9605    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9606    pub when_paren: bool,
9607    pub body: TriggerBody,
9608    pub or_replace: bool,
9609    /// TSQL: CREATE OR ALTER
9610    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9611    pub or_alter: bool,
9612    pub constraint: bool,
9613    pub deferrable: Option<bool>,
9614    pub initially_deferred: Option<bool>,
9615    pub referencing: Option<TriggerReferencing>,
9616}
9617
9618/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9619#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9620#[cfg_attr(feature = "bindings", derive(TS))]
9621pub enum TriggerTiming {
9622    Before,
9623    After,
9624    InsteadOf,
9625}
9626
9627/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9629#[cfg_attr(feature = "bindings", derive(TS))]
9630pub enum TriggerEvent {
9631    Insert,
9632    Update(Option<Vec<Identifier>>),
9633    Delete,
9634    Truncate,
9635}
9636
9637/// Trigger FOR EACH clause
9638#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9639#[cfg_attr(feature = "bindings", derive(TS))]
9640pub enum TriggerForEach {
9641    Row,
9642    Statement,
9643}
9644
9645/// Trigger body
9646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9647#[cfg_attr(feature = "bindings", derive(TS))]
9648pub enum TriggerBody {
9649    /// EXECUTE FUNCTION/PROCEDURE name(args)
9650    Execute {
9651        function: TableRef,
9652        args: Vec<Expression>,
9653    },
9654    /// BEGIN ... END block
9655    Block(String),
9656}
9657
9658/// Trigger REFERENCING clause
9659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9660#[cfg_attr(feature = "bindings", derive(TS))]
9661pub struct TriggerReferencing {
9662    pub old_table: Option<Identifier>,
9663    pub new_table: Option<Identifier>,
9664    pub old_row: Option<Identifier>,
9665    pub new_row: Option<Identifier>,
9666}
9667
9668impl CreateTrigger {
9669    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9670        Self {
9671            name: Identifier::new(name),
9672            table: TableRef::new(table),
9673            timing: TriggerTiming::Before,
9674            events: Vec::new(),
9675            for_each: Some(TriggerForEach::Row),
9676            when: None,
9677            when_paren: false,
9678            body: TriggerBody::Execute {
9679                function: TableRef::new(""),
9680                args: Vec::new(),
9681            },
9682            or_replace: false,
9683            or_alter: false,
9684            constraint: false,
9685            deferrable: None,
9686            initially_deferred: None,
9687            referencing: None,
9688        }
9689    }
9690}
9691
9692/// DROP TRIGGER statement
9693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9694#[cfg_attr(feature = "bindings", derive(TS))]
9695pub struct DropTrigger {
9696    pub name: Identifier,
9697    pub table: Option<TableRef>,
9698    pub if_exists: bool,
9699    pub cascade: bool,
9700}
9701
9702impl DropTrigger {
9703    pub fn new(name: impl Into<String>) -> Self {
9704        Self {
9705            name: Identifier::new(name),
9706            table: None,
9707            if_exists: false,
9708            cascade: false,
9709        }
9710    }
9711}
9712
9713/// CREATE TYPE statement
9714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9715#[cfg_attr(feature = "bindings", derive(TS))]
9716pub struct CreateType {
9717    pub name: TableRef,
9718    pub definition: TypeDefinition,
9719    pub if_not_exists: bool,
9720}
9721
9722/// Type definition
9723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9724#[cfg_attr(feature = "bindings", derive(TS))]
9725pub enum TypeDefinition {
9726    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9727    Enum(Vec<String>),
9728    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9729    Composite(Vec<TypeAttribute>),
9730    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9731    Range {
9732        subtype: DataType,
9733        subtype_diff: Option<String>,
9734        canonical: Option<String>,
9735    },
9736    /// Base type (for advanced usage)
9737    Base {
9738        input: String,
9739        output: String,
9740        internallength: Option<i32>,
9741    },
9742    /// Domain type
9743    Domain {
9744        base_type: DataType,
9745        default: Option<Expression>,
9746        constraints: Vec<DomainConstraint>,
9747    },
9748}
9749
9750/// Type attribute for composite types
9751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9752#[cfg_attr(feature = "bindings", derive(TS))]
9753pub struct TypeAttribute {
9754    pub name: Identifier,
9755    pub data_type: DataType,
9756    pub collate: Option<Identifier>,
9757}
9758
9759/// Domain constraint
9760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9761#[cfg_attr(feature = "bindings", derive(TS))]
9762pub struct DomainConstraint {
9763    pub name: Option<Identifier>,
9764    pub check: Expression,
9765}
9766
9767impl CreateType {
9768    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9769        Self {
9770            name: TableRef::new(name),
9771            definition: TypeDefinition::Enum(values),
9772            if_not_exists: false,
9773        }
9774    }
9775
9776    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9777        Self {
9778            name: TableRef::new(name),
9779            definition: TypeDefinition::Composite(attributes),
9780            if_not_exists: false,
9781        }
9782    }
9783}
9784
9785/// DROP TYPE statement
9786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9787#[cfg_attr(feature = "bindings", derive(TS))]
9788pub struct DropType {
9789    pub name: TableRef,
9790    pub if_exists: bool,
9791    pub cascade: bool,
9792}
9793
9794impl DropType {
9795    pub fn new(name: impl Into<String>) -> Self {
9796        Self {
9797            name: TableRef::new(name),
9798            if_exists: false,
9799            cascade: false,
9800        }
9801    }
9802}
9803
9804/// DESCRIBE statement - shows table structure or query plan
9805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9806#[cfg_attr(feature = "bindings", derive(TS))]
9807pub struct Describe {
9808    /// The target to describe (table name or query)
9809    pub target: Expression,
9810    /// EXTENDED format
9811    pub extended: bool,
9812    /// FORMATTED format
9813    pub formatted: bool,
9814    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9815    #[serde(default)]
9816    pub kind: Option<String>,
9817    /// Properties like type=stage
9818    #[serde(default)]
9819    pub properties: Vec<(String, String)>,
9820    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9821    #[serde(default, skip_serializing_if = "Option::is_none")]
9822    pub style: Option<String>,
9823    /// Partition specification for DESCRIBE PARTITION
9824    #[serde(default)]
9825    pub partition: Option<Box<Expression>>,
9826    /// Leading comments before the statement
9827    #[serde(default)]
9828    pub leading_comments: Vec<String>,
9829    /// AS JSON suffix (Databricks)
9830    #[serde(default)]
9831    pub as_json: bool,
9832    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9833    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9834    pub params: Vec<String>,
9835}
9836
9837impl Describe {
9838    pub fn new(target: Expression) -> Self {
9839        Self {
9840            target,
9841            extended: false,
9842            formatted: false,
9843            kind: None,
9844            properties: Vec::new(),
9845            style: None,
9846            partition: None,
9847            leading_comments: Vec::new(),
9848            as_json: false,
9849            params: Vec::new(),
9850        }
9851    }
9852}
9853
9854/// SHOW statement - displays database objects
9855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9856#[cfg_attr(feature = "bindings", derive(TS))]
9857pub struct Show {
9858    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9859    pub this: String,
9860    /// Whether TERSE was specified
9861    #[serde(default)]
9862    pub terse: bool,
9863    /// Whether HISTORY was specified
9864    #[serde(default)]
9865    pub history: bool,
9866    /// LIKE pattern
9867    pub like: Option<Expression>,
9868    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9869    pub scope_kind: Option<String>,
9870    /// IN scope object
9871    pub scope: Option<Expression>,
9872    /// STARTS WITH pattern
9873    pub starts_with: Option<Expression>,
9874    /// LIMIT clause
9875    pub limit: Option<Box<Limit>>,
9876    /// FROM clause (for specific object)
9877    pub from: Option<Expression>,
9878    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9879    #[serde(default, skip_serializing_if = "Option::is_none")]
9880    pub where_clause: Option<Expression>,
9881    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9882    #[serde(default, skip_serializing_if = "Option::is_none")]
9883    pub for_target: Option<Expression>,
9884    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9885    #[serde(default, skip_serializing_if = "Option::is_none")]
9886    pub db: Option<Expression>,
9887    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9888    #[serde(default, skip_serializing_if = "Option::is_none")]
9889    pub target: Option<Expression>,
9890    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9891    #[serde(default, skip_serializing_if = "Option::is_none")]
9892    pub mutex: Option<bool>,
9893    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9894    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9895    pub privileges: Vec<String>,
9896}
9897
9898impl Show {
9899    pub fn new(this: impl Into<String>) -> Self {
9900        Self {
9901            this: this.into(),
9902            terse: false,
9903            history: false,
9904            like: None,
9905            scope_kind: None,
9906            scope: None,
9907            starts_with: None,
9908            limit: None,
9909            from: None,
9910            where_clause: None,
9911            for_target: None,
9912            db: None,
9913            target: None,
9914            mutex: None,
9915            privileges: Vec::new(),
9916        }
9917    }
9918}
9919
9920/// Represent an explicit parenthesized expression for grouping precedence.
9921///
9922/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9923/// correctly instead of being flattened to `a + b * c`.
9924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9925#[cfg_attr(feature = "bindings", derive(TS))]
9926pub struct Paren {
9927    /// The inner expression wrapped by parentheses.
9928    pub this: Expression,
9929    #[serde(default)]
9930    pub trailing_comments: Vec<String>,
9931}
9932
9933/// Expression annotated with trailing comments (for round-trip preservation)
9934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9935#[cfg_attr(feature = "bindings", derive(TS))]
9936pub struct Annotated {
9937    pub this: Expression,
9938    pub trailing_comments: Vec<String>,
9939}
9940
9941// === BATCH GENERATED STRUCT DEFINITIONS ===
9942// Generated from Python sqlglot expressions.py
9943
9944/// Refresh
9945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9946#[cfg_attr(feature = "bindings", derive(TS))]
9947pub struct Refresh {
9948    pub this: Box<Expression>,
9949    pub kind: String,
9950}
9951
9952/// LockingStatement
9953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9954#[cfg_attr(feature = "bindings", derive(TS))]
9955pub struct LockingStatement {
9956    pub this: Box<Expression>,
9957    pub expression: Box<Expression>,
9958}
9959
9960/// SequenceProperties
9961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9962#[cfg_attr(feature = "bindings", derive(TS))]
9963pub struct SequenceProperties {
9964    #[serde(default)]
9965    pub increment: Option<Box<Expression>>,
9966    #[serde(default)]
9967    pub minvalue: Option<Box<Expression>>,
9968    #[serde(default)]
9969    pub maxvalue: Option<Box<Expression>>,
9970    #[serde(default)]
9971    pub cache: Option<Box<Expression>>,
9972    #[serde(default)]
9973    pub start: Option<Box<Expression>>,
9974    #[serde(default)]
9975    pub owned: Option<Box<Expression>>,
9976    #[serde(default)]
9977    pub options: Vec<Expression>,
9978}
9979
9980/// TruncateTable
9981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9982#[cfg_attr(feature = "bindings", derive(TS))]
9983pub struct TruncateTable {
9984    #[serde(default)]
9985    pub expressions: Vec<Expression>,
9986    #[serde(default)]
9987    pub is_database: Option<Box<Expression>>,
9988    #[serde(default)]
9989    pub exists: bool,
9990    #[serde(default)]
9991    pub only: Option<Box<Expression>>,
9992    #[serde(default)]
9993    pub cluster: Option<Box<Expression>>,
9994    #[serde(default)]
9995    pub identity: Option<Box<Expression>>,
9996    #[serde(default)]
9997    pub option: Option<Box<Expression>>,
9998    #[serde(default)]
9999    pub partition: Option<Box<Expression>>,
10000}
10001
10002/// Clone
10003#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10004#[cfg_attr(feature = "bindings", derive(TS))]
10005pub struct Clone {
10006    pub this: Box<Expression>,
10007    #[serde(default)]
10008    pub shallow: Option<Box<Expression>>,
10009    #[serde(default)]
10010    pub copy: Option<Box<Expression>>,
10011}
10012
10013/// Attach
10014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10015#[cfg_attr(feature = "bindings", derive(TS))]
10016pub struct Attach {
10017    pub this: Box<Expression>,
10018    #[serde(default)]
10019    pub exists: bool,
10020    #[serde(default)]
10021    pub expressions: Vec<Expression>,
10022}
10023
10024/// Detach
10025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10026#[cfg_attr(feature = "bindings", derive(TS))]
10027pub struct Detach {
10028    pub this: Box<Expression>,
10029    #[serde(default)]
10030    pub exists: bool,
10031}
10032
10033/// Install
10034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10035#[cfg_attr(feature = "bindings", derive(TS))]
10036pub struct Install {
10037    pub this: Box<Expression>,
10038    #[serde(default)]
10039    pub from_: Option<Box<Expression>>,
10040    #[serde(default)]
10041    pub force: Option<Box<Expression>>,
10042}
10043
10044/// Summarize
10045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10046#[cfg_attr(feature = "bindings", derive(TS))]
10047pub struct Summarize {
10048    pub this: Box<Expression>,
10049    #[serde(default)]
10050    pub table: Option<Box<Expression>>,
10051}
10052
10053/// Declare
10054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10055#[cfg_attr(feature = "bindings", derive(TS))]
10056pub struct Declare {
10057    #[serde(default)]
10058    pub expressions: Vec<Expression>,
10059    #[serde(default)]
10060    pub replace: bool,
10061}
10062
10063/// DeclareItem
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct DeclareItem {
10067    pub this: Box<Expression>,
10068    #[serde(default)]
10069    pub kind: Option<String>,
10070    #[serde(default)]
10071    pub default: Option<Box<Expression>>,
10072    #[serde(default)]
10073    pub has_as: bool,
10074    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
10075    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10076    pub additional_names: Vec<Expression>,
10077}
10078
10079/// Set
10080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10081#[cfg_attr(feature = "bindings", derive(TS))]
10082pub struct Set {
10083    #[serde(default)]
10084    pub expressions: Vec<Expression>,
10085    #[serde(default)]
10086    pub unset: Option<Box<Expression>>,
10087    #[serde(default)]
10088    pub tag: Option<Box<Expression>>,
10089}
10090
10091/// Heredoc
10092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10093#[cfg_attr(feature = "bindings", derive(TS))]
10094pub struct Heredoc {
10095    pub this: Box<Expression>,
10096    #[serde(default)]
10097    pub tag: Option<Box<Expression>>,
10098}
10099
10100/// QueryBand
10101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10102#[cfg_attr(feature = "bindings", derive(TS))]
10103pub struct QueryBand {
10104    pub this: Box<Expression>,
10105    #[serde(default)]
10106    pub scope: Option<Box<Expression>>,
10107    #[serde(default)]
10108    pub update: Option<Box<Expression>>,
10109}
10110
10111/// UserDefinedFunction
10112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10113#[cfg_attr(feature = "bindings", derive(TS))]
10114pub struct UserDefinedFunction {
10115    pub this: Box<Expression>,
10116    #[serde(default)]
10117    pub expressions: Vec<Expression>,
10118    #[serde(default)]
10119    pub wrapped: Option<Box<Expression>>,
10120}
10121
10122/// RecursiveWithSearch
10123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10124#[cfg_attr(feature = "bindings", derive(TS))]
10125pub struct RecursiveWithSearch {
10126    pub kind: String,
10127    pub this: Box<Expression>,
10128    pub expression: Box<Expression>,
10129    #[serde(default)]
10130    pub using: Option<Box<Expression>>,
10131}
10132
10133/// ProjectionDef
10134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10135#[cfg_attr(feature = "bindings", derive(TS))]
10136pub struct ProjectionDef {
10137    pub this: Box<Expression>,
10138    pub expression: Box<Expression>,
10139}
10140
10141/// TableAlias
10142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10143#[cfg_attr(feature = "bindings", derive(TS))]
10144pub struct TableAlias {
10145    #[serde(default)]
10146    pub this: Option<Box<Expression>>,
10147    #[serde(default)]
10148    pub columns: Vec<Expression>,
10149}
10150
10151/// ByteString
10152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10153#[cfg_attr(feature = "bindings", derive(TS))]
10154pub struct ByteString {
10155    pub this: Box<Expression>,
10156    #[serde(default)]
10157    pub is_bytes: Option<Box<Expression>>,
10158}
10159
10160/// HexStringExpr - Hex string expression (not literal)
10161/// BigQuery: converts to FROM_HEX(this)
10162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10163#[cfg_attr(feature = "bindings", derive(TS))]
10164pub struct HexStringExpr {
10165    pub this: Box<Expression>,
10166    #[serde(default)]
10167    pub is_integer: Option<bool>,
10168}
10169
10170/// UnicodeString
10171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10172#[cfg_attr(feature = "bindings", derive(TS))]
10173pub struct UnicodeString {
10174    pub this: Box<Expression>,
10175    #[serde(default)]
10176    pub escape: Option<Box<Expression>>,
10177}
10178
10179/// AlterColumn
10180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10181#[cfg_attr(feature = "bindings", derive(TS))]
10182pub struct AlterColumn {
10183    pub this: Box<Expression>,
10184    #[serde(default)]
10185    pub dtype: Option<Box<Expression>>,
10186    #[serde(default)]
10187    pub collate: Option<Box<Expression>>,
10188    #[serde(default)]
10189    pub using: Option<Box<Expression>>,
10190    #[serde(default)]
10191    pub default: Option<Box<Expression>>,
10192    #[serde(default)]
10193    pub drop: Option<Box<Expression>>,
10194    #[serde(default)]
10195    pub comment: Option<Box<Expression>>,
10196    #[serde(default)]
10197    pub allow_null: Option<Box<Expression>>,
10198    #[serde(default)]
10199    pub visible: Option<Box<Expression>>,
10200    #[serde(default)]
10201    pub rename_to: Option<Box<Expression>>,
10202}
10203
10204/// AlterSortKey
10205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10206#[cfg_attr(feature = "bindings", derive(TS))]
10207pub struct AlterSortKey {
10208    #[serde(default)]
10209    pub this: Option<Box<Expression>>,
10210    #[serde(default)]
10211    pub expressions: Vec<Expression>,
10212    #[serde(default)]
10213    pub compound: Option<Box<Expression>>,
10214}
10215
10216/// AlterSet
10217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10218#[cfg_attr(feature = "bindings", derive(TS))]
10219pub struct AlterSet {
10220    #[serde(default)]
10221    pub expressions: Vec<Expression>,
10222    #[serde(default)]
10223    pub option: Option<Box<Expression>>,
10224    #[serde(default)]
10225    pub tablespace: Option<Box<Expression>>,
10226    #[serde(default)]
10227    pub access_method: Option<Box<Expression>>,
10228    #[serde(default)]
10229    pub file_format: Option<Box<Expression>>,
10230    #[serde(default)]
10231    pub copy_options: Option<Box<Expression>>,
10232    #[serde(default)]
10233    pub tag: Option<Box<Expression>>,
10234    #[serde(default)]
10235    pub location: Option<Box<Expression>>,
10236    #[serde(default)]
10237    pub serde: Option<Box<Expression>>,
10238}
10239
10240/// RenameColumn
10241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10242#[cfg_attr(feature = "bindings", derive(TS))]
10243pub struct RenameColumn {
10244    pub this: Box<Expression>,
10245    #[serde(default)]
10246    pub to: Option<Box<Expression>>,
10247    #[serde(default)]
10248    pub exists: bool,
10249}
10250
10251/// Comprehension
10252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10253#[cfg_attr(feature = "bindings", derive(TS))]
10254pub struct Comprehension {
10255    pub this: Box<Expression>,
10256    pub expression: Box<Expression>,
10257    #[serde(default)]
10258    pub position: Option<Box<Expression>>,
10259    #[serde(default)]
10260    pub iterator: Option<Box<Expression>>,
10261    #[serde(default)]
10262    pub condition: Option<Box<Expression>>,
10263}
10264
10265/// MergeTreeTTLAction
10266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10267#[cfg_attr(feature = "bindings", derive(TS))]
10268pub struct MergeTreeTTLAction {
10269    pub this: Box<Expression>,
10270    #[serde(default)]
10271    pub delete: Option<Box<Expression>>,
10272    #[serde(default)]
10273    pub recompress: Option<Box<Expression>>,
10274    #[serde(default)]
10275    pub to_disk: Option<Box<Expression>>,
10276    #[serde(default)]
10277    pub to_volume: Option<Box<Expression>>,
10278}
10279
10280/// MergeTreeTTL
10281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10282#[cfg_attr(feature = "bindings", derive(TS))]
10283pub struct MergeTreeTTL {
10284    #[serde(default)]
10285    pub expressions: Vec<Expression>,
10286    #[serde(default)]
10287    pub where_: Option<Box<Expression>>,
10288    #[serde(default)]
10289    pub group: Option<Box<Expression>>,
10290    #[serde(default)]
10291    pub aggregates: Option<Box<Expression>>,
10292}
10293
10294/// IndexConstraintOption
10295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10296#[cfg_attr(feature = "bindings", derive(TS))]
10297pub struct IndexConstraintOption {
10298    #[serde(default)]
10299    pub key_block_size: Option<Box<Expression>>,
10300    #[serde(default)]
10301    pub using: Option<Box<Expression>>,
10302    #[serde(default)]
10303    pub parser: Option<Box<Expression>>,
10304    #[serde(default)]
10305    pub comment: Option<Box<Expression>>,
10306    #[serde(default)]
10307    pub visible: Option<Box<Expression>>,
10308    #[serde(default)]
10309    pub engine_attr: Option<Box<Expression>>,
10310    #[serde(default)]
10311    pub secondary_engine_attr: Option<Box<Expression>>,
10312}
10313
10314/// PeriodForSystemTimeConstraint
10315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10316#[cfg_attr(feature = "bindings", derive(TS))]
10317pub struct PeriodForSystemTimeConstraint {
10318    pub this: Box<Expression>,
10319    pub expression: Box<Expression>,
10320}
10321
10322/// CaseSpecificColumnConstraint
10323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10324#[cfg_attr(feature = "bindings", derive(TS))]
10325pub struct CaseSpecificColumnConstraint {
10326    #[serde(default)]
10327    pub not_: Option<Box<Expression>>,
10328}
10329
10330/// CharacterSetColumnConstraint
10331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10332#[cfg_attr(feature = "bindings", derive(TS))]
10333pub struct CharacterSetColumnConstraint {
10334    pub this: Box<Expression>,
10335}
10336
10337/// CheckColumnConstraint
10338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10339#[cfg_attr(feature = "bindings", derive(TS))]
10340pub struct CheckColumnConstraint {
10341    pub this: Box<Expression>,
10342    #[serde(default)]
10343    pub enforced: Option<Box<Expression>>,
10344}
10345
10346/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10348#[cfg_attr(feature = "bindings", derive(TS))]
10349pub struct AssumeColumnConstraint {
10350    pub this: Box<Expression>,
10351}
10352
10353/// CompressColumnConstraint
10354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10355#[cfg_attr(feature = "bindings", derive(TS))]
10356pub struct CompressColumnConstraint {
10357    #[serde(default)]
10358    pub this: Option<Box<Expression>>,
10359}
10360
10361/// DateFormatColumnConstraint
10362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10363#[cfg_attr(feature = "bindings", derive(TS))]
10364pub struct DateFormatColumnConstraint {
10365    pub this: Box<Expression>,
10366}
10367
10368/// EphemeralColumnConstraint
10369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10370#[cfg_attr(feature = "bindings", derive(TS))]
10371pub struct EphemeralColumnConstraint {
10372    #[serde(default)]
10373    pub this: Option<Box<Expression>>,
10374}
10375
10376/// WithOperator
10377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10378#[cfg_attr(feature = "bindings", derive(TS))]
10379pub struct WithOperator {
10380    pub this: Box<Expression>,
10381    pub op: String,
10382}
10383
10384/// GeneratedAsIdentityColumnConstraint
10385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10386#[cfg_attr(feature = "bindings", derive(TS))]
10387pub struct GeneratedAsIdentityColumnConstraint {
10388    #[serde(default)]
10389    pub this: Option<Box<Expression>>,
10390    #[serde(default)]
10391    pub expression: Option<Box<Expression>>,
10392    #[serde(default)]
10393    pub on_null: Option<Box<Expression>>,
10394    #[serde(default)]
10395    pub start: Option<Box<Expression>>,
10396    #[serde(default)]
10397    pub increment: Option<Box<Expression>>,
10398    #[serde(default)]
10399    pub minvalue: Option<Box<Expression>>,
10400    #[serde(default)]
10401    pub maxvalue: Option<Box<Expression>>,
10402    #[serde(default)]
10403    pub cycle: Option<Box<Expression>>,
10404    #[serde(default)]
10405    pub order: Option<Box<Expression>>,
10406}
10407
10408/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10409/// TSQL: outputs "IDENTITY"
10410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10411#[cfg_attr(feature = "bindings", derive(TS))]
10412pub struct AutoIncrementColumnConstraint;
10413
10414/// CommentColumnConstraint - Column comment marker
10415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10416#[cfg_attr(feature = "bindings", derive(TS))]
10417pub struct CommentColumnConstraint;
10418
10419/// GeneratedAsRowColumnConstraint
10420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10421#[cfg_attr(feature = "bindings", derive(TS))]
10422pub struct GeneratedAsRowColumnConstraint {
10423    #[serde(default)]
10424    pub start: Option<Box<Expression>>,
10425    #[serde(default)]
10426    pub hidden: Option<Box<Expression>>,
10427}
10428
10429/// IndexColumnConstraint
10430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10431#[cfg_attr(feature = "bindings", derive(TS))]
10432pub struct IndexColumnConstraint {
10433    #[serde(default)]
10434    pub this: Option<Box<Expression>>,
10435    #[serde(default)]
10436    pub expressions: Vec<Expression>,
10437    #[serde(default)]
10438    pub kind: Option<String>,
10439    #[serde(default)]
10440    pub index_type: Option<Box<Expression>>,
10441    #[serde(default)]
10442    pub options: Vec<Expression>,
10443    #[serde(default)]
10444    pub expression: Option<Box<Expression>>,
10445    #[serde(default)]
10446    pub granularity: Option<Box<Expression>>,
10447}
10448
10449/// MaskingPolicyColumnConstraint
10450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10451#[cfg_attr(feature = "bindings", derive(TS))]
10452pub struct MaskingPolicyColumnConstraint {
10453    pub this: Box<Expression>,
10454    #[serde(default)]
10455    pub expressions: Vec<Expression>,
10456}
10457
10458/// NotNullColumnConstraint
10459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10460#[cfg_attr(feature = "bindings", derive(TS))]
10461pub struct NotNullColumnConstraint {
10462    #[serde(default)]
10463    pub allow_null: Option<Box<Expression>>,
10464}
10465
10466/// DefaultColumnConstraint - DEFAULT value for a column
10467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10468#[cfg_attr(feature = "bindings", derive(TS))]
10469pub struct DefaultColumnConstraint {
10470    pub this: Box<Expression>,
10471    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10472    #[serde(default, skip_serializing_if = "Option::is_none")]
10473    pub for_column: Option<Identifier>,
10474}
10475
10476/// PrimaryKeyColumnConstraint
10477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10478#[cfg_attr(feature = "bindings", derive(TS))]
10479pub struct PrimaryKeyColumnConstraint {
10480    #[serde(default)]
10481    pub desc: Option<Box<Expression>>,
10482    #[serde(default)]
10483    pub options: Vec<Expression>,
10484}
10485
10486/// UniqueColumnConstraint
10487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10488#[cfg_attr(feature = "bindings", derive(TS))]
10489pub struct UniqueColumnConstraint {
10490    #[serde(default)]
10491    pub this: Option<Box<Expression>>,
10492    #[serde(default)]
10493    pub index_type: Option<Box<Expression>>,
10494    #[serde(default)]
10495    pub on_conflict: Option<Box<Expression>>,
10496    #[serde(default)]
10497    pub nulls: Option<Box<Expression>>,
10498    #[serde(default)]
10499    pub options: Vec<Expression>,
10500}
10501
10502/// WatermarkColumnConstraint
10503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10504#[cfg_attr(feature = "bindings", derive(TS))]
10505pub struct WatermarkColumnConstraint {
10506    pub this: Box<Expression>,
10507    pub expression: Box<Expression>,
10508}
10509
10510/// ComputedColumnConstraint
10511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10512#[cfg_attr(feature = "bindings", derive(TS))]
10513pub struct ComputedColumnConstraint {
10514    pub this: Box<Expression>,
10515    #[serde(default)]
10516    pub persisted: Option<Box<Expression>>,
10517    #[serde(default)]
10518    pub not_null: Option<Box<Expression>>,
10519    #[serde(default)]
10520    pub data_type: Option<Box<Expression>>,
10521}
10522
10523/// InOutColumnConstraint
10524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10525#[cfg_attr(feature = "bindings", derive(TS))]
10526pub struct InOutColumnConstraint {
10527    #[serde(default)]
10528    pub input_: Option<Box<Expression>>,
10529    #[serde(default)]
10530    pub output: Option<Box<Expression>>,
10531}
10532
10533/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10535#[cfg_attr(feature = "bindings", derive(TS))]
10536pub struct PathColumnConstraint {
10537    pub this: Box<Expression>,
10538}
10539
10540/// Constraint
10541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10542#[cfg_attr(feature = "bindings", derive(TS))]
10543pub struct Constraint {
10544    pub this: Box<Expression>,
10545    #[serde(default)]
10546    pub expressions: Vec<Expression>,
10547}
10548
10549/// Export
10550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10551#[cfg_attr(feature = "bindings", derive(TS))]
10552pub struct Export {
10553    pub this: Box<Expression>,
10554    #[serde(default)]
10555    pub connection: Option<Box<Expression>>,
10556    #[serde(default)]
10557    pub options: Vec<Expression>,
10558}
10559
10560/// Filter
10561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10562#[cfg_attr(feature = "bindings", derive(TS))]
10563pub struct Filter {
10564    pub this: Box<Expression>,
10565    pub expression: Box<Expression>,
10566}
10567
10568/// Changes
10569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10570#[cfg_attr(feature = "bindings", derive(TS))]
10571pub struct Changes {
10572    #[serde(default)]
10573    pub information: Option<Box<Expression>>,
10574    #[serde(default)]
10575    pub at_before: Option<Box<Expression>>,
10576    #[serde(default)]
10577    pub end: Option<Box<Expression>>,
10578}
10579
10580/// Directory
10581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10582#[cfg_attr(feature = "bindings", derive(TS))]
10583pub struct Directory {
10584    pub this: Box<Expression>,
10585    #[serde(default)]
10586    pub local: Option<Box<Expression>>,
10587    #[serde(default)]
10588    pub row_format: Option<Box<Expression>>,
10589}
10590
10591/// ForeignKey
10592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10593#[cfg_attr(feature = "bindings", derive(TS))]
10594pub struct ForeignKey {
10595    #[serde(default)]
10596    pub expressions: Vec<Expression>,
10597    #[serde(default)]
10598    pub reference: Option<Box<Expression>>,
10599    #[serde(default)]
10600    pub delete: Option<Box<Expression>>,
10601    #[serde(default)]
10602    pub update: Option<Box<Expression>>,
10603    #[serde(default)]
10604    pub options: Vec<Expression>,
10605}
10606
10607/// ColumnPrefix
10608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10609#[cfg_attr(feature = "bindings", derive(TS))]
10610pub struct ColumnPrefix {
10611    pub this: Box<Expression>,
10612    pub expression: Box<Expression>,
10613}
10614
10615/// PrimaryKey
10616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10617#[cfg_attr(feature = "bindings", derive(TS))]
10618pub struct PrimaryKey {
10619    #[serde(default)]
10620    pub this: Option<Box<Expression>>,
10621    #[serde(default)]
10622    pub expressions: Vec<Expression>,
10623    #[serde(default)]
10624    pub options: Vec<Expression>,
10625    #[serde(default)]
10626    pub include: Option<Box<Expression>>,
10627}
10628
10629/// Into
10630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10631#[cfg_attr(feature = "bindings", derive(TS))]
10632pub struct IntoClause {
10633    #[serde(default)]
10634    pub this: Option<Box<Expression>>,
10635    #[serde(default)]
10636    pub temporary: bool,
10637    #[serde(default)]
10638    pub unlogged: Option<Box<Expression>>,
10639    #[serde(default)]
10640    pub bulk_collect: Option<Box<Expression>>,
10641    #[serde(default)]
10642    pub expressions: Vec<Expression>,
10643}
10644
10645/// JoinHint
10646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10647#[cfg_attr(feature = "bindings", derive(TS))]
10648pub struct JoinHint {
10649    pub this: Box<Expression>,
10650    #[serde(default)]
10651    pub expressions: Vec<Expression>,
10652}
10653
10654/// Opclass
10655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10656#[cfg_attr(feature = "bindings", derive(TS))]
10657pub struct Opclass {
10658    pub this: Box<Expression>,
10659    pub expression: Box<Expression>,
10660}
10661
10662/// Index
10663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10664#[cfg_attr(feature = "bindings", derive(TS))]
10665pub struct Index {
10666    #[serde(default)]
10667    pub this: Option<Box<Expression>>,
10668    #[serde(default)]
10669    pub table: Option<Box<Expression>>,
10670    #[serde(default)]
10671    pub unique: bool,
10672    #[serde(default)]
10673    pub primary: Option<Box<Expression>>,
10674    #[serde(default)]
10675    pub amp: Option<Box<Expression>>,
10676    #[serde(default)]
10677    pub params: Vec<Expression>,
10678}
10679
10680/// IndexParameters
10681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10682#[cfg_attr(feature = "bindings", derive(TS))]
10683pub struct IndexParameters {
10684    #[serde(default)]
10685    pub using: Option<Box<Expression>>,
10686    #[serde(default)]
10687    pub include: Option<Box<Expression>>,
10688    #[serde(default)]
10689    pub columns: Vec<Expression>,
10690    #[serde(default)]
10691    pub with_storage: Option<Box<Expression>>,
10692    #[serde(default)]
10693    pub partition_by: Option<Box<Expression>>,
10694    #[serde(default)]
10695    pub tablespace: Option<Box<Expression>>,
10696    #[serde(default)]
10697    pub where_: Option<Box<Expression>>,
10698    #[serde(default)]
10699    pub on: Option<Box<Expression>>,
10700}
10701
10702/// ConditionalInsert
10703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10704#[cfg_attr(feature = "bindings", derive(TS))]
10705pub struct ConditionalInsert {
10706    pub this: Box<Expression>,
10707    #[serde(default)]
10708    pub expression: Option<Box<Expression>>,
10709    #[serde(default)]
10710    pub else_: Option<Box<Expression>>,
10711}
10712
10713/// MultitableInserts
10714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10715#[cfg_attr(feature = "bindings", derive(TS))]
10716pub struct MultitableInserts {
10717    #[serde(default)]
10718    pub expressions: Vec<Expression>,
10719    pub kind: String,
10720    #[serde(default)]
10721    pub source: Option<Box<Expression>>,
10722    /// Leading comments before the statement
10723    #[serde(default)]
10724    pub leading_comments: Vec<String>,
10725    /// OVERWRITE modifier (Snowflake: INSERT OVERWRITE ALL)
10726    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10727    pub overwrite: bool,
10728}
10729
10730/// OnConflict
10731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10732#[cfg_attr(feature = "bindings", derive(TS))]
10733pub struct OnConflict {
10734    #[serde(default)]
10735    pub duplicate: Option<Box<Expression>>,
10736    #[serde(default)]
10737    pub expressions: Vec<Expression>,
10738    #[serde(default)]
10739    pub action: Option<Box<Expression>>,
10740    #[serde(default)]
10741    pub conflict_keys: Option<Box<Expression>>,
10742    #[serde(default)]
10743    pub index_predicate: Option<Box<Expression>>,
10744    #[serde(default)]
10745    pub constraint: Option<Box<Expression>>,
10746    #[serde(default)]
10747    pub where_: Option<Box<Expression>>,
10748}
10749
10750/// OnCondition
10751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10752#[cfg_attr(feature = "bindings", derive(TS))]
10753pub struct OnCondition {
10754    #[serde(default)]
10755    pub error: Option<Box<Expression>>,
10756    #[serde(default)]
10757    pub empty: Option<Box<Expression>>,
10758    #[serde(default)]
10759    pub null: Option<Box<Expression>>,
10760}
10761
10762/// Returning
10763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10764#[cfg_attr(feature = "bindings", derive(TS))]
10765pub struct Returning {
10766    #[serde(default)]
10767    pub expressions: Vec<Expression>,
10768    #[serde(default)]
10769    pub into: Option<Box<Expression>>,
10770}
10771
10772/// Introducer
10773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10774#[cfg_attr(feature = "bindings", derive(TS))]
10775pub struct Introducer {
10776    pub this: Box<Expression>,
10777    pub expression: Box<Expression>,
10778}
10779
10780/// PartitionRange
10781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10782#[cfg_attr(feature = "bindings", derive(TS))]
10783pub struct PartitionRange {
10784    pub this: Box<Expression>,
10785    #[serde(default)]
10786    pub expression: Option<Box<Expression>>,
10787    #[serde(default)]
10788    pub expressions: Vec<Expression>,
10789}
10790
10791/// Group
10792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10793#[cfg_attr(feature = "bindings", derive(TS))]
10794pub struct Group {
10795    #[serde(default)]
10796    pub expressions: Vec<Expression>,
10797    #[serde(default)]
10798    pub grouping_sets: Option<Box<Expression>>,
10799    #[serde(default)]
10800    pub cube: Option<Box<Expression>>,
10801    #[serde(default)]
10802    pub rollup: Option<Box<Expression>>,
10803    #[serde(default)]
10804    pub totals: Option<Box<Expression>>,
10805    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10806    #[serde(default)]
10807    pub all: Option<bool>,
10808}
10809
10810/// Cube
10811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10812#[cfg_attr(feature = "bindings", derive(TS))]
10813pub struct Cube {
10814    #[serde(default)]
10815    pub expressions: Vec<Expression>,
10816}
10817
10818/// Rollup
10819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10820#[cfg_attr(feature = "bindings", derive(TS))]
10821pub struct Rollup {
10822    #[serde(default)]
10823    pub expressions: Vec<Expression>,
10824}
10825
10826/// GroupingSets
10827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10828#[cfg_attr(feature = "bindings", derive(TS))]
10829pub struct GroupingSets {
10830    #[serde(default)]
10831    pub expressions: Vec<Expression>,
10832}
10833
10834/// LimitOptions
10835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10836#[cfg_attr(feature = "bindings", derive(TS))]
10837pub struct LimitOptions {
10838    #[serde(default)]
10839    pub percent: Option<Box<Expression>>,
10840    #[serde(default)]
10841    pub rows: Option<Box<Expression>>,
10842    #[serde(default)]
10843    pub with_ties: Option<Box<Expression>>,
10844}
10845
10846/// Lateral
10847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10848#[cfg_attr(feature = "bindings", derive(TS))]
10849pub struct Lateral {
10850    pub this: Box<Expression>,
10851    #[serde(default)]
10852    pub view: Option<Box<Expression>>,
10853    #[serde(default)]
10854    pub outer: Option<Box<Expression>>,
10855    #[serde(default)]
10856    pub alias: Option<String>,
10857    /// Whether the alias was originally quoted (backtick/double-quote)
10858    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10859    pub alias_quoted: bool,
10860    #[serde(default)]
10861    pub cross_apply: Option<Box<Expression>>,
10862    #[serde(default)]
10863    pub ordinality: Option<Box<Expression>>,
10864    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10865    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10866    pub column_aliases: Vec<String>,
10867}
10868
10869/// TableFromRows
10870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10871#[cfg_attr(feature = "bindings", derive(TS))]
10872pub struct TableFromRows {
10873    pub this: Box<Expression>,
10874    #[serde(default)]
10875    pub alias: Option<String>,
10876    #[serde(default)]
10877    pub joins: Vec<Expression>,
10878    #[serde(default)]
10879    pub pivots: Option<Box<Expression>>,
10880    #[serde(default)]
10881    pub sample: Option<Box<Expression>>,
10882}
10883
10884/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10885/// Used for set-returning functions with typed column definitions
10886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10887#[cfg_attr(feature = "bindings", derive(TS))]
10888pub struct RowsFrom {
10889    /// List of function expressions, each potentially with an alias and typed columns
10890    pub expressions: Vec<Expression>,
10891    /// WITH ORDINALITY modifier
10892    #[serde(default)]
10893    pub ordinality: bool,
10894    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10895    #[serde(default)]
10896    pub alias: Option<Box<Expression>>,
10897}
10898
10899/// WithFill
10900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10901#[cfg_attr(feature = "bindings", derive(TS))]
10902pub struct WithFill {
10903    #[serde(default)]
10904    pub from_: Option<Box<Expression>>,
10905    #[serde(default)]
10906    pub to: Option<Box<Expression>>,
10907    #[serde(default)]
10908    pub step: Option<Box<Expression>>,
10909    #[serde(default)]
10910    pub staleness: Option<Box<Expression>>,
10911    #[serde(default)]
10912    pub interpolate: Option<Box<Expression>>,
10913}
10914
10915/// Property
10916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10917#[cfg_attr(feature = "bindings", derive(TS))]
10918pub struct Property {
10919    pub this: Box<Expression>,
10920    #[serde(default)]
10921    pub value: Option<Box<Expression>>,
10922}
10923
10924/// GrantPrivilege
10925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10926#[cfg_attr(feature = "bindings", derive(TS))]
10927pub struct GrantPrivilege {
10928    pub this: Box<Expression>,
10929    #[serde(default)]
10930    pub expressions: Vec<Expression>,
10931}
10932
10933/// AllowedValuesProperty
10934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10935#[cfg_attr(feature = "bindings", derive(TS))]
10936pub struct AllowedValuesProperty {
10937    #[serde(default)]
10938    pub expressions: Vec<Expression>,
10939}
10940
10941/// AlgorithmProperty
10942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10943#[cfg_attr(feature = "bindings", derive(TS))]
10944pub struct AlgorithmProperty {
10945    pub this: Box<Expression>,
10946}
10947
10948/// AutoIncrementProperty
10949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10950#[cfg_attr(feature = "bindings", derive(TS))]
10951pub struct AutoIncrementProperty {
10952    pub this: Box<Expression>,
10953}
10954
10955/// AutoRefreshProperty
10956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10957#[cfg_attr(feature = "bindings", derive(TS))]
10958pub struct AutoRefreshProperty {
10959    pub this: Box<Expression>,
10960}
10961
10962/// BackupProperty
10963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10964#[cfg_attr(feature = "bindings", derive(TS))]
10965pub struct BackupProperty {
10966    pub this: Box<Expression>,
10967}
10968
10969/// BuildProperty
10970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10971#[cfg_attr(feature = "bindings", derive(TS))]
10972pub struct BuildProperty {
10973    pub this: Box<Expression>,
10974}
10975
10976/// BlockCompressionProperty
10977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10978#[cfg_attr(feature = "bindings", derive(TS))]
10979pub struct BlockCompressionProperty {
10980    #[serde(default)]
10981    pub autotemp: Option<Box<Expression>>,
10982    #[serde(default)]
10983    pub always: Option<Box<Expression>>,
10984    #[serde(default)]
10985    pub default: Option<Box<Expression>>,
10986    #[serde(default)]
10987    pub manual: Option<Box<Expression>>,
10988    #[serde(default)]
10989    pub never: Option<Box<Expression>>,
10990}
10991
10992/// CharacterSetProperty
10993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10994#[cfg_attr(feature = "bindings", derive(TS))]
10995pub struct CharacterSetProperty {
10996    pub this: Box<Expression>,
10997    #[serde(default)]
10998    pub default: Option<Box<Expression>>,
10999}
11000
11001/// ChecksumProperty
11002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11003#[cfg_attr(feature = "bindings", derive(TS))]
11004pub struct ChecksumProperty {
11005    #[serde(default)]
11006    pub on: Option<Box<Expression>>,
11007    #[serde(default)]
11008    pub default: Option<Box<Expression>>,
11009}
11010
11011/// CollateProperty
11012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11013#[cfg_attr(feature = "bindings", derive(TS))]
11014pub struct CollateProperty {
11015    pub this: Box<Expression>,
11016    #[serde(default)]
11017    pub default: Option<Box<Expression>>,
11018}
11019
11020/// DataBlocksizeProperty
11021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11022#[cfg_attr(feature = "bindings", derive(TS))]
11023pub struct DataBlocksizeProperty {
11024    #[serde(default)]
11025    pub size: Option<i64>,
11026    #[serde(default)]
11027    pub units: Option<Box<Expression>>,
11028    #[serde(default)]
11029    pub minimum: Option<Box<Expression>>,
11030    #[serde(default)]
11031    pub maximum: Option<Box<Expression>>,
11032    #[serde(default)]
11033    pub default: Option<Box<Expression>>,
11034}
11035
11036/// DataDeletionProperty
11037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11038#[cfg_attr(feature = "bindings", derive(TS))]
11039pub struct DataDeletionProperty {
11040    pub on: Box<Expression>,
11041    #[serde(default)]
11042    pub filter_column: Option<Box<Expression>>,
11043    #[serde(default)]
11044    pub retention_period: Option<Box<Expression>>,
11045}
11046
11047/// DefinerProperty
11048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11049#[cfg_attr(feature = "bindings", derive(TS))]
11050pub struct DefinerProperty {
11051    pub this: Box<Expression>,
11052}
11053
11054/// DistKeyProperty
11055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11056#[cfg_attr(feature = "bindings", derive(TS))]
11057pub struct DistKeyProperty {
11058    pub this: Box<Expression>,
11059}
11060
11061/// DistributedByProperty
11062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11063#[cfg_attr(feature = "bindings", derive(TS))]
11064pub struct DistributedByProperty {
11065    #[serde(default)]
11066    pub expressions: Vec<Expression>,
11067    pub kind: String,
11068    #[serde(default)]
11069    pub buckets: Option<Box<Expression>>,
11070    #[serde(default)]
11071    pub order: Option<Box<Expression>>,
11072}
11073
11074/// DistStyleProperty
11075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11076#[cfg_attr(feature = "bindings", derive(TS))]
11077pub struct DistStyleProperty {
11078    pub this: Box<Expression>,
11079}
11080
11081/// DuplicateKeyProperty
11082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11083#[cfg_attr(feature = "bindings", derive(TS))]
11084pub struct DuplicateKeyProperty {
11085    #[serde(default)]
11086    pub expressions: Vec<Expression>,
11087}
11088
11089/// EngineProperty
11090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11091#[cfg_attr(feature = "bindings", derive(TS))]
11092pub struct EngineProperty {
11093    pub this: Box<Expression>,
11094}
11095
11096/// ToTableProperty
11097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11098#[cfg_attr(feature = "bindings", derive(TS))]
11099pub struct ToTableProperty {
11100    pub this: Box<Expression>,
11101}
11102
11103/// ExecuteAsProperty
11104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11105#[cfg_attr(feature = "bindings", derive(TS))]
11106pub struct ExecuteAsProperty {
11107    pub this: Box<Expression>,
11108}
11109
11110/// ExternalProperty
11111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11112#[cfg_attr(feature = "bindings", derive(TS))]
11113pub struct ExternalProperty {
11114    #[serde(default)]
11115    pub this: Option<Box<Expression>>,
11116}
11117
11118/// FallbackProperty
11119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11120#[cfg_attr(feature = "bindings", derive(TS))]
11121pub struct FallbackProperty {
11122    #[serde(default)]
11123    pub no: Option<Box<Expression>>,
11124    #[serde(default)]
11125    pub protection: Option<Box<Expression>>,
11126}
11127
11128/// FileFormatProperty
11129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11130#[cfg_attr(feature = "bindings", derive(TS))]
11131pub struct FileFormatProperty {
11132    #[serde(default)]
11133    pub this: Option<Box<Expression>>,
11134    #[serde(default)]
11135    pub expressions: Vec<Expression>,
11136    #[serde(default)]
11137    pub hive_format: Option<Box<Expression>>,
11138}
11139
11140/// CredentialsProperty
11141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11142#[cfg_attr(feature = "bindings", derive(TS))]
11143pub struct CredentialsProperty {
11144    #[serde(default)]
11145    pub expressions: Vec<Expression>,
11146}
11147
11148/// FreespaceProperty
11149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11150#[cfg_attr(feature = "bindings", derive(TS))]
11151pub struct FreespaceProperty {
11152    pub this: Box<Expression>,
11153    #[serde(default)]
11154    pub percent: Option<Box<Expression>>,
11155}
11156
11157/// InheritsProperty
11158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11159#[cfg_attr(feature = "bindings", derive(TS))]
11160pub struct InheritsProperty {
11161    #[serde(default)]
11162    pub expressions: Vec<Expression>,
11163}
11164
11165/// InputModelProperty
11166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11167#[cfg_attr(feature = "bindings", derive(TS))]
11168pub struct InputModelProperty {
11169    pub this: Box<Expression>,
11170}
11171
11172/// OutputModelProperty
11173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11174#[cfg_attr(feature = "bindings", derive(TS))]
11175pub struct OutputModelProperty {
11176    pub this: Box<Expression>,
11177}
11178
11179/// IsolatedLoadingProperty
11180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11181#[cfg_attr(feature = "bindings", derive(TS))]
11182pub struct IsolatedLoadingProperty {
11183    #[serde(default)]
11184    pub no: Option<Box<Expression>>,
11185    #[serde(default)]
11186    pub concurrent: Option<Box<Expression>>,
11187    #[serde(default)]
11188    pub target: Option<Box<Expression>>,
11189}
11190
11191/// JournalProperty
11192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11193#[cfg_attr(feature = "bindings", derive(TS))]
11194pub struct JournalProperty {
11195    #[serde(default)]
11196    pub no: Option<Box<Expression>>,
11197    #[serde(default)]
11198    pub dual: Option<Box<Expression>>,
11199    #[serde(default)]
11200    pub before: Option<Box<Expression>>,
11201    #[serde(default)]
11202    pub local: Option<Box<Expression>>,
11203    #[serde(default)]
11204    pub after: Option<Box<Expression>>,
11205}
11206
11207/// LanguageProperty
11208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11209#[cfg_attr(feature = "bindings", derive(TS))]
11210pub struct LanguageProperty {
11211    pub this: Box<Expression>,
11212}
11213
11214/// EnviromentProperty
11215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11216#[cfg_attr(feature = "bindings", derive(TS))]
11217pub struct EnviromentProperty {
11218    #[serde(default)]
11219    pub expressions: Vec<Expression>,
11220}
11221
11222/// ClusteredByProperty
11223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11224#[cfg_attr(feature = "bindings", derive(TS))]
11225pub struct ClusteredByProperty {
11226    #[serde(default)]
11227    pub expressions: Vec<Expression>,
11228    #[serde(default)]
11229    pub sorted_by: Option<Box<Expression>>,
11230    #[serde(default)]
11231    pub buckets: Option<Box<Expression>>,
11232}
11233
11234/// DictProperty
11235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11236#[cfg_attr(feature = "bindings", derive(TS))]
11237pub struct DictProperty {
11238    pub this: Box<Expression>,
11239    pub kind: String,
11240    #[serde(default)]
11241    pub settings: Option<Box<Expression>>,
11242}
11243
11244/// DictRange
11245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11246#[cfg_attr(feature = "bindings", derive(TS))]
11247pub struct DictRange {
11248    pub this: Box<Expression>,
11249    #[serde(default)]
11250    pub min: Option<Box<Expression>>,
11251    #[serde(default)]
11252    pub max: Option<Box<Expression>>,
11253}
11254
11255/// OnCluster
11256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11257#[cfg_attr(feature = "bindings", derive(TS))]
11258pub struct OnCluster {
11259    pub this: Box<Expression>,
11260}
11261
11262/// LikeProperty
11263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11264#[cfg_attr(feature = "bindings", derive(TS))]
11265pub struct LikeProperty {
11266    pub this: Box<Expression>,
11267    #[serde(default)]
11268    pub expressions: Vec<Expression>,
11269}
11270
11271/// LocationProperty
11272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11273#[cfg_attr(feature = "bindings", derive(TS))]
11274pub struct LocationProperty {
11275    pub this: Box<Expression>,
11276}
11277
11278/// LockProperty
11279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11280#[cfg_attr(feature = "bindings", derive(TS))]
11281pub struct LockProperty {
11282    pub this: Box<Expression>,
11283}
11284
11285/// LockingProperty
11286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11287#[cfg_attr(feature = "bindings", derive(TS))]
11288pub struct LockingProperty {
11289    #[serde(default)]
11290    pub this: Option<Box<Expression>>,
11291    pub kind: String,
11292    #[serde(default)]
11293    pub for_or_in: Option<Box<Expression>>,
11294    #[serde(default)]
11295    pub lock_type: Option<Box<Expression>>,
11296    #[serde(default)]
11297    pub override_: Option<Box<Expression>>,
11298}
11299
11300/// LogProperty
11301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11302#[cfg_attr(feature = "bindings", derive(TS))]
11303pub struct LogProperty {
11304    #[serde(default)]
11305    pub no: Option<Box<Expression>>,
11306}
11307
11308/// MaterializedProperty
11309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11310#[cfg_attr(feature = "bindings", derive(TS))]
11311pub struct MaterializedProperty {
11312    #[serde(default)]
11313    pub this: Option<Box<Expression>>,
11314}
11315
11316/// MergeBlockRatioProperty
11317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11318#[cfg_attr(feature = "bindings", derive(TS))]
11319pub struct MergeBlockRatioProperty {
11320    #[serde(default)]
11321    pub this: Option<Box<Expression>>,
11322    #[serde(default)]
11323    pub no: Option<Box<Expression>>,
11324    #[serde(default)]
11325    pub default: Option<Box<Expression>>,
11326    #[serde(default)]
11327    pub percent: Option<Box<Expression>>,
11328}
11329
11330/// OnProperty
11331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11332#[cfg_attr(feature = "bindings", derive(TS))]
11333pub struct OnProperty {
11334    pub this: Box<Expression>,
11335}
11336
11337/// OnCommitProperty
11338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11339#[cfg_attr(feature = "bindings", derive(TS))]
11340pub struct OnCommitProperty {
11341    #[serde(default)]
11342    pub delete: Option<Box<Expression>>,
11343}
11344
11345/// PartitionedByProperty
11346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11347#[cfg_attr(feature = "bindings", derive(TS))]
11348pub struct PartitionedByProperty {
11349    pub this: Box<Expression>,
11350}
11351
11352/// BigQuery PARTITION BY property in CREATE TABLE statements.
11353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11354#[cfg_attr(feature = "bindings", derive(TS))]
11355pub struct PartitionByProperty {
11356    #[serde(default)]
11357    pub expressions: Vec<Expression>,
11358}
11359
11360/// PartitionedByBucket
11361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11362#[cfg_attr(feature = "bindings", derive(TS))]
11363pub struct PartitionedByBucket {
11364    pub this: Box<Expression>,
11365    pub expression: Box<Expression>,
11366}
11367
11368/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11370#[cfg_attr(feature = "bindings", derive(TS))]
11371pub struct ClusterByColumnsProperty {
11372    #[serde(default)]
11373    pub columns: Vec<Identifier>,
11374}
11375
11376/// PartitionByTruncate
11377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11378#[cfg_attr(feature = "bindings", derive(TS))]
11379pub struct PartitionByTruncate {
11380    pub this: Box<Expression>,
11381    pub expression: Box<Expression>,
11382}
11383
11384/// PartitionByRangeProperty
11385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11386#[cfg_attr(feature = "bindings", derive(TS))]
11387pub struct PartitionByRangeProperty {
11388    #[serde(default)]
11389    pub partition_expressions: Option<Box<Expression>>,
11390    #[serde(default)]
11391    pub create_expressions: Option<Box<Expression>>,
11392}
11393
11394/// PartitionByRangePropertyDynamic
11395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11396#[cfg_attr(feature = "bindings", derive(TS))]
11397pub struct PartitionByRangePropertyDynamic {
11398    #[serde(default)]
11399    pub this: Option<Box<Expression>>,
11400    #[serde(default)]
11401    pub start: Option<Box<Expression>>,
11402    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11403    #[serde(default)]
11404    pub use_start_end: bool,
11405    #[serde(default)]
11406    pub end: Option<Box<Expression>>,
11407    #[serde(default)]
11408    pub every: Option<Box<Expression>>,
11409}
11410
11411/// PartitionByListProperty
11412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11413#[cfg_attr(feature = "bindings", derive(TS))]
11414pub struct PartitionByListProperty {
11415    #[serde(default)]
11416    pub partition_expressions: Option<Box<Expression>>,
11417    #[serde(default)]
11418    pub create_expressions: Option<Box<Expression>>,
11419}
11420
11421/// PartitionList
11422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11423#[cfg_attr(feature = "bindings", derive(TS))]
11424pub struct PartitionList {
11425    pub this: Box<Expression>,
11426    #[serde(default)]
11427    pub expressions: Vec<Expression>,
11428}
11429
11430/// Partition - represents PARTITION/SUBPARTITION clause
11431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11432#[cfg_attr(feature = "bindings", derive(TS))]
11433pub struct Partition {
11434    pub expressions: Vec<Expression>,
11435    #[serde(default)]
11436    pub subpartition: bool,
11437}
11438
11439/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11440/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11442#[cfg_attr(feature = "bindings", derive(TS))]
11443pub struct RefreshTriggerProperty {
11444    /// Method: COMPLETE or AUTO
11445    pub method: String,
11446    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11447    #[serde(default)]
11448    pub kind: Option<String>,
11449    /// For SCHEDULE: EVERY n (the number)
11450    #[serde(default)]
11451    pub every: Option<Box<Expression>>,
11452    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11453    #[serde(default)]
11454    pub unit: Option<String>,
11455    /// For SCHEDULE: STARTS 'datetime'
11456    #[serde(default)]
11457    pub starts: Option<Box<Expression>>,
11458}
11459
11460/// UniqueKeyProperty
11461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11462#[cfg_attr(feature = "bindings", derive(TS))]
11463pub struct UniqueKeyProperty {
11464    #[serde(default)]
11465    pub expressions: Vec<Expression>,
11466}
11467
11468/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11470#[cfg_attr(feature = "bindings", derive(TS))]
11471pub struct RollupProperty {
11472    pub expressions: Vec<RollupIndex>,
11473}
11474
11475/// RollupIndex - A single rollup index: name(col1, col2)
11476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11477#[cfg_attr(feature = "bindings", derive(TS))]
11478pub struct RollupIndex {
11479    pub name: Identifier,
11480    pub expressions: Vec<Identifier>,
11481}
11482
11483/// PartitionBoundSpec
11484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11485#[cfg_attr(feature = "bindings", derive(TS))]
11486pub struct PartitionBoundSpec {
11487    #[serde(default)]
11488    pub this: Option<Box<Expression>>,
11489    #[serde(default)]
11490    pub expression: Option<Box<Expression>>,
11491    #[serde(default)]
11492    pub from_expressions: Option<Box<Expression>>,
11493    #[serde(default)]
11494    pub to_expressions: Option<Box<Expression>>,
11495}
11496
11497/// PartitionedOfProperty
11498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11499#[cfg_attr(feature = "bindings", derive(TS))]
11500pub struct PartitionedOfProperty {
11501    pub this: Box<Expression>,
11502    pub expression: Box<Expression>,
11503}
11504
11505/// RemoteWithConnectionModelProperty
11506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11507#[cfg_attr(feature = "bindings", derive(TS))]
11508pub struct RemoteWithConnectionModelProperty {
11509    pub this: Box<Expression>,
11510}
11511
11512/// ReturnsProperty
11513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11514#[cfg_attr(feature = "bindings", derive(TS))]
11515pub struct ReturnsProperty {
11516    #[serde(default)]
11517    pub this: Option<Box<Expression>>,
11518    #[serde(default)]
11519    pub is_table: Option<Box<Expression>>,
11520    #[serde(default)]
11521    pub table: Option<Box<Expression>>,
11522    #[serde(default)]
11523    pub null: Option<Box<Expression>>,
11524}
11525
11526/// RowFormatProperty
11527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11528#[cfg_attr(feature = "bindings", derive(TS))]
11529pub struct RowFormatProperty {
11530    pub this: Box<Expression>,
11531}
11532
11533/// RowFormatDelimitedProperty
11534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11535#[cfg_attr(feature = "bindings", derive(TS))]
11536pub struct RowFormatDelimitedProperty {
11537    #[serde(default)]
11538    pub fields: Option<Box<Expression>>,
11539    #[serde(default)]
11540    pub escaped: Option<Box<Expression>>,
11541    #[serde(default)]
11542    pub collection_items: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub map_keys: Option<Box<Expression>>,
11545    #[serde(default)]
11546    pub lines: Option<Box<Expression>>,
11547    #[serde(default)]
11548    pub null: Option<Box<Expression>>,
11549    #[serde(default)]
11550    pub serde: Option<Box<Expression>>,
11551}
11552
11553/// RowFormatSerdeProperty
11554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11555#[cfg_attr(feature = "bindings", derive(TS))]
11556pub struct RowFormatSerdeProperty {
11557    pub this: Box<Expression>,
11558    #[serde(default)]
11559    pub serde_properties: Option<Box<Expression>>,
11560}
11561
11562/// QueryTransform
11563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11564#[cfg_attr(feature = "bindings", derive(TS))]
11565pub struct QueryTransform {
11566    #[serde(default)]
11567    pub expressions: Vec<Expression>,
11568    #[serde(default)]
11569    pub command_script: Option<Box<Expression>>,
11570    #[serde(default)]
11571    pub schema: Option<Box<Expression>>,
11572    #[serde(default)]
11573    pub row_format_before: Option<Box<Expression>>,
11574    #[serde(default)]
11575    pub record_writer: Option<Box<Expression>>,
11576    #[serde(default)]
11577    pub row_format_after: Option<Box<Expression>>,
11578    #[serde(default)]
11579    pub record_reader: Option<Box<Expression>>,
11580}
11581
11582/// SampleProperty
11583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11584#[cfg_attr(feature = "bindings", derive(TS))]
11585pub struct SampleProperty {
11586    pub this: Box<Expression>,
11587}
11588
11589/// SecurityProperty
11590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11591#[cfg_attr(feature = "bindings", derive(TS))]
11592pub struct SecurityProperty {
11593    pub this: Box<Expression>,
11594}
11595
11596/// SchemaCommentProperty
11597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11598#[cfg_attr(feature = "bindings", derive(TS))]
11599pub struct SchemaCommentProperty {
11600    pub this: Box<Expression>,
11601}
11602
11603/// SemanticView
11604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11605#[cfg_attr(feature = "bindings", derive(TS))]
11606pub struct SemanticView {
11607    pub this: Box<Expression>,
11608    #[serde(default)]
11609    pub metrics: Option<Box<Expression>>,
11610    #[serde(default)]
11611    pub dimensions: Option<Box<Expression>>,
11612    #[serde(default)]
11613    pub facts: Option<Box<Expression>>,
11614    #[serde(default)]
11615    pub where_: Option<Box<Expression>>,
11616}
11617
11618/// SerdeProperties
11619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11620#[cfg_attr(feature = "bindings", derive(TS))]
11621pub struct SerdeProperties {
11622    #[serde(default)]
11623    pub expressions: Vec<Expression>,
11624    #[serde(default)]
11625    pub with_: Option<Box<Expression>>,
11626}
11627
11628/// SetProperty
11629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11630#[cfg_attr(feature = "bindings", derive(TS))]
11631pub struct SetProperty {
11632    #[serde(default)]
11633    pub multi: Option<Box<Expression>>,
11634}
11635
11636/// SharingProperty
11637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11638#[cfg_attr(feature = "bindings", derive(TS))]
11639pub struct SharingProperty {
11640    #[serde(default)]
11641    pub this: Option<Box<Expression>>,
11642}
11643
11644/// SetConfigProperty
11645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11646#[cfg_attr(feature = "bindings", derive(TS))]
11647pub struct SetConfigProperty {
11648    pub this: Box<Expression>,
11649}
11650
11651/// SettingsProperty
11652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11653#[cfg_attr(feature = "bindings", derive(TS))]
11654pub struct SettingsProperty {
11655    #[serde(default)]
11656    pub expressions: Vec<Expression>,
11657}
11658
11659/// SortKeyProperty
11660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11661#[cfg_attr(feature = "bindings", derive(TS))]
11662pub struct SortKeyProperty {
11663    pub this: Box<Expression>,
11664    #[serde(default)]
11665    pub compound: Option<Box<Expression>>,
11666}
11667
11668/// SqlReadWriteProperty
11669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11670#[cfg_attr(feature = "bindings", derive(TS))]
11671pub struct SqlReadWriteProperty {
11672    pub this: Box<Expression>,
11673}
11674
11675/// SqlSecurityProperty
11676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11677#[cfg_attr(feature = "bindings", derive(TS))]
11678pub struct SqlSecurityProperty {
11679    pub this: Box<Expression>,
11680}
11681
11682/// StabilityProperty
11683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11684#[cfg_attr(feature = "bindings", derive(TS))]
11685pub struct StabilityProperty {
11686    pub this: Box<Expression>,
11687}
11688
11689/// StorageHandlerProperty
11690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11691#[cfg_attr(feature = "bindings", derive(TS))]
11692pub struct StorageHandlerProperty {
11693    pub this: Box<Expression>,
11694}
11695
11696/// TemporaryProperty
11697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11698#[cfg_attr(feature = "bindings", derive(TS))]
11699pub struct TemporaryProperty {
11700    #[serde(default)]
11701    pub this: Option<Box<Expression>>,
11702}
11703
11704/// Tags
11705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11706#[cfg_attr(feature = "bindings", derive(TS))]
11707pub struct Tags {
11708    #[serde(default)]
11709    pub expressions: Vec<Expression>,
11710}
11711
11712/// TransformModelProperty
11713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11714#[cfg_attr(feature = "bindings", derive(TS))]
11715pub struct TransformModelProperty {
11716    #[serde(default)]
11717    pub expressions: Vec<Expression>,
11718}
11719
11720/// TransientProperty
11721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11722#[cfg_attr(feature = "bindings", derive(TS))]
11723pub struct TransientProperty {
11724    #[serde(default)]
11725    pub this: Option<Box<Expression>>,
11726}
11727
11728/// UsingTemplateProperty
11729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11730#[cfg_attr(feature = "bindings", derive(TS))]
11731pub struct UsingTemplateProperty {
11732    pub this: Box<Expression>,
11733}
11734
11735/// ViewAttributeProperty
11736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11737#[cfg_attr(feature = "bindings", derive(TS))]
11738pub struct ViewAttributeProperty {
11739    pub this: Box<Expression>,
11740}
11741
11742/// VolatileProperty
11743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11744#[cfg_attr(feature = "bindings", derive(TS))]
11745pub struct VolatileProperty {
11746    #[serde(default)]
11747    pub this: Option<Box<Expression>>,
11748}
11749
11750/// WithDataProperty
11751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11752#[cfg_attr(feature = "bindings", derive(TS))]
11753pub struct WithDataProperty {
11754    #[serde(default)]
11755    pub no: Option<Box<Expression>>,
11756    #[serde(default)]
11757    pub statistics: Option<Box<Expression>>,
11758}
11759
11760/// WithJournalTableProperty
11761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11762#[cfg_attr(feature = "bindings", derive(TS))]
11763pub struct WithJournalTableProperty {
11764    pub this: Box<Expression>,
11765}
11766
11767/// WithSchemaBindingProperty
11768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11769#[cfg_attr(feature = "bindings", derive(TS))]
11770pub struct WithSchemaBindingProperty {
11771    pub this: Box<Expression>,
11772}
11773
11774/// WithSystemVersioningProperty
11775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11776#[cfg_attr(feature = "bindings", derive(TS))]
11777pub struct WithSystemVersioningProperty {
11778    #[serde(default)]
11779    pub on: Option<Box<Expression>>,
11780    #[serde(default)]
11781    pub this: Option<Box<Expression>>,
11782    #[serde(default)]
11783    pub data_consistency: Option<Box<Expression>>,
11784    #[serde(default)]
11785    pub retention_period: Option<Box<Expression>>,
11786    #[serde(default)]
11787    pub with_: Option<Box<Expression>>,
11788}
11789
11790/// WithProcedureOptions
11791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11792#[cfg_attr(feature = "bindings", derive(TS))]
11793pub struct WithProcedureOptions {
11794    #[serde(default)]
11795    pub expressions: Vec<Expression>,
11796}
11797
11798/// EncodeProperty
11799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11800#[cfg_attr(feature = "bindings", derive(TS))]
11801pub struct EncodeProperty {
11802    pub this: Box<Expression>,
11803    #[serde(default)]
11804    pub properties: Vec<Expression>,
11805    #[serde(default)]
11806    pub key: Option<Box<Expression>>,
11807}
11808
11809/// IncludeProperty
11810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11811#[cfg_attr(feature = "bindings", derive(TS))]
11812pub struct IncludeProperty {
11813    pub this: Box<Expression>,
11814    #[serde(default)]
11815    pub alias: Option<String>,
11816    #[serde(default)]
11817    pub column_def: Option<Box<Expression>>,
11818}
11819
11820/// Properties
11821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11822#[cfg_attr(feature = "bindings", derive(TS))]
11823pub struct Properties {
11824    #[serde(default)]
11825    pub expressions: Vec<Expression>,
11826}
11827
11828/// Key/value pair in a BigQuery OPTIONS (...) clause.
11829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11830#[cfg_attr(feature = "bindings", derive(TS))]
11831pub struct OptionEntry {
11832    pub key: Identifier,
11833    pub value: Expression,
11834}
11835
11836/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11838#[cfg_attr(feature = "bindings", derive(TS))]
11839pub struct OptionsProperty {
11840    #[serde(default)]
11841    pub entries: Vec<OptionEntry>,
11842}
11843
11844/// InputOutputFormat
11845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11846#[cfg_attr(feature = "bindings", derive(TS))]
11847pub struct InputOutputFormat {
11848    #[serde(default)]
11849    pub input_format: Option<Box<Expression>>,
11850    #[serde(default)]
11851    pub output_format: Option<Box<Expression>>,
11852}
11853
11854/// Reference
11855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11856#[cfg_attr(feature = "bindings", derive(TS))]
11857pub struct Reference {
11858    pub this: Box<Expression>,
11859    #[serde(default)]
11860    pub expressions: Vec<Expression>,
11861    #[serde(default)]
11862    pub options: Vec<Expression>,
11863}
11864
11865/// QueryOption
11866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11867#[cfg_attr(feature = "bindings", derive(TS))]
11868pub struct QueryOption {
11869    pub this: Box<Expression>,
11870    #[serde(default)]
11871    pub expression: Option<Box<Expression>>,
11872}
11873
11874/// WithTableHint
11875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11876#[cfg_attr(feature = "bindings", derive(TS))]
11877pub struct WithTableHint {
11878    #[serde(default)]
11879    pub expressions: Vec<Expression>,
11880}
11881
11882/// IndexTableHint
11883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11884#[cfg_attr(feature = "bindings", derive(TS))]
11885pub struct IndexTableHint {
11886    pub this: Box<Expression>,
11887    #[serde(default)]
11888    pub expressions: Vec<Expression>,
11889    #[serde(default)]
11890    pub target: Option<Box<Expression>>,
11891}
11892
11893/// Get
11894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11895#[cfg_attr(feature = "bindings", derive(TS))]
11896pub struct Get {
11897    pub this: Box<Expression>,
11898    #[serde(default)]
11899    pub target: Option<Box<Expression>>,
11900    #[serde(default)]
11901    pub properties: Vec<Expression>,
11902}
11903
11904/// SetOperation
11905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11906#[cfg_attr(feature = "bindings", derive(TS))]
11907pub struct SetOperation {
11908    #[serde(default)]
11909    pub with_: Option<Box<Expression>>,
11910    pub this: Box<Expression>,
11911    pub expression: Box<Expression>,
11912    #[serde(default)]
11913    pub distinct: bool,
11914    #[serde(default)]
11915    pub by_name: Option<Box<Expression>>,
11916    #[serde(default)]
11917    pub side: Option<Box<Expression>>,
11918    #[serde(default)]
11919    pub kind: Option<String>,
11920    #[serde(default)]
11921    pub on: Option<Box<Expression>>,
11922}
11923
11924/// Var - Simple variable reference (for SQL variables, keywords as values)
11925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11926#[cfg_attr(feature = "bindings", derive(TS))]
11927pub struct Var {
11928    pub this: String,
11929}
11930
11931/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11933#[cfg_attr(feature = "bindings", derive(TS))]
11934pub struct Variadic {
11935    pub this: Box<Expression>,
11936}
11937
11938/// Version
11939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11940#[cfg_attr(feature = "bindings", derive(TS))]
11941pub struct Version {
11942    pub this: Box<Expression>,
11943    pub kind: String,
11944    #[serde(default)]
11945    pub expression: Option<Box<Expression>>,
11946}
11947
11948/// Schema
11949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11950#[cfg_attr(feature = "bindings", derive(TS))]
11951pub struct Schema {
11952    #[serde(default)]
11953    pub this: Option<Box<Expression>>,
11954    #[serde(default)]
11955    pub expressions: Vec<Expression>,
11956}
11957
11958/// Lock
11959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11960#[cfg_attr(feature = "bindings", derive(TS))]
11961pub struct Lock {
11962    #[serde(default)]
11963    pub update: Option<Box<Expression>>,
11964    #[serde(default)]
11965    pub expressions: Vec<Expression>,
11966    #[serde(default)]
11967    pub wait: Option<Box<Expression>>,
11968    #[serde(default)]
11969    pub key: Option<Box<Expression>>,
11970}
11971
11972/// TableSample - wraps an expression with a TABLESAMPLE clause
11973/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11975#[cfg_attr(feature = "bindings", derive(TS))]
11976pub struct TableSample {
11977    /// The expression being sampled (subquery, function, etc.)
11978    #[serde(default, skip_serializing_if = "Option::is_none")]
11979    pub this: Option<Box<Expression>>,
11980    /// The sample specification
11981    #[serde(default, skip_serializing_if = "Option::is_none")]
11982    pub sample: Option<Box<Sample>>,
11983    #[serde(default)]
11984    pub expressions: Vec<Expression>,
11985    #[serde(default)]
11986    pub method: Option<String>,
11987    #[serde(default)]
11988    pub bucket_numerator: Option<Box<Expression>>,
11989    #[serde(default)]
11990    pub bucket_denominator: Option<Box<Expression>>,
11991    #[serde(default)]
11992    pub bucket_field: Option<Box<Expression>>,
11993    #[serde(default)]
11994    pub percent: Option<Box<Expression>>,
11995    #[serde(default)]
11996    pub rows: Option<Box<Expression>>,
11997    #[serde(default)]
11998    pub size: Option<i64>,
11999    #[serde(default)]
12000    pub seed: Option<Box<Expression>>,
12001}
12002
12003/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
12004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12005#[cfg_attr(feature = "bindings", derive(TS))]
12006pub struct Tag {
12007    #[serde(default)]
12008    pub this: Option<Box<Expression>>,
12009    #[serde(default)]
12010    pub prefix: Option<Box<Expression>>,
12011    #[serde(default)]
12012    pub postfix: Option<Box<Expression>>,
12013}
12014
12015/// UnpivotColumns
12016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12017#[cfg_attr(feature = "bindings", derive(TS))]
12018pub struct UnpivotColumns {
12019    pub this: Box<Expression>,
12020    #[serde(default)]
12021    pub expressions: Vec<Expression>,
12022}
12023
12024/// SessionParameter
12025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12026#[cfg_attr(feature = "bindings", derive(TS))]
12027pub struct SessionParameter {
12028    pub this: Box<Expression>,
12029    #[serde(default)]
12030    pub kind: Option<String>,
12031}
12032
12033/// PseudoType
12034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12035#[cfg_attr(feature = "bindings", derive(TS))]
12036pub struct PseudoType {
12037    pub this: Box<Expression>,
12038}
12039
12040/// ObjectIdentifier
12041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12042#[cfg_attr(feature = "bindings", derive(TS))]
12043pub struct ObjectIdentifier {
12044    pub this: Box<Expression>,
12045}
12046
12047/// Transaction
12048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12049#[cfg_attr(feature = "bindings", derive(TS))]
12050pub struct Transaction {
12051    #[serde(default)]
12052    pub this: Option<Box<Expression>>,
12053    #[serde(default)]
12054    pub modes: Option<Box<Expression>>,
12055    #[serde(default)]
12056    pub mark: Option<Box<Expression>>,
12057}
12058
12059/// Commit
12060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12061#[cfg_attr(feature = "bindings", derive(TS))]
12062pub struct Commit {
12063    #[serde(default)]
12064    pub chain: Option<Box<Expression>>,
12065    #[serde(default)]
12066    pub this: Option<Box<Expression>>,
12067    #[serde(default)]
12068    pub durability: Option<Box<Expression>>,
12069}
12070
12071/// Rollback
12072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12073#[cfg_attr(feature = "bindings", derive(TS))]
12074pub struct Rollback {
12075    #[serde(default)]
12076    pub savepoint: Option<Box<Expression>>,
12077    #[serde(default)]
12078    pub this: Option<Box<Expression>>,
12079}
12080
12081/// AlterSession
12082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12083#[cfg_attr(feature = "bindings", derive(TS))]
12084pub struct AlterSession {
12085    #[serde(default)]
12086    pub expressions: Vec<Expression>,
12087    #[serde(default)]
12088    pub unset: Option<Box<Expression>>,
12089}
12090
12091/// Analyze
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct Analyze {
12095    #[serde(default)]
12096    pub kind: Option<String>,
12097    #[serde(default)]
12098    pub this: Option<Box<Expression>>,
12099    #[serde(default)]
12100    pub options: Vec<Expression>,
12101    #[serde(default)]
12102    pub mode: Option<Box<Expression>>,
12103    #[serde(default)]
12104    pub partition: Option<Box<Expression>>,
12105    #[serde(default)]
12106    pub expression: Option<Box<Expression>>,
12107    #[serde(default)]
12108    pub properties: Vec<Expression>,
12109    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
12110    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12111    pub columns: Vec<String>,
12112}
12113
12114/// AnalyzeStatistics
12115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12116#[cfg_attr(feature = "bindings", derive(TS))]
12117pub struct AnalyzeStatistics {
12118    pub kind: String,
12119    #[serde(default)]
12120    pub option: Option<Box<Expression>>,
12121    #[serde(default)]
12122    pub this: Option<Box<Expression>>,
12123    #[serde(default)]
12124    pub expressions: Vec<Expression>,
12125}
12126
12127/// AnalyzeHistogram
12128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12129#[cfg_attr(feature = "bindings", derive(TS))]
12130pub struct AnalyzeHistogram {
12131    pub this: Box<Expression>,
12132    #[serde(default)]
12133    pub expressions: Vec<Expression>,
12134    #[serde(default)]
12135    pub expression: Option<Box<Expression>>,
12136    #[serde(default)]
12137    pub update_options: Option<Box<Expression>>,
12138}
12139
12140/// AnalyzeSample
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct AnalyzeSample {
12144    pub kind: String,
12145    #[serde(default)]
12146    pub sample: Option<Box<Expression>>,
12147}
12148
12149/// AnalyzeListChainedRows
12150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12151#[cfg_attr(feature = "bindings", derive(TS))]
12152pub struct AnalyzeListChainedRows {
12153    #[serde(default)]
12154    pub expression: Option<Box<Expression>>,
12155}
12156
12157/// AnalyzeDelete
12158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12159#[cfg_attr(feature = "bindings", derive(TS))]
12160pub struct AnalyzeDelete {
12161    #[serde(default)]
12162    pub kind: Option<String>,
12163}
12164
12165/// AnalyzeWith
12166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12167#[cfg_attr(feature = "bindings", derive(TS))]
12168pub struct AnalyzeWith {
12169    #[serde(default)]
12170    pub expressions: Vec<Expression>,
12171}
12172
12173/// AnalyzeValidate
12174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12175#[cfg_attr(feature = "bindings", derive(TS))]
12176pub struct AnalyzeValidate {
12177    pub kind: String,
12178    #[serde(default)]
12179    pub this: Option<Box<Expression>>,
12180    #[serde(default)]
12181    pub expression: Option<Box<Expression>>,
12182}
12183
12184/// AddPartition
12185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12186#[cfg_attr(feature = "bindings", derive(TS))]
12187pub struct AddPartition {
12188    pub this: Box<Expression>,
12189    #[serde(default)]
12190    pub exists: bool,
12191    #[serde(default)]
12192    pub location: Option<Box<Expression>>,
12193}
12194
12195/// AttachOption
12196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12197#[cfg_attr(feature = "bindings", derive(TS))]
12198pub struct AttachOption {
12199    pub this: Box<Expression>,
12200    #[serde(default)]
12201    pub expression: Option<Box<Expression>>,
12202}
12203
12204/// DropPartition
12205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12206#[cfg_attr(feature = "bindings", derive(TS))]
12207pub struct DropPartition {
12208    #[serde(default)]
12209    pub expressions: Vec<Expression>,
12210    #[serde(default)]
12211    pub exists: bool,
12212}
12213
12214/// ReplacePartition
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct ReplacePartition {
12218    pub expression: Box<Expression>,
12219    #[serde(default)]
12220    pub source: Option<Box<Expression>>,
12221}
12222
12223/// DPipe
12224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12225#[cfg_attr(feature = "bindings", derive(TS))]
12226pub struct DPipe {
12227    pub this: Box<Expression>,
12228    pub expression: Box<Expression>,
12229    #[serde(default)]
12230    pub safe: Option<Box<Expression>>,
12231}
12232
12233/// Operator
12234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12235#[cfg_attr(feature = "bindings", derive(TS))]
12236pub struct Operator {
12237    pub this: Box<Expression>,
12238    #[serde(default)]
12239    pub operator: Option<Box<Expression>>,
12240    pub expression: Box<Expression>,
12241    /// Comments between OPERATOR() and the RHS expression
12242    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12243    pub comments: Vec<String>,
12244}
12245
12246/// PivotAny
12247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12248#[cfg_attr(feature = "bindings", derive(TS))]
12249pub struct PivotAny {
12250    #[serde(default)]
12251    pub this: Option<Box<Expression>>,
12252}
12253
12254/// Aliases
12255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12256#[cfg_attr(feature = "bindings", derive(TS))]
12257pub struct Aliases {
12258    pub this: Box<Expression>,
12259    #[serde(default)]
12260    pub expressions: Vec<Expression>,
12261}
12262
12263/// AtIndex
12264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12265#[cfg_attr(feature = "bindings", derive(TS))]
12266pub struct AtIndex {
12267    pub this: Box<Expression>,
12268    pub expression: Box<Expression>,
12269}
12270
12271/// FromTimeZone
12272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12273#[cfg_attr(feature = "bindings", derive(TS))]
12274pub struct FromTimeZone {
12275    pub this: Box<Expression>,
12276    #[serde(default)]
12277    pub zone: Option<Box<Expression>>,
12278}
12279
12280/// Format override for a column in Teradata
12281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12282#[cfg_attr(feature = "bindings", derive(TS))]
12283pub struct FormatPhrase {
12284    pub this: Box<Expression>,
12285    pub format: String,
12286}
12287
12288/// ForIn
12289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12290#[cfg_attr(feature = "bindings", derive(TS))]
12291pub struct ForIn {
12292    pub this: Box<Expression>,
12293    pub expression: Box<Expression>,
12294}
12295
12296/// Automatically converts unit arg into a var.
12297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12298#[cfg_attr(feature = "bindings", derive(TS))]
12299pub struct TimeUnit {
12300    #[serde(default)]
12301    pub unit: Option<String>,
12302}
12303
12304/// IntervalOp
12305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12306#[cfg_attr(feature = "bindings", derive(TS))]
12307pub struct IntervalOp {
12308    #[serde(default)]
12309    pub unit: Option<String>,
12310    pub expression: Box<Expression>,
12311}
12312
12313/// HavingMax
12314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12315#[cfg_attr(feature = "bindings", derive(TS))]
12316pub struct HavingMax {
12317    pub this: Box<Expression>,
12318    pub expression: Box<Expression>,
12319    #[serde(default)]
12320    pub max: Option<Box<Expression>>,
12321}
12322
12323/// CosineDistance
12324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12325#[cfg_attr(feature = "bindings", derive(TS))]
12326pub struct CosineDistance {
12327    pub this: Box<Expression>,
12328    pub expression: Box<Expression>,
12329}
12330
12331/// DotProduct
12332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12333#[cfg_attr(feature = "bindings", derive(TS))]
12334pub struct DotProduct {
12335    pub this: Box<Expression>,
12336    pub expression: Box<Expression>,
12337}
12338
12339/// EuclideanDistance
12340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12341#[cfg_attr(feature = "bindings", derive(TS))]
12342pub struct EuclideanDistance {
12343    pub this: Box<Expression>,
12344    pub expression: Box<Expression>,
12345}
12346
12347/// ManhattanDistance
12348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12349#[cfg_attr(feature = "bindings", derive(TS))]
12350pub struct ManhattanDistance {
12351    pub this: Box<Expression>,
12352    pub expression: Box<Expression>,
12353}
12354
12355/// JarowinklerSimilarity
12356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12357#[cfg_attr(feature = "bindings", derive(TS))]
12358pub struct JarowinklerSimilarity {
12359    pub this: Box<Expression>,
12360    pub expression: Box<Expression>,
12361}
12362
12363/// Booland
12364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12365#[cfg_attr(feature = "bindings", derive(TS))]
12366pub struct Booland {
12367    pub this: Box<Expression>,
12368    pub expression: Box<Expression>,
12369}
12370
12371/// Boolor
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct Boolor {
12375    pub this: Box<Expression>,
12376    pub expression: Box<Expression>,
12377}
12378
12379/// ParameterizedAgg
12380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12381#[cfg_attr(feature = "bindings", derive(TS))]
12382pub struct ParameterizedAgg {
12383    pub this: Box<Expression>,
12384    #[serde(default)]
12385    pub expressions: Vec<Expression>,
12386    #[serde(default)]
12387    pub params: Vec<Expression>,
12388}
12389
12390/// ArgMax
12391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12392#[cfg_attr(feature = "bindings", derive(TS))]
12393pub struct ArgMax {
12394    pub this: Box<Expression>,
12395    pub expression: Box<Expression>,
12396    #[serde(default)]
12397    pub count: Option<Box<Expression>>,
12398}
12399
12400/// ArgMin
12401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12402#[cfg_attr(feature = "bindings", derive(TS))]
12403pub struct ArgMin {
12404    pub this: Box<Expression>,
12405    pub expression: Box<Expression>,
12406    #[serde(default)]
12407    pub count: Option<Box<Expression>>,
12408}
12409
12410/// ApproxTopK
12411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12412#[cfg_attr(feature = "bindings", derive(TS))]
12413pub struct ApproxTopK {
12414    pub this: Box<Expression>,
12415    #[serde(default)]
12416    pub expression: Option<Box<Expression>>,
12417    #[serde(default)]
12418    pub counters: Option<Box<Expression>>,
12419}
12420
12421/// ApproxTopKAccumulate
12422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12423#[cfg_attr(feature = "bindings", derive(TS))]
12424pub struct ApproxTopKAccumulate {
12425    pub this: Box<Expression>,
12426    #[serde(default)]
12427    pub expression: Option<Box<Expression>>,
12428}
12429
12430/// ApproxTopKCombine
12431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12432#[cfg_attr(feature = "bindings", derive(TS))]
12433pub struct ApproxTopKCombine {
12434    pub this: Box<Expression>,
12435    #[serde(default)]
12436    pub expression: Option<Box<Expression>>,
12437}
12438
12439/// ApproxTopKEstimate
12440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12441#[cfg_attr(feature = "bindings", derive(TS))]
12442pub struct ApproxTopKEstimate {
12443    pub this: Box<Expression>,
12444    #[serde(default)]
12445    pub expression: Option<Box<Expression>>,
12446}
12447
12448/// ApproxTopSum
12449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12450#[cfg_attr(feature = "bindings", derive(TS))]
12451pub struct ApproxTopSum {
12452    pub this: Box<Expression>,
12453    pub expression: Box<Expression>,
12454    #[serde(default)]
12455    pub count: Option<Box<Expression>>,
12456}
12457
12458/// ApproxQuantiles
12459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12460#[cfg_attr(feature = "bindings", derive(TS))]
12461pub struct ApproxQuantiles {
12462    pub this: Box<Expression>,
12463    #[serde(default)]
12464    pub expression: Option<Box<Expression>>,
12465}
12466
12467/// Minhash
12468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12469#[cfg_attr(feature = "bindings", derive(TS))]
12470pub struct Minhash {
12471    pub this: Box<Expression>,
12472    #[serde(default)]
12473    pub expressions: Vec<Expression>,
12474}
12475
12476/// FarmFingerprint
12477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12478#[cfg_attr(feature = "bindings", derive(TS))]
12479pub struct FarmFingerprint {
12480    #[serde(default)]
12481    pub expressions: Vec<Expression>,
12482}
12483
12484/// Float64
12485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12486#[cfg_attr(feature = "bindings", derive(TS))]
12487pub struct Float64 {
12488    pub this: Box<Expression>,
12489    #[serde(default)]
12490    pub expression: Option<Box<Expression>>,
12491}
12492
12493/// Transform
12494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12495#[cfg_attr(feature = "bindings", derive(TS))]
12496pub struct Transform {
12497    pub this: Box<Expression>,
12498    pub expression: Box<Expression>,
12499}
12500
12501/// Translate
12502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12503#[cfg_attr(feature = "bindings", derive(TS))]
12504pub struct Translate {
12505    pub this: Box<Expression>,
12506    #[serde(default)]
12507    pub from_: Option<Box<Expression>>,
12508    #[serde(default)]
12509    pub to: Option<Box<Expression>>,
12510}
12511
12512/// Grouping
12513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12514#[cfg_attr(feature = "bindings", derive(TS))]
12515pub struct Grouping {
12516    #[serde(default)]
12517    pub expressions: Vec<Expression>,
12518}
12519
12520/// GroupingId
12521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12522#[cfg_attr(feature = "bindings", derive(TS))]
12523pub struct GroupingId {
12524    #[serde(default)]
12525    pub expressions: Vec<Expression>,
12526}
12527
12528/// Anonymous
12529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12530#[cfg_attr(feature = "bindings", derive(TS))]
12531pub struct Anonymous {
12532    pub this: Box<Expression>,
12533    #[serde(default)]
12534    pub expressions: Vec<Expression>,
12535}
12536
12537/// AnonymousAggFunc
12538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12539#[cfg_attr(feature = "bindings", derive(TS))]
12540pub struct AnonymousAggFunc {
12541    pub this: Box<Expression>,
12542    #[serde(default)]
12543    pub expressions: Vec<Expression>,
12544}
12545
12546/// CombinedAggFunc
12547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12548#[cfg_attr(feature = "bindings", derive(TS))]
12549pub struct CombinedAggFunc {
12550    pub this: Box<Expression>,
12551    #[serde(default)]
12552    pub expressions: Vec<Expression>,
12553}
12554
12555/// CombinedParameterizedAgg
12556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12557#[cfg_attr(feature = "bindings", derive(TS))]
12558pub struct CombinedParameterizedAgg {
12559    pub this: Box<Expression>,
12560    #[serde(default)]
12561    pub expressions: Vec<Expression>,
12562    #[serde(default)]
12563    pub params: Vec<Expression>,
12564}
12565
12566/// HashAgg
12567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12568#[cfg_attr(feature = "bindings", derive(TS))]
12569pub struct HashAgg {
12570    pub this: Box<Expression>,
12571    #[serde(default)]
12572    pub expressions: Vec<Expression>,
12573}
12574
12575/// Hll
12576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12577#[cfg_attr(feature = "bindings", derive(TS))]
12578pub struct Hll {
12579    pub this: Box<Expression>,
12580    #[serde(default)]
12581    pub expressions: Vec<Expression>,
12582}
12583
12584/// Apply
12585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12586#[cfg_attr(feature = "bindings", derive(TS))]
12587pub struct Apply {
12588    pub this: Box<Expression>,
12589    pub expression: Box<Expression>,
12590}
12591
12592/// ToBoolean
12593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12594#[cfg_attr(feature = "bindings", derive(TS))]
12595pub struct ToBoolean {
12596    pub this: Box<Expression>,
12597    #[serde(default)]
12598    pub safe: Option<Box<Expression>>,
12599}
12600
12601/// List
12602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12603#[cfg_attr(feature = "bindings", derive(TS))]
12604pub struct List {
12605    #[serde(default)]
12606    pub expressions: Vec<Expression>,
12607}
12608
12609/// ToMap - Materialize-style map constructor
12610/// Can hold either:
12611/// - A SELECT subquery (MAP(SELECT 'a', 1))
12612/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12614#[cfg_attr(feature = "bindings", derive(TS))]
12615pub struct ToMap {
12616    /// Either a Select subquery or a Struct containing PropertyEQ entries
12617    pub this: Box<Expression>,
12618}
12619
12620/// Pad
12621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12622#[cfg_attr(feature = "bindings", derive(TS))]
12623pub struct Pad {
12624    pub this: Box<Expression>,
12625    pub expression: Box<Expression>,
12626    #[serde(default)]
12627    pub fill_pattern: Option<Box<Expression>>,
12628    #[serde(default)]
12629    pub is_left: Option<Box<Expression>>,
12630}
12631
12632/// ToChar
12633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12634#[cfg_attr(feature = "bindings", derive(TS))]
12635pub struct ToChar {
12636    pub this: Box<Expression>,
12637    #[serde(default)]
12638    pub format: Option<String>,
12639    #[serde(default)]
12640    pub nlsparam: Option<Box<Expression>>,
12641    #[serde(default)]
12642    pub is_numeric: Option<Box<Expression>>,
12643}
12644
12645/// StringFunc - String type conversion function (BigQuery STRING)
12646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12647#[cfg_attr(feature = "bindings", derive(TS))]
12648pub struct StringFunc {
12649    pub this: Box<Expression>,
12650    #[serde(default)]
12651    pub zone: Option<Box<Expression>>,
12652}
12653
12654/// ToNumber
12655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12656#[cfg_attr(feature = "bindings", derive(TS))]
12657pub struct ToNumber {
12658    pub this: Box<Expression>,
12659    #[serde(default)]
12660    pub format: Option<Box<Expression>>,
12661    #[serde(default)]
12662    pub nlsparam: Option<Box<Expression>>,
12663    #[serde(default)]
12664    pub precision: Option<Box<Expression>>,
12665    #[serde(default)]
12666    pub scale: Option<Box<Expression>>,
12667    #[serde(default)]
12668    pub safe: Option<Box<Expression>>,
12669    #[serde(default)]
12670    pub safe_name: Option<Box<Expression>>,
12671}
12672
12673/// ToDouble
12674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12675#[cfg_attr(feature = "bindings", derive(TS))]
12676pub struct ToDouble {
12677    pub this: Box<Expression>,
12678    #[serde(default)]
12679    pub format: Option<String>,
12680    #[serde(default)]
12681    pub safe: Option<Box<Expression>>,
12682}
12683
12684/// ToDecfloat
12685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12686#[cfg_attr(feature = "bindings", derive(TS))]
12687pub struct ToDecfloat {
12688    pub this: Box<Expression>,
12689    #[serde(default)]
12690    pub format: Option<String>,
12691}
12692
12693/// TryToDecfloat
12694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12695#[cfg_attr(feature = "bindings", derive(TS))]
12696pub struct TryToDecfloat {
12697    pub this: Box<Expression>,
12698    #[serde(default)]
12699    pub format: Option<String>,
12700}
12701
12702/// ToFile
12703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12704#[cfg_attr(feature = "bindings", derive(TS))]
12705pub struct ToFile {
12706    pub this: Box<Expression>,
12707    #[serde(default)]
12708    pub path: Option<Box<Expression>>,
12709    #[serde(default)]
12710    pub safe: Option<Box<Expression>>,
12711}
12712
12713/// Columns
12714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12715#[cfg_attr(feature = "bindings", derive(TS))]
12716pub struct Columns {
12717    pub this: Box<Expression>,
12718    #[serde(default)]
12719    pub unpack: Option<Box<Expression>>,
12720}
12721
12722/// ConvertToCharset
12723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12724#[cfg_attr(feature = "bindings", derive(TS))]
12725pub struct ConvertToCharset {
12726    pub this: Box<Expression>,
12727    #[serde(default)]
12728    pub dest: Option<Box<Expression>>,
12729    #[serde(default)]
12730    pub source: Option<Box<Expression>>,
12731}
12732
12733/// ConvertTimezone
12734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12735#[cfg_attr(feature = "bindings", derive(TS))]
12736pub struct ConvertTimezone {
12737    #[serde(default)]
12738    pub source_tz: Option<Box<Expression>>,
12739    #[serde(default)]
12740    pub target_tz: Option<Box<Expression>>,
12741    #[serde(default)]
12742    pub timestamp: Option<Box<Expression>>,
12743    #[serde(default)]
12744    pub options: Vec<Expression>,
12745}
12746
12747/// GenerateSeries
12748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12749#[cfg_attr(feature = "bindings", derive(TS))]
12750pub struct GenerateSeries {
12751    #[serde(default)]
12752    pub start: Option<Box<Expression>>,
12753    #[serde(default)]
12754    pub end: Option<Box<Expression>>,
12755    #[serde(default)]
12756    pub step: Option<Box<Expression>>,
12757    #[serde(default)]
12758    pub is_end_exclusive: Option<Box<Expression>>,
12759}
12760
12761/// AIAgg
12762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12763#[cfg_attr(feature = "bindings", derive(TS))]
12764pub struct AIAgg {
12765    pub this: Box<Expression>,
12766    pub expression: Box<Expression>,
12767}
12768
12769/// AIClassify
12770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12771#[cfg_attr(feature = "bindings", derive(TS))]
12772pub struct AIClassify {
12773    pub this: Box<Expression>,
12774    #[serde(default)]
12775    pub categories: Option<Box<Expression>>,
12776    #[serde(default)]
12777    pub config: Option<Box<Expression>>,
12778}
12779
12780/// ArrayAll
12781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12782#[cfg_attr(feature = "bindings", derive(TS))]
12783pub struct ArrayAll {
12784    pub this: Box<Expression>,
12785    pub expression: Box<Expression>,
12786}
12787
12788/// ArrayAny
12789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12790#[cfg_attr(feature = "bindings", derive(TS))]
12791pub struct ArrayAny {
12792    pub this: Box<Expression>,
12793    pub expression: Box<Expression>,
12794}
12795
12796/// ArrayConstructCompact
12797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12798#[cfg_attr(feature = "bindings", derive(TS))]
12799pub struct ArrayConstructCompact {
12800    #[serde(default)]
12801    pub expressions: Vec<Expression>,
12802}
12803
12804/// StPoint
12805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12806#[cfg_attr(feature = "bindings", derive(TS))]
12807pub struct StPoint {
12808    pub this: Box<Expression>,
12809    pub expression: Box<Expression>,
12810    #[serde(default)]
12811    pub null: Option<Box<Expression>>,
12812}
12813
12814/// StDistance
12815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12816#[cfg_attr(feature = "bindings", derive(TS))]
12817pub struct StDistance {
12818    pub this: Box<Expression>,
12819    pub expression: Box<Expression>,
12820    #[serde(default)]
12821    pub use_spheroid: Option<Box<Expression>>,
12822}
12823
12824/// StringToArray
12825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12826#[cfg_attr(feature = "bindings", derive(TS))]
12827pub struct StringToArray {
12828    pub this: Box<Expression>,
12829    #[serde(default)]
12830    pub expression: Option<Box<Expression>>,
12831    #[serde(default)]
12832    pub null: Option<Box<Expression>>,
12833}
12834
12835/// ArraySum
12836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12837#[cfg_attr(feature = "bindings", derive(TS))]
12838pub struct ArraySum {
12839    pub this: Box<Expression>,
12840    #[serde(default)]
12841    pub expression: Option<Box<Expression>>,
12842}
12843
12844/// ObjectAgg
12845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12846#[cfg_attr(feature = "bindings", derive(TS))]
12847pub struct ObjectAgg {
12848    pub this: Box<Expression>,
12849    pub expression: Box<Expression>,
12850}
12851
12852/// CastToStrType
12853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12854#[cfg_attr(feature = "bindings", derive(TS))]
12855pub struct CastToStrType {
12856    pub this: Box<Expression>,
12857    #[serde(default)]
12858    pub to: Option<Box<Expression>>,
12859}
12860
12861/// CheckJson
12862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12863#[cfg_attr(feature = "bindings", derive(TS))]
12864pub struct CheckJson {
12865    pub this: Box<Expression>,
12866}
12867
12868/// CheckXml
12869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12870#[cfg_attr(feature = "bindings", derive(TS))]
12871pub struct CheckXml {
12872    pub this: Box<Expression>,
12873    #[serde(default)]
12874    pub disable_auto_convert: Option<Box<Expression>>,
12875}
12876
12877/// TranslateCharacters
12878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12879#[cfg_attr(feature = "bindings", derive(TS))]
12880pub struct TranslateCharacters {
12881    pub this: Box<Expression>,
12882    pub expression: Box<Expression>,
12883    #[serde(default)]
12884    pub with_error: Option<Box<Expression>>,
12885}
12886
12887/// CurrentSchemas
12888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12889#[cfg_attr(feature = "bindings", derive(TS))]
12890pub struct CurrentSchemas {
12891    #[serde(default)]
12892    pub this: Option<Box<Expression>>,
12893}
12894
12895/// CurrentDatetime
12896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12897#[cfg_attr(feature = "bindings", derive(TS))]
12898pub struct CurrentDatetime {
12899    #[serde(default)]
12900    pub this: Option<Box<Expression>>,
12901}
12902
12903/// Localtime
12904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12905#[cfg_attr(feature = "bindings", derive(TS))]
12906pub struct Localtime {
12907    #[serde(default)]
12908    pub this: Option<Box<Expression>>,
12909}
12910
12911/// Localtimestamp
12912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12913#[cfg_attr(feature = "bindings", derive(TS))]
12914pub struct Localtimestamp {
12915    #[serde(default)]
12916    pub this: Option<Box<Expression>>,
12917}
12918
12919/// Systimestamp
12920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12921#[cfg_attr(feature = "bindings", derive(TS))]
12922pub struct Systimestamp {
12923    #[serde(default)]
12924    pub this: Option<Box<Expression>>,
12925}
12926
12927/// CurrentSchema
12928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12929#[cfg_attr(feature = "bindings", derive(TS))]
12930pub struct CurrentSchema {
12931    #[serde(default)]
12932    pub this: Option<Box<Expression>>,
12933}
12934
12935/// CurrentUser
12936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12937#[cfg_attr(feature = "bindings", derive(TS))]
12938pub struct CurrentUser {
12939    #[serde(default)]
12940    pub this: Option<Box<Expression>>,
12941}
12942
12943/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12945#[cfg_attr(feature = "bindings", derive(TS))]
12946pub struct SessionUser;
12947
12948/// JSONPathRoot - Represents $ in JSON path expressions
12949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12950#[cfg_attr(feature = "bindings", derive(TS))]
12951pub struct JSONPathRoot;
12952
12953/// UtcTime
12954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12955#[cfg_attr(feature = "bindings", derive(TS))]
12956pub struct UtcTime {
12957    #[serde(default)]
12958    pub this: Option<Box<Expression>>,
12959}
12960
12961/// UtcTimestamp
12962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12963#[cfg_attr(feature = "bindings", derive(TS))]
12964pub struct UtcTimestamp {
12965    #[serde(default)]
12966    pub this: Option<Box<Expression>>,
12967}
12968
12969/// TimestampFunc - TIMESTAMP constructor function
12970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12971#[cfg_attr(feature = "bindings", derive(TS))]
12972pub struct TimestampFunc {
12973    #[serde(default)]
12974    pub this: Option<Box<Expression>>,
12975    #[serde(default)]
12976    pub zone: Option<Box<Expression>>,
12977    #[serde(default)]
12978    pub with_tz: Option<bool>,
12979    #[serde(default)]
12980    pub safe: Option<bool>,
12981}
12982
12983/// DateBin
12984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12985#[cfg_attr(feature = "bindings", derive(TS))]
12986pub struct DateBin {
12987    pub this: Box<Expression>,
12988    pub expression: Box<Expression>,
12989    #[serde(default)]
12990    pub unit: Option<String>,
12991    #[serde(default)]
12992    pub zone: Option<Box<Expression>>,
12993    #[serde(default)]
12994    pub origin: Option<Box<Expression>>,
12995}
12996
12997/// Datetime
12998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12999#[cfg_attr(feature = "bindings", derive(TS))]
13000pub struct Datetime {
13001    pub this: Box<Expression>,
13002    #[serde(default)]
13003    pub expression: Option<Box<Expression>>,
13004}
13005
13006/// DatetimeAdd
13007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13008#[cfg_attr(feature = "bindings", derive(TS))]
13009pub struct DatetimeAdd {
13010    pub this: Box<Expression>,
13011    pub expression: Box<Expression>,
13012    #[serde(default)]
13013    pub unit: Option<String>,
13014}
13015
13016/// DatetimeSub
13017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13018#[cfg_attr(feature = "bindings", derive(TS))]
13019pub struct DatetimeSub {
13020    pub this: Box<Expression>,
13021    pub expression: Box<Expression>,
13022    #[serde(default)]
13023    pub unit: Option<String>,
13024}
13025
13026/// DatetimeDiff
13027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13028#[cfg_attr(feature = "bindings", derive(TS))]
13029pub struct DatetimeDiff {
13030    pub this: Box<Expression>,
13031    pub expression: Box<Expression>,
13032    #[serde(default)]
13033    pub unit: Option<String>,
13034}
13035
13036/// DatetimeTrunc
13037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13038#[cfg_attr(feature = "bindings", derive(TS))]
13039pub struct DatetimeTrunc {
13040    pub this: Box<Expression>,
13041    pub unit: String,
13042    #[serde(default)]
13043    pub zone: Option<Box<Expression>>,
13044}
13045
13046/// Dayname
13047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13048#[cfg_attr(feature = "bindings", derive(TS))]
13049pub struct Dayname {
13050    pub this: Box<Expression>,
13051    #[serde(default)]
13052    pub abbreviated: Option<Box<Expression>>,
13053}
13054
13055/// MakeInterval
13056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13057#[cfg_attr(feature = "bindings", derive(TS))]
13058pub struct MakeInterval {
13059    #[serde(default)]
13060    pub year: Option<Box<Expression>>,
13061    #[serde(default)]
13062    pub month: Option<Box<Expression>>,
13063    #[serde(default)]
13064    pub week: Option<Box<Expression>>,
13065    #[serde(default)]
13066    pub day: Option<Box<Expression>>,
13067    #[serde(default)]
13068    pub hour: Option<Box<Expression>>,
13069    #[serde(default)]
13070    pub minute: Option<Box<Expression>>,
13071    #[serde(default)]
13072    pub second: Option<Box<Expression>>,
13073}
13074
13075/// PreviousDay
13076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13077#[cfg_attr(feature = "bindings", derive(TS))]
13078pub struct PreviousDay {
13079    pub this: Box<Expression>,
13080    pub expression: Box<Expression>,
13081}
13082
13083/// Elt
13084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13085#[cfg_attr(feature = "bindings", derive(TS))]
13086pub struct Elt {
13087    pub this: Box<Expression>,
13088    #[serde(default)]
13089    pub expressions: Vec<Expression>,
13090}
13091
13092/// TimestampAdd
13093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13094#[cfg_attr(feature = "bindings", derive(TS))]
13095pub struct TimestampAdd {
13096    pub this: Box<Expression>,
13097    pub expression: Box<Expression>,
13098    #[serde(default)]
13099    pub unit: Option<String>,
13100}
13101
13102/// TimestampSub
13103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13104#[cfg_attr(feature = "bindings", derive(TS))]
13105pub struct TimestampSub {
13106    pub this: Box<Expression>,
13107    pub expression: Box<Expression>,
13108    #[serde(default)]
13109    pub unit: Option<String>,
13110}
13111
13112/// TimestampDiff
13113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13114#[cfg_attr(feature = "bindings", derive(TS))]
13115pub struct TimestampDiff {
13116    pub this: Box<Expression>,
13117    pub expression: Box<Expression>,
13118    #[serde(default)]
13119    pub unit: Option<String>,
13120}
13121
13122/// TimeSlice
13123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13124#[cfg_attr(feature = "bindings", derive(TS))]
13125pub struct TimeSlice {
13126    pub this: Box<Expression>,
13127    pub expression: Box<Expression>,
13128    pub unit: String,
13129    #[serde(default)]
13130    pub kind: Option<String>,
13131}
13132
13133/// TimeAdd
13134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13135#[cfg_attr(feature = "bindings", derive(TS))]
13136pub struct TimeAdd {
13137    pub this: Box<Expression>,
13138    pub expression: Box<Expression>,
13139    #[serde(default)]
13140    pub unit: Option<String>,
13141}
13142
13143/// TimeSub
13144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13145#[cfg_attr(feature = "bindings", derive(TS))]
13146pub struct TimeSub {
13147    pub this: Box<Expression>,
13148    pub expression: Box<Expression>,
13149    #[serde(default)]
13150    pub unit: Option<String>,
13151}
13152
13153/// TimeDiff
13154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13155#[cfg_attr(feature = "bindings", derive(TS))]
13156pub struct TimeDiff {
13157    pub this: Box<Expression>,
13158    pub expression: Box<Expression>,
13159    #[serde(default)]
13160    pub unit: Option<String>,
13161}
13162
13163/// TimeTrunc
13164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13165#[cfg_attr(feature = "bindings", derive(TS))]
13166pub struct TimeTrunc {
13167    pub this: Box<Expression>,
13168    pub unit: String,
13169    #[serde(default)]
13170    pub zone: Option<Box<Expression>>,
13171}
13172
13173/// DateFromParts
13174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13175#[cfg_attr(feature = "bindings", derive(TS))]
13176pub struct DateFromParts {
13177    #[serde(default)]
13178    pub year: Option<Box<Expression>>,
13179    #[serde(default)]
13180    pub month: Option<Box<Expression>>,
13181    #[serde(default)]
13182    pub day: Option<Box<Expression>>,
13183    #[serde(default)]
13184    pub allow_overflow: Option<Box<Expression>>,
13185}
13186
13187/// TimeFromParts
13188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13189#[cfg_attr(feature = "bindings", derive(TS))]
13190pub struct TimeFromParts {
13191    #[serde(default)]
13192    pub hour: Option<Box<Expression>>,
13193    #[serde(default)]
13194    pub min: Option<Box<Expression>>,
13195    #[serde(default)]
13196    pub sec: Option<Box<Expression>>,
13197    #[serde(default)]
13198    pub nano: Option<Box<Expression>>,
13199    #[serde(default)]
13200    pub fractions: Option<Box<Expression>>,
13201    #[serde(default)]
13202    pub precision: Option<i64>,
13203}
13204
13205/// DecodeCase
13206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13207#[cfg_attr(feature = "bindings", derive(TS))]
13208pub struct DecodeCase {
13209    #[serde(default)]
13210    pub expressions: Vec<Expression>,
13211}
13212
13213/// Decrypt
13214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13215#[cfg_attr(feature = "bindings", derive(TS))]
13216pub struct Decrypt {
13217    pub this: Box<Expression>,
13218    #[serde(default)]
13219    pub passphrase: Option<Box<Expression>>,
13220    #[serde(default)]
13221    pub aad: Option<Box<Expression>>,
13222    #[serde(default)]
13223    pub encryption_method: Option<Box<Expression>>,
13224    #[serde(default)]
13225    pub safe: Option<Box<Expression>>,
13226}
13227
13228/// DecryptRaw
13229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13230#[cfg_attr(feature = "bindings", derive(TS))]
13231pub struct DecryptRaw {
13232    pub this: Box<Expression>,
13233    #[serde(default)]
13234    pub key: Option<Box<Expression>>,
13235    #[serde(default)]
13236    pub iv: Option<Box<Expression>>,
13237    #[serde(default)]
13238    pub aad: Option<Box<Expression>>,
13239    #[serde(default)]
13240    pub encryption_method: Option<Box<Expression>>,
13241    #[serde(default)]
13242    pub aead: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub safe: Option<Box<Expression>>,
13245}
13246
13247/// Encode
13248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13249#[cfg_attr(feature = "bindings", derive(TS))]
13250pub struct Encode {
13251    pub this: Box<Expression>,
13252    #[serde(default)]
13253    pub charset: Option<Box<Expression>>,
13254}
13255
13256/// Encrypt
13257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13258#[cfg_attr(feature = "bindings", derive(TS))]
13259pub struct Encrypt {
13260    pub this: Box<Expression>,
13261    #[serde(default)]
13262    pub passphrase: Option<Box<Expression>>,
13263    #[serde(default)]
13264    pub aad: Option<Box<Expression>>,
13265    #[serde(default)]
13266    pub encryption_method: Option<Box<Expression>>,
13267}
13268
13269/// EncryptRaw
13270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13271#[cfg_attr(feature = "bindings", derive(TS))]
13272pub struct EncryptRaw {
13273    pub this: Box<Expression>,
13274    #[serde(default)]
13275    pub key: Option<Box<Expression>>,
13276    #[serde(default)]
13277    pub iv: Option<Box<Expression>>,
13278    #[serde(default)]
13279    pub aad: Option<Box<Expression>>,
13280    #[serde(default)]
13281    pub encryption_method: Option<Box<Expression>>,
13282}
13283
13284/// EqualNull
13285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13286#[cfg_attr(feature = "bindings", derive(TS))]
13287pub struct EqualNull {
13288    pub this: Box<Expression>,
13289    pub expression: Box<Expression>,
13290}
13291
13292/// ToBinary
13293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13294#[cfg_attr(feature = "bindings", derive(TS))]
13295pub struct ToBinary {
13296    pub this: Box<Expression>,
13297    #[serde(default)]
13298    pub format: Option<String>,
13299    #[serde(default)]
13300    pub safe: Option<Box<Expression>>,
13301}
13302
13303/// Base64DecodeBinary
13304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13305#[cfg_attr(feature = "bindings", derive(TS))]
13306pub struct Base64DecodeBinary {
13307    pub this: Box<Expression>,
13308    #[serde(default)]
13309    pub alphabet: Option<Box<Expression>>,
13310}
13311
13312/// Base64DecodeString
13313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13314#[cfg_attr(feature = "bindings", derive(TS))]
13315pub struct Base64DecodeString {
13316    pub this: Box<Expression>,
13317    #[serde(default)]
13318    pub alphabet: Option<Box<Expression>>,
13319}
13320
13321/// Base64Encode
13322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13323#[cfg_attr(feature = "bindings", derive(TS))]
13324pub struct Base64Encode {
13325    pub this: Box<Expression>,
13326    #[serde(default)]
13327    pub max_line_length: Option<Box<Expression>>,
13328    #[serde(default)]
13329    pub alphabet: Option<Box<Expression>>,
13330}
13331
13332/// TryBase64DecodeBinary
13333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13334#[cfg_attr(feature = "bindings", derive(TS))]
13335pub struct TryBase64DecodeBinary {
13336    pub this: Box<Expression>,
13337    #[serde(default)]
13338    pub alphabet: Option<Box<Expression>>,
13339}
13340
13341/// TryBase64DecodeString
13342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13343#[cfg_attr(feature = "bindings", derive(TS))]
13344pub struct TryBase64DecodeString {
13345    pub this: Box<Expression>,
13346    #[serde(default)]
13347    pub alphabet: Option<Box<Expression>>,
13348}
13349
13350/// GapFill
13351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13352#[cfg_attr(feature = "bindings", derive(TS))]
13353pub struct GapFill {
13354    pub this: Box<Expression>,
13355    #[serde(default)]
13356    pub ts_column: Option<Box<Expression>>,
13357    #[serde(default)]
13358    pub bucket_width: Option<Box<Expression>>,
13359    #[serde(default)]
13360    pub partitioning_columns: Option<Box<Expression>>,
13361    #[serde(default)]
13362    pub value_columns: Option<Box<Expression>>,
13363    #[serde(default)]
13364    pub origin: Option<Box<Expression>>,
13365    #[serde(default)]
13366    pub ignore_nulls: Option<Box<Expression>>,
13367}
13368
13369/// GenerateDateArray
13370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13371#[cfg_attr(feature = "bindings", derive(TS))]
13372pub struct GenerateDateArray {
13373    #[serde(default)]
13374    pub start: Option<Box<Expression>>,
13375    #[serde(default)]
13376    pub end: Option<Box<Expression>>,
13377    #[serde(default)]
13378    pub step: Option<Box<Expression>>,
13379}
13380
13381/// GenerateTimestampArray
13382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13383#[cfg_attr(feature = "bindings", derive(TS))]
13384pub struct GenerateTimestampArray {
13385    #[serde(default)]
13386    pub start: Option<Box<Expression>>,
13387    #[serde(default)]
13388    pub end: Option<Box<Expression>>,
13389    #[serde(default)]
13390    pub step: Option<Box<Expression>>,
13391}
13392
13393/// GetExtract
13394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13395#[cfg_attr(feature = "bindings", derive(TS))]
13396pub struct GetExtract {
13397    pub this: Box<Expression>,
13398    pub expression: Box<Expression>,
13399}
13400
13401/// Getbit
13402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13403#[cfg_attr(feature = "bindings", derive(TS))]
13404pub struct Getbit {
13405    pub this: Box<Expression>,
13406    pub expression: Box<Expression>,
13407    #[serde(default)]
13408    pub zero_is_msb: Option<Box<Expression>>,
13409}
13410
13411/// OverflowTruncateBehavior
13412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13413#[cfg_attr(feature = "bindings", derive(TS))]
13414pub struct OverflowTruncateBehavior {
13415    #[serde(default)]
13416    pub this: Option<Box<Expression>>,
13417    #[serde(default)]
13418    pub with_count: Option<Box<Expression>>,
13419}
13420
13421/// HexEncode
13422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13423#[cfg_attr(feature = "bindings", derive(TS))]
13424pub struct HexEncode {
13425    pub this: Box<Expression>,
13426    #[serde(default)]
13427    pub case: Option<Box<Expression>>,
13428}
13429
13430/// Compress
13431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13432#[cfg_attr(feature = "bindings", derive(TS))]
13433pub struct Compress {
13434    pub this: Box<Expression>,
13435    #[serde(default)]
13436    pub method: Option<String>,
13437}
13438
13439/// DecompressBinary
13440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13441#[cfg_attr(feature = "bindings", derive(TS))]
13442pub struct DecompressBinary {
13443    pub this: Box<Expression>,
13444    pub method: String,
13445}
13446
13447/// DecompressString
13448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13449#[cfg_attr(feature = "bindings", derive(TS))]
13450pub struct DecompressString {
13451    pub this: Box<Expression>,
13452    pub method: String,
13453}
13454
13455/// Xor
13456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13457#[cfg_attr(feature = "bindings", derive(TS))]
13458pub struct Xor {
13459    #[serde(default)]
13460    pub this: Option<Box<Expression>>,
13461    #[serde(default)]
13462    pub expression: Option<Box<Expression>>,
13463    #[serde(default)]
13464    pub expressions: Vec<Expression>,
13465}
13466
13467/// Nullif
13468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13469#[cfg_attr(feature = "bindings", derive(TS))]
13470pub struct Nullif {
13471    pub this: Box<Expression>,
13472    pub expression: Box<Expression>,
13473}
13474
13475/// JSON
13476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13477#[cfg_attr(feature = "bindings", derive(TS))]
13478pub struct JSON {
13479    #[serde(default)]
13480    pub this: Option<Box<Expression>>,
13481    #[serde(default)]
13482    pub with_: Option<Box<Expression>>,
13483    #[serde(default)]
13484    pub unique: bool,
13485}
13486
13487/// JSONPath
13488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13489#[cfg_attr(feature = "bindings", derive(TS))]
13490pub struct JSONPath {
13491    #[serde(default)]
13492    pub expressions: Vec<Expression>,
13493    #[serde(default)]
13494    pub escape: Option<Box<Expression>>,
13495}
13496
13497/// JSONPathFilter
13498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13499#[cfg_attr(feature = "bindings", derive(TS))]
13500pub struct JSONPathFilter {
13501    pub this: Box<Expression>,
13502}
13503
13504/// JSONPathKey
13505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13506#[cfg_attr(feature = "bindings", derive(TS))]
13507pub struct JSONPathKey {
13508    pub this: Box<Expression>,
13509}
13510
13511/// JSONPathRecursive
13512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13513#[cfg_attr(feature = "bindings", derive(TS))]
13514pub struct JSONPathRecursive {
13515    #[serde(default)]
13516    pub this: Option<Box<Expression>>,
13517}
13518
13519/// JSONPathScript
13520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13521#[cfg_attr(feature = "bindings", derive(TS))]
13522pub struct JSONPathScript {
13523    pub this: Box<Expression>,
13524}
13525
13526/// JSONPathSlice
13527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13528#[cfg_attr(feature = "bindings", derive(TS))]
13529pub struct JSONPathSlice {
13530    #[serde(default)]
13531    pub start: Option<Box<Expression>>,
13532    #[serde(default)]
13533    pub end: Option<Box<Expression>>,
13534    #[serde(default)]
13535    pub step: Option<Box<Expression>>,
13536}
13537
13538/// JSONPathSelector
13539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13540#[cfg_attr(feature = "bindings", derive(TS))]
13541pub struct JSONPathSelector {
13542    pub this: Box<Expression>,
13543}
13544
13545/// JSONPathSubscript
13546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13547#[cfg_attr(feature = "bindings", derive(TS))]
13548pub struct JSONPathSubscript {
13549    pub this: Box<Expression>,
13550}
13551
13552/// JSONPathUnion
13553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13554#[cfg_attr(feature = "bindings", derive(TS))]
13555pub struct JSONPathUnion {
13556    #[serde(default)]
13557    pub expressions: Vec<Expression>,
13558}
13559
13560/// Format
13561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13562#[cfg_attr(feature = "bindings", derive(TS))]
13563pub struct Format {
13564    pub this: Box<Expression>,
13565    #[serde(default)]
13566    pub expressions: Vec<Expression>,
13567}
13568
13569/// JSONKeys
13570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13571#[cfg_attr(feature = "bindings", derive(TS))]
13572pub struct JSONKeys {
13573    pub this: Box<Expression>,
13574    #[serde(default)]
13575    pub expression: Option<Box<Expression>>,
13576    #[serde(default)]
13577    pub expressions: Vec<Expression>,
13578}
13579
13580/// JSONKeyValue
13581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13582#[cfg_attr(feature = "bindings", derive(TS))]
13583pub struct JSONKeyValue {
13584    pub this: Box<Expression>,
13585    pub expression: Box<Expression>,
13586}
13587
13588/// JSONKeysAtDepth
13589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13590#[cfg_attr(feature = "bindings", derive(TS))]
13591pub struct JSONKeysAtDepth {
13592    pub this: Box<Expression>,
13593    #[serde(default)]
13594    pub expression: Option<Box<Expression>>,
13595    #[serde(default)]
13596    pub mode: Option<Box<Expression>>,
13597}
13598
13599/// JSONObject
13600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13601#[cfg_attr(feature = "bindings", derive(TS))]
13602pub struct JSONObject {
13603    #[serde(default)]
13604    pub expressions: Vec<Expression>,
13605    #[serde(default)]
13606    pub null_handling: Option<Box<Expression>>,
13607    #[serde(default)]
13608    pub unique_keys: Option<Box<Expression>>,
13609    #[serde(default)]
13610    pub return_type: Option<Box<Expression>>,
13611    #[serde(default)]
13612    pub encoding: Option<Box<Expression>>,
13613}
13614
13615/// JSONObjectAgg
13616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13617#[cfg_attr(feature = "bindings", derive(TS))]
13618pub struct JSONObjectAgg {
13619    #[serde(default)]
13620    pub expressions: Vec<Expression>,
13621    #[serde(default)]
13622    pub null_handling: Option<Box<Expression>>,
13623    #[serde(default)]
13624    pub unique_keys: Option<Box<Expression>>,
13625    #[serde(default)]
13626    pub return_type: Option<Box<Expression>>,
13627    #[serde(default)]
13628    pub encoding: Option<Box<Expression>>,
13629}
13630
13631/// JSONBObjectAgg
13632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13633#[cfg_attr(feature = "bindings", derive(TS))]
13634pub struct JSONBObjectAgg {
13635    pub this: Box<Expression>,
13636    pub expression: Box<Expression>,
13637}
13638
13639/// JSONArray
13640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13641#[cfg_attr(feature = "bindings", derive(TS))]
13642pub struct JSONArray {
13643    #[serde(default)]
13644    pub expressions: Vec<Expression>,
13645    #[serde(default)]
13646    pub null_handling: Option<Box<Expression>>,
13647    #[serde(default)]
13648    pub return_type: Option<Box<Expression>>,
13649    #[serde(default)]
13650    pub strict: Option<Box<Expression>>,
13651}
13652
13653/// JSONArrayAgg
13654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13655#[cfg_attr(feature = "bindings", derive(TS))]
13656pub struct JSONArrayAgg {
13657    pub this: Box<Expression>,
13658    #[serde(default)]
13659    pub order: Option<Box<Expression>>,
13660    #[serde(default)]
13661    pub null_handling: Option<Box<Expression>>,
13662    #[serde(default)]
13663    pub return_type: Option<Box<Expression>>,
13664    #[serde(default)]
13665    pub strict: Option<Box<Expression>>,
13666}
13667
13668/// JSONExists
13669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13670#[cfg_attr(feature = "bindings", derive(TS))]
13671pub struct JSONExists {
13672    pub this: Box<Expression>,
13673    #[serde(default)]
13674    pub path: Option<Box<Expression>>,
13675    #[serde(default)]
13676    pub passing: Option<Box<Expression>>,
13677    #[serde(default)]
13678    pub on_condition: Option<Box<Expression>>,
13679    #[serde(default)]
13680    pub from_dcolonqmark: Option<Box<Expression>>,
13681}
13682
13683/// JSONColumnDef
13684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13685#[cfg_attr(feature = "bindings", derive(TS))]
13686pub struct JSONColumnDef {
13687    #[serde(default)]
13688    pub this: Option<Box<Expression>>,
13689    #[serde(default)]
13690    pub kind: Option<String>,
13691    #[serde(default)]
13692    pub format_json: bool,
13693    #[serde(default)]
13694    pub path: Option<Box<Expression>>,
13695    #[serde(default)]
13696    pub nested_schema: Option<Box<Expression>>,
13697    #[serde(default)]
13698    pub ordinality: Option<Box<Expression>>,
13699}
13700
13701/// JSONSchema
13702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13703#[cfg_attr(feature = "bindings", derive(TS))]
13704pub struct JSONSchema {
13705    #[serde(default)]
13706    pub expressions: Vec<Expression>,
13707}
13708
13709/// JSONSet
13710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13711#[cfg_attr(feature = "bindings", derive(TS))]
13712pub struct JSONSet {
13713    pub this: Box<Expression>,
13714    #[serde(default)]
13715    pub expressions: Vec<Expression>,
13716}
13717
13718/// JSONStripNulls
13719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13720#[cfg_attr(feature = "bindings", derive(TS))]
13721pub struct JSONStripNulls {
13722    pub this: Box<Expression>,
13723    #[serde(default)]
13724    pub expression: Option<Box<Expression>>,
13725    #[serde(default)]
13726    pub include_arrays: Option<Box<Expression>>,
13727    #[serde(default)]
13728    pub remove_empty: Option<Box<Expression>>,
13729}
13730
13731/// JSONValue
13732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13733#[cfg_attr(feature = "bindings", derive(TS))]
13734pub struct JSONValue {
13735    pub this: Box<Expression>,
13736    #[serde(default)]
13737    pub path: Option<Box<Expression>>,
13738    #[serde(default)]
13739    pub returning: Option<Box<Expression>>,
13740    #[serde(default)]
13741    pub on_condition: Option<Box<Expression>>,
13742}
13743
13744/// JSONValueArray
13745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13746#[cfg_attr(feature = "bindings", derive(TS))]
13747pub struct JSONValueArray {
13748    pub this: Box<Expression>,
13749    #[serde(default)]
13750    pub expression: Option<Box<Expression>>,
13751}
13752
13753/// JSONRemove
13754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13755#[cfg_attr(feature = "bindings", derive(TS))]
13756pub struct JSONRemove {
13757    pub this: Box<Expression>,
13758    #[serde(default)]
13759    pub expressions: Vec<Expression>,
13760}
13761
13762/// JSONTable
13763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13764#[cfg_attr(feature = "bindings", derive(TS))]
13765pub struct JSONTable {
13766    pub this: Box<Expression>,
13767    #[serde(default)]
13768    pub schema: Option<Box<Expression>>,
13769    #[serde(default)]
13770    pub path: Option<Box<Expression>>,
13771    #[serde(default)]
13772    pub error_handling: Option<Box<Expression>>,
13773    #[serde(default)]
13774    pub empty_handling: Option<Box<Expression>>,
13775}
13776
13777/// JSONType
13778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13779#[cfg_attr(feature = "bindings", derive(TS))]
13780pub struct JSONType {
13781    pub this: Box<Expression>,
13782    #[serde(default)]
13783    pub expression: Option<Box<Expression>>,
13784}
13785
13786/// ObjectInsert
13787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13788#[cfg_attr(feature = "bindings", derive(TS))]
13789pub struct ObjectInsert {
13790    pub this: Box<Expression>,
13791    #[serde(default)]
13792    pub key: Option<Box<Expression>>,
13793    #[serde(default)]
13794    pub value: Option<Box<Expression>>,
13795    #[serde(default)]
13796    pub update_flag: Option<Box<Expression>>,
13797}
13798
13799/// OpenJSONColumnDef
13800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13801#[cfg_attr(feature = "bindings", derive(TS))]
13802pub struct OpenJSONColumnDef {
13803    pub this: Box<Expression>,
13804    pub kind: String,
13805    #[serde(default)]
13806    pub path: Option<Box<Expression>>,
13807    #[serde(default)]
13808    pub as_json: Option<Box<Expression>>,
13809    /// The parsed data type for proper generation
13810    #[serde(default, skip_serializing_if = "Option::is_none")]
13811    pub data_type: Option<DataType>,
13812}
13813
13814/// OpenJSON
13815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13816#[cfg_attr(feature = "bindings", derive(TS))]
13817pub struct OpenJSON {
13818    pub this: Box<Expression>,
13819    #[serde(default)]
13820    pub path: Option<Box<Expression>>,
13821    #[serde(default)]
13822    pub expressions: Vec<Expression>,
13823}
13824
13825/// JSONBExists
13826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13827#[cfg_attr(feature = "bindings", derive(TS))]
13828pub struct JSONBExists {
13829    pub this: Box<Expression>,
13830    #[serde(default)]
13831    pub path: Option<Box<Expression>>,
13832}
13833
13834/// JSONCast
13835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13836#[cfg_attr(feature = "bindings", derive(TS))]
13837pub struct JSONCast {
13838    pub this: Box<Expression>,
13839    pub to: DataType,
13840}
13841
13842/// JSONExtract
13843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13844#[cfg_attr(feature = "bindings", derive(TS))]
13845pub struct JSONExtract {
13846    pub this: Box<Expression>,
13847    pub expression: Box<Expression>,
13848    #[serde(default)]
13849    pub only_json_types: Option<Box<Expression>>,
13850    #[serde(default)]
13851    pub expressions: Vec<Expression>,
13852    #[serde(default)]
13853    pub variant_extract: Option<Box<Expression>>,
13854    #[serde(default)]
13855    pub json_query: Option<Box<Expression>>,
13856    #[serde(default)]
13857    pub option: Option<Box<Expression>>,
13858    #[serde(default)]
13859    pub quote: Option<Box<Expression>>,
13860    #[serde(default)]
13861    pub on_condition: Option<Box<Expression>>,
13862    #[serde(default)]
13863    pub requires_json: Option<Box<Expression>>,
13864}
13865
13866/// JSONExtractQuote
13867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13868#[cfg_attr(feature = "bindings", derive(TS))]
13869pub struct JSONExtractQuote {
13870    #[serde(default)]
13871    pub option: Option<Box<Expression>>,
13872    #[serde(default)]
13873    pub scalar: Option<Box<Expression>>,
13874}
13875
13876/// JSONExtractArray
13877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13878#[cfg_attr(feature = "bindings", derive(TS))]
13879pub struct JSONExtractArray {
13880    pub this: Box<Expression>,
13881    #[serde(default)]
13882    pub expression: Option<Box<Expression>>,
13883}
13884
13885/// JSONExtractScalar
13886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13887#[cfg_attr(feature = "bindings", derive(TS))]
13888pub struct JSONExtractScalar {
13889    pub this: Box<Expression>,
13890    pub expression: Box<Expression>,
13891    #[serde(default)]
13892    pub only_json_types: Option<Box<Expression>>,
13893    #[serde(default)]
13894    pub expressions: Vec<Expression>,
13895    #[serde(default)]
13896    pub json_type: Option<Box<Expression>>,
13897    #[serde(default)]
13898    pub scalar_only: Option<Box<Expression>>,
13899}
13900
13901/// JSONBExtractScalar
13902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13903#[cfg_attr(feature = "bindings", derive(TS))]
13904pub struct JSONBExtractScalar {
13905    pub this: Box<Expression>,
13906    pub expression: Box<Expression>,
13907    #[serde(default)]
13908    pub json_type: Option<Box<Expression>>,
13909}
13910
13911/// JSONFormat
13912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13913#[cfg_attr(feature = "bindings", derive(TS))]
13914pub struct JSONFormat {
13915    #[serde(default)]
13916    pub this: Option<Box<Expression>>,
13917    #[serde(default)]
13918    pub options: Vec<Expression>,
13919    #[serde(default)]
13920    pub is_json: Option<Box<Expression>>,
13921    #[serde(default)]
13922    pub to_json: Option<Box<Expression>>,
13923}
13924
13925/// JSONArrayAppend
13926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13927#[cfg_attr(feature = "bindings", derive(TS))]
13928pub struct JSONArrayAppend {
13929    pub this: Box<Expression>,
13930    #[serde(default)]
13931    pub expressions: Vec<Expression>,
13932}
13933
13934/// JSONArrayContains
13935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13936#[cfg_attr(feature = "bindings", derive(TS))]
13937pub struct JSONArrayContains {
13938    pub this: Box<Expression>,
13939    pub expression: Box<Expression>,
13940    #[serde(default)]
13941    pub json_type: Option<Box<Expression>>,
13942}
13943
13944/// JSONArrayInsert
13945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13946#[cfg_attr(feature = "bindings", derive(TS))]
13947pub struct JSONArrayInsert {
13948    pub this: Box<Expression>,
13949    #[serde(default)]
13950    pub expressions: Vec<Expression>,
13951}
13952
13953/// ParseJSON
13954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13955#[cfg_attr(feature = "bindings", derive(TS))]
13956pub struct ParseJSON {
13957    pub this: Box<Expression>,
13958    #[serde(default)]
13959    pub expression: Option<Box<Expression>>,
13960    #[serde(default)]
13961    pub safe: Option<Box<Expression>>,
13962}
13963
13964/// ParseUrl
13965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13966#[cfg_attr(feature = "bindings", derive(TS))]
13967pub struct ParseUrl {
13968    pub this: Box<Expression>,
13969    #[serde(default)]
13970    pub part_to_extract: Option<Box<Expression>>,
13971    #[serde(default)]
13972    pub key: Option<Box<Expression>>,
13973    #[serde(default)]
13974    pub permissive: Option<Box<Expression>>,
13975}
13976
13977/// ParseIp
13978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13979#[cfg_attr(feature = "bindings", derive(TS))]
13980pub struct ParseIp {
13981    pub this: Box<Expression>,
13982    #[serde(default)]
13983    pub type_: Option<Box<Expression>>,
13984    #[serde(default)]
13985    pub permissive: Option<Box<Expression>>,
13986}
13987
13988/// ParseTime
13989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13990#[cfg_attr(feature = "bindings", derive(TS))]
13991pub struct ParseTime {
13992    pub this: Box<Expression>,
13993    pub format: String,
13994}
13995
13996/// ParseDatetime
13997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13998#[cfg_attr(feature = "bindings", derive(TS))]
13999pub struct ParseDatetime {
14000    pub this: Box<Expression>,
14001    #[serde(default)]
14002    pub format: Option<String>,
14003    #[serde(default)]
14004    pub zone: Option<Box<Expression>>,
14005}
14006
14007/// Map
14008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14009#[cfg_attr(feature = "bindings", derive(TS))]
14010pub struct Map {
14011    #[serde(default)]
14012    pub keys: Vec<Expression>,
14013    #[serde(default)]
14014    pub values: Vec<Expression>,
14015}
14016
14017/// MapCat
14018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14019#[cfg_attr(feature = "bindings", derive(TS))]
14020pub struct MapCat {
14021    pub this: Box<Expression>,
14022    pub expression: Box<Expression>,
14023}
14024
14025/// MapDelete
14026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14027#[cfg_attr(feature = "bindings", derive(TS))]
14028pub struct MapDelete {
14029    pub this: Box<Expression>,
14030    #[serde(default)]
14031    pub expressions: Vec<Expression>,
14032}
14033
14034/// MapInsert
14035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14036#[cfg_attr(feature = "bindings", derive(TS))]
14037pub struct MapInsert {
14038    pub this: Box<Expression>,
14039    #[serde(default)]
14040    pub key: Option<Box<Expression>>,
14041    #[serde(default)]
14042    pub value: Option<Box<Expression>>,
14043    #[serde(default)]
14044    pub update_flag: Option<Box<Expression>>,
14045}
14046
14047/// MapPick
14048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14049#[cfg_attr(feature = "bindings", derive(TS))]
14050pub struct MapPick {
14051    pub this: Box<Expression>,
14052    #[serde(default)]
14053    pub expressions: Vec<Expression>,
14054}
14055
14056/// ScopeResolution
14057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14058#[cfg_attr(feature = "bindings", derive(TS))]
14059pub struct ScopeResolution {
14060    #[serde(default)]
14061    pub this: Option<Box<Expression>>,
14062    pub expression: Box<Expression>,
14063}
14064
14065/// Slice
14066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14067#[cfg_attr(feature = "bindings", derive(TS))]
14068pub struct Slice {
14069    #[serde(default)]
14070    pub this: Option<Box<Expression>>,
14071    #[serde(default)]
14072    pub expression: Option<Box<Expression>>,
14073    #[serde(default)]
14074    pub step: Option<Box<Expression>>,
14075}
14076
14077/// VarMap
14078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14079#[cfg_attr(feature = "bindings", derive(TS))]
14080pub struct VarMap {
14081    #[serde(default)]
14082    pub keys: Vec<Expression>,
14083    #[serde(default)]
14084    pub values: Vec<Expression>,
14085}
14086
14087/// MatchAgainst
14088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14089#[cfg_attr(feature = "bindings", derive(TS))]
14090pub struct MatchAgainst {
14091    pub this: Box<Expression>,
14092    #[serde(default)]
14093    pub expressions: Vec<Expression>,
14094    #[serde(default)]
14095    pub modifier: Option<Box<Expression>>,
14096}
14097
14098/// MD5Digest
14099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14100#[cfg_attr(feature = "bindings", derive(TS))]
14101pub struct MD5Digest {
14102    pub this: Box<Expression>,
14103    #[serde(default)]
14104    pub expressions: Vec<Expression>,
14105}
14106
14107/// Monthname
14108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14109#[cfg_attr(feature = "bindings", derive(TS))]
14110pub struct Monthname {
14111    pub this: Box<Expression>,
14112    #[serde(default)]
14113    pub abbreviated: Option<Box<Expression>>,
14114}
14115
14116/// Ntile
14117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14118#[cfg_attr(feature = "bindings", derive(TS))]
14119pub struct Ntile {
14120    #[serde(default)]
14121    pub this: Option<Box<Expression>>,
14122}
14123
14124/// Normalize
14125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14126#[cfg_attr(feature = "bindings", derive(TS))]
14127pub struct Normalize {
14128    pub this: Box<Expression>,
14129    #[serde(default)]
14130    pub form: Option<Box<Expression>>,
14131    #[serde(default)]
14132    pub is_casefold: Option<Box<Expression>>,
14133}
14134
14135/// Normal
14136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14137#[cfg_attr(feature = "bindings", derive(TS))]
14138pub struct Normal {
14139    pub this: Box<Expression>,
14140    #[serde(default)]
14141    pub stddev: Option<Box<Expression>>,
14142    #[serde(default)]
14143    pub gen: Option<Box<Expression>>,
14144}
14145
14146/// Predict
14147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14148#[cfg_attr(feature = "bindings", derive(TS))]
14149pub struct Predict {
14150    pub this: Box<Expression>,
14151    pub expression: Box<Expression>,
14152    #[serde(default)]
14153    pub params_struct: Option<Box<Expression>>,
14154}
14155
14156/// MLTranslate
14157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14158#[cfg_attr(feature = "bindings", derive(TS))]
14159pub struct MLTranslate {
14160    pub this: Box<Expression>,
14161    pub expression: Box<Expression>,
14162    #[serde(default)]
14163    pub params_struct: Option<Box<Expression>>,
14164}
14165
14166/// FeaturesAtTime
14167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14168#[cfg_attr(feature = "bindings", derive(TS))]
14169pub struct FeaturesAtTime {
14170    pub this: Box<Expression>,
14171    #[serde(default)]
14172    pub time: Option<Box<Expression>>,
14173    #[serde(default)]
14174    pub num_rows: Option<Box<Expression>>,
14175    #[serde(default)]
14176    pub ignore_feature_nulls: Option<Box<Expression>>,
14177}
14178
14179/// GenerateEmbedding
14180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14181#[cfg_attr(feature = "bindings", derive(TS))]
14182pub struct GenerateEmbedding {
14183    pub this: Box<Expression>,
14184    pub expression: Box<Expression>,
14185    #[serde(default)]
14186    pub params_struct: Option<Box<Expression>>,
14187    #[serde(default)]
14188    pub is_text: Option<Box<Expression>>,
14189}
14190
14191/// MLForecast
14192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14193#[cfg_attr(feature = "bindings", derive(TS))]
14194pub struct MLForecast {
14195    pub this: Box<Expression>,
14196    #[serde(default)]
14197    pub expression: Option<Box<Expression>>,
14198    #[serde(default)]
14199    pub params_struct: Option<Box<Expression>>,
14200}
14201
14202/// ModelAttribute
14203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14204#[cfg_attr(feature = "bindings", derive(TS))]
14205pub struct ModelAttribute {
14206    pub this: Box<Expression>,
14207    pub expression: Box<Expression>,
14208}
14209
14210/// VectorSearch
14211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14212#[cfg_attr(feature = "bindings", derive(TS))]
14213pub struct VectorSearch {
14214    pub this: Box<Expression>,
14215    #[serde(default)]
14216    pub column_to_search: Option<Box<Expression>>,
14217    #[serde(default)]
14218    pub query_table: Option<Box<Expression>>,
14219    #[serde(default)]
14220    pub query_column_to_search: Option<Box<Expression>>,
14221    #[serde(default)]
14222    pub top_k: Option<Box<Expression>>,
14223    #[serde(default)]
14224    pub distance_type: Option<Box<Expression>>,
14225    #[serde(default)]
14226    pub options: Vec<Expression>,
14227}
14228
14229/// Quantile
14230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14231#[cfg_attr(feature = "bindings", derive(TS))]
14232pub struct Quantile {
14233    pub this: Box<Expression>,
14234    #[serde(default)]
14235    pub quantile: Option<Box<Expression>>,
14236}
14237
14238/// ApproxQuantile
14239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14240#[cfg_attr(feature = "bindings", derive(TS))]
14241pub struct ApproxQuantile {
14242    pub this: Box<Expression>,
14243    #[serde(default)]
14244    pub quantile: Option<Box<Expression>>,
14245    #[serde(default)]
14246    pub accuracy: Option<Box<Expression>>,
14247    #[serde(default)]
14248    pub weight: Option<Box<Expression>>,
14249    #[serde(default)]
14250    pub error_tolerance: Option<Box<Expression>>,
14251}
14252
14253/// ApproxPercentileEstimate
14254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14255#[cfg_attr(feature = "bindings", derive(TS))]
14256pub struct ApproxPercentileEstimate {
14257    pub this: Box<Expression>,
14258    #[serde(default)]
14259    pub percentile: Option<Box<Expression>>,
14260}
14261
14262/// Randn
14263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14264#[cfg_attr(feature = "bindings", derive(TS))]
14265pub struct Randn {
14266    #[serde(default)]
14267    pub this: Option<Box<Expression>>,
14268}
14269
14270/// Randstr
14271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14272#[cfg_attr(feature = "bindings", derive(TS))]
14273pub struct Randstr {
14274    pub this: Box<Expression>,
14275    #[serde(default)]
14276    pub generator: Option<Box<Expression>>,
14277}
14278
14279/// RangeN
14280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14281#[cfg_attr(feature = "bindings", derive(TS))]
14282pub struct RangeN {
14283    pub this: Box<Expression>,
14284    #[serde(default)]
14285    pub expressions: Vec<Expression>,
14286    #[serde(default)]
14287    pub each: Option<Box<Expression>>,
14288}
14289
14290/// RangeBucket
14291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14292#[cfg_attr(feature = "bindings", derive(TS))]
14293pub struct RangeBucket {
14294    pub this: Box<Expression>,
14295    pub expression: Box<Expression>,
14296}
14297
14298/// ReadCSV
14299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14300#[cfg_attr(feature = "bindings", derive(TS))]
14301pub struct ReadCSV {
14302    pub this: Box<Expression>,
14303    #[serde(default)]
14304    pub expressions: Vec<Expression>,
14305}
14306
14307/// ReadParquet
14308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14309#[cfg_attr(feature = "bindings", derive(TS))]
14310pub struct ReadParquet {
14311    #[serde(default)]
14312    pub expressions: Vec<Expression>,
14313}
14314
14315/// Reduce
14316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14317#[cfg_attr(feature = "bindings", derive(TS))]
14318pub struct Reduce {
14319    pub this: Box<Expression>,
14320    #[serde(default)]
14321    pub initial: Option<Box<Expression>>,
14322    #[serde(default)]
14323    pub merge: Option<Box<Expression>>,
14324    #[serde(default)]
14325    pub finish: Option<Box<Expression>>,
14326}
14327
14328/// RegexpExtractAll
14329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14330#[cfg_attr(feature = "bindings", derive(TS))]
14331pub struct RegexpExtractAll {
14332    pub this: Box<Expression>,
14333    pub expression: Box<Expression>,
14334    #[serde(default)]
14335    pub group: Option<Box<Expression>>,
14336    #[serde(default)]
14337    pub parameters: Option<Box<Expression>>,
14338    #[serde(default)]
14339    pub position: Option<Box<Expression>>,
14340    #[serde(default)]
14341    pub occurrence: Option<Box<Expression>>,
14342}
14343
14344/// RegexpILike
14345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14346#[cfg_attr(feature = "bindings", derive(TS))]
14347pub struct RegexpILike {
14348    pub this: Box<Expression>,
14349    pub expression: Box<Expression>,
14350    #[serde(default)]
14351    pub flag: Option<Box<Expression>>,
14352}
14353
14354/// RegexpFullMatch
14355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14356#[cfg_attr(feature = "bindings", derive(TS))]
14357pub struct RegexpFullMatch {
14358    pub this: Box<Expression>,
14359    pub expression: Box<Expression>,
14360    #[serde(default)]
14361    pub options: Vec<Expression>,
14362}
14363
14364/// RegexpInstr
14365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14366#[cfg_attr(feature = "bindings", derive(TS))]
14367pub struct RegexpInstr {
14368    pub this: Box<Expression>,
14369    pub expression: Box<Expression>,
14370    #[serde(default)]
14371    pub position: Option<Box<Expression>>,
14372    #[serde(default)]
14373    pub occurrence: Option<Box<Expression>>,
14374    #[serde(default)]
14375    pub option: Option<Box<Expression>>,
14376    #[serde(default)]
14377    pub parameters: Option<Box<Expression>>,
14378    #[serde(default)]
14379    pub group: Option<Box<Expression>>,
14380}
14381
14382/// RegexpSplit
14383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14384#[cfg_attr(feature = "bindings", derive(TS))]
14385pub struct RegexpSplit {
14386    pub this: Box<Expression>,
14387    pub expression: Box<Expression>,
14388    #[serde(default)]
14389    pub limit: Option<Box<Expression>>,
14390}
14391
14392/// RegexpCount
14393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14394#[cfg_attr(feature = "bindings", derive(TS))]
14395pub struct RegexpCount {
14396    pub this: Box<Expression>,
14397    pub expression: Box<Expression>,
14398    #[serde(default)]
14399    pub position: Option<Box<Expression>>,
14400    #[serde(default)]
14401    pub parameters: Option<Box<Expression>>,
14402}
14403
14404/// RegrValx
14405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14406#[cfg_attr(feature = "bindings", derive(TS))]
14407pub struct RegrValx {
14408    pub this: Box<Expression>,
14409    pub expression: Box<Expression>,
14410}
14411
14412/// RegrValy
14413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14414#[cfg_attr(feature = "bindings", derive(TS))]
14415pub struct RegrValy {
14416    pub this: Box<Expression>,
14417    pub expression: Box<Expression>,
14418}
14419
14420/// RegrAvgy
14421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14422#[cfg_attr(feature = "bindings", derive(TS))]
14423pub struct RegrAvgy {
14424    pub this: Box<Expression>,
14425    pub expression: Box<Expression>,
14426}
14427
14428/// RegrAvgx
14429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14430#[cfg_attr(feature = "bindings", derive(TS))]
14431pub struct RegrAvgx {
14432    pub this: Box<Expression>,
14433    pub expression: Box<Expression>,
14434}
14435
14436/// RegrCount
14437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14438#[cfg_attr(feature = "bindings", derive(TS))]
14439pub struct RegrCount {
14440    pub this: Box<Expression>,
14441    pub expression: Box<Expression>,
14442}
14443
14444/// RegrIntercept
14445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14446#[cfg_attr(feature = "bindings", derive(TS))]
14447pub struct RegrIntercept {
14448    pub this: Box<Expression>,
14449    pub expression: Box<Expression>,
14450}
14451
14452/// RegrR2
14453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14454#[cfg_attr(feature = "bindings", derive(TS))]
14455pub struct RegrR2 {
14456    pub this: Box<Expression>,
14457    pub expression: Box<Expression>,
14458}
14459
14460/// RegrSxx
14461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14462#[cfg_attr(feature = "bindings", derive(TS))]
14463pub struct RegrSxx {
14464    pub this: Box<Expression>,
14465    pub expression: Box<Expression>,
14466}
14467
14468/// RegrSxy
14469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14470#[cfg_attr(feature = "bindings", derive(TS))]
14471pub struct RegrSxy {
14472    pub this: Box<Expression>,
14473    pub expression: Box<Expression>,
14474}
14475
14476/// RegrSyy
14477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14478#[cfg_attr(feature = "bindings", derive(TS))]
14479pub struct RegrSyy {
14480    pub this: Box<Expression>,
14481    pub expression: Box<Expression>,
14482}
14483
14484/// RegrSlope
14485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14486#[cfg_attr(feature = "bindings", derive(TS))]
14487pub struct RegrSlope {
14488    pub this: Box<Expression>,
14489    pub expression: Box<Expression>,
14490}
14491
14492/// SafeAdd
14493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14494#[cfg_attr(feature = "bindings", derive(TS))]
14495pub struct SafeAdd {
14496    pub this: Box<Expression>,
14497    pub expression: Box<Expression>,
14498}
14499
14500/// SafeDivide
14501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14502#[cfg_attr(feature = "bindings", derive(TS))]
14503pub struct SafeDivide {
14504    pub this: Box<Expression>,
14505    pub expression: Box<Expression>,
14506}
14507
14508/// SafeMultiply
14509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14510#[cfg_attr(feature = "bindings", derive(TS))]
14511pub struct SafeMultiply {
14512    pub this: Box<Expression>,
14513    pub expression: Box<Expression>,
14514}
14515
14516/// SafeSubtract
14517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14518#[cfg_attr(feature = "bindings", derive(TS))]
14519pub struct SafeSubtract {
14520    pub this: Box<Expression>,
14521    pub expression: Box<Expression>,
14522}
14523
14524/// SHA2
14525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14526#[cfg_attr(feature = "bindings", derive(TS))]
14527pub struct SHA2 {
14528    pub this: Box<Expression>,
14529    #[serde(default)]
14530    pub length: Option<i64>,
14531}
14532
14533/// SHA2Digest
14534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14535#[cfg_attr(feature = "bindings", derive(TS))]
14536pub struct SHA2Digest {
14537    pub this: Box<Expression>,
14538    #[serde(default)]
14539    pub length: Option<i64>,
14540}
14541
14542/// SortArray
14543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14544#[cfg_attr(feature = "bindings", derive(TS))]
14545pub struct SortArray {
14546    pub this: Box<Expression>,
14547    #[serde(default)]
14548    pub asc: Option<Box<Expression>>,
14549    #[serde(default)]
14550    pub nulls_first: Option<Box<Expression>>,
14551}
14552
14553/// SplitPart
14554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14555#[cfg_attr(feature = "bindings", derive(TS))]
14556pub struct SplitPart {
14557    pub this: Box<Expression>,
14558    #[serde(default)]
14559    pub delimiter: Option<Box<Expression>>,
14560    #[serde(default)]
14561    pub part_index: Option<Box<Expression>>,
14562}
14563
14564/// SUBSTRING_INDEX(str, delim, count)
14565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14566#[cfg_attr(feature = "bindings", derive(TS))]
14567pub struct SubstringIndex {
14568    pub this: Box<Expression>,
14569    #[serde(default)]
14570    pub delimiter: Option<Box<Expression>>,
14571    #[serde(default)]
14572    pub count: Option<Box<Expression>>,
14573}
14574
14575/// StandardHash
14576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14577#[cfg_attr(feature = "bindings", derive(TS))]
14578pub struct StandardHash {
14579    pub this: Box<Expression>,
14580    #[serde(default)]
14581    pub expression: Option<Box<Expression>>,
14582}
14583
14584/// StrPosition
14585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14586#[cfg_attr(feature = "bindings", derive(TS))]
14587pub struct StrPosition {
14588    pub this: Box<Expression>,
14589    #[serde(default)]
14590    pub substr: Option<Box<Expression>>,
14591    #[serde(default)]
14592    pub position: Option<Box<Expression>>,
14593    #[serde(default)]
14594    pub occurrence: Option<Box<Expression>>,
14595}
14596
14597/// Search
14598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14599#[cfg_attr(feature = "bindings", derive(TS))]
14600pub struct Search {
14601    pub this: Box<Expression>,
14602    pub expression: Box<Expression>,
14603    #[serde(default)]
14604    pub json_scope: Option<Box<Expression>>,
14605    #[serde(default)]
14606    pub analyzer: Option<Box<Expression>>,
14607    #[serde(default)]
14608    pub analyzer_options: Option<Box<Expression>>,
14609    #[serde(default)]
14610    pub search_mode: Option<Box<Expression>>,
14611}
14612
14613/// SearchIp
14614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14615#[cfg_attr(feature = "bindings", derive(TS))]
14616pub struct SearchIp {
14617    pub this: Box<Expression>,
14618    pub expression: Box<Expression>,
14619}
14620
14621/// StrToDate
14622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14623#[cfg_attr(feature = "bindings", derive(TS))]
14624pub struct StrToDate {
14625    pub this: Box<Expression>,
14626    #[serde(default)]
14627    pub format: Option<String>,
14628    #[serde(default)]
14629    pub safe: Option<Box<Expression>>,
14630}
14631
14632/// StrToTime
14633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14634#[cfg_attr(feature = "bindings", derive(TS))]
14635pub struct StrToTime {
14636    pub this: Box<Expression>,
14637    pub format: String,
14638    #[serde(default)]
14639    pub zone: Option<Box<Expression>>,
14640    #[serde(default)]
14641    pub safe: Option<Box<Expression>>,
14642    #[serde(default)]
14643    pub target_type: Option<Box<Expression>>,
14644}
14645
14646/// StrToUnix
14647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14648#[cfg_attr(feature = "bindings", derive(TS))]
14649pub struct StrToUnix {
14650    #[serde(default)]
14651    pub this: Option<Box<Expression>>,
14652    #[serde(default)]
14653    pub format: Option<String>,
14654}
14655
14656/// StrToMap
14657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14658#[cfg_attr(feature = "bindings", derive(TS))]
14659pub struct StrToMap {
14660    pub this: Box<Expression>,
14661    #[serde(default)]
14662    pub pair_delim: Option<Box<Expression>>,
14663    #[serde(default)]
14664    pub key_value_delim: Option<Box<Expression>>,
14665    #[serde(default)]
14666    pub duplicate_resolution_callback: Option<Box<Expression>>,
14667}
14668
14669/// NumberToStr
14670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14671#[cfg_attr(feature = "bindings", derive(TS))]
14672pub struct NumberToStr {
14673    pub this: Box<Expression>,
14674    pub format: String,
14675    #[serde(default)]
14676    pub culture: Option<Box<Expression>>,
14677}
14678
14679/// FromBase
14680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14681#[cfg_attr(feature = "bindings", derive(TS))]
14682pub struct FromBase {
14683    pub this: Box<Expression>,
14684    pub expression: Box<Expression>,
14685}
14686
14687/// Stuff
14688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14689#[cfg_attr(feature = "bindings", derive(TS))]
14690pub struct Stuff {
14691    pub this: Box<Expression>,
14692    #[serde(default)]
14693    pub start: Option<Box<Expression>>,
14694    #[serde(default)]
14695    pub length: Option<i64>,
14696    pub expression: Box<Expression>,
14697}
14698
14699/// TimeToStr
14700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14701#[cfg_attr(feature = "bindings", derive(TS))]
14702pub struct TimeToStr {
14703    pub this: Box<Expression>,
14704    pub format: String,
14705    #[serde(default)]
14706    pub culture: Option<Box<Expression>>,
14707    #[serde(default)]
14708    pub zone: Option<Box<Expression>>,
14709}
14710
14711/// TimeStrToTime
14712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14713#[cfg_attr(feature = "bindings", derive(TS))]
14714pub struct TimeStrToTime {
14715    pub this: Box<Expression>,
14716    #[serde(default)]
14717    pub zone: Option<Box<Expression>>,
14718}
14719
14720/// TsOrDsAdd
14721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14722#[cfg_attr(feature = "bindings", derive(TS))]
14723pub struct TsOrDsAdd {
14724    pub this: Box<Expression>,
14725    pub expression: Box<Expression>,
14726    #[serde(default)]
14727    pub unit: Option<String>,
14728    #[serde(default)]
14729    pub return_type: Option<Box<Expression>>,
14730}
14731
14732/// TsOrDsDiff
14733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14734#[cfg_attr(feature = "bindings", derive(TS))]
14735pub struct TsOrDsDiff {
14736    pub this: Box<Expression>,
14737    pub expression: Box<Expression>,
14738    #[serde(default)]
14739    pub unit: Option<String>,
14740}
14741
14742/// TsOrDsToDate
14743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14744#[cfg_attr(feature = "bindings", derive(TS))]
14745pub struct TsOrDsToDate {
14746    pub this: Box<Expression>,
14747    #[serde(default)]
14748    pub format: Option<String>,
14749    #[serde(default)]
14750    pub safe: Option<Box<Expression>>,
14751}
14752
14753/// TsOrDsToTime
14754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14755#[cfg_attr(feature = "bindings", derive(TS))]
14756pub struct TsOrDsToTime {
14757    pub this: Box<Expression>,
14758    #[serde(default)]
14759    pub format: Option<String>,
14760    #[serde(default)]
14761    pub safe: Option<Box<Expression>>,
14762}
14763
14764/// Unhex
14765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14766#[cfg_attr(feature = "bindings", derive(TS))]
14767pub struct Unhex {
14768    pub this: Box<Expression>,
14769    #[serde(default)]
14770    pub expression: Option<Box<Expression>>,
14771}
14772
14773/// Uniform
14774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14775#[cfg_attr(feature = "bindings", derive(TS))]
14776pub struct Uniform {
14777    pub this: Box<Expression>,
14778    pub expression: Box<Expression>,
14779    #[serde(default)]
14780    pub gen: Option<Box<Expression>>,
14781    #[serde(default)]
14782    pub seed: Option<Box<Expression>>,
14783}
14784
14785/// UnixToStr
14786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14787#[cfg_attr(feature = "bindings", derive(TS))]
14788pub struct UnixToStr {
14789    pub this: Box<Expression>,
14790    #[serde(default)]
14791    pub format: Option<String>,
14792}
14793
14794/// UnixToTime
14795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14796#[cfg_attr(feature = "bindings", derive(TS))]
14797pub struct UnixToTime {
14798    pub this: Box<Expression>,
14799    #[serde(default)]
14800    pub scale: Option<i64>,
14801    #[serde(default)]
14802    pub zone: Option<Box<Expression>>,
14803    #[serde(default)]
14804    pub hours: Option<Box<Expression>>,
14805    #[serde(default)]
14806    pub minutes: Option<Box<Expression>>,
14807    #[serde(default)]
14808    pub format: Option<String>,
14809    #[serde(default)]
14810    pub target_type: Option<Box<Expression>>,
14811}
14812
14813/// Uuid
14814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14815#[cfg_attr(feature = "bindings", derive(TS))]
14816pub struct Uuid {
14817    #[serde(default)]
14818    pub this: Option<Box<Expression>>,
14819    #[serde(default)]
14820    pub name: Option<String>,
14821    #[serde(default)]
14822    pub is_string: Option<Box<Expression>>,
14823}
14824
14825/// TimestampFromParts
14826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14827#[cfg_attr(feature = "bindings", derive(TS))]
14828pub struct TimestampFromParts {
14829    #[serde(default)]
14830    pub zone: Option<Box<Expression>>,
14831    #[serde(default)]
14832    pub milli: Option<Box<Expression>>,
14833    #[serde(default)]
14834    pub this: Option<Box<Expression>>,
14835    #[serde(default)]
14836    pub expression: Option<Box<Expression>>,
14837}
14838
14839/// TimestampTzFromParts
14840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14841#[cfg_attr(feature = "bindings", derive(TS))]
14842pub struct TimestampTzFromParts {
14843    #[serde(default)]
14844    pub zone: Option<Box<Expression>>,
14845}
14846
14847/// Corr
14848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14849#[cfg_attr(feature = "bindings", derive(TS))]
14850pub struct Corr {
14851    pub this: Box<Expression>,
14852    pub expression: Box<Expression>,
14853    #[serde(default)]
14854    pub null_on_zero_variance: Option<Box<Expression>>,
14855}
14856
14857/// WidthBucket
14858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14859#[cfg_attr(feature = "bindings", derive(TS))]
14860pub struct WidthBucket {
14861    pub this: Box<Expression>,
14862    #[serde(default)]
14863    pub min_value: Option<Box<Expression>>,
14864    #[serde(default)]
14865    pub max_value: Option<Box<Expression>>,
14866    #[serde(default)]
14867    pub num_buckets: Option<Box<Expression>>,
14868    #[serde(default)]
14869    pub threshold: Option<Box<Expression>>,
14870}
14871
14872/// CovarSamp
14873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14874#[cfg_attr(feature = "bindings", derive(TS))]
14875pub struct CovarSamp {
14876    pub this: Box<Expression>,
14877    pub expression: Box<Expression>,
14878}
14879
14880/// CovarPop
14881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14882#[cfg_attr(feature = "bindings", derive(TS))]
14883pub struct CovarPop {
14884    pub this: Box<Expression>,
14885    pub expression: Box<Expression>,
14886}
14887
14888/// Week
14889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14890#[cfg_attr(feature = "bindings", derive(TS))]
14891pub struct Week {
14892    pub this: Box<Expression>,
14893    #[serde(default)]
14894    pub mode: Option<Box<Expression>>,
14895}
14896
14897/// XMLElement
14898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14899#[cfg_attr(feature = "bindings", derive(TS))]
14900pub struct XMLElement {
14901    pub this: Box<Expression>,
14902    #[serde(default)]
14903    pub expressions: Vec<Expression>,
14904    #[serde(default)]
14905    pub evalname: Option<Box<Expression>>,
14906}
14907
14908/// XMLGet
14909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14910#[cfg_attr(feature = "bindings", derive(TS))]
14911pub struct XMLGet {
14912    pub this: Box<Expression>,
14913    pub expression: Box<Expression>,
14914    #[serde(default)]
14915    pub instance: Option<Box<Expression>>,
14916}
14917
14918/// XMLTable
14919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14920#[cfg_attr(feature = "bindings", derive(TS))]
14921pub struct XMLTable {
14922    pub this: Box<Expression>,
14923    #[serde(default)]
14924    pub namespaces: Option<Box<Expression>>,
14925    #[serde(default)]
14926    pub passing: Option<Box<Expression>>,
14927    #[serde(default)]
14928    pub columns: Vec<Expression>,
14929    #[serde(default)]
14930    pub by_ref: Option<Box<Expression>>,
14931}
14932
14933/// XMLKeyValueOption
14934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14935#[cfg_attr(feature = "bindings", derive(TS))]
14936pub struct XMLKeyValueOption {
14937    pub this: Box<Expression>,
14938    #[serde(default)]
14939    pub expression: Option<Box<Expression>>,
14940}
14941
14942/// Zipf
14943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14944#[cfg_attr(feature = "bindings", derive(TS))]
14945pub struct Zipf {
14946    pub this: Box<Expression>,
14947    #[serde(default)]
14948    pub elementcount: Option<Box<Expression>>,
14949    #[serde(default)]
14950    pub gen: Option<Box<Expression>>,
14951}
14952
14953/// Merge
14954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14955#[cfg_attr(feature = "bindings", derive(TS))]
14956pub struct Merge {
14957    pub this: Box<Expression>,
14958    pub using: Box<Expression>,
14959    #[serde(default)]
14960    pub on: Option<Box<Expression>>,
14961    #[serde(default)]
14962    pub using_cond: Option<Box<Expression>>,
14963    #[serde(default)]
14964    pub whens: Option<Box<Expression>>,
14965    #[serde(default)]
14966    pub with_: Option<Box<Expression>>,
14967    #[serde(default)]
14968    pub returning: Option<Box<Expression>>,
14969}
14970
14971/// When
14972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14973#[cfg_attr(feature = "bindings", derive(TS))]
14974pub struct When {
14975    #[serde(default)]
14976    pub matched: Option<Box<Expression>>,
14977    #[serde(default)]
14978    pub source: Option<Box<Expression>>,
14979    #[serde(default)]
14980    pub condition: Option<Box<Expression>>,
14981    pub then: Box<Expression>,
14982}
14983
14984/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14986#[cfg_attr(feature = "bindings", derive(TS))]
14987pub struct Whens {
14988    #[serde(default)]
14989    pub expressions: Vec<Expression>,
14990}
14991
14992/// NextValueFor
14993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14994#[cfg_attr(feature = "bindings", derive(TS))]
14995pub struct NextValueFor {
14996    pub this: Box<Expression>,
14997    #[serde(default)]
14998    pub order: Option<Box<Expression>>,
14999}
15000
15001#[cfg(test)]
15002mod tests {
15003    use super::*;
15004
15005    #[test]
15006    #[cfg(feature = "bindings")]
15007    fn export_typescript_types() {
15008        // This test exports TypeScript types to the generated directory
15009        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
15010        Expression::export_all(&ts_rs::Config::default())
15011            .expect("Failed to export Expression types");
15012    }
15013
15014    #[test]
15015    fn test_simple_select_builder() {
15016        let select = Select::new()
15017            .column(Expression::star())
15018            .from(Expression::Table(Box::new(TableRef::new("users"))));
15019
15020        assert_eq!(select.expressions.len(), 1);
15021        assert!(select.from.is_some());
15022    }
15023
15024    #[test]
15025    fn test_expression_alias() {
15026        let expr = Expression::column("id").alias("user_id");
15027
15028        match expr {
15029            Expression::Alias(a) => {
15030                assert_eq!(a.alias.name, "user_id");
15031            }
15032            _ => panic!("Expected Alias"),
15033        }
15034    }
15035
15036    #[test]
15037    fn test_literal_creation() {
15038        let num = Expression::number(42);
15039        let str = Expression::string("hello");
15040
15041        match num {
15042            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
15043                let Literal::Number(n) = lit.as_ref() else {
15044                    unreachable!()
15045                };
15046                assert_eq!(n, "42")
15047            }
15048            _ => panic!("Expected Number"),
15049        }
15050
15051        match str {
15052            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
15053                let Literal::String(s) = lit.as_ref() else {
15054                    unreachable!()
15055                };
15056                assert_eq!(s, "hello")
15057            }
15058            _ => panic!("Expected String"),
15059        }
15060    }
15061
15062    #[test]
15063    fn test_expression_sql() {
15064        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
15065        assert_eq!(expr.sql(), "SELECT 1 + 2");
15066    }
15067
15068    #[test]
15069    fn test_expression_sql_for() {
15070        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
15071        let sql = expr.sql_for(crate::DialectType::Generic);
15072        // Generic mode normalizes IF() to CASE WHEN
15073        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
15074    }
15075}