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