Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117    TryCatch(Box<TryCatch>),
118
119    // Expressions
120    Alias(Box<Alias>),
121    Cast(Box<Cast>),
122    Collation(Box<CollationExpr>),
123    Case(Box<Case>),
124
125    // Binary operations
126    And(Box<BinaryOp>),
127    Or(Box<BinaryOp>),
128    Add(Box<BinaryOp>),
129    Sub(Box<BinaryOp>),
130    Mul(Box<BinaryOp>),
131    Div(Box<BinaryOp>),
132    Mod(Box<BinaryOp>),
133    Eq(Box<BinaryOp>),
134    Neq(Box<BinaryOp>),
135    Lt(Box<BinaryOp>),
136    Lte(Box<BinaryOp>),
137    Gt(Box<BinaryOp>),
138    Gte(Box<BinaryOp>),
139    Like(Box<LikeOp>),
140    ILike(Box<LikeOp>),
141    /// SQLite MATCH operator (FTS)
142    Match(Box<BinaryOp>),
143    BitwiseAnd(Box<BinaryOp>),
144    BitwiseOr(Box<BinaryOp>),
145    BitwiseXor(Box<BinaryOp>),
146    Concat(Box<BinaryOp>),
147    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
148    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
149    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
150
151    // PostgreSQL array/JSONB operators
152    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
153    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
154    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
155    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
156    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
157    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
158    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
159    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
160
161    // Unary operations
162    Not(Box<UnaryOp>),
163    Neg(Box<UnaryOp>),
164    BitwiseNot(Box<UnaryOp>),
165
166    // Predicates
167    In(Box<In>),
168    Between(Box<Between>),
169    IsNull(Box<IsNull>),
170    IsTrue(Box<IsTrueFalse>),
171    IsFalse(Box<IsTrueFalse>),
172    IsJson(Box<IsJson>),
173    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
174    Exists(Box<Exists>),
175    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
176    MemberOf(Box<BinaryOp>),
177
178    // Functions
179    Function(Box<Function>),
180    AggregateFunction(Box<AggregateFunction>),
181    WindowFunction(Box<WindowFunction>),
182
183    // Clauses
184    From(Box<From>),
185    Join(Box<Join>),
186    JoinedTable(Box<JoinedTable>),
187    Where(Box<Where>),
188    GroupBy(Box<GroupBy>),
189    Having(Box<Having>),
190    OrderBy(Box<OrderBy>),
191    Limit(Box<Limit>),
192    Offset(Box<Offset>),
193    Qualify(Box<Qualify>),
194    With(Box<With>),
195    Cte(Box<Cte>),
196    DistributeBy(Box<DistributeBy>),
197    ClusterBy(Box<ClusterBy>),
198    SortBy(Box<SortBy>),
199    LateralView(Box<LateralView>),
200    Hint(Box<Hint>),
201    Pseudocolumn(Pseudocolumn),
202
203    // Oracle hierarchical queries (CONNECT BY)
204    Connect(Box<Connect>),
205    Prior(Box<Prior>),
206    ConnectByRoot(Box<ConnectByRoot>),
207
208    // Pattern matching (MATCH_RECOGNIZE)
209    MatchRecognize(Box<MatchRecognize>),
210
211    // Order expressions
212    Ordered(Box<Ordered>),
213
214    // Window specifications
215    Window(Box<WindowSpec>),
216    Over(Box<Over>),
217    WithinGroup(Box<WithinGroup>),
218
219    // Data types
220    DataType(DataType),
221
222    // Arrays and structs
223    Array(Box<Array>),
224    Struct(Box<Struct>),
225    Tuple(Box<Tuple>),
226
227    // Interval
228    Interval(Box<Interval>),
229
230    // String functions
231    ConcatWs(Box<ConcatWs>),
232    Substring(Box<SubstringFunc>),
233    Upper(Box<UnaryFunc>),
234    Lower(Box<UnaryFunc>),
235    Length(Box<UnaryFunc>),
236    Trim(Box<TrimFunc>),
237    LTrim(Box<UnaryFunc>),
238    RTrim(Box<UnaryFunc>),
239    Replace(Box<ReplaceFunc>),
240    Reverse(Box<UnaryFunc>),
241    Left(Box<LeftRightFunc>),
242    Right(Box<LeftRightFunc>),
243    Repeat(Box<RepeatFunc>),
244    Lpad(Box<PadFunc>),
245    Rpad(Box<PadFunc>),
246    Split(Box<SplitFunc>),
247    RegexpLike(Box<RegexpFunc>),
248    RegexpReplace(Box<RegexpReplaceFunc>),
249    RegexpExtract(Box<RegexpExtractFunc>),
250    Overlay(Box<OverlayFunc>),
251
252    // Math functions
253    Abs(Box<UnaryFunc>),
254    Round(Box<RoundFunc>),
255    Floor(Box<FloorFunc>),
256    Ceil(Box<CeilFunc>),
257    Power(Box<BinaryFunc>),
258    Sqrt(Box<UnaryFunc>),
259    Cbrt(Box<UnaryFunc>),
260    Ln(Box<UnaryFunc>),
261    Log(Box<LogFunc>),
262    Exp(Box<UnaryFunc>),
263    Sign(Box<UnaryFunc>),
264    Greatest(Box<VarArgFunc>),
265    Least(Box<VarArgFunc>),
266
267    // Date/time functions
268    CurrentDate(CurrentDate),
269    CurrentTime(CurrentTime),
270    CurrentTimestamp(CurrentTimestamp),
271    CurrentTimestampLTZ(CurrentTimestampLTZ),
272    AtTimeZone(Box<AtTimeZone>),
273    DateAdd(Box<DateAddFunc>),
274    DateSub(Box<DateAddFunc>),
275    DateDiff(Box<DateDiffFunc>),
276    DateTrunc(Box<DateTruncFunc>),
277    Extract(Box<ExtractFunc>),
278    ToDate(Box<ToDateFunc>),
279    ToTimestamp(Box<ToTimestampFunc>),
280    Date(Box<UnaryFunc>),
281    Time(Box<UnaryFunc>),
282    DateFromUnixDate(Box<UnaryFunc>),
283    UnixDate(Box<UnaryFunc>),
284    UnixSeconds(Box<UnaryFunc>),
285    UnixMillis(Box<UnaryFunc>),
286    UnixMicros(Box<UnaryFunc>),
287    UnixToTimeStr(Box<BinaryFunc>),
288    TimeStrToDate(Box<UnaryFunc>),
289    DateToDi(Box<UnaryFunc>),
290    DiToDate(Box<UnaryFunc>),
291    TsOrDiToDi(Box<UnaryFunc>),
292    TsOrDsToDatetime(Box<UnaryFunc>),
293    TsOrDsToTimestamp(Box<UnaryFunc>),
294    YearOfWeek(Box<UnaryFunc>),
295    YearOfWeekIso(Box<UnaryFunc>),
296
297    // Control flow functions
298    Coalesce(Box<VarArgFunc>),
299    NullIf(Box<BinaryFunc>),
300    IfFunc(Box<IfFunc>),
301    IfNull(Box<BinaryFunc>),
302    Nvl(Box<BinaryFunc>),
303    Nvl2(Box<Nvl2Func>),
304
305    // Type conversion
306    TryCast(Box<Cast>),
307    SafeCast(Box<Cast>),
308
309    // Typed aggregate functions
310    Count(Box<CountFunc>),
311    Sum(Box<AggFunc>),
312    Avg(Box<AggFunc>),
313    Min(Box<AggFunc>),
314    Max(Box<AggFunc>),
315    GroupConcat(Box<GroupConcatFunc>),
316    StringAgg(Box<StringAggFunc>),
317    ListAgg(Box<ListAggFunc>),
318    ArrayAgg(Box<AggFunc>),
319    CountIf(Box<AggFunc>),
320    SumIf(Box<SumIfFunc>),
321    Stddev(Box<AggFunc>),
322    StddevPop(Box<AggFunc>),
323    StddevSamp(Box<AggFunc>),
324    Variance(Box<AggFunc>),
325    VarPop(Box<AggFunc>),
326    VarSamp(Box<AggFunc>),
327    Median(Box<AggFunc>),
328    Mode(Box<AggFunc>),
329    First(Box<AggFunc>),
330    Last(Box<AggFunc>),
331    AnyValue(Box<AggFunc>),
332    ApproxDistinct(Box<AggFunc>),
333    ApproxCountDistinct(Box<AggFunc>),
334    ApproxPercentile(Box<ApproxPercentileFunc>),
335    Percentile(Box<PercentileFunc>),
336    LogicalAnd(Box<AggFunc>),
337    LogicalOr(Box<AggFunc>),
338    Skewness(Box<AggFunc>),
339    BitwiseCount(Box<UnaryFunc>),
340    ArrayConcatAgg(Box<AggFunc>),
341    ArrayUniqueAgg(Box<AggFunc>),
342    BoolXorAgg(Box<AggFunc>),
343
344    // Typed window functions
345    RowNumber(RowNumber),
346    Rank(Rank),
347    DenseRank(DenseRank),
348    NTile(Box<NTileFunc>),
349    Lead(Box<LeadLagFunc>),
350    Lag(Box<LeadLagFunc>),
351    FirstValue(Box<ValueFunc>),
352    LastValue(Box<ValueFunc>),
353    NthValue(Box<NthValueFunc>),
354    PercentRank(PercentRank),
355    CumeDist(CumeDist),
356    PercentileCont(Box<PercentileFunc>),
357    PercentileDisc(Box<PercentileFunc>),
358
359    // Additional string functions
360    Contains(Box<BinaryFunc>),
361    StartsWith(Box<BinaryFunc>),
362    EndsWith(Box<BinaryFunc>),
363    Position(Box<PositionFunc>),
364    Initcap(Box<UnaryFunc>),
365    Ascii(Box<UnaryFunc>),
366    Chr(Box<UnaryFunc>),
367    /// MySQL CHAR function with multiple args and optional USING charset
368    CharFunc(Box<CharFunc>),
369    Soundex(Box<UnaryFunc>),
370    Levenshtein(Box<BinaryFunc>),
371    ByteLength(Box<UnaryFunc>),
372    Hex(Box<UnaryFunc>),
373    LowerHex(Box<UnaryFunc>),
374    Unicode(Box<UnaryFunc>),
375
376    // Additional math functions
377    ModFunc(Box<BinaryFunc>),
378    Random(Random),
379    Rand(Box<Rand>),
380    TruncFunc(Box<TruncateFunc>),
381    Pi(Pi),
382    Radians(Box<UnaryFunc>),
383    Degrees(Box<UnaryFunc>),
384    Sin(Box<UnaryFunc>),
385    Cos(Box<UnaryFunc>),
386    Tan(Box<UnaryFunc>),
387    Asin(Box<UnaryFunc>),
388    Acos(Box<UnaryFunc>),
389    Atan(Box<UnaryFunc>),
390    Atan2(Box<BinaryFunc>),
391    IsNan(Box<UnaryFunc>),
392    IsInf(Box<UnaryFunc>),
393    IntDiv(Box<BinaryFunc>),
394
395    // Control flow
396    Decode(Box<DecodeFunc>),
397
398    // Additional date/time functions
399    DateFormat(Box<DateFormatFunc>),
400    FormatDate(Box<DateFormatFunc>),
401    Year(Box<UnaryFunc>),
402    Month(Box<UnaryFunc>),
403    Day(Box<UnaryFunc>),
404    Hour(Box<UnaryFunc>),
405    Minute(Box<UnaryFunc>),
406    Second(Box<UnaryFunc>),
407    DayOfWeek(Box<UnaryFunc>),
408    DayOfWeekIso(Box<UnaryFunc>),
409    DayOfMonth(Box<UnaryFunc>),
410    DayOfYear(Box<UnaryFunc>),
411    WeekOfYear(Box<UnaryFunc>),
412    Quarter(Box<UnaryFunc>),
413    AddMonths(Box<BinaryFunc>),
414    MonthsBetween(Box<BinaryFunc>),
415    LastDay(Box<LastDayFunc>),
416    NextDay(Box<BinaryFunc>),
417    Epoch(Box<UnaryFunc>),
418    EpochMs(Box<UnaryFunc>),
419    FromUnixtime(Box<FromUnixtimeFunc>),
420    UnixTimestamp(Box<UnixTimestampFunc>),
421    MakeDate(Box<MakeDateFunc>),
422    MakeTimestamp(Box<MakeTimestampFunc>),
423    TimestampTrunc(Box<DateTruncFunc>),
424    TimeStrToUnix(Box<UnaryFunc>),
425
426    // Session/User functions
427    SessionUser(SessionUser),
428
429    // Hash/Crypto functions
430    SHA(Box<UnaryFunc>),
431    SHA1Digest(Box<UnaryFunc>),
432
433    // Time conversion functions
434    TimeToUnix(Box<UnaryFunc>),
435
436    // Array functions
437    ArrayFunc(Box<ArrayConstructor>),
438    ArrayLength(Box<UnaryFunc>),
439    ArraySize(Box<UnaryFunc>),
440    Cardinality(Box<UnaryFunc>),
441    ArrayContains(Box<BinaryFunc>),
442    ArrayPosition(Box<BinaryFunc>),
443    ArrayAppend(Box<BinaryFunc>),
444    ArrayPrepend(Box<BinaryFunc>),
445    ArrayConcat(Box<VarArgFunc>),
446    ArraySort(Box<ArraySortFunc>),
447    ArrayReverse(Box<UnaryFunc>),
448    ArrayDistinct(Box<UnaryFunc>),
449    ArrayJoin(Box<ArrayJoinFunc>),
450    ArrayToString(Box<ArrayJoinFunc>),
451    Unnest(Box<UnnestFunc>),
452    Explode(Box<UnaryFunc>),
453    ExplodeOuter(Box<UnaryFunc>),
454    ArrayFilter(Box<ArrayFilterFunc>),
455    ArrayTransform(Box<ArrayTransformFunc>),
456    ArrayFlatten(Box<UnaryFunc>),
457    ArrayCompact(Box<UnaryFunc>),
458    ArrayIntersect(Box<VarArgFunc>),
459    ArrayUnion(Box<BinaryFunc>),
460    ArrayExcept(Box<BinaryFunc>),
461    ArrayRemove(Box<BinaryFunc>),
462    ArrayZip(Box<VarArgFunc>),
463    Sequence(Box<SequenceFunc>),
464    Generate(Box<SequenceFunc>),
465    ExplodingGenerateSeries(Box<SequenceFunc>),
466    ToArray(Box<UnaryFunc>),
467    StarMap(Box<BinaryFunc>),
468
469    // Struct functions
470    StructFunc(Box<StructConstructor>),
471    StructExtract(Box<StructExtractFunc>),
472    NamedStruct(Box<NamedStructFunc>),
473
474    // Map functions
475    MapFunc(Box<MapConstructor>),
476    MapFromEntries(Box<UnaryFunc>),
477    MapFromArrays(Box<BinaryFunc>),
478    MapKeys(Box<UnaryFunc>),
479    MapValues(Box<UnaryFunc>),
480    MapContainsKey(Box<BinaryFunc>),
481    MapConcat(Box<VarArgFunc>),
482    ElementAt(Box<BinaryFunc>),
483    TransformKeys(Box<TransformFunc>),
484    TransformValues(Box<TransformFunc>),
485
486    // Exasol: function call with EMITS clause
487    FunctionEmits(Box<FunctionEmits>),
488
489    // JSON functions
490    JsonExtract(Box<JsonExtractFunc>),
491    JsonExtractScalar(Box<JsonExtractFunc>),
492    JsonExtractPath(Box<JsonPathFunc>),
493    JsonArray(Box<VarArgFunc>),
494    JsonObject(Box<JsonObjectFunc>),
495    JsonQuery(Box<JsonExtractFunc>),
496    JsonValue(Box<JsonExtractFunc>),
497    JsonArrayLength(Box<UnaryFunc>),
498    JsonKeys(Box<UnaryFunc>),
499    JsonType(Box<UnaryFunc>),
500    ParseJson(Box<UnaryFunc>),
501    ToJson(Box<UnaryFunc>),
502    JsonSet(Box<JsonModifyFunc>),
503    JsonInsert(Box<JsonModifyFunc>),
504    JsonRemove(Box<JsonPathFunc>),
505    JsonMergePatch(Box<BinaryFunc>),
506    JsonArrayAgg(Box<JsonArrayAggFunc>),
507    JsonObjectAgg(Box<JsonObjectAggFunc>),
508
509    // Type casting/conversion
510    Convert(Box<ConvertFunc>),
511    Typeof(Box<UnaryFunc>),
512
513    // Additional expressions
514    Lambda(Box<LambdaExpr>),
515    Parameter(Box<Parameter>),
516    Placeholder(Placeholder),
517    NamedArgument(Box<NamedArgument>),
518    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
519    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
520    TableArgument(Box<TableArgument>),
521    SqlComment(Box<SqlComment>),
522
523    // Additional predicates
524    NullSafeEq(Box<BinaryOp>),
525    NullSafeNeq(Box<BinaryOp>),
526    Glob(Box<BinaryOp>),
527    SimilarTo(Box<SimilarToExpr>),
528    Any(Box<QuantifiedExpr>),
529    All(Box<QuantifiedExpr>),
530    Overlaps(Box<OverlapsExpr>),
531
532    // Bitwise operations
533    BitwiseLeftShift(Box<BinaryOp>),
534    BitwiseRightShift(Box<BinaryOp>),
535    BitwiseAndAgg(Box<AggFunc>),
536    BitwiseOrAgg(Box<AggFunc>),
537    BitwiseXorAgg(Box<AggFunc>),
538
539    // Array/struct/map access
540    Subscript(Box<Subscript>),
541    Dot(Box<DotAccess>),
542    MethodCall(Box<MethodCall>),
543    ArraySlice(Box<ArraySlice>),
544
545    // DDL statements
546    CreateTable(Box<CreateTable>),
547    DropTable(Box<DropTable>),
548    Undrop(Box<Undrop>),
549    AlterTable(Box<AlterTable>),
550    CreateIndex(Box<CreateIndex>),
551    DropIndex(Box<DropIndex>),
552    CreateView(Box<CreateView>),
553    DropView(Box<DropView>),
554    AlterView(Box<AlterView>),
555    AlterIndex(Box<AlterIndex>),
556    Truncate(Box<Truncate>),
557    Use(Box<Use>),
558    Cache(Box<Cache>),
559    Uncache(Box<Uncache>),
560    LoadData(Box<LoadData>),
561    Pragma(Box<Pragma>),
562    Grant(Box<Grant>),
563    Revoke(Box<Revoke>),
564    Comment(Box<Comment>),
565    SetStatement(Box<SetStatement>),
566    // Phase 4: Additional DDL statements
567    CreateSchema(Box<CreateSchema>),
568    DropSchema(Box<DropSchema>),
569    DropNamespace(Box<DropNamespace>),
570    CreateDatabase(Box<CreateDatabase>),
571    DropDatabase(Box<DropDatabase>),
572    CreateFunction(Box<CreateFunction>),
573    DropFunction(Box<DropFunction>),
574    CreateProcedure(Box<CreateProcedure>),
575    DropProcedure(Box<DropProcedure>),
576    CreateSequence(Box<CreateSequence>),
577    CreateSynonym(Box<CreateSynonym>),
578    DropSequence(Box<DropSequence>),
579    AlterSequence(Box<AlterSequence>),
580    CreateTrigger(Box<CreateTrigger>),
581    DropTrigger(Box<DropTrigger>),
582    CreateType(Box<CreateType>),
583    DropType(Box<DropType>),
584    Describe(Box<Describe>),
585    Show(Box<Show>),
586
587    // Transaction and other commands
588    Command(Box<Command>),
589    Kill(Box<Kill>),
590    /// EXEC/EXECUTE statement (TSQL stored procedure call)
591    Execute(Box<ExecuteStatement>),
592
593    /// Snowflake CREATE TASK statement
594    CreateTask(Box<CreateTask>),
595
596    // Placeholder for unparsed/raw SQL
597    Raw(Raw),
598
599    // Paren for grouping
600    Paren(Box<Paren>),
601
602    // Expression with trailing comments (for round-trip preservation)
603    Annotated(Box<Annotated>),
604
605    // === BATCH GENERATED EXPRESSION TYPES ===
606    // Generated from Python sqlglot expressions.py
607    Refresh(Box<Refresh>),
608    LockingStatement(Box<LockingStatement>),
609    SequenceProperties(Box<SequenceProperties>),
610    TruncateTable(Box<TruncateTable>),
611    Clone(Box<Clone>),
612    Attach(Box<Attach>),
613    Detach(Box<Detach>),
614    Install(Box<Install>),
615    Summarize(Box<Summarize>),
616    Declare(Box<Declare>),
617    DeclareItem(Box<DeclareItem>),
618    Set(Box<Set>),
619    Heredoc(Box<Heredoc>),
620    SetItem(Box<SetItem>),
621    QueryBand(Box<QueryBand>),
622    UserDefinedFunction(Box<UserDefinedFunction>),
623    RecursiveWithSearch(Box<RecursiveWithSearch>),
624    ProjectionDef(Box<ProjectionDef>),
625    TableAlias(Box<TableAlias>),
626    ByteString(Box<ByteString>),
627    HexStringExpr(Box<HexStringExpr>),
628    UnicodeString(Box<UnicodeString>),
629    ColumnPosition(Box<ColumnPosition>),
630    ColumnDef(Box<ColumnDef>),
631    AlterColumn(Box<AlterColumn>),
632    AlterSortKey(Box<AlterSortKey>),
633    AlterSet(Box<AlterSet>),
634    RenameColumn(Box<RenameColumn>),
635    Comprehension(Box<Comprehension>),
636    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
637    MergeTreeTTL(Box<MergeTreeTTL>),
638    IndexConstraintOption(Box<IndexConstraintOption>),
639    ColumnConstraint(Box<ColumnConstraint>),
640    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
641    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
642    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
643    CheckColumnConstraint(Box<CheckColumnConstraint>),
644    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
645    CompressColumnConstraint(Box<CompressColumnConstraint>),
646    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
647    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
648    WithOperator(Box<WithOperator>),
649    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
650    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
651    CommentColumnConstraint(CommentColumnConstraint),
652    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
653    IndexColumnConstraint(Box<IndexColumnConstraint>),
654    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
655    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
656    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
657    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
658    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
659    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
660    InOutColumnConstraint(Box<InOutColumnConstraint>),
661    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
662    PathColumnConstraint(Box<PathColumnConstraint>),
663    Constraint(Box<Constraint>),
664    Export(Box<Export>),
665    Filter(Box<Filter>),
666    Changes(Box<Changes>),
667    CopyParameter(Box<CopyParameter>),
668    Credentials(Box<Credentials>),
669    Directory(Box<Directory>),
670    ForeignKey(Box<ForeignKey>),
671    ColumnPrefix(Box<ColumnPrefix>),
672    PrimaryKey(Box<PrimaryKey>),
673    IntoClause(Box<IntoClause>),
674    JoinHint(Box<JoinHint>),
675    Opclass(Box<Opclass>),
676    Index(Box<Index>),
677    IndexParameters(Box<IndexParameters>),
678    ConditionalInsert(Box<ConditionalInsert>),
679    MultitableInserts(Box<MultitableInserts>),
680    OnConflict(Box<OnConflict>),
681    OnCondition(Box<OnCondition>),
682    Returning(Box<Returning>),
683    Introducer(Box<Introducer>),
684    PartitionRange(Box<PartitionRange>),
685    Fetch(Box<Fetch>),
686    Group(Box<Group>),
687    Cube(Box<Cube>),
688    Rollup(Box<Rollup>),
689    GroupingSets(Box<GroupingSets>),
690    LimitOptions(Box<LimitOptions>),
691    Lateral(Box<Lateral>),
692    TableFromRows(Box<TableFromRows>),
693    RowsFrom(Box<RowsFrom>),
694    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
695    WithFill(Box<WithFill>),
696    Property(Box<Property>),
697    GrantPrivilege(Box<GrantPrivilege>),
698    GrantPrincipal(Box<GrantPrincipal>),
699    AllowedValuesProperty(Box<AllowedValuesProperty>),
700    AlgorithmProperty(Box<AlgorithmProperty>),
701    AutoIncrementProperty(Box<AutoIncrementProperty>),
702    AutoRefreshProperty(Box<AutoRefreshProperty>),
703    BackupProperty(Box<BackupProperty>),
704    BuildProperty(Box<BuildProperty>),
705    BlockCompressionProperty(Box<BlockCompressionProperty>),
706    CharacterSetProperty(Box<CharacterSetProperty>),
707    ChecksumProperty(Box<ChecksumProperty>),
708    CollateProperty(Box<CollateProperty>),
709    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
710    DataDeletionProperty(Box<DataDeletionProperty>),
711    DefinerProperty(Box<DefinerProperty>),
712    DistKeyProperty(Box<DistKeyProperty>),
713    DistributedByProperty(Box<DistributedByProperty>),
714    DistStyleProperty(Box<DistStyleProperty>),
715    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
716    EngineProperty(Box<EngineProperty>),
717    ToTableProperty(Box<ToTableProperty>),
718    ExecuteAsProperty(Box<ExecuteAsProperty>),
719    ExternalProperty(Box<ExternalProperty>),
720    FallbackProperty(Box<FallbackProperty>),
721    FileFormatProperty(Box<FileFormatProperty>),
722    CredentialsProperty(Box<CredentialsProperty>),
723    FreespaceProperty(Box<FreespaceProperty>),
724    InheritsProperty(Box<InheritsProperty>),
725    InputModelProperty(Box<InputModelProperty>),
726    OutputModelProperty(Box<OutputModelProperty>),
727    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
728    JournalProperty(Box<JournalProperty>),
729    LanguageProperty(Box<LanguageProperty>),
730    EnviromentProperty(Box<EnviromentProperty>),
731    ClusteredByProperty(Box<ClusteredByProperty>),
732    DictProperty(Box<DictProperty>),
733    DictRange(Box<DictRange>),
734    OnCluster(Box<OnCluster>),
735    LikeProperty(Box<LikeProperty>),
736    LocationProperty(Box<LocationProperty>),
737    LockProperty(Box<LockProperty>),
738    LockingProperty(Box<LockingProperty>),
739    LogProperty(Box<LogProperty>),
740    MaterializedProperty(Box<MaterializedProperty>),
741    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
742    OnProperty(Box<OnProperty>),
743    OnCommitProperty(Box<OnCommitProperty>),
744    PartitionedByProperty(Box<PartitionedByProperty>),
745    PartitionByProperty(Box<PartitionByProperty>),
746    PartitionedByBucket(Box<PartitionedByBucket>),
747    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
748    PartitionByTruncate(Box<PartitionByTruncate>),
749    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
750    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
751    PartitionByListProperty(Box<PartitionByListProperty>),
752    PartitionList(Box<PartitionList>),
753    Partition(Box<Partition>),
754    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
755    UniqueKeyProperty(Box<UniqueKeyProperty>),
756    RollupProperty(Box<RollupProperty>),
757    PartitionBoundSpec(Box<PartitionBoundSpec>),
758    PartitionedOfProperty(Box<PartitionedOfProperty>),
759    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
760    ReturnsProperty(Box<ReturnsProperty>),
761    RowFormatProperty(Box<RowFormatProperty>),
762    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
763    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
764    QueryTransform(Box<QueryTransform>),
765    SampleProperty(Box<SampleProperty>),
766    SecurityProperty(Box<SecurityProperty>),
767    SchemaCommentProperty(Box<SchemaCommentProperty>),
768    SemanticView(Box<SemanticView>),
769    SerdeProperties(Box<SerdeProperties>),
770    SetProperty(Box<SetProperty>),
771    SharingProperty(Box<SharingProperty>),
772    SetConfigProperty(Box<SetConfigProperty>),
773    SettingsProperty(Box<SettingsProperty>),
774    SortKeyProperty(Box<SortKeyProperty>),
775    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
776    SqlSecurityProperty(Box<SqlSecurityProperty>),
777    StabilityProperty(Box<StabilityProperty>),
778    StorageHandlerProperty(Box<StorageHandlerProperty>),
779    TemporaryProperty(Box<TemporaryProperty>),
780    Tags(Box<Tags>),
781    TransformModelProperty(Box<TransformModelProperty>),
782    TransientProperty(Box<TransientProperty>),
783    UsingTemplateProperty(Box<UsingTemplateProperty>),
784    ViewAttributeProperty(Box<ViewAttributeProperty>),
785    VolatileProperty(Box<VolatileProperty>),
786    WithDataProperty(Box<WithDataProperty>),
787    WithJournalTableProperty(Box<WithJournalTableProperty>),
788    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
789    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
790    WithProcedureOptions(Box<WithProcedureOptions>),
791    EncodeProperty(Box<EncodeProperty>),
792    IncludeProperty(Box<IncludeProperty>),
793    Properties(Box<Properties>),
794    OptionsProperty(Box<OptionsProperty>),
795    InputOutputFormat(Box<InputOutputFormat>),
796    Reference(Box<Reference>),
797    QueryOption(Box<QueryOption>),
798    WithTableHint(Box<WithTableHint>),
799    IndexTableHint(Box<IndexTableHint>),
800    HistoricalData(Box<HistoricalData>),
801    Get(Box<Get>),
802    SetOperation(Box<SetOperation>),
803    Var(Box<Var>),
804    Variadic(Box<Variadic>),
805    Version(Box<Version>),
806    Schema(Box<Schema>),
807    Lock(Box<Lock>),
808    TableSample(Box<TableSample>),
809    Tag(Box<Tag>),
810    UnpivotColumns(Box<UnpivotColumns>),
811    WindowSpec(Box<WindowSpec>),
812    SessionParameter(Box<SessionParameter>),
813    PseudoType(Box<PseudoType>),
814    ObjectIdentifier(Box<ObjectIdentifier>),
815    Transaction(Box<Transaction>),
816    Commit(Box<Commit>),
817    Rollback(Box<Rollback>),
818    AlterSession(Box<AlterSession>),
819    Analyze(Box<Analyze>),
820    AnalyzeStatistics(Box<AnalyzeStatistics>),
821    AnalyzeHistogram(Box<AnalyzeHistogram>),
822    AnalyzeSample(Box<AnalyzeSample>),
823    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
824    AnalyzeDelete(Box<AnalyzeDelete>),
825    AnalyzeWith(Box<AnalyzeWith>),
826    AnalyzeValidate(Box<AnalyzeValidate>),
827    AddPartition(Box<AddPartition>),
828    AttachOption(Box<AttachOption>),
829    DropPartition(Box<DropPartition>),
830    ReplacePartition(Box<ReplacePartition>),
831    DPipe(Box<DPipe>),
832    Operator(Box<Operator>),
833    PivotAny(Box<PivotAny>),
834    Aliases(Box<Aliases>),
835    AtIndex(Box<AtIndex>),
836    FromTimeZone(Box<FromTimeZone>),
837    FormatPhrase(Box<FormatPhrase>),
838    ForIn(Box<ForIn>),
839    TimeUnit(Box<TimeUnit>),
840    IntervalOp(Box<IntervalOp>),
841    IntervalSpan(Box<IntervalSpan>),
842    HavingMax(Box<HavingMax>),
843    CosineDistance(Box<CosineDistance>),
844    DotProduct(Box<DotProduct>),
845    EuclideanDistance(Box<EuclideanDistance>),
846    ManhattanDistance(Box<ManhattanDistance>),
847    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
848    Booland(Box<Booland>),
849    Boolor(Box<Boolor>),
850    ParameterizedAgg(Box<ParameterizedAgg>),
851    ArgMax(Box<ArgMax>),
852    ArgMin(Box<ArgMin>),
853    ApproxTopK(Box<ApproxTopK>),
854    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
855    ApproxTopKCombine(Box<ApproxTopKCombine>),
856    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
857    ApproxTopSum(Box<ApproxTopSum>),
858    ApproxQuantiles(Box<ApproxQuantiles>),
859    Minhash(Box<Minhash>),
860    FarmFingerprint(Box<FarmFingerprint>),
861    Float64(Box<Float64>),
862    Transform(Box<Transform>),
863    Translate(Box<Translate>),
864    Grouping(Box<Grouping>),
865    GroupingId(Box<GroupingId>),
866    Anonymous(Box<Anonymous>),
867    AnonymousAggFunc(Box<AnonymousAggFunc>),
868    CombinedAggFunc(Box<CombinedAggFunc>),
869    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
870    HashAgg(Box<HashAgg>),
871    Hll(Box<Hll>),
872    Apply(Box<Apply>),
873    ToBoolean(Box<ToBoolean>),
874    List(Box<List>),
875    ToMap(Box<ToMap>),
876    Pad(Box<Pad>),
877    ToChar(Box<ToChar>),
878    ToNumber(Box<ToNumber>),
879    ToDouble(Box<ToDouble>),
880    Int64(Box<UnaryFunc>),
881    StringFunc(Box<StringFunc>),
882    ToDecfloat(Box<ToDecfloat>),
883    TryToDecfloat(Box<TryToDecfloat>),
884    ToFile(Box<ToFile>),
885    Columns(Box<Columns>),
886    ConvertToCharset(Box<ConvertToCharset>),
887    ConvertTimezone(Box<ConvertTimezone>),
888    GenerateSeries(Box<GenerateSeries>),
889    AIAgg(Box<AIAgg>),
890    AIClassify(Box<AIClassify>),
891    ArrayAll(Box<ArrayAll>),
892    ArrayAny(Box<ArrayAny>),
893    ArrayConstructCompact(Box<ArrayConstructCompact>),
894    StPoint(Box<StPoint>),
895    StDistance(Box<StDistance>),
896    StringToArray(Box<StringToArray>),
897    ArraySum(Box<ArraySum>),
898    ObjectAgg(Box<ObjectAgg>),
899    CastToStrType(Box<CastToStrType>),
900    CheckJson(Box<CheckJson>),
901    CheckXml(Box<CheckXml>),
902    TranslateCharacters(Box<TranslateCharacters>),
903    CurrentSchemas(Box<CurrentSchemas>),
904    CurrentDatetime(Box<CurrentDatetime>),
905    Localtime(Box<Localtime>),
906    Localtimestamp(Box<Localtimestamp>),
907    Systimestamp(Box<Systimestamp>),
908    CurrentSchema(Box<CurrentSchema>),
909    CurrentUser(Box<CurrentUser>),
910    UtcTime(Box<UtcTime>),
911    UtcTimestamp(Box<UtcTimestamp>),
912    Timestamp(Box<TimestampFunc>),
913    DateBin(Box<DateBin>),
914    Datetime(Box<Datetime>),
915    DatetimeAdd(Box<DatetimeAdd>),
916    DatetimeSub(Box<DatetimeSub>),
917    DatetimeDiff(Box<DatetimeDiff>),
918    DatetimeTrunc(Box<DatetimeTrunc>),
919    Dayname(Box<Dayname>),
920    MakeInterval(Box<MakeInterval>),
921    PreviousDay(Box<PreviousDay>),
922    Elt(Box<Elt>),
923    TimestampAdd(Box<TimestampAdd>),
924    TimestampSub(Box<TimestampSub>),
925    TimestampDiff(Box<TimestampDiff>),
926    TimeSlice(Box<TimeSlice>),
927    TimeAdd(Box<TimeAdd>),
928    TimeSub(Box<TimeSub>),
929    TimeDiff(Box<TimeDiff>),
930    TimeTrunc(Box<TimeTrunc>),
931    DateFromParts(Box<DateFromParts>),
932    TimeFromParts(Box<TimeFromParts>),
933    DecodeCase(Box<DecodeCase>),
934    Decrypt(Box<Decrypt>),
935    DecryptRaw(Box<DecryptRaw>),
936    Encode(Box<Encode>),
937    Encrypt(Box<Encrypt>),
938    EncryptRaw(Box<EncryptRaw>),
939    EqualNull(Box<EqualNull>),
940    ToBinary(Box<ToBinary>),
941    Base64DecodeBinary(Box<Base64DecodeBinary>),
942    Base64DecodeString(Box<Base64DecodeString>),
943    Base64Encode(Box<Base64Encode>),
944    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
945    TryBase64DecodeString(Box<TryBase64DecodeString>),
946    GapFill(Box<GapFill>),
947    GenerateDateArray(Box<GenerateDateArray>),
948    GenerateTimestampArray(Box<GenerateTimestampArray>),
949    GetExtract(Box<GetExtract>),
950    Getbit(Box<Getbit>),
951    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
952    HexEncode(Box<HexEncode>),
953    Compress(Box<Compress>),
954    DecompressBinary(Box<DecompressBinary>),
955    DecompressString(Box<DecompressString>),
956    Xor(Box<Xor>),
957    Nullif(Box<Nullif>),
958    JSON(Box<JSON>),
959    JSONPath(Box<JSONPath>),
960    JSONPathFilter(Box<JSONPathFilter>),
961    JSONPathKey(Box<JSONPathKey>),
962    JSONPathRecursive(Box<JSONPathRecursive>),
963    JSONPathScript(Box<JSONPathScript>),
964    JSONPathSlice(Box<JSONPathSlice>),
965    JSONPathSelector(Box<JSONPathSelector>),
966    JSONPathSubscript(Box<JSONPathSubscript>),
967    JSONPathUnion(Box<JSONPathUnion>),
968    Format(Box<Format>),
969    JSONKeys(Box<JSONKeys>),
970    JSONKeyValue(Box<JSONKeyValue>),
971    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
972    JSONObject(Box<JSONObject>),
973    JSONObjectAgg(Box<JSONObjectAgg>),
974    JSONBObjectAgg(Box<JSONBObjectAgg>),
975    JSONArray(Box<JSONArray>),
976    JSONArrayAgg(Box<JSONArrayAgg>),
977    JSONExists(Box<JSONExists>),
978    JSONColumnDef(Box<JSONColumnDef>),
979    JSONSchema(Box<JSONSchema>),
980    JSONSet(Box<JSONSet>),
981    JSONStripNulls(Box<JSONStripNulls>),
982    JSONValue(Box<JSONValue>),
983    JSONValueArray(Box<JSONValueArray>),
984    JSONRemove(Box<JSONRemove>),
985    JSONTable(Box<JSONTable>),
986    JSONType(Box<JSONType>),
987    ObjectInsert(Box<ObjectInsert>),
988    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
989    OpenJSON(Box<OpenJSON>),
990    JSONBExists(Box<JSONBExists>),
991    JSONBContains(Box<BinaryFunc>),
992    JSONBExtract(Box<BinaryFunc>),
993    JSONCast(Box<JSONCast>),
994    JSONExtract(Box<JSONExtract>),
995    JSONExtractQuote(Box<JSONExtractQuote>),
996    JSONExtractArray(Box<JSONExtractArray>),
997    JSONExtractScalar(Box<JSONExtractScalar>),
998    JSONBExtractScalar(Box<JSONBExtractScalar>),
999    JSONFormat(Box<JSONFormat>),
1000    JSONBool(Box<UnaryFunc>),
1001    JSONPathRoot(JSONPathRoot),
1002    JSONArrayAppend(Box<JSONArrayAppend>),
1003    JSONArrayContains(Box<JSONArrayContains>),
1004    JSONArrayInsert(Box<JSONArrayInsert>),
1005    ParseJSON(Box<ParseJSON>),
1006    ParseUrl(Box<ParseUrl>),
1007    ParseIp(Box<ParseIp>),
1008    ParseTime(Box<ParseTime>),
1009    ParseDatetime(Box<ParseDatetime>),
1010    Map(Box<Map>),
1011    MapCat(Box<MapCat>),
1012    MapDelete(Box<MapDelete>),
1013    MapInsert(Box<MapInsert>),
1014    MapPick(Box<MapPick>),
1015    ScopeResolution(Box<ScopeResolution>),
1016    Slice(Box<Slice>),
1017    VarMap(Box<VarMap>),
1018    MatchAgainst(Box<MatchAgainst>),
1019    MD5Digest(Box<MD5Digest>),
1020    MD5NumberLower64(Box<UnaryFunc>),
1021    MD5NumberUpper64(Box<UnaryFunc>),
1022    Monthname(Box<Monthname>),
1023    Ntile(Box<Ntile>),
1024    Normalize(Box<Normalize>),
1025    Normal(Box<Normal>),
1026    Predict(Box<Predict>),
1027    MLTranslate(Box<MLTranslate>),
1028    FeaturesAtTime(Box<FeaturesAtTime>),
1029    GenerateEmbedding(Box<GenerateEmbedding>),
1030    MLForecast(Box<MLForecast>),
1031    ModelAttribute(Box<ModelAttribute>),
1032    VectorSearch(Box<VectorSearch>),
1033    Quantile(Box<Quantile>),
1034    ApproxQuantile(Box<ApproxQuantile>),
1035    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1036    Randn(Box<Randn>),
1037    Randstr(Box<Randstr>),
1038    RangeN(Box<RangeN>),
1039    RangeBucket(Box<RangeBucket>),
1040    ReadCSV(Box<ReadCSV>),
1041    ReadParquet(Box<ReadParquet>),
1042    Reduce(Box<Reduce>),
1043    RegexpExtractAll(Box<RegexpExtractAll>),
1044    RegexpILike(Box<RegexpILike>),
1045    RegexpFullMatch(Box<RegexpFullMatch>),
1046    RegexpInstr(Box<RegexpInstr>),
1047    RegexpSplit(Box<RegexpSplit>),
1048    RegexpCount(Box<RegexpCount>),
1049    RegrValx(Box<RegrValx>),
1050    RegrValy(Box<RegrValy>),
1051    RegrAvgy(Box<RegrAvgy>),
1052    RegrAvgx(Box<RegrAvgx>),
1053    RegrCount(Box<RegrCount>),
1054    RegrIntercept(Box<RegrIntercept>),
1055    RegrR2(Box<RegrR2>),
1056    RegrSxx(Box<RegrSxx>),
1057    RegrSxy(Box<RegrSxy>),
1058    RegrSyy(Box<RegrSyy>),
1059    RegrSlope(Box<RegrSlope>),
1060    SafeAdd(Box<SafeAdd>),
1061    SafeDivide(Box<SafeDivide>),
1062    SafeMultiply(Box<SafeMultiply>),
1063    SafeSubtract(Box<SafeSubtract>),
1064    SHA2(Box<SHA2>),
1065    SHA2Digest(Box<SHA2Digest>),
1066    SortArray(Box<SortArray>),
1067    SplitPart(Box<SplitPart>),
1068    SubstringIndex(Box<SubstringIndex>),
1069    StandardHash(Box<StandardHash>),
1070    StrPosition(Box<StrPosition>),
1071    Search(Box<Search>),
1072    SearchIp(Box<SearchIp>),
1073    StrToDate(Box<StrToDate>),
1074    DateStrToDate(Box<UnaryFunc>),
1075    DateToDateStr(Box<UnaryFunc>),
1076    StrToTime(Box<StrToTime>),
1077    StrToUnix(Box<StrToUnix>),
1078    StrToMap(Box<StrToMap>),
1079    NumberToStr(Box<NumberToStr>),
1080    FromBase(Box<FromBase>),
1081    Stuff(Box<Stuff>),
1082    TimeToStr(Box<TimeToStr>),
1083    TimeStrToTime(Box<TimeStrToTime>),
1084    TsOrDsAdd(Box<TsOrDsAdd>),
1085    TsOrDsDiff(Box<TsOrDsDiff>),
1086    TsOrDsToDate(Box<TsOrDsToDate>),
1087    TsOrDsToTime(Box<TsOrDsToTime>),
1088    Unhex(Box<Unhex>),
1089    Uniform(Box<Uniform>),
1090    UnixToStr(Box<UnixToStr>),
1091    UnixToTime(Box<UnixToTime>),
1092    Uuid(Box<Uuid>),
1093    TimestampFromParts(Box<TimestampFromParts>),
1094    TimestampTzFromParts(Box<TimestampTzFromParts>),
1095    Corr(Box<Corr>),
1096    WidthBucket(Box<WidthBucket>),
1097    CovarSamp(Box<CovarSamp>),
1098    CovarPop(Box<CovarPop>),
1099    Week(Box<Week>),
1100    XMLElement(Box<XMLElement>),
1101    XMLGet(Box<XMLGet>),
1102    XMLTable(Box<XMLTable>),
1103    XMLKeyValueOption(Box<XMLKeyValueOption>),
1104    Zipf(Box<Zipf>),
1105    Merge(Box<Merge>),
1106    When(Box<When>),
1107    Whens(Box<Whens>),
1108    NextValueFor(Box<NextValueFor>),
1109    /// RETURN statement (DuckDB stored procedures)
1110    ReturnStmt(Box<Expression>),
1111}
1112
1113impl Expression {
1114    /// Create a `Column` variant, boxing the value automatically.
1115    #[inline]
1116    pub fn boxed_column(col: Column) -> Self {
1117        Expression::Column(Box::new(col))
1118    }
1119
1120    /// Create a `Table` variant, boxing the value automatically.
1121    #[inline]
1122    pub fn boxed_table(t: TableRef) -> Self {
1123        Expression::Table(Box::new(t))
1124    }
1125
1126    /// Returns `true` if this expression is a valid top-level SQL statement.
1127    ///
1128    /// Bare expressions like identifiers, literals, and function calls are not
1129    /// valid statements. This is used by `validate()` to reject inputs like
1130    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1131    /// plus the bare identifier `doo`.
1132    pub fn is_statement(&self) -> bool {
1133        match self {
1134            // Queries
1135            Expression::Select(_)
1136            | Expression::Union(_)
1137            | Expression::Intersect(_)
1138            | Expression::Except(_)
1139            | Expression::Subquery(_)
1140            | Expression::Values(_)
1141            | Expression::PipeOperator(_)
1142
1143            // DML
1144            | Expression::Insert(_)
1145            | Expression::Update(_)
1146            | Expression::Delete(_)
1147            | Expression::Copy(_)
1148            | Expression::Put(_)
1149            | Expression::Merge(_)
1150            | Expression::TryCatch(_)
1151
1152            // DDL
1153            | Expression::CreateTable(_)
1154            | Expression::DropTable(_)
1155            | Expression::Undrop(_)
1156            | Expression::AlterTable(_)
1157            | Expression::CreateIndex(_)
1158            | Expression::DropIndex(_)
1159            | Expression::CreateView(_)
1160            | Expression::DropView(_)
1161            | Expression::AlterView(_)
1162            | Expression::AlterIndex(_)
1163            | Expression::Truncate(_)
1164            | Expression::TruncateTable(_)
1165            | Expression::CreateSchema(_)
1166            | Expression::DropSchema(_)
1167            | Expression::DropNamespace(_)
1168            | Expression::CreateDatabase(_)
1169            | Expression::DropDatabase(_)
1170            | Expression::CreateFunction(_)
1171            | Expression::DropFunction(_)
1172            | Expression::CreateProcedure(_)
1173            | Expression::DropProcedure(_)
1174            | Expression::CreateSequence(_)
1175            | Expression::CreateSynonym(_)
1176            | Expression::DropSequence(_)
1177            | Expression::AlterSequence(_)
1178            | Expression::CreateTrigger(_)
1179            | Expression::DropTrigger(_)
1180            | Expression::CreateType(_)
1181            | Expression::DropType(_)
1182            | Expression::Comment(_)
1183
1184            // Session/Transaction/Control
1185            | Expression::Use(_)
1186            | Expression::Set(_)
1187            | Expression::SetStatement(_)
1188            | Expression::Transaction(_)
1189            | Expression::Commit(_)
1190            | Expression::Rollback(_)
1191            | Expression::Grant(_)
1192            | Expression::Revoke(_)
1193            | Expression::Cache(_)
1194            | Expression::Uncache(_)
1195            | Expression::LoadData(_)
1196            | Expression::Pragma(_)
1197            | Expression::Describe(_)
1198            | Expression::Show(_)
1199            | Expression::Kill(_)
1200            | Expression::Execute(_)
1201            | Expression::Declare(_)
1202            | Expression::Refresh(_)
1203            | Expression::AlterSession(_)
1204            | Expression::LockingStatement(_)
1205
1206            // Analyze
1207            | Expression::Analyze(_)
1208            | Expression::AnalyzeStatistics(_)
1209            | Expression::AnalyzeHistogram(_)
1210            | Expression::AnalyzeSample(_)
1211            | Expression::AnalyzeListChainedRows(_)
1212            | Expression::AnalyzeDelete(_)
1213
1214            // Attach/Detach/Install/Summarize
1215            | Expression::Attach(_)
1216            | Expression::Detach(_)
1217            | Expression::Install(_)
1218            | Expression::Summarize(_)
1219
1220            // Pivot at statement level
1221            | Expression::Pivot(_)
1222            | Expression::Unpivot(_)
1223
1224            // Command (raw/unparsed statements)
1225            | Expression::Command(_)
1226            | Expression::Raw(_)
1227            | Expression::CreateTask(_)
1228
1229            // Return statement
1230            | Expression::ReturnStmt(_) => true,
1231
1232            // Annotated wraps another expression with comments — check inner
1233            Expression::Annotated(a) => a.this.is_statement(),
1234
1235            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1236            Expression::Alias(a) => a.this.is_statement(),
1237
1238            // Everything else (identifiers, literals, operators, functions, etc.)
1239            _ => false,
1240        }
1241    }
1242
1243    /// Create a literal number expression from an integer.
1244    pub fn number(n: i64) -> Self {
1245        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1246    }
1247
1248    /// Create a single-quoted literal string expression.
1249    pub fn string(s: impl Into<String>) -> Self {
1250        Expression::Literal(Box::new(Literal::String(s.into())))
1251    }
1252
1253    /// Create a literal number expression from a float.
1254    pub fn float(f: f64) -> Self {
1255        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1256    }
1257
1258    /// Get the inferred type annotation, if present.
1259    ///
1260    /// For value-producing expressions with an `inferred_type` field, returns
1261    /// the stored type. For literals and boolean constants, computes the type
1262    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1263    pub fn inferred_type(&self) -> Option<&DataType> {
1264        match self {
1265            // Structs with inferred_type field
1266            Expression::And(op)
1267            | Expression::Or(op)
1268            | Expression::Add(op)
1269            | Expression::Sub(op)
1270            | Expression::Mul(op)
1271            | Expression::Div(op)
1272            | Expression::Mod(op)
1273            | Expression::Eq(op)
1274            | Expression::Neq(op)
1275            | Expression::Lt(op)
1276            | Expression::Lte(op)
1277            | Expression::Gt(op)
1278            | Expression::Gte(op)
1279            | Expression::Concat(op)
1280            | Expression::BitwiseAnd(op)
1281            | Expression::BitwiseOr(op)
1282            | Expression::BitwiseXor(op)
1283            | Expression::Adjacent(op)
1284            | Expression::TsMatch(op)
1285            | Expression::PropertyEQ(op)
1286            | Expression::ArrayContainsAll(op)
1287            | Expression::ArrayContainedBy(op)
1288            | Expression::ArrayOverlaps(op)
1289            | Expression::JSONBContainsAllTopKeys(op)
1290            | Expression::JSONBContainsAnyTopKeys(op)
1291            | Expression::JSONBDeleteAtPath(op)
1292            | Expression::ExtendsLeft(op)
1293            | Expression::ExtendsRight(op)
1294            | Expression::Is(op)
1295            | Expression::MemberOf(op)
1296            | Expression::Match(op)
1297            | Expression::NullSafeEq(op)
1298            | Expression::NullSafeNeq(op)
1299            | Expression::Glob(op)
1300            | Expression::BitwiseLeftShift(op)
1301            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1302
1303            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1304                op.inferred_type.as_ref()
1305            }
1306
1307            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1308
1309            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1310                c.inferred_type.as_ref()
1311            }
1312
1313            Expression::Column(c) => c.inferred_type.as_ref(),
1314            Expression::Function(f) => f.inferred_type.as_ref(),
1315            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1316            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1317            Expression::Case(c) => c.inferred_type.as_ref(),
1318            Expression::Subquery(s) => s.inferred_type.as_ref(),
1319            Expression::Alias(a) => a.inferred_type.as_ref(),
1320            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1321            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1322            Expression::Count(f) => f.inferred_type.as_ref(),
1323            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1324            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1325            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1326            Expression::SumIf(f) => f.inferred_type.as_ref(),
1327
1328            // UnaryFunc variants
1329            Expression::Upper(f)
1330            | Expression::Lower(f)
1331            | Expression::Length(f)
1332            | Expression::LTrim(f)
1333            | Expression::RTrim(f)
1334            | Expression::Reverse(f)
1335            | Expression::Abs(f)
1336            | Expression::Sqrt(f)
1337            | Expression::Cbrt(f)
1338            | Expression::Ln(f)
1339            | Expression::Exp(f)
1340            | Expression::Sign(f)
1341            | Expression::Date(f)
1342            | Expression::Time(f)
1343            | Expression::Initcap(f)
1344            | Expression::Ascii(f)
1345            | Expression::Chr(f)
1346            | Expression::Soundex(f)
1347            | Expression::ByteLength(f)
1348            | Expression::Hex(f)
1349            | Expression::LowerHex(f)
1350            | Expression::Unicode(f)
1351            | Expression::Typeof(f)
1352            | Expression::Explode(f)
1353            | Expression::ExplodeOuter(f)
1354            | Expression::MapFromEntries(f)
1355            | Expression::MapKeys(f)
1356            | Expression::MapValues(f)
1357            | Expression::ArrayLength(f)
1358            | Expression::ArraySize(f)
1359            | Expression::Cardinality(f)
1360            | Expression::ArrayReverse(f)
1361            | Expression::ArrayDistinct(f)
1362            | Expression::ArrayFlatten(f)
1363            | Expression::ArrayCompact(f)
1364            | Expression::ToArray(f)
1365            | Expression::JsonArrayLength(f)
1366            | Expression::JsonKeys(f)
1367            | Expression::JsonType(f)
1368            | Expression::ParseJson(f)
1369            | Expression::ToJson(f)
1370            | Expression::Radians(f)
1371            | Expression::Degrees(f)
1372            | Expression::Sin(f)
1373            | Expression::Cos(f)
1374            | Expression::Tan(f)
1375            | Expression::Asin(f)
1376            | Expression::Acos(f)
1377            | Expression::Atan(f)
1378            | Expression::IsNan(f)
1379            | Expression::IsInf(f)
1380            | Expression::Year(f)
1381            | Expression::Month(f)
1382            | Expression::Day(f)
1383            | Expression::Hour(f)
1384            | Expression::Minute(f)
1385            | Expression::Second(f)
1386            | Expression::DayOfWeek(f)
1387            | Expression::DayOfWeekIso(f)
1388            | Expression::DayOfMonth(f)
1389            | Expression::DayOfYear(f)
1390            | Expression::WeekOfYear(f)
1391            | Expression::Quarter(f)
1392            | Expression::Epoch(f)
1393            | Expression::EpochMs(f)
1394            | Expression::BitwiseCount(f)
1395            | Expression::DateFromUnixDate(f)
1396            | Expression::UnixDate(f)
1397            | Expression::UnixSeconds(f)
1398            | Expression::UnixMillis(f)
1399            | Expression::UnixMicros(f)
1400            | Expression::TimeStrToDate(f)
1401            | Expression::DateToDi(f)
1402            | Expression::DiToDate(f)
1403            | Expression::TsOrDiToDi(f)
1404            | Expression::TsOrDsToDatetime(f)
1405            | Expression::TsOrDsToTimestamp(f)
1406            | Expression::YearOfWeek(f)
1407            | Expression::YearOfWeekIso(f)
1408            | Expression::SHA(f)
1409            | Expression::SHA1Digest(f)
1410            | Expression::TimeToUnix(f)
1411            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1412
1413            // BinaryFunc variants
1414            Expression::Power(f)
1415            | Expression::NullIf(f)
1416            | Expression::IfNull(f)
1417            | Expression::Nvl(f)
1418            | Expression::Contains(f)
1419            | Expression::StartsWith(f)
1420            | Expression::EndsWith(f)
1421            | Expression::Levenshtein(f)
1422            | Expression::ModFunc(f)
1423            | Expression::IntDiv(f)
1424            | Expression::Atan2(f)
1425            | Expression::AddMonths(f)
1426            | Expression::MonthsBetween(f)
1427            | Expression::NextDay(f)
1428            | Expression::UnixToTimeStr(f)
1429            | Expression::ArrayContains(f)
1430            | Expression::ArrayPosition(f)
1431            | Expression::ArrayAppend(f)
1432            | Expression::ArrayPrepend(f)
1433            | Expression::ArrayUnion(f)
1434            | Expression::ArrayExcept(f)
1435            | Expression::ArrayRemove(f)
1436            | Expression::StarMap(f)
1437            | Expression::MapFromArrays(f)
1438            | Expression::MapContainsKey(f)
1439            | Expression::ElementAt(f)
1440            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1441
1442            // VarArgFunc variants
1443            Expression::Coalesce(f)
1444            | Expression::Greatest(f)
1445            | Expression::Least(f)
1446            | Expression::ArrayConcat(f)
1447            | Expression::ArrayIntersect(f)
1448            | Expression::ArrayZip(f)
1449            | Expression::MapConcat(f)
1450            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1451
1452            // AggFunc variants
1453            Expression::Sum(f)
1454            | Expression::Avg(f)
1455            | Expression::Min(f)
1456            | Expression::Max(f)
1457            | Expression::ArrayAgg(f)
1458            | Expression::CountIf(f)
1459            | Expression::Stddev(f)
1460            | Expression::StddevPop(f)
1461            | Expression::StddevSamp(f)
1462            | Expression::Variance(f)
1463            | Expression::VarPop(f)
1464            | Expression::VarSamp(f)
1465            | Expression::Median(f)
1466            | Expression::Mode(f)
1467            | Expression::First(f)
1468            | Expression::Last(f)
1469            | Expression::AnyValue(f)
1470            | Expression::ApproxDistinct(f)
1471            | Expression::ApproxCountDistinct(f)
1472            | Expression::LogicalAnd(f)
1473            | Expression::LogicalOr(f)
1474            | Expression::Skewness(f)
1475            | Expression::ArrayConcatAgg(f)
1476            | Expression::ArrayUniqueAgg(f)
1477            | Expression::BoolXorAgg(f)
1478            | Expression::BitwiseAndAgg(f)
1479            | Expression::BitwiseOrAgg(f)
1480            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1481
1482            // Everything else: no inferred_type field
1483            _ => None,
1484        }
1485    }
1486
1487    /// Set the inferred type annotation on this expression.
1488    ///
1489    /// Only has an effect on value-producing expressions with an `inferred_type`
1490    /// field. For other expression types, this is a no-op.
1491    pub fn set_inferred_type(&mut self, dt: DataType) {
1492        match self {
1493            Expression::And(op)
1494            | Expression::Or(op)
1495            | Expression::Add(op)
1496            | Expression::Sub(op)
1497            | Expression::Mul(op)
1498            | Expression::Div(op)
1499            | Expression::Mod(op)
1500            | Expression::Eq(op)
1501            | Expression::Neq(op)
1502            | Expression::Lt(op)
1503            | Expression::Lte(op)
1504            | Expression::Gt(op)
1505            | Expression::Gte(op)
1506            | Expression::Concat(op)
1507            | Expression::BitwiseAnd(op)
1508            | Expression::BitwiseOr(op)
1509            | Expression::BitwiseXor(op)
1510            | Expression::Adjacent(op)
1511            | Expression::TsMatch(op)
1512            | Expression::PropertyEQ(op)
1513            | Expression::ArrayContainsAll(op)
1514            | Expression::ArrayContainedBy(op)
1515            | Expression::ArrayOverlaps(op)
1516            | Expression::JSONBContainsAllTopKeys(op)
1517            | Expression::JSONBContainsAnyTopKeys(op)
1518            | Expression::JSONBDeleteAtPath(op)
1519            | Expression::ExtendsLeft(op)
1520            | Expression::ExtendsRight(op)
1521            | Expression::Is(op)
1522            | Expression::MemberOf(op)
1523            | Expression::Match(op)
1524            | Expression::NullSafeEq(op)
1525            | Expression::NullSafeNeq(op)
1526            | Expression::Glob(op)
1527            | Expression::BitwiseLeftShift(op)
1528            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1529
1530            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1531                op.inferred_type = Some(dt)
1532            }
1533
1534            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1535
1536            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1537                c.inferred_type = Some(dt)
1538            }
1539
1540            Expression::Column(c) => c.inferred_type = Some(dt),
1541            Expression::Function(f) => f.inferred_type = Some(dt),
1542            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1543            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1544            Expression::Case(c) => c.inferred_type = Some(dt),
1545            Expression::Subquery(s) => s.inferred_type = Some(dt),
1546            Expression::Alias(a) => a.inferred_type = Some(dt),
1547            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1548            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1549            Expression::Count(f) => f.inferred_type = Some(dt),
1550            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1551            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1552            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1553            Expression::SumIf(f) => f.inferred_type = Some(dt),
1554
1555            // UnaryFunc variants
1556            Expression::Upper(f)
1557            | Expression::Lower(f)
1558            | Expression::Length(f)
1559            | Expression::LTrim(f)
1560            | Expression::RTrim(f)
1561            | Expression::Reverse(f)
1562            | Expression::Abs(f)
1563            | Expression::Sqrt(f)
1564            | Expression::Cbrt(f)
1565            | Expression::Ln(f)
1566            | Expression::Exp(f)
1567            | Expression::Sign(f)
1568            | Expression::Date(f)
1569            | Expression::Time(f)
1570            | Expression::Initcap(f)
1571            | Expression::Ascii(f)
1572            | Expression::Chr(f)
1573            | Expression::Soundex(f)
1574            | Expression::ByteLength(f)
1575            | Expression::Hex(f)
1576            | Expression::LowerHex(f)
1577            | Expression::Unicode(f)
1578            | Expression::Typeof(f)
1579            | Expression::Explode(f)
1580            | Expression::ExplodeOuter(f)
1581            | Expression::MapFromEntries(f)
1582            | Expression::MapKeys(f)
1583            | Expression::MapValues(f)
1584            | Expression::ArrayLength(f)
1585            | Expression::ArraySize(f)
1586            | Expression::Cardinality(f)
1587            | Expression::ArrayReverse(f)
1588            | Expression::ArrayDistinct(f)
1589            | Expression::ArrayFlatten(f)
1590            | Expression::ArrayCompact(f)
1591            | Expression::ToArray(f)
1592            | Expression::JsonArrayLength(f)
1593            | Expression::JsonKeys(f)
1594            | Expression::JsonType(f)
1595            | Expression::ParseJson(f)
1596            | Expression::ToJson(f)
1597            | Expression::Radians(f)
1598            | Expression::Degrees(f)
1599            | Expression::Sin(f)
1600            | Expression::Cos(f)
1601            | Expression::Tan(f)
1602            | Expression::Asin(f)
1603            | Expression::Acos(f)
1604            | Expression::Atan(f)
1605            | Expression::IsNan(f)
1606            | Expression::IsInf(f)
1607            | Expression::Year(f)
1608            | Expression::Month(f)
1609            | Expression::Day(f)
1610            | Expression::Hour(f)
1611            | Expression::Minute(f)
1612            | Expression::Second(f)
1613            | Expression::DayOfWeek(f)
1614            | Expression::DayOfWeekIso(f)
1615            | Expression::DayOfMonth(f)
1616            | Expression::DayOfYear(f)
1617            | Expression::WeekOfYear(f)
1618            | Expression::Quarter(f)
1619            | Expression::Epoch(f)
1620            | Expression::EpochMs(f)
1621            | Expression::BitwiseCount(f)
1622            | Expression::DateFromUnixDate(f)
1623            | Expression::UnixDate(f)
1624            | Expression::UnixSeconds(f)
1625            | Expression::UnixMillis(f)
1626            | Expression::UnixMicros(f)
1627            | Expression::TimeStrToDate(f)
1628            | Expression::DateToDi(f)
1629            | Expression::DiToDate(f)
1630            | Expression::TsOrDiToDi(f)
1631            | Expression::TsOrDsToDatetime(f)
1632            | Expression::TsOrDsToTimestamp(f)
1633            | Expression::YearOfWeek(f)
1634            | Expression::YearOfWeekIso(f)
1635            | Expression::SHA(f)
1636            | Expression::SHA1Digest(f)
1637            | Expression::TimeToUnix(f)
1638            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1639
1640            // BinaryFunc variants
1641            Expression::Power(f)
1642            | Expression::NullIf(f)
1643            | Expression::IfNull(f)
1644            | Expression::Nvl(f)
1645            | Expression::Contains(f)
1646            | Expression::StartsWith(f)
1647            | Expression::EndsWith(f)
1648            | Expression::Levenshtein(f)
1649            | Expression::ModFunc(f)
1650            | Expression::IntDiv(f)
1651            | Expression::Atan2(f)
1652            | Expression::AddMonths(f)
1653            | Expression::MonthsBetween(f)
1654            | Expression::NextDay(f)
1655            | Expression::UnixToTimeStr(f)
1656            | Expression::ArrayContains(f)
1657            | Expression::ArrayPosition(f)
1658            | Expression::ArrayAppend(f)
1659            | Expression::ArrayPrepend(f)
1660            | Expression::ArrayUnion(f)
1661            | Expression::ArrayExcept(f)
1662            | Expression::ArrayRemove(f)
1663            | Expression::StarMap(f)
1664            | Expression::MapFromArrays(f)
1665            | Expression::MapContainsKey(f)
1666            | Expression::ElementAt(f)
1667            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1668
1669            // VarArgFunc variants
1670            Expression::Coalesce(f)
1671            | Expression::Greatest(f)
1672            | Expression::Least(f)
1673            | Expression::ArrayConcat(f)
1674            | Expression::ArrayIntersect(f)
1675            | Expression::ArrayZip(f)
1676            | Expression::MapConcat(f)
1677            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1678
1679            // AggFunc variants
1680            Expression::Sum(f)
1681            | Expression::Avg(f)
1682            | Expression::Min(f)
1683            | Expression::Max(f)
1684            | Expression::ArrayAgg(f)
1685            | Expression::CountIf(f)
1686            | Expression::Stddev(f)
1687            | Expression::StddevPop(f)
1688            | Expression::StddevSamp(f)
1689            | Expression::Variance(f)
1690            | Expression::VarPop(f)
1691            | Expression::VarSamp(f)
1692            | Expression::Median(f)
1693            | Expression::Mode(f)
1694            | Expression::First(f)
1695            | Expression::Last(f)
1696            | Expression::AnyValue(f)
1697            | Expression::ApproxDistinct(f)
1698            | Expression::ApproxCountDistinct(f)
1699            | Expression::LogicalAnd(f)
1700            | Expression::LogicalOr(f)
1701            | Expression::Skewness(f)
1702            | Expression::ArrayConcatAgg(f)
1703            | Expression::ArrayUniqueAgg(f)
1704            | Expression::BoolXorAgg(f)
1705            | Expression::BitwiseAndAgg(f)
1706            | Expression::BitwiseOrAgg(f)
1707            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1708
1709            // Expressions without inferred_type field - no-op
1710            _ => {}
1711        }
1712    }
1713
1714    /// Create an unqualified column reference (e.g. `name`).
1715    pub fn column(name: impl Into<String>) -> Self {
1716        Expression::Column(Box::new(Column {
1717            name: Identifier::new(name),
1718            table: None,
1719            join_mark: false,
1720            trailing_comments: Vec::new(),
1721            span: None,
1722            inferred_type: None,
1723        }))
1724    }
1725
1726    /// Create a qualified column reference (`table.column`).
1727    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1728        Expression::Column(Box::new(Column {
1729            name: Identifier::new(column),
1730            table: Some(Identifier::new(table)),
1731            join_mark: false,
1732            trailing_comments: Vec::new(),
1733            span: None,
1734            inferred_type: None,
1735        }))
1736    }
1737
1738    /// Create a bare identifier expression (not a column reference).
1739    pub fn identifier(name: impl Into<String>) -> Self {
1740        Expression::Identifier(Identifier::new(name))
1741    }
1742
1743    /// Create a NULL expression
1744    pub fn null() -> Self {
1745        Expression::Null(Null)
1746    }
1747
1748    /// Create a TRUE expression
1749    pub fn true_() -> Self {
1750        Expression::Boolean(BooleanLiteral { value: true })
1751    }
1752
1753    /// Create a FALSE expression
1754    pub fn false_() -> Self {
1755        Expression::Boolean(BooleanLiteral { value: false })
1756    }
1757
1758    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1759    pub fn star() -> Self {
1760        Expression::Star(Star {
1761            table: None,
1762            except: None,
1763            replace: None,
1764            rename: None,
1765            trailing_comments: Vec::new(),
1766            span: None,
1767        })
1768    }
1769
1770    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1771    pub fn alias(self, name: impl Into<String>) -> Self {
1772        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1773    }
1774
1775    /// Check if this is a SELECT expression
1776    pub fn is_select(&self) -> bool {
1777        matches!(self, Expression::Select(_))
1778    }
1779
1780    /// Try to get as a Select
1781    pub fn as_select(&self) -> Option<&Select> {
1782        match self {
1783            Expression::Select(s) => Some(s),
1784            _ => None,
1785        }
1786    }
1787
1788    /// Try to get as a mutable Select
1789    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1790        match self {
1791            Expression::Select(s) => Some(s),
1792            _ => None,
1793        }
1794    }
1795
1796    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1797    ///
1798    /// Returns an empty string if generation fails. For dialect-specific output,
1799    /// use [`sql_for()`](Self::sql_for) instead.
1800    #[cfg(feature = "generate")]
1801    pub fn sql(&self) -> String {
1802        crate::generator::Generator::sql(self).unwrap_or_default()
1803    }
1804
1805    /// Generate a SQL string for this expression targeting a specific dialect.
1806    ///
1807    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1808    /// syntax variations) are applied automatically.  Returns an empty string if
1809    /// generation fails.
1810    #[cfg(feature = "generate")]
1811    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1812        crate::generate(self, dialect).unwrap_or_default()
1813    }
1814}
1815
1816// === Python API accessor methods ===
1817
1818impl Expression {
1819    /// Returns the serde-compatible snake_case variant name without serialization.
1820    /// This is much faster than serializing to JSON and extracting the key.
1821    pub fn variant_name(&self) -> &'static str {
1822        match self {
1823            Expression::Literal(_) => "literal",
1824            Expression::Boolean(_) => "boolean",
1825            Expression::Null(_) => "null",
1826            Expression::Identifier(_) => "identifier",
1827            Expression::Column(_) => "column",
1828            Expression::Table(_) => "table",
1829            Expression::Star(_) => "star",
1830            Expression::BracedWildcard(_) => "braced_wildcard",
1831            Expression::Select(_) => "select",
1832            Expression::Union(_) => "union",
1833            Expression::Intersect(_) => "intersect",
1834            Expression::Except(_) => "except",
1835            Expression::Subquery(_) => "subquery",
1836            Expression::PipeOperator(_) => "pipe_operator",
1837            Expression::Pivot(_) => "pivot",
1838            Expression::PivotAlias(_) => "pivot_alias",
1839            Expression::Unpivot(_) => "unpivot",
1840            Expression::Values(_) => "values",
1841            Expression::PreWhere(_) => "pre_where",
1842            Expression::Stream(_) => "stream",
1843            Expression::UsingData(_) => "using_data",
1844            Expression::XmlNamespace(_) => "xml_namespace",
1845            Expression::Insert(_) => "insert",
1846            Expression::Update(_) => "update",
1847            Expression::Delete(_) => "delete",
1848            Expression::Copy(_) => "copy",
1849            Expression::Put(_) => "put",
1850            Expression::StageReference(_) => "stage_reference",
1851            Expression::Alias(_) => "alias",
1852            Expression::Cast(_) => "cast",
1853            Expression::Collation(_) => "collation",
1854            Expression::Case(_) => "case",
1855            Expression::And(_) => "and",
1856            Expression::Or(_) => "or",
1857            Expression::Add(_) => "add",
1858            Expression::Sub(_) => "sub",
1859            Expression::Mul(_) => "mul",
1860            Expression::Div(_) => "div",
1861            Expression::Mod(_) => "mod",
1862            Expression::Eq(_) => "eq",
1863            Expression::Neq(_) => "neq",
1864            Expression::Lt(_) => "lt",
1865            Expression::Lte(_) => "lte",
1866            Expression::Gt(_) => "gt",
1867            Expression::Gte(_) => "gte",
1868            Expression::Like(_) => "like",
1869            Expression::ILike(_) => "i_like",
1870            Expression::Match(_) => "match",
1871            Expression::BitwiseAnd(_) => "bitwise_and",
1872            Expression::BitwiseOr(_) => "bitwise_or",
1873            Expression::BitwiseXor(_) => "bitwise_xor",
1874            Expression::Concat(_) => "concat",
1875            Expression::Adjacent(_) => "adjacent",
1876            Expression::TsMatch(_) => "ts_match",
1877            Expression::PropertyEQ(_) => "property_e_q",
1878            Expression::ArrayContainsAll(_) => "array_contains_all",
1879            Expression::ArrayContainedBy(_) => "array_contained_by",
1880            Expression::ArrayOverlaps(_) => "array_overlaps",
1881            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1882            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1883            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1884            Expression::ExtendsLeft(_) => "extends_left",
1885            Expression::ExtendsRight(_) => "extends_right",
1886            Expression::Not(_) => "not",
1887            Expression::Neg(_) => "neg",
1888            Expression::BitwiseNot(_) => "bitwise_not",
1889            Expression::In(_) => "in",
1890            Expression::Between(_) => "between",
1891            Expression::IsNull(_) => "is_null",
1892            Expression::IsTrue(_) => "is_true",
1893            Expression::IsFalse(_) => "is_false",
1894            Expression::IsJson(_) => "is_json",
1895            Expression::Is(_) => "is",
1896            Expression::Exists(_) => "exists",
1897            Expression::MemberOf(_) => "member_of",
1898            Expression::Function(_) => "function",
1899            Expression::AggregateFunction(_) => "aggregate_function",
1900            Expression::WindowFunction(_) => "window_function",
1901            Expression::From(_) => "from",
1902            Expression::Join(_) => "join",
1903            Expression::JoinedTable(_) => "joined_table",
1904            Expression::Where(_) => "where",
1905            Expression::GroupBy(_) => "group_by",
1906            Expression::Having(_) => "having",
1907            Expression::OrderBy(_) => "order_by",
1908            Expression::Limit(_) => "limit",
1909            Expression::Offset(_) => "offset",
1910            Expression::Qualify(_) => "qualify",
1911            Expression::With(_) => "with",
1912            Expression::Cte(_) => "cte",
1913            Expression::DistributeBy(_) => "distribute_by",
1914            Expression::ClusterBy(_) => "cluster_by",
1915            Expression::SortBy(_) => "sort_by",
1916            Expression::LateralView(_) => "lateral_view",
1917            Expression::Hint(_) => "hint",
1918            Expression::Pseudocolumn(_) => "pseudocolumn",
1919            Expression::Connect(_) => "connect",
1920            Expression::Prior(_) => "prior",
1921            Expression::ConnectByRoot(_) => "connect_by_root",
1922            Expression::MatchRecognize(_) => "match_recognize",
1923            Expression::Ordered(_) => "ordered",
1924            Expression::Window(_) => "window",
1925            Expression::Over(_) => "over",
1926            Expression::WithinGroup(_) => "within_group",
1927            Expression::DataType(_) => "data_type",
1928            Expression::Array(_) => "array",
1929            Expression::Struct(_) => "struct",
1930            Expression::Tuple(_) => "tuple",
1931            Expression::Interval(_) => "interval",
1932            Expression::ConcatWs(_) => "concat_ws",
1933            Expression::Substring(_) => "substring",
1934            Expression::Upper(_) => "upper",
1935            Expression::Lower(_) => "lower",
1936            Expression::Length(_) => "length",
1937            Expression::Trim(_) => "trim",
1938            Expression::LTrim(_) => "l_trim",
1939            Expression::RTrim(_) => "r_trim",
1940            Expression::Replace(_) => "replace",
1941            Expression::Reverse(_) => "reverse",
1942            Expression::Left(_) => "left",
1943            Expression::Right(_) => "right",
1944            Expression::Repeat(_) => "repeat",
1945            Expression::Lpad(_) => "lpad",
1946            Expression::Rpad(_) => "rpad",
1947            Expression::Split(_) => "split",
1948            Expression::RegexpLike(_) => "regexp_like",
1949            Expression::RegexpReplace(_) => "regexp_replace",
1950            Expression::RegexpExtract(_) => "regexp_extract",
1951            Expression::Overlay(_) => "overlay",
1952            Expression::Abs(_) => "abs",
1953            Expression::Round(_) => "round",
1954            Expression::Floor(_) => "floor",
1955            Expression::Ceil(_) => "ceil",
1956            Expression::Power(_) => "power",
1957            Expression::Sqrt(_) => "sqrt",
1958            Expression::Cbrt(_) => "cbrt",
1959            Expression::Ln(_) => "ln",
1960            Expression::Log(_) => "log",
1961            Expression::Exp(_) => "exp",
1962            Expression::Sign(_) => "sign",
1963            Expression::Greatest(_) => "greatest",
1964            Expression::Least(_) => "least",
1965            Expression::CurrentDate(_) => "current_date",
1966            Expression::CurrentTime(_) => "current_time",
1967            Expression::CurrentTimestamp(_) => "current_timestamp",
1968            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1969            Expression::AtTimeZone(_) => "at_time_zone",
1970            Expression::DateAdd(_) => "date_add",
1971            Expression::DateSub(_) => "date_sub",
1972            Expression::DateDiff(_) => "date_diff",
1973            Expression::DateTrunc(_) => "date_trunc",
1974            Expression::Extract(_) => "extract",
1975            Expression::ToDate(_) => "to_date",
1976            Expression::ToTimestamp(_) => "to_timestamp",
1977            Expression::Date(_) => "date",
1978            Expression::Time(_) => "time",
1979            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1980            Expression::UnixDate(_) => "unix_date",
1981            Expression::UnixSeconds(_) => "unix_seconds",
1982            Expression::UnixMillis(_) => "unix_millis",
1983            Expression::UnixMicros(_) => "unix_micros",
1984            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1985            Expression::TimeStrToDate(_) => "time_str_to_date",
1986            Expression::DateToDi(_) => "date_to_di",
1987            Expression::DiToDate(_) => "di_to_date",
1988            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1989            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1990            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1991            Expression::YearOfWeek(_) => "year_of_week",
1992            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1993            Expression::Coalesce(_) => "coalesce",
1994            Expression::NullIf(_) => "null_if",
1995            Expression::IfFunc(_) => "if_func",
1996            Expression::IfNull(_) => "if_null",
1997            Expression::Nvl(_) => "nvl",
1998            Expression::Nvl2(_) => "nvl2",
1999            Expression::TryCast(_) => "try_cast",
2000            Expression::SafeCast(_) => "safe_cast",
2001            Expression::Count(_) => "count",
2002            Expression::Sum(_) => "sum",
2003            Expression::Avg(_) => "avg",
2004            Expression::Min(_) => "min",
2005            Expression::Max(_) => "max",
2006            Expression::GroupConcat(_) => "group_concat",
2007            Expression::StringAgg(_) => "string_agg",
2008            Expression::ListAgg(_) => "list_agg",
2009            Expression::ArrayAgg(_) => "array_agg",
2010            Expression::CountIf(_) => "count_if",
2011            Expression::SumIf(_) => "sum_if",
2012            Expression::Stddev(_) => "stddev",
2013            Expression::StddevPop(_) => "stddev_pop",
2014            Expression::StddevSamp(_) => "stddev_samp",
2015            Expression::Variance(_) => "variance",
2016            Expression::VarPop(_) => "var_pop",
2017            Expression::VarSamp(_) => "var_samp",
2018            Expression::Median(_) => "median",
2019            Expression::Mode(_) => "mode",
2020            Expression::First(_) => "first",
2021            Expression::Last(_) => "last",
2022            Expression::AnyValue(_) => "any_value",
2023            Expression::ApproxDistinct(_) => "approx_distinct",
2024            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2025            Expression::ApproxPercentile(_) => "approx_percentile",
2026            Expression::Percentile(_) => "percentile",
2027            Expression::LogicalAnd(_) => "logical_and",
2028            Expression::LogicalOr(_) => "logical_or",
2029            Expression::Skewness(_) => "skewness",
2030            Expression::BitwiseCount(_) => "bitwise_count",
2031            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2032            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2033            Expression::BoolXorAgg(_) => "bool_xor_agg",
2034            Expression::RowNumber(_) => "row_number",
2035            Expression::Rank(_) => "rank",
2036            Expression::DenseRank(_) => "dense_rank",
2037            Expression::NTile(_) => "n_tile",
2038            Expression::Lead(_) => "lead",
2039            Expression::Lag(_) => "lag",
2040            Expression::FirstValue(_) => "first_value",
2041            Expression::LastValue(_) => "last_value",
2042            Expression::NthValue(_) => "nth_value",
2043            Expression::PercentRank(_) => "percent_rank",
2044            Expression::CumeDist(_) => "cume_dist",
2045            Expression::PercentileCont(_) => "percentile_cont",
2046            Expression::PercentileDisc(_) => "percentile_disc",
2047            Expression::Contains(_) => "contains",
2048            Expression::StartsWith(_) => "starts_with",
2049            Expression::EndsWith(_) => "ends_with",
2050            Expression::Position(_) => "position",
2051            Expression::Initcap(_) => "initcap",
2052            Expression::Ascii(_) => "ascii",
2053            Expression::Chr(_) => "chr",
2054            Expression::CharFunc(_) => "char_func",
2055            Expression::Soundex(_) => "soundex",
2056            Expression::Levenshtein(_) => "levenshtein",
2057            Expression::ByteLength(_) => "byte_length",
2058            Expression::Hex(_) => "hex",
2059            Expression::LowerHex(_) => "lower_hex",
2060            Expression::Unicode(_) => "unicode",
2061            Expression::ModFunc(_) => "mod_func",
2062            Expression::Random(_) => "random",
2063            Expression::Rand(_) => "rand",
2064            Expression::TruncFunc(_) => "trunc_func",
2065            Expression::Pi(_) => "pi",
2066            Expression::Radians(_) => "radians",
2067            Expression::Degrees(_) => "degrees",
2068            Expression::Sin(_) => "sin",
2069            Expression::Cos(_) => "cos",
2070            Expression::Tan(_) => "tan",
2071            Expression::Asin(_) => "asin",
2072            Expression::Acos(_) => "acos",
2073            Expression::Atan(_) => "atan",
2074            Expression::Atan2(_) => "atan2",
2075            Expression::IsNan(_) => "is_nan",
2076            Expression::IsInf(_) => "is_inf",
2077            Expression::IntDiv(_) => "int_div",
2078            Expression::Decode(_) => "decode",
2079            Expression::DateFormat(_) => "date_format",
2080            Expression::FormatDate(_) => "format_date",
2081            Expression::Year(_) => "year",
2082            Expression::Month(_) => "month",
2083            Expression::Day(_) => "day",
2084            Expression::Hour(_) => "hour",
2085            Expression::Minute(_) => "minute",
2086            Expression::Second(_) => "second",
2087            Expression::DayOfWeek(_) => "day_of_week",
2088            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2089            Expression::DayOfMonth(_) => "day_of_month",
2090            Expression::DayOfYear(_) => "day_of_year",
2091            Expression::WeekOfYear(_) => "week_of_year",
2092            Expression::Quarter(_) => "quarter",
2093            Expression::AddMonths(_) => "add_months",
2094            Expression::MonthsBetween(_) => "months_between",
2095            Expression::LastDay(_) => "last_day",
2096            Expression::NextDay(_) => "next_day",
2097            Expression::Epoch(_) => "epoch",
2098            Expression::EpochMs(_) => "epoch_ms",
2099            Expression::FromUnixtime(_) => "from_unixtime",
2100            Expression::UnixTimestamp(_) => "unix_timestamp",
2101            Expression::MakeDate(_) => "make_date",
2102            Expression::MakeTimestamp(_) => "make_timestamp",
2103            Expression::TimestampTrunc(_) => "timestamp_trunc",
2104            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2105            Expression::SessionUser(_) => "session_user",
2106            Expression::SHA(_) => "s_h_a",
2107            Expression::SHA1Digest(_) => "s_h_a1_digest",
2108            Expression::TimeToUnix(_) => "time_to_unix",
2109            Expression::ArrayFunc(_) => "array_func",
2110            Expression::ArrayLength(_) => "array_length",
2111            Expression::ArraySize(_) => "array_size",
2112            Expression::Cardinality(_) => "cardinality",
2113            Expression::ArrayContains(_) => "array_contains",
2114            Expression::ArrayPosition(_) => "array_position",
2115            Expression::ArrayAppend(_) => "array_append",
2116            Expression::ArrayPrepend(_) => "array_prepend",
2117            Expression::ArrayConcat(_) => "array_concat",
2118            Expression::ArraySort(_) => "array_sort",
2119            Expression::ArrayReverse(_) => "array_reverse",
2120            Expression::ArrayDistinct(_) => "array_distinct",
2121            Expression::ArrayJoin(_) => "array_join",
2122            Expression::ArrayToString(_) => "array_to_string",
2123            Expression::Unnest(_) => "unnest",
2124            Expression::Explode(_) => "explode",
2125            Expression::ExplodeOuter(_) => "explode_outer",
2126            Expression::ArrayFilter(_) => "array_filter",
2127            Expression::ArrayTransform(_) => "array_transform",
2128            Expression::ArrayFlatten(_) => "array_flatten",
2129            Expression::ArrayCompact(_) => "array_compact",
2130            Expression::ArrayIntersect(_) => "array_intersect",
2131            Expression::ArrayUnion(_) => "array_union",
2132            Expression::ArrayExcept(_) => "array_except",
2133            Expression::ArrayRemove(_) => "array_remove",
2134            Expression::ArrayZip(_) => "array_zip",
2135            Expression::Sequence(_) => "sequence",
2136            Expression::Generate(_) => "generate",
2137            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2138            Expression::ToArray(_) => "to_array",
2139            Expression::StarMap(_) => "star_map",
2140            Expression::StructFunc(_) => "struct_func",
2141            Expression::StructExtract(_) => "struct_extract",
2142            Expression::NamedStruct(_) => "named_struct",
2143            Expression::MapFunc(_) => "map_func",
2144            Expression::MapFromEntries(_) => "map_from_entries",
2145            Expression::MapFromArrays(_) => "map_from_arrays",
2146            Expression::MapKeys(_) => "map_keys",
2147            Expression::MapValues(_) => "map_values",
2148            Expression::MapContainsKey(_) => "map_contains_key",
2149            Expression::MapConcat(_) => "map_concat",
2150            Expression::ElementAt(_) => "element_at",
2151            Expression::TransformKeys(_) => "transform_keys",
2152            Expression::TransformValues(_) => "transform_values",
2153            Expression::FunctionEmits(_) => "function_emits",
2154            Expression::JsonExtract(_) => "json_extract",
2155            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2156            Expression::JsonExtractPath(_) => "json_extract_path",
2157            Expression::JsonArray(_) => "json_array",
2158            Expression::JsonObject(_) => "json_object",
2159            Expression::JsonQuery(_) => "json_query",
2160            Expression::JsonValue(_) => "json_value",
2161            Expression::JsonArrayLength(_) => "json_array_length",
2162            Expression::JsonKeys(_) => "json_keys",
2163            Expression::JsonType(_) => "json_type",
2164            Expression::ParseJson(_) => "parse_json",
2165            Expression::ToJson(_) => "to_json",
2166            Expression::JsonSet(_) => "json_set",
2167            Expression::JsonInsert(_) => "json_insert",
2168            Expression::JsonRemove(_) => "json_remove",
2169            Expression::JsonMergePatch(_) => "json_merge_patch",
2170            Expression::JsonArrayAgg(_) => "json_array_agg",
2171            Expression::JsonObjectAgg(_) => "json_object_agg",
2172            Expression::Convert(_) => "convert",
2173            Expression::Typeof(_) => "typeof",
2174            Expression::Lambda(_) => "lambda",
2175            Expression::Parameter(_) => "parameter",
2176            Expression::Placeholder(_) => "placeholder",
2177            Expression::NamedArgument(_) => "named_argument",
2178            Expression::TableArgument(_) => "table_argument",
2179            Expression::SqlComment(_) => "sql_comment",
2180            Expression::NullSafeEq(_) => "null_safe_eq",
2181            Expression::NullSafeNeq(_) => "null_safe_neq",
2182            Expression::Glob(_) => "glob",
2183            Expression::SimilarTo(_) => "similar_to",
2184            Expression::Any(_) => "any",
2185            Expression::All(_) => "all",
2186            Expression::Overlaps(_) => "overlaps",
2187            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2188            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2189            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2190            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2191            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2192            Expression::Subscript(_) => "subscript",
2193            Expression::Dot(_) => "dot",
2194            Expression::MethodCall(_) => "method_call",
2195            Expression::ArraySlice(_) => "array_slice",
2196            Expression::CreateTable(_) => "create_table",
2197            Expression::DropTable(_) => "drop_table",
2198            Expression::Undrop(_) => "undrop",
2199            Expression::AlterTable(_) => "alter_table",
2200            Expression::CreateIndex(_) => "create_index",
2201            Expression::DropIndex(_) => "drop_index",
2202            Expression::CreateView(_) => "create_view",
2203            Expression::DropView(_) => "drop_view",
2204            Expression::AlterView(_) => "alter_view",
2205            Expression::AlterIndex(_) => "alter_index",
2206            Expression::Truncate(_) => "truncate",
2207            Expression::Use(_) => "use",
2208            Expression::Cache(_) => "cache",
2209            Expression::Uncache(_) => "uncache",
2210            Expression::LoadData(_) => "load_data",
2211            Expression::Pragma(_) => "pragma",
2212            Expression::Grant(_) => "grant",
2213            Expression::Revoke(_) => "revoke",
2214            Expression::Comment(_) => "comment",
2215            Expression::SetStatement(_) => "set_statement",
2216            Expression::CreateSchema(_) => "create_schema",
2217            Expression::DropSchema(_) => "drop_schema",
2218            Expression::DropNamespace(_) => "drop_namespace",
2219            Expression::CreateDatabase(_) => "create_database",
2220            Expression::DropDatabase(_) => "drop_database",
2221            Expression::CreateFunction(_) => "create_function",
2222            Expression::DropFunction(_) => "drop_function",
2223            Expression::CreateProcedure(_) => "create_procedure",
2224            Expression::DropProcedure(_) => "drop_procedure",
2225            Expression::CreateSequence(_) => "create_sequence",
2226            Expression::CreateSynonym(_) => "create_synonym",
2227            Expression::DropSequence(_) => "drop_sequence",
2228            Expression::AlterSequence(_) => "alter_sequence",
2229            Expression::CreateTrigger(_) => "create_trigger",
2230            Expression::DropTrigger(_) => "drop_trigger",
2231            Expression::CreateType(_) => "create_type",
2232            Expression::DropType(_) => "drop_type",
2233            Expression::Describe(_) => "describe",
2234            Expression::Show(_) => "show",
2235            Expression::Command(_) => "command",
2236            Expression::TryCatch(_) => "try_catch",
2237            Expression::Kill(_) => "kill",
2238            Expression::Execute(_) => "execute",
2239            Expression::Raw(_) => "raw",
2240            Expression::CreateTask(_) => "create_task",
2241            Expression::Paren(_) => "paren",
2242            Expression::Annotated(_) => "annotated",
2243            Expression::Refresh(_) => "refresh",
2244            Expression::LockingStatement(_) => "locking_statement",
2245            Expression::SequenceProperties(_) => "sequence_properties",
2246            Expression::TruncateTable(_) => "truncate_table",
2247            Expression::Clone(_) => "clone",
2248            Expression::Attach(_) => "attach",
2249            Expression::Detach(_) => "detach",
2250            Expression::Install(_) => "install",
2251            Expression::Summarize(_) => "summarize",
2252            Expression::Declare(_) => "declare",
2253            Expression::DeclareItem(_) => "declare_item",
2254            Expression::Set(_) => "set",
2255            Expression::Heredoc(_) => "heredoc",
2256            Expression::SetItem(_) => "set_item",
2257            Expression::QueryBand(_) => "query_band",
2258            Expression::UserDefinedFunction(_) => "user_defined_function",
2259            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2260            Expression::ProjectionDef(_) => "projection_def",
2261            Expression::TableAlias(_) => "table_alias",
2262            Expression::ByteString(_) => "byte_string",
2263            Expression::HexStringExpr(_) => "hex_string_expr",
2264            Expression::UnicodeString(_) => "unicode_string",
2265            Expression::ColumnPosition(_) => "column_position",
2266            Expression::ColumnDef(_) => "column_def",
2267            Expression::AlterColumn(_) => "alter_column",
2268            Expression::AlterSortKey(_) => "alter_sort_key",
2269            Expression::AlterSet(_) => "alter_set",
2270            Expression::RenameColumn(_) => "rename_column",
2271            Expression::Comprehension(_) => "comprehension",
2272            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2273            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2274            Expression::IndexConstraintOption(_) => "index_constraint_option",
2275            Expression::ColumnConstraint(_) => "column_constraint",
2276            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2277            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2278            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2279            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2280            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2281            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2282            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2283            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2284            Expression::WithOperator(_) => "with_operator",
2285            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2286                "generated_as_identity_column_constraint"
2287            }
2288            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2289            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2290            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2291            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2292            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2293            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2294            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2295            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2296            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2297            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2298            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2299            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2300            Expression::PathColumnConstraint(_) => "path_column_constraint",
2301            Expression::Constraint(_) => "constraint",
2302            Expression::Export(_) => "export",
2303            Expression::Filter(_) => "filter",
2304            Expression::Changes(_) => "changes",
2305            Expression::CopyParameter(_) => "copy_parameter",
2306            Expression::Credentials(_) => "credentials",
2307            Expression::Directory(_) => "directory",
2308            Expression::ForeignKey(_) => "foreign_key",
2309            Expression::ColumnPrefix(_) => "column_prefix",
2310            Expression::PrimaryKey(_) => "primary_key",
2311            Expression::IntoClause(_) => "into_clause",
2312            Expression::JoinHint(_) => "join_hint",
2313            Expression::Opclass(_) => "opclass",
2314            Expression::Index(_) => "index",
2315            Expression::IndexParameters(_) => "index_parameters",
2316            Expression::ConditionalInsert(_) => "conditional_insert",
2317            Expression::MultitableInserts(_) => "multitable_inserts",
2318            Expression::OnConflict(_) => "on_conflict",
2319            Expression::OnCondition(_) => "on_condition",
2320            Expression::Returning(_) => "returning",
2321            Expression::Introducer(_) => "introducer",
2322            Expression::PartitionRange(_) => "partition_range",
2323            Expression::Fetch(_) => "fetch",
2324            Expression::Group(_) => "group",
2325            Expression::Cube(_) => "cube",
2326            Expression::Rollup(_) => "rollup",
2327            Expression::GroupingSets(_) => "grouping_sets",
2328            Expression::LimitOptions(_) => "limit_options",
2329            Expression::Lateral(_) => "lateral",
2330            Expression::TableFromRows(_) => "table_from_rows",
2331            Expression::RowsFrom(_) => "rows_from",
2332            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2333            Expression::WithFill(_) => "with_fill",
2334            Expression::Property(_) => "property",
2335            Expression::GrantPrivilege(_) => "grant_privilege",
2336            Expression::GrantPrincipal(_) => "grant_principal",
2337            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2338            Expression::AlgorithmProperty(_) => "algorithm_property",
2339            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2340            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2341            Expression::BackupProperty(_) => "backup_property",
2342            Expression::BuildProperty(_) => "build_property",
2343            Expression::BlockCompressionProperty(_) => "block_compression_property",
2344            Expression::CharacterSetProperty(_) => "character_set_property",
2345            Expression::ChecksumProperty(_) => "checksum_property",
2346            Expression::CollateProperty(_) => "collate_property",
2347            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2348            Expression::DataDeletionProperty(_) => "data_deletion_property",
2349            Expression::DefinerProperty(_) => "definer_property",
2350            Expression::DistKeyProperty(_) => "dist_key_property",
2351            Expression::DistributedByProperty(_) => "distributed_by_property",
2352            Expression::DistStyleProperty(_) => "dist_style_property",
2353            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2354            Expression::EngineProperty(_) => "engine_property",
2355            Expression::ToTableProperty(_) => "to_table_property",
2356            Expression::ExecuteAsProperty(_) => "execute_as_property",
2357            Expression::ExternalProperty(_) => "external_property",
2358            Expression::FallbackProperty(_) => "fallback_property",
2359            Expression::FileFormatProperty(_) => "file_format_property",
2360            Expression::CredentialsProperty(_) => "credentials_property",
2361            Expression::FreespaceProperty(_) => "freespace_property",
2362            Expression::InheritsProperty(_) => "inherits_property",
2363            Expression::InputModelProperty(_) => "input_model_property",
2364            Expression::OutputModelProperty(_) => "output_model_property",
2365            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2366            Expression::JournalProperty(_) => "journal_property",
2367            Expression::LanguageProperty(_) => "language_property",
2368            Expression::EnviromentProperty(_) => "enviroment_property",
2369            Expression::ClusteredByProperty(_) => "clustered_by_property",
2370            Expression::DictProperty(_) => "dict_property",
2371            Expression::DictRange(_) => "dict_range",
2372            Expression::OnCluster(_) => "on_cluster",
2373            Expression::LikeProperty(_) => "like_property",
2374            Expression::LocationProperty(_) => "location_property",
2375            Expression::LockProperty(_) => "lock_property",
2376            Expression::LockingProperty(_) => "locking_property",
2377            Expression::LogProperty(_) => "log_property",
2378            Expression::MaterializedProperty(_) => "materialized_property",
2379            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2380            Expression::OnProperty(_) => "on_property",
2381            Expression::OnCommitProperty(_) => "on_commit_property",
2382            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2383            Expression::PartitionByProperty(_) => "partition_by_property",
2384            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2385            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2386            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2387            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2388            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2389            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2390            Expression::PartitionList(_) => "partition_list",
2391            Expression::Partition(_) => "partition",
2392            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2393            Expression::UniqueKeyProperty(_) => "unique_key_property",
2394            Expression::RollupProperty(_) => "rollup_property",
2395            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2396            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2397            Expression::RemoteWithConnectionModelProperty(_) => {
2398                "remote_with_connection_model_property"
2399            }
2400            Expression::ReturnsProperty(_) => "returns_property",
2401            Expression::RowFormatProperty(_) => "row_format_property",
2402            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2403            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2404            Expression::QueryTransform(_) => "query_transform",
2405            Expression::SampleProperty(_) => "sample_property",
2406            Expression::SecurityProperty(_) => "security_property",
2407            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2408            Expression::SemanticView(_) => "semantic_view",
2409            Expression::SerdeProperties(_) => "serde_properties",
2410            Expression::SetProperty(_) => "set_property",
2411            Expression::SharingProperty(_) => "sharing_property",
2412            Expression::SetConfigProperty(_) => "set_config_property",
2413            Expression::SettingsProperty(_) => "settings_property",
2414            Expression::SortKeyProperty(_) => "sort_key_property",
2415            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2416            Expression::SqlSecurityProperty(_) => "sql_security_property",
2417            Expression::StabilityProperty(_) => "stability_property",
2418            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2419            Expression::TemporaryProperty(_) => "temporary_property",
2420            Expression::Tags(_) => "tags",
2421            Expression::TransformModelProperty(_) => "transform_model_property",
2422            Expression::TransientProperty(_) => "transient_property",
2423            Expression::UsingTemplateProperty(_) => "using_template_property",
2424            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2425            Expression::VolatileProperty(_) => "volatile_property",
2426            Expression::WithDataProperty(_) => "with_data_property",
2427            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2428            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2429            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2430            Expression::WithProcedureOptions(_) => "with_procedure_options",
2431            Expression::EncodeProperty(_) => "encode_property",
2432            Expression::IncludeProperty(_) => "include_property",
2433            Expression::Properties(_) => "properties",
2434            Expression::OptionsProperty(_) => "options_property",
2435            Expression::InputOutputFormat(_) => "input_output_format",
2436            Expression::Reference(_) => "reference",
2437            Expression::QueryOption(_) => "query_option",
2438            Expression::WithTableHint(_) => "with_table_hint",
2439            Expression::IndexTableHint(_) => "index_table_hint",
2440            Expression::HistoricalData(_) => "historical_data",
2441            Expression::Get(_) => "get",
2442            Expression::SetOperation(_) => "set_operation",
2443            Expression::Var(_) => "var",
2444            Expression::Variadic(_) => "variadic",
2445            Expression::Version(_) => "version",
2446            Expression::Schema(_) => "schema",
2447            Expression::Lock(_) => "lock",
2448            Expression::TableSample(_) => "table_sample",
2449            Expression::Tag(_) => "tag",
2450            Expression::UnpivotColumns(_) => "unpivot_columns",
2451            Expression::WindowSpec(_) => "window_spec",
2452            Expression::SessionParameter(_) => "session_parameter",
2453            Expression::PseudoType(_) => "pseudo_type",
2454            Expression::ObjectIdentifier(_) => "object_identifier",
2455            Expression::Transaction(_) => "transaction",
2456            Expression::Commit(_) => "commit",
2457            Expression::Rollback(_) => "rollback",
2458            Expression::AlterSession(_) => "alter_session",
2459            Expression::Analyze(_) => "analyze",
2460            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2461            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2462            Expression::AnalyzeSample(_) => "analyze_sample",
2463            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2464            Expression::AnalyzeDelete(_) => "analyze_delete",
2465            Expression::AnalyzeWith(_) => "analyze_with",
2466            Expression::AnalyzeValidate(_) => "analyze_validate",
2467            Expression::AddPartition(_) => "add_partition",
2468            Expression::AttachOption(_) => "attach_option",
2469            Expression::DropPartition(_) => "drop_partition",
2470            Expression::ReplacePartition(_) => "replace_partition",
2471            Expression::DPipe(_) => "d_pipe",
2472            Expression::Operator(_) => "operator",
2473            Expression::PivotAny(_) => "pivot_any",
2474            Expression::Aliases(_) => "aliases",
2475            Expression::AtIndex(_) => "at_index",
2476            Expression::FromTimeZone(_) => "from_time_zone",
2477            Expression::FormatPhrase(_) => "format_phrase",
2478            Expression::ForIn(_) => "for_in",
2479            Expression::TimeUnit(_) => "time_unit",
2480            Expression::IntervalOp(_) => "interval_op",
2481            Expression::IntervalSpan(_) => "interval_span",
2482            Expression::HavingMax(_) => "having_max",
2483            Expression::CosineDistance(_) => "cosine_distance",
2484            Expression::DotProduct(_) => "dot_product",
2485            Expression::EuclideanDistance(_) => "euclidean_distance",
2486            Expression::ManhattanDistance(_) => "manhattan_distance",
2487            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2488            Expression::Booland(_) => "booland",
2489            Expression::Boolor(_) => "boolor",
2490            Expression::ParameterizedAgg(_) => "parameterized_agg",
2491            Expression::ArgMax(_) => "arg_max",
2492            Expression::ArgMin(_) => "arg_min",
2493            Expression::ApproxTopK(_) => "approx_top_k",
2494            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2495            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2496            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2497            Expression::ApproxTopSum(_) => "approx_top_sum",
2498            Expression::ApproxQuantiles(_) => "approx_quantiles",
2499            Expression::Minhash(_) => "minhash",
2500            Expression::FarmFingerprint(_) => "farm_fingerprint",
2501            Expression::Float64(_) => "float64",
2502            Expression::Transform(_) => "transform",
2503            Expression::Translate(_) => "translate",
2504            Expression::Grouping(_) => "grouping",
2505            Expression::GroupingId(_) => "grouping_id",
2506            Expression::Anonymous(_) => "anonymous",
2507            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2508            Expression::CombinedAggFunc(_) => "combined_agg_func",
2509            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2510            Expression::HashAgg(_) => "hash_agg",
2511            Expression::Hll(_) => "hll",
2512            Expression::Apply(_) => "apply",
2513            Expression::ToBoolean(_) => "to_boolean",
2514            Expression::List(_) => "list",
2515            Expression::ToMap(_) => "to_map",
2516            Expression::Pad(_) => "pad",
2517            Expression::ToChar(_) => "to_char",
2518            Expression::ToNumber(_) => "to_number",
2519            Expression::ToDouble(_) => "to_double",
2520            Expression::Int64(_) => "int64",
2521            Expression::StringFunc(_) => "string_func",
2522            Expression::ToDecfloat(_) => "to_decfloat",
2523            Expression::TryToDecfloat(_) => "try_to_decfloat",
2524            Expression::ToFile(_) => "to_file",
2525            Expression::Columns(_) => "columns",
2526            Expression::ConvertToCharset(_) => "convert_to_charset",
2527            Expression::ConvertTimezone(_) => "convert_timezone",
2528            Expression::GenerateSeries(_) => "generate_series",
2529            Expression::AIAgg(_) => "a_i_agg",
2530            Expression::AIClassify(_) => "a_i_classify",
2531            Expression::ArrayAll(_) => "array_all",
2532            Expression::ArrayAny(_) => "array_any",
2533            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2534            Expression::StPoint(_) => "st_point",
2535            Expression::StDistance(_) => "st_distance",
2536            Expression::StringToArray(_) => "string_to_array",
2537            Expression::ArraySum(_) => "array_sum",
2538            Expression::ObjectAgg(_) => "object_agg",
2539            Expression::CastToStrType(_) => "cast_to_str_type",
2540            Expression::CheckJson(_) => "check_json",
2541            Expression::CheckXml(_) => "check_xml",
2542            Expression::TranslateCharacters(_) => "translate_characters",
2543            Expression::CurrentSchemas(_) => "current_schemas",
2544            Expression::CurrentDatetime(_) => "current_datetime",
2545            Expression::Localtime(_) => "localtime",
2546            Expression::Localtimestamp(_) => "localtimestamp",
2547            Expression::Systimestamp(_) => "systimestamp",
2548            Expression::CurrentSchema(_) => "current_schema",
2549            Expression::CurrentUser(_) => "current_user",
2550            Expression::UtcTime(_) => "utc_time",
2551            Expression::UtcTimestamp(_) => "utc_timestamp",
2552            Expression::Timestamp(_) => "timestamp",
2553            Expression::DateBin(_) => "date_bin",
2554            Expression::Datetime(_) => "datetime",
2555            Expression::DatetimeAdd(_) => "datetime_add",
2556            Expression::DatetimeSub(_) => "datetime_sub",
2557            Expression::DatetimeDiff(_) => "datetime_diff",
2558            Expression::DatetimeTrunc(_) => "datetime_trunc",
2559            Expression::Dayname(_) => "dayname",
2560            Expression::MakeInterval(_) => "make_interval",
2561            Expression::PreviousDay(_) => "previous_day",
2562            Expression::Elt(_) => "elt",
2563            Expression::TimestampAdd(_) => "timestamp_add",
2564            Expression::TimestampSub(_) => "timestamp_sub",
2565            Expression::TimestampDiff(_) => "timestamp_diff",
2566            Expression::TimeSlice(_) => "time_slice",
2567            Expression::TimeAdd(_) => "time_add",
2568            Expression::TimeSub(_) => "time_sub",
2569            Expression::TimeDiff(_) => "time_diff",
2570            Expression::TimeTrunc(_) => "time_trunc",
2571            Expression::DateFromParts(_) => "date_from_parts",
2572            Expression::TimeFromParts(_) => "time_from_parts",
2573            Expression::DecodeCase(_) => "decode_case",
2574            Expression::Decrypt(_) => "decrypt",
2575            Expression::DecryptRaw(_) => "decrypt_raw",
2576            Expression::Encode(_) => "encode",
2577            Expression::Encrypt(_) => "encrypt",
2578            Expression::EncryptRaw(_) => "encrypt_raw",
2579            Expression::EqualNull(_) => "equal_null",
2580            Expression::ToBinary(_) => "to_binary",
2581            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2582            Expression::Base64DecodeString(_) => "base64_decode_string",
2583            Expression::Base64Encode(_) => "base64_encode",
2584            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2585            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2586            Expression::GapFill(_) => "gap_fill",
2587            Expression::GenerateDateArray(_) => "generate_date_array",
2588            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2589            Expression::GetExtract(_) => "get_extract",
2590            Expression::Getbit(_) => "getbit",
2591            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2592            Expression::HexEncode(_) => "hex_encode",
2593            Expression::Compress(_) => "compress",
2594            Expression::DecompressBinary(_) => "decompress_binary",
2595            Expression::DecompressString(_) => "decompress_string",
2596            Expression::Xor(_) => "xor",
2597            Expression::Nullif(_) => "nullif",
2598            Expression::JSON(_) => "j_s_o_n",
2599            Expression::JSONPath(_) => "j_s_o_n_path",
2600            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2601            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2602            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2603            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2604            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2605            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2606            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2607            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2608            Expression::Format(_) => "format",
2609            Expression::JSONKeys(_) => "j_s_o_n_keys",
2610            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2611            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2612            Expression::JSONObject(_) => "j_s_o_n_object",
2613            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2614            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2615            Expression::JSONArray(_) => "j_s_o_n_array",
2616            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2617            Expression::JSONExists(_) => "j_s_o_n_exists",
2618            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2619            Expression::JSONSchema(_) => "j_s_o_n_schema",
2620            Expression::JSONSet(_) => "j_s_o_n_set",
2621            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2622            Expression::JSONValue(_) => "j_s_o_n_value",
2623            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2624            Expression::JSONRemove(_) => "j_s_o_n_remove",
2625            Expression::JSONTable(_) => "j_s_o_n_table",
2626            Expression::JSONType(_) => "j_s_o_n_type",
2627            Expression::ObjectInsert(_) => "object_insert",
2628            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2629            Expression::OpenJSON(_) => "open_j_s_o_n",
2630            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2631            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2632            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2633            Expression::JSONCast(_) => "j_s_o_n_cast",
2634            Expression::JSONExtract(_) => "j_s_o_n_extract",
2635            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2636            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2637            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2638            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2639            Expression::JSONFormat(_) => "j_s_o_n_format",
2640            Expression::JSONBool(_) => "j_s_o_n_bool",
2641            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2642            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2643            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2644            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2645            Expression::ParseJSON(_) => "parse_j_s_o_n",
2646            Expression::ParseUrl(_) => "parse_url",
2647            Expression::ParseIp(_) => "parse_ip",
2648            Expression::ParseTime(_) => "parse_time",
2649            Expression::ParseDatetime(_) => "parse_datetime",
2650            Expression::Map(_) => "map",
2651            Expression::MapCat(_) => "map_cat",
2652            Expression::MapDelete(_) => "map_delete",
2653            Expression::MapInsert(_) => "map_insert",
2654            Expression::MapPick(_) => "map_pick",
2655            Expression::ScopeResolution(_) => "scope_resolution",
2656            Expression::Slice(_) => "slice",
2657            Expression::VarMap(_) => "var_map",
2658            Expression::MatchAgainst(_) => "match_against",
2659            Expression::MD5Digest(_) => "m_d5_digest",
2660            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2661            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2662            Expression::Monthname(_) => "monthname",
2663            Expression::Ntile(_) => "ntile",
2664            Expression::Normalize(_) => "normalize",
2665            Expression::Normal(_) => "normal",
2666            Expression::Predict(_) => "predict",
2667            Expression::MLTranslate(_) => "m_l_translate",
2668            Expression::FeaturesAtTime(_) => "features_at_time",
2669            Expression::GenerateEmbedding(_) => "generate_embedding",
2670            Expression::MLForecast(_) => "m_l_forecast",
2671            Expression::ModelAttribute(_) => "model_attribute",
2672            Expression::VectorSearch(_) => "vector_search",
2673            Expression::Quantile(_) => "quantile",
2674            Expression::ApproxQuantile(_) => "approx_quantile",
2675            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2676            Expression::Randn(_) => "randn",
2677            Expression::Randstr(_) => "randstr",
2678            Expression::RangeN(_) => "range_n",
2679            Expression::RangeBucket(_) => "range_bucket",
2680            Expression::ReadCSV(_) => "read_c_s_v",
2681            Expression::ReadParquet(_) => "read_parquet",
2682            Expression::Reduce(_) => "reduce",
2683            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2684            Expression::RegexpILike(_) => "regexp_i_like",
2685            Expression::RegexpFullMatch(_) => "regexp_full_match",
2686            Expression::RegexpInstr(_) => "regexp_instr",
2687            Expression::RegexpSplit(_) => "regexp_split",
2688            Expression::RegexpCount(_) => "regexp_count",
2689            Expression::RegrValx(_) => "regr_valx",
2690            Expression::RegrValy(_) => "regr_valy",
2691            Expression::RegrAvgy(_) => "regr_avgy",
2692            Expression::RegrAvgx(_) => "regr_avgx",
2693            Expression::RegrCount(_) => "regr_count",
2694            Expression::RegrIntercept(_) => "regr_intercept",
2695            Expression::RegrR2(_) => "regr_r2",
2696            Expression::RegrSxx(_) => "regr_sxx",
2697            Expression::RegrSxy(_) => "regr_sxy",
2698            Expression::RegrSyy(_) => "regr_syy",
2699            Expression::RegrSlope(_) => "regr_slope",
2700            Expression::SafeAdd(_) => "safe_add",
2701            Expression::SafeDivide(_) => "safe_divide",
2702            Expression::SafeMultiply(_) => "safe_multiply",
2703            Expression::SafeSubtract(_) => "safe_subtract",
2704            Expression::SHA2(_) => "s_h_a2",
2705            Expression::SHA2Digest(_) => "s_h_a2_digest",
2706            Expression::SortArray(_) => "sort_array",
2707            Expression::SplitPart(_) => "split_part",
2708            Expression::SubstringIndex(_) => "substring_index",
2709            Expression::StandardHash(_) => "standard_hash",
2710            Expression::StrPosition(_) => "str_position",
2711            Expression::Search(_) => "search",
2712            Expression::SearchIp(_) => "search_ip",
2713            Expression::StrToDate(_) => "str_to_date",
2714            Expression::DateStrToDate(_) => "date_str_to_date",
2715            Expression::DateToDateStr(_) => "date_to_date_str",
2716            Expression::StrToTime(_) => "str_to_time",
2717            Expression::StrToUnix(_) => "str_to_unix",
2718            Expression::StrToMap(_) => "str_to_map",
2719            Expression::NumberToStr(_) => "number_to_str",
2720            Expression::FromBase(_) => "from_base",
2721            Expression::Stuff(_) => "stuff",
2722            Expression::TimeToStr(_) => "time_to_str",
2723            Expression::TimeStrToTime(_) => "time_str_to_time",
2724            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2725            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2726            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2727            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2728            Expression::Unhex(_) => "unhex",
2729            Expression::Uniform(_) => "uniform",
2730            Expression::UnixToStr(_) => "unix_to_str",
2731            Expression::UnixToTime(_) => "unix_to_time",
2732            Expression::Uuid(_) => "uuid",
2733            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2734            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2735            Expression::Corr(_) => "corr",
2736            Expression::WidthBucket(_) => "width_bucket",
2737            Expression::CovarSamp(_) => "covar_samp",
2738            Expression::CovarPop(_) => "covar_pop",
2739            Expression::Week(_) => "week",
2740            Expression::XMLElement(_) => "x_m_l_element",
2741            Expression::XMLGet(_) => "x_m_l_get",
2742            Expression::XMLTable(_) => "x_m_l_table",
2743            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2744            Expression::Zipf(_) => "zipf",
2745            Expression::Merge(_) => "merge",
2746            Expression::When(_) => "when",
2747            Expression::Whens(_) => "whens",
2748            Expression::NextValueFor(_) => "next_value_for",
2749            Expression::ReturnStmt(_) => "return_stmt",
2750        }
2751    }
2752
2753    /// Returns the primary child expression (".this" in sqlglot).
2754    pub fn get_this(&self) -> Option<&Expression> {
2755        match self {
2756            // Unary ops
2757            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2758            // UnaryFunc variants
2759            Expression::Upper(f)
2760            | Expression::Lower(f)
2761            | Expression::Length(f)
2762            | Expression::LTrim(f)
2763            | Expression::RTrim(f)
2764            | Expression::Reverse(f)
2765            | Expression::Abs(f)
2766            | Expression::Sqrt(f)
2767            | Expression::Cbrt(f)
2768            | Expression::Ln(f)
2769            | Expression::Exp(f)
2770            | Expression::Sign(f)
2771            | Expression::Date(f)
2772            | Expression::Time(f)
2773            | Expression::Initcap(f)
2774            | Expression::Ascii(f)
2775            | Expression::Chr(f)
2776            | Expression::Soundex(f)
2777            | Expression::ByteLength(f)
2778            | Expression::Hex(f)
2779            | Expression::LowerHex(f)
2780            | Expression::Unicode(f)
2781            | Expression::Typeof(f)
2782            | Expression::Explode(f)
2783            | Expression::ExplodeOuter(f)
2784            | Expression::MapFromEntries(f)
2785            | Expression::MapKeys(f)
2786            | Expression::MapValues(f)
2787            | Expression::ArrayLength(f)
2788            | Expression::ArraySize(f)
2789            | Expression::Cardinality(f)
2790            | Expression::ArrayReverse(f)
2791            | Expression::ArrayDistinct(f)
2792            | Expression::ArrayFlatten(f)
2793            | Expression::ArrayCompact(f)
2794            | Expression::ToArray(f)
2795            | Expression::JsonArrayLength(f)
2796            | Expression::JsonKeys(f)
2797            | Expression::JsonType(f)
2798            | Expression::ParseJson(f)
2799            | Expression::ToJson(f)
2800            | Expression::Radians(f)
2801            | Expression::Degrees(f)
2802            | Expression::Sin(f)
2803            | Expression::Cos(f)
2804            | Expression::Tan(f)
2805            | Expression::Asin(f)
2806            | Expression::Acos(f)
2807            | Expression::Atan(f)
2808            | Expression::IsNan(f)
2809            | Expression::IsInf(f)
2810            | Expression::Year(f)
2811            | Expression::Month(f)
2812            | Expression::Day(f)
2813            | Expression::Hour(f)
2814            | Expression::Minute(f)
2815            | Expression::Second(f)
2816            | Expression::DayOfWeek(f)
2817            | Expression::DayOfWeekIso(f)
2818            | Expression::DayOfMonth(f)
2819            | Expression::DayOfYear(f)
2820            | Expression::WeekOfYear(f)
2821            | Expression::Quarter(f)
2822            | Expression::Epoch(f)
2823            | Expression::EpochMs(f)
2824            | Expression::BitwiseCount(f)
2825            | Expression::DateFromUnixDate(f)
2826            | Expression::UnixDate(f)
2827            | Expression::UnixSeconds(f)
2828            | Expression::UnixMillis(f)
2829            | Expression::UnixMicros(f)
2830            | Expression::TimeStrToDate(f)
2831            | Expression::DateToDi(f)
2832            | Expression::DiToDate(f)
2833            | Expression::TsOrDiToDi(f)
2834            | Expression::TsOrDsToDatetime(f)
2835            | Expression::TsOrDsToTimestamp(f)
2836            | Expression::YearOfWeek(f)
2837            | Expression::YearOfWeekIso(f)
2838            | Expression::SHA(f)
2839            | Expression::SHA1Digest(f)
2840            | Expression::TimeToUnix(f)
2841            | Expression::TimeStrToUnix(f)
2842            | Expression::Int64(f)
2843            | Expression::JSONBool(f)
2844            | Expression::MD5NumberLower64(f)
2845            | Expression::MD5NumberUpper64(f)
2846            | Expression::DateStrToDate(f)
2847            | Expression::DateToDateStr(f) => Some(&f.this),
2848            // BinaryFunc - this is the primary child
2849            Expression::Power(f)
2850            | Expression::NullIf(f)
2851            | Expression::IfNull(f)
2852            | Expression::Nvl(f)
2853            | Expression::Contains(f)
2854            | Expression::StartsWith(f)
2855            | Expression::EndsWith(f)
2856            | Expression::Levenshtein(f)
2857            | Expression::ModFunc(f)
2858            | Expression::IntDiv(f)
2859            | Expression::Atan2(f)
2860            | Expression::AddMonths(f)
2861            | Expression::MonthsBetween(f)
2862            | Expression::NextDay(f)
2863            | Expression::UnixToTimeStr(f)
2864            | Expression::ArrayContains(f)
2865            | Expression::ArrayPosition(f)
2866            | Expression::ArrayAppend(f)
2867            | Expression::ArrayPrepend(f)
2868            | Expression::ArrayUnion(f)
2869            | Expression::ArrayExcept(f)
2870            | Expression::ArrayRemove(f)
2871            | Expression::StarMap(f)
2872            | Expression::MapFromArrays(f)
2873            | Expression::MapContainsKey(f)
2874            | Expression::ElementAt(f)
2875            | Expression::JsonMergePatch(f)
2876            | Expression::JSONBContains(f)
2877            | Expression::JSONBExtract(f) => Some(&f.this),
2878            // AggFunc - this is the primary child
2879            Expression::Sum(af)
2880            | Expression::Avg(af)
2881            | Expression::Min(af)
2882            | Expression::Max(af)
2883            | Expression::ArrayAgg(af)
2884            | Expression::CountIf(af)
2885            | Expression::Stddev(af)
2886            | Expression::StddevPop(af)
2887            | Expression::StddevSamp(af)
2888            | Expression::Variance(af)
2889            | Expression::VarPop(af)
2890            | Expression::VarSamp(af)
2891            | Expression::Median(af)
2892            | Expression::Mode(af)
2893            | Expression::First(af)
2894            | Expression::Last(af)
2895            | Expression::AnyValue(af)
2896            | Expression::ApproxDistinct(af)
2897            | Expression::ApproxCountDistinct(af)
2898            | Expression::LogicalAnd(af)
2899            | Expression::LogicalOr(af)
2900            | Expression::Skewness(af)
2901            | Expression::ArrayConcatAgg(af)
2902            | Expression::ArrayUniqueAgg(af)
2903            | Expression::BoolXorAgg(af)
2904            | Expression::BitwiseAndAgg(af)
2905            | Expression::BitwiseOrAgg(af)
2906            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2907            // Binary operations - left is "this" in sqlglot
2908            Expression::And(op)
2909            | Expression::Or(op)
2910            | Expression::Add(op)
2911            | Expression::Sub(op)
2912            | Expression::Mul(op)
2913            | Expression::Div(op)
2914            | Expression::Mod(op)
2915            | Expression::Eq(op)
2916            | Expression::Neq(op)
2917            | Expression::Lt(op)
2918            | Expression::Lte(op)
2919            | Expression::Gt(op)
2920            | Expression::Gte(op)
2921            | Expression::BitwiseAnd(op)
2922            | Expression::BitwiseOr(op)
2923            | Expression::BitwiseXor(op)
2924            | Expression::Concat(op)
2925            | Expression::Adjacent(op)
2926            | Expression::TsMatch(op)
2927            | Expression::PropertyEQ(op)
2928            | Expression::ArrayContainsAll(op)
2929            | Expression::ArrayContainedBy(op)
2930            | Expression::ArrayOverlaps(op)
2931            | Expression::JSONBContainsAllTopKeys(op)
2932            | Expression::JSONBContainsAnyTopKeys(op)
2933            | Expression::JSONBDeleteAtPath(op)
2934            | Expression::ExtendsLeft(op)
2935            | Expression::ExtendsRight(op)
2936            | Expression::Is(op)
2937            | Expression::MemberOf(op)
2938            | Expression::Match(op)
2939            | Expression::NullSafeEq(op)
2940            | Expression::NullSafeNeq(op)
2941            | Expression::Glob(op)
2942            | Expression::BitwiseLeftShift(op)
2943            | Expression::BitwiseRightShift(op) => Some(&op.left),
2944            // Like operations - left is "this"
2945            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2946            // Structural types with .this
2947            Expression::Alias(a) => Some(&a.this),
2948            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2949            Expression::Paren(p) => Some(&p.this),
2950            Expression::Annotated(a) => Some(&a.this),
2951            Expression::Subquery(s) => Some(&s.this),
2952            Expression::Where(w) => Some(&w.this),
2953            Expression::Having(h) => Some(&h.this),
2954            Expression::Qualify(q) => Some(&q.this),
2955            Expression::IsNull(i) => Some(&i.this),
2956            Expression::Exists(e) => Some(&e.this),
2957            Expression::Ordered(o) => Some(&o.this),
2958            Expression::WindowFunction(wf) => Some(&wf.this),
2959            Expression::Cte(cte) => Some(&cte.this),
2960            Expression::Between(b) => Some(&b.this),
2961            Expression::In(i) => Some(&i.this),
2962            Expression::ReturnStmt(e) => Some(e),
2963            _ => None,
2964        }
2965    }
2966
2967    /// Returns the secondary child expression (".expression" in sqlglot).
2968    pub fn get_expression(&self) -> Option<&Expression> {
2969        match self {
2970            // Binary operations - right is "expression"
2971            Expression::And(op)
2972            | Expression::Or(op)
2973            | Expression::Add(op)
2974            | Expression::Sub(op)
2975            | Expression::Mul(op)
2976            | Expression::Div(op)
2977            | Expression::Mod(op)
2978            | Expression::Eq(op)
2979            | Expression::Neq(op)
2980            | Expression::Lt(op)
2981            | Expression::Lte(op)
2982            | Expression::Gt(op)
2983            | Expression::Gte(op)
2984            | Expression::BitwiseAnd(op)
2985            | Expression::BitwiseOr(op)
2986            | Expression::BitwiseXor(op)
2987            | Expression::Concat(op)
2988            | Expression::Adjacent(op)
2989            | Expression::TsMatch(op)
2990            | Expression::PropertyEQ(op)
2991            | Expression::ArrayContainsAll(op)
2992            | Expression::ArrayContainedBy(op)
2993            | Expression::ArrayOverlaps(op)
2994            | Expression::JSONBContainsAllTopKeys(op)
2995            | Expression::JSONBContainsAnyTopKeys(op)
2996            | Expression::JSONBDeleteAtPath(op)
2997            | Expression::ExtendsLeft(op)
2998            | Expression::ExtendsRight(op)
2999            | Expression::Is(op)
3000            | Expression::MemberOf(op)
3001            | Expression::Match(op)
3002            | Expression::NullSafeEq(op)
3003            | Expression::NullSafeNeq(op)
3004            | Expression::Glob(op)
3005            | Expression::BitwiseLeftShift(op)
3006            | Expression::BitwiseRightShift(op) => Some(&op.right),
3007            // Like operations - right is "expression"
3008            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3009            // BinaryFunc - expression is the secondary
3010            Expression::Power(f)
3011            | Expression::NullIf(f)
3012            | Expression::IfNull(f)
3013            | Expression::Nvl(f)
3014            | Expression::Contains(f)
3015            | Expression::StartsWith(f)
3016            | Expression::EndsWith(f)
3017            | Expression::Levenshtein(f)
3018            | Expression::ModFunc(f)
3019            | Expression::IntDiv(f)
3020            | Expression::Atan2(f)
3021            | Expression::AddMonths(f)
3022            | Expression::MonthsBetween(f)
3023            | Expression::NextDay(f)
3024            | Expression::UnixToTimeStr(f)
3025            | Expression::ArrayContains(f)
3026            | Expression::ArrayPosition(f)
3027            | Expression::ArrayAppend(f)
3028            | Expression::ArrayPrepend(f)
3029            | Expression::ArrayUnion(f)
3030            | Expression::ArrayExcept(f)
3031            | Expression::ArrayRemove(f)
3032            | Expression::StarMap(f)
3033            | Expression::MapFromArrays(f)
3034            | Expression::MapContainsKey(f)
3035            | Expression::ElementAt(f)
3036            | Expression::JsonMergePatch(f)
3037            | Expression::JSONBContains(f)
3038            | Expression::JSONBExtract(f) => Some(&f.expression),
3039            _ => None,
3040        }
3041    }
3042
3043    /// Returns the list of child expressions (".expressions" in sqlglot).
3044    pub fn get_expressions(&self) -> &[Expression] {
3045        match self {
3046            Expression::Select(s) => &s.expressions,
3047            Expression::Function(f) => &f.args,
3048            Expression::AggregateFunction(f) => &f.args,
3049            Expression::From(f) => &f.expressions,
3050            Expression::GroupBy(g) => &g.expressions,
3051            Expression::In(i) => &i.expressions,
3052            Expression::Array(a) => &a.expressions,
3053            Expression::Tuple(t) => &t.expressions,
3054            Expression::Coalesce(f)
3055            | Expression::Greatest(f)
3056            | Expression::Least(f)
3057            | Expression::ArrayConcat(f)
3058            | Expression::ArrayIntersect(f)
3059            | Expression::ArrayZip(f)
3060            | Expression::MapConcat(f)
3061            | Expression::JsonArray(f) => &f.expressions,
3062            _ => &[],
3063        }
3064    }
3065
3066    /// Returns the name of this expression as a string slice.
3067    pub fn get_name(&self) -> &str {
3068        match self {
3069            Expression::Identifier(id) => &id.name,
3070            Expression::Column(col) => &col.name.name,
3071            Expression::Table(t) => &t.name.name,
3072            Expression::Literal(lit) => lit.value_str(),
3073            Expression::Star(_) => "*",
3074            Expression::Function(f) => &f.name,
3075            Expression::AggregateFunction(f) => &f.name,
3076            Expression::Alias(a) => a.this.get_name(),
3077            Expression::Boolean(b) => {
3078                if b.value {
3079                    "TRUE"
3080                } else {
3081                    "FALSE"
3082                }
3083            }
3084            Expression::Null(_) => "NULL",
3085            _ => "",
3086        }
3087    }
3088
3089    /// Returns the alias name if this expression has one.
3090    pub fn get_alias(&self) -> &str {
3091        match self {
3092            Expression::Alias(a) => &a.alias.name,
3093            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3094            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3095            _ => "",
3096        }
3097    }
3098
3099    /// Returns the output name of this expression (what it shows up as in a SELECT).
3100    pub fn get_output_name(&self) -> &str {
3101        match self {
3102            Expression::Alias(a) => &a.alias.name,
3103            Expression::Column(c) => &c.name.name,
3104            Expression::Identifier(id) => &id.name,
3105            Expression::Literal(lit) => lit.value_str(),
3106            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3107            Expression::Star(_) => "*",
3108            _ => "",
3109        }
3110    }
3111
3112    /// Returns comments attached to this expression.
3113    pub fn get_comments(&self) -> Vec<&str> {
3114        match self {
3115            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3116            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3117            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3118            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3119            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3120            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3121            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3122                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3123            }
3124            Expression::And(op)
3125            | Expression::Or(op)
3126            | Expression::Add(op)
3127            | Expression::Sub(op)
3128            | Expression::Mul(op)
3129            | Expression::Div(op)
3130            | Expression::Mod(op)
3131            | Expression::Eq(op)
3132            | Expression::Neq(op)
3133            | Expression::Lt(op)
3134            | Expression::Lte(op)
3135            | Expression::Gt(op)
3136            | Expression::Gte(op)
3137            | Expression::Concat(op)
3138            | Expression::BitwiseAnd(op)
3139            | Expression::BitwiseOr(op)
3140            | Expression::BitwiseXor(op) => {
3141                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3142            }
3143            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3144            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3145            _ => Vec::new(),
3146        }
3147    }
3148}
3149
3150impl fmt::Display for Expression {
3151    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3152        // Basic display - full SQL generation is in generator module
3153        match self {
3154            Expression::Literal(lit) => write!(f, "{}", lit),
3155            Expression::Identifier(id) => write!(f, "{}", id),
3156            Expression::Column(col) => write!(f, "{}", col),
3157            Expression::Star(_) => write!(f, "*"),
3158            Expression::Null(_) => write!(f, "NULL"),
3159            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3160            Expression::Select(_) => write!(f, "SELECT ..."),
3161            _ => write!(f, "{:?}", self),
3162        }
3163    }
3164}
3165
3166/// Represent a SQL literal value.
3167///
3168/// Numeric values are stored as their original text representation (not parsed
3169/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3170/// preserved across round-trips.
3171///
3172/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3173/// strings, raw strings, etc.) each have a dedicated variant so that the
3174/// generator can emit them with the correct syntax.
3175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3176#[cfg_attr(feature = "bindings", derive(TS))]
3177#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3178pub enum Literal {
3179    /// Single-quoted string literal: `'hello'`
3180    String(String),
3181    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3182    Number(String),
3183    /// Hex string literal: `X'FF'`
3184    HexString(String),
3185    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3186    HexNumber(String),
3187    BitString(String),
3188    /// Byte string: b"..." (BigQuery style)
3189    ByteString(String),
3190    /// National string: N'abc'
3191    NationalString(String),
3192    /// DATE literal: DATE '2024-01-15'
3193    Date(String),
3194    /// TIME literal: TIME '10:30:00'
3195    Time(String),
3196    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3197    Timestamp(String),
3198    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3199    Datetime(String),
3200    /// Triple-quoted string: """...""" or '''...'''
3201    /// Contains (content, quote_char) where quote_char is '"' or '\''
3202    TripleQuotedString(String, char),
3203    /// Escape string: E'...' (PostgreSQL)
3204    EscapeString(String),
3205    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3206    DollarString(String),
3207    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3208    /// In raw strings, backslashes are literal and not escape characters.
3209    /// When converting to a regular string, backslashes must be doubled.
3210    RawString(String),
3211}
3212
3213impl Literal {
3214    /// Returns the inner value as a string slice, regardless of literal type.
3215    pub fn value_str(&self) -> &str {
3216        match self {
3217            Literal::String(s)
3218            | Literal::Number(s)
3219            | Literal::HexString(s)
3220            | Literal::HexNumber(s)
3221            | Literal::BitString(s)
3222            | Literal::ByteString(s)
3223            | Literal::NationalString(s)
3224            | Literal::Date(s)
3225            | Literal::Time(s)
3226            | Literal::Timestamp(s)
3227            | Literal::Datetime(s)
3228            | Literal::EscapeString(s)
3229            | Literal::DollarString(s)
3230            | Literal::RawString(s) => s.as_str(),
3231            Literal::TripleQuotedString(s, _) => s.as_str(),
3232        }
3233    }
3234
3235    /// Returns `true` if this is a string-type literal.
3236    pub fn is_string(&self) -> bool {
3237        matches!(
3238            self,
3239            Literal::String(_)
3240                | Literal::NationalString(_)
3241                | Literal::EscapeString(_)
3242                | Literal::DollarString(_)
3243                | Literal::RawString(_)
3244                | Literal::TripleQuotedString(_, _)
3245        )
3246    }
3247
3248    /// Returns `true` if this is a numeric literal.
3249    pub fn is_number(&self) -> bool {
3250        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3251    }
3252}
3253
3254impl fmt::Display for Literal {
3255    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3256        match self {
3257            Literal::String(s) => write!(f, "'{}'", s),
3258            Literal::Number(n) => write!(f, "{}", n),
3259            Literal::HexString(h) => write!(f, "X'{}'", h),
3260            Literal::HexNumber(h) => write!(f, "0x{}", h),
3261            Literal::BitString(b) => write!(f, "B'{}'", b),
3262            Literal::ByteString(b) => write!(f, "b'{}'", b),
3263            Literal::NationalString(s) => write!(f, "N'{}'", s),
3264            Literal::Date(d) => write!(f, "DATE '{}'", d),
3265            Literal::Time(t) => write!(f, "TIME '{}'", t),
3266            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3267            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3268            Literal::TripleQuotedString(s, q) => {
3269                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3270            }
3271            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3272            Literal::DollarString(s) => write!(f, "$${}$$", s),
3273            Literal::RawString(s) => write!(f, "r'{}'", s),
3274        }
3275    }
3276}
3277
3278/// Boolean literal
3279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3280#[cfg_attr(feature = "bindings", derive(TS))]
3281pub struct BooleanLiteral {
3282    pub value: bool,
3283}
3284
3285/// NULL literal
3286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3287#[cfg_attr(feature = "bindings", derive(TS))]
3288pub struct Null;
3289
3290/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3291///
3292/// The `quoted` flag indicates whether the identifier was originally delimited
3293/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3294/// dialect). The generator uses this flag to decide whether to emit quoting
3295/// characters.
3296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3297#[cfg_attr(feature = "bindings", derive(TS))]
3298pub struct Identifier {
3299    /// The raw text of the identifier, without any quoting characters.
3300    pub name: String,
3301    /// Whether the identifier was quoted in the source SQL.
3302    pub quoted: bool,
3303    #[serde(default)]
3304    pub trailing_comments: Vec<String>,
3305    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3306    #[serde(default, skip_serializing_if = "Option::is_none")]
3307    pub span: Option<Span>,
3308}
3309
3310impl Identifier {
3311    pub fn new(name: impl Into<String>) -> Self {
3312        Self {
3313            name: name.into(),
3314            quoted: false,
3315            trailing_comments: Vec::new(),
3316            span: None,
3317        }
3318    }
3319
3320    pub fn quoted(name: impl Into<String>) -> Self {
3321        Self {
3322            name: name.into(),
3323            quoted: true,
3324            trailing_comments: Vec::new(),
3325            span: None,
3326        }
3327    }
3328
3329    pub fn empty() -> Self {
3330        Self {
3331            name: String::new(),
3332            quoted: false,
3333            trailing_comments: Vec::new(),
3334            span: None,
3335        }
3336    }
3337
3338    pub fn is_empty(&self) -> bool {
3339        self.name.is_empty()
3340    }
3341
3342    /// Set the source span on this identifier
3343    pub fn with_span(mut self, span: Span) -> Self {
3344        self.span = Some(span);
3345        self
3346    }
3347}
3348
3349impl fmt::Display for Identifier {
3350    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3351        if self.quoted {
3352            write!(f, "\"{}\"", self.name)
3353        } else {
3354            write!(f, "{}", self.name)
3355        }
3356    }
3357}
3358
3359/// Represent a column reference, optionally qualified by a table name.
3360///
3361/// Renders as `name` when unqualified, or `table.name` when qualified.
3362/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3363/// convenient construction.
3364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3365#[cfg_attr(feature = "bindings", derive(TS))]
3366pub struct Column {
3367    /// The column name.
3368    pub name: Identifier,
3369    /// Optional table qualifier (e.g. `t` in `t.col`).
3370    pub table: Option<Identifier>,
3371    /// Oracle-style join marker (+) for outer joins
3372    #[serde(default)]
3373    pub join_mark: bool,
3374    /// Trailing comments that appeared after this column reference
3375    #[serde(default)]
3376    pub trailing_comments: Vec<String>,
3377    /// Source position span
3378    #[serde(default, skip_serializing_if = "Option::is_none")]
3379    pub span: Option<Span>,
3380    /// Inferred data type from type annotation
3381    #[serde(default, skip_serializing_if = "Option::is_none")]
3382    pub inferred_type: Option<DataType>,
3383}
3384
3385impl fmt::Display for Column {
3386    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3387        if let Some(table) = &self.table {
3388            write!(f, "{}.{}", table, self.name)
3389        } else {
3390            write!(f, "{}", self.name)
3391        }
3392    }
3393}
3394
3395/// Represent a table reference with optional schema and catalog qualifiers.
3396///
3397/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3398/// which qualifiers are present. Supports aliases, column alias lists,
3399/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3400/// several other dialect-specific extensions.
3401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3402#[cfg_attr(feature = "bindings", derive(TS))]
3403pub struct TableRef {
3404    /// The unqualified table name.
3405    pub name: Identifier,
3406    /// Optional schema qualifier (e.g. `public` in `public.users`).
3407    pub schema: Option<Identifier>,
3408    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3409    pub catalog: Option<Identifier>,
3410    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3411    pub alias: Option<Identifier>,
3412    /// Whether AS keyword was explicitly used for the alias
3413    #[serde(default)]
3414    pub alias_explicit_as: bool,
3415    /// Column aliases for table alias: AS t(c1, c2)
3416    #[serde(default)]
3417    pub column_aliases: Vec<Identifier>,
3418    /// Leading comments that appeared before this table reference in a FROM clause
3419    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3420    pub leading_comments: Vec<String>,
3421    /// Trailing comments that appeared after this table reference
3422    #[serde(default)]
3423    pub trailing_comments: Vec<String>,
3424    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3425    #[serde(default)]
3426    pub when: Option<Box<HistoricalData>>,
3427    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3428    #[serde(default)]
3429    pub only: bool,
3430    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3431    #[serde(default)]
3432    pub final_: bool,
3433    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3434    #[serde(default, skip_serializing_if = "Option::is_none")]
3435    pub table_sample: Option<Box<Sample>>,
3436    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3437    #[serde(default)]
3438    pub hints: Vec<Expression>,
3439    /// TSQL: FOR SYSTEM_TIME temporal clause
3440    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3441    #[serde(default, skip_serializing_if = "Option::is_none")]
3442    pub system_time: Option<String>,
3443    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3444    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3445    pub partitions: Vec<Identifier>,
3446    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3447    /// When set, this is used instead of the name field
3448    #[serde(default, skip_serializing_if = "Option::is_none")]
3449    pub identifier_func: Option<Box<Expression>>,
3450    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3451    #[serde(default, skip_serializing_if = "Option::is_none")]
3452    pub changes: Option<Box<Changes>>,
3453    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3454    #[serde(default, skip_serializing_if = "Option::is_none")]
3455    pub version: Option<Box<Version>>,
3456    /// Source position span
3457    #[serde(default, skip_serializing_if = "Option::is_none")]
3458    pub span: Option<Span>,
3459}
3460
3461impl TableRef {
3462    pub fn new(name: impl Into<String>) -> Self {
3463        Self {
3464            name: Identifier::new(name),
3465            schema: None,
3466            catalog: None,
3467            alias: None,
3468            alias_explicit_as: false,
3469            column_aliases: Vec::new(),
3470            leading_comments: Vec::new(),
3471            trailing_comments: Vec::new(),
3472            when: None,
3473            only: false,
3474            final_: false,
3475            table_sample: None,
3476            hints: Vec::new(),
3477            system_time: None,
3478            partitions: Vec::new(),
3479            identifier_func: None,
3480            changes: None,
3481            version: None,
3482            span: None,
3483        }
3484    }
3485
3486    /// Create with a schema qualifier.
3487    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3488        let mut t = Self::new(name);
3489        t.schema = Some(Identifier::new(schema));
3490        t
3491    }
3492
3493    /// Create with catalog and schema qualifiers.
3494    pub fn new_with_catalog(
3495        name: impl Into<String>,
3496        schema: impl Into<String>,
3497        catalog: impl Into<String>,
3498    ) -> Self {
3499        let mut t = Self::new(name);
3500        t.schema = Some(Identifier::new(schema));
3501        t.catalog = Some(Identifier::new(catalog));
3502        t
3503    }
3504
3505    /// Create from an Identifier, preserving the quoted flag
3506    pub fn from_identifier(name: Identifier) -> Self {
3507        Self {
3508            name,
3509            schema: None,
3510            catalog: None,
3511            alias: None,
3512            alias_explicit_as: false,
3513            column_aliases: Vec::new(),
3514            leading_comments: Vec::new(),
3515            trailing_comments: Vec::new(),
3516            when: None,
3517            only: false,
3518            final_: false,
3519            table_sample: None,
3520            hints: Vec::new(),
3521            system_time: None,
3522            partitions: Vec::new(),
3523            identifier_func: None,
3524            changes: None,
3525            version: None,
3526            span: None,
3527        }
3528    }
3529
3530    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3531        self.alias = Some(Identifier::new(alias));
3532        self
3533    }
3534
3535    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3536        self.schema = Some(Identifier::new(schema));
3537        self
3538    }
3539}
3540
3541/// Represent a wildcard star expression (`*`, `table.*`).
3542///
3543/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3544/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3546#[cfg_attr(feature = "bindings", derive(TS))]
3547pub struct Star {
3548    /// Optional table qualifier (e.g. `t` in `t.*`).
3549    pub table: Option<Identifier>,
3550    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3551    pub except: Option<Vec<Identifier>>,
3552    /// REPLACE expressions (BigQuery, Snowflake)
3553    pub replace: Option<Vec<Alias>>,
3554    /// RENAME columns (Snowflake)
3555    pub rename: Option<Vec<(Identifier, Identifier)>>,
3556    /// Trailing comments that appeared after the star
3557    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3558    pub trailing_comments: Vec<String>,
3559    /// Source position span
3560    #[serde(default, skip_serializing_if = "Option::is_none")]
3561    pub span: Option<Span>,
3562}
3563
3564/// Represent a complete SELECT statement.
3565///
3566/// This is the most feature-rich AST node, covering the full surface area of
3567/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3568/// `Vec` are omitted from the generated SQL when absent.
3569///
3570/// # Key Fields
3571///
3572/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3573/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3574/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3575/// - `where_clause` -- the WHERE predicate.
3576/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3577/// - `having` -- HAVING predicate.
3578/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3579/// - `limit` / `offset` / `fetch` -- result set limiting.
3580/// - `with` -- Common Table Expressions (CTEs).
3581/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3582/// - `windows` -- named window definitions (WINDOW w AS ...).
3583///
3584/// Dialect-specific extensions are supported via fields like `prewhere`
3585/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3586/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3588#[cfg_attr(feature = "bindings", derive(TS))]
3589pub struct Select {
3590    /// The select-list: columns, expressions, aliases, and wildcards.
3591    pub expressions: Vec<Expression>,
3592    /// The FROM clause, containing one or more table sources.
3593    pub from: Option<From>,
3594    /// JOIN clauses applied after the FROM source.
3595    pub joins: Vec<Join>,
3596    pub lateral_views: Vec<LateralView>,
3597    /// ClickHouse PREWHERE clause
3598    #[serde(default, skip_serializing_if = "Option::is_none")]
3599    pub prewhere: Option<Expression>,
3600    pub where_clause: Option<Where>,
3601    pub group_by: Option<GroupBy>,
3602    pub having: Option<Having>,
3603    pub qualify: Option<Qualify>,
3604    pub order_by: Option<OrderBy>,
3605    pub distribute_by: Option<DistributeBy>,
3606    pub cluster_by: Option<ClusterBy>,
3607    pub sort_by: Option<SortBy>,
3608    pub limit: Option<Limit>,
3609    pub offset: Option<Offset>,
3610    /// ClickHouse LIMIT BY clause expressions
3611    #[serde(default, skip_serializing_if = "Option::is_none")]
3612    pub limit_by: Option<Vec<Expression>>,
3613    pub fetch: Option<Fetch>,
3614    pub distinct: bool,
3615    pub distinct_on: Option<Vec<Expression>>,
3616    pub top: Option<Top>,
3617    pub with: Option<With>,
3618    pub sample: Option<Sample>,
3619    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3620    #[serde(default, skip_serializing_if = "Option::is_none")]
3621    pub settings: Option<Vec<Expression>>,
3622    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3623    #[serde(default, skip_serializing_if = "Option::is_none")]
3624    pub format: Option<Expression>,
3625    pub windows: Option<Vec<NamedWindow>>,
3626    pub hint: Option<Hint>,
3627    /// Oracle CONNECT BY clause for hierarchical queries
3628    pub connect: Option<Connect>,
3629    /// SELECT ... INTO table_name for creating tables
3630    pub into: Option<SelectInto>,
3631    /// FOR UPDATE/SHARE locking clauses
3632    #[serde(default)]
3633    pub locks: Vec<Lock>,
3634    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3635    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3636    pub for_xml: Vec<Expression>,
3637    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3638    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3639    pub for_json: Vec<Expression>,
3640    /// Leading comments before the statement
3641    #[serde(default)]
3642    pub leading_comments: Vec<String>,
3643    /// Comments that appear after SELECT keyword (before expressions)
3644    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3645    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3646    pub post_select_comments: Vec<String>,
3647    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3648    #[serde(default, skip_serializing_if = "Option::is_none")]
3649    pub kind: Option<String>,
3650    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3651    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3652    pub operation_modifiers: Vec<String>,
3653    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3654    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3655    pub qualify_after_window: bool,
3656    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3657    #[serde(default, skip_serializing_if = "Option::is_none")]
3658    pub option: Option<String>,
3659    /// Redshift-style EXCLUDE clause at the end of the projection list
3660    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3661    #[serde(default, skip_serializing_if = "Option::is_none")]
3662    pub exclude: Option<Vec<Expression>>,
3663}
3664
3665impl Select {
3666    pub fn new() -> Self {
3667        Self {
3668            expressions: Vec::new(),
3669            from: None,
3670            joins: Vec::new(),
3671            lateral_views: Vec::new(),
3672            prewhere: None,
3673            where_clause: None,
3674            group_by: None,
3675            having: None,
3676            qualify: None,
3677            order_by: None,
3678            distribute_by: None,
3679            cluster_by: None,
3680            sort_by: None,
3681            limit: None,
3682            offset: None,
3683            limit_by: None,
3684            fetch: None,
3685            distinct: false,
3686            distinct_on: None,
3687            top: None,
3688            with: None,
3689            sample: None,
3690            settings: None,
3691            format: None,
3692            windows: None,
3693            hint: None,
3694            connect: None,
3695            into: None,
3696            locks: Vec::new(),
3697            for_xml: Vec::new(),
3698            for_json: Vec::new(),
3699            leading_comments: Vec::new(),
3700            post_select_comments: Vec::new(),
3701            kind: None,
3702            operation_modifiers: Vec::new(),
3703            qualify_after_window: false,
3704            option: None,
3705            exclude: None,
3706        }
3707    }
3708
3709    /// Add a column to select
3710    pub fn column(mut self, expr: Expression) -> Self {
3711        self.expressions.push(expr);
3712        self
3713    }
3714
3715    /// Set the FROM clause
3716    pub fn from(mut self, table: Expression) -> Self {
3717        self.from = Some(From {
3718            expressions: vec![table],
3719        });
3720        self
3721    }
3722
3723    /// Add a WHERE clause
3724    pub fn where_(mut self, condition: Expression) -> Self {
3725        self.where_clause = Some(Where { this: condition });
3726        self
3727    }
3728
3729    /// Set DISTINCT
3730    pub fn distinct(mut self) -> Self {
3731        self.distinct = true;
3732        self
3733    }
3734
3735    /// Add a JOIN
3736    pub fn join(mut self, join: Join) -> Self {
3737        self.joins.push(join);
3738        self
3739    }
3740
3741    /// Set ORDER BY
3742    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3743        self.order_by = Some(OrderBy {
3744            expressions,
3745            siblings: false,
3746            comments: Vec::new(),
3747        });
3748        self
3749    }
3750
3751    /// Set LIMIT
3752    pub fn limit(mut self, n: Expression) -> Self {
3753        self.limit = Some(Limit {
3754            this: n,
3755            percent: false,
3756            comments: Vec::new(),
3757        });
3758        self
3759    }
3760
3761    /// Set OFFSET
3762    pub fn offset(mut self, n: Expression) -> Self {
3763        self.offset = Some(Offset {
3764            this: n,
3765            rows: None,
3766        });
3767        self
3768    }
3769}
3770
3771impl Default for Select {
3772    fn default() -> Self {
3773        Self::new()
3774    }
3775}
3776
3777/// Represent a UNION set operation between two query expressions.
3778///
3779/// When `all` is true, duplicate rows are preserved (UNION ALL).
3780/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3781/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3783#[cfg_attr(feature = "bindings", derive(TS))]
3784pub struct Union {
3785    /// The left-hand query operand.
3786    pub left: Expression,
3787    /// The right-hand query operand.
3788    pub right: Expression,
3789    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3790    pub all: bool,
3791    /// Whether DISTINCT was explicitly specified
3792    #[serde(default)]
3793    pub distinct: bool,
3794    /// Optional WITH clause
3795    pub with: Option<With>,
3796    /// ORDER BY applied to entire UNION result
3797    pub order_by: Option<OrderBy>,
3798    /// LIMIT applied to entire UNION result
3799    pub limit: Option<Box<Expression>>,
3800    /// OFFSET applied to entire UNION result
3801    pub offset: Option<Box<Expression>>,
3802    /// DISTRIBUTE BY clause (Hive/Spark)
3803    #[serde(default, skip_serializing_if = "Option::is_none")]
3804    pub distribute_by: Option<DistributeBy>,
3805    /// SORT BY clause (Hive/Spark)
3806    #[serde(default, skip_serializing_if = "Option::is_none")]
3807    pub sort_by: Option<SortBy>,
3808    /// CLUSTER BY clause (Hive/Spark)
3809    #[serde(default, skip_serializing_if = "Option::is_none")]
3810    pub cluster_by: Option<ClusterBy>,
3811    /// DuckDB BY NAME modifier
3812    #[serde(default)]
3813    pub by_name: bool,
3814    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3815    #[serde(default, skip_serializing_if = "Option::is_none")]
3816    pub side: Option<String>,
3817    /// BigQuery: Set operation kind (INNER)
3818    #[serde(default, skip_serializing_if = "Option::is_none")]
3819    pub kind: Option<String>,
3820    /// BigQuery: CORRESPONDING modifier
3821    #[serde(default)]
3822    pub corresponding: bool,
3823    /// BigQuery: STRICT modifier (before CORRESPONDING)
3824    #[serde(default)]
3825    pub strict: bool,
3826    /// BigQuery: BY (columns) after CORRESPONDING
3827    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3828    pub on_columns: Vec<Expression>,
3829}
3830
3831/// Iteratively flatten the left-recursive chain to prevent stack overflow
3832/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3833impl Drop for Union {
3834    fn drop(&mut self) {
3835        loop {
3836            if let Expression::Union(ref mut inner) = self.left {
3837                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3838                let old_left = std::mem::replace(&mut self.left, next_left);
3839                drop(old_left);
3840            } else {
3841                break;
3842            }
3843        }
3844    }
3845}
3846
3847/// Represent an INTERSECT set operation between two query expressions.
3848///
3849/// Returns only rows that appear in both operands. When `all` is true,
3850/// duplicates are preserved according to their multiplicity.
3851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3852#[cfg_attr(feature = "bindings", derive(TS))]
3853pub struct Intersect {
3854    /// The left-hand query operand.
3855    pub left: Expression,
3856    /// The right-hand query operand.
3857    pub right: Expression,
3858    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3859    pub all: bool,
3860    /// Whether DISTINCT was explicitly specified
3861    #[serde(default)]
3862    pub distinct: bool,
3863    /// Optional WITH clause
3864    pub with: Option<With>,
3865    /// ORDER BY applied to entire INTERSECT result
3866    pub order_by: Option<OrderBy>,
3867    /// LIMIT applied to entire INTERSECT result
3868    pub limit: Option<Box<Expression>>,
3869    /// OFFSET applied to entire INTERSECT result
3870    pub offset: Option<Box<Expression>>,
3871    /// DISTRIBUTE BY clause (Hive/Spark)
3872    #[serde(default, skip_serializing_if = "Option::is_none")]
3873    pub distribute_by: Option<DistributeBy>,
3874    /// SORT BY clause (Hive/Spark)
3875    #[serde(default, skip_serializing_if = "Option::is_none")]
3876    pub sort_by: Option<SortBy>,
3877    /// CLUSTER BY clause (Hive/Spark)
3878    #[serde(default, skip_serializing_if = "Option::is_none")]
3879    pub cluster_by: Option<ClusterBy>,
3880    /// DuckDB BY NAME modifier
3881    #[serde(default)]
3882    pub by_name: bool,
3883    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3884    #[serde(default, skip_serializing_if = "Option::is_none")]
3885    pub side: Option<String>,
3886    /// BigQuery: Set operation kind (INNER)
3887    #[serde(default, skip_serializing_if = "Option::is_none")]
3888    pub kind: Option<String>,
3889    /// BigQuery: CORRESPONDING modifier
3890    #[serde(default)]
3891    pub corresponding: bool,
3892    /// BigQuery: STRICT modifier (before CORRESPONDING)
3893    #[serde(default)]
3894    pub strict: bool,
3895    /// BigQuery: BY (columns) after CORRESPONDING
3896    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3897    pub on_columns: Vec<Expression>,
3898}
3899
3900impl Drop for Intersect {
3901    fn drop(&mut self) {
3902        loop {
3903            if let Expression::Intersect(ref mut inner) = self.left {
3904                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3905                let old_left = std::mem::replace(&mut self.left, next_left);
3906                drop(old_left);
3907            } else {
3908                break;
3909            }
3910        }
3911    }
3912}
3913
3914/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3915///
3916/// Returns rows from the left operand that do not appear in the right operand.
3917/// When `all` is true, duplicates are subtracted according to their multiplicity.
3918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3919#[cfg_attr(feature = "bindings", derive(TS))]
3920pub struct Except {
3921    /// The left-hand query operand.
3922    pub left: Expression,
3923    /// The right-hand query operand (rows to subtract).
3924    pub right: Expression,
3925    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3926    pub all: bool,
3927    /// Whether DISTINCT was explicitly specified
3928    #[serde(default)]
3929    pub distinct: bool,
3930    /// Optional WITH clause
3931    pub with: Option<With>,
3932    /// ORDER BY applied to entire EXCEPT result
3933    pub order_by: Option<OrderBy>,
3934    /// LIMIT applied to entire EXCEPT result
3935    pub limit: Option<Box<Expression>>,
3936    /// OFFSET applied to entire EXCEPT result
3937    pub offset: Option<Box<Expression>>,
3938    /// DISTRIBUTE BY clause (Hive/Spark)
3939    #[serde(default, skip_serializing_if = "Option::is_none")]
3940    pub distribute_by: Option<DistributeBy>,
3941    /// SORT BY clause (Hive/Spark)
3942    #[serde(default, skip_serializing_if = "Option::is_none")]
3943    pub sort_by: Option<SortBy>,
3944    /// CLUSTER BY clause (Hive/Spark)
3945    #[serde(default, skip_serializing_if = "Option::is_none")]
3946    pub cluster_by: Option<ClusterBy>,
3947    /// DuckDB BY NAME modifier
3948    #[serde(default)]
3949    pub by_name: bool,
3950    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3951    #[serde(default, skip_serializing_if = "Option::is_none")]
3952    pub side: Option<String>,
3953    /// BigQuery: Set operation kind (INNER)
3954    #[serde(default, skip_serializing_if = "Option::is_none")]
3955    pub kind: Option<String>,
3956    /// BigQuery: CORRESPONDING modifier
3957    #[serde(default)]
3958    pub corresponding: bool,
3959    /// BigQuery: STRICT modifier (before CORRESPONDING)
3960    #[serde(default)]
3961    pub strict: bool,
3962    /// BigQuery: BY (columns) after CORRESPONDING
3963    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3964    pub on_columns: Vec<Expression>,
3965}
3966
3967impl Drop for Except {
3968    fn drop(&mut self) {
3969        loop {
3970            if let Expression::Except(ref mut inner) = self.left {
3971                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3972                let old_left = std::mem::replace(&mut self.left, next_left);
3973                drop(old_left);
3974            } else {
3975                break;
3976            }
3977        }
3978    }
3979}
3980
3981/// INTO clause for SELECT INTO statements
3982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3983#[cfg_attr(feature = "bindings", derive(TS))]
3984pub struct SelectInto {
3985    /// Target table or variable (used when single target)
3986    pub this: Expression,
3987    /// Whether TEMPORARY keyword was used
3988    #[serde(default)]
3989    pub temporary: bool,
3990    /// Whether UNLOGGED keyword was used (PostgreSQL)
3991    #[serde(default)]
3992    pub unlogged: bool,
3993    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3994    #[serde(default)]
3995    pub bulk_collect: bool,
3996    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3997    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3998    pub expressions: Vec<Expression>,
3999}
4000
4001/// Represent a parenthesized subquery expression.
4002///
4003/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
4004/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4005/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4006/// modifiers are rendered inside or outside the parentheses.
4007///
4008/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4009/// scalar subqueries in select-lists, and derived tables.
4010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4011#[cfg_attr(feature = "bindings", derive(TS))]
4012pub struct Subquery {
4013    /// The inner query expression.
4014    pub this: Expression,
4015    /// Optional alias for the derived table.
4016    pub alias: Option<Identifier>,
4017    /// Optional column aliases: AS t(c1, c2)
4018    pub column_aliases: Vec<Identifier>,
4019    /// Whether AS keyword was explicitly used for the alias.
4020    #[serde(default)]
4021    pub alias_explicit_as: bool,
4022    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4023    #[serde(skip_serializing_if = "Option::is_none", default)]
4024    pub alias_keyword: Option<String>,
4025    /// ORDER BY clause (for parenthesized queries)
4026    pub order_by: Option<OrderBy>,
4027    /// LIMIT clause
4028    pub limit: Option<Limit>,
4029    /// OFFSET clause
4030    pub offset: Option<Offset>,
4031    /// DISTRIBUTE BY clause (Hive/Spark)
4032    #[serde(default, skip_serializing_if = "Option::is_none")]
4033    pub distribute_by: Option<DistributeBy>,
4034    /// SORT BY clause (Hive/Spark)
4035    #[serde(default, skip_serializing_if = "Option::is_none")]
4036    pub sort_by: Option<SortBy>,
4037    /// CLUSTER BY clause (Hive/Spark)
4038    #[serde(default, skip_serializing_if = "Option::is_none")]
4039    pub cluster_by: Option<ClusterBy>,
4040    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4041    #[serde(default)]
4042    pub lateral: bool,
4043    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4044    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4045    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4046    #[serde(default)]
4047    pub modifiers_inside: bool,
4048    /// Trailing comments after the closing paren
4049    #[serde(default)]
4050    pub trailing_comments: Vec<String>,
4051    /// Inferred data type from type annotation
4052    #[serde(default, skip_serializing_if = "Option::is_none")]
4053    pub inferred_type: Option<DataType>,
4054}
4055
4056/// Pipe operator expression: query |> transform
4057///
4058/// Used in DataFusion and BigQuery pipe syntax:
4059///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4061#[cfg_attr(feature = "bindings", derive(TS))]
4062pub struct PipeOperator {
4063    /// The input query/expression (left side of |>)
4064    pub this: Expression,
4065    /// The piped operation (right side of |>)
4066    pub expression: Expression,
4067}
4068
4069/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4071#[cfg_attr(feature = "bindings", derive(TS))]
4072pub struct Values {
4073    /// The rows of values
4074    pub expressions: Vec<Tuple>,
4075    /// Optional alias for the table
4076    pub alias: Option<Identifier>,
4077    /// Optional column aliases: AS t(c1, c2)
4078    pub column_aliases: Vec<Identifier>,
4079}
4080
4081/// PIVOT operation - supports both standard and DuckDB simplified syntax
4082///
4083/// Standard syntax (in FROM clause):
4084///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4085///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4086///
4087/// DuckDB simplified syntax (statement-level):
4088///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4089///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4091#[cfg_attr(feature = "bindings", derive(TS))]
4092pub struct Pivot {
4093    /// Source table/expression
4094    pub this: Expression,
4095    /// For standard PIVOT: the aggregation function(s) (first is primary)
4096    /// For DuckDB simplified: unused (use `using` instead)
4097    #[serde(default)]
4098    pub expressions: Vec<Expression>,
4099    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4100    #[serde(default)]
4101    pub fields: Vec<Expression>,
4102    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4103    #[serde(default)]
4104    pub using: Vec<Expression>,
4105    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4106    #[serde(default)]
4107    pub group: Option<Box<Expression>>,
4108    /// Whether this is an UNPIVOT (vs PIVOT)
4109    #[serde(default)]
4110    pub unpivot: bool,
4111    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4112    #[serde(default)]
4113    pub into: Option<Box<Expression>>,
4114    /// Optional alias
4115    #[serde(default)]
4116    pub alias: Option<Identifier>,
4117    /// Include/exclude nulls (for UNPIVOT)
4118    #[serde(default)]
4119    pub include_nulls: Option<bool>,
4120    /// Default on null value (Snowflake)
4121    #[serde(default)]
4122    pub default_on_null: Option<Box<Expression>>,
4123    /// WITH clause (CTEs)
4124    #[serde(default, skip_serializing_if = "Option::is_none")]
4125    pub with: Option<With>,
4126}
4127
4128/// UNPIVOT operation
4129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4130#[cfg_attr(feature = "bindings", derive(TS))]
4131pub struct Unpivot {
4132    pub this: Expression,
4133    pub value_column: Identifier,
4134    pub name_column: Identifier,
4135    pub columns: Vec<Expression>,
4136    pub alias: Option<Identifier>,
4137    /// Whether the value_column was parenthesized in the original SQL
4138    #[serde(default)]
4139    pub value_column_parenthesized: bool,
4140    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4141    #[serde(default)]
4142    pub include_nulls: Option<bool>,
4143    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4144    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4145    pub extra_value_columns: Vec<Identifier>,
4146}
4147
4148/// PIVOT alias for aliasing pivot expressions
4149/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4151#[cfg_attr(feature = "bindings", derive(TS))]
4152pub struct PivotAlias {
4153    pub this: Expression,
4154    pub alias: Expression,
4155}
4156
4157/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4159#[cfg_attr(feature = "bindings", derive(TS))]
4160pub struct PreWhere {
4161    pub this: Expression,
4162}
4163
4164/// STREAM definition (Snowflake) - for change data capture
4165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub struct Stream {
4168    pub this: Expression,
4169    #[serde(skip_serializing_if = "Option::is_none")]
4170    pub on: Option<Expression>,
4171    #[serde(skip_serializing_if = "Option::is_none")]
4172    pub show_initial_rows: Option<bool>,
4173}
4174
4175/// USING DATA clause for data import statements
4176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4177#[cfg_attr(feature = "bindings", derive(TS))]
4178pub struct UsingData {
4179    pub this: Expression,
4180}
4181
4182/// XML Namespace declaration
4183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4184#[cfg_attr(feature = "bindings", derive(TS))]
4185pub struct XmlNamespace {
4186    pub this: Expression,
4187    #[serde(skip_serializing_if = "Option::is_none")]
4188    pub alias: Option<Identifier>,
4189}
4190
4191/// ROW FORMAT clause for Hive/Spark
4192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4193#[cfg_attr(feature = "bindings", derive(TS))]
4194pub struct RowFormat {
4195    pub delimited: bool,
4196    pub fields_terminated_by: Option<String>,
4197    pub collection_items_terminated_by: Option<String>,
4198    pub map_keys_terminated_by: Option<String>,
4199    pub lines_terminated_by: Option<String>,
4200    pub null_defined_as: Option<String>,
4201}
4202
4203/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4205#[cfg_attr(feature = "bindings", derive(TS))]
4206pub struct DirectoryInsert {
4207    pub local: bool,
4208    pub path: String,
4209    pub row_format: Option<RowFormat>,
4210    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4211    #[serde(default)]
4212    pub stored_as: Option<String>,
4213}
4214
4215/// INSERT statement
4216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4217#[cfg_attr(feature = "bindings", derive(TS))]
4218pub struct Insert {
4219    pub table: TableRef,
4220    pub columns: Vec<Identifier>,
4221    pub values: Vec<Vec<Expression>>,
4222    pub query: Option<Expression>,
4223    /// INSERT OVERWRITE for Hive/Spark
4224    pub overwrite: bool,
4225    /// PARTITION clause for Hive/Spark
4226    pub partition: Vec<(Identifier, Option<Expression>)>,
4227    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4228    #[serde(default)]
4229    pub directory: Option<DirectoryInsert>,
4230    /// RETURNING clause (PostgreSQL, SQLite)
4231    #[serde(default)]
4232    pub returning: Vec<Expression>,
4233    /// OUTPUT clause (TSQL)
4234    #[serde(default)]
4235    pub output: Option<OutputClause>,
4236    /// ON CONFLICT clause (PostgreSQL, SQLite)
4237    #[serde(default)]
4238    pub on_conflict: Option<Box<Expression>>,
4239    /// Leading comments before the statement
4240    #[serde(default)]
4241    pub leading_comments: Vec<String>,
4242    /// IF EXISTS clause (Hive)
4243    #[serde(default)]
4244    pub if_exists: bool,
4245    /// WITH clause (CTEs)
4246    #[serde(default)]
4247    pub with: Option<With>,
4248    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4249    #[serde(default)]
4250    pub ignore: bool,
4251    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4252    #[serde(default)]
4253    pub source_alias: Option<Identifier>,
4254    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4255    #[serde(default)]
4256    pub alias: Option<Identifier>,
4257    /// Whether the alias uses explicit AS keyword
4258    #[serde(default)]
4259    pub alias_explicit_as: bool,
4260    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4261    #[serde(default)]
4262    pub default_values: bool,
4263    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4264    #[serde(default)]
4265    pub by_name: bool,
4266    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4267    #[serde(default, skip_serializing_if = "Option::is_none")]
4268    pub conflict_action: Option<String>,
4269    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4270    #[serde(default)]
4271    pub is_replace: bool,
4272    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4273    #[serde(default, skip_serializing_if = "Option::is_none")]
4274    pub hint: Option<Hint>,
4275    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4276    #[serde(default)]
4277    pub replace_where: Option<Box<Expression>>,
4278    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4279    #[serde(default)]
4280    pub source: Option<Box<Expression>>,
4281    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4282    #[serde(default, skip_serializing_if = "Option::is_none")]
4283    pub function_target: Option<Box<Expression>>,
4284    /// ClickHouse: PARTITION BY expr
4285    #[serde(default, skip_serializing_if = "Option::is_none")]
4286    pub partition_by: Option<Box<Expression>>,
4287    /// ClickHouse: SETTINGS key = val, ...
4288    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4289    pub settings: Vec<Expression>,
4290}
4291
4292/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4294#[cfg_attr(feature = "bindings", derive(TS))]
4295pub struct OutputClause {
4296    /// Columns/expressions to output
4297    pub columns: Vec<Expression>,
4298    /// Optional INTO target table or table variable
4299    #[serde(default)]
4300    pub into_table: Option<Expression>,
4301}
4302
4303/// UPDATE statement
4304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4305#[cfg_attr(feature = "bindings", derive(TS))]
4306pub struct Update {
4307    pub table: TableRef,
4308    #[serde(default)]
4309    pub hint: Option<Hint>,
4310    /// Additional tables for multi-table UPDATE (MySQL syntax)
4311    #[serde(default)]
4312    pub extra_tables: Vec<TableRef>,
4313    /// JOINs attached to the table list (MySQL multi-table syntax)
4314    #[serde(default)]
4315    pub table_joins: Vec<Join>,
4316    pub set: Vec<(Identifier, Expression)>,
4317    pub from_clause: Option<From>,
4318    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4319    #[serde(default)]
4320    pub from_joins: Vec<Join>,
4321    pub where_clause: Option<Where>,
4322    /// RETURNING clause (PostgreSQL, SQLite)
4323    #[serde(default)]
4324    pub returning: Vec<Expression>,
4325    /// OUTPUT clause (TSQL)
4326    #[serde(default)]
4327    pub output: Option<OutputClause>,
4328    /// WITH clause (CTEs)
4329    #[serde(default)]
4330    pub with: Option<With>,
4331    /// Leading comments before the statement
4332    #[serde(default)]
4333    pub leading_comments: Vec<String>,
4334    /// LIMIT clause (MySQL)
4335    #[serde(default)]
4336    pub limit: Option<Expression>,
4337    /// ORDER BY clause (MySQL)
4338    #[serde(default)]
4339    pub order_by: Option<OrderBy>,
4340    /// Whether FROM clause appears before SET (Snowflake syntax)
4341    #[serde(default)]
4342    pub from_before_set: bool,
4343}
4344
4345/// DELETE statement
4346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4347#[cfg_attr(feature = "bindings", derive(TS))]
4348pub struct Delete {
4349    pub table: TableRef,
4350    #[serde(default)]
4351    pub hint: Option<Hint>,
4352    /// ClickHouse: ON CLUSTER clause for distributed DDL
4353    #[serde(default, skip_serializing_if = "Option::is_none")]
4354    pub on_cluster: Option<OnCluster>,
4355    /// Optional alias for the table
4356    pub alias: Option<Identifier>,
4357    /// Whether the alias was declared with explicit AS keyword
4358    #[serde(default)]
4359    pub alias_explicit_as: bool,
4360    /// PostgreSQL/DuckDB USING clause - additional tables to join
4361    pub using: Vec<TableRef>,
4362    pub where_clause: Option<Where>,
4363    /// OUTPUT clause (TSQL)
4364    #[serde(default)]
4365    pub output: Option<OutputClause>,
4366    /// Leading comments before the statement
4367    #[serde(default)]
4368    pub leading_comments: Vec<String>,
4369    /// WITH clause (CTEs)
4370    #[serde(default)]
4371    pub with: Option<With>,
4372    /// LIMIT clause (MySQL)
4373    #[serde(default)]
4374    pub limit: Option<Expression>,
4375    /// ORDER BY clause (MySQL)
4376    #[serde(default)]
4377    pub order_by: Option<OrderBy>,
4378    /// RETURNING clause (PostgreSQL)
4379    #[serde(default)]
4380    pub returning: Vec<Expression>,
4381    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4382    /// These are the target tables to delete from
4383    #[serde(default)]
4384    pub tables: Vec<TableRef>,
4385    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4386    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4387    #[serde(default)]
4388    pub tables_from_using: bool,
4389    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4390    #[serde(default)]
4391    pub joins: Vec<Join>,
4392    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4393    #[serde(default)]
4394    pub force_index: Option<String>,
4395    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4396    #[serde(default)]
4397    pub no_from: bool,
4398}
4399
4400/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4402#[cfg_attr(feature = "bindings", derive(TS))]
4403pub struct CopyStmt {
4404    /// Target table or query
4405    pub this: Expression,
4406    /// True for FROM (loading into table), false for TO (exporting)
4407    pub kind: bool,
4408    /// Source/destination file(s) or stage
4409    pub files: Vec<Expression>,
4410    /// Copy parameters
4411    #[serde(default)]
4412    pub params: Vec<CopyParameter>,
4413    /// Credentials for external access
4414    #[serde(default)]
4415    pub credentials: Option<Box<Credentials>>,
4416    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4417    #[serde(default)]
4418    pub is_into: bool,
4419    /// Whether parameters are wrapped in WITH (...) syntax
4420    #[serde(default)]
4421    pub with_wrapped: bool,
4422}
4423
4424/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4426#[cfg_attr(feature = "bindings", derive(TS))]
4427pub struct CopyParameter {
4428    pub name: String,
4429    pub value: Option<Expression>,
4430    pub values: Vec<Expression>,
4431    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4432    #[serde(default)]
4433    pub eq: bool,
4434}
4435
4436/// Credentials for external access (S3, Azure, etc.)
4437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4438#[cfg_attr(feature = "bindings", derive(TS))]
4439pub struct Credentials {
4440    pub credentials: Vec<(String, String)>,
4441    pub encryption: Option<String>,
4442    pub storage: Option<String>,
4443}
4444
4445/// PUT statement (Snowflake)
4446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4447#[cfg_attr(feature = "bindings", derive(TS))]
4448pub struct PutStmt {
4449    /// Source file path
4450    pub source: String,
4451    /// Whether source was quoted in the original SQL
4452    #[serde(default)]
4453    pub source_quoted: bool,
4454    /// Target stage
4455    pub target: Expression,
4456    /// PUT parameters
4457    #[serde(default)]
4458    pub params: Vec<CopyParameter>,
4459}
4460
4461/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4463#[cfg_attr(feature = "bindings", derive(TS))]
4464pub struct StageReference {
4465    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4466    pub name: String,
4467    /// Optional path within the stage (e.g., "/path/to/file.csv")
4468    #[serde(default)]
4469    pub path: Option<String>,
4470    /// Optional FILE_FORMAT parameter
4471    #[serde(default)]
4472    pub file_format: Option<Expression>,
4473    /// Optional PATTERN parameter
4474    #[serde(default)]
4475    pub pattern: Option<String>,
4476    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4477    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4478    pub quoted: bool,
4479}
4480
4481/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4483#[cfg_attr(feature = "bindings", derive(TS))]
4484pub struct HistoricalData {
4485    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4486    pub this: Box<Expression>,
4487    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4488    pub kind: String,
4489    /// The expression value (e.g., the statement ID or timestamp)
4490    pub expression: Box<Expression>,
4491}
4492
4493/// Represent an aliased expression (`expr AS name`).
4494///
4495/// Used for column aliases in select-lists, table aliases on subqueries,
4496/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4498#[cfg_attr(feature = "bindings", derive(TS))]
4499pub struct Alias {
4500    /// The expression being aliased.
4501    pub this: Expression,
4502    /// The alias name (required for simple aliases, optional when only column aliases provided)
4503    pub alias: Identifier,
4504    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4505    #[serde(default)]
4506    pub column_aliases: Vec<Identifier>,
4507    /// Whether AS keyword was explicitly used for the alias.
4508    #[serde(default)]
4509    pub alias_explicit_as: bool,
4510    /// Original alias keyword spelling, e.g. `AS` vs `as`.
4511    #[serde(skip_serializing_if = "Option::is_none", default)]
4512    pub alias_keyword: Option<String>,
4513    /// Comments that appeared between the expression and AS keyword
4514    #[serde(default)]
4515    pub pre_alias_comments: Vec<String>,
4516    /// Trailing comments that appeared after the alias
4517    #[serde(default)]
4518    pub trailing_comments: Vec<String>,
4519    /// Inferred data type from type annotation
4520    #[serde(default, skip_serializing_if = "Option::is_none")]
4521    pub inferred_type: Option<DataType>,
4522}
4523
4524impl Alias {
4525    /// Create a simple alias
4526    pub fn new(this: Expression, alias: Identifier) -> Self {
4527        Self {
4528            this,
4529            alias,
4530            column_aliases: Vec::new(),
4531            alias_explicit_as: false,
4532            alias_keyword: None,
4533            pre_alias_comments: Vec::new(),
4534            trailing_comments: Vec::new(),
4535            inferred_type: None,
4536        }
4537    }
4538
4539    /// Create an alias with column aliases only (no table alias name)
4540    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4541        Self {
4542            this,
4543            alias: Identifier::empty(),
4544            column_aliases,
4545            alias_explicit_as: false,
4546            alias_keyword: None,
4547            pre_alias_comments: Vec::new(),
4548            trailing_comments: Vec::new(),
4549            inferred_type: None,
4550        }
4551    }
4552}
4553
4554/// Represent a type cast expression.
4555///
4556/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4557/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4558/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4559/// CONVERSION ERROR (Oracle) clauses.
4560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4561#[cfg_attr(feature = "bindings", derive(TS))]
4562pub struct Cast {
4563    /// The expression being cast.
4564    pub this: Expression,
4565    /// The target data type.
4566    pub to: DataType,
4567    #[serde(default)]
4568    pub trailing_comments: Vec<String>,
4569    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4570    #[serde(default)]
4571    pub double_colon_syntax: bool,
4572    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4573    #[serde(skip_serializing_if = "Option::is_none", default)]
4574    pub format: Option<Box<Expression>>,
4575    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4576    #[serde(skip_serializing_if = "Option::is_none", default)]
4577    pub default: Option<Box<Expression>>,
4578    /// Inferred data type from type annotation
4579    #[serde(default, skip_serializing_if = "Option::is_none")]
4580    pub inferred_type: Option<DataType>,
4581}
4582
4583///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4585#[cfg_attr(feature = "bindings", derive(TS))]
4586pub struct CollationExpr {
4587    pub this: Expression,
4588    pub collation: String,
4589    /// True if the collation was single-quoted in the original SQL (string literal)
4590    #[serde(default)]
4591    pub quoted: bool,
4592    /// True if the collation was double-quoted in the original SQL (identifier)
4593    #[serde(default)]
4594    pub double_quoted: bool,
4595}
4596
4597/// Represent a CASE expression (both simple and searched forms).
4598///
4599/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4600/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4601/// Each entry in `whens` is a `(condition, result)` pair.
4602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4603#[cfg_attr(feature = "bindings", derive(TS))]
4604pub struct Case {
4605    /// The operand for simple CASE, or `None` for searched CASE.
4606    pub operand: Option<Expression>,
4607    /// Pairs of (WHEN condition, THEN result).
4608    pub whens: Vec<(Expression, Expression)>,
4609    /// Optional ELSE result.
4610    pub else_: Option<Expression>,
4611    /// Comments from the CASE keyword (emitted after END)
4612    #[serde(default)]
4613    #[serde(skip_serializing_if = "Vec::is_empty")]
4614    pub comments: Vec<String>,
4615    /// Inferred data type from type annotation
4616    #[serde(default, skip_serializing_if = "Option::is_none")]
4617    pub inferred_type: Option<DataType>,
4618}
4619
4620/// Represent a binary operation (two operands separated by an operator).
4621///
4622/// This is the shared payload struct for all binary operator variants in the
4623/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4624/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4625/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4626/// preservation of inline comments around operators.
4627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4628#[cfg_attr(feature = "bindings", derive(TS))]
4629pub struct BinaryOp {
4630    pub left: Expression,
4631    pub right: Expression,
4632    /// Comments after the left operand (before the operator)
4633    #[serde(default)]
4634    pub left_comments: Vec<String>,
4635    /// Comments after the operator (before the right operand)
4636    #[serde(default)]
4637    pub operator_comments: Vec<String>,
4638    /// Comments after the right operand
4639    #[serde(default)]
4640    pub trailing_comments: Vec<String>,
4641    /// Inferred data type from type annotation
4642    #[serde(default, skip_serializing_if = "Option::is_none")]
4643    pub inferred_type: Option<DataType>,
4644}
4645
4646impl BinaryOp {
4647    pub fn new(left: Expression, right: Expression) -> Self {
4648        Self {
4649            left,
4650            right,
4651            left_comments: Vec::new(),
4652            operator_comments: Vec::new(),
4653            trailing_comments: Vec::new(),
4654            inferred_type: None,
4655        }
4656    }
4657}
4658
4659/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4661#[cfg_attr(feature = "bindings", derive(TS))]
4662pub struct LikeOp {
4663    pub left: Expression,
4664    pub right: Expression,
4665    /// ESCAPE character/expression
4666    #[serde(default)]
4667    pub escape: Option<Expression>,
4668    /// Quantifier: ANY, ALL, or SOME
4669    #[serde(default)]
4670    pub quantifier: Option<String>,
4671    /// Inferred data type from type annotation
4672    #[serde(default, skip_serializing_if = "Option::is_none")]
4673    pub inferred_type: Option<DataType>,
4674}
4675
4676impl LikeOp {
4677    pub fn new(left: Expression, right: Expression) -> Self {
4678        Self {
4679            left,
4680            right,
4681            escape: None,
4682            quantifier: None,
4683            inferred_type: None,
4684        }
4685    }
4686
4687    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4688        Self {
4689            left,
4690            right,
4691            escape: Some(escape),
4692            quantifier: None,
4693            inferred_type: None,
4694        }
4695    }
4696}
4697
4698/// Represent a unary operation (single operand with a prefix operator).
4699///
4700/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4702#[cfg_attr(feature = "bindings", derive(TS))]
4703pub struct UnaryOp {
4704    /// The operand expression.
4705    pub this: Expression,
4706    /// Inferred data type from type annotation
4707    #[serde(default, skip_serializing_if = "Option::is_none")]
4708    pub inferred_type: Option<DataType>,
4709}
4710
4711impl UnaryOp {
4712    pub fn new(this: Expression) -> Self {
4713        Self {
4714            this,
4715            inferred_type: None,
4716        }
4717    }
4718}
4719
4720/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4721///
4722/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4723/// but not both. When `not` is true, the predicate is `NOT IN`.
4724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4725#[cfg_attr(feature = "bindings", derive(TS))]
4726pub struct In {
4727    /// The expression being tested.
4728    pub this: Expression,
4729    /// The value list (mutually exclusive with `query`).
4730    pub expressions: Vec<Expression>,
4731    /// A subquery (mutually exclusive with `expressions`).
4732    pub query: Option<Expression>,
4733    /// Whether this is NOT IN.
4734    pub not: bool,
4735    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4736    pub global: bool,
4737    /// BigQuery: IN UNNEST(expr)
4738    #[serde(default, skip_serializing_if = "Option::is_none")]
4739    pub unnest: Option<Box<Expression>>,
4740    /// Whether the right side is a bare field reference (no parentheses).
4741    /// Matches Python sqlglot's `field` attribute on `In` expression.
4742    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4743    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4744    pub is_field: bool,
4745}
4746
4747/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4749#[cfg_attr(feature = "bindings", derive(TS))]
4750pub struct Between {
4751    /// The expression being tested.
4752    pub this: Expression,
4753    /// The lower bound.
4754    pub low: Expression,
4755    /// The upper bound.
4756    pub high: Expression,
4757    /// Whether this is NOT BETWEEN.
4758    pub not: bool,
4759    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4760    #[serde(default)]
4761    pub symmetric: Option<bool>,
4762}
4763
4764/// IS NULL predicate
4765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4766#[cfg_attr(feature = "bindings", derive(TS))]
4767pub struct IsNull {
4768    pub this: Expression,
4769    pub not: bool,
4770    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4771    #[serde(default)]
4772    pub postfix_form: bool,
4773}
4774
4775/// IS TRUE / IS FALSE predicate
4776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4777#[cfg_attr(feature = "bindings", derive(TS))]
4778pub struct IsTrueFalse {
4779    pub this: Expression,
4780    pub not: bool,
4781}
4782
4783/// IS JSON predicate (SQL standard)
4784/// Checks if a value is valid JSON
4785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4786#[cfg_attr(feature = "bindings", derive(TS))]
4787pub struct IsJson {
4788    pub this: Expression,
4789    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4790    pub json_type: Option<String>,
4791    /// Key uniqueness constraint
4792    pub unique_keys: Option<JsonUniqueKeys>,
4793    /// Whether IS NOT JSON
4794    pub negated: bool,
4795}
4796
4797/// JSON unique keys constraint variants
4798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4799#[cfg_attr(feature = "bindings", derive(TS))]
4800pub enum JsonUniqueKeys {
4801    /// WITH UNIQUE KEYS
4802    With,
4803    /// WITHOUT UNIQUE KEYS
4804    Without,
4805    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4806    Shorthand,
4807}
4808
4809/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4811#[cfg_attr(feature = "bindings", derive(TS))]
4812pub struct Exists {
4813    /// The subquery expression.
4814    pub this: Expression,
4815    /// Whether this is NOT EXISTS.
4816    pub not: bool,
4817}
4818
4819/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4820///
4821/// This is the generic function node. Well-known aggregates, window functions,
4822/// and built-in functions each have their own dedicated `Expression` variants
4823/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4824/// not recognize as built-ins are represented with this struct.
4825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4826#[cfg_attr(feature = "bindings", derive(TS))]
4827pub struct Function {
4828    /// The function name, as originally written (may be schema-qualified).
4829    pub name: String,
4830    /// Positional arguments to the function.
4831    pub args: Vec<Expression>,
4832    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4833    pub distinct: bool,
4834    #[serde(default)]
4835    pub trailing_comments: Vec<String>,
4836    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4837    #[serde(default)]
4838    pub use_bracket_syntax: bool,
4839    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4840    #[serde(default)]
4841    pub no_parens: bool,
4842    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4843    #[serde(default)]
4844    pub quoted: bool,
4845    /// Source position span
4846    #[serde(default, skip_serializing_if = "Option::is_none")]
4847    pub span: Option<Span>,
4848    /// Inferred data type from type annotation
4849    #[serde(default, skip_serializing_if = "Option::is_none")]
4850    pub inferred_type: Option<DataType>,
4851}
4852
4853impl Default for Function {
4854    fn default() -> Self {
4855        Self {
4856            name: String::new(),
4857            args: Vec::new(),
4858            distinct: false,
4859            trailing_comments: Vec::new(),
4860            use_bracket_syntax: false,
4861            no_parens: false,
4862            quoted: false,
4863            span: None,
4864            inferred_type: None,
4865        }
4866    }
4867}
4868
4869impl Function {
4870    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4871        Self {
4872            name: name.into(),
4873            args,
4874            distinct: false,
4875            trailing_comments: Vec::new(),
4876            use_bracket_syntax: false,
4877            no_parens: false,
4878            quoted: false,
4879            span: None,
4880            inferred_type: None,
4881        }
4882    }
4883}
4884
4885/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4886///
4887/// This struct is used for aggregate function calls that are not covered by
4888/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4889/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4890/// IGNORE NULLS / RESPECT NULLS modifiers.
4891#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4892#[cfg_attr(feature = "bindings", derive(TS))]
4893pub struct AggregateFunction {
4894    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4895    pub name: String,
4896    /// Positional arguments.
4897    pub args: Vec<Expression>,
4898    /// Whether DISTINCT was specified.
4899    pub distinct: bool,
4900    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4901    pub filter: Option<Expression>,
4902    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4903    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4904    pub order_by: Vec<Ordered>,
4905    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4906    #[serde(default, skip_serializing_if = "Option::is_none")]
4907    pub limit: Option<Box<Expression>>,
4908    /// IGNORE NULLS / RESPECT NULLS
4909    #[serde(default, skip_serializing_if = "Option::is_none")]
4910    pub ignore_nulls: Option<bool>,
4911    /// Inferred data type from type annotation
4912    #[serde(default, skip_serializing_if = "Option::is_none")]
4913    pub inferred_type: Option<DataType>,
4914}
4915
4916/// Represent a window function call with its OVER clause.
4917///
4918/// The inner `this` expression is typically a window-specific expression
4919/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4920/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4921/// frame specification.
4922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4923#[cfg_attr(feature = "bindings", derive(TS))]
4924pub struct WindowFunction {
4925    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4926    pub this: Expression,
4927    /// The OVER clause defining the window partitioning, ordering, and frame.
4928    pub over: Over,
4929    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4930    #[serde(default, skip_serializing_if = "Option::is_none")]
4931    pub keep: Option<Keep>,
4932    /// Inferred data type from type annotation
4933    #[serde(default, skip_serializing_if = "Option::is_none")]
4934    pub inferred_type: Option<DataType>,
4935}
4936
4937/// Oracle KEEP clause for aggregate functions
4938/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4940#[cfg_attr(feature = "bindings", derive(TS))]
4941pub struct Keep {
4942    /// true = FIRST, false = LAST
4943    pub first: bool,
4944    /// ORDER BY clause inside KEEP
4945    pub order_by: Vec<Ordered>,
4946}
4947
4948/// WITHIN GROUP clause (for ordered-set aggregate functions)
4949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4950#[cfg_attr(feature = "bindings", derive(TS))]
4951pub struct WithinGroup {
4952    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4953    pub this: Expression,
4954    /// The ORDER BY clause within the group
4955    pub order_by: Vec<Ordered>,
4956}
4957
4958/// Represent the FROM clause of a SELECT statement.
4959///
4960/// Contains one or more table sources (tables, subqueries, table-valued
4961/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4963#[cfg_attr(feature = "bindings", derive(TS))]
4964pub struct From {
4965    /// The table source expressions.
4966    pub expressions: Vec<Expression>,
4967}
4968
4969/// Represent a JOIN clause between two table sources.
4970///
4971/// The join condition can be specified via `on` (ON predicate) or `using`
4972/// (USING column list), but not both. The `kind` field determines the join
4973/// type (INNER, LEFT, CROSS, etc.).
4974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4975#[cfg_attr(feature = "bindings", derive(TS))]
4976pub struct Join {
4977    /// The right-hand table expression being joined.
4978    pub this: Expression,
4979    /// The ON condition (mutually exclusive with `using`).
4980    pub on: Option<Expression>,
4981    /// The USING column list (mutually exclusive with `on`).
4982    pub using: Vec<Identifier>,
4983    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4984    pub kind: JoinKind,
4985    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4986    pub use_inner_keyword: bool,
4987    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4988    pub use_outer_keyword: bool,
4989    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4990    pub deferred_condition: bool,
4991    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4992    #[serde(default, skip_serializing_if = "Option::is_none")]
4993    pub join_hint: Option<String>,
4994    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4995    #[serde(default, skip_serializing_if = "Option::is_none")]
4996    pub match_condition: Option<Expression>,
4997    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4998    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4999    pub pivots: Vec<Expression>,
5000    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
5001    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5002    pub comments: Vec<String>,
5003    /// Nesting group identifier for nested join pretty-printing.
5004    /// Joins in the same group were parsed together; group boundaries come from
5005    /// deferred condition resolution phases.
5006    #[serde(default)]
5007    pub nesting_group: usize,
5008    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
5009    #[serde(default)]
5010    pub directed: bool,
5011}
5012
5013/// Enumerate all supported SQL join types.
5014///
5015/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
5016/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
5017/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
5018/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
5019#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5020#[cfg_attr(feature = "bindings", derive(TS))]
5021pub enum JoinKind {
5022    Inner,
5023    Left,
5024    Right,
5025    Full,
5026    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5027    Cross,
5028    Natural,
5029    NaturalLeft,
5030    NaturalRight,
5031    NaturalFull,
5032    Semi,
5033    Anti,
5034    // Directional SEMI/ANTI joins
5035    LeftSemi,
5036    LeftAnti,
5037    RightSemi,
5038    RightAnti,
5039    // SQL Server specific
5040    CrossApply,
5041    OuterApply,
5042    // Time-series specific
5043    AsOf,
5044    AsOfLeft,
5045    AsOfRight,
5046    // Lateral join
5047    Lateral,
5048    LeftLateral,
5049    // MySQL specific
5050    Straight,
5051    // Implicit join (comma-separated tables: FROM a, b)
5052    Implicit,
5053    // ClickHouse ARRAY JOIN
5054    Array,
5055    LeftArray,
5056    // ClickHouse PASTE JOIN (positional join)
5057    Paste,
5058    // DuckDB POSITIONAL JOIN
5059    Positional,
5060}
5061
5062impl Default for JoinKind {
5063    fn default() -> Self {
5064        JoinKind::Inner
5065    }
5066}
5067
5068/// Parenthesized table expression with joins
5069/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5071#[cfg_attr(feature = "bindings", derive(TS))]
5072pub struct JoinedTable {
5073    /// The left-hand side table expression
5074    pub left: Expression,
5075    /// The joins applied to the left table
5076    pub joins: Vec<Join>,
5077    /// LATERAL VIEW clauses (Hive/Spark)
5078    pub lateral_views: Vec<LateralView>,
5079    /// Optional alias for the joined table expression
5080    pub alias: Option<Identifier>,
5081}
5082
5083/// Represent a WHERE clause containing a boolean filter predicate.
5084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5085#[cfg_attr(feature = "bindings", derive(TS))]
5086pub struct Where {
5087    /// The filter predicate expression.
5088    pub this: Expression,
5089}
5090
5091/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5092///
5093/// The `expressions` list may contain plain columns, ordinal positions,
5094/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5096#[cfg_attr(feature = "bindings", derive(TS))]
5097pub struct GroupBy {
5098    /// The grouping expressions.
5099    pub expressions: Vec<Expression>,
5100    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5101    #[serde(default)]
5102    pub all: Option<bool>,
5103    /// ClickHouse: WITH TOTALS modifier
5104    #[serde(default)]
5105    pub totals: bool,
5106    /// Leading comments that appeared before the GROUP BY keyword
5107    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5108    pub comments: Vec<String>,
5109}
5110
5111/// Represent a HAVING clause containing a predicate over aggregate results.
5112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5113#[cfg_attr(feature = "bindings", derive(TS))]
5114pub struct Having {
5115    /// The filter predicate, typically involving aggregate functions.
5116    pub this: Expression,
5117    /// Leading comments that appeared before the HAVING keyword
5118    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5119    pub comments: Vec<String>,
5120}
5121
5122/// Represent an ORDER BY clause containing one or more sort specifications.
5123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5124#[cfg_attr(feature = "bindings", derive(TS))]
5125pub struct OrderBy {
5126    /// The sort specifications, each with direction and null ordering.
5127    pub expressions: Vec<Ordered>,
5128    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5129    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5130    pub siblings: bool,
5131    /// Leading comments that appeared before the ORDER BY keyword
5132    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5133    pub comments: Vec<String>,
5134}
5135
5136/// Represent an expression with sort direction and null ordering.
5137///
5138/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5139/// When `desc` is false the sort is ascending. The `nulls_first` field
5140/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5141/// (database default).
5142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5143#[cfg_attr(feature = "bindings", derive(TS))]
5144pub struct Ordered {
5145    /// The expression to sort by.
5146    pub this: Expression,
5147    /// Whether the sort direction is descending (true) or ascending (false).
5148    pub desc: bool,
5149    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5150    pub nulls_first: Option<bool>,
5151    /// Whether ASC was explicitly written (not just implied)
5152    #[serde(default)]
5153    pub explicit_asc: bool,
5154    /// ClickHouse WITH FILL clause
5155    #[serde(default, skip_serializing_if = "Option::is_none")]
5156    pub with_fill: Option<Box<WithFill>>,
5157}
5158
5159impl Ordered {
5160    pub fn asc(expr: Expression) -> Self {
5161        Self {
5162            this: expr,
5163            desc: false,
5164            nulls_first: None,
5165            explicit_asc: false,
5166            with_fill: None,
5167        }
5168    }
5169
5170    pub fn desc(expr: Expression) -> Self {
5171        Self {
5172            this: expr,
5173            desc: true,
5174            nulls_first: None,
5175            explicit_asc: false,
5176            with_fill: None,
5177        }
5178    }
5179}
5180
5181/// DISTRIBUTE BY clause (Hive/Spark)
5182/// Controls how rows are distributed across reducers
5183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5184#[cfg_attr(feature = "bindings", derive(TS))]
5185#[cfg_attr(feature = "bindings", ts(export))]
5186pub struct DistributeBy {
5187    pub expressions: Vec<Expression>,
5188}
5189
5190/// CLUSTER BY clause (Hive/Spark)
5191/// Combines DISTRIBUTE BY and SORT BY on the same columns
5192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5193#[cfg_attr(feature = "bindings", derive(TS))]
5194#[cfg_attr(feature = "bindings", ts(export))]
5195pub struct ClusterBy {
5196    pub expressions: Vec<Ordered>,
5197}
5198
5199/// SORT BY clause (Hive/Spark)
5200/// Sorts data within each reducer (local sort, not global)
5201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5202#[cfg_attr(feature = "bindings", derive(TS))]
5203#[cfg_attr(feature = "bindings", ts(export))]
5204pub struct SortBy {
5205    pub expressions: Vec<Ordered>,
5206}
5207
5208/// LATERAL VIEW clause (Hive/Spark)
5209/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5211#[cfg_attr(feature = "bindings", derive(TS))]
5212#[cfg_attr(feature = "bindings", ts(export))]
5213pub struct LateralView {
5214    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5215    pub this: Expression,
5216    /// Table alias for the generated table
5217    pub table_alias: Option<Identifier>,
5218    /// Column aliases for the generated columns
5219    pub column_aliases: Vec<Identifier>,
5220    /// OUTER keyword - preserve nulls when input is empty/null
5221    pub outer: bool,
5222}
5223
5224/// Query hint
5225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5226#[cfg_attr(feature = "bindings", derive(TS))]
5227#[cfg_attr(feature = "bindings", ts(export))]
5228pub struct Hint {
5229    pub expressions: Vec<HintExpression>,
5230}
5231
5232/// Individual hint expression
5233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5234#[cfg_attr(feature = "bindings", derive(TS))]
5235#[cfg_attr(feature = "bindings", ts(export))]
5236pub enum HintExpression {
5237    /// Function-style hint: USE_HASH(table)
5238    Function { name: String, args: Vec<Expression> },
5239    /// Simple identifier hint: PARALLEL
5240    Identifier(String),
5241    /// Raw hint text (unparsed)
5242    Raw(String),
5243}
5244
5245/// Pseudocolumn type
5246#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5247#[cfg_attr(feature = "bindings", derive(TS))]
5248#[cfg_attr(feature = "bindings", ts(export))]
5249pub enum PseudocolumnType {
5250    Rownum,      // Oracle ROWNUM
5251    Rowid,       // Oracle ROWID
5252    Level,       // Oracle LEVEL (for CONNECT BY)
5253    Sysdate,     // Oracle SYSDATE
5254    ObjectId,    // Oracle OBJECT_ID
5255    ObjectValue, // Oracle OBJECT_VALUE
5256}
5257
5258impl PseudocolumnType {
5259    pub fn as_str(&self) -> &'static str {
5260        match self {
5261            PseudocolumnType::Rownum => "ROWNUM",
5262            PseudocolumnType::Rowid => "ROWID",
5263            PseudocolumnType::Level => "LEVEL",
5264            PseudocolumnType::Sysdate => "SYSDATE",
5265            PseudocolumnType::ObjectId => "OBJECT_ID",
5266            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5267        }
5268    }
5269
5270    pub fn from_str(s: &str) -> Option<Self> {
5271        match s.to_uppercase().as_str() {
5272            "ROWNUM" => Some(PseudocolumnType::Rownum),
5273            "ROWID" => Some(PseudocolumnType::Rowid),
5274            "LEVEL" => Some(PseudocolumnType::Level),
5275            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5276            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5277            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5278            _ => None,
5279        }
5280    }
5281}
5282
5283/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5284/// These are special identifiers that should not be quoted
5285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5286#[cfg_attr(feature = "bindings", derive(TS))]
5287#[cfg_attr(feature = "bindings", ts(export))]
5288pub struct Pseudocolumn {
5289    pub kind: PseudocolumnType,
5290}
5291
5292impl Pseudocolumn {
5293    pub fn rownum() -> Self {
5294        Self {
5295            kind: PseudocolumnType::Rownum,
5296        }
5297    }
5298
5299    pub fn rowid() -> Self {
5300        Self {
5301            kind: PseudocolumnType::Rowid,
5302        }
5303    }
5304
5305    pub fn level() -> Self {
5306        Self {
5307            kind: PseudocolumnType::Level,
5308        }
5309    }
5310}
5311
5312/// Oracle CONNECT BY clause for hierarchical queries
5313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5314#[cfg_attr(feature = "bindings", derive(TS))]
5315#[cfg_attr(feature = "bindings", ts(export))]
5316pub struct Connect {
5317    /// START WITH condition (optional, can come before or after CONNECT BY)
5318    pub start: Option<Expression>,
5319    /// CONNECT BY condition (required, contains PRIOR references)
5320    pub connect: Expression,
5321    /// NOCYCLE keyword to prevent infinite loops
5322    pub nocycle: bool,
5323}
5324
5325/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5327#[cfg_attr(feature = "bindings", derive(TS))]
5328#[cfg_attr(feature = "bindings", ts(export))]
5329pub struct Prior {
5330    pub this: Expression,
5331}
5332
5333/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5335#[cfg_attr(feature = "bindings", derive(TS))]
5336#[cfg_attr(feature = "bindings", ts(export))]
5337pub struct ConnectByRoot {
5338    pub this: Expression,
5339}
5340
5341/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5343#[cfg_attr(feature = "bindings", derive(TS))]
5344#[cfg_attr(feature = "bindings", ts(export))]
5345pub struct MatchRecognize {
5346    /// Source table/expression
5347    pub this: Option<Box<Expression>>,
5348    /// PARTITION BY expressions
5349    pub partition_by: Option<Vec<Expression>>,
5350    /// ORDER BY expressions
5351    pub order_by: Option<Vec<Ordered>>,
5352    /// MEASURES definitions
5353    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5354    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5355    pub rows: Option<MatchRecognizeRows>,
5356    /// AFTER MATCH SKIP behavior
5357    pub after: Option<MatchRecognizeAfter>,
5358    /// PATTERN definition (stored as raw string for complex regex patterns)
5359    pub pattern: Option<String>,
5360    /// DEFINE clauses (pattern variable definitions)
5361    pub define: Option<Vec<(Identifier, Expression)>>,
5362    /// Optional alias for the result
5363    pub alias: Option<Identifier>,
5364    /// Whether AS keyword was explicitly present before alias
5365    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5366    pub alias_explicit_as: bool,
5367}
5368
5369/// MEASURES expression with optional RUNNING/FINAL semantics
5370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5371#[cfg_attr(feature = "bindings", derive(TS))]
5372#[cfg_attr(feature = "bindings", ts(export))]
5373pub struct MatchRecognizeMeasure {
5374    /// The measure expression
5375    pub this: Expression,
5376    /// RUNNING or FINAL semantics (Snowflake-specific)
5377    pub window_frame: Option<MatchRecognizeSemantics>,
5378}
5379
5380/// Semantics for MEASURES in MATCH_RECOGNIZE
5381#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5382#[cfg_attr(feature = "bindings", derive(TS))]
5383#[cfg_attr(feature = "bindings", ts(export))]
5384pub enum MatchRecognizeSemantics {
5385    Running,
5386    Final,
5387}
5388
5389/// Row output semantics for MATCH_RECOGNIZE
5390#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5391#[cfg_attr(feature = "bindings", derive(TS))]
5392#[cfg_attr(feature = "bindings", ts(export))]
5393pub enum MatchRecognizeRows {
5394    OneRowPerMatch,
5395    AllRowsPerMatch,
5396    AllRowsPerMatchShowEmptyMatches,
5397    AllRowsPerMatchOmitEmptyMatches,
5398    AllRowsPerMatchWithUnmatchedRows,
5399}
5400
5401/// AFTER MATCH SKIP behavior
5402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5403#[cfg_attr(feature = "bindings", derive(TS))]
5404#[cfg_attr(feature = "bindings", ts(export))]
5405pub enum MatchRecognizeAfter {
5406    PastLastRow,
5407    ToNextRow,
5408    ToFirst(Identifier),
5409    ToLast(Identifier),
5410}
5411
5412/// Represent a LIMIT clause that restricts the number of returned rows.
5413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5414#[cfg_attr(feature = "bindings", derive(TS))]
5415pub struct Limit {
5416    /// The limit count expression.
5417    pub this: Expression,
5418    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5419    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5420    pub percent: bool,
5421    /// Comments from before the LIMIT keyword (emitted after the limit value)
5422    #[serde(default)]
5423    #[serde(skip_serializing_if = "Vec::is_empty")]
5424    pub comments: Vec<String>,
5425}
5426
5427/// OFFSET clause
5428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5429#[cfg_attr(feature = "bindings", derive(TS))]
5430pub struct Offset {
5431    pub this: Expression,
5432    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5433    #[serde(skip_serializing_if = "Option::is_none", default)]
5434    pub rows: Option<bool>,
5435}
5436
5437/// TOP clause (SQL Server)
5438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5439#[cfg_attr(feature = "bindings", derive(TS))]
5440pub struct Top {
5441    pub this: Expression,
5442    pub percent: bool,
5443    pub with_ties: bool,
5444    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5445    #[serde(default)]
5446    pub parenthesized: bool,
5447}
5448
5449/// FETCH FIRST/NEXT clause (SQL standard)
5450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5451#[cfg_attr(feature = "bindings", derive(TS))]
5452pub struct Fetch {
5453    /// FIRST or NEXT
5454    pub direction: String,
5455    /// Count expression (optional)
5456    pub count: Option<Expression>,
5457    /// PERCENT modifier
5458    pub percent: bool,
5459    /// ROWS or ROW keyword present
5460    pub rows: bool,
5461    /// WITH TIES modifier
5462    pub with_ties: bool,
5463}
5464
5465/// Represent a QUALIFY clause for filtering on window function results.
5466///
5467/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5468/// typically references a window function (e.g.
5469/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5471#[cfg_attr(feature = "bindings", derive(TS))]
5472pub struct Qualify {
5473    /// The filter predicate over window function results.
5474    pub this: Expression,
5475}
5476
5477/// SAMPLE / TABLESAMPLE clause
5478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5479#[cfg_attr(feature = "bindings", derive(TS))]
5480pub struct Sample {
5481    pub method: SampleMethod,
5482    pub size: Expression,
5483    pub seed: Option<Expression>,
5484    /// ClickHouse OFFSET expression after SAMPLE size
5485    #[serde(default)]
5486    pub offset: Option<Expression>,
5487    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5488    pub unit_after_size: bool,
5489    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5490    #[serde(default)]
5491    pub use_sample_keyword: bool,
5492    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5493    #[serde(default)]
5494    pub explicit_method: bool,
5495    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5496    #[serde(default)]
5497    pub method_before_size: bool,
5498    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5499    #[serde(default)]
5500    pub use_seed_keyword: bool,
5501    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5502    pub bucket_numerator: Option<Box<Expression>>,
5503    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5504    pub bucket_denominator: Option<Box<Expression>>,
5505    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5506    pub bucket_field: Option<Box<Expression>>,
5507    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5508    #[serde(default)]
5509    pub is_using_sample: bool,
5510    /// Whether the unit was explicitly PERCENT (vs ROWS)
5511    #[serde(default)]
5512    pub is_percent: bool,
5513    /// Whether to suppress method output (for cross-dialect transpilation)
5514    #[serde(default)]
5515    pub suppress_method_output: bool,
5516}
5517
5518/// Sample method
5519#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5520#[cfg_attr(feature = "bindings", derive(TS))]
5521pub enum SampleMethod {
5522    Bernoulli,
5523    System,
5524    Block,
5525    Row,
5526    Percent,
5527    /// Hive bucket sampling
5528    Bucket,
5529    /// DuckDB reservoir sampling
5530    Reservoir,
5531}
5532
5533/// Named window definition (WINDOW w AS (...))
5534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5535#[cfg_attr(feature = "bindings", derive(TS))]
5536pub struct NamedWindow {
5537    pub name: Identifier,
5538    pub spec: Over,
5539}
5540
5541/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5542///
5543/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5544/// that reference themselves. Each CTE is defined in the `ctes` vector and
5545/// can be referenced by name in subsequent CTEs and in the main query body.
5546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5547#[cfg_attr(feature = "bindings", derive(TS))]
5548pub struct With {
5549    /// The list of CTE definitions, in order.
5550    pub ctes: Vec<Cte>,
5551    /// Whether the WITH RECURSIVE keyword was used.
5552    pub recursive: bool,
5553    /// Leading comments before the statement
5554    #[serde(default)]
5555    pub leading_comments: Vec<String>,
5556    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5557    #[serde(default, skip_serializing_if = "Option::is_none")]
5558    pub search: Option<Box<Expression>>,
5559}
5560
5561/// Represent a single Common Table Expression definition.
5562///
5563/// A CTE has a name (`alias`), an optional column list, and a body query.
5564/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5565/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5566/// the expression comes before the alias (`alias_first`).
5567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5568#[cfg_attr(feature = "bindings", derive(TS))]
5569pub struct Cte {
5570    /// The CTE name.
5571    pub alias: Identifier,
5572    /// The CTE body (typically a SELECT, UNION, etc.).
5573    pub this: Expression,
5574    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5575    pub columns: Vec<Identifier>,
5576    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5577    pub materialized: Option<bool>,
5578    /// USING KEY (columns) for DuckDB recursive CTEs
5579    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5580    pub key_expressions: Vec<Identifier>,
5581    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5582    #[serde(default)]
5583    pub alias_first: bool,
5584    /// Comments associated with this CTE (placed after alias name, before AS)
5585    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5586    pub comments: Vec<String>,
5587}
5588
5589/// Window specification
5590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5591#[cfg_attr(feature = "bindings", derive(TS))]
5592pub struct WindowSpec {
5593    pub partition_by: Vec<Expression>,
5594    pub order_by: Vec<Ordered>,
5595    pub frame: Option<WindowFrame>,
5596}
5597
5598/// OVER clause
5599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5600#[cfg_attr(feature = "bindings", derive(TS))]
5601pub struct Over {
5602    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5603    pub window_name: Option<Identifier>,
5604    pub partition_by: Vec<Expression>,
5605    pub order_by: Vec<Ordered>,
5606    pub frame: Option<WindowFrame>,
5607    pub alias: Option<Identifier>,
5608}
5609
5610/// Window frame
5611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5612#[cfg_attr(feature = "bindings", derive(TS))]
5613pub struct WindowFrame {
5614    pub kind: WindowFrameKind,
5615    pub start: WindowFrameBound,
5616    pub end: Option<WindowFrameBound>,
5617    pub exclude: Option<WindowFrameExclude>,
5618    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5619    #[serde(default, skip_serializing_if = "Option::is_none")]
5620    pub kind_text: Option<String>,
5621    /// Original text of the start bound side keyword (e.g. "preceding")
5622    #[serde(default, skip_serializing_if = "Option::is_none")]
5623    pub start_side_text: Option<String>,
5624    /// Original text of the end bound side keyword
5625    #[serde(default, skip_serializing_if = "Option::is_none")]
5626    pub end_side_text: Option<String>,
5627}
5628
5629#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5630#[cfg_attr(feature = "bindings", derive(TS))]
5631pub enum WindowFrameKind {
5632    Rows,
5633    Range,
5634    Groups,
5635}
5636
5637/// EXCLUDE clause for window frames
5638#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5639#[cfg_attr(feature = "bindings", derive(TS))]
5640pub enum WindowFrameExclude {
5641    CurrentRow,
5642    Group,
5643    Ties,
5644    NoOthers,
5645}
5646
5647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5648#[cfg_attr(feature = "bindings", derive(TS))]
5649pub enum WindowFrameBound {
5650    CurrentRow,
5651    UnboundedPreceding,
5652    UnboundedFollowing,
5653    Preceding(Box<Expression>),
5654    Following(Box<Expression>),
5655    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5656    BarePreceding,
5657    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5658    BareFollowing,
5659    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5660    Value(Box<Expression>),
5661}
5662
5663/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5665#[cfg_attr(feature = "bindings", derive(TS))]
5666pub struct StructField {
5667    pub name: String,
5668    pub data_type: DataType,
5669    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5670    pub options: Vec<Expression>,
5671    #[serde(default, skip_serializing_if = "Option::is_none")]
5672    pub comment: Option<String>,
5673}
5674
5675impl StructField {
5676    /// Create a new struct field without options
5677    pub fn new(name: String, data_type: DataType) -> Self {
5678        Self {
5679            name,
5680            data_type,
5681            options: Vec::new(),
5682            comment: None,
5683        }
5684    }
5685
5686    /// Create a new struct field with options
5687    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5688        Self {
5689            name,
5690            data_type,
5691            options,
5692            comment: None,
5693        }
5694    }
5695
5696    /// Create a new struct field with options and comment
5697    pub fn with_options_and_comment(
5698        name: String,
5699        data_type: DataType,
5700        options: Vec<Expression>,
5701        comment: Option<String>,
5702    ) -> Self {
5703        Self {
5704            name,
5705            data_type,
5706            options,
5707            comment,
5708        }
5709    }
5710}
5711
5712/// Enumerate all SQL data types recognized by the parser.
5713///
5714/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5715/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5716/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5717///
5718/// This enum is used in CAST expressions, column definitions, function return
5719/// types, and anywhere a data type specification appears in SQL.
5720///
5721/// Types that do not match any known variant fall through to `Custom { name }`,
5722/// preserving the original type name for round-trip fidelity.
5723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5724#[cfg_attr(feature = "bindings", derive(TS))]
5725#[serde(tag = "data_type", rename_all = "snake_case")]
5726pub enum DataType {
5727    // Numeric
5728    Boolean,
5729    TinyInt {
5730        length: Option<u32>,
5731    },
5732    SmallInt {
5733        length: Option<u32>,
5734    },
5735    /// Int type with optional length. `integer_spelling` indicates whether the original
5736    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5737    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5738    Int {
5739        length: Option<u32>,
5740        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5741        integer_spelling: bool,
5742    },
5743    BigInt {
5744        length: Option<u32>,
5745    },
5746    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5747    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5748    /// preserve the original spelling.
5749    Float {
5750        precision: Option<u32>,
5751        scale: Option<u32>,
5752        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5753        real_spelling: bool,
5754    },
5755    Double {
5756        precision: Option<u32>,
5757        scale: Option<u32>,
5758    },
5759    Decimal {
5760        precision: Option<u32>,
5761        scale: Option<u32>,
5762    },
5763
5764    // String
5765    Char {
5766        length: Option<u32>,
5767    },
5768    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5769    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5770    VarChar {
5771        length: Option<u32>,
5772        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5773        parenthesized_length: bool,
5774    },
5775    /// String type with optional max length (BigQuery STRING(n))
5776    String {
5777        length: Option<u32>,
5778    },
5779    Text,
5780    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5781    TextWithLength {
5782        length: u32,
5783    },
5784
5785    // Binary
5786    Binary {
5787        length: Option<u32>,
5788    },
5789    VarBinary {
5790        length: Option<u32>,
5791    },
5792    Blob,
5793
5794    // Bit
5795    Bit {
5796        length: Option<u32>,
5797    },
5798    VarBit {
5799        length: Option<u32>,
5800    },
5801
5802    // Date/Time
5803    Date,
5804    Time {
5805        precision: Option<u32>,
5806        #[serde(default)]
5807        timezone: bool,
5808    },
5809    Timestamp {
5810        precision: Option<u32>,
5811        timezone: bool,
5812    },
5813    Interval {
5814        unit: Option<String>,
5815        /// For range intervals like INTERVAL DAY TO HOUR
5816        #[serde(default, skip_serializing_if = "Option::is_none")]
5817        to: Option<String>,
5818    },
5819
5820    // JSON
5821    Json,
5822    JsonB,
5823
5824    // UUID
5825    Uuid,
5826
5827    // Array
5828    Array {
5829        element_type: Box<DataType>,
5830        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5831        #[serde(default, skip_serializing_if = "Option::is_none")]
5832        dimension: Option<u32>,
5833    },
5834
5835    /// List type (Materialize): INT LIST, TEXT LIST LIST
5836    /// Uses postfix LIST syntax instead of ARRAY<T>
5837    List {
5838        element_type: Box<DataType>,
5839    },
5840
5841    // Struct/Map
5842    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5843    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5844    Struct {
5845        fields: Vec<StructField>,
5846        nested: bool,
5847    },
5848    Map {
5849        key_type: Box<DataType>,
5850        value_type: Box<DataType>,
5851    },
5852
5853    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5854    Enum {
5855        values: Vec<String>,
5856        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5857        assignments: Vec<Option<String>>,
5858    },
5859
5860    // Set type (MySQL): SET('a', 'b', 'c')
5861    Set {
5862        values: Vec<String>,
5863    },
5864
5865    // Union type (DuckDB): UNION(num INT, str TEXT)
5866    Union {
5867        fields: Vec<(String, DataType)>,
5868    },
5869
5870    // Vector (Snowflake / SingleStore)
5871    Vector {
5872        #[serde(default)]
5873        element_type: Option<Box<DataType>>,
5874        dimension: Option<u32>,
5875    },
5876
5877    // Object (Snowflake structured type)
5878    // fields: Vec of (field_name, field_type, not_null)
5879    Object {
5880        fields: Vec<(String, DataType, bool)>,
5881        modifier: Option<String>,
5882    },
5883
5884    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5885    Nullable {
5886        inner: Box<DataType>,
5887    },
5888
5889    // Custom/User-defined
5890    Custom {
5891        name: String,
5892    },
5893
5894    // Spatial types
5895    Geometry {
5896        subtype: Option<String>,
5897        srid: Option<u32>,
5898    },
5899    Geography {
5900        subtype: Option<String>,
5901        srid: Option<u32>,
5902    },
5903
5904    // Character Set (for CONVERT USING in MySQL)
5905    // Renders as CHAR CHARACTER SET {name} in cast target
5906    CharacterSet {
5907        name: String,
5908    },
5909
5910    // Unknown
5911    Unknown,
5912}
5913
5914/// Array expression
5915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5916#[cfg_attr(feature = "bindings", derive(TS))]
5917#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5918pub struct Array {
5919    pub expressions: Vec<Expression>,
5920}
5921
5922/// Struct expression
5923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5924#[cfg_attr(feature = "bindings", derive(TS))]
5925pub struct Struct {
5926    pub fields: Vec<(Option<String>, Expression)>,
5927}
5928
5929/// Tuple expression
5930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5931#[cfg_attr(feature = "bindings", derive(TS))]
5932pub struct Tuple {
5933    pub expressions: Vec<Expression>,
5934}
5935
5936/// Interval expression
5937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5938#[cfg_attr(feature = "bindings", derive(TS))]
5939pub struct Interval {
5940    /// The value expression (e.g., '1', 5, column_ref)
5941    pub this: Option<Expression>,
5942    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5943    pub unit: Option<IntervalUnitSpec>,
5944}
5945
5946/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5948#[cfg_attr(feature = "bindings", derive(TS))]
5949#[serde(tag = "type", rename_all = "snake_case")]
5950pub enum IntervalUnitSpec {
5951    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5952    Simple {
5953        unit: IntervalUnit,
5954        /// Whether to use plural form (e.g., DAYS vs DAY)
5955        use_plural: bool,
5956    },
5957    /// Interval span (e.g., HOUR TO SECOND)
5958    Span(IntervalSpan),
5959    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5960    /// The start and end can be expressions like function calls with precision
5961    ExprSpan(IntervalSpanExpr),
5962    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5963    Expr(Box<Expression>),
5964}
5965
5966/// Interval span for ranges like HOUR TO SECOND
5967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5968#[cfg_attr(feature = "bindings", derive(TS))]
5969pub struct IntervalSpan {
5970    /// Start unit (e.g., HOUR)
5971    pub this: IntervalUnit,
5972    /// End unit (e.g., SECOND)
5973    pub expression: IntervalUnit,
5974}
5975
5976/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5977/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5979#[cfg_attr(feature = "bindings", derive(TS))]
5980pub struct IntervalSpanExpr {
5981    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5982    pub this: Box<Expression>,
5983    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5984    pub expression: Box<Expression>,
5985}
5986
5987#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5988#[cfg_attr(feature = "bindings", derive(TS))]
5989pub enum IntervalUnit {
5990    Year,
5991    Quarter,
5992    Month,
5993    Week,
5994    Day,
5995    Hour,
5996    Minute,
5997    Second,
5998    Millisecond,
5999    Microsecond,
6000    Nanosecond,
6001}
6002
6003/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
6004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6005#[cfg_attr(feature = "bindings", derive(TS))]
6006pub struct Command {
6007    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
6008    pub this: String,
6009}
6010
6011/// T-SQL TRY/CATCH block.
6012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6013#[cfg_attr(feature = "bindings", derive(TS))]
6014pub struct TryCatch {
6015    /// Statements inside BEGIN TRY ... END TRY.
6016    #[serde(default)]
6017    pub try_body: Vec<Expression>,
6018    /// Statements inside BEGIN CATCH ... END CATCH, when present.
6019    #[serde(default, skip_serializing_if = "Option::is_none")]
6020    pub catch_body: Option<Vec<Expression>>,
6021}
6022
6023/// EXEC/EXECUTE statement (TSQL stored procedure call)
6024/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
6025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6026#[cfg_attr(feature = "bindings", derive(TS))]
6027pub struct ExecuteStatement {
6028    /// The procedure name (can be qualified: schema.proc_name)
6029    pub this: Expression,
6030    /// Named parameters: @param=value pairs
6031    #[serde(default)]
6032    pub parameters: Vec<ExecuteParameter>,
6033    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
6034    #[serde(default, skip_serializing_if = "Option::is_none")]
6035    pub suffix: Option<String>,
6036}
6037
6038/// Named parameter in EXEC statement: @name=value
6039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6040#[cfg_attr(feature = "bindings", derive(TS))]
6041pub struct ExecuteParameter {
6042    /// Parameter name (including @)
6043    pub name: String,
6044    /// Parameter value
6045    pub value: Expression,
6046    /// Whether this is a positional parameter (no = sign)
6047    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6048    pub positional: bool,
6049    /// TSQL OUTPUT modifier on parameter
6050    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6051    pub output: bool,
6052}
6053
6054/// KILL statement (MySQL/MariaDB)
6055/// KILL [CONNECTION | QUERY] <id>
6056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6057#[cfg_attr(feature = "bindings", derive(TS))]
6058pub struct Kill {
6059    /// The target (process ID or connection ID)
6060    pub this: Expression,
6061    /// Optional kind: "CONNECTION" or "QUERY"
6062    pub kind: Option<String>,
6063}
6064
6065/// Snowflake CREATE TASK statement
6066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6067#[cfg_attr(feature = "bindings", derive(TS))]
6068pub struct CreateTask {
6069    pub or_replace: bool,
6070    pub if_not_exists: bool,
6071    /// Task name (possibly qualified: db.schema.task)
6072    pub name: String,
6073    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6074    pub properties: String,
6075    /// The SQL statement body after AS
6076    pub body: Expression,
6077}
6078
6079/// Raw/unparsed SQL
6080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6081#[cfg_attr(feature = "bindings", derive(TS))]
6082pub struct Raw {
6083    pub sql: String,
6084}
6085
6086// ============================================================================
6087// Function expression types
6088// ============================================================================
6089
6090/// Generic unary function (takes a single argument)
6091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6092#[cfg_attr(feature = "bindings", derive(TS))]
6093pub struct UnaryFunc {
6094    pub this: Expression,
6095    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6096    #[serde(skip_serializing_if = "Option::is_none", default)]
6097    pub original_name: Option<String>,
6098    /// Inferred data type from type annotation
6099    #[serde(default, skip_serializing_if = "Option::is_none")]
6100    pub inferred_type: Option<DataType>,
6101}
6102
6103impl UnaryFunc {
6104    /// Create a new UnaryFunc with no original_name
6105    pub fn new(this: Expression) -> Self {
6106        Self {
6107            this,
6108            original_name: None,
6109            inferred_type: None,
6110        }
6111    }
6112
6113    /// Create a new UnaryFunc with an original name for round-trip preservation
6114    pub fn with_name(this: Expression, name: String) -> Self {
6115        Self {
6116            this,
6117            original_name: Some(name),
6118            inferred_type: None,
6119        }
6120    }
6121}
6122
6123/// CHAR/CHR function with multiple args and optional USING charset
6124/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6125/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6127#[cfg_attr(feature = "bindings", derive(TS))]
6128pub struct CharFunc {
6129    pub args: Vec<Expression>,
6130    #[serde(skip_serializing_if = "Option::is_none", default)]
6131    pub charset: Option<String>,
6132    /// Original function name (CHAR or CHR), defaults to CHAR
6133    #[serde(skip_serializing_if = "Option::is_none", default)]
6134    pub name: Option<String>,
6135}
6136
6137/// Generic binary function (takes two arguments)
6138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6139#[cfg_attr(feature = "bindings", derive(TS))]
6140pub struct BinaryFunc {
6141    pub this: Expression,
6142    pub expression: Expression,
6143    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6144    #[serde(skip_serializing_if = "Option::is_none", default)]
6145    pub original_name: Option<String>,
6146    /// Inferred data type from type annotation
6147    #[serde(default, skip_serializing_if = "Option::is_none")]
6148    pub inferred_type: Option<DataType>,
6149}
6150
6151/// Variable argument function
6152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6153#[cfg_attr(feature = "bindings", derive(TS))]
6154pub struct VarArgFunc {
6155    pub expressions: Vec<Expression>,
6156    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6157    #[serde(skip_serializing_if = "Option::is_none", default)]
6158    pub original_name: Option<String>,
6159    /// Inferred data type from type annotation
6160    #[serde(default, skip_serializing_if = "Option::is_none")]
6161    pub inferred_type: Option<DataType>,
6162}
6163
6164/// CONCAT_WS function
6165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6166#[cfg_attr(feature = "bindings", derive(TS))]
6167pub struct ConcatWs {
6168    pub separator: Expression,
6169    pub expressions: Vec<Expression>,
6170}
6171
6172/// SUBSTRING function
6173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6174#[cfg_attr(feature = "bindings", derive(TS))]
6175pub struct SubstringFunc {
6176    pub this: Expression,
6177    pub start: Expression,
6178    pub length: Option<Expression>,
6179    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6180    #[serde(default)]
6181    pub from_for_syntax: bool,
6182}
6183
6184/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6186#[cfg_attr(feature = "bindings", derive(TS))]
6187pub struct OverlayFunc {
6188    pub this: Expression,
6189    pub replacement: Expression,
6190    pub from: Expression,
6191    pub length: Option<Expression>,
6192}
6193
6194/// TRIM function
6195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6196#[cfg_attr(feature = "bindings", derive(TS))]
6197pub struct TrimFunc {
6198    pub this: Expression,
6199    pub characters: Option<Expression>,
6200    pub position: TrimPosition,
6201    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6202    #[serde(default)]
6203    pub sql_standard_syntax: bool,
6204    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6205    #[serde(default)]
6206    pub position_explicit: bool,
6207}
6208
6209#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6210#[cfg_attr(feature = "bindings", derive(TS))]
6211pub enum TrimPosition {
6212    Both,
6213    Leading,
6214    Trailing,
6215}
6216
6217/// REPLACE function
6218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6219#[cfg_attr(feature = "bindings", derive(TS))]
6220pub struct ReplaceFunc {
6221    pub this: Expression,
6222    pub old: Expression,
6223    pub new: Expression,
6224}
6225
6226/// LEFT/RIGHT function
6227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6228#[cfg_attr(feature = "bindings", derive(TS))]
6229pub struct LeftRightFunc {
6230    pub this: Expression,
6231    pub length: Expression,
6232}
6233
6234/// REPEAT function
6235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6236#[cfg_attr(feature = "bindings", derive(TS))]
6237pub struct RepeatFunc {
6238    pub this: Expression,
6239    pub times: Expression,
6240}
6241
6242/// LPAD/RPAD function
6243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6244#[cfg_attr(feature = "bindings", derive(TS))]
6245pub struct PadFunc {
6246    pub this: Expression,
6247    pub length: Expression,
6248    pub fill: Option<Expression>,
6249}
6250
6251/// SPLIT function
6252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6253#[cfg_attr(feature = "bindings", derive(TS))]
6254pub struct SplitFunc {
6255    pub this: Expression,
6256    pub delimiter: Expression,
6257}
6258
6259/// REGEXP_LIKE function
6260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6261#[cfg_attr(feature = "bindings", derive(TS))]
6262pub struct RegexpFunc {
6263    pub this: Expression,
6264    pub pattern: Expression,
6265    pub flags: Option<Expression>,
6266}
6267
6268/// REGEXP_REPLACE function
6269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6270#[cfg_attr(feature = "bindings", derive(TS))]
6271pub struct RegexpReplaceFunc {
6272    pub this: Expression,
6273    pub pattern: Expression,
6274    pub replacement: Expression,
6275    pub flags: Option<Expression>,
6276}
6277
6278/// REGEXP_EXTRACT function
6279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6280#[cfg_attr(feature = "bindings", derive(TS))]
6281pub struct RegexpExtractFunc {
6282    pub this: Expression,
6283    pub pattern: Expression,
6284    pub group: Option<Expression>,
6285}
6286
6287/// ROUND function
6288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6289#[cfg_attr(feature = "bindings", derive(TS))]
6290pub struct RoundFunc {
6291    pub this: Expression,
6292    pub decimals: Option<Expression>,
6293}
6294
6295/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6297#[cfg_attr(feature = "bindings", derive(TS))]
6298pub struct FloorFunc {
6299    pub this: Expression,
6300    pub scale: Option<Expression>,
6301    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6302    #[serde(skip_serializing_if = "Option::is_none", default)]
6303    pub to: Option<Expression>,
6304}
6305
6306/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6308#[cfg_attr(feature = "bindings", derive(TS))]
6309pub struct CeilFunc {
6310    pub this: Expression,
6311    #[serde(skip_serializing_if = "Option::is_none", default)]
6312    pub decimals: Option<Expression>,
6313    /// Time unit for Druid-style CEIL(time TO unit) syntax
6314    #[serde(skip_serializing_if = "Option::is_none", default)]
6315    pub to: Option<Expression>,
6316}
6317
6318/// LOG function
6319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6320#[cfg_attr(feature = "bindings", derive(TS))]
6321pub struct LogFunc {
6322    pub this: Expression,
6323    pub base: Option<Expression>,
6324}
6325
6326/// CURRENT_DATE (no arguments)
6327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6328#[cfg_attr(feature = "bindings", derive(TS))]
6329pub struct CurrentDate;
6330
6331/// CURRENT_TIME
6332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6333#[cfg_attr(feature = "bindings", derive(TS))]
6334pub struct CurrentTime {
6335    pub precision: Option<u32>,
6336}
6337
6338/// CURRENT_TIMESTAMP
6339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6340#[cfg_attr(feature = "bindings", derive(TS))]
6341pub struct CurrentTimestamp {
6342    pub precision: Option<u32>,
6343    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6344    #[serde(default)]
6345    pub sysdate: bool,
6346}
6347
6348/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6350#[cfg_attr(feature = "bindings", derive(TS))]
6351pub struct CurrentTimestampLTZ {
6352    pub precision: Option<u32>,
6353}
6354
6355/// AT TIME ZONE expression for timezone conversion
6356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6357#[cfg_attr(feature = "bindings", derive(TS))]
6358pub struct AtTimeZone {
6359    /// The expression to convert
6360    pub this: Expression,
6361    /// The target timezone
6362    pub zone: Expression,
6363}
6364
6365/// DATE_ADD / DATE_SUB function
6366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6367#[cfg_attr(feature = "bindings", derive(TS))]
6368pub struct DateAddFunc {
6369    pub this: Expression,
6370    pub interval: Expression,
6371    pub unit: IntervalUnit,
6372}
6373
6374/// DATEDIFF function
6375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6376#[cfg_attr(feature = "bindings", derive(TS))]
6377pub struct DateDiffFunc {
6378    pub this: Expression,
6379    pub expression: Expression,
6380    pub unit: Option<IntervalUnit>,
6381}
6382
6383/// DATE_TRUNC function
6384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6385#[cfg_attr(feature = "bindings", derive(TS))]
6386pub struct DateTruncFunc {
6387    pub this: Expression,
6388    pub unit: DateTimeField,
6389}
6390
6391/// EXTRACT function
6392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6393#[cfg_attr(feature = "bindings", derive(TS))]
6394pub struct ExtractFunc {
6395    pub this: Expression,
6396    pub field: DateTimeField,
6397}
6398
6399#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6400#[cfg_attr(feature = "bindings", derive(TS))]
6401pub enum DateTimeField {
6402    Year,
6403    Month,
6404    Day,
6405    Hour,
6406    Minute,
6407    Second,
6408    Millisecond,
6409    Microsecond,
6410    DayOfWeek,
6411    DayOfYear,
6412    Week,
6413    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6414    WeekWithModifier(String),
6415    Quarter,
6416    Epoch,
6417    Timezone,
6418    TimezoneHour,
6419    TimezoneMinute,
6420    Date,
6421    Time,
6422    /// Custom datetime field for dialect-specific or arbitrary fields
6423    Custom(String),
6424}
6425
6426/// TO_DATE function
6427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6428#[cfg_attr(feature = "bindings", derive(TS))]
6429pub struct ToDateFunc {
6430    pub this: Expression,
6431    pub format: Option<Expression>,
6432}
6433
6434/// TO_TIMESTAMP function
6435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6436#[cfg_attr(feature = "bindings", derive(TS))]
6437pub struct ToTimestampFunc {
6438    pub this: Expression,
6439    pub format: Option<Expression>,
6440}
6441
6442/// IF function
6443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6444#[cfg_attr(feature = "bindings", derive(TS))]
6445pub struct IfFunc {
6446    pub condition: Expression,
6447    pub true_value: Expression,
6448    pub false_value: Option<Expression>,
6449    /// Original function name (IF, IFF, IIF) for round-trip preservation
6450    #[serde(skip_serializing_if = "Option::is_none", default)]
6451    pub original_name: Option<String>,
6452    /// Inferred data type from type annotation
6453    #[serde(default, skip_serializing_if = "Option::is_none")]
6454    pub inferred_type: Option<DataType>,
6455}
6456
6457/// NVL2 function
6458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6459#[cfg_attr(feature = "bindings", derive(TS))]
6460pub struct Nvl2Func {
6461    pub this: Expression,
6462    pub true_value: Expression,
6463    pub false_value: Expression,
6464    /// Inferred data type from type annotation
6465    #[serde(default, skip_serializing_if = "Option::is_none")]
6466    pub inferred_type: Option<DataType>,
6467}
6468
6469// ============================================================================
6470// Typed Aggregate Function types
6471// ============================================================================
6472
6473/// Generic aggregate function base type
6474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6475#[cfg_attr(feature = "bindings", derive(TS))]
6476pub struct AggFunc {
6477    pub this: Expression,
6478    pub distinct: bool,
6479    pub filter: Option<Expression>,
6480    pub order_by: Vec<Ordered>,
6481    /// Original function name (case-preserving) when parsed from SQL
6482    #[serde(skip_serializing_if = "Option::is_none", default)]
6483    pub name: Option<String>,
6484    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6485    #[serde(skip_serializing_if = "Option::is_none", default)]
6486    pub ignore_nulls: Option<bool>,
6487    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6488    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6489    #[serde(skip_serializing_if = "Option::is_none", default)]
6490    pub having_max: Option<(Box<Expression>, bool)>,
6491    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6492    #[serde(skip_serializing_if = "Option::is_none", default)]
6493    pub limit: Option<Box<Expression>>,
6494    /// Inferred data type from type annotation
6495    #[serde(default, skip_serializing_if = "Option::is_none")]
6496    pub inferred_type: Option<DataType>,
6497}
6498
6499/// COUNT function with optional star
6500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6501#[cfg_attr(feature = "bindings", derive(TS))]
6502pub struct CountFunc {
6503    pub this: Option<Expression>,
6504    pub star: bool,
6505    pub distinct: bool,
6506    pub filter: Option<Expression>,
6507    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6508    #[serde(default, skip_serializing_if = "Option::is_none")]
6509    pub ignore_nulls: Option<bool>,
6510    /// Original function name for case preservation (e.g., "count" or "COUNT")
6511    #[serde(default, skip_serializing_if = "Option::is_none")]
6512    pub original_name: Option<String>,
6513    /// Inferred data type from type annotation
6514    #[serde(default, skip_serializing_if = "Option::is_none")]
6515    pub inferred_type: Option<DataType>,
6516}
6517
6518/// GROUP_CONCAT function (MySQL style)
6519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6520#[cfg_attr(feature = "bindings", derive(TS))]
6521pub struct GroupConcatFunc {
6522    pub this: Expression,
6523    pub separator: Option<Expression>,
6524    pub order_by: Option<Vec<Ordered>>,
6525    pub distinct: bool,
6526    pub filter: Option<Expression>,
6527    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6528    #[serde(default, skip_serializing_if = "Option::is_none")]
6529    pub limit: Option<Box<Expression>>,
6530    /// Inferred data type from type annotation
6531    #[serde(default, skip_serializing_if = "Option::is_none")]
6532    pub inferred_type: Option<DataType>,
6533}
6534
6535/// STRING_AGG function (PostgreSQL/Standard SQL)
6536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6537#[cfg_attr(feature = "bindings", derive(TS))]
6538pub struct StringAggFunc {
6539    pub this: Expression,
6540    #[serde(default)]
6541    pub separator: Option<Expression>,
6542    #[serde(default)]
6543    pub order_by: Option<Vec<Ordered>>,
6544    #[serde(default)]
6545    pub distinct: bool,
6546    #[serde(default)]
6547    pub filter: Option<Expression>,
6548    /// BigQuery LIMIT inside STRING_AGG
6549    #[serde(default, skip_serializing_if = "Option::is_none")]
6550    pub limit: Option<Box<Expression>>,
6551    /// Inferred data type from type annotation
6552    #[serde(default, skip_serializing_if = "Option::is_none")]
6553    pub inferred_type: Option<DataType>,
6554}
6555
6556/// LISTAGG function (Oracle style)
6557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6558#[cfg_attr(feature = "bindings", derive(TS))]
6559pub struct ListAggFunc {
6560    pub this: Expression,
6561    pub separator: Option<Expression>,
6562    pub on_overflow: Option<ListAggOverflow>,
6563    pub order_by: Option<Vec<Ordered>>,
6564    pub distinct: bool,
6565    pub filter: Option<Expression>,
6566    /// Inferred data type from type annotation
6567    #[serde(default, skip_serializing_if = "Option::is_none")]
6568    pub inferred_type: Option<DataType>,
6569}
6570
6571/// LISTAGG ON OVERFLOW behavior
6572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6573#[cfg_attr(feature = "bindings", derive(TS))]
6574pub enum ListAggOverflow {
6575    Error,
6576    Truncate {
6577        filler: Option<Expression>,
6578        with_count: bool,
6579    },
6580}
6581
6582/// SUM_IF / COUNT_IF function
6583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6584#[cfg_attr(feature = "bindings", derive(TS))]
6585pub struct SumIfFunc {
6586    pub this: Expression,
6587    pub condition: Expression,
6588    pub filter: Option<Expression>,
6589    /// Inferred data type from type annotation
6590    #[serde(default, skip_serializing_if = "Option::is_none")]
6591    pub inferred_type: Option<DataType>,
6592}
6593
6594/// APPROX_PERCENTILE function
6595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6596#[cfg_attr(feature = "bindings", derive(TS))]
6597pub struct ApproxPercentileFunc {
6598    pub this: Expression,
6599    pub percentile: Expression,
6600    pub accuracy: Option<Expression>,
6601    pub filter: Option<Expression>,
6602}
6603
6604/// PERCENTILE_CONT / PERCENTILE_DISC function
6605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6606#[cfg_attr(feature = "bindings", derive(TS))]
6607pub struct PercentileFunc {
6608    pub this: Expression,
6609    pub percentile: Expression,
6610    pub order_by: Option<Vec<Ordered>>,
6611    pub filter: Option<Expression>,
6612}
6613
6614// ============================================================================
6615// Typed Window Function types
6616// ============================================================================
6617
6618/// ROW_NUMBER function (no arguments)
6619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6620#[cfg_attr(feature = "bindings", derive(TS))]
6621pub struct RowNumber;
6622
6623/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6625#[cfg_attr(feature = "bindings", derive(TS))]
6626pub struct Rank {
6627    /// DuckDB: RANK(ORDER BY col) - order by inside function
6628    #[serde(default, skip_serializing_if = "Option::is_none")]
6629    pub order_by: Option<Vec<Ordered>>,
6630    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6631    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6632    pub args: Vec<Expression>,
6633}
6634
6635/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6637#[cfg_attr(feature = "bindings", derive(TS))]
6638pub struct DenseRank {
6639    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6641    pub args: Vec<Expression>,
6642}
6643
6644/// NTILE function (DuckDB allows ORDER BY inside)
6645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6646#[cfg_attr(feature = "bindings", derive(TS))]
6647pub struct NTileFunc {
6648    /// num_buckets is optional to support Databricks NTILE() without arguments
6649    #[serde(default, skip_serializing_if = "Option::is_none")]
6650    pub num_buckets: Option<Expression>,
6651    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6652    #[serde(default, skip_serializing_if = "Option::is_none")]
6653    pub order_by: Option<Vec<Ordered>>,
6654}
6655
6656/// LEAD / LAG function
6657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6658#[cfg_attr(feature = "bindings", derive(TS))]
6659pub struct LeadLagFunc {
6660    pub this: Expression,
6661    pub offset: Option<Expression>,
6662    pub default: Option<Expression>,
6663    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6664    #[serde(default, skip_serializing_if = "Option::is_none")]
6665    pub ignore_nulls: Option<bool>,
6666}
6667
6668/// FIRST_VALUE / LAST_VALUE function
6669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6670#[cfg_attr(feature = "bindings", derive(TS))]
6671pub struct ValueFunc {
6672    pub this: Expression,
6673    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6674    #[serde(default, skip_serializing_if = "Option::is_none")]
6675    pub ignore_nulls: Option<bool>,
6676    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6677    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6678    pub order_by: Vec<Ordered>,
6679}
6680
6681/// NTH_VALUE function
6682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6683#[cfg_attr(feature = "bindings", derive(TS))]
6684pub struct NthValueFunc {
6685    pub this: Expression,
6686    pub offset: 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    /// Snowflake FROM FIRST / FROM LAST clause
6691    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6692    #[serde(default, skip_serializing_if = "Option::is_none")]
6693    pub from_first: Option<bool>,
6694}
6695
6696/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6698#[cfg_attr(feature = "bindings", derive(TS))]
6699pub struct PercentRank {
6700    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6701    #[serde(default, skip_serializing_if = "Option::is_none")]
6702    pub order_by: Option<Vec<Ordered>>,
6703    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6704    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6705    pub args: Vec<Expression>,
6706}
6707
6708/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6710#[cfg_attr(feature = "bindings", derive(TS))]
6711pub struct CumeDist {
6712    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6713    #[serde(default, skip_serializing_if = "Option::is_none")]
6714    pub order_by: Option<Vec<Ordered>>,
6715    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6716    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6717    pub args: Vec<Expression>,
6718}
6719
6720// ============================================================================
6721// Additional String Function types
6722// ============================================================================
6723
6724/// POSITION/INSTR function
6725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6726#[cfg_attr(feature = "bindings", derive(TS))]
6727pub struct PositionFunc {
6728    pub substring: Expression,
6729    pub string: Expression,
6730    pub start: Option<Expression>,
6731}
6732
6733// ============================================================================
6734// Additional Math Function types
6735// ============================================================================
6736
6737/// RANDOM function (no arguments)
6738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6739#[cfg_attr(feature = "bindings", derive(TS))]
6740pub struct Random;
6741
6742/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6744#[cfg_attr(feature = "bindings", derive(TS))]
6745pub struct Rand {
6746    pub seed: Option<Box<Expression>>,
6747    /// Teradata RANDOM lower bound
6748    #[serde(default)]
6749    pub lower: Option<Box<Expression>>,
6750    /// Teradata RANDOM upper bound
6751    #[serde(default)]
6752    pub upper: Option<Box<Expression>>,
6753}
6754
6755/// TRUNCATE / TRUNC function
6756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6757#[cfg_attr(feature = "bindings", derive(TS))]
6758pub struct TruncateFunc {
6759    pub this: Expression,
6760    pub decimals: Option<Expression>,
6761}
6762
6763/// PI function (no arguments)
6764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6765#[cfg_attr(feature = "bindings", derive(TS))]
6766pub struct Pi;
6767
6768// ============================================================================
6769// Control Flow Function types
6770// ============================================================================
6771
6772/// DECODE function (Oracle style)
6773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6774#[cfg_attr(feature = "bindings", derive(TS))]
6775pub struct DecodeFunc {
6776    pub this: Expression,
6777    pub search_results: Vec<(Expression, Expression)>,
6778    pub default: Option<Expression>,
6779}
6780
6781// ============================================================================
6782// Additional Date/Time Function types
6783// ============================================================================
6784
6785/// DATE_FORMAT / FORMAT_DATE function
6786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6787#[cfg_attr(feature = "bindings", derive(TS))]
6788pub struct DateFormatFunc {
6789    pub this: Expression,
6790    pub format: Expression,
6791}
6792
6793/// FROM_UNIXTIME function
6794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6795#[cfg_attr(feature = "bindings", derive(TS))]
6796pub struct FromUnixtimeFunc {
6797    pub this: Expression,
6798    pub format: Option<Expression>,
6799}
6800
6801/// UNIX_TIMESTAMP function
6802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6803#[cfg_attr(feature = "bindings", derive(TS))]
6804pub struct UnixTimestampFunc {
6805    pub this: Option<Expression>,
6806    pub format: Option<Expression>,
6807}
6808
6809/// MAKE_DATE function
6810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6811#[cfg_attr(feature = "bindings", derive(TS))]
6812pub struct MakeDateFunc {
6813    pub year: Expression,
6814    pub month: Expression,
6815    pub day: Expression,
6816}
6817
6818/// MAKE_TIMESTAMP function
6819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6820#[cfg_attr(feature = "bindings", derive(TS))]
6821pub struct MakeTimestampFunc {
6822    pub year: Expression,
6823    pub month: Expression,
6824    pub day: Expression,
6825    pub hour: Expression,
6826    pub minute: Expression,
6827    pub second: Expression,
6828    pub timezone: Option<Expression>,
6829}
6830
6831/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6833#[cfg_attr(feature = "bindings", derive(TS))]
6834pub struct LastDayFunc {
6835    pub this: Expression,
6836    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6837    #[serde(skip_serializing_if = "Option::is_none", default)]
6838    pub unit: Option<DateTimeField>,
6839}
6840
6841// ============================================================================
6842// Array Function types
6843// ============================================================================
6844
6845/// ARRAY constructor
6846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6847#[cfg_attr(feature = "bindings", derive(TS))]
6848pub struct ArrayConstructor {
6849    pub expressions: Vec<Expression>,
6850    pub bracket_notation: bool,
6851    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6852    pub use_list_keyword: bool,
6853}
6854
6855/// ARRAY_SORT function
6856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6857#[cfg_attr(feature = "bindings", derive(TS))]
6858pub struct ArraySortFunc {
6859    pub this: Expression,
6860    pub comparator: Option<Expression>,
6861    pub desc: bool,
6862    pub nulls_first: Option<bool>,
6863}
6864
6865/// ARRAY_JOIN / ARRAY_TO_STRING function
6866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6867#[cfg_attr(feature = "bindings", derive(TS))]
6868pub struct ArrayJoinFunc {
6869    pub this: Expression,
6870    pub separator: Expression,
6871    pub null_replacement: Option<Expression>,
6872}
6873
6874/// UNNEST function
6875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6876#[cfg_attr(feature = "bindings", derive(TS))]
6877pub struct UnnestFunc {
6878    pub this: Expression,
6879    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6880    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6881    pub expressions: Vec<Expression>,
6882    pub with_ordinality: bool,
6883    pub alias: Option<Identifier>,
6884    /// BigQuery: offset alias for WITH OFFSET AS <name>
6885    #[serde(default, skip_serializing_if = "Option::is_none")]
6886    pub offset_alias: Option<Identifier>,
6887}
6888
6889/// ARRAY_FILTER function (with lambda)
6890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6891#[cfg_attr(feature = "bindings", derive(TS))]
6892pub struct ArrayFilterFunc {
6893    pub this: Expression,
6894    pub filter: Expression,
6895}
6896
6897/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6899#[cfg_attr(feature = "bindings", derive(TS))]
6900pub struct ArrayTransformFunc {
6901    pub this: Expression,
6902    pub transform: Expression,
6903}
6904
6905/// SEQUENCE / GENERATE_SERIES function
6906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6907#[cfg_attr(feature = "bindings", derive(TS))]
6908pub struct SequenceFunc {
6909    pub start: Expression,
6910    pub stop: Expression,
6911    pub step: Option<Expression>,
6912}
6913
6914// ============================================================================
6915// Struct Function types
6916// ============================================================================
6917
6918/// STRUCT constructor
6919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6920#[cfg_attr(feature = "bindings", derive(TS))]
6921pub struct StructConstructor {
6922    pub fields: Vec<(Option<Identifier>, Expression)>,
6923}
6924
6925/// STRUCT_EXTRACT function
6926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6927#[cfg_attr(feature = "bindings", derive(TS))]
6928pub struct StructExtractFunc {
6929    pub this: Expression,
6930    pub field: Identifier,
6931}
6932
6933/// NAMED_STRUCT function
6934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6935#[cfg_attr(feature = "bindings", derive(TS))]
6936pub struct NamedStructFunc {
6937    pub pairs: Vec<(Expression, Expression)>,
6938}
6939
6940// ============================================================================
6941// Map Function types
6942// ============================================================================
6943
6944/// MAP constructor
6945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6946#[cfg_attr(feature = "bindings", derive(TS))]
6947pub struct MapConstructor {
6948    pub keys: Vec<Expression>,
6949    pub values: Vec<Expression>,
6950    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6951    #[serde(default)]
6952    pub curly_brace_syntax: bool,
6953    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6954    #[serde(default)]
6955    pub with_map_keyword: bool,
6956}
6957
6958/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6960#[cfg_attr(feature = "bindings", derive(TS))]
6961pub struct TransformFunc {
6962    pub this: Expression,
6963    pub transform: Expression,
6964}
6965
6966/// Function call with EMITS clause (Exasol)
6967/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6969#[cfg_attr(feature = "bindings", derive(TS))]
6970pub struct FunctionEmits {
6971    /// The function call expression
6972    pub this: Expression,
6973    /// The EMITS schema definition
6974    pub emits: Expression,
6975}
6976
6977// ============================================================================
6978// JSON Function types
6979// ============================================================================
6980
6981/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6983#[cfg_attr(feature = "bindings", derive(TS))]
6984pub struct JsonExtractFunc {
6985    pub this: Expression,
6986    pub path: Expression,
6987    pub returning: Option<DataType>,
6988    /// True if parsed from -> or ->> operator syntax
6989    #[serde(default)]
6990    pub arrow_syntax: bool,
6991    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6992    #[serde(default)]
6993    pub hash_arrow_syntax: bool,
6994    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6995    #[serde(default)]
6996    pub wrapper_option: Option<String>,
6997    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6998    #[serde(default)]
6999    pub quotes_option: Option<String>,
7000    /// ON SCALAR STRING flag
7001    #[serde(default)]
7002    pub on_scalar_string: bool,
7003    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
7004    #[serde(default)]
7005    pub on_error: Option<String>,
7006}
7007
7008/// JSON path extraction
7009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7010#[cfg_attr(feature = "bindings", derive(TS))]
7011pub struct JsonPathFunc {
7012    pub this: Expression,
7013    pub paths: Vec<Expression>,
7014}
7015
7016/// JSON_OBJECT function
7017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7018#[cfg_attr(feature = "bindings", derive(TS))]
7019pub struct JsonObjectFunc {
7020    pub pairs: Vec<(Expression, Expression)>,
7021    pub null_handling: Option<JsonNullHandling>,
7022    #[serde(default)]
7023    pub with_unique_keys: bool,
7024    #[serde(default)]
7025    pub returning_type: Option<DataType>,
7026    #[serde(default)]
7027    pub format_json: bool,
7028    #[serde(default)]
7029    pub encoding: Option<String>,
7030    /// For JSON_OBJECT(*) syntax
7031    #[serde(default)]
7032    pub star: bool,
7033}
7034
7035/// JSON null handling options
7036#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7037#[cfg_attr(feature = "bindings", derive(TS))]
7038pub enum JsonNullHandling {
7039    NullOnNull,
7040    AbsentOnNull,
7041}
7042
7043/// JSON_SET / JSON_INSERT function
7044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7045#[cfg_attr(feature = "bindings", derive(TS))]
7046pub struct JsonModifyFunc {
7047    pub this: Expression,
7048    pub path_values: Vec<(Expression, Expression)>,
7049}
7050
7051/// JSON_ARRAYAGG function
7052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7053#[cfg_attr(feature = "bindings", derive(TS))]
7054pub struct JsonArrayAggFunc {
7055    pub this: Expression,
7056    pub order_by: Option<Vec<Ordered>>,
7057    pub null_handling: Option<JsonNullHandling>,
7058    pub filter: Option<Expression>,
7059}
7060
7061/// JSON_OBJECTAGG function
7062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7063#[cfg_attr(feature = "bindings", derive(TS))]
7064pub struct JsonObjectAggFunc {
7065    pub key: Expression,
7066    pub value: Expression,
7067    pub null_handling: Option<JsonNullHandling>,
7068    pub filter: Option<Expression>,
7069}
7070
7071// ============================================================================
7072// Type Casting Function types
7073// ============================================================================
7074
7075/// CONVERT function (SQL Server style)
7076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7077#[cfg_attr(feature = "bindings", derive(TS))]
7078pub struct ConvertFunc {
7079    pub this: Expression,
7080    pub to: DataType,
7081    pub style: Option<Expression>,
7082}
7083
7084// ============================================================================
7085// Additional Expression types
7086// ============================================================================
7087
7088/// Lambda expression
7089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7090#[cfg_attr(feature = "bindings", derive(TS))]
7091pub struct LambdaExpr {
7092    pub parameters: Vec<Identifier>,
7093    pub body: Expression,
7094    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7095    #[serde(default)]
7096    pub colon: bool,
7097    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7098    /// Maps parameter index to data type
7099    #[serde(default)]
7100    pub parameter_types: Vec<Option<DataType>>,
7101}
7102
7103/// Parameter (parameterized queries)
7104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7105#[cfg_attr(feature = "bindings", derive(TS))]
7106pub struct Parameter {
7107    pub name: Option<String>,
7108    pub index: Option<u32>,
7109    pub style: ParameterStyle,
7110    /// Whether the name was quoted (e.g., @"x" vs @x)
7111    #[serde(default)]
7112    pub quoted: bool,
7113    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7114    #[serde(default)]
7115    pub string_quoted: bool,
7116    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7117    #[serde(default)]
7118    pub expression: Option<String>,
7119}
7120
7121/// Parameter placeholder styles
7122#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7123#[cfg_attr(feature = "bindings", derive(TS))]
7124pub enum ParameterStyle {
7125    Question,     // ?
7126    Dollar,       // $1, $2
7127    DollarBrace,  // ${name} (Databricks, Hive template variables)
7128    Brace,        // {name} (Spark/Databricks widget/template variables)
7129    Colon,        // :name
7130    At,           // @name
7131    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7132    DoubleDollar, // $$name
7133    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7134}
7135
7136/// Placeholder expression
7137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7138#[cfg_attr(feature = "bindings", derive(TS))]
7139pub struct Placeholder {
7140    pub index: Option<u32>,
7141}
7142
7143/// Named argument in function call: name => value or name := value
7144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7145#[cfg_attr(feature = "bindings", derive(TS))]
7146pub struct NamedArgument {
7147    pub name: Identifier,
7148    pub value: Expression,
7149    /// The separator used: `=>`, `:=`, or `=`
7150    pub separator: NamedArgSeparator,
7151}
7152
7153/// Separator style for named arguments
7154#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7155#[cfg_attr(feature = "bindings", derive(TS))]
7156pub enum NamedArgSeparator {
7157    /// `=>` (standard SQL, Snowflake, BigQuery)
7158    DArrow,
7159    /// `:=` (Oracle, MySQL)
7160    ColonEq,
7161    /// `=` (simple equals, some dialects)
7162    Eq,
7163}
7164
7165/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7166/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7168#[cfg_attr(feature = "bindings", derive(TS))]
7169pub struct TableArgument {
7170    /// The keyword prefix: "TABLE" or "MODEL"
7171    pub prefix: String,
7172    /// The table/model reference expression
7173    pub this: Expression,
7174}
7175
7176/// SQL Comment preservation
7177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7178#[cfg_attr(feature = "bindings", derive(TS))]
7179pub struct SqlComment {
7180    pub text: String,
7181    pub is_block: bool,
7182}
7183
7184// ============================================================================
7185// Additional Predicate types
7186// ============================================================================
7187
7188/// SIMILAR TO expression
7189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7190#[cfg_attr(feature = "bindings", derive(TS))]
7191pub struct SimilarToExpr {
7192    pub this: Expression,
7193    pub pattern: Expression,
7194    pub escape: Option<Expression>,
7195    pub not: bool,
7196}
7197
7198/// ANY / ALL quantified expression
7199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7200#[cfg_attr(feature = "bindings", derive(TS))]
7201pub struct QuantifiedExpr {
7202    pub this: Expression,
7203    pub subquery: Expression,
7204    pub op: Option<QuantifiedOp>,
7205}
7206
7207/// Comparison operator for quantified expressions
7208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7209#[cfg_attr(feature = "bindings", derive(TS))]
7210pub enum QuantifiedOp {
7211    Eq,
7212    Neq,
7213    Lt,
7214    Lte,
7215    Gt,
7216    Gte,
7217}
7218
7219/// OVERLAPS expression
7220/// Supports two forms:
7221/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7222/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7224#[cfg_attr(feature = "bindings", derive(TS))]
7225pub struct OverlapsExpr {
7226    /// Left operand for simple binary form
7227    #[serde(skip_serializing_if = "Option::is_none")]
7228    pub this: Option<Expression>,
7229    /// Right operand for simple binary form
7230    #[serde(skip_serializing_if = "Option::is_none")]
7231    pub expression: Option<Expression>,
7232    /// Left range start for full ANSI form
7233    #[serde(skip_serializing_if = "Option::is_none")]
7234    pub left_start: Option<Expression>,
7235    /// Left range end for full ANSI form
7236    #[serde(skip_serializing_if = "Option::is_none")]
7237    pub left_end: Option<Expression>,
7238    /// Right range start for full ANSI form
7239    #[serde(skip_serializing_if = "Option::is_none")]
7240    pub right_start: Option<Expression>,
7241    /// Right range end for full ANSI form
7242    #[serde(skip_serializing_if = "Option::is_none")]
7243    pub right_end: Option<Expression>,
7244}
7245
7246// ============================================================================
7247// Array/Struct/Map access
7248// ============================================================================
7249
7250/// Subscript access (array[index] or map[key])
7251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7252#[cfg_attr(feature = "bindings", derive(TS))]
7253pub struct Subscript {
7254    pub this: Expression,
7255    pub index: Expression,
7256}
7257
7258/// Dot access (struct.field)
7259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7260#[cfg_attr(feature = "bindings", derive(TS))]
7261pub struct DotAccess {
7262    pub this: Expression,
7263    pub field: Identifier,
7264}
7265
7266/// Method call (expr.method(args))
7267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7268#[cfg_attr(feature = "bindings", derive(TS))]
7269pub struct MethodCall {
7270    pub this: Expression,
7271    pub method: Identifier,
7272    pub args: Vec<Expression>,
7273}
7274
7275/// Array slice (array[start:end])
7276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7277#[cfg_attr(feature = "bindings", derive(TS))]
7278pub struct ArraySlice {
7279    pub this: Expression,
7280    pub start: Option<Expression>,
7281    pub end: Option<Expression>,
7282}
7283
7284// ============================================================================
7285// DDL (Data Definition Language) Statements
7286// ============================================================================
7287
7288/// ON COMMIT behavior for temporary tables
7289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7290#[cfg_attr(feature = "bindings", derive(TS))]
7291pub enum OnCommit {
7292    /// ON COMMIT PRESERVE ROWS
7293    PreserveRows,
7294    /// ON COMMIT DELETE ROWS
7295    DeleteRows,
7296}
7297
7298/// CREATE TABLE statement
7299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7300#[cfg_attr(feature = "bindings", derive(TS))]
7301pub struct CreateTable {
7302    pub name: TableRef,
7303    /// ClickHouse: ON CLUSTER clause for distributed DDL
7304    #[serde(default, skip_serializing_if = "Option::is_none")]
7305    pub on_cluster: Option<OnCluster>,
7306    pub columns: Vec<ColumnDef>,
7307    pub constraints: Vec<TableConstraint>,
7308    pub if_not_exists: bool,
7309    pub temporary: bool,
7310    pub or_replace: bool,
7311    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7312    #[serde(default, skip_serializing_if = "Option::is_none")]
7313    pub table_modifier: Option<String>,
7314    pub as_select: Option<Expression>,
7315    /// Whether the AS SELECT was wrapped in parentheses
7316    #[serde(default)]
7317    pub as_select_parenthesized: bool,
7318    /// ON COMMIT behavior for temporary tables
7319    #[serde(default)]
7320    pub on_commit: Option<OnCommit>,
7321    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7322    #[serde(default)]
7323    pub clone_source: Option<TableRef>,
7324    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7325    #[serde(default, skip_serializing_if = "Option::is_none")]
7326    pub clone_at_clause: Option<Expression>,
7327    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7328    #[serde(default)]
7329    pub is_copy: bool,
7330    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7331    #[serde(default)]
7332    pub shallow_clone: bool,
7333    /// Whether this is an explicit DEEP CLONE (Databricks/Delta Lake)
7334    #[serde(default)]
7335    pub deep_clone: bool,
7336    /// Leading comments before the statement
7337    #[serde(default)]
7338    pub leading_comments: Vec<String>,
7339    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7340    #[serde(default)]
7341    pub with_properties: Vec<(String, String)>,
7342    /// Teradata: table options after name before columns (comma-separated)
7343    #[serde(default)]
7344    pub teradata_post_name_options: Vec<String>,
7345    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7346    #[serde(default)]
7347    pub with_data: Option<bool>,
7348    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7349    #[serde(default)]
7350    pub with_statistics: Option<bool>,
7351    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7352    #[serde(default)]
7353    pub teradata_indexes: Vec<TeradataIndex>,
7354    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7355    #[serde(default)]
7356    pub with_cte: Option<With>,
7357    /// Table properties like DEFAULT COLLATE (BigQuery)
7358    #[serde(default)]
7359    pub properties: Vec<Expression>,
7360    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7361    #[serde(default, skip_serializing_if = "Option::is_none")]
7362    pub partition_of: Option<Expression>,
7363    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7364    #[serde(default)]
7365    pub post_table_properties: Vec<Expression>,
7366    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7367    #[serde(default)]
7368    pub mysql_table_options: Vec<(String, String)>,
7369    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7370    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7371    pub inherits: Vec<TableRef>,
7372    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7373    #[serde(default, skip_serializing_if = "Option::is_none")]
7374    pub on_property: Option<OnProperty>,
7375    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7376    #[serde(default)]
7377    pub copy_grants: bool,
7378    /// Snowflake: USING TEMPLATE expression for schema inference
7379    #[serde(default, skip_serializing_if = "Option::is_none")]
7380    pub using_template: Option<Box<Expression>>,
7381    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7382    #[serde(default, skip_serializing_if = "Option::is_none")]
7383    pub rollup: Option<RollupProperty>,
7384    /// ClickHouse: UUID 'xxx' clause after table name
7385    #[serde(default, skip_serializing_if = "Option::is_none")]
7386    pub uuid: Option<String>,
7387    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7388    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7389    /// could appear in other engines.
7390    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7391    pub with_partition_columns: Vec<ColumnDef>,
7392    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7393    /// for external tables that reference a Cloud Resource connection.
7394    #[serde(default, skip_serializing_if = "Option::is_none")]
7395    pub with_connection: Option<TableRef>,
7396}
7397
7398/// Teradata index specification for CREATE TABLE
7399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7400#[cfg_attr(feature = "bindings", derive(TS))]
7401pub struct TeradataIndex {
7402    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7403    pub kind: TeradataIndexKind,
7404    /// Optional index name
7405    pub name: Option<String>,
7406    /// Optional column list
7407    pub columns: Vec<String>,
7408}
7409
7410/// Kind of Teradata index
7411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7412#[cfg_attr(feature = "bindings", derive(TS))]
7413pub enum TeradataIndexKind {
7414    /// NO PRIMARY INDEX
7415    NoPrimary,
7416    /// PRIMARY INDEX
7417    Primary,
7418    /// PRIMARY AMP INDEX
7419    PrimaryAmp,
7420    /// UNIQUE INDEX
7421    Unique,
7422    /// UNIQUE PRIMARY INDEX
7423    UniquePrimary,
7424    /// INDEX (secondary, non-primary)
7425    Secondary,
7426}
7427
7428impl CreateTable {
7429    pub fn new(name: impl Into<String>) -> Self {
7430        Self {
7431            name: TableRef::new(name),
7432            on_cluster: None,
7433            columns: Vec::new(),
7434            constraints: Vec::new(),
7435            if_not_exists: false,
7436            temporary: false,
7437            or_replace: false,
7438            table_modifier: None,
7439            as_select: None,
7440            as_select_parenthesized: false,
7441            on_commit: None,
7442            clone_source: None,
7443            clone_at_clause: None,
7444            shallow_clone: false,
7445            deep_clone: false,
7446            is_copy: false,
7447            leading_comments: Vec::new(),
7448            with_properties: Vec::new(),
7449            teradata_post_name_options: Vec::new(),
7450            with_data: None,
7451            with_statistics: None,
7452            teradata_indexes: Vec::new(),
7453            with_cte: None,
7454            properties: Vec::new(),
7455            partition_of: None,
7456            post_table_properties: Vec::new(),
7457            mysql_table_options: Vec::new(),
7458            inherits: Vec::new(),
7459            on_property: None,
7460            copy_grants: false,
7461            using_template: None,
7462            rollup: None,
7463            uuid: None,
7464            with_partition_columns: Vec::new(),
7465            with_connection: None,
7466        }
7467    }
7468}
7469
7470/// Sort order for PRIMARY KEY ASC/DESC
7471#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7472#[cfg_attr(feature = "bindings", derive(TS))]
7473pub enum SortOrder {
7474    Asc,
7475    Desc,
7476}
7477
7478/// Type of column constraint for tracking order
7479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7480#[cfg_attr(feature = "bindings", derive(TS))]
7481pub enum ConstraintType {
7482    NotNull,
7483    Null,
7484    PrimaryKey,
7485    Unique,
7486    Default,
7487    AutoIncrement,
7488    Collate,
7489    Comment,
7490    References,
7491    Check,
7492    GeneratedAsIdentity,
7493    /// Snowflake: TAG (key='value', ...)
7494    Tags,
7495    /// Computed/generated column
7496    ComputedColumn,
7497    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7498    GeneratedAsRow,
7499    /// MySQL: ON UPDATE expression
7500    OnUpdate,
7501    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7502    Path,
7503    /// Redshift: ENCODE encoding_type
7504    Encode,
7505}
7506
7507/// Column definition in CREATE TABLE
7508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7509#[cfg_attr(feature = "bindings", derive(TS))]
7510pub struct ColumnDef {
7511    pub name: Identifier,
7512    pub data_type: DataType,
7513    pub nullable: Option<bool>,
7514    pub default: Option<Expression>,
7515    pub primary_key: bool,
7516    /// Sort order for PRIMARY KEY (ASC/DESC)
7517    #[serde(default)]
7518    pub primary_key_order: Option<SortOrder>,
7519    pub unique: bool,
7520    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7521    #[serde(default)]
7522    pub unique_nulls_not_distinct: bool,
7523    pub auto_increment: bool,
7524    pub comment: Option<String>,
7525    pub constraints: Vec<ColumnConstraint>,
7526    /// Track original order of constraints for accurate regeneration
7527    #[serde(default)]
7528    pub constraint_order: Vec<ConstraintType>,
7529    /// Teradata: FORMAT 'pattern'
7530    #[serde(default)]
7531    pub format: Option<String>,
7532    /// Teradata: TITLE 'title'
7533    #[serde(default)]
7534    pub title: Option<String>,
7535    /// Teradata: INLINE LENGTH n
7536    #[serde(default)]
7537    pub inline_length: Option<u64>,
7538    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7539    #[serde(default)]
7540    pub compress: Option<Vec<Expression>>,
7541    /// Teradata: CHARACTER SET name
7542    #[serde(default)]
7543    pub character_set: Option<String>,
7544    /// Teradata: UPPERCASE
7545    #[serde(default)]
7546    pub uppercase: bool,
7547    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7548    #[serde(default)]
7549    pub casespecific: Option<bool>,
7550    /// Snowflake: AUTOINCREMENT START value
7551    #[serde(default)]
7552    pub auto_increment_start: Option<Box<Expression>>,
7553    /// Snowflake: AUTOINCREMENT INCREMENT value
7554    #[serde(default)]
7555    pub auto_increment_increment: Option<Box<Expression>>,
7556    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7557    #[serde(default)]
7558    pub auto_increment_order: Option<bool>,
7559    /// MySQL: UNSIGNED modifier
7560    #[serde(default)]
7561    pub unsigned: bool,
7562    /// MySQL: ZEROFILL modifier
7563    #[serde(default)]
7564    pub zerofill: bool,
7565    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7566    #[serde(default, skip_serializing_if = "Option::is_none")]
7567    pub on_update: Option<Expression>,
7568    /// MySQL: column VISIBLE/INVISIBLE modifier.
7569    #[serde(default, skip_serializing_if = "Option::is_none")]
7570    pub visible: Option<bool>,
7571    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7572    #[serde(default, skip_serializing_if = "Option::is_none")]
7573    pub unique_constraint_name: Option<String>,
7574    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7575    #[serde(default, skip_serializing_if = "Option::is_none")]
7576    pub not_null_constraint_name: Option<String>,
7577    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7578    #[serde(default, skip_serializing_if = "Option::is_none")]
7579    pub primary_key_constraint_name: Option<String>,
7580    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7581    #[serde(default, skip_serializing_if = "Option::is_none")]
7582    pub check_constraint_name: Option<String>,
7583    /// BigQuery: OPTIONS (key=value, ...) on column
7584    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7585    pub options: Vec<Expression>,
7586    /// SQLite: Column definition without explicit type
7587    #[serde(default)]
7588    pub no_type: bool,
7589    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7590    #[serde(default, skip_serializing_if = "Option::is_none")]
7591    pub encoding: Option<String>,
7592    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7593    #[serde(default, skip_serializing_if = "Option::is_none")]
7594    pub codec: Option<String>,
7595    /// ClickHouse: EPHEMERAL [expr] modifier
7596    #[serde(default, skip_serializing_if = "Option::is_none")]
7597    pub ephemeral: Option<Option<Box<Expression>>>,
7598    /// ClickHouse: MATERIALIZED expr modifier
7599    #[serde(default, skip_serializing_if = "Option::is_none")]
7600    pub materialized_expr: Option<Box<Expression>>,
7601    /// ClickHouse: ALIAS expr modifier
7602    #[serde(default, skip_serializing_if = "Option::is_none")]
7603    pub alias_expr: Option<Box<Expression>>,
7604    /// ClickHouse: TTL expr modifier on columns
7605    #[serde(default, skip_serializing_if = "Option::is_none")]
7606    pub ttl_expr: Option<Box<Expression>>,
7607    /// TSQL: NOT FOR REPLICATION
7608    #[serde(default)]
7609    pub not_for_replication: bool,
7610}
7611
7612impl ColumnDef {
7613    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7614        Self {
7615            name: Identifier::new(name),
7616            data_type,
7617            nullable: None,
7618            default: None,
7619            primary_key: false,
7620            primary_key_order: None,
7621            unique: false,
7622            unique_nulls_not_distinct: false,
7623            auto_increment: false,
7624            comment: None,
7625            constraints: Vec::new(),
7626            constraint_order: Vec::new(),
7627            format: None,
7628            title: None,
7629            inline_length: None,
7630            compress: None,
7631            character_set: None,
7632            uppercase: false,
7633            casespecific: None,
7634            auto_increment_start: None,
7635            auto_increment_increment: None,
7636            auto_increment_order: None,
7637            unsigned: false,
7638            zerofill: false,
7639            on_update: None,
7640            visible: None,
7641            unique_constraint_name: None,
7642            not_null_constraint_name: None,
7643            primary_key_constraint_name: None,
7644            check_constraint_name: None,
7645            options: Vec::new(),
7646            no_type: false,
7647            encoding: None,
7648            codec: None,
7649            ephemeral: None,
7650            materialized_expr: None,
7651            alias_expr: None,
7652            ttl_expr: None,
7653            not_for_replication: false,
7654        }
7655    }
7656}
7657
7658/// Column-level constraint
7659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7660#[cfg_attr(feature = "bindings", derive(TS))]
7661pub enum ColumnConstraint {
7662    NotNull,
7663    Null,
7664    Unique,
7665    PrimaryKey,
7666    Default(Expression),
7667    Check(Expression),
7668    References(ForeignKeyRef),
7669    GeneratedAsIdentity(GeneratedAsIdentity),
7670    Collate(Identifier),
7671    Comment(String),
7672    /// Snowflake: TAG (key='value', ...)
7673    Tags(Tags),
7674    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7675    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7676    ComputedColumn(ComputedColumn),
7677    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7678    GeneratedAsRow(GeneratedAsRow),
7679    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7680    Path(Expression),
7681}
7682
7683/// Computed/generated column constraint
7684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7685#[cfg_attr(feature = "bindings", derive(TS))]
7686pub struct ComputedColumn {
7687    /// The expression that computes the column value
7688    pub expression: Box<Expression>,
7689    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7690    #[serde(default)]
7691    pub persisted: bool,
7692    /// NOT NULL (TSQL computed columns)
7693    #[serde(default)]
7694    pub not_null: bool,
7695    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7696    /// When None, defaults to dialect-appropriate output
7697    #[serde(default)]
7698    pub persistence_kind: Option<String>,
7699    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7700    #[serde(default, skip_serializing_if = "Option::is_none")]
7701    pub data_type: Option<DataType>,
7702}
7703
7704/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7706#[cfg_attr(feature = "bindings", derive(TS))]
7707pub struct GeneratedAsRow {
7708    /// true = ROW START, false = ROW END
7709    pub start: bool,
7710    /// HIDDEN modifier
7711    #[serde(default)]
7712    pub hidden: bool,
7713}
7714
7715/// Generated identity column constraint
7716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7717#[cfg_attr(feature = "bindings", derive(TS))]
7718pub struct GeneratedAsIdentity {
7719    /// True for ALWAYS, False for BY DEFAULT
7720    pub always: bool,
7721    /// ON NULL (only valid with BY DEFAULT)
7722    pub on_null: bool,
7723    /// START WITH value
7724    pub start: Option<Box<Expression>>,
7725    /// INCREMENT BY value
7726    pub increment: Option<Box<Expression>>,
7727    /// MINVALUE
7728    pub minvalue: Option<Box<Expression>>,
7729    /// MAXVALUE
7730    pub maxvalue: Option<Box<Expression>>,
7731    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7732    pub cycle: Option<bool>,
7733}
7734
7735/// Constraint modifiers (shared between table-level constraints)
7736#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7737#[cfg_attr(feature = "bindings", derive(TS))]
7738pub struct ConstraintModifiers {
7739    /// ENFORCED / NOT ENFORCED
7740    pub enforced: Option<bool>,
7741    /// DEFERRABLE / NOT DEFERRABLE
7742    pub deferrable: Option<bool>,
7743    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7744    pub initially_deferred: Option<bool>,
7745    /// NORELY (Oracle)
7746    pub norely: bool,
7747    /// RELY (Oracle)
7748    pub rely: bool,
7749    /// USING index type (MySQL): BTREE or HASH
7750    #[serde(default)]
7751    pub using: Option<String>,
7752    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7753    #[serde(default)]
7754    pub using_before_columns: bool,
7755    /// MySQL index COMMENT 'text'
7756    #[serde(default, skip_serializing_if = "Option::is_none")]
7757    pub comment: Option<String>,
7758    /// MySQL index VISIBLE/INVISIBLE
7759    #[serde(default, skip_serializing_if = "Option::is_none")]
7760    pub visible: Option<bool>,
7761    /// MySQL ENGINE_ATTRIBUTE = 'value'
7762    #[serde(default, skip_serializing_if = "Option::is_none")]
7763    pub engine_attribute: Option<String>,
7764    /// MySQL WITH PARSER name
7765    #[serde(default, skip_serializing_if = "Option::is_none")]
7766    pub with_parser: Option<String>,
7767    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7768    #[serde(default)]
7769    pub not_valid: bool,
7770    /// TSQL CLUSTERED/NONCLUSTERED modifier
7771    #[serde(default, skip_serializing_if = "Option::is_none")]
7772    pub clustered: Option<String>,
7773    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7774    #[serde(default, skip_serializing_if = "Option::is_none")]
7775    pub on_conflict: Option<String>,
7776    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7777    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7778    pub with_options: Vec<(String, String)>,
7779    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7780    #[serde(default, skip_serializing_if = "Option::is_none")]
7781    pub on_filegroup: Option<Identifier>,
7782}
7783
7784/// Table-level constraint
7785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7786#[cfg_attr(feature = "bindings", derive(TS))]
7787pub enum TableConstraint {
7788    PrimaryKey {
7789        name: Option<Identifier>,
7790        columns: Vec<Identifier>,
7791        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7792        #[serde(default)]
7793        include_columns: Vec<Identifier>,
7794        #[serde(default)]
7795        modifiers: ConstraintModifiers,
7796        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7797        #[serde(default)]
7798        has_constraint_keyword: bool,
7799    },
7800    Unique {
7801        name: Option<Identifier>,
7802        columns: Vec<Identifier>,
7803        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7804        #[serde(default)]
7805        columns_parenthesized: bool,
7806        #[serde(default)]
7807        modifiers: ConstraintModifiers,
7808        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7809        #[serde(default)]
7810        has_constraint_keyword: bool,
7811        /// PostgreSQL 15+: NULLS NOT DISTINCT
7812        #[serde(default)]
7813        nulls_not_distinct: bool,
7814    },
7815    ForeignKey {
7816        name: Option<Identifier>,
7817        columns: Vec<Identifier>,
7818        #[serde(default)]
7819        references: Option<ForeignKeyRef>,
7820        /// ON DELETE action when REFERENCES is absent
7821        #[serde(default)]
7822        on_delete: Option<ReferentialAction>,
7823        /// ON UPDATE action when REFERENCES is absent
7824        #[serde(default)]
7825        on_update: Option<ReferentialAction>,
7826        #[serde(default)]
7827        modifiers: ConstraintModifiers,
7828    },
7829    Check {
7830        name: Option<Identifier>,
7831        expression: Expression,
7832        #[serde(default)]
7833        modifiers: ConstraintModifiers,
7834    },
7835    /// ClickHouse ASSUME constraint (query optimization assumption)
7836    Assume {
7837        name: Option<Identifier>,
7838        expression: Expression,
7839    },
7840    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7841    Default {
7842        name: Option<Identifier>,
7843        expression: Expression,
7844        column: Identifier,
7845    },
7846    /// INDEX / KEY constraint (MySQL)
7847    Index {
7848        name: Option<Identifier>,
7849        columns: Vec<Identifier>,
7850        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7851        #[serde(default)]
7852        kind: Option<String>,
7853        #[serde(default)]
7854        modifiers: ConstraintModifiers,
7855        /// True if KEY keyword was used instead of INDEX
7856        #[serde(default)]
7857        use_key_keyword: bool,
7858        /// ClickHouse: indexed expression (instead of columns)
7859        #[serde(default, skip_serializing_if = "Option::is_none")]
7860        expression: Option<Box<Expression>>,
7861        /// ClickHouse: TYPE type_func(args)
7862        #[serde(default, skip_serializing_if = "Option::is_none")]
7863        index_type: Option<Box<Expression>>,
7864        /// ClickHouse: GRANULARITY n
7865        #[serde(default, skip_serializing_if = "Option::is_none")]
7866        granularity: Option<Box<Expression>>,
7867    },
7868    /// ClickHouse PROJECTION definition
7869    Projection {
7870        name: Identifier,
7871        expression: Expression,
7872    },
7873    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7874    Like {
7875        source: TableRef,
7876        /// Options as (INCLUDING|EXCLUDING, property) pairs
7877        options: Vec<(LikeOptionAction, String)>,
7878    },
7879    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7880    PeriodForSystemTime {
7881        start_col: Identifier,
7882        end_col: Identifier,
7883    },
7884    /// PostgreSQL EXCLUDE constraint
7885    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7886    Exclude {
7887        name: Option<Identifier>,
7888        /// Index access method (gist, btree, etc.)
7889        #[serde(default)]
7890        using: Option<String>,
7891        /// Elements: (expression, operator) pairs
7892        elements: Vec<ExcludeElement>,
7893        /// INCLUDE columns
7894        #[serde(default)]
7895        include_columns: Vec<Identifier>,
7896        /// WHERE predicate
7897        #[serde(default)]
7898        where_clause: Option<Box<Expression>>,
7899        /// WITH (storage_parameters)
7900        #[serde(default)]
7901        with_params: Vec<(String, String)>,
7902        /// USING INDEX TABLESPACE tablespace_name
7903        #[serde(default)]
7904        using_index_tablespace: Option<String>,
7905        #[serde(default)]
7906        modifiers: ConstraintModifiers,
7907    },
7908    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7909    Tags(Tags),
7910    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7911    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7912    /// for all deferrable constraints in the table
7913    InitiallyDeferred {
7914        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7915        deferred: bool,
7916    },
7917}
7918
7919/// Element in an EXCLUDE constraint: expression WITH operator
7920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7921#[cfg_attr(feature = "bindings", derive(TS))]
7922pub struct ExcludeElement {
7923    /// The column expression (may include operator class, ordering, nulls)
7924    pub expression: String,
7925    /// The operator (e.g., &&, =)
7926    pub operator: String,
7927}
7928
7929/// Action for LIKE clause options
7930#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7931#[cfg_attr(feature = "bindings", derive(TS))]
7932pub enum LikeOptionAction {
7933    Including,
7934    Excluding,
7935}
7936
7937/// MATCH type for foreign keys
7938#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7939#[cfg_attr(feature = "bindings", derive(TS))]
7940pub enum MatchType {
7941    Full,
7942    Partial,
7943    Simple,
7944}
7945
7946/// Foreign key reference
7947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7948#[cfg_attr(feature = "bindings", derive(TS))]
7949pub struct ForeignKeyRef {
7950    pub table: TableRef,
7951    pub columns: Vec<Identifier>,
7952    pub on_delete: Option<ReferentialAction>,
7953    pub on_update: Option<ReferentialAction>,
7954    /// True if ON UPDATE appears before ON DELETE in the original SQL
7955    #[serde(default)]
7956    pub on_update_first: bool,
7957    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7958    #[serde(default)]
7959    pub match_type: Option<MatchType>,
7960    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7961    #[serde(default)]
7962    pub match_after_actions: bool,
7963    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7964    #[serde(default)]
7965    pub constraint_name: Option<String>,
7966    /// DEFERRABLE / NOT DEFERRABLE
7967    #[serde(default)]
7968    pub deferrable: Option<bool>,
7969    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7970    #[serde(default)]
7971    pub has_foreign_key_keywords: bool,
7972}
7973
7974/// Referential action for foreign keys
7975#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7976#[cfg_attr(feature = "bindings", derive(TS))]
7977pub enum ReferentialAction {
7978    Cascade,
7979    SetNull,
7980    SetDefault,
7981    Restrict,
7982    NoAction,
7983}
7984
7985/// DROP TABLE statement
7986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7987#[cfg_attr(feature = "bindings", derive(TS))]
7988pub struct DropTable {
7989    pub names: Vec<TableRef>,
7990    pub if_exists: bool,
7991    pub cascade: bool,
7992    /// Oracle: CASCADE CONSTRAINTS
7993    #[serde(default)]
7994    pub cascade_constraints: bool,
7995    /// Oracle: PURGE
7996    #[serde(default)]
7997    pub purge: bool,
7998    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7999    #[serde(default)]
8000    pub leading_comments: Vec<String>,
8001    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
8002    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
8003    #[serde(default, skip_serializing_if = "Option::is_none")]
8004    pub object_id_args: Option<String>,
8005    /// ClickHouse: SYNC modifier
8006    #[serde(default)]
8007    pub sync: bool,
8008    /// Snowflake: DROP ICEBERG TABLE
8009    #[serde(default)]
8010    pub iceberg: bool,
8011    /// RESTRICT modifier (opposite of CASCADE)
8012    #[serde(default)]
8013    pub restrict: bool,
8014}
8015
8016impl DropTable {
8017    pub fn new(name: impl Into<String>) -> Self {
8018        Self {
8019            names: vec![TableRef::new(name)],
8020            if_exists: false,
8021            cascade: false,
8022            cascade_constraints: false,
8023            purge: false,
8024            leading_comments: Vec::new(),
8025            object_id_args: None,
8026            sync: false,
8027            iceberg: false,
8028            restrict: false,
8029        }
8030    }
8031}
8032
8033/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
8034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8035#[cfg_attr(feature = "bindings", derive(TS))]
8036pub struct Undrop {
8037    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
8038    pub kind: String,
8039    /// The object name
8040    pub name: TableRef,
8041    /// IF EXISTS clause
8042    #[serde(default)]
8043    pub if_exists: bool,
8044}
8045
8046/// ALTER TABLE statement
8047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8048#[cfg_attr(feature = "bindings", derive(TS))]
8049pub struct AlterTable {
8050    pub name: TableRef,
8051    pub actions: Vec<AlterTableAction>,
8052    /// IF EXISTS clause
8053    #[serde(default)]
8054    pub if_exists: bool,
8055    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8056    #[serde(default, skip_serializing_if = "Option::is_none")]
8057    pub algorithm: Option<String>,
8058    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8059    #[serde(default, skip_serializing_if = "Option::is_none")]
8060    pub lock: Option<String>,
8061    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8062    #[serde(default, skip_serializing_if = "Option::is_none")]
8063    pub with_check: Option<String>,
8064    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8065    #[serde(default, skip_serializing_if = "Option::is_none")]
8066    pub partition: Option<Vec<(Identifier, Expression)>>,
8067    /// ClickHouse: ON CLUSTER clause for distributed DDL
8068    #[serde(default, skip_serializing_if = "Option::is_none")]
8069    pub on_cluster: Option<OnCluster>,
8070    /// Snowflake: ALTER ICEBERG TABLE
8071    #[serde(default, skip_serializing_if = "Option::is_none")]
8072    pub table_modifier: Option<String>,
8073}
8074
8075impl AlterTable {
8076    pub fn new(name: impl Into<String>) -> Self {
8077        Self {
8078            name: TableRef::new(name),
8079            actions: Vec::new(),
8080            if_exists: false,
8081            algorithm: None,
8082            lock: None,
8083            with_check: None,
8084            partition: None,
8085            on_cluster: None,
8086            table_modifier: None,
8087        }
8088    }
8089}
8090
8091/// Column position for ADD COLUMN (MySQL/MariaDB)
8092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8093#[cfg_attr(feature = "bindings", derive(TS))]
8094pub enum ColumnPosition {
8095    First,
8096    After(Identifier),
8097}
8098
8099/// Actions for ALTER TABLE
8100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8101#[cfg_attr(feature = "bindings", derive(TS))]
8102pub enum AlterTableAction {
8103    AddColumn {
8104        column: ColumnDef,
8105        if_not_exists: bool,
8106        position: Option<ColumnPosition>,
8107    },
8108    DropColumn {
8109        name: Identifier,
8110        if_exists: bool,
8111        cascade: bool,
8112    },
8113    RenameColumn {
8114        old_name: Identifier,
8115        new_name: Identifier,
8116        if_exists: bool,
8117    },
8118    AlterColumn {
8119        name: Identifier,
8120        action: AlterColumnAction,
8121        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8122        #[serde(default)]
8123        use_modify_keyword: bool,
8124    },
8125    RenameTable(TableRef),
8126    AddConstraint(TableConstraint),
8127    DropConstraint {
8128        name: Identifier,
8129        if_exists: bool,
8130    },
8131    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8132    DropForeignKey {
8133        name: Identifier,
8134    },
8135    /// DROP PARTITION action (Hive/BigQuery)
8136    DropPartition {
8137        /// List of partitions to drop (each partition is a list of key=value pairs)
8138        partitions: Vec<Vec<(Identifier, Expression)>>,
8139        if_exists: bool,
8140    },
8141    /// ADD PARTITION action (Hive/Spark)
8142    AddPartition {
8143        /// The partition expression
8144        partition: Expression,
8145        if_not_exists: bool,
8146        location: Option<Expression>,
8147    },
8148    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8149    Delete {
8150        where_clause: Expression,
8151    },
8152    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8153    SwapWith(TableRef),
8154    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8155    SetProperty {
8156        properties: Vec<(String, Expression)>,
8157    },
8158    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8159    UnsetProperty {
8160        properties: Vec<String>,
8161    },
8162    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8163    ClusterBy {
8164        expressions: Vec<Expression>,
8165    },
8166    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8167    SetTag {
8168        expressions: Vec<(String, Expression)>,
8169    },
8170    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8171    UnsetTag {
8172        names: Vec<String>,
8173    },
8174    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8175    SetOptions {
8176        expressions: Vec<Expression>,
8177    },
8178    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8179    AlterIndex {
8180        name: Identifier,
8181        visible: bool,
8182    },
8183    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8184    SetAttribute {
8185        attribute: String,
8186    },
8187    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8188    SetStageFileFormat {
8189        options: Option<Expression>,
8190    },
8191    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8192    SetStageCopyOptions {
8193        options: Option<Expression>,
8194    },
8195    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8196    AddColumns {
8197        columns: Vec<ColumnDef>,
8198        cascade: bool,
8199    },
8200    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8201    DropColumns {
8202        names: Vec<Identifier>,
8203    },
8204    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8205    /// In SingleStore, data_type can be omitted for simple column renames
8206    ChangeColumn {
8207        old_name: Identifier,
8208        new_name: Identifier,
8209        #[serde(default, skip_serializing_if = "Option::is_none")]
8210        data_type: Option<DataType>,
8211        comment: Option<String>,
8212        #[serde(default)]
8213        cascade: bool,
8214    },
8215    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8216    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8217    AlterSortKey {
8218        /// AUTO or NONE keyword
8219        this: Option<String>,
8220        /// Column list for (col1, col2) syntax
8221        expressions: Vec<Expression>,
8222        /// Whether COMPOUND keyword was present
8223        compound: bool,
8224    },
8225    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8226    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8227    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8228    AlterDistStyle {
8229        /// Distribution style: ALL, EVEN, AUTO, or KEY
8230        style: String,
8231        /// DISTKEY column (only when style is KEY)
8232        distkey: Option<Identifier>,
8233    },
8234    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8235    SetTableProperties {
8236        properties: Vec<(Expression, Expression)>,
8237    },
8238    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8239    SetLocation {
8240        location: String,
8241    },
8242    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8243    SetFileFormat {
8244        format: String,
8245    },
8246    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8247    ReplacePartition {
8248        partition: Expression,
8249        source: Option<Box<Expression>>,
8250    },
8251    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8252    Raw {
8253        sql: String,
8254    },
8255}
8256
8257/// Actions for ALTER COLUMN
8258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8259#[cfg_attr(feature = "bindings", derive(TS))]
8260pub enum AlterColumnAction {
8261    SetDataType {
8262        data_type: DataType,
8263        /// USING expression for type conversion (PostgreSQL)
8264        using: Option<Expression>,
8265        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8266        #[serde(default, skip_serializing_if = "Option::is_none")]
8267        collate: Option<String>,
8268    },
8269    SetDefault(Expression),
8270    DropDefault,
8271    SetNotNull,
8272    DropNotNull,
8273    /// Set column comment
8274    Comment(String),
8275    /// MySQL: SET VISIBLE
8276    SetVisible,
8277    /// MySQL: SET INVISIBLE
8278    SetInvisible,
8279}
8280
8281/// CREATE INDEX statement
8282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8283#[cfg_attr(feature = "bindings", derive(TS))]
8284pub struct CreateIndex {
8285    pub name: Identifier,
8286    pub table: TableRef,
8287    pub columns: Vec<IndexColumn>,
8288    pub unique: bool,
8289    pub if_not_exists: bool,
8290    pub using: Option<String>,
8291    /// TSQL CLUSTERED/NONCLUSTERED modifier
8292    #[serde(default)]
8293    pub clustered: Option<String>,
8294    /// PostgreSQL CONCURRENTLY modifier
8295    #[serde(default)]
8296    pub concurrently: bool,
8297    /// PostgreSQL WHERE clause for partial indexes
8298    #[serde(default)]
8299    pub where_clause: Option<Box<Expression>>,
8300    /// PostgreSQL INCLUDE columns
8301    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8302    pub include_columns: Vec<Identifier>,
8303    /// TSQL WITH options (e.g., allow_page_locks=on)
8304    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8305    pub with_options: Vec<(String, String)>,
8306    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8307    #[serde(default)]
8308    pub on_filegroup: Option<String>,
8309}
8310
8311impl CreateIndex {
8312    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8313        Self {
8314            name: Identifier::new(name),
8315            table: TableRef::new(table),
8316            columns: Vec::new(),
8317            unique: false,
8318            if_not_exists: false,
8319            using: None,
8320            clustered: None,
8321            concurrently: false,
8322            where_clause: None,
8323            include_columns: Vec::new(),
8324            with_options: Vec::new(),
8325            on_filegroup: None,
8326        }
8327    }
8328}
8329
8330/// Index column specification
8331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8332#[cfg_attr(feature = "bindings", derive(TS))]
8333pub struct IndexColumn {
8334    pub column: Identifier,
8335    pub desc: bool,
8336    /// Explicit ASC keyword was present
8337    #[serde(default)]
8338    pub asc: bool,
8339    pub nulls_first: Option<bool>,
8340    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8341    #[serde(default, skip_serializing_if = "Option::is_none")]
8342    pub opclass: Option<String>,
8343}
8344
8345/// DROP INDEX statement
8346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8347#[cfg_attr(feature = "bindings", derive(TS))]
8348pub struct DropIndex {
8349    pub name: Identifier,
8350    pub table: Option<TableRef>,
8351    pub if_exists: bool,
8352    /// PostgreSQL CONCURRENTLY modifier
8353    #[serde(default)]
8354    pub concurrently: bool,
8355}
8356
8357impl DropIndex {
8358    pub fn new(name: impl Into<String>) -> Self {
8359        Self {
8360            name: Identifier::new(name),
8361            table: None,
8362            if_exists: false,
8363            concurrently: false,
8364        }
8365    }
8366}
8367
8368/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8370#[cfg_attr(feature = "bindings", derive(TS))]
8371pub struct ViewColumn {
8372    pub name: Identifier,
8373    pub comment: Option<String>,
8374    /// BigQuery: OPTIONS (key=value, ...) on column
8375    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8376    pub options: Vec<Expression>,
8377}
8378
8379impl ViewColumn {
8380    pub fn new(name: impl Into<String>) -> Self {
8381        Self {
8382            name: Identifier::new(name),
8383            comment: None,
8384            options: Vec::new(),
8385        }
8386    }
8387
8388    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8389        Self {
8390            name: Identifier::new(name),
8391            comment: Some(comment.into()),
8392            options: Vec::new(),
8393        }
8394    }
8395}
8396
8397/// CREATE VIEW statement
8398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8399#[cfg_attr(feature = "bindings", derive(TS))]
8400pub struct CreateView {
8401    pub name: TableRef,
8402    pub columns: Vec<ViewColumn>,
8403    pub query: Expression,
8404    pub or_replace: bool,
8405    /// TSQL: CREATE OR ALTER
8406    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8407    pub or_alter: bool,
8408    pub if_not_exists: bool,
8409    pub materialized: bool,
8410    pub temporary: bool,
8411    /// Snowflake: SECURE VIEW
8412    #[serde(default)]
8413    pub secure: bool,
8414    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8415    #[serde(skip_serializing_if = "Option::is_none")]
8416    pub algorithm: Option<String>,
8417    /// MySQL: DEFINER=user@host
8418    #[serde(skip_serializing_if = "Option::is_none")]
8419    pub definer: Option<String>,
8420    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8421    #[serde(skip_serializing_if = "Option::is_none")]
8422    pub security: Option<FunctionSecurity>,
8423    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8424    #[serde(default = "default_true")]
8425    pub security_sql_style: bool,
8426    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8427    #[serde(default)]
8428    pub security_after_name: bool,
8429    /// Whether the query was parenthesized: AS (SELECT ...)
8430    #[serde(default)]
8431    pub query_parenthesized: bool,
8432    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8433    #[serde(skip_serializing_if = "Option::is_none")]
8434    pub locking_mode: Option<String>,
8435    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8436    #[serde(skip_serializing_if = "Option::is_none")]
8437    pub locking_access: Option<String>,
8438    /// Snowflake: COPY GRANTS
8439    #[serde(default)]
8440    pub copy_grants: bool,
8441    /// Snowflake: COMMENT = 'text'
8442    #[serde(skip_serializing_if = "Option::is_none", default)]
8443    pub comment: Option<String>,
8444    /// Snowflake: WITH ROW ACCESS POLICY ... clause
8445    #[serde(skip_serializing_if = "Option::is_none", default)]
8446    pub row_access_policy: Option<String>,
8447    /// Snowflake: TAG (name='value', ...)
8448    #[serde(default)]
8449    pub tags: Vec<(String, String)>,
8450    /// BigQuery: OPTIONS (key=value, ...)
8451    #[serde(default)]
8452    pub options: Vec<Expression>,
8453    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8454    #[serde(skip_serializing_if = "Option::is_none", default)]
8455    pub build: Option<String>,
8456    /// Doris: REFRESH property for materialized views
8457    #[serde(skip_serializing_if = "Option::is_none", default)]
8458    pub refresh: Option<Box<RefreshTriggerProperty>>,
8459    /// Doris: Schema with typed column definitions for materialized views
8460    /// This is used instead of `columns` when the view has typed column definitions
8461    #[serde(skip_serializing_if = "Option::is_none", default)]
8462    pub schema: Option<Box<Schema>>,
8463    /// Doris: KEY (columns) for materialized views
8464    #[serde(skip_serializing_if = "Option::is_none", default)]
8465    pub unique_key: Option<Box<UniqueKeyProperty>>,
8466    /// Redshift: WITH NO SCHEMA BINDING
8467    #[serde(default)]
8468    pub no_schema_binding: bool,
8469    /// Redshift: AUTO REFRESH YES|NO for materialized views
8470    #[serde(skip_serializing_if = "Option::is_none", default)]
8471    pub auto_refresh: Option<bool>,
8472    /// ClickHouse: POPULATE / EMPTY before AS in materialized views
8473    #[serde(skip_serializing_if = "Option::is_none", default)]
8474    pub clickhouse_population: Option<String>,
8475    /// ClickHouse: ON CLUSTER clause
8476    #[serde(default, skip_serializing_if = "Option::is_none")]
8477    pub on_cluster: Option<OnCluster>,
8478    /// ClickHouse: TO destination_table
8479    #[serde(default, skip_serializing_if = "Option::is_none")]
8480    pub to_table: Option<TableRef>,
8481    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8482    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8483    pub table_properties: Vec<Expression>,
8484}
8485
8486impl CreateView {
8487    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8488        Self {
8489            name: TableRef::new(name),
8490            columns: Vec::new(),
8491            query,
8492            or_replace: false,
8493            or_alter: false,
8494            if_not_exists: false,
8495            materialized: false,
8496            temporary: false,
8497            secure: false,
8498            algorithm: None,
8499            definer: None,
8500            security: None,
8501            security_sql_style: true,
8502            security_after_name: false,
8503            query_parenthesized: false,
8504            locking_mode: None,
8505            locking_access: None,
8506            copy_grants: false,
8507            comment: None,
8508            row_access_policy: None,
8509            tags: Vec::new(),
8510            options: Vec::new(),
8511            build: None,
8512            refresh: None,
8513            schema: None,
8514            unique_key: None,
8515            no_schema_binding: false,
8516            auto_refresh: None,
8517            clickhouse_population: None,
8518            on_cluster: None,
8519            to_table: None,
8520            table_properties: Vec::new(),
8521        }
8522    }
8523}
8524
8525/// DROP VIEW statement
8526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8527#[cfg_attr(feature = "bindings", derive(TS))]
8528pub struct DropView {
8529    pub name: TableRef,
8530    pub if_exists: bool,
8531    pub materialized: bool,
8532}
8533
8534impl DropView {
8535    pub fn new(name: impl Into<String>) -> Self {
8536        Self {
8537            name: TableRef::new(name),
8538            if_exists: false,
8539            materialized: false,
8540        }
8541    }
8542}
8543
8544/// TRUNCATE TABLE statement
8545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8546#[cfg_attr(feature = "bindings", derive(TS))]
8547pub struct Truncate {
8548    /// Target of TRUNCATE (TABLE vs DATABASE)
8549    #[serde(default)]
8550    pub target: TruncateTarget,
8551    /// IF EXISTS clause
8552    #[serde(default)]
8553    pub if_exists: bool,
8554    pub table: TableRef,
8555    /// ClickHouse: ON CLUSTER clause for distributed DDL
8556    #[serde(default, skip_serializing_if = "Option::is_none")]
8557    pub on_cluster: Option<OnCluster>,
8558    pub cascade: bool,
8559    /// Additional tables for multi-table TRUNCATE
8560    #[serde(default)]
8561    pub extra_tables: Vec<TruncateTableEntry>,
8562    /// RESTART IDENTITY or CONTINUE IDENTITY
8563    #[serde(default)]
8564    pub identity: Option<TruncateIdentity>,
8565    /// RESTRICT option (alternative to CASCADE)
8566    #[serde(default)]
8567    pub restrict: bool,
8568    /// Hive PARTITION clause: PARTITION(key=value, ...)
8569    #[serde(default, skip_serializing_if = "Option::is_none")]
8570    pub partition: Option<Box<Expression>>,
8571}
8572
8573/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8575#[cfg_attr(feature = "bindings", derive(TS))]
8576pub struct TruncateTableEntry {
8577    pub table: TableRef,
8578    /// Whether the table has a * suffix (inherit children)
8579    #[serde(default)]
8580    pub star: bool,
8581}
8582
8583/// TRUNCATE target type
8584#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8585#[cfg_attr(feature = "bindings", derive(TS))]
8586pub enum TruncateTarget {
8587    Table,
8588    Database,
8589}
8590
8591impl Default for TruncateTarget {
8592    fn default() -> Self {
8593        TruncateTarget::Table
8594    }
8595}
8596
8597/// TRUNCATE identity option
8598#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8599#[cfg_attr(feature = "bindings", derive(TS))]
8600pub enum TruncateIdentity {
8601    Restart,
8602    Continue,
8603}
8604
8605impl Truncate {
8606    pub fn new(table: impl Into<String>) -> Self {
8607        Self {
8608            target: TruncateTarget::Table,
8609            if_exists: false,
8610            table: TableRef::new(table),
8611            on_cluster: None,
8612            cascade: false,
8613            extra_tables: Vec::new(),
8614            identity: None,
8615            restrict: false,
8616            partition: None,
8617        }
8618    }
8619}
8620
8621/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8623#[cfg_attr(feature = "bindings", derive(TS))]
8624pub struct Use {
8625    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8626    pub kind: Option<UseKind>,
8627    /// The name of the object
8628    pub this: Identifier,
8629}
8630
8631/// Kind of USE statement
8632#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8633#[cfg_attr(feature = "bindings", derive(TS))]
8634pub enum UseKind {
8635    Database,
8636    Schema,
8637    Role,
8638    Warehouse,
8639    Catalog,
8640    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8641    SecondaryRoles,
8642}
8643
8644/// SET variable statement
8645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8646#[cfg_attr(feature = "bindings", derive(TS))]
8647pub struct SetStatement {
8648    /// The items being set
8649    pub items: Vec<SetItem>,
8650}
8651
8652/// A single SET item (variable assignment)
8653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8654#[cfg_attr(feature = "bindings", derive(TS))]
8655pub struct SetItem {
8656    /// The variable name
8657    pub name: Expression,
8658    /// The value to set
8659    pub value: Expression,
8660    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8661    pub kind: Option<String>,
8662    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8663    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8664    pub no_equals: bool,
8665}
8666
8667/// CACHE TABLE statement (Spark)
8668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8669#[cfg_attr(feature = "bindings", derive(TS))]
8670pub struct Cache {
8671    /// The table to cache
8672    pub table: Identifier,
8673    /// LAZY keyword - defer caching until first use
8674    pub lazy: bool,
8675    /// Optional OPTIONS clause (key-value pairs)
8676    pub options: Vec<(Expression, Expression)>,
8677    /// Optional AS clause with query
8678    pub query: Option<Expression>,
8679}
8680
8681/// UNCACHE TABLE statement (Spark)
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct Uncache {
8685    /// The table to uncache
8686    pub table: Identifier,
8687    /// IF EXISTS clause
8688    pub if_exists: bool,
8689}
8690
8691/// LOAD DATA statement (Hive)
8692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8693#[cfg_attr(feature = "bindings", derive(TS))]
8694pub struct LoadData {
8695    /// LOCAL keyword - load from local filesystem
8696    pub local: bool,
8697    /// The path to load data from (INPATH value)
8698    pub inpath: String,
8699    /// Whether to overwrite existing data
8700    pub overwrite: bool,
8701    /// The target table
8702    pub table: Expression,
8703    /// Optional PARTITION clause with key-value pairs
8704    pub partition: Vec<(Identifier, Expression)>,
8705    /// Optional INPUTFORMAT clause
8706    pub input_format: Option<String>,
8707    /// Optional SERDE clause
8708    pub serde: Option<String>,
8709}
8710
8711/// PRAGMA statement (SQLite)
8712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8713#[cfg_attr(feature = "bindings", derive(TS))]
8714pub struct Pragma {
8715    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8716    pub schema: Option<Identifier>,
8717    /// The pragma name
8718    pub name: Identifier,
8719    /// Optional value for assignment (PRAGMA name = value)
8720    pub value: Option<Expression>,
8721    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8722    pub args: Vec<Expression>,
8723    /// Whether this pragma should be generated using assignment syntax.
8724    #[serde(default)]
8725    pub use_assignment_syntax: bool,
8726}
8727
8728/// A privilege with optional column list for GRANT/REVOKE
8729/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8731#[cfg_attr(feature = "bindings", derive(TS))]
8732pub struct Privilege {
8733    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8734    pub name: String,
8735    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8736    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8737    pub columns: Vec<String>,
8738}
8739
8740/// Principal in GRANT/REVOKE (user, role, etc.)
8741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8742#[cfg_attr(feature = "bindings", derive(TS))]
8743pub struct GrantPrincipal {
8744    /// The name of the principal
8745    pub name: Identifier,
8746    /// Whether prefixed with ROLE keyword
8747    pub is_role: bool,
8748    /// Whether prefixed with GROUP keyword (Redshift)
8749    #[serde(default)]
8750    pub is_group: bool,
8751    /// Whether prefixed with SHARE keyword (Snowflake)
8752    #[serde(default)]
8753    pub is_share: bool,
8754}
8755
8756/// GRANT statement
8757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8758#[cfg_attr(feature = "bindings", derive(TS))]
8759pub struct Grant {
8760    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8761    pub privileges: Vec<Privilege>,
8762    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8763    pub kind: Option<String>,
8764    /// The object to grant on
8765    pub securable: Identifier,
8766    /// Function parameter types (for FUNCTION kind)
8767    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8768    pub function_params: Vec<String>,
8769    /// The grantees
8770    pub principals: Vec<GrantPrincipal>,
8771    /// WITH GRANT OPTION
8772    pub grant_option: bool,
8773    /// TSQL: AS principal (the grantor role)
8774    #[serde(default, skip_serializing_if = "Option::is_none")]
8775    pub as_principal: Option<Identifier>,
8776}
8777
8778/// REVOKE statement
8779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8780#[cfg_attr(feature = "bindings", derive(TS))]
8781pub struct Revoke {
8782    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8783    pub privileges: Vec<Privilege>,
8784    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8785    pub kind: Option<String>,
8786    /// The object to revoke from
8787    pub securable: Identifier,
8788    /// Function parameter types (for FUNCTION kind)
8789    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8790    pub function_params: Vec<String>,
8791    /// The grantees
8792    pub principals: Vec<GrantPrincipal>,
8793    /// GRANT OPTION FOR
8794    pub grant_option: bool,
8795    /// CASCADE
8796    pub cascade: bool,
8797    /// RESTRICT
8798    #[serde(default)]
8799    pub restrict: bool,
8800}
8801
8802/// COMMENT ON statement
8803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8804#[cfg_attr(feature = "bindings", derive(TS))]
8805pub struct Comment {
8806    /// The object being commented on
8807    pub this: Expression,
8808    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8809    pub kind: String,
8810    /// The comment text expression
8811    pub expression: Expression,
8812    /// IF EXISTS clause
8813    pub exists: bool,
8814    /// MATERIALIZED keyword
8815    pub materialized: bool,
8816}
8817
8818// ============================================================================
8819// Phase 4: Additional DDL Statements
8820// ============================================================================
8821
8822/// ALTER VIEW statement
8823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8824#[cfg_attr(feature = "bindings", derive(TS))]
8825pub struct AlterView {
8826    pub name: TableRef,
8827    pub actions: Vec<AlterViewAction>,
8828    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8829    #[serde(default, skip_serializing_if = "Option::is_none")]
8830    pub algorithm: Option<String>,
8831    /// MySQL: DEFINER = 'user'@'host'
8832    #[serde(default, skip_serializing_if = "Option::is_none")]
8833    pub definer: Option<String>,
8834    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8835    #[serde(default, skip_serializing_if = "Option::is_none")]
8836    pub sql_security: Option<String>,
8837    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8838    #[serde(default, skip_serializing_if = "Option::is_none")]
8839    pub with_option: Option<String>,
8840    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8841    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8842    pub columns: Vec<ViewColumn>,
8843}
8844
8845/// Actions for ALTER VIEW
8846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8847#[cfg_attr(feature = "bindings", derive(TS))]
8848pub enum AlterViewAction {
8849    /// Rename the view
8850    Rename(TableRef),
8851    /// Change owner
8852    OwnerTo(Identifier),
8853    /// Set schema
8854    SetSchema(Identifier),
8855    /// Set authorization (Trino/Presto)
8856    SetAuthorization(String),
8857    /// Alter column
8858    AlterColumn {
8859        name: Identifier,
8860        action: AlterColumnAction,
8861    },
8862    /// Redefine view as query (SELECT, UNION, etc.)
8863    AsSelect(Box<Expression>),
8864    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8865    SetTblproperties(Vec<(String, String)>),
8866    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8867    UnsetTblproperties(Vec<String>),
8868}
8869
8870impl AlterView {
8871    pub fn new(name: impl Into<String>) -> Self {
8872        Self {
8873            name: TableRef::new(name),
8874            actions: Vec::new(),
8875            algorithm: None,
8876            definer: None,
8877            sql_security: None,
8878            with_option: None,
8879            columns: Vec::new(),
8880        }
8881    }
8882}
8883
8884/// ALTER INDEX statement
8885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8886#[cfg_attr(feature = "bindings", derive(TS))]
8887pub struct AlterIndex {
8888    pub name: Identifier,
8889    pub table: Option<TableRef>,
8890    pub actions: Vec<AlterIndexAction>,
8891}
8892
8893/// Actions for ALTER INDEX
8894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8895#[cfg_attr(feature = "bindings", derive(TS))]
8896pub enum AlterIndexAction {
8897    /// Rename the index
8898    Rename(Identifier),
8899    /// Set tablespace
8900    SetTablespace(Identifier),
8901    /// Set visibility (MySQL)
8902    Visible(bool),
8903}
8904
8905impl AlterIndex {
8906    pub fn new(name: impl Into<String>) -> Self {
8907        Self {
8908            name: Identifier::new(name),
8909            table: None,
8910            actions: Vec::new(),
8911        }
8912    }
8913}
8914
8915/// CREATE SCHEMA statement
8916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8917#[cfg_attr(feature = "bindings", derive(TS))]
8918pub struct CreateSchema {
8919    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8920    pub name: Vec<Identifier>,
8921    pub if_not_exists: bool,
8922    pub authorization: Option<Identifier>,
8923    /// CLONE source parts, possibly dot-qualified
8924    #[serde(default)]
8925    pub clone_from: Option<Vec<Identifier>>,
8926    /// AT/BEFORE clause for time travel (Snowflake)
8927    #[serde(default)]
8928    pub at_clause: Option<Expression>,
8929    /// Schema properties like DEFAULT COLLATE
8930    #[serde(default)]
8931    pub properties: Vec<Expression>,
8932    /// Leading comments before the statement
8933    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8934    pub leading_comments: Vec<String>,
8935}
8936
8937impl CreateSchema {
8938    pub fn new(name: impl Into<String>) -> Self {
8939        Self {
8940            name: vec![Identifier::new(name)],
8941            if_not_exists: false,
8942            authorization: None,
8943            clone_from: None,
8944            at_clause: None,
8945            properties: Vec::new(),
8946            leading_comments: Vec::new(),
8947        }
8948    }
8949}
8950
8951/// DROP SCHEMA statement
8952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8953#[cfg_attr(feature = "bindings", derive(TS))]
8954pub struct DropSchema {
8955    pub name: Identifier,
8956    pub if_exists: bool,
8957    pub cascade: bool,
8958}
8959
8960impl DropSchema {
8961    pub fn new(name: impl Into<String>) -> Self {
8962        Self {
8963            name: Identifier::new(name),
8964            if_exists: false,
8965            cascade: false,
8966        }
8967    }
8968}
8969
8970/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8972#[cfg_attr(feature = "bindings", derive(TS))]
8973pub struct DropNamespace {
8974    pub name: Identifier,
8975    pub if_exists: bool,
8976    pub cascade: bool,
8977}
8978
8979impl DropNamespace {
8980    pub fn new(name: impl Into<String>) -> Self {
8981        Self {
8982            name: Identifier::new(name),
8983            if_exists: false,
8984            cascade: false,
8985        }
8986    }
8987}
8988
8989/// CREATE DATABASE statement
8990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8991#[cfg_attr(feature = "bindings", derive(TS))]
8992pub struct CreateDatabase {
8993    pub name: Identifier,
8994    pub if_not_exists: bool,
8995    pub options: Vec<DatabaseOption>,
8996    /// Snowflake CLONE source
8997    #[serde(default)]
8998    pub clone_from: Option<Identifier>,
8999    /// AT/BEFORE clause for time travel (Snowflake)
9000    #[serde(default)]
9001    pub at_clause: Option<Expression>,
9002}
9003
9004/// Database option
9005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9006#[cfg_attr(feature = "bindings", derive(TS))]
9007pub enum DatabaseOption {
9008    CharacterSet(String),
9009    Collate(String),
9010    Owner(Identifier),
9011    Template(Identifier),
9012    Encoding(String),
9013    Location(String),
9014}
9015
9016impl CreateDatabase {
9017    pub fn new(name: impl Into<String>) -> Self {
9018        Self {
9019            name: Identifier::new(name),
9020            if_not_exists: false,
9021            options: Vec::new(),
9022            clone_from: None,
9023            at_clause: None,
9024        }
9025    }
9026}
9027
9028/// DROP DATABASE statement
9029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9030#[cfg_attr(feature = "bindings", derive(TS))]
9031pub struct DropDatabase {
9032    pub name: Identifier,
9033    pub if_exists: bool,
9034    /// ClickHouse: SYNC modifier
9035    #[serde(default)]
9036    pub sync: bool,
9037}
9038
9039impl DropDatabase {
9040    pub fn new(name: impl Into<String>) -> Self {
9041        Self {
9042            name: Identifier::new(name),
9043            if_exists: false,
9044            sync: false,
9045        }
9046    }
9047}
9048
9049/// CREATE FUNCTION statement
9050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9051#[cfg_attr(feature = "bindings", derive(TS))]
9052pub struct CreateFunction {
9053    pub name: TableRef,
9054    pub parameters: Vec<FunctionParameter>,
9055    pub return_type: Option<DataType>,
9056    pub body: Option<FunctionBody>,
9057    pub or_replace: bool,
9058    /// TSQL: CREATE OR ALTER
9059    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9060    pub or_alter: bool,
9061    pub if_not_exists: bool,
9062    pub temporary: bool,
9063    pub language: Option<String>,
9064    pub deterministic: Option<bool>,
9065    pub returns_null_on_null_input: Option<bool>,
9066    pub security: Option<FunctionSecurity>,
9067    /// Whether parentheses were present in the original syntax
9068    #[serde(default = "default_true")]
9069    pub has_parens: bool,
9070    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9071    #[serde(default)]
9072    pub sql_data_access: Option<SqlDataAccess>,
9073    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9074    #[serde(default, skip_serializing_if = "Option::is_none")]
9075    pub returns_table_body: Option<String>,
9076    /// True if LANGUAGE clause appears before RETURNS clause
9077    #[serde(default)]
9078    pub language_first: bool,
9079    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9080    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9081    pub set_options: Vec<FunctionSetOption>,
9082    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9083    #[serde(default)]
9084    pub strict: bool,
9085    /// BigQuery: OPTIONS (key=value, ...)
9086    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9087    pub options: Vec<Expression>,
9088    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9089    #[serde(default)]
9090    pub is_table_function: bool,
9091    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9092    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9093    pub property_order: Vec<FunctionPropertyKind>,
9094    /// Hive: USING JAR|FILE|ARCHIVE '...'
9095    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9096    pub using_resources: Vec<FunctionUsingResource>,
9097    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9098    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9099    pub environment: Vec<Expression>,
9100    /// HANDLER 'handler_function' clause (Databricks)
9101    #[serde(default, skip_serializing_if = "Option::is_none")]
9102    pub handler: Option<String>,
9103    /// True when the HANDLER clause used Snowflake-style `HANDLER = 'fn'`
9104    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9105    pub handler_uses_eq: bool,
9106    /// Snowflake: RUNTIME_VERSION='3.11'
9107    #[serde(default, skip_serializing_if = "Option::is_none")]
9108    pub runtime_version: Option<String>,
9109    /// Snowflake: PACKAGES=('pkg1', 'pkg2')
9110    #[serde(default, skip_serializing_if = "Option::is_none")]
9111    pub packages: Option<Vec<String>>,
9112    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9113    #[serde(default, skip_serializing_if = "Option::is_none")]
9114    pub parameter_style: Option<String>,
9115}
9116
9117/// A SET option in CREATE FUNCTION (PostgreSQL)
9118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9119#[cfg_attr(feature = "bindings", derive(TS))]
9120pub struct FunctionSetOption {
9121    pub name: String,
9122    pub value: FunctionSetValue,
9123}
9124
9125/// The value of a SET option
9126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9127#[cfg_attr(feature = "bindings", derive(TS))]
9128pub enum FunctionSetValue {
9129    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9130    Value { value: String, use_to: bool },
9131    /// SET key FROM CURRENT
9132    FromCurrent,
9133}
9134
9135/// SQL data access characteristics for functions
9136#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9137#[cfg_attr(feature = "bindings", derive(TS))]
9138pub enum SqlDataAccess {
9139    /// NO SQL
9140    NoSql,
9141    /// CONTAINS SQL
9142    ContainsSql,
9143    /// READS SQL DATA
9144    ReadsSqlData,
9145    /// MODIFIES SQL DATA
9146    ModifiesSqlData,
9147}
9148
9149/// Types of properties in CREATE FUNCTION for tracking their original order
9150#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9151#[cfg_attr(feature = "bindings", derive(TS))]
9152pub enum FunctionPropertyKind {
9153    /// SET option
9154    Set,
9155    /// AS body
9156    As,
9157    /// Hive: USING JAR|FILE|ARCHIVE ...
9158    Using,
9159    /// LANGUAGE clause
9160    Language,
9161    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9162    Determinism,
9163    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9164    NullInput,
9165    /// SECURITY DEFINER/INVOKER
9166    Security,
9167    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9168    SqlDataAccess,
9169    /// OPTIONS clause (BigQuery)
9170    Options,
9171    /// ENVIRONMENT clause (Databricks)
9172    Environment,
9173    /// HANDLER clause (Databricks)
9174    Handler,
9175    /// Snowflake: RUNTIME_VERSION='...'
9176    RuntimeVersion,
9177    /// Snowflake: PACKAGES=(...)
9178    Packages,
9179    /// PARAMETER STYLE clause (Databricks)
9180    ParameterStyle,
9181}
9182
9183/// Hive CREATE FUNCTION resource in a USING clause
9184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9185#[cfg_attr(feature = "bindings", derive(TS))]
9186pub struct FunctionUsingResource {
9187    pub kind: String,
9188    pub uri: String,
9189}
9190
9191/// Function parameter
9192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9193#[cfg_attr(feature = "bindings", derive(TS))]
9194pub struct FunctionParameter {
9195    pub name: Option<Identifier>,
9196    pub data_type: DataType,
9197    pub mode: Option<ParameterMode>,
9198    pub default: Option<Expression>,
9199    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9200    #[serde(default, skip_serializing_if = "Option::is_none")]
9201    pub mode_text: Option<String>,
9202}
9203
9204/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9205#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9206#[cfg_attr(feature = "bindings", derive(TS))]
9207pub enum ParameterMode {
9208    In,
9209    Out,
9210    InOut,
9211    Variadic,
9212}
9213
9214/// Function body
9215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9216#[cfg_attr(feature = "bindings", derive(TS))]
9217pub enum FunctionBody {
9218    /// AS $$ ... $$ (dollar-quoted)
9219    Block(String),
9220    /// AS 'string' (single-quoted string literal body)
9221    StringLiteral(String),
9222    /// AS 'expression'
9223    Expression(Expression),
9224    /// EXTERNAL NAME 'library'
9225    External(String),
9226    /// RETURN expression
9227    Return(Expression),
9228    /// BEGIN ... END block with parsed statements
9229    Statements(Vec<Expression>),
9230    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9231    /// Stores (content, optional_tag)
9232    DollarQuoted {
9233        content: String,
9234        tag: Option<String>,
9235    },
9236    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9237    RawBlock(String),
9238}
9239
9240/// Function security (DEFINER, INVOKER, or NONE)
9241#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9242#[cfg_attr(feature = "bindings", derive(TS))]
9243pub enum FunctionSecurity {
9244    Definer,
9245    Invoker,
9246    /// StarRocks/MySQL: SECURITY NONE
9247    None,
9248}
9249
9250impl CreateFunction {
9251    pub fn new(name: impl Into<String>) -> Self {
9252        Self {
9253            name: TableRef::new(name),
9254            parameters: Vec::new(),
9255            return_type: None,
9256            body: None,
9257            or_replace: false,
9258            or_alter: false,
9259            if_not_exists: false,
9260            temporary: false,
9261            language: None,
9262            deterministic: None,
9263            returns_null_on_null_input: None,
9264            security: None,
9265            has_parens: true,
9266            sql_data_access: None,
9267            returns_table_body: None,
9268            language_first: false,
9269            set_options: Vec::new(),
9270            strict: false,
9271            options: Vec::new(),
9272            is_table_function: false,
9273            property_order: Vec::new(),
9274            using_resources: Vec::new(),
9275            environment: Vec::new(),
9276            handler: None,
9277            handler_uses_eq: false,
9278            runtime_version: None,
9279            packages: None,
9280            parameter_style: None,
9281        }
9282    }
9283}
9284
9285/// DROP FUNCTION statement
9286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9287#[cfg_attr(feature = "bindings", derive(TS))]
9288pub struct DropFunction {
9289    pub name: TableRef,
9290    pub parameters: Option<Vec<DataType>>,
9291    pub if_exists: bool,
9292    pub cascade: bool,
9293}
9294
9295impl DropFunction {
9296    pub fn new(name: impl Into<String>) -> Self {
9297        Self {
9298            name: TableRef::new(name),
9299            parameters: None,
9300            if_exists: false,
9301            cascade: false,
9302        }
9303    }
9304}
9305
9306/// CREATE PROCEDURE statement
9307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9308#[cfg_attr(feature = "bindings", derive(TS))]
9309pub struct CreateProcedure {
9310    pub name: TableRef,
9311    pub parameters: Vec<FunctionParameter>,
9312    pub body: Option<FunctionBody>,
9313    pub or_replace: bool,
9314    /// TSQL: CREATE OR ALTER
9315    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9316    pub or_alter: bool,
9317    pub if_not_exists: bool,
9318    pub language: Option<String>,
9319    pub security: Option<FunctionSecurity>,
9320    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9321    #[serde(default)]
9322    pub return_type: Option<DataType>,
9323    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9324    #[serde(default)]
9325    pub execute_as: Option<String>,
9326    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9327    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9328    pub with_options: Vec<String>,
9329    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9330    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9331    pub has_parens: bool,
9332    /// Whether the short form PROC was used (instead of PROCEDURE)
9333    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9334    pub use_proc_keyword: bool,
9335}
9336
9337impl CreateProcedure {
9338    pub fn new(name: impl Into<String>) -> Self {
9339        Self {
9340            name: TableRef::new(name),
9341            parameters: Vec::new(),
9342            body: None,
9343            or_replace: false,
9344            or_alter: false,
9345            if_not_exists: false,
9346            language: None,
9347            security: None,
9348            return_type: None,
9349            execute_as: None,
9350            with_options: Vec::new(),
9351            has_parens: true,
9352            use_proc_keyword: false,
9353        }
9354    }
9355}
9356
9357/// DROP PROCEDURE statement
9358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9359#[cfg_attr(feature = "bindings", derive(TS))]
9360pub struct DropProcedure {
9361    pub name: TableRef,
9362    pub parameters: Option<Vec<DataType>>,
9363    pub if_exists: bool,
9364    pub cascade: bool,
9365}
9366
9367impl DropProcedure {
9368    pub fn new(name: impl Into<String>) -> Self {
9369        Self {
9370            name: TableRef::new(name),
9371            parameters: None,
9372            if_exists: false,
9373            cascade: false,
9374        }
9375    }
9376}
9377
9378/// Sequence property tag for ordering
9379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9380#[cfg_attr(feature = "bindings", derive(TS))]
9381pub enum SeqPropKind {
9382    Start,
9383    Increment,
9384    Minvalue,
9385    Maxvalue,
9386    Cache,
9387    NoCache,
9388    Cycle,
9389    NoCycle,
9390    OwnedBy,
9391    Order,
9392    NoOrder,
9393    Comment,
9394    /// SHARING=<value> (Oracle)
9395    Sharing,
9396    /// KEEP (Oracle)
9397    Keep,
9398    /// NOKEEP (Oracle)
9399    NoKeep,
9400    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9401    Scale,
9402    /// NOSCALE (Oracle)
9403    NoScale,
9404    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9405    Shard,
9406    /// NOSHARD (Oracle)
9407    NoShard,
9408    /// SESSION (Oracle)
9409    Session,
9410    /// GLOBAL (Oracle)
9411    Global,
9412    /// NOCACHE (single word, Oracle)
9413    NoCacheWord,
9414    /// NOCYCLE (single word, Oracle)
9415    NoCycleWord,
9416    /// NOMINVALUE (single word, Oracle)
9417    NoMinvalueWord,
9418    /// NOMAXVALUE (single word, Oracle)
9419    NoMaxvalueWord,
9420}
9421
9422/// CREATE SYNONYM statement (TSQL)
9423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9424#[cfg_attr(feature = "bindings", derive(TS))]
9425pub struct CreateSynonym {
9426    /// The synonym name (can be qualified: schema.synonym_name)
9427    pub name: TableRef,
9428    /// The target object the synonym refers to
9429    pub target: TableRef,
9430}
9431
9432/// CREATE SEQUENCE statement
9433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9434#[cfg_attr(feature = "bindings", derive(TS))]
9435pub struct CreateSequence {
9436    pub name: TableRef,
9437    pub if_not_exists: bool,
9438    pub temporary: bool,
9439    #[serde(default)]
9440    pub or_replace: bool,
9441    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9442    #[serde(default, skip_serializing_if = "Option::is_none")]
9443    pub as_type: Option<DataType>,
9444    pub increment: Option<i64>,
9445    pub minvalue: Option<SequenceBound>,
9446    pub maxvalue: Option<SequenceBound>,
9447    pub start: Option<i64>,
9448    pub cache: Option<i64>,
9449    pub cycle: bool,
9450    pub owned_by: Option<TableRef>,
9451    /// Whether OWNED BY NONE was specified
9452    #[serde(default)]
9453    pub owned_by_none: bool,
9454    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9455    #[serde(default)]
9456    pub order: Option<bool>,
9457    /// Snowflake: COMMENT = 'value'
9458    #[serde(default)]
9459    pub comment: Option<String>,
9460    /// SHARING=<value> (Oracle)
9461    #[serde(default, skip_serializing_if = "Option::is_none")]
9462    pub sharing: Option<String>,
9463    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9464    #[serde(default, skip_serializing_if = "Option::is_none")]
9465    pub scale_modifier: Option<String>,
9466    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9467    #[serde(default, skip_serializing_if = "Option::is_none")]
9468    pub shard_modifier: Option<String>,
9469    /// Tracks the order in which properties appeared in the source
9470    #[serde(default)]
9471    pub property_order: Vec<SeqPropKind>,
9472}
9473
9474/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9476#[cfg_attr(feature = "bindings", derive(TS))]
9477pub enum SequenceBound {
9478    Value(i64),
9479    None,
9480}
9481
9482impl CreateSequence {
9483    pub fn new(name: impl Into<String>) -> Self {
9484        Self {
9485            name: TableRef::new(name),
9486            if_not_exists: false,
9487            temporary: false,
9488            or_replace: false,
9489            as_type: None,
9490            increment: None,
9491            minvalue: None,
9492            maxvalue: None,
9493            start: None,
9494            cache: None,
9495            cycle: false,
9496            owned_by: None,
9497            owned_by_none: false,
9498            order: None,
9499            comment: None,
9500            sharing: None,
9501            scale_modifier: None,
9502            shard_modifier: None,
9503            property_order: Vec::new(),
9504        }
9505    }
9506}
9507
9508/// DROP SEQUENCE statement
9509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9510#[cfg_attr(feature = "bindings", derive(TS))]
9511pub struct DropSequence {
9512    pub name: TableRef,
9513    pub if_exists: bool,
9514    pub cascade: bool,
9515}
9516
9517impl DropSequence {
9518    pub fn new(name: impl Into<String>) -> Self {
9519        Self {
9520            name: TableRef::new(name),
9521            if_exists: false,
9522            cascade: false,
9523        }
9524    }
9525}
9526
9527/// ALTER SEQUENCE statement
9528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9529#[cfg_attr(feature = "bindings", derive(TS))]
9530pub struct AlterSequence {
9531    pub name: TableRef,
9532    pub if_exists: bool,
9533    pub increment: Option<i64>,
9534    pub minvalue: Option<SequenceBound>,
9535    pub maxvalue: Option<SequenceBound>,
9536    pub start: Option<i64>,
9537    pub restart: Option<Option<i64>>,
9538    pub cache: Option<i64>,
9539    pub cycle: Option<bool>,
9540    pub owned_by: Option<Option<TableRef>>,
9541}
9542
9543impl AlterSequence {
9544    pub fn new(name: impl Into<String>) -> Self {
9545        Self {
9546            name: TableRef::new(name),
9547            if_exists: false,
9548            increment: None,
9549            minvalue: None,
9550            maxvalue: None,
9551            start: None,
9552            restart: None,
9553            cache: None,
9554            cycle: None,
9555            owned_by: None,
9556        }
9557    }
9558}
9559
9560/// CREATE TRIGGER statement
9561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9562#[cfg_attr(feature = "bindings", derive(TS))]
9563pub struct CreateTrigger {
9564    pub name: Identifier,
9565    pub table: TableRef,
9566    pub timing: TriggerTiming,
9567    pub events: Vec<TriggerEvent>,
9568    #[serde(default, skip_serializing_if = "Option::is_none")]
9569    pub for_each: Option<TriggerForEach>,
9570    pub when: Option<Expression>,
9571    /// Whether the WHEN clause was parenthesized in the original SQL
9572    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9573    pub when_paren: bool,
9574    pub body: TriggerBody,
9575    pub or_replace: bool,
9576    /// TSQL: CREATE OR ALTER
9577    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9578    pub or_alter: bool,
9579    pub constraint: bool,
9580    pub deferrable: Option<bool>,
9581    pub initially_deferred: Option<bool>,
9582    pub referencing: Option<TriggerReferencing>,
9583}
9584
9585/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9586#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9587#[cfg_attr(feature = "bindings", derive(TS))]
9588pub enum TriggerTiming {
9589    Before,
9590    After,
9591    InsteadOf,
9592}
9593
9594/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9596#[cfg_attr(feature = "bindings", derive(TS))]
9597pub enum TriggerEvent {
9598    Insert,
9599    Update(Option<Vec<Identifier>>),
9600    Delete,
9601    Truncate,
9602}
9603
9604/// Trigger FOR EACH clause
9605#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9606#[cfg_attr(feature = "bindings", derive(TS))]
9607pub enum TriggerForEach {
9608    Row,
9609    Statement,
9610}
9611
9612/// Trigger body
9613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9614#[cfg_attr(feature = "bindings", derive(TS))]
9615pub enum TriggerBody {
9616    /// EXECUTE FUNCTION/PROCEDURE name(args)
9617    Execute {
9618        function: TableRef,
9619        args: Vec<Expression>,
9620    },
9621    /// BEGIN ... END block
9622    Block(String),
9623}
9624
9625/// Trigger REFERENCING clause
9626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9627#[cfg_attr(feature = "bindings", derive(TS))]
9628pub struct TriggerReferencing {
9629    pub old_table: Option<Identifier>,
9630    pub new_table: Option<Identifier>,
9631    pub old_row: Option<Identifier>,
9632    pub new_row: Option<Identifier>,
9633}
9634
9635impl CreateTrigger {
9636    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9637        Self {
9638            name: Identifier::new(name),
9639            table: TableRef::new(table),
9640            timing: TriggerTiming::Before,
9641            events: Vec::new(),
9642            for_each: Some(TriggerForEach::Row),
9643            when: None,
9644            when_paren: false,
9645            body: TriggerBody::Execute {
9646                function: TableRef::new(""),
9647                args: Vec::new(),
9648            },
9649            or_replace: false,
9650            or_alter: false,
9651            constraint: false,
9652            deferrable: None,
9653            initially_deferred: None,
9654            referencing: None,
9655        }
9656    }
9657}
9658
9659/// DROP TRIGGER statement
9660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9661#[cfg_attr(feature = "bindings", derive(TS))]
9662pub struct DropTrigger {
9663    pub name: Identifier,
9664    pub table: Option<TableRef>,
9665    pub if_exists: bool,
9666    pub cascade: bool,
9667}
9668
9669impl DropTrigger {
9670    pub fn new(name: impl Into<String>) -> Self {
9671        Self {
9672            name: Identifier::new(name),
9673            table: None,
9674            if_exists: false,
9675            cascade: false,
9676        }
9677    }
9678}
9679
9680/// CREATE TYPE statement
9681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9682#[cfg_attr(feature = "bindings", derive(TS))]
9683pub struct CreateType {
9684    pub name: TableRef,
9685    pub definition: TypeDefinition,
9686    pub if_not_exists: bool,
9687}
9688
9689/// Type definition
9690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9691#[cfg_attr(feature = "bindings", derive(TS))]
9692pub enum TypeDefinition {
9693    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9694    Enum(Vec<String>),
9695    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9696    Composite(Vec<TypeAttribute>),
9697    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9698    Range {
9699        subtype: DataType,
9700        subtype_diff: Option<String>,
9701        canonical: Option<String>,
9702    },
9703    /// Base type (for advanced usage)
9704    Base {
9705        input: String,
9706        output: String,
9707        internallength: Option<i32>,
9708    },
9709    /// Domain type
9710    Domain {
9711        base_type: DataType,
9712        default: Option<Expression>,
9713        constraints: Vec<DomainConstraint>,
9714    },
9715}
9716
9717/// Type attribute for composite types
9718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9719#[cfg_attr(feature = "bindings", derive(TS))]
9720pub struct TypeAttribute {
9721    pub name: Identifier,
9722    pub data_type: DataType,
9723    pub collate: Option<Identifier>,
9724}
9725
9726/// Domain constraint
9727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9728#[cfg_attr(feature = "bindings", derive(TS))]
9729pub struct DomainConstraint {
9730    pub name: Option<Identifier>,
9731    pub check: Expression,
9732}
9733
9734impl CreateType {
9735    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9736        Self {
9737            name: TableRef::new(name),
9738            definition: TypeDefinition::Enum(values),
9739            if_not_exists: false,
9740        }
9741    }
9742
9743    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9744        Self {
9745            name: TableRef::new(name),
9746            definition: TypeDefinition::Composite(attributes),
9747            if_not_exists: false,
9748        }
9749    }
9750}
9751
9752/// DROP TYPE statement
9753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9754#[cfg_attr(feature = "bindings", derive(TS))]
9755pub struct DropType {
9756    pub name: TableRef,
9757    pub if_exists: bool,
9758    pub cascade: bool,
9759}
9760
9761impl DropType {
9762    pub fn new(name: impl Into<String>) -> Self {
9763        Self {
9764            name: TableRef::new(name),
9765            if_exists: false,
9766            cascade: false,
9767        }
9768    }
9769}
9770
9771/// DESCRIBE statement - shows table structure or query plan
9772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9773#[cfg_attr(feature = "bindings", derive(TS))]
9774pub struct Describe {
9775    /// The target to describe (table name or query)
9776    pub target: Expression,
9777    /// EXTENDED format
9778    pub extended: bool,
9779    /// FORMATTED format
9780    pub formatted: bool,
9781    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9782    #[serde(default)]
9783    pub kind: Option<String>,
9784    /// Properties like type=stage
9785    #[serde(default)]
9786    pub properties: Vec<(String, String)>,
9787    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9788    #[serde(default, skip_serializing_if = "Option::is_none")]
9789    pub style: Option<String>,
9790    /// Partition specification for DESCRIBE PARTITION
9791    #[serde(default)]
9792    pub partition: Option<Box<Expression>>,
9793    /// Leading comments before the statement
9794    #[serde(default)]
9795    pub leading_comments: Vec<String>,
9796    /// AS JSON suffix (Databricks)
9797    #[serde(default)]
9798    pub as_json: bool,
9799    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9800    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9801    pub params: Vec<String>,
9802}
9803
9804impl Describe {
9805    pub fn new(target: Expression) -> Self {
9806        Self {
9807            target,
9808            extended: false,
9809            formatted: false,
9810            kind: None,
9811            properties: Vec::new(),
9812            style: None,
9813            partition: None,
9814            leading_comments: Vec::new(),
9815            as_json: false,
9816            params: Vec::new(),
9817        }
9818    }
9819}
9820
9821/// SHOW statement - displays database objects
9822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9823#[cfg_attr(feature = "bindings", derive(TS))]
9824pub struct Show {
9825    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9826    pub this: String,
9827    /// Whether TERSE was specified
9828    #[serde(default)]
9829    pub terse: bool,
9830    /// Whether HISTORY was specified
9831    #[serde(default)]
9832    pub history: bool,
9833    /// LIKE pattern
9834    pub like: Option<Expression>,
9835    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9836    pub scope_kind: Option<String>,
9837    /// IN scope object
9838    pub scope: Option<Expression>,
9839    /// STARTS WITH pattern
9840    pub starts_with: Option<Expression>,
9841    /// LIMIT clause
9842    pub limit: Option<Box<Limit>>,
9843    /// FROM clause (for specific object)
9844    pub from: Option<Expression>,
9845    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9846    #[serde(default, skip_serializing_if = "Option::is_none")]
9847    pub where_clause: Option<Expression>,
9848    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9849    #[serde(default, skip_serializing_if = "Option::is_none")]
9850    pub for_target: Option<Expression>,
9851    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9852    #[serde(default, skip_serializing_if = "Option::is_none")]
9853    pub db: Option<Expression>,
9854    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9855    #[serde(default, skip_serializing_if = "Option::is_none")]
9856    pub target: Option<Expression>,
9857    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9858    #[serde(default, skip_serializing_if = "Option::is_none")]
9859    pub mutex: Option<bool>,
9860    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9861    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9862    pub privileges: Vec<String>,
9863}
9864
9865impl Show {
9866    pub fn new(this: impl Into<String>) -> Self {
9867        Self {
9868            this: this.into(),
9869            terse: false,
9870            history: false,
9871            like: None,
9872            scope_kind: None,
9873            scope: None,
9874            starts_with: None,
9875            limit: None,
9876            from: None,
9877            where_clause: None,
9878            for_target: None,
9879            db: None,
9880            target: None,
9881            mutex: None,
9882            privileges: Vec::new(),
9883        }
9884    }
9885}
9886
9887/// Represent an explicit parenthesized expression for grouping precedence.
9888///
9889/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9890/// correctly instead of being flattened to `a + b * c`.
9891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9892#[cfg_attr(feature = "bindings", derive(TS))]
9893pub struct Paren {
9894    /// The inner expression wrapped by parentheses.
9895    pub this: Expression,
9896    #[serde(default)]
9897    pub trailing_comments: Vec<String>,
9898}
9899
9900/// Expression annotated with trailing comments (for round-trip preservation)
9901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9902#[cfg_attr(feature = "bindings", derive(TS))]
9903pub struct Annotated {
9904    pub this: Expression,
9905    pub trailing_comments: Vec<String>,
9906}
9907
9908// === BATCH GENERATED STRUCT DEFINITIONS ===
9909// Generated from Python sqlglot expressions.py
9910
9911/// Refresh
9912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9913#[cfg_attr(feature = "bindings", derive(TS))]
9914pub struct Refresh {
9915    pub this: Box<Expression>,
9916    pub kind: String,
9917}
9918
9919/// LockingStatement
9920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9921#[cfg_attr(feature = "bindings", derive(TS))]
9922pub struct LockingStatement {
9923    pub this: Box<Expression>,
9924    pub expression: Box<Expression>,
9925}
9926
9927/// SequenceProperties
9928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9929#[cfg_attr(feature = "bindings", derive(TS))]
9930pub struct SequenceProperties {
9931    #[serde(default)]
9932    pub increment: Option<Box<Expression>>,
9933    #[serde(default)]
9934    pub minvalue: Option<Box<Expression>>,
9935    #[serde(default)]
9936    pub maxvalue: Option<Box<Expression>>,
9937    #[serde(default)]
9938    pub cache: Option<Box<Expression>>,
9939    #[serde(default)]
9940    pub start: Option<Box<Expression>>,
9941    #[serde(default)]
9942    pub owned: Option<Box<Expression>>,
9943    #[serde(default)]
9944    pub options: Vec<Expression>,
9945}
9946
9947/// TruncateTable
9948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9949#[cfg_attr(feature = "bindings", derive(TS))]
9950pub struct TruncateTable {
9951    #[serde(default)]
9952    pub expressions: Vec<Expression>,
9953    #[serde(default)]
9954    pub is_database: Option<Box<Expression>>,
9955    #[serde(default)]
9956    pub exists: bool,
9957    #[serde(default)]
9958    pub only: Option<Box<Expression>>,
9959    #[serde(default)]
9960    pub cluster: Option<Box<Expression>>,
9961    #[serde(default)]
9962    pub identity: Option<Box<Expression>>,
9963    #[serde(default)]
9964    pub option: Option<Box<Expression>>,
9965    #[serde(default)]
9966    pub partition: Option<Box<Expression>>,
9967}
9968
9969/// Clone
9970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9971#[cfg_attr(feature = "bindings", derive(TS))]
9972pub struct Clone {
9973    pub this: Box<Expression>,
9974    #[serde(default)]
9975    pub shallow: Option<Box<Expression>>,
9976    #[serde(default)]
9977    pub copy: Option<Box<Expression>>,
9978}
9979
9980/// Attach
9981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9982#[cfg_attr(feature = "bindings", derive(TS))]
9983pub struct Attach {
9984    pub this: Box<Expression>,
9985    #[serde(default)]
9986    pub exists: bool,
9987    #[serde(default)]
9988    pub expressions: Vec<Expression>,
9989}
9990
9991/// Detach
9992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9993#[cfg_attr(feature = "bindings", derive(TS))]
9994pub struct Detach {
9995    pub this: Box<Expression>,
9996    #[serde(default)]
9997    pub exists: bool,
9998}
9999
10000/// Install
10001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10002#[cfg_attr(feature = "bindings", derive(TS))]
10003pub struct Install {
10004    pub this: Box<Expression>,
10005    #[serde(default)]
10006    pub from_: Option<Box<Expression>>,
10007    #[serde(default)]
10008    pub force: Option<Box<Expression>>,
10009}
10010
10011/// Summarize
10012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10013#[cfg_attr(feature = "bindings", derive(TS))]
10014pub struct Summarize {
10015    pub this: Box<Expression>,
10016    #[serde(default)]
10017    pub table: Option<Box<Expression>>,
10018}
10019
10020/// Declare
10021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10022#[cfg_attr(feature = "bindings", derive(TS))]
10023pub struct Declare {
10024    #[serde(default)]
10025    pub expressions: Vec<Expression>,
10026    #[serde(default)]
10027    pub replace: bool,
10028}
10029
10030/// DeclareItem
10031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10032#[cfg_attr(feature = "bindings", derive(TS))]
10033pub struct DeclareItem {
10034    pub this: Box<Expression>,
10035    #[serde(default)]
10036    pub kind: Option<String>,
10037    #[serde(default)]
10038    pub default: Option<Box<Expression>>,
10039    #[serde(default)]
10040    pub has_as: bool,
10041    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
10042    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10043    pub additional_names: Vec<Expression>,
10044}
10045
10046/// Set
10047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10048#[cfg_attr(feature = "bindings", derive(TS))]
10049pub struct Set {
10050    #[serde(default)]
10051    pub expressions: Vec<Expression>,
10052    #[serde(default)]
10053    pub unset: Option<Box<Expression>>,
10054    #[serde(default)]
10055    pub tag: Option<Box<Expression>>,
10056}
10057
10058/// Heredoc
10059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10060#[cfg_attr(feature = "bindings", derive(TS))]
10061pub struct Heredoc {
10062    pub this: Box<Expression>,
10063    #[serde(default)]
10064    pub tag: Option<Box<Expression>>,
10065}
10066
10067/// QueryBand
10068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10069#[cfg_attr(feature = "bindings", derive(TS))]
10070pub struct QueryBand {
10071    pub this: Box<Expression>,
10072    #[serde(default)]
10073    pub scope: Option<Box<Expression>>,
10074    #[serde(default)]
10075    pub update: Option<Box<Expression>>,
10076}
10077
10078/// UserDefinedFunction
10079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10080#[cfg_attr(feature = "bindings", derive(TS))]
10081pub struct UserDefinedFunction {
10082    pub this: Box<Expression>,
10083    #[serde(default)]
10084    pub expressions: Vec<Expression>,
10085    #[serde(default)]
10086    pub wrapped: Option<Box<Expression>>,
10087}
10088
10089/// RecursiveWithSearch
10090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10091#[cfg_attr(feature = "bindings", derive(TS))]
10092pub struct RecursiveWithSearch {
10093    pub kind: String,
10094    pub this: Box<Expression>,
10095    pub expression: Box<Expression>,
10096    #[serde(default)]
10097    pub using: Option<Box<Expression>>,
10098}
10099
10100/// ProjectionDef
10101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10102#[cfg_attr(feature = "bindings", derive(TS))]
10103pub struct ProjectionDef {
10104    pub this: Box<Expression>,
10105    pub expression: Box<Expression>,
10106}
10107
10108/// TableAlias
10109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10110#[cfg_attr(feature = "bindings", derive(TS))]
10111pub struct TableAlias {
10112    #[serde(default)]
10113    pub this: Option<Box<Expression>>,
10114    #[serde(default)]
10115    pub columns: Vec<Expression>,
10116}
10117
10118/// ByteString
10119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10120#[cfg_attr(feature = "bindings", derive(TS))]
10121pub struct ByteString {
10122    pub this: Box<Expression>,
10123    #[serde(default)]
10124    pub is_bytes: Option<Box<Expression>>,
10125}
10126
10127/// HexStringExpr - Hex string expression (not literal)
10128/// BigQuery: converts to FROM_HEX(this)
10129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10130#[cfg_attr(feature = "bindings", derive(TS))]
10131pub struct HexStringExpr {
10132    pub this: Box<Expression>,
10133    #[serde(default)]
10134    pub is_integer: Option<bool>,
10135}
10136
10137/// UnicodeString
10138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10139#[cfg_attr(feature = "bindings", derive(TS))]
10140pub struct UnicodeString {
10141    pub this: Box<Expression>,
10142    #[serde(default)]
10143    pub escape: Option<Box<Expression>>,
10144}
10145
10146/// AlterColumn
10147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10148#[cfg_attr(feature = "bindings", derive(TS))]
10149pub struct AlterColumn {
10150    pub this: Box<Expression>,
10151    #[serde(default)]
10152    pub dtype: Option<Box<Expression>>,
10153    #[serde(default)]
10154    pub collate: Option<Box<Expression>>,
10155    #[serde(default)]
10156    pub using: Option<Box<Expression>>,
10157    #[serde(default)]
10158    pub default: Option<Box<Expression>>,
10159    #[serde(default)]
10160    pub drop: Option<Box<Expression>>,
10161    #[serde(default)]
10162    pub comment: Option<Box<Expression>>,
10163    #[serde(default)]
10164    pub allow_null: Option<Box<Expression>>,
10165    #[serde(default)]
10166    pub visible: Option<Box<Expression>>,
10167    #[serde(default)]
10168    pub rename_to: Option<Box<Expression>>,
10169}
10170
10171/// AlterSortKey
10172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10173#[cfg_attr(feature = "bindings", derive(TS))]
10174pub struct AlterSortKey {
10175    #[serde(default)]
10176    pub this: Option<Box<Expression>>,
10177    #[serde(default)]
10178    pub expressions: Vec<Expression>,
10179    #[serde(default)]
10180    pub compound: Option<Box<Expression>>,
10181}
10182
10183/// AlterSet
10184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10185#[cfg_attr(feature = "bindings", derive(TS))]
10186pub struct AlterSet {
10187    #[serde(default)]
10188    pub expressions: Vec<Expression>,
10189    #[serde(default)]
10190    pub option: Option<Box<Expression>>,
10191    #[serde(default)]
10192    pub tablespace: Option<Box<Expression>>,
10193    #[serde(default)]
10194    pub access_method: Option<Box<Expression>>,
10195    #[serde(default)]
10196    pub file_format: Option<Box<Expression>>,
10197    #[serde(default)]
10198    pub copy_options: Option<Box<Expression>>,
10199    #[serde(default)]
10200    pub tag: Option<Box<Expression>>,
10201    #[serde(default)]
10202    pub location: Option<Box<Expression>>,
10203    #[serde(default)]
10204    pub serde: Option<Box<Expression>>,
10205}
10206
10207/// RenameColumn
10208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10209#[cfg_attr(feature = "bindings", derive(TS))]
10210pub struct RenameColumn {
10211    pub this: Box<Expression>,
10212    #[serde(default)]
10213    pub to: Option<Box<Expression>>,
10214    #[serde(default)]
10215    pub exists: bool,
10216}
10217
10218/// Comprehension
10219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10220#[cfg_attr(feature = "bindings", derive(TS))]
10221pub struct Comprehension {
10222    pub this: Box<Expression>,
10223    pub expression: Box<Expression>,
10224    #[serde(default)]
10225    pub position: Option<Box<Expression>>,
10226    #[serde(default)]
10227    pub iterator: Option<Box<Expression>>,
10228    #[serde(default)]
10229    pub condition: Option<Box<Expression>>,
10230}
10231
10232/// MergeTreeTTLAction
10233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10234#[cfg_attr(feature = "bindings", derive(TS))]
10235pub struct MergeTreeTTLAction {
10236    pub this: Box<Expression>,
10237    #[serde(default)]
10238    pub delete: Option<Box<Expression>>,
10239    #[serde(default)]
10240    pub recompress: Option<Box<Expression>>,
10241    #[serde(default)]
10242    pub to_disk: Option<Box<Expression>>,
10243    #[serde(default)]
10244    pub to_volume: Option<Box<Expression>>,
10245}
10246
10247/// MergeTreeTTL
10248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10249#[cfg_attr(feature = "bindings", derive(TS))]
10250pub struct MergeTreeTTL {
10251    #[serde(default)]
10252    pub expressions: Vec<Expression>,
10253    #[serde(default)]
10254    pub where_: Option<Box<Expression>>,
10255    #[serde(default)]
10256    pub group: Option<Box<Expression>>,
10257    #[serde(default)]
10258    pub aggregates: Option<Box<Expression>>,
10259}
10260
10261/// IndexConstraintOption
10262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10263#[cfg_attr(feature = "bindings", derive(TS))]
10264pub struct IndexConstraintOption {
10265    #[serde(default)]
10266    pub key_block_size: Option<Box<Expression>>,
10267    #[serde(default)]
10268    pub using: Option<Box<Expression>>,
10269    #[serde(default)]
10270    pub parser: Option<Box<Expression>>,
10271    #[serde(default)]
10272    pub comment: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub visible: Option<Box<Expression>>,
10275    #[serde(default)]
10276    pub engine_attr: Option<Box<Expression>>,
10277    #[serde(default)]
10278    pub secondary_engine_attr: Option<Box<Expression>>,
10279}
10280
10281/// PeriodForSystemTimeConstraint
10282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10283#[cfg_attr(feature = "bindings", derive(TS))]
10284pub struct PeriodForSystemTimeConstraint {
10285    pub this: Box<Expression>,
10286    pub expression: Box<Expression>,
10287}
10288
10289/// CaseSpecificColumnConstraint
10290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10291#[cfg_attr(feature = "bindings", derive(TS))]
10292pub struct CaseSpecificColumnConstraint {
10293    #[serde(default)]
10294    pub not_: Option<Box<Expression>>,
10295}
10296
10297/// CharacterSetColumnConstraint
10298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10299#[cfg_attr(feature = "bindings", derive(TS))]
10300pub struct CharacterSetColumnConstraint {
10301    pub this: Box<Expression>,
10302}
10303
10304/// CheckColumnConstraint
10305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10306#[cfg_attr(feature = "bindings", derive(TS))]
10307pub struct CheckColumnConstraint {
10308    pub this: Box<Expression>,
10309    #[serde(default)]
10310    pub enforced: Option<Box<Expression>>,
10311}
10312
10313/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10315#[cfg_attr(feature = "bindings", derive(TS))]
10316pub struct AssumeColumnConstraint {
10317    pub this: Box<Expression>,
10318}
10319
10320/// CompressColumnConstraint
10321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10322#[cfg_attr(feature = "bindings", derive(TS))]
10323pub struct CompressColumnConstraint {
10324    #[serde(default)]
10325    pub this: Option<Box<Expression>>,
10326}
10327
10328/// DateFormatColumnConstraint
10329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10330#[cfg_attr(feature = "bindings", derive(TS))]
10331pub struct DateFormatColumnConstraint {
10332    pub this: Box<Expression>,
10333}
10334
10335/// EphemeralColumnConstraint
10336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10337#[cfg_attr(feature = "bindings", derive(TS))]
10338pub struct EphemeralColumnConstraint {
10339    #[serde(default)]
10340    pub this: Option<Box<Expression>>,
10341}
10342
10343/// WithOperator
10344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10345#[cfg_attr(feature = "bindings", derive(TS))]
10346pub struct WithOperator {
10347    pub this: Box<Expression>,
10348    pub op: String,
10349}
10350
10351/// GeneratedAsIdentityColumnConstraint
10352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10353#[cfg_attr(feature = "bindings", derive(TS))]
10354pub struct GeneratedAsIdentityColumnConstraint {
10355    #[serde(default)]
10356    pub this: Option<Box<Expression>>,
10357    #[serde(default)]
10358    pub expression: Option<Box<Expression>>,
10359    #[serde(default)]
10360    pub on_null: Option<Box<Expression>>,
10361    #[serde(default)]
10362    pub start: Option<Box<Expression>>,
10363    #[serde(default)]
10364    pub increment: Option<Box<Expression>>,
10365    #[serde(default)]
10366    pub minvalue: Option<Box<Expression>>,
10367    #[serde(default)]
10368    pub maxvalue: Option<Box<Expression>>,
10369    #[serde(default)]
10370    pub cycle: Option<Box<Expression>>,
10371    #[serde(default)]
10372    pub order: Option<Box<Expression>>,
10373}
10374
10375/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10376/// TSQL: outputs "IDENTITY"
10377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10378#[cfg_attr(feature = "bindings", derive(TS))]
10379pub struct AutoIncrementColumnConstraint;
10380
10381/// CommentColumnConstraint - Column comment marker
10382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10383#[cfg_attr(feature = "bindings", derive(TS))]
10384pub struct CommentColumnConstraint;
10385
10386/// GeneratedAsRowColumnConstraint
10387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10388#[cfg_attr(feature = "bindings", derive(TS))]
10389pub struct GeneratedAsRowColumnConstraint {
10390    #[serde(default)]
10391    pub start: Option<Box<Expression>>,
10392    #[serde(default)]
10393    pub hidden: Option<Box<Expression>>,
10394}
10395
10396/// IndexColumnConstraint
10397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10398#[cfg_attr(feature = "bindings", derive(TS))]
10399pub struct IndexColumnConstraint {
10400    #[serde(default)]
10401    pub this: Option<Box<Expression>>,
10402    #[serde(default)]
10403    pub expressions: Vec<Expression>,
10404    #[serde(default)]
10405    pub kind: Option<String>,
10406    #[serde(default)]
10407    pub index_type: Option<Box<Expression>>,
10408    #[serde(default)]
10409    pub options: Vec<Expression>,
10410    #[serde(default)]
10411    pub expression: Option<Box<Expression>>,
10412    #[serde(default)]
10413    pub granularity: Option<Box<Expression>>,
10414}
10415
10416/// MaskingPolicyColumnConstraint
10417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10418#[cfg_attr(feature = "bindings", derive(TS))]
10419pub struct MaskingPolicyColumnConstraint {
10420    pub this: Box<Expression>,
10421    #[serde(default)]
10422    pub expressions: Vec<Expression>,
10423}
10424
10425/// NotNullColumnConstraint
10426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10427#[cfg_attr(feature = "bindings", derive(TS))]
10428pub struct NotNullColumnConstraint {
10429    #[serde(default)]
10430    pub allow_null: Option<Box<Expression>>,
10431}
10432
10433/// DefaultColumnConstraint - DEFAULT value for a column
10434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10435#[cfg_attr(feature = "bindings", derive(TS))]
10436pub struct DefaultColumnConstraint {
10437    pub this: Box<Expression>,
10438    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10439    #[serde(default, skip_serializing_if = "Option::is_none")]
10440    pub for_column: Option<Identifier>,
10441}
10442
10443/// PrimaryKeyColumnConstraint
10444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10445#[cfg_attr(feature = "bindings", derive(TS))]
10446pub struct PrimaryKeyColumnConstraint {
10447    #[serde(default)]
10448    pub desc: Option<Box<Expression>>,
10449    #[serde(default)]
10450    pub options: Vec<Expression>,
10451}
10452
10453/// UniqueColumnConstraint
10454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10455#[cfg_attr(feature = "bindings", derive(TS))]
10456pub struct UniqueColumnConstraint {
10457    #[serde(default)]
10458    pub this: Option<Box<Expression>>,
10459    #[serde(default)]
10460    pub index_type: Option<Box<Expression>>,
10461    #[serde(default)]
10462    pub on_conflict: Option<Box<Expression>>,
10463    #[serde(default)]
10464    pub nulls: Option<Box<Expression>>,
10465    #[serde(default)]
10466    pub options: Vec<Expression>,
10467}
10468
10469/// WatermarkColumnConstraint
10470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10471#[cfg_attr(feature = "bindings", derive(TS))]
10472pub struct WatermarkColumnConstraint {
10473    pub this: Box<Expression>,
10474    pub expression: Box<Expression>,
10475}
10476
10477/// ComputedColumnConstraint
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct ComputedColumnConstraint {
10481    pub this: Box<Expression>,
10482    #[serde(default)]
10483    pub persisted: Option<Box<Expression>>,
10484    #[serde(default)]
10485    pub not_null: Option<Box<Expression>>,
10486    #[serde(default)]
10487    pub data_type: Option<Box<Expression>>,
10488}
10489
10490/// InOutColumnConstraint
10491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10492#[cfg_attr(feature = "bindings", derive(TS))]
10493pub struct InOutColumnConstraint {
10494    #[serde(default)]
10495    pub input_: Option<Box<Expression>>,
10496    #[serde(default)]
10497    pub output: Option<Box<Expression>>,
10498}
10499
10500/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10502#[cfg_attr(feature = "bindings", derive(TS))]
10503pub struct PathColumnConstraint {
10504    pub this: Box<Expression>,
10505}
10506
10507/// Constraint
10508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10509#[cfg_attr(feature = "bindings", derive(TS))]
10510pub struct Constraint {
10511    pub this: Box<Expression>,
10512    #[serde(default)]
10513    pub expressions: Vec<Expression>,
10514}
10515
10516/// Export
10517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10518#[cfg_attr(feature = "bindings", derive(TS))]
10519pub struct Export {
10520    pub this: Box<Expression>,
10521    #[serde(default)]
10522    pub connection: Option<Box<Expression>>,
10523    #[serde(default)]
10524    pub options: Vec<Expression>,
10525}
10526
10527/// Filter
10528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10529#[cfg_attr(feature = "bindings", derive(TS))]
10530pub struct Filter {
10531    pub this: Box<Expression>,
10532    pub expression: Box<Expression>,
10533}
10534
10535/// Changes
10536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10537#[cfg_attr(feature = "bindings", derive(TS))]
10538pub struct Changes {
10539    #[serde(default)]
10540    pub information: Option<Box<Expression>>,
10541    #[serde(default)]
10542    pub at_before: Option<Box<Expression>>,
10543    #[serde(default)]
10544    pub end: Option<Box<Expression>>,
10545}
10546
10547/// Directory
10548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10549#[cfg_attr(feature = "bindings", derive(TS))]
10550pub struct Directory {
10551    pub this: Box<Expression>,
10552    #[serde(default)]
10553    pub local: Option<Box<Expression>>,
10554    #[serde(default)]
10555    pub row_format: Option<Box<Expression>>,
10556}
10557
10558/// ForeignKey
10559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10560#[cfg_attr(feature = "bindings", derive(TS))]
10561pub struct ForeignKey {
10562    #[serde(default)]
10563    pub expressions: Vec<Expression>,
10564    #[serde(default)]
10565    pub reference: Option<Box<Expression>>,
10566    #[serde(default)]
10567    pub delete: Option<Box<Expression>>,
10568    #[serde(default)]
10569    pub update: Option<Box<Expression>>,
10570    #[serde(default)]
10571    pub options: Vec<Expression>,
10572}
10573
10574/// ColumnPrefix
10575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10576#[cfg_attr(feature = "bindings", derive(TS))]
10577pub struct ColumnPrefix {
10578    pub this: Box<Expression>,
10579    pub expression: Box<Expression>,
10580}
10581
10582/// PrimaryKey
10583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10584#[cfg_attr(feature = "bindings", derive(TS))]
10585pub struct PrimaryKey {
10586    #[serde(default)]
10587    pub this: Option<Box<Expression>>,
10588    #[serde(default)]
10589    pub expressions: Vec<Expression>,
10590    #[serde(default)]
10591    pub options: Vec<Expression>,
10592    #[serde(default)]
10593    pub include: Option<Box<Expression>>,
10594}
10595
10596/// Into
10597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10598#[cfg_attr(feature = "bindings", derive(TS))]
10599pub struct IntoClause {
10600    #[serde(default)]
10601    pub this: Option<Box<Expression>>,
10602    #[serde(default)]
10603    pub temporary: bool,
10604    #[serde(default)]
10605    pub unlogged: Option<Box<Expression>>,
10606    #[serde(default)]
10607    pub bulk_collect: Option<Box<Expression>>,
10608    #[serde(default)]
10609    pub expressions: Vec<Expression>,
10610}
10611
10612/// JoinHint
10613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10614#[cfg_attr(feature = "bindings", derive(TS))]
10615pub struct JoinHint {
10616    pub this: Box<Expression>,
10617    #[serde(default)]
10618    pub expressions: Vec<Expression>,
10619}
10620
10621/// Opclass
10622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10623#[cfg_attr(feature = "bindings", derive(TS))]
10624pub struct Opclass {
10625    pub this: Box<Expression>,
10626    pub expression: Box<Expression>,
10627}
10628
10629/// Index
10630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10631#[cfg_attr(feature = "bindings", derive(TS))]
10632pub struct Index {
10633    #[serde(default)]
10634    pub this: Option<Box<Expression>>,
10635    #[serde(default)]
10636    pub table: Option<Box<Expression>>,
10637    #[serde(default)]
10638    pub unique: bool,
10639    #[serde(default)]
10640    pub primary: Option<Box<Expression>>,
10641    #[serde(default)]
10642    pub amp: Option<Box<Expression>>,
10643    #[serde(default)]
10644    pub params: Vec<Expression>,
10645}
10646
10647/// IndexParameters
10648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10649#[cfg_attr(feature = "bindings", derive(TS))]
10650pub struct IndexParameters {
10651    #[serde(default)]
10652    pub using: Option<Box<Expression>>,
10653    #[serde(default)]
10654    pub include: Option<Box<Expression>>,
10655    #[serde(default)]
10656    pub columns: Vec<Expression>,
10657    #[serde(default)]
10658    pub with_storage: Option<Box<Expression>>,
10659    #[serde(default)]
10660    pub partition_by: Option<Box<Expression>>,
10661    #[serde(default)]
10662    pub tablespace: Option<Box<Expression>>,
10663    #[serde(default)]
10664    pub where_: Option<Box<Expression>>,
10665    #[serde(default)]
10666    pub on: Option<Box<Expression>>,
10667}
10668
10669/// ConditionalInsert
10670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10671#[cfg_attr(feature = "bindings", derive(TS))]
10672pub struct ConditionalInsert {
10673    pub this: Box<Expression>,
10674    #[serde(default)]
10675    pub expression: Option<Box<Expression>>,
10676    #[serde(default)]
10677    pub else_: Option<Box<Expression>>,
10678}
10679
10680/// MultitableInserts
10681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10682#[cfg_attr(feature = "bindings", derive(TS))]
10683pub struct MultitableInserts {
10684    #[serde(default)]
10685    pub expressions: Vec<Expression>,
10686    pub kind: String,
10687    #[serde(default)]
10688    pub source: Option<Box<Expression>>,
10689    /// Leading comments before the statement
10690    #[serde(default)]
10691    pub leading_comments: Vec<String>,
10692    /// OVERWRITE modifier (Snowflake: INSERT OVERWRITE ALL)
10693    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10694    pub overwrite: bool,
10695}
10696
10697/// OnConflict
10698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10699#[cfg_attr(feature = "bindings", derive(TS))]
10700pub struct OnConflict {
10701    #[serde(default)]
10702    pub duplicate: Option<Box<Expression>>,
10703    #[serde(default)]
10704    pub expressions: Vec<Expression>,
10705    #[serde(default)]
10706    pub action: Option<Box<Expression>>,
10707    #[serde(default)]
10708    pub conflict_keys: Option<Box<Expression>>,
10709    #[serde(default)]
10710    pub index_predicate: Option<Box<Expression>>,
10711    #[serde(default)]
10712    pub constraint: Option<Box<Expression>>,
10713    #[serde(default)]
10714    pub where_: Option<Box<Expression>>,
10715}
10716
10717/// OnCondition
10718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10719#[cfg_attr(feature = "bindings", derive(TS))]
10720pub struct OnCondition {
10721    #[serde(default)]
10722    pub error: Option<Box<Expression>>,
10723    #[serde(default)]
10724    pub empty: Option<Box<Expression>>,
10725    #[serde(default)]
10726    pub null: Option<Box<Expression>>,
10727}
10728
10729/// Returning
10730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10731#[cfg_attr(feature = "bindings", derive(TS))]
10732pub struct Returning {
10733    #[serde(default)]
10734    pub expressions: Vec<Expression>,
10735    #[serde(default)]
10736    pub into: Option<Box<Expression>>,
10737}
10738
10739/// Introducer
10740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10741#[cfg_attr(feature = "bindings", derive(TS))]
10742pub struct Introducer {
10743    pub this: Box<Expression>,
10744    pub expression: Box<Expression>,
10745}
10746
10747/// PartitionRange
10748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10749#[cfg_attr(feature = "bindings", derive(TS))]
10750pub struct PartitionRange {
10751    pub this: Box<Expression>,
10752    #[serde(default)]
10753    pub expression: Option<Box<Expression>>,
10754    #[serde(default)]
10755    pub expressions: Vec<Expression>,
10756}
10757
10758/// Group
10759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10760#[cfg_attr(feature = "bindings", derive(TS))]
10761pub struct Group {
10762    #[serde(default)]
10763    pub expressions: Vec<Expression>,
10764    #[serde(default)]
10765    pub grouping_sets: Option<Box<Expression>>,
10766    #[serde(default)]
10767    pub cube: Option<Box<Expression>>,
10768    #[serde(default)]
10769    pub rollup: Option<Box<Expression>>,
10770    #[serde(default)]
10771    pub totals: Option<Box<Expression>>,
10772    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10773    #[serde(default)]
10774    pub all: Option<bool>,
10775}
10776
10777/// Cube
10778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10779#[cfg_attr(feature = "bindings", derive(TS))]
10780pub struct Cube {
10781    #[serde(default)]
10782    pub expressions: Vec<Expression>,
10783}
10784
10785/// Rollup
10786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10787#[cfg_attr(feature = "bindings", derive(TS))]
10788pub struct Rollup {
10789    #[serde(default)]
10790    pub expressions: Vec<Expression>,
10791}
10792
10793/// GroupingSets
10794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10795#[cfg_attr(feature = "bindings", derive(TS))]
10796pub struct GroupingSets {
10797    #[serde(default)]
10798    pub expressions: Vec<Expression>,
10799}
10800
10801/// LimitOptions
10802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10803#[cfg_attr(feature = "bindings", derive(TS))]
10804pub struct LimitOptions {
10805    #[serde(default)]
10806    pub percent: Option<Box<Expression>>,
10807    #[serde(default)]
10808    pub rows: Option<Box<Expression>>,
10809    #[serde(default)]
10810    pub with_ties: Option<Box<Expression>>,
10811}
10812
10813/// Lateral
10814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10815#[cfg_attr(feature = "bindings", derive(TS))]
10816pub struct Lateral {
10817    pub this: Box<Expression>,
10818    #[serde(default)]
10819    pub view: Option<Box<Expression>>,
10820    #[serde(default)]
10821    pub outer: Option<Box<Expression>>,
10822    #[serde(default)]
10823    pub alias: Option<String>,
10824    /// Whether the alias was originally quoted (backtick/double-quote)
10825    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10826    pub alias_quoted: bool,
10827    #[serde(default)]
10828    pub cross_apply: Option<Box<Expression>>,
10829    #[serde(default)]
10830    pub ordinality: Option<Box<Expression>>,
10831    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10832    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10833    pub column_aliases: Vec<String>,
10834}
10835
10836/// TableFromRows
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct TableFromRows {
10840    pub this: Box<Expression>,
10841    #[serde(default)]
10842    pub alias: Option<String>,
10843    #[serde(default)]
10844    pub joins: Vec<Expression>,
10845    #[serde(default)]
10846    pub pivots: Option<Box<Expression>>,
10847    #[serde(default)]
10848    pub sample: Option<Box<Expression>>,
10849}
10850
10851/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10852/// Used for set-returning functions with typed column definitions
10853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10854#[cfg_attr(feature = "bindings", derive(TS))]
10855pub struct RowsFrom {
10856    /// List of function expressions, each potentially with an alias and typed columns
10857    pub expressions: Vec<Expression>,
10858    /// WITH ORDINALITY modifier
10859    #[serde(default)]
10860    pub ordinality: bool,
10861    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10862    #[serde(default)]
10863    pub alias: Option<Box<Expression>>,
10864}
10865
10866/// WithFill
10867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10868#[cfg_attr(feature = "bindings", derive(TS))]
10869pub struct WithFill {
10870    #[serde(default)]
10871    pub from_: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub to: Option<Box<Expression>>,
10874    #[serde(default)]
10875    pub step: Option<Box<Expression>>,
10876    #[serde(default)]
10877    pub staleness: Option<Box<Expression>>,
10878    #[serde(default)]
10879    pub interpolate: Option<Box<Expression>>,
10880}
10881
10882/// Property
10883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10884#[cfg_attr(feature = "bindings", derive(TS))]
10885pub struct Property {
10886    pub this: Box<Expression>,
10887    #[serde(default)]
10888    pub value: Option<Box<Expression>>,
10889}
10890
10891/// GrantPrivilege
10892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10893#[cfg_attr(feature = "bindings", derive(TS))]
10894pub struct GrantPrivilege {
10895    pub this: Box<Expression>,
10896    #[serde(default)]
10897    pub expressions: Vec<Expression>,
10898}
10899
10900/// AllowedValuesProperty
10901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10902#[cfg_attr(feature = "bindings", derive(TS))]
10903pub struct AllowedValuesProperty {
10904    #[serde(default)]
10905    pub expressions: Vec<Expression>,
10906}
10907
10908/// AlgorithmProperty
10909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10910#[cfg_attr(feature = "bindings", derive(TS))]
10911pub struct AlgorithmProperty {
10912    pub this: Box<Expression>,
10913}
10914
10915/// AutoIncrementProperty
10916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10917#[cfg_attr(feature = "bindings", derive(TS))]
10918pub struct AutoIncrementProperty {
10919    pub this: Box<Expression>,
10920}
10921
10922/// AutoRefreshProperty
10923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10924#[cfg_attr(feature = "bindings", derive(TS))]
10925pub struct AutoRefreshProperty {
10926    pub this: Box<Expression>,
10927}
10928
10929/// BackupProperty
10930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10931#[cfg_attr(feature = "bindings", derive(TS))]
10932pub struct BackupProperty {
10933    pub this: Box<Expression>,
10934}
10935
10936/// BuildProperty
10937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10938#[cfg_attr(feature = "bindings", derive(TS))]
10939pub struct BuildProperty {
10940    pub this: Box<Expression>,
10941}
10942
10943/// BlockCompressionProperty
10944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10945#[cfg_attr(feature = "bindings", derive(TS))]
10946pub struct BlockCompressionProperty {
10947    #[serde(default)]
10948    pub autotemp: Option<Box<Expression>>,
10949    #[serde(default)]
10950    pub always: Option<Box<Expression>>,
10951    #[serde(default)]
10952    pub default: Option<Box<Expression>>,
10953    #[serde(default)]
10954    pub manual: Option<Box<Expression>>,
10955    #[serde(default)]
10956    pub never: Option<Box<Expression>>,
10957}
10958
10959/// CharacterSetProperty
10960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10961#[cfg_attr(feature = "bindings", derive(TS))]
10962pub struct CharacterSetProperty {
10963    pub this: Box<Expression>,
10964    #[serde(default)]
10965    pub default: Option<Box<Expression>>,
10966}
10967
10968/// ChecksumProperty
10969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10970#[cfg_attr(feature = "bindings", derive(TS))]
10971pub struct ChecksumProperty {
10972    #[serde(default)]
10973    pub on: Option<Box<Expression>>,
10974    #[serde(default)]
10975    pub default: Option<Box<Expression>>,
10976}
10977
10978/// CollateProperty
10979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10980#[cfg_attr(feature = "bindings", derive(TS))]
10981pub struct CollateProperty {
10982    pub this: Box<Expression>,
10983    #[serde(default)]
10984    pub default: Option<Box<Expression>>,
10985}
10986
10987/// DataBlocksizeProperty
10988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10989#[cfg_attr(feature = "bindings", derive(TS))]
10990pub struct DataBlocksizeProperty {
10991    #[serde(default)]
10992    pub size: Option<i64>,
10993    #[serde(default)]
10994    pub units: Option<Box<Expression>>,
10995    #[serde(default)]
10996    pub minimum: Option<Box<Expression>>,
10997    #[serde(default)]
10998    pub maximum: Option<Box<Expression>>,
10999    #[serde(default)]
11000    pub default: Option<Box<Expression>>,
11001}
11002
11003/// DataDeletionProperty
11004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11005#[cfg_attr(feature = "bindings", derive(TS))]
11006pub struct DataDeletionProperty {
11007    pub on: Box<Expression>,
11008    #[serde(default)]
11009    pub filter_column: Option<Box<Expression>>,
11010    #[serde(default)]
11011    pub retention_period: Option<Box<Expression>>,
11012}
11013
11014/// DefinerProperty
11015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11016#[cfg_attr(feature = "bindings", derive(TS))]
11017pub struct DefinerProperty {
11018    pub this: Box<Expression>,
11019}
11020
11021/// DistKeyProperty
11022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11023#[cfg_attr(feature = "bindings", derive(TS))]
11024pub struct DistKeyProperty {
11025    pub this: Box<Expression>,
11026}
11027
11028/// DistributedByProperty
11029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11030#[cfg_attr(feature = "bindings", derive(TS))]
11031pub struct DistributedByProperty {
11032    #[serde(default)]
11033    pub expressions: Vec<Expression>,
11034    pub kind: String,
11035    #[serde(default)]
11036    pub buckets: Option<Box<Expression>>,
11037    #[serde(default)]
11038    pub order: Option<Box<Expression>>,
11039}
11040
11041/// DistStyleProperty
11042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11043#[cfg_attr(feature = "bindings", derive(TS))]
11044pub struct DistStyleProperty {
11045    pub this: Box<Expression>,
11046}
11047
11048/// DuplicateKeyProperty
11049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11050#[cfg_attr(feature = "bindings", derive(TS))]
11051pub struct DuplicateKeyProperty {
11052    #[serde(default)]
11053    pub expressions: Vec<Expression>,
11054}
11055
11056/// EngineProperty
11057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11058#[cfg_attr(feature = "bindings", derive(TS))]
11059pub struct EngineProperty {
11060    pub this: Box<Expression>,
11061}
11062
11063/// ToTableProperty
11064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11065#[cfg_attr(feature = "bindings", derive(TS))]
11066pub struct ToTableProperty {
11067    pub this: Box<Expression>,
11068}
11069
11070/// ExecuteAsProperty
11071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11072#[cfg_attr(feature = "bindings", derive(TS))]
11073pub struct ExecuteAsProperty {
11074    pub this: Box<Expression>,
11075}
11076
11077/// ExternalProperty
11078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11079#[cfg_attr(feature = "bindings", derive(TS))]
11080pub struct ExternalProperty {
11081    #[serde(default)]
11082    pub this: Option<Box<Expression>>,
11083}
11084
11085/// FallbackProperty
11086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11087#[cfg_attr(feature = "bindings", derive(TS))]
11088pub struct FallbackProperty {
11089    #[serde(default)]
11090    pub no: Option<Box<Expression>>,
11091    #[serde(default)]
11092    pub protection: Option<Box<Expression>>,
11093}
11094
11095/// FileFormatProperty
11096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11097#[cfg_attr(feature = "bindings", derive(TS))]
11098pub struct FileFormatProperty {
11099    #[serde(default)]
11100    pub this: Option<Box<Expression>>,
11101    #[serde(default)]
11102    pub expressions: Vec<Expression>,
11103    #[serde(default)]
11104    pub hive_format: Option<Box<Expression>>,
11105}
11106
11107/// CredentialsProperty
11108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11109#[cfg_attr(feature = "bindings", derive(TS))]
11110pub struct CredentialsProperty {
11111    #[serde(default)]
11112    pub expressions: Vec<Expression>,
11113}
11114
11115/// FreespaceProperty
11116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11117#[cfg_attr(feature = "bindings", derive(TS))]
11118pub struct FreespaceProperty {
11119    pub this: Box<Expression>,
11120    #[serde(default)]
11121    pub percent: Option<Box<Expression>>,
11122}
11123
11124/// InheritsProperty
11125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11126#[cfg_attr(feature = "bindings", derive(TS))]
11127pub struct InheritsProperty {
11128    #[serde(default)]
11129    pub expressions: Vec<Expression>,
11130}
11131
11132/// InputModelProperty
11133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11134#[cfg_attr(feature = "bindings", derive(TS))]
11135pub struct InputModelProperty {
11136    pub this: Box<Expression>,
11137}
11138
11139/// OutputModelProperty
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct OutputModelProperty {
11143    pub this: Box<Expression>,
11144}
11145
11146/// IsolatedLoadingProperty
11147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11148#[cfg_attr(feature = "bindings", derive(TS))]
11149pub struct IsolatedLoadingProperty {
11150    #[serde(default)]
11151    pub no: Option<Box<Expression>>,
11152    #[serde(default)]
11153    pub concurrent: Option<Box<Expression>>,
11154    #[serde(default)]
11155    pub target: Option<Box<Expression>>,
11156}
11157
11158/// JournalProperty
11159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11160#[cfg_attr(feature = "bindings", derive(TS))]
11161pub struct JournalProperty {
11162    #[serde(default)]
11163    pub no: Option<Box<Expression>>,
11164    #[serde(default)]
11165    pub dual: Option<Box<Expression>>,
11166    #[serde(default)]
11167    pub before: Option<Box<Expression>>,
11168    #[serde(default)]
11169    pub local: Option<Box<Expression>>,
11170    #[serde(default)]
11171    pub after: Option<Box<Expression>>,
11172}
11173
11174/// LanguageProperty
11175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11176#[cfg_attr(feature = "bindings", derive(TS))]
11177pub struct LanguageProperty {
11178    pub this: Box<Expression>,
11179}
11180
11181/// EnviromentProperty
11182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11183#[cfg_attr(feature = "bindings", derive(TS))]
11184pub struct EnviromentProperty {
11185    #[serde(default)]
11186    pub expressions: Vec<Expression>,
11187}
11188
11189/// ClusteredByProperty
11190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11191#[cfg_attr(feature = "bindings", derive(TS))]
11192pub struct ClusteredByProperty {
11193    #[serde(default)]
11194    pub expressions: Vec<Expression>,
11195    #[serde(default)]
11196    pub sorted_by: Option<Box<Expression>>,
11197    #[serde(default)]
11198    pub buckets: Option<Box<Expression>>,
11199}
11200
11201/// DictProperty
11202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11203#[cfg_attr(feature = "bindings", derive(TS))]
11204pub struct DictProperty {
11205    pub this: Box<Expression>,
11206    pub kind: String,
11207    #[serde(default)]
11208    pub settings: Option<Box<Expression>>,
11209}
11210
11211/// DictRange
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct DictRange {
11215    pub this: Box<Expression>,
11216    #[serde(default)]
11217    pub min: Option<Box<Expression>>,
11218    #[serde(default)]
11219    pub max: Option<Box<Expression>>,
11220}
11221
11222/// OnCluster
11223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11224#[cfg_attr(feature = "bindings", derive(TS))]
11225pub struct OnCluster {
11226    pub this: Box<Expression>,
11227}
11228
11229/// LikeProperty
11230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11231#[cfg_attr(feature = "bindings", derive(TS))]
11232pub struct LikeProperty {
11233    pub this: Box<Expression>,
11234    #[serde(default)]
11235    pub expressions: Vec<Expression>,
11236}
11237
11238/// LocationProperty
11239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11240#[cfg_attr(feature = "bindings", derive(TS))]
11241pub struct LocationProperty {
11242    pub this: Box<Expression>,
11243}
11244
11245/// LockProperty
11246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11247#[cfg_attr(feature = "bindings", derive(TS))]
11248pub struct LockProperty {
11249    pub this: Box<Expression>,
11250}
11251
11252/// LockingProperty
11253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11254#[cfg_attr(feature = "bindings", derive(TS))]
11255pub struct LockingProperty {
11256    #[serde(default)]
11257    pub this: Option<Box<Expression>>,
11258    pub kind: String,
11259    #[serde(default)]
11260    pub for_or_in: Option<Box<Expression>>,
11261    #[serde(default)]
11262    pub lock_type: Option<Box<Expression>>,
11263    #[serde(default)]
11264    pub override_: Option<Box<Expression>>,
11265}
11266
11267/// LogProperty
11268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11269#[cfg_attr(feature = "bindings", derive(TS))]
11270pub struct LogProperty {
11271    #[serde(default)]
11272    pub no: Option<Box<Expression>>,
11273}
11274
11275/// MaterializedProperty
11276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11277#[cfg_attr(feature = "bindings", derive(TS))]
11278pub struct MaterializedProperty {
11279    #[serde(default)]
11280    pub this: Option<Box<Expression>>,
11281}
11282
11283/// MergeBlockRatioProperty
11284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11285#[cfg_attr(feature = "bindings", derive(TS))]
11286pub struct MergeBlockRatioProperty {
11287    #[serde(default)]
11288    pub this: Option<Box<Expression>>,
11289    #[serde(default)]
11290    pub no: Option<Box<Expression>>,
11291    #[serde(default)]
11292    pub default: Option<Box<Expression>>,
11293    #[serde(default)]
11294    pub percent: Option<Box<Expression>>,
11295}
11296
11297/// OnProperty
11298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11299#[cfg_attr(feature = "bindings", derive(TS))]
11300pub struct OnProperty {
11301    pub this: Box<Expression>,
11302}
11303
11304/// OnCommitProperty
11305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11306#[cfg_attr(feature = "bindings", derive(TS))]
11307pub struct OnCommitProperty {
11308    #[serde(default)]
11309    pub delete: Option<Box<Expression>>,
11310}
11311
11312/// PartitionedByProperty
11313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11314#[cfg_attr(feature = "bindings", derive(TS))]
11315pub struct PartitionedByProperty {
11316    pub this: Box<Expression>,
11317}
11318
11319/// BigQuery PARTITION BY property in CREATE TABLE statements.
11320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11321#[cfg_attr(feature = "bindings", derive(TS))]
11322pub struct PartitionByProperty {
11323    #[serde(default)]
11324    pub expressions: Vec<Expression>,
11325}
11326
11327/// PartitionedByBucket
11328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11329#[cfg_attr(feature = "bindings", derive(TS))]
11330pub struct PartitionedByBucket {
11331    pub this: Box<Expression>,
11332    pub expression: Box<Expression>,
11333}
11334
11335/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11337#[cfg_attr(feature = "bindings", derive(TS))]
11338pub struct ClusterByColumnsProperty {
11339    #[serde(default)]
11340    pub columns: Vec<Identifier>,
11341}
11342
11343/// PartitionByTruncate
11344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11345#[cfg_attr(feature = "bindings", derive(TS))]
11346pub struct PartitionByTruncate {
11347    pub this: Box<Expression>,
11348    pub expression: Box<Expression>,
11349}
11350
11351/// PartitionByRangeProperty
11352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11353#[cfg_attr(feature = "bindings", derive(TS))]
11354pub struct PartitionByRangeProperty {
11355    #[serde(default)]
11356    pub partition_expressions: Option<Box<Expression>>,
11357    #[serde(default)]
11358    pub create_expressions: Option<Box<Expression>>,
11359}
11360
11361/// PartitionByRangePropertyDynamic
11362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11363#[cfg_attr(feature = "bindings", derive(TS))]
11364pub struct PartitionByRangePropertyDynamic {
11365    #[serde(default)]
11366    pub this: Option<Box<Expression>>,
11367    #[serde(default)]
11368    pub start: Option<Box<Expression>>,
11369    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11370    #[serde(default)]
11371    pub use_start_end: bool,
11372    #[serde(default)]
11373    pub end: Option<Box<Expression>>,
11374    #[serde(default)]
11375    pub every: Option<Box<Expression>>,
11376}
11377
11378/// PartitionByListProperty
11379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11380#[cfg_attr(feature = "bindings", derive(TS))]
11381pub struct PartitionByListProperty {
11382    #[serde(default)]
11383    pub partition_expressions: Option<Box<Expression>>,
11384    #[serde(default)]
11385    pub create_expressions: Option<Box<Expression>>,
11386}
11387
11388/// PartitionList
11389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11390#[cfg_attr(feature = "bindings", derive(TS))]
11391pub struct PartitionList {
11392    pub this: Box<Expression>,
11393    #[serde(default)]
11394    pub expressions: Vec<Expression>,
11395}
11396
11397/// Partition - represents PARTITION/SUBPARTITION clause
11398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11399#[cfg_attr(feature = "bindings", derive(TS))]
11400pub struct Partition {
11401    pub expressions: Vec<Expression>,
11402    #[serde(default)]
11403    pub subpartition: bool,
11404}
11405
11406/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11407/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11409#[cfg_attr(feature = "bindings", derive(TS))]
11410pub struct RefreshTriggerProperty {
11411    /// Method: COMPLETE or AUTO
11412    pub method: String,
11413    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11414    #[serde(default)]
11415    pub kind: Option<String>,
11416    /// For SCHEDULE: EVERY n (the number)
11417    #[serde(default)]
11418    pub every: Option<Box<Expression>>,
11419    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11420    #[serde(default)]
11421    pub unit: Option<String>,
11422    /// For SCHEDULE: STARTS 'datetime'
11423    #[serde(default)]
11424    pub starts: Option<Box<Expression>>,
11425}
11426
11427/// UniqueKeyProperty
11428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11429#[cfg_attr(feature = "bindings", derive(TS))]
11430pub struct UniqueKeyProperty {
11431    #[serde(default)]
11432    pub expressions: Vec<Expression>,
11433}
11434
11435/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11437#[cfg_attr(feature = "bindings", derive(TS))]
11438pub struct RollupProperty {
11439    pub expressions: Vec<RollupIndex>,
11440}
11441
11442/// RollupIndex - A single rollup index: name(col1, col2)
11443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11444#[cfg_attr(feature = "bindings", derive(TS))]
11445pub struct RollupIndex {
11446    pub name: Identifier,
11447    pub expressions: Vec<Identifier>,
11448}
11449
11450/// PartitionBoundSpec
11451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11452#[cfg_attr(feature = "bindings", derive(TS))]
11453pub struct PartitionBoundSpec {
11454    #[serde(default)]
11455    pub this: Option<Box<Expression>>,
11456    #[serde(default)]
11457    pub expression: Option<Box<Expression>>,
11458    #[serde(default)]
11459    pub from_expressions: Option<Box<Expression>>,
11460    #[serde(default)]
11461    pub to_expressions: Option<Box<Expression>>,
11462}
11463
11464/// PartitionedOfProperty
11465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11466#[cfg_attr(feature = "bindings", derive(TS))]
11467pub struct PartitionedOfProperty {
11468    pub this: Box<Expression>,
11469    pub expression: Box<Expression>,
11470}
11471
11472/// RemoteWithConnectionModelProperty
11473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11474#[cfg_attr(feature = "bindings", derive(TS))]
11475pub struct RemoteWithConnectionModelProperty {
11476    pub this: Box<Expression>,
11477}
11478
11479/// ReturnsProperty
11480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11481#[cfg_attr(feature = "bindings", derive(TS))]
11482pub struct ReturnsProperty {
11483    #[serde(default)]
11484    pub this: Option<Box<Expression>>,
11485    #[serde(default)]
11486    pub is_table: Option<Box<Expression>>,
11487    #[serde(default)]
11488    pub table: Option<Box<Expression>>,
11489    #[serde(default)]
11490    pub null: Option<Box<Expression>>,
11491}
11492
11493/// RowFormatProperty
11494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11495#[cfg_attr(feature = "bindings", derive(TS))]
11496pub struct RowFormatProperty {
11497    pub this: Box<Expression>,
11498}
11499
11500/// RowFormatDelimitedProperty
11501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11502#[cfg_attr(feature = "bindings", derive(TS))]
11503pub struct RowFormatDelimitedProperty {
11504    #[serde(default)]
11505    pub fields: Option<Box<Expression>>,
11506    #[serde(default)]
11507    pub escaped: Option<Box<Expression>>,
11508    #[serde(default)]
11509    pub collection_items: Option<Box<Expression>>,
11510    #[serde(default)]
11511    pub map_keys: Option<Box<Expression>>,
11512    #[serde(default)]
11513    pub lines: Option<Box<Expression>>,
11514    #[serde(default)]
11515    pub null: Option<Box<Expression>>,
11516    #[serde(default)]
11517    pub serde: Option<Box<Expression>>,
11518}
11519
11520/// RowFormatSerdeProperty
11521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11522#[cfg_attr(feature = "bindings", derive(TS))]
11523pub struct RowFormatSerdeProperty {
11524    pub this: Box<Expression>,
11525    #[serde(default)]
11526    pub serde_properties: Option<Box<Expression>>,
11527}
11528
11529/// QueryTransform
11530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11531#[cfg_attr(feature = "bindings", derive(TS))]
11532pub struct QueryTransform {
11533    #[serde(default)]
11534    pub expressions: Vec<Expression>,
11535    #[serde(default)]
11536    pub command_script: Option<Box<Expression>>,
11537    #[serde(default)]
11538    pub schema: Option<Box<Expression>>,
11539    #[serde(default)]
11540    pub row_format_before: Option<Box<Expression>>,
11541    #[serde(default)]
11542    pub record_writer: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub row_format_after: Option<Box<Expression>>,
11545    #[serde(default)]
11546    pub record_reader: Option<Box<Expression>>,
11547}
11548
11549/// SampleProperty
11550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11551#[cfg_attr(feature = "bindings", derive(TS))]
11552pub struct SampleProperty {
11553    pub this: Box<Expression>,
11554}
11555
11556/// SecurityProperty
11557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11558#[cfg_attr(feature = "bindings", derive(TS))]
11559pub struct SecurityProperty {
11560    pub this: Box<Expression>,
11561}
11562
11563/// SchemaCommentProperty
11564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11565#[cfg_attr(feature = "bindings", derive(TS))]
11566pub struct SchemaCommentProperty {
11567    pub this: Box<Expression>,
11568}
11569
11570/// SemanticView
11571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11572#[cfg_attr(feature = "bindings", derive(TS))]
11573pub struct SemanticView {
11574    pub this: Box<Expression>,
11575    #[serde(default)]
11576    pub metrics: Option<Box<Expression>>,
11577    #[serde(default)]
11578    pub dimensions: Option<Box<Expression>>,
11579    #[serde(default)]
11580    pub facts: Option<Box<Expression>>,
11581    #[serde(default)]
11582    pub where_: Option<Box<Expression>>,
11583}
11584
11585/// SerdeProperties
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct SerdeProperties {
11589    #[serde(default)]
11590    pub expressions: Vec<Expression>,
11591    #[serde(default)]
11592    pub with_: Option<Box<Expression>>,
11593}
11594
11595/// SetProperty
11596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11597#[cfg_attr(feature = "bindings", derive(TS))]
11598pub struct SetProperty {
11599    #[serde(default)]
11600    pub multi: Option<Box<Expression>>,
11601}
11602
11603/// SharingProperty
11604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11605#[cfg_attr(feature = "bindings", derive(TS))]
11606pub struct SharingProperty {
11607    #[serde(default)]
11608    pub this: Option<Box<Expression>>,
11609}
11610
11611/// SetConfigProperty
11612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11613#[cfg_attr(feature = "bindings", derive(TS))]
11614pub struct SetConfigProperty {
11615    pub this: Box<Expression>,
11616}
11617
11618/// SettingsProperty
11619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11620#[cfg_attr(feature = "bindings", derive(TS))]
11621pub struct SettingsProperty {
11622    #[serde(default)]
11623    pub expressions: Vec<Expression>,
11624}
11625
11626/// SortKeyProperty
11627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11628#[cfg_attr(feature = "bindings", derive(TS))]
11629pub struct SortKeyProperty {
11630    pub this: Box<Expression>,
11631    #[serde(default)]
11632    pub compound: Option<Box<Expression>>,
11633}
11634
11635/// SqlReadWriteProperty
11636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11637#[cfg_attr(feature = "bindings", derive(TS))]
11638pub struct SqlReadWriteProperty {
11639    pub this: Box<Expression>,
11640}
11641
11642/// SqlSecurityProperty
11643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11644#[cfg_attr(feature = "bindings", derive(TS))]
11645pub struct SqlSecurityProperty {
11646    pub this: Box<Expression>,
11647}
11648
11649/// StabilityProperty
11650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11651#[cfg_attr(feature = "bindings", derive(TS))]
11652pub struct StabilityProperty {
11653    pub this: Box<Expression>,
11654}
11655
11656/// StorageHandlerProperty
11657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11658#[cfg_attr(feature = "bindings", derive(TS))]
11659pub struct StorageHandlerProperty {
11660    pub this: Box<Expression>,
11661}
11662
11663/// TemporaryProperty
11664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11665#[cfg_attr(feature = "bindings", derive(TS))]
11666pub struct TemporaryProperty {
11667    #[serde(default)]
11668    pub this: Option<Box<Expression>>,
11669}
11670
11671/// Tags
11672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11673#[cfg_attr(feature = "bindings", derive(TS))]
11674pub struct Tags {
11675    #[serde(default)]
11676    pub expressions: Vec<Expression>,
11677}
11678
11679/// TransformModelProperty
11680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11681#[cfg_attr(feature = "bindings", derive(TS))]
11682pub struct TransformModelProperty {
11683    #[serde(default)]
11684    pub expressions: Vec<Expression>,
11685}
11686
11687/// TransientProperty
11688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11689#[cfg_attr(feature = "bindings", derive(TS))]
11690pub struct TransientProperty {
11691    #[serde(default)]
11692    pub this: Option<Box<Expression>>,
11693}
11694
11695/// UsingTemplateProperty
11696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11697#[cfg_attr(feature = "bindings", derive(TS))]
11698pub struct UsingTemplateProperty {
11699    pub this: Box<Expression>,
11700}
11701
11702/// ViewAttributeProperty
11703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11704#[cfg_attr(feature = "bindings", derive(TS))]
11705pub struct ViewAttributeProperty {
11706    pub this: Box<Expression>,
11707}
11708
11709/// VolatileProperty
11710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11711#[cfg_attr(feature = "bindings", derive(TS))]
11712pub struct VolatileProperty {
11713    #[serde(default)]
11714    pub this: Option<Box<Expression>>,
11715}
11716
11717/// WithDataProperty
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct WithDataProperty {
11721    #[serde(default)]
11722    pub no: Option<Box<Expression>>,
11723    #[serde(default)]
11724    pub statistics: Option<Box<Expression>>,
11725}
11726
11727/// WithJournalTableProperty
11728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11729#[cfg_attr(feature = "bindings", derive(TS))]
11730pub struct WithJournalTableProperty {
11731    pub this: Box<Expression>,
11732}
11733
11734/// WithSchemaBindingProperty
11735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11736#[cfg_attr(feature = "bindings", derive(TS))]
11737pub struct WithSchemaBindingProperty {
11738    pub this: Box<Expression>,
11739}
11740
11741/// WithSystemVersioningProperty
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct WithSystemVersioningProperty {
11745    #[serde(default)]
11746    pub on: Option<Box<Expression>>,
11747    #[serde(default)]
11748    pub this: Option<Box<Expression>>,
11749    #[serde(default)]
11750    pub data_consistency: Option<Box<Expression>>,
11751    #[serde(default)]
11752    pub retention_period: Option<Box<Expression>>,
11753    #[serde(default)]
11754    pub with_: Option<Box<Expression>>,
11755}
11756
11757/// WithProcedureOptions
11758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11759#[cfg_attr(feature = "bindings", derive(TS))]
11760pub struct WithProcedureOptions {
11761    #[serde(default)]
11762    pub expressions: Vec<Expression>,
11763}
11764
11765/// EncodeProperty
11766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11767#[cfg_attr(feature = "bindings", derive(TS))]
11768pub struct EncodeProperty {
11769    pub this: Box<Expression>,
11770    #[serde(default)]
11771    pub properties: Vec<Expression>,
11772    #[serde(default)]
11773    pub key: Option<Box<Expression>>,
11774}
11775
11776/// IncludeProperty
11777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11778#[cfg_attr(feature = "bindings", derive(TS))]
11779pub struct IncludeProperty {
11780    pub this: Box<Expression>,
11781    #[serde(default)]
11782    pub alias: Option<String>,
11783    #[serde(default)]
11784    pub column_def: Option<Box<Expression>>,
11785}
11786
11787/// Properties
11788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11789#[cfg_attr(feature = "bindings", derive(TS))]
11790pub struct Properties {
11791    #[serde(default)]
11792    pub expressions: Vec<Expression>,
11793}
11794
11795/// Key/value pair in a BigQuery OPTIONS (...) clause.
11796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11797#[cfg_attr(feature = "bindings", derive(TS))]
11798pub struct OptionEntry {
11799    pub key: Identifier,
11800    pub value: Expression,
11801}
11802
11803/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11805#[cfg_attr(feature = "bindings", derive(TS))]
11806pub struct OptionsProperty {
11807    #[serde(default)]
11808    pub entries: Vec<OptionEntry>,
11809}
11810
11811/// InputOutputFormat
11812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11813#[cfg_attr(feature = "bindings", derive(TS))]
11814pub struct InputOutputFormat {
11815    #[serde(default)]
11816    pub input_format: Option<Box<Expression>>,
11817    #[serde(default)]
11818    pub output_format: Option<Box<Expression>>,
11819}
11820
11821/// Reference
11822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11823#[cfg_attr(feature = "bindings", derive(TS))]
11824pub struct Reference {
11825    pub this: Box<Expression>,
11826    #[serde(default)]
11827    pub expressions: Vec<Expression>,
11828    #[serde(default)]
11829    pub options: Vec<Expression>,
11830}
11831
11832/// QueryOption
11833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11834#[cfg_attr(feature = "bindings", derive(TS))]
11835pub struct QueryOption {
11836    pub this: Box<Expression>,
11837    #[serde(default)]
11838    pub expression: Option<Box<Expression>>,
11839}
11840
11841/// WithTableHint
11842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11843#[cfg_attr(feature = "bindings", derive(TS))]
11844pub struct WithTableHint {
11845    #[serde(default)]
11846    pub expressions: Vec<Expression>,
11847}
11848
11849/// IndexTableHint
11850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11851#[cfg_attr(feature = "bindings", derive(TS))]
11852pub struct IndexTableHint {
11853    pub this: Box<Expression>,
11854    #[serde(default)]
11855    pub expressions: Vec<Expression>,
11856    #[serde(default)]
11857    pub target: Option<Box<Expression>>,
11858}
11859
11860/// Get
11861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11862#[cfg_attr(feature = "bindings", derive(TS))]
11863pub struct Get {
11864    pub this: Box<Expression>,
11865    #[serde(default)]
11866    pub target: Option<Box<Expression>>,
11867    #[serde(default)]
11868    pub properties: Vec<Expression>,
11869}
11870
11871/// SetOperation
11872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11873#[cfg_attr(feature = "bindings", derive(TS))]
11874pub struct SetOperation {
11875    #[serde(default)]
11876    pub with_: Option<Box<Expression>>,
11877    pub this: Box<Expression>,
11878    pub expression: Box<Expression>,
11879    #[serde(default)]
11880    pub distinct: bool,
11881    #[serde(default)]
11882    pub by_name: Option<Box<Expression>>,
11883    #[serde(default)]
11884    pub side: Option<Box<Expression>>,
11885    #[serde(default)]
11886    pub kind: Option<String>,
11887    #[serde(default)]
11888    pub on: Option<Box<Expression>>,
11889}
11890
11891/// Var - Simple variable reference (for SQL variables, keywords as values)
11892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11893#[cfg_attr(feature = "bindings", derive(TS))]
11894pub struct Var {
11895    pub this: String,
11896}
11897
11898/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11900#[cfg_attr(feature = "bindings", derive(TS))]
11901pub struct Variadic {
11902    pub this: Box<Expression>,
11903}
11904
11905/// Version
11906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11907#[cfg_attr(feature = "bindings", derive(TS))]
11908pub struct Version {
11909    pub this: Box<Expression>,
11910    pub kind: String,
11911    #[serde(default)]
11912    pub expression: Option<Box<Expression>>,
11913}
11914
11915/// Schema
11916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11917#[cfg_attr(feature = "bindings", derive(TS))]
11918pub struct Schema {
11919    #[serde(default)]
11920    pub this: Option<Box<Expression>>,
11921    #[serde(default)]
11922    pub expressions: Vec<Expression>,
11923}
11924
11925/// Lock
11926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11927#[cfg_attr(feature = "bindings", derive(TS))]
11928pub struct Lock {
11929    #[serde(default)]
11930    pub update: Option<Box<Expression>>,
11931    #[serde(default)]
11932    pub expressions: Vec<Expression>,
11933    #[serde(default)]
11934    pub wait: Option<Box<Expression>>,
11935    #[serde(default)]
11936    pub key: Option<Box<Expression>>,
11937}
11938
11939/// TableSample - wraps an expression with a TABLESAMPLE clause
11940/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11942#[cfg_attr(feature = "bindings", derive(TS))]
11943pub struct TableSample {
11944    /// The expression being sampled (subquery, function, etc.)
11945    #[serde(default, skip_serializing_if = "Option::is_none")]
11946    pub this: Option<Box<Expression>>,
11947    /// The sample specification
11948    #[serde(default, skip_serializing_if = "Option::is_none")]
11949    pub sample: Option<Box<Sample>>,
11950    #[serde(default)]
11951    pub expressions: Vec<Expression>,
11952    #[serde(default)]
11953    pub method: Option<String>,
11954    #[serde(default)]
11955    pub bucket_numerator: Option<Box<Expression>>,
11956    #[serde(default)]
11957    pub bucket_denominator: Option<Box<Expression>>,
11958    #[serde(default)]
11959    pub bucket_field: Option<Box<Expression>>,
11960    #[serde(default)]
11961    pub percent: Option<Box<Expression>>,
11962    #[serde(default)]
11963    pub rows: Option<Box<Expression>>,
11964    #[serde(default)]
11965    pub size: Option<i64>,
11966    #[serde(default)]
11967    pub seed: Option<Box<Expression>>,
11968}
11969
11970/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11972#[cfg_attr(feature = "bindings", derive(TS))]
11973pub struct Tag {
11974    #[serde(default)]
11975    pub this: Option<Box<Expression>>,
11976    #[serde(default)]
11977    pub prefix: Option<Box<Expression>>,
11978    #[serde(default)]
11979    pub postfix: Option<Box<Expression>>,
11980}
11981
11982/// UnpivotColumns
11983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11984#[cfg_attr(feature = "bindings", derive(TS))]
11985pub struct UnpivotColumns {
11986    pub this: Box<Expression>,
11987    #[serde(default)]
11988    pub expressions: Vec<Expression>,
11989}
11990
11991/// SessionParameter
11992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11993#[cfg_attr(feature = "bindings", derive(TS))]
11994pub struct SessionParameter {
11995    pub this: Box<Expression>,
11996    #[serde(default)]
11997    pub kind: Option<String>,
11998}
11999
12000/// PseudoType
12001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12002#[cfg_attr(feature = "bindings", derive(TS))]
12003pub struct PseudoType {
12004    pub this: Box<Expression>,
12005}
12006
12007/// ObjectIdentifier
12008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12009#[cfg_attr(feature = "bindings", derive(TS))]
12010pub struct ObjectIdentifier {
12011    pub this: Box<Expression>,
12012}
12013
12014/// Transaction
12015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12016#[cfg_attr(feature = "bindings", derive(TS))]
12017pub struct Transaction {
12018    #[serde(default)]
12019    pub this: Option<Box<Expression>>,
12020    #[serde(default)]
12021    pub modes: Option<Box<Expression>>,
12022    #[serde(default)]
12023    pub mark: Option<Box<Expression>>,
12024}
12025
12026/// Commit
12027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12028#[cfg_attr(feature = "bindings", derive(TS))]
12029pub struct Commit {
12030    #[serde(default)]
12031    pub chain: Option<Box<Expression>>,
12032    #[serde(default)]
12033    pub this: Option<Box<Expression>>,
12034    #[serde(default)]
12035    pub durability: Option<Box<Expression>>,
12036}
12037
12038/// Rollback
12039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12040#[cfg_attr(feature = "bindings", derive(TS))]
12041pub struct Rollback {
12042    #[serde(default)]
12043    pub savepoint: Option<Box<Expression>>,
12044    #[serde(default)]
12045    pub this: Option<Box<Expression>>,
12046}
12047
12048/// AlterSession
12049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12050#[cfg_attr(feature = "bindings", derive(TS))]
12051pub struct AlterSession {
12052    #[serde(default)]
12053    pub expressions: Vec<Expression>,
12054    #[serde(default)]
12055    pub unset: Option<Box<Expression>>,
12056}
12057
12058/// Analyze
12059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12060#[cfg_attr(feature = "bindings", derive(TS))]
12061pub struct Analyze {
12062    #[serde(default)]
12063    pub kind: Option<String>,
12064    #[serde(default)]
12065    pub this: Option<Box<Expression>>,
12066    #[serde(default)]
12067    pub options: Vec<Expression>,
12068    #[serde(default)]
12069    pub mode: Option<Box<Expression>>,
12070    #[serde(default)]
12071    pub partition: Option<Box<Expression>>,
12072    #[serde(default)]
12073    pub expression: Option<Box<Expression>>,
12074    #[serde(default)]
12075    pub properties: Vec<Expression>,
12076    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
12077    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12078    pub columns: Vec<String>,
12079}
12080
12081/// AnalyzeStatistics
12082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12083#[cfg_attr(feature = "bindings", derive(TS))]
12084pub struct AnalyzeStatistics {
12085    pub kind: String,
12086    #[serde(default)]
12087    pub option: Option<Box<Expression>>,
12088    #[serde(default)]
12089    pub this: Option<Box<Expression>>,
12090    #[serde(default)]
12091    pub expressions: Vec<Expression>,
12092}
12093
12094/// AnalyzeHistogram
12095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12096#[cfg_attr(feature = "bindings", derive(TS))]
12097pub struct AnalyzeHistogram {
12098    pub this: Box<Expression>,
12099    #[serde(default)]
12100    pub expressions: Vec<Expression>,
12101    #[serde(default)]
12102    pub expression: Option<Box<Expression>>,
12103    #[serde(default)]
12104    pub update_options: Option<Box<Expression>>,
12105}
12106
12107/// AnalyzeSample
12108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12109#[cfg_attr(feature = "bindings", derive(TS))]
12110pub struct AnalyzeSample {
12111    pub kind: String,
12112    #[serde(default)]
12113    pub sample: Option<Box<Expression>>,
12114}
12115
12116/// AnalyzeListChainedRows
12117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12118#[cfg_attr(feature = "bindings", derive(TS))]
12119pub struct AnalyzeListChainedRows {
12120    #[serde(default)]
12121    pub expression: Option<Box<Expression>>,
12122}
12123
12124/// AnalyzeDelete
12125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12126#[cfg_attr(feature = "bindings", derive(TS))]
12127pub struct AnalyzeDelete {
12128    #[serde(default)]
12129    pub kind: Option<String>,
12130}
12131
12132/// AnalyzeWith
12133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12134#[cfg_attr(feature = "bindings", derive(TS))]
12135pub struct AnalyzeWith {
12136    #[serde(default)]
12137    pub expressions: Vec<Expression>,
12138}
12139
12140/// AnalyzeValidate
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct AnalyzeValidate {
12144    pub kind: String,
12145    #[serde(default)]
12146    pub this: Option<Box<Expression>>,
12147    #[serde(default)]
12148    pub expression: Option<Box<Expression>>,
12149}
12150
12151/// AddPartition
12152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12153#[cfg_attr(feature = "bindings", derive(TS))]
12154pub struct AddPartition {
12155    pub this: Box<Expression>,
12156    #[serde(default)]
12157    pub exists: bool,
12158    #[serde(default)]
12159    pub location: Option<Box<Expression>>,
12160}
12161
12162/// AttachOption
12163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12164#[cfg_attr(feature = "bindings", derive(TS))]
12165pub struct AttachOption {
12166    pub this: Box<Expression>,
12167    #[serde(default)]
12168    pub expression: Option<Box<Expression>>,
12169}
12170
12171/// DropPartition
12172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12173#[cfg_attr(feature = "bindings", derive(TS))]
12174pub struct DropPartition {
12175    #[serde(default)]
12176    pub expressions: Vec<Expression>,
12177    #[serde(default)]
12178    pub exists: bool,
12179}
12180
12181/// ReplacePartition
12182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12183#[cfg_attr(feature = "bindings", derive(TS))]
12184pub struct ReplacePartition {
12185    pub expression: Box<Expression>,
12186    #[serde(default)]
12187    pub source: Option<Box<Expression>>,
12188}
12189
12190/// DPipe
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct DPipe {
12194    pub this: Box<Expression>,
12195    pub expression: Box<Expression>,
12196    #[serde(default)]
12197    pub safe: Option<Box<Expression>>,
12198}
12199
12200/// Operator
12201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12202#[cfg_attr(feature = "bindings", derive(TS))]
12203pub struct Operator {
12204    pub this: Box<Expression>,
12205    #[serde(default)]
12206    pub operator: Option<Box<Expression>>,
12207    pub expression: Box<Expression>,
12208    /// Comments between OPERATOR() and the RHS expression
12209    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12210    pub comments: Vec<String>,
12211}
12212
12213/// PivotAny
12214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12215#[cfg_attr(feature = "bindings", derive(TS))]
12216pub struct PivotAny {
12217    #[serde(default)]
12218    pub this: Option<Box<Expression>>,
12219}
12220
12221/// Aliases
12222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12223#[cfg_attr(feature = "bindings", derive(TS))]
12224pub struct Aliases {
12225    pub this: Box<Expression>,
12226    #[serde(default)]
12227    pub expressions: Vec<Expression>,
12228}
12229
12230/// AtIndex
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct AtIndex {
12234    pub this: Box<Expression>,
12235    pub expression: Box<Expression>,
12236}
12237
12238/// FromTimeZone
12239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12240#[cfg_attr(feature = "bindings", derive(TS))]
12241pub struct FromTimeZone {
12242    pub this: Box<Expression>,
12243    #[serde(default)]
12244    pub zone: Option<Box<Expression>>,
12245}
12246
12247/// Format override for a column in Teradata
12248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12249#[cfg_attr(feature = "bindings", derive(TS))]
12250pub struct FormatPhrase {
12251    pub this: Box<Expression>,
12252    pub format: String,
12253}
12254
12255/// ForIn
12256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12257#[cfg_attr(feature = "bindings", derive(TS))]
12258pub struct ForIn {
12259    pub this: Box<Expression>,
12260    pub expression: Box<Expression>,
12261}
12262
12263/// Automatically converts unit arg into a var.
12264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12265#[cfg_attr(feature = "bindings", derive(TS))]
12266pub struct TimeUnit {
12267    #[serde(default)]
12268    pub unit: Option<String>,
12269}
12270
12271/// IntervalOp
12272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12273#[cfg_attr(feature = "bindings", derive(TS))]
12274pub struct IntervalOp {
12275    #[serde(default)]
12276    pub unit: Option<String>,
12277    pub expression: Box<Expression>,
12278}
12279
12280/// HavingMax
12281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12282#[cfg_attr(feature = "bindings", derive(TS))]
12283pub struct HavingMax {
12284    pub this: Box<Expression>,
12285    pub expression: Box<Expression>,
12286    #[serde(default)]
12287    pub max: Option<Box<Expression>>,
12288}
12289
12290/// CosineDistance
12291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12292#[cfg_attr(feature = "bindings", derive(TS))]
12293pub struct CosineDistance {
12294    pub this: Box<Expression>,
12295    pub expression: Box<Expression>,
12296}
12297
12298/// DotProduct
12299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12300#[cfg_attr(feature = "bindings", derive(TS))]
12301pub struct DotProduct {
12302    pub this: Box<Expression>,
12303    pub expression: Box<Expression>,
12304}
12305
12306/// EuclideanDistance
12307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12308#[cfg_attr(feature = "bindings", derive(TS))]
12309pub struct EuclideanDistance {
12310    pub this: Box<Expression>,
12311    pub expression: Box<Expression>,
12312}
12313
12314/// ManhattanDistance
12315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12316#[cfg_attr(feature = "bindings", derive(TS))]
12317pub struct ManhattanDistance {
12318    pub this: Box<Expression>,
12319    pub expression: Box<Expression>,
12320}
12321
12322/// JarowinklerSimilarity
12323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12324#[cfg_attr(feature = "bindings", derive(TS))]
12325pub struct JarowinklerSimilarity {
12326    pub this: Box<Expression>,
12327    pub expression: Box<Expression>,
12328}
12329
12330/// Booland
12331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12332#[cfg_attr(feature = "bindings", derive(TS))]
12333pub struct Booland {
12334    pub this: Box<Expression>,
12335    pub expression: Box<Expression>,
12336}
12337
12338/// Boolor
12339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12340#[cfg_attr(feature = "bindings", derive(TS))]
12341pub struct Boolor {
12342    pub this: Box<Expression>,
12343    pub expression: Box<Expression>,
12344}
12345
12346/// ParameterizedAgg
12347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12348#[cfg_attr(feature = "bindings", derive(TS))]
12349pub struct ParameterizedAgg {
12350    pub this: Box<Expression>,
12351    #[serde(default)]
12352    pub expressions: Vec<Expression>,
12353    #[serde(default)]
12354    pub params: Vec<Expression>,
12355}
12356
12357/// ArgMax
12358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12359#[cfg_attr(feature = "bindings", derive(TS))]
12360pub struct ArgMax {
12361    pub this: Box<Expression>,
12362    pub expression: Box<Expression>,
12363    #[serde(default)]
12364    pub count: Option<Box<Expression>>,
12365}
12366
12367/// ArgMin
12368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12369#[cfg_attr(feature = "bindings", derive(TS))]
12370pub struct ArgMin {
12371    pub this: Box<Expression>,
12372    pub expression: Box<Expression>,
12373    #[serde(default)]
12374    pub count: Option<Box<Expression>>,
12375}
12376
12377/// ApproxTopK
12378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12379#[cfg_attr(feature = "bindings", derive(TS))]
12380pub struct ApproxTopK {
12381    pub this: Box<Expression>,
12382    #[serde(default)]
12383    pub expression: Option<Box<Expression>>,
12384    #[serde(default)]
12385    pub counters: Option<Box<Expression>>,
12386}
12387
12388/// ApproxTopKAccumulate
12389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12390#[cfg_attr(feature = "bindings", derive(TS))]
12391pub struct ApproxTopKAccumulate {
12392    pub this: Box<Expression>,
12393    #[serde(default)]
12394    pub expression: Option<Box<Expression>>,
12395}
12396
12397/// ApproxTopKCombine
12398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12399#[cfg_attr(feature = "bindings", derive(TS))]
12400pub struct ApproxTopKCombine {
12401    pub this: Box<Expression>,
12402    #[serde(default)]
12403    pub expression: Option<Box<Expression>>,
12404}
12405
12406/// ApproxTopKEstimate
12407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12408#[cfg_attr(feature = "bindings", derive(TS))]
12409pub struct ApproxTopKEstimate {
12410    pub this: Box<Expression>,
12411    #[serde(default)]
12412    pub expression: Option<Box<Expression>>,
12413}
12414
12415/// ApproxTopSum
12416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12417#[cfg_attr(feature = "bindings", derive(TS))]
12418pub struct ApproxTopSum {
12419    pub this: Box<Expression>,
12420    pub expression: Box<Expression>,
12421    #[serde(default)]
12422    pub count: Option<Box<Expression>>,
12423}
12424
12425/// ApproxQuantiles
12426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12427#[cfg_attr(feature = "bindings", derive(TS))]
12428pub struct ApproxQuantiles {
12429    pub this: Box<Expression>,
12430    #[serde(default)]
12431    pub expression: Option<Box<Expression>>,
12432}
12433
12434/// Minhash
12435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12436#[cfg_attr(feature = "bindings", derive(TS))]
12437pub struct Minhash {
12438    pub this: Box<Expression>,
12439    #[serde(default)]
12440    pub expressions: Vec<Expression>,
12441}
12442
12443/// FarmFingerprint
12444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12445#[cfg_attr(feature = "bindings", derive(TS))]
12446pub struct FarmFingerprint {
12447    #[serde(default)]
12448    pub expressions: Vec<Expression>,
12449}
12450
12451/// Float64
12452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12453#[cfg_attr(feature = "bindings", derive(TS))]
12454pub struct Float64 {
12455    pub this: Box<Expression>,
12456    #[serde(default)]
12457    pub expression: Option<Box<Expression>>,
12458}
12459
12460/// Transform
12461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12462#[cfg_attr(feature = "bindings", derive(TS))]
12463pub struct Transform {
12464    pub this: Box<Expression>,
12465    pub expression: Box<Expression>,
12466}
12467
12468/// Translate
12469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12470#[cfg_attr(feature = "bindings", derive(TS))]
12471pub struct Translate {
12472    pub this: Box<Expression>,
12473    #[serde(default)]
12474    pub from_: Option<Box<Expression>>,
12475    #[serde(default)]
12476    pub to: Option<Box<Expression>>,
12477}
12478
12479/// Grouping
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct Grouping {
12483    #[serde(default)]
12484    pub expressions: Vec<Expression>,
12485}
12486
12487/// GroupingId
12488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12489#[cfg_attr(feature = "bindings", derive(TS))]
12490pub struct GroupingId {
12491    #[serde(default)]
12492    pub expressions: Vec<Expression>,
12493}
12494
12495/// Anonymous
12496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12497#[cfg_attr(feature = "bindings", derive(TS))]
12498pub struct Anonymous {
12499    pub this: Box<Expression>,
12500    #[serde(default)]
12501    pub expressions: Vec<Expression>,
12502}
12503
12504/// AnonymousAggFunc
12505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12506#[cfg_attr(feature = "bindings", derive(TS))]
12507pub struct AnonymousAggFunc {
12508    pub this: Box<Expression>,
12509    #[serde(default)]
12510    pub expressions: Vec<Expression>,
12511}
12512
12513/// CombinedAggFunc
12514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12515#[cfg_attr(feature = "bindings", derive(TS))]
12516pub struct CombinedAggFunc {
12517    pub this: Box<Expression>,
12518    #[serde(default)]
12519    pub expressions: Vec<Expression>,
12520}
12521
12522/// CombinedParameterizedAgg
12523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12524#[cfg_attr(feature = "bindings", derive(TS))]
12525pub struct CombinedParameterizedAgg {
12526    pub this: Box<Expression>,
12527    #[serde(default)]
12528    pub expressions: Vec<Expression>,
12529    #[serde(default)]
12530    pub params: Vec<Expression>,
12531}
12532
12533/// HashAgg
12534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12535#[cfg_attr(feature = "bindings", derive(TS))]
12536pub struct HashAgg {
12537    pub this: Box<Expression>,
12538    #[serde(default)]
12539    pub expressions: Vec<Expression>,
12540}
12541
12542/// Hll
12543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12544#[cfg_attr(feature = "bindings", derive(TS))]
12545pub struct Hll {
12546    pub this: Box<Expression>,
12547    #[serde(default)]
12548    pub expressions: Vec<Expression>,
12549}
12550
12551/// Apply
12552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12553#[cfg_attr(feature = "bindings", derive(TS))]
12554pub struct Apply {
12555    pub this: Box<Expression>,
12556    pub expression: Box<Expression>,
12557}
12558
12559/// ToBoolean
12560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12561#[cfg_attr(feature = "bindings", derive(TS))]
12562pub struct ToBoolean {
12563    pub this: Box<Expression>,
12564    #[serde(default)]
12565    pub safe: Option<Box<Expression>>,
12566}
12567
12568/// List
12569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12570#[cfg_attr(feature = "bindings", derive(TS))]
12571pub struct List {
12572    #[serde(default)]
12573    pub expressions: Vec<Expression>,
12574}
12575
12576/// ToMap - Materialize-style map constructor
12577/// Can hold either:
12578/// - A SELECT subquery (MAP(SELECT 'a', 1))
12579/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12581#[cfg_attr(feature = "bindings", derive(TS))]
12582pub struct ToMap {
12583    /// Either a Select subquery or a Struct containing PropertyEQ entries
12584    pub this: Box<Expression>,
12585}
12586
12587/// Pad
12588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12589#[cfg_attr(feature = "bindings", derive(TS))]
12590pub struct Pad {
12591    pub this: Box<Expression>,
12592    pub expression: Box<Expression>,
12593    #[serde(default)]
12594    pub fill_pattern: Option<Box<Expression>>,
12595    #[serde(default)]
12596    pub is_left: Option<Box<Expression>>,
12597}
12598
12599/// ToChar
12600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12601#[cfg_attr(feature = "bindings", derive(TS))]
12602pub struct ToChar {
12603    pub this: Box<Expression>,
12604    #[serde(default)]
12605    pub format: Option<String>,
12606    #[serde(default)]
12607    pub nlsparam: Option<Box<Expression>>,
12608    #[serde(default)]
12609    pub is_numeric: Option<Box<Expression>>,
12610}
12611
12612/// StringFunc - String type conversion function (BigQuery STRING)
12613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12614#[cfg_attr(feature = "bindings", derive(TS))]
12615pub struct StringFunc {
12616    pub this: Box<Expression>,
12617    #[serde(default)]
12618    pub zone: Option<Box<Expression>>,
12619}
12620
12621/// ToNumber
12622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12623#[cfg_attr(feature = "bindings", derive(TS))]
12624pub struct ToNumber {
12625    pub this: Box<Expression>,
12626    #[serde(default)]
12627    pub format: Option<Box<Expression>>,
12628    #[serde(default)]
12629    pub nlsparam: Option<Box<Expression>>,
12630    #[serde(default)]
12631    pub precision: Option<Box<Expression>>,
12632    #[serde(default)]
12633    pub scale: Option<Box<Expression>>,
12634    #[serde(default)]
12635    pub safe: Option<Box<Expression>>,
12636    #[serde(default)]
12637    pub safe_name: Option<Box<Expression>>,
12638}
12639
12640/// ToDouble
12641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12642#[cfg_attr(feature = "bindings", derive(TS))]
12643pub struct ToDouble {
12644    pub this: Box<Expression>,
12645    #[serde(default)]
12646    pub format: Option<String>,
12647    #[serde(default)]
12648    pub safe: Option<Box<Expression>>,
12649}
12650
12651/// ToDecfloat
12652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12653#[cfg_attr(feature = "bindings", derive(TS))]
12654pub struct ToDecfloat {
12655    pub this: Box<Expression>,
12656    #[serde(default)]
12657    pub format: Option<String>,
12658}
12659
12660/// TryToDecfloat
12661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12662#[cfg_attr(feature = "bindings", derive(TS))]
12663pub struct TryToDecfloat {
12664    pub this: Box<Expression>,
12665    #[serde(default)]
12666    pub format: Option<String>,
12667}
12668
12669/// ToFile
12670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12671#[cfg_attr(feature = "bindings", derive(TS))]
12672pub struct ToFile {
12673    pub this: Box<Expression>,
12674    #[serde(default)]
12675    pub path: Option<Box<Expression>>,
12676    #[serde(default)]
12677    pub safe: Option<Box<Expression>>,
12678}
12679
12680/// Columns
12681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12682#[cfg_attr(feature = "bindings", derive(TS))]
12683pub struct Columns {
12684    pub this: Box<Expression>,
12685    #[serde(default)]
12686    pub unpack: Option<Box<Expression>>,
12687}
12688
12689/// ConvertToCharset
12690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12691#[cfg_attr(feature = "bindings", derive(TS))]
12692pub struct ConvertToCharset {
12693    pub this: Box<Expression>,
12694    #[serde(default)]
12695    pub dest: Option<Box<Expression>>,
12696    #[serde(default)]
12697    pub source: Option<Box<Expression>>,
12698}
12699
12700/// ConvertTimezone
12701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12702#[cfg_attr(feature = "bindings", derive(TS))]
12703pub struct ConvertTimezone {
12704    #[serde(default)]
12705    pub source_tz: Option<Box<Expression>>,
12706    #[serde(default)]
12707    pub target_tz: Option<Box<Expression>>,
12708    #[serde(default)]
12709    pub timestamp: Option<Box<Expression>>,
12710    #[serde(default)]
12711    pub options: Vec<Expression>,
12712}
12713
12714/// GenerateSeries
12715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12716#[cfg_attr(feature = "bindings", derive(TS))]
12717pub struct GenerateSeries {
12718    #[serde(default)]
12719    pub start: Option<Box<Expression>>,
12720    #[serde(default)]
12721    pub end: Option<Box<Expression>>,
12722    #[serde(default)]
12723    pub step: Option<Box<Expression>>,
12724    #[serde(default)]
12725    pub is_end_exclusive: Option<Box<Expression>>,
12726}
12727
12728/// AIAgg
12729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12730#[cfg_attr(feature = "bindings", derive(TS))]
12731pub struct AIAgg {
12732    pub this: Box<Expression>,
12733    pub expression: Box<Expression>,
12734}
12735
12736/// AIClassify
12737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12738#[cfg_attr(feature = "bindings", derive(TS))]
12739pub struct AIClassify {
12740    pub this: Box<Expression>,
12741    #[serde(default)]
12742    pub categories: Option<Box<Expression>>,
12743    #[serde(default)]
12744    pub config: Option<Box<Expression>>,
12745}
12746
12747/// ArrayAll
12748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12749#[cfg_attr(feature = "bindings", derive(TS))]
12750pub struct ArrayAll {
12751    pub this: Box<Expression>,
12752    pub expression: Box<Expression>,
12753}
12754
12755/// ArrayAny
12756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12757#[cfg_attr(feature = "bindings", derive(TS))]
12758pub struct ArrayAny {
12759    pub this: Box<Expression>,
12760    pub expression: Box<Expression>,
12761}
12762
12763/// ArrayConstructCompact
12764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12765#[cfg_attr(feature = "bindings", derive(TS))]
12766pub struct ArrayConstructCompact {
12767    #[serde(default)]
12768    pub expressions: Vec<Expression>,
12769}
12770
12771/// StPoint
12772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12773#[cfg_attr(feature = "bindings", derive(TS))]
12774pub struct StPoint {
12775    pub this: Box<Expression>,
12776    pub expression: Box<Expression>,
12777    #[serde(default)]
12778    pub null: Option<Box<Expression>>,
12779}
12780
12781/// StDistance
12782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12783#[cfg_attr(feature = "bindings", derive(TS))]
12784pub struct StDistance {
12785    pub this: Box<Expression>,
12786    pub expression: Box<Expression>,
12787    #[serde(default)]
12788    pub use_spheroid: Option<Box<Expression>>,
12789}
12790
12791/// StringToArray
12792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12793#[cfg_attr(feature = "bindings", derive(TS))]
12794pub struct StringToArray {
12795    pub this: Box<Expression>,
12796    #[serde(default)]
12797    pub expression: Option<Box<Expression>>,
12798    #[serde(default)]
12799    pub null: Option<Box<Expression>>,
12800}
12801
12802/// ArraySum
12803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12804#[cfg_attr(feature = "bindings", derive(TS))]
12805pub struct ArraySum {
12806    pub this: Box<Expression>,
12807    #[serde(default)]
12808    pub expression: Option<Box<Expression>>,
12809}
12810
12811/// ObjectAgg
12812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12813#[cfg_attr(feature = "bindings", derive(TS))]
12814pub struct ObjectAgg {
12815    pub this: Box<Expression>,
12816    pub expression: Box<Expression>,
12817}
12818
12819/// CastToStrType
12820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12821#[cfg_attr(feature = "bindings", derive(TS))]
12822pub struct CastToStrType {
12823    pub this: Box<Expression>,
12824    #[serde(default)]
12825    pub to: Option<Box<Expression>>,
12826}
12827
12828/// CheckJson
12829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12830#[cfg_attr(feature = "bindings", derive(TS))]
12831pub struct CheckJson {
12832    pub this: Box<Expression>,
12833}
12834
12835/// CheckXml
12836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12837#[cfg_attr(feature = "bindings", derive(TS))]
12838pub struct CheckXml {
12839    pub this: Box<Expression>,
12840    #[serde(default)]
12841    pub disable_auto_convert: Option<Box<Expression>>,
12842}
12843
12844/// TranslateCharacters
12845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12846#[cfg_attr(feature = "bindings", derive(TS))]
12847pub struct TranslateCharacters {
12848    pub this: Box<Expression>,
12849    pub expression: Box<Expression>,
12850    #[serde(default)]
12851    pub with_error: Option<Box<Expression>>,
12852}
12853
12854/// CurrentSchemas
12855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12856#[cfg_attr(feature = "bindings", derive(TS))]
12857pub struct CurrentSchemas {
12858    #[serde(default)]
12859    pub this: Option<Box<Expression>>,
12860}
12861
12862/// CurrentDatetime
12863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12864#[cfg_attr(feature = "bindings", derive(TS))]
12865pub struct CurrentDatetime {
12866    #[serde(default)]
12867    pub this: Option<Box<Expression>>,
12868}
12869
12870/// Localtime
12871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12872#[cfg_attr(feature = "bindings", derive(TS))]
12873pub struct Localtime {
12874    #[serde(default)]
12875    pub this: Option<Box<Expression>>,
12876}
12877
12878/// Localtimestamp
12879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12880#[cfg_attr(feature = "bindings", derive(TS))]
12881pub struct Localtimestamp {
12882    #[serde(default)]
12883    pub this: Option<Box<Expression>>,
12884}
12885
12886/// Systimestamp
12887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12888#[cfg_attr(feature = "bindings", derive(TS))]
12889pub struct Systimestamp {
12890    #[serde(default)]
12891    pub this: Option<Box<Expression>>,
12892}
12893
12894/// CurrentSchema
12895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12896#[cfg_attr(feature = "bindings", derive(TS))]
12897pub struct CurrentSchema {
12898    #[serde(default)]
12899    pub this: Option<Box<Expression>>,
12900}
12901
12902/// CurrentUser
12903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12904#[cfg_attr(feature = "bindings", derive(TS))]
12905pub struct CurrentUser {
12906    #[serde(default)]
12907    pub this: Option<Box<Expression>>,
12908}
12909
12910/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12912#[cfg_attr(feature = "bindings", derive(TS))]
12913pub struct SessionUser;
12914
12915/// JSONPathRoot - Represents $ in JSON path expressions
12916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12917#[cfg_attr(feature = "bindings", derive(TS))]
12918pub struct JSONPathRoot;
12919
12920/// UtcTime
12921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12922#[cfg_attr(feature = "bindings", derive(TS))]
12923pub struct UtcTime {
12924    #[serde(default)]
12925    pub this: Option<Box<Expression>>,
12926}
12927
12928/// UtcTimestamp
12929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12930#[cfg_attr(feature = "bindings", derive(TS))]
12931pub struct UtcTimestamp {
12932    #[serde(default)]
12933    pub this: Option<Box<Expression>>,
12934}
12935
12936/// TimestampFunc - TIMESTAMP constructor function
12937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12938#[cfg_attr(feature = "bindings", derive(TS))]
12939pub struct TimestampFunc {
12940    #[serde(default)]
12941    pub this: Option<Box<Expression>>,
12942    #[serde(default)]
12943    pub zone: Option<Box<Expression>>,
12944    #[serde(default)]
12945    pub with_tz: Option<bool>,
12946    #[serde(default)]
12947    pub safe: Option<bool>,
12948}
12949
12950/// DateBin
12951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12952#[cfg_attr(feature = "bindings", derive(TS))]
12953pub struct DateBin {
12954    pub this: Box<Expression>,
12955    pub expression: Box<Expression>,
12956    #[serde(default)]
12957    pub unit: Option<String>,
12958    #[serde(default)]
12959    pub zone: Option<Box<Expression>>,
12960    #[serde(default)]
12961    pub origin: Option<Box<Expression>>,
12962}
12963
12964/// Datetime
12965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12966#[cfg_attr(feature = "bindings", derive(TS))]
12967pub struct Datetime {
12968    pub this: Box<Expression>,
12969    #[serde(default)]
12970    pub expression: Option<Box<Expression>>,
12971}
12972
12973/// DatetimeAdd
12974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12975#[cfg_attr(feature = "bindings", derive(TS))]
12976pub struct DatetimeAdd {
12977    pub this: Box<Expression>,
12978    pub expression: Box<Expression>,
12979    #[serde(default)]
12980    pub unit: Option<String>,
12981}
12982
12983/// DatetimeSub
12984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12985#[cfg_attr(feature = "bindings", derive(TS))]
12986pub struct DatetimeSub {
12987    pub this: Box<Expression>,
12988    pub expression: Box<Expression>,
12989    #[serde(default)]
12990    pub unit: Option<String>,
12991}
12992
12993/// DatetimeDiff
12994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12995#[cfg_attr(feature = "bindings", derive(TS))]
12996pub struct DatetimeDiff {
12997    pub this: Box<Expression>,
12998    pub expression: Box<Expression>,
12999    #[serde(default)]
13000    pub unit: Option<String>,
13001}
13002
13003/// DatetimeTrunc
13004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13005#[cfg_attr(feature = "bindings", derive(TS))]
13006pub struct DatetimeTrunc {
13007    pub this: Box<Expression>,
13008    pub unit: String,
13009    #[serde(default)]
13010    pub zone: Option<Box<Expression>>,
13011}
13012
13013/// Dayname
13014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13015#[cfg_attr(feature = "bindings", derive(TS))]
13016pub struct Dayname {
13017    pub this: Box<Expression>,
13018    #[serde(default)]
13019    pub abbreviated: Option<Box<Expression>>,
13020}
13021
13022/// MakeInterval
13023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13024#[cfg_attr(feature = "bindings", derive(TS))]
13025pub struct MakeInterval {
13026    #[serde(default)]
13027    pub year: Option<Box<Expression>>,
13028    #[serde(default)]
13029    pub month: Option<Box<Expression>>,
13030    #[serde(default)]
13031    pub week: Option<Box<Expression>>,
13032    #[serde(default)]
13033    pub day: Option<Box<Expression>>,
13034    #[serde(default)]
13035    pub hour: Option<Box<Expression>>,
13036    #[serde(default)]
13037    pub minute: Option<Box<Expression>>,
13038    #[serde(default)]
13039    pub second: Option<Box<Expression>>,
13040}
13041
13042/// PreviousDay
13043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13044#[cfg_attr(feature = "bindings", derive(TS))]
13045pub struct PreviousDay {
13046    pub this: Box<Expression>,
13047    pub expression: Box<Expression>,
13048}
13049
13050/// Elt
13051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13052#[cfg_attr(feature = "bindings", derive(TS))]
13053pub struct Elt {
13054    pub this: Box<Expression>,
13055    #[serde(default)]
13056    pub expressions: Vec<Expression>,
13057}
13058
13059/// TimestampAdd
13060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13061#[cfg_attr(feature = "bindings", derive(TS))]
13062pub struct TimestampAdd {
13063    pub this: Box<Expression>,
13064    pub expression: Box<Expression>,
13065    #[serde(default)]
13066    pub unit: Option<String>,
13067}
13068
13069/// TimestampSub
13070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13071#[cfg_attr(feature = "bindings", derive(TS))]
13072pub struct TimestampSub {
13073    pub this: Box<Expression>,
13074    pub expression: Box<Expression>,
13075    #[serde(default)]
13076    pub unit: Option<String>,
13077}
13078
13079/// TimestampDiff
13080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13081#[cfg_attr(feature = "bindings", derive(TS))]
13082pub struct TimestampDiff {
13083    pub this: Box<Expression>,
13084    pub expression: Box<Expression>,
13085    #[serde(default)]
13086    pub unit: Option<String>,
13087}
13088
13089/// TimeSlice
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct TimeSlice {
13093    pub this: Box<Expression>,
13094    pub expression: Box<Expression>,
13095    pub unit: String,
13096    #[serde(default)]
13097    pub kind: Option<String>,
13098}
13099
13100/// TimeAdd
13101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13102#[cfg_attr(feature = "bindings", derive(TS))]
13103pub struct TimeAdd {
13104    pub this: Box<Expression>,
13105    pub expression: Box<Expression>,
13106    #[serde(default)]
13107    pub unit: Option<String>,
13108}
13109
13110/// TimeSub
13111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13112#[cfg_attr(feature = "bindings", derive(TS))]
13113pub struct TimeSub {
13114    pub this: Box<Expression>,
13115    pub expression: Box<Expression>,
13116    #[serde(default)]
13117    pub unit: Option<String>,
13118}
13119
13120/// TimeDiff
13121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13122#[cfg_attr(feature = "bindings", derive(TS))]
13123pub struct TimeDiff {
13124    pub this: Box<Expression>,
13125    pub expression: Box<Expression>,
13126    #[serde(default)]
13127    pub unit: Option<String>,
13128}
13129
13130/// TimeTrunc
13131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13132#[cfg_attr(feature = "bindings", derive(TS))]
13133pub struct TimeTrunc {
13134    pub this: Box<Expression>,
13135    pub unit: String,
13136    #[serde(default)]
13137    pub zone: Option<Box<Expression>>,
13138}
13139
13140/// DateFromParts
13141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13142#[cfg_attr(feature = "bindings", derive(TS))]
13143pub struct DateFromParts {
13144    #[serde(default)]
13145    pub year: Option<Box<Expression>>,
13146    #[serde(default)]
13147    pub month: Option<Box<Expression>>,
13148    #[serde(default)]
13149    pub day: Option<Box<Expression>>,
13150    #[serde(default)]
13151    pub allow_overflow: Option<Box<Expression>>,
13152}
13153
13154/// TimeFromParts
13155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13156#[cfg_attr(feature = "bindings", derive(TS))]
13157pub struct TimeFromParts {
13158    #[serde(default)]
13159    pub hour: Option<Box<Expression>>,
13160    #[serde(default)]
13161    pub min: Option<Box<Expression>>,
13162    #[serde(default)]
13163    pub sec: Option<Box<Expression>>,
13164    #[serde(default)]
13165    pub nano: Option<Box<Expression>>,
13166    #[serde(default)]
13167    pub fractions: Option<Box<Expression>>,
13168    #[serde(default)]
13169    pub precision: Option<i64>,
13170}
13171
13172/// DecodeCase
13173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13174#[cfg_attr(feature = "bindings", derive(TS))]
13175pub struct DecodeCase {
13176    #[serde(default)]
13177    pub expressions: Vec<Expression>,
13178}
13179
13180/// Decrypt
13181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13182#[cfg_attr(feature = "bindings", derive(TS))]
13183pub struct Decrypt {
13184    pub this: Box<Expression>,
13185    #[serde(default)]
13186    pub passphrase: Option<Box<Expression>>,
13187    #[serde(default)]
13188    pub aad: Option<Box<Expression>>,
13189    #[serde(default)]
13190    pub encryption_method: Option<Box<Expression>>,
13191    #[serde(default)]
13192    pub safe: Option<Box<Expression>>,
13193}
13194
13195/// DecryptRaw
13196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13197#[cfg_attr(feature = "bindings", derive(TS))]
13198pub struct DecryptRaw {
13199    pub this: Box<Expression>,
13200    #[serde(default)]
13201    pub key: Option<Box<Expression>>,
13202    #[serde(default)]
13203    pub iv: Option<Box<Expression>>,
13204    #[serde(default)]
13205    pub aad: Option<Box<Expression>>,
13206    #[serde(default)]
13207    pub encryption_method: Option<Box<Expression>>,
13208    #[serde(default)]
13209    pub aead: Option<Box<Expression>>,
13210    #[serde(default)]
13211    pub safe: Option<Box<Expression>>,
13212}
13213
13214/// Encode
13215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13216#[cfg_attr(feature = "bindings", derive(TS))]
13217pub struct Encode {
13218    pub this: Box<Expression>,
13219    #[serde(default)]
13220    pub charset: Option<Box<Expression>>,
13221}
13222
13223/// Encrypt
13224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13225#[cfg_attr(feature = "bindings", derive(TS))]
13226pub struct Encrypt {
13227    pub this: Box<Expression>,
13228    #[serde(default)]
13229    pub passphrase: Option<Box<Expression>>,
13230    #[serde(default)]
13231    pub aad: Option<Box<Expression>>,
13232    #[serde(default)]
13233    pub encryption_method: Option<Box<Expression>>,
13234}
13235
13236/// EncryptRaw
13237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13238#[cfg_attr(feature = "bindings", derive(TS))]
13239pub struct EncryptRaw {
13240    pub this: Box<Expression>,
13241    #[serde(default)]
13242    pub key: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub iv: Option<Box<Expression>>,
13245    #[serde(default)]
13246    pub aad: Option<Box<Expression>>,
13247    #[serde(default)]
13248    pub encryption_method: Option<Box<Expression>>,
13249}
13250
13251/// EqualNull
13252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13253#[cfg_attr(feature = "bindings", derive(TS))]
13254pub struct EqualNull {
13255    pub this: Box<Expression>,
13256    pub expression: Box<Expression>,
13257}
13258
13259/// ToBinary
13260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13261#[cfg_attr(feature = "bindings", derive(TS))]
13262pub struct ToBinary {
13263    pub this: Box<Expression>,
13264    #[serde(default)]
13265    pub format: Option<String>,
13266    #[serde(default)]
13267    pub safe: Option<Box<Expression>>,
13268}
13269
13270/// Base64DecodeBinary
13271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13272#[cfg_attr(feature = "bindings", derive(TS))]
13273pub struct Base64DecodeBinary {
13274    pub this: Box<Expression>,
13275    #[serde(default)]
13276    pub alphabet: Option<Box<Expression>>,
13277}
13278
13279/// Base64DecodeString
13280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13281#[cfg_attr(feature = "bindings", derive(TS))]
13282pub struct Base64DecodeString {
13283    pub this: Box<Expression>,
13284    #[serde(default)]
13285    pub alphabet: Option<Box<Expression>>,
13286}
13287
13288/// Base64Encode
13289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13290#[cfg_attr(feature = "bindings", derive(TS))]
13291pub struct Base64Encode {
13292    pub this: Box<Expression>,
13293    #[serde(default)]
13294    pub max_line_length: Option<Box<Expression>>,
13295    #[serde(default)]
13296    pub alphabet: Option<Box<Expression>>,
13297}
13298
13299/// TryBase64DecodeBinary
13300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13301#[cfg_attr(feature = "bindings", derive(TS))]
13302pub struct TryBase64DecodeBinary {
13303    pub this: Box<Expression>,
13304    #[serde(default)]
13305    pub alphabet: Option<Box<Expression>>,
13306}
13307
13308/// TryBase64DecodeString
13309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13310#[cfg_attr(feature = "bindings", derive(TS))]
13311pub struct TryBase64DecodeString {
13312    pub this: Box<Expression>,
13313    #[serde(default)]
13314    pub alphabet: Option<Box<Expression>>,
13315}
13316
13317/// GapFill
13318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13319#[cfg_attr(feature = "bindings", derive(TS))]
13320pub struct GapFill {
13321    pub this: Box<Expression>,
13322    #[serde(default)]
13323    pub ts_column: Option<Box<Expression>>,
13324    #[serde(default)]
13325    pub bucket_width: Option<Box<Expression>>,
13326    #[serde(default)]
13327    pub partitioning_columns: Option<Box<Expression>>,
13328    #[serde(default)]
13329    pub value_columns: Option<Box<Expression>>,
13330    #[serde(default)]
13331    pub origin: Option<Box<Expression>>,
13332    #[serde(default)]
13333    pub ignore_nulls: Option<Box<Expression>>,
13334}
13335
13336/// GenerateDateArray
13337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13338#[cfg_attr(feature = "bindings", derive(TS))]
13339pub struct GenerateDateArray {
13340    #[serde(default)]
13341    pub start: Option<Box<Expression>>,
13342    #[serde(default)]
13343    pub end: Option<Box<Expression>>,
13344    #[serde(default)]
13345    pub step: Option<Box<Expression>>,
13346}
13347
13348/// GenerateTimestampArray
13349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13350#[cfg_attr(feature = "bindings", derive(TS))]
13351pub struct GenerateTimestampArray {
13352    #[serde(default)]
13353    pub start: Option<Box<Expression>>,
13354    #[serde(default)]
13355    pub end: Option<Box<Expression>>,
13356    #[serde(default)]
13357    pub step: Option<Box<Expression>>,
13358}
13359
13360/// GetExtract
13361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13362#[cfg_attr(feature = "bindings", derive(TS))]
13363pub struct GetExtract {
13364    pub this: Box<Expression>,
13365    pub expression: Box<Expression>,
13366}
13367
13368/// Getbit
13369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13370#[cfg_attr(feature = "bindings", derive(TS))]
13371pub struct Getbit {
13372    pub this: Box<Expression>,
13373    pub expression: Box<Expression>,
13374    #[serde(default)]
13375    pub zero_is_msb: Option<Box<Expression>>,
13376}
13377
13378/// OverflowTruncateBehavior
13379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13380#[cfg_attr(feature = "bindings", derive(TS))]
13381pub struct OverflowTruncateBehavior {
13382    #[serde(default)]
13383    pub this: Option<Box<Expression>>,
13384    #[serde(default)]
13385    pub with_count: Option<Box<Expression>>,
13386}
13387
13388/// HexEncode
13389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13390#[cfg_attr(feature = "bindings", derive(TS))]
13391pub struct HexEncode {
13392    pub this: Box<Expression>,
13393    #[serde(default)]
13394    pub case: Option<Box<Expression>>,
13395}
13396
13397/// Compress
13398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13399#[cfg_attr(feature = "bindings", derive(TS))]
13400pub struct Compress {
13401    pub this: Box<Expression>,
13402    #[serde(default)]
13403    pub method: Option<String>,
13404}
13405
13406/// DecompressBinary
13407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13408#[cfg_attr(feature = "bindings", derive(TS))]
13409pub struct DecompressBinary {
13410    pub this: Box<Expression>,
13411    pub method: String,
13412}
13413
13414/// DecompressString
13415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13416#[cfg_attr(feature = "bindings", derive(TS))]
13417pub struct DecompressString {
13418    pub this: Box<Expression>,
13419    pub method: String,
13420}
13421
13422/// Xor
13423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13424#[cfg_attr(feature = "bindings", derive(TS))]
13425pub struct Xor {
13426    #[serde(default)]
13427    pub this: Option<Box<Expression>>,
13428    #[serde(default)]
13429    pub expression: Option<Box<Expression>>,
13430    #[serde(default)]
13431    pub expressions: Vec<Expression>,
13432}
13433
13434/// Nullif
13435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13436#[cfg_attr(feature = "bindings", derive(TS))]
13437pub struct Nullif {
13438    pub this: Box<Expression>,
13439    pub expression: Box<Expression>,
13440}
13441
13442/// JSON
13443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13444#[cfg_attr(feature = "bindings", derive(TS))]
13445pub struct JSON {
13446    #[serde(default)]
13447    pub this: Option<Box<Expression>>,
13448    #[serde(default)]
13449    pub with_: Option<Box<Expression>>,
13450    #[serde(default)]
13451    pub unique: bool,
13452}
13453
13454/// JSONPath
13455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13456#[cfg_attr(feature = "bindings", derive(TS))]
13457pub struct JSONPath {
13458    #[serde(default)]
13459    pub expressions: Vec<Expression>,
13460    #[serde(default)]
13461    pub escape: Option<Box<Expression>>,
13462}
13463
13464/// JSONPathFilter
13465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13466#[cfg_attr(feature = "bindings", derive(TS))]
13467pub struct JSONPathFilter {
13468    pub this: Box<Expression>,
13469}
13470
13471/// JSONPathKey
13472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13473#[cfg_attr(feature = "bindings", derive(TS))]
13474pub struct JSONPathKey {
13475    pub this: Box<Expression>,
13476}
13477
13478/// JSONPathRecursive
13479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13480#[cfg_attr(feature = "bindings", derive(TS))]
13481pub struct JSONPathRecursive {
13482    #[serde(default)]
13483    pub this: Option<Box<Expression>>,
13484}
13485
13486/// JSONPathScript
13487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13488#[cfg_attr(feature = "bindings", derive(TS))]
13489pub struct JSONPathScript {
13490    pub this: Box<Expression>,
13491}
13492
13493/// JSONPathSlice
13494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13495#[cfg_attr(feature = "bindings", derive(TS))]
13496pub struct JSONPathSlice {
13497    #[serde(default)]
13498    pub start: Option<Box<Expression>>,
13499    #[serde(default)]
13500    pub end: Option<Box<Expression>>,
13501    #[serde(default)]
13502    pub step: Option<Box<Expression>>,
13503}
13504
13505/// JSONPathSelector
13506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13507#[cfg_attr(feature = "bindings", derive(TS))]
13508pub struct JSONPathSelector {
13509    pub this: Box<Expression>,
13510}
13511
13512/// JSONPathSubscript
13513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13514#[cfg_attr(feature = "bindings", derive(TS))]
13515pub struct JSONPathSubscript {
13516    pub this: Box<Expression>,
13517}
13518
13519/// JSONPathUnion
13520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13521#[cfg_attr(feature = "bindings", derive(TS))]
13522pub struct JSONPathUnion {
13523    #[serde(default)]
13524    pub expressions: Vec<Expression>,
13525}
13526
13527/// Format
13528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13529#[cfg_attr(feature = "bindings", derive(TS))]
13530pub struct Format {
13531    pub this: Box<Expression>,
13532    #[serde(default)]
13533    pub expressions: Vec<Expression>,
13534}
13535
13536/// JSONKeys
13537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13538#[cfg_attr(feature = "bindings", derive(TS))]
13539pub struct JSONKeys {
13540    pub this: Box<Expression>,
13541    #[serde(default)]
13542    pub expression: Option<Box<Expression>>,
13543    #[serde(default)]
13544    pub expressions: Vec<Expression>,
13545}
13546
13547/// JSONKeyValue
13548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13549#[cfg_attr(feature = "bindings", derive(TS))]
13550pub struct JSONKeyValue {
13551    pub this: Box<Expression>,
13552    pub expression: Box<Expression>,
13553}
13554
13555/// JSONKeysAtDepth
13556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13557#[cfg_attr(feature = "bindings", derive(TS))]
13558pub struct JSONKeysAtDepth {
13559    pub this: Box<Expression>,
13560    #[serde(default)]
13561    pub expression: Option<Box<Expression>>,
13562    #[serde(default)]
13563    pub mode: Option<Box<Expression>>,
13564}
13565
13566/// JSONObject
13567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13568#[cfg_attr(feature = "bindings", derive(TS))]
13569pub struct JSONObject {
13570    #[serde(default)]
13571    pub expressions: Vec<Expression>,
13572    #[serde(default)]
13573    pub null_handling: Option<Box<Expression>>,
13574    #[serde(default)]
13575    pub unique_keys: Option<Box<Expression>>,
13576    #[serde(default)]
13577    pub return_type: Option<Box<Expression>>,
13578    #[serde(default)]
13579    pub encoding: Option<Box<Expression>>,
13580}
13581
13582/// JSONObjectAgg
13583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13584#[cfg_attr(feature = "bindings", derive(TS))]
13585pub struct JSONObjectAgg {
13586    #[serde(default)]
13587    pub expressions: Vec<Expression>,
13588    #[serde(default)]
13589    pub null_handling: Option<Box<Expression>>,
13590    #[serde(default)]
13591    pub unique_keys: Option<Box<Expression>>,
13592    #[serde(default)]
13593    pub return_type: Option<Box<Expression>>,
13594    #[serde(default)]
13595    pub encoding: Option<Box<Expression>>,
13596}
13597
13598/// JSONBObjectAgg
13599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13600#[cfg_attr(feature = "bindings", derive(TS))]
13601pub struct JSONBObjectAgg {
13602    pub this: Box<Expression>,
13603    pub expression: Box<Expression>,
13604}
13605
13606/// JSONArray
13607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13608#[cfg_attr(feature = "bindings", derive(TS))]
13609pub struct JSONArray {
13610    #[serde(default)]
13611    pub expressions: Vec<Expression>,
13612    #[serde(default)]
13613    pub null_handling: Option<Box<Expression>>,
13614    #[serde(default)]
13615    pub return_type: Option<Box<Expression>>,
13616    #[serde(default)]
13617    pub strict: Option<Box<Expression>>,
13618}
13619
13620/// JSONArrayAgg
13621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13622#[cfg_attr(feature = "bindings", derive(TS))]
13623pub struct JSONArrayAgg {
13624    pub this: Box<Expression>,
13625    #[serde(default)]
13626    pub order: Option<Box<Expression>>,
13627    #[serde(default)]
13628    pub null_handling: Option<Box<Expression>>,
13629    #[serde(default)]
13630    pub return_type: Option<Box<Expression>>,
13631    #[serde(default)]
13632    pub strict: Option<Box<Expression>>,
13633}
13634
13635/// JSONExists
13636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13637#[cfg_attr(feature = "bindings", derive(TS))]
13638pub struct JSONExists {
13639    pub this: Box<Expression>,
13640    #[serde(default)]
13641    pub path: Option<Box<Expression>>,
13642    #[serde(default)]
13643    pub passing: Option<Box<Expression>>,
13644    #[serde(default)]
13645    pub on_condition: Option<Box<Expression>>,
13646    #[serde(default)]
13647    pub from_dcolonqmark: Option<Box<Expression>>,
13648}
13649
13650/// JSONColumnDef
13651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13652#[cfg_attr(feature = "bindings", derive(TS))]
13653pub struct JSONColumnDef {
13654    #[serde(default)]
13655    pub this: Option<Box<Expression>>,
13656    #[serde(default)]
13657    pub kind: Option<String>,
13658    #[serde(default)]
13659    pub format_json: bool,
13660    #[serde(default)]
13661    pub path: Option<Box<Expression>>,
13662    #[serde(default)]
13663    pub nested_schema: Option<Box<Expression>>,
13664    #[serde(default)]
13665    pub ordinality: Option<Box<Expression>>,
13666}
13667
13668/// JSONSchema
13669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13670#[cfg_attr(feature = "bindings", derive(TS))]
13671pub struct JSONSchema {
13672    #[serde(default)]
13673    pub expressions: Vec<Expression>,
13674}
13675
13676/// JSONSet
13677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13678#[cfg_attr(feature = "bindings", derive(TS))]
13679pub struct JSONSet {
13680    pub this: Box<Expression>,
13681    #[serde(default)]
13682    pub expressions: Vec<Expression>,
13683}
13684
13685/// JSONStripNulls
13686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13687#[cfg_attr(feature = "bindings", derive(TS))]
13688pub struct JSONStripNulls {
13689    pub this: Box<Expression>,
13690    #[serde(default)]
13691    pub expression: Option<Box<Expression>>,
13692    #[serde(default)]
13693    pub include_arrays: Option<Box<Expression>>,
13694    #[serde(default)]
13695    pub remove_empty: Option<Box<Expression>>,
13696}
13697
13698/// JSONValue
13699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13700#[cfg_attr(feature = "bindings", derive(TS))]
13701pub struct JSONValue {
13702    pub this: Box<Expression>,
13703    #[serde(default)]
13704    pub path: Option<Box<Expression>>,
13705    #[serde(default)]
13706    pub returning: Option<Box<Expression>>,
13707    #[serde(default)]
13708    pub on_condition: Option<Box<Expression>>,
13709}
13710
13711/// JSONValueArray
13712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13713#[cfg_attr(feature = "bindings", derive(TS))]
13714pub struct JSONValueArray {
13715    pub this: Box<Expression>,
13716    #[serde(default)]
13717    pub expression: Option<Box<Expression>>,
13718}
13719
13720/// JSONRemove
13721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13722#[cfg_attr(feature = "bindings", derive(TS))]
13723pub struct JSONRemove {
13724    pub this: Box<Expression>,
13725    #[serde(default)]
13726    pub expressions: Vec<Expression>,
13727}
13728
13729/// JSONTable
13730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13731#[cfg_attr(feature = "bindings", derive(TS))]
13732pub struct JSONTable {
13733    pub this: Box<Expression>,
13734    #[serde(default)]
13735    pub schema: Option<Box<Expression>>,
13736    #[serde(default)]
13737    pub path: Option<Box<Expression>>,
13738    #[serde(default)]
13739    pub error_handling: Option<Box<Expression>>,
13740    #[serde(default)]
13741    pub empty_handling: Option<Box<Expression>>,
13742}
13743
13744/// JSONType
13745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13746#[cfg_attr(feature = "bindings", derive(TS))]
13747pub struct JSONType {
13748    pub this: Box<Expression>,
13749    #[serde(default)]
13750    pub expression: Option<Box<Expression>>,
13751}
13752
13753/// ObjectInsert
13754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13755#[cfg_attr(feature = "bindings", derive(TS))]
13756pub struct ObjectInsert {
13757    pub this: Box<Expression>,
13758    #[serde(default)]
13759    pub key: Option<Box<Expression>>,
13760    #[serde(default)]
13761    pub value: Option<Box<Expression>>,
13762    #[serde(default)]
13763    pub update_flag: Option<Box<Expression>>,
13764}
13765
13766/// OpenJSONColumnDef
13767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13768#[cfg_attr(feature = "bindings", derive(TS))]
13769pub struct OpenJSONColumnDef {
13770    pub this: Box<Expression>,
13771    pub kind: String,
13772    #[serde(default)]
13773    pub path: Option<Box<Expression>>,
13774    #[serde(default)]
13775    pub as_json: Option<Box<Expression>>,
13776    /// The parsed data type for proper generation
13777    #[serde(default, skip_serializing_if = "Option::is_none")]
13778    pub data_type: Option<DataType>,
13779}
13780
13781/// OpenJSON
13782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13783#[cfg_attr(feature = "bindings", derive(TS))]
13784pub struct OpenJSON {
13785    pub this: Box<Expression>,
13786    #[serde(default)]
13787    pub path: Option<Box<Expression>>,
13788    #[serde(default)]
13789    pub expressions: Vec<Expression>,
13790}
13791
13792/// JSONBExists
13793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13794#[cfg_attr(feature = "bindings", derive(TS))]
13795pub struct JSONBExists {
13796    pub this: Box<Expression>,
13797    #[serde(default)]
13798    pub path: Option<Box<Expression>>,
13799}
13800
13801/// JSONCast
13802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13803#[cfg_attr(feature = "bindings", derive(TS))]
13804pub struct JSONCast {
13805    pub this: Box<Expression>,
13806    pub to: DataType,
13807}
13808
13809/// JSONExtract
13810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13811#[cfg_attr(feature = "bindings", derive(TS))]
13812pub struct JSONExtract {
13813    pub this: Box<Expression>,
13814    pub expression: Box<Expression>,
13815    #[serde(default)]
13816    pub only_json_types: Option<Box<Expression>>,
13817    #[serde(default)]
13818    pub expressions: Vec<Expression>,
13819    #[serde(default)]
13820    pub variant_extract: Option<Box<Expression>>,
13821    #[serde(default)]
13822    pub json_query: Option<Box<Expression>>,
13823    #[serde(default)]
13824    pub option: Option<Box<Expression>>,
13825    #[serde(default)]
13826    pub quote: Option<Box<Expression>>,
13827    #[serde(default)]
13828    pub on_condition: Option<Box<Expression>>,
13829    #[serde(default)]
13830    pub requires_json: Option<Box<Expression>>,
13831}
13832
13833/// JSONExtractQuote
13834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13835#[cfg_attr(feature = "bindings", derive(TS))]
13836pub struct JSONExtractQuote {
13837    #[serde(default)]
13838    pub option: Option<Box<Expression>>,
13839    #[serde(default)]
13840    pub scalar: Option<Box<Expression>>,
13841}
13842
13843/// JSONExtractArray
13844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13845#[cfg_attr(feature = "bindings", derive(TS))]
13846pub struct JSONExtractArray {
13847    pub this: Box<Expression>,
13848    #[serde(default)]
13849    pub expression: Option<Box<Expression>>,
13850}
13851
13852/// JSONExtractScalar
13853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13854#[cfg_attr(feature = "bindings", derive(TS))]
13855pub struct JSONExtractScalar {
13856    pub this: Box<Expression>,
13857    pub expression: Box<Expression>,
13858    #[serde(default)]
13859    pub only_json_types: Option<Box<Expression>>,
13860    #[serde(default)]
13861    pub expressions: Vec<Expression>,
13862    #[serde(default)]
13863    pub json_type: Option<Box<Expression>>,
13864    #[serde(default)]
13865    pub scalar_only: Option<Box<Expression>>,
13866}
13867
13868/// JSONBExtractScalar
13869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13870#[cfg_attr(feature = "bindings", derive(TS))]
13871pub struct JSONBExtractScalar {
13872    pub this: Box<Expression>,
13873    pub expression: Box<Expression>,
13874    #[serde(default)]
13875    pub json_type: Option<Box<Expression>>,
13876}
13877
13878/// JSONFormat
13879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13880#[cfg_attr(feature = "bindings", derive(TS))]
13881pub struct JSONFormat {
13882    #[serde(default)]
13883    pub this: Option<Box<Expression>>,
13884    #[serde(default)]
13885    pub options: Vec<Expression>,
13886    #[serde(default)]
13887    pub is_json: Option<Box<Expression>>,
13888    #[serde(default)]
13889    pub to_json: Option<Box<Expression>>,
13890}
13891
13892/// JSONArrayAppend
13893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13894#[cfg_attr(feature = "bindings", derive(TS))]
13895pub struct JSONArrayAppend {
13896    pub this: Box<Expression>,
13897    #[serde(default)]
13898    pub expressions: Vec<Expression>,
13899}
13900
13901/// JSONArrayContains
13902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13903#[cfg_attr(feature = "bindings", derive(TS))]
13904pub struct JSONArrayContains {
13905    pub this: Box<Expression>,
13906    pub expression: Box<Expression>,
13907    #[serde(default)]
13908    pub json_type: Option<Box<Expression>>,
13909}
13910
13911/// JSONArrayInsert
13912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13913#[cfg_attr(feature = "bindings", derive(TS))]
13914pub struct JSONArrayInsert {
13915    pub this: Box<Expression>,
13916    #[serde(default)]
13917    pub expressions: Vec<Expression>,
13918}
13919
13920/// ParseJSON
13921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13922#[cfg_attr(feature = "bindings", derive(TS))]
13923pub struct ParseJSON {
13924    pub this: Box<Expression>,
13925    #[serde(default)]
13926    pub expression: Option<Box<Expression>>,
13927    #[serde(default)]
13928    pub safe: Option<Box<Expression>>,
13929}
13930
13931/// ParseUrl
13932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13933#[cfg_attr(feature = "bindings", derive(TS))]
13934pub struct ParseUrl {
13935    pub this: Box<Expression>,
13936    #[serde(default)]
13937    pub part_to_extract: Option<Box<Expression>>,
13938    #[serde(default)]
13939    pub key: Option<Box<Expression>>,
13940    #[serde(default)]
13941    pub permissive: Option<Box<Expression>>,
13942}
13943
13944/// ParseIp
13945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13946#[cfg_attr(feature = "bindings", derive(TS))]
13947pub struct ParseIp {
13948    pub this: Box<Expression>,
13949    #[serde(default)]
13950    pub type_: Option<Box<Expression>>,
13951    #[serde(default)]
13952    pub permissive: Option<Box<Expression>>,
13953}
13954
13955/// ParseTime
13956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13957#[cfg_attr(feature = "bindings", derive(TS))]
13958pub struct ParseTime {
13959    pub this: Box<Expression>,
13960    pub format: String,
13961}
13962
13963/// ParseDatetime
13964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13965#[cfg_attr(feature = "bindings", derive(TS))]
13966pub struct ParseDatetime {
13967    pub this: Box<Expression>,
13968    #[serde(default)]
13969    pub format: Option<String>,
13970    #[serde(default)]
13971    pub zone: Option<Box<Expression>>,
13972}
13973
13974/// Map
13975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13976#[cfg_attr(feature = "bindings", derive(TS))]
13977pub struct Map {
13978    #[serde(default)]
13979    pub keys: Vec<Expression>,
13980    #[serde(default)]
13981    pub values: Vec<Expression>,
13982}
13983
13984/// MapCat
13985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13986#[cfg_attr(feature = "bindings", derive(TS))]
13987pub struct MapCat {
13988    pub this: Box<Expression>,
13989    pub expression: Box<Expression>,
13990}
13991
13992/// MapDelete
13993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13994#[cfg_attr(feature = "bindings", derive(TS))]
13995pub struct MapDelete {
13996    pub this: Box<Expression>,
13997    #[serde(default)]
13998    pub expressions: Vec<Expression>,
13999}
14000
14001/// MapInsert
14002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14003#[cfg_attr(feature = "bindings", derive(TS))]
14004pub struct MapInsert {
14005    pub this: Box<Expression>,
14006    #[serde(default)]
14007    pub key: Option<Box<Expression>>,
14008    #[serde(default)]
14009    pub value: Option<Box<Expression>>,
14010    #[serde(default)]
14011    pub update_flag: Option<Box<Expression>>,
14012}
14013
14014/// MapPick
14015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14016#[cfg_attr(feature = "bindings", derive(TS))]
14017pub struct MapPick {
14018    pub this: Box<Expression>,
14019    #[serde(default)]
14020    pub expressions: Vec<Expression>,
14021}
14022
14023/// ScopeResolution
14024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14025#[cfg_attr(feature = "bindings", derive(TS))]
14026pub struct ScopeResolution {
14027    #[serde(default)]
14028    pub this: Option<Box<Expression>>,
14029    pub expression: Box<Expression>,
14030}
14031
14032/// Slice
14033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14034#[cfg_attr(feature = "bindings", derive(TS))]
14035pub struct Slice {
14036    #[serde(default)]
14037    pub this: Option<Box<Expression>>,
14038    #[serde(default)]
14039    pub expression: Option<Box<Expression>>,
14040    #[serde(default)]
14041    pub step: Option<Box<Expression>>,
14042}
14043
14044/// VarMap
14045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14046#[cfg_attr(feature = "bindings", derive(TS))]
14047pub struct VarMap {
14048    #[serde(default)]
14049    pub keys: Vec<Expression>,
14050    #[serde(default)]
14051    pub values: Vec<Expression>,
14052}
14053
14054/// MatchAgainst
14055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14056#[cfg_attr(feature = "bindings", derive(TS))]
14057pub struct MatchAgainst {
14058    pub this: Box<Expression>,
14059    #[serde(default)]
14060    pub expressions: Vec<Expression>,
14061    #[serde(default)]
14062    pub modifier: Option<Box<Expression>>,
14063}
14064
14065/// MD5Digest
14066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14067#[cfg_attr(feature = "bindings", derive(TS))]
14068pub struct MD5Digest {
14069    pub this: Box<Expression>,
14070    #[serde(default)]
14071    pub expressions: Vec<Expression>,
14072}
14073
14074/// Monthname
14075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14076#[cfg_attr(feature = "bindings", derive(TS))]
14077pub struct Monthname {
14078    pub this: Box<Expression>,
14079    #[serde(default)]
14080    pub abbreviated: Option<Box<Expression>>,
14081}
14082
14083/// Ntile
14084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14085#[cfg_attr(feature = "bindings", derive(TS))]
14086pub struct Ntile {
14087    #[serde(default)]
14088    pub this: Option<Box<Expression>>,
14089}
14090
14091/// Normalize
14092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14093#[cfg_attr(feature = "bindings", derive(TS))]
14094pub struct Normalize {
14095    pub this: Box<Expression>,
14096    #[serde(default)]
14097    pub form: Option<Box<Expression>>,
14098    #[serde(default)]
14099    pub is_casefold: Option<Box<Expression>>,
14100}
14101
14102/// Normal
14103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14104#[cfg_attr(feature = "bindings", derive(TS))]
14105pub struct Normal {
14106    pub this: Box<Expression>,
14107    #[serde(default)]
14108    pub stddev: Option<Box<Expression>>,
14109    #[serde(default)]
14110    pub gen: Option<Box<Expression>>,
14111}
14112
14113/// Predict
14114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14115#[cfg_attr(feature = "bindings", derive(TS))]
14116pub struct Predict {
14117    pub this: Box<Expression>,
14118    pub expression: Box<Expression>,
14119    #[serde(default)]
14120    pub params_struct: Option<Box<Expression>>,
14121}
14122
14123/// MLTranslate
14124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14125#[cfg_attr(feature = "bindings", derive(TS))]
14126pub struct MLTranslate {
14127    pub this: Box<Expression>,
14128    pub expression: Box<Expression>,
14129    #[serde(default)]
14130    pub params_struct: Option<Box<Expression>>,
14131}
14132
14133/// FeaturesAtTime
14134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14135#[cfg_attr(feature = "bindings", derive(TS))]
14136pub struct FeaturesAtTime {
14137    pub this: Box<Expression>,
14138    #[serde(default)]
14139    pub time: Option<Box<Expression>>,
14140    #[serde(default)]
14141    pub num_rows: Option<Box<Expression>>,
14142    #[serde(default)]
14143    pub ignore_feature_nulls: Option<Box<Expression>>,
14144}
14145
14146/// GenerateEmbedding
14147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14148#[cfg_attr(feature = "bindings", derive(TS))]
14149pub struct GenerateEmbedding {
14150    pub this: Box<Expression>,
14151    pub expression: Box<Expression>,
14152    #[serde(default)]
14153    pub params_struct: Option<Box<Expression>>,
14154    #[serde(default)]
14155    pub is_text: Option<Box<Expression>>,
14156}
14157
14158/// MLForecast
14159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14160#[cfg_attr(feature = "bindings", derive(TS))]
14161pub struct MLForecast {
14162    pub this: Box<Expression>,
14163    #[serde(default)]
14164    pub expression: Option<Box<Expression>>,
14165    #[serde(default)]
14166    pub params_struct: Option<Box<Expression>>,
14167}
14168
14169/// ModelAttribute
14170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14171#[cfg_attr(feature = "bindings", derive(TS))]
14172pub struct ModelAttribute {
14173    pub this: Box<Expression>,
14174    pub expression: Box<Expression>,
14175}
14176
14177/// VectorSearch
14178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14179#[cfg_attr(feature = "bindings", derive(TS))]
14180pub struct VectorSearch {
14181    pub this: Box<Expression>,
14182    #[serde(default)]
14183    pub column_to_search: Option<Box<Expression>>,
14184    #[serde(default)]
14185    pub query_table: Option<Box<Expression>>,
14186    #[serde(default)]
14187    pub query_column_to_search: Option<Box<Expression>>,
14188    #[serde(default)]
14189    pub top_k: Option<Box<Expression>>,
14190    #[serde(default)]
14191    pub distance_type: Option<Box<Expression>>,
14192    #[serde(default)]
14193    pub options: Vec<Expression>,
14194}
14195
14196/// Quantile
14197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14198#[cfg_attr(feature = "bindings", derive(TS))]
14199pub struct Quantile {
14200    pub this: Box<Expression>,
14201    #[serde(default)]
14202    pub quantile: Option<Box<Expression>>,
14203}
14204
14205/// ApproxQuantile
14206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14207#[cfg_attr(feature = "bindings", derive(TS))]
14208pub struct ApproxQuantile {
14209    pub this: Box<Expression>,
14210    #[serde(default)]
14211    pub quantile: Option<Box<Expression>>,
14212    #[serde(default)]
14213    pub accuracy: Option<Box<Expression>>,
14214    #[serde(default)]
14215    pub weight: Option<Box<Expression>>,
14216    #[serde(default)]
14217    pub error_tolerance: Option<Box<Expression>>,
14218}
14219
14220/// ApproxPercentileEstimate
14221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14222#[cfg_attr(feature = "bindings", derive(TS))]
14223pub struct ApproxPercentileEstimate {
14224    pub this: Box<Expression>,
14225    #[serde(default)]
14226    pub percentile: Option<Box<Expression>>,
14227}
14228
14229/// Randn
14230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14231#[cfg_attr(feature = "bindings", derive(TS))]
14232pub struct Randn {
14233    #[serde(default)]
14234    pub this: Option<Box<Expression>>,
14235}
14236
14237/// Randstr
14238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14239#[cfg_attr(feature = "bindings", derive(TS))]
14240pub struct Randstr {
14241    pub this: Box<Expression>,
14242    #[serde(default)]
14243    pub generator: Option<Box<Expression>>,
14244}
14245
14246/// RangeN
14247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14248#[cfg_attr(feature = "bindings", derive(TS))]
14249pub struct RangeN {
14250    pub this: Box<Expression>,
14251    #[serde(default)]
14252    pub expressions: Vec<Expression>,
14253    #[serde(default)]
14254    pub each: Option<Box<Expression>>,
14255}
14256
14257/// RangeBucket
14258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14259#[cfg_attr(feature = "bindings", derive(TS))]
14260pub struct RangeBucket {
14261    pub this: Box<Expression>,
14262    pub expression: Box<Expression>,
14263}
14264
14265/// ReadCSV
14266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14267#[cfg_attr(feature = "bindings", derive(TS))]
14268pub struct ReadCSV {
14269    pub this: Box<Expression>,
14270    #[serde(default)]
14271    pub expressions: Vec<Expression>,
14272}
14273
14274/// ReadParquet
14275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14276#[cfg_attr(feature = "bindings", derive(TS))]
14277pub struct ReadParquet {
14278    #[serde(default)]
14279    pub expressions: Vec<Expression>,
14280}
14281
14282/// Reduce
14283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14284#[cfg_attr(feature = "bindings", derive(TS))]
14285pub struct Reduce {
14286    pub this: Box<Expression>,
14287    #[serde(default)]
14288    pub initial: Option<Box<Expression>>,
14289    #[serde(default)]
14290    pub merge: Option<Box<Expression>>,
14291    #[serde(default)]
14292    pub finish: Option<Box<Expression>>,
14293}
14294
14295/// RegexpExtractAll
14296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14297#[cfg_attr(feature = "bindings", derive(TS))]
14298pub struct RegexpExtractAll {
14299    pub this: Box<Expression>,
14300    pub expression: Box<Expression>,
14301    #[serde(default)]
14302    pub group: Option<Box<Expression>>,
14303    #[serde(default)]
14304    pub parameters: Option<Box<Expression>>,
14305    #[serde(default)]
14306    pub position: Option<Box<Expression>>,
14307    #[serde(default)]
14308    pub occurrence: Option<Box<Expression>>,
14309}
14310
14311/// RegexpILike
14312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14313#[cfg_attr(feature = "bindings", derive(TS))]
14314pub struct RegexpILike {
14315    pub this: Box<Expression>,
14316    pub expression: Box<Expression>,
14317    #[serde(default)]
14318    pub flag: Option<Box<Expression>>,
14319}
14320
14321/// RegexpFullMatch
14322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14323#[cfg_attr(feature = "bindings", derive(TS))]
14324pub struct RegexpFullMatch {
14325    pub this: Box<Expression>,
14326    pub expression: Box<Expression>,
14327    #[serde(default)]
14328    pub options: Vec<Expression>,
14329}
14330
14331/// RegexpInstr
14332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14333#[cfg_attr(feature = "bindings", derive(TS))]
14334pub struct RegexpInstr {
14335    pub this: Box<Expression>,
14336    pub expression: Box<Expression>,
14337    #[serde(default)]
14338    pub position: Option<Box<Expression>>,
14339    #[serde(default)]
14340    pub occurrence: Option<Box<Expression>>,
14341    #[serde(default)]
14342    pub option: Option<Box<Expression>>,
14343    #[serde(default)]
14344    pub parameters: Option<Box<Expression>>,
14345    #[serde(default)]
14346    pub group: Option<Box<Expression>>,
14347}
14348
14349/// RegexpSplit
14350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14351#[cfg_attr(feature = "bindings", derive(TS))]
14352pub struct RegexpSplit {
14353    pub this: Box<Expression>,
14354    pub expression: Box<Expression>,
14355    #[serde(default)]
14356    pub limit: Option<Box<Expression>>,
14357}
14358
14359/// RegexpCount
14360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14361#[cfg_attr(feature = "bindings", derive(TS))]
14362pub struct RegexpCount {
14363    pub this: Box<Expression>,
14364    pub expression: Box<Expression>,
14365    #[serde(default)]
14366    pub position: Option<Box<Expression>>,
14367    #[serde(default)]
14368    pub parameters: Option<Box<Expression>>,
14369}
14370
14371/// RegrValx
14372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14373#[cfg_attr(feature = "bindings", derive(TS))]
14374pub struct RegrValx {
14375    pub this: Box<Expression>,
14376    pub expression: Box<Expression>,
14377}
14378
14379/// RegrValy
14380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14381#[cfg_attr(feature = "bindings", derive(TS))]
14382pub struct RegrValy {
14383    pub this: Box<Expression>,
14384    pub expression: Box<Expression>,
14385}
14386
14387/// RegrAvgy
14388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14389#[cfg_attr(feature = "bindings", derive(TS))]
14390pub struct RegrAvgy {
14391    pub this: Box<Expression>,
14392    pub expression: Box<Expression>,
14393}
14394
14395/// RegrAvgx
14396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14397#[cfg_attr(feature = "bindings", derive(TS))]
14398pub struct RegrAvgx {
14399    pub this: Box<Expression>,
14400    pub expression: Box<Expression>,
14401}
14402
14403/// RegrCount
14404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14405#[cfg_attr(feature = "bindings", derive(TS))]
14406pub struct RegrCount {
14407    pub this: Box<Expression>,
14408    pub expression: Box<Expression>,
14409}
14410
14411/// RegrIntercept
14412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14413#[cfg_attr(feature = "bindings", derive(TS))]
14414pub struct RegrIntercept {
14415    pub this: Box<Expression>,
14416    pub expression: Box<Expression>,
14417}
14418
14419/// RegrR2
14420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14421#[cfg_attr(feature = "bindings", derive(TS))]
14422pub struct RegrR2 {
14423    pub this: Box<Expression>,
14424    pub expression: Box<Expression>,
14425}
14426
14427/// RegrSxx
14428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14429#[cfg_attr(feature = "bindings", derive(TS))]
14430pub struct RegrSxx {
14431    pub this: Box<Expression>,
14432    pub expression: Box<Expression>,
14433}
14434
14435/// RegrSxy
14436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14437#[cfg_attr(feature = "bindings", derive(TS))]
14438pub struct RegrSxy {
14439    pub this: Box<Expression>,
14440    pub expression: Box<Expression>,
14441}
14442
14443/// RegrSyy
14444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14445#[cfg_attr(feature = "bindings", derive(TS))]
14446pub struct RegrSyy {
14447    pub this: Box<Expression>,
14448    pub expression: Box<Expression>,
14449}
14450
14451/// RegrSlope
14452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14453#[cfg_attr(feature = "bindings", derive(TS))]
14454pub struct RegrSlope {
14455    pub this: Box<Expression>,
14456    pub expression: Box<Expression>,
14457}
14458
14459/// SafeAdd
14460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14461#[cfg_attr(feature = "bindings", derive(TS))]
14462pub struct SafeAdd {
14463    pub this: Box<Expression>,
14464    pub expression: Box<Expression>,
14465}
14466
14467/// SafeDivide
14468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14469#[cfg_attr(feature = "bindings", derive(TS))]
14470pub struct SafeDivide {
14471    pub this: Box<Expression>,
14472    pub expression: Box<Expression>,
14473}
14474
14475/// SafeMultiply
14476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14477#[cfg_attr(feature = "bindings", derive(TS))]
14478pub struct SafeMultiply {
14479    pub this: Box<Expression>,
14480    pub expression: Box<Expression>,
14481}
14482
14483/// SafeSubtract
14484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14485#[cfg_attr(feature = "bindings", derive(TS))]
14486pub struct SafeSubtract {
14487    pub this: Box<Expression>,
14488    pub expression: Box<Expression>,
14489}
14490
14491/// SHA2
14492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14493#[cfg_attr(feature = "bindings", derive(TS))]
14494pub struct SHA2 {
14495    pub this: Box<Expression>,
14496    #[serde(default)]
14497    pub length: Option<i64>,
14498}
14499
14500/// SHA2Digest
14501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14502#[cfg_attr(feature = "bindings", derive(TS))]
14503pub struct SHA2Digest {
14504    pub this: Box<Expression>,
14505    #[serde(default)]
14506    pub length: Option<i64>,
14507}
14508
14509/// SortArray
14510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14511#[cfg_attr(feature = "bindings", derive(TS))]
14512pub struct SortArray {
14513    pub this: Box<Expression>,
14514    #[serde(default)]
14515    pub asc: Option<Box<Expression>>,
14516    #[serde(default)]
14517    pub nulls_first: Option<Box<Expression>>,
14518}
14519
14520/// SplitPart
14521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14522#[cfg_attr(feature = "bindings", derive(TS))]
14523pub struct SplitPart {
14524    pub this: Box<Expression>,
14525    #[serde(default)]
14526    pub delimiter: Option<Box<Expression>>,
14527    #[serde(default)]
14528    pub part_index: Option<Box<Expression>>,
14529}
14530
14531/// SUBSTRING_INDEX(str, delim, count)
14532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14533#[cfg_attr(feature = "bindings", derive(TS))]
14534pub struct SubstringIndex {
14535    pub this: Box<Expression>,
14536    #[serde(default)]
14537    pub delimiter: Option<Box<Expression>>,
14538    #[serde(default)]
14539    pub count: Option<Box<Expression>>,
14540}
14541
14542/// StandardHash
14543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14544#[cfg_attr(feature = "bindings", derive(TS))]
14545pub struct StandardHash {
14546    pub this: Box<Expression>,
14547    #[serde(default)]
14548    pub expression: Option<Box<Expression>>,
14549}
14550
14551/// StrPosition
14552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14553#[cfg_attr(feature = "bindings", derive(TS))]
14554pub struct StrPosition {
14555    pub this: Box<Expression>,
14556    #[serde(default)]
14557    pub substr: Option<Box<Expression>>,
14558    #[serde(default)]
14559    pub position: Option<Box<Expression>>,
14560    #[serde(default)]
14561    pub occurrence: Option<Box<Expression>>,
14562}
14563
14564/// Search
14565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14566#[cfg_attr(feature = "bindings", derive(TS))]
14567pub struct Search {
14568    pub this: Box<Expression>,
14569    pub expression: Box<Expression>,
14570    #[serde(default)]
14571    pub json_scope: Option<Box<Expression>>,
14572    #[serde(default)]
14573    pub analyzer: Option<Box<Expression>>,
14574    #[serde(default)]
14575    pub analyzer_options: Option<Box<Expression>>,
14576    #[serde(default)]
14577    pub search_mode: Option<Box<Expression>>,
14578}
14579
14580/// SearchIp
14581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14582#[cfg_attr(feature = "bindings", derive(TS))]
14583pub struct SearchIp {
14584    pub this: Box<Expression>,
14585    pub expression: Box<Expression>,
14586}
14587
14588/// StrToDate
14589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14590#[cfg_attr(feature = "bindings", derive(TS))]
14591pub struct StrToDate {
14592    pub this: Box<Expression>,
14593    #[serde(default)]
14594    pub format: Option<String>,
14595    #[serde(default)]
14596    pub safe: Option<Box<Expression>>,
14597}
14598
14599/// StrToTime
14600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14601#[cfg_attr(feature = "bindings", derive(TS))]
14602pub struct StrToTime {
14603    pub this: Box<Expression>,
14604    pub format: String,
14605    #[serde(default)]
14606    pub zone: Option<Box<Expression>>,
14607    #[serde(default)]
14608    pub safe: Option<Box<Expression>>,
14609    #[serde(default)]
14610    pub target_type: Option<Box<Expression>>,
14611}
14612
14613/// StrToUnix
14614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14615#[cfg_attr(feature = "bindings", derive(TS))]
14616pub struct StrToUnix {
14617    #[serde(default)]
14618    pub this: Option<Box<Expression>>,
14619    #[serde(default)]
14620    pub format: Option<String>,
14621}
14622
14623/// StrToMap
14624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14625#[cfg_attr(feature = "bindings", derive(TS))]
14626pub struct StrToMap {
14627    pub this: Box<Expression>,
14628    #[serde(default)]
14629    pub pair_delim: Option<Box<Expression>>,
14630    #[serde(default)]
14631    pub key_value_delim: Option<Box<Expression>>,
14632    #[serde(default)]
14633    pub duplicate_resolution_callback: Option<Box<Expression>>,
14634}
14635
14636/// NumberToStr
14637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14638#[cfg_attr(feature = "bindings", derive(TS))]
14639pub struct NumberToStr {
14640    pub this: Box<Expression>,
14641    pub format: String,
14642    #[serde(default)]
14643    pub culture: Option<Box<Expression>>,
14644}
14645
14646/// FromBase
14647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14648#[cfg_attr(feature = "bindings", derive(TS))]
14649pub struct FromBase {
14650    pub this: Box<Expression>,
14651    pub expression: Box<Expression>,
14652}
14653
14654/// Stuff
14655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14656#[cfg_attr(feature = "bindings", derive(TS))]
14657pub struct Stuff {
14658    pub this: Box<Expression>,
14659    #[serde(default)]
14660    pub start: Option<Box<Expression>>,
14661    #[serde(default)]
14662    pub length: Option<i64>,
14663    pub expression: Box<Expression>,
14664}
14665
14666/// TimeToStr
14667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14668#[cfg_attr(feature = "bindings", derive(TS))]
14669pub struct TimeToStr {
14670    pub this: Box<Expression>,
14671    pub format: String,
14672    #[serde(default)]
14673    pub culture: Option<Box<Expression>>,
14674    #[serde(default)]
14675    pub zone: Option<Box<Expression>>,
14676}
14677
14678/// TimeStrToTime
14679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14680#[cfg_attr(feature = "bindings", derive(TS))]
14681pub struct TimeStrToTime {
14682    pub this: Box<Expression>,
14683    #[serde(default)]
14684    pub zone: Option<Box<Expression>>,
14685}
14686
14687/// TsOrDsAdd
14688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14689#[cfg_attr(feature = "bindings", derive(TS))]
14690pub struct TsOrDsAdd {
14691    pub this: Box<Expression>,
14692    pub expression: Box<Expression>,
14693    #[serde(default)]
14694    pub unit: Option<String>,
14695    #[serde(default)]
14696    pub return_type: Option<Box<Expression>>,
14697}
14698
14699/// TsOrDsDiff
14700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14701#[cfg_attr(feature = "bindings", derive(TS))]
14702pub struct TsOrDsDiff {
14703    pub this: Box<Expression>,
14704    pub expression: Box<Expression>,
14705    #[serde(default)]
14706    pub unit: Option<String>,
14707}
14708
14709/// TsOrDsToDate
14710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14711#[cfg_attr(feature = "bindings", derive(TS))]
14712pub struct TsOrDsToDate {
14713    pub this: Box<Expression>,
14714    #[serde(default)]
14715    pub format: Option<String>,
14716    #[serde(default)]
14717    pub safe: Option<Box<Expression>>,
14718}
14719
14720/// TsOrDsToTime
14721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14722#[cfg_attr(feature = "bindings", derive(TS))]
14723pub struct TsOrDsToTime {
14724    pub this: Box<Expression>,
14725    #[serde(default)]
14726    pub format: Option<String>,
14727    #[serde(default)]
14728    pub safe: Option<Box<Expression>>,
14729}
14730
14731/// Unhex
14732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14733#[cfg_attr(feature = "bindings", derive(TS))]
14734pub struct Unhex {
14735    pub this: Box<Expression>,
14736    #[serde(default)]
14737    pub expression: Option<Box<Expression>>,
14738}
14739
14740/// Uniform
14741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14742#[cfg_attr(feature = "bindings", derive(TS))]
14743pub struct Uniform {
14744    pub this: Box<Expression>,
14745    pub expression: Box<Expression>,
14746    #[serde(default)]
14747    pub gen: Option<Box<Expression>>,
14748    #[serde(default)]
14749    pub seed: Option<Box<Expression>>,
14750}
14751
14752/// UnixToStr
14753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14754#[cfg_attr(feature = "bindings", derive(TS))]
14755pub struct UnixToStr {
14756    pub this: Box<Expression>,
14757    #[serde(default)]
14758    pub format: Option<String>,
14759}
14760
14761/// UnixToTime
14762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14763#[cfg_attr(feature = "bindings", derive(TS))]
14764pub struct UnixToTime {
14765    pub this: Box<Expression>,
14766    #[serde(default)]
14767    pub scale: Option<i64>,
14768    #[serde(default)]
14769    pub zone: Option<Box<Expression>>,
14770    #[serde(default)]
14771    pub hours: Option<Box<Expression>>,
14772    #[serde(default)]
14773    pub minutes: Option<Box<Expression>>,
14774    #[serde(default)]
14775    pub format: Option<String>,
14776    #[serde(default)]
14777    pub target_type: Option<Box<Expression>>,
14778}
14779
14780/// Uuid
14781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14782#[cfg_attr(feature = "bindings", derive(TS))]
14783pub struct Uuid {
14784    #[serde(default)]
14785    pub this: Option<Box<Expression>>,
14786    #[serde(default)]
14787    pub name: Option<String>,
14788    #[serde(default)]
14789    pub is_string: Option<Box<Expression>>,
14790}
14791
14792/// TimestampFromParts
14793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14794#[cfg_attr(feature = "bindings", derive(TS))]
14795pub struct TimestampFromParts {
14796    #[serde(default)]
14797    pub zone: Option<Box<Expression>>,
14798    #[serde(default)]
14799    pub milli: Option<Box<Expression>>,
14800    #[serde(default)]
14801    pub this: Option<Box<Expression>>,
14802    #[serde(default)]
14803    pub expression: Option<Box<Expression>>,
14804}
14805
14806/// TimestampTzFromParts
14807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14808#[cfg_attr(feature = "bindings", derive(TS))]
14809pub struct TimestampTzFromParts {
14810    #[serde(default)]
14811    pub zone: Option<Box<Expression>>,
14812}
14813
14814/// Corr
14815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14816#[cfg_attr(feature = "bindings", derive(TS))]
14817pub struct Corr {
14818    pub this: Box<Expression>,
14819    pub expression: Box<Expression>,
14820    #[serde(default)]
14821    pub null_on_zero_variance: Option<Box<Expression>>,
14822}
14823
14824/// WidthBucket
14825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14826#[cfg_attr(feature = "bindings", derive(TS))]
14827pub struct WidthBucket {
14828    pub this: Box<Expression>,
14829    #[serde(default)]
14830    pub min_value: Option<Box<Expression>>,
14831    #[serde(default)]
14832    pub max_value: Option<Box<Expression>>,
14833    #[serde(default)]
14834    pub num_buckets: Option<Box<Expression>>,
14835    #[serde(default)]
14836    pub threshold: Option<Box<Expression>>,
14837}
14838
14839/// CovarSamp
14840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14841#[cfg_attr(feature = "bindings", derive(TS))]
14842pub struct CovarSamp {
14843    pub this: Box<Expression>,
14844    pub expression: Box<Expression>,
14845}
14846
14847/// CovarPop
14848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14849#[cfg_attr(feature = "bindings", derive(TS))]
14850pub struct CovarPop {
14851    pub this: Box<Expression>,
14852    pub expression: Box<Expression>,
14853}
14854
14855/// Week
14856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14857#[cfg_attr(feature = "bindings", derive(TS))]
14858pub struct Week {
14859    pub this: Box<Expression>,
14860    #[serde(default)]
14861    pub mode: Option<Box<Expression>>,
14862}
14863
14864/// XMLElement
14865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14866#[cfg_attr(feature = "bindings", derive(TS))]
14867pub struct XMLElement {
14868    pub this: Box<Expression>,
14869    #[serde(default)]
14870    pub expressions: Vec<Expression>,
14871    #[serde(default)]
14872    pub evalname: Option<Box<Expression>>,
14873}
14874
14875/// XMLGet
14876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14877#[cfg_attr(feature = "bindings", derive(TS))]
14878pub struct XMLGet {
14879    pub this: Box<Expression>,
14880    pub expression: Box<Expression>,
14881    #[serde(default)]
14882    pub instance: Option<Box<Expression>>,
14883}
14884
14885/// XMLTable
14886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14887#[cfg_attr(feature = "bindings", derive(TS))]
14888pub struct XMLTable {
14889    pub this: Box<Expression>,
14890    #[serde(default)]
14891    pub namespaces: Option<Box<Expression>>,
14892    #[serde(default)]
14893    pub passing: Option<Box<Expression>>,
14894    #[serde(default)]
14895    pub columns: Vec<Expression>,
14896    #[serde(default)]
14897    pub by_ref: Option<Box<Expression>>,
14898}
14899
14900/// XMLKeyValueOption
14901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14902#[cfg_attr(feature = "bindings", derive(TS))]
14903pub struct XMLKeyValueOption {
14904    pub this: Box<Expression>,
14905    #[serde(default)]
14906    pub expression: Option<Box<Expression>>,
14907}
14908
14909/// Zipf
14910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14911#[cfg_attr(feature = "bindings", derive(TS))]
14912pub struct Zipf {
14913    pub this: Box<Expression>,
14914    #[serde(default)]
14915    pub elementcount: Option<Box<Expression>>,
14916    #[serde(default)]
14917    pub gen: Option<Box<Expression>>,
14918}
14919
14920/// Merge
14921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14922#[cfg_attr(feature = "bindings", derive(TS))]
14923pub struct Merge {
14924    pub this: Box<Expression>,
14925    pub using: Box<Expression>,
14926    #[serde(default)]
14927    pub on: Option<Box<Expression>>,
14928    #[serde(default)]
14929    pub using_cond: Option<Box<Expression>>,
14930    #[serde(default)]
14931    pub whens: Option<Box<Expression>>,
14932    #[serde(default)]
14933    pub with_: Option<Box<Expression>>,
14934    #[serde(default)]
14935    pub returning: Option<Box<Expression>>,
14936}
14937
14938/// When
14939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14940#[cfg_attr(feature = "bindings", derive(TS))]
14941pub struct When {
14942    #[serde(default)]
14943    pub matched: Option<Box<Expression>>,
14944    #[serde(default)]
14945    pub source: Option<Box<Expression>>,
14946    #[serde(default)]
14947    pub condition: Option<Box<Expression>>,
14948    pub then: Box<Expression>,
14949}
14950
14951/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14953#[cfg_attr(feature = "bindings", derive(TS))]
14954pub struct Whens {
14955    #[serde(default)]
14956    pub expressions: Vec<Expression>,
14957}
14958
14959/// NextValueFor
14960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14961#[cfg_attr(feature = "bindings", derive(TS))]
14962pub struct NextValueFor {
14963    pub this: Box<Expression>,
14964    #[serde(default)]
14965    pub order: Option<Box<Expression>>,
14966}
14967
14968#[cfg(test)]
14969mod tests {
14970    use super::*;
14971
14972    #[test]
14973    #[cfg(feature = "bindings")]
14974    fn export_typescript_types() {
14975        // This test exports TypeScript types to the generated directory
14976        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14977        Expression::export_all(&ts_rs::Config::default())
14978            .expect("Failed to export Expression types");
14979    }
14980
14981    #[test]
14982    fn test_simple_select_builder() {
14983        let select = Select::new()
14984            .column(Expression::star())
14985            .from(Expression::Table(Box::new(TableRef::new("users"))));
14986
14987        assert_eq!(select.expressions.len(), 1);
14988        assert!(select.from.is_some());
14989    }
14990
14991    #[test]
14992    fn test_expression_alias() {
14993        let expr = Expression::column("id").alias("user_id");
14994
14995        match expr {
14996            Expression::Alias(a) => {
14997                assert_eq!(a.alias.name, "user_id");
14998            }
14999            _ => panic!("Expected Alias"),
15000        }
15001    }
15002
15003    #[test]
15004    fn test_literal_creation() {
15005        let num = Expression::number(42);
15006        let str = Expression::string("hello");
15007
15008        match num {
15009            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
15010                let Literal::Number(n) = lit.as_ref() else {
15011                    unreachable!()
15012                };
15013                assert_eq!(n, "42")
15014            }
15015            _ => panic!("Expected Number"),
15016        }
15017
15018        match str {
15019            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
15020                let Literal::String(s) = lit.as_ref() else {
15021                    unreachable!()
15022                };
15023                assert_eq!(s, "hello")
15024            }
15025            _ => panic!("Expected String"),
15026        }
15027    }
15028
15029    #[test]
15030    fn test_expression_sql() {
15031        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
15032        assert_eq!(expr.sql(), "SELECT 1 + 2");
15033    }
15034
15035    #[test]
15036    fn test_expression_sql_for() {
15037        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
15038        let sql = expr.sql_for(crate::DialectType::Generic);
15039        // Generic mode normalizes IF() to CASE WHEN
15040        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
15041    }
15042}