Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // Exasol: function call with EMITS clause
486    FunctionEmits(Box<FunctionEmits>),
487
488    // JSON functions
489    JsonExtract(Box<JsonExtractFunc>),
490    JsonExtractScalar(Box<JsonExtractFunc>),
491    JsonExtractPath(Box<JsonPathFunc>),
492    JsonArray(Box<VarArgFunc>),
493    JsonObject(Box<JsonObjectFunc>),
494    JsonQuery(Box<JsonExtractFunc>),
495    JsonValue(Box<JsonExtractFunc>),
496    JsonArrayLength(Box<UnaryFunc>),
497    JsonKeys(Box<UnaryFunc>),
498    JsonType(Box<UnaryFunc>),
499    ParseJson(Box<UnaryFunc>),
500    ToJson(Box<UnaryFunc>),
501    JsonSet(Box<JsonModifyFunc>),
502    JsonInsert(Box<JsonModifyFunc>),
503    JsonRemove(Box<JsonPathFunc>),
504    JsonMergePatch(Box<BinaryFunc>),
505    JsonArrayAgg(Box<JsonArrayAggFunc>),
506    JsonObjectAgg(Box<JsonObjectAggFunc>),
507
508    // Type casting/conversion
509    Convert(Box<ConvertFunc>),
510    Typeof(Box<UnaryFunc>),
511
512    // Additional expressions
513    Lambda(Box<LambdaExpr>),
514    Parameter(Box<Parameter>),
515    Placeholder(Placeholder),
516    NamedArgument(Box<NamedArgument>),
517    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
518    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
519    TableArgument(Box<TableArgument>),
520    SqlComment(Box<SqlComment>),
521
522    // Additional predicates
523    NullSafeEq(Box<BinaryOp>),
524    NullSafeNeq(Box<BinaryOp>),
525    Glob(Box<BinaryOp>),
526    SimilarTo(Box<SimilarToExpr>),
527    Any(Box<QuantifiedExpr>),
528    All(Box<QuantifiedExpr>),
529    Overlaps(Box<OverlapsExpr>),
530
531    // Bitwise operations
532    BitwiseLeftShift(Box<BinaryOp>),
533    BitwiseRightShift(Box<BinaryOp>),
534    BitwiseAndAgg(Box<AggFunc>),
535    BitwiseOrAgg(Box<AggFunc>),
536    BitwiseXorAgg(Box<AggFunc>),
537
538    // Array/struct/map access
539    Subscript(Box<Subscript>),
540    Dot(Box<DotAccess>),
541    MethodCall(Box<MethodCall>),
542    ArraySlice(Box<ArraySlice>),
543
544    // DDL statements
545    CreateTable(Box<CreateTable>),
546    DropTable(Box<DropTable>),
547    Undrop(Box<Undrop>),
548    AlterTable(Box<AlterTable>),
549    CreateIndex(Box<CreateIndex>),
550    DropIndex(Box<DropIndex>),
551    CreateView(Box<CreateView>),
552    DropView(Box<DropView>),
553    AlterView(Box<AlterView>),
554    AlterIndex(Box<AlterIndex>),
555    Truncate(Box<Truncate>),
556    Use(Box<Use>),
557    Cache(Box<Cache>),
558    Uncache(Box<Uncache>),
559    LoadData(Box<LoadData>),
560    Pragma(Box<Pragma>),
561    Grant(Box<Grant>),
562    Revoke(Box<Revoke>),
563    Comment(Box<Comment>),
564    SetStatement(Box<SetStatement>),
565    // Phase 4: Additional DDL statements
566    CreateSchema(Box<CreateSchema>),
567    DropSchema(Box<DropSchema>),
568    DropNamespace(Box<DropNamespace>),
569    CreateDatabase(Box<CreateDatabase>),
570    DropDatabase(Box<DropDatabase>),
571    CreateFunction(Box<CreateFunction>),
572    DropFunction(Box<DropFunction>),
573    CreateProcedure(Box<CreateProcedure>),
574    DropProcedure(Box<DropProcedure>),
575    CreateSequence(Box<CreateSequence>),
576    CreateSynonym(Box<CreateSynonym>),
577    DropSequence(Box<DropSequence>),
578    AlterSequence(Box<AlterSequence>),
579    CreateTrigger(Box<CreateTrigger>),
580    DropTrigger(Box<DropTrigger>),
581    CreateType(Box<CreateType>),
582    DropType(Box<DropType>),
583    Describe(Box<Describe>),
584    Show(Box<Show>),
585
586    // Transaction and other commands
587    Command(Box<Command>),
588    Kill(Box<Kill>),
589    /// EXEC/EXECUTE statement (TSQL stored procedure call)
590    Execute(Box<ExecuteStatement>),
591
592    /// Snowflake CREATE TASK statement
593    CreateTask(Box<CreateTask>),
594
595    // Placeholder for unparsed/raw SQL
596    Raw(Raw),
597
598    // Paren for grouping
599    Paren(Box<Paren>),
600
601    // Expression with trailing comments (for round-trip preservation)
602    Annotated(Box<Annotated>),
603
604    // === BATCH GENERATED EXPRESSION TYPES ===
605    // Generated from Python sqlglot expressions.py
606    Refresh(Box<Refresh>),
607    LockingStatement(Box<LockingStatement>),
608    SequenceProperties(Box<SequenceProperties>),
609    TruncateTable(Box<TruncateTable>),
610    Clone(Box<Clone>),
611    Attach(Box<Attach>),
612    Detach(Box<Detach>),
613    Install(Box<Install>),
614    Summarize(Box<Summarize>),
615    Declare(Box<Declare>),
616    DeclareItem(Box<DeclareItem>),
617    Set(Box<Set>),
618    Heredoc(Box<Heredoc>),
619    SetItem(Box<SetItem>),
620    QueryBand(Box<QueryBand>),
621    UserDefinedFunction(Box<UserDefinedFunction>),
622    RecursiveWithSearch(Box<RecursiveWithSearch>),
623    ProjectionDef(Box<ProjectionDef>),
624    TableAlias(Box<TableAlias>),
625    ByteString(Box<ByteString>),
626    HexStringExpr(Box<HexStringExpr>),
627    UnicodeString(Box<UnicodeString>),
628    ColumnPosition(Box<ColumnPosition>),
629    ColumnDef(Box<ColumnDef>),
630    AlterColumn(Box<AlterColumn>),
631    AlterSortKey(Box<AlterSortKey>),
632    AlterSet(Box<AlterSet>),
633    RenameColumn(Box<RenameColumn>),
634    Comprehension(Box<Comprehension>),
635    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
636    MergeTreeTTL(Box<MergeTreeTTL>),
637    IndexConstraintOption(Box<IndexConstraintOption>),
638    ColumnConstraint(Box<ColumnConstraint>),
639    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
640    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
641    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
642    CheckColumnConstraint(Box<CheckColumnConstraint>),
643    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
644    CompressColumnConstraint(Box<CompressColumnConstraint>),
645    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
646    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
647    WithOperator(Box<WithOperator>),
648    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
649    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
650    CommentColumnConstraint(CommentColumnConstraint),
651    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
652    IndexColumnConstraint(Box<IndexColumnConstraint>),
653    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
654    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
655    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
656    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
657    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
658    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
659    InOutColumnConstraint(Box<InOutColumnConstraint>),
660    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
661    PathColumnConstraint(Box<PathColumnConstraint>),
662    Constraint(Box<Constraint>),
663    Export(Box<Export>),
664    Filter(Box<Filter>),
665    Changes(Box<Changes>),
666    CopyParameter(Box<CopyParameter>),
667    Credentials(Box<Credentials>),
668    Directory(Box<Directory>),
669    ForeignKey(Box<ForeignKey>),
670    ColumnPrefix(Box<ColumnPrefix>),
671    PrimaryKey(Box<PrimaryKey>),
672    IntoClause(Box<IntoClause>),
673    JoinHint(Box<JoinHint>),
674    Opclass(Box<Opclass>),
675    Index(Box<Index>),
676    IndexParameters(Box<IndexParameters>),
677    ConditionalInsert(Box<ConditionalInsert>),
678    MultitableInserts(Box<MultitableInserts>),
679    OnConflict(Box<OnConflict>),
680    OnCondition(Box<OnCondition>),
681    Returning(Box<Returning>),
682    Introducer(Box<Introducer>),
683    PartitionRange(Box<PartitionRange>),
684    Fetch(Box<Fetch>),
685    Group(Box<Group>),
686    Cube(Box<Cube>),
687    Rollup(Box<Rollup>),
688    GroupingSets(Box<GroupingSets>),
689    LimitOptions(Box<LimitOptions>),
690    Lateral(Box<Lateral>),
691    TableFromRows(Box<TableFromRows>),
692    RowsFrom(Box<RowsFrom>),
693    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
694    WithFill(Box<WithFill>),
695    Property(Box<Property>),
696    GrantPrivilege(Box<GrantPrivilege>),
697    GrantPrincipal(Box<GrantPrincipal>),
698    AllowedValuesProperty(Box<AllowedValuesProperty>),
699    AlgorithmProperty(Box<AlgorithmProperty>),
700    AutoIncrementProperty(Box<AutoIncrementProperty>),
701    AutoRefreshProperty(Box<AutoRefreshProperty>),
702    BackupProperty(Box<BackupProperty>),
703    BuildProperty(Box<BuildProperty>),
704    BlockCompressionProperty(Box<BlockCompressionProperty>),
705    CharacterSetProperty(Box<CharacterSetProperty>),
706    ChecksumProperty(Box<ChecksumProperty>),
707    CollateProperty(Box<CollateProperty>),
708    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
709    DataDeletionProperty(Box<DataDeletionProperty>),
710    DefinerProperty(Box<DefinerProperty>),
711    DistKeyProperty(Box<DistKeyProperty>),
712    DistributedByProperty(Box<DistributedByProperty>),
713    DistStyleProperty(Box<DistStyleProperty>),
714    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
715    EngineProperty(Box<EngineProperty>),
716    ToTableProperty(Box<ToTableProperty>),
717    ExecuteAsProperty(Box<ExecuteAsProperty>),
718    ExternalProperty(Box<ExternalProperty>),
719    FallbackProperty(Box<FallbackProperty>),
720    FileFormatProperty(Box<FileFormatProperty>),
721    CredentialsProperty(Box<CredentialsProperty>),
722    FreespaceProperty(Box<FreespaceProperty>),
723    InheritsProperty(Box<InheritsProperty>),
724    InputModelProperty(Box<InputModelProperty>),
725    OutputModelProperty(Box<OutputModelProperty>),
726    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
727    JournalProperty(Box<JournalProperty>),
728    LanguageProperty(Box<LanguageProperty>),
729    EnviromentProperty(Box<EnviromentProperty>),
730    ClusteredByProperty(Box<ClusteredByProperty>),
731    DictProperty(Box<DictProperty>),
732    DictRange(Box<DictRange>),
733    OnCluster(Box<OnCluster>),
734    LikeProperty(Box<LikeProperty>),
735    LocationProperty(Box<LocationProperty>),
736    LockProperty(Box<LockProperty>),
737    LockingProperty(Box<LockingProperty>),
738    LogProperty(Box<LogProperty>),
739    MaterializedProperty(Box<MaterializedProperty>),
740    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
741    OnProperty(Box<OnProperty>),
742    OnCommitProperty(Box<OnCommitProperty>),
743    PartitionedByProperty(Box<PartitionedByProperty>),
744    PartitionByProperty(Box<PartitionByProperty>),
745    PartitionedByBucket(Box<PartitionedByBucket>),
746    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
747    PartitionByTruncate(Box<PartitionByTruncate>),
748    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
749    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
750    PartitionByListProperty(Box<PartitionByListProperty>),
751    PartitionList(Box<PartitionList>),
752    Partition(Box<Partition>),
753    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
754    UniqueKeyProperty(Box<UniqueKeyProperty>),
755    RollupProperty(Box<RollupProperty>),
756    PartitionBoundSpec(Box<PartitionBoundSpec>),
757    PartitionedOfProperty(Box<PartitionedOfProperty>),
758    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
759    ReturnsProperty(Box<ReturnsProperty>),
760    RowFormatProperty(Box<RowFormatProperty>),
761    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
762    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
763    QueryTransform(Box<QueryTransform>),
764    SampleProperty(Box<SampleProperty>),
765    SecurityProperty(Box<SecurityProperty>),
766    SchemaCommentProperty(Box<SchemaCommentProperty>),
767    SemanticView(Box<SemanticView>),
768    SerdeProperties(Box<SerdeProperties>),
769    SetProperty(Box<SetProperty>),
770    SharingProperty(Box<SharingProperty>),
771    SetConfigProperty(Box<SetConfigProperty>),
772    SettingsProperty(Box<SettingsProperty>),
773    SortKeyProperty(Box<SortKeyProperty>),
774    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
775    SqlSecurityProperty(Box<SqlSecurityProperty>),
776    StabilityProperty(Box<StabilityProperty>),
777    StorageHandlerProperty(Box<StorageHandlerProperty>),
778    TemporaryProperty(Box<TemporaryProperty>),
779    Tags(Box<Tags>),
780    TransformModelProperty(Box<TransformModelProperty>),
781    TransientProperty(Box<TransientProperty>),
782    UsingTemplateProperty(Box<UsingTemplateProperty>),
783    ViewAttributeProperty(Box<ViewAttributeProperty>),
784    VolatileProperty(Box<VolatileProperty>),
785    WithDataProperty(Box<WithDataProperty>),
786    WithJournalTableProperty(Box<WithJournalTableProperty>),
787    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
788    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
789    WithProcedureOptions(Box<WithProcedureOptions>),
790    EncodeProperty(Box<EncodeProperty>),
791    IncludeProperty(Box<IncludeProperty>),
792    Properties(Box<Properties>),
793    OptionsProperty(Box<OptionsProperty>),
794    InputOutputFormat(Box<InputOutputFormat>),
795    Reference(Box<Reference>),
796    QueryOption(Box<QueryOption>),
797    WithTableHint(Box<WithTableHint>),
798    IndexTableHint(Box<IndexTableHint>),
799    HistoricalData(Box<HistoricalData>),
800    Get(Box<Get>),
801    SetOperation(Box<SetOperation>),
802    Var(Box<Var>),
803    Variadic(Box<Variadic>),
804    Version(Box<Version>),
805    Schema(Box<Schema>),
806    Lock(Box<Lock>),
807    TableSample(Box<TableSample>),
808    Tag(Box<Tag>),
809    UnpivotColumns(Box<UnpivotColumns>),
810    WindowSpec(Box<WindowSpec>),
811    SessionParameter(Box<SessionParameter>),
812    PseudoType(Box<PseudoType>),
813    ObjectIdentifier(Box<ObjectIdentifier>),
814    Transaction(Box<Transaction>),
815    Commit(Box<Commit>),
816    Rollback(Box<Rollback>),
817    AlterSession(Box<AlterSession>),
818    Analyze(Box<Analyze>),
819    AnalyzeStatistics(Box<AnalyzeStatistics>),
820    AnalyzeHistogram(Box<AnalyzeHistogram>),
821    AnalyzeSample(Box<AnalyzeSample>),
822    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
823    AnalyzeDelete(Box<AnalyzeDelete>),
824    AnalyzeWith(Box<AnalyzeWith>),
825    AnalyzeValidate(Box<AnalyzeValidate>),
826    AddPartition(Box<AddPartition>),
827    AttachOption(Box<AttachOption>),
828    DropPartition(Box<DropPartition>),
829    ReplacePartition(Box<ReplacePartition>),
830    DPipe(Box<DPipe>),
831    Operator(Box<Operator>),
832    PivotAny(Box<PivotAny>),
833    Aliases(Box<Aliases>),
834    AtIndex(Box<AtIndex>),
835    FromTimeZone(Box<FromTimeZone>),
836    FormatPhrase(Box<FormatPhrase>),
837    ForIn(Box<ForIn>),
838    TimeUnit(Box<TimeUnit>),
839    IntervalOp(Box<IntervalOp>),
840    IntervalSpan(Box<IntervalSpan>),
841    HavingMax(Box<HavingMax>),
842    CosineDistance(Box<CosineDistance>),
843    DotProduct(Box<DotProduct>),
844    EuclideanDistance(Box<EuclideanDistance>),
845    ManhattanDistance(Box<ManhattanDistance>),
846    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
847    Booland(Box<Booland>),
848    Boolor(Box<Boolor>),
849    ParameterizedAgg(Box<ParameterizedAgg>),
850    ArgMax(Box<ArgMax>),
851    ArgMin(Box<ArgMin>),
852    ApproxTopK(Box<ApproxTopK>),
853    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
854    ApproxTopKCombine(Box<ApproxTopKCombine>),
855    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
856    ApproxTopSum(Box<ApproxTopSum>),
857    ApproxQuantiles(Box<ApproxQuantiles>),
858    Minhash(Box<Minhash>),
859    FarmFingerprint(Box<FarmFingerprint>),
860    Float64(Box<Float64>),
861    Transform(Box<Transform>),
862    Translate(Box<Translate>),
863    Grouping(Box<Grouping>),
864    GroupingId(Box<GroupingId>),
865    Anonymous(Box<Anonymous>),
866    AnonymousAggFunc(Box<AnonymousAggFunc>),
867    CombinedAggFunc(Box<CombinedAggFunc>),
868    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
869    HashAgg(Box<HashAgg>),
870    Hll(Box<Hll>),
871    Apply(Box<Apply>),
872    ToBoolean(Box<ToBoolean>),
873    List(Box<List>),
874    ToMap(Box<ToMap>),
875    Pad(Box<Pad>),
876    ToChar(Box<ToChar>),
877    ToNumber(Box<ToNumber>),
878    ToDouble(Box<ToDouble>),
879    Int64(Box<UnaryFunc>),
880    StringFunc(Box<StringFunc>),
881    ToDecfloat(Box<ToDecfloat>),
882    TryToDecfloat(Box<TryToDecfloat>),
883    ToFile(Box<ToFile>),
884    Columns(Box<Columns>),
885    ConvertToCharset(Box<ConvertToCharset>),
886    ConvertTimezone(Box<ConvertTimezone>),
887    GenerateSeries(Box<GenerateSeries>),
888    AIAgg(Box<AIAgg>),
889    AIClassify(Box<AIClassify>),
890    ArrayAll(Box<ArrayAll>),
891    ArrayAny(Box<ArrayAny>),
892    ArrayConstructCompact(Box<ArrayConstructCompact>),
893    StPoint(Box<StPoint>),
894    StDistance(Box<StDistance>),
895    StringToArray(Box<StringToArray>),
896    ArraySum(Box<ArraySum>),
897    ObjectAgg(Box<ObjectAgg>),
898    CastToStrType(Box<CastToStrType>),
899    CheckJson(Box<CheckJson>),
900    CheckXml(Box<CheckXml>),
901    TranslateCharacters(Box<TranslateCharacters>),
902    CurrentSchemas(Box<CurrentSchemas>),
903    CurrentDatetime(Box<CurrentDatetime>),
904    Localtime(Box<Localtime>),
905    Localtimestamp(Box<Localtimestamp>),
906    Systimestamp(Box<Systimestamp>),
907    CurrentSchema(Box<CurrentSchema>),
908    CurrentUser(Box<CurrentUser>),
909    UtcTime(Box<UtcTime>),
910    UtcTimestamp(Box<UtcTimestamp>),
911    Timestamp(Box<TimestampFunc>),
912    DateBin(Box<DateBin>),
913    Datetime(Box<Datetime>),
914    DatetimeAdd(Box<DatetimeAdd>),
915    DatetimeSub(Box<DatetimeSub>),
916    DatetimeDiff(Box<DatetimeDiff>),
917    DatetimeTrunc(Box<DatetimeTrunc>),
918    Dayname(Box<Dayname>),
919    MakeInterval(Box<MakeInterval>),
920    PreviousDay(Box<PreviousDay>),
921    Elt(Box<Elt>),
922    TimestampAdd(Box<TimestampAdd>),
923    TimestampSub(Box<TimestampSub>),
924    TimestampDiff(Box<TimestampDiff>),
925    TimeSlice(Box<TimeSlice>),
926    TimeAdd(Box<TimeAdd>),
927    TimeSub(Box<TimeSub>),
928    TimeDiff(Box<TimeDiff>),
929    TimeTrunc(Box<TimeTrunc>),
930    DateFromParts(Box<DateFromParts>),
931    TimeFromParts(Box<TimeFromParts>),
932    DecodeCase(Box<DecodeCase>),
933    Decrypt(Box<Decrypt>),
934    DecryptRaw(Box<DecryptRaw>),
935    Encode(Box<Encode>),
936    Encrypt(Box<Encrypt>),
937    EncryptRaw(Box<EncryptRaw>),
938    EqualNull(Box<EqualNull>),
939    ToBinary(Box<ToBinary>),
940    Base64DecodeBinary(Box<Base64DecodeBinary>),
941    Base64DecodeString(Box<Base64DecodeString>),
942    Base64Encode(Box<Base64Encode>),
943    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
944    TryBase64DecodeString(Box<TryBase64DecodeString>),
945    GapFill(Box<GapFill>),
946    GenerateDateArray(Box<GenerateDateArray>),
947    GenerateTimestampArray(Box<GenerateTimestampArray>),
948    GetExtract(Box<GetExtract>),
949    Getbit(Box<Getbit>),
950    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
951    HexEncode(Box<HexEncode>),
952    Compress(Box<Compress>),
953    DecompressBinary(Box<DecompressBinary>),
954    DecompressString(Box<DecompressString>),
955    Xor(Box<Xor>),
956    Nullif(Box<Nullif>),
957    JSON(Box<JSON>),
958    JSONPath(Box<JSONPath>),
959    JSONPathFilter(Box<JSONPathFilter>),
960    JSONPathKey(Box<JSONPathKey>),
961    JSONPathRecursive(Box<JSONPathRecursive>),
962    JSONPathScript(Box<JSONPathScript>),
963    JSONPathSlice(Box<JSONPathSlice>),
964    JSONPathSelector(Box<JSONPathSelector>),
965    JSONPathSubscript(Box<JSONPathSubscript>),
966    JSONPathUnion(Box<JSONPathUnion>),
967    Format(Box<Format>),
968    JSONKeys(Box<JSONKeys>),
969    JSONKeyValue(Box<JSONKeyValue>),
970    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
971    JSONObject(Box<JSONObject>),
972    JSONObjectAgg(Box<JSONObjectAgg>),
973    JSONBObjectAgg(Box<JSONBObjectAgg>),
974    JSONArray(Box<JSONArray>),
975    JSONArrayAgg(Box<JSONArrayAgg>),
976    JSONExists(Box<JSONExists>),
977    JSONColumnDef(Box<JSONColumnDef>),
978    JSONSchema(Box<JSONSchema>),
979    JSONSet(Box<JSONSet>),
980    JSONStripNulls(Box<JSONStripNulls>),
981    JSONValue(Box<JSONValue>),
982    JSONValueArray(Box<JSONValueArray>),
983    JSONRemove(Box<JSONRemove>),
984    JSONTable(Box<JSONTable>),
985    JSONType(Box<JSONType>),
986    ObjectInsert(Box<ObjectInsert>),
987    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
988    OpenJSON(Box<OpenJSON>),
989    JSONBExists(Box<JSONBExists>),
990    JSONBContains(Box<BinaryFunc>),
991    JSONBExtract(Box<BinaryFunc>),
992    JSONCast(Box<JSONCast>),
993    JSONExtract(Box<JSONExtract>),
994    JSONExtractQuote(Box<JSONExtractQuote>),
995    JSONExtractArray(Box<JSONExtractArray>),
996    JSONExtractScalar(Box<JSONExtractScalar>),
997    JSONBExtractScalar(Box<JSONBExtractScalar>),
998    JSONFormat(Box<JSONFormat>),
999    JSONBool(Box<UnaryFunc>),
1000    JSONPathRoot(JSONPathRoot),
1001    JSONArrayAppend(Box<JSONArrayAppend>),
1002    JSONArrayContains(Box<JSONArrayContains>),
1003    JSONArrayInsert(Box<JSONArrayInsert>),
1004    ParseJSON(Box<ParseJSON>),
1005    ParseUrl(Box<ParseUrl>),
1006    ParseIp(Box<ParseIp>),
1007    ParseTime(Box<ParseTime>),
1008    ParseDatetime(Box<ParseDatetime>),
1009    Map(Box<Map>),
1010    MapCat(Box<MapCat>),
1011    MapDelete(Box<MapDelete>),
1012    MapInsert(Box<MapInsert>),
1013    MapPick(Box<MapPick>),
1014    ScopeResolution(Box<ScopeResolution>),
1015    Slice(Box<Slice>),
1016    VarMap(Box<VarMap>),
1017    MatchAgainst(Box<MatchAgainst>),
1018    MD5Digest(Box<MD5Digest>),
1019    MD5NumberLower64(Box<UnaryFunc>),
1020    MD5NumberUpper64(Box<UnaryFunc>),
1021    Monthname(Box<Monthname>),
1022    Ntile(Box<Ntile>),
1023    Normalize(Box<Normalize>),
1024    Normal(Box<Normal>),
1025    Predict(Box<Predict>),
1026    MLTranslate(Box<MLTranslate>),
1027    FeaturesAtTime(Box<FeaturesAtTime>),
1028    GenerateEmbedding(Box<GenerateEmbedding>),
1029    MLForecast(Box<MLForecast>),
1030    ModelAttribute(Box<ModelAttribute>),
1031    VectorSearch(Box<VectorSearch>),
1032    Quantile(Box<Quantile>),
1033    ApproxQuantile(Box<ApproxQuantile>),
1034    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1035    Randn(Box<Randn>),
1036    Randstr(Box<Randstr>),
1037    RangeN(Box<RangeN>),
1038    RangeBucket(Box<RangeBucket>),
1039    ReadCSV(Box<ReadCSV>),
1040    ReadParquet(Box<ReadParquet>),
1041    Reduce(Box<Reduce>),
1042    RegexpExtractAll(Box<RegexpExtractAll>),
1043    RegexpILike(Box<RegexpILike>),
1044    RegexpFullMatch(Box<RegexpFullMatch>),
1045    RegexpInstr(Box<RegexpInstr>),
1046    RegexpSplit(Box<RegexpSplit>),
1047    RegexpCount(Box<RegexpCount>),
1048    RegrValx(Box<RegrValx>),
1049    RegrValy(Box<RegrValy>),
1050    RegrAvgy(Box<RegrAvgy>),
1051    RegrAvgx(Box<RegrAvgx>),
1052    RegrCount(Box<RegrCount>),
1053    RegrIntercept(Box<RegrIntercept>),
1054    RegrR2(Box<RegrR2>),
1055    RegrSxx(Box<RegrSxx>),
1056    RegrSxy(Box<RegrSxy>),
1057    RegrSyy(Box<RegrSyy>),
1058    RegrSlope(Box<RegrSlope>),
1059    SafeAdd(Box<SafeAdd>),
1060    SafeDivide(Box<SafeDivide>),
1061    SafeMultiply(Box<SafeMultiply>),
1062    SafeSubtract(Box<SafeSubtract>),
1063    SHA2(Box<SHA2>),
1064    SHA2Digest(Box<SHA2Digest>),
1065    SortArray(Box<SortArray>),
1066    SplitPart(Box<SplitPart>),
1067    SubstringIndex(Box<SubstringIndex>),
1068    StandardHash(Box<StandardHash>),
1069    StrPosition(Box<StrPosition>),
1070    Search(Box<Search>),
1071    SearchIp(Box<SearchIp>),
1072    StrToDate(Box<StrToDate>),
1073    DateStrToDate(Box<UnaryFunc>),
1074    DateToDateStr(Box<UnaryFunc>),
1075    StrToTime(Box<StrToTime>),
1076    StrToUnix(Box<StrToUnix>),
1077    StrToMap(Box<StrToMap>),
1078    NumberToStr(Box<NumberToStr>),
1079    FromBase(Box<FromBase>),
1080    Stuff(Box<Stuff>),
1081    TimeToStr(Box<TimeToStr>),
1082    TimeStrToTime(Box<TimeStrToTime>),
1083    TsOrDsAdd(Box<TsOrDsAdd>),
1084    TsOrDsDiff(Box<TsOrDsDiff>),
1085    TsOrDsToDate(Box<TsOrDsToDate>),
1086    TsOrDsToTime(Box<TsOrDsToTime>),
1087    Unhex(Box<Unhex>),
1088    Uniform(Box<Uniform>),
1089    UnixToStr(Box<UnixToStr>),
1090    UnixToTime(Box<UnixToTime>),
1091    Uuid(Box<Uuid>),
1092    TimestampFromParts(Box<TimestampFromParts>),
1093    TimestampTzFromParts(Box<TimestampTzFromParts>),
1094    Corr(Box<Corr>),
1095    WidthBucket(Box<WidthBucket>),
1096    CovarSamp(Box<CovarSamp>),
1097    CovarPop(Box<CovarPop>),
1098    Week(Box<Week>),
1099    XMLElement(Box<XMLElement>),
1100    XMLGet(Box<XMLGet>),
1101    XMLTable(Box<XMLTable>),
1102    XMLKeyValueOption(Box<XMLKeyValueOption>),
1103    Zipf(Box<Zipf>),
1104    Merge(Box<Merge>),
1105    When(Box<When>),
1106    Whens(Box<Whens>),
1107    NextValueFor(Box<NextValueFor>),
1108    /// RETURN statement (DuckDB stored procedures)
1109    ReturnStmt(Box<Expression>),
1110}
1111
1112impl Expression {
1113    /// Create a `Column` variant, boxing the value automatically.
1114    #[inline]
1115    pub fn boxed_column(col: Column) -> Self {
1116        Expression::Column(Box::new(col))
1117    }
1118
1119    /// Create a `Table` variant, boxing the value automatically.
1120    #[inline]
1121    pub fn boxed_table(t: TableRef) -> Self {
1122        Expression::Table(Box::new(t))
1123    }
1124
1125    /// Returns `true` if this expression is a valid top-level SQL statement.
1126    ///
1127    /// Bare expressions like identifiers, literals, and function calls are not
1128    /// valid statements. This is used by `validate()` to reject inputs like
1129    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1130    /// plus the bare identifier `doo`.
1131    pub fn is_statement(&self) -> bool {
1132        match self {
1133            // Queries
1134            Expression::Select(_)
1135            | Expression::Union(_)
1136            | Expression::Intersect(_)
1137            | Expression::Except(_)
1138            | Expression::Subquery(_)
1139            | Expression::Values(_)
1140            | Expression::PipeOperator(_)
1141
1142            // DML
1143            | Expression::Insert(_)
1144            | Expression::Update(_)
1145            | Expression::Delete(_)
1146            | Expression::Copy(_)
1147            | Expression::Put(_)
1148            | Expression::Merge(_)
1149
1150            // DDL
1151            | Expression::CreateTable(_)
1152            | Expression::DropTable(_)
1153            | Expression::Undrop(_)
1154            | Expression::AlterTable(_)
1155            | Expression::CreateIndex(_)
1156            | Expression::DropIndex(_)
1157            | Expression::CreateView(_)
1158            | Expression::DropView(_)
1159            | Expression::AlterView(_)
1160            | Expression::AlterIndex(_)
1161            | Expression::Truncate(_)
1162            | Expression::TruncateTable(_)
1163            | Expression::CreateSchema(_)
1164            | Expression::DropSchema(_)
1165            | Expression::DropNamespace(_)
1166            | Expression::CreateDatabase(_)
1167            | Expression::DropDatabase(_)
1168            | Expression::CreateFunction(_)
1169            | Expression::DropFunction(_)
1170            | Expression::CreateProcedure(_)
1171            | Expression::DropProcedure(_)
1172            | Expression::CreateSequence(_)
1173            | Expression::CreateSynonym(_)
1174            | Expression::DropSequence(_)
1175            | Expression::AlterSequence(_)
1176            | Expression::CreateTrigger(_)
1177            | Expression::DropTrigger(_)
1178            | Expression::CreateType(_)
1179            | Expression::DropType(_)
1180            | Expression::Comment(_)
1181
1182            // Session/Transaction/Control
1183            | Expression::Use(_)
1184            | Expression::Set(_)
1185            | Expression::SetStatement(_)
1186            | Expression::Transaction(_)
1187            | Expression::Commit(_)
1188            | Expression::Rollback(_)
1189            | Expression::Grant(_)
1190            | Expression::Revoke(_)
1191            | Expression::Cache(_)
1192            | Expression::Uncache(_)
1193            | Expression::LoadData(_)
1194            | Expression::Pragma(_)
1195            | Expression::Describe(_)
1196            | Expression::Show(_)
1197            | Expression::Kill(_)
1198            | Expression::Execute(_)
1199            | Expression::Declare(_)
1200            | Expression::Refresh(_)
1201            | Expression::AlterSession(_)
1202            | Expression::LockingStatement(_)
1203
1204            // Analyze
1205            | Expression::Analyze(_)
1206            | Expression::AnalyzeStatistics(_)
1207            | Expression::AnalyzeHistogram(_)
1208            | Expression::AnalyzeSample(_)
1209            | Expression::AnalyzeListChainedRows(_)
1210            | Expression::AnalyzeDelete(_)
1211
1212            // Attach/Detach/Install/Summarize
1213            | Expression::Attach(_)
1214            | Expression::Detach(_)
1215            | Expression::Install(_)
1216            | Expression::Summarize(_)
1217
1218            // Pivot at statement level
1219            | Expression::Pivot(_)
1220            | Expression::Unpivot(_)
1221
1222            // Command (raw/unparsed statements)
1223            | Expression::Command(_)
1224            | Expression::Raw(_)
1225            | Expression::CreateTask(_)
1226
1227            // Return statement
1228            | Expression::ReturnStmt(_) => true,
1229
1230            // Annotated wraps another expression with comments — check inner
1231            Expression::Annotated(a) => a.this.is_statement(),
1232
1233            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1234            Expression::Alias(a) => a.this.is_statement(),
1235
1236            // Everything else (identifiers, literals, operators, functions, etc.)
1237            _ => false,
1238        }
1239    }
1240
1241    /// Create a literal number expression from an integer.
1242    pub fn number(n: i64) -> Self {
1243        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1244    }
1245
1246    /// Create a single-quoted literal string expression.
1247    pub fn string(s: impl Into<String>) -> Self {
1248        Expression::Literal(Box::new(Literal::String(s.into())))
1249    }
1250
1251    /// Create a literal number expression from a float.
1252    pub fn float(f: f64) -> Self {
1253        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1254    }
1255
1256    /// Get the inferred type annotation, if present.
1257    ///
1258    /// For value-producing expressions with an `inferred_type` field, returns
1259    /// the stored type. For literals and boolean constants, computes the type
1260    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1261    pub fn inferred_type(&self) -> Option<&DataType> {
1262        match self {
1263            // Structs with inferred_type field
1264            Expression::And(op)
1265            | Expression::Or(op)
1266            | Expression::Add(op)
1267            | Expression::Sub(op)
1268            | Expression::Mul(op)
1269            | Expression::Div(op)
1270            | Expression::Mod(op)
1271            | Expression::Eq(op)
1272            | Expression::Neq(op)
1273            | Expression::Lt(op)
1274            | Expression::Lte(op)
1275            | Expression::Gt(op)
1276            | Expression::Gte(op)
1277            | Expression::Concat(op)
1278            | Expression::BitwiseAnd(op)
1279            | Expression::BitwiseOr(op)
1280            | Expression::BitwiseXor(op)
1281            | Expression::Adjacent(op)
1282            | Expression::TsMatch(op)
1283            | Expression::PropertyEQ(op)
1284            | Expression::ArrayContainsAll(op)
1285            | Expression::ArrayContainedBy(op)
1286            | Expression::ArrayOverlaps(op)
1287            | Expression::JSONBContainsAllTopKeys(op)
1288            | Expression::JSONBContainsAnyTopKeys(op)
1289            | Expression::JSONBDeleteAtPath(op)
1290            | Expression::ExtendsLeft(op)
1291            | Expression::ExtendsRight(op)
1292            | Expression::Is(op)
1293            | Expression::MemberOf(op)
1294            | Expression::Match(op)
1295            | Expression::NullSafeEq(op)
1296            | Expression::NullSafeNeq(op)
1297            | Expression::Glob(op)
1298            | Expression::BitwiseLeftShift(op)
1299            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1300
1301            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1302                op.inferred_type.as_ref()
1303            }
1304
1305            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1306
1307            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1308                c.inferred_type.as_ref()
1309            }
1310
1311            Expression::Column(c) => c.inferred_type.as_ref(),
1312            Expression::Function(f) => f.inferred_type.as_ref(),
1313            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1314            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1315            Expression::Case(c) => c.inferred_type.as_ref(),
1316            Expression::Subquery(s) => s.inferred_type.as_ref(),
1317            Expression::Alias(a) => a.inferred_type.as_ref(),
1318            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1319            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1320            Expression::Count(f) => f.inferred_type.as_ref(),
1321            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1322            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1323            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1324            Expression::SumIf(f) => f.inferred_type.as_ref(),
1325
1326            // UnaryFunc variants
1327            Expression::Upper(f)
1328            | Expression::Lower(f)
1329            | Expression::Length(f)
1330            | Expression::LTrim(f)
1331            | Expression::RTrim(f)
1332            | Expression::Reverse(f)
1333            | Expression::Abs(f)
1334            | Expression::Sqrt(f)
1335            | Expression::Cbrt(f)
1336            | Expression::Ln(f)
1337            | Expression::Exp(f)
1338            | Expression::Sign(f)
1339            | Expression::Date(f)
1340            | Expression::Time(f)
1341            | Expression::Initcap(f)
1342            | Expression::Ascii(f)
1343            | Expression::Chr(f)
1344            | Expression::Soundex(f)
1345            | Expression::ByteLength(f)
1346            | Expression::Hex(f)
1347            | Expression::LowerHex(f)
1348            | Expression::Unicode(f)
1349            | Expression::Typeof(f)
1350            | Expression::Explode(f)
1351            | Expression::ExplodeOuter(f)
1352            | Expression::MapFromEntries(f)
1353            | Expression::MapKeys(f)
1354            | Expression::MapValues(f)
1355            | Expression::ArrayLength(f)
1356            | Expression::ArraySize(f)
1357            | Expression::Cardinality(f)
1358            | Expression::ArrayReverse(f)
1359            | Expression::ArrayDistinct(f)
1360            | Expression::ArrayFlatten(f)
1361            | Expression::ArrayCompact(f)
1362            | Expression::ToArray(f)
1363            | Expression::JsonArrayLength(f)
1364            | Expression::JsonKeys(f)
1365            | Expression::JsonType(f)
1366            | Expression::ParseJson(f)
1367            | Expression::ToJson(f)
1368            | Expression::Radians(f)
1369            | Expression::Degrees(f)
1370            | Expression::Sin(f)
1371            | Expression::Cos(f)
1372            | Expression::Tan(f)
1373            | Expression::Asin(f)
1374            | Expression::Acos(f)
1375            | Expression::Atan(f)
1376            | Expression::IsNan(f)
1377            | Expression::IsInf(f)
1378            | Expression::Year(f)
1379            | Expression::Month(f)
1380            | Expression::Day(f)
1381            | Expression::Hour(f)
1382            | Expression::Minute(f)
1383            | Expression::Second(f)
1384            | Expression::DayOfWeek(f)
1385            | Expression::DayOfWeekIso(f)
1386            | Expression::DayOfMonth(f)
1387            | Expression::DayOfYear(f)
1388            | Expression::WeekOfYear(f)
1389            | Expression::Quarter(f)
1390            | Expression::Epoch(f)
1391            | Expression::EpochMs(f)
1392            | Expression::BitwiseCount(f)
1393            | Expression::DateFromUnixDate(f)
1394            | Expression::UnixDate(f)
1395            | Expression::UnixSeconds(f)
1396            | Expression::UnixMillis(f)
1397            | Expression::UnixMicros(f)
1398            | Expression::TimeStrToDate(f)
1399            | Expression::DateToDi(f)
1400            | Expression::DiToDate(f)
1401            | Expression::TsOrDiToDi(f)
1402            | Expression::TsOrDsToDatetime(f)
1403            | Expression::TsOrDsToTimestamp(f)
1404            | Expression::YearOfWeek(f)
1405            | Expression::YearOfWeekIso(f)
1406            | Expression::SHA(f)
1407            | Expression::SHA1Digest(f)
1408            | Expression::TimeToUnix(f)
1409            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1410
1411            // BinaryFunc variants
1412            Expression::Power(f)
1413            | Expression::NullIf(f)
1414            | Expression::IfNull(f)
1415            | Expression::Nvl(f)
1416            | Expression::Contains(f)
1417            | Expression::StartsWith(f)
1418            | Expression::EndsWith(f)
1419            | Expression::Levenshtein(f)
1420            | Expression::ModFunc(f)
1421            | Expression::IntDiv(f)
1422            | Expression::Atan2(f)
1423            | Expression::AddMonths(f)
1424            | Expression::MonthsBetween(f)
1425            | Expression::NextDay(f)
1426            | Expression::UnixToTimeStr(f)
1427            | Expression::ArrayContains(f)
1428            | Expression::ArrayPosition(f)
1429            | Expression::ArrayAppend(f)
1430            | Expression::ArrayPrepend(f)
1431            | Expression::ArrayUnion(f)
1432            | Expression::ArrayExcept(f)
1433            | Expression::ArrayRemove(f)
1434            | Expression::StarMap(f)
1435            | Expression::MapFromArrays(f)
1436            | Expression::MapContainsKey(f)
1437            | Expression::ElementAt(f)
1438            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1439
1440            // VarArgFunc variants
1441            Expression::Coalesce(f)
1442            | Expression::Greatest(f)
1443            | Expression::Least(f)
1444            | Expression::ArrayConcat(f)
1445            | Expression::ArrayIntersect(f)
1446            | Expression::ArrayZip(f)
1447            | Expression::MapConcat(f)
1448            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1449
1450            // AggFunc variants
1451            Expression::Sum(f)
1452            | Expression::Avg(f)
1453            | Expression::Min(f)
1454            | Expression::Max(f)
1455            | Expression::ArrayAgg(f)
1456            | Expression::CountIf(f)
1457            | Expression::Stddev(f)
1458            | Expression::StddevPop(f)
1459            | Expression::StddevSamp(f)
1460            | Expression::Variance(f)
1461            | Expression::VarPop(f)
1462            | Expression::VarSamp(f)
1463            | Expression::Median(f)
1464            | Expression::Mode(f)
1465            | Expression::First(f)
1466            | Expression::Last(f)
1467            | Expression::AnyValue(f)
1468            | Expression::ApproxDistinct(f)
1469            | Expression::ApproxCountDistinct(f)
1470            | Expression::LogicalAnd(f)
1471            | Expression::LogicalOr(f)
1472            | Expression::Skewness(f)
1473            | Expression::ArrayConcatAgg(f)
1474            | Expression::ArrayUniqueAgg(f)
1475            | Expression::BoolXorAgg(f)
1476            | Expression::BitwiseAndAgg(f)
1477            | Expression::BitwiseOrAgg(f)
1478            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1479
1480            // Everything else: no inferred_type field
1481            _ => None,
1482        }
1483    }
1484
1485    /// Set the inferred type annotation on this expression.
1486    ///
1487    /// Only has an effect on value-producing expressions with an `inferred_type`
1488    /// field. For other expression types, this is a no-op.
1489    pub fn set_inferred_type(&mut self, dt: DataType) {
1490        match self {
1491            Expression::And(op)
1492            | Expression::Or(op)
1493            | Expression::Add(op)
1494            | Expression::Sub(op)
1495            | Expression::Mul(op)
1496            | Expression::Div(op)
1497            | Expression::Mod(op)
1498            | Expression::Eq(op)
1499            | Expression::Neq(op)
1500            | Expression::Lt(op)
1501            | Expression::Lte(op)
1502            | Expression::Gt(op)
1503            | Expression::Gte(op)
1504            | Expression::Concat(op)
1505            | Expression::BitwiseAnd(op)
1506            | Expression::BitwiseOr(op)
1507            | Expression::BitwiseXor(op)
1508            | Expression::Adjacent(op)
1509            | Expression::TsMatch(op)
1510            | Expression::PropertyEQ(op)
1511            | Expression::ArrayContainsAll(op)
1512            | Expression::ArrayContainedBy(op)
1513            | Expression::ArrayOverlaps(op)
1514            | Expression::JSONBContainsAllTopKeys(op)
1515            | Expression::JSONBContainsAnyTopKeys(op)
1516            | Expression::JSONBDeleteAtPath(op)
1517            | Expression::ExtendsLeft(op)
1518            | Expression::ExtendsRight(op)
1519            | Expression::Is(op)
1520            | Expression::MemberOf(op)
1521            | Expression::Match(op)
1522            | Expression::NullSafeEq(op)
1523            | Expression::NullSafeNeq(op)
1524            | Expression::Glob(op)
1525            | Expression::BitwiseLeftShift(op)
1526            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1527
1528            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1529                op.inferred_type = Some(dt)
1530            }
1531
1532            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1533
1534            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1535                c.inferred_type = Some(dt)
1536            }
1537
1538            Expression::Column(c) => c.inferred_type = Some(dt),
1539            Expression::Function(f) => f.inferred_type = Some(dt),
1540            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1541            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1542            Expression::Case(c) => c.inferred_type = Some(dt),
1543            Expression::Subquery(s) => s.inferred_type = Some(dt),
1544            Expression::Alias(a) => a.inferred_type = Some(dt),
1545            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1546            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1547            Expression::Count(f) => f.inferred_type = Some(dt),
1548            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1549            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1550            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1551            Expression::SumIf(f) => f.inferred_type = Some(dt),
1552
1553            // UnaryFunc variants
1554            Expression::Upper(f)
1555            | Expression::Lower(f)
1556            | Expression::Length(f)
1557            | Expression::LTrim(f)
1558            | Expression::RTrim(f)
1559            | Expression::Reverse(f)
1560            | Expression::Abs(f)
1561            | Expression::Sqrt(f)
1562            | Expression::Cbrt(f)
1563            | Expression::Ln(f)
1564            | Expression::Exp(f)
1565            | Expression::Sign(f)
1566            | Expression::Date(f)
1567            | Expression::Time(f)
1568            | Expression::Initcap(f)
1569            | Expression::Ascii(f)
1570            | Expression::Chr(f)
1571            | Expression::Soundex(f)
1572            | Expression::ByteLength(f)
1573            | Expression::Hex(f)
1574            | Expression::LowerHex(f)
1575            | Expression::Unicode(f)
1576            | Expression::Typeof(f)
1577            | Expression::Explode(f)
1578            | Expression::ExplodeOuter(f)
1579            | Expression::MapFromEntries(f)
1580            | Expression::MapKeys(f)
1581            | Expression::MapValues(f)
1582            | Expression::ArrayLength(f)
1583            | Expression::ArraySize(f)
1584            | Expression::Cardinality(f)
1585            | Expression::ArrayReverse(f)
1586            | Expression::ArrayDistinct(f)
1587            | Expression::ArrayFlatten(f)
1588            | Expression::ArrayCompact(f)
1589            | Expression::ToArray(f)
1590            | Expression::JsonArrayLength(f)
1591            | Expression::JsonKeys(f)
1592            | Expression::JsonType(f)
1593            | Expression::ParseJson(f)
1594            | Expression::ToJson(f)
1595            | Expression::Radians(f)
1596            | Expression::Degrees(f)
1597            | Expression::Sin(f)
1598            | Expression::Cos(f)
1599            | Expression::Tan(f)
1600            | Expression::Asin(f)
1601            | Expression::Acos(f)
1602            | Expression::Atan(f)
1603            | Expression::IsNan(f)
1604            | Expression::IsInf(f)
1605            | Expression::Year(f)
1606            | Expression::Month(f)
1607            | Expression::Day(f)
1608            | Expression::Hour(f)
1609            | Expression::Minute(f)
1610            | Expression::Second(f)
1611            | Expression::DayOfWeek(f)
1612            | Expression::DayOfWeekIso(f)
1613            | Expression::DayOfMonth(f)
1614            | Expression::DayOfYear(f)
1615            | Expression::WeekOfYear(f)
1616            | Expression::Quarter(f)
1617            | Expression::Epoch(f)
1618            | Expression::EpochMs(f)
1619            | Expression::BitwiseCount(f)
1620            | Expression::DateFromUnixDate(f)
1621            | Expression::UnixDate(f)
1622            | Expression::UnixSeconds(f)
1623            | Expression::UnixMillis(f)
1624            | Expression::UnixMicros(f)
1625            | Expression::TimeStrToDate(f)
1626            | Expression::DateToDi(f)
1627            | Expression::DiToDate(f)
1628            | Expression::TsOrDiToDi(f)
1629            | Expression::TsOrDsToDatetime(f)
1630            | Expression::TsOrDsToTimestamp(f)
1631            | Expression::YearOfWeek(f)
1632            | Expression::YearOfWeekIso(f)
1633            | Expression::SHA(f)
1634            | Expression::SHA1Digest(f)
1635            | Expression::TimeToUnix(f)
1636            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1637
1638            // BinaryFunc variants
1639            Expression::Power(f)
1640            | Expression::NullIf(f)
1641            | Expression::IfNull(f)
1642            | Expression::Nvl(f)
1643            | Expression::Contains(f)
1644            | Expression::StartsWith(f)
1645            | Expression::EndsWith(f)
1646            | Expression::Levenshtein(f)
1647            | Expression::ModFunc(f)
1648            | Expression::IntDiv(f)
1649            | Expression::Atan2(f)
1650            | Expression::AddMonths(f)
1651            | Expression::MonthsBetween(f)
1652            | Expression::NextDay(f)
1653            | Expression::UnixToTimeStr(f)
1654            | Expression::ArrayContains(f)
1655            | Expression::ArrayPosition(f)
1656            | Expression::ArrayAppend(f)
1657            | Expression::ArrayPrepend(f)
1658            | Expression::ArrayUnion(f)
1659            | Expression::ArrayExcept(f)
1660            | Expression::ArrayRemove(f)
1661            | Expression::StarMap(f)
1662            | Expression::MapFromArrays(f)
1663            | Expression::MapContainsKey(f)
1664            | Expression::ElementAt(f)
1665            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1666
1667            // VarArgFunc variants
1668            Expression::Coalesce(f)
1669            | Expression::Greatest(f)
1670            | Expression::Least(f)
1671            | Expression::ArrayConcat(f)
1672            | Expression::ArrayIntersect(f)
1673            | Expression::ArrayZip(f)
1674            | Expression::MapConcat(f)
1675            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1676
1677            // AggFunc variants
1678            Expression::Sum(f)
1679            | Expression::Avg(f)
1680            | Expression::Min(f)
1681            | Expression::Max(f)
1682            | Expression::ArrayAgg(f)
1683            | Expression::CountIf(f)
1684            | Expression::Stddev(f)
1685            | Expression::StddevPop(f)
1686            | Expression::StddevSamp(f)
1687            | Expression::Variance(f)
1688            | Expression::VarPop(f)
1689            | Expression::VarSamp(f)
1690            | Expression::Median(f)
1691            | Expression::Mode(f)
1692            | Expression::First(f)
1693            | Expression::Last(f)
1694            | Expression::AnyValue(f)
1695            | Expression::ApproxDistinct(f)
1696            | Expression::ApproxCountDistinct(f)
1697            | Expression::LogicalAnd(f)
1698            | Expression::LogicalOr(f)
1699            | Expression::Skewness(f)
1700            | Expression::ArrayConcatAgg(f)
1701            | Expression::ArrayUniqueAgg(f)
1702            | Expression::BoolXorAgg(f)
1703            | Expression::BitwiseAndAgg(f)
1704            | Expression::BitwiseOrAgg(f)
1705            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1706
1707            // Expressions without inferred_type field - no-op
1708            _ => {}
1709        }
1710    }
1711
1712    /// Create an unqualified column reference (e.g. `name`).
1713    pub fn column(name: impl Into<String>) -> Self {
1714        Expression::Column(Box::new(Column {
1715            name: Identifier::new(name),
1716            table: None,
1717            join_mark: false,
1718            trailing_comments: Vec::new(),
1719            span: None,
1720            inferred_type: None,
1721        }))
1722    }
1723
1724    /// Create a qualified column reference (`table.column`).
1725    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1726        Expression::Column(Box::new(Column {
1727            name: Identifier::new(column),
1728            table: Some(Identifier::new(table)),
1729            join_mark: false,
1730            trailing_comments: Vec::new(),
1731            span: None,
1732            inferred_type: None,
1733        }))
1734    }
1735
1736    /// Create a bare identifier expression (not a column reference).
1737    pub fn identifier(name: impl Into<String>) -> Self {
1738        Expression::Identifier(Identifier::new(name))
1739    }
1740
1741    /// Create a NULL expression
1742    pub fn null() -> Self {
1743        Expression::Null(Null)
1744    }
1745
1746    /// Create a TRUE expression
1747    pub fn true_() -> Self {
1748        Expression::Boolean(BooleanLiteral { value: true })
1749    }
1750
1751    /// Create a FALSE expression
1752    pub fn false_() -> Self {
1753        Expression::Boolean(BooleanLiteral { value: false })
1754    }
1755
1756    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1757    pub fn star() -> Self {
1758        Expression::Star(Star {
1759            table: None,
1760            except: None,
1761            replace: None,
1762            rename: None,
1763            trailing_comments: Vec::new(),
1764            span: None,
1765        })
1766    }
1767
1768    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1769    pub fn alias(self, name: impl Into<String>) -> Self {
1770        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1771    }
1772
1773    /// Check if this is a SELECT expression
1774    pub fn is_select(&self) -> bool {
1775        matches!(self, Expression::Select(_))
1776    }
1777
1778    /// Try to get as a Select
1779    pub fn as_select(&self) -> Option<&Select> {
1780        match self {
1781            Expression::Select(s) => Some(s),
1782            _ => None,
1783        }
1784    }
1785
1786    /// Try to get as a mutable Select
1787    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1788        match self {
1789            Expression::Select(s) => Some(s),
1790            _ => None,
1791        }
1792    }
1793
1794    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1795    ///
1796    /// Returns an empty string if generation fails. For dialect-specific output,
1797    /// use [`sql_for()`](Self::sql_for) instead.
1798    pub fn sql(&self) -> String {
1799        crate::generator::Generator::sql(self).unwrap_or_default()
1800    }
1801
1802    /// Generate a SQL string for this expression targeting a specific dialect.
1803    ///
1804    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1805    /// syntax variations) are applied automatically.  Returns an empty string if
1806    /// generation fails.
1807    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1808        crate::generate(self, dialect).unwrap_or_default()
1809    }
1810}
1811
1812// === Python API accessor methods ===
1813
1814impl Expression {
1815    /// Returns the serde-compatible snake_case variant name without serialization.
1816    /// This is much faster than serializing to JSON and extracting the key.
1817    pub fn variant_name(&self) -> &'static str {
1818        match self {
1819            Expression::Literal(_) => "literal",
1820            Expression::Boolean(_) => "boolean",
1821            Expression::Null(_) => "null",
1822            Expression::Identifier(_) => "identifier",
1823            Expression::Column(_) => "column",
1824            Expression::Table(_) => "table",
1825            Expression::Star(_) => "star",
1826            Expression::BracedWildcard(_) => "braced_wildcard",
1827            Expression::Select(_) => "select",
1828            Expression::Union(_) => "union",
1829            Expression::Intersect(_) => "intersect",
1830            Expression::Except(_) => "except",
1831            Expression::Subquery(_) => "subquery",
1832            Expression::PipeOperator(_) => "pipe_operator",
1833            Expression::Pivot(_) => "pivot",
1834            Expression::PivotAlias(_) => "pivot_alias",
1835            Expression::Unpivot(_) => "unpivot",
1836            Expression::Values(_) => "values",
1837            Expression::PreWhere(_) => "pre_where",
1838            Expression::Stream(_) => "stream",
1839            Expression::UsingData(_) => "using_data",
1840            Expression::XmlNamespace(_) => "xml_namespace",
1841            Expression::Insert(_) => "insert",
1842            Expression::Update(_) => "update",
1843            Expression::Delete(_) => "delete",
1844            Expression::Copy(_) => "copy",
1845            Expression::Put(_) => "put",
1846            Expression::StageReference(_) => "stage_reference",
1847            Expression::Alias(_) => "alias",
1848            Expression::Cast(_) => "cast",
1849            Expression::Collation(_) => "collation",
1850            Expression::Case(_) => "case",
1851            Expression::And(_) => "and",
1852            Expression::Or(_) => "or",
1853            Expression::Add(_) => "add",
1854            Expression::Sub(_) => "sub",
1855            Expression::Mul(_) => "mul",
1856            Expression::Div(_) => "div",
1857            Expression::Mod(_) => "mod",
1858            Expression::Eq(_) => "eq",
1859            Expression::Neq(_) => "neq",
1860            Expression::Lt(_) => "lt",
1861            Expression::Lte(_) => "lte",
1862            Expression::Gt(_) => "gt",
1863            Expression::Gte(_) => "gte",
1864            Expression::Like(_) => "like",
1865            Expression::ILike(_) => "i_like",
1866            Expression::Match(_) => "match",
1867            Expression::BitwiseAnd(_) => "bitwise_and",
1868            Expression::BitwiseOr(_) => "bitwise_or",
1869            Expression::BitwiseXor(_) => "bitwise_xor",
1870            Expression::Concat(_) => "concat",
1871            Expression::Adjacent(_) => "adjacent",
1872            Expression::TsMatch(_) => "ts_match",
1873            Expression::PropertyEQ(_) => "property_e_q",
1874            Expression::ArrayContainsAll(_) => "array_contains_all",
1875            Expression::ArrayContainedBy(_) => "array_contained_by",
1876            Expression::ArrayOverlaps(_) => "array_overlaps",
1877            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1878            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1879            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1880            Expression::ExtendsLeft(_) => "extends_left",
1881            Expression::ExtendsRight(_) => "extends_right",
1882            Expression::Not(_) => "not",
1883            Expression::Neg(_) => "neg",
1884            Expression::BitwiseNot(_) => "bitwise_not",
1885            Expression::In(_) => "in",
1886            Expression::Between(_) => "between",
1887            Expression::IsNull(_) => "is_null",
1888            Expression::IsTrue(_) => "is_true",
1889            Expression::IsFalse(_) => "is_false",
1890            Expression::IsJson(_) => "is_json",
1891            Expression::Is(_) => "is",
1892            Expression::Exists(_) => "exists",
1893            Expression::MemberOf(_) => "member_of",
1894            Expression::Function(_) => "function",
1895            Expression::AggregateFunction(_) => "aggregate_function",
1896            Expression::WindowFunction(_) => "window_function",
1897            Expression::From(_) => "from",
1898            Expression::Join(_) => "join",
1899            Expression::JoinedTable(_) => "joined_table",
1900            Expression::Where(_) => "where",
1901            Expression::GroupBy(_) => "group_by",
1902            Expression::Having(_) => "having",
1903            Expression::OrderBy(_) => "order_by",
1904            Expression::Limit(_) => "limit",
1905            Expression::Offset(_) => "offset",
1906            Expression::Qualify(_) => "qualify",
1907            Expression::With(_) => "with",
1908            Expression::Cte(_) => "cte",
1909            Expression::DistributeBy(_) => "distribute_by",
1910            Expression::ClusterBy(_) => "cluster_by",
1911            Expression::SortBy(_) => "sort_by",
1912            Expression::LateralView(_) => "lateral_view",
1913            Expression::Hint(_) => "hint",
1914            Expression::Pseudocolumn(_) => "pseudocolumn",
1915            Expression::Connect(_) => "connect",
1916            Expression::Prior(_) => "prior",
1917            Expression::ConnectByRoot(_) => "connect_by_root",
1918            Expression::MatchRecognize(_) => "match_recognize",
1919            Expression::Ordered(_) => "ordered",
1920            Expression::Window(_) => "window",
1921            Expression::Over(_) => "over",
1922            Expression::WithinGroup(_) => "within_group",
1923            Expression::DataType(_) => "data_type",
1924            Expression::Array(_) => "array",
1925            Expression::Struct(_) => "struct",
1926            Expression::Tuple(_) => "tuple",
1927            Expression::Interval(_) => "interval",
1928            Expression::ConcatWs(_) => "concat_ws",
1929            Expression::Substring(_) => "substring",
1930            Expression::Upper(_) => "upper",
1931            Expression::Lower(_) => "lower",
1932            Expression::Length(_) => "length",
1933            Expression::Trim(_) => "trim",
1934            Expression::LTrim(_) => "l_trim",
1935            Expression::RTrim(_) => "r_trim",
1936            Expression::Replace(_) => "replace",
1937            Expression::Reverse(_) => "reverse",
1938            Expression::Left(_) => "left",
1939            Expression::Right(_) => "right",
1940            Expression::Repeat(_) => "repeat",
1941            Expression::Lpad(_) => "lpad",
1942            Expression::Rpad(_) => "rpad",
1943            Expression::Split(_) => "split",
1944            Expression::RegexpLike(_) => "regexp_like",
1945            Expression::RegexpReplace(_) => "regexp_replace",
1946            Expression::RegexpExtract(_) => "regexp_extract",
1947            Expression::Overlay(_) => "overlay",
1948            Expression::Abs(_) => "abs",
1949            Expression::Round(_) => "round",
1950            Expression::Floor(_) => "floor",
1951            Expression::Ceil(_) => "ceil",
1952            Expression::Power(_) => "power",
1953            Expression::Sqrt(_) => "sqrt",
1954            Expression::Cbrt(_) => "cbrt",
1955            Expression::Ln(_) => "ln",
1956            Expression::Log(_) => "log",
1957            Expression::Exp(_) => "exp",
1958            Expression::Sign(_) => "sign",
1959            Expression::Greatest(_) => "greatest",
1960            Expression::Least(_) => "least",
1961            Expression::CurrentDate(_) => "current_date",
1962            Expression::CurrentTime(_) => "current_time",
1963            Expression::CurrentTimestamp(_) => "current_timestamp",
1964            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1965            Expression::AtTimeZone(_) => "at_time_zone",
1966            Expression::DateAdd(_) => "date_add",
1967            Expression::DateSub(_) => "date_sub",
1968            Expression::DateDiff(_) => "date_diff",
1969            Expression::DateTrunc(_) => "date_trunc",
1970            Expression::Extract(_) => "extract",
1971            Expression::ToDate(_) => "to_date",
1972            Expression::ToTimestamp(_) => "to_timestamp",
1973            Expression::Date(_) => "date",
1974            Expression::Time(_) => "time",
1975            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1976            Expression::UnixDate(_) => "unix_date",
1977            Expression::UnixSeconds(_) => "unix_seconds",
1978            Expression::UnixMillis(_) => "unix_millis",
1979            Expression::UnixMicros(_) => "unix_micros",
1980            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1981            Expression::TimeStrToDate(_) => "time_str_to_date",
1982            Expression::DateToDi(_) => "date_to_di",
1983            Expression::DiToDate(_) => "di_to_date",
1984            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1985            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1986            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1987            Expression::YearOfWeek(_) => "year_of_week",
1988            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1989            Expression::Coalesce(_) => "coalesce",
1990            Expression::NullIf(_) => "null_if",
1991            Expression::IfFunc(_) => "if_func",
1992            Expression::IfNull(_) => "if_null",
1993            Expression::Nvl(_) => "nvl",
1994            Expression::Nvl2(_) => "nvl2",
1995            Expression::TryCast(_) => "try_cast",
1996            Expression::SafeCast(_) => "safe_cast",
1997            Expression::Count(_) => "count",
1998            Expression::Sum(_) => "sum",
1999            Expression::Avg(_) => "avg",
2000            Expression::Min(_) => "min",
2001            Expression::Max(_) => "max",
2002            Expression::GroupConcat(_) => "group_concat",
2003            Expression::StringAgg(_) => "string_agg",
2004            Expression::ListAgg(_) => "list_agg",
2005            Expression::ArrayAgg(_) => "array_agg",
2006            Expression::CountIf(_) => "count_if",
2007            Expression::SumIf(_) => "sum_if",
2008            Expression::Stddev(_) => "stddev",
2009            Expression::StddevPop(_) => "stddev_pop",
2010            Expression::StddevSamp(_) => "stddev_samp",
2011            Expression::Variance(_) => "variance",
2012            Expression::VarPop(_) => "var_pop",
2013            Expression::VarSamp(_) => "var_samp",
2014            Expression::Median(_) => "median",
2015            Expression::Mode(_) => "mode",
2016            Expression::First(_) => "first",
2017            Expression::Last(_) => "last",
2018            Expression::AnyValue(_) => "any_value",
2019            Expression::ApproxDistinct(_) => "approx_distinct",
2020            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2021            Expression::ApproxPercentile(_) => "approx_percentile",
2022            Expression::Percentile(_) => "percentile",
2023            Expression::LogicalAnd(_) => "logical_and",
2024            Expression::LogicalOr(_) => "logical_or",
2025            Expression::Skewness(_) => "skewness",
2026            Expression::BitwiseCount(_) => "bitwise_count",
2027            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2028            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2029            Expression::BoolXorAgg(_) => "bool_xor_agg",
2030            Expression::RowNumber(_) => "row_number",
2031            Expression::Rank(_) => "rank",
2032            Expression::DenseRank(_) => "dense_rank",
2033            Expression::NTile(_) => "n_tile",
2034            Expression::Lead(_) => "lead",
2035            Expression::Lag(_) => "lag",
2036            Expression::FirstValue(_) => "first_value",
2037            Expression::LastValue(_) => "last_value",
2038            Expression::NthValue(_) => "nth_value",
2039            Expression::PercentRank(_) => "percent_rank",
2040            Expression::CumeDist(_) => "cume_dist",
2041            Expression::PercentileCont(_) => "percentile_cont",
2042            Expression::PercentileDisc(_) => "percentile_disc",
2043            Expression::Contains(_) => "contains",
2044            Expression::StartsWith(_) => "starts_with",
2045            Expression::EndsWith(_) => "ends_with",
2046            Expression::Position(_) => "position",
2047            Expression::Initcap(_) => "initcap",
2048            Expression::Ascii(_) => "ascii",
2049            Expression::Chr(_) => "chr",
2050            Expression::CharFunc(_) => "char_func",
2051            Expression::Soundex(_) => "soundex",
2052            Expression::Levenshtein(_) => "levenshtein",
2053            Expression::ByteLength(_) => "byte_length",
2054            Expression::Hex(_) => "hex",
2055            Expression::LowerHex(_) => "lower_hex",
2056            Expression::Unicode(_) => "unicode",
2057            Expression::ModFunc(_) => "mod_func",
2058            Expression::Random(_) => "random",
2059            Expression::Rand(_) => "rand",
2060            Expression::TruncFunc(_) => "trunc_func",
2061            Expression::Pi(_) => "pi",
2062            Expression::Radians(_) => "radians",
2063            Expression::Degrees(_) => "degrees",
2064            Expression::Sin(_) => "sin",
2065            Expression::Cos(_) => "cos",
2066            Expression::Tan(_) => "tan",
2067            Expression::Asin(_) => "asin",
2068            Expression::Acos(_) => "acos",
2069            Expression::Atan(_) => "atan",
2070            Expression::Atan2(_) => "atan2",
2071            Expression::IsNan(_) => "is_nan",
2072            Expression::IsInf(_) => "is_inf",
2073            Expression::IntDiv(_) => "int_div",
2074            Expression::Decode(_) => "decode",
2075            Expression::DateFormat(_) => "date_format",
2076            Expression::FormatDate(_) => "format_date",
2077            Expression::Year(_) => "year",
2078            Expression::Month(_) => "month",
2079            Expression::Day(_) => "day",
2080            Expression::Hour(_) => "hour",
2081            Expression::Minute(_) => "minute",
2082            Expression::Second(_) => "second",
2083            Expression::DayOfWeek(_) => "day_of_week",
2084            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2085            Expression::DayOfMonth(_) => "day_of_month",
2086            Expression::DayOfYear(_) => "day_of_year",
2087            Expression::WeekOfYear(_) => "week_of_year",
2088            Expression::Quarter(_) => "quarter",
2089            Expression::AddMonths(_) => "add_months",
2090            Expression::MonthsBetween(_) => "months_between",
2091            Expression::LastDay(_) => "last_day",
2092            Expression::NextDay(_) => "next_day",
2093            Expression::Epoch(_) => "epoch",
2094            Expression::EpochMs(_) => "epoch_ms",
2095            Expression::FromUnixtime(_) => "from_unixtime",
2096            Expression::UnixTimestamp(_) => "unix_timestamp",
2097            Expression::MakeDate(_) => "make_date",
2098            Expression::MakeTimestamp(_) => "make_timestamp",
2099            Expression::TimestampTrunc(_) => "timestamp_trunc",
2100            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2101            Expression::SessionUser(_) => "session_user",
2102            Expression::SHA(_) => "s_h_a",
2103            Expression::SHA1Digest(_) => "s_h_a1_digest",
2104            Expression::TimeToUnix(_) => "time_to_unix",
2105            Expression::ArrayFunc(_) => "array_func",
2106            Expression::ArrayLength(_) => "array_length",
2107            Expression::ArraySize(_) => "array_size",
2108            Expression::Cardinality(_) => "cardinality",
2109            Expression::ArrayContains(_) => "array_contains",
2110            Expression::ArrayPosition(_) => "array_position",
2111            Expression::ArrayAppend(_) => "array_append",
2112            Expression::ArrayPrepend(_) => "array_prepend",
2113            Expression::ArrayConcat(_) => "array_concat",
2114            Expression::ArraySort(_) => "array_sort",
2115            Expression::ArrayReverse(_) => "array_reverse",
2116            Expression::ArrayDistinct(_) => "array_distinct",
2117            Expression::ArrayJoin(_) => "array_join",
2118            Expression::ArrayToString(_) => "array_to_string",
2119            Expression::Unnest(_) => "unnest",
2120            Expression::Explode(_) => "explode",
2121            Expression::ExplodeOuter(_) => "explode_outer",
2122            Expression::ArrayFilter(_) => "array_filter",
2123            Expression::ArrayTransform(_) => "array_transform",
2124            Expression::ArrayFlatten(_) => "array_flatten",
2125            Expression::ArrayCompact(_) => "array_compact",
2126            Expression::ArrayIntersect(_) => "array_intersect",
2127            Expression::ArrayUnion(_) => "array_union",
2128            Expression::ArrayExcept(_) => "array_except",
2129            Expression::ArrayRemove(_) => "array_remove",
2130            Expression::ArrayZip(_) => "array_zip",
2131            Expression::Sequence(_) => "sequence",
2132            Expression::Generate(_) => "generate",
2133            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2134            Expression::ToArray(_) => "to_array",
2135            Expression::StarMap(_) => "star_map",
2136            Expression::StructFunc(_) => "struct_func",
2137            Expression::StructExtract(_) => "struct_extract",
2138            Expression::NamedStruct(_) => "named_struct",
2139            Expression::MapFunc(_) => "map_func",
2140            Expression::MapFromEntries(_) => "map_from_entries",
2141            Expression::MapFromArrays(_) => "map_from_arrays",
2142            Expression::MapKeys(_) => "map_keys",
2143            Expression::MapValues(_) => "map_values",
2144            Expression::MapContainsKey(_) => "map_contains_key",
2145            Expression::MapConcat(_) => "map_concat",
2146            Expression::ElementAt(_) => "element_at",
2147            Expression::TransformKeys(_) => "transform_keys",
2148            Expression::TransformValues(_) => "transform_values",
2149            Expression::FunctionEmits(_) => "function_emits",
2150            Expression::JsonExtract(_) => "json_extract",
2151            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2152            Expression::JsonExtractPath(_) => "json_extract_path",
2153            Expression::JsonArray(_) => "json_array",
2154            Expression::JsonObject(_) => "json_object",
2155            Expression::JsonQuery(_) => "json_query",
2156            Expression::JsonValue(_) => "json_value",
2157            Expression::JsonArrayLength(_) => "json_array_length",
2158            Expression::JsonKeys(_) => "json_keys",
2159            Expression::JsonType(_) => "json_type",
2160            Expression::ParseJson(_) => "parse_json",
2161            Expression::ToJson(_) => "to_json",
2162            Expression::JsonSet(_) => "json_set",
2163            Expression::JsonInsert(_) => "json_insert",
2164            Expression::JsonRemove(_) => "json_remove",
2165            Expression::JsonMergePatch(_) => "json_merge_patch",
2166            Expression::JsonArrayAgg(_) => "json_array_agg",
2167            Expression::JsonObjectAgg(_) => "json_object_agg",
2168            Expression::Convert(_) => "convert",
2169            Expression::Typeof(_) => "typeof",
2170            Expression::Lambda(_) => "lambda",
2171            Expression::Parameter(_) => "parameter",
2172            Expression::Placeholder(_) => "placeholder",
2173            Expression::NamedArgument(_) => "named_argument",
2174            Expression::TableArgument(_) => "table_argument",
2175            Expression::SqlComment(_) => "sql_comment",
2176            Expression::NullSafeEq(_) => "null_safe_eq",
2177            Expression::NullSafeNeq(_) => "null_safe_neq",
2178            Expression::Glob(_) => "glob",
2179            Expression::SimilarTo(_) => "similar_to",
2180            Expression::Any(_) => "any",
2181            Expression::All(_) => "all",
2182            Expression::Overlaps(_) => "overlaps",
2183            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2184            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2185            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2186            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2187            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2188            Expression::Subscript(_) => "subscript",
2189            Expression::Dot(_) => "dot",
2190            Expression::MethodCall(_) => "method_call",
2191            Expression::ArraySlice(_) => "array_slice",
2192            Expression::CreateTable(_) => "create_table",
2193            Expression::DropTable(_) => "drop_table",
2194            Expression::Undrop(_) => "undrop",
2195            Expression::AlterTable(_) => "alter_table",
2196            Expression::CreateIndex(_) => "create_index",
2197            Expression::DropIndex(_) => "drop_index",
2198            Expression::CreateView(_) => "create_view",
2199            Expression::DropView(_) => "drop_view",
2200            Expression::AlterView(_) => "alter_view",
2201            Expression::AlterIndex(_) => "alter_index",
2202            Expression::Truncate(_) => "truncate",
2203            Expression::Use(_) => "use",
2204            Expression::Cache(_) => "cache",
2205            Expression::Uncache(_) => "uncache",
2206            Expression::LoadData(_) => "load_data",
2207            Expression::Pragma(_) => "pragma",
2208            Expression::Grant(_) => "grant",
2209            Expression::Revoke(_) => "revoke",
2210            Expression::Comment(_) => "comment",
2211            Expression::SetStatement(_) => "set_statement",
2212            Expression::CreateSchema(_) => "create_schema",
2213            Expression::DropSchema(_) => "drop_schema",
2214            Expression::DropNamespace(_) => "drop_namespace",
2215            Expression::CreateDatabase(_) => "create_database",
2216            Expression::DropDatabase(_) => "drop_database",
2217            Expression::CreateFunction(_) => "create_function",
2218            Expression::DropFunction(_) => "drop_function",
2219            Expression::CreateProcedure(_) => "create_procedure",
2220            Expression::DropProcedure(_) => "drop_procedure",
2221            Expression::CreateSequence(_) => "create_sequence",
2222            Expression::CreateSynonym(_) => "create_synonym",
2223            Expression::DropSequence(_) => "drop_sequence",
2224            Expression::AlterSequence(_) => "alter_sequence",
2225            Expression::CreateTrigger(_) => "create_trigger",
2226            Expression::DropTrigger(_) => "drop_trigger",
2227            Expression::CreateType(_) => "create_type",
2228            Expression::DropType(_) => "drop_type",
2229            Expression::Describe(_) => "describe",
2230            Expression::Show(_) => "show",
2231            Expression::Command(_) => "command",
2232            Expression::Kill(_) => "kill",
2233            Expression::Execute(_) => "execute",
2234            Expression::Raw(_) => "raw",
2235            Expression::CreateTask(_) => "create_task",
2236            Expression::Paren(_) => "paren",
2237            Expression::Annotated(_) => "annotated",
2238            Expression::Refresh(_) => "refresh",
2239            Expression::LockingStatement(_) => "locking_statement",
2240            Expression::SequenceProperties(_) => "sequence_properties",
2241            Expression::TruncateTable(_) => "truncate_table",
2242            Expression::Clone(_) => "clone",
2243            Expression::Attach(_) => "attach",
2244            Expression::Detach(_) => "detach",
2245            Expression::Install(_) => "install",
2246            Expression::Summarize(_) => "summarize",
2247            Expression::Declare(_) => "declare",
2248            Expression::DeclareItem(_) => "declare_item",
2249            Expression::Set(_) => "set",
2250            Expression::Heredoc(_) => "heredoc",
2251            Expression::SetItem(_) => "set_item",
2252            Expression::QueryBand(_) => "query_band",
2253            Expression::UserDefinedFunction(_) => "user_defined_function",
2254            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2255            Expression::ProjectionDef(_) => "projection_def",
2256            Expression::TableAlias(_) => "table_alias",
2257            Expression::ByteString(_) => "byte_string",
2258            Expression::HexStringExpr(_) => "hex_string_expr",
2259            Expression::UnicodeString(_) => "unicode_string",
2260            Expression::ColumnPosition(_) => "column_position",
2261            Expression::ColumnDef(_) => "column_def",
2262            Expression::AlterColumn(_) => "alter_column",
2263            Expression::AlterSortKey(_) => "alter_sort_key",
2264            Expression::AlterSet(_) => "alter_set",
2265            Expression::RenameColumn(_) => "rename_column",
2266            Expression::Comprehension(_) => "comprehension",
2267            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2268            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2269            Expression::IndexConstraintOption(_) => "index_constraint_option",
2270            Expression::ColumnConstraint(_) => "column_constraint",
2271            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2272            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2273            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2274            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2275            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2276            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2277            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2278            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2279            Expression::WithOperator(_) => "with_operator",
2280            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2281                "generated_as_identity_column_constraint"
2282            }
2283            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2284            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2285            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2286            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2287            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2288            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2289            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2290            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2291            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2292            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2293            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2294            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2295            Expression::PathColumnConstraint(_) => "path_column_constraint",
2296            Expression::Constraint(_) => "constraint",
2297            Expression::Export(_) => "export",
2298            Expression::Filter(_) => "filter",
2299            Expression::Changes(_) => "changes",
2300            Expression::CopyParameter(_) => "copy_parameter",
2301            Expression::Credentials(_) => "credentials",
2302            Expression::Directory(_) => "directory",
2303            Expression::ForeignKey(_) => "foreign_key",
2304            Expression::ColumnPrefix(_) => "column_prefix",
2305            Expression::PrimaryKey(_) => "primary_key",
2306            Expression::IntoClause(_) => "into_clause",
2307            Expression::JoinHint(_) => "join_hint",
2308            Expression::Opclass(_) => "opclass",
2309            Expression::Index(_) => "index",
2310            Expression::IndexParameters(_) => "index_parameters",
2311            Expression::ConditionalInsert(_) => "conditional_insert",
2312            Expression::MultitableInserts(_) => "multitable_inserts",
2313            Expression::OnConflict(_) => "on_conflict",
2314            Expression::OnCondition(_) => "on_condition",
2315            Expression::Returning(_) => "returning",
2316            Expression::Introducer(_) => "introducer",
2317            Expression::PartitionRange(_) => "partition_range",
2318            Expression::Fetch(_) => "fetch",
2319            Expression::Group(_) => "group",
2320            Expression::Cube(_) => "cube",
2321            Expression::Rollup(_) => "rollup",
2322            Expression::GroupingSets(_) => "grouping_sets",
2323            Expression::LimitOptions(_) => "limit_options",
2324            Expression::Lateral(_) => "lateral",
2325            Expression::TableFromRows(_) => "table_from_rows",
2326            Expression::RowsFrom(_) => "rows_from",
2327            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2328            Expression::WithFill(_) => "with_fill",
2329            Expression::Property(_) => "property",
2330            Expression::GrantPrivilege(_) => "grant_privilege",
2331            Expression::GrantPrincipal(_) => "grant_principal",
2332            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2333            Expression::AlgorithmProperty(_) => "algorithm_property",
2334            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2335            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2336            Expression::BackupProperty(_) => "backup_property",
2337            Expression::BuildProperty(_) => "build_property",
2338            Expression::BlockCompressionProperty(_) => "block_compression_property",
2339            Expression::CharacterSetProperty(_) => "character_set_property",
2340            Expression::ChecksumProperty(_) => "checksum_property",
2341            Expression::CollateProperty(_) => "collate_property",
2342            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2343            Expression::DataDeletionProperty(_) => "data_deletion_property",
2344            Expression::DefinerProperty(_) => "definer_property",
2345            Expression::DistKeyProperty(_) => "dist_key_property",
2346            Expression::DistributedByProperty(_) => "distributed_by_property",
2347            Expression::DistStyleProperty(_) => "dist_style_property",
2348            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2349            Expression::EngineProperty(_) => "engine_property",
2350            Expression::ToTableProperty(_) => "to_table_property",
2351            Expression::ExecuteAsProperty(_) => "execute_as_property",
2352            Expression::ExternalProperty(_) => "external_property",
2353            Expression::FallbackProperty(_) => "fallback_property",
2354            Expression::FileFormatProperty(_) => "file_format_property",
2355            Expression::CredentialsProperty(_) => "credentials_property",
2356            Expression::FreespaceProperty(_) => "freespace_property",
2357            Expression::InheritsProperty(_) => "inherits_property",
2358            Expression::InputModelProperty(_) => "input_model_property",
2359            Expression::OutputModelProperty(_) => "output_model_property",
2360            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2361            Expression::JournalProperty(_) => "journal_property",
2362            Expression::LanguageProperty(_) => "language_property",
2363            Expression::EnviromentProperty(_) => "enviroment_property",
2364            Expression::ClusteredByProperty(_) => "clustered_by_property",
2365            Expression::DictProperty(_) => "dict_property",
2366            Expression::DictRange(_) => "dict_range",
2367            Expression::OnCluster(_) => "on_cluster",
2368            Expression::LikeProperty(_) => "like_property",
2369            Expression::LocationProperty(_) => "location_property",
2370            Expression::LockProperty(_) => "lock_property",
2371            Expression::LockingProperty(_) => "locking_property",
2372            Expression::LogProperty(_) => "log_property",
2373            Expression::MaterializedProperty(_) => "materialized_property",
2374            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2375            Expression::OnProperty(_) => "on_property",
2376            Expression::OnCommitProperty(_) => "on_commit_property",
2377            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2378            Expression::PartitionByProperty(_) => "partition_by_property",
2379            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2380            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2381            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2382            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2383            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2384            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2385            Expression::PartitionList(_) => "partition_list",
2386            Expression::Partition(_) => "partition",
2387            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2388            Expression::UniqueKeyProperty(_) => "unique_key_property",
2389            Expression::RollupProperty(_) => "rollup_property",
2390            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2391            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2392            Expression::RemoteWithConnectionModelProperty(_) => {
2393                "remote_with_connection_model_property"
2394            }
2395            Expression::ReturnsProperty(_) => "returns_property",
2396            Expression::RowFormatProperty(_) => "row_format_property",
2397            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2398            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2399            Expression::QueryTransform(_) => "query_transform",
2400            Expression::SampleProperty(_) => "sample_property",
2401            Expression::SecurityProperty(_) => "security_property",
2402            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2403            Expression::SemanticView(_) => "semantic_view",
2404            Expression::SerdeProperties(_) => "serde_properties",
2405            Expression::SetProperty(_) => "set_property",
2406            Expression::SharingProperty(_) => "sharing_property",
2407            Expression::SetConfigProperty(_) => "set_config_property",
2408            Expression::SettingsProperty(_) => "settings_property",
2409            Expression::SortKeyProperty(_) => "sort_key_property",
2410            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2411            Expression::SqlSecurityProperty(_) => "sql_security_property",
2412            Expression::StabilityProperty(_) => "stability_property",
2413            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2414            Expression::TemporaryProperty(_) => "temporary_property",
2415            Expression::Tags(_) => "tags",
2416            Expression::TransformModelProperty(_) => "transform_model_property",
2417            Expression::TransientProperty(_) => "transient_property",
2418            Expression::UsingTemplateProperty(_) => "using_template_property",
2419            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2420            Expression::VolatileProperty(_) => "volatile_property",
2421            Expression::WithDataProperty(_) => "with_data_property",
2422            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2423            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2424            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2425            Expression::WithProcedureOptions(_) => "with_procedure_options",
2426            Expression::EncodeProperty(_) => "encode_property",
2427            Expression::IncludeProperty(_) => "include_property",
2428            Expression::Properties(_) => "properties",
2429            Expression::OptionsProperty(_) => "options_property",
2430            Expression::InputOutputFormat(_) => "input_output_format",
2431            Expression::Reference(_) => "reference",
2432            Expression::QueryOption(_) => "query_option",
2433            Expression::WithTableHint(_) => "with_table_hint",
2434            Expression::IndexTableHint(_) => "index_table_hint",
2435            Expression::HistoricalData(_) => "historical_data",
2436            Expression::Get(_) => "get",
2437            Expression::SetOperation(_) => "set_operation",
2438            Expression::Var(_) => "var",
2439            Expression::Variadic(_) => "variadic",
2440            Expression::Version(_) => "version",
2441            Expression::Schema(_) => "schema",
2442            Expression::Lock(_) => "lock",
2443            Expression::TableSample(_) => "table_sample",
2444            Expression::Tag(_) => "tag",
2445            Expression::UnpivotColumns(_) => "unpivot_columns",
2446            Expression::WindowSpec(_) => "window_spec",
2447            Expression::SessionParameter(_) => "session_parameter",
2448            Expression::PseudoType(_) => "pseudo_type",
2449            Expression::ObjectIdentifier(_) => "object_identifier",
2450            Expression::Transaction(_) => "transaction",
2451            Expression::Commit(_) => "commit",
2452            Expression::Rollback(_) => "rollback",
2453            Expression::AlterSession(_) => "alter_session",
2454            Expression::Analyze(_) => "analyze",
2455            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2456            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2457            Expression::AnalyzeSample(_) => "analyze_sample",
2458            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2459            Expression::AnalyzeDelete(_) => "analyze_delete",
2460            Expression::AnalyzeWith(_) => "analyze_with",
2461            Expression::AnalyzeValidate(_) => "analyze_validate",
2462            Expression::AddPartition(_) => "add_partition",
2463            Expression::AttachOption(_) => "attach_option",
2464            Expression::DropPartition(_) => "drop_partition",
2465            Expression::ReplacePartition(_) => "replace_partition",
2466            Expression::DPipe(_) => "d_pipe",
2467            Expression::Operator(_) => "operator",
2468            Expression::PivotAny(_) => "pivot_any",
2469            Expression::Aliases(_) => "aliases",
2470            Expression::AtIndex(_) => "at_index",
2471            Expression::FromTimeZone(_) => "from_time_zone",
2472            Expression::FormatPhrase(_) => "format_phrase",
2473            Expression::ForIn(_) => "for_in",
2474            Expression::TimeUnit(_) => "time_unit",
2475            Expression::IntervalOp(_) => "interval_op",
2476            Expression::IntervalSpan(_) => "interval_span",
2477            Expression::HavingMax(_) => "having_max",
2478            Expression::CosineDistance(_) => "cosine_distance",
2479            Expression::DotProduct(_) => "dot_product",
2480            Expression::EuclideanDistance(_) => "euclidean_distance",
2481            Expression::ManhattanDistance(_) => "manhattan_distance",
2482            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2483            Expression::Booland(_) => "booland",
2484            Expression::Boolor(_) => "boolor",
2485            Expression::ParameterizedAgg(_) => "parameterized_agg",
2486            Expression::ArgMax(_) => "arg_max",
2487            Expression::ArgMin(_) => "arg_min",
2488            Expression::ApproxTopK(_) => "approx_top_k",
2489            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2490            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2491            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2492            Expression::ApproxTopSum(_) => "approx_top_sum",
2493            Expression::ApproxQuantiles(_) => "approx_quantiles",
2494            Expression::Minhash(_) => "minhash",
2495            Expression::FarmFingerprint(_) => "farm_fingerprint",
2496            Expression::Float64(_) => "float64",
2497            Expression::Transform(_) => "transform",
2498            Expression::Translate(_) => "translate",
2499            Expression::Grouping(_) => "grouping",
2500            Expression::GroupingId(_) => "grouping_id",
2501            Expression::Anonymous(_) => "anonymous",
2502            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2503            Expression::CombinedAggFunc(_) => "combined_agg_func",
2504            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2505            Expression::HashAgg(_) => "hash_agg",
2506            Expression::Hll(_) => "hll",
2507            Expression::Apply(_) => "apply",
2508            Expression::ToBoolean(_) => "to_boolean",
2509            Expression::List(_) => "list",
2510            Expression::ToMap(_) => "to_map",
2511            Expression::Pad(_) => "pad",
2512            Expression::ToChar(_) => "to_char",
2513            Expression::ToNumber(_) => "to_number",
2514            Expression::ToDouble(_) => "to_double",
2515            Expression::Int64(_) => "int64",
2516            Expression::StringFunc(_) => "string_func",
2517            Expression::ToDecfloat(_) => "to_decfloat",
2518            Expression::TryToDecfloat(_) => "try_to_decfloat",
2519            Expression::ToFile(_) => "to_file",
2520            Expression::Columns(_) => "columns",
2521            Expression::ConvertToCharset(_) => "convert_to_charset",
2522            Expression::ConvertTimezone(_) => "convert_timezone",
2523            Expression::GenerateSeries(_) => "generate_series",
2524            Expression::AIAgg(_) => "a_i_agg",
2525            Expression::AIClassify(_) => "a_i_classify",
2526            Expression::ArrayAll(_) => "array_all",
2527            Expression::ArrayAny(_) => "array_any",
2528            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2529            Expression::StPoint(_) => "st_point",
2530            Expression::StDistance(_) => "st_distance",
2531            Expression::StringToArray(_) => "string_to_array",
2532            Expression::ArraySum(_) => "array_sum",
2533            Expression::ObjectAgg(_) => "object_agg",
2534            Expression::CastToStrType(_) => "cast_to_str_type",
2535            Expression::CheckJson(_) => "check_json",
2536            Expression::CheckXml(_) => "check_xml",
2537            Expression::TranslateCharacters(_) => "translate_characters",
2538            Expression::CurrentSchemas(_) => "current_schemas",
2539            Expression::CurrentDatetime(_) => "current_datetime",
2540            Expression::Localtime(_) => "localtime",
2541            Expression::Localtimestamp(_) => "localtimestamp",
2542            Expression::Systimestamp(_) => "systimestamp",
2543            Expression::CurrentSchema(_) => "current_schema",
2544            Expression::CurrentUser(_) => "current_user",
2545            Expression::UtcTime(_) => "utc_time",
2546            Expression::UtcTimestamp(_) => "utc_timestamp",
2547            Expression::Timestamp(_) => "timestamp",
2548            Expression::DateBin(_) => "date_bin",
2549            Expression::Datetime(_) => "datetime",
2550            Expression::DatetimeAdd(_) => "datetime_add",
2551            Expression::DatetimeSub(_) => "datetime_sub",
2552            Expression::DatetimeDiff(_) => "datetime_diff",
2553            Expression::DatetimeTrunc(_) => "datetime_trunc",
2554            Expression::Dayname(_) => "dayname",
2555            Expression::MakeInterval(_) => "make_interval",
2556            Expression::PreviousDay(_) => "previous_day",
2557            Expression::Elt(_) => "elt",
2558            Expression::TimestampAdd(_) => "timestamp_add",
2559            Expression::TimestampSub(_) => "timestamp_sub",
2560            Expression::TimestampDiff(_) => "timestamp_diff",
2561            Expression::TimeSlice(_) => "time_slice",
2562            Expression::TimeAdd(_) => "time_add",
2563            Expression::TimeSub(_) => "time_sub",
2564            Expression::TimeDiff(_) => "time_diff",
2565            Expression::TimeTrunc(_) => "time_trunc",
2566            Expression::DateFromParts(_) => "date_from_parts",
2567            Expression::TimeFromParts(_) => "time_from_parts",
2568            Expression::DecodeCase(_) => "decode_case",
2569            Expression::Decrypt(_) => "decrypt",
2570            Expression::DecryptRaw(_) => "decrypt_raw",
2571            Expression::Encode(_) => "encode",
2572            Expression::Encrypt(_) => "encrypt",
2573            Expression::EncryptRaw(_) => "encrypt_raw",
2574            Expression::EqualNull(_) => "equal_null",
2575            Expression::ToBinary(_) => "to_binary",
2576            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2577            Expression::Base64DecodeString(_) => "base64_decode_string",
2578            Expression::Base64Encode(_) => "base64_encode",
2579            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2580            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2581            Expression::GapFill(_) => "gap_fill",
2582            Expression::GenerateDateArray(_) => "generate_date_array",
2583            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2584            Expression::GetExtract(_) => "get_extract",
2585            Expression::Getbit(_) => "getbit",
2586            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2587            Expression::HexEncode(_) => "hex_encode",
2588            Expression::Compress(_) => "compress",
2589            Expression::DecompressBinary(_) => "decompress_binary",
2590            Expression::DecompressString(_) => "decompress_string",
2591            Expression::Xor(_) => "xor",
2592            Expression::Nullif(_) => "nullif",
2593            Expression::JSON(_) => "j_s_o_n",
2594            Expression::JSONPath(_) => "j_s_o_n_path",
2595            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2596            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2597            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2598            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2599            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2600            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2601            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2602            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2603            Expression::Format(_) => "format",
2604            Expression::JSONKeys(_) => "j_s_o_n_keys",
2605            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2606            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2607            Expression::JSONObject(_) => "j_s_o_n_object",
2608            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2609            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2610            Expression::JSONArray(_) => "j_s_o_n_array",
2611            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2612            Expression::JSONExists(_) => "j_s_o_n_exists",
2613            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2614            Expression::JSONSchema(_) => "j_s_o_n_schema",
2615            Expression::JSONSet(_) => "j_s_o_n_set",
2616            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2617            Expression::JSONValue(_) => "j_s_o_n_value",
2618            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2619            Expression::JSONRemove(_) => "j_s_o_n_remove",
2620            Expression::JSONTable(_) => "j_s_o_n_table",
2621            Expression::JSONType(_) => "j_s_o_n_type",
2622            Expression::ObjectInsert(_) => "object_insert",
2623            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2624            Expression::OpenJSON(_) => "open_j_s_o_n",
2625            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2626            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2627            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2628            Expression::JSONCast(_) => "j_s_o_n_cast",
2629            Expression::JSONExtract(_) => "j_s_o_n_extract",
2630            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2631            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2632            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2633            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2634            Expression::JSONFormat(_) => "j_s_o_n_format",
2635            Expression::JSONBool(_) => "j_s_o_n_bool",
2636            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2637            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2638            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2639            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2640            Expression::ParseJSON(_) => "parse_j_s_o_n",
2641            Expression::ParseUrl(_) => "parse_url",
2642            Expression::ParseIp(_) => "parse_ip",
2643            Expression::ParseTime(_) => "parse_time",
2644            Expression::ParseDatetime(_) => "parse_datetime",
2645            Expression::Map(_) => "map",
2646            Expression::MapCat(_) => "map_cat",
2647            Expression::MapDelete(_) => "map_delete",
2648            Expression::MapInsert(_) => "map_insert",
2649            Expression::MapPick(_) => "map_pick",
2650            Expression::ScopeResolution(_) => "scope_resolution",
2651            Expression::Slice(_) => "slice",
2652            Expression::VarMap(_) => "var_map",
2653            Expression::MatchAgainst(_) => "match_against",
2654            Expression::MD5Digest(_) => "m_d5_digest",
2655            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2656            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2657            Expression::Monthname(_) => "monthname",
2658            Expression::Ntile(_) => "ntile",
2659            Expression::Normalize(_) => "normalize",
2660            Expression::Normal(_) => "normal",
2661            Expression::Predict(_) => "predict",
2662            Expression::MLTranslate(_) => "m_l_translate",
2663            Expression::FeaturesAtTime(_) => "features_at_time",
2664            Expression::GenerateEmbedding(_) => "generate_embedding",
2665            Expression::MLForecast(_) => "m_l_forecast",
2666            Expression::ModelAttribute(_) => "model_attribute",
2667            Expression::VectorSearch(_) => "vector_search",
2668            Expression::Quantile(_) => "quantile",
2669            Expression::ApproxQuantile(_) => "approx_quantile",
2670            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2671            Expression::Randn(_) => "randn",
2672            Expression::Randstr(_) => "randstr",
2673            Expression::RangeN(_) => "range_n",
2674            Expression::RangeBucket(_) => "range_bucket",
2675            Expression::ReadCSV(_) => "read_c_s_v",
2676            Expression::ReadParquet(_) => "read_parquet",
2677            Expression::Reduce(_) => "reduce",
2678            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2679            Expression::RegexpILike(_) => "regexp_i_like",
2680            Expression::RegexpFullMatch(_) => "regexp_full_match",
2681            Expression::RegexpInstr(_) => "regexp_instr",
2682            Expression::RegexpSplit(_) => "regexp_split",
2683            Expression::RegexpCount(_) => "regexp_count",
2684            Expression::RegrValx(_) => "regr_valx",
2685            Expression::RegrValy(_) => "regr_valy",
2686            Expression::RegrAvgy(_) => "regr_avgy",
2687            Expression::RegrAvgx(_) => "regr_avgx",
2688            Expression::RegrCount(_) => "regr_count",
2689            Expression::RegrIntercept(_) => "regr_intercept",
2690            Expression::RegrR2(_) => "regr_r2",
2691            Expression::RegrSxx(_) => "regr_sxx",
2692            Expression::RegrSxy(_) => "regr_sxy",
2693            Expression::RegrSyy(_) => "regr_syy",
2694            Expression::RegrSlope(_) => "regr_slope",
2695            Expression::SafeAdd(_) => "safe_add",
2696            Expression::SafeDivide(_) => "safe_divide",
2697            Expression::SafeMultiply(_) => "safe_multiply",
2698            Expression::SafeSubtract(_) => "safe_subtract",
2699            Expression::SHA2(_) => "s_h_a2",
2700            Expression::SHA2Digest(_) => "s_h_a2_digest",
2701            Expression::SortArray(_) => "sort_array",
2702            Expression::SplitPart(_) => "split_part",
2703            Expression::SubstringIndex(_) => "substring_index",
2704            Expression::StandardHash(_) => "standard_hash",
2705            Expression::StrPosition(_) => "str_position",
2706            Expression::Search(_) => "search",
2707            Expression::SearchIp(_) => "search_ip",
2708            Expression::StrToDate(_) => "str_to_date",
2709            Expression::DateStrToDate(_) => "date_str_to_date",
2710            Expression::DateToDateStr(_) => "date_to_date_str",
2711            Expression::StrToTime(_) => "str_to_time",
2712            Expression::StrToUnix(_) => "str_to_unix",
2713            Expression::StrToMap(_) => "str_to_map",
2714            Expression::NumberToStr(_) => "number_to_str",
2715            Expression::FromBase(_) => "from_base",
2716            Expression::Stuff(_) => "stuff",
2717            Expression::TimeToStr(_) => "time_to_str",
2718            Expression::TimeStrToTime(_) => "time_str_to_time",
2719            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2720            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2721            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2722            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2723            Expression::Unhex(_) => "unhex",
2724            Expression::Uniform(_) => "uniform",
2725            Expression::UnixToStr(_) => "unix_to_str",
2726            Expression::UnixToTime(_) => "unix_to_time",
2727            Expression::Uuid(_) => "uuid",
2728            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2729            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2730            Expression::Corr(_) => "corr",
2731            Expression::WidthBucket(_) => "width_bucket",
2732            Expression::CovarSamp(_) => "covar_samp",
2733            Expression::CovarPop(_) => "covar_pop",
2734            Expression::Week(_) => "week",
2735            Expression::XMLElement(_) => "x_m_l_element",
2736            Expression::XMLGet(_) => "x_m_l_get",
2737            Expression::XMLTable(_) => "x_m_l_table",
2738            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2739            Expression::Zipf(_) => "zipf",
2740            Expression::Merge(_) => "merge",
2741            Expression::When(_) => "when",
2742            Expression::Whens(_) => "whens",
2743            Expression::NextValueFor(_) => "next_value_for",
2744            Expression::ReturnStmt(_) => "return_stmt",
2745        }
2746    }
2747
2748    /// Returns the primary child expression (".this" in sqlglot).
2749    pub fn get_this(&self) -> Option<&Expression> {
2750        match self {
2751            // Unary ops
2752            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2753            // UnaryFunc variants
2754            Expression::Upper(f)
2755            | Expression::Lower(f)
2756            | Expression::Length(f)
2757            | Expression::LTrim(f)
2758            | Expression::RTrim(f)
2759            | Expression::Reverse(f)
2760            | Expression::Abs(f)
2761            | Expression::Sqrt(f)
2762            | Expression::Cbrt(f)
2763            | Expression::Ln(f)
2764            | Expression::Exp(f)
2765            | Expression::Sign(f)
2766            | Expression::Date(f)
2767            | Expression::Time(f)
2768            | Expression::Initcap(f)
2769            | Expression::Ascii(f)
2770            | Expression::Chr(f)
2771            | Expression::Soundex(f)
2772            | Expression::ByteLength(f)
2773            | Expression::Hex(f)
2774            | Expression::LowerHex(f)
2775            | Expression::Unicode(f)
2776            | Expression::Typeof(f)
2777            | Expression::Explode(f)
2778            | Expression::ExplodeOuter(f)
2779            | Expression::MapFromEntries(f)
2780            | Expression::MapKeys(f)
2781            | Expression::MapValues(f)
2782            | Expression::ArrayLength(f)
2783            | Expression::ArraySize(f)
2784            | Expression::Cardinality(f)
2785            | Expression::ArrayReverse(f)
2786            | Expression::ArrayDistinct(f)
2787            | Expression::ArrayFlatten(f)
2788            | Expression::ArrayCompact(f)
2789            | Expression::ToArray(f)
2790            | Expression::JsonArrayLength(f)
2791            | Expression::JsonKeys(f)
2792            | Expression::JsonType(f)
2793            | Expression::ParseJson(f)
2794            | Expression::ToJson(f)
2795            | Expression::Radians(f)
2796            | Expression::Degrees(f)
2797            | Expression::Sin(f)
2798            | Expression::Cos(f)
2799            | Expression::Tan(f)
2800            | Expression::Asin(f)
2801            | Expression::Acos(f)
2802            | Expression::Atan(f)
2803            | Expression::IsNan(f)
2804            | Expression::IsInf(f)
2805            | Expression::Year(f)
2806            | Expression::Month(f)
2807            | Expression::Day(f)
2808            | Expression::Hour(f)
2809            | Expression::Minute(f)
2810            | Expression::Second(f)
2811            | Expression::DayOfWeek(f)
2812            | Expression::DayOfWeekIso(f)
2813            | Expression::DayOfMonth(f)
2814            | Expression::DayOfYear(f)
2815            | Expression::WeekOfYear(f)
2816            | Expression::Quarter(f)
2817            | Expression::Epoch(f)
2818            | Expression::EpochMs(f)
2819            | Expression::BitwiseCount(f)
2820            | Expression::DateFromUnixDate(f)
2821            | Expression::UnixDate(f)
2822            | Expression::UnixSeconds(f)
2823            | Expression::UnixMillis(f)
2824            | Expression::UnixMicros(f)
2825            | Expression::TimeStrToDate(f)
2826            | Expression::DateToDi(f)
2827            | Expression::DiToDate(f)
2828            | Expression::TsOrDiToDi(f)
2829            | Expression::TsOrDsToDatetime(f)
2830            | Expression::TsOrDsToTimestamp(f)
2831            | Expression::YearOfWeek(f)
2832            | Expression::YearOfWeekIso(f)
2833            | Expression::SHA(f)
2834            | Expression::SHA1Digest(f)
2835            | Expression::TimeToUnix(f)
2836            | Expression::TimeStrToUnix(f)
2837            | Expression::Int64(f)
2838            | Expression::JSONBool(f)
2839            | Expression::MD5NumberLower64(f)
2840            | Expression::MD5NumberUpper64(f)
2841            | Expression::DateStrToDate(f)
2842            | Expression::DateToDateStr(f) => Some(&f.this),
2843            // BinaryFunc - this is the primary child
2844            Expression::Power(f)
2845            | Expression::NullIf(f)
2846            | Expression::IfNull(f)
2847            | Expression::Nvl(f)
2848            | Expression::Contains(f)
2849            | Expression::StartsWith(f)
2850            | Expression::EndsWith(f)
2851            | Expression::Levenshtein(f)
2852            | Expression::ModFunc(f)
2853            | Expression::IntDiv(f)
2854            | Expression::Atan2(f)
2855            | Expression::AddMonths(f)
2856            | Expression::MonthsBetween(f)
2857            | Expression::NextDay(f)
2858            | Expression::UnixToTimeStr(f)
2859            | Expression::ArrayContains(f)
2860            | Expression::ArrayPosition(f)
2861            | Expression::ArrayAppend(f)
2862            | Expression::ArrayPrepend(f)
2863            | Expression::ArrayUnion(f)
2864            | Expression::ArrayExcept(f)
2865            | Expression::ArrayRemove(f)
2866            | Expression::StarMap(f)
2867            | Expression::MapFromArrays(f)
2868            | Expression::MapContainsKey(f)
2869            | Expression::ElementAt(f)
2870            | Expression::JsonMergePatch(f)
2871            | Expression::JSONBContains(f)
2872            | Expression::JSONBExtract(f) => Some(&f.this),
2873            // AggFunc - this is the primary child
2874            Expression::Sum(af)
2875            | Expression::Avg(af)
2876            | Expression::Min(af)
2877            | Expression::Max(af)
2878            | Expression::ArrayAgg(af)
2879            | Expression::CountIf(af)
2880            | Expression::Stddev(af)
2881            | Expression::StddevPop(af)
2882            | Expression::StddevSamp(af)
2883            | Expression::Variance(af)
2884            | Expression::VarPop(af)
2885            | Expression::VarSamp(af)
2886            | Expression::Median(af)
2887            | Expression::Mode(af)
2888            | Expression::First(af)
2889            | Expression::Last(af)
2890            | Expression::AnyValue(af)
2891            | Expression::ApproxDistinct(af)
2892            | Expression::ApproxCountDistinct(af)
2893            | Expression::LogicalAnd(af)
2894            | Expression::LogicalOr(af)
2895            | Expression::Skewness(af)
2896            | Expression::ArrayConcatAgg(af)
2897            | Expression::ArrayUniqueAgg(af)
2898            | Expression::BoolXorAgg(af)
2899            | Expression::BitwiseAndAgg(af)
2900            | Expression::BitwiseOrAgg(af)
2901            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2902            // Binary operations - left is "this" in sqlglot
2903            Expression::And(op)
2904            | Expression::Or(op)
2905            | Expression::Add(op)
2906            | Expression::Sub(op)
2907            | Expression::Mul(op)
2908            | Expression::Div(op)
2909            | Expression::Mod(op)
2910            | Expression::Eq(op)
2911            | Expression::Neq(op)
2912            | Expression::Lt(op)
2913            | Expression::Lte(op)
2914            | Expression::Gt(op)
2915            | Expression::Gte(op)
2916            | Expression::BitwiseAnd(op)
2917            | Expression::BitwiseOr(op)
2918            | Expression::BitwiseXor(op)
2919            | Expression::Concat(op)
2920            | Expression::Adjacent(op)
2921            | Expression::TsMatch(op)
2922            | Expression::PropertyEQ(op)
2923            | Expression::ArrayContainsAll(op)
2924            | Expression::ArrayContainedBy(op)
2925            | Expression::ArrayOverlaps(op)
2926            | Expression::JSONBContainsAllTopKeys(op)
2927            | Expression::JSONBContainsAnyTopKeys(op)
2928            | Expression::JSONBDeleteAtPath(op)
2929            | Expression::ExtendsLeft(op)
2930            | Expression::ExtendsRight(op)
2931            | Expression::Is(op)
2932            | Expression::MemberOf(op)
2933            | Expression::Match(op)
2934            | Expression::NullSafeEq(op)
2935            | Expression::NullSafeNeq(op)
2936            | Expression::Glob(op)
2937            | Expression::BitwiseLeftShift(op)
2938            | Expression::BitwiseRightShift(op) => Some(&op.left),
2939            // Like operations - left is "this"
2940            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2941            // Structural types with .this
2942            Expression::Alias(a) => Some(&a.this),
2943            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2944            Expression::Paren(p) => Some(&p.this),
2945            Expression::Annotated(a) => Some(&a.this),
2946            Expression::Subquery(s) => Some(&s.this),
2947            Expression::Where(w) => Some(&w.this),
2948            Expression::Having(h) => Some(&h.this),
2949            Expression::Qualify(q) => Some(&q.this),
2950            Expression::IsNull(i) => Some(&i.this),
2951            Expression::Exists(e) => Some(&e.this),
2952            Expression::Ordered(o) => Some(&o.this),
2953            Expression::WindowFunction(wf) => Some(&wf.this),
2954            Expression::Cte(cte) => Some(&cte.this),
2955            Expression::Between(b) => Some(&b.this),
2956            Expression::In(i) => Some(&i.this),
2957            Expression::ReturnStmt(e) => Some(e),
2958            _ => None,
2959        }
2960    }
2961
2962    /// Returns the secondary child expression (".expression" in sqlglot).
2963    pub fn get_expression(&self) -> Option<&Expression> {
2964        match self {
2965            // Binary operations - right is "expression"
2966            Expression::And(op)
2967            | Expression::Or(op)
2968            | Expression::Add(op)
2969            | Expression::Sub(op)
2970            | Expression::Mul(op)
2971            | Expression::Div(op)
2972            | Expression::Mod(op)
2973            | Expression::Eq(op)
2974            | Expression::Neq(op)
2975            | Expression::Lt(op)
2976            | Expression::Lte(op)
2977            | Expression::Gt(op)
2978            | Expression::Gte(op)
2979            | Expression::BitwiseAnd(op)
2980            | Expression::BitwiseOr(op)
2981            | Expression::BitwiseXor(op)
2982            | Expression::Concat(op)
2983            | Expression::Adjacent(op)
2984            | Expression::TsMatch(op)
2985            | Expression::PropertyEQ(op)
2986            | Expression::ArrayContainsAll(op)
2987            | Expression::ArrayContainedBy(op)
2988            | Expression::ArrayOverlaps(op)
2989            | Expression::JSONBContainsAllTopKeys(op)
2990            | Expression::JSONBContainsAnyTopKeys(op)
2991            | Expression::JSONBDeleteAtPath(op)
2992            | Expression::ExtendsLeft(op)
2993            | Expression::ExtendsRight(op)
2994            | Expression::Is(op)
2995            | Expression::MemberOf(op)
2996            | Expression::Match(op)
2997            | Expression::NullSafeEq(op)
2998            | Expression::NullSafeNeq(op)
2999            | Expression::Glob(op)
3000            | Expression::BitwiseLeftShift(op)
3001            | Expression::BitwiseRightShift(op) => Some(&op.right),
3002            // Like operations - right is "expression"
3003            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3004            // BinaryFunc - expression is the secondary
3005            Expression::Power(f)
3006            | Expression::NullIf(f)
3007            | Expression::IfNull(f)
3008            | Expression::Nvl(f)
3009            | Expression::Contains(f)
3010            | Expression::StartsWith(f)
3011            | Expression::EndsWith(f)
3012            | Expression::Levenshtein(f)
3013            | Expression::ModFunc(f)
3014            | Expression::IntDiv(f)
3015            | Expression::Atan2(f)
3016            | Expression::AddMonths(f)
3017            | Expression::MonthsBetween(f)
3018            | Expression::NextDay(f)
3019            | Expression::UnixToTimeStr(f)
3020            | Expression::ArrayContains(f)
3021            | Expression::ArrayPosition(f)
3022            | Expression::ArrayAppend(f)
3023            | Expression::ArrayPrepend(f)
3024            | Expression::ArrayUnion(f)
3025            | Expression::ArrayExcept(f)
3026            | Expression::ArrayRemove(f)
3027            | Expression::StarMap(f)
3028            | Expression::MapFromArrays(f)
3029            | Expression::MapContainsKey(f)
3030            | Expression::ElementAt(f)
3031            | Expression::JsonMergePatch(f)
3032            | Expression::JSONBContains(f)
3033            | Expression::JSONBExtract(f) => Some(&f.expression),
3034            _ => None,
3035        }
3036    }
3037
3038    /// Returns the list of child expressions (".expressions" in sqlglot).
3039    pub fn get_expressions(&self) -> &[Expression] {
3040        match self {
3041            Expression::Select(s) => &s.expressions,
3042            Expression::Function(f) => &f.args,
3043            Expression::AggregateFunction(f) => &f.args,
3044            Expression::From(f) => &f.expressions,
3045            Expression::GroupBy(g) => &g.expressions,
3046            Expression::In(i) => &i.expressions,
3047            Expression::Array(a) => &a.expressions,
3048            Expression::Tuple(t) => &t.expressions,
3049            Expression::Coalesce(f)
3050            | Expression::Greatest(f)
3051            | Expression::Least(f)
3052            | Expression::ArrayConcat(f)
3053            | Expression::ArrayIntersect(f)
3054            | Expression::ArrayZip(f)
3055            | Expression::MapConcat(f)
3056            | Expression::JsonArray(f) => &f.expressions,
3057            _ => &[],
3058        }
3059    }
3060
3061    /// Returns the name of this expression as a string slice.
3062    pub fn get_name(&self) -> &str {
3063        match self {
3064            Expression::Identifier(id) => &id.name,
3065            Expression::Column(col) => &col.name.name,
3066            Expression::Table(t) => &t.name.name,
3067            Expression::Literal(lit) => lit.value_str(),
3068            Expression::Star(_) => "*",
3069            Expression::Function(f) => &f.name,
3070            Expression::AggregateFunction(f) => &f.name,
3071            Expression::Alias(a) => a.this.get_name(),
3072            Expression::Boolean(b) => {
3073                if b.value {
3074                    "TRUE"
3075                } else {
3076                    "FALSE"
3077                }
3078            }
3079            Expression::Null(_) => "NULL",
3080            _ => "",
3081        }
3082    }
3083
3084    /// Returns the alias name if this expression has one.
3085    pub fn get_alias(&self) -> &str {
3086        match self {
3087            Expression::Alias(a) => &a.alias.name,
3088            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3089            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3090            _ => "",
3091        }
3092    }
3093
3094    /// Returns the output name of this expression (what it shows up as in a SELECT).
3095    pub fn get_output_name(&self) -> &str {
3096        match self {
3097            Expression::Alias(a) => &a.alias.name,
3098            Expression::Column(c) => &c.name.name,
3099            Expression::Identifier(id) => &id.name,
3100            Expression::Literal(lit) => lit.value_str(),
3101            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3102            Expression::Star(_) => "*",
3103            _ => "",
3104        }
3105    }
3106
3107    /// Returns comments attached to this expression.
3108    pub fn get_comments(&self) -> Vec<&str> {
3109        match self {
3110            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3111            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3112            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3113            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3114            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3115            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3116            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3117                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3118            }
3119            Expression::And(op)
3120            | Expression::Or(op)
3121            | Expression::Add(op)
3122            | Expression::Sub(op)
3123            | Expression::Mul(op)
3124            | Expression::Div(op)
3125            | Expression::Mod(op)
3126            | Expression::Eq(op)
3127            | Expression::Neq(op)
3128            | Expression::Lt(op)
3129            | Expression::Lte(op)
3130            | Expression::Gt(op)
3131            | Expression::Gte(op)
3132            | Expression::Concat(op)
3133            | Expression::BitwiseAnd(op)
3134            | Expression::BitwiseOr(op)
3135            | Expression::BitwiseXor(op) => {
3136                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3137            }
3138            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3139            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3140            _ => Vec::new(),
3141        }
3142    }
3143}
3144
3145impl fmt::Display for Expression {
3146    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3147        // Basic display - full SQL generation is in generator module
3148        match self {
3149            Expression::Literal(lit) => write!(f, "{}", lit),
3150            Expression::Identifier(id) => write!(f, "{}", id),
3151            Expression::Column(col) => write!(f, "{}", col),
3152            Expression::Star(_) => write!(f, "*"),
3153            Expression::Null(_) => write!(f, "NULL"),
3154            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3155            Expression::Select(_) => write!(f, "SELECT ..."),
3156            _ => write!(f, "{:?}", self),
3157        }
3158    }
3159}
3160
3161/// Represent a SQL literal value.
3162///
3163/// Numeric values are stored as their original text representation (not parsed
3164/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3165/// preserved across round-trips.
3166///
3167/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3168/// strings, raw strings, etc.) each have a dedicated variant so that the
3169/// generator can emit them with the correct syntax.
3170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3171#[cfg_attr(feature = "bindings", derive(TS))]
3172#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3173pub enum Literal {
3174    /// Single-quoted string literal: `'hello'`
3175    String(String),
3176    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3177    Number(String),
3178    /// Hex string literal: `X'FF'`
3179    HexString(String),
3180    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3181    HexNumber(String),
3182    BitString(String),
3183    /// Byte string: b"..." (BigQuery style)
3184    ByteString(String),
3185    /// National string: N'abc'
3186    NationalString(String),
3187    /// DATE literal: DATE '2024-01-15'
3188    Date(String),
3189    /// TIME literal: TIME '10:30:00'
3190    Time(String),
3191    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3192    Timestamp(String),
3193    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3194    Datetime(String),
3195    /// Triple-quoted string: """...""" or '''...'''
3196    /// Contains (content, quote_char) where quote_char is '"' or '\''
3197    TripleQuotedString(String, char),
3198    /// Escape string: E'...' (PostgreSQL)
3199    EscapeString(String),
3200    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3201    DollarString(String),
3202    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3203    /// In raw strings, backslashes are literal and not escape characters.
3204    /// When converting to a regular string, backslashes must be doubled.
3205    RawString(String),
3206}
3207
3208impl Literal {
3209    /// Returns the inner value as a string slice, regardless of literal type.
3210    pub fn value_str(&self) -> &str {
3211        match self {
3212            Literal::String(s)
3213            | Literal::Number(s)
3214            | Literal::HexString(s)
3215            | Literal::HexNumber(s)
3216            | Literal::BitString(s)
3217            | Literal::ByteString(s)
3218            | Literal::NationalString(s)
3219            | Literal::Date(s)
3220            | Literal::Time(s)
3221            | Literal::Timestamp(s)
3222            | Literal::Datetime(s)
3223            | Literal::EscapeString(s)
3224            | Literal::DollarString(s)
3225            | Literal::RawString(s) => s.as_str(),
3226            Literal::TripleQuotedString(s, _) => s.as_str(),
3227        }
3228    }
3229
3230    /// Returns `true` if this is a string-type literal.
3231    pub fn is_string(&self) -> bool {
3232        matches!(
3233            self,
3234            Literal::String(_)
3235                | Literal::NationalString(_)
3236                | Literal::EscapeString(_)
3237                | Literal::DollarString(_)
3238                | Literal::RawString(_)
3239                | Literal::TripleQuotedString(_, _)
3240        )
3241    }
3242
3243    /// Returns `true` if this is a numeric literal.
3244    pub fn is_number(&self) -> bool {
3245        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3246    }
3247}
3248
3249impl fmt::Display for Literal {
3250    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3251        match self {
3252            Literal::String(s) => write!(f, "'{}'", s),
3253            Literal::Number(n) => write!(f, "{}", n),
3254            Literal::HexString(h) => write!(f, "X'{}'", h),
3255            Literal::HexNumber(h) => write!(f, "0x{}", h),
3256            Literal::BitString(b) => write!(f, "B'{}'", b),
3257            Literal::ByteString(b) => write!(f, "b'{}'", b),
3258            Literal::NationalString(s) => write!(f, "N'{}'", s),
3259            Literal::Date(d) => write!(f, "DATE '{}'", d),
3260            Literal::Time(t) => write!(f, "TIME '{}'", t),
3261            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3262            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3263            Literal::TripleQuotedString(s, q) => {
3264                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3265            }
3266            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3267            Literal::DollarString(s) => write!(f, "$${}$$", s),
3268            Literal::RawString(s) => write!(f, "r'{}'", s),
3269        }
3270    }
3271}
3272
3273/// Boolean literal
3274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3275#[cfg_attr(feature = "bindings", derive(TS))]
3276pub struct BooleanLiteral {
3277    pub value: bool,
3278}
3279
3280/// NULL literal
3281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3282#[cfg_attr(feature = "bindings", derive(TS))]
3283pub struct Null;
3284
3285/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3286///
3287/// The `quoted` flag indicates whether the identifier was originally delimited
3288/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3289/// dialect). The generator uses this flag to decide whether to emit quoting
3290/// characters.
3291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3292#[cfg_attr(feature = "bindings", derive(TS))]
3293pub struct Identifier {
3294    /// The raw text of the identifier, without any quoting characters.
3295    pub name: String,
3296    /// Whether the identifier was quoted in the source SQL.
3297    pub quoted: bool,
3298    #[serde(default)]
3299    pub trailing_comments: Vec<String>,
3300    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3301    #[serde(default, skip_serializing_if = "Option::is_none")]
3302    pub span: Option<Span>,
3303}
3304
3305impl Identifier {
3306    pub fn new(name: impl Into<String>) -> Self {
3307        Self {
3308            name: name.into(),
3309            quoted: false,
3310            trailing_comments: Vec::new(),
3311            span: None,
3312        }
3313    }
3314
3315    pub fn quoted(name: impl Into<String>) -> Self {
3316        Self {
3317            name: name.into(),
3318            quoted: true,
3319            trailing_comments: Vec::new(),
3320            span: None,
3321        }
3322    }
3323
3324    pub fn empty() -> Self {
3325        Self {
3326            name: String::new(),
3327            quoted: false,
3328            trailing_comments: Vec::new(),
3329            span: None,
3330        }
3331    }
3332
3333    pub fn is_empty(&self) -> bool {
3334        self.name.is_empty()
3335    }
3336
3337    /// Set the source span on this identifier
3338    pub fn with_span(mut self, span: Span) -> Self {
3339        self.span = Some(span);
3340        self
3341    }
3342}
3343
3344impl fmt::Display for Identifier {
3345    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3346        if self.quoted {
3347            write!(f, "\"{}\"", self.name)
3348        } else {
3349            write!(f, "{}", self.name)
3350        }
3351    }
3352}
3353
3354/// Represent a column reference, optionally qualified by a table name.
3355///
3356/// Renders as `name` when unqualified, or `table.name` when qualified.
3357/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3358/// convenient construction.
3359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3360#[cfg_attr(feature = "bindings", derive(TS))]
3361pub struct Column {
3362    /// The column name.
3363    pub name: Identifier,
3364    /// Optional table qualifier (e.g. `t` in `t.col`).
3365    pub table: Option<Identifier>,
3366    /// Oracle-style join marker (+) for outer joins
3367    #[serde(default)]
3368    pub join_mark: bool,
3369    /// Trailing comments that appeared after this column reference
3370    #[serde(default)]
3371    pub trailing_comments: Vec<String>,
3372    /// Source position span
3373    #[serde(default, skip_serializing_if = "Option::is_none")]
3374    pub span: Option<Span>,
3375    /// Inferred data type from type annotation
3376    #[serde(default, skip_serializing_if = "Option::is_none")]
3377    pub inferred_type: Option<DataType>,
3378}
3379
3380impl fmt::Display for Column {
3381    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3382        if let Some(table) = &self.table {
3383            write!(f, "{}.{}", table, self.name)
3384        } else {
3385            write!(f, "{}", self.name)
3386        }
3387    }
3388}
3389
3390/// Represent a table reference with optional schema and catalog qualifiers.
3391///
3392/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3393/// which qualifiers are present. Supports aliases, column alias lists,
3394/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3395/// several other dialect-specific extensions.
3396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3397#[cfg_attr(feature = "bindings", derive(TS))]
3398pub struct TableRef {
3399    /// The unqualified table name.
3400    pub name: Identifier,
3401    /// Optional schema qualifier (e.g. `public` in `public.users`).
3402    pub schema: Option<Identifier>,
3403    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3404    pub catalog: Option<Identifier>,
3405    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3406    pub alias: Option<Identifier>,
3407    /// Whether AS keyword was explicitly used for the alias
3408    #[serde(default)]
3409    pub alias_explicit_as: bool,
3410    /// Column aliases for table alias: AS t(c1, c2)
3411    #[serde(default)]
3412    pub column_aliases: Vec<Identifier>,
3413    /// Leading comments that appeared before this table reference in a FROM clause
3414    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3415    pub leading_comments: Vec<String>,
3416    /// Trailing comments that appeared after this table reference
3417    #[serde(default)]
3418    pub trailing_comments: Vec<String>,
3419    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3420    #[serde(default)]
3421    pub when: Option<Box<HistoricalData>>,
3422    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3423    #[serde(default)]
3424    pub only: bool,
3425    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3426    #[serde(default)]
3427    pub final_: bool,
3428    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3429    #[serde(default, skip_serializing_if = "Option::is_none")]
3430    pub table_sample: Option<Box<Sample>>,
3431    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3432    #[serde(default)]
3433    pub hints: Vec<Expression>,
3434    /// TSQL: FOR SYSTEM_TIME temporal clause
3435    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3436    #[serde(default, skip_serializing_if = "Option::is_none")]
3437    pub system_time: Option<String>,
3438    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3439    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3440    pub partitions: Vec<Identifier>,
3441    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3442    /// When set, this is used instead of the name field
3443    #[serde(default, skip_serializing_if = "Option::is_none")]
3444    pub identifier_func: Option<Box<Expression>>,
3445    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3446    #[serde(default, skip_serializing_if = "Option::is_none")]
3447    pub changes: Option<Box<Changes>>,
3448    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3449    #[serde(default, skip_serializing_if = "Option::is_none")]
3450    pub version: Option<Box<Version>>,
3451    /// Source position span
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub span: Option<Span>,
3454}
3455
3456impl TableRef {
3457    pub fn new(name: impl Into<String>) -> Self {
3458        Self {
3459            name: Identifier::new(name),
3460            schema: None,
3461            catalog: None,
3462            alias: None,
3463            alias_explicit_as: false,
3464            column_aliases: Vec::new(),
3465            leading_comments: Vec::new(),
3466            trailing_comments: Vec::new(),
3467            when: None,
3468            only: false,
3469            final_: false,
3470            table_sample: None,
3471            hints: Vec::new(),
3472            system_time: None,
3473            partitions: Vec::new(),
3474            identifier_func: None,
3475            changes: None,
3476            version: None,
3477            span: None,
3478        }
3479    }
3480
3481    /// Create with a schema qualifier.
3482    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3483        let mut t = Self::new(name);
3484        t.schema = Some(Identifier::new(schema));
3485        t
3486    }
3487
3488    /// Create with catalog and schema qualifiers.
3489    pub fn new_with_catalog(
3490        name: impl Into<String>,
3491        schema: impl Into<String>,
3492        catalog: impl Into<String>,
3493    ) -> Self {
3494        let mut t = Self::new(name);
3495        t.schema = Some(Identifier::new(schema));
3496        t.catalog = Some(Identifier::new(catalog));
3497        t
3498    }
3499
3500    /// Create from an Identifier, preserving the quoted flag
3501    pub fn from_identifier(name: Identifier) -> Self {
3502        Self {
3503            name,
3504            schema: None,
3505            catalog: None,
3506            alias: None,
3507            alias_explicit_as: false,
3508            column_aliases: Vec::new(),
3509            leading_comments: Vec::new(),
3510            trailing_comments: Vec::new(),
3511            when: None,
3512            only: false,
3513            final_: false,
3514            table_sample: None,
3515            hints: Vec::new(),
3516            system_time: None,
3517            partitions: Vec::new(),
3518            identifier_func: None,
3519            changes: None,
3520            version: None,
3521            span: None,
3522        }
3523    }
3524
3525    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3526        self.alias = Some(Identifier::new(alias));
3527        self
3528    }
3529
3530    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3531        self.schema = Some(Identifier::new(schema));
3532        self
3533    }
3534}
3535
3536/// Represent a wildcard star expression (`*`, `table.*`).
3537///
3538/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3539/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3541#[cfg_attr(feature = "bindings", derive(TS))]
3542pub struct Star {
3543    /// Optional table qualifier (e.g. `t` in `t.*`).
3544    pub table: Option<Identifier>,
3545    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3546    pub except: Option<Vec<Identifier>>,
3547    /// REPLACE expressions (BigQuery, Snowflake)
3548    pub replace: Option<Vec<Alias>>,
3549    /// RENAME columns (Snowflake)
3550    pub rename: Option<Vec<(Identifier, Identifier)>>,
3551    /// Trailing comments that appeared after the star
3552    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3553    pub trailing_comments: Vec<String>,
3554    /// Source position span
3555    #[serde(default, skip_serializing_if = "Option::is_none")]
3556    pub span: Option<Span>,
3557}
3558
3559/// Represent a complete SELECT statement.
3560///
3561/// This is the most feature-rich AST node, covering the full surface area of
3562/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3563/// `Vec` are omitted from the generated SQL when absent.
3564///
3565/// # Key Fields
3566///
3567/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3568/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3569/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3570/// - `where_clause` -- the WHERE predicate.
3571/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3572/// - `having` -- HAVING predicate.
3573/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3574/// - `limit` / `offset` / `fetch` -- result set limiting.
3575/// - `with` -- Common Table Expressions (CTEs).
3576/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3577/// - `windows` -- named window definitions (WINDOW w AS ...).
3578///
3579/// Dialect-specific extensions are supported via fields like `prewhere`
3580/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3581/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3583#[cfg_attr(feature = "bindings", derive(TS))]
3584pub struct Select {
3585    /// The select-list: columns, expressions, aliases, and wildcards.
3586    pub expressions: Vec<Expression>,
3587    /// The FROM clause, containing one or more table sources.
3588    pub from: Option<From>,
3589    /// JOIN clauses applied after the FROM source.
3590    pub joins: Vec<Join>,
3591    pub lateral_views: Vec<LateralView>,
3592    /// ClickHouse PREWHERE clause
3593    #[serde(default, skip_serializing_if = "Option::is_none")]
3594    pub prewhere: Option<Expression>,
3595    pub where_clause: Option<Where>,
3596    pub group_by: Option<GroupBy>,
3597    pub having: Option<Having>,
3598    pub qualify: Option<Qualify>,
3599    pub order_by: Option<OrderBy>,
3600    pub distribute_by: Option<DistributeBy>,
3601    pub cluster_by: Option<ClusterBy>,
3602    pub sort_by: Option<SortBy>,
3603    pub limit: Option<Limit>,
3604    pub offset: Option<Offset>,
3605    /// ClickHouse LIMIT BY clause expressions
3606    #[serde(default, skip_serializing_if = "Option::is_none")]
3607    pub limit_by: Option<Vec<Expression>>,
3608    pub fetch: Option<Fetch>,
3609    pub distinct: bool,
3610    pub distinct_on: Option<Vec<Expression>>,
3611    pub top: Option<Top>,
3612    pub with: Option<With>,
3613    pub sample: Option<Sample>,
3614    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub settings: Option<Vec<Expression>>,
3617    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3618    #[serde(default, skip_serializing_if = "Option::is_none")]
3619    pub format: Option<Expression>,
3620    pub windows: Option<Vec<NamedWindow>>,
3621    pub hint: Option<Hint>,
3622    /// Oracle CONNECT BY clause for hierarchical queries
3623    pub connect: Option<Connect>,
3624    /// SELECT ... INTO table_name for creating tables
3625    pub into: Option<SelectInto>,
3626    /// FOR UPDATE/SHARE locking clauses
3627    #[serde(default)]
3628    pub locks: Vec<Lock>,
3629    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3630    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3631    pub for_xml: Vec<Expression>,
3632    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub for_json: Vec<Expression>,
3635    /// Leading comments before the statement
3636    #[serde(default)]
3637    pub leading_comments: Vec<String>,
3638    /// Comments that appear after SELECT keyword (before expressions)
3639    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3641    pub post_select_comments: Vec<String>,
3642    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3643    #[serde(default, skip_serializing_if = "Option::is_none")]
3644    pub kind: Option<String>,
3645    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3646    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3647    pub operation_modifiers: Vec<String>,
3648    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3649    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3650    pub qualify_after_window: bool,
3651    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub option: Option<String>,
3654    /// Redshift-style EXCLUDE clause at the end of the projection list
3655    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3656    #[serde(default, skip_serializing_if = "Option::is_none")]
3657    pub exclude: Option<Vec<Expression>>,
3658}
3659
3660impl Select {
3661    pub fn new() -> Self {
3662        Self {
3663            expressions: Vec::new(),
3664            from: None,
3665            joins: Vec::new(),
3666            lateral_views: Vec::new(),
3667            prewhere: None,
3668            where_clause: None,
3669            group_by: None,
3670            having: None,
3671            qualify: None,
3672            order_by: None,
3673            distribute_by: None,
3674            cluster_by: None,
3675            sort_by: None,
3676            limit: None,
3677            offset: None,
3678            limit_by: None,
3679            fetch: None,
3680            distinct: false,
3681            distinct_on: None,
3682            top: None,
3683            with: None,
3684            sample: None,
3685            settings: None,
3686            format: None,
3687            windows: None,
3688            hint: None,
3689            connect: None,
3690            into: None,
3691            locks: Vec::new(),
3692            for_xml: Vec::new(),
3693            for_json: Vec::new(),
3694            leading_comments: Vec::new(),
3695            post_select_comments: Vec::new(),
3696            kind: None,
3697            operation_modifiers: Vec::new(),
3698            qualify_after_window: false,
3699            option: None,
3700            exclude: None,
3701        }
3702    }
3703
3704    /// Add a column to select
3705    pub fn column(mut self, expr: Expression) -> Self {
3706        self.expressions.push(expr);
3707        self
3708    }
3709
3710    /// Set the FROM clause
3711    pub fn from(mut self, table: Expression) -> Self {
3712        self.from = Some(From {
3713            expressions: vec![table],
3714        });
3715        self
3716    }
3717
3718    /// Add a WHERE clause
3719    pub fn where_(mut self, condition: Expression) -> Self {
3720        self.where_clause = Some(Where { this: condition });
3721        self
3722    }
3723
3724    /// Set DISTINCT
3725    pub fn distinct(mut self) -> Self {
3726        self.distinct = true;
3727        self
3728    }
3729
3730    /// Add a JOIN
3731    pub fn join(mut self, join: Join) -> Self {
3732        self.joins.push(join);
3733        self
3734    }
3735
3736    /// Set ORDER BY
3737    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3738        self.order_by = Some(OrderBy {
3739            expressions,
3740            siblings: false,
3741            comments: Vec::new(),
3742        });
3743        self
3744    }
3745
3746    /// Set LIMIT
3747    pub fn limit(mut self, n: Expression) -> Self {
3748        self.limit = Some(Limit {
3749            this: n,
3750            percent: false,
3751            comments: Vec::new(),
3752        });
3753        self
3754    }
3755
3756    /// Set OFFSET
3757    pub fn offset(mut self, n: Expression) -> Self {
3758        self.offset = Some(Offset {
3759            this: n,
3760            rows: None,
3761        });
3762        self
3763    }
3764}
3765
3766impl Default for Select {
3767    fn default() -> Self {
3768        Self::new()
3769    }
3770}
3771
3772/// Represent a UNION set operation between two query expressions.
3773///
3774/// When `all` is true, duplicate rows are preserved (UNION ALL).
3775/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3776/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3778#[cfg_attr(feature = "bindings", derive(TS))]
3779pub struct Union {
3780    /// The left-hand query operand.
3781    pub left: Expression,
3782    /// The right-hand query operand.
3783    pub right: Expression,
3784    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3785    pub all: bool,
3786    /// Whether DISTINCT was explicitly specified
3787    #[serde(default)]
3788    pub distinct: bool,
3789    /// Optional WITH clause
3790    pub with: Option<With>,
3791    /// ORDER BY applied to entire UNION result
3792    pub order_by: Option<OrderBy>,
3793    /// LIMIT applied to entire UNION result
3794    pub limit: Option<Box<Expression>>,
3795    /// OFFSET applied to entire UNION result
3796    pub offset: Option<Box<Expression>>,
3797    /// DISTRIBUTE BY clause (Hive/Spark)
3798    #[serde(default, skip_serializing_if = "Option::is_none")]
3799    pub distribute_by: Option<DistributeBy>,
3800    /// SORT BY clause (Hive/Spark)
3801    #[serde(default, skip_serializing_if = "Option::is_none")]
3802    pub sort_by: Option<SortBy>,
3803    /// CLUSTER BY clause (Hive/Spark)
3804    #[serde(default, skip_serializing_if = "Option::is_none")]
3805    pub cluster_by: Option<ClusterBy>,
3806    /// DuckDB BY NAME modifier
3807    #[serde(default)]
3808    pub by_name: bool,
3809    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3810    #[serde(default, skip_serializing_if = "Option::is_none")]
3811    pub side: Option<String>,
3812    /// BigQuery: Set operation kind (INNER)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub kind: Option<String>,
3815    /// BigQuery: CORRESPONDING modifier
3816    #[serde(default)]
3817    pub corresponding: bool,
3818    /// BigQuery: STRICT modifier (before CORRESPONDING)
3819    #[serde(default)]
3820    pub strict: bool,
3821    /// BigQuery: BY (columns) after CORRESPONDING
3822    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3823    pub on_columns: Vec<Expression>,
3824}
3825
3826/// Iteratively flatten the left-recursive chain to prevent stack overflow
3827/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3828impl Drop for Union {
3829    fn drop(&mut self) {
3830        loop {
3831            if let Expression::Union(ref mut inner) = self.left {
3832                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3833                let old_left = std::mem::replace(&mut self.left, next_left);
3834                drop(old_left);
3835            } else {
3836                break;
3837            }
3838        }
3839    }
3840}
3841
3842/// Represent an INTERSECT set operation between two query expressions.
3843///
3844/// Returns only rows that appear in both operands. When `all` is true,
3845/// duplicates are preserved according to their multiplicity.
3846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3847#[cfg_attr(feature = "bindings", derive(TS))]
3848pub struct Intersect {
3849    /// The left-hand query operand.
3850    pub left: Expression,
3851    /// The right-hand query operand.
3852    pub right: Expression,
3853    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3854    pub all: bool,
3855    /// Whether DISTINCT was explicitly specified
3856    #[serde(default)]
3857    pub distinct: bool,
3858    /// Optional WITH clause
3859    pub with: Option<With>,
3860    /// ORDER BY applied to entire INTERSECT result
3861    pub order_by: Option<OrderBy>,
3862    /// LIMIT applied to entire INTERSECT result
3863    pub limit: Option<Box<Expression>>,
3864    /// OFFSET applied to entire INTERSECT result
3865    pub offset: Option<Box<Expression>>,
3866    /// DISTRIBUTE BY clause (Hive/Spark)
3867    #[serde(default, skip_serializing_if = "Option::is_none")]
3868    pub distribute_by: Option<DistributeBy>,
3869    /// SORT BY clause (Hive/Spark)
3870    #[serde(default, skip_serializing_if = "Option::is_none")]
3871    pub sort_by: Option<SortBy>,
3872    /// CLUSTER BY clause (Hive/Spark)
3873    #[serde(default, skip_serializing_if = "Option::is_none")]
3874    pub cluster_by: Option<ClusterBy>,
3875    /// DuckDB BY NAME modifier
3876    #[serde(default)]
3877    pub by_name: bool,
3878    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3879    #[serde(default, skip_serializing_if = "Option::is_none")]
3880    pub side: Option<String>,
3881    /// BigQuery: Set operation kind (INNER)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub kind: Option<String>,
3884    /// BigQuery: CORRESPONDING modifier
3885    #[serde(default)]
3886    pub corresponding: bool,
3887    /// BigQuery: STRICT modifier (before CORRESPONDING)
3888    #[serde(default)]
3889    pub strict: bool,
3890    /// BigQuery: BY (columns) after CORRESPONDING
3891    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3892    pub on_columns: Vec<Expression>,
3893}
3894
3895impl Drop for Intersect {
3896    fn drop(&mut self) {
3897        loop {
3898            if let Expression::Intersect(ref mut inner) = self.left {
3899                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3900                let old_left = std::mem::replace(&mut self.left, next_left);
3901                drop(old_left);
3902            } else {
3903                break;
3904            }
3905        }
3906    }
3907}
3908
3909/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3910///
3911/// Returns rows from the left operand that do not appear in the right operand.
3912/// When `all` is true, duplicates are subtracted according to their multiplicity.
3913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3914#[cfg_attr(feature = "bindings", derive(TS))]
3915pub struct Except {
3916    /// The left-hand query operand.
3917    pub left: Expression,
3918    /// The right-hand query operand (rows to subtract).
3919    pub right: Expression,
3920    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3921    pub all: bool,
3922    /// Whether DISTINCT was explicitly specified
3923    #[serde(default)]
3924    pub distinct: bool,
3925    /// Optional WITH clause
3926    pub with: Option<With>,
3927    /// ORDER BY applied to entire EXCEPT result
3928    pub order_by: Option<OrderBy>,
3929    /// LIMIT applied to entire EXCEPT result
3930    pub limit: Option<Box<Expression>>,
3931    /// OFFSET applied to entire EXCEPT result
3932    pub offset: Option<Box<Expression>>,
3933    /// DISTRIBUTE BY clause (Hive/Spark)
3934    #[serde(default, skip_serializing_if = "Option::is_none")]
3935    pub distribute_by: Option<DistributeBy>,
3936    /// SORT BY clause (Hive/Spark)
3937    #[serde(default, skip_serializing_if = "Option::is_none")]
3938    pub sort_by: Option<SortBy>,
3939    /// CLUSTER BY clause (Hive/Spark)
3940    #[serde(default, skip_serializing_if = "Option::is_none")]
3941    pub cluster_by: Option<ClusterBy>,
3942    /// DuckDB BY NAME modifier
3943    #[serde(default)]
3944    pub by_name: bool,
3945    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3946    #[serde(default, skip_serializing_if = "Option::is_none")]
3947    pub side: Option<String>,
3948    /// BigQuery: Set operation kind (INNER)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub kind: Option<String>,
3951    /// BigQuery: CORRESPONDING modifier
3952    #[serde(default)]
3953    pub corresponding: bool,
3954    /// BigQuery: STRICT modifier (before CORRESPONDING)
3955    #[serde(default)]
3956    pub strict: bool,
3957    /// BigQuery: BY (columns) after CORRESPONDING
3958    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3959    pub on_columns: Vec<Expression>,
3960}
3961
3962impl Drop for Except {
3963    fn drop(&mut self) {
3964        loop {
3965            if let Expression::Except(ref mut inner) = self.left {
3966                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3967                let old_left = std::mem::replace(&mut self.left, next_left);
3968                drop(old_left);
3969            } else {
3970                break;
3971            }
3972        }
3973    }
3974}
3975
3976/// INTO clause for SELECT INTO statements
3977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3978#[cfg_attr(feature = "bindings", derive(TS))]
3979pub struct SelectInto {
3980    /// Target table or variable (used when single target)
3981    pub this: Expression,
3982    /// Whether TEMPORARY keyword was used
3983    #[serde(default)]
3984    pub temporary: bool,
3985    /// Whether UNLOGGED keyword was used (PostgreSQL)
3986    #[serde(default)]
3987    pub unlogged: bool,
3988    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3989    #[serde(default)]
3990    pub bulk_collect: bool,
3991    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3992    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3993    pub expressions: Vec<Expression>,
3994}
3995
3996/// Represent a parenthesized subquery expression.
3997///
3998/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3999/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4000/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4001/// modifiers are rendered inside or outside the parentheses.
4002///
4003/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4004/// scalar subqueries in select-lists, and derived tables.
4005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4006#[cfg_attr(feature = "bindings", derive(TS))]
4007pub struct Subquery {
4008    /// The inner query expression.
4009    pub this: Expression,
4010    /// Optional alias for the derived table.
4011    pub alias: Option<Identifier>,
4012    /// Optional column aliases: AS t(c1, c2)
4013    pub column_aliases: Vec<Identifier>,
4014    /// ORDER BY clause (for parenthesized queries)
4015    pub order_by: Option<OrderBy>,
4016    /// LIMIT clause
4017    pub limit: Option<Limit>,
4018    /// OFFSET clause
4019    pub offset: Option<Offset>,
4020    /// DISTRIBUTE BY clause (Hive/Spark)
4021    #[serde(default, skip_serializing_if = "Option::is_none")]
4022    pub distribute_by: Option<DistributeBy>,
4023    /// SORT BY clause (Hive/Spark)
4024    #[serde(default, skip_serializing_if = "Option::is_none")]
4025    pub sort_by: Option<SortBy>,
4026    /// CLUSTER BY clause (Hive/Spark)
4027    #[serde(default, skip_serializing_if = "Option::is_none")]
4028    pub cluster_by: Option<ClusterBy>,
4029    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4030    #[serde(default)]
4031    pub lateral: bool,
4032    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4033    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4034    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4035    #[serde(default)]
4036    pub modifiers_inside: bool,
4037    /// Trailing comments after the closing paren
4038    #[serde(default)]
4039    pub trailing_comments: Vec<String>,
4040    /// Inferred data type from type annotation
4041    #[serde(default, skip_serializing_if = "Option::is_none")]
4042    pub inferred_type: Option<DataType>,
4043}
4044
4045/// Pipe operator expression: query |> transform
4046///
4047/// Used in DataFusion and BigQuery pipe syntax:
4048///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4050#[cfg_attr(feature = "bindings", derive(TS))]
4051pub struct PipeOperator {
4052    /// The input query/expression (left side of |>)
4053    pub this: Expression,
4054    /// The piped operation (right side of |>)
4055    pub expression: Expression,
4056}
4057
4058/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4060#[cfg_attr(feature = "bindings", derive(TS))]
4061pub struct Values {
4062    /// The rows of values
4063    pub expressions: Vec<Tuple>,
4064    /// Optional alias for the table
4065    pub alias: Option<Identifier>,
4066    /// Optional column aliases: AS t(c1, c2)
4067    pub column_aliases: Vec<Identifier>,
4068}
4069
4070/// PIVOT operation - supports both standard and DuckDB simplified syntax
4071///
4072/// Standard syntax (in FROM clause):
4073///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4074///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4075///
4076/// DuckDB simplified syntax (statement-level):
4077///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4078///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4080#[cfg_attr(feature = "bindings", derive(TS))]
4081pub struct Pivot {
4082    /// Source table/expression
4083    pub this: Expression,
4084    /// For standard PIVOT: the aggregation function(s) (first is primary)
4085    /// For DuckDB simplified: unused (use `using` instead)
4086    #[serde(default)]
4087    pub expressions: Vec<Expression>,
4088    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4089    #[serde(default)]
4090    pub fields: Vec<Expression>,
4091    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4092    #[serde(default)]
4093    pub using: Vec<Expression>,
4094    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4095    #[serde(default)]
4096    pub group: Option<Box<Expression>>,
4097    /// Whether this is an UNPIVOT (vs PIVOT)
4098    #[serde(default)]
4099    pub unpivot: bool,
4100    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4101    #[serde(default)]
4102    pub into: Option<Box<Expression>>,
4103    /// Optional alias
4104    #[serde(default)]
4105    pub alias: Option<Identifier>,
4106    /// Include/exclude nulls (for UNPIVOT)
4107    #[serde(default)]
4108    pub include_nulls: Option<bool>,
4109    /// Default on null value (Snowflake)
4110    #[serde(default)]
4111    pub default_on_null: Option<Box<Expression>>,
4112    /// WITH clause (CTEs)
4113    #[serde(default, skip_serializing_if = "Option::is_none")]
4114    pub with: Option<With>,
4115}
4116
4117/// UNPIVOT operation
4118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4119#[cfg_attr(feature = "bindings", derive(TS))]
4120pub struct Unpivot {
4121    pub this: Expression,
4122    pub value_column: Identifier,
4123    pub name_column: Identifier,
4124    pub columns: Vec<Expression>,
4125    pub alias: Option<Identifier>,
4126    /// Whether the value_column was parenthesized in the original SQL
4127    #[serde(default)]
4128    pub value_column_parenthesized: bool,
4129    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4130    #[serde(default)]
4131    pub include_nulls: Option<bool>,
4132    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4133    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4134    pub extra_value_columns: Vec<Identifier>,
4135}
4136
4137/// PIVOT alias for aliasing pivot expressions
4138/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4140#[cfg_attr(feature = "bindings", derive(TS))]
4141pub struct PivotAlias {
4142    pub this: Expression,
4143    pub alias: Expression,
4144}
4145
4146/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4148#[cfg_attr(feature = "bindings", derive(TS))]
4149pub struct PreWhere {
4150    pub this: Expression,
4151}
4152
4153/// STREAM definition (Snowflake) - for change data capture
4154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4155#[cfg_attr(feature = "bindings", derive(TS))]
4156pub struct Stream {
4157    pub this: Expression,
4158    #[serde(skip_serializing_if = "Option::is_none")]
4159    pub on: Option<Expression>,
4160    #[serde(skip_serializing_if = "Option::is_none")]
4161    pub show_initial_rows: Option<bool>,
4162}
4163
4164/// USING DATA clause for data import statements
4165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub struct UsingData {
4168    pub this: Expression,
4169}
4170
4171/// XML Namespace declaration
4172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4173#[cfg_attr(feature = "bindings", derive(TS))]
4174pub struct XmlNamespace {
4175    pub this: Expression,
4176    #[serde(skip_serializing_if = "Option::is_none")]
4177    pub alias: Option<Identifier>,
4178}
4179
4180/// ROW FORMAT clause for Hive/Spark
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct RowFormat {
4184    pub delimited: bool,
4185    pub fields_terminated_by: Option<String>,
4186    pub collection_items_terminated_by: Option<String>,
4187    pub map_keys_terminated_by: Option<String>,
4188    pub lines_terminated_by: Option<String>,
4189    pub null_defined_as: Option<String>,
4190}
4191
4192/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub struct DirectoryInsert {
4196    pub local: bool,
4197    pub path: String,
4198    pub row_format: Option<RowFormat>,
4199    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4200    #[serde(default)]
4201    pub stored_as: Option<String>,
4202}
4203
4204/// INSERT statement
4205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4206#[cfg_attr(feature = "bindings", derive(TS))]
4207pub struct Insert {
4208    pub table: TableRef,
4209    pub columns: Vec<Identifier>,
4210    pub values: Vec<Vec<Expression>>,
4211    pub query: Option<Expression>,
4212    /// INSERT OVERWRITE for Hive/Spark
4213    pub overwrite: bool,
4214    /// PARTITION clause for Hive/Spark
4215    pub partition: Vec<(Identifier, Option<Expression>)>,
4216    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4217    #[serde(default)]
4218    pub directory: Option<DirectoryInsert>,
4219    /// RETURNING clause (PostgreSQL, SQLite)
4220    #[serde(default)]
4221    pub returning: Vec<Expression>,
4222    /// OUTPUT clause (TSQL)
4223    #[serde(default)]
4224    pub output: Option<OutputClause>,
4225    /// ON CONFLICT clause (PostgreSQL, SQLite)
4226    #[serde(default)]
4227    pub on_conflict: Option<Box<Expression>>,
4228    /// Leading comments before the statement
4229    #[serde(default)]
4230    pub leading_comments: Vec<String>,
4231    /// IF EXISTS clause (Hive)
4232    #[serde(default)]
4233    pub if_exists: bool,
4234    /// WITH clause (CTEs)
4235    #[serde(default)]
4236    pub with: Option<With>,
4237    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4238    #[serde(default)]
4239    pub ignore: bool,
4240    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4241    #[serde(default)]
4242    pub source_alias: Option<Identifier>,
4243    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4244    #[serde(default)]
4245    pub alias: Option<Identifier>,
4246    /// Whether the alias uses explicit AS keyword
4247    #[serde(default)]
4248    pub alias_explicit_as: bool,
4249    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4250    #[serde(default)]
4251    pub default_values: bool,
4252    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4253    #[serde(default)]
4254    pub by_name: bool,
4255    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4256    #[serde(default, skip_serializing_if = "Option::is_none")]
4257    pub conflict_action: Option<String>,
4258    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4259    #[serde(default)]
4260    pub is_replace: bool,
4261    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4262    #[serde(default, skip_serializing_if = "Option::is_none")]
4263    pub hint: Option<Hint>,
4264    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4265    #[serde(default)]
4266    pub replace_where: Option<Box<Expression>>,
4267    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4268    #[serde(default)]
4269    pub source: Option<Box<Expression>>,
4270    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4271    #[serde(default, skip_serializing_if = "Option::is_none")]
4272    pub function_target: Option<Box<Expression>>,
4273    /// ClickHouse: PARTITION BY expr
4274    #[serde(default, skip_serializing_if = "Option::is_none")]
4275    pub partition_by: Option<Box<Expression>>,
4276    /// ClickHouse: SETTINGS key = val, ...
4277    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4278    pub settings: Vec<Expression>,
4279}
4280
4281/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4283#[cfg_attr(feature = "bindings", derive(TS))]
4284pub struct OutputClause {
4285    /// Columns/expressions to output
4286    pub columns: Vec<Expression>,
4287    /// Optional INTO target table or table variable
4288    #[serde(default)]
4289    pub into_table: Option<Expression>,
4290}
4291
4292/// UPDATE statement
4293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4294#[cfg_attr(feature = "bindings", derive(TS))]
4295pub struct Update {
4296    pub table: TableRef,
4297    #[serde(default)]
4298    pub hint: Option<Hint>,
4299    /// Additional tables for multi-table UPDATE (MySQL syntax)
4300    #[serde(default)]
4301    pub extra_tables: Vec<TableRef>,
4302    /// JOINs attached to the table list (MySQL multi-table syntax)
4303    #[serde(default)]
4304    pub table_joins: Vec<Join>,
4305    pub set: Vec<(Identifier, Expression)>,
4306    pub from_clause: Option<From>,
4307    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4308    #[serde(default)]
4309    pub from_joins: Vec<Join>,
4310    pub where_clause: Option<Where>,
4311    /// RETURNING clause (PostgreSQL, SQLite)
4312    #[serde(default)]
4313    pub returning: Vec<Expression>,
4314    /// OUTPUT clause (TSQL)
4315    #[serde(default)]
4316    pub output: Option<OutputClause>,
4317    /// WITH clause (CTEs)
4318    #[serde(default)]
4319    pub with: Option<With>,
4320    /// Leading comments before the statement
4321    #[serde(default)]
4322    pub leading_comments: Vec<String>,
4323    /// LIMIT clause (MySQL)
4324    #[serde(default)]
4325    pub limit: Option<Expression>,
4326    /// ORDER BY clause (MySQL)
4327    #[serde(default)]
4328    pub order_by: Option<OrderBy>,
4329    /// Whether FROM clause appears before SET (Snowflake syntax)
4330    #[serde(default)]
4331    pub from_before_set: bool,
4332}
4333
4334/// DELETE statement
4335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4336#[cfg_attr(feature = "bindings", derive(TS))]
4337pub struct Delete {
4338    pub table: TableRef,
4339    #[serde(default)]
4340    pub hint: Option<Hint>,
4341    /// ClickHouse: ON CLUSTER clause for distributed DDL
4342    #[serde(default, skip_serializing_if = "Option::is_none")]
4343    pub on_cluster: Option<OnCluster>,
4344    /// Optional alias for the table
4345    pub alias: Option<Identifier>,
4346    /// Whether the alias was declared with explicit AS keyword
4347    #[serde(default)]
4348    pub alias_explicit_as: bool,
4349    /// PostgreSQL/DuckDB USING clause - additional tables to join
4350    pub using: Vec<TableRef>,
4351    pub where_clause: Option<Where>,
4352    /// OUTPUT clause (TSQL)
4353    #[serde(default)]
4354    pub output: Option<OutputClause>,
4355    /// Leading comments before the statement
4356    #[serde(default)]
4357    pub leading_comments: Vec<String>,
4358    /// WITH clause (CTEs)
4359    #[serde(default)]
4360    pub with: Option<With>,
4361    /// LIMIT clause (MySQL)
4362    #[serde(default)]
4363    pub limit: Option<Expression>,
4364    /// ORDER BY clause (MySQL)
4365    #[serde(default)]
4366    pub order_by: Option<OrderBy>,
4367    /// RETURNING clause (PostgreSQL)
4368    #[serde(default)]
4369    pub returning: Vec<Expression>,
4370    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4371    /// These are the target tables to delete from
4372    #[serde(default)]
4373    pub tables: Vec<TableRef>,
4374    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4375    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4376    #[serde(default)]
4377    pub tables_from_using: bool,
4378    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4379    #[serde(default)]
4380    pub joins: Vec<Join>,
4381    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4382    #[serde(default)]
4383    pub force_index: Option<String>,
4384    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4385    #[serde(default)]
4386    pub no_from: bool,
4387}
4388
4389/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4391#[cfg_attr(feature = "bindings", derive(TS))]
4392pub struct CopyStmt {
4393    /// Target table or query
4394    pub this: Expression,
4395    /// True for FROM (loading into table), false for TO (exporting)
4396    pub kind: bool,
4397    /// Source/destination file(s) or stage
4398    pub files: Vec<Expression>,
4399    /// Copy parameters
4400    #[serde(default)]
4401    pub params: Vec<CopyParameter>,
4402    /// Credentials for external access
4403    #[serde(default)]
4404    pub credentials: Option<Box<Credentials>>,
4405    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4406    #[serde(default)]
4407    pub is_into: bool,
4408    /// Whether parameters are wrapped in WITH (...) syntax
4409    #[serde(default)]
4410    pub with_wrapped: bool,
4411}
4412
4413/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4415#[cfg_attr(feature = "bindings", derive(TS))]
4416pub struct CopyParameter {
4417    pub name: String,
4418    pub value: Option<Expression>,
4419    pub values: Vec<Expression>,
4420    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4421    #[serde(default)]
4422    pub eq: bool,
4423}
4424
4425/// Credentials for external access (S3, Azure, etc.)
4426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4427#[cfg_attr(feature = "bindings", derive(TS))]
4428pub struct Credentials {
4429    pub credentials: Vec<(String, String)>,
4430    pub encryption: Option<String>,
4431    pub storage: Option<String>,
4432}
4433
4434/// PUT statement (Snowflake)
4435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4436#[cfg_attr(feature = "bindings", derive(TS))]
4437pub struct PutStmt {
4438    /// Source file path
4439    pub source: String,
4440    /// Whether source was quoted in the original SQL
4441    #[serde(default)]
4442    pub source_quoted: bool,
4443    /// Target stage
4444    pub target: Expression,
4445    /// PUT parameters
4446    #[serde(default)]
4447    pub params: Vec<CopyParameter>,
4448}
4449
4450/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4452#[cfg_attr(feature = "bindings", derive(TS))]
4453pub struct StageReference {
4454    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4455    pub name: String,
4456    /// Optional path within the stage (e.g., "/path/to/file.csv")
4457    #[serde(default)]
4458    pub path: Option<String>,
4459    /// Optional FILE_FORMAT parameter
4460    #[serde(default)]
4461    pub file_format: Option<Expression>,
4462    /// Optional PATTERN parameter
4463    #[serde(default)]
4464    pub pattern: Option<String>,
4465    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4466    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4467    pub quoted: bool,
4468}
4469
4470/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4472#[cfg_attr(feature = "bindings", derive(TS))]
4473pub struct HistoricalData {
4474    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4475    pub this: Box<Expression>,
4476    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4477    pub kind: String,
4478    /// The expression value (e.g., the statement ID or timestamp)
4479    pub expression: Box<Expression>,
4480}
4481
4482/// Represent an aliased expression (`expr AS name`).
4483///
4484/// Used for column aliases in select-lists, table aliases on subqueries,
4485/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4487#[cfg_attr(feature = "bindings", derive(TS))]
4488pub struct Alias {
4489    /// The expression being aliased.
4490    pub this: Expression,
4491    /// The alias name (required for simple aliases, optional when only column aliases provided)
4492    pub alias: Identifier,
4493    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4494    #[serde(default)]
4495    pub column_aliases: Vec<Identifier>,
4496    /// Comments that appeared between the expression and AS keyword
4497    #[serde(default)]
4498    pub pre_alias_comments: Vec<String>,
4499    /// Trailing comments that appeared after the alias
4500    #[serde(default)]
4501    pub trailing_comments: Vec<String>,
4502    /// Inferred data type from type annotation
4503    #[serde(default, skip_serializing_if = "Option::is_none")]
4504    pub inferred_type: Option<DataType>,
4505}
4506
4507impl Alias {
4508    /// Create a simple alias
4509    pub fn new(this: Expression, alias: Identifier) -> Self {
4510        Self {
4511            this,
4512            alias,
4513            column_aliases: Vec::new(),
4514            pre_alias_comments: Vec::new(),
4515            trailing_comments: Vec::new(),
4516            inferred_type: None,
4517        }
4518    }
4519
4520    /// Create an alias with column aliases only (no table alias name)
4521    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4522        Self {
4523            this,
4524            alias: Identifier::empty(),
4525            column_aliases,
4526            pre_alias_comments: Vec::new(),
4527            trailing_comments: Vec::new(),
4528            inferred_type: None,
4529        }
4530    }
4531}
4532
4533/// Represent a type cast expression.
4534///
4535/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4536/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4537/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4538/// CONVERSION ERROR (Oracle) clauses.
4539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4540#[cfg_attr(feature = "bindings", derive(TS))]
4541pub struct Cast {
4542    /// The expression being cast.
4543    pub this: Expression,
4544    /// The target data type.
4545    pub to: DataType,
4546    #[serde(default)]
4547    pub trailing_comments: Vec<String>,
4548    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4549    #[serde(default)]
4550    pub double_colon_syntax: bool,
4551    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4552    #[serde(skip_serializing_if = "Option::is_none", default)]
4553    pub format: Option<Box<Expression>>,
4554    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4555    #[serde(skip_serializing_if = "Option::is_none", default)]
4556    pub default: Option<Box<Expression>>,
4557    /// Inferred data type from type annotation
4558    #[serde(default, skip_serializing_if = "Option::is_none")]
4559    pub inferred_type: Option<DataType>,
4560}
4561
4562///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4564#[cfg_attr(feature = "bindings", derive(TS))]
4565pub struct CollationExpr {
4566    pub this: Expression,
4567    pub collation: String,
4568    /// True if the collation was single-quoted in the original SQL (string literal)
4569    #[serde(default)]
4570    pub quoted: bool,
4571    /// True if the collation was double-quoted in the original SQL (identifier)
4572    #[serde(default)]
4573    pub double_quoted: bool,
4574}
4575
4576/// Represent a CASE expression (both simple and searched forms).
4577///
4578/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4579/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4580/// Each entry in `whens` is a `(condition, result)` pair.
4581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4582#[cfg_attr(feature = "bindings", derive(TS))]
4583pub struct Case {
4584    /// The operand for simple CASE, or `None` for searched CASE.
4585    pub operand: Option<Expression>,
4586    /// Pairs of (WHEN condition, THEN result).
4587    pub whens: Vec<(Expression, Expression)>,
4588    /// Optional ELSE result.
4589    pub else_: Option<Expression>,
4590    /// Comments from the CASE keyword (emitted after END)
4591    #[serde(default)]
4592    #[serde(skip_serializing_if = "Vec::is_empty")]
4593    pub comments: Vec<String>,
4594    /// Inferred data type from type annotation
4595    #[serde(default, skip_serializing_if = "Option::is_none")]
4596    pub inferred_type: Option<DataType>,
4597}
4598
4599/// Represent a binary operation (two operands separated by an operator).
4600///
4601/// This is the shared payload struct for all binary operator variants in the
4602/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4603/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4604/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4605/// preservation of inline comments around operators.
4606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4607#[cfg_attr(feature = "bindings", derive(TS))]
4608pub struct BinaryOp {
4609    pub left: Expression,
4610    pub right: Expression,
4611    /// Comments after the left operand (before the operator)
4612    #[serde(default)]
4613    pub left_comments: Vec<String>,
4614    /// Comments after the operator (before the right operand)
4615    #[serde(default)]
4616    pub operator_comments: Vec<String>,
4617    /// Comments after the right operand
4618    #[serde(default)]
4619    pub trailing_comments: Vec<String>,
4620    /// Inferred data type from type annotation
4621    #[serde(default, skip_serializing_if = "Option::is_none")]
4622    pub inferred_type: Option<DataType>,
4623}
4624
4625impl BinaryOp {
4626    pub fn new(left: Expression, right: Expression) -> Self {
4627        Self {
4628            left,
4629            right,
4630            left_comments: Vec::new(),
4631            operator_comments: Vec::new(),
4632            trailing_comments: Vec::new(),
4633            inferred_type: None,
4634        }
4635    }
4636}
4637
4638/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4640#[cfg_attr(feature = "bindings", derive(TS))]
4641pub struct LikeOp {
4642    pub left: Expression,
4643    pub right: Expression,
4644    /// ESCAPE character/expression
4645    #[serde(default)]
4646    pub escape: Option<Expression>,
4647    /// Quantifier: ANY, ALL, or SOME
4648    #[serde(default)]
4649    pub quantifier: Option<String>,
4650    /// Inferred data type from type annotation
4651    #[serde(default, skip_serializing_if = "Option::is_none")]
4652    pub inferred_type: Option<DataType>,
4653}
4654
4655impl LikeOp {
4656    pub fn new(left: Expression, right: Expression) -> Self {
4657        Self {
4658            left,
4659            right,
4660            escape: None,
4661            quantifier: None,
4662            inferred_type: None,
4663        }
4664    }
4665
4666    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4667        Self {
4668            left,
4669            right,
4670            escape: Some(escape),
4671            quantifier: None,
4672            inferred_type: None,
4673        }
4674    }
4675}
4676
4677/// Represent a unary operation (single operand with a prefix operator).
4678///
4679/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4681#[cfg_attr(feature = "bindings", derive(TS))]
4682pub struct UnaryOp {
4683    /// The operand expression.
4684    pub this: Expression,
4685    /// Inferred data type from type annotation
4686    #[serde(default, skip_serializing_if = "Option::is_none")]
4687    pub inferred_type: Option<DataType>,
4688}
4689
4690impl UnaryOp {
4691    pub fn new(this: Expression) -> Self {
4692        Self {
4693            this,
4694            inferred_type: None,
4695        }
4696    }
4697}
4698
4699/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4700///
4701/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4702/// but not both. When `not` is true, the predicate is `NOT IN`.
4703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4704#[cfg_attr(feature = "bindings", derive(TS))]
4705pub struct In {
4706    /// The expression being tested.
4707    pub this: Expression,
4708    /// The value list (mutually exclusive with `query`).
4709    pub expressions: Vec<Expression>,
4710    /// A subquery (mutually exclusive with `expressions`).
4711    pub query: Option<Expression>,
4712    /// Whether this is NOT IN.
4713    pub not: bool,
4714    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4715    pub global: bool,
4716    /// BigQuery: IN UNNEST(expr)
4717    #[serde(default, skip_serializing_if = "Option::is_none")]
4718    pub unnest: Option<Box<Expression>>,
4719    /// Whether the right side is a bare field reference (no parentheses).
4720    /// Matches Python sqlglot's `field` attribute on `In` expression.
4721    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4722    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4723    pub is_field: bool,
4724}
4725
4726/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4728#[cfg_attr(feature = "bindings", derive(TS))]
4729pub struct Between {
4730    /// The expression being tested.
4731    pub this: Expression,
4732    /// The lower bound.
4733    pub low: Expression,
4734    /// The upper bound.
4735    pub high: Expression,
4736    /// Whether this is NOT BETWEEN.
4737    pub not: bool,
4738    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4739    #[serde(default)]
4740    pub symmetric: Option<bool>,
4741}
4742
4743/// IS NULL predicate
4744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4745#[cfg_attr(feature = "bindings", derive(TS))]
4746pub struct IsNull {
4747    pub this: Expression,
4748    pub not: bool,
4749    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4750    #[serde(default)]
4751    pub postfix_form: bool,
4752}
4753
4754/// IS TRUE / IS FALSE predicate
4755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4756#[cfg_attr(feature = "bindings", derive(TS))]
4757pub struct IsTrueFalse {
4758    pub this: Expression,
4759    pub not: bool,
4760}
4761
4762/// IS JSON predicate (SQL standard)
4763/// Checks if a value is valid JSON
4764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4765#[cfg_attr(feature = "bindings", derive(TS))]
4766pub struct IsJson {
4767    pub this: Expression,
4768    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4769    pub json_type: Option<String>,
4770    /// Key uniqueness constraint
4771    pub unique_keys: Option<JsonUniqueKeys>,
4772    /// Whether IS NOT JSON
4773    pub negated: bool,
4774}
4775
4776/// JSON unique keys constraint variants
4777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4778#[cfg_attr(feature = "bindings", derive(TS))]
4779pub enum JsonUniqueKeys {
4780    /// WITH UNIQUE KEYS
4781    With,
4782    /// WITHOUT UNIQUE KEYS
4783    Without,
4784    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4785    Shorthand,
4786}
4787
4788/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4790#[cfg_attr(feature = "bindings", derive(TS))]
4791pub struct Exists {
4792    /// The subquery expression.
4793    pub this: Expression,
4794    /// Whether this is NOT EXISTS.
4795    pub not: bool,
4796}
4797
4798/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4799///
4800/// This is the generic function node. Well-known aggregates, window functions,
4801/// and built-in functions each have their own dedicated `Expression` variants
4802/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4803/// not recognize as built-ins are represented with this struct.
4804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4805#[cfg_attr(feature = "bindings", derive(TS))]
4806pub struct Function {
4807    /// The function name, as originally written (may be schema-qualified).
4808    pub name: String,
4809    /// Positional arguments to the function.
4810    pub args: Vec<Expression>,
4811    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4812    pub distinct: bool,
4813    #[serde(default)]
4814    pub trailing_comments: Vec<String>,
4815    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4816    #[serde(default)]
4817    pub use_bracket_syntax: bool,
4818    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4819    #[serde(default)]
4820    pub no_parens: bool,
4821    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4822    #[serde(default)]
4823    pub quoted: bool,
4824    /// Source position span
4825    #[serde(default, skip_serializing_if = "Option::is_none")]
4826    pub span: Option<Span>,
4827    /// Inferred data type from type annotation
4828    #[serde(default, skip_serializing_if = "Option::is_none")]
4829    pub inferred_type: Option<DataType>,
4830}
4831
4832impl Default for Function {
4833    fn default() -> Self {
4834        Self {
4835            name: String::new(),
4836            args: Vec::new(),
4837            distinct: false,
4838            trailing_comments: Vec::new(),
4839            use_bracket_syntax: false,
4840            no_parens: false,
4841            quoted: false,
4842            span: None,
4843            inferred_type: None,
4844        }
4845    }
4846}
4847
4848impl Function {
4849    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4850        Self {
4851            name: name.into(),
4852            args,
4853            distinct: false,
4854            trailing_comments: Vec::new(),
4855            use_bracket_syntax: false,
4856            no_parens: false,
4857            quoted: false,
4858            span: None,
4859            inferred_type: None,
4860        }
4861    }
4862}
4863
4864/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4865///
4866/// This struct is used for aggregate function calls that are not covered by
4867/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4868/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4869/// IGNORE NULLS / RESPECT NULLS modifiers.
4870#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4871#[cfg_attr(feature = "bindings", derive(TS))]
4872pub struct AggregateFunction {
4873    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4874    pub name: String,
4875    /// Positional arguments.
4876    pub args: Vec<Expression>,
4877    /// Whether DISTINCT was specified.
4878    pub distinct: bool,
4879    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4880    pub filter: Option<Expression>,
4881    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4882    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4883    pub order_by: Vec<Ordered>,
4884    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4885    #[serde(default, skip_serializing_if = "Option::is_none")]
4886    pub limit: Option<Box<Expression>>,
4887    /// IGNORE NULLS / RESPECT NULLS
4888    #[serde(default, skip_serializing_if = "Option::is_none")]
4889    pub ignore_nulls: Option<bool>,
4890    /// Inferred data type from type annotation
4891    #[serde(default, skip_serializing_if = "Option::is_none")]
4892    pub inferred_type: Option<DataType>,
4893}
4894
4895/// Represent a window function call with its OVER clause.
4896///
4897/// The inner `this` expression is typically a window-specific expression
4898/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4899/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4900/// frame specification.
4901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4902#[cfg_attr(feature = "bindings", derive(TS))]
4903pub struct WindowFunction {
4904    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4905    pub this: Expression,
4906    /// The OVER clause defining the window partitioning, ordering, and frame.
4907    pub over: Over,
4908    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4909    #[serde(default, skip_serializing_if = "Option::is_none")]
4910    pub keep: Option<Keep>,
4911    /// Inferred data type from type annotation
4912    #[serde(default, skip_serializing_if = "Option::is_none")]
4913    pub inferred_type: Option<DataType>,
4914}
4915
4916/// Oracle KEEP clause for aggregate functions
4917/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4919#[cfg_attr(feature = "bindings", derive(TS))]
4920pub struct Keep {
4921    /// true = FIRST, false = LAST
4922    pub first: bool,
4923    /// ORDER BY clause inside KEEP
4924    pub order_by: Vec<Ordered>,
4925}
4926
4927/// WITHIN GROUP clause (for ordered-set aggregate functions)
4928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4929#[cfg_attr(feature = "bindings", derive(TS))]
4930pub struct WithinGroup {
4931    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4932    pub this: Expression,
4933    /// The ORDER BY clause within the group
4934    pub order_by: Vec<Ordered>,
4935}
4936
4937/// Represent the FROM clause of a SELECT statement.
4938///
4939/// Contains one or more table sources (tables, subqueries, table-valued
4940/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4942#[cfg_attr(feature = "bindings", derive(TS))]
4943pub struct From {
4944    /// The table source expressions.
4945    pub expressions: Vec<Expression>,
4946}
4947
4948/// Represent a JOIN clause between two table sources.
4949///
4950/// The join condition can be specified via `on` (ON predicate) or `using`
4951/// (USING column list), but not both. The `kind` field determines the join
4952/// type (INNER, LEFT, CROSS, etc.).
4953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4954#[cfg_attr(feature = "bindings", derive(TS))]
4955pub struct Join {
4956    /// The right-hand table expression being joined.
4957    pub this: Expression,
4958    /// The ON condition (mutually exclusive with `using`).
4959    pub on: Option<Expression>,
4960    /// The USING column list (mutually exclusive with `on`).
4961    pub using: Vec<Identifier>,
4962    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4963    pub kind: JoinKind,
4964    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4965    pub use_inner_keyword: bool,
4966    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4967    pub use_outer_keyword: bool,
4968    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4969    pub deferred_condition: bool,
4970    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4971    #[serde(default, skip_serializing_if = "Option::is_none")]
4972    pub join_hint: Option<String>,
4973    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4974    #[serde(default, skip_serializing_if = "Option::is_none")]
4975    pub match_condition: Option<Expression>,
4976    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4977    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4978    pub pivots: Vec<Expression>,
4979    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4980    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4981    pub comments: Vec<String>,
4982    /// Nesting group identifier for nested join pretty-printing.
4983    /// Joins in the same group were parsed together; group boundaries come from
4984    /// deferred condition resolution phases.
4985    #[serde(default)]
4986    pub nesting_group: usize,
4987    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4988    #[serde(default)]
4989    pub directed: bool,
4990}
4991
4992/// Enumerate all supported SQL join types.
4993///
4994/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4995/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4996/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4997/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4998#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4999#[cfg_attr(feature = "bindings", derive(TS))]
5000pub enum JoinKind {
5001    Inner,
5002    Left,
5003    Right,
5004    Full,
5005    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5006    Cross,
5007    Natural,
5008    NaturalLeft,
5009    NaturalRight,
5010    NaturalFull,
5011    Semi,
5012    Anti,
5013    // Directional SEMI/ANTI joins
5014    LeftSemi,
5015    LeftAnti,
5016    RightSemi,
5017    RightAnti,
5018    // SQL Server specific
5019    CrossApply,
5020    OuterApply,
5021    // Time-series specific
5022    AsOf,
5023    AsOfLeft,
5024    AsOfRight,
5025    // Lateral join
5026    Lateral,
5027    LeftLateral,
5028    // MySQL specific
5029    Straight,
5030    // Implicit join (comma-separated tables: FROM a, b)
5031    Implicit,
5032    // ClickHouse ARRAY JOIN
5033    Array,
5034    LeftArray,
5035    // ClickHouse PASTE JOIN (positional join)
5036    Paste,
5037    // DuckDB POSITIONAL JOIN
5038    Positional,
5039}
5040
5041impl Default for JoinKind {
5042    fn default() -> Self {
5043        JoinKind::Inner
5044    }
5045}
5046
5047/// Parenthesized table expression with joins
5048/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5050#[cfg_attr(feature = "bindings", derive(TS))]
5051pub struct JoinedTable {
5052    /// The left-hand side table expression
5053    pub left: Expression,
5054    /// The joins applied to the left table
5055    pub joins: Vec<Join>,
5056    /// LATERAL VIEW clauses (Hive/Spark)
5057    pub lateral_views: Vec<LateralView>,
5058    /// Optional alias for the joined table expression
5059    pub alias: Option<Identifier>,
5060}
5061
5062/// Represent a WHERE clause containing a boolean filter predicate.
5063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5064#[cfg_attr(feature = "bindings", derive(TS))]
5065pub struct Where {
5066    /// The filter predicate expression.
5067    pub this: Expression,
5068}
5069
5070/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5071///
5072/// The `expressions` list may contain plain columns, ordinal positions,
5073/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5075#[cfg_attr(feature = "bindings", derive(TS))]
5076pub struct GroupBy {
5077    /// The grouping expressions.
5078    pub expressions: Vec<Expression>,
5079    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5080    #[serde(default)]
5081    pub all: Option<bool>,
5082    /// ClickHouse: WITH TOTALS modifier
5083    #[serde(default)]
5084    pub totals: bool,
5085    /// Leading comments that appeared before the GROUP BY keyword
5086    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5087    pub comments: Vec<String>,
5088}
5089
5090/// Represent a HAVING clause containing a predicate over aggregate results.
5091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5092#[cfg_attr(feature = "bindings", derive(TS))]
5093pub struct Having {
5094    /// The filter predicate, typically involving aggregate functions.
5095    pub this: Expression,
5096    /// Leading comments that appeared before the HAVING keyword
5097    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5098    pub comments: Vec<String>,
5099}
5100
5101/// Represent an ORDER BY clause containing one or more sort specifications.
5102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5103#[cfg_attr(feature = "bindings", derive(TS))]
5104pub struct OrderBy {
5105    /// The sort specifications, each with direction and null ordering.
5106    pub expressions: Vec<Ordered>,
5107    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5108    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5109    pub siblings: bool,
5110    /// Leading comments that appeared before the ORDER BY keyword
5111    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5112    pub comments: Vec<String>,
5113}
5114
5115/// Represent an expression with sort direction and null ordering.
5116///
5117/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5118/// When `desc` is false the sort is ascending. The `nulls_first` field
5119/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5120/// (database default).
5121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5122#[cfg_attr(feature = "bindings", derive(TS))]
5123pub struct Ordered {
5124    /// The expression to sort by.
5125    pub this: Expression,
5126    /// Whether the sort direction is descending (true) or ascending (false).
5127    pub desc: bool,
5128    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5129    pub nulls_first: Option<bool>,
5130    /// Whether ASC was explicitly written (not just implied)
5131    #[serde(default)]
5132    pub explicit_asc: bool,
5133    /// ClickHouse WITH FILL clause
5134    #[serde(default, skip_serializing_if = "Option::is_none")]
5135    pub with_fill: Option<Box<WithFill>>,
5136}
5137
5138impl Ordered {
5139    pub fn asc(expr: Expression) -> Self {
5140        Self {
5141            this: expr,
5142            desc: false,
5143            nulls_first: None,
5144            explicit_asc: false,
5145            with_fill: None,
5146        }
5147    }
5148
5149    pub fn desc(expr: Expression) -> Self {
5150        Self {
5151            this: expr,
5152            desc: true,
5153            nulls_first: None,
5154            explicit_asc: false,
5155            with_fill: None,
5156        }
5157    }
5158}
5159
5160/// DISTRIBUTE BY clause (Hive/Spark)
5161/// Controls how rows are distributed across reducers
5162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5163#[cfg_attr(feature = "bindings", derive(TS))]
5164#[cfg_attr(feature = "bindings", ts(export))]
5165pub struct DistributeBy {
5166    pub expressions: Vec<Expression>,
5167}
5168
5169/// CLUSTER BY clause (Hive/Spark)
5170/// Combines DISTRIBUTE BY and SORT BY on the same columns
5171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5172#[cfg_attr(feature = "bindings", derive(TS))]
5173#[cfg_attr(feature = "bindings", ts(export))]
5174pub struct ClusterBy {
5175    pub expressions: Vec<Ordered>,
5176}
5177
5178/// SORT BY clause (Hive/Spark)
5179/// Sorts data within each reducer (local sort, not global)
5180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5181#[cfg_attr(feature = "bindings", derive(TS))]
5182#[cfg_attr(feature = "bindings", ts(export))]
5183pub struct SortBy {
5184    pub expressions: Vec<Ordered>,
5185}
5186
5187/// LATERAL VIEW clause (Hive/Spark)
5188/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5190#[cfg_attr(feature = "bindings", derive(TS))]
5191#[cfg_attr(feature = "bindings", ts(export))]
5192pub struct LateralView {
5193    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5194    pub this: Expression,
5195    /// Table alias for the generated table
5196    pub table_alias: Option<Identifier>,
5197    /// Column aliases for the generated columns
5198    pub column_aliases: Vec<Identifier>,
5199    /// OUTER keyword - preserve nulls when input is empty/null
5200    pub outer: bool,
5201}
5202
5203/// Query hint
5204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5205#[cfg_attr(feature = "bindings", derive(TS))]
5206#[cfg_attr(feature = "bindings", ts(export))]
5207pub struct Hint {
5208    pub expressions: Vec<HintExpression>,
5209}
5210
5211/// Individual hint expression
5212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5213#[cfg_attr(feature = "bindings", derive(TS))]
5214#[cfg_attr(feature = "bindings", ts(export))]
5215pub enum HintExpression {
5216    /// Function-style hint: USE_HASH(table)
5217    Function { name: String, args: Vec<Expression> },
5218    /// Simple identifier hint: PARALLEL
5219    Identifier(String),
5220    /// Raw hint text (unparsed)
5221    Raw(String),
5222}
5223
5224/// Pseudocolumn type
5225#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5226#[cfg_attr(feature = "bindings", derive(TS))]
5227#[cfg_attr(feature = "bindings", ts(export))]
5228pub enum PseudocolumnType {
5229    Rownum,      // Oracle ROWNUM
5230    Rowid,       // Oracle ROWID
5231    Level,       // Oracle LEVEL (for CONNECT BY)
5232    Sysdate,     // Oracle SYSDATE
5233    ObjectId,    // Oracle OBJECT_ID
5234    ObjectValue, // Oracle OBJECT_VALUE
5235}
5236
5237impl PseudocolumnType {
5238    pub fn as_str(&self) -> &'static str {
5239        match self {
5240            PseudocolumnType::Rownum => "ROWNUM",
5241            PseudocolumnType::Rowid => "ROWID",
5242            PseudocolumnType::Level => "LEVEL",
5243            PseudocolumnType::Sysdate => "SYSDATE",
5244            PseudocolumnType::ObjectId => "OBJECT_ID",
5245            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5246        }
5247    }
5248
5249    pub fn from_str(s: &str) -> Option<Self> {
5250        match s.to_uppercase().as_str() {
5251            "ROWNUM" => Some(PseudocolumnType::Rownum),
5252            "ROWID" => Some(PseudocolumnType::Rowid),
5253            "LEVEL" => Some(PseudocolumnType::Level),
5254            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5255            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5256            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5257            _ => None,
5258        }
5259    }
5260}
5261
5262/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5263/// These are special identifiers that should not be quoted
5264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5265#[cfg_attr(feature = "bindings", derive(TS))]
5266#[cfg_attr(feature = "bindings", ts(export))]
5267pub struct Pseudocolumn {
5268    pub kind: PseudocolumnType,
5269}
5270
5271impl Pseudocolumn {
5272    pub fn rownum() -> Self {
5273        Self {
5274            kind: PseudocolumnType::Rownum,
5275        }
5276    }
5277
5278    pub fn rowid() -> Self {
5279        Self {
5280            kind: PseudocolumnType::Rowid,
5281        }
5282    }
5283
5284    pub fn level() -> Self {
5285        Self {
5286            kind: PseudocolumnType::Level,
5287        }
5288    }
5289}
5290
5291/// Oracle CONNECT BY clause for hierarchical queries
5292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5293#[cfg_attr(feature = "bindings", derive(TS))]
5294#[cfg_attr(feature = "bindings", ts(export))]
5295pub struct Connect {
5296    /// START WITH condition (optional, can come before or after CONNECT BY)
5297    pub start: Option<Expression>,
5298    /// CONNECT BY condition (required, contains PRIOR references)
5299    pub connect: Expression,
5300    /// NOCYCLE keyword to prevent infinite loops
5301    pub nocycle: bool,
5302}
5303
5304/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5306#[cfg_attr(feature = "bindings", derive(TS))]
5307#[cfg_attr(feature = "bindings", ts(export))]
5308pub struct Prior {
5309    pub this: Expression,
5310}
5311
5312/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5314#[cfg_attr(feature = "bindings", derive(TS))]
5315#[cfg_attr(feature = "bindings", ts(export))]
5316pub struct ConnectByRoot {
5317    pub this: Expression,
5318}
5319
5320/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5322#[cfg_attr(feature = "bindings", derive(TS))]
5323#[cfg_attr(feature = "bindings", ts(export))]
5324pub struct MatchRecognize {
5325    /// Source table/expression
5326    pub this: Option<Box<Expression>>,
5327    /// PARTITION BY expressions
5328    pub partition_by: Option<Vec<Expression>>,
5329    /// ORDER BY expressions
5330    pub order_by: Option<Vec<Ordered>>,
5331    /// MEASURES definitions
5332    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5333    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5334    pub rows: Option<MatchRecognizeRows>,
5335    /// AFTER MATCH SKIP behavior
5336    pub after: Option<MatchRecognizeAfter>,
5337    /// PATTERN definition (stored as raw string for complex regex patterns)
5338    pub pattern: Option<String>,
5339    /// DEFINE clauses (pattern variable definitions)
5340    pub define: Option<Vec<(Identifier, Expression)>>,
5341    /// Optional alias for the result
5342    pub alias: Option<Identifier>,
5343    /// Whether AS keyword was explicitly present before alias
5344    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5345    pub alias_explicit_as: bool,
5346}
5347
5348/// MEASURES expression with optional RUNNING/FINAL semantics
5349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5350#[cfg_attr(feature = "bindings", derive(TS))]
5351#[cfg_attr(feature = "bindings", ts(export))]
5352pub struct MatchRecognizeMeasure {
5353    /// The measure expression
5354    pub this: Expression,
5355    /// RUNNING or FINAL semantics (Snowflake-specific)
5356    pub window_frame: Option<MatchRecognizeSemantics>,
5357}
5358
5359/// Semantics for MEASURES in MATCH_RECOGNIZE
5360#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5361#[cfg_attr(feature = "bindings", derive(TS))]
5362#[cfg_attr(feature = "bindings", ts(export))]
5363pub enum MatchRecognizeSemantics {
5364    Running,
5365    Final,
5366}
5367
5368/// Row output semantics for MATCH_RECOGNIZE
5369#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5370#[cfg_attr(feature = "bindings", derive(TS))]
5371#[cfg_attr(feature = "bindings", ts(export))]
5372pub enum MatchRecognizeRows {
5373    OneRowPerMatch,
5374    AllRowsPerMatch,
5375    AllRowsPerMatchShowEmptyMatches,
5376    AllRowsPerMatchOmitEmptyMatches,
5377    AllRowsPerMatchWithUnmatchedRows,
5378}
5379
5380/// AFTER MATCH SKIP behavior
5381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5382#[cfg_attr(feature = "bindings", derive(TS))]
5383#[cfg_attr(feature = "bindings", ts(export))]
5384pub enum MatchRecognizeAfter {
5385    PastLastRow,
5386    ToNextRow,
5387    ToFirst(Identifier),
5388    ToLast(Identifier),
5389}
5390
5391/// Represent a LIMIT clause that restricts the number of returned rows.
5392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5393#[cfg_attr(feature = "bindings", derive(TS))]
5394pub struct Limit {
5395    /// The limit count expression.
5396    pub this: Expression,
5397    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5398    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5399    pub percent: bool,
5400    /// Comments from before the LIMIT keyword (emitted after the limit value)
5401    #[serde(default)]
5402    #[serde(skip_serializing_if = "Vec::is_empty")]
5403    pub comments: Vec<String>,
5404}
5405
5406/// OFFSET clause
5407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5408#[cfg_attr(feature = "bindings", derive(TS))]
5409pub struct Offset {
5410    pub this: Expression,
5411    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5412    #[serde(skip_serializing_if = "Option::is_none", default)]
5413    pub rows: Option<bool>,
5414}
5415
5416/// TOP clause (SQL Server)
5417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5418#[cfg_attr(feature = "bindings", derive(TS))]
5419pub struct Top {
5420    pub this: Expression,
5421    pub percent: bool,
5422    pub with_ties: bool,
5423    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5424    #[serde(default)]
5425    pub parenthesized: bool,
5426}
5427
5428/// FETCH FIRST/NEXT clause (SQL standard)
5429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5430#[cfg_attr(feature = "bindings", derive(TS))]
5431pub struct Fetch {
5432    /// FIRST or NEXT
5433    pub direction: String,
5434    /// Count expression (optional)
5435    pub count: Option<Expression>,
5436    /// PERCENT modifier
5437    pub percent: bool,
5438    /// ROWS or ROW keyword present
5439    pub rows: bool,
5440    /// WITH TIES modifier
5441    pub with_ties: bool,
5442}
5443
5444/// Represent a QUALIFY clause for filtering on window function results.
5445///
5446/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5447/// typically references a window function (e.g.
5448/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5450#[cfg_attr(feature = "bindings", derive(TS))]
5451pub struct Qualify {
5452    /// The filter predicate over window function results.
5453    pub this: Expression,
5454}
5455
5456/// SAMPLE / TABLESAMPLE clause
5457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5458#[cfg_attr(feature = "bindings", derive(TS))]
5459pub struct Sample {
5460    pub method: SampleMethod,
5461    pub size: Expression,
5462    pub seed: Option<Expression>,
5463    /// ClickHouse OFFSET expression after SAMPLE size
5464    #[serde(default)]
5465    pub offset: Option<Expression>,
5466    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5467    pub unit_after_size: bool,
5468    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5469    #[serde(default)]
5470    pub use_sample_keyword: bool,
5471    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5472    #[serde(default)]
5473    pub explicit_method: bool,
5474    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5475    #[serde(default)]
5476    pub method_before_size: bool,
5477    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5478    #[serde(default)]
5479    pub use_seed_keyword: bool,
5480    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5481    pub bucket_numerator: Option<Box<Expression>>,
5482    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5483    pub bucket_denominator: Option<Box<Expression>>,
5484    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5485    pub bucket_field: Option<Box<Expression>>,
5486    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5487    #[serde(default)]
5488    pub is_using_sample: bool,
5489    /// Whether the unit was explicitly PERCENT (vs ROWS)
5490    #[serde(default)]
5491    pub is_percent: bool,
5492    /// Whether to suppress method output (for cross-dialect transpilation)
5493    #[serde(default)]
5494    pub suppress_method_output: bool,
5495}
5496
5497/// Sample method
5498#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5499#[cfg_attr(feature = "bindings", derive(TS))]
5500pub enum SampleMethod {
5501    Bernoulli,
5502    System,
5503    Block,
5504    Row,
5505    Percent,
5506    /// Hive bucket sampling
5507    Bucket,
5508    /// DuckDB reservoir sampling
5509    Reservoir,
5510}
5511
5512/// Named window definition (WINDOW w AS (...))
5513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5514#[cfg_attr(feature = "bindings", derive(TS))]
5515pub struct NamedWindow {
5516    pub name: Identifier,
5517    pub spec: Over,
5518}
5519
5520/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5521///
5522/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5523/// that reference themselves. Each CTE is defined in the `ctes` vector and
5524/// can be referenced by name in subsequent CTEs and in the main query body.
5525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5526#[cfg_attr(feature = "bindings", derive(TS))]
5527pub struct With {
5528    /// The list of CTE definitions, in order.
5529    pub ctes: Vec<Cte>,
5530    /// Whether the WITH RECURSIVE keyword was used.
5531    pub recursive: bool,
5532    /// Leading comments before the statement
5533    #[serde(default)]
5534    pub leading_comments: Vec<String>,
5535    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5536    #[serde(default, skip_serializing_if = "Option::is_none")]
5537    pub search: Option<Box<Expression>>,
5538}
5539
5540/// Represent a single Common Table Expression definition.
5541///
5542/// A CTE has a name (`alias`), an optional column list, and a body query.
5543/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5544/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5545/// the expression comes before the alias (`alias_first`).
5546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5547#[cfg_attr(feature = "bindings", derive(TS))]
5548pub struct Cte {
5549    /// The CTE name.
5550    pub alias: Identifier,
5551    /// The CTE body (typically a SELECT, UNION, etc.).
5552    pub this: Expression,
5553    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5554    pub columns: Vec<Identifier>,
5555    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5556    pub materialized: Option<bool>,
5557    /// USING KEY (columns) for DuckDB recursive CTEs
5558    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5559    pub key_expressions: Vec<Identifier>,
5560    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5561    #[serde(default)]
5562    pub alias_first: bool,
5563    /// Comments associated with this CTE (placed after alias name, before AS)
5564    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5565    pub comments: Vec<String>,
5566}
5567
5568/// Window specification
5569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5570#[cfg_attr(feature = "bindings", derive(TS))]
5571pub struct WindowSpec {
5572    pub partition_by: Vec<Expression>,
5573    pub order_by: Vec<Ordered>,
5574    pub frame: Option<WindowFrame>,
5575}
5576
5577/// OVER clause
5578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5579#[cfg_attr(feature = "bindings", derive(TS))]
5580pub struct Over {
5581    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5582    pub window_name: Option<Identifier>,
5583    pub partition_by: Vec<Expression>,
5584    pub order_by: Vec<Ordered>,
5585    pub frame: Option<WindowFrame>,
5586    pub alias: Option<Identifier>,
5587}
5588
5589/// Window frame
5590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5591#[cfg_attr(feature = "bindings", derive(TS))]
5592pub struct WindowFrame {
5593    pub kind: WindowFrameKind,
5594    pub start: WindowFrameBound,
5595    pub end: Option<WindowFrameBound>,
5596    pub exclude: Option<WindowFrameExclude>,
5597    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5598    #[serde(default, skip_serializing_if = "Option::is_none")]
5599    pub kind_text: Option<String>,
5600    /// Original text of the start bound side keyword (e.g. "preceding")
5601    #[serde(default, skip_serializing_if = "Option::is_none")]
5602    pub start_side_text: Option<String>,
5603    /// Original text of the end bound side keyword
5604    #[serde(default, skip_serializing_if = "Option::is_none")]
5605    pub end_side_text: Option<String>,
5606}
5607
5608#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5609#[cfg_attr(feature = "bindings", derive(TS))]
5610pub enum WindowFrameKind {
5611    Rows,
5612    Range,
5613    Groups,
5614}
5615
5616/// EXCLUDE clause for window frames
5617#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5618#[cfg_attr(feature = "bindings", derive(TS))]
5619pub enum WindowFrameExclude {
5620    CurrentRow,
5621    Group,
5622    Ties,
5623    NoOthers,
5624}
5625
5626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5627#[cfg_attr(feature = "bindings", derive(TS))]
5628pub enum WindowFrameBound {
5629    CurrentRow,
5630    UnboundedPreceding,
5631    UnboundedFollowing,
5632    Preceding(Box<Expression>),
5633    Following(Box<Expression>),
5634    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5635    BarePreceding,
5636    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5637    BareFollowing,
5638    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5639    Value(Box<Expression>),
5640}
5641
5642/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5644#[cfg_attr(feature = "bindings", derive(TS))]
5645pub struct StructField {
5646    pub name: String,
5647    pub data_type: DataType,
5648    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5649    pub options: Vec<Expression>,
5650    #[serde(default, skip_serializing_if = "Option::is_none")]
5651    pub comment: Option<String>,
5652}
5653
5654impl StructField {
5655    /// Create a new struct field without options
5656    pub fn new(name: String, data_type: DataType) -> Self {
5657        Self {
5658            name,
5659            data_type,
5660            options: Vec::new(),
5661            comment: None,
5662        }
5663    }
5664
5665    /// Create a new struct field with options
5666    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5667        Self {
5668            name,
5669            data_type,
5670            options,
5671            comment: None,
5672        }
5673    }
5674
5675    /// Create a new struct field with options and comment
5676    pub fn with_options_and_comment(
5677        name: String,
5678        data_type: DataType,
5679        options: Vec<Expression>,
5680        comment: Option<String>,
5681    ) -> Self {
5682        Self {
5683            name,
5684            data_type,
5685            options,
5686            comment,
5687        }
5688    }
5689}
5690
5691/// Enumerate all SQL data types recognized by the parser.
5692///
5693/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5694/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5695/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5696///
5697/// This enum is used in CAST expressions, column definitions, function return
5698/// types, and anywhere a data type specification appears in SQL.
5699///
5700/// Types that do not match any known variant fall through to `Custom { name }`,
5701/// preserving the original type name for round-trip fidelity.
5702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5703#[cfg_attr(feature = "bindings", derive(TS))]
5704#[serde(tag = "data_type", rename_all = "snake_case")]
5705pub enum DataType {
5706    // Numeric
5707    Boolean,
5708    TinyInt {
5709        length: Option<u32>,
5710    },
5711    SmallInt {
5712        length: Option<u32>,
5713    },
5714    /// Int type with optional length. `integer_spelling` indicates whether the original
5715    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5716    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5717    Int {
5718        length: Option<u32>,
5719        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5720        integer_spelling: bool,
5721    },
5722    BigInt {
5723        length: Option<u32>,
5724    },
5725    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5726    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5727    /// preserve the original spelling.
5728    Float {
5729        precision: Option<u32>,
5730        scale: Option<u32>,
5731        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5732        real_spelling: bool,
5733    },
5734    Double {
5735        precision: Option<u32>,
5736        scale: Option<u32>,
5737    },
5738    Decimal {
5739        precision: Option<u32>,
5740        scale: Option<u32>,
5741    },
5742
5743    // String
5744    Char {
5745        length: Option<u32>,
5746    },
5747    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5748    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5749    VarChar {
5750        length: Option<u32>,
5751        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5752        parenthesized_length: bool,
5753    },
5754    /// String type with optional max length (BigQuery STRING(n))
5755    String {
5756        length: Option<u32>,
5757    },
5758    Text,
5759    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5760    TextWithLength {
5761        length: u32,
5762    },
5763
5764    // Binary
5765    Binary {
5766        length: Option<u32>,
5767    },
5768    VarBinary {
5769        length: Option<u32>,
5770    },
5771    Blob,
5772
5773    // Bit
5774    Bit {
5775        length: Option<u32>,
5776    },
5777    VarBit {
5778        length: Option<u32>,
5779    },
5780
5781    // Date/Time
5782    Date,
5783    Time {
5784        precision: Option<u32>,
5785        #[serde(default)]
5786        timezone: bool,
5787    },
5788    Timestamp {
5789        precision: Option<u32>,
5790        timezone: bool,
5791    },
5792    Interval {
5793        unit: Option<String>,
5794        /// For range intervals like INTERVAL DAY TO HOUR
5795        #[serde(default, skip_serializing_if = "Option::is_none")]
5796        to: Option<String>,
5797    },
5798
5799    // JSON
5800    Json,
5801    JsonB,
5802
5803    // UUID
5804    Uuid,
5805
5806    // Array
5807    Array {
5808        element_type: Box<DataType>,
5809        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5810        #[serde(default, skip_serializing_if = "Option::is_none")]
5811        dimension: Option<u32>,
5812    },
5813
5814    /// List type (Materialize): INT LIST, TEXT LIST LIST
5815    /// Uses postfix LIST syntax instead of ARRAY<T>
5816    List {
5817        element_type: Box<DataType>,
5818    },
5819
5820    // Struct/Map
5821    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5822    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5823    Struct {
5824        fields: Vec<StructField>,
5825        nested: bool,
5826    },
5827    Map {
5828        key_type: Box<DataType>,
5829        value_type: Box<DataType>,
5830    },
5831
5832    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5833    Enum {
5834        values: Vec<String>,
5835        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5836        assignments: Vec<Option<String>>,
5837    },
5838
5839    // Set type (MySQL): SET('a', 'b', 'c')
5840    Set {
5841        values: Vec<String>,
5842    },
5843
5844    // Union type (DuckDB): UNION(num INT, str TEXT)
5845    Union {
5846        fields: Vec<(String, DataType)>,
5847    },
5848
5849    // Vector (Snowflake / SingleStore)
5850    Vector {
5851        #[serde(default)]
5852        element_type: Option<Box<DataType>>,
5853        dimension: Option<u32>,
5854    },
5855
5856    // Object (Snowflake structured type)
5857    // fields: Vec of (field_name, field_type, not_null)
5858    Object {
5859        fields: Vec<(String, DataType, bool)>,
5860        modifier: Option<String>,
5861    },
5862
5863    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5864    Nullable {
5865        inner: Box<DataType>,
5866    },
5867
5868    // Custom/User-defined
5869    Custom {
5870        name: String,
5871    },
5872
5873    // Spatial types
5874    Geometry {
5875        subtype: Option<String>,
5876        srid: Option<u32>,
5877    },
5878    Geography {
5879        subtype: Option<String>,
5880        srid: Option<u32>,
5881    },
5882
5883    // Character Set (for CONVERT USING in MySQL)
5884    // Renders as CHAR CHARACTER SET {name} in cast target
5885    CharacterSet {
5886        name: String,
5887    },
5888
5889    // Unknown
5890    Unknown,
5891}
5892
5893/// Array expression
5894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5895#[cfg_attr(feature = "bindings", derive(TS))]
5896#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5897pub struct Array {
5898    pub expressions: Vec<Expression>,
5899}
5900
5901/// Struct expression
5902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5903#[cfg_attr(feature = "bindings", derive(TS))]
5904pub struct Struct {
5905    pub fields: Vec<(Option<String>, Expression)>,
5906}
5907
5908/// Tuple expression
5909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5910#[cfg_attr(feature = "bindings", derive(TS))]
5911pub struct Tuple {
5912    pub expressions: Vec<Expression>,
5913}
5914
5915/// Interval expression
5916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5917#[cfg_attr(feature = "bindings", derive(TS))]
5918pub struct Interval {
5919    /// The value expression (e.g., '1', 5, column_ref)
5920    pub this: Option<Expression>,
5921    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5922    pub unit: Option<IntervalUnitSpec>,
5923}
5924
5925/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5927#[cfg_attr(feature = "bindings", derive(TS))]
5928#[serde(tag = "type", rename_all = "snake_case")]
5929pub enum IntervalUnitSpec {
5930    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5931    Simple {
5932        unit: IntervalUnit,
5933        /// Whether to use plural form (e.g., DAYS vs DAY)
5934        use_plural: bool,
5935    },
5936    /// Interval span (e.g., HOUR TO SECOND)
5937    Span(IntervalSpan),
5938    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5939    /// The start and end can be expressions like function calls with precision
5940    ExprSpan(IntervalSpanExpr),
5941    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5942    Expr(Box<Expression>),
5943}
5944
5945/// Interval span for ranges like HOUR TO SECOND
5946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5947#[cfg_attr(feature = "bindings", derive(TS))]
5948pub struct IntervalSpan {
5949    /// Start unit (e.g., HOUR)
5950    pub this: IntervalUnit,
5951    /// End unit (e.g., SECOND)
5952    pub expression: IntervalUnit,
5953}
5954
5955/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5956/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5958#[cfg_attr(feature = "bindings", derive(TS))]
5959pub struct IntervalSpanExpr {
5960    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5961    pub this: Box<Expression>,
5962    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5963    pub expression: Box<Expression>,
5964}
5965
5966#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5967#[cfg_attr(feature = "bindings", derive(TS))]
5968pub enum IntervalUnit {
5969    Year,
5970    Quarter,
5971    Month,
5972    Week,
5973    Day,
5974    Hour,
5975    Minute,
5976    Second,
5977    Millisecond,
5978    Microsecond,
5979    Nanosecond,
5980}
5981
5982/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5984#[cfg_attr(feature = "bindings", derive(TS))]
5985pub struct Command {
5986    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5987    pub this: String,
5988}
5989
5990/// EXEC/EXECUTE statement (TSQL stored procedure call)
5991/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5993#[cfg_attr(feature = "bindings", derive(TS))]
5994pub struct ExecuteStatement {
5995    /// The procedure name (can be qualified: schema.proc_name)
5996    pub this: Expression,
5997    /// Named parameters: @param=value pairs
5998    #[serde(default)]
5999    pub parameters: Vec<ExecuteParameter>,
6000    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
6001    #[serde(default, skip_serializing_if = "Option::is_none")]
6002    pub suffix: Option<String>,
6003}
6004
6005/// Named parameter in EXEC statement: @name=value
6006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6007#[cfg_attr(feature = "bindings", derive(TS))]
6008pub struct ExecuteParameter {
6009    /// Parameter name (including @)
6010    pub name: String,
6011    /// Parameter value
6012    pub value: Expression,
6013    /// Whether this is a positional parameter (no = sign)
6014    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6015    pub positional: bool,
6016    /// TSQL OUTPUT modifier on parameter
6017    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6018    pub output: bool,
6019}
6020
6021/// KILL statement (MySQL/MariaDB)
6022/// KILL [CONNECTION | QUERY] <id>
6023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6024#[cfg_attr(feature = "bindings", derive(TS))]
6025pub struct Kill {
6026    /// The target (process ID or connection ID)
6027    pub this: Expression,
6028    /// Optional kind: "CONNECTION" or "QUERY"
6029    pub kind: Option<String>,
6030}
6031
6032/// Snowflake CREATE TASK statement
6033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6034#[cfg_attr(feature = "bindings", derive(TS))]
6035pub struct CreateTask {
6036    pub or_replace: bool,
6037    pub if_not_exists: bool,
6038    /// Task name (possibly qualified: db.schema.task)
6039    pub name: String,
6040    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6041    pub properties: String,
6042    /// The SQL statement body after AS
6043    pub body: Expression,
6044}
6045
6046/// Raw/unparsed SQL
6047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6048#[cfg_attr(feature = "bindings", derive(TS))]
6049pub struct Raw {
6050    pub sql: String,
6051}
6052
6053// ============================================================================
6054// Function expression types
6055// ============================================================================
6056
6057/// Generic unary function (takes a single argument)
6058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6059#[cfg_attr(feature = "bindings", derive(TS))]
6060pub struct UnaryFunc {
6061    pub this: Expression,
6062    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6063    #[serde(skip_serializing_if = "Option::is_none", default)]
6064    pub original_name: Option<String>,
6065    /// Inferred data type from type annotation
6066    #[serde(default, skip_serializing_if = "Option::is_none")]
6067    pub inferred_type: Option<DataType>,
6068}
6069
6070impl UnaryFunc {
6071    /// Create a new UnaryFunc with no original_name
6072    pub fn new(this: Expression) -> Self {
6073        Self {
6074            this,
6075            original_name: None,
6076            inferred_type: None,
6077        }
6078    }
6079
6080    /// Create a new UnaryFunc with an original name for round-trip preservation
6081    pub fn with_name(this: Expression, name: String) -> Self {
6082        Self {
6083            this,
6084            original_name: Some(name),
6085            inferred_type: None,
6086        }
6087    }
6088}
6089
6090/// CHAR/CHR function with multiple args and optional USING charset
6091/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6092/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6094#[cfg_attr(feature = "bindings", derive(TS))]
6095pub struct CharFunc {
6096    pub args: Vec<Expression>,
6097    #[serde(skip_serializing_if = "Option::is_none", default)]
6098    pub charset: Option<String>,
6099    /// Original function name (CHAR or CHR), defaults to CHAR
6100    #[serde(skip_serializing_if = "Option::is_none", default)]
6101    pub name: Option<String>,
6102}
6103
6104/// Generic binary function (takes two arguments)
6105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6106#[cfg_attr(feature = "bindings", derive(TS))]
6107pub struct BinaryFunc {
6108    pub this: Expression,
6109    pub expression: Expression,
6110    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6111    #[serde(skip_serializing_if = "Option::is_none", default)]
6112    pub original_name: Option<String>,
6113    /// Inferred data type from type annotation
6114    #[serde(default, skip_serializing_if = "Option::is_none")]
6115    pub inferred_type: Option<DataType>,
6116}
6117
6118/// Variable argument function
6119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6120#[cfg_attr(feature = "bindings", derive(TS))]
6121pub struct VarArgFunc {
6122    pub expressions: Vec<Expression>,
6123    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6124    #[serde(skip_serializing_if = "Option::is_none", default)]
6125    pub original_name: Option<String>,
6126    /// Inferred data type from type annotation
6127    #[serde(default, skip_serializing_if = "Option::is_none")]
6128    pub inferred_type: Option<DataType>,
6129}
6130
6131/// CONCAT_WS function
6132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6133#[cfg_attr(feature = "bindings", derive(TS))]
6134pub struct ConcatWs {
6135    pub separator: Expression,
6136    pub expressions: Vec<Expression>,
6137}
6138
6139/// SUBSTRING function
6140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6141#[cfg_attr(feature = "bindings", derive(TS))]
6142pub struct SubstringFunc {
6143    pub this: Expression,
6144    pub start: Expression,
6145    pub length: Option<Expression>,
6146    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6147    #[serde(default)]
6148    pub from_for_syntax: bool,
6149}
6150
6151/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6153#[cfg_attr(feature = "bindings", derive(TS))]
6154pub struct OverlayFunc {
6155    pub this: Expression,
6156    pub replacement: Expression,
6157    pub from: Expression,
6158    pub length: Option<Expression>,
6159}
6160
6161/// TRIM function
6162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6163#[cfg_attr(feature = "bindings", derive(TS))]
6164pub struct TrimFunc {
6165    pub this: Expression,
6166    pub characters: Option<Expression>,
6167    pub position: TrimPosition,
6168    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6169    #[serde(default)]
6170    pub sql_standard_syntax: bool,
6171    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6172    #[serde(default)]
6173    pub position_explicit: bool,
6174}
6175
6176#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6177#[cfg_attr(feature = "bindings", derive(TS))]
6178pub enum TrimPosition {
6179    Both,
6180    Leading,
6181    Trailing,
6182}
6183
6184/// REPLACE function
6185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6186#[cfg_attr(feature = "bindings", derive(TS))]
6187pub struct ReplaceFunc {
6188    pub this: Expression,
6189    pub old: Expression,
6190    pub new: Expression,
6191}
6192
6193/// LEFT/RIGHT function
6194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6195#[cfg_attr(feature = "bindings", derive(TS))]
6196pub struct LeftRightFunc {
6197    pub this: Expression,
6198    pub length: Expression,
6199}
6200
6201/// REPEAT function
6202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6203#[cfg_attr(feature = "bindings", derive(TS))]
6204pub struct RepeatFunc {
6205    pub this: Expression,
6206    pub times: Expression,
6207}
6208
6209/// LPAD/RPAD function
6210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6211#[cfg_attr(feature = "bindings", derive(TS))]
6212pub struct PadFunc {
6213    pub this: Expression,
6214    pub length: Expression,
6215    pub fill: Option<Expression>,
6216}
6217
6218/// SPLIT function
6219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6220#[cfg_attr(feature = "bindings", derive(TS))]
6221pub struct SplitFunc {
6222    pub this: Expression,
6223    pub delimiter: Expression,
6224}
6225
6226/// REGEXP_LIKE function
6227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6228#[cfg_attr(feature = "bindings", derive(TS))]
6229pub struct RegexpFunc {
6230    pub this: Expression,
6231    pub pattern: Expression,
6232    pub flags: Option<Expression>,
6233}
6234
6235/// REGEXP_REPLACE function
6236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6237#[cfg_attr(feature = "bindings", derive(TS))]
6238pub struct RegexpReplaceFunc {
6239    pub this: Expression,
6240    pub pattern: Expression,
6241    pub replacement: Expression,
6242    pub flags: Option<Expression>,
6243}
6244
6245/// REGEXP_EXTRACT function
6246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6247#[cfg_attr(feature = "bindings", derive(TS))]
6248pub struct RegexpExtractFunc {
6249    pub this: Expression,
6250    pub pattern: Expression,
6251    pub group: Option<Expression>,
6252}
6253
6254/// ROUND function
6255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6256#[cfg_attr(feature = "bindings", derive(TS))]
6257pub struct RoundFunc {
6258    pub this: Expression,
6259    pub decimals: Option<Expression>,
6260}
6261
6262/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6264#[cfg_attr(feature = "bindings", derive(TS))]
6265pub struct FloorFunc {
6266    pub this: Expression,
6267    pub scale: Option<Expression>,
6268    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6269    #[serde(skip_serializing_if = "Option::is_none", default)]
6270    pub to: Option<Expression>,
6271}
6272
6273/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6275#[cfg_attr(feature = "bindings", derive(TS))]
6276pub struct CeilFunc {
6277    pub this: Expression,
6278    #[serde(skip_serializing_if = "Option::is_none", default)]
6279    pub decimals: Option<Expression>,
6280    /// Time unit for Druid-style CEIL(time TO unit) syntax
6281    #[serde(skip_serializing_if = "Option::is_none", default)]
6282    pub to: Option<Expression>,
6283}
6284
6285/// LOG function
6286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6287#[cfg_attr(feature = "bindings", derive(TS))]
6288pub struct LogFunc {
6289    pub this: Expression,
6290    pub base: Option<Expression>,
6291}
6292
6293/// CURRENT_DATE (no arguments)
6294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6295#[cfg_attr(feature = "bindings", derive(TS))]
6296pub struct CurrentDate;
6297
6298/// CURRENT_TIME
6299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6300#[cfg_attr(feature = "bindings", derive(TS))]
6301pub struct CurrentTime {
6302    pub precision: Option<u32>,
6303}
6304
6305/// CURRENT_TIMESTAMP
6306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6307#[cfg_attr(feature = "bindings", derive(TS))]
6308pub struct CurrentTimestamp {
6309    pub precision: Option<u32>,
6310    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6311    #[serde(default)]
6312    pub sysdate: bool,
6313}
6314
6315/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6317#[cfg_attr(feature = "bindings", derive(TS))]
6318pub struct CurrentTimestampLTZ {
6319    pub precision: Option<u32>,
6320}
6321
6322/// AT TIME ZONE expression for timezone conversion
6323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6324#[cfg_attr(feature = "bindings", derive(TS))]
6325pub struct AtTimeZone {
6326    /// The expression to convert
6327    pub this: Expression,
6328    /// The target timezone
6329    pub zone: Expression,
6330}
6331
6332/// DATE_ADD / DATE_SUB function
6333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6334#[cfg_attr(feature = "bindings", derive(TS))]
6335pub struct DateAddFunc {
6336    pub this: Expression,
6337    pub interval: Expression,
6338    pub unit: IntervalUnit,
6339}
6340
6341/// DATEDIFF function
6342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6343#[cfg_attr(feature = "bindings", derive(TS))]
6344pub struct DateDiffFunc {
6345    pub this: Expression,
6346    pub expression: Expression,
6347    pub unit: Option<IntervalUnit>,
6348}
6349
6350/// DATE_TRUNC function
6351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6352#[cfg_attr(feature = "bindings", derive(TS))]
6353pub struct DateTruncFunc {
6354    pub this: Expression,
6355    pub unit: DateTimeField,
6356}
6357
6358/// EXTRACT function
6359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6360#[cfg_attr(feature = "bindings", derive(TS))]
6361pub struct ExtractFunc {
6362    pub this: Expression,
6363    pub field: DateTimeField,
6364}
6365
6366#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6367#[cfg_attr(feature = "bindings", derive(TS))]
6368pub enum DateTimeField {
6369    Year,
6370    Month,
6371    Day,
6372    Hour,
6373    Minute,
6374    Second,
6375    Millisecond,
6376    Microsecond,
6377    DayOfWeek,
6378    DayOfYear,
6379    Week,
6380    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6381    WeekWithModifier(String),
6382    Quarter,
6383    Epoch,
6384    Timezone,
6385    TimezoneHour,
6386    TimezoneMinute,
6387    Date,
6388    Time,
6389    /// Custom datetime field for dialect-specific or arbitrary fields
6390    Custom(String),
6391}
6392
6393/// TO_DATE function
6394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6395#[cfg_attr(feature = "bindings", derive(TS))]
6396pub struct ToDateFunc {
6397    pub this: Expression,
6398    pub format: Option<Expression>,
6399}
6400
6401/// TO_TIMESTAMP function
6402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6403#[cfg_attr(feature = "bindings", derive(TS))]
6404pub struct ToTimestampFunc {
6405    pub this: Expression,
6406    pub format: Option<Expression>,
6407}
6408
6409/// IF function
6410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6411#[cfg_attr(feature = "bindings", derive(TS))]
6412pub struct IfFunc {
6413    pub condition: Expression,
6414    pub true_value: Expression,
6415    pub false_value: Option<Expression>,
6416    /// Original function name (IF, IFF, IIF) for round-trip preservation
6417    #[serde(skip_serializing_if = "Option::is_none", default)]
6418    pub original_name: Option<String>,
6419    /// Inferred data type from type annotation
6420    #[serde(default, skip_serializing_if = "Option::is_none")]
6421    pub inferred_type: Option<DataType>,
6422}
6423
6424/// NVL2 function
6425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6426#[cfg_attr(feature = "bindings", derive(TS))]
6427pub struct Nvl2Func {
6428    pub this: Expression,
6429    pub true_value: Expression,
6430    pub false_value: Expression,
6431    /// Inferred data type from type annotation
6432    #[serde(default, skip_serializing_if = "Option::is_none")]
6433    pub inferred_type: Option<DataType>,
6434}
6435
6436// ============================================================================
6437// Typed Aggregate Function types
6438// ============================================================================
6439
6440/// Generic aggregate function base type
6441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6442#[cfg_attr(feature = "bindings", derive(TS))]
6443pub struct AggFunc {
6444    pub this: Expression,
6445    pub distinct: bool,
6446    pub filter: Option<Expression>,
6447    pub order_by: Vec<Ordered>,
6448    /// Original function name (case-preserving) when parsed from SQL
6449    #[serde(skip_serializing_if = "Option::is_none", default)]
6450    pub name: Option<String>,
6451    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6452    #[serde(skip_serializing_if = "Option::is_none", default)]
6453    pub ignore_nulls: Option<bool>,
6454    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6455    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6456    #[serde(skip_serializing_if = "Option::is_none", default)]
6457    pub having_max: Option<(Box<Expression>, bool)>,
6458    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6459    #[serde(skip_serializing_if = "Option::is_none", default)]
6460    pub limit: Option<Box<Expression>>,
6461    /// Inferred data type from type annotation
6462    #[serde(default, skip_serializing_if = "Option::is_none")]
6463    pub inferred_type: Option<DataType>,
6464}
6465
6466/// COUNT function with optional star
6467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6468#[cfg_attr(feature = "bindings", derive(TS))]
6469pub struct CountFunc {
6470    pub this: Option<Expression>,
6471    pub star: bool,
6472    pub distinct: bool,
6473    pub filter: Option<Expression>,
6474    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6475    #[serde(default, skip_serializing_if = "Option::is_none")]
6476    pub ignore_nulls: Option<bool>,
6477    /// Original function name for case preservation (e.g., "count" or "COUNT")
6478    #[serde(default, skip_serializing_if = "Option::is_none")]
6479    pub original_name: Option<String>,
6480    /// Inferred data type from type annotation
6481    #[serde(default, skip_serializing_if = "Option::is_none")]
6482    pub inferred_type: Option<DataType>,
6483}
6484
6485/// GROUP_CONCAT function (MySQL style)
6486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6487#[cfg_attr(feature = "bindings", derive(TS))]
6488pub struct GroupConcatFunc {
6489    pub this: Expression,
6490    pub separator: Option<Expression>,
6491    pub order_by: Option<Vec<Ordered>>,
6492    pub distinct: bool,
6493    pub filter: Option<Expression>,
6494    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6495    #[serde(default, skip_serializing_if = "Option::is_none")]
6496    pub limit: Option<Box<Expression>>,
6497    /// Inferred data type from type annotation
6498    #[serde(default, skip_serializing_if = "Option::is_none")]
6499    pub inferred_type: Option<DataType>,
6500}
6501
6502/// STRING_AGG function (PostgreSQL/Standard SQL)
6503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6504#[cfg_attr(feature = "bindings", derive(TS))]
6505pub struct StringAggFunc {
6506    pub this: Expression,
6507    #[serde(default)]
6508    pub separator: Option<Expression>,
6509    #[serde(default)]
6510    pub order_by: Option<Vec<Ordered>>,
6511    #[serde(default)]
6512    pub distinct: bool,
6513    #[serde(default)]
6514    pub filter: Option<Expression>,
6515    /// BigQuery LIMIT inside STRING_AGG
6516    #[serde(default, skip_serializing_if = "Option::is_none")]
6517    pub limit: Option<Box<Expression>>,
6518    /// Inferred data type from type annotation
6519    #[serde(default, skip_serializing_if = "Option::is_none")]
6520    pub inferred_type: Option<DataType>,
6521}
6522
6523/// LISTAGG function (Oracle style)
6524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6525#[cfg_attr(feature = "bindings", derive(TS))]
6526pub struct ListAggFunc {
6527    pub this: Expression,
6528    pub separator: Option<Expression>,
6529    pub on_overflow: Option<ListAggOverflow>,
6530    pub order_by: Option<Vec<Ordered>>,
6531    pub distinct: bool,
6532    pub filter: Option<Expression>,
6533    /// Inferred data type from type annotation
6534    #[serde(default, skip_serializing_if = "Option::is_none")]
6535    pub inferred_type: Option<DataType>,
6536}
6537
6538/// LISTAGG ON OVERFLOW behavior
6539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6540#[cfg_attr(feature = "bindings", derive(TS))]
6541pub enum ListAggOverflow {
6542    Error,
6543    Truncate {
6544        filler: Option<Expression>,
6545        with_count: bool,
6546    },
6547}
6548
6549/// SUM_IF / COUNT_IF function
6550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6551#[cfg_attr(feature = "bindings", derive(TS))]
6552pub struct SumIfFunc {
6553    pub this: Expression,
6554    pub condition: Expression,
6555    pub filter: Option<Expression>,
6556    /// Inferred data type from type annotation
6557    #[serde(default, skip_serializing_if = "Option::is_none")]
6558    pub inferred_type: Option<DataType>,
6559}
6560
6561/// APPROX_PERCENTILE function
6562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6563#[cfg_attr(feature = "bindings", derive(TS))]
6564pub struct ApproxPercentileFunc {
6565    pub this: Expression,
6566    pub percentile: Expression,
6567    pub accuracy: Option<Expression>,
6568    pub filter: Option<Expression>,
6569}
6570
6571/// PERCENTILE_CONT / PERCENTILE_DISC function
6572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6573#[cfg_attr(feature = "bindings", derive(TS))]
6574pub struct PercentileFunc {
6575    pub this: Expression,
6576    pub percentile: Expression,
6577    pub order_by: Option<Vec<Ordered>>,
6578    pub filter: Option<Expression>,
6579}
6580
6581// ============================================================================
6582// Typed Window Function types
6583// ============================================================================
6584
6585/// ROW_NUMBER function (no arguments)
6586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6587#[cfg_attr(feature = "bindings", derive(TS))]
6588pub struct RowNumber;
6589
6590/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6592#[cfg_attr(feature = "bindings", derive(TS))]
6593pub struct Rank {
6594    /// DuckDB: RANK(ORDER BY col) - order by inside function
6595    #[serde(default, skip_serializing_if = "Option::is_none")]
6596    pub order_by: Option<Vec<Ordered>>,
6597    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6598    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6599    pub args: Vec<Expression>,
6600}
6601
6602/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6604#[cfg_attr(feature = "bindings", derive(TS))]
6605pub struct DenseRank {
6606    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6607    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6608    pub args: Vec<Expression>,
6609}
6610
6611/// NTILE function (DuckDB allows ORDER BY inside)
6612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6613#[cfg_attr(feature = "bindings", derive(TS))]
6614pub struct NTileFunc {
6615    /// num_buckets is optional to support Databricks NTILE() without arguments
6616    #[serde(default, skip_serializing_if = "Option::is_none")]
6617    pub num_buckets: Option<Expression>,
6618    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6619    #[serde(default, skip_serializing_if = "Option::is_none")]
6620    pub order_by: Option<Vec<Ordered>>,
6621}
6622
6623/// LEAD / LAG function
6624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6625#[cfg_attr(feature = "bindings", derive(TS))]
6626pub struct LeadLagFunc {
6627    pub this: Expression,
6628    pub offset: Option<Expression>,
6629    pub default: Option<Expression>,
6630    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6631    #[serde(default, skip_serializing_if = "Option::is_none")]
6632    pub ignore_nulls: Option<bool>,
6633}
6634
6635/// FIRST_VALUE / LAST_VALUE function
6636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6637#[cfg_attr(feature = "bindings", derive(TS))]
6638pub struct ValueFunc {
6639    pub this: Expression,
6640    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6641    #[serde(default, skip_serializing_if = "Option::is_none")]
6642    pub ignore_nulls: Option<bool>,
6643    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6644    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6645    pub order_by: Vec<Ordered>,
6646}
6647
6648/// NTH_VALUE function
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub struct NthValueFunc {
6652    pub this: Expression,
6653    pub offset: Expression,
6654    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6655    #[serde(default, skip_serializing_if = "Option::is_none")]
6656    pub ignore_nulls: Option<bool>,
6657    /// Snowflake FROM FIRST / FROM LAST clause
6658    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6659    #[serde(default, skip_serializing_if = "Option::is_none")]
6660    pub from_first: Option<bool>,
6661}
6662
6663/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6665#[cfg_attr(feature = "bindings", derive(TS))]
6666pub struct PercentRank {
6667    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6668    #[serde(default, skip_serializing_if = "Option::is_none")]
6669    pub order_by: Option<Vec<Ordered>>,
6670    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6671    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6672    pub args: Vec<Expression>,
6673}
6674
6675/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6677#[cfg_attr(feature = "bindings", derive(TS))]
6678pub struct CumeDist {
6679    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6680    #[serde(default, skip_serializing_if = "Option::is_none")]
6681    pub order_by: Option<Vec<Ordered>>,
6682    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6683    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6684    pub args: Vec<Expression>,
6685}
6686
6687// ============================================================================
6688// Additional String Function types
6689// ============================================================================
6690
6691/// POSITION/INSTR function
6692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6693#[cfg_attr(feature = "bindings", derive(TS))]
6694pub struct PositionFunc {
6695    pub substring: Expression,
6696    pub string: Expression,
6697    pub start: Option<Expression>,
6698}
6699
6700// ============================================================================
6701// Additional Math Function types
6702// ============================================================================
6703
6704/// RANDOM function (no arguments)
6705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6706#[cfg_attr(feature = "bindings", derive(TS))]
6707pub struct Random;
6708
6709/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6711#[cfg_attr(feature = "bindings", derive(TS))]
6712pub struct Rand {
6713    pub seed: Option<Box<Expression>>,
6714    /// Teradata RANDOM lower bound
6715    #[serde(default)]
6716    pub lower: Option<Box<Expression>>,
6717    /// Teradata RANDOM upper bound
6718    #[serde(default)]
6719    pub upper: Option<Box<Expression>>,
6720}
6721
6722/// TRUNCATE / TRUNC function
6723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6724#[cfg_attr(feature = "bindings", derive(TS))]
6725pub struct TruncateFunc {
6726    pub this: Expression,
6727    pub decimals: Option<Expression>,
6728}
6729
6730/// PI function (no arguments)
6731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6732#[cfg_attr(feature = "bindings", derive(TS))]
6733pub struct Pi;
6734
6735// ============================================================================
6736// Control Flow Function types
6737// ============================================================================
6738
6739/// DECODE function (Oracle style)
6740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6741#[cfg_attr(feature = "bindings", derive(TS))]
6742pub struct DecodeFunc {
6743    pub this: Expression,
6744    pub search_results: Vec<(Expression, Expression)>,
6745    pub default: Option<Expression>,
6746}
6747
6748// ============================================================================
6749// Additional Date/Time Function types
6750// ============================================================================
6751
6752/// DATE_FORMAT / FORMAT_DATE function
6753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6754#[cfg_attr(feature = "bindings", derive(TS))]
6755pub struct DateFormatFunc {
6756    pub this: Expression,
6757    pub format: Expression,
6758}
6759
6760/// FROM_UNIXTIME function
6761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6762#[cfg_attr(feature = "bindings", derive(TS))]
6763pub struct FromUnixtimeFunc {
6764    pub this: Expression,
6765    pub format: Option<Expression>,
6766}
6767
6768/// UNIX_TIMESTAMP function
6769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6770#[cfg_attr(feature = "bindings", derive(TS))]
6771pub struct UnixTimestampFunc {
6772    pub this: Option<Expression>,
6773    pub format: Option<Expression>,
6774}
6775
6776/// MAKE_DATE function
6777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6778#[cfg_attr(feature = "bindings", derive(TS))]
6779pub struct MakeDateFunc {
6780    pub year: Expression,
6781    pub month: Expression,
6782    pub day: Expression,
6783}
6784
6785/// MAKE_TIMESTAMP function
6786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6787#[cfg_attr(feature = "bindings", derive(TS))]
6788pub struct MakeTimestampFunc {
6789    pub year: Expression,
6790    pub month: Expression,
6791    pub day: Expression,
6792    pub hour: Expression,
6793    pub minute: Expression,
6794    pub second: Expression,
6795    pub timezone: Option<Expression>,
6796}
6797
6798/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6800#[cfg_attr(feature = "bindings", derive(TS))]
6801pub struct LastDayFunc {
6802    pub this: Expression,
6803    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6804    #[serde(skip_serializing_if = "Option::is_none", default)]
6805    pub unit: Option<DateTimeField>,
6806}
6807
6808// ============================================================================
6809// Array Function types
6810// ============================================================================
6811
6812/// ARRAY constructor
6813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6814#[cfg_attr(feature = "bindings", derive(TS))]
6815pub struct ArrayConstructor {
6816    pub expressions: Vec<Expression>,
6817    pub bracket_notation: bool,
6818    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6819    pub use_list_keyword: bool,
6820}
6821
6822/// ARRAY_SORT function
6823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6824#[cfg_attr(feature = "bindings", derive(TS))]
6825pub struct ArraySortFunc {
6826    pub this: Expression,
6827    pub comparator: Option<Expression>,
6828    pub desc: bool,
6829    pub nulls_first: Option<bool>,
6830}
6831
6832/// ARRAY_JOIN / ARRAY_TO_STRING function
6833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6834#[cfg_attr(feature = "bindings", derive(TS))]
6835pub struct ArrayJoinFunc {
6836    pub this: Expression,
6837    pub separator: Expression,
6838    pub null_replacement: Option<Expression>,
6839}
6840
6841/// UNNEST function
6842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6843#[cfg_attr(feature = "bindings", derive(TS))]
6844pub struct UnnestFunc {
6845    pub this: Expression,
6846    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6847    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6848    pub expressions: Vec<Expression>,
6849    pub with_ordinality: bool,
6850    pub alias: Option<Identifier>,
6851    /// BigQuery: offset alias for WITH OFFSET AS <name>
6852    #[serde(default, skip_serializing_if = "Option::is_none")]
6853    pub offset_alias: Option<Identifier>,
6854}
6855
6856/// ARRAY_FILTER function (with lambda)
6857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6858#[cfg_attr(feature = "bindings", derive(TS))]
6859pub struct ArrayFilterFunc {
6860    pub this: Expression,
6861    pub filter: Expression,
6862}
6863
6864/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6866#[cfg_attr(feature = "bindings", derive(TS))]
6867pub struct ArrayTransformFunc {
6868    pub this: Expression,
6869    pub transform: Expression,
6870}
6871
6872/// SEQUENCE / GENERATE_SERIES function
6873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6874#[cfg_attr(feature = "bindings", derive(TS))]
6875pub struct SequenceFunc {
6876    pub start: Expression,
6877    pub stop: Expression,
6878    pub step: Option<Expression>,
6879}
6880
6881// ============================================================================
6882// Struct Function types
6883// ============================================================================
6884
6885/// STRUCT constructor
6886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6887#[cfg_attr(feature = "bindings", derive(TS))]
6888pub struct StructConstructor {
6889    pub fields: Vec<(Option<Identifier>, Expression)>,
6890}
6891
6892/// STRUCT_EXTRACT function
6893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6894#[cfg_attr(feature = "bindings", derive(TS))]
6895pub struct StructExtractFunc {
6896    pub this: Expression,
6897    pub field: Identifier,
6898}
6899
6900/// NAMED_STRUCT function
6901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6902#[cfg_attr(feature = "bindings", derive(TS))]
6903pub struct NamedStructFunc {
6904    pub pairs: Vec<(Expression, Expression)>,
6905}
6906
6907// ============================================================================
6908// Map Function types
6909// ============================================================================
6910
6911/// MAP constructor
6912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6913#[cfg_attr(feature = "bindings", derive(TS))]
6914pub struct MapConstructor {
6915    pub keys: Vec<Expression>,
6916    pub values: Vec<Expression>,
6917    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6918    #[serde(default)]
6919    pub curly_brace_syntax: bool,
6920    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6921    #[serde(default)]
6922    pub with_map_keyword: bool,
6923}
6924
6925/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6927#[cfg_attr(feature = "bindings", derive(TS))]
6928pub struct TransformFunc {
6929    pub this: Expression,
6930    pub transform: Expression,
6931}
6932
6933/// Function call with EMITS clause (Exasol)
6934/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6936#[cfg_attr(feature = "bindings", derive(TS))]
6937pub struct FunctionEmits {
6938    /// The function call expression
6939    pub this: Expression,
6940    /// The EMITS schema definition
6941    pub emits: Expression,
6942}
6943
6944// ============================================================================
6945// JSON Function types
6946// ============================================================================
6947
6948/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6950#[cfg_attr(feature = "bindings", derive(TS))]
6951pub struct JsonExtractFunc {
6952    pub this: Expression,
6953    pub path: Expression,
6954    pub returning: Option<DataType>,
6955    /// True if parsed from -> or ->> operator syntax
6956    #[serde(default)]
6957    pub arrow_syntax: bool,
6958    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6959    #[serde(default)]
6960    pub hash_arrow_syntax: bool,
6961    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6962    #[serde(default)]
6963    pub wrapper_option: Option<String>,
6964    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6965    #[serde(default)]
6966    pub quotes_option: Option<String>,
6967    /// ON SCALAR STRING flag
6968    #[serde(default)]
6969    pub on_scalar_string: bool,
6970    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6971    #[serde(default)]
6972    pub on_error: Option<String>,
6973}
6974
6975/// JSON path extraction
6976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6977#[cfg_attr(feature = "bindings", derive(TS))]
6978pub struct JsonPathFunc {
6979    pub this: Expression,
6980    pub paths: Vec<Expression>,
6981}
6982
6983/// JSON_OBJECT function
6984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6985#[cfg_attr(feature = "bindings", derive(TS))]
6986pub struct JsonObjectFunc {
6987    pub pairs: Vec<(Expression, Expression)>,
6988    pub null_handling: Option<JsonNullHandling>,
6989    #[serde(default)]
6990    pub with_unique_keys: bool,
6991    #[serde(default)]
6992    pub returning_type: Option<DataType>,
6993    #[serde(default)]
6994    pub format_json: bool,
6995    #[serde(default)]
6996    pub encoding: Option<String>,
6997    /// For JSON_OBJECT(*) syntax
6998    #[serde(default)]
6999    pub star: bool,
7000}
7001
7002/// JSON null handling options
7003#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7004#[cfg_attr(feature = "bindings", derive(TS))]
7005pub enum JsonNullHandling {
7006    NullOnNull,
7007    AbsentOnNull,
7008}
7009
7010/// JSON_SET / JSON_INSERT function
7011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7012#[cfg_attr(feature = "bindings", derive(TS))]
7013pub struct JsonModifyFunc {
7014    pub this: Expression,
7015    pub path_values: Vec<(Expression, Expression)>,
7016}
7017
7018/// JSON_ARRAYAGG function
7019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7020#[cfg_attr(feature = "bindings", derive(TS))]
7021pub struct JsonArrayAggFunc {
7022    pub this: Expression,
7023    pub order_by: Option<Vec<Ordered>>,
7024    pub null_handling: Option<JsonNullHandling>,
7025    pub filter: Option<Expression>,
7026}
7027
7028/// JSON_OBJECTAGG function
7029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7030#[cfg_attr(feature = "bindings", derive(TS))]
7031pub struct JsonObjectAggFunc {
7032    pub key: Expression,
7033    pub value: Expression,
7034    pub null_handling: Option<JsonNullHandling>,
7035    pub filter: Option<Expression>,
7036}
7037
7038// ============================================================================
7039// Type Casting Function types
7040// ============================================================================
7041
7042/// CONVERT function (SQL Server style)
7043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7044#[cfg_attr(feature = "bindings", derive(TS))]
7045pub struct ConvertFunc {
7046    pub this: Expression,
7047    pub to: DataType,
7048    pub style: Option<Expression>,
7049}
7050
7051// ============================================================================
7052// Additional Expression types
7053// ============================================================================
7054
7055/// Lambda expression
7056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7057#[cfg_attr(feature = "bindings", derive(TS))]
7058pub struct LambdaExpr {
7059    pub parameters: Vec<Identifier>,
7060    pub body: Expression,
7061    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7062    #[serde(default)]
7063    pub colon: bool,
7064    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7065    /// Maps parameter index to data type
7066    #[serde(default)]
7067    pub parameter_types: Vec<Option<DataType>>,
7068}
7069
7070/// Parameter (parameterized queries)
7071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7072#[cfg_attr(feature = "bindings", derive(TS))]
7073pub struct Parameter {
7074    pub name: Option<String>,
7075    pub index: Option<u32>,
7076    pub style: ParameterStyle,
7077    /// Whether the name was quoted (e.g., @"x" vs @x)
7078    #[serde(default)]
7079    pub quoted: bool,
7080    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7081    #[serde(default)]
7082    pub string_quoted: bool,
7083    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7084    #[serde(default)]
7085    pub expression: Option<String>,
7086}
7087
7088/// Parameter placeholder styles
7089#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7090#[cfg_attr(feature = "bindings", derive(TS))]
7091pub enum ParameterStyle {
7092    Question,     // ?
7093    Dollar,       // $1, $2
7094    DollarBrace,  // ${name} (Databricks, Hive template variables)
7095    Brace,        // {name} (Spark/Databricks widget/template variables)
7096    Colon,        // :name
7097    At,           // @name
7098    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7099    DoubleDollar, // $$name
7100    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7101}
7102
7103/// Placeholder expression
7104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7105#[cfg_attr(feature = "bindings", derive(TS))]
7106pub struct Placeholder {
7107    pub index: Option<u32>,
7108}
7109
7110/// Named argument in function call: name => value or name := value
7111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7112#[cfg_attr(feature = "bindings", derive(TS))]
7113pub struct NamedArgument {
7114    pub name: Identifier,
7115    pub value: Expression,
7116    /// The separator used: `=>`, `:=`, or `=`
7117    pub separator: NamedArgSeparator,
7118}
7119
7120/// Separator style for named arguments
7121#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7122#[cfg_attr(feature = "bindings", derive(TS))]
7123pub enum NamedArgSeparator {
7124    /// `=>` (standard SQL, Snowflake, BigQuery)
7125    DArrow,
7126    /// `:=` (Oracle, MySQL)
7127    ColonEq,
7128    /// `=` (simple equals, some dialects)
7129    Eq,
7130}
7131
7132/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7133/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7135#[cfg_attr(feature = "bindings", derive(TS))]
7136pub struct TableArgument {
7137    /// The keyword prefix: "TABLE" or "MODEL"
7138    pub prefix: String,
7139    /// The table/model reference expression
7140    pub this: Expression,
7141}
7142
7143/// SQL Comment preservation
7144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7145#[cfg_attr(feature = "bindings", derive(TS))]
7146pub struct SqlComment {
7147    pub text: String,
7148    pub is_block: bool,
7149}
7150
7151// ============================================================================
7152// Additional Predicate types
7153// ============================================================================
7154
7155/// SIMILAR TO expression
7156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7157#[cfg_attr(feature = "bindings", derive(TS))]
7158pub struct SimilarToExpr {
7159    pub this: Expression,
7160    pub pattern: Expression,
7161    pub escape: Option<Expression>,
7162    pub not: bool,
7163}
7164
7165/// ANY / ALL quantified expression
7166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7167#[cfg_attr(feature = "bindings", derive(TS))]
7168pub struct QuantifiedExpr {
7169    pub this: Expression,
7170    pub subquery: Expression,
7171    pub op: Option<QuantifiedOp>,
7172}
7173
7174/// Comparison operator for quantified expressions
7175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7176#[cfg_attr(feature = "bindings", derive(TS))]
7177pub enum QuantifiedOp {
7178    Eq,
7179    Neq,
7180    Lt,
7181    Lte,
7182    Gt,
7183    Gte,
7184}
7185
7186/// OVERLAPS expression
7187/// Supports two forms:
7188/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7189/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7191#[cfg_attr(feature = "bindings", derive(TS))]
7192pub struct OverlapsExpr {
7193    /// Left operand for simple binary form
7194    #[serde(skip_serializing_if = "Option::is_none")]
7195    pub this: Option<Expression>,
7196    /// Right operand for simple binary form
7197    #[serde(skip_serializing_if = "Option::is_none")]
7198    pub expression: Option<Expression>,
7199    /// Left range start for full ANSI form
7200    #[serde(skip_serializing_if = "Option::is_none")]
7201    pub left_start: Option<Expression>,
7202    /// Left range end for full ANSI form
7203    #[serde(skip_serializing_if = "Option::is_none")]
7204    pub left_end: Option<Expression>,
7205    /// Right range start for full ANSI form
7206    #[serde(skip_serializing_if = "Option::is_none")]
7207    pub right_start: Option<Expression>,
7208    /// Right range end for full ANSI form
7209    #[serde(skip_serializing_if = "Option::is_none")]
7210    pub right_end: Option<Expression>,
7211}
7212
7213// ============================================================================
7214// Array/Struct/Map access
7215// ============================================================================
7216
7217/// Subscript access (array[index] or map[key])
7218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7219#[cfg_attr(feature = "bindings", derive(TS))]
7220pub struct Subscript {
7221    pub this: Expression,
7222    pub index: Expression,
7223}
7224
7225/// Dot access (struct.field)
7226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7227#[cfg_attr(feature = "bindings", derive(TS))]
7228pub struct DotAccess {
7229    pub this: Expression,
7230    pub field: Identifier,
7231}
7232
7233/// Method call (expr.method(args))
7234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7235#[cfg_attr(feature = "bindings", derive(TS))]
7236pub struct MethodCall {
7237    pub this: Expression,
7238    pub method: Identifier,
7239    pub args: Vec<Expression>,
7240}
7241
7242/// Array slice (array[start:end])
7243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7244#[cfg_attr(feature = "bindings", derive(TS))]
7245pub struct ArraySlice {
7246    pub this: Expression,
7247    pub start: Option<Expression>,
7248    pub end: Option<Expression>,
7249}
7250
7251// ============================================================================
7252// DDL (Data Definition Language) Statements
7253// ============================================================================
7254
7255/// ON COMMIT behavior for temporary tables
7256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7257#[cfg_attr(feature = "bindings", derive(TS))]
7258pub enum OnCommit {
7259    /// ON COMMIT PRESERVE ROWS
7260    PreserveRows,
7261    /// ON COMMIT DELETE ROWS
7262    DeleteRows,
7263}
7264
7265/// CREATE TABLE statement
7266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7267#[cfg_attr(feature = "bindings", derive(TS))]
7268pub struct CreateTable {
7269    pub name: TableRef,
7270    /// ClickHouse: ON CLUSTER clause for distributed DDL
7271    #[serde(default, skip_serializing_if = "Option::is_none")]
7272    pub on_cluster: Option<OnCluster>,
7273    pub columns: Vec<ColumnDef>,
7274    pub constraints: Vec<TableConstraint>,
7275    pub if_not_exists: bool,
7276    pub temporary: bool,
7277    pub or_replace: bool,
7278    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7279    #[serde(default, skip_serializing_if = "Option::is_none")]
7280    pub table_modifier: Option<String>,
7281    pub as_select: Option<Expression>,
7282    /// Whether the AS SELECT was wrapped in parentheses
7283    #[serde(default)]
7284    pub as_select_parenthesized: bool,
7285    /// ON COMMIT behavior for temporary tables
7286    #[serde(default)]
7287    pub on_commit: Option<OnCommit>,
7288    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7289    #[serde(default)]
7290    pub clone_source: Option<TableRef>,
7291    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7292    #[serde(default, skip_serializing_if = "Option::is_none")]
7293    pub clone_at_clause: Option<Expression>,
7294    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7295    #[serde(default)]
7296    pub is_copy: bool,
7297    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7298    #[serde(default)]
7299    pub shallow_clone: bool,
7300    /// Leading comments before the statement
7301    #[serde(default)]
7302    pub leading_comments: Vec<String>,
7303    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7304    #[serde(default)]
7305    pub with_properties: Vec<(String, String)>,
7306    /// Teradata: table options after name before columns (comma-separated)
7307    #[serde(default)]
7308    pub teradata_post_name_options: Vec<String>,
7309    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7310    #[serde(default)]
7311    pub with_data: Option<bool>,
7312    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7313    #[serde(default)]
7314    pub with_statistics: Option<bool>,
7315    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7316    #[serde(default)]
7317    pub teradata_indexes: Vec<TeradataIndex>,
7318    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7319    #[serde(default)]
7320    pub with_cte: Option<With>,
7321    /// Table properties like DEFAULT COLLATE (BigQuery)
7322    #[serde(default)]
7323    pub properties: Vec<Expression>,
7324    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7325    #[serde(default, skip_serializing_if = "Option::is_none")]
7326    pub partition_of: Option<Expression>,
7327    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7328    #[serde(default)]
7329    pub post_table_properties: Vec<Expression>,
7330    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7331    #[serde(default)]
7332    pub mysql_table_options: Vec<(String, String)>,
7333    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7334    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7335    pub inherits: Vec<TableRef>,
7336    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7337    #[serde(default, skip_serializing_if = "Option::is_none")]
7338    pub on_property: Option<OnProperty>,
7339    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7340    #[serde(default)]
7341    pub copy_grants: bool,
7342    /// Snowflake: USING TEMPLATE expression for schema inference
7343    #[serde(default, skip_serializing_if = "Option::is_none")]
7344    pub using_template: Option<Box<Expression>>,
7345    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7346    #[serde(default, skip_serializing_if = "Option::is_none")]
7347    pub rollup: Option<RollupProperty>,
7348    /// ClickHouse: UUID 'xxx' clause after table name
7349    #[serde(default, skip_serializing_if = "Option::is_none")]
7350    pub uuid: Option<String>,
7351    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7352    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7353    /// could appear in other engines.
7354    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7355    pub with_partition_columns: Vec<ColumnDef>,
7356    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7357    /// for external tables that reference a Cloud Resource connection.
7358    #[serde(default, skip_serializing_if = "Option::is_none")]
7359    pub with_connection: Option<TableRef>,
7360}
7361
7362/// Teradata index specification for CREATE TABLE
7363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7364#[cfg_attr(feature = "bindings", derive(TS))]
7365pub struct TeradataIndex {
7366    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7367    pub kind: TeradataIndexKind,
7368    /// Optional index name
7369    pub name: Option<String>,
7370    /// Optional column list
7371    pub columns: Vec<String>,
7372}
7373
7374/// Kind of Teradata index
7375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7376#[cfg_attr(feature = "bindings", derive(TS))]
7377pub enum TeradataIndexKind {
7378    /// NO PRIMARY INDEX
7379    NoPrimary,
7380    /// PRIMARY INDEX
7381    Primary,
7382    /// PRIMARY AMP INDEX
7383    PrimaryAmp,
7384    /// UNIQUE INDEX
7385    Unique,
7386    /// UNIQUE PRIMARY INDEX
7387    UniquePrimary,
7388    /// INDEX (secondary, non-primary)
7389    Secondary,
7390}
7391
7392impl CreateTable {
7393    pub fn new(name: impl Into<String>) -> Self {
7394        Self {
7395            name: TableRef::new(name),
7396            on_cluster: None,
7397            columns: Vec::new(),
7398            constraints: Vec::new(),
7399            if_not_exists: false,
7400            temporary: false,
7401            or_replace: false,
7402            table_modifier: None,
7403            as_select: None,
7404            as_select_parenthesized: false,
7405            on_commit: None,
7406            clone_source: None,
7407            clone_at_clause: None,
7408            shallow_clone: false,
7409            is_copy: false,
7410            leading_comments: Vec::new(),
7411            with_properties: Vec::new(),
7412            teradata_post_name_options: Vec::new(),
7413            with_data: None,
7414            with_statistics: None,
7415            teradata_indexes: Vec::new(),
7416            with_cte: None,
7417            properties: Vec::new(),
7418            partition_of: None,
7419            post_table_properties: Vec::new(),
7420            mysql_table_options: Vec::new(),
7421            inherits: Vec::new(),
7422            on_property: None,
7423            copy_grants: false,
7424            using_template: None,
7425            rollup: None,
7426            uuid: None,
7427            with_partition_columns: Vec::new(),
7428            with_connection: None,
7429        }
7430    }
7431}
7432
7433/// Sort order for PRIMARY KEY ASC/DESC
7434#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7435#[cfg_attr(feature = "bindings", derive(TS))]
7436pub enum SortOrder {
7437    Asc,
7438    Desc,
7439}
7440
7441/// Type of column constraint for tracking order
7442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7443#[cfg_attr(feature = "bindings", derive(TS))]
7444pub enum ConstraintType {
7445    NotNull,
7446    Null,
7447    PrimaryKey,
7448    Unique,
7449    Default,
7450    AutoIncrement,
7451    Collate,
7452    Comment,
7453    References,
7454    Check,
7455    GeneratedAsIdentity,
7456    /// Snowflake: TAG (key='value', ...)
7457    Tags,
7458    /// Computed/generated column
7459    ComputedColumn,
7460    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7461    GeneratedAsRow,
7462    /// MySQL: ON UPDATE expression
7463    OnUpdate,
7464    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7465    Path,
7466    /// Redshift: ENCODE encoding_type
7467    Encode,
7468}
7469
7470/// Column definition in CREATE TABLE
7471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7472#[cfg_attr(feature = "bindings", derive(TS))]
7473pub struct ColumnDef {
7474    pub name: Identifier,
7475    pub data_type: DataType,
7476    pub nullable: Option<bool>,
7477    pub default: Option<Expression>,
7478    pub primary_key: bool,
7479    /// Sort order for PRIMARY KEY (ASC/DESC)
7480    #[serde(default)]
7481    pub primary_key_order: Option<SortOrder>,
7482    pub unique: bool,
7483    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7484    #[serde(default)]
7485    pub unique_nulls_not_distinct: bool,
7486    pub auto_increment: bool,
7487    pub comment: Option<String>,
7488    pub constraints: Vec<ColumnConstraint>,
7489    /// Track original order of constraints for accurate regeneration
7490    #[serde(default)]
7491    pub constraint_order: Vec<ConstraintType>,
7492    /// Teradata: FORMAT 'pattern'
7493    #[serde(default)]
7494    pub format: Option<String>,
7495    /// Teradata: TITLE 'title'
7496    #[serde(default)]
7497    pub title: Option<String>,
7498    /// Teradata: INLINE LENGTH n
7499    #[serde(default)]
7500    pub inline_length: Option<u64>,
7501    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7502    #[serde(default)]
7503    pub compress: Option<Vec<Expression>>,
7504    /// Teradata: CHARACTER SET name
7505    #[serde(default)]
7506    pub character_set: Option<String>,
7507    /// Teradata: UPPERCASE
7508    #[serde(default)]
7509    pub uppercase: bool,
7510    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7511    #[serde(default)]
7512    pub casespecific: Option<bool>,
7513    /// Snowflake: AUTOINCREMENT START value
7514    #[serde(default)]
7515    pub auto_increment_start: Option<Box<Expression>>,
7516    /// Snowflake: AUTOINCREMENT INCREMENT value
7517    #[serde(default)]
7518    pub auto_increment_increment: Option<Box<Expression>>,
7519    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7520    #[serde(default)]
7521    pub auto_increment_order: Option<bool>,
7522    /// MySQL: UNSIGNED modifier
7523    #[serde(default)]
7524    pub unsigned: bool,
7525    /// MySQL: ZEROFILL modifier
7526    #[serde(default)]
7527    pub zerofill: bool,
7528    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7529    #[serde(default, skip_serializing_if = "Option::is_none")]
7530    pub on_update: Option<Expression>,
7531    /// MySQL: column VISIBLE/INVISIBLE modifier.
7532    #[serde(default, skip_serializing_if = "Option::is_none")]
7533    pub visible: Option<bool>,
7534    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7535    #[serde(default, skip_serializing_if = "Option::is_none")]
7536    pub unique_constraint_name: Option<String>,
7537    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7538    #[serde(default, skip_serializing_if = "Option::is_none")]
7539    pub not_null_constraint_name: Option<String>,
7540    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7541    #[serde(default, skip_serializing_if = "Option::is_none")]
7542    pub primary_key_constraint_name: Option<String>,
7543    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7544    #[serde(default, skip_serializing_if = "Option::is_none")]
7545    pub check_constraint_name: Option<String>,
7546    /// BigQuery: OPTIONS (key=value, ...) on column
7547    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7548    pub options: Vec<Expression>,
7549    /// SQLite: Column definition without explicit type
7550    #[serde(default)]
7551    pub no_type: bool,
7552    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7553    #[serde(default, skip_serializing_if = "Option::is_none")]
7554    pub encoding: Option<String>,
7555    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7556    #[serde(default, skip_serializing_if = "Option::is_none")]
7557    pub codec: Option<String>,
7558    /// ClickHouse: EPHEMERAL [expr] modifier
7559    #[serde(default, skip_serializing_if = "Option::is_none")]
7560    pub ephemeral: Option<Option<Box<Expression>>>,
7561    /// ClickHouse: MATERIALIZED expr modifier
7562    #[serde(default, skip_serializing_if = "Option::is_none")]
7563    pub materialized_expr: Option<Box<Expression>>,
7564    /// ClickHouse: ALIAS expr modifier
7565    #[serde(default, skip_serializing_if = "Option::is_none")]
7566    pub alias_expr: Option<Box<Expression>>,
7567    /// ClickHouse: TTL expr modifier on columns
7568    #[serde(default, skip_serializing_if = "Option::is_none")]
7569    pub ttl_expr: Option<Box<Expression>>,
7570    /// TSQL: NOT FOR REPLICATION
7571    #[serde(default)]
7572    pub not_for_replication: bool,
7573}
7574
7575impl ColumnDef {
7576    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7577        Self {
7578            name: Identifier::new(name),
7579            data_type,
7580            nullable: None,
7581            default: None,
7582            primary_key: false,
7583            primary_key_order: None,
7584            unique: false,
7585            unique_nulls_not_distinct: false,
7586            auto_increment: false,
7587            comment: None,
7588            constraints: Vec::new(),
7589            constraint_order: Vec::new(),
7590            format: None,
7591            title: None,
7592            inline_length: None,
7593            compress: None,
7594            character_set: None,
7595            uppercase: false,
7596            casespecific: None,
7597            auto_increment_start: None,
7598            auto_increment_increment: None,
7599            auto_increment_order: None,
7600            unsigned: false,
7601            zerofill: false,
7602            on_update: None,
7603            visible: None,
7604            unique_constraint_name: None,
7605            not_null_constraint_name: None,
7606            primary_key_constraint_name: None,
7607            check_constraint_name: None,
7608            options: Vec::new(),
7609            no_type: false,
7610            encoding: None,
7611            codec: None,
7612            ephemeral: None,
7613            materialized_expr: None,
7614            alias_expr: None,
7615            ttl_expr: None,
7616            not_for_replication: false,
7617        }
7618    }
7619}
7620
7621/// Column-level constraint
7622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7623#[cfg_attr(feature = "bindings", derive(TS))]
7624pub enum ColumnConstraint {
7625    NotNull,
7626    Null,
7627    Unique,
7628    PrimaryKey,
7629    Default(Expression),
7630    Check(Expression),
7631    References(ForeignKeyRef),
7632    GeneratedAsIdentity(GeneratedAsIdentity),
7633    Collate(Identifier),
7634    Comment(String),
7635    /// Snowflake: TAG (key='value', ...)
7636    Tags(Tags),
7637    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7638    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7639    ComputedColumn(ComputedColumn),
7640    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7641    GeneratedAsRow(GeneratedAsRow),
7642    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7643    Path(Expression),
7644}
7645
7646/// Computed/generated column constraint
7647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7648#[cfg_attr(feature = "bindings", derive(TS))]
7649pub struct ComputedColumn {
7650    /// The expression that computes the column value
7651    pub expression: Box<Expression>,
7652    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7653    #[serde(default)]
7654    pub persisted: bool,
7655    /// NOT NULL (TSQL computed columns)
7656    #[serde(default)]
7657    pub not_null: bool,
7658    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7659    /// When None, defaults to dialect-appropriate output
7660    #[serde(default)]
7661    pub persistence_kind: Option<String>,
7662    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7663    #[serde(default, skip_serializing_if = "Option::is_none")]
7664    pub data_type: Option<DataType>,
7665}
7666
7667/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7669#[cfg_attr(feature = "bindings", derive(TS))]
7670pub struct GeneratedAsRow {
7671    /// true = ROW START, false = ROW END
7672    pub start: bool,
7673    /// HIDDEN modifier
7674    #[serde(default)]
7675    pub hidden: bool,
7676}
7677
7678/// Generated identity column constraint
7679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7680#[cfg_attr(feature = "bindings", derive(TS))]
7681pub struct GeneratedAsIdentity {
7682    /// True for ALWAYS, False for BY DEFAULT
7683    pub always: bool,
7684    /// ON NULL (only valid with BY DEFAULT)
7685    pub on_null: bool,
7686    /// START WITH value
7687    pub start: Option<Box<Expression>>,
7688    /// INCREMENT BY value
7689    pub increment: Option<Box<Expression>>,
7690    /// MINVALUE
7691    pub minvalue: Option<Box<Expression>>,
7692    /// MAXVALUE
7693    pub maxvalue: Option<Box<Expression>>,
7694    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7695    pub cycle: Option<bool>,
7696}
7697
7698/// Constraint modifiers (shared between table-level constraints)
7699#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7700#[cfg_attr(feature = "bindings", derive(TS))]
7701pub struct ConstraintModifiers {
7702    /// ENFORCED / NOT ENFORCED
7703    pub enforced: Option<bool>,
7704    /// DEFERRABLE / NOT DEFERRABLE
7705    pub deferrable: Option<bool>,
7706    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7707    pub initially_deferred: Option<bool>,
7708    /// NORELY (Oracle)
7709    pub norely: bool,
7710    /// RELY (Oracle)
7711    pub rely: bool,
7712    /// USING index type (MySQL): BTREE or HASH
7713    #[serde(default)]
7714    pub using: Option<String>,
7715    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7716    #[serde(default)]
7717    pub using_before_columns: bool,
7718    /// MySQL index COMMENT 'text'
7719    #[serde(default, skip_serializing_if = "Option::is_none")]
7720    pub comment: Option<String>,
7721    /// MySQL index VISIBLE/INVISIBLE
7722    #[serde(default, skip_serializing_if = "Option::is_none")]
7723    pub visible: Option<bool>,
7724    /// MySQL ENGINE_ATTRIBUTE = 'value'
7725    #[serde(default, skip_serializing_if = "Option::is_none")]
7726    pub engine_attribute: Option<String>,
7727    /// MySQL WITH PARSER name
7728    #[serde(default, skip_serializing_if = "Option::is_none")]
7729    pub with_parser: Option<String>,
7730    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7731    #[serde(default)]
7732    pub not_valid: bool,
7733    /// TSQL CLUSTERED/NONCLUSTERED modifier
7734    #[serde(default, skip_serializing_if = "Option::is_none")]
7735    pub clustered: Option<String>,
7736    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7737    #[serde(default, skip_serializing_if = "Option::is_none")]
7738    pub on_conflict: Option<String>,
7739    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7740    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7741    pub with_options: Vec<(String, String)>,
7742    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7743    #[serde(default, skip_serializing_if = "Option::is_none")]
7744    pub on_filegroup: Option<Identifier>,
7745}
7746
7747/// Table-level constraint
7748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7749#[cfg_attr(feature = "bindings", derive(TS))]
7750pub enum TableConstraint {
7751    PrimaryKey {
7752        name: Option<Identifier>,
7753        columns: Vec<Identifier>,
7754        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7755        #[serde(default)]
7756        include_columns: Vec<Identifier>,
7757        #[serde(default)]
7758        modifiers: ConstraintModifiers,
7759        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7760        #[serde(default)]
7761        has_constraint_keyword: bool,
7762    },
7763    Unique {
7764        name: Option<Identifier>,
7765        columns: Vec<Identifier>,
7766        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7767        #[serde(default)]
7768        columns_parenthesized: bool,
7769        #[serde(default)]
7770        modifiers: ConstraintModifiers,
7771        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7772        #[serde(default)]
7773        has_constraint_keyword: bool,
7774        /// PostgreSQL 15+: NULLS NOT DISTINCT
7775        #[serde(default)]
7776        nulls_not_distinct: bool,
7777    },
7778    ForeignKey {
7779        name: Option<Identifier>,
7780        columns: Vec<Identifier>,
7781        #[serde(default)]
7782        references: Option<ForeignKeyRef>,
7783        /// ON DELETE action when REFERENCES is absent
7784        #[serde(default)]
7785        on_delete: Option<ReferentialAction>,
7786        /// ON UPDATE action when REFERENCES is absent
7787        #[serde(default)]
7788        on_update: Option<ReferentialAction>,
7789        #[serde(default)]
7790        modifiers: ConstraintModifiers,
7791    },
7792    Check {
7793        name: Option<Identifier>,
7794        expression: Expression,
7795        #[serde(default)]
7796        modifiers: ConstraintModifiers,
7797    },
7798    /// ClickHouse ASSUME constraint (query optimization assumption)
7799    Assume {
7800        name: Option<Identifier>,
7801        expression: Expression,
7802    },
7803    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7804    Default {
7805        name: Option<Identifier>,
7806        expression: Expression,
7807        column: Identifier,
7808    },
7809    /// INDEX / KEY constraint (MySQL)
7810    Index {
7811        name: Option<Identifier>,
7812        columns: Vec<Identifier>,
7813        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7814        #[serde(default)]
7815        kind: Option<String>,
7816        #[serde(default)]
7817        modifiers: ConstraintModifiers,
7818        /// True if KEY keyword was used instead of INDEX
7819        #[serde(default)]
7820        use_key_keyword: bool,
7821        /// ClickHouse: indexed expression (instead of columns)
7822        #[serde(default, skip_serializing_if = "Option::is_none")]
7823        expression: Option<Box<Expression>>,
7824        /// ClickHouse: TYPE type_func(args)
7825        #[serde(default, skip_serializing_if = "Option::is_none")]
7826        index_type: Option<Box<Expression>>,
7827        /// ClickHouse: GRANULARITY n
7828        #[serde(default, skip_serializing_if = "Option::is_none")]
7829        granularity: Option<Box<Expression>>,
7830    },
7831    /// ClickHouse PROJECTION definition
7832    Projection {
7833        name: Identifier,
7834        expression: Expression,
7835    },
7836    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7837    Like {
7838        source: TableRef,
7839        /// Options as (INCLUDING|EXCLUDING, property) pairs
7840        options: Vec<(LikeOptionAction, String)>,
7841    },
7842    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7843    PeriodForSystemTime {
7844        start_col: Identifier,
7845        end_col: Identifier,
7846    },
7847    /// PostgreSQL EXCLUDE constraint
7848    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7849    Exclude {
7850        name: Option<Identifier>,
7851        /// Index access method (gist, btree, etc.)
7852        #[serde(default)]
7853        using: Option<String>,
7854        /// Elements: (expression, operator) pairs
7855        elements: Vec<ExcludeElement>,
7856        /// INCLUDE columns
7857        #[serde(default)]
7858        include_columns: Vec<Identifier>,
7859        /// WHERE predicate
7860        #[serde(default)]
7861        where_clause: Option<Box<Expression>>,
7862        /// WITH (storage_parameters)
7863        #[serde(default)]
7864        with_params: Vec<(String, String)>,
7865        /// USING INDEX TABLESPACE tablespace_name
7866        #[serde(default)]
7867        using_index_tablespace: Option<String>,
7868        #[serde(default)]
7869        modifiers: ConstraintModifiers,
7870    },
7871    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7872    Tags(Tags),
7873    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7874    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7875    /// for all deferrable constraints in the table
7876    InitiallyDeferred {
7877        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7878        deferred: bool,
7879    },
7880}
7881
7882/// Element in an EXCLUDE constraint: expression WITH operator
7883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7884#[cfg_attr(feature = "bindings", derive(TS))]
7885pub struct ExcludeElement {
7886    /// The column expression (may include operator class, ordering, nulls)
7887    pub expression: String,
7888    /// The operator (e.g., &&, =)
7889    pub operator: String,
7890}
7891
7892/// Action for LIKE clause options
7893#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7894#[cfg_attr(feature = "bindings", derive(TS))]
7895pub enum LikeOptionAction {
7896    Including,
7897    Excluding,
7898}
7899
7900/// MATCH type for foreign keys
7901#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7902#[cfg_attr(feature = "bindings", derive(TS))]
7903pub enum MatchType {
7904    Full,
7905    Partial,
7906    Simple,
7907}
7908
7909/// Foreign key reference
7910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7911#[cfg_attr(feature = "bindings", derive(TS))]
7912pub struct ForeignKeyRef {
7913    pub table: TableRef,
7914    pub columns: Vec<Identifier>,
7915    pub on_delete: Option<ReferentialAction>,
7916    pub on_update: Option<ReferentialAction>,
7917    /// True if ON UPDATE appears before ON DELETE in the original SQL
7918    #[serde(default)]
7919    pub on_update_first: bool,
7920    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7921    #[serde(default)]
7922    pub match_type: Option<MatchType>,
7923    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7924    #[serde(default)]
7925    pub match_after_actions: bool,
7926    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7927    #[serde(default)]
7928    pub constraint_name: Option<String>,
7929    /// DEFERRABLE / NOT DEFERRABLE
7930    #[serde(default)]
7931    pub deferrable: Option<bool>,
7932    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7933    #[serde(default)]
7934    pub has_foreign_key_keywords: bool,
7935}
7936
7937/// Referential action for foreign keys
7938#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7939#[cfg_attr(feature = "bindings", derive(TS))]
7940pub enum ReferentialAction {
7941    Cascade,
7942    SetNull,
7943    SetDefault,
7944    Restrict,
7945    NoAction,
7946}
7947
7948/// DROP TABLE statement
7949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7950#[cfg_attr(feature = "bindings", derive(TS))]
7951pub struct DropTable {
7952    pub names: Vec<TableRef>,
7953    pub if_exists: bool,
7954    pub cascade: bool,
7955    /// Oracle: CASCADE CONSTRAINTS
7956    #[serde(default)]
7957    pub cascade_constraints: bool,
7958    /// Oracle: PURGE
7959    #[serde(default)]
7960    pub purge: bool,
7961    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7962    #[serde(default)]
7963    pub leading_comments: Vec<String>,
7964    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7965    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7966    #[serde(default, skip_serializing_if = "Option::is_none")]
7967    pub object_id_args: Option<String>,
7968    /// ClickHouse: SYNC modifier
7969    #[serde(default)]
7970    pub sync: bool,
7971    /// Snowflake: DROP ICEBERG TABLE
7972    #[serde(default)]
7973    pub iceberg: bool,
7974    /// RESTRICT modifier (opposite of CASCADE)
7975    #[serde(default)]
7976    pub restrict: bool,
7977}
7978
7979impl DropTable {
7980    pub fn new(name: impl Into<String>) -> Self {
7981        Self {
7982            names: vec![TableRef::new(name)],
7983            if_exists: false,
7984            cascade: false,
7985            cascade_constraints: false,
7986            purge: false,
7987            leading_comments: Vec::new(),
7988            object_id_args: None,
7989            sync: false,
7990            iceberg: false,
7991            restrict: false,
7992        }
7993    }
7994}
7995
7996/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
7997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7998#[cfg_attr(feature = "bindings", derive(TS))]
7999pub struct Undrop {
8000    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
8001    pub kind: String,
8002    /// The object name
8003    pub name: TableRef,
8004    /// IF EXISTS clause
8005    #[serde(default)]
8006    pub if_exists: bool,
8007}
8008
8009/// ALTER TABLE statement
8010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8011#[cfg_attr(feature = "bindings", derive(TS))]
8012pub struct AlterTable {
8013    pub name: TableRef,
8014    pub actions: Vec<AlterTableAction>,
8015    /// IF EXISTS clause
8016    #[serde(default)]
8017    pub if_exists: bool,
8018    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8019    #[serde(default, skip_serializing_if = "Option::is_none")]
8020    pub algorithm: Option<String>,
8021    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8022    #[serde(default, skip_serializing_if = "Option::is_none")]
8023    pub lock: Option<String>,
8024    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8025    #[serde(default, skip_serializing_if = "Option::is_none")]
8026    pub with_check: Option<String>,
8027    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8028    #[serde(default, skip_serializing_if = "Option::is_none")]
8029    pub partition: Option<Vec<(Identifier, Expression)>>,
8030    /// ClickHouse: ON CLUSTER clause for distributed DDL
8031    #[serde(default, skip_serializing_if = "Option::is_none")]
8032    pub on_cluster: Option<OnCluster>,
8033    /// Snowflake: ALTER ICEBERG TABLE
8034    #[serde(default, skip_serializing_if = "Option::is_none")]
8035    pub table_modifier: Option<String>,
8036}
8037
8038impl AlterTable {
8039    pub fn new(name: impl Into<String>) -> Self {
8040        Self {
8041            name: TableRef::new(name),
8042            actions: Vec::new(),
8043            if_exists: false,
8044            algorithm: None,
8045            lock: None,
8046            with_check: None,
8047            partition: None,
8048            on_cluster: None,
8049            table_modifier: None,
8050        }
8051    }
8052}
8053
8054/// Column position for ADD COLUMN (MySQL/MariaDB)
8055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8056#[cfg_attr(feature = "bindings", derive(TS))]
8057pub enum ColumnPosition {
8058    First,
8059    After(Identifier),
8060}
8061
8062/// Actions for ALTER TABLE
8063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8064#[cfg_attr(feature = "bindings", derive(TS))]
8065pub enum AlterTableAction {
8066    AddColumn {
8067        column: ColumnDef,
8068        if_not_exists: bool,
8069        position: Option<ColumnPosition>,
8070    },
8071    DropColumn {
8072        name: Identifier,
8073        if_exists: bool,
8074        cascade: bool,
8075    },
8076    RenameColumn {
8077        old_name: Identifier,
8078        new_name: Identifier,
8079        if_exists: bool,
8080    },
8081    AlterColumn {
8082        name: Identifier,
8083        action: AlterColumnAction,
8084        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8085        #[serde(default)]
8086        use_modify_keyword: bool,
8087    },
8088    RenameTable(TableRef),
8089    AddConstraint(TableConstraint),
8090    DropConstraint {
8091        name: Identifier,
8092        if_exists: bool,
8093    },
8094    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8095    DropForeignKey {
8096        name: Identifier,
8097    },
8098    /// DROP PARTITION action (Hive/BigQuery)
8099    DropPartition {
8100        /// List of partitions to drop (each partition is a list of key=value pairs)
8101        partitions: Vec<Vec<(Identifier, Expression)>>,
8102        if_exists: bool,
8103    },
8104    /// ADD PARTITION action (Hive/Spark)
8105    AddPartition {
8106        /// The partition expression
8107        partition: Expression,
8108        if_not_exists: bool,
8109        location: Option<Expression>,
8110    },
8111    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8112    Delete {
8113        where_clause: Expression,
8114    },
8115    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8116    SwapWith(TableRef),
8117    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8118    SetProperty {
8119        properties: Vec<(String, Expression)>,
8120    },
8121    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8122    UnsetProperty {
8123        properties: Vec<String>,
8124    },
8125    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8126    ClusterBy {
8127        expressions: Vec<Expression>,
8128    },
8129    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8130    SetTag {
8131        expressions: Vec<(String, Expression)>,
8132    },
8133    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8134    UnsetTag {
8135        names: Vec<String>,
8136    },
8137    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8138    SetOptions {
8139        expressions: Vec<Expression>,
8140    },
8141    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8142    AlterIndex {
8143        name: Identifier,
8144        visible: bool,
8145    },
8146    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8147    SetAttribute {
8148        attribute: String,
8149    },
8150    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8151    SetStageFileFormat {
8152        options: Option<Expression>,
8153    },
8154    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8155    SetStageCopyOptions {
8156        options: Option<Expression>,
8157    },
8158    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8159    AddColumns {
8160        columns: Vec<ColumnDef>,
8161        cascade: bool,
8162    },
8163    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8164    DropColumns {
8165        names: Vec<Identifier>,
8166    },
8167    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8168    /// In SingleStore, data_type can be omitted for simple column renames
8169    ChangeColumn {
8170        old_name: Identifier,
8171        new_name: Identifier,
8172        #[serde(default, skip_serializing_if = "Option::is_none")]
8173        data_type: Option<DataType>,
8174        comment: Option<String>,
8175        #[serde(default)]
8176        cascade: bool,
8177    },
8178    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8179    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8180    AlterSortKey {
8181        /// AUTO or NONE keyword
8182        this: Option<String>,
8183        /// Column list for (col1, col2) syntax
8184        expressions: Vec<Expression>,
8185        /// Whether COMPOUND keyword was present
8186        compound: bool,
8187    },
8188    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8189    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8190    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8191    AlterDistStyle {
8192        /// Distribution style: ALL, EVEN, AUTO, or KEY
8193        style: String,
8194        /// DISTKEY column (only when style is KEY)
8195        distkey: Option<Identifier>,
8196    },
8197    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8198    SetTableProperties {
8199        properties: Vec<(Expression, Expression)>,
8200    },
8201    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8202    SetLocation {
8203        location: String,
8204    },
8205    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8206    SetFileFormat {
8207        format: String,
8208    },
8209    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8210    ReplacePartition {
8211        partition: Expression,
8212        source: Option<Box<Expression>>,
8213    },
8214    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8215    Raw {
8216        sql: String,
8217    },
8218}
8219
8220/// Actions for ALTER COLUMN
8221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8222#[cfg_attr(feature = "bindings", derive(TS))]
8223pub enum AlterColumnAction {
8224    SetDataType {
8225        data_type: DataType,
8226        /// USING expression for type conversion (PostgreSQL)
8227        using: Option<Expression>,
8228        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8229        #[serde(default, skip_serializing_if = "Option::is_none")]
8230        collate: Option<String>,
8231    },
8232    SetDefault(Expression),
8233    DropDefault,
8234    SetNotNull,
8235    DropNotNull,
8236    /// Set column comment
8237    Comment(String),
8238    /// MySQL: SET VISIBLE
8239    SetVisible,
8240    /// MySQL: SET INVISIBLE
8241    SetInvisible,
8242}
8243
8244/// CREATE INDEX statement
8245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8246#[cfg_attr(feature = "bindings", derive(TS))]
8247pub struct CreateIndex {
8248    pub name: Identifier,
8249    pub table: TableRef,
8250    pub columns: Vec<IndexColumn>,
8251    pub unique: bool,
8252    pub if_not_exists: bool,
8253    pub using: Option<String>,
8254    /// TSQL CLUSTERED/NONCLUSTERED modifier
8255    #[serde(default)]
8256    pub clustered: Option<String>,
8257    /// PostgreSQL CONCURRENTLY modifier
8258    #[serde(default)]
8259    pub concurrently: bool,
8260    /// PostgreSQL WHERE clause for partial indexes
8261    #[serde(default)]
8262    pub where_clause: Option<Box<Expression>>,
8263    /// PostgreSQL INCLUDE columns
8264    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8265    pub include_columns: Vec<Identifier>,
8266    /// TSQL WITH options (e.g., allow_page_locks=on)
8267    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8268    pub with_options: Vec<(String, String)>,
8269    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8270    #[serde(default)]
8271    pub on_filegroup: Option<String>,
8272}
8273
8274impl CreateIndex {
8275    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8276        Self {
8277            name: Identifier::new(name),
8278            table: TableRef::new(table),
8279            columns: Vec::new(),
8280            unique: false,
8281            if_not_exists: false,
8282            using: None,
8283            clustered: None,
8284            concurrently: false,
8285            where_clause: None,
8286            include_columns: Vec::new(),
8287            with_options: Vec::new(),
8288            on_filegroup: None,
8289        }
8290    }
8291}
8292
8293/// Index column specification
8294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8295#[cfg_attr(feature = "bindings", derive(TS))]
8296pub struct IndexColumn {
8297    pub column: Identifier,
8298    pub desc: bool,
8299    /// Explicit ASC keyword was present
8300    #[serde(default)]
8301    pub asc: bool,
8302    pub nulls_first: Option<bool>,
8303    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8304    #[serde(default, skip_serializing_if = "Option::is_none")]
8305    pub opclass: Option<String>,
8306}
8307
8308/// DROP INDEX statement
8309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8310#[cfg_attr(feature = "bindings", derive(TS))]
8311pub struct DropIndex {
8312    pub name: Identifier,
8313    pub table: Option<TableRef>,
8314    pub if_exists: bool,
8315    /// PostgreSQL CONCURRENTLY modifier
8316    #[serde(default)]
8317    pub concurrently: bool,
8318}
8319
8320impl DropIndex {
8321    pub fn new(name: impl Into<String>) -> Self {
8322        Self {
8323            name: Identifier::new(name),
8324            table: None,
8325            if_exists: false,
8326            concurrently: false,
8327        }
8328    }
8329}
8330
8331/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8333#[cfg_attr(feature = "bindings", derive(TS))]
8334pub struct ViewColumn {
8335    pub name: Identifier,
8336    pub comment: Option<String>,
8337    /// BigQuery: OPTIONS (key=value, ...) on column
8338    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8339    pub options: Vec<Expression>,
8340}
8341
8342impl ViewColumn {
8343    pub fn new(name: impl Into<String>) -> Self {
8344        Self {
8345            name: Identifier::new(name),
8346            comment: None,
8347            options: Vec::new(),
8348        }
8349    }
8350
8351    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8352        Self {
8353            name: Identifier::new(name),
8354            comment: Some(comment.into()),
8355            options: Vec::new(),
8356        }
8357    }
8358}
8359
8360/// CREATE VIEW statement
8361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8362#[cfg_attr(feature = "bindings", derive(TS))]
8363pub struct CreateView {
8364    pub name: TableRef,
8365    pub columns: Vec<ViewColumn>,
8366    pub query: Expression,
8367    pub or_replace: bool,
8368    /// TSQL: CREATE OR ALTER
8369    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8370    pub or_alter: bool,
8371    pub if_not_exists: bool,
8372    pub materialized: bool,
8373    pub temporary: bool,
8374    /// Snowflake: SECURE VIEW
8375    #[serde(default)]
8376    pub secure: bool,
8377    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8378    #[serde(skip_serializing_if = "Option::is_none")]
8379    pub algorithm: Option<String>,
8380    /// MySQL: DEFINER=user@host
8381    #[serde(skip_serializing_if = "Option::is_none")]
8382    pub definer: Option<String>,
8383    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8384    #[serde(skip_serializing_if = "Option::is_none")]
8385    pub security: Option<FunctionSecurity>,
8386    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8387    #[serde(default = "default_true")]
8388    pub security_sql_style: bool,
8389    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8390    #[serde(default)]
8391    pub security_after_name: bool,
8392    /// Whether the query was parenthesized: AS (SELECT ...)
8393    #[serde(default)]
8394    pub query_parenthesized: bool,
8395    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8396    #[serde(skip_serializing_if = "Option::is_none")]
8397    pub locking_mode: Option<String>,
8398    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8399    #[serde(skip_serializing_if = "Option::is_none")]
8400    pub locking_access: Option<String>,
8401    /// Snowflake: COPY GRANTS
8402    #[serde(default)]
8403    pub copy_grants: bool,
8404    /// Snowflake: COMMENT = 'text'
8405    #[serde(skip_serializing_if = "Option::is_none", default)]
8406    pub comment: Option<String>,
8407    /// Snowflake: WITH ROW ACCESS POLICY ... clause
8408    #[serde(skip_serializing_if = "Option::is_none", default)]
8409    pub row_access_policy: Option<String>,
8410    /// Snowflake: TAG (name='value', ...)
8411    #[serde(default)]
8412    pub tags: Vec<(String, String)>,
8413    /// BigQuery: OPTIONS (key=value, ...)
8414    #[serde(default)]
8415    pub options: Vec<Expression>,
8416    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8417    #[serde(skip_serializing_if = "Option::is_none", default)]
8418    pub build: Option<String>,
8419    /// Doris: REFRESH property for materialized views
8420    #[serde(skip_serializing_if = "Option::is_none", default)]
8421    pub refresh: Option<Box<RefreshTriggerProperty>>,
8422    /// Doris: Schema with typed column definitions for materialized views
8423    /// This is used instead of `columns` when the view has typed column definitions
8424    #[serde(skip_serializing_if = "Option::is_none", default)]
8425    pub schema: Option<Box<Schema>>,
8426    /// Doris: KEY (columns) for materialized views
8427    #[serde(skip_serializing_if = "Option::is_none", default)]
8428    pub unique_key: Option<Box<UniqueKeyProperty>>,
8429    /// Redshift: WITH NO SCHEMA BINDING
8430    #[serde(default)]
8431    pub no_schema_binding: bool,
8432    /// Redshift: AUTO REFRESH YES|NO for materialized views
8433    #[serde(skip_serializing_if = "Option::is_none", default)]
8434    pub auto_refresh: Option<bool>,
8435    /// ClickHouse: ON CLUSTER clause
8436    #[serde(default, skip_serializing_if = "Option::is_none")]
8437    pub on_cluster: Option<OnCluster>,
8438    /// ClickHouse: TO destination_table
8439    #[serde(default, skip_serializing_if = "Option::is_none")]
8440    pub to_table: Option<TableRef>,
8441    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8442    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8443    pub table_properties: Vec<Expression>,
8444}
8445
8446impl CreateView {
8447    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8448        Self {
8449            name: TableRef::new(name),
8450            columns: Vec::new(),
8451            query,
8452            or_replace: false,
8453            or_alter: false,
8454            if_not_exists: false,
8455            materialized: false,
8456            temporary: false,
8457            secure: false,
8458            algorithm: None,
8459            definer: None,
8460            security: None,
8461            security_sql_style: true,
8462            security_after_name: false,
8463            query_parenthesized: false,
8464            locking_mode: None,
8465            locking_access: None,
8466            copy_grants: false,
8467            comment: None,
8468            row_access_policy: None,
8469            tags: Vec::new(),
8470            options: Vec::new(),
8471            build: None,
8472            refresh: None,
8473            schema: None,
8474            unique_key: None,
8475            no_schema_binding: false,
8476            auto_refresh: None,
8477            on_cluster: None,
8478            to_table: None,
8479            table_properties: Vec::new(),
8480        }
8481    }
8482}
8483
8484/// DROP VIEW statement
8485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8486#[cfg_attr(feature = "bindings", derive(TS))]
8487pub struct DropView {
8488    pub name: TableRef,
8489    pub if_exists: bool,
8490    pub materialized: bool,
8491}
8492
8493impl DropView {
8494    pub fn new(name: impl Into<String>) -> Self {
8495        Self {
8496            name: TableRef::new(name),
8497            if_exists: false,
8498            materialized: false,
8499        }
8500    }
8501}
8502
8503/// TRUNCATE TABLE statement
8504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8505#[cfg_attr(feature = "bindings", derive(TS))]
8506pub struct Truncate {
8507    /// Target of TRUNCATE (TABLE vs DATABASE)
8508    #[serde(default)]
8509    pub target: TruncateTarget,
8510    /// IF EXISTS clause
8511    #[serde(default)]
8512    pub if_exists: bool,
8513    pub table: TableRef,
8514    /// ClickHouse: ON CLUSTER clause for distributed DDL
8515    #[serde(default, skip_serializing_if = "Option::is_none")]
8516    pub on_cluster: Option<OnCluster>,
8517    pub cascade: bool,
8518    /// Additional tables for multi-table TRUNCATE
8519    #[serde(default)]
8520    pub extra_tables: Vec<TruncateTableEntry>,
8521    /// RESTART IDENTITY or CONTINUE IDENTITY
8522    #[serde(default)]
8523    pub identity: Option<TruncateIdentity>,
8524    /// RESTRICT option (alternative to CASCADE)
8525    #[serde(default)]
8526    pub restrict: bool,
8527    /// Hive PARTITION clause: PARTITION(key=value, ...)
8528    #[serde(default, skip_serializing_if = "Option::is_none")]
8529    pub partition: Option<Box<Expression>>,
8530}
8531
8532/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8534#[cfg_attr(feature = "bindings", derive(TS))]
8535pub struct TruncateTableEntry {
8536    pub table: TableRef,
8537    /// Whether the table has a * suffix (inherit children)
8538    #[serde(default)]
8539    pub star: bool,
8540}
8541
8542/// TRUNCATE target type
8543#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8544#[cfg_attr(feature = "bindings", derive(TS))]
8545pub enum TruncateTarget {
8546    Table,
8547    Database,
8548}
8549
8550impl Default for TruncateTarget {
8551    fn default() -> Self {
8552        TruncateTarget::Table
8553    }
8554}
8555
8556/// TRUNCATE identity option
8557#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8558#[cfg_attr(feature = "bindings", derive(TS))]
8559pub enum TruncateIdentity {
8560    Restart,
8561    Continue,
8562}
8563
8564impl Truncate {
8565    pub fn new(table: impl Into<String>) -> Self {
8566        Self {
8567            target: TruncateTarget::Table,
8568            if_exists: false,
8569            table: TableRef::new(table),
8570            on_cluster: None,
8571            cascade: false,
8572            extra_tables: Vec::new(),
8573            identity: None,
8574            restrict: false,
8575            partition: None,
8576        }
8577    }
8578}
8579
8580/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8582#[cfg_attr(feature = "bindings", derive(TS))]
8583pub struct Use {
8584    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8585    pub kind: Option<UseKind>,
8586    /// The name of the object
8587    pub this: Identifier,
8588}
8589
8590/// Kind of USE statement
8591#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8592#[cfg_attr(feature = "bindings", derive(TS))]
8593pub enum UseKind {
8594    Database,
8595    Schema,
8596    Role,
8597    Warehouse,
8598    Catalog,
8599    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8600    SecondaryRoles,
8601}
8602
8603/// SET variable statement
8604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8605#[cfg_attr(feature = "bindings", derive(TS))]
8606pub struct SetStatement {
8607    /// The items being set
8608    pub items: Vec<SetItem>,
8609}
8610
8611/// A single SET item (variable assignment)
8612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8613#[cfg_attr(feature = "bindings", derive(TS))]
8614pub struct SetItem {
8615    /// The variable name
8616    pub name: Expression,
8617    /// The value to set
8618    pub value: Expression,
8619    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8620    pub kind: Option<String>,
8621    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8622    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8623    pub no_equals: bool,
8624}
8625
8626/// CACHE TABLE statement (Spark)
8627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8628#[cfg_attr(feature = "bindings", derive(TS))]
8629pub struct Cache {
8630    /// The table to cache
8631    pub table: Identifier,
8632    /// LAZY keyword - defer caching until first use
8633    pub lazy: bool,
8634    /// Optional OPTIONS clause (key-value pairs)
8635    pub options: Vec<(Expression, Expression)>,
8636    /// Optional AS clause with query
8637    pub query: Option<Expression>,
8638}
8639
8640/// UNCACHE TABLE statement (Spark)
8641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8642#[cfg_attr(feature = "bindings", derive(TS))]
8643pub struct Uncache {
8644    /// The table to uncache
8645    pub table: Identifier,
8646    /// IF EXISTS clause
8647    pub if_exists: bool,
8648}
8649
8650/// LOAD DATA statement (Hive)
8651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8652#[cfg_attr(feature = "bindings", derive(TS))]
8653pub struct LoadData {
8654    /// LOCAL keyword - load from local filesystem
8655    pub local: bool,
8656    /// The path to load data from (INPATH value)
8657    pub inpath: String,
8658    /// Whether to overwrite existing data
8659    pub overwrite: bool,
8660    /// The target table
8661    pub table: Expression,
8662    /// Optional PARTITION clause with key-value pairs
8663    pub partition: Vec<(Identifier, Expression)>,
8664    /// Optional INPUTFORMAT clause
8665    pub input_format: Option<String>,
8666    /// Optional SERDE clause
8667    pub serde: Option<String>,
8668}
8669
8670/// PRAGMA statement (SQLite)
8671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8672#[cfg_attr(feature = "bindings", derive(TS))]
8673pub struct Pragma {
8674    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8675    pub schema: Option<Identifier>,
8676    /// The pragma name
8677    pub name: Identifier,
8678    /// Optional value for assignment (PRAGMA name = value)
8679    pub value: Option<Expression>,
8680    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8681    pub args: Vec<Expression>,
8682    /// Whether this pragma should be generated using assignment syntax.
8683    #[serde(default)]
8684    pub use_assignment_syntax: bool,
8685}
8686
8687/// A privilege with optional column list for GRANT/REVOKE
8688/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8690#[cfg_attr(feature = "bindings", derive(TS))]
8691pub struct Privilege {
8692    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8693    pub name: String,
8694    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8695    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8696    pub columns: Vec<String>,
8697}
8698
8699/// Principal in GRANT/REVOKE (user, role, etc.)
8700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8701#[cfg_attr(feature = "bindings", derive(TS))]
8702pub struct GrantPrincipal {
8703    /// The name of the principal
8704    pub name: Identifier,
8705    /// Whether prefixed with ROLE keyword
8706    pub is_role: bool,
8707    /// Whether prefixed with GROUP keyword (Redshift)
8708    #[serde(default)]
8709    pub is_group: bool,
8710    /// Whether prefixed with SHARE keyword (Snowflake)
8711    #[serde(default)]
8712    pub is_share: bool,
8713}
8714
8715/// GRANT statement
8716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8717#[cfg_attr(feature = "bindings", derive(TS))]
8718pub struct Grant {
8719    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8720    pub privileges: Vec<Privilege>,
8721    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8722    pub kind: Option<String>,
8723    /// The object to grant on
8724    pub securable: Identifier,
8725    /// Function parameter types (for FUNCTION kind)
8726    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8727    pub function_params: Vec<String>,
8728    /// The grantees
8729    pub principals: Vec<GrantPrincipal>,
8730    /// WITH GRANT OPTION
8731    pub grant_option: bool,
8732    /// TSQL: AS principal (the grantor role)
8733    #[serde(default, skip_serializing_if = "Option::is_none")]
8734    pub as_principal: Option<Identifier>,
8735}
8736
8737/// REVOKE statement
8738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8739#[cfg_attr(feature = "bindings", derive(TS))]
8740pub struct Revoke {
8741    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8742    pub privileges: Vec<Privilege>,
8743    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8744    pub kind: Option<String>,
8745    /// The object to revoke from
8746    pub securable: Identifier,
8747    /// Function parameter types (for FUNCTION kind)
8748    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8749    pub function_params: Vec<String>,
8750    /// The grantees
8751    pub principals: Vec<GrantPrincipal>,
8752    /// GRANT OPTION FOR
8753    pub grant_option: bool,
8754    /// CASCADE
8755    pub cascade: bool,
8756    /// RESTRICT
8757    #[serde(default)]
8758    pub restrict: bool,
8759}
8760
8761/// COMMENT ON statement
8762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8763#[cfg_attr(feature = "bindings", derive(TS))]
8764pub struct Comment {
8765    /// The object being commented on
8766    pub this: Expression,
8767    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8768    pub kind: String,
8769    /// The comment text expression
8770    pub expression: Expression,
8771    /// IF EXISTS clause
8772    pub exists: bool,
8773    /// MATERIALIZED keyword
8774    pub materialized: bool,
8775}
8776
8777// ============================================================================
8778// Phase 4: Additional DDL Statements
8779// ============================================================================
8780
8781/// ALTER VIEW statement
8782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8783#[cfg_attr(feature = "bindings", derive(TS))]
8784pub struct AlterView {
8785    pub name: TableRef,
8786    pub actions: Vec<AlterViewAction>,
8787    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8788    #[serde(default, skip_serializing_if = "Option::is_none")]
8789    pub algorithm: Option<String>,
8790    /// MySQL: DEFINER = 'user'@'host'
8791    #[serde(default, skip_serializing_if = "Option::is_none")]
8792    pub definer: Option<String>,
8793    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8794    #[serde(default, skip_serializing_if = "Option::is_none")]
8795    pub sql_security: Option<String>,
8796    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8797    #[serde(default, skip_serializing_if = "Option::is_none")]
8798    pub with_option: Option<String>,
8799    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8800    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8801    pub columns: Vec<ViewColumn>,
8802}
8803
8804/// Actions for ALTER VIEW
8805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8806#[cfg_attr(feature = "bindings", derive(TS))]
8807pub enum AlterViewAction {
8808    /// Rename the view
8809    Rename(TableRef),
8810    /// Change owner
8811    OwnerTo(Identifier),
8812    /// Set schema
8813    SetSchema(Identifier),
8814    /// Set authorization (Trino/Presto)
8815    SetAuthorization(String),
8816    /// Alter column
8817    AlterColumn {
8818        name: Identifier,
8819        action: AlterColumnAction,
8820    },
8821    /// Redefine view as query (SELECT, UNION, etc.)
8822    AsSelect(Box<Expression>),
8823    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8824    SetTblproperties(Vec<(String, String)>),
8825    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8826    UnsetTblproperties(Vec<String>),
8827}
8828
8829impl AlterView {
8830    pub fn new(name: impl Into<String>) -> Self {
8831        Self {
8832            name: TableRef::new(name),
8833            actions: Vec::new(),
8834            algorithm: None,
8835            definer: None,
8836            sql_security: None,
8837            with_option: None,
8838            columns: Vec::new(),
8839        }
8840    }
8841}
8842
8843/// ALTER INDEX statement
8844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8845#[cfg_attr(feature = "bindings", derive(TS))]
8846pub struct AlterIndex {
8847    pub name: Identifier,
8848    pub table: Option<TableRef>,
8849    pub actions: Vec<AlterIndexAction>,
8850}
8851
8852/// Actions for ALTER INDEX
8853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8854#[cfg_attr(feature = "bindings", derive(TS))]
8855pub enum AlterIndexAction {
8856    /// Rename the index
8857    Rename(Identifier),
8858    /// Set tablespace
8859    SetTablespace(Identifier),
8860    /// Set visibility (MySQL)
8861    Visible(bool),
8862}
8863
8864impl AlterIndex {
8865    pub fn new(name: impl Into<String>) -> Self {
8866        Self {
8867            name: Identifier::new(name),
8868            table: None,
8869            actions: Vec::new(),
8870        }
8871    }
8872}
8873
8874/// CREATE SCHEMA statement
8875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8876#[cfg_attr(feature = "bindings", derive(TS))]
8877pub struct CreateSchema {
8878    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8879    pub name: Vec<Identifier>,
8880    pub if_not_exists: bool,
8881    pub authorization: Option<Identifier>,
8882    /// CLONE source parts, possibly dot-qualified
8883    #[serde(default)]
8884    pub clone_from: Option<Vec<Identifier>>,
8885    /// AT/BEFORE clause for time travel (Snowflake)
8886    #[serde(default)]
8887    pub at_clause: Option<Expression>,
8888    /// Schema properties like DEFAULT COLLATE
8889    #[serde(default)]
8890    pub properties: Vec<Expression>,
8891    /// Leading comments before the statement
8892    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8893    pub leading_comments: Vec<String>,
8894}
8895
8896impl CreateSchema {
8897    pub fn new(name: impl Into<String>) -> Self {
8898        Self {
8899            name: vec![Identifier::new(name)],
8900            if_not_exists: false,
8901            authorization: None,
8902            clone_from: None,
8903            at_clause: None,
8904            properties: Vec::new(),
8905            leading_comments: Vec::new(),
8906        }
8907    }
8908}
8909
8910/// DROP SCHEMA statement
8911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8912#[cfg_attr(feature = "bindings", derive(TS))]
8913pub struct DropSchema {
8914    pub name: Identifier,
8915    pub if_exists: bool,
8916    pub cascade: bool,
8917}
8918
8919impl DropSchema {
8920    pub fn new(name: impl Into<String>) -> Self {
8921        Self {
8922            name: Identifier::new(name),
8923            if_exists: false,
8924            cascade: false,
8925        }
8926    }
8927}
8928
8929/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8931#[cfg_attr(feature = "bindings", derive(TS))]
8932pub struct DropNamespace {
8933    pub name: Identifier,
8934    pub if_exists: bool,
8935    pub cascade: bool,
8936}
8937
8938impl DropNamespace {
8939    pub fn new(name: impl Into<String>) -> Self {
8940        Self {
8941            name: Identifier::new(name),
8942            if_exists: false,
8943            cascade: false,
8944        }
8945    }
8946}
8947
8948/// CREATE DATABASE statement
8949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8950#[cfg_attr(feature = "bindings", derive(TS))]
8951pub struct CreateDatabase {
8952    pub name: Identifier,
8953    pub if_not_exists: bool,
8954    pub options: Vec<DatabaseOption>,
8955    /// Snowflake CLONE source
8956    #[serde(default)]
8957    pub clone_from: Option<Identifier>,
8958    /// AT/BEFORE clause for time travel (Snowflake)
8959    #[serde(default)]
8960    pub at_clause: Option<Expression>,
8961}
8962
8963/// Database option
8964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8965#[cfg_attr(feature = "bindings", derive(TS))]
8966pub enum DatabaseOption {
8967    CharacterSet(String),
8968    Collate(String),
8969    Owner(Identifier),
8970    Template(Identifier),
8971    Encoding(String),
8972    Location(String),
8973}
8974
8975impl CreateDatabase {
8976    pub fn new(name: impl Into<String>) -> Self {
8977        Self {
8978            name: Identifier::new(name),
8979            if_not_exists: false,
8980            options: Vec::new(),
8981            clone_from: None,
8982            at_clause: None,
8983        }
8984    }
8985}
8986
8987/// DROP DATABASE statement
8988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8989#[cfg_attr(feature = "bindings", derive(TS))]
8990pub struct DropDatabase {
8991    pub name: Identifier,
8992    pub if_exists: bool,
8993    /// ClickHouse: SYNC modifier
8994    #[serde(default)]
8995    pub sync: bool,
8996}
8997
8998impl DropDatabase {
8999    pub fn new(name: impl Into<String>) -> Self {
9000        Self {
9001            name: Identifier::new(name),
9002            if_exists: false,
9003            sync: false,
9004        }
9005    }
9006}
9007
9008/// CREATE FUNCTION statement
9009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9010#[cfg_attr(feature = "bindings", derive(TS))]
9011pub struct CreateFunction {
9012    pub name: TableRef,
9013    pub parameters: Vec<FunctionParameter>,
9014    pub return_type: Option<DataType>,
9015    pub body: Option<FunctionBody>,
9016    pub or_replace: bool,
9017    /// TSQL: CREATE OR ALTER
9018    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9019    pub or_alter: bool,
9020    pub if_not_exists: bool,
9021    pub temporary: bool,
9022    pub language: Option<String>,
9023    pub deterministic: Option<bool>,
9024    pub returns_null_on_null_input: Option<bool>,
9025    pub security: Option<FunctionSecurity>,
9026    /// Whether parentheses were present in the original syntax
9027    #[serde(default = "default_true")]
9028    pub has_parens: bool,
9029    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9030    #[serde(default)]
9031    pub sql_data_access: Option<SqlDataAccess>,
9032    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9033    #[serde(default, skip_serializing_if = "Option::is_none")]
9034    pub returns_table_body: Option<String>,
9035    /// True if LANGUAGE clause appears before RETURNS clause
9036    #[serde(default)]
9037    pub language_first: bool,
9038    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9039    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9040    pub set_options: Vec<FunctionSetOption>,
9041    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9042    #[serde(default)]
9043    pub strict: bool,
9044    /// BigQuery: OPTIONS (key=value, ...)
9045    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9046    pub options: Vec<Expression>,
9047    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9048    #[serde(default)]
9049    pub is_table_function: bool,
9050    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9051    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9052    pub property_order: Vec<FunctionPropertyKind>,
9053    /// Hive: USING JAR|FILE|ARCHIVE '...'
9054    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9055    pub using_resources: Vec<FunctionUsingResource>,
9056    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9057    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9058    pub environment: Vec<Expression>,
9059    /// HANDLER 'handler_function' clause (Databricks)
9060    #[serde(default, skip_serializing_if = "Option::is_none")]
9061    pub handler: Option<String>,
9062    /// True when the HANDLER clause used Snowflake-style `HANDLER = 'fn'`
9063    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9064    pub handler_uses_eq: bool,
9065    /// Snowflake: RUNTIME_VERSION='3.11'
9066    #[serde(default, skip_serializing_if = "Option::is_none")]
9067    pub runtime_version: Option<String>,
9068    /// Snowflake: PACKAGES=('pkg1', 'pkg2')
9069    #[serde(default, skip_serializing_if = "Option::is_none")]
9070    pub packages: Option<Vec<String>>,
9071    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9072    #[serde(default, skip_serializing_if = "Option::is_none")]
9073    pub parameter_style: Option<String>,
9074}
9075
9076/// A SET option in CREATE FUNCTION (PostgreSQL)
9077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9078#[cfg_attr(feature = "bindings", derive(TS))]
9079pub struct FunctionSetOption {
9080    pub name: String,
9081    pub value: FunctionSetValue,
9082}
9083
9084/// The value of a SET option
9085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9086#[cfg_attr(feature = "bindings", derive(TS))]
9087pub enum FunctionSetValue {
9088    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9089    Value { value: String, use_to: bool },
9090    /// SET key FROM CURRENT
9091    FromCurrent,
9092}
9093
9094/// SQL data access characteristics for functions
9095#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9096#[cfg_attr(feature = "bindings", derive(TS))]
9097pub enum SqlDataAccess {
9098    /// NO SQL
9099    NoSql,
9100    /// CONTAINS SQL
9101    ContainsSql,
9102    /// READS SQL DATA
9103    ReadsSqlData,
9104    /// MODIFIES SQL DATA
9105    ModifiesSqlData,
9106}
9107
9108/// Types of properties in CREATE FUNCTION for tracking their original order
9109#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9110#[cfg_attr(feature = "bindings", derive(TS))]
9111pub enum FunctionPropertyKind {
9112    /// SET option
9113    Set,
9114    /// AS body
9115    As,
9116    /// Hive: USING JAR|FILE|ARCHIVE ...
9117    Using,
9118    /// LANGUAGE clause
9119    Language,
9120    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9121    Determinism,
9122    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9123    NullInput,
9124    /// SECURITY DEFINER/INVOKER
9125    Security,
9126    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9127    SqlDataAccess,
9128    /// OPTIONS clause (BigQuery)
9129    Options,
9130    /// ENVIRONMENT clause (Databricks)
9131    Environment,
9132    /// HANDLER clause (Databricks)
9133    Handler,
9134    /// Snowflake: RUNTIME_VERSION='...'
9135    RuntimeVersion,
9136    /// Snowflake: PACKAGES=(...)
9137    Packages,
9138    /// PARAMETER STYLE clause (Databricks)
9139    ParameterStyle,
9140}
9141
9142/// Hive CREATE FUNCTION resource in a USING clause
9143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9144#[cfg_attr(feature = "bindings", derive(TS))]
9145pub struct FunctionUsingResource {
9146    pub kind: String,
9147    pub uri: String,
9148}
9149
9150/// Function parameter
9151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9152#[cfg_attr(feature = "bindings", derive(TS))]
9153pub struct FunctionParameter {
9154    pub name: Option<Identifier>,
9155    pub data_type: DataType,
9156    pub mode: Option<ParameterMode>,
9157    pub default: Option<Expression>,
9158    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9159    #[serde(default, skip_serializing_if = "Option::is_none")]
9160    pub mode_text: Option<String>,
9161}
9162
9163/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9164#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9165#[cfg_attr(feature = "bindings", derive(TS))]
9166pub enum ParameterMode {
9167    In,
9168    Out,
9169    InOut,
9170    Variadic,
9171}
9172
9173/// Function body
9174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9175#[cfg_attr(feature = "bindings", derive(TS))]
9176pub enum FunctionBody {
9177    /// AS $$ ... $$ (dollar-quoted)
9178    Block(String),
9179    /// AS 'string' (single-quoted string literal body)
9180    StringLiteral(String),
9181    /// AS 'expression'
9182    Expression(Expression),
9183    /// EXTERNAL NAME 'library'
9184    External(String),
9185    /// RETURN expression
9186    Return(Expression),
9187    /// BEGIN ... END block with parsed statements
9188    Statements(Vec<Expression>),
9189    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9190    /// Stores (content, optional_tag)
9191    DollarQuoted {
9192        content: String,
9193        tag: Option<String>,
9194    },
9195    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9196    RawBlock(String),
9197}
9198
9199/// Function security (DEFINER, INVOKER, or NONE)
9200#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9201#[cfg_attr(feature = "bindings", derive(TS))]
9202pub enum FunctionSecurity {
9203    Definer,
9204    Invoker,
9205    /// StarRocks/MySQL: SECURITY NONE
9206    None,
9207}
9208
9209impl CreateFunction {
9210    pub fn new(name: impl Into<String>) -> Self {
9211        Self {
9212            name: TableRef::new(name),
9213            parameters: Vec::new(),
9214            return_type: None,
9215            body: None,
9216            or_replace: false,
9217            or_alter: false,
9218            if_not_exists: false,
9219            temporary: false,
9220            language: None,
9221            deterministic: None,
9222            returns_null_on_null_input: None,
9223            security: None,
9224            has_parens: true,
9225            sql_data_access: None,
9226            returns_table_body: None,
9227            language_first: false,
9228            set_options: Vec::new(),
9229            strict: false,
9230            options: Vec::new(),
9231            is_table_function: false,
9232            property_order: Vec::new(),
9233            using_resources: Vec::new(),
9234            environment: Vec::new(),
9235            handler: None,
9236            handler_uses_eq: false,
9237            runtime_version: None,
9238            packages: None,
9239            parameter_style: None,
9240        }
9241    }
9242}
9243
9244/// DROP FUNCTION statement
9245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9246#[cfg_attr(feature = "bindings", derive(TS))]
9247pub struct DropFunction {
9248    pub name: TableRef,
9249    pub parameters: Option<Vec<DataType>>,
9250    pub if_exists: bool,
9251    pub cascade: bool,
9252}
9253
9254impl DropFunction {
9255    pub fn new(name: impl Into<String>) -> Self {
9256        Self {
9257            name: TableRef::new(name),
9258            parameters: None,
9259            if_exists: false,
9260            cascade: false,
9261        }
9262    }
9263}
9264
9265/// CREATE PROCEDURE statement
9266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9267#[cfg_attr(feature = "bindings", derive(TS))]
9268pub struct CreateProcedure {
9269    pub name: TableRef,
9270    pub parameters: Vec<FunctionParameter>,
9271    pub body: Option<FunctionBody>,
9272    pub or_replace: bool,
9273    /// TSQL: CREATE OR ALTER
9274    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9275    pub or_alter: bool,
9276    pub if_not_exists: bool,
9277    pub language: Option<String>,
9278    pub security: Option<FunctionSecurity>,
9279    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9280    #[serde(default)]
9281    pub return_type: Option<DataType>,
9282    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9283    #[serde(default)]
9284    pub execute_as: Option<String>,
9285    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9286    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9287    pub with_options: Vec<String>,
9288    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9289    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9290    pub has_parens: bool,
9291    /// Whether the short form PROC was used (instead of PROCEDURE)
9292    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9293    pub use_proc_keyword: bool,
9294}
9295
9296impl CreateProcedure {
9297    pub fn new(name: impl Into<String>) -> Self {
9298        Self {
9299            name: TableRef::new(name),
9300            parameters: Vec::new(),
9301            body: None,
9302            or_replace: false,
9303            or_alter: false,
9304            if_not_exists: false,
9305            language: None,
9306            security: None,
9307            return_type: None,
9308            execute_as: None,
9309            with_options: Vec::new(),
9310            has_parens: true,
9311            use_proc_keyword: false,
9312        }
9313    }
9314}
9315
9316/// DROP PROCEDURE statement
9317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9318#[cfg_attr(feature = "bindings", derive(TS))]
9319pub struct DropProcedure {
9320    pub name: TableRef,
9321    pub parameters: Option<Vec<DataType>>,
9322    pub if_exists: bool,
9323    pub cascade: bool,
9324}
9325
9326impl DropProcedure {
9327    pub fn new(name: impl Into<String>) -> Self {
9328        Self {
9329            name: TableRef::new(name),
9330            parameters: None,
9331            if_exists: false,
9332            cascade: false,
9333        }
9334    }
9335}
9336
9337/// Sequence property tag for ordering
9338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9339#[cfg_attr(feature = "bindings", derive(TS))]
9340pub enum SeqPropKind {
9341    Start,
9342    Increment,
9343    Minvalue,
9344    Maxvalue,
9345    Cache,
9346    NoCache,
9347    Cycle,
9348    NoCycle,
9349    OwnedBy,
9350    Order,
9351    NoOrder,
9352    Comment,
9353    /// SHARING=<value> (Oracle)
9354    Sharing,
9355    /// KEEP (Oracle)
9356    Keep,
9357    /// NOKEEP (Oracle)
9358    NoKeep,
9359    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9360    Scale,
9361    /// NOSCALE (Oracle)
9362    NoScale,
9363    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9364    Shard,
9365    /// NOSHARD (Oracle)
9366    NoShard,
9367    /// SESSION (Oracle)
9368    Session,
9369    /// GLOBAL (Oracle)
9370    Global,
9371    /// NOCACHE (single word, Oracle)
9372    NoCacheWord,
9373    /// NOCYCLE (single word, Oracle)
9374    NoCycleWord,
9375    /// NOMINVALUE (single word, Oracle)
9376    NoMinvalueWord,
9377    /// NOMAXVALUE (single word, Oracle)
9378    NoMaxvalueWord,
9379}
9380
9381/// CREATE SYNONYM statement (TSQL)
9382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9383#[cfg_attr(feature = "bindings", derive(TS))]
9384pub struct CreateSynonym {
9385    /// The synonym name (can be qualified: schema.synonym_name)
9386    pub name: TableRef,
9387    /// The target object the synonym refers to
9388    pub target: TableRef,
9389}
9390
9391/// CREATE SEQUENCE statement
9392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9393#[cfg_attr(feature = "bindings", derive(TS))]
9394pub struct CreateSequence {
9395    pub name: TableRef,
9396    pub if_not_exists: bool,
9397    pub temporary: bool,
9398    #[serde(default)]
9399    pub or_replace: bool,
9400    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9401    #[serde(default, skip_serializing_if = "Option::is_none")]
9402    pub as_type: Option<DataType>,
9403    pub increment: Option<i64>,
9404    pub minvalue: Option<SequenceBound>,
9405    pub maxvalue: Option<SequenceBound>,
9406    pub start: Option<i64>,
9407    pub cache: Option<i64>,
9408    pub cycle: bool,
9409    pub owned_by: Option<TableRef>,
9410    /// Whether OWNED BY NONE was specified
9411    #[serde(default)]
9412    pub owned_by_none: bool,
9413    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9414    #[serde(default)]
9415    pub order: Option<bool>,
9416    /// Snowflake: COMMENT = 'value'
9417    #[serde(default)]
9418    pub comment: Option<String>,
9419    /// SHARING=<value> (Oracle)
9420    #[serde(default, skip_serializing_if = "Option::is_none")]
9421    pub sharing: Option<String>,
9422    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9423    #[serde(default, skip_serializing_if = "Option::is_none")]
9424    pub scale_modifier: Option<String>,
9425    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9426    #[serde(default, skip_serializing_if = "Option::is_none")]
9427    pub shard_modifier: Option<String>,
9428    /// Tracks the order in which properties appeared in the source
9429    #[serde(default)]
9430    pub property_order: Vec<SeqPropKind>,
9431}
9432
9433/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9435#[cfg_attr(feature = "bindings", derive(TS))]
9436pub enum SequenceBound {
9437    Value(i64),
9438    None,
9439}
9440
9441impl CreateSequence {
9442    pub fn new(name: impl Into<String>) -> Self {
9443        Self {
9444            name: TableRef::new(name),
9445            if_not_exists: false,
9446            temporary: false,
9447            or_replace: false,
9448            as_type: None,
9449            increment: None,
9450            minvalue: None,
9451            maxvalue: None,
9452            start: None,
9453            cache: None,
9454            cycle: false,
9455            owned_by: None,
9456            owned_by_none: false,
9457            order: None,
9458            comment: None,
9459            sharing: None,
9460            scale_modifier: None,
9461            shard_modifier: None,
9462            property_order: Vec::new(),
9463        }
9464    }
9465}
9466
9467/// DROP SEQUENCE statement
9468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9469#[cfg_attr(feature = "bindings", derive(TS))]
9470pub struct DropSequence {
9471    pub name: TableRef,
9472    pub if_exists: bool,
9473    pub cascade: bool,
9474}
9475
9476impl DropSequence {
9477    pub fn new(name: impl Into<String>) -> Self {
9478        Self {
9479            name: TableRef::new(name),
9480            if_exists: false,
9481            cascade: false,
9482        }
9483    }
9484}
9485
9486/// ALTER SEQUENCE statement
9487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9488#[cfg_attr(feature = "bindings", derive(TS))]
9489pub struct AlterSequence {
9490    pub name: TableRef,
9491    pub if_exists: bool,
9492    pub increment: Option<i64>,
9493    pub minvalue: Option<SequenceBound>,
9494    pub maxvalue: Option<SequenceBound>,
9495    pub start: Option<i64>,
9496    pub restart: Option<Option<i64>>,
9497    pub cache: Option<i64>,
9498    pub cycle: Option<bool>,
9499    pub owned_by: Option<Option<TableRef>>,
9500}
9501
9502impl AlterSequence {
9503    pub fn new(name: impl Into<String>) -> Self {
9504        Self {
9505            name: TableRef::new(name),
9506            if_exists: false,
9507            increment: None,
9508            minvalue: None,
9509            maxvalue: None,
9510            start: None,
9511            restart: None,
9512            cache: None,
9513            cycle: None,
9514            owned_by: None,
9515        }
9516    }
9517}
9518
9519/// CREATE TRIGGER statement
9520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9521#[cfg_attr(feature = "bindings", derive(TS))]
9522pub struct CreateTrigger {
9523    pub name: Identifier,
9524    pub table: TableRef,
9525    pub timing: TriggerTiming,
9526    pub events: Vec<TriggerEvent>,
9527    #[serde(default, skip_serializing_if = "Option::is_none")]
9528    pub for_each: Option<TriggerForEach>,
9529    pub when: Option<Expression>,
9530    /// Whether the WHEN clause was parenthesized in the original SQL
9531    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9532    pub when_paren: bool,
9533    pub body: TriggerBody,
9534    pub or_replace: bool,
9535    /// TSQL: CREATE OR ALTER
9536    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9537    pub or_alter: bool,
9538    pub constraint: bool,
9539    pub deferrable: Option<bool>,
9540    pub initially_deferred: Option<bool>,
9541    pub referencing: Option<TriggerReferencing>,
9542}
9543
9544/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9545#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub enum TriggerTiming {
9548    Before,
9549    After,
9550    InsteadOf,
9551}
9552
9553/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9555#[cfg_attr(feature = "bindings", derive(TS))]
9556pub enum TriggerEvent {
9557    Insert,
9558    Update(Option<Vec<Identifier>>),
9559    Delete,
9560    Truncate,
9561}
9562
9563/// Trigger FOR EACH clause
9564#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9565#[cfg_attr(feature = "bindings", derive(TS))]
9566pub enum TriggerForEach {
9567    Row,
9568    Statement,
9569}
9570
9571/// Trigger body
9572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9573#[cfg_attr(feature = "bindings", derive(TS))]
9574pub enum TriggerBody {
9575    /// EXECUTE FUNCTION/PROCEDURE name(args)
9576    Execute {
9577        function: TableRef,
9578        args: Vec<Expression>,
9579    },
9580    /// BEGIN ... END block
9581    Block(String),
9582}
9583
9584/// Trigger REFERENCING clause
9585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9586#[cfg_attr(feature = "bindings", derive(TS))]
9587pub struct TriggerReferencing {
9588    pub old_table: Option<Identifier>,
9589    pub new_table: Option<Identifier>,
9590    pub old_row: Option<Identifier>,
9591    pub new_row: Option<Identifier>,
9592}
9593
9594impl CreateTrigger {
9595    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9596        Self {
9597            name: Identifier::new(name),
9598            table: TableRef::new(table),
9599            timing: TriggerTiming::Before,
9600            events: Vec::new(),
9601            for_each: Some(TriggerForEach::Row),
9602            when: None,
9603            when_paren: false,
9604            body: TriggerBody::Execute {
9605                function: TableRef::new(""),
9606                args: Vec::new(),
9607            },
9608            or_replace: false,
9609            or_alter: false,
9610            constraint: false,
9611            deferrable: None,
9612            initially_deferred: None,
9613            referencing: None,
9614        }
9615    }
9616}
9617
9618/// DROP TRIGGER statement
9619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9620#[cfg_attr(feature = "bindings", derive(TS))]
9621pub struct DropTrigger {
9622    pub name: Identifier,
9623    pub table: Option<TableRef>,
9624    pub if_exists: bool,
9625    pub cascade: bool,
9626}
9627
9628impl DropTrigger {
9629    pub fn new(name: impl Into<String>) -> Self {
9630        Self {
9631            name: Identifier::new(name),
9632            table: None,
9633            if_exists: false,
9634            cascade: false,
9635        }
9636    }
9637}
9638
9639/// CREATE TYPE statement
9640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9641#[cfg_attr(feature = "bindings", derive(TS))]
9642pub struct CreateType {
9643    pub name: TableRef,
9644    pub definition: TypeDefinition,
9645    pub if_not_exists: bool,
9646}
9647
9648/// Type definition
9649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9650#[cfg_attr(feature = "bindings", derive(TS))]
9651pub enum TypeDefinition {
9652    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9653    Enum(Vec<String>),
9654    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9655    Composite(Vec<TypeAttribute>),
9656    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9657    Range {
9658        subtype: DataType,
9659        subtype_diff: Option<String>,
9660        canonical: Option<String>,
9661    },
9662    /// Base type (for advanced usage)
9663    Base {
9664        input: String,
9665        output: String,
9666        internallength: Option<i32>,
9667    },
9668    /// Domain type
9669    Domain {
9670        base_type: DataType,
9671        default: Option<Expression>,
9672        constraints: Vec<DomainConstraint>,
9673    },
9674}
9675
9676/// Type attribute for composite types
9677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9678#[cfg_attr(feature = "bindings", derive(TS))]
9679pub struct TypeAttribute {
9680    pub name: Identifier,
9681    pub data_type: DataType,
9682    pub collate: Option<Identifier>,
9683}
9684
9685/// Domain constraint
9686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9687#[cfg_attr(feature = "bindings", derive(TS))]
9688pub struct DomainConstraint {
9689    pub name: Option<Identifier>,
9690    pub check: Expression,
9691}
9692
9693impl CreateType {
9694    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9695        Self {
9696            name: TableRef::new(name),
9697            definition: TypeDefinition::Enum(values),
9698            if_not_exists: false,
9699        }
9700    }
9701
9702    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9703        Self {
9704            name: TableRef::new(name),
9705            definition: TypeDefinition::Composite(attributes),
9706            if_not_exists: false,
9707        }
9708    }
9709}
9710
9711/// DROP TYPE statement
9712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9713#[cfg_attr(feature = "bindings", derive(TS))]
9714pub struct DropType {
9715    pub name: TableRef,
9716    pub if_exists: bool,
9717    pub cascade: bool,
9718}
9719
9720impl DropType {
9721    pub fn new(name: impl Into<String>) -> Self {
9722        Self {
9723            name: TableRef::new(name),
9724            if_exists: false,
9725            cascade: false,
9726        }
9727    }
9728}
9729
9730/// DESCRIBE statement - shows table structure or query plan
9731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9732#[cfg_attr(feature = "bindings", derive(TS))]
9733pub struct Describe {
9734    /// The target to describe (table name or query)
9735    pub target: Expression,
9736    /// EXTENDED format
9737    pub extended: bool,
9738    /// FORMATTED format
9739    pub formatted: bool,
9740    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9741    #[serde(default)]
9742    pub kind: Option<String>,
9743    /// Properties like type=stage
9744    #[serde(default)]
9745    pub properties: Vec<(String, String)>,
9746    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9747    #[serde(default, skip_serializing_if = "Option::is_none")]
9748    pub style: Option<String>,
9749    /// Partition specification for DESCRIBE PARTITION
9750    #[serde(default)]
9751    pub partition: Option<Box<Expression>>,
9752    /// Leading comments before the statement
9753    #[serde(default)]
9754    pub leading_comments: Vec<String>,
9755    /// AS JSON suffix (Databricks)
9756    #[serde(default)]
9757    pub as_json: bool,
9758    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9759    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9760    pub params: Vec<String>,
9761}
9762
9763impl Describe {
9764    pub fn new(target: Expression) -> Self {
9765        Self {
9766            target,
9767            extended: false,
9768            formatted: false,
9769            kind: None,
9770            properties: Vec::new(),
9771            style: None,
9772            partition: None,
9773            leading_comments: Vec::new(),
9774            as_json: false,
9775            params: Vec::new(),
9776        }
9777    }
9778}
9779
9780/// SHOW statement - displays database objects
9781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9782#[cfg_attr(feature = "bindings", derive(TS))]
9783pub struct Show {
9784    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9785    pub this: String,
9786    /// Whether TERSE was specified
9787    #[serde(default)]
9788    pub terse: bool,
9789    /// Whether HISTORY was specified
9790    #[serde(default)]
9791    pub history: bool,
9792    /// LIKE pattern
9793    pub like: Option<Expression>,
9794    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9795    pub scope_kind: Option<String>,
9796    /// IN scope object
9797    pub scope: Option<Expression>,
9798    /// STARTS WITH pattern
9799    pub starts_with: Option<Expression>,
9800    /// LIMIT clause
9801    pub limit: Option<Box<Limit>>,
9802    /// FROM clause (for specific object)
9803    pub from: Option<Expression>,
9804    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9805    #[serde(default, skip_serializing_if = "Option::is_none")]
9806    pub where_clause: Option<Expression>,
9807    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9808    #[serde(default, skip_serializing_if = "Option::is_none")]
9809    pub for_target: Option<Expression>,
9810    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9811    #[serde(default, skip_serializing_if = "Option::is_none")]
9812    pub db: Option<Expression>,
9813    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9814    #[serde(default, skip_serializing_if = "Option::is_none")]
9815    pub target: Option<Expression>,
9816    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9817    #[serde(default, skip_serializing_if = "Option::is_none")]
9818    pub mutex: Option<bool>,
9819    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9820    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9821    pub privileges: Vec<String>,
9822}
9823
9824impl Show {
9825    pub fn new(this: impl Into<String>) -> Self {
9826        Self {
9827            this: this.into(),
9828            terse: false,
9829            history: false,
9830            like: None,
9831            scope_kind: None,
9832            scope: None,
9833            starts_with: None,
9834            limit: None,
9835            from: None,
9836            where_clause: None,
9837            for_target: None,
9838            db: None,
9839            target: None,
9840            mutex: None,
9841            privileges: Vec::new(),
9842        }
9843    }
9844}
9845
9846/// Represent an explicit parenthesized expression for grouping precedence.
9847///
9848/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9849/// correctly instead of being flattened to `a + b * c`.
9850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9851#[cfg_attr(feature = "bindings", derive(TS))]
9852pub struct Paren {
9853    /// The inner expression wrapped by parentheses.
9854    pub this: Expression,
9855    #[serde(default)]
9856    pub trailing_comments: Vec<String>,
9857}
9858
9859/// Expression annotated with trailing comments (for round-trip preservation)
9860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9861#[cfg_attr(feature = "bindings", derive(TS))]
9862pub struct Annotated {
9863    pub this: Expression,
9864    pub trailing_comments: Vec<String>,
9865}
9866
9867// === BATCH GENERATED STRUCT DEFINITIONS ===
9868// Generated from Python sqlglot expressions.py
9869
9870/// Refresh
9871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9872#[cfg_attr(feature = "bindings", derive(TS))]
9873pub struct Refresh {
9874    pub this: Box<Expression>,
9875    pub kind: String,
9876}
9877
9878/// LockingStatement
9879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9880#[cfg_attr(feature = "bindings", derive(TS))]
9881pub struct LockingStatement {
9882    pub this: Box<Expression>,
9883    pub expression: Box<Expression>,
9884}
9885
9886/// SequenceProperties
9887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9888#[cfg_attr(feature = "bindings", derive(TS))]
9889pub struct SequenceProperties {
9890    #[serde(default)]
9891    pub increment: Option<Box<Expression>>,
9892    #[serde(default)]
9893    pub minvalue: Option<Box<Expression>>,
9894    #[serde(default)]
9895    pub maxvalue: Option<Box<Expression>>,
9896    #[serde(default)]
9897    pub cache: Option<Box<Expression>>,
9898    #[serde(default)]
9899    pub start: Option<Box<Expression>>,
9900    #[serde(default)]
9901    pub owned: Option<Box<Expression>>,
9902    #[serde(default)]
9903    pub options: Vec<Expression>,
9904}
9905
9906/// TruncateTable
9907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9908#[cfg_attr(feature = "bindings", derive(TS))]
9909pub struct TruncateTable {
9910    #[serde(default)]
9911    pub expressions: Vec<Expression>,
9912    #[serde(default)]
9913    pub is_database: Option<Box<Expression>>,
9914    #[serde(default)]
9915    pub exists: bool,
9916    #[serde(default)]
9917    pub only: Option<Box<Expression>>,
9918    #[serde(default)]
9919    pub cluster: Option<Box<Expression>>,
9920    #[serde(default)]
9921    pub identity: Option<Box<Expression>>,
9922    #[serde(default)]
9923    pub option: Option<Box<Expression>>,
9924    #[serde(default)]
9925    pub partition: Option<Box<Expression>>,
9926}
9927
9928/// Clone
9929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9930#[cfg_attr(feature = "bindings", derive(TS))]
9931pub struct Clone {
9932    pub this: Box<Expression>,
9933    #[serde(default)]
9934    pub shallow: Option<Box<Expression>>,
9935    #[serde(default)]
9936    pub copy: Option<Box<Expression>>,
9937}
9938
9939/// Attach
9940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9941#[cfg_attr(feature = "bindings", derive(TS))]
9942pub struct Attach {
9943    pub this: Box<Expression>,
9944    #[serde(default)]
9945    pub exists: bool,
9946    #[serde(default)]
9947    pub expressions: Vec<Expression>,
9948}
9949
9950/// Detach
9951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9952#[cfg_attr(feature = "bindings", derive(TS))]
9953pub struct Detach {
9954    pub this: Box<Expression>,
9955    #[serde(default)]
9956    pub exists: bool,
9957}
9958
9959/// Install
9960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9961#[cfg_attr(feature = "bindings", derive(TS))]
9962pub struct Install {
9963    pub this: Box<Expression>,
9964    #[serde(default)]
9965    pub from_: Option<Box<Expression>>,
9966    #[serde(default)]
9967    pub force: Option<Box<Expression>>,
9968}
9969
9970/// Summarize
9971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9972#[cfg_attr(feature = "bindings", derive(TS))]
9973pub struct Summarize {
9974    pub this: Box<Expression>,
9975    #[serde(default)]
9976    pub table: Option<Box<Expression>>,
9977}
9978
9979/// Declare
9980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9981#[cfg_attr(feature = "bindings", derive(TS))]
9982pub struct Declare {
9983    #[serde(default)]
9984    pub expressions: Vec<Expression>,
9985    #[serde(default)]
9986    pub replace: bool,
9987}
9988
9989/// DeclareItem
9990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9991#[cfg_attr(feature = "bindings", derive(TS))]
9992pub struct DeclareItem {
9993    pub this: Box<Expression>,
9994    #[serde(default)]
9995    pub kind: Option<String>,
9996    #[serde(default)]
9997    pub default: Option<Box<Expression>>,
9998    #[serde(default)]
9999    pub has_as: bool,
10000    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
10001    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10002    pub additional_names: Vec<Expression>,
10003}
10004
10005/// Set
10006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10007#[cfg_attr(feature = "bindings", derive(TS))]
10008pub struct Set {
10009    #[serde(default)]
10010    pub expressions: Vec<Expression>,
10011    #[serde(default)]
10012    pub unset: Option<Box<Expression>>,
10013    #[serde(default)]
10014    pub tag: Option<Box<Expression>>,
10015}
10016
10017/// Heredoc
10018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10019#[cfg_attr(feature = "bindings", derive(TS))]
10020pub struct Heredoc {
10021    pub this: Box<Expression>,
10022    #[serde(default)]
10023    pub tag: Option<Box<Expression>>,
10024}
10025
10026/// QueryBand
10027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10028#[cfg_attr(feature = "bindings", derive(TS))]
10029pub struct QueryBand {
10030    pub this: Box<Expression>,
10031    #[serde(default)]
10032    pub scope: Option<Box<Expression>>,
10033    #[serde(default)]
10034    pub update: Option<Box<Expression>>,
10035}
10036
10037/// UserDefinedFunction
10038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10039#[cfg_attr(feature = "bindings", derive(TS))]
10040pub struct UserDefinedFunction {
10041    pub this: Box<Expression>,
10042    #[serde(default)]
10043    pub expressions: Vec<Expression>,
10044    #[serde(default)]
10045    pub wrapped: Option<Box<Expression>>,
10046}
10047
10048/// RecursiveWithSearch
10049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10050#[cfg_attr(feature = "bindings", derive(TS))]
10051pub struct RecursiveWithSearch {
10052    pub kind: String,
10053    pub this: Box<Expression>,
10054    pub expression: Box<Expression>,
10055    #[serde(default)]
10056    pub using: Option<Box<Expression>>,
10057}
10058
10059/// ProjectionDef
10060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10061#[cfg_attr(feature = "bindings", derive(TS))]
10062pub struct ProjectionDef {
10063    pub this: Box<Expression>,
10064    pub expression: Box<Expression>,
10065}
10066
10067/// TableAlias
10068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10069#[cfg_attr(feature = "bindings", derive(TS))]
10070pub struct TableAlias {
10071    #[serde(default)]
10072    pub this: Option<Box<Expression>>,
10073    #[serde(default)]
10074    pub columns: Vec<Expression>,
10075}
10076
10077/// ByteString
10078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10079#[cfg_attr(feature = "bindings", derive(TS))]
10080pub struct ByteString {
10081    pub this: Box<Expression>,
10082    #[serde(default)]
10083    pub is_bytes: Option<Box<Expression>>,
10084}
10085
10086/// HexStringExpr - Hex string expression (not literal)
10087/// BigQuery: converts to FROM_HEX(this)
10088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10089#[cfg_attr(feature = "bindings", derive(TS))]
10090pub struct HexStringExpr {
10091    pub this: Box<Expression>,
10092    #[serde(default)]
10093    pub is_integer: Option<bool>,
10094}
10095
10096/// UnicodeString
10097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10098#[cfg_attr(feature = "bindings", derive(TS))]
10099pub struct UnicodeString {
10100    pub this: Box<Expression>,
10101    #[serde(default)]
10102    pub escape: Option<Box<Expression>>,
10103}
10104
10105/// AlterColumn
10106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10107#[cfg_attr(feature = "bindings", derive(TS))]
10108pub struct AlterColumn {
10109    pub this: Box<Expression>,
10110    #[serde(default)]
10111    pub dtype: Option<Box<Expression>>,
10112    #[serde(default)]
10113    pub collate: Option<Box<Expression>>,
10114    #[serde(default)]
10115    pub using: Option<Box<Expression>>,
10116    #[serde(default)]
10117    pub default: Option<Box<Expression>>,
10118    #[serde(default)]
10119    pub drop: Option<Box<Expression>>,
10120    #[serde(default)]
10121    pub comment: Option<Box<Expression>>,
10122    #[serde(default)]
10123    pub allow_null: Option<Box<Expression>>,
10124    #[serde(default)]
10125    pub visible: Option<Box<Expression>>,
10126    #[serde(default)]
10127    pub rename_to: Option<Box<Expression>>,
10128}
10129
10130/// AlterSortKey
10131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10132#[cfg_attr(feature = "bindings", derive(TS))]
10133pub struct AlterSortKey {
10134    #[serde(default)]
10135    pub this: Option<Box<Expression>>,
10136    #[serde(default)]
10137    pub expressions: Vec<Expression>,
10138    #[serde(default)]
10139    pub compound: Option<Box<Expression>>,
10140}
10141
10142/// AlterSet
10143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10144#[cfg_attr(feature = "bindings", derive(TS))]
10145pub struct AlterSet {
10146    #[serde(default)]
10147    pub expressions: Vec<Expression>,
10148    #[serde(default)]
10149    pub option: Option<Box<Expression>>,
10150    #[serde(default)]
10151    pub tablespace: Option<Box<Expression>>,
10152    #[serde(default)]
10153    pub access_method: Option<Box<Expression>>,
10154    #[serde(default)]
10155    pub file_format: Option<Box<Expression>>,
10156    #[serde(default)]
10157    pub copy_options: Option<Box<Expression>>,
10158    #[serde(default)]
10159    pub tag: Option<Box<Expression>>,
10160    #[serde(default)]
10161    pub location: Option<Box<Expression>>,
10162    #[serde(default)]
10163    pub serde: Option<Box<Expression>>,
10164}
10165
10166/// RenameColumn
10167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10168#[cfg_attr(feature = "bindings", derive(TS))]
10169pub struct RenameColumn {
10170    pub this: Box<Expression>,
10171    #[serde(default)]
10172    pub to: Option<Box<Expression>>,
10173    #[serde(default)]
10174    pub exists: bool,
10175}
10176
10177/// Comprehension
10178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10179#[cfg_attr(feature = "bindings", derive(TS))]
10180pub struct Comprehension {
10181    pub this: Box<Expression>,
10182    pub expression: Box<Expression>,
10183    #[serde(default)]
10184    pub position: Option<Box<Expression>>,
10185    #[serde(default)]
10186    pub iterator: Option<Box<Expression>>,
10187    #[serde(default)]
10188    pub condition: Option<Box<Expression>>,
10189}
10190
10191/// MergeTreeTTLAction
10192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10193#[cfg_attr(feature = "bindings", derive(TS))]
10194pub struct MergeTreeTTLAction {
10195    pub this: Box<Expression>,
10196    #[serde(default)]
10197    pub delete: Option<Box<Expression>>,
10198    #[serde(default)]
10199    pub recompress: Option<Box<Expression>>,
10200    #[serde(default)]
10201    pub to_disk: Option<Box<Expression>>,
10202    #[serde(default)]
10203    pub to_volume: Option<Box<Expression>>,
10204}
10205
10206/// MergeTreeTTL
10207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10208#[cfg_attr(feature = "bindings", derive(TS))]
10209pub struct MergeTreeTTL {
10210    #[serde(default)]
10211    pub expressions: Vec<Expression>,
10212    #[serde(default)]
10213    pub where_: Option<Box<Expression>>,
10214    #[serde(default)]
10215    pub group: Option<Box<Expression>>,
10216    #[serde(default)]
10217    pub aggregates: Option<Box<Expression>>,
10218}
10219
10220/// IndexConstraintOption
10221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10222#[cfg_attr(feature = "bindings", derive(TS))]
10223pub struct IndexConstraintOption {
10224    #[serde(default)]
10225    pub key_block_size: Option<Box<Expression>>,
10226    #[serde(default)]
10227    pub using: Option<Box<Expression>>,
10228    #[serde(default)]
10229    pub parser: Option<Box<Expression>>,
10230    #[serde(default)]
10231    pub comment: Option<Box<Expression>>,
10232    #[serde(default)]
10233    pub visible: Option<Box<Expression>>,
10234    #[serde(default)]
10235    pub engine_attr: Option<Box<Expression>>,
10236    #[serde(default)]
10237    pub secondary_engine_attr: Option<Box<Expression>>,
10238}
10239
10240/// PeriodForSystemTimeConstraint
10241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10242#[cfg_attr(feature = "bindings", derive(TS))]
10243pub struct PeriodForSystemTimeConstraint {
10244    pub this: Box<Expression>,
10245    pub expression: Box<Expression>,
10246}
10247
10248/// CaseSpecificColumnConstraint
10249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10250#[cfg_attr(feature = "bindings", derive(TS))]
10251pub struct CaseSpecificColumnConstraint {
10252    #[serde(default)]
10253    pub not_: Option<Box<Expression>>,
10254}
10255
10256/// CharacterSetColumnConstraint
10257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10258#[cfg_attr(feature = "bindings", derive(TS))]
10259pub struct CharacterSetColumnConstraint {
10260    pub this: Box<Expression>,
10261}
10262
10263/// CheckColumnConstraint
10264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10265#[cfg_attr(feature = "bindings", derive(TS))]
10266pub struct CheckColumnConstraint {
10267    pub this: Box<Expression>,
10268    #[serde(default)]
10269    pub enforced: Option<Box<Expression>>,
10270}
10271
10272/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10274#[cfg_attr(feature = "bindings", derive(TS))]
10275pub struct AssumeColumnConstraint {
10276    pub this: Box<Expression>,
10277}
10278
10279/// CompressColumnConstraint
10280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10281#[cfg_attr(feature = "bindings", derive(TS))]
10282pub struct CompressColumnConstraint {
10283    #[serde(default)]
10284    pub this: Option<Box<Expression>>,
10285}
10286
10287/// DateFormatColumnConstraint
10288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10289#[cfg_attr(feature = "bindings", derive(TS))]
10290pub struct DateFormatColumnConstraint {
10291    pub this: Box<Expression>,
10292}
10293
10294/// EphemeralColumnConstraint
10295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10296#[cfg_attr(feature = "bindings", derive(TS))]
10297pub struct EphemeralColumnConstraint {
10298    #[serde(default)]
10299    pub this: Option<Box<Expression>>,
10300}
10301
10302/// WithOperator
10303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10304#[cfg_attr(feature = "bindings", derive(TS))]
10305pub struct WithOperator {
10306    pub this: Box<Expression>,
10307    pub op: String,
10308}
10309
10310/// GeneratedAsIdentityColumnConstraint
10311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10312#[cfg_attr(feature = "bindings", derive(TS))]
10313pub struct GeneratedAsIdentityColumnConstraint {
10314    #[serde(default)]
10315    pub this: Option<Box<Expression>>,
10316    #[serde(default)]
10317    pub expression: Option<Box<Expression>>,
10318    #[serde(default)]
10319    pub on_null: Option<Box<Expression>>,
10320    #[serde(default)]
10321    pub start: Option<Box<Expression>>,
10322    #[serde(default)]
10323    pub increment: Option<Box<Expression>>,
10324    #[serde(default)]
10325    pub minvalue: Option<Box<Expression>>,
10326    #[serde(default)]
10327    pub maxvalue: Option<Box<Expression>>,
10328    #[serde(default)]
10329    pub cycle: Option<Box<Expression>>,
10330    #[serde(default)]
10331    pub order: Option<Box<Expression>>,
10332}
10333
10334/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10335/// TSQL: outputs "IDENTITY"
10336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10337#[cfg_attr(feature = "bindings", derive(TS))]
10338pub struct AutoIncrementColumnConstraint;
10339
10340/// CommentColumnConstraint - Column comment marker
10341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10342#[cfg_attr(feature = "bindings", derive(TS))]
10343pub struct CommentColumnConstraint;
10344
10345/// GeneratedAsRowColumnConstraint
10346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10347#[cfg_attr(feature = "bindings", derive(TS))]
10348pub struct GeneratedAsRowColumnConstraint {
10349    #[serde(default)]
10350    pub start: Option<Box<Expression>>,
10351    #[serde(default)]
10352    pub hidden: Option<Box<Expression>>,
10353}
10354
10355/// IndexColumnConstraint
10356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10357#[cfg_attr(feature = "bindings", derive(TS))]
10358pub struct IndexColumnConstraint {
10359    #[serde(default)]
10360    pub this: Option<Box<Expression>>,
10361    #[serde(default)]
10362    pub expressions: Vec<Expression>,
10363    #[serde(default)]
10364    pub kind: Option<String>,
10365    #[serde(default)]
10366    pub index_type: Option<Box<Expression>>,
10367    #[serde(default)]
10368    pub options: Vec<Expression>,
10369    #[serde(default)]
10370    pub expression: Option<Box<Expression>>,
10371    #[serde(default)]
10372    pub granularity: Option<Box<Expression>>,
10373}
10374
10375/// MaskingPolicyColumnConstraint
10376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10377#[cfg_attr(feature = "bindings", derive(TS))]
10378pub struct MaskingPolicyColumnConstraint {
10379    pub this: Box<Expression>,
10380    #[serde(default)]
10381    pub expressions: Vec<Expression>,
10382}
10383
10384/// NotNullColumnConstraint
10385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10386#[cfg_attr(feature = "bindings", derive(TS))]
10387pub struct NotNullColumnConstraint {
10388    #[serde(default)]
10389    pub allow_null: Option<Box<Expression>>,
10390}
10391
10392/// DefaultColumnConstraint - DEFAULT value for a column
10393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10394#[cfg_attr(feature = "bindings", derive(TS))]
10395pub struct DefaultColumnConstraint {
10396    pub this: Box<Expression>,
10397    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10398    #[serde(default, skip_serializing_if = "Option::is_none")]
10399    pub for_column: Option<Identifier>,
10400}
10401
10402/// PrimaryKeyColumnConstraint
10403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10404#[cfg_attr(feature = "bindings", derive(TS))]
10405pub struct PrimaryKeyColumnConstraint {
10406    #[serde(default)]
10407    pub desc: Option<Box<Expression>>,
10408    #[serde(default)]
10409    pub options: Vec<Expression>,
10410}
10411
10412/// UniqueColumnConstraint
10413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10414#[cfg_attr(feature = "bindings", derive(TS))]
10415pub struct UniqueColumnConstraint {
10416    #[serde(default)]
10417    pub this: Option<Box<Expression>>,
10418    #[serde(default)]
10419    pub index_type: Option<Box<Expression>>,
10420    #[serde(default)]
10421    pub on_conflict: Option<Box<Expression>>,
10422    #[serde(default)]
10423    pub nulls: Option<Box<Expression>>,
10424    #[serde(default)]
10425    pub options: Vec<Expression>,
10426}
10427
10428/// WatermarkColumnConstraint
10429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10430#[cfg_attr(feature = "bindings", derive(TS))]
10431pub struct WatermarkColumnConstraint {
10432    pub this: Box<Expression>,
10433    pub expression: Box<Expression>,
10434}
10435
10436/// ComputedColumnConstraint
10437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10438#[cfg_attr(feature = "bindings", derive(TS))]
10439pub struct ComputedColumnConstraint {
10440    pub this: Box<Expression>,
10441    #[serde(default)]
10442    pub persisted: Option<Box<Expression>>,
10443    #[serde(default)]
10444    pub not_null: Option<Box<Expression>>,
10445    #[serde(default)]
10446    pub data_type: Option<Box<Expression>>,
10447}
10448
10449/// InOutColumnConstraint
10450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10451#[cfg_attr(feature = "bindings", derive(TS))]
10452pub struct InOutColumnConstraint {
10453    #[serde(default)]
10454    pub input_: Option<Box<Expression>>,
10455    #[serde(default)]
10456    pub output: Option<Box<Expression>>,
10457}
10458
10459/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10461#[cfg_attr(feature = "bindings", derive(TS))]
10462pub struct PathColumnConstraint {
10463    pub this: Box<Expression>,
10464}
10465
10466/// Constraint
10467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10468#[cfg_attr(feature = "bindings", derive(TS))]
10469pub struct Constraint {
10470    pub this: Box<Expression>,
10471    #[serde(default)]
10472    pub expressions: Vec<Expression>,
10473}
10474
10475/// Export
10476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10477#[cfg_attr(feature = "bindings", derive(TS))]
10478pub struct Export {
10479    pub this: Box<Expression>,
10480    #[serde(default)]
10481    pub connection: Option<Box<Expression>>,
10482    #[serde(default)]
10483    pub options: Vec<Expression>,
10484}
10485
10486/// Filter
10487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10488#[cfg_attr(feature = "bindings", derive(TS))]
10489pub struct Filter {
10490    pub this: Box<Expression>,
10491    pub expression: Box<Expression>,
10492}
10493
10494/// Changes
10495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10496#[cfg_attr(feature = "bindings", derive(TS))]
10497pub struct Changes {
10498    #[serde(default)]
10499    pub information: Option<Box<Expression>>,
10500    #[serde(default)]
10501    pub at_before: Option<Box<Expression>>,
10502    #[serde(default)]
10503    pub end: Option<Box<Expression>>,
10504}
10505
10506/// Directory
10507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10508#[cfg_attr(feature = "bindings", derive(TS))]
10509pub struct Directory {
10510    pub this: Box<Expression>,
10511    #[serde(default)]
10512    pub local: Option<Box<Expression>>,
10513    #[serde(default)]
10514    pub row_format: Option<Box<Expression>>,
10515}
10516
10517/// ForeignKey
10518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10519#[cfg_attr(feature = "bindings", derive(TS))]
10520pub struct ForeignKey {
10521    #[serde(default)]
10522    pub expressions: Vec<Expression>,
10523    #[serde(default)]
10524    pub reference: Option<Box<Expression>>,
10525    #[serde(default)]
10526    pub delete: Option<Box<Expression>>,
10527    #[serde(default)]
10528    pub update: Option<Box<Expression>>,
10529    #[serde(default)]
10530    pub options: Vec<Expression>,
10531}
10532
10533/// ColumnPrefix
10534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10535#[cfg_attr(feature = "bindings", derive(TS))]
10536pub struct ColumnPrefix {
10537    pub this: Box<Expression>,
10538    pub expression: Box<Expression>,
10539}
10540
10541/// PrimaryKey
10542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10543#[cfg_attr(feature = "bindings", derive(TS))]
10544pub struct PrimaryKey {
10545    #[serde(default)]
10546    pub this: Option<Box<Expression>>,
10547    #[serde(default)]
10548    pub expressions: Vec<Expression>,
10549    #[serde(default)]
10550    pub options: Vec<Expression>,
10551    #[serde(default)]
10552    pub include: Option<Box<Expression>>,
10553}
10554
10555/// Into
10556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10557#[cfg_attr(feature = "bindings", derive(TS))]
10558pub struct IntoClause {
10559    #[serde(default)]
10560    pub this: Option<Box<Expression>>,
10561    #[serde(default)]
10562    pub temporary: bool,
10563    #[serde(default)]
10564    pub unlogged: Option<Box<Expression>>,
10565    #[serde(default)]
10566    pub bulk_collect: Option<Box<Expression>>,
10567    #[serde(default)]
10568    pub expressions: Vec<Expression>,
10569}
10570
10571/// JoinHint
10572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10573#[cfg_attr(feature = "bindings", derive(TS))]
10574pub struct JoinHint {
10575    pub this: Box<Expression>,
10576    #[serde(default)]
10577    pub expressions: Vec<Expression>,
10578}
10579
10580/// Opclass
10581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10582#[cfg_attr(feature = "bindings", derive(TS))]
10583pub struct Opclass {
10584    pub this: Box<Expression>,
10585    pub expression: Box<Expression>,
10586}
10587
10588/// Index
10589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10590#[cfg_attr(feature = "bindings", derive(TS))]
10591pub struct Index {
10592    #[serde(default)]
10593    pub this: Option<Box<Expression>>,
10594    #[serde(default)]
10595    pub table: Option<Box<Expression>>,
10596    #[serde(default)]
10597    pub unique: bool,
10598    #[serde(default)]
10599    pub primary: Option<Box<Expression>>,
10600    #[serde(default)]
10601    pub amp: Option<Box<Expression>>,
10602    #[serde(default)]
10603    pub params: Vec<Expression>,
10604}
10605
10606/// IndexParameters
10607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10608#[cfg_attr(feature = "bindings", derive(TS))]
10609pub struct IndexParameters {
10610    #[serde(default)]
10611    pub using: Option<Box<Expression>>,
10612    #[serde(default)]
10613    pub include: Option<Box<Expression>>,
10614    #[serde(default)]
10615    pub columns: Vec<Expression>,
10616    #[serde(default)]
10617    pub with_storage: Option<Box<Expression>>,
10618    #[serde(default)]
10619    pub partition_by: Option<Box<Expression>>,
10620    #[serde(default)]
10621    pub tablespace: Option<Box<Expression>>,
10622    #[serde(default)]
10623    pub where_: Option<Box<Expression>>,
10624    #[serde(default)]
10625    pub on: Option<Box<Expression>>,
10626}
10627
10628/// ConditionalInsert
10629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10630#[cfg_attr(feature = "bindings", derive(TS))]
10631pub struct ConditionalInsert {
10632    pub this: Box<Expression>,
10633    #[serde(default)]
10634    pub expression: Option<Box<Expression>>,
10635    #[serde(default)]
10636    pub else_: Option<Box<Expression>>,
10637}
10638
10639/// MultitableInserts
10640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10641#[cfg_attr(feature = "bindings", derive(TS))]
10642pub struct MultitableInserts {
10643    #[serde(default)]
10644    pub expressions: Vec<Expression>,
10645    pub kind: String,
10646    #[serde(default)]
10647    pub source: Option<Box<Expression>>,
10648    /// Leading comments before the statement
10649    #[serde(default)]
10650    pub leading_comments: Vec<String>,
10651    /// OVERWRITE modifier (Snowflake: INSERT OVERWRITE ALL)
10652    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10653    pub overwrite: bool,
10654}
10655
10656/// OnConflict
10657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10658#[cfg_attr(feature = "bindings", derive(TS))]
10659pub struct OnConflict {
10660    #[serde(default)]
10661    pub duplicate: Option<Box<Expression>>,
10662    #[serde(default)]
10663    pub expressions: Vec<Expression>,
10664    #[serde(default)]
10665    pub action: Option<Box<Expression>>,
10666    #[serde(default)]
10667    pub conflict_keys: Option<Box<Expression>>,
10668    #[serde(default)]
10669    pub index_predicate: Option<Box<Expression>>,
10670    #[serde(default)]
10671    pub constraint: Option<Box<Expression>>,
10672    #[serde(default)]
10673    pub where_: Option<Box<Expression>>,
10674}
10675
10676/// OnCondition
10677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10678#[cfg_attr(feature = "bindings", derive(TS))]
10679pub struct OnCondition {
10680    #[serde(default)]
10681    pub error: Option<Box<Expression>>,
10682    #[serde(default)]
10683    pub empty: Option<Box<Expression>>,
10684    #[serde(default)]
10685    pub null: Option<Box<Expression>>,
10686}
10687
10688/// Returning
10689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10690#[cfg_attr(feature = "bindings", derive(TS))]
10691pub struct Returning {
10692    #[serde(default)]
10693    pub expressions: Vec<Expression>,
10694    #[serde(default)]
10695    pub into: Option<Box<Expression>>,
10696}
10697
10698/// Introducer
10699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10700#[cfg_attr(feature = "bindings", derive(TS))]
10701pub struct Introducer {
10702    pub this: Box<Expression>,
10703    pub expression: Box<Expression>,
10704}
10705
10706/// PartitionRange
10707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10708#[cfg_attr(feature = "bindings", derive(TS))]
10709pub struct PartitionRange {
10710    pub this: Box<Expression>,
10711    #[serde(default)]
10712    pub expression: Option<Box<Expression>>,
10713    #[serde(default)]
10714    pub expressions: Vec<Expression>,
10715}
10716
10717/// Group
10718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10719#[cfg_attr(feature = "bindings", derive(TS))]
10720pub struct Group {
10721    #[serde(default)]
10722    pub expressions: Vec<Expression>,
10723    #[serde(default)]
10724    pub grouping_sets: Option<Box<Expression>>,
10725    #[serde(default)]
10726    pub cube: Option<Box<Expression>>,
10727    #[serde(default)]
10728    pub rollup: Option<Box<Expression>>,
10729    #[serde(default)]
10730    pub totals: Option<Box<Expression>>,
10731    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10732    #[serde(default)]
10733    pub all: Option<bool>,
10734}
10735
10736/// Cube
10737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10738#[cfg_attr(feature = "bindings", derive(TS))]
10739pub struct Cube {
10740    #[serde(default)]
10741    pub expressions: Vec<Expression>,
10742}
10743
10744/// Rollup
10745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10746#[cfg_attr(feature = "bindings", derive(TS))]
10747pub struct Rollup {
10748    #[serde(default)]
10749    pub expressions: Vec<Expression>,
10750}
10751
10752/// GroupingSets
10753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10754#[cfg_attr(feature = "bindings", derive(TS))]
10755pub struct GroupingSets {
10756    #[serde(default)]
10757    pub expressions: Vec<Expression>,
10758}
10759
10760/// LimitOptions
10761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10762#[cfg_attr(feature = "bindings", derive(TS))]
10763pub struct LimitOptions {
10764    #[serde(default)]
10765    pub percent: Option<Box<Expression>>,
10766    #[serde(default)]
10767    pub rows: Option<Box<Expression>>,
10768    #[serde(default)]
10769    pub with_ties: Option<Box<Expression>>,
10770}
10771
10772/// Lateral
10773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10774#[cfg_attr(feature = "bindings", derive(TS))]
10775pub struct Lateral {
10776    pub this: Box<Expression>,
10777    #[serde(default)]
10778    pub view: Option<Box<Expression>>,
10779    #[serde(default)]
10780    pub outer: Option<Box<Expression>>,
10781    #[serde(default)]
10782    pub alias: Option<String>,
10783    /// Whether the alias was originally quoted (backtick/double-quote)
10784    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10785    pub alias_quoted: bool,
10786    #[serde(default)]
10787    pub cross_apply: Option<Box<Expression>>,
10788    #[serde(default)]
10789    pub ordinality: Option<Box<Expression>>,
10790    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10791    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10792    pub column_aliases: Vec<String>,
10793}
10794
10795/// TableFromRows
10796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10797#[cfg_attr(feature = "bindings", derive(TS))]
10798pub struct TableFromRows {
10799    pub this: Box<Expression>,
10800    #[serde(default)]
10801    pub alias: Option<String>,
10802    #[serde(default)]
10803    pub joins: Vec<Expression>,
10804    #[serde(default)]
10805    pub pivots: Option<Box<Expression>>,
10806    #[serde(default)]
10807    pub sample: Option<Box<Expression>>,
10808}
10809
10810/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10811/// Used for set-returning functions with typed column definitions
10812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10813#[cfg_attr(feature = "bindings", derive(TS))]
10814pub struct RowsFrom {
10815    /// List of function expressions, each potentially with an alias and typed columns
10816    pub expressions: Vec<Expression>,
10817    /// WITH ORDINALITY modifier
10818    #[serde(default)]
10819    pub ordinality: bool,
10820    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10821    #[serde(default)]
10822    pub alias: Option<Box<Expression>>,
10823}
10824
10825/// WithFill
10826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10827#[cfg_attr(feature = "bindings", derive(TS))]
10828pub struct WithFill {
10829    #[serde(default)]
10830    pub from_: Option<Box<Expression>>,
10831    #[serde(default)]
10832    pub to: Option<Box<Expression>>,
10833    #[serde(default)]
10834    pub step: Option<Box<Expression>>,
10835    #[serde(default)]
10836    pub staleness: Option<Box<Expression>>,
10837    #[serde(default)]
10838    pub interpolate: Option<Box<Expression>>,
10839}
10840
10841/// Property
10842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10843#[cfg_attr(feature = "bindings", derive(TS))]
10844pub struct Property {
10845    pub this: Box<Expression>,
10846    #[serde(default)]
10847    pub value: Option<Box<Expression>>,
10848}
10849
10850/// GrantPrivilege
10851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10852#[cfg_attr(feature = "bindings", derive(TS))]
10853pub struct GrantPrivilege {
10854    pub this: Box<Expression>,
10855    #[serde(default)]
10856    pub expressions: Vec<Expression>,
10857}
10858
10859/// AllowedValuesProperty
10860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10861#[cfg_attr(feature = "bindings", derive(TS))]
10862pub struct AllowedValuesProperty {
10863    #[serde(default)]
10864    pub expressions: Vec<Expression>,
10865}
10866
10867/// AlgorithmProperty
10868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10869#[cfg_attr(feature = "bindings", derive(TS))]
10870pub struct AlgorithmProperty {
10871    pub this: Box<Expression>,
10872}
10873
10874/// AutoIncrementProperty
10875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10876#[cfg_attr(feature = "bindings", derive(TS))]
10877pub struct AutoIncrementProperty {
10878    pub this: Box<Expression>,
10879}
10880
10881/// AutoRefreshProperty
10882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10883#[cfg_attr(feature = "bindings", derive(TS))]
10884pub struct AutoRefreshProperty {
10885    pub this: Box<Expression>,
10886}
10887
10888/// BackupProperty
10889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10890#[cfg_attr(feature = "bindings", derive(TS))]
10891pub struct BackupProperty {
10892    pub this: Box<Expression>,
10893}
10894
10895/// BuildProperty
10896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10897#[cfg_attr(feature = "bindings", derive(TS))]
10898pub struct BuildProperty {
10899    pub this: Box<Expression>,
10900}
10901
10902/// BlockCompressionProperty
10903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10904#[cfg_attr(feature = "bindings", derive(TS))]
10905pub struct BlockCompressionProperty {
10906    #[serde(default)]
10907    pub autotemp: Option<Box<Expression>>,
10908    #[serde(default)]
10909    pub always: Option<Box<Expression>>,
10910    #[serde(default)]
10911    pub default: Option<Box<Expression>>,
10912    #[serde(default)]
10913    pub manual: Option<Box<Expression>>,
10914    #[serde(default)]
10915    pub never: Option<Box<Expression>>,
10916}
10917
10918/// CharacterSetProperty
10919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10920#[cfg_attr(feature = "bindings", derive(TS))]
10921pub struct CharacterSetProperty {
10922    pub this: Box<Expression>,
10923    #[serde(default)]
10924    pub default: Option<Box<Expression>>,
10925}
10926
10927/// ChecksumProperty
10928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10929#[cfg_attr(feature = "bindings", derive(TS))]
10930pub struct ChecksumProperty {
10931    #[serde(default)]
10932    pub on: Option<Box<Expression>>,
10933    #[serde(default)]
10934    pub default: Option<Box<Expression>>,
10935}
10936
10937/// CollateProperty
10938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10939#[cfg_attr(feature = "bindings", derive(TS))]
10940pub struct CollateProperty {
10941    pub this: Box<Expression>,
10942    #[serde(default)]
10943    pub default: Option<Box<Expression>>,
10944}
10945
10946/// DataBlocksizeProperty
10947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10948#[cfg_attr(feature = "bindings", derive(TS))]
10949pub struct DataBlocksizeProperty {
10950    #[serde(default)]
10951    pub size: Option<i64>,
10952    #[serde(default)]
10953    pub units: Option<Box<Expression>>,
10954    #[serde(default)]
10955    pub minimum: Option<Box<Expression>>,
10956    #[serde(default)]
10957    pub maximum: Option<Box<Expression>>,
10958    #[serde(default)]
10959    pub default: Option<Box<Expression>>,
10960}
10961
10962/// DataDeletionProperty
10963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10964#[cfg_attr(feature = "bindings", derive(TS))]
10965pub struct DataDeletionProperty {
10966    pub on: Box<Expression>,
10967    #[serde(default)]
10968    pub filter_column: Option<Box<Expression>>,
10969    #[serde(default)]
10970    pub retention_period: Option<Box<Expression>>,
10971}
10972
10973/// DefinerProperty
10974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10975#[cfg_attr(feature = "bindings", derive(TS))]
10976pub struct DefinerProperty {
10977    pub this: Box<Expression>,
10978}
10979
10980/// DistKeyProperty
10981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10982#[cfg_attr(feature = "bindings", derive(TS))]
10983pub struct DistKeyProperty {
10984    pub this: Box<Expression>,
10985}
10986
10987/// DistributedByProperty
10988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10989#[cfg_attr(feature = "bindings", derive(TS))]
10990pub struct DistributedByProperty {
10991    #[serde(default)]
10992    pub expressions: Vec<Expression>,
10993    pub kind: String,
10994    #[serde(default)]
10995    pub buckets: Option<Box<Expression>>,
10996    #[serde(default)]
10997    pub order: Option<Box<Expression>>,
10998}
10999
11000/// DistStyleProperty
11001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11002#[cfg_attr(feature = "bindings", derive(TS))]
11003pub struct DistStyleProperty {
11004    pub this: Box<Expression>,
11005}
11006
11007/// DuplicateKeyProperty
11008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11009#[cfg_attr(feature = "bindings", derive(TS))]
11010pub struct DuplicateKeyProperty {
11011    #[serde(default)]
11012    pub expressions: Vec<Expression>,
11013}
11014
11015/// EngineProperty
11016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11017#[cfg_attr(feature = "bindings", derive(TS))]
11018pub struct EngineProperty {
11019    pub this: Box<Expression>,
11020}
11021
11022/// ToTableProperty
11023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11024#[cfg_attr(feature = "bindings", derive(TS))]
11025pub struct ToTableProperty {
11026    pub this: Box<Expression>,
11027}
11028
11029/// ExecuteAsProperty
11030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11031#[cfg_attr(feature = "bindings", derive(TS))]
11032pub struct ExecuteAsProperty {
11033    pub this: Box<Expression>,
11034}
11035
11036/// ExternalProperty
11037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11038#[cfg_attr(feature = "bindings", derive(TS))]
11039pub struct ExternalProperty {
11040    #[serde(default)]
11041    pub this: Option<Box<Expression>>,
11042}
11043
11044/// FallbackProperty
11045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11046#[cfg_attr(feature = "bindings", derive(TS))]
11047pub struct FallbackProperty {
11048    #[serde(default)]
11049    pub no: Option<Box<Expression>>,
11050    #[serde(default)]
11051    pub protection: Option<Box<Expression>>,
11052}
11053
11054/// FileFormatProperty
11055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11056#[cfg_attr(feature = "bindings", derive(TS))]
11057pub struct FileFormatProperty {
11058    #[serde(default)]
11059    pub this: Option<Box<Expression>>,
11060    #[serde(default)]
11061    pub expressions: Vec<Expression>,
11062    #[serde(default)]
11063    pub hive_format: Option<Box<Expression>>,
11064}
11065
11066/// CredentialsProperty
11067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11068#[cfg_attr(feature = "bindings", derive(TS))]
11069pub struct CredentialsProperty {
11070    #[serde(default)]
11071    pub expressions: Vec<Expression>,
11072}
11073
11074/// FreespaceProperty
11075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11076#[cfg_attr(feature = "bindings", derive(TS))]
11077pub struct FreespaceProperty {
11078    pub this: Box<Expression>,
11079    #[serde(default)]
11080    pub percent: Option<Box<Expression>>,
11081}
11082
11083/// InheritsProperty
11084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11085#[cfg_attr(feature = "bindings", derive(TS))]
11086pub struct InheritsProperty {
11087    #[serde(default)]
11088    pub expressions: Vec<Expression>,
11089}
11090
11091/// InputModelProperty
11092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11093#[cfg_attr(feature = "bindings", derive(TS))]
11094pub struct InputModelProperty {
11095    pub this: Box<Expression>,
11096}
11097
11098/// OutputModelProperty
11099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11100#[cfg_attr(feature = "bindings", derive(TS))]
11101pub struct OutputModelProperty {
11102    pub this: Box<Expression>,
11103}
11104
11105/// IsolatedLoadingProperty
11106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11107#[cfg_attr(feature = "bindings", derive(TS))]
11108pub struct IsolatedLoadingProperty {
11109    #[serde(default)]
11110    pub no: Option<Box<Expression>>,
11111    #[serde(default)]
11112    pub concurrent: Option<Box<Expression>>,
11113    #[serde(default)]
11114    pub target: Option<Box<Expression>>,
11115}
11116
11117/// JournalProperty
11118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11119#[cfg_attr(feature = "bindings", derive(TS))]
11120pub struct JournalProperty {
11121    #[serde(default)]
11122    pub no: Option<Box<Expression>>,
11123    #[serde(default)]
11124    pub dual: Option<Box<Expression>>,
11125    #[serde(default)]
11126    pub before: Option<Box<Expression>>,
11127    #[serde(default)]
11128    pub local: Option<Box<Expression>>,
11129    #[serde(default)]
11130    pub after: Option<Box<Expression>>,
11131}
11132
11133/// LanguageProperty
11134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11135#[cfg_attr(feature = "bindings", derive(TS))]
11136pub struct LanguageProperty {
11137    pub this: Box<Expression>,
11138}
11139
11140/// EnviromentProperty
11141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11142#[cfg_attr(feature = "bindings", derive(TS))]
11143pub struct EnviromentProperty {
11144    #[serde(default)]
11145    pub expressions: Vec<Expression>,
11146}
11147
11148/// ClusteredByProperty
11149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11150#[cfg_attr(feature = "bindings", derive(TS))]
11151pub struct ClusteredByProperty {
11152    #[serde(default)]
11153    pub expressions: Vec<Expression>,
11154    #[serde(default)]
11155    pub sorted_by: Option<Box<Expression>>,
11156    #[serde(default)]
11157    pub buckets: Option<Box<Expression>>,
11158}
11159
11160/// DictProperty
11161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11162#[cfg_attr(feature = "bindings", derive(TS))]
11163pub struct DictProperty {
11164    pub this: Box<Expression>,
11165    pub kind: String,
11166    #[serde(default)]
11167    pub settings: Option<Box<Expression>>,
11168}
11169
11170/// DictRange
11171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11172#[cfg_attr(feature = "bindings", derive(TS))]
11173pub struct DictRange {
11174    pub this: Box<Expression>,
11175    #[serde(default)]
11176    pub min: Option<Box<Expression>>,
11177    #[serde(default)]
11178    pub max: Option<Box<Expression>>,
11179}
11180
11181/// OnCluster
11182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11183#[cfg_attr(feature = "bindings", derive(TS))]
11184pub struct OnCluster {
11185    pub this: Box<Expression>,
11186}
11187
11188/// LikeProperty
11189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11190#[cfg_attr(feature = "bindings", derive(TS))]
11191pub struct LikeProperty {
11192    pub this: Box<Expression>,
11193    #[serde(default)]
11194    pub expressions: Vec<Expression>,
11195}
11196
11197/// LocationProperty
11198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11199#[cfg_attr(feature = "bindings", derive(TS))]
11200pub struct LocationProperty {
11201    pub this: Box<Expression>,
11202}
11203
11204/// LockProperty
11205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11206#[cfg_attr(feature = "bindings", derive(TS))]
11207pub struct LockProperty {
11208    pub this: Box<Expression>,
11209}
11210
11211/// LockingProperty
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct LockingProperty {
11215    #[serde(default)]
11216    pub this: Option<Box<Expression>>,
11217    pub kind: String,
11218    #[serde(default)]
11219    pub for_or_in: Option<Box<Expression>>,
11220    #[serde(default)]
11221    pub lock_type: Option<Box<Expression>>,
11222    #[serde(default)]
11223    pub override_: Option<Box<Expression>>,
11224}
11225
11226/// LogProperty
11227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11228#[cfg_attr(feature = "bindings", derive(TS))]
11229pub struct LogProperty {
11230    #[serde(default)]
11231    pub no: Option<Box<Expression>>,
11232}
11233
11234/// MaterializedProperty
11235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11236#[cfg_attr(feature = "bindings", derive(TS))]
11237pub struct MaterializedProperty {
11238    #[serde(default)]
11239    pub this: Option<Box<Expression>>,
11240}
11241
11242/// MergeBlockRatioProperty
11243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11244#[cfg_attr(feature = "bindings", derive(TS))]
11245pub struct MergeBlockRatioProperty {
11246    #[serde(default)]
11247    pub this: Option<Box<Expression>>,
11248    #[serde(default)]
11249    pub no: Option<Box<Expression>>,
11250    #[serde(default)]
11251    pub default: Option<Box<Expression>>,
11252    #[serde(default)]
11253    pub percent: Option<Box<Expression>>,
11254}
11255
11256/// OnProperty
11257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11258#[cfg_attr(feature = "bindings", derive(TS))]
11259pub struct OnProperty {
11260    pub this: Box<Expression>,
11261}
11262
11263/// OnCommitProperty
11264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11265#[cfg_attr(feature = "bindings", derive(TS))]
11266pub struct OnCommitProperty {
11267    #[serde(default)]
11268    pub delete: Option<Box<Expression>>,
11269}
11270
11271/// PartitionedByProperty
11272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11273#[cfg_attr(feature = "bindings", derive(TS))]
11274pub struct PartitionedByProperty {
11275    pub this: Box<Expression>,
11276}
11277
11278/// BigQuery PARTITION BY property in CREATE TABLE statements.
11279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11280#[cfg_attr(feature = "bindings", derive(TS))]
11281pub struct PartitionByProperty {
11282    #[serde(default)]
11283    pub expressions: Vec<Expression>,
11284}
11285
11286/// PartitionedByBucket
11287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11288#[cfg_attr(feature = "bindings", derive(TS))]
11289pub struct PartitionedByBucket {
11290    pub this: Box<Expression>,
11291    pub expression: Box<Expression>,
11292}
11293
11294/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11296#[cfg_attr(feature = "bindings", derive(TS))]
11297pub struct ClusterByColumnsProperty {
11298    #[serde(default)]
11299    pub columns: Vec<Identifier>,
11300}
11301
11302/// PartitionByTruncate
11303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11304#[cfg_attr(feature = "bindings", derive(TS))]
11305pub struct PartitionByTruncate {
11306    pub this: Box<Expression>,
11307    pub expression: Box<Expression>,
11308}
11309
11310/// PartitionByRangeProperty
11311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11312#[cfg_attr(feature = "bindings", derive(TS))]
11313pub struct PartitionByRangeProperty {
11314    #[serde(default)]
11315    pub partition_expressions: Option<Box<Expression>>,
11316    #[serde(default)]
11317    pub create_expressions: Option<Box<Expression>>,
11318}
11319
11320/// PartitionByRangePropertyDynamic
11321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11322#[cfg_attr(feature = "bindings", derive(TS))]
11323pub struct PartitionByRangePropertyDynamic {
11324    #[serde(default)]
11325    pub this: Option<Box<Expression>>,
11326    #[serde(default)]
11327    pub start: Option<Box<Expression>>,
11328    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11329    #[serde(default)]
11330    pub use_start_end: bool,
11331    #[serde(default)]
11332    pub end: Option<Box<Expression>>,
11333    #[serde(default)]
11334    pub every: Option<Box<Expression>>,
11335}
11336
11337/// PartitionByListProperty
11338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11339#[cfg_attr(feature = "bindings", derive(TS))]
11340pub struct PartitionByListProperty {
11341    #[serde(default)]
11342    pub partition_expressions: Option<Box<Expression>>,
11343    #[serde(default)]
11344    pub create_expressions: Option<Box<Expression>>,
11345}
11346
11347/// PartitionList
11348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11349#[cfg_attr(feature = "bindings", derive(TS))]
11350pub struct PartitionList {
11351    pub this: Box<Expression>,
11352    #[serde(default)]
11353    pub expressions: Vec<Expression>,
11354}
11355
11356/// Partition - represents PARTITION/SUBPARTITION clause
11357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11358#[cfg_attr(feature = "bindings", derive(TS))]
11359pub struct Partition {
11360    pub expressions: Vec<Expression>,
11361    #[serde(default)]
11362    pub subpartition: bool,
11363}
11364
11365/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11366/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11368#[cfg_attr(feature = "bindings", derive(TS))]
11369pub struct RefreshTriggerProperty {
11370    /// Method: COMPLETE or AUTO
11371    pub method: String,
11372    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11373    #[serde(default)]
11374    pub kind: Option<String>,
11375    /// For SCHEDULE: EVERY n (the number)
11376    #[serde(default)]
11377    pub every: Option<Box<Expression>>,
11378    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11379    #[serde(default)]
11380    pub unit: Option<String>,
11381    /// For SCHEDULE: STARTS 'datetime'
11382    #[serde(default)]
11383    pub starts: Option<Box<Expression>>,
11384}
11385
11386/// UniqueKeyProperty
11387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11388#[cfg_attr(feature = "bindings", derive(TS))]
11389pub struct UniqueKeyProperty {
11390    #[serde(default)]
11391    pub expressions: Vec<Expression>,
11392}
11393
11394/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11396#[cfg_attr(feature = "bindings", derive(TS))]
11397pub struct RollupProperty {
11398    pub expressions: Vec<RollupIndex>,
11399}
11400
11401/// RollupIndex - A single rollup index: name(col1, col2)
11402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11403#[cfg_attr(feature = "bindings", derive(TS))]
11404pub struct RollupIndex {
11405    pub name: Identifier,
11406    pub expressions: Vec<Identifier>,
11407}
11408
11409/// PartitionBoundSpec
11410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11411#[cfg_attr(feature = "bindings", derive(TS))]
11412pub struct PartitionBoundSpec {
11413    #[serde(default)]
11414    pub this: Option<Box<Expression>>,
11415    #[serde(default)]
11416    pub expression: Option<Box<Expression>>,
11417    #[serde(default)]
11418    pub from_expressions: Option<Box<Expression>>,
11419    #[serde(default)]
11420    pub to_expressions: Option<Box<Expression>>,
11421}
11422
11423/// PartitionedOfProperty
11424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11425#[cfg_attr(feature = "bindings", derive(TS))]
11426pub struct PartitionedOfProperty {
11427    pub this: Box<Expression>,
11428    pub expression: Box<Expression>,
11429}
11430
11431/// RemoteWithConnectionModelProperty
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct RemoteWithConnectionModelProperty {
11435    pub this: Box<Expression>,
11436}
11437
11438/// ReturnsProperty
11439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11440#[cfg_attr(feature = "bindings", derive(TS))]
11441pub struct ReturnsProperty {
11442    #[serde(default)]
11443    pub this: Option<Box<Expression>>,
11444    #[serde(default)]
11445    pub is_table: Option<Box<Expression>>,
11446    #[serde(default)]
11447    pub table: Option<Box<Expression>>,
11448    #[serde(default)]
11449    pub null: Option<Box<Expression>>,
11450}
11451
11452/// RowFormatProperty
11453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11454#[cfg_attr(feature = "bindings", derive(TS))]
11455pub struct RowFormatProperty {
11456    pub this: Box<Expression>,
11457}
11458
11459/// RowFormatDelimitedProperty
11460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11461#[cfg_attr(feature = "bindings", derive(TS))]
11462pub struct RowFormatDelimitedProperty {
11463    #[serde(default)]
11464    pub fields: Option<Box<Expression>>,
11465    #[serde(default)]
11466    pub escaped: Option<Box<Expression>>,
11467    #[serde(default)]
11468    pub collection_items: Option<Box<Expression>>,
11469    #[serde(default)]
11470    pub map_keys: Option<Box<Expression>>,
11471    #[serde(default)]
11472    pub lines: Option<Box<Expression>>,
11473    #[serde(default)]
11474    pub null: Option<Box<Expression>>,
11475    #[serde(default)]
11476    pub serde: Option<Box<Expression>>,
11477}
11478
11479/// RowFormatSerdeProperty
11480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11481#[cfg_attr(feature = "bindings", derive(TS))]
11482pub struct RowFormatSerdeProperty {
11483    pub this: Box<Expression>,
11484    #[serde(default)]
11485    pub serde_properties: Option<Box<Expression>>,
11486}
11487
11488/// QueryTransform
11489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11490#[cfg_attr(feature = "bindings", derive(TS))]
11491pub struct QueryTransform {
11492    #[serde(default)]
11493    pub expressions: Vec<Expression>,
11494    #[serde(default)]
11495    pub command_script: Option<Box<Expression>>,
11496    #[serde(default)]
11497    pub schema: Option<Box<Expression>>,
11498    #[serde(default)]
11499    pub row_format_before: Option<Box<Expression>>,
11500    #[serde(default)]
11501    pub record_writer: Option<Box<Expression>>,
11502    #[serde(default)]
11503    pub row_format_after: Option<Box<Expression>>,
11504    #[serde(default)]
11505    pub record_reader: Option<Box<Expression>>,
11506}
11507
11508/// SampleProperty
11509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11510#[cfg_attr(feature = "bindings", derive(TS))]
11511pub struct SampleProperty {
11512    pub this: Box<Expression>,
11513}
11514
11515/// SecurityProperty
11516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11517#[cfg_attr(feature = "bindings", derive(TS))]
11518pub struct SecurityProperty {
11519    pub this: Box<Expression>,
11520}
11521
11522/// SchemaCommentProperty
11523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11524#[cfg_attr(feature = "bindings", derive(TS))]
11525pub struct SchemaCommentProperty {
11526    pub this: Box<Expression>,
11527}
11528
11529/// SemanticView
11530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11531#[cfg_attr(feature = "bindings", derive(TS))]
11532pub struct SemanticView {
11533    pub this: Box<Expression>,
11534    #[serde(default)]
11535    pub metrics: Option<Box<Expression>>,
11536    #[serde(default)]
11537    pub dimensions: Option<Box<Expression>>,
11538    #[serde(default)]
11539    pub facts: Option<Box<Expression>>,
11540    #[serde(default)]
11541    pub where_: Option<Box<Expression>>,
11542}
11543
11544/// SerdeProperties
11545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11546#[cfg_attr(feature = "bindings", derive(TS))]
11547pub struct SerdeProperties {
11548    #[serde(default)]
11549    pub expressions: Vec<Expression>,
11550    #[serde(default)]
11551    pub with_: Option<Box<Expression>>,
11552}
11553
11554/// SetProperty
11555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11556#[cfg_attr(feature = "bindings", derive(TS))]
11557pub struct SetProperty {
11558    #[serde(default)]
11559    pub multi: Option<Box<Expression>>,
11560}
11561
11562/// SharingProperty
11563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11564#[cfg_attr(feature = "bindings", derive(TS))]
11565pub struct SharingProperty {
11566    #[serde(default)]
11567    pub this: Option<Box<Expression>>,
11568}
11569
11570/// SetConfigProperty
11571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11572#[cfg_attr(feature = "bindings", derive(TS))]
11573pub struct SetConfigProperty {
11574    pub this: Box<Expression>,
11575}
11576
11577/// SettingsProperty
11578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11579#[cfg_attr(feature = "bindings", derive(TS))]
11580pub struct SettingsProperty {
11581    #[serde(default)]
11582    pub expressions: Vec<Expression>,
11583}
11584
11585/// SortKeyProperty
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct SortKeyProperty {
11589    pub this: Box<Expression>,
11590    #[serde(default)]
11591    pub compound: Option<Box<Expression>>,
11592}
11593
11594/// SqlReadWriteProperty
11595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11596#[cfg_attr(feature = "bindings", derive(TS))]
11597pub struct SqlReadWriteProperty {
11598    pub this: Box<Expression>,
11599}
11600
11601/// SqlSecurityProperty
11602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11603#[cfg_attr(feature = "bindings", derive(TS))]
11604pub struct SqlSecurityProperty {
11605    pub this: Box<Expression>,
11606}
11607
11608/// StabilityProperty
11609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11610#[cfg_attr(feature = "bindings", derive(TS))]
11611pub struct StabilityProperty {
11612    pub this: Box<Expression>,
11613}
11614
11615/// StorageHandlerProperty
11616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11617#[cfg_attr(feature = "bindings", derive(TS))]
11618pub struct StorageHandlerProperty {
11619    pub this: Box<Expression>,
11620}
11621
11622/// TemporaryProperty
11623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11624#[cfg_attr(feature = "bindings", derive(TS))]
11625pub struct TemporaryProperty {
11626    #[serde(default)]
11627    pub this: Option<Box<Expression>>,
11628}
11629
11630/// Tags
11631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11632#[cfg_attr(feature = "bindings", derive(TS))]
11633pub struct Tags {
11634    #[serde(default)]
11635    pub expressions: Vec<Expression>,
11636}
11637
11638/// TransformModelProperty
11639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11640#[cfg_attr(feature = "bindings", derive(TS))]
11641pub struct TransformModelProperty {
11642    #[serde(default)]
11643    pub expressions: Vec<Expression>,
11644}
11645
11646/// TransientProperty
11647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11648#[cfg_attr(feature = "bindings", derive(TS))]
11649pub struct TransientProperty {
11650    #[serde(default)]
11651    pub this: Option<Box<Expression>>,
11652}
11653
11654/// UsingTemplateProperty
11655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11656#[cfg_attr(feature = "bindings", derive(TS))]
11657pub struct UsingTemplateProperty {
11658    pub this: Box<Expression>,
11659}
11660
11661/// ViewAttributeProperty
11662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11663#[cfg_attr(feature = "bindings", derive(TS))]
11664pub struct ViewAttributeProperty {
11665    pub this: Box<Expression>,
11666}
11667
11668/// VolatileProperty
11669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11670#[cfg_attr(feature = "bindings", derive(TS))]
11671pub struct VolatileProperty {
11672    #[serde(default)]
11673    pub this: Option<Box<Expression>>,
11674}
11675
11676/// WithDataProperty
11677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11678#[cfg_attr(feature = "bindings", derive(TS))]
11679pub struct WithDataProperty {
11680    #[serde(default)]
11681    pub no: Option<Box<Expression>>,
11682    #[serde(default)]
11683    pub statistics: Option<Box<Expression>>,
11684}
11685
11686/// WithJournalTableProperty
11687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11688#[cfg_attr(feature = "bindings", derive(TS))]
11689pub struct WithJournalTableProperty {
11690    pub this: Box<Expression>,
11691}
11692
11693/// WithSchemaBindingProperty
11694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11695#[cfg_attr(feature = "bindings", derive(TS))]
11696pub struct WithSchemaBindingProperty {
11697    pub this: Box<Expression>,
11698}
11699
11700/// WithSystemVersioningProperty
11701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11702#[cfg_attr(feature = "bindings", derive(TS))]
11703pub struct WithSystemVersioningProperty {
11704    #[serde(default)]
11705    pub on: Option<Box<Expression>>,
11706    #[serde(default)]
11707    pub this: Option<Box<Expression>>,
11708    #[serde(default)]
11709    pub data_consistency: Option<Box<Expression>>,
11710    #[serde(default)]
11711    pub retention_period: Option<Box<Expression>>,
11712    #[serde(default)]
11713    pub with_: Option<Box<Expression>>,
11714}
11715
11716/// WithProcedureOptions
11717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11718#[cfg_attr(feature = "bindings", derive(TS))]
11719pub struct WithProcedureOptions {
11720    #[serde(default)]
11721    pub expressions: Vec<Expression>,
11722}
11723
11724/// EncodeProperty
11725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11726#[cfg_attr(feature = "bindings", derive(TS))]
11727pub struct EncodeProperty {
11728    pub this: Box<Expression>,
11729    #[serde(default)]
11730    pub properties: Vec<Expression>,
11731    #[serde(default)]
11732    pub key: Option<Box<Expression>>,
11733}
11734
11735/// IncludeProperty
11736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11737#[cfg_attr(feature = "bindings", derive(TS))]
11738pub struct IncludeProperty {
11739    pub this: Box<Expression>,
11740    #[serde(default)]
11741    pub alias: Option<String>,
11742    #[serde(default)]
11743    pub column_def: Option<Box<Expression>>,
11744}
11745
11746/// Properties
11747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11748#[cfg_attr(feature = "bindings", derive(TS))]
11749pub struct Properties {
11750    #[serde(default)]
11751    pub expressions: Vec<Expression>,
11752}
11753
11754/// Key/value pair in a BigQuery OPTIONS (...) clause.
11755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11756#[cfg_attr(feature = "bindings", derive(TS))]
11757pub struct OptionEntry {
11758    pub key: Identifier,
11759    pub value: Expression,
11760}
11761
11762/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11764#[cfg_attr(feature = "bindings", derive(TS))]
11765pub struct OptionsProperty {
11766    #[serde(default)]
11767    pub entries: Vec<OptionEntry>,
11768}
11769
11770/// InputOutputFormat
11771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11772#[cfg_attr(feature = "bindings", derive(TS))]
11773pub struct InputOutputFormat {
11774    #[serde(default)]
11775    pub input_format: Option<Box<Expression>>,
11776    #[serde(default)]
11777    pub output_format: Option<Box<Expression>>,
11778}
11779
11780/// Reference
11781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11782#[cfg_attr(feature = "bindings", derive(TS))]
11783pub struct Reference {
11784    pub this: Box<Expression>,
11785    #[serde(default)]
11786    pub expressions: Vec<Expression>,
11787    #[serde(default)]
11788    pub options: Vec<Expression>,
11789}
11790
11791/// QueryOption
11792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11793#[cfg_attr(feature = "bindings", derive(TS))]
11794pub struct QueryOption {
11795    pub this: Box<Expression>,
11796    #[serde(default)]
11797    pub expression: Option<Box<Expression>>,
11798}
11799
11800/// WithTableHint
11801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11802#[cfg_attr(feature = "bindings", derive(TS))]
11803pub struct WithTableHint {
11804    #[serde(default)]
11805    pub expressions: Vec<Expression>,
11806}
11807
11808/// IndexTableHint
11809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11810#[cfg_attr(feature = "bindings", derive(TS))]
11811pub struct IndexTableHint {
11812    pub this: Box<Expression>,
11813    #[serde(default)]
11814    pub expressions: Vec<Expression>,
11815    #[serde(default)]
11816    pub target: Option<Box<Expression>>,
11817}
11818
11819/// Get
11820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11821#[cfg_attr(feature = "bindings", derive(TS))]
11822pub struct Get {
11823    pub this: Box<Expression>,
11824    #[serde(default)]
11825    pub target: Option<Box<Expression>>,
11826    #[serde(default)]
11827    pub properties: Vec<Expression>,
11828}
11829
11830/// SetOperation
11831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11832#[cfg_attr(feature = "bindings", derive(TS))]
11833pub struct SetOperation {
11834    #[serde(default)]
11835    pub with_: Option<Box<Expression>>,
11836    pub this: Box<Expression>,
11837    pub expression: Box<Expression>,
11838    #[serde(default)]
11839    pub distinct: bool,
11840    #[serde(default)]
11841    pub by_name: Option<Box<Expression>>,
11842    #[serde(default)]
11843    pub side: Option<Box<Expression>>,
11844    #[serde(default)]
11845    pub kind: Option<String>,
11846    #[serde(default)]
11847    pub on: Option<Box<Expression>>,
11848}
11849
11850/// Var - Simple variable reference (for SQL variables, keywords as values)
11851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11852#[cfg_attr(feature = "bindings", derive(TS))]
11853pub struct Var {
11854    pub this: String,
11855}
11856
11857/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11859#[cfg_attr(feature = "bindings", derive(TS))]
11860pub struct Variadic {
11861    pub this: Box<Expression>,
11862}
11863
11864/// Version
11865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11866#[cfg_attr(feature = "bindings", derive(TS))]
11867pub struct Version {
11868    pub this: Box<Expression>,
11869    pub kind: String,
11870    #[serde(default)]
11871    pub expression: Option<Box<Expression>>,
11872}
11873
11874/// Schema
11875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11876#[cfg_attr(feature = "bindings", derive(TS))]
11877pub struct Schema {
11878    #[serde(default)]
11879    pub this: Option<Box<Expression>>,
11880    #[serde(default)]
11881    pub expressions: Vec<Expression>,
11882}
11883
11884/// Lock
11885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11886#[cfg_attr(feature = "bindings", derive(TS))]
11887pub struct Lock {
11888    #[serde(default)]
11889    pub update: Option<Box<Expression>>,
11890    #[serde(default)]
11891    pub expressions: Vec<Expression>,
11892    #[serde(default)]
11893    pub wait: Option<Box<Expression>>,
11894    #[serde(default)]
11895    pub key: Option<Box<Expression>>,
11896}
11897
11898/// TableSample - wraps an expression with a TABLESAMPLE clause
11899/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11901#[cfg_attr(feature = "bindings", derive(TS))]
11902pub struct TableSample {
11903    /// The expression being sampled (subquery, function, etc.)
11904    #[serde(default, skip_serializing_if = "Option::is_none")]
11905    pub this: Option<Box<Expression>>,
11906    /// The sample specification
11907    #[serde(default, skip_serializing_if = "Option::is_none")]
11908    pub sample: Option<Box<Sample>>,
11909    #[serde(default)]
11910    pub expressions: Vec<Expression>,
11911    #[serde(default)]
11912    pub method: Option<String>,
11913    #[serde(default)]
11914    pub bucket_numerator: Option<Box<Expression>>,
11915    #[serde(default)]
11916    pub bucket_denominator: Option<Box<Expression>>,
11917    #[serde(default)]
11918    pub bucket_field: Option<Box<Expression>>,
11919    #[serde(default)]
11920    pub percent: Option<Box<Expression>>,
11921    #[serde(default)]
11922    pub rows: Option<Box<Expression>>,
11923    #[serde(default)]
11924    pub size: Option<i64>,
11925    #[serde(default)]
11926    pub seed: Option<Box<Expression>>,
11927}
11928
11929/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11931#[cfg_attr(feature = "bindings", derive(TS))]
11932pub struct Tag {
11933    #[serde(default)]
11934    pub this: Option<Box<Expression>>,
11935    #[serde(default)]
11936    pub prefix: Option<Box<Expression>>,
11937    #[serde(default)]
11938    pub postfix: Option<Box<Expression>>,
11939}
11940
11941/// UnpivotColumns
11942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11943#[cfg_attr(feature = "bindings", derive(TS))]
11944pub struct UnpivotColumns {
11945    pub this: Box<Expression>,
11946    #[serde(default)]
11947    pub expressions: Vec<Expression>,
11948}
11949
11950/// SessionParameter
11951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11952#[cfg_attr(feature = "bindings", derive(TS))]
11953pub struct SessionParameter {
11954    pub this: Box<Expression>,
11955    #[serde(default)]
11956    pub kind: Option<String>,
11957}
11958
11959/// PseudoType
11960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11961#[cfg_attr(feature = "bindings", derive(TS))]
11962pub struct PseudoType {
11963    pub this: Box<Expression>,
11964}
11965
11966/// ObjectIdentifier
11967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11968#[cfg_attr(feature = "bindings", derive(TS))]
11969pub struct ObjectIdentifier {
11970    pub this: Box<Expression>,
11971}
11972
11973/// Transaction
11974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11975#[cfg_attr(feature = "bindings", derive(TS))]
11976pub struct Transaction {
11977    #[serde(default)]
11978    pub this: Option<Box<Expression>>,
11979    #[serde(default)]
11980    pub modes: Option<Box<Expression>>,
11981    #[serde(default)]
11982    pub mark: Option<Box<Expression>>,
11983}
11984
11985/// Commit
11986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11987#[cfg_attr(feature = "bindings", derive(TS))]
11988pub struct Commit {
11989    #[serde(default)]
11990    pub chain: Option<Box<Expression>>,
11991    #[serde(default)]
11992    pub this: Option<Box<Expression>>,
11993    #[serde(default)]
11994    pub durability: Option<Box<Expression>>,
11995}
11996
11997/// Rollback
11998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11999#[cfg_attr(feature = "bindings", derive(TS))]
12000pub struct Rollback {
12001    #[serde(default)]
12002    pub savepoint: Option<Box<Expression>>,
12003    #[serde(default)]
12004    pub this: Option<Box<Expression>>,
12005}
12006
12007/// AlterSession
12008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12009#[cfg_attr(feature = "bindings", derive(TS))]
12010pub struct AlterSession {
12011    #[serde(default)]
12012    pub expressions: Vec<Expression>,
12013    #[serde(default)]
12014    pub unset: Option<Box<Expression>>,
12015}
12016
12017/// Analyze
12018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12019#[cfg_attr(feature = "bindings", derive(TS))]
12020pub struct Analyze {
12021    #[serde(default)]
12022    pub kind: Option<String>,
12023    #[serde(default)]
12024    pub this: Option<Box<Expression>>,
12025    #[serde(default)]
12026    pub options: Vec<Expression>,
12027    #[serde(default)]
12028    pub mode: Option<Box<Expression>>,
12029    #[serde(default)]
12030    pub partition: Option<Box<Expression>>,
12031    #[serde(default)]
12032    pub expression: Option<Box<Expression>>,
12033    #[serde(default)]
12034    pub properties: Vec<Expression>,
12035    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
12036    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12037    pub columns: Vec<String>,
12038}
12039
12040/// AnalyzeStatistics
12041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12042#[cfg_attr(feature = "bindings", derive(TS))]
12043pub struct AnalyzeStatistics {
12044    pub kind: String,
12045    #[serde(default)]
12046    pub option: Option<Box<Expression>>,
12047    #[serde(default)]
12048    pub this: Option<Box<Expression>>,
12049    #[serde(default)]
12050    pub expressions: Vec<Expression>,
12051}
12052
12053/// AnalyzeHistogram
12054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12055#[cfg_attr(feature = "bindings", derive(TS))]
12056pub struct AnalyzeHistogram {
12057    pub this: Box<Expression>,
12058    #[serde(default)]
12059    pub expressions: Vec<Expression>,
12060    #[serde(default)]
12061    pub expression: Option<Box<Expression>>,
12062    #[serde(default)]
12063    pub update_options: Option<Box<Expression>>,
12064}
12065
12066/// AnalyzeSample
12067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12068#[cfg_attr(feature = "bindings", derive(TS))]
12069pub struct AnalyzeSample {
12070    pub kind: String,
12071    #[serde(default)]
12072    pub sample: Option<Box<Expression>>,
12073}
12074
12075/// AnalyzeListChainedRows
12076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12077#[cfg_attr(feature = "bindings", derive(TS))]
12078pub struct AnalyzeListChainedRows {
12079    #[serde(default)]
12080    pub expression: Option<Box<Expression>>,
12081}
12082
12083/// AnalyzeDelete
12084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12085#[cfg_attr(feature = "bindings", derive(TS))]
12086pub struct AnalyzeDelete {
12087    #[serde(default)]
12088    pub kind: Option<String>,
12089}
12090
12091/// AnalyzeWith
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct AnalyzeWith {
12095    #[serde(default)]
12096    pub expressions: Vec<Expression>,
12097}
12098
12099/// AnalyzeValidate
12100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12101#[cfg_attr(feature = "bindings", derive(TS))]
12102pub struct AnalyzeValidate {
12103    pub kind: String,
12104    #[serde(default)]
12105    pub this: Option<Box<Expression>>,
12106    #[serde(default)]
12107    pub expression: Option<Box<Expression>>,
12108}
12109
12110/// AddPartition
12111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12112#[cfg_attr(feature = "bindings", derive(TS))]
12113pub struct AddPartition {
12114    pub this: Box<Expression>,
12115    #[serde(default)]
12116    pub exists: bool,
12117    #[serde(default)]
12118    pub location: Option<Box<Expression>>,
12119}
12120
12121/// AttachOption
12122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12123#[cfg_attr(feature = "bindings", derive(TS))]
12124pub struct AttachOption {
12125    pub this: Box<Expression>,
12126    #[serde(default)]
12127    pub expression: Option<Box<Expression>>,
12128}
12129
12130/// DropPartition
12131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12132#[cfg_attr(feature = "bindings", derive(TS))]
12133pub struct DropPartition {
12134    #[serde(default)]
12135    pub expressions: Vec<Expression>,
12136    #[serde(default)]
12137    pub exists: bool,
12138}
12139
12140/// ReplacePartition
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct ReplacePartition {
12144    pub expression: Box<Expression>,
12145    #[serde(default)]
12146    pub source: Option<Box<Expression>>,
12147}
12148
12149/// DPipe
12150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12151#[cfg_attr(feature = "bindings", derive(TS))]
12152pub struct DPipe {
12153    pub this: Box<Expression>,
12154    pub expression: Box<Expression>,
12155    #[serde(default)]
12156    pub safe: Option<Box<Expression>>,
12157}
12158
12159/// Operator
12160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12161#[cfg_attr(feature = "bindings", derive(TS))]
12162pub struct Operator {
12163    pub this: Box<Expression>,
12164    #[serde(default)]
12165    pub operator: Option<Box<Expression>>,
12166    pub expression: Box<Expression>,
12167    /// Comments between OPERATOR() and the RHS expression
12168    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12169    pub comments: Vec<String>,
12170}
12171
12172/// PivotAny
12173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12174#[cfg_attr(feature = "bindings", derive(TS))]
12175pub struct PivotAny {
12176    #[serde(default)]
12177    pub this: Option<Box<Expression>>,
12178}
12179
12180/// Aliases
12181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12182#[cfg_attr(feature = "bindings", derive(TS))]
12183pub struct Aliases {
12184    pub this: Box<Expression>,
12185    #[serde(default)]
12186    pub expressions: Vec<Expression>,
12187}
12188
12189/// AtIndex
12190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12191#[cfg_attr(feature = "bindings", derive(TS))]
12192pub struct AtIndex {
12193    pub this: Box<Expression>,
12194    pub expression: Box<Expression>,
12195}
12196
12197/// FromTimeZone
12198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12199#[cfg_attr(feature = "bindings", derive(TS))]
12200pub struct FromTimeZone {
12201    pub this: Box<Expression>,
12202    #[serde(default)]
12203    pub zone: Option<Box<Expression>>,
12204}
12205
12206/// Format override for a column in Teradata
12207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12208#[cfg_attr(feature = "bindings", derive(TS))]
12209pub struct FormatPhrase {
12210    pub this: Box<Expression>,
12211    pub format: String,
12212}
12213
12214/// ForIn
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct ForIn {
12218    pub this: Box<Expression>,
12219    pub expression: Box<Expression>,
12220}
12221
12222/// Automatically converts unit arg into a var.
12223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12224#[cfg_attr(feature = "bindings", derive(TS))]
12225pub struct TimeUnit {
12226    #[serde(default)]
12227    pub unit: Option<String>,
12228}
12229
12230/// IntervalOp
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct IntervalOp {
12234    #[serde(default)]
12235    pub unit: Option<String>,
12236    pub expression: Box<Expression>,
12237}
12238
12239/// HavingMax
12240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12241#[cfg_attr(feature = "bindings", derive(TS))]
12242pub struct HavingMax {
12243    pub this: Box<Expression>,
12244    pub expression: Box<Expression>,
12245    #[serde(default)]
12246    pub max: Option<Box<Expression>>,
12247}
12248
12249/// CosineDistance
12250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12251#[cfg_attr(feature = "bindings", derive(TS))]
12252pub struct CosineDistance {
12253    pub this: Box<Expression>,
12254    pub expression: Box<Expression>,
12255}
12256
12257/// DotProduct
12258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12259#[cfg_attr(feature = "bindings", derive(TS))]
12260pub struct DotProduct {
12261    pub this: Box<Expression>,
12262    pub expression: Box<Expression>,
12263}
12264
12265/// EuclideanDistance
12266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12267#[cfg_attr(feature = "bindings", derive(TS))]
12268pub struct EuclideanDistance {
12269    pub this: Box<Expression>,
12270    pub expression: Box<Expression>,
12271}
12272
12273/// ManhattanDistance
12274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12275#[cfg_attr(feature = "bindings", derive(TS))]
12276pub struct ManhattanDistance {
12277    pub this: Box<Expression>,
12278    pub expression: Box<Expression>,
12279}
12280
12281/// JarowinklerSimilarity
12282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12283#[cfg_attr(feature = "bindings", derive(TS))]
12284pub struct JarowinklerSimilarity {
12285    pub this: Box<Expression>,
12286    pub expression: Box<Expression>,
12287}
12288
12289/// Booland
12290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12291#[cfg_attr(feature = "bindings", derive(TS))]
12292pub struct Booland {
12293    pub this: Box<Expression>,
12294    pub expression: Box<Expression>,
12295}
12296
12297/// Boolor
12298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12299#[cfg_attr(feature = "bindings", derive(TS))]
12300pub struct Boolor {
12301    pub this: Box<Expression>,
12302    pub expression: Box<Expression>,
12303}
12304
12305/// ParameterizedAgg
12306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12307#[cfg_attr(feature = "bindings", derive(TS))]
12308pub struct ParameterizedAgg {
12309    pub this: Box<Expression>,
12310    #[serde(default)]
12311    pub expressions: Vec<Expression>,
12312    #[serde(default)]
12313    pub params: Vec<Expression>,
12314}
12315
12316/// ArgMax
12317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12318#[cfg_attr(feature = "bindings", derive(TS))]
12319pub struct ArgMax {
12320    pub this: Box<Expression>,
12321    pub expression: Box<Expression>,
12322    #[serde(default)]
12323    pub count: Option<Box<Expression>>,
12324}
12325
12326/// ArgMin
12327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12328#[cfg_attr(feature = "bindings", derive(TS))]
12329pub struct ArgMin {
12330    pub this: Box<Expression>,
12331    pub expression: Box<Expression>,
12332    #[serde(default)]
12333    pub count: Option<Box<Expression>>,
12334}
12335
12336/// ApproxTopK
12337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12338#[cfg_attr(feature = "bindings", derive(TS))]
12339pub struct ApproxTopK {
12340    pub this: Box<Expression>,
12341    #[serde(default)]
12342    pub expression: Option<Box<Expression>>,
12343    #[serde(default)]
12344    pub counters: Option<Box<Expression>>,
12345}
12346
12347/// ApproxTopKAccumulate
12348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12349#[cfg_attr(feature = "bindings", derive(TS))]
12350pub struct ApproxTopKAccumulate {
12351    pub this: Box<Expression>,
12352    #[serde(default)]
12353    pub expression: Option<Box<Expression>>,
12354}
12355
12356/// ApproxTopKCombine
12357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12358#[cfg_attr(feature = "bindings", derive(TS))]
12359pub struct ApproxTopKCombine {
12360    pub this: Box<Expression>,
12361    #[serde(default)]
12362    pub expression: Option<Box<Expression>>,
12363}
12364
12365/// ApproxTopKEstimate
12366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12367#[cfg_attr(feature = "bindings", derive(TS))]
12368pub struct ApproxTopKEstimate {
12369    pub this: Box<Expression>,
12370    #[serde(default)]
12371    pub expression: Option<Box<Expression>>,
12372}
12373
12374/// ApproxTopSum
12375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12376#[cfg_attr(feature = "bindings", derive(TS))]
12377pub struct ApproxTopSum {
12378    pub this: Box<Expression>,
12379    pub expression: Box<Expression>,
12380    #[serde(default)]
12381    pub count: Option<Box<Expression>>,
12382}
12383
12384/// ApproxQuantiles
12385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12386#[cfg_attr(feature = "bindings", derive(TS))]
12387pub struct ApproxQuantiles {
12388    pub this: Box<Expression>,
12389    #[serde(default)]
12390    pub expression: Option<Box<Expression>>,
12391}
12392
12393/// Minhash
12394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12395#[cfg_attr(feature = "bindings", derive(TS))]
12396pub struct Minhash {
12397    pub this: Box<Expression>,
12398    #[serde(default)]
12399    pub expressions: Vec<Expression>,
12400}
12401
12402/// FarmFingerprint
12403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12404#[cfg_attr(feature = "bindings", derive(TS))]
12405pub struct FarmFingerprint {
12406    #[serde(default)]
12407    pub expressions: Vec<Expression>,
12408}
12409
12410/// Float64
12411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12412#[cfg_attr(feature = "bindings", derive(TS))]
12413pub struct Float64 {
12414    pub this: Box<Expression>,
12415    #[serde(default)]
12416    pub expression: Option<Box<Expression>>,
12417}
12418
12419/// Transform
12420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12421#[cfg_attr(feature = "bindings", derive(TS))]
12422pub struct Transform {
12423    pub this: Box<Expression>,
12424    pub expression: Box<Expression>,
12425}
12426
12427/// Translate
12428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12429#[cfg_attr(feature = "bindings", derive(TS))]
12430pub struct Translate {
12431    pub this: Box<Expression>,
12432    #[serde(default)]
12433    pub from_: Option<Box<Expression>>,
12434    #[serde(default)]
12435    pub to: Option<Box<Expression>>,
12436}
12437
12438/// Grouping
12439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12440#[cfg_attr(feature = "bindings", derive(TS))]
12441pub struct Grouping {
12442    #[serde(default)]
12443    pub expressions: Vec<Expression>,
12444}
12445
12446/// GroupingId
12447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12448#[cfg_attr(feature = "bindings", derive(TS))]
12449pub struct GroupingId {
12450    #[serde(default)]
12451    pub expressions: Vec<Expression>,
12452}
12453
12454/// Anonymous
12455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12456#[cfg_attr(feature = "bindings", derive(TS))]
12457pub struct Anonymous {
12458    pub this: Box<Expression>,
12459    #[serde(default)]
12460    pub expressions: Vec<Expression>,
12461}
12462
12463/// AnonymousAggFunc
12464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12465#[cfg_attr(feature = "bindings", derive(TS))]
12466pub struct AnonymousAggFunc {
12467    pub this: Box<Expression>,
12468    #[serde(default)]
12469    pub expressions: Vec<Expression>,
12470}
12471
12472/// CombinedAggFunc
12473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12474#[cfg_attr(feature = "bindings", derive(TS))]
12475pub struct CombinedAggFunc {
12476    pub this: Box<Expression>,
12477    #[serde(default)]
12478    pub expressions: Vec<Expression>,
12479}
12480
12481/// CombinedParameterizedAgg
12482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12483#[cfg_attr(feature = "bindings", derive(TS))]
12484pub struct CombinedParameterizedAgg {
12485    pub this: Box<Expression>,
12486    #[serde(default)]
12487    pub expressions: Vec<Expression>,
12488    #[serde(default)]
12489    pub params: Vec<Expression>,
12490}
12491
12492/// HashAgg
12493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12494#[cfg_attr(feature = "bindings", derive(TS))]
12495pub struct HashAgg {
12496    pub this: Box<Expression>,
12497    #[serde(default)]
12498    pub expressions: Vec<Expression>,
12499}
12500
12501/// Hll
12502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12503#[cfg_attr(feature = "bindings", derive(TS))]
12504pub struct Hll {
12505    pub this: Box<Expression>,
12506    #[serde(default)]
12507    pub expressions: Vec<Expression>,
12508}
12509
12510/// Apply
12511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12512#[cfg_attr(feature = "bindings", derive(TS))]
12513pub struct Apply {
12514    pub this: Box<Expression>,
12515    pub expression: Box<Expression>,
12516}
12517
12518/// ToBoolean
12519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12520#[cfg_attr(feature = "bindings", derive(TS))]
12521pub struct ToBoolean {
12522    pub this: Box<Expression>,
12523    #[serde(default)]
12524    pub safe: Option<Box<Expression>>,
12525}
12526
12527/// List
12528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12529#[cfg_attr(feature = "bindings", derive(TS))]
12530pub struct List {
12531    #[serde(default)]
12532    pub expressions: Vec<Expression>,
12533}
12534
12535/// ToMap - Materialize-style map constructor
12536/// Can hold either:
12537/// - A SELECT subquery (MAP(SELECT 'a', 1))
12538/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12540#[cfg_attr(feature = "bindings", derive(TS))]
12541pub struct ToMap {
12542    /// Either a Select subquery or a Struct containing PropertyEQ entries
12543    pub this: Box<Expression>,
12544}
12545
12546/// Pad
12547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12548#[cfg_attr(feature = "bindings", derive(TS))]
12549pub struct Pad {
12550    pub this: Box<Expression>,
12551    pub expression: Box<Expression>,
12552    #[serde(default)]
12553    pub fill_pattern: Option<Box<Expression>>,
12554    #[serde(default)]
12555    pub is_left: Option<Box<Expression>>,
12556}
12557
12558/// ToChar
12559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12560#[cfg_attr(feature = "bindings", derive(TS))]
12561pub struct ToChar {
12562    pub this: Box<Expression>,
12563    #[serde(default)]
12564    pub format: Option<String>,
12565    #[serde(default)]
12566    pub nlsparam: Option<Box<Expression>>,
12567    #[serde(default)]
12568    pub is_numeric: Option<Box<Expression>>,
12569}
12570
12571/// StringFunc - String type conversion function (BigQuery STRING)
12572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12573#[cfg_attr(feature = "bindings", derive(TS))]
12574pub struct StringFunc {
12575    pub this: Box<Expression>,
12576    #[serde(default)]
12577    pub zone: Option<Box<Expression>>,
12578}
12579
12580/// ToNumber
12581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12582#[cfg_attr(feature = "bindings", derive(TS))]
12583pub struct ToNumber {
12584    pub this: Box<Expression>,
12585    #[serde(default)]
12586    pub format: Option<Box<Expression>>,
12587    #[serde(default)]
12588    pub nlsparam: Option<Box<Expression>>,
12589    #[serde(default)]
12590    pub precision: Option<Box<Expression>>,
12591    #[serde(default)]
12592    pub scale: Option<Box<Expression>>,
12593    #[serde(default)]
12594    pub safe: Option<Box<Expression>>,
12595    #[serde(default)]
12596    pub safe_name: Option<Box<Expression>>,
12597}
12598
12599/// ToDouble
12600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12601#[cfg_attr(feature = "bindings", derive(TS))]
12602pub struct ToDouble {
12603    pub this: Box<Expression>,
12604    #[serde(default)]
12605    pub format: Option<String>,
12606    #[serde(default)]
12607    pub safe: Option<Box<Expression>>,
12608}
12609
12610/// ToDecfloat
12611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12612#[cfg_attr(feature = "bindings", derive(TS))]
12613pub struct ToDecfloat {
12614    pub this: Box<Expression>,
12615    #[serde(default)]
12616    pub format: Option<String>,
12617}
12618
12619/// TryToDecfloat
12620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12621#[cfg_attr(feature = "bindings", derive(TS))]
12622pub struct TryToDecfloat {
12623    pub this: Box<Expression>,
12624    #[serde(default)]
12625    pub format: Option<String>,
12626}
12627
12628/// ToFile
12629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12630#[cfg_attr(feature = "bindings", derive(TS))]
12631pub struct ToFile {
12632    pub this: Box<Expression>,
12633    #[serde(default)]
12634    pub path: Option<Box<Expression>>,
12635    #[serde(default)]
12636    pub safe: Option<Box<Expression>>,
12637}
12638
12639/// Columns
12640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12641#[cfg_attr(feature = "bindings", derive(TS))]
12642pub struct Columns {
12643    pub this: Box<Expression>,
12644    #[serde(default)]
12645    pub unpack: Option<Box<Expression>>,
12646}
12647
12648/// ConvertToCharset
12649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12650#[cfg_attr(feature = "bindings", derive(TS))]
12651pub struct ConvertToCharset {
12652    pub this: Box<Expression>,
12653    #[serde(default)]
12654    pub dest: Option<Box<Expression>>,
12655    #[serde(default)]
12656    pub source: Option<Box<Expression>>,
12657}
12658
12659/// ConvertTimezone
12660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12661#[cfg_attr(feature = "bindings", derive(TS))]
12662pub struct ConvertTimezone {
12663    #[serde(default)]
12664    pub source_tz: Option<Box<Expression>>,
12665    #[serde(default)]
12666    pub target_tz: Option<Box<Expression>>,
12667    #[serde(default)]
12668    pub timestamp: Option<Box<Expression>>,
12669    #[serde(default)]
12670    pub options: Vec<Expression>,
12671}
12672
12673/// GenerateSeries
12674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12675#[cfg_attr(feature = "bindings", derive(TS))]
12676pub struct GenerateSeries {
12677    #[serde(default)]
12678    pub start: Option<Box<Expression>>,
12679    #[serde(default)]
12680    pub end: Option<Box<Expression>>,
12681    #[serde(default)]
12682    pub step: Option<Box<Expression>>,
12683    #[serde(default)]
12684    pub is_end_exclusive: Option<Box<Expression>>,
12685}
12686
12687/// AIAgg
12688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12689#[cfg_attr(feature = "bindings", derive(TS))]
12690pub struct AIAgg {
12691    pub this: Box<Expression>,
12692    pub expression: Box<Expression>,
12693}
12694
12695/// AIClassify
12696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12697#[cfg_attr(feature = "bindings", derive(TS))]
12698pub struct AIClassify {
12699    pub this: Box<Expression>,
12700    #[serde(default)]
12701    pub categories: Option<Box<Expression>>,
12702    #[serde(default)]
12703    pub config: Option<Box<Expression>>,
12704}
12705
12706/// ArrayAll
12707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12708#[cfg_attr(feature = "bindings", derive(TS))]
12709pub struct ArrayAll {
12710    pub this: Box<Expression>,
12711    pub expression: Box<Expression>,
12712}
12713
12714/// ArrayAny
12715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12716#[cfg_attr(feature = "bindings", derive(TS))]
12717pub struct ArrayAny {
12718    pub this: Box<Expression>,
12719    pub expression: Box<Expression>,
12720}
12721
12722/// ArrayConstructCompact
12723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12724#[cfg_attr(feature = "bindings", derive(TS))]
12725pub struct ArrayConstructCompact {
12726    #[serde(default)]
12727    pub expressions: Vec<Expression>,
12728}
12729
12730/// StPoint
12731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12732#[cfg_attr(feature = "bindings", derive(TS))]
12733pub struct StPoint {
12734    pub this: Box<Expression>,
12735    pub expression: Box<Expression>,
12736    #[serde(default)]
12737    pub null: Option<Box<Expression>>,
12738}
12739
12740/// StDistance
12741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12742#[cfg_attr(feature = "bindings", derive(TS))]
12743pub struct StDistance {
12744    pub this: Box<Expression>,
12745    pub expression: Box<Expression>,
12746    #[serde(default)]
12747    pub use_spheroid: Option<Box<Expression>>,
12748}
12749
12750/// StringToArray
12751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12752#[cfg_attr(feature = "bindings", derive(TS))]
12753pub struct StringToArray {
12754    pub this: Box<Expression>,
12755    #[serde(default)]
12756    pub expression: Option<Box<Expression>>,
12757    #[serde(default)]
12758    pub null: Option<Box<Expression>>,
12759}
12760
12761/// ArraySum
12762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12763#[cfg_attr(feature = "bindings", derive(TS))]
12764pub struct ArraySum {
12765    pub this: Box<Expression>,
12766    #[serde(default)]
12767    pub expression: Option<Box<Expression>>,
12768}
12769
12770/// ObjectAgg
12771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12772#[cfg_attr(feature = "bindings", derive(TS))]
12773pub struct ObjectAgg {
12774    pub this: Box<Expression>,
12775    pub expression: Box<Expression>,
12776}
12777
12778/// CastToStrType
12779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12780#[cfg_attr(feature = "bindings", derive(TS))]
12781pub struct CastToStrType {
12782    pub this: Box<Expression>,
12783    #[serde(default)]
12784    pub to: Option<Box<Expression>>,
12785}
12786
12787/// CheckJson
12788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12789#[cfg_attr(feature = "bindings", derive(TS))]
12790pub struct CheckJson {
12791    pub this: Box<Expression>,
12792}
12793
12794/// CheckXml
12795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12796#[cfg_attr(feature = "bindings", derive(TS))]
12797pub struct CheckXml {
12798    pub this: Box<Expression>,
12799    #[serde(default)]
12800    pub disable_auto_convert: Option<Box<Expression>>,
12801}
12802
12803/// TranslateCharacters
12804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12805#[cfg_attr(feature = "bindings", derive(TS))]
12806pub struct TranslateCharacters {
12807    pub this: Box<Expression>,
12808    pub expression: Box<Expression>,
12809    #[serde(default)]
12810    pub with_error: Option<Box<Expression>>,
12811}
12812
12813/// CurrentSchemas
12814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12815#[cfg_attr(feature = "bindings", derive(TS))]
12816pub struct CurrentSchemas {
12817    #[serde(default)]
12818    pub this: Option<Box<Expression>>,
12819}
12820
12821/// CurrentDatetime
12822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12823#[cfg_attr(feature = "bindings", derive(TS))]
12824pub struct CurrentDatetime {
12825    #[serde(default)]
12826    pub this: Option<Box<Expression>>,
12827}
12828
12829/// Localtime
12830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12831#[cfg_attr(feature = "bindings", derive(TS))]
12832pub struct Localtime {
12833    #[serde(default)]
12834    pub this: Option<Box<Expression>>,
12835}
12836
12837/// Localtimestamp
12838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12839#[cfg_attr(feature = "bindings", derive(TS))]
12840pub struct Localtimestamp {
12841    #[serde(default)]
12842    pub this: Option<Box<Expression>>,
12843}
12844
12845/// Systimestamp
12846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12847#[cfg_attr(feature = "bindings", derive(TS))]
12848pub struct Systimestamp {
12849    #[serde(default)]
12850    pub this: Option<Box<Expression>>,
12851}
12852
12853/// CurrentSchema
12854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12855#[cfg_attr(feature = "bindings", derive(TS))]
12856pub struct CurrentSchema {
12857    #[serde(default)]
12858    pub this: Option<Box<Expression>>,
12859}
12860
12861/// CurrentUser
12862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12863#[cfg_attr(feature = "bindings", derive(TS))]
12864pub struct CurrentUser {
12865    #[serde(default)]
12866    pub this: Option<Box<Expression>>,
12867}
12868
12869/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12871#[cfg_attr(feature = "bindings", derive(TS))]
12872pub struct SessionUser;
12873
12874/// JSONPathRoot - Represents $ in JSON path expressions
12875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12876#[cfg_attr(feature = "bindings", derive(TS))]
12877pub struct JSONPathRoot;
12878
12879/// UtcTime
12880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12881#[cfg_attr(feature = "bindings", derive(TS))]
12882pub struct UtcTime {
12883    #[serde(default)]
12884    pub this: Option<Box<Expression>>,
12885}
12886
12887/// UtcTimestamp
12888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12889#[cfg_attr(feature = "bindings", derive(TS))]
12890pub struct UtcTimestamp {
12891    #[serde(default)]
12892    pub this: Option<Box<Expression>>,
12893}
12894
12895/// TimestampFunc - TIMESTAMP constructor function
12896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12897#[cfg_attr(feature = "bindings", derive(TS))]
12898pub struct TimestampFunc {
12899    #[serde(default)]
12900    pub this: Option<Box<Expression>>,
12901    #[serde(default)]
12902    pub zone: Option<Box<Expression>>,
12903    #[serde(default)]
12904    pub with_tz: Option<bool>,
12905    #[serde(default)]
12906    pub safe: Option<bool>,
12907}
12908
12909/// DateBin
12910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12911#[cfg_attr(feature = "bindings", derive(TS))]
12912pub struct DateBin {
12913    pub this: Box<Expression>,
12914    pub expression: Box<Expression>,
12915    #[serde(default)]
12916    pub unit: Option<String>,
12917    #[serde(default)]
12918    pub zone: Option<Box<Expression>>,
12919    #[serde(default)]
12920    pub origin: Option<Box<Expression>>,
12921}
12922
12923/// Datetime
12924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12925#[cfg_attr(feature = "bindings", derive(TS))]
12926pub struct Datetime {
12927    pub this: Box<Expression>,
12928    #[serde(default)]
12929    pub expression: Option<Box<Expression>>,
12930}
12931
12932/// DatetimeAdd
12933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12934#[cfg_attr(feature = "bindings", derive(TS))]
12935pub struct DatetimeAdd {
12936    pub this: Box<Expression>,
12937    pub expression: Box<Expression>,
12938    #[serde(default)]
12939    pub unit: Option<String>,
12940}
12941
12942/// DatetimeSub
12943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12944#[cfg_attr(feature = "bindings", derive(TS))]
12945pub struct DatetimeSub {
12946    pub this: Box<Expression>,
12947    pub expression: Box<Expression>,
12948    #[serde(default)]
12949    pub unit: Option<String>,
12950}
12951
12952/// DatetimeDiff
12953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12954#[cfg_attr(feature = "bindings", derive(TS))]
12955pub struct DatetimeDiff {
12956    pub this: Box<Expression>,
12957    pub expression: Box<Expression>,
12958    #[serde(default)]
12959    pub unit: Option<String>,
12960}
12961
12962/// DatetimeTrunc
12963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12964#[cfg_attr(feature = "bindings", derive(TS))]
12965pub struct DatetimeTrunc {
12966    pub this: Box<Expression>,
12967    pub unit: String,
12968    #[serde(default)]
12969    pub zone: Option<Box<Expression>>,
12970}
12971
12972/// Dayname
12973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12974#[cfg_attr(feature = "bindings", derive(TS))]
12975pub struct Dayname {
12976    pub this: Box<Expression>,
12977    #[serde(default)]
12978    pub abbreviated: Option<Box<Expression>>,
12979}
12980
12981/// MakeInterval
12982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12983#[cfg_attr(feature = "bindings", derive(TS))]
12984pub struct MakeInterval {
12985    #[serde(default)]
12986    pub year: Option<Box<Expression>>,
12987    #[serde(default)]
12988    pub month: Option<Box<Expression>>,
12989    #[serde(default)]
12990    pub week: Option<Box<Expression>>,
12991    #[serde(default)]
12992    pub day: Option<Box<Expression>>,
12993    #[serde(default)]
12994    pub hour: Option<Box<Expression>>,
12995    #[serde(default)]
12996    pub minute: Option<Box<Expression>>,
12997    #[serde(default)]
12998    pub second: Option<Box<Expression>>,
12999}
13000
13001/// PreviousDay
13002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13003#[cfg_attr(feature = "bindings", derive(TS))]
13004pub struct PreviousDay {
13005    pub this: Box<Expression>,
13006    pub expression: Box<Expression>,
13007}
13008
13009/// Elt
13010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13011#[cfg_attr(feature = "bindings", derive(TS))]
13012pub struct Elt {
13013    pub this: Box<Expression>,
13014    #[serde(default)]
13015    pub expressions: Vec<Expression>,
13016}
13017
13018/// TimestampAdd
13019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13020#[cfg_attr(feature = "bindings", derive(TS))]
13021pub struct TimestampAdd {
13022    pub this: Box<Expression>,
13023    pub expression: Box<Expression>,
13024    #[serde(default)]
13025    pub unit: Option<String>,
13026}
13027
13028/// TimestampSub
13029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13030#[cfg_attr(feature = "bindings", derive(TS))]
13031pub struct TimestampSub {
13032    pub this: Box<Expression>,
13033    pub expression: Box<Expression>,
13034    #[serde(default)]
13035    pub unit: Option<String>,
13036}
13037
13038/// TimestampDiff
13039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13040#[cfg_attr(feature = "bindings", derive(TS))]
13041pub struct TimestampDiff {
13042    pub this: Box<Expression>,
13043    pub expression: Box<Expression>,
13044    #[serde(default)]
13045    pub unit: Option<String>,
13046}
13047
13048/// TimeSlice
13049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13050#[cfg_attr(feature = "bindings", derive(TS))]
13051pub struct TimeSlice {
13052    pub this: Box<Expression>,
13053    pub expression: Box<Expression>,
13054    pub unit: String,
13055    #[serde(default)]
13056    pub kind: Option<String>,
13057}
13058
13059/// TimeAdd
13060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13061#[cfg_attr(feature = "bindings", derive(TS))]
13062pub struct TimeAdd {
13063    pub this: Box<Expression>,
13064    pub expression: Box<Expression>,
13065    #[serde(default)]
13066    pub unit: Option<String>,
13067}
13068
13069/// TimeSub
13070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13071#[cfg_attr(feature = "bindings", derive(TS))]
13072pub struct TimeSub {
13073    pub this: Box<Expression>,
13074    pub expression: Box<Expression>,
13075    #[serde(default)]
13076    pub unit: Option<String>,
13077}
13078
13079/// TimeDiff
13080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13081#[cfg_attr(feature = "bindings", derive(TS))]
13082pub struct TimeDiff {
13083    pub this: Box<Expression>,
13084    pub expression: Box<Expression>,
13085    #[serde(default)]
13086    pub unit: Option<String>,
13087}
13088
13089/// TimeTrunc
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct TimeTrunc {
13093    pub this: Box<Expression>,
13094    pub unit: String,
13095    #[serde(default)]
13096    pub zone: Option<Box<Expression>>,
13097}
13098
13099/// DateFromParts
13100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13101#[cfg_attr(feature = "bindings", derive(TS))]
13102pub struct DateFromParts {
13103    #[serde(default)]
13104    pub year: Option<Box<Expression>>,
13105    #[serde(default)]
13106    pub month: Option<Box<Expression>>,
13107    #[serde(default)]
13108    pub day: Option<Box<Expression>>,
13109    #[serde(default)]
13110    pub allow_overflow: Option<Box<Expression>>,
13111}
13112
13113/// TimeFromParts
13114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13115#[cfg_attr(feature = "bindings", derive(TS))]
13116pub struct TimeFromParts {
13117    #[serde(default)]
13118    pub hour: Option<Box<Expression>>,
13119    #[serde(default)]
13120    pub min: Option<Box<Expression>>,
13121    #[serde(default)]
13122    pub sec: Option<Box<Expression>>,
13123    #[serde(default)]
13124    pub nano: Option<Box<Expression>>,
13125    #[serde(default)]
13126    pub fractions: Option<Box<Expression>>,
13127    #[serde(default)]
13128    pub precision: Option<i64>,
13129}
13130
13131/// DecodeCase
13132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13133#[cfg_attr(feature = "bindings", derive(TS))]
13134pub struct DecodeCase {
13135    #[serde(default)]
13136    pub expressions: Vec<Expression>,
13137}
13138
13139/// Decrypt
13140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13141#[cfg_attr(feature = "bindings", derive(TS))]
13142pub struct Decrypt {
13143    pub this: Box<Expression>,
13144    #[serde(default)]
13145    pub passphrase: Option<Box<Expression>>,
13146    #[serde(default)]
13147    pub aad: Option<Box<Expression>>,
13148    #[serde(default)]
13149    pub encryption_method: Option<Box<Expression>>,
13150    #[serde(default)]
13151    pub safe: Option<Box<Expression>>,
13152}
13153
13154/// DecryptRaw
13155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13156#[cfg_attr(feature = "bindings", derive(TS))]
13157pub struct DecryptRaw {
13158    pub this: Box<Expression>,
13159    #[serde(default)]
13160    pub key: Option<Box<Expression>>,
13161    #[serde(default)]
13162    pub iv: Option<Box<Expression>>,
13163    #[serde(default)]
13164    pub aad: Option<Box<Expression>>,
13165    #[serde(default)]
13166    pub encryption_method: Option<Box<Expression>>,
13167    #[serde(default)]
13168    pub aead: Option<Box<Expression>>,
13169    #[serde(default)]
13170    pub safe: Option<Box<Expression>>,
13171}
13172
13173/// Encode
13174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13175#[cfg_attr(feature = "bindings", derive(TS))]
13176pub struct Encode {
13177    pub this: Box<Expression>,
13178    #[serde(default)]
13179    pub charset: Option<Box<Expression>>,
13180}
13181
13182/// Encrypt
13183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13184#[cfg_attr(feature = "bindings", derive(TS))]
13185pub struct Encrypt {
13186    pub this: Box<Expression>,
13187    #[serde(default)]
13188    pub passphrase: Option<Box<Expression>>,
13189    #[serde(default)]
13190    pub aad: Option<Box<Expression>>,
13191    #[serde(default)]
13192    pub encryption_method: Option<Box<Expression>>,
13193}
13194
13195/// EncryptRaw
13196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13197#[cfg_attr(feature = "bindings", derive(TS))]
13198pub struct EncryptRaw {
13199    pub this: Box<Expression>,
13200    #[serde(default)]
13201    pub key: Option<Box<Expression>>,
13202    #[serde(default)]
13203    pub iv: Option<Box<Expression>>,
13204    #[serde(default)]
13205    pub aad: Option<Box<Expression>>,
13206    #[serde(default)]
13207    pub encryption_method: Option<Box<Expression>>,
13208}
13209
13210/// EqualNull
13211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13212#[cfg_attr(feature = "bindings", derive(TS))]
13213pub struct EqualNull {
13214    pub this: Box<Expression>,
13215    pub expression: Box<Expression>,
13216}
13217
13218/// ToBinary
13219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13220#[cfg_attr(feature = "bindings", derive(TS))]
13221pub struct ToBinary {
13222    pub this: Box<Expression>,
13223    #[serde(default)]
13224    pub format: Option<String>,
13225    #[serde(default)]
13226    pub safe: Option<Box<Expression>>,
13227}
13228
13229/// Base64DecodeBinary
13230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13231#[cfg_attr(feature = "bindings", derive(TS))]
13232pub struct Base64DecodeBinary {
13233    pub this: Box<Expression>,
13234    #[serde(default)]
13235    pub alphabet: Option<Box<Expression>>,
13236}
13237
13238/// Base64DecodeString
13239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13240#[cfg_attr(feature = "bindings", derive(TS))]
13241pub struct Base64DecodeString {
13242    pub this: Box<Expression>,
13243    #[serde(default)]
13244    pub alphabet: Option<Box<Expression>>,
13245}
13246
13247/// Base64Encode
13248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13249#[cfg_attr(feature = "bindings", derive(TS))]
13250pub struct Base64Encode {
13251    pub this: Box<Expression>,
13252    #[serde(default)]
13253    pub max_line_length: Option<Box<Expression>>,
13254    #[serde(default)]
13255    pub alphabet: Option<Box<Expression>>,
13256}
13257
13258/// TryBase64DecodeBinary
13259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13260#[cfg_attr(feature = "bindings", derive(TS))]
13261pub struct TryBase64DecodeBinary {
13262    pub this: Box<Expression>,
13263    #[serde(default)]
13264    pub alphabet: Option<Box<Expression>>,
13265}
13266
13267/// TryBase64DecodeString
13268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13269#[cfg_attr(feature = "bindings", derive(TS))]
13270pub struct TryBase64DecodeString {
13271    pub this: Box<Expression>,
13272    #[serde(default)]
13273    pub alphabet: Option<Box<Expression>>,
13274}
13275
13276/// GapFill
13277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13278#[cfg_attr(feature = "bindings", derive(TS))]
13279pub struct GapFill {
13280    pub this: Box<Expression>,
13281    #[serde(default)]
13282    pub ts_column: Option<Box<Expression>>,
13283    #[serde(default)]
13284    pub bucket_width: Option<Box<Expression>>,
13285    #[serde(default)]
13286    pub partitioning_columns: Option<Box<Expression>>,
13287    #[serde(default)]
13288    pub value_columns: Option<Box<Expression>>,
13289    #[serde(default)]
13290    pub origin: Option<Box<Expression>>,
13291    #[serde(default)]
13292    pub ignore_nulls: Option<Box<Expression>>,
13293}
13294
13295/// GenerateDateArray
13296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13297#[cfg_attr(feature = "bindings", derive(TS))]
13298pub struct GenerateDateArray {
13299    #[serde(default)]
13300    pub start: Option<Box<Expression>>,
13301    #[serde(default)]
13302    pub end: Option<Box<Expression>>,
13303    #[serde(default)]
13304    pub step: Option<Box<Expression>>,
13305}
13306
13307/// GenerateTimestampArray
13308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13309#[cfg_attr(feature = "bindings", derive(TS))]
13310pub struct GenerateTimestampArray {
13311    #[serde(default)]
13312    pub start: Option<Box<Expression>>,
13313    #[serde(default)]
13314    pub end: Option<Box<Expression>>,
13315    #[serde(default)]
13316    pub step: Option<Box<Expression>>,
13317}
13318
13319/// GetExtract
13320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13321#[cfg_attr(feature = "bindings", derive(TS))]
13322pub struct GetExtract {
13323    pub this: Box<Expression>,
13324    pub expression: Box<Expression>,
13325}
13326
13327/// Getbit
13328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13329#[cfg_attr(feature = "bindings", derive(TS))]
13330pub struct Getbit {
13331    pub this: Box<Expression>,
13332    pub expression: Box<Expression>,
13333    #[serde(default)]
13334    pub zero_is_msb: Option<Box<Expression>>,
13335}
13336
13337/// OverflowTruncateBehavior
13338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13339#[cfg_attr(feature = "bindings", derive(TS))]
13340pub struct OverflowTruncateBehavior {
13341    #[serde(default)]
13342    pub this: Option<Box<Expression>>,
13343    #[serde(default)]
13344    pub with_count: Option<Box<Expression>>,
13345}
13346
13347/// HexEncode
13348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13349#[cfg_attr(feature = "bindings", derive(TS))]
13350pub struct HexEncode {
13351    pub this: Box<Expression>,
13352    #[serde(default)]
13353    pub case: Option<Box<Expression>>,
13354}
13355
13356/// Compress
13357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13358#[cfg_attr(feature = "bindings", derive(TS))]
13359pub struct Compress {
13360    pub this: Box<Expression>,
13361    #[serde(default)]
13362    pub method: Option<String>,
13363}
13364
13365/// DecompressBinary
13366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13367#[cfg_attr(feature = "bindings", derive(TS))]
13368pub struct DecompressBinary {
13369    pub this: Box<Expression>,
13370    pub method: String,
13371}
13372
13373/// DecompressString
13374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13375#[cfg_attr(feature = "bindings", derive(TS))]
13376pub struct DecompressString {
13377    pub this: Box<Expression>,
13378    pub method: String,
13379}
13380
13381/// Xor
13382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13383#[cfg_attr(feature = "bindings", derive(TS))]
13384pub struct Xor {
13385    #[serde(default)]
13386    pub this: Option<Box<Expression>>,
13387    #[serde(default)]
13388    pub expression: Option<Box<Expression>>,
13389    #[serde(default)]
13390    pub expressions: Vec<Expression>,
13391}
13392
13393/// Nullif
13394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13395#[cfg_attr(feature = "bindings", derive(TS))]
13396pub struct Nullif {
13397    pub this: Box<Expression>,
13398    pub expression: Box<Expression>,
13399}
13400
13401/// JSON
13402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13403#[cfg_attr(feature = "bindings", derive(TS))]
13404pub struct JSON {
13405    #[serde(default)]
13406    pub this: Option<Box<Expression>>,
13407    #[serde(default)]
13408    pub with_: Option<Box<Expression>>,
13409    #[serde(default)]
13410    pub unique: bool,
13411}
13412
13413/// JSONPath
13414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13415#[cfg_attr(feature = "bindings", derive(TS))]
13416pub struct JSONPath {
13417    #[serde(default)]
13418    pub expressions: Vec<Expression>,
13419    #[serde(default)]
13420    pub escape: Option<Box<Expression>>,
13421}
13422
13423/// JSONPathFilter
13424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13425#[cfg_attr(feature = "bindings", derive(TS))]
13426pub struct JSONPathFilter {
13427    pub this: Box<Expression>,
13428}
13429
13430/// JSONPathKey
13431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13432#[cfg_attr(feature = "bindings", derive(TS))]
13433pub struct JSONPathKey {
13434    pub this: Box<Expression>,
13435}
13436
13437/// JSONPathRecursive
13438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13439#[cfg_attr(feature = "bindings", derive(TS))]
13440pub struct JSONPathRecursive {
13441    #[serde(default)]
13442    pub this: Option<Box<Expression>>,
13443}
13444
13445/// JSONPathScript
13446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13447#[cfg_attr(feature = "bindings", derive(TS))]
13448pub struct JSONPathScript {
13449    pub this: Box<Expression>,
13450}
13451
13452/// JSONPathSlice
13453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13454#[cfg_attr(feature = "bindings", derive(TS))]
13455pub struct JSONPathSlice {
13456    #[serde(default)]
13457    pub start: Option<Box<Expression>>,
13458    #[serde(default)]
13459    pub end: Option<Box<Expression>>,
13460    #[serde(default)]
13461    pub step: Option<Box<Expression>>,
13462}
13463
13464/// JSONPathSelector
13465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13466#[cfg_attr(feature = "bindings", derive(TS))]
13467pub struct JSONPathSelector {
13468    pub this: Box<Expression>,
13469}
13470
13471/// JSONPathSubscript
13472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13473#[cfg_attr(feature = "bindings", derive(TS))]
13474pub struct JSONPathSubscript {
13475    pub this: Box<Expression>,
13476}
13477
13478/// JSONPathUnion
13479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13480#[cfg_attr(feature = "bindings", derive(TS))]
13481pub struct JSONPathUnion {
13482    #[serde(default)]
13483    pub expressions: Vec<Expression>,
13484}
13485
13486/// Format
13487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13488#[cfg_attr(feature = "bindings", derive(TS))]
13489pub struct Format {
13490    pub this: Box<Expression>,
13491    #[serde(default)]
13492    pub expressions: Vec<Expression>,
13493}
13494
13495/// JSONKeys
13496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13497#[cfg_attr(feature = "bindings", derive(TS))]
13498pub struct JSONKeys {
13499    pub this: Box<Expression>,
13500    #[serde(default)]
13501    pub expression: Option<Box<Expression>>,
13502    #[serde(default)]
13503    pub expressions: Vec<Expression>,
13504}
13505
13506/// JSONKeyValue
13507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13508#[cfg_attr(feature = "bindings", derive(TS))]
13509pub struct JSONKeyValue {
13510    pub this: Box<Expression>,
13511    pub expression: Box<Expression>,
13512}
13513
13514/// JSONKeysAtDepth
13515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13516#[cfg_attr(feature = "bindings", derive(TS))]
13517pub struct JSONKeysAtDepth {
13518    pub this: Box<Expression>,
13519    #[serde(default)]
13520    pub expression: Option<Box<Expression>>,
13521    #[serde(default)]
13522    pub mode: Option<Box<Expression>>,
13523}
13524
13525/// JSONObject
13526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13527#[cfg_attr(feature = "bindings", derive(TS))]
13528pub struct JSONObject {
13529    #[serde(default)]
13530    pub expressions: Vec<Expression>,
13531    #[serde(default)]
13532    pub null_handling: Option<Box<Expression>>,
13533    #[serde(default)]
13534    pub unique_keys: Option<Box<Expression>>,
13535    #[serde(default)]
13536    pub return_type: Option<Box<Expression>>,
13537    #[serde(default)]
13538    pub encoding: Option<Box<Expression>>,
13539}
13540
13541/// JSONObjectAgg
13542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13543#[cfg_attr(feature = "bindings", derive(TS))]
13544pub struct JSONObjectAgg {
13545    #[serde(default)]
13546    pub expressions: Vec<Expression>,
13547    #[serde(default)]
13548    pub null_handling: Option<Box<Expression>>,
13549    #[serde(default)]
13550    pub unique_keys: Option<Box<Expression>>,
13551    #[serde(default)]
13552    pub return_type: Option<Box<Expression>>,
13553    #[serde(default)]
13554    pub encoding: Option<Box<Expression>>,
13555}
13556
13557/// JSONBObjectAgg
13558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13559#[cfg_attr(feature = "bindings", derive(TS))]
13560pub struct JSONBObjectAgg {
13561    pub this: Box<Expression>,
13562    pub expression: Box<Expression>,
13563}
13564
13565/// JSONArray
13566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13567#[cfg_attr(feature = "bindings", derive(TS))]
13568pub struct JSONArray {
13569    #[serde(default)]
13570    pub expressions: Vec<Expression>,
13571    #[serde(default)]
13572    pub null_handling: Option<Box<Expression>>,
13573    #[serde(default)]
13574    pub return_type: Option<Box<Expression>>,
13575    #[serde(default)]
13576    pub strict: Option<Box<Expression>>,
13577}
13578
13579/// JSONArrayAgg
13580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13581#[cfg_attr(feature = "bindings", derive(TS))]
13582pub struct JSONArrayAgg {
13583    pub this: Box<Expression>,
13584    #[serde(default)]
13585    pub order: Option<Box<Expression>>,
13586    #[serde(default)]
13587    pub null_handling: Option<Box<Expression>>,
13588    #[serde(default)]
13589    pub return_type: Option<Box<Expression>>,
13590    #[serde(default)]
13591    pub strict: Option<Box<Expression>>,
13592}
13593
13594/// JSONExists
13595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13596#[cfg_attr(feature = "bindings", derive(TS))]
13597pub struct JSONExists {
13598    pub this: Box<Expression>,
13599    #[serde(default)]
13600    pub path: Option<Box<Expression>>,
13601    #[serde(default)]
13602    pub passing: Option<Box<Expression>>,
13603    #[serde(default)]
13604    pub on_condition: Option<Box<Expression>>,
13605    #[serde(default)]
13606    pub from_dcolonqmark: Option<Box<Expression>>,
13607}
13608
13609/// JSONColumnDef
13610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13611#[cfg_attr(feature = "bindings", derive(TS))]
13612pub struct JSONColumnDef {
13613    #[serde(default)]
13614    pub this: Option<Box<Expression>>,
13615    #[serde(default)]
13616    pub kind: Option<String>,
13617    #[serde(default)]
13618    pub path: Option<Box<Expression>>,
13619    #[serde(default)]
13620    pub nested_schema: Option<Box<Expression>>,
13621    #[serde(default)]
13622    pub ordinality: Option<Box<Expression>>,
13623}
13624
13625/// JSONSchema
13626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13627#[cfg_attr(feature = "bindings", derive(TS))]
13628pub struct JSONSchema {
13629    #[serde(default)]
13630    pub expressions: Vec<Expression>,
13631}
13632
13633/// JSONSet
13634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13635#[cfg_attr(feature = "bindings", derive(TS))]
13636pub struct JSONSet {
13637    pub this: Box<Expression>,
13638    #[serde(default)]
13639    pub expressions: Vec<Expression>,
13640}
13641
13642/// JSONStripNulls
13643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13644#[cfg_attr(feature = "bindings", derive(TS))]
13645pub struct JSONStripNulls {
13646    pub this: Box<Expression>,
13647    #[serde(default)]
13648    pub expression: Option<Box<Expression>>,
13649    #[serde(default)]
13650    pub include_arrays: Option<Box<Expression>>,
13651    #[serde(default)]
13652    pub remove_empty: Option<Box<Expression>>,
13653}
13654
13655/// JSONValue
13656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13657#[cfg_attr(feature = "bindings", derive(TS))]
13658pub struct JSONValue {
13659    pub this: Box<Expression>,
13660    #[serde(default)]
13661    pub path: Option<Box<Expression>>,
13662    #[serde(default)]
13663    pub returning: Option<Box<Expression>>,
13664    #[serde(default)]
13665    pub on_condition: Option<Box<Expression>>,
13666}
13667
13668/// JSONValueArray
13669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13670#[cfg_attr(feature = "bindings", derive(TS))]
13671pub struct JSONValueArray {
13672    pub this: Box<Expression>,
13673    #[serde(default)]
13674    pub expression: Option<Box<Expression>>,
13675}
13676
13677/// JSONRemove
13678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13679#[cfg_attr(feature = "bindings", derive(TS))]
13680pub struct JSONRemove {
13681    pub this: Box<Expression>,
13682    #[serde(default)]
13683    pub expressions: Vec<Expression>,
13684}
13685
13686/// JSONTable
13687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13688#[cfg_attr(feature = "bindings", derive(TS))]
13689pub struct JSONTable {
13690    pub this: Box<Expression>,
13691    #[serde(default)]
13692    pub schema: Option<Box<Expression>>,
13693    #[serde(default)]
13694    pub path: Option<Box<Expression>>,
13695    #[serde(default)]
13696    pub error_handling: Option<Box<Expression>>,
13697    #[serde(default)]
13698    pub empty_handling: Option<Box<Expression>>,
13699}
13700
13701/// JSONType
13702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13703#[cfg_attr(feature = "bindings", derive(TS))]
13704pub struct JSONType {
13705    pub this: Box<Expression>,
13706    #[serde(default)]
13707    pub expression: Option<Box<Expression>>,
13708}
13709
13710/// ObjectInsert
13711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13712#[cfg_attr(feature = "bindings", derive(TS))]
13713pub struct ObjectInsert {
13714    pub this: Box<Expression>,
13715    #[serde(default)]
13716    pub key: Option<Box<Expression>>,
13717    #[serde(default)]
13718    pub value: Option<Box<Expression>>,
13719    #[serde(default)]
13720    pub update_flag: Option<Box<Expression>>,
13721}
13722
13723/// OpenJSONColumnDef
13724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13725#[cfg_attr(feature = "bindings", derive(TS))]
13726pub struct OpenJSONColumnDef {
13727    pub this: Box<Expression>,
13728    pub kind: String,
13729    #[serde(default)]
13730    pub path: Option<Box<Expression>>,
13731    #[serde(default)]
13732    pub as_json: Option<Box<Expression>>,
13733    /// The parsed data type for proper generation
13734    #[serde(default, skip_serializing_if = "Option::is_none")]
13735    pub data_type: Option<DataType>,
13736}
13737
13738/// OpenJSON
13739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13740#[cfg_attr(feature = "bindings", derive(TS))]
13741pub struct OpenJSON {
13742    pub this: Box<Expression>,
13743    #[serde(default)]
13744    pub path: Option<Box<Expression>>,
13745    #[serde(default)]
13746    pub expressions: Vec<Expression>,
13747}
13748
13749/// JSONBExists
13750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13751#[cfg_attr(feature = "bindings", derive(TS))]
13752pub struct JSONBExists {
13753    pub this: Box<Expression>,
13754    #[serde(default)]
13755    pub path: Option<Box<Expression>>,
13756}
13757
13758/// JSONCast
13759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13760#[cfg_attr(feature = "bindings", derive(TS))]
13761pub struct JSONCast {
13762    pub this: Box<Expression>,
13763    pub to: DataType,
13764}
13765
13766/// JSONExtract
13767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13768#[cfg_attr(feature = "bindings", derive(TS))]
13769pub struct JSONExtract {
13770    pub this: Box<Expression>,
13771    pub expression: Box<Expression>,
13772    #[serde(default)]
13773    pub only_json_types: Option<Box<Expression>>,
13774    #[serde(default)]
13775    pub expressions: Vec<Expression>,
13776    #[serde(default)]
13777    pub variant_extract: Option<Box<Expression>>,
13778    #[serde(default)]
13779    pub json_query: Option<Box<Expression>>,
13780    #[serde(default)]
13781    pub option: Option<Box<Expression>>,
13782    #[serde(default)]
13783    pub quote: Option<Box<Expression>>,
13784    #[serde(default)]
13785    pub on_condition: Option<Box<Expression>>,
13786    #[serde(default)]
13787    pub requires_json: Option<Box<Expression>>,
13788}
13789
13790/// JSONExtractQuote
13791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13792#[cfg_attr(feature = "bindings", derive(TS))]
13793pub struct JSONExtractQuote {
13794    #[serde(default)]
13795    pub option: Option<Box<Expression>>,
13796    #[serde(default)]
13797    pub scalar: Option<Box<Expression>>,
13798}
13799
13800/// JSONExtractArray
13801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13802#[cfg_attr(feature = "bindings", derive(TS))]
13803pub struct JSONExtractArray {
13804    pub this: Box<Expression>,
13805    #[serde(default)]
13806    pub expression: Option<Box<Expression>>,
13807}
13808
13809/// JSONExtractScalar
13810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13811#[cfg_attr(feature = "bindings", derive(TS))]
13812pub struct JSONExtractScalar {
13813    pub this: Box<Expression>,
13814    pub expression: Box<Expression>,
13815    #[serde(default)]
13816    pub only_json_types: Option<Box<Expression>>,
13817    #[serde(default)]
13818    pub expressions: Vec<Expression>,
13819    #[serde(default)]
13820    pub json_type: Option<Box<Expression>>,
13821    #[serde(default)]
13822    pub scalar_only: Option<Box<Expression>>,
13823}
13824
13825/// JSONBExtractScalar
13826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13827#[cfg_attr(feature = "bindings", derive(TS))]
13828pub struct JSONBExtractScalar {
13829    pub this: Box<Expression>,
13830    pub expression: Box<Expression>,
13831    #[serde(default)]
13832    pub json_type: Option<Box<Expression>>,
13833}
13834
13835/// JSONFormat
13836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13837#[cfg_attr(feature = "bindings", derive(TS))]
13838pub struct JSONFormat {
13839    #[serde(default)]
13840    pub this: Option<Box<Expression>>,
13841    #[serde(default)]
13842    pub options: Vec<Expression>,
13843    #[serde(default)]
13844    pub is_json: Option<Box<Expression>>,
13845    #[serde(default)]
13846    pub to_json: Option<Box<Expression>>,
13847}
13848
13849/// JSONArrayAppend
13850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13851#[cfg_attr(feature = "bindings", derive(TS))]
13852pub struct JSONArrayAppend {
13853    pub this: Box<Expression>,
13854    #[serde(default)]
13855    pub expressions: Vec<Expression>,
13856}
13857
13858/// JSONArrayContains
13859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13860#[cfg_attr(feature = "bindings", derive(TS))]
13861pub struct JSONArrayContains {
13862    pub this: Box<Expression>,
13863    pub expression: Box<Expression>,
13864    #[serde(default)]
13865    pub json_type: Option<Box<Expression>>,
13866}
13867
13868/// JSONArrayInsert
13869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13870#[cfg_attr(feature = "bindings", derive(TS))]
13871pub struct JSONArrayInsert {
13872    pub this: Box<Expression>,
13873    #[serde(default)]
13874    pub expressions: Vec<Expression>,
13875}
13876
13877/// ParseJSON
13878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13879#[cfg_attr(feature = "bindings", derive(TS))]
13880pub struct ParseJSON {
13881    pub this: Box<Expression>,
13882    #[serde(default)]
13883    pub expression: Option<Box<Expression>>,
13884    #[serde(default)]
13885    pub safe: Option<Box<Expression>>,
13886}
13887
13888/// ParseUrl
13889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13890#[cfg_attr(feature = "bindings", derive(TS))]
13891pub struct ParseUrl {
13892    pub this: Box<Expression>,
13893    #[serde(default)]
13894    pub part_to_extract: Option<Box<Expression>>,
13895    #[serde(default)]
13896    pub key: Option<Box<Expression>>,
13897    #[serde(default)]
13898    pub permissive: Option<Box<Expression>>,
13899}
13900
13901/// ParseIp
13902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13903#[cfg_attr(feature = "bindings", derive(TS))]
13904pub struct ParseIp {
13905    pub this: Box<Expression>,
13906    #[serde(default)]
13907    pub type_: Option<Box<Expression>>,
13908    #[serde(default)]
13909    pub permissive: Option<Box<Expression>>,
13910}
13911
13912/// ParseTime
13913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13914#[cfg_attr(feature = "bindings", derive(TS))]
13915pub struct ParseTime {
13916    pub this: Box<Expression>,
13917    pub format: String,
13918}
13919
13920/// ParseDatetime
13921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13922#[cfg_attr(feature = "bindings", derive(TS))]
13923pub struct ParseDatetime {
13924    pub this: Box<Expression>,
13925    #[serde(default)]
13926    pub format: Option<String>,
13927    #[serde(default)]
13928    pub zone: Option<Box<Expression>>,
13929}
13930
13931/// Map
13932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13933#[cfg_attr(feature = "bindings", derive(TS))]
13934pub struct Map {
13935    #[serde(default)]
13936    pub keys: Vec<Expression>,
13937    #[serde(default)]
13938    pub values: Vec<Expression>,
13939}
13940
13941/// MapCat
13942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13943#[cfg_attr(feature = "bindings", derive(TS))]
13944pub struct MapCat {
13945    pub this: Box<Expression>,
13946    pub expression: Box<Expression>,
13947}
13948
13949/// MapDelete
13950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13951#[cfg_attr(feature = "bindings", derive(TS))]
13952pub struct MapDelete {
13953    pub this: Box<Expression>,
13954    #[serde(default)]
13955    pub expressions: Vec<Expression>,
13956}
13957
13958/// MapInsert
13959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13960#[cfg_attr(feature = "bindings", derive(TS))]
13961pub struct MapInsert {
13962    pub this: Box<Expression>,
13963    #[serde(default)]
13964    pub key: Option<Box<Expression>>,
13965    #[serde(default)]
13966    pub value: Option<Box<Expression>>,
13967    #[serde(default)]
13968    pub update_flag: Option<Box<Expression>>,
13969}
13970
13971/// MapPick
13972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13973#[cfg_attr(feature = "bindings", derive(TS))]
13974pub struct MapPick {
13975    pub this: Box<Expression>,
13976    #[serde(default)]
13977    pub expressions: Vec<Expression>,
13978}
13979
13980/// ScopeResolution
13981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13982#[cfg_attr(feature = "bindings", derive(TS))]
13983pub struct ScopeResolution {
13984    #[serde(default)]
13985    pub this: Option<Box<Expression>>,
13986    pub expression: Box<Expression>,
13987}
13988
13989/// Slice
13990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13991#[cfg_attr(feature = "bindings", derive(TS))]
13992pub struct Slice {
13993    #[serde(default)]
13994    pub this: Option<Box<Expression>>,
13995    #[serde(default)]
13996    pub expression: Option<Box<Expression>>,
13997    #[serde(default)]
13998    pub step: Option<Box<Expression>>,
13999}
14000
14001/// VarMap
14002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14003#[cfg_attr(feature = "bindings", derive(TS))]
14004pub struct VarMap {
14005    #[serde(default)]
14006    pub keys: Vec<Expression>,
14007    #[serde(default)]
14008    pub values: Vec<Expression>,
14009}
14010
14011/// MatchAgainst
14012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14013#[cfg_attr(feature = "bindings", derive(TS))]
14014pub struct MatchAgainst {
14015    pub this: Box<Expression>,
14016    #[serde(default)]
14017    pub expressions: Vec<Expression>,
14018    #[serde(default)]
14019    pub modifier: Option<Box<Expression>>,
14020}
14021
14022/// MD5Digest
14023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14024#[cfg_attr(feature = "bindings", derive(TS))]
14025pub struct MD5Digest {
14026    pub this: Box<Expression>,
14027    #[serde(default)]
14028    pub expressions: Vec<Expression>,
14029}
14030
14031/// Monthname
14032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14033#[cfg_attr(feature = "bindings", derive(TS))]
14034pub struct Monthname {
14035    pub this: Box<Expression>,
14036    #[serde(default)]
14037    pub abbreviated: Option<Box<Expression>>,
14038}
14039
14040/// Ntile
14041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14042#[cfg_attr(feature = "bindings", derive(TS))]
14043pub struct Ntile {
14044    #[serde(default)]
14045    pub this: Option<Box<Expression>>,
14046}
14047
14048/// Normalize
14049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14050#[cfg_attr(feature = "bindings", derive(TS))]
14051pub struct Normalize {
14052    pub this: Box<Expression>,
14053    #[serde(default)]
14054    pub form: Option<Box<Expression>>,
14055    #[serde(default)]
14056    pub is_casefold: Option<Box<Expression>>,
14057}
14058
14059/// Normal
14060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14061#[cfg_attr(feature = "bindings", derive(TS))]
14062pub struct Normal {
14063    pub this: Box<Expression>,
14064    #[serde(default)]
14065    pub stddev: Option<Box<Expression>>,
14066    #[serde(default)]
14067    pub gen: Option<Box<Expression>>,
14068}
14069
14070/// Predict
14071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14072#[cfg_attr(feature = "bindings", derive(TS))]
14073pub struct Predict {
14074    pub this: Box<Expression>,
14075    pub expression: Box<Expression>,
14076    #[serde(default)]
14077    pub params_struct: Option<Box<Expression>>,
14078}
14079
14080/// MLTranslate
14081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14082#[cfg_attr(feature = "bindings", derive(TS))]
14083pub struct MLTranslate {
14084    pub this: Box<Expression>,
14085    pub expression: Box<Expression>,
14086    #[serde(default)]
14087    pub params_struct: Option<Box<Expression>>,
14088}
14089
14090/// FeaturesAtTime
14091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14092#[cfg_attr(feature = "bindings", derive(TS))]
14093pub struct FeaturesAtTime {
14094    pub this: Box<Expression>,
14095    #[serde(default)]
14096    pub time: Option<Box<Expression>>,
14097    #[serde(default)]
14098    pub num_rows: Option<Box<Expression>>,
14099    #[serde(default)]
14100    pub ignore_feature_nulls: Option<Box<Expression>>,
14101}
14102
14103/// GenerateEmbedding
14104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14105#[cfg_attr(feature = "bindings", derive(TS))]
14106pub struct GenerateEmbedding {
14107    pub this: Box<Expression>,
14108    pub expression: Box<Expression>,
14109    #[serde(default)]
14110    pub params_struct: Option<Box<Expression>>,
14111    #[serde(default)]
14112    pub is_text: Option<Box<Expression>>,
14113}
14114
14115/// MLForecast
14116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14117#[cfg_attr(feature = "bindings", derive(TS))]
14118pub struct MLForecast {
14119    pub this: Box<Expression>,
14120    #[serde(default)]
14121    pub expression: Option<Box<Expression>>,
14122    #[serde(default)]
14123    pub params_struct: Option<Box<Expression>>,
14124}
14125
14126/// ModelAttribute
14127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14128#[cfg_attr(feature = "bindings", derive(TS))]
14129pub struct ModelAttribute {
14130    pub this: Box<Expression>,
14131    pub expression: Box<Expression>,
14132}
14133
14134/// VectorSearch
14135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14136#[cfg_attr(feature = "bindings", derive(TS))]
14137pub struct VectorSearch {
14138    pub this: Box<Expression>,
14139    #[serde(default)]
14140    pub column_to_search: Option<Box<Expression>>,
14141    #[serde(default)]
14142    pub query_table: Option<Box<Expression>>,
14143    #[serde(default)]
14144    pub query_column_to_search: Option<Box<Expression>>,
14145    #[serde(default)]
14146    pub top_k: Option<Box<Expression>>,
14147    #[serde(default)]
14148    pub distance_type: Option<Box<Expression>>,
14149    #[serde(default)]
14150    pub options: Vec<Expression>,
14151}
14152
14153/// Quantile
14154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14155#[cfg_attr(feature = "bindings", derive(TS))]
14156pub struct Quantile {
14157    pub this: Box<Expression>,
14158    #[serde(default)]
14159    pub quantile: Option<Box<Expression>>,
14160}
14161
14162/// ApproxQuantile
14163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14164#[cfg_attr(feature = "bindings", derive(TS))]
14165pub struct ApproxQuantile {
14166    pub this: Box<Expression>,
14167    #[serde(default)]
14168    pub quantile: Option<Box<Expression>>,
14169    #[serde(default)]
14170    pub accuracy: Option<Box<Expression>>,
14171    #[serde(default)]
14172    pub weight: Option<Box<Expression>>,
14173    #[serde(default)]
14174    pub error_tolerance: Option<Box<Expression>>,
14175}
14176
14177/// ApproxPercentileEstimate
14178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14179#[cfg_attr(feature = "bindings", derive(TS))]
14180pub struct ApproxPercentileEstimate {
14181    pub this: Box<Expression>,
14182    #[serde(default)]
14183    pub percentile: Option<Box<Expression>>,
14184}
14185
14186/// Randn
14187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14188#[cfg_attr(feature = "bindings", derive(TS))]
14189pub struct Randn {
14190    #[serde(default)]
14191    pub this: Option<Box<Expression>>,
14192}
14193
14194/// Randstr
14195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14196#[cfg_attr(feature = "bindings", derive(TS))]
14197pub struct Randstr {
14198    pub this: Box<Expression>,
14199    #[serde(default)]
14200    pub generator: Option<Box<Expression>>,
14201}
14202
14203/// RangeN
14204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14205#[cfg_attr(feature = "bindings", derive(TS))]
14206pub struct RangeN {
14207    pub this: Box<Expression>,
14208    #[serde(default)]
14209    pub expressions: Vec<Expression>,
14210    #[serde(default)]
14211    pub each: Option<Box<Expression>>,
14212}
14213
14214/// RangeBucket
14215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14216#[cfg_attr(feature = "bindings", derive(TS))]
14217pub struct RangeBucket {
14218    pub this: Box<Expression>,
14219    pub expression: Box<Expression>,
14220}
14221
14222/// ReadCSV
14223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14224#[cfg_attr(feature = "bindings", derive(TS))]
14225pub struct ReadCSV {
14226    pub this: Box<Expression>,
14227    #[serde(default)]
14228    pub expressions: Vec<Expression>,
14229}
14230
14231/// ReadParquet
14232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14233#[cfg_attr(feature = "bindings", derive(TS))]
14234pub struct ReadParquet {
14235    #[serde(default)]
14236    pub expressions: Vec<Expression>,
14237}
14238
14239/// Reduce
14240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14241#[cfg_attr(feature = "bindings", derive(TS))]
14242pub struct Reduce {
14243    pub this: Box<Expression>,
14244    #[serde(default)]
14245    pub initial: Option<Box<Expression>>,
14246    #[serde(default)]
14247    pub merge: Option<Box<Expression>>,
14248    #[serde(default)]
14249    pub finish: Option<Box<Expression>>,
14250}
14251
14252/// RegexpExtractAll
14253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14254#[cfg_attr(feature = "bindings", derive(TS))]
14255pub struct RegexpExtractAll {
14256    pub this: Box<Expression>,
14257    pub expression: Box<Expression>,
14258    #[serde(default)]
14259    pub group: Option<Box<Expression>>,
14260    #[serde(default)]
14261    pub parameters: Option<Box<Expression>>,
14262    #[serde(default)]
14263    pub position: Option<Box<Expression>>,
14264    #[serde(default)]
14265    pub occurrence: Option<Box<Expression>>,
14266}
14267
14268/// RegexpILike
14269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14270#[cfg_attr(feature = "bindings", derive(TS))]
14271pub struct RegexpILike {
14272    pub this: Box<Expression>,
14273    pub expression: Box<Expression>,
14274    #[serde(default)]
14275    pub flag: Option<Box<Expression>>,
14276}
14277
14278/// RegexpFullMatch
14279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14280#[cfg_attr(feature = "bindings", derive(TS))]
14281pub struct RegexpFullMatch {
14282    pub this: Box<Expression>,
14283    pub expression: Box<Expression>,
14284    #[serde(default)]
14285    pub options: Vec<Expression>,
14286}
14287
14288/// RegexpInstr
14289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14290#[cfg_attr(feature = "bindings", derive(TS))]
14291pub struct RegexpInstr {
14292    pub this: Box<Expression>,
14293    pub expression: Box<Expression>,
14294    #[serde(default)]
14295    pub position: Option<Box<Expression>>,
14296    #[serde(default)]
14297    pub occurrence: Option<Box<Expression>>,
14298    #[serde(default)]
14299    pub option: Option<Box<Expression>>,
14300    #[serde(default)]
14301    pub parameters: Option<Box<Expression>>,
14302    #[serde(default)]
14303    pub group: Option<Box<Expression>>,
14304}
14305
14306/// RegexpSplit
14307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14308#[cfg_attr(feature = "bindings", derive(TS))]
14309pub struct RegexpSplit {
14310    pub this: Box<Expression>,
14311    pub expression: Box<Expression>,
14312    #[serde(default)]
14313    pub limit: Option<Box<Expression>>,
14314}
14315
14316/// RegexpCount
14317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14318#[cfg_attr(feature = "bindings", derive(TS))]
14319pub struct RegexpCount {
14320    pub this: Box<Expression>,
14321    pub expression: Box<Expression>,
14322    #[serde(default)]
14323    pub position: Option<Box<Expression>>,
14324    #[serde(default)]
14325    pub parameters: Option<Box<Expression>>,
14326}
14327
14328/// RegrValx
14329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14330#[cfg_attr(feature = "bindings", derive(TS))]
14331pub struct RegrValx {
14332    pub this: Box<Expression>,
14333    pub expression: Box<Expression>,
14334}
14335
14336/// RegrValy
14337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14338#[cfg_attr(feature = "bindings", derive(TS))]
14339pub struct RegrValy {
14340    pub this: Box<Expression>,
14341    pub expression: Box<Expression>,
14342}
14343
14344/// RegrAvgy
14345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14346#[cfg_attr(feature = "bindings", derive(TS))]
14347pub struct RegrAvgy {
14348    pub this: Box<Expression>,
14349    pub expression: Box<Expression>,
14350}
14351
14352/// RegrAvgx
14353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14354#[cfg_attr(feature = "bindings", derive(TS))]
14355pub struct RegrAvgx {
14356    pub this: Box<Expression>,
14357    pub expression: Box<Expression>,
14358}
14359
14360/// RegrCount
14361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14362#[cfg_attr(feature = "bindings", derive(TS))]
14363pub struct RegrCount {
14364    pub this: Box<Expression>,
14365    pub expression: Box<Expression>,
14366}
14367
14368/// RegrIntercept
14369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14370#[cfg_attr(feature = "bindings", derive(TS))]
14371pub struct RegrIntercept {
14372    pub this: Box<Expression>,
14373    pub expression: Box<Expression>,
14374}
14375
14376/// RegrR2
14377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14378#[cfg_attr(feature = "bindings", derive(TS))]
14379pub struct RegrR2 {
14380    pub this: Box<Expression>,
14381    pub expression: Box<Expression>,
14382}
14383
14384/// RegrSxx
14385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14386#[cfg_attr(feature = "bindings", derive(TS))]
14387pub struct RegrSxx {
14388    pub this: Box<Expression>,
14389    pub expression: Box<Expression>,
14390}
14391
14392/// RegrSxy
14393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14394#[cfg_attr(feature = "bindings", derive(TS))]
14395pub struct RegrSxy {
14396    pub this: Box<Expression>,
14397    pub expression: Box<Expression>,
14398}
14399
14400/// RegrSyy
14401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14402#[cfg_attr(feature = "bindings", derive(TS))]
14403pub struct RegrSyy {
14404    pub this: Box<Expression>,
14405    pub expression: Box<Expression>,
14406}
14407
14408/// RegrSlope
14409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14410#[cfg_attr(feature = "bindings", derive(TS))]
14411pub struct RegrSlope {
14412    pub this: Box<Expression>,
14413    pub expression: Box<Expression>,
14414}
14415
14416/// SafeAdd
14417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14418#[cfg_attr(feature = "bindings", derive(TS))]
14419pub struct SafeAdd {
14420    pub this: Box<Expression>,
14421    pub expression: Box<Expression>,
14422}
14423
14424/// SafeDivide
14425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14426#[cfg_attr(feature = "bindings", derive(TS))]
14427pub struct SafeDivide {
14428    pub this: Box<Expression>,
14429    pub expression: Box<Expression>,
14430}
14431
14432/// SafeMultiply
14433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14434#[cfg_attr(feature = "bindings", derive(TS))]
14435pub struct SafeMultiply {
14436    pub this: Box<Expression>,
14437    pub expression: Box<Expression>,
14438}
14439
14440/// SafeSubtract
14441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14442#[cfg_attr(feature = "bindings", derive(TS))]
14443pub struct SafeSubtract {
14444    pub this: Box<Expression>,
14445    pub expression: Box<Expression>,
14446}
14447
14448/// SHA2
14449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14450#[cfg_attr(feature = "bindings", derive(TS))]
14451pub struct SHA2 {
14452    pub this: Box<Expression>,
14453    #[serde(default)]
14454    pub length: Option<i64>,
14455}
14456
14457/// SHA2Digest
14458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14459#[cfg_attr(feature = "bindings", derive(TS))]
14460pub struct SHA2Digest {
14461    pub this: Box<Expression>,
14462    #[serde(default)]
14463    pub length: Option<i64>,
14464}
14465
14466/// SortArray
14467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14468#[cfg_attr(feature = "bindings", derive(TS))]
14469pub struct SortArray {
14470    pub this: Box<Expression>,
14471    #[serde(default)]
14472    pub asc: Option<Box<Expression>>,
14473    #[serde(default)]
14474    pub nulls_first: Option<Box<Expression>>,
14475}
14476
14477/// SplitPart
14478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14479#[cfg_attr(feature = "bindings", derive(TS))]
14480pub struct SplitPart {
14481    pub this: Box<Expression>,
14482    #[serde(default)]
14483    pub delimiter: Option<Box<Expression>>,
14484    #[serde(default)]
14485    pub part_index: Option<Box<Expression>>,
14486}
14487
14488/// SUBSTRING_INDEX(str, delim, count)
14489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14490#[cfg_attr(feature = "bindings", derive(TS))]
14491pub struct SubstringIndex {
14492    pub this: Box<Expression>,
14493    #[serde(default)]
14494    pub delimiter: Option<Box<Expression>>,
14495    #[serde(default)]
14496    pub count: Option<Box<Expression>>,
14497}
14498
14499/// StandardHash
14500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14501#[cfg_attr(feature = "bindings", derive(TS))]
14502pub struct StandardHash {
14503    pub this: Box<Expression>,
14504    #[serde(default)]
14505    pub expression: Option<Box<Expression>>,
14506}
14507
14508/// StrPosition
14509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14510#[cfg_attr(feature = "bindings", derive(TS))]
14511pub struct StrPosition {
14512    pub this: Box<Expression>,
14513    #[serde(default)]
14514    pub substr: Option<Box<Expression>>,
14515    #[serde(default)]
14516    pub position: Option<Box<Expression>>,
14517    #[serde(default)]
14518    pub occurrence: Option<Box<Expression>>,
14519}
14520
14521/// Search
14522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14523#[cfg_attr(feature = "bindings", derive(TS))]
14524pub struct Search {
14525    pub this: Box<Expression>,
14526    pub expression: Box<Expression>,
14527    #[serde(default)]
14528    pub json_scope: Option<Box<Expression>>,
14529    #[serde(default)]
14530    pub analyzer: Option<Box<Expression>>,
14531    #[serde(default)]
14532    pub analyzer_options: Option<Box<Expression>>,
14533    #[serde(default)]
14534    pub search_mode: Option<Box<Expression>>,
14535}
14536
14537/// SearchIp
14538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14539#[cfg_attr(feature = "bindings", derive(TS))]
14540pub struct SearchIp {
14541    pub this: Box<Expression>,
14542    pub expression: Box<Expression>,
14543}
14544
14545/// StrToDate
14546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14547#[cfg_attr(feature = "bindings", derive(TS))]
14548pub struct StrToDate {
14549    pub this: Box<Expression>,
14550    #[serde(default)]
14551    pub format: Option<String>,
14552    #[serde(default)]
14553    pub safe: Option<Box<Expression>>,
14554}
14555
14556/// StrToTime
14557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14558#[cfg_attr(feature = "bindings", derive(TS))]
14559pub struct StrToTime {
14560    pub this: Box<Expression>,
14561    pub format: String,
14562    #[serde(default)]
14563    pub zone: Option<Box<Expression>>,
14564    #[serde(default)]
14565    pub safe: Option<Box<Expression>>,
14566    #[serde(default)]
14567    pub target_type: Option<Box<Expression>>,
14568}
14569
14570/// StrToUnix
14571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14572#[cfg_attr(feature = "bindings", derive(TS))]
14573pub struct StrToUnix {
14574    #[serde(default)]
14575    pub this: Option<Box<Expression>>,
14576    #[serde(default)]
14577    pub format: Option<String>,
14578}
14579
14580/// StrToMap
14581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14582#[cfg_attr(feature = "bindings", derive(TS))]
14583pub struct StrToMap {
14584    pub this: Box<Expression>,
14585    #[serde(default)]
14586    pub pair_delim: Option<Box<Expression>>,
14587    #[serde(default)]
14588    pub key_value_delim: Option<Box<Expression>>,
14589    #[serde(default)]
14590    pub duplicate_resolution_callback: Option<Box<Expression>>,
14591}
14592
14593/// NumberToStr
14594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14595#[cfg_attr(feature = "bindings", derive(TS))]
14596pub struct NumberToStr {
14597    pub this: Box<Expression>,
14598    pub format: String,
14599    #[serde(default)]
14600    pub culture: Option<Box<Expression>>,
14601}
14602
14603/// FromBase
14604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14605#[cfg_attr(feature = "bindings", derive(TS))]
14606pub struct FromBase {
14607    pub this: Box<Expression>,
14608    pub expression: Box<Expression>,
14609}
14610
14611/// Stuff
14612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14613#[cfg_attr(feature = "bindings", derive(TS))]
14614pub struct Stuff {
14615    pub this: Box<Expression>,
14616    #[serde(default)]
14617    pub start: Option<Box<Expression>>,
14618    #[serde(default)]
14619    pub length: Option<i64>,
14620    pub expression: Box<Expression>,
14621}
14622
14623/// TimeToStr
14624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14625#[cfg_attr(feature = "bindings", derive(TS))]
14626pub struct TimeToStr {
14627    pub this: Box<Expression>,
14628    pub format: String,
14629    #[serde(default)]
14630    pub culture: Option<Box<Expression>>,
14631    #[serde(default)]
14632    pub zone: Option<Box<Expression>>,
14633}
14634
14635/// TimeStrToTime
14636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14637#[cfg_attr(feature = "bindings", derive(TS))]
14638pub struct TimeStrToTime {
14639    pub this: Box<Expression>,
14640    #[serde(default)]
14641    pub zone: Option<Box<Expression>>,
14642}
14643
14644/// TsOrDsAdd
14645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14646#[cfg_attr(feature = "bindings", derive(TS))]
14647pub struct TsOrDsAdd {
14648    pub this: Box<Expression>,
14649    pub expression: Box<Expression>,
14650    #[serde(default)]
14651    pub unit: Option<String>,
14652    #[serde(default)]
14653    pub return_type: Option<Box<Expression>>,
14654}
14655
14656/// TsOrDsDiff
14657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14658#[cfg_attr(feature = "bindings", derive(TS))]
14659pub struct TsOrDsDiff {
14660    pub this: Box<Expression>,
14661    pub expression: Box<Expression>,
14662    #[serde(default)]
14663    pub unit: Option<String>,
14664}
14665
14666/// TsOrDsToDate
14667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14668#[cfg_attr(feature = "bindings", derive(TS))]
14669pub struct TsOrDsToDate {
14670    pub this: Box<Expression>,
14671    #[serde(default)]
14672    pub format: Option<String>,
14673    #[serde(default)]
14674    pub safe: Option<Box<Expression>>,
14675}
14676
14677/// TsOrDsToTime
14678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14679#[cfg_attr(feature = "bindings", derive(TS))]
14680pub struct TsOrDsToTime {
14681    pub this: Box<Expression>,
14682    #[serde(default)]
14683    pub format: Option<String>,
14684    #[serde(default)]
14685    pub safe: Option<Box<Expression>>,
14686}
14687
14688/// Unhex
14689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14690#[cfg_attr(feature = "bindings", derive(TS))]
14691pub struct Unhex {
14692    pub this: Box<Expression>,
14693    #[serde(default)]
14694    pub expression: Option<Box<Expression>>,
14695}
14696
14697/// Uniform
14698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14699#[cfg_attr(feature = "bindings", derive(TS))]
14700pub struct Uniform {
14701    pub this: Box<Expression>,
14702    pub expression: Box<Expression>,
14703    #[serde(default)]
14704    pub gen: Option<Box<Expression>>,
14705    #[serde(default)]
14706    pub seed: Option<Box<Expression>>,
14707}
14708
14709/// UnixToStr
14710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14711#[cfg_attr(feature = "bindings", derive(TS))]
14712pub struct UnixToStr {
14713    pub this: Box<Expression>,
14714    #[serde(default)]
14715    pub format: Option<String>,
14716}
14717
14718/// UnixToTime
14719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14720#[cfg_attr(feature = "bindings", derive(TS))]
14721pub struct UnixToTime {
14722    pub this: Box<Expression>,
14723    #[serde(default)]
14724    pub scale: Option<i64>,
14725    #[serde(default)]
14726    pub zone: Option<Box<Expression>>,
14727    #[serde(default)]
14728    pub hours: Option<Box<Expression>>,
14729    #[serde(default)]
14730    pub minutes: Option<Box<Expression>>,
14731    #[serde(default)]
14732    pub format: Option<String>,
14733    #[serde(default)]
14734    pub target_type: Option<Box<Expression>>,
14735}
14736
14737/// Uuid
14738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14739#[cfg_attr(feature = "bindings", derive(TS))]
14740pub struct Uuid {
14741    #[serde(default)]
14742    pub this: Option<Box<Expression>>,
14743    #[serde(default)]
14744    pub name: Option<String>,
14745    #[serde(default)]
14746    pub is_string: Option<Box<Expression>>,
14747}
14748
14749/// TimestampFromParts
14750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14751#[cfg_attr(feature = "bindings", derive(TS))]
14752pub struct TimestampFromParts {
14753    #[serde(default)]
14754    pub zone: Option<Box<Expression>>,
14755    #[serde(default)]
14756    pub milli: Option<Box<Expression>>,
14757    #[serde(default)]
14758    pub this: Option<Box<Expression>>,
14759    #[serde(default)]
14760    pub expression: Option<Box<Expression>>,
14761}
14762
14763/// TimestampTzFromParts
14764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14765#[cfg_attr(feature = "bindings", derive(TS))]
14766pub struct TimestampTzFromParts {
14767    #[serde(default)]
14768    pub zone: Option<Box<Expression>>,
14769}
14770
14771/// Corr
14772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14773#[cfg_attr(feature = "bindings", derive(TS))]
14774pub struct Corr {
14775    pub this: Box<Expression>,
14776    pub expression: Box<Expression>,
14777    #[serde(default)]
14778    pub null_on_zero_variance: Option<Box<Expression>>,
14779}
14780
14781/// WidthBucket
14782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14783#[cfg_attr(feature = "bindings", derive(TS))]
14784pub struct WidthBucket {
14785    pub this: Box<Expression>,
14786    #[serde(default)]
14787    pub min_value: Option<Box<Expression>>,
14788    #[serde(default)]
14789    pub max_value: Option<Box<Expression>>,
14790    #[serde(default)]
14791    pub num_buckets: Option<Box<Expression>>,
14792    #[serde(default)]
14793    pub threshold: Option<Box<Expression>>,
14794}
14795
14796/// CovarSamp
14797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14798#[cfg_attr(feature = "bindings", derive(TS))]
14799pub struct CovarSamp {
14800    pub this: Box<Expression>,
14801    pub expression: Box<Expression>,
14802}
14803
14804/// CovarPop
14805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14806#[cfg_attr(feature = "bindings", derive(TS))]
14807pub struct CovarPop {
14808    pub this: Box<Expression>,
14809    pub expression: Box<Expression>,
14810}
14811
14812/// Week
14813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14814#[cfg_attr(feature = "bindings", derive(TS))]
14815pub struct Week {
14816    pub this: Box<Expression>,
14817    #[serde(default)]
14818    pub mode: Option<Box<Expression>>,
14819}
14820
14821/// XMLElement
14822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14823#[cfg_attr(feature = "bindings", derive(TS))]
14824pub struct XMLElement {
14825    pub this: Box<Expression>,
14826    #[serde(default)]
14827    pub expressions: Vec<Expression>,
14828    #[serde(default)]
14829    pub evalname: Option<Box<Expression>>,
14830}
14831
14832/// XMLGet
14833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14834#[cfg_attr(feature = "bindings", derive(TS))]
14835pub struct XMLGet {
14836    pub this: Box<Expression>,
14837    pub expression: Box<Expression>,
14838    #[serde(default)]
14839    pub instance: Option<Box<Expression>>,
14840}
14841
14842/// XMLTable
14843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14844#[cfg_attr(feature = "bindings", derive(TS))]
14845pub struct XMLTable {
14846    pub this: Box<Expression>,
14847    #[serde(default)]
14848    pub namespaces: Option<Box<Expression>>,
14849    #[serde(default)]
14850    pub passing: Option<Box<Expression>>,
14851    #[serde(default)]
14852    pub columns: Vec<Expression>,
14853    #[serde(default)]
14854    pub by_ref: Option<Box<Expression>>,
14855}
14856
14857/// XMLKeyValueOption
14858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14859#[cfg_attr(feature = "bindings", derive(TS))]
14860pub struct XMLKeyValueOption {
14861    pub this: Box<Expression>,
14862    #[serde(default)]
14863    pub expression: Option<Box<Expression>>,
14864}
14865
14866/// Zipf
14867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14868#[cfg_attr(feature = "bindings", derive(TS))]
14869pub struct Zipf {
14870    pub this: Box<Expression>,
14871    #[serde(default)]
14872    pub elementcount: Option<Box<Expression>>,
14873    #[serde(default)]
14874    pub gen: Option<Box<Expression>>,
14875}
14876
14877/// Merge
14878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14879#[cfg_attr(feature = "bindings", derive(TS))]
14880pub struct Merge {
14881    pub this: Box<Expression>,
14882    pub using: Box<Expression>,
14883    #[serde(default)]
14884    pub on: Option<Box<Expression>>,
14885    #[serde(default)]
14886    pub using_cond: Option<Box<Expression>>,
14887    #[serde(default)]
14888    pub whens: Option<Box<Expression>>,
14889    #[serde(default)]
14890    pub with_: Option<Box<Expression>>,
14891    #[serde(default)]
14892    pub returning: Option<Box<Expression>>,
14893}
14894
14895/// When
14896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14897#[cfg_attr(feature = "bindings", derive(TS))]
14898pub struct When {
14899    #[serde(default)]
14900    pub matched: Option<Box<Expression>>,
14901    #[serde(default)]
14902    pub source: Option<Box<Expression>>,
14903    #[serde(default)]
14904    pub condition: Option<Box<Expression>>,
14905    pub then: Box<Expression>,
14906}
14907
14908/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14910#[cfg_attr(feature = "bindings", derive(TS))]
14911pub struct Whens {
14912    #[serde(default)]
14913    pub expressions: Vec<Expression>,
14914}
14915
14916/// NextValueFor
14917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14918#[cfg_attr(feature = "bindings", derive(TS))]
14919pub struct NextValueFor {
14920    pub this: Box<Expression>,
14921    #[serde(default)]
14922    pub order: Option<Box<Expression>>,
14923}
14924
14925#[cfg(test)]
14926mod tests {
14927    use super::*;
14928
14929    #[test]
14930    #[cfg(feature = "bindings")]
14931    fn export_typescript_types() {
14932        // This test exports TypeScript types to the generated directory
14933        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14934        Expression::export_all(&ts_rs::Config::default())
14935            .expect("Failed to export Expression types");
14936    }
14937
14938    #[test]
14939    fn test_simple_select_builder() {
14940        let select = Select::new()
14941            .column(Expression::star())
14942            .from(Expression::Table(Box::new(TableRef::new("users"))));
14943
14944        assert_eq!(select.expressions.len(), 1);
14945        assert!(select.from.is_some());
14946    }
14947
14948    #[test]
14949    fn test_expression_alias() {
14950        let expr = Expression::column("id").alias("user_id");
14951
14952        match expr {
14953            Expression::Alias(a) => {
14954                assert_eq!(a.alias.name, "user_id");
14955            }
14956            _ => panic!("Expected Alias"),
14957        }
14958    }
14959
14960    #[test]
14961    fn test_literal_creation() {
14962        let num = Expression::number(42);
14963        let str = Expression::string("hello");
14964
14965        match num {
14966            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
14967                let Literal::Number(n) = lit.as_ref() else {
14968                    unreachable!()
14969                };
14970                assert_eq!(n, "42")
14971            }
14972            _ => panic!("Expected Number"),
14973        }
14974
14975        match str {
14976            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
14977                let Literal::String(s) = lit.as_ref() else {
14978                    unreachable!()
14979                };
14980                assert_eq!(s, "hello")
14981            }
14982            _ => panic!("Expected String"),
14983        }
14984    }
14985
14986    #[test]
14987    fn test_expression_sql() {
14988        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14989        assert_eq!(expr.sql(), "SELECT 1 + 2");
14990    }
14991
14992    #[test]
14993    fn test_expression_sql_for() {
14994        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14995        let sql = expr.sql_for(crate::DialectType::Generic);
14996        // Generic mode normalizes IF() to CASE WHEN
14997        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14998    }
14999}