Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117    TryCatch(Box<TryCatch>),
118
119    // Expressions
120    Alias(Box<Alias>),
121    Cast(Box<Cast>),
122    Collation(Box<CollationExpr>),
123    Case(Box<Case>),
124
125    // Binary operations
126    And(Box<BinaryOp>),
127    Or(Box<BinaryOp>),
128    Add(Box<BinaryOp>),
129    Sub(Box<BinaryOp>),
130    Mul(Box<BinaryOp>),
131    Div(Box<BinaryOp>),
132    Mod(Box<BinaryOp>),
133    Eq(Box<BinaryOp>),
134    Neq(Box<BinaryOp>),
135    Lt(Box<BinaryOp>),
136    Lte(Box<BinaryOp>),
137    Gt(Box<BinaryOp>),
138    Gte(Box<BinaryOp>),
139    Like(Box<LikeOp>),
140    ILike(Box<LikeOp>),
141    /// SQLite MATCH operator (FTS)
142    Match(Box<BinaryOp>),
143    BitwiseAnd(Box<BinaryOp>),
144    BitwiseOr(Box<BinaryOp>),
145    BitwiseXor(Box<BinaryOp>),
146    Concat(Box<BinaryOp>),
147    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
148    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
149    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
150
151    // PostgreSQL array/JSONB operators
152    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
153    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
154    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
155    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
156    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
157    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
158    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
159    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
160
161    // Unary operations
162    Not(Box<UnaryOp>),
163    Neg(Box<UnaryOp>),
164    BitwiseNot(Box<UnaryOp>),
165
166    // Predicates
167    In(Box<In>),
168    Between(Box<Between>),
169    IsNull(Box<IsNull>),
170    IsTrue(Box<IsTrueFalse>),
171    IsFalse(Box<IsTrueFalse>),
172    IsJson(Box<IsJson>),
173    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
174    Exists(Box<Exists>),
175    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
176    MemberOf(Box<BinaryOp>),
177
178    // Functions
179    Function(Box<Function>),
180    AggregateFunction(Box<AggregateFunction>),
181    WindowFunction(Box<WindowFunction>),
182
183    // Clauses
184    From(Box<From>),
185    Join(Box<Join>),
186    JoinedTable(Box<JoinedTable>),
187    Where(Box<Where>),
188    GroupBy(Box<GroupBy>),
189    Having(Box<Having>),
190    OrderBy(Box<OrderBy>),
191    Limit(Box<Limit>),
192    Offset(Box<Offset>),
193    Qualify(Box<Qualify>),
194    With(Box<With>),
195    Cte(Box<Cte>),
196    DistributeBy(Box<DistributeBy>),
197    ClusterBy(Box<ClusterBy>),
198    SortBy(Box<SortBy>),
199    LateralView(Box<LateralView>),
200    Hint(Box<Hint>),
201    Pseudocolumn(Pseudocolumn),
202
203    // Oracle hierarchical queries (CONNECT BY)
204    Connect(Box<Connect>),
205    Prior(Box<Prior>),
206    ConnectByRoot(Box<ConnectByRoot>),
207
208    // Pattern matching (MATCH_RECOGNIZE)
209    MatchRecognize(Box<MatchRecognize>),
210
211    // Order expressions
212    Ordered(Box<Ordered>),
213
214    // Window specifications
215    Window(Box<WindowSpec>),
216    Over(Box<Over>),
217    WithinGroup(Box<WithinGroup>),
218
219    // Data types
220    DataType(DataType),
221
222    // Arrays and structs
223    Array(Box<Array>),
224    Struct(Box<Struct>),
225    Tuple(Box<Tuple>),
226
227    // Interval
228    Interval(Box<Interval>),
229
230    // String functions
231    ConcatWs(Box<ConcatWs>),
232    Substring(Box<SubstringFunc>),
233    Upper(Box<UnaryFunc>),
234    Lower(Box<UnaryFunc>),
235    Length(Box<UnaryFunc>),
236    Trim(Box<TrimFunc>),
237    LTrim(Box<UnaryFunc>),
238    RTrim(Box<UnaryFunc>),
239    Replace(Box<ReplaceFunc>),
240    Reverse(Box<UnaryFunc>),
241    Left(Box<LeftRightFunc>),
242    Right(Box<LeftRightFunc>),
243    Repeat(Box<RepeatFunc>),
244    Lpad(Box<PadFunc>),
245    Rpad(Box<PadFunc>),
246    Split(Box<SplitFunc>),
247    RegexpLike(Box<RegexpFunc>),
248    RegexpReplace(Box<RegexpReplaceFunc>),
249    RegexpExtract(Box<RegexpExtractFunc>),
250    Overlay(Box<OverlayFunc>),
251
252    // Math functions
253    Abs(Box<UnaryFunc>),
254    Round(Box<RoundFunc>),
255    Floor(Box<FloorFunc>),
256    Ceil(Box<CeilFunc>),
257    Power(Box<BinaryFunc>),
258    Sqrt(Box<UnaryFunc>),
259    Cbrt(Box<UnaryFunc>),
260    Ln(Box<UnaryFunc>),
261    Log(Box<LogFunc>),
262    Exp(Box<UnaryFunc>),
263    Sign(Box<UnaryFunc>),
264    Greatest(Box<VarArgFunc>),
265    Least(Box<VarArgFunc>),
266
267    // Date/time functions
268    CurrentDate(CurrentDate),
269    CurrentTime(CurrentTime),
270    CurrentTimestamp(CurrentTimestamp),
271    CurrentTimestampLTZ(CurrentTimestampLTZ),
272    AtTimeZone(Box<AtTimeZone>),
273    DateAdd(Box<DateAddFunc>),
274    DateSub(Box<DateAddFunc>),
275    DateDiff(Box<DateDiffFunc>),
276    DateTrunc(Box<DateTruncFunc>),
277    Extract(Box<ExtractFunc>),
278    ToDate(Box<ToDateFunc>),
279    ToTimestamp(Box<ToTimestampFunc>),
280    Date(Box<UnaryFunc>),
281    Time(Box<UnaryFunc>),
282    DateFromUnixDate(Box<UnaryFunc>),
283    UnixDate(Box<UnaryFunc>),
284    UnixSeconds(Box<UnaryFunc>),
285    UnixMillis(Box<UnaryFunc>),
286    UnixMicros(Box<UnaryFunc>),
287    UnixToTimeStr(Box<BinaryFunc>),
288    TimeStrToDate(Box<UnaryFunc>),
289    DateToDi(Box<UnaryFunc>),
290    DiToDate(Box<UnaryFunc>),
291    TsOrDiToDi(Box<UnaryFunc>),
292    TsOrDsToDatetime(Box<UnaryFunc>),
293    TsOrDsToTimestamp(Box<UnaryFunc>),
294    YearOfWeek(Box<UnaryFunc>),
295    YearOfWeekIso(Box<UnaryFunc>),
296
297    // Control flow functions
298    Coalesce(Box<VarArgFunc>),
299    NullIf(Box<BinaryFunc>),
300    IfFunc(Box<IfFunc>),
301    IfNull(Box<BinaryFunc>),
302    Nvl(Box<BinaryFunc>),
303    Nvl2(Box<Nvl2Func>),
304
305    // Type conversion
306    TryCast(Box<Cast>),
307    SafeCast(Box<Cast>),
308
309    // Typed aggregate functions
310    Count(Box<CountFunc>),
311    Sum(Box<AggFunc>),
312    Avg(Box<AggFunc>),
313    Min(Box<AggFunc>),
314    Max(Box<AggFunc>),
315    GroupConcat(Box<GroupConcatFunc>),
316    StringAgg(Box<StringAggFunc>),
317    ListAgg(Box<ListAggFunc>),
318    ArrayAgg(Box<AggFunc>),
319    CountIf(Box<AggFunc>),
320    SumIf(Box<SumIfFunc>),
321    Stddev(Box<AggFunc>),
322    StddevPop(Box<AggFunc>),
323    StddevSamp(Box<AggFunc>),
324    Variance(Box<AggFunc>),
325    VarPop(Box<AggFunc>),
326    VarSamp(Box<AggFunc>),
327    Median(Box<AggFunc>),
328    Mode(Box<AggFunc>),
329    First(Box<AggFunc>),
330    Last(Box<AggFunc>),
331    AnyValue(Box<AggFunc>),
332    ApproxDistinct(Box<AggFunc>),
333    ApproxCountDistinct(Box<AggFunc>),
334    ApproxPercentile(Box<ApproxPercentileFunc>),
335    Percentile(Box<PercentileFunc>),
336    LogicalAnd(Box<AggFunc>),
337    LogicalOr(Box<AggFunc>),
338    Skewness(Box<AggFunc>),
339    BitwiseCount(Box<UnaryFunc>),
340    ArrayConcatAgg(Box<AggFunc>),
341    ArrayUniqueAgg(Box<AggFunc>),
342    BoolXorAgg(Box<AggFunc>),
343
344    // Typed window functions
345    RowNumber(RowNumber),
346    Rank(Rank),
347    DenseRank(DenseRank),
348    NTile(Box<NTileFunc>),
349    Lead(Box<LeadLagFunc>),
350    Lag(Box<LeadLagFunc>),
351    FirstValue(Box<ValueFunc>),
352    LastValue(Box<ValueFunc>),
353    NthValue(Box<NthValueFunc>),
354    PercentRank(PercentRank),
355    CumeDist(CumeDist),
356    PercentileCont(Box<PercentileFunc>),
357    PercentileDisc(Box<PercentileFunc>),
358
359    // Additional string functions
360    Contains(Box<BinaryFunc>),
361    StartsWith(Box<BinaryFunc>),
362    EndsWith(Box<BinaryFunc>),
363    Position(Box<PositionFunc>),
364    Initcap(Box<UnaryFunc>),
365    Ascii(Box<UnaryFunc>),
366    Chr(Box<UnaryFunc>),
367    /// MySQL CHAR function with multiple args and optional USING charset
368    CharFunc(Box<CharFunc>),
369    Soundex(Box<UnaryFunc>),
370    Levenshtein(Box<BinaryFunc>),
371    ByteLength(Box<UnaryFunc>),
372    Hex(Box<UnaryFunc>),
373    LowerHex(Box<UnaryFunc>),
374    Unicode(Box<UnaryFunc>),
375
376    // Additional math functions
377    ModFunc(Box<BinaryFunc>),
378    Random(Random),
379    Rand(Box<Rand>),
380    TruncFunc(Box<TruncateFunc>),
381    Pi(Pi),
382    Radians(Box<UnaryFunc>),
383    Degrees(Box<UnaryFunc>),
384    Sin(Box<UnaryFunc>),
385    Cos(Box<UnaryFunc>),
386    Tan(Box<UnaryFunc>),
387    Asin(Box<UnaryFunc>),
388    Acos(Box<UnaryFunc>),
389    Atan(Box<UnaryFunc>),
390    Atan2(Box<BinaryFunc>),
391    IsNan(Box<UnaryFunc>),
392    IsInf(Box<UnaryFunc>),
393    IntDiv(Box<BinaryFunc>),
394
395    // Control flow
396    Decode(Box<DecodeFunc>),
397
398    // Additional date/time functions
399    DateFormat(Box<DateFormatFunc>),
400    FormatDate(Box<DateFormatFunc>),
401    Year(Box<UnaryFunc>),
402    Month(Box<UnaryFunc>),
403    Day(Box<UnaryFunc>),
404    Hour(Box<UnaryFunc>),
405    Minute(Box<UnaryFunc>),
406    Second(Box<UnaryFunc>),
407    DayOfWeek(Box<UnaryFunc>),
408    DayOfWeekIso(Box<UnaryFunc>),
409    DayOfMonth(Box<UnaryFunc>),
410    DayOfYear(Box<UnaryFunc>),
411    WeekOfYear(Box<UnaryFunc>),
412    Quarter(Box<UnaryFunc>),
413    AddMonths(Box<BinaryFunc>),
414    MonthsBetween(Box<BinaryFunc>),
415    LastDay(Box<LastDayFunc>),
416    NextDay(Box<BinaryFunc>),
417    Epoch(Box<UnaryFunc>),
418    EpochMs(Box<UnaryFunc>),
419    FromUnixtime(Box<FromUnixtimeFunc>),
420    UnixTimestamp(Box<UnixTimestampFunc>),
421    MakeDate(Box<MakeDateFunc>),
422    MakeTimestamp(Box<MakeTimestampFunc>),
423    TimestampTrunc(Box<DateTruncFunc>),
424    TimeStrToUnix(Box<UnaryFunc>),
425
426    // Session/User functions
427    SessionUser(SessionUser),
428
429    // Hash/Crypto functions
430    SHA(Box<UnaryFunc>),
431    SHA1Digest(Box<UnaryFunc>),
432
433    // Time conversion functions
434    TimeToUnix(Box<UnaryFunc>),
435
436    // Array functions
437    ArrayFunc(Box<ArrayConstructor>),
438    ArrayLength(Box<UnaryFunc>),
439    ArraySize(Box<UnaryFunc>),
440    Cardinality(Box<UnaryFunc>),
441    ArrayContains(Box<BinaryFunc>),
442    ArrayPosition(Box<BinaryFunc>),
443    ArrayAppend(Box<BinaryFunc>),
444    ArrayPrepend(Box<BinaryFunc>),
445    ArrayConcat(Box<VarArgFunc>),
446    ArraySort(Box<ArraySortFunc>),
447    ArrayReverse(Box<UnaryFunc>),
448    ArrayDistinct(Box<UnaryFunc>),
449    ArrayJoin(Box<ArrayJoinFunc>),
450    ArrayToString(Box<ArrayJoinFunc>),
451    Unnest(Box<UnnestFunc>),
452    Explode(Box<UnaryFunc>),
453    ExplodeOuter(Box<UnaryFunc>),
454    ArrayFilter(Box<ArrayFilterFunc>),
455    ArrayTransform(Box<ArrayTransformFunc>),
456    ArrayFlatten(Box<UnaryFunc>),
457    ArrayCompact(Box<UnaryFunc>),
458    ArrayIntersect(Box<VarArgFunc>),
459    ArrayUnion(Box<BinaryFunc>),
460    ArrayExcept(Box<BinaryFunc>),
461    ArrayRemove(Box<BinaryFunc>),
462    ArrayZip(Box<VarArgFunc>),
463    Sequence(Box<SequenceFunc>),
464    Generate(Box<SequenceFunc>),
465    ExplodingGenerateSeries(Box<SequenceFunc>),
466    ToArray(Box<UnaryFunc>),
467    StarMap(Box<BinaryFunc>),
468
469    // Struct functions
470    StructFunc(Box<StructConstructor>),
471    StructExtract(Box<StructExtractFunc>),
472    NamedStruct(Box<NamedStructFunc>),
473
474    // Map functions
475    MapFunc(Box<MapConstructor>),
476    MapFromEntries(Box<UnaryFunc>),
477    MapFromArrays(Box<BinaryFunc>),
478    MapKeys(Box<UnaryFunc>),
479    MapValues(Box<UnaryFunc>),
480    MapContainsKey(Box<BinaryFunc>),
481    MapConcat(Box<VarArgFunc>),
482    ElementAt(Box<BinaryFunc>),
483    TransformKeys(Box<TransformFunc>),
484    TransformValues(Box<TransformFunc>),
485
486    // Exasol: function call with EMITS clause
487    FunctionEmits(Box<FunctionEmits>),
488
489    // JSON functions
490    JsonExtract(Box<JsonExtractFunc>),
491    JsonExtractScalar(Box<JsonExtractFunc>),
492    JsonExtractPath(Box<JsonPathFunc>),
493    JsonArray(Box<VarArgFunc>),
494    JsonObject(Box<JsonObjectFunc>),
495    JsonQuery(Box<JsonExtractFunc>),
496    JsonValue(Box<JsonExtractFunc>),
497    JsonArrayLength(Box<UnaryFunc>),
498    JsonKeys(Box<UnaryFunc>),
499    JsonType(Box<UnaryFunc>),
500    ParseJson(Box<UnaryFunc>),
501    ToJson(Box<UnaryFunc>),
502    JsonSet(Box<JsonModifyFunc>),
503    JsonInsert(Box<JsonModifyFunc>),
504    JsonRemove(Box<JsonPathFunc>),
505    JsonMergePatch(Box<BinaryFunc>),
506    JsonArrayAgg(Box<JsonArrayAggFunc>),
507    JsonObjectAgg(Box<JsonObjectAggFunc>),
508
509    // Type casting/conversion
510    Convert(Box<ConvertFunc>),
511    Typeof(Box<UnaryFunc>),
512
513    // Additional expressions
514    Lambda(Box<LambdaExpr>),
515    Parameter(Box<Parameter>),
516    Placeholder(Placeholder),
517    NamedArgument(Box<NamedArgument>),
518    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
519    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
520    TableArgument(Box<TableArgument>),
521    SqlComment(Box<SqlComment>),
522
523    // Additional predicates
524    NullSafeEq(Box<BinaryOp>),
525    NullSafeNeq(Box<BinaryOp>),
526    Glob(Box<BinaryOp>),
527    SimilarTo(Box<SimilarToExpr>),
528    Any(Box<QuantifiedExpr>),
529    All(Box<QuantifiedExpr>),
530    Overlaps(Box<OverlapsExpr>),
531
532    // Bitwise operations
533    BitwiseLeftShift(Box<BinaryOp>),
534    BitwiseRightShift(Box<BinaryOp>),
535    BitwiseAndAgg(Box<AggFunc>),
536    BitwiseOrAgg(Box<AggFunc>),
537    BitwiseXorAgg(Box<AggFunc>),
538
539    // Array/struct/map access
540    Subscript(Box<Subscript>),
541    Dot(Box<DotAccess>),
542    MethodCall(Box<MethodCall>),
543    ArraySlice(Box<ArraySlice>),
544
545    // DDL statements
546    CreateTable(Box<CreateTable>),
547    DropTable(Box<DropTable>),
548    Undrop(Box<Undrop>),
549    AlterTable(Box<AlterTable>),
550    CreateIndex(Box<CreateIndex>),
551    DropIndex(Box<DropIndex>),
552    CreateView(Box<CreateView>),
553    DropView(Box<DropView>),
554    AlterView(Box<AlterView>),
555    AlterIndex(Box<AlterIndex>),
556    Truncate(Box<Truncate>),
557    Use(Box<Use>),
558    Cache(Box<Cache>),
559    Uncache(Box<Uncache>),
560    LoadData(Box<LoadData>),
561    Pragma(Box<Pragma>),
562    Grant(Box<Grant>),
563    Revoke(Box<Revoke>),
564    Comment(Box<Comment>),
565    SetStatement(Box<SetStatement>),
566    // Phase 4: Additional DDL statements
567    CreateSchema(Box<CreateSchema>),
568    DropSchema(Box<DropSchema>),
569    DropNamespace(Box<DropNamespace>),
570    CreateDatabase(Box<CreateDatabase>),
571    DropDatabase(Box<DropDatabase>),
572    CreateFunction(Box<CreateFunction>),
573    DropFunction(Box<DropFunction>),
574    CreateProcedure(Box<CreateProcedure>),
575    DropProcedure(Box<DropProcedure>),
576    CreateSequence(Box<CreateSequence>),
577    CreateSynonym(Box<CreateSynonym>),
578    DropSequence(Box<DropSequence>),
579    AlterSequence(Box<AlterSequence>),
580    CreateTrigger(Box<CreateTrigger>),
581    DropTrigger(Box<DropTrigger>),
582    CreateType(Box<CreateType>),
583    DropType(Box<DropType>),
584    Describe(Box<Describe>),
585    Show(Box<Show>),
586
587    // Transaction and other commands
588    Command(Box<Command>),
589    Kill(Box<Kill>),
590    /// PREPARE statement (PostgreSQL/generic prepared statement definition)
591    Prepare(Box<PrepareStatement>),
592    /// EXEC/EXECUTE statement (TSQL stored procedure call)
593    Execute(Box<ExecuteStatement>),
594
595    /// Snowflake CREATE TASK statement
596    CreateTask(Box<CreateTask>),
597
598    // Placeholder for unparsed/raw SQL
599    Raw(Raw),
600
601    // Paren for grouping
602    Paren(Box<Paren>),
603
604    // Expression with trailing comments (for round-trip preservation)
605    Annotated(Box<Annotated>),
606
607    // === BATCH GENERATED EXPRESSION TYPES ===
608    // Generated from Python sqlglot expressions.py
609    Refresh(Box<Refresh>),
610    LockingStatement(Box<LockingStatement>),
611    SequenceProperties(Box<SequenceProperties>),
612    TruncateTable(Box<TruncateTable>),
613    Clone(Box<Clone>),
614    Attach(Box<Attach>),
615    Detach(Box<Detach>),
616    Install(Box<Install>),
617    Summarize(Box<Summarize>),
618    Declare(Box<Declare>),
619    DeclareItem(Box<DeclareItem>),
620    Set(Box<Set>),
621    Heredoc(Box<Heredoc>),
622    SetItem(Box<SetItem>),
623    QueryBand(Box<QueryBand>),
624    UserDefinedFunction(Box<UserDefinedFunction>),
625    RecursiveWithSearch(Box<RecursiveWithSearch>),
626    ProjectionDef(Box<ProjectionDef>),
627    TableAlias(Box<TableAlias>),
628    ByteString(Box<ByteString>),
629    HexStringExpr(Box<HexStringExpr>),
630    UnicodeString(Box<UnicodeString>),
631    ColumnPosition(Box<ColumnPosition>),
632    ColumnDef(Box<ColumnDef>),
633    AlterColumn(Box<AlterColumn>),
634    AlterSortKey(Box<AlterSortKey>),
635    AlterSet(Box<AlterSet>),
636    RenameColumn(Box<RenameColumn>),
637    Comprehension(Box<Comprehension>),
638    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
639    MergeTreeTTL(Box<MergeTreeTTL>),
640    IndexConstraintOption(Box<IndexConstraintOption>),
641    ColumnConstraint(Box<ColumnConstraint>),
642    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
643    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
644    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
645    CheckColumnConstraint(Box<CheckColumnConstraint>),
646    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
647    CompressColumnConstraint(Box<CompressColumnConstraint>),
648    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
649    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
650    WithOperator(Box<WithOperator>),
651    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
652    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
653    CommentColumnConstraint(CommentColumnConstraint),
654    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
655    IndexColumnConstraint(Box<IndexColumnConstraint>),
656    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
657    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
658    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
659    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
660    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
661    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
662    InOutColumnConstraint(Box<InOutColumnConstraint>),
663    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
664    PathColumnConstraint(Box<PathColumnConstraint>),
665    Constraint(Box<Constraint>),
666    Export(Box<Export>),
667    Filter(Box<Filter>),
668    Changes(Box<Changes>),
669    CopyParameter(Box<CopyParameter>),
670    Credentials(Box<Credentials>),
671    Directory(Box<Directory>),
672    ForeignKey(Box<ForeignKey>),
673    ColumnPrefix(Box<ColumnPrefix>),
674    PrimaryKey(Box<PrimaryKey>),
675    IntoClause(Box<IntoClause>),
676    JoinHint(Box<JoinHint>),
677    Opclass(Box<Opclass>),
678    Index(Box<Index>),
679    IndexParameters(Box<IndexParameters>),
680    ConditionalInsert(Box<ConditionalInsert>),
681    MultitableInserts(Box<MultitableInserts>),
682    OnConflict(Box<OnConflict>),
683    OnCondition(Box<OnCondition>),
684    Returning(Box<Returning>),
685    Introducer(Box<Introducer>),
686    PartitionRange(Box<PartitionRange>),
687    Fetch(Box<Fetch>),
688    Group(Box<Group>),
689    Cube(Box<Cube>),
690    Rollup(Box<Rollup>),
691    GroupingSets(Box<GroupingSets>),
692    LimitOptions(Box<LimitOptions>),
693    Lateral(Box<Lateral>),
694    TableFromRows(Box<TableFromRows>),
695    RowsFrom(Box<RowsFrom>),
696    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
697    WithFill(Box<WithFill>),
698    Property(Box<Property>),
699    GrantPrivilege(Box<GrantPrivilege>),
700    GrantPrincipal(Box<GrantPrincipal>),
701    AllowedValuesProperty(Box<AllowedValuesProperty>),
702    AlgorithmProperty(Box<AlgorithmProperty>),
703    AutoIncrementProperty(Box<AutoIncrementProperty>),
704    AutoRefreshProperty(Box<AutoRefreshProperty>),
705    BackupProperty(Box<BackupProperty>),
706    BuildProperty(Box<BuildProperty>),
707    BlockCompressionProperty(Box<BlockCompressionProperty>),
708    CharacterSetProperty(Box<CharacterSetProperty>),
709    ChecksumProperty(Box<ChecksumProperty>),
710    CollateProperty(Box<CollateProperty>),
711    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
712    DataDeletionProperty(Box<DataDeletionProperty>),
713    DefinerProperty(Box<DefinerProperty>),
714    DistKeyProperty(Box<DistKeyProperty>),
715    DistributedByProperty(Box<DistributedByProperty>),
716    DistStyleProperty(Box<DistStyleProperty>),
717    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
718    EngineProperty(Box<EngineProperty>),
719    ToTableProperty(Box<ToTableProperty>),
720    ExecuteAsProperty(Box<ExecuteAsProperty>),
721    ExternalProperty(Box<ExternalProperty>),
722    FallbackProperty(Box<FallbackProperty>),
723    FileFormatProperty(Box<FileFormatProperty>),
724    CredentialsProperty(Box<CredentialsProperty>),
725    FreespaceProperty(Box<FreespaceProperty>),
726    InheritsProperty(Box<InheritsProperty>),
727    InputModelProperty(Box<InputModelProperty>),
728    OutputModelProperty(Box<OutputModelProperty>),
729    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
730    JournalProperty(Box<JournalProperty>),
731    LanguageProperty(Box<LanguageProperty>),
732    EnviromentProperty(Box<EnviromentProperty>),
733    ClusteredByProperty(Box<ClusteredByProperty>),
734    DictProperty(Box<DictProperty>),
735    DictRange(Box<DictRange>),
736    OnCluster(Box<OnCluster>),
737    LikeProperty(Box<LikeProperty>),
738    LocationProperty(Box<LocationProperty>),
739    LockProperty(Box<LockProperty>),
740    LockingProperty(Box<LockingProperty>),
741    LogProperty(Box<LogProperty>),
742    MaterializedProperty(Box<MaterializedProperty>),
743    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
744    OnProperty(Box<OnProperty>),
745    OnCommitProperty(Box<OnCommitProperty>),
746    PartitionedByProperty(Box<PartitionedByProperty>),
747    PartitionByProperty(Box<PartitionByProperty>),
748    PartitionedByBucket(Box<PartitionedByBucket>),
749    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
750    PartitionByTruncate(Box<PartitionByTruncate>),
751    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
752    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
753    PartitionByListProperty(Box<PartitionByListProperty>),
754    PartitionList(Box<PartitionList>),
755    Partition(Box<Partition>),
756    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
757    UniqueKeyProperty(Box<UniqueKeyProperty>),
758    RollupProperty(Box<RollupProperty>),
759    PartitionBoundSpec(Box<PartitionBoundSpec>),
760    PartitionedOfProperty(Box<PartitionedOfProperty>),
761    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
762    ReturnsProperty(Box<ReturnsProperty>),
763    RowFormatProperty(Box<RowFormatProperty>),
764    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
765    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
766    QueryTransform(Box<QueryTransform>),
767    SampleProperty(Box<SampleProperty>),
768    SecurityProperty(Box<SecurityProperty>),
769    SchemaCommentProperty(Box<SchemaCommentProperty>),
770    SemanticView(Box<SemanticView>),
771    SerdeProperties(Box<SerdeProperties>),
772    SetProperty(Box<SetProperty>),
773    SharingProperty(Box<SharingProperty>),
774    SetConfigProperty(Box<SetConfigProperty>),
775    SettingsProperty(Box<SettingsProperty>),
776    SortKeyProperty(Box<SortKeyProperty>),
777    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
778    SqlSecurityProperty(Box<SqlSecurityProperty>),
779    StabilityProperty(Box<StabilityProperty>),
780    StorageHandlerProperty(Box<StorageHandlerProperty>),
781    TemporaryProperty(Box<TemporaryProperty>),
782    Tags(Box<Tags>),
783    TransformModelProperty(Box<TransformModelProperty>),
784    TransientProperty(Box<TransientProperty>),
785    UsingTemplateProperty(Box<UsingTemplateProperty>),
786    ViewAttributeProperty(Box<ViewAttributeProperty>),
787    VolatileProperty(Box<VolatileProperty>),
788    WithDataProperty(Box<WithDataProperty>),
789    WithJournalTableProperty(Box<WithJournalTableProperty>),
790    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
791    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
792    WithProcedureOptions(Box<WithProcedureOptions>),
793    EncodeProperty(Box<EncodeProperty>),
794    IncludeProperty(Box<IncludeProperty>),
795    Properties(Box<Properties>),
796    OptionsProperty(Box<OptionsProperty>),
797    InputOutputFormat(Box<InputOutputFormat>),
798    Reference(Box<Reference>),
799    QueryOption(Box<QueryOption>),
800    WithTableHint(Box<WithTableHint>),
801    IndexTableHint(Box<IndexTableHint>),
802    HistoricalData(Box<HistoricalData>),
803    Get(Box<Get>),
804    SetOperation(Box<SetOperation>),
805    Var(Box<Var>),
806    Variadic(Box<Variadic>),
807    Version(Box<Version>),
808    Schema(Box<Schema>),
809    Lock(Box<Lock>),
810    TableSample(Box<TableSample>),
811    Tag(Box<Tag>),
812    UnpivotColumns(Box<UnpivotColumns>),
813    WindowSpec(Box<WindowSpec>),
814    SessionParameter(Box<SessionParameter>),
815    PseudoType(Box<PseudoType>),
816    ObjectIdentifier(Box<ObjectIdentifier>),
817    Transaction(Box<Transaction>),
818    Commit(Box<Commit>),
819    Rollback(Box<Rollback>),
820    AlterSession(Box<AlterSession>),
821    Analyze(Box<Analyze>),
822    AnalyzeStatistics(Box<AnalyzeStatistics>),
823    AnalyzeHistogram(Box<AnalyzeHistogram>),
824    AnalyzeSample(Box<AnalyzeSample>),
825    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
826    AnalyzeDelete(Box<AnalyzeDelete>),
827    AnalyzeWith(Box<AnalyzeWith>),
828    AnalyzeValidate(Box<AnalyzeValidate>),
829    AddPartition(Box<AddPartition>),
830    AttachOption(Box<AttachOption>),
831    DropPartition(Box<DropPartition>),
832    ReplacePartition(Box<ReplacePartition>),
833    DPipe(Box<DPipe>),
834    Operator(Box<Operator>),
835    PivotAny(Box<PivotAny>),
836    Aliases(Box<Aliases>),
837    AtIndex(Box<AtIndex>),
838    FromTimeZone(Box<FromTimeZone>),
839    FormatPhrase(Box<FormatPhrase>),
840    ForIn(Box<ForIn>),
841    TimeUnit(Box<TimeUnit>),
842    IntervalOp(Box<IntervalOp>),
843    IntervalSpan(Box<IntervalSpan>),
844    HavingMax(Box<HavingMax>),
845    CosineDistance(Box<CosineDistance>),
846    DotProduct(Box<DotProduct>),
847    EuclideanDistance(Box<EuclideanDistance>),
848    ManhattanDistance(Box<ManhattanDistance>),
849    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
850    Booland(Box<Booland>),
851    Boolor(Box<Boolor>),
852    ParameterizedAgg(Box<ParameterizedAgg>),
853    ArgMax(Box<ArgMax>),
854    ArgMin(Box<ArgMin>),
855    ApproxTopK(Box<ApproxTopK>),
856    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
857    ApproxTopKCombine(Box<ApproxTopKCombine>),
858    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
859    ApproxTopSum(Box<ApproxTopSum>),
860    ApproxQuantiles(Box<ApproxQuantiles>),
861    Minhash(Box<Minhash>),
862    FarmFingerprint(Box<FarmFingerprint>),
863    Float64(Box<Float64>),
864    Transform(Box<Transform>),
865    Translate(Box<Translate>),
866    Grouping(Box<Grouping>),
867    GroupingId(Box<GroupingId>),
868    Anonymous(Box<Anonymous>),
869    AnonymousAggFunc(Box<AnonymousAggFunc>),
870    CombinedAggFunc(Box<CombinedAggFunc>),
871    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
872    HashAgg(Box<HashAgg>),
873    Hll(Box<Hll>),
874    Apply(Box<Apply>),
875    ToBoolean(Box<ToBoolean>),
876    List(Box<List>),
877    ToMap(Box<ToMap>),
878    Pad(Box<Pad>),
879    ToChar(Box<ToChar>),
880    ToNumber(Box<ToNumber>),
881    ToDouble(Box<ToDouble>),
882    Int64(Box<UnaryFunc>),
883    StringFunc(Box<StringFunc>),
884    ToDecfloat(Box<ToDecfloat>),
885    TryToDecfloat(Box<TryToDecfloat>),
886    ToFile(Box<ToFile>),
887    Columns(Box<Columns>),
888    ConvertToCharset(Box<ConvertToCharset>),
889    ConvertTimezone(Box<ConvertTimezone>),
890    GenerateSeries(Box<GenerateSeries>),
891    AIAgg(Box<AIAgg>),
892    AIClassify(Box<AIClassify>),
893    ArrayAll(Box<ArrayAll>),
894    ArrayAny(Box<ArrayAny>),
895    ArrayConstructCompact(Box<ArrayConstructCompact>),
896    StPoint(Box<StPoint>),
897    StDistance(Box<StDistance>),
898    StringToArray(Box<StringToArray>),
899    ArraySum(Box<ArraySum>),
900    ObjectAgg(Box<ObjectAgg>),
901    CastToStrType(Box<CastToStrType>),
902    CheckJson(Box<CheckJson>),
903    CheckXml(Box<CheckXml>),
904    TranslateCharacters(Box<TranslateCharacters>),
905    CurrentSchemas(Box<CurrentSchemas>),
906    CurrentDatetime(Box<CurrentDatetime>),
907    Localtime(Box<Localtime>),
908    Localtimestamp(Box<Localtimestamp>),
909    Systimestamp(Box<Systimestamp>),
910    CurrentSchema(Box<CurrentSchema>),
911    CurrentUser(Box<CurrentUser>),
912    UtcTime(Box<UtcTime>),
913    UtcTimestamp(Box<UtcTimestamp>),
914    Timestamp(Box<TimestampFunc>),
915    DateBin(Box<DateBin>),
916    Datetime(Box<Datetime>),
917    DatetimeAdd(Box<DatetimeAdd>),
918    DatetimeSub(Box<DatetimeSub>),
919    DatetimeDiff(Box<DatetimeDiff>),
920    DatetimeTrunc(Box<DatetimeTrunc>),
921    Dayname(Box<Dayname>),
922    MakeInterval(Box<MakeInterval>),
923    PreviousDay(Box<PreviousDay>),
924    Elt(Box<Elt>),
925    TimestampAdd(Box<TimestampAdd>),
926    TimestampSub(Box<TimestampSub>),
927    TimestampDiff(Box<TimestampDiff>),
928    TimeSlice(Box<TimeSlice>),
929    TimeAdd(Box<TimeAdd>),
930    TimeSub(Box<TimeSub>),
931    TimeDiff(Box<TimeDiff>),
932    TimeTrunc(Box<TimeTrunc>),
933    DateFromParts(Box<DateFromParts>),
934    TimeFromParts(Box<TimeFromParts>),
935    DecodeCase(Box<DecodeCase>),
936    Decrypt(Box<Decrypt>),
937    DecryptRaw(Box<DecryptRaw>),
938    Encode(Box<Encode>),
939    Encrypt(Box<Encrypt>),
940    EncryptRaw(Box<EncryptRaw>),
941    EqualNull(Box<EqualNull>),
942    ToBinary(Box<ToBinary>),
943    Base64DecodeBinary(Box<Base64DecodeBinary>),
944    Base64DecodeString(Box<Base64DecodeString>),
945    Base64Encode(Box<Base64Encode>),
946    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
947    TryBase64DecodeString(Box<TryBase64DecodeString>),
948    GapFill(Box<GapFill>),
949    GenerateDateArray(Box<GenerateDateArray>),
950    GenerateTimestampArray(Box<GenerateTimestampArray>),
951    GetExtract(Box<GetExtract>),
952    Getbit(Box<Getbit>),
953    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
954    HexEncode(Box<HexEncode>),
955    Compress(Box<Compress>),
956    DecompressBinary(Box<DecompressBinary>),
957    DecompressString(Box<DecompressString>),
958    Xor(Box<Xor>),
959    Nullif(Box<Nullif>),
960    JSON(Box<JSON>),
961    JSONPath(Box<JSONPath>),
962    JSONPathFilter(Box<JSONPathFilter>),
963    JSONPathKey(Box<JSONPathKey>),
964    JSONPathRecursive(Box<JSONPathRecursive>),
965    JSONPathScript(Box<JSONPathScript>),
966    JSONPathSlice(Box<JSONPathSlice>),
967    JSONPathSelector(Box<JSONPathSelector>),
968    JSONPathSubscript(Box<JSONPathSubscript>),
969    JSONPathUnion(Box<JSONPathUnion>),
970    Format(Box<Format>),
971    JSONKeys(Box<JSONKeys>),
972    JSONKeyValue(Box<JSONKeyValue>),
973    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
974    JSONObject(Box<JSONObject>),
975    JSONObjectAgg(Box<JSONObjectAgg>),
976    JSONBObjectAgg(Box<JSONBObjectAgg>),
977    JSONArray(Box<JSONArray>),
978    JSONArrayAgg(Box<JSONArrayAgg>),
979    JSONExists(Box<JSONExists>),
980    JSONColumnDef(Box<JSONColumnDef>),
981    JSONSchema(Box<JSONSchema>),
982    JSONSet(Box<JSONSet>),
983    JSONStripNulls(Box<JSONStripNulls>),
984    JSONValue(Box<JSONValue>),
985    JSONValueArray(Box<JSONValueArray>),
986    JSONRemove(Box<JSONRemove>),
987    JSONTable(Box<JSONTable>),
988    JSONType(Box<JSONType>),
989    ObjectInsert(Box<ObjectInsert>),
990    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
991    OpenJSON(Box<OpenJSON>),
992    JSONBExists(Box<JSONBExists>),
993    JSONBContains(Box<BinaryFunc>),
994    JSONBExtract(Box<BinaryFunc>),
995    JSONCast(Box<JSONCast>),
996    JSONExtract(Box<JSONExtract>),
997    JSONExtractQuote(Box<JSONExtractQuote>),
998    JSONExtractArray(Box<JSONExtractArray>),
999    JSONExtractScalar(Box<JSONExtractScalar>),
1000    JSONBExtractScalar(Box<JSONBExtractScalar>),
1001    JSONFormat(Box<JSONFormat>),
1002    JSONBool(Box<UnaryFunc>),
1003    JSONPathRoot(JSONPathRoot),
1004    JSONArrayAppend(Box<JSONArrayAppend>),
1005    JSONArrayContains(Box<JSONArrayContains>),
1006    JSONArrayInsert(Box<JSONArrayInsert>),
1007    ParseJSON(Box<ParseJSON>),
1008    ParseUrl(Box<ParseUrl>),
1009    ParseIp(Box<ParseIp>),
1010    ParseTime(Box<ParseTime>),
1011    ParseDatetime(Box<ParseDatetime>),
1012    Map(Box<Map>),
1013    MapCat(Box<MapCat>),
1014    MapDelete(Box<MapDelete>),
1015    MapInsert(Box<MapInsert>),
1016    MapPick(Box<MapPick>),
1017    ScopeResolution(Box<ScopeResolution>),
1018    Slice(Box<Slice>),
1019    VarMap(Box<VarMap>),
1020    MatchAgainst(Box<MatchAgainst>),
1021    MD5Digest(Box<MD5Digest>),
1022    MD5NumberLower64(Box<UnaryFunc>),
1023    MD5NumberUpper64(Box<UnaryFunc>),
1024    Monthname(Box<Monthname>),
1025    Ntile(Box<Ntile>),
1026    Normalize(Box<Normalize>),
1027    Normal(Box<Normal>),
1028    Predict(Box<Predict>),
1029    MLTranslate(Box<MLTranslate>),
1030    FeaturesAtTime(Box<FeaturesAtTime>),
1031    GenerateEmbedding(Box<GenerateEmbedding>),
1032    MLForecast(Box<MLForecast>),
1033    ModelAttribute(Box<ModelAttribute>),
1034    VectorSearch(Box<VectorSearch>),
1035    Quantile(Box<Quantile>),
1036    ApproxQuantile(Box<ApproxQuantile>),
1037    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1038    Randn(Box<Randn>),
1039    Randstr(Box<Randstr>),
1040    RangeN(Box<RangeN>),
1041    RangeBucket(Box<RangeBucket>),
1042    ReadCSV(Box<ReadCSV>),
1043    ReadParquet(Box<ReadParquet>),
1044    Reduce(Box<Reduce>),
1045    RegexpExtractAll(Box<RegexpExtractAll>),
1046    RegexpILike(Box<RegexpILike>),
1047    RegexpFullMatch(Box<RegexpFullMatch>),
1048    RegexpInstr(Box<RegexpInstr>),
1049    RegexpSplit(Box<RegexpSplit>),
1050    RegexpCount(Box<RegexpCount>),
1051    RegrValx(Box<RegrValx>),
1052    RegrValy(Box<RegrValy>),
1053    RegrAvgy(Box<RegrAvgy>),
1054    RegrAvgx(Box<RegrAvgx>),
1055    RegrCount(Box<RegrCount>),
1056    RegrIntercept(Box<RegrIntercept>),
1057    RegrR2(Box<RegrR2>),
1058    RegrSxx(Box<RegrSxx>),
1059    RegrSxy(Box<RegrSxy>),
1060    RegrSyy(Box<RegrSyy>),
1061    RegrSlope(Box<RegrSlope>),
1062    SafeAdd(Box<SafeAdd>),
1063    SafeDivide(Box<SafeDivide>),
1064    SafeMultiply(Box<SafeMultiply>),
1065    SafeSubtract(Box<SafeSubtract>),
1066    SHA2(Box<SHA2>),
1067    SHA2Digest(Box<SHA2Digest>),
1068    SortArray(Box<SortArray>),
1069    SplitPart(Box<SplitPart>),
1070    SubstringIndex(Box<SubstringIndex>),
1071    StandardHash(Box<StandardHash>),
1072    StrPosition(Box<StrPosition>),
1073    Search(Box<Search>),
1074    SearchIp(Box<SearchIp>),
1075    StrToDate(Box<StrToDate>),
1076    DateStrToDate(Box<UnaryFunc>),
1077    DateToDateStr(Box<UnaryFunc>),
1078    StrToTime(Box<StrToTime>),
1079    StrToUnix(Box<StrToUnix>),
1080    StrToMap(Box<StrToMap>),
1081    NumberToStr(Box<NumberToStr>),
1082    FromBase(Box<FromBase>),
1083    Stuff(Box<Stuff>),
1084    TimeToStr(Box<TimeToStr>),
1085    TimeStrToTime(Box<TimeStrToTime>),
1086    TsOrDsAdd(Box<TsOrDsAdd>),
1087    TsOrDsDiff(Box<TsOrDsDiff>),
1088    TsOrDsToDate(Box<TsOrDsToDate>),
1089    TsOrDsToTime(Box<TsOrDsToTime>),
1090    Unhex(Box<Unhex>),
1091    Uniform(Box<Uniform>),
1092    UnixToStr(Box<UnixToStr>),
1093    UnixToTime(Box<UnixToTime>),
1094    Uuid(Box<Uuid>),
1095    TimestampFromParts(Box<TimestampFromParts>),
1096    TimestampTzFromParts(Box<TimestampTzFromParts>),
1097    Corr(Box<Corr>),
1098    WidthBucket(Box<WidthBucket>),
1099    CovarSamp(Box<CovarSamp>),
1100    CovarPop(Box<CovarPop>),
1101    Week(Box<Week>),
1102    XMLElement(Box<XMLElement>),
1103    XMLGet(Box<XMLGet>),
1104    XMLTable(Box<XMLTable>),
1105    XMLKeyValueOption(Box<XMLKeyValueOption>),
1106    Zipf(Box<Zipf>),
1107    Merge(Box<Merge>),
1108    When(Box<When>),
1109    Whens(Box<Whens>),
1110    NextValueFor(Box<NextValueFor>),
1111    /// RETURN statement (DuckDB stored procedures)
1112    ReturnStmt(Box<Expression>),
1113}
1114
1115impl Expression {
1116    /// Create a `Column` variant, boxing the value automatically.
1117    #[inline]
1118    pub fn boxed_column(col: Column) -> Self {
1119        Expression::Column(Box::new(col))
1120    }
1121
1122    /// Create a `Table` variant, boxing the value automatically.
1123    #[inline]
1124    pub fn boxed_table(t: TableRef) -> Self {
1125        Expression::Table(Box::new(t))
1126    }
1127
1128    /// Returns `true` if this expression is a valid top-level SQL statement.
1129    ///
1130    /// Bare expressions like identifiers, literals, and function calls are not
1131    /// valid statements. This is used by `validate()` to reject inputs like
1132    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1133    /// plus the bare identifier `doo`.
1134    pub fn is_statement(&self) -> bool {
1135        match self {
1136            // Queries
1137            Expression::Select(_)
1138            | Expression::Union(_)
1139            | Expression::Intersect(_)
1140            | Expression::Except(_)
1141            | Expression::Subquery(_)
1142            | Expression::Values(_)
1143            | Expression::PipeOperator(_)
1144
1145            // DML
1146            | Expression::Insert(_)
1147            | Expression::Update(_)
1148            | Expression::Delete(_)
1149            | Expression::Copy(_)
1150            | Expression::Put(_)
1151            | Expression::Merge(_)
1152            | Expression::TryCatch(_)
1153
1154            // DDL
1155            | Expression::CreateTable(_)
1156            | Expression::DropTable(_)
1157            | Expression::Undrop(_)
1158            | Expression::AlterTable(_)
1159            | Expression::CreateIndex(_)
1160            | Expression::DropIndex(_)
1161            | Expression::CreateView(_)
1162            | Expression::DropView(_)
1163            | Expression::AlterView(_)
1164            | Expression::AlterIndex(_)
1165            | Expression::Truncate(_)
1166            | Expression::TruncateTable(_)
1167            | Expression::CreateSchema(_)
1168            | Expression::DropSchema(_)
1169            | Expression::DropNamespace(_)
1170            | Expression::CreateDatabase(_)
1171            | Expression::DropDatabase(_)
1172            | Expression::CreateFunction(_)
1173            | Expression::DropFunction(_)
1174            | Expression::CreateProcedure(_)
1175            | Expression::DropProcedure(_)
1176            | Expression::CreateSequence(_)
1177            | Expression::CreateSynonym(_)
1178            | Expression::DropSequence(_)
1179            | Expression::AlterSequence(_)
1180            | Expression::CreateTrigger(_)
1181            | Expression::DropTrigger(_)
1182            | Expression::CreateType(_)
1183            | Expression::DropType(_)
1184            | Expression::Comment(_)
1185
1186            // Session/Transaction/Control
1187            | Expression::Use(_)
1188            | Expression::Set(_)
1189            | Expression::SetStatement(_)
1190            | Expression::Transaction(_)
1191            | Expression::Commit(_)
1192            | Expression::Rollback(_)
1193            | Expression::Grant(_)
1194            | Expression::Revoke(_)
1195            | Expression::Cache(_)
1196            | Expression::Uncache(_)
1197            | Expression::LoadData(_)
1198            | Expression::Pragma(_)
1199            | Expression::Describe(_)
1200            | Expression::Show(_)
1201            | Expression::Kill(_)
1202            | Expression::Prepare(_)
1203            | Expression::Execute(_)
1204            | Expression::Declare(_)
1205            | Expression::Refresh(_)
1206            | Expression::AlterSession(_)
1207            | Expression::LockingStatement(_)
1208
1209            // Analyze
1210            | Expression::Analyze(_)
1211            | Expression::AnalyzeStatistics(_)
1212            | Expression::AnalyzeHistogram(_)
1213            | Expression::AnalyzeSample(_)
1214            | Expression::AnalyzeListChainedRows(_)
1215            | Expression::AnalyzeDelete(_)
1216
1217            // Attach/Detach/Install/Summarize
1218            | Expression::Attach(_)
1219            | Expression::Detach(_)
1220            | Expression::Install(_)
1221            | Expression::Summarize(_)
1222
1223            // Pivot at statement level
1224            | Expression::Pivot(_)
1225            | Expression::Unpivot(_)
1226
1227            // Command (raw/unparsed statements)
1228            | Expression::Command(_)
1229            | Expression::Raw(_)
1230            | Expression::CreateTask(_)
1231
1232            // Return statement
1233            | Expression::ReturnStmt(_) => true,
1234
1235            // Annotated wraps another expression with comments — check inner
1236            Expression::Annotated(a) => a.this.is_statement(),
1237
1238            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1239            Expression::Alias(a) => a.this.is_statement(),
1240
1241            // Everything else (identifiers, literals, operators, functions, etc.)
1242            _ => false,
1243        }
1244    }
1245
1246    /// Create a literal number expression from an integer.
1247    pub fn number(n: i64) -> Self {
1248        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1249    }
1250
1251    /// Create a single-quoted literal string expression.
1252    pub fn string(s: impl Into<String>) -> Self {
1253        Expression::Literal(Box::new(Literal::String(s.into())))
1254    }
1255
1256    /// Create a literal number expression from a float.
1257    pub fn float(f: f64) -> Self {
1258        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1259    }
1260
1261    /// Get the inferred type annotation, if present.
1262    ///
1263    /// For value-producing expressions with an `inferred_type` field, returns
1264    /// the stored type. For literals and boolean constants, computes the type
1265    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1266    pub fn inferred_type(&self) -> Option<&DataType> {
1267        match self {
1268            // Structs with inferred_type field
1269            Expression::And(op)
1270            | Expression::Or(op)
1271            | Expression::Add(op)
1272            | Expression::Sub(op)
1273            | Expression::Mul(op)
1274            | Expression::Div(op)
1275            | Expression::Mod(op)
1276            | Expression::Eq(op)
1277            | Expression::Neq(op)
1278            | Expression::Lt(op)
1279            | Expression::Lte(op)
1280            | Expression::Gt(op)
1281            | Expression::Gte(op)
1282            | Expression::Concat(op)
1283            | Expression::BitwiseAnd(op)
1284            | Expression::BitwiseOr(op)
1285            | Expression::BitwiseXor(op)
1286            | Expression::Adjacent(op)
1287            | Expression::TsMatch(op)
1288            | Expression::PropertyEQ(op)
1289            | Expression::ArrayContainsAll(op)
1290            | Expression::ArrayContainedBy(op)
1291            | Expression::ArrayOverlaps(op)
1292            | Expression::JSONBContainsAllTopKeys(op)
1293            | Expression::JSONBContainsAnyTopKeys(op)
1294            | Expression::JSONBDeleteAtPath(op)
1295            | Expression::ExtendsLeft(op)
1296            | Expression::ExtendsRight(op)
1297            | Expression::Is(op)
1298            | Expression::MemberOf(op)
1299            | Expression::Match(op)
1300            | Expression::NullSafeEq(op)
1301            | Expression::NullSafeNeq(op)
1302            | Expression::Glob(op)
1303            | Expression::BitwiseLeftShift(op)
1304            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1305
1306            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1307                op.inferred_type.as_ref()
1308            }
1309
1310            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1311
1312            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1313                c.inferred_type.as_ref()
1314            }
1315
1316            Expression::Column(c) => c.inferred_type.as_ref(),
1317            Expression::Function(f) => f.inferred_type.as_ref(),
1318            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1319            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1320            Expression::Case(c) => c.inferred_type.as_ref(),
1321            Expression::Subquery(s) => s.inferred_type.as_ref(),
1322            Expression::Alias(a) => a.inferred_type.as_ref(),
1323            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1324            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1325            Expression::Count(f) => f.inferred_type.as_ref(),
1326            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1327            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1328            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1329            Expression::SumIf(f) => f.inferred_type.as_ref(),
1330
1331            // UnaryFunc variants
1332            Expression::Upper(f)
1333            | Expression::Lower(f)
1334            | Expression::Length(f)
1335            | Expression::LTrim(f)
1336            | Expression::RTrim(f)
1337            | Expression::Reverse(f)
1338            | Expression::Abs(f)
1339            | Expression::Sqrt(f)
1340            | Expression::Cbrt(f)
1341            | Expression::Ln(f)
1342            | Expression::Exp(f)
1343            | Expression::Sign(f)
1344            | Expression::Date(f)
1345            | Expression::Time(f)
1346            | Expression::Initcap(f)
1347            | Expression::Ascii(f)
1348            | Expression::Chr(f)
1349            | Expression::Soundex(f)
1350            | Expression::ByteLength(f)
1351            | Expression::Hex(f)
1352            | Expression::LowerHex(f)
1353            | Expression::Unicode(f)
1354            | Expression::Typeof(f)
1355            | Expression::Explode(f)
1356            | Expression::ExplodeOuter(f)
1357            | Expression::MapFromEntries(f)
1358            | Expression::MapKeys(f)
1359            | Expression::MapValues(f)
1360            | Expression::ArrayLength(f)
1361            | Expression::ArraySize(f)
1362            | Expression::Cardinality(f)
1363            | Expression::ArrayReverse(f)
1364            | Expression::ArrayDistinct(f)
1365            | Expression::ArrayFlatten(f)
1366            | Expression::ArrayCompact(f)
1367            | Expression::ToArray(f)
1368            | Expression::JsonArrayLength(f)
1369            | Expression::JsonKeys(f)
1370            | Expression::JsonType(f)
1371            | Expression::ParseJson(f)
1372            | Expression::ToJson(f)
1373            | Expression::Radians(f)
1374            | Expression::Degrees(f)
1375            | Expression::Sin(f)
1376            | Expression::Cos(f)
1377            | Expression::Tan(f)
1378            | Expression::Asin(f)
1379            | Expression::Acos(f)
1380            | Expression::Atan(f)
1381            | Expression::IsNan(f)
1382            | Expression::IsInf(f)
1383            | Expression::Year(f)
1384            | Expression::Month(f)
1385            | Expression::Day(f)
1386            | Expression::Hour(f)
1387            | Expression::Minute(f)
1388            | Expression::Second(f)
1389            | Expression::DayOfWeek(f)
1390            | Expression::DayOfWeekIso(f)
1391            | Expression::DayOfMonth(f)
1392            | Expression::DayOfYear(f)
1393            | Expression::WeekOfYear(f)
1394            | Expression::Quarter(f)
1395            | Expression::Epoch(f)
1396            | Expression::EpochMs(f)
1397            | Expression::BitwiseCount(f)
1398            | Expression::DateFromUnixDate(f)
1399            | Expression::UnixDate(f)
1400            | Expression::UnixSeconds(f)
1401            | Expression::UnixMillis(f)
1402            | Expression::UnixMicros(f)
1403            | Expression::TimeStrToDate(f)
1404            | Expression::DateToDi(f)
1405            | Expression::DiToDate(f)
1406            | Expression::TsOrDiToDi(f)
1407            | Expression::TsOrDsToDatetime(f)
1408            | Expression::TsOrDsToTimestamp(f)
1409            | Expression::YearOfWeek(f)
1410            | Expression::YearOfWeekIso(f)
1411            | Expression::SHA(f)
1412            | Expression::SHA1Digest(f)
1413            | Expression::TimeToUnix(f)
1414            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1415
1416            // BinaryFunc variants
1417            Expression::Power(f)
1418            | Expression::NullIf(f)
1419            | Expression::IfNull(f)
1420            | Expression::Nvl(f)
1421            | Expression::Contains(f)
1422            | Expression::StartsWith(f)
1423            | Expression::EndsWith(f)
1424            | Expression::Levenshtein(f)
1425            | Expression::ModFunc(f)
1426            | Expression::IntDiv(f)
1427            | Expression::Atan2(f)
1428            | Expression::AddMonths(f)
1429            | Expression::MonthsBetween(f)
1430            | Expression::NextDay(f)
1431            | Expression::UnixToTimeStr(f)
1432            | Expression::ArrayContains(f)
1433            | Expression::ArrayPosition(f)
1434            | Expression::ArrayAppend(f)
1435            | Expression::ArrayPrepend(f)
1436            | Expression::ArrayUnion(f)
1437            | Expression::ArrayExcept(f)
1438            | Expression::ArrayRemove(f)
1439            | Expression::StarMap(f)
1440            | Expression::MapFromArrays(f)
1441            | Expression::MapContainsKey(f)
1442            | Expression::ElementAt(f)
1443            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1444
1445            // VarArgFunc variants
1446            Expression::Coalesce(f)
1447            | Expression::Greatest(f)
1448            | Expression::Least(f)
1449            | Expression::ArrayConcat(f)
1450            | Expression::ArrayIntersect(f)
1451            | Expression::ArrayZip(f)
1452            | Expression::MapConcat(f)
1453            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1454
1455            // AggFunc variants
1456            Expression::Sum(f)
1457            | Expression::Avg(f)
1458            | Expression::Min(f)
1459            | Expression::Max(f)
1460            | Expression::ArrayAgg(f)
1461            | Expression::CountIf(f)
1462            | Expression::Stddev(f)
1463            | Expression::StddevPop(f)
1464            | Expression::StddevSamp(f)
1465            | Expression::Variance(f)
1466            | Expression::VarPop(f)
1467            | Expression::VarSamp(f)
1468            | Expression::Median(f)
1469            | Expression::Mode(f)
1470            | Expression::First(f)
1471            | Expression::Last(f)
1472            | Expression::AnyValue(f)
1473            | Expression::ApproxDistinct(f)
1474            | Expression::ApproxCountDistinct(f)
1475            | Expression::LogicalAnd(f)
1476            | Expression::LogicalOr(f)
1477            | Expression::Skewness(f)
1478            | Expression::ArrayConcatAgg(f)
1479            | Expression::ArrayUniqueAgg(f)
1480            | Expression::BoolXorAgg(f)
1481            | Expression::BitwiseAndAgg(f)
1482            | Expression::BitwiseOrAgg(f)
1483            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1484
1485            // Everything else: no inferred_type field
1486            _ => None,
1487        }
1488    }
1489
1490    /// Set the inferred type annotation on this expression.
1491    ///
1492    /// Only has an effect on value-producing expressions with an `inferred_type`
1493    /// field. For other expression types, this is a no-op.
1494    pub fn set_inferred_type(&mut self, dt: DataType) {
1495        match self {
1496            Expression::And(op)
1497            | Expression::Or(op)
1498            | Expression::Add(op)
1499            | Expression::Sub(op)
1500            | Expression::Mul(op)
1501            | Expression::Div(op)
1502            | Expression::Mod(op)
1503            | Expression::Eq(op)
1504            | Expression::Neq(op)
1505            | Expression::Lt(op)
1506            | Expression::Lte(op)
1507            | Expression::Gt(op)
1508            | Expression::Gte(op)
1509            | Expression::Concat(op)
1510            | Expression::BitwiseAnd(op)
1511            | Expression::BitwiseOr(op)
1512            | Expression::BitwiseXor(op)
1513            | Expression::Adjacent(op)
1514            | Expression::TsMatch(op)
1515            | Expression::PropertyEQ(op)
1516            | Expression::ArrayContainsAll(op)
1517            | Expression::ArrayContainedBy(op)
1518            | Expression::ArrayOverlaps(op)
1519            | Expression::JSONBContainsAllTopKeys(op)
1520            | Expression::JSONBContainsAnyTopKeys(op)
1521            | Expression::JSONBDeleteAtPath(op)
1522            | Expression::ExtendsLeft(op)
1523            | Expression::ExtendsRight(op)
1524            | Expression::Is(op)
1525            | Expression::MemberOf(op)
1526            | Expression::Match(op)
1527            | Expression::NullSafeEq(op)
1528            | Expression::NullSafeNeq(op)
1529            | Expression::Glob(op)
1530            | Expression::BitwiseLeftShift(op)
1531            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1532
1533            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1534                op.inferred_type = Some(dt)
1535            }
1536
1537            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1538
1539            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1540                c.inferred_type = Some(dt)
1541            }
1542
1543            Expression::Column(c) => c.inferred_type = Some(dt),
1544            Expression::Function(f) => f.inferred_type = Some(dt),
1545            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1546            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1547            Expression::Case(c) => c.inferred_type = Some(dt),
1548            Expression::Subquery(s) => s.inferred_type = Some(dt),
1549            Expression::Alias(a) => a.inferred_type = Some(dt),
1550            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1551            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1552            Expression::Count(f) => f.inferred_type = Some(dt),
1553            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1554            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1555            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1556            Expression::SumIf(f) => f.inferred_type = Some(dt),
1557
1558            // UnaryFunc variants
1559            Expression::Upper(f)
1560            | Expression::Lower(f)
1561            | Expression::Length(f)
1562            | Expression::LTrim(f)
1563            | Expression::RTrim(f)
1564            | Expression::Reverse(f)
1565            | Expression::Abs(f)
1566            | Expression::Sqrt(f)
1567            | Expression::Cbrt(f)
1568            | Expression::Ln(f)
1569            | Expression::Exp(f)
1570            | Expression::Sign(f)
1571            | Expression::Date(f)
1572            | Expression::Time(f)
1573            | Expression::Initcap(f)
1574            | Expression::Ascii(f)
1575            | Expression::Chr(f)
1576            | Expression::Soundex(f)
1577            | Expression::ByteLength(f)
1578            | Expression::Hex(f)
1579            | Expression::LowerHex(f)
1580            | Expression::Unicode(f)
1581            | Expression::Typeof(f)
1582            | Expression::Explode(f)
1583            | Expression::ExplodeOuter(f)
1584            | Expression::MapFromEntries(f)
1585            | Expression::MapKeys(f)
1586            | Expression::MapValues(f)
1587            | Expression::ArrayLength(f)
1588            | Expression::ArraySize(f)
1589            | Expression::Cardinality(f)
1590            | Expression::ArrayReverse(f)
1591            | Expression::ArrayDistinct(f)
1592            | Expression::ArrayFlatten(f)
1593            | Expression::ArrayCompact(f)
1594            | Expression::ToArray(f)
1595            | Expression::JsonArrayLength(f)
1596            | Expression::JsonKeys(f)
1597            | Expression::JsonType(f)
1598            | Expression::ParseJson(f)
1599            | Expression::ToJson(f)
1600            | Expression::Radians(f)
1601            | Expression::Degrees(f)
1602            | Expression::Sin(f)
1603            | Expression::Cos(f)
1604            | Expression::Tan(f)
1605            | Expression::Asin(f)
1606            | Expression::Acos(f)
1607            | Expression::Atan(f)
1608            | Expression::IsNan(f)
1609            | Expression::IsInf(f)
1610            | Expression::Year(f)
1611            | Expression::Month(f)
1612            | Expression::Day(f)
1613            | Expression::Hour(f)
1614            | Expression::Minute(f)
1615            | Expression::Second(f)
1616            | Expression::DayOfWeek(f)
1617            | Expression::DayOfWeekIso(f)
1618            | Expression::DayOfMonth(f)
1619            | Expression::DayOfYear(f)
1620            | Expression::WeekOfYear(f)
1621            | Expression::Quarter(f)
1622            | Expression::Epoch(f)
1623            | Expression::EpochMs(f)
1624            | Expression::BitwiseCount(f)
1625            | Expression::DateFromUnixDate(f)
1626            | Expression::UnixDate(f)
1627            | Expression::UnixSeconds(f)
1628            | Expression::UnixMillis(f)
1629            | Expression::UnixMicros(f)
1630            | Expression::TimeStrToDate(f)
1631            | Expression::DateToDi(f)
1632            | Expression::DiToDate(f)
1633            | Expression::TsOrDiToDi(f)
1634            | Expression::TsOrDsToDatetime(f)
1635            | Expression::TsOrDsToTimestamp(f)
1636            | Expression::YearOfWeek(f)
1637            | Expression::YearOfWeekIso(f)
1638            | Expression::SHA(f)
1639            | Expression::SHA1Digest(f)
1640            | Expression::TimeToUnix(f)
1641            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1642
1643            // BinaryFunc variants
1644            Expression::Power(f)
1645            | Expression::NullIf(f)
1646            | Expression::IfNull(f)
1647            | Expression::Nvl(f)
1648            | Expression::Contains(f)
1649            | Expression::StartsWith(f)
1650            | Expression::EndsWith(f)
1651            | Expression::Levenshtein(f)
1652            | Expression::ModFunc(f)
1653            | Expression::IntDiv(f)
1654            | Expression::Atan2(f)
1655            | Expression::AddMonths(f)
1656            | Expression::MonthsBetween(f)
1657            | Expression::NextDay(f)
1658            | Expression::UnixToTimeStr(f)
1659            | Expression::ArrayContains(f)
1660            | Expression::ArrayPosition(f)
1661            | Expression::ArrayAppend(f)
1662            | Expression::ArrayPrepend(f)
1663            | Expression::ArrayUnion(f)
1664            | Expression::ArrayExcept(f)
1665            | Expression::ArrayRemove(f)
1666            | Expression::StarMap(f)
1667            | Expression::MapFromArrays(f)
1668            | Expression::MapContainsKey(f)
1669            | Expression::ElementAt(f)
1670            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1671
1672            // VarArgFunc variants
1673            Expression::Coalesce(f)
1674            | Expression::Greatest(f)
1675            | Expression::Least(f)
1676            | Expression::ArrayConcat(f)
1677            | Expression::ArrayIntersect(f)
1678            | Expression::ArrayZip(f)
1679            | Expression::MapConcat(f)
1680            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1681
1682            // AggFunc variants
1683            Expression::Sum(f)
1684            | Expression::Avg(f)
1685            | Expression::Min(f)
1686            | Expression::Max(f)
1687            | Expression::ArrayAgg(f)
1688            | Expression::CountIf(f)
1689            | Expression::Stddev(f)
1690            | Expression::StddevPop(f)
1691            | Expression::StddevSamp(f)
1692            | Expression::Variance(f)
1693            | Expression::VarPop(f)
1694            | Expression::VarSamp(f)
1695            | Expression::Median(f)
1696            | Expression::Mode(f)
1697            | Expression::First(f)
1698            | Expression::Last(f)
1699            | Expression::AnyValue(f)
1700            | Expression::ApproxDistinct(f)
1701            | Expression::ApproxCountDistinct(f)
1702            | Expression::LogicalAnd(f)
1703            | Expression::LogicalOr(f)
1704            | Expression::Skewness(f)
1705            | Expression::ArrayConcatAgg(f)
1706            | Expression::ArrayUniqueAgg(f)
1707            | Expression::BoolXorAgg(f)
1708            | Expression::BitwiseAndAgg(f)
1709            | Expression::BitwiseOrAgg(f)
1710            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1711
1712            // Expressions without inferred_type field - no-op
1713            _ => {}
1714        }
1715    }
1716
1717    /// Create an unqualified column reference (e.g. `name`).
1718    pub fn column(name: impl Into<String>) -> Self {
1719        Expression::Column(Box::new(Column {
1720            name: Identifier::new(name),
1721            table: None,
1722            join_mark: false,
1723            trailing_comments: Vec::new(),
1724            span: None,
1725            inferred_type: None,
1726        }))
1727    }
1728
1729    /// Create a qualified column reference (`table.column`).
1730    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1731        Expression::Column(Box::new(Column {
1732            name: Identifier::new(column),
1733            table: Some(Identifier::new(table)),
1734            join_mark: false,
1735            trailing_comments: Vec::new(),
1736            span: None,
1737            inferred_type: None,
1738        }))
1739    }
1740
1741    /// Create a bare identifier expression (not a column reference).
1742    pub fn identifier(name: impl Into<String>) -> Self {
1743        Expression::Identifier(Identifier::new(name))
1744    }
1745
1746    /// Create a NULL expression
1747    pub fn null() -> Self {
1748        Expression::Null(Null)
1749    }
1750
1751    /// Create a TRUE expression
1752    pub fn true_() -> Self {
1753        Expression::Boolean(BooleanLiteral { value: true })
1754    }
1755
1756    /// Create a FALSE expression
1757    pub fn false_() -> Self {
1758        Expression::Boolean(BooleanLiteral { value: false })
1759    }
1760
1761    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1762    pub fn star() -> Self {
1763        Expression::Star(Star {
1764            table: None,
1765            except: None,
1766            replace: None,
1767            rename: None,
1768            trailing_comments: Vec::new(),
1769            span: None,
1770        })
1771    }
1772
1773    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1774    pub fn alias(self, name: impl Into<String>) -> Self {
1775        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1776    }
1777
1778    /// Check if this is a SELECT expression
1779    pub fn is_select(&self) -> bool {
1780        matches!(self, Expression::Select(_))
1781    }
1782
1783    /// Try to get as a Select
1784    pub fn as_select(&self) -> Option<&Select> {
1785        match self {
1786            Expression::Select(s) => Some(s),
1787            _ => None,
1788        }
1789    }
1790
1791    /// Try to get as a mutable Select
1792    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1793        match self {
1794            Expression::Select(s) => Some(s),
1795            _ => None,
1796        }
1797    }
1798
1799    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1800    ///
1801    /// Returns an empty string if generation fails. For dialect-specific output,
1802    /// use [`sql_for()`](Self::sql_for) instead.
1803    #[cfg(feature = "generate")]
1804    pub fn sql(&self) -> String {
1805        crate::generator::Generator::sql(self).unwrap_or_default()
1806    }
1807
1808    /// Generate a SQL string for this expression targeting a specific dialect.
1809    ///
1810    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1811    /// syntax variations) are applied automatically.  Returns an empty string if
1812    /// generation fails.
1813    #[cfg(feature = "generate")]
1814    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1815        crate::generate(self, dialect).unwrap_or_default()
1816    }
1817}
1818
1819// === Python API accessor methods ===
1820
1821impl Expression {
1822    /// Returns the serde-compatible snake_case variant name without serialization.
1823    /// This is much faster than serializing to JSON and extracting the key.
1824    pub fn variant_name(&self) -> &'static str {
1825        match self {
1826            Expression::Literal(_) => "literal",
1827            Expression::Boolean(_) => "boolean",
1828            Expression::Null(_) => "null",
1829            Expression::Identifier(_) => "identifier",
1830            Expression::Column(_) => "column",
1831            Expression::Table(_) => "table",
1832            Expression::Star(_) => "star",
1833            Expression::BracedWildcard(_) => "braced_wildcard",
1834            Expression::Select(_) => "select",
1835            Expression::Union(_) => "union",
1836            Expression::Intersect(_) => "intersect",
1837            Expression::Except(_) => "except",
1838            Expression::Subquery(_) => "subquery",
1839            Expression::PipeOperator(_) => "pipe_operator",
1840            Expression::Pivot(_) => "pivot",
1841            Expression::PivotAlias(_) => "pivot_alias",
1842            Expression::Unpivot(_) => "unpivot",
1843            Expression::Values(_) => "values",
1844            Expression::PreWhere(_) => "pre_where",
1845            Expression::Stream(_) => "stream",
1846            Expression::UsingData(_) => "using_data",
1847            Expression::XmlNamespace(_) => "xml_namespace",
1848            Expression::Insert(_) => "insert",
1849            Expression::Update(_) => "update",
1850            Expression::Delete(_) => "delete",
1851            Expression::Copy(_) => "copy",
1852            Expression::Put(_) => "put",
1853            Expression::StageReference(_) => "stage_reference",
1854            Expression::Alias(_) => "alias",
1855            Expression::Cast(_) => "cast",
1856            Expression::Collation(_) => "collation",
1857            Expression::Case(_) => "case",
1858            Expression::And(_) => "and",
1859            Expression::Or(_) => "or",
1860            Expression::Add(_) => "add",
1861            Expression::Sub(_) => "sub",
1862            Expression::Mul(_) => "mul",
1863            Expression::Div(_) => "div",
1864            Expression::Mod(_) => "mod",
1865            Expression::Eq(_) => "eq",
1866            Expression::Neq(_) => "neq",
1867            Expression::Lt(_) => "lt",
1868            Expression::Lte(_) => "lte",
1869            Expression::Gt(_) => "gt",
1870            Expression::Gte(_) => "gte",
1871            Expression::Like(_) => "like",
1872            Expression::ILike(_) => "i_like",
1873            Expression::Match(_) => "match",
1874            Expression::BitwiseAnd(_) => "bitwise_and",
1875            Expression::BitwiseOr(_) => "bitwise_or",
1876            Expression::BitwiseXor(_) => "bitwise_xor",
1877            Expression::Concat(_) => "concat",
1878            Expression::Adjacent(_) => "adjacent",
1879            Expression::TsMatch(_) => "ts_match",
1880            Expression::PropertyEQ(_) => "property_e_q",
1881            Expression::ArrayContainsAll(_) => "array_contains_all",
1882            Expression::ArrayContainedBy(_) => "array_contained_by",
1883            Expression::ArrayOverlaps(_) => "array_overlaps",
1884            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1885            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1886            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1887            Expression::ExtendsLeft(_) => "extends_left",
1888            Expression::ExtendsRight(_) => "extends_right",
1889            Expression::Not(_) => "not",
1890            Expression::Neg(_) => "neg",
1891            Expression::BitwiseNot(_) => "bitwise_not",
1892            Expression::In(_) => "in",
1893            Expression::Between(_) => "between",
1894            Expression::IsNull(_) => "is_null",
1895            Expression::IsTrue(_) => "is_true",
1896            Expression::IsFalse(_) => "is_false",
1897            Expression::IsJson(_) => "is_json",
1898            Expression::Is(_) => "is",
1899            Expression::Exists(_) => "exists",
1900            Expression::MemberOf(_) => "member_of",
1901            Expression::Function(_) => "function",
1902            Expression::AggregateFunction(_) => "aggregate_function",
1903            Expression::WindowFunction(_) => "window_function",
1904            Expression::From(_) => "from",
1905            Expression::Join(_) => "join",
1906            Expression::JoinedTable(_) => "joined_table",
1907            Expression::Where(_) => "where",
1908            Expression::GroupBy(_) => "group_by",
1909            Expression::Having(_) => "having",
1910            Expression::OrderBy(_) => "order_by",
1911            Expression::Limit(_) => "limit",
1912            Expression::Offset(_) => "offset",
1913            Expression::Qualify(_) => "qualify",
1914            Expression::With(_) => "with",
1915            Expression::Cte(_) => "cte",
1916            Expression::DistributeBy(_) => "distribute_by",
1917            Expression::ClusterBy(_) => "cluster_by",
1918            Expression::SortBy(_) => "sort_by",
1919            Expression::LateralView(_) => "lateral_view",
1920            Expression::Hint(_) => "hint",
1921            Expression::Pseudocolumn(_) => "pseudocolumn",
1922            Expression::Connect(_) => "connect",
1923            Expression::Prior(_) => "prior",
1924            Expression::ConnectByRoot(_) => "connect_by_root",
1925            Expression::MatchRecognize(_) => "match_recognize",
1926            Expression::Ordered(_) => "ordered",
1927            Expression::Window(_) => "window",
1928            Expression::Over(_) => "over",
1929            Expression::WithinGroup(_) => "within_group",
1930            Expression::DataType(_) => "data_type",
1931            Expression::Array(_) => "array",
1932            Expression::Struct(_) => "struct",
1933            Expression::Tuple(_) => "tuple",
1934            Expression::Interval(_) => "interval",
1935            Expression::ConcatWs(_) => "concat_ws",
1936            Expression::Substring(_) => "substring",
1937            Expression::Upper(_) => "upper",
1938            Expression::Lower(_) => "lower",
1939            Expression::Length(_) => "length",
1940            Expression::Trim(_) => "trim",
1941            Expression::LTrim(_) => "l_trim",
1942            Expression::RTrim(_) => "r_trim",
1943            Expression::Replace(_) => "replace",
1944            Expression::Reverse(_) => "reverse",
1945            Expression::Left(_) => "left",
1946            Expression::Right(_) => "right",
1947            Expression::Repeat(_) => "repeat",
1948            Expression::Lpad(_) => "lpad",
1949            Expression::Rpad(_) => "rpad",
1950            Expression::Split(_) => "split",
1951            Expression::RegexpLike(_) => "regexp_like",
1952            Expression::RegexpReplace(_) => "regexp_replace",
1953            Expression::RegexpExtract(_) => "regexp_extract",
1954            Expression::Overlay(_) => "overlay",
1955            Expression::Abs(_) => "abs",
1956            Expression::Round(_) => "round",
1957            Expression::Floor(_) => "floor",
1958            Expression::Ceil(_) => "ceil",
1959            Expression::Power(_) => "power",
1960            Expression::Sqrt(_) => "sqrt",
1961            Expression::Cbrt(_) => "cbrt",
1962            Expression::Ln(_) => "ln",
1963            Expression::Log(_) => "log",
1964            Expression::Exp(_) => "exp",
1965            Expression::Sign(_) => "sign",
1966            Expression::Greatest(_) => "greatest",
1967            Expression::Least(_) => "least",
1968            Expression::CurrentDate(_) => "current_date",
1969            Expression::CurrentTime(_) => "current_time",
1970            Expression::CurrentTimestamp(_) => "current_timestamp",
1971            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1972            Expression::AtTimeZone(_) => "at_time_zone",
1973            Expression::DateAdd(_) => "date_add",
1974            Expression::DateSub(_) => "date_sub",
1975            Expression::DateDiff(_) => "date_diff",
1976            Expression::DateTrunc(_) => "date_trunc",
1977            Expression::Extract(_) => "extract",
1978            Expression::ToDate(_) => "to_date",
1979            Expression::ToTimestamp(_) => "to_timestamp",
1980            Expression::Date(_) => "date",
1981            Expression::Time(_) => "time",
1982            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1983            Expression::UnixDate(_) => "unix_date",
1984            Expression::UnixSeconds(_) => "unix_seconds",
1985            Expression::UnixMillis(_) => "unix_millis",
1986            Expression::UnixMicros(_) => "unix_micros",
1987            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1988            Expression::TimeStrToDate(_) => "time_str_to_date",
1989            Expression::DateToDi(_) => "date_to_di",
1990            Expression::DiToDate(_) => "di_to_date",
1991            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1992            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1993            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1994            Expression::YearOfWeek(_) => "year_of_week",
1995            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1996            Expression::Coalesce(_) => "coalesce",
1997            Expression::NullIf(_) => "null_if",
1998            Expression::IfFunc(_) => "if_func",
1999            Expression::IfNull(_) => "if_null",
2000            Expression::Nvl(_) => "nvl",
2001            Expression::Nvl2(_) => "nvl2",
2002            Expression::TryCast(_) => "try_cast",
2003            Expression::SafeCast(_) => "safe_cast",
2004            Expression::Count(_) => "count",
2005            Expression::Sum(_) => "sum",
2006            Expression::Avg(_) => "avg",
2007            Expression::Min(_) => "min",
2008            Expression::Max(_) => "max",
2009            Expression::GroupConcat(_) => "group_concat",
2010            Expression::StringAgg(_) => "string_agg",
2011            Expression::ListAgg(_) => "list_agg",
2012            Expression::ArrayAgg(_) => "array_agg",
2013            Expression::CountIf(_) => "count_if",
2014            Expression::SumIf(_) => "sum_if",
2015            Expression::Stddev(_) => "stddev",
2016            Expression::StddevPop(_) => "stddev_pop",
2017            Expression::StddevSamp(_) => "stddev_samp",
2018            Expression::Variance(_) => "variance",
2019            Expression::VarPop(_) => "var_pop",
2020            Expression::VarSamp(_) => "var_samp",
2021            Expression::Median(_) => "median",
2022            Expression::Mode(_) => "mode",
2023            Expression::First(_) => "first",
2024            Expression::Last(_) => "last",
2025            Expression::AnyValue(_) => "any_value",
2026            Expression::ApproxDistinct(_) => "approx_distinct",
2027            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2028            Expression::ApproxPercentile(_) => "approx_percentile",
2029            Expression::Percentile(_) => "percentile",
2030            Expression::LogicalAnd(_) => "logical_and",
2031            Expression::LogicalOr(_) => "logical_or",
2032            Expression::Skewness(_) => "skewness",
2033            Expression::BitwiseCount(_) => "bitwise_count",
2034            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2035            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2036            Expression::BoolXorAgg(_) => "bool_xor_agg",
2037            Expression::RowNumber(_) => "row_number",
2038            Expression::Rank(_) => "rank",
2039            Expression::DenseRank(_) => "dense_rank",
2040            Expression::NTile(_) => "n_tile",
2041            Expression::Lead(_) => "lead",
2042            Expression::Lag(_) => "lag",
2043            Expression::FirstValue(_) => "first_value",
2044            Expression::LastValue(_) => "last_value",
2045            Expression::NthValue(_) => "nth_value",
2046            Expression::PercentRank(_) => "percent_rank",
2047            Expression::CumeDist(_) => "cume_dist",
2048            Expression::PercentileCont(_) => "percentile_cont",
2049            Expression::PercentileDisc(_) => "percentile_disc",
2050            Expression::Contains(_) => "contains",
2051            Expression::StartsWith(_) => "starts_with",
2052            Expression::EndsWith(_) => "ends_with",
2053            Expression::Position(_) => "position",
2054            Expression::Initcap(_) => "initcap",
2055            Expression::Ascii(_) => "ascii",
2056            Expression::Chr(_) => "chr",
2057            Expression::CharFunc(_) => "char_func",
2058            Expression::Soundex(_) => "soundex",
2059            Expression::Levenshtein(_) => "levenshtein",
2060            Expression::ByteLength(_) => "byte_length",
2061            Expression::Hex(_) => "hex",
2062            Expression::LowerHex(_) => "lower_hex",
2063            Expression::Unicode(_) => "unicode",
2064            Expression::ModFunc(_) => "mod_func",
2065            Expression::Random(_) => "random",
2066            Expression::Rand(_) => "rand",
2067            Expression::TruncFunc(_) => "trunc_func",
2068            Expression::Pi(_) => "pi",
2069            Expression::Radians(_) => "radians",
2070            Expression::Degrees(_) => "degrees",
2071            Expression::Sin(_) => "sin",
2072            Expression::Cos(_) => "cos",
2073            Expression::Tan(_) => "tan",
2074            Expression::Asin(_) => "asin",
2075            Expression::Acos(_) => "acos",
2076            Expression::Atan(_) => "atan",
2077            Expression::Atan2(_) => "atan2",
2078            Expression::IsNan(_) => "is_nan",
2079            Expression::IsInf(_) => "is_inf",
2080            Expression::IntDiv(_) => "int_div",
2081            Expression::Decode(_) => "decode",
2082            Expression::DateFormat(_) => "date_format",
2083            Expression::FormatDate(_) => "format_date",
2084            Expression::Year(_) => "year",
2085            Expression::Month(_) => "month",
2086            Expression::Day(_) => "day",
2087            Expression::Hour(_) => "hour",
2088            Expression::Minute(_) => "minute",
2089            Expression::Second(_) => "second",
2090            Expression::DayOfWeek(_) => "day_of_week",
2091            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2092            Expression::DayOfMonth(_) => "day_of_month",
2093            Expression::DayOfYear(_) => "day_of_year",
2094            Expression::WeekOfYear(_) => "week_of_year",
2095            Expression::Quarter(_) => "quarter",
2096            Expression::AddMonths(_) => "add_months",
2097            Expression::MonthsBetween(_) => "months_between",
2098            Expression::LastDay(_) => "last_day",
2099            Expression::NextDay(_) => "next_day",
2100            Expression::Epoch(_) => "epoch",
2101            Expression::EpochMs(_) => "epoch_ms",
2102            Expression::FromUnixtime(_) => "from_unixtime",
2103            Expression::UnixTimestamp(_) => "unix_timestamp",
2104            Expression::MakeDate(_) => "make_date",
2105            Expression::MakeTimestamp(_) => "make_timestamp",
2106            Expression::TimestampTrunc(_) => "timestamp_trunc",
2107            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2108            Expression::SessionUser(_) => "session_user",
2109            Expression::SHA(_) => "s_h_a",
2110            Expression::SHA1Digest(_) => "s_h_a1_digest",
2111            Expression::TimeToUnix(_) => "time_to_unix",
2112            Expression::ArrayFunc(_) => "array_func",
2113            Expression::ArrayLength(_) => "array_length",
2114            Expression::ArraySize(_) => "array_size",
2115            Expression::Cardinality(_) => "cardinality",
2116            Expression::ArrayContains(_) => "array_contains",
2117            Expression::ArrayPosition(_) => "array_position",
2118            Expression::ArrayAppend(_) => "array_append",
2119            Expression::ArrayPrepend(_) => "array_prepend",
2120            Expression::ArrayConcat(_) => "array_concat",
2121            Expression::ArraySort(_) => "array_sort",
2122            Expression::ArrayReverse(_) => "array_reverse",
2123            Expression::ArrayDistinct(_) => "array_distinct",
2124            Expression::ArrayJoin(_) => "array_join",
2125            Expression::ArrayToString(_) => "array_to_string",
2126            Expression::Unnest(_) => "unnest",
2127            Expression::Explode(_) => "explode",
2128            Expression::ExplodeOuter(_) => "explode_outer",
2129            Expression::ArrayFilter(_) => "array_filter",
2130            Expression::ArrayTransform(_) => "array_transform",
2131            Expression::ArrayFlatten(_) => "array_flatten",
2132            Expression::ArrayCompact(_) => "array_compact",
2133            Expression::ArrayIntersect(_) => "array_intersect",
2134            Expression::ArrayUnion(_) => "array_union",
2135            Expression::ArrayExcept(_) => "array_except",
2136            Expression::ArrayRemove(_) => "array_remove",
2137            Expression::ArrayZip(_) => "array_zip",
2138            Expression::Sequence(_) => "sequence",
2139            Expression::Generate(_) => "generate",
2140            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2141            Expression::ToArray(_) => "to_array",
2142            Expression::StarMap(_) => "star_map",
2143            Expression::StructFunc(_) => "struct_func",
2144            Expression::StructExtract(_) => "struct_extract",
2145            Expression::NamedStruct(_) => "named_struct",
2146            Expression::MapFunc(_) => "map_func",
2147            Expression::MapFromEntries(_) => "map_from_entries",
2148            Expression::MapFromArrays(_) => "map_from_arrays",
2149            Expression::MapKeys(_) => "map_keys",
2150            Expression::MapValues(_) => "map_values",
2151            Expression::MapContainsKey(_) => "map_contains_key",
2152            Expression::MapConcat(_) => "map_concat",
2153            Expression::ElementAt(_) => "element_at",
2154            Expression::TransformKeys(_) => "transform_keys",
2155            Expression::TransformValues(_) => "transform_values",
2156            Expression::FunctionEmits(_) => "function_emits",
2157            Expression::JsonExtract(_) => "json_extract",
2158            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2159            Expression::JsonExtractPath(_) => "json_extract_path",
2160            Expression::JsonArray(_) => "json_array",
2161            Expression::JsonObject(_) => "json_object",
2162            Expression::JsonQuery(_) => "json_query",
2163            Expression::JsonValue(_) => "json_value",
2164            Expression::JsonArrayLength(_) => "json_array_length",
2165            Expression::JsonKeys(_) => "json_keys",
2166            Expression::JsonType(_) => "json_type",
2167            Expression::ParseJson(_) => "parse_json",
2168            Expression::ToJson(_) => "to_json",
2169            Expression::JsonSet(_) => "json_set",
2170            Expression::JsonInsert(_) => "json_insert",
2171            Expression::JsonRemove(_) => "json_remove",
2172            Expression::JsonMergePatch(_) => "json_merge_patch",
2173            Expression::JsonArrayAgg(_) => "json_array_agg",
2174            Expression::JsonObjectAgg(_) => "json_object_agg",
2175            Expression::Convert(_) => "convert",
2176            Expression::Typeof(_) => "typeof",
2177            Expression::Lambda(_) => "lambda",
2178            Expression::Parameter(_) => "parameter",
2179            Expression::Placeholder(_) => "placeholder",
2180            Expression::NamedArgument(_) => "named_argument",
2181            Expression::TableArgument(_) => "table_argument",
2182            Expression::SqlComment(_) => "sql_comment",
2183            Expression::NullSafeEq(_) => "null_safe_eq",
2184            Expression::NullSafeNeq(_) => "null_safe_neq",
2185            Expression::Glob(_) => "glob",
2186            Expression::SimilarTo(_) => "similar_to",
2187            Expression::Any(_) => "any",
2188            Expression::All(_) => "all",
2189            Expression::Overlaps(_) => "overlaps",
2190            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2191            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2192            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2193            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2194            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2195            Expression::Subscript(_) => "subscript",
2196            Expression::Dot(_) => "dot",
2197            Expression::MethodCall(_) => "method_call",
2198            Expression::ArraySlice(_) => "array_slice",
2199            Expression::CreateTable(_) => "create_table",
2200            Expression::DropTable(_) => "drop_table",
2201            Expression::Undrop(_) => "undrop",
2202            Expression::AlterTable(_) => "alter_table",
2203            Expression::CreateIndex(_) => "create_index",
2204            Expression::DropIndex(_) => "drop_index",
2205            Expression::CreateView(_) => "create_view",
2206            Expression::DropView(_) => "drop_view",
2207            Expression::AlterView(_) => "alter_view",
2208            Expression::AlterIndex(_) => "alter_index",
2209            Expression::Truncate(_) => "truncate",
2210            Expression::Use(_) => "use",
2211            Expression::Cache(_) => "cache",
2212            Expression::Uncache(_) => "uncache",
2213            Expression::LoadData(_) => "load_data",
2214            Expression::Pragma(_) => "pragma",
2215            Expression::Grant(_) => "grant",
2216            Expression::Revoke(_) => "revoke",
2217            Expression::Comment(_) => "comment",
2218            Expression::SetStatement(_) => "set_statement",
2219            Expression::CreateSchema(_) => "create_schema",
2220            Expression::DropSchema(_) => "drop_schema",
2221            Expression::DropNamespace(_) => "drop_namespace",
2222            Expression::CreateDatabase(_) => "create_database",
2223            Expression::DropDatabase(_) => "drop_database",
2224            Expression::CreateFunction(_) => "create_function",
2225            Expression::DropFunction(_) => "drop_function",
2226            Expression::CreateProcedure(_) => "create_procedure",
2227            Expression::DropProcedure(_) => "drop_procedure",
2228            Expression::CreateSequence(_) => "create_sequence",
2229            Expression::CreateSynonym(_) => "create_synonym",
2230            Expression::DropSequence(_) => "drop_sequence",
2231            Expression::AlterSequence(_) => "alter_sequence",
2232            Expression::CreateTrigger(_) => "create_trigger",
2233            Expression::DropTrigger(_) => "drop_trigger",
2234            Expression::CreateType(_) => "create_type",
2235            Expression::DropType(_) => "drop_type",
2236            Expression::Describe(_) => "describe",
2237            Expression::Show(_) => "show",
2238            Expression::Command(_) => "command",
2239            Expression::TryCatch(_) => "try_catch",
2240            Expression::Kill(_) => "kill",
2241            Expression::Prepare(_) => "prepare",
2242            Expression::Execute(_) => "execute",
2243            Expression::Raw(_) => "raw",
2244            Expression::CreateTask(_) => "create_task",
2245            Expression::Paren(_) => "paren",
2246            Expression::Annotated(_) => "annotated",
2247            Expression::Refresh(_) => "refresh",
2248            Expression::LockingStatement(_) => "locking_statement",
2249            Expression::SequenceProperties(_) => "sequence_properties",
2250            Expression::TruncateTable(_) => "truncate_table",
2251            Expression::Clone(_) => "clone",
2252            Expression::Attach(_) => "attach",
2253            Expression::Detach(_) => "detach",
2254            Expression::Install(_) => "install",
2255            Expression::Summarize(_) => "summarize",
2256            Expression::Declare(_) => "declare",
2257            Expression::DeclareItem(_) => "declare_item",
2258            Expression::Set(_) => "set",
2259            Expression::Heredoc(_) => "heredoc",
2260            Expression::SetItem(_) => "set_item",
2261            Expression::QueryBand(_) => "query_band",
2262            Expression::UserDefinedFunction(_) => "user_defined_function",
2263            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2264            Expression::ProjectionDef(_) => "projection_def",
2265            Expression::TableAlias(_) => "table_alias",
2266            Expression::ByteString(_) => "byte_string",
2267            Expression::HexStringExpr(_) => "hex_string_expr",
2268            Expression::UnicodeString(_) => "unicode_string",
2269            Expression::ColumnPosition(_) => "column_position",
2270            Expression::ColumnDef(_) => "column_def",
2271            Expression::AlterColumn(_) => "alter_column",
2272            Expression::AlterSortKey(_) => "alter_sort_key",
2273            Expression::AlterSet(_) => "alter_set",
2274            Expression::RenameColumn(_) => "rename_column",
2275            Expression::Comprehension(_) => "comprehension",
2276            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2277            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2278            Expression::IndexConstraintOption(_) => "index_constraint_option",
2279            Expression::ColumnConstraint(_) => "column_constraint",
2280            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2281            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2282            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2283            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2284            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2285            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2286            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2287            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2288            Expression::WithOperator(_) => "with_operator",
2289            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2290                "generated_as_identity_column_constraint"
2291            }
2292            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2293            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2294            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2295            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2296            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2297            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2298            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2299            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2300            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2301            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2302            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2303            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2304            Expression::PathColumnConstraint(_) => "path_column_constraint",
2305            Expression::Constraint(_) => "constraint",
2306            Expression::Export(_) => "export",
2307            Expression::Filter(_) => "filter",
2308            Expression::Changes(_) => "changes",
2309            Expression::CopyParameter(_) => "copy_parameter",
2310            Expression::Credentials(_) => "credentials",
2311            Expression::Directory(_) => "directory",
2312            Expression::ForeignKey(_) => "foreign_key",
2313            Expression::ColumnPrefix(_) => "column_prefix",
2314            Expression::PrimaryKey(_) => "primary_key",
2315            Expression::IntoClause(_) => "into_clause",
2316            Expression::JoinHint(_) => "join_hint",
2317            Expression::Opclass(_) => "opclass",
2318            Expression::Index(_) => "index",
2319            Expression::IndexParameters(_) => "index_parameters",
2320            Expression::ConditionalInsert(_) => "conditional_insert",
2321            Expression::MultitableInserts(_) => "multitable_inserts",
2322            Expression::OnConflict(_) => "on_conflict",
2323            Expression::OnCondition(_) => "on_condition",
2324            Expression::Returning(_) => "returning",
2325            Expression::Introducer(_) => "introducer",
2326            Expression::PartitionRange(_) => "partition_range",
2327            Expression::Fetch(_) => "fetch",
2328            Expression::Group(_) => "group",
2329            Expression::Cube(_) => "cube",
2330            Expression::Rollup(_) => "rollup",
2331            Expression::GroupingSets(_) => "grouping_sets",
2332            Expression::LimitOptions(_) => "limit_options",
2333            Expression::Lateral(_) => "lateral",
2334            Expression::TableFromRows(_) => "table_from_rows",
2335            Expression::RowsFrom(_) => "rows_from",
2336            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2337            Expression::WithFill(_) => "with_fill",
2338            Expression::Property(_) => "property",
2339            Expression::GrantPrivilege(_) => "grant_privilege",
2340            Expression::GrantPrincipal(_) => "grant_principal",
2341            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2342            Expression::AlgorithmProperty(_) => "algorithm_property",
2343            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2344            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2345            Expression::BackupProperty(_) => "backup_property",
2346            Expression::BuildProperty(_) => "build_property",
2347            Expression::BlockCompressionProperty(_) => "block_compression_property",
2348            Expression::CharacterSetProperty(_) => "character_set_property",
2349            Expression::ChecksumProperty(_) => "checksum_property",
2350            Expression::CollateProperty(_) => "collate_property",
2351            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2352            Expression::DataDeletionProperty(_) => "data_deletion_property",
2353            Expression::DefinerProperty(_) => "definer_property",
2354            Expression::DistKeyProperty(_) => "dist_key_property",
2355            Expression::DistributedByProperty(_) => "distributed_by_property",
2356            Expression::DistStyleProperty(_) => "dist_style_property",
2357            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2358            Expression::EngineProperty(_) => "engine_property",
2359            Expression::ToTableProperty(_) => "to_table_property",
2360            Expression::ExecuteAsProperty(_) => "execute_as_property",
2361            Expression::ExternalProperty(_) => "external_property",
2362            Expression::FallbackProperty(_) => "fallback_property",
2363            Expression::FileFormatProperty(_) => "file_format_property",
2364            Expression::CredentialsProperty(_) => "credentials_property",
2365            Expression::FreespaceProperty(_) => "freespace_property",
2366            Expression::InheritsProperty(_) => "inherits_property",
2367            Expression::InputModelProperty(_) => "input_model_property",
2368            Expression::OutputModelProperty(_) => "output_model_property",
2369            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2370            Expression::JournalProperty(_) => "journal_property",
2371            Expression::LanguageProperty(_) => "language_property",
2372            Expression::EnviromentProperty(_) => "enviroment_property",
2373            Expression::ClusteredByProperty(_) => "clustered_by_property",
2374            Expression::DictProperty(_) => "dict_property",
2375            Expression::DictRange(_) => "dict_range",
2376            Expression::OnCluster(_) => "on_cluster",
2377            Expression::LikeProperty(_) => "like_property",
2378            Expression::LocationProperty(_) => "location_property",
2379            Expression::LockProperty(_) => "lock_property",
2380            Expression::LockingProperty(_) => "locking_property",
2381            Expression::LogProperty(_) => "log_property",
2382            Expression::MaterializedProperty(_) => "materialized_property",
2383            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2384            Expression::OnProperty(_) => "on_property",
2385            Expression::OnCommitProperty(_) => "on_commit_property",
2386            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2387            Expression::PartitionByProperty(_) => "partition_by_property",
2388            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2389            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2390            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2391            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2392            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2393            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2394            Expression::PartitionList(_) => "partition_list",
2395            Expression::Partition(_) => "partition",
2396            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2397            Expression::UniqueKeyProperty(_) => "unique_key_property",
2398            Expression::RollupProperty(_) => "rollup_property",
2399            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2400            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2401            Expression::RemoteWithConnectionModelProperty(_) => {
2402                "remote_with_connection_model_property"
2403            }
2404            Expression::ReturnsProperty(_) => "returns_property",
2405            Expression::RowFormatProperty(_) => "row_format_property",
2406            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2407            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2408            Expression::QueryTransform(_) => "query_transform",
2409            Expression::SampleProperty(_) => "sample_property",
2410            Expression::SecurityProperty(_) => "security_property",
2411            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2412            Expression::SemanticView(_) => "semantic_view",
2413            Expression::SerdeProperties(_) => "serde_properties",
2414            Expression::SetProperty(_) => "set_property",
2415            Expression::SharingProperty(_) => "sharing_property",
2416            Expression::SetConfigProperty(_) => "set_config_property",
2417            Expression::SettingsProperty(_) => "settings_property",
2418            Expression::SortKeyProperty(_) => "sort_key_property",
2419            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2420            Expression::SqlSecurityProperty(_) => "sql_security_property",
2421            Expression::StabilityProperty(_) => "stability_property",
2422            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2423            Expression::TemporaryProperty(_) => "temporary_property",
2424            Expression::Tags(_) => "tags",
2425            Expression::TransformModelProperty(_) => "transform_model_property",
2426            Expression::TransientProperty(_) => "transient_property",
2427            Expression::UsingTemplateProperty(_) => "using_template_property",
2428            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2429            Expression::VolatileProperty(_) => "volatile_property",
2430            Expression::WithDataProperty(_) => "with_data_property",
2431            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2432            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2433            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2434            Expression::WithProcedureOptions(_) => "with_procedure_options",
2435            Expression::EncodeProperty(_) => "encode_property",
2436            Expression::IncludeProperty(_) => "include_property",
2437            Expression::Properties(_) => "properties",
2438            Expression::OptionsProperty(_) => "options_property",
2439            Expression::InputOutputFormat(_) => "input_output_format",
2440            Expression::Reference(_) => "reference",
2441            Expression::QueryOption(_) => "query_option",
2442            Expression::WithTableHint(_) => "with_table_hint",
2443            Expression::IndexTableHint(_) => "index_table_hint",
2444            Expression::HistoricalData(_) => "historical_data",
2445            Expression::Get(_) => "get",
2446            Expression::SetOperation(_) => "set_operation",
2447            Expression::Var(_) => "var",
2448            Expression::Variadic(_) => "variadic",
2449            Expression::Version(_) => "version",
2450            Expression::Schema(_) => "schema",
2451            Expression::Lock(_) => "lock",
2452            Expression::TableSample(_) => "table_sample",
2453            Expression::Tag(_) => "tag",
2454            Expression::UnpivotColumns(_) => "unpivot_columns",
2455            Expression::WindowSpec(_) => "window_spec",
2456            Expression::SessionParameter(_) => "session_parameter",
2457            Expression::PseudoType(_) => "pseudo_type",
2458            Expression::ObjectIdentifier(_) => "object_identifier",
2459            Expression::Transaction(_) => "transaction",
2460            Expression::Commit(_) => "commit",
2461            Expression::Rollback(_) => "rollback",
2462            Expression::AlterSession(_) => "alter_session",
2463            Expression::Analyze(_) => "analyze",
2464            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2465            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2466            Expression::AnalyzeSample(_) => "analyze_sample",
2467            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2468            Expression::AnalyzeDelete(_) => "analyze_delete",
2469            Expression::AnalyzeWith(_) => "analyze_with",
2470            Expression::AnalyzeValidate(_) => "analyze_validate",
2471            Expression::AddPartition(_) => "add_partition",
2472            Expression::AttachOption(_) => "attach_option",
2473            Expression::DropPartition(_) => "drop_partition",
2474            Expression::ReplacePartition(_) => "replace_partition",
2475            Expression::DPipe(_) => "d_pipe",
2476            Expression::Operator(_) => "operator",
2477            Expression::PivotAny(_) => "pivot_any",
2478            Expression::Aliases(_) => "aliases",
2479            Expression::AtIndex(_) => "at_index",
2480            Expression::FromTimeZone(_) => "from_time_zone",
2481            Expression::FormatPhrase(_) => "format_phrase",
2482            Expression::ForIn(_) => "for_in",
2483            Expression::TimeUnit(_) => "time_unit",
2484            Expression::IntervalOp(_) => "interval_op",
2485            Expression::IntervalSpan(_) => "interval_span",
2486            Expression::HavingMax(_) => "having_max",
2487            Expression::CosineDistance(_) => "cosine_distance",
2488            Expression::DotProduct(_) => "dot_product",
2489            Expression::EuclideanDistance(_) => "euclidean_distance",
2490            Expression::ManhattanDistance(_) => "manhattan_distance",
2491            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2492            Expression::Booland(_) => "booland",
2493            Expression::Boolor(_) => "boolor",
2494            Expression::ParameterizedAgg(_) => "parameterized_agg",
2495            Expression::ArgMax(_) => "arg_max",
2496            Expression::ArgMin(_) => "arg_min",
2497            Expression::ApproxTopK(_) => "approx_top_k",
2498            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2499            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2500            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2501            Expression::ApproxTopSum(_) => "approx_top_sum",
2502            Expression::ApproxQuantiles(_) => "approx_quantiles",
2503            Expression::Minhash(_) => "minhash",
2504            Expression::FarmFingerprint(_) => "farm_fingerprint",
2505            Expression::Float64(_) => "float64",
2506            Expression::Transform(_) => "transform",
2507            Expression::Translate(_) => "translate",
2508            Expression::Grouping(_) => "grouping",
2509            Expression::GroupingId(_) => "grouping_id",
2510            Expression::Anonymous(_) => "anonymous",
2511            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2512            Expression::CombinedAggFunc(_) => "combined_agg_func",
2513            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2514            Expression::HashAgg(_) => "hash_agg",
2515            Expression::Hll(_) => "hll",
2516            Expression::Apply(_) => "apply",
2517            Expression::ToBoolean(_) => "to_boolean",
2518            Expression::List(_) => "list",
2519            Expression::ToMap(_) => "to_map",
2520            Expression::Pad(_) => "pad",
2521            Expression::ToChar(_) => "to_char",
2522            Expression::ToNumber(_) => "to_number",
2523            Expression::ToDouble(_) => "to_double",
2524            Expression::Int64(_) => "int64",
2525            Expression::StringFunc(_) => "string_func",
2526            Expression::ToDecfloat(_) => "to_decfloat",
2527            Expression::TryToDecfloat(_) => "try_to_decfloat",
2528            Expression::ToFile(_) => "to_file",
2529            Expression::Columns(_) => "columns",
2530            Expression::ConvertToCharset(_) => "convert_to_charset",
2531            Expression::ConvertTimezone(_) => "convert_timezone",
2532            Expression::GenerateSeries(_) => "generate_series",
2533            Expression::AIAgg(_) => "a_i_agg",
2534            Expression::AIClassify(_) => "a_i_classify",
2535            Expression::ArrayAll(_) => "array_all",
2536            Expression::ArrayAny(_) => "array_any",
2537            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2538            Expression::StPoint(_) => "st_point",
2539            Expression::StDistance(_) => "st_distance",
2540            Expression::StringToArray(_) => "string_to_array",
2541            Expression::ArraySum(_) => "array_sum",
2542            Expression::ObjectAgg(_) => "object_agg",
2543            Expression::CastToStrType(_) => "cast_to_str_type",
2544            Expression::CheckJson(_) => "check_json",
2545            Expression::CheckXml(_) => "check_xml",
2546            Expression::TranslateCharacters(_) => "translate_characters",
2547            Expression::CurrentSchemas(_) => "current_schemas",
2548            Expression::CurrentDatetime(_) => "current_datetime",
2549            Expression::Localtime(_) => "localtime",
2550            Expression::Localtimestamp(_) => "localtimestamp",
2551            Expression::Systimestamp(_) => "systimestamp",
2552            Expression::CurrentSchema(_) => "current_schema",
2553            Expression::CurrentUser(_) => "current_user",
2554            Expression::UtcTime(_) => "utc_time",
2555            Expression::UtcTimestamp(_) => "utc_timestamp",
2556            Expression::Timestamp(_) => "timestamp",
2557            Expression::DateBin(_) => "date_bin",
2558            Expression::Datetime(_) => "datetime",
2559            Expression::DatetimeAdd(_) => "datetime_add",
2560            Expression::DatetimeSub(_) => "datetime_sub",
2561            Expression::DatetimeDiff(_) => "datetime_diff",
2562            Expression::DatetimeTrunc(_) => "datetime_trunc",
2563            Expression::Dayname(_) => "dayname",
2564            Expression::MakeInterval(_) => "make_interval",
2565            Expression::PreviousDay(_) => "previous_day",
2566            Expression::Elt(_) => "elt",
2567            Expression::TimestampAdd(_) => "timestamp_add",
2568            Expression::TimestampSub(_) => "timestamp_sub",
2569            Expression::TimestampDiff(_) => "timestamp_diff",
2570            Expression::TimeSlice(_) => "time_slice",
2571            Expression::TimeAdd(_) => "time_add",
2572            Expression::TimeSub(_) => "time_sub",
2573            Expression::TimeDiff(_) => "time_diff",
2574            Expression::TimeTrunc(_) => "time_trunc",
2575            Expression::DateFromParts(_) => "date_from_parts",
2576            Expression::TimeFromParts(_) => "time_from_parts",
2577            Expression::DecodeCase(_) => "decode_case",
2578            Expression::Decrypt(_) => "decrypt",
2579            Expression::DecryptRaw(_) => "decrypt_raw",
2580            Expression::Encode(_) => "encode",
2581            Expression::Encrypt(_) => "encrypt",
2582            Expression::EncryptRaw(_) => "encrypt_raw",
2583            Expression::EqualNull(_) => "equal_null",
2584            Expression::ToBinary(_) => "to_binary",
2585            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2586            Expression::Base64DecodeString(_) => "base64_decode_string",
2587            Expression::Base64Encode(_) => "base64_encode",
2588            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2589            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2590            Expression::GapFill(_) => "gap_fill",
2591            Expression::GenerateDateArray(_) => "generate_date_array",
2592            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2593            Expression::GetExtract(_) => "get_extract",
2594            Expression::Getbit(_) => "getbit",
2595            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2596            Expression::HexEncode(_) => "hex_encode",
2597            Expression::Compress(_) => "compress",
2598            Expression::DecompressBinary(_) => "decompress_binary",
2599            Expression::DecompressString(_) => "decompress_string",
2600            Expression::Xor(_) => "xor",
2601            Expression::Nullif(_) => "nullif",
2602            Expression::JSON(_) => "j_s_o_n",
2603            Expression::JSONPath(_) => "j_s_o_n_path",
2604            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2605            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2606            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2607            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2608            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2609            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2610            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2611            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2612            Expression::Format(_) => "format",
2613            Expression::JSONKeys(_) => "j_s_o_n_keys",
2614            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2615            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2616            Expression::JSONObject(_) => "j_s_o_n_object",
2617            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2618            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2619            Expression::JSONArray(_) => "j_s_o_n_array",
2620            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2621            Expression::JSONExists(_) => "j_s_o_n_exists",
2622            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2623            Expression::JSONSchema(_) => "j_s_o_n_schema",
2624            Expression::JSONSet(_) => "j_s_o_n_set",
2625            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2626            Expression::JSONValue(_) => "j_s_o_n_value",
2627            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2628            Expression::JSONRemove(_) => "j_s_o_n_remove",
2629            Expression::JSONTable(_) => "j_s_o_n_table",
2630            Expression::JSONType(_) => "j_s_o_n_type",
2631            Expression::ObjectInsert(_) => "object_insert",
2632            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2633            Expression::OpenJSON(_) => "open_j_s_o_n",
2634            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2635            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2636            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2637            Expression::JSONCast(_) => "j_s_o_n_cast",
2638            Expression::JSONExtract(_) => "j_s_o_n_extract",
2639            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2640            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2641            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2642            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2643            Expression::JSONFormat(_) => "j_s_o_n_format",
2644            Expression::JSONBool(_) => "j_s_o_n_bool",
2645            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2646            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2647            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2648            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2649            Expression::ParseJSON(_) => "parse_j_s_o_n",
2650            Expression::ParseUrl(_) => "parse_url",
2651            Expression::ParseIp(_) => "parse_ip",
2652            Expression::ParseTime(_) => "parse_time",
2653            Expression::ParseDatetime(_) => "parse_datetime",
2654            Expression::Map(_) => "map",
2655            Expression::MapCat(_) => "map_cat",
2656            Expression::MapDelete(_) => "map_delete",
2657            Expression::MapInsert(_) => "map_insert",
2658            Expression::MapPick(_) => "map_pick",
2659            Expression::ScopeResolution(_) => "scope_resolution",
2660            Expression::Slice(_) => "slice",
2661            Expression::VarMap(_) => "var_map",
2662            Expression::MatchAgainst(_) => "match_against",
2663            Expression::MD5Digest(_) => "m_d5_digest",
2664            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2665            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2666            Expression::Monthname(_) => "monthname",
2667            Expression::Ntile(_) => "ntile",
2668            Expression::Normalize(_) => "normalize",
2669            Expression::Normal(_) => "normal",
2670            Expression::Predict(_) => "predict",
2671            Expression::MLTranslate(_) => "m_l_translate",
2672            Expression::FeaturesAtTime(_) => "features_at_time",
2673            Expression::GenerateEmbedding(_) => "generate_embedding",
2674            Expression::MLForecast(_) => "m_l_forecast",
2675            Expression::ModelAttribute(_) => "model_attribute",
2676            Expression::VectorSearch(_) => "vector_search",
2677            Expression::Quantile(_) => "quantile",
2678            Expression::ApproxQuantile(_) => "approx_quantile",
2679            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2680            Expression::Randn(_) => "randn",
2681            Expression::Randstr(_) => "randstr",
2682            Expression::RangeN(_) => "range_n",
2683            Expression::RangeBucket(_) => "range_bucket",
2684            Expression::ReadCSV(_) => "read_c_s_v",
2685            Expression::ReadParquet(_) => "read_parquet",
2686            Expression::Reduce(_) => "reduce",
2687            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2688            Expression::RegexpILike(_) => "regexp_i_like",
2689            Expression::RegexpFullMatch(_) => "regexp_full_match",
2690            Expression::RegexpInstr(_) => "regexp_instr",
2691            Expression::RegexpSplit(_) => "regexp_split",
2692            Expression::RegexpCount(_) => "regexp_count",
2693            Expression::RegrValx(_) => "regr_valx",
2694            Expression::RegrValy(_) => "regr_valy",
2695            Expression::RegrAvgy(_) => "regr_avgy",
2696            Expression::RegrAvgx(_) => "regr_avgx",
2697            Expression::RegrCount(_) => "regr_count",
2698            Expression::RegrIntercept(_) => "regr_intercept",
2699            Expression::RegrR2(_) => "regr_r2",
2700            Expression::RegrSxx(_) => "regr_sxx",
2701            Expression::RegrSxy(_) => "regr_sxy",
2702            Expression::RegrSyy(_) => "regr_syy",
2703            Expression::RegrSlope(_) => "regr_slope",
2704            Expression::SafeAdd(_) => "safe_add",
2705            Expression::SafeDivide(_) => "safe_divide",
2706            Expression::SafeMultiply(_) => "safe_multiply",
2707            Expression::SafeSubtract(_) => "safe_subtract",
2708            Expression::SHA2(_) => "s_h_a2",
2709            Expression::SHA2Digest(_) => "s_h_a2_digest",
2710            Expression::SortArray(_) => "sort_array",
2711            Expression::SplitPart(_) => "split_part",
2712            Expression::SubstringIndex(_) => "substring_index",
2713            Expression::StandardHash(_) => "standard_hash",
2714            Expression::StrPosition(_) => "str_position",
2715            Expression::Search(_) => "search",
2716            Expression::SearchIp(_) => "search_ip",
2717            Expression::StrToDate(_) => "str_to_date",
2718            Expression::DateStrToDate(_) => "date_str_to_date",
2719            Expression::DateToDateStr(_) => "date_to_date_str",
2720            Expression::StrToTime(_) => "str_to_time",
2721            Expression::StrToUnix(_) => "str_to_unix",
2722            Expression::StrToMap(_) => "str_to_map",
2723            Expression::NumberToStr(_) => "number_to_str",
2724            Expression::FromBase(_) => "from_base",
2725            Expression::Stuff(_) => "stuff",
2726            Expression::TimeToStr(_) => "time_to_str",
2727            Expression::TimeStrToTime(_) => "time_str_to_time",
2728            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2729            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2730            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2731            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2732            Expression::Unhex(_) => "unhex",
2733            Expression::Uniform(_) => "uniform",
2734            Expression::UnixToStr(_) => "unix_to_str",
2735            Expression::UnixToTime(_) => "unix_to_time",
2736            Expression::Uuid(_) => "uuid",
2737            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2738            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2739            Expression::Corr(_) => "corr",
2740            Expression::WidthBucket(_) => "width_bucket",
2741            Expression::CovarSamp(_) => "covar_samp",
2742            Expression::CovarPop(_) => "covar_pop",
2743            Expression::Week(_) => "week",
2744            Expression::XMLElement(_) => "x_m_l_element",
2745            Expression::XMLGet(_) => "x_m_l_get",
2746            Expression::XMLTable(_) => "x_m_l_table",
2747            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2748            Expression::Zipf(_) => "zipf",
2749            Expression::Merge(_) => "merge",
2750            Expression::When(_) => "when",
2751            Expression::Whens(_) => "whens",
2752            Expression::NextValueFor(_) => "next_value_for",
2753            Expression::ReturnStmt(_) => "return_stmt",
2754        }
2755    }
2756
2757    /// Returns the primary child expression (".this" in sqlglot).
2758    pub fn get_this(&self) -> Option<&Expression> {
2759        match self {
2760            // Unary ops
2761            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2762            // UnaryFunc variants
2763            Expression::Upper(f)
2764            | Expression::Lower(f)
2765            | Expression::Length(f)
2766            | Expression::LTrim(f)
2767            | Expression::RTrim(f)
2768            | Expression::Reverse(f)
2769            | Expression::Abs(f)
2770            | Expression::Sqrt(f)
2771            | Expression::Cbrt(f)
2772            | Expression::Ln(f)
2773            | Expression::Exp(f)
2774            | Expression::Sign(f)
2775            | Expression::Date(f)
2776            | Expression::Time(f)
2777            | Expression::Initcap(f)
2778            | Expression::Ascii(f)
2779            | Expression::Chr(f)
2780            | Expression::Soundex(f)
2781            | Expression::ByteLength(f)
2782            | Expression::Hex(f)
2783            | Expression::LowerHex(f)
2784            | Expression::Unicode(f)
2785            | Expression::Typeof(f)
2786            | Expression::Explode(f)
2787            | Expression::ExplodeOuter(f)
2788            | Expression::MapFromEntries(f)
2789            | Expression::MapKeys(f)
2790            | Expression::MapValues(f)
2791            | Expression::ArrayLength(f)
2792            | Expression::ArraySize(f)
2793            | Expression::Cardinality(f)
2794            | Expression::ArrayReverse(f)
2795            | Expression::ArrayDistinct(f)
2796            | Expression::ArrayFlatten(f)
2797            | Expression::ArrayCompact(f)
2798            | Expression::ToArray(f)
2799            | Expression::JsonArrayLength(f)
2800            | Expression::JsonKeys(f)
2801            | Expression::JsonType(f)
2802            | Expression::ParseJson(f)
2803            | Expression::ToJson(f)
2804            | Expression::Radians(f)
2805            | Expression::Degrees(f)
2806            | Expression::Sin(f)
2807            | Expression::Cos(f)
2808            | Expression::Tan(f)
2809            | Expression::Asin(f)
2810            | Expression::Acos(f)
2811            | Expression::Atan(f)
2812            | Expression::IsNan(f)
2813            | Expression::IsInf(f)
2814            | Expression::Year(f)
2815            | Expression::Month(f)
2816            | Expression::Day(f)
2817            | Expression::Hour(f)
2818            | Expression::Minute(f)
2819            | Expression::Second(f)
2820            | Expression::DayOfWeek(f)
2821            | Expression::DayOfWeekIso(f)
2822            | Expression::DayOfMonth(f)
2823            | Expression::DayOfYear(f)
2824            | Expression::WeekOfYear(f)
2825            | Expression::Quarter(f)
2826            | Expression::Epoch(f)
2827            | Expression::EpochMs(f)
2828            | Expression::BitwiseCount(f)
2829            | Expression::DateFromUnixDate(f)
2830            | Expression::UnixDate(f)
2831            | Expression::UnixSeconds(f)
2832            | Expression::UnixMillis(f)
2833            | Expression::UnixMicros(f)
2834            | Expression::TimeStrToDate(f)
2835            | Expression::DateToDi(f)
2836            | Expression::DiToDate(f)
2837            | Expression::TsOrDiToDi(f)
2838            | Expression::TsOrDsToDatetime(f)
2839            | Expression::TsOrDsToTimestamp(f)
2840            | Expression::YearOfWeek(f)
2841            | Expression::YearOfWeekIso(f)
2842            | Expression::SHA(f)
2843            | Expression::SHA1Digest(f)
2844            | Expression::TimeToUnix(f)
2845            | Expression::TimeStrToUnix(f)
2846            | Expression::Int64(f)
2847            | Expression::JSONBool(f)
2848            | Expression::MD5NumberLower64(f)
2849            | Expression::MD5NumberUpper64(f)
2850            | Expression::DateStrToDate(f)
2851            | Expression::DateToDateStr(f) => Some(&f.this),
2852            // BinaryFunc - this is the primary child
2853            Expression::Power(f)
2854            | Expression::NullIf(f)
2855            | Expression::IfNull(f)
2856            | Expression::Nvl(f)
2857            | Expression::Contains(f)
2858            | Expression::StartsWith(f)
2859            | Expression::EndsWith(f)
2860            | Expression::Levenshtein(f)
2861            | Expression::ModFunc(f)
2862            | Expression::IntDiv(f)
2863            | Expression::Atan2(f)
2864            | Expression::AddMonths(f)
2865            | Expression::MonthsBetween(f)
2866            | Expression::NextDay(f)
2867            | Expression::UnixToTimeStr(f)
2868            | Expression::ArrayContains(f)
2869            | Expression::ArrayPosition(f)
2870            | Expression::ArrayAppend(f)
2871            | Expression::ArrayPrepend(f)
2872            | Expression::ArrayUnion(f)
2873            | Expression::ArrayExcept(f)
2874            | Expression::ArrayRemove(f)
2875            | Expression::StarMap(f)
2876            | Expression::MapFromArrays(f)
2877            | Expression::MapContainsKey(f)
2878            | Expression::ElementAt(f)
2879            | Expression::JsonMergePatch(f)
2880            | Expression::JSONBContains(f)
2881            | Expression::JSONBExtract(f) => Some(&f.this),
2882            // AggFunc - this is the primary child
2883            Expression::Sum(af)
2884            | Expression::Avg(af)
2885            | Expression::Min(af)
2886            | Expression::Max(af)
2887            | Expression::ArrayAgg(af)
2888            | Expression::CountIf(af)
2889            | Expression::Stddev(af)
2890            | Expression::StddevPop(af)
2891            | Expression::StddevSamp(af)
2892            | Expression::Variance(af)
2893            | Expression::VarPop(af)
2894            | Expression::VarSamp(af)
2895            | Expression::Median(af)
2896            | Expression::Mode(af)
2897            | Expression::First(af)
2898            | Expression::Last(af)
2899            | Expression::AnyValue(af)
2900            | Expression::ApproxDistinct(af)
2901            | Expression::ApproxCountDistinct(af)
2902            | Expression::LogicalAnd(af)
2903            | Expression::LogicalOr(af)
2904            | Expression::Skewness(af)
2905            | Expression::ArrayConcatAgg(af)
2906            | Expression::ArrayUniqueAgg(af)
2907            | Expression::BoolXorAgg(af)
2908            | Expression::BitwiseAndAgg(af)
2909            | Expression::BitwiseOrAgg(af)
2910            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2911            // Binary operations - left is "this" in sqlglot
2912            Expression::And(op)
2913            | Expression::Or(op)
2914            | Expression::Add(op)
2915            | Expression::Sub(op)
2916            | Expression::Mul(op)
2917            | Expression::Div(op)
2918            | Expression::Mod(op)
2919            | Expression::Eq(op)
2920            | Expression::Neq(op)
2921            | Expression::Lt(op)
2922            | Expression::Lte(op)
2923            | Expression::Gt(op)
2924            | Expression::Gte(op)
2925            | Expression::BitwiseAnd(op)
2926            | Expression::BitwiseOr(op)
2927            | Expression::BitwiseXor(op)
2928            | Expression::Concat(op)
2929            | Expression::Adjacent(op)
2930            | Expression::TsMatch(op)
2931            | Expression::PropertyEQ(op)
2932            | Expression::ArrayContainsAll(op)
2933            | Expression::ArrayContainedBy(op)
2934            | Expression::ArrayOverlaps(op)
2935            | Expression::JSONBContainsAllTopKeys(op)
2936            | Expression::JSONBContainsAnyTopKeys(op)
2937            | Expression::JSONBDeleteAtPath(op)
2938            | Expression::ExtendsLeft(op)
2939            | Expression::ExtendsRight(op)
2940            | Expression::Is(op)
2941            | Expression::MemberOf(op)
2942            | Expression::Match(op)
2943            | Expression::NullSafeEq(op)
2944            | Expression::NullSafeNeq(op)
2945            | Expression::Glob(op)
2946            | Expression::BitwiseLeftShift(op)
2947            | Expression::BitwiseRightShift(op) => Some(&op.left),
2948            // Like operations - left is "this"
2949            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2950            // Structural types with .this
2951            Expression::Alias(a) => Some(&a.this),
2952            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2953            Expression::Paren(p) => Some(&p.this),
2954            Expression::Annotated(a) => Some(&a.this),
2955            Expression::Subquery(s) => Some(&s.this),
2956            Expression::Where(w) => Some(&w.this),
2957            Expression::Having(h) => Some(&h.this),
2958            Expression::Qualify(q) => Some(&q.this),
2959            Expression::IsNull(i) => Some(&i.this),
2960            Expression::Exists(e) => Some(&e.this),
2961            Expression::Ordered(o) => Some(&o.this),
2962            Expression::WindowFunction(wf) => Some(&wf.this),
2963            Expression::Cte(cte) => Some(&cte.this),
2964            Expression::Between(b) => Some(&b.this),
2965            Expression::In(i) => Some(&i.this),
2966            Expression::ReturnStmt(e) => Some(e),
2967            _ => None,
2968        }
2969    }
2970
2971    /// Returns the secondary child expression (".expression" in sqlglot).
2972    pub fn get_expression(&self) -> Option<&Expression> {
2973        match self {
2974            // Binary operations - right is "expression"
2975            Expression::And(op)
2976            | Expression::Or(op)
2977            | Expression::Add(op)
2978            | Expression::Sub(op)
2979            | Expression::Mul(op)
2980            | Expression::Div(op)
2981            | Expression::Mod(op)
2982            | Expression::Eq(op)
2983            | Expression::Neq(op)
2984            | Expression::Lt(op)
2985            | Expression::Lte(op)
2986            | Expression::Gt(op)
2987            | Expression::Gte(op)
2988            | Expression::BitwiseAnd(op)
2989            | Expression::BitwiseOr(op)
2990            | Expression::BitwiseXor(op)
2991            | Expression::Concat(op)
2992            | Expression::Adjacent(op)
2993            | Expression::TsMatch(op)
2994            | Expression::PropertyEQ(op)
2995            | Expression::ArrayContainsAll(op)
2996            | Expression::ArrayContainedBy(op)
2997            | Expression::ArrayOverlaps(op)
2998            | Expression::JSONBContainsAllTopKeys(op)
2999            | Expression::JSONBContainsAnyTopKeys(op)
3000            | Expression::JSONBDeleteAtPath(op)
3001            | Expression::ExtendsLeft(op)
3002            | Expression::ExtendsRight(op)
3003            | Expression::Is(op)
3004            | Expression::MemberOf(op)
3005            | Expression::Match(op)
3006            | Expression::NullSafeEq(op)
3007            | Expression::NullSafeNeq(op)
3008            | Expression::Glob(op)
3009            | Expression::BitwiseLeftShift(op)
3010            | Expression::BitwiseRightShift(op) => Some(&op.right),
3011            // Like operations - right is "expression"
3012            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3013            // BinaryFunc - expression is the secondary
3014            Expression::Power(f)
3015            | Expression::NullIf(f)
3016            | Expression::IfNull(f)
3017            | Expression::Nvl(f)
3018            | Expression::Contains(f)
3019            | Expression::StartsWith(f)
3020            | Expression::EndsWith(f)
3021            | Expression::Levenshtein(f)
3022            | Expression::ModFunc(f)
3023            | Expression::IntDiv(f)
3024            | Expression::Atan2(f)
3025            | Expression::AddMonths(f)
3026            | Expression::MonthsBetween(f)
3027            | Expression::NextDay(f)
3028            | Expression::UnixToTimeStr(f)
3029            | Expression::ArrayContains(f)
3030            | Expression::ArrayPosition(f)
3031            | Expression::ArrayAppend(f)
3032            | Expression::ArrayPrepend(f)
3033            | Expression::ArrayUnion(f)
3034            | Expression::ArrayExcept(f)
3035            | Expression::ArrayRemove(f)
3036            | Expression::StarMap(f)
3037            | Expression::MapFromArrays(f)
3038            | Expression::MapContainsKey(f)
3039            | Expression::ElementAt(f)
3040            | Expression::JsonMergePatch(f)
3041            | Expression::JSONBContains(f)
3042            | Expression::JSONBExtract(f) => Some(&f.expression),
3043            _ => None,
3044        }
3045    }
3046
3047    /// Returns the list of child expressions (".expressions" in sqlglot).
3048    pub fn get_expressions(&self) -> &[Expression] {
3049        match self {
3050            Expression::Select(s) => &s.expressions,
3051            Expression::Function(f) => &f.args,
3052            Expression::AggregateFunction(f) => &f.args,
3053            Expression::From(f) => &f.expressions,
3054            Expression::GroupBy(g) => &g.expressions,
3055            Expression::In(i) => &i.expressions,
3056            Expression::Array(a) => &a.expressions,
3057            Expression::Tuple(t) => &t.expressions,
3058            Expression::Coalesce(f)
3059            | Expression::Greatest(f)
3060            | Expression::Least(f)
3061            | Expression::ArrayConcat(f)
3062            | Expression::ArrayIntersect(f)
3063            | Expression::ArrayZip(f)
3064            | Expression::MapConcat(f)
3065            | Expression::JsonArray(f) => &f.expressions,
3066            _ => &[],
3067        }
3068    }
3069
3070    /// Returns the name of this expression as a string slice.
3071    pub fn get_name(&self) -> &str {
3072        match self {
3073            Expression::Identifier(id) => &id.name,
3074            Expression::Column(col) => &col.name.name,
3075            Expression::Table(t) => &t.name.name,
3076            Expression::Literal(lit) => lit.value_str(),
3077            Expression::Star(_) => "*",
3078            Expression::Function(f) => &f.name,
3079            Expression::AggregateFunction(f) => &f.name,
3080            Expression::Alias(a) => a.this.get_name(),
3081            Expression::Boolean(b) => {
3082                if b.value {
3083                    "TRUE"
3084                } else {
3085                    "FALSE"
3086                }
3087            }
3088            Expression::Null(_) => "NULL",
3089            _ => "",
3090        }
3091    }
3092
3093    /// Returns the alias name if this expression has one.
3094    pub fn get_alias(&self) -> &str {
3095        match self {
3096            Expression::Alias(a) => &a.alias.name,
3097            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3098            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3099            _ => "",
3100        }
3101    }
3102
3103    /// Returns the output name of this expression (what it shows up as in a SELECT).
3104    pub fn get_output_name(&self) -> &str {
3105        match self {
3106            Expression::Alias(a) => &a.alias.name,
3107            Expression::Column(c) => &c.name.name,
3108            Expression::Identifier(id) => &id.name,
3109            Expression::Literal(lit) => lit.value_str(),
3110            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3111            Expression::Star(_) => "*",
3112            _ => "",
3113        }
3114    }
3115
3116    /// Returns comments attached to this expression.
3117    pub fn get_comments(&self) -> Vec<&str> {
3118        match self {
3119            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3120            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3121            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3122            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3123            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3124            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3125            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3126                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3127            }
3128            Expression::And(op)
3129            | Expression::Or(op)
3130            | Expression::Add(op)
3131            | Expression::Sub(op)
3132            | Expression::Mul(op)
3133            | Expression::Div(op)
3134            | Expression::Mod(op)
3135            | Expression::Eq(op)
3136            | Expression::Neq(op)
3137            | Expression::Lt(op)
3138            | Expression::Lte(op)
3139            | Expression::Gt(op)
3140            | Expression::Gte(op)
3141            | Expression::Concat(op)
3142            | Expression::BitwiseAnd(op)
3143            | Expression::BitwiseOr(op)
3144            | Expression::BitwiseXor(op) => {
3145                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3146            }
3147            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3148            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3149            _ => Vec::new(),
3150        }
3151    }
3152}
3153
3154impl fmt::Display for Expression {
3155    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3156        // Basic display - full SQL generation is in generator module
3157        match self {
3158            Expression::Literal(lit) => write!(f, "{}", lit),
3159            Expression::Identifier(id) => write!(f, "{}", id),
3160            Expression::Column(col) => write!(f, "{}", col),
3161            Expression::Star(_) => write!(f, "*"),
3162            Expression::Null(_) => write!(f, "NULL"),
3163            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3164            Expression::Select(_) => write!(f, "SELECT ..."),
3165            _ => write!(f, "{:?}", self),
3166        }
3167    }
3168}
3169
3170/// Represent a SQL literal value.
3171///
3172/// Numeric values are stored as their original text representation (not parsed
3173/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3174/// preserved across round-trips.
3175///
3176/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3177/// strings, raw strings, etc.) each have a dedicated variant so that the
3178/// generator can emit them with the correct syntax.
3179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3180#[cfg_attr(feature = "bindings", derive(TS))]
3181#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3182pub enum Literal {
3183    /// Single-quoted string literal: `'hello'`
3184    String(String),
3185    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3186    Number(String),
3187    /// Hex string literal: `X'FF'`
3188    HexString(String),
3189    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3190    HexNumber(String),
3191    BitString(String),
3192    /// Byte string: b"..." (BigQuery style)
3193    ByteString(String),
3194    /// National string: N'abc'
3195    NationalString(String),
3196    /// DATE literal: DATE '2024-01-15'
3197    Date(String),
3198    /// TIME literal: TIME '10:30:00'
3199    Time(String),
3200    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3201    Timestamp(String),
3202    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3203    Datetime(String),
3204    /// Triple-quoted string: """...""" or '''...'''
3205    /// Contains (content, quote_char) where quote_char is '"' or '\''
3206    TripleQuotedString(String, char),
3207    /// Escape string: E'...' (PostgreSQL)
3208    EscapeString(String),
3209    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3210    DollarString(String),
3211    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3212    /// In raw strings, backslashes are literal and not escape characters.
3213    /// When converting to a regular string, backslashes must be doubled.
3214    RawString(String),
3215}
3216
3217impl Literal {
3218    /// Returns the inner value as a string slice, regardless of literal type.
3219    pub fn value_str(&self) -> &str {
3220        match self {
3221            Literal::String(s)
3222            | Literal::Number(s)
3223            | Literal::HexString(s)
3224            | Literal::HexNumber(s)
3225            | Literal::BitString(s)
3226            | Literal::ByteString(s)
3227            | Literal::NationalString(s)
3228            | Literal::Date(s)
3229            | Literal::Time(s)
3230            | Literal::Timestamp(s)
3231            | Literal::Datetime(s)
3232            | Literal::EscapeString(s)
3233            | Literal::DollarString(s)
3234            | Literal::RawString(s) => s.as_str(),
3235            Literal::TripleQuotedString(s, _) => s.as_str(),
3236        }
3237    }
3238
3239    /// Returns `true` if this is a string-type literal.
3240    pub fn is_string(&self) -> bool {
3241        matches!(
3242            self,
3243            Literal::String(_)
3244                | Literal::NationalString(_)
3245                | Literal::EscapeString(_)
3246                | Literal::DollarString(_)
3247                | Literal::RawString(_)
3248                | Literal::TripleQuotedString(_, _)
3249        )
3250    }
3251
3252    /// Returns `true` if this is a numeric literal.
3253    pub fn is_number(&self) -> bool {
3254        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3255    }
3256}
3257
3258impl fmt::Display for Literal {
3259    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3260        match self {
3261            Literal::String(s) => write!(f, "'{}'", s),
3262            Literal::Number(n) => write!(f, "{}", n),
3263            Literal::HexString(h) => write!(f, "X'{}'", h),
3264            Literal::HexNumber(h) => write!(f, "0x{}", h),
3265            Literal::BitString(b) => write!(f, "B'{}'", b),
3266            Literal::ByteString(b) => write!(f, "b'{}'", b),
3267            Literal::NationalString(s) => write!(f, "N'{}'", s),
3268            Literal::Date(d) => write!(f, "DATE '{}'", d),
3269            Literal::Time(t) => write!(f, "TIME '{}'", t),
3270            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3271            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3272            Literal::TripleQuotedString(s, q) => {
3273                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3274            }
3275            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3276            Literal::DollarString(s) => write!(f, "$${}$$", s),
3277            Literal::RawString(s) => write!(f, "r'{}'", s),
3278        }
3279    }
3280}
3281
3282/// Boolean literal
3283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3284#[cfg_attr(feature = "bindings", derive(TS))]
3285pub struct BooleanLiteral {
3286    pub value: bool,
3287}
3288
3289/// NULL literal
3290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3291#[cfg_attr(feature = "bindings", derive(TS))]
3292pub struct Null;
3293
3294/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3295///
3296/// The `quoted` flag indicates whether the identifier was originally delimited
3297/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3298/// dialect). The generator uses this flag to decide whether to emit quoting
3299/// characters.
3300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3301#[cfg_attr(feature = "bindings", derive(TS))]
3302pub struct Identifier {
3303    /// The raw text of the identifier, without any quoting characters.
3304    pub name: String,
3305    /// Whether the identifier was quoted in the source SQL.
3306    pub quoted: bool,
3307    #[serde(default)]
3308    pub trailing_comments: Vec<String>,
3309    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3310    #[serde(default, skip_serializing_if = "Option::is_none")]
3311    pub span: Option<Span>,
3312}
3313
3314impl Identifier {
3315    pub fn new(name: impl Into<String>) -> Self {
3316        Self {
3317            name: name.into(),
3318            quoted: false,
3319            trailing_comments: Vec::new(),
3320            span: None,
3321        }
3322    }
3323
3324    pub fn quoted(name: impl Into<String>) -> Self {
3325        Self {
3326            name: name.into(),
3327            quoted: true,
3328            trailing_comments: Vec::new(),
3329            span: None,
3330        }
3331    }
3332
3333    pub fn empty() -> Self {
3334        Self {
3335            name: String::new(),
3336            quoted: false,
3337            trailing_comments: Vec::new(),
3338            span: None,
3339        }
3340    }
3341
3342    pub fn is_empty(&self) -> bool {
3343        self.name.is_empty()
3344    }
3345
3346    /// Set the source span on this identifier
3347    pub fn with_span(mut self, span: Span) -> Self {
3348        self.span = Some(span);
3349        self
3350    }
3351}
3352
3353impl fmt::Display for Identifier {
3354    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3355        if self.quoted {
3356            write!(f, "\"{}\"", self.name)
3357        } else {
3358            write!(f, "{}", self.name)
3359        }
3360    }
3361}
3362
3363/// Represent a column reference, optionally qualified by a table name.
3364///
3365/// Renders as `name` when unqualified, or `table.name` when qualified.
3366/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3367/// convenient construction.
3368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3369#[cfg_attr(feature = "bindings", derive(TS))]
3370pub struct Column {
3371    /// The column name.
3372    pub name: Identifier,
3373    /// Optional table qualifier (e.g. `t` in `t.col`).
3374    pub table: Option<Identifier>,
3375    /// Oracle-style join marker (+) for outer joins
3376    #[serde(default)]
3377    pub join_mark: bool,
3378    /// Trailing comments that appeared after this column reference
3379    #[serde(default)]
3380    pub trailing_comments: Vec<String>,
3381    /// Source position span
3382    #[serde(default, skip_serializing_if = "Option::is_none")]
3383    pub span: Option<Span>,
3384    /// Inferred data type from type annotation
3385    #[serde(default, skip_serializing_if = "Option::is_none")]
3386    pub inferred_type: Option<DataType>,
3387}
3388
3389impl fmt::Display for Column {
3390    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3391        if let Some(table) = &self.table {
3392            write!(f, "{}.{}", table, self.name)
3393        } else {
3394            write!(f, "{}", self.name)
3395        }
3396    }
3397}
3398
3399/// Represent a table reference with optional schema and catalog qualifiers.
3400///
3401/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3402/// which qualifiers are present. Supports aliases, column alias lists,
3403/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3404/// several other dialect-specific extensions.
3405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3406#[cfg_attr(feature = "bindings", derive(TS))]
3407pub struct TableRef {
3408    /// The unqualified table name.
3409    pub name: Identifier,
3410    /// Optional schema qualifier (e.g. `public` in `public.users`).
3411    pub schema: Option<Identifier>,
3412    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3413    pub catalog: Option<Identifier>,
3414    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3415    pub alias: Option<Identifier>,
3416    /// Whether AS keyword was explicitly used for the alias
3417    #[serde(default)]
3418    pub alias_explicit_as: bool,
3419    /// Column aliases for table alias: AS t(c1, c2)
3420    #[serde(default)]
3421    pub column_aliases: Vec<Identifier>,
3422    /// Leading comments that appeared before this table reference in a FROM clause
3423    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3424    pub leading_comments: Vec<String>,
3425    /// Trailing comments that appeared after this table reference
3426    #[serde(default)]
3427    pub trailing_comments: Vec<String>,
3428    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3429    #[serde(default)]
3430    pub when: Option<Box<HistoricalData>>,
3431    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3432    #[serde(default)]
3433    pub only: bool,
3434    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3435    #[serde(default)]
3436    pub final_: bool,
3437    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3438    #[serde(default, skip_serializing_if = "Option::is_none")]
3439    pub table_sample: Option<Box<Sample>>,
3440    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3441    #[serde(default)]
3442    pub hints: Vec<Expression>,
3443    /// TSQL: FOR SYSTEM_TIME temporal clause
3444    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3445    #[serde(default, skip_serializing_if = "Option::is_none")]
3446    pub system_time: Option<String>,
3447    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3448    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3449    pub partitions: Vec<Identifier>,
3450    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3451    /// When set, this is used instead of the name field
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub identifier_func: Option<Box<Expression>>,
3454    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3455    #[serde(default, skip_serializing_if = "Option::is_none")]
3456    pub changes: Option<Box<Changes>>,
3457    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3458    #[serde(default, skip_serializing_if = "Option::is_none")]
3459    pub version: Option<Box<Version>>,
3460    /// Source position span
3461    #[serde(default, skip_serializing_if = "Option::is_none")]
3462    pub span: Option<Span>,
3463}
3464
3465impl TableRef {
3466    pub fn new(name: impl Into<String>) -> Self {
3467        Self {
3468            name: Identifier::new(name),
3469            schema: None,
3470            catalog: None,
3471            alias: None,
3472            alias_explicit_as: false,
3473            column_aliases: Vec::new(),
3474            leading_comments: Vec::new(),
3475            trailing_comments: Vec::new(),
3476            when: None,
3477            only: false,
3478            final_: false,
3479            table_sample: None,
3480            hints: Vec::new(),
3481            system_time: None,
3482            partitions: Vec::new(),
3483            identifier_func: None,
3484            changes: None,
3485            version: None,
3486            span: None,
3487        }
3488    }
3489
3490    /// Create with a schema qualifier.
3491    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3492        let mut t = Self::new(name);
3493        t.schema = Some(Identifier::new(schema));
3494        t
3495    }
3496
3497    /// Create with catalog and schema qualifiers.
3498    pub fn new_with_catalog(
3499        name: impl Into<String>,
3500        schema: impl Into<String>,
3501        catalog: impl Into<String>,
3502    ) -> Self {
3503        let mut t = Self::new(name);
3504        t.schema = Some(Identifier::new(schema));
3505        t.catalog = Some(Identifier::new(catalog));
3506        t
3507    }
3508
3509    /// Create from an Identifier, preserving the quoted flag
3510    pub fn from_identifier(name: Identifier) -> Self {
3511        Self {
3512            name,
3513            schema: None,
3514            catalog: None,
3515            alias: None,
3516            alias_explicit_as: false,
3517            column_aliases: Vec::new(),
3518            leading_comments: Vec::new(),
3519            trailing_comments: Vec::new(),
3520            when: None,
3521            only: false,
3522            final_: false,
3523            table_sample: None,
3524            hints: Vec::new(),
3525            system_time: None,
3526            partitions: Vec::new(),
3527            identifier_func: None,
3528            changes: None,
3529            version: None,
3530            span: None,
3531        }
3532    }
3533
3534    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3535        self.alias = Some(Identifier::new(alias));
3536        self
3537    }
3538
3539    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3540        self.schema = Some(Identifier::new(schema));
3541        self
3542    }
3543}
3544
3545/// Represent a wildcard star expression (`*`, `table.*`).
3546///
3547/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3548/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3550#[cfg_attr(feature = "bindings", derive(TS))]
3551pub struct Star {
3552    /// Optional table qualifier (e.g. `t` in `t.*`).
3553    pub table: Option<Identifier>,
3554    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3555    pub except: Option<Vec<Identifier>>,
3556    /// REPLACE expressions (BigQuery, Snowflake)
3557    pub replace: Option<Vec<Alias>>,
3558    /// RENAME columns (Snowflake)
3559    pub rename: Option<Vec<(Identifier, Identifier)>>,
3560    /// Trailing comments that appeared after the star
3561    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3562    pub trailing_comments: Vec<String>,
3563    /// Source position span
3564    #[serde(default, skip_serializing_if = "Option::is_none")]
3565    pub span: Option<Span>,
3566}
3567
3568/// Represent a complete SELECT statement.
3569///
3570/// This is the most feature-rich AST node, covering the full surface area of
3571/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3572/// `Vec` are omitted from the generated SQL when absent.
3573///
3574/// # Key Fields
3575///
3576/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3577/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3578/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3579/// - `where_clause` -- the WHERE predicate.
3580/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3581/// - `having` -- HAVING predicate.
3582/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3583/// - `limit` / `offset` / `fetch` -- result set limiting.
3584/// - `with` -- Common Table Expressions (CTEs).
3585/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3586/// - `windows` -- named window definitions (WINDOW w AS ...).
3587///
3588/// Dialect-specific extensions are supported via fields like `prewhere`
3589/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3590/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3592#[cfg_attr(feature = "bindings", derive(TS))]
3593pub struct Select {
3594    /// The select-list: columns, expressions, aliases, and wildcards.
3595    pub expressions: Vec<Expression>,
3596    /// The FROM clause, containing one or more table sources.
3597    pub from: Option<From>,
3598    /// JOIN clauses applied after the FROM source.
3599    pub joins: Vec<Join>,
3600    pub lateral_views: Vec<LateralView>,
3601    /// ClickHouse PREWHERE clause
3602    #[serde(default, skip_serializing_if = "Option::is_none")]
3603    pub prewhere: Option<Expression>,
3604    pub where_clause: Option<Where>,
3605    pub group_by: Option<GroupBy>,
3606    pub having: Option<Having>,
3607    pub qualify: Option<Qualify>,
3608    pub order_by: Option<OrderBy>,
3609    pub distribute_by: Option<DistributeBy>,
3610    pub cluster_by: Option<ClusterBy>,
3611    pub sort_by: Option<SortBy>,
3612    pub limit: Option<Limit>,
3613    pub offset: Option<Offset>,
3614    /// ClickHouse LIMIT BY clause expressions
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub limit_by: Option<Vec<Expression>>,
3617    pub fetch: Option<Fetch>,
3618    pub distinct: bool,
3619    pub distinct_on: Option<Vec<Expression>>,
3620    pub top: Option<Top>,
3621    pub with: Option<With>,
3622    pub sample: Option<Sample>,
3623    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3624    #[serde(default, skip_serializing_if = "Option::is_none")]
3625    pub settings: Option<Vec<Expression>>,
3626    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3627    #[serde(default, skip_serializing_if = "Option::is_none")]
3628    pub format: Option<Expression>,
3629    pub windows: Option<Vec<NamedWindow>>,
3630    pub hint: Option<Hint>,
3631    /// Oracle CONNECT BY clause for hierarchical queries
3632    pub connect: Option<Connect>,
3633    /// SELECT ... INTO table_name for creating tables
3634    pub into: Option<SelectInto>,
3635    /// FOR UPDATE/SHARE locking clauses
3636    #[serde(default)]
3637    pub locks: Vec<Lock>,
3638    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3639    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3640    pub for_xml: Vec<Expression>,
3641    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3642    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3643    pub for_json: Vec<Expression>,
3644    /// Leading comments before the statement
3645    #[serde(default)]
3646    pub leading_comments: Vec<String>,
3647    /// Comments that appear after SELECT keyword (before expressions)
3648    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3649    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3650    pub post_select_comments: Vec<String>,
3651    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub kind: Option<String>,
3654    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3655    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3656    pub operation_modifiers: Vec<String>,
3657    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3658    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3659    pub qualify_after_window: bool,
3660    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3661    #[serde(default, skip_serializing_if = "Option::is_none")]
3662    pub option: Option<String>,
3663    /// Redshift-style EXCLUDE clause at the end of the projection list
3664    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3665    #[serde(default, skip_serializing_if = "Option::is_none")]
3666    pub exclude: Option<Vec<Expression>>,
3667}
3668
3669impl Select {
3670    pub fn new() -> Self {
3671        Self {
3672            expressions: Vec::new(),
3673            from: None,
3674            joins: Vec::new(),
3675            lateral_views: Vec::new(),
3676            prewhere: None,
3677            where_clause: None,
3678            group_by: None,
3679            having: None,
3680            qualify: None,
3681            order_by: None,
3682            distribute_by: None,
3683            cluster_by: None,
3684            sort_by: None,
3685            limit: None,
3686            offset: None,
3687            limit_by: None,
3688            fetch: None,
3689            distinct: false,
3690            distinct_on: None,
3691            top: None,
3692            with: None,
3693            sample: None,
3694            settings: None,
3695            format: None,
3696            windows: None,
3697            hint: None,
3698            connect: None,
3699            into: None,
3700            locks: Vec::new(),
3701            for_xml: Vec::new(),
3702            for_json: Vec::new(),
3703            leading_comments: Vec::new(),
3704            post_select_comments: Vec::new(),
3705            kind: None,
3706            operation_modifiers: Vec::new(),
3707            qualify_after_window: false,
3708            option: None,
3709            exclude: None,
3710        }
3711    }
3712
3713    /// Add a column to select
3714    pub fn column(mut self, expr: Expression) -> Self {
3715        self.expressions.push(expr);
3716        self
3717    }
3718
3719    /// Set the FROM clause
3720    pub fn from(mut self, table: Expression) -> Self {
3721        self.from = Some(From {
3722            expressions: vec![table],
3723        });
3724        self
3725    }
3726
3727    /// Add a WHERE clause
3728    pub fn where_(mut self, condition: Expression) -> Self {
3729        self.where_clause = Some(Where { this: condition });
3730        self
3731    }
3732
3733    /// Set DISTINCT
3734    pub fn distinct(mut self) -> Self {
3735        self.distinct = true;
3736        self
3737    }
3738
3739    /// Add a JOIN
3740    pub fn join(mut self, join: Join) -> Self {
3741        self.joins.push(join);
3742        self
3743    }
3744
3745    /// Set ORDER BY
3746    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3747        self.order_by = Some(OrderBy {
3748            expressions,
3749            siblings: false,
3750            comments: Vec::new(),
3751        });
3752        self
3753    }
3754
3755    /// Set LIMIT
3756    pub fn limit(mut self, n: Expression) -> Self {
3757        self.limit = Some(Limit {
3758            this: n,
3759            percent: false,
3760            comments: Vec::new(),
3761        });
3762        self
3763    }
3764
3765    /// Set OFFSET
3766    pub fn offset(mut self, n: Expression) -> Self {
3767        self.offset = Some(Offset {
3768            this: n,
3769            rows: None,
3770        });
3771        self
3772    }
3773}
3774
3775impl Default for Select {
3776    fn default() -> Self {
3777        Self::new()
3778    }
3779}
3780
3781/// Represent a UNION set operation between two query expressions.
3782///
3783/// When `all` is true, duplicate rows are preserved (UNION ALL).
3784/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3785/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3787#[cfg_attr(feature = "bindings", derive(TS))]
3788pub struct Union {
3789    /// The left-hand query operand.
3790    pub left: Expression,
3791    /// The right-hand query operand.
3792    pub right: Expression,
3793    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3794    pub all: bool,
3795    /// Whether DISTINCT was explicitly specified
3796    #[serde(default)]
3797    pub distinct: bool,
3798    /// Optional WITH clause
3799    pub with: Option<With>,
3800    /// ORDER BY applied to entire UNION result
3801    pub order_by: Option<OrderBy>,
3802    /// LIMIT applied to entire UNION result
3803    pub limit: Option<Box<Expression>>,
3804    /// OFFSET applied to entire UNION result
3805    pub offset: Option<Box<Expression>>,
3806    /// DISTRIBUTE BY clause (Hive/Spark)
3807    #[serde(default, skip_serializing_if = "Option::is_none")]
3808    pub distribute_by: Option<DistributeBy>,
3809    /// SORT BY clause (Hive/Spark)
3810    #[serde(default, skip_serializing_if = "Option::is_none")]
3811    pub sort_by: Option<SortBy>,
3812    /// CLUSTER BY clause (Hive/Spark)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub cluster_by: Option<ClusterBy>,
3815    /// DuckDB BY NAME modifier
3816    #[serde(default)]
3817    pub by_name: bool,
3818    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3819    #[serde(default, skip_serializing_if = "Option::is_none")]
3820    pub side: Option<String>,
3821    /// BigQuery: Set operation kind (INNER)
3822    #[serde(default, skip_serializing_if = "Option::is_none")]
3823    pub kind: Option<String>,
3824    /// BigQuery: CORRESPONDING modifier
3825    #[serde(default)]
3826    pub corresponding: bool,
3827    /// BigQuery: STRICT modifier (before CORRESPONDING)
3828    #[serde(default)]
3829    pub strict: bool,
3830    /// BigQuery: BY (columns) after CORRESPONDING
3831    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3832    pub on_columns: Vec<Expression>,
3833}
3834
3835/// Iteratively flatten the left-recursive chain to prevent stack overflow
3836/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3837impl Drop for Union {
3838    fn drop(&mut self) {
3839        loop {
3840            if let Expression::Union(ref mut inner) = self.left {
3841                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3842                let old_left = std::mem::replace(&mut self.left, next_left);
3843                drop(old_left);
3844            } else {
3845                break;
3846            }
3847        }
3848    }
3849}
3850
3851/// Represent an INTERSECT set operation between two query expressions.
3852///
3853/// Returns only rows that appear in both operands. When `all` is true,
3854/// duplicates are preserved according to their multiplicity.
3855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3856#[cfg_attr(feature = "bindings", derive(TS))]
3857pub struct Intersect {
3858    /// The left-hand query operand.
3859    pub left: Expression,
3860    /// The right-hand query operand.
3861    pub right: Expression,
3862    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3863    pub all: bool,
3864    /// Whether DISTINCT was explicitly specified
3865    #[serde(default)]
3866    pub distinct: bool,
3867    /// Optional WITH clause
3868    pub with: Option<With>,
3869    /// ORDER BY applied to entire INTERSECT result
3870    pub order_by: Option<OrderBy>,
3871    /// LIMIT applied to entire INTERSECT result
3872    pub limit: Option<Box<Expression>>,
3873    /// OFFSET applied to entire INTERSECT result
3874    pub offset: Option<Box<Expression>>,
3875    /// DISTRIBUTE BY clause (Hive/Spark)
3876    #[serde(default, skip_serializing_if = "Option::is_none")]
3877    pub distribute_by: Option<DistributeBy>,
3878    /// SORT BY clause (Hive/Spark)
3879    #[serde(default, skip_serializing_if = "Option::is_none")]
3880    pub sort_by: Option<SortBy>,
3881    /// CLUSTER BY clause (Hive/Spark)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub cluster_by: Option<ClusterBy>,
3884    /// DuckDB BY NAME modifier
3885    #[serde(default)]
3886    pub by_name: bool,
3887    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3888    #[serde(default, skip_serializing_if = "Option::is_none")]
3889    pub side: Option<String>,
3890    /// BigQuery: Set operation kind (INNER)
3891    #[serde(default, skip_serializing_if = "Option::is_none")]
3892    pub kind: Option<String>,
3893    /// BigQuery: CORRESPONDING modifier
3894    #[serde(default)]
3895    pub corresponding: bool,
3896    /// BigQuery: STRICT modifier (before CORRESPONDING)
3897    #[serde(default)]
3898    pub strict: bool,
3899    /// BigQuery: BY (columns) after CORRESPONDING
3900    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3901    pub on_columns: Vec<Expression>,
3902}
3903
3904impl Drop for Intersect {
3905    fn drop(&mut self) {
3906        loop {
3907            if let Expression::Intersect(ref mut inner) = self.left {
3908                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3909                let old_left = std::mem::replace(&mut self.left, next_left);
3910                drop(old_left);
3911            } else {
3912                break;
3913            }
3914        }
3915    }
3916}
3917
3918/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3919///
3920/// Returns rows from the left operand that do not appear in the right operand.
3921/// When `all` is true, duplicates are subtracted according to their multiplicity.
3922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3923#[cfg_attr(feature = "bindings", derive(TS))]
3924pub struct Except {
3925    /// The left-hand query operand.
3926    pub left: Expression,
3927    /// The right-hand query operand (rows to subtract).
3928    pub right: Expression,
3929    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3930    pub all: bool,
3931    /// Whether DISTINCT was explicitly specified
3932    #[serde(default)]
3933    pub distinct: bool,
3934    /// Optional WITH clause
3935    pub with: Option<With>,
3936    /// ORDER BY applied to entire EXCEPT result
3937    pub order_by: Option<OrderBy>,
3938    /// LIMIT applied to entire EXCEPT result
3939    pub limit: Option<Box<Expression>>,
3940    /// OFFSET applied to entire EXCEPT result
3941    pub offset: Option<Box<Expression>>,
3942    /// DISTRIBUTE BY clause (Hive/Spark)
3943    #[serde(default, skip_serializing_if = "Option::is_none")]
3944    pub distribute_by: Option<DistributeBy>,
3945    /// SORT BY clause (Hive/Spark)
3946    #[serde(default, skip_serializing_if = "Option::is_none")]
3947    pub sort_by: Option<SortBy>,
3948    /// CLUSTER BY clause (Hive/Spark)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub cluster_by: Option<ClusterBy>,
3951    /// DuckDB BY NAME modifier
3952    #[serde(default)]
3953    pub by_name: bool,
3954    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3955    #[serde(default, skip_serializing_if = "Option::is_none")]
3956    pub side: Option<String>,
3957    /// BigQuery: Set operation kind (INNER)
3958    #[serde(default, skip_serializing_if = "Option::is_none")]
3959    pub kind: Option<String>,
3960    /// BigQuery: CORRESPONDING modifier
3961    #[serde(default)]
3962    pub corresponding: bool,
3963    /// BigQuery: STRICT modifier (before CORRESPONDING)
3964    #[serde(default)]
3965    pub strict: bool,
3966    /// BigQuery: BY (columns) after CORRESPONDING
3967    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3968    pub on_columns: Vec<Expression>,
3969}
3970
3971impl Drop for Except {
3972    fn drop(&mut self) {
3973        loop {
3974            if let Expression::Except(ref mut inner) = self.left {
3975                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3976                let old_left = std::mem::replace(&mut self.left, next_left);
3977                drop(old_left);
3978            } else {
3979                break;
3980            }
3981        }
3982    }
3983}
3984
3985/// INTO clause for SELECT INTO statements
3986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3987#[cfg_attr(feature = "bindings", derive(TS))]
3988pub struct SelectInto {
3989    /// Target table or variable (used when single target)
3990    pub this: Expression,
3991    /// Whether TEMPORARY keyword was used
3992    #[serde(default)]
3993    pub temporary: bool,
3994    /// Whether UNLOGGED keyword was used (PostgreSQL)
3995    #[serde(default)]
3996    pub unlogged: bool,
3997    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3998    #[serde(default)]
3999    pub bulk_collect: bool,
4000    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
4001    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4002    pub expressions: Vec<Expression>,
4003}
4004
4005/// Represent a parenthesized subquery expression.
4006///
4007/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
4008/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4009/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4010/// modifiers are rendered inside or outside the parentheses.
4011///
4012/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4013/// scalar subqueries in select-lists, and derived tables.
4014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4015#[cfg_attr(feature = "bindings", derive(TS))]
4016pub struct Subquery {
4017    /// The inner query expression.
4018    pub this: Expression,
4019    /// Optional alias for the derived table.
4020    pub alias: Option<Identifier>,
4021    /// Optional column aliases: AS t(c1, c2)
4022    pub column_aliases: Vec<Identifier>,
4023    /// Whether AS keyword was explicitly used for the alias.
4024    #[serde(default)]
4025    pub alias_explicit_as: bool,
4026    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4027    #[serde(skip_serializing_if = "Option::is_none", default)]
4028    pub alias_keyword: Option<String>,
4029    /// ORDER BY clause (for parenthesized queries)
4030    pub order_by: Option<OrderBy>,
4031    /// LIMIT clause
4032    pub limit: Option<Limit>,
4033    /// OFFSET clause
4034    pub offset: Option<Offset>,
4035    /// DISTRIBUTE BY clause (Hive/Spark)
4036    #[serde(default, skip_serializing_if = "Option::is_none")]
4037    pub distribute_by: Option<DistributeBy>,
4038    /// SORT BY clause (Hive/Spark)
4039    #[serde(default, skip_serializing_if = "Option::is_none")]
4040    pub sort_by: Option<SortBy>,
4041    /// CLUSTER BY clause (Hive/Spark)
4042    #[serde(default, skip_serializing_if = "Option::is_none")]
4043    pub cluster_by: Option<ClusterBy>,
4044    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4045    #[serde(default)]
4046    pub lateral: bool,
4047    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4048    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4049    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4050    #[serde(default)]
4051    pub modifiers_inside: bool,
4052    /// Trailing comments after the closing paren
4053    #[serde(default)]
4054    pub trailing_comments: Vec<String>,
4055    /// Inferred data type from type annotation
4056    #[serde(default, skip_serializing_if = "Option::is_none")]
4057    pub inferred_type: Option<DataType>,
4058}
4059
4060/// Pipe operator expression: query |> transform
4061///
4062/// Used in DataFusion and BigQuery pipe syntax:
4063///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4065#[cfg_attr(feature = "bindings", derive(TS))]
4066pub struct PipeOperator {
4067    /// The input query/expression (left side of |>)
4068    pub this: Expression,
4069    /// The piped operation (right side of |>)
4070    pub expression: Expression,
4071}
4072
4073/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4075#[cfg_attr(feature = "bindings", derive(TS))]
4076pub struct Values {
4077    /// The rows of values
4078    pub expressions: Vec<Tuple>,
4079    /// Optional alias for the table
4080    pub alias: Option<Identifier>,
4081    /// Optional column aliases: AS t(c1, c2)
4082    pub column_aliases: Vec<Identifier>,
4083}
4084
4085/// PIVOT operation - supports both standard and DuckDB simplified syntax
4086///
4087/// Standard syntax (in FROM clause):
4088///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4089///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4090///
4091/// DuckDB simplified syntax (statement-level):
4092///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4093///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4095#[cfg_attr(feature = "bindings", derive(TS))]
4096pub struct Pivot {
4097    /// Source table/expression
4098    pub this: Expression,
4099    /// For standard PIVOT: the aggregation function(s) (first is primary)
4100    /// For DuckDB simplified: unused (use `using` instead)
4101    #[serde(default)]
4102    pub expressions: Vec<Expression>,
4103    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4104    #[serde(default)]
4105    pub fields: Vec<Expression>,
4106    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4107    #[serde(default)]
4108    pub using: Vec<Expression>,
4109    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4110    #[serde(default)]
4111    pub group: Option<Box<Expression>>,
4112    /// Whether this is an UNPIVOT (vs PIVOT)
4113    #[serde(default)]
4114    pub unpivot: bool,
4115    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4116    #[serde(default)]
4117    pub into: Option<Box<Expression>>,
4118    /// Optional alias
4119    #[serde(default)]
4120    pub alias: Option<Identifier>,
4121    /// Optional output column aliases from `PIVOT(...) AS alias(col1, col2, ...)`
4122    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4123    pub alias_columns: Vec<Identifier>,
4124    /// Include/exclude nulls (for UNPIVOT)
4125    #[serde(default)]
4126    pub include_nulls: Option<bool>,
4127    /// Default on null value (Snowflake)
4128    #[serde(default)]
4129    pub default_on_null: Option<Box<Expression>>,
4130    /// WITH clause (CTEs)
4131    #[serde(default, skip_serializing_if = "Option::is_none")]
4132    pub with: Option<With>,
4133}
4134
4135/// UNPIVOT operation
4136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4137#[cfg_attr(feature = "bindings", derive(TS))]
4138pub struct Unpivot {
4139    pub this: Expression,
4140    pub value_column: Identifier,
4141    pub name_column: Identifier,
4142    pub columns: Vec<Expression>,
4143    pub alias: Option<Identifier>,
4144    /// Optional output column aliases from `UNPIVOT(...) AS alias(col1, col2, ...)`
4145    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4146    pub alias_columns: Vec<Identifier>,
4147    /// Whether the value_column was parenthesized in the original SQL
4148    #[serde(default)]
4149    pub value_column_parenthesized: bool,
4150    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4151    #[serde(default)]
4152    pub include_nulls: Option<bool>,
4153    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4154    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4155    pub extra_value_columns: Vec<Identifier>,
4156}
4157
4158/// PIVOT alias for aliasing pivot expressions
4159/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4161#[cfg_attr(feature = "bindings", derive(TS))]
4162pub struct PivotAlias {
4163    pub this: Expression,
4164    pub alias: Expression,
4165}
4166
4167/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4169#[cfg_attr(feature = "bindings", derive(TS))]
4170pub struct PreWhere {
4171    pub this: Expression,
4172}
4173
4174/// STREAM definition (Snowflake) - for change data capture
4175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4176#[cfg_attr(feature = "bindings", derive(TS))]
4177pub struct Stream {
4178    pub this: Expression,
4179    #[serde(skip_serializing_if = "Option::is_none")]
4180    pub on: Option<Expression>,
4181    #[serde(skip_serializing_if = "Option::is_none")]
4182    pub show_initial_rows: Option<bool>,
4183}
4184
4185/// USING DATA clause for data import statements
4186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4187#[cfg_attr(feature = "bindings", derive(TS))]
4188pub struct UsingData {
4189    pub this: Expression,
4190}
4191
4192/// XML Namespace declaration
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub struct XmlNamespace {
4196    pub this: Expression,
4197    #[serde(skip_serializing_if = "Option::is_none")]
4198    pub alias: Option<Identifier>,
4199}
4200
4201/// ROW FORMAT clause for Hive/Spark
4202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4203#[cfg_attr(feature = "bindings", derive(TS))]
4204pub struct RowFormat {
4205    pub delimited: bool,
4206    pub fields_terminated_by: Option<String>,
4207    pub collection_items_terminated_by: Option<String>,
4208    pub map_keys_terminated_by: Option<String>,
4209    pub lines_terminated_by: Option<String>,
4210    pub null_defined_as: Option<String>,
4211}
4212
4213/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4215#[cfg_attr(feature = "bindings", derive(TS))]
4216pub struct DirectoryInsert {
4217    pub local: bool,
4218    pub path: String,
4219    pub row_format: Option<RowFormat>,
4220    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4221    #[serde(default)]
4222    pub stored_as: Option<String>,
4223}
4224
4225/// INSERT statement
4226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4227#[cfg_attr(feature = "bindings", derive(TS))]
4228pub struct Insert {
4229    pub table: TableRef,
4230    pub columns: Vec<Identifier>,
4231    pub values: Vec<Vec<Expression>>,
4232    pub query: Option<Expression>,
4233    /// INSERT OVERWRITE for Hive/Spark
4234    pub overwrite: bool,
4235    /// PARTITION clause for Hive/Spark
4236    pub partition: Vec<(Identifier, Option<Expression>)>,
4237    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4238    #[serde(default)]
4239    pub directory: Option<DirectoryInsert>,
4240    /// RETURNING clause (PostgreSQL, SQLite)
4241    #[serde(default)]
4242    pub returning: Vec<Expression>,
4243    /// OUTPUT clause (TSQL)
4244    #[serde(default)]
4245    pub output: Option<OutputClause>,
4246    /// ON CONFLICT clause (PostgreSQL, SQLite)
4247    #[serde(default)]
4248    pub on_conflict: Option<Box<Expression>>,
4249    /// Leading comments before the statement
4250    #[serde(default)]
4251    pub leading_comments: Vec<String>,
4252    /// IF EXISTS clause (Hive)
4253    #[serde(default)]
4254    pub if_exists: bool,
4255    /// WITH clause (CTEs)
4256    #[serde(default)]
4257    pub with: Option<With>,
4258    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4259    #[serde(default)]
4260    pub ignore: bool,
4261    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4262    #[serde(default)]
4263    pub source_alias: Option<Identifier>,
4264    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4265    #[serde(default)]
4266    pub alias: Option<Identifier>,
4267    /// Whether the alias uses explicit AS keyword
4268    #[serde(default)]
4269    pub alias_explicit_as: bool,
4270    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4271    #[serde(default)]
4272    pub default_values: bool,
4273    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4274    #[serde(default)]
4275    pub by_name: bool,
4276    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4277    #[serde(default, skip_serializing_if = "Option::is_none")]
4278    pub conflict_action: Option<String>,
4279    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4280    #[serde(default)]
4281    pub is_replace: bool,
4282    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4283    #[serde(default, skip_serializing_if = "Option::is_none")]
4284    pub hint: Option<Hint>,
4285    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4286    #[serde(default)]
4287    pub replace_where: Option<Box<Expression>>,
4288    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4289    #[serde(default)]
4290    pub source: Option<Box<Expression>>,
4291    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4292    #[serde(default, skip_serializing_if = "Option::is_none")]
4293    pub function_target: Option<Box<Expression>>,
4294    /// ClickHouse: PARTITION BY expr
4295    #[serde(default, skip_serializing_if = "Option::is_none")]
4296    pub partition_by: Option<Box<Expression>>,
4297    /// ClickHouse: SETTINGS key = val, ...
4298    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4299    pub settings: Vec<Expression>,
4300}
4301
4302/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4304#[cfg_attr(feature = "bindings", derive(TS))]
4305pub struct OutputClause {
4306    /// Columns/expressions to output
4307    pub columns: Vec<Expression>,
4308    /// Optional INTO target table or table variable
4309    #[serde(default)]
4310    pub into_table: Option<Expression>,
4311}
4312
4313/// UPDATE statement
4314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4315#[cfg_attr(feature = "bindings", derive(TS))]
4316pub struct Update {
4317    pub table: TableRef,
4318    #[serde(default)]
4319    pub hint: Option<Hint>,
4320    /// Additional tables for multi-table UPDATE (MySQL syntax)
4321    #[serde(default)]
4322    pub extra_tables: Vec<TableRef>,
4323    /// JOINs attached to the table list (MySQL multi-table syntax)
4324    #[serde(default)]
4325    pub table_joins: Vec<Join>,
4326    pub set: Vec<(Identifier, Expression)>,
4327    pub from_clause: Option<From>,
4328    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4329    #[serde(default)]
4330    pub from_joins: Vec<Join>,
4331    pub where_clause: Option<Where>,
4332    /// RETURNING clause (PostgreSQL, SQLite)
4333    #[serde(default)]
4334    pub returning: Vec<Expression>,
4335    /// OUTPUT clause (TSQL)
4336    #[serde(default)]
4337    pub output: Option<OutputClause>,
4338    /// WITH clause (CTEs)
4339    #[serde(default)]
4340    pub with: Option<With>,
4341    /// Leading comments before the statement
4342    #[serde(default)]
4343    pub leading_comments: Vec<String>,
4344    /// LIMIT clause (MySQL)
4345    #[serde(default)]
4346    pub limit: Option<Expression>,
4347    /// ORDER BY clause (MySQL)
4348    #[serde(default)]
4349    pub order_by: Option<OrderBy>,
4350    /// Whether FROM clause appears before SET (Snowflake syntax)
4351    #[serde(default)]
4352    pub from_before_set: bool,
4353}
4354
4355/// DELETE statement
4356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4357#[cfg_attr(feature = "bindings", derive(TS))]
4358pub struct Delete {
4359    pub table: TableRef,
4360    #[serde(default)]
4361    pub hint: Option<Hint>,
4362    /// ClickHouse: ON CLUSTER clause for distributed DDL
4363    #[serde(default, skip_serializing_if = "Option::is_none")]
4364    pub on_cluster: Option<OnCluster>,
4365    /// Optional alias for the table
4366    pub alias: Option<Identifier>,
4367    /// Whether the alias was declared with explicit AS keyword
4368    #[serde(default)]
4369    pub alias_explicit_as: bool,
4370    /// PostgreSQL/DuckDB USING clause - additional tables to join
4371    pub using: Vec<TableRef>,
4372    pub where_clause: Option<Where>,
4373    /// OUTPUT clause (TSQL)
4374    #[serde(default)]
4375    pub output: Option<OutputClause>,
4376    /// Leading comments before the statement
4377    #[serde(default)]
4378    pub leading_comments: Vec<String>,
4379    /// WITH clause (CTEs)
4380    #[serde(default)]
4381    pub with: Option<With>,
4382    /// LIMIT clause (MySQL)
4383    #[serde(default)]
4384    pub limit: Option<Expression>,
4385    /// ORDER BY clause (MySQL)
4386    #[serde(default)]
4387    pub order_by: Option<OrderBy>,
4388    /// RETURNING clause (PostgreSQL)
4389    #[serde(default)]
4390    pub returning: Vec<Expression>,
4391    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4392    /// These are the target tables to delete from
4393    #[serde(default)]
4394    pub tables: Vec<TableRef>,
4395    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4396    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4397    #[serde(default)]
4398    pub tables_from_using: bool,
4399    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4400    #[serde(default)]
4401    pub joins: Vec<Join>,
4402    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4403    #[serde(default)]
4404    pub force_index: Option<String>,
4405    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4406    #[serde(default)]
4407    pub no_from: bool,
4408}
4409
4410/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4412#[cfg_attr(feature = "bindings", derive(TS))]
4413pub struct CopyStmt {
4414    /// Target table or query
4415    pub this: Expression,
4416    /// True for FROM (loading into table), false for TO (exporting)
4417    pub kind: bool,
4418    /// Source/destination file(s) or stage
4419    pub files: Vec<Expression>,
4420    /// Copy parameters
4421    #[serde(default)]
4422    pub params: Vec<CopyParameter>,
4423    /// Credentials for external access
4424    #[serde(default)]
4425    pub credentials: Option<Box<Credentials>>,
4426    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4427    #[serde(default)]
4428    pub is_into: bool,
4429    /// Whether parameters are wrapped in WITH (...) syntax
4430    #[serde(default)]
4431    pub with_wrapped: bool,
4432}
4433
4434/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4436#[cfg_attr(feature = "bindings", derive(TS))]
4437pub struct CopyParameter {
4438    pub name: String,
4439    pub value: Option<Expression>,
4440    pub values: Vec<Expression>,
4441    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4442    #[serde(default)]
4443    pub eq: bool,
4444}
4445
4446/// Credentials for external access (S3, Azure, etc.)
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct Credentials {
4450    pub credentials: Vec<(String, String)>,
4451    pub encryption: Option<String>,
4452    pub storage: Option<String>,
4453}
4454
4455/// PUT statement (Snowflake)
4456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4457#[cfg_attr(feature = "bindings", derive(TS))]
4458pub struct PutStmt {
4459    /// Source file path
4460    pub source: String,
4461    /// Whether source was quoted in the original SQL
4462    #[serde(default)]
4463    pub source_quoted: bool,
4464    /// Target stage
4465    pub target: Expression,
4466    /// PUT parameters
4467    #[serde(default)]
4468    pub params: Vec<CopyParameter>,
4469}
4470
4471/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4473#[cfg_attr(feature = "bindings", derive(TS))]
4474pub struct StageReference {
4475    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4476    pub name: String,
4477    /// Optional path within the stage (e.g., "/path/to/file.csv")
4478    #[serde(default)]
4479    pub path: Option<String>,
4480    /// Optional FILE_FORMAT parameter
4481    #[serde(default)]
4482    pub file_format: Option<Expression>,
4483    /// Optional PATTERN parameter
4484    #[serde(default)]
4485    pub pattern: Option<String>,
4486    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4487    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4488    pub quoted: bool,
4489}
4490
4491/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4493#[cfg_attr(feature = "bindings", derive(TS))]
4494pub struct HistoricalData {
4495    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4496    pub this: Box<Expression>,
4497    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4498    pub kind: String,
4499    /// The expression value (e.g., the statement ID or timestamp)
4500    pub expression: Box<Expression>,
4501}
4502
4503/// Represent an aliased expression (`expr AS name`).
4504///
4505/// Used for column aliases in select-lists, table aliases on subqueries,
4506/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct Alias {
4510    /// The expression being aliased.
4511    pub this: Expression,
4512    /// The alias name (required for simple aliases, optional when only column aliases provided)
4513    pub alias: Identifier,
4514    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4515    #[serde(default)]
4516    pub column_aliases: Vec<Identifier>,
4517    /// Whether AS keyword was explicitly used for the alias.
4518    #[serde(default)]
4519    pub alias_explicit_as: bool,
4520    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4521    #[serde(skip_serializing_if = "Option::is_none", default)]
4522    pub alias_keyword: Option<String>,
4523    /// Comments that appeared between the expression and AS keyword
4524    #[serde(default)]
4525    pub pre_alias_comments: Vec<String>,
4526    /// Trailing comments that appeared after the alias
4527    #[serde(default)]
4528    pub trailing_comments: Vec<String>,
4529    /// Inferred data type from type annotation
4530    #[serde(default, skip_serializing_if = "Option::is_none")]
4531    pub inferred_type: Option<DataType>,
4532}
4533
4534impl Alias {
4535    /// Create a simple alias
4536    pub fn new(this: Expression, alias: Identifier) -> Self {
4537        Self {
4538            this,
4539            alias,
4540            column_aliases: Vec::new(),
4541            alias_explicit_as: false,
4542            alias_keyword: None,
4543            pre_alias_comments: Vec::new(),
4544            trailing_comments: Vec::new(),
4545            inferred_type: None,
4546        }
4547    }
4548
4549    /// Create an alias with column aliases only (no table alias name)
4550    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4551        Self {
4552            this,
4553            alias: Identifier::empty(),
4554            column_aliases,
4555            alias_explicit_as: false,
4556            alias_keyword: None,
4557            pre_alias_comments: Vec::new(),
4558            trailing_comments: Vec::new(),
4559            inferred_type: None,
4560        }
4561    }
4562}
4563
4564/// Represent a type cast expression.
4565///
4566/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4567/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4568/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4569/// CONVERSION ERROR (Oracle) clauses.
4570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4571#[cfg_attr(feature = "bindings", derive(TS))]
4572pub struct Cast {
4573    /// The expression being cast.
4574    pub this: Expression,
4575    /// The target data type.
4576    pub to: DataType,
4577    #[serde(default)]
4578    pub trailing_comments: Vec<String>,
4579    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4580    #[serde(default)]
4581    pub double_colon_syntax: bool,
4582    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4583    #[serde(skip_serializing_if = "Option::is_none", default)]
4584    pub format: Option<Box<Expression>>,
4585    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4586    #[serde(skip_serializing_if = "Option::is_none", default)]
4587    pub default: Option<Box<Expression>>,
4588    /// Inferred data type from type annotation
4589    #[serde(default, skip_serializing_if = "Option::is_none")]
4590    pub inferred_type: Option<DataType>,
4591}
4592
4593///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4595#[cfg_attr(feature = "bindings", derive(TS))]
4596pub struct CollationExpr {
4597    pub this: Expression,
4598    pub collation: String,
4599    /// True if the collation was single-quoted in the original SQL (string literal)
4600    #[serde(default)]
4601    pub quoted: bool,
4602    /// True if the collation was double-quoted in the original SQL (identifier)
4603    #[serde(default)]
4604    pub double_quoted: bool,
4605}
4606
4607/// Represent a CASE expression (both simple and searched forms).
4608///
4609/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4610/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4611/// Each entry in `whens` is a `(condition, result)` pair.
4612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4613#[cfg_attr(feature = "bindings", derive(TS))]
4614pub struct Case {
4615    /// The operand for simple CASE, or `None` for searched CASE.
4616    pub operand: Option<Expression>,
4617    /// Pairs of (WHEN condition, THEN result).
4618    pub whens: Vec<(Expression, Expression)>,
4619    /// Optional ELSE result.
4620    pub else_: Option<Expression>,
4621    /// Comments from the CASE keyword (emitted after END)
4622    #[serde(default)]
4623    #[serde(skip_serializing_if = "Vec::is_empty")]
4624    pub comments: Vec<String>,
4625    /// Inferred data type from type annotation
4626    #[serde(default, skip_serializing_if = "Option::is_none")]
4627    pub inferred_type: Option<DataType>,
4628}
4629
4630/// Represent a binary operation (two operands separated by an operator).
4631///
4632/// This is the shared payload struct for all binary operator variants in the
4633/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4634/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4635/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4636/// preservation of inline comments around operators.
4637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4638#[cfg_attr(feature = "bindings", derive(TS))]
4639pub struct BinaryOp {
4640    pub left: Expression,
4641    pub right: Expression,
4642    /// Comments after the left operand (before the operator)
4643    #[serde(default)]
4644    pub left_comments: Vec<String>,
4645    /// Comments after the operator (before the right operand)
4646    #[serde(default)]
4647    pub operator_comments: Vec<String>,
4648    /// Comments after the right operand
4649    #[serde(default)]
4650    pub trailing_comments: Vec<String>,
4651    /// Inferred data type from type annotation
4652    #[serde(default, skip_serializing_if = "Option::is_none")]
4653    pub inferred_type: Option<DataType>,
4654}
4655
4656impl BinaryOp {
4657    pub fn new(left: Expression, right: Expression) -> Self {
4658        Self {
4659            left,
4660            right,
4661            left_comments: Vec::new(),
4662            operator_comments: Vec::new(),
4663            trailing_comments: Vec::new(),
4664            inferred_type: None,
4665        }
4666    }
4667}
4668
4669/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4671#[cfg_attr(feature = "bindings", derive(TS))]
4672pub struct LikeOp {
4673    pub left: Expression,
4674    pub right: Expression,
4675    /// ESCAPE character/expression
4676    #[serde(default)]
4677    pub escape: Option<Expression>,
4678    /// Quantifier: ANY, ALL, or SOME
4679    #[serde(default)]
4680    pub quantifier: Option<String>,
4681    /// Inferred data type from type annotation
4682    #[serde(default, skip_serializing_if = "Option::is_none")]
4683    pub inferred_type: Option<DataType>,
4684}
4685
4686impl LikeOp {
4687    pub fn new(left: Expression, right: Expression) -> Self {
4688        Self {
4689            left,
4690            right,
4691            escape: None,
4692            quantifier: None,
4693            inferred_type: None,
4694        }
4695    }
4696
4697    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4698        Self {
4699            left,
4700            right,
4701            escape: Some(escape),
4702            quantifier: None,
4703            inferred_type: None,
4704        }
4705    }
4706}
4707
4708/// Represent a unary operation (single operand with a prefix operator).
4709///
4710/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4712#[cfg_attr(feature = "bindings", derive(TS))]
4713pub struct UnaryOp {
4714    /// The operand expression.
4715    pub this: Expression,
4716    /// Inferred data type from type annotation
4717    #[serde(default, skip_serializing_if = "Option::is_none")]
4718    pub inferred_type: Option<DataType>,
4719}
4720
4721impl UnaryOp {
4722    pub fn new(this: Expression) -> Self {
4723        Self {
4724            this,
4725            inferred_type: None,
4726        }
4727    }
4728}
4729
4730/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4731///
4732/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4733/// but not both. When `not` is true, the predicate is `NOT IN`.
4734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4735#[cfg_attr(feature = "bindings", derive(TS))]
4736pub struct In {
4737    /// The expression being tested.
4738    pub this: Expression,
4739    /// The value list (mutually exclusive with `query`).
4740    pub expressions: Vec<Expression>,
4741    /// A subquery (mutually exclusive with `expressions`).
4742    pub query: Option<Expression>,
4743    /// Whether this is NOT IN.
4744    pub not: bool,
4745    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4746    pub global: bool,
4747    /// BigQuery: IN UNNEST(expr)
4748    #[serde(default, skip_serializing_if = "Option::is_none")]
4749    pub unnest: Option<Box<Expression>>,
4750    /// Whether the right side is a bare field reference (no parentheses).
4751    /// Matches Python sqlglot's `field` attribute on `In` expression.
4752    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4753    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4754    pub is_field: bool,
4755}
4756
4757/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4759#[cfg_attr(feature = "bindings", derive(TS))]
4760pub struct Between {
4761    /// The expression being tested.
4762    pub this: Expression,
4763    /// The lower bound.
4764    pub low: Expression,
4765    /// The upper bound.
4766    pub high: Expression,
4767    /// Whether this is NOT BETWEEN.
4768    pub not: bool,
4769    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4770    #[serde(default)]
4771    pub symmetric: Option<bool>,
4772}
4773
4774/// IS NULL predicate
4775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4776#[cfg_attr(feature = "bindings", derive(TS))]
4777pub struct IsNull {
4778    pub this: Expression,
4779    pub not: bool,
4780    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4781    #[serde(default)]
4782    pub postfix_form: bool,
4783}
4784
4785/// IS TRUE / IS FALSE predicate
4786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4787#[cfg_attr(feature = "bindings", derive(TS))]
4788pub struct IsTrueFalse {
4789    pub this: Expression,
4790    pub not: bool,
4791}
4792
4793/// IS JSON predicate (SQL standard)
4794/// Checks if a value is valid JSON
4795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4796#[cfg_attr(feature = "bindings", derive(TS))]
4797pub struct IsJson {
4798    pub this: Expression,
4799    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4800    pub json_type: Option<String>,
4801    /// Key uniqueness constraint
4802    pub unique_keys: Option<JsonUniqueKeys>,
4803    /// Whether IS NOT JSON
4804    pub negated: bool,
4805}
4806
4807/// JSON unique keys constraint variants
4808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4809#[cfg_attr(feature = "bindings", derive(TS))]
4810pub enum JsonUniqueKeys {
4811    /// WITH UNIQUE KEYS
4812    With,
4813    /// WITHOUT UNIQUE KEYS
4814    Without,
4815    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4816    Shorthand,
4817}
4818
4819/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4821#[cfg_attr(feature = "bindings", derive(TS))]
4822pub struct Exists {
4823    /// The subquery expression.
4824    pub this: Expression,
4825    /// Whether this is NOT EXISTS.
4826    pub not: bool,
4827}
4828
4829/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4830///
4831/// This is the generic function node. Well-known aggregates, window functions,
4832/// and built-in functions each have their own dedicated `Expression` variants
4833/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4834/// not recognize as built-ins are represented with this struct.
4835#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4836#[cfg_attr(feature = "bindings", derive(TS))]
4837pub struct Function {
4838    /// The function name, as originally written (may be schema-qualified).
4839    pub name: String,
4840    /// Positional arguments to the function.
4841    pub args: Vec<Expression>,
4842    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4843    pub distinct: bool,
4844    #[serde(default)]
4845    pub trailing_comments: Vec<String>,
4846    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4847    #[serde(default)]
4848    pub use_bracket_syntax: bool,
4849    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4850    #[serde(default)]
4851    pub no_parens: bool,
4852    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4853    #[serde(default)]
4854    pub quoted: bool,
4855    /// Source position span
4856    #[serde(default, skip_serializing_if = "Option::is_none")]
4857    pub span: Option<Span>,
4858    /// Inferred data type from type annotation
4859    #[serde(default, skip_serializing_if = "Option::is_none")]
4860    pub inferred_type: Option<DataType>,
4861}
4862
4863impl Default for Function {
4864    fn default() -> Self {
4865        Self {
4866            name: String::new(),
4867            args: Vec::new(),
4868            distinct: false,
4869            trailing_comments: Vec::new(),
4870            use_bracket_syntax: false,
4871            no_parens: false,
4872            quoted: false,
4873            span: None,
4874            inferred_type: None,
4875        }
4876    }
4877}
4878
4879impl Function {
4880    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4881        Self {
4882            name: name.into(),
4883            args,
4884            distinct: false,
4885            trailing_comments: Vec::new(),
4886            use_bracket_syntax: false,
4887            no_parens: false,
4888            quoted: false,
4889            span: None,
4890            inferred_type: None,
4891        }
4892    }
4893}
4894
4895/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4896///
4897/// This struct is used for aggregate function calls that are not covered by
4898/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4899/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4900/// IGNORE NULLS / RESPECT NULLS modifiers.
4901#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4902#[cfg_attr(feature = "bindings", derive(TS))]
4903pub struct AggregateFunction {
4904    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4905    pub name: String,
4906    /// Positional arguments.
4907    pub args: Vec<Expression>,
4908    /// Whether DISTINCT was specified.
4909    pub distinct: bool,
4910    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4911    pub filter: Option<Expression>,
4912    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4913    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4914    pub order_by: Vec<Ordered>,
4915    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4916    #[serde(default, skip_serializing_if = "Option::is_none")]
4917    pub limit: Option<Box<Expression>>,
4918    /// IGNORE NULLS / RESPECT NULLS
4919    #[serde(default, skip_serializing_if = "Option::is_none")]
4920    pub ignore_nulls: Option<bool>,
4921    /// Inferred data type from type annotation
4922    #[serde(default, skip_serializing_if = "Option::is_none")]
4923    pub inferred_type: Option<DataType>,
4924}
4925
4926/// Represent a window function call with its OVER clause.
4927///
4928/// The inner `this` expression is typically a window-specific expression
4929/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4930/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4931/// frame specification.
4932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4933#[cfg_attr(feature = "bindings", derive(TS))]
4934pub struct WindowFunction {
4935    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4936    pub this: Expression,
4937    /// The OVER clause defining the window partitioning, ordering, and frame.
4938    pub over: Over,
4939    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4940    #[serde(default, skip_serializing_if = "Option::is_none")]
4941    pub keep: Option<Keep>,
4942    /// Inferred data type from type annotation
4943    #[serde(default, skip_serializing_if = "Option::is_none")]
4944    pub inferred_type: Option<DataType>,
4945}
4946
4947/// Oracle KEEP clause for aggregate functions
4948/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4950#[cfg_attr(feature = "bindings", derive(TS))]
4951pub struct Keep {
4952    /// true = FIRST, false = LAST
4953    pub first: bool,
4954    /// ORDER BY clause inside KEEP
4955    pub order_by: Vec<Ordered>,
4956}
4957
4958/// WITHIN GROUP clause (for ordered-set aggregate functions)
4959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4960#[cfg_attr(feature = "bindings", derive(TS))]
4961pub struct WithinGroup {
4962    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4963    pub this: Expression,
4964    /// The ORDER BY clause within the group
4965    pub order_by: Vec<Ordered>,
4966}
4967
4968/// Represent the FROM clause of a SELECT statement.
4969///
4970/// Contains one or more table sources (tables, subqueries, table-valued
4971/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4973#[cfg_attr(feature = "bindings", derive(TS))]
4974pub struct From {
4975    /// The table source expressions.
4976    pub expressions: Vec<Expression>,
4977}
4978
4979/// Represent a JOIN clause between two table sources.
4980///
4981/// The join condition can be specified via `on` (ON predicate) or `using`
4982/// (USING column list), but not both. The `kind` field determines the join
4983/// type (INNER, LEFT, CROSS, etc.).
4984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4985#[cfg_attr(feature = "bindings", derive(TS))]
4986pub struct Join {
4987    /// The right-hand table expression being joined.
4988    pub this: Expression,
4989    /// The ON condition (mutually exclusive with `using`).
4990    pub on: Option<Expression>,
4991    /// The USING column list (mutually exclusive with `on`).
4992    pub using: Vec<Identifier>,
4993    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4994    pub kind: JoinKind,
4995    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4996    pub use_inner_keyword: bool,
4997    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4998    pub use_outer_keyword: bool,
4999    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
5000    pub deferred_condition: bool,
5001    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
5002    #[serde(default, skip_serializing_if = "Option::is_none")]
5003    pub join_hint: Option<String>,
5004    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
5005    #[serde(default, skip_serializing_if = "Option::is_none")]
5006    pub match_condition: Option<Expression>,
5007    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
5008    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5009    pub pivots: Vec<Expression>,
5010    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
5011    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5012    pub comments: Vec<String>,
5013    /// Nesting group identifier for nested join pretty-printing.
5014    /// Joins in the same group were parsed together; group boundaries come from
5015    /// deferred condition resolution phases.
5016    #[serde(default)]
5017    pub nesting_group: usize,
5018    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
5019    #[serde(default)]
5020    pub directed: bool,
5021}
5022
5023/// Enumerate all supported SQL join types.
5024///
5025/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
5026/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
5027/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
5028/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
5029#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5030#[cfg_attr(feature = "bindings", derive(TS))]
5031pub enum JoinKind {
5032    Inner,
5033    Left,
5034    Right,
5035    Full,
5036    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5037    Cross,
5038    Natural,
5039    NaturalLeft,
5040    NaturalRight,
5041    NaturalFull,
5042    Semi,
5043    Anti,
5044    // Directional SEMI/ANTI joins
5045    LeftSemi,
5046    LeftAnti,
5047    RightSemi,
5048    RightAnti,
5049    // SQL Server specific
5050    CrossApply,
5051    OuterApply,
5052    // Time-series specific
5053    AsOf,
5054    AsOfLeft,
5055    AsOfRight,
5056    // Lateral join
5057    Lateral,
5058    LeftLateral,
5059    // MySQL specific
5060    Straight,
5061    // Implicit join (comma-separated tables: FROM a, b)
5062    Implicit,
5063    // ClickHouse ARRAY JOIN
5064    Array,
5065    LeftArray,
5066    // ClickHouse PASTE JOIN (positional join)
5067    Paste,
5068    // DuckDB POSITIONAL JOIN
5069    Positional,
5070}
5071
5072impl Default for JoinKind {
5073    fn default() -> Self {
5074        JoinKind::Inner
5075    }
5076}
5077
5078/// Parenthesized table expression with joins
5079/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5081#[cfg_attr(feature = "bindings", derive(TS))]
5082pub struct JoinedTable {
5083    /// The left-hand side table expression
5084    pub left: Expression,
5085    /// The joins applied to the left table
5086    pub joins: Vec<Join>,
5087    /// LATERAL VIEW clauses (Hive/Spark)
5088    pub lateral_views: Vec<LateralView>,
5089    /// Optional alias for the joined table expression
5090    pub alias: Option<Identifier>,
5091}
5092
5093/// Represent a WHERE clause containing a boolean filter predicate.
5094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5095#[cfg_attr(feature = "bindings", derive(TS))]
5096pub struct Where {
5097    /// The filter predicate expression.
5098    pub this: Expression,
5099}
5100
5101/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5102///
5103/// The `expressions` list may contain plain columns, ordinal positions,
5104/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5106#[cfg_attr(feature = "bindings", derive(TS))]
5107pub struct GroupBy {
5108    /// The grouping expressions.
5109    pub expressions: Vec<Expression>,
5110    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5111    #[serde(default)]
5112    pub all: Option<bool>,
5113    /// ClickHouse: WITH TOTALS modifier
5114    #[serde(default)]
5115    pub totals: bool,
5116    /// Leading comments that appeared before the GROUP BY keyword
5117    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5118    pub comments: Vec<String>,
5119}
5120
5121/// Represent a HAVING clause containing a predicate over aggregate results.
5122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5123#[cfg_attr(feature = "bindings", derive(TS))]
5124pub struct Having {
5125    /// The filter predicate, typically involving aggregate functions.
5126    pub this: Expression,
5127    /// Leading comments that appeared before the HAVING keyword
5128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5129    pub comments: Vec<String>,
5130}
5131
5132/// Represent an ORDER BY clause containing one or more sort specifications.
5133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5134#[cfg_attr(feature = "bindings", derive(TS))]
5135pub struct OrderBy {
5136    /// The sort specifications, each with direction and null ordering.
5137    pub expressions: Vec<Ordered>,
5138    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5139    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5140    pub siblings: bool,
5141    /// Leading comments that appeared before the ORDER BY keyword
5142    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5143    pub comments: Vec<String>,
5144}
5145
5146/// Represent an expression with sort direction and null ordering.
5147///
5148/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5149/// When `desc` is false the sort is ascending. The `nulls_first` field
5150/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5151/// (database default).
5152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5153#[cfg_attr(feature = "bindings", derive(TS))]
5154pub struct Ordered {
5155    /// The expression to sort by.
5156    pub this: Expression,
5157    /// Whether the sort direction is descending (true) or ascending (false).
5158    pub desc: bool,
5159    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5160    pub nulls_first: Option<bool>,
5161    /// Whether ASC was explicitly written (not just implied)
5162    #[serde(default)]
5163    pub explicit_asc: bool,
5164    /// ClickHouse WITH FILL clause
5165    #[serde(default, skip_serializing_if = "Option::is_none")]
5166    pub with_fill: Option<Box<WithFill>>,
5167}
5168
5169impl Ordered {
5170    pub fn asc(expr: Expression) -> Self {
5171        Self {
5172            this: expr,
5173            desc: false,
5174            nulls_first: None,
5175            explicit_asc: false,
5176            with_fill: None,
5177        }
5178    }
5179
5180    pub fn desc(expr: Expression) -> Self {
5181        Self {
5182            this: expr,
5183            desc: true,
5184            nulls_first: None,
5185            explicit_asc: false,
5186            with_fill: None,
5187        }
5188    }
5189}
5190
5191/// DISTRIBUTE BY clause (Hive/Spark)
5192/// Controls how rows are distributed across reducers
5193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5194#[cfg_attr(feature = "bindings", derive(TS))]
5195#[cfg_attr(feature = "bindings", ts(export))]
5196pub struct DistributeBy {
5197    pub expressions: Vec<Expression>,
5198}
5199
5200/// CLUSTER BY clause (Hive/Spark)
5201/// Combines DISTRIBUTE BY and SORT BY on the same columns
5202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5203#[cfg_attr(feature = "bindings", derive(TS))]
5204#[cfg_attr(feature = "bindings", ts(export))]
5205pub struct ClusterBy {
5206    pub expressions: Vec<Ordered>,
5207}
5208
5209/// SORT BY clause (Hive/Spark)
5210/// Sorts data within each reducer (local sort, not global)
5211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5212#[cfg_attr(feature = "bindings", derive(TS))]
5213#[cfg_attr(feature = "bindings", ts(export))]
5214pub struct SortBy {
5215    pub expressions: Vec<Ordered>,
5216}
5217
5218/// LATERAL VIEW clause (Hive/Spark)
5219/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5221#[cfg_attr(feature = "bindings", derive(TS))]
5222#[cfg_attr(feature = "bindings", ts(export))]
5223pub struct LateralView {
5224    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5225    pub this: Expression,
5226    /// Table alias for the generated table
5227    pub table_alias: Option<Identifier>,
5228    /// Column aliases for the generated columns
5229    pub column_aliases: Vec<Identifier>,
5230    /// OUTER keyword - preserve nulls when input is empty/null
5231    pub outer: bool,
5232}
5233
5234/// Query hint
5235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5236#[cfg_attr(feature = "bindings", derive(TS))]
5237#[cfg_attr(feature = "bindings", ts(export))]
5238pub struct Hint {
5239    pub expressions: Vec<HintExpression>,
5240}
5241
5242/// Individual hint expression
5243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5244#[cfg_attr(feature = "bindings", derive(TS))]
5245#[cfg_attr(feature = "bindings", ts(export))]
5246pub enum HintExpression {
5247    /// Function-style hint: USE_HASH(table)
5248    Function { name: String, args: Vec<Expression> },
5249    /// Simple identifier hint: PARALLEL
5250    Identifier(String),
5251    /// Raw hint text (unparsed)
5252    Raw(String),
5253}
5254
5255/// Pseudocolumn type
5256#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5257#[cfg_attr(feature = "bindings", derive(TS))]
5258#[cfg_attr(feature = "bindings", ts(export))]
5259pub enum PseudocolumnType {
5260    Rownum,      // Oracle ROWNUM
5261    Rowid,       // Oracle ROWID
5262    Level,       // Oracle LEVEL (for CONNECT BY)
5263    Sysdate,     // Oracle SYSDATE
5264    ObjectId,    // Oracle OBJECT_ID
5265    ObjectValue, // Oracle OBJECT_VALUE
5266}
5267
5268impl PseudocolumnType {
5269    pub fn as_str(&self) -> &'static str {
5270        match self {
5271            PseudocolumnType::Rownum => "ROWNUM",
5272            PseudocolumnType::Rowid => "ROWID",
5273            PseudocolumnType::Level => "LEVEL",
5274            PseudocolumnType::Sysdate => "SYSDATE",
5275            PseudocolumnType::ObjectId => "OBJECT_ID",
5276            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5277        }
5278    }
5279
5280    pub fn from_str(s: &str) -> Option<Self> {
5281        match s.to_uppercase().as_str() {
5282            "ROWNUM" => Some(PseudocolumnType::Rownum),
5283            "ROWID" => Some(PseudocolumnType::Rowid),
5284            "LEVEL" => Some(PseudocolumnType::Level),
5285            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5286            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5287            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5288            _ => None,
5289        }
5290    }
5291}
5292
5293/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5294/// These are special identifiers that should not be quoted
5295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5296#[cfg_attr(feature = "bindings", derive(TS))]
5297#[cfg_attr(feature = "bindings", ts(export))]
5298pub struct Pseudocolumn {
5299    pub kind: PseudocolumnType,
5300}
5301
5302impl Pseudocolumn {
5303    pub fn rownum() -> Self {
5304        Self {
5305            kind: PseudocolumnType::Rownum,
5306        }
5307    }
5308
5309    pub fn rowid() -> Self {
5310        Self {
5311            kind: PseudocolumnType::Rowid,
5312        }
5313    }
5314
5315    pub fn level() -> Self {
5316        Self {
5317            kind: PseudocolumnType::Level,
5318        }
5319    }
5320}
5321
5322/// Oracle CONNECT BY clause for hierarchical queries
5323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5324#[cfg_attr(feature = "bindings", derive(TS))]
5325#[cfg_attr(feature = "bindings", ts(export))]
5326pub struct Connect {
5327    /// START WITH condition (optional, can come before or after CONNECT BY)
5328    pub start: Option<Expression>,
5329    /// CONNECT BY condition (required, contains PRIOR references)
5330    pub connect: Expression,
5331    /// NOCYCLE keyword to prevent infinite loops
5332    pub nocycle: bool,
5333}
5334
5335/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5337#[cfg_attr(feature = "bindings", derive(TS))]
5338#[cfg_attr(feature = "bindings", ts(export))]
5339pub struct Prior {
5340    pub this: Expression,
5341}
5342
5343/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5345#[cfg_attr(feature = "bindings", derive(TS))]
5346#[cfg_attr(feature = "bindings", ts(export))]
5347pub struct ConnectByRoot {
5348    pub this: Expression,
5349}
5350
5351/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5353#[cfg_attr(feature = "bindings", derive(TS))]
5354#[cfg_attr(feature = "bindings", ts(export))]
5355pub struct MatchRecognize {
5356    /// Source table/expression
5357    pub this: Option<Box<Expression>>,
5358    /// PARTITION BY expressions
5359    pub partition_by: Option<Vec<Expression>>,
5360    /// ORDER BY expressions
5361    pub order_by: Option<Vec<Ordered>>,
5362    /// MEASURES definitions
5363    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5364    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5365    pub rows: Option<MatchRecognizeRows>,
5366    /// AFTER MATCH SKIP behavior
5367    pub after: Option<MatchRecognizeAfter>,
5368    /// PATTERN definition (stored as raw string for complex regex patterns)
5369    pub pattern: Option<String>,
5370    /// DEFINE clauses (pattern variable definitions)
5371    pub define: Option<Vec<(Identifier, Expression)>>,
5372    /// Optional alias for the result
5373    pub alias: Option<Identifier>,
5374    /// Whether AS keyword was explicitly present before alias
5375    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5376    pub alias_explicit_as: bool,
5377}
5378
5379/// MEASURES expression with optional RUNNING/FINAL semantics
5380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5381#[cfg_attr(feature = "bindings", derive(TS))]
5382#[cfg_attr(feature = "bindings", ts(export))]
5383pub struct MatchRecognizeMeasure {
5384    /// The measure expression
5385    pub this: Expression,
5386    /// RUNNING or FINAL semantics (Snowflake-specific)
5387    pub window_frame: Option<MatchRecognizeSemantics>,
5388}
5389
5390/// Semantics for MEASURES in MATCH_RECOGNIZE
5391#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5392#[cfg_attr(feature = "bindings", derive(TS))]
5393#[cfg_attr(feature = "bindings", ts(export))]
5394pub enum MatchRecognizeSemantics {
5395    Running,
5396    Final,
5397}
5398
5399/// Row output semantics for MATCH_RECOGNIZE
5400#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5401#[cfg_attr(feature = "bindings", derive(TS))]
5402#[cfg_attr(feature = "bindings", ts(export))]
5403pub enum MatchRecognizeRows {
5404    OneRowPerMatch,
5405    AllRowsPerMatch,
5406    AllRowsPerMatchShowEmptyMatches,
5407    AllRowsPerMatchOmitEmptyMatches,
5408    AllRowsPerMatchWithUnmatchedRows,
5409}
5410
5411/// AFTER MATCH SKIP behavior
5412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5413#[cfg_attr(feature = "bindings", derive(TS))]
5414#[cfg_attr(feature = "bindings", ts(export))]
5415pub enum MatchRecognizeAfter {
5416    PastLastRow,
5417    ToNextRow,
5418    ToFirst(Identifier),
5419    ToLast(Identifier),
5420}
5421
5422/// Represent a LIMIT clause that restricts the number of returned rows.
5423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5424#[cfg_attr(feature = "bindings", derive(TS))]
5425pub struct Limit {
5426    /// The limit count expression.
5427    pub this: Expression,
5428    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5429    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5430    pub percent: bool,
5431    /// Comments from before the LIMIT keyword (emitted after the limit value)
5432    #[serde(default)]
5433    #[serde(skip_serializing_if = "Vec::is_empty")]
5434    pub comments: Vec<String>,
5435}
5436
5437/// OFFSET clause
5438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5439#[cfg_attr(feature = "bindings", derive(TS))]
5440pub struct Offset {
5441    pub this: Expression,
5442    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5443    #[serde(skip_serializing_if = "Option::is_none", default)]
5444    pub rows: Option<bool>,
5445}
5446
5447/// TOP clause (SQL Server)
5448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5449#[cfg_attr(feature = "bindings", derive(TS))]
5450pub struct Top {
5451    pub this: Expression,
5452    pub percent: bool,
5453    pub with_ties: bool,
5454    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5455    #[serde(default)]
5456    pub parenthesized: bool,
5457}
5458
5459/// FETCH FIRST/NEXT clause (SQL standard)
5460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5461#[cfg_attr(feature = "bindings", derive(TS))]
5462pub struct Fetch {
5463    /// FIRST or NEXT
5464    pub direction: String,
5465    /// Count expression (optional)
5466    pub count: Option<Expression>,
5467    /// PERCENT modifier
5468    pub percent: bool,
5469    /// ROWS or ROW keyword present
5470    pub rows: bool,
5471    /// WITH TIES modifier
5472    pub with_ties: bool,
5473}
5474
5475/// Represent a QUALIFY clause for filtering on window function results.
5476///
5477/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5478/// typically references a window function (e.g.
5479/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5481#[cfg_attr(feature = "bindings", derive(TS))]
5482pub struct Qualify {
5483    /// The filter predicate over window function results.
5484    pub this: Expression,
5485}
5486
5487/// SAMPLE / TABLESAMPLE clause
5488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5489#[cfg_attr(feature = "bindings", derive(TS))]
5490pub struct Sample {
5491    pub method: SampleMethod,
5492    pub size: Expression,
5493    pub seed: Option<Expression>,
5494    /// ClickHouse OFFSET expression after SAMPLE size
5495    #[serde(default)]
5496    pub offset: Option<Expression>,
5497    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5498    pub unit_after_size: bool,
5499    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5500    #[serde(default)]
5501    pub use_sample_keyword: bool,
5502    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5503    #[serde(default)]
5504    pub explicit_method: bool,
5505    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5506    #[serde(default)]
5507    pub method_before_size: bool,
5508    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5509    #[serde(default)]
5510    pub use_seed_keyword: bool,
5511    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5512    pub bucket_numerator: Option<Box<Expression>>,
5513    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5514    pub bucket_denominator: Option<Box<Expression>>,
5515    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5516    pub bucket_field: Option<Box<Expression>>,
5517    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5518    #[serde(default)]
5519    pub is_using_sample: bool,
5520    /// Whether the unit was explicitly PERCENT (vs ROWS)
5521    #[serde(default)]
5522    pub is_percent: bool,
5523    /// Whether to suppress method output (for cross-dialect transpilation)
5524    #[serde(default)]
5525    pub suppress_method_output: bool,
5526}
5527
5528/// Sample method
5529#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5530#[cfg_attr(feature = "bindings", derive(TS))]
5531pub enum SampleMethod {
5532    Bernoulli,
5533    System,
5534    Block,
5535    Row,
5536    Percent,
5537    /// Hive bucket sampling
5538    Bucket,
5539    /// DuckDB reservoir sampling
5540    Reservoir,
5541}
5542
5543/// Named window definition (WINDOW w AS (...))
5544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5545#[cfg_attr(feature = "bindings", derive(TS))]
5546pub struct NamedWindow {
5547    pub name: Identifier,
5548    pub spec: Over,
5549}
5550
5551/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5552///
5553/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5554/// that reference themselves. Each CTE is defined in the `ctes` vector and
5555/// can be referenced by name in subsequent CTEs and in the main query body.
5556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5557#[cfg_attr(feature = "bindings", derive(TS))]
5558pub struct With {
5559    /// The list of CTE definitions, in order.
5560    pub ctes: Vec<Cte>,
5561    /// Whether the WITH RECURSIVE keyword was used.
5562    pub recursive: bool,
5563    /// Leading comments before the statement
5564    #[serde(default)]
5565    pub leading_comments: Vec<String>,
5566    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5567    #[serde(default, skip_serializing_if = "Option::is_none")]
5568    pub search: Option<Box<Expression>>,
5569}
5570
5571/// Represent a single Common Table Expression definition.
5572///
5573/// A CTE has a name (`alias`), an optional column list, and a body query.
5574/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5575/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5576/// the expression comes before the alias (`alias_first`).
5577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5578#[cfg_attr(feature = "bindings", derive(TS))]
5579pub struct Cte {
5580    /// The CTE name.
5581    pub alias: Identifier,
5582    /// The CTE body (typically a SELECT, UNION, etc.).
5583    pub this: Expression,
5584    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5585    pub columns: Vec<Identifier>,
5586    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5587    pub materialized: Option<bool>,
5588    /// USING KEY (columns) for DuckDB recursive CTEs
5589    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5590    pub key_expressions: Vec<Identifier>,
5591    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5592    #[serde(default)]
5593    pub alias_first: bool,
5594    /// Comments associated with this CTE (placed after alias name, before AS)
5595    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5596    pub comments: Vec<String>,
5597}
5598
5599/// Window specification
5600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5601#[cfg_attr(feature = "bindings", derive(TS))]
5602pub struct WindowSpec {
5603    pub partition_by: Vec<Expression>,
5604    pub order_by: Vec<Ordered>,
5605    pub frame: Option<WindowFrame>,
5606}
5607
5608/// OVER clause
5609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5610#[cfg_attr(feature = "bindings", derive(TS))]
5611pub struct Over {
5612    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5613    pub window_name: Option<Identifier>,
5614    pub partition_by: Vec<Expression>,
5615    pub order_by: Vec<Ordered>,
5616    pub frame: Option<WindowFrame>,
5617    pub alias: Option<Identifier>,
5618}
5619
5620/// Window frame
5621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5622#[cfg_attr(feature = "bindings", derive(TS))]
5623pub struct WindowFrame {
5624    pub kind: WindowFrameKind,
5625    pub start: WindowFrameBound,
5626    pub end: Option<WindowFrameBound>,
5627    pub exclude: Option<WindowFrameExclude>,
5628    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5629    #[serde(default, skip_serializing_if = "Option::is_none")]
5630    pub kind_text: Option<String>,
5631    /// Original text of the start bound side keyword (e.g. "preceding")
5632    #[serde(default, skip_serializing_if = "Option::is_none")]
5633    pub start_side_text: Option<String>,
5634    /// Original text of the end bound side keyword
5635    #[serde(default, skip_serializing_if = "Option::is_none")]
5636    pub end_side_text: Option<String>,
5637}
5638
5639#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5640#[cfg_attr(feature = "bindings", derive(TS))]
5641pub enum WindowFrameKind {
5642    Rows,
5643    Range,
5644    Groups,
5645}
5646
5647/// EXCLUDE clause for window frames
5648#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5649#[cfg_attr(feature = "bindings", derive(TS))]
5650pub enum WindowFrameExclude {
5651    CurrentRow,
5652    Group,
5653    Ties,
5654    NoOthers,
5655}
5656
5657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5658#[cfg_attr(feature = "bindings", derive(TS))]
5659pub enum WindowFrameBound {
5660    CurrentRow,
5661    UnboundedPreceding,
5662    UnboundedFollowing,
5663    Preceding(Box<Expression>),
5664    Following(Box<Expression>),
5665    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5666    BarePreceding,
5667    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5668    BareFollowing,
5669    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5670    Value(Box<Expression>),
5671}
5672
5673/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5675#[cfg_attr(feature = "bindings", derive(TS))]
5676pub struct StructField {
5677    pub name: String,
5678    pub data_type: DataType,
5679    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5680    pub options: Vec<Expression>,
5681    #[serde(default, skip_serializing_if = "Option::is_none")]
5682    pub comment: Option<String>,
5683}
5684
5685impl StructField {
5686    /// Create a new struct field without options
5687    pub fn new(name: String, data_type: DataType) -> Self {
5688        Self {
5689            name,
5690            data_type,
5691            options: Vec::new(),
5692            comment: None,
5693        }
5694    }
5695
5696    /// Create a new struct field with options
5697    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5698        Self {
5699            name,
5700            data_type,
5701            options,
5702            comment: None,
5703        }
5704    }
5705
5706    /// Create a new struct field with options and comment
5707    pub fn with_options_and_comment(
5708        name: String,
5709        data_type: DataType,
5710        options: Vec<Expression>,
5711        comment: Option<String>,
5712    ) -> Self {
5713        Self {
5714            name,
5715            data_type,
5716            options,
5717            comment,
5718        }
5719    }
5720}
5721
5722/// Enumerate all SQL data types recognized by the parser.
5723///
5724/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5725/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5726/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5727///
5728/// This enum is used in CAST expressions, column definitions, function return
5729/// types, and anywhere a data type specification appears in SQL.
5730///
5731/// Types that do not match any known variant fall through to `Custom { name }`,
5732/// preserving the original type name for round-trip fidelity.
5733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5734#[cfg_attr(feature = "bindings", derive(TS))]
5735#[serde(tag = "data_type", rename_all = "snake_case")]
5736pub enum DataType {
5737    // Numeric
5738    Boolean,
5739    TinyInt {
5740        length: Option<u32>,
5741    },
5742    SmallInt {
5743        length: Option<u32>,
5744    },
5745    /// Int type with optional length. `integer_spelling` indicates whether the original
5746    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5747    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5748    Int {
5749        length: Option<u32>,
5750        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5751        integer_spelling: bool,
5752    },
5753    BigInt {
5754        length: Option<u32>,
5755    },
5756    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5757    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5758    /// preserve the original spelling.
5759    Float {
5760        precision: Option<u32>,
5761        scale: Option<u32>,
5762        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5763        real_spelling: bool,
5764    },
5765    Double {
5766        precision: Option<u32>,
5767        scale: Option<u32>,
5768    },
5769    Decimal {
5770        precision: Option<u32>,
5771        scale: Option<u32>,
5772    },
5773
5774    // String
5775    Char {
5776        length: Option<u32>,
5777    },
5778    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5779    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5780    VarChar {
5781        length: Option<u32>,
5782        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5783        parenthesized_length: bool,
5784    },
5785    /// String type with optional max length (BigQuery STRING(n))
5786    String {
5787        length: Option<u32>,
5788    },
5789    Text,
5790    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5791    TextWithLength {
5792        length: u32,
5793    },
5794
5795    // Binary
5796    Binary {
5797        length: Option<u32>,
5798    },
5799    VarBinary {
5800        length: Option<u32>,
5801    },
5802    Blob,
5803
5804    // Bit
5805    Bit {
5806        length: Option<u32>,
5807    },
5808    VarBit {
5809        length: Option<u32>,
5810    },
5811
5812    // Date/Time
5813    Date,
5814    Time {
5815        precision: Option<u32>,
5816        #[serde(default)]
5817        timezone: bool,
5818    },
5819    Timestamp {
5820        precision: Option<u32>,
5821        timezone: bool,
5822    },
5823    Interval {
5824        unit: Option<String>,
5825        /// For range intervals like INTERVAL DAY TO HOUR
5826        #[serde(default, skip_serializing_if = "Option::is_none")]
5827        to: Option<String>,
5828    },
5829
5830    // JSON
5831    Json,
5832    JsonB,
5833
5834    // UUID
5835    Uuid,
5836
5837    // Array
5838    Array {
5839        element_type: Box<DataType>,
5840        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5841        #[serde(default, skip_serializing_if = "Option::is_none")]
5842        dimension: Option<u32>,
5843    },
5844
5845    /// List type (Materialize): INT LIST, TEXT LIST LIST
5846    /// Uses postfix LIST syntax instead of ARRAY<T>
5847    List {
5848        element_type: Box<DataType>,
5849    },
5850
5851    // Struct/Map
5852    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5853    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5854    Struct {
5855        fields: Vec<StructField>,
5856        nested: bool,
5857    },
5858    Map {
5859        key_type: Box<DataType>,
5860        value_type: Box<DataType>,
5861    },
5862
5863    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5864    Enum {
5865        values: Vec<String>,
5866        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5867        assignments: Vec<Option<String>>,
5868    },
5869
5870    // Set type (MySQL): SET('a', 'b', 'c')
5871    Set {
5872        values: Vec<String>,
5873    },
5874
5875    // Union type (DuckDB): UNION(num INT, str TEXT)
5876    Union {
5877        fields: Vec<(String, DataType)>,
5878    },
5879
5880    // Vector (Snowflake / SingleStore)
5881    Vector {
5882        #[serde(default)]
5883        element_type: Option<Box<DataType>>,
5884        dimension: Option<u32>,
5885    },
5886
5887    // Object (Snowflake structured type)
5888    // fields: Vec of (field_name, field_type, not_null)
5889    Object {
5890        fields: Vec<(String, DataType, bool)>,
5891        modifier: Option<String>,
5892    },
5893
5894    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5895    Nullable {
5896        inner: Box<DataType>,
5897    },
5898
5899    // Custom/User-defined
5900    Custom {
5901        name: String,
5902    },
5903
5904    // Spatial types
5905    Geometry {
5906        subtype: Option<String>,
5907        srid: Option<u32>,
5908    },
5909    Geography {
5910        subtype: Option<String>,
5911        srid: Option<u32>,
5912    },
5913
5914    // Character Set (for CONVERT USING in MySQL)
5915    // Renders as CHAR CHARACTER SET {name} in cast target
5916    CharacterSet {
5917        name: String,
5918    },
5919
5920    // Unknown
5921    Unknown,
5922}
5923
5924/// Array expression
5925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5926#[cfg_attr(feature = "bindings", derive(TS))]
5927#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5928pub struct Array {
5929    pub expressions: Vec<Expression>,
5930}
5931
5932/// Struct expression
5933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5934#[cfg_attr(feature = "bindings", derive(TS))]
5935pub struct Struct {
5936    pub fields: Vec<(Option<String>, Expression)>,
5937}
5938
5939/// Tuple expression
5940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5941#[cfg_attr(feature = "bindings", derive(TS))]
5942pub struct Tuple {
5943    pub expressions: Vec<Expression>,
5944}
5945
5946/// Interval expression
5947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5948#[cfg_attr(feature = "bindings", derive(TS))]
5949pub struct Interval {
5950    /// The value expression (e.g., '1', 5, column_ref)
5951    pub this: Option<Expression>,
5952    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5953    pub unit: Option<IntervalUnitSpec>,
5954}
5955
5956/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5958#[cfg_attr(feature = "bindings", derive(TS))]
5959#[serde(tag = "type", rename_all = "snake_case")]
5960pub enum IntervalUnitSpec {
5961    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5962    Simple {
5963        unit: IntervalUnit,
5964        /// Whether to use plural form (e.g., DAYS vs DAY)
5965        use_plural: bool,
5966    },
5967    /// Interval span (e.g., HOUR TO SECOND)
5968    Span(IntervalSpan),
5969    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5970    /// The start and end can be expressions like function calls with precision
5971    ExprSpan(IntervalSpanExpr),
5972    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5973    Expr(Box<Expression>),
5974}
5975
5976/// Interval span for ranges like HOUR TO SECOND
5977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5978#[cfg_attr(feature = "bindings", derive(TS))]
5979pub struct IntervalSpan {
5980    /// Start unit (e.g., HOUR)
5981    pub this: IntervalUnit,
5982    /// End unit (e.g., SECOND)
5983    pub expression: IntervalUnit,
5984}
5985
5986/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5987/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5989#[cfg_attr(feature = "bindings", derive(TS))]
5990pub struct IntervalSpanExpr {
5991    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5992    pub this: Box<Expression>,
5993    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5994    pub expression: Box<Expression>,
5995}
5996
5997#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5998#[cfg_attr(feature = "bindings", derive(TS))]
5999pub enum IntervalUnit {
6000    Year,
6001    Quarter,
6002    Month,
6003    Week,
6004    Day,
6005    Hour,
6006    Minute,
6007    Second,
6008    Millisecond,
6009    Microsecond,
6010    Nanosecond,
6011}
6012
6013/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
6014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6015#[cfg_attr(feature = "bindings", derive(TS))]
6016pub struct Command {
6017    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
6018    pub this: String,
6019}
6020
6021/// PREPARE statement (PostgreSQL/generic prepared statement definition)
6022/// Syntax: PREPARE name [(type, ...)] AS statement
6023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6024#[cfg_attr(feature = "bindings", derive(TS))]
6025pub struct PrepareStatement {
6026    /// The prepared statement name.
6027    pub name: Identifier,
6028    /// Optional PostgreSQL parameter type list.
6029    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6030    pub parameter_types: Vec<DataType>,
6031    /// The statement to execute when the prepared statement is invoked.
6032    pub statement: Expression,
6033}
6034
6035/// T-SQL TRY/CATCH block.
6036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6037#[cfg_attr(feature = "bindings", derive(TS))]
6038pub struct TryCatch {
6039    /// Statements inside BEGIN TRY ... END TRY.
6040    #[serde(default)]
6041    pub try_body: Vec<Expression>,
6042    /// Statements inside BEGIN CATCH ... END CATCH, when present.
6043    #[serde(default, skip_serializing_if = "Option::is_none")]
6044    pub catch_body: Option<Vec<Expression>>,
6045}
6046
6047/// EXEC/EXECUTE statement (TSQL stored procedure call)
6048/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
6049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6050#[cfg_attr(feature = "bindings", derive(TS))]
6051pub struct ExecuteStatement {
6052    /// The procedure name (can be qualified: schema.proc_name)
6053    pub this: Expression,
6054    /// Named parameters: @param=value pairs
6055    #[serde(default)]
6056    pub parameters: Vec<ExecuteParameter>,
6057    /// Positional prepared statement arguments, used by PostgreSQL EXECUTE name(...).
6058    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6059    pub arguments: Vec<Expression>,
6060    /// Whether this statement represents PostgreSQL-style prepared statement execution.
6061    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6062    pub prepared: bool,
6063    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
6064    #[serde(default, skip_serializing_if = "Option::is_none")]
6065    pub suffix: Option<String>,
6066}
6067
6068/// Named parameter in EXEC statement: @name=value
6069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6070#[cfg_attr(feature = "bindings", derive(TS))]
6071pub struct ExecuteParameter {
6072    /// Parameter name (including @)
6073    pub name: String,
6074    /// Parameter value
6075    pub value: Expression,
6076    /// Whether this is a positional parameter (no = sign)
6077    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6078    pub positional: bool,
6079    /// TSQL OUTPUT modifier on parameter
6080    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6081    pub output: bool,
6082}
6083
6084/// KILL statement (MySQL/MariaDB)
6085/// KILL [CONNECTION | QUERY] <id>
6086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6087#[cfg_attr(feature = "bindings", derive(TS))]
6088pub struct Kill {
6089    /// The target (process ID or connection ID)
6090    pub this: Expression,
6091    /// Optional kind: "CONNECTION" or "QUERY"
6092    pub kind: Option<String>,
6093}
6094
6095/// Snowflake CREATE TASK statement
6096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6097#[cfg_attr(feature = "bindings", derive(TS))]
6098pub struct CreateTask {
6099    pub or_replace: bool,
6100    pub if_not_exists: bool,
6101    /// Task name (possibly qualified: db.schema.task)
6102    pub name: String,
6103    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6104    pub properties: String,
6105    /// The SQL statement body after AS
6106    pub body: Expression,
6107}
6108
6109/// Raw/unparsed SQL
6110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6111#[cfg_attr(feature = "bindings", derive(TS))]
6112pub struct Raw {
6113    pub sql: String,
6114}
6115
6116// ============================================================================
6117// Function expression types
6118// ============================================================================
6119
6120/// Generic unary function (takes a single argument)
6121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6122#[cfg_attr(feature = "bindings", derive(TS))]
6123pub struct UnaryFunc {
6124    pub this: Expression,
6125    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6126    #[serde(skip_serializing_if = "Option::is_none", default)]
6127    pub original_name: Option<String>,
6128    /// Inferred data type from type annotation
6129    #[serde(default, skip_serializing_if = "Option::is_none")]
6130    pub inferred_type: Option<DataType>,
6131}
6132
6133impl UnaryFunc {
6134    /// Create a new UnaryFunc with no original_name
6135    pub fn new(this: Expression) -> Self {
6136        Self {
6137            this,
6138            original_name: None,
6139            inferred_type: None,
6140        }
6141    }
6142
6143    /// Create a new UnaryFunc with an original name for round-trip preservation
6144    pub fn with_name(this: Expression, name: String) -> Self {
6145        Self {
6146            this,
6147            original_name: Some(name),
6148            inferred_type: None,
6149        }
6150    }
6151}
6152
6153/// CHAR/CHR function with multiple args and optional USING charset
6154/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6155/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6157#[cfg_attr(feature = "bindings", derive(TS))]
6158pub struct CharFunc {
6159    pub args: Vec<Expression>,
6160    #[serde(skip_serializing_if = "Option::is_none", default)]
6161    pub charset: Option<String>,
6162    /// Original function name (CHAR or CHR), defaults to CHAR
6163    #[serde(skip_serializing_if = "Option::is_none", default)]
6164    pub name: Option<String>,
6165}
6166
6167/// Generic binary function (takes two arguments)
6168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6169#[cfg_attr(feature = "bindings", derive(TS))]
6170pub struct BinaryFunc {
6171    pub this: Expression,
6172    pub expression: Expression,
6173    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6174    #[serde(skip_serializing_if = "Option::is_none", default)]
6175    pub original_name: Option<String>,
6176    /// Inferred data type from type annotation
6177    #[serde(default, skip_serializing_if = "Option::is_none")]
6178    pub inferred_type: Option<DataType>,
6179}
6180
6181/// Variable argument function
6182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6183#[cfg_attr(feature = "bindings", derive(TS))]
6184pub struct VarArgFunc {
6185    pub expressions: Vec<Expression>,
6186    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6187    #[serde(skip_serializing_if = "Option::is_none", default)]
6188    pub original_name: Option<String>,
6189    /// Inferred data type from type annotation
6190    #[serde(default, skip_serializing_if = "Option::is_none")]
6191    pub inferred_type: Option<DataType>,
6192}
6193
6194/// CONCAT_WS function
6195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6196#[cfg_attr(feature = "bindings", derive(TS))]
6197pub struct ConcatWs {
6198    pub separator: Expression,
6199    pub expressions: Vec<Expression>,
6200}
6201
6202/// SUBSTRING function
6203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6204#[cfg_attr(feature = "bindings", derive(TS))]
6205pub struct SubstringFunc {
6206    pub this: Expression,
6207    pub start: Expression,
6208    pub length: Option<Expression>,
6209    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6210    #[serde(default)]
6211    pub from_for_syntax: bool,
6212}
6213
6214/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6216#[cfg_attr(feature = "bindings", derive(TS))]
6217pub struct OverlayFunc {
6218    pub this: Expression,
6219    pub replacement: Expression,
6220    pub from: Expression,
6221    pub length: Option<Expression>,
6222}
6223
6224/// TRIM function
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub struct TrimFunc {
6228    pub this: Expression,
6229    pub characters: Option<Expression>,
6230    pub position: TrimPosition,
6231    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6232    #[serde(default)]
6233    pub sql_standard_syntax: bool,
6234    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6235    #[serde(default)]
6236    pub position_explicit: bool,
6237}
6238
6239#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6240#[cfg_attr(feature = "bindings", derive(TS))]
6241pub enum TrimPosition {
6242    Both,
6243    Leading,
6244    Trailing,
6245}
6246
6247/// REPLACE function
6248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6249#[cfg_attr(feature = "bindings", derive(TS))]
6250pub struct ReplaceFunc {
6251    pub this: Expression,
6252    pub old: Expression,
6253    pub new: Expression,
6254}
6255
6256/// LEFT/RIGHT function
6257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6258#[cfg_attr(feature = "bindings", derive(TS))]
6259pub struct LeftRightFunc {
6260    pub this: Expression,
6261    pub length: Expression,
6262}
6263
6264/// REPEAT function
6265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6266#[cfg_attr(feature = "bindings", derive(TS))]
6267pub struct RepeatFunc {
6268    pub this: Expression,
6269    pub times: Expression,
6270}
6271
6272/// LPAD/RPAD function
6273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6274#[cfg_attr(feature = "bindings", derive(TS))]
6275pub struct PadFunc {
6276    pub this: Expression,
6277    pub length: Expression,
6278    pub fill: Option<Expression>,
6279}
6280
6281/// SPLIT function
6282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6283#[cfg_attr(feature = "bindings", derive(TS))]
6284pub struct SplitFunc {
6285    pub this: Expression,
6286    pub delimiter: Expression,
6287}
6288
6289/// REGEXP_LIKE function
6290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6291#[cfg_attr(feature = "bindings", derive(TS))]
6292pub struct RegexpFunc {
6293    pub this: Expression,
6294    pub pattern: Expression,
6295    pub flags: Option<Expression>,
6296}
6297
6298/// REGEXP_REPLACE function
6299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6300#[cfg_attr(feature = "bindings", derive(TS))]
6301pub struct RegexpReplaceFunc {
6302    pub this: Expression,
6303    pub pattern: Expression,
6304    pub replacement: Expression,
6305    pub flags: Option<Expression>,
6306}
6307
6308/// REGEXP_EXTRACT function
6309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6310#[cfg_attr(feature = "bindings", derive(TS))]
6311pub struct RegexpExtractFunc {
6312    pub this: Expression,
6313    pub pattern: Expression,
6314    pub group: Option<Expression>,
6315}
6316
6317/// ROUND function
6318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6319#[cfg_attr(feature = "bindings", derive(TS))]
6320pub struct RoundFunc {
6321    pub this: Expression,
6322    pub decimals: Option<Expression>,
6323}
6324
6325/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6327#[cfg_attr(feature = "bindings", derive(TS))]
6328pub struct FloorFunc {
6329    pub this: Expression,
6330    pub scale: Option<Expression>,
6331    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6332    #[serde(skip_serializing_if = "Option::is_none", default)]
6333    pub to: Option<Expression>,
6334}
6335
6336/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6338#[cfg_attr(feature = "bindings", derive(TS))]
6339pub struct CeilFunc {
6340    pub this: Expression,
6341    #[serde(skip_serializing_if = "Option::is_none", default)]
6342    pub decimals: Option<Expression>,
6343    /// Time unit for Druid-style CEIL(time TO unit) syntax
6344    #[serde(skip_serializing_if = "Option::is_none", default)]
6345    pub to: Option<Expression>,
6346}
6347
6348/// LOG function
6349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6350#[cfg_attr(feature = "bindings", derive(TS))]
6351pub struct LogFunc {
6352    pub this: Expression,
6353    pub base: Option<Expression>,
6354}
6355
6356/// CURRENT_DATE (no arguments)
6357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6358#[cfg_attr(feature = "bindings", derive(TS))]
6359pub struct CurrentDate;
6360
6361/// CURRENT_TIME
6362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6363#[cfg_attr(feature = "bindings", derive(TS))]
6364pub struct CurrentTime {
6365    pub precision: Option<u32>,
6366}
6367
6368/// CURRENT_TIMESTAMP
6369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6370#[cfg_attr(feature = "bindings", derive(TS))]
6371pub struct CurrentTimestamp {
6372    pub precision: Option<u32>,
6373    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6374    #[serde(default)]
6375    pub sysdate: bool,
6376}
6377
6378/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6380#[cfg_attr(feature = "bindings", derive(TS))]
6381pub struct CurrentTimestampLTZ {
6382    pub precision: Option<u32>,
6383}
6384
6385/// AT TIME ZONE expression for timezone conversion
6386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6387#[cfg_attr(feature = "bindings", derive(TS))]
6388pub struct AtTimeZone {
6389    /// The expression to convert
6390    pub this: Expression,
6391    /// The target timezone
6392    pub zone: Expression,
6393}
6394
6395/// DATE_ADD / DATE_SUB function
6396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6397#[cfg_attr(feature = "bindings", derive(TS))]
6398pub struct DateAddFunc {
6399    pub this: Expression,
6400    pub interval: Expression,
6401    pub unit: IntervalUnit,
6402}
6403
6404/// DATEDIFF function
6405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6406#[cfg_attr(feature = "bindings", derive(TS))]
6407pub struct DateDiffFunc {
6408    pub this: Expression,
6409    pub expression: Expression,
6410    pub unit: Option<IntervalUnit>,
6411}
6412
6413/// DATE_TRUNC function
6414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6415#[cfg_attr(feature = "bindings", derive(TS))]
6416pub struct DateTruncFunc {
6417    pub this: Expression,
6418    pub unit: DateTimeField,
6419}
6420
6421/// EXTRACT function
6422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6423#[cfg_attr(feature = "bindings", derive(TS))]
6424pub struct ExtractFunc {
6425    pub this: Expression,
6426    pub field: DateTimeField,
6427}
6428
6429#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6430#[cfg_attr(feature = "bindings", derive(TS))]
6431pub enum DateTimeField {
6432    Year,
6433    Month,
6434    Day,
6435    Hour,
6436    Minute,
6437    Second,
6438    Millisecond,
6439    Microsecond,
6440    DayOfWeek,
6441    DayOfYear,
6442    Week,
6443    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6444    WeekWithModifier(String),
6445    Quarter,
6446    Epoch,
6447    Timezone,
6448    TimezoneHour,
6449    TimezoneMinute,
6450    Date,
6451    Time,
6452    /// Custom datetime field for dialect-specific or arbitrary fields
6453    Custom(String),
6454}
6455
6456/// TO_DATE function
6457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6458#[cfg_attr(feature = "bindings", derive(TS))]
6459pub struct ToDateFunc {
6460    pub this: Expression,
6461    pub format: Option<Expression>,
6462}
6463
6464/// TO_TIMESTAMP function
6465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6466#[cfg_attr(feature = "bindings", derive(TS))]
6467pub struct ToTimestampFunc {
6468    pub this: Expression,
6469    pub format: Option<Expression>,
6470}
6471
6472/// IF function
6473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6474#[cfg_attr(feature = "bindings", derive(TS))]
6475pub struct IfFunc {
6476    pub condition: Expression,
6477    pub true_value: Expression,
6478    pub false_value: Option<Expression>,
6479    /// Original function name (IF, IFF, IIF) for round-trip preservation
6480    #[serde(skip_serializing_if = "Option::is_none", default)]
6481    pub original_name: Option<String>,
6482    /// Inferred data type from type annotation
6483    #[serde(default, skip_serializing_if = "Option::is_none")]
6484    pub inferred_type: Option<DataType>,
6485}
6486
6487/// NVL2 function
6488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6489#[cfg_attr(feature = "bindings", derive(TS))]
6490pub struct Nvl2Func {
6491    pub this: Expression,
6492    pub true_value: Expression,
6493    pub false_value: Expression,
6494    /// Inferred data type from type annotation
6495    #[serde(default, skip_serializing_if = "Option::is_none")]
6496    pub inferred_type: Option<DataType>,
6497}
6498
6499// ============================================================================
6500// Typed Aggregate Function types
6501// ============================================================================
6502
6503/// Generic aggregate function base type
6504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6505#[cfg_attr(feature = "bindings", derive(TS))]
6506pub struct AggFunc {
6507    pub this: Expression,
6508    pub distinct: bool,
6509    pub filter: Option<Expression>,
6510    pub order_by: Vec<Ordered>,
6511    /// Original function name (case-preserving) when parsed from SQL
6512    #[serde(skip_serializing_if = "Option::is_none", default)]
6513    pub name: Option<String>,
6514    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6515    #[serde(skip_serializing_if = "Option::is_none", default)]
6516    pub ignore_nulls: Option<bool>,
6517    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6518    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6519    #[serde(skip_serializing_if = "Option::is_none", default)]
6520    pub having_max: Option<(Box<Expression>, bool)>,
6521    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6522    #[serde(skip_serializing_if = "Option::is_none", default)]
6523    pub limit: Option<Box<Expression>>,
6524    /// Inferred data type from type annotation
6525    #[serde(default, skip_serializing_if = "Option::is_none")]
6526    pub inferred_type: Option<DataType>,
6527}
6528
6529/// COUNT function with optional star
6530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6531#[cfg_attr(feature = "bindings", derive(TS))]
6532pub struct CountFunc {
6533    pub this: Option<Expression>,
6534    pub star: bool,
6535    pub distinct: bool,
6536    pub filter: Option<Expression>,
6537    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6538    #[serde(default, skip_serializing_if = "Option::is_none")]
6539    pub ignore_nulls: Option<bool>,
6540    /// Original function name for case preservation (e.g., "count" or "COUNT")
6541    #[serde(default, skip_serializing_if = "Option::is_none")]
6542    pub original_name: Option<String>,
6543    /// Inferred data type from type annotation
6544    #[serde(default, skip_serializing_if = "Option::is_none")]
6545    pub inferred_type: Option<DataType>,
6546}
6547
6548/// GROUP_CONCAT function (MySQL style)
6549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6550#[cfg_attr(feature = "bindings", derive(TS))]
6551pub struct GroupConcatFunc {
6552    pub this: Expression,
6553    pub separator: Option<Expression>,
6554    pub order_by: Option<Vec<Ordered>>,
6555    pub distinct: bool,
6556    pub filter: Option<Expression>,
6557    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6558    #[serde(default, skip_serializing_if = "Option::is_none")]
6559    pub limit: Option<Box<Expression>>,
6560    /// Inferred data type from type annotation
6561    #[serde(default, skip_serializing_if = "Option::is_none")]
6562    pub inferred_type: Option<DataType>,
6563}
6564
6565/// STRING_AGG function (PostgreSQL/Standard SQL)
6566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6567#[cfg_attr(feature = "bindings", derive(TS))]
6568pub struct StringAggFunc {
6569    pub this: Expression,
6570    #[serde(default)]
6571    pub separator: Option<Expression>,
6572    #[serde(default)]
6573    pub order_by: Option<Vec<Ordered>>,
6574    #[serde(default)]
6575    pub distinct: bool,
6576    #[serde(default)]
6577    pub filter: Option<Expression>,
6578    /// BigQuery LIMIT inside STRING_AGG
6579    #[serde(default, skip_serializing_if = "Option::is_none")]
6580    pub limit: Option<Box<Expression>>,
6581    /// Inferred data type from type annotation
6582    #[serde(default, skip_serializing_if = "Option::is_none")]
6583    pub inferred_type: Option<DataType>,
6584}
6585
6586/// LISTAGG function (Oracle style)
6587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6588#[cfg_attr(feature = "bindings", derive(TS))]
6589pub struct ListAggFunc {
6590    pub this: Expression,
6591    pub separator: Option<Expression>,
6592    pub on_overflow: Option<ListAggOverflow>,
6593    pub order_by: Option<Vec<Ordered>>,
6594    pub distinct: bool,
6595    pub filter: Option<Expression>,
6596    /// Inferred data type from type annotation
6597    #[serde(default, skip_serializing_if = "Option::is_none")]
6598    pub inferred_type: Option<DataType>,
6599}
6600
6601/// LISTAGG ON OVERFLOW behavior
6602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6603#[cfg_attr(feature = "bindings", derive(TS))]
6604pub enum ListAggOverflow {
6605    Error,
6606    Truncate {
6607        filler: Option<Expression>,
6608        with_count: bool,
6609    },
6610}
6611
6612/// SUM_IF / COUNT_IF function
6613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6614#[cfg_attr(feature = "bindings", derive(TS))]
6615pub struct SumIfFunc {
6616    pub this: Expression,
6617    pub condition: Expression,
6618    pub filter: Option<Expression>,
6619    /// Inferred data type from type annotation
6620    #[serde(default, skip_serializing_if = "Option::is_none")]
6621    pub inferred_type: Option<DataType>,
6622}
6623
6624/// APPROX_PERCENTILE function
6625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6626#[cfg_attr(feature = "bindings", derive(TS))]
6627pub struct ApproxPercentileFunc {
6628    pub this: Expression,
6629    pub percentile: Expression,
6630    pub accuracy: Option<Expression>,
6631    pub filter: Option<Expression>,
6632}
6633
6634/// PERCENTILE_CONT / PERCENTILE_DISC function
6635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6636#[cfg_attr(feature = "bindings", derive(TS))]
6637pub struct PercentileFunc {
6638    pub this: Expression,
6639    pub percentile: Expression,
6640    pub order_by: Option<Vec<Ordered>>,
6641    pub filter: Option<Expression>,
6642}
6643
6644// ============================================================================
6645// Typed Window Function types
6646// ============================================================================
6647
6648/// ROW_NUMBER function (no arguments)
6649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6650#[cfg_attr(feature = "bindings", derive(TS))]
6651pub struct RowNumber;
6652
6653/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6655#[cfg_attr(feature = "bindings", derive(TS))]
6656pub struct Rank {
6657    /// DuckDB: RANK(ORDER BY col) - order by inside function
6658    #[serde(default, skip_serializing_if = "Option::is_none")]
6659    pub order_by: Option<Vec<Ordered>>,
6660    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6661    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6662    pub args: Vec<Expression>,
6663}
6664
6665/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6667#[cfg_attr(feature = "bindings", derive(TS))]
6668pub struct DenseRank {
6669    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6670    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6671    pub args: Vec<Expression>,
6672}
6673
6674/// NTILE function (DuckDB allows ORDER BY inside)
6675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6676#[cfg_attr(feature = "bindings", derive(TS))]
6677pub struct NTileFunc {
6678    /// num_buckets is optional to support Databricks NTILE() without arguments
6679    #[serde(default, skip_serializing_if = "Option::is_none")]
6680    pub num_buckets: Option<Expression>,
6681    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6682    #[serde(default, skip_serializing_if = "Option::is_none")]
6683    pub order_by: Option<Vec<Ordered>>,
6684}
6685
6686/// LEAD / LAG function
6687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6688#[cfg_attr(feature = "bindings", derive(TS))]
6689pub struct LeadLagFunc {
6690    pub this: Expression,
6691    pub offset: Option<Expression>,
6692    pub default: Option<Expression>,
6693    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6694    #[serde(default, skip_serializing_if = "Option::is_none")]
6695    pub ignore_nulls: Option<bool>,
6696}
6697
6698/// FIRST_VALUE / LAST_VALUE function
6699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6700#[cfg_attr(feature = "bindings", derive(TS))]
6701pub struct ValueFunc {
6702    pub this: Expression,
6703    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6704    #[serde(default, skip_serializing_if = "Option::is_none")]
6705    pub ignore_nulls: Option<bool>,
6706    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6707    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6708    pub order_by: Vec<Ordered>,
6709}
6710
6711/// NTH_VALUE function
6712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6713#[cfg_attr(feature = "bindings", derive(TS))]
6714pub struct NthValueFunc {
6715    pub this: Expression,
6716    pub offset: Expression,
6717    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6718    #[serde(default, skip_serializing_if = "Option::is_none")]
6719    pub ignore_nulls: Option<bool>,
6720    /// Snowflake FROM FIRST / FROM LAST clause
6721    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6722    #[serde(default, skip_serializing_if = "Option::is_none")]
6723    pub from_first: Option<bool>,
6724}
6725
6726/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6728#[cfg_attr(feature = "bindings", derive(TS))]
6729pub struct PercentRank {
6730    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6731    #[serde(default, skip_serializing_if = "Option::is_none")]
6732    pub order_by: Option<Vec<Ordered>>,
6733    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6734    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6735    pub args: Vec<Expression>,
6736}
6737
6738/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6740#[cfg_attr(feature = "bindings", derive(TS))]
6741pub struct CumeDist {
6742    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6743    #[serde(default, skip_serializing_if = "Option::is_none")]
6744    pub order_by: Option<Vec<Ordered>>,
6745    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6746    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6747    pub args: Vec<Expression>,
6748}
6749
6750// ============================================================================
6751// Additional String Function types
6752// ============================================================================
6753
6754/// POSITION/INSTR function
6755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6756#[cfg_attr(feature = "bindings", derive(TS))]
6757pub struct PositionFunc {
6758    pub substring: Expression,
6759    pub string: Expression,
6760    pub start: Option<Expression>,
6761}
6762
6763// ============================================================================
6764// Additional Math Function types
6765// ============================================================================
6766
6767/// RANDOM function (no arguments)
6768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6769#[cfg_attr(feature = "bindings", derive(TS))]
6770pub struct Random;
6771
6772/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6774#[cfg_attr(feature = "bindings", derive(TS))]
6775pub struct Rand {
6776    pub seed: Option<Box<Expression>>,
6777    /// Teradata RANDOM lower bound
6778    #[serde(default)]
6779    pub lower: Option<Box<Expression>>,
6780    /// Teradata RANDOM upper bound
6781    #[serde(default)]
6782    pub upper: Option<Box<Expression>>,
6783}
6784
6785/// TRUNCATE / TRUNC function
6786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6787#[cfg_attr(feature = "bindings", derive(TS))]
6788pub struct TruncateFunc {
6789    pub this: Expression,
6790    pub decimals: Option<Expression>,
6791}
6792
6793/// PI function (no arguments)
6794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6795#[cfg_attr(feature = "bindings", derive(TS))]
6796pub struct Pi;
6797
6798// ============================================================================
6799// Control Flow Function types
6800// ============================================================================
6801
6802/// DECODE function (Oracle style)
6803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6804#[cfg_attr(feature = "bindings", derive(TS))]
6805pub struct DecodeFunc {
6806    pub this: Expression,
6807    pub search_results: Vec<(Expression, Expression)>,
6808    pub default: Option<Expression>,
6809}
6810
6811// ============================================================================
6812// Additional Date/Time Function types
6813// ============================================================================
6814
6815/// DATE_FORMAT / FORMAT_DATE function
6816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6817#[cfg_attr(feature = "bindings", derive(TS))]
6818pub struct DateFormatFunc {
6819    pub this: Expression,
6820    pub format: Expression,
6821}
6822
6823/// FROM_UNIXTIME function
6824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6825#[cfg_attr(feature = "bindings", derive(TS))]
6826pub struct FromUnixtimeFunc {
6827    pub this: Expression,
6828    pub format: Option<Expression>,
6829}
6830
6831/// UNIX_TIMESTAMP function
6832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6833#[cfg_attr(feature = "bindings", derive(TS))]
6834pub struct UnixTimestampFunc {
6835    pub this: Option<Expression>,
6836    pub format: Option<Expression>,
6837}
6838
6839/// MAKE_DATE function
6840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6841#[cfg_attr(feature = "bindings", derive(TS))]
6842pub struct MakeDateFunc {
6843    pub year: Expression,
6844    pub month: Expression,
6845    pub day: Expression,
6846}
6847
6848/// MAKE_TIMESTAMP function
6849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6850#[cfg_attr(feature = "bindings", derive(TS))]
6851pub struct MakeTimestampFunc {
6852    pub year: Expression,
6853    pub month: Expression,
6854    pub day: Expression,
6855    pub hour: Expression,
6856    pub minute: Expression,
6857    pub second: Expression,
6858    pub timezone: Option<Expression>,
6859}
6860
6861/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6863#[cfg_attr(feature = "bindings", derive(TS))]
6864pub struct LastDayFunc {
6865    pub this: Expression,
6866    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6867    #[serde(skip_serializing_if = "Option::is_none", default)]
6868    pub unit: Option<DateTimeField>,
6869}
6870
6871// ============================================================================
6872// Array Function types
6873// ============================================================================
6874
6875/// ARRAY constructor
6876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6877#[cfg_attr(feature = "bindings", derive(TS))]
6878pub struct ArrayConstructor {
6879    pub expressions: Vec<Expression>,
6880    pub bracket_notation: bool,
6881    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6882    pub use_list_keyword: bool,
6883}
6884
6885/// ARRAY_SORT function
6886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6887#[cfg_attr(feature = "bindings", derive(TS))]
6888pub struct ArraySortFunc {
6889    pub this: Expression,
6890    pub comparator: Option<Expression>,
6891    pub desc: bool,
6892    pub nulls_first: Option<bool>,
6893}
6894
6895/// ARRAY_JOIN / ARRAY_TO_STRING function
6896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6897#[cfg_attr(feature = "bindings", derive(TS))]
6898pub struct ArrayJoinFunc {
6899    pub this: Expression,
6900    pub separator: Expression,
6901    pub null_replacement: Option<Expression>,
6902}
6903
6904/// UNNEST function
6905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6906#[cfg_attr(feature = "bindings", derive(TS))]
6907pub struct UnnestFunc {
6908    pub this: Expression,
6909    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6910    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6911    pub expressions: Vec<Expression>,
6912    pub with_ordinality: bool,
6913    pub alias: Option<Identifier>,
6914    /// BigQuery: offset alias for WITH OFFSET AS <name>
6915    #[serde(default, skip_serializing_if = "Option::is_none")]
6916    pub offset_alias: Option<Identifier>,
6917}
6918
6919/// ARRAY_FILTER function (with lambda)
6920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6921#[cfg_attr(feature = "bindings", derive(TS))]
6922pub struct ArrayFilterFunc {
6923    pub this: Expression,
6924    pub filter: Expression,
6925}
6926
6927/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6929#[cfg_attr(feature = "bindings", derive(TS))]
6930pub struct ArrayTransformFunc {
6931    pub this: Expression,
6932    pub transform: Expression,
6933}
6934
6935/// SEQUENCE / GENERATE_SERIES function
6936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6937#[cfg_attr(feature = "bindings", derive(TS))]
6938pub struct SequenceFunc {
6939    pub start: Expression,
6940    pub stop: Expression,
6941    pub step: Option<Expression>,
6942}
6943
6944// ============================================================================
6945// Struct Function types
6946// ============================================================================
6947
6948/// STRUCT constructor
6949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6950#[cfg_attr(feature = "bindings", derive(TS))]
6951pub struct StructConstructor {
6952    pub fields: Vec<(Option<Identifier>, Expression)>,
6953}
6954
6955/// STRUCT_EXTRACT function
6956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6957#[cfg_attr(feature = "bindings", derive(TS))]
6958pub struct StructExtractFunc {
6959    pub this: Expression,
6960    pub field: Identifier,
6961}
6962
6963/// NAMED_STRUCT function
6964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6965#[cfg_attr(feature = "bindings", derive(TS))]
6966pub struct NamedStructFunc {
6967    pub pairs: Vec<(Expression, Expression)>,
6968}
6969
6970// ============================================================================
6971// Map Function types
6972// ============================================================================
6973
6974/// MAP constructor
6975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6976#[cfg_attr(feature = "bindings", derive(TS))]
6977pub struct MapConstructor {
6978    pub keys: Vec<Expression>,
6979    pub values: Vec<Expression>,
6980    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6981    #[serde(default)]
6982    pub curly_brace_syntax: bool,
6983    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6984    #[serde(default)]
6985    pub with_map_keyword: bool,
6986}
6987
6988/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6990#[cfg_attr(feature = "bindings", derive(TS))]
6991pub struct TransformFunc {
6992    pub this: Expression,
6993    pub transform: Expression,
6994}
6995
6996/// Function call with EMITS clause (Exasol)
6997/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6999#[cfg_attr(feature = "bindings", derive(TS))]
7000pub struct FunctionEmits {
7001    /// The function call expression
7002    pub this: Expression,
7003    /// The EMITS schema definition
7004    pub emits: Expression,
7005}
7006
7007// ============================================================================
7008// JSON Function types
7009// ============================================================================
7010
7011/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
7012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7013#[cfg_attr(feature = "bindings", derive(TS))]
7014pub struct JsonExtractFunc {
7015    pub this: Expression,
7016    pub path: Expression,
7017    pub returning: Option<DataType>,
7018    /// True if parsed from -> or ->> operator syntax
7019    #[serde(default)]
7020    pub arrow_syntax: bool,
7021    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
7022    #[serde(default)]
7023    pub hash_arrow_syntax: bool,
7024    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
7025    #[serde(default)]
7026    pub wrapper_option: Option<String>,
7027    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
7028    #[serde(default)]
7029    pub quotes_option: Option<String>,
7030    /// ON SCALAR STRING flag
7031    #[serde(default)]
7032    pub on_scalar_string: bool,
7033    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
7034    #[serde(default)]
7035    pub on_error: Option<String>,
7036}
7037
7038/// JSON path extraction
7039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7040#[cfg_attr(feature = "bindings", derive(TS))]
7041pub struct JsonPathFunc {
7042    pub this: Expression,
7043    pub paths: Vec<Expression>,
7044}
7045
7046/// JSON_OBJECT function
7047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7048#[cfg_attr(feature = "bindings", derive(TS))]
7049pub struct JsonObjectFunc {
7050    pub pairs: Vec<(Expression, Expression)>,
7051    pub null_handling: Option<JsonNullHandling>,
7052    #[serde(default)]
7053    pub with_unique_keys: bool,
7054    #[serde(default)]
7055    pub returning_type: Option<DataType>,
7056    #[serde(default)]
7057    pub format_json: bool,
7058    #[serde(default)]
7059    pub encoding: Option<String>,
7060    /// For JSON_OBJECT(*) syntax
7061    #[serde(default)]
7062    pub star: bool,
7063}
7064
7065/// JSON null handling options
7066#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7067#[cfg_attr(feature = "bindings", derive(TS))]
7068pub enum JsonNullHandling {
7069    NullOnNull,
7070    AbsentOnNull,
7071}
7072
7073/// JSON_SET / JSON_INSERT function
7074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7075#[cfg_attr(feature = "bindings", derive(TS))]
7076pub struct JsonModifyFunc {
7077    pub this: Expression,
7078    pub path_values: Vec<(Expression, Expression)>,
7079}
7080
7081/// JSON_ARRAYAGG function
7082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7083#[cfg_attr(feature = "bindings", derive(TS))]
7084pub struct JsonArrayAggFunc {
7085    pub this: Expression,
7086    pub order_by: Option<Vec<Ordered>>,
7087    pub null_handling: Option<JsonNullHandling>,
7088    pub filter: Option<Expression>,
7089}
7090
7091/// JSON_OBJECTAGG function
7092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7093#[cfg_attr(feature = "bindings", derive(TS))]
7094pub struct JsonObjectAggFunc {
7095    pub key: Expression,
7096    pub value: Expression,
7097    pub null_handling: Option<JsonNullHandling>,
7098    pub filter: Option<Expression>,
7099}
7100
7101// ============================================================================
7102// Type Casting Function types
7103// ============================================================================
7104
7105/// CONVERT function (SQL Server style)
7106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7107#[cfg_attr(feature = "bindings", derive(TS))]
7108pub struct ConvertFunc {
7109    pub this: Expression,
7110    pub to: DataType,
7111    pub style: Option<Expression>,
7112}
7113
7114// ============================================================================
7115// Additional Expression types
7116// ============================================================================
7117
7118/// Lambda expression
7119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7120#[cfg_attr(feature = "bindings", derive(TS))]
7121pub struct LambdaExpr {
7122    pub parameters: Vec<Identifier>,
7123    pub body: Expression,
7124    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7125    #[serde(default)]
7126    pub colon: bool,
7127    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7128    /// Maps parameter index to data type
7129    #[serde(default)]
7130    pub parameter_types: Vec<Option<DataType>>,
7131}
7132
7133/// Parameter (parameterized queries)
7134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7135#[cfg_attr(feature = "bindings", derive(TS))]
7136pub struct Parameter {
7137    pub name: Option<String>,
7138    pub index: Option<u32>,
7139    pub style: ParameterStyle,
7140    /// Whether the name was quoted (e.g., @"x" vs @x)
7141    #[serde(default)]
7142    pub quoted: bool,
7143    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7144    #[serde(default)]
7145    pub string_quoted: bool,
7146    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7147    #[serde(default)]
7148    pub expression: Option<String>,
7149}
7150
7151/// Parameter placeholder styles
7152#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub enum ParameterStyle {
7155    Question,     // ?
7156    Dollar,       // $1, $2
7157    DollarBrace,  // ${name} (Databricks, Hive template variables)
7158    Brace,        // {name} (Spark/Databricks widget/template variables)
7159    Colon,        // :name
7160    At,           // @name
7161    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7162    DoubleDollar, // $$name
7163    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7164}
7165
7166/// Placeholder expression
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub struct Placeholder {
7170    pub index: Option<u32>,
7171}
7172
7173/// Named argument in function call: name => value or name := value
7174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7175#[cfg_attr(feature = "bindings", derive(TS))]
7176pub struct NamedArgument {
7177    pub name: Identifier,
7178    pub value: Expression,
7179    /// The separator used: `=>`, `:=`, or `=`
7180    pub separator: NamedArgSeparator,
7181}
7182
7183/// Separator style for named arguments
7184#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7185#[cfg_attr(feature = "bindings", derive(TS))]
7186pub enum NamedArgSeparator {
7187    /// `=>` (standard SQL, Snowflake, BigQuery)
7188    DArrow,
7189    /// `:=` (Oracle, MySQL)
7190    ColonEq,
7191    /// `=` (simple equals, some dialects)
7192    Eq,
7193}
7194
7195/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7196/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7198#[cfg_attr(feature = "bindings", derive(TS))]
7199pub struct TableArgument {
7200    /// The keyword prefix: "TABLE" or "MODEL"
7201    pub prefix: String,
7202    /// The table/model reference expression
7203    pub this: Expression,
7204}
7205
7206/// SQL Comment preservation
7207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7208#[cfg_attr(feature = "bindings", derive(TS))]
7209pub struct SqlComment {
7210    pub text: String,
7211    pub is_block: bool,
7212}
7213
7214// ============================================================================
7215// Additional Predicate types
7216// ============================================================================
7217
7218/// SIMILAR TO expression
7219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7220#[cfg_attr(feature = "bindings", derive(TS))]
7221pub struct SimilarToExpr {
7222    pub this: Expression,
7223    pub pattern: Expression,
7224    pub escape: Option<Expression>,
7225    pub not: bool,
7226}
7227
7228/// ANY / ALL quantified expression
7229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7230#[cfg_attr(feature = "bindings", derive(TS))]
7231pub struct QuantifiedExpr {
7232    pub this: Expression,
7233    pub subquery: Expression,
7234    pub op: Option<QuantifiedOp>,
7235}
7236
7237/// Comparison operator for quantified expressions
7238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7239#[cfg_attr(feature = "bindings", derive(TS))]
7240pub enum QuantifiedOp {
7241    Eq,
7242    Neq,
7243    Lt,
7244    Lte,
7245    Gt,
7246    Gte,
7247}
7248
7249/// OVERLAPS expression
7250/// Supports two forms:
7251/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7252/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7254#[cfg_attr(feature = "bindings", derive(TS))]
7255pub struct OverlapsExpr {
7256    /// Left operand for simple binary form
7257    #[serde(skip_serializing_if = "Option::is_none")]
7258    pub this: Option<Expression>,
7259    /// Right operand for simple binary form
7260    #[serde(skip_serializing_if = "Option::is_none")]
7261    pub expression: Option<Expression>,
7262    /// Left range start for full ANSI form
7263    #[serde(skip_serializing_if = "Option::is_none")]
7264    pub left_start: Option<Expression>,
7265    /// Left range end for full ANSI form
7266    #[serde(skip_serializing_if = "Option::is_none")]
7267    pub left_end: Option<Expression>,
7268    /// Right range start for full ANSI form
7269    #[serde(skip_serializing_if = "Option::is_none")]
7270    pub right_start: Option<Expression>,
7271    /// Right range end for full ANSI form
7272    #[serde(skip_serializing_if = "Option::is_none")]
7273    pub right_end: Option<Expression>,
7274}
7275
7276// ============================================================================
7277// Array/Struct/Map access
7278// ============================================================================
7279
7280/// Subscript access (array[index] or map[key])
7281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7282#[cfg_attr(feature = "bindings", derive(TS))]
7283pub struct Subscript {
7284    pub this: Expression,
7285    pub index: Expression,
7286}
7287
7288/// Dot access (struct.field)
7289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7290#[cfg_attr(feature = "bindings", derive(TS))]
7291pub struct DotAccess {
7292    pub this: Expression,
7293    pub field: Identifier,
7294}
7295
7296/// Method call (expr.method(args))
7297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7298#[cfg_attr(feature = "bindings", derive(TS))]
7299pub struct MethodCall {
7300    pub this: Expression,
7301    pub method: Identifier,
7302    pub args: Vec<Expression>,
7303}
7304
7305/// Array slice (array[start:end])
7306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7307#[cfg_attr(feature = "bindings", derive(TS))]
7308pub struct ArraySlice {
7309    pub this: Expression,
7310    pub start: Option<Expression>,
7311    pub end: Option<Expression>,
7312}
7313
7314// ============================================================================
7315// DDL (Data Definition Language) Statements
7316// ============================================================================
7317
7318/// ON COMMIT behavior for temporary tables
7319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7320#[cfg_attr(feature = "bindings", derive(TS))]
7321pub enum OnCommit {
7322    /// ON COMMIT PRESERVE ROWS
7323    PreserveRows,
7324    /// ON COMMIT DELETE ROWS
7325    DeleteRows,
7326}
7327
7328/// CREATE TABLE statement
7329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7330#[cfg_attr(feature = "bindings", derive(TS))]
7331pub struct CreateTable {
7332    pub name: TableRef,
7333    /// ClickHouse: ON CLUSTER clause for distributed DDL
7334    #[serde(default, skip_serializing_if = "Option::is_none")]
7335    pub on_cluster: Option<OnCluster>,
7336    pub columns: Vec<ColumnDef>,
7337    pub constraints: Vec<TableConstraint>,
7338    pub if_not_exists: bool,
7339    pub temporary: bool,
7340    pub or_replace: bool,
7341    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7342    #[serde(default, skip_serializing_if = "Option::is_none")]
7343    pub table_modifier: Option<String>,
7344    pub as_select: Option<Expression>,
7345    /// Whether the AS SELECT was wrapped in parentheses
7346    #[serde(default)]
7347    pub as_select_parenthesized: bool,
7348    /// ON COMMIT behavior for temporary tables
7349    #[serde(default)]
7350    pub on_commit: Option<OnCommit>,
7351    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7352    #[serde(default)]
7353    pub clone_source: Option<TableRef>,
7354    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7355    #[serde(default, skip_serializing_if = "Option::is_none")]
7356    pub clone_at_clause: Option<Expression>,
7357    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7358    #[serde(default)]
7359    pub is_copy: bool,
7360    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7361    #[serde(default)]
7362    pub shallow_clone: bool,
7363    /// Whether this is an explicit DEEP CLONE (Databricks/Delta Lake)
7364    #[serde(default)]
7365    pub deep_clone: bool,
7366    /// Leading comments before the statement
7367    #[serde(default)]
7368    pub leading_comments: Vec<String>,
7369    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7370    #[serde(default)]
7371    pub with_properties: Vec<(String, String)>,
7372    /// Teradata: table options after name before columns (comma-separated)
7373    #[serde(default)]
7374    pub teradata_post_name_options: Vec<String>,
7375    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7376    #[serde(default)]
7377    pub with_data: Option<bool>,
7378    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7379    #[serde(default)]
7380    pub with_statistics: Option<bool>,
7381    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7382    #[serde(default)]
7383    pub teradata_indexes: Vec<TeradataIndex>,
7384    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7385    #[serde(default)]
7386    pub with_cte: Option<With>,
7387    /// Table properties like DEFAULT COLLATE (BigQuery)
7388    #[serde(default)]
7389    pub properties: Vec<Expression>,
7390    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7391    #[serde(default, skip_serializing_if = "Option::is_none")]
7392    pub partition_of: Option<Expression>,
7393    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7394    #[serde(default)]
7395    pub post_table_properties: Vec<Expression>,
7396    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7397    #[serde(default)]
7398    pub mysql_table_options: Vec<(String, String)>,
7399    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7400    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7401    pub inherits: Vec<TableRef>,
7402    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7403    #[serde(default, skip_serializing_if = "Option::is_none")]
7404    pub on_property: Option<OnProperty>,
7405    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7406    #[serde(default)]
7407    pub copy_grants: bool,
7408    /// Snowflake: USING TEMPLATE expression for schema inference
7409    #[serde(default, skip_serializing_if = "Option::is_none")]
7410    pub using_template: Option<Box<Expression>>,
7411    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7412    #[serde(default, skip_serializing_if = "Option::is_none")]
7413    pub rollup: Option<RollupProperty>,
7414    /// ClickHouse: UUID 'xxx' clause after table name
7415    #[serde(default, skip_serializing_if = "Option::is_none")]
7416    pub uuid: Option<String>,
7417    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7418    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7419    /// could appear in other engines.
7420    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7421    pub with_partition_columns: Vec<ColumnDef>,
7422    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7423    /// for external tables that reference a Cloud Resource connection.
7424    #[serde(default, skip_serializing_if = "Option::is_none")]
7425    pub with_connection: Option<TableRef>,
7426}
7427
7428/// Teradata index specification for CREATE TABLE
7429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7430#[cfg_attr(feature = "bindings", derive(TS))]
7431pub struct TeradataIndex {
7432    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7433    pub kind: TeradataIndexKind,
7434    /// Optional index name
7435    pub name: Option<String>,
7436    /// Optional column list
7437    pub columns: Vec<String>,
7438}
7439
7440/// Kind of Teradata index
7441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7442#[cfg_attr(feature = "bindings", derive(TS))]
7443pub enum TeradataIndexKind {
7444    /// NO PRIMARY INDEX
7445    NoPrimary,
7446    /// PRIMARY INDEX
7447    Primary,
7448    /// PRIMARY AMP INDEX
7449    PrimaryAmp,
7450    /// UNIQUE INDEX
7451    Unique,
7452    /// UNIQUE PRIMARY INDEX
7453    UniquePrimary,
7454    /// INDEX (secondary, non-primary)
7455    Secondary,
7456}
7457
7458impl CreateTable {
7459    pub fn new(name: impl Into<String>) -> Self {
7460        Self {
7461            name: TableRef::new(name),
7462            on_cluster: None,
7463            columns: Vec::new(),
7464            constraints: Vec::new(),
7465            if_not_exists: false,
7466            temporary: false,
7467            or_replace: false,
7468            table_modifier: None,
7469            as_select: None,
7470            as_select_parenthesized: false,
7471            on_commit: None,
7472            clone_source: None,
7473            clone_at_clause: None,
7474            shallow_clone: false,
7475            deep_clone: false,
7476            is_copy: false,
7477            leading_comments: Vec::new(),
7478            with_properties: Vec::new(),
7479            teradata_post_name_options: Vec::new(),
7480            with_data: None,
7481            with_statistics: None,
7482            teradata_indexes: Vec::new(),
7483            with_cte: None,
7484            properties: Vec::new(),
7485            partition_of: None,
7486            post_table_properties: Vec::new(),
7487            mysql_table_options: Vec::new(),
7488            inherits: Vec::new(),
7489            on_property: None,
7490            copy_grants: false,
7491            using_template: None,
7492            rollup: None,
7493            uuid: None,
7494            with_partition_columns: Vec::new(),
7495            with_connection: None,
7496        }
7497    }
7498}
7499
7500/// Sort order for PRIMARY KEY ASC/DESC
7501#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7502#[cfg_attr(feature = "bindings", derive(TS))]
7503pub enum SortOrder {
7504    Asc,
7505    Desc,
7506}
7507
7508/// Type of column constraint for tracking order
7509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7510#[cfg_attr(feature = "bindings", derive(TS))]
7511pub enum ConstraintType {
7512    NotNull,
7513    Null,
7514    PrimaryKey,
7515    Unique,
7516    Default,
7517    AutoIncrement,
7518    Collate,
7519    Comment,
7520    References,
7521    Check,
7522    GeneratedAsIdentity,
7523    /// Snowflake: TAG (key='value', ...)
7524    Tags,
7525    /// Computed/generated column
7526    ComputedColumn,
7527    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7528    GeneratedAsRow,
7529    /// MySQL: ON UPDATE expression
7530    OnUpdate,
7531    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7532    Path,
7533    /// Redshift: ENCODE encoding_type
7534    Encode,
7535}
7536
7537/// Column definition in CREATE TABLE
7538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7539#[cfg_attr(feature = "bindings", derive(TS))]
7540pub struct ColumnDef {
7541    pub name: Identifier,
7542    pub data_type: DataType,
7543    pub nullable: Option<bool>,
7544    pub default: Option<Expression>,
7545    pub primary_key: bool,
7546    /// Sort order for PRIMARY KEY (ASC/DESC)
7547    #[serde(default)]
7548    pub primary_key_order: Option<SortOrder>,
7549    pub unique: bool,
7550    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7551    #[serde(default)]
7552    pub unique_nulls_not_distinct: bool,
7553    pub auto_increment: bool,
7554    pub comment: Option<String>,
7555    pub constraints: Vec<ColumnConstraint>,
7556    /// Track original order of constraints for accurate regeneration
7557    #[serde(default)]
7558    pub constraint_order: Vec<ConstraintType>,
7559    /// Teradata: FORMAT 'pattern'
7560    #[serde(default)]
7561    pub format: Option<String>,
7562    /// Teradata: TITLE 'title'
7563    #[serde(default)]
7564    pub title: Option<String>,
7565    /// Teradata: INLINE LENGTH n
7566    #[serde(default)]
7567    pub inline_length: Option<u64>,
7568    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7569    #[serde(default)]
7570    pub compress: Option<Vec<Expression>>,
7571    /// Teradata: CHARACTER SET name
7572    #[serde(default)]
7573    pub character_set: Option<String>,
7574    /// Teradata: UPPERCASE
7575    #[serde(default)]
7576    pub uppercase: bool,
7577    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7578    #[serde(default)]
7579    pub casespecific: Option<bool>,
7580    /// Snowflake: AUTOINCREMENT START value
7581    #[serde(default)]
7582    pub auto_increment_start: Option<Box<Expression>>,
7583    /// Snowflake: AUTOINCREMENT INCREMENT value
7584    #[serde(default)]
7585    pub auto_increment_increment: Option<Box<Expression>>,
7586    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7587    #[serde(default)]
7588    pub auto_increment_order: Option<bool>,
7589    /// MySQL: UNSIGNED modifier
7590    #[serde(default)]
7591    pub unsigned: bool,
7592    /// MySQL: ZEROFILL modifier
7593    #[serde(default)]
7594    pub zerofill: bool,
7595    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7596    #[serde(default, skip_serializing_if = "Option::is_none")]
7597    pub on_update: Option<Expression>,
7598    /// MySQL: column VISIBLE/INVISIBLE modifier.
7599    #[serde(default, skip_serializing_if = "Option::is_none")]
7600    pub visible: Option<bool>,
7601    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7602    #[serde(default, skip_serializing_if = "Option::is_none")]
7603    pub unique_constraint_name: Option<String>,
7604    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7605    #[serde(default, skip_serializing_if = "Option::is_none")]
7606    pub not_null_constraint_name: Option<String>,
7607    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7608    #[serde(default, skip_serializing_if = "Option::is_none")]
7609    pub primary_key_constraint_name: Option<String>,
7610    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7611    #[serde(default, skip_serializing_if = "Option::is_none")]
7612    pub check_constraint_name: Option<String>,
7613    /// BigQuery: OPTIONS (key=value, ...) on column
7614    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7615    pub options: Vec<Expression>,
7616    /// SQLite: Column definition without explicit type
7617    #[serde(default)]
7618    pub no_type: bool,
7619    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7620    #[serde(default, skip_serializing_if = "Option::is_none")]
7621    pub encoding: Option<String>,
7622    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7623    #[serde(default, skip_serializing_if = "Option::is_none")]
7624    pub codec: Option<String>,
7625    /// ClickHouse: EPHEMERAL [expr] modifier
7626    #[serde(default, skip_serializing_if = "Option::is_none")]
7627    pub ephemeral: Option<Option<Box<Expression>>>,
7628    /// ClickHouse: MATERIALIZED expr modifier
7629    #[serde(default, skip_serializing_if = "Option::is_none")]
7630    pub materialized_expr: Option<Box<Expression>>,
7631    /// ClickHouse: ALIAS expr modifier
7632    #[serde(default, skip_serializing_if = "Option::is_none")]
7633    pub alias_expr: Option<Box<Expression>>,
7634    /// ClickHouse: TTL expr modifier on columns
7635    #[serde(default, skip_serializing_if = "Option::is_none")]
7636    pub ttl_expr: Option<Box<Expression>>,
7637    /// TSQL: NOT FOR REPLICATION
7638    #[serde(default)]
7639    pub not_for_replication: bool,
7640}
7641
7642impl ColumnDef {
7643    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7644        Self {
7645            name: Identifier::new(name),
7646            data_type,
7647            nullable: None,
7648            default: None,
7649            primary_key: false,
7650            primary_key_order: None,
7651            unique: false,
7652            unique_nulls_not_distinct: false,
7653            auto_increment: false,
7654            comment: None,
7655            constraints: Vec::new(),
7656            constraint_order: Vec::new(),
7657            format: None,
7658            title: None,
7659            inline_length: None,
7660            compress: None,
7661            character_set: None,
7662            uppercase: false,
7663            casespecific: None,
7664            auto_increment_start: None,
7665            auto_increment_increment: None,
7666            auto_increment_order: None,
7667            unsigned: false,
7668            zerofill: false,
7669            on_update: None,
7670            visible: None,
7671            unique_constraint_name: None,
7672            not_null_constraint_name: None,
7673            primary_key_constraint_name: None,
7674            check_constraint_name: None,
7675            options: Vec::new(),
7676            no_type: false,
7677            encoding: None,
7678            codec: None,
7679            ephemeral: None,
7680            materialized_expr: None,
7681            alias_expr: None,
7682            ttl_expr: None,
7683            not_for_replication: false,
7684        }
7685    }
7686}
7687
7688/// Column-level constraint
7689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7690#[cfg_attr(feature = "bindings", derive(TS))]
7691pub enum ColumnConstraint {
7692    NotNull,
7693    Null,
7694    Unique,
7695    PrimaryKey,
7696    Default(Expression),
7697    Check(Expression),
7698    References(ForeignKeyRef),
7699    GeneratedAsIdentity(GeneratedAsIdentity),
7700    Collate(Identifier),
7701    Comment(String),
7702    /// Snowflake: TAG (key='value', ...)
7703    Tags(Tags),
7704    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7705    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7706    ComputedColumn(ComputedColumn),
7707    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7708    GeneratedAsRow(GeneratedAsRow),
7709    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7710    Path(Expression),
7711}
7712
7713/// Computed/generated column constraint
7714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7715#[cfg_attr(feature = "bindings", derive(TS))]
7716pub struct ComputedColumn {
7717    /// The expression that computes the column value
7718    pub expression: Box<Expression>,
7719    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7720    #[serde(default)]
7721    pub persisted: bool,
7722    /// NOT NULL (TSQL computed columns)
7723    #[serde(default)]
7724    pub not_null: bool,
7725    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7726    /// When None, defaults to dialect-appropriate output
7727    #[serde(default)]
7728    pub persistence_kind: Option<String>,
7729    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7730    #[serde(default, skip_serializing_if = "Option::is_none")]
7731    pub data_type: Option<DataType>,
7732}
7733
7734/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7736#[cfg_attr(feature = "bindings", derive(TS))]
7737pub struct GeneratedAsRow {
7738    /// true = ROW START, false = ROW END
7739    pub start: bool,
7740    /// HIDDEN modifier
7741    #[serde(default)]
7742    pub hidden: bool,
7743}
7744
7745/// Generated identity column constraint
7746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7747#[cfg_attr(feature = "bindings", derive(TS))]
7748pub struct GeneratedAsIdentity {
7749    /// True for ALWAYS, False for BY DEFAULT
7750    pub always: bool,
7751    /// ON NULL (only valid with BY DEFAULT)
7752    pub on_null: bool,
7753    /// START WITH value
7754    pub start: Option<Box<Expression>>,
7755    /// INCREMENT BY value
7756    pub increment: Option<Box<Expression>>,
7757    /// MINVALUE
7758    pub minvalue: Option<Box<Expression>>,
7759    /// MAXVALUE
7760    pub maxvalue: Option<Box<Expression>>,
7761    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7762    pub cycle: Option<bool>,
7763}
7764
7765/// Constraint modifiers (shared between table-level constraints)
7766#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7767#[cfg_attr(feature = "bindings", derive(TS))]
7768pub struct ConstraintModifiers {
7769    /// ENFORCED / NOT ENFORCED
7770    pub enforced: Option<bool>,
7771    /// DEFERRABLE / NOT DEFERRABLE
7772    pub deferrable: Option<bool>,
7773    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7774    pub initially_deferred: Option<bool>,
7775    /// NORELY (Oracle)
7776    pub norely: bool,
7777    /// RELY (Oracle)
7778    pub rely: bool,
7779    /// USING index type (MySQL): BTREE or HASH
7780    #[serde(default)]
7781    pub using: Option<String>,
7782    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7783    #[serde(default)]
7784    pub using_before_columns: bool,
7785    /// MySQL index COMMENT 'text'
7786    #[serde(default, skip_serializing_if = "Option::is_none")]
7787    pub comment: Option<String>,
7788    /// MySQL index VISIBLE/INVISIBLE
7789    #[serde(default, skip_serializing_if = "Option::is_none")]
7790    pub visible: Option<bool>,
7791    /// MySQL ENGINE_ATTRIBUTE = 'value'
7792    #[serde(default, skip_serializing_if = "Option::is_none")]
7793    pub engine_attribute: Option<String>,
7794    /// MySQL WITH PARSER name
7795    #[serde(default, skip_serializing_if = "Option::is_none")]
7796    pub with_parser: Option<String>,
7797    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7798    #[serde(default)]
7799    pub not_valid: bool,
7800    /// TSQL CLUSTERED/NONCLUSTERED modifier
7801    #[serde(default, skip_serializing_if = "Option::is_none")]
7802    pub clustered: Option<String>,
7803    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7804    #[serde(default, skip_serializing_if = "Option::is_none")]
7805    pub on_conflict: Option<String>,
7806    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7807    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7808    pub with_options: Vec<(String, String)>,
7809    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7810    #[serde(default, skip_serializing_if = "Option::is_none")]
7811    pub on_filegroup: Option<Identifier>,
7812}
7813
7814/// Table-level constraint
7815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7816#[cfg_attr(feature = "bindings", derive(TS))]
7817pub enum TableConstraint {
7818    PrimaryKey {
7819        name: Option<Identifier>,
7820        columns: Vec<Identifier>,
7821        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7822        #[serde(default)]
7823        include_columns: Vec<Identifier>,
7824        #[serde(default)]
7825        modifiers: ConstraintModifiers,
7826        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7827        #[serde(default)]
7828        has_constraint_keyword: bool,
7829    },
7830    Unique {
7831        name: Option<Identifier>,
7832        columns: Vec<Identifier>,
7833        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7834        #[serde(default)]
7835        columns_parenthesized: bool,
7836        #[serde(default)]
7837        modifiers: ConstraintModifiers,
7838        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7839        #[serde(default)]
7840        has_constraint_keyword: bool,
7841        /// PostgreSQL 15+: NULLS NOT DISTINCT
7842        #[serde(default)]
7843        nulls_not_distinct: bool,
7844    },
7845    ForeignKey {
7846        name: Option<Identifier>,
7847        columns: Vec<Identifier>,
7848        #[serde(default)]
7849        references: Option<ForeignKeyRef>,
7850        /// ON DELETE action when REFERENCES is absent
7851        #[serde(default)]
7852        on_delete: Option<ReferentialAction>,
7853        /// ON UPDATE action when REFERENCES is absent
7854        #[serde(default)]
7855        on_update: Option<ReferentialAction>,
7856        #[serde(default)]
7857        modifiers: ConstraintModifiers,
7858    },
7859    Check {
7860        name: Option<Identifier>,
7861        expression: Expression,
7862        #[serde(default)]
7863        modifiers: ConstraintModifiers,
7864    },
7865    /// ClickHouse ASSUME constraint (query optimization assumption)
7866    Assume {
7867        name: Option<Identifier>,
7868        expression: Expression,
7869    },
7870    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7871    Default {
7872        name: Option<Identifier>,
7873        expression: Expression,
7874        column: Identifier,
7875    },
7876    /// INDEX / KEY constraint (MySQL)
7877    Index {
7878        name: Option<Identifier>,
7879        columns: Vec<Identifier>,
7880        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7881        #[serde(default)]
7882        kind: Option<String>,
7883        #[serde(default)]
7884        modifiers: ConstraintModifiers,
7885        /// True if KEY keyword was used instead of INDEX
7886        #[serde(default)]
7887        use_key_keyword: bool,
7888        /// ClickHouse: indexed expression (instead of columns)
7889        #[serde(default, skip_serializing_if = "Option::is_none")]
7890        expression: Option<Box<Expression>>,
7891        /// ClickHouse: TYPE type_func(args)
7892        #[serde(default, skip_serializing_if = "Option::is_none")]
7893        index_type: Option<Box<Expression>>,
7894        /// ClickHouse: GRANULARITY n
7895        #[serde(default, skip_serializing_if = "Option::is_none")]
7896        granularity: Option<Box<Expression>>,
7897    },
7898    /// ClickHouse PROJECTION definition
7899    Projection {
7900        name: Identifier,
7901        expression: Expression,
7902    },
7903    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7904    Like {
7905        source: TableRef,
7906        /// Options as (INCLUDING|EXCLUDING, property) pairs
7907        options: Vec<(LikeOptionAction, String)>,
7908    },
7909    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7910    PeriodForSystemTime {
7911        start_col: Identifier,
7912        end_col: Identifier,
7913    },
7914    /// PostgreSQL EXCLUDE constraint
7915    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7916    Exclude {
7917        name: Option<Identifier>,
7918        /// Index access method (gist, btree, etc.)
7919        #[serde(default)]
7920        using: Option<String>,
7921        /// Elements: (expression, operator) pairs
7922        elements: Vec<ExcludeElement>,
7923        /// INCLUDE columns
7924        #[serde(default)]
7925        include_columns: Vec<Identifier>,
7926        /// WHERE predicate
7927        #[serde(default)]
7928        where_clause: Option<Box<Expression>>,
7929        /// WITH (storage_parameters)
7930        #[serde(default)]
7931        with_params: Vec<(String, String)>,
7932        /// USING INDEX TABLESPACE tablespace_name
7933        #[serde(default)]
7934        using_index_tablespace: Option<String>,
7935        #[serde(default)]
7936        modifiers: ConstraintModifiers,
7937    },
7938    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7939    Tags(Tags),
7940    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7941    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7942    /// for all deferrable constraints in the table
7943    InitiallyDeferred {
7944        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7945        deferred: bool,
7946    },
7947}
7948
7949/// Element in an EXCLUDE constraint: expression WITH operator
7950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7951#[cfg_attr(feature = "bindings", derive(TS))]
7952pub struct ExcludeElement {
7953    /// The column expression (may include operator class, ordering, nulls)
7954    pub expression: String,
7955    /// The operator (e.g., &&, =)
7956    pub operator: String,
7957}
7958
7959/// Action for LIKE clause options
7960#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7961#[cfg_attr(feature = "bindings", derive(TS))]
7962pub enum LikeOptionAction {
7963    Including,
7964    Excluding,
7965}
7966
7967/// MATCH type for foreign keys
7968#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7969#[cfg_attr(feature = "bindings", derive(TS))]
7970pub enum MatchType {
7971    Full,
7972    Partial,
7973    Simple,
7974}
7975
7976/// Foreign key reference
7977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7978#[cfg_attr(feature = "bindings", derive(TS))]
7979pub struct ForeignKeyRef {
7980    pub table: TableRef,
7981    pub columns: Vec<Identifier>,
7982    pub on_delete: Option<ReferentialAction>,
7983    pub on_update: Option<ReferentialAction>,
7984    /// True if ON UPDATE appears before ON DELETE in the original SQL
7985    #[serde(default)]
7986    pub on_update_first: bool,
7987    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7988    #[serde(default)]
7989    pub match_type: Option<MatchType>,
7990    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7991    #[serde(default)]
7992    pub match_after_actions: bool,
7993    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7994    #[serde(default)]
7995    pub constraint_name: Option<String>,
7996    /// DEFERRABLE / NOT DEFERRABLE
7997    #[serde(default)]
7998    pub deferrable: Option<bool>,
7999    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
8000    #[serde(default)]
8001    pub has_foreign_key_keywords: bool,
8002}
8003
8004/// Referential action for foreign keys
8005#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8006#[cfg_attr(feature = "bindings", derive(TS))]
8007pub enum ReferentialAction {
8008    Cascade,
8009    SetNull,
8010    SetDefault,
8011    Restrict,
8012    NoAction,
8013}
8014
8015/// DROP TABLE statement
8016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8017#[cfg_attr(feature = "bindings", derive(TS))]
8018pub struct DropTable {
8019    pub names: Vec<TableRef>,
8020    pub if_exists: bool,
8021    pub cascade: bool,
8022    /// Oracle: CASCADE CONSTRAINTS
8023    #[serde(default)]
8024    pub cascade_constraints: bool,
8025    /// Oracle: PURGE
8026    #[serde(default)]
8027    pub purge: bool,
8028    /// Comments that appear before the DROP keyword (e.g., leading line comments)
8029    #[serde(default)]
8030    pub leading_comments: Vec<String>,
8031    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
8032    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
8033    #[serde(default, skip_serializing_if = "Option::is_none")]
8034    pub object_id_args: Option<String>,
8035    /// ClickHouse: SYNC modifier
8036    #[serde(default)]
8037    pub sync: bool,
8038    /// Snowflake: DROP ICEBERG TABLE
8039    #[serde(default)]
8040    pub iceberg: bool,
8041    /// RESTRICT modifier (opposite of CASCADE)
8042    #[serde(default)]
8043    pub restrict: bool,
8044}
8045
8046impl DropTable {
8047    pub fn new(name: impl Into<String>) -> Self {
8048        Self {
8049            names: vec![TableRef::new(name)],
8050            if_exists: false,
8051            cascade: false,
8052            cascade_constraints: false,
8053            purge: false,
8054            leading_comments: Vec::new(),
8055            object_id_args: None,
8056            sync: false,
8057            iceberg: false,
8058            restrict: false,
8059        }
8060    }
8061}
8062
8063/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
8064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8065#[cfg_attr(feature = "bindings", derive(TS))]
8066pub struct Undrop {
8067    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
8068    pub kind: String,
8069    /// The object name
8070    pub name: TableRef,
8071    /// IF EXISTS clause
8072    #[serde(default)]
8073    pub if_exists: bool,
8074}
8075
8076/// ALTER TABLE statement
8077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8078#[cfg_attr(feature = "bindings", derive(TS))]
8079pub struct AlterTable {
8080    pub name: TableRef,
8081    pub actions: Vec<AlterTableAction>,
8082    /// IF EXISTS clause
8083    #[serde(default)]
8084    pub if_exists: bool,
8085    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8086    #[serde(default, skip_serializing_if = "Option::is_none")]
8087    pub algorithm: Option<String>,
8088    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8089    #[serde(default, skip_serializing_if = "Option::is_none")]
8090    pub lock: Option<String>,
8091    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8092    #[serde(default, skip_serializing_if = "Option::is_none")]
8093    pub with_check: Option<String>,
8094    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8095    #[serde(default, skip_serializing_if = "Option::is_none")]
8096    pub partition: Option<Vec<(Identifier, Expression)>>,
8097    /// ClickHouse: ON CLUSTER clause for distributed DDL
8098    #[serde(default, skip_serializing_if = "Option::is_none")]
8099    pub on_cluster: Option<OnCluster>,
8100    /// Snowflake: ALTER ICEBERG TABLE
8101    #[serde(default, skip_serializing_if = "Option::is_none")]
8102    pub table_modifier: Option<String>,
8103}
8104
8105impl AlterTable {
8106    pub fn new(name: impl Into<String>) -> Self {
8107        Self {
8108            name: TableRef::new(name),
8109            actions: Vec::new(),
8110            if_exists: false,
8111            algorithm: None,
8112            lock: None,
8113            with_check: None,
8114            partition: None,
8115            on_cluster: None,
8116            table_modifier: None,
8117        }
8118    }
8119}
8120
8121/// Column position for ADD COLUMN (MySQL/MariaDB)
8122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8123#[cfg_attr(feature = "bindings", derive(TS))]
8124pub enum ColumnPosition {
8125    First,
8126    After(Identifier),
8127}
8128
8129/// Actions for ALTER TABLE
8130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8131#[cfg_attr(feature = "bindings", derive(TS))]
8132pub enum AlterTableAction {
8133    AddColumn {
8134        column: ColumnDef,
8135        if_not_exists: bool,
8136        position: Option<ColumnPosition>,
8137    },
8138    DropColumn {
8139        name: Identifier,
8140        if_exists: bool,
8141        cascade: bool,
8142    },
8143    RenameColumn {
8144        old_name: Identifier,
8145        new_name: Identifier,
8146        if_exists: bool,
8147    },
8148    AlterColumn {
8149        name: Identifier,
8150        action: AlterColumnAction,
8151        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8152        #[serde(default)]
8153        use_modify_keyword: bool,
8154    },
8155    RenameTable(TableRef),
8156    AddConstraint(TableConstraint),
8157    DropConstraint {
8158        name: Identifier,
8159        if_exists: bool,
8160    },
8161    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8162    DropForeignKey {
8163        name: Identifier,
8164    },
8165    /// DROP PARTITION action (Hive/BigQuery)
8166    DropPartition {
8167        /// List of partitions to drop (each partition is a list of key=value pairs)
8168        partitions: Vec<Vec<(Identifier, Expression)>>,
8169        if_exists: bool,
8170    },
8171    /// ADD PARTITION action (Hive/Spark)
8172    AddPartition {
8173        /// The partition expression
8174        partition: Expression,
8175        if_not_exists: bool,
8176        location: Option<Expression>,
8177    },
8178    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8179    Delete {
8180        where_clause: Expression,
8181    },
8182    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8183    SwapWith(TableRef),
8184    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8185    SetProperty {
8186        properties: Vec<(String, Expression)>,
8187    },
8188    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8189    UnsetProperty {
8190        properties: Vec<String>,
8191    },
8192    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8193    ClusterBy {
8194        expressions: Vec<Expression>,
8195    },
8196    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8197    SetTag {
8198        expressions: Vec<(String, Expression)>,
8199    },
8200    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8201    UnsetTag {
8202        names: Vec<String>,
8203    },
8204    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8205    SetOptions {
8206        expressions: Vec<Expression>,
8207    },
8208    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8209    AlterIndex {
8210        name: Identifier,
8211        visible: bool,
8212    },
8213    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8214    SetAttribute {
8215        attribute: String,
8216    },
8217    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8218    SetStageFileFormat {
8219        options: Option<Expression>,
8220    },
8221    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8222    SetStageCopyOptions {
8223        options: Option<Expression>,
8224    },
8225    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8226    AddColumns {
8227        columns: Vec<ColumnDef>,
8228        cascade: bool,
8229    },
8230    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8231    DropColumns {
8232        names: Vec<Identifier>,
8233    },
8234    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8235    /// In SingleStore, data_type can be omitted for simple column renames
8236    ChangeColumn {
8237        old_name: Identifier,
8238        new_name: Identifier,
8239        #[serde(default, skip_serializing_if = "Option::is_none")]
8240        data_type: Option<DataType>,
8241        comment: Option<String>,
8242        #[serde(default)]
8243        cascade: bool,
8244    },
8245    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8246    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8247    AlterSortKey {
8248        /// AUTO or NONE keyword
8249        this: Option<String>,
8250        /// Column list for (col1, col2) syntax
8251        expressions: Vec<Expression>,
8252        /// Whether COMPOUND keyword was present
8253        compound: bool,
8254    },
8255    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8256    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8257    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8258    AlterDistStyle {
8259        /// Distribution style: ALL, EVEN, AUTO, or KEY
8260        style: String,
8261        /// DISTKEY column (only when style is KEY)
8262        distkey: Option<Identifier>,
8263    },
8264    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8265    SetTableProperties {
8266        properties: Vec<(Expression, Expression)>,
8267    },
8268    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8269    SetLocation {
8270        location: String,
8271    },
8272    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8273    SetFileFormat {
8274        format: String,
8275    },
8276    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8277    ReplacePartition {
8278        partition: Expression,
8279        source: Option<Box<Expression>>,
8280    },
8281    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8282    Raw {
8283        sql: String,
8284    },
8285}
8286
8287/// Actions for ALTER COLUMN
8288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8289#[cfg_attr(feature = "bindings", derive(TS))]
8290pub enum AlterColumnAction {
8291    SetDataType {
8292        data_type: DataType,
8293        /// USING expression for type conversion (PostgreSQL)
8294        using: Option<Expression>,
8295        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8296        #[serde(default, skip_serializing_if = "Option::is_none")]
8297        collate: Option<String>,
8298    },
8299    SetDefault(Expression),
8300    DropDefault,
8301    SetNotNull,
8302    DropNotNull,
8303    /// Set column comment
8304    Comment(String),
8305    /// MySQL: SET VISIBLE
8306    SetVisible,
8307    /// MySQL: SET INVISIBLE
8308    SetInvisible,
8309}
8310
8311/// CREATE INDEX statement
8312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8313#[cfg_attr(feature = "bindings", derive(TS))]
8314pub struct CreateIndex {
8315    pub name: Identifier,
8316    pub table: TableRef,
8317    pub columns: Vec<IndexColumn>,
8318    pub unique: bool,
8319    pub if_not_exists: bool,
8320    pub using: Option<String>,
8321    /// TSQL CLUSTERED/NONCLUSTERED modifier
8322    #[serde(default)]
8323    pub clustered: Option<String>,
8324    /// PostgreSQL CONCURRENTLY modifier
8325    #[serde(default)]
8326    pub concurrently: bool,
8327    /// PostgreSQL WHERE clause for partial indexes
8328    #[serde(default)]
8329    pub where_clause: Option<Box<Expression>>,
8330    /// PostgreSQL INCLUDE columns
8331    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8332    pub include_columns: Vec<Identifier>,
8333    /// TSQL WITH options (e.g., allow_page_locks=on)
8334    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8335    pub with_options: Vec<(String, String)>,
8336    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8337    #[serde(default)]
8338    pub on_filegroup: Option<String>,
8339}
8340
8341impl CreateIndex {
8342    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8343        Self {
8344            name: Identifier::new(name),
8345            table: TableRef::new(table),
8346            columns: Vec::new(),
8347            unique: false,
8348            if_not_exists: false,
8349            using: None,
8350            clustered: None,
8351            concurrently: false,
8352            where_clause: None,
8353            include_columns: Vec::new(),
8354            with_options: Vec::new(),
8355            on_filegroup: None,
8356        }
8357    }
8358}
8359
8360/// Index column specification
8361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8362#[cfg_attr(feature = "bindings", derive(TS))]
8363pub struct IndexColumn {
8364    pub column: Identifier,
8365    pub desc: bool,
8366    /// Explicit ASC keyword was present
8367    #[serde(default)]
8368    pub asc: bool,
8369    pub nulls_first: Option<bool>,
8370    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8371    #[serde(default, skip_serializing_if = "Option::is_none")]
8372    pub opclass: Option<String>,
8373}
8374
8375/// DROP INDEX statement
8376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8377#[cfg_attr(feature = "bindings", derive(TS))]
8378pub struct DropIndex {
8379    pub name: TableRef,
8380    pub table: Option<TableRef>,
8381    pub if_exists: bool,
8382    /// PostgreSQL CONCURRENTLY modifier
8383    #[serde(default)]
8384    pub concurrently: bool,
8385}
8386
8387impl DropIndex {
8388    pub fn new(name: impl Into<String>) -> Self {
8389        Self {
8390            name: TableRef::new(name),
8391            table: None,
8392            if_exists: false,
8393            concurrently: false,
8394        }
8395    }
8396}
8397
8398/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8400#[cfg_attr(feature = "bindings", derive(TS))]
8401pub struct ViewColumn {
8402    pub name: Identifier,
8403    pub comment: Option<String>,
8404    /// BigQuery: OPTIONS (key=value, ...) on column
8405    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8406    pub options: Vec<Expression>,
8407}
8408
8409impl ViewColumn {
8410    pub fn new(name: impl Into<String>) -> Self {
8411        Self {
8412            name: Identifier::new(name),
8413            comment: None,
8414            options: Vec::new(),
8415        }
8416    }
8417
8418    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8419        Self {
8420            name: Identifier::new(name),
8421            comment: Some(comment.into()),
8422            options: Vec::new(),
8423        }
8424    }
8425}
8426
8427/// CREATE VIEW statement
8428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8429#[cfg_attr(feature = "bindings", derive(TS))]
8430pub struct CreateView {
8431    pub name: TableRef,
8432    pub columns: Vec<ViewColumn>,
8433    pub query: Expression,
8434    pub or_replace: bool,
8435    /// TSQL: CREATE OR ALTER
8436    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8437    pub or_alter: bool,
8438    pub if_not_exists: bool,
8439    pub materialized: bool,
8440    pub temporary: bool,
8441    /// Snowflake: SECURE VIEW
8442    #[serde(default)]
8443    pub secure: bool,
8444    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8445    #[serde(skip_serializing_if = "Option::is_none")]
8446    pub algorithm: Option<String>,
8447    /// MySQL: DEFINER=user@host
8448    #[serde(skip_serializing_if = "Option::is_none")]
8449    pub definer: Option<String>,
8450    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8451    #[serde(skip_serializing_if = "Option::is_none")]
8452    pub security: Option<FunctionSecurity>,
8453    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8454    #[serde(default = "default_true")]
8455    pub security_sql_style: bool,
8456    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8457    #[serde(default)]
8458    pub security_after_name: bool,
8459    /// Whether the query was parenthesized: AS (SELECT ...)
8460    #[serde(default)]
8461    pub query_parenthesized: bool,
8462    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8463    #[serde(skip_serializing_if = "Option::is_none")]
8464    pub locking_mode: Option<String>,
8465    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8466    #[serde(skip_serializing_if = "Option::is_none")]
8467    pub locking_access: Option<String>,
8468    /// Snowflake: COPY GRANTS
8469    #[serde(default)]
8470    pub copy_grants: bool,
8471    /// Snowflake: COMMENT = 'text'
8472    #[serde(skip_serializing_if = "Option::is_none", default)]
8473    pub comment: Option<String>,
8474    /// Snowflake: WITH ROW ACCESS POLICY ... clause
8475    #[serde(skip_serializing_if = "Option::is_none", default)]
8476    pub row_access_policy: Option<String>,
8477    /// Snowflake: TAG (name='value', ...)
8478    #[serde(default)]
8479    pub tags: Vec<(String, String)>,
8480    /// BigQuery: OPTIONS (key=value, ...)
8481    #[serde(default)]
8482    pub options: Vec<Expression>,
8483    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8484    #[serde(skip_serializing_if = "Option::is_none", default)]
8485    pub build: Option<String>,
8486    /// Doris: REFRESH property for materialized views
8487    #[serde(skip_serializing_if = "Option::is_none", default)]
8488    pub refresh: Option<Box<RefreshTriggerProperty>>,
8489    /// Doris: Schema with typed column definitions for materialized views
8490    /// This is used instead of `columns` when the view has typed column definitions
8491    #[serde(skip_serializing_if = "Option::is_none", default)]
8492    pub schema: Option<Box<Schema>>,
8493    /// Doris: KEY (columns) for materialized views
8494    #[serde(skip_serializing_if = "Option::is_none", default)]
8495    pub unique_key: Option<Box<UniqueKeyProperty>>,
8496    /// Redshift: WITH NO SCHEMA BINDING
8497    #[serde(default)]
8498    pub no_schema_binding: bool,
8499    /// Redshift: AUTO REFRESH YES|NO for materialized views
8500    #[serde(skip_serializing_if = "Option::is_none", default)]
8501    pub auto_refresh: Option<bool>,
8502    /// ClickHouse: POPULATE / EMPTY before AS in materialized views
8503    #[serde(skip_serializing_if = "Option::is_none", default)]
8504    pub clickhouse_population: Option<String>,
8505    /// ClickHouse: ON CLUSTER clause
8506    #[serde(default, skip_serializing_if = "Option::is_none")]
8507    pub on_cluster: Option<OnCluster>,
8508    /// ClickHouse: TO destination_table
8509    #[serde(default, skip_serializing_if = "Option::is_none")]
8510    pub to_table: Option<TableRef>,
8511    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8512    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8513    pub table_properties: Vec<Expression>,
8514}
8515
8516impl CreateView {
8517    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8518        Self {
8519            name: TableRef::new(name),
8520            columns: Vec::new(),
8521            query,
8522            or_replace: false,
8523            or_alter: false,
8524            if_not_exists: false,
8525            materialized: false,
8526            temporary: false,
8527            secure: false,
8528            algorithm: None,
8529            definer: None,
8530            security: None,
8531            security_sql_style: true,
8532            security_after_name: false,
8533            query_parenthesized: false,
8534            locking_mode: None,
8535            locking_access: None,
8536            copy_grants: false,
8537            comment: None,
8538            row_access_policy: None,
8539            tags: Vec::new(),
8540            options: Vec::new(),
8541            build: None,
8542            refresh: None,
8543            schema: None,
8544            unique_key: None,
8545            no_schema_binding: false,
8546            auto_refresh: None,
8547            clickhouse_population: None,
8548            on_cluster: None,
8549            to_table: None,
8550            table_properties: Vec::new(),
8551        }
8552    }
8553}
8554
8555/// DROP VIEW statement
8556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8557#[cfg_attr(feature = "bindings", derive(TS))]
8558pub struct DropView {
8559    pub name: TableRef,
8560    pub if_exists: bool,
8561    pub materialized: bool,
8562}
8563
8564impl DropView {
8565    pub fn new(name: impl Into<String>) -> Self {
8566        Self {
8567            name: TableRef::new(name),
8568            if_exists: false,
8569            materialized: false,
8570        }
8571    }
8572}
8573
8574/// TRUNCATE TABLE statement
8575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8576#[cfg_attr(feature = "bindings", derive(TS))]
8577pub struct Truncate {
8578    /// Target of TRUNCATE (TABLE vs DATABASE)
8579    #[serde(default)]
8580    pub target: TruncateTarget,
8581    /// IF EXISTS clause
8582    #[serde(default)]
8583    pub if_exists: bool,
8584    pub table: TableRef,
8585    /// ClickHouse: ON CLUSTER clause for distributed DDL
8586    #[serde(default, skip_serializing_if = "Option::is_none")]
8587    pub on_cluster: Option<OnCluster>,
8588    pub cascade: bool,
8589    /// Additional tables for multi-table TRUNCATE
8590    #[serde(default)]
8591    pub extra_tables: Vec<TruncateTableEntry>,
8592    /// RESTART IDENTITY or CONTINUE IDENTITY
8593    #[serde(default)]
8594    pub identity: Option<TruncateIdentity>,
8595    /// RESTRICT option (alternative to CASCADE)
8596    #[serde(default)]
8597    pub restrict: bool,
8598    /// Hive PARTITION clause: PARTITION(key=value, ...)
8599    #[serde(default, skip_serializing_if = "Option::is_none")]
8600    pub partition: Option<Box<Expression>>,
8601}
8602
8603/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8605#[cfg_attr(feature = "bindings", derive(TS))]
8606pub struct TruncateTableEntry {
8607    pub table: TableRef,
8608    /// Whether the table has a * suffix (inherit children)
8609    #[serde(default)]
8610    pub star: bool,
8611}
8612
8613/// TRUNCATE target type
8614#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8615#[cfg_attr(feature = "bindings", derive(TS))]
8616pub enum TruncateTarget {
8617    Table,
8618    Database,
8619}
8620
8621impl Default for TruncateTarget {
8622    fn default() -> Self {
8623        TruncateTarget::Table
8624    }
8625}
8626
8627/// TRUNCATE identity option
8628#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8629#[cfg_attr(feature = "bindings", derive(TS))]
8630pub enum TruncateIdentity {
8631    Restart,
8632    Continue,
8633}
8634
8635impl Truncate {
8636    pub fn new(table: impl Into<String>) -> Self {
8637        Self {
8638            target: TruncateTarget::Table,
8639            if_exists: false,
8640            table: TableRef::new(table),
8641            on_cluster: None,
8642            cascade: false,
8643            extra_tables: Vec::new(),
8644            identity: None,
8645            restrict: false,
8646            partition: None,
8647        }
8648    }
8649}
8650
8651/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8653#[cfg_attr(feature = "bindings", derive(TS))]
8654pub struct Use {
8655    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8656    pub kind: Option<UseKind>,
8657    /// The name of the object
8658    pub this: Identifier,
8659}
8660
8661/// Kind of USE statement
8662#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8663#[cfg_attr(feature = "bindings", derive(TS))]
8664pub enum UseKind {
8665    Database,
8666    Schema,
8667    Role,
8668    Warehouse,
8669    Catalog,
8670    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8671    SecondaryRoles,
8672}
8673
8674/// SET variable statement
8675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8676#[cfg_attr(feature = "bindings", derive(TS))]
8677pub struct SetStatement {
8678    /// The items being set
8679    pub items: Vec<SetItem>,
8680}
8681
8682/// A single SET item (variable assignment)
8683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8684#[cfg_attr(feature = "bindings", derive(TS))]
8685pub struct SetItem {
8686    /// The variable name
8687    pub name: Expression,
8688    /// The value to set
8689    pub value: Expression,
8690    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8691    pub kind: Option<String>,
8692    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8693    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8694    pub no_equals: bool,
8695}
8696
8697/// CACHE TABLE statement (Spark)
8698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8699#[cfg_attr(feature = "bindings", derive(TS))]
8700pub struct Cache {
8701    /// The table to cache
8702    pub table: Identifier,
8703    /// LAZY keyword - defer caching until first use
8704    pub lazy: bool,
8705    /// Optional OPTIONS clause (key-value pairs)
8706    pub options: Vec<(Expression, Expression)>,
8707    /// Optional AS clause with query
8708    pub query: Option<Expression>,
8709}
8710
8711/// UNCACHE TABLE statement (Spark)
8712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8713#[cfg_attr(feature = "bindings", derive(TS))]
8714pub struct Uncache {
8715    /// The table to uncache
8716    pub table: Identifier,
8717    /// IF EXISTS clause
8718    pub if_exists: bool,
8719}
8720
8721/// LOAD DATA statement (Hive)
8722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8723#[cfg_attr(feature = "bindings", derive(TS))]
8724pub struct LoadData {
8725    /// LOCAL keyword - load from local filesystem
8726    pub local: bool,
8727    /// The path to load data from (INPATH value)
8728    pub inpath: String,
8729    /// Whether to overwrite existing data
8730    pub overwrite: bool,
8731    /// The target table
8732    pub table: Expression,
8733    /// Optional PARTITION clause with key-value pairs
8734    pub partition: Vec<(Identifier, Expression)>,
8735    /// Optional INPUTFORMAT clause
8736    pub input_format: Option<String>,
8737    /// Optional SERDE clause
8738    pub serde: Option<String>,
8739}
8740
8741/// PRAGMA statement (SQLite)
8742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8743#[cfg_attr(feature = "bindings", derive(TS))]
8744pub struct Pragma {
8745    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8746    pub schema: Option<Identifier>,
8747    /// The pragma name
8748    pub name: Identifier,
8749    /// Optional value for assignment (PRAGMA name = value)
8750    pub value: Option<Expression>,
8751    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8752    pub args: Vec<Expression>,
8753    /// Whether this pragma should be generated using assignment syntax.
8754    #[serde(default)]
8755    pub use_assignment_syntax: bool,
8756}
8757
8758/// A privilege with optional column list for GRANT/REVOKE
8759/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8761#[cfg_attr(feature = "bindings", derive(TS))]
8762pub struct Privilege {
8763    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8764    pub name: String,
8765    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8766    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8767    pub columns: Vec<String>,
8768}
8769
8770/// Principal in GRANT/REVOKE (user, role, etc.)
8771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8772#[cfg_attr(feature = "bindings", derive(TS))]
8773pub struct GrantPrincipal {
8774    /// The name of the principal
8775    pub name: Identifier,
8776    /// Whether prefixed with ROLE keyword
8777    pub is_role: bool,
8778    /// Whether prefixed with GROUP keyword (Redshift)
8779    #[serde(default)]
8780    pub is_group: bool,
8781    /// Whether prefixed with SHARE keyword (Snowflake)
8782    #[serde(default)]
8783    pub is_share: bool,
8784}
8785
8786/// GRANT statement
8787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8788#[cfg_attr(feature = "bindings", derive(TS))]
8789pub struct Grant {
8790    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8791    pub privileges: Vec<Privilege>,
8792    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8793    pub kind: Option<String>,
8794    /// The object to grant on
8795    pub securable: Identifier,
8796    /// Function parameter types (for FUNCTION kind)
8797    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8798    pub function_params: Vec<String>,
8799    /// The grantees
8800    pub principals: Vec<GrantPrincipal>,
8801    /// WITH GRANT OPTION
8802    pub grant_option: bool,
8803    /// TSQL: AS principal (the grantor role)
8804    #[serde(default, skip_serializing_if = "Option::is_none")]
8805    pub as_principal: Option<Identifier>,
8806}
8807
8808/// REVOKE statement
8809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8810#[cfg_attr(feature = "bindings", derive(TS))]
8811pub struct Revoke {
8812    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8813    pub privileges: Vec<Privilege>,
8814    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8815    pub kind: Option<String>,
8816    /// The object to revoke from
8817    pub securable: Identifier,
8818    /// Function parameter types (for FUNCTION kind)
8819    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8820    pub function_params: Vec<String>,
8821    /// The grantees
8822    pub principals: Vec<GrantPrincipal>,
8823    /// GRANT OPTION FOR
8824    pub grant_option: bool,
8825    /// CASCADE
8826    pub cascade: bool,
8827    /// RESTRICT
8828    #[serde(default)]
8829    pub restrict: bool,
8830}
8831
8832/// COMMENT ON statement
8833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8834#[cfg_attr(feature = "bindings", derive(TS))]
8835pub struct Comment {
8836    /// The object being commented on
8837    pub this: Expression,
8838    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8839    pub kind: String,
8840    /// The comment text expression
8841    pub expression: Expression,
8842    /// IF EXISTS clause
8843    pub exists: bool,
8844    /// MATERIALIZED keyword
8845    pub materialized: bool,
8846}
8847
8848// ============================================================================
8849// Phase 4: Additional DDL Statements
8850// ============================================================================
8851
8852/// ALTER VIEW statement
8853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8854#[cfg_attr(feature = "bindings", derive(TS))]
8855pub struct AlterView {
8856    pub name: TableRef,
8857    pub actions: Vec<AlterViewAction>,
8858    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8859    #[serde(default, skip_serializing_if = "Option::is_none")]
8860    pub algorithm: Option<String>,
8861    /// MySQL: DEFINER = 'user'@'host'
8862    #[serde(default, skip_serializing_if = "Option::is_none")]
8863    pub definer: Option<String>,
8864    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8865    #[serde(default, skip_serializing_if = "Option::is_none")]
8866    pub sql_security: Option<String>,
8867    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8868    #[serde(default, skip_serializing_if = "Option::is_none")]
8869    pub with_option: Option<String>,
8870    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8871    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8872    pub columns: Vec<ViewColumn>,
8873}
8874
8875/// Actions for ALTER VIEW
8876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8877#[cfg_attr(feature = "bindings", derive(TS))]
8878pub enum AlterViewAction {
8879    /// Rename the view
8880    Rename(TableRef),
8881    /// Change owner
8882    OwnerTo(Identifier),
8883    /// Set schema
8884    SetSchema(Identifier),
8885    /// Set authorization (Trino/Presto)
8886    SetAuthorization(String),
8887    /// Alter column
8888    AlterColumn {
8889        name: Identifier,
8890        action: AlterColumnAction,
8891    },
8892    /// Redefine view as query (SELECT, UNION, etc.)
8893    AsSelect(Box<Expression>),
8894    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8895    SetTblproperties(Vec<(String, String)>),
8896    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8897    UnsetTblproperties(Vec<String>),
8898}
8899
8900impl AlterView {
8901    pub fn new(name: impl Into<String>) -> Self {
8902        Self {
8903            name: TableRef::new(name),
8904            actions: Vec::new(),
8905            algorithm: None,
8906            definer: None,
8907            sql_security: None,
8908            with_option: None,
8909            columns: Vec::new(),
8910        }
8911    }
8912}
8913
8914/// ALTER INDEX statement
8915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8916#[cfg_attr(feature = "bindings", derive(TS))]
8917pub struct AlterIndex {
8918    pub name: Identifier,
8919    pub table: Option<TableRef>,
8920    pub actions: Vec<AlterIndexAction>,
8921}
8922
8923/// Actions for ALTER INDEX
8924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8925#[cfg_attr(feature = "bindings", derive(TS))]
8926pub enum AlterIndexAction {
8927    /// Rename the index
8928    Rename(Identifier),
8929    /// Set tablespace
8930    SetTablespace(Identifier),
8931    /// Set visibility (MySQL)
8932    Visible(bool),
8933}
8934
8935impl AlterIndex {
8936    pub fn new(name: impl Into<String>) -> Self {
8937        Self {
8938            name: Identifier::new(name),
8939            table: None,
8940            actions: Vec::new(),
8941        }
8942    }
8943}
8944
8945/// CREATE SCHEMA statement
8946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8947#[cfg_attr(feature = "bindings", derive(TS))]
8948pub struct CreateSchema {
8949    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8950    pub name: Vec<Identifier>,
8951    pub if_not_exists: bool,
8952    pub authorization: Option<Identifier>,
8953    /// CLONE source parts, possibly dot-qualified
8954    #[serde(default)]
8955    pub clone_from: Option<Vec<Identifier>>,
8956    /// AT/BEFORE clause for time travel (Snowflake)
8957    #[serde(default)]
8958    pub at_clause: Option<Expression>,
8959    /// Schema properties like DEFAULT COLLATE
8960    #[serde(default)]
8961    pub properties: Vec<Expression>,
8962    /// Leading comments before the statement
8963    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8964    pub leading_comments: Vec<String>,
8965}
8966
8967impl CreateSchema {
8968    pub fn new(name: impl Into<String>) -> Self {
8969        Self {
8970            name: vec![Identifier::new(name)],
8971            if_not_exists: false,
8972            authorization: None,
8973            clone_from: None,
8974            at_clause: None,
8975            properties: Vec::new(),
8976            leading_comments: Vec::new(),
8977        }
8978    }
8979}
8980
8981/// DROP SCHEMA statement
8982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8983#[cfg_attr(feature = "bindings", derive(TS))]
8984pub struct DropSchema {
8985    pub name: Identifier,
8986    pub if_exists: bool,
8987    pub cascade: bool,
8988}
8989
8990impl DropSchema {
8991    pub fn new(name: impl Into<String>) -> Self {
8992        Self {
8993            name: Identifier::new(name),
8994            if_exists: false,
8995            cascade: false,
8996        }
8997    }
8998}
8999
9000/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
9001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9002#[cfg_attr(feature = "bindings", derive(TS))]
9003pub struct DropNamespace {
9004    pub name: Identifier,
9005    pub if_exists: bool,
9006    pub cascade: bool,
9007}
9008
9009impl DropNamespace {
9010    pub fn new(name: impl Into<String>) -> Self {
9011        Self {
9012            name: Identifier::new(name),
9013            if_exists: false,
9014            cascade: false,
9015        }
9016    }
9017}
9018
9019/// CREATE DATABASE statement
9020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9021#[cfg_attr(feature = "bindings", derive(TS))]
9022pub struct CreateDatabase {
9023    pub name: Identifier,
9024    pub if_not_exists: bool,
9025    pub options: Vec<DatabaseOption>,
9026    /// Snowflake CLONE source
9027    #[serde(default)]
9028    pub clone_from: Option<Identifier>,
9029    /// AT/BEFORE clause for time travel (Snowflake)
9030    #[serde(default)]
9031    pub at_clause: Option<Expression>,
9032}
9033
9034/// Database option
9035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9036#[cfg_attr(feature = "bindings", derive(TS))]
9037pub enum DatabaseOption {
9038    CharacterSet(String),
9039    Collate(String),
9040    Owner(Identifier),
9041    Template(Identifier),
9042    Encoding(String),
9043    Location(String),
9044}
9045
9046impl CreateDatabase {
9047    pub fn new(name: impl Into<String>) -> Self {
9048        Self {
9049            name: Identifier::new(name),
9050            if_not_exists: false,
9051            options: Vec::new(),
9052            clone_from: None,
9053            at_clause: None,
9054        }
9055    }
9056}
9057
9058/// DROP DATABASE statement
9059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9060#[cfg_attr(feature = "bindings", derive(TS))]
9061pub struct DropDatabase {
9062    pub name: Identifier,
9063    pub if_exists: bool,
9064    /// ClickHouse: SYNC modifier
9065    #[serde(default)]
9066    pub sync: bool,
9067}
9068
9069impl DropDatabase {
9070    pub fn new(name: impl Into<String>) -> Self {
9071        Self {
9072            name: Identifier::new(name),
9073            if_exists: false,
9074            sync: false,
9075        }
9076    }
9077}
9078
9079/// CREATE FUNCTION statement
9080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9081#[cfg_attr(feature = "bindings", derive(TS))]
9082pub struct CreateFunction {
9083    pub name: TableRef,
9084    pub parameters: Vec<FunctionParameter>,
9085    pub return_type: Option<DataType>,
9086    pub body: Option<FunctionBody>,
9087    pub or_replace: bool,
9088    /// TSQL: CREATE OR ALTER
9089    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9090    pub or_alter: bool,
9091    pub if_not_exists: bool,
9092    pub temporary: bool,
9093    pub language: Option<String>,
9094    pub deterministic: Option<bool>,
9095    pub returns_null_on_null_input: Option<bool>,
9096    pub security: Option<FunctionSecurity>,
9097    /// Whether parentheses were present in the original syntax
9098    #[serde(default = "default_true")]
9099    pub has_parens: bool,
9100    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9101    #[serde(default)]
9102    pub sql_data_access: Option<SqlDataAccess>,
9103    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9104    #[serde(default, skip_serializing_if = "Option::is_none")]
9105    pub returns_table_body: Option<String>,
9106    /// True if LANGUAGE clause appears before RETURNS clause
9107    #[serde(default)]
9108    pub language_first: bool,
9109    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9110    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9111    pub set_options: Vec<FunctionSetOption>,
9112    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9113    #[serde(default)]
9114    pub strict: bool,
9115    /// BigQuery: OPTIONS (key=value, ...)
9116    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9117    pub options: Vec<Expression>,
9118    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9119    #[serde(default)]
9120    pub is_table_function: bool,
9121    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9122    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9123    pub property_order: Vec<FunctionPropertyKind>,
9124    /// Hive: USING JAR|FILE|ARCHIVE '...'
9125    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9126    pub using_resources: Vec<FunctionUsingResource>,
9127    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9129    pub environment: Vec<Expression>,
9130    /// HANDLER 'handler_function' clause (Databricks)
9131    #[serde(default, skip_serializing_if = "Option::is_none")]
9132    pub handler: Option<String>,
9133    /// True when the HANDLER clause used Snowflake-style `HANDLER = 'fn'`
9134    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9135    pub handler_uses_eq: bool,
9136    /// Snowflake: RUNTIME_VERSION='3.11'
9137    #[serde(default, skip_serializing_if = "Option::is_none")]
9138    pub runtime_version: Option<String>,
9139    /// Snowflake: PACKAGES=('pkg1', 'pkg2')
9140    #[serde(default, skip_serializing_if = "Option::is_none")]
9141    pub packages: Option<Vec<String>>,
9142    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9143    #[serde(default, skip_serializing_if = "Option::is_none")]
9144    pub parameter_style: Option<String>,
9145}
9146
9147/// A SET option in CREATE FUNCTION (PostgreSQL)
9148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9149#[cfg_attr(feature = "bindings", derive(TS))]
9150pub struct FunctionSetOption {
9151    pub name: String,
9152    pub value: FunctionSetValue,
9153}
9154
9155/// The value of a SET option
9156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9157#[cfg_attr(feature = "bindings", derive(TS))]
9158pub enum FunctionSetValue {
9159    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9160    Value { value: String, use_to: bool },
9161    /// SET key FROM CURRENT
9162    FromCurrent,
9163}
9164
9165/// SQL data access characteristics for functions
9166#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9167#[cfg_attr(feature = "bindings", derive(TS))]
9168pub enum SqlDataAccess {
9169    /// NO SQL
9170    NoSql,
9171    /// CONTAINS SQL
9172    ContainsSql,
9173    /// READS SQL DATA
9174    ReadsSqlData,
9175    /// MODIFIES SQL DATA
9176    ModifiesSqlData,
9177}
9178
9179/// Types of properties in CREATE FUNCTION for tracking their original order
9180#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9181#[cfg_attr(feature = "bindings", derive(TS))]
9182pub enum FunctionPropertyKind {
9183    /// SET option
9184    Set,
9185    /// AS body
9186    As,
9187    /// Hive: USING JAR|FILE|ARCHIVE ...
9188    Using,
9189    /// LANGUAGE clause
9190    Language,
9191    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9192    Determinism,
9193    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9194    NullInput,
9195    /// SECURITY DEFINER/INVOKER
9196    Security,
9197    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9198    SqlDataAccess,
9199    /// OPTIONS clause (BigQuery)
9200    Options,
9201    /// ENVIRONMENT clause (Databricks)
9202    Environment,
9203    /// HANDLER clause (Databricks)
9204    Handler,
9205    /// Snowflake: RUNTIME_VERSION='...'
9206    RuntimeVersion,
9207    /// Snowflake: PACKAGES=(...)
9208    Packages,
9209    /// PARAMETER STYLE clause (Databricks)
9210    ParameterStyle,
9211}
9212
9213/// Hive CREATE FUNCTION resource in a USING clause
9214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9215#[cfg_attr(feature = "bindings", derive(TS))]
9216pub struct FunctionUsingResource {
9217    pub kind: String,
9218    pub uri: String,
9219}
9220
9221/// Function parameter
9222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9223#[cfg_attr(feature = "bindings", derive(TS))]
9224pub struct FunctionParameter {
9225    pub name: Option<Identifier>,
9226    pub data_type: DataType,
9227    pub mode: Option<ParameterMode>,
9228    pub default: Option<Expression>,
9229    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9230    #[serde(default, skip_serializing_if = "Option::is_none")]
9231    pub mode_text: Option<String>,
9232}
9233
9234/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9235#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9236#[cfg_attr(feature = "bindings", derive(TS))]
9237pub enum ParameterMode {
9238    In,
9239    Out,
9240    InOut,
9241    Variadic,
9242}
9243
9244/// Function body
9245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9246#[cfg_attr(feature = "bindings", derive(TS))]
9247pub enum FunctionBody {
9248    /// AS $$ ... $$ (dollar-quoted)
9249    Block(String),
9250    /// AS 'string' (single-quoted string literal body)
9251    StringLiteral(String),
9252    /// AS 'expression'
9253    Expression(Expression),
9254    /// EXTERNAL NAME 'library'
9255    External(String),
9256    /// RETURN expression
9257    Return(Expression),
9258    /// BEGIN ... END block with parsed statements
9259    Statements(Vec<Expression>),
9260    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9261    /// Stores (content, optional_tag)
9262    DollarQuoted {
9263        content: String,
9264        tag: Option<String>,
9265    },
9266    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9267    RawBlock(String),
9268}
9269
9270/// Function security (DEFINER, INVOKER, or NONE)
9271#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9272#[cfg_attr(feature = "bindings", derive(TS))]
9273pub enum FunctionSecurity {
9274    Definer,
9275    Invoker,
9276    /// StarRocks/MySQL: SECURITY NONE
9277    None,
9278}
9279
9280impl CreateFunction {
9281    pub fn new(name: impl Into<String>) -> Self {
9282        Self {
9283            name: TableRef::new(name),
9284            parameters: Vec::new(),
9285            return_type: None,
9286            body: None,
9287            or_replace: false,
9288            or_alter: false,
9289            if_not_exists: false,
9290            temporary: false,
9291            language: None,
9292            deterministic: None,
9293            returns_null_on_null_input: None,
9294            security: None,
9295            has_parens: true,
9296            sql_data_access: None,
9297            returns_table_body: None,
9298            language_first: false,
9299            set_options: Vec::new(),
9300            strict: false,
9301            options: Vec::new(),
9302            is_table_function: false,
9303            property_order: Vec::new(),
9304            using_resources: Vec::new(),
9305            environment: Vec::new(),
9306            handler: None,
9307            handler_uses_eq: false,
9308            runtime_version: None,
9309            packages: None,
9310            parameter_style: None,
9311        }
9312    }
9313}
9314
9315/// DROP FUNCTION statement
9316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9317#[cfg_attr(feature = "bindings", derive(TS))]
9318pub struct DropFunction {
9319    pub name: TableRef,
9320    pub parameters: Option<Vec<DataType>>,
9321    pub if_exists: bool,
9322    pub cascade: bool,
9323}
9324
9325impl DropFunction {
9326    pub fn new(name: impl Into<String>) -> Self {
9327        Self {
9328            name: TableRef::new(name),
9329            parameters: None,
9330            if_exists: false,
9331            cascade: false,
9332        }
9333    }
9334}
9335
9336/// CREATE PROCEDURE statement
9337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9338#[cfg_attr(feature = "bindings", derive(TS))]
9339pub struct CreateProcedure {
9340    pub name: TableRef,
9341    pub parameters: Vec<FunctionParameter>,
9342    pub body: Option<FunctionBody>,
9343    pub or_replace: bool,
9344    /// TSQL: CREATE OR ALTER
9345    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9346    pub or_alter: bool,
9347    pub if_not_exists: bool,
9348    pub language: Option<String>,
9349    pub security: Option<FunctionSecurity>,
9350    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9351    #[serde(default)]
9352    pub return_type: Option<DataType>,
9353    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9354    #[serde(default)]
9355    pub execute_as: Option<String>,
9356    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9357    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9358    pub with_options: Vec<String>,
9359    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9360    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9361    pub has_parens: bool,
9362    /// Whether the short form PROC was used (instead of PROCEDURE)
9363    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9364    pub use_proc_keyword: bool,
9365}
9366
9367impl CreateProcedure {
9368    pub fn new(name: impl Into<String>) -> Self {
9369        Self {
9370            name: TableRef::new(name),
9371            parameters: Vec::new(),
9372            body: None,
9373            or_replace: false,
9374            or_alter: false,
9375            if_not_exists: false,
9376            language: None,
9377            security: None,
9378            return_type: None,
9379            execute_as: None,
9380            with_options: Vec::new(),
9381            has_parens: true,
9382            use_proc_keyword: false,
9383        }
9384    }
9385}
9386
9387/// DROP PROCEDURE statement
9388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9389#[cfg_attr(feature = "bindings", derive(TS))]
9390pub struct DropProcedure {
9391    pub name: TableRef,
9392    pub parameters: Option<Vec<DataType>>,
9393    pub if_exists: bool,
9394    pub cascade: bool,
9395}
9396
9397impl DropProcedure {
9398    pub fn new(name: impl Into<String>) -> Self {
9399        Self {
9400            name: TableRef::new(name),
9401            parameters: None,
9402            if_exists: false,
9403            cascade: false,
9404        }
9405    }
9406}
9407
9408/// Sequence property tag for ordering
9409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9410#[cfg_attr(feature = "bindings", derive(TS))]
9411pub enum SeqPropKind {
9412    Start,
9413    Increment,
9414    Minvalue,
9415    Maxvalue,
9416    Cache,
9417    NoCache,
9418    Cycle,
9419    NoCycle,
9420    OwnedBy,
9421    Order,
9422    NoOrder,
9423    Comment,
9424    /// SHARING=<value> (Oracle)
9425    Sharing,
9426    /// KEEP (Oracle)
9427    Keep,
9428    /// NOKEEP (Oracle)
9429    NoKeep,
9430    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9431    Scale,
9432    /// NOSCALE (Oracle)
9433    NoScale,
9434    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9435    Shard,
9436    /// NOSHARD (Oracle)
9437    NoShard,
9438    /// SESSION (Oracle)
9439    Session,
9440    /// GLOBAL (Oracle)
9441    Global,
9442    /// NOCACHE (single word, Oracle)
9443    NoCacheWord,
9444    /// NOCYCLE (single word, Oracle)
9445    NoCycleWord,
9446    /// NOMINVALUE (single word, Oracle)
9447    NoMinvalueWord,
9448    /// NOMAXVALUE (single word, Oracle)
9449    NoMaxvalueWord,
9450}
9451
9452/// CREATE SYNONYM statement (TSQL)
9453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9454#[cfg_attr(feature = "bindings", derive(TS))]
9455pub struct CreateSynonym {
9456    /// The synonym name (can be qualified: schema.synonym_name)
9457    pub name: TableRef,
9458    /// The target object the synonym refers to
9459    pub target: TableRef,
9460}
9461
9462/// CREATE SEQUENCE statement
9463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9464#[cfg_attr(feature = "bindings", derive(TS))]
9465pub struct CreateSequence {
9466    pub name: TableRef,
9467    pub if_not_exists: bool,
9468    pub temporary: bool,
9469    #[serde(default)]
9470    pub or_replace: bool,
9471    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9472    #[serde(default, skip_serializing_if = "Option::is_none")]
9473    pub as_type: Option<DataType>,
9474    pub increment: Option<i64>,
9475    pub minvalue: Option<SequenceBound>,
9476    pub maxvalue: Option<SequenceBound>,
9477    pub start: Option<i64>,
9478    pub cache: Option<i64>,
9479    pub cycle: bool,
9480    pub owned_by: Option<TableRef>,
9481    /// Whether OWNED BY NONE was specified
9482    #[serde(default)]
9483    pub owned_by_none: bool,
9484    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9485    #[serde(default)]
9486    pub order: Option<bool>,
9487    /// Snowflake: COMMENT = 'value'
9488    #[serde(default)]
9489    pub comment: Option<String>,
9490    /// SHARING=<value> (Oracle)
9491    #[serde(default, skip_serializing_if = "Option::is_none")]
9492    pub sharing: Option<String>,
9493    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9494    #[serde(default, skip_serializing_if = "Option::is_none")]
9495    pub scale_modifier: Option<String>,
9496    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9497    #[serde(default, skip_serializing_if = "Option::is_none")]
9498    pub shard_modifier: Option<String>,
9499    /// Tracks the order in which properties appeared in the source
9500    #[serde(default)]
9501    pub property_order: Vec<SeqPropKind>,
9502}
9503
9504/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9506#[cfg_attr(feature = "bindings", derive(TS))]
9507pub enum SequenceBound {
9508    Value(i64),
9509    None,
9510}
9511
9512impl CreateSequence {
9513    pub fn new(name: impl Into<String>) -> Self {
9514        Self {
9515            name: TableRef::new(name),
9516            if_not_exists: false,
9517            temporary: false,
9518            or_replace: false,
9519            as_type: None,
9520            increment: None,
9521            minvalue: None,
9522            maxvalue: None,
9523            start: None,
9524            cache: None,
9525            cycle: false,
9526            owned_by: None,
9527            owned_by_none: false,
9528            order: None,
9529            comment: None,
9530            sharing: None,
9531            scale_modifier: None,
9532            shard_modifier: None,
9533            property_order: Vec::new(),
9534        }
9535    }
9536}
9537
9538/// DROP SEQUENCE statement
9539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9540#[cfg_attr(feature = "bindings", derive(TS))]
9541pub struct DropSequence {
9542    pub name: TableRef,
9543    pub if_exists: bool,
9544    pub cascade: bool,
9545}
9546
9547impl DropSequence {
9548    pub fn new(name: impl Into<String>) -> Self {
9549        Self {
9550            name: TableRef::new(name),
9551            if_exists: false,
9552            cascade: false,
9553        }
9554    }
9555}
9556
9557/// ALTER SEQUENCE statement
9558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9559#[cfg_attr(feature = "bindings", derive(TS))]
9560pub struct AlterSequence {
9561    pub name: TableRef,
9562    pub if_exists: bool,
9563    pub increment: Option<i64>,
9564    pub minvalue: Option<SequenceBound>,
9565    pub maxvalue: Option<SequenceBound>,
9566    pub start: Option<i64>,
9567    pub restart: Option<Option<i64>>,
9568    pub cache: Option<i64>,
9569    pub cycle: Option<bool>,
9570    pub owned_by: Option<Option<TableRef>>,
9571}
9572
9573impl AlterSequence {
9574    pub fn new(name: impl Into<String>) -> Self {
9575        Self {
9576            name: TableRef::new(name),
9577            if_exists: false,
9578            increment: None,
9579            minvalue: None,
9580            maxvalue: None,
9581            start: None,
9582            restart: None,
9583            cache: None,
9584            cycle: None,
9585            owned_by: None,
9586        }
9587    }
9588}
9589
9590/// CREATE TRIGGER statement
9591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9592#[cfg_attr(feature = "bindings", derive(TS))]
9593pub struct CreateTrigger {
9594    pub name: Identifier,
9595    pub table: TableRef,
9596    pub timing: TriggerTiming,
9597    pub events: Vec<TriggerEvent>,
9598    #[serde(default, skip_serializing_if = "Option::is_none")]
9599    pub for_each: Option<TriggerForEach>,
9600    pub when: Option<Expression>,
9601    /// Whether the WHEN clause was parenthesized in the original SQL
9602    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9603    pub when_paren: bool,
9604    pub body: TriggerBody,
9605    pub or_replace: bool,
9606    /// TSQL: CREATE OR ALTER
9607    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9608    pub or_alter: bool,
9609    pub constraint: bool,
9610    pub deferrable: Option<bool>,
9611    pub initially_deferred: Option<bool>,
9612    pub referencing: Option<TriggerReferencing>,
9613}
9614
9615/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9616#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9617#[cfg_attr(feature = "bindings", derive(TS))]
9618pub enum TriggerTiming {
9619    Before,
9620    After,
9621    InsteadOf,
9622}
9623
9624/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9626#[cfg_attr(feature = "bindings", derive(TS))]
9627pub enum TriggerEvent {
9628    Insert,
9629    Update(Option<Vec<Identifier>>),
9630    Delete,
9631    Truncate,
9632}
9633
9634/// Trigger FOR EACH clause
9635#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9636#[cfg_attr(feature = "bindings", derive(TS))]
9637pub enum TriggerForEach {
9638    Row,
9639    Statement,
9640}
9641
9642/// Trigger body
9643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9644#[cfg_attr(feature = "bindings", derive(TS))]
9645pub enum TriggerBody {
9646    /// EXECUTE FUNCTION/PROCEDURE name(args)
9647    Execute {
9648        function: TableRef,
9649        args: Vec<Expression>,
9650    },
9651    /// BEGIN ... END block
9652    Block(String),
9653}
9654
9655/// Trigger REFERENCING clause
9656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9657#[cfg_attr(feature = "bindings", derive(TS))]
9658pub struct TriggerReferencing {
9659    pub old_table: Option<Identifier>,
9660    pub new_table: Option<Identifier>,
9661    pub old_row: Option<Identifier>,
9662    pub new_row: Option<Identifier>,
9663}
9664
9665impl CreateTrigger {
9666    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9667        Self {
9668            name: Identifier::new(name),
9669            table: TableRef::new(table),
9670            timing: TriggerTiming::Before,
9671            events: Vec::new(),
9672            for_each: Some(TriggerForEach::Row),
9673            when: None,
9674            when_paren: false,
9675            body: TriggerBody::Execute {
9676                function: TableRef::new(""),
9677                args: Vec::new(),
9678            },
9679            or_replace: false,
9680            or_alter: false,
9681            constraint: false,
9682            deferrable: None,
9683            initially_deferred: None,
9684            referencing: None,
9685        }
9686    }
9687}
9688
9689/// DROP TRIGGER statement
9690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9691#[cfg_attr(feature = "bindings", derive(TS))]
9692pub struct DropTrigger {
9693    pub name: Identifier,
9694    pub table: Option<TableRef>,
9695    pub if_exists: bool,
9696    pub cascade: bool,
9697}
9698
9699impl DropTrigger {
9700    pub fn new(name: impl Into<String>) -> Self {
9701        Self {
9702            name: Identifier::new(name),
9703            table: None,
9704            if_exists: false,
9705            cascade: false,
9706        }
9707    }
9708}
9709
9710/// CREATE TYPE statement
9711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9712#[cfg_attr(feature = "bindings", derive(TS))]
9713pub struct CreateType {
9714    pub name: TableRef,
9715    pub definition: TypeDefinition,
9716    pub if_not_exists: bool,
9717}
9718
9719/// Type definition
9720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9721#[cfg_attr(feature = "bindings", derive(TS))]
9722pub enum TypeDefinition {
9723    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9724    Enum(Vec<String>),
9725    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9726    Composite(Vec<TypeAttribute>),
9727    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9728    Range {
9729        subtype: DataType,
9730        subtype_diff: Option<String>,
9731        canonical: Option<String>,
9732    },
9733    /// Base type (for advanced usage)
9734    Base {
9735        input: String,
9736        output: String,
9737        internallength: Option<i32>,
9738    },
9739    /// Domain type
9740    Domain {
9741        base_type: DataType,
9742        default: Option<Expression>,
9743        constraints: Vec<DomainConstraint>,
9744    },
9745}
9746
9747/// Type attribute for composite types
9748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9749#[cfg_attr(feature = "bindings", derive(TS))]
9750pub struct TypeAttribute {
9751    pub name: Identifier,
9752    pub data_type: DataType,
9753    pub collate: Option<Identifier>,
9754}
9755
9756/// Domain constraint
9757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9758#[cfg_attr(feature = "bindings", derive(TS))]
9759pub struct DomainConstraint {
9760    pub name: Option<Identifier>,
9761    pub check: Expression,
9762}
9763
9764impl CreateType {
9765    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9766        Self {
9767            name: TableRef::new(name),
9768            definition: TypeDefinition::Enum(values),
9769            if_not_exists: false,
9770        }
9771    }
9772
9773    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9774        Self {
9775            name: TableRef::new(name),
9776            definition: TypeDefinition::Composite(attributes),
9777            if_not_exists: false,
9778        }
9779    }
9780}
9781
9782/// DROP TYPE statement
9783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9784#[cfg_attr(feature = "bindings", derive(TS))]
9785pub struct DropType {
9786    pub name: TableRef,
9787    pub if_exists: bool,
9788    pub cascade: bool,
9789}
9790
9791impl DropType {
9792    pub fn new(name: impl Into<String>) -> Self {
9793        Self {
9794            name: TableRef::new(name),
9795            if_exists: false,
9796            cascade: false,
9797        }
9798    }
9799}
9800
9801/// DESCRIBE statement - shows table structure or query plan
9802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9803#[cfg_attr(feature = "bindings", derive(TS))]
9804pub struct Describe {
9805    /// The target to describe (table name or query)
9806    pub target: Expression,
9807    /// EXTENDED format
9808    pub extended: bool,
9809    /// FORMATTED format
9810    pub formatted: bool,
9811    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9812    #[serde(default)]
9813    pub kind: Option<String>,
9814    /// Properties like type=stage
9815    #[serde(default)]
9816    pub properties: Vec<(String, String)>,
9817    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9818    #[serde(default, skip_serializing_if = "Option::is_none")]
9819    pub style: Option<String>,
9820    /// Partition specification for DESCRIBE PARTITION
9821    #[serde(default)]
9822    pub partition: Option<Box<Expression>>,
9823    /// Leading comments before the statement
9824    #[serde(default)]
9825    pub leading_comments: Vec<String>,
9826    /// AS JSON suffix (Databricks)
9827    #[serde(default)]
9828    pub as_json: bool,
9829    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9830    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9831    pub params: Vec<String>,
9832}
9833
9834impl Describe {
9835    pub fn new(target: Expression) -> Self {
9836        Self {
9837            target,
9838            extended: false,
9839            formatted: false,
9840            kind: None,
9841            properties: Vec::new(),
9842            style: None,
9843            partition: None,
9844            leading_comments: Vec::new(),
9845            as_json: false,
9846            params: Vec::new(),
9847        }
9848    }
9849}
9850
9851/// SHOW statement - displays database objects
9852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9853#[cfg_attr(feature = "bindings", derive(TS))]
9854pub struct Show {
9855    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9856    pub this: String,
9857    /// Whether TERSE was specified
9858    #[serde(default)]
9859    pub terse: bool,
9860    /// Whether HISTORY was specified
9861    #[serde(default)]
9862    pub history: bool,
9863    /// LIKE pattern
9864    pub like: Option<Expression>,
9865    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9866    pub scope_kind: Option<String>,
9867    /// IN scope object
9868    pub scope: Option<Expression>,
9869    /// STARTS WITH pattern
9870    pub starts_with: Option<Expression>,
9871    /// LIMIT clause
9872    pub limit: Option<Box<Limit>>,
9873    /// FROM clause (for specific object)
9874    pub from: Option<Expression>,
9875    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9876    #[serde(default, skip_serializing_if = "Option::is_none")]
9877    pub where_clause: Option<Expression>,
9878    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9879    #[serde(default, skip_serializing_if = "Option::is_none")]
9880    pub for_target: Option<Expression>,
9881    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9882    #[serde(default, skip_serializing_if = "Option::is_none")]
9883    pub db: Option<Expression>,
9884    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9885    #[serde(default, skip_serializing_if = "Option::is_none")]
9886    pub target: Option<Expression>,
9887    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9888    #[serde(default, skip_serializing_if = "Option::is_none")]
9889    pub mutex: Option<bool>,
9890    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9891    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9892    pub privileges: Vec<String>,
9893}
9894
9895impl Show {
9896    pub fn new(this: impl Into<String>) -> Self {
9897        Self {
9898            this: this.into(),
9899            terse: false,
9900            history: false,
9901            like: None,
9902            scope_kind: None,
9903            scope: None,
9904            starts_with: None,
9905            limit: None,
9906            from: None,
9907            where_clause: None,
9908            for_target: None,
9909            db: None,
9910            target: None,
9911            mutex: None,
9912            privileges: Vec::new(),
9913        }
9914    }
9915}
9916
9917/// Represent an explicit parenthesized expression for grouping precedence.
9918///
9919/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9920/// correctly instead of being flattened to `a + b * c`.
9921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9922#[cfg_attr(feature = "bindings", derive(TS))]
9923pub struct Paren {
9924    /// The inner expression wrapped by parentheses.
9925    pub this: Expression,
9926    #[serde(default)]
9927    pub trailing_comments: Vec<String>,
9928}
9929
9930/// Expression annotated with trailing comments (for round-trip preservation)
9931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9932#[cfg_attr(feature = "bindings", derive(TS))]
9933pub struct Annotated {
9934    pub this: Expression,
9935    pub trailing_comments: Vec<String>,
9936}
9937
9938// === BATCH GENERATED STRUCT DEFINITIONS ===
9939// Generated from Python sqlglot expressions.py
9940
9941/// Refresh
9942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9943#[cfg_attr(feature = "bindings", derive(TS))]
9944pub struct Refresh {
9945    pub this: Box<Expression>,
9946    pub kind: String,
9947}
9948
9949/// LockingStatement
9950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9951#[cfg_attr(feature = "bindings", derive(TS))]
9952pub struct LockingStatement {
9953    pub this: Box<Expression>,
9954    pub expression: Box<Expression>,
9955}
9956
9957/// SequenceProperties
9958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9959#[cfg_attr(feature = "bindings", derive(TS))]
9960pub struct SequenceProperties {
9961    #[serde(default)]
9962    pub increment: Option<Box<Expression>>,
9963    #[serde(default)]
9964    pub minvalue: Option<Box<Expression>>,
9965    #[serde(default)]
9966    pub maxvalue: Option<Box<Expression>>,
9967    #[serde(default)]
9968    pub cache: Option<Box<Expression>>,
9969    #[serde(default)]
9970    pub start: Option<Box<Expression>>,
9971    #[serde(default)]
9972    pub owned: Option<Box<Expression>>,
9973    #[serde(default)]
9974    pub options: Vec<Expression>,
9975}
9976
9977/// TruncateTable
9978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9979#[cfg_attr(feature = "bindings", derive(TS))]
9980pub struct TruncateTable {
9981    #[serde(default)]
9982    pub expressions: Vec<Expression>,
9983    #[serde(default)]
9984    pub is_database: Option<Box<Expression>>,
9985    #[serde(default)]
9986    pub exists: bool,
9987    #[serde(default)]
9988    pub only: Option<Box<Expression>>,
9989    #[serde(default)]
9990    pub cluster: Option<Box<Expression>>,
9991    #[serde(default)]
9992    pub identity: Option<Box<Expression>>,
9993    #[serde(default)]
9994    pub option: Option<Box<Expression>>,
9995    #[serde(default)]
9996    pub partition: Option<Box<Expression>>,
9997}
9998
9999/// Clone
10000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10001#[cfg_attr(feature = "bindings", derive(TS))]
10002pub struct Clone {
10003    pub this: Box<Expression>,
10004    #[serde(default)]
10005    pub shallow: Option<Box<Expression>>,
10006    #[serde(default)]
10007    pub copy: Option<Box<Expression>>,
10008}
10009
10010/// Attach
10011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10012#[cfg_attr(feature = "bindings", derive(TS))]
10013pub struct Attach {
10014    pub this: Box<Expression>,
10015    #[serde(default)]
10016    pub exists: bool,
10017    #[serde(default)]
10018    pub expressions: Vec<Expression>,
10019}
10020
10021/// Detach
10022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10023#[cfg_attr(feature = "bindings", derive(TS))]
10024pub struct Detach {
10025    pub this: Box<Expression>,
10026    #[serde(default)]
10027    pub exists: bool,
10028}
10029
10030/// Install
10031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10032#[cfg_attr(feature = "bindings", derive(TS))]
10033pub struct Install {
10034    pub this: Box<Expression>,
10035    #[serde(default)]
10036    pub from_: Option<Box<Expression>>,
10037    #[serde(default)]
10038    pub force: Option<Box<Expression>>,
10039}
10040
10041/// Summarize
10042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10043#[cfg_attr(feature = "bindings", derive(TS))]
10044pub struct Summarize {
10045    pub this: Box<Expression>,
10046    #[serde(default)]
10047    pub table: Option<Box<Expression>>,
10048}
10049
10050/// Declare
10051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10052#[cfg_attr(feature = "bindings", derive(TS))]
10053pub struct Declare {
10054    #[serde(default)]
10055    pub expressions: Vec<Expression>,
10056    #[serde(default)]
10057    pub replace: bool,
10058}
10059
10060/// DeclareItem
10061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10062#[cfg_attr(feature = "bindings", derive(TS))]
10063pub struct DeclareItem {
10064    pub this: Box<Expression>,
10065    #[serde(default)]
10066    pub kind: Option<String>,
10067    #[serde(default)]
10068    pub default: Option<Box<Expression>>,
10069    #[serde(default)]
10070    pub has_as: bool,
10071    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
10072    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10073    pub additional_names: Vec<Expression>,
10074}
10075
10076/// Set
10077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10078#[cfg_attr(feature = "bindings", derive(TS))]
10079pub struct Set {
10080    #[serde(default)]
10081    pub expressions: Vec<Expression>,
10082    #[serde(default)]
10083    pub unset: Option<Box<Expression>>,
10084    #[serde(default)]
10085    pub tag: Option<Box<Expression>>,
10086}
10087
10088/// Heredoc
10089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10090#[cfg_attr(feature = "bindings", derive(TS))]
10091pub struct Heredoc {
10092    pub this: Box<Expression>,
10093    #[serde(default)]
10094    pub tag: Option<Box<Expression>>,
10095}
10096
10097/// QueryBand
10098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10099#[cfg_attr(feature = "bindings", derive(TS))]
10100pub struct QueryBand {
10101    pub this: Box<Expression>,
10102    #[serde(default)]
10103    pub scope: Option<Box<Expression>>,
10104    #[serde(default)]
10105    pub update: Option<Box<Expression>>,
10106}
10107
10108/// UserDefinedFunction
10109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10110#[cfg_attr(feature = "bindings", derive(TS))]
10111pub struct UserDefinedFunction {
10112    pub this: Box<Expression>,
10113    #[serde(default)]
10114    pub expressions: Vec<Expression>,
10115    #[serde(default)]
10116    pub wrapped: Option<Box<Expression>>,
10117}
10118
10119/// RecursiveWithSearch
10120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10121#[cfg_attr(feature = "bindings", derive(TS))]
10122pub struct RecursiveWithSearch {
10123    pub kind: String,
10124    pub this: Box<Expression>,
10125    pub expression: Box<Expression>,
10126    #[serde(default)]
10127    pub using: Option<Box<Expression>>,
10128}
10129
10130/// ProjectionDef
10131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10132#[cfg_attr(feature = "bindings", derive(TS))]
10133pub struct ProjectionDef {
10134    pub this: Box<Expression>,
10135    pub expression: Box<Expression>,
10136}
10137
10138/// TableAlias
10139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10140#[cfg_attr(feature = "bindings", derive(TS))]
10141pub struct TableAlias {
10142    #[serde(default)]
10143    pub this: Option<Box<Expression>>,
10144    #[serde(default)]
10145    pub columns: Vec<Expression>,
10146}
10147
10148/// ByteString
10149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10150#[cfg_attr(feature = "bindings", derive(TS))]
10151pub struct ByteString {
10152    pub this: Box<Expression>,
10153    #[serde(default)]
10154    pub is_bytes: Option<Box<Expression>>,
10155}
10156
10157/// HexStringExpr - Hex string expression (not literal)
10158/// BigQuery: converts to FROM_HEX(this)
10159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10160#[cfg_attr(feature = "bindings", derive(TS))]
10161pub struct HexStringExpr {
10162    pub this: Box<Expression>,
10163    #[serde(default)]
10164    pub is_integer: Option<bool>,
10165}
10166
10167/// UnicodeString
10168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10169#[cfg_attr(feature = "bindings", derive(TS))]
10170pub struct UnicodeString {
10171    pub this: Box<Expression>,
10172    #[serde(default)]
10173    pub escape: Option<Box<Expression>>,
10174}
10175
10176/// AlterColumn
10177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10178#[cfg_attr(feature = "bindings", derive(TS))]
10179pub struct AlterColumn {
10180    pub this: Box<Expression>,
10181    #[serde(default)]
10182    pub dtype: Option<Box<Expression>>,
10183    #[serde(default)]
10184    pub collate: Option<Box<Expression>>,
10185    #[serde(default)]
10186    pub using: Option<Box<Expression>>,
10187    #[serde(default)]
10188    pub default: Option<Box<Expression>>,
10189    #[serde(default)]
10190    pub drop: Option<Box<Expression>>,
10191    #[serde(default)]
10192    pub comment: Option<Box<Expression>>,
10193    #[serde(default)]
10194    pub allow_null: Option<Box<Expression>>,
10195    #[serde(default)]
10196    pub visible: Option<Box<Expression>>,
10197    #[serde(default)]
10198    pub rename_to: Option<Box<Expression>>,
10199}
10200
10201/// AlterSortKey
10202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10203#[cfg_attr(feature = "bindings", derive(TS))]
10204pub struct AlterSortKey {
10205    #[serde(default)]
10206    pub this: Option<Box<Expression>>,
10207    #[serde(default)]
10208    pub expressions: Vec<Expression>,
10209    #[serde(default)]
10210    pub compound: Option<Box<Expression>>,
10211}
10212
10213/// AlterSet
10214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10215#[cfg_attr(feature = "bindings", derive(TS))]
10216pub struct AlterSet {
10217    #[serde(default)]
10218    pub expressions: Vec<Expression>,
10219    #[serde(default)]
10220    pub option: Option<Box<Expression>>,
10221    #[serde(default)]
10222    pub tablespace: Option<Box<Expression>>,
10223    #[serde(default)]
10224    pub access_method: Option<Box<Expression>>,
10225    #[serde(default)]
10226    pub file_format: Option<Box<Expression>>,
10227    #[serde(default)]
10228    pub copy_options: Option<Box<Expression>>,
10229    #[serde(default)]
10230    pub tag: Option<Box<Expression>>,
10231    #[serde(default)]
10232    pub location: Option<Box<Expression>>,
10233    #[serde(default)]
10234    pub serde: Option<Box<Expression>>,
10235}
10236
10237/// RenameColumn
10238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10239#[cfg_attr(feature = "bindings", derive(TS))]
10240pub struct RenameColumn {
10241    pub this: Box<Expression>,
10242    #[serde(default)]
10243    pub to: Option<Box<Expression>>,
10244    #[serde(default)]
10245    pub exists: bool,
10246}
10247
10248/// Comprehension
10249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10250#[cfg_attr(feature = "bindings", derive(TS))]
10251pub struct Comprehension {
10252    pub this: Box<Expression>,
10253    pub expression: Box<Expression>,
10254    #[serde(default)]
10255    pub position: Option<Box<Expression>>,
10256    #[serde(default)]
10257    pub iterator: Option<Box<Expression>>,
10258    #[serde(default)]
10259    pub condition: Option<Box<Expression>>,
10260}
10261
10262/// MergeTreeTTLAction
10263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10264#[cfg_attr(feature = "bindings", derive(TS))]
10265pub struct MergeTreeTTLAction {
10266    pub this: Box<Expression>,
10267    #[serde(default)]
10268    pub delete: Option<Box<Expression>>,
10269    #[serde(default)]
10270    pub recompress: Option<Box<Expression>>,
10271    #[serde(default)]
10272    pub to_disk: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub to_volume: Option<Box<Expression>>,
10275}
10276
10277/// MergeTreeTTL
10278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10279#[cfg_attr(feature = "bindings", derive(TS))]
10280pub struct MergeTreeTTL {
10281    #[serde(default)]
10282    pub expressions: Vec<Expression>,
10283    #[serde(default)]
10284    pub where_: Option<Box<Expression>>,
10285    #[serde(default)]
10286    pub group: Option<Box<Expression>>,
10287    #[serde(default)]
10288    pub aggregates: Option<Box<Expression>>,
10289}
10290
10291/// IndexConstraintOption
10292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10293#[cfg_attr(feature = "bindings", derive(TS))]
10294pub struct IndexConstraintOption {
10295    #[serde(default)]
10296    pub key_block_size: Option<Box<Expression>>,
10297    #[serde(default)]
10298    pub using: Option<Box<Expression>>,
10299    #[serde(default)]
10300    pub parser: Option<Box<Expression>>,
10301    #[serde(default)]
10302    pub comment: Option<Box<Expression>>,
10303    #[serde(default)]
10304    pub visible: Option<Box<Expression>>,
10305    #[serde(default)]
10306    pub engine_attr: Option<Box<Expression>>,
10307    #[serde(default)]
10308    pub secondary_engine_attr: Option<Box<Expression>>,
10309}
10310
10311/// PeriodForSystemTimeConstraint
10312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10313#[cfg_attr(feature = "bindings", derive(TS))]
10314pub struct PeriodForSystemTimeConstraint {
10315    pub this: Box<Expression>,
10316    pub expression: Box<Expression>,
10317}
10318
10319/// CaseSpecificColumnConstraint
10320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10321#[cfg_attr(feature = "bindings", derive(TS))]
10322pub struct CaseSpecificColumnConstraint {
10323    #[serde(default)]
10324    pub not_: Option<Box<Expression>>,
10325}
10326
10327/// CharacterSetColumnConstraint
10328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10329#[cfg_attr(feature = "bindings", derive(TS))]
10330pub struct CharacterSetColumnConstraint {
10331    pub this: Box<Expression>,
10332}
10333
10334/// CheckColumnConstraint
10335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10336#[cfg_attr(feature = "bindings", derive(TS))]
10337pub struct CheckColumnConstraint {
10338    pub this: Box<Expression>,
10339    #[serde(default)]
10340    pub enforced: Option<Box<Expression>>,
10341}
10342
10343/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10345#[cfg_attr(feature = "bindings", derive(TS))]
10346pub struct AssumeColumnConstraint {
10347    pub this: Box<Expression>,
10348}
10349
10350/// CompressColumnConstraint
10351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10352#[cfg_attr(feature = "bindings", derive(TS))]
10353pub struct CompressColumnConstraint {
10354    #[serde(default)]
10355    pub this: Option<Box<Expression>>,
10356}
10357
10358/// DateFormatColumnConstraint
10359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10360#[cfg_attr(feature = "bindings", derive(TS))]
10361pub struct DateFormatColumnConstraint {
10362    pub this: Box<Expression>,
10363}
10364
10365/// EphemeralColumnConstraint
10366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10367#[cfg_attr(feature = "bindings", derive(TS))]
10368pub struct EphemeralColumnConstraint {
10369    #[serde(default)]
10370    pub this: Option<Box<Expression>>,
10371}
10372
10373/// WithOperator
10374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10375#[cfg_attr(feature = "bindings", derive(TS))]
10376pub struct WithOperator {
10377    pub this: Box<Expression>,
10378    pub op: String,
10379}
10380
10381/// GeneratedAsIdentityColumnConstraint
10382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10383#[cfg_attr(feature = "bindings", derive(TS))]
10384pub struct GeneratedAsIdentityColumnConstraint {
10385    #[serde(default)]
10386    pub this: Option<Box<Expression>>,
10387    #[serde(default)]
10388    pub expression: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub on_null: Option<Box<Expression>>,
10391    #[serde(default)]
10392    pub start: Option<Box<Expression>>,
10393    #[serde(default)]
10394    pub increment: Option<Box<Expression>>,
10395    #[serde(default)]
10396    pub minvalue: Option<Box<Expression>>,
10397    #[serde(default)]
10398    pub maxvalue: Option<Box<Expression>>,
10399    #[serde(default)]
10400    pub cycle: Option<Box<Expression>>,
10401    #[serde(default)]
10402    pub order: Option<Box<Expression>>,
10403}
10404
10405/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10406/// TSQL: outputs "IDENTITY"
10407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10408#[cfg_attr(feature = "bindings", derive(TS))]
10409pub struct AutoIncrementColumnConstraint;
10410
10411/// CommentColumnConstraint - Column comment marker
10412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10413#[cfg_attr(feature = "bindings", derive(TS))]
10414pub struct CommentColumnConstraint;
10415
10416/// GeneratedAsRowColumnConstraint
10417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10418#[cfg_attr(feature = "bindings", derive(TS))]
10419pub struct GeneratedAsRowColumnConstraint {
10420    #[serde(default)]
10421    pub start: Option<Box<Expression>>,
10422    #[serde(default)]
10423    pub hidden: Option<Box<Expression>>,
10424}
10425
10426/// IndexColumnConstraint
10427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10428#[cfg_attr(feature = "bindings", derive(TS))]
10429pub struct IndexColumnConstraint {
10430    #[serde(default)]
10431    pub this: Option<Box<Expression>>,
10432    #[serde(default)]
10433    pub expressions: Vec<Expression>,
10434    #[serde(default)]
10435    pub kind: Option<String>,
10436    #[serde(default)]
10437    pub index_type: Option<Box<Expression>>,
10438    #[serde(default)]
10439    pub options: Vec<Expression>,
10440    #[serde(default)]
10441    pub expression: Option<Box<Expression>>,
10442    #[serde(default)]
10443    pub granularity: Option<Box<Expression>>,
10444}
10445
10446/// MaskingPolicyColumnConstraint
10447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10448#[cfg_attr(feature = "bindings", derive(TS))]
10449pub struct MaskingPolicyColumnConstraint {
10450    pub this: Box<Expression>,
10451    #[serde(default)]
10452    pub expressions: Vec<Expression>,
10453}
10454
10455/// NotNullColumnConstraint
10456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10457#[cfg_attr(feature = "bindings", derive(TS))]
10458pub struct NotNullColumnConstraint {
10459    #[serde(default)]
10460    pub allow_null: Option<Box<Expression>>,
10461}
10462
10463/// DefaultColumnConstraint - DEFAULT value for a column
10464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10465#[cfg_attr(feature = "bindings", derive(TS))]
10466pub struct DefaultColumnConstraint {
10467    pub this: Box<Expression>,
10468    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10469    #[serde(default, skip_serializing_if = "Option::is_none")]
10470    pub for_column: Option<Identifier>,
10471}
10472
10473/// PrimaryKeyColumnConstraint
10474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10475#[cfg_attr(feature = "bindings", derive(TS))]
10476pub struct PrimaryKeyColumnConstraint {
10477    #[serde(default)]
10478    pub desc: Option<Box<Expression>>,
10479    #[serde(default)]
10480    pub options: Vec<Expression>,
10481}
10482
10483/// UniqueColumnConstraint
10484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10485#[cfg_attr(feature = "bindings", derive(TS))]
10486pub struct UniqueColumnConstraint {
10487    #[serde(default)]
10488    pub this: Option<Box<Expression>>,
10489    #[serde(default)]
10490    pub index_type: Option<Box<Expression>>,
10491    #[serde(default)]
10492    pub on_conflict: Option<Box<Expression>>,
10493    #[serde(default)]
10494    pub nulls: Option<Box<Expression>>,
10495    #[serde(default)]
10496    pub options: Vec<Expression>,
10497}
10498
10499/// WatermarkColumnConstraint
10500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10501#[cfg_attr(feature = "bindings", derive(TS))]
10502pub struct WatermarkColumnConstraint {
10503    pub this: Box<Expression>,
10504    pub expression: Box<Expression>,
10505}
10506
10507/// ComputedColumnConstraint
10508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10509#[cfg_attr(feature = "bindings", derive(TS))]
10510pub struct ComputedColumnConstraint {
10511    pub this: Box<Expression>,
10512    #[serde(default)]
10513    pub persisted: Option<Box<Expression>>,
10514    #[serde(default)]
10515    pub not_null: Option<Box<Expression>>,
10516    #[serde(default)]
10517    pub data_type: Option<Box<Expression>>,
10518}
10519
10520/// InOutColumnConstraint
10521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10522#[cfg_attr(feature = "bindings", derive(TS))]
10523pub struct InOutColumnConstraint {
10524    #[serde(default)]
10525    pub input_: Option<Box<Expression>>,
10526    #[serde(default)]
10527    pub output: Option<Box<Expression>>,
10528}
10529
10530/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10532#[cfg_attr(feature = "bindings", derive(TS))]
10533pub struct PathColumnConstraint {
10534    pub this: Box<Expression>,
10535}
10536
10537/// Constraint
10538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10539#[cfg_attr(feature = "bindings", derive(TS))]
10540pub struct Constraint {
10541    pub this: Box<Expression>,
10542    #[serde(default)]
10543    pub expressions: Vec<Expression>,
10544}
10545
10546/// Export
10547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10548#[cfg_attr(feature = "bindings", derive(TS))]
10549pub struct Export {
10550    pub this: Box<Expression>,
10551    #[serde(default)]
10552    pub connection: Option<Box<Expression>>,
10553    #[serde(default)]
10554    pub options: Vec<Expression>,
10555}
10556
10557/// Filter
10558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10559#[cfg_attr(feature = "bindings", derive(TS))]
10560pub struct Filter {
10561    pub this: Box<Expression>,
10562    pub expression: Box<Expression>,
10563}
10564
10565/// Changes
10566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10567#[cfg_attr(feature = "bindings", derive(TS))]
10568pub struct Changes {
10569    #[serde(default)]
10570    pub information: Option<Box<Expression>>,
10571    #[serde(default)]
10572    pub at_before: Option<Box<Expression>>,
10573    #[serde(default)]
10574    pub end: Option<Box<Expression>>,
10575}
10576
10577/// Directory
10578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10579#[cfg_attr(feature = "bindings", derive(TS))]
10580pub struct Directory {
10581    pub this: Box<Expression>,
10582    #[serde(default)]
10583    pub local: Option<Box<Expression>>,
10584    #[serde(default)]
10585    pub row_format: Option<Box<Expression>>,
10586}
10587
10588/// ForeignKey
10589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10590#[cfg_attr(feature = "bindings", derive(TS))]
10591pub struct ForeignKey {
10592    #[serde(default)]
10593    pub expressions: Vec<Expression>,
10594    #[serde(default)]
10595    pub reference: Option<Box<Expression>>,
10596    #[serde(default)]
10597    pub delete: Option<Box<Expression>>,
10598    #[serde(default)]
10599    pub update: Option<Box<Expression>>,
10600    #[serde(default)]
10601    pub options: Vec<Expression>,
10602}
10603
10604/// ColumnPrefix
10605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10606#[cfg_attr(feature = "bindings", derive(TS))]
10607pub struct ColumnPrefix {
10608    pub this: Box<Expression>,
10609    pub expression: Box<Expression>,
10610}
10611
10612/// PrimaryKey
10613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10614#[cfg_attr(feature = "bindings", derive(TS))]
10615pub struct PrimaryKey {
10616    #[serde(default)]
10617    pub this: Option<Box<Expression>>,
10618    #[serde(default)]
10619    pub expressions: Vec<Expression>,
10620    #[serde(default)]
10621    pub options: Vec<Expression>,
10622    #[serde(default)]
10623    pub include: Option<Box<Expression>>,
10624}
10625
10626/// Into
10627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10628#[cfg_attr(feature = "bindings", derive(TS))]
10629pub struct IntoClause {
10630    #[serde(default)]
10631    pub this: Option<Box<Expression>>,
10632    #[serde(default)]
10633    pub temporary: bool,
10634    #[serde(default)]
10635    pub unlogged: Option<Box<Expression>>,
10636    #[serde(default)]
10637    pub bulk_collect: Option<Box<Expression>>,
10638    #[serde(default)]
10639    pub expressions: Vec<Expression>,
10640}
10641
10642/// JoinHint
10643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10644#[cfg_attr(feature = "bindings", derive(TS))]
10645pub struct JoinHint {
10646    pub this: Box<Expression>,
10647    #[serde(default)]
10648    pub expressions: Vec<Expression>,
10649}
10650
10651/// Opclass
10652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10653#[cfg_attr(feature = "bindings", derive(TS))]
10654pub struct Opclass {
10655    pub this: Box<Expression>,
10656    pub expression: Box<Expression>,
10657}
10658
10659/// Index
10660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10661#[cfg_attr(feature = "bindings", derive(TS))]
10662pub struct Index {
10663    #[serde(default)]
10664    pub this: Option<Box<Expression>>,
10665    #[serde(default)]
10666    pub table: Option<Box<Expression>>,
10667    #[serde(default)]
10668    pub unique: bool,
10669    #[serde(default)]
10670    pub primary: Option<Box<Expression>>,
10671    #[serde(default)]
10672    pub amp: Option<Box<Expression>>,
10673    #[serde(default)]
10674    pub params: Vec<Expression>,
10675}
10676
10677/// IndexParameters
10678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10679#[cfg_attr(feature = "bindings", derive(TS))]
10680pub struct IndexParameters {
10681    #[serde(default)]
10682    pub using: Option<Box<Expression>>,
10683    #[serde(default)]
10684    pub include: Option<Box<Expression>>,
10685    #[serde(default)]
10686    pub columns: Vec<Expression>,
10687    #[serde(default)]
10688    pub with_storage: Option<Box<Expression>>,
10689    #[serde(default)]
10690    pub partition_by: Option<Box<Expression>>,
10691    #[serde(default)]
10692    pub tablespace: Option<Box<Expression>>,
10693    #[serde(default)]
10694    pub where_: Option<Box<Expression>>,
10695    #[serde(default)]
10696    pub on: Option<Box<Expression>>,
10697}
10698
10699/// ConditionalInsert
10700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10701#[cfg_attr(feature = "bindings", derive(TS))]
10702pub struct ConditionalInsert {
10703    pub this: Box<Expression>,
10704    #[serde(default)]
10705    pub expression: Option<Box<Expression>>,
10706    #[serde(default)]
10707    pub else_: Option<Box<Expression>>,
10708}
10709
10710/// MultitableInserts
10711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10712#[cfg_attr(feature = "bindings", derive(TS))]
10713pub struct MultitableInserts {
10714    #[serde(default)]
10715    pub expressions: Vec<Expression>,
10716    pub kind: String,
10717    #[serde(default)]
10718    pub source: Option<Box<Expression>>,
10719    /// Leading comments before the statement
10720    #[serde(default)]
10721    pub leading_comments: Vec<String>,
10722    /// OVERWRITE modifier (Snowflake: INSERT OVERWRITE ALL)
10723    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10724    pub overwrite: bool,
10725}
10726
10727/// OnConflict
10728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10729#[cfg_attr(feature = "bindings", derive(TS))]
10730pub struct OnConflict {
10731    #[serde(default)]
10732    pub duplicate: Option<Box<Expression>>,
10733    #[serde(default)]
10734    pub expressions: Vec<Expression>,
10735    #[serde(default)]
10736    pub action: Option<Box<Expression>>,
10737    #[serde(default)]
10738    pub conflict_keys: Option<Box<Expression>>,
10739    #[serde(default)]
10740    pub index_predicate: Option<Box<Expression>>,
10741    #[serde(default)]
10742    pub constraint: Option<Box<Expression>>,
10743    #[serde(default)]
10744    pub where_: Option<Box<Expression>>,
10745}
10746
10747/// OnCondition
10748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10749#[cfg_attr(feature = "bindings", derive(TS))]
10750pub struct OnCondition {
10751    #[serde(default)]
10752    pub error: Option<Box<Expression>>,
10753    #[serde(default)]
10754    pub empty: Option<Box<Expression>>,
10755    #[serde(default)]
10756    pub null: Option<Box<Expression>>,
10757}
10758
10759/// Returning
10760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10761#[cfg_attr(feature = "bindings", derive(TS))]
10762pub struct Returning {
10763    #[serde(default)]
10764    pub expressions: Vec<Expression>,
10765    #[serde(default)]
10766    pub into: Option<Box<Expression>>,
10767}
10768
10769/// Introducer
10770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10771#[cfg_attr(feature = "bindings", derive(TS))]
10772pub struct Introducer {
10773    pub this: Box<Expression>,
10774    pub expression: Box<Expression>,
10775}
10776
10777/// PartitionRange
10778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10779#[cfg_attr(feature = "bindings", derive(TS))]
10780pub struct PartitionRange {
10781    pub this: Box<Expression>,
10782    #[serde(default)]
10783    pub expression: Option<Box<Expression>>,
10784    #[serde(default)]
10785    pub expressions: Vec<Expression>,
10786}
10787
10788/// Group
10789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10790#[cfg_attr(feature = "bindings", derive(TS))]
10791pub struct Group {
10792    #[serde(default)]
10793    pub expressions: Vec<Expression>,
10794    #[serde(default)]
10795    pub grouping_sets: Option<Box<Expression>>,
10796    #[serde(default)]
10797    pub cube: Option<Box<Expression>>,
10798    #[serde(default)]
10799    pub rollup: Option<Box<Expression>>,
10800    #[serde(default)]
10801    pub totals: Option<Box<Expression>>,
10802    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10803    #[serde(default)]
10804    pub all: Option<bool>,
10805}
10806
10807/// Cube
10808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10809#[cfg_attr(feature = "bindings", derive(TS))]
10810pub struct Cube {
10811    #[serde(default)]
10812    pub expressions: Vec<Expression>,
10813}
10814
10815/// Rollup
10816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10817#[cfg_attr(feature = "bindings", derive(TS))]
10818pub struct Rollup {
10819    #[serde(default)]
10820    pub expressions: Vec<Expression>,
10821}
10822
10823/// GroupingSets
10824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10825#[cfg_attr(feature = "bindings", derive(TS))]
10826pub struct GroupingSets {
10827    #[serde(default)]
10828    pub expressions: Vec<Expression>,
10829}
10830
10831/// LimitOptions
10832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10833#[cfg_attr(feature = "bindings", derive(TS))]
10834pub struct LimitOptions {
10835    #[serde(default)]
10836    pub percent: Option<Box<Expression>>,
10837    #[serde(default)]
10838    pub rows: Option<Box<Expression>>,
10839    #[serde(default)]
10840    pub with_ties: Option<Box<Expression>>,
10841}
10842
10843/// Lateral
10844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10845#[cfg_attr(feature = "bindings", derive(TS))]
10846pub struct Lateral {
10847    pub this: Box<Expression>,
10848    #[serde(default)]
10849    pub view: Option<Box<Expression>>,
10850    #[serde(default)]
10851    pub outer: Option<Box<Expression>>,
10852    #[serde(default)]
10853    pub alias: Option<String>,
10854    /// Whether the alias was originally quoted (backtick/double-quote)
10855    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10856    pub alias_quoted: bool,
10857    #[serde(default)]
10858    pub cross_apply: Option<Box<Expression>>,
10859    #[serde(default)]
10860    pub ordinality: Option<Box<Expression>>,
10861    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10862    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10863    pub column_aliases: Vec<String>,
10864}
10865
10866/// TableFromRows
10867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10868#[cfg_attr(feature = "bindings", derive(TS))]
10869pub struct TableFromRows {
10870    pub this: Box<Expression>,
10871    #[serde(default)]
10872    pub alias: Option<String>,
10873    #[serde(default)]
10874    pub joins: Vec<Expression>,
10875    #[serde(default)]
10876    pub pivots: Option<Box<Expression>>,
10877    #[serde(default)]
10878    pub sample: Option<Box<Expression>>,
10879}
10880
10881/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10882/// Used for set-returning functions with typed column definitions
10883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10884#[cfg_attr(feature = "bindings", derive(TS))]
10885pub struct RowsFrom {
10886    /// List of function expressions, each potentially with an alias and typed columns
10887    pub expressions: Vec<Expression>,
10888    /// WITH ORDINALITY modifier
10889    #[serde(default)]
10890    pub ordinality: bool,
10891    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10892    #[serde(default)]
10893    pub alias: Option<Box<Expression>>,
10894}
10895
10896/// WithFill
10897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10898#[cfg_attr(feature = "bindings", derive(TS))]
10899pub struct WithFill {
10900    #[serde(default)]
10901    pub from_: Option<Box<Expression>>,
10902    #[serde(default)]
10903    pub to: Option<Box<Expression>>,
10904    #[serde(default)]
10905    pub step: Option<Box<Expression>>,
10906    #[serde(default)]
10907    pub staleness: Option<Box<Expression>>,
10908    #[serde(default)]
10909    pub interpolate: Option<Box<Expression>>,
10910}
10911
10912/// Property
10913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10914#[cfg_attr(feature = "bindings", derive(TS))]
10915pub struct Property {
10916    pub this: Box<Expression>,
10917    #[serde(default)]
10918    pub value: Option<Box<Expression>>,
10919}
10920
10921/// GrantPrivilege
10922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10923#[cfg_attr(feature = "bindings", derive(TS))]
10924pub struct GrantPrivilege {
10925    pub this: Box<Expression>,
10926    #[serde(default)]
10927    pub expressions: Vec<Expression>,
10928}
10929
10930/// AllowedValuesProperty
10931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10932#[cfg_attr(feature = "bindings", derive(TS))]
10933pub struct AllowedValuesProperty {
10934    #[serde(default)]
10935    pub expressions: Vec<Expression>,
10936}
10937
10938/// AlgorithmProperty
10939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10940#[cfg_attr(feature = "bindings", derive(TS))]
10941pub struct AlgorithmProperty {
10942    pub this: Box<Expression>,
10943}
10944
10945/// AutoIncrementProperty
10946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10947#[cfg_attr(feature = "bindings", derive(TS))]
10948pub struct AutoIncrementProperty {
10949    pub this: Box<Expression>,
10950}
10951
10952/// AutoRefreshProperty
10953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10954#[cfg_attr(feature = "bindings", derive(TS))]
10955pub struct AutoRefreshProperty {
10956    pub this: Box<Expression>,
10957}
10958
10959/// BackupProperty
10960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10961#[cfg_attr(feature = "bindings", derive(TS))]
10962pub struct BackupProperty {
10963    pub this: Box<Expression>,
10964}
10965
10966/// BuildProperty
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct BuildProperty {
10970    pub this: Box<Expression>,
10971}
10972
10973/// BlockCompressionProperty
10974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10975#[cfg_attr(feature = "bindings", derive(TS))]
10976pub struct BlockCompressionProperty {
10977    #[serde(default)]
10978    pub autotemp: Option<Box<Expression>>,
10979    #[serde(default)]
10980    pub always: Option<Box<Expression>>,
10981    #[serde(default)]
10982    pub default: Option<Box<Expression>>,
10983    #[serde(default)]
10984    pub manual: Option<Box<Expression>>,
10985    #[serde(default)]
10986    pub never: Option<Box<Expression>>,
10987}
10988
10989/// CharacterSetProperty
10990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10991#[cfg_attr(feature = "bindings", derive(TS))]
10992pub struct CharacterSetProperty {
10993    pub this: Box<Expression>,
10994    #[serde(default)]
10995    pub default: Option<Box<Expression>>,
10996}
10997
10998/// ChecksumProperty
10999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11000#[cfg_attr(feature = "bindings", derive(TS))]
11001pub struct ChecksumProperty {
11002    #[serde(default)]
11003    pub on: Option<Box<Expression>>,
11004    #[serde(default)]
11005    pub default: Option<Box<Expression>>,
11006}
11007
11008/// CollateProperty
11009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11010#[cfg_attr(feature = "bindings", derive(TS))]
11011pub struct CollateProperty {
11012    pub this: Box<Expression>,
11013    #[serde(default)]
11014    pub default: Option<Box<Expression>>,
11015}
11016
11017/// DataBlocksizeProperty
11018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11019#[cfg_attr(feature = "bindings", derive(TS))]
11020pub struct DataBlocksizeProperty {
11021    #[serde(default)]
11022    pub size: Option<i64>,
11023    #[serde(default)]
11024    pub units: Option<Box<Expression>>,
11025    #[serde(default)]
11026    pub minimum: Option<Box<Expression>>,
11027    #[serde(default)]
11028    pub maximum: Option<Box<Expression>>,
11029    #[serde(default)]
11030    pub default: Option<Box<Expression>>,
11031}
11032
11033/// DataDeletionProperty
11034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11035#[cfg_attr(feature = "bindings", derive(TS))]
11036pub struct DataDeletionProperty {
11037    pub on: Box<Expression>,
11038    #[serde(default)]
11039    pub filter_column: Option<Box<Expression>>,
11040    #[serde(default)]
11041    pub retention_period: Option<Box<Expression>>,
11042}
11043
11044/// DefinerProperty
11045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11046#[cfg_attr(feature = "bindings", derive(TS))]
11047pub struct DefinerProperty {
11048    pub this: Box<Expression>,
11049}
11050
11051/// DistKeyProperty
11052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11053#[cfg_attr(feature = "bindings", derive(TS))]
11054pub struct DistKeyProperty {
11055    pub this: Box<Expression>,
11056}
11057
11058/// DistributedByProperty
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct DistributedByProperty {
11062    #[serde(default)]
11063    pub expressions: Vec<Expression>,
11064    pub kind: String,
11065    #[serde(default)]
11066    pub buckets: Option<Box<Expression>>,
11067    #[serde(default)]
11068    pub order: Option<Box<Expression>>,
11069}
11070
11071/// DistStyleProperty
11072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11073#[cfg_attr(feature = "bindings", derive(TS))]
11074pub struct DistStyleProperty {
11075    pub this: Box<Expression>,
11076}
11077
11078/// DuplicateKeyProperty
11079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11080#[cfg_attr(feature = "bindings", derive(TS))]
11081pub struct DuplicateKeyProperty {
11082    #[serde(default)]
11083    pub expressions: Vec<Expression>,
11084}
11085
11086/// EngineProperty
11087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11088#[cfg_attr(feature = "bindings", derive(TS))]
11089pub struct EngineProperty {
11090    pub this: Box<Expression>,
11091}
11092
11093/// ToTableProperty
11094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11095#[cfg_attr(feature = "bindings", derive(TS))]
11096pub struct ToTableProperty {
11097    pub this: Box<Expression>,
11098}
11099
11100/// ExecuteAsProperty
11101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11102#[cfg_attr(feature = "bindings", derive(TS))]
11103pub struct ExecuteAsProperty {
11104    pub this: Box<Expression>,
11105}
11106
11107/// ExternalProperty
11108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11109#[cfg_attr(feature = "bindings", derive(TS))]
11110pub struct ExternalProperty {
11111    #[serde(default)]
11112    pub this: Option<Box<Expression>>,
11113}
11114
11115/// FallbackProperty
11116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11117#[cfg_attr(feature = "bindings", derive(TS))]
11118pub struct FallbackProperty {
11119    #[serde(default)]
11120    pub no: Option<Box<Expression>>,
11121    #[serde(default)]
11122    pub protection: Option<Box<Expression>>,
11123}
11124
11125/// FileFormatProperty
11126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11127#[cfg_attr(feature = "bindings", derive(TS))]
11128pub struct FileFormatProperty {
11129    #[serde(default)]
11130    pub this: Option<Box<Expression>>,
11131    #[serde(default)]
11132    pub expressions: Vec<Expression>,
11133    #[serde(default)]
11134    pub hive_format: Option<Box<Expression>>,
11135}
11136
11137/// CredentialsProperty
11138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11139#[cfg_attr(feature = "bindings", derive(TS))]
11140pub struct CredentialsProperty {
11141    #[serde(default)]
11142    pub expressions: Vec<Expression>,
11143}
11144
11145/// FreespaceProperty
11146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11147#[cfg_attr(feature = "bindings", derive(TS))]
11148pub struct FreespaceProperty {
11149    pub this: Box<Expression>,
11150    #[serde(default)]
11151    pub percent: Option<Box<Expression>>,
11152}
11153
11154/// InheritsProperty
11155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11156#[cfg_attr(feature = "bindings", derive(TS))]
11157pub struct InheritsProperty {
11158    #[serde(default)]
11159    pub expressions: Vec<Expression>,
11160}
11161
11162/// InputModelProperty
11163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11164#[cfg_attr(feature = "bindings", derive(TS))]
11165pub struct InputModelProperty {
11166    pub this: Box<Expression>,
11167}
11168
11169/// OutputModelProperty
11170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11171#[cfg_attr(feature = "bindings", derive(TS))]
11172pub struct OutputModelProperty {
11173    pub this: Box<Expression>,
11174}
11175
11176/// IsolatedLoadingProperty
11177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11178#[cfg_attr(feature = "bindings", derive(TS))]
11179pub struct IsolatedLoadingProperty {
11180    #[serde(default)]
11181    pub no: Option<Box<Expression>>,
11182    #[serde(default)]
11183    pub concurrent: Option<Box<Expression>>,
11184    #[serde(default)]
11185    pub target: Option<Box<Expression>>,
11186}
11187
11188/// JournalProperty
11189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11190#[cfg_attr(feature = "bindings", derive(TS))]
11191pub struct JournalProperty {
11192    #[serde(default)]
11193    pub no: Option<Box<Expression>>,
11194    #[serde(default)]
11195    pub dual: Option<Box<Expression>>,
11196    #[serde(default)]
11197    pub before: Option<Box<Expression>>,
11198    #[serde(default)]
11199    pub local: Option<Box<Expression>>,
11200    #[serde(default)]
11201    pub after: Option<Box<Expression>>,
11202}
11203
11204/// LanguageProperty
11205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11206#[cfg_attr(feature = "bindings", derive(TS))]
11207pub struct LanguageProperty {
11208    pub this: Box<Expression>,
11209}
11210
11211/// EnviromentProperty
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct EnviromentProperty {
11215    #[serde(default)]
11216    pub expressions: Vec<Expression>,
11217}
11218
11219/// ClusteredByProperty
11220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11221#[cfg_attr(feature = "bindings", derive(TS))]
11222pub struct ClusteredByProperty {
11223    #[serde(default)]
11224    pub expressions: Vec<Expression>,
11225    #[serde(default)]
11226    pub sorted_by: Option<Box<Expression>>,
11227    #[serde(default)]
11228    pub buckets: Option<Box<Expression>>,
11229}
11230
11231/// DictProperty
11232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11233#[cfg_attr(feature = "bindings", derive(TS))]
11234pub struct DictProperty {
11235    pub this: Box<Expression>,
11236    pub kind: String,
11237    #[serde(default)]
11238    pub settings: Option<Box<Expression>>,
11239}
11240
11241/// DictRange
11242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11243#[cfg_attr(feature = "bindings", derive(TS))]
11244pub struct DictRange {
11245    pub this: Box<Expression>,
11246    #[serde(default)]
11247    pub min: Option<Box<Expression>>,
11248    #[serde(default)]
11249    pub max: Option<Box<Expression>>,
11250}
11251
11252/// OnCluster
11253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11254#[cfg_attr(feature = "bindings", derive(TS))]
11255pub struct OnCluster {
11256    pub this: Box<Expression>,
11257}
11258
11259/// LikeProperty
11260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11261#[cfg_attr(feature = "bindings", derive(TS))]
11262pub struct LikeProperty {
11263    pub this: Box<Expression>,
11264    #[serde(default)]
11265    pub expressions: Vec<Expression>,
11266}
11267
11268/// LocationProperty
11269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11270#[cfg_attr(feature = "bindings", derive(TS))]
11271pub struct LocationProperty {
11272    pub this: Box<Expression>,
11273}
11274
11275/// LockProperty
11276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11277#[cfg_attr(feature = "bindings", derive(TS))]
11278pub struct LockProperty {
11279    pub this: Box<Expression>,
11280}
11281
11282/// LockingProperty
11283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11284#[cfg_attr(feature = "bindings", derive(TS))]
11285pub struct LockingProperty {
11286    #[serde(default)]
11287    pub this: Option<Box<Expression>>,
11288    pub kind: String,
11289    #[serde(default)]
11290    pub for_or_in: Option<Box<Expression>>,
11291    #[serde(default)]
11292    pub lock_type: Option<Box<Expression>>,
11293    #[serde(default)]
11294    pub override_: Option<Box<Expression>>,
11295}
11296
11297/// LogProperty
11298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11299#[cfg_attr(feature = "bindings", derive(TS))]
11300pub struct LogProperty {
11301    #[serde(default)]
11302    pub no: Option<Box<Expression>>,
11303}
11304
11305/// MaterializedProperty
11306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11307#[cfg_attr(feature = "bindings", derive(TS))]
11308pub struct MaterializedProperty {
11309    #[serde(default)]
11310    pub this: Option<Box<Expression>>,
11311}
11312
11313/// MergeBlockRatioProperty
11314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11315#[cfg_attr(feature = "bindings", derive(TS))]
11316pub struct MergeBlockRatioProperty {
11317    #[serde(default)]
11318    pub this: Option<Box<Expression>>,
11319    #[serde(default)]
11320    pub no: Option<Box<Expression>>,
11321    #[serde(default)]
11322    pub default: Option<Box<Expression>>,
11323    #[serde(default)]
11324    pub percent: Option<Box<Expression>>,
11325}
11326
11327/// OnProperty
11328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11329#[cfg_attr(feature = "bindings", derive(TS))]
11330pub struct OnProperty {
11331    pub this: Box<Expression>,
11332}
11333
11334/// OnCommitProperty
11335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11336#[cfg_attr(feature = "bindings", derive(TS))]
11337pub struct OnCommitProperty {
11338    #[serde(default)]
11339    pub delete: Option<Box<Expression>>,
11340}
11341
11342/// PartitionedByProperty
11343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11344#[cfg_attr(feature = "bindings", derive(TS))]
11345pub struct PartitionedByProperty {
11346    pub this: Box<Expression>,
11347}
11348
11349/// BigQuery PARTITION BY property in CREATE TABLE statements.
11350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11351#[cfg_attr(feature = "bindings", derive(TS))]
11352pub struct PartitionByProperty {
11353    #[serde(default)]
11354    pub expressions: Vec<Expression>,
11355}
11356
11357/// PartitionedByBucket
11358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11359#[cfg_attr(feature = "bindings", derive(TS))]
11360pub struct PartitionedByBucket {
11361    pub this: Box<Expression>,
11362    pub expression: Box<Expression>,
11363}
11364
11365/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11367#[cfg_attr(feature = "bindings", derive(TS))]
11368pub struct ClusterByColumnsProperty {
11369    #[serde(default)]
11370    pub columns: Vec<Identifier>,
11371}
11372
11373/// PartitionByTruncate
11374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11375#[cfg_attr(feature = "bindings", derive(TS))]
11376pub struct PartitionByTruncate {
11377    pub this: Box<Expression>,
11378    pub expression: Box<Expression>,
11379}
11380
11381/// PartitionByRangeProperty
11382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11383#[cfg_attr(feature = "bindings", derive(TS))]
11384pub struct PartitionByRangeProperty {
11385    #[serde(default)]
11386    pub partition_expressions: Option<Box<Expression>>,
11387    #[serde(default)]
11388    pub create_expressions: Option<Box<Expression>>,
11389}
11390
11391/// PartitionByRangePropertyDynamic
11392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11393#[cfg_attr(feature = "bindings", derive(TS))]
11394pub struct PartitionByRangePropertyDynamic {
11395    #[serde(default)]
11396    pub this: Option<Box<Expression>>,
11397    #[serde(default)]
11398    pub start: Option<Box<Expression>>,
11399    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11400    #[serde(default)]
11401    pub use_start_end: bool,
11402    #[serde(default)]
11403    pub end: Option<Box<Expression>>,
11404    #[serde(default)]
11405    pub every: Option<Box<Expression>>,
11406}
11407
11408/// PartitionByListProperty
11409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11410#[cfg_attr(feature = "bindings", derive(TS))]
11411pub struct PartitionByListProperty {
11412    #[serde(default)]
11413    pub partition_expressions: Option<Box<Expression>>,
11414    #[serde(default)]
11415    pub create_expressions: Option<Box<Expression>>,
11416}
11417
11418/// PartitionList
11419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11420#[cfg_attr(feature = "bindings", derive(TS))]
11421pub struct PartitionList {
11422    pub this: Box<Expression>,
11423    #[serde(default)]
11424    pub expressions: Vec<Expression>,
11425}
11426
11427/// Partition - represents PARTITION/SUBPARTITION clause
11428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11429#[cfg_attr(feature = "bindings", derive(TS))]
11430pub struct Partition {
11431    pub expressions: Vec<Expression>,
11432    #[serde(default)]
11433    pub subpartition: bool,
11434}
11435
11436/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11437/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11439#[cfg_attr(feature = "bindings", derive(TS))]
11440pub struct RefreshTriggerProperty {
11441    /// Method: COMPLETE or AUTO
11442    pub method: String,
11443    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11444    #[serde(default)]
11445    pub kind: Option<String>,
11446    /// For SCHEDULE: EVERY n (the number)
11447    #[serde(default)]
11448    pub every: Option<Box<Expression>>,
11449    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11450    #[serde(default)]
11451    pub unit: Option<String>,
11452    /// For SCHEDULE: STARTS 'datetime'
11453    #[serde(default)]
11454    pub starts: Option<Box<Expression>>,
11455}
11456
11457/// UniqueKeyProperty
11458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11459#[cfg_attr(feature = "bindings", derive(TS))]
11460pub struct UniqueKeyProperty {
11461    #[serde(default)]
11462    pub expressions: Vec<Expression>,
11463}
11464
11465/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11467#[cfg_attr(feature = "bindings", derive(TS))]
11468pub struct RollupProperty {
11469    pub expressions: Vec<RollupIndex>,
11470}
11471
11472/// RollupIndex - A single rollup index: name(col1, col2)
11473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11474#[cfg_attr(feature = "bindings", derive(TS))]
11475pub struct RollupIndex {
11476    pub name: Identifier,
11477    pub expressions: Vec<Identifier>,
11478}
11479
11480/// PartitionBoundSpec
11481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11482#[cfg_attr(feature = "bindings", derive(TS))]
11483pub struct PartitionBoundSpec {
11484    #[serde(default)]
11485    pub this: Option<Box<Expression>>,
11486    #[serde(default)]
11487    pub expression: Option<Box<Expression>>,
11488    #[serde(default)]
11489    pub from_expressions: Option<Box<Expression>>,
11490    #[serde(default)]
11491    pub to_expressions: Option<Box<Expression>>,
11492}
11493
11494/// PartitionedOfProperty
11495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11496#[cfg_attr(feature = "bindings", derive(TS))]
11497pub struct PartitionedOfProperty {
11498    pub this: Box<Expression>,
11499    pub expression: Box<Expression>,
11500}
11501
11502/// RemoteWithConnectionModelProperty
11503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11504#[cfg_attr(feature = "bindings", derive(TS))]
11505pub struct RemoteWithConnectionModelProperty {
11506    pub this: Box<Expression>,
11507}
11508
11509/// ReturnsProperty
11510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11511#[cfg_attr(feature = "bindings", derive(TS))]
11512pub struct ReturnsProperty {
11513    #[serde(default)]
11514    pub this: Option<Box<Expression>>,
11515    #[serde(default)]
11516    pub is_table: Option<Box<Expression>>,
11517    #[serde(default)]
11518    pub table: Option<Box<Expression>>,
11519    #[serde(default)]
11520    pub null: Option<Box<Expression>>,
11521}
11522
11523/// RowFormatProperty
11524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11525#[cfg_attr(feature = "bindings", derive(TS))]
11526pub struct RowFormatProperty {
11527    pub this: Box<Expression>,
11528}
11529
11530/// RowFormatDelimitedProperty
11531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11532#[cfg_attr(feature = "bindings", derive(TS))]
11533pub struct RowFormatDelimitedProperty {
11534    #[serde(default)]
11535    pub fields: Option<Box<Expression>>,
11536    #[serde(default)]
11537    pub escaped: Option<Box<Expression>>,
11538    #[serde(default)]
11539    pub collection_items: Option<Box<Expression>>,
11540    #[serde(default)]
11541    pub map_keys: Option<Box<Expression>>,
11542    #[serde(default)]
11543    pub lines: Option<Box<Expression>>,
11544    #[serde(default)]
11545    pub null: Option<Box<Expression>>,
11546    #[serde(default)]
11547    pub serde: Option<Box<Expression>>,
11548}
11549
11550/// RowFormatSerdeProperty
11551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11552#[cfg_attr(feature = "bindings", derive(TS))]
11553pub struct RowFormatSerdeProperty {
11554    pub this: Box<Expression>,
11555    #[serde(default)]
11556    pub serde_properties: Option<Box<Expression>>,
11557}
11558
11559/// QueryTransform
11560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11561#[cfg_attr(feature = "bindings", derive(TS))]
11562pub struct QueryTransform {
11563    #[serde(default)]
11564    pub expressions: Vec<Expression>,
11565    #[serde(default)]
11566    pub command_script: Option<Box<Expression>>,
11567    #[serde(default)]
11568    pub schema: Option<Box<Expression>>,
11569    #[serde(default)]
11570    pub row_format_before: Option<Box<Expression>>,
11571    #[serde(default)]
11572    pub record_writer: Option<Box<Expression>>,
11573    #[serde(default)]
11574    pub row_format_after: Option<Box<Expression>>,
11575    #[serde(default)]
11576    pub record_reader: Option<Box<Expression>>,
11577}
11578
11579/// SampleProperty
11580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11581#[cfg_attr(feature = "bindings", derive(TS))]
11582pub struct SampleProperty {
11583    pub this: Box<Expression>,
11584}
11585
11586/// SecurityProperty
11587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11588#[cfg_attr(feature = "bindings", derive(TS))]
11589pub struct SecurityProperty {
11590    pub this: Box<Expression>,
11591}
11592
11593/// SchemaCommentProperty
11594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11595#[cfg_attr(feature = "bindings", derive(TS))]
11596pub struct SchemaCommentProperty {
11597    pub this: Box<Expression>,
11598}
11599
11600/// SemanticView
11601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11602#[cfg_attr(feature = "bindings", derive(TS))]
11603pub struct SemanticView {
11604    pub this: Box<Expression>,
11605    #[serde(default)]
11606    pub metrics: Option<Box<Expression>>,
11607    #[serde(default)]
11608    pub dimensions: Option<Box<Expression>>,
11609    #[serde(default)]
11610    pub facts: Option<Box<Expression>>,
11611    #[serde(default)]
11612    pub where_: Option<Box<Expression>>,
11613}
11614
11615/// SerdeProperties
11616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11617#[cfg_attr(feature = "bindings", derive(TS))]
11618pub struct SerdeProperties {
11619    #[serde(default)]
11620    pub expressions: Vec<Expression>,
11621    #[serde(default)]
11622    pub with_: Option<Box<Expression>>,
11623}
11624
11625/// SetProperty
11626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11627#[cfg_attr(feature = "bindings", derive(TS))]
11628pub struct SetProperty {
11629    #[serde(default)]
11630    pub multi: Option<Box<Expression>>,
11631}
11632
11633/// SharingProperty
11634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11635#[cfg_attr(feature = "bindings", derive(TS))]
11636pub struct SharingProperty {
11637    #[serde(default)]
11638    pub this: Option<Box<Expression>>,
11639}
11640
11641/// SetConfigProperty
11642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11643#[cfg_attr(feature = "bindings", derive(TS))]
11644pub struct SetConfigProperty {
11645    pub this: Box<Expression>,
11646}
11647
11648/// SettingsProperty
11649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11650#[cfg_attr(feature = "bindings", derive(TS))]
11651pub struct SettingsProperty {
11652    #[serde(default)]
11653    pub expressions: Vec<Expression>,
11654}
11655
11656/// SortKeyProperty
11657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11658#[cfg_attr(feature = "bindings", derive(TS))]
11659pub struct SortKeyProperty {
11660    pub this: Box<Expression>,
11661    #[serde(default)]
11662    pub compound: Option<Box<Expression>>,
11663}
11664
11665/// SqlReadWriteProperty
11666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11667#[cfg_attr(feature = "bindings", derive(TS))]
11668pub struct SqlReadWriteProperty {
11669    pub this: Box<Expression>,
11670}
11671
11672/// SqlSecurityProperty
11673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11674#[cfg_attr(feature = "bindings", derive(TS))]
11675pub struct SqlSecurityProperty {
11676    pub this: Box<Expression>,
11677}
11678
11679/// StabilityProperty
11680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11681#[cfg_attr(feature = "bindings", derive(TS))]
11682pub struct StabilityProperty {
11683    pub this: Box<Expression>,
11684}
11685
11686/// StorageHandlerProperty
11687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11688#[cfg_attr(feature = "bindings", derive(TS))]
11689pub struct StorageHandlerProperty {
11690    pub this: Box<Expression>,
11691}
11692
11693/// TemporaryProperty
11694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11695#[cfg_attr(feature = "bindings", derive(TS))]
11696pub struct TemporaryProperty {
11697    #[serde(default)]
11698    pub this: Option<Box<Expression>>,
11699}
11700
11701/// Tags
11702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11703#[cfg_attr(feature = "bindings", derive(TS))]
11704pub struct Tags {
11705    #[serde(default)]
11706    pub expressions: Vec<Expression>,
11707}
11708
11709/// TransformModelProperty
11710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11711#[cfg_attr(feature = "bindings", derive(TS))]
11712pub struct TransformModelProperty {
11713    #[serde(default)]
11714    pub expressions: Vec<Expression>,
11715}
11716
11717/// TransientProperty
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct TransientProperty {
11721    #[serde(default)]
11722    pub this: Option<Box<Expression>>,
11723}
11724
11725/// UsingTemplateProperty
11726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11727#[cfg_attr(feature = "bindings", derive(TS))]
11728pub struct UsingTemplateProperty {
11729    pub this: Box<Expression>,
11730}
11731
11732/// ViewAttributeProperty
11733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11734#[cfg_attr(feature = "bindings", derive(TS))]
11735pub struct ViewAttributeProperty {
11736    pub this: Box<Expression>,
11737}
11738
11739/// VolatileProperty
11740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11741#[cfg_attr(feature = "bindings", derive(TS))]
11742pub struct VolatileProperty {
11743    #[serde(default)]
11744    pub this: Option<Box<Expression>>,
11745}
11746
11747/// WithDataProperty
11748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11749#[cfg_attr(feature = "bindings", derive(TS))]
11750pub struct WithDataProperty {
11751    #[serde(default)]
11752    pub no: Option<Box<Expression>>,
11753    #[serde(default)]
11754    pub statistics: Option<Box<Expression>>,
11755}
11756
11757/// WithJournalTableProperty
11758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11759#[cfg_attr(feature = "bindings", derive(TS))]
11760pub struct WithJournalTableProperty {
11761    pub this: Box<Expression>,
11762}
11763
11764/// WithSchemaBindingProperty
11765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11766#[cfg_attr(feature = "bindings", derive(TS))]
11767pub struct WithSchemaBindingProperty {
11768    pub this: Box<Expression>,
11769}
11770
11771/// WithSystemVersioningProperty
11772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11773#[cfg_attr(feature = "bindings", derive(TS))]
11774pub struct WithSystemVersioningProperty {
11775    #[serde(default)]
11776    pub on: Option<Box<Expression>>,
11777    #[serde(default)]
11778    pub this: Option<Box<Expression>>,
11779    #[serde(default)]
11780    pub data_consistency: Option<Box<Expression>>,
11781    #[serde(default)]
11782    pub retention_period: Option<Box<Expression>>,
11783    #[serde(default)]
11784    pub with_: Option<Box<Expression>>,
11785}
11786
11787/// WithProcedureOptions
11788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11789#[cfg_attr(feature = "bindings", derive(TS))]
11790pub struct WithProcedureOptions {
11791    #[serde(default)]
11792    pub expressions: Vec<Expression>,
11793}
11794
11795/// EncodeProperty
11796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11797#[cfg_attr(feature = "bindings", derive(TS))]
11798pub struct EncodeProperty {
11799    pub this: Box<Expression>,
11800    #[serde(default)]
11801    pub properties: Vec<Expression>,
11802    #[serde(default)]
11803    pub key: Option<Box<Expression>>,
11804}
11805
11806/// IncludeProperty
11807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11808#[cfg_attr(feature = "bindings", derive(TS))]
11809pub struct IncludeProperty {
11810    pub this: Box<Expression>,
11811    #[serde(default)]
11812    pub alias: Option<String>,
11813    #[serde(default)]
11814    pub column_def: Option<Box<Expression>>,
11815}
11816
11817/// Properties
11818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11819#[cfg_attr(feature = "bindings", derive(TS))]
11820pub struct Properties {
11821    #[serde(default)]
11822    pub expressions: Vec<Expression>,
11823}
11824
11825/// Key/value pair in a BigQuery OPTIONS (...) clause.
11826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11827#[cfg_attr(feature = "bindings", derive(TS))]
11828pub struct OptionEntry {
11829    pub key: Identifier,
11830    pub value: Expression,
11831}
11832
11833/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11835#[cfg_attr(feature = "bindings", derive(TS))]
11836pub struct OptionsProperty {
11837    #[serde(default)]
11838    pub entries: Vec<OptionEntry>,
11839}
11840
11841/// InputOutputFormat
11842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11843#[cfg_attr(feature = "bindings", derive(TS))]
11844pub struct InputOutputFormat {
11845    #[serde(default)]
11846    pub input_format: Option<Box<Expression>>,
11847    #[serde(default)]
11848    pub output_format: Option<Box<Expression>>,
11849}
11850
11851/// Reference
11852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11853#[cfg_attr(feature = "bindings", derive(TS))]
11854pub struct Reference {
11855    pub this: Box<Expression>,
11856    #[serde(default)]
11857    pub expressions: Vec<Expression>,
11858    #[serde(default)]
11859    pub options: Vec<Expression>,
11860}
11861
11862/// QueryOption
11863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11864#[cfg_attr(feature = "bindings", derive(TS))]
11865pub struct QueryOption {
11866    pub this: Box<Expression>,
11867    #[serde(default)]
11868    pub expression: Option<Box<Expression>>,
11869}
11870
11871/// WithTableHint
11872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11873#[cfg_attr(feature = "bindings", derive(TS))]
11874pub struct WithTableHint {
11875    #[serde(default)]
11876    pub expressions: Vec<Expression>,
11877}
11878
11879/// IndexTableHint
11880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11881#[cfg_attr(feature = "bindings", derive(TS))]
11882pub struct IndexTableHint {
11883    pub this: Box<Expression>,
11884    #[serde(default)]
11885    pub expressions: Vec<Expression>,
11886    #[serde(default)]
11887    pub target: Option<Box<Expression>>,
11888}
11889
11890/// Get
11891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11892#[cfg_attr(feature = "bindings", derive(TS))]
11893pub struct Get {
11894    pub this: Box<Expression>,
11895    #[serde(default)]
11896    pub target: Option<Box<Expression>>,
11897    #[serde(default)]
11898    pub properties: Vec<Expression>,
11899}
11900
11901/// SetOperation
11902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11903#[cfg_attr(feature = "bindings", derive(TS))]
11904pub struct SetOperation {
11905    #[serde(default)]
11906    pub with_: Option<Box<Expression>>,
11907    pub this: Box<Expression>,
11908    pub expression: Box<Expression>,
11909    #[serde(default)]
11910    pub distinct: bool,
11911    #[serde(default)]
11912    pub by_name: Option<Box<Expression>>,
11913    #[serde(default)]
11914    pub side: Option<Box<Expression>>,
11915    #[serde(default)]
11916    pub kind: Option<String>,
11917    #[serde(default)]
11918    pub on: Option<Box<Expression>>,
11919}
11920
11921/// Var - Simple variable reference (for SQL variables, keywords as values)
11922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11923#[cfg_attr(feature = "bindings", derive(TS))]
11924pub struct Var {
11925    pub this: String,
11926}
11927
11928/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11930#[cfg_attr(feature = "bindings", derive(TS))]
11931pub struct Variadic {
11932    pub this: Box<Expression>,
11933}
11934
11935/// Version
11936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11937#[cfg_attr(feature = "bindings", derive(TS))]
11938pub struct Version {
11939    pub this: Box<Expression>,
11940    pub kind: String,
11941    #[serde(default)]
11942    pub expression: Option<Box<Expression>>,
11943}
11944
11945/// Schema
11946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11947#[cfg_attr(feature = "bindings", derive(TS))]
11948pub struct Schema {
11949    #[serde(default)]
11950    pub this: Option<Box<Expression>>,
11951    #[serde(default)]
11952    pub expressions: Vec<Expression>,
11953}
11954
11955/// Lock
11956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11957#[cfg_attr(feature = "bindings", derive(TS))]
11958pub struct Lock {
11959    #[serde(default)]
11960    pub update: Option<Box<Expression>>,
11961    #[serde(default)]
11962    pub expressions: Vec<Expression>,
11963    #[serde(default)]
11964    pub wait: Option<Box<Expression>>,
11965    #[serde(default)]
11966    pub key: Option<Box<Expression>>,
11967}
11968
11969/// TableSample - wraps an expression with a TABLESAMPLE clause
11970/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11972#[cfg_attr(feature = "bindings", derive(TS))]
11973pub struct TableSample {
11974    /// The expression being sampled (subquery, function, etc.)
11975    #[serde(default, skip_serializing_if = "Option::is_none")]
11976    pub this: Option<Box<Expression>>,
11977    /// The sample specification
11978    #[serde(default, skip_serializing_if = "Option::is_none")]
11979    pub sample: Option<Box<Sample>>,
11980    #[serde(default)]
11981    pub expressions: Vec<Expression>,
11982    #[serde(default)]
11983    pub method: Option<String>,
11984    #[serde(default)]
11985    pub bucket_numerator: Option<Box<Expression>>,
11986    #[serde(default)]
11987    pub bucket_denominator: Option<Box<Expression>>,
11988    #[serde(default)]
11989    pub bucket_field: Option<Box<Expression>>,
11990    #[serde(default)]
11991    pub percent: Option<Box<Expression>>,
11992    #[serde(default)]
11993    pub rows: Option<Box<Expression>>,
11994    #[serde(default)]
11995    pub size: Option<i64>,
11996    #[serde(default)]
11997    pub seed: Option<Box<Expression>>,
11998}
11999
12000/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
12001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12002#[cfg_attr(feature = "bindings", derive(TS))]
12003pub struct Tag {
12004    #[serde(default)]
12005    pub this: Option<Box<Expression>>,
12006    #[serde(default)]
12007    pub prefix: Option<Box<Expression>>,
12008    #[serde(default)]
12009    pub postfix: Option<Box<Expression>>,
12010}
12011
12012/// UnpivotColumns
12013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12014#[cfg_attr(feature = "bindings", derive(TS))]
12015pub struct UnpivotColumns {
12016    pub this: Box<Expression>,
12017    #[serde(default)]
12018    pub expressions: Vec<Expression>,
12019}
12020
12021/// SessionParameter
12022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12023#[cfg_attr(feature = "bindings", derive(TS))]
12024pub struct SessionParameter {
12025    pub this: Box<Expression>,
12026    #[serde(default)]
12027    pub kind: Option<String>,
12028}
12029
12030/// PseudoType
12031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12032#[cfg_attr(feature = "bindings", derive(TS))]
12033pub struct PseudoType {
12034    pub this: Box<Expression>,
12035}
12036
12037/// ObjectIdentifier
12038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12039#[cfg_attr(feature = "bindings", derive(TS))]
12040pub struct ObjectIdentifier {
12041    pub this: Box<Expression>,
12042}
12043
12044/// Transaction
12045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12046#[cfg_attr(feature = "bindings", derive(TS))]
12047pub struct Transaction {
12048    #[serde(default)]
12049    pub this: Option<Box<Expression>>,
12050    #[serde(default)]
12051    pub modes: Option<Box<Expression>>,
12052    #[serde(default)]
12053    pub mark: Option<Box<Expression>>,
12054}
12055
12056/// Commit
12057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12058#[cfg_attr(feature = "bindings", derive(TS))]
12059pub struct Commit {
12060    #[serde(default)]
12061    pub chain: Option<Box<Expression>>,
12062    #[serde(default)]
12063    pub this: Option<Box<Expression>>,
12064    #[serde(default)]
12065    pub durability: Option<Box<Expression>>,
12066}
12067
12068/// Rollback
12069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12070#[cfg_attr(feature = "bindings", derive(TS))]
12071pub struct Rollback {
12072    #[serde(default)]
12073    pub savepoint: Option<Box<Expression>>,
12074    #[serde(default)]
12075    pub this: Option<Box<Expression>>,
12076}
12077
12078/// AlterSession
12079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12080#[cfg_attr(feature = "bindings", derive(TS))]
12081pub struct AlterSession {
12082    #[serde(default)]
12083    pub expressions: Vec<Expression>,
12084    #[serde(default)]
12085    pub unset: Option<Box<Expression>>,
12086}
12087
12088/// Analyze
12089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12090#[cfg_attr(feature = "bindings", derive(TS))]
12091pub struct Analyze {
12092    #[serde(default)]
12093    pub kind: Option<String>,
12094    #[serde(default)]
12095    pub this: Option<Box<Expression>>,
12096    #[serde(default)]
12097    pub options: Vec<Expression>,
12098    #[serde(default)]
12099    pub mode: Option<Box<Expression>>,
12100    #[serde(default)]
12101    pub partition: Option<Box<Expression>>,
12102    #[serde(default)]
12103    pub expression: Option<Box<Expression>>,
12104    #[serde(default)]
12105    pub properties: Vec<Expression>,
12106    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
12107    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12108    pub columns: Vec<String>,
12109}
12110
12111/// AnalyzeStatistics
12112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12113#[cfg_attr(feature = "bindings", derive(TS))]
12114pub struct AnalyzeStatistics {
12115    pub kind: String,
12116    #[serde(default)]
12117    pub option: Option<Box<Expression>>,
12118    #[serde(default)]
12119    pub this: Option<Box<Expression>>,
12120    #[serde(default)]
12121    pub expressions: Vec<Expression>,
12122}
12123
12124/// AnalyzeHistogram
12125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12126#[cfg_attr(feature = "bindings", derive(TS))]
12127pub struct AnalyzeHistogram {
12128    pub this: Box<Expression>,
12129    #[serde(default)]
12130    pub expressions: Vec<Expression>,
12131    #[serde(default)]
12132    pub expression: Option<Box<Expression>>,
12133    #[serde(default)]
12134    pub update_options: Option<Box<Expression>>,
12135}
12136
12137/// AnalyzeSample
12138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12139#[cfg_attr(feature = "bindings", derive(TS))]
12140pub struct AnalyzeSample {
12141    pub kind: String,
12142    #[serde(default)]
12143    pub sample: Option<Box<Expression>>,
12144}
12145
12146/// AnalyzeListChainedRows
12147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12148#[cfg_attr(feature = "bindings", derive(TS))]
12149pub struct AnalyzeListChainedRows {
12150    #[serde(default)]
12151    pub expression: Option<Box<Expression>>,
12152}
12153
12154/// AnalyzeDelete
12155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12156#[cfg_attr(feature = "bindings", derive(TS))]
12157pub struct AnalyzeDelete {
12158    #[serde(default)]
12159    pub kind: Option<String>,
12160}
12161
12162/// AnalyzeWith
12163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12164#[cfg_attr(feature = "bindings", derive(TS))]
12165pub struct AnalyzeWith {
12166    #[serde(default)]
12167    pub expressions: Vec<Expression>,
12168}
12169
12170/// AnalyzeValidate
12171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12172#[cfg_attr(feature = "bindings", derive(TS))]
12173pub struct AnalyzeValidate {
12174    pub kind: String,
12175    #[serde(default)]
12176    pub this: Option<Box<Expression>>,
12177    #[serde(default)]
12178    pub expression: Option<Box<Expression>>,
12179}
12180
12181/// AddPartition
12182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12183#[cfg_attr(feature = "bindings", derive(TS))]
12184pub struct AddPartition {
12185    pub this: Box<Expression>,
12186    #[serde(default)]
12187    pub exists: bool,
12188    #[serde(default)]
12189    pub location: Option<Box<Expression>>,
12190}
12191
12192/// AttachOption
12193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12194#[cfg_attr(feature = "bindings", derive(TS))]
12195pub struct AttachOption {
12196    pub this: Box<Expression>,
12197    #[serde(default)]
12198    pub expression: Option<Box<Expression>>,
12199}
12200
12201/// DropPartition
12202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12203#[cfg_attr(feature = "bindings", derive(TS))]
12204pub struct DropPartition {
12205    #[serde(default)]
12206    pub expressions: Vec<Expression>,
12207    #[serde(default)]
12208    pub exists: bool,
12209}
12210
12211/// ReplacePartition
12212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12213#[cfg_attr(feature = "bindings", derive(TS))]
12214pub struct ReplacePartition {
12215    pub expression: Box<Expression>,
12216    #[serde(default)]
12217    pub source: Option<Box<Expression>>,
12218}
12219
12220/// DPipe
12221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12222#[cfg_attr(feature = "bindings", derive(TS))]
12223pub struct DPipe {
12224    pub this: Box<Expression>,
12225    pub expression: Box<Expression>,
12226    #[serde(default)]
12227    pub safe: Option<Box<Expression>>,
12228}
12229
12230/// Operator
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct Operator {
12234    pub this: Box<Expression>,
12235    #[serde(default)]
12236    pub operator: Option<Box<Expression>>,
12237    pub expression: Box<Expression>,
12238    /// Comments between OPERATOR() and the RHS expression
12239    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12240    pub comments: Vec<String>,
12241}
12242
12243/// PivotAny
12244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12245#[cfg_attr(feature = "bindings", derive(TS))]
12246pub struct PivotAny {
12247    #[serde(default)]
12248    pub this: Option<Box<Expression>>,
12249}
12250
12251/// Aliases
12252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12253#[cfg_attr(feature = "bindings", derive(TS))]
12254pub struct Aliases {
12255    pub this: Box<Expression>,
12256    #[serde(default)]
12257    pub expressions: Vec<Expression>,
12258}
12259
12260/// AtIndex
12261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12262#[cfg_attr(feature = "bindings", derive(TS))]
12263pub struct AtIndex {
12264    pub this: Box<Expression>,
12265    pub expression: Box<Expression>,
12266}
12267
12268/// FromTimeZone
12269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12270#[cfg_attr(feature = "bindings", derive(TS))]
12271pub struct FromTimeZone {
12272    pub this: Box<Expression>,
12273    #[serde(default)]
12274    pub zone: Option<Box<Expression>>,
12275}
12276
12277/// Format override for a column in Teradata
12278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12279#[cfg_attr(feature = "bindings", derive(TS))]
12280pub struct FormatPhrase {
12281    pub this: Box<Expression>,
12282    pub format: String,
12283}
12284
12285/// ForIn
12286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12287#[cfg_attr(feature = "bindings", derive(TS))]
12288pub struct ForIn {
12289    pub this: Box<Expression>,
12290    pub expression: Box<Expression>,
12291}
12292
12293/// Automatically converts unit arg into a var.
12294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12295#[cfg_attr(feature = "bindings", derive(TS))]
12296pub struct TimeUnit {
12297    #[serde(default)]
12298    pub unit: Option<String>,
12299}
12300
12301/// IntervalOp
12302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12303#[cfg_attr(feature = "bindings", derive(TS))]
12304pub struct IntervalOp {
12305    #[serde(default)]
12306    pub unit: Option<String>,
12307    pub expression: Box<Expression>,
12308}
12309
12310/// HavingMax
12311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12312#[cfg_attr(feature = "bindings", derive(TS))]
12313pub struct HavingMax {
12314    pub this: Box<Expression>,
12315    pub expression: Box<Expression>,
12316    #[serde(default)]
12317    pub max: Option<Box<Expression>>,
12318}
12319
12320/// CosineDistance
12321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12322#[cfg_attr(feature = "bindings", derive(TS))]
12323pub struct CosineDistance {
12324    pub this: Box<Expression>,
12325    pub expression: Box<Expression>,
12326}
12327
12328/// DotProduct
12329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12330#[cfg_attr(feature = "bindings", derive(TS))]
12331pub struct DotProduct {
12332    pub this: Box<Expression>,
12333    pub expression: Box<Expression>,
12334}
12335
12336/// EuclideanDistance
12337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12338#[cfg_attr(feature = "bindings", derive(TS))]
12339pub struct EuclideanDistance {
12340    pub this: Box<Expression>,
12341    pub expression: Box<Expression>,
12342}
12343
12344/// ManhattanDistance
12345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12346#[cfg_attr(feature = "bindings", derive(TS))]
12347pub struct ManhattanDistance {
12348    pub this: Box<Expression>,
12349    pub expression: Box<Expression>,
12350}
12351
12352/// JarowinklerSimilarity
12353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12354#[cfg_attr(feature = "bindings", derive(TS))]
12355pub struct JarowinklerSimilarity {
12356    pub this: Box<Expression>,
12357    pub expression: Box<Expression>,
12358}
12359
12360/// Booland
12361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12362#[cfg_attr(feature = "bindings", derive(TS))]
12363pub struct Booland {
12364    pub this: Box<Expression>,
12365    pub expression: Box<Expression>,
12366}
12367
12368/// Boolor
12369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12370#[cfg_attr(feature = "bindings", derive(TS))]
12371pub struct Boolor {
12372    pub this: Box<Expression>,
12373    pub expression: Box<Expression>,
12374}
12375
12376/// ParameterizedAgg
12377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12378#[cfg_attr(feature = "bindings", derive(TS))]
12379pub struct ParameterizedAgg {
12380    pub this: Box<Expression>,
12381    #[serde(default)]
12382    pub expressions: Vec<Expression>,
12383    #[serde(default)]
12384    pub params: Vec<Expression>,
12385}
12386
12387/// ArgMax
12388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12389#[cfg_attr(feature = "bindings", derive(TS))]
12390pub struct ArgMax {
12391    pub this: Box<Expression>,
12392    pub expression: Box<Expression>,
12393    #[serde(default)]
12394    pub count: Option<Box<Expression>>,
12395}
12396
12397/// ArgMin
12398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12399#[cfg_attr(feature = "bindings", derive(TS))]
12400pub struct ArgMin {
12401    pub this: Box<Expression>,
12402    pub expression: Box<Expression>,
12403    #[serde(default)]
12404    pub count: Option<Box<Expression>>,
12405}
12406
12407/// ApproxTopK
12408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12409#[cfg_attr(feature = "bindings", derive(TS))]
12410pub struct ApproxTopK {
12411    pub this: Box<Expression>,
12412    #[serde(default)]
12413    pub expression: Option<Box<Expression>>,
12414    #[serde(default)]
12415    pub counters: Option<Box<Expression>>,
12416}
12417
12418/// ApproxTopKAccumulate
12419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12420#[cfg_attr(feature = "bindings", derive(TS))]
12421pub struct ApproxTopKAccumulate {
12422    pub this: Box<Expression>,
12423    #[serde(default)]
12424    pub expression: Option<Box<Expression>>,
12425}
12426
12427/// ApproxTopKCombine
12428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12429#[cfg_attr(feature = "bindings", derive(TS))]
12430pub struct ApproxTopKCombine {
12431    pub this: Box<Expression>,
12432    #[serde(default)]
12433    pub expression: Option<Box<Expression>>,
12434}
12435
12436/// ApproxTopKEstimate
12437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12438#[cfg_attr(feature = "bindings", derive(TS))]
12439pub struct ApproxTopKEstimate {
12440    pub this: Box<Expression>,
12441    #[serde(default)]
12442    pub expression: Option<Box<Expression>>,
12443}
12444
12445/// ApproxTopSum
12446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12447#[cfg_attr(feature = "bindings", derive(TS))]
12448pub struct ApproxTopSum {
12449    pub this: Box<Expression>,
12450    pub expression: Box<Expression>,
12451    #[serde(default)]
12452    pub count: Option<Box<Expression>>,
12453}
12454
12455/// ApproxQuantiles
12456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12457#[cfg_attr(feature = "bindings", derive(TS))]
12458pub struct ApproxQuantiles {
12459    pub this: Box<Expression>,
12460    #[serde(default)]
12461    pub expression: Option<Box<Expression>>,
12462}
12463
12464/// Minhash
12465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12466#[cfg_attr(feature = "bindings", derive(TS))]
12467pub struct Minhash {
12468    pub this: Box<Expression>,
12469    #[serde(default)]
12470    pub expressions: Vec<Expression>,
12471}
12472
12473/// FarmFingerprint
12474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12475#[cfg_attr(feature = "bindings", derive(TS))]
12476pub struct FarmFingerprint {
12477    #[serde(default)]
12478    pub expressions: Vec<Expression>,
12479}
12480
12481/// Float64
12482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12483#[cfg_attr(feature = "bindings", derive(TS))]
12484pub struct Float64 {
12485    pub this: Box<Expression>,
12486    #[serde(default)]
12487    pub expression: Option<Box<Expression>>,
12488}
12489
12490/// Transform
12491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12492#[cfg_attr(feature = "bindings", derive(TS))]
12493pub struct Transform {
12494    pub this: Box<Expression>,
12495    pub expression: Box<Expression>,
12496}
12497
12498/// Translate
12499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12500#[cfg_attr(feature = "bindings", derive(TS))]
12501pub struct Translate {
12502    pub this: Box<Expression>,
12503    #[serde(default)]
12504    pub from_: Option<Box<Expression>>,
12505    #[serde(default)]
12506    pub to: Option<Box<Expression>>,
12507}
12508
12509/// Grouping
12510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12511#[cfg_attr(feature = "bindings", derive(TS))]
12512pub struct Grouping {
12513    #[serde(default)]
12514    pub expressions: Vec<Expression>,
12515}
12516
12517/// GroupingId
12518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12519#[cfg_attr(feature = "bindings", derive(TS))]
12520pub struct GroupingId {
12521    #[serde(default)]
12522    pub expressions: Vec<Expression>,
12523}
12524
12525/// Anonymous
12526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12527#[cfg_attr(feature = "bindings", derive(TS))]
12528pub struct Anonymous {
12529    pub this: Box<Expression>,
12530    #[serde(default)]
12531    pub expressions: Vec<Expression>,
12532}
12533
12534/// AnonymousAggFunc
12535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12536#[cfg_attr(feature = "bindings", derive(TS))]
12537pub struct AnonymousAggFunc {
12538    pub this: Box<Expression>,
12539    #[serde(default)]
12540    pub expressions: Vec<Expression>,
12541}
12542
12543/// CombinedAggFunc
12544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12545#[cfg_attr(feature = "bindings", derive(TS))]
12546pub struct CombinedAggFunc {
12547    pub this: Box<Expression>,
12548    #[serde(default)]
12549    pub expressions: Vec<Expression>,
12550}
12551
12552/// CombinedParameterizedAgg
12553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12554#[cfg_attr(feature = "bindings", derive(TS))]
12555pub struct CombinedParameterizedAgg {
12556    pub this: Box<Expression>,
12557    #[serde(default)]
12558    pub expressions: Vec<Expression>,
12559    #[serde(default)]
12560    pub params: Vec<Expression>,
12561}
12562
12563/// HashAgg
12564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12565#[cfg_attr(feature = "bindings", derive(TS))]
12566pub struct HashAgg {
12567    pub this: Box<Expression>,
12568    #[serde(default)]
12569    pub expressions: Vec<Expression>,
12570}
12571
12572/// Hll
12573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12574#[cfg_attr(feature = "bindings", derive(TS))]
12575pub struct Hll {
12576    pub this: Box<Expression>,
12577    #[serde(default)]
12578    pub expressions: Vec<Expression>,
12579}
12580
12581/// Apply
12582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12583#[cfg_attr(feature = "bindings", derive(TS))]
12584pub struct Apply {
12585    pub this: Box<Expression>,
12586    pub expression: Box<Expression>,
12587}
12588
12589/// ToBoolean
12590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12591#[cfg_attr(feature = "bindings", derive(TS))]
12592pub struct ToBoolean {
12593    pub this: Box<Expression>,
12594    #[serde(default)]
12595    pub safe: Option<Box<Expression>>,
12596}
12597
12598/// List
12599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12600#[cfg_attr(feature = "bindings", derive(TS))]
12601pub struct List {
12602    #[serde(default)]
12603    pub expressions: Vec<Expression>,
12604}
12605
12606/// ToMap - Materialize-style map constructor
12607/// Can hold either:
12608/// - A SELECT subquery (MAP(SELECT 'a', 1))
12609/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12611#[cfg_attr(feature = "bindings", derive(TS))]
12612pub struct ToMap {
12613    /// Either a Select subquery or a Struct containing PropertyEQ entries
12614    pub this: Box<Expression>,
12615}
12616
12617/// Pad
12618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12619#[cfg_attr(feature = "bindings", derive(TS))]
12620pub struct Pad {
12621    pub this: Box<Expression>,
12622    pub expression: Box<Expression>,
12623    #[serde(default)]
12624    pub fill_pattern: Option<Box<Expression>>,
12625    #[serde(default)]
12626    pub is_left: Option<Box<Expression>>,
12627}
12628
12629/// ToChar
12630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12631#[cfg_attr(feature = "bindings", derive(TS))]
12632pub struct ToChar {
12633    pub this: Box<Expression>,
12634    #[serde(default)]
12635    pub format: Option<String>,
12636    #[serde(default)]
12637    pub nlsparam: Option<Box<Expression>>,
12638    #[serde(default)]
12639    pub is_numeric: Option<Box<Expression>>,
12640}
12641
12642/// StringFunc - String type conversion function (BigQuery STRING)
12643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12644#[cfg_attr(feature = "bindings", derive(TS))]
12645pub struct StringFunc {
12646    pub this: Box<Expression>,
12647    #[serde(default)]
12648    pub zone: Option<Box<Expression>>,
12649}
12650
12651/// ToNumber
12652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12653#[cfg_attr(feature = "bindings", derive(TS))]
12654pub struct ToNumber {
12655    pub this: Box<Expression>,
12656    #[serde(default)]
12657    pub format: Option<Box<Expression>>,
12658    #[serde(default)]
12659    pub nlsparam: Option<Box<Expression>>,
12660    #[serde(default)]
12661    pub precision: Option<Box<Expression>>,
12662    #[serde(default)]
12663    pub scale: Option<Box<Expression>>,
12664    #[serde(default)]
12665    pub safe: Option<Box<Expression>>,
12666    #[serde(default)]
12667    pub safe_name: Option<Box<Expression>>,
12668}
12669
12670/// ToDouble
12671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12672#[cfg_attr(feature = "bindings", derive(TS))]
12673pub struct ToDouble {
12674    pub this: Box<Expression>,
12675    #[serde(default)]
12676    pub format: Option<String>,
12677    #[serde(default)]
12678    pub safe: Option<Box<Expression>>,
12679}
12680
12681/// ToDecfloat
12682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12683#[cfg_attr(feature = "bindings", derive(TS))]
12684pub struct ToDecfloat {
12685    pub this: Box<Expression>,
12686    #[serde(default)]
12687    pub format: Option<String>,
12688}
12689
12690/// TryToDecfloat
12691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12692#[cfg_attr(feature = "bindings", derive(TS))]
12693pub struct TryToDecfloat {
12694    pub this: Box<Expression>,
12695    #[serde(default)]
12696    pub format: Option<String>,
12697}
12698
12699/// ToFile
12700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12701#[cfg_attr(feature = "bindings", derive(TS))]
12702pub struct ToFile {
12703    pub this: Box<Expression>,
12704    #[serde(default)]
12705    pub path: Option<Box<Expression>>,
12706    #[serde(default)]
12707    pub safe: Option<Box<Expression>>,
12708}
12709
12710/// Columns
12711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12712#[cfg_attr(feature = "bindings", derive(TS))]
12713pub struct Columns {
12714    pub this: Box<Expression>,
12715    #[serde(default)]
12716    pub unpack: Option<Box<Expression>>,
12717}
12718
12719/// ConvertToCharset
12720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12721#[cfg_attr(feature = "bindings", derive(TS))]
12722pub struct ConvertToCharset {
12723    pub this: Box<Expression>,
12724    #[serde(default)]
12725    pub dest: Option<Box<Expression>>,
12726    #[serde(default)]
12727    pub source: Option<Box<Expression>>,
12728}
12729
12730/// ConvertTimezone
12731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12732#[cfg_attr(feature = "bindings", derive(TS))]
12733pub struct ConvertTimezone {
12734    #[serde(default)]
12735    pub source_tz: Option<Box<Expression>>,
12736    #[serde(default)]
12737    pub target_tz: Option<Box<Expression>>,
12738    #[serde(default)]
12739    pub timestamp: Option<Box<Expression>>,
12740    #[serde(default)]
12741    pub options: Vec<Expression>,
12742}
12743
12744/// GenerateSeries
12745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12746#[cfg_attr(feature = "bindings", derive(TS))]
12747pub struct GenerateSeries {
12748    #[serde(default)]
12749    pub start: Option<Box<Expression>>,
12750    #[serde(default)]
12751    pub end: Option<Box<Expression>>,
12752    #[serde(default)]
12753    pub step: Option<Box<Expression>>,
12754    #[serde(default)]
12755    pub is_end_exclusive: Option<Box<Expression>>,
12756}
12757
12758/// AIAgg
12759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12760#[cfg_attr(feature = "bindings", derive(TS))]
12761pub struct AIAgg {
12762    pub this: Box<Expression>,
12763    pub expression: Box<Expression>,
12764}
12765
12766/// AIClassify
12767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12768#[cfg_attr(feature = "bindings", derive(TS))]
12769pub struct AIClassify {
12770    pub this: Box<Expression>,
12771    #[serde(default)]
12772    pub categories: Option<Box<Expression>>,
12773    #[serde(default)]
12774    pub config: Option<Box<Expression>>,
12775}
12776
12777/// ArrayAll
12778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12779#[cfg_attr(feature = "bindings", derive(TS))]
12780pub struct ArrayAll {
12781    pub this: Box<Expression>,
12782    pub expression: Box<Expression>,
12783}
12784
12785/// ArrayAny
12786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12787#[cfg_attr(feature = "bindings", derive(TS))]
12788pub struct ArrayAny {
12789    pub this: Box<Expression>,
12790    pub expression: Box<Expression>,
12791}
12792
12793/// ArrayConstructCompact
12794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12795#[cfg_attr(feature = "bindings", derive(TS))]
12796pub struct ArrayConstructCompact {
12797    #[serde(default)]
12798    pub expressions: Vec<Expression>,
12799}
12800
12801/// StPoint
12802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12803#[cfg_attr(feature = "bindings", derive(TS))]
12804pub struct StPoint {
12805    pub this: Box<Expression>,
12806    pub expression: Box<Expression>,
12807    #[serde(default)]
12808    pub null: Option<Box<Expression>>,
12809}
12810
12811/// StDistance
12812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12813#[cfg_attr(feature = "bindings", derive(TS))]
12814pub struct StDistance {
12815    pub this: Box<Expression>,
12816    pub expression: Box<Expression>,
12817    #[serde(default)]
12818    pub use_spheroid: Option<Box<Expression>>,
12819}
12820
12821/// StringToArray
12822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12823#[cfg_attr(feature = "bindings", derive(TS))]
12824pub struct StringToArray {
12825    pub this: Box<Expression>,
12826    #[serde(default)]
12827    pub expression: Option<Box<Expression>>,
12828    #[serde(default)]
12829    pub null: Option<Box<Expression>>,
12830}
12831
12832/// ArraySum
12833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12834#[cfg_attr(feature = "bindings", derive(TS))]
12835pub struct ArraySum {
12836    pub this: Box<Expression>,
12837    #[serde(default)]
12838    pub expression: Option<Box<Expression>>,
12839}
12840
12841/// ObjectAgg
12842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12843#[cfg_attr(feature = "bindings", derive(TS))]
12844pub struct ObjectAgg {
12845    pub this: Box<Expression>,
12846    pub expression: Box<Expression>,
12847}
12848
12849/// CastToStrType
12850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12851#[cfg_attr(feature = "bindings", derive(TS))]
12852pub struct CastToStrType {
12853    pub this: Box<Expression>,
12854    #[serde(default)]
12855    pub to: Option<Box<Expression>>,
12856}
12857
12858/// CheckJson
12859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12860#[cfg_attr(feature = "bindings", derive(TS))]
12861pub struct CheckJson {
12862    pub this: Box<Expression>,
12863}
12864
12865/// CheckXml
12866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12867#[cfg_attr(feature = "bindings", derive(TS))]
12868pub struct CheckXml {
12869    pub this: Box<Expression>,
12870    #[serde(default)]
12871    pub disable_auto_convert: Option<Box<Expression>>,
12872}
12873
12874/// TranslateCharacters
12875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12876#[cfg_attr(feature = "bindings", derive(TS))]
12877pub struct TranslateCharacters {
12878    pub this: Box<Expression>,
12879    pub expression: Box<Expression>,
12880    #[serde(default)]
12881    pub with_error: Option<Box<Expression>>,
12882}
12883
12884/// CurrentSchemas
12885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12886#[cfg_attr(feature = "bindings", derive(TS))]
12887pub struct CurrentSchemas {
12888    #[serde(default)]
12889    pub this: Option<Box<Expression>>,
12890}
12891
12892/// CurrentDatetime
12893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12894#[cfg_attr(feature = "bindings", derive(TS))]
12895pub struct CurrentDatetime {
12896    #[serde(default)]
12897    pub this: Option<Box<Expression>>,
12898}
12899
12900/// Localtime
12901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12902#[cfg_attr(feature = "bindings", derive(TS))]
12903pub struct Localtime {
12904    #[serde(default)]
12905    pub this: Option<Box<Expression>>,
12906}
12907
12908/// Localtimestamp
12909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12910#[cfg_attr(feature = "bindings", derive(TS))]
12911pub struct Localtimestamp {
12912    #[serde(default)]
12913    pub this: Option<Box<Expression>>,
12914}
12915
12916/// Systimestamp
12917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12918#[cfg_attr(feature = "bindings", derive(TS))]
12919pub struct Systimestamp {
12920    #[serde(default)]
12921    pub this: Option<Box<Expression>>,
12922}
12923
12924/// CurrentSchema
12925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12926#[cfg_attr(feature = "bindings", derive(TS))]
12927pub struct CurrentSchema {
12928    #[serde(default)]
12929    pub this: Option<Box<Expression>>,
12930}
12931
12932/// CurrentUser
12933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12934#[cfg_attr(feature = "bindings", derive(TS))]
12935pub struct CurrentUser {
12936    #[serde(default)]
12937    pub this: Option<Box<Expression>>,
12938}
12939
12940/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12942#[cfg_attr(feature = "bindings", derive(TS))]
12943pub struct SessionUser;
12944
12945/// JSONPathRoot - Represents $ in JSON path expressions
12946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12947#[cfg_attr(feature = "bindings", derive(TS))]
12948pub struct JSONPathRoot;
12949
12950/// UtcTime
12951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12952#[cfg_attr(feature = "bindings", derive(TS))]
12953pub struct UtcTime {
12954    #[serde(default)]
12955    pub this: Option<Box<Expression>>,
12956}
12957
12958/// UtcTimestamp
12959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12960#[cfg_attr(feature = "bindings", derive(TS))]
12961pub struct UtcTimestamp {
12962    #[serde(default)]
12963    pub this: Option<Box<Expression>>,
12964}
12965
12966/// TimestampFunc - TIMESTAMP constructor function
12967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12968#[cfg_attr(feature = "bindings", derive(TS))]
12969pub struct TimestampFunc {
12970    #[serde(default)]
12971    pub this: Option<Box<Expression>>,
12972    #[serde(default)]
12973    pub zone: Option<Box<Expression>>,
12974    #[serde(default)]
12975    pub with_tz: Option<bool>,
12976    #[serde(default)]
12977    pub safe: Option<bool>,
12978}
12979
12980/// DateBin
12981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12982#[cfg_attr(feature = "bindings", derive(TS))]
12983pub struct DateBin {
12984    pub this: Box<Expression>,
12985    pub expression: Box<Expression>,
12986    #[serde(default)]
12987    pub unit: Option<String>,
12988    #[serde(default)]
12989    pub zone: Option<Box<Expression>>,
12990    #[serde(default)]
12991    pub origin: Option<Box<Expression>>,
12992}
12993
12994/// Datetime
12995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12996#[cfg_attr(feature = "bindings", derive(TS))]
12997pub struct Datetime {
12998    pub this: Box<Expression>,
12999    #[serde(default)]
13000    pub expression: Option<Box<Expression>>,
13001}
13002
13003/// DatetimeAdd
13004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13005#[cfg_attr(feature = "bindings", derive(TS))]
13006pub struct DatetimeAdd {
13007    pub this: Box<Expression>,
13008    pub expression: Box<Expression>,
13009    #[serde(default)]
13010    pub unit: Option<String>,
13011}
13012
13013/// DatetimeSub
13014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13015#[cfg_attr(feature = "bindings", derive(TS))]
13016pub struct DatetimeSub {
13017    pub this: Box<Expression>,
13018    pub expression: Box<Expression>,
13019    #[serde(default)]
13020    pub unit: Option<String>,
13021}
13022
13023/// DatetimeDiff
13024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13025#[cfg_attr(feature = "bindings", derive(TS))]
13026pub struct DatetimeDiff {
13027    pub this: Box<Expression>,
13028    pub expression: Box<Expression>,
13029    #[serde(default)]
13030    pub unit: Option<String>,
13031}
13032
13033/// DatetimeTrunc
13034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13035#[cfg_attr(feature = "bindings", derive(TS))]
13036pub struct DatetimeTrunc {
13037    pub this: Box<Expression>,
13038    pub unit: String,
13039    #[serde(default)]
13040    pub zone: Option<Box<Expression>>,
13041}
13042
13043/// Dayname
13044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13045#[cfg_attr(feature = "bindings", derive(TS))]
13046pub struct Dayname {
13047    pub this: Box<Expression>,
13048    #[serde(default)]
13049    pub abbreviated: Option<Box<Expression>>,
13050}
13051
13052/// MakeInterval
13053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13054#[cfg_attr(feature = "bindings", derive(TS))]
13055pub struct MakeInterval {
13056    #[serde(default)]
13057    pub year: Option<Box<Expression>>,
13058    #[serde(default)]
13059    pub month: Option<Box<Expression>>,
13060    #[serde(default)]
13061    pub week: Option<Box<Expression>>,
13062    #[serde(default)]
13063    pub day: Option<Box<Expression>>,
13064    #[serde(default)]
13065    pub hour: Option<Box<Expression>>,
13066    #[serde(default)]
13067    pub minute: Option<Box<Expression>>,
13068    #[serde(default)]
13069    pub second: Option<Box<Expression>>,
13070}
13071
13072/// PreviousDay
13073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13074#[cfg_attr(feature = "bindings", derive(TS))]
13075pub struct PreviousDay {
13076    pub this: Box<Expression>,
13077    pub expression: Box<Expression>,
13078}
13079
13080/// Elt
13081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13082#[cfg_attr(feature = "bindings", derive(TS))]
13083pub struct Elt {
13084    pub this: Box<Expression>,
13085    #[serde(default)]
13086    pub expressions: Vec<Expression>,
13087}
13088
13089/// TimestampAdd
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct TimestampAdd {
13093    pub this: Box<Expression>,
13094    pub expression: Box<Expression>,
13095    #[serde(default)]
13096    pub unit: Option<String>,
13097}
13098
13099/// TimestampSub
13100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13101#[cfg_attr(feature = "bindings", derive(TS))]
13102pub struct TimestampSub {
13103    pub this: Box<Expression>,
13104    pub expression: Box<Expression>,
13105    #[serde(default)]
13106    pub unit: Option<String>,
13107}
13108
13109/// TimestampDiff
13110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13111#[cfg_attr(feature = "bindings", derive(TS))]
13112pub struct TimestampDiff {
13113    pub this: Box<Expression>,
13114    pub expression: Box<Expression>,
13115    #[serde(default)]
13116    pub unit: Option<String>,
13117}
13118
13119/// TimeSlice
13120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13121#[cfg_attr(feature = "bindings", derive(TS))]
13122pub struct TimeSlice {
13123    pub this: Box<Expression>,
13124    pub expression: Box<Expression>,
13125    pub unit: String,
13126    #[serde(default)]
13127    pub kind: Option<String>,
13128}
13129
13130/// TimeAdd
13131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13132#[cfg_attr(feature = "bindings", derive(TS))]
13133pub struct TimeAdd {
13134    pub this: Box<Expression>,
13135    pub expression: Box<Expression>,
13136    #[serde(default)]
13137    pub unit: Option<String>,
13138}
13139
13140/// TimeSub
13141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13142#[cfg_attr(feature = "bindings", derive(TS))]
13143pub struct TimeSub {
13144    pub this: Box<Expression>,
13145    pub expression: Box<Expression>,
13146    #[serde(default)]
13147    pub unit: Option<String>,
13148}
13149
13150/// TimeDiff
13151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13152#[cfg_attr(feature = "bindings", derive(TS))]
13153pub struct TimeDiff {
13154    pub this: Box<Expression>,
13155    pub expression: Box<Expression>,
13156    #[serde(default)]
13157    pub unit: Option<String>,
13158}
13159
13160/// TimeTrunc
13161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13162#[cfg_attr(feature = "bindings", derive(TS))]
13163pub struct TimeTrunc {
13164    pub this: Box<Expression>,
13165    pub unit: String,
13166    #[serde(default)]
13167    pub zone: Option<Box<Expression>>,
13168}
13169
13170/// DateFromParts
13171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13172#[cfg_attr(feature = "bindings", derive(TS))]
13173pub struct DateFromParts {
13174    #[serde(default)]
13175    pub year: Option<Box<Expression>>,
13176    #[serde(default)]
13177    pub month: Option<Box<Expression>>,
13178    #[serde(default)]
13179    pub day: Option<Box<Expression>>,
13180    #[serde(default)]
13181    pub allow_overflow: Option<Box<Expression>>,
13182}
13183
13184/// TimeFromParts
13185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13186#[cfg_attr(feature = "bindings", derive(TS))]
13187pub struct TimeFromParts {
13188    #[serde(default)]
13189    pub hour: Option<Box<Expression>>,
13190    #[serde(default)]
13191    pub min: Option<Box<Expression>>,
13192    #[serde(default)]
13193    pub sec: Option<Box<Expression>>,
13194    #[serde(default)]
13195    pub nano: Option<Box<Expression>>,
13196    #[serde(default)]
13197    pub fractions: Option<Box<Expression>>,
13198    #[serde(default)]
13199    pub precision: Option<i64>,
13200}
13201
13202/// DecodeCase
13203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13204#[cfg_attr(feature = "bindings", derive(TS))]
13205pub struct DecodeCase {
13206    #[serde(default)]
13207    pub expressions: Vec<Expression>,
13208}
13209
13210/// Decrypt
13211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13212#[cfg_attr(feature = "bindings", derive(TS))]
13213pub struct Decrypt {
13214    pub this: Box<Expression>,
13215    #[serde(default)]
13216    pub passphrase: Option<Box<Expression>>,
13217    #[serde(default)]
13218    pub aad: Option<Box<Expression>>,
13219    #[serde(default)]
13220    pub encryption_method: Option<Box<Expression>>,
13221    #[serde(default)]
13222    pub safe: Option<Box<Expression>>,
13223}
13224
13225/// DecryptRaw
13226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13227#[cfg_attr(feature = "bindings", derive(TS))]
13228pub struct DecryptRaw {
13229    pub this: Box<Expression>,
13230    #[serde(default)]
13231    pub key: Option<Box<Expression>>,
13232    #[serde(default)]
13233    pub iv: Option<Box<Expression>>,
13234    #[serde(default)]
13235    pub aad: Option<Box<Expression>>,
13236    #[serde(default)]
13237    pub encryption_method: Option<Box<Expression>>,
13238    #[serde(default)]
13239    pub aead: Option<Box<Expression>>,
13240    #[serde(default)]
13241    pub safe: Option<Box<Expression>>,
13242}
13243
13244/// Encode
13245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13246#[cfg_attr(feature = "bindings", derive(TS))]
13247pub struct Encode {
13248    pub this: Box<Expression>,
13249    #[serde(default)]
13250    pub charset: Option<Box<Expression>>,
13251}
13252
13253/// Encrypt
13254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13255#[cfg_attr(feature = "bindings", derive(TS))]
13256pub struct Encrypt {
13257    pub this: Box<Expression>,
13258    #[serde(default)]
13259    pub passphrase: Option<Box<Expression>>,
13260    #[serde(default)]
13261    pub aad: Option<Box<Expression>>,
13262    #[serde(default)]
13263    pub encryption_method: Option<Box<Expression>>,
13264}
13265
13266/// EncryptRaw
13267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13268#[cfg_attr(feature = "bindings", derive(TS))]
13269pub struct EncryptRaw {
13270    pub this: Box<Expression>,
13271    #[serde(default)]
13272    pub key: Option<Box<Expression>>,
13273    #[serde(default)]
13274    pub iv: Option<Box<Expression>>,
13275    #[serde(default)]
13276    pub aad: Option<Box<Expression>>,
13277    #[serde(default)]
13278    pub encryption_method: Option<Box<Expression>>,
13279}
13280
13281/// EqualNull
13282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13283#[cfg_attr(feature = "bindings", derive(TS))]
13284pub struct EqualNull {
13285    pub this: Box<Expression>,
13286    pub expression: Box<Expression>,
13287}
13288
13289/// ToBinary
13290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13291#[cfg_attr(feature = "bindings", derive(TS))]
13292pub struct ToBinary {
13293    pub this: Box<Expression>,
13294    #[serde(default)]
13295    pub format: Option<String>,
13296    #[serde(default)]
13297    pub safe: Option<Box<Expression>>,
13298}
13299
13300/// Base64DecodeBinary
13301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13302#[cfg_attr(feature = "bindings", derive(TS))]
13303pub struct Base64DecodeBinary {
13304    pub this: Box<Expression>,
13305    #[serde(default)]
13306    pub alphabet: Option<Box<Expression>>,
13307}
13308
13309/// Base64DecodeString
13310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13311#[cfg_attr(feature = "bindings", derive(TS))]
13312pub struct Base64DecodeString {
13313    pub this: Box<Expression>,
13314    #[serde(default)]
13315    pub alphabet: Option<Box<Expression>>,
13316}
13317
13318/// Base64Encode
13319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13320#[cfg_attr(feature = "bindings", derive(TS))]
13321pub struct Base64Encode {
13322    pub this: Box<Expression>,
13323    #[serde(default)]
13324    pub max_line_length: Option<Box<Expression>>,
13325    #[serde(default)]
13326    pub alphabet: Option<Box<Expression>>,
13327}
13328
13329/// TryBase64DecodeBinary
13330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13331#[cfg_attr(feature = "bindings", derive(TS))]
13332pub struct TryBase64DecodeBinary {
13333    pub this: Box<Expression>,
13334    #[serde(default)]
13335    pub alphabet: Option<Box<Expression>>,
13336}
13337
13338/// TryBase64DecodeString
13339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13340#[cfg_attr(feature = "bindings", derive(TS))]
13341pub struct TryBase64DecodeString {
13342    pub this: Box<Expression>,
13343    #[serde(default)]
13344    pub alphabet: Option<Box<Expression>>,
13345}
13346
13347/// GapFill
13348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13349#[cfg_attr(feature = "bindings", derive(TS))]
13350pub struct GapFill {
13351    pub this: Box<Expression>,
13352    #[serde(default)]
13353    pub ts_column: Option<Box<Expression>>,
13354    #[serde(default)]
13355    pub bucket_width: Option<Box<Expression>>,
13356    #[serde(default)]
13357    pub partitioning_columns: Option<Box<Expression>>,
13358    #[serde(default)]
13359    pub value_columns: Option<Box<Expression>>,
13360    #[serde(default)]
13361    pub origin: Option<Box<Expression>>,
13362    #[serde(default)]
13363    pub ignore_nulls: Option<Box<Expression>>,
13364}
13365
13366/// GenerateDateArray
13367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13368#[cfg_attr(feature = "bindings", derive(TS))]
13369pub struct GenerateDateArray {
13370    #[serde(default)]
13371    pub start: Option<Box<Expression>>,
13372    #[serde(default)]
13373    pub end: Option<Box<Expression>>,
13374    #[serde(default)]
13375    pub step: Option<Box<Expression>>,
13376}
13377
13378/// GenerateTimestampArray
13379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13380#[cfg_attr(feature = "bindings", derive(TS))]
13381pub struct GenerateTimestampArray {
13382    #[serde(default)]
13383    pub start: Option<Box<Expression>>,
13384    #[serde(default)]
13385    pub end: Option<Box<Expression>>,
13386    #[serde(default)]
13387    pub step: Option<Box<Expression>>,
13388}
13389
13390/// GetExtract
13391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13392#[cfg_attr(feature = "bindings", derive(TS))]
13393pub struct GetExtract {
13394    pub this: Box<Expression>,
13395    pub expression: Box<Expression>,
13396}
13397
13398/// Getbit
13399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13400#[cfg_attr(feature = "bindings", derive(TS))]
13401pub struct Getbit {
13402    pub this: Box<Expression>,
13403    pub expression: Box<Expression>,
13404    #[serde(default)]
13405    pub zero_is_msb: Option<Box<Expression>>,
13406}
13407
13408/// OverflowTruncateBehavior
13409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13410#[cfg_attr(feature = "bindings", derive(TS))]
13411pub struct OverflowTruncateBehavior {
13412    #[serde(default)]
13413    pub this: Option<Box<Expression>>,
13414    #[serde(default)]
13415    pub with_count: Option<Box<Expression>>,
13416}
13417
13418/// HexEncode
13419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13420#[cfg_attr(feature = "bindings", derive(TS))]
13421pub struct HexEncode {
13422    pub this: Box<Expression>,
13423    #[serde(default)]
13424    pub case: Option<Box<Expression>>,
13425}
13426
13427/// Compress
13428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13429#[cfg_attr(feature = "bindings", derive(TS))]
13430pub struct Compress {
13431    pub this: Box<Expression>,
13432    #[serde(default)]
13433    pub method: Option<String>,
13434}
13435
13436/// DecompressBinary
13437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13438#[cfg_attr(feature = "bindings", derive(TS))]
13439pub struct DecompressBinary {
13440    pub this: Box<Expression>,
13441    pub method: String,
13442}
13443
13444/// DecompressString
13445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13446#[cfg_attr(feature = "bindings", derive(TS))]
13447pub struct DecompressString {
13448    pub this: Box<Expression>,
13449    pub method: String,
13450}
13451
13452/// Xor
13453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13454#[cfg_attr(feature = "bindings", derive(TS))]
13455pub struct Xor {
13456    #[serde(default)]
13457    pub this: Option<Box<Expression>>,
13458    #[serde(default)]
13459    pub expression: Option<Box<Expression>>,
13460    #[serde(default)]
13461    pub expressions: Vec<Expression>,
13462}
13463
13464/// Nullif
13465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13466#[cfg_attr(feature = "bindings", derive(TS))]
13467pub struct Nullif {
13468    pub this: Box<Expression>,
13469    pub expression: Box<Expression>,
13470}
13471
13472/// JSON
13473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13474#[cfg_attr(feature = "bindings", derive(TS))]
13475pub struct JSON {
13476    #[serde(default)]
13477    pub this: Option<Box<Expression>>,
13478    #[serde(default)]
13479    pub with_: Option<Box<Expression>>,
13480    #[serde(default)]
13481    pub unique: bool,
13482}
13483
13484/// JSONPath
13485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13486#[cfg_attr(feature = "bindings", derive(TS))]
13487pub struct JSONPath {
13488    #[serde(default)]
13489    pub expressions: Vec<Expression>,
13490    #[serde(default)]
13491    pub escape: Option<Box<Expression>>,
13492}
13493
13494/// JSONPathFilter
13495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13496#[cfg_attr(feature = "bindings", derive(TS))]
13497pub struct JSONPathFilter {
13498    pub this: Box<Expression>,
13499}
13500
13501/// JSONPathKey
13502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13503#[cfg_attr(feature = "bindings", derive(TS))]
13504pub struct JSONPathKey {
13505    pub this: Box<Expression>,
13506}
13507
13508/// JSONPathRecursive
13509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13510#[cfg_attr(feature = "bindings", derive(TS))]
13511pub struct JSONPathRecursive {
13512    #[serde(default)]
13513    pub this: Option<Box<Expression>>,
13514}
13515
13516/// JSONPathScript
13517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13518#[cfg_attr(feature = "bindings", derive(TS))]
13519pub struct JSONPathScript {
13520    pub this: Box<Expression>,
13521}
13522
13523/// JSONPathSlice
13524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13525#[cfg_attr(feature = "bindings", derive(TS))]
13526pub struct JSONPathSlice {
13527    #[serde(default)]
13528    pub start: Option<Box<Expression>>,
13529    #[serde(default)]
13530    pub end: Option<Box<Expression>>,
13531    #[serde(default)]
13532    pub step: Option<Box<Expression>>,
13533}
13534
13535/// JSONPathSelector
13536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13537#[cfg_attr(feature = "bindings", derive(TS))]
13538pub struct JSONPathSelector {
13539    pub this: Box<Expression>,
13540}
13541
13542/// JSONPathSubscript
13543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13544#[cfg_attr(feature = "bindings", derive(TS))]
13545pub struct JSONPathSubscript {
13546    pub this: Box<Expression>,
13547}
13548
13549/// JSONPathUnion
13550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13551#[cfg_attr(feature = "bindings", derive(TS))]
13552pub struct JSONPathUnion {
13553    #[serde(default)]
13554    pub expressions: Vec<Expression>,
13555}
13556
13557/// Format
13558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13559#[cfg_attr(feature = "bindings", derive(TS))]
13560pub struct Format {
13561    pub this: Box<Expression>,
13562    #[serde(default)]
13563    pub expressions: Vec<Expression>,
13564}
13565
13566/// JSONKeys
13567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13568#[cfg_attr(feature = "bindings", derive(TS))]
13569pub struct JSONKeys {
13570    pub this: Box<Expression>,
13571    #[serde(default)]
13572    pub expression: Option<Box<Expression>>,
13573    #[serde(default)]
13574    pub expressions: Vec<Expression>,
13575}
13576
13577/// JSONKeyValue
13578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13579#[cfg_attr(feature = "bindings", derive(TS))]
13580pub struct JSONKeyValue {
13581    pub this: Box<Expression>,
13582    pub expression: Box<Expression>,
13583}
13584
13585/// JSONKeysAtDepth
13586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13587#[cfg_attr(feature = "bindings", derive(TS))]
13588pub struct JSONKeysAtDepth {
13589    pub this: Box<Expression>,
13590    #[serde(default)]
13591    pub expression: Option<Box<Expression>>,
13592    #[serde(default)]
13593    pub mode: Option<Box<Expression>>,
13594}
13595
13596/// JSONObject
13597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13598#[cfg_attr(feature = "bindings", derive(TS))]
13599pub struct JSONObject {
13600    #[serde(default)]
13601    pub expressions: Vec<Expression>,
13602    #[serde(default)]
13603    pub null_handling: Option<Box<Expression>>,
13604    #[serde(default)]
13605    pub unique_keys: Option<Box<Expression>>,
13606    #[serde(default)]
13607    pub return_type: Option<Box<Expression>>,
13608    #[serde(default)]
13609    pub encoding: Option<Box<Expression>>,
13610}
13611
13612/// JSONObjectAgg
13613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13614#[cfg_attr(feature = "bindings", derive(TS))]
13615pub struct JSONObjectAgg {
13616    #[serde(default)]
13617    pub expressions: Vec<Expression>,
13618    #[serde(default)]
13619    pub null_handling: Option<Box<Expression>>,
13620    #[serde(default)]
13621    pub unique_keys: Option<Box<Expression>>,
13622    #[serde(default)]
13623    pub return_type: Option<Box<Expression>>,
13624    #[serde(default)]
13625    pub encoding: Option<Box<Expression>>,
13626}
13627
13628/// JSONBObjectAgg
13629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13630#[cfg_attr(feature = "bindings", derive(TS))]
13631pub struct JSONBObjectAgg {
13632    pub this: Box<Expression>,
13633    pub expression: Box<Expression>,
13634}
13635
13636/// JSONArray
13637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13638#[cfg_attr(feature = "bindings", derive(TS))]
13639pub struct JSONArray {
13640    #[serde(default)]
13641    pub expressions: Vec<Expression>,
13642    #[serde(default)]
13643    pub null_handling: Option<Box<Expression>>,
13644    #[serde(default)]
13645    pub return_type: Option<Box<Expression>>,
13646    #[serde(default)]
13647    pub strict: Option<Box<Expression>>,
13648}
13649
13650/// JSONArrayAgg
13651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13652#[cfg_attr(feature = "bindings", derive(TS))]
13653pub struct JSONArrayAgg {
13654    pub this: Box<Expression>,
13655    #[serde(default)]
13656    pub order: Option<Box<Expression>>,
13657    #[serde(default)]
13658    pub null_handling: Option<Box<Expression>>,
13659    #[serde(default)]
13660    pub return_type: Option<Box<Expression>>,
13661    #[serde(default)]
13662    pub strict: Option<Box<Expression>>,
13663}
13664
13665/// JSONExists
13666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13667#[cfg_attr(feature = "bindings", derive(TS))]
13668pub struct JSONExists {
13669    pub this: Box<Expression>,
13670    #[serde(default)]
13671    pub path: Option<Box<Expression>>,
13672    #[serde(default)]
13673    pub passing: Option<Box<Expression>>,
13674    #[serde(default)]
13675    pub on_condition: Option<Box<Expression>>,
13676    #[serde(default)]
13677    pub from_dcolonqmark: Option<Box<Expression>>,
13678}
13679
13680/// JSONColumnDef
13681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13682#[cfg_attr(feature = "bindings", derive(TS))]
13683pub struct JSONColumnDef {
13684    #[serde(default)]
13685    pub this: Option<Box<Expression>>,
13686    #[serde(default)]
13687    pub kind: Option<String>,
13688    #[serde(default)]
13689    pub format_json: bool,
13690    #[serde(default)]
13691    pub path: Option<Box<Expression>>,
13692    #[serde(default)]
13693    pub nested_schema: Option<Box<Expression>>,
13694    #[serde(default)]
13695    pub ordinality: Option<Box<Expression>>,
13696}
13697
13698/// JSONSchema
13699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13700#[cfg_attr(feature = "bindings", derive(TS))]
13701pub struct JSONSchema {
13702    #[serde(default)]
13703    pub expressions: Vec<Expression>,
13704}
13705
13706/// JSONSet
13707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13708#[cfg_attr(feature = "bindings", derive(TS))]
13709pub struct JSONSet {
13710    pub this: Box<Expression>,
13711    #[serde(default)]
13712    pub expressions: Vec<Expression>,
13713}
13714
13715/// JSONStripNulls
13716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13717#[cfg_attr(feature = "bindings", derive(TS))]
13718pub struct JSONStripNulls {
13719    pub this: Box<Expression>,
13720    #[serde(default)]
13721    pub expression: Option<Box<Expression>>,
13722    #[serde(default)]
13723    pub include_arrays: Option<Box<Expression>>,
13724    #[serde(default)]
13725    pub remove_empty: Option<Box<Expression>>,
13726}
13727
13728/// JSONValue
13729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13730#[cfg_attr(feature = "bindings", derive(TS))]
13731pub struct JSONValue {
13732    pub this: Box<Expression>,
13733    #[serde(default)]
13734    pub path: Option<Box<Expression>>,
13735    #[serde(default)]
13736    pub returning: Option<Box<Expression>>,
13737    #[serde(default)]
13738    pub on_condition: Option<Box<Expression>>,
13739}
13740
13741/// JSONValueArray
13742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13743#[cfg_attr(feature = "bindings", derive(TS))]
13744pub struct JSONValueArray {
13745    pub this: Box<Expression>,
13746    #[serde(default)]
13747    pub expression: Option<Box<Expression>>,
13748}
13749
13750/// JSONRemove
13751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13752#[cfg_attr(feature = "bindings", derive(TS))]
13753pub struct JSONRemove {
13754    pub this: Box<Expression>,
13755    #[serde(default)]
13756    pub expressions: Vec<Expression>,
13757}
13758
13759/// JSONTable
13760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13761#[cfg_attr(feature = "bindings", derive(TS))]
13762pub struct JSONTable {
13763    pub this: Box<Expression>,
13764    #[serde(default)]
13765    pub schema: Option<Box<Expression>>,
13766    #[serde(default)]
13767    pub path: Option<Box<Expression>>,
13768    #[serde(default)]
13769    pub error_handling: Option<Box<Expression>>,
13770    #[serde(default)]
13771    pub empty_handling: Option<Box<Expression>>,
13772}
13773
13774/// JSONType
13775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13776#[cfg_attr(feature = "bindings", derive(TS))]
13777pub struct JSONType {
13778    pub this: Box<Expression>,
13779    #[serde(default)]
13780    pub expression: Option<Box<Expression>>,
13781}
13782
13783/// ObjectInsert
13784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13785#[cfg_attr(feature = "bindings", derive(TS))]
13786pub struct ObjectInsert {
13787    pub this: Box<Expression>,
13788    #[serde(default)]
13789    pub key: Option<Box<Expression>>,
13790    #[serde(default)]
13791    pub value: Option<Box<Expression>>,
13792    #[serde(default)]
13793    pub update_flag: Option<Box<Expression>>,
13794}
13795
13796/// OpenJSONColumnDef
13797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13798#[cfg_attr(feature = "bindings", derive(TS))]
13799pub struct OpenJSONColumnDef {
13800    pub this: Box<Expression>,
13801    pub kind: String,
13802    #[serde(default)]
13803    pub path: Option<Box<Expression>>,
13804    #[serde(default)]
13805    pub as_json: Option<Box<Expression>>,
13806    /// The parsed data type for proper generation
13807    #[serde(default, skip_serializing_if = "Option::is_none")]
13808    pub data_type: Option<DataType>,
13809}
13810
13811/// OpenJSON
13812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13813#[cfg_attr(feature = "bindings", derive(TS))]
13814pub struct OpenJSON {
13815    pub this: Box<Expression>,
13816    #[serde(default)]
13817    pub path: Option<Box<Expression>>,
13818    #[serde(default)]
13819    pub expressions: Vec<Expression>,
13820}
13821
13822/// JSONBExists
13823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13824#[cfg_attr(feature = "bindings", derive(TS))]
13825pub struct JSONBExists {
13826    pub this: Box<Expression>,
13827    #[serde(default)]
13828    pub path: Option<Box<Expression>>,
13829}
13830
13831/// JSONCast
13832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13833#[cfg_attr(feature = "bindings", derive(TS))]
13834pub struct JSONCast {
13835    pub this: Box<Expression>,
13836    pub to: DataType,
13837}
13838
13839/// JSONExtract
13840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13841#[cfg_attr(feature = "bindings", derive(TS))]
13842pub struct JSONExtract {
13843    pub this: Box<Expression>,
13844    pub expression: Box<Expression>,
13845    #[serde(default)]
13846    pub only_json_types: Option<Box<Expression>>,
13847    #[serde(default)]
13848    pub expressions: Vec<Expression>,
13849    #[serde(default)]
13850    pub variant_extract: Option<Box<Expression>>,
13851    #[serde(default)]
13852    pub json_query: Option<Box<Expression>>,
13853    #[serde(default)]
13854    pub option: Option<Box<Expression>>,
13855    #[serde(default)]
13856    pub quote: Option<Box<Expression>>,
13857    #[serde(default)]
13858    pub on_condition: Option<Box<Expression>>,
13859    #[serde(default)]
13860    pub requires_json: Option<Box<Expression>>,
13861}
13862
13863/// JSONExtractQuote
13864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13865#[cfg_attr(feature = "bindings", derive(TS))]
13866pub struct JSONExtractQuote {
13867    #[serde(default)]
13868    pub option: Option<Box<Expression>>,
13869    #[serde(default)]
13870    pub scalar: Option<Box<Expression>>,
13871}
13872
13873/// JSONExtractArray
13874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13875#[cfg_attr(feature = "bindings", derive(TS))]
13876pub struct JSONExtractArray {
13877    pub this: Box<Expression>,
13878    #[serde(default)]
13879    pub expression: Option<Box<Expression>>,
13880}
13881
13882/// JSONExtractScalar
13883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13884#[cfg_attr(feature = "bindings", derive(TS))]
13885pub struct JSONExtractScalar {
13886    pub this: Box<Expression>,
13887    pub expression: Box<Expression>,
13888    #[serde(default)]
13889    pub only_json_types: Option<Box<Expression>>,
13890    #[serde(default)]
13891    pub expressions: Vec<Expression>,
13892    #[serde(default)]
13893    pub json_type: Option<Box<Expression>>,
13894    #[serde(default)]
13895    pub scalar_only: Option<Box<Expression>>,
13896}
13897
13898/// JSONBExtractScalar
13899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13900#[cfg_attr(feature = "bindings", derive(TS))]
13901pub struct JSONBExtractScalar {
13902    pub this: Box<Expression>,
13903    pub expression: Box<Expression>,
13904    #[serde(default)]
13905    pub json_type: Option<Box<Expression>>,
13906}
13907
13908/// JSONFormat
13909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13910#[cfg_attr(feature = "bindings", derive(TS))]
13911pub struct JSONFormat {
13912    #[serde(default)]
13913    pub this: Option<Box<Expression>>,
13914    #[serde(default)]
13915    pub options: Vec<Expression>,
13916    #[serde(default)]
13917    pub is_json: Option<Box<Expression>>,
13918    #[serde(default)]
13919    pub to_json: Option<Box<Expression>>,
13920}
13921
13922/// JSONArrayAppend
13923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13924#[cfg_attr(feature = "bindings", derive(TS))]
13925pub struct JSONArrayAppend {
13926    pub this: Box<Expression>,
13927    #[serde(default)]
13928    pub expressions: Vec<Expression>,
13929}
13930
13931/// JSONArrayContains
13932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13933#[cfg_attr(feature = "bindings", derive(TS))]
13934pub struct JSONArrayContains {
13935    pub this: Box<Expression>,
13936    pub expression: Box<Expression>,
13937    #[serde(default)]
13938    pub json_type: Option<Box<Expression>>,
13939}
13940
13941/// JSONArrayInsert
13942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13943#[cfg_attr(feature = "bindings", derive(TS))]
13944pub struct JSONArrayInsert {
13945    pub this: Box<Expression>,
13946    #[serde(default)]
13947    pub expressions: Vec<Expression>,
13948}
13949
13950/// ParseJSON
13951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13952#[cfg_attr(feature = "bindings", derive(TS))]
13953pub struct ParseJSON {
13954    pub this: Box<Expression>,
13955    #[serde(default)]
13956    pub expression: Option<Box<Expression>>,
13957    #[serde(default)]
13958    pub safe: Option<Box<Expression>>,
13959}
13960
13961/// ParseUrl
13962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13963#[cfg_attr(feature = "bindings", derive(TS))]
13964pub struct ParseUrl {
13965    pub this: Box<Expression>,
13966    #[serde(default)]
13967    pub part_to_extract: Option<Box<Expression>>,
13968    #[serde(default)]
13969    pub key: Option<Box<Expression>>,
13970    #[serde(default)]
13971    pub permissive: Option<Box<Expression>>,
13972}
13973
13974/// ParseIp
13975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13976#[cfg_attr(feature = "bindings", derive(TS))]
13977pub struct ParseIp {
13978    pub this: Box<Expression>,
13979    #[serde(default)]
13980    pub type_: Option<Box<Expression>>,
13981    #[serde(default)]
13982    pub permissive: Option<Box<Expression>>,
13983}
13984
13985/// ParseTime
13986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13987#[cfg_attr(feature = "bindings", derive(TS))]
13988pub struct ParseTime {
13989    pub this: Box<Expression>,
13990    pub format: String,
13991}
13992
13993/// ParseDatetime
13994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13995#[cfg_attr(feature = "bindings", derive(TS))]
13996pub struct ParseDatetime {
13997    pub this: Box<Expression>,
13998    #[serde(default)]
13999    pub format: Option<String>,
14000    #[serde(default)]
14001    pub zone: Option<Box<Expression>>,
14002}
14003
14004/// Map
14005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14006#[cfg_attr(feature = "bindings", derive(TS))]
14007pub struct Map {
14008    #[serde(default)]
14009    pub keys: Vec<Expression>,
14010    #[serde(default)]
14011    pub values: Vec<Expression>,
14012}
14013
14014/// MapCat
14015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14016#[cfg_attr(feature = "bindings", derive(TS))]
14017pub struct MapCat {
14018    pub this: Box<Expression>,
14019    pub expression: Box<Expression>,
14020}
14021
14022/// MapDelete
14023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14024#[cfg_attr(feature = "bindings", derive(TS))]
14025pub struct MapDelete {
14026    pub this: Box<Expression>,
14027    #[serde(default)]
14028    pub expressions: Vec<Expression>,
14029}
14030
14031/// MapInsert
14032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14033#[cfg_attr(feature = "bindings", derive(TS))]
14034pub struct MapInsert {
14035    pub this: Box<Expression>,
14036    #[serde(default)]
14037    pub key: Option<Box<Expression>>,
14038    #[serde(default)]
14039    pub value: Option<Box<Expression>>,
14040    #[serde(default)]
14041    pub update_flag: Option<Box<Expression>>,
14042}
14043
14044/// MapPick
14045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14046#[cfg_attr(feature = "bindings", derive(TS))]
14047pub struct MapPick {
14048    pub this: Box<Expression>,
14049    #[serde(default)]
14050    pub expressions: Vec<Expression>,
14051}
14052
14053/// ScopeResolution
14054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14055#[cfg_attr(feature = "bindings", derive(TS))]
14056pub struct ScopeResolution {
14057    #[serde(default)]
14058    pub this: Option<Box<Expression>>,
14059    pub expression: Box<Expression>,
14060}
14061
14062/// Slice
14063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14064#[cfg_attr(feature = "bindings", derive(TS))]
14065pub struct Slice {
14066    #[serde(default)]
14067    pub this: Option<Box<Expression>>,
14068    #[serde(default)]
14069    pub expression: Option<Box<Expression>>,
14070    #[serde(default)]
14071    pub step: Option<Box<Expression>>,
14072}
14073
14074/// VarMap
14075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14076#[cfg_attr(feature = "bindings", derive(TS))]
14077pub struct VarMap {
14078    #[serde(default)]
14079    pub keys: Vec<Expression>,
14080    #[serde(default)]
14081    pub values: Vec<Expression>,
14082}
14083
14084/// MatchAgainst
14085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14086#[cfg_attr(feature = "bindings", derive(TS))]
14087pub struct MatchAgainst {
14088    pub this: Box<Expression>,
14089    #[serde(default)]
14090    pub expressions: Vec<Expression>,
14091    #[serde(default)]
14092    pub modifier: Option<Box<Expression>>,
14093}
14094
14095/// MD5Digest
14096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14097#[cfg_attr(feature = "bindings", derive(TS))]
14098pub struct MD5Digest {
14099    pub this: Box<Expression>,
14100    #[serde(default)]
14101    pub expressions: Vec<Expression>,
14102}
14103
14104/// Monthname
14105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14106#[cfg_attr(feature = "bindings", derive(TS))]
14107pub struct Monthname {
14108    pub this: Box<Expression>,
14109    #[serde(default)]
14110    pub abbreviated: Option<Box<Expression>>,
14111}
14112
14113/// Ntile
14114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14115#[cfg_attr(feature = "bindings", derive(TS))]
14116pub struct Ntile {
14117    #[serde(default)]
14118    pub this: Option<Box<Expression>>,
14119}
14120
14121/// Normalize
14122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14123#[cfg_attr(feature = "bindings", derive(TS))]
14124pub struct Normalize {
14125    pub this: Box<Expression>,
14126    #[serde(default)]
14127    pub form: Option<Box<Expression>>,
14128    #[serde(default)]
14129    pub is_casefold: Option<Box<Expression>>,
14130}
14131
14132/// Normal
14133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14134#[cfg_attr(feature = "bindings", derive(TS))]
14135pub struct Normal {
14136    pub this: Box<Expression>,
14137    #[serde(default)]
14138    pub stddev: Option<Box<Expression>>,
14139    #[serde(default)]
14140    pub gen: Option<Box<Expression>>,
14141}
14142
14143/// Predict
14144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14145#[cfg_attr(feature = "bindings", derive(TS))]
14146pub struct Predict {
14147    pub this: Box<Expression>,
14148    pub expression: Box<Expression>,
14149    #[serde(default)]
14150    pub params_struct: Option<Box<Expression>>,
14151}
14152
14153/// MLTranslate
14154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14155#[cfg_attr(feature = "bindings", derive(TS))]
14156pub struct MLTranslate {
14157    pub this: Box<Expression>,
14158    pub expression: Box<Expression>,
14159    #[serde(default)]
14160    pub params_struct: Option<Box<Expression>>,
14161}
14162
14163/// FeaturesAtTime
14164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14165#[cfg_attr(feature = "bindings", derive(TS))]
14166pub struct FeaturesAtTime {
14167    pub this: Box<Expression>,
14168    #[serde(default)]
14169    pub time: Option<Box<Expression>>,
14170    #[serde(default)]
14171    pub num_rows: Option<Box<Expression>>,
14172    #[serde(default)]
14173    pub ignore_feature_nulls: Option<Box<Expression>>,
14174}
14175
14176/// GenerateEmbedding
14177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14178#[cfg_attr(feature = "bindings", derive(TS))]
14179pub struct GenerateEmbedding {
14180    pub this: Box<Expression>,
14181    pub expression: Box<Expression>,
14182    #[serde(default)]
14183    pub params_struct: Option<Box<Expression>>,
14184    #[serde(default)]
14185    pub is_text: Option<Box<Expression>>,
14186}
14187
14188/// MLForecast
14189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14190#[cfg_attr(feature = "bindings", derive(TS))]
14191pub struct MLForecast {
14192    pub this: Box<Expression>,
14193    #[serde(default)]
14194    pub expression: Option<Box<Expression>>,
14195    #[serde(default)]
14196    pub params_struct: Option<Box<Expression>>,
14197}
14198
14199/// ModelAttribute
14200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14201#[cfg_attr(feature = "bindings", derive(TS))]
14202pub struct ModelAttribute {
14203    pub this: Box<Expression>,
14204    pub expression: Box<Expression>,
14205}
14206
14207/// VectorSearch
14208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14209#[cfg_attr(feature = "bindings", derive(TS))]
14210pub struct VectorSearch {
14211    pub this: Box<Expression>,
14212    #[serde(default)]
14213    pub column_to_search: Option<Box<Expression>>,
14214    #[serde(default)]
14215    pub query_table: Option<Box<Expression>>,
14216    #[serde(default)]
14217    pub query_column_to_search: Option<Box<Expression>>,
14218    #[serde(default)]
14219    pub top_k: Option<Box<Expression>>,
14220    #[serde(default)]
14221    pub distance_type: Option<Box<Expression>>,
14222    #[serde(default)]
14223    pub options: Vec<Expression>,
14224}
14225
14226/// Quantile
14227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14228#[cfg_attr(feature = "bindings", derive(TS))]
14229pub struct Quantile {
14230    pub this: Box<Expression>,
14231    #[serde(default)]
14232    pub quantile: Option<Box<Expression>>,
14233}
14234
14235/// ApproxQuantile
14236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14237#[cfg_attr(feature = "bindings", derive(TS))]
14238pub struct ApproxQuantile {
14239    pub this: Box<Expression>,
14240    #[serde(default)]
14241    pub quantile: Option<Box<Expression>>,
14242    #[serde(default)]
14243    pub accuracy: Option<Box<Expression>>,
14244    #[serde(default)]
14245    pub weight: Option<Box<Expression>>,
14246    #[serde(default)]
14247    pub error_tolerance: Option<Box<Expression>>,
14248}
14249
14250/// ApproxPercentileEstimate
14251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14252#[cfg_attr(feature = "bindings", derive(TS))]
14253pub struct ApproxPercentileEstimate {
14254    pub this: Box<Expression>,
14255    #[serde(default)]
14256    pub percentile: Option<Box<Expression>>,
14257}
14258
14259/// Randn
14260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14261#[cfg_attr(feature = "bindings", derive(TS))]
14262pub struct Randn {
14263    #[serde(default)]
14264    pub this: Option<Box<Expression>>,
14265}
14266
14267/// Randstr
14268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14269#[cfg_attr(feature = "bindings", derive(TS))]
14270pub struct Randstr {
14271    pub this: Box<Expression>,
14272    #[serde(default)]
14273    pub generator: Option<Box<Expression>>,
14274}
14275
14276/// RangeN
14277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14278#[cfg_attr(feature = "bindings", derive(TS))]
14279pub struct RangeN {
14280    pub this: Box<Expression>,
14281    #[serde(default)]
14282    pub expressions: Vec<Expression>,
14283    #[serde(default)]
14284    pub each: Option<Box<Expression>>,
14285}
14286
14287/// RangeBucket
14288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14289#[cfg_attr(feature = "bindings", derive(TS))]
14290pub struct RangeBucket {
14291    pub this: Box<Expression>,
14292    pub expression: Box<Expression>,
14293}
14294
14295/// ReadCSV
14296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14297#[cfg_attr(feature = "bindings", derive(TS))]
14298pub struct ReadCSV {
14299    pub this: Box<Expression>,
14300    #[serde(default)]
14301    pub expressions: Vec<Expression>,
14302}
14303
14304/// ReadParquet
14305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14306#[cfg_attr(feature = "bindings", derive(TS))]
14307pub struct ReadParquet {
14308    #[serde(default)]
14309    pub expressions: Vec<Expression>,
14310}
14311
14312/// Reduce
14313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14314#[cfg_attr(feature = "bindings", derive(TS))]
14315pub struct Reduce {
14316    pub this: Box<Expression>,
14317    #[serde(default)]
14318    pub initial: Option<Box<Expression>>,
14319    #[serde(default)]
14320    pub merge: Option<Box<Expression>>,
14321    #[serde(default)]
14322    pub finish: Option<Box<Expression>>,
14323}
14324
14325/// RegexpExtractAll
14326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14327#[cfg_attr(feature = "bindings", derive(TS))]
14328pub struct RegexpExtractAll {
14329    pub this: Box<Expression>,
14330    pub expression: Box<Expression>,
14331    #[serde(default)]
14332    pub group: Option<Box<Expression>>,
14333    #[serde(default)]
14334    pub parameters: Option<Box<Expression>>,
14335    #[serde(default)]
14336    pub position: Option<Box<Expression>>,
14337    #[serde(default)]
14338    pub occurrence: Option<Box<Expression>>,
14339}
14340
14341/// RegexpILike
14342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14343#[cfg_attr(feature = "bindings", derive(TS))]
14344pub struct RegexpILike {
14345    pub this: Box<Expression>,
14346    pub expression: Box<Expression>,
14347    #[serde(default)]
14348    pub flag: Option<Box<Expression>>,
14349}
14350
14351/// RegexpFullMatch
14352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14353#[cfg_attr(feature = "bindings", derive(TS))]
14354pub struct RegexpFullMatch {
14355    pub this: Box<Expression>,
14356    pub expression: Box<Expression>,
14357    #[serde(default)]
14358    pub options: Vec<Expression>,
14359}
14360
14361/// RegexpInstr
14362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14363#[cfg_attr(feature = "bindings", derive(TS))]
14364pub struct RegexpInstr {
14365    pub this: Box<Expression>,
14366    pub expression: Box<Expression>,
14367    #[serde(default)]
14368    pub position: Option<Box<Expression>>,
14369    #[serde(default)]
14370    pub occurrence: Option<Box<Expression>>,
14371    #[serde(default)]
14372    pub option: Option<Box<Expression>>,
14373    #[serde(default)]
14374    pub parameters: Option<Box<Expression>>,
14375    #[serde(default)]
14376    pub group: Option<Box<Expression>>,
14377}
14378
14379/// RegexpSplit
14380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14381#[cfg_attr(feature = "bindings", derive(TS))]
14382pub struct RegexpSplit {
14383    pub this: Box<Expression>,
14384    pub expression: Box<Expression>,
14385    #[serde(default)]
14386    pub limit: Option<Box<Expression>>,
14387}
14388
14389/// RegexpCount
14390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14391#[cfg_attr(feature = "bindings", derive(TS))]
14392pub struct RegexpCount {
14393    pub this: Box<Expression>,
14394    pub expression: Box<Expression>,
14395    #[serde(default)]
14396    pub position: Option<Box<Expression>>,
14397    #[serde(default)]
14398    pub parameters: Option<Box<Expression>>,
14399}
14400
14401/// RegrValx
14402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14403#[cfg_attr(feature = "bindings", derive(TS))]
14404pub struct RegrValx {
14405    pub this: Box<Expression>,
14406    pub expression: Box<Expression>,
14407}
14408
14409/// RegrValy
14410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14411#[cfg_attr(feature = "bindings", derive(TS))]
14412pub struct RegrValy {
14413    pub this: Box<Expression>,
14414    pub expression: Box<Expression>,
14415}
14416
14417/// RegrAvgy
14418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14419#[cfg_attr(feature = "bindings", derive(TS))]
14420pub struct RegrAvgy {
14421    pub this: Box<Expression>,
14422    pub expression: Box<Expression>,
14423}
14424
14425/// RegrAvgx
14426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14427#[cfg_attr(feature = "bindings", derive(TS))]
14428pub struct RegrAvgx {
14429    pub this: Box<Expression>,
14430    pub expression: Box<Expression>,
14431}
14432
14433/// RegrCount
14434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14435#[cfg_attr(feature = "bindings", derive(TS))]
14436pub struct RegrCount {
14437    pub this: Box<Expression>,
14438    pub expression: Box<Expression>,
14439}
14440
14441/// RegrIntercept
14442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14443#[cfg_attr(feature = "bindings", derive(TS))]
14444pub struct RegrIntercept {
14445    pub this: Box<Expression>,
14446    pub expression: Box<Expression>,
14447}
14448
14449/// RegrR2
14450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14451#[cfg_attr(feature = "bindings", derive(TS))]
14452pub struct RegrR2 {
14453    pub this: Box<Expression>,
14454    pub expression: Box<Expression>,
14455}
14456
14457/// RegrSxx
14458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14459#[cfg_attr(feature = "bindings", derive(TS))]
14460pub struct RegrSxx {
14461    pub this: Box<Expression>,
14462    pub expression: Box<Expression>,
14463}
14464
14465/// RegrSxy
14466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14467#[cfg_attr(feature = "bindings", derive(TS))]
14468pub struct RegrSxy {
14469    pub this: Box<Expression>,
14470    pub expression: Box<Expression>,
14471}
14472
14473/// RegrSyy
14474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14475#[cfg_attr(feature = "bindings", derive(TS))]
14476pub struct RegrSyy {
14477    pub this: Box<Expression>,
14478    pub expression: Box<Expression>,
14479}
14480
14481/// RegrSlope
14482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14483#[cfg_attr(feature = "bindings", derive(TS))]
14484pub struct RegrSlope {
14485    pub this: Box<Expression>,
14486    pub expression: Box<Expression>,
14487}
14488
14489/// SafeAdd
14490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14491#[cfg_attr(feature = "bindings", derive(TS))]
14492pub struct SafeAdd {
14493    pub this: Box<Expression>,
14494    pub expression: Box<Expression>,
14495}
14496
14497/// SafeDivide
14498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14499#[cfg_attr(feature = "bindings", derive(TS))]
14500pub struct SafeDivide {
14501    pub this: Box<Expression>,
14502    pub expression: Box<Expression>,
14503}
14504
14505/// SafeMultiply
14506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14507#[cfg_attr(feature = "bindings", derive(TS))]
14508pub struct SafeMultiply {
14509    pub this: Box<Expression>,
14510    pub expression: Box<Expression>,
14511}
14512
14513/// SafeSubtract
14514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14515#[cfg_attr(feature = "bindings", derive(TS))]
14516pub struct SafeSubtract {
14517    pub this: Box<Expression>,
14518    pub expression: Box<Expression>,
14519}
14520
14521/// SHA2
14522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14523#[cfg_attr(feature = "bindings", derive(TS))]
14524pub struct SHA2 {
14525    pub this: Box<Expression>,
14526    #[serde(default)]
14527    pub length: Option<i64>,
14528}
14529
14530/// SHA2Digest
14531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14532#[cfg_attr(feature = "bindings", derive(TS))]
14533pub struct SHA2Digest {
14534    pub this: Box<Expression>,
14535    #[serde(default)]
14536    pub length: Option<i64>,
14537}
14538
14539/// SortArray
14540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14541#[cfg_attr(feature = "bindings", derive(TS))]
14542pub struct SortArray {
14543    pub this: Box<Expression>,
14544    #[serde(default)]
14545    pub asc: Option<Box<Expression>>,
14546    #[serde(default)]
14547    pub nulls_first: Option<Box<Expression>>,
14548}
14549
14550/// SplitPart
14551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14552#[cfg_attr(feature = "bindings", derive(TS))]
14553pub struct SplitPart {
14554    pub this: Box<Expression>,
14555    #[serde(default)]
14556    pub delimiter: Option<Box<Expression>>,
14557    #[serde(default)]
14558    pub part_index: Option<Box<Expression>>,
14559}
14560
14561/// SUBSTRING_INDEX(str, delim, count)
14562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14563#[cfg_attr(feature = "bindings", derive(TS))]
14564pub struct SubstringIndex {
14565    pub this: Box<Expression>,
14566    #[serde(default)]
14567    pub delimiter: Option<Box<Expression>>,
14568    #[serde(default)]
14569    pub count: Option<Box<Expression>>,
14570}
14571
14572/// StandardHash
14573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14574#[cfg_attr(feature = "bindings", derive(TS))]
14575pub struct StandardHash {
14576    pub this: Box<Expression>,
14577    #[serde(default)]
14578    pub expression: Option<Box<Expression>>,
14579}
14580
14581/// StrPosition
14582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14583#[cfg_attr(feature = "bindings", derive(TS))]
14584pub struct StrPosition {
14585    pub this: Box<Expression>,
14586    #[serde(default)]
14587    pub substr: Option<Box<Expression>>,
14588    #[serde(default)]
14589    pub position: Option<Box<Expression>>,
14590    #[serde(default)]
14591    pub occurrence: Option<Box<Expression>>,
14592}
14593
14594/// Search
14595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14596#[cfg_attr(feature = "bindings", derive(TS))]
14597pub struct Search {
14598    pub this: Box<Expression>,
14599    pub expression: Box<Expression>,
14600    #[serde(default)]
14601    pub json_scope: Option<Box<Expression>>,
14602    #[serde(default)]
14603    pub analyzer: Option<Box<Expression>>,
14604    #[serde(default)]
14605    pub analyzer_options: Option<Box<Expression>>,
14606    #[serde(default)]
14607    pub search_mode: Option<Box<Expression>>,
14608}
14609
14610/// SearchIp
14611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14612#[cfg_attr(feature = "bindings", derive(TS))]
14613pub struct SearchIp {
14614    pub this: Box<Expression>,
14615    pub expression: Box<Expression>,
14616}
14617
14618/// StrToDate
14619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14620#[cfg_attr(feature = "bindings", derive(TS))]
14621pub struct StrToDate {
14622    pub this: Box<Expression>,
14623    #[serde(default)]
14624    pub format: Option<String>,
14625    #[serde(default)]
14626    pub safe: Option<Box<Expression>>,
14627}
14628
14629/// StrToTime
14630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14631#[cfg_attr(feature = "bindings", derive(TS))]
14632pub struct StrToTime {
14633    pub this: Box<Expression>,
14634    pub format: String,
14635    #[serde(default)]
14636    pub zone: Option<Box<Expression>>,
14637    #[serde(default)]
14638    pub safe: Option<Box<Expression>>,
14639    #[serde(default)]
14640    pub target_type: Option<Box<Expression>>,
14641}
14642
14643/// StrToUnix
14644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14645#[cfg_attr(feature = "bindings", derive(TS))]
14646pub struct StrToUnix {
14647    #[serde(default)]
14648    pub this: Option<Box<Expression>>,
14649    #[serde(default)]
14650    pub format: Option<String>,
14651}
14652
14653/// StrToMap
14654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14655#[cfg_attr(feature = "bindings", derive(TS))]
14656pub struct StrToMap {
14657    pub this: Box<Expression>,
14658    #[serde(default)]
14659    pub pair_delim: Option<Box<Expression>>,
14660    #[serde(default)]
14661    pub key_value_delim: Option<Box<Expression>>,
14662    #[serde(default)]
14663    pub duplicate_resolution_callback: Option<Box<Expression>>,
14664}
14665
14666/// NumberToStr
14667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14668#[cfg_attr(feature = "bindings", derive(TS))]
14669pub struct NumberToStr {
14670    pub this: Box<Expression>,
14671    pub format: String,
14672    #[serde(default)]
14673    pub culture: Option<Box<Expression>>,
14674}
14675
14676/// FromBase
14677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14678#[cfg_attr(feature = "bindings", derive(TS))]
14679pub struct FromBase {
14680    pub this: Box<Expression>,
14681    pub expression: Box<Expression>,
14682}
14683
14684/// Stuff
14685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14686#[cfg_attr(feature = "bindings", derive(TS))]
14687pub struct Stuff {
14688    pub this: Box<Expression>,
14689    #[serde(default)]
14690    pub start: Option<Box<Expression>>,
14691    #[serde(default)]
14692    pub length: Option<i64>,
14693    pub expression: Box<Expression>,
14694}
14695
14696/// TimeToStr
14697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14698#[cfg_attr(feature = "bindings", derive(TS))]
14699pub struct TimeToStr {
14700    pub this: Box<Expression>,
14701    pub format: String,
14702    #[serde(default)]
14703    pub culture: Option<Box<Expression>>,
14704    #[serde(default)]
14705    pub zone: Option<Box<Expression>>,
14706}
14707
14708/// TimeStrToTime
14709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14710#[cfg_attr(feature = "bindings", derive(TS))]
14711pub struct TimeStrToTime {
14712    pub this: Box<Expression>,
14713    #[serde(default)]
14714    pub zone: Option<Box<Expression>>,
14715}
14716
14717/// TsOrDsAdd
14718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14719#[cfg_attr(feature = "bindings", derive(TS))]
14720pub struct TsOrDsAdd {
14721    pub this: Box<Expression>,
14722    pub expression: Box<Expression>,
14723    #[serde(default)]
14724    pub unit: Option<String>,
14725    #[serde(default)]
14726    pub return_type: Option<Box<Expression>>,
14727}
14728
14729/// TsOrDsDiff
14730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14731#[cfg_attr(feature = "bindings", derive(TS))]
14732pub struct TsOrDsDiff {
14733    pub this: Box<Expression>,
14734    pub expression: Box<Expression>,
14735    #[serde(default)]
14736    pub unit: Option<String>,
14737}
14738
14739/// TsOrDsToDate
14740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14741#[cfg_attr(feature = "bindings", derive(TS))]
14742pub struct TsOrDsToDate {
14743    pub this: Box<Expression>,
14744    #[serde(default)]
14745    pub format: Option<String>,
14746    #[serde(default)]
14747    pub safe: Option<Box<Expression>>,
14748}
14749
14750/// TsOrDsToTime
14751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14752#[cfg_attr(feature = "bindings", derive(TS))]
14753pub struct TsOrDsToTime {
14754    pub this: Box<Expression>,
14755    #[serde(default)]
14756    pub format: Option<String>,
14757    #[serde(default)]
14758    pub safe: Option<Box<Expression>>,
14759}
14760
14761/// Unhex
14762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14763#[cfg_attr(feature = "bindings", derive(TS))]
14764pub struct Unhex {
14765    pub this: Box<Expression>,
14766    #[serde(default)]
14767    pub expression: Option<Box<Expression>>,
14768}
14769
14770/// Uniform
14771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14772#[cfg_attr(feature = "bindings", derive(TS))]
14773pub struct Uniform {
14774    pub this: Box<Expression>,
14775    pub expression: Box<Expression>,
14776    #[serde(default)]
14777    pub gen: Option<Box<Expression>>,
14778    #[serde(default)]
14779    pub seed: Option<Box<Expression>>,
14780}
14781
14782/// UnixToStr
14783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14784#[cfg_attr(feature = "bindings", derive(TS))]
14785pub struct UnixToStr {
14786    pub this: Box<Expression>,
14787    #[serde(default)]
14788    pub format: Option<String>,
14789}
14790
14791/// UnixToTime
14792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14793#[cfg_attr(feature = "bindings", derive(TS))]
14794pub struct UnixToTime {
14795    pub this: Box<Expression>,
14796    #[serde(default)]
14797    pub scale: Option<i64>,
14798    #[serde(default)]
14799    pub zone: Option<Box<Expression>>,
14800    #[serde(default)]
14801    pub hours: Option<Box<Expression>>,
14802    #[serde(default)]
14803    pub minutes: Option<Box<Expression>>,
14804    #[serde(default)]
14805    pub format: Option<String>,
14806    #[serde(default)]
14807    pub target_type: Option<Box<Expression>>,
14808}
14809
14810/// Uuid
14811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14812#[cfg_attr(feature = "bindings", derive(TS))]
14813pub struct Uuid {
14814    #[serde(default)]
14815    pub this: Option<Box<Expression>>,
14816    #[serde(default)]
14817    pub name: Option<String>,
14818    #[serde(default)]
14819    pub is_string: Option<Box<Expression>>,
14820}
14821
14822/// TimestampFromParts
14823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14824#[cfg_attr(feature = "bindings", derive(TS))]
14825pub struct TimestampFromParts {
14826    #[serde(default)]
14827    pub zone: Option<Box<Expression>>,
14828    #[serde(default)]
14829    pub milli: Option<Box<Expression>>,
14830    #[serde(default)]
14831    pub this: Option<Box<Expression>>,
14832    #[serde(default)]
14833    pub expression: Option<Box<Expression>>,
14834}
14835
14836/// TimestampTzFromParts
14837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14838#[cfg_attr(feature = "bindings", derive(TS))]
14839pub struct TimestampTzFromParts {
14840    #[serde(default)]
14841    pub zone: Option<Box<Expression>>,
14842}
14843
14844/// Corr
14845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14846#[cfg_attr(feature = "bindings", derive(TS))]
14847pub struct Corr {
14848    pub this: Box<Expression>,
14849    pub expression: Box<Expression>,
14850    #[serde(default)]
14851    pub null_on_zero_variance: Option<Box<Expression>>,
14852}
14853
14854/// WidthBucket
14855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14856#[cfg_attr(feature = "bindings", derive(TS))]
14857pub struct WidthBucket {
14858    pub this: Box<Expression>,
14859    #[serde(default)]
14860    pub min_value: Option<Box<Expression>>,
14861    #[serde(default)]
14862    pub max_value: Option<Box<Expression>>,
14863    #[serde(default)]
14864    pub num_buckets: Option<Box<Expression>>,
14865    #[serde(default)]
14866    pub threshold: Option<Box<Expression>>,
14867}
14868
14869/// CovarSamp
14870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14871#[cfg_attr(feature = "bindings", derive(TS))]
14872pub struct CovarSamp {
14873    pub this: Box<Expression>,
14874    pub expression: Box<Expression>,
14875}
14876
14877/// CovarPop
14878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14879#[cfg_attr(feature = "bindings", derive(TS))]
14880pub struct CovarPop {
14881    pub this: Box<Expression>,
14882    pub expression: Box<Expression>,
14883}
14884
14885/// Week
14886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14887#[cfg_attr(feature = "bindings", derive(TS))]
14888pub struct Week {
14889    pub this: Box<Expression>,
14890    #[serde(default)]
14891    pub mode: Option<Box<Expression>>,
14892}
14893
14894/// XMLElement
14895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14896#[cfg_attr(feature = "bindings", derive(TS))]
14897pub struct XMLElement {
14898    pub this: Box<Expression>,
14899    #[serde(default)]
14900    pub expressions: Vec<Expression>,
14901    #[serde(default)]
14902    pub evalname: Option<Box<Expression>>,
14903}
14904
14905/// XMLGet
14906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14907#[cfg_attr(feature = "bindings", derive(TS))]
14908pub struct XMLGet {
14909    pub this: Box<Expression>,
14910    pub expression: Box<Expression>,
14911    #[serde(default)]
14912    pub instance: Option<Box<Expression>>,
14913}
14914
14915/// XMLTable
14916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14917#[cfg_attr(feature = "bindings", derive(TS))]
14918pub struct XMLTable {
14919    pub this: Box<Expression>,
14920    #[serde(default)]
14921    pub namespaces: Option<Box<Expression>>,
14922    #[serde(default)]
14923    pub passing: Option<Box<Expression>>,
14924    #[serde(default)]
14925    pub columns: Vec<Expression>,
14926    #[serde(default)]
14927    pub by_ref: Option<Box<Expression>>,
14928}
14929
14930/// XMLKeyValueOption
14931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14932#[cfg_attr(feature = "bindings", derive(TS))]
14933pub struct XMLKeyValueOption {
14934    pub this: Box<Expression>,
14935    #[serde(default)]
14936    pub expression: Option<Box<Expression>>,
14937}
14938
14939/// Zipf
14940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14941#[cfg_attr(feature = "bindings", derive(TS))]
14942pub struct Zipf {
14943    pub this: Box<Expression>,
14944    #[serde(default)]
14945    pub elementcount: Option<Box<Expression>>,
14946    #[serde(default)]
14947    pub gen: Option<Box<Expression>>,
14948}
14949
14950/// Merge
14951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14952#[cfg_attr(feature = "bindings", derive(TS))]
14953pub struct Merge {
14954    pub this: Box<Expression>,
14955    pub using: Box<Expression>,
14956    #[serde(default)]
14957    pub on: Option<Box<Expression>>,
14958    #[serde(default)]
14959    pub using_cond: Option<Box<Expression>>,
14960    #[serde(default)]
14961    pub whens: Option<Box<Expression>>,
14962    #[serde(default)]
14963    pub with_: Option<Box<Expression>>,
14964    #[serde(default)]
14965    pub returning: Option<Box<Expression>>,
14966}
14967
14968/// When
14969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14970#[cfg_attr(feature = "bindings", derive(TS))]
14971pub struct When {
14972    #[serde(default)]
14973    pub matched: Option<Box<Expression>>,
14974    #[serde(default)]
14975    pub source: Option<Box<Expression>>,
14976    #[serde(default)]
14977    pub condition: Option<Box<Expression>>,
14978    pub then: Box<Expression>,
14979}
14980
14981/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14983#[cfg_attr(feature = "bindings", derive(TS))]
14984pub struct Whens {
14985    #[serde(default)]
14986    pub expressions: Vec<Expression>,
14987}
14988
14989/// NextValueFor
14990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14991#[cfg_attr(feature = "bindings", derive(TS))]
14992pub struct NextValueFor {
14993    pub this: Box<Expression>,
14994    #[serde(default)]
14995    pub order: Option<Box<Expression>>,
14996}
14997
14998#[cfg(test)]
14999mod tests {
15000    use super::*;
15001
15002    #[test]
15003    #[cfg(feature = "bindings")]
15004    fn export_typescript_types() {
15005        // This test exports TypeScript types to the generated directory
15006        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
15007        Expression::export_all(&ts_rs::Config::default())
15008            .expect("Failed to export Expression types");
15009    }
15010
15011    #[test]
15012    fn test_simple_select_builder() {
15013        let select = Select::new()
15014            .column(Expression::star())
15015            .from(Expression::Table(Box::new(TableRef::new("users"))));
15016
15017        assert_eq!(select.expressions.len(), 1);
15018        assert!(select.from.is_some());
15019    }
15020
15021    #[test]
15022    fn test_expression_alias() {
15023        let expr = Expression::column("id").alias("user_id");
15024
15025        match expr {
15026            Expression::Alias(a) => {
15027                assert_eq!(a.alias.name, "user_id");
15028            }
15029            _ => panic!("Expected Alias"),
15030        }
15031    }
15032
15033    #[test]
15034    fn test_literal_creation() {
15035        let num = Expression::number(42);
15036        let str = Expression::string("hello");
15037
15038        match num {
15039            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
15040                let Literal::Number(n) = lit.as_ref() else {
15041                    unreachable!()
15042                };
15043                assert_eq!(n, "42")
15044            }
15045            _ => panic!("Expected Number"),
15046        }
15047
15048        match str {
15049            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
15050                let Literal::String(s) = lit.as_ref() else {
15051                    unreachable!()
15052                };
15053                assert_eq!(s, "hello")
15054            }
15055            _ => panic!("Expected String"),
15056        }
15057    }
15058
15059    #[test]
15060    fn test_expression_sql() {
15061        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
15062        assert_eq!(expr.sql(), "SELECT 1 + 2");
15063    }
15064
15065    #[test]
15066    fn test_expression_sql_for() {
15067        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
15068        let sql = expr.sql_for(crate::DialectType::Generic);
15069        // Generic mode normalizes IF() to CASE WHEN
15070        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
15071    }
15072}