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