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