Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Box<Literal>),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // Exasol: function call with EMITS clause
486    FunctionEmits(Box<FunctionEmits>),
487
488    // JSON functions
489    JsonExtract(Box<JsonExtractFunc>),
490    JsonExtractScalar(Box<JsonExtractFunc>),
491    JsonExtractPath(Box<JsonPathFunc>),
492    JsonArray(Box<VarArgFunc>),
493    JsonObject(Box<JsonObjectFunc>),
494    JsonQuery(Box<JsonExtractFunc>),
495    JsonValue(Box<JsonExtractFunc>),
496    JsonArrayLength(Box<UnaryFunc>),
497    JsonKeys(Box<UnaryFunc>),
498    JsonType(Box<UnaryFunc>),
499    ParseJson(Box<UnaryFunc>),
500    ToJson(Box<UnaryFunc>),
501    JsonSet(Box<JsonModifyFunc>),
502    JsonInsert(Box<JsonModifyFunc>),
503    JsonRemove(Box<JsonPathFunc>),
504    JsonMergePatch(Box<BinaryFunc>),
505    JsonArrayAgg(Box<JsonArrayAggFunc>),
506    JsonObjectAgg(Box<JsonObjectAggFunc>),
507
508    // Type casting/conversion
509    Convert(Box<ConvertFunc>),
510    Typeof(Box<UnaryFunc>),
511
512    // Additional expressions
513    Lambda(Box<LambdaExpr>),
514    Parameter(Box<Parameter>),
515    Placeholder(Placeholder),
516    NamedArgument(Box<NamedArgument>),
517    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
518    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
519    TableArgument(Box<TableArgument>),
520    SqlComment(Box<SqlComment>),
521
522    // Additional predicates
523    NullSafeEq(Box<BinaryOp>),
524    NullSafeNeq(Box<BinaryOp>),
525    Glob(Box<BinaryOp>),
526    SimilarTo(Box<SimilarToExpr>),
527    Any(Box<QuantifiedExpr>),
528    All(Box<QuantifiedExpr>),
529    Overlaps(Box<OverlapsExpr>),
530
531    // Bitwise operations
532    BitwiseLeftShift(Box<BinaryOp>),
533    BitwiseRightShift(Box<BinaryOp>),
534    BitwiseAndAgg(Box<AggFunc>),
535    BitwiseOrAgg(Box<AggFunc>),
536    BitwiseXorAgg(Box<AggFunc>),
537
538    // Array/struct/map access
539    Subscript(Box<Subscript>),
540    Dot(Box<DotAccess>),
541    MethodCall(Box<MethodCall>),
542    ArraySlice(Box<ArraySlice>),
543
544    // DDL statements
545    CreateTable(Box<CreateTable>),
546    DropTable(Box<DropTable>),
547    Undrop(Box<Undrop>),
548    AlterTable(Box<AlterTable>),
549    CreateIndex(Box<CreateIndex>),
550    DropIndex(Box<DropIndex>),
551    CreateView(Box<CreateView>),
552    DropView(Box<DropView>),
553    AlterView(Box<AlterView>),
554    AlterIndex(Box<AlterIndex>),
555    Truncate(Box<Truncate>),
556    Use(Box<Use>),
557    Cache(Box<Cache>),
558    Uncache(Box<Uncache>),
559    LoadData(Box<LoadData>),
560    Pragma(Box<Pragma>),
561    Grant(Box<Grant>),
562    Revoke(Box<Revoke>),
563    Comment(Box<Comment>),
564    SetStatement(Box<SetStatement>),
565    // Phase 4: Additional DDL statements
566    CreateSchema(Box<CreateSchema>),
567    DropSchema(Box<DropSchema>),
568    DropNamespace(Box<DropNamespace>),
569    CreateDatabase(Box<CreateDatabase>),
570    DropDatabase(Box<DropDatabase>),
571    CreateFunction(Box<CreateFunction>),
572    DropFunction(Box<DropFunction>),
573    CreateProcedure(Box<CreateProcedure>),
574    DropProcedure(Box<DropProcedure>),
575    CreateSequence(Box<CreateSequence>),
576    CreateSynonym(Box<CreateSynonym>),
577    DropSequence(Box<DropSequence>),
578    AlterSequence(Box<AlterSequence>),
579    CreateTrigger(Box<CreateTrigger>),
580    DropTrigger(Box<DropTrigger>),
581    CreateType(Box<CreateType>),
582    DropType(Box<DropType>),
583    Describe(Box<Describe>),
584    Show(Box<Show>),
585
586    // Transaction and other commands
587    Command(Box<Command>),
588    Kill(Box<Kill>),
589    /// EXEC/EXECUTE statement (TSQL stored procedure call)
590    Execute(Box<ExecuteStatement>),
591
592    /// Snowflake CREATE TASK statement
593    CreateTask(Box<CreateTask>),
594
595    // Placeholder for unparsed/raw SQL
596    Raw(Raw),
597
598    // Paren for grouping
599    Paren(Box<Paren>),
600
601    // Expression with trailing comments (for round-trip preservation)
602    Annotated(Box<Annotated>),
603
604    // === BATCH GENERATED EXPRESSION TYPES ===
605    // Generated from Python sqlglot expressions.py
606    Refresh(Box<Refresh>),
607    LockingStatement(Box<LockingStatement>),
608    SequenceProperties(Box<SequenceProperties>),
609    TruncateTable(Box<TruncateTable>),
610    Clone(Box<Clone>),
611    Attach(Box<Attach>),
612    Detach(Box<Detach>),
613    Install(Box<Install>),
614    Summarize(Box<Summarize>),
615    Declare(Box<Declare>),
616    DeclareItem(Box<DeclareItem>),
617    Set(Box<Set>),
618    Heredoc(Box<Heredoc>),
619    SetItem(Box<SetItem>),
620    QueryBand(Box<QueryBand>),
621    UserDefinedFunction(Box<UserDefinedFunction>),
622    RecursiveWithSearch(Box<RecursiveWithSearch>),
623    ProjectionDef(Box<ProjectionDef>),
624    TableAlias(Box<TableAlias>),
625    ByteString(Box<ByteString>),
626    HexStringExpr(Box<HexStringExpr>),
627    UnicodeString(Box<UnicodeString>),
628    ColumnPosition(Box<ColumnPosition>),
629    ColumnDef(Box<ColumnDef>),
630    AlterColumn(Box<AlterColumn>),
631    AlterSortKey(Box<AlterSortKey>),
632    AlterSet(Box<AlterSet>),
633    RenameColumn(Box<RenameColumn>),
634    Comprehension(Box<Comprehension>),
635    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
636    MergeTreeTTL(Box<MergeTreeTTL>),
637    IndexConstraintOption(Box<IndexConstraintOption>),
638    ColumnConstraint(Box<ColumnConstraint>),
639    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
640    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
641    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
642    CheckColumnConstraint(Box<CheckColumnConstraint>),
643    AssumeColumnConstraint(Box<AssumeColumnConstraint>),
644    CompressColumnConstraint(Box<CompressColumnConstraint>),
645    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
646    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
647    WithOperator(Box<WithOperator>),
648    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
649    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
650    CommentColumnConstraint(CommentColumnConstraint),
651    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
652    IndexColumnConstraint(Box<IndexColumnConstraint>),
653    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
654    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
655    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
656    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
657    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
658    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
659    InOutColumnConstraint(Box<InOutColumnConstraint>),
660    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
661    PathColumnConstraint(Box<PathColumnConstraint>),
662    Constraint(Box<Constraint>),
663    Export(Box<Export>),
664    Filter(Box<Filter>),
665    Changes(Box<Changes>),
666    CopyParameter(Box<CopyParameter>),
667    Credentials(Box<Credentials>),
668    Directory(Box<Directory>),
669    ForeignKey(Box<ForeignKey>),
670    ColumnPrefix(Box<ColumnPrefix>),
671    PrimaryKey(Box<PrimaryKey>),
672    IntoClause(Box<IntoClause>),
673    JoinHint(Box<JoinHint>),
674    Opclass(Box<Opclass>),
675    Index(Box<Index>),
676    IndexParameters(Box<IndexParameters>),
677    ConditionalInsert(Box<ConditionalInsert>),
678    MultitableInserts(Box<MultitableInserts>),
679    OnConflict(Box<OnConflict>),
680    OnCondition(Box<OnCondition>),
681    Returning(Box<Returning>),
682    Introducer(Box<Introducer>),
683    PartitionRange(Box<PartitionRange>),
684    Fetch(Box<Fetch>),
685    Group(Box<Group>),
686    Cube(Box<Cube>),
687    Rollup(Box<Rollup>),
688    GroupingSets(Box<GroupingSets>),
689    LimitOptions(Box<LimitOptions>),
690    Lateral(Box<Lateral>),
691    TableFromRows(Box<TableFromRows>),
692    RowsFrom(Box<RowsFrom>),
693    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
694    WithFill(Box<WithFill>),
695    Property(Box<Property>),
696    GrantPrivilege(Box<GrantPrivilege>),
697    GrantPrincipal(Box<GrantPrincipal>),
698    AllowedValuesProperty(Box<AllowedValuesProperty>),
699    AlgorithmProperty(Box<AlgorithmProperty>),
700    AutoIncrementProperty(Box<AutoIncrementProperty>),
701    AutoRefreshProperty(Box<AutoRefreshProperty>),
702    BackupProperty(Box<BackupProperty>),
703    BuildProperty(Box<BuildProperty>),
704    BlockCompressionProperty(Box<BlockCompressionProperty>),
705    CharacterSetProperty(Box<CharacterSetProperty>),
706    ChecksumProperty(Box<ChecksumProperty>),
707    CollateProperty(Box<CollateProperty>),
708    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
709    DataDeletionProperty(Box<DataDeletionProperty>),
710    DefinerProperty(Box<DefinerProperty>),
711    DistKeyProperty(Box<DistKeyProperty>),
712    DistributedByProperty(Box<DistributedByProperty>),
713    DistStyleProperty(Box<DistStyleProperty>),
714    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
715    EngineProperty(Box<EngineProperty>),
716    ToTableProperty(Box<ToTableProperty>),
717    ExecuteAsProperty(Box<ExecuteAsProperty>),
718    ExternalProperty(Box<ExternalProperty>),
719    FallbackProperty(Box<FallbackProperty>),
720    FileFormatProperty(Box<FileFormatProperty>),
721    CredentialsProperty(Box<CredentialsProperty>),
722    FreespaceProperty(Box<FreespaceProperty>),
723    InheritsProperty(Box<InheritsProperty>),
724    InputModelProperty(Box<InputModelProperty>),
725    OutputModelProperty(Box<OutputModelProperty>),
726    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
727    JournalProperty(Box<JournalProperty>),
728    LanguageProperty(Box<LanguageProperty>),
729    EnviromentProperty(Box<EnviromentProperty>),
730    ClusteredByProperty(Box<ClusteredByProperty>),
731    DictProperty(Box<DictProperty>),
732    DictRange(Box<DictRange>),
733    OnCluster(Box<OnCluster>),
734    LikeProperty(Box<LikeProperty>),
735    LocationProperty(Box<LocationProperty>),
736    LockProperty(Box<LockProperty>),
737    LockingProperty(Box<LockingProperty>),
738    LogProperty(Box<LogProperty>),
739    MaterializedProperty(Box<MaterializedProperty>),
740    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
741    OnProperty(Box<OnProperty>),
742    OnCommitProperty(Box<OnCommitProperty>),
743    PartitionedByProperty(Box<PartitionedByProperty>),
744    PartitionByProperty(Box<PartitionByProperty>),
745    PartitionedByBucket(Box<PartitionedByBucket>),
746    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
747    PartitionByTruncate(Box<PartitionByTruncate>),
748    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
749    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
750    PartitionByListProperty(Box<PartitionByListProperty>),
751    PartitionList(Box<PartitionList>),
752    Partition(Box<Partition>),
753    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
754    UniqueKeyProperty(Box<UniqueKeyProperty>),
755    RollupProperty(Box<RollupProperty>),
756    PartitionBoundSpec(Box<PartitionBoundSpec>),
757    PartitionedOfProperty(Box<PartitionedOfProperty>),
758    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
759    ReturnsProperty(Box<ReturnsProperty>),
760    RowFormatProperty(Box<RowFormatProperty>),
761    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
762    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
763    QueryTransform(Box<QueryTransform>),
764    SampleProperty(Box<SampleProperty>),
765    SecurityProperty(Box<SecurityProperty>),
766    SchemaCommentProperty(Box<SchemaCommentProperty>),
767    SemanticView(Box<SemanticView>),
768    SerdeProperties(Box<SerdeProperties>),
769    SetProperty(Box<SetProperty>),
770    SharingProperty(Box<SharingProperty>),
771    SetConfigProperty(Box<SetConfigProperty>),
772    SettingsProperty(Box<SettingsProperty>),
773    SortKeyProperty(Box<SortKeyProperty>),
774    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
775    SqlSecurityProperty(Box<SqlSecurityProperty>),
776    StabilityProperty(Box<StabilityProperty>),
777    StorageHandlerProperty(Box<StorageHandlerProperty>),
778    TemporaryProperty(Box<TemporaryProperty>),
779    Tags(Box<Tags>),
780    TransformModelProperty(Box<TransformModelProperty>),
781    TransientProperty(Box<TransientProperty>),
782    UsingTemplateProperty(Box<UsingTemplateProperty>),
783    ViewAttributeProperty(Box<ViewAttributeProperty>),
784    VolatileProperty(Box<VolatileProperty>),
785    WithDataProperty(Box<WithDataProperty>),
786    WithJournalTableProperty(Box<WithJournalTableProperty>),
787    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
788    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
789    WithProcedureOptions(Box<WithProcedureOptions>),
790    EncodeProperty(Box<EncodeProperty>),
791    IncludeProperty(Box<IncludeProperty>),
792    Properties(Box<Properties>),
793    OptionsProperty(Box<OptionsProperty>),
794    InputOutputFormat(Box<InputOutputFormat>),
795    Reference(Box<Reference>),
796    QueryOption(Box<QueryOption>),
797    WithTableHint(Box<WithTableHint>),
798    IndexTableHint(Box<IndexTableHint>),
799    HistoricalData(Box<HistoricalData>),
800    Get(Box<Get>),
801    SetOperation(Box<SetOperation>),
802    Var(Box<Var>),
803    Variadic(Box<Variadic>),
804    Version(Box<Version>),
805    Schema(Box<Schema>),
806    Lock(Box<Lock>),
807    TableSample(Box<TableSample>),
808    Tag(Box<Tag>),
809    UnpivotColumns(Box<UnpivotColumns>),
810    WindowSpec(Box<WindowSpec>),
811    SessionParameter(Box<SessionParameter>),
812    PseudoType(Box<PseudoType>),
813    ObjectIdentifier(Box<ObjectIdentifier>),
814    Transaction(Box<Transaction>),
815    Commit(Box<Commit>),
816    Rollback(Box<Rollback>),
817    AlterSession(Box<AlterSession>),
818    Analyze(Box<Analyze>),
819    AnalyzeStatistics(Box<AnalyzeStatistics>),
820    AnalyzeHistogram(Box<AnalyzeHistogram>),
821    AnalyzeSample(Box<AnalyzeSample>),
822    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
823    AnalyzeDelete(Box<AnalyzeDelete>),
824    AnalyzeWith(Box<AnalyzeWith>),
825    AnalyzeValidate(Box<AnalyzeValidate>),
826    AddPartition(Box<AddPartition>),
827    AttachOption(Box<AttachOption>),
828    DropPartition(Box<DropPartition>),
829    ReplacePartition(Box<ReplacePartition>),
830    DPipe(Box<DPipe>),
831    Operator(Box<Operator>),
832    PivotAny(Box<PivotAny>),
833    Aliases(Box<Aliases>),
834    AtIndex(Box<AtIndex>),
835    FromTimeZone(Box<FromTimeZone>),
836    FormatPhrase(Box<FormatPhrase>),
837    ForIn(Box<ForIn>),
838    TimeUnit(Box<TimeUnit>),
839    IntervalOp(Box<IntervalOp>),
840    IntervalSpan(Box<IntervalSpan>),
841    HavingMax(Box<HavingMax>),
842    CosineDistance(Box<CosineDistance>),
843    DotProduct(Box<DotProduct>),
844    EuclideanDistance(Box<EuclideanDistance>),
845    ManhattanDistance(Box<ManhattanDistance>),
846    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
847    Booland(Box<Booland>),
848    Boolor(Box<Boolor>),
849    ParameterizedAgg(Box<ParameterizedAgg>),
850    ArgMax(Box<ArgMax>),
851    ArgMin(Box<ArgMin>),
852    ApproxTopK(Box<ApproxTopK>),
853    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
854    ApproxTopKCombine(Box<ApproxTopKCombine>),
855    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
856    ApproxTopSum(Box<ApproxTopSum>),
857    ApproxQuantiles(Box<ApproxQuantiles>),
858    Minhash(Box<Minhash>),
859    FarmFingerprint(Box<FarmFingerprint>),
860    Float64(Box<Float64>),
861    Transform(Box<Transform>),
862    Translate(Box<Translate>),
863    Grouping(Box<Grouping>),
864    GroupingId(Box<GroupingId>),
865    Anonymous(Box<Anonymous>),
866    AnonymousAggFunc(Box<AnonymousAggFunc>),
867    CombinedAggFunc(Box<CombinedAggFunc>),
868    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
869    HashAgg(Box<HashAgg>),
870    Hll(Box<Hll>),
871    Apply(Box<Apply>),
872    ToBoolean(Box<ToBoolean>),
873    List(Box<List>),
874    ToMap(Box<ToMap>),
875    Pad(Box<Pad>),
876    ToChar(Box<ToChar>),
877    ToNumber(Box<ToNumber>),
878    ToDouble(Box<ToDouble>),
879    Int64(Box<UnaryFunc>),
880    StringFunc(Box<StringFunc>),
881    ToDecfloat(Box<ToDecfloat>),
882    TryToDecfloat(Box<TryToDecfloat>),
883    ToFile(Box<ToFile>),
884    Columns(Box<Columns>),
885    ConvertToCharset(Box<ConvertToCharset>),
886    ConvertTimezone(Box<ConvertTimezone>),
887    GenerateSeries(Box<GenerateSeries>),
888    AIAgg(Box<AIAgg>),
889    AIClassify(Box<AIClassify>),
890    ArrayAll(Box<ArrayAll>),
891    ArrayAny(Box<ArrayAny>),
892    ArrayConstructCompact(Box<ArrayConstructCompact>),
893    StPoint(Box<StPoint>),
894    StDistance(Box<StDistance>),
895    StringToArray(Box<StringToArray>),
896    ArraySum(Box<ArraySum>),
897    ObjectAgg(Box<ObjectAgg>),
898    CastToStrType(Box<CastToStrType>),
899    CheckJson(Box<CheckJson>),
900    CheckXml(Box<CheckXml>),
901    TranslateCharacters(Box<TranslateCharacters>),
902    CurrentSchemas(Box<CurrentSchemas>),
903    CurrentDatetime(Box<CurrentDatetime>),
904    Localtime(Box<Localtime>),
905    Localtimestamp(Box<Localtimestamp>),
906    Systimestamp(Box<Systimestamp>),
907    CurrentSchema(Box<CurrentSchema>),
908    CurrentUser(Box<CurrentUser>),
909    UtcTime(Box<UtcTime>),
910    UtcTimestamp(Box<UtcTimestamp>),
911    Timestamp(Box<TimestampFunc>),
912    DateBin(Box<DateBin>),
913    Datetime(Box<Datetime>),
914    DatetimeAdd(Box<DatetimeAdd>),
915    DatetimeSub(Box<DatetimeSub>),
916    DatetimeDiff(Box<DatetimeDiff>),
917    DatetimeTrunc(Box<DatetimeTrunc>),
918    Dayname(Box<Dayname>),
919    MakeInterval(Box<MakeInterval>),
920    PreviousDay(Box<PreviousDay>),
921    Elt(Box<Elt>),
922    TimestampAdd(Box<TimestampAdd>),
923    TimestampSub(Box<TimestampSub>),
924    TimestampDiff(Box<TimestampDiff>),
925    TimeSlice(Box<TimeSlice>),
926    TimeAdd(Box<TimeAdd>),
927    TimeSub(Box<TimeSub>),
928    TimeDiff(Box<TimeDiff>),
929    TimeTrunc(Box<TimeTrunc>),
930    DateFromParts(Box<DateFromParts>),
931    TimeFromParts(Box<TimeFromParts>),
932    DecodeCase(Box<DecodeCase>),
933    Decrypt(Box<Decrypt>),
934    DecryptRaw(Box<DecryptRaw>),
935    Encode(Box<Encode>),
936    Encrypt(Box<Encrypt>),
937    EncryptRaw(Box<EncryptRaw>),
938    EqualNull(Box<EqualNull>),
939    ToBinary(Box<ToBinary>),
940    Base64DecodeBinary(Box<Base64DecodeBinary>),
941    Base64DecodeString(Box<Base64DecodeString>),
942    Base64Encode(Box<Base64Encode>),
943    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
944    TryBase64DecodeString(Box<TryBase64DecodeString>),
945    GapFill(Box<GapFill>),
946    GenerateDateArray(Box<GenerateDateArray>),
947    GenerateTimestampArray(Box<GenerateTimestampArray>),
948    GetExtract(Box<GetExtract>),
949    Getbit(Box<Getbit>),
950    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
951    HexEncode(Box<HexEncode>),
952    Compress(Box<Compress>),
953    DecompressBinary(Box<DecompressBinary>),
954    DecompressString(Box<DecompressString>),
955    Xor(Box<Xor>),
956    Nullif(Box<Nullif>),
957    JSON(Box<JSON>),
958    JSONPath(Box<JSONPath>),
959    JSONPathFilter(Box<JSONPathFilter>),
960    JSONPathKey(Box<JSONPathKey>),
961    JSONPathRecursive(Box<JSONPathRecursive>),
962    JSONPathScript(Box<JSONPathScript>),
963    JSONPathSlice(Box<JSONPathSlice>),
964    JSONPathSelector(Box<JSONPathSelector>),
965    JSONPathSubscript(Box<JSONPathSubscript>),
966    JSONPathUnion(Box<JSONPathUnion>),
967    Format(Box<Format>),
968    JSONKeys(Box<JSONKeys>),
969    JSONKeyValue(Box<JSONKeyValue>),
970    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
971    JSONObject(Box<JSONObject>),
972    JSONObjectAgg(Box<JSONObjectAgg>),
973    JSONBObjectAgg(Box<JSONBObjectAgg>),
974    JSONArray(Box<JSONArray>),
975    JSONArrayAgg(Box<JSONArrayAgg>),
976    JSONExists(Box<JSONExists>),
977    JSONColumnDef(Box<JSONColumnDef>),
978    JSONSchema(Box<JSONSchema>),
979    JSONSet(Box<JSONSet>),
980    JSONStripNulls(Box<JSONStripNulls>),
981    JSONValue(Box<JSONValue>),
982    JSONValueArray(Box<JSONValueArray>),
983    JSONRemove(Box<JSONRemove>),
984    JSONTable(Box<JSONTable>),
985    JSONType(Box<JSONType>),
986    ObjectInsert(Box<ObjectInsert>),
987    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
988    OpenJSON(Box<OpenJSON>),
989    JSONBExists(Box<JSONBExists>),
990    JSONBContains(Box<BinaryFunc>),
991    JSONBExtract(Box<BinaryFunc>),
992    JSONCast(Box<JSONCast>),
993    JSONExtract(Box<JSONExtract>),
994    JSONExtractQuote(Box<JSONExtractQuote>),
995    JSONExtractArray(Box<JSONExtractArray>),
996    JSONExtractScalar(Box<JSONExtractScalar>),
997    JSONBExtractScalar(Box<JSONBExtractScalar>),
998    JSONFormat(Box<JSONFormat>),
999    JSONBool(Box<UnaryFunc>),
1000    JSONPathRoot(JSONPathRoot),
1001    JSONArrayAppend(Box<JSONArrayAppend>),
1002    JSONArrayContains(Box<JSONArrayContains>),
1003    JSONArrayInsert(Box<JSONArrayInsert>),
1004    ParseJSON(Box<ParseJSON>),
1005    ParseUrl(Box<ParseUrl>),
1006    ParseIp(Box<ParseIp>),
1007    ParseTime(Box<ParseTime>),
1008    ParseDatetime(Box<ParseDatetime>),
1009    Map(Box<Map>),
1010    MapCat(Box<MapCat>),
1011    MapDelete(Box<MapDelete>),
1012    MapInsert(Box<MapInsert>),
1013    MapPick(Box<MapPick>),
1014    ScopeResolution(Box<ScopeResolution>),
1015    Slice(Box<Slice>),
1016    VarMap(Box<VarMap>),
1017    MatchAgainst(Box<MatchAgainst>),
1018    MD5Digest(Box<MD5Digest>),
1019    MD5NumberLower64(Box<UnaryFunc>),
1020    MD5NumberUpper64(Box<UnaryFunc>),
1021    Monthname(Box<Monthname>),
1022    Ntile(Box<Ntile>),
1023    Normalize(Box<Normalize>),
1024    Normal(Box<Normal>),
1025    Predict(Box<Predict>),
1026    MLTranslate(Box<MLTranslate>),
1027    FeaturesAtTime(Box<FeaturesAtTime>),
1028    GenerateEmbedding(Box<GenerateEmbedding>),
1029    MLForecast(Box<MLForecast>),
1030    ModelAttribute(Box<ModelAttribute>),
1031    VectorSearch(Box<VectorSearch>),
1032    Quantile(Box<Quantile>),
1033    ApproxQuantile(Box<ApproxQuantile>),
1034    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1035    Randn(Box<Randn>),
1036    Randstr(Box<Randstr>),
1037    RangeN(Box<RangeN>),
1038    RangeBucket(Box<RangeBucket>),
1039    ReadCSV(Box<ReadCSV>),
1040    ReadParquet(Box<ReadParquet>),
1041    Reduce(Box<Reduce>),
1042    RegexpExtractAll(Box<RegexpExtractAll>),
1043    RegexpILike(Box<RegexpILike>),
1044    RegexpFullMatch(Box<RegexpFullMatch>),
1045    RegexpInstr(Box<RegexpInstr>),
1046    RegexpSplit(Box<RegexpSplit>),
1047    RegexpCount(Box<RegexpCount>),
1048    RegrValx(Box<RegrValx>),
1049    RegrValy(Box<RegrValy>),
1050    RegrAvgy(Box<RegrAvgy>),
1051    RegrAvgx(Box<RegrAvgx>),
1052    RegrCount(Box<RegrCount>),
1053    RegrIntercept(Box<RegrIntercept>),
1054    RegrR2(Box<RegrR2>),
1055    RegrSxx(Box<RegrSxx>),
1056    RegrSxy(Box<RegrSxy>),
1057    RegrSyy(Box<RegrSyy>),
1058    RegrSlope(Box<RegrSlope>),
1059    SafeAdd(Box<SafeAdd>),
1060    SafeDivide(Box<SafeDivide>),
1061    SafeMultiply(Box<SafeMultiply>),
1062    SafeSubtract(Box<SafeSubtract>),
1063    SHA2(Box<SHA2>),
1064    SHA2Digest(Box<SHA2Digest>),
1065    SortArray(Box<SortArray>),
1066    SplitPart(Box<SplitPart>),
1067    SubstringIndex(Box<SubstringIndex>),
1068    StandardHash(Box<StandardHash>),
1069    StrPosition(Box<StrPosition>),
1070    Search(Box<Search>),
1071    SearchIp(Box<SearchIp>),
1072    StrToDate(Box<StrToDate>),
1073    DateStrToDate(Box<UnaryFunc>),
1074    DateToDateStr(Box<UnaryFunc>),
1075    StrToTime(Box<StrToTime>),
1076    StrToUnix(Box<StrToUnix>),
1077    StrToMap(Box<StrToMap>),
1078    NumberToStr(Box<NumberToStr>),
1079    FromBase(Box<FromBase>),
1080    Stuff(Box<Stuff>),
1081    TimeToStr(Box<TimeToStr>),
1082    TimeStrToTime(Box<TimeStrToTime>),
1083    TsOrDsAdd(Box<TsOrDsAdd>),
1084    TsOrDsDiff(Box<TsOrDsDiff>),
1085    TsOrDsToDate(Box<TsOrDsToDate>),
1086    TsOrDsToTime(Box<TsOrDsToTime>),
1087    Unhex(Box<Unhex>),
1088    Uniform(Box<Uniform>),
1089    UnixToStr(Box<UnixToStr>),
1090    UnixToTime(Box<UnixToTime>),
1091    Uuid(Box<Uuid>),
1092    TimestampFromParts(Box<TimestampFromParts>),
1093    TimestampTzFromParts(Box<TimestampTzFromParts>),
1094    Corr(Box<Corr>),
1095    WidthBucket(Box<WidthBucket>),
1096    CovarSamp(Box<CovarSamp>),
1097    CovarPop(Box<CovarPop>),
1098    Week(Box<Week>),
1099    XMLElement(Box<XMLElement>),
1100    XMLGet(Box<XMLGet>),
1101    XMLTable(Box<XMLTable>),
1102    XMLKeyValueOption(Box<XMLKeyValueOption>),
1103    Zipf(Box<Zipf>),
1104    Merge(Box<Merge>),
1105    When(Box<When>),
1106    Whens(Box<Whens>),
1107    NextValueFor(Box<NextValueFor>),
1108    /// RETURN statement (DuckDB stored procedures)
1109    ReturnStmt(Box<Expression>),
1110}
1111
1112impl Expression {
1113    /// Create a `Column` variant, boxing the value automatically.
1114    #[inline]
1115    pub fn boxed_column(col: Column) -> Self {
1116        Expression::Column(Box::new(col))
1117    }
1118
1119    /// Create a `Table` variant, boxing the value automatically.
1120    #[inline]
1121    pub fn boxed_table(t: TableRef) -> Self {
1122        Expression::Table(Box::new(t))
1123    }
1124
1125    /// Returns `true` if this expression is a valid top-level SQL statement.
1126    ///
1127    /// Bare expressions like identifiers, literals, and function calls are not
1128    /// valid statements. This is used by `validate()` to reject inputs like
1129    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1130    /// plus the bare identifier `doo`.
1131    pub fn is_statement(&self) -> bool {
1132        match self {
1133            // Queries
1134            Expression::Select(_)
1135            | Expression::Union(_)
1136            | Expression::Intersect(_)
1137            | Expression::Except(_)
1138            | Expression::Subquery(_)
1139            | Expression::Values(_)
1140            | Expression::PipeOperator(_)
1141
1142            // DML
1143            | Expression::Insert(_)
1144            | Expression::Update(_)
1145            | Expression::Delete(_)
1146            | Expression::Copy(_)
1147            | Expression::Put(_)
1148            | Expression::Merge(_)
1149
1150            // DDL
1151            | Expression::CreateTable(_)
1152            | Expression::DropTable(_)
1153            | Expression::Undrop(_)
1154            | Expression::AlterTable(_)
1155            | Expression::CreateIndex(_)
1156            | Expression::DropIndex(_)
1157            | Expression::CreateView(_)
1158            | Expression::DropView(_)
1159            | Expression::AlterView(_)
1160            | Expression::AlterIndex(_)
1161            | Expression::Truncate(_)
1162            | Expression::TruncateTable(_)
1163            | Expression::CreateSchema(_)
1164            | Expression::DropSchema(_)
1165            | Expression::DropNamespace(_)
1166            | Expression::CreateDatabase(_)
1167            | Expression::DropDatabase(_)
1168            | Expression::CreateFunction(_)
1169            | Expression::DropFunction(_)
1170            | Expression::CreateProcedure(_)
1171            | Expression::DropProcedure(_)
1172            | Expression::CreateSequence(_)
1173            | Expression::CreateSynonym(_)
1174            | Expression::DropSequence(_)
1175            | Expression::AlterSequence(_)
1176            | Expression::CreateTrigger(_)
1177            | Expression::DropTrigger(_)
1178            | Expression::CreateType(_)
1179            | Expression::DropType(_)
1180            | Expression::Comment(_)
1181
1182            // Session/Transaction/Control
1183            | Expression::Use(_)
1184            | Expression::Set(_)
1185            | Expression::SetStatement(_)
1186            | Expression::Transaction(_)
1187            | Expression::Commit(_)
1188            | Expression::Rollback(_)
1189            | Expression::Grant(_)
1190            | Expression::Revoke(_)
1191            | Expression::Cache(_)
1192            | Expression::Uncache(_)
1193            | Expression::LoadData(_)
1194            | Expression::Pragma(_)
1195            | Expression::Describe(_)
1196            | Expression::Show(_)
1197            | Expression::Kill(_)
1198            | Expression::Execute(_)
1199            | Expression::Declare(_)
1200            | Expression::Refresh(_)
1201            | Expression::AlterSession(_)
1202            | Expression::LockingStatement(_)
1203
1204            // Analyze
1205            | Expression::Analyze(_)
1206            | Expression::AnalyzeStatistics(_)
1207            | Expression::AnalyzeHistogram(_)
1208            | Expression::AnalyzeSample(_)
1209            | Expression::AnalyzeListChainedRows(_)
1210            | Expression::AnalyzeDelete(_)
1211
1212            // Attach/Detach/Install/Summarize
1213            | Expression::Attach(_)
1214            | Expression::Detach(_)
1215            | Expression::Install(_)
1216            | Expression::Summarize(_)
1217
1218            // Pivot at statement level
1219            | Expression::Pivot(_)
1220            | Expression::Unpivot(_)
1221
1222            // Command (raw/unparsed statements)
1223            | Expression::Command(_)
1224            | Expression::Raw(_)
1225            | Expression::CreateTask(_)
1226
1227            // Return statement
1228            | Expression::ReturnStmt(_) => true,
1229
1230            // Annotated wraps another expression with comments — check inner
1231            Expression::Annotated(a) => a.this.is_statement(),
1232
1233            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1234            Expression::Alias(a) => a.this.is_statement(),
1235
1236            // Everything else (identifiers, literals, operators, functions, etc.)
1237            _ => false,
1238        }
1239    }
1240
1241    /// Create a literal number expression from an integer.
1242    pub fn number(n: i64) -> Self {
1243        Expression::Literal(Box::new(Literal::Number(n.to_string())))
1244    }
1245
1246    /// Create a single-quoted literal string expression.
1247    pub fn string(s: impl Into<String>) -> Self {
1248        Expression::Literal(Box::new(Literal::String(s.into())))
1249    }
1250
1251    /// Create a literal number expression from a float.
1252    pub fn float(f: f64) -> Self {
1253        Expression::Literal(Box::new(Literal::Number(f.to_string())))
1254    }
1255
1256    /// Get the inferred type annotation, if present.
1257    ///
1258    /// For value-producing expressions with an `inferred_type` field, returns
1259    /// the stored type. For literals and boolean constants, computes the type
1260    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1261    pub fn inferred_type(&self) -> Option<&DataType> {
1262        match self {
1263            // Structs with inferred_type field
1264            Expression::And(op)
1265            | Expression::Or(op)
1266            | Expression::Add(op)
1267            | Expression::Sub(op)
1268            | Expression::Mul(op)
1269            | Expression::Div(op)
1270            | Expression::Mod(op)
1271            | Expression::Eq(op)
1272            | Expression::Neq(op)
1273            | Expression::Lt(op)
1274            | Expression::Lte(op)
1275            | Expression::Gt(op)
1276            | Expression::Gte(op)
1277            | Expression::Concat(op)
1278            | Expression::BitwiseAnd(op)
1279            | Expression::BitwiseOr(op)
1280            | Expression::BitwiseXor(op)
1281            | Expression::Adjacent(op)
1282            | Expression::TsMatch(op)
1283            | Expression::PropertyEQ(op)
1284            | Expression::ArrayContainsAll(op)
1285            | Expression::ArrayContainedBy(op)
1286            | Expression::ArrayOverlaps(op)
1287            | Expression::JSONBContainsAllTopKeys(op)
1288            | Expression::JSONBContainsAnyTopKeys(op)
1289            | Expression::JSONBDeleteAtPath(op)
1290            | Expression::ExtendsLeft(op)
1291            | Expression::ExtendsRight(op)
1292            | Expression::Is(op)
1293            | Expression::MemberOf(op)
1294            | Expression::Match(op)
1295            | Expression::NullSafeEq(op)
1296            | Expression::NullSafeNeq(op)
1297            | Expression::Glob(op)
1298            | Expression::BitwiseLeftShift(op)
1299            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1300
1301            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1302                op.inferred_type.as_ref()
1303            }
1304
1305            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1306
1307            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1308                c.inferred_type.as_ref()
1309            }
1310
1311            Expression::Column(c) => c.inferred_type.as_ref(),
1312            Expression::Function(f) => f.inferred_type.as_ref(),
1313            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1314            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1315            Expression::Case(c) => c.inferred_type.as_ref(),
1316            Expression::Subquery(s) => s.inferred_type.as_ref(),
1317            Expression::Alias(a) => a.inferred_type.as_ref(),
1318            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1319            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1320            Expression::Count(f) => f.inferred_type.as_ref(),
1321            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1322            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1323            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1324            Expression::SumIf(f) => f.inferred_type.as_ref(),
1325
1326            // UnaryFunc variants
1327            Expression::Upper(f)
1328            | Expression::Lower(f)
1329            | Expression::Length(f)
1330            | Expression::LTrim(f)
1331            | Expression::RTrim(f)
1332            | Expression::Reverse(f)
1333            | Expression::Abs(f)
1334            | Expression::Sqrt(f)
1335            | Expression::Cbrt(f)
1336            | Expression::Ln(f)
1337            | Expression::Exp(f)
1338            | Expression::Sign(f)
1339            | Expression::Date(f)
1340            | Expression::Time(f)
1341            | Expression::Initcap(f)
1342            | Expression::Ascii(f)
1343            | Expression::Chr(f)
1344            | Expression::Soundex(f)
1345            | Expression::ByteLength(f)
1346            | Expression::Hex(f)
1347            | Expression::LowerHex(f)
1348            | Expression::Unicode(f)
1349            | Expression::Typeof(f)
1350            | Expression::Explode(f)
1351            | Expression::ExplodeOuter(f)
1352            | Expression::MapFromEntries(f)
1353            | Expression::MapKeys(f)
1354            | Expression::MapValues(f)
1355            | Expression::ArrayLength(f)
1356            | Expression::ArraySize(f)
1357            | Expression::Cardinality(f)
1358            | Expression::ArrayReverse(f)
1359            | Expression::ArrayDistinct(f)
1360            | Expression::ArrayFlatten(f)
1361            | Expression::ArrayCompact(f)
1362            | Expression::ToArray(f)
1363            | Expression::JsonArrayLength(f)
1364            | Expression::JsonKeys(f)
1365            | Expression::JsonType(f)
1366            | Expression::ParseJson(f)
1367            | Expression::ToJson(f)
1368            | Expression::Radians(f)
1369            | Expression::Degrees(f)
1370            | Expression::Sin(f)
1371            | Expression::Cos(f)
1372            | Expression::Tan(f)
1373            | Expression::Asin(f)
1374            | Expression::Acos(f)
1375            | Expression::Atan(f)
1376            | Expression::IsNan(f)
1377            | Expression::IsInf(f)
1378            | Expression::Year(f)
1379            | Expression::Month(f)
1380            | Expression::Day(f)
1381            | Expression::Hour(f)
1382            | Expression::Minute(f)
1383            | Expression::Second(f)
1384            | Expression::DayOfWeek(f)
1385            | Expression::DayOfWeekIso(f)
1386            | Expression::DayOfMonth(f)
1387            | Expression::DayOfYear(f)
1388            | Expression::WeekOfYear(f)
1389            | Expression::Quarter(f)
1390            | Expression::Epoch(f)
1391            | Expression::EpochMs(f)
1392            | Expression::BitwiseCount(f)
1393            | Expression::DateFromUnixDate(f)
1394            | Expression::UnixDate(f)
1395            | Expression::UnixSeconds(f)
1396            | Expression::UnixMillis(f)
1397            | Expression::UnixMicros(f)
1398            | Expression::TimeStrToDate(f)
1399            | Expression::DateToDi(f)
1400            | Expression::DiToDate(f)
1401            | Expression::TsOrDiToDi(f)
1402            | Expression::TsOrDsToDatetime(f)
1403            | Expression::TsOrDsToTimestamp(f)
1404            | Expression::YearOfWeek(f)
1405            | Expression::YearOfWeekIso(f)
1406            | Expression::SHA(f)
1407            | Expression::SHA1Digest(f)
1408            | Expression::TimeToUnix(f)
1409            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1410
1411            // BinaryFunc variants
1412            Expression::Power(f)
1413            | Expression::NullIf(f)
1414            | Expression::IfNull(f)
1415            | Expression::Nvl(f)
1416            | Expression::Contains(f)
1417            | Expression::StartsWith(f)
1418            | Expression::EndsWith(f)
1419            | Expression::Levenshtein(f)
1420            | Expression::ModFunc(f)
1421            | Expression::IntDiv(f)
1422            | Expression::Atan2(f)
1423            | Expression::AddMonths(f)
1424            | Expression::MonthsBetween(f)
1425            | Expression::NextDay(f)
1426            | Expression::UnixToTimeStr(f)
1427            | Expression::ArrayContains(f)
1428            | Expression::ArrayPosition(f)
1429            | Expression::ArrayAppend(f)
1430            | Expression::ArrayPrepend(f)
1431            | Expression::ArrayUnion(f)
1432            | Expression::ArrayExcept(f)
1433            | Expression::ArrayRemove(f)
1434            | Expression::StarMap(f)
1435            | Expression::MapFromArrays(f)
1436            | Expression::MapContainsKey(f)
1437            | Expression::ElementAt(f)
1438            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1439
1440            // VarArgFunc variants
1441            Expression::Coalesce(f)
1442            | Expression::Greatest(f)
1443            | Expression::Least(f)
1444            | Expression::ArrayConcat(f)
1445            | Expression::ArrayIntersect(f)
1446            | Expression::ArrayZip(f)
1447            | Expression::MapConcat(f)
1448            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1449
1450            // AggFunc variants
1451            Expression::Sum(f)
1452            | Expression::Avg(f)
1453            | Expression::Min(f)
1454            | Expression::Max(f)
1455            | Expression::ArrayAgg(f)
1456            | Expression::CountIf(f)
1457            | Expression::Stddev(f)
1458            | Expression::StddevPop(f)
1459            | Expression::StddevSamp(f)
1460            | Expression::Variance(f)
1461            | Expression::VarPop(f)
1462            | Expression::VarSamp(f)
1463            | Expression::Median(f)
1464            | Expression::Mode(f)
1465            | Expression::First(f)
1466            | Expression::Last(f)
1467            | Expression::AnyValue(f)
1468            | Expression::ApproxDistinct(f)
1469            | Expression::ApproxCountDistinct(f)
1470            | Expression::LogicalAnd(f)
1471            | Expression::LogicalOr(f)
1472            | Expression::Skewness(f)
1473            | Expression::ArrayConcatAgg(f)
1474            | Expression::ArrayUniqueAgg(f)
1475            | Expression::BoolXorAgg(f)
1476            | Expression::BitwiseAndAgg(f)
1477            | Expression::BitwiseOrAgg(f)
1478            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1479
1480            // Everything else: no inferred_type field
1481            _ => None,
1482        }
1483    }
1484
1485    /// Set the inferred type annotation on this expression.
1486    ///
1487    /// Only has an effect on value-producing expressions with an `inferred_type`
1488    /// field. For other expression types, this is a no-op.
1489    pub fn set_inferred_type(&mut self, dt: DataType) {
1490        match self {
1491            Expression::And(op)
1492            | Expression::Or(op)
1493            | Expression::Add(op)
1494            | Expression::Sub(op)
1495            | Expression::Mul(op)
1496            | Expression::Div(op)
1497            | Expression::Mod(op)
1498            | Expression::Eq(op)
1499            | Expression::Neq(op)
1500            | Expression::Lt(op)
1501            | Expression::Lte(op)
1502            | Expression::Gt(op)
1503            | Expression::Gte(op)
1504            | Expression::Concat(op)
1505            | Expression::BitwiseAnd(op)
1506            | Expression::BitwiseOr(op)
1507            | Expression::BitwiseXor(op)
1508            | Expression::Adjacent(op)
1509            | Expression::TsMatch(op)
1510            | Expression::PropertyEQ(op)
1511            | Expression::ArrayContainsAll(op)
1512            | Expression::ArrayContainedBy(op)
1513            | Expression::ArrayOverlaps(op)
1514            | Expression::JSONBContainsAllTopKeys(op)
1515            | Expression::JSONBContainsAnyTopKeys(op)
1516            | Expression::JSONBDeleteAtPath(op)
1517            | Expression::ExtendsLeft(op)
1518            | Expression::ExtendsRight(op)
1519            | Expression::Is(op)
1520            | Expression::MemberOf(op)
1521            | Expression::Match(op)
1522            | Expression::NullSafeEq(op)
1523            | Expression::NullSafeNeq(op)
1524            | Expression::Glob(op)
1525            | Expression::BitwiseLeftShift(op)
1526            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1527
1528            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1529                op.inferred_type = Some(dt)
1530            }
1531
1532            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1533
1534            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1535                c.inferred_type = Some(dt)
1536            }
1537
1538            Expression::Column(c) => c.inferred_type = Some(dt),
1539            Expression::Function(f) => f.inferred_type = Some(dt),
1540            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1541            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1542            Expression::Case(c) => c.inferred_type = Some(dt),
1543            Expression::Subquery(s) => s.inferred_type = Some(dt),
1544            Expression::Alias(a) => a.inferred_type = Some(dt),
1545            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1546            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1547            Expression::Count(f) => f.inferred_type = Some(dt),
1548            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1549            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1550            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1551            Expression::SumIf(f) => f.inferred_type = Some(dt),
1552
1553            // UnaryFunc variants
1554            Expression::Upper(f)
1555            | Expression::Lower(f)
1556            | Expression::Length(f)
1557            | Expression::LTrim(f)
1558            | Expression::RTrim(f)
1559            | Expression::Reverse(f)
1560            | Expression::Abs(f)
1561            | Expression::Sqrt(f)
1562            | Expression::Cbrt(f)
1563            | Expression::Ln(f)
1564            | Expression::Exp(f)
1565            | Expression::Sign(f)
1566            | Expression::Date(f)
1567            | Expression::Time(f)
1568            | Expression::Initcap(f)
1569            | Expression::Ascii(f)
1570            | Expression::Chr(f)
1571            | Expression::Soundex(f)
1572            | Expression::ByteLength(f)
1573            | Expression::Hex(f)
1574            | Expression::LowerHex(f)
1575            | Expression::Unicode(f)
1576            | Expression::Typeof(f)
1577            | Expression::Explode(f)
1578            | Expression::ExplodeOuter(f)
1579            | Expression::MapFromEntries(f)
1580            | Expression::MapKeys(f)
1581            | Expression::MapValues(f)
1582            | Expression::ArrayLength(f)
1583            | Expression::ArraySize(f)
1584            | Expression::Cardinality(f)
1585            | Expression::ArrayReverse(f)
1586            | Expression::ArrayDistinct(f)
1587            | Expression::ArrayFlatten(f)
1588            | Expression::ArrayCompact(f)
1589            | Expression::ToArray(f)
1590            | Expression::JsonArrayLength(f)
1591            | Expression::JsonKeys(f)
1592            | Expression::JsonType(f)
1593            | Expression::ParseJson(f)
1594            | Expression::ToJson(f)
1595            | Expression::Radians(f)
1596            | Expression::Degrees(f)
1597            | Expression::Sin(f)
1598            | Expression::Cos(f)
1599            | Expression::Tan(f)
1600            | Expression::Asin(f)
1601            | Expression::Acos(f)
1602            | Expression::Atan(f)
1603            | Expression::IsNan(f)
1604            | Expression::IsInf(f)
1605            | Expression::Year(f)
1606            | Expression::Month(f)
1607            | Expression::Day(f)
1608            | Expression::Hour(f)
1609            | Expression::Minute(f)
1610            | Expression::Second(f)
1611            | Expression::DayOfWeek(f)
1612            | Expression::DayOfWeekIso(f)
1613            | Expression::DayOfMonth(f)
1614            | Expression::DayOfYear(f)
1615            | Expression::WeekOfYear(f)
1616            | Expression::Quarter(f)
1617            | Expression::Epoch(f)
1618            | Expression::EpochMs(f)
1619            | Expression::BitwiseCount(f)
1620            | Expression::DateFromUnixDate(f)
1621            | Expression::UnixDate(f)
1622            | Expression::UnixSeconds(f)
1623            | Expression::UnixMillis(f)
1624            | Expression::UnixMicros(f)
1625            | Expression::TimeStrToDate(f)
1626            | Expression::DateToDi(f)
1627            | Expression::DiToDate(f)
1628            | Expression::TsOrDiToDi(f)
1629            | Expression::TsOrDsToDatetime(f)
1630            | Expression::TsOrDsToTimestamp(f)
1631            | Expression::YearOfWeek(f)
1632            | Expression::YearOfWeekIso(f)
1633            | Expression::SHA(f)
1634            | Expression::SHA1Digest(f)
1635            | Expression::TimeToUnix(f)
1636            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1637
1638            // BinaryFunc variants
1639            Expression::Power(f)
1640            | Expression::NullIf(f)
1641            | Expression::IfNull(f)
1642            | Expression::Nvl(f)
1643            | Expression::Contains(f)
1644            | Expression::StartsWith(f)
1645            | Expression::EndsWith(f)
1646            | Expression::Levenshtein(f)
1647            | Expression::ModFunc(f)
1648            | Expression::IntDiv(f)
1649            | Expression::Atan2(f)
1650            | Expression::AddMonths(f)
1651            | Expression::MonthsBetween(f)
1652            | Expression::NextDay(f)
1653            | Expression::UnixToTimeStr(f)
1654            | Expression::ArrayContains(f)
1655            | Expression::ArrayPosition(f)
1656            | Expression::ArrayAppend(f)
1657            | Expression::ArrayPrepend(f)
1658            | Expression::ArrayUnion(f)
1659            | Expression::ArrayExcept(f)
1660            | Expression::ArrayRemove(f)
1661            | Expression::StarMap(f)
1662            | Expression::MapFromArrays(f)
1663            | Expression::MapContainsKey(f)
1664            | Expression::ElementAt(f)
1665            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1666
1667            // VarArgFunc variants
1668            Expression::Coalesce(f)
1669            | Expression::Greatest(f)
1670            | Expression::Least(f)
1671            | Expression::ArrayConcat(f)
1672            | Expression::ArrayIntersect(f)
1673            | Expression::ArrayZip(f)
1674            | Expression::MapConcat(f)
1675            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1676
1677            // AggFunc variants
1678            Expression::Sum(f)
1679            | Expression::Avg(f)
1680            | Expression::Min(f)
1681            | Expression::Max(f)
1682            | Expression::ArrayAgg(f)
1683            | Expression::CountIf(f)
1684            | Expression::Stddev(f)
1685            | Expression::StddevPop(f)
1686            | Expression::StddevSamp(f)
1687            | Expression::Variance(f)
1688            | Expression::VarPop(f)
1689            | Expression::VarSamp(f)
1690            | Expression::Median(f)
1691            | Expression::Mode(f)
1692            | Expression::First(f)
1693            | Expression::Last(f)
1694            | Expression::AnyValue(f)
1695            | Expression::ApproxDistinct(f)
1696            | Expression::ApproxCountDistinct(f)
1697            | Expression::LogicalAnd(f)
1698            | Expression::LogicalOr(f)
1699            | Expression::Skewness(f)
1700            | Expression::ArrayConcatAgg(f)
1701            | Expression::ArrayUniqueAgg(f)
1702            | Expression::BoolXorAgg(f)
1703            | Expression::BitwiseAndAgg(f)
1704            | Expression::BitwiseOrAgg(f)
1705            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1706
1707            // Expressions without inferred_type field - no-op
1708            _ => {}
1709        }
1710    }
1711
1712    /// Create an unqualified column reference (e.g. `name`).
1713    pub fn column(name: impl Into<String>) -> Self {
1714        Expression::Column(Box::new(Column {
1715            name: Identifier::new(name),
1716            table: None,
1717            join_mark: false,
1718            trailing_comments: Vec::new(),
1719            span: None,
1720            inferred_type: None,
1721        }))
1722    }
1723
1724    /// Create a qualified column reference (`table.column`).
1725    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1726        Expression::Column(Box::new(Column {
1727            name: Identifier::new(column),
1728            table: Some(Identifier::new(table)),
1729            join_mark: false,
1730            trailing_comments: Vec::new(),
1731            span: None,
1732            inferred_type: None,
1733        }))
1734    }
1735
1736    /// Create a bare identifier expression (not a column reference).
1737    pub fn identifier(name: impl Into<String>) -> Self {
1738        Expression::Identifier(Identifier::new(name))
1739    }
1740
1741    /// Create a NULL expression
1742    pub fn null() -> Self {
1743        Expression::Null(Null)
1744    }
1745
1746    /// Create a TRUE expression
1747    pub fn true_() -> Self {
1748        Expression::Boolean(BooleanLiteral { value: true })
1749    }
1750
1751    /// Create a FALSE expression
1752    pub fn false_() -> Self {
1753        Expression::Boolean(BooleanLiteral { value: false })
1754    }
1755
1756    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1757    pub fn star() -> Self {
1758        Expression::Star(Star {
1759            table: None,
1760            except: None,
1761            replace: None,
1762            rename: None,
1763            trailing_comments: Vec::new(),
1764            span: None,
1765        })
1766    }
1767
1768    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1769    pub fn alias(self, name: impl Into<String>) -> Self {
1770        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1771    }
1772
1773    /// Check if this is a SELECT expression
1774    pub fn is_select(&self) -> bool {
1775        matches!(self, Expression::Select(_))
1776    }
1777
1778    /// Try to get as a Select
1779    pub fn as_select(&self) -> Option<&Select> {
1780        match self {
1781            Expression::Select(s) => Some(s),
1782            _ => None,
1783        }
1784    }
1785
1786    /// Try to get as a mutable Select
1787    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1788        match self {
1789            Expression::Select(s) => Some(s),
1790            _ => None,
1791        }
1792    }
1793
1794    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1795    ///
1796    /// Returns an empty string if generation fails. For dialect-specific output,
1797    /// use [`sql_for()`](Self::sql_for) instead.
1798    pub fn sql(&self) -> String {
1799        crate::generator::Generator::sql(self).unwrap_or_default()
1800    }
1801
1802    /// Generate a SQL string for this expression targeting a specific dialect.
1803    ///
1804    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1805    /// syntax variations) are applied automatically.  Returns an empty string if
1806    /// generation fails.
1807    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1808        crate::generate(self, dialect).unwrap_or_default()
1809    }
1810}
1811
1812// === Python API accessor methods ===
1813
1814impl Expression {
1815    /// Returns the serde-compatible snake_case variant name without serialization.
1816    /// This is much faster than serializing to JSON and extracting the key.
1817    pub fn variant_name(&self) -> &'static str {
1818        match self {
1819            Expression::Literal(_) => "literal",
1820            Expression::Boolean(_) => "boolean",
1821            Expression::Null(_) => "null",
1822            Expression::Identifier(_) => "identifier",
1823            Expression::Column(_) => "column",
1824            Expression::Table(_) => "table",
1825            Expression::Star(_) => "star",
1826            Expression::BracedWildcard(_) => "braced_wildcard",
1827            Expression::Select(_) => "select",
1828            Expression::Union(_) => "union",
1829            Expression::Intersect(_) => "intersect",
1830            Expression::Except(_) => "except",
1831            Expression::Subquery(_) => "subquery",
1832            Expression::PipeOperator(_) => "pipe_operator",
1833            Expression::Pivot(_) => "pivot",
1834            Expression::PivotAlias(_) => "pivot_alias",
1835            Expression::Unpivot(_) => "unpivot",
1836            Expression::Values(_) => "values",
1837            Expression::PreWhere(_) => "pre_where",
1838            Expression::Stream(_) => "stream",
1839            Expression::UsingData(_) => "using_data",
1840            Expression::XmlNamespace(_) => "xml_namespace",
1841            Expression::Insert(_) => "insert",
1842            Expression::Update(_) => "update",
1843            Expression::Delete(_) => "delete",
1844            Expression::Copy(_) => "copy",
1845            Expression::Put(_) => "put",
1846            Expression::StageReference(_) => "stage_reference",
1847            Expression::Alias(_) => "alias",
1848            Expression::Cast(_) => "cast",
1849            Expression::Collation(_) => "collation",
1850            Expression::Case(_) => "case",
1851            Expression::And(_) => "and",
1852            Expression::Or(_) => "or",
1853            Expression::Add(_) => "add",
1854            Expression::Sub(_) => "sub",
1855            Expression::Mul(_) => "mul",
1856            Expression::Div(_) => "div",
1857            Expression::Mod(_) => "mod",
1858            Expression::Eq(_) => "eq",
1859            Expression::Neq(_) => "neq",
1860            Expression::Lt(_) => "lt",
1861            Expression::Lte(_) => "lte",
1862            Expression::Gt(_) => "gt",
1863            Expression::Gte(_) => "gte",
1864            Expression::Like(_) => "like",
1865            Expression::ILike(_) => "i_like",
1866            Expression::Match(_) => "match",
1867            Expression::BitwiseAnd(_) => "bitwise_and",
1868            Expression::BitwiseOr(_) => "bitwise_or",
1869            Expression::BitwiseXor(_) => "bitwise_xor",
1870            Expression::Concat(_) => "concat",
1871            Expression::Adjacent(_) => "adjacent",
1872            Expression::TsMatch(_) => "ts_match",
1873            Expression::PropertyEQ(_) => "property_e_q",
1874            Expression::ArrayContainsAll(_) => "array_contains_all",
1875            Expression::ArrayContainedBy(_) => "array_contained_by",
1876            Expression::ArrayOverlaps(_) => "array_overlaps",
1877            Expression::JSONBContainsAllTopKeys(_) => "j_s_o_n_b_contains_all_top_keys",
1878            Expression::JSONBContainsAnyTopKeys(_) => "j_s_o_n_b_contains_any_top_keys",
1879            Expression::JSONBDeleteAtPath(_) => "j_s_o_n_b_delete_at_path",
1880            Expression::ExtendsLeft(_) => "extends_left",
1881            Expression::ExtendsRight(_) => "extends_right",
1882            Expression::Not(_) => "not",
1883            Expression::Neg(_) => "neg",
1884            Expression::BitwiseNot(_) => "bitwise_not",
1885            Expression::In(_) => "in",
1886            Expression::Between(_) => "between",
1887            Expression::IsNull(_) => "is_null",
1888            Expression::IsTrue(_) => "is_true",
1889            Expression::IsFalse(_) => "is_false",
1890            Expression::IsJson(_) => "is_json",
1891            Expression::Is(_) => "is",
1892            Expression::Exists(_) => "exists",
1893            Expression::MemberOf(_) => "member_of",
1894            Expression::Function(_) => "function",
1895            Expression::AggregateFunction(_) => "aggregate_function",
1896            Expression::WindowFunction(_) => "window_function",
1897            Expression::From(_) => "from",
1898            Expression::Join(_) => "join",
1899            Expression::JoinedTable(_) => "joined_table",
1900            Expression::Where(_) => "where",
1901            Expression::GroupBy(_) => "group_by",
1902            Expression::Having(_) => "having",
1903            Expression::OrderBy(_) => "order_by",
1904            Expression::Limit(_) => "limit",
1905            Expression::Offset(_) => "offset",
1906            Expression::Qualify(_) => "qualify",
1907            Expression::With(_) => "with",
1908            Expression::Cte(_) => "cte",
1909            Expression::DistributeBy(_) => "distribute_by",
1910            Expression::ClusterBy(_) => "cluster_by",
1911            Expression::SortBy(_) => "sort_by",
1912            Expression::LateralView(_) => "lateral_view",
1913            Expression::Hint(_) => "hint",
1914            Expression::Pseudocolumn(_) => "pseudocolumn",
1915            Expression::Connect(_) => "connect",
1916            Expression::Prior(_) => "prior",
1917            Expression::ConnectByRoot(_) => "connect_by_root",
1918            Expression::MatchRecognize(_) => "match_recognize",
1919            Expression::Ordered(_) => "ordered",
1920            Expression::Window(_) => "window",
1921            Expression::Over(_) => "over",
1922            Expression::WithinGroup(_) => "within_group",
1923            Expression::DataType(_) => "data_type",
1924            Expression::Array(_) => "array",
1925            Expression::Struct(_) => "struct",
1926            Expression::Tuple(_) => "tuple",
1927            Expression::Interval(_) => "interval",
1928            Expression::ConcatWs(_) => "concat_ws",
1929            Expression::Substring(_) => "substring",
1930            Expression::Upper(_) => "upper",
1931            Expression::Lower(_) => "lower",
1932            Expression::Length(_) => "length",
1933            Expression::Trim(_) => "trim",
1934            Expression::LTrim(_) => "l_trim",
1935            Expression::RTrim(_) => "r_trim",
1936            Expression::Replace(_) => "replace",
1937            Expression::Reverse(_) => "reverse",
1938            Expression::Left(_) => "left",
1939            Expression::Right(_) => "right",
1940            Expression::Repeat(_) => "repeat",
1941            Expression::Lpad(_) => "lpad",
1942            Expression::Rpad(_) => "rpad",
1943            Expression::Split(_) => "split",
1944            Expression::RegexpLike(_) => "regexp_like",
1945            Expression::RegexpReplace(_) => "regexp_replace",
1946            Expression::RegexpExtract(_) => "regexp_extract",
1947            Expression::Overlay(_) => "overlay",
1948            Expression::Abs(_) => "abs",
1949            Expression::Round(_) => "round",
1950            Expression::Floor(_) => "floor",
1951            Expression::Ceil(_) => "ceil",
1952            Expression::Power(_) => "power",
1953            Expression::Sqrt(_) => "sqrt",
1954            Expression::Cbrt(_) => "cbrt",
1955            Expression::Ln(_) => "ln",
1956            Expression::Log(_) => "log",
1957            Expression::Exp(_) => "exp",
1958            Expression::Sign(_) => "sign",
1959            Expression::Greatest(_) => "greatest",
1960            Expression::Least(_) => "least",
1961            Expression::CurrentDate(_) => "current_date",
1962            Expression::CurrentTime(_) => "current_time",
1963            Expression::CurrentTimestamp(_) => "current_timestamp",
1964            Expression::CurrentTimestampLTZ(_) => "current_timestamp_l_t_z",
1965            Expression::AtTimeZone(_) => "at_time_zone",
1966            Expression::DateAdd(_) => "date_add",
1967            Expression::DateSub(_) => "date_sub",
1968            Expression::DateDiff(_) => "date_diff",
1969            Expression::DateTrunc(_) => "date_trunc",
1970            Expression::Extract(_) => "extract",
1971            Expression::ToDate(_) => "to_date",
1972            Expression::ToTimestamp(_) => "to_timestamp",
1973            Expression::Date(_) => "date",
1974            Expression::Time(_) => "time",
1975            Expression::DateFromUnixDate(_) => "date_from_unix_date",
1976            Expression::UnixDate(_) => "unix_date",
1977            Expression::UnixSeconds(_) => "unix_seconds",
1978            Expression::UnixMillis(_) => "unix_millis",
1979            Expression::UnixMicros(_) => "unix_micros",
1980            Expression::UnixToTimeStr(_) => "unix_to_time_str",
1981            Expression::TimeStrToDate(_) => "time_str_to_date",
1982            Expression::DateToDi(_) => "date_to_di",
1983            Expression::DiToDate(_) => "di_to_date",
1984            Expression::TsOrDiToDi(_) => "ts_or_di_to_di",
1985            Expression::TsOrDsToDatetime(_) => "ts_or_ds_to_datetime",
1986            Expression::TsOrDsToTimestamp(_) => "ts_or_ds_to_timestamp",
1987            Expression::YearOfWeek(_) => "year_of_week",
1988            Expression::YearOfWeekIso(_) => "year_of_week_iso",
1989            Expression::Coalesce(_) => "coalesce",
1990            Expression::NullIf(_) => "null_if",
1991            Expression::IfFunc(_) => "if_func",
1992            Expression::IfNull(_) => "if_null",
1993            Expression::Nvl(_) => "nvl",
1994            Expression::Nvl2(_) => "nvl2",
1995            Expression::TryCast(_) => "try_cast",
1996            Expression::SafeCast(_) => "safe_cast",
1997            Expression::Count(_) => "count",
1998            Expression::Sum(_) => "sum",
1999            Expression::Avg(_) => "avg",
2000            Expression::Min(_) => "min",
2001            Expression::Max(_) => "max",
2002            Expression::GroupConcat(_) => "group_concat",
2003            Expression::StringAgg(_) => "string_agg",
2004            Expression::ListAgg(_) => "list_agg",
2005            Expression::ArrayAgg(_) => "array_agg",
2006            Expression::CountIf(_) => "count_if",
2007            Expression::SumIf(_) => "sum_if",
2008            Expression::Stddev(_) => "stddev",
2009            Expression::StddevPop(_) => "stddev_pop",
2010            Expression::StddevSamp(_) => "stddev_samp",
2011            Expression::Variance(_) => "variance",
2012            Expression::VarPop(_) => "var_pop",
2013            Expression::VarSamp(_) => "var_samp",
2014            Expression::Median(_) => "median",
2015            Expression::Mode(_) => "mode",
2016            Expression::First(_) => "first",
2017            Expression::Last(_) => "last",
2018            Expression::AnyValue(_) => "any_value",
2019            Expression::ApproxDistinct(_) => "approx_distinct",
2020            Expression::ApproxCountDistinct(_) => "approx_count_distinct",
2021            Expression::ApproxPercentile(_) => "approx_percentile",
2022            Expression::Percentile(_) => "percentile",
2023            Expression::LogicalAnd(_) => "logical_and",
2024            Expression::LogicalOr(_) => "logical_or",
2025            Expression::Skewness(_) => "skewness",
2026            Expression::BitwiseCount(_) => "bitwise_count",
2027            Expression::ArrayConcatAgg(_) => "array_concat_agg",
2028            Expression::ArrayUniqueAgg(_) => "array_unique_agg",
2029            Expression::BoolXorAgg(_) => "bool_xor_agg",
2030            Expression::RowNumber(_) => "row_number",
2031            Expression::Rank(_) => "rank",
2032            Expression::DenseRank(_) => "dense_rank",
2033            Expression::NTile(_) => "n_tile",
2034            Expression::Lead(_) => "lead",
2035            Expression::Lag(_) => "lag",
2036            Expression::FirstValue(_) => "first_value",
2037            Expression::LastValue(_) => "last_value",
2038            Expression::NthValue(_) => "nth_value",
2039            Expression::PercentRank(_) => "percent_rank",
2040            Expression::CumeDist(_) => "cume_dist",
2041            Expression::PercentileCont(_) => "percentile_cont",
2042            Expression::PercentileDisc(_) => "percentile_disc",
2043            Expression::Contains(_) => "contains",
2044            Expression::StartsWith(_) => "starts_with",
2045            Expression::EndsWith(_) => "ends_with",
2046            Expression::Position(_) => "position",
2047            Expression::Initcap(_) => "initcap",
2048            Expression::Ascii(_) => "ascii",
2049            Expression::Chr(_) => "chr",
2050            Expression::CharFunc(_) => "char_func",
2051            Expression::Soundex(_) => "soundex",
2052            Expression::Levenshtein(_) => "levenshtein",
2053            Expression::ByteLength(_) => "byte_length",
2054            Expression::Hex(_) => "hex",
2055            Expression::LowerHex(_) => "lower_hex",
2056            Expression::Unicode(_) => "unicode",
2057            Expression::ModFunc(_) => "mod_func",
2058            Expression::Random(_) => "random",
2059            Expression::Rand(_) => "rand",
2060            Expression::TruncFunc(_) => "trunc_func",
2061            Expression::Pi(_) => "pi",
2062            Expression::Radians(_) => "radians",
2063            Expression::Degrees(_) => "degrees",
2064            Expression::Sin(_) => "sin",
2065            Expression::Cos(_) => "cos",
2066            Expression::Tan(_) => "tan",
2067            Expression::Asin(_) => "asin",
2068            Expression::Acos(_) => "acos",
2069            Expression::Atan(_) => "atan",
2070            Expression::Atan2(_) => "atan2",
2071            Expression::IsNan(_) => "is_nan",
2072            Expression::IsInf(_) => "is_inf",
2073            Expression::IntDiv(_) => "int_div",
2074            Expression::Decode(_) => "decode",
2075            Expression::DateFormat(_) => "date_format",
2076            Expression::FormatDate(_) => "format_date",
2077            Expression::Year(_) => "year",
2078            Expression::Month(_) => "month",
2079            Expression::Day(_) => "day",
2080            Expression::Hour(_) => "hour",
2081            Expression::Minute(_) => "minute",
2082            Expression::Second(_) => "second",
2083            Expression::DayOfWeek(_) => "day_of_week",
2084            Expression::DayOfWeekIso(_) => "day_of_week_iso",
2085            Expression::DayOfMonth(_) => "day_of_month",
2086            Expression::DayOfYear(_) => "day_of_year",
2087            Expression::WeekOfYear(_) => "week_of_year",
2088            Expression::Quarter(_) => "quarter",
2089            Expression::AddMonths(_) => "add_months",
2090            Expression::MonthsBetween(_) => "months_between",
2091            Expression::LastDay(_) => "last_day",
2092            Expression::NextDay(_) => "next_day",
2093            Expression::Epoch(_) => "epoch",
2094            Expression::EpochMs(_) => "epoch_ms",
2095            Expression::FromUnixtime(_) => "from_unixtime",
2096            Expression::UnixTimestamp(_) => "unix_timestamp",
2097            Expression::MakeDate(_) => "make_date",
2098            Expression::MakeTimestamp(_) => "make_timestamp",
2099            Expression::TimestampTrunc(_) => "timestamp_trunc",
2100            Expression::TimeStrToUnix(_) => "time_str_to_unix",
2101            Expression::SessionUser(_) => "session_user",
2102            Expression::SHA(_) => "s_h_a",
2103            Expression::SHA1Digest(_) => "s_h_a1_digest",
2104            Expression::TimeToUnix(_) => "time_to_unix",
2105            Expression::ArrayFunc(_) => "array_func",
2106            Expression::ArrayLength(_) => "array_length",
2107            Expression::ArraySize(_) => "array_size",
2108            Expression::Cardinality(_) => "cardinality",
2109            Expression::ArrayContains(_) => "array_contains",
2110            Expression::ArrayPosition(_) => "array_position",
2111            Expression::ArrayAppend(_) => "array_append",
2112            Expression::ArrayPrepend(_) => "array_prepend",
2113            Expression::ArrayConcat(_) => "array_concat",
2114            Expression::ArraySort(_) => "array_sort",
2115            Expression::ArrayReverse(_) => "array_reverse",
2116            Expression::ArrayDistinct(_) => "array_distinct",
2117            Expression::ArrayJoin(_) => "array_join",
2118            Expression::ArrayToString(_) => "array_to_string",
2119            Expression::Unnest(_) => "unnest",
2120            Expression::Explode(_) => "explode",
2121            Expression::ExplodeOuter(_) => "explode_outer",
2122            Expression::ArrayFilter(_) => "array_filter",
2123            Expression::ArrayTransform(_) => "array_transform",
2124            Expression::ArrayFlatten(_) => "array_flatten",
2125            Expression::ArrayCompact(_) => "array_compact",
2126            Expression::ArrayIntersect(_) => "array_intersect",
2127            Expression::ArrayUnion(_) => "array_union",
2128            Expression::ArrayExcept(_) => "array_except",
2129            Expression::ArrayRemove(_) => "array_remove",
2130            Expression::ArrayZip(_) => "array_zip",
2131            Expression::Sequence(_) => "sequence",
2132            Expression::Generate(_) => "generate",
2133            Expression::ExplodingGenerateSeries(_) => "exploding_generate_series",
2134            Expression::ToArray(_) => "to_array",
2135            Expression::StarMap(_) => "star_map",
2136            Expression::StructFunc(_) => "struct_func",
2137            Expression::StructExtract(_) => "struct_extract",
2138            Expression::NamedStruct(_) => "named_struct",
2139            Expression::MapFunc(_) => "map_func",
2140            Expression::MapFromEntries(_) => "map_from_entries",
2141            Expression::MapFromArrays(_) => "map_from_arrays",
2142            Expression::MapKeys(_) => "map_keys",
2143            Expression::MapValues(_) => "map_values",
2144            Expression::MapContainsKey(_) => "map_contains_key",
2145            Expression::MapConcat(_) => "map_concat",
2146            Expression::ElementAt(_) => "element_at",
2147            Expression::TransformKeys(_) => "transform_keys",
2148            Expression::TransformValues(_) => "transform_values",
2149            Expression::FunctionEmits(_) => "function_emits",
2150            Expression::JsonExtract(_) => "json_extract",
2151            Expression::JsonExtractScalar(_) => "json_extract_scalar",
2152            Expression::JsonExtractPath(_) => "json_extract_path",
2153            Expression::JsonArray(_) => "json_array",
2154            Expression::JsonObject(_) => "json_object",
2155            Expression::JsonQuery(_) => "json_query",
2156            Expression::JsonValue(_) => "json_value",
2157            Expression::JsonArrayLength(_) => "json_array_length",
2158            Expression::JsonKeys(_) => "json_keys",
2159            Expression::JsonType(_) => "json_type",
2160            Expression::ParseJson(_) => "parse_json",
2161            Expression::ToJson(_) => "to_json",
2162            Expression::JsonSet(_) => "json_set",
2163            Expression::JsonInsert(_) => "json_insert",
2164            Expression::JsonRemove(_) => "json_remove",
2165            Expression::JsonMergePatch(_) => "json_merge_patch",
2166            Expression::JsonArrayAgg(_) => "json_array_agg",
2167            Expression::JsonObjectAgg(_) => "json_object_agg",
2168            Expression::Convert(_) => "convert",
2169            Expression::Typeof(_) => "typeof",
2170            Expression::Lambda(_) => "lambda",
2171            Expression::Parameter(_) => "parameter",
2172            Expression::Placeholder(_) => "placeholder",
2173            Expression::NamedArgument(_) => "named_argument",
2174            Expression::TableArgument(_) => "table_argument",
2175            Expression::SqlComment(_) => "sql_comment",
2176            Expression::NullSafeEq(_) => "null_safe_eq",
2177            Expression::NullSafeNeq(_) => "null_safe_neq",
2178            Expression::Glob(_) => "glob",
2179            Expression::SimilarTo(_) => "similar_to",
2180            Expression::Any(_) => "any",
2181            Expression::All(_) => "all",
2182            Expression::Overlaps(_) => "overlaps",
2183            Expression::BitwiseLeftShift(_) => "bitwise_left_shift",
2184            Expression::BitwiseRightShift(_) => "bitwise_right_shift",
2185            Expression::BitwiseAndAgg(_) => "bitwise_and_agg",
2186            Expression::BitwiseOrAgg(_) => "bitwise_or_agg",
2187            Expression::BitwiseXorAgg(_) => "bitwise_xor_agg",
2188            Expression::Subscript(_) => "subscript",
2189            Expression::Dot(_) => "dot",
2190            Expression::MethodCall(_) => "method_call",
2191            Expression::ArraySlice(_) => "array_slice",
2192            Expression::CreateTable(_) => "create_table",
2193            Expression::DropTable(_) => "drop_table",
2194            Expression::Undrop(_) => "undrop",
2195            Expression::AlterTable(_) => "alter_table",
2196            Expression::CreateIndex(_) => "create_index",
2197            Expression::DropIndex(_) => "drop_index",
2198            Expression::CreateView(_) => "create_view",
2199            Expression::DropView(_) => "drop_view",
2200            Expression::AlterView(_) => "alter_view",
2201            Expression::AlterIndex(_) => "alter_index",
2202            Expression::Truncate(_) => "truncate",
2203            Expression::Use(_) => "use",
2204            Expression::Cache(_) => "cache",
2205            Expression::Uncache(_) => "uncache",
2206            Expression::LoadData(_) => "load_data",
2207            Expression::Pragma(_) => "pragma",
2208            Expression::Grant(_) => "grant",
2209            Expression::Revoke(_) => "revoke",
2210            Expression::Comment(_) => "comment",
2211            Expression::SetStatement(_) => "set_statement",
2212            Expression::CreateSchema(_) => "create_schema",
2213            Expression::DropSchema(_) => "drop_schema",
2214            Expression::DropNamespace(_) => "drop_namespace",
2215            Expression::CreateDatabase(_) => "create_database",
2216            Expression::DropDatabase(_) => "drop_database",
2217            Expression::CreateFunction(_) => "create_function",
2218            Expression::DropFunction(_) => "drop_function",
2219            Expression::CreateProcedure(_) => "create_procedure",
2220            Expression::DropProcedure(_) => "drop_procedure",
2221            Expression::CreateSequence(_) => "create_sequence",
2222            Expression::CreateSynonym(_) => "create_synonym",
2223            Expression::DropSequence(_) => "drop_sequence",
2224            Expression::AlterSequence(_) => "alter_sequence",
2225            Expression::CreateTrigger(_) => "create_trigger",
2226            Expression::DropTrigger(_) => "drop_trigger",
2227            Expression::CreateType(_) => "create_type",
2228            Expression::DropType(_) => "drop_type",
2229            Expression::Describe(_) => "describe",
2230            Expression::Show(_) => "show",
2231            Expression::Command(_) => "command",
2232            Expression::Kill(_) => "kill",
2233            Expression::Execute(_) => "execute",
2234            Expression::Raw(_) => "raw",
2235            Expression::CreateTask(_) => "create_task",
2236            Expression::Paren(_) => "paren",
2237            Expression::Annotated(_) => "annotated",
2238            Expression::Refresh(_) => "refresh",
2239            Expression::LockingStatement(_) => "locking_statement",
2240            Expression::SequenceProperties(_) => "sequence_properties",
2241            Expression::TruncateTable(_) => "truncate_table",
2242            Expression::Clone(_) => "clone",
2243            Expression::Attach(_) => "attach",
2244            Expression::Detach(_) => "detach",
2245            Expression::Install(_) => "install",
2246            Expression::Summarize(_) => "summarize",
2247            Expression::Declare(_) => "declare",
2248            Expression::DeclareItem(_) => "declare_item",
2249            Expression::Set(_) => "set",
2250            Expression::Heredoc(_) => "heredoc",
2251            Expression::SetItem(_) => "set_item",
2252            Expression::QueryBand(_) => "query_band",
2253            Expression::UserDefinedFunction(_) => "user_defined_function",
2254            Expression::RecursiveWithSearch(_) => "recursive_with_search",
2255            Expression::ProjectionDef(_) => "projection_def",
2256            Expression::TableAlias(_) => "table_alias",
2257            Expression::ByteString(_) => "byte_string",
2258            Expression::HexStringExpr(_) => "hex_string_expr",
2259            Expression::UnicodeString(_) => "unicode_string",
2260            Expression::ColumnPosition(_) => "column_position",
2261            Expression::ColumnDef(_) => "column_def",
2262            Expression::AlterColumn(_) => "alter_column",
2263            Expression::AlterSortKey(_) => "alter_sort_key",
2264            Expression::AlterSet(_) => "alter_set",
2265            Expression::RenameColumn(_) => "rename_column",
2266            Expression::Comprehension(_) => "comprehension",
2267            Expression::MergeTreeTTLAction(_) => "merge_tree_t_t_l_action",
2268            Expression::MergeTreeTTL(_) => "merge_tree_t_t_l",
2269            Expression::IndexConstraintOption(_) => "index_constraint_option",
2270            Expression::ColumnConstraint(_) => "column_constraint",
2271            Expression::PeriodForSystemTimeConstraint(_) => "period_for_system_time_constraint",
2272            Expression::CaseSpecificColumnConstraint(_) => "case_specific_column_constraint",
2273            Expression::CharacterSetColumnConstraint(_) => "character_set_column_constraint",
2274            Expression::CheckColumnConstraint(_) => "check_column_constraint",
2275            Expression::AssumeColumnConstraint(_) => "assume_column_constraint",
2276            Expression::CompressColumnConstraint(_) => "compress_column_constraint",
2277            Expression::DateFormatColumnConstraint(_) => "date_format_column_constraint",
2278            Expression::EphemeralColumnConstraint(_) => "ephemeral_column_constraint",
2279            Expression::WithOperator(_) => "with_operator",
2280            Expression::GeneratedAsIdentityColumnConstraint(_) => {
2281                "generated_as_identity_column_constraint"
2282            }
2283            Expression::AutoIncrementColumnConstraint(_) => "auto_increment_column_constraint",
2284            Expression::CommentColumnConstraint(_) => "comment_column_constraint",
2285            Expression::GeneratedAsRowColumnConstraint(_) => "generated_as_row_column_constraint",
2286            Expression::IndexColumnConstraint(_) => "index_column_constraint",
2287            Expression::MaskingPolicyColumnConstraint(_) => "masking_policy_column_constraint",
2288            Expression::NotNullColumnConstraint(_) => "not_null_column_constraint",
2289            Expression::PrimaryKeyColumnConstraint(_) => "primary_key_column_constraint",
2290            Expression::UniqueColumnConstraint(_) => "unique_column_constraint",
2291            Expression::WatermarkColumnConstraint(_) => "watermark_column_constraint",
2292            Expression::ComputedColumnConstraint(_) => "computed_column_constraint",
2293            Expression::InOutColumnConstraint(_) => "in_out_column_constraint",
2294            Expression::DefaultColumnConstraint(_) => "default_column_constraint",
2295            Expression::PathColumnConstraint(_) => "path_column_constraint",
2296            Expression::Constraint(_) => "constraint",
2297            Expression::Export(_) => "export",
2298            Expression::Filter(_) => "filter",
2299            Expression::Changes(_) => "changes",
2300            Expression::CopyParameter(_) => "copy_parameter",
2301            Expression::Credentials(_) => "credentials",
2302            Expression::Directory(_) => "directory",
2303            Expression::ForeignKey(_) => "foreign_key",
2304            Expression::ColumnPrefix(_) => "column_prefix",
2305            Expression::PrimaryKey(_) => "primary_key",
2306            Expression::IntoClause(_) => "into_clause",
2307            Expression::JoinHint(_) => "join_hint",
2308            Expression::Opclass(_) => "opclass",
2309            Expression::Index(_) => "index",
2310            Expression::IndexParameters(_) => "index_parameters",
2311            Expression::ConditionalInsert(_) => "conditional_insert",
2312            Expression::MultitableInserts(_) => "multitable_inserts",
2313            Expression::OnConflict(_) => "on_conflict",
2314            Expression::OnCondition(_) => "on_condition",
2315            Expression::Returning(_) => "returning",
2316            Expression::Introducer(_) => "introducer",
2317            Expression::PartitionRange(_) => "partition_range",
2318            Expression::Fetch(_) => "fetch",
2319            Expression::Group(_) => "group",
2320            Expression::Cube(_) => "cube",
2321            Expression::Rollup(_) => "rollup",
2322            Expression::GroupingSets(_) => "grouping_sets",
2323            Expression::LimitOptions(_) => "limit_options",
2324            Expression::Lateral(_) => "lateral",
2325            Expression::TableFromRows(_) => "table_from_rows",
2326            Expression::RowsFrom(_) => "rows_from",
2327            Expression::MatchRecognizeMeasure(_) => "match_recognize_measure",
2328            Expression::WithFill(_) => "with_fill",
2329            Expression::Property(_) => "property",
2330            Expression::GrantPrivilege(_) => "grant_privilege",
2331            Expression::GrantPrincipal(_) => "grant_principal",
2332            Expression::AllowedValuesProperty(_) => "allowed_values_property",
2333            Expression::AlgorithmProperty(_) => "algorithm_property",
2334            Expression::AutoIncrementProperty(_) => "auto_increment_property",
2335            Expression::AutoRefreshProperty(_) => "auto_refresh_property",
2336            Expression::BackupProperty(_) => "backup_property",
2337            Expression::BuildProperty(_) => "build_property",
2338            Expression::BlockCompressionProperty(_) => "block_compression_property",
2339            Expression::CharacterSetProperty(_) => "character_set_property",
2340            Expression::ChecksumProperty(_) => "checksum_property",
2341            Expression::CollateProperty(_) => "collate_property",
2342            Expression::DataBlocksizeProperty(_) => "data_blocksize_property",
2343            Expression::DataDeletionProperty(_) => "data_deletion_property",
2344            Expression::DefinerProperty(_) => "definer_property",
2345            Expression::DistKeyProperty(_) => "dist_key_property",
2346            Expression::DistributedByProperty(_) => "distributed_by_property",
2347            Expression::DistStyleProperty(_) => "dist_style_property",
2348            Expression::DuplicateKeyProperty(_) => "duplicate_key_property",
2349            Expression::EngineProperty(_) => "engine_property",
2350            Expression::ToTableProperty(_) => "to_table_property",
2351            Expression::ExecuteAsProperty(_) => "execute_as_property",
2352            Expression::ExternalProperty(_) => "external_property",
2353            Expression::FallbackProperty(_) => "fallback_property",
2354            Expression::FileFormatProperty(_) => "file_format_property",
2355            Expression::CredentialsProperty(_) => "credentials_property",
2356            Expression::FreespaceProperty(_) => "freespace_property",
2357            Expression::InheritsProperty(_) => "inherits_property",
2358            Expression::InputModelProperty(_) => "input_model_property",
2359            Expression::OutputModelProperty(_) => "output_model_property",
2360            Expression::IsolatedLoadingProperty(_) => "isolated_loading_property",
2361            Expression::JournalProperty(_) => "journal_property",
2362            Expression::LanguageProperty(_) => "language_property",
2363            Expression::EnviromentProperty(_) => "enviroment_property",
2364            Expression::ClusteredByProperty(_) => "clustered_by_property",
2365            Expression::DictProperty(_) => "dict_property",
2366            Expression::DictRange(_) => "dict_range",
2367            Expression::OnCluster(_) => "on_cluster",
2368            Expression::LikeProperty(_) => "like_property",
2369            Expression::LocationProperty(_) => "location_property",
2370            Expression::LockProperty(_) => "lock_property",
2371            Expression::LockingProperty(_) => "locking_property",
2372            Expression::LogProperty(_) => "log_property",
2373            Expression::MaterializedProperty(_) => "materialized_property",
2374            Expression::MergeBlockRatioProperty(_) => "merge_block_ratio_property",
2375            Expression::OnProperty(_) => "on_property",
2376            Expression::OnCommitProperty(_) => "on_commit_property",
2377            Expression::PartitionedByProperty(_) => "partitioned_by_property",
2378            Expression::PartitionByProperty(_) => "partition_by_property",
2379            Expression::PartitionedByBucket(_) => "partitioned_by_bucket",
2380            Expression::ClusterByColumnsProperty(_) => "cluster_by_columns_property",
2381            Expression::PartitionByTruncate(_) => "partition_by_truncate",
2382            Expression::PartitionByRangeProperty(_) => "partition_by_range_property",
2383            Expression::PartitionByRangePropertyDynamic(_) => "partition_by_range_property_dynamic",
2384            Expression::PartitionByListProperty(_) => "partition_by_list_property",
2385            Expression::PartitionList(_) => "partition_list",
2386            Expression::Partition(_) => "partition",
2387            Expression::RefreshTriggerProperty(_) => "refresh_trigger_property",
2388            Expression::UniqueKeyProperty(_) => "unique_key_property",
2389            Expression::RollupProperty(_) => "rollup_property",
2390            Expression::PartitionBoundSpec(_) => "partition_bound_spec",
2391            Expression::PartitionedOfProperty(_) => "partitioned_of_property",
2392            Expression::RemoteWithConnectionModelProperty(_) => {
2393                "remote_with_connection_model_property"
2394            }
2395            Expression::ReturnsProperty(_) => "returns_property",
2396            Expression::RowFormatProperty(_) => "row_format_property",
2397            Expression::RowFormatDelimitedProperty(_) => "row_format_delimited_property",
2398            Expression::RowFormatSerdeProperty(_) => "row_format_serde_property",
2399            Expression::QueryTransform(_) => "query_transform",
2400            Expression::SampleProperty(_) => "sample_property",
2401            Expression::SecurityProperty(_) => "security_property",
2402            Expression::SchemaCommentProperty(_) => "schema_comment_property",
2403            Expression::SemanticView(_) => "semantic_view",
2404            Expression::SerdeProperties(_) => "serde_properties",
2405            Expression::SetProperty(_) => "set_property",
2406            Expression::SharingProperty(_) => "sharing_property",
2407            Expression::SetConfigProperty(_) => "set_config_property",
2408            Expression::SettingsProperty(_) => "settings_property",
2409            Expression::SortKeyProperty(_) => "sort_key_property",
2410            Expression::SqlReadWriteProperty(_) => "sql_read_write_property",
2411            Expression::SqlSecurityProperty(_) => "sql_security_property",
2412            Expression::StabilityProperty(_) => "stability_property",
2413            Expression::StorageHandlerProperty(_) => "storage_handler_property",
2414            Expression::TemporaryProperty(_) => "temporary_property",
2415            Expression::Tags(_) => "tags",
2416            Expression::TransformModelProperty(_) => "transform_model_property",
2417            Expression::TransientProperty(_) => "transient_property",
2418            Expression::UsingTemplateProperty(_) => "using_template_property",
2419            Expression::ViewAttributeProperty(_) => "view_attribute_property",
2420            Expression::VolatileProperty(_) => "volatile_property",
2421            Expression::WithDataProperty(_) => "with_data_property",
2422            Expression::WithJournalTableProperty(_) => "with_journal_table_property",
2423            Expression::WithSchemaBindingProperty(_) => "with_schema_binding_property",
2424            Expression::WithSystemVersioningProperty(_) => "with_system_versioning_property",
2425            Expression::WithProcedureOptions(_) => "with_procedure_options",
2426            Expression::EncodeProperty(_) => "encode_property",
2427            Expression::IncludeProperty(_) => "include_property",
2428            Expression::Properties(_) => "properties",
2429            Expression::OptionsProperty(_) => "options_property",
2430            Expression::InputOutputFormat(_) => "input_output_format",
2431            Expression::Reference(_) => "reference",
2432            Expression::QueryOption(_) => "query_option",
2433            Expression::WithTableHint(_) => "with_table_hint",
2434            Expression::IndexTableHint(_) => "index_table_hint",
2435            Expression::HistoricalData(_) => "historical_data",
2436            Expression::Get(_) => "get",
2437            Expression::SetOperation(_) => "set_operation",
2438            Expression::Var(_) => "var",
2439            Expression::Variadic(_) => "variadic",
2440            Expression::Version(_) => "version",
2441            Expression::Schema(_) => "schema",
2442            Expression::Lock(_) => "lock",
2443            Expression::TableSample(_) => "table_sample",
2444            Expression::Tag(_) => "tag",
2445            Expression::UnpivotColumns(_) => "unpivot_columns",
2446            Expression::WindowSpec(_) => "window_spec",
2447            Expression::SessionParameter(_) => "session_parameter",
2448            Expression::PseudoType(_) => "pseudo_type",
2449            Expression::ObjectIdentifier(_) => "object_identifier",
2450            Expression::Transaction(_) => "transaction",
2451            Expression::Commit(_) => "commit",
2452            Expression::Rollback(_) => "rollback",
2453            Expression::AlterSession(_) => "alter_session",
2454            Expression::Analyze(_) => "analyze",
2455            Expression::AnalyzeStatistics(_) => "analyze_statistics",
2456            Expression::AnalyzeHistogram(_) => "analyze_histogram",
2457            Expression::AnalyzeSample(_) => "analyze_sample",
2458            Expression::AnalyzeListChainedRows(_) => "analyze_list_chained_rows",
2459            Expression::AnalyzeDelete(_) => "analyze_delete",
2460            Expression::AnalyzeWith(_) => "analyze_with",
2461            Expression::AnalyzeValidate(_) => "analyze_validate",
2462            Expression::AddPartition(_) => "add_partition",
2463            Expression::AttachOption(_) => "attach_option",
2464            Expression::DropPartition(_) => "drop_partition",
2465            Expression::ReplacePartition(_) => "replace_partition",
2466            Expression::DPipe(_) => "d_pipe",
2467            Expression::Operator(_) => "operator",
2468            Expression::PivotAny(_) => "pivot_any",
2469            Expression::Aliases(_) => "aliases",
2470            Expression::AtIndex(_) => "at_index",
2471            Expression::FromTimeZone(_) => "from_time_zone",
2472            Expression::FormatPhrase(_) => "format_phrase",
2473            Expression::ForIn(_) => "for_in",
2474            Expression::TimeUnit(_) => "time_unit",
2475            Expression::IntervalOp(_) => "interval_op",
2476            Expression::IntervalSpan(_) => "interval_span",
2477            Expression::HavingMax(_) => "having_max",
2478            Expression::CosineDistance(_) => "cosine_distance",
2479            Expression::DotProduct(_) => "dot_product",
2480            Expression::EuclideanDistance(_) => "euclidean_distance",
2481            Expression::ManhattanDistance(_) => "manhattan_distance",
2482            Expression::JarowinklerSimilarity(_) => "jarowinkler_similarity",
2483            Expression::Booland(_) => "booland",
2484            Expression::Boolor(_) => "boolor",
2485            Expression::ParameterizedAgg(_) => "parameterized_agg",
2486            Expression::ArgMax(_) => "arg_max",
2487            Expression::ArgMin(_) => "arg_min",
2488            Expression::ApproxTopK(_) => "approx_top_k",
2489            Expression::ApproxTopKAccumulate(_) => "approx_top_k_accumulate",
2490            Expression::ApproxTopKCombine(_) => "approx_top_k_combine",
2491            Expression::ApproxTopKEstimate(_) => "approx_top_k_estimate",
2492            Expression::ApproxTopSum(_) => "approx_top_sum",
2493            Expression::ApproxQuantiles(_) => "approx_quantiles",
2494            Expression::Minhash(_) => "minhash",
2495            Expression::FarmFingerprint(_) => "farm_fingerprint",
2496            Expression::Float64(_) => "float64",
2497            Expression::Transform(_) => "transform",
2498            Expression::Translate(_) => "translate",
2499            Expression::Grouping(_) => "grouping",
2500            Expression::GroupingId(_) => "grouping_id",
2501            Expression::Anonymous(_) => "anonymous",
2502            Expression::AnonymousAggFunc(_) => "anonymous_agg_func",
2503            Expression::CombinedAggFunc(_) => "combined_agg_func",
2504            Expression::CombinedParameterizedAgg(_) => "combined_parameterized_agg",
2505            Expression::HashAgg(_) => "hash_agg",
2506            Expression::Hll(_) => "hll",
2507            Expression::Apply(_) => "apply",
2508            Expression::ToBoolean(_) => "to_boolean",
2509            Expression::List(_) => "list",
2510            Expression::ToMap(_) => "to_map",
2511            Expression::Pad(_) => "pad",
2512            Expression::ToChar(_) => "to_char",
2513            Expression::ToNumber(_) => "to_number",
2514            Expression::ToDouble(_) => "to_double",
2515            Expression::Int64(_) => "int64",
2516            Expression::StringFunc(_) => "string_func",
2517            Expression::ToDecfloat(_) => "to_decfloat",
2518            Expression::TryToDecfloat(_) => "try_to_decfloat",
2519            Expression::ToFile(_) => "to_file",
2520            Expression::Columns(_) => "columns",
2521            Expression::ConvertToCharset(_) => "convert_to_charset",
2522            Expression::ConvertTimezone(_) => "convert_timezone",
2523            Expression::GenerateSeries(_) => "generate_series",
2524            Expression::AIAgg(_) => "a_i_agg",
2525            Expression::AIClassify(_) => "a_i_classify",
2526            Expression::ArrayAll(_) => "array_all",
2527            Expression::ArrayAny(_) => "array_any",
2528            Expression::ArrayConstructCompact(_) => "array_construct_compact",
2529            Expression::StPoint(_) => "st_point",
2530            Expression::StDistance(_) => "st_distance",
2531            Expression::StringToArray(_) => "string_to_array",
2532            Expression::ArraySum(_) => "array_sum",
2533            Expression::ObjectAgg(_) => "object_agg",
2534            Expression::CastToStrType(_) => "cast_to_str_type",
2535            Expression::CheckJson(_) => "check_json",
2536            Expression::CheckXml(_) => "check_xml",
2537            Expression::TranslateCharacters(_) => "translate_characters",
2538            Expression::CurrentSchemas(_) => "current_schemas",
2539            Expression::CurrentDatetime(_) => "current_datetime",
2540            Expression::Localtime(_) => "localtime",
2541            Expression::Localtimestamp(_) => "localtimestamp",
2542            Expression::Systimestamp(_) => "systimestamp",
2543            Expression::CurrentSchema(_) => "current_schema",
2544            Expression::CurrentUser(_) => "current_user",
2545            Expression::UtcTime(_) => "utc_time",
2546            Expression::UtcTimestamp(_) => "utc_timestamp",
2547            Expression::Timestamp(_) => "timestamp",
2548            Expression::DateBin(_) => "date_bin",
2549            Expression::Datetime(_) => "datetime",
2550            Expression::DatetimeAdd(_) => "datetime_add",
2551            Expression::DatetimeSub(_) => "datetime_sub",
2552            Expression::DatetimeDiff(_) => "datetime_diff",
2553            Expression::DatetimeTrunc(_) => "datetime_trunc",
2554            Expression::Dayname(_) => "dayname",
2555            Expression::MakeInterval(_) => "make_interval",
2556            Expression::PreviousDay(_) => "previous_day",
2557            Expression::Elt(_) => "elt",
2558            Expression::TimestampAdd(_) => "timestamp_add",
2559            Expression::TimestampSub(_) => "timestamp_sub",
2560            Expression::TimestampDiff(_) => "timestamp_diff",
2561            Expression::TimeSlice(_) => "time_slice",
2562            Expression::TimeAdd(_) => "time_add",
2563            Expression::TimeSub(_) => "time_sub",
2564            Expression::TimeDiff(_) => "time_diff",
2565            Expression::TimeTrunc(_) => "time_trunc",
2566            Expression::DateFromParts(_) => "date_from_parts",
2567            Expression::TimeFromParts(_) => "time_from_parts",
2568            Expression::DecodeCase(_) => "decode_case",
2569            Expression::Decrypt(_) => "decrypt",
2570            Expression::DecryptRaw(_) => "decrypt_raw",
2571            Expression::Encode(_) => "encode",
2572            Expression::Encrypt(_) => "encrypt",
2573            Expression::EncryptRaw(_) => "encrypt_raw",
2574            Expression::EqualNull(_) => "equal_null",
2575            Expression::ToBinary(_) => "to_binary",
2576            Expression::Base64DecodeBinary(_) => "base64_decode_binary",
2577            Expression::Base64DecodeString(_) => "base64_decode_string",
2578            Expression::Base64Encode(_) => "base64_encode",
2579            Expression::TryBase64DecodeBinary(_) => "try_base64_decode_binary",
2580            Expression::TryBase64DecodeString(_) => "try_base64_decode_string",
2581            Expression::GapFill(_) => "gap_fill",
2582            Expression::GenerateDateArray(_) => "generate_date_array",
2583            Expression::GenerateTimestampArray(_) => "generate_timestamp_array",
2584            Expression::GetExtract(_) => "get_extract",
2585            Expression::Getbit(_) => "getbit",
2586            Expression::OverflowTruncateBehavior(_) => "overflow_truncate_behavior",
2587            Expression::HexEncode(_) => "hex_encode",
2588            Expression::Compress(_) => "compress",
2589            Expression::DecompressBinary(_) => "decompress_binary",
2590            Expression::DecompressString(_) => "decompress_string",
2591            Expression::Xor(_) => "xor",
2592            Expression::Nullif(_) => "nullif",
2593            Expression::JSON(_) => "j_s_o_n",
2594            Expression::JSONPath(_) => "j_s_o_n_path",
2595            Expression::JSONPathFilter(_) => "j_s_o_n_path_filter",
2596            Expression::JSONPathKey(_) => "j_s_o_n_path_key",
2597            Expression::JSONPathRecursive(_) => "j_s_o_n_path_recursive",
2598            Expression::JSONPathScript(_) => "j_s_o_n_path_script",
2599            Expression::JSONPathSlice(_) => "j_s_o_n_path_slice",
2600            Expression::JSONPathSelector(_) => "j_s_o_n_path_selector",
2601            Expression::JSONPathSubscript(_) => "j_s_o_n_path_subscript",
2602            Expression::JSONPathUnion(_) => "j_s_o_n_path_union",
2603            Expression::Format(_) => "format",
2604            Expression::JSONKeys(_) => "j_s_o_n_keys",
2605            Expression::JSONKeyValue(_) => "j_s_o_n_key_value",
2606            Expression::JSONKeysAtDepth(_) => "j_s_o_n_keys_at_depth",
2607            Expression::JSONObject(_) => "j_s_o_n_object",
2608            Expression::JSONObjectAgg(_) => "j_s_o_n_object_agg",
2609            Expression::JSONBObjectAgg(_) => "j_s_o_n_b_object_agg",
2610            Expression::JSONArray(_) => "j_s_o_n_array",
2611            Expression::JSONArrayAgg(_) => "j_s_o_n_array_agg",
2612            Expression::JSONExists(_) => "j_s_o_n_exists",
2613            Expression::JSONColumnDef(_) => "j_s_o_n_column_def",
2614            Expression::JSONSchema(_) => "j_s_o_n_schema",
2615            Expression::JSONSet(_) => "j_s_o_n_set",
2616            Expression::JSONStripNulls(_) => "j_s_o_n_strip_nulls",
2617            Expression::JSONValue(_) => "j_s_o_n_value",
2618            Expression::JSONValueArray(_) => "j_s_o_n_value_array",
2619            Expression::JSONRemove(_) => "j_s_o_n_remove",
2620            Expression::JSONTable(_) => "j_s_o_n_table",
2621            Expression::JSONType(_) => "j_s_o_n_type",
2622            Expression::ObjectInsert(_) => "object_insert",
2623            Expression::OpenJSONColumnDef(_) => "open_j_s_o_n_column_def",
2624            Expression::OpenJSON(_) => "open_j_s_o_n",
2625            Expression::JSONBExists(_) => "j_s_o_n_b_exists",
2626            Expression::JSONBContains(_) => "j_s_o_n_b_contains",
2627            Expression::JSONBExtract(_) => "j_s_o_n_b_extract",
2628            Expression::JSONCast(_) => "j_s_o_n_cast",
2629            Expression::JSONExtract(_) => "j_s_o_n_extract",
2630            Expression::JSONExtractQuote(_) => "j_s_o_n_extract_quote",
2631            Expression::JSONExtractArray(_) => "j_s_o_n_extract_array",
2632            Expression::JSONExtractScalar(_) => "j_s_o_n_extract_scalar",
2633            Expression::JSONBExtractScalar(_) => "j_s_o_n_b_extract_scalar",
2634            Expression::JSONFormat(_) => "j_s_o_n_format",
2635            Expression::JSONBool(_) => "j_s_o_n_bool",
2636            Expression::JSONPathRoot(_) => "j_s_o_n_path_root",
2637            Expression::JSONArrayAppend(_) => "j_s_o_n_array_append",
2638            Expression::JSONArrayContains(_) => "j_s_o_n_array_contains",
2639            Expression::JSONArrayInsert(_) => "j_s_o_n_array_insert",
2640            Expression::ParseJSON(_) => "parse_j_s_o_n",
2641            Expression::ParseUrl(_) => "parse_url",
2642            Expression::ParseIp(_) => "parse_ip",
2643            Expression::ParseTime(_) => "parse_time",
2644            Expression::ParseDatetime(_) => "parse_datetime",
2645            Expression::Map(_) => "map",
2646            Expression::MapCat(_) => "map_cat",
2647            Expression::MapDelete(_) => "map_delete",
2648            Expression::MapInsert(_) => "map_insert",
2649            Expression::MapPick(_) => "map_pick",
2650            Expression::ScopeResolution(_) => "scope_resolution",
2651            Expression::Slice(_) => "slice",
2652            Expression::VarMap(_) => "var_map",
2653            Expression::MatchAgainst(_) => "match_against",
2654            Expression::MD5Digest(_) => "m_d5_digest",
2655            Expression::MD5NumberLower64(_) => "m_d5_number_lower64",
2656            Expression::MD5NumberUpper64(_) => "m_d5_number_upper64",
2657            Expression::Monthname(_) => "monthname",
2658            Expression::Ntile(_) => "ntile",
2659            Expression::Normalize(_) => "normalize",
2660            Expression::Normal(_) => "normal",
2661            Expression::Predict(_) => "predict",
2662            Expression::MLTranslate(_) => "m_l_translate",
2663            Expression::FeaturesAtTime(_) => "features_at_time",
2664            Expression::GenerateEmbedding(_) => "generate_embedding",
2665            Expression::MLForecast(_) => "m_l_forecast",
2666            Expression::ModelAttribute(_) => "model_attribute",
2667            Expression::VectorSearch(_) => "vector_search",
2668            Expression::Quantile(_) => "quantile",
2669            Expression::ApproxQuantile(_) => "approx_quantile",
2670            Expression::ApproxPercentileEstimate(_) => "approx_percentile_estimate",
2671            Expression::Randn(_) => "randn",
2672            Expression::Randstr(_) => "randstr",
2673            Expression::RangeN(_) => "range_n",
2674            Expression::RangeBucket(_) => "range_bucket",
2675            Expression::ReadCSV(_) => "read_c_s_v",
2676            Expression::ReadParquet(_) => "read_parquet",
2677            Expression::Reduce(_) => "reduce",
2678            Expression::RegexpExtractAll(_) => "regexp_extract_all",
2679            Expression::RegexpILike(_) => "regexp_i_like",
2680            Expression::RegexpFullMatch(_) => "regexp_full_match",
2681            Expression::RegexpInstr(_) => "regexp_instr",
2682            Expression::RegexpSplit(_) => "regexp_split",
2683            Expression::RegexpCount(_) => "regexp_count",
2684            Expression::RegrValx(_) => "regr_valx",
2685            Expression::RegrValy(_) => "regr_valy",
2686            Expression::RegrAvgy(_) => "regr_avgy",
2687            Expression::RegrAvgx(_) => "regr_avgx",
2688            Expression::RegrCount(_) => "regr_count",
2689            Expression::RegrIntercept(_) => "regr_intercept",
2690            Expression::RegrR2(_) => "regr_r2",
2691            Expression::RegrSxx(_) => "regr_sxx",
2692            Expression::RegrSxy(_) => "regr_sxy",
2693            Expression::RegrSyy(_) => "regr_syy",
2694            Expression::RegrSlope(_) => "regr_slope",
2695            Expression::SafeAdd(_) => "safe_add",
2696            Expression::SafeDivide(_) => "safe_divide",
2697            Expression::SafeMultiply(_) => "safe_multiply",
2698            Expression::SafeSubtract(_) => "safe_subtract",
2699            Expression::SHA2(_) => "s_h_a2",
2700            Expression::SHA2Digest(_) => "s_h_a2_digest",
2701            Expression::SortArray(_) => "sort_array",
2702            Expression::SplitPart(_) => "split_part",
2703            Expression::SubstringIndex(_) => "substring_index",
2704            Expression::StandardHash(_) => "standard_hash",
2705            Expression::StrPosition(_) => "str_position",
2706            Expression::Search(_) => "search",
2707            Expression::SearchIp(_) => "search_ip",
2708            Expression::StrToDate(_) => "str_to_date",
2709            Expression::DateStrToDate(_) => "date_str_to_date",
2710            Expression::DateToDateStr(_) => "date_to_date_str",
2711            Expression::StrToTime(_) => "str_to_time",
2712            Expression::StrToUnix(_) => "str_to_unix",
2713            Expression::StrToMap(_) => "str_to_map",
2714            Expression::NumberToStr(_) => "number_to_str",
2715            Expression::FromBase(_) => "from_base",
2716            Expression::Stuff(_) => "stuff",
2717            Expression::TimeToStr(_) => "time_to_str",
2718            Expression::TimeStrToTime(_) => "time_str_to_time",
2719            Expression::TsOrDsAdd(_) => "ts_or_ds_add",
2720            Expression::TsOrDsDiff(_) => "ts_or_ds_diff",
2721            Expression::TsOrDsToDate(_) => "ts_or_ds_to_date",
2722            Expression::TsOrDsToTime(_) => "ts_or_ds_to_time",
2723            Expression::Unhex(_) => "unhex",
2724            Expression::Uniform(_) => "uniform",
2725            Expression::UnixToStr(_) => "unix_to_str",
2726            Expression::UnixToTime(_) => "unix_to_time",
2727            Expression::Uuid(_) => "uuid",
2728            Expression::TimestampFromParts(_) => "timestamp_from_parts",
2729            Expression::TimestampTzFromParts(_) => "timestamp_tz_from_parts",
2730            Expression::Corr(_) => "corr",
2731            Expression::WidthBucket(_) => "width_bucket",
2732            Expression::CovarSamp(_) => "covar_samp",
2733            Expression::CovarPop(_) => "covar_pop",
2734            Expression::Week(_) => "week",
2735            Expression::XMLElement(_) => "x_m_l_element",
2736            Expression::XMLGet(_) => "x_m_l_get",
2737            Expression::XMLTable(_) => "x_m_l_table",
2738            Expression::XMLKeyValueOption(_) => "x_m_l_key_value_option",
2739            Expression::Zipf(_) => "zipf",
2740            Expression::Merge(_) => "merge",
2741            Expression::When(_) => "when",
2742            Expression::Whens(_) => "whens",
2743            Expression::NextValueFor(_) => "next_value_for",
2744            Expression::ReturnStmt(_) => "return_stmt",
2745        }
2746    }
2747
2748    /// Returns the primary child expression (".this" in sqlglot).
2749    pub fn get_this(&self) -> Option<&Expression> {
2750        match self {
2751            // Unary ops
2752            Expression::Not(u) | Expression::Neg(u) | Expression::BitwiseNot(u) => Some(&u.this),
2753            // UnaryFunc variants
2754            Expression::Upper(f)
2755            | Expression::Lower(f)
2756            | Expression::Length(f)
2757            | Expression::LTrim(f)
2758            | Expression::RTrim(f)
2759            | Expression::Reverse(f)
2760            | Expression::Abs(f)
2761            | Expression::Sqrt(f)
2762            | Expression::Cbrt(f)
2763            | Expression::Ln(f)
2764            | Expression::Exp(f)
2765            | Expression::Sign(f)
2766            | Expression::Date(f)
2767            | Expression::Time(f)
2768            | Expression::Initcap(f)
2769            | Expression::Ascii(f)
2770            | Expression::Chr(f)
2771            | Expression::Soundex(f)
2772            | Expression::ByteLength(f)
2773            | Expression::Hex(f)
2774            | Expression::LowerHex(f)
2775            | Expression::Unicode(f)
2776            | Expression::Typeof(f)
2777            | Expression::Explode(f)
2778            | Expression::ExplodeOuter(f)
2779            | Expression::MapFromEntries(f)
2780            | Expression::MapKeys(f)
2781            | Expression::MapValues(f)
2782            | Expression::ArrayLength(f)
2783            | Expression::ArraySize(f)
2784            | Expression::Cardinality(f)
2785            | Expression::ArrayReverse(f)
2786            | Expression::ArrayDistinct(f)
2787            | Expression::ArrayFlatten(f)
2788            | Expression::ArrayCompact(f)
2789            | Expression::ToArray(f)
2790            | Expression::JsonArrayLength(f)
2791            | Expression::JsonKeys(f)
2792            | Expression::JsonType(f)
2793            | Expression::ParseJson(f)
2794            | Expression::ToJson(f)
2795            | Expression::Radians(f)
2796            | Expression::Degrees(f)
2797            | Expression::Sin(f)
2798            | Expression::Cos(f)
2799            | Expression::Tan(f)
2800            | Expression::Asin(f)
2801            | Expression::Acos(f)
2802            | Expression::Atan(f)
2803            | Expression::IsNan(f)
2804            | Expression::IsInf(f)
2805            | Expression::Year(f)
2806            | Expression::Month(f)
2807            | Expression::Day(f)
2808            | Expression::Hour(f)
2809            | Expression::Minute(f)
2810            | Expression::Second(f)
2811            | Expression::DayOfWeek(f)
2812            | Expression::DayOfWeekIso(f)
2813            | Expression::DayOfMonth(f)
2814            | Expression::DayOfYear(f)
2815            | Expression::WeekOfYear(f)
2816            | Expression::Quarter(f)
2817            | Expression::Epoch(f)
2818            | Expression::EpochMs(f)
2819            | Expression::BitwiseCount(f)
2820            | Expression::DateFromUnixDate(f)
2821            | Expression::UnixDate(f)
2822            | Expression::UnixSeconds(f)
2823            | Expression::UnixMillis(f)
2824            | Expression::UnixMicros(f)
2825            | Expression::TimeStrToDate(f)
2826            | Expression::DateToDi(f)
2827            | Expression::DiToDate(f)
2828            | Expression::TsOrDiToDi(f)
2829            | Expression::TsOrDsToDatetime(f)
2830            | Expression::TsOrDsToTimestamp(f)
2831            | Expression::YearOfWeek(f)
2832            | Expression::YearOfWeekIso(f)
2833            | Expression::SHA(f)
2834            | Expression::SHA1Digest(f)
2835            | Expression::TimeToUnix(f)
2836            | Expression::TimeStrToUnix(f)
2837            | Expression::Int64(f)
2838            | Expression::JSONBool(f)
2839            | Expression::MD5NumberLower64(f)
2840            | Expression::MD5NumberUpper64(f)
2841            | Expression::DateStrToDate(f)
2842            | Expression::DateToDateStr(f) => Some(&f.this),
2843            // BinaryFunc - this is the primary child
2844            Expression::Power(f)
2845            | Expression::NullIf(f)
2846            | Expression::IfNull(f)
2847            | Expression::Nvl(f)
2848            | Expression::Contains(f)
2849            | Expression::StartsWith(f)
2850            | Expression::EndsWith(f)
2851            | Expression::Levenshtein(f)
2852            | Expression::ModFunc(f)
2853            | Expression::IntDiv(f)
2854            | Expression::Atan2(f)
2855            | Expression::AddMonths(f)
2856            | Expression::MonthsBetween(f)
2857            | Expression::NextDay(f)
2858            | Expression::UnixToTimeStr(f)
2859            | Expression::ArrayContains(f)
2860            | Expression::ArrayPosition(f)
2861            | Expression::ArrayAppend(f)
2862            | Expression::ArrayPrepend(f)
2863            | Expression::ArrayUnion(f)
2864            | Expression::ArrayExcept(f)
2865            | Expression::ArrayRemove(f)
2866            | Expression::StarMap(f)
2867            | Expression::MapFromArrays(f)
2868            | Expression::MapContainsKey(f)
2869            | Expression::ElementAt(f)
2870            | Expression::JsonMergePatch(f)
2871            | Expression::JSONBContains(f)
2872            | Expression::JSONBExtract(f) => Some(&f.this),
2873            // AggFunc - this is the primary child
2874            Expression::Sum(af)
2875            | Expression::Avg(af)
2876            | Expression::Min(af)
2877            | Expression::Max(af)
2878            | Expression::ArrayAgg(af)
2879            | Expression::CountIf(af)
2880            | Expression::Stddev(af)
2881            | Expression::StddevPop(af)
2882            | Expression::StddevSamp(af)
2883            | Expression::Variance(af)
2884            | Expression::VarPop(af)
2885            | Expression::VarSamp(af)
2886            | Expression::Median(af)
2887            | Expression::Mode(af)
2888            | Expression::First(af)
2889            | Expression::Last(af)
2890            | Expression::AnyValue(af)
2891            | Expression::ApproxDistinct(af)
2892            | Expression::ApproxCountDistinct(af)
2893            | Expression::LogicalAnd(af)
2894            | Expression::LogicalOr(af)
2895            | Expression::Skewness(af)
2896            | Expression::ArrayConcatAgg(af)
2897            | Expression::ArrayUniqueAgg(af)
2898            | Expression::BoolXorAgg(af)
2899            | Expression::BitwiseAndAgg(af)
2900            | Expression::BitwiseOrAgg(af)
2901            | Expression::BitwiseXorAgg(af) => Some(&af.this),
2902            // Binary operations - left is "this" in sqlglot
2903            Expression::And(op)
2904            | Expression::Or(op)
2905            | Expression::Add(op)
2906            | Expression::Sub(op)
2907            | Expression::Mul(op)
2908            | Expression::Div(op)
2909            | Expression::Mod(op)
2910            | Expression::Eq(op)
2911            | Expression::Neq(op)
2912            | Expression::Lt(op)
2913            | Expression::Lte(op)
2914            | Expression::Gt(op)
2915            | Expression::Gte(op)
2916            | Expression::BitwiseAnd(op)
2917            | Expression::BitwiseOr(op)
2918            | Expression::BitwiseXor(op)
2919            | Expression::Concat(op)
2920            | Expression::Adjacent(op)
2921            | Expression::TsMatch(op)
2922            | Expression::PropertyEQ(op)
2923            | Expression::ArrayContainsAll(op)
2924            | Expression::ArrayContainedBy(op)
2925            | Expression::ArrayOverlaps(op)
2926            | Expression::JSONBContainsAllTopKeys(op)
2927            | Expression::JSONBContainsAnyTopKeys(op)
2928            | Expression::JSONBDeleteAtPath(op)
2929            | Expression::ExtendsLeft(op)
2930            | Expression::ExtendsRight(op)
2931            | Expression::Is(op)
2932            | Expression::MemberOf(op)
2933            | Expression::Match(op)
2934            | Expression::NullSafeEq(op)
2935            | Expression::NullSafeNeq(op)
2936            | Expression::Glob(op)
2937            | Expression::BitwiseLeftShift(op)
2938            | Expression::BitwiseRightShift(op) => Some(&op.left),
2939            // Like operations - left is "this"
2940            Expression::Like(op) | Expression::ILike(op) => Some(&op.left),
2941            // Structural types with .this
2942            Expression::Alias(a) => Some(&a.this),
2943            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => Some(&c.this),
2944            Expression::Paren(p) => Some(&p.this),
2945            Expression::Annotated(a) => Some(&a.this),
2946            Expression::Subquery(s) => Some(&s.this),
2947            Expression::Where(w) => Some(&w.this),
2948            Expression::Having(h) => Some(&h.this),
2949            Expression::Qualify(q) => Some(&q.this),
2950            Expression::IsNull(i) => Some(&i.this),
2951            Expression::Exists(e) => Some(&e.this),
2952            Expression::Ordered(o) => Some(&o.this),
2953            Expression::WindowFunction(wf) => Some(&wf.this),
2954            Expression::Cte(cte) => Some(&cte.this),
2955            Expression::Between(b) => Some(&b.this),
2956            Expression::In(i) => Some(&i.this),
2957            Expression::ReturnStmt(e) => Some(e),
2958            _ => None,
2959        }
2960    }
2961
2962    /// Returns the secondary child expression (".expression" in sqlglot).
2963    pub fn get_expression(&self) -> Option<&Expression> {
2964        match self {
2965            // Binary operations - right is "expression"
2966            Expression::And(op)
2967            | Expression::Or(op)
2968            | Expression::Add(op)
2969            | Expression::Sub(op)
2970            | Expression::Mul(op)
2971            | Expression::Div(op)
2972            | Expression::Mod(op)
2973            | Expression::Eq(op)
2974            | Expression::Neq(op)
2975            | Expression::Lt(op)
2976            | Expression::Lte(op)
2977            | Expression::Gt(op)
2978            | Expression::Gte(op)
2979            | Expression::BitwiseAnd(op)
2980            | Expression::BitwiseOr(op)
2981            | Expression::BitwiseXor(op)
2982            | Expression::Concat(op)
2983            | Expression::Adjacent(op)
2984            | Expression::TsMatch(op)
2985            | Expression::PropertyEQ(op)
2986            | Expression::ArrayContainsAll(op)
2987            | Expression::ArrayContainedBy(op)
2988            | Expression::ArrayOverlaps(op)
2989            | Expression::JSONBContainsAllTopKeys(op)
2990            | Expression::JSONBContainsAnyTopKeys(op)
2991            | Expression::JSONBDeleteAtPath(op)
2992            | Expression::ExtendsLeft(op)
2993            | Expression::ExtendsRight(op)
2994            | Expression::Is(op)
2995            | Expression::MemberOf(op)
2996            | Expression::Match(op)
2997            | Expression::NullSafeEq(op)
2998            | Expression::NullSafeNeq(op)
2999            | Expression::Glob(op)
3000            | Expression::BitwiseLeftShift(op)
3001            | Expression::BitwiseRightShift(op) => Some(&op.right),
3002            // Like operations - right is "expression"
3003            Expression::Like(op) | Expression::ILike(op) => Some(&op.right),
3004            // BinaryFunc - expression is the secondary
3005            Expression::Power(f)
3006            | Expression::NullIf(f)
3007            | Expression::IfNull(f)
3008            | Expression::Nvl(f)
3009            | Expression::Contains(f)
3010            | Expression::StartsWith(f)
3011            | Expression::EndsWith(f)
3012            | Expression::Levenshtein(f)
3013            | Expression::ModFunc(f)
3014            | Expression::IntDiv(f)
3015            | Expression::Atan2(f)
3016            | Expression::AddMonths(f)
3017            | Expression::MonthsBetween(f)
3018            | Expression::NextDay(f)
3019            | Expression::UnixToTimeStr(f)
3020            | Expression::ArrayContains(f)
3021            | Expression::ArrayPosition(f)
3022            | Expression::ArrayAppend(f)
3023            | Expression::ArrayPrepend(f)
3024            | Expression::ArrayUnion(f)
3025            | Expression::ArrayExcept(f)
3026            | Expression::ArrayRemove(f)
3027            | Expression::StarMap(f)
3028            | Expression::MapFromArrays(f)
3029            | Expression::MapContainsKey(f)
3030            | Expression::ElementAt(f)
3031            | Expression::JsonMergePatch(f)
3032            | Expression::JSONBContains(f)
3033            | Expression::JSONBExtract(f) => Some(&f.expression),
3034            _ => None,
3035        }
3036    }
3037
3038    /// Returns the list of child expressions (".expressions" in sqlglot).
3039    pub fn get_expressions(&self) -> &[Expression] {
3040        match self {
3041            Expression::Select(s) => &s.expressions,
3042            Expression::Function(f) => &f.args,
3043            Expression::AggregateFunction(f) => &f.args,
3044            Expression::From(f) => &f.expressions,
3045            Expression::GroupBy(g) => &g.expressions,
3046            Expression::In(i) => &i.expressions,
3047            Expression::Array(a) => &a.expressions,
3048            Expression::Tuple(t) => &t.expressions,
3049            Expression::Coalesce(f)
3050            | Expression::Greatest(f)
3051            | Expression::Least(f)
3052            | Expression::ArrayConcat(f)
3053            | Expression::ArrayIntersect(f)
3054            | Expression::ArrayZip(f)
3055            | Expression::MapConcat(f)
3056            | Expression::JsonArray(f) => &f.expressions,
3057            _ => &[],
3058        }
3059    }
3060
3061    /// Returns the name of this expression as a string slice.
3062    pub fn get_name(&self) -> &str {
3063        match self {
3064            Expression::Identifier(id) => &id.name,
3065            Expression::Column(col) => &col.name.name,
3066            Expression::Table(t) => &t.name.name,
3067            Expression::Literal(lit) => lit.value_str(),
3068            Expression::Star(_) => "*",
3069            Expression::Function(f) => &f.name,
3070            Expression::AggregateFunction(f) => &f.name,
3071            Expression::Alias(a) => a.this.get_name(),
3072            Expression::Boolean(b) => {
3073                if b.value {
3074                    "TRUE"
3075                } else {
3076                    "FALSE"
3077                }
3078            }
3079            Expression::Null(_) => "NULL",
3080            _ => "",
3081        }
3082    }
3083
3084    /// Returns the alias name if this expression has one.
3085    pub fn get_alias(&self) -> &str {
3086        match self {
3087            Expression::Alias(a) => &a.alias.name,
3088            Expression::Table(t) => t.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3089            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3090            _ => "",
3091        }
3092    }
3093
3094    /// Returns the output name of this expression (what it shows up as in a SELECT).
3095    pub fn get_output_name(&self) -> &str {
3096        match self {
3097            Expression::Alias(a) => &a.alias.name,
3098            Expression::Column(c) => &c.name.name,
3099            Expression::Identifier(id) => &id.name,
3100            Expression::Literal(lit) => lit.value_str(),
3101            Expression::Subquery(s) => s.alias.as_ref().map(|a| a.name.as_str()).unwrap_or(""),
3102            Expression::Star(_) => "*",
3103            _ => "",
3104        }
3105    }
3106
3107    /// Returns comments attached to this expression.
3108    pub fn get_comments(&self) -> Vec<&str> {
3109        match self {
3110            Expression::Identifier(id) => id.trailing_comments.iter().map(|s| s.as_str()).collect(),
3111            Expression::Column(c) => c.trailing_comments.iter().map(|s| s.as_str()).collect(),
3112            Expression::Star(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3113            Expression::Paren(p) => p.trailing_comments.iter().map(|s| s.as_str()).collect(),
3114            Expression::Annotated(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3115            Expression::Alias(a) => a.trailing_comments.iter().map(|s| s.as_str()).collect(),
3116            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
3117                c.trailing_comments.iter().map(|s| s.as_str()).collect()
3118            }
3119            Expression::And(op)
3120            | Expression::Or(op)
3121            | Expression::Add(op)
3122            | Expression::Sub(op)
3123            | Expression::Mul(op)
3124            | Expression::Div(op)
3125            | Expression::Mod(op)
3126            | Expression::Eq(op)
3127            | Expression::Neq(op)
3128            | Expression::Lt(op)
3129            | Expression::Lte(op)
3130            | Expression::Gt(op)
3131            | Expression::Gte(op)
3132            | Expression::Concat(op)
3133            | Expression::BitwiseAnd(op)
3134            | Expression::BitwiseOr(op)
3135            | Expression::BitwiseXor(op) => {
3136                op.trailing_comments.iter().map(|s| s.as_str()).collect()
3137            }
3138            Expression::Function(f) => f.trailing_comments.iter().map(|s| s.as_str()).collect(),
3139            Expression::Subquery(s) => s.trailing_comments.iter().map(|s| s.as_str()).collect(),
3140            _ => Vec::new(),
3141        }
3142    }
3143}
3144
3145impl fmt::Display for Expression {
3146    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3147        // Basic display - full SQL generation is in generator module
3148        match self {
3149            Expression::Literal(lit) => write!(f, "{}", lit),
3150            Expression::Identifier(id) => write!(f, "{}", id),
3151            Expression::Column(col) => write!(f, "{}", col),
3152            Expression::Star(_) => write!(f, "*"),
3153            Expression::Null(_) => write!(f, "NULL"),
3154            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
3155            Expression::Select(_) => write!(f, "SELECT ..."),
3156            _ => write!(f, "{:?}", self),
3157        }
3158    }
3159}
3160
3161/// Represent a SQL literal value.
3162///
3163/// Numeric values are stored as their original text representation (not parsed
3164/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
3165/// preserved across round-trips.
3166///
3167/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
3168/// strings, raw strings, etc.) each have a dedicated variant so that the
3169/// generator can emit them with the correct syntax.
3170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3171#[cfg_attr(feature = "bindings", derive(TS))]
3172#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
3173pub enum Literal {
3174    /// Single-quoted string literal: `'hello'`
3175    String(String),
3176    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
3177    Number(String),
3178    /// Hex string literal: `X'FF'`
3179    HexString(String),
3180    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
3181    HexNumber(String),
3182    BitString(String),
3183    /// Byte string: b"..." (BigQuery style)
3184    ByteString(String),
3185    /// National string: N'abc'
3186    NationalString(String),
3187    /// DATE literal: DATE '2024-01-15'
3188    Date(String),
3189    /// TIME literal: TIME '10:30:00'
3190    Time(String),
3191    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
3192    Timestamp(String),
3193    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
3194    Datetime(String),
3195    /// Triple-quoted string: """...""" or '''...'''
3196    /// Contains (content, quote_char) where quote_char is '"' or '\''
3197    TripleQuotedString(String, char),
3198    /// Escape string: E'...' (PostgreSQL)
3199    EscapeString(String),
3200    /// Dollar-quoted string: $$...$$  (PostgreSQL)
3201    DollarString(String),
3202    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
3203    /// In raw strings, backslashes are literal and not escape characters.
3204    /// When converting to a regular string, backslashes must be doubled.
3205    RawString(String),
3206}
3207
3208impl Literal {
3209    /// Returns the inner value as a string slice, regardless of literal type.
3210    pub fn value_str(&self) -> &str {
3211        match self {
3212            Literal::String(s)
3213            | Literal::Number(s)
3214            | Literal::HexString(s)
3215            | Literal::HexNumber(s)
3216            | Literal::BitString(s)
3217            | Literal::ByteString(s)
3218            | Literal::NationalString(s)
3219            | Literal::Date(s)
3220            | Literal::Time(s)
3221            | Literal::Timestamp(s)
3222            | Literal::Datetime(s)
3223            | Literal::EscapeString(s)
3224            | Literal::DollarString(s)
3225            | Literal::RawString(s) => s.as_str(),
3226            Literal::TripleQuotedString(s, _) => s.as_str(),
3227        }
3228    }
3229
3230    /// Returns `true` if this is a string-type literal.
3231    pub fn is_string(&self) -> bool {
3232        matches!(
3233            self,
3234            Literal::String(_)
3235                | Literal::NationalString(_)
3236                | Literal::EscapeString(_)
3237                | Literal::DollarString(_)
3238                | Literal::RawString(_)
3239                | Literal::TripleQuotedString(_, _)
3240        )
3241    }
3242
3243    /// Returns `true` if this is a numeric literal.
3244    pub fn is_number(&self) -> bool {
3245        matches!(self, Literal::Number(_) | Literal::HexNumber(_))
3246    }
3247}
3248
3249impl fmt::Display for Literal {
3250    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3251        match self {
3252            Literal::String(s) => write!(f, "'{}'", s),
3253            Literal::Number(n) => write!(f, "{}", n),
3254            Literal::HexString(h) => write!(f, "X'{}'", h),
3255            Literal::HexNumber(h) => write!(f, "0x{}", h),
3256            Literal::BitString(b) => write!(f, "B'{}'", b),
3257            Literal::ByteString(b) => write!(f, "b'{}'", b),
3258            Literal::NationalString(s) => write!(f, "N'{}'", s),
3259            Literal::Date(d) => write!(f, "DATE '{}'", d),
3260            Literal::Time(t) => write!(f, "TIME '{}'", t),
3261            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
3262            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
3263            Literal::TripleQuotedString(s, q) => {
3264                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
3265            }
3266            Literal::EscapeString(s) => write!(f, "E'{}'", s),
3267            Literal::DollarString(s) => write!(f, "$${}$$", s),
3268            Literal::RawString(s) => write!(f, "r'{}'", s),
3269        }
3270    }
3271}
3272
3273/// Boolean literal
3274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3275#[cfg_attr(feature = "bindings", derive(TS))]
3276pub struct BooleanLiteral {
3277    pub value: bool,
3278}
3279
3280/// NULL literal
3281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3282#[cfg_attr(feature = "bindings", derive(TS))]
3283pub struct Null;
3284
3285/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
3286///
3287/// The `quoted` flag indicates whether the identifier was originally delimited
3288/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
3289/// dialect). The generator uses this flag to decide whether to emit quoting
3290/// characters.
3291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3292#[cfg_attr(feature = "bindings", derive(TS))]
3293pub struct Identifier {
3294    /// The raw text of the identifier, without any quoting characters.
3295    pub name: String,
3296    /// Whether the identifier was quoted in the source SQL.
3297    pub quoted: bool,
3298    #[serde(default)]
3299    pub trailing_comments: Vec<String>,
3300    /// Source position span (populated during parsing, None for programmatically constructed nodes)
3301    #[serde(default, skip_serializing_if = "Option::is_none")]
3302    pub span: Option<Span>,
3303}
3304
3305impl Identifier {
3306    pub fn new(name: impl Into<String>) -> Self {
3307        Self {
3308            name: name.into(),
3309            quoted: false,
3310            trailing_comments: Vec::new(),
3311            span: None,
3312        }
3313    }
3314
3315    pub fn quoted(name: impl Into<String>) -> Self {
3316        Self {
3317            name: name.into(),
3318            quoted: true,
3319            trailing_comments: Vec::new(),
3320            span: None,
3321        }
3322    }
3323
3324    pub fn empty() -> Self {
3325        Self {
3326            name: String::new(),
3327            quoted: false,
3328            trailing_comments: Vec::new(),
3329            span: None,
3330        }
3331    }
3332
3333    pub fn is_empty(&self) -> bool {
3334        self.name.is_empty()
3335    }
3336
3337    /// Set the source span on this identifier
3338    pub fn with_span(mut self, span: Span) -> Self {
3339        self.span = Some(span);
3340        self
3341    }
3342}
3343
3344impl fmt::Display for Identifier {
3345    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3346        if self.quoted {
3347            write!(f, "\"{}\"", self.name)
3348        } else {
3349            write!(f, "{}", self.name)
3350        }
3351    }
3352}
3353
3354/// Represent a column reference, optionally qualified by a table name.
3355///
3356/// Renders as `name` when unqualified, or `table.name` when qualified.
3357/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
3358/// convenient construction.
3359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3360#[cfg_attr(feature = "bindings", derive(TS))]
3361pub struct Column {
3362    /// The column name.
3363    pub name: Identifier,
3364    /// Optional table qualifier (e.g. `t` in `t.col`).
3365    pub table: Option<Identifier>,
3366    /// Oracle-style join marker (+) for outer joins
3367    #[serde(default)]
3368    pub join_mark: bool,
3369    /// Trailing comments that appeared after this column reference
3370    #[serde(default)]
3371    pub trailing_comments: Vec<String>,
3372    /// Source position span
3373    #[serde(default, skip_serializing_if = "Option::is_none")]
3374    pub span: Option<Span>,
3375    /// Inferred data type from type annotation
3376    #[serde(default, skip_serializing_if = "Option::is_none")]
3377    pub inferred_type: Option<DataType>,
3378}
3379
3380impl fmt::Display for Column {
3381    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3382        if let Some(table) = &self.table {
3383            write!(f, "{}.{}", table, self.name)
3384        } else {
3385            write!(f, "{}", self.name)
3386        }
3387    }
3388}
3389
3390/// Represent a table reference with optional schema and catalog qualifiers.
3391///
3392/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
3393/// which qualifiers are present. Supports aliases, column alias lists,
3394/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
3395/// several other dialect-specific extensions.
3396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3397#[cfg_attr(feature = "bindings", derive(TS))]
3398pub struct TableRef {
3399    /// The unqualified table name.
3400    pub name: Identifier,
3401    /// Optional schema qualifier (e.g. `public` in `public.users`).
3402    pub schema: Option<Identifier>,
3403    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
3404    pub catalog: Option<Identifier>,
3405    /// Optional table alias (e.g. `t` in `FROM users AS t`).
3406    pub alias: Option<Identifier>,
3407    /// Whether AS keyword was explicitly used for the alias
3408    #[serde(default)]
3409    pub alias_explicit_as: bool,
3410    /// Column aliases for table alias: AS t(c1, c2)
3411    #[serde(default)]
3412    pub column_aliases: Vec<Identifier>,
3413    /// Leading comments that appeared before this table reference in a FROM clause
3414    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3415    pub leading_comments: Vec<String>,
3416    /// Trailing comments that appeared after this table reference
3417    #[serde(default)]
3418    pub trailing_comments: Vec<String>,
3419    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3420    #[serde(default)]
3421    pub when: Option<Box<HistoricalData>>,
3422    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
3423    #[serde(default)]
3424    pub only: bool,
3425    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
3426    #[serde(default)]
3427    pub final_: bool,
3428    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
3429    #[serde(default, skip_serializing_if = "Option::is_none")]
3430    pub table_sample: Option<Box<Sample>>,
3431    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
3432    #[serde(default)]
3433    pub hints: Vec<Expression>,
3434    /// TSQL: FOR SYSTEM_TIME temporal clause
3435    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
3436    #[serde(default, skip_serializing_if = "Option::is_none")]
3437    pub system_time: Option<String>,
3438    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
3439    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3440    pub partitions: Vec<Identifier>,
3441    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
3442    /// When set, this is used instead of the name field
3443    #[serde(default, skip_serializing_if = "Option::is_none")]
3444    pub identifier_func: Option<Box<Expression>>,
3445    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
3446    #[serde(default, skip_serializing_if = "Option::is_none")]
3447    pub changes: Option<Box<Changes>>,
3448    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
3449    #[serde(default, skip_serializing_if = "Option::is_none")]
3450    pub version: Option<Box<Version>>,
3451    /// Source position span
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub span: Option<Span>,
3454}
3455
3456impl TableRef {
3457    pub fn new(name: impl Into<String>) -> Self {
3458        Self {
3459            name: Identifier::new(name),
3460            schema: None,
3461            catalog: None,
3462            alias: None,
3463            alias_explicit_as: false,
3464            column_aliases: Vec::new(),
3465            leading_comments: Vec::new(),
3466            trailing_comments: Vec::new(),
3467            when: None,
3468            only: false,
3469            final_: false,
3470            table_sample: None,
3471            hints: Vec::new(),
3472            system_time: None,
3473            partitions: Vec::new(),
3474            identifier_func: None,
3475            changes: None,
3476            version: None,
3477            span: None,
3478        }
3479    }
3480
3481    /// Create with a schema qualifier.
3482    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
3483        let mut t = Self::new(name);
3484        t.schema = Some(Identifier::new(schema));
3485        t
3486    }
3487
3488    /// Create with catalog and schema qualifiers.
3489    pub fn new_with_catalog(
3490        name: impl Into<String>,
3491        schema: impl Into<String>,
3492        catalog: impl Into<String>,
3493    ) -> Self {
3494        let mut t = Self::new(name);
3495        t.schema = Some(Identifier::new(schema));
3496        t.catalog = Some(Identifier::new(catalog));
3497        t
3498    }
3499
3500    /// Create from an Identifier, preserving the quoted flag
3501    pub fn from_identifier(name: Identifier) -> Self {
3502        Self {
3503            name,
3504            schema: None,
3505            catalog: None,
3506            alias: None,
3507            alias_explicit_as: false,
3508            column_aliases: Vec::new(),
3509            leading_comments: Vec::new(),
3510            trailing_comments: Vec::new(),
3511            when: None,
3512            only: false,
3513            final_: false,
3514            table_sample: None,
3515            hints: Vec::new(),
3516            system_time: None,
3517            partitions: Vec::new(),
3518            identifier_func: None,
3519            changes: None,
3520            version: None,
3521            span: None,
3522        }
3523    }
3524
3525    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
3526        self.alias = Some(Identifier::new(alias));
3527        self
3528    }
3529
3530    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
3531        self.schema = Some(Identifier::new(schema));
3532        self
3533    }
3534}
3535
3536/// Represent a wildcard star expression (`*`, `table.*`).
3537///
3538/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
3539/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
3540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3541#[cfg_attr(feature = "bindings", derive(TS))]
3542pub struct Star {
3543    /// Optional table qualifier (e.g. `t` in `t.*`).
3544    pub table: Option<Identifier>,
3545    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
3546    pub except: Option<Vec<Identifier>>,
3547    /// REPLACE expressions (BigQuery, Snowflake)
3548    pub replace: Option<Vec<Alias>>,
3549    /// RENAME columns (Snowflake)
3550    pub rename: Option<Vec<(Identifier, Identifier)>>,
3551    /// Trailing comments that appeared after the star
3552    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3553    pub trailing_comments: Vec<String>,
3554    /// Source position span
3555    #[serde(default, skip_serializing_if = "Option::is_none")]
3556    pub span: Option<Span>,
3557}
3558
3559/// Represent a complete SELECT statement.
3560///
3561/// This is the most feature-rich AST node, covering the full surface area of
3562/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
3563/// `Vec` are omitted from the generated SQL when absent.
3564///
3565/// # Key Fields
3566///
3567/// - `expressions` -- the select-list (columns, `*`, computed expressions).
3568/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
3569/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
3570/// - `where_clause` -- the WHERE predicate.
3571/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
3572/// - `having` -- HAVING predicate.
3573/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
3574/// - `limit` / `offset` / `fetch` -- result set limiting.
3575/// - `with` -- Common Table Expressions (CTEs).
3576/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
3577/// - `windows` -- named window definitions (WINDOW w AS ...).
3578///
3579/// Dialect-specific extensions are supported via fields like `prewhere`
3580/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
3581/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
3582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3583#[cfg_attr(feature = "bindings", derive(TS))]
3584pub struct Select {
3585    /// The select-list: columns, expressions, aliases, and wildcards.
3586    pub expressions: Vec<Expression>,
3587    /// The FROM clause, containing one or more table sources.
3588    pub from: Option<From>,
3589    /// JOIN clauses applied after the FROM source.
3590    pub joins: Vec<Join>,
3591    pub lateral_views: Vec<LateralView>,
3592    /// ClickHouse PREWHERE clause
3593    #[serde(default, skip_serializing_if = "Option::is_none")]
3594    pub prewhere: Option<Expression>,
3595    pub where_clause: Option<Where>,
3596    pub group_by: Option<GroupBy>,
3597    pub having: Option<Having>,
3598    pub qualify: Option<Qualify>,
3599    pub order_by: Option<OrderBy>,
3600    pub distribute_by: Option<DistributeBy>,
3601    pub cluster_by: Option<ClusterBy>,
3602    pub sort_by: Option<SortBy>,
3603    pub limit: Option<Limit>,
3604    pub offset: Option<Offset>,
3605    /// ClickHouse LIMIT BY clause expressions
3606    #[serde(default, skip_serializing_if = "Option::is_none")]
3607    pub limit_by: Option<Vec<Expression>>,
3608    pub fetch: Option<Fetch>,
3609    pub distinct: bool,
3610    pub distinct_on: Option<Vec<Expression>>,
3611    pub top: Option<Top>,
3612    pub with: Option<With>,
3613    pub sample: Option<Sample>,
3614    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
3615    #[serde(default, skip_serializing_if = "Option::is_none")]
3616    pub settings: Option<Vec<Expression>>,
3617    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
3618    #[serde(default, skip_serializing_if = "Option::is_none")]
3619    pub format: Option<Expression>,
3620    pub windows: Option<Vec<NamedWindow>>,
3621    pub hint: Option<Hint>,
3622    /// Oracle CONNECT BY clause for hierarchical queries
3623    pub connect: Option<Connect>,
3624    /// SELECT ... INTO table_name for creating tables
3625    pub into: Option<SelectInto>,
3626    /// FOR UPDATE/SHARE locking clauses
3627    #[serde(default)]
3628    pub locks: Vec<Lock>,
3629    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
3630    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3631    pub for_xml: Vec<Expression>,
3632    /// T-SQL FOR JSON clause options (PATH, AUTO, ROOT, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)
3633    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3634    pub for_json: Vec<Expression>,
3635    /// Leading comments before the statement
3636    #[serde(default)]
3637    pub leading_comments: Vec<String>,
3638    /// Comments that appear after SELECT keyword (before expressions)
3639    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
3640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3641    pub post_select_comments: Vec<String>,
3642    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
3643    #[serde(default, skip_serializing_if = "Option::is_none")]
3644    pub kind: Option<String>,
3645    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
3646    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3647    pub operation_modifiers: Vec<String>,
3648    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
3649    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3650    pub qualify_after_window: bool,
3651    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
3652    #[serde(default, skip_serializing_if = "Option::is_none")]
3653    pub option: Option<String>,
3654    /// Redshift-style EXCLUDE clause at the end of the projection list
3655    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
3656    #[serde(default, skip_serializing_if = "Option::is_none")]
3657    pub exclude: Option<Vec<Expression>>,
3658}
3659
3660impl Select {
3661    pub fn new() -> Self {
3662        Self {
3663            expressions: Vec::new(),
3664            from: None,
3665            joins: Vec::new(),
3666            lateral_views: Vec::new(),
3667            prewhere: None,
3668            where_clause: None,
3669            group_by: None,
3670            having: None,
3671            qualify: None,
3672            order_by: None,
3673            distribute_by: None,
3674            cluster_by: None,
3675            sort_by: None,
3676            limit: None,
3677            offset: None,
3678            limit_by: None,
3679            fetch: None,
3680            distinct: false,
3681            distinct_on: None,
3682            top: None,
3683            with: None,
3684            sample: None,
3685            settings: None,
3686            format: None,
3687            windows: None,
3688            hint: None,
3689            connect: None,
3690            into: None,
3691            locks: Vec::new(),
3692            for_xml: Vec::new(),
3693            for_json: Vec::new(),
3694            leading_comments: Vec::new(),
3695            post_select_comments: Vec::new(),
3696            kind: None,
3697            operation_modifiers: Vec::new(),
3698            qualify_after_window: false,
3699            option: None,
3700            exclude: None,
3701        }
3702    }
3703
3704    /// Add a column to select
3705    pub fn column(mut self, expr: Expression) -> Self {
3706        self.expressions.push(expr);
3707        self
3708    }
3709
3710    /// Set the FROM clause
3711    pub fn from(mut self, table: Expression) -> Self {
3712        self.from = Some(From {
3713            expressions: vec![table],
3714        });
3715        self
3716    }
3717
3718    /// Add a WHERE clause
3719    pub fn where_(mut self, condition: Expression) -> Self {
3720        self.where_clause = Some(Where { this: condition });
3721        self
3722    }
3723
3724    /// Set DISTINCT
3725    pub fn distinct(mut self) -> Self {
3726        self.distinct = true;
3727        self
3728    }
3729
3730    /// Add a JOIN
3731    pub fn join(mut self, join: Join) -> Self {
3732        self.joins.push(join);
3733        self
3734    }
3735
3736    /// Set ORDER BY
3737    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
3738        self.order_by = Some(OrderBy {
3739            expressions,
3740            siblings: false,
3741            comments: Vec::new(),
3742        });
3743        self
3744    }
3745
3746    /// Set LIMIT
3747    pub fn limit(mut self, n: Expression) -> Self {
3748        self.limit = Some(Limit {
3749            this: n,
3750            percent: false,
3751            comments: Vec::new(),
3752        });
3753        self
3754    }
3755
3756    /// Set OFFSET
3757    pub fn offset(mut self, n: Expression) -> Self {
3758        self.offset = Some(Offset {
3759            this: n,
3760            rows: None,
3761        });
3762        self
3763    }
3764}
3765
3766impl Default for Select {
3767    fn default() -> Self {
3768        Self::new()
3769    }
3770}
3771
3772/// Represent a UNION set operation between two query expressions.
3773///
3774/// When `all` is true, duplicate rows are preserved (UNION ALL).
3775/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
3776/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
3777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3778#[cfg_attr(feature = "bindings", derive(TS))]
3779pub struct Union {
3780    /// The left-hand query operand.
3781    pub left: Expression,
3782    /// The right-hand query operand.
3783    pub right: Expression,
3784    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
3785    pub all: bool,
3786    /// Whether DISTINCT was explicitly specified
3787    #[serde(default)]
3788    pub distinct: bool,
3789    /// Optional WITH clause
3790    pub with: Option<With>,
3791    /// ORDER BY applied to entire UNION result
3792    pub order_by: Option<OrderBy>,
3793    /// LIMIT applied to entire UNION result
3794    pub limit: Option<Box<Expression>>,
3795    /// OFFSET applied to entire UNION result
3796    pub offset: Option<Box<Expression>>,
3797    /// DISTRIBUTE BY clause (Hive/Spark)
3798    #[serde(default, skip_serializing_if = "Option::is_none")]
3799    pub distribute_by: Option<DistributeBy>,
3800    /// SORT BY clause (Hive/Spark)
3801    #[serde(default, skip_serializing_if = "Option::is_none")]
3802    pub sort_by: Option<SortBy>,
3803    /// CLUSTER BY clause (Hive/Spark)
3804    #[serde(default, skip_serializing_if = "Option::is_none")]
3805    pub cluster_by: Option<ClusterBy>,
3806    /// DuckDB BY NAME modifier
3807    #[serde(default)]
3808    pub by_name: bool,
3809    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3810    #[serde(default, skip_serializing_if = "Option::is_none")]
3811    pub side: Option<String>,
3812    /// BigQuery: Set operation kind (INNER)
3813    #[serde(default, skip_serializing_if = "Option::is_none")]
3814    pub kind: Option<String>,
3815    /// BigQuery: CORRESPONDING modifier
3816    #[serde(default)]
3817    pub corresponding: bool,
3818    /// BigQuery: STRICT modifier (before CORRESPONDING)
3819    #[serde(default)]
3820    pub strict: bool,
3821    /// BigQuery: BY (columns) after CORRESPONDING
3822    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3823    pub on_columns: Vec<Expression>,
3824}
3825
3826/// Iteratively flatten the left-recursive chain to prevent stack overflow
3827/// when dropping deeply nested set operation trees (e.g., 1000+ UNION ALLs).
3828impl Drop for Union {
3829    fn drop(&mut self) {
3830        loop {
3831            if let Expression::Union(ref mut inner) = self.left {
3832                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3833                let old_left = std::mem::replace(&mut self.left, next_left);
3834                drop(old_left);
3835            } else {
3836                break;
3837            }
3838        }
3839    }
3840}
3841
3842/// Represent an INTERSECT set operation between two query expressions.
3843///
3844/// Returns only rows that appear in both operands. When `all` is true,
3845/// duplicates are preserved according to their multiplicity.
3846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3847#[cfg_attr(feature = "bindings", derive(TS))]
3848pub struct Intersect {
3849    /// The left-hand query operand.
3850    pub left: Expression,
3851    /// The right-hand query operand.
3852    pub right: Expression,
3853    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
3854    pub all: bool,
3855    /// Whether DISTINCT was explicitly specified
3856    #[serde(default)]
3857    pub distinct: bool,
3858    /// Optional WITH clause
3859    pub with: Option<With>,
3860    /// ORDER BY applied to entire INTERSECT result
3861    pub order_by: Option<OrderBy>,
3862    /// LIMIT applied to entire INTERSECT result
3863    pub limit: Option<Box<Expression>>,
3864    /// OFFSET applied to entire INTERSECT result
3865    pub offset: Option<Box<Expression>>,
3866    /// DISTRIBUTE BY clause (Hive/Spark)
3867    #[serde(default, skip_serializing_if = "Option::is_none")]
3868    pub distribute_by: Option<DistributeBy>,
3869    /// SORT BY clause (Hive/Spark)
3870    #[serde(default, skip_serializing_if = "Option::is_none")]
3871    pub sort_by: Option<SortBy>,
3872    /// CLUSTER BY clause (Hive/Spark)
3873    #[serde(default, skip_serializing_if = "Option::is_none")]
3874    pub cluster_by: Option<ClusterBy>,
3875    /// DuckDB BY NAME modifier
3876    #[serde(default)]
3877    pub by_name: bool,
3878    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3879    #[serde(default, skip_serializing_if = "Option::is_none")]
3880    pub side: Option<String>,
3881    /// BigQuery: Set operation kind (INNER)
3882    #[serde(default, skip_serializing_if = "Option::is_none")]
3883    pub kind: Option<String>,
3884    /// BigQuery: CORRESPONDING modifier
3885    #[serde(default)]
3886    pub corresponding: bool,
3887    /// BigQuery: STRICT modifier (before CORRESPONDING)
3888    #[serde(default)]
3889    pub strict: bool,
3890    /// BigQuery: BY (columns) after CORRESPONDING
3891    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3892    pub on_columns: Vec<Expression>,
3893}
3894
3895impl Drop for Intersect {
3896    fn drop(&mut self) {
3897        loop {
3898            if let Expression::Intersect(ref mut inner) = self.left {
3899                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3900                let old_left = std::mem::replace(&mut self.left, next_left);
3901                drop(old_left);
3902            } else {
3903                break;
3904            }
3905        }
3906    }
3907}
3908
3909/// Represent an EXCEPT (MINUS) set operation between two query expressions.
3910///
3911/// Returns rows from the left operand that do not appear in the right operand.
3912/// When `all` is true, duplicates are subtracted according to their multiplicity.
3913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3914#[cfg_attr(feature = "bindings", derive(TS))]
3915pub struct Except {
3916    /// The left-hand query operand.
3917    pub left: Expression,
3918    /// The right-hand query operand (rows to subtract).
3919    pub right: Expression,
3920    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
3921    pub all: bool,
3922    /// Whether DISTINCT was explicitly specified
3923    #[serde(default)]
3924    pub distinct: bool,
3925    /// Optional WITH clause
3926    pub with: Option<With>,
3927    /// ORDER BY applied to entire EXCEPT result
3928    pub order_by: Option<OrderBy>,
3929    /// LIMIT applied to entire EXCEPT result
3930    pub limit: Option<Box<Expression>>,
3931    /// OFFSET applied to entire EXCEPT result
3932    pub offset: Option<Box<Expression>>,
3933    /// DISTRIBUTE BY clause (Hive/Spark)
3934    #[serde(default, skip_serializing_if = "Option::is_none")]
3935    pub distribute_by: Option<DistributeBy>,
3936    /// SORT BY clause (Hive/Spark)
3937    #[serde(default, skip_serializing_if = "Option::is_none")]
3938    pub sort_by: Option<SortBy>,
3939    /// CLUSTER BY clause (Hive/Spark)
3940    #[serde(default, skip_serializing_if = "Option::is_none")]
3941    pub cluster_by: Option<ClusterBy>,
3942    /// DuckDB BY NAME modifier
3943    #[serde(default)]
3944    pub by_name: bool,
3945    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
3946    #[serde(default, skip_serializing_if = "Option::is_none")]
3947    pub side: Option<String>,
3948    /// BigQuery: Set operation kind (INNER)
3949    #[serde(default, skip_serializing_if = "Option::is_none")]
3950    pub kind: Option<String>,
3951    /// BigQuery: CORRESPONDING modifier
3952    #[serde(default)]
3953    pub corresponding: bool,
3954    /// BigQuery: STRICT modifier (before CORRESPONDING)
3955    #[serde(default)]
3956    pub strict: bool,
3957    /// BigQuery: BY (columns) after CORRESPONDING
3958    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3959    pub on_columns: Vec<Expression>,
3960}
3961
3962impl Drop for Except {
3963    fn drop(&mut self) {
3964        loop {
3965            if let Expression::Except(ref mut inner) = self.left {
3966                let next_left = std::mem::replace(&mut inner.left, Expression::Null(Null));
3967                let old_left = std::mem::replace(&mut self.left, next_left);
3968                drop(old_left);
3969            } else {
3970                break;
3971            }
3972        }
3973    }
3974}
3975
3976/// INTO clause for SELECT INTO statements
3977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3978#[cfg_attr(feature = "bindings", derive(TS))]
3979pub struct SelectInto {
3980    /// Target table or variable (used when single target)
3981    pub this: Expression,
3982    /// Whether TEMPORARY keyword was used
3983    #[serde(default)]
3984    pub temporary: bool,
3985    /// Whether UNLOGGED keyword was used (PostgreSQL)
3986    #[serde(default)]
3987    pub unlogged: bool,
3988    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
3989    #[serde(default)]
3990    pub bulk_collect: bool,
3991    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
3992    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3993    pub expressions: Vec<Expression>,
3994}
3995
3996/// Represent a parenthesized subquery expression.
3997///
3998/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
3999/// parentheses and optionally applies an alias, column aliases, ORDER BY,
4000/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
4001/// modifiers are rendered inside or outside the parentheses.
4002///
4003/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
4004/// scalar subqueries in select-lists, and derived tables.
4005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4006#[cfg_attr(feature = "bindings", derive(TS))]
4007pub struct Subquery {
4008    /// The inner query expression.
4009    pub this: Expression,
4010    /// Optional alias for the derived table.
4011    pub alias: Option<Identifier>,
4012    /// Optional column aliases: AS t(c1, c2)
4013    pub column_aliases: Vec<Identifier>,
4014    /// ORDER BY clause (for parenthesized queries)
4015    pub order_by: Option<OrderBy>,
4016    /// LIMIT clause
4017    pub limit: Option<Limit>,
4018    /// OFFSET clause
4019    pub offset: Option<Offset>,
4020    /// DISTRIBUTE BY clause (Hive/Spark)
4021    #[serde(default, skip_serializing_if = "Option::is_none")]
4022    pub distribute_by: Option<DistributeBy>,
4023    /// SORT BY clause (Hive/Spark)
4024    #[serde(default, skip_serializing_if = "Option::is_none")]
4025    pub sort_by: Option<SortBy>,
4026    /// CLUSTER BY clause (Hive/Spark)
4027    #[serde(default, skip_serializing_if = "Option::is_none")]
4028    pub cluster_by: Option<ClusterBy>,
4029    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
4030    #[serde(default)]
4031    pub lateral: bool,
4032    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
4033    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
4034    /// false: (SELECT 1) LIMIT 1 - modifiers outside
4035    #[serde(default)]
4036    pub modifiers_inside: bool,
4037    /// Trailing comments after the closing paren
4038    #[serde(default)]
4039    pub trailing_comments: Vec<String>,
4040    /// Inferred data type from type annotation
4041    #[serde(default, skip_serializing_if = "Option::is_none")]
4042    pub inferred_type: Option<DataType>,
4043}
4044
4045/// Pipe operator expression: query |> transform
4046///
4047/// Used in DataFusion and BigQuery pipe syntax:
4048///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
4049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4050#[cfg_attr(feature = "bindings", derive(TS))]
4051pub struct PipeOperator {
4052    /// The input query/expression (left side of |>)
4053    pub this: Expression,
4054    /// The piped operation (right side of |>)
4055    pub expression: Expression,
4056}
4057
4058/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
4059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4060#[cfg_attr(feature = "bindings", derive(TS))]
4061pub struct Values {
4062    /// The rows of values
4063    pub expressions: Vec<Tuple>,
4064    /// Optional alias for the table
4065    pub alias: Option<Identifier>,
4066    /// Optional column aliases: AS t(c1, c2)
4067    pub column_aliases: Vec<Identifier>,
4068}
4069
4070/// PIVOT operation - supports both standard and DuckDB simplified syntax
4071///
4072/// Standard syntax (in FROM clause):
4073///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
4074///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
4075///
4076/// DuckDB simplified syntax (statement-level):
4077///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
4078///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
4079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4080#[cfg_attr(feature = "bindings", derive(TS))]
4081pub struct Pivot {
4082    /// Source table/expression
4083    pub this: Expression,
4084    /// For standard PIVOT: the aggregation function(s) (first is primary)
4085    /// For DuckDB simplified: unused (use `using` instead)
4086    #[serde(default)]
4087    pub expressions: Vec<Expression>,
4088    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
4089    #[serde(default)]
4090    pub fields: Vec<Expression>,
4091    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
4092    #[serde(default)]
4093    pub using: Vec<Expression>,
4094    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
4095    #[serde(default)]
4096    pub group: Option<Box<Expression>>,
4097    /// Whether this is an UNPIVOT (vs PIVOT)
4098    #[serde(default)]
4099    pub unpivot: bool,
4100    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
4101    #[serde(default)]
4102    pub into: Option<Box<Expression>>,
4103    /// Optional alias
4104    #[serde(default)]
4105    pub alias: Option<Identifier>,
4106    /// Include/exclude nulls (for UNPIVOT)
4107    #[serde(default)]
4108    pub include_nulls: Option<bool>,
4109    /// Default on null value (Snowflake)
4110    #[serde(default)]
4111    pub default_on_null: Option<Box<Expression>>,
4112    /// WITH clause (CTEs)
4113    #[serde(default, skip_serializing_if = "Option::is_none")]
4114    pub with: Option<With>,
4115}
4116
4117/// UNPIVOT operation
4118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4119#[cfg_attr(feature = "bindings", derive(TS))]
4120pub struct Unpivot {
4121    pub this: Expression,
4122    pub value_column: Identifier,
4123    pub name_column: Identifier,
4124    pub columns: Vec<Expression>,
4125    pub alias: Option<Identifier>,
4126    /// Whether the value_column was parenthesized in the original SQL
4127    #[serde(default)]
4128    pub value_column_parenthesized: bool,
4129    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
4130    #[serde(default)]
4131    pub include_nulls: Option<bool>,
4132    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
4133    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4134    pub extra_value_columns: Vec<Identifier>,
4135}
4136
4137/// PIVOT alias for aliasing pivot expressions
4138/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
4139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4140#[cfg_attr(feature = "bindings", derive(TS))]
4141pub struct PivotAlias {
4142    pub this: Expression,
4143    pub alias: Expression,
4144}
4145
4146/// PREWHERE clause (ClickHouse) - early filtering before WHERE
4147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4148#[cfg_attr(feature = "bindings", derive(TS))]
4149pub struct PreWhere {
4150    pub this: Expression,
4151}
4152
4153/// STREAM definition (Snowflake) - for change data capture
4154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4155#[cfg_attr(feature = "bindings", derive(TS))]
4156pub struct Stream {
4157    pub this: Expression,
4158    #[serde(skip_serializing_if = "Option::is_none")]
4159    pub on: Option<Expression>,
4160    #[serde(skip_serializing_if = "Option::is_none")]
4161    pub show_initial_rows: Option<bool>,
4162}
4163
4164/// USING DATA clause for data import statements
4165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub struct UsingData {
4168    pub this: Expression,
4169}
4170
4171/// XML Namespace declaration
4172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4173#[cfg_attr(feature = "bindings", derive(TS))]
4174pub struct XmlNamespace {
4175    pub this: Expression,
4176    #[serde(skip_serializing_if = "Option::is_none")]
4177    pub alias: Option<Identifier>,
4178}
4179
4180/// ROW FORMAT clause for Hive/Spark
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct RowFormat {
4184    pub delimited: bool,
4185    pub fields_terminated_by: Option<String>,
4186    pub collection_items_terminated_by: Option<String>,
4187    pub map_keys_terminated_by: Option<String>,
4188    pub lines_terminated_by: Option<String>,
4189    pub null_defined_as: Option<String>,
4190}
4191
4192/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
4193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4194#[cfg_attr(feature = "bindings", derive(TS))]
4195pub struct DirectoryInsert {
4196    pub local: bool,
4197    pub path: String,
4198    pub row_format: Option<RowFormat>,
4199    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
4200    #[serde(default)]
4201    pub stored_as: Option<String>,
4202}
4203
4204/// INSERT statement
4205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4206#[cfg_attr(feature = "bindings", derive(TS))]
4207pub struct Insert {
4208    pub table: TableRef,
4209    pub columns: Vec<Identifier>,
4210    pub values: Vec<Vec<Expression>>,
4211    pub query: Option<Expression>,
4212    /// INSERT OVERWRITE for Hive/Spark
4213    pub overwrite: bool,
4214    /// PARTITION clause for Hive/Spark
4215    pub partition: Vec<(Identifier, Option<Expression>)>,
4216    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
4217    #[serde(default)]
4218    pub directory: Option<DirectoryInsert>,
4219    /// RETURNING clause (PostgreSQL, SQLite)
4220    #[serde(default)]
4221    pub returning: Vec<Expression>,
4222    /// OUTPUT clause (TSQL)
4223    #[serde(default)]
4224    pub output: Option<OutputClause>,
4225    /// ON CONFLICT clause (PostgreSQL, SQLite)
4226    #[serde(default)]
4227    pub on_conflict: Option<Box<Expression>>,
4228    /// Leading comments before the statement
4229    #[serde(default)]
4230    pub leading_comments: Vec<String>,
4231    /// IF EXISTS clause (Hive)
4232    #[serde(default)]
4233    pub if_exists: bool,
4234    /// WITH clause (CTEs)
4235    #[serde(default)]
4236    pub with: Option<With>,
4237    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
4238    #[serde(default)]
4239    pub ignore: bool,
4240    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
4241    #[serde(default)]
4242    pub source_alias: Option<Identifier>,
4243    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
4244    #[serde(default)]
4245    pub alias: Option<Identifier>,
4246    /// Whether the alias uses explicit AS keyword
4247    #[serde(default)]
4248    pub alias_explicit_as: bool,
4249    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
4250    #[serde(default)]
4251    pub default_values: bool,
4252    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
4253    #[serde(default)]
4254    pub by_name: bool,
4255    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
4256    #[serde(default, skip_serializing_if = "Option::is_none")]
4257    pub conflict_action: Option<String>,
4258    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
4259    #[serde(default)]
4260    pub is_replace: bool,
4261    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
4262    #[serde(default, skip_serializing_if = "Option::is_none")]
4263    pub hint: Option<Hint>,
4264    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
4265    #[serde(default)]
4266    pub replace_where: Option<Box<Expression>>,
4267    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
4268    #[serde(default)]
4269    pub source: Option<Box<Expression>>,
4270    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
4271    #[serde(default, skip_serializing_if = "Option::is_none")]
4272    pub function_target: Option<Box<Expression>>,
4273    /// ClickHouse: PARTITION BY expr
4274    #[serde(default, skip_serializing_if = "Option::is_none")]
4275    pub partition_by: Option<Box<Expression>>,
4276    /// ClickHouse: SETTINGS key = val, ...
4277    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4278    pub settings: Vec<Expression>,
4279}
4280
4281/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
4282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4283#[cfg_attr(feature = "bindings", derive(TS))]
4284pub struct OutputClause {
4285    /// Columns/expressions to output
4286    pub columns: Vec<Expression>,
4287    /// Optional INTO target table or table variable
4288    #[serde(default)]
4289    pub into_table: Option<Expression>,
4290}
4291
4292/// UPDATE statement
4293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4294#[cfg_attr(feature = "bindings", derive(TS))]
4295pub struct Update {
4296    pub table: TableRef,
4297    /// Additional tables for multi-table UPDATE (MySQL syntax)
4298    #[serde(default)]
4299    pub extra_tables: Vec<TableRef>,
4300    /// JOINs attached to the table list (MySQL multi-table syntax)
4301    #[serde(default)]
4302    pub table_joins: Vec<Join>,
4303    pub set: Vec<(Identifier, Expression)>,
4304    pub from_clause: Option<From>,
4305    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
4306    #[serde(default)]
4307    pub from_joins: Vec<Join>,
4308    pub where_clause: Option<Where>,
4309    /// RETURNING clause (PostgreSQL, SQLite)
4310    #[serde(default)]
4311    pub returning: Vec<Expression>,
4312    /// OUTPUT clause (TSQL)
4313    #[serde(default)]
4314    pub output: Option<OutputClause>,
4315    /// WITH clause (CTEs)
4316    #[serde(default)]
4317    pub with: Option<With>,
4318    /// Leading comments before the statement
4319    #[serde(default)]
4320    pub leading_comments: Vec<String>,
4321    /// LIMIT clause (MySQL)
4322    #[serde(default)]
4323    pub limit: Option<Expression>,
4324    /// ORDER BY clause (MySQL)
4325    #[serde(default)]
4326    pub order_by: Option<OrderBy>,
4327    /// Whether FROM clause appears before SET (Snowflake syntax)
4328    #[serde(default)]
4329    pub from_before_set: bool,
4330}
4331
4332/// DELETE statement
4333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4334#[cfg_attr(feature = "bindings", derive(TS))]
4335pub struct Delete {
4336    pub table: TableRef,
4337    /// ClickHouse: ON CLUSTER clause for distributed DDL
4338    #[serde(default, skip_serializing_if = "Option::is_none")]
4339    pub on_cluster: Option<OnCluster>,
4340    /// Optional alias for the table
4341    pub alias: Option<Identifier>,
4342    /// Whether the alias was declared with explicit AS keyword
4343    #[serde(default)]
4344    pub alias_explicit_as: bool,
4345    /// PostgreSQL/DuckDB USING clause - additional tables to join
4346    pub using: Vec<TableRef>,
4347    pub where_clause: Option<Where>,
4348    /// OUTPUT clause (TSQL)
4349    #[serde(default)]
4350    pub output: Option<OutputClause>,
4351    /// Leading comments before the statement
4352    #[serde(default)]
4353    pub leading_comments: Vec<String>,
4354    /// WITH clause (CTEs)
4355    #[serde(default)]
4356    pub with: Option<With>,
4357    /// LIMIT clause (MySQL)
4358    #[serde(default)]
4359    pub limit: Option<Expression>,
4360    /// ORDER BY clause (MySQL)
4361    #[serde(default)]
4362    pub order_by: Option<OrderBy>,
4363    /// RETURNING clause (PostgreSQL)
4364    #[serde(default)]
4365    pub returning: Vec<Expression>,
4366    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
4367    /// These are the target tables to delete from
4368    #[serde(default)]
4369    pub tables: Vec<TableRef>,
4370    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
4371    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
4372    #[serde(default)]
4373    pub tables_from_using: bool,
4374    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
4375    #[serde(default)]
4376    pub joins: Vec<Join>,
4377    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
4378    #[serde(default)]
4379    pub force_index: Option<String>,
4380    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
4381    #[serde(default)]
4382    pub no_from: bool,
4383}
4384
4385/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
4386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4387#[cfg_attr(feature = "bindings", derive(TS))]
4388pub struct CopyStmt {
4389    /// Target table or query
4390    pub this: Expression,
4391    /// True for FROM (loading into table), false for TO (exporting)
4392    pub kind: bool,
4393    /// Source/destination file(s) or stage
4394    pub files: Vec<Expression>,
4395    /// Copy parameters
4396    #[serde(default)]
4397    pub params: Vec<CopyParameter>,
4398    /// Credentials for external access
4399    #[serde(default)]
4400    pub credentials: Option<Box<Credentials>>,
4401    /// Whether the INTO keyword was used (COPY INTO vs COPY)
4402    #[serde(default)]
4403    pub is_into: bool,
4404    /// Whether parameters are wrapped in WITH (...) syntax
4405    #[serde(default)]
4406    pub with_wrapped: bool,
4407}
4408
4409/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
4410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4411#[cfg_attr(feature = "bindings", derive(TS))]
4412pub struct CopyParameter {
4413    pub name: String,
4414    pub value: Option<Expression>,
4415    pub values: Vec<Expression>,
4416    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
4417    #[serde(default)]
4418    pub eq: bool,
4419}
4420
4421/// Credentials for external access (S3, Azure, etc.)
4422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4423#[cfg_attr(feature = "bindings", derive(TS))]
4424pub struct Credentials {
4425    pub credentials: Vec<(String, String)>,
4426    pub encryption: Option<String>,
4427    pub storage: Option<String>,
4428}
4429
4430/// PUT statement (Snowflake)
4431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4432#[cfg_attr(feature = "bindings", derive(TS))]
4433pub struct PutStmt {
4434    /// Source file path
4435    pub source: String,
4436    /// Whether source was quoted in the original SQL
4437    #[serde(default)]
4438    pub source_quoted: bool,
4439    /// Target stage
4440    pub target: Expression,
4441    /// PUT parameters
4442    #[serde(default)]
4443    pub params: Vec<CopyParameter>,
4444}
4445
4446/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct StageReference {
4450    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
4451    pub name: String,
4452    /// Optional path within the stage (e.g., "/path/to/file.csv")
4453    #[serde(default)]
4454    pub path: Option<String>,
4455    /// Optional FILE_FORMAT parameter
4456    #[serde(default)]
4457    pub file_format: Option<Expression>,
4458    /// Optional PATTERN parameter
4459    #[serde(default)]
4460    pub pattern: Option<String>,
4461    /// Whether the stage reference was originally quoted (e.g., '@mystage')
4462    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4463    pub quoted: bool,
4464}
4465
4466/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
4467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4468#[cfg_attr(feature = "bindings", derive(TS))]
4469pub struct HistoricalData {
4470    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
4471    pub this: Box<Expression>,
4472    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
4473    pub kind: String,
4474    /// The expression value (e.g., the statement ID or timestamp)
4475    pub expression: Box<Expression>,
4476}
4477
4478/// Represent an aliased expression (`expr AS name`).
4479///
4480/// Used for column aliases in select-lists, table aliases on subqueries,
4481/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
4482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4483#[cfg_attr(feature = "bindings", derive(TS))]
4484pub struct Alias {
4485    /// The expression being aliased.
4486    pub this: Expression,
4487    /// The alias name (required for simple aliases, optional when only column aliases provided)
4488    pub alias: Identifier,
4489    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
4490    #[serde(default)]
4491    pub column_aliases: Vec<Identifier>,
4492    /// Comments that appeared between the expression and AS keyword
4493    #[serde(default)]
4494    pub pre_alias_comments: Vec<String>,
4495    /// Trailing comments that appeared after the alias
4496    #[serde(default)]
4497    pub trailing_comments: Vec<String>,
4498    /// Inferred data type from type annotation
4499    #[serde(default, skip_serializing_if = "Option::is_none")]
4500    pub inferred_type: Option<DataType>,
4501}
4502
4503impl Alias {
4504    /// Create a simple alias
4505    pub fn new(this: Expression, alias: Identifier) -> Self {
4506        Self {
4507            this,
4508            alias,
4509            column_aliases: Vec::new(),
4510            pre_alias_comments: Vec::new(),
4511            trailing_comments: Vec::new(),
4512            inferred_type: None,
4513        }
4514    }
4515
4516    /// Create an alias with column aliases only (no table alias name)
4517    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
4518        Self {
4519            this,
4520            alias: Identifier::empty(),
4521            column_aliases,
4522            pre_alias_comments: Vec::new(),
4523            trailing_comments: Vec::new(),
4524            inferred_type: None,
4525        }
4526    }
4527}
4528
4529/// Represent a type cast expression.
4530///
4531/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
4532/// shorthand `expr::type`. Also used as the payload for `TryCast` and
4533/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
4534/// CONVERSION ERROR (Oracle) clauses.
4535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4536#[cfg_attr(feature = "bindings", derive(TS))]
4537pub struct Cast {
4538    /// The expression being cast.
4539    pub this: Expression,
4540    /// The target data type.
4541    pub to: DataType,
4542    #[serde(default)]
4543    pub trailing_comments: Vec<String>,
4544    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
4545    #[serde(default)]
4546    pub double_colon_syntax: bool,
4547    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
4548    #[serde(skip_serializing_if = "Option::is_none", default)]
4549    pub format: Option<Box<Expression>>,
4550    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
4551    #[serde(skip_serializing_if = "Option::is_none", default)]
4552    pub default: Option<Box<Expression>>,
4553    /// Inferred data type from type annotation
4554    #[serde(default, skip_serializing_if = "Option::is_none")]
4555    pub inferred_type: Option<DataType>,
4556}
4557
4558///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
4559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4560#[cfg_attr(feature = "bindings", derive(TS))]
4561pub struct CollationExpr {
4562    pub this: Expression,
4563    pub collation: String,
4564    /// True if the collation was single-quoted in the original SQL (string literal)
4565    #[serde(default)]
4566    pub quoted: bool,
4567    /// True if the collation was double-quoted in the original SQL (identifier)
4568    #[serde(default)]
4569    pub double_quoted: bool,
4570}
4571
4572/// Represent a CASE expression (both simple and searched forms).
4573///
4574/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
4575/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
4576/// Each entry in `whens` is a `(condition, result)` pair.
4577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4578#[cfg_attr(feature = "bindings", derive(TS))]
4579pub struct Case {
4580    /// The operand for simple CASE, or `None` for searched CASE.
4581    pub operand: Option<Expression>,
4582    /// Pairs of (WHEN condition, THEN result).
4583    pub whens: Vec<(Expression, Expression)>,
4584    /// Optional ELSE result.
4585    pub else_: Option<Expression>,
4586    /// Comments from the CASE keyword (emitted after END)
4587    #[serde(default)]
4588    #[serde(skip_serializing_if = "Vec::is_empty")]
4589    pub comments: Vec<String>,
4590    /// Inferred data type from type annotation
4591    #[serde(default, skip_serializing_if = "Option::is_none")]
4592    pub inferred_type: Option<DataType>,
4593}
4594
4595/// Represent a binary operation (two operands separated by an operator).
4596///
4597/// This is the shared payload struct for all binary operator variants in the
4598/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
4599/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
4600/// bitwise, and dialect-specific operators. Comment fields enable round-trip
4601/// preservation of inline comments around operators.
4602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4603#[cfg_attr(feature = "bindings", derive(TS))]
4604pub struct BinaryOp {
4605    pub left: Expression,
4606    pub right: Expression,
4607    /// Comments after the left operand (before the operator)
4608    #[serde(default)]
4609    pub left_comments: Vec<String>,
4610    /// Comments after the operator (before the right operand)
4611    #[serde(default)]
4612    pub operator_comments: Vec<String>,
4613    /// Comments after the right operand
4614    #[serde(default)]
4615    pub trailing_comments: Vec<String>,
4616    /// Inferred data type from type annotation
4617    #[serde(default, skip_serializing_if = "Option::is_none")]
4618    pub inferred_type: Option<DataType>,
4619}
4620
4621impl BinaryOp {
4622    pub fn new(left: Expression, right: Expression) -> Self {
4623        Self {
4624            left,
4625            right,
4626            left_comments: Vec::new(),
4627            operator_comments: Vec::new(),
4628            trailing_comments: Vec::new(),
4629            inferred_type: None,
4630        }
4631    }
4632}
4633
4634/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
4635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4636#[cfg_attr(feature = "bindings", derive(TS))]
4637pub struct LikeOp {
4638    pub left: Expression,
4639    pub right: Expression,
4640    /// ESCAPE character/expression
4641    #[serde(default)]
4642    pub escape: Option<Expression>,
4643    /// Quantifier: ANY, ALL, or SOME
4644    #[serde(default)]
4645    pub quantifier: Option<String>,
4646    /// Inferred data type from type annotation
4647    #[serde(default, skip_serializing_if = "Option::is_none")]
4648    pub inferred_type: Option<DataType>,
4649}
4650
4651impl LikeOp {
4652    pub fn new(left: Expression, right: Expression) -> Self {
4653        Self {
4654            left,
4655            right,
4656            escape: None,
4657            quantifier: None,
4658            inferred_type: None,
4659        }
4660    }
4661
4662    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
4663        Self {
4664            left,
4665            right,
4666            escape: Some(escape),
4667            quantifier: None,
4668            inferred_type: None,
4669        }
4670    }
4671}
4672
4673/// Represent a unary operation (single operand with a prefix operator).
4674///
4675/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
4676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4677#[cfg_attr(feature = "bindings", derive(TS))]
4678pub struct UnaryOp {
4679    /// The operand expression.
4680    pub this: Expression,
4681    /// Inferred data type from type annotation
4682    #[serde(default, skip_serializing_if = "Option::is_none")]
4683    pub inferred_type: Option<DataType>,
4684}
4685
4686impl UnaryOp {
4687    pub fn new(this: Expression) -> Self {
4688        Self {
4689            this,
4690            inferred_type: None,
4691        }
4692    }
4693}
4694
4695/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
4696///
4697/// Either `expressions` (a value list) or `query` (a subquery) is populated,
4698/// but not both. When `not` is true, the predicate is `NOT IN`.
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct In {
4702    /// The expression being tested.
4703    pub this: Expression,
4704    /// The value list (mutually exclusive with `query`).
4705    pub expressions: Vec<Expression>,
4706    /// A subquery (mutually exclusive with `expressions`).
4707    pub query: Option<Expression>,
4708    /// Whether this is NOT IN.
4709    pub not: bool,
4710    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4711    pub global: bool,
4712    /// BigQuery: IN UNNEST(expr)
4713    #[serde(default, skip_serializing_if = "Option::is_none")]
4714    pub unnest: Option<Box<Expression>>,
4715    /// Whether the right side is a bare field reference (no parentheses).
4716    /// Matches Python sqlglot's `field` attribute on `In` expression.
4717    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
4718    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4719    pub is_field: bool,
4720}
4721
4722/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
4723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4724#[cfg_attr(feature = "bindings", derive(TS))]
4725pub struct Between {
4726    /// The expression being tested.
4727    pub this: Expression,
4728    /// The lower bound.
4729    pub low: Expression,
4730    /// The upper bound.
4731    pub high: Expression,
4732    /// Whether this is NOT BETWEEN.
4733    pub not: bool,
4734    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
4735    #[serde(default)]
4736    pub symmetric: Option<bool>,
4737}
4738
4739/// IS NULL predicate
4740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4741#[cfg_attr(feature = "bindings", derive(TS))]
4742pub struct IsNull {
4743    pub this: Expression,
4744    pub not: bool,
4745    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
4746    #[serde(default)]
4747    pub postfix_form: bool,
4748}
4749
4750/// IS TRUE / IS FALSE predicate
4751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4752#[cfg_attr(feature = "bindings", derive(TS))]
4753pub struct IsTrueFalse {
4754    pub this: Expression,
4755    pub not: bool,
4756}
4757
4758/// IS JSON predicate (SQL standard)
4759/// Checks if a value is valid JSON
4760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4761#[cfg_attr(feature = "bindings", derive(TS))]
4762pub struct IsJson {
4763    pub this: Expression,
4764    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
4765    pub json_type: Option<String>,
4766    /// Key uniqueness constraint
4767    pub unique_keys: Option<JsonUniqueKeys>,
4768    /// Whether IS NOT JSON
4769    pub negated: bool,
4770}
4771
4772/// JSON unique keys constraint variants
4773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4774#[cfg_attr(feature = "bindings", derive(TS))]
4775pub enum JsonUniqueKeys {
4776    /// WITH UNIQUE KEYS
4777    With,
4778    /// WITHOUT UNIQUE KEYS
4779    Without,
4780    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
4781    Shorthand,
4782}
4783
4784/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
4785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4786#[cfg_attr(feature = "bindings", derive(TS))]
4787pub struct Exists {
4788    /// The subquery expression.
4789    pub this: Expression,
4790    /// Whether this is NOT EXISTS.
4791    pub not: bool,
4792}
4793
4794/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
4795///
4796/// This is the generic function node. Well-known aggregates, window functions,
4797/// and built-in functions each have their own dedicated `Expression` variants
4798/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
4799/// not recognize as built-ins are represented with this struct.
4800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4801#[cfg_attr(feature = "bindings", derive(TS))]
4802pub struct Function {
4803    /// The function name, as originally written (may be schema-qualified).
4804    pub name: String,
4805    /// Positional arguments to the function.
4806    pub args: Vec<Expression>,
4807    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
4808    pub distinct: bool,
4809    #[serde(default)]
4810    pub trailing_comments: Vec<String>,
4811    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
4812    #[serde(default)]
4813    pub use_bracket_syntax: bool,
4814    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
4815    #[serde(default)]
4816    pub no_parens: bool,
4817    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
4818    #[serde(default)]
4819    pub quoted: bool,
4820    /// Source position span
4821    #[serde(default, skip_serializing_if = "Option::is_none")]
4822    pub span: Option<Span>,
4823    /// Inferred data type from type annotation
4824    #[serde(default, skip_serializing_if = "Option::is_none")]
4825    pub inferred_type: Option<DataType>,
4826}
4827
4828impl Default for Function {
4829    fn default() -> Self {
4830        Self {
4831            name: String::new(),
4832            args: Vec::new(),
4833            distinct: false,
4834            trailing_comments: Vec::new(),
4835            use_bracket_syntax: false,
4836            no_parens: false,
4837            quoted: false,
4838            span: None,
4839            inferred_type: None,
4840        }
4841    }
4842}
4843
4844impl Function {
4845    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
4846        Self {
4847            name: name.into(),
4848            args,
4849            distinct: false,
4850            trailing_comments: Vec::new(),
4851            use_bracket_syntax: false,
4852            no_parens: false,
4853            quoted: false,
4854            span: None,
4855            inferred_type: None,
4856        }
4857    }
4858}
4859
4860/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
4861///
4862/// This struct is used for aggregate function calls that are not covered by
4863/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
4864/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
4865/// IGNORE NULLS / RESPECT NULLS modifiers.
4866#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4867#[cfg_attr(feature = "bindings", derive(TS))]
4868pub struct AggregateFunction {
4869    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
4870    pub name: String,
4871    /// Positional arguments.
4872    pub args: Vec<Expression>,
4873    /// Whether DISTINCT was specified.
4874    pub distinct: bool,
4875    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
4876    pub filter: Option<Expression>,
4877    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
4878    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4879    pub order_by: Vec<Ordered>,
4880    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
4881    #[serde(default, skip_serializing_if = "Option::is_none")]
4882    pub limit: Option<Box<Expression>>,
4883    /// IGNORE NULLS / RESPECT NULLS
4884    #[serde(default, skip_serializing_if = "Option::is_none")]
4885    pub ignore_nulls: Option<bool>,
4886    /// Inferred data type from type annotation
4887    #[serde(default, skip_serializing_if = "Option::is_none")]
4888    pub inferred_type: Option<DataType>,
4889}
4890
4891/// Represent a window function call with its OVER clause.
4892///
4893/// The inner `this` expression is typically a window-specific expression
4894/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
4895/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
4896/// frame specification.
4897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4898#[cfg_attr(feature = "bindings", derive(TS))]
4899pub struct WindowFunction {
4900    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
4901    pub this: Expression,
4902    /// The OVER clause defining the window partitioning, ordering, and frame.
4903    pub over: Over,
4904    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
4905    #[serde(default, skip_serializing_if = "Option::is_none")]
4906    pub keep: Option<Keep>,
4907    /// Inferred data type from type annotation
4908    #[serde(default, skip_serializing_if = "Option::is_none")]
4909    pub inferred_type: Option<DataType>,
4910}
4911
4912/// Oracle KEEP clause for aggregate functions
4913/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
4914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4915#[cfg_attr(feature = "bindings", derive(TS))]
4916pub struct Keep {
4917    /// true = FIRST, false = LAST
4918    pub first: bool,
4919    /// ORDER BY clause inside KEEP
4920    pub order_by: Vec<Ordered>,
4921}
4922
4923/// WITHIN GROUP clause (for ordered-set aggregate functions)
4924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4925#[cfg_attr(feature = "bindings", derive(TS))]
4926pub struct WithinGroup {
4927    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
4928    pub this: Expression,
4929    /// The ORDER BY clause within the group
4930    pub order_by: Vec<Ordered>,
4931}
4932
4933/// Represent the FROM clause of a SELECT statement.
4934///
4935/// Contains one or more table sources (tables, subqueries, table-valued
4936/// functions, etc.). Multiple entries represent comma-separated implicit joins.
4937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4938#[cfg_attr(feature = "bindings", derive(TS))]
4939pub struct From {
4940    /// The table source expressions.
4941    pub expressions: Vec<Expression>,
4942}
4943
4944/// Represent a JOIN clause between two table sources.
4945///
4946/// The join condition can be specified via `on` (ON predicate) or `using`
4947/// (USING column list), but not both. The `kind` field determines the join
4948/// type (INNER, LEFT, CROSS, etc.).
4949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4950#[cfg_attr(feature = "bindings", derive(TS))]
4951pub struct Join {
4952    /// The right-hand table expression being joined.
4953    pub this: Expression,
4954    /// The ON condition (mutually exclusive with `using`).
4955    pub on: Option<Expression>,
4956    /// The USING column list (mutually exclusive with `on`).
4957    pub using: Vec<Identifier>,
4958    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
4959    pub kind: JoinKind,
4960    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
4961    pub use_inner_keyword: bool,
4962    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
4963    pub use_outer_keyword: bool,
4964    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
4965    pub deferred_condition: bool,
4966    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
4967    #[serde(default, skip_serializing_if = "Option::is_none")]
4968    pub join_hint: Option<String>,
4969    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
4970    #[serde(default, skip_serializing_if = "Option::is_none")]
4971    pub match_condition: Option<Expression>,
4972    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
4973    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4974    pub pivots: Vec<Expression>,
4975    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
4976    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4977    pub comments: Vec<String>,
4978    /// Nesting group identifier for nested join pretty-printing.
4979    /// Joins in the same group were parsed together; group boundaries come from
4980    /// deferred condition resolution phases.
4981    #[serde(default)]
4982    pub nesting_group: usize,
4983    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
4984    #[serde(default)]
4985    pub directed: bool,
4986}
4987
4988/// Enumerate all supported SQL join types.
4989///
4990/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
4991/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
4992/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
4993/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
4994#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4995#[cfg_attr(feature = "bindings", derive(TS))]
4996pub enum JoinKind {
4997    Inner,
4998    Left,
4999    Right,
5000    Full,
5001    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
5002    Cross,
5003    Natural,
5004    NaturalLeft,
5005    NaturalRight,
5006    NaturalFull,
5007    Semi,
5008    Anti,
5009    // Directional SEMI/ANTI joins
5010    LeftSemi,
5011    LeftAnti,
5012    RightSemi,
5013    RightAnti,
5014    // SQL Server specific
5015    CrossApply,
5016    OuterApply,
5017    // Time-series specific
5018    AsOf,
5019    AsOfLeft,
5020    AsOfRight,
5021    // Lateral join
5022    Lateral,
5023    LeftLateral,
5024    // MySQL specific
5025    Straight,
5026    // Implicit join (comma-separated tables: FROM a, b)
5027    Implicit,
5028    // ClickHouse ARRAY JOIN
5029    Array,
5030    LeftArray,
5031    // ClickHouse PASTE JOIN (positional join)
5032    Paste,
5033    // DuckDB POSITIONAL JOIN
5034    Positional,
5035}
5036
5037impl Default for JoinKind {
5038    fn default() -> Self {
5039        JoinKind::Inner
5040    }
5041}
5042
5043/// Parenthesized table expression with joins
5044/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
5045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5046#[cfg_attr(feature = "bindings", derive(TS))]
5047pub struct JoinedTable {
5048    /// The left-hand side table expression
5049    pub left: Expression,
5050    /// The joins applied to the left table
5051    pub joins: Vec<Join>,
5052    /// LATERAL VIEW clauses (Hive/Spark)
5053    pub lateral_views: Vec<LateralView>,
5054    /// Optional alias for the joined table expression
5055    pub alias: Option<Identifier>,
5056}
5057
5058/// Represent a WHERE clause containing a boolean filter predicate.
5059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5060#[cfg_attr(feature = "bindings", derive(TS))]
5061pub struct Where {
5062    /// The filter predicate expression.
5063    pub this: Expression,
5064}
5065
5066/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
5067///
5068/// The `expressions` list may contain plain columns, ordinal positions,
5069/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
5070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5071#[cfg_attr(feature = "bindings", derive(TS))]
5072pub struct GroupBy {
5073    /// The grouping expressions.
5074    pub expressions: Vec<Expression>,
5075    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
5076    #[serde(default)]
5077    pub all: Option<bool>,
5078    /// ClickHouse: WITH TOTALS modifier
5079    #[serde(default)]
5080    pub totals: bool,
5081    /// Leading comments that appeared before the GROUP BY keyword
5082    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5083    pub comments: Vec<String>,
5084}
5085
5086/// Represent a HAVING clause containing a predicate over aggregate results.
5087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5088#[cfg_attr(feature = "bindings", derive(TS))]
5089pub struct Having {
5090    /// The filter predicate, typically involving aggregate functions.
5091    pub this: Expression,
5092    /// Leading comments that appeared before the HAVING keyword
5093    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5094    pub comments: Vec<String>,
5095}
5096
5097/// Represent an ORDER BY clause containing one or more sort specifications.
5098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5099#[cfg_attr(feature = "bindings", derive(TS))]
5100pub struct OrderBy {
5101    /// The sort specifications, each with direction and null ordering.
5102    pub expressions: Vec<Ordered>,
5103    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
5104    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5105    pub siblings: bool,
5106    /// Leading comments that appeared before the ORDER BY keyword
5107    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5108    pub comments: Vec<String>,
5109}
5110
5111/// Represent an expression with sort direction and null ordering.
5112///
5113/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
5114/// When `desc` is false the sort is ascending. The `nulls_first` field
5115/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
5116/// (database default).
5117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5118#[cfg_attr(feature = "bindings", derive(TS))]
5119pub struct Ordered {
5120    /// The expression to sort by.
5121    pub this: Expression,
5122    /// Whether the sort direction is descending (true) or ascending (false).
5123    pub desc: bool,
5124    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
5125    pub nulls_first: Option<bool>,
5126    /// Whether ASC was explicitly written (not just implied)
5127    #[serde(default)]
5128    pub explicit_asc: bool,
5129    /// ClickHouse WITH FILL clause
5130    #[serde(default, skip_serializing_if = "Option::is_none")]
5131    pub with_fill: Option<Box<WithFill>>,
5132}
5133
5134impl Ordered {
5135    pub fn asc(expr: Expression) -> Self {
5136        Self {
5137            this: expr,
5138            desc: false,
5139            nulls_first: None,
5140            explicit_asc: false,
5141            with_fill: None,
5142        }
5143    }
5144
5145    pub fn desc(expr: Expression) -> Self {
5146        Self {
5147            this: expr,
5148            desc: true,
5149            nulls_first: None,
5150            explicit_asc: false,
5151            with_fill: None,
5152        }
5153    }
5154}
5155
5156/// DISTRIBUTE BY clause (Hive/Spark)
5157/// Controls how rows are distributed across reducers
5158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5159#[cfg_attr(feature = "bindings", derive(TS))]
5160#[cfg_attr(feature = "bindings", ts(export))]
5161pub struct DistributeBy {
5162    pub expressions: Vec<Expression>,
5163}
5164
5165/// CLUSTER BY clause (Hive/Spark)
5166/// Combines DISTRIBUTE BY and SORT BY on the same columns
5167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5168#[cfg_attr(feature = "bindings", derive(TS))]
5169#[cfg_attr(feature = "bindings", ts(export))]
5170pub struct ClusterBy {
5171    pub expressions: Vec<Ordered>,
5172}
5173
5174/// SORT BY clause (Hive/Spark)
5175/// Sorts data within each reducer (local sort, not global)
5176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5177#[cfg_attr(feature = "bindings", derive(TS))]
5178#[cfg_attr(feature = "bindings", ts(export))]
5179pub struct SortBy {
5180    pub expressions: Vec<Ordered>,
5181}
5182
5183/// LATERAL VIEW clause (Hive/Spark)
5184/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
5185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5186#[cfg_attr(feature = "bindings", derive(TS))]
5187#[cfg_attr(feature = "bindings", ts(export))]
5188pub struct LateralView {
5189    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
5190    pub this: Expression,
5191    /// Table alias for the generated table
5192    pub table_alias: Option<Identifier>,
5193    /// Column aliases for the generated columns
5194    pub column_aliases: Vec<Identifier>,
5195    /// OUTER keyword - preserve nulls when input is empty/null
5196    pub outer: bool,
5197}
5198
5199/// Query hint
5200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5201#[cfg_attr(feature = "bindings", derive(TS))]
5202#[cfg_attr(feature = "bindings", ts(export))]
5203pub struct Hint {
5204    pub expressions: Vec<HintExpression>,
5205}
5206
5207/// Individual hint expression
5208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5209#[cfg_attr(feature = "bindings", derive(TS))]
5210#[cfg_attr(feature = "bindings", ts(export))]
5211pub enum HintExpression {
5212    /// Function-style hint: USE_HASH(table)
5213    Function { name: String, args: Vec<Expression> },
5214    /// Simple identifier hint: PARALLEL
5215    Identifier(String),
5216    /// Raw hint text (unparsed)
5217    Raw(String),
5218}
5219
5220/// Pseudocolumn type
5221#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5222#[cfg_attr(feature = "bindings", derive(TS))]
5223#[cfg_attr(feature = "bindings", ts(export))]
5224pub enum PseudocolumnType {
5225    Rownum,      // Oracle ROWNUM
5226    Rowid,       // Oracle ROWID
5227    Level,       // Oracle LEVEL (for CONNECT BY)
5228    Sysdate,     // Oracle SYSDATE
5229    ObjectId,    // Oracle OBJECT_ID
5230    ObjectValue, // Oracle OBJECT_VALUE
5231}
5232
5233impl PseudocolumnType {
5234    pub fn as_str(&self) -> &'static str {
5235        match self {
5236            PseudocolumnType::Rownum => "ROWNUM",
5237            PseudocolumnType::Rowid => "ROWID",
5238            PseudocolumnType::Level => "LEVEL",
5239            PseudocolumnType::Sysdate => "SYSDATE",
5240            PseudocolumnType::ObjectId => "OBJECT_ID",
5241            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
5242        }
5243    }
5244
5245    pub fn from_str(s: &str) -> Option<Self> {
5246        match s.to_uppercase().as_str() {
5247            "ROWNUM" => Some(PseudocolumnType::Rownum),
5248            "ROWID" => Some(PseudocolumnType::Rowid),
5249            "LEVEL" => Some(PseudocolumnType::Level),
5250            "SYSDATE" => Some(PseudocolumnType::Sysdate),
5251            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
5252            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
5253            _ => None,
5254        }
5255    }
5256}
5257
5258/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
5259/// These are special identifiers that should not be quoted
5260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5261#[cfg_attr(feature = "bindings", derive(TS))]
5262#[cfg_attr(feature = "bindings", ts(export))]
5263pub struct Pseudocolumn {
5264    pub kind: PseudocolumnType,
5265}
5266
5267impl Pseudocolumn {
5268    pub fn rownum() -> Self {
5269        Self {
5270            kind: PseudocolumnType::Rownum,
5271        }
5272    }
5273
5274    pub fn rowid() -> Self {
5275        Self {
5276            kind: PseudocolumnType::Rowid,
5277        }
5278    }
5279
5280    pub fn level() -> Self {
5281        Self {
5282            kind: PseudocolumnType::Level,
5283        }
5284    }
5285}
5286
5287/// Oracle CONNECT BY clause for hierarchical queries
5288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5289#[cfg_attr(feature = "bindings", derive(TS))]
5290#[cfg_attr(feature = "bindings", ts(export))]
5291pub struct Connect {
5292    /// START WITH condition (optional, can come before or after CONNECT BY)
5293    pub start: Option<Expression>,
5294    /// CONNECT BY condition (required, contains PRIOR references)
5295    pub connect: Expression,
5296    /// NOCYCLE keyword to prevent infinite loops
5297    pub nocycle: bool,
5298}
5299
5300/// Oracle PRIOR expression - references parent row's value in CONNECT BY
5301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5302#[cfg_attr(feature = "bindings", derive(TS))]
5303#[cfg_attr(feature = "bindings", ts(export))]
5304pub struct Prior {
5305    pub this: Expression,
5306}
5307
5308/// Oracle CONNECT_BY_ROOT function - returns root row's column value
5309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5310#[cfg_attr(feature = "bindings", derive(TS))]
5311#[cfg_attr(feature = "bindings", ts(export))]
5312pub struct ConnectByRoot {
5313    pub this: Expression,
5314}
5315
5316/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
5317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5318#[cfg_attr(feature = "bindings", derive(TS))]
5319#[cfg_attr(feature = "bindings", ts(export))]
5320pub struct MatchRecognize {
5321    /// Source table/expression
5322    pub this: Option<Box<Expression>>,
5323    /// PARTITION BY expressions
5324    pub partition_by: Option<Vec<Expression>>,
5325    /// ORDER BY expressions
5326    pub order_by: Option<Vec<Ordered>>,
5327    /// MEASURES definitions
5328    pub measures: Option<Vec<MatchRecognizeMeasure>>,
5329    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
5330    pub rows: Option<MatchRecognizeRows>,
5331    /// AFTER MATCH SKIP behavior
5332    pub after: Option<MatchRecognizeAfter>,
5333    /// PATTERN definition (stored as raw string for complex regex patterns)
5334    pub pattern: Option<String>,
5335    /// DEFINE clauses (pattern variable definitions)
5336    pub define: Option<Vec<(Identifier, Expression)>>,
5337    /// Optional alias for the result
5338    pub alias: Option<Identifier>,
5339    /// Whether AS keyword was explicitly present before alias
5340    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5341    pub alias_explicit_as: bool,
5342}
5343
5344/// MEASURES expression with optional RUNNING/FINAL semantics
5345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5346#[cfg_attr(feature = "bindings", derive(TS))]
5347#[cfg_attr(feature = "bindings", ts(export))]
5348pub struct MatchRecognizeMeasure {
5349    /// The measure expression
5350    pub this: Expression,
5351    /// RUNNING or FINAL semantics (Snowflake-specific)
5352    pub window_frame: Option<MatchRecognizeSemantics>,
5353}
5354
5355/// Semantics for MEASURES in MATCH_RECOGNIZE
5356#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5357#[cfg_attr(feature = "bindings", derive(TS))]
5358#[cfg_attr(feature = "bindings", ts(export))]
5359pub enum MatchRecognizeSemantics {
5360    Running,
5361    Final,
5362}
5363
5364/// Row output semantics for MATCH_RECOGNIZE
5365#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5366#[cfg_attr(feature = "bindings", derive(TS))]
5367#[cfg_attr(feature = "bindings", ts(export))]
5368pub enum MatchRecognizeRows {
5369    OneRowPerMatch,
5370    AllRowsPerMatch,
5371    AllRowsPerMatchShowEmptyMatches,
5372    AllRowsPerMatchOmitEmptyMatches,
5373    AllRowsPerMatchWithUnmatchedRows,
5374}
5375
5376/// AFTER MATCH SKIP behavior
5377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5378#[cfg_attr(feature = "bindings", derive(TS))]
5379#[cfg_attr(feature = "bindings", ts(export))]
5380pub enum MatchRecognizeAfter {
5381    PastLastRow,
5382    ToNextRow,
5383    ToFirst(Identifier),
5384    ToLast(Identifier),
5385}
5386
5387/// Represent a LIMIT clause that restricts the number of returned rows.
5388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5389#[cfg_attr(feature = "bindings", derive(TS))]
5390pub struct Limit {
5391    /// The limit count expression.
5392    pub this: Expression,
5393    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
5394    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5395    pub percent: bool,
5396    /// Comments from before the LIMIT keyword (emitted after the limit value)
5397    #[serde(default)]
5398    #[serde(skip_serializing_if = "Vec::is_empty")]
5399    pub comments: Vec<String>,
5400}
5401
5402/// OFFSET clause
5403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5404#[cfg_attr(feature = "bindings", derive(TS))]
5405pub struct Offset {
5406    pub this: Expression,
5407    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
5408    #[serde(skip_serializing_if = "Option::is_none", default)]
5409    pub rows: Option<bool>,
5410}
5411
5412/// TOP clause (SQL Server)
5413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5414#[cfg_attr(feature = "bindings", derive(TS))]
5415pub struct Top {
5416    pub this: Expression,
5417    pub percent: bool,
5418    pub with_ties: bool,
5419    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
5420    #[serde(default)]
5421    pub parenthesized: bool,
5422}
5423
5424/// FETCH FIRST/NEXT clause (SQL standard)
5425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5426#[cfg_attr(feature = "bindings", derive(TS))]
5427pub struct Fetch {
5428    /// FIRST or NEXT
5429    pub direction: String,
5430    /// Count expression (optional)
5431    pub count: Option<Expression>,
5432    /// PERCENT modifier
5433    pub percent: bool,
5434    /// ROWS or ROW keyword present
5435    pub rows: bool,
5436    /// WITH TIES modifier
5437    pub with_ties: bool,
5438}
5439
5440/// Represent a QUALIFY clause for filtering on window function results.
5441///
5442/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
5443/// typically references a window function (e.g.
5444/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct Qualify {
5448    /// The filter predicate over window function results.
5449    pub this: Expression,
5450}
5451
5452/// SAMPLE / TABLESAMPLE clause
5453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5454#[cfg_attr(feature = "bindings", derive(TS))]
5455pub struct Sample {
5456    pub method: SampleMethod,
5457    pub size: Expression,
5458    pub seed: Option<Expression>,
5459    /// ClickHouse OFFSET expression after SAMPLE size
5460    #[serde(default)]
5461    pub offset: Option<Expression>,
5462    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
5463    pub unit_after_size: bool,
5464    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
5465    #[serde(default)]
5466    pub use_sample_keyword: bool,
5467    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
5468    #[serde(default)]
5469    pub explicit_method: bool,
5470    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
5471    #[serde(default)]
5472    pub method_before_size: bool,
5473    /// Whether SEED keyword was used (true) or REPEATABLE (false)
5474    #[serde(default)]
5475    pub use_seed_keyword: bool,
5476    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
5477    pub bucket_numerator: Option<Box<Expression>>,
5478    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
5479    pub bucket_denominator: Option<Box<Expression>>,
5480    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
5481    pub bucket_field: Option<Box<Expression>>,
5482    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
5483    #[serde(default)]
5484    pub is_using_sample: bool,
5485    /// Whether the unit was explicitly PERCENT (vs ROWS)
5486    #[serde(default)]
5487    pub is_percent: bool,
5488    /// Whether to suppress method output (for cross-dialect transpilation)
5489    #[serde(default)]
5490    pub suppress_method_output: bool,
5491}
5492
5493/// Sample method
5494#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5495#[cfg_attr(feature = "bindings", derive(TS))]
5496pub enum SampleMethod {
5497    Bernoulli,
5498    System,
5499    Block,
5500    Row,
5501    Percent,
5502    /// Hive bucket sampling
5503    Bucket,
5504    /// DuckDB reservoir sampling
5505    Reservoir,
5506}
5507
5508/// Named window definition (WINDOW w AS (...))
5509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5510#[cfg_attr(feature = "bindings", derive(TS))]
5511pub struct NamedWindow {
5512    pub name: Identifier,
5513    pub spec: Over,
5514}
5515
5516/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
5517///
5518/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
5519/// that reference themselves. Each CTE is defined in the `ctes` vector and
5520/// can be referenced by name in subsequent CTEs and in the main query body.
5521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5522#[cfg_attr(feature = "bindings", derive(TS))]
5523pub struct With {
5524    /// The list of CTE definitions, in order.
5525    pub ctes: Vec<Cte>,
5526    /// Whether the WITH RECURSIVE keyword was used.
5527    pub recursive: bool,
5528    /// Leading comments before the statement
5529    #[serde(default)]
5530    pub leading_comments: Vec<String>,
5531    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
5532    #[serde(default, skip_serializing_if = "Option::is_none")]
5533    pub search: Option<Box<Expression>>,
5534}
5535
5536/// Represent a single Common Table Expression definition.
5537///
5538/// A CTE has a name (`alias`), an optional column list, and a body query.
5539/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
5540/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
5541/// the expression comes before the alias (`alias_first`).
5542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5543#[cfg_attr(feature = "bindings", derive(TS))]
5544pub struct Cte {
5545    /// The CTE name.
5546    pub alias: Identifier,
5547    /// The CTE body (typically a SELECT, UNION, etc.).
5548    pub this: Expression,
5549    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
5550    pub columns: Vec<Identifier>,
5551    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
5552    pub materialized: Option<bool>,
5553    /// USING KEY (columns) for DuckDB recursive CTEs
5554    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5555    pub key_expressions: Vec<Identifier>,
5556    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
5557    #[serde(default)]
5558    pub alias_first: bool,
5559    /// Comments associated with this CTE (placed after alias name, before AS)
5560    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5561    pub comments: Vec<String>,
5562}
5563
5564/// Window specification
5565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5566#[cfg_attr(feature = "bindings", derive(TS))]
5567pub struct WindowSpec {
5568    pub partition_by: Vec<Expression>,
5569    pub order_by: Vec<Ordered>,
5570    pub frame: Option<WindowFrame>,
5571}
5572
5573/// OVER clause
5574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5575#[cfg_attr(feature = "bindings", derive(TS))]
5576pub struct Over {
5577    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
5578    pub window_name: Option<Identifier>,
5579    pub partition_by: Vec<Expression>,
5580    pub order_by: Vec<Ordered>,
5581    pub frame: Option<WindowFrame>,
5582    pub alias: Option<Identifier>,
5583}
5584
5585/// Window frame
5586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5587#[cfg_attr(feature = "bindings", derive(TS))]
5588pub struct WindowFrame {
5589    pub kind: WindowFrameKind,
5590    pub start: WindowFrameBound,
5591    pub end: Option<WindowFrameBound>,
5592    pub exclude: Option<WindowFrameExclude>,
5593    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
5594    #[serde(default, skip_serializing_if = "Option::is_none")]
5595    pub kind_text: Option<String>,
5596    /// Original text of the start bound side keyword (e.g. "preceding")
5597    #[serde(default, skip_serializing_if = "Option::is_none")]
5598    pub start_side_text: Option<String>,
5599    /// Original text of the end bound side keyword
5600    #[serde(default, skip_serializing_if = "Option::is_none")]
5601    pub end_side_text: Option<String>,
5602}
5603
5604#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5605#[cfg_attr(feature = "bindings", derive(TS))]
5606pub enum WindowFrameKind {
5607    Rows,
5608    Range,
5609    Groups,
5610}
5611
5612/// EXCLUDE clause for window frames
5613#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5614#[cfg_attr(feature = "bindings", derive(TS))]
5615pub enum WindowFrameExclude {
5616    CurrentRow,
5617    Group,
5618    Ties,
5619    NoOthers,
5620}
5621
5622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5623#[cfg_attr(feature = "bindings", derive(TS))]
5624pub enum WindowFrameBound {
5625    CurrentRow,
5626    UnboundedPreceding,
5627    UnboundedFollowing,
5628    Preceding(Box<Expression>),
5629    Following(Box<Expression>),
5630    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
5631    BarePreceding,
5632    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
5633    BareFollowing,
5634    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
5635    Value(Box<Expression>),
5636}
5637
5638/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
5639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5640#[cfg_attr(feature = "bindings", derive(TS))]
5641pub struct StructField {
5642    pub name: String,
5643    pub data_type: DataType,
5644    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5645    pub options: Vec<Expression>,
5646    #[serde(default, skip_serializing_if = "Option::is_none")]
5647    pub comment: Option<String>,
5648}
5649
5650impl StructField {
5651    /// Create a new struct field without options
5652    pub fn new(name: String, data_type: DataType) -> Self {
5653        Self {
5654            name,
5655            data_type,
5656            options: Vec::new(),
5657            comment: None,
5658        }
5659    }
5660
5661    /// Create a new struct field with options
5662    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
5663        Self {
5664            name,
5665            data_type,
5666            options,
5667            comment: None,
5668        }
5669    }
5670
5671    /// Create a new struct field with options and comment
5672    pub fn with_options_and_comment(
5673        name: String,
5674        data_type: DataType,
5675        options: Vec<Expression>,
5676        comment: Option<String>,
5677    ) -> Self {
5678        Self {
5679            name,
5680            data_type,
5681            options,
5682            comment,
5683        }
5684    }
5685}
5686
5687/// Enumerate all SQL data types recognized by the parser.
5688///
5689/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
5690/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
5691/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
5692///
5693/// This enum is used in CAST expressions, column definitions, function return
5694/// types, and anywhere a data type specification appears in SQL.
5695///
5696/// Types that do not match any known variant fall through to `Custom { name }`,
5697/// preserving the original type name for round-trip fidelity.
5698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5699#[cfg_attr(feature = "bindings", derive(TS))]
5700#[serde(tag = "data_type", rename_all = "snake_case")]
5701pub enum DataType {
5702    // Numeric
5703    Boolean,
5704    TinyInt {
5705        length: Option<u32>,
5706    },
5707    SmallInt {
5708        length: Option<u32>,
5709    },
5710    /// Int type with optional length. `integer_spelling` indicates whether the original
5711    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
5712    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
5713    Int {
5714        length: Option<u32>,
5715        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5716        integer_spelling: bool,
5717    },
5718    BigInt {
5719        length: Option<u32>,
5720    },
5721    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
5722    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
5723    /// preserve the original spelling.
5724    Float {
5725        precision: Option<u32>,
5726        scale: Option<u32>,
5727        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5728        real_spelling: bool,
5729    },
5730    Double {
5731        precision: Option<u32>,
5732        scale: Option<u32>,
5733    },
5734    Decimal {
5735        precision: Option<u32>,
5736        scale: Option<u32>,
5737    },
5738
5739    // String
5740    Char {
5741        length: Option<u32>,
5742    },
5743    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
5744    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
5745    VarChar {
5746        length: Option<u32>,
5747        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
5748        parenthesized_length: bool,
5749    },
5750    /// String type with optional max length (BigQuery STRING(n))
5751    String {
5752        length: Option<u32>,
5753    },
5754    Text,
5755    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
5756    TextWithLength {
5757        length: u32,
5758    },
5759
5760    // Binary
5761    Binary {
5762        length: Option<u32>,
5763    },
5764    VarBinary {
5765        length: Option<u32>,
5766    },
5767    Blob,
5768
5769    // Bit
5770    Bit {
5771        length: Option<u32>,
5772    },
5773    VarBit {
5774        length: Option<u32>,
5775    },
5776
5777    // Date/Time
5778    Date,
5779    Time {
5780        precision: Option<u32>,
5781        #[serde(default)]
5782        timezone: bool,
5783    },
5784    Timestamp {
5785        precision: Option<u32>,
5786        timezone: bool,
5787    },
5788    Interval {
5789        unit: Option<String>,
5790        /// For range intervals like INTERVAL DAY TO HOUR
5791        #[serde(default, skip_serializing_if = "Option::is_none")]
5792        to: Option<String>,
5793    },
5794
5795    // JSON
5796    Json,
5797    JsonB,
5798
5799    // UUID
5800    Uuid,
5801
5802    // Array
5803    Array {
5804        element_type: Box<DataType>,
5805        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
5806        #[serde(default, skip_serializing_if = "Option::is_none")]
5807        dimension: Option<u32>,
5808    },
5809
5810    /// List type (Materialize): INT LIST, TEXT LIST LIST
5811    /// Uses postfix LIST syntax instead of ARRAY<T>
5812    List {
5813        element_type: Box<DataType>,
5814    },
5815
5816    // Struct/Map
5817    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
5818    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
5819    Struct {
5820        fields: Vec<StructField>,
5821        nested: bool,
5822    },
5823    Map {
5824        key_type: Box<DataType>,
5825        value_type: Box<DataType>,
5826    },
5827
5828    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
5829    Enum {
5830        values: Vec<String>,
5831        #[serde(default, skip_serializing_if = "Vec::is_empty")]
5832        assignments: Vec<Option<String>>,
5833    },
5834
5835    // Set type (MySQL): SET('a', 'b', 'c')
5836    Set {
5837        values: Vec<String>,
5838    },
5839
5840    // Union type (DuckDB): UNION(num INT, str TEXT)
5841    Union {
5842        fields: Vec<(String, DataType)>,
5843    },
5844
5845    // Vector (Snowflake / SingleStore)
5846    Vector {
5847        #[serde(default)]
5848        element_type: Option<Box<DataType>>,
5849        dimension: Option<u32>,
5850    },
5851
5852    // Object (Snowflake structured type)
5853    // fields: Vec of (field_name, field_type, not_null)
5854    Object {
5855        fields: Vec<(String, DataType, bool)>,
5856        modifier: Option<String>,
5857    },
5858
5859    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
5860    Nullable {
5861        inner: Box<DataType>,
5862    },
5863
5864    // Custom/User-defined
5865    Custom {
5866        name: String,
5867    },
5868
5869    // Spatial types
5870    Geometry {
5871        subtype: Option<String>,
5872        srid: Option<u32>,
5873    },
5874    Geography {
5875        subtype: Option<String>,
5876        srid: Option<u32>,
5877    },
5878
5879    // Character Set (for CONVERT USING in MySQL)
5880    // Renders as CHAR CHARACTER SET {name} in cast target
5881    CharacterSet {
5882        name: String,
5883    },
5884
5885    // Unknown
5886    Unknown,
5887}
5888
5889/// Array expression
5890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5891#[cfg_attr(feature = "bindings", derive(TS))]
5892#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
5893pub struct Array {
5894    pub expressions: Vec<Expression>,
5895}
5896
5897/// Struct expression
5898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5899#[cfg_attr(feature = "bindings", derive(TS))]
5900pub struct Struct {
5901    pub fields: Vec<(Option<String>, Expression)>,
5902}
5903
5904/// Tuple expression
5905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5906#[cfg_attr(feature = "bindings", derive(TS))]
5907pub struct Tuple {
5908    pub expressions: Vec<Expression>,
5909}
5910
5911/// Interval expression
5912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5913#[cfg_attr(feature = "bindings", derive(TS))]
5914pub struct Interval {
5915    /// The value expression (e.g., '1', 5, column_ref)
5916    pub this: Option<Expression>,
5917    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
5918    pub unit: Option<IntervalUnitSpec>,
5919}
5920
5921/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
5922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5923#[cfg_attr(feature = "bindings", derive(TS))]
5924#[serde(tag = "type", rename_all = "snake_case")]
5925pub enum IntervalUnitSpec {
5926    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
5927    Simple {
5928        unit: IntervalUnit,
5929        /// Whether to use plural form (e.g., DAYS vs DAY)
5930        use_plural: bool,
5931    },
5932    /// Interval span (e.g., HOUR TO SECOND)
5933    Span(IntervalSpan),
5934    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5935    /// The start and end can be expressions like function calls with precision
5936    ExprSpan(IntervalSpanExpr),
5937    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
5938    Expr(Box<Expression>),
5939}
5940
5941/// Interval span for ranges like HOUR TO SECOND
5942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5943#[cfg_attr(feature = "bindings", derive(TS))]
5944pub struct IntervalSpan {
5945    /// Start unit (e.g., HOUR)
5946    pub this: IntervalUnit,
5947    /// End unit (e.g., SECOND)
5948    pub expression: IntervalUnit,
5949}
5950
5951/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
5952/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
5953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5954#[cfg_attr(feature = "bindings", derive(TS))]
5955pub struct IntervalSpanExpr {
5956    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
5957    pub this: Box<Expression>,
5958    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
5959    pub expression: Box<Expression>,
5960}
5961
5962#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5963#[cfg_attr(feature = "bindings", derive(TS))]
5964pub enum IntervalUnit {
5965    Year,
5966    Quarter,
5967    Month,
5968    Week,
5969    Day,
5970    Hour,
5971    Minute,
5972    Second,
5973    Millisecond,
5974    Microsecond,
5975    Nanosecond,
5976}
5977
5978/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
5979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5980#[cfg_attr(feature = "bindings", derive(TS))]
5981pub struct Command {
5982    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
5983    pub this: String,
5984}
5985
5986/// EXEC/EXECUTE statement (TSQL stored procedure call)
5987/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
5988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5989#[cfg_attr(feature = "bindings", derive(TS))]
5990pub struct ExecuteStatement {
5991    /// The procedure name (can be qualified: schema.proc_name)
5992    pub this: Expression,
5993    /// Named parameters: @param=value pairs
5994    #[serde(default)]
5995    pub parameters: Vec<ExecuteParameter>,
5996    /// Trailing clause text (e.g. WITH RESULT SETS ((...)))
5997    #[serde(default, skip_serializing_if = "Option::is_none")]
5998    pub suffix: Option<String>,
5999}
6000
6001/// Named parameter in EXEC statement: @name=value
6002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6003#[cfg_attr(feature = "bindings", derive(TS))]
6004pub struct ExecuteParameter {
6005    /// Parameter name (including @)
6006    pub name: String,
6007    /// Parameter value
6008    pub value: Expression,
6009    /// Whether this is a positional parameter (no = sign)
6010    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6011    pub positional: bool,
6012    /// TSQL OUTPUT modifier on parameter
6013    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6014    pub output: bool,
6015}
6016
6017/// KILL statement (MySQL/MariaDB)
6018/// KILL [CONNECTION | QUERY] <id>
6019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6020#[cfg_attr(feature = "bindings", derive(TS))]
6021pub struct Kill {
6022    /// The target (process ID or connection ID)
6023    pub this: Expression,
6024    /// Optional kind: "CONNECTION" or "QUERY"
6025    pub kind: Option<String>,
6026}
6027
6028/// Snowflake CREATE TASK statement
6029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6030#[cfg_attr(feature = "bindings", derive(TS))]
6031pub struct CreateTask {
6032    pub or_replace: bool,
6033    pub if_not_exists: bool,
6034    /// Task name (possibly qualified: db.schema.task)
6035    pub name: String,
6036    /// Raw text of properties between name and AS (WAREHOUSE, SCHEDULE, etc.)
6037    pub properties: String,
6038    /// The SQL statement body after AS
6039    pub body: Expression,
6040}
6041
6042/// Raw/unparsed SQL
6043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6044#[cfg_attr(feature = "bindings", derive(TS))]
6045pub struct Raw {
6046    pub sql: String,
6047}
6048
6049// ============================================================================
6050// Function expression types
6051// ============================================================================
6052
6053/// Generic unary function (takes a single argument)
6054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6055#[cfg_attr(feature = "bindings", derive(TS))]
6056pub struct UnaryFunc {
6057    pub this: Expression,
6058    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
6059    #[serde(skip_serializing_if = "Option::is_none", default)]
6060    pub original_name: Option<String>,
6061    /// Inferred data type from type annotation
6062    #[serde(default, skip_serializing_if = "Option::is_none")]
6063    pub inferred_type: Option<DataType>,
6064}
6065
6066impl UnaryFunc {
6067    /// Create a new UnaryFunc with no original_name
6068    pub fn new(this: Expression) -> Self {
6069        Self {
6070            this,
6071            original_name: None,
6072            inferred_type: None,
6073        }
6074    }
6075
6076    /// Create a new UnaryFunc with an original name for round-trip preservation
6077    pub fn with_name(this: Expression, name: String) -> Self {
6078        Self {
6079            this,
6080            original_name: Some(name),
6081            inferred_type: None,
6082        }
6083    }
6084}
6085
6086/// CHAR/CHR function with multiple args and optional USING charset
6087/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
6088/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
6089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6090#[cfg_attr(feature = "bindings", derive(TS))]
6091pub struct CharFunc {
6092    pub args: Vec<Expression>,
6093    #[serde(skip_serializing_if = "Option::is_none", default)]
6094    pub charset: Option<String>,
6095    /// Original function name (CHAR or CHR), defaults to CHAR
6096    #[serde(skip_serializing_if = "Option::is_none", default)]
6097    pub name: Option<String>,
6098}
6099
6100/// Generic binary function (takes two arguments)
6101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6102#[cfg_attr(feature = "bindings", derive(TS))]
6103pub struct BinaryFunc {
6104    pub this: Expression,
6105    pub expression: Expression,
6106    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
6107    #[serde(skip_serializing_if = "Option::is_none", default)]
6108    pub original_name: Option<String>,
6109    /// Inferred data type from type annotation
6110    #[serde(default, skip_serializing_if = "Option::is_none")]
6111    pub inferred_type: Option<DataType>,
6112}
6113
6114/// Variable argument function
6115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6116#[cfg_attr(feature = "bindings", derive(TS))]
6117pub struct VarArgFunc {
6118    pub expressions: Vec<Expression>,
6119    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
6120    #[serde(skip_serializing_if = "Option::is_none", default)]
6121    pub original_name: Option<String>,
6122    /// Inferred data type from type annotation
6123    #[serde(default, skip_serializing_if = "Option::is_none")]
6124    pub inferred_type: Option<DataType>,
6125}
6126
6127/// CONCAT_WS function
6128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6129#[cfg_attr(feature = "bindings", derive(TS))]
6130pub struct ConcatWs {
6131    pub separator: Expression,
6132    pub expressions: Vec<Expression>,
6133}
6134
6135/// SUBSTRING function
6136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6137#[cfg_attr(feature = "bindings", derive(TS))]
6138pub struct SubstringFunc {
6139    pub this: Expression,
6140    pub start: Expression,
6141    pub length: Option<Expression>,
6142    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
6143    #[serde(default)]
6144    pub from_for_syntax: bool,
6145}
6146
6147/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
6148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6149#[cfg_attr(feature = "bindings", derive(TS))]
6150pub struct OverlayFunc {
6151    pub this: Expression,
6152    pub replacement: Expression,
6153    pub from: Expression,
6154    pub length: Option<Expression>,
6155}
6156
6157/// TRIM function
6158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6159#[cfg_attr(feature = "bindings", derive(TS))]
6160pub struct TrimFunc {
6161    pub this: Expression,
6162    pub characters: Option<Expression>,
6163    pub position: TrimPosition,
6164    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
6165    #[serde(default)]
6166    pub sql_standard_syntax: bool,
6167    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
6168    #[serde(default)]
6169    pub position_explicit: bool,
6170}
6171
6172#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6173#[cfg_attr(feature = "bindings", derive(TS))]
6174pub enum TrimPosition {
6175    Both,
6176    Leading,
6177    Trailing,
6178}
6179
6180/// REPLACE function
6181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6182#[cfg_attr(feature = "bindings", derive(TS))]
6183pub struct ReplaceFunc {
6184    pub this: Expression,
6185    pub old: Expression,
6186    pub new: Expression,
6187}
6188
6189/// LEFT/RIGHT function
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct LeftRightFunc {
6193    pub this: Expression,
6194    pub length: Expression,
6195}
6196
6197/// REPEAT function
6198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6199#[cfg_attr(feature = "bindings", derive(TS))]
6200pub struct RepeatFunc {
6201    pub this: Expression,
6202    pub times: Expression,
6203}
6204
6205/// LPAD/RPAD function
6206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6207#[cfg_attr(feature = "bindings", derive(TS))]
6208pub struct PadFunc {
6209    pub this: Expression,
6210    pub length: Expression,
6211    pub fill: Option<Expression>,
6212}
6213
6214/// SPLIT function
6215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6216#[cfg_attr(feature = "bindings", derive(TS))]
6217pub struct SplitFunc {
6218    pub this: Expression,
6219    pub delimiter: Expression,
6220}
6221
6222/// REGEXP_LIKE function
6223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6224#[cfg_attr(feature = "bindings", derive(TS))]
6225pub struct RegexpFunc {
6226    pub this: Expression,
6227    pub pattern: Expression,
6228    pub flags: Option<Expression>,
6229}
6230
6231/// REGEXP_REPLACE function
6232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6233#[cfg_attr(feature = "bindings", derive(TS))]
6234pub struct RegexpReplaceFunc {
6235    pub this: Expression,
6236    pub pattern: Expression,
6237    pub replacement: Expression,
6238    pub flags: Option<Expression>,
6239}
6240
6241/// REGEXP_EXTRACT function
6242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6243#[cfg_attr(feature = "bindings", derive(TS))]
6244pub struct RegexpExtractFunc {
6245    pub this: Expression,
6246    pub pattern: Expression,
6247    pub group: Option<Expression>,
6248}
6249
6250/// ROUND function
6251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6252#[cfg_attr(feature = "bindings", derive(TS))]
6253pub struct RoundFunc {
6254    pub this: Expression,
6255    pub decimals: Option<Expression>,
6256}
6257
6258/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
6259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6260#[cfg_attr(feature = "bindings", derive(TS))]
6261pub struct FloorFunc {
6262    pub this: Expression,
6263    pub scale: Option<Expression>,
6264    /// Time unit for Druid-style FLOOR(time TO unit) syntax
6265    #[serde(skip_serializing_if = "Option::is_none", default)]
6266    pub to: Option<Expression>,
6267}
6268
6269/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
6270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6271#[cfg_attr(feature = "bindings", derive(TS))]
6272pub struct CeilFunc {
6273    pub this: Expression,
6274    #[serde(skip_serializing_if = "Option::is_none", default)]
6275    pub decimals: Option<Expression>,
6276    /// Time unit for Druid-style CEIL(time TO unit) syntax
6277    #[serde(skip_serializing_if = "Option::is_none", default)]
6278    pub to: Option<Expression>,
6279}
6280
6281/// LOG function
6282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6283#[cfg_attr(feature = "bindings", derive(TS))]
6284pub struct LogFunc {
6285    pub this: Expression,
6286    pub base: Option<Expression>,
6287}
6288
6289/// CURRENT_DATE (no arguments)
6290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6291#[cfg_attr(feature = "bindings", derive(TS))]
6292pub struct CurrentDate;
6293
6294/// CURRENT_TIME
6295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6296#[cfg_attr(feature = "bindings", derive(TS))]
6297pub struct CurrentTime {
6298    pub precision: Option<u32>,
6299}
6300
6301/// CURRENT_TIMESTAMP
6302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6303#[cfg_attr(feature = "bindings", derive(TS))]
6304pub struct CurrentTimestamp {
6305    pub precision: Option<u32>,
6306    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
6307    #[serde(default)]
6308    pub sysdate: bool,
6309}
6310
6311/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
6312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6313#[cfg_attr(feature = "bindings", derive(TS))]
6314pub struct CurrentTimestampLTZ {
6315    pub precision: Option<u32>,
6316}
6317
6318/// AT TIME ZONE expression for timezone conversion
6319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6320#[cfg_attr(feature = "bindings", derive(TS))]
6321pub struct AtTimeZone {
6322    /// The expression to convert
6323    pub this: Expression,
6324    /// The target timezone
6325    pub zone: Expression,
6326}
6327
6328/// DATE_ADD / DATE_SUB function
6329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6330#[cfg_attr(feature = "bindings", derive(TS))]
6331pub struct DateAddFunc {
6332    pub this: Expression,
6333    pub interval: Expression,
6334    pub unit: IntervalUnit,
6335}
6336
6337/// DATEDIFF function
6338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6339#[cfg_attr(feature = "bindings", derive(TS))]
6340pub struct DateDiffFunc {
6341    pub this: Expression,
6342    pub expression: Expression,
6343    pub unit: Option<IntervalUnit>,
6344}
6345
6346/// DATE_TRUNC function
6347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6348#[cfg_attr(feature = "bindings", derive(TS))]
6349pub struct DateTruncFunc {
6350    pub this: Expression,
6351    pub unit: DateTimeField,
6352}
6353
6354/// EXTRACT function
6355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6356#[cfg_attr(feature = "bindings", derive(TS))]
6357pub struct ExtractFunc {
6358    pub this: Expression,
6359    pub field: DateTimeField,
6360}
6361
6362#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6363#[cfg_attr(feature = "bindings", derive(TS))]
6364pub enum DateTimeField {
6365    Year,
6366    Month,
6367    Day,
6368    Hour,
6369    Minute,
6370    Second,
6371    Millisecond,
6372    Microsecond,
6373    DayOfWeek,
6374    DayOfYear,
6375    Week,
6376    /// Week with a modifier like WEEK(monday), WEEK(sunday)
6377    WeekWithModifier(String),
6378    Quarter,
6379    Epoch,
6380    Timezone,
6381    TimezoneHour,
6382    TimezoneMinute,
6383    Date,
6384    Time,
6385    /// Custom datetime field for dialect-specific or arbitrary fields
6386    Custom(String),
6387}
6388
6389/// TO_DATE function
6390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6391#[cfg_attr(feature = "bindings", derive(TS))]
6392pub struct ToDateFunc {
6393    pub this: Expression,
6394    pub format: Option<Expression>,
6395}
6396
6397/// TO_TIMESTAMP function
6398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6399#[cfg_attr(feature = "bindings", derive(TS))]
6400pub struct ToTimestampFunc {
6401    pub this: Expression,
6402    pub format: Option<Expression>,
6403}
6404
6405/// IF function
6406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6407#[cfg_attr(feature = "bindings", derive(TS))]
6408pub struct IfFunc {
6409    pub condition: Expression,
6410    pub true_value: Expression,
6411    pub false_value: Option<Expression>,
6412    /// Original function name (IF, IFF, IIF) for round-trip preservation
6413    #[serde(skip_serializing_if = "Option::is_none", default)]
6414    pub original_name: Option<String>,
6415    /// Inferred data type from type annotation
6416    #[serde(default, skip_serializing_if = "Option::is_none")]
6417    pub inferred_type: Option<DataType>,
6418}
6419
6420/// NVL2 function
6421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6422#[cfg_attr(feature = "bindings", derive(TS))]
6423pub struct Nvl2Func {
6424    pub this: Expression,
6425    pub true_value: Expression,
6426    pub false_value: Expression,
6427    /// Inferred data type from type annotation
6428    #[serde(default, skip_serializing_if = "Option::is_none")]
6429    pub inferred_type: Option<DataType>,
6430}
6431
6432// ============================================================================
6433// Typed Aggregate Function types
6434// ============================================================================
6435
6436/// Generic aggregate function base type
6437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6438#[cfg_attr(feature = "bindings", derive(TS))]
6439pub struct AggFunc {
6440    pub this: Expression,
6441    pub distinct: bool,
6442    pub filter: Option<Expression>,
6443    pub order_by: Vec<Ordered>,
6444    /// Original function name (case-preserving) when parsed from SQL
6445    #[serde(skip_serializing_if = "Option::is_none", default)]
6446    pub name: Option<String>,
6447    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
6448    #[serde(skip_serializing_if = "Option::is_none", default)]
6449    pub ignore_nulls: Option<bool>,
6450    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
6451    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
6452    #[serde(skip_serializing_if = "Option::is_none", default)]
6453    pub having_max: Option<(Box<Expression>, bool)>,
6454    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
6455    #[serde(skip_serializing_if = "Option::is_none", default)]
6456    pub limit: Option<Box<Expression>>,
6457    /// Inferred data type from type annotation
6458    #[serde(default, skip_serializing_if = "Option::is_none")]
6459    pub inferred_type: Option<DataType>,
6460}
6461
6462/// COUNT function with optional star
6463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6464#[cfg_attr(feature = "bindings", derive(TS))]
6465pub struct CountFunc {
6466    pub this: Option<Expression>,
6467    pub star: bool,
6468    pub distinct: bool,
6469    pub filter: Option<Expression>,
6470    /// IGNORE NULLS (true) or RESPECT NULLS (false)
6471    #[serde(default, skip_serializing_if = "Option::is_none")]
6472    pub ignore_nulls: Option<bool>,
6473    /// Original function name for case preservation (e.g., "count" or "COUNT")
6474    #[serde(default, skip_serializing_if = "Option::is_none")]
6475    pub original_name: Option<String>,
6476    /// Inferred data type from type annotation
6477    #[serde(default, skip_serializing_if = "Option::is_none")]
6478    pub inferred_type: Option<DataType>,
6479}
6480
6481/// GROUP_CONCAT function (MySQL style)
6482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6483#[cfg_attr(feature = "bindings", derive(TS))]
6484pub struct GroupConcatFunc {
6485    pub this: Expression,
6486    pub separator: Option<Expression>,
6487    pub order_by: Option<Vec<Ordered>>,
6488    pub distinct: bool,
6489    pub filter: Option<Expression>,
6490    /// MySQL 8.0.19+: LIMIT n inside GROUP_CONCAT
6491    #[serde(default, skip_serializing_if = "Option::is_none")]
6492    pub limit: Option<Box<Expression>>,
6493    /// Inferred data type from type annotation
6494    #[serde(default, skip_serializing_if = "Option::is_none")]
6495    pub inferred_type: Option<DataType>,
6496}
6497
6498/// STRING_AGG function (PostgreSQL/Standard SQL)
6499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6500#[cfg_attr(feature = "bindings", derive(TS))]
6501pub struct StringAggFunc {
6502    pub this: Expression,
6503    #[serde(default)]
6504    pub separator: Option<Expression>,
6505    #[serde(default)]
6506    pub order_by: Option<Vec<Ordered>>,
6507    #[serde(default)]
6508    pub distinct: bool,
6509    #[serde(default)]
6510    pub filter: Option<Expression>,
6511    /// BigQuery LIMIT inside STRING_AGG
6512    #[serde(default, skip_serializing_if = "Option::is_none")]
6513    pub limit: Option<Box<Expression>>,
6514    /// Inferred data type from type annotation
6515    #[serde(default, skip_serializing_if = "Option::is_none")]
6516    pub inferred_type: Option<DataType>,
6517}
6518
6519/// LISTAGG function (Oracle style)
6520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6521#[cfg_attr(feature = "bindings", derive(TS))]
6522pub struct ListAggFunc {
6523    pub this: Expression,
6524    pub separator: Option<Expression>,
6525    pub on_overflow: Option<ListAggOverflow>,
6526    pub order_by: Option<Vec<Ordered>>,
6527    pub distinct: bool,
6528    pub filter: Option<Expression>,
6529    /// Inferred data type from type annotation
6530    #[serde(default, skip_serializing_if = "Option::is_none")]
6531    pub inferred_type: Option<DataType>,
6532}
6533
6534/// LISTAGG ON OVERFLOW behavior
6535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6536#[cfg_attr(feature = "bindings", derive(TS))]
6537pub enum ListAggOverflow {
6538    Error,
6539    Truncate {
6540        filler: Option<Expression>,
6541        with_count: bool,
6542    },
6543}
6544
6545/// SUM_IF / COUNT_IF function
6546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6547#[cfg_attr(feature = "bindings", derive(TS))]
6548pub struct SumIfFunc {
6549    pub this: Expression,
6550    pub condition: Expression,
6551    pub filter: Option<Expression>,
6552    /// Inferred data type from type annotation
6553    #[serde(default, skip_serializing_if = "Option::is_none")]
6554    pub inferred_type: Option<DataType>,
6555}
6556
6557/// APPROX_PERCENTILE function
6558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6559#[cfg_attr(feature = "bindings", derive(TS))]
6560pub struct ApproxPercentileFunc {
6561    pub this: Expression,
6562    pub percentile: Expression,
6563    pub accuracy: Option<Expression>,
6564    pub filter: Option<Expression>,
6565}
6566
6567/// PERCENTILE_CONT / PERCENTILE_DISC function
6568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6569#[cfg_attr(feature = "bindings", derive(TS))]
6570pub struct PercentileFunc {
6571    pub this: Expression,
6572    pub percentile: Expression,
6573    pub order_by: Option<Vec<Ordered>>,
6574    pub filter: Option<Expression>,
6575}
6576
6577// ============================================================================
6578// Typed Window Function types
6579// ============================================================================
6580
6581/// ROW_NUMBER function (no arguments)
6582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6583#[cfg_attr(feature = "bindings", derive(TS))]
6584pub struct RowNumber;
6585
6586/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6588#[cfg_attr(feature = "bindings", derive(TS))]
6589pub struct Rank {
6590    /// DuckDB: RANK(ORDER BY col) - order by inside function
6591    #[serde(default, skip_serializing_if = "Option::is_none")]
6592    pub order_by: Option<Vec<Ordered>>,
6593    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6594    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6595    pub args: Vec<Expression>,
6596}
6597
6598/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
6599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6600#[cfg_attr(feature = "bindings", derive(TS))]
6601pub struct DenseRank {
6602    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6603    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6604    pub args: Vec<Expression>,
6605}
6606
6607/// NTILE function (DuckDB allows ORDER BY inside)
6608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6609#[cfg_attr(feature = "bindings", derive(TS))]
6610pub struct NTileFunc {
6611    /// num_buckets is optional to support Databricks NTILE() without arguments
6612    #[serde(default, skip_serializing_if = "Option::is_none")]
6613    pub num_buckets: Option<Expression>,
6614    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
6615    #[serde(default, skip_serializing_if = "Option::is_none")]
6616    pub order_by: Option<Vec<Ordered>>,
6617}
6618
6619/// LEAD / LAG function
6620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6621#[cfg_attr(feature = "bindings", derive(TS))]
6622pub struct LeadLagFunc {
6623    pub this: Expression,
6624    pub offset: Option<Expression>,
6625    pub default: Option<Expression>,
6626    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6627    #[serde(default, skip_serializing_if = "Option::is_none")]
6628    pub ignore_nulls: Option<bool>,
6629}
6630
6631/// FIRST_VALUE / LAST_VALUE function
6632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6633#[cfg_attr(feature = "bindings", derive(TS))]
6634pub struct ValueFunc {
6635    pub this: Expression,
6636    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6637    #[serde(default, skip_serializing_if = "Option::is_none")]
6638    pub ignore_nulls: Option<bool>,
6639    /// ORDER BY inside the function parens (e.g., DuckDB: LAST_VALUE(x ORDER BY x))
6640    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6641    pub order_by: Vec<Ordered>,
6642}
6643
6644/// NTH_VALUE function
6645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6646#[cfg_attr(feature = "bindings", derive(TS))]
6647pub struct NthValueFunc {
6648    pub this: Expression,
6649    pub offset: Expression,
6650    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
6651    #[serde(default, skip_serializing_if = "Option::is_none")]
6652    pub ignore_nulls: Option<bool>,
6653    /// Snowflake FROM FIRST / FROM LAST clause
6654    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
6655    #[serde(default, skip_serializing_if = "Option::is_none")]
6656    pub from_first: Option<bool>,
6657}
6658
6659/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6661#[cfg_attr(feature = "bindings", derive(TS))]
6662pub struct PercentRank {
6663    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
6664    #[serde(default, skip_serializing_if = "Option::is_none")]
6665    pub order_by: Option<Vec<Ordered>>,
6666    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6667    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6668    pub args: Vec<Expression>,
6669}
6670
6671/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
6672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6673#[cfg_attr(feature = "bindings", derive(TS))]
6674pub struct CumeDist {
6675    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
6676    #[serde(default, skip_serializing_if = "Option::is_none")]
6677    pub order_by: Option<Vec<Ordered>>,
6678    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
6679    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6680    pub args: Vec<Expression>,
6681}
6682
6683// ============================================================================
6684// Additional String Function types
6685// ============================================================================
6686
6687/// POSITION/INSTR function
6688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6689#[cfg_attr(feature = "bindings", derive(TS))]
6690pub struct PositionFunc {
6691    pub substring: Expression,
6692    pub string: Expression,
6693    pub start: Option<Expression>,
6694}
6695
6696// ============================================================================
6697// Additional Math Function types
6698// ============================================================================
6699
6700/// RANDOM function (no arguments)
6701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6702#[cfg_attr(feature = "bindings", derive(TS))]
6703pub struct Random;
6704
6705/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
6706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6707#[cfg_attr(feature = "bindings", derive(TS))]
6708pub struct Rand {
6709    pub seed: Option<Box<Expression>>,
6710    /// Teradata RANDOM lower bound
6711    #[serde(default)]
6712    pub lower: Option<Box<Expression>>,
6713    /// Teradata RANDOM upper bound
6714    #[serde(default)]
6715    pub upper: Option<Box<Expression>>,
6716}
6717
6718/// TRUNCATE / TRUNC function
6719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6720#[cfg_attr(feature = "bindings", derive(TS))]
6721pub struct TruncateFunc {
6722    pub this: Expression,
6723    pub decimals: Option<Expression>,
6724}
6725
6726/// PI function (no arguments)
6727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6728#[cfg_attr(feature = "bindings", derive(TS))]
6729pub struct Pi;
6730
6731// ============================================================================
6732// Control Flow Function types
6733// ============================================================================
6734
6735/// DECODE function (Oracle style)
6736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6737#[cfg_attr(feature = "bindings", derive(TS))]
6738pub struct DecodeFunc {
6739    pub this: Expression,
6740    pub search_results: Vec<(Expression, Expression)>,
6741    pub default: Option<Expression>,
6742}
6743
6744// ============================================================================
6745// Additional Date/Time Function types
6746// ============================================================================
6747
6748/// DATE_FORMAT / FORMAT_DATE function
6749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6750#[cfg_attr(feature = "bindings", derive(TS))]
6751pub struct DateFormatFunc {
6752    pub this: Expression,
6753    pub format: Expression,
6754}
6755
6756/// FROM_UNIXTIME function
6757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6758#[cfg_attr(feature = "bindings", derive(TS))]
6759pub struct FromUnixtimeFunc {
6760    pub this: Expression,
6761    pub format: Option<Expression>,
6762}
6763
6764/// UNIX_TIMESTAMP function
6765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6766#[cfg_attr(feature = "bindings", derive(TS))]
6767pub struct UnixTimestampFunc {
6768    pub this: Option<Expression>,
6769    pub format: Option<Expression>,
6770}
6771
6772/// MAKE_DATE function
6773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6774#[cfg_attr(feature = "bindings", derive(TS))]
6775pub struct MakeDateFunc {
6776    pub year: Expression,
6777    pub month: Expression,
6778    pub day: Expression,
6779}
6780
6781/// MAKE_TIMESTAMP function
6782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6783#[cfg_attr(feature = "bindings", derive(TS))]
6784pub struct MakeTimestampFunc {
6785    pub year: Expression,
6786    pub month: Expression,
6787    pub day: Expression,
6788    pub hour: Expression,
6789    pub minute: Expression,
6790    pub second: Expression,
6791    pub timezone: Option<Expression>,
6792}
6793
6794/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
6795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6796#[cfg_attr(feature = "bindings", derive(TS))]
6797pub struct LastDayFunc {
6798    pub this: Expression,
6799    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
6800    #[serde(skip_serializing_if = "Option::is_none", default)]
6801    pub unit: Option<DateTimeField>,
6802}
6803
6804// ============================================================================
6805// Array Function types
6806// ============================================================================
6807
6808/// ARRAY constructor
6809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6810#[cfg_attr(feature = "bindings", derive(TS))]
6811pub struct ArrayConstructor {
6812    pub expressions: Vec<Expression>,
6813    pub bracket_notation: bool,
6814    /// True if LIST keyword was used instead of ARRAY (DuckDB)
6815    pub use_list_keyword: bool,
6816}
6817
6818/// ARRAY_SORT function
6819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6820#[cfg_attr(feature = "bindings", derive(TS))]
6821pub struct ArraySortFunc {
6822    pub this: Expression,
6823    pub comparator: Option<Expression>,
6824    pub desc: bool,
6825    pub nulls_first: Option<bool>,
6826}
6827
6828/// ARRAY_JOIN / ARRAY_TO_STRING function
6829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6830#[cfg_attr(feature = "bindings", derive(TS))]
6831pub struct ArrayJoinFunc {
6832    pub this: Expression,
6833    pub separator: Expression,
6834    pub null_replacement: Option<Expression>,
6835}
6836
6837/// UNNEST function
6838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6839#[cfg_attr(feature = "bindings", derive(TS))]
6840pub struct UnnestFunc {
6841    pub this: Expression,
6842    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
6843    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6844    pub expressions: Vec<Expression>,
6845    pub with_ordinality: bool,
6846    pub alias: Option<Identifier>,
6847    /// BigQuery: offset alias for WITH OFFSET AS <name>
6848    #[serde(default, skip_serializing_if = "Option::is_none")]
6849    pub offset_alias: Option<Identifier>,
6850}
6851
6852/// ARRAY_FILTER function (with lambda)
6853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6854#[cfg_attr(feature = "bindings", derive(TS))]
6855pub struct ArrayFilterFunc {
6856    pub this: Expression,
6857    pub filter: Expression,
6858}
6859
6860/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
6861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6862#[cfg_attr(feature = "bindings", derive(TS))]
6863pub struct ArrayTransformFunc {
6864    pub this: Expression,
6865    pub transform: Expression,
6866}
6867
6868/// SEQUENCE / GENERATE_SERIES function
6869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6870#[cfg_attr(feature = "bindings", derive(TS))]
6871pub struct SequenceFunc {
6872    pub start: Expression,
6873    pub stop: Expression,
6874    pub step: Option<Expression>,
6875}
6876
6877// ============================================================================
6878// Struct Function types
6879// ============================================================================
6880
6881/// STRUCT constructor
6882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6883#[cfg_attr(feature = "bindings", derive(TS))]
6884pub struct StructConstructor {
6885    pub fields: Vec<(Option<Identifier>, Expression)>,
6886}
6887
6888/// STRUCT_EXTRACT function
6889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6890#[cfg_attr(feature = "bindings", derive(TS))]
6891pub struct StructExtractFunc {
6892    pub this: Expression,
6893    pub field: Identifier,
6894}
6895
6896/// NAMED_STRUCT function
6897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6898#[cfg_attr(feature = "bindings", derive(TS))]
6899pub struct NamedStructFunc {
6900    pub pairs: Vec<(Expression, Expression)>,
6901}
6902
6903// ============================================================================
6904// Map Function types
6905// ============================================================================
6906
6907/// MAP constructor
6908#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6909#[cfg_attr(feature = "bindings", derive(TS))]
6910pub struct MapConstructor {
6911    pub keys: Vec<Expression>,
6912    pub values: Vec<Expression>,
6913    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
6914    #[serde(default)]
6915    pub curly_brace_syntax: bool,
6916    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
6917    #[serde(default)]
6918    pub with_map_keyword: bool,
6919}
6920
6921/// TRANSFORM_KEYS / TRANSFORM_VALUES function
6922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6923#[cfg_attr(feature = "bindings", derive(TS))]
6924pub struct TransformFunc {
6925    pub this: Expression,
6926    pub transform: Expression,
6927}
6928
6929/// Function call with EMITS clause (Exasol)
6930/// Used for JSON_EXTRACT(...) EMITS (col1 TYPE1, col2 TYPE2)
6931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6932#[cfg_attr(feature = "bindings", derive(TS))]
6933pub struct FunctionEmits {
6934    /// The function call expression
6935    pub this: Expression,
6936    /// The EMITS schema definition
6937    pub emits: Expression,
6938}
6939
6940// ============================================================================
6941// JSON Function types
6942// ============================================================================
6943
6944/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
6945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6946#[cfg_attr(feature = "bindings", derive(TS))]
6947pub struct JsonExtractFunc {
6948    pub this: Expression,
6949    pub path: Expression,
6950    pub returning: Option<DataType>,
6951    /// True if parsed from -> or ->> operator syntax
6952    #[serde(default)]
6953    pub arrow_syntax: bool,
6954    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
6955    #[serde(default)]
6956    pub hash_arrow_syntax: bool,
6957    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
6958    #[serde(default)]
6959    pub wrapper_option: Option<String>,
6960    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
6961    #[serde(default)]
6962    pub quotes_option: Option<String>,
6963    /// ON SCALAR STRING flag
6964    #[serde(default)]
6965    pub on_scalar_string: bool,
6966    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
6967    #[serde(default)]
6968    pub on_error: Option<String>,
6969}
6970
6971/// JSON path extraction
6972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6973#[cfg_attr(feature = "bindings", derive(TS))]
6974pub struct JsonPathFunc {
6975    pub this: Expression,
6976    pub paths: Vec<Expression>,
6977}
6978
6979/// JSON_OBJECT function
6980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6981#[cfg_attr(feature = "bindings", derive(TS))]
6982pub struct JsonObjectFunc {
6983    pub pairs: Vec<(Expression, Expression)>,
6984    pub null_handling: Option<JsonNullHandling>,
6985    #[serde(default)]
6986    pub with_unique_keys: bool,
6987    #[serde(default)]
6988    pub returning_type: Option<DataType>,
6989    #[serde(default)]
6990    pub format_json: bool,
6991    #[serde(default)]
6992    pub encoding: Option<String>,
6993    /// For JSON_OBJECT(*) syntax
6994    #[serde(default)]
6995    pub star: bool,
6996}
6997
6998/// JSON null handling options
6999#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7000#[cfg_attr(feature = "bindings", derive(TS))]
7001pub enum JsonNullHandling {
7002    NullOnNull,
7003    AbsentOnNull,
7004}
7005
7006/// JSON_SET / JSON_INSERT function
7007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7008#[cfg_attr(feature = "bindings", derive(TS))]
7009pub struct JsonModifyFunc {
7010    pub this: Expression,
7011    pub path_values: Vec<(Expression, Expression)>,
7012}
7013
7014/// JSON_ARRAYAGG function
7015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7016#[cfg_attr(feature = "bindings", derive(TS))]
7017pub struct JsonArrayAggFunc {
7018    pub this: Expression,
7019    pub order_by: Option<Vec<Ordered>>,
7020    pub null_handling: Option<JsonNullHandling>,
7021    pub filter: Option<Expression>,
7022}
7023
7024/// JSON_OBJECTAGG function
7025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7026#[cfg_attr(feature = "bindings", derive(TS))]
7027pub struct JsonObjectAggFunc {
7028    pub key: Expression,
7029    pub value: Expression,
7030    pub null_handling: Option<JsonNullHandling>,
7031    pub filter: Option<Expression>,
7032}
7033
7034// ============================================================================
7035// Type Casting Function types
7036// ============================================================================
7037
7038/// CONVERT function (SQL Server style)
7039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7040#[cfg_attr(feature = "bindings", derive(TS))]
7041pub struct ConvertFunc {
7042    pub this: Expression,
7043    pub to: DataType,
7044    pub style: Option<Expression>,
7045}
7046
7047// ============================================================================
7048// Additional Expression types
7049// ============================================================================
7050
7051/// Lambda expression
7052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7053#[cfg_attr(feature = "bindings", derive(TS))]
7054pub struct LambdaExpr {
7055    pub parameters: Vec<Identifier>,
7056    pub body: Expression,
7057    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
7058    #[serde(default)]
7059    pub colon: bool,
7060    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
7061    /// Maps parameter index to data type
7062    #[serde(default)]
7063    pub parameter_types: Vec<Option<DataType>>,
7064}
7065
7066/// Parameter (parameterized queries)
7067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7068#[cfg_attr(feature = "bindings", derive(TS))]
7069pub struct Parameter {
7070    pub name: Option<String>,
7071    pub index: Option<u32>,
7072    pub style: ParameterStyle,
7073    /// Whether the name was quoted (e.g., @"x" vs @x)
7074    #[serde(default)]
7075    pub quoted: bool,
7076    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
7077    #[serde(default)]
7078    pub string_quoted: bool,
7079    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
7080    #[serde(default)]
7081    pub expression: Option<String>,
7082}
7083
7084/// Parameter placeholder styles
7085#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7086#[cfg_attr(feature = "bindings", derive(TS))]
7087pub enum ParameterStyle {
7088    Question,     // ?
7089    Dollar,       // $1, $2
7090    DollarBrace,  // ${name} (Databricks, Hive template variables)
7091    Brace,        // {name} (Spark/Databricks widget/template variables)
7092    Colon,        // :name
7093    At,           // @name
7094    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
7095    DoubleDollar, // $$name
7096    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
7097}
7098
7099/// Placeholder expression
7100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7101#[cfg_attr(feature = "bindings", derive(TS))]
7102pub struct Placeholder {
7103    pub index: Option<u32>,
7104}
7105
7106/// Named argument in function call: name => value or name := value
7107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7108#[cfg_attr(feature = "bindings", derive(TS))]
7109pub struct NamedArgument {
7110    pub name: Identifier,
7111    pub value: Expression,
7112    /// The separator used: `=>`, `:=`, or `=`
7113    pub separator: NamedArgSeparator,
7114}
7115
7116/// Separator style for named arguments
7117#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7118#[cfg_attr(feature = "bindings", derive(TS))]
7119pub enum NamedArgSeparator {
7120    /// `=>` (standard SQL, Snowflake, BigQuery)
7121    DArrow,
7122    /// `:=` (Oracle, MySQL)
7123    ColonEq,
7124    /// `=` (simple equals, some dialects)
7125    Eq,
7126}
7127
7128/// TABLE ref or MODEL ref used as a function argument (BigQuery)
7129/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
7130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7131#[cfg_attr(feature = "bindings", derive(TS))]
7132pub struct TableArgument {
7133    /// The keyword prefix: "TABLE" or "MODEL"
7134    pub prefix: String,
7135    /// The table/model reference expression
7136    pub this: Expression,
7137}
7138
7139/// SQL Comment preservation
7140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7141#[cfg_attr(feature = "bindings", derive(TS))]
7142pub struct SqlComment {
7143    pub text: String,
7144    pub is_block: bool,
7145}
7146
7147// ============================================================================
7148// Additional Predicate types
7149// ============================================================================
7150
7151/// SIMILAR TO expression
7152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub struct SimilarToExpr {
7155    pub this: Expression,
7156    pub pattern: Expression,
7157    pub escape: Option<Expression>,
7158    pub not: bool,
7159}
7160
7161/// ANY / ALL quantified expression
7162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7163#[cfg_attr(feature = "bindings", derive(TS))]
7164pub struct QuantifiedExpr {
7165    pub this: Expression,
7166    pub subquery: Expression,
7167    pub op: Option<QuantifiedOp>,
7168}
7169
7170/// Comparison operator for quantified expressions
7171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7172#[cfg_attr(feature = "bindings", derive(TS))]
7173pub enum QuantifiedOp {
7174    Eq,
7175    Neq,
7176    Lt,
7177    Lte,
7178    Gt,
7179    Gte,
7180}
7181
7182/// OVERLAPS expression
7183/// Supports two forms:
7184/// 1. Simple binary: a OVERLAPS b (this, expression are set)
7185/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
7186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7187#[cfg_attr(feature = "bindings", derive(TS))]
7188pub struct OverlapsExpr {
7189    /// Left operand for simple binary form
7190    #[serde(skip_serializing_if = "Option::is_none")]
7191    pub this: Option<Expression>,
7192    /// Right operand for simple binary form
7193    #[serde(skip_serializing_if = "Option::is_none")]
7194    pub expression: Option<Expression>,
7195    /// Left range start for full ANSI form
7196    #[serde(skip_serializing_if = "Option::is_none")]
7197    pub left_start: Option<Expression>,
7198    /// Left range end for full ANSI form
7199    #[serde(skip_serializing_if = "Option::is_none")]
7200    pub left_end: Option<Expression>,
7201    /// Right range start for full ANSI form
7202    #[serde(skip_serializing_if = "Option::is_none")]
7203    pub right_start: Option<Expression>,
7204    /// Right range end for full ANSI form
7205    #[serde(skip_serializing_if = "Option::is_none")]
7206    pub right_end: Option<Expression>,
7207}
7208
7209// ============================================================================
7210// Array/Struct/Map access
7211// ============================================================================
7212
7213/// Subscript access (array[index] or map[key])
7214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7215#[cfg_attr(feature = "bindings", derive(TS))]
7216pub struct Subscript {
7217    pub this: Expression,
7218    pub index: Expression,
7219}
7220
7221/// Dot access (struct.field)
7222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7223#[cfg_attr(feature = "bindings", derive(TS))]
7224pub struct DotAccess {
7225    pub this: Expression,
7226    pub field: Identifier,
7227}
7228
7229/// Method call (expr.method(args))
7230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7231#[cfg_attr(feature = "bindings", derive(TS))]
7232pub struct MethodCall {
7233    pub this: Expression,
7234    pub method: Identifier,
7235    pub args: Vec<Expression>,
7236}
7237
7238/// Array slice (array[start:end])
7239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7240#[cfg_attr(feature = "bindings", derive(TS))]
7241pub struct ArraySlice {
7242    pub this: Expression,
7243    pub start: Option<Expression>,
7244    pub end: Option<Expression>,
7245}
7246
7247// ============================================================================
7248// DDL (Data Definition Language) Statements
7249// ============================================================================
7250
7251/// ON COMMIT behavior for temporary tables
7252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7253#[cfg_attr(feature = "bindings", derive(TS))]
7254pub enum OnCommit {
7255    /// ON COMMIT PRESERVE ROWS
7256    PreserveRows,
7257    /// ON COMMIT DELETE ROWS
7258    DeleteRows,
7259}
7260
7261/// CREATE TABLE statement
7262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7263#[cfg_attr(feature = "bindings", derive(TS))]
7264pub struct CreateTable {
7265    pub name: TableRef,
7266    /// ClickHouse: ON CLUSTER clause for distributed DDL
7267    #[serde(default, skip_serializing_if = "Option::is_none")]
7268    pub on_cluster: Option<OnCluster>,
7269    pub columns: Vec<ColumnDef>,
7270    pub constraints: Vec<TableConstraint>,
7271    pub if_not_exists: bool,
7272    pub temporary: bool,
7273    pub or_replace: bool,
7274    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
7275    #[serde(default, skip_serializing_if = "Option::is_none")]
7276    pub table_modifier: Option<String>,
7277    pub as_select: Option<Expression>,
7278    /// Whether the AS SELECT was wrapped in parentheses
7279    #[serde(default)]
7280    pub as_select_parenthesized: bool,
7281    /// ON COMMIT behavior for temporary tables
7282    #[serde(default)]
7283    pub on_commit: Option<OnCommit>,
7284    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
7285    #[serde(default)]
7286    pub clone_source: Option<TableRef>,
7287    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
7288    #[serde(default, skip_serializing_if = "Option::is_none")]
7289    pub clone_at_clause: Option<Expression>,
7290    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
7291    #[serde(default)]
7292    pub is_copy: bool,
7293    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
7294    #[serde(default)]
7295    pub shallow_clone: bool,
7296    /// Leading comments before the statement
7297    #[serde(default)]
7298    pub leading_comments: Vec<String>,
7299    /// WITH properties (e.g., WITH (FORMAT='parquet'))
7300    #[serde(default)]
7301    pub with_properties: Vec<(String, String)>,
7302    /// Teradata: table options after name before columns (comma-separated)
7303    #[serde(default)]
7304    pub teradata_post_name_options: Vec<String>,
7305    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
7306    #[serde(default)]
7307    pub with_data: Option<bool>,
7308    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
7309    #[serde(default)]
7310    pub with_statistics: Option<bool>,
7311    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
7312    #[serde(default)]
7313    pub teradata_indexes: Vec<TeradataIndex>,
7314    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
7315    #[serde(default)]
7316    pub with_cte: Option<With>,
7317    /// Table properties like DEFAULT COLLATE (BigQuery)
7318    #[serde(default)]
7319    pub properties: Vec<Expression>,
7320    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
7321    #[serde(default, skip_serializing_if = "Option::is_none")]
7322    pub partition_of: Option<Expression>,
7323    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
7324    #[serde(default)]
7325    pub post_table_properties: Vec<Expression>,
7326    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
7327    #[serde(default)]
7328    pub mysql_table_options: Vec<(String, String)>,
7329    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
7330    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7331    pub inherits: Vec<TableRef>,
7332    /// TSQL ON filegroup or ON filegroup (partition_column) clause
7333    #[serde(default, skip_serializing_if = "Option::is_none")]
7334    pub on_property: Option<OnProperty>,
7335    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
7336    #[serde(default)]
7337    pub copy_grants: bool,
7338    /// Snowflake: USING TEMPLATE expression for schema inference
7339    #[serde(default, skip_serializing_if = "Option::is_none")]
7340    pub using_template: Option<Box<Expression>>,
7341    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
7342    #[serde(default, skip_serializing_if = "Option::is_none")]
7343    pub rollup: Option<RollupProperty>,
7344    /// ClickHouse: UUID 'xxx' clause after table name
7345    #[serde(default, skip_serializing_if = "Option::is_none")]
7346    pub uuid: Option<String>,
7347    /// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
7348    /// for hive-partitioned external tables. Not dialect-prefixed since the syntax
7349    /// could appear in other engines.
7350    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7351    pub with_partition_columns: Vec<ColumnDef>,
7352    /// WITH CONNECTION `project.region.connection` — currently used by BigQuery
7353    /// for external tables that reference a Cloud Resource connection.
7354    #[serde(default, skip_serializing_if = "Option::is_none")]
7355    pub with_connection: Option<TableRef>,
7356}
7357
7358/// Teradata index specification for CREATE TABLE
7359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7360#[cfg_attr(feature = "bindings", derive(TS))]
7361pub struct TeradataIndex {
7362    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
7363    pub kind: TeradataIndexKind,
7364    /// Optional index name
7365    pub name: Option<String>,
7366    /// Optional column list
7367    pub columns: Vec<String>,
7368}
7369
7370/// Kind of Teradata index
7371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7372#[cfg_attr(feature = "bindings", derive(TS))]
7373pub enum TeradataIndexKind {
7374    /// NO PRIMARY INDEX
7375    NoPrimary,
7376    /// PRIMARY INDEX
7377    Primary,
7378    /// PRIMARY AMP INDEX
7379    PrimaryAmp,
7380    /// UNIQUE INDEX
7381    Unique,
7382    /// UNIQUE PRIMARY INDEX
7383    UniquePrimary,
7384    /// INDEX (secondary, non-primary)
7385    Secondary,
7386}
7387
7388impl CreateTable {
7389    pub fn new(name: impl Into<String>) -> Self {
7390        Self {
7391            name: TableRef::new(name),
7392            on_cluster: None,
7393            columns: Vec::new(),
7394            constraints: Vec::new(),
7395            if_not_exists: false,
7396            temporary: false,
7397            or_replace: false,
7398            table_modifier: None,
7399            as_select: None,
7400            as_select_parenthesized: false,
7401            on_commit: None,
7402            clone_source: None,
7403            clone_at_clause: None,
7404            shallow_clone: false,
7405            is_copy: false,
7406            leading_comments: Vec::new(),
7407            with_properties: Vec::new(),
7408            teradata_post_name_options: Vec::new(),
7409            with_data: None,
7410            with_statistics: None,
7411            teradata_indexes: Vec::new(),
7412            with_cte: None,
7413            properties: Vec::new(),
7414            partition_of: None,
7415            post_table_properties: Vec::new(),
7416            mysql_table_options: Vec::new(),
7417            inherits: Vec::new(),
7418            on_property: None,
7419            copy_grants: false,
7420            using_template: None,
7421            rollup: None,
7422            uuid: None,
7423            with_partition_columns: Vec::new(),
7424            with_connection: None,
7425        }
7426    }
7427}
7428
7429/// Sort order for PRIMARY KEY ASC/DESC
7430#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7431#[cfg_attr(feature = "bindings", derive(TS))]
7432pub enum SortOrder {
7433    Asc,
7434    Desc,
7435}
7436
7437/// Type of column constraint for tracking order
7438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7439#[cfg_attr(feature = "bindings", derive(TS))]
7440pub enum ConstraintType {
7441    NotNull,
7442    Null,
7443    PrimaryKey,
7444    Unique,
7445    Default,
7446    AutoIncrement,
7447    Collate,
7448    Comment,
7449    References,
7450    Check,
7451    GeneratedAsIdentity,
7452    /// Snowflake: TAG (key='value', ...)
7453    Tags,
7454    /// Computed/generated column
7455    ComputedColumn,
7456    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
7457    GeneratedAsRow,
7458    /// MySQL: ON UPDATE expression
7459    OnUpdate,
7460    /// PATH constraint for XMLTABLE/JSON_TABLE columns
7461    Path,
7462    /// Redshift: ENCODE encoding_type
7463    Encode,
7464}
7465
7466/// Column definition in CREATE TABLE
7467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7468#[cfg_attr(feature = "bindings", derive(TS))]
7469pub struct ColumnDef {
7470    pub name: Identifier,
7471    pub data_type: DataType,
7472    pub nullable: Option<bool>,
7473    pub default: Option<Expression>,
7474    pub primary_key: bool,
7475    /// Sort order for PRIMARY KEY (ASC/DESC)
7476    #[serde(default)]
7477    pub primary_key_order: Option<SortOrder>,
7478    pub unique: bool,
7479    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
7480    #[serde(default)]
7481    pub unique_nulls_not_distinct: bool,
7482    pub auto_increment: bool,
7483    pub comment: Option<String>,
7484    pub constraints: Vec<ColumnConstraint>,
7485    /// Track original order of constraints for accurate regeneration
7486    #[serde(default)]
7487    pub constraint_order: Vec<ConstraintType>,
7488    /// Teradata: FORMAT 'pattern'
7489    #[serde(default)]
7490    pub format: Option<String>,
7491    /// Teradata: TITLE 'title'
7492    #[serde(default)]
7493    pub title: Option<String>,
7494    /// Teradata: INLINE LENGTH n
7495    #[serde(default)]
7496    pub inline_length: Option<u64>,
7497    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
7498    #[serde(default)]
7499    pub compress: Option<Vec<Expression>>,
7500    /// Teradata: CHARACTER SET name
7501    #[serde(default)]
7502    pub character_set: Option<String>,
7503    /// Teradata: UPPERCASE
7504    #[serde(default)]
7505    pub uppercase: bool,
7506    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
7507    #[serde(default)]
7508    pub casespecific: Option<bool>,
7509    /// Snowflake: AUTOINCREMENT START value
7510    #[serde(default)]
7511    pub auto_increment_start: Option<Box<Expression>>,
7512    /// Snowflake: AUTOINCREMENT INCREMENT value
7513    #[serde(default)]
7514    pub auto_increment_increment: Option<Box<Expression>>,
7515    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
7516    #[serde(default)]
7517    pub auto_increment_order: Option<bool>,
7518    /// MySQL: UNSIGNED modifier
7519    #[serde(default)]
7520    pub unsigned: bool,
7521    /// MySQL: ZEROFILL modifier
7522    #[serde(default)]
7523    pub zerofill: bool,
7524    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
7525    #[serde(default, skip_serializing_if = "Option::is_none")]
7526    pub on_update: Option<Expression>,
7527    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
7528    #[serde(default, skip_serializing_if = "Option::is_none")]
7529    pub unique_constraint_name: Option<String>,
7530    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
7531    #[serde(default, skip_serializing_if = "Option::is_none")]
7532    pub not_null_constraint_name: Option<String>,
7533    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
7534    #[serde(default, skip_serializing_if = "Option::is_none")]
7535    pub primary_key_constraint_name: Option<String>,
7536    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
7537    #[serde(default, skip_serializing_if = "Option::is_none")]
7538    pub check_constraint_name: Option<String>,
7539    /// BigQuery: OPTIONS (key=value, ...) on column
7540    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7541    pub options: Vec<Expression>,
7542    /// SQLite: Column definition without explicit type
7543    #[serde(default)]
7544    pub no_type: bool,
7545    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
7546    #[serde(default, skip_serializing_if = "Option::is_none")]
7547    pub encoding: Option<String>,
7548    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
7549    #[serde(default, skip_serializing_if = "Option::is_none")]
7550    pub codec: Option<String>,
7551    /// ClickHouse: EPHEMERAL [expr] modifier
7552    #[serde(default, skip_serializing_if = "Option::is_none")]
7553    pub ephemeral: Option<Option<Box<Expression>>>,
7554    /// ClickHouse: MATERIALIZED expr modifier
7555    #[serde(default, skip_serializing_if = "Option::is_none")]
7556    pub materialized_expr: Option<Box<Expression>>,
7557    /// ClickHouse: ALIAS expr modifier
7558    #[serde(default, skip_serializing_if = "Option::is_none")]
7559    pub alias_expr: Option<Box<Expression>>,
7560    /// ClickHouse: TTL expr modifier on columns
7561    #[serde(default, skip_serializing_if = "Option::is_none")]
7562    pub ttl_expr: Option<Box<Expression>>,
7563    /// TSQL: NOT FOR REPLICATION
7564    #[serde(default)]
7565    pub not_for_replication: bool,
7566}
7567
7568impl ColumnDef {
7569    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
7570        Self {
7571            name: Identifier::new(name),
7572            data_type,
7573            nullable: None,
7574            default: None,
7575            primary_key: false,
7576            primary_key_order: None,
7577            unique: false,
7578            unique_nulls_not_distinct: false,
7579            auto_increment: false,
7580            comment: None,
7581            constraints: Vec::new(),
7582            constraint_order: Vec::new(),
7583            format: None,
7584            title: None,
7585            inline_length: None,
7586            compress: None,
7587            character_set: None,
7588            uppercase: false,
7589            casespecific: None,
7590            auto_increment_start: None,
7591            auto_increment_increment: None,
7592            auto_increment_order: None,
7593            unsigned: false,
7594            zerofill: false,
7595            on_update: None,
7596            unique_constraint_name: None,
7597            not_null_constraint_name: None,
7598            primary_key_constraint_name: None,
7599            check_constraint_name: None,
7600            options: Vec::new(),
7601            no_type: false,
7602            encoding: None,
7603            codec: None,
7604            ephemeral: None,
7605            materialized_expr: None,
7606            alias_expr: None,
7607            ttl_expr: None,
7608            not_for_replication: false,
7609        }
7610    }
7611}
7612
7613/// Column-level constraint
7614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7615#[cfg_attr(feature = "bindings", derive(TS))]
7616pub enum ColumnConstraint {
7617    NotNull,
7618    Null,
7619    Unique,
7620    PrimaryKey,
7621    Default(Expression),
7622    Check(Expression),
7623    References(ForeignKeyRef),
7624    GeneratedAsIdentity(GeneratedAsIdentity),
7625    Collate(Identifier),
7626    Comment(String),
7627    /// Snowflake: TAG (key='value', ...)
7628    Tags(Tags),
7629    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
7630    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
7631    ComputedColumn(ComputedColumn),
7632    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7633    GeneratedAsRow(GeneratedAsRow),
7634    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
7635    Path(Expression),
7636}
7637
7638/// Computed/generated column constraint
7639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7640#[cfg_attr(feature = "bindings", derive(TS))]
7641pub struct ComputedColumn {
7642    /// The expression that computes the column value
7643    pub expression: Box<Expression>,
7644    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
7645    #[serde(default)]
7646    pub persisted: bool,
7647    /// NOT NULL (TSQL computed columns)
7648    #[serde(default)]
7649    pub not_null: bool,
7650    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
7651    /// When None, defaults to dialect-appropriate output
7652    #[serde(default)]
7653    pub persistence_kind: Option<String>,
7654    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
7655    #[serde(default, skip_serializing_if = "Option::is_none")]
7656    pub data_type: Option<DataType>,
7657}
7658
7659/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
7660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7661#[cfg_attr(feature = "bindings", derive(TS))]
7662pub struct GeneratedAsRow {
7663    /// true = ROW START, false = ROW END
7664    pub start: bool,
7665    /// HIDDEN modifier
7666    #[serde(default)]
7667    pub hidden: bool,
7668}
7669
7670/// Generated identity column constraint
7671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7672#[cfg_attr(feature = "bindings", derive(TS))]
7673pub struct GeneratedAsIdentity {
7674    /// True for ALWAYS, False for BY DEFAULT
7675    pub always: bool,
7676    /// ON NULL (only valid with BY DEFAULT)
7677    pub on_null: bool,
7678    /// START WITH value
7679    pub start: Option<Box<Expression>>,
7680    /// INCREMENT BY value
7681    pub increment: Option<Box<Expression>>,
7682    /// MINVALUE
7683    pub minvalue: Option<Box<Expression>>,
7684    /// MAXVALUE
7685    pub maxvalue: Option<Box<Expression>>,
7686    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
7687    pub cycle: Option<bool>,
7688}
7689
7690/// Constraint modifiers (shared between table-level constraints)
7691#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7692#[cfg_attr(feature = "bindings", derive(TS))]
7693pub struct ConstraintModifiers {
7694    /// ENFORCED / NOT ENFORCED
7695    pub enforced: Option<bool>,
7696    /// DEFERRABLE / NOT DEFERRABLE
7697    pub deferrable: Option<bool>,
7698    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
7699    pub initially_deferred: Option<bool>,
7700    /// NORELY (Oracle)
7701    pub norely: bool,
7702    /// RELY (Oracle)
7703    pub rely: bool,
7704    /// USING index type (MySQL): BTREE or HASH
7705    #[serde(default)]
7706    pub using: Option<String>,
7707    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
7708    #[serde(default)]
7709    pub using_before_columns: bool,
7710    /// MySQL index COMMENT 'text'
7711    #[serde(default, skip_serializing_if = "Option::is_none")]
7712    pub comment: Option<String>,
7713    /// MySQL index VISIBLE/INVISIBLE
7714    #[serde(default, skip_serializing_if = "Option::is_none")]
7715    pub visible: Option<bool>,
7716    /// MySQL ENGINE_ATTRIBUTE = 'value'
7717    #[serde(default, skip_serializing_if = "Option::is_none")]
7718    pub engine_attribute: Option<String>,
7719    /// MySQL WITH PARSER name
7720    #[serde(default, skip_serializing_if = "Option::is_none")]
7721    pub with_parser: Option<String>,
7722    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
7723    #[serde(default)]
7724    pub not_valid: bool,
7725    /// TSQL CLUSTERED/NONCLUSTERED modifier
7726    #[serde(default, skip_serializing_if = "Option::is_none")]
7727    pub clustered: Option<String>,
7728    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
7729    #[serde(default, skip_serializing_if = "Option::is_none")]
7730    pub on_conflict: Option<String>,
7731    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
7732    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7733    pub with_options: Vec<(String, String)>,
7734    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
7735    #[serde(default, skip_serializing_if = "Option::is_none")]
7736    pub on_filegroup: Option<Identifier>,
7737}
7738
7739/// Table-level constraint
7740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7741#[cfg_attr(feature = "bindings", derive(TS))]
7742pub enum TableConstraint {
7743    PrimaryKey {
7744        name: Option<Identifier>,
7745        columns: Vec<Identifier>,
7746        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
7747        #[serde(default)]
7748        include_columns: Vec<Identifier>,
7749        #[serde(default)]
7750        modifiers: ConstraintModifiers,
7751        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
7752        #[serde(default)]
7753        has_constraint_keyword: bool,
7754    },
7755    Unique {
7756        name: Option<Identifier>,
7757        columns: Vec<Identifier>,
7758        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
7759        #[serde(default)]
7760        columns_parenthesized: bool,
7761        #[serde(default)]
7762        modifiers: ConstraintModifiers,
7763        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
7764        #[serde(default)]
7765        has_constraint_keyword: bool,
7766        /// PostgreSQL 15+: NULLS NOT DISTINCT
7767        #[serde(default)]
7768        nulls_not_distinct: bool,
7769    },
7770    ForeignKey {
7771        name: Option<Identifier>,
7772        columns: Vec<Identifier>,
7773        #[serde(default)]
7774        references: Option<ForeignKeyRef>,
7775        /// ON DELETE action when REFERENCES is absent
7776        #[serde(default)]
7777        on_delete: Option<ReferentialAction>,
7778        /// ON UPDATE action when REFERENCES is absent
7779        #[serde(default)]
7780        on_update: Option<ReferentialAction>,
7781        #[serde(default)]
7782        modifiers: ConstraintModifiers,
7783    },
7784    Check {
7785        name: Option<Identifier>,
7786        expression: Expression,
7787        #[serde(default)]
7788        modifiers: ConstraintModifiers,
7789    },
7790    /// ClickHouse ASSUME constraint (query optimization assumption)
7791    Assume {
7792        name: Option<Identifier>,
7793        expression: Expression,
7794    },
7795    /// TSQL named DEFAULT constraint: CONSTRAINT name DEFAULT value FOR column
7796    Default {
7797        name: Option<Identifier>,
7798        expression: Expression,
7799        column: Identifier,
7800    },
7801    /// INDEX / KEY constraint (MySQL)
7802    Index {
7803        name: Option<Identifier>,
7804        columns: Vec<Identifier>,
7805        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
7806        #[serde(default)]
7807        kind: Option<String>,
7808        #[serde(default)]
7809        modifiers: ConstraintModifiers,
7810        /// True if KEY keyword was used instead of INDEX
7811        #[serde(default)]
7812        use_key_keyword: bool,
7813        /// ClickHouse: indexed expression (instead of columns)
7814        #[serde(default, skip_serializing_if = "Option::is_none")]
7815        expression: Option<Box<Expression>>,
7816        /// ClickHouse: TYPE type_func(args)
7817        #[serde(default, skip_serializing_if = "Option::is_none")]
7818        index_type: Option<Box<Expression>>,
7819        /// ClickHouse: GRANULARITY n
7820        #[serde(default, skip_serializing_if = "Option::is_none")]
7821        granularity: Option<Box<Expression>>,
7822    },
7823    /// ClickHouse PROJECTION definition
7824    Projection {
7825        name: Identifier,
7826        expression: Expression,
7827    },
7828    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
7829    Like {
7830        source: TableRef,
7831        /// Options as (INCLUDING|EXCLUDING, property) pairs
7832        options: Vec<(LikeOptionAction, String)>,
7833    },
7834    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
7835    PeriodForSystemTime {
7836        start_col: Identifier,
7837        end_col: Identifier,
7838    },
7839    /// PostgreSQL EXCLUDE constraint
7840    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
7841    Exclude {
7842        name: Option<Identifier>,
7843        /// Index access method (gist, btree, etc.)
7844        #[serde(default)]
7845        using: Option<String>,
7846        /// Elements: (expression, operator) pairs
7847        elements: Vec<ExcludeElement>,
7848        /// INCLUDE columns
7849        #[serde(default)]
7850        include_columns: Vec<Identifier>,
7851        /// WHERE predicate
7852        #[serde(default)]
7853        where_clause: Option<Box<Expression>>,
7854        /// WITH (storage_parameters)
7855        #[serde(default)]
7856        with_params: Vec<(String, String)>,
7857        /// USING INDEX TABLESPACE tablespace_name
7858        #[serde(default)]
7859        using_index_tablespace: Option<String>,
7860        #[serde(default)]
7861        modifiers: ConstraintModifiers,
7862    },
7863    /// Snowflake TAG clause: TAG (key='value', key2='value2')
7864    Tags(Tags),
7865    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
7866    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
7867    /// for all deferrable constraints in the table
7868    InitiallyDeferred {
7869        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
7870        deferred: bool,
7871    },
7872}
7873
7874/// Element in an EXCLUDE constraint: expression WITH operator
7875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7876#[cfg_attr(feature = "bindings", derive(TS))]
7877pub struct ExcludeElement {
7878    /// The column expression (may include operator class, ordering, nulls)
7879    pub expression: String,
7880    /// The operator (e.g., &&, =)
7881    pub operator: String,
7882}
7883
7884/// Action for LIKE clause options
7885#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7886#[cfg_attr(feature = "bindings", derive(TS))]
7887pub enum LikeOptionAction {
7888    Including,
7889    Excluding,
7890}
7891
7892/// MATCH type for foreign keys
7893#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7894#[cfg_attr(feature = "bindings", derive(TS))]
7895pub enum MatchType {
7896    Full,
7897    Partial,
7898    Simple,
7899}
7900
7901/// Foreign key reference
7902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7903#[cfg_attr(feature = "bindings", derive(TS))]
7904pub struct ForeignKeyRef {
7905    pub table: TableRef,
7906    pub columns: Vec<Identifier>,
7907    pub on_delete: Option<ReferentialAction>,
7908    pub on_update: Option<ReferentialAction>,
7909    /// True if ON UPDATE appears before ON DELETE in the original SQL
7910    #[serde(default)]
7911    pub on_update_first: bool,
7912    /// MATCH clause (FULL, PARTIAL, SIMPLE)
7913    #[serde(default)]
7914    pub match_type: Option<MatchType>,
7915    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
7916    #[serde(default)]
7917    pub match_after_actions: bool,
7918    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
7919    #[serde(default)]
7920    pub constraint_name: Option<String>,
7921    /// DEFERRABLE / NOT DEFERRABLE
7922    #[serde(default)]
7923    pub deferrable: Option<bool>,
7924    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
7925    #[serde(default)]
7926    pub has_foreign_key_keywords: bool,
7927}
7928
7929/// Referential action for foreign keys
7930#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7931#[cfg_attr(feature = "bindings", derive(TS))]
7932pub enum ReferentialAction {
7933    Cascade,
7934    SetNull,
7935    SetDefault,
7936    Restrict,
7937    NoAction,
7938}
7939
7940/// DROP TABLE statement
7941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7942#[cfg_attr(feature = "bindings", derive(TS))]
7943pub struct DropTable {
7944    pub names: Vec<TableRef>,
7945    pub if_exists: bool,
7946    pub cascade: bool,
7947    /// Oracle: CASCADE CONSTRAINTS
7948    #[serde(default)]
7949    pub cascade_constraints: bool,
7950    /// Oracle: PURGE
7951    #[serde(default)]
7952    pub purge: bool,
7953    /// Comments that appear before the DROP keyword (e.g., leading line comments)
7954    #[serde(default)]
7955    pub leading_comments: Vec<String>,
7956    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
7957    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
7958    #[serde(default, skip_serializing_if = "Option::is_none")]
7959    pub object_id_args: Option<String>,
7960    /// ClickHouse: SYNC modifier
7961    #[serde(default)]
7962    pub sync: bool,
7963    /// Snowflake: DROP ICEBERG TABLE
7964    #[serde(default)]
7965    pub iceberg: bool,
7966    /// RESTRICT modifier (opposite of CASCADE)
7967    #[serde(default)]
7968    pub restrict: bool,
7969}
7970
7971impl DropTable {
7972    pub fn new(name: impl Into<String>) -> Self {
7973        Self {
7974            names: vec![TableRef::new(name)],
7975            if_exists: false,
7976            cascade: false,
7977            cascade_constraints: false,
7978            purge: false,
7979            leading_comments: Vec::new(),
7980            object_id_args: None,
7981            sync: false,
7982            iceberg: false,
7983            restrict: false,
7984        }
7985    }
7986}
7987
7988/// UNDROP TABLE/SCHEMA/DATABASE statement (Snowflake, ClickHouse)
7989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7990#[cfg_attr(feature = "bindings", derive(TS))]
7991pub struct Undrop {
7992    /// The object kind: "TABLE", "SCHEMA", or "DATABASE"
7993    pub kind: String,
7994    /// The object name
7995    pub name: TableRef,
7996    /// IF EXISTS clause
7997    #[serde(default)]
7998    pub if_exists: bool,
7999}
8000
8001/// ALTER TABLE statement
8002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8003#[cfg_attr(feature = "bindings", derive(TS))]
8004pub struct AlterTable {
8005    pub name: TableRef,
8006    pub actions: Vec<AlterTableAction>,
8007    /// IF EXISTS clause
8008    #[serde(default)]
8009    pub if_exists: bool,
8010    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
8011    #[serde(default, skip_serializing_if = "Option::is_none")]
8012    pub algorithm: Option<String>,
8013    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
8014    #[serde(default, skip_serializing_if = "Option::is_none")]
8015    pub lock: Option<String>,
8016    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
8017    #[serde(default, skip_serializing_if = "Option::is_none")]
8018    pub with_check: Option<String>,
8019    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
8020    #[serde(default, skip_serializing_if = "Option::is_none")]
8021    pub partition: Option<Vec<(Identifier, Expression)>>,
8022    /// ClickHouse: ON CLUSTER clause for distributed DDL
8023    #[serde(default, skip_serializing_if = "Option::is_none")]
8024    pub on_cluster: Option<OnCluster>,
8025    /// Snowflake: ALTER ICEBERG TABLE
8026    #[serde(default, skip_serializing_if = "Option::is_none")]
8027    pub table_modifier: Option<String>,
8028}
8029
8030impl AlterTable {
8031    pub fn new(name: impl Into<String>) -> Self {
8032        Self {
8033            name: TableRef::new(name),
8034            actions: Vec::new(),
8035            if_exists: false,
8036            algorithm: None,
8037            lock: None,
8038            with_check: None,
8039            partition: None,
8040            on_cluster: None,
8041            table_modifier: None,
8042        }
8043    }
8044}
8045
8046/// Column position for ADD COLUMN (MySQL/MariaDB)
8047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8048#[cfg_attr(feature = "bindings", derive(TS))]
8049pub enum ColumnPosition {
8050    First,
8051    After(Identifier),
8052}
8053
8054/// Actions for ALTER TABLE
8055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8056#[cfg_attr(feature = "bindings", derive(TS))]
8057pub enum AlterTableAction {
8058    AddColumn {
8059        column: ColumnDef,
8060        if_not_exists: bool,
8061        position: Option<ColumnPosition>,
8062    },
8063    DropColumn {
8064        name: Identifier,
8065        if_exists: bool,
8066        cascade: bool,
8067    },
8068    RenameColumn {
8069        old_name: Identifier,
8070        new_name: Identifier,
8071        if_exists: bool,
8072    },
8073    AlterColumn {
8074        name: Identifier,
8075        action: AlterColumnAction,
8076        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
8077        #[serde(default)]
8078        use_modify_keyword: bool,
8079    },
8080    RenameTable(TableRef),
8081    AddConstraint(TableConstraint),
8082    DropConstraint {
8083        name: Identifier,
8084        if_exists: bool,
8085    },
8086    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
8087    DropForeignKey {
8088        name: Identifier,
8089    },
8090    /// DROP PARTITION action (Hive/BigQuery)
8091    DropPartition {
8092        /// List of partitions to drop (each partition is a list of key=value pairs)
8093        partitions: Vec<Vec<(Identifier, Expression)>>,
8094        if_exists: bool,
8095    },
8096    /// ADD PARTITION action (Hive/Spark)
8097    AddPartition {
8098        /// The partition expression
8099        partition: Expression,
8100        if_not_exists: bool,
8101        location: Option<Expression>,
8102    },
8103    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
8104    Delete {
8105        where_clause: Expression,
8106    },
8107    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
8108    SwapWith(TableRef),
8109    /// SET property action (Snowflake): ALTER TABLE t SET property=value
8110    SetProperty {
8111        properties: Vec<(String, Expression)>,
8112    },
8113    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
8114    UnsetProperty {
8115        properties: Vec<String>,
8116    },
8117    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
8118    ClusterBy {
8119        expressions: Vec<Expression>,
8120    },
8121    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
8122    SetTag {
8123        expressions: Vec<(String, Expression)>,
8124    },
8125    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
8126    UnsetTag {
8127        names: Vec<String>,
8128    },
8129    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
8130    SetOptions {
8131        expressions: Vec<Expression>,
8132    },
8133    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
8134    AlterIndex {
8135        name: Identifier,
8136        visible: bool,
8137    },
8138    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
8139    SetAttribute {
8140        attribute: String,
8141    },
8142    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
8143    SetStageFileFormat {
8144        options: Option<Expression>,
8145    },
8146    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
8147    SetStageCopyOptions {
8148        options: Option<Expression>,
8149    },
8150    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
8151    AddColumns {
8152        columns: Vec<ColumnDef>,
8153        cascade: bool,
8154    },
8155    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
8156    DropColumns {
8157        names: Vec<Identifier>,
8158    },
8159    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
8160    /// In SingleStore, data_type can be omitted for simple column renames
8161    ChangeColumn {
8162        old_name: Identifier,
8163        new_name: Identifier,
8164        #[serde(default, skip_serializing_if = "Option::is_none")]
8165        data_type: Option<DataType>,
8166        comment: Option<String>,
8167        #[serde(default)]
8168        cascade: bool,
8169    },
8170    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
8171    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
8172    AlterSortKey {
8173        /// AUTO or NONE keyword
8174        this: Option<String>,
8175        /// Column list for (col1, col2) syntax
8176        expressions: Vec<Expression>,
8177        /// Whether COMPOUND keyword was present
8178        compound: bool,
8179    },
8180    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
8181    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
8182    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
8183    AlterDistStyle {
8184        /// Distribution style: ALL, EVEN, AUTO, or KEY
8185        style: String,
8186        /// DISTKEY column (only when style is KEY)
8187        distkey: Option<Identifier>,
8188    },
8189    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
8190    SetTableProperties {
8191        properties: Vec<(Expression, Expression)>,
8192    },
8193    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
8194    SetLocation {
8195        location: String,
8196    },
8197    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
8198    SetFileFormat {
8199        format: String,
8200    },
8201    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
8202    ReplacePartition {
8203        partition: Expression,
8204        source: Option<Box<Expression>>,
8205    },
8206    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
8207    Raw {
8208        sql: String,
8209    },
8210}
8211
8212/// Actions for ALTER COLUMN
8213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8214#[cfg_attr(feature = "bindings", derive(TS))]
8215pub enum AlterColumnAction {
8216    SetDataType {
8217        data_type: DataType,
8218        /// USING expression for type conversion (PostgreSQL)
8219        using: Option<Expression>,
8220        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
8221        #[serde(default, skip_serializing_if = "Option::is_none")]
8222        collate: Option<String>,
8223    },
8224    SetDefault(Expression),
8225    DropDefault,
8226    SetNotNull,
8227    DropNotNull,
8228    /// Set column comment
8229    Comment(String),
8230    /// MySQL: SET VISIBLE
8231    SetVisible,
8232    /// MySQL: SET INVISIBLE
8233    SetInvisible,
8234}
8235
8236/// CREATE INDEX statement
8237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8238#[cfg_attr(feature = "bindings", derive(TS))]
8239pub struct CreateIndex {
8240    pub name: Identifier,
8241    pub table: TableRef,
8242    pub columns: Vec<IndexColumn>,
8243    pub unique: bool,
8244    pub if_not_exists: bool,
8245    pub using: Option<String>,
8246    /// TSQL CLUSTERED/NONCLUSTERED modifier
8247    #[serde(default)]
8248    pub clustered: Option<String>,
8249    /// PostgreSQL CONCURRENTLY modifier
8250    #[serde(default)]
8251    pub concurrently: bool,
8252    /// PostgreSQL WHERE clause for partial indexes
8253    #[serde(default)]
8254    pub where_clause: Option<Box<Expression>>,
8255    /// PostgreSQL INCLUDE columns
8256    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8257    pub include_columns: Vec<Identifier>,
8258    /// TSQL WITH options (e.g., allow_page_locks=on)
8259    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8260    pub with_options: Vec<(String, String)>,
8261    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
8262    #[serde(default)]
8263    pub on_filegroup: Option<String>,
8264}
8265
8266impl CreateIndex {
8267    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
8268        Self {
8269            name: Identifier::new(name),
8270            table: TableRef::new(table),
8271            columns: Vec::new(),
8272            unique: false,
8273            if_not_exists: false,
8274            using: None,
8275            clustered: None,
8276            concurrently: false,
8277            where_clause: None,
8278            include_columns: Vec::new(),
8279            with_options: Vec::new(),
8280            on_filegroup: None,
8281        }
8282    }
8283}
8284
8285/// Index column specification
8286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8287#[cfg_attr(feature = "bindings", derive(TS))]
8288pub struct IndexColumn {
8289    pub column: Identifier,
8290    pub desc: bool,
8291    /// Explicit ASC keyword was present
8292    #[serde(default)]
8293    pub asc: bool,
8294    pub nulls_first: Option<bool>,
8295    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
8296    #[serde(default, skip_serializing_if = "Option::is_none")]
8297    pub opclass: Option<String>,
8298}
8299
8300/// DROP INDEX statement
8301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8302#[cfg_attr(feature = "bindings", derive(TS))]
8303pub struct DropIndex {
8304    pub name: Identifier,
8305    pub table: Option<TableRef>,
8306    pub if_exists: bool,
8307    /// PostgreSQL CONCURRENTLY modifier
8308    #[serde(default)]
8309    pub concurrently: bool,
8310}
8311
8312impl DropIndex {
8313    pub fn new(name: impl Into<String>) -> Self {
8314        Self {
8315            name: Identifier::new(name),
8316            table: None,
8317            if_exists: false,
8318            concurrently: false,
8319        }
8320    }
8321}
8322
8323/// View column definition with optional COMMENT and OPTIONS (BigQuery)
8324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8325#[cfg_attr(feature = "bindings", derive(TS))]
8326pub struct ViewColumn {
8327    pub name: Identifier,
8328    pub comment: Option<String>,
8329    /// BigQuery: OPTIONS (key=value, ...) on column
8330    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8331    pub options: Vec<Expression>,
8332}
8333
8334impl ViewColumn {
8335    pub fn new(name: impl Into<String>) -> Self {
8336        Self {
8337            name: Identifier::new(name),
8338            comment: None,
8339            options: Vec::new(),
8340        }
8341    }
8342
8343    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
8344        Self {
8345            name: Identifier::new(name),
8346            comment: Some(comment.into()),
8347            options: Vec::new(),
8348        }
8349    }
8350}
8351
8352/// CREATE VIEW statement
8353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8354#[cfg_attr(feature = "bindings", derive(TS))]
8355pub struct CreateView {
8356    pub name: TableRef,
8357    pub columns: Vec<ViewColumn>,
8358    pub query: Expression,
8359    pub or_replace: bool,
8360    /// TSQL: CREATE OR ALTER
8361    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8362    pub or_alter: bool,
8363    pub if_not_exists: bool,
8364    pub materialized: bool,
8365    pub temporary: bool,
8366    /// Snowflake: SECURE VIEW
8367    #[serde(default)]
8368    pub secure: bool,
8369    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
8370    #[serde(skip_serializing_if = "Option::is_none")]
8371    pub algorithm: Option<String>,
8372    /// MySQL: DEFINER=user@host
8373    #[serde(skip_serializing_if = "Option::is_none")]
8374    pub definer: Option<String>,
8375    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
8376    #[serde(skip_serializing_if = "Option::is_none")]
8377    pub security: Option<FunctionSecurity>,
8378    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
8379    #[serde(default = "default_true")]
8380    pub security_sql_style: bool,
8381    /// True when SQL SECURITY appears after the view name (not before VIEW keyword)
8382    #[serde(default)]
8383    pub security_after_name: bool,
8384    /// Whether the query was parenthesized: AS (SELECT ...)
8385    #[serde(default)]
8386    pub query_parenthesized: bool,
8387    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
8388    #[serde(skip_serializing_if = "Option::is_none")]
8389    pub locking_mode: Option<String>,
8390    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
8391    #[serde(skip_serializing_if = "Option::is_none")]
8392    pub locking_access: Option<String>,
8393    /// Snowflake: COPY GRANTS
8394    #[serde(default)]
8395    pub copy_grants: bool,
8396    /// Snowflake: COMMENT = 'text'
8397    #[serde(skip_serializing_if = "Option::is_none", default)]
8398    pub comment: Option<String>,
8399    /// Snowflake: TAG (name='value', ...)
8400    #[serde(default)]
8401    pub tags: Vec<(String, String)>,
8402    /// BigQuery: OPTIONS (key=value, ...)
8403    #[serde(default)]
8404    pub options: Vec<Expression>,
8405    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
8406    #[serde(skip_serializing_if = "Option::is_none", default)]
8407    pub build: Option<String>,
8408    /// Doris: REFRESH property for materialized views
8409    #[serde(skip_serializing_if = "Option::is_none", default)]
8410    pub refresh: Option<Box<RefreshTriggerProperty>>,
8411    /// Doris: Schema with typed column definitions for materialized views
8412    /// This is used instead of `columns` when the view has typed column definitions
8413    #[serde(skip_serializing_if = "Option::is_none", default)]
8414    pub schema: Option<Box<Schema>>,
8415    /// Doris: KEY (columns) for materialized views
8416    #[serde(skip_serializing_if = "Option::is_none", default)]
8417    pub unique_key: Option<Box<UniqueKeyProperty>>,
8418    /// Redshift: WITH NO SCHEMA BINDING
8419    #[serde(default)]
8420    pub no_schema_binding: bool,
8421    /// Redshift: AUTO REFRESH YES|NO for materialized views
8422    #[serde(skip_serializing_if = "Option::is_none", default)]
8423    pub auto_refresh: Option<bool>,
8424    /// ClickHouse: ON CLUSTER clause
8425    #[serde(default, skip_serializing_if = "Option::is_none")]
8426    pub on_cluster: Option<OnCluster>,
8427    /// ClickHouse: TO destination_table
8428    #[serde(default, skip_serializing_if = "Option::is_none")]
8429    pub to_table: Option<TableRef>,
8430    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
8431    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8432    pub table_properties: Vec<Expression>,
8433}
8434
8435impl CreateView {
8436    pub fn new(name: impl Into<String>, query: Expression) -> Self {
8437        Self {
8438            name: TableRef::new(name),
8439            columns: Vec::new(),
8440            query,
8441            or_replace: false,
8442            or_alter: false,
8443            if_not_exists: false,
8444            materialized: false,
8445            temporary: false,
8446            secure: false,
8447            algorithm: None,
8448            definer: None,
8449            security: None,
8450            security_sql_style: true,
8451            security_after_name: false,
8452            query_parenthesized: false,
8453            locking_mode: None,
8454            locking_access: None,
8455            copy_grants: false,
8456            comment: None,
8457            tags: Vec::new(),
8458            options: Vec::new(),
8459            build: None,
8460            refresh: None,
8461            schema: None,
8462            unique_key: None,
8463            no_schema_binding: false,
8464            auto_refresh: None,
8465            on_cluster: None,
8466            to_table: None,
8467            table_properties: Vec::new(),
8468        }
8469    }
8470}
8471
8472/// DROP VIEW statement
8473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8474#[cfg_attr(feature = "bindings", derive(TS))]
8475pub struct DropView {
8476    pub name: TableRef,
8477    pub if_exists: bool,
8478    pub materialized: bool,
8479}
8480
8481impl DropView {
8482    pub fn new(name: impl Into<String>) -> Self {
8483        Self {
8484            name: TableRef::new(name),
8485            if_exists: false,
8486            materialized: false,
8487        }
8488    }
8489}
8490
8491/// TRUNCATE TABLE statement
8492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8493#[cfg_attr(feature = "bindings", derive(TS))]
8494pub struct Truncate {
8495    /// Target of TRUNCATE (TABLE vs DATABASE)
8496    #[serde(default)]
8497    pub target: TruncateTarget,
8498    /// IF EXISTS clause
8499    #[serde(default)]
8500    pub if_exists: bool,
8501    pub table: TableRef,
8502    /// ClickHouse: ON CLUSTER clause for distributed DDL
8503    #[serde(default, skip_serializing_if = "Option::is_none")]
8504    pub on_cluster: Option<OnCluster>,
8505    pub cascade: bool,
8506    /// Additional tables for multi-table TRUNCATE
8507    #[serde(default)]
8508    pub extra_tables: Vec<TruncateTableEntry>,
8509    /// RESTART IDENTITY or CONTINUE IDENTITY
8510    #[serde(default)]
8511    pub identity: Option<TruncateIdentity>,
8512    /// RESTRICT option (alternative to CASCADE)
8513    #[serde(default)]
8514    pub restrict: bool,
8515    /// Hive PARTITION clause: PARTITION(key=value, ...)
8516    #[serde(default, skip_serializing_if = "Option::is_none")]
8517    pub partition: Option<Box<Expression>>,
8518}
8519
8520/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
8521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8522#[cfg_attr(feature = "bindings", derive(TS))]
8523pub struct TruncateTableEntry {
8524    pub table: TableRef,
8525    /// Whether the table has a * suffix (inherit children)
8526    #[serde(default)]
8527    pub star: bool,
8528}
8529
8530/// TRUNCATE target type
8531#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8532#[cfg_attr(feature = "bindings", derive(TS))]
8533pub enum TruncateTarget {
8534    Table,
8535    Database,
8536}
8537
8538impl Default for TruncateTarget {
8539    fn default() -> Self {
8540        TruncateTarget::Table
8541    }
8542}
8543
8544/// TRUNCATE identity option
8545#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8546#[cfg_attr(feature = "bindings", derive(TS))]
8547pub enum TruncateIdentity {
8548    Restart,
8549    Continue,
8550}
8551
8552impl Truncate {
8553    pub fn new(table: impl Into<String>) -> Self {
8554        Self {
8555            target: TruncateTarget::Table,
8556            if_exists: false,
8557            table: TableRef::new(table),
8558            on_cluster: None,
8559            cascade: false,
8560            extra_tables: Vec::new(),
8561            identity: None,
8562            restrict: false,
8563            partition: None,
8564        }
8565    }
8566}
8567
8568/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
8569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8570#[cfg_attr(feature = "bindings", derive(TS))]
8571pub struct Use {
8572    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
8573    pub kind: Option<UseKind>,
8574    /// The name of the object
8575    pub this: Identifier,
8576}
8577
8578/// Kind of USE statement
8579#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8580#[cfg_attr(feature = "bindings", derive(TS))]
8581pub enum UseKind {
8582    Database,
8583    Schema,
8584    Role,
8585    Warehouse,
8586    Catalog,
8587    /// Snowflake: USE SECONDARY ROLES ALL|NONE
8588    SecondaryRoles,
8589}
8590
8591/// SET variable statement
8592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8593#[cfg_attr(feature = "bindings", derive(TS))]
8594pub struct SetStatement {
8595    /// The items being set
8596    pub items: Vec<SetItem>,
8597}
8598
8599/// A single SET item (variable assignment)
8600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8601#[cfg_attr(feature = "bindings", derive(TS))]
8602pub struct SetItem {
8603    /// The variable name
8604    pub name: Expression,
8605    /// The value to set
8606    pub value: Expression,
8607    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
8608    pub kind: Option<String>,
8609    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
8610    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8611    pub no_equals: bool,
8612}
8613
8614/// CACHE TABLE statement (Spark)
8615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8616#[cfg_attr(feature = "bindings", derive(TS))]
8617pub struct Cache {
8618    /// The table to cache
8619    pub table: Identifier,
8620    /// LAZY keyword - defer caching until first use
8621    pub lazy: bool,
8622    /// Optional OPTIONS clause (key-value pairs)
8623    pub options: Vec<(Expression, Expression)>,
8624    /// Optional AS clause with query
8625    pub query: Option<Expression>,
8626}
8627
8628/// UNCACHE TABLE statement (Spark)
8629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8630#[cfg_attr(feature = "bindings", derive(TS))]
8631pub struct Uncache {
8632    /// The table to uncache
8633    pub table: Identifier,
8634    /// IF EXISTS clause
8635    pub if_exists: bool,
8636}
8637
8638/// LOAD DATA statement (Hive)
8639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8640#[cfg_attr(feature = "bindings", derive(TS))]
8641pub struct LoadData {
8642    /// LOCAL keyword - load from local filesystem
8643    pub local: bool,
8644    /// The path to load data from (INPATH value)
8645    pub inpath: String,
8646    /// Whether to overwrite existing data
8647    pub overwrite: bool,
8648    /// The target table
8649    pub table: Expression,
8650    /// Optional PARTITION clause with key-value pairs
8651    pub partition: Vec<(Identifier, Expression)>,
8652    /// Optional INPUTFORMAT clause
8653    pub input_format: Option<String>,
8654    /// Optional SERDE clause
8655    pub serde: Option<String>,
8656}
8657
8658/// PRAGMA statement (SQLite)
8659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8660#[cfg_attr(feature = "bindings", derive(TS))]
8661pub struct Pragma {
8662    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
8663    pub schema: Option<Identifier>,
8664    /// The pragma name
8665    pub name: Identifier,
8666    /// Optional value for assignment (PRAGMA name = value)
8667    pub value: Option<Expression>,
8668    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
8669    pub args: Vec<Expression>,
8670}
8671
8672/// A privilege with optional column list for GRANT/REVOKE
8673/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
8674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8675#[cfg_attr(feature = "bindings", derive(TS))]
8676pub struct Privilege {
8677    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
8678    pub name: String,
8679    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
8680    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8681    pub columns: Vec<String>,
8682}
8683
8684/// Principal in GRANT/REVOKE (user, role, etc.)
8685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8686#[cfg_attr(feature = "bindings", derive(TS))]
8687pub struct GrantPrincipal {
8688    /// The name of the principal
8689    pub name: Identifier,
8690    /// Whether prefixed with ROLE keyword
8691    pub is_role: bool,
8692    /// Whether prefixed with GROUP keyword (Redshift)
8693    #[serde(default)]
8694    pub is_group: bool,
8695    /// Whether prefixed with SHARE keyword (Snowflake)
8696    #[serde(default)]
8697    pub is_share: bool,
8698}
8699
8700/// GRANT statement
8701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8702#[cfg_attr(feature = "bindings", derive(TS))]
8703pub struct Grant {
8704    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
8705    pub privileges: Vec<Privilege>,
8706    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8707    pub kind: Option<String>,
8708    /// The object to grant on
8709    pub securable: Identifier,
8710    /// Function parameter types (for FUNCTION kind)
8711    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8712    pub function_params: Vec<String>,
8713    /// The grantees
8714    pub principals: Vec<GrantPrincipal>,
8715    /// WITH GRANT OPTION
8716    pub grant_option: bool,
8717    /// TSQL: AS principal (the grantor role)
8718    #[serde(default, skip_serializing_if = "Option::is_none")]
8719    pub as_principal: Option<Identifier>,
8720}
8721
8722/// REVOKE statement
8723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8724#[cfg_attr(feature = "bindings", derive(TS))]
8725pub struct Revoke {
8726    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
8727    pub privileges: Vec<Privilege>,
8728    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
8729    pub kind: Option<String>,
8730    /// The object to revoke from
8731    pub securable: Identifier,
8732    /// Function parameter types (for FUNCTION kind)
8733    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8734    pub function_params: Vec<String>,
8735    /// The grantees
8736    pub principals: Vec<GrantPrincipal>,
8737    /// GRANT OPTION FOR
8738    pub grant_option: bool,
8739    /// CASCADE
8740    pub cascade: bool,
8741    /// RESTRICT
8742    #[serde(default)]
8743    pub restrict: bool,
8744}
8745
8746/// COMMENT ON statement
8747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8748#[cfg_attr(feature = "bindings", derive(TS))]
8749pub struct Comment {
8750    /// The object being commented on
8751    pub this: Expression,
8752    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
8753    pub kind: String,
8754    /// The comment text expression
8755    pub expression: Expression,
8756    /// IF EXISTS clause
8757    pub exists: bool,
8758    /// MATERIALIZED keyword
8759    pub materialized: bool,
8760}
8761
8762// ============================================================================
8763// Phase 4: Additional DDL Statements
8764// ============================================================================
8765
8766/// ALTER VIEW statement
8767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8768#[cfg_attr(feature = "bindings", derive(TS))]
8769pub struct AlterView {
8770    pub name: TableRef,
8771    pub actions: Vec<AlterViewAction>,
8772    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
8773    #[serde(default, skip_serializing_if = "Option::is_none")]
8774    pub algorithm: Option<String>,
8775    /// MySQL: DEFINER = 'user'@'host'
8776    #[serde(default, skip_serializing_if = "Option::is_none")]
8777    pub definer: Option<String>,
8778    /// MySQL: SQL SECURITY = DEFINER|INVOKER
8779    #[serde(default, skip_serializing_if = "Option::is_none")]
8780    pub sql_security: Option<String>,
8781    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
8782    #[serde(default, skip_serializing_if = "Option::is_none")]
8783    pub with_option: Option<String>,
8784    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
8785    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8786    pub columns: Vec<ViewColumn>,
8787}
8788
8789/// Actions for ALTER VIEW
8790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8791#[cfg_attr(feature = "bindings", derive(TS))]
8792pub enum AlterViewAction {
8793    /// Rename the view
8794    Rename(TableRef),
8795    /// Change owner
8796    OwnerTo(Identifier),
8797    /// Set schema
8798    SetSchema(Identifier),
8799    /// Set authorization (Trino/Presto)
8800    SetAuthorization(String),
8801    /// Alter column
8802    AlterColumn {
8803        name: Identifier,
8804        action: AlterColumnAction,
8805    },
8806    /// Redefine view as query (SELECT, UNION, etc.)
8807    AsSelect(Box<Expression>),
8808    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
8809    SetTblproperties(Vec<(String, String)>),
8810    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
8811    UnsetTblproperties(Vec<String>),
8812}
8813
8814impl AlterView {
8815    pub fn new(name: impl Into<String>) -> Self {
8816        Self {
8817            name: TableRef::new(name),
8818            actions: Vec::new(),
8819            algorithm: None,
8820            definer: None,
8821            sql_security: None,
8822            with_option: None,
8823            columns: Vec::new(),
8824        }
8825    }
8826}
8827
8828/// ALTER INDEX statement
8829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8830#[cfg_attr(feature = "bindings", derive(TS))]
8831pub struct AlterIndex {
8832    pub name: Identifier,
8833    pub table: Option<TableRef>,
8834    pub actions: Vec<AlterIndexAction>,
8835}
8836
8837/// Actions for ALTER INDEX
8838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8839#[cfg_attr(feature = "bindings", derive(TS))]
8840pub enum AlterIndexAction {
8841    /// Rename the index
8842    Rename(Identifier),
8843    /// Set tablespace
8844    SetTablespace(Identifier),
8845    /// Set visibility (MySQL)
8846    Visible(bool),
8847}
8848
8849impl AlterIndex {
8850    pub fn new(name: impl Into<String>) -> Self {
8851        Self {
8852            name: Identifier::new(name),
8853            table: None,
8854            actions: Vec::new(),
8855        }
8856    }
8857}
8858
8859/// CREATE SCHEMA statement
8860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8861#[cfg_attr(feature = "bindings", derive(TS))]
8862pub struct CreateSchema {
8863    /// Schema name parts, possibly dot-qualified (e.g. [mydb, hr] for "mydb.hr")
8864    pub name: Vec<Identifier>,
8865    pub if_not_exists: bool,
8866    pub authorization: Option<Identifier>,
8867    /// CLONE source parts, possibly dot-qualified
8868    #[serde(default)]
8869    pub clone_from: Option<Vec<Identifier>>,
8870    /// AT/BEFORE clause for time travel (Snowflake)
8871    #[serde(default)]
8872    pub at_clause: Option<Expression>,
8873    /// Schema properties like DEFAULT COLLATE
8874    #[serde(default)]
8875    pub properties: Vec<Expression>,
8876    /// Leading comments before the statement
8877    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8878    pub leading_comments: Vec<String>,
8879}
8880
8881impl CreateSchema {
8882    pub fn new(name: impl Into<String>) -> Self {
8883        Self {
8884            name: vec![Identifier::new(name)],
8885            if_not_exists: false,
8886            authorization: None,
8887            clone_from: None,
8888            at_clause: None,
8889            properties: Vec::new(),
8890            leading_comments: Vec::new(),
8891        }
8892    }
8893}
8894
8895/// DROP SCHEMA statement
8896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8897#[cfg_attr(feature = "bindings", derive(TS))]
8898pub struct DropSchema {
8899    pub name: Identifier,
8900    pub if_exists: bool,
8901    pub cascade: bool,
8902}
8903
8904impl DropSchema {
8905    pub fn new(name: impl Into<String>) -> Self {
8906        Self {
8907            name: Identifier::new(name),
8908            if_exists: false,
8909            cascade: false,
8910        }
8911    }
8912}
8913
8914/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
8915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8916#[cfg_attr(feature = "bindings", derive(TS))]
8917pub struct DropNamespace {
8918    pub name: Identifier,
8919    pub if_exists: bool,
8920    pub cascade: bool,
8921}
8922
8923impl DropNamespace {
8924    pub fn new(name: impl Into<String>) -> Self {
8925        Self {
8926            name: Identifier::new(name),
8927            if_exists: false,
8928            cascade: false,
8929        }
8930    }
8931}
8932
8933/// CREATE DATABASE statement
8934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8935#[cfg_attr(feature = "bindings", derive(TS))]
8936pub struct CreateDatabase {
8937    pub name: Identifier,
8938    pub if_not_exists: bool,
8939    pub options: Vec<DatabaseOption>,
8940    /// Snowflake CLONE source
8941    #[serde(default)]
8942    pub clone_from: Option<Identifier>,
8943    /// AT/BEFORE clause for time travel (Snowflake)
8944    #[serde(default)]
8945    pub at_clause: Option<Expression>,
8946}
8947
8948/// Database option
8949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8950#[cfg_attr(feature = "bindings", derive(TS))]
8951pub enum DatabaseOption {
8952    CharacterSet(String),
8953    Collate(String),
8954    Owner(Identifier),
8955    Template(Identifier),
8956    Encoding(String),
8957    Location(String),
8958}
8959
8960impl CreateDatabase {
8961    pub fn new(name: impl Into<String>) -> Self {
8962        Self {
8963            name: Identifier::new(name),
8964            if_not_exists: false,
8965            options: Vec::new(),
8966            clone_from: None,
8967            at_clause: None,
8968        }
8969    }
8970}
8971
8972/// DROP DATABASE statement
8973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8974#[cfg_attr(feature = "bindings", derive(TS))]
8975pub struct DropDatabase {
8976    pub name: Identifier,
8977    pub if_exists: bool,
8978    /// ClickHouse: SYNC modifier
8979    #[serde(default)]
8980    pub sync: bool,
8981}
8982
8983impl DropDatabase {
8984    pub fn new(name: impl Into<String>) -> Self {
8985        Self {
8986            name: Identifier::new(name),
8987            if_exists: false,
8988            sync: false,
8989        }
8990    }
8991}
8992
8993/// CREATE FUNCTION statement
8994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8995#[cfg_attr(feature = "bindings", derive(TS))]
8996pub struct CreateFunction {
8997    pub name: TableRef,
8998    pub parameters: Vec<FunctionParameter>,
8999    pub return_type: Option<DataType>,
9000    pub body: Option<FunctionBody>,
9001    pub or_replace: bool,
9002    /// TSQL: CREATE OR ALTER
9003    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9004    pub or_alter: bool,
9005    pub if_not_exists: bool,
9006    pub temporary: bool,
9007    pub language: Option<String>,
9008    pub deterministic: Option<bool>,
9009    pub returns_null_on_null_input: Option<bool>,
9010    pub security: Option<FunctionSecurity>,
9011    /// Whether parentheses were present in the original syntax
9012    #[serde(default = "default_true")]
9013    pub has_parens: bool,
9014    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
9015    #[serde(default)]
9016    pub sql_data_access: Option<SqlDataAccess>,
9017    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
9018    #[serde(default, skip_serializing_if = "Option::is_none")]
9019    pub returns_table_body: Option<String>,
9020    /// True if LANGUAGE clause appears before RETURNS clause
9021    #[serde(default)]
9022    pub language_first: bool,
9023    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
9024    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9025    pub set_options: Vec<FunctionSetOption>,
9026    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
9027    #[serde(default)]
9028    pub strict: bool,
9029    /// BigQuery: OPTIONS (key=value, ...)
9030    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9031    pub options: Vec<Expression>,
9032    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
9033    #[serde(default)]
9034    pub is_table_function: bool,
9035    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
9036    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9037    pub property_order: Vec<FunctionPropertyKind>,
9038    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
9039    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9040    pub environment: Vec<Expression>,
9041    /// HANDLER 'handler_function' clause (Databricks)
9042    #[serde(default, skip_serializing_if = "Option::is_none")]
9043    pub handler: Option<String>,
9044    /// PARAMETER STYLE clause (e.g., PANDAS for Databricks)
9045    #[serde(default, skip_serializing_if = "Option::is_none")]
9046    pub parameter_style: Option<String>,
9047}
9048
9049/// A SET option in CREATE FUNCTION (PostgreSQL)
9050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9051#[cfg_attr(feature = "bindings", derive(TS))]
9052pub struct FunctionSetOption {
9053    pub name: String,
9054    pub value: FunctionSetValue,
9055}
9056
9057/// The value of a SET option
9058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9059#[cfg_attr(feature = "bindings", derive(TS))]
9060pub enum FunctionSetValue {
9061    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
9062    Value { value: String, use_to: bool },
9063    /// SET key FROM CURRENT
9064    FromCurrent,
9065}
9066
9067/// SQL data access characteristics for functions
9068#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9069#[cfg_attr(feature = "bindings", derive(TS))]
9070pub enum SqlDataAccess {
9071    /// NO SQL
9072    NoSql,
9073    /// CONTAINS SQL
9074    ContainsSql,
9075    /// READS SQL DATA
9076    ReadsSqlData,
9077    /// MODIFIES SQL DATA
9078    ModifiesSqlData,
9079}
9080
9081/// Types of properties in CREATE FUNCTION for tracking their original order
9082#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9083#[cfg_attr(feature = "bindings", derive(TS))]
9084pub enum FunctionPropertyKind {
9085    /// SET option
9086    Set,
9087    /// AS body
9088    As,
9089    /// LANGUAGE clause
9090    Language,
9091    /// IMMUTABLE/VOLATILE/STABLE (determinism)
9092    Determinism,
9093    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
9094    NullInput,
9095    /// SECURITY DEFINER/INVOKER
9096    Security,
9097    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
9098    SqlDataAccess,
9099    /// OPTIONS clause (BigQuery)
9100    Options,
9101    /// ENVIRONMENT clause (Databricks)
9102    Environment,
9103    /// HANDLER clause (Databricks)
9104    Handler,
9105    /// PARAMETER STYLE clause (Databricks)
9106    ParameterStyle,
9107}
9108
9109/// Function parameter
9110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9111#[cfg_attr(feature = "bindings", derive(TS))]
9112pub struct FunctionParameter {
9113    pub name: Option<Identifier>,
9114    pub data_type: DataType,
9115    pub mode: Option<ParameterMode>,
9116    pub default: Option<Expression>,
9117    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
9118    #[serde(default, skip_serializing_if = "Option::is_none")]
9119    pub mode_text: Option<String>,
9120}
9121
9122/// Parameter mode (IN, OUT, INOUT, VARIADIC)
9123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9124#[cfg_attr(feature = "bindings", derive(TS))]
9125pub enum ParameterMode {
9126    In,
9127    Out,
9128    InOut,
9129    Variadic,
9130}
9131
9132/// Function body
9133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9134#[cfg_attr(feature = "bindings", derive(TS))]
9135pub enum FunctionBody {
9136    /// AS $$ ... $$ (dollar-quoted)
9137    Block(String),
9138    /// AS 'string' (single-quoted string literal body)
9139    StringLiteral(String),
9140    /// AS 'expression'
9141    Expression(Expression),
9142    /// EXTERNAL NAME 'library'
9143    External(String),
9144    /// RETURN expression
9145    Return(Expression),
9146    /// BEGIN ... END block with parsed statements
9147    Statements(Vec<Expression>),
9148    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
9149    /// Stores (content, optional_tag)
9150    DollarQuoted {
9151        content: String,
9152        tag: Option<String>,
9153    },
9154    /// BEGIN ... END block preserved as raw text (MySQL procedural bodies)
9155    RawBlock(String),
9156}
9157
9158/// Function security (DEFINER, INVOKER, or NONE)
9159#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9160#[cfg_attr(feature = "bindings", derive(TS))]
9161pub enum FunctionSecurity {
9162    Definer,
9163    Invoker,
9164    /// StarRocks/MySQL: SECURITY NONE
9165    None,
9166}
9167
9168impl CreateFunction {
9169    pub fn new(name: impl Into<String>) -> Self {
9170        Self {
9171            name: TableRef::new(name),
9172            parameters: Vec::new(),
9173            return_type: None,
9174            body: None,
9175            or_replace: false,
9176            or_alter: false,
9177            if_not_exists: false,
9178            temporary: false,
9179            language: None,
9180            deterministic: None,
9181            returns_null_on_null_input: None,
9182            security: None,
9183            has_parens: true,
9184            sql_data_access: None,
9185            returns_table_body: None,
9186            language_first: false,
9187            set_options: Vec::new(),
9188            strict: false,
9189            options: Vec::new(),
9190            is_table_function: false,
9191            property_order: Vec::new(),
9192            environment: Vec::new(),
9193            handler: None,
9194            parameter_style: None,
9195        }
9196    }
9197}
9198
9199/// DROP FUNCTION statement
9200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9201#[cfg_attr(feature = "bindings", derive(TS))]
9202pub struct DropFunction {
9203    pub name: TableRef,
9204    pub parameters: Option<Vec<DataType>>,
9205    pub if_exists: bool,
9206    pub cascade: bool,
9207}
9208
9209impl DropFunction {
9210    pub fn new(name: impl Into<String>) -> Self {
9211        Self {
9212            name: TableRef::new(name),
9213            parameters: None,
9214            if_exists: false,
9215            cascade: false,
9216        }
9217    }
9218}
9219
9220/// CREATE PROCEDURE statement
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct CreateProcedure {
9224    pub name: TableRef,
9225    pub parameters: Vec<FunctionParameter>,
9226    pub body: Option<FunctionBody>,
9227    pub or_replace: bool,
9228    /// TSQL: CREATE OR ALTER
9229    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9230    pub or_alter: bool,
9231    pub if_not_exists: bool,
9232    pub language: Option<String>,
9233    pub security: Option<FunctionSecurity>,
9234    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
9235    #[serde(default)]
9236    pub return_type: Option<DataType>,
9237    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
9238    #[serde(default)]
9239    pub execute_as: Option<String>,
9240    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
9241    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9242    pub with_options: Vec<String>,
9243    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
9244    #[serde(default = "default_true", skip_serializing_if = "is_true")]
9245    pub has_parens: bool,
9246    /// Whether the short form PROC was used (instead of PROCEDURE)
9247    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9248    pub use_proc_keyword: bool,
9249}
9250
9251impl CreateProcedure {
9252    pub fn new(name: impl Into<String>) -> Self {
9253        Self {
9254            name: TableRef::new(name),
9255            parameters: Vec::new(),
9256            body: None,
9257            or_replace: false,
9258            or_alter: false,
9259            if_not_exists: false,
9260            language: None,
9261            security: None,
9262            return_type: None,
9263            execute_as: None,
9264            with_options: Vec::new(),
9265            has_parens: true,
9266            use_proc_keyword: false,
9267        }
9268    }
9269}
9270
9271/// DROP PROCEDURE statement
9272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9273#[cfg_attr(feature = "bindings", derive(TS))]
9274pub struct DropProcedure {
9275    pub name: TableRef,
9276    pub parameters: Option<Vec<DataType>>,
9277    pub if_exists: bool,
9278    pub cascade: bool,
9279}
9280
9281impl DropProcedure {
9282    pub fn new(name: impl Into<String>) -> Self {
9283        Self {
9284            name: TableRef::new(name),
9285            parameters: None,
9286            if_exists: false,
9287            cascade: false,
9288        }
9289    }
9290}
9291
9292/// Sequence property tag for ordering
9293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9294#[cfg_attr(feature = "bindings", derive(TS))]
9295pub enum SeqPropKind {
9296    Start,
9297    Increment,
9298    Minvalue,
9299    Maxvalue,
9300    Cache,
9301    NoCache,
9302    Cycle,
9303    NoCycle,
9304    OwnedBy,
9305    Order,
9306    NoOrder,
9307    Comment,
9308    /// SHARING=<value> (Oracle)
9309    Sharing,
9310    /// KEEP (Oracle)
9311    Keep,
9312    /// NOKEEP (Oracle)
9313    NoKeep,
9314    /// SCALE [EXTEND|NOEXTEND] (Oracle)
9315    Scale,
9316    /// NOSCALE (Oracle)
9317    NoScale,
9318    /// SHARD [EXTEND|NOEXTEND] (Oracle)
9319    Shard,
9320    /// NOSHARD (Oracle)
9321    NoShard,
9322    /// SESSION (Oracle)
9323    Session,
9324    /// GLOBAL (Oracle)
9325    Global,
9326    /// NOCACHE (single word, Oracle)
9327    NoCacheWord,
9328    /// NOCYCLE (single word, Oracle)
9329    NoCycleWord,
9330    /// NOMINVALUE (single word, Oracle)
9331    NoMinvalueWord,
9332    /// NOMAXVALUE (single word, Oracle)
9333    NoMaxvalueWord,
9334}
9335
9336/// CREATE SYNONYM statement (TSQL)
9337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9338#[cfg_attr(feature = "bindings", derive(TS))]
9339pub struct CreateSynonym {
9340    /// The synonym name (can be qualified: schema.synonym_name)
9341    pub name: TableRef,
9342    /// The target object the synonym refers to
9343    pub target: TableRef,
9344}
9345
9346/// CREATE SEQUENCE statement
9347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9348#[cfg_attr(feature = "bindings", derive(TS))]
9349pub struct CreateSequence {
9350    pub name: TableRef,
9351    pub if_not_exists: bool,
9352    pub temporary: bool,
9353    #[serde(default)]
9354    pub or_replace: bool,
9355    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
9356    #[serde(default, skip_serializing_if = "Option::is_none")]
9357    pub as_type: Option<DataType>,
9358    pub increment: Option<i64>,
9359    pub minvalue: Option<SequenceBound>,
9360    pub maxvalue: Option<SequenceBound>,
9361    pub start: Option<i64>,
9362    pub cache: Option<i64>,
9363    pub cycle: bool,
9364    pub owned_by: Option<TableRef>,
9365    /// Whether OWNED BY NONE was specified
9366    #[serde(default)]
9367    pub owned_by_none: bool,
9368    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
9369    #[serde(default)]
9370    pub order: Option<bool>,
9371    /// Snowflake: COMMENT = 'value'
9372    #[serde(default)]
9373    pub comment: Option<String>,
9374    /// SHARING=<value> (Oracle)
9375    #[serde(default, skip_serializing_if = "Option::is_none")]
9376    pub sharing: Option<String>,
9377    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
9378    #[serde(default, skip_serializing_if = "Option::is_none")]
9379    pub scale_modifier: Option<String>,
9380    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
9381    #[serde(default, skip_serializing_if = "Option::is_none")]
9382    pub shard_modifier: Option<String>,
9383    /// Tracks the order in which properties appeared in the source
9384    #[serde(default)]
9385    pub property_order: Vec<SeqPropKind>,
9386}
9387
9388/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
9389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9390#[cfg_attr(feature = "bindings", derive(TS))]
9391pub enum SequenceBound {
9392    Value(i64),
9393    None,
9394}
9395
9396impl CreateSequence {
9397    pub fn new(name: impl Into<String>) -> Self {
9398        Self {
9399            name: TableRef::new(name),
9400            if_not_exists: false,
9401            temporary: false,
9402            or_replace: false,
9403            as_type: None,
9404            increment: None,
9405            minvalue: None,
9406            maxvalue: None,
9407            start: None,
9408            cache: None,
9409            cycle: false,
9410            owned_by: None,
9411            owned_by_none: false,
9412            order: None,
9413            comment: None,
9414            sharing: None,
9415            scale_modifier: None,
9416            shard_modifier: None,
9417            property_order: Vec::new(),
9418        }
9419    }
9420}
9421
9422/// DROP SEQUENCE statement
9423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9424#[cfg_attr(feature = "bindings", derive(TS))]
9425pub struct DropSequence {
9426    pub name: TableRef,
9427    pub if_exists: bool,
9428    pub cascade: bool,
9429}
9430
9431impl DropSequence {
9432    pub fn new(name: impl Into<String>) -> Self {
9433        Self {
9434            name: TableRef::new(name),
9435            if_exists: false,
9436            cascade: false,
9437        }
9438    }
9439}
9440
9441/// ALTER SEQUENCE statement
9442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9443#[cfg_attr(feature = "bindings", derive(TS))]
9444pub struct AlterSequence {
9445    pub name: TableRef,
9446    pub if_exists: bool,
9447    pub increment: Option<i64>,
9448    pub minvalue: Option<SequenceBound>,
9449    pub maxvalue: Option<SequenceBound>,
9450    pub start: Option<i64>,
9451    pub restart: Option<Option<i64>>,
9452    pub cache: Option<i64>,
9453    pub cycle: Option<bool>,
9454    pub owned_by: Option<Option<TableRef>>,
9455}
9456
9457impl AlterSequence {
9458    pub fn new(name: impl Into<String>) -> Self {
9459        Self {
9460            name: TableRef::new(name),
9461            if_exists: false,
9462            increment: None,
9463            minvalue: None,
9464            maxvalue: None,
9465            start: None,
9466            restart: None,
9467            cache: None,
9468            cycle: None,
9469            owned_by: None,
9470        }
9471    }
9472}
9473
9474/// CREATE TRIGGER statement
9475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9476#[cfg_attr(feature = "bindings", derive(TS))]
9477pub struct CreateTrigger {
9478    pub name: Identifier,
9479    pub table: TableRef,
9480    pub timing: TriggerTiming,
9481    pub events: Vec<TriggerEvent>,
9482    #[serde(default, skip_serializing_if = "Option::is_none")]
9483    pub for_each: Option<TriggerForEach>,
9484    pub when: Option<Expression>,
9485    /// Whether the WHEN clause was parenthesized in the original SQL
9486    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9487    pub when_paren: bool,
9488    pub body: TriggerBody,
9489    pub or_replace: bool,
9490    /// TSQL: CREATE OR ALTER
9491    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9492    pub or_alter: bool,
9493    pub constraint: bool,
9494    pub deferrable: Option<bool>,
9495    pub initially_deferred: Option<bool>,
9496    pub referencing: Option<TriggerReferencing>,
9497}
9498
9499/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
9500#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9501#[cfg_attr(feature = "bindings", derive(TS))]
9502pub enum TriggerTiming {
9503    Before,
9504    After,
9505    InsteadOf,
9506}
9507
9508/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
9509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9510#[cfg_attr(feature = "bindings", derive(TS))]
9511pub enum TriggerEvent {
9512    Insert,
9513    Update(Option<Vec<Identifier>>),
9514    Delete,
9515    Truncate,
9516}
9517
9518/// Trigger FOR EACH clause
9519#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9520#[cfg_attr(feature = "bindings", derive(TS))]
9521pub enum TriggerForEach {
9522    Row,
9523    Statement,
9524}
9525
9526/// Trigger body
9527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9528#[cfg_attr(feature = "bindings", derive(TS))]
9529pub enum TriggerBody {
9530    /// EXECUTE FUNCTION/PROCEDURE name(args)
9531    Execute {
9532        function: TableRef,
9533        args: Vec<Expression>,
9534    },
9535    /// BEGIN ... END block
9536    Block(String),
9537}
9538
9539/// Trigger REFERENCING clause
9540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9541#[cfg_attr(feature = "bindings", derive(TS))]
9542pub struct TriggerReferencing {
9543    pub old_table: Option<Identifier>,
9544    pub new_table: Option<Identifier>,
9545    pub old_row: Option<Identifier>,
9546    pub new_row: Option<Identifier>,
9547}
9548
9549impl CreateTrigger {
9550    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
9551        Self {
9552            name: Identifier::new(name),
9553            table: TableRef::new(table),
9554            timing: TriggerTiming::Before,
9555            events: Vec::new(),
9556            for_each: Some(TriggerForEach::Row),
9557            when: None,
9558            when_paren: false,
9559            body: TriggerBody::Execute {
9560                function: TableRef::new(""),
9561                args: Vec::new(),
9562            },
9563            or_replace: false,
9564            or_alter: false,
9565            constraint: false,
9566            deferrable: None,
9567            initially_deferred: None,
9568            referencing: None,
9569        }
9570    }
9571}
9572
9573/// DROP TRIGGER statement
9574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9575#[cfg_attr(feature = "bindings", derive(TS))]
9576pub struct DropTrigger {
9577    pub name: Identifier,
9578    pub table: Option<TableRef>,
9579    pub if_exists: bool,
9580    pub cascade: bool,
9581}
9582
9583impl DropTrigger {
9584    pub fn new(name: impl Into<String>) -> Self {
9585        Self {
9586            name: Identifier::new(name),
9587            table: None,
9588            if_exists: false,
9589            cascade: false,
9590        }
9591    }
9592}
9593
9594/// CREATE TYPE statement
9595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9596#[cfg_attr(feature = "bindings", derive(TS))]
9597pub struct CreateType {
9598    pub name: TableRef,
9599    pub definition: TypeDefinition,
9600    pub if_not_exists: bool,
9601}
9602
9603/// Type definition
9604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9605#[cfg_attr(feature = "bindings", derive(TS))]
9606pub enum TypeDefinition {
9607    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
9608    Enum(Vec<String>),
9609    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
9610    Composite(Vec<TypeAttribute>),
9611    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
9612    Range {
9613        subtype: DataType,
9614        subtype_diff: Option<String>,
9615        canonical: Option<String>,
9616    },
9617    /// Base type (for advanced usage)
9618    Base {
9619        input: String,
9620        output: String,
9621        internallength: Option<i32>,
9622    },
9623    /// Domain type
9624    Domain {
9625        base_type: DataType,
9626        default: Option<Expression>,
9627        constraints: Vec<DomainConstraint>,
9628    },
9629}
9630
9631/// Type attribute for composite types
9632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9633#[cfg_attr(feature = "bindings", derive(TS))]
9634pub struct TypeAttribute {
9635    pub name: Identifier,
9636    pub data_type: DataType,
9637    pub collate: Option<Identifier>,
9638}
9639
9640/// Domain constraint
9641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9642#[cfg_attr(feature = "bindings", derive(TS))]
9643pub struct DomainConstraint {
9644    pub name: Option<Identifier>,
9645    pub check: Expression,
9646}
9647
9648impl CreateType {
9649    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
9650        Self {
9651            name: TableRef::new(name),
9652            definition: TypeDefinition::Enum(values),
9653            if_not_exists: false,
9654        }
9655    }
9656
9657    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
9658        Self {
9659            name: TableRef::new(name),
9660            definition: TypeDefinition::Composite(attributes),
9661            if_not_exists: false,
9662        }
9663    }
9664}
9665
9666/// DROP TYPE statement
9667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9668#[cfg_attr(feature = "bindings", derive(TS))]
9669pub struct DropType {
9670    pub name: TableRef,
9671    pub if_exists: bool,
9672    pub cascade: bool,
9673}
9674
9675impl DropType {
9676    pub fn new(name: impl Into<String>) -> Self {
9677        Self {
9678            name: TableRef::new(name),
9679            if_exists: false,
9680            cascade: false,
9681        }
9682    }
9683}
9684
9685/// DESCRIBE statement - shows table structure or query plan
9686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9687#[cfg_attr(feature = "bindings", derive(TS))]
9688pub struct Describe {
9689    /// The target to describe (table name or query)
9690    pub target: Expression,
9691    /// EXTENDED format
9692    pub extended: bool,
9693    /// FORMATTED format
9694    pub formatted: bool,
9695    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
9696    #[serde(default)]
9697    pub kind: Option<String>,
9698    /// Properties like type=stage
9699    #[serde(default)]
9700    pub properties: Vec<(String, String)>,
9701    /// Style keyword (e.g., "ANALYZE", "HISTORY")
9702    #[serde(default, skip_serializing_if = "Option::is_none")]
9703    pub style: Option<String>,
9704    /// Partition specification for DESCRIBE PARTITION
9705    #[serde(default)]
9706    pub partition: Option<Box<Expression>>,
9707    /// Leading comments before the statement
9708    #[serde(default)]
9709    pub leading_comments: Vec<String>,
9710    /// AS JSON suffix (Databricks)
9711    #[serde(default)]
9712    pub as_json: bool,
9713    /// Parenthesized parameter types for DESCRIBE PROCEDURE/FUNCTION (e.g., INT, VARCHAR)
9714    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9715    pub params: Vec<String>,
9716}
9717
9718impl Describe {
9719    pub fn new(target: Expression) -> Self {
9720        Self {
9721            target,
9722            extended: false,
9723            formatted: false,
9724            kind: None,
9725            properties: Vec::new(),
9726            style: None,
9727            partition: None,
9728            leading_comments: Vec::new(),
9729            as_json: false,
9730            params: Vec::new(),
9731        }
9732    }
9733}
9734
9735/// SHOW statement - displays database objects
9736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9737#[cfg_attr(feature = "bindings", derive(TS))]
9738pub struct Show {
9739    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
9740    pub this: String,
9741    /// Whether TERSE was specified
9742    #[serde(default)]
9743    pub terse: bool,
9744    /// Whether HISTORY was specified
9745    #[serde(default)]
9746    pub history: bool,
9747    /// LIKE pattern
9748    pub like: Option<Expression>,
9749    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
9750    pub scope_kind: Option<String>,
9751    /// IN scope object
9752    pub scope: Option<Expression>,
9753    /// STARTS WITH pattern
9754    pub starts_with: Option<Expression>,
9755    /// LIMIT clause
9756    pub limit: Option<Box<Limit>>,
9757    /// FROM clause (for specific object)
9758    pub from: Option<Expression>,
9759    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
9760    #[serde(default, skip_serializing_if = "Option::is_none")]
9761    pub where_clause: Option<Expression>,
9762    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
9763    #[serde(default, skip_serializing_if = "Option::is_none")]
9764    pub for_target: Option<Expression>,
9765    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
9766    #[serde(default, skip_serializing_if = "Option::is_none")]
9767    pub db: Option<Expression>,
9768    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
9769    #[serde(default, skip_serializing_if = "Option::is_none")]
9770    pub target: Option<Expression>,
9771    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
9772    #[serde(default, skip_serializing_if = "Option::is_none")]
9773    pub mutex: Option<bool>,
9774    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
9775    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9776    pub privileges: Vec<String>,
9777}
9778
9779impl Show {
9780    pub fn new(this: impl Into<String>) -> Self {
9781        Self {
9782            this: this.into(),
9783            terse: false,
9784            history: false,
9785            like: None,
9786            scope_kind: None,
9787            scope: None,
9788            starts_with: None,
9789            limit: None,
9790            from: None,
9791            where_clause: None,
9792            for_target: None,
9793            db: None,
9794            target: None,
9795            mutex: None,
9796            privileges: Vec::new(),
9797        }
9798    }
9799}
9800
9801/// Represent an explicit parenthesized expression for grouping precedence.
9802///
9803/// Preserves user-written parentheses so that `(a + b) * c` round-trips
9804/// correctly instead of being flattened to `a + b * c`.
9805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9806#[cfg_attr(feature = "bindings", derive(TS))]
9807pub struct Paren {
9808    /// The inner expression wrapped by parentheses.
9809    pub this: Expression,
9810    #[serde(default)]
9811    pub trailing_comments: Vec<String>,
9812}
9813
9814/// Expression annotated with trailing comments (for round-trip preservation)
9815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9816#[cfg_attr(feature = "bindings", derive(TS))]
9817pub struct Annotated {
9818    pub this: Expression,
9819    pub trailing_comments: Vec<String>,
9820}
9821
9822// === BATCH GENERATED STRUCT DEFINITIONS ===
9823// Generated from Python sqlglot expressions.py
9824
9825/// Refresh
9826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9827#[cfg_attr(feature = "bindings", derive(TS))]
9828pub struct Refresh {
9829    pub this: Box<Expression>,
9830    pub kind: String,
9831}
9832
9833/// LockingStatement
9834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9835#[cfg_attr(feature = "bindings", derive(TS))]
9836pub struct LockingStatement {
9837    pub this: Box<Expression>,
9838    pub expression: Box<Expression>,
9839}
9840
9841/// SequenceProperties
9842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9843#[cfg_attr(feature = "bindings", derive(TS))]
9844pub struct SequenceProperties {
9845    #[serde(default)]
9846    pub increment: Option<Box<Expression>>,
9847    #[serde(default)]
9848    pub minvalue: Option<Box<Expression>>,
9849    #[serde(default)]
9850    pub maxvalue: Option<Box<Expression>>,
9851    #[serde(default)]
9852    pub cache: Option<Box<Expression>>,
9853    #[serde(default)]
9854    pub start: Option<Box<Expression>>,
9855    #[serde(default)]
9856    pub owned: Option<Box<Expression>>,
9857    #[serde(default)]
9858    pub options: Vec<Expression>,
9859}
9860
9861/// TruncateTable
9862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9863#[cfg_attr(feature = "bindings", derive(TS))]
9864pub struct TruncateTable {
9865    #[serde(default)]
9866    pub expressions: Vec<Expression>,
9867    #[serde(default)]
9868    pub is_database: Option<Box<Expression>>,
9869    #[serde(default)]
9870    pub exists: bool,
9871    #[serde(default)]
9872    pub only: Option<Box<Expression>>,
9873    #[serde(default)]
9874    pub cluster: Option<Box<Expression>>,
9875    #[serde(default)]
9876    pub identity: Option<Box<Expression>>,
9877    #[serde(default)]
9878    pub option: Option<Box<Expression>>,
9879    #[serde(default)]
9880    pub partition: Option<Box<Expression>>,
9881}
9882
9883/// Clone
9884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9885#[cfg_attr(feature = "bindings", derive(TS))]
9886pub struct Clone {
9887    pub this: Box<Expression>,
9888    #[serde(default)]
9889    pub shallow: Option<Box<Expression>>,
9890    #[serde(default)]
9891    pub copy: Option<Box<Expression>>,
9892}
9893
9894/// Attach
9895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9896#[cfg_attr(feature = "bindings", derive(TS))]
9897pub struct Attach {
9898    pub this: Box<Expression>,
9899    #[serde(default)]
9900    pub exists: bool,
9901    #[serde(default)]
9902    pub expressions: Vec<Expression>,
9903}
9904
9905/// Detach
9906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9907#[cfg_attr(feature = "bindings", derive(TS))]
9908pub struct Detach {
9909    pub this: Box<Expression>,
9910    #[serde(default)]
9911    pub exists: bool,
9912}
9913
9914/// Install
9915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9916#[cfg_attr(feature = "bindings", derive(TS))]
9917pub struct Install {
9918    pub this: Box<Expression>,
9919    #[serde(default)]
9920    pub from_: Option<Box<Expression>>,
9921    #[serde(default)]
9922    pub force: Option<Box<Expression>>,
9923}
9924
9925/// Summarize
9926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9927#[cfg_attr(feature = "bindings", derive(TS))]
9928pub struct Summarize {
9929    pub this: Box<Expression>,
9930    #[serde(default)]
9931    pub table: Option<Box<Expression>>,
9932}
9933
9934/// Declare
9935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9936#[cfg_attr(feature = "bindings", derive(TS))]
9937pub struct Declare {
9938    #[serde(default)]
9939    pub expressions: Vec<Expression>,
9940    #[serde(default)]
9941    pub replace: bool,
9942}
9943
9944/// DeclareItem
9945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9946#[cfg_attr(feature = "bindings", derive(TS))]
9947pub struct DeclareItem {
9948    pub this: Box<Expression>,
9949    #[serde(default)]
9950    pub kind: Option<String>,
9951    #[serde(default)]
9952    pub default: Option<Box<Expression>>,
9953    #[serde(default)]
9954    pub has_as: bool,
9955    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
9956    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9957    pub additional_names: Vec<Expression>,
9958}
9959
9960/// Set
9961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9962#[cfg_attr(feature = "bindings", derive(TS))]
9963pub struct Set {
9964    #[serde(default)]
9965    pub expressions: Vec<Expression>,
9966    #[serde(default)]
9967    pub unset: Option<Box<Expression>>,
9968    #[serde(default)]
9969    pub tag: Option<Box<Expression>>,
9970}
9971
9972/// Heredoc
9973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9974#[cfg_attr(feature = "bindings", derive(TS))]
9975pub struct Heredoc {
9976    pub this: Box<Expression>,
9977    #[serde(default)]
9978    pub tag: Option<Box<Expression>>,
9979}
9980
9981/// QueryBand
9982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9983#[cfg_attr(feature = "bindings", derive(TS))]
9984pub struct QueryBand {
9985    pub this: Box<Expression>,
9986    #[serde(default)]
9987    pub scope: Option<Box<Expression>>,
9988    #[serde(default)]
9989    pub update: Option<Box<Expression>>,
9990}
9991
9992/// UserDefinedFunction
9993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9994#[cfg_attr(feature = "bindings", derive(TS))]
9995pub struct UserDefinedFunction {
9996    pub this: Box<Expression>,
9997    #[serde(default)]
9998    pub expressions: Vec<Expression>,
9999    #[serde(default)]
10000    pub wrapped: Option<Box<Expression>>,
10001}
10002
10003/// RecursiveWithSearch
10004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10005#[cfg_attr(feature = "bindings", derive(TS))]
10006pub struct RecursiveWithSearch {
10007    pub kind: String,
10008    pub this: Box<Expression>,
10009    pub expression: Box<Expression>,
10010    #[serde(default)]
10011    pub using: Option<Box<Expression>>,
10012}
10013
10014/// ProjectionDef
10015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10016#[cfg_attr(feature = "bindings", derive(TS))]
10017pub struct ProjectionDef {
10018    pub this: Box<Expression>,
10019    pub expression: Box<Expression>,
10020}
10021
10022/// TableAlias
10023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10024#[cfg_attr(feature = "bindings", derive(TS))]
10025pub struct TableAlias {
10026    #[serde(default)]
10027    pub this: Option<Box<Expression>>,
10028    #[serde(default)]
10029    pub columns: Vec<Expression>,
10030}
10031
10032/// ByteString
10033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10034#[cfg_attr(feature = "bindings", derive(TS))]
10035pub struct ByteString {
10036    pub this: Box<Expression>,
10037    #[serde(default)]
10038    pub is_bytes: Option<Box<Expression>>,
10039}
10040
10041/// HexStringExpr - Hex string expression (not literal)
10042/// BigQuery: converts to FROM_HEX(this)
10043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10044#[cfg_attr(feature = "bindings", derive(TS))]
10045pub struct HexStringExpr {
10046    pub this: Box<Expression>,
10047    #[serde(default)]
10048    pub is_integer: Option<bool>,
10049}
10050
10051/// UnicodeString
10052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10053#[cfg_attr(feature = "bindings", derive(TS))]
10054pub struct UnicodeString {
10055    pub this: Box<Expression>,
10056    #[serde(default)]
10057    pub escape: Option<Box<Expression>>,
10058}
10059
10060/// AlterColumn
10061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10062#[cfg_attr(feature = "bindings", derive(TS))]
10063pub struct AlterColumn {
10064    pub this: Box<Expression>,
10065    #[serde(default)]
10066    pub dtype: Option<Box<Expression>>,
10067    #[serde(default)]
10068    pub collate: Option<Box<Expression>>,
10069    #[serde(default)]
10070    pub using: Option<Box<Expression>>,
10071    #[serde(default)]
10072    pub default: Option<Box<Expression>>,
10073    #[serde(default)]
10074    pub drop: Option<Box<Expression>>,
10075    #[serde(default)]
10076    pub comment: Option<Box<Expression>>,
10077    #[serde(default)]
10078    pub allow_null: Option<Box<Expression>>,
10079    #[serde(default)]
10080    pub visible: Option<Box<Expression>>,
10081    #[serde(default)]
10082    pub rename_to: Option<Box<Expression>>,
10083}
10084
10085/// AlterSortKey
10086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10087#[cfg_attr(feature = "bindings", derive(TS))]
10088pub struct AlterSortKey {
10089    #[serde(default)]
10090    pub this: Option<Box<Expression>>,
10091    #[serde(default)]
10092    pub expressions: Vec<Expression>,
10093    #[serde(default)]
10094    pub compound: Option<Box<Expression>>,
10095}
10096
10097/// AlterSet
10098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10099#[cfg_attr(feature = "bindings", derive(TS))]
10100pub struct AlterSet {
10101    #[serde(default)]
10102    pub expressions: Vec<Expression>,
10103    #[serde(default)]
10104    pub option: Option<Box<Expression>>,
10105    #[serde(default)]
10106    pub tablespace: Option<Box<Expression>>,
10107    #[serde(default)]
10108    pub access_method: Option<Box<Expression>>,
10109    #[serde(default)]
10110    pub file_format: Option<Box<Expression>>,
10111    #[serde(default)]
10112    pub copy_options: Option<Box<Expression>>,
10113    #[serde(default)]
10114    pub tag: Option<Box<Expression>>,
10115    #[serde(default)]
10116    pub location: Option<Box<Expression>>,
10117    #[serde(default)]
10118    pub serde: Option<Box<Expression>>,
10119}
10120
10121/// RenameColumn
10122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10123#[cfg_attr(feature = "bindings", derive(TS))]
10124pub struct RenameColumn {
10125    pub this: Box<Expression>,
10126    #[serde(default)]
10127    pub to: Option<Box<Expression>>,
10128    #[serde(default)]
10129    pub exists: bool,
10130}
10131
10132/// Comprehension
10133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10134#[cfg_attr(feature = "bindings", derive(TS))]
10135pub struct Comprehension {
10136    pub this: Box<Expression>,
10137    pub expression: Box<Expression>,
10138    #[serde(default)]
10139    pub position: Option<Box<Expression>>,
10140    #[serde(default)]
10141    pub iterator: Option<Box<Expression>>,
10142    #[serde(default)]
10143    pub condition: Option<Box<Expression>>,
10144}
10145
10146/// MergeTreeTTLAction
10147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10148#[cfg_attr(feature = "bindings", derive(TS))]
10149pub struct MergeTreeTTLAction {
10150    pub this: Box<Expression>,
10151    #[serde(default)]
10152    pub delete: Option<Box<Expression>>,
10153    #[serde(default)]
10154    pub recompress: Option<Box<Expression>>,
10155    #[serde(default)]
10156    pub to_disk: Option<Box<Expression>>,
10157    #[serde(default)]
10158    pub to_volume: Option<Box<Expression>>,
10159}
10160
10161/// MergeTreeTTL
10162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10163#[cfg_attr(feature = "bindings", derive(TS))]
10164pub struct MergeTreeTTL {
10165    #[serde(default)]
10166    pub expressions: Vec<Expression>,
10167    #[serde(default)]
10168    pub where_: Option<Box<Expression>>,
10169    #[serde(default)]
10170    pub group: Option<Box<Expression>>,
10171    #[serde(default)]
10172    pub aggregates: Option<Box<Expression>>,
10173}
10174
10175/// IndexConstraintOption
10176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10177#[cfg_attr(feature = "bindings", derive(TS))]
10178pub struct IndexConstraintOption {
10179    #[serde(default)]
10180    pub key_block_size: Option<Box<Expression>>,
10181    #[serde(default)]
10182    pub using: Option<Box<Expression>>,
10183    #[serde(default)]
10184    pub parser: Option<Box<Expression>>,
10185    #[serde(default)]
10186    pub comment: Option<Box<Expression>>,
10187    #[serde(default)]
10188    pub visible: Option<Box<Expression>>,
10189    #[serde(default)]
10190    pub engine_attr: Option<Box<Expression>>,
10191    #[serde(default)]
10192    pub secondary_engine_attr: Option<Box<Expression>>,
10193}
10194
10195/// PeriodForSystemTimeConstraint
10196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10197#[cfg_attr(feature = "bindings", derive(TS))]
10198pub struct PeriodForSystemTimeConstraint {
10199    pub this: Box<Expression>,
10200    pub expression: Box<Expression>,
10201}
10202
10203/// CaseSpecificColumnConstraint
10204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10205#[cfg_attr(feature = "bindings", derive(TS))]
10206pub struct CaseSpecificColumnConstraint {
10207    #[serde(default)]
10208    pub not_: Option<Box<Expression>>,
10209}
10210
10211/// CharacterSetColumnConstraint
10212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10213#[cfg_attr(feature = "bindings", derive(TS))]
10214pub struct CharacterSetColumnConstraint {
10215    pub this: Box<Expression>,
10216}
10217
10218/// CheckColumnConstraint
10219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10220#[cfg_attr(feature = "bindings", derive(TS))]
10221pub struct CheckColumnConstraint {
10222    pub this: Box<Expression>,
10223    #[serde(default)]
10224    pub enforced: Option<Box<Expression>>,
10225}
10226
10227/// AssumeColumnConstraint (ClickHouse ASSUME constraint)
10228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10229#[cfg_attr(feature = "bindings", derive(TS))]
10230pub struct AssumeColumnConstraint {
10231    pub this: Box<Expression>,
10232}
10233
10234/// CompressColumnConstraint
10235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10236#[cfg_attr(feature = "bindings", derive(TS))]
10237pub struct CompressColumnConstraint {
10238    #[serde(default)]
10239    pub this: Option<Box<Expression>>,
10240}
10241
10242/// DateFormatColumnConstraint
10243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10244#[cfg_attr(feature = "bindings", derive(TS))]
10245pub struct DateFormatColumnConstraint {
10246    pub this: Box<Expression>,
10247}
10248
10249/// EphemeralColumnConstraint
10250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10251#[cfg_attr(feature = "bindings", derive(TS))]
10252pub struct EphemeralColumnConstraint {
10253    #[serde(default)]
10254    pub this: Option<Box<Expression>>,
10255}
10256
10257/// WithOperator
10258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10259#[cfg_attr(feature = "bindings", derive(TS))]
10260pub struct WithOperator {
10261    pub this: Box<Expression>,
10262    pub op: String,
10263}
10264
10265/// GeneratedAsIdentityColumnConstraint
10266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10267#[cfg_attr(feature = "bindings", derive(TS))]
10268pub struct GeneratedAsIdentityColumnConstraint {
10269    #[serde(default)]
10270    pub this: Option<Box<Expression>>,
10271    #[serde(default)]
10272    pub expression: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub on_null: Option<Box<Expression>>,
10275    #[serde(default)]
10276    pub start: Option<Box<Expression>>,
10277    #[serde(default)]
10278    pub increment: Option<Box<Expression>>,
10279    #[serde(default)]
10280    pub minvalue: Option<Box<Expression>>,
10281    #[serde(default)]
10282    pub maxvalue: Option<Box<Expression>>,
10283    #[serde(default)]
10284    pub cycle: Option<Box<Expression>>,
10285    #[serde(default)]
10286    pub order: Option<Box<Expression>>,
10287}
10288
10289/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
10290/// TSQL: outputs "IDENTITY"
10291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10292#[cfg_attr(feature = "bindings", derive(TS))]
10293pub struct AutoIncrementColumnConstraint;
10294
10295/// CommentColumnConstraint - Column comment marker
10296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10297#[cfg_attr(feature = "bindings", derive(TS))]
10298pub struct CommentColumnConstraint;
10299
10300/// GeneratedAsRowColumnConstraint
10301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10302#[cfg_attr(feature = "bindings", derive(TS))]
10303pub struct GeneratedAsRowColumnConstraint {
10304    #[serde(default)]
10305    pub start: Option<Box<Expression>>,
10306    #[serde(default)]
10307    pub hidden: Option<Box<Expression>>,
10308}
10309
10310/// IndexColumnConstraint
10311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10312#[cfg_attr(feature = "bindings", derive(TS))]
10313pub struct IndexColumnConstraint {
10314    #[serde(default)]
10315    pub this: Option<Box<Expression>>,
10316    #[serde(default)]
10317    pub expressions: Vec<Expression>,
10318    #[serde(default)]
10319    pub kind: Option<String>,
10320    #[serde(default)]
10321    pub index_type: Option<Box<Expression>>,
10322    #[serde(default)]
10323    pub options: Vec<Expression>,
10324    #[serde(default)]
10325    pub expression: Option<Box<Expression>>,
10326    #[serde(default)]
10327    pub granularity: Option<Box<Expression>>,
10328}
10329
10330/// MaskingPolicyColumnConstraint
10331#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10332#[cfg_attr(feature = "bindings", derive(TS))]
10333pub struct MaskingPolicyColumnConstraint {
10334    pub this: Box<Expression>,
10335    #[serde(default)]
10336    pub expressions: Vec<Expression>,
10337}
10338
10339/// NotNullColumnConstraint
10340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10341#[cfg_attr(feature = "bindings", derive(TS))]
10342pub struct NotNullColumnConstraint {
10343    #[serde(default)]
10344    pub allow_null: Option<Box<Expression>>,
10345}
10346
10347/// DefaultColumnConstraint - DEFAULT value for a column
10348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10349#[cfg_attr(feature = "bindings", derive(TS))]
10350pub struct DefaultColumnConstraint {
10351    pub this: Box<Expression>,
10352    /// TSQL: DEFAULT value FOR column (table-level default constraint)
10353    #[serde(default, skip_serializing_if = "Option::is_none")]
10354    pub for_column: Option<Identifier>,
10355}
10356
10357/// PrimaryKeyColumnConstraint
10358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10359#[cfg_attr(feature = "bindings", derive(TS))]
10360pub struct PrimaryKeyColumnConstraint {
10361    #[serde(default)]
10362    pub desc: Option<Box<Expression>>,
10363    #[serde(default)]
10364    pub options: Vec<Expression>,
10365}
10366
10367/// UniqueColumnConstraint
10368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10369#[cfg_attr(feature = "bindings", derive(TS))]
10370pub struct UniqueColumnConstraint {
10371    #[serde(default)]
10372    pub this: Option<Box<Expression>>,
10373    #[serde(default)]
10374    pub index_type: Option<Box<Expression>>,
10375    #[serde(default)]
10376    pub on_conflict: Option<Box<Expression>>,
10377    #[serde(default)]
10378    pub nulls: Option<Box<Expression>>,
10379    #[serde(default)]
10380    pub options: Vec<Expression>,
10381}
10382
10383/// WatermarkColumnConstraint
10384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10385#[cfg_attr(feature = "bindings", derive(TS))]
10386pub struct WatermarkColumnConstraint {
10387    pub this: Box<Expression>,
10388    pub expression: Box<Expression>,
10389}
10390
10391/// ComputedColumnConstraint
10392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10393#[cfg_attr(feature = "bindings", derive(TS))]
10394pub struct ComputedColumnConstraint {
10395    pub this: Box<Expression>,
10396    #[serde(default)]
10397    pub persisted: Option<Box<Expression>>,
10398    #[serde(default)]
10399    pub not_null: Option<Box<Expression>>,
10400    #[serde(default)]
10401    pub data_type: Option<Box<Expression>>,
10402}
10403
10404/// InOutColumnConstraint
10405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10406#[cfg_attr(feature = "bindings", derive(TS))]
10407pub struct InOutColumnConstraint {
10408    #[serde(default)]
10409    pub input_: Option<Box<Expression>>,
10410    #[serde(default)]
10411    pub output: Option<Box<Expression>>,
10412}
10413
10414/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
10415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10416#[cfg_attr(feature = "bindings", derive(TS))]
10417pub struct PathColumnConstraint {
10418    pub this: Box<Expression>,
10419}
10420
10421/// Constraint
10422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10423#[cfg_attr(feature = "bindings", derive(TS))]
10424pub struct Constraint {
10425    pub this: Box<Expression>,
10426    #[serde(default)]
10427    pub expressions: Vec<Expression>,
10428}
10429
10430/// Export
10431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10432#[cfg_attr(feature = "bindings", derive(TS))]
10433pub struct Export {
10434    pub this: Box<Expression>,
10435    #[serde(default)]
10436    pub connection: Option<Box<Expression>>,
10437    #[serde(default)]
10438    pub options: Vec<Expression>,
10439}
10440
10441/// Filter
10442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10443#[cfg_attr(feature = "bindings", derive(TS))]
10444pub struct Filter {
10445    pub this: Box<Expression>,
10446    pub expression: Box<Expression>,
10447}
10448
10449/// Changes
10450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10451#[cfg_attr(feature = "bindings", derive(TS))]
10452pub struct Changes {
10453    #[serde(default)]
10454    pub information: Option<Box<Expression>>,
10455    #[serde(default)]
10456    pub at_before: Option<Box<Expression>>,
10457    #[serde(default)]
10458    pub end: Option<Box<Expression>>,
10459}
10460
10461/// Directory
10462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10463#[cfg_attr(feature = "bindings", derive(TS))]
10464pub struct Directory {
10465    pub this: Box<Expression>,
10466    #[serde(default)]
10467    pub local: Option<Box<Expression>>,
10468    #[serde(default)]
10469    pub row_format: Option<Box<Expression>>,
10470}
10471
10472/// ForeignKey
10473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10474#[cfg_attr(feature = "bindings", derive(TS))]
10475pub struct ForeignKey {
10476    #[serde(default)]
10477    pub expressions: Vec<Expression>,
10478    #[serde(default)]
10479    pub reference: Option<Box<Expression>>,
10480    #[serde(default)]
10481    pub delete: Option<Box<Expression>>,
10482    #[serde(default)]
10483    pub update: Option<Box<Expression>>,
10484    #[serde(default)]
10485    pub options: Vec<Expression>,
10486}
10487
10488/// ColumnPrefix
10489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10490#[cfg_attr(feature = "bindings", derive(TS))]
10491pub struct ColumnPrefix {
10492    pub this: Box<Expression>,
10493    pub expression: Box<Expression>,
10494}
10495
10496/// PrimaryKey
10497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10498#[cfg_attr(feature = "bindings", derive(TS))]
10499pub struct PrimaryKey {
10500    #[serde(default)]
10501    pub this: Option<Box<Expression>>,
10502    #[serde(default)]
10503    pub expressions: Vec<Expression>,
10504    #[serde(default)]
10505    pub options: Vec<Expression>,
10506    #[serde(default)]
10507    pub include: Option<Box<Expression>>,
10508}
10509
10510/// Into
10511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10512#[cfg_attr(feature = "bindings", derive(TS))]
10513pub struct IntoClause {
10514    #[serde(default)]
10515    pub this: Option<Box<Expression>>,
10516    #[serde(default)]
10517    pub temporary: bool,
10518    #[serde(default)]
10519    pub unlogged: Option<Box<Expression>>,
10520    #[serde(default)]
10521    pub bulk_collect: Option<Box<Expression>>,
10522    #[serde(default)]
10523    pub expressions: Vec<Expression>,
10524}
10525
10526/// JoinHint
10527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10528#[cfg_attr(feature = "bindings", derive(TS))]
10529pub struct JoinHint {
10530    pub this: Box<Expression>,
10531    #[serde(default)]
10532    pub expressions: Vec<Expression>,
10533}
10534
10535/// Opclass
10536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10537#[cfg_attr(feature = "bindings", derive(TS))]
10538pub struct Opclass {
10539    pub this: Box<Expression>,
10540    pub expression: Box<Expression>,
10541}
10542
10543/// Index
10544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10545#[cfg_attr(feature = "bindings", derive(TS))]
10546pub struct Index {
10547    #[serde(default)]
10548    pub this: Option<Box<Expression>>,
10549    #[serde(default)]
10550    pub table: Option<Box<Expression>>,
10551    #[serde(default)]
10552    pub unique: bool,
10553    #[serde(default)]
10554    pub primary: Option<Box<Expression>>,
10555    #[serde(default)]
10556    pub amp: Option<Box<Expression>>,
10557    #[serde(default)]
10558    pub params: Vec<Expression>,
10559}
10560
10561/// IndexParameters
10562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10563#[cfg_attr(feature = "bindings", derive(TS))]
10564pub struct IndexParameters {
10565    #[serde(default)]
10566    pub using: Option<Box<Expression>>,
10567    #[serde(default)]
10568    pub include: Option<Box<Expression>>,
10569    #[serde(default)]
10570    pub columns: Vec<Expression>,
10571    #[serde(default)]
10572    pub with_storage: Option<Box<Expression>>,
10573    #[serde(default)]
10574    pub partition_by: Option<Box<Expression>>,
10575    #[serde(default)]
10576    pub tablespace: Option<Box<Expression>>,
10577    #[serde(default)]
10578    pub where_: Option<Box<Expression>>,
10579    #[serde(default)]
10580    pub on: Option<Box<Expression>>,
10581}
10582
10583/// ConditionalInsert
10584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10585#[cfg_attr(feature = "bindings", derive(TS))]
10586pub struct ConditionalInsert {
10587    pub this: Box<Expression>,
10588    #[serde(default)]
10589    pub expression: Option<Box<Expression>>,
10590    #[serde(default)]
10591    pub else_: Option<Box<Expression>>,
10592}
10593
10594/// MultitableInserts
10595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10596#[cfg_attr(feature = "bindings", derive(TS))]
10597pub struct MultitableInserts {
10598    #[serde(default)]
10599    pub expressions: Vec<Expression>,
10600    pub kind: String,
10601    #[serde(default)]
10602    pub source: Option<Box<Expression>>,
10603    /// Leading comments before the statement
10604    #[serde(default)]
10605    pub leading_comments: Vec<String>,
10606}
10607
10608/// OnConflict
10609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10610#[cfg_attr(feature = "bindings", derive(TS))]
10611pub struct OnConflict {
10612    #[serde(default)]
10613    pub duplicate: Option<Box<Expression>>,
10614    #[serde(default)]
10615    pub expressions: Vec<Expression>,
10616    #[serde(default)]
10617    pub action: Option<Box<Expression>>,
10618    #[serde(default)]
10619    pub conflict_keys: Option<Box<Expression>>,
10620    #[serde(default)]
10621    pub index_predicate: Option<Box<Expression>>,
10622    #[serde(default)]
10623    pub constraint: Option<Box<Expression>>,
10624    #[serde(default)]
10625    pub where_: Option<Box<Expression>>,
10626}
10627
10628/// OnCondition
10629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10630#[cfg_attr(feature = "bindings", derive(TS))]
10631pub struct OnCondition {
10632    #[serde(default)]
10633    pub error: Option<Box<Expression>>,
10634    #[serde(default)]
10635    pub empty: Option<Box<Expression>>,
10636    #[serde(default)]
10637    pub null: Option<Box<Expression>>,
10638}
10639
10640/// Returning
10641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10642#[cfg_attr(feature = "bindings", derive(TS))]
10643pub struct Returning {
10644    #[serde(default)]
10645    pub expressions: Vec<Expression>,
10646    #[serde(default)]
10647    pub into: Option<Box<Expression>>,
10648}
10649
10650/// Introducer
10651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10652#[cfg_attr(feature = "bindings", derive(TS))]
10653pub struct Introducer {
10654    pub this: Box<Expression>,
10655    pub expression: Box<Expression>,
10656}
10657
10658/// PartitionRange
10659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10660#[cfg_attr(feature = "bindings", derive(TS))]
10661pub struct PartitionRange {
10662    pub this: Box<Expression>,
10663    #[serde(default)]
10664    pub expression: Option<Box<Expression>>,
10665    #[serde(default)]
10666    pub expressions: Vec<Expression>,
10667}
10668
10669/// Group
10670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10671#[cfg_attr(feature = "bindings", derive(TS))]
10672pub struct Group {
10673    #[serde(default)]
10674    pub expressions: Vec<Expression>,
10675    #[serde(default)]
10676    pub grouping_sets: Option<Box<Expression>>,
10677    #[serde(default)]
10678    pub cube: Option<Box<Expression>>,
10679    #[serde(default)]
10680    pub rollup: Option<Box<Expression>>,
10681    #[serde(default)]
10682    pub totals: Option<Box<Expression>>,
10683    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
10684    #[serde(default)]
10685    pub all: Option<bool>,
10686}
10687
10688/// Cube
10689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10690#[cfg_attr(feature = "bindings", derive(TS))]
10691pub struct Cube {
10692    #[serde(default)]
10693    pub expressions: Vec<Expression>,
10694}
10695
10696/// Rollup
10697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10698#[cfg_attr(feature = "bindings", derive(TS))]
10699pub struct Rollup {
10700    #[serde(default)]
10701    pub expressions: Vec<Expression>,
10702}
10703
10704/// GroupingSets
10705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10706#[cfg_attr(feature = "bindings", derive(TS))]
10707pub struct GroupingSets {
10708    #[serde(default)]
10709    pub expressions: Vec<Expression>,
10710}
10711
10712/// LimitOptions
10713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10714#[cfg_attr(feature = "bindings", derive(TS))]
10715pub struct LimitOptions {
10716    #[serde(default)]
10717    pub percent: Option<Box<Expression>>,
10718    #[serde(default)]
10719    pub rows: Option<Box<Expression>>,
10720    #[serde(default)]
10721    pub with_ties: Option<Box<Expression>>,
10722}
10723
10724/// Lateral
10725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10726#[cfg_attr(feature = "bindings", derive(TS))]
10727pub struct Lateral {
10728    pub this: Box<Expression>,
10729    #[serde(default)]
10730    pub view: Option<Box<Expression>>,
10731    #[serde(default)]
10732    pub outer: Option<Box<Expression>>,
10733    #[serde(default)]
10734    pub alias: Option<String>,
10735    /// Whether the alias was originally quoted (backtick/double-quote)
10736    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
10737    pub alias_quoted: bool,
10738    #[serde(default)]
10739    pub cross_apply: Option<Box<Expression>>,
10740    #[serde(default)]
10741    pub ordinality: Option<Box<Expression>>,
10742    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
10743    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10744    pub column_aliases: Vec<String>,
10745}
10746
10747/// TableFromRows
10748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10749#[cfg_attr(feature = "bindings", derive(TS))]
10750pub struct TableFromRows {
10751    pub this: Box<Expression>,
10752    #[serde(default)]
10753    pub alias: Option<String>,
10754    #[serde(default)]
10755    pub joins: Vec<Expression>,
10756    #[serde(default)]
10757    pub pivots: Option<Box<Expression>>,
10758    #[serde(default)]
10759    pub sample: Option<Box<Expression>>,
10760}
10761
10762/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
10763/// Used for set-returning functions with typed column definitions
10764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10765#[cfg_attr(feature = "bindings", derive(TS))]
10766pub struct RowsFrom {
10767    /// List of function expressions, each potentially with an alias and typed columns
10768    pub expressions: Vec<Expression>,
10769    /// WITH ORDINALITY modifier
10770    #[serde(default)]
10771    pub ordinality: bool,
10772    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
10773    #[serde(default)]
10774    pub alias: Option<Box<Expression>>,
10775}
10776
10777/// WithFill
10778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10779#[cfg_attr(feature = "bindings", derive(TS))]
10780pub struct WithFill {
10781    #[serde(default)]
10782    pub from_: Option<Box<Expression>>,
10783    #[serde(default)]
10784    pub to: Option<Box<Expression>>,
10785    #[serde(default)]
10786    pub step: Option<Box<Expression>>,
10787    #[serde(default)]
10788    pub staleness: Option<Box<Expression>>,
10789    #[serde(default)]
10790    pub interpolate: Option<Box<Expression>>,
10791}
10792
10793/// Property
10794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10795#[cfg_attr(feature = "bindings", derive(TS))]
10796pub struct Property {
10797    pub this: Box<Expression>,
10798    #[serde(default)]
10799    pub value: Option<Box<Expression>>,
10800}
10801
10802/// GrantPrivilege
10803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10804#[cfg_attr(feature = "bindings", derive(TS))]
10805pub struct GrantPrivilege {
10806    pub this: Box<Expression>,
10807    #[serde(default)]
10808    pub expressions: Vec<Expression>,
10809}
10810
10811/// AllowedValuesProperty
10812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10813#[cfg_attr(feature = "bindings", derive(TS))]
10814pub struct AllowedValuesProperty {
10815    #[serde(default)]
10816    pub expressions: Vec<Expression>,
10817}
10818
10819/// AlgorithmProperty
10820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10821#[cfg_attr(feature = "bindings", derive(TS))]
10822pub struct AlgorithmProperty {
10823    pub this: Box<Expression>,
10824}
10825
10826/// AutoIncrementProperty
10827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10828#[cfg_attr(feature = "bindings", derive(TS))]
10829pub struct AutoIncrementProperty {
10830    pub this: Box<Expression>,
10831}
10832
10833/// AutoRefreshProperty
10834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10835#[cfg_attr(feature = "bindings", derive(TS))]
10836pub struct AutoRefreshProperty {
10837    pub this: Box<Expression>,
10838}
10839
10840/// BackupProperty
10841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10842#[cfg_attr(feature = "bindings", derive(TS))]
10843pub struct BackupProperty {
10844    pub this: Box<Expression>,
10845}
10846
10847/// BuildProperty
10848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10849#[cfg_attr(feature = "bindings", derive(TS))]
10850pub struct BuildProperty {
10851    pub this: Box<Expression>,
10852}
10853
10854/// BlockCompressionProperty
10855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10856#[cfg_attr(feature = "bindings", derive(TS))]
10857pub struct BlockCompressionProperty {
10858    #[serde(default)]
10859    pub autotemp: Option<Box<Expression>>,
10860    #[serde(default)]
10861    pub always: Option<Box<Expression>>,
10862    #[serde(default)]
10863    pub default: Option<Box<Expression>>,
10864    #[serde(default)]
10865    pub manual: Option<Box<Expression>>,
10866    #[serde(default)]
10867    pub never: Option<Box<Expression>>,
10868}
10869
10870/// CharacterSetProperty
10871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10872#[cfg_attr(feature = "bindings", derive(TS))]
10873pub struct CharacterSetProperty {
10874    pub this: Box<Expression>,
10875    #[serde(default)]
10876    pub default: Option<Box<Expression>>,
10877}
10878
10879/// ChecksumProperty
10880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10881#[cfg_attr(feature = "bindings", derive(TS))]
10882pub struct ChecksumProperty {
10883    #[serde(default)]
10884    pub on: Option<Box<Expression>>,
10885    #[serde(default)]
10886    pub default: Option<Box<Expression>>,
10887}
10888
10889/// CollateProperty
10890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10891#[cfg_attr(feature = "bindings", derive(TS))]
10892pub struct CollateProperty {
10893    pub this: Box<Expression>,
10894    #[serde(default)]
10895    pub default: Option<Box<Expression>>,
10896}
10897
10898/// DataBlocksizeProperty
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct DataBlocksizeProperty {
10902    #[serde(default)]
10903    pub size: Option<i64>,
10904    #[serde(default)]
10905    pub units: Option<Box<Expression>>,
10906    #[serde(default)]
10907    pub minimum: Option<Box<Expression>>,
10908    #[serde(default)]
10909    pub maximum: Option<Box<Expression>>,
10910    #[serde(default)]
10911    pub default: Option<Box<Expression>>,
10912}
10913
10914/// DataDeletionProperty
10915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10916#[cfg_attr(feature = "bindings", derive(TS))]
10917pub struct DataDeletionProperty {
10918    pub on: Box<Expression>,
10919    #[serde(default)]
10920    pub filter_column: Option<Box<Expression>>,
10921    #[serde(default)]
10922    pub retention_period: Option<Box<Expression>>,
10923}
10924
10925/// DefinerProperty
10926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10927#[cfg_attr(feature = "bindings", derive(TS))]
10928pub struct DefinerProperty {
10929    pub this: Box<Expression>,
10930}
10931
10932/// DistKeyProperty
10933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10934#[cfg_attr(feature = "bindings", derive(TS))]
10935pub struct DistKeyProperty {
10936    pub this: Box<Expression>,
10937}
10938
10939/// DistributedByProperty
10940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10941#[cfg_attr(feature = "bindings", derive(TS))]
10942pub struct DistributedByProperty {
10943    #[serde(default)]
10944    pub expressions: Vec<Expression>,
10945    pub kind: String,
10946    #[serde(default)]
10947    pub buckets: Option<Box<Expression>>,
10948    #[serde(default)]
10949    pub order: Option<Box<Expression>>,
10950}
10951
10952/// DistStyleProperty
10953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10954#[cfg_attr(feature = "bindings", derive(TS))]
10955pub struct DistStyleProperty {
10956    pub this: Box<Expression>,
10957}
10958
10959/// DuplicateKeyProperty
10960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10961#[cfg_attr(feature = "bindings", derive(TS))]
10962pub struct DuplicateKeyProperty {
10963    #[serde(default)]
10964    pub expressions: Vec<Expression>,
10965}
10966
10967/// EngineProperty
10968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10969#[cfg_attr(feature = "bindings", derive(TS))]
10970pub struct EngineProperty {
10971    pub this: Box<Expression>,
10972}
10973
10974/// ToTableProperty
10975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10976#[cfg_attr(feature = "bindings", derive(TS))]
10977pub struct ToTableProperty {
10978    pub this: Box<Expression>,
10979}
10980
10981/// ExecuteAsProperty
10982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10983#[cfg_attr(feature = "bindings", derive(TS))]
10984pub struct ExecuteAsProperty {
10985    pub this: Box<Expression>,
10986}
10987
10988/// ExternalProperty
10989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10990#[cfg_attr(feature = "bindings", derive(TS))]
10991pub struct ExternalProperty {
10992    #[serde(default)]
10993    pub this: Option<Box<Expression>>,
10994}
10995
10996/// FallbackProperty
10997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10998#[cfg_attr(feature = "bindings", derive(TS))]
10999pub struct FallbackProperty {
11000    #[serde(default)]
11001    pub no: Option<Box<Expression>>,
11002    #[serde(default)]
11003    pub protection: Option<Box<Expression>>,
11004}
11005
11006/// FileFormatProperty
11007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11008#[cfg_attr(feature = "bindings", derive(TS))]
11009pub struct FileFormatProperty {
11010    #[serde(default)]
11011    pub this: Option<Box<Expression>>,
11012    #[serde(default)]
11013    pub expressions: Vec<Expression>,
11014    #[serde(default)]
11015    pub hive_format: Option<Box<Expression>>,
11016}
11017
11018/// CredentialsProperty
11019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11020#[cfg_attr(feature = "bindings", derive(TS))]
11021pub struct CredentialsProperty {
11022    #[serde(default)]
11023    pub expressions: Vec<Expression>,
11024}
11025
11026/// FreespaceProperty
11027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11028#[cfg_attr(feature = "bindings", derive(TS))]
11029pub struct FreespaceProperty {
11030    pub this: Box<Expression>,
11031    #[serde(default)]
11032    pub percent: Option<Box<Expression>>,
11033}
11034
11035/// InheritsProperty
11036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11037#[cfg_attr(feature = "bindings", derive(TS))]
11038pub struct InheritsProperty {
11039    #[serde(default)]
11040    pub expressions: Vec<Expression>,
11041}
11042
11043/// InputModelProperty
11044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11045#[cfg_attr(feature = "bindings", derive(TS))]
11046pub struct InputModelProperty {
11047    pub this: Box<Expression>,
11048}
11049
11050/// OutputModelProperty
11051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11052#[cfg_attr(feature = "bindings", derive(TS))]
11053pub struct OutputModelProperty {
11054    pub this: Box<Expression>,
11055}
11056
11057/// IsolatedLoadingProperty
11058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11059#[cfg_attr(feature = "bindings", derive(TS))]
11060pub struct IsolatedLoadingProperty {
11061    #[serde(default)]
11062    pub no: Option<Box<Expression>>,
11063    #[serde(default)]
11064    pub concurrent: Option<Box<Expression>>,
11065    #[serde(default)]
11066    pub target: Option<Box<Expression>>,
11067}
11068
11069/// JournalProperty
11070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11071#[cfg_attr(feature = "bindings", derive(TS))]
11072pub struct JournalProperty {
11073    #[serde(default)]
11074    pub no: Option<Box<Expression>>,
11075    #[serde(default)]
11076    pub dual: Option<Box<Expression>>,
11077    #[serde(default)]
11078    pub before: Option<Box<Expression>>,
11079    #[serde(default)]
11080    pub local: Option<Box<Expression>>,
11081    #[serde(default)]
11082    pub after: Option<Box<Expression>>,
11083}
11084
11085/// LanguageProperty
11086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11087#[cfg_attr(feature = "bindings", derive(TS))]
11088pub struct LanguageProperty {
11089    pub this: Box<Expression>,
11090}
11091
11092/// EnviromentProperty
11093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11094#[cfg_attr(feature = "bindings", derive(TS))]
11095pub struct EnviromentProperty {
11096    #[serde(default)]
11097    pub expressions: Vec<Expression>,
11098}
11099
11100/// ClusteredByProperty
11101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11102#[cfg_attr(feature = "bindings", derive(TS))]
11103pub struct ClusteredByProperty {
11104    #[serde(default)]
11105    pub expressions: Vec<Expression>,
11106    #[serde(default)]
11107    pub sorted_by: Option<Box<Expression>>,
11108    #[serde(default)]
11109    pub buckets: Option<Box<Expression>>,
11110}
11111
11112/// DictProperty
11113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11114#[cfg_attr(feature = "bindings", derive(TS))]
11115pub struct DictProperty {
11116    pub this: Box<Expression>,
11117    pub kind: String,
11118    #[serde(default)]
11119    pub settings: Option<Box<Expression>>,
11120}
11121
11122/// DictRange
11123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11124#[cfg_attr(feature = "bindings", derive(TS))]
11125pub struct DictRange {
11126    pub this: Box<Expression>,
11127    #[serde(default)]
11128    pub min: Option<Box<Expression>>,
11129    #[serde(default)]
11130    pub max: Option<Box<Expression>>,
11131}
11132
11133/// OnCluster
11134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11135#[cfg_attr(feature = "bindings", derive(TS))]
11136pub struct OnCluster {
11137    pub this: Box<Expression>,
11138}
11139
11140/// LikeProperty
11141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11142#[cfg_attr(feature = "bindings", derive(TS))]
11143pub struct LikeProperty {
11144    pub this: Box<Expression>,
11145    #[serde(default)]
11146    pub expressions: Vec<Expression>,
11147}
11148
11149/// LocationProperty
11150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11151#[cfg_attr(feature = "bindings", derive(TS))]
11152pub struct LocationProperty {
11153    pub this: Box<Expression>,
11154}
11155
11156/// LockProperty
11157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11158#[cfg_attr(feature = "bindings", derive(TS))]
11159pub struct LockProperty {
11160    pub this: Box<Expression>,
11161}
11162
11163/// LockingProperty
11164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11165#[cfg_attr(feature = "bindings", derive(TS))]
11166pub struct LockingProperty {
11167    #[serde(default)]
11168    pub this: Option<Box<Expression>>,
11169    pub kind: String,
11170    #[serde(default)]
11171    pub for_or_in: Option<Box<Expression>>,
11172    #[serde(default)]
11173    pub lock_type: Option<Box<Expression>>,
11174    #[serde(default)]
11175    pub override_: Option<Box<Expression>>,
11176}
11177
11178/// LogProperty
11179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11180#[cfg_attr(feature = "bindings", derive(TS))]
11181pub struct LogProperty {
11182    #[serde(default)]
11183    pub no: Option<Box<Expression>>,
11184}
11185
11186/// MaterializedProperty
11187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11188#[cfg_attr(feature = "bindings", derive(TS))]
11189pub struct MaterializedProperty {
11190    #[serde(default)]
11191    pub this: Option<Box<Expression>>,
11192}
11193
11194/// MergeBlockRatioProperty
11195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11196#[cfg_attr(feature = "bindings", derive(TS))]
11197pub struct MergeBlockRatioProperty {
11198    #[serde(default)]
11199    pub this: Option<Box<Expression>>,
11200    #[serde(default)]
11201    pub no: Option<Box<Expression>>,
11202    #[serde(default)]
11203    pub default: Option<Box<Expression>>,
11204    #[serde(default)]
11205    pub percent: Option<Box<Expression>>,
11206}
11207
11208/// OnProperty
11209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11210#[cfg_attr(feature = "bindings", derive(TS))]
11211pub struct OnProperty {
11212    pub this: Box<Expression>,
11213}
11214
11215/// OnCommitProperty
11216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11217#[cfg_attr(feature = "bindings", derive(TS))]
11218pub struct OnCommitProperty {
11219    #[serde(default)]
11220    pub delete: Option<Box<Expression>>,
11221}
11222
11223/// PartitionedByProperty
11224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11225#[cfg_attr(feature = "bindings", derive(TS))]
11226pub struct PartitionedByProperty {
11227    pub this: Box<Expression>,
11228}
11229
11230/// BigQuery PARTITION BY property in CREATE TABLE statements.
11231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11232#[cfg_attr(feature = "bindings", derive(TS))]
11233pub struct PartitionByProperty {
11234    #[serde(default)]
11235    pub expressions: Vec<Expression>,
11236}
11237
11238/// PartitionedByBucket
11239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11240#[cfg_attr(feature = "bindings", derive(TS))]
11241pub struct PartitionedByBucket {
11242    pub this: Box<Expression>,
11243    pub expression: Box<Expression>,
11244}
11245
11246/// BigQuery CLUSTER BY property in CREATE TABLE statements.
11247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11248#[cfg_attr(feature = "bindings", derive(TS))]
11249pub struct ClusterByColumnsProperty {
11250    #[serde(default)]
11251    pub columns: Vec<Identifier>,
11252}
11253
11254/// PartitionByTruncate
11255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11256#[cfg_attr(feature = "bindings", derive(TS))]
11257pub struct PartitionByTruncate {
11258    pub this: Box<Expression>,
11259    pub expression: Box<Expression>,
11260}
11261
11262/// PartitionByRangeProperty
11263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11264#[cfg_attr(feature = "bindings", derive(TS))]
11265pub struct PartitionByRangeProperty {
11266    #[serde(default)]
11267    pub partition_expressions: Option<Box<Expression>>,
11268    #[serde(default)]
11269    pub create_expressions: Option<Box<Expression>>,
11270}
11271
11272/// PartitionByRangePropertyDynamic
11273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11274#[cfg_attr(feature = "bindings", derive(TS))]
11275pub struct PartitionByRangePropertyDynamic {
11276    #[serde(default)]
11277    pub this: Option<Box<Expression>>,
11278    #[serde(default)]
11279    pub start: Option<Box<Expression>>,
11280    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
11281    #[serde(default)]
11282    pub use_start_end: bool,
11283    #[serde(default)]
11284    pub end: Option<Box<Expression>>,
11285    #[serde(default)]
11286    pub every: Option<Box<Expression>>,
11287}
11288
11289/// PartitionByListProperty
11290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11291#[cfg_attr(feature = "bindings", derive(TS))]
11292pub struct PartitionByListProperty {
11293    #[serde(default)]
11294    pub partition_expressions: Option<Box<Expression>>,
11295    #[serde(default)]
11296    pub create_expressions: Option<Box<Expression>>,
11297}
11298
11299/// PartitionList
11300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11301#[cfg_attr(feature = "bindings", derive(TS))]
11302pub struct PartitionList {
11303    pub this: Box<Expression>,
11304    #[serde(default)]
11305    pub expressions: Vec<Expression>,
11306}
11307
11308/// Partition - represents PARTITION/SUBPARTITION clause
11309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11310#[cfg_attr(feature = "bindings", derive(TS))]
11311pub struct Partition {
11312    pub expressions: Vec<Expression>,
11313    #[serde(default)]
11314    pub subpartition: bool,
11315}
11316
11317/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
11318/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
11319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11320#[cfg_attr(feature = "bindings", derive(TS))]
11321pub struct RefreshTriggerProperty {
11322    /// Method: COMPLETE or AUTO
11323    pub method: String,
11324    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
11325    #[serde(default)]
11326    pub kind: Option<String>,
11327    /// For SCHEDULE: EVERY n (the number)
11328    #[serde(default)]
11329    pub every: Option<Box<Expression>>,
11330    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
11331    #[serde(default)]
11332    pub unit: Option<String>,
11333    /// For SCHEDULE: STARTS 'datetime'
11334    #[serde(default)]
11335    pub starts: Option<Box<Expression>>,
11336}
11337
11338/// UniqueKeyProperty
11339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11340#[cfg_attr(feature = "bindings", derive(TS))]
11341pub struct UniqueKeyProperty {
11342    #[serde(default)]
11343    pub expressions: Vec<Expression>,
11344}
11345
11346/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
11347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11348#[cfg_attr(feature = "bindings", derive(TS))]
11349pub struct RollupProperty {
11350    pub expressions: Vec<RollupIndex>,
11351}
11352
11353/// RollupIndex - A single rollup index: name(col1, col2)
11354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11355#[cfg_attr(feature = "bindings", derive(TS))]
11356pub struct RollupIndex {
11357    pub name: Identifier,
11358    pub expressions: Vec<Identifier>,
11359}
11360
11361/// PartitionBoundSpec
11362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11363#[cfg_attr(feature = "bindings", derive(TS))]
11364pub struct PartitionBoundSpec {
11365    #[serde(default)]
11366    pub this: Option<Box<Expression>>,
11367    #[serde(default)]
11368    pub expression: Option<Box<Expression>>,
11369    #[serde(default)]
11370    pub from_expressions: Option<Box<Expression>>,
11371    #[serde(default)]
11372    pub to_expressions: Option<Box<Expression>>,
11373}
11374
11375/// PartitionedOfProperty
11376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11377#[cfg_attr(feature = "bindings", derive(TS))]
11378pub struct PartitionedOfProperty {
11379    pub this: Box<Expression>,
11380    pub expression: Box<Expression>,
11381}
11382
11383/// RemoteWithConnectionModelProperty
11384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11385#[cfg_attr(feature = "bindings", derive(TS))]
11386pub struct RemoteWithConnectionModelProperty {
11387    pub this: Box<Expression>,
11388}
11389
11390/// ReturnsProperty
11391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11392#[cfg_attr(feature = "bindings", derive(TS))]
11393pub struct ReturnsProperty {
11394    #[serde(default)]
11395    pub this: Option<Box<Expression>>,
11396    #[serde(default)]
11397    pub is_table: Option<Box<Expression>>,
11398    #[serde(default)]
11399    pub table: Option<Box<Expression>>,
11400    #[serde(default)]
11401    pub null: Option<Box<Expression>>,
11402}
11403
11404/// RowFormatProperty
11405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11406#[cfg_attr(feature = "bindings", derive(TS))]
11407pub struct RowFormatProperty {
11408    pub this: Box<Expression>,
11409}
11410
11411/// RowFormatDelimitedProperty
11412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11413#[cfg_attr(feature = "bindings", derive(TS))]
11414pub struct RowFormatDelimitedProperty {
11415    #[serde(default)]
11416    pub fields: Option<Box<Expression>>,
11417    #[serde(default)]
11418    pub escaped: Option<Box<Expression>>,
11419    #[serde(default)]
11420    pub collection_items: Option<Box<Expression>>,
11421    #[serde(default)]
11422    pub map_keys: Option<Box<Expression>>,
11423    #[serde(default)]
11424    pub lines: Option<Box<Expression>>,
11425    #[serde(default)]
11426    pub null: Option<Box<Expression>>,
11427    #[serde(default)]
11428    pub serde: Option<Box<Expression>>,
11429}
11430
11431/// RowFormatSerdeProperty
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct RowFormatSerdeProperty {
11435    pub this: Box<Expression>,
11436    #[serde(default)]
11437    pub serde_properties: Option<Box<Expression>>,
11438}
11439
11440/// QueryTransform
11441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11442#[cfg_attr(feature = "bindings", derive(TS))]
11443pub struct QueryTransform {
11444    #[serde(default)]
11445    pub expressions: Vec<Expression>,
11446    #[serde(default)]
11447    pub command_script: Option<Box<Expression>>,
11448    #[serde(default)]
11449    pub schema: Option<Box<Expression>>,
11450    #[serde(default)]
11451    pub row_format_before: Option<Box<Expression>>,
11452    #[serde(default)]
11453    pub record_writer: Option<Box<Expression>>,
11454    #[serde(default)]
11455    pub row_format_after: Option<Box<Expression>>,
11456    #[serde(default)]
11457    pub record_reader: Option<Box<Expression>>,
11458}
11459
11460/// SampleProperty
11461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11462#[cfg_attr(feature = "bindings", derive(TS))]
11463pub struct SampleProperty {
11464    pub this: Box<Expression>,
11465}
11466
11467/// SecurityProperty
11468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11469#[cfg_attr(feature = "bindings", derive(TS))]
11470pub struct SecurityProperty {
11471    pub this: Box<Expression>,
11472}
11473
11474/// SchemaCommentProperty
11475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11476#[cfg_attr(feature = "bindings", derive(TS))]
11477pub struct SchemaCommentProperty {
11478    pub this: Box<Expression>,
11479}
11480
11481/// SemanticView
11482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11483#[cfg_attr(feature = "bindings", derive(TS))]
11484pub struct SemanticView {
11485    pub this: Box<Expression>,
11486    #[serde(default)]
11487    pub metrics: Option<Box<Expression>>,
11488    #[serde(default)]
11489    pub dimensions: Option<Box<Expression>>,
11490    #[serde(default)]
11491    pub facts: Option<Box<Expression>>,
11492    #[serde(default)]
11493    pub where_: Option<Box<Expression>>,
11494}
11495
11496/// SerdeProperties
11497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11498#[cfg_attr(feature = "bindings", derive(TS))]
11499pub struct SerdeProperties {
11500    #[serde(default)]
11501    pub expressions: Vec<Expression>,
11502    #[serde(default)]
11503    pub with_: Option<Box<Expression>>,
11504}
11505
11506/// SetProperty
11507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11508#[cfg_attr(feature = "bindings", derive(TS))]
11509pub struct SetProperty {
11510    #[serde(default)]
11511    pub multi: Option<Box<Expression>>,
11512}
11513
11514/// SharingProperty
11515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11516#[cfg_attr(feature = "bindings", derive(TS))]
11517pub struct SharingProperty {
11518    #[serde(default)]
11519    pub this: Option<Box<Expression>>,
11520}
11521
11522/// SetConfigProperty
11523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11524#[cfg_attr(feature = "bindings", derive(TS))]
11525pub struct SetConfigProperty {
11526    pub this: Box<Expression>,
11527}
11528
11529/// SettingsProperty
11530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11531#[cfg_attr(feature = "bindings", derive(TS))]
11532pub struct SettingsProperty {
11533    #[serde(default)]
11534    pub expressions: Vec<Expression>,
11535}
11536
11537/// SortKeyProperty
11538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11539#[cfg_attr(feature = "bindings", derive(TS))]
11540pub struct SortKeyProperty {
11541    pub this: Box<Expression>,
11542    #[serde(default)]
11543    pub compound: Option<Box<Expression>>,
11544}
11545
11546/// SqlReadWriteProperty
11547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11548#[cfg_attr(feature = "bindings", derive(TS))]
11549pub struct SqlReadWriteProperty {
11550    pub this: Box<Expression>,
11551}
11552
11553/// SqlSecurityProperty
11554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11555#[cfg_attr(feature = "bindings", derive(TS))]
11556pub struct SqlSecurityProperty {
11557    pub this: Box<Expression>,
11558}
11559
11560/// StabilityProperty
11561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11562#[cfg_attr(feature = "bindings", derive(TS))]
11563pub struct StabilityProperty {
11564    pub this: Box<Expression>,
11565}
11566
11567/// StorageHandlerProperty
11568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11569#[cfg_attr(feature = "bindings", derive(TS))]
11570pub struct StorageHandlerProperty {
11571    pub this: Box<Expression>,
11572}
11573
11574/// TemporaryProperty
11575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11576#[cfg_attr(feature = "bindings", derive(TS))]
11577pub struct TemporaryProperty {
11578    #[serde(default)]
11579    pub this: Option<Box<Expression>>,
11580}
11581
11582/// Tags
11583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11584#[cfg_attr(feature = "bindings", derive(TS))]
11585pub struct Tags {
11586    #[serde(default)]
11587    pub expressions: Vec<Expression>,
11588}
11589
11590/// TransformModelProperty
11591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11592#[cfg_attr(feature = "bindings", derive(TS))]
11593pub struct TransformModelProperty {
11594    #[serde(default)]
11595    pub expressions: Vec<Expression>,
11596}
11597
11598/// TransientProperty
11599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11600#[cfg_attr(feature = "bindings", derive(TS))]
11601pub struct TransientProperty {
11602    #[serde(default)]
11603    pub this: Option<Box<Expression>>,
11604}
11605
11606/// UsingTemplateProperty
11607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11608#[cfg_attr(feature = "bindings", derive(TS))]
11609pub struct UsingTemplateProperty {
11610    pub this: Box<Expression>,
11611}
11612
11613/// ViewAttributeProperty
11614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11615#[cfg_attr(feature = "bindings", derive(TS))]
11616pub struct ViewAttributeProperty {
11617    pub this: Box<Expression>,
11618}
11619
11620/// VolatileProperty
11621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11622#[cfg_attr(feature = "bindings", derive(TS))]
11623pub struct VolatileProperty {
11624    #[serde(default)]
11625    pub this: Option<Box<Expression>>,
11626}
11627
11628/// WithDataProperty
11629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11630#[cfg_attr(feature = "bindings", derive(TS))]
11631pub struct WithDataProperty {
11632    #[serde(default)]
11633    pub no: Option<Box<Expression>>,
11634    #[serde(default)]
11635    pub statistics: Option<Box<Expression>>,
11636}
11637
11638/// WithJournalTableProperty
11639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11640#[cfg_attr(feature = "bindings", derive(TS))]
11641pub struct WithJournalTableProperty {
11642    pub this: Box<Expression>,
11643}
11644
11645/// WithSchemaBindingProperty
11646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11647#[cfg_attr(feature = "bindings", derive(TS))]
11648pub struct WithSchemaBindingProperty {
11649    pub this: Box<Expression>,
11650}
11651
11652/// WithSystemVersioningProperty
11653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11654#[cfg_attr(feature = "bindings", derive(TS))]
11655pub struct WithSystemVersioningProperty {
11656    #[serde(default)]
11657    pub on: Option<Box<Expression>>,
11658    #[serde(default)]
11659    pub this: Option<Box<Expression>>,
11660    #[serde(default)]
11661    pub data_consistency: Option<Box<Expression>>,
11662    #[serde(default)]
11663    pub retention_period: Option<Box<Expression>>,
11664    #[serde(default)]
11665    pub with_: Option<Box<Expression>>,
11666}
11667
11668/// WithProcedureOptions
11669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11670#[cfg_attr(feature = "bindings", derive(TS))]
11671pub struct WithProcedureOptions {
11672    #[serde(default)]
11673    pub expressions: Vec<Expression>,
11674}
11675
11676/// EncodeProperty
11677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11678#[cfg_attr(feature = "bindings", derive(TS))]
11679pub struct EncodeProperty {
11680    pub this: Box<Expression>,
11681    #[serde(default)]
11682    pub properties: Vec<Expression>,
11683    #[serde(default)]
11684    pub key: Option<Box<Expression>>,
11685}
11686
11687/// IncludeProperty
11688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11689#[cfg_attr(feature = "bindings", derive(TS))]
11690pub struct IncludeProperty {
11691    pub this: Box<Expression>,
11692    #[serde(default)]
11693    pub alias: Option<String>,
11694    #[serde(default)]
11695    pub column_def: Option<Box<Expression>>,
11696}
11697
11698/// Properties
11699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11700#[cfg_attr(feature = "bindings", derive(TS))]
11701pub struct Properties {
11702    #[serde(default)]
11703    pub expressions: Vec<Expression>,
11704}
11705
11706/// Key/value pair in a BigQuery OPTIONS (...) clause.
11707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11708#[cfg_attr(feature = "bindings", derive(TS))]
11709pub struct OptionEntry {
11710    pub key: Identifier,
11711    pub value: Expression,
11712}
11713
11714/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
11715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11716#[cfg_attr(feature = "bindings", derive(TS))]
11717pub struct OptionsProperty {
11718    #[serde(default)]
11719    pub entries: Vec<OptionEntry>,
11720}
11721
11722/// InputOutputFormat
11723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11724#[cfg_attr(feature = "bindings", derive(TS))]
11725pub struct InputOutputFormat {
11726    #[serde(default)]
11727    pub input_format: Option<Box<Expression>>,
11728    #[serde(default)]
11729    pub output_format: Option<Box<Expression>>,
11730}
11731
11732/// Reference
11733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11734#[cfg_attr(feature = "bindings", derive(TS))]
11735pub struct Reference {
11736    pub this: Box<Expression>,
11737    #[serde(default)]
11738    pub expressions: Vec<Expression>,
11739    #[serde(default)]
11740    pub options: Vec<Expression>,
11741}
11742
11743/// QueryOption
11744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11745#[cfg_attr(feature = "bindings", derive(TS))]
11746pub struct QueryOption {
11747    pub this: Box<Expression>,
11748    #[serde(default)]
11749    pub expression: Option<Box<Expression>>,
11750}
11751
11752/// WithTableHint
11753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11754#[cfg_attr(feature = "bindings", derive(TS))]
11755pub struct WithTableHint {
11756    #[serde(default)]
11757    pub expressions: Vec<Expression>,
11758}
11759
11760/// IndexTableHint
11761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11762#[cfg_attr(feature = "bindings", derive(TS))]
11763pub struct IndexTableHint {
11764    pub this: Box<Expression>,
11765    #[serde(default)]
11766    pub expressions: Vec<Expression>,
11767    #[serde(default)]
11768    pub target: Option<Box<Expression>>,
11769}
11770
11771/// Get
11772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11773#[cfg_attr(feature = "bindings", derive(TS))]
11774pub struct Get {
11775    pub this: Box<Expression>,
11776    #[serde(default)]
11777    pub target: Option<Box<Expression>>,
11778    #[serde(default)]
11779    pub properties: Vec<Expression>,
11780}
11781
11782/// SetOperation
11783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11784#[cfg_attr(feature = "bindings", derive(TS))]
11785pub struct SetOperation {
11786    #[serde(default)]
11787    pub with_: Option<Box<Expression>>,
11788    pub this: Box<Expression>,
11789    pub expression: Box<Expression>,
11790    #[serde(default)]
11791    pub distinct: bool,
11792    #[serde(default)]
11793    pub by_name: Option<Box<Expression>>,
11794    #[serde(default)]
11795    pub side: Option<Box<Expression>>,
11796    #[serde(default)]
11797    pub kind: Option<String>,
11798    #[serde(default)]
11799    pub on: Option<Box<Expression>>,
11800}
11801
11802/// Var - Simple variable reference (for SQL variables, keywords as values)
11803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11804#[cfg_attr(feature = "bindings", derive(TS))]
11805pub struct Var {
11806    pub this: String,
11807}
11808
11809/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
11810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11811#[cfg_attr(feature = "bindings", derive(TS))]
11812pub struct Variadic {
11813    pub this: Box<Expression>,
11814}
11815
11816/// Version
11817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11818#[cfg_attr(feature = "bindings", derive(TS))]
11819pub struct Version {
11820    pub this: Box<Expression>,
11821    pub kind: String,
11822    #[serde(default)]
11823    pub expression: Option<Box<Expression>>,
11824}
11825
11826/// Schema
11827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11828#[cfg_attr(feature = "bindings", derive(TS))]
11829pub struct Schema {
11830    #[serde(default)]
11831    pub this: Option<Box<Expression>>,
11832    #[serde(default)]
11833    pub expressions: Vec<Expression>,
11834}
11835
11836/// Lock
11837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11838#[cfg_attr(feature = "bindings", derive(TS))]
11839pub struct Lock {
11840    #[serde(default)]
11841    pub update: Option<Box<Expression>>,
11842    #[serde(default)]
11843    pub expressions: Vec<Expression>,
11844    #[serde(default)]
11845    pub wait: Option<Box<Expression>>,
11846    #[serde(default)]
11847    pub key: Option<Box<Expression>>,
11848}
11849
11850/// TableSample - wraps an expression with a TABLESAMPLE clause
11851/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
11852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11853#[cfg_attr(feature = "bindings", derive(TS))]
11854pub struct TableSample {
11855    /// The expression being sampled (subquery, function, etc.)
11856    #[serde(default, skip_serializing_if = "Option::is_none")]
11857    pub this: Option<Box<Expression>>,
11858    /// The sample specification
11859    #[serde(default, skip_serializing_if = "Option::is_none")]
11860    pub sample: Option<Box<Sample>>,
11861    #[serde(default)]
11862    pub expressions: Vec<Expression>,
11863    #[serde(default)]
11864    pub method: Option<String>,
11865    #[serde(default)]
11866    pub bucket_numerator: Option<Box<Expression>>,
11867    #[serde(default)]
11868    pub bucket_denominator: Option<Box<Expression>>,
11869    #[serde(default)]
11870    pub bucket_field: Option<Box<Expression>>,
11871    #[serde(default)]
11872    pub percent: Option<Box<Expression>>,
11873    #[serde(default)]
11874    pub rows: Option<Box<Expression>>,
11875    #[serde(default)]
11876    pub size: Option<i64>,
11877    #[serde(default)]
11878    pub seed: Option<Box<Expression>>,
11879}
11880
11881/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
11882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11883#[cfg_attr(feature = "bindings", derive(TS))]
11884pub struct Tag {
11885    #[serde(default)]
11886    pub this: Option<Box<Expression>>,
11887    #[serde(default)]
11888    pub prefix: Option<Box<Expression>>,
11889    #[serde(default)]
11890    pub postfix: Option<Box<Expression>>,
11891}
11892
11893/// UnpivotColumns
11894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11895#[cfg_attr(feature = "bindings", derive(TS))]
11896pub struct UnpivotColumns {
11897    pub this: Box<Expression>,
11898    #[serde(default)]
11899    pub expressions: Vec<Expression>,
11900}
11901
11902/// SessionParameter
11903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11904#[cfg_attr(feature = "bindings", derive(TS))]
11905pub struct SessionParameter {
11906    pub this: Box<Expression>,
11907    #[serde(default)]
11908    pub kind: Option<String>,
11909}
11910
11911/// PseudoType
11912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11913#[cfg_attr(feature = "bindings", derive(TS))]
11914pub struct PseudoType {
11915    pub this: Box<Expression>,
11916}
11917
11918/// ObjectIdentifier
11919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11920#[cfg_attr(feature = "bindings", derive(TS))]
11921pub struct ObjectIdentifier {
11922    pub this: Box<Expression>,
11923}
11924
11925/// Transaction
11926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11927#[cfg_attr(feature = "bindings", derive(TS))]
11928pub struct Transaction {
11929    #[serde(default)]
11930    pub this: Option<Box<Expression>>,
11931    #[serde(default)]
11932    pub modes: Option<Box<Expression>>,
11933    #[serde(default)]
11934    pub mark: Option<Box<Expression>>,
11935}
11936
11937/// Commit
11938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11939#[cfg_attr(feature = "bindings", derive(TS))]
11940pub struct Commit {
11941    #[serde(default)]
11942    pub chain: Option<Box<Expression>>,
11943    #[serde(default)]
11944    pub this: Option<Box<Expression>>,
11945    #[serde(default)]
11946    pub durability: Option<Box<Expression>>,
11947}
11948
11949/// Rollback
11950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11951#[cfg_attr(feature = "bindings", derive(TS))]
11952pub struct Rollback {
11953    #[serde(default)]
11954    pub savepoint: Option<Box<Expression>>,
11955    #[serde(default)]
11956    pub this: Option<Box<Expression>>,
11957}
11958
11959/// AlterSession
11960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11961#[cfg_attr(feature = "bindings", derive(TS))]
11962pub struct AlterSession {
11963    #[serde(default)]
11964    pub expressions: Vec<Expression>,
11965    #[serde(default)]
11966    pub unset: Option<Box<Expression>>,
11967}
11968
11969/// Analyze
11970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11971#[cfg_attr(feature = "bindings", derive(TS))]
11972pub struct Analyze {
11973    #[serde(default)]
11974    pub kind: Option<String>,
11975    #[serde(default)]
11976    pub this: Option<Box<Expression>>,
11977    #[serde(default)]
11978    pub options: Vec<Expression>,
11979    #[serde(default)]
11980    pub mode: Option<Box<Expression>>,
11981    #[serde(default)]
11982    pub partition: Option<Box<Expression>>,
11983    #[serde(default)]
11984    pub expression: Option<Box<Expression>>,
11985    #[serde(default)]
11986    pub properties: Vec<Expression>,
11987    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
11988    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11989    pub columns: Vec<String>,
11990}
11991
11992/// AnalyzeStatistics
11993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11994#[cfg_attr(feature = "bindings", derive(TS))]
11995pub struct AnalyzeStatistics {
11996    pub kind: String,
11997    #[serde(default)]
11998    pub option: Option<Box<Expression>>,
11999    #[serde(default)]
12000    pub this: Option<Box<Expression>>,
12001    #[serde(default)]
12002    pub expressions: Vec<Expression>,
12003}
12004
12005/// AnalyzeHistogram
12006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12007#[cfg_attr(feature = "bindings", derive(TS))]
12008pub struct AnalyzeHistogram {
12009    pub this: Box<Expression>,
12010    #[serde(default)]
12011    pub expressions: Vec<Expression>,
12012    #[serde(default)]
12013    pub expression: Option<Box<Expression>>,
12014    #[serde(default)]
12015    pub update_options: Option<Box<Expression>>,
12016}
12017
12018/// AnalyzeSample
12019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12020#[cfg_attr(feature = "bindings", derive(TS))]
12021pub struct AnalyzeSample {
12022    pub kind: String,
12023    #[serde(default)]
12024    pub sample: Option<Box<Expression>>,
12025}
12026
12027/// AnalyzeListChainedRows
12028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12029#[cfg_attr(feature = "bindings", derive(TS))]
12030pub struct AnalyzeListChainedRows {
12031    #[serde(default)]
12032    pub expression: Option<Box<Expression>>,
12033}
12034
12035/// AnalyzeDelete
12036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12037#[cfg_attr(feature = "bindings", derive(TS))]
12038pub struct AnalyzeDelete {
12039    #[serde(default)]
12040    pub kind: Option<String>,
12041}
12042
12043/// AnalyzeWith
12044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12045#[cfg_attr(feature = "bindings", derive(TS))]
12046pub struct AnalyzeWith {
12047    #[serde(default)]
12048    pub expressions: Vec<Expression>,
12049}
12050
12051/// AnalyzeValidate
12052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12053#[cfg_attr(feature = "bindings", derive(TS))]
12054pub struct AnalyzeValidate {
12055    pub kind: String,
12056    #[serde(default)]
12057    pub this: Option<Box<Expression>>,
12058    #[serde(default)]
12059    pub expression: Option<Box<Expression>>,
12060}
12061
12062/// AddPartition
12063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12064#[cfg_attr(feature = "bindings", derive(TS))]
12065pub struct AddPartition {
12066    pub this: Box<Expression>,
12067    #[serde(default)]
12068    pub exists: bool,
12069    #[serde(default)]
12070    pub location: Option<Box<Expression>>,
12071}
12072
12073/// AttachOption
12074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12075#[cfg_attr(feature = "bindings", derive(TS))]
12076pub struct AttachOption {
12077    pub this: Box<Expression>,
12078    #[serde(default)]
12079    pub expression: Option<Box<Expression>>,
12080}
12081
12082/// DropPartition
12083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12084#[cfg_attr(feature = "bindings", derive(TS))]
12085pub struct DropPartition {
12086    #[serde(default)]
12087    pub expressions: Vec<Expression>,
12088    #[serde(default)]
12089    pub exists: bool,
12090}
12091
12092/// ReplacePartition
12093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12094#[cfg_attr(feature = "bindings", derive(TS))]
12095pub struct ReplacePartition {
12096    pub expression: Box<Expression>,
12097    #[serde(default)]
12098    pub source: Option<Box<Expression>>,
12099}
12100
12101/// DPipe
12102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12103#[cfg_attr(feature = "bindings", derive(TS))]
12104pub struct DPipe {
12105    pub this: Box<Expression>,
12106    pub expression: Box<Expression>,
12107    #[serde(default)]
12108    pub safe: Option<Box<Expression>>,
12109}
12110
12111/// Operator
12112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12113#[cfg_attr(feature = "bindings", derive(TS))]
12114pub struct Operator {
12115    pub this: Box<Expression>,
12116    #[serde(default)]
12117    pub operator: Option<Box<Expression>>,
12118    pub expression: Box<Expression>,
12119    /// Comments between OPERATOR() and the RHS expression
12120    #[serde(default, skip_serializing_if = "Vec::is_empty")]
12121    pub comments: Vec<String>,
12122}
12123
12124/// PivotAny
12125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12126#[cfg_attr(feature = "bindings", derive(TS))]
12127pub struct PivotAny {
12128    #[serde(default)]
12129    pub this: Option<Box<Expression>>,
12130}
12131
12132/// Aliases
12133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12134#[cfg_attr(feature = "bindings", derive(TS))]
12135pub struct Aliases {
12136    pub this: Box<Expression>,
12137    #[serde(default)]
12138    pub expressions: Vec<Expression>,
12139}
12140
12141/// AtIndex
12142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12143#[cfg_attr(feature = "bindings", derive(TS))]
12144pub struct AtIndex {
12145    pub this: Box<Expression>,
12146    pub expression: Box<Expression>,
12147}
12148
12149/// FromTimeZone
12150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12151#[cfg_attr(feature = "bindings", derive(TS))]
12152pub struct FromTimeZone {
12153    pub this: Box<Expression>,
12154    #[serde(default)]
12155    pub zone: Option<Box<Expression>>,
12156}
12157
12158/// Format override for a column in Teradata
12159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12160#[cfg_attr(feature = "bindings", derive(TS))]
12161pub struct FormatPhrase {
12162    pub this: Box<Expression>,
12163    pub format: String,
12164}
12165
12166/// ForIn
12167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12168#[cfg_attr(feature = "bindings", derive(TS))]
12169pub struct ForIn {
12170    pub this: Box<Expression>,
12171    pub expression: Box<Expression>,
12172}
12173
12174/// Automatically converts unit arg into a var.
12175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12176#[cfg_attr(feature = "bindings", derive(TS))]
12177pub struct TimeUnit {
12178    #[serde(default)]
12179    pub unit: Option<String>,
12180}
12181
12182/// IntervalOp
12183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12184#[cfg_attr(feature = "bindings", derive(TS))]
12185pub struct IntervalOp {
12186    #[serde(default)]
12187    pub unit: Option<String>,
12188    pub expression: Box<Expression>,
12189}
12190
12191/// HavingMax
12192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12193#[cfg_attr(feature = "bindings", derive(TS))]
12194pub struct HavingMax {
12195    pub this: Box<Expression>,
12196    pub expression: Box<Expression>,
12197    #[serde(default)]
12198    pub max: Option<Box<Expression>>,
12199}
12200
12201/// CosineDistance
12202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12203#[cfg_attr(feature = "bindings", derive(TS))]
12204pub struct CosineDistance {
12205    pub this: Box<Expression>,
12206    pub expression: Box<Expression>,
12207}
12208
12209/// DotProduct
12210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12211#[cfg_attr(feature = "bindings", derive(TS))]
12212pub struct DotProduct {
12213    pub this: Box<Expression>,
12214    pub expression: Box<Expression>,
12215}
12216
12217/// EuclideanDistance
12218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12219#[cfg_attr(feature = "bindings", derive(TS))]
12220pub struct EuclideanDistance {
12221    pub this: Box<Expression>,
12222    pub expression: Box<Expression>,
12223}
12224
12225/// ManhattanDistance
12226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12227#[cfg_attr(feature = "bindings", derive(TS))]
12228pub struct ManhattanDistance {
12229    pub this: Box<Expression>,
12230    pub expression: Box<Expression>,
12231}
12232
12233/// JarowinklerSimilarity
12234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12235#[cfg_attr(feature = "bindings", derive(TS))]
12236pub struct JarowinklerSimilarity {
12237    pub this: Box<Expression>,
12238    pub expression: Box<Expression>,
12239}
12240
12241/// Booland
12242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12243#[cfg_attr(feature = "bindings", derive(TS))]
12244pub struct Booland {
12245    pub this: Box<Expression>,
12246    pub expression: Box<Expression>,
12247}
12248
12249/// Boolor
12250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12251#[cfg_attr(feature = "bindings", derive(TS))]
12252pub struct Boolor {
12253    pub this: Box<Expression>,
12254    pub expression: Box<Expression>,
12255}
12256
12257/// ParameterizedAgg
12258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12259#[cfg_attr(feature = "bindings", derive(TS))]
12260pub struct ParameterizedAgg {
12261    pub this: Box<Expression>,
12262    #[serde(default)]
12263    pub expressions: Vec<Expression>,
12264    #[serde(default)]
12265    pub params: Vec<Expression>,
12266}
12267
12268/// ArgMax
12269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12270#[cfg_attr(feature = "bindings", derive(TS))]
12271pub struct ArgMax {
12272    pub this: Box<Expression>,
12273    pub expression: Box<Expression>,
12274    #[serde(default)]
12275    pub count: Option<Box<Expression>>,
12276}
12277
12278/// ArgMin
12279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12280#[cfg_attr(feature = "bindings", derive(TS))]
12281pub struct ArgMin {
12282    pub this: Box<Expression>,
12283    pub expression: Box<Expression>,
12284    #[serde(default)]
12285    pub count: Option<Box<Expression>>,
12286}
12287
12288/// ApproxTopK
12289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12290#[cfg_attr(feature = "bindings", derive(TS))]
12291pub struct ApproxTopK {
12292    pub this: Box<Expression>,
12293    #[serde(default)]
12294    pub expression: Option<Box<Expression>>,
12295    #[serde(default)]
12296    pub counters: Option<Box<Expression>>,
12297}
12298
12299/// ApproxTopKAccumulate
12300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12301#[cfg_attr(feature = "bindings", derive(TS))]
12302pub struct ApproxTopKAccumulate {
12303    pub this: Box<Expression>,
12304    #[serde(default)]
12305    pub expression: Option<Box<Expression>>,
12306}
12307
12308/// ApproxTopKCombine
12309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12310#[cfg_attr(feature = "bindings", derive(TS))]
12311pub struct ApproxTopKCombine {
12312    pub this: Box<Expression>,
12313    #[serde(default)]
12314    pub expression: Option<Box<Expression>>,
12315}
12316
12317/// ApproxTopKEstimate
12318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12319#[cfg_attr(feature = "bindings", derive(TS))]
12320pub struct ApproxTopKEstimate {
12321    pub this: Box<Expression>,
12322    #[serde(default)]
12323    pub expression: Option<Box<Expression>>,
12324}
12325
12326/// ApproxTopSum
12327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12328#[cfg_attr(feature = "bindings", derive(TS))]
12329pub struct ApproxTopSum {
12330    pub this: Box<Expression>,
12331    pub expression: Box<Expression>,
12332    #[serde(default)]
12333    pub count: Option<Box<Expression>>,
12334}
12335
12336/// ApproxQuantiles
12337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12338#[cfg_attr(feature = "bindings", derive(TS))]
12339pub struct ApproxQuantiles {
12340    pub this: Box<Expression>,
12341    #[serde(default)]
12342    pub expression: Option<Box<Expression>>,
12343}
12344
12345/// Minhash
12346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12347#[cfg_attr(feature = "bindings", derive(TS))]
12348pub struct Minhash {
12349    pub this: Box<Expression>,
12350    #[serde(default)]
12351    pub expressions: Vec<Expression>,
12352}
12353
12354/// FarmFingerprint
12355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12356#[cfg_attr(feature = "bindings", derive(TS))]
12357pub struct FarmFingerprint {
12358    #[serde(default)]
12359    pub expressions: Vec<Expression>,
12360}
12361
12362/// Float64
12363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12364#[cfg_attr(feature = "bindings", derive(TS))]
12365pub struct Float64 {
12366    pub this: Box<Expression>,
12367    #[serde(default)]
12368    pub expression: Option<Box<Expression>>,
12369}
12370
12371/// Transform
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct Transform {
12375    pub this: Box<Expression>,
12376    pub expression: Box<Expression>,
12377}
12378
12379/// Translate
12380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12381#[cfg_attr(feature = "bindings", derive(TS))]
12382pub struct Translate {
12383    pub this: Box<Expression>,
12384    #[serde(default)]
12385    pub from_: Option<Box<Expression>>,
12386    #[serde(default)]
12387    pub to: Option<Box<Expression>>,
12388}
12389
12390/// Grouping
12391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12392#[cfg_attr(feature = "bindings", derive(TS))]
12393pub struct Grouping {
12394    #[serde(default)]
12395    pub expressions: Vec<Expression>,
12396}
12397
12398/// GroupingId
12399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12400#[cfg_attr(feature = "bindings", derive(TS))]
12401pub struct GroupingId {
12402    #[serde(default)]
12403    pub expressions: Vec<Expression>,
12404}
12405
12406/// Anonymous
12407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12408#[cfg_attr(feature = "bindings", derive(TS))]
12409pub struct Anonymous {
12410    pub this: Box<Expression>,
12411    #[serde(default)]
12412    pub expressions: Vec<Expression>,
12413}
12414
12415/// AnonymousAggFunc
12416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12417#[cfg_attr(feature = "bindings", derive(TS))]
12418pub struct AnonymousAggFunc {
12419    pub this: Box<Expression>,
12420    #[serde(default)]
12421    pub expressions: Vec<Expression>,
12422}
12423
12424/// CombinedAggFunc
12425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12426#[cfg_attr(feature = "bindings", derive(TS))]
12427pub struct CombinedAggFunc {
12428    pub this: Box<Expression>,
12429    #[serde(default)]
12430    pub expressions: Vec<Expression>,
12431}
12432
12433/// CombinedParameterizedAgg
12434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12435#[cfg_attr(feature = "bindings", derive(TS))]
12436pub struct CombinedParameterizedAgg {
12437    pub this: Box<Expression>,
12438    #[serde(default)]
12439    pub expressions: Vec<Expression>,
12440    #[serde(default)]
12441    pub params: Vec<Expression>,
12442}
12443
12444/// HashAgg
12445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12446#[cfg_attr(feature = "bindings", derive(TS))]
12447pub struct HashAgg {
12448    pub this: Box<Expression>,
12449    #[serde(default)]
12450    pub expressions: Vec<Expression>,
12451}
12452
12453/// Hll
12454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12455#[cfg_attr(feature = "bindings", derive(TS))]
12456pub struct Hll {
12457    pub this: Box<Expression>,
12458    #[serde(default)]
12459    pub expressions: Vec<Expression>,
12460}
12461
12462/// Apply
12463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12464#[cfg_attr(feature = "bindings", derive(TS))]
12465pub struct Apply {
12466    pub this: Box<Expression>,
12467    pub expression: Box<Expression>,
12468}
12469
12470/// ToBoolean
12471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12472#[cfg_attr(feature = "bindings", derive(TS))]
12473pub struct ToBoolean {
12474    pub this: Box<Expression>,
12475    #[serde(default)]
12476    pub safe: Option<Box<Expression>>,
12477}
12478
12479/// List
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct List {
12483    #[serde(default)]
12484    pub expressions: Vec<Expression>,
12485}
12486
12487/// ToMap - Materialize-style map constructor
12488/// Can hold either:
12489/// - A SELECT subquery (MAP(SELECT 'a', 1))
12490/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
12491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12492#[cfg_attr(feature = "bindings", derive(TS))]
12493pub struct ToMap {
12494    /// Either a Select subquery or a Struct containing PropertyEQ entries
12495    pub this: Box<Expression>,
12496}
12497
12498/// Pad
12499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12500#[cfg_attr(feature = "bindings", derive(TS))]
12501pub struct Pad {
12502    pub this: Box<Expression>,
12503    pub expression: Box<Expression>,
12504    #[serde(default)]
12505    pub fill_pattern: Option<Box<Expression>>,
12506    #[serde(default)]
12507    pub is_left: Option<Box<Expression>>,
12508}
12509
12510/// ToChar
12511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12512#[cfg_attr(feature = "bindings", derive(TS))]
12513pub struct ToChar {
12514    pub this: Box<Expression>,
12515    #[serde(default)]
12516    pub format: Option<String>,
12517    #[serde(default)]
12518    pub nlsparam: Option<Box<Expression>>,
12519    #[serde(default)]
12520    pub is_numeric: Option<Box<Expression>>,
12521}
12522
12523/// StringFunc - String type conversion function (BigQuery STRING)
12524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12525#[cfg_attr(feature = "bindings", derive(TS))]
12526pub struct StringFunc {
12527    pub this: Box<Expression>,
12528    #[serde(default)]
12529    pub zone: Option<Box<Expression>>,
12530}
12531
12532/// ToNumber
12533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12534#[cfg_attr(feature = "bindings", derive(TS))]
12535pub struct ToNumber {
12536    pub this: Box<Expression>,
12537    #[serde(default)]
12538    pub format: Option<Box<Expression>>,
12539    #[serde(default)]
12540    pub nlsparam: Option<Box<Expression>>,
12541    #[serde(default)]
12542    pub precision: Option<Box<Expression>>,
12543    #[serde(default)]
12544    pub scale: Option<Box<Expression>>,
12545    #[serde(default)]
12546    pub safe: Option<Box<Expression>>,
12547    #[serde(default)]
12548    pub safe_name: Option<Box<Expression>>,
12549}
12550
12551/// ToDouble
12552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12553#[cfg_attr(feature = "bindings", derive(TS))]
12554pub struct ToDouble {
12555    pub this: Box<Expression>,
12556    #[serde(default)]
12557    pub format: Option<String>,
12558    #[serde(default)]
12559    pub safe: Option<Box<Expression>>,
12560}
12561
12562/// ToDecfloat
12563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12564#[cfg_attr(feature = "bindings", derive(TS))]
12565pub struct ToDecfloat {
12566    pub this: Box<Expression>,
12567    #[serde(default)]
12568    pub format: Option<String>,
12569}
12570
12571/// TryToDecfloat
12572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12573#[cfg_attr(feature = "bindings", derive(TS))]
12574pub struct TryToDecfloat {
12575    pub this: Box<Expression>,
12576    #[serde(default)]
12577    pub format: Option<String>,
12578}
12579
12580/// ToFile
12581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12582#[cfg_attr(feature = "bindings", derive(TS))]
12583pub struct ToFile {
12584    pub this: Box<Expression>,
12585    #[serde(default)]
12586    pub path: Option<Box<Expression>>,
12587    #[serde(default)]
12588    pub safe: Option<Box<Expression>>,
12589}
12590
12591/// Columns
12592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12593#[cfg_attr(feature = "bindings", derive(TS))]
12594pub struct Columns {
12595    pub this: Box<Expression>,
12596    #[serde(default)]
12597    pub unpack: Option<Box<Expression>>,
12598}
12599
12600/// ConvertToCharset
12601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12602#[cfg_attr(feature = "bindings", derive(TS))]
12603pub struct ConvertToCharset {
12604    pub this: Box<Expression>,
12605    #[serde(default)]
12606    pub dest: Option<Box<Expression>>,
12607    #[serde(default)]
12608    pub source: Option<Box<Expression>>,
12609}
12610
12611/// ConvertTimezone
12612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12613#[cfg_attr(feature = "bindings", derive(TS))]
12614pub struct ConvertTimezone {
12615    #[serde(default)]
12616    pub source_tz: Option<Box<Expression>>,
12617    #[serde(default)]
12618    pub target_tz: Option<Box<Expression>>,
12619    #[serde(default)]
12620    pub timestamp: Option<Box<Expression>>,
12621    #[serde(default)]
12622    pub options: Vec<Expression>,
12623}
12624
12625/// GenerateSeries
12626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12627#[cfg_attr(feature = "bindings", derive(TS))]
12628pub struct GenerateSeries {
12629    #[serde(default)]
12630    pub start: Option<Box<Expression>>,
12631    #[serde(default)]
12632    pub end: Option<Box<Expression>>,
12633    #[serde(default)]
12634    pub step: Option<Box<Expression>>,
12635    #[serde(default)]
12636    pub is_end_exclusive: Option<Box<Expression>>,
12637}
12638
12639/// AIAgg
12640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12641#[cfg_attr(feature = "bindings", derive(TS))]
12642pub struct AIAgg {
12643    pub this: Box<Expression>,
12644    pub expression: Box<Expression>,
12645}
12646
12647/// AIClassify
12648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12649#[cfg_attr(feature = "bindings", derive(TS))]
12650pub struct AIClassify {
12651    pub this: Box<Expression>,
12652    #[serde(default)]
12653    pub categories: Option<Box<Expression>>,
12654    #[serde(default)]
12655    pub config: Option<Box<Expression>>,
12656}
12657
12658/// ArrayAll
12659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12660#[cfg_attr(feature = "bindings", derive(TS))]
12661pub struct ArrayAll {
12662    pub this: Box<Expression>,
12663    pub expression: Box<Expression>,
12664}
12665
12666/// ArrayAny
12667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12668#[cfg_attr(feature = "bindings", derive(TS))]
12669pub struct ArrayAny {
12670    pub this: Box<Expression>,
12671    pub expression: Box<Expression>,
12672}
12673
12674/// ArrayConstructCompact
12675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12676#[cfg_attr(feature = "bindings", derive(TS))]
12677pub struct ArrayConstructCompact {
12678    #[serde(default)]
12679    pub expressions: Vec<Expression>,
12680}
12681
12682/// StPoint
12683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12684#[cfg_attr(feature = "bindings", derive(TS))]
12685pub struct StPoint {
12686    pub this: Box<Expression>,
12687    pub expression: Box<Expression>,
12688    #[serde(default)]
12689    pub null: Option<Box<Expression>>,
12690}
12691
12692/// StDistance
12693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12694#[cfg_attr(feature = "bindings", derive(TS))]
12695pub struct StDistance {
12696    pub this: Box<Expression>,
12697    pub expression: Box<Expression>,
12698    #[serde(default)]
12699    pub use_spheroid: Option<Box<Expression>>,
12700}
12701
12702/// StringToArray
12703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12704#[cfg_attr(feature = "bindings", derive(TS))]
12705pub struct StringToArray {
12706    pub this: Box<Expression>,
12707    #[serde(default)]
12708    pub expression: Option<Box<Expression>>,
12709    #[serde(default)]
12710    pub null: Option<Box<Expression>>,
12711}
12712
12713/// ArraySum
12714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12715#[cfg_attr(feature = "bindings", derive(TS))]
12716pub struct ArraySum {
12717    pub this: Box<Expression>,
12718    #[serde(default)]
12719    pub expression: Option<Box<Expression>>,
12720}
12721
12722/// ObjectAgg
12723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12724#[cfg_attr(feature = "bindings", derive(TS))]
12725pub struct ObjectAgg {
12726    pub this: Box<Expression>,
12727    pub expression: Box<Expression>,
12728}
12729
12730/// CastToStrType
12731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12732#[cfg_attr(feature = "bindings", derive(TS))]
12733pub struct CastToStrType {
12734    pub this: Box<Expression>,
12735    #[serde(default)]
12736    pub to: Option<Box<Expression>>,
12737}
12738
12739/// CheckJson
12740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12741#[cfg_attr(feature = "bindings", derive(TS))]
12742pub struct CheckJson {
12743    pub this: Box<Expression>,
12744}
12745
12746/// CheckXml
12747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12748#[cfg_attr(feature = "bindings", derive(TS))]
12749pub struct CheckXml {
12750    pub this: Box<Expression>,
12751    #[serde(default)]
12752    pub disable_auto_convert: Option<Box<Expression>>,
12753}
12754
12755/// TranslateCharacters
12756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12757#[cfg_attr(feature = "bindings", derive(TS))]
12758pub struct TranslateCharacters {
12759    pub this: Box<Expression>,
12760    pub expression: Box<Expression>,
12761    #[serde(default)]
12762    pub with_error: Option<Box<Expression>>,
12763}
12764
12765/// CurrentSchemas
12766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12767#[cfg_attr(feature = "bindings", derive(TS))]
12768pub struct CurrentSchemas {
12769    #[serde(default)]
12770    pub this: Option<Box<Expression>>,
12771}
12772
12773/// CurrentDatetime
12774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12775#[cfg_attr(feature = "bindings", derive(TS))]
12776pub struct CurrentDatetime {
12777    #[serde(default)]
12778    pub this: Option<Box<Expression>>,
12779}
12780
12781/// Localtime
12782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12783#[cfg_attr(feature = "bindings", derive(TS))]
12784pub struct Localtime {
12785    #[serde(default)]
12786    pub this: Option<Box<Expression>>,
12787}
12788
12789/// Localtimestamp
12790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12791#[cfg_attr(feature = "bindings", derive(TS))]
12792pub struct Localtimestamp {
12793    #[serde(default)]
12794    pub this: Option<Box<Expression>>,
12795}
12796
12797/// Systimestamp
12798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12799#[cfg_attr(feature = "bindings", derive(TS))]
12800pub struct Systimestamp {
12801    #[serde(default)]
12802    pub this: Option<Box<Expression>>,
12803}
12804
12805/// CurrentSchema
12806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12807#[cfg_attr(feature = "bindings", derive(TS))]
12808pub struct CurrentSchema {
12809    #[serde(default)]
12810    pub this: Option<Box<Expression>>,
12811}
12812
12813/// CurrentUser
12814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12815#[cfg_attr(feature = "bindings", derive(TS))]
12816pub struct CurrentUser {
12817    #[serde(default)]
12818    pub this: Option<Box<Expression>>,
12819}
12820
12821/// SessionUser - MySQL/PostgreSQL SESSION_USER function
12822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12823#[cfg_attr(feature = "bindings", derive(TS))]
12824pub struct SessionUser;
12825
12826/// JSONPathRoot - Represents $ in JSON path expressions
12827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12828#[cfg_attr(feature = "bindings", derive(TS))]
12829pub struct JSONPathRoot;
12830
12831/// UtcTime
12832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12833#[cfg_attr(feature = "bindings", derive(TS))]
12834pub struct UtcTime {
12835    #[serde(default)]
12836    pub this: Option<Box<Expression>>,
12837}
12838
12839/// UtcTimestamp
12840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12841#[cfg_attr(feature = "bindings", derive(TS))]
12842pub struct UtcTimestamp {
12843    #[serde(default)]
12844    pub this: Option<Box<Expression>>,
12845}
12846
12847/// TimestampFunc - TIMESTAMP constructor function
12848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12849#[cfg_attr(feature = "bindings", derive(TS))]
12850pub struct TimestampFunc {
12851    #[serde(default)]
12852    pub this: Option<Box<Expression>>,
12853    #[serde(default)]
12854    pub zone: Option<Box<Expression>>,
12855    #[serde(default)]
12856    pub with_tz: Option<bool>,
12857    #[serde(default)]
12858    pub safe: Option<bool>,
12859}
12860
12861/// DateBin
12862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12863#[cfg_attr(feature = "bindings", derive(TS))]
12864pub struct DateBin {
12865    pub this: Box<Expression>,
12866    pub expression: Box<Expression>,
12867    #[serde(default)]
12868    pub unit: Option<String>,
12869    #[serde(default)]
12870    pub zone: Option<Box<Expression>>,
12871    #[serde(default)]
12872    pub origin: Option<Box<Expression>>,
12873}
12874
12875/// Datetime
12876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12877#[cfg_attr(feature = "bindings", derive(TS))]
12878pub struct Datetime {
12879    pub this: Box<Expression>,
12880    #[serde(default)]
12881    pub expression: Option<Box<Expression>>,
12882}
12883
12884/// DatetimeAdd
12885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12886#[cfg_attr(feature = "bindings", derive(TS))]
12887pub struct DatetimeAdd {
12888    pub this: Box<Expression>,
12889    pub expression: Box<Expression>,
12890    #[serde(default)]
12891    pub unit: Option<String>,
12892}
12893
12894/// DatetimeSub
12895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12896#[cfg_attr(feature = "bindings", derive(TS))]
12897pub struct DatetimeSub {
12898    pub this: Box<Expression>,
12899    pub expression: Box<Expression>,
12900    #[serde(default)]
12901    pub unit: Option<String>,
12902}
12903
12904/// DatetimeDiff
12905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12906#[cfg_attr(feature = "bindings", derive(TS))]
12907pub struct DatetimeDiff {
12908    pub this: Box<Expression>,
12909    pub expression: Box<Expression>,
12910    #[serde(default)]
12911    pub unit: Option<String>,
12912}
12913
12914/// DatetimeTrunc
12915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12916#[cfg_attr(feature = "bindings", derive(TS))]
12917pub struct DatetimeTrunc {
12918    pub this: Box<Expression>,
12919    pub unit: String,
12920    #[serde(default)]
12921    pub zone: Option<Box<Expression>>,
12922}
12923
12924/// Dayname
12925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12926#[cfg_attr(feature = "bindings", derive(TS))]
12927pub struct Dayname {
12928    pub this: Box<Expression>,
12929    #[serde(default)]
12930    pub abbreviated: Option<Box<Expression>>,
12931}
12932
12933/// MakeInterval
12934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12935#[cfg_attr(feature = "bindings", derive(TS))]
12936pub struct MakeInterval {
12937    #[serde(default)]
12938    pub year: Option<Box<Expression>>,
12939    #[serde(default)]
12940    pub month: Option<Box<Expression>>,
12941    #[serde(default)]
12942    pub week: Option<Box<Expression>>,
12943    #[serde(default)]
12944    pub day: Option<Box<Expression>>,
12945    #[serde(default)]
12946    pub hour: Option<Box<Expression>>,
12947    #[serde(default)]
12948    pub minute: Option<Box<Expression>>,
12949    #[serde(default)]
12950    pub second: Option<Box<Expression>>,
12951}
12952
12953/// PreviousDay
12954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12955#[cfg_attr(feature = "bindings", derive(TS))]
12956pub struct PreviousDay {
12957    pub this: Box<Expression>,
12958    pub expression: Box<Expression>,
12959}
12960
12961/// Elt
12962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12963#[cfg_attr(feature = "bindings", derive(TS))]
12964pub struct Elt {
12965    pub this: Box<Expression>,
12966    #[serde(default)]
12967    pub expressions: Vec<Expression>,
12968}
12969
12970/// TimestampAdd
12971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12972#[cfg_attr(feature = "bindings", derive(TS))]
12973pub struct TimestampAdd {
12974    pub this: Box<Expression>,
12975    pub expression: Box<Expression>,
12976    #[serde(default)]
12977    pub unit: Option<String>,
12978}
12979
12980/// TimestampSub
12981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12982#[cfg_attr(feature = "bindings", derive(TS))]
12983pub struct TimestampSub {
12984    pub this: Box<Expression>,
12985    pub expression: Box<Expression>,
12986    #[serde(default)]
12987    pub unit: Option<String>,
12988}
12989
12990/// TimestampDiff
12991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12992#[cfg_attr(feature = "bindings", derive(TS))]
12993pub struct TimestampDiff {
12994    pub this: Box<Expression>,
12995    pub expression: Box<Expression>,
12996    #[serde(default)]
12997    pub unit: Option<String>,
12998}
12999
13000/// TimeSlice
13001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13002#[cfg_attr(feature = "bindings", derive(TS))]
13003pub struct TimeSlice {
13004    pub this: Box<Expression>,
13005    pub expression: Box<Expression>,
13006    pub unit: String,
13007    #[serde(default)]
13008    pub kind: Option<String>,
13009}
13010
13011/// TimeAdd
13012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13013#[cfg_attr(feature = "bindings", derive(TS))]
13014pub struct TimeAdd {
13015    pub this: Box<Expression>,
13016    pub expression: Box<Expression>,
13017    #[serde(default)]
13018    pub unit: Option<String>,
13019}
13020
13021/// TimeSub
13022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13023#[cfg_attr(feature = "bindings", derive(TS))]
13024pub struct TimeSub {
13025    pub this: Box<Expression>,
13026    pub expression: Box<Expression>,
13027    #[serde(default)]
13028    pub unit: Option<String>,
13029}
13030
13031/// TimeDiff
13032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13033#[cfg_attr(feature = "bindings", derive(TS))]
13034pub struct TimeDiff {
13035    pub this: Box<Expression>,
13036    pub expression: Box<Expression>,
13037    #[serde(default)]
13038    pub unit: Option<String>,
13039}
13040
13041/// TimeTrunc
13042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13043#[cfg_attr(feature = "bindings", derive(TS))]
13044pub struct TimeTrunc {
13045    pub this: Box<Expression>,
13046    pub unit: String,
13047    #[serde(default)]
13048    pub zone: Option<Box<Expression>>,
13049}
13050
13051/// DateFromParts
13052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13053#[cfg_attr(feature = "bindings", derive(TS))]
13054pub struct DateFromParts {
13055    #[serde(default)]
13056    pub year: Option<Box<Expression>>,
13057    #[serde(default)]
13058    pub month: Option<Box<Expression>>,
13059    #[serde(default)]
13060    pub day: Option<Box<Expression>>,
13061    #[serde(default)]
13062    pub allow_overflow: Option<Box<Expression>>,
13063}
13064
13065/// TimeFromParts
13066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13067#[cfg_attr(feature = "bindings", derive(TS))]
13068pub struct TimeFromParts {
13069    #[serde(default)]
13070    pub hour: Option<Box<Expression>>,
13071    #[serde(default)]
13072    pub min: Option<Box<Expression>>,
13073    #[serde(default)]
13074    pub sec: Option<Box<Expression>>,
13075    #[serde(default)]
13076    pub nano: Option<Box<Expression>>,
13077    #[serde(default)]
13078    pub fractions: Option<Box<Expression>>,
13079    #[serde(default)]
13080    pub precision: Option<i64>,
13081}
13082
13083/// DecodeCase
13084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13085#[cfg_attr(feature = "bindings", derive(TS))]
13086pub struct DecodeCase {
13087    #[serde(default)]
13088    pub expressions: Vec<Expression>,
13089}
13090
13091/// Decrypt
13092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13093#[cfg_attr(feature = "bindings", derive(TS))]
13094pub struct Decrypt {
13095    pub this: Box<Expression>,
13096    #[serde(default)]
13097    pub passphrase: Option<Box<Expression>>,
13098    #[serde(default)]
13099    pub aad: Option<Box<Expression>>,
13100    #[serde(default)]
13101    pub encryption_method: Option<Box<Expression>>,
13102    #[serde(default)]
13103    pub safe: Option<Box<Expression>>,
13104}
13105
13106/// DecryptRaw
13107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13108#[cfg_attr(feature = "bindings", derive(TS))]
13109pub struct DecryptRaw {
13110    pub this: Box<Expression>,
13111    #[serde(default)]
13112    pub key: Option<Box<Expression>>,
13113    #[serde(default)]
13114    pub iv: Option<Box<Expression>>,
13115    #[serde(default)]
13116    pub aad: Option<Box<Expression>>,
13117    #[serde(default)]
13118    pub encryption_method: Option<Box<Expression>>,
13119    #[serde(default)]
13120    pub aead: Option<Box<Expression>>,
13121    #[serde(default)]
13122    pub safe: Option<Box<Expression>>,
13123}
13124
13125/// Encode
13126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13127#[cfg_attr(feature = "bindings", derive(TS))]
13128pub struct Encode {
13129    pub this: Box<Expression>,
13130    #[serde(default)]
13131    pub charset: Option<Box<Expression>>,
13132}
13133
13134/// Encrypt
13135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13136#[cfg_attr(feature = "bindings", derive(TS))]
13137pub struct Encrypt {
13138    pub this: Box<Expression>,
13139    #[serde(default)]
13140    pub passphrase: Option<Box<Expression>>,
13141    #[serde(default)]
13142    pub aad: Option<Box<Expression>>,
13143    #[serde(default)]
13144    pub encryption_method: Option<Box<Expression>>,
13145}
13146
13147/// EncryptRaw
13148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13149#[cfg_attr(feature = "bindings", derive(TS))]
13150pub struct EncryptRaw {
13151    pub this: Box<Expression>,
13152    #[serde(default)]
13153    pub key: Option<Box<Expression>>,
13154    #[serde(default)]
13155    pub iv: Option<Box<Expression>>,
13156    #[serde(default)]
13157    pub aad: Option<Box<Expression>>,
13158    #[serde(default)]
13159    pub encryption_method: Option<Box<Expression>>,
13160}
13161
13162/// EqualNull
13163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13164#[cfg_attr(feature = "bindings", derive(TS))]
13165pub struct EqualNull {
13166    pub this: Box<Expression>,
13167    pub expression: Box<Expression>,
13168}
13169
13170/// ToBinary
13171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13172#[cfg_attr(feature = "bindings", derive(TS))]
13173pub struct ToBinary {
13174    pub this: Box<Expression>,
13175    #[serde(default)]
13176    pub format: Option<String>,
13177    #[serde(default)]
13178    pub safe: Option<Box<Expression>>,
13179}
13180
13181/// Base64DecodeBinary
13182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13183#[cfg_attr(feature = "bindings", derive(TS))]
13184pub struct Base64DecodeBinary {
13185    pub this: Box<Expression>,
13186    #[serde(default)]
13187    pub alphabet: Option<Box<Expression>>,
13188}
13189
13190/// Base64DecodeString
13191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13192#[cfg_attr(feature = "bindings", derive(TS))]
13193pub struct Base64DecodeString {
13194    pub this: Box<Expression>,
13195    #[serde(default)]
13196    pub alphabet: Option<Box<Expression>>,
13197}
13198
13199/// Base64Encode
13200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13201#[cfg_attr(feature = "bindings", derive(TS))]
13202pub struct Base64Encode {
13203    pub this: Box<Expression>,
13204    #[serde(default)]
13205    pub max_line_length: Option<Box<Expression>>,
13206    #[serde(default)]
13207    pub alphabet: Option<Box<Expression>>,
13208}
13209
13210/// TryBase64DecodeBinary
13211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13212#[cfg_attr(feature = "bindings", derive(TS))]
13213pub struct TryBase64DecodeBinary {
13214    pub this: Box<Expression>,
13215    #[serde(default)]
13216    pub alphabet: Option<Box<Expression>>,
13217}
13218
13219/// TryBase64DecodeString
13220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13221#[cfg_attr(feature = "bindings", derive(TS))]
13222pub struct TryBase64DecodeString {
13223    pub this: Box<Expression>,
13224    #[serde(default)]
13225    pub alphabet: Option<Box<Expression>>,
13226}
13227
13228/// GapFill
13229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13230#[cfg_attr(feature = "bindings", derive(TS))]
13231pub struct GapFill {
13232    pub this: Box<Expression>,
13233    #[serde(default)]
13234    pub ts_column: Option<Box<Expression>>,
13235    #[serde(default)]
13236    pub bucket_width: Option<Box<Expression>>,
13237    #[serde(default)]
13238    pub partitioning_columns: Option<Box<Expression>>,
13239    #[serde(default)]
13240    pub value_columns: Option<Box<Expression>>,
13241    #[serde(default)]
13242    pub origin: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub ignore_nulls: Option<Box<Expression>>,
13245}
13246
13247/// GenerateDateArray
13248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13249#[cfg_attr(feature = "bindings", derive(TS))]
13250pub struct GenerateDateArray {
13251    #[serde(default)]
13252    pub start: Option<Box<Expression>>,
13253    #[serde(default)]
13254    pub end: Option<Box<Expression>>,
13255    #[serde(default)]
13256    pub step: Option<Box<Expression>>,
13257}
13258
13259/// GenerateTimestampArray
13260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13261#[cfg_attr(feature = "bindings", derive(TS))]
13262pub struct GenerateTimestampArray {
13263    #[serde(default)]
13264    pub start: Option<Box<Expression>>,
13265    #[serde(default)]
13266    pub end: Option<Box<Expression>>,
13267    #[serde(default)]
13268    pub step: Option<Box<Expression>>,
13269}
13270
13271/// GetExtract
13272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13273#[cfg_attr(feature = "bindings", derive(TS))]
13274pub struct GetExtract {
13275    pub this: Box<Expression>,
13276    pub expression: Box<Expression>,
13277}
13278
13279/// Getbit
13280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13281#[cfg_attr(feature = "bindings", derive(TS))]
13282pub struct Getbit {
13283    pub this: Box<Expression>,
13284    pub expression: Box<Expression>,
13285    #[serde(default)]
13286    pub zero_is_msb: Option<Box<Expression>>,
13287}
13288
13289/// OverflowTruncateBehavior
13290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13291#[cfg_attr(feature = "bindings", derive(TS))]
13292pub struct OverflowTruncateBehavior {
13293    #[serde(default)]
13294    pub this: Option<Box<Expression>>,
13295    #[serde(default)]
13296    pub with_count: Option<Box<Expression>>,
13297}
13298
13299/// HexEncode
13300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13301#[cfg_attr(feature = "bindings", derive(TS))]
13302pub struct HexEncode {
13303    pub this: Box<Expression>,
13304    #[serde(default)]
13305    pub case: Option<Box<Expression>>,
13306}
13307
13308/// Compress
13309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13310#[cfg_attr(feature = "bindings", derive(TS))]
13311pub struct Compress {
13312    pub this: Box<Expression>,
13313    #[serde(default)]
13314    pub method: Option<String>,
13315}
13316
13317/// DecompressBinary
13318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13319#[cfg_attr(feature = "bindings", derive(TS))]
13320pub struct DecompressBinary {
13321    pub this: Box<Expression>,
13322    pub method: String,
13323}
13324
13325/// DecompressString
13326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13327#[cfg_attr(feature = "bindings", derive(TS))]
13328pub struct DecompressString {
13329    pub this: Box<Expression>,
13330    pub method: String,
13331}
13332
13333/// Xor
13334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13335#[cfg_attr(feature = "bindings", derive(TS))]
13336pub struct Xor {
13337    #[serde(default)]
13338    pub this: Option<Box<Expression>>,
13339    #[serde(default)]
13340    pub expression: Option<Box<Expression>>,
13341    #[serde(default)]
13342    pub expressions: Vec<Expression>,
13343}
13344
13345/// Nullif
13346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13347#[cfg_attr(feature = "bindings", derive(TS))]
13348pub struct Nullif {
13349    pub this: Box<Expression>,
13350    pub expression: Box<Expression>,
13351}
13352
13353/// JSON
13354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13355#[cfg_attr(feature = "bindings", derive(TS))]
13356pub struct JSON {
13357    #[serde(default)]
13358    pub this: Option<Box<Expression>>,
13359    #[serde(default)]
13360    pub with_: Option<Box<Expression>>,
13361    #[serde(default)]
13362    pub unique: bool,
13363}
13364
13365/// JSONPath
13366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13367#[cfg_attr(feature = "bindings", derive(TS))]
13368pub struct JSONPath {
13369    #[serde(default)]
13370    pub expressions: Vec<Expression>,
13371    #[serde(default)]
13372    pub escape: Option<Box<Expression>>,
13373}
13374
13375/// JSONPathFilter
13376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13377#[cfg_attr(feature = "bindings", derive(TS))]
13378pub struct JSONPathFilter {
13379    pub this: Box<Expression>,
13380}
13381
13382/// JSONPathKey
13383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13384#[cfg_attr(feature = "bindings", derive(TS))]
13385pub struct JSONPathKey {
13386    pub this: Box<Expression>,
13387}
13388
13389/// JSONPathRecursive
13390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13391#[cfg_attr(feature = "bindings", derive(TS))]
13392pub struct JSONPathRecursive {
13393    #[serde(default)]
13394    pub this: Option<Box<Expression>>,
13395}
13396
13397/// JSONPathScript
13398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13399#[cfg_attr(feature = "bindings", derive(TS))]
13400pub struct JSONPathScript {
13401    pub this: Box<Expression>,
13402}
13403
13404/// JSONPathSlice
13405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13406#[cfg_attr(feature = "bindings", derive(TS))]
13407pub struct JSONPathSlice {
13408    #[serde(default)]
13409    pub start: Option<Box<Expression>>,
13410    #[serde(default)]
13411    pub end: Option<Box<Expression>>,
13412    #[serde(default)]
13413    pub step: Option<Box<Expression>>,
13414}
13415
13416/// JSONPathSelector
13417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13418#[cfg_attr(feature = "bindings", derive(TS))]
13419pub struct JSONPathSelector {
13420    pub this: Box<Expression>,
13421}
13422
13423/// JSONPathSubscript
13424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13425#[cfg_attr(feature = "bindings", derive(TS))]
13426pub struct JSONPathSubscript {
13427    pub this: Box<Expression>,
13428}
13429
13430/// JSONPathUnion
13431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13432#[cfg_attr(feature = "bindings", derive(TS))]
13433pub struct JSONPathUnion {
13434    #[serde(default)]
13435    pub expressions: Vec<Expression>,
13436}
13437
13438/// Format
13439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13440#[cfg_attr(feature = "bindings", derive(TS))]
13441pub struct Format {
13442    pub this: Box<Expression>,
13443    #[serde(default)]
13444    pub expressions: Vec<Expression>,
13445}
13446
13447/// JSONKeys
13448#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13449#[cfg_attr(feature = "bindings", derive(TS))]
13450pub struct JSONKeys {
13451    pub this: Box<Expression>,
13452    #[serde(default)]
13453    pub expression: Option<Box<Expression>>,
13454    #[serde(default)]
13455    pub expressions: Vec<Expression>,
13456}
13457
13458/// JSONKeyValue
13459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13460#[cfg_attr(feature = "bindings", derive(TS))]
13461pub struct JSONKeyValue {
13462    pub this: Box<Expression>,
13463    pub expression: Box<Expression>,
13464}
13465
13466/// JSONKeysAtDepth
13467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13468#[cfg_attr(feature = "bindings", derive(TS))]
13469pub struct JSONKeysAtDepth {
13470    pub this: Box<Expression>,
13471    #[serde(default)]
13472    pub expression: Option<Box<Expression>>,
13473    #[serde(default)]
13474    pub mode: Option<Box<Expression>>,
13475}
13476
13477/// JSONObject
13478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13479#[cfg_attr(feature = "bindings", derive(TS))]
13480pub struct JSONObject {
13481    #[serde(default)]
13482    pub expressions: Vec<Expression>,
13483    #[serde(default)]
13484    pub null_handling: Option<Box<Expression>>,
13485    #[serde(default)]
13486    pub unique_keys: Option<Box<Expression>>,
13487    #[serde(default)]
13488    pub return_type: Option<Box<Expression>>,
13489    #[serde(default)]
13490    pub encoding: Option<Box<Expression>>,
13491}
13492
13493/// JSONObjectAgg
13494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13495#[cfg_attr(feature = "bindings", derive(TS))]
13496pub struct JSONObjectAgg {
13497    #[serde(default)]
13498    pub expressions: Vec<Expression>,
13499    #[serde(default)]
13500    pub null_handling: Option<Box<Expression>>,
13501    #[serde(default)]
13502    pub unique_keys: Option<Box<Expression>>,
13503    #[serde(default)]
13504    pub return_type: Option<Box<Expression>>,
13505    #[serde(default)]
13506    pub encoding: Option<Box<Expression>>,
13507}
13508
13509/// JSONBObjectAgg
13510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13511#[cfg_attr(feature = "bindings", derive(TS))]
13512pub struct JSONBObjectAgg {
13513    pub this: Box<Expression>,
13514    pub expression: Box<Expression>,
13515}
13516
13517/// JSONArray
13518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13519#[cfg_attr(feature = "bindings", derive(TS))]
13520pub struct JSONArray {
13521    #[serde(default)]
13522    pub expressions: Vec<Expression>,
13523    #[serde(default)]
13524    pub null_handling: Option<Box<Expression>>,
13525    #[serde(default)]
13526    pub return_type: Option<Box<Expression>>,
13527    #[serde(default)]
13528    pub strict: Option<Box<Expression>>,
13529}
13530
13531/// JSONArrayAgg
13532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13533#[cfg_attr(feature = "bindings", derive(TS))]
13534pub struct JSONArrayAgg {
13535    pub this: Box<Expression>,
13536    #[serde(default)]
13537    pub order: Option<Box<Expression>>,
13538    #[serde(default)]
13539    pub null_handling: Option<Box<Expression>>,
13540    #[serde(default)]
13541    pub return_type: Option<Box<Expression>>,
13542    #[serde(default)]
13543    pub strict: Option<Box<Expression>>,
13544}
13545
13546/// JSONExists
13547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13548#[cfg_attr(feature = "bindings", derive(TS))]
13549pub struct JSONExists {
13550    pub this: Box<Expression>,
13551    #[serde(default)]
13552    pub path: Option<Box<Expression>>,
13553    #[serde(default)]
13554    pub passing: Option<Box<Expression>>,
13555    #[serde(default)]
13556    pub on_condition: Option<Box<Expression>>,
13557    #[serde(default)]
13558    pub from_dcolonqmark: Option<Box<Expression>>,
13559}
13560
13561/// JSONColumnDef
13562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13563#[cfg_attr(feature = "bindings", derive(TS))]
13564pub struct JSONColumnDef {
13565    #[serde(default)]
13566    pub this: Option<Box<Expression>>,
13567    #[serde(default)]
13568    pub kind: Option<String>,
13569    #[serde(default)]
13570    pub path: Option<Box<Expression>>,
13571    #[serde(default)]
13572    pub nested_schema: Option<Box<Expression>>,
13573    #[serde(default)]
13574    pub ordinality: Option<Box<Expression>>,
13575}
13576
13577/// JSONSchema
13578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13579#[cfg_attr(feature = "bindings", derive(TS))]
13580pub struct JSONSchema {
13581    #[serde(default)]
13582    pub expressions: Vec<Expression>,
13583}
13584
13585/// JSONSet
13586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13587#[cfg_attr(feature = "bindings", derive(TS))]
13588pub struct JSONSet {
13589    pub this: Box<Expression>,
13590    #[serde(default)]
13591    pub expressions: Vec<Expression>,
13592}
13593
13594/// JSONStripNulls
13595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13596#[cfg_attr(feature = "bindings", derive(TS))]
13597pub struct JSONStripNulls {
13598    pub this: Box<Expression>,
13599    #[serde(default)]
13600    pub expression: Option<Box<Expression>>,
13601    #[serde(default)]
13602    pub include_arrays: Option<Box<Expression>>,
13603    #[serde(default)]
13604    pub remove_empty: Option<Box<Expression>>,
13605}
13606
13607/// JSONValue
13608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13609#[cfg_attr(feature = "bindings", derive(TS))]
13610pub struct JSONValue {
13611    pub this: Box<Expression>,
13612    #[serde(default)]
13613    pub path: Option<Box<Expression>>,
13614    #[serde(default)]
13615    pub returning: Option<Box<Expression>>,
13616    #[serde(default)]
13617    pub on_condition: Option<Box<Expression>>,
13618}
13619
13620/// JSONValueArray
13621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13622#[cfg_attr(feature = "bindings", derive(TS))]
13623pub struct JSONValueArray {
13624    pub this: Box<Expression>,
13625    #[serde(default)]
13626    pub expression: Option<Box<Expression>>,
13627}
13628
13629/// JSONRemove
13630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13631#[cfg_attr(feature = "bindings", derive(TS))]
13632pub struct JSONRemove {
13633    pub this: Box<Expression>,
13634    #[serde(default)]
13635    pub expressions: Vec<Expression>,
13636}
13637
13638/// JSONTable
13639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13640#[cfg_attr(feature = "bindings", derive(TS))]
13641pub struct JSONTable {
13642    pub this: Box<Expression>,
13643    #[serde(default)]
13644    pub schema: Option<Box<Expression>>,
13645    #[serde(default)]
13646    pub path: Option<Box<Expression>>,
13647    #[serde(default)]
13648    pub error_handling: Option<Box<Expression>>,
13649    #[serde(default)]
13650    pub empty_handling: Option<Box<Expression>>,
13651}
13652
13653/// JSONType
13654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13655#[cfg_attr(feature = "bindings", derive(TS))]
13656pub struct JSONType {
13657    pub this: Box<Expression>,
13658    #[serde(default)]
13659    pub expression: Option<Box<Expression>>,
13660}
13661
13662/// ObjectInsert
13663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13664#[cfg_attr(feature = "bindings", derive(TS))]
13665pub struct ObjectInsert {
13666    pub this: Box<Expression>,
13667    #[serde(default)]
13668    pub key: Option<Box<Expression>>,
13669    #[serde(default)]
13670    pub value: Option<Box<Expression>>,
13671    #[serde(default)]
13672    pub update_flag: Option<Box<Expression>>,
13673}
13674
13675/// OpenJSONColumnDef
13676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13677#[cfg_attr(feature = "bindings", derive(TS))]
13678pub struct OpenJSONColumnDef {
13679    pub this: Box<Expression>,
13680    pub kind: String,
13681    #[serde(default)]
13682    pub path: Option<Box<Expression>>,
13683    #[serde(default)]
13684    pub as_json: Option<Box<Expression>>,
13685    /// The parsed data type for proper generation
13686    #[serde(default, skip_serializing_if = "Option::is_none")]
13687    pub data_type: Option<DataType>,
13688}
13689
13690/// OpenJSON
13691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13692#[cfg_attr(feature = "bindings", derive(TS))]
13693pub struct OpenJSON {
13694    pub this: Box<Expression>,
13695    #[serde(default)]
13696    pub path: Option<Box<Expression>>,
13697    #[serde(default)]
13698    pub expressions: Vec<Expression>,
13699}
13700
13701/// JSONBExists
13702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13703#[cfg_attr(feature = "bindings", derive(TS))]
13704pub struct JSONBExists {
13705    pub this: Box<Expression>,
13706    #[serde(default)]
13707    pub path: Option<Box<Expression>>,
13708}
13709
13710/// JSONCast
13711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13712#[cfg_attr(feature = "bindings", derive(TS))]
13713pub struct JSONCast {
13714    pub this: Box<Expression>,
13715    pub to: DataType,
13716}
13717
13718/// JSONExtract
13719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13720#[cfg_attr(feature = "bindings", derive(TS))]
13721pub struct JSONExtract {
13722    pub this: Box<Expression>,
13723    pub expression: Box<Expression>,
13724    #[serde(default)]
13725    pub only_json_types: Option<Box<Expression>>,
13726    #[serde(default)]
13727    pub expressions: Vec<Expression>,
13728    #[serde(default)]
13729    pub variant_extract: Option<Box<Expression>>,
13730    #[serde(default)]
13731    pub json_query: Option<Box<Expression>>,
13732    #[serde(default)]
13733    pub option: Option<Box<Expression>>,
13734    #[serde(default)]
13735    pub quote: Option<Box<Expression>>,
13736    #[serde(default)]
13737    pub on_condition: Option<Box<Expression>>,
13738    #[serde(default)]
13739    pub requires_json: Option<Box<Expression>>,
13740}
13741
13742/// JSONExtractQuote
13743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13744#[cfg_attr(feature = "bindings", derive(TS))]
13745pub struct JSONExtractQuote {
13746    #[serde(default)]
13747    pub option: Option<Box<Expression>>,
13748    #[serde(default)]
13749    pub scalar: Option<Box<Expression>>,
13750}
13751
13752/// JSONExtractArray
13753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13754#[cfg_attr(feature = "bindings", derive(TS))]
13755pub struct JSONExtractArray {
13756    pub this: Box<Expression>,
13757    #[serde(default)]
13758    pub expression: Option<Box<Expression>>,
13759}
13760
13761/// JSONExtractScalar
13762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13763#[cfg_attr(feature = "bindings", derive(TS))]
13764pub struct JSONExtractScalar {
13765    pub this: Box<Expression>,
13766    pub expression: Box<Expression>,
13767    #[serde(default)]
13768    pub only_json_types: Option<Box<Expression>>,
13769    #[serde(default)]
13770    pub expressions: Vec<Expression>,
13771    #[serde(default)]
13772    pub json_type: Option<Box<Expression>>,
13773    #[serde(default)]
13774    pub scalar_only: Option<Box<Expression>>,
13775}
13776
13777/// JSONBExtractScalar
13778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13779#[cfg_attr(feature = "bindings", derive(TS))]
13780pub struct JSONBExtractScalar {
13781    pub this: Box<Expression>,
13782    pub expression: Box<Expression>,
13783    #[serde(default)]
13784    pub json_type: Option<Box<Expression>>,
13785}
13786
13787/// JSONFormat
13788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13789#[cfg_attr(feature = "bindings", derive(TS))]
13790pub struct JSONFormat {
13791    #[serde(default)]
13792    pub this: Option<Box<Expression>>,
13793    #[serde(default)]
13794    pub options: Vec<Expression>,
13795    #[serde(default)]
13796    pub is_json: Option<Box<Expression>>,
13797    #[serde(default)]
13798    pub to_json: Option<Box<Expression>>,
13799}
13800
13801/// JSONArrayAppend
13802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13803#[cfg_attr(feature = "bindings", derive(TS))]
13804pub struct JSONArrayAppend {
13805    pub this: Box<Expression>,
13806    #[serde(default)]
13807    pub expressions: Vec<Expression>,
13808}
13809
13810/// JSONArrayContains
13811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13812#[cfg_attr(feature = "bindings", derive(TS))]
13813pub struct JSONArrayContains {
13814    pub this: Box<Expression>,
13815    pub expression: Box<Expression>,
13816    #[serde(default)]
13817    pub json_type: Option<Box<Expression>>,
13818}
13819
13820/// JSONArrayInsert
13821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13822#[cfg_attr(feature = "bindings", derive(TS))]
13823pub struct JSONArrayInsert {
13824    pub this: Box<Expression>,
13825    #[serde(default)]
13826    pub expressions: Vec<Expression>,
13827}
13828
13829/// ParseJSON
13830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13831#[cfg_attr(feature = "bindings", derive(TS))]
13832pub struct ParseJSON {
13833    pub this: Box<Expression>,
13834    #[serde(default)]
13835    pub expression: Option<Box<Expression>>,
13836    #[serde(default)]
13837    pub safe: Option<Box<Expression>>,
13838}
13839
13840/// ParseUrl
13841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13842#[cfg_attr(feature = "bindings", derive(TS))]
13843pub struct ParseUrl {
13844    pub this: Box<Expression>,
13845    #[serde(default)]
13846    pub part_to_extract: Option<Box<Expression>>,
13847    #[serde(default)]
13848    pub key: Option<Box<Expression>>,
13849    #[serde(default)]
13850    pub permissive: Option<Box<Expression>>,
13851}
13852
13853/// ParseIp
13854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13855#[cfg_attr(feature = "bindings", derive(TS))]
13856pub struct ParseIp {
13857    pub this: Box<Expression>,
13858    #[serde(default)]
13859    pub type_: Option<Box<Expression>>,
13860    #[serde(default)]
13861    pub permissive: Option<Box<Expression>>,
13862}
13863
13864/// ParseTime
13865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13866#[cfg_attr(feature = "bindings", derive(TS))]
13867pub struct ParseTime {
13868    pub this: Box<Expression>,
13869    pub format: String,
13870}
13871
13872/// ParseDatetime
13873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13874#[cfg_attr(feature = "bindings", derive(TS))]
13875pub struct ParseDatetime {
13876    pub this: Box<Expression>,
13877    #[serde(default)]
13878    pub format: Option<String>,
13879    #[serde(default)]
13880    pub zone: Option<Box<Expression>>,
13881}
13882
13883/// Map
13884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13885#[cfg_attr(feature = "bindings", derive(TS))]
13886pub struct Map {
13887    #[serde(default)]
13888    pub keys: Vec<Expression>,
13889    #[serde(default)]
13890    pub values: Vec<Expression>,
13891}
13892
13893/// MapCat
13894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13895#[cfg_attr(feature = "bindings", derive(TS))]
13896pub struct MapCat {
13897    pub this: Box<Expression>,
13898    pub expression: Box<Expression>,
13899}
13900
13901/// MapDelete
13902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13903#[cfg_attr(feature = "bindings", derive(TS))]
13904pub struct MapDelete {
13905    pub this: Box<Expression>,
13906    #[serde(default)]
13907    pub expressions: Vec<Expression>,
13908}
13909
13910/// MapInsert
13911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13912#[cfg_attr(feature = "bindings", derive(TS))]
13913pub struct MapInsert {
13914    pub this: Box<Expression>,
13915    #[serde(default)]
13916    pub key: Option<Box<Expression>>,
13917    #[serde(default)]
13918    pub value: Option<Box<Expression>>,
13919    #[serde(default)]
13920    pub update_flag: Option<Box<Expression>>,
13921}
13922
13923/// MapPick
13924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13925#[cfg_attr(feature = "bindings", derive(TS))]
13926pub struct MapPick {
13927    pub this: Box<Expression>,
13928    #[serde(default)]
13929    pub expressions: Vec<Expression>,
13930}
13931
13932/// ScopeResolution
13933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13934#[cfg_attr(feature = "bindings", derive(TS))]
13935pub struct ScopeResolution {
13936    #[serde(default)]
13937    pub this: Option<Box<Expression>>,
13938    pub expression: Box<Expression>,
13939}
13940
13941/// Slice
13942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13943#[cfg_attr(feature = "bindings", derive(TS))]
13944pub struct Slice {
13945    #[serde(default)]
13946    pub this: Option<Box<Expression>>,
13947    #[serde(default)]
13948    pub expression: Option<Box<Expression>>,
13949    #[serde(default)]
13950    pub step: Option<Box<Expression>>,
13951}
13952
13953/// VarMap
13954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13955#[cfg_attr(feature = "bindings", derive(TS))]
13956pub struct VarMap {
13957    #[serde(default)]
13958    pub keys: Vec<Expression>,
13959    #[serde(default)]
13960    pub values: Vec<Expression>,
13961}
13962
13963/// MatchAgainst
13964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13965#[cfg_attr(feature = "bindings", derive(TS))]
13966pub struct MatchAgainst {
13967    pub this: Box<Expression>,
13968    #[serde(default)]
13969    pub expressions: Vec<Expression>,
13970    #[serde(default)]
13971    pub modifier: Option<Box<Expression>>,
13972}
13973
13974/// MD5Digest
13975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13976#[cfg_attr(feature = "bindings", derive(TS))]
13977pub struct MD5Digest {
13978    pub this: Box<Expression>,
13979    #[serde(default)]
13980    pub expressions: Vec<Expression>,
13981}
13982
13983/// Monthname
13984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13985#[cfg_attr(feature = "bindings", derive(TS))]
13986pub struct Monthname {
13987    pub this: Box<Expression>,
13988    #[serde(default)]
13989    pub abbreviated: Option<Box<Expression>>,
13990}
13991
13992/// Ntile
13993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13994#[cfg_attr(feature = "bindings", derive(TS))]
13995pub struct Ntile {
13996    #[serde(default)]
13997    pub this: Option<Box<Expression>>,
13998}
13999
14000/// Normalize
14001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14002#[cfg_attr(feature = "bindings", derive(TS))]
14003pub struct Normalize {
14004    pub this: Box<Expression>,
14005    #[serde(default)]
14006    pub form: Option<Box<Expression>>,
14007    #[serde(default)]
14008    pub is_casefold: Option<Box<Expression>>,
14009}
14010
14011/// Normal
14012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14013#[cfg_attr(feature = "bindings", derive(TS))]
14014pub struct Normal {
14015    pub this: Box<Expression>,
14016    #[serde(default)]
14017    pub stddev: Option<Box<Expression>>,
14018    #[serde(default)]
14019    pub gen: Option<Box<Expression>>,
14020}
14021
14022/// Predict
14023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14024#[cfg_attr(feature = "bindings", derive(TS))]
14025pub struct Predict {
14026    pub this: Box<Expression>,
14027    pub expression: Box<Expression>,
14028    #[serde(default)]
14029    pub params_struct: Option<Box<Expression>>,
14030}
14031
14032/// MLTranslate
14033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14034#[cfg_attr(feature = "bindings", derive(TS))]
14035pub struct MLTranslate {
14036    pub this: Box<Expression>,
14037    pub expression: Box<Expression>,
14038    #[serde(default)]
14039    pub params_struct: Option<Box<Expression>>,
14040}
14041
14042/// FeaturesAtTime
14043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14044#[cfg_attr(feature = "bindings", derive(TS))]
14045pub struct FeaturesAtTime {
14046    pub this: Box<Expression>,
14047    #[serde(default)]
14048    pub time: Option<Box<Expression>>,
14049    #[serde(default)]
14050    pub num_rows: Option<Box<Expression>>,
14051    #[serde(default)]
14052    pub ignore_feature_nulls: Option<Box<Expression>>,
14053}
14054
14055/// GenerateEmbedding
14056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14057#[cfg_attr(feature = "bindings", derive(TS))]
14058pub struct GenerateEmbedding {
14059    pub this: Box<Expression>,
14060    pub expression: Box<Expression>,
14061    #[serde(default)]
14062    pub params_struct: Option<Box<Expression>>,
14063    #[serde(default)]
14064    pub is_text: Option<Box<Expression>>,
14065}
14066
14067/// MLForecast
14068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14069#[cfg_attr(feature = "bindings", derive(TS))]
14070pub struct MLForecast {
14071    pub this: Box<Expression>,
14072    #[serde(default)]
14073    pub expression: Option<Box<Expression>>,
14074    #[serde(default)]
14075    pub params_struct: Option<Box<Expression>>,
14076}
14077
14078/// ModelAttribute
14079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14080#[cfg_attr(feature = "bindings", derive(TS))]
14081pub struct ModelAttribute {
14082    pub this: Box<Expression>,
14083    pub expression: Box<Expression>,
14084}
14085
14086/// VectorSearch
14087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14088#[cfg_attr(feature = "bindings", derive(TS))]
14089pub struct VectorSearch {
14090    pub this: Box<Expression>,
14091    #[serde(default)]
14092    pub column_to_search: Option<Box<Expression>>,
14093    #[serde(default)]
14094    pub query_table: Option<Box<Expression>>,
14095    #[serde(default)]
14096    pub query_column_to_search: Option<Box<Expression>>,
14097    #[serde(default)]
14098    pub top_k: Option<Box<Expression>>,
14099    #[serde(default)]
14100    pub distance_type: Option<Box<Expression>>,
14101    #[serde(default)]
14102    pub options: Vec<Expression>,
14103}
14104
14105/// Quantile
14106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14107#[cfg_attr(feature = "bindings", derive(TS))]
14108pub struct Quantile {
14109    pub this: Box<Expression>,
14110    #[serde(default)]
14111    pub quantile: Option<Box<Expression>>,
14112}
14113
14114/// ApproxQuantile
14115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14116#[cfg_attr(feature = "bindings", derive(TS))]
14117pub struct ApproxQuantile {
14118    pub this: Box<Expression>,
14119    #[serde(default)]
14120    pub quantile: Option<Box<Expression>>,
14121    #[serde(default)]
14122    pub accuracy: Option<Box<Expression>>,
14123    #[serde(default)]
14124    pub weight: Option<Box<Expression>>,
14125    #[serde(default)]
14126    pub error_tolerance: Option<Box<Expression>>,
14127}
14128
14129/// ApproxPercentileEstimate
14130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14131#[cfg_attr(feature = "bindings", derive(TS))]
14132pub struct ApproxPercentileEstimate {
14133    pub this: Box<Expression>,
14134    #[serde(default)]
14135    pub percentile: Option<Box<Expression>>,
14136}
14137
14138/// Randn
14139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14140#[cfg_attr(feature = "bindings", derive(TS))]
14141pub struct Randn {
14142    #[serde(default)]
14143    pub this: Option<Box<Expression>>,
14144}
14145
14146/// Randstr
14147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14148#[cfg_attr(feature = "bindings", derive(TS))]
14149pub struct Randstr {
14150    pub this: Box<Expression>,
14151    #[serde(default)]
14152    pub generator: Option<Box<Expression>>,
14153}
14154
14155/// RangeN
14156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14157#[cfg_attr(feature = "bindings", derive(TS))]
14158pub struct RangeN {
14159    pub this: Box<Expression>,
14160    #[serde(default)]
14161    pub expressions: Vec<Expression>,
14162    #[serde(default)]
14163    pub each: Option<Box<Expression>>,
14164}
14165
14166/// RangeBucket
14167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14168#[cfg_attr(feature = "bindings", derive(TS))]
14169pub struct RangeBucket {
14170    pub this: Box<Expression>,
14171    pub expression: Box<Expression>,
14172}
14173
14174/// ReadCSV
14175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14176#[cfg_attr(feature = "bindings", derive(TS))]
14177pub struct ReadCSV {
14178    pub this: Box<Expression>,
14179    #[serde(default)]
14180    pub expressions: Vec<Expression>,
14181}
14182
14183/// ReadParquet
14184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14185#[cfg_attr(feature = "bindings", derive(TS))]
14186pub struct ReadParquet {
14187    #[serde(default)]
14188    pub expressions: Vec<Expression>,
14189}
14190
14191/// Reduce
14192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14193#[cfg_attr(feature = "bindings", derive(TS))]
14194pub struct Reduce {
14195    pub this: Box<Expression>,
14196    #[serde(default)]
14197    pub initial: Option<Box<Expression>>,
14198    #[serde(default)]
14199    pub merge: Option<Box<Expression>>,
14200    #[serde(default)]
14201    pub finish: Option<Box<Expression>>,
14202}
14203
14204/// RegexpExtractAll
14205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14206#[cfg_attr(feature = "bindings", derive(TS))]
14207pub struct RegexpExtractAll {
14208    pub this: Box<Expression>,
14209    pub expression: Box<Expression>,
14210    #[serde(default)]
14211    pub group: Option<Box<Expression>>,
14212    #[serde(default)]
14213    pub parameters: Option<Box<Expression>>,
14214    #[serde(default)]
14215    pub position: Option<Box<Expression>>,
14216    #[serde(default)]
14217    pub occurrence: Option<Box<Expression>>,
14218}
14219
14220/// RegexpILike
14221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14222#[cfg_attr(feature = "bindings", derive(TS))]
14223pub struct RegexpILike {
14224    pub this: Box<Expression>,
14225    pub expression: Box<Expression>,
14226    #[serde(default)]
14227    pub flag: Option<Box<Expression>>,
14228}
14229
14230/// RegexpFullMatch
14231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14232#[cfg_attr(feature = "bindings", derive(TS))]
14233pub struct RegexpFullMatch {
14234    pub this: Box<Expression>,
14235    pub expression: Box<Expression>,
14236    #[serde(default)]
14237    pub options: Vec<Expression>,
14238}
14239
14240/// RegexpInstr
14241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14242#[cfg_attr(feature = "bindings", derive(TS))]
14243pub struct RegexpInstr {
14244    pub this: Box<Expression>,
14245    pub expression: Box<Expression>,
14246    #[serde(default)]
14247    pub position: Option<Box<Expression>>,
14248    #[serde(default)]
14249    pub occurrence: Option<Box<Expression>>,
14250    #[serde(default)]
14251    pub option: Option<Box<Expression>>,
14252    #[serde(default)]
14253    pub parameters: Option<Box<Expression>>,
14254    #[serde(default)]
14255    pub group: Option<Box<Expression>>,
14256}
14257
14258/// RegexpSplit
14259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14260#[cfg_attr(feature = "bindings", derive(TS))]
14261pub struct RegexpSplit {
14262    pub this: Box<Expression>,
14263    pub expression: Box<Expression>,
14264    #[serde(default)]
14265    pub limit: Option<Box<Expression>>,
14266}
14267
14268/// RegexpCount
14269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14270#[cfg_attr(feature = "bindings", derive(TS))]
14271pub struct RegexpCount {
14272    pub this: Box<Expression>,
14273    pub expression: Box<Expression>,
14274    #[serde(default)]
14275    pub position: Option<Box<Expression>>,
14276    #[serde(default)]
14277    pub parameters: Option<Box<Expression>>,
14278}
14279
14280/// RegrValx
14281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14282#[cfg_attr(feature = "bindings", derive(TS))]
14283pub struct RegrValx {
14284    pub this: Box<Expression>,
14285    pub expression: Box<Expression>,
14286}
14287
14288/// RegrValy
14289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14290#[cfg_attr(feature = "bindings", derive(TS))]
14291pub struct RegrValy {
14292    pub this: Box<Expression>,
14293    pub expression: Box<Expression>,
14294}
14295
14296/// RegrAvgy
14297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14298#[cfg_attr(feature = "bindings", derive(TS))]
14299pub struct RegrAvgy {
14300    pub this: Box<Expression>,
14301    pub expression: Box<Expression>,
14302}
14303
14304/// RegrAvgx
14305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14306#[cfg_attr(feature = "bindings", derive(TS))]
14307pub struct RegrAvgx {
14308    pub this: Box<Expression>,
14309    pub expression: Box<Expression>,
14310}
14311
14312/// RegrCount
14313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14314#[cfg_attr(feature = "bindings", derive(TS))]
14315pub struct RegrCount {
14316    pub this: Box<Expression>,
14317    pub expression: Box<Expression>,
14318}
14319
14320/// RegrIntercept
14321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14322#[cfg_attr(feature = "bindings", derive(TS))]
14323pub struct RegrIntercept {
14324    pub this: Box<Expression>,
14325    pub expression: Box<Expression>,
14326}
14327
14328/// RegrR2
14329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14330#[cfg_attr(feature = "bindings", derive(TS))]
14331pub struct RegrR2 {
14332    pub this: Box<Expression>,
14333    pub expression: Box<Expression>,
14334}
14335
14336/// RegrSxx
14337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14338#[cfg_attr(feature = "bindings", derive(TS))]
14339pub struct RegrSxx {
14340    pub this: Box<Expression>,
14341    pub expression: Box<Expression>,
14342}
14343
14344/// RegrSxy
14345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14346#[cfg_attr(feature = "bindings", derive(TS))]
14347pub struct RegrSxy {
14348    pub this: Box<Expression>,
14349    pub expression: Box<Expression>,
14350}
14351
14352/// RegrSyy
14353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14354#[cfg_attr(feature = "bindings", derive(TS))]
14355pub struct RegrSyy {
14356    pub this: Box<Expression>,
14357    pub expression: Box<Expression>,
14358}
14359
14360/// RegrSlope
14361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14362#[cfg_attr(feature = "bindings", derive(TS))]
14363pub struct RegrSlope {
14364    pub this: Box<Expression>,
14365    pub expression: Box<Expression>,
14366}
14367
14368/// SafeAdd
14369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14370#[cfg_attr(feature = "bindings", derive(TS))]
14371pub struct SafeAdd {
14372    pub this: Box<Expression>,
14373    pub expression: Box<Expression>,
14374}
14375
14376/// SafeDivide
14377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14378#[cfg_attr(feature = "bindings", derive(TS))]
14379pub struct SafeDivide {
14380    pub this: Box<Expression>,
14381    pub expression: Box<Expression>,
14382}
14383
14384/// SafeMultiply
14385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14386#[cfg_attr(feature = "bindings", derive(TS))]
14387pub struct SafeMultiply {
14388    pub this: Box<Expression>,
14389    pub expression: Box<Expression>,
14390}
14391
14392/// SafeSubtract
14393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14394#[cfg_attr(feature = "bindings", derive(TS))]
14395pub struct SafeSubtract {
14396    pub this: Box<Expression>,
14397    pub expression: Box<Expression>,
14398}
14399
14400/// SHA2
14401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14402#[cfg_attr(feature = "bindings", derive(TS))]
14403pub struct SHA2 {
14404    pub this: Box<Expression>,
14405    #[serde(default)]
14406    pub length: Option<i64>,
14407}
14408
14409/// SHA2Digest
14410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14411#[cfg_attr(feature = "bindings", derive(TS))]
14412pub struct SHA2Digest {
14413    pub this: Box<Expression>,
14414    #[serde(default)]
14415    pub length: Option<i64>,
14416}
14417
14418/// SortArray
14419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14420#[cfg_attr(feature = "bindings", derive(TS))]
14421pub struct SortArray {
14422    pub this: Box<Expression>,
14423    #[serde(default)]
14424    pub asc: Option<Box<Expression>>,
14425    #[serde(default)]
14426    pub nulls_first: Option<Box<Expression>>,
14427}
14428
14429/// SplitPart
14430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14431#[cfg_attr(feature = "bindings", derive(TS))]
14432pub struct SplitPart {
14433    pub this: Box<Expression>,
14434    #[serde(default)]
14435    pub delimiter: Option<Box<Expression>>,
14436    #[serde(default)]
14437    pub part_index: Option<Box<Expression>>,
14438}
14439
14440/// SUBSTRING_INDEX(str, delim, count)
14441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14442#[cfg_attr(feature = "bindings", derive(TS))]
14443pub struct SubstringIndex {
14444    pub this: Box<Expression>,
14445    #[serde(default)]
14446    pub delimiter: Option<Box<Expression>>,
14447    #[serde(default)]
14448    pub count: Option<Box<Expression>>,
14449}
14450
14451/// StandardHash
14452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14453#[cfg_attr(feature = "bindings", derive(TS))]
14454pub struct StandardHash {
14455    pub this: Box<Expression>,
14456    #[serde(default)]
14457    pub expression: Option<Box<Expression>>,
14458}
14459
14460/// StrPosition
14461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14462#[cfg_attr(feature = "bindings", derive(TS))]
14463pub struct StrPosition {
14464    pub this: Box<Expression>,
14465    #[serde(default)]
14466    pub substr: Option<Box<Expression>>,
14467    #[serde(default)]
14468    pub position: Option<Box<Expression>>,
14469    #[serde(default)]
14470    pub occurrence: Option<Box<Expression>>,
14471}
14472
14473/// Search
14474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14475#[cfg_attr(feature = "bindings", derive(TS))]
14476pub struct Search {
14477    pub this: Box<Expression>,
14478    pub expression: Box<Expression>,
14479    #[serde(default)]
14480    pub json_scope: Option<Box<Expression>>,
14481    #[serde(default)]
14482    pub analyzer: Option<Box<Expression>>,
14483    #[serde(default)]
14484    pub analyzer_options: Option<Box<Expression>>,
14485    #[serde(default)]
14486    pub search_mode: Option<Box<Expression>>,
14487}
14488
14489/// SearchIp
14490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14491#[cfg_attr(feature = "bindings", derive(TS))]
14492pub struct SearchIp {
14493    pub this: Box<Expression>,
14494    pub expression: Box<Expression>,
14495}
14496
14497/// StrToDate
14498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14499#[cfg_attr(feature = "bindings", derive(TS))]
14500pub struct StrToDate {
14501    pub this: Box<Expression>,
14502    #[serde(default)]
14503    pub format: Option<String>,
14504    #[serde(default)]
14505    pub safe: Option<Box<Expression>>,
14506}
14507
14508/// StrToTime
14509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14510#[cfg_attr(feature = "bindings", derive(TS))]
14511pub struct StrToTime {
14512    pub this: Box<Expression>,
14513    pub format: String,
14514    #[serde(default)]
14515    pub zone: Option<Box<Expression>>,
14516    #[serde(default)]
14517    pub safe: Option<Box<Expression>>,
14518    #[serde(default)]
14519    pub target_type: Option<Box<Expression>>,
14520}
14521
14522/// StrToUnix
14523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14524#[cfg_attr(feature = "bindings", derive(TS))]
14525pub struct StrToUnix {
14526    #[serde(default)]
14527    pub this: Option<Box<Expression>>,
14528    #[serde(default)]
14529    pub format: Option<String>,
14530}
14531
14532/// StrToMap
14533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14534#[cfg_attr(feature = "bindings", derive(TS))]
14535pub struct StrToMap {
14536    pub this: Box<Expression>,
14537    #[serde(default)]
14538    pub pair_delim: Option<Box<Expression>>,
14539    #[serde(default)]
14540    pub key_value_delim: Option<Box<Expression>>,
14541    #[serde(default)]
14542    pub duplicate_resolution_callback: Option<Box<Expression>>,
14543}
14544
14545/// NumberToStr
14546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14547#[cfg_attr(feature = "bindings", derive(TS))]
14548pub struct NumberToStr {
14549    pub this: Box<Expression>,
14550    pub format: String,
14551    #[serde(default)]
14552    pub culture: Option<Box<Expression>>,
14553}
14554
14555/// FromBase
14556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14557#[cfg_attr(feature = "bindings", derive(TS))]
14558pub struct FromBase {
14559    pub this: Box<Expression>,
14560    pub expression: Box<Expression>,
14561}
14562
14563/// Stuff
14564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14565#[cfg_attr(feature = "bindings", derive(TS))]
14566pub struct Stuff {
14567    pub this: Box<Expression>,
14568    #[serde(default)]
14569    pub start: Option<Box<Expression>>,
14570    #[serde(default)]
14571    pub length: Option<i64>,
14572    pub expression: Box<Expression>,
14573}
14574
14575/// TimeToStr
14576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14577#[cfg_attr(feature = "bindings", derive(TS))]
14578pub struct TimeToStr {
14579    pub this: Box<Expression>,
14580    pub format: String,
14581    #[serde(default)]
14582    pub culture: Option<Box<Expression>>,
14583    #[serde(default)]
14584    pub zone: Option<Box<Expression>>,
14585}
14586
14587/// TimeStrToTime
14588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14589#[cfg_attr(feature = "bindings", derive(TS))]
14590pub struct TimeStrToTime {
14591    pub this: Box<Expression>,
14592    #[serde(default)]
14593    pub zone: Option<Box<Expression>>,
14594}
14595
14596/// TsOrDsAdd
14597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14598#[cfg_attr(feature = "bindings", derive(TS))]
14599pub struct TsOrDsAdd {
14600    pub this: Box<Expression>,
14601    pub expression: Box<Expression>,
14602    #[serde(default)]
14603    pub unit: Option<String>,
14604    #[serde(default)]
14605    pub return_type: Option<Box<Expression>>,
14606}
14607
14608/// TsOrDsDiff
14609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14610#[cfg_attr(feature = "bindings", derive(TS))]
14611pub struct TsOrDsDiff {
14612    pub this: Box<Expression>,
14613    pub expression: Box<Expression>,
14614    #[serde(default)]
14615    pub unit: Option<String>,
14616}
14617
14618/// TsOrDsToDate
14619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14620#[cfg_attr(feature = "bindings", derive(TS))]
14621pub struct TsOrDsToDate {
14622    pub this: Box<Expression>,
14623    #[serde(default)]
14624    pub format: Option<String>,
14625    #[serde(default)]
14626    pub safe: Option<Box<Expression>>,
14627}
14628
14629/// TsOrDsToTime
14630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14631#[cfg_attr(feature = "bindings", derive(TS))]
14632pub struct TsOrDsToTime {
14633    pub this: Box<Expression>,
14634    #[serde(default)]
14635    pub format: Option<String>,
14636    #[serde(default)]
14637    pub safe: Option<Box<Expression>>,
14638}
14639
14640/// Unhex
14641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14642#[cfg_attr(feature = "bindings", derive(TS))]
14643pub struct Unhex {
14644    pub this: Box<Expression>,
14645    #[serde(default)]
14646    pub expression: Option<Box<Expression>>,
14647}
14648
14649/// Uniform
14650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14651#[cfg_attr(feature = "bindings", derive(TS))]
14652pub struct Uniform {
14653    pub this: Box<Expression>,
14654    pub expression: Box<Expression>,
14655    #[serde(default)]
14656    pub gen: Option<Box<Expression>>,
14657    #[serde(default)]
14658    pub seed: Option<Box<Expression>>,
14659}
14660
14661/// UnixToStr
14662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14663#[cfg_attr(feature = "bindings", derive(TS))]
14664pub struct UnixToStr {
14665    pub this: Box<Expression>,
14666    #[serde(default)]
14667    pub format: Option<String>,
14668}
14669
14670/// UnixToTime
14671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14672#[cfg_attr(feature = "bindings", derive(TS))]
14673pub struct UnixToTime {
14674    pub this: Box<Expression>,
14675    #[serde(default)]
14676    pub scale: Option<i64>,
14677    #[serde(default)]
14678    pub zone: Option<Box<Expression>>,
14679    #[serde(default)]
14680    pub hours: Option<Box<Expression>>,
14681    #[serde(default)]
14682    pub minutes: Option<Box<Expression>>,
14683    #[serde(default)]
14684    pub format: Option<String>,
14685    #[serde(default)]
14686    pub target_type: Option<Box<Expression>>,
14687}
14688
14689/// Uuid
14690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14691#[cfg_attr(feature = "bindings", derive(TS))]
14692pub struct Uuid {
14693    #[serde(default)]
14694    pub this: Option<Box<Expression>>,
14695    #[serde(default)]
14696    pub name: Option<String>,
14697    #[serde(default)]
14698    pub is_string: Option<Box<Expression>>,
14699}
14700
14701/// TimestampFromParts
14702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14703#[cfg_attr(feature = "bindings", derive(TS))]
14704pub struct TimestampFromParts {
14705    #[serde(default)]
14706    pub zone: Option<Box<Expression>>,
14707    #[serde(default)]
14708    pub milli: Option<Box<Expression>>,
14709    #[serde(default)]
14710    pub this: Option<Box<Expression>>,
14711    #[serde(default)]
14712    pub expression: Option<Box<Expression>>,
14713}
14714
14715/// TimestampTzFromParts
14716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14717#[cfg_attr(feature = "bindings", derive(TS))]
14718pub struct TimestampTzFromParts {
14719    #[serde(default)]
14720    pub zone: Option<Box<Expression>>,
14721}
14722
14723/// Corr
14724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14725#[cfg_attr(feature = "bindings", derive(TS))]
14726pub struct Corr {
14727    pub this: Box<Expression>,
14728    pub expression: Box<Expression>,
14729    #[serde(default)]
14730    pub null_on_zero_variance: Option<Box<Expression>>,
14731}
14732
14733/// WidthBucket
14734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14735#[cfg_attr(feature = "bindings", derive(TS))]
14736pub struct WidthBucket {
14737    pub this: Box<Expression>,
14738    #[serde(default)]
14739    pub min_value: Option<Box<Expression>>,
14740    #[serde(default)]
14741    pub max_value: Option<Box<Expression>>,
14742    #[serde(default)]
14743    pub num_buckets: Option<Box<Expression>>,
14744    #[serde(default)]
14745    pub threshold: Option<Box<Expression>>,
14746}
14747
14748/// CovarSamp
14749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14750#[cfg_attr(feature = "bindings", derive(TS))]
14751pub struct CovarSamp {
14752    pub this: Box<Expression>,
14753    pub expression: Box<Expression>,
14754}
14755
14756/// CovarPop
14757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14758#[cfg_attr(feature = "bindings", derive(TS))]
14759pub struct CovarPop {
14760    pub this: Box<Expression>,
14761    pub expression: Box<Expression>,
14762}
14763
14764/// Week
14765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14766#[cfg_attr(feature = "bindings", derive(TS))]
14767pub struct Week {
14768    pub this: Box<Expression>,
14769    #[serde(default)]
14770    pub mode: Option<Box<Expression>>,
14771}
14772
14773/// XMLElement
14774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14775#[cfg_attr(feature = "bindings", derive(TS))]
14776pub struct XMLElement {
14777    pub this: Box<Expression>,
14778    #[serde(default)]
14779    pub expressions: Vec<Expression>,
14780    #[serde(default)]
14781    pub evalname: Option<Box<Expression>>,
14782}
14783
14784/// XMLGet
14785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14786#[cfg_attr(feature = "bindings", derive(TS))]
14787pub struct XMLGet {
14788    pub this: Box<Expression>,
14789    pub expression: Box<Expression>,
14790    #[serde(default)]
14791    pub instance: Option<Box<Expression>>,
14792}
14793
14794/// XMLTable
14795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14796#[cfg_attr(feature = "bindings", derive(TS))]
14797pub struct XMLTable {
14798    pub this: Box<Expression>,
14799    #[serde(default)]
14800    pub namespaces: Option<Box<Expression>>,
14801    #[serde(default)]
14802    pub passing: Option<Box<Expression>>,
14803    #[serde(default)]
14804    pub columns: Vec<Expression>,
14805    #[serde(default)]
14806    pub by_ref: Option<Box<Expression>>,
14807}
14808
14809/// XMLKeyValueOption
14810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14811#[cfg_attr(feature = "bindings", derive(TS))]
14812pub struct XMLKeyValueOption {
14813    pub this: Box<Expression>,
14814    #[serde(default)]
14815    pub expression: Option<Box<Expression>>,
14816}
14817
14818/// Zipf
14819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14820#[cfg_attr(feature = "bindings", derive(TS))]
14821pub struct Zipf {
14822    pub this: Box<Expression>,
14823    #[serde(default)]
14824    pub elementcount: Option<Box<Expression>>,
14825    #[serde(default)]
14826    pub gen: Option<Box<Expression>>,
14827}
14828
14829/// Merge
14830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14831#[cfg_attr(feature = "bindings", derive(TS))]
14832pub struct Merge {
14833    pub this: Box<Expression>,
14834    pub using: Box<Expression>,
14835    #[serde(default)]
14836    pub on: Option<Box<Expression>>,
14837    #[serde(default)]
14838    pub using_cond: Option<Box<Expression>>,
14839    #[serde(default)]
14840    pub whens: Option<Box<Expression>>,
14841    #[serde(default)]
14842    pub with_: Option<Box<Expression>>,
14843    #[serde(default)]
14844    pub returning: Option<Box<Expression>>,
14845}
14846
14847/// When
14848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14849#[cfg_attr(feature = "bindings", derive(TS))]
14850pub struct When {
14851    #[serde(default)]
14852    pub matched: Option<Box<Expression>>,
14853    #[serde(default)]
14854    pub source: Option<Box<Expression>>,
14855    #[serde(default)]
14856    pub condition: Option<Box<Expression>>,
14857    pub then: Box<Expression>,
14858}
14859
14860/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
14861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14862#[cfg_attr(feature = "bindings", derive(TS))]
14863pub struct Whens {
14864    #[serde(default)]
14865    pub expressions: Vec<Expression>,
14866}
14867
14868/// NextValueFor
14869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14870#[cfg_attr(feature = "bindings", derive(TS))]
14871pub struct NextValueFor {
14872    pub this: Box<Expression>,
14873    #[serde(default)]
14874    pub order: Option<Box<Expression>>,
14875}
14876
14877#[cfg(test)]
14878mod tests {
14879    use super::*;
14880
14881    #[test]
14882    #[cfg(feature = "bindings")]
14883    fn export_typescript_types() {
14884        // This test exports TypeScript types to the generated directory
14885        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
14886        Expression::export_all(&ts_rs::Config::default())
14887            .expect("Failed to export Expression types");
14888    }
14889
14890    #[test]
14891    fn test_simple_select_builder() {
14892        let select = Select::new()
14893            .column(Expression::star())
14894            .from(Expression::Table(Box::new(TableRef::new("users"))));
14895
14896        assert_eq!(select.expressions.len(), 1);
14897        assert!(select.from.is_some());
14898    }
14899
14900    #[test]
14901    fn test_expression_alias() {
14902        let expr = Expression::column("id").alias("user_id");
14903
14904        match expr {
14905            Expression::Alias(a) => {
14906                assert_eq!(a.alias.name, "user_id");
14907            }
14908            _ => panic!("Expected Alias"),
14909        }
14910    }
14911
14912    #[test]
14913    fn test_literal_creation() {
14914        let num = Expression::number(42);
14915        let str = Expression::string("hello");
14916
14917        match num {
14918            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::Number(_)) => {
14919                let Literal::Number(n) = lit.as_ref() else {
14920                    unreachable!()
14921                };
14922                assert_eq!(n, "42")
14923            }
14924            _ => panic!("Expected Number"),
14925        }
14926
14927        match str {
14928            Expression::Literal(lit) if matches!(lit.as_ref(), Literal::String(_)) => {
14929                let Literal::String(s) = lit.as_ref() else {
14930                    unreachable!()
14931                };
14932                assert_eq!(s, "hello")
14933            }
14934            _ => panic!("Expected String"),
14935        }
14936    }
14937
14938    #[test]
14939    fn test_expression_sql() {
14940        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
14941        assert_eq!(expr.sql(), "SELECT 1 + 2");
14942    }
14943
14944    #[test]
14945    fn test_expression_sql_for() {
14946        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
14947        let sql = expr.sql_for(crate::DialectType::Generic);
14948        // Generic mode normalizes IF() to CASE WHEN
14949        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
14950    }
14951}