Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117    TryCatch(Box<TryCatch>),
118
119    // Expressions
120    Alias(Box<Alias>),
121    Cast(Box<Cast>),
122    Collation(Box<CollationExpr>),
123    Case(Box<Case>),
124
125    // Binary operations
126    And(Box<BinaryOp>),
127    Or(Box<BinaryOp>),
128    Add(Box<BinaryOp>),
129    Sub(Box<BinaryOp>),
130    Mul(Box<BinaryOp>),
131    Div(Box<BinaryOp>),
132    Mod(Box<BinaryOp>),
133    Eq(Box<BinaryOp>),
134    Neq(Box<BinaryOp>),
135    Lt(Box<BinaryOp>),
136    Lte(Box<BinaryOp>),
137    Gt(Box<BinaryOp>),
138    Gte(Box<BinaryOp>),
139    Like(Box<LikeOp>),
140    ILike(Box<LikeOp>),
141    /// SQLite MATCH operator (FTS)
142    Match(Box<BinaryOp>),
143    BitwiseAnd(Box<BinaryOp>),
144    BitwiseOr(Box<BinaryOp>),
145    BitwiseXor(Box<BinaryOp>),
146    Concat(Box<BinaryOp>),
147    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
148    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
149    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
150
151    // PostgreSQL array/JSONB operators
152    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
153    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
154    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
155    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
156    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
157    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
158    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
159    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
160
161    // Unary operations
162    Not(Box<UnaryOp>),
163    Neg(Box<UnaryOp>),
164    BitwiseNot(Box<UnaryOp>),
165
166    // Predicates
167    In(Box<In>),
168    Between(Box<Between>),
169    IsNull(Box<IsNull>),
170    IsTrue(Box<IsTrueFalse>),
171    IsFalse(Box<IsTrueFalse>),
172    IsJson(Box<IsJson>),
173    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
174    Exists(Box<Exists>),
175    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
176    MemberOf(Box<BinaryOp>),
177
178    // Functions
179    Function(Box<Function>),
180    AggregateFunction(Box<AggregateFunction>),
181    WindowFunction(Box<WindowFunction>),
182
183    // Clauses
184    From(Box<From>),
185    Join(Box<Join>),
186    JoinedTable(Box<JoinedTable>),
187    Where(Box<Where>),
188    GroupBy(Box<GroupBy>),
189    Having(Box<Having>),
190    OrderBy(Box<OrderBy>),
191    Limit(Box<Limit>),
192    Offset(Box<Offset>),
193    Qualify(Box<Qualify>),
194    With(Box<With>),
195    Cte(Box<Cte>),
196    DistributeBy(Box<DistributeBy>),
197    ClusterBy(Box<ClusterBy>),
198    SortBy(Box<SortBy>),
199    LateralView(Box<LateralView>),
200    Hint(Box<Hint>),
201    Pseudocolumn(Pseudocolumn),
202
203    // Oracle hierarchical queries (CONNECT BY)
204    Connect(Box<Connect>),
205    Prior(Box<Prior>),
206    ConnectByRoot(Box<ConnectByRoot>),
207
208    // Pattern matching (MATCH_RECOGNIZE)
209    MatchRecognize(Box<MatchRecognize>),
210
211    // Order expressions
212    Ordered(Box<Ordered>),
213
214    // Window specifications
215    Window(Box<WindowSpec>),
216    Over(Box<Over>),
217    WithinGroup(Box<WithinGroup>),
218
219    // Data types
220    DataType(DataType),
221
222    // Arrays and structs
223    Array(Box<Array>),
224    Struct(Box<Struct>),
225    Tuple(Box<Tuple>),
226
227    // Interval
228    Interval(Box<Interval>),
229
230    // String functions
231    ConcatWs(Box<ConcatWs>),
232    Substring(Box<SubstringFunc>),
233    Upper(Box<UnaryFunc>),
234    Lower(Box<UnaryFunc>),
235    Length(Box<UnaryFunc>),
236    Trim(Box<TrimFunc>),
237    LTrim(Box<UnaryFunc>),
238    RTrim(Box<UnaryFunc>),
239    Replace(Box<ReplaceFunc>),
240    Reverse(Box<UnaryFunc>),
241    Left(Box<LeftRightFunc>),
242    Right(Box<LeftRightFunc>),
243    Repeat(Box<RepeatFunc>),
244    Lpad(Box<PadFunc>),
245    Rpad(Box<PadFunc>),
246    Split(Box<SplitFunc>),
247    RegexpLike(Box<RegexpFunc>),
248    RegexpReplace(Box<RegexpReplaceFunc>),
249    RegexpExtract(Box<RegexpExtractFunc>),
250    Overlay(Box<OverlayFunc>),
251
252    // Math functions
253    Abs(Box<UnaryFunc>),
254    Round(Box<RoundFunc>),
255    Floor(Box<FloorFunc>),
256    Ceil(Box<CeilFunc>),
257    Power(Box<BinaryFunc>),
258    Sqrt(Box<UnaryFunc>),
259    Cbrt(Box<UnaryFunc>),
260    Ln(Box<UnaryFunc>),
261    Log(Box<LogFunc>),
262    Exp(Box<UnaryFunc>),
263    Sign(Box<UnaryFunc>),
264    Greatest(Box<VarArgFunc>),
265    Least(Box<VarArgFunc>),
266
267    // Date/time functions
268    CurrentDate(CurrentDate),
269    CurrentTime(CurrentTime),
270    CurrentTimestamp(CurrentTimestamp),
271    CurrentTimestampLTZ(CurrentTimestampLTZ),
272    AtTimeZone(Box<AtTimeZone>),
273    DateAdd(Box<DateAddFunc>),
274    DateSub(Box<DateAddFunc>),
275    DateDiff(Box<DateDiffFunc>),
276    DateTrunc(Box<DateTruncFunc>),
277    Extract(Box<ExtractFunc>),
278    ToDate(Box<ToDateFunc>),
279    ToTimestamp(Box<ToTimestampFunc>),
280    Date(Box<UnaryFunc>),
281    Time(Box<UnaryFunc>),
282    DateFromUnixDate(Box<UnaryFunc>),
283    UnixDate(Box<UnaryFunc>),
284    UnixSeconds(Box<UnaryFunc>),
285    UnixMillis(Box<UnaryFunc>),
286    UnixMicros(Box<UnaryFunc>),
287    UnixToTimeStr(Box<BinaryFunc>),
288    TimeStrToDate(Box<UnaryFunc>),
289    DateToDi(Box<UnaryFunc>),
290    DiToDate(Box<UnaryFunc>),
291    TsOrDiToDi(Box<UnaryFunc>),
292    TsOrDsToDatetime(Box<UnaryFunc>),
293    TsOrDsToTimestamp(Box<UnaryFunc>),
294    YearOfWeek(Box<UnaryFunc>),
295    YearOfWeekIso(Box<UnaryFunc>),
296
297    // Control flow functions
298    Coalesce(Box<VarArgFunc>),
299    NullIf(Box<BinaryFunc>),
300    IfFunc(Box<IfFunc>),
301    IfNull(Box<BinaryFunc>),
302    Nvl(Box<BinaryFunc>),
303    Nvl2(Box<Nvl2Func>),
304
305    // Type conversion
306    TryCast(Box<Cast>),
307    SafeCast(Box<Cast>),
308
309    // Typed aggregate functions
310    Count(Box<CountFunc>),
311    Sum(Box<AggFunc>),
312    Avg(Box<AggFunc>),
313    Min(Box<AggFunc>),
314    Max(Box<AggFunc>),
315    GroupConcat(Box<GroupConcatFunc>),
316    StringAgg(Box<StringAggFunc>),
317    ListAgg(Box<ListAggFunc>),
318    ArrayAgg(Box<AggFunc>),
319    CountIf(Box<AggFunc>),
320    SumIf(Box<SumIfFunc>),
321    Stddev(Box<AggFunc>),
322    StddevPop(Box<AggFunc>),
323    StddevSamp(Box<AggFunc>),
324    Variance(Box<AggFunc>),
325    VarPop(Box<AggFunc>),
326    VarSamp(Box<AggFunc>),
327    Median(Box<AggFunc>),
328    Mode(Box<AggFunc>),
329    First(Box<AggFunc>),
330    Last(Box<AggFunc>),
331    AnyValue(Box<AggFunc>),
332    ApproxDistinct(Box<AggFunc>),
333    ApproxCountDistinct(Box<AggFunc>),
334    ApproxPercentile(Box<ApproxPercentileFunc>),
335    Percentile(Box<PercentileFunc>),
336    LogicalAnd(Box<AggFunc>),
337    LogicalOr(Box<AggFunc>),
338    Skewness(Box<AggFunc>),
339    BitwiseCount(Box<UnaryFunc>),
340    ArrayConcatAgg(Box<AggFunc>),
341    ArrayUniqueAgg(Box<AggFunc>),
342    BoolXorAgg(Box<AggFunc>),
343
344    // Typed window functions
345    RowNumber(RowNumber),
346    Rank(Rank),
347    DenseRank(DenseRank),
348    NTile(Box<NTileFunc>),
349    Lead(Box<LeadLagFunc>),
350    Lag(Box<LeadLagFunc>),
351    FirstValue(Box<ValueFunc>),
352    LastValue(Box<ValueFunc>),
353    NthValue(Box<NthValueFunc>),
354    PercentRank(PercentRank),
355    CumeDist(CumeDist),
356    PercentileCont(Box<PercentileFunc>),
357    PercentileDisc(Box<PercentileFunc>),
358
359    // Additional string functions
360    Contains(Box<BinaryFunc>),
361    StartsWith(Box<BinaryFunc>),
362    EndsWith(Box<BinaryFunc>),
363    Position(Box<PositionFunc>),
364    Initcap(Box<UnaryFunc>),
365    Ascii(Box<UnaryFunc>),
366    Chr(Box<UnaryFunc>),
367    /// MySQL CHAR function with multiple args and optional USING charset
368    CharFunc(Box<CharFunc>),
369    Soundex(Box<UnaryFunc>),
370    Levenshtein(Box<BinaryFunc>),
371    ByteLength(Box<UnaryFunc>),
372    Hex(Box<UnaryFunc>),
373    LowerHex(Box<UnaryFunc>),
374    Unicode(Box<UnaryFunc>),
375
376    // Additional math functions
377    ModFunc(Box<BinaryFunc>),
378    Random(Random),
379    Rand(Box<Rand>),
380    TruncFunc(Box<TruncateFunc>),
381    Pi(Pi),
382    Radians(Box<UnaryFunc>),
383    Degrees(Box<UnaryFunc>),
384    Sin(Box<UnaryFunc>),
385    Cos(Box<UnaryFunc>),
386    Tan(Box<UnaryFunc>),
387    Asin(Box<UnaryFunc>),
388    Acos(Box<UnaryFunc>),
389    Atan(Box<UnaryFunc>),
390    Atan2(Box<BinaryFunc>),
391    IsNan(Box<UnaryFunc>),
392    IsInf(Box<UnaryFunc>),
393    IntDiv(Box<BinaryFunc>),
394
395    // Control flow
396    Decode(Box<DecodeFunc>),
397
398    // Additional date/time functions
399    DateFormat(Box<DateFormatFunc>),
400    FormatDate(Box<DateFormatFunc>),
401    Year(Box<UnaryFunc>),
402    Month(Box<UnaryFunc>),
403    Day(Box<UnaryFunc>),
404    Hour(Box<UnaryFunc>),
405    Minute(Box<UnaryFunc>),
406    Second(Box<UnaryFunc>),
407    DayOfWeek(Box<UnaryFunc>),
408    DayOfWeekIso(Box<UnaryFunc>),
409    DayOfMonth(Box<UnaryFunc>),
410    DayOfYear(Box<UnaryFunc>),
411    WeekOfYear(Box<UnaryFunc>),
412    Quarter(Box<UnaryFunc>),
413    AddMonths(Box<BinaryFunc>),
414    MonthsBetween(Box<BinaryFunc>),
415    LastDay(Box<LastDayFunc>),
416    NextDay(Box<BinaryFunc>),
417    Epoch(Box<UnaryFunc>),
418    EpochMs(Box<UnaryFunc>),
419    FromUnixtime(Box<FromUnixtimeFunc>),
420    UnixTimestamp(Box<UnixTimestampFunc>),
421    MakeDate(Box<MakeDateFunc>),
422    MakeTimestamp(Box<MakeTimestampFunc>),
423    TimestampTrunc(Box<DateTruncFunc>),
424    TimeStrToUnix(Box<UnaryFunc>),
425
426    // Session/User functions
427    SessionUser(SessionUser),
428
429    // Hash/Crypto functions
430    SHA(Box<UnaryFunc>),
431    SHA1Digest(Box<UnaryFunc>),
432
433    // Time conversion functions
434    TimeToUnix(Box<UnaryFunc>),
435
436    // Array functions
437    ArrayFunc(Box<ArrayConstructor>),
438    ArrayLength(Box<UnaryFunc>),
439    ArraySize(Box<UnaryFunc>),
440    Cardinality(Box<UnaryFunc>),
441    ArrayContains(Box<BinaryFunc>),
442    ArrayPosition(Box<BinaryFunc>),
443    ArrayAppend(Box<BinaryFunc>),
444    ArrayPrepend(Box<BinaryFunc>),
445    ArrayConcat(Box<VarArgFunc>),
446    ArraySort(Box<ArraySortFunc>),
447    ArrayReverse(Box<UnaryFunc>),
448    ArrayDistinct(Box<UnaryFunc>),
449    ArrayJoin(Box<ArrayJoinFunc>),
450    ArrayToString(Box<ArrayJoinFunc>),
451    Unnest(Box<UnnestFunc>),
452    Explode(Box<UnaryFunc>),
453    ExplodeOuter(Box<UnaryFunc>),
454    ArrayFilter(Box<ArrayFilterFunc>),
455    ArrayTransform(Box<ArrayTransformFunc>),
456    ArrayFlatten(Box<UnaryFunc>),
457    ArrayCompact(Box<UnaryFunc>),
458    ArrayIntersect(Box<VarArgFunc>),
459    ArrayUnion(Box<BinaryFunc>),
460    ArrayExcept(Box<BinaryFunc>),
461    ArrayRemove(Box<BinaryFunc>),
462    ArrayZip(Box<VarArgFunc>),
463    Sequence(Box<SequenceFunc>),
464    Generate(Box<SequenceFunc>),
465    ExplodingGenerateSeries(Box<SequenceFunc>),
466    ToArray(Box<UnaryFunc>),
467    StarMap(Box<BinaryFunc>),
468
469    // Struct functions
470    StructFunc(Box<StructConstructor>),
471    StructExtract(Box<StructExtractFunc>),
472    NamedStruct(Box<NamedStructFunc>),
473
474    // Map functions
475    MapFunc(Box<MapConstructor>),
476    MapFromEntries(Box<UnaryFunc>),
477    MapFromArrays(Box<BinaryFunc>),
478    MapKeys(Box<UnaryFunc>),
479    MapValues(Box<UnaryFunc>),
480    MapContainsKey(Box<BinaryFunc>),
481    MapConcat(Box<VarArgFunc>),
482    ElementAt(Box<BinaryFunc>),
483    TransformKeys(Box<TransformFunc>),
484    TransformValues(Box<TransformFunc>),
485
486    // Exasol: function call with EMITS clause
487    FunctionEmits(Box<FunctionEmits>),
488
489    // JSON functions
490    JsonExtract(Box<JsonExtractFunc>),
491    JsonExtractScalar(Box<JsonExtractFunc>),
492    JsonExtractPath(Box<JsonPathFunc>),
493    JsonArray(Box<VarArgFunc>),
494    JsonObject(Box<JsonObjectFunc>),
495    JsonQuery(Box<JsonExtractFunc>),
496    JsonValue(Box<JsonExtractFunc>),
497    JsonArrayLength(Box<UnaryFunc>),
498    JsonKeys(Box<UnaryFunc>),
499    JsonType(Box<UnaryFunc>),
500    ParseJson(Box<UnaryFunc>),
501    ToJson(Box<UnaryFunc>),
502    JsonSet(Box<JsonModifyFunc>),
503    JsonInsert(Box<JsonModifyFunc>),
504    JsonRemove(Box<JsonPathFunc>),
505    JsonMergePatch(Box<BinaryFunc>),
506    JsonArrayAgg(Box<JsonArrayAggFunc>),
507    JsonObjectAgg(Box<JsonObjectAggFunc>),
508
509    // Type casting/conversion
510    Convert(Box<ConvertFunc>),
511    Typeof(Box<UnaryFunc>),
512
513    // Additional expressions
514    Lambda(Box<LambdaExpr>),
515    Parameter(Box<Parameter>),
516    Placeholder(Placeholder),
517    NamedArgument(Box<NamedArgument>),
518    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
519    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
520    TableArgument(Box<TableArgument>),
521    SqlComment(Box<SqlComment>),
522
523    // Additional predicates
524    NullSafeEq(Box<BinaryOp>),
525    NullSafeNeq(Box<BinaryOp>),
526    Glob(Box<BinaryOp>),
527    SimilarTo(Box<SimilarToExpr>),
528    Any(Box<QuantifiedExpr>),
529    All(Box<QuantifiedExpr>),
530    Overlaps(Box<OverlapsExpr>),
531
532    // Bitwise operations
533    BitwiseLeftShift(Box<BinaryOp>),
534    BitwiseRightShift(Box<BinaryOp>),
535    BitwiseAndAgg(Box<AggFunc>),
536    BitwiseOrAgg(Box<AggFunc>),
537    BitwiseXorAgg(Box<AggFunc>),
538
539    // Array/struct/map access
540    Subscript(Box<Subscript>),
541    Dot(Box<DotAccess>),
542    MethodCall(Box<MethodCall>),
543    ArraySlice(Box<ArraySlice>),
544
545    // DDL statements
546    CreateTable(Box<CreateTable>),
547    DropTable(Box<DropTable>),
548    Undrop(Box<Undrop>),
549    AlterTable(Box<AlterTable>),
550    CreateIndex(Box<CreateIndex>),
551    DropIndex(Box<DropIndex>),
552    CreateView(Box<CreateView>),
553    DropView(Box<DropView>),
554    AlterView(Box<AlterView>),
555    AlterIndex(Box<AlterIndex>),
556    Truncate(Box<Truncate>),
557    Use(Box<Use>),
558    Cache(Box<Cache>),
559    Uncache(Box<Uncache>),
560    LoadData(Box<LoadData>),
561    Pragma(Box<Pragma>),
562    Grant(Box<Grant>),
563    Revoke(Box<Revoke>),
564    Comment(Box<Comment>),
565    SetStatement(Box<SetStatement>),
566    // Phase 4: Additional DDL statements
567    CreateSchema(Box<CreateSchema>),
568    DropSchema(Box<DropSchema>),
569    DropNamespace(Box<DropNamespace>),
570    CreateDatabase(Box<CreateDatabase>),
571    DropDatabase(Box<DropDatabase>),
572    CreateFunction(Box<CreateFunction>),
573    DropFunction(Box<DropFunction>),
574    CreateProcedure(Box<CreateProcedure>),
575    DropProcedure(Box<DropProcedure>),
576    CreateSequence(Box<CreateSequence>),
577    CreateSynonym(Box<CreateSynonym>),
578    DropSequence(Box<DropSequence>),
579    AlterSequence(Box<AlterSequence>),
580    CreateTrigger(Box<CreateTrigger>),
581    DropTrigger(Box<DropTrigger>),
582    CreateType(Box<CreateType>),
583    DropType(Box<DropType>),
584    Describe(Box<Describe>),
585    Show(Box<Show>),
586
587    // Transaction and other commands
588    Command(Box<Command>),
589    Kill(Box<Kill>),
590    /// EXEC/EXECUTE statement (TSQL stored procedure call)
591    Execute(Box<ExecuteStatement>),
592
593    /// Snowflake CREATE TASK statement
594    CreateTask(Box<CreateTask>),
595
596    // Placeholder for unparsed/raw SQL
597    Raw(Raw),
598
599    // Paren for grouping
600    Paren(Box<Paren>),
601
602    // Expression with trailing comments (for round-trip preservation)
603    Annotated(Box<Annotated>),
604
605    // === BATCH GENERATED EXPRESSION TYPES ===
606    // Generated from Python sqlglot expressions.py
607    Refresh(Box<Refresh>),
608    LockingStatement(Box<LockingStatement>),
609    SequenceProperties(Box<SequenceProperties>),
610    TruncateTable(Box<TruncateTable>),
611    Clone(Box<Clone>),
612    Attach(Box<Attach>),
613    Detach(Box<Detach>),
614    Install(Box<Install>),
615    Summarize(Box<Summarize>),
616    Declare(Box<Declare>),
617    DeclareItem(Box<DeclareItem>),
618    Set(Box<Set>),
619    Heredoc(Box<Heredoc>),
620    SetItem(Box<SetItem>),
621    QueryBand(Box<QueryBand>),
622    UserDefinedFunction(Box<UserDefinedFunction>),
623    RecursiveWithSearch(Box<RecursiveWithSearch>),
624    ProjectionDef(Box<ProjectionDef>),
625    TableAlias(Box<TableAlias>),
626    ByteString(Box<ByteString>),
627    HexStringExpr(Box<HexStringExpr>),
628    UnicodeString(Box<UnicodeString>),
629    ColumnPosition(Box<ColumnPosition>),
630    ColumnDef(Box<ColumnDef>),
631    AlterColumn(Box<AlterColumn>),
632    AlterSortKey(Box<AlterSortKey>),
633    AlterSet(Box<AlterSet>),
634    RenameColumn(Box<RenameColumn>),
635    Comprehension(Box<Comprehension>),
636    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
637    MergeTreeTTL(Box<MergeTreeTTL>),
638    IndexConstraintOption(Box<IndexConstraintOption>),
639    ColumnConstraint(Box<ColumnConstraint>),
640    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
641    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
642    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
643    CheckColumnConstraint(Box<CheckColumnConstraint>),
644    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
645    CompressColumnConstraint(Box<CompressColumnConstraint>),
646    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
647    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
648    WithOperator(Box<WithOperator>),
649    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
650    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
651    CommentColumnConstraint(CommentColumnConstraint),
652    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
653    IndexColumnConstraint(Box<IndexColumnConstraint>),
654    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
655    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
656    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
657    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
658    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
659    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
660    InOutColumnConstraint(Box<InOutColumnConstraint>),
661    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
662    PathColumnConstraint(Box<PathColumnConstraint>),
663    Constraint(Box<Constraint>),
664    Export(Box<Export>),
665    Filter(Box<Filter>),
666    Changes(Box<Changes>),
667    CopyParameter(Box<CopyParameter>),
668    Credentials(Box<Credentials>),
669    Directory(Box<Directory>),
670    ForeignKey(Box<ForeignKey>),
671    ColumnPrefix(Box<ColumnPrefix>),
672    PrimaryKey(Box<PrimaryKey>),
673    IntoClause(Box<IntoClause>),
674    JoinHint(Box<JoinHint>),
675    Opclass(Box<Opclass>),
676    Index(Box<Index>),
677    IndexParameters(Box<IndexParameters>),
678    ConditionalInsert(Box<ConditionalInsert>),
679    MultitableInserts(Box<MultitableInserts>),
680    OnConflict(Box<OnConflict>),
681    OnCondition(Box<OnCondition>),
682    Returning(Box<Returning>),
683    Introducer(Box<Introducer>),
684    PartitionRange(Box<PartitionRange>),
685    Fetch(Box<Fetch>),
686    Group(Box<Group>),
687    Cube(Box<Cube>),
688    Rollup(Box<Rollup>),
689    GroupingSets(Box<GroupingSets>),
690    LimitOptions(Box<LimitOptions>),
691    Lateral(Box<Lateral>),
692    TableFromRows(Box<TableFromRows>),
693    RowsFrom(Box<RowsFrom>),
694    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
695    WithFill(Box<WithFill>),
696    Property(Box<Property>),
697    GrantPrivilege(Box<GrantPrivilege>),
698    GrantPrincipal(Box<GrantPrincipal>),
699    AllowedValuesProperty(Box<AllowedValuesProperty>),
700    AlgorithmProperty(Box<AlgorithmProperty>),
701    AutoIncrementProperty(Box<AutoIncrementProperty>),
702    AutoRefreshProperty(Box<AutoRefreshProperty>),
703    BackupProperty(Box<BackupProperty>),
704    BuildProperty(Box<BuildProperty>),
705    BlockCompressionProperty(Box<BlockCompressionProperty>),
706    CharacterSetProperty(Box<CharacterSetProperty>),
707    ChecksumProperty(Box<ChecksumProperty>),
708    CollateProperty(Box<CollateProperty>),
709    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
710    DataDeletionProperty(Box<DataDeletionProperty>),
711    DefinerProperty(Box<DefinerProperty>),
712    DistKeyProperty(Box<DistKeyProperty>),
713    DistributedByProperty(Box<DistributedByProperty>),
714    DistStyleProperty(Box<DistStyleProperty>),
715    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
716    EngineProperty(Box<EngineProperty>),
717    ToTableProperty(Box<ToTableProperty>),
718    ExecuteAsProperty(Box<ExecuteAsProperty>),
719    ExternalProperty(Box<ExternalProperty>),
720    FallbackProperty(Box<FallbackProperty>),
721    FileFormatProperty(Box<FileFormatProperty>),
722    CredentialsProperty(Box<CredentialsProperty>),
723    FreespaceProperty(Box<FreespaceProperty>),
724    InheritsProperty(Box<InheritsProperty>),
725    InputModelProperty(Box<InputModelProperty>),
726    OutputModelProperty(Box<OutputModelProperty>),
727    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
728    JournalProperty(Box<JournalProperty>),
729    LanguageProperty(Box<LanguageProperty>),
730    EnviromentProperty(Box<EnviromentProperty>),
731    ClusteredByProperty(Box<ClusteredByProperty>),
732    DictProperty(Box<DictProperty>),
733    DictRange(Box<DictRange>),
734    OnCluster(Box<OnCluster>),
735    LikeProperty(Box<LikeProperty>),
736    LocationProperty(Box<LocationProperty>),
737    LockProperty(Box<LockProperty>),
738    LockingProperty(Box<LockingProperty>),
739    LogProperty(Box<LogProperty>),
740    MaterializedProperty(Box<MaterializedProperty>),
741    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
742    OnProperty(Box<OnProperty>),
743    OnCommitProperty(Box<OnCommitProperty>),
744    PartitionedByProperty(Box<PartitionedByProperty>),
745    PartitionByProperty(Box<PartitionByProperty>),
746    PartitionedByBucket(Box<PartitionedByBucket>),
747    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
748    PartitionByTruncate(Box<PartitionByTruncate>),
749    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
750    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
751    PartitionByListProperty(Box<PartitionByListProperty>),
752    PartitionList(Box<PartitionList>),
753    Partition(Box<Partition>),
754    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
755    UniqueKeyProperty(Box<UniqueKeyProperty>),
756    RollupProperty(Box<RollupProperty>),
757    PartitionBoundSpec(Box<PartitionBoundSpec>),
758    PartitionedOfProperty(Box<PartitionedOfProperty>),
759    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
760    ReturnsProperty(Box<ReturnsProperty>),
761    RowFormatProperty(Box<RowFormatProperty>),
762    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
763    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
764    QueryTransform(Box<QueryTransform>),
765    SampleProperty(Box<SampleProperty>),
766    SecurityProperty(Box<SecurityProperty>),
767    SchemaCommentProperty(Box<SchemaCommentProperty>),
768    SemanticView(Box<SemanticView>),
769    SerdeProperties(Box<SerdeProperties>),
770    SetProperty(Box<SetProperty>),
771    SharingProperty(Box<SharingProperty>),
772    SetConfigProperty(Box<SetConfigProperty>),
773    SettingsProperty(Box<SettingsProperty>),
774    SortKeyProperty(Box<SortKeyProperty>),
775    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
776    SqlSecurityProperty(Box<SqlSecurityProperty>),
777    StabilityProperty(Box<StabilityProperty>),
778    StorageHandlerProperty(Box<StorageHandlerProperty>),
779    TemporaryProperty(Box<TemporaryProperty>),
780    Tags(Box<Tags>),
781    TransformModelProperty(Box<TransformModelProperty>),
782    TransientProperty(Box<TransientProperty>),
783    UsingTemplateProperty(Box<UsingTemplateProperty>),
784    ViewAttributeProperty(Box<ViewAttributeProperty>),
785    VolatileProperty(Box<VolatileProperty>),
786    WithDataProperty(Box<WithDataProperty>),
787    WithJournalTableProperty(Box<WithJournalTableProperty>),
788    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
789    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
790    WithProcedureOptions(Box<WithProcedureOptions>),
791    EncodeProperty(Box<EncodeProperty>),
792    IncludeProperty(Box<IncludeProperty>),
793    Properties(Box<Properties>),
794    OptionsProperty(Box<OptionsProperty>),
795    InputOutputFormat(Box<InputOutputFormat>),
796    Reference(Box<Reference>),
797    QueryOption(Box<QueryOption>),
798    WithTableHint(Box<WithTableHint>),
799    IndexTableHint(Box<IndexTableHint>),
800    HistoricalData(Box<HistoricalData>),
801    Get(Box<Get>),
802    SetOperation(Box<SetOperation>),
803    Var(Box<Var>),
804    Variadic(Box<Variadic>),
805    Version(Box<Version>),
806    Schema(Box<Schema>),
807    Lock(Box<Lock>),
808    TableSample(Box<TableSample>),
809    Tag(Box<Tag>),
810    UnpivotColumns(Box<UnpivotColumns>),
811    WindowSpec(Box<WindowSpec>),
812    SessionParameter(Box<SessionParameter>),
813    PseudoType(Box<PseudoType>),
814    ObjectIdentifier(Box<ObjectIdentifier>),
815    Transaction(Box<Transaction>),
816    Commit(Box<Commit>),
817    Rollback(Box<Rollback>),
818    AlterSession(Box<AlterSession>),
819    Analyze(Box<Analyze>),
820    AnalyzeStatistics(Box<AnalyzeStatistics>),
821    AnalyzeHistogram(Box<AnalyzeHistogram>),
822    AnalyzeSample(Box<AnalyzeSample>),
823    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
824    AnalyzeDelete(Box<AnalyzeDelete>),
825    AnalyzeWith(Box<AnalyzeWith>),
826    AnalyzeValidate(Box<AnalyzeValidate>),
827    AddPartition(Box<AddPartition>),
828    AttachOption(Box<AttachOption>),
829    DropPartition(Box<DropPartition>),
830    ReplacePartition(Box<ReplacePartition>),
831    DPipe(Box<DPipe>),
832    Operator(Box<Operator>),
833    PivotAny(Box<PivotAny>),
834    Aliases(Box<Aliases>),
835    AtIndex(Box<AtIndex>),
836    FromTimeZone(Box<FromTimeZone>),
837    FormatPhrase(Box<FormatPhrase>),
838    ForIn(Box<ForIn>),
839    TimeUnit(Box<TimeUnit>),
840    IntervalOp(Box<IntervalOp>),
841    IntervalSpan(Box<IntervalSpan>),
842    HavingMax(Box<HavingMax>),
843    CosineDistance(Box<CosineDistance>),
844    DotProduct(Box<DotProduct>),
845    EuclideanDistance(Box<EuclideanDistance>),
846    ManhattanDistance(Box<ManhattanDistance>),
847    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
848    Booland(Box<Booland>),
849    Boolor(Box<Boolor>),
850    ParameterizedAgg(Box<ParameterizedAgg>),
851    ArgMax(Box<ArgMax>),
852    ArgMin(Box<ArgMin>),
853    ApproxTopK(Box<ApproxTopK>),
854    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
855    ApproxTopKCombine(Box<ApproxTopKCombine>),
856    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
857    ApproxTopSum(Box<ApproxTopSum>),
858    ApproxQuantiles(Box<ApproxQuantiles>),
859    Minhash(Box<Minhash>),
860    FarmFingerprint(Box<FarmFingerprint>),
861    Float64(Box<Float64>),
862    Transform(Box<Transform>),
863    Translate(Box<Translate>),
864    Grouping(Box<Grouping>),
865    GroupingId(Box<GroupingId>),
866    Anonymous(Box<Anonymous>),
867    AnonymousAggFunc(Box<AnonymousAggFunc>),
868    CombinedAggFunc(Box<CombinedAggFunc>),
869    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
870    HashAgg(Box<HashAgg>),
871    Hll(Box<Hll>),
872    Apply(Box<Apply>),
873    ToBoolean(Box<ToBoolean>),
874    List(Box<List>),
875    ToMap(Box<ToMap>),
876    Pad(Box<Pad>),
877    ToChar(Box<ToChar>),
878    ToNumber(Box<ToNumber>),
879    ToDouble(Box<ToDouble>),
880    Int64(Box<UnaryFunc>),
881    StringFunc(Box<StringFunc>),
882    ToDecfloat(Box<ToDecfloat>),
883    TryToDecfloat(Box<TryToDecfloat>),
884    ToFile(Box<ToFile>),
885    Columns(Box<Columns>),
886    ConvertToCharset(Box<ConvertToCharset>),
887    ConvertTimezone(Box<ConvertTimezone>),
888    GenerateSeries(Box<GenerateSeries>),
889    AIAgg(Box<AIAgg>),
890    AIClassify(Box<AIClassify>),
891    ArrayAll(Box<ArrayAll>),
892    ArrayAny(Box<ArrayAny>),
893    ArrayConstructCompact(Box<ArrayConstructCompact>),
894    StPoint(Box<StPoint>),
895    StDistance(Box<StDistance>),
896    StringToArray(Box<StringToArray>),
897    ArraySum(Box<ArraySum>),
898    ObjectAgg(Box<ObjectAgg>),
899    CastToStrType(Box<CastToStrType>),
900    CheckJson(Box<CheckJson>),
901    CheckXml(Box<CheckXml>),
902    TranslateCharacters(Box<TranslateCharacters>),
903    CurrentSchemas(Box<CurrentSchemas>),
904    CurrentDatetime(Box<CurrentDatetime>),
905    Localtime(Box<Localtime>),
906    Localtimestamp(Box<Localtimestamp>),
907    Systimestamp(Box<Systimestamp>),
908    CurrentSchema(Box<CurrentSchema>),
909    CurrentUser(Box<CurrentUser>),
910    UtcTime(Box<UtcTime>),
911    UtcTimestamp(Box<UtcTimestamp>),
912    Timestamp(Box<TimestampFunc>),
913    DateBin(Box<DateBin>),
914    Datetime(Box<Datetime>),
915    DatetimeAdd(Box<DatetimeAdd>),
916    DatetimeSub(Box<DatetimeSub>),
917    DatetimeDiff(Box<DatetimeDiff>),
918    DatetimeTrunc(Box<DatetimeTrunc>),
919    Dayname(Box<Dayname>),
920    MakeInterval(Box<MakeInterval>),
921    PreviousDay(Box<PreviousDay>),
922    Elt(Box<Elt>),
923    TimestampAdd(Box<TimestampAdd>),
924    TimestampSub(Box<TimestampSub>),
925    TimestampDiff(Box<TimestampDiff>),
926    TimeSlice(Box<TimeSlice>),
927    TimeAdd(Box<TimeAdd>),
928    TimeSub(Box<TimeSub>),
929    TimeDiff(Box<TimeDiff>),
930    TimeTrunc(Box<TimeTrunc>),
931    DateFromParts(Box<DateFromParts>),
932    TimeFromParts(Box<TimeFromParts>),
933    DecodeCase(Box<DecodeCase>),
934    Decrypt(Box<Decrypt>),
935    DecryptRaw(Box<DecryptRaw>),
936    Encode(Box<Encode>),
937    Encrypt(Box<Encrypt>),
938    EncryptRaw(Box<EncryptRaw>),
939    EqualNull(Box<EqualNull>),
940    ToBinary(Box<ToBinary>),
941    Base64DecodeBinary(Box<Base64DecodeBinary>),
942    Base64DecodeString(Box<Base64DecodeString>),
943    Base64Encode(Box<Base64Encode>),
944    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
945    TryBase64DecodeString(Box<TryBase64DecodeString>),
946    GapFill(Box<GapFill>),
947    GenerateDateArray(Box<GenerateDateArray>),
948    GenerateTimestampArray(Box<GenerateTimestampArray>),
949    GetExtract(Box<GetExtract>),
950    Getbit(Box<Getbit>),
951    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
952    HexEncode(Box<HexEncode>),
953    Compress(Box<Compress>),
954    DecompressBinary(Box<DecompressBinary>),
955    DecompressString(Box<DecompressString>),
956    Xor(Box<Xor>),
957    Nullif(Box<Nullif>),
958    JSON(Box<JSON>),
959    JSONPath(Box<JSONPath>),
960    JSONPathFilter(Box<JSONPathFilter>),
961    JSONPathKey(Box<JSONPathKey>),
962    JSONPathRecursive(Box<JSONPathRecursive>),
963    JSONPathScript(Box<JSONPathScript>),
964    JSONPathSlice(Box<JSONPathSlice>),
965    JSONPathSelector(Box<JSONPathSelector>),
966    JSONPathSubscript(Box<JSONPathSubscript>),
967    JSONPathUnion(Box<JSONPathUnion>),
968    Format(Box<Format>),
969    JSONKeys(Box<JSONKeys>),
970    JSONKeyValue(Box<JSONKeyValue>),
971    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
972    JSONObject(Box<JSONObject>),
973    JSONObjectAgg(Box<JSONObjectAgg>),
974    JSONBObjectAgg(Box<JSONBObjectAgg>),
975    JSONArray(Box<JSONArray>),
976    JSONArrayAgg(Box<JSONArrayAgg>),
977    JSONExists(Box<JSONExists>),
978    JSONColumnDef(Box<JSONColumnDef>),
979    JSONSchema(Box<JSONSchema>),
980    JSONSet(Box<JSONSet>),
981    JSONStripNulls(Box<JSONStripNulls>),
982    JSONValue(Box<JSONValue>),
983    JSONValueArray(Box<JSONValueArray>),
984    JSONRemove(Box<JSONRemove>),
985    JSONTable(Box<JSONTable>),
986    JSONType(Box<JSONType>),
987    ObjectInsert(Box<ObjectInsert>),
988    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
989    OpenJSON(Box<OpenJSON>),
990    JSONBExists(Box<JSONBExists>),
991    JSONBContains(Box<BinaryFunc>),
992    JSONBExtract(Box<BinaryFunc>),
993    JSONCast(Box<JSONCast>),
994    JSONExtract(Box<JSONExtract>),
995    JSONExtractQuote(Box<JSONExtractQuote>),
996    JSONExtractArray(Box<JSONExtractArray>),
997    JSONExtractScalar(Box<JSONExtractScalar>),
998    JSONBExtractScalar(Box<JSONBExtractScalar>),
999    JSONFormat(Box<JSONFormat>),
1000    JSONBool(Box<UnaryFunc>),
1001    JSONPathRoot(JSONPathRoot),
1002    JSONArrayAppend(Box<JSONArrayAppend>),
1003    JSONArrayContains(Box<JSONArrayContains>),
1004    JSONArrayInsert(Box<JSONArrayInsert>),
1005    ParseJSON(Box<ParseJSON>),
1006    ParseUrl(Box<ParseUrl>),
1007    ParseIp(Box<ParseIp>),
1008    ParseTime(Box<ParseTime>),
1009    ParseDatetime(Box<ParseDatetime>),
1010    Map(Box<Map>),
1011    MapCat(Box<MapCat>),
1012    MapDelete(Box<MapDelete>),
1013    MapInsert(Box<MapInsert>),
1014    MapPick(Box<MapPick>),
1015    ScopeResolution(Box<ScopeResolution>),
1016    Slice(Box<Slice>),
1017    VarMap(Box<VarMap>),
1018    MatchAgainst(Box<MatchAgainst>),
1019    MD5Digest(Box<MD5Digest>),
1020    MD5NumberLower64(Box<UnaryFunc>),
1021    MD5NumberUpper64(Box<UnaryFunc>),
1022    Monthname(Box<Monthname>),
1023    Ntile(Box<Ntile>),
1024    Normalize(Box<Normalize>),
1025    Normal(Box<Normal>),
1026    Predict(Box<Predict>),
1027    MLTranslate(Box<MLTranslate>),
1028    FeaturesAtTime(Box<FeaturesAtTime>),
1029    GenerateEmbedding(Box<GenerateEmbedding>),
1030    MLForecast(Box<MLForecast>),
1031    ModelAttribute(Box<ModelAttribute>),
1032    VectorSearch(Box<VectorSearch>),
1033    Quantile(Box<Quantile>),
1034    ApproxQuantile(Box<ApproxQuantile>),
1035    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1036    Randn(Box<Randn>),
1037    Randstr(Box<Randstr>),
1038    RangeN(Box<RangeN>),
1039    RangeBucket(Box<RangeBucket>),
1040    ReadCSV(Box<ReadCSV>),
1041    ReadParquet(Box<ReadParquet>),
1042    Reduce(Box<Reduce>),
1043    RegexpExtractAll(Box<RegexpExtractAll>),
1044    RegexpILike(Box<RegexpILike>),
1045    RegexpFullMatch(Box<RegexpFullMatch>),
1046    RegexpInstr(Box<RegexpInstr>),
1047    RegexpSplit(Box<RegexpSplit>),
1048    RegexpCount(Box<RegexpCount>),
1049    RegrValx(Box<RegrValx>),
1050    RegrValy(Box<RegrValy>),
1051    RegrAvgy(Box<RegrAvgy>),
1052    RegrAvgx(Box<RegrAvgx>),
1053    RegrCount(Box<RegrCount>),
1054    RegrIntercept(Box<RegrIntercept>),
1055    RegrR2(Box<RegrR2>),
1056    RegrSxx(Box<RegrSxx>),
1057    RegrSxy(Box<RegrSxy>),
1058    RegrSyy(Box<RegrSyy>),
1059    RegrSlope(Box<RegrSlope>),
1060    SafeAdd(Box<SafeAdd>),
1061    SafeDivide(Box<SafeDivide>),
1062    SafeMultiply(Box<SafeMultiply>),
1063    SafeSubtract(Box<SafeSubtract>),
1064    SHA2(Box<SHA2>),
1065    SHA2Digest(Box<SHA2Digest>),
1066    SortArray(Box<SortArray>),
1067    SplitPart(Box<SplitPart>),
1068    SubstringIndex(Box<SubstringIndex>),
1069    StandardHash(Box<StandardHash>),
1070    StrPosition(Box<StrPosition>),
1071    Search(Box<Search>),
1072    SearchIp(Box<SearchIp>),
1073    StrToDate(Box<StrToDate>),
1074    DateStrToDate(Box<UnaryFunc>),
1075    DateToDateStr(Box<UnaryFunc>),
1076    StrToTime(Box<StrToTime>),
1077    StrToUnix(Box<StrToUnix>),
1078    StrToMap(Box<StrToMap>),
1079    NumberToStr(Box<NumberToStr>),
1080    FromBase(Box<FromBase>),
1081    Stuff(Box<Stuff>),
1082    TimeToStr(Box<TimeToStr>),
1083    TimeStrToTime(Box<TimeStrToTime>),
1084    TsOrDsAdd(Box<TsOrDsAdd>),
1085    TsOrDsDiff(Box<TsOrDsDiff>),
1086    TsOrDsToDate(Box<TsOrDsToDate>),
1087    TsOrDsToTime(Box<TsOrDsToTime>),
1088    Unhex(Box<Unhex>),
1089    Uniform(Box<Uniform>),
1090    UnixToStr(Box<UnixToStr>),
1091    UnixToTime(Box<UnixToTime>),
1092    Uuid(Box<Uuid>),
1093    TimestampFromParts(Box<TimestampFromParts>),
1094    TimestampTzFromParts(Box<TimestampTzFromParts>),
1095    Corr(Box<Corr>),
1096    WidthBucket(Box<WidthBucket>),
1097    CovarSamp(Box<CovarSamp>),
1098    CovarPop(Box<CovarPop>),
1099    Week(Box<Week>),
1100    XMLElement(Box<XMLElement>),
1101    XMLGet(Box<XMLGet>),
1102    XMLTable(Box<XMLTable>),
1103    XMLKeyValueOption(Box<XMLKeyValueOption>),
1104    Zipf(Box<Zipf>),
1105    Merge(Box<Merge>),
1106    When(Box<When>),
1107    Whens(Box<Whens>),
1108    NextValueFor(Box<NextValueFor>),
1109    /// RETURN statement (DuckDB stored procedures)
1110    ReturnStmt(Box<Expression>),
1111}
1112
1113impl Expression {
1114    /// Create a `Column` variant, boxing the value automatically.
1115    #[inline]
1116    pub fn boxed_column(col: Column) -> Self {
1117        Expression::Column(Box::new(col))
1118    }
1119
1120    /// Create a `Table` variant, boxing the value automatically.
1121    #[inline]
1122    pub fn boxed_table(t: TableRef) -> Self {
1123        Expression::Table(Box::new(t))
1124    }
1125
1126    /// Returns `true` if this expression is a valid top-level SQL statement.
1127    ///
1128    /// Bare expressions like identifiers, literals, and function calls are not
1129    /// valid statements. This is used by `validate()` to reject inputs like
1130    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1131    /// plus the bare identifier `doo`.
1132    pub fn is_statement(&self) -> bool {
1133        match self {
1134            // Queries
1135            Expression::Select(_)
1136            | Expression::Union(_)
1137            | Expression::Intersect(_)
1138            | Expression::Except(_)
1139            | Expression::Subquery(_)
1140            | Expression::Values(_)
1141            | Expression::PipeOperator(_)
1142
1143            // DML
1144            | Expression::Insert(_)
1145            | Expression::Update(_)
1146            | Expression::Delete(_)
1147            | Expression::Copy(_)
1148            | Expression::Put(_)
1149            | Expression::Merge(_)
1150            | Expression::TryCatch(_)
1151
1152            // DDL
1153            | Expression::CreateTable(_)
1154            | Expression::DropTable(_)
1155            | Expression::Undrop(_)
1156            | Expression::AlterTable(_)
1157            | Expression::CreateIndex(_)
1158            | Expression::DropIndex(_)
1159            | Expression::CreateView(_)
1160            | Expression::DropView(_)
1161            | Expression::AlterView(_)
1162            | Expression::AlterIndex(_)
1163            | Expression::Truncate(_)
1164            | Expression::TruncateTable(_)
1165            | Expression::CreateSchema(_)
1166            | Expression::DropSchema(_)
1167            | Expression::DropNamespace(_)
1168            | Expression::CreateDatabase(_)
1169            | Expression::DropDatabase(_)
1170            | Expression::CreateFunction(_)
1171            | Expression::DropFunction(_)
1172            | Expression::CreateProcedure(_)
1173            | Expression::DropProcedure(_)
1174            | Expression::CreateSequence(_)
1175            | Expression::CreateSynonym(_)
1176            | Expression::DropSequence(_)
1177            | Expression::AlterSequence(_)
1178            | Expression::CreateTrigger(_)
1179            | Expression::DropTrigger(_)
1180            | Expression::CreateType(_)
1181            | Expression::DropType(_)
1182            | Expression::Comment(_)
1183
1184            // Session/Transaction/Control
1185            | Expression::Use(_)
1186            | Expression::Set(_)
1187            | Expression::SetStatement(_)
1188            | Expression::Transaction(_)
1189            | Expression::Commit(_)
1190            | Expression::Rollback(_)
1191            | Expression::Grant(_)
1192            | Expression::Revoke(_)
1193            | Expression::Cache(_)
1194            | Expression::Uncache(_)
1195            | Expression::LoadData(_)
1196            | Expression::Pragma(_)
1197            | Expression::Describe(_)
1198            | Expression::Show(_)
1199            | Expression::Kill(_)
1200            | Expression::Execute(_)
1201            | Expression::Declare(_)
1202            | Expression::Refresh(_)
1203            | Expression::AlterSession(_)
1204            | Expression::LockingStatement(_)
1205
1206            // Analyze
1207            | Expression::Analyze(_)
1208            | Expression::AnalyzeStatistics(_)
1209            | Expression::AnalyzeHistogram(_)
1210            | Expression::AnalyzeSample(_)
1211            | Expression::AnalyzeListChainedRows(_)
1212            | Expression::AnalyzeDelete(_)
1213
1214            // Attach/Detach/Install/Summarize
1215            | Expression::Attach(_)
1216            | Expression::Detach(_)
1217            | Expression::Install(_)
1218            | Expression::Summarize(_)
1219
1220            // Pivot at statement level
1221            | Expression::Pivot(_)
1222            | Expression::Unpivot(_)
1223
1224            // Command (raw/unparsed statements)
1225            | Expression::Command(_)
1226            | Expression::Raw(_)
1227            | Expression::CreateTask(_)
1228
1229            // Return statement
1230            | Expression::ReturnStmt(_) => true,
1231
1232            // Annotated wraps another expression with comments — check inner
1233            Expression::Annotated(a) => a.this.is_statement(),
1234
1235            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1236            Expression::Alias(a) => a.this.is_statement(),
1237
1238            // Everything else (identifiers, literals, operators, functions, etc.)
1239            _ => false,
1240        }
1241    }
1242
1243    /// Create a literal number expression from an integer.
1244    pub fn number(n: i64) -> Self {
1245        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1246    }
1247
1248    /// Create a single-quoted literal string expression.
1249    pub fn string(s: impl Into<String>) -> Self {
1250        Expression::Literal(Box::new(Literal::String(s.into())))
1251    }
1252
1253    /// Create a literal number expression from a float.
1254    pub fn float(f: f64) -> Self {
1255        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1256    }
1257
1258    /// Get the inferred type annotation, if present.
1259    ///
1260    /// For value-producing expressions with an `inferred_type` field, returns
1261    /// the stored type. For literals and boolean constants, computes the type
1262    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1263    pub fn inferred_type(&self) -> Option<&DataType> {
1264        match self {
1265            // Structs with inferred_type field
1266            Expression::And(op)
1267            | Expression::Or(op)
1268            | Expression::Add(op)
1269            | Expression::Sub(op)
1270            | Expression::Mul(op)
1271            | Expression::Div(op)
1272            | Expression::Mod(op)
1273            | Expression::Eq(op)
1274            | Expression::Neq(op)
1275            | Expression::Lt(op)
1276            | Expression::Lte(op)
1277            | Expression::Gt(op)
1278            | Expression::Gte(op)
1279            | Expression::Concat(op)
1280            | Expression::BitwiseAnd(op)
1281            | Expression::BitwiseOr(op)
1282            | Expression::BitwiseXor(op)
1283            | Expression::Adjacent(op)
1284            | Expression::TsMatch(op)
1285            | Expression::PropertyEQ(op)
1286            | Expression::ArrayContainsAll(op)
1287            | Expression::ArrayContainedBy(op)
1288            | Expression::ArrayOverlaps(op)
1289            | Expression::JSONBContainsAllTopKeys(op)
1290            | Expression::JSONBContainsAnyTopKeys(op)
1291            | Expression::JSONBDeleteAtPath(op)
1292            | Expression::ExtendsLeft(op)
1293            | Expression::ExtendsRight(op)
1294            | Expression::Is(op)
1295            | Expression::MemberOf(op)
1296            | Expression::Match(op)
1297            | Expression::NullSafeEq(op)
1298            | Expression::NullSafeNeq(op)
1299            | Expression::Glob(op)
1300            | Expression::BitwiseLeftShift(op)
1301            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1302
1303            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1304                op.inferred_type.as_ref()
1305            }
1306
1307            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1308
1309            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1310                c.inferred_type.as_ref()
1311            }
1312
1313            Expression::Column(c) => c.inferred_type.as_ref(),
1314            Expression::Function(f) => f.inferred_type.as_ref(),
1315            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1316            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1317            Expression::Case(c) => c.inferred_type.as_ref(),
1318            Expression::Subquery(s) => s.inferred_type.as_ref(),
1319            Expression::Alias(a) => a.inferred_type.as_ref(),
1320            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1321            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1322            Expression::Count(f) => f.inferred_type.as_ref(),
1323            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1324            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1325            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1326            Expression::SumIf(f) => f.inferred_type.as_ref(),
1327
1328            // UnaryFunc variants
1329            Expression::Upper(f)
1330            | Expression::Lower(f)
1331            | Expression::Length(f)
1332            | Expression::LTrim(f)
1333            | Expression::RTrim(f)
1334            | Expression::Reverse(f)
1335            | Expression::Abs(f)
1336            | Expression::Sqrt(f)
1337            | Expression::Cbrt(f)
1338            | Expression::Ln(f)
1339            | Expression::Exp(f)
1340            | Expression::Sign(f)
1341            | Expression::Date(f)
1342            | Expression::Time(f)
1343            | Expression::Initcap(f)
1344            | Expression::Ascii(f)
1345            | Expression::Chr(f)
1346            | Expression::Soundex(f)
1347            | Expression::ByteLength(f)
1348            | Expression::Hex(f)
1349            | Expression::LowerHex(f)
1350            | Expression::Unicode(f)
1351            | Expression::Typeof(f)
1352            | Expression::Explode(f)
1353            | Expression::ExplodeOuter(f)
1354            | Expression::MapFromEntries(f)
1355            | Expression::MapKeys(f)
1356            | Expression::MapValues(f)
1357            | Expression::ArrayLength(f)
1358            | Expression::ArraySize(f)
1359            | Expression::Cardinality(f)
1360            | Expression::ArrayReverse(f)
1361            | Expression::ArrayDistinct(f)
1362            | Expression::ArrayFlatten(f)
1363            | Expression::ArrayCompact(f)
1364            | Expression::ToArray(f)
1365            | Expression::JsonArrayLength(f)
1366            | Expression::JsonKeys(f)
1367            | Expression::JsonType(f)
1368            | Expression::ParseJson(f)
1369            | Expression::ToJson(f)
1370            | Expression::Radians(f)
1371            | Expression::Degrees(f)
1372            | Expression::Sin(f)
1373            | Expression::Cos(f)
1374            | Expression::Tan(f)
1375            | Expression::Asin(f)
1376            | Expression::Acos(f)
1377            | Expression::Atan(f)
1378            | Expression::IsNan(f)
1379            | Expression::IsInf(f)
1380            | Expression::Year(f)
1381            | Expression::Month(f)
1382            | Expression::Day(f)
1383            | Expression::Hour(f)
1384            | Expression::Minute(f)
1385            | Expression::Second(f)
1386            | Expression::DayOfWeek(f)
1387            | Expression::DayOfWeekIso(f)
1388            | Expression::DayOfMonth(f)
1389            | Expression::DayOfYear(f)
1390            | Expression::WeekOfYear(f)
1391            | Expression::Quarter(f)
1392            | Expression::Epoch(f)
1393            | Expression::EpochMs(f)
1394            | Expression::BitwiseCount(f)
1395            | Expression::DateFromUnixDate(f)
1396            | Expression::UnixDate(f)
1397            | Expression::UnixSeconds(f)
1398            | Expression::UnixMillis(f)
1399            | Expression::UnixMicros(f)
1400            | Expression::TimeStrToDate(f)
1401            | Expression::DateToDi(f)
1402            | Expression::DiToDate(f)
1403            | Expression::TsOrDiToDi(f)
1404            | Expression::TsOrDsToDatetime(f)
1405            | Expression::TsOrDsToTimestamp(f)
1406            | Expression::YearOfWeek(f)
1407            | Expression::YearOfWeekIso(f)
1408            | Expression::SHA(f)
1409            | Expression::SHA1Digest(f)
1410            | Expression::TimeToUnix(f)
1411            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1412
1413            // BinaryFunc variants
1414            Expression::Power(f)
1415            | Expression::NullIf(f)
1416            | Expression::IfNull(f)
1417            | Expression::Nvl(f)
1418            | Expression::Contains(f)
1419            | Expression::StartsWith(f)
1420            | Expression::EndsWith(f)
1421            | Expression::Levenshtein(f)
1422            | Expression::ModFunc(f)
1423            | Expression::IntDiv(f)
1424            | Expression::Atan2(f)
1425            | Expression::AddMonths(f)
1426            | Expression::MonthsBetween(f)
1427            | Expression::NextDay(f)
1428            | Expression::UnixToTimeStr(f)
1429            | Expression::ArrayContains(f)
1430            | Expression::ArrayPosition(f)
1431            | Expression::ArrayAppend(f)
1432            | Expression::ArrayPrepend(f)
1433            | Expression::ArrayUnion(f)
1434            | Expression::ArrayExcept(f)
1435            | Expression::ArrayRemove(f)
1436            | Expression::StarMap(f)
1437            | Expression::MapFromArrays(f)
1438            | Expression::MapContainsKey(f)
1439            | Expression::ElementAt(f)
1440            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1441
1442            // VarArgFunc variants
1443            Expression::Coalesce(f)
1444            | Expression::Greatest(f)
1445            | Expression::Least(f)
1446            | Expression::ArrayConcat(f)
1447            | Expression::ArrayIntersect(f)
1448            | Expression::ArrayZip(f)
1449            | Expression::MapConcat(f)
1450            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1451
1452            // AggFunc variants
1453            Expression::Sum(f)
1454            | Expression::Avg(f)
1455            | Expression::Min(f)
1456            | Expression::Max(f)
1457            | Expression::ArrayAgg(f)
1458            | Expression::CountIf(f)
1459            | Expression::Stddev(f)
1460            | Expression::StddevPop(f)
1461            | Expression::StddevSamp(f)
1462            | Expression::Variance(f)
1463            | Expression::VarPop(f)
1464            | Expression::VarSamp(f)
1465            | Expression::Median(f)
1466            | Expression::Mode(f)
1467            | Expression::First(f)
1468            | Expression::Last(f)
1469            | Expression::AnyValue(f)
1470            | Expression::ApproxDistinct(f)
1471            | Expression::ApproxCountDistinct(f)
1472            | Expression::LogicalAnd(f)
1473            | Expression::LogicalOr(f)
1474            | Expression::Skewness(f)
1475            | Expression::ArrayConcatAgg(f)
1476            | Expression::ArrayUniqueAgg(f)
1477            | Expression::BoolXorAgg(f)
1478            | Expression::BitwiseAndAgg(f)
1479            | Expression::BitwiseOrAgg(f)
1480            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1481
1482            // Everything else: no inferred_type field
1483            _ => None,
1484        }
1485    }
1486
1487    /// Set the inferred type annotation on this expression.
1488    ///
1489    /// Only has an effect on value-producing expressions with an `inferred_type`
1490    /// field. For other expression types, this is a no-op.
1491    pub fn set_inferred_type(&mut self, dt: DataType) {
1492        match self {
1493            Expression::And(op)
1494            | Expression::Or(op)
1495            | Expression::Add(op)
1496            | Expression::Sub(op)
1497            | Expression::Mul(op)
1498            | Expression::Div(op)
1499            | Expression::Mod(op)
1500            | Expression::Eq(op)
1501            | Expression::Neq(op)
1502            | Expression::Lt(op)
1503            | Expression::Lte(op)
1504            | Expression::Gt(op)
1505            | Expression::Gte(op)
1506            | Expression::Concat(op)
1507            | Expression::BitwiseAnd(op)
1508            | Expression::BitwiseOr(op)
1509            | Expression::BitwiseXor(op)
1510            | Expression::Adjacent(op)
1511            | Expression::TsMatch(op)
1512            | Expression::PropertyEQ(op)
1513            | Expression::ArrayContainsAll(op)
1514            | Expression::ArrayContainedBy(op)
1515            | Expression::ArrayOverlaps(op)
1516            | Expression::JSONBContainsAllTopKeys(op)
1517            | Expression::JSONBContainsAnyTopKeys(op)
1518            | Expression::JSONBDeleteAtPath(op)
1519            | Expression::ExtendsLeft(op)
1520            | Expression::ExtendsRight(op)
1521            | Expression::Is(op)
1522            | Expression::MemberOf(op)
1523            | Expression::Match(op)
1524            | Expression::NullSafeEq(op)
1525            | Expression::NullSafeNeq(op)
1526            | Expression::Glob(op)
1527            | Expression::BitwiseLeftShift(op)
1528            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1529
1530            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1531                op.inferred_type = Some(dt)
1532            }
1533
1534            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1535
1536            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1537                c.inferred_type = Some(dt)
1538            }
1539
1540            Expression::Column(c) => c.inferred_type = Some(dt),
1541            Expression::Function(f) => f.inferred_type = Some(dt),
1542            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1543            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1544            Expression::Case(c) => c.inferred_type = Some(dt),
1545            Expression::Subquery(s) => s.inferred_type = Some(dt),
1546            Expression::Alias(a) => a.inferred_type = Some(dt),
1547            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1548            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1549            Expression::Count(f) => f.inferred_type = Some(dt),
1550            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1551            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1552            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1553            Expression::SumIf(f) => f.inferred_type = Some(dt),
1554
1555            // UnaryFunc variants
1556            Expression::Upper(f)
1557            | Expression::Lower(f)
1558            | Expression::Length(f)
1559            | Expression::LTrim(f)
1560            | Expression::RTrim(f)
1561            | Expression::Reverse(f)
1562            | Expression::Abs(f)
1563            | Expression::Sqrt(f)
1564            | Expression::Cbrt(f)
1565            | Expression::Ln(f)
1566            | Expression::Exp(f)
1567            | Expression::Sign(f)
1568            | Expression::Date(f)
1569            | Expression::Time(f)
1570            | Expression::Initcap(f)
1571            | Expression::Ascii(f)
1572            | Expression::Chr(f)
1573            | Expression::Soundex(f)
1574            | Expression::ByteLength(f)
1575            | Expression::Hex(f)
1576            | Expression::LowerHex(f)
1577            | Expression::Unicode(f)
1578            | Expression::Typeof(f)
1579            | Expression::Explode(f)
1580            | Expression::ExplodeOuter(f)
1581            | Expression::MapFromEntries(f)
1582            | Expression::MapKeys(f)
1583            | Expression::MapValues(f)
1584            | Expression::ArrayLength(f)
1585            | Expression::ArraySize(f)
1586            | Expression::Cardinality(f)
1587            | Expression::ArrayReverse(f)
1588            | Expression::ArrayDistinct(f)
1589            | Expression::ArrayFlatten(f)
1590            | Expression::ArrayCompact(f)
1591            | Expression::ToArray(f)
1592            | Expression::JsonArrayLength(f)
1593            | Expression::JsonKeys(f)
1594            | Expression::JsonType(f)
1595            | Expression::ParseJson(f)
1596            | Expression::ToJson(f)
1597            | Expression::Radians(f)
1598            | Expression::Degrees(f)
1599            | Expression::Sin(f)
1600            | Expression::Cos(f)
1601            | Expression::Tan(f)
1602            | Expression::Asin(f)
1603            | Expression::Acos(f)
1604            | Expression::Atan(f)
1605            | Expression::IsNan(f)
1606            | Expression::IsInf(f)
1607            | Expression::Year(f)
1608            | Expression::Month(f)
1609            | Expression::Day(f)
1610            | Expression::Hour(f)
1611            | Expression::Minute(f)
1612            | Expression::Second(f)
1613            | Expression::DayOfWeek(f)
1614            | Expression::DayOfWeekIso(f)
1615            | Expression::DayOfMonth(f)
1616            | Expression::DayOfYear(f)
1617            | Expression::WeekOfYear(f)
1618            | Expression::Quarter(f)
1619            | Expression::Epoch(f)
1620            | Expression::EpochMs(f)
1621            | Expression::BitwiseCount(f)
1622            | Expression::DateFromUnixDate(f)
1623            | Expression::UnixDate(f)
1624            | Expression::UnixSeconds(f)
1625            | Expression::UnixMillis(f)
1626            | Expression::UnixMicros(f)
1627            | Expression::TimeStrToDate(f)
1628            | Expression::DateToDi(f)
1629            | Expression::DiToDate(f)
1630            | Expression::TsOrDiToDi(f)
1631            | Expression::TsOrDsToDatetime(f)
1632            | Expression::TsOrDsToTimestamp(f)
1633            | Expression::YearOfWeek(f)
1634            | Expression::YearOfWeekIso(f)
1635            | Expression::SHA(f)
1636            | Expression::SHA1Digest(f)
1637            | Expression::TimeToUnix(f)
1638            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1639
1640            // BinaryFunc variants
1641            Expression::Power(f)
1642            | Expression::NullIf(f)
1643            | Expression::IfNull(f)
1644            | Expression::Nvl(f)
1645            | Expression::Contains(f)
1646            | Expression::StartsWith(f)
1647            | Expression::EndsWith(f)
1648            | Expression::Levenshtein(f)
1649            | Expression::ModFunc(f)
1650            | Expression::IntDiv(f)
1651            | Expression::Atan2(f)
1652            | Expression::AddMonths(f)
1653            | Expression::MonthsBetween(f)
1654            | Expression::NextDay(f)
1655            | Expression::UnixToTimeStr(f)
1656            | Expression::ArrayContains(f)
1657            | Expression::ArrayPosition(f)
1658            | Expression::ArrayAppend(f)
1659            | Expression::ArrayPrepend(f)
1660            | Expression::ArrayUnion(f)
1661            | Expression::ArrayExcept(f)
1662            | Expression::ArrayRemove(f)
1663            | Expression::StarMap(f)
1664            | Expression::MapFromArrays(f)
1665            | Expression::MapContainsKey(f)
1666            | Expression::ElementAt(f)
1667            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1668
1669            // VarArgFunc variants
1670            Expression::Coalesce(f)
1671            | Expression::Greatest(f)
1672            | Expression::Least(f)
1673            | Expression::ArrayConcat(f)
1674            | Expression::ArrayIntersect(f)
1675            | Expression::ArrayZip(f)
1676            | Expression::MapConcat(f)
1677            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1678
1679            // AggFunc variants
1680            Expression::Sum(f)
1681            | Expression::Avg(f)
1682            | Expression::Min(f)
1683            | Expression::Max(f)
1684            | Expression::ArrayAgg(f)
1685            | Expression::CountIf(f)
1686            | Expression::Stddev(f)
1687            | Expression::StddevPop(f)
1688            | Expression::StddevSamp(f)
1689            | Expression::Variance(f)
1690            | Expression::VarPop(f)
1691            | Expression::VarSamp(f)
1692            | Expression::Median(f)
1693            | Expression::Mode(f)
1694            | Expression::First(f)
1695            | Expression::Last(f)
1696            | Expression::AnyValue(f)
1697            | Expression::ApproxDistinct(f)
1698            | Expression::ApproxCountDistinct(f)
1699            | Expression::LogicalAnd(f)
1700            | Expression::LogicalOr(f)
1701            | Expression::Skewness(f)
1702            | Expression::ArrayConcatAgg(f)
1703            | Expression::ArrayUniqueAgg(f)
1704            | Expression::BoolXorAgg(f)
1705            | Expression::BitwiseAndAgg(f)
1706            | Expression::BitwiseOrAgg(f)
1707            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1708
1709            // Expressions without inferred_type field - no-op
1710            _ => {}
1711        }
1712    }
1713
1714    /// Create an unqualified column reference (e.g. `name`).
1715    pub fn column(name: impl Into<String>) -> Self {
1716        Expression::Column(Box::new(Column {
1717            name: Identifier::new(name),
1718            table: None,
1719            join_mark: false,
1720            trailing_comments: Vec::new(),
1721            span: None,
1722            inferred_type: None,
1723        }))
1724    }
1725
1726    /// Create a qualified column reference (`table.column`).
1727    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1728        Expression::Column(Box::new(Column {
1729            name: Identifier::new(column),
1730            table: Some(Identifier::new(table)),
1731            join_mark: false,
1732            trailing_comments: Vec::new(),
1733            span: None,
1734            inferred_type: None,
1735        }))
1736    }
1737
1738    /// Create a bare identifier expression (not a column reference).
1739    pub fn identifier(name: impl Into<String>) -> Self {
1740        Expression::Identifier(Identifier::new(name))
1741    }
1742
1743    /// Create a NULL expression
1744    pub fn null() -> Self {
1745        Expression::Null(Null)
1746    }
1747
1748    /// Create a TRUE expression
1749    pub fn true_() -> Self {
1750        Expression::Boolean(BooleanLiteral { value: true })
1751    }
1752
1753    /// Create a FALSE expression
1754    pub fn false_() -> Self {
1755        Expression::Boolean(BooleanLiteral { value: false })
1756    }
1757
1758    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1759    pub fn star() -> Self {
1760        Expression::Star(Star {
1761            table: None,
1762            except: None,
1763            replace: None,
1764            rename: None,
1765            trailing_comments: Vec::new(),
1766            span: None,
1767        })
1768    }
1769
1770    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1771    pub fn alias(self, name: impl Into<String>) -> Self {
1772        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1773    }
1774
1775    /// Check if this is a SELECT expression
1776    pub fn is_select(&self) -> bool {
1777        matches!(self, Expression::Select(_))
1778    }
1779
1780    /// Try to get as a Select
1781    pub fn as_select(&self) -> Option<&Select> {
1782        match self {
1783            Expression::Select(s) => Some(s),
1784            _ => None,
1785        }
1786    }
1787
1788    /// Try to get as a mutable Select
1789    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1790        match self {
1791            Expression::Select(s) => Some(s),
1792            _ => None,
1793        }
1794    }
1795
1796    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1797    ///
1798    /// Returns an empty string if generation fails. For dialect-specific output,
1799    /// use [`sql_for()`](Self::sql_for) instead.
1800    pub fn sql(&self) -> String {
1801        crate::generator::Generator::sql(self).unwrap_or_default()
1802    }
1803
1804    /// Generate a SQL string for this expression targeting a specific dialect.
1805    ///
1806    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1807    /// syntax variations) are applied automatically.  Returns an empty string if
1808    /// generation fails.
1809    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1810        crate::generate(self, dialect).unwrap_or_default()
1811    }
1812}
1813
1814// === Python API accessor methods ===
1815
1816impl Expression {
1817    /// Returns the serde-compatible snake_case variant name without serialization.
1818    /// This is much faster than serializing to JSON and extracting the key.
1819    pub fn variant_name(&self) -> &'static str {
1820        match self {
1821            Expression::Literal(_) => "literal",
1822            Expression::Boolean(_) => "boolean",
1823            Expression::Null(_) => "null",
1824            Expression::Identifier(_) => "identifier",
1825            Expression::Column(_) => "column",
1826            Expression::Table(_) => "table",
1827            Expression::Star(_) => "star",
1828            Expression::BracedWildcard(_) => "braced_wildcard",
1829            Expression::Select(_) => "select",
1830            Expression::Union(_) => "union",
1831            Expression::Intersect(_) => "intersect",
1832            Expression::Except(_) => "except",
1833            Expression::Subquery(_) => "subquery",
1834            Expression::PipeOperator(_) => "pipe_operator",
1835            Expression::Pivot(_) => "pivot",
1836            Expression::PivotAlias(_) => "pivot_alias",
1837            Expression::Unpivot(_) => "unpivot",
1838            Expression::Values(_) => "values",
1839            Expression::PreWhere(_) => "pre_where",
1840            Expression::Stream(_) => "stream",
1841            Expression::UsingData(_) => "using_data",
1842            Expression::XmlNamespace(_) => "xml_namespace",
1843            Expression::Insert(_) => "insert",
1844            Expression::Update(_) => "update",
1845            Expression::Delete(_) => "delete",
1846            Expression::Copy(_) => "copy",
1847            Expression::Put(_) => "put",
1848            Expression::StageReference(_) => "stage_reference",
1849            Expression::Alias(_) => "alias",
1850            Expression::Cast(_) => "cast",
1851            Expression::Collation(_) => "collation",
1852            Expression::Case(_) => "case",
1853            Expression::And(_) => "and",
1854            Expression::Or(_) => "or",
1855            Expression::Add(_) => "add",
1856            Expression::Sub(_) => "sub",
1857            Expression::Mul(_) => "mul",
1858            Expression::Div(_) => "div",
1859            Expression::Mod(_) => "mod",
1860            Expression::Eq(_) => "eq",
1861            Expression::Neq(_) => "neq",
1862            Expression::Lt(_) => "lt",
1863            Expression::Lte(_) => "lte",
1864            Expression::Gt(_) => "gt",
1865            Expression::Gte(_) => "gte",
1866            Expression::Like(_) => "like",
1867            Expression::ILike(_) => "i_like",
1868            Expression::Match(_) => "match",
1869            Expression::BitwiseAnd(_) => "bitwise_and",
1870            Expression::BitwiseOr(_) => "bitwise_or",
1871            Expression::BitwiseXor(_) => "bitwise_xor",
1872            Expression::Concat(_) => "concat",
1873            Expression::Adjacent(_) => "adjacent",
1874            Expression::TsMatch(_) => "ts_match",
1875            Expression::PropertyEQ(_) => "property_e_q",
1876            Expression::ArrayContainsAll(_) => "array_contains_all",
1877            Expression::ArrayContainedBy(_) => "array_contained_by",
1878            Expression::ArrayOverlaps(_) => "array_overlaps",
1879            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1880            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1881            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1882            Expression::ExtendsLeft(_) => "extends_left",
1883            Expression::ExtendsRight(_) => "extends_right",
1884            Expression::Not(_) => "not",
1885            Expression::Neg(_) => "neg",
1886            Expression::BitwiseNot(_) => "bitwise_not",
1887            Expression::In(_) => "in",
1888            Expression::Between(_) => "between",
1889            Expression::IsNull(_) => "is_null",
1890            Expression::IsTrue(_) => "is_true",
1891            Expression::IsFalse(_) => "is_false",
1892            Expression::IsJson(_) => "is_json",
1893            Expression::Is(_) => "is",
1894            Expression::Exists(_) => "exists",
1895            Expression::MemberOf(_) => "member_of",
1896            Expression::Function(_) => "function",
1897            Expression::AggregateFunction(_) => "aggregate_function",
1898            Expression::WindowFunction(_) => "window_function",
1899            Expression::From(_) => "from",
1900            Expression::Join(_) => "join",
1901            Expression::JoinedTable(_) => "joined_table",
1902            Expression::Where(_) => "where",
1903            Expression::GroupBy(_) => "group_by",
1904            Expression::Having(_) => "having",
1905            Expression::OrderBy(_) => "order_by",
1906            Expression::Limit(_) => "limit",
1907            Expression::Offset(_) => "offset",
1908            Expression::Qualify(_) => "qualify",
1909            Expression::With(_) => "with",
1910            Expression::Cte(_) => "cte",
1911            Expression::DistributeBy(_) => "distribute_by",
1912            Expression::ClusterBy(_) => "cluster_by",
1913            Expression::SortBy(_) => "sort_by",
1914            Expression::LateralView(_) => "lateral_view",
1915            Expression::Hint(_) => "hint",
1916            Expression::Pseudocolumn(_) => "pseudocolumn",
1917            Expression::Connect(_) => "connect",
1918            Expression::Prior(_) => "prior",
1919            Expression::ConnectByRoot(_) => "connect_by_root",
1920            Expression::MatchRecognize(_) => "match_recognize",
1921            Expression::Ordered(_) => "ordered",
1922            Expression::Window(_) => "window",
1923            Expression::Over(_) => "over",
1924            Expression::WithinGroup(_) => "within_group",
1925            Expression::DataType(_) => "data_type",
1926            Expression::Array(_) => "array",
1927            Expression::Struct(_) => "struct",
1928            Expression::Tuple(_) => "tuple",
1929            Expression::Interval(_) => "interval",
1930            Expression::ConcatWs(_) => "concat_ws",
1931            Expression::Substring(_) => "substring",
1932            Expression::Upper(_) => "upper",
1933            Expression::Lower(_) => "lower",
1934            Expression::Length(_) => "length",
1935            Expression::Trim(_) => "trim",
1936            Expression::LTrim(_) => "l_trim",
1937            Expression::RTrim(_) => "r_trim",
1938            Expression::Replace(_) => "replace",
1939            Expression::Reverse(_) => "reverse",
1940            Expression::Left(_) => "left",
1941            Expression::Right(_) => "right",
1942            Expression::Repeat(_) => "repeat",
1943            Expression::Lpad(_) => "lpad",
1944            Expression::Rpad(_) => "rpad",
1945            Expression::Split(_) => "split",
1946            Expression::RegexpLike(_) => "regexp_like",
1947            Expression::RegexpReplace(_) => "regexp_replace",
1948            Expression::RegexpExtract(_) => "regexp_extract",
1949            Expression::Overlay(_) => "overlay",
1950            Expression::Abs(_) => "abs",
1951            Expression::Round(_) => "round",
1952            Expression::Floor(_) => "floor",
1953            Expression::Ceil(_) => "ceil",
1954            Expression::Power(_) => "power",
1955            Expression::Sqrt(_) => "sqrt",
1956            Expression::Cbrt(_) => "cbrt",
1957            Expression::Ln(_) => "ln",
1958            Expression::Log(_) => "log",
1959            Expression::Exp(_) => "exp",
1960            Expression::Sign(_) => "sign",
1961            Expression::Greatest(_) => "greatest",
1962            Expression::Least(_) => "least",
1963            Expression::CurrentDate(_) => "current_date",
1964            Expression::CurrentTime(_) => "current_time",
1965            Expression::CurrentTimestamp(_) => "current_timestamp",
1966            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1967            Expression::AtTimeZone(_) => "at_time_zone",
1968            Expression::DateAdd(_) => "date_add",
1969            Expression::DateSub(_) => "date_sub",
1970            Expression::DateDiff(_) => "date_diff",
1971            Expression::DateTrunc(_) => "date_trunc",
1972            Expression::Extract(_) => "extract",
1973            Expression::ToDate(_) => "to_date",
1974            Expression::ToTimestamp(_) => "to_timestamp",
1975            Expression::Date(_) => "date",
1976            Expression::Time(_) => "time",
1977            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1978            Expression::UnixDate(_) => "unix_date",
1979            Expression::UnixSeconds(_) => "unix_seconds",
1980            Expression::UnixMillis(_) => "unix_millis",
1981            Expression::UnixMicros(_) => "unix_micros",
1982            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1983            Expression::TimeStrToDate(_) => "time_str_to_date",
1984            Expression::DateToDi(_) => "date_to_di",
1985            Expression::DiToDate(_) => "di_to_date",
1986            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1987            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1988            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1989            Expression::YearOfWeek(_) => "year_of_week",
1990            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1991            Expression::Coalesce(_) => "coalesce",
1992            Expression::NullIf(_) => "null_if",
1993            Expression::IfFunc(_) => "if_func",
1994            Expression::IfNull(_) => "if_null",
1995            Expression::Nvl(_) => "nvl",
1996            Expression::Nvl2(_) => "nvl2",
1997            Expression::TryCast(_) => "try_cast",
1998            Expression::SafeCast(_) => "safe_cast",
1999            Expression::Count(_) => "count",
2000            Expression::Sum(_) => "sum",
2001            Expression::Avg(_) => "avg",
2002            Expression::Min(_) => "min",
2003            Expression::Max(_) => "max",
2004            Expression::GroupConcat(_) => "group_concat",
2005            Expression::StringAgg(_) => "string_agg",
2006            Expression::ListAgg(_) => "list_agg",
2007            Expression::ArrayAgg(_) => "array_agg",
2008            Expression::CountIf(_) => "count_if",
2009            Expression::SumIf(_) => "sum_if",
2010            Expression::Stddev(_) => "stddev",
2011            Expression::StddevPop(_) => "stddev_pop",
2012            Expression::StddevSamp(_) => "stddev_samp",
2013            Expression::Variance(_) => "variance",
2014            Expression::VarPop(_) => "var_pop",
2015            Expression::VarSamp(_) => "var_samp",
2016            Expression::Median(_) => "median",
2017            Expression::Mode(_) => "mode",
2018            Expression::First(_) => "first",
2019            Expression::Last(_) => "last",
2020            Expression::AnyValue(_) => "any_value",
2021            Expression::ApproxDistinct(_) => "approx_distinct",
2022            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2023            Expression::ApproxPercentile(_) => "approx_percentile",
2024            Expression::Percentile(_) => "percentile",
2025            Expression::LogicalAnd(_) => "logical_and",
2026            Expression::LogicalOr(_) => "logical_or",
2027            Expression::Skewness(_) => "skewness",
2028            Expression::BitwiseCount(_) => "bitwise_count",
2029            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2030            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2031            Expression::BoolXorAgg(_) => "bool_xor_agg",
2032            Expression::RowNumber(_) => "row_number",
2033            Expression::Rank(_) => "rank",
2034            Expression::DenseRank(_) => "dense_rank",
2035            Expression::NTile(_) => "n_tile",
2036            Expression::Lead(_) => "lead",
2037            Expression::Lag(_) => "lag",
2038            Expression::FirstValue(_) => "first_value",
2039            Expression::LastValue(_) => "last_value",
2040            Expression::NthValue(_) => "nth_value",
2041            Expression::PercentRank(_) => "percent_rank",
2042            Expression::CumeDist(_) => "cume_dist",
2043            Expression::PercentileCont(_) => "percentile_cont",
2044            Expression::PercentileDisc(_) => "percentile_disc",
2045            Expression::Contains(_) => "contains",
2046            Expression::StartsWith(_) => "starts_with",
2047            Expression::EndsWith(_) => "ends_with",
2048            Expression::Position(_) => "position",
2049            Expression::Initcap(_) => "initcap",
2050            Expression::Ascii(_) => "ascii",
2051            Expression::Chr(_) => "chr",
2052            Expression::CharFunc(_) => "char_func",
2053            Expression::Soundex(_) => "soundex",
2054            Expression::Levenshtein(_) => "levenshtein",
2055            Expression::ByteLength(_) => "byte_length",
2056            Expression::Hex(_) => "hex",
2057            Expression::LowerHex(_) => "lower_hex",
2058            Expression::Unicode(_) => "unicode",
2059            Expression::ModFunc(_) => "mod_func",
2060            Expression::Random(_) => "random",
2061            Expression::Rand(_) => "rand",
2062            Expression::TruncFunc(_) => "trunc_func",
2063            Expression::Pi(_) => "pi",
2064            Expression::Radians(_) => "radians",
2065            Expression::Degrees(_) => "degrees",
2066            Expression::Sin(_) => "sin",
2067            Expression::Cos(_) => "cos",
2068            Expression::Tan(_) => "tan",
2069            Expression::Asin(_) => "asin",
2070            Expression::Acos(_) => "acos",
2071            Expression::Atan(_) => "atan",
2072            Expression::Atan2(_) => "atan2",
2073            Expression::IsNan(_) => "is_nan",
2074            Expression::IsInf(_) => "is_inf",
2075            Expression::IntDiv(_) => "int_div",
2076            Expression::Decode(_) => "decode",
2077            Expression::DateFormat(_) => "date_format",
2078            Expression::FormatDate(_) => "format_date",
2079            Expression::Year(_) => "year",
2080            Expression::Month(_) => "month",
2081            Expression::Day(_) => "day",
2082            Expression::Hour(_) => "hour",
2083            Expression::Minute(_) => "minute",
2084            Expression::Second(_) => "second",
2085            Expression::DayOfWeek(_) => "day_of_week",
2086            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2087            Expression::DayOfMonth(_) => "day_of_month",
2088            Expression::DayOfYear(_) => "day_of_year",
2089            Expression::WeekOfYear(_) => "week_of_year",
2090            Expression::Quarter(_) => "quarter",
2091            Expression::AddMonths(_) => "add_months",
2092            Expression::MonthsBetween(_) => "months_between",
2093            Expression::LastDay(_) => "last_day",
2094            Expression::NextDay(_) => "next_day",
2095            Expression::Epoch(_) => "epoch",
2096            Expression::EpochMs(_) => "epoch_ms",
2097            Expression::FromUnixtime(_) => "from_unixtime",
2098            Expression::UnixTimestamp(_) => "unix_timestamp",
2099            Expression::MakeDate(_) => "make_date",
2100            Expression::MakeTimestamp(_) => "make_timestamp",
2101            Expression::TimestampTrunc(_) => "timestamp_trunc",
2102            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2103            Expression::SessionUser(_) => "session_user",
2104            Expression::SHA(_) => "s_h_a",
2105            Expression::SHA1Digest(_) => "s_h_a1_digest",
2106            Expression::TimeToUnix(_) => "time_to_unix",
2107            Expression::ArrayFunc(_) => "array_func",
2108            Expression::ArrayLength(_) => "array_length",
2109            Expression::ArraySize(_) => "array_size",
2110            Expression::Cardinality(_) => "cardinality",
2111            Expression::ArrayContains(_) => "array_contains",
2112            Expression::ArrayPosition(_) => "array_position",
2113            Expression::ArrayAppend(_) => "array_append",
2114            Expression::ArrayPrepend(_) => "array_prepend",
2115            Expression::ArrayConcat(_) => "array_concat",
2116            Expression::ArraySort(_) => "array_sort",
2117            Expression::ArrayReverse(_) => "array_reverse",
2118            Expression::ArrayDistinct(_) => "array_distinct",
2119            Expression::ArrayJoin(_) => "array_join",
2120            Expression::ArrayToString(_) => "array_to_string",
2121            Expression::Unnest(_) => "unnest",
2122            Expression::Explode(_) => "explode",
2123            Expression::ExplodeOuter(_) => "explode_outer",
2124            Expression::ArrayFilter(_) => "array_filter",
2125            Expression::ArrayTransform(_) => "array_transform",
2126            Expression::ArrayFlatten(_) => "array_flatten",
2127            Expression::ArrayCompact(_) => "array_compact",
2128            Expression::ArrayIntersect(_) => "array_intersect",
2129            Expression::ArrayUnion(_) => "array_union",
2130            Expression::ArrayExcept(_) => "array_except",
2131            Expression::ArrayRemove(_) => "array_remove",
2132            Expression::ArrayZip(_) => "array_zip",
2133            Expression::Sequence(_) => "sequence",
2134            Expression::Generate(_) => "generate",
2135            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2136            Expression::ToArray(_) => "to_array",
2137            Expression::StarMap(_) => "star_map",
2138            Expression::StructFunc(_) => "struct_func",
2139            Expression::StructExtract(_) => "struct_extract",
2140            Expression::NamedStruct(_) => "named_struct",
2141            Expression::MapFunc(_) => "map_func",
2142            Expression::MapFromEntries(_) => "map_from_entries",
2143            Expression::MapFromArrays(_) => "map_from_arrays",
2144            Expression::MapKeys(_) => "map_keys",
2145            Expression::MapValues(_) => "map_values",
2146            Expression::MapContainsKey(_) => "map_contains_key",
2147            Expression::MapConcat(_) => "map_concat",
2148            Expression::ElementAt(_) => "element_at",
2149            Expression::TransformKeys(_) => "transform_keys",
2150            Expression::TransformValues(_) => "transform_values",
2151            Expression::FunctionEmits(_) => "function_emits",
2152            Expression::JsonExtract(_) => "json_extract",
2153            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2154            Expression::JsonExtractPath(_) => "json_extract_path",
2155            Expression::JsonArray(_) => "json_array",
2156            Expression::JsonObject(_) => "json_object",
2157            Expression::JsonQuery(_) => "json_query",
2158            Expression::JsonValue(_) => "json_value",
2159            Expression::JsonArrayLength(_) => "json_array_length",
2160            Expression::JsonKeys(_) => "json_keys",
2161            Expression::JsonType(_) => "json_type",
2162            Expression::ParseJson(_) => "parse_json",
2163            Expression::ToJson(_) => "to_json",
2164            Expression::JsonSet(_) => "json_set",
2165            Expression::JsonInsert(_) => "json_insert",
2166            Expression::JsonRemove(_) => "json_remove",
2167            Expression::JsonMergePatch(_) => "json_merge_patch",
2168            Expression::JsonArrayAgg(_) => "json_array_agg",
2169            Expression::JsonObjectAgg(_) => "json_object_agg",
2170            Expression::Convert(_) => "convert",
2171            Expression::Typeof(_) => "typeof",
2172            Expression::Lambda(_) => "lambda",
2173            Expression::Parameter(_) => "parameter",
2174            Expression::Placeholder(_) => "placeholder",
2175            Expression::NamedArgument(_) => "named_argument",
2176            Expression::TableArgument(_) => "table_argument",
2177            Expression::SqlComment(_) => "sql_comment",
2178            Expression::NullSafeEq(_) => "null_safe_eq",
2179            Expression::NullSafeNeq(_) => "null_safe_neq",
2180            Expression::Glob(_) => "glob",
2181            Expression::SimilarTo(_) => "similar_to",
2182            Expression::Any(_) => "any",
2183            Expression::All(_) => "all",
2184            Expression::Overlaps(_) => "overlaps",
2185            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2186            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2187            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2188            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2189            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2190            Expression::Subscript(_) => "subscript",
2191            Expression::Dot(_) => "dot",
2192            Expression::MethodCall(_) => "method_call",
2193            Expression::ArraySlice(_) => "array_slice",
2194            Expression::CreateTable(_) => "create_table",
2195            Expression::DropTable(_) => "drop_table",
2196            Expression::Undrop(_) => "undrop",
2197            Expression::AlterTable(_) => "alter_table",
2198            Expression::CreateIndex(_) => "create_index",
2199            Expression::DropIndex(_) => "drop_index",
2200            Expression::CreateView(_) => "create_view",
2201            Expression::DropView(_) => "drop_view",
2202            Expression::AlterView(_) => "alter_view",
2203            Expression::AlterIndex(_) => "alter_index",
2204            Expression::Truncate(_) => "truncate",
2205            Expression::Use(_) => "use",
2206            Expression::Cache(_) => "cache",
2207            Expression::Uncache(_) => "uncache",
2208            Expression::LoadData(_) => "load_data",
2209            Expression::Pragma(_) => "pragma",
2210            Expression::Grant(_) => "grant",
2211            Expression::Revoke(_) => "revoke",
2212            Expression::Comment(_) => "comment",
2213            Expression::SetStatement(_) => "set_statement",
2214            Expression::CreateSchema(_) => "create_schema",
2215            Expression::DropSchema(_) => "drop_schema",
2216            Expression::DropNamespace(_) => "drop_namespace",
2217            Expression::CreateDatabase(_) => "create_database",
2218            Expression::DropDatabase(_) => "drop_database",
2219            Expression::CreateFunction(_) => "create_function",
2220            Expression::DropFunction(_) => "drop_function",
2221            Expression::CreateProcedure(_) => "create_procedure",
2222            Expression::DropProcedure(_) => "drop_procedure",
2223            Expression::CreateSequence(_) => "create_sequence",
2224            Expression::CreateSynonym(_) => "create_synonym",
2225            Expression::DropSequence(_) => "drop_sequence",
2226            Expression::AlterSequence(_) => "alter_sequence",
2227            Expression::CreateTrigger(_) => "create_trigger",
2228            Expression::DropTrigger(_) => "drop_trigger",
2229            Expression::CreateType(_) => "create_type",
2230            Expression::DropType(_) => "drop_type",
2231            Expression::Describe(_) => "describe",
2232            Expression::Show(_) => "show",
2233            Expression::Command(_) => "command",
2234            Expression::TryCatch(_) => "try_catch",
2235            Expression::Kill(_) => "kill",
2236            Expression::Execute(_) => "execute",
2237            Expression::Raw(_) => "raw",
2238            Expression::CreateTask(_) => "create_task",
2239            Expression::Paren(_) => "paren",
2240            Expression::Annotated(_) => "annotated",
2241            Expression::Refresh(_) => "refresh",
2242            Expression::LockingStatement(_) => "locking_statement",
2243            Expression::SequenceProperties(_) => "sequence_properties",
2244            Expression::TruncateTable(_) => "truncate_table",
2245            Expression::Clone(_) => "clone",
2246            Expression::Attach(_) => "attach",
2247            Expression::Detach(_) => "detach",
2248            Expression::Install(_) => "install",
2249            Expression::Summarize(_) => "summarize",
2250            Expression::Declare(_) => "declare",
2251            Expression::DeclareItem(_) => "declare_item",
2252            Expression::Set(_) => "set",
2253            Expression::Heredoc(_) => "heredoc",
2254            Expression::SetItem(_) => "set_item",
2255            Expression::QueryBand(_) => "query_band",
2256            Expression::UserDefinedFunction(_) => "user_defined_function",
2257            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2258            Expression::ProjectionDef(_) => "projection_def",
2259            Expression::TableAlias(_) => "table_alias",
2260            Expression::ByteString(_) => "byte_string",
2261            Expression::HexStringExpr(_) => "hex_string_expr",
2262            Expression::UnicodeString(_) => "unicode_string",
2263            Expression::ColumnPosition(_) => "column_position",
2264            Expression::ColumnDef(_) => "column_def",
2265            Expression::AlterColumn(_) => "alter_column",
2266            Expression::AlterSortKey(_) => "alter_sort_key",
2267            Expression::AlterSet(_) => "alter_set",
2268            Expression::RenameColumn(_) => "rename_column",
2269            Expression::Comprehension(_) => "comprehension",
2270            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2271            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2272            Expression::IndexConstraintOption(_) => "index_constraint_option",
2273            Expression::ColumnConstraint(_) => "column_constraint",
2274            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2275            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2276            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2277            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2278            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2279            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2280            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2281            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2282            Expression::WithOperator(_) => "with_operator",
2283            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2284                "generated_as_identity_column_constraint"
2285            }
2286            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2287            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2288            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2289            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2290            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2291            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2292            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2293            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2294            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2295            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2296            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2297            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2298            Expression::PathColumnConstraint(_) => "path_column_constraint",
2299            Expression::Constraint(_) => "constraint",
2300            Expression::Export(_) => "export",
2301            Expression::Filter(_) => "filter",
2302            Expression::Changes(_) => "changes",
2303            Expression::CopyParameter(_) => "copy_parameter",
2304            Expression::Credentials(_) => "credentials",
2305            Expression::Directory(_) => "directory",
2306            Expression::ForeignKey(_) => "foreign_key",
2307            Expression::ColumnPrefix(_) => "column_prefix",
2308            Expression::PrimaryKey(_) => "primary_key",
2309            Expression::IntoClause(_) => "into_clause",
2310            Expression::JoinHint(_) => "join_hint",
2311            Expression::Opclass(_) => "opclass",
2312            Expression::Index(_) => "index",
2313            Expression::IndexParameters(_) => "index_parameters",
2314            Expression::ConditionalInsert(_) => "conditional_insert",
2315            Expression::MultitableInserts(_) => "multitable_inserts",
2316            Expression::OnConflict(_) => "on_conflict",
2317            Expression::OnCondition(_) => "on_condition",
2318            Expression::Returning(_) => "returning",
2319            Expression::Introducer(_) => "introducer",
2320            Expression::PartitionRange(_) => "partition_range",
2321            Expression::Fetch(_) => "fetch",
2322            Expression::Group(_) => "group",
2323            Expression::Cube(_) => "cube",
2324            Expression::Rollup(_) => "rollup",
2325            Expression::GroupingSets(_) => "grouping_sets",
2326            Expression::LimitOptions(_) => "limit_options",
2327            Expression::Lateral(_) => "lateral",
2328            Expression::TableFromRows(_) => "table_from_rows",
2329            Expression::RowsFrom(_) => "rows_from",
2330            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2331            Expression::WithFill(_) => "with_fill",
2332            Expression::Property(_) => "property",
2333            Expression::GrantPrivilege(_) => "grant_privilege",
2334            Expression::GrantPrincipal(_) => "grant_principal",
2335            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2336            Expression::AlgorithmProperty(_) => "algorithm_property",
2337            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2338            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2339            Expression::BackupProperty(_) => "backup_property",
2340            Expression::BuildProperty(_) => "build_property",
2341            Expression::BlockCompressionProperty(_) => "block_compression_property",
2342            Expression::CharacterSetProperty(_) => "character_set_property",
2343            Expression::ChecksumProperty(_) => "checksum_property",
2344            Expression::CollateProperty(_) => "collate_property",
2345            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2346            Expression::DataDeletionProperty(_) => "data_deletion_property",
2347            Expression::DefinerProperty(_) => "definer_property",
2348            Expression::DistKeyProperty(_) => "dist_key_property",
2349            Expression::DistributedByProperty(_) => "distributed_by_property",
2350            Expression::DistStyleProperty(_) => "dist_style_property",
2351            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2352            Expression::EngineProperty(_) => "engine_property",
2353            Expression::ToTableProperty(_) => "to_table_property",
2354            Expression::ExecuteAsProperty(_) => "execute_as_property",
2355            Expression::ExternalProperty(_) => "external_property",
2356            Expression::FallbackProperty(_) => "fallback_property",
2357            Expression::FileFormatProperty(_) => "file_format_property",
2358            Expression::CredentialsProperty(_) => "credentials_property",
2359            Expression::FreespaceProperty(_) => "freespace_property",
2360            Expression::InheritsProperty(_) => "inherits_property",
2361            Expression::InputModelProperty(_) => "input_model_property",
2362            Expression::OutputModelProperty(_) => "output_model_property",
2363            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2364            Expression::JournalProperty(_) => "journal_property",
2365            Expression::LanguageProperty(_) => "language_property",
2366            Expression::EnviromentProperty(_) => "enviroment_property",
2367            Expression::ClusteredByProperty(_) => "clustered_by_property",
2368            Expression::DictProperty(_) => "dict_property",
2369            Expression::DictRange(_) => "dict_range",
2370            Expression::OnCluster(_) => "on_cluster",
2371            Expression::LikeProperty(_) => "like_property",
2372            Expression::LocationProperty(_) => "location_property",
2373            Expression::LockProperty(_) => "lock_property",
2374            Expression::LockingProperty(_) => "locking_property",
2375            Expression::LogProperty(_) => "log_property",
2376            Expression::MaterializedProperty(_) => "materialized_property",
2377            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2378            Expression::OnProperty(_) => "on_property",
2379            Expression::OnCommitProperty(_) => "on_commit_property",
2380            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2381            Expression::PartitionByProperty(_) => "partition_by_property",
2382            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2383            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2384            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2385            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2386            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2387            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2388            Expression::PartitionList(_) => "partition_list",
2389            Expression::Partition(_) => "partition",
2390            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2391            Expression::UniqueKeyProperty(_) => "unique_key_property",
2392            Expression::RollupProperty(_) => "rollup_property",
2393            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2394            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2395            Expression::RemoteWithConnectionModelProperty(_) => {
2396                "remote_with_connection_model_property"
2397            }
2398            Expression::ReturnsProperty(_) => "returns_property",
2399            Expression::RowFormatProperty(_) => "row_format_property",
2400            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2401            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2402            Expression::QueryTransform(_) => "query_transform",
2403            Expression::SampleProperty(_) => "sample_property",
2404            Expression::SecurityProperty(_) => "security_property",
2405            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2406            Expression::SemanticView(_) => "semantic_view",
2407            Expression::SerdeProperties(_) => "serde_properties",
2408            Expression::SetProperty(_) => "set_property",
2409            Expression::SharingProperty(_) => "sharing_property",
2410            Expression::SetConfigProperty(_) => "set_config_property",
2411            Expression::SettingsProperty(_) => "settings_property",
2412            Expression::SortKeyProperty(_) => "sort_key_property",
2413            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2414            Expression::SqlSecurityProperty(_) => "sql_security_property",
2415            Expression::StabilityProperty(_) => "stability_property",
2416            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2417            Expression::TemporaryProperty(_) => "temporary_property",
2418            Expression::Tags(_) => "tags",
2419            Expression::TransformModelProperty(_) => "transform_model_property",
2420            Expression::TransientProperty(_) => "transient_property",
2421            Expression::UsingTemplateProperty(_) => "using_template_property",
2422            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2423            Expression::VolatileProperty(_) => "volatile_property",
2424            Expression::WithDataProperty(_) => "with_data_property",
2425            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2426            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2427            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2428            Expression::WithProcedureOptions(_) => "with_procedure_options",
2429            Expression::EncodeProperty(_) => "encode_property",
2430            Expression::IncludeProperty(_) => "include_property",
2431            Expression::Properties(_) => "properties",
2432            Expression::OptionsProperty(_) => "options_property",
2433            Expression::InputOutputFormat(_) => "input_output_format",
2434            Expression::Reference(_) => "reference",
2435            Expression::QueryOption(_) => "query_option",
2436            Expression::WithTableHint(_) => "with_table_hint",
2437            Expression::IndexTableHint(_) => "index_table_hint",
2438            Expression::HistoricalData(_) => "historical_data",
2439            Expression::Get(_) => "get",
2440            Expression::SetOperation(_) => "set_operation",
2441            Expression::Var(_) => "var",
2442            Expression::Variadic(_) => "variadic",
2443            Expression::Version(_) => "version",
2444            Expression::Schema(_) => "schema",
2445            Expression::Lock(_) => "lock",
2446            Expression::TableSample(_) => "table_sample",
2447            Expression::Tag(_) => "tag",
2448            Expression::UnpivotColumns(_) => "unpivot_columns",
2449            Expression::WindowSpec(_) => "window_spec",
2450            Expression::SessionParameter(_) => "session_parameter",
2451            Expression::PseudoType(_) => "pseudo_type",
2452            Expression::ObjectIdentifier(_) => "object_identifier",
2453            Expression::Transaction(_) => "transaction",
2454            Expression::Commit(_) => "commit",
2455            Expression::Rollback(_) => "rollback",
2456            Expression::AlterSession(_) => "alter_session",
2457            Expression::Analyze(_) => "analyze",
2458            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2459            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2460            Expression::AnalyzeSample(_) => "analyze_sample",
2461            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2462            Expression::AnalyzeDelete(_) => "analyze_delete",
2463            Expression::AnalyzeWith(_) => "analyze_with",
2464            Expression::AnalyzeValidate(_) => "analyze_validate",
2465            Expression::AddPartition(_) => "add_partition",
2466            Expression::AttachOption(_) => "attach_option",
2467            Expression::DropPartition(_) => "drop_partition",
2468            Expression::ReplacePartition(_) => "replace_partition",
2469            Expression::DPipe(_) => "d_pipe",
2470            Expression::Operator(_) => "operator",
2471            Expression::PivotAny(_) => "pivot_any",
2472            Expression::Aliases(_) => "aliases",
2473            Expression::AtIndex(_) => "at_index",
2474            Expression::FromTimeZone(_) => "from_time_zone",
2475            Expression::FormatPhrase(_) => "format_phrase",
2476            Expression::ForIn(_) => "for_in",
2477            Expression::TimeUnit(_) => "time_unit",
2478            Expression::IntervalOp(_) => "interval_op",
2479            Expression::IntervalSpan(_) => "interval_span",
2480            Expression::HavingMax(_) => "having_max",
2481            Expression::CosineDistance(_) => "cosine_distance",
2482            Expression::DotProduct(_) => "dot_product",
2483            Expression::EuclideanDistance(_) => "euclidean_distance",
2484            Expression::ManhattanDistance(_) => "manhattan_distance",
2485            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2486            Expression::Booland(_) => "booland",
2487            Expression::Boolor(_) => "boolor",
2488            Expression::ParameterizedAgg(_) => "parameterized_agg",
2489            Expression::ArgMax(_) => "arg_max",
2490            Expression::ArgMin(_) => "arg_min",
2491            Expression::ApproxTopK(_) => "approx_top_k",
2492            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2493            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2494            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2495            Expression::ApproxTopSum(_) => "approx_top_sum",
2496            Expression::ApproxQuantiles(_) => "approx_quantiles",
2497            Expression::Minhash(_) => "minhash",
2498            Expression::FarmFingerprint(_) => "farm_fingerprint",
2499            Expression::Float64(_) => "float64",
2500            Expression::Transform(_) => "transform",
2501            Expression::Translate(_) => "translate",
2502            Expression::Grouping(_) => "grouping",
2503            Expression::GroupingId(_) => "grouping_id",
2504            Expression::Anonymous(_) => "anonymous",
2505            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2506            Expression::CombinedAggFunc(_) => "combined_agg_func",
2507            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2508            Expression::HashAgg(_) => "hash_agg",
2509            Expression::Hll(_) => "hll",
2510            Expression::Apply(_) => "apply",
2511            Expression::ToBoolean(_) => "to_boolean",
2512            Expression::List(_) => "list",
2513            Expression::ToMap(_) => "to_map",
2514            Expression::Pad(_) => "pad",
2515            Expression::ToChar(_) => "to_char",
2516            Expression::ToNumber(_) => "to_number",
2517            Expression::ToDouble(_) => "to_double",
2518            Expression::Int64(_) => "int64",
2519            Expression::StringFunc(_) => "string_func",
2520            Expression::ToDecfloat(_) => "to_decfloat",
2521            Expression::TryToDecfloat(_) => "try_to_decfloat",
2522            Expression::ToFile(_) => "to_file",
2523            Expression::Columns(_) => "columns",
2524            Expression::ConvertToCharset(_) => "convert_to_charset",
2525            Expression::ConvertTimezone(_) => "convert_timezone",
2526            Expression::GenerateSeries(_) => "generate_series",
2527            Expression::AIAgg(_) => "a_i_agg",
2528            Expression::AIClassify(_) => "a_i_classify",
2529            Expression::ArrayAll(_) => "array_all",
2530            Expression::ArrayAny(_) => "array_any",
2531            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2532            Expression::StPoint(_) => "st_point",
2533            Expression::StDistance(_) => "st_distance",
2534            Expression::StringToArray(_) => "string_to_array",
2535            Expression::ArraySum(_) => "array_sum",
2536            Expression::ObjectAgg(_) => "object_agg",
2537            Expression::CastToStrType(_) => "cast_to_str_type",
2538            Expression::CheckJson(_) => "check_json",
2539            Expression::CheckXml(_) => "check_xml",
2540            Expression::TranslateCharacters(_) => "translate_characters",
2541            Expression::CurrentSchemas(_) => "current_schemas",
2542            Expression::CurrentDatetime(_) => "current_datetime",
2543            Expression::Localtime(_) => "localtime",
2544            Expression::Localtimestamp(_) => "localtimestamp",
2545            Expression::Systimestamp(_) => "systimestamp",
2546            Expression::CurrentSchema(_) => "current_schema",
2547            Expression::CurrentUser(_) => "current_user",
2548            Expression::UtcTime(_) => "utc_time",
2549            Expression::UtcTimestamp(_) => "utc_timestamp",
2550            Expression::Timestamp(_) => "timestamp",
2551            Expression::DateBin(_) => "date_bin",
2552            Expression::Datetime(_) => "datetime",
2553            Expression::DatetimeAdd(_) => "datetime_add",
2554            Expression::DatetimeSub(_) => "datetime_sub",
2555            Expression::DatetimeDiff(_) => "datetime_diff",
2556            Expression::DatetimeTrunc(_) => "datetime_trunc",
2557            Expression::Dayname(_) => "dayname",
2558            Expression::MakeInterval(_) => "make_interval",
2559            Expression::PreviousDay(_) => "previous_day",
2560            Expression::Elt(_) => "elt",
2561            Expression::TimestampAdd(_) => "timestamp_add",
2562            Expression::TimestampSub(_) => "timestamp_sub",
2563            Expression::TimestampDiff(_) => "timestamp_diff",
2564            Expression::TimeSlice(_) => "time_slice",
2565            Expression::TimeAdd(_) => "time_add",
2566            Expression::TimeSub(_) => "time_sub",
2567            Expression::TimeDiff(_) => "time_diff",
2568            Expression::TimeTrunc(_) => "time_trunc",
2569            Expression::DateFromParts(_) => "date_from_parts",
2570            Expression::TimeFromParts(_) => "time_from_parts",
2571            Expression::DecodeCase(_) => "decode_case",
2572            Expression::Decrypt(_) => "decrypt",
2573            Expression::DecryptRaw(_) => "decrypt_raw",
2574            Expression::Encode(_) => "encode",
2575            Expression::Encrypt(_) => "encrypt",
2576            Expression::EncryptRaw(_) => "encrypt_raw",
2577            Expression::EqualNull(_) => "equal_null",
2578            Expression::ToBinary(_) => "to_binary",
2579            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2580            Expression::Base64DecodeString(_) => "base64_decode_string",
2581            Expression::Base64Encode(_) => "base64_encode",
2582            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2583            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2584            Expression::GapFill(_) => "gap_fill",
2585            Expression::GenerateDateArray(_) => "generate_date_array",
2586            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2587            Expression::GetExtract(_) => "get_extract",
2588            Expression::Getbit(_) => "getbit",
2589            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2590            Expression::HexEncode(_) => "hex_encode",
2591            Expression::Compress(_) => "compress",
2592            Expression::DecompressBinary(_) => "decompress_binary",
2593            Expression::DecompressString(_) => "decompress_string",
2594            Expression::Xor(_) => "xor",
2595            Expression::Nullif(_) => "nullif",
2596            Expression::JSON(_) => "j_s_o_n",
2597            Expression::JSONPath(_) => "j_s_o_n_path",
2598            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2599            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2600            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2601            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2602            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2603            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2604            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2605            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2606            Expression::Format(_) => "format",
2607            Expression::JSONKeys(_) => "j_s_o_n_keys",
2608            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2609            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2610            Expression::JSONObject(_) => "j_s_o_n_object",
2611            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2612            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2613            Expression::JSONArray(_) => "j_s_o_n_array",
2614            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2615            Expression::JSONExists(_) => "j_s_o_n_exists",
2616            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2617            Expression::JSONSchema(_) => "j_s_o_n_schema",
2618            Expression::JSONSet(_) => "j_s_o_n_set",
2619            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2620            Expression::JSONValue(_) => "j_s_o_n_value",
2621            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2622            Expression::JSONRemove(_) => "j_s_o_n_remove",
2623            Expression::JSONTable(_) => "j_s_o_n_table",
2624            Expression::JSONType(_) => "j_s_o_n_type",
2625            Expression::ObjectInsert(_) => "object_insert",
2626            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2627            Expression::OpenJSON(_) => "open_j_s_o_n",
2628            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2629            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2630            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2631            Expression::JSONCast(_) => "j_s_o_n_cast",
2632            Expression::JSONExtract(_) => "j_s_o_n_extract",
2633            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2634            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2635            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2636            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2637            Expression::JSONFormat(_) => "j_s_o_n_format",
2638            Expression::JSONBool(_) => "j_s_o_n_bool",
2639            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2640            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2641            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2642            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2643            Expression::ParseJSON(_) => "parse_j_s_o_n",
2644            Expression::ParseUrl(_) => "parse_url",
2645            Expression::ParseIp(_) => "parse_ip",
2646            Expression::ParseTime(_) => "parse_time",
2647            Expression::ParseDatetime(_) => "parse_datetime",
2648            Expression::Map(_) => "map",
2649            Expression::MapCat(_) => "map_cat",
2650            Expression::MapDelete(_) => "map_delete",
2651            Expression::MapInsert(_) => "map_insert",
2652            Expression::MapPick(_) => "map_pick",
2653            Expression::ScopeResolution(_) => "scope_resolution",
2654            Expression::Slice(_) => "slice",
2655            Expression::VarMap(_) => "var_map",
2656            Expression::MatchAgainst(_) => "match_against",
2657            Expression::MD5Digest(_) => "m_d5_digest",
2658            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2659            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2660            Expression::Monthname(_) => "monthname",
2661            Expression::Ntile(_) => "ntile",
2662            Expression::Normalize(_) => "normalize",
2663            Expression::Normal(_) => "normal",
2664            Expression::Predict(_) => "predict",
2665            Expression::MLTranslate(_) => "m_l_translate",
2666            Expression::FeaturesAtTime(_) => "features_at_time",
2667            Expression::GenerateEmbedding(_) => "generate_embedding",
2668            Expression::MLForecast(_) => "m_l_forecast",
2669            Expression::ModelAttribute(_) => "model_attribute",
2670            Expression::VectorSearch(_) => "vector_search",
2671            Expression::Quantile(_) => "quantile",
2672            Expression::ApproxQuantile(_) => "approx_quantile",
2673            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2674            Expression::Randn(_) => "randn",
2675            Expression::Randstr(_) => "randstr",
2676            Expression::RangeN(_) => "range_n",
2677            Expression::RangeBucket(_) => "range_bucket",
2678            Expression::ReadCSV(_) => "read_c_s_v",
2679            Expression::ReadParquet(_) => "read_parquet",
2680            Expression::Reduce(_) => "reduce",
2681            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2682            Expression::RegexpILike(_) => "regexp_i_like",
2683            Expression::RegexpFullMatch(_) => "regexp_full_match",
2684            Expression::RegexpInstr(_) => "regexp_instr",
2685            Expression::RegexpSplit(_) => "regexp_split",
2686            Expression::RegexpCount(_) => "regexp_count",
2687            Expression::RegrValx(_) => "regr_valx",
2688            Expression::RegrValy(_) => "regr_valy",
2689            Expression::RegrAvgy(_) => "regr_avgy",
2690            Expression::RegrAvgx(_) => "regr_avgx",
2691            Expression::RegrCount(_) => "regr_count",
2692            Expression::RegrIntercept(_) => "regr_intercept",
2693            Expression::RegrR2(_) => "regr_r2",
2694            Expression::RegrSxx(_) => "regr_sxx",
2695            Expression::RegrSxy(_) => "regr_sxy",
2696            Expression::RegrSyy(_) => "regr_syy",
2697            Expression::RegrSlope(_) => "regr_slope",
2698            Expression::SafeAdd(_) => "safe_add",
2699            Expression::SafeDivide(_) => "safe_divide",
2700            Expression::SafeMultiply(_) => "safe_multiply",
2701            Expression::SafeSubtract(_) => "safe_subtract",
2702            Expression::SHA2(_) => "s_h_a2",
2703            Expression::SHA2Digest(_) => "s_h_a2_digest",
2704            Expression::SortArray(_) => "sort_array",
2705            Expression::SplitPart(_) => "split_part",
2706            Expression::SubstringIndex(_) => "substring_index",
2707            Expression::StandardHash(_) => "standard_hash",
2708            Expression::StrPosition(_) => "str_position",
2709            Expression::Search(_) => "search",
2710            Expression::SearchIp(_) => "search_ip",
2711            Expression::StrToDate(_) => "str_to_date",
2712            Expression::DateStrToDate(_) => "date_str_to_date",
2713            Expression::DateToDateStr(_) => "date_to_date_str",
2714            Expression::StrToTime(_) => "str_to_time",
2715            Expression::StrToUnix(_) => "str_to_unix",
2716            Expression::StrToMap(_) => "str_to_map",
2717            Expression::NumberToStr(_) => "number_to_str",
2718            Expression::FromBase(_) => "from_base",
2719            Expression::Stuff(_) => "stuff",
2720            Expression::TimeToStr(_) => "time_to_str",
2721            Expression::TimeStrToTime(_) => "time_str_to_time",
2722            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2723            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2724            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2725            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2726            Expression::Unhex(_) => "unhex",
2727            Expression::Uniform(_) => "uniform",
2728            Expression::UnixToStr(_) => "unix_to_str",
2729            Expression::UnixToTime(_) => "unix_to_time",
2730            Expression::Uuid(_) => "uuid",
2731            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2732            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2733            Expression::Corr(_) => "corr",
2734            Expression::WidthBucket(_) => "width_bucket",
2735            Expression::CovarSamp(_) => "covar_samp",
2736            Expression::CovarPop(_) => "covar_pop",
2737            Expression::Week(_) => "week",
2738            Expression::XMLElement(_) => "x_m_l_element",
2739            Expression::XMLGet(_) => "x_m_l_get",
2740            Expression::XMLTable(_) => "x_m_l_table",
2741            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2742            Expression::Zipf(_) => "zipf",
2743            Expression::Merge(_) => "merge",
2744            Expression::When(_) => "when",
2745            Expression::Whens(_) => "whens",
2746            Expression::NextValueFor(_) => "next_value_for",
2747            Expression::ReturnStmt(_) => "return_stmt",
2748        }
2749    }
2750
2751    /// Returns the primary child expression (".this" in sqlglot).
2752    pub fn get_this(&self) -> Option<&Expression> {
2753        match self {
2754            // Unary ops
2755            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2756            // UnaryFunc variants
2757            Expression::Upper(f)
2758            | Expression::Lower(f)
2759            | Expression::Length(f)
2760            | Expression::LTrim(f)
2761            | Expression::RTrim(f)
2762            | Expression::Reverse(f)
2763            | Expression::Abs(f)
2764            | Expression::Sqrt(f)
2765            | Expression::Cbrt(f)
2766            | Expression::Ln(f)
2767            | Expression::Exp(f)
2768            | Expression::Sign(f)
2769            | Expression::Date(f)
2770            | Expression::Time(f)
2771            | Expression::Initcap(f)
2772            | Expression::Ascii(f)
2773            | Expression::Chr(f)
2774            | Expression::Soundex(f)
2775            | Expression::ByteLength(f)
2776            | Expression::Hex(f)
2777            | Expression::LowerHex(f)
2778            | Expression::Unicode(f)
2779            | Expression::Typeof(f)
2780            | Expression::Explode(f)
2781            | Expression::ExplodeOuter(f)
2782            | Expression::MapFromEntries(f)
2783            | Expression::MapKeys(f)
2784            | Expression::MapValues(f)
2785            | Expression::ArrayLength(f)
2786            | Expression::ArraySize(f)
2787            | Expression::Cardinality(f)
2788            | Expression::ArrayReverse(f)
2789            | Expression::ArrayDistinct(f)
2790            | Expression::ArrayFlatten(f)
2791            | Expression::ArrayCompact(f)
2792            | Expression::ToArray(f)
2793            | Expression::JsonArrayLength(f)
2794            | Expression::JsonKeys(f)
2795            | Expression::JsonType(f)
2796            | Expression::ParseJson(f)
2797            | Expression::ToJson(f)
2798            | Expression::Radians(f)
2799            | Expression::Degrees(f)
2800            | Expression::Sin(f)
2801            | Expression::Cos(f)
2802            | Expression::Tan(f)
2803            | Expression::Asin(f)
2804            | Expression::Acos(f)
2805            | Expression::Atan(f)
2806            | Expression::IsNan(f)
2807            | Expression::IsInf(f)
2808            | Expression::Year(f)
2809            | Expression::Month(f)
2810            | Expression::Day(f)
2811            | Expression::Hour(f)
2812            | Expression::Minute(f)
2813            | Expression::Second(f)
2814            | Expression::DayOfWeek(f)
2815            | Expression::DayOfWeekIso(f)
2816            | Expression::DayOfMonth(f)
2817            | Expression::DayOfYear(f)
2818            | Expression::WeekOfYear(f)
2819            | Expression::Quarter(f)
2820            | Expression::Epoch(f)
2821            | Expression::EpochMs(f)
2822            | Expression::BitwiseCount(f)
2823            | Expression::DateFromUnixDate(f)
2824            | Expression::UnixDate(f)
2825            | Expression::UnixSeconds(f)
2826            | Expression::UnixMillis(f)
2827            | Expression::UnixMicros(f)
2828            | Expression::TimeStrToDate(f)
2829            | Expression::DateToDi(f)
2830            | Expression::DiToDate(f)
2831            | Expression::TsOrDiToDi(f)
2832            | Expression::TsOrDsToDatetime(f)
2833            | Expression::TsOrDsToTimestamp(f)
2834            | Expression::YearOfWeek(f)
2835            | Expression::YearOfWeekIso(f)
2836            | Expression::SHA(f)
2837            | Expression::SHA1Digest(f)
2838            | Expression::TimeToUnix(f)
2839            | Expression::TimeStrToUnix(f)
2840            | Expression::Int64(f)
2841            | Expression::JSONBool(f)
2842            | Expression::MD5NumberLower64(f)
2843            | Expression::MD5NumberUpper64(f)
2844            | Expression::DateStrToDate(f)
2845            | Expression::DateToDateStr(f) => Some(&f.this),
2846            // BinaryFunc - this is the primary child
2847            Expression::Power(f)
2848            | Expression::NullIf(f)
2849            | Expression::IfNull(f)
2850            | Expression::Nvl(f)
2851            | Expression::Contains(f)
2852            | Expression::StartsWith(f)
2853            | Expression::EndsWith(f)
2854            | Expression::Levenshtein(f)
2855            | Expression::ModFunc(f)
2856            | Expression::IntDiv(f)
2857            | Expression::Atan2(f)
2858            | Expression::AddMonths(f)
2859            | Expression::MonthsBetween(f)
2860            | Expression::NextDay(f)
2861            | Expression::UnixToTimeStr(f)
2862            | Expression::ArrayContains(f)
2863            | Expression::ArrayPosition(f)
2864            | Expression::ArrayAppend(f)
2865            | Expression::ArrayPrepend(f)
2866            | Expression::ArrayUnion(f)
2867            | Expression::ArrayExcept(f)
2868            | Expression::ArrayRemove(f)
2869            | Expression::StarMap(f)
2870            | Expression::MapFromArrays(f)
2871            | Expression::MapContainsKey(f)
2872            | Expression::ElementAt(f)
2873            | Expression::JsonMergePatch(f)
2874            | Expression::JSONBContains(f)
2875            | Expression::JSONBExtract(f) => Some(&f.this),
2876            // AggFunc - this is the primary child
2877            Expression::Sum(af)
2878            | Expression::Avg(af)
2879            | Expression::Min(af)
2880            | Expression::Max(af)
2881            | Expression::ArrayAgg(af)
2882            | Expression::CountIf(af)
2883            | Expression::Stddev(af)
2884            | Expression::StddevPop(af)
2885            | Expression::StddevSamp(af)
2886            | Expression::Variance(af)
2887            | Expression::VarPop(af)
2888            | Expression::VarSamp(af)
2889            | Expression::Median(af)
2890            | Expression::Mode(af)
2891            | Expression::First(af)
2892            | Expression::Last(af)
2893            | Expression::AnyValue(af)
2894            | Expression::ApproxDistinct(af)
2895            | Expression::ApproxCountDistinct(af)
2896            | Expression::LogicalAnd(af)
2897            | Expression::LogicalOr(af)
2898            | Expression::Skewness(af)
2899            | Expression::ArrayConcatAgg(af)
2900            | Expression::ArrayUniqueAgg(af)
2901            | Expression::BoolXorAgg(af)
2902            | Expression::BitwiseAndAgg(af)
2903            | Expression::BitwiseOrAgg(af)
2904            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2905            // Binary operations - left is "this" in sqlglot
2906            Expression::And(op)
2907            | Expression::Or(op)
2908            | Expression::Add(op)
2909            | Expression::Sub(op)
2910            | Expression::Mul(op)
2911            | Expression::Div(op)
2912            | Expression::Mod(op)
2913            | Expression::Eq(op)
2914            | Expression::Neq(op)
2915            | Expression::Lt(op)
2916            | Expression::Lte(op)
2917            | Expression::Gt(op)
2918            | Expression::Gte(op)
2919            | Expression::BitwiseAnd(op)
2920            | Expression::BitwiseOr(op)
2921            | Expression::BitwiseXor(op)
2922            | Expression::Concat(op)
2923            | Expression::Adjacent(op)
2924            | Expression::TsMatch(op)
2925            | Expression::PropertyEQ(op)
2926            | Expression::ArrayContainsAll(op)
2927            | Expression::ArrayContainedBy(op)
2928            | Expression::ArrayOverlaps(op)
2929            | Expression::JSONBContainsAllTopKeys(op)
2930            | Expression::JSONBContainsAnyTopKeys(op)
2931            | Expression::JSONBDeleteAtPath(op)
2932            | Expression::ExtendsLeft(op)
2933            | Expression::ExtendsRight(op)
2934            | Expression::Is(op)
2935            | Expression::MemberOf(op)
2936            | Expression::Match(op)
2937            | Expression::NullSafeEq(op)
2938            | Expression::NullSafeNeq(op)
2939            | Expression::Glob(op)
2940            | Expression::BitwiseLeftShift(op)
2941            | Expression::BitwiseRightShift(op) => Some(&op.left),
2942            // Like operations - left is "this"
2943            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2944            // Structural types with .this
2945            Expression::Alias(a) => Some(&a.this),
2946            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2947            Expression::Paren(p) => Some(&p.this),
2948            Expression::Annotated(a) => Some(&a.this),
2949            Expression::Subquery(s) => Some(&s.this),
2950            Expression::Where(w) => Some(&w.this),
2951            Expression::Having(h) => Some(&h.this),
2952            Expression::Qualify(q) => Some(&q.this),
2953            Expression::IsNull(i) => Some(&i.this),
2954            Expression::Exists(e) => Some(&e.this),
2955            Expression::Ordered(o) => Some(&o.this),
2956            Expression::WindowFunction(wf) => Some(&wf.this),
2957            Expression::Cte(cte) => Some(&cte.this),
2958            Expression::Between(b) => Some(&b.this),
2959            Expression::In(i) => Some(&i.this),
2960            Expression::ReturnStmt(e) => Some(e),
2961            _ => None,
2962        }
2963    }
2964
2965    /// Returns the secondary child expression (".expression" in sqlglot).
2966    pub fn get_expression(&self) -> Option<&Expression> {
2967        match self {
2968            // Binary operations - right is "expression"
2969            Expression::And(op)
2970            | Expression::Or(op)
2971            | Expression::Add(op)
2972            | Expression::Sub(op)
2973            | Expression::Mul(op)
2974            | Expression::Div(op)
2975            | Expression::Mod(op)
2976            | Expression::Eq(op)
2977            | Expression::Neq(op)
2978            | Expression::Lt(op)
2979            | Expression::Lte(op)
2980            | Expression::Gt(op)
2981            | Expression::Gte(op)
2982            | Expression::BitwiseAnd(op)
2983            | Expression::BitwiseOr(op)
2984            | Expression::BitwiseXor(op)
2985            | Expression::Concat(op)
2986            | Expression::Adjacent(op)
2987            | Expression::TsMatch(op)
2988            | Expression::PropertyEQ(op)
2989            | Expression::ArrayContainsAll(op)
2990            | Expression::ArrayContainedBy(op)
2991            | Expression::ArrayOverlaps(op)
2992            | Expression::JSONBContainsAllTopKeys(op)
2993            | Expression::JSONBContainsAnyTopKeys(op)
2994            | Expression::JSONBDeleteAtPath(op)
2995            | Expression::ExtendsLeft(op)
2996            | Expression::ExtendsRight(op)
2997            | Expression::Is(op)
2998            | Expression::MemberOf(op)
2999            | Expression::Match(op)
3000            | Expression::NullSafeEq(op)
3001            | Expression::NullSafeNeq(op)
3002            | Expression::Glob(op)
3003            | Expression::BitwiseLeftShift(op)
3004            | Expression::BitwiseRightShift(op) => Some(&op.right),
3005            // Like operations - right is "expression"
3006            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3007            // BinaryFunc - expression is the secondary
3008            Expression::Power(f)
3009            | Expression::NullIf(f)
3010            | Expression::IfNull(f)
3011            | Expression::Nvl(f)
3012            | Expression::Contains(f)
3013            | Expression::StartsWith(f)
3014            | Expression::EndsWith(f)
3015            | Expression::Levenshtein(f)
3016            | Expression::ModFunc(f)
3017            | Expression::IntDiv(f)
3018            | Expression::Atan2(f)
3019            | Expression::AddMonths(f)
3020            | Expression::MonthsBetween(f)
3021            | Expression::NextDay(f)
3022            | Expression::UnixToTimeStr(f)
3023            | Expression::ArrayContains(f)
3024            | Expression::ArrayPosition(f)
3025            | Expression::ArrayAppend(f)
3026            | Expression::ArrayPrepend(f)
3027            | Expression::ArrayUnion(f)
3028            | Expression::ArrayExcept(f)
3029            | Expression::ArrayRemove(f)
3030            | Expression::StarMap(f)
3031            | Expression::MapFromArrays(f)
3032            | Expression::MapContainsKey(f)
3033            | Expression::ElementAt(f)
3034            | Expression::JsonMergePatch(f)
3035            | Expression::JSONBContains(f)
3036            | Expression::JSONBExtract(f) => Some(&f.expression),
3037            _ => None,
3038        }
3039    }
3040
3041    /// Returns the list of child expressions (".expressions" in sqlglot).
3042    pub fn get_expressions(&self) -> &[Expression] {
3043        match self {
3044            Expression::Select(s) => &s.expressions,
3045            Expression::Function(f) => &f.args,
3046            Expression::AggregateFunction(f) => &f.args,
3047            Expression::From(f) => &f.expressions,
3048            Expression::GroupBy(g) => &g.expressions,
3049            Expression::In(i) => &i.expressions,
3050            Expression::Array(a) => &a.expressions,
3051            Expression::Tuple(t) => &t.expressions,
3052            Expression::Coalesce(f)
3053            | Expression::Greatest(f)
3054            | Expression::Least(f)
3055            | Expression::ArrayConcat(f)
3056            | Expression::ArrayIntersect(f)
3057            | Expression::ArrayZip(f)
3058            | Expression::MapConcat(f)
3059            | Expression::JsonArray(f) => &f.expressions,
3060            _ => &[],
3061        }
3062    }
3063
3064    /// Returns the name of this expression as a string slice.
3065    pub fn get_name(&self) -> &str {
3066        match self {
3067            Expression::Identifier(id) => &id.name,
3068            Expression::Column(col) => &col.name.name,
3069            Expression::Table(t) => &t.name.name,
3070            Expression::Literal(lit) => lit.value_str(),
3071            Expression::Star(_) => "*",
3072            Expression::Function(f) => &f.name,
3073            Expression::AggregateFunction(f) => &f.name,
3074            Expression::Alias(a) => a.this.get_name(),
3075            Expression::Boolean(b) => {
3076                if b.value {
3077                    "TRUE"
3078                } else {
3079                    "FALSE"
3080                }
3081            }
3082            Expression::Null(_) => "NULL",
3083            _ => "",
3084        }
3085    }
3086
3087    /// Returns the alias name if this expression has one.
3088    pub fn get_alias(&self) -> &str {
3089        match self {
3090            Expression::Alias(a) => &a.alias.name,
3091            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3092            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3093            _ => "",
3094        }
3095    }
3096
3097    /// Returns the output name of this expression (what it shows up as in a SELECT).
3098    pub fn get_output_name(&self) -> &str {
3099        match self {
3100            Expression::Alias(a) => &a.alias.name,
3101            Expression::Column(c) => &c.name.name,
3102            Expression::Identifier(id) => &id.name,
3103            Expression::Literal(lit) => lit.value_str(),
3104            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3105            Expression::Star(_) => "*",
3106            _ => "",
3107        }
3108    }
3109
3110    /// Returns comments attached to this expression.
3111    pub fn get_comments(&self) -> Vec<&str> {
3112        match self {
3113            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3114            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3115            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3116            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3117            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3118            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3119            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3120                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3121            }
3122            Expression::And(op)
3123            | Expression::Or(op)
3124            | Expression::Add(op)
3125            | Expression::Sub(op)
3126            | Expression::Mul(op)
3127            | Expression::Div(op)
3128            | Expression::Mod(op)
3129            | Expression::Eq(op)
3130            | Expression::Neq(op)
3131            | Expression::Lt(op)
3132            | Expression::Lte(op)
3133            | Expression::Gt(op)
3134            | Expression::Gte(op)
3135            | Expression::Concat(op)
3136            | Expression::BitwiseAnd(op)
3137            | Expression::BitwiseOr(op)
3138            | Expression::BitwiseXor(op) => {
3139                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3140            }
3141            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3142            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3143            _ => Vec::new(),
3144        }
3145    }
3146}
3147
3148impl fmt::Display for Expression {
3149    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3150        // Basic display - full SQL generation is in generator module
3151        match self {
3152            Expression::Literal(lit) => write!(f, "{}", lit),
3153            Expression::Identifier(id) => write!(f, "{}", id),
3154            Expression::Column(col) => write!(f, "{}", col),
3155            Expression::Star(_) => write!(f, "*"),
3156            Expression::Null(_) => write!(f, "NULL"),
3157            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3158            Expression::Select(_) => write!(f, "SELECT ..."),
3159            _ => write!(f, "{:?}", self),
3160        }
3161    }
3162}
3163
3164/// Represent a SQL literal value.
3165///
3166/// Numeric values are stored as their original text representation (not parsed
3167/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3168/// preserved across round-trips.
3169///
3170/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3171/// strings, raw strings, etc.) each have a dedicated variant so that the
3172/// generator can emit them with the correct syntax.
3173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3174#[cfg_attr(feature = "bindings", derive(TS))]
3175#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3176pub enum Literal {
3177    /// Single-quoted string literal: `'hello'`
3178    String(String),
3179    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3180    Number(String),
3181    /// Hex string literal: `X'FF'`
3182    HexString(String),
3183    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3184    HexNumber(String),
3185    BitString(String),
3186    /// Byte string: b"..." (BigQuery style)
3187    ByteString(String),
3188    /// National string: N'abc'
3189    NationalString(String),
3190    /// DATE literal: DATE '2024-01-15'
3191    Date(String),
3192    /// TIME literal: TIME '10:30:00'
3193    Time(String),
3194    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3195    Timestamp(String),
3196    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3197    Datetime(String),
3198    /// Triple-quoted string: """...""" or '''...'''
3199    /// Contains (content, quote_char) where quote_char is '"' or '\''
3200    TripleQuotedString(String, char),
3201    /// Escape string: E'...' (PostgreSQL)
3202    EscapeString(String),
3203    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3204    DollarString(String),
3205    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3206    /// In raw strings, backslashes are literal and not escape characters.
3207    /// When converting to a regular string, backslashes must be doubled.
3208    RawString(String),
3209}
3210
3211impl Literal {
3212    /// Returns the inner value as a string slice, regardless of literal type.
3213    pub fn value_str(&self) -> &str {
3214        match self {
3215            Literal::String(s)
3216            | Literal::Number(s)
3217            | Literal::HexString(s)
3218            | Literal::HexNumber(s)
3219            | Literal::BitString(s)
3220            | Literal::ByteString(s)
3221            | Literal::NationalString(s)
3222            | Literal::Date(s)
3223            | Literal::Time(s)
3224            | Literal::Timestamp(s)
3225            | Literal::Datetime(s)
3226            | Literal::EscapeString(s)
3227            | Literal::DollarString(s)
3228            | Literal::RawString(s) => s.as_str(),
3229            Literal::TripleQuotedString(s, _) => s.as_str(),
3230        }
3231    }
3232
3233    /// Returns `true` if this is a string-type literal.
3234    pub fn is_string(&self) -> bool {
3235        matches!(
3236            self,
3237            Literal::String(_)
3238                | Literal::NationalString(_)
3239                | Literal::EscapeString(_)
3240                | Literal::DollarString(_)
3241                | Literal::RawString(_)
3242                | Literal::TripleQuotedString(_, _)
3243        )
3244    }
3245
3246    /// Returns `true` if this is a numeric literal.
3247    pub fn is_number(&self) -> bool {
3248        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3249    }
3250}
3251
3252impl fmt::Display for Literal {
3253    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3254        match self {
3255            Literal::String(s) => write!(f, "'{}'", s),
3256            Literal::Number(n) => write!(f, "{}", n),
3257            Literal::HexString(h) => write!(f, "X'{}'", h),
3258            Literal::HexNumber(h) => write!(f, "0x{}", h),
3259            Literal::BitString(b) => write!(f, "B'{}'", b),
3260            Literal::ByteString(b) => write!(f, "b'{}'", b),
3261            Literal::NationalString(s) => write!(f, "N'{}'", s),
3262            Literal::Date(d) => write!(f, "DATE '{}'", d),
3263            Literal::Time(t) => write!(f, "TIME '{}'", t),
3264            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3265            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3266            Literal::TripleQuotedString(s, q) => {
3267                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3268            }
3269            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3270            Literal::DollarString(s) => write!(f, "$${}$$", s),
3271            Literal::RawString(s) => write!(f, "r'{}'", s),
3272        }
3273    }
3274}
3275
3276/// Boolean literal
3277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3278#[cfg_attr(feature = "bindings", derive(TS))]
3279pub struct BooleanLiteral {
3280    pub value: bool,
3281}
3282
3283/// NULL literal
3284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3285#[cfg_attr(feature = "bindings", derive(TS))]
3286pub struct Null;
3287
3288/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3289///
3290/// The `quoted` flag indicates whether the identifier was originally delimited
3291/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3292/// dialect). The generator uses this flag to decide whether to emit quoting
3293/// characters.
3294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3295#[cfg_attr(feature = "bindings", derive(TS))]
3296pub struct Identifier {
3297    /// The raw text of the identifier, without any quoting characters.
3298    pub name: String,
3299    /// Whether the identifier was quoted in the source SQL.
3300    pub quoted: bool,
3301    #[serde(default)]
3302    pub trailing_comments: Vec<String>,
3303    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3304    #[serde(default, skip_serializing_if = "Option::is_none")]
3305    pub span: Option<Span>,
3306}
3307
3308impl Identifier {
3309    pub fn new(name: impl Into<String>) -> Self {
3310        Self {
3311            name: name.into(),
3312            quoted: false,
3313            trailing_comments: Vec::new(),
3314            span: None,
3315        }
3316    }
3317
3318    pub fn quoted(name: impl Into<String>) -> Self {
3319        Self {
3320            name: name.into(),
3321            quoted: true,
3322            trailing_comments: Vec::new(),
3323            span: None,
3324        }
3325    }
3326
3327    pub fn empty() -> Self {
3328        Self {
3329            name: String::new(),
3330            quoted: false,
3331            trailing_comments: Vec::new(),
3332            span: None,
3333        }
3334    }
3335
3336    pub fn is_empty(&self) -> bool {
3337        self.name.is_empty()
3338    }
3339
3340    /// Set the source span on this identifier
3341    pub fn with_span(mut self, span: Span) -> Self {
3342        self.span = Some(span);
3343        self
3344    }
3345}
3346
3347impl fmt::Display for Identifier {
3348    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3349        if self.quoted {
3350            write!(f, "\"{}\"", self.name)
3351        } else {
3352            write!(f, "{}", self.name)
3353        }
3354    }
3355}
3356
3357/// Represent a column reference, optionally qualified by a table name.
3358///
3359/// Renders as `name` when unqualified, or `table.name` when qualified.
3360/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3361/// convenient construction.
3362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3363#[cfg_attr(feature = "bindings", derive(TS))]
3364pub struct Column {
3365    /// The column name.
3366    pub name: Identifier,
3367    /// Optional table qualifier (e.g. `t` in `t.col`).
3368    pub table: Option<Identifier>,
3369    /// Oracle-style join marker (+) for outer joins
3370    #[serde(default)]
3371    pub join_mark: bool,
3372    /// Trailing comments that appeared after this column reference
3373    #[serde(default)]
3374    pub trailing_comments: Vec<String>,
3375    /// Source position span
3376    #[serde(default, skip_serializing_if = "Option::is_none")]
3377    pub span: Option<Span>,
3378    /// Inferred data type from type annotation
3379    #[serde(default, skip_serializing_if = "Option::is_none")]
3380    pub inferred_type: Option<DataType>,
3381}
3382
3383impl fmt::Display for Column {
3384    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3385        if let Some(table) = &self.table {
3386            write!(f, "{}.{}", table, self.name)
3387        } else {
3388            write!(f, "{}", self.name)
3389        }
3390    }
3391}
3392
3393/// Represent a table reference with optional schema and catalog qualifiers.
3394///
3395/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3396/// which qualifiers are present. Supports aliases, column alias lists,
3397/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3398/// several other dialect-specific extensions.
3399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3400#[cfg_attr(feature = "bindings", derive(TS))]
3401pub struct TableRef {
3402    /// The unqualified table name.
3403    pub name: Identifier,
3404    /// Optional schema qualifier (e.g. `public` in `public.users`).
3405    pub schema: Option<Identifier>,
3406    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3407    pub catalog: Option<Identifier>,
3408    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3409    pub alias: Option<Identifier>,
3410    /// Whether AS keyword was explicitly used for the alias
3411    #[serde(default)]
3412    pub alias_explicit_as: bool,
3413    /// Column aliases for table alias: AS t(c1, c2)
3414    #[serde(default)]
3415    pub column_aliases: Vec<Identifier>,
3416    /// Leading comments that appeared before this table reference in a FROM clause
3417    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3418    pub leading_comments: Vec<String>,
3419    /// Trailing comments that appeared after this table reference
3420    #[serde(default)]
3421    pub trailing_comments: Vec<String>,
3422    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3423    #[serde(default)]
3424    pub when: Option<Box<HistoricalData>>,
3425    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3426    #[serde(default)]
3427    pub only: bool,
3428    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3429    #[serde(default)]
3430    pub final_: bool,
3431    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3432    #[serde(default, skip_serializing_if = "Option::is_none")]
3433    pub table_sample: Option<Box<Sample>>,
3434    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3435    #[serde(default)]
3436    pub hints: Vec<Expression>,
3437    /// TSQL: FOR SYSTEM_TIME temporal clause
3438    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3439    #[serde(default, skip_serializing_if = "Option::is_none")]
3440    pub system_time: Option<String>,
3441    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3442    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3443    pub partitions: Vec<Identifier>,
3444    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3445    /// When set, this is used instead of the name field
3446    #[serde(default, skip_serializing_if = "Option::is_none")]
3447    pub identifier_func: Option<Box<Expression>>,
3448    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3449    #[serde(default, skip_serializing_if = "Option::is_none")]
3450    pub changes: Option<Box<Changes>>,
3451    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub version: Option<Box<Version>>,
3454    /// Source position span
3455    #[serde(default, skip_serializing_if = "Option::is_none")]
3456    pub span: Option<Span>,
3457}
3458
3459impl TableRef {
3460    pub fn new(name: impl Into<String>) -> Self {
3461        Self {
3462            name: Identifier::new(name),
3463            schema: None,
3464            catalog: None,
3465            alias: None,
3466            alias_explicit_as: false,
3467            column_aliases: Vec::new(),
3468            leading_comments: Vec::new(),
3469            trailing_comments: Vec::new(),
3470            when: None,
3471            only: false,
3472            final_: false,
3473            table_sample: None,
3474            hints: Vec::new(),
3475            system_time: None,
3476            partitions: Vec::new(),
3477            identifier_func: None,
3478            changes: None,
3479            version: None,
3480            span: None,
3481        }
3482    }
3483
3484    /// Create with a schema qualifier.
3485    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3486        let mut t = Self::new(name);
3487        t.schema = Some(Identifier::new(schema));
3488        t
3489    }
3490
3491    /// Create with catalog and schema qualifiers.
3492    pub fn new_with_catalog(
3493        name: impl Into<String>,
3494        schema: impl Into<String>,
3495        catalog: impl Into<String>,
3496    ) -> Self {
3497        let mut t = Self::new(name);
3498        t.schema = Some(Identifier::new(schema));
3499        t.catalog = Some(Identifier::new(catalog));
3500        t
3501    }
3502
3503    /// Create from an Identifier, preserving the quoted flag
3504    pub fn from_identifier(name: Identifier) -> Self {
3505        Self {
3506            name,
3507            schema: None,
3508            catalog: None,
3509            alias: None,
3510            alias_explicit_as: false,
3511            column_aliases: Vec::new(),
3512            leading_comments: Vec::new(),
3513            trailing_comments: Vec::new(),
3514            when: None,
3515            only: false,
3516            final_: false,
3517            table_sample: None,
3518            hints: Vec::new(),
3519            system_time: None,
3520            partitions: Vec::new(),
3521            identifier_func: None,
3522            changes: None,
3523            version: None,
3524            span: None,
3525        }
3526    }
3527
3528    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3529        self.alias = Some(Identifier::new(alias));
3530        self
3531    }
3532
3533    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3534        self.schema = Some(Identifier::new(schema));
3535        self
3536    }
3537}
3538
3539/// Represent a wildcard star expression (`*`, `table.*`).
3540///
3541/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3542/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3544#[cfg_attr(feature = "bindings", derive(TS))]
3545pub struct Star {
3546    /// Optional table qualifier (e.g. `t` in `t.*`).
3547    pub table: Option<Identifier>,
3548    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3549    pub except: Option<Vec<Identifier>>,
3550    /// REPLACE expressions (BigQuery, Snowflake)
3551    pub replace: Option<Vec<Alias>>,
3552    /// RENAME columns (Snowflake)
3553    pub rename: Option<Vec<(Identifier, Identifier)>>,
3554    /// Trailing comments that appeared after the star
3555    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3556    pub trailing_comments: Vec<String>,
3557    /// Source position span
3558    #[serde(default, skip_serializing_if = "Option::is_none")]
3559    pub span: Option<Span>,
3560}
3561
3562/// Represent a complete SELECT statement.
3563///
3564/// This is the most feature-rich AST node, covering the full surface area of
3565/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3566/// `Vec` are omitted from the generated SQL when absent.
3567///
3568/// # Key Fields
3569///
3570/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3571/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3572/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3573/// - `where_clause` -- the WHERE predicate.
3574/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3575/// - `having` -- HAVING predicate.
3576/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3577/// - `limit` / `offset` / `fetch` -- result set limiting.
3578/// - `with` -- Common Table Expressions (CTEs).
3579/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3580/// - `windows` -- named window definitions (WINDOW w AS ...).
3581///
3582/// Dialect-specific extensions are supported via fields like `prewhere`
3583/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3584/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3586#[cfg_attr(feature = "bindings", derive(TS))]
3587pub struct Select {
3588    /// The select-list: columns, expressions, aliases, and wildcards.
3589    pub expressions: Vec<Expression>,
3590    /// The FROM clause, containing one or more table sources.
3591    pub from: Option<From>,
3592    /// JOIN clauses applied after the FROM source.
3593    pub joins: Vec<Join>,
3594    pub lateral_views: Vec<LateralView>,
3595    /// ClickHouse PREWHERE clause
3596    #[serde(default, skip_serializing_if = "Option::is_none")]
3597    pub prewhere: Option<Expression>,
3598    pub where_clause: Option<Where>,
3599    pub group_by: Option<GroupBy>,
3600    pub having: Option<Having>,
3601    pub qualify: Option<Qualify>,
3602    pub order_by: Option<OrderBy>,
3603    pub distribute_by: Option<DistributeBy>,
3604    pub cluster_by: Option<ClusterBy>,
3605    pub sort_by: Option<SortBy>,
3606    pub limit: Option<Limit>,
3607    pub offset: Option<Offset>,
3608    /// ClickHouse LIMIT BY clause expressions
3609    #[serde(default, skip_serializing_if = "Option::is_none")]
3610    pub limit_by: Option<Vec<Expression>>,
3611    pub fetch: Option<Fetch>,
3612    pub distinct: bool,
3613    pub distinct_on: Option<Vec<Expression>>,
3614    pub top: Option<Top>,
3615    pub with: Option<With>,
3616    pub sample: Option<Sample>,
3617    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3618    #[serde(default, skip_serializing_if = "Option::is_none")]
3619    pub settings: Option<Vec<Expression>>,
3620    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3621    #[serde(default, skip_serializing_if = "Option::is_none")]
3622    pub format: Option<Expression>,
3623    pub windows: Option<Vec<NamedWindow>>,
3624    pub hint: Option<Hint>,
3625    /// Oracle CONNECT BY clause for hierarchical queries
3626    pub connect: Option<Connect>,
3627    /// SELECT ... INTO table_name for creating tables
3628    pub into: Option<SelectInto>,
3629    /// FOR UPDATE/SHARE locking clauses
3630    #[serde(default)]
3631    pub locks: Vec<Lock>,
3632    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub for_xml: Vec<Expression>,
3635    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3636    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3637    pub for_json: Vec<Expression>,
3638    /// Leading comments before the statement
3639    #[serde(default)]
3640    pub leading_comments: Vec<String>,
3641    /// Comments that appear after SELECT keyword (before expressions)
3642    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3643    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3644    pub post_select_comments: Vec<String>,
3645    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3646    #[serde(default, skip_serializing_if = "Option::is_none")]
3647    pub kind: Option<String>,
3648    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3649    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3650    pub operation_modifiers: Vec<String>,
3651    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3652    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3653    pub qualify_after_window: bool,
3654    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3655    #[serde(default, skip_serializing_if = "Option::is_none")]
3656    pub option: Option<String>,
3657    /// Redshift-style EXCLUDE clause at the end of the projection list
3658    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3659    #[serde(default, skip_serializing_if = "Option::is_none")]
3660    pub exclude: Option<Vec<Expression>>,
3661}
3662
3663impl Select {
3664    pub fn new() -> Self {
3665        Self {
3666            expressions: Vec::new(),
3667            from: None,
3668            joins: Vec::new(),
3669            lateral_views: Vec::new(),
3670            prewhere: None,
3671            where_clause: None,
3672            group_by: None,
3673            having: None,
3674            qualify: None,
3675            order_by: None,
3676            distribute_by: None,
3677            cluster_by: None,
3678            sort_by: None,
3679            limit: None,
3680            offset: None,
3681            limit_by: None,
3682            fetch: None,
3683            distinct: false,
3684            distinct_on: None,
3685            top: None,
3686            with: None,
3687            sample: None,
3688            settings: None,
3689            format: None,
3690            windows: None,
3691            hint: None,
3692            connect: None,
3693            into: None,
3694            locks: Vec::new(),
3695            for_xml: Vec::new(),
3696            for_json: Vec::new(),
3697            leading_comments: Vec::new(),
3698            post_select_comments: Vec::new(),
3699            kind: None,
3700            operation_modifiers: Vec::new(),
3701            qualify_after_window: false,
3702            option: None,
3703            exclude: None,
3704        }
3705    }
3706
3707    /// Add a column to select
3708    pub fn column(mut self, expr: Expression) -> Self {
3709        self.expressions.push(expr);
3710        self
3711    }
3712
3713    /// Set the FROM clause
3714    pub fn from(mut self, table: Expression) -> Self {
3715        self.from = Some(From {
3716            expressions: vec![table],
3717        });
3718        self
3719    }
3720
3721    /// Add a WHERE clause
3722    pub fn where_(mut self, condition: Expression) -> Self {
3723        self.where_clause = Some(Where { this: condition });
3724        self
3725    }
3726
3727    /// Set DISTINCT
3728    pub fn distinct(mut self) -> Self {
3729        self.distinct = true;
3730        self
3731    }
3732
3733    /// Add a JOIN
3734    pub fn join(mut self, join: Join) -> Self {
3735        self.joins.push(join);
3736        self
3737    }
3738
3739    /// Set ORDER BY
3740    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3741        self.order_by = Some(OrderBy {
3742            expressions,
3743            siblings: false,
3744            comments: Vec::new(),
3745        });
3746        self
3747    }
3748
3749    /// Set LIMIT
3750    pub fn limit(mut self, n: Expression) -> Self {
3751        self.limit = Some(Limit {
3752            this: n,
3753            percent: false,
3754            comments: Vec::new(),
3755        });
3756        self
3757    }
3758
3759    /// Set OFFSET
3760    pub fn offset(mut self, n: Expression) -> Self {
3761        self.offset = Some(Offset {
3762            this: n,
3763            rows: None,
3764        });
3765        self
3766    }
3767}
3768
3769impl Default for Select {
3770    fn default() -> Self {
3771        Self::new()
3772    }
3773}
3774
3775/// Represent a UNION set operation between two query expressions.
3776///
3777/// When `all` is true, duplicate rows are preserved (UNION ALL).
3778/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3779/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3781#[cfg_attr(feature = "bindings", derive(TS))]
3782pub struct Union {
3783    /// The left-hand query operand.
3784    pub left: Expression,
3785    /// The right-hand query operand.
3786    pub right: Expression,
3787    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3788    pub all: bool,
3789    /// Whether DISTINCT was explicitly specified
3790    #[serde(default)]
3791    pub distinct: bool,
3792    /// Optional WITH clause
3793    pub with: Option<With>,
3794    /// ORDER BY applied to entire UNION result
3795    pub order_by: Option<OrderBy>,
3796    /// LIMIT applied to entire UNION result
3797    pub limit: Option<Box<Expression>>,
3798    /// OFFSET applied to entire UNION result
3799    pub offset: Option<Box<Expression>>,
3800    /// DISTRIBUTE BY clause (Hive/Spark)
3801    #[serde(default, skip_serializing_if = "Option::is_none")]
3802    pub distribute_by: Option<DistributeBy>,
3803    /// SORT BY clause (Hive/Spark)
3804    #[serde(default, skip_serializing_if = "Option::is_none")]
3805    pub sort_by: Option<SortBy>,
3806    /// CLUSTER BY clause (Hive/Spark)
3807    #[serde(default, skip_serializing_if = "Option::is_none")]
3808    pub cluster_by: Option<ClusterBy>,
3809    /// DuckDB BY NAME modifier
3810    #[serde(default)]
3811    pub by_name: bool,
3812    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub side: Option<String>,
3815    /// BigQuery: Set operation kind (INNER)
3816    #[serde(default, skip_serializing_if = "Option::is_none")]
3817    pub kind: Option<String>,
3818    /// BigQuery: CORRESPONDING modifier
3819    #[serde(default)]
3820    pub corresponding: bool,
3821    /// BigQuery: STRICT modifier (before CORRESPONDING)
3822    #[serde(default)]
3823    pub strict: bool,
3824    /// BigQuery: BY (columns) after CORRESPONDING
3825    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3826    pub on_columns: Vec<Expression>,
3827}
3828
3829/// Iteratively flatten the left-recursive chain to prevent stack overflow
3830/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3831impl Drop for Union {
3832    fn drop(&mut self) {
3833        loop {
3834            if let Expression::Union(ref mut inner) = self.left {
3835                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3836                let old_left = std::mem::replace(&mut self.left, next_left);
3837                drop(old_left);
3838            } else {
3839                break;
3840            }
3841        }
3842    }
3843}
3844
3845/// Represent an INTERSECT set operation between two query expressions.
3846///
3847/// Returns only rows that appear in both operands. When `all` is true,
3848/// duplicates are preserved according to their multiplicity.
3849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3850#[cfg_attr(feature = "bindings", derive(TS))]
3851pub struct Intersect {
3852    /// The left-hand query operand.
3853    pub left: Expression,
3854    /// The right-hand query operand.
3855    pub right: Expression,
3856    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3857    pub all: bool,
3858    /// Whether DISTINCT was explicitly specified
3859    #[serde(default)]
3860    pub distinct: bool,
3861    /// Optional WITH clause
3862    pub with: Option<With>,
3863    /// ORDER BY applied to entire INTERSECT result
3864    pub order_by: Option<OrderBy>,
3865    /// LIMIT applied to entire INTERSECT result
3866    pub limit: Option<Box<Expression>>,
3867    /// OFFSET applied to entire INTERSECT result
3868    pub offset: Option<Box<Expression>>,
3869    /// DISTRIBUTE BY clause (Hive/Spark)
3870    #[serde(default, skip_serializing_if = "Option::is_none")]
3871    pub distribute_by: Option<DistributeBy>,
3872    /// SORT BY clause (Hive/Spark)
3873    #[serde(default, skip_serializing_if = "Option::is_none")]
3874    pub sort_by: Option<SortBy>,
3875    /// CLUSTER BY clause (Hive/Spark)
3876    #[serde(default, skip_serializing_if = "Option::is_none")]
3877    pub cluster_by: Option<ClusterBy>,
3878    /// DuckDB BY NAME modifier
3879    #[serde(default)]
3880    pub by_name: bool,
3881    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub side: Option<String>,
3884    /// BigQuery: Set operation kind (INNER)
3885    #[serde(default, skip_serializing_if = "Option::is_none")]
3886    pub kind: Option<String>,
3887    /// BigQuery: CORRESPONDING modifier
3888    #[serde(default)]
3889    pub corresponding: bool,
3890    /// BigQuery: STRICT modifier (before CORRESPONDING)
3891    #[serde(default)]
3892    pub strict: bool,
3893    /// BigQuery: BY (columns) after CORRESPONDING
3894    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3895    pub on_columns: Vec<Expression>,
3896}
3897
3898impl Drop for Intersect {
3899    fn drop(&mut self) {
3900        loop {
3901            if let Expression::Intersect(ref mut inner) = self.left {
3902                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3903                let old_left = std::mem::replace(&mut self.left, next_left);
3904                drop(old_left);
3905            } else {
3906                break;
3907            }
3908        }
3909    }
3910}
3911
3912/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3913///
3914/// Returns rows from the left operand that do not appear in the right operand.
3915/// When `all` is true, duplicates are subtracted according to their multiplicity.
3916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3917#[cfg_attr(feature = "bindings", derive(TS))]
3918pub struct Except {
3919    /// The left-hand query operand.
3920    pub left: Expression,
3921    /// The right-hand query operand (rows to subtract).
3922    pub right: Expression,
3923    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3924    pub all: bool,
3925    /// Whether DISTINCT was explicitly specified
3926    #[serde(default)]
3927    pub distinct: bool,
3928    /// Optional WITH clause
3929    pub with: Option<With>,
3930    /// ORDER BY applied to entire EXCEPT result
3931    pub order_by: Option<OrderBy>,
3932    /// LIMIT applied to entire EXCEPT result
3933    pub limit: Option<Box<Expression>>,
3934    /// OFFSET applied to entire EXCEPT result
3935    pub offset: Option<Box<Expression>>,
3936    /// DISTRIBUTE BY clause (Hive/Spark)
3937    #[serde(default, skip_serializing_if = "Option::is_none")]
3938    pub distribute_by: Option<DistributeBy>,
3939    /// SORT BY clause (Hive/Spark)
3940    #[serde(default, skip_serializing_if = "Option::is_none")]
3941    pub sort_by: Option<SortBy>,
3942    /// CLUSTER BY clause (Hive/Spark)
3943    #[serde(default, skip_serializing_if = "Option::is_none")]
3944    pub cluster_by: Option<ClusterBy>,
3945    /// DuckDB BY NAME modifier
3946    #[serde(default)]
3947    pub by_name: bool,
3948    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub side: Option<String>,
3951    /// BigQuery: Set operation kind (INNER)
3952    #[serde(default, skip_serializing_if = "Option::is_none")]
3953    pub kind: Option<String>,
3954    /// BigQuery: CORRESPONDING modifier
3955    #[serde(default)]
3956    pub corresponding: bool,
3957    /// BigQuery: STRICT modifier (before CORRESPONDING)
3958    #[serde(default)]
3959    pub strict: bool,
3960    /// BigQuery: BY (columns) after CORRESPONDING
3961    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3962    pub on_columns: Vec<Expression>,
3963}
3964
3965impl Drop for Except {
3966    fn drop(&mut self) {
3967        loop {
3968            if let Expression::Except(ref mut inner) = self.left {
3969                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3970                let old_left = std::mem::replace(&mut self.left, next_left);
3971                drop(old_left);
3972            } else {
3973                break;
3974            }
3975        }
3976    }
3977}
3978
3979/// INTO clause for SELECT INTO statements
3980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3981#[cfg_attr(feature = "bindings", derive(TS))]
3982pub struct SelectInto {
3983    /// Target table or variable (used when single target)
3984    pub this: Expression,
3985    /// Whether TEMPORARY keyword was used
3986    #[serde(default)]
3987    pub temporary: bool,
3988    /// Whether UNLOGGED keyword was used (PostgreSQL)
3989    #[serde(default)]
3990    pub unlogged: bool,
3991    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3992    #[serde(default)]
3993    pub bulk_collect: bool,
3994    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3995    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3996    pub expressions: Vec<Expression>,
3997}
3998
3999/// Represent a parenthesized subquery expression.
4000///
4001/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
4002/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4003/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4004/// modifiers are rendered inside or outside the parentheses.
4005///
4006/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4007/// scalar subqueries in select-lists, and derived tables.
4008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4009#[cfg_attr(feature = "bindings", derive(TS))]
4010pub struct Subquery {
4011    /// The inner query expression.
4012    pub this: Expression,
4013    /// Optional alias for the derived table.
4014    pub alias: Option<Identifier>,
4015    /// Optional column aliases: AS t(c1, c2)
4016    pub column_aliases: Vec<Identifier>,
4017    /// Whether AS keyword was explicitly used for the alias.
4018    #[serde(default)]
4019    pub alias_explicit_as: bool,
4020    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4021    #[serde(skip_serializing_if = "Option::is_none", default)]
4022    pub alias_keyword: Option<String>,
4023    /// ORDER BY clause (for parenthesized queries)
4024    pub order_by: Option<OrderBy>,
4025    /// LIMIT clause
4026    pub limit: Option<Limit>,
4027    /// OFFSET clause
4028    pub offset: Option<Offset>,
4029    /// DISTRIBUTE BY clause (Hive/Spark)
4030    #[serde(default, skip_serializing_if = "Option::is_none")]
4031    pub distribute_by: Option<DistributeBy>,
4032    /// SORT BY clause (Hive/Spark)
4033    #[serde(default, skip_serializing_if = "Option::is_none")]
4034    pub sort_by: Option<SortBy>,
4035    /// CLUSTER BY clause (Hive/Spark)
4036    #[serde(default, skip_serializing_if = "Option::is_none")]
4037    pub cluster_by: Option<ClusterBy>,
4038    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4039    #[serde(default)]
4040    pub lateral: bool,
4041    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4042    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4043    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4044    #[serde(default)]
4045    pub modifiers_inside: bool,
4046    /// Trailing comments after the closing paren
4047    #[serde(default)]
4048    pub trailing_comments: Vec<String>,
4049    /// Inferred data type from type annotation
4050    #[serde(default, skip_serializing_if = "Option::is_none")]
4051    pub inferred_type: Option<DataType>,
4052}
4053
4054/// Pipe operator expression: query |> transform
4055///
4056/// Used in DataFusion and BigQuery pipe syntax:
4057///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4059#[cfg_attr(feature = "bindings", derive(TS))]
4060pub struct PipeOperator {
4061    /// The input query/expression (left side of |>)
4062    pub this: Expression,
4063    /// The piped operation (right side of |>)
4064    pub expression: Expression,
4065}
4066
4067/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4069#[cfg_attr(feature = "bindings", derive(TS))]
4070pub struct Values {
4071    /// The rows of values
4072    pub expressions: Vec<Tuple>,
4073    /// Optional alias for the table
4074    pub alias: Option<Identifier>,
4075    /// Optional column aliases: AS t(c1, c2)
4076    pub column_aliases: Vec<Identifier>,
4077}
4078
4079/// PIVOT operation - supports both standard and DuckDB simplified syntax
4080///
4081/// Standard syntax (in FROM clause):
4082///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4083///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4084///
4085/// DuckDB simplified syntax (statement-level):
4086///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4087///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4089#[cfg_attr(feature = "bindings", derive(TS))]
4090pub struct Pivot {
4091    /// Source table/expression
4092    pub this: Expression,
4093    /// For standard PIVOT: the aggregation function(s) (first is primary)
4094    /// For DuckDB simplified: unused (use `using` instead)
4095    #[serde(default)]
4096    pub expressions: Vec<Expression>,
4097    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4098    #[serde(default)]
4099    pub fields: Vec<Expression>,
4100    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4101    #[serde(default)]
4102    pub using: Vec<Expression>,
4103    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4104    #[serde(default)]
4105    pub group: Option<Box<Expression>>,
4106    /// Whether this is an UNPIVOT (vs PIVOT)
4107    #[serde(default)]
4108    pub unpivot: bool,
4109    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4110    #[serde(default)]
4111    pub into: Option<Box<Expression>>,
4112    /// Optional alias
4113    #[serde(default)]
4114    pub alias: Option<Identifier>,
4115    /// Include/exclude nulls (for UNPIVOT)
4116    #[serde(default)]
4117    pub include_nulls: Option<bool>,
4118    /// Default on null value (Snowflake)
4119    #[serde(default)]
4120    pub default_on_null: Option<Box<Expression>>,
4121    /// WITH clause (CTEs)
4122    #[serde(default, skip_serializing_if = "Option::is_none")]
4123    pub with: Option<With>,
4124}
4125
4126/// UNPIVOT operation
4127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4128#[cfg_attr(feature = "bindings", derive(TS))]
4129pub struct Unpivot {
4130    pub this: Expression,
4131    pub value_column: Identifier,
4132    pub name_column: Identifier,
4133    pub columns: Vec<Expression>,
4134    pub alias: Option<Identifier>,
4135    /// Whether the value_column was parenthesized in the original SQL
4136    #[serde(default)]
4137    pub value_column_parenthesized: bool,
4138    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4139    #[serde(default)]
4140    pub include_nulls: Option<bool>,
4141    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4142    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4143    pub extra_value_columns: Vec<Identifier>,
4144}
4145
4146/// PIVOT alias for aliasing pivot expressions
4147/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4149#[cfg_attr(feature = "bindings", derive(TS))]
4150pub struct PivotAlias {
4151    pub this: Expression,
4152    pub alias: Expression,
4153}
4154
4155/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4157#[cfg_attr(feature = "bindings", derive(TS))]
4158pub struct PreWhere {
4159    pub this: Expression,
4160}
4161
4162/// STREAM definition (Snowflake) - for change data capture
4163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4164#[cfg_attr(feature = "bindings", derive(TS))]
4165pub struct Stream {
4166    pub this: Expression,
4167    #[serde(skip_serializing_if = "Option::is_none")]
4168    pub on: Option<Expression>,
4169    #[serde(skip_serializing_if = "Option::is_none")]
4170    pub show_initial_rows: Option<bool>,
4171}
4172
4173/// USING DATA clause for data import statements
4174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4175#[cfg_attr(feature = "bindings", derive(TS))]
4176pub struct UsingData {
4177    pub this: Expression,
4178}
4179
4180/// XML Namespace declaration
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct XmlNamespace {
4184    pub this: Expression,
4185    #[serde(skip_serializing_if = "Option::is_none")]
4186    pub alias: Option<Identifier>,
4187}
4188
4189/// ROW FORMAT clause for Hive/Spark
4190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4191#[cfg_attr(feature = "bindings", derive(TS))]
4192pub struct RowFormat {
4193    pub delimited: bool,
4194    pub fields_terminated_by: Option<String>,
4195    pub collection_items_terminated_by: Option<String>,
4196    pub map_keys_terminated_by: Option<String>,
4197    pub lines_terminated_by: Option<String>,
4198    pub null_defined_as: Option<String>,
4199}
4200
4201/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4203#[cfg_attr(feature = "bindings", derive(TS))]
4204pub struct DirectoryInsert {
4205    pub local: bool,
4206    pub path: String,
4207    pub row_format: Option<RowFormat>,
4208    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4209    #[serde(default)]
4210    pub stored_as: Option<String>,
4211}
4212
4213/// INSERT statement
4214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4215#[cfg_attr(feature = "bindings", derive(TS))]
4216pub struct Insert {
4217    pub table: TableRef,
4218    pub columns: Vec<Identifier>,
4219    pub values: Vec<Vec<Expression>>,
4220    pub query: Option<Expression>,
4221    /// INSERT OVERWRITE for Hive/Spark
4222    pub overwrite: bool,
4223    /// PARTITION clause for Hive/Spark
4224    pub partition: Vec<(Identifier, Option<Expression>)>,
4225    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4226    #[serde(default)]
4227    pub directory: Option<DirectoryInsert>,
4228    /// RETURNING clause (PostgreSQL, SQLite)
4229    #[serde(default)]
4230    pub returning: Vec<Expression>,
4231    /// OUTPUT clause (TSQL)
4232    #[serde(default)]
4233    pub output: Option<OutputClause>,
4234    /// ON CONFLICT clause (PostgreSQL, SQLite)
4235    #[serde(default)]
4236    pub on_conflict: Option<Box<Expression>>,
4237    /// Leading comments before the statement
4238    #[serde(default)]
4239    pub leading_comments: Vec<String>,
4240    /// IF EXISTS clause (Hive)
4241    #[serde(default)]
4242    pub if_exists: bool,
4243    /// WITH clause (CTEs)
4244    #[serde(default)]
4245    pub with: Option<With>,
4246    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4247    #[serde(default)]
4248    pub ignore: bool,
4249    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4250    #[serde(default)]
4251    pub source_alias: Option<Identifier>,
4252    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4253    #[serde(default)]
4254    pub alias: Option<Identifier>,
4255    /// Whether the alias uses explicit AS keyword
4256    #[serde(default)]
4257    pub alias_explicit_as: bool,
4258    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4259    #[serde(default)]
4260    pub default_values: bool,
4261    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4262    #[serde(default)]
4263    pub by_name: bool,
4264    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4265    #[serde(default, skip_serializing_if = "Option::is_none")]
4266    pub conflict_action: Option<String>,
4267    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4268    #[serde(default)]
4269    pub is_replace: bool,
4270    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4271    #[serde(default, skip_serializing_if = "Option::is_none")]
4272    pub hint: Option<Hint>,
4273    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4274    #[serde(default)]
4275    pub replace_where: Option<Box<Expression>>,
4276    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4277    #[serde(default)]
4278    pub source: Option<Box<Expression>>,
4279    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4280    #[serde(default, skip_serializing_if = "Option::is_none")]
4281    pub function_target: Option<Box<Expression>>,
4282    /// ClickHouse: PARTITION BY expr
4283    #[serde(default, skip_serializing_if = "Option::is_none")]
4284    pub partition_by: Option<Box<Expression>>,
4285    /// ClickHouse: SETTINGS key = val, ...
4286    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4287    pub settings: Vec<Expression>,
4288}
4289
4290/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4292#[cfg_attr(feature = "bindings", derive(TS))]
4293pub struct OutputClause {
4294    /// Columns/expressions to output
4295    pub columns: Vec<Expression>,
4296    /// Optional INTO target table or table variable
4297    #[serde(default)]
4298    pub into_table: Option<Expression>,
4299}
4300
4301/// UPDATE statement
4302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4303#[cfg_attr(feature = "bindings", derive(TS))]
4304pub struct Update {
4305    pub table: TableRef,
4306    #[serde(default)]
4307    pub hint: Option<Hint>,
4308    /// Additional tables for multi-table UPDATE (MySQL syntax)
4309    #[serde(default)]
4310    pub extra_tables: Vec<TableRef>,
4311    /// JOINs attached to the table list (MySQL multi-table syntax)
4312    #[serde(default)]
4313    pub table_joins: Vec<Join>,
4314    pub set: Vec<(Identifier, Expression)>,
4315    pub from_clause: Option<From>,
4316    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4317    #[serde(default)]
4318    pub from_joins: Vec<Join>,
4319    pub where_clause: Option<Where>,
4320    /// RETURNING clause (PostgreSQL, SQLite)
4321    #[serde(default)]
4322    pub returning: Vec<Expression>,
4323    /// OUTPUT clause (TSQL)
4324    #[serde(default)]
4325    pub output: Option<OutputClause>,
4326    /// WITH clause (CTEs)
4327    #[serde(default)]
4328    pub with: Option<With>,
4329    /// Leading comments before the statement
4330    #[serde(default)]
4331    pub leading_comments: Vec<String>,
4332    /// LIMIT clause (MySQL)
4333    #[serde(default)]
4334    pub limit: Option<Expression>,
4335    /// ORDER BY clause (MySQL)
4336    #[serde(default)]
4337    pub order_by: Option<OrderBy>,
4338    /// Whether FROM clause appears before SET (Snowflake syntax)
4339    #[serde(default)]
4340    pub from_before_set: bool,
4341}
4342
4343/// DELETE statement
4344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4345#[cfg_attr(feature = "bindings", derive(TS))]
4346pub struct Delete {
4347    pub table: TableRef,
4348    #[serde(default)]
4349    pub hint: Option<Hint>,
4350    /// ClickHouse: ON CLUSTER clause for distributed DDL
4351    #[serde(default, skip_serializing_if = "Option::is_none")]
4352    pub on_cluster: Option<OnCluster>,
4353    /// Optional alias for the table
4354    pub alias: Option<Identifier>,
4355    /// Whether the alias was declared with explicit AS keyword
4356    #[serde(default)]
4357    pub alias_explicit_as: bool,
4358    /// PostgreSQL/DuckDB USING clause - additional tables to join
4359    pub using: Vec<TableRef>,
4360    pub where_clause: Option<Where>,
4361    /// OUTPUT clause (TSQL)
4362    #[serde(default)]
4363    pub output: Option<OutputClause>,
4364    /// Leading comments before the statement
4365    #[serde(default)]
4366    pub leading_comments: Vec<String>,
4367    /// WITH clause (CTEs)
4368    #[serde(default)]
4369    pub with: Option<With>,
4370    /// LIMIT clause (MySQL)
4371    #[serde(default)]
4372    pub limit: Option<Expression>,
4373    /// ORDER BY clause (MySQL)
4374    #[serde(default)]
4375    pub order_by: Option<OrderBy>,
4376    /// RETURNING clause (PostgreSQL)
4377    #[serde(default)]
4378    pub returning: Vec<Expression>,
4379    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4380    /// These are the target tables to delete from
4381    #[serde(default)]
4382    pub tables: Vec<TableRef>,
4383    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4384    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4385    #[serde(default)]
4386    pub tables_from_using: bool,
4387    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4388    #[serde(default)]
4389    pub joins: Vec<Join>,
4390    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4391    #[serde(default)]
4392    pub force_index: Option<String>,
4393    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4394    #[serde(default)]
4395    pub no_from: bool,
4396}
4397
4398/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4400#[cfg_attr(feature = "bindings", derive(TS))]
4401pub struct CopyStmt {
4402    /// Target table or query
4403    pub this: Expression,
4404    /// True for FROM (loading into table), false for TO (exporting)
4405    pub kind: bool,
4406    /// Source/destination file(s) or stage
4407    pub files: Vec<Expression>,
4408    /// Copy parameters
4409    #[serde(default)]
4410    pub params: Vec<CopyParameter>,
4411    /// Credentials for external access
4412    #[serde(default)]
4413    pub credentials: Option<Box<Credentials>>,
4414    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4415    #[serde(default)]
4416    pub is_into: bool,
4417    /// Whether parameters are wrapped in WITH (...) syntax
4418    #[serde(default)]
4419    pub with_wrapped: bool,
4420}
4421
4422/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4424#[cfg_attr(feature = "bindings", derive(TS))]
4425pub struct CopyParameter {
4426    pub name: String,
4427    pub value: Option<Expression>,
4428    pub values: Vec<Expression>,
4429    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4430    #[serde(default)]
4431    pub eq: bool,
4432}
4433
4434/// Credentials for external access (S3, Azure, etc.)
4435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4436#[cfg_attr(feature = "bindings", derive(TS))]
4437pub struct Credentials {
4438    pub credentials: Vec<(String, String)>,
4439    pub encryption: Option<String>,
4440    pub storage: Option<String>,
4441}
4442
4443/// PUT statement (Snowflake)
4444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4445#[cfg_attr(feature = "bindings", derive(TS))]
4446pub struct PutStmt {
4447    /// Source file path
4448    pub source: String,
4449    /// Whether source was quoted in the original SQL
4450    #[serde(default)]
4451    pub source_quoted: bool,
4452    /// Target stage
4453    pub target: Expression,
4454    /// PUT parameters
4455    #[serde(default)]
4456    pub params: Vec<CopyParameter>,
4457}
4458
4459/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4461#[cfg_attr(feature = "bindings", derive(TS))]
4462pub struct StageReference {
4463    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4464    pub name: String,
4465    /// Optional path within the stage (e.g., "/path/to/file.csv")
4466    #[serde(default)]
4467    pub path: Option<String>,
4468    /// Optional FILE_FORMAT parameter
4469    #[serde(default)]
4470    pub file_format: Option<Expression>,
4471    /// Optional PATTERN parameter
4472    #[serde(default)]
4473    pub pattern: Option<String>,
4474    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4475    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4476    pub quoted: bool,
4477}
4478
4479/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4481#[cfg_attr(feature = "bindings", derive(TS))]
4482pub struct HistoricalData {
4483    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4484    pub this: Box<Expression>,
4485    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4486    pub kind: String,
4487    /// The expression value (e.g., the statement ID or timestamp)
4488    pub expression: Box<Expression>,
4489}
4490
4491/// Represent an aliased expression (`expr AS name`).
4492///
4493/// Used for column aliases in select-lists, table aliases on subqueries,
4494/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4496#[cfg_attr(feature = "bindings", derive(TS))]
4497pub struct Alias {
4498    /// The expression being aliased.
4499    pub this: Expression,
4500    /// The alias name (required for simple aliases, optional when only column aliases provided)
4501    pub alias: Identifier,
4502    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4503    #[serde(default)]
4504    pub column_aliases: Vec<Identifier>,
4505    /// Whether AS keyword was explicitly used for the alias.
4506    #[serde(default)]
4507    pub alias_explicit_as: bool,
4508    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4509    #[serde(skip_serializing_if = "Option::is_none", default)]
4510    pub alias_keyword: Option<String>,
4511    /// Comments that appeared between the expression and AS keyword
4512    #[serde(default)]
4513    pub pre_alias_comments: Vec<String>,
4514    /// Trailing comments that appeared after the alias
4515    #[serde(default)]
4516    pub trailing_comments: Vec<String>,
4517    /// Inferred data type from type annotation
4518    #[serde(default, skip_serializing_if = "Option::is_none")]
4519    pub inferred_type: Option<DataType>,
4520}
4521
4522impl Alias {
4523    /// Create a simple alias
4524    pub fn new(this: Expression, alias: Identifier) -> Self {
4525        Self {
4526            this,
4527            alias,
4528            column_aliases: Vec::new(),
4529            alias_explicit_as: false,
4530            alias_keyword: None,
4531            pre_alias_comments: Vec::new(),
4532            trailing_comments: Vec::new(),
4533            inferred_type: None,
4534        }
4535    }
4536
4537    /// Create an alias with column aliases only (no table alias name)
4538    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4539        Self {
4540            this,
4541            alias: Identifier::empty(),
4542            column_aliases,
4543            alias_explicit_as: false,
4544            alias_keyword: None,
4545            pre_alias_comments: Vec::new(),
4546            trailing_comments: Vec::new(),
4547            inferred_type: None,
4548        }
4549    }
4550}
4551
4552/// Represent a type cast expression.
4553///
4554/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4555/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4556/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4557/// CONVERSION ERROR (Oracle) clauses.
4558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4559#[cfg_attr(feature = "bindings", derive(TS))]
4560pub struct Cast {
4561    /// The expression being cast.
4562    pub this: Expression,
4563    /// The target data type.
4564    pub to: DataType,
4565    #[serde(default)]
4566    pub trailing_comments: Vec<String>,
4567    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4568    #[serde(default)]
4569    pub double_colon_syntax: bool,
4570    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4571    #[serde(skip_serializing_if = "Option::is_none", default)]
4572    pub format: Option<Box<Expression>>,
4573    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4574    #[serde(skip_serializing_if = "Option::is_none", default)]
4575    pub default: Option<Box<Expression>>,
4576    /// Inferred data type from type annotation
4577    #[serde(default, skip_serializing_if = "Option::is_none")]
4578    pub inferred_type: Option<DataType>,
4579}
4580
4581///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4583#[cfg_attr(feature = "bindings", derive(TS))]
4584pub struct CollationExpr {
4585    pub this: Expression,
4586    pub collation: String,
4587    /// True if the collation was single-quoted in the original SQL (string literal)
4588    #[serde(default)]
4589    pub quoted: bool,
4590    /// True if the collation was double-quoted in the original SQL (identifier)
4591    #[serde(default)]
4592    pub double_quoted: bool,
4593}
4594
4595/// Represent a CASE expression (both simple and searched forms).
4596///
4597/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4598/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4599/// Each entry in `whens` is a `(condition, result)` pair.
4600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4601#[cfg_attr(feature = "bindings", derive(TS))]
4602pub struct Case {
4603    /// The operand for simple CASE, or `None` for searched CASE.
4604    pub operand: Option<Expression>,
4605    /// Pairs of (WHEN condition, THEN result).
4606    pub whens: Vec<(Expression, Expression)>,
4607    /// Optional ELSE result.
4608    pub else_: Option<Expression>,
4609    /// Comments from the CASE keyword (emitted after END)
4610    #[serde(default)]
4611    #[serde(skip_serializing_if = "Vec::is_empty")]
4612    pub comments: Vec<String>,
4613    /// Inferred data type from type annotation
4614    #[serde(default, skip_serializing_if = "Option::is_none")]
4615    pub inferred_type: Option<DataType>,
4616}
4617
4618/// Represent a binary operation (two operands separated by an operator).
4619///
4620/// This is the shared payload struct for all binary operator variants in the
4621/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4622/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4623/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4624/// preservation of inline comments around operators.
4625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4626#[cfg_attr(feature = "bindings", derive(TS))]
4627pub struct BinaryOp {
4628    pub left: Expression,
4629    pub right: Expression,
4630    /// Comments after the left operand (before the operator)
4631    #[serde(default)]
4632    pub left_comments: Vec<String>,
4633    /// Comments after the operator (before the right operand)
4634    #[serde(default)]
4635    pub operator_comments: Vec<String>,
4636    /// Comments after the right operand
4637    #[serde(default)]
4638    pub trailing_comments: Vec<String>,
4639    /// Inferred data type from type annotation
4640    #[serde(default, skip_serializing_if = "Option::is_none")]
4641    pub inferred_type: Option<DataType>,
4642}
4643
4644impl BinaryOp {
4645    pub fn new(left: Expression, right: Expression) -> Self {
4646        Self {
4647            left,
4648            right,
4649            left_comments: Vec::new(),
4650            operator_comments: Vec::new(),
4651            trailing_comments: Vec::new(),
4652            inferred_type: None,
4653        }
4654    }
4655}
4656
4657/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4659#[cfg_attr(feature = "bindings", derive(TS))]
4660pub struct LikeOp {
4661    pub left: Expression,
4662    pub right: Expression,
4663    /// ESCAPE character/expression
4664    #[serde(default)]
4665    pub escape: Option<Expression>,
4666    /// Quantifier: ANY, ALL, or SOME
4667    #[serde(default)]
4668    pub quantifier: Option<String>,
4669    /// Inferred data type from type annotation
4670    #[serde(default, skip_serializing_if = "Option::is_none")]
4671    pub inferred_type: Option<DataType>,
4672}
4673
4674impl LikeOp {
4675    pub fn new(left: Expression, right: Expression) -> Self {
4676        Self {
4677            left,
4678            right,
4679            escape: None,
4680            quantifier: None,
4681            inferred_type: None,
4682        }
4683    }
4684
4685    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4686        Self {
4687            left,
4688            right,
4689            escape: Some(escape),
4690            quantifier: None,
4691            inferred_type: None,
4692        }
4693    }
4694}
4695
4696/// Represent a unary operation (single operand with a prefix operator).
4697///
4698/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct UnaryOp {
4702    /// The operand expression.
4703    pub this: Expression,
4704    /// Inferred data type from type annotation
4705    #[serde(default, skip_serializing_if = "Option::is_none")]
4706    pub inferred_type: Option<DataType>,
4707}
4708
4709impl UnaryOp {
4710    pub fn new(this: Expression) -> Self {
4711        Self {
4712            this,
4713            inferred_type: None,
4714        }
4715    }
4716}
4717
4718/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4719///
4720/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4721/// but not both. When `not` is true, the predicate is `NOT IN`.
4722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4723#[cfg_attr(feature = "bindings", derive(TS))]
4724pub struct In {
4725    /// The expression being tested.
4726    pub this: Expression,
4727    /// The value list (mutually exclusive with `query`).
4728    pub expressions: Vec<Expression>,
4729    /// A subquery (mutually exclusive with `expressions`).
4730    pub query: Option<Expression>,
4731    /// Whether this is NOT IN.
4732    pub not: bool,
4733    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4734    pub global: bool,
4735    /// BigQuery: IN UNNEST(expr)
4736    #[serde(default, skip_serializing_if = "Option::is_none")]
4737    pub unnest: Option<Box<Expression>>,
4738    /// Whether the right side is a bare field reference (no parentheses).
4739    /// Matches Python sqlglot's `field` attribute on `In` expression.
4740    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4741    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4742    pub is_field: bool,
4743}
4744
4745/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4747#[cfg_attr(feature = "bindings", derive(TS))]
4748pub struct Between {
4749    /// The expression being tested.
4750    pub this: Expression,
4751    /// The lower bound.
4752    pub low: Expression,
4753    /// The upper bound.
4754    pub high: Expression,
4755    /// Whether this is NOT BETWEEN.
4756    pub not: bool,
4757    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4758    #[serde(default)]
4759    pub symmetric: Option<bool>,
4760}
4761
4762/// IS NULL predicate
4763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4764#[cfg_attr(feature = "bindings", derive(TS))]
4765pub struct IsNull {
4766    pub this: Expression,
4767    pub not: bool,
4768    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4769    #[serde(default)]
4770    pub postfix_form: bool,
4771}
4772
4773/// IS TRUE / IS FALSE predicate
4774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4775#[cfg_attr(feature = "bindings", derive(TS))]
4776pub struct IsTrueFalse {
4777    pub this: Expression,
4778    pub not: bool,
4779}
4780
4781/// IS JSON predicate (SQL standard)
4782/// Checks if a value is valid JSON
4783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4784#[cfg_attr(feature = "bindings", derive(TS))]
4785pub struct IsJson {
4786    pub this: Expression,
4787    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4788    pub json_type: Option<String>,
4789    /// Key uniqueness constraint
4790    pub unique_keys: Option<JsonUniqueKeys>,
4791    /// Whether IS NOT JSON
4792    pub negated: bool,
4793}
4794
4795/// JSON unique keys constraint variants
4796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4797#[cfg_attr(feature = "bindings", derive(TS))]
4798pub enum JsonUniqueKeys {
4799    /// WITH UNIQUE KEYS
4800    With,
4801    /// WITHOUT UNIQUE KEYS
4802    Without,
4803    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4804    Shorthand,
4805}
4806
4807/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4809#[cfg_attr(feature = "bindings", derive(TS))]
4810pub struct Exists {
4811    /// The subquery expression.
4812    pub this: Expression,
4813    /// Whether this is NOT EXISTS.
4814    pub not: bool,
4815}
4816
4817/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4818///
4819/// This is the generic function node. Well-known aggregates, window functions,
4820/// and built-in functions each have their own dedicated `Expression` variants
4821/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4822/// not recognize as built-ins are represented with this struct.
4823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4824#[cfg_attr(feature = "bindings", derive(TS))]
4825pub struct Function {
4826    /// The function name, as originally written (may be schema-qualified).
4827    pub name: String,
4828    /// Positional arguments to the function.
4829    pub args: Vec<Expression>,
4830    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4831    pub distinct: bool,
4832    #[serde(default)]
4833    pub trailing_comments: Vec<String>,
4834    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4835    #[serde(default)]
4836    pub use_bracket_syntax: bool,
4837    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4838    #[serde(default)]
4839    pub no_parens: bool,
4840    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4841    #[serde(default)]
4842    pub quoted: bool,
4843    /// Source position span
4844    #[serde(default, skip_serializing_if = "Option::is_none")]
4845    pub span: Option<Span>,
4846    /// Inferred data type from type annotation
4847    #[serde(default, skip_serializing_if = "Option::is_none")]
4848    pub inferred_type: Option<DataType>,
4849}
4850
4851impl Default for Function {
4852    fn default() -> Self {
4853        Self {
4854            name: String::new(),
4855            args: Vec::new(),
4856            distinct: false,
4857            trailing_comments: Vec::new(),
4858            use_bracket_syntax: false,
4859            no_parens: false,
4860            quoted: false,
4861            span: None,
4862            inferred_type: None,
4863        }
4864    }
4865}
4866
4867impl Function {
4868    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4869        Self {
4870            name: name.into(),
4871            args,
4872            distinct: false,
4873            trailing_comments: Vec::new(),
4874            use_bracket_syntax: false,
4875            no_parens: false,
4876            quoted: false,
4877            span: None,
4878            inferred_type: None,
4879        }
4880    }
4881}
4882
4883/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4884///
4885/// This struct is used for aggregate function calls that are not covered by
4886/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4887/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4888/// IGNORE NULLS / RESPECT NULLS modifiers.
4889#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4890#[cfg_attr(feature = "bindings", derive(TS))]
4891pub struct AggregateFunction {
4892    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4893    pub name: String,
4894    /// Positional arguments.
4895    pub args: Vec<Expression>,
4896    /// Whether DISTINCT was specified.
4897    pub distinct: bool,
4898    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4899    pub filter: Option<Expression>,
4900    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4901    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4902    pub order_by: Vec<Ordered>,
4903    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4904    #[serde(default, skip_serializing_if = "Option::is_none")]
4905    pub limit: Option<Box<Expression>>,
4906    /// IGNORE NULLS / RESPECT NULLS
4907    #[serde(default, skip_serializing_if = "Option::is_none")]
4908    pub ignore_nulls: Option<bool>,
4909    /// Inferred data type from type annotation
4910    #[serde(default, skip_serializing_if = "Option::is_none")]
4911    pub inferred_type: Option<DataType>,
4912}
4913
4914/// Represent a window function call with its OVER clause.
4915///
4916/// The inner `this` expression is typically a window-specific expression
4917/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4918/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4919/// frame specification.
4920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4921#[cfg_attr(feature = "bindings", derive(TS))]
4922pub struct WindowFunction {
4923    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4924    pub this: Expression,
4925    /// The OVER clause defining the window partitioning, ordering, and frame.
4926    pub over: Over,
4927    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4928    #[serde(default, skip_serializing_if = "Option::is_none")]
4929    pub keep: Option<Keep>,
4930    /// Inferred data type from type annotation
4931    #[serde(default, skip_serializing_if = "Option::is_none")]
4932    pub inferred_type: Option<DataType>,
4933}
4934
4935/// Oracle KEEP clause for aggregate functions
4936/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4938#[cfg_attr(feature = "bindings", derive(TS))]
4939pub struct Keep {
4940    /// true = FIRST, false = LAST
4941    pub first: bool,
4942    /// ORDER BY clause inside KEEP
4943    pub order_by: Vec<Ordered>,
4944}
4945
4946/// WITHIN GROUP clause (for ordered-set aggregate functions)
4947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4948#[cfg_attr(feature = "bindings", derive(TS))]
4949pub struct WithinGroup {
4950    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4951    pub this: Expression,
4952    /// The ORDER BY clause within the group
4953    pub order_by: Vec<Ordered>,
4954}
4955
4956/// Represent the FROM clause of a SELECT statement.
4957///
4958/// Contains one or more table sources (tables, subqueries, table-valued
4959/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4961#[cfg_attr(feature = "bindings", derive(TS))]
4962pub struct From {
4963    /// The table source expressions.
4964    pub expressions: Vec<Expression>,
4965}
4966
4967/// Represent a JOIN clause between two table sources.
4968///
4969/// The join condition can be specified via `on` (ON predicate) or `using`
4970/// (USING column list), but not both. The `kind` field determines the join
4971/// type (INNER, LEFT, CROSS, etc.).
4972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4973#[cfg_attr(feature = "bindings", derive(TS))]
4974pub struct Join {
4975    /// The right-hand table expression being joined.
4976    pub this: Expression,
4977    /// The ON condition (mutually exclusive with `using`).
4978    pub on: Option<Expression>,
4979    /// The USING column list (mutually exclusive with `on`).
4980    pub using: Vec<Identifier>,
4981    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4982    pub kind: JoinKind,
4983    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4984    pub use_inner_keyword: bool,
4985    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4986    pub use_outer_keyword: bool,
4987    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4988    pub deferred_condition: bool,
4989    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4990    #[serde(default, skip_serializing_if = "Option::is_none")]
4991    pub join_hint: Option<String>,
4992    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4993    #[serde(default, skip_serializing_if = "Option::is_none")]
4994    pub match_condition: Option<Expression>,
4995    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4996    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4997    pub pivots: Vec<Expression>,
4998    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4999    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5000    pub comments: Vec<String>,
5001    /// Nesting group identifier for nested join pretty-printing.
5002    /// Joins in the same group were parsed together; group boundaries come from
5003    /// deferred condition resolution phases.
5004    #[serde(default)]
5005    pub nesting_group: usize,
5006    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
5007    #[serde(default)]
5008    pub directed: bool,
5009}
5010
5011/// Enumerate all supported SQL join types.
5012///
5013/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
5014/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
5015/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
5016/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
5017#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5018#[cfg_attr(feature = "bindings", derive(TS))]
5019pub enum JoinKind {
5020    Inner,
5021    Left,
5022    Right,
5023    Full,
5024    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5025    Cross,
5026    Natural,
5027    NaturalLeft,
5028    NaturalRight,
5029    NaturalFull,
5030    Semi,
5031    Anti,
5032    // Directional SEMI/ANTI joins
5033    LeftSemi,
5034    LeftAnti,
5035    RightSemi,
5036    RightAnti,
5037    // SQL Server specific
5038    CrossApply,
5039    OuterApply,
5040    // Time-series specific
5041    AsOf,
5042    AsOfLeft,
5043    AsOfRight,
5044    // Lateral join
5045    Lateral,
5046    LeftLateral,
5047    // MySQL specific
5048    Straight,
5049    // Implicit join (comma-separated tables: FROM a, b)
5050    Implicit,
5051    // ClickHouse ARRAY JOIN
5052    Array,
5053    LeftArray,
5054    // ClickHouse PASTE JOIN (positional join)
5055    Paste,
5056    // DuckDB POSITIONAL JOIN
5057    Positional,
5058}
5059
5060impl Default for JoinKind {
5061    fn default() -> Self {
5062        JoinKind::Inner
5063    }
5064}
5065
5066/// Parenthesized table expression with joins
5067/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5069#[cfg_attr(feature = "bindings", derive(TS))]
5070pub struct JoinedTable {
5071    /// The left-hand side table expression
5072    pub left: Expression,
5073    /// The joins applied to the left table
5074    pub joins: Vec<Join>,
5075    /// LATERAL VIEW clauses (Hive/Spark)
5076    pub lateral_views: Vec<LateralView>,
5077    /// Optional alias for the joined table expression
5078    pub alias: Option<Identifier>,
5079}
5080
5081/// Represent a WHERE clause containing a boolean filter predicate.
5082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5083#[cfg_attr(feature = "bindings", derive(TS))]
5084pub struct Where {
5085    /// The filter predicate expression.
5086    pub this: Expression,
5087}
5088
5089/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5090///
5091/// The `expressions` list may contain plain columns, ordinal positions,
5092/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5094#[cfg_attr(feature = "bindings", derive(TS))]
5095pub struct GroupBy {
5096    /// The grouping expressions.
5097    pub expressions: Vec<Expression>,
5098    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5099    #[serde(default)]
5100    pub all: Option<bool>,
5101    /// ClickHouse: WITH TOTALS modifier
5102    #[serde(default)]
5103    pub totals: bool,
5104    /// Leading comments that appeared before the GROUP BY keyword
5105    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5106    pub comments: Vec<String>,
5107}
5108
5109/// Represent a HAVING clause containing a predicate over aggregate results.
5110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5111#[cfg_attr(feature = "bindings", derive(TS))]
5112pub struct Having {
5113    /// The filter predicate, typically involving aggregate functions.
5114    pub this: Expression,
5115    /// Leading comments that appeared before the HAVING keyword
5116    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5117    pub comments: Vec<String>,
5118}
5119
5120/// Represent an ORDER BY clause containing one or more sort specifications.
5121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5122#[cfg_attr(feature = "bindings", derive(TS))]
5123pub struct OrderBy {
5124    /// The sort specifications, each with direction and null ordering.
5125    pub expressions: Vec<Ordered>,
5126    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5127    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5128    pub siblings: bool,
5129    /// Leading comments that appeared before the ORDER BY keyword
5130    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5131    pub comments: Vec<String>,
5132}
5133
5134/// Represent an expression with sort direction and null ordering.
5135///
5136/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5137/// When `desc` is false the sort is ascending. The `nulls_first` field
5138/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5139/// (database default).
5140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5141#[cfg_attr(feature = "bindings", derive(TS))]
5142pub struct Ordered {
5143    /// The expression to sort by.
5144    pub this: Expression,
5145    /// Whether the sort direction is descending (true) or ascending (false).
5146    pub desc: bool,
5147    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5148    pub nulls_first: Option<bool>,
5149    /// Whether ASC was explicitly written (not just implied)
5150    #[serde(default)]
5151    pub explicit_asc: bool,
5152    /// ClickHouse WITH FILL clause
5153    #[serde(default, skip_serializing_if = "Option::is_none")]
5154    pub with_fill: Option<Box<WithFill>>,
5155}
5156
5157impl Ordered {
5158    pub fn asc(expr: Expression) -> Self {
5159        Self {
5160            this: expr,
5161            desc: false,
5162            nulls_first: None,
5163            explicit_asc: false,
5164            with_fill: None,
5165        }
5166    }
5167
5168    pub fn desc(expr: Expression) -> Self {
5169        Self {
5170            this: expr,
5171            desc: true,
5172            nulls_first: None,
5173            explicit_asc: false,
5174            with_fill: None,
5175        }
5176    }
5177}
5178
5179/// DISTRIBUTE BY clause (Hive/Spark)
5180/// Controls how rows are distributed across reducers
5181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5182#[cfg_attr(feature = "bindings", derive(TS))]
5183#[cfg_attr(feature = "bindings", ts(export))]
5184pub struct DistributeBy {
5185    pub expressions: Vec<Expression>,
5186}
5187
5188/// CLUSTER BY clause (Hive/Spark)
5189/// Combines DISTRIBUTE BY and SORT BY on the same columns
5190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5191#[cfg_attr(feature = "bindings", derive(TS))]
5192#[cfg_attr(feature = "bindings", ts(export))]
5193pub struct ClusterBy {
5194    pub expressions: Vec<Ordered>,
5195}
5196
5197/// SORT BY clause (Hive/Spark)
5198/// Sorts data within each reducer (local sort, not global)
5199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5200#[cfg_attr(feature = "bindings", derive(TS))]
5201#[cfg_attr(feature = "bindings", ts(export))]
5202pub struct SortBy {
5203    pub expressions: Vec<Ordered>,
5204}
5205
5206/// LATERAL VIEW clause (Hive/Spark)
5207/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5209#[cfg_attr(feature = "bindings", derive(TS))]
5210#[cfg_attr(feature = "bindings", ts(export))]
5211pub struct LateralView {
5212    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5213    pub this: Expression,
5214    /// Table alias for the generated table
5215    pub table_alias: Option<Identifier>,
5216    /// Column aliases for the generated columns
5217    pub column_aliases: Vec<Identifier>,
5218    /// OUTER keyword - preserve nulls when input is empty/null
5219    pub outer: bool,
5220}
5221
5222/// Query hint
5223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5224#[cfg_attr(feature = "bindings", derive(TS))]
5225#[cfg_attr(feature = "bindings", ts(export))]
5226pub struct Hint {
5227    pub expressions: Vec<HintExpression>,
5228}
5229
5230/// Individual hint expression
5231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5232#[cfg_attr(feature = "bindings", derive(TS))]
5233#[cfg_attr(feature = "bindings", ts(export))]
5234pub enum HintExpression {
5235    /// Function-style hint: USE_HASH(table)
5236    Function { name: String, args: Vec<Expression> },
5237    /// Simple identifier hint: PARALLEL
5238    Identifier(String),
5239    /// Raw hint text (unparsed)
5240    Raw(String),
5241}
5242
5243/// Pseudocolumn type
5244#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5245#[cfg_attr(feature = "bindings", derive(TS))]
5246#[cfg_attr(feature = "bindings", ts(export))]
5247pub enum PseudocolumnType {
5248    Rownum,      // Oracle ROWNUM
5249    Rowid,       // Oracle ROWID
5250    Level,       // Oracle LEVEL (for CONNECT BY)
5251    Sysdate,     // Oracle SYSDATE
5252    ObjectId,    // Oracle OBJECT_ID
5253    ObjectValue, // Oracle OBJECT_VALUE
5254}
5255
5256impl PseudocolumnType {
5257    pub fn as_str(&self) -> &'static str {
5258        match self {
5259            PseudocolumnType::Rownum => "ROWNUM",
5260            PseudocolumnType::Rowid => "ROWID",
5261            PseudocolumnType::Level => "LEVEL",
5262            PseudocolumnType::Sysdate => "SYSDATE",
5263            PseudocolumnType::ObjectId => "OBJECT_ID",
5264            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5265        }
5266    }
5267
5268    pub fn from_str(s: &str) -> Option<Self> {
5269        match s.to_uppercase().as_str() {
5270            "ROWNUM" => Some(PseudocolumnType::Rownum),
5271            "ROWID" => Some(PseudocolumnType::Rowid),
5272            "LEVEL" => Some(PseudocolumnType::Level),
5273            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5274            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5275            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5276            _ => None,
5277        }
5278    }
5279}
5280
5281/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5282/// These are special identifiers that should not be quoted
5283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5284#[cfg_attr(feature = "bindings", derive(TS))]
5285#[cfg_attr(feature = "bindings", ts(export))]
5286pub struct Pseudocolumn {
5287    pub kind: PseudocolumnType,
5288}
5289
5290impl Pseudocolumn {
5291    pub fn rownum() -> Self {
5292        Self {
5293            kind: PseudocolumnType::Rownum,
5294        }
5295    }
5296
5297    pub fn rowid() -> Self {
5298        Self {
5299            kind: PseudocolumnType::Rowid,
5300        }
5301    }
5302
5303    pub fn level() -> Self {
5304        Self {
5305            kind: PseudocolumnType::Level,
5306        }
5307    }
5308}
5309
5310/// Oracle CONNECT BY clause for hierarchical queries
5311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5312#[cfg_attr(feature = "bindings", derive(TS))]
5313#[cfg_attr(feature = "bindings", ts(export))]
5314pub struct Connect {
5315    /// START WITH condition (optional, can come before or after CONNECT BY)
5316    pub start: Option<Expression>,
5317    /// CONNECT BY condition (required, contains PRIOR references)
5318    pub connect: Expression,
5319    /// NOCYCLE keyword to prevent infinite loops
5320    pub nocycle: bool,
5321}
5322
5323/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5325#[cfg_attr(feature = "bindings", derive(TS))]
5326#[cfg_attr(feature = "bindings", ts(export))]
5327pub struct Prior {
5328    pub this: Expression,
5329}
5330
5331/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5333#[cfg_attr(feature = "bindings", derive(TS))]
5334#[cfg_attr(feature = "bindings", ts(export))]
5335pub struct ConnectByRoot {
5336    pub this: Expression,
5337}
5338
5339/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5341#[cfg_attr(feature = "bindings", derive(TS))]
5342#[cfg_attr(feature = "bindings", ts(export))]
5343pub struct MatchRecognize {
5344    /// Source table/expression
5345    pub this: Option<Box<Expression>>,
5346    /// PARTITION BY expressions
5347    pub partition_by: Option<Vec<Expression>>,
5348    /// ORDER BY expressions
5349    pub order_by: Option<Vec<Ordered>>,
5350    /// MEASURES definitions
5351    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5352    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5353    pub rows: Option<MatchRecognizeRows>,
5354    /// AFTER MATCH SKIP behavior
5355    pub after: Option<MatchRecognizeAfter>,
5356    /// PATTERN definition (stored as raw string for complex regex patterns)
5357    pub pattern: Option<String>,
5358    /// DEFINE clauses (pattern variable definitions)
5359    pub define: Option<Vec<(Identifier, Expression)>>,
5360    /// Optional alias for the result
5361    pub alias: Option<Identifier>,
5362    /// Whether AS keyword was explicitly present before alias
5363    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5364    pub alias_explicit_as: bool,
5365}
5366
5367/// MEASURES expression with optional RUNNING/FINAL semantics
5368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5369#[cfg_attr(feature = "bindings", derive(TS))]
5370#[cfg_attr(feature = "bindings", ts(export))]
5371pub struct MatchRecognizeMeasure {
5372    /// The measure expression
5373    pub this: Expression,
5374    /// RUNNING or FINAL semantics (Snowflake-specific)
5375    pub window_frame: Option<MatchRecognizeSemantics>,
5376}
5377
5378/// Semantics for MEASURES in MATCH_RECOGNIZE
5379#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5380#[cfg_attr(feature = "bindings", derive(TS))]
5381#[cfg_attr(feature = "bindings", ts(export))]
5382pub enum MatchRecognizeSemantics {
5383    Running,
5384    Final,
5385}
5386
5387/// Row output semantics for MATCH_RECOGNIZE
5388#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5389#[cfg_attr(feature = "bindings", derive(TS))]
5390#[cfg_attr(feature = "bindings", ts(export))]
5391pub enum MatchRecognizeRows {
5392    OneRowPerMatch,
5393    AllRowsPerMatch,
5394    AllRowsPerMatchShowEmptyMatches,
5395    AllRowsPerMatchOmitEmptyMatches,
5396    AllRowsPerMatchWithUnmatchedRows,
5397}
5398
5399/// AFTER MATCH SKIP behavior
5400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5401#[cfg_attr(feature = "bindings", derive(TS))]
5402#[cfg_attr(feature = "bindings", ts(export))]
5403pub enum MatchRecognizeAfter {
5404    PastLastRow,
5405    ToNextRow,
5406    ToFirst(Identifier),
5407    ToLast(Identifier),
5408}
5409
5410/// Represent a LIMIT clause that restricts the number of returned rows.
5411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5412#[cfg_attr(feature = "bindings", derive(TS))]
5413pub struct Limit {
5414    /// The limit count expression.
5415    pub this: Expression,
5416    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5417    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5418    pub percent: bool,
5419    /// Comments from before the LIMIT keyword (emitted after the limit value)
5420    #[serde(default)]
5421    #[serde(skip_serializing_if = "Vec::is_empty")]
5422    pub comments: Vec<String>,
5423}
5424
5425/// OFFSET clause
5426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5427#[cfg_attr(feature = "bindings", derive(TS))]
5428pub struct Offset {
5429    pub this: Expression,
5430    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5431    #[serde(skip_serializing_if = "Option::is_none", default)]
5432    pub rows: Option<bool>,
5433}
5434
5435/// TOP clause (SQL Server)
5436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5437#[cfg_attr(feature = "bindings", derive(TS))]
5438pub struct Top {
5439    pub this: Expression,
5440    pub percent: bool,
5441    pub with_ties: bool,
5442    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5443    #[serde(default)]
5444    pub parenthesized: bool,
5445}
5446
5447/// FETCH FIRST/NEXT clause (SQL standard)
5448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5449#[cfg_attr(feature = "bindings", derive(TS))]
5450pub struct Fetch {
5451    /// FIRST or NEXT
5452    pub direction: String,
5453    /// Count expression (optional)
5454    pub count: Option<Expression>,
5455    /// PERCENT modifier
5456    pub percent: bool,
5457    /// ROWS or ROW keyword present
5458    pub rows: bool,
5459    /// WITH TIES modifier
5460    pub with_ties: bool,
5461}
5462
5463/// Represent a QUALIFY clause for filtering on window function results.
5464///
5465/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5466/// typically references a window function (e.g.
5467/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5469#[cfg_attr(feature = "bindings", derive(TS))]
5470pub struct Qualify {
5471    /// The filter predicate over window function results.
5472    pub this: Expression,
5473}
5474
5475/// SAMPLE / TABLESAMPLE clause
5476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5477#[cfg_attr(feature = "bindings", derive(TS))]
5478pub struct Sample {
5479    pub method: SampleMethod,
5480    pub size: Expression,
5481    pub seed: Option<Expression>,
5482    /// ClickHouse OFFSET expression after SAMPLE size
5483    #[serde(default)]
5484    pub offset: Option<Expression>,
5485    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5486    pub unit_after_size: bool,
5487    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5488    #[serde(default)]
5489    pub use_sample_keyword: bool,
5490    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5491    #[serde(default)]
5492    pub explicit_method: bool,
5493    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5494    #[serde(default)]
5495    pub method_before_size: bool,
5496    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5497    #[serde(default)]
5498    pub use_seed_keyword: bool,
5499    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5500    pub bucket_numerator: Option<Box<Expression>>,
5501    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5502    pub bucket_denominator: Option<Box<Expression>>,
5503    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5504    pub bucket_field: Option<Box<Expression>>,
5505    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5506    #[serde(default)]
5507    pub is_using_sample: bool,
5508    /// Whether the unit was explicitly PERCENT (vs ROWS)
5509    #[serde(default)]
5510    pub is_percent: bool,
5511    /// Whether to suppress method output (for cross-dialect transpilation)
5512    #[serde(default)]
5513    pub suppress_method_output: bool,
5514}
5515
5516/// Sample method
5517#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5518#[cfg_attr(feature = "bindings", derive(TS))]
5519pub enum SampleMethod {
5520    Bernoulli,
5521    System,
5522    Block,
5523    Row,
5524    Percent,
5525    /// Hive bucket sampling
5526    Bucket,
5527    /// DuckDB reservoir sampling
5528    Reservoir,
5529}
5530
5531/// Named window definition (WINDOW w AS (...))
5532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5533#[cfg_attr(feature = "bindings", derive(TS))]
5534pub struct NamedWindow {
5535    pub name: Identifier,
5536    pub spec: Over,
5537}
5538
5539/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5540///
5541/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5542/// that reference themselves. Each CTE is defined in the `ctes` vector and
5543/// can be referenced by name in subsequent CTEs and in the main query body.
5544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5545#[cfg_attr(feature = "bindings", derive(TS))]
5546pub struct With {
5547    /// The list of CTE definitions, in order.
5548    pub ctes: Vec<Cte>,
5549    /// Whether the WITH RECURSIVE keyword was used.
5550    pub recursive: bool,
5551    /// Leading comments before the statement
5552    #[serde(default)]
5553    pub leading_comments: Vec<String>,
5554    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5555    #[serde(default, skip_serializing_if = "Option::is_none")]
5556    pub search: Option<Box<Expression>>,
5557}
5558
5559/// Represent a single Common Table Expression definition.
5560///
5561/// A CTE has a name (`alias`), an optional column list, and a body query.
5562/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5563/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5564/// the expression comes before the alias (`alias_first`).
5565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5566#[cfg_attr(feature = "bindings", derive(TS))]
5567pub struct Cte {
5568    /// The CTE name.
5569    pub alias: Identifier,
5570    /// The CTE body (typically a SELECT, UNION, etc.).
5571    pub this: Expression,
5572    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5573    pub columns: Vec<Identifier>,
5574    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5575    pub materialized: Option<bool>,
5576    /// USING KEY (columns) for DuckDB recursive CTEs
5577    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5578    pub key_expressions: Vec<Identifier>,
5579    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5580    #[serde(default)]
5581    pub alias_first: bool,
5582    /// Comments associated with this CTE (placed after alias name, before AS)
5583    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5584    pub comments: Vec<String>,
5585}
5586
5587/// Window specification
5588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5589#[cfg_attr(feature = "bindings", derive(TS))]
5590pub struct WindowSpec {
5591    pub partition_by: Vec<Expression>,
5592    pub order_by: Vec<Ordered>,
5593    pub frame: Option<WindowFrame>,
5594}
5595
5596/// OVER clause
5597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5598#[cfg_attr(feature = "bindings", derive(TS))]
5599pub struct Over {
5600    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5601    pub window_name: Option<Identifier>,
5602    pub partition_by: Vec<Expression>,
5603    pub order_by: Vec<Ordered>,
5604    pub frame: Option<WindowFrame>,
5605    pub alias: Option<Identifier>,
5606}
5607
5608/// Window frame
5609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5610#[cfg_attr(feature = "bindings", derive(TS))]
5611pub struct WindowFrame {
5612    pub kind: WindowFrameKind,
5613    pub start: WindowFrameBound,
5614    pub end: Option<WindowFrameBound>,
5615    pub exclude: Option<WindowFrameExclude>,
5616    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5617    #[serde(default, skip_serializing_if = "Option::is_none")]
5618    pub kind_text: Option<String>,
5619    /// Original text of the start bound side keyword (e.g. "preceding")
5620    #[serde(default, skip_serializing_if = "Option::is_none")]
5621    pub start_side_text: Option<String>,
5622    /// Original text of the end bound side keyword
5623    #[serde(default, skip_serializing_if = "Option::is_none")]
5624    pub end_side_text: Option<String>,
5625}
5626
5627#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5628#[cfg_attr(feature = "bindings", derive(TS))]
5629pub enum WindowFrameKind {
5630    Rows,
5631    Range,
5632    Groups,
5633}
5634
5635/// EXCLUDE clause for window frames
5636#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5637#[cfg_attr(feature = "bindings", derive(TS))]
5638pub enum WindowFrameExclude {
5639    CurrentRow,
5640    Group,
5641    Ties,
5642    NoOthers,
5643}
5644
5645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5646#[cfg_attr(feature = "bindings", derive(TS))]
5647pub enum WindowFrameBound {
5648    CurrentRow,
5649    UnboundedPreceding,
5650    UnboundedFollowing,
5651    Preceding(Box<Expression>),
5652    Following(Box<Expression>),
5653    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5654    BarePreceding,
5655    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5656    BareFollowing,
5657    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5658    Value(Box<Expression>),
5659}
5660
5661/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5663#[cfg_attr(feature = "bindings", derive(TS))]
5664pub struct StructField {
5665    pub name: String,
5666    pub data_type: DataType,
5667    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5668    pub options: Vec<Expression>,
5669    #[serde(default, skip_serializing_if = "Option::is_none")]
5670    pub comment: Option<String>,
5671}
5672
5673impl StructField {
5674    /// Create a new struct field without options
5675    pub fn new(name: String, data_type: DataType) -> Self {
5676        Self {
5677            name,
5678            data_type,
5679            options: Vec::new(),
5680            comment: None,
5681        }
5682    }
5683
5684    /// Create a new struct field with options
5685    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5686        Self {
5687            name,
5688            data_type,
5689            options,
5690            comment: None,
5691        }
5692    }
5693
5694    /// Create a new struct field with options and comment
5695    pub fn with_options_and_comment(
5696        name: String,
5697        data_type: DataType,
5698        options: Vec<Expression>,
5699        comment: Option<String>,
5700    ) -> Self {
5701        Self {
5702            name,
5703            data_type,
5704            options,
5705            comment,
5706        }
5707    }
5708}
5709
5710/// Enumerate all SQL data types recognized by the parser.
5711///
5712/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5713/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5714/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5715///
5716/// This enum is used in CAST expressions, column definitions, function return
5717/// types, and anywhere a data type specification appears in SQL.
5718///
5719/// Types that do not match any known variant fall through to `Custom { name }`,
5720/// preserving the original type name for round-trip fidelity.
5721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5722#[cfg_attr(feature = "bindings", derive(TS))]
5723#[serde(tag = "data_type", rename_all = "snake_case")]
5724pub enum DataType {
5725    // Numeric
5726    Boolean,
5727    TinyInt {
5728        length: Option<u32>,
5729    },
5730    SmallInt {
5731        length: Option<u32>,
5732    },
5733    /// Int type with optional length. `integer_spelling` indicates whether the original
5734    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5735    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5736    Int {
5737        length: Option<u32>,
5738        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5739        integer_spelling: bool,
5740    },
5741    BigInt {
5742        length: Option<u32>,
5743    },
5744    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5745    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5746    /// preserve the original spelling.
5747    Float {
5748        precision: Option<u32>,
5749        scale: Option<u32>,
5750        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5751        real_spelling: bool,
5752    },
5753    Double {
5754        precision: Option<u32>,
5755        scale: Option<u32>,
5756    },
5757    Decimal {
5758        precision: Option<u32>,
5759        scale: Option<u32>,
5760    },
5761
5762    // String
5763    Char {
5764        length: Option<u32>,
5765    },
5766    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5767    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5768    VarChar {
5769        length: Option<u32>,
5770        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5771        parenthesized_length: bool,
5772    },
5773    /// String type with optional max length (BigQuery STRING(n))
5774    String {
5775        length: Option<u32>,
5776    },
5777    Text,
5778    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5779    TextWithLength {
5780        length: u32,
5781    },
5782
5783    // Binary
5784    Binary {
5785        length: Option<u32>,
5786    },
5787    VarBinary {
5788        length: Option<u32>,
5789    },
5790    Blob,
5791
5792    // Bit
5793    Bit {
5794        length: Option<u32>,
5795    },
5796    VarBit {
5797        length: Option<u32>,
5798    },
5799
5800    // Date/Time
5801    Date,
5802    Time {
5803        precision: Option<u32>,
5804        #[serde(default)]
5805        timezone: bool,
5806    },
5807    Timestamp {
5808        precision: Option<u32>,
5809        timezone: bool,
5810    },
5811    Interval {
5812        unit: Option<String>,
5813        /// For range intervals like INTERVAL DAY TO HOUR
5814        #[serde(default, skip_serializing_if = "Option::is_none")]
5815        to: Option<String>,
5816    },
5817
5818    // JSON
5819    Json,
5820    JsonB,
5821
5822    // UUID
5823    Uuid,
5824
5825    // Array
5826    Array {
5827        element_type: Box<DataType>,
5828        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5829        #[serde(default, skip_serializing_if = "Option::is_none")]
5830        dimension: Option<u32>,
5831    },
5832
5833    /// List type (Materialize): INT LIST, TEXT LIST LIST
5834    /// Uses postfix LIST syntax instead of ARRAY<T>
5835    List {
5836        element_type: Box<DataType>,
5837    },
5838
5839    // Struct/Map
5840    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5841    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5842    Struct {
5843        fields: Vec<StructField>,
5844        nested: bool,
5845    },
5846    Map {
5847        key_type: Box<DataType>,
5848        value_type: Box<DataType>,
5849    },
5850
5851    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5852    Enum {
5853        values: Vec<String>,
5854        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5855        assignments: Vec<Option<String>>,
5856    },
5857
5858    // Set type (MySQL): SET('a', 'b', 'c')
5859    Set {
5860        values: Vec<String>,
5861    },
5862
5863    // Union type (DuckDB): UNION(num INT, str TEXT)
5864    Union {
5865        fields: Vec<(String, DataType)>,
5866    },
5867
5868    // Vector (Snowflake / SingleStore)
5869    Vector {
5870        #[serde(default)]
5871        element_type: Option<Box<DataType>>,
5872        dimension: Option<u32>,
5873    },
5874
5875    // Object (Snowflake structured type)
5876    // fields: Vec of (field_name, field_type, not_null)
5877    Object {
5878        fields: Vec<(String, DataType, bool)>,
5879        modifier: Option<String>,
5880    },
5881
5882    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5883    Nullable {
5884        inner: Box<DataType>,
5885    },
5886
5887    // Custom/User-defined
5888    Custom {
5889        name: String,
5890    },
5891
5892    // Spatial types
5893    Geometry {
5894        subtype: Option<String>,
5895        srid: Option<u32>,
5896    },
5897    Geography {
5898        subtype: Option<String>,
5899        srid: Option<u32>,
5900    },
5901
5902    // Character Set (for CONVERT USING in MySQL)
5903    // Renders as CHAR CHARACTER SET {name} in cast target
5904    CharacterSet {
5905        name: String,
5906    },
5907
5908    // Unknown
5909    Unknown,
5910}
5911
5912/// Array expression
5913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5914#[cfg_attr(feature = "bindings", derive(TS))]
5915#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5916pub struct Array {
5917    pub expressions: Vec<Expression>,
5918}
5919
5920/// Struct expression
5921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5922#[cfg_attr(feature = "bindings", derive(TS))]
5923pub struct Struct {
5924    pub fields: Vec<(Option<String>, Expression)>,
5925}
5926
5927/// Tuple expression
5928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5929#[cfg_attr(feature = "bindings", derive(TS))]
5930pub struct Tuple {
5931    pub expressions: Vec<Expression>,
5932}
5933
5934/// Interval expression
5935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5936#[cfg_attr(feature = "bindings", derive(TS))]
5937pub struct Interval {
5938    /// The value expression (e.g., '1', 5, column_ref)
5939    pub this: Option<Expression>,
5940    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5941    pub unit: Option<IntervalUnitSpec>,
5942}
5943
5944/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5946#[cfg_attr(feature = "bindings", derive(TS))]
5947#[serde(tag = "type", rename_all = "snake_case")]
5948pub enum IntervalUnitSpec {
5949    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5950    Simple {
5951        unit: IntervalUnit,
5952        /// Whether to use plural form (e.g., DAYS vs DAY)
5953        use_plural: bool,
5954    },
5955    /// Interval span (e.g., HOUR TO SECOND)
5956    Span(IntervalSpan),
5957    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5958    /// The start and end can be expressions like function calls with precision
5959    ExprSpan(IntervalSpanExpr),
5960    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5961    Expr(Box<Expression>),
5962}
5963
5964/// Interval span for ranges like HOUR TO SECOND
5965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5966#[cfg_attr(feature = "bindings", derive(TS))]
5967pub struct IntervalSpan {
5968    /// Start unit (e.g., HOUR)
5969    pub this: IntervalUnit,
5970    /// End unit (e.g., SECOND)
5971    pub expression: IntervalUnit,
5972}
5973
5974/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5975/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5977#[cfg_attr(feature = "bindings", derive(TS))]
5978pub struct IntervalSpanExpr {
5979    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5980    pub this: Box<Expression>,
5981    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5982    pub expression: Box<Expression>,
5983}
5984
5985#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5986#[cfg_attr(feature = "bindings", derive(TS))]
5987pub enum IntervalUnit {
5988    Year,
5989    Quarter,
5990    Month,
5991    Week,
5992    Day,
5993    Hour,
5994    Minute,
5995    Second,
5996    Millisecond,
5997    Microsecond,
5998    Nanosecond,
5999}
6000
6001/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
6002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6003#[cfg_attr(feature = "bindings", derive(TS))]
6004pub struct Command {
6005    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
6006    pub this: String,
6007}
6008
6009/// T-SQL TRY/CATCH block.
6010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6011#[cfg_attr(feature = "bindings", derive(TS))]
6012pub struct TryCatch {
6013    /// Statements inside BEGIN TRY ... END TRY.
6014    #[serde(default)]
6015    pub try_body: Vec<Expression>,
6016    /// Statements inside BEGIN CATCH ... END CATCH, when present.
6017    #[serde(default, skip_serializing_if = "Option::is_none")]
6018    pub catch_body: Option<Vec<Expression>>,
6019}
6020
6021/// EXEC/EXECUTE statement (TSQL stored procedure call)
6022/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
6023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6024#[cfg_attr(feature = "bindings", derive(TS))]
6025pub struct ExecuteStatement {
6026    /// The procedure name (can be qualified: schema.proc_name)
6027    pub this: Expression,
6028    /// Named parameters: @param=value pairs
6029    #[serde(default)]
6030    pub parameters: Vec<ExecuteParameter>,
6031    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
6032    #[serde(default, skip_serializing_if = "Option::is_none")]
6033    pub suffix: Option<String>,
6034}
6035
6036/// Named parameter in EXEC statement: @name=value
6037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6038#[cfg_attr(feature = "bindings", derive(TS))]
6039pub struct ExecuteParameter {
6040    /// Parameter name (including @)
6041    pub name: String,
6042    /// Parameter value
6043    pub value: Expression,
6044    /// Whether this is a positional parameter (no = sign)
6045    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6046    pub positional: bool,
6047    /// TSQL OUTPUT modifier on parameter
6048    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6049    pub output: bool,
6050}
6051
6052/// KILL statement (MySQL/MariaDB)
6053/// KILL [CONNECTION | QUERY] <id>
6054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6055#[cfg_attr(feature = "bindings", derive(TS))]
6056pub struct Kill {
6057    /// The target (process ID or connection ID)
6058    pub this: Expression,
6059    /// Optional kind: "CONNECTION" or "QUERY"
6060    pub kind: Option<String>,
6061}
6062
6063/// Snowflake CREATE TASK statement
6064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6065#[cfg_attr(feature = "bindings", derive(TS))]
6066pub struct CreateTask {
6067    pub or_replace: bool,
6068    pub if_not_exists: bool,
6069    /// Task name (possibly qualified: db.schema.task)
6070    pub name: String,
6071    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6072    pub properties: String,
6073    /// The SQL statement body after AS
6074    pub body: Expression,
6075}
6076
6077/// Raw/unparsed SQL
6078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6079#[cfg_attr(feature = "bindings", derive(TS))]
6080pub struct Raw {
6081    pub sql: String,
6082}
6083
6084// ============================================================================
6085// Function expression types
6086// ============================================================================
6087
6088/// Generic unary function (takes a single argument)
6089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6090#[cfg_attr(feature = "bindings", derive(TS))]
6091pub struct UnaryFunc {
6092    pub this: Expression,
6093    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6094    #[serde(skip_serializing_if = "Option::is_none", default)]
6095    pub original_name: Option<String>,
6096    /// Inferred data type from type annotation
6097    #[serde(default, skip_serializing_if = "Option::is_none")]
6098    pub inferred_type: Option<DataType>,
6099}
6100
6101impl UnaryFunc {
6102    /// Create a new UnaryFunc with no original_name
6103    pub fn new(this: Expression) -> Self {
6104        Self {
6105            this,
6106            original_name: None,
6107            inferred_type: None,
6108        }
6109    }
6110
6111    /// Create a new UnaryFunc with an original name for round-trip preservation
6112    pub fn with_name(this: Expression, name: String) -> Self {
6113        Self {
6114            this,
6115            original_name: Some(name),
6116            inferred_type: None,
6117        }
6118    }
6119}
6120
6121/// CHAR/CHR function with multiple args and optional USING charset
6122/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6123/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6125#[cfg_attr(feature = "bindings", derive(TS))]
6126pub struct CharFunc {
6127    pub args: Vec<Expression>,
6128    #[serde(skip_serializing_if = "Option::is_none", default)]
6129    pub charset: Option<String>,
6130    /// Original function name (CHAR or CHR), defaults to CHAR
6131    #[serde(skip_serializing_if = "Option::is_none", default)]
6132    pub name: Option<String>,
6133}
6134
6135/// Generic binary function (takes two arguments)
6136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6137#[cfg_attr(feature = "bindings", derive(TS))]
6138pub struct BinaryFunc {
6139    pub this: Expression,
6140    pub expression: Expression,
6141    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6142    #[serde(skip_serializing_if = "Option::is_none", default)]
6143    pub original_name: Option<String>,
6144    /// Inferred data type from type annotation
6145    #[serde(default, skip_serializing_if = "Option::is_none")]
6146    pub inferred_type: Option<DataType>,
6147}
6148
6149/// Variable argument function
6150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6151#[cfg_attr(feature = "bindings", derive(TS))]
6152pub struct VarArgFunc {
6153    pub expressions: Vec<Expression>,
6154    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6155    #[serde(skip_serializing_if = "Option::is_none", default)]
6156    pub original_name: Option<String>,
6157    /// Inferred data type from type annotation
6158    #[serde(default, skip_serializing_if = "Option::is_none")]
6159    pub inferred_type: Option<DataType>,
6160}
6161
6162/// CONCAT_WS function
6163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6164#[cfg_attr(feature = "bindings", derive(TS))]
6165pub struct ConcatWs {
6166    pub separator: Expression,
6167    pub expressions: Vec<Expression>,
6168}
6169
6170/// SUBSTRING function
6171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6172#[cfg_attr(feature = "bindings", derive(TS))]
6173pub struct SubstringFunc {
6174    pub this: Expression,
6175    pub start: Expression,
6176    pub length: Option<Expression>,
6177    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6178    #[serde(default)]
6179    pub from_for_syntax: bool,
6180}
6181
6182/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6184#[cfg_attr(feature = "bindings", derive(TS))]
6185pub struct OverlayFunc {
6186    pub this: Expression,
6187    pub replacement: Expression,
6188    pub from: Expression,
6189    pub length: Option<Expression>,
6190}
6191
6192/// TRIM function
6193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6194#[cfg_attr(feature = "bindings", derive(TS))]
6195pub struct TrimFunc {
6196    pub this: Expression,
6197    pub characters: Option<Expression>,
6198    pub position: TrimPosition,
6199    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6200    #[serde(default)]
6201    pub sql_standard_syntax: bool,
6202    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6203    #[serde(default)]
6204    pub position_explicit: bool,
6205}
6206
6207#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6208#[cfg_attr(feature = "bindings", derive(TS))]
6209pub enum TrimPosition {
6210    Both,
6211    Leading,
6212    Trailing,
6213}
6214
6215/// REPLACE function
6216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6217#[cfg_attr(feature = "bindings", derive(TS))]
6218pub struct ReplaceFunc {
6219    pub this: Expression,
6220    pub old: Expression,
6221    pub new: Expression,
6222}
6223
6224/// LEFT/RIGHT function
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub struct LeftRightFunc {
6228    pub this: Expression,
6229    pub length: Expression,
6230}
6231
6232/// REPEAT function
6233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6234#[cfg_attr(feature = "bindings", derive(TS))]
6235pub struct RepeatFunc {
6236    pub this: Expression,
6237    pub times: Expression,
6238}
6239
6240/// LPAD/RPAD function
6241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6242#[cfg_attr(feature = "bindings", derive(TS))]
6243pub struct PadFunc {
6244    pub this: Expression,
6245    pub length: Expression,
6246    pub fill: Option<Expression>,
6247}
6248
6249/// SPLIT function
6250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6251#[cfg_attr(feature = "bindings", derive(TS))]
6252pub struct SplitFunc {
6253    pub this: Expression,
6254    pub delimiter: Expression,
6255}
6256
6257/// REGEXP_LIKE function
6258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6259#[cfg_attr(feature = "bindings", derive(TS))]
6260pub struct RegexpFunc {
6261    pub this: Expression,
6262    pub pattern: Expression,
6263    pub flags: Option<Expression>,
6264}
6265
6266/// REGEXP_REPLACE function
6267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6268#[cfg_attr(feature = "bindings", derive(TS))]
6269pub struct RegexpReplaceFunc {
6270    pub this: Expression,
6271    pub pattern: Expression,
6272    pub replacement: Expression,
6273    pub flags: Option<Expression>,
6274}
6275
6276/// REGEXP_EXTRACT function
6277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6278#[cfg_attr(feature = "bindings", derive(TS))]
6279pub struct RegexpExtractFunc {
6280    pub this: Expression,
6281    pub pattern: Expression,
6282    pub group: Option<Expression>,
6283}
6284
6285/// ROUND function
6286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6287#[cfg_attr(feature = "bindings", derive(TS))]
6288pub struct RoundFunc {
6289    pub this: Expression,
6290    pub decimals: Option<Expression>,
6291}
6292
6293/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6295#[cfg_attr(feature = "bindings", derive(TS))]
6296pub struct FloorFunc {
6297    pub this: Expression,
6298    pub scale: Option<Expression>,
6299    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6300    #[serde(skip_serializing_if = "Option::is_none", default)]
6301    pub to: Option<Expression>,
6302}
6303
6304/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6306#[cfg_attr(feature = "bindings", derive(TS))]
6307pub struct CeilFunc {
6308    pub this: Expression,
6309    #[serde(skip_serializing_if = "Option::is_none", default)]
6310    pub decimals: Option<Expression>,
6311    /// Time unit for Druid-style CEIL(time TO unit) syntax
6312    #[serde(skip_serializing_if = "Option::is_none", default)]
6313    pub to: Option<Expression>,
6314}
6315
6316/// LOG function
6317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6318#[cfg_attr(feature = "bindings", derive(TS))]
6319pub struct LogFunc {
6320    pub this: Expression,
6321    pub base: Option<Expression>,
6322}
6323
6324/// CURRENT_DATE (no arguments)
6325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6326#[cfg_attr(feature = "bindings", derive(TS))]
6327pub struct CurrentDate;
6328
6329/// CURRENT_TIME
6330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6331#[cfg_attr(feature = "bindings", derive(TS))]
6332pub struct CurrentTime {
6333    pub precision: Option<u32>,
6334}
6335
6336/// CURRENT_TIMESTAMP
6337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6338#[cfg_attr(feature = "bindings", derive(TS))]
6339pub struct CurrentTimestamp {
6340    pub precision: Option<u32>,
6341    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6342    #[serde(default)]
6343    pub sysdate: bool,
6344}
6345
6346/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6348#[cfg_attr(feature = "bindings", derive(TS))]
6349pub struct CurrentTimestampLTZ {
6350    pub precision: Option<u32>,
6351}
6352
6353/// AT TIME ZONE expression for timezone conversion
6354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6355#[cfg_attr(feature = "bindings", derive(TS))]
6356pub struct AtTimeZone {
6357    /// The expression to convert
6358    pub this: Expression,
6359    /// The target timezone
6360    pub zone: Expression,
6361}
6362
6363/// DATE_ADD / DATE_SUB function
6364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6365#[cfg_attr(feature = "bindings", derive(TS))]
6366pub struct DateAddFunc {
6367    pub this: Expression,
6368    pub interval: Expression,
6369    pub unit: IntervalUnit,
6370}
6371
6372/// DATEDIFF function
6373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6374#[cfg_attr(feature = "bindings", derive(TS))]
6375pub struct DateDiffFunc {
6376    pub this: Expression,
6377    pub expression: Expression,
6378    pub unit: Option<IntervalUnit>,
6379}
6380
6381/// DATE_TRUNC function
6382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6383#[cfg_attr(feature = "bindings", derive(TS))]
6384pub struct DateTruncFunc {
6385    pub this: Expression,
6386    pub unit: DateTimeField,
6387}
6388
6389/// EXTRACT function
6390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6391#[cfg_attr(feature = "bindings", derive(TS))]
6392pub struct ExtractFunc {
6393    pub this: Expression,
6394    pub field: DateTimeField,
6395}
6396
6397#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6398#[cfg_attr(feature = "bindings", derive(TS))]
6399pub enum DateTimeField {
6400    Year,
6401    Month,
6402    Day,
6403    Hour,
6404    Minute,
6405    Second,
6406    Millisecond,
6407    Microsecond,
6408    DayOfWeek,
6409    DayOfYear,
6410    Week,
6411    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6412    WeekWithModifier(String),
6413    Quarter,
6414    Epoch,
6415    Timezone,
6416    TimezoneHour,
6417    TimezoneMinute,
6418    Date,
6419    Time,
6420    /// Custom datetime field for dialect-specific or arbitrary fields
6421    Custom(String),
6422}
6423
6424/// TO_DATE function
6425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6426#[cfg_attr(feature = "bindings", derive(TS))]
6427pub struct ToDateFunc {
6428    pub this: Expression,
6429    pub format: Option<Expression>,
6430}
6431
6432/// TO_TIMESTAMP function
6433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6434#[cfg_attr(feature = "bindings", derive(TS))]
6435pub struct ToTimestampFunc {
6436    pub this: Expression,
6437    pub format: Option<Expression>,
6438}
6439
6440/// IF function
6441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6442#[cfg_attr(feature = "bindings", derive(TS))]
6443pub struct IfFunc {
6444    pub condition: Expression,
6445    pub true_value: Expression,
6446    pub false_value: Option<Expression>,
6447    /// Original function name (IF, IFF, IIF) for round-trip preservation
6448    #[serde(skip_serializing_if = "Option::is_none", default)]
6449    pub original_name: Option<String>,
6450    /// Inferred data type from type annotation
6451    #[serde(default, skip_serializing_if = "Option::is_none")]
6452    pub inferred_type: Option<DataType>,
6453}
6454
6455/// NVL2 function
6456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6457#[cfg_attr(feature = "bindings", derive(TS))]
6458pub struct Nvl2Func {
6459    pub this: Expression,
6460    pub true_value: Expression,
6461    pub false_value: Expression,
6462    /// Inferred data type from type annotation
6463    #[serde(default, skip_serializing_if = "Option::is_none")]
6464    pub inferred_type: Option<DataType>,
6465}
6466
6467// ============================================================================
6468// Typed Aggregate Function types
6469// ============================================================================
6470
6471/// Generic aggregate function base type
6472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6473#[cfg_attr(feature = "bindings", derive(TS))]
6474pub struct AggFunc {
6475    pub this: Expression,
6476    pub distinct: bool,
6477    pub filter: Option<Expression>,
6478    pub order_by: Vec<Ordered>,
6479    /// Original function name (case-preserving) when parsed from SQL
6480    #[serde(skip_serializing_if = "Option::is_none", default)]
6481    pub name: Option<String>,
6482    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6483    #[serde(skip_serializing_if = "Option::is_none", default)]
6484    pub ignore_nulls: Option<bool>,
6485    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6486    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6487    #[serde(skip_serializing_if = "Option::is_none", default)]
6488    pub having_max: Option<(Box<Expression>, bool)>,
6489    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6490    #[serde(skip_serializing_if = "Option::is_none", default)]
6491    pub limit: Option<Box<Expression>>,
6492    /// Inferred data type from type annotation
6493    #[serde(default, skip_serializing_if = "Option::is_none")]
6494    pub inferred_type: Option<DataType>,
6495}
6496
6497/// COUNT function with optional star
6498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6499#[cfg_attr(feature = "bindings", derive(TS))]
6500pub struct CountFunc {
6501    pub this: Option<Expression>,
6502    pub star: bool,
6503    pub distinct: bool,
6504    pub filter: Option<Expression>,
6505    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6506    #[serde(default, skip_serializing_if = "Option::is_none")]
6507    pub ignore_nulls: Option<bool>,
6508    /// Original function name for case preservation (e.g., "count" or "COUNT")
6509    #[serde(default, skip_serializing_if = "Option::is_none")]
6510    pub original_name: Option<String>,
6511    /// Inferred data type from type annotation
6512    #[serde(default, skip_serializing_if = "Option::is_none")]
6513    pub inferred_type: Option<DataType>,
6514}
6515
6516/// GROUP_CONCAT function (MySQL style)
6517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6518#[cfg_attr(feature = "bindings", derive(TS))]
6519pub struct GroupConcatFunc {
6520    pub this: Expression,
6521    pub separator: Option<Expression>,
6522    pub order_by: Option<Vec<Ordered>>,
6523    pub distinct: bool,
6524    pub filter: Option<Expression>,
6525    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6526    #[serde(default, skip_serializing_if = "Option::is_none")]
6527    pub limit: Option<Box<Expression>>,
6528    /// Inferred data type from type annotation
6529    #[serde(default, skip_serializing_if = "Option::is_none")]
6530    pub inferred_type: Option<DataType>,
6531}
6532
6533/// STRING_AGG function (PostgreSQL/Standard SQL)
6534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6535#[cfg_attr(feature = "bindings", derive(TS))]
6536pub struct StringAggFunc {
6537    pub this: Expression,
6538    #[serde(default)]
6539    pub separator: Option<Expression>,
6540    #[serde(default)]
6541    pub order_by: Option<Vec<Ordered>>,
6542    #[serde(default)]
6543    pub distinct: bool,
6544    #[serde(default)]
6545    pub filter: Option<Expression>,
6546    /// BigQuery LIMIT inside STRING_AGG
6547    #[serde(default, skip_serializing_if = "Option::is_none")]
6548    pub limit: Option<Box<Expression>>,
6549    /// Inferred data type from type annotation
6550    #[serde(default, skip_serializing_if = "Option::is_none")]
6551    pub inferred_type: Option<DataType>,
6552}
6553
6554/// LISTAGG function (Oracle style)
6555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6556#[cfg_attr(feature = "bindings", derive(TS))]
6557pub struct ListAggFunc {
6558    pub this: Expression,
6559    pub separator: Option<Expression>,
6560    pub on_overflow: Option<ListAggOverflow>,
6561    pub order_by: Option<Vec<Ordered>>,
6562    pub distinct: bool,
6563    pub filter: Option<Expression>,
6564    /// Inferred data type from type annotation
6565    #[serde(default, skip_serializing_if = "Option::is_none")]
6566    pub inferred_type: Option<DataType>,
6567}
6568
6569/// LISTAGG ON OVERFLOW behavior
6570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6571#[cfg_attr(feature = "bindings", derive(TS))]
6572pub enum ListAggOverflow {
6573    Error,
6574    Truncate {
6575        filler: Option<Expression>,
6576        with_count: bool,
6577    },
6578}
6579
6580/// SUM_IF / COUNT_IF function
6581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6582#[cfg_attr(feature = "bindings", derive(TS))]
6583pub struct SumIfFunc {
6584    pub this: Expression,
6585    pub condition: Expression,
6586    pub filter: Option<Expression>,
6587    /// Inferred data type from type annotation
6588    #[serde(default, skip_serializing_if = "Option::is_none")]
6589    pub inferred_type: Option<DataType>,
6590}
6591
6592/// APPROX_PERCENTILE function
6593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6594#[cfg_attr(feature = "bindings", derive(TS))]
6595pub struct ApproxPercentileFunc {
6596    pub this: Expression,
6597    pub percentile: Expression,
6598    pub accuracy: Option<Expression>,
6599    pub filter: Option<Expression>,
6600}
6601
6602/// PERCENTILE_CONT / PERCENTILE_DISC function
6603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6604#[cfg_attr(feature = "bindings", derive(TS))]
6605pub struct PercentileFunc {
6606    pub this: Expression,
6607    pub percentile: Expression,
6608    pub order_by: Option<Vec<Ordered>>,
6609    pub filter: Option<Expression>,
6610}
6611
6612// ============================================================================
6613// Typed Window Function types
6614// ============================================================================
6615
6616/// ROW_NUMBER function (no arguments)
6617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6618#[cfg_attr(feature = "bindings", derive(TS))]
6619pub struct RowNumber;
6620
6621/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6623#[cfg_attr(feature = "bindings", derive(TS))]
6624pub struct Rank {
6625    /// DuckDB: RANK(ORDER BY col) - order by inside function
6626    #[serde(default, skip_serializing_if = "Option::is_none")]
6627    pub order_by: Option<Vec<Ordered>>,
6628    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6629    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6630    pub args: Vec<Expression>,
6631}
6632
6633/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6635#[cfg_attr(feature = "bindings", derive(TS))]
6636pub struct DenseRank {
6637    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6638    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6639    pub args: Vec<Expression>,
6640}
6641
6642/// NTILE function (DuckDB allows ORDER BY inside)
6643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6644#[cfg_attr(feature = "bindings", derive(TS))]
6645pub struct NTileFunc {
6646    /// num_buckets is optional to support Databricks NTILE() without arguments
6647    #[serde(default, skip_serializing_if = "Option::is_none")]
6648    pub num_buckets: Option<Expression>,
6649    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6650    #[serde(default, skip_serializing_if = "Option::is_none")]
6651    pub order_by: Option<Vec<Ordered>>,
6652}
6653
6654/// LEAD / LAG function
6655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6656#[cfg_attr(feature = "bindings", derive(TS))]
6657pub struct LeadLagFunc {
6658    pub this: Expression,
6659    pub offset: Option<Expression>,
6660    pub default: Option<Expression>,
6661    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6662    #[serde(default, skip_serializing_if = "Option::is_none")]
6663    pub ignore_nulls: Option<bool>,
6664}
6665
6666/// FIRST_VALUE / LAST_VALUE function
6667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6668#[cfg_attr(feature = "bindings", derive(TS))]
6669pub struct ValueFunc {
6670    pub this: Expression,
6671    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6672    #[serde(default, skip_serializing_if = "Option::is_none")]
6673    pub ignore_nulls: Option<bool>,
6674    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6675    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6676    pub order_by: Vec<Ordered>,
6677}
6678
6679/// NTH_VALUE function
6680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6681#[cfg_attr(feature = "bindings", derive(TS))]
6682pub struct NthValueFunc {
6683    pub this: Expression,
6684    pub offset: Expression,
6685    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6686    #[serde(default, skip_serializing_if = "Option::is_none")]
6687    pub ignore_nulls: Option<bool>,
6688    /// Snowflake FROM FIRST / FROM LAST clause
6689    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6690    #[serde(default, skip_serializing_if = "Option::is_none")]
6691    pub from_first: Option<bool>,
6692}
6693
6694/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6696#[cfg_attr(feature = "bindings", derive(TS))]
6697pub struct PercentRank {
6698    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6699    #[serde(default, skip_serializing_if = "Option::is_none")]
6700    pub order_by: Option<Vec<Ordered>>,
6701    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6702    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6703    pub args: Vec<Expression>,
6704}
6705
6706/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6708#[cfg_attr(feature = "bindings", derive(TS))]
6709pub struct CumeDist {
6710    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6711    #[serde(default, skip_serializing_if = "Option::is_none")]
6712    pub order_by: Option<Vec<Ordered>>,
6713    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6714    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6715    pub args: Vec<Expression>,
6716}
6717
6718// ============================================================================
6719// Additional String Function types
6720// ============================================================================
6721
6722/// POSITION/INSTR function
6723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6724#[cfg_attr(feature = "bindings", derive(TS))]
6725pub struct PositionFunc {
6726    pub substring: Expression,
6727    pub string: Expression,
6728    pub start: Option<Expression>,
6729}
6730
6731// ============================================================================
6732// Additional Math Function types
6733// ============================================================================
6734
6735/// RANDOM function (no arguments)
6736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6737#[cfg_attr(feature = "bindings", derive(TS))]
6738pub struct Random;
6739
6740/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6742#[cfg_attr(feature = "bindings", derive(TS))]
6743pub struct Rand {
6744    pub seed: Option<Box<Expression>>,
6745    /// Teradata RANDOM lower bound
6746    #[serde(default)]
6747    pub lower: Option<Box<Expression>>,
6748    /// Teradata RANDOM upper bound
6749    #[serde(default)]
6750    pub upper: Option<Box<Expression>>,
6751}
6752
6753/// TRUNCATE / TRUNC function
6754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6755#[cfg_attr(feature = "bindings", derive(TS))]
6756pub struct TruncateFunc {
6757    pub this: Expression,
6758    pub decimals: Option<Expression>,
6759}
6760
6761/// PI function (no arguments)
6762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6763#[cfg_attr(feature = "bindings", derive(TS))]
6764pub struct Pi;
6765
6766// ============================================================================
6767// Control Flow Function types
6768// ============================================================================
6769
6770/// DECODE function (Oracle style)
6771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6772#[cfg_attr(feature = "bindings", derive(TS))]
6773pub struct DecodeFunc {
6774    pub this: Expression,
6775    pub search_results: Vec<(Expression, Expression)>,
6776    pub default: Option<Expression>,
6777}
6778
6779// ============================================================================
6780// Additional Date/Time Function types
6781// ============================================================================
6782
6783/// DATE_FORMAT / FORMAT_DATE function
6784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6785#[cfg_attr(feature = "bindings", derive(TS))]
6786pub struct DateFormatFunc {
6787    pub this: Expression,
6788    pub format: Expression,
6789}
6790
6791/// FROM_UNIXTIME function
6792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6793#[cfg_attr(feature = "bindings", derive(TS))]
6794pub struct FromUnixtimeFunc {
6795    pub this: Expression,
6796    pub format: Option<Expression>,
6797}
6798
6799/// UNIX_TIMESTAMP function
6800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6801#[cfg_attr(feature = "bindings", derive(TS))]
6802pub struct UnixTimestampFunc {
6803    pub this: Option<Expression>,
6804    pub format: Option<Expression>,
6805}
6806
6807/// MAKE_DATE function
6808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6809#[cfg_attr(feature = "bindings", derive(TS))]
6810pub struct MakeDateFunc {
6811    pub year: Expression,
6812    pub month: Expression,
6813    pub day: Expression,
6814}
6815
6816/// MAKE_TIMESTAMP function
6817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6818#[cfg_attr(feature = "bindings", derive(TS))]
6819pub struct MakeTimestampFunc {
6820    pub year: Expression,
6821    pub month: Expression,
6822    pub day: Expression,
6823    pub hour: Expression,
6824    pub minute: Expression,
6825    pub second: Expression,
6826    pub timezone: Option<Expression>,
6827}
6828
6829/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6831#[cfg_attr(feature = "bindings", derive(TS))]
6832pub struct LastDayFunc {
6833    pub this: Expression,
6834    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6835    #[serde(skip_serializing_if = "Option::is_none", default)]
6836    pub unit: Option<DateTimeField>,
6837}
6838
6839// ============================================================================
6840// Array Function types
6841// ============================================================================
6842
6843/// ARRAY constructor
6844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6845#[cfg_attr(feature = "bindings", derive(TS))]
6846pub struct ArrayConstructor {
6847    pub expressions: Vec<Expression>,
6848    pub bracket_notation: bool,
6849    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6850    pub use_list_keyword: bool,
6851}
6852
6853/// ARRAY_SORT function
6854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6855#[cfg_attr(feature = "bindings", derive(TS))]
6856pub struct ArraySortFunc {
6857    pub this: Expression,
6858    pub comparator: Option<Expression>,
6859    pub desc: bool,
6860    pub nulls_first: Option<bool>,
6861}
6862
6863/// ARRAY_JOIN / ARRAY_TO_STRING function
6864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6865#[cfg_attr(feature = "bindings", derive(TS))]
6866pub struct ArrayJoinFunc {
6867    pub this: Expression,
6868    pub separator: Expression,
6869    pub null_replacement: Option<Expression>,
6870}
6871
6872/// UNNEST function
6873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6874#[cfg_attr(feature = "bindings", derive(TS))]
6875pub struct UnnestFunc {
6876    pub this: Expression,
6877    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6878    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6879    pub expressions: Vec<Expression>,
6880    pub with_ordinality: bool,
6881    pub alias: Option<Identifier>,
6882    /// BigQuery: offset alias for WITH OFFSET AS <name>
6883    #[serde(default, skip_serializing_if = "Option::is_none")]
6884    pub offset_alias: Option<Identifier>,
6885}
6886
6887/// ARRAY_FILTER function (with lambda)
6888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6889#[cfg_attr(feature = "bindings", derive(TS))]
6890pub struct ArrayFilterFunc {
6891    pub this: Expression,
6892    pub filter: Expression,
6893}
6894
6895/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6897#[cfg_attr(feature = "bindings", derive(TS))]
6898pub struct ArrayTransformFunc {
6899    pub this: Expression,
6900    pub transform: Expression,
6901}
6902
6903/// SEQUENCE / GENERATE_SERIES function
6904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6905#[cfg_attr(feature = "bindings", derive(TS))]
6906pub struct SequenceFunc {
6907    pub start: Expression,
6908    pub stop: Expression,
6909    pub step: Option<Expression>,
6910}
6911
6912// ============================================================================
6913// Struct Function types
6914// ============================================================================
6915
6916/// STRUCT constructor
6917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6918#[cfg_attr(feature = "bindings", derive(TS))]
6919pub struct StructConstructor {
6920    pub fields: Vec<(Option<Identifier>, Expression)>,
6921}
6922
6923/// STRUCT_EXTRACT function
6924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6925#[cfg_attr(feature = "bindings", derive(TS))]
6926pub struct StructExtractFunc {
6927    pub this: Expression,
6928    pub field: Identifier,
6929}
6930
6931/// NAMED_STRUCT function
6932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6933#[cfg_attr(feature = "bindings", derive(TS))]
6934pub struct NamedStructFunc {
6935    pub pairs: Vec<(Expression, Expression)>,
6936}
6937
6938// ============================================================================
6939// Map Function types
6940// ============================================================================
6941
6942/// MAP constructor
6943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6944#[cfg_attr(feature = "bindings", derive(TS))]
6945pub struct MapConstructor {
6946    pub keys: Vec<Expression>,
6947    pub values: Vec<Expression>,
6948    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6949    #[serde(default)]
6950    pub curly_brace_syntax: bool,
6951    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6952    #[serde(default)]
6953    pub with_map_keyword: bool,
6954}
6955
6956/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6958#[cfg_attr(feature = "bindings", derive(TS))]
6959pub struct TransformFunc {
6960    pub this: Expression,
6961    pub transform: Expression,
6962}
6963
6964/// Function call with EMITS clause (Exasol)
6965/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6967#[cfg_attr(feature = "bindings", derive(TS))]
6968pub struct FunctionEmits {
6969    /// The function call expression
6970    pub this: Expression,
6971    /// The EMITS schema definition
6972    pub emits: Expression,
6973}
6974
6975// ============================================================================
6976// JSON Function types
6977// ============================================================================
6978
6979/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6981#[cfg_attr(feature = "bindings", derive(TS))]
6982pub struct JsonExtractFunc {
6983    pub this: Expression,
6984    pub path: Expression,
6985    pub returning: Option<DataType>,
6986    /// True if parsed from -> or ->> operator syntax
6987    #[serde(default)]
6988    pub arrow_syntax: bool,
6989    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6990    #[serde(default)]
6991    pub hash_arrow_syntax: bool,
6992    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6993    #[serde(default)]
6994    pub wrapper_option: Option<String>,
6995    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6996    #[serde(default)]
6997    pub quotes_option: Option<String>,
6998    /// ON SCALAR STRING flag
6999    #[serde(default)]
7000    pub on_scalar_string: bool,
7001    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
7002    #[serde(default)]
7003    pub on_error: Option<String>,
7004}
7005
7006/// JSON path extraction
7007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7008#[cfg_attr(feature = "bindings", derive(TS))]
7009pub struct JsonPathFunc {
7010    pub this: Expression,
7011    pub paths: Vec<Expression>,
7012}
7013
7014/// JSON_OBJECT function
7015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7016#[cfg_attr(feature = "bindings", derive(TS))]
7017pub struct JsonObjectFunc {
7018    pub pairs: Vec<(Expression, Expression)>,
7019    pub null_handling: Option<JsonNullHandling>,
7020    #[serde(default)]
7021    pub with_unique_keys: bool,
7022    #[serde(default)]
7023    pub returning_type: Option<DataType>,
7024    #[serde(default)]
7025    pub format_json: bool,
7026    #[serde(default)]
7027    pub encoding: Option<String>,
7028    /// For JSON_OBJECT(*) syntax
7029    #[serde(default)]
7030    pub star: bool,
7031}
7032
7033/// JSON null handling options
7034#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7035#[cfg_attr(feature = "bindings", derive(TS))]
7036pub enum JsonNullHandling {
7037    NullOnNull,
7038    AbsentOnNull,
7039}
7040
7041/// JSON_SET / JSON_INSERT function
7042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7043#[cfg_attr(feature = "bindings", derive(TS))]
7044pub struct JsonModifyFunc {
7045    pub this: Expression,
7046    pub path_values: Vec<(Expression, Expression)>,
7047}
7048
7049/// JSON_ARRAYAGG function
7050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7051#[cfg_attr(feature = "bindings", derive(TS))]
7052pub struct JsonArrayAggFunc {
7053    pub this: Expression,
7054    pub order_by: Option<Vec<Ordered>>,
7055    pub null_handling: Option<JsonNullHandling>,
7056    pub filter: Option<Expression>,
7057}
7058
7059/// JSON_OBJECTAGG function
7060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7061#[cfg_attr(feature = "bindings", derive(TS))]
7062pub struct JsonObjectAggFunc {
7063    pub key: Expression,
7064    pub value: Expression,
7065    pub null_handling: Option<JsonNullHandling>,
7066    pub filter: Option<Expression>,
7067}
7068
7069// ============================================================================
7070// Type Casting Function types
7071// ============================================================================
7072
7073/// CONVERT function (SQL Server style)
7074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7075#[cfg_attr(feature = "bindings", derive(TS))]
7076pub struct ConvertFunc {
7077    pub this: Expression,
7078    pub to: DataType,
7079    pub style: Option<Expression>,
7080}
7081
7082// ============================================================================
7083// Additional Expression types
7084// ============================================================================
7085
7086/// Lambda expression
7087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7088#[cfg_attr(feature = "bindings", derive(TS))]
7089pub struct LambdaExpr {
7090    pub parameters: Vec<Identifier>,
7091    pub body: Expression,
7092    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7093    #[serde(default)]
7094    pub colon: bool,
7095    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7096    /// Maps parameter index to data type
7097    #[serde(default)]
7098    pub parameter_types: Vec<Option<DataType>>,
7099}
7100
7101/// Parameter (parameterized queries)
7102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7103#[cfg_attr(feature = "bindings", derive(TS))]
7104pub struct Parameter {
7105    pub name: Option<String>,
7106    pub index: Option<u32>,
7107    pub style: ParameterStyle,
7108    /// Whether the name was quoted (e.g., @"x" vs @x)
7109    #[serde(default)]
7110    pub quoted: bool,
7111    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7112    #[serde(default)]
7113    pub string_quoted: bool,
7114    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7115    #[serde(default)]
7116    pub expression: Option<String>,
7117}
7118
7119/// Parameter placeholder styles
7120#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7121#[cfg_attr(feature = "bindings", derive(TS))]
7122pub enum ParameterStyle {
7123    Question,     // ?
7124    Dollar,       // $1, $2
7125    DollarBrace,  // ${name} (Databricks, Hive template variables)
7126    Brace,        // {name} (Spark/Databricks widget/template variables)
7127    Colon,        // :name
7128    At,           // @name
7129    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7130    DoubleDollar, // $$name
7131    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7132}
7133
7134/// Placeholder expression
7135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7136#[cfg_attr(feature = "bindings", derive(TS))]
7137pub struct Placeholder {
7138    pub index: Option<u32>,
7139}
7140
7141/// Named argument in function call: name => value or name := value
7142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7143#[cfg_attr(feature = "bindings", derive(TS))]
7144pub struct NamedArgument {
7145    pub name: Identifier,
7146    pub value: Expression,
7147    /// The separator used: `=>`, `:=`, or `=`
7148    pub separator: NamedArgSeparator,
7149}
7150
7151/// Separator style for named arguments
7152#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub enum NamedArgSeparator {
7155    /// `=>` (standard SQL, Snowflake, BigQuery)
7156    DArrow,
7157    /// `:=` (Oracle, MySQL)
7158    ColonEq,
7159    /// `=` (simple equals, some dialects)
7160    Eq,
7161}
7162
7163/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7164/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7166#[cfg_attr(feature = "bindings", derive(TS))]
7167pub struct TableArgument {
7168    /// The keyword prefix: "TABLE" or "MODEL"
7169    pub prefix: String,
7170    /// The table/model reference expression
7171    pub this: Expression,
7172}
7173
7174/// SQL Comment preservation
7175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7176#[cfg_attr(feature = "bindings", derive(TS))]
7177pub struct SqlComment {
7178    pub text: String,
7179    pub is_block: bool,
7180}
7181
7182// ============================================================================
7183// Additional Predicate types
7184// ============================================================================
7185
7186/// SIMILAR TO expression
7187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7188#[cfg_attr(feature = "bindings", derive(TS))]
7189pub struct SimilarToExpr {
7190    pub this: Expression,
7191    pub pattern: Expression,
7192    pub escape: Option<Expression>,
7193    pub not: bool,
7194}
7195
7196/// ANY / ALL quantified expression
7197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7198#[cfg_attr(feature = "bindings", derive(TS))]
7199pub struct QuantifiedExpr {
7200    pub this: Expression,
7201    pub subquery: Expression,
7202    pub op: Option<QuantifiedOp>,
7203}
7204
7205/// Comparison operator for quantified expressions
7206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7207#[cfg_attr(feature = "bindings", derive(TS))]
7208pub enum QuantifiedOp {
7209    Eq,
7210    Neq,
7211    Lt,
7212    Lte,
7213    Gt,
7214    Gte,
7215}
7216
7217/// OVERLAPS expression
7218/// Supports two forms:
7219/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7220/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7222#[cfg_attr(feature = "bindings", derive(TS))]
7223pub struct OverlapsExpr {
7224    /// Left operand for simple binary form
7225    #[serde(skip_serializing_if = "Option::is_none")]
7226    pub this: Option<Expression>,
7227    /// Right operand for simple binary form
7228    #[serde(skip_serializing_if = "Option::is_none")]
7229    pub expression: Option<Expression>,
7230    /// Left range start for full ANSI form
7231    #[serde(skip_serializing_if = "Option::is_none")]
7232    pub left_start: Option<Expression>,
7233    /// Left range end for full ANSI form
7234    #[serde(skip_serializing_if = "Option::is_none")]
7235    pub left_end: Option<Expression>,
7236    /// Right range start for full ANSI form
7237    #[serde(skip_serializing_if = "Option::is_none")]
7238    pub right_start: Option<Expression>,
7239    /// Right range end for full ANSI form
7240    #[serde(skip_serializing_if = "Option::is_none")]
7241    pub right_end: Option<Expression>,
7242}
7243
7244// ============================================================================
7245// Array/Struct/Map access
7246// ============================================================================
7247
7248/// Subscript access (array[index] or map[key])
7249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7250#[cfg_attr(feature = "bindings", derive(TS))]
7251pub struct Subscript {
7252    pub this: Expression,
7253    pub index: Expression,
7254}
7255
7256/// Dot access (struct.field)
7257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7258#[cfg_attr(feature = "bindings", derive(TS))]
7259pub struct DotAccess {
7260    pub this: Expression,
7261    pub field: Identifier,
7262}
7263
7264/// Method call (expr.method(args))
7265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7266#[cfg_attr(feature = "bindings", derive(TS))]
7267pub struct MethodCall {
7268    pub this: Expression,
7269    pub method: Identifier,
7270    pub args: Vec<Expression>,
7271}
7272
7273/// Array slice (array[start:end])
7274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7275#[cfg_attr(feature = "bindings", derive(TS))]
7276pub struct ArraySlice {
7277    pub this: Expression,
7278    pub start: Option<Expression>,
7279    pub end: Option<Expression>,
7280}
7281
7282// ============================================================================
7283// DDL (Data Definition Language) Statements
7284// ============================================================================
7285
7286/// ON COMMIT behavior for temporary tables
7287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7288#[cfg_attr(feature = "bindings", derive(TS))]
7289pub enum OnCommit {
7290    /// ON COMMIT PRESERVE ROWS
7291    PreserveRows,
7292    /// ON COMMIT DELETE ROWS
7293    DeleteRows,
7294}
7295
7296/// CREATE TABLE statement
7297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7298#[cfg_attr(feature = "bindings", derive(TS))]
7299pub struct CreateTable {
7300    pub name: TableRef,
7301    /// ClickHouse: ON CLUSTER clause for distributed DDL
7302    #[serde(default, skip_serializing_if = "Option::is_none")]
7303    pub on_cluster: Option<OnCluster>,
7304    pub columns: Vec<ColumnDef>,
7305    pub constraints: Vec<TableConstraint>,
7306    pub if_not_exists: bool,
7307    pub temporary: bool,
7308    pub or_replace: bool,
7309    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7310    #[serde(default, skip_serializing_if = "Option::is_none")]
7311    pub table_modifier: Option<String>,
7312    pub as_select: Option<Expression>,
7313    /// Whether the AS SELECT was wrapped in parentheses
7314    #[serde(default)]
7315    pub as_select_parenthesized: bool,
7316    /// ON COMMIT behavior for temporary tables
7317    #[serde(default)]
7318    pub on_commit: Option<OnCommit>,
7319    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7320    #[serde(default)]
7321    pub clone_source: Option<TableRef>,
7322    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7323    #[serde(default, skip_serializing_if = "Option::is_none")]
7324    pub clone_at_clause: Option<Expression>,
7325    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7326    #[serde(default)]
7327    pub is_copy: bool,
7328    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7329    #[serde(default)]
7330    pub shallow_clone: bool,
7331    /// Whether this is an explicit DEEP CLONE (Databricks/Delta Lake)
7332    #[serde(default)]
7333    pub deep_clone: bool,
7334    /// Leading comments before the statement
7335    #[serde(default)]
7336    pub leading_comments: Vec<String>,
7337    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7338    #[serde(default)]
7339    pub with_properties: Vec<(String, String)>,
7340    /// Teradata: table options after name before columns (comma-separated)
7341    #[serde(default)]
7342    pub teradata_post_name_options: Vec<String>,
7343    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7344    #[serde(default)]
7345    pub with_data: Option<bool>,
7346    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7347    #[serde(default)]
7348    pub with_statistics: Option<bool>,
7349    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7350    #[serde(default)]
7351    pub teradata_indexes: Vec<TeradataIndex>,
7352    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7353    #[serde(default)]
7354    pub with_cte: Option<With>,
7355    /// Table properties like DEFAULT COLLATE (BigQuery)
7356    #[serde(default)]
7357    pub properties: Vec<Expression>,
7358    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7359    #[serde(default, skip_serializing_if = "Option::is_none")]
7360    pub partition_of: Option<Expression>,
7361    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7362    #[serde(default)]
7363    pub post_table_properties: Vec<Expression>,
7364    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7365    #[serde(default)]
7366    pub mysql_table_options: Vec<(String, String)>,
7367    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7368    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7369    pub inherits: Vec<TableRef>,
7370    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7371    #[serde(default, skip_serializing_if = "Option::is_none")]
7372    pub on_property: Option<OnProperty>,
7373    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7374    #[serde(default)]
7375    pub copy_grants: bool,
7376    /// Snowflake: USING TEMPLATE expression for schema inference
7377    #[serde(default, skip_serializing_if = "Option::is_none")]
7378    pub using_template: Option<Box<Expression>>,
7379    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7380    #[serde(default, skip_serializing_if = "Option::is_none")]
7381    pub rollup: Option<RollupProperty>,
7382    /// ClickHouse: UUID 'xxx' clause after table name
7383    #[serde(default, skip_serializing_if = "Option::is_none")]
7384    pub uuid: Option<String>,
7385    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7386    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7387    /// could appear in other engines.
7388    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7389    pub with_partition_columns: Vec<ColumnDef>,
7390    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7391    /// for external tables that reference a Cloud Resource connection.
7392    #[serde(default, skip_serializing_if = "Option::is_none")]
7393    pub with_connection: Option<TableRef>,
7394}
7395
7396/// Teradata index specification for CREATE TABLE
7397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7398#[cfg_attr(feature = "bindings", derive(TS))]
7399pub struct TeradataIndex {
7400    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7401    pub kind: TeradataIndexKind,
7402    /// Optional index name
7403    pub name: Option<String>,
7404    /// Optional column list
7405    pub columns: Vec<String>,
7406}
7407
7408/// Kind of Teradata index
7409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7410#[cfg_attr(feature = "bindings", derive(TS))]
7411pub enum TeradataIndexKind {
7412    /// NO PRIMARY INDEX
7413    NoPrimary,
7414    /// PRIMARY INDEX
7415    Primary,
7416    /// PRIMARY AMP INDEX
7417    PrimaryAmp,
7418    /// UNIQUE INDEX
7419    Unique,
7420    /// UNIQUE PRIMARY INDEX
7421    UniquePrimary,
7422    /// INDEX (secondary, non-primary)
7423    Secondary,
7424}
7425
7426impl CreateTable {
7427    pub fn new(name: impl Into<String>) -> Self {
7428        Self {
7429            name: TableRef::new(name),
7430            on_cluster: None,
7431            columns: Vec::new(),
7432            constraints: Vec::new(),
7433            if_not_exists: false,
7434            temporary: false,
7435            or_replace: false,
7436            table_modifier: None,
7437            as_select: None,
7438            as_select_parenthesized: false,
7439            on_commit: None,
7440            clone_source: None,
7441            clone_at_clause: None,
7442            shallow_clone: false,
7443            deep_clone: false,
7444            is_copy: false,
7445            leading_comments: Vec::new(),
7446            with_properties: Vec::new(),
7447            teradata_post_name_options: Vec::new(),
7448            with_data: None,
7449            with_statistics: None,
7450            teradata_indexes: Vec::new(),
7451            with_cte: None,
7452            properties: Vec::new(),
7453            partition_of: None,
7454            post_table_properties: Vec::new(),
7455            mysql_table_options: Vec::new(),
7456            inherits: Vec::new(),
7457            on_property: None,
7458            copy_grants: false,
7459            using_template: None,
7460            rollup: None,
7461            uuid: None,
7462            with_partition_columns: Vec::new(),
7463            with_connection: None,
7464        }
7465    }
7466}
7467
7468/// Sort order for PRIMARY KEY ASC/DESC
7469#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7470#[cfg_attr(feature = "bindings", derive(TS))]
7471pub enum SortOrder {
7472    Asc,
7473    Desc,
7474}
7475
7476/// Type of column constraint for tracking order
7477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7478#[cfg_attr(feature = "bindings", derive(TS))]
7479pub enum ConstraintType {
7480    NotNull,
7481    Null,
7482    PrimaryKey,
7483    Unique,
7484    Default,
7485    AutoIncrement,
7486    Collate,
7487    Comment,
7488    References,
7489    Check,
7490    GeneratedAsIdentity,
7491    /// Snowflake: TAG (key='value', ...)
7492    Tags,
7493    /// Computed/generated column
7494    ComputedColumn,
7495    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7496    GeneratedAsRow,
7497    /// MySQL: ON UPDATE expression
7498    OnUpdate,
7499    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7500    Path,
7501    /// Redshift: ENCODE encoding_type
7502    Encode,
7503}
7504
7505/// Column definition in CREATE TABLE
7506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7507#[cfg_attr(feature = "bindings", derive(TS))]
7508pub struct ColumnDef {
7509    pub name: Identifier,
7510    pub data_type: DataType,
7511    pub nullable: Option<bool>,
7512    pub default: Option<Expression>,
7513    pub primary_key: bool,
7514    /// Sort order for PRIMARY KEY (ASC/DESC)
7515    #[serde(default)]
7516    pub primary_key_order: Option<SortOrder>,
7517    pub unique: bool,
7518    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7519    #[serde(default)]
7520    pub unique_nulls_not_distinct: bool,
7521    pub auto_increment: bool,
7522    pub comment: Option<String>,
7523    pub constraints: Vec<ColumnConstraint>,
7524    /// Track original order of constraints for accurate regeneration
7525    #[serde(default)]
7526    pub constraint_order: Vec<ConstraintType>,
7527    /// Teradata: FORMAT 'pattern'
7528    #[serde(default)]
7529    pub format: Option<String>,
7530    /// Teradata: TITLE 'title'
7531    #[serde(default)]
7532    pub title: Option<String>,
7533    /// Teradata: INLINE LENGTH n
7534    #[serde(default)]
7535    pub inline_length: Option<u64>,
7536    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7537    #[serde(default)]
7538    pub compress: Option<Vec<Expression>>,
7539    /// Teradata: CHARACTER SET name
7540    #[serde(default)]
7541    pub character_set: Option<String>,
7542    /// Teradata: UPPERCASE
7543    #[serde(default)]
7544    pub uppercase: bool,
7545    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7546    #[serde(default)]
7547    pub casespecific: Option<bool>,
7548    /// Snowflake: AUTOINCREMENT START value
7549    #[serde(default)]
7550    pub auto_increment_start: Option<Box<Expression>>,
7551    /// Snowflake: AUTOINCREMENT INCREMENT value
7552    #[serde(default)]
7553    pub auto_increment_increment: Option<Box<Expression>>,
7554    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7555    #[serde(default)]
7556    pub auto_increment_order: Option<bool>,
7557    /// MySQL: UNSIGNED modifier
7558    #[serde(default)]
7559    pub unsigned: bool,
7560    /// MySQL: ZEROFILL modifier
7561    #[serde(default)]
7562    pub zerofill: bool,
7563    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7564    #[serde(default, skip_serializing_if = "Option::is_none")]
7565    pub on_update: Option<Expression>,
7566    /// MySQL: column VISIBLE/INVISIBLE modifier.
7567    #[serde(default, skip_serializing_if = "Option::is_none")]
7568    pub visible: Option<bool>,
7569    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7570    #[serde(default, skip_serializing_if = "Option::is_none")]
7571    pub unique_constraint_name: Option<String>,
7572    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7573    #[serde(default, skip_serializing_if = "Option::is_none")]
7574    pub not_null_constraint_name: Option<String>,
7575    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7576    #[serde(default, skip_serializing_if = "Option::is_none")]
7577    pub primary_key_constraint_name: Option<String>,
7578    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7579    #[serde(default, skip_serializing_if = "Option::is_none")]
7580    pub check_constraint_name: Option<String>,
7581    /// BigQuery: OPTIONS (key=value, ...) on column
7582    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7583    pub options: Vec<Expression>,
7584    /// SQLite: Column definition without explicit type
7585    #[serde(default)]
7586    pub no_type: bool,
7587    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7588    #[serde(default, skip_serializing_if = "Option::is_none")]
7589    pub encoding: Option<String>,
7590    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7591    #[serde(default, skip_serializing_if = "Option::is_none")]
7592    pub codec: Option<String>,
7593    /// ClickHouse: EPHEMERAL [expr] modifier
7594    #[serde(default, skip_serializing_if = "Option::is_none")]
7595    pub ephemeral: Option<Option<Box<Expression>>>,
7596    /// ClickHouse: MATERIALIZED expr modifier
7597    #[serde(default, skip_serializing_if = "Option::is_none")]
7598    pub materialized_expr: Option<Box<Expression>>,
7599    /// ClickHouse: ALIAS expr modifier
7600    #[serde(default, skip_serializing_if = "Option::is_none")]
7601    pub alias_expr: Option<Box<Expression>>,
7602    /// ClickHouse: TTL expr modifier on columns
7603    #[serde(default, skip_serializing_if = "Option::is_none")]
7604    pub ttl_expr: Option<Box<Expression>>,
7605    /// TSQL: NOT FOR REPLICATION
7606    #[serde(default)]
7607    pub not_for_replication: bool,
7608}
7609
7610impl ColumnDef {
7611    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7612        Self {
7613            name: Identifier::new(name),
7614            data_type,
7615            nullable: None,
7616            default: None,
7617            primary_key: false,
7618            primary_key_order: None,
7619            unique: false,
7620            unique_nulls_not_distinct: false,
7621            auto_increment: false,
7622            comment: None,
7623            constraints: Vec::new(),
7624            constraint_order: Vec::new(),
7625            format: None,
7626            title: None,
7627            inline_length: None,
7628            compress: None,
7629            character_set: None,
7630            uppercase: false,
7631            casespecific: None,
7632            auto_increment_start: None,
7633            auto_increment_increment: None,
7634            auto_increment_order: None,
7635            unsigned: false,
7636            zerofill: false,
7637            on_update: None,
7638            visible: None,
7639            unique_constraint_name: None,
7640            not_null_constraint_name: None,
7641            primary_key_constraint_name: None,
7642            check_constraint_name: None,
7643            options: Vec::new(),
7644            no_type: false,
7645            encoding: None,
7646            codec: None,
7647            ephemeral: None,
7648            materialized_expr: None,
7649            alias_expr: None,
7650            ttl_expr: None,
7651            not_for_replication: false,
7652        }
7653    }
7654}
7655
7656/// Column-level constraint
7657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7658#[cfg_attr(feature = "bindings", derive(TS))]
7659pub enum ColumnConstraint {
7660    NotNull,
7661    Null,
7662    Unique,
7663    PrimaryKey,
7664    Default(Expression),
7665    Check(Expression),
7666    References(ForeignKeyRef),
7667    GeneratedAsIdentity(GeneratedAsIdentity),
7668    Collate(Identifier),
7669    Comment(String),
7670    /// Snowflake: TAG (key='value', ...)
7671    Tags(Tags),
7672    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7673    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7674    ComputedColumn(ComputedColumn),
7675    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7676    GeneratedAsRow(GeneratedAsRow),
7677    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7678    Path(Expression),
7679}
7680
7681/// Computed/generated column constraint
7682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7683#[cfg_attr(feature = "bindings", derive(TS))]
7684pub struct ComputedColumn {
7685    /// The expression that computes the column value
7686    pub expression: Box<Expression>,
7687    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7688    #[serde(default)]
7689    pub persisted: bool,
7690    /// NOT NULL (TSQL computed columns)
7691    #[serde(default)]
7692    pub not_null: bool,
7693    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7694    /// When None, defaults to dialect-appropriate output
7695    #[serde(default)]
7696    pub persistence_kind: Option<String>,
7697    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7698    #[serde(default, skip_serializing_if = "Option::is_none")]
7699    pub data_type: Option<DataType>,
7700}
7701
7702/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7704#[cfg_attr(feature = "bindings", derive(TS))]
7705pub struct GeneratedAsRow {
7706    /// true = ROW START, false = ROW END
7707    pub start: bool,
7708    /// HIDDEN modifier
7709    #[serde(default)]
7710    pub hidden: bool,
7711}
7712
7713/// Generated identity column constraint
7714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7715#[cfg_attr(feature = "bindings", derive(TS))]
7716pub struct GeneratedAsIdentity {
7717    /// True for ALWAYS, False for BY DEFAULT
7718    pub always: bool,
7719    /// ON NULL (only valid with BY DEFAULT)
7720    pub on_null: bool,
7721    /// START WITH value
7722    pub start: Option<Box<Expression>>,
7723    /// INCREMENT BY value
7724    pub increment: Option<Box<Expression>>,
7725    /// MINVALUE
7726    pub minvalue: Option<Box<Expression>>,
7727    /// MAXVALUE
7728    pub maxvalue: Option<Box<Expression>>,
7729    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7730    pub cycle: Option<bool>,
7731}
7732
7733/// Constraint modifiers (shared between table-level constraints)
7734#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7735#[cfg_attr(feature = "bindings", derive(TS))]
7736pub struct ConstraintModifiers {
7737    /// ENFORCED / NOT ENFORCED
7738    pub enforced: Option<bool>,
7739    /// DEFERRABLE / NOT DEFERRABLE
7740    pub deferrable: Option<bool>,
7741    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7742    pub initially_deferred: Option<bool>,
7743    /// NORELY (Oracle)
7744    pub norely: bool,
7745    /// RELY (Oracle)
7746    pub rely: bool,
7747    /// USING index type (MySQL): BTREE or HASH
7748    #[serde(default)]
7749    pub using: Option<String>,
7750    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7751    #[serde(default)]
7752    pub using_before_columns: bool,
7753    /// MySQL index COMMENT 'text'
7754    #[serde(default, skip_serializing_if = "Option::is_none")]
7755    pub comment: Option<String>,
7756    /// MySQL index VISIBLE/INVISIBLE
7757    #[serde(default, skip_serializing_if = "Option::is_none")]
7758    pub visible: Option<bool>,
7759    /// MySQL ENGINE_ATTRIBUTE = 'value'
7760    #[serde(default, skip_serializing_if = "Option::is_none")]
7761    pub engine_attribute: Option<String>,
7762    /// MySQL WITH PARSER name
7763    #[serde(default, skip_serializing_if = "Option::is_none")]
7764    pub with_parser: Option<String>,
7765    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7766    #[serde(default)]
7767    pub not_valid: bool,
7768    /// TSQL CLUSTERED/NONCLUSTERED modifier
7769    #[serde(default, skip_serializing_if = "Option::is_none")]
7770    pub clustered: Option<String>,
7771    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7772    #[serde(default, skip_serializing_if = "Option::is_none")]
7773    pub on_conflict: Option<String>,
7774    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7775    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7776    pub with_options: Vec<(String, String)>,
7777    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7778    #[serde(default, skip_serializing_if = "Option::is_none")]
7779    pub on_filegroup: Option<Identifier>,
7780}
7781
7782/// Table-level constraint
7783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7784#[cfg_attr(feature = "bindings", derive(TS))]
7785pub enum TableConstraint {
7786    PrimaryKey {
7787        name: Option<Identifier>,
7788        columns: Vec<Identifier>,
7789        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7790        #[serde(default)]
7791        include_columns: Vec<Identifier>,
7792        #[serde(default)]
7793        modifiers: ConstraintModifiers,
7794        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7795        #[serde(default)]
7796        has_constraint_keyword: bool,
7797    },
7798    Unique {
7799        name: Option<Identifier>,
7800        columns: Vec<Identifier>,
7801        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7802        #[serde(default)]
7803        columns_parenthesized: bool,
7804        #[serde(default)]
7805        modifiers: ConstraintModifiers,
7806        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7807        #[serde(default)]
7808        has_constraint_keyword: bool,
7809        /// PostgreSQL 15+: NULLS NOT DISTINCT
7810        #[serde(default)]
7811        nulls_not_distinct: bool,
7812    },
7813    ForeignKey {
7814        name: Option<Identifier>,
7815        columns: Vec<Identifier>,
7816        #[serde(default)]
7817        references: Option<ForeignKeyRef>,
7818        /// ON DELETE action when REFERENCES is absent
7819        #[serde(default)]
7820        on_delete: Option<ReferentialAction>,
7821        /// ON UPDATE action when REFERENCES is absent
7822        #[serde(default)]
7823        on_update: Option<ReferentialAction>,
7824        #[serde(default)]
7825        modifiers: ConstraintModifiers,
7826    },
7827    Check {
7828        name: Option<Identifier>,
7829        expression: Expression,
7830        #[serde(default)]
7831        modifiers: ConstraintModifiers,
7832    },
7833    /// ClickHouse ASSUME constraint (query optimization assumption)
7834    Assume {
7835        name: Option<Identifier>,
7836        expression: Expression,
7837    },
7838    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7839    Default {
7840        name: Option<Identifier>,
7841        expression: Expression,
7842        column: Identifier,
7843    },
7844    /// INDEX / KEY constraint (MySQL)
7845    Index {
7846        name: Option<Identifier>,
7847        columns: Vec<Identifier>,
7848        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7849        #[serde(default)]
7850        kind: Option<String>,
7851        #[serde(default)]
7852        modifiers: ConstraintModifiers,
7853        /// True if KEY keyword was used instead of INDEX
7854        #[serde(default)]
7855        use_key_keyword: bool,
7856        /// ClickHouse: indexed expression (instead of columns)
7857        #[serde(default, skip_serializing_if = "Option::is_none")]
7858        expression: Option<Box<Expression>>,
7859        /// ClickHouse: TYPE type_func(args)
7860        #[serde(default, skip_serializing_if = "Option::is_none")]
7861        index_type: Option<Box<Expression>>,
7862        /// ClickHouse: GRANULARITY n
7863        #[serde(default, skip_serializing_if = "Option::is_none")]
7864        granularity: Option<Box<Expression>>,
7865    },
7866    /// ClickHouse PROJECTION definition
7867    Projection {
7868        name: Identifier,
7869        expression: Expression,
7870    },
7871    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7872    Like {
7873        source: TableRef,
7874        /// Options as (INCLUDING|EXCLUDING, property) pairs
7875        options: Vec<(LikeOptionAction, String)>,
7876    },
7877    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7878    PeriodForSystemTime {
7879        start_col: Identifier,
7880        end_col: Identifier,
7881    },
7882    /// PostgreSQL EXCLUDE constraint
7883    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7884    Exclude {
7885        name: Option<Identifier>,
7886        /// Index access method (gist, btree, etc.)
7887        #[serde(default)]
7888        using: Option<String>,
7889        /// Elements: (expression, operator) pairs
7890        elements: Vec<ExcludeElement>,
7891        /// INCLUDE columns
7892        #[serde(default)]
7893        include_columns: Vec<Identifier>,
7894        /// WHERE predicate
7895        #[serde(default)]
7896        where_clause: Option<Box<Expression>>,
7897        /// WITH (storage_parameters)
7898        #[serde(default)]
7899        with_params: Vec<(String, String)>,
7900        /// USING INDEX TABLESPACE tablespace_name
7901        #[serde(default)]
7902        using_index_tablespace: Option<String>,
7903        #[serde(default)]
7904        modifiers: ConstraintModifiers,
7905    },
7906    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7907    Tags(Tags),
7908    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7909    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7910    /// for all deferrable constraints in the table
7911    InitiallyDeferred {
7912        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7913        deferred: bool,
7914    },
7915}
7916
7917/// Element in an EXCLUDE constraint: expression WITH operator
7918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7919#[cfg_attr(feature = "bindings", derive(TS))]
7920pub struct ExcludeElement {
7921    /// The column expression (may include operator class, ordering, nulls)
7922    pub expression: String,
7923    /// The operator (e.g., &&, =)
7924    pub operator: String,
7925}
7926
7927/// Action for LIKE clause options
7928#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7929#[cfg_attr(feature = "bindings", derive(TS))]
7930pub enum LikeOptionAction {
7931    Including,
7932    Excluding,
7933}
7934
7935/// MATCH type for foreign keys
7936#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7937#[cfg_attr(feature = "bindings", derive(TS))]
7938pub enum MatchType {
7939    Full,
7940    Partial,
7941    Simple,
7942}
7943
7944/// Foreign key reference
7945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7946#[cfg_attr(feature = "bindings", derive(TS))]
7947pub struct ForeignKeyRef {
7948    pub table: TableRef,
7949    pub columns: Vec<Identifier>,
7950    pub on_delete: Option<ReferentialAction>,
7951    pub on_update: Option<ReferentialAction>,
7952    /// True if ON UPDATE appears before ON DELETE in the original SQL
7953    #[serde(default)]
7954    pub on_update_first: bool,
7955    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7956    #[serde(default)]
7957    pub match_type: Option<MatchType>,
7958    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7959    #[serde(default)]
7960    pub match_after_actions: bool,
7961    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7962    #[serde(default)]
7963    pub constraint_name: Option<String>,
7964    /// DEFERRABLE / NOT DEFERRABLE
7965    #[serde(default)]
7966    pub deferrable: Option<bool>,
7967    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7968    #[serde(default)]
7969    pub has_foreign_key_keywords: bool,
7970}
7971
7972/// Referential action for foreign keys
7973#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7974#[cfg_attr(feature = "bindings", derive(TS))]
7975pub enum ReferentialAction {
7976    Cascade,
7977    SetNull,
7978    SetDefault,
7979    Restrict,
7980    NoAction,
7981}
7982
7983/// DROP TABLE statement
7984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7985#[cfg_attr(feature = "bindings", derive(TS))]
7986pub struct DropTable {
7987    pub names: Vec<TableRef>,
7988    pub if_exists: bool,
7989    pub cascade: bool,
7990    /// Oracle: CASCADE CONSTRAINTS
7991    #[serde(default)]
7992    pub cascade_constraints: bool,
7993    /// Oracle: PURGE
7994    #[serde(default)]
7995    pub purge: bool,
7996    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7997    #[serde(default)]
7998    pub leading_comments: Vec<String>,
7999    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
8000    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
8001    #[serde(default, skip_serializing_if = "Option::is_none")]
8002    pub object_id_args: Option<String>,
8003    /// ClickHouse: SYNC modifier
8004    #[serde(default)]
8005    pub sync: bool,
8006    /// Snowflake: DROP ICEBERG TABLE
8007    #[serde(default)]
8008    pub iceberg: bool,
8009    /// RESTRICT modifier (opposite of CASCADE)
8010    #[serde(default)]
8011    pub restrict: bool,
8012}
8013
8014impl DropTable {
8015    pub fn new(name: impl Into<String>) -> Self {
8016        Self {
8017            names: vec![TableRef::new(name)],
8018            if_exists: false,
8019            cascade: false,
8020            cascade_constraints: false,
8021            purge: false,
8022            leading_comments: Vec::new(),
8023            object_id_args: None,
8024            sync: false,
8025            iceberg: false,
8026            restrict: false,
8027        }
8028    }
8029}
8030
8031/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
8032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8033#[cfg_attr(feature = "bindings", derive(TS))]
8034pub struct Undrop {
8035    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
8036    pub kind: String,
8037    /// The object name
8038    pub name: TableRef,
8039    /// IF EXISTS clause
8040    #[serde(default)]
8041    pub if_exists: bool,
8042}
8043
8044/// ALTER TABLE statement
8045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8046#[cfg_attr(feature = "bindings", derive(TS))]
8047pub struct AlterTable {
8048    pub name: TableRef,
8049    pub actions: Vec<AlterTableAction>,
8050    /// IF EXISTS clause
8051    #[serde(default)]
8052    pub if_exists: bool,
8053    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8054    #[serde(default, skip_serializing_if = "Option::is_none")]
8055    pub algorithm: Option<String>,
8056    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8057    #[serde(default, skip_serializing_if = "Option::is_none")]
8058    pub lock: Option<String>,
8059    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8060    #[serde(default, skip_serializing_if = "Option::is_none")]
8061    pub with_check: Option<String>,
8062    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8063    #[serde(default, skip_serializing_if = "Option::is_none")]
8064    pub partition: Option<Vec<(Identifier, Expression)>>,
8065    /// ClickHouse: ON CLUSTER clause for distributed DDL
8066    #[serde(default, skip_serializing_if = "Option::is_none")]
8067    pub on_cluster: Option<OnCluster>,
8068    /// Snowflake: ALTER ICEBERG TABLE
8069    #[serde(default, skip_serializing_if = "Option::is_none")]
8070    pub table_modifier: Option<String>,
8071}
8072
8073impl AlterTable {
8074    pub fn new(name: impl Into<String>) -> Self {
8075        Self {
8076            name: TableRef::new(name),
8077            actions: Vec::new(),
8078            if_exists: false,
8079            algorithm: None,
8080            lock: None,
8081            with_check: None,
8082            partition: None,
8083            on_cluster: None,
8084            table_modifier: None,
8085        }
8086    }
8087}
8088
8089/// Column position for ADD COLUMN (MySQL/MariaDB)
8090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8091#[cfg_attr(feature = "bindings", derive(TS))]
8092pub enum ColumnPosition {
8093    First,
8094    After(Identifier),
8095}
8096
8097/// Actions for ALTER TABLE
8098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8099#[cfg_attr(feature = "bindings", derive(TS))]
8100pub enum AlterTableAction {
8101    AddColumn {
8102        column: ColumnDef,
8103        if_not_exists: bool,
8104        position: Option<ColumnPosition>,
8105    },
8106    DropColumn {
8107        name: Identifier,
8108        if_exists: bool,
8109        cascade: bool,
8110    },
8111    RenameColumn {
8112        old_name: Identifier,
8113        new_name: Identifier,
8114        if_exists: bool,
8115    },
8116    AlterColumn {
8117        name: Identifier,
8118        action: AlterColumnAction,
8119        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8120        #[serde(default)]
8121        use_modify_keyword: bool,
8122    },
8123    RenameTable(TableRef),
8124    AddConstraint(TableConstraint),
8125    DropConstraint {
8126        name: Identifier,
8127        if_exists: bool,
8128    },
8129    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8130    DropForeignKey {
8131        name: Identifier,
8132    },
8133    /// DROP PARTITION action (Hive/BigQuery)
8134    DropPartition {
8135        /// List of partitions to drop (each partition is a list of key=value pairs)
8136        partitions: Vec<Vec<(Identifier, Expression)>>,
8137        if_exists: bool,
8138    },
8139    /// ADD PARTITION action (Hive/Spark)
8140    AddPartition {
8141        /// The partition expression
8142        partition: Expression,
8143        if_not_exists: bool,
8144        location: Option<Expression>,
8145    },
8146    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8147    Delete {
8148        where_clause: Expression,
8149    },
8150    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8151    SwapWith(TableRef),
8152    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8153    SetProperty {
8154        properties: Vec<(String, Expression)>,
8155    },
8156    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8157    UnsetProperty {
8158        properties: Vec<String>,
8159    },
8160    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8161    ClusterBy {
8162        expressions: Vec<Expression>,
8163    },
8164    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8165    SetTag {
8166        expressions: Vec<(String, Expression)>,
8167    },
8168    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8169    UnsetTag {
8170        names: Vec<String>,
8171    },
8172    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8173    SetOptions {
8174        expressions: Vec<Expression>,
8175    },
8176    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8177    AlterIndex {
8178        name: Identifier,
8179        visible: bool,
8180    },
8181    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8182    SetAttribute {
8183        attribute: String,
8184    },
8185    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8186    SetStageFileFormat {
8187        options: Option<Expression>,
8188    },
8189    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8190    SetStageCopyOptions {
8191        options: Option<Expression>,
8192    },
8193    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8194    AddColumns {
8195        columns: Vec<ColumnDef>,
8196        cascade: bool,
8197    },
8198    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8199    DropColumns {
8200        names: Vec<Identifier>,
8201    },
8202    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8203    /// In SingleStore, data_type can be omitted for simple column renames
8204    ChangeColumn {
8205        old_name: Identifier,
8206        new_name: Identifier,
8207        #[serde(default, skip_serializing_if = "Option::is_none")]
8208        data_type: Option<DataType>,
8209        comment: Option<String>,
8210        #[serde(default)]
8211        cascade: bool,
8212    },
8213    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8214    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8215    AlterSortKey {
8216        /// AUTO or NONE keyword
8217        this: Option<String>,
8218        /// Column list for (col1, col2) syntax
8219        expressions: Vec<Expression>,
8220        /// Whether COMPOUND keyword was present
8221        compound: bool,
8222    },
8223    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8224    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8225    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8226    AlterDistStyle {
8227        /// Distribution style: ALL, EVEN, AUTO, or KEY
8228        style: String,
8229        /// DISTKEY column (only when style is KEY)
8230        distkey: Option<Identifier>,
8231    },
8232    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8233    SetTableProperties {
8234        properties: Vec<(Expression, Expression)>,
8235    },
8236    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8237    SetLocation {
8238        location: String,
8239    },
8240    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8241    SetFileFormat {
8242        format: String,
8243    },
8244    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8245    ReplacePartition {
8246        partition: Expression,
8247        source: Option<Box<Expression>>,
8248    },
8249    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8250    Raw {
8251        sql: String,
8252    },
8253}
8254
8255/// Actions for ALTER COLUMN
8256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8257#[cfg_attr(feature = "bindings", derive(TS))]
8258pub enum AlterColumnAction {
8259    SetDataType {
8260        data_type: DataType,
8261        /// USING expression for type conversion (PostgreSQL)
8262        using: Option<Expression>,
8263        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8264        #[serde(default, skip_serializing_if = "Option::is_none")]
8265        collate: Option<String>,
8266    },
8267    SetDefault(Expression),
8268    DropDefault,
8269    SetNotNull,
8270    DropNotNull,
8271    /// Set column comment
8272    Comment(String),
8273    /// MySQL: SET VISIBLE
8274    SetVisible,
8275    /// MySQL: SET INVISIBLE
8276    SetInvisible,
8277}
8278
8279/// CREATE INDEX statement
8280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8281#[cfg_attr(feature = "bindings", derive(TS))]
8282pub struct CreateIndex {
8283    pub name: Identifier,
8284    pub table: TableRef,
8285    pub columns: Vec<IndexColumn>,
8286    pub unique: bool,
8287    pub if_not_exists: bool,
8288    pub using: Option<String>,
8289    /// TSQL CLUSTERED/NONCLUSTERED modifier
8290    #[serde(default)]
8291    pub clustered: Option<String>,
8292    /// PostgreSQL CONCURRENTLY modifier
8293    #[serde(default)]
8294    pub concurrently: bool,
8295    /// PostgreSQL WHERE clause for partial indexes
8296    #[serde(default)]
8297    pub where_clause: Option<Box<Expression>>,
8298    /// PostgreSQL INCLUDE columns
8299    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8300    pub include_columns: Vec<Identifier>,
8301    /// TSQL WITH options (e.g., allow_page_locks=on)
8302    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8303    pub with_options: Vec<(String, String)>,
8304    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8305    #[serde(default)]
8306    pub on_filegroup: Option<String>,
8307}
8308
8309impl CreateIndex {
8310    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8311        Self {
8312            name: Identifier::new(name),
8313            table: TableRef::new(table),
8314            columns: Vec::new(),
8315            unique: false,
8316            if_not_exists: false,
8317            using: None,
8318            clustered: None,
8319            concurrently: false,
8320            where_clause: None,
8321            include_columns: Vec::new(),
8322            with_options: Vec::new(),
8323            on_filegroup: None,
8324        }
8325    }
8326}
8327
8328/// Index column specification
8329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8330#[cfg_attr(feature = "bindings", derive(TS))]
8331pub struct IndexColumn {
8332    pub column: Identifier,
8333    pub desc: bool,
8334    /// Explicit ASC keyword was present
8335    #[serde(default)]
8336    pub asc: bool,
8337    pub nulls_first: Option<bool>,
8338    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8339    #[serde(default, skip_serializing_if = "Option::is_none")]
8340    pub opclass: Option<String>,
8341}
8342
8343/// DROP INDEX statement
8344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8345#[cfg_attr(feature = "bindings", derive(TS))]
8346pub struct DropIndex {
8347    pub name: Identifier,
8348    pub table: Option<TableRef>,
8349    pub if_exists: bool,
8350    /// PostgreSQL CONCURRENTLY modifier
8351    #[serde(default)]
8352    pub concurrently: bool,
8353}
8354
8355impl DropIndex {
8356    pub fn new(name: impl Into<String>) -> Self {
8357        Self {
8358            name: Identifier::new(name),
8359            table: None,
8360            if_exists: false,
8361            concurrently: false,
8362        }
8363    }
8364}
8365
8366/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8368#[cfg_attr(feature = "bindings", derive(TS))]
8369pub struct ViewColumn {
8370    pub name: Identifier,
8371    pub comment: Option<String>,
8372    /// BigQuery: OPTIONS (key=value, ...) on column
8373    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8374    pub options: Vec<Expression>,
8375}
8376
8377impl ViewColumn {
8378    pub fn new(name: impl Into<String>) -> Self {
8379        Self {
8380            name: Identifier::new(name),
8381            comment: None,
8382            options: Vec::new(),
8383        }
8384    }
8385
8386    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8387        Self {
8388            name: Identifier::new(name),
8389            comment: Some(comment.into()),
8390            options: Vec::new(),
8391        }
8392    }
8393}
8394
8395/// CREATE VIEW statement
8396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8397#[cfg_attr(feature = "bindings", derive(TS))]
8398pub struct CreateView {
8399    pub name: TableRef,
8400    pub columns: Vec<ViewColumn>,
8401    pub query: Expression,
8402    pub or_replace: bool,
8403    /// TSQL: CREATE OR ALTER
8404    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8405    pub or_alter: bool,
8406    pub if_not_exists: bool,
8407    pub materialized: bool,
8408    pub temporary: bool,
8409    /// Snowflake: SECURE VIEW
8410    #[serde(default)]
8411    pub secure: bool,
8412    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8413    #[serde(skip_serializing_if = "Option::is_none")]
8414    pub algorithm: Option<String>,
8415    /// MySQL: DEFINER=user@host
8416    #[serde(skip_serializing_if = "Option::is_none")]
8417    pub definer: Option<String>,
8418    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8419    #[serde(skip_serializing_if = "Option::is_none")]
8420    pub security: Option<FunctionSecurity>,
8421    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8422    #[serde(default = "default_true")]
8423    pub security_sql_style: bool,
8424    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8425    #[serde(default)]
8426    pub security_after_name: bool,
8427    /// Whether the query was parenthesized: AS (SELECT ...)
8428    #[serde(default)]
8429    pub query_parenthesized: bool,
8430    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8431    #[serde(skip_serializing_if = "Option::is_none")]
8432    pub locking_mode: Option<String>,
8433    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8434    #[serde(skip_serializing_if = "Option::is_none")]
8435    pub locking_access: Option<String>,
8436    /// Snowflake: COPY GRANTS
8437    #[serde(default)]
8438    pub copy_grants: bool,
8439    /// Snowflake: COMMENT = 'text'
8440    #[serde(skip_serializing_if = "Option::is_none", default)]
8441    pub comment: Option<String>,
8442    /// Snowflake: WITH ROW ACCESS POLICY ... clause
8443    #[serde(skip_serializing_if = "Option::is_none", default)]
8444    pub row_access_policy: Option<String>,
8445    /// Snowflake: TAG (name='value', ...)
8446    #[serde(default)]
8447    pub tags: Vec<(String, String)>,
8448    /// BigQuery: OPTIONS (key=value, ...)
8449    #[serde(default)]
8450    pub options: Vec<Expression>,
8451    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8452    #[serde(skip_serializing_if = "Option::is_none", default)]
8453    pub build: Option<String>,
8454    /// Doris: REFRESH property for materialized views
8455    #[serde(skip_serializing_if = "Option::is_none", default)]
8456    pub refresh: Option<Box<RefreshTriggerProperty>>,
8457    /// Doris: Schema with typed column definitions for materialized views
8458    /// This is used instead of `columns` when the view has typed column definitions
8459    #[serde(skip_serializing_if = "Option::is_none", default)]
8460    pub schema: Option<Box<Schema>>,
8461    /// Doris: KEY (columns) for materialized views
8462    #[serde(skip_serializing_if = "Option::is_none", default)]
8463    pub unique_key: Option<Box<UniqueKeyProperty>>,
8464    /// Redshift: WITH NO SCHEMA BINDING
8465    #[serde(default)]
8466    pub no_schema_binding: bool,
8467    /// Redshift: AUTO REFRESH YES|NO for materialized views
8468    #[serde(skip_serializing_if = "Option::is_none", default)]
8469    pub auto_refresh: Option<bool>,
8470    /// ClickHouse: POPULATE / EMPTY before AS in materialized views
8471    #[serde(skip_serializing_if = "Option::is_none", default)]
8472    pub clickhouse_population: Option<String>,
8473    /// ClickHouse: ON CLUSTER clause
8474    #[serde(default, skip_serializing_if = "Option::is_none")]
8475    pub on_cluster: Option<OnCluster>,
8476    /// ClickHouse: TO destination_table
8477    #[serde(default, skip_serializing_if = "Option::is_none")]
8478    pub to_table: Option<TableRef>,
8479    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8480    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8481    pub table_properties: Vec<Expression>,
8482}
8483
8484impl CreateView {
8485    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8486        Self {
8487            name: TableRef::new(name),
8488            columns: Vec::new(),
8489            query,
8490            or_replace: false,
8491            or_alter: false,
8492            if_not_exists: false,
8493            materialized: false,
8494            temporary: false,
8495            secure: false,
8496            algorithm: None,
8497            definer: None,
8498            security: None,
8499            security_sql_style: true,
8500            security_after_name: false,
8501            query_parenthesized: false,
8502            locking_mode: None,
8503            locking_access: None,
8504            copy_grants: false,
8505            comment: None,
8506            row_access_policy: None,
8507            tags: Vec::new(),
8508            options: Vec::new(),
8509            build: None,
8510            refresh: None,
8511            schema: None,
8512            unique_key: None,
8513            no_schema_binding: false,
8514            auto_refresh: None,
8515            clickhouse_population: None,
8516            on_cluster: None,
8517            to_table: None,
8518            table_properties: Vec::new(),
8519        }
8520    }
8521}
8522
8523/// DROP VIEW statement
8524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8525#[cfg_attr(feature = "bindings", derive(TS))]
8526pub struct DropView {
8527    pub name: TableRef,
8528    pub if_exists: bool,
8529    pub materialized: bool,
8530}
8531
8532impl DropView {
8533    pub fn new(name: impl Into<String>) -> Self {
8534        Self {
8535            name: TableRef::new(name),
8536            if_exists: false,
8537            materialized: false,
8538        }
8539    }
8540}
8541
8542/// TRUNCATE TABLE statement
8543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8544#[cfg_attr(feature = "bindings", derive(TS))]
8545pub struct Truncate {
8546    /// Target of TRUNCATE (TABLE vs DATABASE)
8547    #[serde(default)]
8548    pub target: TruncateTarget,
8549    /// IF EXISTS clause
8550    #[serde(default)]
8551    pub if_exists: bool,
8552    pub table: TableRef,
8553    /// ClickHouse: ON CLUSTER clause for distributed DDL
8554    #[serde(default, skip_serializing_if = "Option::is_none")]
8555    pub on_cluster: Option<OnCluster>,
8556    pub cascade: bool,
8557    /// Additional tables for multi-table TRUNCATE
8558    #[serde(default)]
8559    pub extra_tables: Vec<TruncateTableEntry>,
8560    /// RESTART IDENTITY or CONTINUE IDENTITY
8561    #[serde(default)]
8562    pub identity: Option<TruncateIdentity>,
8563    /// RESTRICT option (alternative to CASCADE)
8564    #[serde(default)]
8565    pub restrict: bool,
8566    /// Hive PARTITION clause: PARTITION(key=value, ...)
8567    #[serde(default, skip_serializing_if = "Option::is_none")]
8568    pub partition: Option<Box<Expression>>,
8569}
8570
8571/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8573#[cfg_attr(feature = "bindings", derive(TS))]
8574pub struct TruncateTableEntry {
8575    pub table: TableRef,
8576    /// Whether the table has a * suffix (inherit children)
8577    #[serde(default)]
8578    pub star: bool,
8579}
8580
8581/// TRUNCATE target type
8582#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8583#[cfg_attr(feature = "bindings", derive(TS))]
8584pub enum TruncateTarget {
8585    Table,
8586    Database,
8587}
8588
8589impl Default for TruncateTarget {
8590    fn default() -> Self {
8591        TruncateTarget::Table
8592    }
8593}
8594
8595/// TRUNCATE identity option
8596#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8597#[cfg_attr(feature = "bindings", derive(TS))]
8598pub enum TruncateIdentity {
8599    Restart,
8600    Continue,
8601}
8602
8603impl Truncate {
8604    pub fn new(table: impl Into<String>) -> Self {
8605        Self {
8606            target: TruncateTarget::Table,
8607            if_exists: false,
8608            table: TableRef::new(table),
8609            on_cluster: None,
8610            cascade: false,
8611            extra_tables: Vec::new(),
8612            identity: None,
8613            restrict: false,
8614            partition: None,
8615        }
8616    }
8617}
8618
8619/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8621#[cfg_attr(feature = "bindings", derive(TS))]
8622pub struct Use {
8623    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8624    pub kind: Option<UseKind>,
8625    /// The name of the object
8626    pub this: Identifier,
8627}
8628
8629/// Kind of USE statement
8630#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8631#[cfg_attr(feature = "bindings", derive(TS))]
8632pub enum UseKind {
8633    Database,
8634    Schema,
8635    Role,
8636    Warehouse,
8637    Catalog,
8638    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8639    SecondaryRoles,
8640}
8641
8642/// SET variable statement
8643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8644#[cfg_attr(feature = "bindings", derive(TS))]
8645pub struct SetStatement {
8646    /// The items being set
8647    pub items: Vec<SetItem>,
8648}
8649
8650/// A single SET item (variable assignment)
8651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8652#[cfg_attr(feature = "bindings", derive(TS))]
8653pub struct SetItem {
8654    /// The variable name
8655    pub name: Expression,
8656    /// The value to set
8657    pub value: Expression,
8658    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8659    pub kind: Option<String>,
8660    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8661    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8662    pub no_equals: bool,
8663}
8664
8665/// CACHE TABLE statement (Spark)
8666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8667#[cfg_attr(feature = "bindings", derive(TS))]
8668pub struct Cache {
8669    /// The table to cache
8670    pub table: Identifier,
8671    /// LAZY keyword - defer caching until first use
8672    pub lazy: bool,
8673    /// Optional OPTIONS clause (key-value pairs)
8674    pub options: Vec<(Expression, Expression)>,
8675    /// Optional AS clause with query
8676    pub query: Option<Expression>,
8677}
8678
8679/// UNCACHE TABLE statement (Spark)
8680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8681#[cfg_attr(feature = "bindings", derive(TS))]
8682pub struct Uncache {
8683    /// The table to uncache
8684    pub table: Identifier,
8685    /// IF EXISTS clause
8686    pub if_exists: bool,
8687}
8688
8689/// LOAD DATA statement (Hive)
8690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8691#[cfg_attr(feature = "bindings", derive(TS))]
8692pub struct LoadData {
8693    /// LOCAL keyword - load from local filesystem
8694    pub local: bool,
8695    /// The path to load data from (INPATH value)
8696    pub inpath: String,
8697    /// Whether to overwrite existing data
8698    pub overwrite: bool,
8699    /// The target table
8700    pub table: Expression,
8701    /// Optional PARTITION clause with key-value pairs
8702    pub partition: Vec<(Identifier, Expression)>,
8703    /// Optional INPUTFORMAT clause
8704    pub input_format: Option<String>,
8705    /// Optional SERDE clause
8706    pub serde: Option<String>,
8707}
8708
8709/// PRAGMA statement (SQLite)
8710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8711#[cfg_attr(feature = "bindings", derive(TS))]
8712pub struct Pragma {
8713    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8714    pub schema: Option<Identifier>,
8715    /// The pragma name
8716    pub name: Identifier,
8717    /// Optional value for assignment (PRAGMA name = value)
8718    pub value: Option<Expression>,
8719    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8720    pub args: Vec<Expression>,
8721    /// Whether this pragma should be generated using assignment syntax.
8722    #[serde(default)]
8723    pub use_assignment_syntax: bool,
8724}
8725
8726/// A privilege with optional column list for GRANT/REVOKE
8727/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8729#[cfg_attr(feature = "bindings", derive(TS))]
8730pub struct Privilege {
8731    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8732    pub name: String,
8733    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8734    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8735    pub columns: Vec<String>,
8736}
8737
8738/// Principal in GRANT/REVOKE (user, role, etc.)
8739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8740#[cfg_attr(feature = "bindings", derive(TS))]
8741pub struct GrantPrincipal {
8742    /// The name of the principal
8743    pub name: Identifier,
8744    /// Whether prefixed with ROLE keyword
8745    pub is_role: bool,
8746    /// Whether prefixed with GROUP keyword (Redshift)
8747    #[serde(default)]
8748    pub is_group: bool,
8749    /// Whether prefixed with SHARE keyword (Snowflake)
8750    #[serde(default)]
8751    pub is_share: bool,
8752}
8753
8754/// GRANT statement
8755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8756#[cfg_attr(feature = "bindings", derive(TS))]
8757pub struct Grant {
8758    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8759    pub privileges: Vec<Privilege>,
8760    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8761    pub kind: Option<String>,
8762    /// The object to grant on
8763    pub securable: Identifier,
8764    /// Function parameter types (for FUNCTION kind)
8765    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8766    pub function_params: Vec<String>,
8767    /// The grantees
8768    pub principals: Vec<GrantPrincipal>,
8769    /// WITH GRANT OPTION
8770    pub grant_option: bool,
8771    /// TSQL: AS principal (the grantor role)
8772    #[serde(default, skip_serializing_if = "Option::is_none")]
8773    pub as_principal: Option<Identifier>,
8774}
8775
8776/// REVOKE statement
8777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8778#[cfg_attr(feature = "bindings", derive(TS))]
8779pub struct Revoke {
8780    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8781    pub privileges: Vec<Privilege>,
8782    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8783    pub kind: Option<String>,
8784    /// The object to revoke from
8785    pub securable: Identifier,
8786    /// Function parameter types (for FUNCTION kind)
8787    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8788    pub function_params: Vec<String>,
8789    /// The grantees
8790    pub principals: Vec<GrantPrincipal>,
8791    /// GRANT OPTION FOR
8792    pub grant_option: bool,
8793    /// CASCADE
8794    pub cascade: bool,
8795    /// RESTRICT
8796    #[serde(default)]
8797    pub restrict: bool,
8798}
8799
8800/// COMMENT ON statement
8801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8802#[cfg_attr(feature = "bindings", derive(TS))]
8803pub struct Comment {
8804    /// The object being commented on
8805    pub this: Expression,
8806    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8807    pub kind: String,
8808    /// The comment text expression
8809    pub expression: Expression,
8810    /// IF EXISTS clause
8811    pub exists: bool,
8812    /// MATERIALIZED keyword
8813    pub materialized: bool,
8814}
8815
8816// ============================================================================
8817// Phase 4: Additional DDL Statements
8818// ============================================================================
8819
8820/// ALTER VIEW statement
8821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8822#[cfg_attr(feature = "bindings", derive(TS))]
8823pub struct AlterView {
8824    pub name: TableRef,
8825    pub actions: Vec<AlterViewAction>,
8826    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8827    #[serde(default, skip_serializing_if = "Option::is_none")]
8828    pub algorithm: Option<String>,
8829    /// MySQL: DEFINER = 'user'@'host'
8830    #[serde(default, skip_serializing_if = "Option::is_none")]
8831    pub definer: Option<String>,
8832    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8833    #[serde(default, skip_serializing_if = "Option::is_none")]
8834    pub sql_security: Option<String>,
8835    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8836    #[serde(default, skip_serializing_if = "Option::is_none")]
8837    pub with_option: Option<String>,
8838    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8839    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8840    pub columns: Vec<ViewColumn>,
8841}
8842
8843/// Actions for ALTER VIEW
8844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8845#[cfg_attr(feature = "bindings", derive(TS))]
8846pub enum AlterViewAction {
8847    /// Rename the view
8848    Rename(TableRef),
8849    /// Change owner
8850    OwnerTo(Identifier),
8851    /// Set schema
8852    SetSchema(Identifier),
8853    /// Set authorization (Trino/Presto)
8854    SetAuthorization(String),
8855    /// Alter column
8856    AlterColumn {
8857        name: Identifier,
8858        action: AlterColumnAction,
8859    },
8860    /// Redefine view as query (SELECT, UNION, etc.)
8861    AsSelect(Box<Expression>),
8862    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8863    SetTblproperties(Vec<(String, String)>),
8864    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8865    UnsetTblproperties(Vec<String>),
8866}
8867
8868impl AlterView {
8869    pub fn new(name: impl Into<String>) -> Self {
8870        Self {
8871            name: TableRef::new(name),
8872            actions: Vec::new(),
8873            algorithm: None,
8874            definer: None,
8875            sql_security: None,
8876            with_option: None,
8877            columns: Vec::new(),
8878        }
8879    }
8880}
8881
8882/// ALTER INDEX statement
8883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8884#[cfg_attr(feature = "bindings", derive(TS))]
8885pub struct AlterIndex {
8886    pub name: Identifier,
8887    pub table: Option<TableRef>,
8888    pub actions: Vec<AlterIndexAction>,
8889}
8890
8891/// Actions for ALTER INDEX
8892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8893#[cfg_attr(feature = "bindings", derive(TS))]
8894pub enum AlterIndexAction {
8895    /// Rename the index
8896    Rename(Identifier),
8897    /// Set tablespace
8898    SetTablespace(Identifier),
8899    /// Set visibility (MySQL)
8900    Visible(bool),
8901}
8902
8903impl AlterIndex {
8904    pub fn new(name: impl Into<String>) -> Self {
8905        Self {
8906            name: Identifier::new(name),
8907            table: None,
8908            actions: Vec::new(),
8909        }
8910    }
8911}
8912
8913/// CREATE SCHEMA statement
8914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8915#[cfg_attr(feature = "bindings", derive(TS))]
8916pub struct CreateSchema {
8917    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8918    pub name: Vec<Identifier>,
8919    pub if_not_exists: bool,
8920    pub authorization: Option<Identifier>,
8921    /// CLONE source parts, possibly dot-qualified
8922    #[serde(default)]
8923    pub clone_from: Option<Vec<Identifier>>,
8924    /// AT/BEFORE clause for time travel (Snowflake)
8925    #[serde(default)]
8926    pub at_clause: Option<Expression>,
8927    /// Schema properties like DEFAULT COLLATE
8928    #[serde(default)]
8929    pub properties: Vec<Expression>,
8930    /// Leading comments before the statement
8931    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8932    pub leading_comments: Vec<String>,
8933}
8934
8935impl CreateSchema {
8936    pub fn new(name: impl Into<String>) -> Self {
8937        Self {
8938            name: vec![Identifier::new(name)],
8939            if_not_exists: false,
8940            authorization: None,
8941            clone_from: None,
8942            at_clause: None,
8943            properties: Vec::new(),
8944            leading_comments: Vec::new(),
8945        }
8946    }
8947}
8948
8949/// DROP SCHEMA statement
8950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8951#[cfg_attr(feature = "bindings", derive(TS))]
8952pub struct DropSchema {
8953    pub name: Identifier,
8954    pub if_exists: bool,
8955    pub cascade: bool,
8956}
8957
8958impl DropSchema {
8959    pub fn new(name: impl Into<String>) -> Self {
8960        Self {
8961            name: Identifier::new(name),
8962            if_exists: false,
8963            cascade: false,
8964        }
8965    }
8966}
8967
8968/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8970#[cfg_attr(feature = "bindings", derive(TS))]
8971pub struct DropNamespace {
8972    pub name: Identifier,
8973    pub if_exists: bool,
8974    pub cascade: bool,
8975}
8976
8977impl DropNamespace {
8978    pub fn new(name: impl Into<String>) -> Self {
8979        Self {
8980            name: Identifier::new(name),
8981            if_exists: false,
8982            cascade: false,
8983        }
8984    }
8985}
8986
8987/// CREATE DATABASE statement
8988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8989#[cfg_attr(feature = "bindings", derive(TS))]
8990pub struct CreateDatabase {
8991    pub name: Identifier,
8992    pub if_not_exists: bool,
8993    pub options: Vec<DatabaseOption>,
8994    /// Snowflake CLONE source
8995    #[serde(default)]
8996    pub clone_from: Option<Identifier>,
8997    /// AT/BEFORE clause for time travel (Snowflake)
8998    #[serde(default)]
8999    pub at_clause: Option<Expression>,
9000}
9001
9002/// Database option
9003#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9004#[cfg_attr(feature = "bindings", derive(TS))]
9005pub enum DatabaseOption {
9006    CharacterSet(String),
9007    Collate(String),
9008    Owner(Identifier),
9009    Template(Identifier),
9010    Encoding(String),
9011    Location(String),
9012}
9013
9014impl CreateDatabase {
9015    pub fn new(name: impl Into<String>) -> Self {
9016        Self {
9017            name: Identifier::new(name),
9018            if_not_exists: false,
9019            options: Vec::new(),
9020            clone_from: None,
9021            at_clause: None,
9022        }
9023    }
9024}
9025
9026/// DROP DATABASE statement
9027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9028#[cfg_attr(feature = "bindings", derive(TS))]
9029pub struct DropDatabase {
9030    pub name: Identifier,
9031    pub if_exists: bool,
9032    /// ClickHouse: SYNC modifier
9033    #[serde(default)]
9034    pub sync: bool,
9035}
9036
9037impl DropDatabase {
9038    pub fn new(name: impl Into<String>) -> Self {
9039        Self {
9040            name: Identifier::new(name),
9041            if_exists: false,
9042            sync: false,
9043        }
9044    }
9045}
9046
9047/// CREATE FUNCTION statement
9048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9049#[cfg_attr(feature = "bindings", derive(TS))]
9050pub struct CreateFunction {
9051    pub name: TableRef,
9052    pub parameters: Vec<FunctionParameter>,
9053    pub return_type: Option<DataType>,
9054    pub body: Option<FunctionBody>,
9055    pub or_replace: bool,
9056    /// TSQL: CREATE OR ALTER
9057    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9058    pub or_alter: bool,
9059    pub if_not_exists: bool,
9060    pub temporary: bool,
9061    pub language: Option<String>,
9062    pub deterministic: Option<bool>,
9063    pub returns_null_on_null_input: Option<bool>,
9064    pub security: Option<FunctionSecurity>,
9065    /// Whether parentheses were present in the original syntax
9066    #[serde(default = "default_true")]
9067    pub has_parens: bool,
9068    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9069    #[serde(default)]
9070    pub sql_data_access: Option<SqlDataAccess>,
9071    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9072    #[serde(default, skip_serializing_if = "Option::is_none")]
9073    pub returns_table_body: Option<String>,
9074    /// True if LANGUAGE clause appears before RETURNS clause
9075    #[serde(default)]
9076    pub language_first: bool,
9077    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9078    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9079    pub set_options: Vec<FunctionSetOption>,
9080    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9081    #[serde(default)]
9082    pub strict: bool,
9083    /// BigQuery: OPTIONS (key=value, ...)
9084    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9085    pub options: Vec<Expression>,
9086    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9087    #[serde(default)]
9088    pub is_table_function: bool,
9089    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9090    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9091    pub property_order: Vec<FunctionPropertyKind>,
9092    /// Hive: USING JAR|FILE|ARCHIVE '...'
9093    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9094    pub using_resources: Vec<FunctionUsingResource>,
9095    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9096    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9097    pub environment: Vec<Expression>,
9098    /// HANDLER 'handler_function' clause (Databricks)
9099    #[serde(default, skip_serializing_if = "Option::is_none")]
9100    pub handler: Option<String>,
9101    /// True when the HANDLER clause used Snowflake-style `HANDLER = 'fn'`
9102    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9103    pub handler_uses_eq: bool,
9104    /// Snowflake: RUNTIME_VERSION='3.11'
9105    #[serde(default, skip_serializing_if = "Option::is_none")]
9106    pub runtime_version: Option<String>,
9107    /// Snowflake: PACKAGES=('pkg1', 'pkg2')
9108    #[serde(default, skip_serializing_if = "Option::is_none")]
9109    pub packages: Option<Vec<String>>,
9110    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9111    #[serde(default, skip_serializing_if = "Option::is_none")]
9112    pub parameter_style: Option<String>,
9113}
9114
9115/// A SET option in CREATE FUNCTION (PostgreSQL)
9116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9117#[cfg_attr(feature = "bindings", derive(TS))]
9118pub struct FunctionSetOption {
9119    pub name: String,
9120    pub value: FunctionSetValue,
9121}
9122
9123/// The value of a SET option
9124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9125#[cfg_attr(feature = "bindings", derive(TS))]
9126pub enum FunctionSetValue {
9127    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9128    Value { value: String, use_to: bool },
9129    /// SET key FROM CURRENT
9130    FromCurrent,
9131}
9132
9133/// SQL data access characteristics for functions
9134#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9135#[cfg_attr(feature = "bindings", derive(TS))]
9136pub enum SqlDataAccess {
9137    /// NO SQL
9138    NoSql,
9139    /// CONTAINS SQL
9140    ContainsSql,
9141    /// READS SQL DATA
9142    ReadsSqlData,
9143    /// MODIFIES SQL DATA
9144    ModifiesSqlData,
9145}
9146
9147/// Types of properties in CREATE FUNCTION for tracking their original order
9148#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9149#[cfg_attr(feature = "bindings", derive(TS))]
9150pub enum FunctionPropertyKind {
9151    /// SET option
9152    Set,
9153    /// AS body
9154    As,
9155    /// Hive: USING JAR|FILE|ARCHIVE ...
9156    Using,
9157    /// LANGUAGE clause
9158    Language,
9159    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9160    Determinism,
9161    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9162    NullInput,
9163    /// SECURITY DEFINER/INVOKER
9164    Security,
9165    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9166    SqlDataAccess,
9167    /// OPTIONS clause (BigQuery)
9168    Options,
9169    /// ENVIRONMENT clause (Databricks)
9170    Environment,
9171    /// HANDLER clause (Databricks)
9172    Handler,
9173    /// Snowflake: RUNTIME_VERSION='...'
9174    RuntimeVersion,
9175    /// Snowflake: PACKAGES=(...)
9176    Packages,
9177    /// PARAMETER STYLE clause (Databricks)
9178    ParameterStyle,
9179}
9180
9181/// Hive CREATE FUNCTION resource in a USING clause
9182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9183#[cfg_attr(feature = "bindings", derive(TS))]
9184pub struct FunctionUsingResource {
9185    pub kind: String,
9186    pub uri: String,
9187}
9188
9189/// Function parameter
9190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9191#[cfg_attr(feature = "bindings", derive(TS))]
9192pub struct FunctionParameter {
9193    pub name: Option<Identifier>,
9194    pub data_type: DataType,
9195    pub mode: Option<ParameterMode>,
9196    pub default: Option<Expression>,
9197    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9198    #[serde(default, skip_serializing_if = "Option::is_none")]
9199    pub mode_text: Option<String>,
9200}
9201
9202/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9203#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9204#[cfg_attr(feature = "bindings", derive(TS))]
9205pub enum ParameterMode {
9206    In,
9207    Out,
9208    InOut,
9209    Variadic,
9210}
9211
9212/// Function body
9213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9214#[cfg_attr(feature = "bindings", derive(TS))]
9215pub enum FunctionBody {
9216    /// AS $$ ... $$ (dollar-quoted)
9217    Block(String),
9218    /// AS 'string' (single-quoted string literal body)
9219    StringLiteral(String),
9220    /// AS 'expression'
9221    Expression(Expression),
9222    /// EXTERNAL NAME 'library'
9223    External(String),
9224    /// RETURN expression
9225    Return(Expression),
9226    /// BEGIN ... END block with parsed statements
9227    Statements(Vec<Expression>),
9228    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9229    /// Stores (content, optional_tag)
9230    DollarQuoted {
9231        content: String,
9232        tag: Option<String>,
9233    },
9234    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9235    RawBlock(String),
9236}
9237
9238/// Function security (DEFINER, INVOKER, or NONE)
9239#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9240#[cfg_attr(feature = "bindings", derive(TS))]
9241pub enum FunctionSecurity {
9242    Definer,
9243    Invoker,
9244    /// StarRocks/MySQL: SECURITY NONE
9245    None,
9246}
9247
9248impl CreateFunction {
9249    pub fn new(name: impl Into<String>) -> Self {
9250        Self {
9251            name: TableRef::new(name),
9252            parameters: Vec::new(),
9253            return_type: None,
9254            body: None,
9255            or_replace: false,
9256            or_alter: false,
9257            if_not_exists: false,
9258            temporary: false,
9259            language: None,
9260            deterministic: None,
9261            returns_null_on_null_input: None,
9262            security: None,
9263            has_parens: true,
9264            sql_data_access: None,
9265            returns_table_body: None,
9266            language_first: false,
9267            set_options: Vec::new(),
9268            strict: false,
9269            options: Vec::new(),
9270            is_table_function: false,
9271            property_order: Vec::new(),
9272            using_resources: Vec::new(),
9273            environment: Vec::new(),
9274            handler: None,
9275            handler_uses_eq: false,
9276            runtime_version: None,
9277            packages: None,
9278            parameter_style: None,
9279        }
9280    }
9281}
9282
9283/// DROP FUNCTION statement
9284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9285#[cfg_attr(feature = "bindings", derive(TS))]
9286pub struct DropFunction {
9287    pub name: TableRef,
9288    pub parameters: Option<Vec<DataType>>,
9289    pub if_exists: bool,
9290    pub cascade: bool,
9291}
9292
9293impl DropFunction {
9294    pub fn new(name: impl Into<String>) -> Self {
9295        Self {
9296            name: TableRef::new(name),
9297            parameters: None,
9298            if_exists: false,
9299            cascade: false,
9300        }
9301    }
9302}
9303
9304/// CREATE PROCEDURE statement
9305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9306#[cfg_attr(feature = "bindings", derive(TS))]
9307pub struct CreateProcedure {
9308    pub name: TableRef,
9309    pub parameters: Vec<FunctionParameter>,
9310    pub body: Option<FunctionBody>,
9311    pub or_replace: bool,
9312    /// TSQL: CREATE OR ALTER
9313    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9314    pub or_alter: bool,
9315    pub if_not_exists: bool,
9316    pub language: Option<String>,
9317    pub security: Option<FunctionSecurity>,
9318    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9319    #[serde(default)]
9320    pub return_type: Option<DataType>,
9321    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9322    #[serde(default)]
9323    pub execute_as: Option<String>,
9324    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9325    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9326    pub with_options: Vec<String>,
9327    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9328    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9329    pub has_parens: bool,
9330    /// Whether the short form PROC was used (instead of PROCEDURE)
9331    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9332    pub use_proc_keyword: bool,
9333}
9334
9335impl CreateProcedure {
9336    pub fn new(name: impl Into<String>) -> Self {
9337        Self {
9338            name: TableRef::new(name),
9339            parameters: Vec::new(),
9340            body: None,
9341            or_replace: false,
9342            or_alter: false,
9343            if_not_exists: false,
9344            language: None,
9345            security: None,
9346            return_type: None,
9347            execute_as: None,
9348            with_options: Vec::new(),
9349            has_parens: true,
9350            use_proc_keyword: false,
9351        }
9352    }
9353}
9354
9355/// DROP PROCEDURE statement
9356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9357#[cfg_attr(feature = "bindings", derive(TS))]
9358pub struct DropProcedure {
9359    pub name: TableRef,
9360    pub parameters: Option<Vec<DataType>>,
9361    pub if_exists: bool,
9362    pub cascade: bool,
9363}
9364
9365impl DropProcedure {
9366    pub fn new(name: impl Into<String>) -> Self {
9367        Self {
9368            name: TableRef::new(name),
9369            parameters: None,
9370            if_exists: false,
9371            cascade: false,
9372        }
9373    }
9374}
9375
9376/// Sequence property tag for ordering
9377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9378#[cfg_attr(feature = "bindings", derive(TS))]
9379pub enum SeqPropKind {
9380    Start,
9381    Increment,
9382    Minvalue,
9383    Maxvalue,
9384    Cache,
9385    NoCache,
9386    Cycle,
9387    NoCycle,
9388    OwnedBy,
9389    Order,
9390    NoOrder,
9391    Comment,
9392    /// SHARING=<value> (Oracle)
9393    Sharing,
9394    /// KEEP (Oracle)
9395    Keep,
9396    /// NOKEEP (Oracle)
9397    NoKeep,
9398    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9399    Scale,
9400    /// NOSCALE (Oracle)
9401    NoScale,
9402    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9403    Shard,
9404    /// NOSHARD (Oracle)
9405    NoShard,
9406    /// SESSION (Oracle)
9407    Session,
9408    /// GLOBAL (Oracle)
9409    Global,
9410    /// NOCACHE (single word, Oracle)
9411    NoCacheWord,
9412    /// NOCYCLE (single word, Oracle)
9413    NoCycleWord,
9414    /// NOMINVALUE (single word, Oracle)
9415    NoMinvalueWord,
9416    /// NOMAXVALUE (single word, Oracle)
9417    NoMaxvalueWord,
9418}
9419
9420/// CREATE SYNONYM statement (TSQL)
9421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9422#[cfg_attr(feature = "bindings", derive(TS))]
9423pub struct CreateSynonym {
9424    /// The synonym name (can be qualified: schema.synonym_name)
9425    pub name: TableRef,
9426    /// The target object the synonym refers to
9427    pub target: TableRef,
9428}
9429
9430/// CREATE SEQUENCE statement
9431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9432#[cfg_attr(feature = "bindings", derive(TS))]
9433pub struct CreateSequence {
9434    pub name: TableRef,
9435    pub if_not_exists: bool,
9436    pub temporary: bool,
9437    #[serde(default)]
9438    pub or_replace: bool,
9439    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9440    #[serde(default, skip_serializing_if = "Option::is_none")]
9441    pub as_type: Option<DataType>,
9442    pub increment: Option<i64>,
9443    pub minvalue: Option<SequenceBound>,
9444    pub maxvalue: Option<SequenceBound>,
9445    pub start: Option<i64>,
9446    pub cache: Option<i64>,
9447    pub cycle: bool,
9448    pub owned_by: Option<TableRef>,
9449    /// Whether OWNED BY NONE was specified
9450    #[serde(default)]
9451    pub owned_by_none: bool,
9452    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9453    #[serde(default)]
9454    pub order: Option<bool>,
9455    /// Snowflake: COMMENT = 'value'
9456    #[serde(default)]
9457    pub comment: Option<String>,
9458    /// SHARING=<value> (Oracle)
9459    #[serde(default, skip_serializing_if = "Option::is_none")]
9460    pub sharing: Option<String>,
9461    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9462    #[serde(default, skip_serializing_if = "Option::is_none")]
9463    pub scale_modifier: Option<String>,
9464    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9465    #[serde(default, skip_serializing_if = "Option::is_none")]
9466    pub shard_modifier: Option<String>,
9467    /// Tracks the order in which properties appeared in the source
9468    #[serde(default)]
9469    pub property_order: Vec<SeqPropKind>,
9470}
9471
9472/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9474#[cfg_attr(feature = "bindings", derive(TS))]
9475pub enum SequenceBound {
9476    Value(i64),
9477    None,
9478}
9479
9480impl CreateSequence {
9481    pub fn new(name: impl Into<String>) -> Self {
9482        Self {
9483            name: TableRef::new(name),
9484            if_not_exists: false,
9485            temporary: false,
9486            or_replace: false,
9487            as_type: None,
9488            increment: None,
9489            minvalue: None,
9490            maxvalue: None,
9491            start: None,
9492            cache: None,
9493            cycle: false,
9494            owned_by: None,
9495            owned_by_none: false,
9496            order: None,
9497            comment: None,
9498            sharing: None,
9499            scale_modifier: None,
9500            shard_modifier: None,
9501            property_order: Vec::new(),
9502        }
9503    }
9504}
9505
9506/// DROP SEQUENCE statement
9507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9508#[cfg_attr(feature = "bindings", derive(TS))]
9509pub struct DropSequence {
9510    pub name: TableRef,
9511    pub if_exists: bool,
9512    pub cascade: bool,
9513}
9514
9515impl DropSequence {
9516    pub fn new(name: impl Into<String>) -> Self {
9517        Self {
9518            name: TableRef::new(name),
9519            if_exists: false,
9520            cascade: false,
9521        }
9522    }
9523}
9524
9525/// ALTER SEQUENCE statement
9526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9527#[cfg_attr(feature = "bindings", derive(TS))]
9528pub struct AlterSequence {
9529    pub name: TableRef,
9530    pub if_exists: bool,
9531    pub increment: Option<i64>,
9532    pub minvalue: Option<SequenceBound>,
9533    pub maxvalue: Option<SequenceBound>,
9534    pub start: Option<i64>,
9535    pub restart: Option<Option<i64>>,
9536    pub cache: Option<i64>,
9537    pub cycle: Option<bool>,
9538    pub owned_by: Option<Option<TableRef>>,
9539}
9540
9541impl AlterSequence {
9542    pub fn new(name: impl Into<String>) -> Self {
9543        Self {
9544            name: TableRef::new(name),
9545            if_exists: false,
9546            increment: None,
9547            minvalue: None,
9548            maxvalue: None,
9549            start: None,
9550            restart: None,
9551            cache: None,
9552            cycle: None,
9553            owned_by: None,
9554        }
9555    }
9556}
9557
9558/// CREATE TRIGGER statement
9559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9560#[cfg_attr(feature = "bindings", derive(TS))]
9561pub struct CreateTrigger {
9562    pub name: Identifier,
9563    pub table: TableRef,
9564    pub timing: TriggerTiming,
9565    pub events: Vec<TriggerEvent>,
9566    #[serde(default, skip_serializing_if = "Option::is_none")]
9567    pub for_each: Option<TriggerForEach>,
9568    pub when: Option<Expression>,
9569    /// Whether the WHEN clause was parenthesized in the original SQL
9570    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9571    pub when_paren: bool,
9572    pub body: TriggerBody,
9573    pub or_replace: bool,
9574    /// TSQL: CREATE OR ALTER
9575    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9576    pub or_alter: bool,
9577    pub constraint: bool,
9578    pub deferrable: Option<bool>,
9579    pub initially_deferred: Option<bool>,
9580    pub referencing: Option<TriggerReferencing>,
9581}
9582
9583/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9584#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9585#[cfg_attr(feature = "bindings", derive(TS))]
9586pub enum TriggerTiming {
9587    Before,
9588    After,
9589    InsteadOf,
9590}
9591
9592/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9594#[cfg_attr(feature = "bindings", derive(TS))]
9595pub enum TriggerEvent {
9596    Insert,
9597    Update(Option<Vec<Identifier>>),
9598    Delete,
9599    Truncate,
9600}
9601
9602/// Trigger FOR EACH clause
9603#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9604#[cfg_attr(feature = "bindings", derive(TS))]
9605pub enum TriggerForEach {
9606    Row,
9607    Statement,
9608}
9609
9610/// Trigger body
9611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9612#[cfg_attr(feature = "bindings", derive(TS))]
9613pub enum TriggerBody {
9614    /// EXECUTE FUNCTION/PROCEDURE name(args)
9615    Execute {
9616        function: TableRef,
9617        args: Vec<Expression>,
9618    },
9619    /// BEGIN ... END block
9620    Block(String),
9621}
9622
9623/// Trigger REFERENCING clause
9624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9625#[cfg_attr(feature = "bindings", derive(TS))]
9626pub struct TriggerReferencing {
9627    pub old_table: Option<Identifier>,
9628    pub new_table: Option<Identifier>,
9629    pub old_row: Option<Identifier>,
9630    pub new_row: Option<Identifier>,
9631}
9632
9633impl CreateTrigger {
9634    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9635        Self {
9636            name: Identifier::new(name),
9637            table: TableRef::new(table),
9638            timing: TriggerTiming::Before,
9639            events: Vec::new(),
9640            for_each: Some(TriggerForEach::Row),
9641            when: None,
9642            when_paren: false,
9643            body: TriggerBody::Execute {
9644                function: TableRef::new(""),
9645                args: Vec::new(),
9646            },
9647            or_replace: false,
9648            or_alter: false,
9649            constraint: false,
9650            deferrable: None,
9651            initially_deferred: None,
9652            referencing: None,
9653        }
9654    }
9655}
9656
9657/// DROP TRIGGER statement
9658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9659#[cfg_attr(feature = "bindings", derive(TS))]
9660pub struct DropTrigger {
9661    pub name: Identifier,
9662    pub table: Option<TableRef>,
9663    pub if_exists: bool,
9664    pub cascade: bool,
9665}
9666
9667impl DropTrigger {
9668    pub fn new(name: impl Into<String>) -> Self {
9669        Self {
9670            name: Identifier::new(name),
9671            table: None,
9672            if_exists: false,
9673            cascade: false,
9674        }
9675    }
9676}
9677
9678/// CREATE TYPE statement
9679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9680#[cfg_attr(feature = "bindings", derive(TS))]
9681pub struct CreateType {
9682    pub name: TableRef,
9683    pub definition: TypeDefinition,
9684    pub if_not_exists: bool,
9685}
9686
9687/// Type definition
9688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9689#[cfg_attr(feature = "bindings", derive(TS))]
9690pub enum TypeDefinition {
9691    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9692    Enum(Vec<String>),
9693    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9694    Composite(Vec<TypeAttribute>),
9695    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9696    Range {
9697        subtype: DataType,
9698        subtype_diff: Option<String>,
9699        canonical: Option<String>,
9700    },
9701    /// Base type (for advanced usage)
9702    Base {
9703        input: String,
9704        output: String,
9705        internallength: Option<i32>,
9706    },
9707    /// Domain type
9708    Domain {
9709        base_type: DataType,
9710        default: Option<Expression>,
9711        constraints: Vec<DomainConstraint>,
9712    },
9713}
9714
9715/// Type attribute for composite types
9716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9717#[cfg_attr(feature = "bindings", derive(TS))]
9718pub struct TypeAttribute {
9719    pub name: Identifier,
9720    pub data_type: DataType,
9721    pub collate: Option<Identifier>,
9722}
9723
9724/// Domain constraint
9725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9726#[cfg_attr(feature = "bindings", derive(TS))]
9727pub struct DomainConstraint {
9728    pub name: Option<Identifier>,
9729    pub check: Expression,
9730}
9731
9732impl CreateType {
9733    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9734        Self {
9735            name: TableRef::new(name),
9736            definition: TypeDefinition::Enum(values),
9737            if_not_exists: false,
9738        }
9739    }
9740
9741    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9742        Self {
9743            name: TableRef::new(name),
9744            definition: TypeDefinition::Composite(attributes),
9745            if_not_exists: false,
9746        }
9747    }
9748}
9749
9750/// DROP TYPE statement
9751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9752#[cfg_attr(feature = "bindings", derive(TS))]
9753pub struct DropType {
9754    pub name: TableRef,
9755    pub if_exists: bool,
9756    pub cascade: bool,
9757}
9758
9759impl DropType {
9760    pub fn new(name: impl Into<String>) -> Self {
9761        Self {
9762            name: TableRef::new(name),
9763            if_exists: false,
9764            cascade: false,
9765        }
9766    }
9767}
9768
9769/// DESCRIBE statement - shows table structure or query plan
9770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9771#[cfg_attr(feature = "bindings", derive(TS))]
9772pub struct Describe {
9773    /// The target to describe (table name or query)
9774    pub target: Expression,
9775    /// EXTENDED format
9776    pub extended: bool,
9777    /// FORMATTED format
9778    pub formatted: bool,
9779    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9780    #[serde(default)]
9781    pub kind: Option<String>,
9782    /// Properties like type=stage
9783    #[serde(default)]
9784    pub properties: Vec<(String, String)>,
9785    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9786    #[serde(default, skip_serializing_if = "Option::is_none")]
9787    pub style: Option<String>,
9788    /// Partition specification for DESCRIBE PARTITION
9789    #[serde(default)]
9790    pub partition: Option<Box<Expression>>,
9791    /// Leading comments before the statement
9792    #[serde(default)]
9793    pub leading_comments: Vec<String>,
9794    /// AS JSON suffix (Databricks)
9795    #[serde(default)]
9796    pub as_json: bool,
9797    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9798    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9799    pub params: Vec<String>,
9800}
9801
9802impl Describe {
9803    pub fn new(target: Expression) -> Self {
9804        Self {
9805            target,
9806            extended: false,
9807            formatted: false,
9808            kind: None,
9809            properties: Vec::new(),
9810            style: None,
9811            partition: None,
9812            leading_comments: Vec::new(),
9813            as_json: false,
9814            params: Vec::new(),
9815        }
9816    }
9817}
9818
9819/// SHOW statement - displays database objects
9820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9821#[cfg_attr(feature = "bindings", derive(TS))]
9822pub struct Show {
9823    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9824    pub this: String,
9825    /// Whether TERSE was specified
9826    #[serde(default)]
9827    pub terse: bool,
9828    /// Whether HISTORY was specified
9829    #[serde(default)]
9830    pub history: bool,
9831    /// LIKE pattern
9832    pub like: Option<Expression>,
9833    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9834    pub scope_kind: Option<String>,
9835    /// IN scope object
9836    pub scope: Option<Expression>,
9837    /// STARTS WITH pattern
9838    pub starts_with: Option<Expression>,
9839    /// LIMIT clause
9840    pub limit: Option<Box<Limit>>,
9841    /// FROM clause (for specific object)
9842    pub from: Option<Expression>,
9843    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9844    #[serde(default, skip_serializing_if = "Option::is_none")]
9845    pub where_clause: Option<Expression>,
9846    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9847    #[serde(default, skip_serializing_if = "Option::is_none")]
9848    pub for_target: Option<Expression>,
9849    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9850    #[serde(default, skip_serializing_if = "Option::is_none")]
9851    pub db: Option<Expression>,
9852    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9853    #[serde(default, skip_serializing_if = "Option::is_none")]
9854    pub target: Option<Expression>,
9855    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9856    #[serde(default, skip_serializing_if = "Option::is_none")]
9857    pub mutex: Option<bool>,
9858    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9859    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9860    pub privileges: Vec<String>,
9861}
9862
9863impl Show {
9864    pub fn new(this: impl Into<String>) -> Self {
9865        Self {
9866            this: this.into(),
9867            terse: false,
9868            history: false,
9869            like: None,
9870            scope_kind: None,
9871            scope: None,
9872            starts_with: None,
9873            limit: None,
9874            from: None,
9875            where_clause: None,
9876            for_target: None,
9877            db: None,
9878            target: None,
9879            mutex: None,
9880            privileges: Vec::new(),
9881        }
9882    }
9883}
9884
9885/// Represent an explicit parenthesized expression for grouping precedence.
9886///
9887/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9888/// correctly instead of being flattened to `a + b * c`.
9889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9890#[cfg_attr(feature = "bindings", derive(TS))]
9891pub struct Paren {
9892    /// The inner expression wrapped by parentheses.
9893    pub this: Expression,
9894    #[serde(default)]
9895    pub trailing_comments: Vec<String>,
9896}
9897
9898/// Expression annotated with trailing comments (for round-trip preservation)
9899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9900#[cfg_attr(feature = "bindings", derive(TS))]
9901pub struct Annotated {
9902    pub this: Expression,
9903    pub trailing_comments: Vec<String>,
9904}
9905
9906// === BATCH GENERATED STRUCT DEFINITIONS ===
9907// Generated from Python sqlglot expressions.py
9908
9909/// Refresh
9910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9911#[cfg_attr(feature = "bindings", derive(TS))]
9912pub struct Refresh {
9913    pub this: Box<Expression>,
9914    pub kind: String,
9915}
9916
9917/// LockingStatement
9918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9919#[cfg_attr(feature = "bindings", derive(TS))]
9920pub struct LockingStatement {
9921    pub this: Box<Expression>,
9922    pub expression: Box<Expression>,
9923}
9924
9925/// SequenceProperties
9926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9927#[cfg_attr(feature = "bindings", derive(TS))]
9928pub struct SequenceProperties {
9929    #[serde(default)]
9930    pub increment: Option<Box<Expression>>,
9931    #[serde(default)]
9932    pub minvalue: Option<Box<Expression>>,
9933    #[serde(default)]
9934    pub maxvalue: Option<Box<Expression>>,
9935    #[serde(default)]
9936    pub cache: Option<Box<Expression>>,
9937    #[serde(default)]
9938    pub start: Option<Box<Expression>>,
9939    #[serde(default)]
9940    pub owned: Option<Box<Expression>>,
9941    #[serde(default)]
9942    pub options: Vec<Expression>,
9943}
9944
9945/// TruncateTable
9946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9947#[cfg_attr(feature = "bindings", derive(TS))]
9948pub struct TruncateTable {
9949    #[serde(default)]
9950    pub expressions: Vec<Expression>,
9951    #[serde(default)]
9952    pub is_database: Option<Box<Expression>>,
9953    #[serde(default)]
9954    pub exists: bool,
9955    #[serde(default)]
9956    pub only: Option<Box<Expression>>,
9957    #[serde(default)]
9958    pub cluster: Option<Box<Expression>>,
9959    #[serde(default)]
9960    pub identity: Option<Box<Expression>>,
9961    #[serde(default)]
9962    pub option: Option<Box<Expression>>,
9963    #[serde(default)]
9964    pub partition: Option<Box<Expression>>,
9965}
9966
9967/// Clone
9968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9969#[cfg_attr(feature = "bindings", derive(TS))]
9970pub struct Clone {
9971    pub this: Box<Expression>,
9972    #[serde(default)]
9973    pub shallow: Option<Box<Expression>>,
9974    #[serde(default)]
9975    pub copy: Option<Box<Expression>>,
9976}
9977
9978/// Attach
9979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9980#[cfg_attr(feature = "bindings", derive(TS))]
9981pub struct Attach {
9982    pub this: Box<Expression>,
9983    #[serde(default)]
9984    pub exists: bool,
9985    #[serde(default)]
9986    pub expressions: Vec<Expression>,
9987}
9988
9989/// Detach
9990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9991#[cfg_attr(feature = "bindings", derive(TS))]
9992pub struct Detach {
9993    pub this: Box<Expression>,
9994    #[serde(default)]
9995    pub exists: bool,
9996}
9997
9998/// Install
9999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10000#[cfg_attr(feature = "bindings", derive(TS))]
10001pub struct Install {
10002    pub this: Box<Expression>,
10003    #[serde(default)]
10004    pub from_: Option<Box<Expression>>,
10005    #[serde(default)]
10006    pub force: Option<Box<Expression>>,
10007}
10008
10009/// Summarize
10010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10011#[cfg_attr(feature = "bindings", derive(TS))]
10012pub struct Summarize {
10013    pub this: Box<Expression>,
10014    #[serde(default)]
10015    pub table: Option<Box<Expression>>,
10016}
10017
10018/// Declare
10019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10020#[cfg_attr(feature = "bindings", derive(TS))]
10021pub struct Declare {
10022    #[serde(default)]
10023    pub expressions: Vec<Expression>,
10024    #[serde(default)]
10025    pub replace: bool,
10026}
10027
10028/// DeclareItem
10029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10030#[cfg_attr(feature = "bindings", derive(TS))]
10031pub struct DeclareItem {
10032    pub this: Box<Expression>,
10033    #[serde(default)]
10034    pub kind: Option<String>,
10035    #[serde(default)]
10036    pub default: Option<Box<Expression>>,
10037    #[serde(default)]
10038    pub has_as: bool,
10039    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
10040    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10041    pub additional_names: Vec<Expression>,
10042}
10043
10044/// Set
10045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10046#[cfg_attr(feature = "bindings", derive(TS))]
10047pub struct Set {
10048    #[serde(default)]
10049    pub expressions: Vec<Expression>,
10050    #[serde(default)]
10051    pub unset: Option<Box<Expression>>,
10052    #[serde(default)]
10053    pub tag: Option<Box<Expression>>,
10054}
10055
10056/// Heredoc
10057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10058#[cfg_attr(feature = "bindings", derive(TS))]
10059pub struct Heredoc {
10060    pub this: Box<Expression>,
10061    #[serde(default)]
10062    pub tag: Option<Box<Expression>>,
10063}
10064
10065/// QueryBand
10066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10067#[cfg_attr(feature = "bindings", derive(TS))]
10068pub struct QueryBand {
10069    pub this: Box<Expression>,
10070    #[serde(default)]
10071    pub scope: Option<Box<Expression>>,
10072    #[serde(default)]
10073    pub update: Option<Box<Expression>>,
10074}
10075
10076/// UserDefinedFunction
10077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10078#[cfg_attr(feature = "bindings", derive(TS))]
10079pub struct UserDefinedFunction {
10080    pub this: Box<Expression>,
10081    #[serde(default)]
10082    pub expressions: Vec<Expression>,
10083    #[serde(default)]
10084    pub wrapped: Option<Box<Expression>>,
10085}
10086
10087/// RecursiveWithSearch
10088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10089#[cfg_attr(feature = "bindings", derive(TS))]
10090pub struct RecursiveWithSearch {
10091    pub kind: String,
10092    pub this: Box<Expression>,
10093    pub expression: Box<Expression>,
10094    #[serde(default)]
10095    pub using: Option<Box<Expression>>,
10096}
10097
10098/// ProjectionDef
10099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10100#[cfg_attr(feature = "bindings", derive(TS))]
10101pub struct ProjectionDef {
10102    pub this: Box<Expression>,
10103    pub expression: Box<Expression>,
10104}
10105
10106/// TableAlias
10107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10108#[cfg_attr(feature = "bindings", derive(TS))]
10109pub struct TableAlias {
10110    #[serde(default)]
10111    pub this: Option<Box<Expression>>,
10112    #[serde(default)]
10113    pub columns: Vec<Expression>,
10114}
10115
10116/// ByteString
10117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10118#[cfg_attr(feature = "bindings", derive(TS))]
10119pub struct ByteString {
10120    pub this: Box<Expression>,
10121    #[serde(default)]
10122    pub is_bytes: Option<Box<Expression>>,
10123}
10124
10125/// HexStringExpr - Hex string expression (not literal)
10126/// BigQuery: converts to FROM_HEX(this)
10127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10128#[cfg_attr(feature = "bindings", derive(TS))]
10129pub struct HexStringExpr {
10130    pub this: Box<Expression>,
10131    #[serde(default)]
10132    pub is_integer: Option<bool>,
10133}
10134
10135/// UnicodeString
10136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10137#[cfg_attr(feature = "bindings", derive(TS))]
10138pub struct UnicodeString {
10139    pub this: Box<Expression>,
10140    #[serde(default)]
10141    pub escape: Option<Box<Expression>>,
10142}
10143
10144/// AlterColumn
10145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10146#[cfg_attr(feature = "bindings", derive(TS))]
10147pub struct AlterColumn {
10148    pub this: Box<Expression>,
10149    #[serde(default)]
10150    pub dtype: Option<Box<Expression>>,
10151    #[serde(default)]
10152    pub collate: Option<Box<Expression>>,
10153    #[serde(default)]
10154    pub using: Option<Box<Expression>>,
10155    #[serde(default)]
10156    pub default: Option<Box<Expression>>,
10157    #[serde(default)]
10158    pub drop: Option<Box<Expression>>,
10159    #[serde(default)]
10160    pub comment: Option<Box<Expression>>,
10161    #[serde(default)]
10162    pub allow_null: Option<Box<Expression>>,
10163    #[serde(default)]
10164    pub visible: Option<Box<Expression>>,
10165    #[serde(default)]
10166    pub rename_to: Option<Box<Expression>>,
10167}
10168
10169/// AlterSortKey
10170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10171#[cfg_attr(feature = "bindings", derive(TS))]
10172pub struct AlterSortKey {
10173    #[serde(default)]
10174    pub this: Option<Box<Expression>>,
10175    #[serde(default)]
10176    pub expressions: Vec<Expression>,
10177    #[serde(default)]
10178    pub compound: Option<Box<Expression>>,
10179}
10180
10181/// AlterSet
10182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10183#[cfg_attr(feature = "bindings", derive(TS))]
10184pub struct AlterSet {
10185    #[serde(default)]
10186    pub expressions: Vec<Expression>,
10187    #[serde(default)]
10188    pub option: Option<Box<Expression>>,
10189    #[serde(default)]
10190    pub tablespace: Option<Box<Expression>>,
10191    #[serde(default)]
10192    pub access_method: Option<Box<Expression>>,
10193    #[serde(default)]
10194    pub file_format: Option<Box<Expression>>,
10195    #[serde(default)]
10196    pub copy_options: Option<Box<Expression>>,
10197    #[serde(default)]
10198    pub tag: Option<Box<Expression>>,
10199    #[serde(default)]
10200    pub location: Option<Box<Expression>>,
10201    #[serde(default)]
10202    pub serde: Option<Box<Expression>>,
10203}
10204
10205/// RenameColumn
10206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10207#[cfg_attr(feature = "bindings", derive(TS))]
10208pub struct RenameColumn {
10209    pub this: Box<Expression>,
10210    #[serde(default)]
10211    pub to: Option<Box<Expression>>,
10212    #[serde(default)]
10213    pub exists: bool,
10214}
10215
10216/// Comprehension
10217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10218#[cfg_attr(feature = "bindings", derive(TS))]
10219pub struct Comprehension {
10220    pub this: Box<Expression>,
10221    pub expression: Box<Expression>,
10222    #[serde(default)]
10223    pub position: Option<Box<Expression>>,
10224    #[serde(default)]
10225    pub iterator: Option<Box<Expression>>,
10226    #[serde(default)]
10227    pub condition: Option<Box<Expression>>,
10228}
10229
10230/// MergeTreeTTLAction
10231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10232#[cfg_attr(feature = "bindings", derive(TS))]
10233pub struct MergeTreeTTLAction {
10234    pub this: Box<Expression>,
10235    #[serde(default)]
10236    pub delete: Option<Box<Expression>>,
10237    #[serde(default)]
10238    pub recompress: Option<Box<Expression>>,
10239    #[serde(default)]
10240    pub to_disk: Option<Box<Expression>>,
10241    #[serde(default)]
10242    pub to_volume: Option<Box<Expression>>,
10243}
10244
10245/// MergeTreeTTL
10246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10247#[cfg_attr(feature = "bindings", derive(TS))]
10248pub struct MergeTreeTTL {
10249    #[serde(default)]
10250    pub expressions: Vec<Expression>,
10251    #[serde(default)]
10252    pub where_: Option<Box<Expression>>,
10253    #[serde(default)]
10254    pub group: Option<Box<Expression>>,
10255    #[serde(default)]
10256    pub aggregates: Option<Box<Expression>>,
10257}
10258
10259/// IndexConstraintOption
10260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10261#[cfg_attr(feature = "bindings", derive(TS))]
10262pub struct IndexConstraintOption {
10263    #[serde(default)]
10264    pub key_block_size: Option<Box<Expression>>,
10265    #[serde(default)]
10266    pub using: Option<Box<Expression>>,
10267    #[serde(default)]
10268    pub parser: Option<Box<Expression>>,
10269    #[serde(default)]
10270    pub comment: Option<Box<Expression>>,
10271    #[serde(default)]
10272    pub visible: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub engine_attr: Option<Box<Expression>>,
10275    #[serde(default)]
10276    pub secondary_engine_attr: Option<Box<Expression>>,
10277}
10278
10279/// PeriodForSystemTimeConstraint
10280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10281#[cfg_attr(feature = "bindings", derive(TS))]
10282pub struct PeriodForSystemTimeConstraint {
10283    pub this: Box<Expression>,
10284    pub expression: Box<Expression>,
10285}
10286
10287/// CaseSpecificColumnConstraint
10288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10289#[cfg_attr(feature = "bindings", derive(TS))]
10290pub struct CaseSpecificColumnConstraint {
10291    #[serde(default)]
10292    pub not_: Option<Box<Expression>>,
10293}
10294
10295/// CharacterSetColumnConstraint
10296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10297#[cfg_attr(feature = "bindings", derive(TS))]
10298pub struct CharacterSetColumnConstraint {
10299    pub this: Box<Expression>,
10300}
10301
10302/// CheckColumnConstraint
10303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10304#[cfg_attr(feature = "bindings", derive(TS))]
10305pub struct CheckColumnConstraint {
10306    pub this: Box<Expression>,
10307    #[serde(default)]
10308    pub enforced: Option<Box<Expression>>,
10309}
10310
10311/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10313#[cfg_attr(feature = "bindings", derive(TS))]
10314pub struct AssumeColumnConstraint {
10315    pub this: Box<Expression>,
10316}
10317
10318/// CompressColumnConstraint
10319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10320#[cfg_attr(feature = "bindings", derive(TS))]
10321pub struct CompressColumnConstraint {
10322    #[serde(default)]
10323    pub this: Option<Box<Expression>>,
10324}
10325
10326/// DateFormatColumnConstraint
10327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10328#[cfg_attr(feature = "bindings", derive(TS))]
10329pub struct DateFormatColumnConstraint {
10330    pub this: Box<Expression>,
10331}
10332
10333/// EphemeralColumnConstraint
10334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10335#[cfg_attr(feature = "bindings", derive(TS))]
10336pub struct EphemeralColumnConstraint {
10337    #[serde(default)]
10338    pub this: Option<Box<Expression>>,
10339}
10340
10341/// WithOperator
10342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10343#[cfg_attr(feature = "bindings", derive(TS))]
10344pub struct WithOperator {
10345    pub this: Box<Expression>,
10346    pub op: String,
10347}
10348
10349/// GeneratedAsIdentityColumnConstraint
10350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10351#[cfg_attr(feature = "bindings", derive(TS))]
10352pub struct GeneratedAsIdentityColumnConstraint {
10353    #[serde(default)]
10354    pub this: Option<Box<Expression>>,
10355    #[serde(default)]
10356    pub expression: Option<Box<Expression>>,
10357    #[serde(default)]
10358    pub on_null: Option<Box<Expression>>,
10359    #[serde(default)]
10360    pub start: Option<Box<Expression>>,
10361    #[serde(default)]
10362    pub increment: Option<Box<Expression>>,
10363    #[serde(default)]
10364    pub minvalue: Option<Box<Expression>>,
10365    #[serde(default)]
10366    pub maxvalue: Option<Box<Expression>>,
10367    #[serde(default)]
10368    pub cycle: Option<Box<Expression>>,
10369    #[serde(default)]
10370    pub order: Option<Box<Expression>>,
10371}
10372
10373/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10374/// TSQL: outputs "IDENTITY"
10375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10376#[cfg_attr(feature = "bindings", derive(TS))]
10377pub struct AutoIncrementColumnConstraint;
10378
10379/// CommentColumnConstraint - Column comment marker
10380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10381#[cfg_attr(feature = "bindings", derive(TS))]
10382pub struct CommentColumnConstraint;
10383
10384/// GeneratedAsRowColumnConstraint
10385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10386#[cfg_attr(feature = "bindings", derive(TS))]
10387pub struct GeneratedAsRowColumnConstraint {
10388    #[serde(default)]
10389    pub start: Option<Box<Expression>>,
10390    #[serde(default)]
10391    pub hidden: Option<Box<Expression>>,
10392}
10393
10394/// IndexColumnConstraint
10395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10396#[cfg_attr(feature = "bindings", derive(TS))]
10397pub struct IndexColumnConstraint {
10398    #[serde(default)]
10399    pub this: Option<Box<Expression>>,
10400    #[serde(default)]
10401    pub expressions: Vec<Expression>,
10402    #[serde(default)]
10403    pub kind: Option<String>,
10404    #[serde(default)]
10405    pub index_type: Option<Box<Expression>>,
10406    #[serde(default)]
10407    pub options: Vec<Expression>,
10408    #[serde(default)]
10409    pub expression: Option<Box<Expression>>,
10410    #[serde(default)]
10411    pub granularity: Option<Box<Expression>>,
10412}
10413
10414/// MaskingPolicyColumnConstraint
10415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10416#[cfg_attr(feature = "bindings", derive(TS))]
10417pub struct MaskingPolicyColumnConstraint {
10418    pub this: Box<Expression>,
10419    #[serde(default)]
10420    pub expressions: Vec<Expression>,
10421}
10422
10423/// NotNullColumnConstraint
10424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10425#[cfg_attr(feature = "bindings", derive(TS))]
10426pub struct NotNullColumnConstraint {
10427    #[serde(default)]
10428    pub allow_null: Option<Box<Expression>>,
10429}
10430
10431/// DefaultColumnConstraint - DEFAULT value for a column
10432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10433#[cfg_attr(feature = "bindings", derive(TS))]
10434pub struct DefaultColumnConstraint {
10435    pub this: Box<Expression>,
10436    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10437    #[serde(default, skip_serializing_if = "Option::is_none")]
10438    pub for_column: Option<Identifier>,
10439}
10440
10441/// PrimaryKeyColumnConstraint
10442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10443#[cfg_attr(feature = "bindings", derive(TS))]
10444pub struct PrimaryKeyColumnConstraint {
10445    #[serde(default)]
10446    pub desc: Option<Box<Expression>>,
10447    #[serde(default)]
10448    pub options: Vec<Expression>,
10449}
10450
10451/// UniqueColumnConstraint
10452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10453#[cfg_attr(feature = "bindings", derive(TS))]
10454pub struct UniqueColumnConstraint {
10455    #[serde(default)]
10456    pub this: Option<Box<Expression>>,
10457    #[serde(default)]
10458    pub index_type: Option<Box<Expression>>,
10459    #[serde(default)]
10460    pub on_conflict: Option<Box<Expression>>,
10461    #[serde(default)]
10462    pub nulls: Option<Box<Expression>>,
10463    #[serde(default)]
10464    pub options: Vec<Expression>,
10465}
10466
10467/// WatermarkColumnConstraint
10468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10469#[cfg_attr(feature = "bindings", derive(TS))]
10470pub struct WatermarkColumnConstraint {
10471    pub this: Box<Expression>,
10472    pub expression: Box<Expression>,
10473}
10474
10475/// ComputedColumnConstraint
10476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10477#[cfg_attr(feature = "bindings", derive(TS))]
10478pub struct ComputedColumnConstraint {
10479    pub this: Box<Expression>,
10480    #[serde(default)]
10481    pub persisted: Option<Box<Expression>>,
10482    #[serde(default)]
10483    pub not_null: Option<Box<Expression>>,
10484    #[serde(default)]
10485    pub data_type: Option<Box<Expression>>,
10486}
10487
10488/// InOutColumnConstraint
10489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10490#[cfg_attr(feature = "bindings", derive(TS))]
10491pub struct InOutColumnConstraint {
10492    #[serde(default)]
10493    pub input_: Option<Box<Expression>>,
10494    #[serde(default)]
10495    pub output: Option<Box<Expression>>,
10496}
10497
10498/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10500#[cfg_attr(feature = "bindings", derive(TS))]
10501pub struct PathColumnConstraint {
10502    pub this: Box<Expression>,
10503}
10504
10505/// Constraint
10506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10507#[cfg_attr(feature = "bindings", derive(TS))]
10508pub struct Constraint {
10509    pub this: Box<Expression>,
10510    #[serde(default)]
10511    pub expressions: Vec<Expression>,
10512}
10513
10514/// Export
10515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10516#[cfg_attr(feature = "bindings", derive(TS))]
10517pub struct Export {
10518    pub this: Box<Expression>,
10519    #[serde(default)]
10520    pub connection: Option<Box<Expression>>,
10521    #[serde(default)]
10522    pub options: Vec<Expression>,
10523}
10524
10525/// Filter
10526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10527#[cfg_attr(feature = "bindings", derive(TS))]
10528pub struct Filter {
10529    pub this: Box<Expression>,
10530    pub expression: Box<Expression>,
10531}
10532
10533/// Changes
10534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10535#[cfg_attr(feature = "bindings", derive(TS))]
10536pub struct Changes {
10537    #[serde(default)]
10538    pub information: Option<Box<Expression>>,
10539    #[serde(default)]
10540    pub at_before: Option<Box<Expression>>,
10541    #[serde(default)]
10542    pub end: Option<Box<Expression>>,
10543}
10544
10545/// Directory
10546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10547#[cfg_attr(feature = "bindings", derive(TS))]
10548pub struct Directory {
10549    pub this: Box<Expression>,
10550    #[serde(default)]
10551    pub local: Option<Box<Expression>>,
10552    #[serde(default)]
10553    pub row_format: Option<Box<Expression>>,
10554}
10555
10556/// ForeignKey
10557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10558#[cfg_attr(feature = "bindings", derive(TS))]
10559pub struct ForeignKey {
10560    #[serde(default)]
10561    pub expressions: Vec<Expression>,
10562    #[serde(default)]
10563    pub reference: Option<Box<Expression>>,
10564    #[serde(default)]
10565    pub delete: Option<Box<Expression>>,
10566    #[serde(default)]
10567    pub update: Option<Box<Expression>>,
10568    #[serde(default)]
10569    pub options: Vec<Expression>,
10570}
10571
10572/// ColumnPrefix
10573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10574#[cfg_attr(feature = "bindings", derive(TS))]
10575pub struct ColumnPrefix {
10576    pub this: Box<Expression>,
10577    pub expression: Box<Expression>,
10578}
10579
10580/// PrimaryKey
10581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10582#[cfg_attr(feature = "bindings", derive(TS))]
10583pub struct PrimaryKey {
10584    #[serde(default)]
10585    pub this: Option<Box<Expression>>,
10586    #[serde(default)]
10587    pub expressions: Vec<Expression>,
10588    #[serde(default)]
10589    pub options: Vec<Expression>,
10590    #[serde(default)]
10591    pub include: Option<Box<Expression>>,
10592}
10593
10594/// Into
10595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10596#[cfg_attr(feature = "bindings", derive(TS))]
10597pub struct IntoClause {
10598    #[serde(default)]
10599    pub this: Option<Box<Expression>>,
10600    #[serde(default)]
10601    pub temporary: bool,
10602    #[serde(default)]
10603    pub unlogged: Option<Box<Expression>>,
10604    #[serde(default)]
10605    pub bulk_collect: Option<Box<Expression>>,
10606    #[serde(default)]
10607    pub expressions: Vec<Expression>,
10608}
10609
10610/// JoinHint
10611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10612#[cfg_attr(feature = "bindings", derive(TS))]
10613pub struct JoinHint {
10614    pub this: Box<Expression>,
10615    #[serde(default)]
10616    pub expressions: Vec<Expression>,
10617}
10618
10619/// Opclass
10620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10621#[cfg_attr(feature = "bindings", derive(TS))]
10622pub struct Opclass {
10623    pub this: Box<Expression>,
10624    pub expression: Box<Expression>,
10625}
10626
10627/// Index
10628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10629#[cfg_attr(feature = "bindings", derive(TS))]
10630pub struct Index {
10631    #[serde(default)]
10632    pub this: Option<Box<Expression>>,
10633    #[serde(default)]
10634    pub table: Option<Box<Expression>>,
10635    #[serde(default)]
10636    pub unique: bool,
10637    #[serde(default)]
10638    pub primary: Option<Box<Expression>>,
10639    #[serde(default)]
10640    pub amp: Option<Box<Expression>>,
10641    #[serde(default)]
10642    pub params: Vec<Expression>,
10643}
10644
10645/// IndexParameters
10646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10647#[cfg_attr(feature = "bindings", derive(TS))]
10648pub struct IndexParameters {
10649    #[serde(default)]
10650    pub using: Option<Box<Expression>>,
10651    #[serde(default)]
10652    pub include: Option<Box<Expression>>,
10653    #[serde(default)]
10654    pub columns: Vec<Expression>,
10655    #[serde(default)]
10656    pub with_storage: Option<Box<Expression>>,
10657    #[serde(default)]
10658    pub partition_by: Option<Box<Expression>>,
10659    #[serde(default)]
10660    pub tablespace: Option<Box<Expression>>,
10661    #[serde(default)]
10662    pub where_: Option<Box<Expression>>,
10663    #[serde(default)]
10664    pub on: Option<Box<Expression>>,
10665}
10666
10667/// ConditionalInsert
10668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10669#[cfg_attr(feature = "bindings", derive(TS))]
10670pub struct ConditionalInsert {
10671    pub this: Box<Expression>,
10672    #[serde(default)]
10673    pub expression: Option<Box<Expression>>,
10674    #[serde(default)]
10675    pub else_: Option<Box<Expression>>,
10676}
10677
10678/// MultitableInserts
10679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10680#[cfg_attr(feature = "bindings", derive(TS))]
10681pub struct MultitableInserts {
10682    #[serde(default)]
10683    pub expressions: Vec<Expression>,
10684    pub kind: String,
10685    #[serde(default)]
10686    pub source: Option<Box<Expression>>,
10687    /// Leading comments before the statement
10688    #[serde(default)]
10689    pub leading_comments: Vec<String>,
10690    /// OVERWRITE modifier (Snowflake: INSERT OVERWRITE ALL)
10691    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10692    pub overwrite: bool,
10693}
10694
10695/// OnConflict
10696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10697#[cfg_attr(feature = "bindings", derive(TS))]
10698pub struct OnConflict {
10699    #[serde(default)]
10700    pub duplicate: Option<Box<Expression>>,
10701    #[serde(default)]
10702    pub expressions: Vec<Expression>,
10703    #[serde(default)]
10704    pub action: Option<Box<Expression>>,
10705    #[serde(default)]
10706    pub conflict_keys: Option<Box<Expression>>,
10707    #[serde(default)]
10708    pub index_predicate: Option<Box<Expression>>,
10709    #[serde(default)]
10710    pub constraint: Option<Box<Expression>>,
10711    #[serde(default)]
10712    pub where_: Option<Box<Expression>>,
10713}
10714
10715/// OnCondition
10716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10717#[cfg_attr(feature = "bindings", derive(TS))]
10718pub struct OnCondition {
10719    #[serde(default)]
10720    pub error: Option<Box<Expression>>,
10721    #[serde(default)]
10722    pub empty: Option<Box<Expression>>,
10723    #[serde(default)]
10724    pub null: Option<Box<Expression>>,
10725}
10726
10727/// Returning
10728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10729#[cfg_attr(feature = "bindings", derive(TS))]
10730pub struct Returning {
10731    #[serde(default)]
10732    pub expressions: Vec<Expression>,
10733    #[serde(default)]
10734    pub into: Option<Box<Expression>>,
10735}
10736
10737/// Introducer
10738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10739#[cfg_attr(feature = "bindings", derive(TS))]
10740pub struct Introducer {
10741    pub this: Box<Expression>,
10742    pub expression: Box<Expression>,
10743}
10744
10745/// PartitionRange
10746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10747#[cfg_attr(feature = "bindings", derive(TS))]
10748pub struct PartitionRange {
10749    pub this: Box<Expression>,
10750    #[serde(default)]
10751    pub expression: Option<Box<Expression>>,
10752    #[serde(default)]
10753    pub expressions: Vec<Expression>,
10754}
10755
10756/// Group
10757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10758#[cfg_attr(feature = "bindings", derive(TS))]
10759pub struct Group {
10760    #[serde(default)]
10761    pub expressions: Vec<Expression>,
10762    #[serde(default)]
10763    pub grouping_sets: Option<Box<Expression>>,
10764    #[serde(default)]
10765    pub cube: Option<Box<Expression>>,
10766    #[serde(default)]
10767    pub rollup: Option<Box<Expression>>,
10768    #[serde(default)]
10769    pub totals: Option<Box<Expression>>,
10770    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10771    #[serde(default)]
10772    pub all: Option<bool>,
10773}
10774
10775/// Cube
10776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10777#[cfg_attr(feature = "bindings", derive(TS))]
10778pub struct Cube {
10779    #[serde(default)]
10780    pub expressions: Vec<Expression>,
10781}
10782
10783/// Rollup
10784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10785#[cfg_attr(feature = "bindings", derive(TS))]
10786pub struct Rollup {
10787    #[serde(default)]
10788    pub expressions: Vec<Expression>,
10789}
10790
10791/// GroupingSets
10792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10793#[cfg_attr(feature = "bindings", derive(TS))]
10794pub struct GroupingSets {
10795    #[serde(default)]
10796    pub expressions: Vec<Expression>,
10797}
10798
10799/// LimitOptions
10800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10801#[cfg_attr(feature = "bindings", derive(TS))]
10802pub struct LimitOptions {
10803    #[serde(default)]
10804    pub percent: Option<Box<Expression>>,
10805    #[serde(default)]
10806    pub rows: Option<Box<Expression>>,
10807    #[serde(default)]
10808    pub with_ties: Option<Box<Expression>>,
10809}
10810
10811/// Lateral
10812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10813#[cfg_attr(feature = "bindings", derive(TS))]
10814pub struct Lateral {
10815    pub this: Box<Expression>,
10816    #[serde(default)]
10817    pub view: Option<Box<Expression>>,
10818    #[serde(default)]
10819    pub outer: Option<Box<Expression>>,
10820    #[serde(default)]
10821    pub alias: Option<String>,
10822    /// Whether the alias was originally quoted (backtick/double-quote)
10823    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10824    pub alias_quoted: bool,
10825    #[serde(default)]
10826    pub cross_apply: Option<Box<Expression>>,
10827    #[serde(default)]
10828    pub ordinality: Option<Box<Expression>>,
10829    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10830    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10831    pub column_aliases: Vec<String>,
10832}
10833
10834/// TableFromRows
10835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10836#[cfg_attr(feature = "bindings", derive(TS))]
10837pub struct TableFromRows {
10838    pub this: Box<Expression>,
10839    #[serde(default)]
10840    pub alias: Option<String>,
10841    #[serde(default)]
10842    pub joins: Vec<Expression>,
10843    #[serde(default)]
10844    pub pivots: Option<Box<Expression>>,
10845    #[serde(default)]
10846    pub sample: Option<Box<Expression>>,
10847}
10848
10849/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10850/// Used for set-returning functions with typed column definitions
10851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10852#[cfg_attr(feature = "bindings", derive(TS))]
10853pub struct RowsFrom {
10854    /// List of function expressions, each potentially with an alias and typed columns
10855    pub expressions: Vec<Expression>,
10856    /// WITH ORDINALITY modifier
10857    #[serde(default)]
10858    pub ordinality: bool,
10859    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10860    #[serde(default)]
10861    pub alias: Option<Box<Expression>>,
10862}
10863
10864/// WithFill
10865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10866#[cfg_attr(feature = "bindings", derive(TS))]
10867pub struct WithFill {
10868    #[serde(default)]
10869    pub from_: Option<Box<Expression>>,
10870    #[serde(default)]
10871    pub to: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub step: Option<Box<Expression>>,
10874    #[serde(default)]
10875    pub staleness: Option<Box<Expression>>,
10876    #[serde(default)]
10877    pub interpolate: Option<Box<Expression>>,
10878}
10879
10880/// Property
10881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10882#[cfg_attr(feature = "bindings", derive(TS))]
10883pub struct Property {
10884    pub this: Box<Expression>,
10885    #[serde(default)]
10886    pub value: Option<Box<Expression>>,
10887}
10888
10889/// GrantPrivilege
10890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10891#[cfg_attr(feature = "bindings", derive(TS))]
10892pub struct GrantPrivilege {
10893    pub this: Box<Expression>,
10894    #[serde(default)]
10895    pub expressions: Vec<Expression>,
10896}
10897
10898/// AllowedValuesProperty
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct AllowedValuesProperty {
10902    #[serde(default)]
10903    pub expressions: Vec<Expression>,
10904}
10905
10906/// AlgorithmProperty
10907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10908#[cfg_attr(feature = "bindings", derive(TS))]
10909pub struct AlgorithmProperty {
10910    pub this: Box<Expression>,
10911}
10912
10913/// AutoIncrementProperty
10914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10915#[cfg_attr(feature = "bindings", derive(TS))]
10916pub struct AutoIncrementProperty {
10917    pub this: Box<Expression>,
10918}
10919
10920/// AutoRefreshProperty
10921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10922#[cfg_attr(feature = "bindings", derive(TS))]
10923pub struct AutoRefreshProperty {
10924    pub this: Box<Expression>,
10925}
10926
10927/// BackupProperty
10928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10929#[cfg_attr(feature = "bindings", derive(TS))]
10930pub struct BackupProperty {
10931    pub this: Box<Expression>,
10932}
10933
10934/// BuildProperty
10935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10936#[cfg_attr(feature = "bindings", derive(TS))]
10937pub struct BuildProperty {
10938    pub this: Box<Expression>,
10939}
10940
10941/// BlockCompressionProperty
10942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10943#[cfg_attr(feature = "bindings", derive(TS))]
10944pub struct BlockCompressionProperty {
10945    #[serde(default)]
10946    pub autotemp: Option<Box<Expression>>,
10947    #[serde(default)]
10948    pub always: Option<Box<Expression>>,
10949    #[serde(default)]
10950    pub default: Option<Box<Expression>>,
10951    #[serde(default)]
10952    pub manual: Option<Box<Expression>>,
10953    #[serde(default)]
10954    pub never: Option<Box<Expression>>,
10955}
10956
10957/// CharacterSetProperty
10958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10959#[cfg_attr(feature = "bindings", derive(TS))]
10960pub struct CharacterSetProperty {
10961    pub this: Box<Expression>,
10962    #[serde(default)]
10963    pub default: Option<Box<Expression>>,
10964}
10965
10966/// ChecksumProperty
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct ChecksumProperty {
10970    #[serde(default)]
10971    pub on: Option<Box<Expression>>,
10972    #[serde(default)]
10973    pub default: Option<Box<Expression>>,
10974}
10975
10976/// CollateProperty
10977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10978#[cfg_attr(feature = "bindings", derive(TS))]
10979pub struct CollateProperty {
10980    pub this: Box<Expression>,
10981    #[serde(default)]
10982    pub default: Option<Box<Expression>>,
10983}
10984
10985/// DataBlocksizeProperty
10986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10987#[cfg_attr(feature = "bindings", derive(TS))]
10988pub struct DataBlocksizeProperty {
10989    #[serde(default)]
10990    pub size: Option<i64>,
10991    #[serde(default)]
10992    pub units: Option<Box<Expression>>,
10993    #[serde(default)]
10994    pub minimum: Option<Box<Expression>>,
10995    #[serde(default)]
10996    pub maximum: Option<Box<Expression>>,
10997    #[serde(default)]
10998    pub default: Option<Box<Expression>>,
10999}
11000
11001/// DataDeletionProperty
11002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11003#[cfg_attr(feature = "bindings", derive(TS))]
11004pub struct DataDeletionProperty {
11005    pub on: Box<Expression>,
11006    #[serde(default)]
11007    pub filter_column: Option<Box<Expression>>,
11008    #[serde(default)]
11009    pub retention_period: Option<Box<Expression>>,
11010}
11011
11012/// DefinerProperty
11013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11014#[cfg_attr(feature = "bindings", derive(TS))]
11015pub struct DefinerProperty {
11016    pub this: Box<Expression>,
11017}
11018
11019/// DistKeyProperty
11020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11021#[cfg_attr(feature = "bindings", derive(TS))]
11022pub struct DistKeyProperty {
11023    pub this: Box<Expression>,
11024}
11025
11026/// DistributedByProperty
11027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11028#[cfg_attr(feature = "bindings", derive(TS))]
11029pub struct DistributedByProperty {
11030    #[serde(default)]
11031    pub expressions: Vec<Expression>,
11032    pub kind: String,
11033    #[serde(default)]
11034    pub buckets: Option<Box<Expression>>,
11035    #[serde(default)]
11036    pub order: Option<Box<Expression>>,
11037}
11038
11039/// DistStyleProperty
11040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11041#[cfg_attr(feature = "bindings", derive(TS))]
11042pub struct DistStyleProperty {
11043    pub this: Box<Expression>,
11044}
11045
11046/// DuplicateKeyProperty
11047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11048#[cfg_attr(feature = "bindings", derive(TS))]
11049pub struct DuplicateKeyProperty {
11050    #[serde(default)]
11051    pub expressions: Vec<Expression>,
11052}
11053
11054/// EngineProperty
11055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11056#[cfg_attr(feature = "bindings", derive(TS))]
11057pub struct EngineProperty {
11058    pub this: Box<Expression>,
11059}
11060
11061/// ToTableProperty
11062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11063#[cfg_attr(feature = "bindings", derive(TS))]
11064pub struct ToTableProperty {
11065    pub this: Box<Expression>,
11066}
11067
11068/// ExecuteAsProperty
11069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11070#[cfg_attr(feature = "bindings", derive(TS))]
11071pub struct ExecuteAsProperty {
11072    pub this: Box<Expression>,
11073}
11074
11075/// ExternalProperty
11076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11077#[cfg_attr(feature = "bindings", derive(TS))]
11078pub struct ExternalProperty {
11079    #[serde(default)]
11080    pub this: Option<Box<Expression>>,
11081}
11082
11083/// FallbackProperty
11084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11085#[cfg_attr(feature = "bindings", derive(TS))]
11086pub struct FallbackProperty {
11087    #[serde(default)]
11088    pub no: Option<Box<Expression>>,
11089    #[serde(default)]
11090    pub protection: Option<Box<Expression>>,
11091}
11092
11093/// FileFormatProperty
11094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11095#[cfg_attr(feature = "bindings", derive(TS))]
11096pub struct FileFormatProperty {
11097    #[serde(default)]
11098    pub this: Option<Box<Expression>>,
11099    #[serde(default)]
11100    pub expressions: Vec<Expression>,
11101    #[serde(default)]
11102    pub hive_format: Option<Box<Expression>>,
11103}
11104
11105/// CredentialsProperty
11106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11107#[cfg_attr(feature = "bindings", derive(TS))]
11108pub struct CredentialsProperty {
11109    #[serde(default)]
11110    pub expressions: Vec<Expression>,
11111}
11112
11113/// FreespaceProperty
11114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11115#[cfg_attr(feature = "bindings", derive(TS))]
11116pub struct FreespaceProperty {
11117    pub this: Box<Expression>,
11118    #[serde(default)]
11119    pub percent: Option<Box<Expression>>,
11120}
11121
11122/// InheritsProperty
11123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11124#[cfg_attr(feature = "bindings", derive(TS))]
11125pub struct InheritsProperty {
11126    #[serde(default)]
11127    pub expressions: Vec<Expression>,
11128}
11129
11130/// InputModelProperty
11131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11132#[cfg_attr(feature = "bindings", derive(TS))]
11133pub struct InputModelProperty {
11134    pub this: Box<Expression>,
11135}
11136
11137/// OutputModelProperty
11138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11139#[cfg_attr(feature = "bindings", derive(TS))]
11140pub struct OutputModelProperty {
11141    pub this: Box<Expression>,
11142}
11143
11144/// IsolatedLoadingProperty
11145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11146#[cfg_attr(feature = "bindings", derive(TS))]
11147pub struct IsolatedLoadingProperty {
11148    #[serde(default)]
11149    pub no: Option<Box<Expression>>,
11150    #[serde(default)]
11151    pub concurrent: Option<Box<Expression>>,
11152    #[serde(default)]
11153    pub target: Option<Box<Expression>>,
11154}
11155
11156/// JournalProperty
11157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11158#[cfg_attr(feature = "bindings", derive(TS))]
11159pub struct JournalProperty {
11160    #[serde(default)]
11161    pub no: Option<Box<Expression>>,
11162    #[serde(default)]
11163    pub dual: Option<Box<Expression>>,
11164    #[serde(default)]
11165    pub before: Option<Box<Expression>>,
11166    #[serde(default)]
11167    pub local: Option<Box<Expression>>,
11168    #[serde(default)]
11169    pub after: Option<Box<Expression>>,
11170}
11171
11172/// LanguageProperty
11173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11174#[cfg_attr(feature = "bindings", derive(TS))]
11175pub struct LanguageProperty {
11176    pub this: Box<Expression>,
11177}
11178
11179/// EnviromentProperty
11180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11181#[cfg_attr(feature = "bindings", derive(TS))]
11182pub struct EnviromentProperty {
11183    #[serde(default)]
11184    pub expressions: Vec<Expression>,
11185}
11186
11187/// ClusteredByProperty
11188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11189#[cfg_attr(feature = "bindings", derive(TS))]
11190pub struct ClusteredByProperty {
11191    #[serde(default)]
11192    pub expressions: Vec<Expression>,
11193    #[serde(default)]
11194    pub sorted_by: Option<Box<Expression>>,
11195    #[serde(default)]
11196    pub buckets: Option<Box<Expression>>,
11197}
11198
11199/// DictProperty
11200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11201#[cfg_attr(feature = "bindings", derive(TS))]
11202pub struct DictProperty {
11203    pub this: Box<Expression>,
11204    pub kind: String,
11205    #[serde(default)]
11206    pub settings: Option<Box<Expression>>,
11207}
11208
11209/// DictRange
11210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11211#[cfg_attr(feature = "bindings", derive(TS))]
11212pub struct DictRange {
11213    pub this: Box<Expression>,
11214    #[serde(default)]
11215    pub min: Option<Box<Expression>>,
11216    #[serde(default)]
11217    pub max: Option<Box<Expression>>,
11218}
11219
11220/// OnCluster
11221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11222#[cfg_attr(feature = "bindings", derive(TS))]
11223pub struct OnCluster {
11224    pub this: Box<Expression>,
11225}
11226
11227/// LikeProperty
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct LikeProperty {
11231    pub this: Box<Expression>,
11232    #[serde(default)]
11233    pub expressions: Vec<Expression>,
11234}
11235
11236/// LocationProperty
11237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11238#[cfg_attr(feature = "bindings", derive(TS))]
11239pub struct LocationProperty {
11240    pub this: Box<Expression>,
11241}
11242
11243/// LockProperty
11244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11245#[cfg_attr(feature = "bindings", derive(TS))]
11246pub struct LockProperty {
11247    pub this: Box<Expression>,
11248}
11249
11250/// LockingProperty
11251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11252#[cfg_attr(feature = "bindings", derive(TS))]
11253pub struct LockingProperty {
11254    #[serde(default)]
11255    pub this: Option<Box<Expression>>,
11256    pub kind: String,
11257    #[serde(default)]
11258    pub for_or_in: Option<Box<Expression>>,
11259    #[serde(default)]
11260    pub lock_type: Option<Box<Expression>>,
11261    #[serde(default)]
11262    pub override_: Option<Box<Expression>>,
11263}
11264
11265/// LogProperty
11266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11267#[cfg_attr(feature = "bindings", derive(TS))]
11268pub struct LogProperty {
11269    #[serde(default)]
11270    pub no: Option<Box<Expression>>,
11271}
11272
11273/// MaterializedProperty
11274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11275#[cfg_attr(feature = "bindings", derive(TS))]
11276pub struct MaterializedProperty {
11277    #[serde(default)]
11278    pub this: Option<Box<Expression>>,
11279}
11280
11281/// MergeBlockRatioProperty
11282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11283#[cfg_attr(feature = "bindings", derive(TS))]
11284pub struct MergeBlockRatioProperty {
11285    #[serde(default)]
11286    pub this: Option<Box<Expression>>,
11287    #[serde(default)]
11288    pub no: Option<Box<Expression>>,
11289    #[serde(default)]
11290    pub default: Option<Box<Expression>>,
11291    #[serde(default)]
11292    pub percent: Option<Box<Expression>>,
11293}
11294
11295/// OnProperty
11296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11297#[cfg_attr(feature = "bindings", derive(TS))]
11298pub struct OnProperty {
11299    pub this: Box<Expression>,
11300}
11301
11302/// OnCommitProperty
11303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11304#[cfg_attr(feature = "bindings", derive(TS))]
11305pub struct OnCommitProperty {
11306    #[serde(default)]
11307    pub delete: Option<Box<Expression>>,
11308}
11309
11310/// PartitionedByProperty
11311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11312#[cfg_attr(feature = "bindings", derive(TS))]
11313pub struct PartitionedByProperty {
11314    pub this: Box<Expression>,
11315}
11316
11317/// BigQuery PARTITION BY property in CREATE TABLE statements.
11318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11319#[cfg_attr(feature = "bindings", derive(TS))]
11320pub struct PartitionByProperty {
11321    #[serde(default)]
11322    pub expressions: Vec<Expression>,
11323}
11324
11325/// PartitionedByBucket
11326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11327#[cfg_attr(feature = "bindings", derive(TS))]
11328pub struct PartitionedByBucket {
11329    pub this: Box<Expression>,
11330    pub expression: Box<Expression>,
11331}
11332
11333/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11335#[cfg_attr(feature = "bindings", derive(TS))]
11336pub struct ClusterByColumnsProperty {
11337    #[serde(default)]
11338    pub columns: Vec<Identifier>,
11339}
11340
11341/// PartitionByTruncate
11342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11343#[cfg_attr(feature = "bindings", derive(TS))]
11344pub struct PartitionByTruncate {
11345    pub this: Box<Expression>,
11346    pub expression: Box<Expression>,
11347}
11348
11349/// PartitionByRangeProperty
11350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11351#[cfg_attr(feature = "bindings", derive(TS))]
11352pub struct PartitionByRangeProperty {
11353    #[serde(default)]
11354    pub partition_expressions: Option<Box<Expression>>,
11355    #[serde(default)]
11356    pub create_expressions: Option<Box<Expression>>,
11357}
11358
11359/// PartitionByRangePropertyDynamic
11360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11361#[cfg_attr(feature = "bindings", derive(TS))]
11362pub struct PartitionByRangePropertyDynamic {
11363    #[serde(default)]
11364    pub this: Option<Box<Expression>>,
11365    #[serde(default)]
11366    pub start: Option<Box<Expression>>,
11367    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11368    #[serde(default)]
11369    pub use_start_end: bool,
11370    #[serde(default)]
11371    pub end: Option<Box<Expression>>,
11372    #[serde(default)]
11373    pub every: Option<Box<Expression>>,
11374}
11375
11376/// PartitionByListProperty
11377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11378#[cfg_attr(feature = "bindings", derive(TS))]
11379pub struct PartitionByListProperty {
11380    #[serde(default)]
11381    pub partition_expressions: Option<Box<Expression>>,
11382    #[serde(default)]
11383    pub create_expressions: Option<Box<Expression>>,
11384}
11385
11386/// PartitionList
11387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11388#[cfg_attr(feature = "bindings", derive(TS))]
11389pub struct PartitionList {
11390    pub this: Box<Expression>,
11391    #[serde(default)]
11392    pub expressions: Vec<Expression>,
11393}
11394
11395/// Partition - represents PARTITION/SUBPARTITION clause
11396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11397#[cfg_attr(feature = "bindings", derive(TS))]
11398pub struct Partition {
11399    pub expressions: Vec<Expression>,
11400    #[serde(default)]
11401    pub subpartition: bool,
11402}
11403
11404/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11405/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11407#[cfg_attr(feature = "bindings", derive(TS))]
11408pub struct RefreshTriggerProperty {
11409    /// Method: COMPLETE or AUTO
11410    pub method: String,
11411    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11412    #[serde(default)]
11413    pub kind: Option<String>,
11414    /// For SCHEDULE: EVERY n (the number)
11415    #[serde(default)]
11416    pub every: Option<Box<Expression>>,
11417    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11418    #[serde(default)]
11419    pub unit: Option<String>,
11420    /// For SCHEDULE: STARTS 'datetime'
11421    #[serde(default)]
11422    pub starts: Option<Box<Expression>>,
11423}
11424
11425/// UniqueKeyProperty
11426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11427#[cfg_attr(feature = "bindings", derive(TS))]
11428pub struct UniqueKeyProperty {
11429    #[serde(default)]
11430    pub expressions: Vec<Expression>,
11431}
11432
11433/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11435#[cfg_attr(feature = "bindings", derive(TS))]
11436pub struct RollupProperty {
11437    pub expressions: Vec<RollupIndex>,
11438}
11439
11440/// RollupIndex - A single rollup index: name(col1, col2)
11441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11442#[cfg_attr(feature = "bindings", derive(TS))]
11443pub struct RollupIndex {
11444    pub name: Identifier,
11445    pub expressions: Vec<Identifier>,
11446}
11447
11448/// PartitionBoundSpec
11449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11450#[cfg_attr(feature = "bindings", derive(TS))]
11451pub struct PartitionBoundSpec {
11452    #[serde(default)]
11453    pub this: Option<Box<Expression>>,
11454    #[serde(default)]
11455    pub expression: Option<Box<Expression>>,
11456    #[serde(default)]
11457    pub from_expressions: Option<Box<Expression>>,
11458    #[serde(default)]
11459    pub to_expressions: Option<Box<Expression>>,
11460}
11461
11462/// PartitionedOfProperty
11463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11464#[cfg_attr(feature = "bindings", derive(TS))]
11465pub struct PartitionedOfProperty {
11466    pub this: Box<Expression>,
11467    pub expression: Box<Expression>,
11468}
11469
11470/// RemoteWithConnectionModelProperty
11471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11472#[cfg_attr(feature = "bindings", derive(TS))]
11473pub struct RemoteWithConnectionModelProperty {
11474    pub this: Box<Expression>,
11475}
11476
11477/// ReturnsProperty
11478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11479#[cfg_attr(feature = "bindings", derive(TS))]
11480pub struct ReturnsProperty {
11481    #[serde(default)]
11482    pub this: Option<Box<Expression>>,
11483    #[serde(default)]
11484    pub is_table: Option<Box<Expression>>,
11485    #[serde(default)]
11486    pub table: Option<Box<Expression>>,
11487    #[serde(default)]
11488    pub null: Option<Box<Expression>>,
11489}
11490
11491/// RowFormatProperty
11492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11493#[cfg_attr(feature = "bindings", derive(TS))]
11494pub struct RowFormatProperty {
11495    pub this: Box<Expression>,
11496}
11497
11498/// RowFormatDelimitedProperty
11499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11500#[cfg_attr(feature = "bindings", derive(TS))]
11501pub struct RowFormatDelimitedProperty {
11502    #[serde(default)]
11503    pub fields: Option<Box<Expression>>,
11504    #[serde(default)]
11505    pub escaped: Option<Box<Expression>>,
11506    #[serde(default)]
11507    pub collection_items: Option<Box<Expression>>,
11508    #[serde(default)]
11509    pub map_keys: Option<Box<Expression>>,
11510    #[serde(default)]
11511    pub lines: Option<Box<Expression>>,
11512    #[serde(default)]
11513    pub null: Option<Box<Expression>>,
11514    #[serde(default)]
11515    pub serde: Option<Box<Expression>>,
11516}
11517
11518/// RowFormatSerdeProperty
11519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11520#[cfg_attr(feature = "bindings", derive(TS))]
11521pub struct RowFormatSerdeProperty {
11522    pub this: Box<Expression>,
11523    #[serde(default)]
11524    pub serde_properties: Option<Box<Expression>>,
11525}
11526
11527/// QueryTransform
11528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11529#[cfg_attr(feature = "bindings", derive(TS))]
11530pub struct QueryTransform {
11531    #[serde(default)]
11532    pub expressions: Vec<Expression>,
11533    #[serde(default)]
11534    pub command_script: Option<Box<Expression>>,
11535    #[serde(default)]
11536    pub schema: Option<Box<Expression>>,
11537    #[serde(default)]
11538    pub row_format_before: Option<Box<Expression>>,
11539    #[serde(default)]
11540    pub record_writer: Option<Box<Expression>>,
11541    #[serde(default)]
11542    pub row_format_after: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub record_reader: Option<Box<Expression>>,
11545}
11546
11547/// SampleProperty
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct SampleProperty {
11551    pub this: Box<Expression>,
11552}
11553
11554/// SecurityProperty
11555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11556#[cfg_attr(feature = "bindings", derive(TS))]
11557pub struct SecurityProperty {
11558    pub this: Box<Expression>,
11559}
11560
11561/// SchemaCommentProperty
11562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11563#[cfg_attr(feature = "bindings", derive(TS))]
11564pub struct SchemaCommentProperty {
11565    pub this: Box<Expression>,
11566}
11567
11568/// SemanticView
11569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11570#[cfg_attr(feature = "bindings", derive(TS))]
11571pub struct SemanticView {
11572    pub this: Box<Expression>,
11573    #[serde(default)]
11574    pub metrics: Option<Box<Expression>>,
11575    #[serde(default)]
11576    pub dimensions: Option<Box<Expression>>,
11577    #[serde(default)]
11578    pub facts: Option<Box<Expression>>,
11579    #[serde(default)]
11580    pub where_: Option<Box<Expression>>,
11581}
11582
11583/// SerdeProperties
11584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11585#[cfg_attr(feature = "bindings", derive(TS))]
11586pub struct SerdeProperties {
11587    #[serde(default)]
11588    pub expressions: Vec<Expression>,
11589    #[serde(default)]
11590    pub with_: Option<Box<Expression>>,
11591}
11592
11593/// SetProperty
11594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11595#[cfg_attr(feature = "bindings", derive(TS))]
11596pub struct SetProperty {
11597    #[serde(default)]
11598    pub multi: Option<Box<Expression>>,
11599}
11600
11601/// SharingProperty
11602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11603#[cfg_attr(feature = "bindings", derive(TS))]
11604pub struct SharingProperty {
11605    #[serde(default)]
11606    pub this: Option<Box<Expression>>,
11607}
11608
11609/// SetConfigProperty
11610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11611#[cfg_attr(feature = "bindings", derive(TS))]
11612pub struct SetConfigProperty {
11613    pub this: Box<Expression>,
11614}
11615
11616/// SettingsProperty
11617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11618#[cfg_attr(feature = "bindings", derive(TS))]
11619pub struct SettingsProperty {
11620    #[serde(default)]
11621    pub expressions: Vec<Expression>,
11622}
11623
11624/// SortKeyProperty
11625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11626#[cfg_attr(feature = "bindings", derive(TS))]
11627pub struct SortKeyProperty {
11628    pub this: Box<Expression>,
11629    #[serde(default)]
11630    pub compound: Option<Box<Expression>>,
11631}
11632
11633/// SqlReadWriteProperty
11634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11635#[cfg_attr(feature = "bindings", derive(TS))]
11636pub struct SqlReadWriteProperty {
11637    pub this: Box<Expression>,
11638}
11639
11640/// SqlSecurityProperty
11641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11642#[cfg_attr(feature = "bindings", derive(TS))]
11643pub struct SqlSecurityProperty {
11644    pub this: Box<Expression>,
11645}
11646
11647/// StabilityProperty
11648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11649#[cfg_attr(feature = "bindings", derive(TS))]
11650pub struct StabilityProperty {
11651    pub this: Box<Expression>,
11652}
11653
11654/// StorageHandlerProperty
11655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11656#[cfg_attr(feature = "bindings", derive(TS))]
11657pub struct StorageHandlerProperty {
11658    pub this: Box<Expression>,
11659}
11660
11661/// TemporaryProperty
11662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11663#[cfg_attr(feature = "bindings", derive(TS))]
11664pub struct TemporaryProperty {
11665    #[serde(default)]
11666    pub this: Option<Box<Expression>>,
11667}
11668
11669/// Tags
11670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11671#[cfg_attr(feature = "bindings", derive(TS))]
11672pub struct Tags {
11673    #[serde(default)]
11674    pub expressions: Vec<Expression>,
11675}
11676
11677/// TransformModelProperty
11678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11679#[cfg_attr(feature = "bindings", derive(TS))]
11680pub struct TransformModelProperty {
11681    #[serde(default)]
11682    pub expressions: Vec<Expression>,
11683}
11684
11685/// TransientProperty
11686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11687#[cfg_attr(feature = "bindings", derive(TS))]
11688pub struct TransientProperty {
11689    #[serde(default)]
11690    pub this: Option<Box<Expression>>,
11691}
11692
11693/// UsingTemplateProperty
11694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11695#[cfg_attr(feature = "bindings", derive(TS))]
11696pub struct UsingTemplateProperty {
11697    pub this: Box<Expression>,
11698}
11699
11700/// ViewAttributeProperty
11701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11702#[cfg_attr(feature = "bindings", derive(TS))]
11703pub struct ViewAttributeProperty {
11704    pub this: Box<Expression>,
11705}
11706
11707/// VolatileProperty
11708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11709#[cfg_attr(feature = "bindings", derive(TS))]
11710pub struct VolatileProperty {
11711    #[serde(default)]
11712    pub this: Option<Box<Expression>>,
11713}
11714
11715/// WithDataProperty
11716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11717#[cfg_attr(feature = "bindings", derive(TS))]
11718pub struct WithDataProperty {
11719    #[serde(default)]
11720    pub no: Option<Box<Expression>>,
11721    #[serde(default)]
11722    pub statistics: Option<Box<Expression>>,
11723}
11724
11725/// WithJournalTableProperty
11726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11727#[cfg_attr(feature = "bindings", derive(TS))]
11728pub struct WithJournalTableProperty {
11729    pub this: Box<Expression>,
11730}
11731
11732/// WithSchemaBindingProperty
11733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11734#[cfg_attr(feature = "bindings", derive(TS))]
11735pub struct WithSchemaBindingProperty {
11736    pub this: Box<Expression>,
11737}
11738
11739/// WithSystemVersioningProperty
11740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11741#[cfg_attr(feature = "bindings", derive(TS))]
11742pub struct WithSystemVersioningProperty {
11743    #[serde(default)]
11744    pub on: Option<Box<Expression>>,
11745    #[serde(default)]
11746    pub this: Option<Box<Expression>>,
11747    #[serde(default)]
11748    pub data_consistency: Option<Box<Expression>>,
11749    #[serde(default)]
11750    pub retention_period: Option<Box<Expression>>,
11751    #[serde(default)]
11752    pub with_: Option<Box<Expression>>,
11753}
11754
11755/// WithProcedureOptions
11756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11757#[cfg_attr(feature = "bindings", derive(TS))]
11758pub struct WithProcedureOptions {
11759    #[serde(default)]
11760    pub expressions: Vec<Expression>,
11761}
11762
11763/// EncodeProperty
11764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11765#[cfg_attr(feature = "bindings", derive(TS))]
11766pub struct EncodeProperty {
11767    pub this: Box<Expression>,
11768    #[serde(default)]
11769    pub properties: Vec<Expression>,
11770    #[serde(default)]
11771    pub key: Option<Box<Expression>>,
11772}
11773
11774/// IncludeProperty
11775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11776#[cfg_attr(feature = "bindings", derive(TS))]
11777pub struct IncludeProperty {
11778    pub this: Box<Expression>,
11779    #[serde(default)]
11780    pub alias: Option<String>,
11781    #[serde(default)]
11782    pub column_def: Option<Box<Expression>>,
11783}
11784
11785/// Properties
11786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11787#[cfg_attr(feature = "bindings", derive(TS))]
11788pub struct Properties {
11789    #[serde(default)]
11790    pub expressions: Vec<Expression>,
11791}
11792
11793/// Key/value pair in a BigQuery OPTIONS (...) clause.
11794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11795#[cfg_attr(feature = "bindings", derive(TS))]
11796pub struct OptionEntry {
11797    pub key: Identifier,
11798    pub value: Expression,
11799}
11800
11801/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11803#[cfg_attr(feature = "bindings", derive(TS))]
11804pub struct OptionsProperty {
11805    #[serde(default)]
11806    pub entries: Vec<OptionEntry>,
11807}
11808
11809/// InputOutputFormat
11810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11811#[cfg_attr(feature = "bindings", derive(TS))]
11812pub struct InputOutputFormat {
11813    #[serde(default)]
11814    pub input_format: Option<Box<Expression>>,
11815    #[serde(default)]
11816    pub output_format: Option<Box<Expression>>,
11817}
11818
11819/// Reference
11820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11821#[cfg_attr(feature = "bindings", derive(TS))]
11822pub struct Reference {
11823    pub this: Box<Expression>,
11824    #[serde(default)]
11825    pub expressions: Vec<Expression>,
11826    #[serde(default)]
11827    pub options: Vec<Expression>,
11828}
11829
11830/// QueryOption
11831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11832#[cfg_attr(feature = "bindings", derive(TS))]
11833pub struct QueryOption {
11834    pub this: Box<Expression>,
11835    #[serde(default)]
11836    pub expression: Option<Box<Expression>>,
11837}
11838
11839/// WithTableHint
11840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11841#[cfg_attr(feature = "bindings", derive(TS))]
11842pub struct WithTableHint {
11843    #[serde(default)]
11844    pub expressions: Vec<Expression>,
11845}
11846
11847/// IndexTableHint
11848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11849#[cfg_attr(feature = "bindings", derive(TS))]
11850pub struct IndexTableHint {
11851    pub this: Box<Expression>,
11852    #[serde(default)]
11853    pub expressions: Vec<Expression>,
11854    #[serde(default)]
11855    pub target: Option<Box<Expression>>,
11856}
11857
11858/// Get
11859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11860#[cfg_attr(feature = "bindings", derive(TS))]
11861pub struct Get {
11862    pub this: Box<Expression>,
11863    #[serde(default)]
11864    pub target: Option<Box<Expression>>,
11865    #[serde(default)]
11866    pub properties: Vec<Expression>,
11867}
11868
11869/// SetOperation
11870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11871#[cfg_attr(feature = "bindings", derive(TS))]
11872pub struct SetOperation {
11873    #[serde(default)]
11874    pub with_: Option<Box<Expression>>,
11875    pub this: Box<Expression>,
11876    pub expression: Box<Expression>,
11877    #[serde(default)]
11878    pub distinct: bool,
11879    #[serde(default)]
11880    pub by_name: Option<Box<Expression>>,
11881    #[serde(default)]
11882    pub side: Option<Box<Expression>>,
11883    #[serde(default)]
11884    pub kind: Option<String>,
11885    #[serde(default)]
11886    pub on: Option<Box<Expression>>,
11887}
11888
11889/// Var - Simple variable reference (for SQL variables, keywords as values)
11890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11891#[cfg_attr(feature = "bindings", derive(TS))]
11892pub struct Var {
11893    pub this: String,
11894}
11895
11896/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11898#[cfg_attr(feature = "bindings", derive(TS))]
11899pub struct Variadic {
11900    pub this: Box<Expression>,
11901}
11902
11903/// Version
11904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11905#[cfg_attr(feature = "bindings", derive(TS))]
11906pub struct Version {
11907    pub this: Box<Expression>,
11908    pub kind: String,
11909    #[serde(default)]
11910    pub expression: Option<Box<Expression>>,
11911}
11912
11913/// Schema
11914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11915#[cfg_attr(feature = "bindings", derive(TS))]
11916pub struct Schema {
11917    #[serde(default)]
11918    pub this: Option<Box<Expression>>,
11919    #[serde(default)]
11920    pub expressions: Vec<Expression>,
11921}
11922
11923/// Lock
11924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11925#[cfg_attr(feature = "bindings", derive(TS))]
11926pub struct Lock {
11927    #[serde(default)]
11928    pub update: Option<Box<Expression>>,
11929    #[serde(default)]
11930    pub expressions: Vec<Expression>,
11931    #[serde(default)]
11932    pub wait: Option<Box<Expression>>,
11933    #[serde(default)]
11934    pub key: Option<Box<Expression>>,
11935}
11936
11937/// TableSample - wraps an expression with a TABLESAMPLE clause
11938/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11940#[cfg_attr(feature = "bindings", derive(TS))]
11941pub struct TableSample {
11942    /// The expression being sampled (subquery, function, etc.)
11943    #[serde(default, skip_serializing_if = "Option::is_none")]
11944    pub this: Option<Box<Expression>>,
11945    /// The sample specification
11946    #[serde(default, skip_serializing_if = "Option::is_none")]
11947    pub sample: Option<Box<Sample>>,
11948    #[serde(default)]
11949    pub expressions: Vec<Expression>,
11950    #[serde(default)]
11951    pub method: Option<String>,
11952    #[serde(default)]
11953    pub bucket_numerator: Option<Box<Expression>>,
11954    #[serde(default)]
11955    pub bucket_denominator: Option<Box<Expression>>,
11956    #[serde(default)]
11957    pub bucket_field: Option<Box<Expression>>,
11958    #[serde(default)]
11959    pub percent: Option<Box<Expression>>,
11960    #[serde(default)]
11961    pub rows: Option<Box<Expression>>,
11962    #[serde(default)]
11963    pub size: Option<i64>,
11964    #[serde(default)]
11965    pub seed: Option<Box<Expression>>,
11966}
11967
11968/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11970#[cfg_attr(feature = "bindings", derive(TS))]
11971pub struct Tag {
11972    #[serde(default)]
11973    pub this: Option<Box<Expression>>,
11974    #[serde(default)]
11975    pub prefix: Option<Box<Expression>>,
11976    #[serde(default)]
11977    pub postfix: Option<Box<Expression>>,
11978}
11979
11980/// UnpivotColumns
11981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11982#[cfg_attr(feature = "bindings", derive(TS))]
11983pub struct UnpivotColumns {
11984    pub this: Box<Expression>,
11985    #[serde(default)]
11986    pub expressions: Vec<Expression>,
11987}
11988
11989/// SessionParameter
11990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11991#[cfg_attr(feature = "bindings", derive(TS))]
11992pub struct SessionParameter {
11993    pub this: Box<Expression>,
11994    #[serde(default)]
11995    pub kind: Option<String>,
11996}
11997
11998/// PseudoType
11999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12000#[cfg_attr(feature = "bindings", derive(TS))]
12001pub struct PseudoType {
12002    pub this: Box<Expression>,
12003}
12004
12005/// ObjectIdentifier
12006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12007#[cfg_attr(feature = "bindings", derive(TS))]
12008pub struct ObjectIdentifier {
12009    pub this: Box<Expression>,
12010}
12011
12012/// Transaction
12013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12014#[cfg_attr(feature = "bindings", derive(TS))]
12015pub struct Transaction {
12016    #[serde(default)]
12017    pub this: Option<Box<Expression>>,
12018    #[serde(default)]
12019    pub modes: Option<Box<Expression>>,
12020    #[serde(default)]
12021    pub mark: Option<Box<Expression>>,
12022}
12023
12024/// Commit
12025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12026#[cfg_attr(feature = "bindings", derive(TS))]
12027pub struct Commit {
12028    #[serde(default)]
12029    pub chain: Option<Box<Expression>>,
12030    #[serde(default)]
12031    pub this: Option<Box<Expression>>,
12032    #[serde(default)]
12033    pub durability: Option<Box<Expression>>,
12034}
12035
12036/// Rollback
12037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12038#[cfg_attr(feature = "bindings", derive(TS))]
12039pub struct Rollback {
12040    #[serde(default)]
12041    pub savepoint: Option<Box<Expression>>,
12042    #[serde(default)]
12043    pub this: Option<Box<Expression>>,
12044}
12045
12046/// AlterSession
12047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12048#[cfg_attr(feature = "bindings", derive(TS))]
12049pub struct AlterSession {
12050    #[serde(default)]
12051    pub expressions: Vec<Expression>,
12052    #[serde(default)]
12053    pub unset: Option<Box<Expression>>,
12054}
12055
12056/// Analyze
12057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12058#[cfg_attr(feature = "bindings", derive(TS))]
12059pub struct Analyze {
12060    #[serde(default)]
12061    pub kind: Option<String>,
12062    #[serde(default)]
12063    pub this: Option<Box<Expression>>,
12064    #[serde(default)]
12065    pub options: Vec<Expression>,
12066    #[serde(default)]
12067    pub mode: Option<Box<Expression>>,
12068    #[serde(default)]
12069    pub partition: Option<Box<Expression>>,
12070    #[serde(default)]
12071    pub expression: Option<Box<Expression>>,
12072    #[serde(default)]
12073    pub properties: Vec<Expression>,
12074    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
12075    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12076    pub columns: Vec<String>,
12077}
12078
12079/// AnalyzeStatistics
12080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12081#[cfg_attr(feature = "bindings", derive(TS))]
12082pub struct AnalyzeStatistics {
12083    pub kind: String,
12084    #[serde(default)]
12085    pub option: Option<Box<Expression>>,
12086    #[serde(default)]
12087    pub this: Option<Box<Expression>>,
12088    #[serde(default)]
12089    pub expressions: Vec<Expression>,
12090}
12091
12092/// AnalyzeHistogram
12093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12094#[cfg_attr(feature = "bindings", derive(TS))]
12095pub struct AnalyzeHistogram {
12096    pub this: Box<Expression>,
12097    #[serde(default)]
12098    pub expressions: Vec<Expression>,
12099    #[serde(default)]
12100    pub expression: Option<Box<Expression>>,
12101    #[serde(default)]
12102    pub update_options: Option<Box<Expression>>,
12103}
12104
12105/// AnalyzeSample
12106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12107#[cfg_attr(feature = "bindings", derive(TS))]
12108pub struct AnalyzeSample {
12109    pub kind: String,
12110    #[serde(default)]
12111    pub sample: Option<Box<Expression>>,
12112}
12113
12114/// AnalyzeListChainedRows
12115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12116#[cfg_attr(feature = "bindings", derive(TS))]
12117pub struct AnalyzeListChainedRows {
12118    #[serde(default)]
12119    pub expression: Option<Box<Expression>>,
12120}
12121
12122/// AnalyzeDelete
12123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12124#[cfg_attr(feature = "bindings", derive(TS))]
12125pub struct AnalyzeDelete {
12126    #[serde(default)]
12127    pub kind: Option<String>,
12128}
12129
12130/// AnalyzeWith
12131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12132#[cfg_attr(feature = "bindings", derive(TS))]
12133pub struct AnalyzeWith {
12134    #[serde(default)]
12135    pub expressions: Vec<Expression>,
12136}
12137
12138/// AnalyzeValidate
12139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12140#[cfg_attr(feature = "bindings", derive(TS))]
12141pub struct AnalyzeValidate {
12142    pub kind: String,
12143    #[serde(default)]
12144    pub this: Option<Box<Expression>>,
12145    #[serde(default)]
12146    pub expression: Option<Box<Expression>>,
12147}
12148
12149/// AddPartition
12150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12151#[cfg_attr(feature = "bindings", derive(TS))]
12152pub struct AddPartition {
12153    pub this: Box<Expression>,
12154    #[serde(default)]
12155    pub exists: bool,
12156    #[serde(default)]
12157    pub location: Option<Box<Expression>>,
12158}
12159
12160/// AttachOption
12161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12162#[cfg_attr(feature = "bindings", derive(TS))]
12163pub struct AttachOption {
12164    pub this: Box<Expression>,
12165    #[serde(default)]
12166    pub expression: Option<Box<Expression>>,
12167}
12168
12169/// DropPartition
12170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12171#[cfg_attr(feature = "bindings", derive(TS))]
12172pub struct DropPartition {
12173    #[serde(default)]
12174    pub expressions: Vec<Expression>,
12175    #[serde(default)]
12176    pub exists: bool,
12177}
12178
12179/// ReplacePartition
12180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12181#[cfg_attr(feature = "bindings", derive(TS))]
12182pub struct ReplacePartition {
12183    pub expression: Box<Expression>,
12184    #[serde(default)]
12185    pub source: Option<Box<Expression>>,
12186}
12187
12188/// DPipe
12189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12190#[cfg_attr(feature = "bindings", derive(TS))]
12191pub struct DPipe {
12192    pub this: Box<Expression>,
12193    pub expression: Box<Expression>,
12194    #[serde(default)]
12195    pub safe: Option<Box<Expression>>,
12196}
12197
12198/// Operator
12199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12200#[cfg_attr(feature = "bindings", derive(TS))]
12201pub struct Operator {
12202    pub this: Box<Expression>,
12203    #[serde(default)]
12204    pub operator: Option<Box<Expression>>,
12205    pub expression: Box<Expression>,
12206    /// Comments between OPERATOR() and the RHS expression
12207    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12208    pub comments: Vec<String>,
12209}
12210
12211/// PivotAny
12212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12213#[cfg_attr(feature = "bindings", derive(TS))]
12214pub struct PivotAny {
12215    #[serde(default)]
12216    pub this: Option<Box<Expression>>,
12217}
12218
12219/// Aliases
12220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12221#[cfg_attr(feature = "bindings", derive(TS))]
12222pub struct Aliases {
12223    pub this: Box<Expression>,
12224    #[serde(default)]
12225    pub expressions: Vec<Expression>,
12226}
12227
12228/// AtIndex
12229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12230#[cfg_attr(feature = "bindings", derive(TS))]
12231pub struct AtIndex {
12232    pub this: Box<Expression>,
12233    pub expression: Box<Expression>,
12234}
12235
12236/// FromTimeZone
12237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12238#[cfg_attr(feature = "bindings", derive(TS))]
12239pub struct FromTimeZone {
12240    pub this: Box<Expression>,
12241    #[serde(default)]
12242    pub zone: Option<Box<Expression>>,
12243}
12244
12245/// Format override for a column in Teradata
12246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12247#[cfg_attr(feature = "bindings", derive(TS))]
12248pub struct FormatPhrase {
12249    pub this: Box<Expression>,
12250    pub format: String,
12251}
12252
12253/// ForIn
12254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12255#[cfg_attr(feature = "bindings", derive(TS))]
12256pub struct ForIn {
12257    pub this: Box<Expression>,
12258    pub expression: Box<Expression>,
12259}
12260
12261/// Automatically converts unit arg into a var.
12262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12263#[cfg_attr(feature = "bindings", derive(TS))]
12264pub struct TimeUnit {
12265    #[serde(default)]
12266    pub unit: Option<String>,
12267}
12268
12269/// IntervalOp
12270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12271#[cfg_attr(feature = "bindings", derive(TS))]
12272pub struct IntervalOp {
12273    #[serde(default)]
12274    pub unit: Option<String>,
12275    pub expression: Box<Expression>,
12276}
12277
12278/// HavingMax
12279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12280#[cfg_attr(feature = "bindings", derive(TS))]
12281pub struct HavingMax {
12282    pub this: Box<Expression>,
12283    pub expression: Box<Expression>,
12284    #[serde(default)]
12285    pub max: Option<Box<Expression>>,
12286}
12287
12288/// CosineDistance
12289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12290#[cfg_attr(feature = "bindings", derive(TS))]
12291pub struct CosineDistance {
12292    pub this: Box<Expression>,
12293    pub expression: Box<Expression>,
12294}
12295
12296/// DotProduct
12297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12298#[cfg_attr(feature = "bindings", derive(TS))]
12299pub struct DotProduct {
12300    pub this: Box<Expression>,
12301    pub expression: Box<Expression>,
12302}
12303
12304/// EuclideanDistance
12305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12306#[cfg_attr(feature = "bindings", derive(TS))]
12307pub struct EuclideanDistance {
12308    pub this: Box<Expression>,
12309    pub expression: Box<Expression>,
12310}
12311
12312/// ManhattanDistance
12313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12314#[cfg_attr(feature = "bindings", derive(TS))]
12315pub struct ManhattanDistance {
12316    pub this: Box<Expression>,
12317    pub expression: Box<Expression>,
12318}
12319
12320/// JarowinklerSimilarity
12321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12322#[cfg_attr(feature = "bindings", derive(TS))]
12323pub struct JarowinklerSimilarity {
12324    pub this: Box<Expression>,
12325    pub expression: Box<Expression>,
12326}
12327
12328/// Booland
12329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12330#[cfg_attr(feature = "bindings", derive(TS))]
12331pub struct Booland {
12332    pub this: Box<Expression>,
12333    pub expression: Box<Expression>,
12334}
12335
12336/// Boolor
12337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12338#[cfg_attr(feature = "bindings", derive(TS))]
12339pub struct Boolor {
12340    pub this: Box<Expression>,
12341    pub expression: Box<Expression>,
12342}
12343
12344/// ParameterizedAgg
12345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12346#[cfg_attr(feature = "bindings", derive(TS))]
12347pub struct ParameterizedAgg {
12348    pub this: Box<Expression>,
12349    #[serde(default)]
12350    pub expressions: Vec<Expression>,
12351    #[serde(default)]
12352    pub params: Vec<Expression>,
12353}
12354
12355/// ArgMax
12356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12357#[cfg_attr(feature = "bindings", derive(TS))]
12358pub struct ArgMax {
12359    pub this: Box<Expression>,
12360    pub expression: Box<Expression>,
12361    #[serde(default)]
12362    pub count: Option<Box<Expression>>,
12363}
12364
12365/// ArgMin
12366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12367#[cfg_attr(feature = "bindings", derive(TS))]
12368pub struct ArgMin {
12369    pub this: Box<Expression>,
12370    pub expression: Box<Expression>,
12371    #[serde(default)]
12372    pub count: Option<Box<Expression>>,
12373}
12374
12375/// ApproxTopK
12376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12377#[cfg_attr(feature = "bindings", derive(TS))]
12378pub struct ApproxTopK {
12379    pub this: Box<Expression>,
12380    #[serde(default)]
12381    pub expression: Option<Box<Expression>>,
12382    #[serde(default)]
12383    pub counters: Option<Box<Expression>>,
12384}
12385
12386/// ApproxTopKAccumulate
12387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12388#[cfg_attr(feature = "bindings", derive(TS))]
12389pub struct ApproxTopKAccumulate {
12390    pub this: Box<Expression>,
12391    #[serde(default)]
12392    pub expression: Option<Box<Expression>>,
12393}
12394
12395/// ApproxTopKCombine
12396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12397#[cfg_attr(feature = "bindings", derive(TS))]
12398pub struct ApproxTopKCombine {
12399    pub this: Box<Expression>,
12400    #[serde(default)]
12401    pub expression: Option<Box<Expression>>,
12402}
12403
12404/// ApproxTopKEstimate
12405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12406#[cfg_attr(feature = "bindings", derive(TS))]
12407pub struct ApproxTopKEstimate {
12408    pub this: Box<Expression>,
12409    #[serde(default)]
12410    pub expression: Option<Box<Expression>>,
12411}
12412
12413/// ApproxTopSum
12414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12415#[cfg_attr(feature = "bindings", derive(TS))]
12416pub struct ApproxTopSum {
12417    pub this: Box<Expression>,
12418    pub expression: Box<Expression>,
12419    #[serde(default)]
12420    pub count: Option<Box<Expression>>,
12421}
12422
12423/// ApproxQuantiles
12424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12425#[cfg_attr(feature = "bindings", derive(TS))]
12426pub struct ApproxQuantiles {
12427    pub this: Box<Expression>,
12428    #[serde(default)]
12429    pub expression: Option<Box<Expression>>,
12430}
12431
12432/// Minhash
12433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12434#[cfg_attr(feature = "bindings", derive(TS))]
12435pub struct Minhash {
12436    pub this: Box<Expression>,
12437    #[serde(default)]
12438    pub expressions: Vec<Expression>,
12439}
12440
12441/// FarmFingerprint
12442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12443#[cfg_attr(feature = "bindings", derive(TS))]
12444pub struct FarmFingerprint {
12445    #[serde(default)]
12446    pub expressions: Vec<Expression>,
12447}
12448
12449/// Float64
12450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12451#[cfg_attr(feature = "bindings", derive(TS))]
12452pub struct Float64 {
12453    pub this: Box<Expression>,
12454    #[serde(default)]
12455    pub expression: Option<Box<Expression>>,
12456}
12457
12458/// Transform
12459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12460#[cfg_attr(feature = "bindings", derive(TS))]
12461pub struct Transform {
12462    pub this: Box<Expression>,
12463    pub expression: Box<Expression>,
12464}
12465
12466/// Translate
12467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12468#[cfg_attr(feature = "bindings", derive(TS))]
12469pub struct Translate {
12470    pub this: Box<Expression>,
12471    #[serde(default)]
12472    pub from_: Option<Box<Expression>>,
12473    #[serde(default)]
12474    pub to: Option<Box<Expression>>,
12475}
12476
12477/// Grouping
12478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12479#[cfg_attr(feature = "bindings", derive(TS))]
12480pub struct Grouping {
12481    #[serde(default)]
12482    pub expressions: Vec<Expression>,
12483}
12484
12485/// GroupingId
12486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12487#[cfg_attr(feature = "bindings", derive(TS))]
12488pub struct GroupingId {
12489    #[serde(default)]
12490    pub expressions: Vec<Expression>,
12491}
12492
12493/// Anonymous
12494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12495#[cfg_attr(feature = "bindings", derive(TS))]
12496pub struct Anonymous {
12497    pub this: Box<Expression>,
12498    #[serde(default)]
12499    pub expressions: Vec<Expression>,
12500}
12501
12502/// AnonymousAggFunc
12503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12504#[cfg_attr(feature = "bindings", derive(TS))]
12505pub struct AnonymousAggFunc {
12506    pub this: Box<Expression>,
12507    #[serde(default)]
12508    pub expressions: Vec<Expression>,
12509}
12510
12511/// CombinedAggFunc
12512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12513#[cfg_attr(feature = "bindings", derive(TS))]
12514pub struct CombinedAggFunc {
12515    pub this: Box<Expression>,
12516    #[serde(default)]
12517    pub expressions: Vec<Expression>,
12518}
12519
12520/// CombinedParameterizedAgg
12521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12522#[cfg_attr(feature = "bindings", derive(TS))]
12523pub struct CombinedParameterizedAgg {
12524    pub this: Box<Expression>,
12525    #[serde(default)]
12526    pub expressions: Vec<Expression>,
12527    #[serde(default)]
12528    pub params: Vec<Expression>,
12529}
12530
12531/// HashAgg
12532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12533#[cfg_attr(feature = "bindings", derive(TS))]
12534pub struct HashAgg {
12535    pub this: Box<Expression>,
12536    #[serde(default)]
12537    pub expressions: Vec<Expression>,
12538}
12539
12540/// Hll
12541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12542#[cfg_attr(feature = "bindings", derive(TS))]
12543pub struct Hll {
12544    pub this: Box<Expression>,
12545    #[serde(default)]
12546    pub expressions: Vec<Expression>,
12547}
12548
12549/// Apply
12550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12551#[cfg_attr(feature = "bindings", derive(TS))]
12552pub struct Apply {
12553    pub this: Box<Expression>,
12554    pub expression: Box<Expression>,
12555}
12556
12557/// ToBoolean
12558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12559#[cfg_attr(feature = "bindings", derive(TS))]
12560pub struct ToBoolean {
12561    pub this: Box<Expression>,
12562    #[serde(default)]
12563    pub safe: Option<Box<Expression>>,
12564}
12565
12566/// List
12567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12568#[cfg_attr(feature = "bindings", derive(TS))]
12569pub struct List {
12570    #[serde(default)]
12571    pub expressions: Vec<Expression>,
12572}
12573
12574/// ToMap - Materialize-style map constructor
12575/// Can hold either:
12576/// - A SELECT subquery (MAP(SELECT 'a', 1))
12577/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12579#[cfg_attr(feature = "bindings", derive(TS))]
12580pub struct ToMap {
12581    /// Either a Select subquery or a Struct containing PropertyEQ entries
12582    pub this: Box<Expression>,
12583}
12584
12585/// Pad
12586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12587#[cfg_attr(feature = "bindings", derive(TS))]
12588pub struct Pad {
12589    pub this: Box<Expression>,
12590    pub expression: Box<Expression>,
12591    #[serde(default)]
12592    pub fill_pattern: Option<Box<Expression>>,
12593    #[serde(default)]
12594    pub is_left: Option<Box<Expression>>,
12595}
12596
12597/// ToChar
12598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12599#[cfg_attr(feature = "bindings", derive(TS))]
12600pub struct ToChar {
12601    pub this: Box<Expression>,
12602    #[serde(default)]
12603    pub format: Option<String>,
12604    #[serde(default)]
12605    pub nlsparam: Option<Box<Expression>>,
12606    #[serde(default)]
12607    pub is_numeric: Option<Box<Expression>>,
12608}
12609
12610/// StringFunc - String type conversion function (BigQuery STRING)
12611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12612#[cfg_attr(feature = "bindings", derive(TS))]
12613pub struct StringFunc {
12614    pub this: Box<Expression>,
12615    #[serde(default)]
12616    pub zone: Option<Box<Expression>>,
12617}
12618
12619/// ToNumber
12620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12621#[cfg_attr(feature = "bindings", derive(TS))]
12622pub struct ToNumber {
12623    pub this: Box<Expression>,
12624    #[serde(default)]
12625    pub format: Option<Box<Expression>>,
12626    #[serde(default)]
12627    pub nlsparam: Option<Box<Expression>>,
12628    #[serde(default)]
12629    pub precision: Option<Box<Expression>>,
12630    #[serde(default)]
12631    pub scale: Option<Box<Expression>>,
12632    #[serde(default)]
12633    pub safe: Option<Box<Expression>>,
12634    #[serde(default)]
12635    pub safe_name: Option<Box<Expression>>,
12636}
12637
12638/// ToDouble
12639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12640#[cfg_attr(feature = "bindings", derive(TS))]
12641pub struct ToDouble {
12642    pub this: Box<Expression>,
12643    #[serde(default)]
12644    pub format: Option<String>,
12645    #[serde(default)]
12646    pub safe: Option<Box<Expression>>,
12647}
12648
12649/// ToDecfloat
12650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12651#[cfg_attr(feature = "bindings", derive(TS))]
12652pub struct ToDecfloat {
12653    pub this: Box<Expression>,
12654    #[serde(default)]
12655    pub format: Option<String>,
12656}
12657
12658/// TryToDecfloat
12659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12660#[cfg_attr(feature = "bindings", derive(TS))]
12661pub struct TryToDecfloat {
12662    pub this: Box<Expression>,
12663    #[serde(default)]
12664    pub format: Option<String>,
12665}
12666
12667/// ToFile
12668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12669#[cfg_attr(feature = "bindings", derive(TS))]
12670pub struct ToFile {
12671    pub this: Box<Expression>,
12672    #[serde(default)]
12673    pub path: Option<Box<Expression>>,
12674    #[serde(default)]
12675    pub safe: Option<Box<Expression>>,
12676}
12677
12678/// Columns
12679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12680#[cfg_attr(feature = "bindings", derive(TS))]
12681pub struct Columns {
12682    pub this: Box<Expression>,
12683    #[serde(default)]
12684    pub unpack: Option<Box<Expression>>,
12685}
12686
12687/// ConvertToCharset
12688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12689#[cfg_attr(feature = "bindings", derive(TS))]
12690pub struct ConvertToCharset {
12691    pub this: Box<Expression>,
12692    #[serde(default)]
12693    pub dest: Option<Box<Expression>>,
12694    #[serde(default)]
12695    pub source: Option<Box<Expression>>,
12696}
12697
12698/// ConvertTimezone
12699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12700#[cfg_attr(feature = "bindings", derive(TS))]
12701pub struct ConvertTimezone {
12702    #[serde(default)]
12703    pub source_tz: Option<Box<Expression>>,
12704    #[serde(default)]
12705    pub target_tz: Option<Box<Expression>>,
12706    #[serde(default)]
12707    pub timestamp: Option<Box<Expression>>,
12708    #[serde(default)]
12709    pub options: Vec<Expression>,
12710}
12711
12712/// GenerateSeries
12713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12714#[cfg_attr(feature = "bindings", derive(TS))]
12715pub struct GenerateSeries {
12716    #[serde(default)]
12717    pub start: Option<Box<Expression>>,
12718    #[serde(default)]
12719    pub end: Option<Box<Expression>>,
12720    #[serde(default)]
12721    pub step: Option<Box<Expression>>,
12722    #[serde(default)]
12723    pub is_end_exclusive: Option<Box<Expression>>,
12724}
12725
12726/// AIAgg
12727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12728#[cfg_attr(feature = "bindings", derive(TS))]
12729pub struct AIAgg {
12730    pub this: Box<Expression>,
12731    pub expression: Box<Expression>,
12732}
12733
12734/// AIClassify
12735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12736#[cfg_attr(feature = "bindings", derive(TS))]
12737pub struct AIClassify {
12738    pub this: Box<Expression>,
12739    #[serde(default)]
12740    pub categories: Option<Box<Expression>>,
12741    #[serde(default)]
12742    pub config: Option<Box<Expression>>,
12743}
12744
12745/// ArrayAll
12746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12747#[cfg_attr(feature = "bindings", derive(TS))]
12748pub struct ArrayAll {
12749    pub this: Box<Expression>,
12750    pub expression: Box<Expression>,
12751}
12752
12753/// ArrayAny
12754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12755#[cfg_attr(feature = "bindings", derive(TS))]
12756pub struct ArrayAny {
12757    pub this: Box<Expression>,
12758    pub expression: Box<Expression>,
12759}
12760
12761/// ArrayConstructCompact
12762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12763#[cfg_attr(feature = "bindings", derive(TS))]
12764pub struct ArrayConstructCompact {
12765    #[serde(default)]
12766    pub expressions: Vec<Expression>,
12767}
12768
12769/// StPoint
12770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12771#[cfg_attr(feature = "bindings", derive(TS))]
12772pub struct StPoint {
12773    pub this: Box<Expression>,
12774    pub expression: Box<Expression>,
12775    #[serde(default)]
12776    pub null: Option<Box<Expression>>,
12777}
12778
12779/// StDistance
12780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12781#[cfg_attr(feature = "bindings", derive(TS))]
12782pub struct StDistance {
12783    pub this: Box<Expression>,
12784    pub expression: Box<Expression>,
12785    #[serde(default)]
12786    pub use_spheroid: Option<Box<Expression>>,
12787}
12788
12789/// StringToArray
12790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12791#[cfg_attr(feature = "bindings", derive(TS))]
12792pub struct StringToArray {
12793    pub this: Box<Expression>,
12794    #[serde(default)]
12795    pub expression: Option<Box<Expression>>,
12796    #[serde(default)]
12797    pub null: Option<Box<Expression>>,
12798}
12799
12800/// ArraySum
12801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12802#[cfg_attr(feature = "bindings", derive(TS))]
12803pub struct ArraySum {
12804    pub this: Box<Expression>,
12805    #[serde(default)]
12806    pub expression: Option<Box<Expression>>,
12807}
12808
12809/// ObjectAgg
12810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12811#[cfg_attr(feature = "bindings", derive(TS))]
12812pub struct ObjectAgg {
12813    pub this: Box<Expression>,
12814    pub expression: Box<Expression>,
12815}
12816
12817/// CastToStrType
12818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12819#[cfg_attr(feature = "bindings", derive(TS))]
12820pub struct CastToStrType {
12821    pub this: Box<Expression>,
12822    #[serde(default)]
12823    pub to: Option<Box<Expression>>,
12824}
12825
12826/// CheckJson
12827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12828#[cfg_attr(feature = "bindings", derive(TS))]
12829pub struct CheckJson {
12830    pub this: Box<Expression>,
12831}
12832
12833/// CheckXml
12834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12835#[cfg_attr(feature = "bindings", derive(TS))]
12836pub struct CheckXml {
12837    pub this: Box<Expression>,
12838    #[serde(default)]
12839    pub disable_auto_convert: Option<Box<Expression>>,
12840}
12841
12842/// TranslateCharacters
12843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12844#[cfg_attr(feature = "bindings", derive(TS))]
12845pub struct TranslateCharacters {
12846    pub this: Box<Expression>,
12847    pub expression: Box<Expression>,
12848    #[serde(default)]
12849    pub with_error: Option<Box<Expression>>,
12850}
12851
12852/// CurrentSchemas
12853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12854#[cfg_attr(feature = "bindings", derive(TS))]
12855pub struct CurrentSchemas {
12856    #[serde(default)]
12857    pub this: Option<Box<Expression>>,
12858}
12859
12860/// CurrentDatetime
12861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12862#[cfg_attr(feature = "bindings", derive(TS))]
12863pub struct CurrentDatetime {
12864    #[serde(default)]
12865    pub this: Option<Box<Expression>>,
12866}
12867
12868/// Localtime
12869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12870#[cfg_attr(feature = "bindings", derive(TS))]
12871pub struct Localtime {
12872    #[serde(default)]
12873    pub this: Option<Box<Expression>>,
12874}
12875
12876/// Localtimestamp
12877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12878#[cfg_attr(feature = "bindings", derive(TS))]
12879pub struct Localtimestamp {
12880    #[serde(default)]
12881    pub this: Option<Box<Expression>>,
12882}
12883
12884/// Systimestamp
12885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12886#[cfg_attr(feature = "bindings", derive(TS))]
12887pub struct Systimestamp {
12888    #[serde(default)]
12889    pub this: Option<Box<Expression>>,
12890}
12891
12892/// CurrentSchema
12893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12894#[cfg_attr(feature = "bindings", derive(TS))]
12895pub struct CurrentSchema {
12896    #[serde(default)]
12897    pub this: Option<Box<Expression>>,
12898}
12899
12900/// CurrentUser
12901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12902#[cfg_attr(feature = "bindings", derive(TS))]
12903pub struct CurrentUser {
12904    #[serde(default)]
12905    pub this: Option<Box<Expression>>,
12906}
12907
12908/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12910#[cfg_attr(feature = "bindings", derive(TS))]
12911pub struct SessionUser;
12912
12913/// JSONPathRoot - Represents $ in JSON path expressions
12914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12915#[cfg_attr(feature = "bindings", derive(TS))]
12916pub struct JSONPathRoot;
12917
12918/// UtcTime
12919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12920#[cfg_attr(feature = "bindings", derive(TS))]
12921pub struct UtcTime {
12922    #[serde(default)]
12923    pub this: Option<Box<Expression>>,
12924}
12925
12926/// UtcTimestamp
12927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12928#[cfg_attr(feature = "bindings", derive(TS))]
12929pub struct UtcTimestamp {
12930    #[serde(default)]
12931    pub this: Option<Box<Expression>>,
12932}
12933
12934/// TimestampFunc - TIMESTAMP constructor function
12935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12936#[cfg_attr(feature = "bindings", derive(TS))]
12937pub struct TimestampFunc {
12938    #[serde(default)]
12939    pub this: Option<Box<Expression>>,
12940    #[serde(default)]
12941    pub zone: Option<Box<Expression>>,
12942    #[serde(default)]
12943    pub with_tz: Option<bool>,
12944    #[serde(default)]
12945    pub safe: Option<bool>,
12946}
12947
12948/// DateBin
12949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12950#[cfg_attr(feature = "bindings", derive(TS))]
12951pub struct DateBin {
12952    pub this: Box<Expression>,
12953    pub expression: Box<Expression>,
12954    #[serde(default)]
12955    pub unit: Option<String>,
12956    #[serde(default)]
12957    pub zone: Option<Box<Expression>>,
12958    #[serde(default)]
12959    pub origin: Option<Box<Expression>>,
12960}
12961
12962/// Datetime
12963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12964#[cfg_attr(feature = "bindings", derive(TS))]
12965pub struct Datetime {
12966    pub this: Box<Expression>,
12967    #[serde(default)]
12968    pub expression: Option<Box<Expression>>,
12969}
12970
12971/// DatetimeAdd
12972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12973#[cfg_attr(feature = "bindings", derive(TS))]
12974pub struct DatetimeAdd {
12975    pub this: Box<Expression>,
12976    pub expression: Box<Expression>,
12977    #[serde(default)]
12978    pub unit: Option<String>,
12979}
12980
12981/// DatetimeSub
12982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12983#[cfg_attr(feature = "bindings", derive(TS))]
12984pub struct DatetimeSub {
12985    pub this: Box<Expression>,
12986    pub expression: Box<Expression>,
12987    #[serde(default)]
12988    pub unit: Option<String>,
12989}
12990
12991/// DatetimeDiff
12992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12993#[cfg_attr(feature = "bindings", derive(TS))]
12994pub struct DatetimeDiff {
12995    pub this: Box<Expression>,
12996    pub expression: Box<Expression>,
12997    #[serde(default)]
12998    pub unit: Option<String>,
12999}
13000
13001/// DatetimeTrunc
13002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13003#[cfg_attr(feature = "bindings", derive(TS))]
13004pub struct DatetimeTrunc {
13005    pub this: Box<Expression>,
13006    pub unit: String,
13007    #[serde(default)]
13008    pub zone: Option<Box<Expression>>,
13009}
13010
13011/// Dayname
13012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13013#[cfg_attr(feature = "bindings", derive(TS))]
13014pub struct Dayname {
13015    pub this: Box<Expression>,
13016    #[serde(default)]
13017    pub abbreviated: Option<Box<Expression>>,
13018}
13019
13020/// MakeInterval
13021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13022#[cfg_attr(feature = "bindings", derive(TS))]
13023pub struct MakeInterval {
13024    #[serde(default)]
13025    pub year: Option<Box<Expression>>,
13026    #[serde(default)]
13027    pub month: Option<Box<Expression>>,
13028    #[serde(default)]
13029    pub week: Option<Box<Expression>>,
13030    #[serde(default)]
13031    pub day: Option<Box<Expression>>,
13032    #[serde(default)]
13033    pub hour: Option<Box<Expression>>,
13034    #[serde(default)]
13035    pub minute: Option<Box<Expression>>,
13036    #[serde(default)]
13037    pub second: Option<Box<Expression>>,
13038}
13039
13040/// PreviousDay
13041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13042#[cfg_attr(feature = "bindings", derive(TS))]
13043pub struct PreviousDay {
13044    pub this: Box<Expression>,
13045    pub expression: Box<Expression>,
13046}
13047
13048/// Elt
13049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13050#[cfg_attr(feature = "bindings", derive(TS))]
13051pub struct Elt {
13052    pub this: Box<Expression>,
13053    #[serde(default)]
13054    pub expressions: Vec<Expression>,
13055}
13056
13057/// TimestampAdd
13058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13059#[cfg_attr(feature = "bindings", derive(TS))]
13060pub struct TimestampAdd {
13061    pub this: Box<Expression>,
13062    pub expression: Box<Expression>,
13063    #[serde(default)]
13064    pub unit: Option<String>,
13065}
13066
13067/// TimestampSub
13068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13069#[cfg_attr(feature = "bindings", derive(TS))]
13070pub struct TimestampSub {
13071    pub this: Box<Expression>,
13072    pub expression: Box<Expression>,
13073    #[serde(default)]
13074    pub unit: Option<String>,
13075}
13076
13077/// TimestampDiff
13078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13079#[cfg_attr(feature = "bindings", derive(TS))]
13080pub struct TimestampDiff {
13081    pub this: Box<Expression>,
13082    pub expression: Box<Expression>,
13083    #[serde(default)]
13084    pub unit: Option<String>,
13085}
13086
13087/// TimeSlice
13088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13089#[cfg_attr(feature = "bindings", derive(TS))]
13090pub struct TimeSlice {
13091    pub this: Box<Expression>,
13092    pub expression: Box<Expression>,
13093    pub unit: String,
13094    #[serde(default)]
13095    pub kind: Option<String>,
13096}
13097
13098/// TimeAdd
13099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13100#[cfg_attr(feature = "bindings", derive(TS))]
13101pub struct TimeAdd {
13102    pub this: Box<Expression>,
13103    pub expression: Box<Expression>,
13104    #[serde(default)]
13105    pub unit: Option<String>,
13106}
13107
13108/// TimeSub
13109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13110#[cfg_attr(feature = "bindings", derive(TS))]
13111pub struct TimeSub {
13112    pub this: Box<Expression>,
13113    pub expression: Box<Expression>,
13114    #[serde(default)]
13115    pub unit: Option<String>,
13116}
13117
13118/// TimeDiff
13119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13120#[cfg_attr(feature = "bindings", derive(TS))]
13121pub struct TimeDiff {
13122    pub this: Box<Expression>,
13123    pub expression: Box<Expression>,
13124    #[serde(default)]
13125    pub unit: Option<String>,
13126}
13127
13128/// TimeTrunc
13129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13130#[cfg_attr(feature = "bindings", derive(TS))]
13131pub struct TimeTrunc {
13132    pub this: Box<Expression>,
13133    pub unit: String,
13134    #[serde(default)]
13135    pub zone: Option<Box<Expression>>,
13136}
13137
13138/// DateFromParts
13139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13140#[cfg_attr(feature = "bindings", derive(TS))]
13141pub struct DateFromParts {
13142    #[serde(default)]
13143    pub year: Option<Box<Expression>>,
13144    #[serde(default)]
13145    pub month: Option<Box<Expression>>,
13146    #[serde(default)]
13147    pub day: Option<Box<Expression>>,
13148    #[serde(default)]
13149    pub allow_overflow: Option<Box<Expression>>,
13150}
13151
13152/// TimeFromParts
13153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13154#[cfg_attr(feature = "bindings", derive(TS))]
13155pub struct TimeFromParts {
13156    #[serde(default)]
13157    pub hour: Option<Box<Expression>>,
13158    #[serde(default)]
13159    pub min: Option<Box<Expression>>,
13160    #[serde(default)]
13161    pub sec: Option<Box<Expression>>,
13162    #[serde(default)]
13163    pub nano: Option<Box<Expression>>,
13164    #[serde(default)]
13165    pub fractions: Option<Box<Expression>>,
13166    #[serde(default)]
13167    pub precision: Option<i64>,
13168}
13169
13170/// DecodeCase
13171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13172#[cfg_attr(feature = "bindings", derive(TS))]
13173pub struct DecodeCase {
13174    #[serde(default)]
13175    pub expressions: Vec<Expression>,
13176}
13177
13178/// Decrypt
13179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13180#[cfg_attr(feature = "bindings", derive(TS))]
13181pub struct Decrypt {
13182    pub this: Box<Expression>,
13183    #[serde(default)]
13184    pub passphrase: Option<Box<Expression>>,
13185    #[serde(default)]
13186    pub aad: Option<Box<Expression>>,
13187    #[serde(default)]
13188    pub encryption_method: Option<Box<Expression>>,
13189    #[serde(default)]
13190    pub safe: Option<Box<Expression>>,
13191}
13192
13193/// DecryptRaw
13194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13195#[cfg_attr(feature = "bindings", derive(TS))]
13196pub struct DecryptRaw {
13197    pub this: Box<Expression>,
13198    #[serde(default)]
13199    pub key: Option<Box<Expression>>,
13200    #[serde(default)]
13201    pub iv: Option<Box<Expression>>,
13202    #[serde(default)]
13203    pub aad: Option<Box<Expression>>,
13204    #[serde(default)]
13205    pub encryption_method: Option<Box<Expression>>,
13206    #[serde(default)]
13207    pub aead: Option<Box<Expression>>,
13208    #[serde(default)]
13209    pub safe: Option<Box<Expression>>,
13210}
13211
13212/// Encode
13213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13214#[cfg_attr(feature = "bindings", derive(TS))]
13215pub struct Encode {
13216    pub this: Box<Expression>,
13217    #[serde(default)]
13218    pub charset: Option<Box<Expression>>,
13219}
13220
13221/// Encrypt
13222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13223#[cfg_attr(feature = "bindings", derive(TS))]
13224pub struct Encrypt {
13225    pub this: Box<Expression>,
13226    #[serde(default)]
13227    pub passphrase: Option<Box<Expression>>,
13228    #[serde(default)]
13229    pub aad: Option<Box<Expression>>,
13230    #[serde(default)]
13231    pub encryption_method: Option<Box<Expression>>,
13232}
13233
13234/// EncryptRaw
13235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13236#[cfg_attr(feature = "bindings", derive(TS))]
13237pub struct EncryptRaw {
13238    pub this: Box<Expression>,
13239    #[serde(default)]
13240    pub key: Option<Box<Expression>>,
13241    #[serde(default)]
13242    pub iv: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub aad: Option<Box<Expression>>,
13245    #[serde(default)]
13246    pub encryption_method: Option<Box<Expression>>,
13247}
13248
13249/// EqualNull
13250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13251#[cfg_attr(feature = "bindings", derive(TS))]
13252pub struct EqualNull {
13253    pub this: Box<Expression>,
13254    pub expression: Box<Expression>,
13255}
13256
13257/// ToBinary
13258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13259#[cfg_attr(feature = "bindings", derive(TS))]
13260pub struct ToBinary {
13261    pub this: Box<Expression>,
13262    #[serde(default)]
13263    pub format: Option<String>,
13264    #[serde(default)]
13265    pub safe: Option<Box<Expression>>,
13266}
13267
13268/// Base64DecodeBinary
13269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13270#[cfg_attr(feature = "bindings", derive(TS))]
13271pub struct Base64DecodeBinary {
13272    pub this: Box<Expression>,
13273    #[serde(default)]
13274    pub alphabet: Option<Box<Expression>>,
13275}
13276
13277/// Base64DecodeString
13278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13279#[cfg_attr(feature = "bindings", derive(TS))]
13280pub struct Base64DecodeString {
13281    pub this: Box<Expression>,
13282    #[serde(default)]
13283    pub alphabet: Option<Box<Expression>>,
13284}
13285
13286/// Base64Encode
13287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13288#[cfg_attr(feature = "bindings", derive(TS))]
13289pub struct Base64Encode {
13290    pub this: Box<Expression>,
13291    #[serde(default)]
13292    pub max_line_length: Option<Box<Expression>>,
13293    #[serde(default)]
13294    pub alphabet: Option<Box<Expression>>,
13295}
13296
13297/// TryBase64DecodeBinary
13298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13299#[cfg_attr(feature = "bindings", derive(TS))]
13300pub struct TryBase64DecodeBinary {
13301    pub this: Box<Expression>,
13302    #[serde(default)]
13303    pub alphabet: Option<Box<Expression>>,
13304}
13305
13306/// TryBase64DecodeString
13307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13308#[cfg_attr(feature = "bindings", derive(TS))]
13309pub struct TryBase64DecodeString {
13310    pub this: Box<Expression>,
13311    #[serde(default)]
13312    pub alphabet: Option<Box<Expression>>,
13313}
13314
13315/// GapFill
13316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13317#[cfg_attr(feature = "bindings", derive(TS))]
13318pub struct GapFill {
13319    pub this: Box<Expression>,
13320    #[serde(default)]
13321    pub ts_column: Option<Box<Expression>>,
13322    #[serde(default)]
13323    pub bucket_width: Option<Box<Expression>>,
13324    #[serde(default)]
13325    pub partitioning_columns: Option<Box<Expression>>,
13326    #[serde(default)]
13327    pub value_columns: Option<Box<Expression>>,
13328    #[serde(default)]
13329    pub origin: Option<Box<Expression>>,
13330    #[serde(default)]
13331    pub ignore_nulls: Option<Box<Expression>>,
13332}
13333
13334/// GenerateDateArray
13335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13336#[cfg_attr(feature = "bindings", derive(TS))]
13337pub struct GenerateDateArray {
13338    #[serde(default)]
13339    pub start: Option<Box<Expression>>,
13340    #[serde(default)]
13341    pub end: Option<Box<Expression>>,
13342    #[serde(default)]
13343    pub step: Option<Box<Expression>>,
13344}
13345
13346/// GenerateTimestampArray
13347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13348#[cfg_attr(feature = "bindings", derive(TS))]
13349pub struct GenerateTimestampArray {
13350    #[serde(default)]
13351    pub start: Option<Box<Expression>>,
13352    #[serde(default)]
13353    pub end: Option<Box<Expression>>,
13354    #[serde(default)]
13355    pub step: Option<Box<Expression>>,
13356}
13357
13358/// GetExtract
13359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13360#[cfg_attr(feature = "bindings", derive(TS))]
13361pub struct GetExtract {
13362    pub this: Box<Expression>,
13363    pub expression: Box<Expression>,
13364}
13365
13366/// Getbit
13367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13368#[cfg_attr(feature = "bindings", derive(TS))]
13369pub struct Getbit {
13370    pub this: Box<Expression>,
13371    pub expression: Box<Expression>,
13372    #[serde(default)]
13373    pub zero_is_msb: Option<Box<Expression>>,
13374}
13375
13376/// OverflowTruncateBehavior
13377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13378#[cfg_attr(feature = "bindings", derive(TS))]
13379pub struct OverflowTruncateBehavior {
13380    #[serde(default)]
13381    pub this: Option<Box<Expression>>,
13382    #[serde(default)]
13383    pub with_count: Option<Box<Expression>>,
13384}
13385
13386/// HexEncode
13387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13388#[cfg_attr(feature = "bindings", derive(TS))]
13389pub struct HexEncode {
13390    pub this: Box<Expression>,
13391    #[serde(default)]
13392    pub case: Option<Box<Expression>>,
13393}
13394
13395/// Compress
13396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13397#[cfg_attr(feature = "bindings", derive(TS))]
13398pub struct Compress {
13399    pub this: Box<Expression>,
13400    #[serde(default)]
13401    pub method: Option<String>,
13402}
13403
13404/// DecompressBinary
13405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13406#[cfg_attr(feature = "bindings", derive(TS))]
13407pub struct DecompressBinary {
13408    pub this: Box<Expression>,
13409    pub method: String,
13410}
13411
13412/// DecompressString
13413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13414#[cfg_attr(feature = "bindings", derive(TS))]
13415pub struct DecompressString {
13416    pub this: Box<Expression>,
13417    pub method: String,
13418}
13419
13420/// Xor
13421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13422#[cfg_attr(feature = "bindings", derive(TS))]
13423pub struct Xor {
13424    #[serde(default)]
13425    pub this: Option<Box<Expression>>,
13426    #[serde(default)]
13427    pub expression: Option<Box<Expression>>,
13428    #[serde(default)]
13429    pub expressions: Vec<Expression>,
13430}
13431
13432/// Nullif
13433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13434#[cfg_attr(feature = "bindings", derive(TS))]
13435pub struct Nullif {
13436    pub this: Box<Expression>,
13437    pub expression: Box<Expression>,
13438}
13439
13440/// JSON
13441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13442#[cfg_attr(feature = "bindings", derive(TS))]
13443pub struct JSON {
13444    #[serde(default)]
13445    pub this: Option<Box<Expression>>,
13446    #[serde(default)]
13447    pub with_: Option<Box<Expression>>,
13448    #[serde(default)]
13449    pub unique: bool,
13450}
13451
13452/// JSONPath
13453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13454#[cfg_attr(feature = "bindings", derive(TS))]
13455pub struct JSONPath {
13456    #[serde(default)]
13457    pub expressions: Vec<Expression>,
13458    #[serde(default)]
13459    pub escape: Option<Box<Expression>>,
13460}
13461
13462/// JSONPathFilter
13463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13464#[cfg_attr(feature = "bindings", derive(TS))]
13465pub struct JSONPathFilter {
13466    pub this: Box<Expression>,
13467}
13468
13469/// JSONPathKey
13470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13471#[cfg_attr(feature = "bindings", derive(TS))]
13472pub struct JSONPathKey {
13473    pub this: Box<Expression>,
13474}
13475
13476/// JSONPathRecursive
13477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13478#[cfg_attr(feature = "bindings", derive(TS))]
13479pub struct JSONPathRecursive {
13480    #[serde(default)]
13481    pub this: Option<Box<Expression>>,
13482}
13483
13484/// JSONPathScript
13485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13486#[cfg_attr(feature = "bindings", derive(TS))]
13487pub struct JSONPathScript {
13488    pub this: Box<Expression>,
13489}
13490
13491/// JSONPathSlice
13492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13493#[cfg_attr(feature = "bindings", derive(TS))]
13494pub struct JSONPathSlice {
13495    #[serde(default)]
13496    pub start: Option<Box<Expression>>,
13497    #[serde(default)]
13498    pub end: Option<Box<Expression>>,
13499    #[serde(default)]
13500    pub step: Option<Box<Expression>>,
13501}
13502
13503/// JSONPathSelector
13504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13505#[cfg_attr(feature = "bindings", derive(TS))]
13506pub struct JSONPathSelector {
13507    pub this: Box<Expression>,
13508}
13509
13510/// JSONPathSubscript
13511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13512#[cfg_attr(feature = "bindings", derive(TS))]
13513pub struct JSONPathSubscript {
13514    pub this: Box<Expression>,
13515}
13516
13517/// JSONPathUnion
13518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13519#[cfg_attr(feature = "bindings", derive(TS))]
13520pub struct JSONPathUnion {
13521    #[serde(default)]
13522    pub expressions: Vec<Expression>,
13523}
13524
13525/// Format
13526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13527#[cfg_attr(feature = "bindings", derive(TS))]
13528pub struct Format {
13529    pub this: Box<Expression>,
13530    #[serde(default)]
13531    pub expressions: Vec<Expression>,
13532}
13533
13534/// JSONKeys
13535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13536#[cfg_attr(feature = "bindings", derive(TS))]
13537pub struct JSONKeys {
13538    pub this: Box<Expression>,
13539    #[serde(default)]
13540    pub expression: Option<Box<Expression>>,
13541    #[serde(default)]
13542    pub expressions: Vec<Expression>,
13543}
13544
13545/// JSONKeyValue
13546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13547#[cfg_attr(feature = "bindings", derive(TS))]
13548pub struct JSONKeyValue {
13549    pub this: Box<Expression>,
13550    pub expression: Box<Expression>,
13551}
13552
13553/// JSONKeysAtDepth
13554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13555#[cfg_attr(feature = "bindings", derive(TS))]
13556pub struct JSONKeysAtDepth {
13557    pub this: Box<Expression>,
13558    #[serde(default)]
13559    pub expression: Option<Box<Expression>>,
13560    #[serde(default)]
13561    pub mode: Option<Box<Expression>>,
13562}
13563
13564/// JSONObject
13565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13566#[cfg_attr(feature = "bindings", derive(TS))]
13567pub struct JSONObject {
13568    #[serde(default)]
13569    pub expressions: Vec<Expression>,
13570    #[serde(default)]
13571    pub null_handling: Option<Box<Expression>>,
13572    #[serde(default)]
13573    pub unique_keys: Option<Box<Expression>>,
13574    #[serde(default)]
13575    pub return_type: Option<Box<Expression>>,
13576    #[serde(default)]
13577    pub encoding: Option<Box<Expression>>,
13578}
13579
13580/// JSONObjectAgg
13581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13582#[cfg_attr(feature = "bindings", derive(TS))]
13583pub struct JSONObjectAgg {
13584    #[serde(default)]
13585    pub expressions: Vec<Expression>,
13586    #[serde(default)]
13587    pub null_handling: Option<Box<Expression>>,
13588    #[serde(default)]
13589    pub unique_keys: Option<Box<Expression>>,
13590    #[serde(default)]
13591    pub return_type: Option<Box<Expression>>,
13592    #[serde(default)]
13593    pub encoding: Option<Box<Expression>>,
13594}
13595
13596/// JSONBObjectAgg
13597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13598#[cfg_attr(feature = "bindings", derive(TS))]
13599pub struct JSONBObjectAgg {
13600    pub this: Box<Expression>,
13601    pub expression: Box<Expression>,
13602}
13603
13604/// JSONArray
13605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13606#[cfg_attr(feature = "bindings", derive(TS))]
13607pub struct JSONArray {
13608    #[serde(default)]
13609    pub expressions: Vec<Expression>,
13610    #[serde(default)]
13611    pub null_handling: Option<Box<Expression>>,
13612    #[serde(default)]
13613    pub return_type: Option<Box<Expression>>,
13614    #[serde(default)]
13615    pub strict: Option<Box<Expression>>,
13616}
13617
13618/// JSONArrayAgg
13619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13620#[cfg_attr(feature = "bindings", derive(TS))]
13621pub struct JSONArrayAgg {
13622    pub this: Box<Expression>,
13623    #[serde(default)]
13624    pub order: Option<Box<Expression>>,
13625    #[serde(default)]
13626    pub null_handling: Option<Box<Expression>>,
13627    #[serde(default)]
13628    pub return_type: Option<Box<Expression>>,
13629    #[serde(default)]
13630    pub strict: Option<Box<Expression>>,
13631}
13632
13633/// JSONExists
13634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13635#[cfg_attr(feature = "bindings", derive(TS))]
13636pub struct JSONExists {
13637    pub this: Box<Expression>,
13638    #[serde(default)]
13639    pub path: Option<Box<Expression>>,
13640    #[serde(default)]
13641    pub passing: Option<Box<Expression>>,
13642    #[serde(default)]
13643    pub on_condition: Option<Box<Expression>>,
13644    #[serde(default)]
13645    pub from_dcolonqmark: Option<Box<Expression>>,
13646}
13647
13648/// JSONColumnDef
13649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13650#[cfg_attr(feature = "bindings", derive(TS))]
13651pub struct JSONColumnDef {
13652    #[serde(default)]
13653    pub this: Option<Box<Expression>>,
13654    #[serde(default)]
13655    pub kind: Option<String>,
13656    #[serde(default)]
13657    pub format_json: bool,
13658    #[serde(default)]
13659    pub path: Option<Box<Expression>>,
13660    #[serde(default)]
13661    pub nested_schema: Option<Box<Expression>>,
13662    #[serde(default)]
13663    pub ordinality: Option<Box<Expression>>,
13664}
13665
13666/// JSONSchema
13667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13668#[cfg_attr(feature = "bindings", derive(TS))]
13669pub struct JSONSchema {
13670    #[serde(default)]
13671    pub expressions: Vec<Expression>,
13672}
13673
13674/// JSONSet
13675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13676#[cfg_attr(feature = "bindings", derive(TS))]
13677pub struct JSONSet {
13678    pub this: Box<Expression>,
13679    #[serde(default)]
13680    pub expressions: Vec<Expression>,
13681}
13682
13683/// JSONStripNulls
13684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13685#[cfg_attr(feature = "bindings", derive(TS))]
13686pub struct JSONStripNulls {
13687    pub this: Box<Expression>,
13688    #[serde(default)]
13689    pub expression: Option<Box<Expression>>,
13690    #[serde(default)]
13691    pub include_arrays: Option<Box<Expression>>,
13692    #[serde(default)]
13693    pub remove_empty: Option<Box<Expression>>,
13694}
13695
13696/// JSONValue
13697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13698#[cfg_attr(feature = "bindings", derive(TS))]
13699pub struct JSONValue {
13700    pub this: Box<Expression>,
13701    #[serde(default)]
13702    pub path: Option<Box<Expression>>,
13703    #[serde(default)]
13704    pub returning: Option<Box<Expression>>,
13705    #[serde(default)]
13706    pub on_condition: Option<Box<Expression>>,
13707}
13708
13709/// JSONValueArray
13710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13711#[cfg_attr(feature = "bindings", derive(TS))]
13712pub struct JSONValueArray {
13713    pub this: Box<Expression>,
13714    #[serde(default)]
13715    pub expression: Option<Box<Expression>>,
13716}
13717
13718/// JSONRemove
13719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13720#[cfg_attr(feature = "bindings", derive(TS))]
13721pub struct JSONRemove {
13722    pub this: Box<Expression>,
13723    #[serde(default)]
13724    pub expressions: Vec<Expression>,
13725}
13726
13727/// JSONTable
13728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13729#[cfg_attr(feature = "bindings", derive(TS))]
13730pub struct JSONTable {
13731    pub this: Box<Expression>,
13732    #[serde(default)]
13733    pub schema: Option<Box<Expression>>,
13734    #[serde(default)]
13735    pub path: Option<Box<Expression>>,
13736    #[serde(default)]
13737    pub error_handling: Option<Box<Expression>>,
13738    #[serde(default)]
13739    pub empty_handling: Option<Box<Expression>>,
13740}
13741
13742/// JSONType
13743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13744#[cfg_attr(feature = "bindings", derive(TS))]
13745pub struct JSONType {
13746    pub this: Box<Expression>,
13747    #[serde(default)]
13748    pub expression: Option<Box<Expression>>,
13749}
13750
13751/// ObjectInsert
13752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13753#[cfg_attr(feature = "bindings", derive(TS))]
13754pub struct ObjectInsert {
13755    pub this: Box<Expression>,
13756    #[serde(default)]
13757    pub key: Option<Box<Expression>>,
13758    #[serde(default)]
13759    pub value: Option<Box<Expression>>,
13760    #[serde(default)]
13761    pub update_flag: Option<Box<Expression>>,
13762}
13763
13764/// OpenJSONColumnDef
13765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13766#[cfg_attr(feature = "bindings", derive(TS))]
13767pub struct OpenJSONColumnDef {
13768    pub this: Box<Expression>,
13769    pub kind: String,
13770    #[serde(default)]
13771    pub path: Option<Box<Expression>>,
13772    #[serde(default)]
13773    pub as_json: Option<Box<Expression>>,
13774    /// The parsed data type for proper generation
13775    #[serde(default, skip_serializing_if = "Option::is_none")]
13776    pub data_type: Option<DataType>,
13777}
13778
13779/// OpenJSON
13780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13781#[cfg_attr(feature = "bindings", derive(TS))]
13782pub struct OpenJSON {
13783    pub this: Box<Expression>,
13784    #[serde(default)]
13785    pub path: Option<Box<Expression>>,
13786    #[serde(default)]
13787    pub expressions: Vec<Expression>,
13788}
13789
13790/// JSONBExists
13791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13792#[cfg_attr(feature = "bindings", derive(TS))]
13793pub struct JSONBExists {
13794    pub this: Box<Expression>,
13795    #[serde(default)]
13796    pub path: Option<Box<Expression>>,
13797}
13798
13799/// JSONCast
13800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13801#[cfg_attr(feature = "bindings", derive(TS))]
13802pub struct JSONCast {
13803    pub this: Box<Expression>,
13804    pub to: DataType,
13805}
13806
13807/// JSONExtract
13808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13809#[cfg_attr(feature = "bindings", derive(TS))]
13810pub struct JSONExtract {
13811    pub this: Box<Expression>,
13812    pub expression: Box<Expression>,
13813    #[serde(default)]
13814    pub only_json_types: Option<Box<Expression>>,
13815    #[serde(default)]
13816    pub expressions: Vec<Expression>,
13817    #[serde(default)]
13818    pub variant_extract: Option<Box<Expression>>,
13819    #[serde(default)]
13820    pub json_query: Option<Box<Expression>>,
13821    #[serde(default)]
13822    pub option: Option<Box<Expression>>,
13823    #[serde(default)]
13824    pub quote: Option<Box<Expression>>,
13825    #[serde(default)]
13826    pub on_condition: Option<Box<Expression>>,
13827    #[serde(default)]
13828    pub requires_json: Option<Box<Expression>>,
13829}
13830
13831/// JSONExtractQuote
13832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13833#[cfg_attr(feature = "bindings", derive(TS))]
13834pub struct JSONExtractQuote {
13835    #[serde(default)]
13836    pub option: Option<Box<Expression>>,
13837    #[serde(default)]
13838    pub scalar: Option<Box<Expression>>,
13839}
13840
13841/// JSONExtractArray
13842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13843#[cfg_attr(feature = "bindings", derive(TS))]
13844pub struct JSONExtractArray {
13845    pub this: Box<Expression>,
13846    #[serde(default)]
13847    pub expression: Option<Box<Expression>>,
13848}
13849
13850/// JSONExtractScalar
13851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13852#[cfg_attr(feature = "bindings", derive(TS))]
13853pub struct JSONExtractScalar {
13854    pub this: Box<Expression>,
13855    pub expression: Box<Expression>,
13856    #[serde(default)]
13857    pub only_json_types: Option<Box<Expression>>,
13858    #[serde(default)]
13859    pub expressions: Vec<Expression>,
13860    #[serde(default)]
13861    pub json_type: Option<Box<Expression>>,
13862    #[serde(default)]
13863    pub scalar_only: Option<Box<Expression>>,
13864}
13865
13866/// JSONBExtractScalar
13867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13868#[cfg_attr(feature = "bindings", derive(TS))]
13869pub struct JSONBExtractScalar {
13870    pub this: Box<Expression>,
13871    pub expression: Box<Expression>,
13872    #[serde(default)]
13873    pub json_type: Option<Box<Expression>>,
13874}
13875
13876/// JSONFormat
13877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13878#[cfg_attr(feature = "bindings", derive(TS))]
13879pub struct JSONFormat {
13880    #[serde(default)]
13881    pub this: Option<Box<Expression>>,
13882    #[serde(default)]
13883    pub options: Vec<Expression>,
13884    #[serde(default)]
13885    pub is_json: Option<Box<Expression>>,
13886    #[serde(default)]
13887    pub to_json: Option<Box<Expression>>,
13888}
13889
13890/// JSONArrayAppend
13891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13892#[cfg_attr(feature = "bindings", derive(TS))]
13893pub struct JSONArrayAppend {
13894    pub this: Box<Expression>,
13895    #[serde(default)]
13896    pub expressions: Vec<Expression>,
13897}
13898
13899/// JSONArrayContains
13900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13901#[cfg_attr(feature = "bindings", derive(TS))]
13902pub struct JSONArrayContains {
13903    pub this: Box<Expression>,
13904    pub expression: Box<Expression>,
13905    #[serde(default)]
13906    pub json_type: Option<Box<Expression>>,
13907}
13908
13909/// JSONArrayInsert
13910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13911#[cfg_attr(feature = "bindings", derive(TS))]
13912pub struct JSONArrayInsert {
13913    pub this: Box<Expression>,
13914    #[serde(default)]
13915    pub expressions: Vec<Expression>,
13916}
13917
13918/// ParseJSON
13919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13920#[cfg_attr(feature = "bindings", derive(TS))]
13921pub struct ParseJSON {
13922    pub this: Box<Expression>,
13923    #[serde(default)]
13924    pub expression: Option<Box<Expression>>,
13925    #[serde(default)]
13926    pub safe: Option<Box<Expression>>,
13927}
13928
13929/// ParseUrl
13930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13931#[cfg_attr(feature = "bindings", derive(TS))]
13932pub struct ParseUrl {
13933    pub this: Box<Expression>,
13934    #[serde(default)]
13935    pub part_to_extract: Option<Box<Expression>>,
13936    #[serde(default)]
13937    pub key: Option<Box<Expression>>,
13938    #[serde(default)]
13939    pub permissive: Option<Box<Expression>>,
13940}
13941
13942/// ParseIp
13943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13944#[cfg_attr(feature = "bindings", derive(TS))]
13945pub struct ParseIp {
13946    pub this: Box<Expression>,
13947    #[serde(default)]
13948    pub type_: Option<Box<Expression>>,
13949    #[serde(default)]
13950    pub permissive: Option<Box<Expression>>,
13951}
13952
13953/// ParseTime
13954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13955#[cfg_attr(feature = "bindings", derive(TS))]
13956pub struct ParseTime {
13957    pub this: Box<Expression>,
13958    pub format: String,
13959}
13960
13961/// ParseDatetime
13962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13963#[cfg_attr(feature = "bindings", derive(TS))]
13964pub struct ParseDatetime {
13965    pub this: Box<Expression>,
13966    #[serde(default)]
13967    pub format: Option<String>,
13968    #[serde(default)]
13969    pub zone: Option<Box<Expression>>,
13970}
13971
13972/// Map
13973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13974#[cfg_attr(feature = "bindings", derive(TS))]
13975pub struct Map {
13976    #[serde(default)]
13977    pub keys: Vec<Expression>,
13978    #[serde(default)]
13979    pub values: Vec<Expression>,
13980}
13981
13982/// MapCat
13983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13984#[cfg_attr(feature = "bindings", derive(TS))]
13985pub struct MapCat {
13986    pub this: Box<Expression>,
13987    pub expression: Box<Expression>,
13988}
13989
13990/// MapDelete
13991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13992#[cfg_attr(feature = "bindings", derive(TS))]
13993pub struct MapDelete {
13994    pub this: Box<Expression>,
13995    #[serde(default)]
13996    pub expressions: Vec<Expression>,
13997}
13998
13999/// MapInsert
14000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14001#[cfg_attr(feature = "bindings", derive(TS))]
14002pub struct MapInsert {
14003    pub this: Box<Expression>,
14004    #[serde(default)]
14005    pub key: Option<Box<Expression>>,
14006    #[serde(default)]
14007    pub value: Option<Box<Expression>>,
14008    #[serde(default)]
14009    pub update_flag: Option<Box<Expression>>,
14010}
14011
14012/// MapPick
14013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14014#[cfg_attr(feature = "bindings", derive(TS))]
14015pub struct MapPick {
14016    pub this: Box<Expression>,
14017    #[serde(default)]
14018    pub expressions: Vec<Expression>,
14019}
14020
14021/// ScopeResolution
14022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14023#[cfg_attr(feature = "bindings", derive(TS))]
14024pub struct ScopeResolution {
14025    #[serde(default)]
14026    pub this: Option<Box<Expression>>,
14027    pub expression: Box<Expression>,
14028}
14029
14030/// Slice
14031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14032#[cfg_attr(feature = "bindings", derive(TS))]
14033pub struct Slice {
14034    #[serde(default)]
14035    pub this: Option<Box<Expression>>,
14036    #[serde(default)]
14037    pub expression: Option<Box<Expression>>,
14038    #[serde(default)]
14039    pub step: Option<Box<Expression>>,
14040}
14041
14042/// VarMap
14043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14044#[cfg_attr(feature = "bindings", derive(TS))]
14045pub struct VarMap {
14046    #[serde(default)]
14047    pub keys: Vec<Expression>,
14048    #[serde(default)]
14049    pub values: Vec<Expression>,
14050}
14051
14052/// MatchAgainst
14053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14054#[cfg_attr(feature = "bindings", derive(TS))]
14055pub struct MatchAgainst {
14056    pub this: Box<Expression>,
14057    #[serde(default)]
14058    pub expressions: Vec<Expression>,
14059    #[serde(default)]
14060    pub modifier: Option<Box<Expression>>,
14061}
14062
14063/// MD5Digest
14064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14065#[cfg_attr(feature = "bindings", derive(TS))]
14066pub struct MD5Digest {
14067    pub this: Box<Expression>,
14068    #[serde(default)]
14069    pub expressions: Vec<Expression>,
14070}
14071
14072/// Monthname
14073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14074#[cfg_attr(feature = "bindings", derive(TS))]
14075pub struct Monthname {
14076    pub this: Box<Expression>,
14077    #[serde(default)]
14078    pub abbreviated: Option<Box<Expression>>,
14079}
14080
14081/// Ntile
14082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14083#[cfg_attr(feature = "bindings", derive(TS))]
14084pub struct Ntile {
14085    #[serde(default)]
14086    pub this: Option<Box<Expression>>,
14087}
14088
14089/// Normalize
14090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14091#[cfg_attr(feature = "bindings", derive(TS))]
14092pub struct Normalize {
14093    pub this: Box<Expression>,
14094    #[serde(default)]
14095    pub form: Option<Box<Expression>>,
14096    #[serde(default)]
14097    pub is_casefold: Option<Box<Expression>>,
14098}
14099
14100/// Normal
14101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14102#[cfg_attr(feature = "bindings", derive(TS))]
14103pub struct Normal {
14104    pub this: Box<Expression>,
14105    #[serde(default)]
14106    pub stddev: Option<Box<Expression>>,
14107    #[serde(default)]
14108    pub gen: Option<Box<Expression>>,
14109}
14110
14111/// Predict
14112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14113#[cfg_attr(feature = "bindings", derive(TS))]
14114pub struct Predict {
14115    pub this: Box<Expression>,
14116    pub expression: Box<Expression>,
14117    #[serde(default)]
14118    pub params_struct: Option<Box<Expression>>,
14119}
14120
14121/// MLTranslate
14122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14123#[cfg_attr(feature = "bindings", derive(TS))]
14124pub struct MLTranslate {
14125    pub this: Box<Expression>,
14126    pub expression: Box<Expression>,
14127    #[serde(default)]
14128    pub params_struct: Option<Box<Expression>>,
14129}
14130
14131/// FeaturesAtTime
14132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14133#[cfg_attr(feature = "bindings", derive(TS))]
14134pub struct FeaturesAtTime {
14135    pub this: Box<Expression>,
14136    #[serde(default)]
14137    pub time: Option<Box<Expression>>,
14138    #[serde(default)]
14139    pub num_rows: Option<Box<Expression>>,
14140    #[serde(default)]
14141    pub ignore_feature_nulls: Option<Box<Expression>>,
14142}
14143
14144/// GenerateEmbedding
14145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14146#[cfg_attr(feature = "bindings", derive(TS))]
14147pub struct GenerateEmbedding {
14148    pub this: Box<Expression>,
14149    pub expression: Box<Expression>,
14150    #[serde(default)]
14151    pub params_struct: Option<Box<Expression>>,
14152    #[serde(default)]
14153    pub is_text: Option<Box<Expression>>,
14154}
14155
14156/// MLForecast
14157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14158#[cfg_attr(feature = "bindings", derive(TS))]
14159pub struct MLForecast {
14160    pub this: Box<Expression>,
14161    #[serde(default)]
14162    pub expression: Option<Box<Expression>>,
14163    #[serde(default)]
14164    pub params_struct: Option<Box<Expression>>,
14165}
14166
14167/// ModelAttribute
14168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14169#[cfg_attr(feature = "bindings", derive(TS))]
14170pub struct ModelAttribute {
14171    pub this: Box<Expression>,
14172    pub expression: Box<Expression>,
14173}
14174
14175/// VectorSearch
14176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14177#[cfg_attr(feature = "bindings", derive(TS))]
14178pub struct VectorSearch {
14179    pub this: Box<Expression>,
14180    #[serde(default)]
14181    pub column_to_search: Option<Box<Expression>>,
14182    #[serde(default)]
14183    pub query_table: Option<Box<Expression>>,
14184    #[serde(default)]
14185    pub query_column_to_search: Option<Box<Expression>>,
14186    #[serde(default)]
14187    pub top_k: Option<Box<Expression>>,
14188    #[serde(default)]
14189    pub distance_type: Option<Box<Expression>>,
14190    #[serde(default)]
14191    pub options: Vec<Expression>,
14192}
14193
14194/// Quantile
14195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14196#[cfg_attr(feature = "bindings", derive(TS))]
14197pub struct Quantile {
14198    pub this: Box<Expression>,
14199    #[serde(default)]
14200    pub quantile: Option<Box<Expression>>,
14201}
14202
14203/// ApproxQuantile
14204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14205#[cfg_attr(feature = "bindings", derive(TS))]
14206pub struct ApproxQuantile {
14207    pub this: Box<Expression>,
14208    #[serde(default)]
14209    pub quantile: Option<Box<Expression>>,
14210    #[serde(default)]
14211    pub accuracy: Option<Box<Expression>>,
14212    #[serde(default)]
14213    pub weight: Option<Box<Expression>>,
14214    #[serde(default)]
14215    pub error_tolerance: Option<Box<Expression>>,
14216}
14217
14218/// ApproxPercentileEstimate
14219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14220#[cfg_attr(feature = "bindings", derive(TS))]
14221pub struct ApproxPercentileEstimate {
14222    pub this: Box<Expression>,
14223    #[serde(default)]
14224    pub percentile: Option<Box<Expression>>,
14225}
14226
14227/// Randn
14228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14229#[cfg_attr(feature = "bindings", derive(TS))]
14230pub struct Randn {
14231    #[serde(default)]
14232    pub this: Option<Box<Expression>>,
14233}
14234
14235/// Randstr
14236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14237#[cfg_attr(feature = "bindings", derive(TS))]
14238pub struct Randstr {
14239    pub this: Box<Expression>,
14240    #[serde(default)]
14241    pub generator: Option<Box<Expression>>,
14242}
14243
14244/// RangeN
14245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14246#[cfg_attr(feature = "bindings", derive(TS))]
14247pub struct RangeN {
14248    pub this: Box<Expression>,
14249    #[serde(default)]
14250    pub expressions: Vec<Expression>,
14251    #[serde(default)]
14252    pub each: Option<Box<Expression>>,
14253}
14254
14255/// RangeBucket
14256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14257#[cfg_attr(feature = "bindings", derive(TS))]
14258pub struct RangeBucket {
14259    pub this: Box<Expression>,
14260    pub expression: Box<Expression>,
14261}
14262
14263/// ReadCSV
14264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14265#[cfg_attr(feature = "bindings", derive(TS))]
14266pub struct ReadCSV {
14267    pub this: Box<Expression>,
14268    #[serde(default)]
14269    pub expressions: Vec<Expression>,
14270}
14271
14272/// ReadParquet
14273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14274#[cfg_attr(feature = "bindings", derive(TS))]
14275pub struct ReadParquet {
14276    #[serde(default)]
14277    pub expressions: Vec<Expression>,
14278}
14279
14280/// Reduce
14281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14282#[cfg_attr(feature = "bindings", derive(TS))]
14283pub struct Reduce {
14284    pub this: Box<Expression>,
14285    #[serde(default)]
14286    pub initial: Option<Box<Expression>>,
14287    #[serde(default)]
14288    pub merge: Option<Box<Expression>>,
14289    #[serde(default)]
14290    pub finish: Option<Box<Expression>>,
14291}
14292
14293/// RegexpExtractAll
14294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14295#[cfg_attr(feature = "bindings", derive(TS))]
14296pub struct RegexpExtractAll {
14297    pub this: Box<Expression>,
14298    pub expression: Box<Expression>,
14299    #[serde(default)]
14300    pub group: Option<Box<Expression>>,
14301    #[serde(default)]
14302    pub parameters: Option<Box<Expression>>,
14303    #[serde(default)]
14304    pub position: Option<Box<Expression>>,
14305    #[serde(default)]
14306    pub occurrence: Option<Box<Expression>>,
14307}
14308
14309/// RegexpILike
14310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14311#[cfg_attr(feature = "bindings", derive(TS))]
14312pub struct RegexpILike {
14313    pub this: Box<Expression>,
14314    pub expression: Box<Expression>,
14315    #[serde(default)]
14316    pub flag: Option<Box<Expression>>,
14317}
14318
14319/// RegexpFullMatch
14320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14321#[cfg_attr(feature = "bindings", derive(TS))]
14322pub struct RegexpFullMatch {
14323    pub this: Box<Expression>,
14324    pub expression: Box<Expression>,
14325    #[serde(default)]
14326    pub options: Vec<Expression>,
14327}
14328
14329/// RegexpInstr
14330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14331#[cfg_attr(feature = "bindings", derive(TS))]
14332pub struct RegexpInstr {
14333    pub this: Box<Expression>,
14334    pub expression: Box<Expression>,
14335    #[serde(default)]
14336    pub position: Option<Box<Expression>>,
14337    #[serde(default)]
14338    pub occurrence: Option<Box<Expression>>,
14339    #[serde(default)]
14340    pub option: Option<Box<Expression>>,
14341    #[serde(default)]
14342    pub parameters: Option<Box<Expression>>,
14343    #[serde(default)]
14344    pub group: Option<Box<Expression>>,
14345}
14346
14347/// RegexpSplit
14348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14349#[cfg_attr(feature = "bindings", derive(TS))]
14350pub struct RegexpSplit {
14351    pub this: Box<Expression>,
14352    pub expression: Box<Expression>,
14353    #[serde(default)]
14354    pub limit: Option<Box<Expression>>,
14355}
14356
14357/// RegexpCount
14358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14359#[cfg_attr(feature = "bindings", derive(TS))]
14360pub struct RegexpCount {
14361    pub this: Box<Expression>,
14362    pub expression: Box<Expression>,
14363    #[serde(default)]
14364    pub position: Option<Box<Expression>>,
14365    #[serde(default)]
14366    pub parameters: Option<Box<Expression>>,
14367}
14368
14369/// RegrValx
14370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14371#[cfg_attr(feature = "bindings", derive(TS))]
14372pub struct RegrValx {
14373    pub this: Box<Expression>,
14374    pub expression: Box<Expression>,
14375}
14376
14377/// RegrValy
14378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14379#[cfg_attr(feature = "bindings", derive(TS))]
14380pub struct RegrValy {
14381    pub this: Box<Expression>,
14382    pub expression: Box<Expression>,
14383}
14384
14385/// RegrAvgy
14386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14387#[cfg_attr(feature = "bindings", derive(TS))]
14388pub struct RegrAvgy {
14389    pub this: Box<Expression>,
14390    pub expression: Box<Expression>,
14391}
14392
14393/// RegrAvgx
14394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14395#[cfg_attr(feature = "bindings", derive(TS))]
14396pub struct RegrAvgx {
14397    pub this: Box<Expression>,
14398    pub expression: Box<Expression>,
14399}
14400
14401/// RegrCount
14402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14403#[cfg_attr(feature = "bindings", derive(TS))]
14404pub struct RegrCount {
14405    pub this: Box<Expression>,
14406    pub expression: Box<Expression>,
14407}
14408
14409/// RegrIntercept
14410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14411#[cfg_attr(feature = "bindings", derive(TS))]
14412pub struct RegrIntercept {
14413    pub this: Box<Expression>,
14414    pub expression: Box<Expression>,
14415}
14416
14417/// RegrR2
14418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14419#[cfg_attr(feature = "bindings", derive(TS))]
14420pub struct RegrR2 {
14421    pub this: Box<Expression>,
14422    pub expression: Box<Expression>,
14423}
14424
14425/// RegrSxx
14426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14427#[cfg_attr(feature = "bindings", derive(TS))]
14428pub struct RegrSxx {
14429    pub this: Box<Expression>,
14430    pub expression: Box<Expression>,
14431}
14432
14433/// RegrSxy
14434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14435#[cfg_attr(feature = "bindings", derive(TS))]
14436pub struct RegrSxy {
14437    pub this: Box<Expression>,
14438    pub expression: Box<Expression>,
14439}
14440
14441/// RegrSyy
14442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14443#[cfg_attr(feature = "bindings", derive(TS))]
14444pub struct RegrSyy {
14445    pub this: Box<Expression>,
14446    pub expression: Box<Expression>,
14447}
14448
14449/// RegrSlope
14450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14451#[cfg_attr(feature = "bindings", derive(TS))]
14452pub struct RegrSlope {
14453    pub this: Box<Expression>,
14454    pub expression: Box<Expression>,
14455}
14456
14457/// SafeAdd
14458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14459#[cfg_attr(feature = "bindings", derive(TS))]
14460pub struct SafeAdd {
14461    pub this: Box<Expression>,
14462    pub expression: Box<Expression>,
14463}
14464
14465/// SafeDivide
14466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14467#[cfg_attr(feature = "bindings", derive(TS))]
14468pub struct SafeDivide {
14469    pub this: Box<Expression>,
14470    pub expression: Box<Expression>,
14471}
14472
14473/// SafeMultiply
14474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14475#[cfg_attr(feature = "bindings", derive(TS))]
14476pub struct SafeMultiply {
14477    pub this: Box<Expression>,
14478    pub expression: Box<Expression>,
14479}
14480
14481/// SafeSubtract
14482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14483#[cfg_attr(feature = "bindings", derive(TS))]
14484pub struct SafeSubtract {
14485    pub this: Box<Expression>,
14486    pub expression: Box<Expression>,
14487}
14488
14489/// SHA2
14490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14491#[cfg_attr(feature = "bindings", derive(TS))]
14492pub struct SHA2 {
14493    pub this: Box<Expression>,
14494    #[serde(default)]
14495    pub length: Option<i64>,
14496}
14497
14498/// SHA2Digest
14499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14500#[cfg_attr(feature = "bindings", derive(TS))]
14501pub struct SHA2Digest {
14502    pub this: Box<Expression>,
14503    #[serde(default)]
14504    pub length: Option<i64>,
14505}
14506
14507/// SortArray
14508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14509#[cfg_attr(feature = "bindings", derive(TS))]
14510pub struct SortArray {
14511    pub this: Box<Expression>,
14512    #[serde(default)]
14513    pub asc: Option<Box<Expression>>,
14514    #[serde(default)]
14515    pub nulls_first: Option<Box<Expression>>,
14516}
14517
14518/// SplitPart
14519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14520#[cfg_attr(feature = "bindings", derive(TS))]
14521pub struct SplitPart {
14522    pub this: Box<Expression>,
14523    #[serde(default)]
14524    pub delimiter: Option<Box<Expression>>,
14525    #[serde(default)]
14526    pub part_index: Option<Box<Expression>>,
14527}
14528
14529/// SUBSTRING_INDEX(str, delim, count)
14530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14531#[cfg_attr(feature = "bindings", derive(TS))]
14532pub struct SubstringIndex {
14533    pub this: Box<Expression>,
14534    #[serde(default)]
14535    pub delimiter: Option<Box<Expression>>,
14536    #[serde(default)]
14537    pub count: Option<Box<Expression>>,
14538}
14539
14540/// StandardHash
14541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14542#[cfg_attr(feature = "bindings", derive(TS))]
14543pub struct StandardHash {
14544    pub this: Box<Expression>,
14545    #[serde(default)]
14546    pub expression: Option<Box<Expression>>,
14547}
14548
14549/// StrPosition
14550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14551#[cfg_attr(feature = "bindings", derive(TS))]
14552pub struct StrPosition {
14553    pub this: Box<Expression>,
14554    #[serde(default)]
14555    pub substr: Option<Box<Expression>>,
14556    #[serde(default)]
14557    pub position: Option<Box<Expression>>,
14558    #[serde(default)]
14559    pub occurrence: Option<Box<Expression>>,
14560}
14561
14562/// Search
14563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14564#[cfg_attr(feature = "bindings", derive(TS))]
14565pub struct Search {
14566    pub this: Box<Expression>,
14567    pub expression: Box<Expression>,
14568    #[serde(default)]
14569    pub json_scope: Option<Box<Expression>>,
14570    #[serde(default)]
14571    pub analyzer: Option<Box<Expression>>,
14572    #[serde(default)]
14573    pub analyzer_options: Option<Box<Expression>>,
14574    #[serde(default)]
14575    pub search_mode: Option<Box<Expression>>,
14576}
14577
14578/// SearchIp
14579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14580#[cfg_attr(feature = "bindings", derive(TS))]
14581pub struct SearchIp {
14582    pub this: Box<Expression>,
14583    pub expression: Box<Expression>,
14584}
14585
14586/// StrToDate
14587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14588#[cfg_attr(feature = "bindings", derive(TS))]
14589pub struct StrToDate {
14590    pub this: Box<Expression>,
14591    #[serde(default)]
14592    pub format: Option<String>,
14593    #[serde(default)]
14594    pub safe: Option<Box<Expression>>,
14595}
14596
14597/// StrToTime
14598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14599#[cfg_attr(feature = "bindings", derive(TS))]
14600pub struct StrToTime {
14601    pub this: Box<Expression>,
14602    pub format: String,
14603    #[serde(default)]
14604    pub zone: Option<Box<Expression>>,
14605    #[serde(default)]
14606    pub safe: Option<Box<Expression>>,
14607    #[serde(default)]
14608    pub target_type: Option<Box<Expression>>,
14609}
14610
14611/// StrToUnix
14612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14613#[cfg_attr(feature = "bindings", derive(TS))]
14614pub struct StrToUnix {
14615    #[serde(default)]
14616    pub this: Option<Box<Expression>>,
14617    #[serde(default)]
14618    pub format: Option<String>,
14619}
14620
14621/// StrToMap
14622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14623#[cfg_attr(feature = "bindings", derive(TS))]
14624pub struct StrToMap {
14625    pub this: Box<Expression>,
14626    #[serde(default)]
14627    pub pair_delim: Option<Box<Expression>>,
14628    #[serde(default)]
14629    pub key_value_delim: Option<Box<Expression>>,
14630    #[serde(default)]
14631    pub duplicate_resolution_callback: Option<Box<Expression>>,
14632}
14633
14634/// NumberToStr
14635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14636#[cfg_attr(feature = "bindings", derive(TS))]
14637pub struct NumberToStr {
14638    pub this: Box<Expression>,
14639    pub format: String,
14640    #[serde(default)]
14641    pub culture: Option<Box<Expression>>,
14642}
14643
14644/// FromBase
14645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14646#[cfg_attr(feature = "bindings", derive(TS))]
14647pub struct FromBase {
14648    pub this: Box<Expression>,
14649    pub expression: Box<Expression>,
14650}
14651
14652/// Stuff
14653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14654#[cfg_attr(feature = "bindings", derive(TS))]
14655pub struct Stuff {
14656    pub this: Box<Expression>,
14657    #[serde(default)]
14658    pub start: Option<Box<Expression>>,
14659    #[serde(default)]
14660    pub length: Option<i64>,
14661    pub expression: Box<Expression>,
14662}
14663
14664/// TimeToStr
14665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14666#[cfg_attr(feature = "bindings", derive(TS))]
14667pub struct TimeToStr {
14668    pub this: Box<Expression>,
14669    pub format: String,
14670    #[serde(default)]
14671    pub culture: Option<Box<Expression>>,
14672    #[serde(default)]
14673    pub zone: Option<Box<Expression>>,
14674}
14675
14676/// TimeStrToTime
14677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14678#[cfg_attr(feature = "bindings", derive(TS))]
14679pub struct TimeStrToTime {
14680    pub this: Box<Expression>,
14681    #[serde(default)]
14682    pub zone: Option<Box<Expression>>,
14683}
14684
14685/// TsOrDsAdd
14686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14687#[cfg_attr(feature = "bindings", derive(TS))]
14688pub struct TsOrDsAdd {
14689    pub this: Box<Expression>,
14690    pub expression: Box<Expression>,
14691    #[serde(default)]
14692    pub unit: Option<String>,
14693    #[serde(default)]
14694    pub return_type: Option<Box<Expression>>,
14695}
14696
14697/// TsOrDsDiff
14698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14699#[cfg_attr(feature = "bindings", derive(TS))]
14700pub struct TsOrDsDiff {
14701    pub this: Box<Expression>,
14702    pub expression: Box<Expression>,
14703    #[serde(default)]
14704    pub unit: Option<String>,
14705}
14706
14707/// TsOrDsToDate
14708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14709#[cfg_attr(feature = "bindings", derive(TS))]
14710pub struct TsOrDsToDate {
14711    pub this: Box<Expression>,
14712    #[serde(default)]
14713    pub format: Option<String>,
14714    #[serde(default)]
14715    pub safe: Option<Box<Expression>>,
14716}
14717
14718/// TsOrDsToTime
14719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14720#[cfg_attr(feature = "bindings", derive(TS))]
14721pub struct TsOrDsToTime {
14722    pub this: Box<Expression>,
14723    #[serde(default)]
14724    pub format: Option<String>,
14725    #[serde(default)]
14726    pub safe: Option<Box<Expression>>,
14727}
14728
14729/// Unhex
14730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14731#[cfg_attr(feature = "bindings", derive(TS))]
14732pub struct Unhex {
14733    pub this: Box<Expression>,
14734    #[serde(default)]
14735    pub expression: Option<Box<Expression>>,
14736}
14737
14738/// Uniform
14739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14740#[cfg_attr(feature = "bindings", derive(TS))]
14741pub struct Uniform {
14742    pub this: Box<Expression>,
14743    pub expression: Box<Expression>,
14744    #[serde(default)]
14745    pub gen: Option<Box<Expression>>,
14746    #[serde(default)]
14747    pub seed: Option<Box<Expression>>,
14748}
14749
14750/// UnixToStr
14751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14752#[cfg_attr(feature = "bindings", derive(TS))]
14753pub struct UnixToStr {
14754    pub this: Box<Expression>,
14755    #[serde(default)]
14756    pub format: Option<String>,
14757}
14758
14759/// UnixToTime
14760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14761#[cfg_attr(feature = "bindings", derive(TS))]
14762pub struct UnixToTime {
14763    pub this: Box<Expression>,
14764    #[serde(default)]
14765    pub scale: Option<i64>,
14766    #[serde(default)]
14767    pub zone: Option<Box<Expression>>,
14768    #[serde(default)]
14769    pub hours: Option<Box<Expression>>,
14770    #[serde(default)]
14771    pub minutes: Option<Box<Expression>>,
14772    #[serde(default)]
14773    pub format: Option<String>,
14774    #[serde(default)]
14775    pub target_type: Option<Box<Expression>>,
14776}
14777
14778/// Uuid
14779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14780#[cfg_attr(feature = "bindings", derive(TS))]
14781pub struct Uuid {
14782    #[serde(default)]
14783    pub this: Option<Box<Expression>>,
14784    #[serde(default)]
14785    pub name: Option<String>,
14786    #[serde(default)]
14787    pub is_string: Option<Box<Expression>>,
14788}
14789
14790/// TimestampFromParts
14791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14792#[cfg_attr(feature = "bindings", derive(TS))]
14793pub struct TimestampFromParts {
14794    #[serde(default)]
14795    pub zone: Option<Box<Expression>>,
14796    #[serde(default)]
14797    pub milli: Option<Box<Expression>>,
14798    #[serde(default)]
14799    pub this: Option<Box<Expression>>,
14800    #[serde(default)]
14801    pub expression: Option<Box<Expression>>,
14802}
14803
14804/// TimestampTzFromParts
14805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14806#[cfg_attr(feature = "bindings", derive(TS))]
14807pub struct TimestampTzFromParts {
14808    #[serde(default)]
14809    pub zone: Option<Box<Expression>>,
14810}
14811
14812/// Corr
14813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14814#[cfg_attr(feature = "bindings", derive(TS))]
14815pub struct Corr {
14816    pub this: Box<Expression>,
14817    pub expression: Box<Expression>,
14818    #[serde(default)]
14819    pub null_on_zero_variance: Option<Box<Expression>>,
14820}
14821
14822/// WidthBucket
14823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14824#[cfg_attr(feature = "bindings", derive(TS))]
14825pub struct WidthBucket {
14826    pub this: Box<Expression>,
14827    #[serde(default)]
14828    pub min_value: Option<Box<Expression>>,
14829    #[serde(default)]
14830    pub max_value: Option<Box<Expression>>,
14831    #[serde(default)]
14832    pub num_buckets: Option<Box<Expression>>,
14833    #[serde(default)]
14834    pub threshold: Option<Box<Expression>>,
14835}
14836
14837/// CovarSamp
14838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14839#[cfg_attr(feature = "bindings", derive(TS))]
14840pub struct CovarSamp {
14841    pub this: Box<Expression>,
14842    pub expression: Box<Expression>,
14843}
14844
14845/// CovarPop
14846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14847#[cfg_attr(feature = "bindings", derive(TS))]
14848pub struct CovarPop {
14849    pub this: Box<Expression>,
14850    pub expression: Box<Expression>,
14851}
14852
14853/// Week
14854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14855#[cfg_attr(feature = "bindings", derive(TS))]
14856pub struct Week {
14857    pub this: Box<Expression>,
14858    #[serde(default)]
14859    pub mode: Option<Box<Expression>>,
14860}
14861
14862/// XMLElement
14863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14864#[cfg_attr(feature = "bindings", derive(TS))]
14865pub struct XMLElement {
14866    pub this: Box<Expression>,
14867    #[serde(default)]
14868    pub expressions: Vec<Expression>,
14869    #[serde(default)]
14870    pub evalname: Option<Box<Expression>>,
14871}
14872
14873/// XMLGet
14874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14875#[cfg_attr(feature = "bindings", derive(TS))]
14876pub struct XMLGet {
14877    pub this: Box<Expression>,
14878    pub expression: Box<Expression>,
14879    #[serde(default)]
14880    pub instance: Option<Box<Expression>>,
14881}
14882
14883/// XMLTable
14884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14885#[cfg_attr(feature = "bindings", derive(TS))]
14886pub struct XMLTable {
14887    pub this: Box<Expression>,
14888    #[serde(default)]
14889    pub namespaces: Option<Box<Expression>>,
14890    #[serde(default)]
14891    pub passing: Option<Box<Expression>>,
14892    #[serde(default)]
14893    pub columns: Vec<Expression>,
14894    #[serde(default)]
14895    pub by_ref: Option<Box<Expression>>,
14896}
14897
14898/// XMLKeyValueOption
14899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14900#[cfg_attr(feature = "bindings", derive(TS))]
14901pub struct XMLKeyValueOption {
14902    pub this: Box<Expression>,
14903    #[serde(default)]
14904    pub expression: Option<Box<Expression>>,
14905}
14906
14907/// Zipf
14908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14909#[cfg_attr(feature = "bindings", derive(TS))]
14910pub struct Zipf {
14911    pub this: Box<Expression>,
14912    #[serde(default)]
14913    pub elementcount: Option<Box<Expression>>,
14914    #[serde(default)]
14915    pub gen: Option<Box<Expression>>,
14916}
14917
14918/// Merge
14919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14920#[cfg_attr(feature = "bindings", derive(TS))]
14921pub struct Merge {
14922    pub this: Box<Expression>,
14923    pub using: Box<Expression>,
14924    #[serde(default)]
14925    pub on: Option<Box<Expression>>,
14926    #[serde(default)]
14927    pub using_cond: Option<Box<Expression>>,
14928    #[serde(default)]
14929    pub whens: Option<Box<Expression>>,
14930    #[serde(default)]
14931    pub with_: Option<Box<Expression>>,
14932    #[serde(default)]
14933    pub returning: Option<Box<Expression>>,
14934}
14935
14936/// When
14937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14938#[cfg_attr(feature = "bindings", derive(TS))]
14939pub struct When {
14940    #[serde(default)]
14941    pub matched: Option<Box<Expression>>,
14942    #[serde(default)]
14943    pub source: Option<Box<Expression>>,
14944    #[serde(default)]
14945    pub condition: Option<Box<Expression>>,
14946    pub then: Box<Expression>,
14947}
14948
14949/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14951#[cfg_attr(feature = "bindings", derive(TS))]
14952pub struct Whens {
14953    #[serde(default)]
14954    pub expressions: Vec<Expression>,
14955}
14956
14957/// NextValueFor
14958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14959#[cfg_attr(feature = "bindings", derive(TS))]
14960pub struct NextValueFor {
14961    pub this: Box<Expression>,
14962    #[serde(default)]
14963    pub order: Option<Box<Expression>>,
14964}
14965
14966#[cfg(test)]
14967mod tests {
14968    use super::*;
14969
14970    #[test]
14971    #[cfg(feature = "bindings")]
14972    fn export_typescript_types() {
14973        // This test exports TypeScript types to the generated directory
14974        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14975        Expression::export_all(&ts_rs::Config::default())
14976            .expect("Failed to export Expression types");
14977    }
14978
14979    #[test]
14980    fn test_simple_select_builder() {
14981        let select = Select::new()
14982            .column(Expression::star())
14983            .from(Expression::Table(Box::new(TableRef::new("users"))));
14984
14985        assert_eq!(select.expressions.len(), 1);
14986        assert!(select.from.is_some());
14987    }
14988
14989    #[test]
14990    fn test_expression_alias() {
14991        let expr = Expression::column("id").alias("user_id");
14992
14993        match expr {
14994            Expression::Alias(a) => {
14995                assert_eq!(a.alias.name, "user_id");
14996            }
14997            _ => panic!("Expected Alias"),
14998        }
14999    }
15000
15001    #[test]
15002    fn test_literal_creation() {
15003        let num = Expression::number(42);
15004        let str = Expression::string("hello");
15005
15006        match num {
15007            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
15008                let Literal::Number(n) = lit.as_ref() else {
15009                    unreachable!()
15010                };
15011                assert_eq!(n, "42")
15012            }
15013            _ => panic!("Expected Number"),
15014        }
15015
15016        match str {
15017            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
15018                let Literal::String(s) = lit.as_ref() else {
15019                    unreachable!()
15020                };
15021                assert_eq!(s, "hello")
15022            }
15023            _ => panic!("Expected String"),
15024        }
15025    }
15026
15027    #[test]
15028    fn test_expression_sql() {
15029        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
15030        assert_eq!(expr.sql(), "SELECT 1 + 2");
15031    }
15032
15033    #[test]
15034    fn test_expression_sql_for() {
15035        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
15036        let sql = expr.sql_for(crate::DialectType::Generic);
15037        // Generic mode normalizes IF() to CASE WHEN
15038        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
15039    }
15040}