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(Literal),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Column),
89    Table(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    // JSON functions
486    JsonExtract(Box<JsonExtractFunc>),
487    JsonExtractScalar(Box<JsonExtractFunc>),
488    JsonExtractPath(Box<JsonPathFunc>),
489    JsonArray(Box<VarArgFunc>),
490    JsonObject(Box<JsonObjectFunc>),
491    JsonQuery(Box<JsonExtractFunc>),
492    JsonValue(Box<JsonExtractFunc>),
493    JsonArrayLength(Box<UnaryFunc>),
494    JsonKeys(Box<UnaryFunc>),
495    JsonType(Box<UnaryFunc>),
496    ParseJson(Box<UnaryFunc>),
497    ToJson(Box<UnaryFunc>),
498    JsonSet(Box<JsonModifyFunc>),
499    JsonInsert(Box<JsonModifyFunc>),
500    JsonRemove(Box<JsonPathFunc>),
501    JsonMergePatch(Box<BinaryFunc>),
502    JsonArrayAgg(Box<JsonArrayAggFunc>),
503    JsonObjectAgg(Box<JsonObjectAggFunc>),
504
505    // Type casting/conversion
506    Convert(Box<ConvertFunc>),
507    Typeof(Box<UnaryFunc>),
508
509    // Additional expressions
510    Lambda(Box<LambdaExpr>),
511    Parameter(Box<Parameter>),
512    Placeholder(Placeholder),
513    NamedArgument(Box<NamedArgument>),
514    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
515    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
516    TableArgument(Box<TableArgument>),
517    SqlComment(Box<SqlComment>),
518
519    // Additional predicates
520    NullSafeEq(Box<BinaryOp>),
521    NullSafeNeq(Box<BinaryOp>),
522    Glob(Box<BinaryOp>),
523    SimilarTo(Box<SimilarToExpr>),
524    Any(Box<QuantifiedExpr>),
525    All(Box<QuantifiedExpr>),
526    Overlaps(Box<OverlapsExpr>),
527
528    // Bitwise operations
529    BitwiseLeftShift(Box<BinaryOp>),
530    BitwiseRightShift(Box<BinaryOp>),
531    BitwiseAndAgg(Box<AggFunc>),
532    BitwiseOrAgg(Box<AggFunc>),
533    BitwiseXorAgg(Box<AggFunc>),
534
535    // Array/struct/map access
536    Subscript(Box<Subscript>),
537    Dot(Box<DotAccess>),
538    MethodCall(Box<MethodCall>),
539    ArraySlice(Box<ArraySlice>),
540
541    // DDL statements
542    CreateTable(Box<CreateTable>),
543    DropTable(Box<DropTable>),
544    AlterTable(Box<AlterTable>),
545    CreateIndex(Box<CreateIndex>),
546    DropIndex(Box<DropIndex>),
547    CreateView(Box<CreateView>),
548    DropView(Box<DropView>),
549    AlterView(Box<AlterView>),
550    AlterIndex(Box<AlterIndex>),
551    Truncate(Box<Truncate>),
552    Use(Box<Use>),
553    Cache(Box<Cache>),
554    Uncache(Box<Uncache>),
555    LoadData(Box<LoadData>),
556    Pragma(Box<Pragma>),
557    Grant(Box<Grant>),
558    Revoke(Box<Revoke>),
559    Comment(Box<Comment>),
560    SetStatement(Box<SetStatement>),
561    // Phase 4: Additional DDL statements
562    CreateSchema(Box<CreateSchema>),
563    DropSchema(Box<DropSchema>),
564    DropNamespace(Box<DropNamespace>),
565    CreateDatabase(Box<CreateDatabase>),
566    DropDatabase(Box<DropDatabase>),
567    CreateFunction(Box<CreateFunction>),
568    DropFunction(Box<DropFunction>),
569    CreateProcedure(Box<CreateProcedure>),
570    DropProcedure(Box<DropProcedure>),
571    CreateSequence(Box<CreateSequence>),
572    DropSequence(Box<DropSequence>),
573    AlterSequence(Box<AlterSequence>),
574    CreateTrigger(Box<CreateTrigger>),
575    DropTrigger(Box<DropTrigger>),
576    CreateType(Box<CreateType>),
577    DropType(Box<DropType>),
578    Describe(Box<Describe>),
579    Show(Box<Show>),
580
581    // Transaction and other commands
582    Command(Box<Command>),
583    Kill(Box<Kill>),
584    /// EXEC/EXECUTE statement (TSQL stored procedure call)
585    Execute(Box<ExecuteStatement>),
586
587    // Placeholder for unparsed/raw SQL
588    Raw(Raw),
589
590    // Paren for grouping
591    Paren(Box<Paren>),
592
593    // Expression with trailing comments (for round-trip preservation)
594    Annotated(Box<Annotated>),
595
596    // === BATCH GENERATED EXPRESSION TYPES ===
597    // Generated from Python sqlglot expressions.py
598    Refresh(Box<Refresh>),
599    LockingStatement(Box<LockingStatement>),
600    SequenceProperties(Box<SequenceProperties>),
601    TruncateTable(Box<TruncateTable>),
602    Clone(Box<Clone>),
603    Attach(Box<Attach>),
604    Detach(Box<Detach>),
605    Install(Box<Install>),
606    Summarize(Box<Summarize>),
607    Declare(Box<Declare>),
608    DeclareItem(Box<DeclareItem>),
609    Set(Box<Set>),
610    Heredoc(Box<Heredoc>),
611    SetItem(Box<SetItem>),
612    QueryBand(Box<QueryBand>),
613    UserDefinedFunction(Box<UserDefinedFunction>),
614    RecursiveWithSearch(Box<RecursiveWithSearch>),
615    ProjectionDef(Box<ProjectionDef>),
616    TableAlias(Box<TableAlias>),
617    ByteString(Box<ByteString>),
618    HexStringExpr(Box<HexStringExpr>),
619    UnicodeString(Box<UnicodeString>),
620    ColumnPosition(Box<ColumnPosition>),
621    ColumnDef(Box<ColumnDef>),
622    AlterColumn(Box<AlterColumn>),
623    AlterSortKey(Box<AlterSortKey>),
624    AlterSet(Box<AlterSet>),
625    RenameColumn(Box<RenameColumn>),
626    Comprehension(Box<Comprehension>),
627    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
628    MergeTreeTTL(Box<MergeTreeTTL>),
629    IndexConstraintOption(Box<IndexConstraintOption>),
630    ColumnConstraint(Box<ColumnConstraint>),
631    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
632    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
633    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
634    CheckColumnConstraint(Box<CheckColumnConstraint>),
635    CompressColumnConstraint(Box<CompressColumnConstraint>),
636    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
637    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
638    WithOperator(Box<WithOperator>),
639    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
640    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
641    CommentColumnConstraint(CommentColumnConstraint),
642    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
643    IndexColumnConstraint(Box<IndexColumnConstraint>),
644    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
645    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
646    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
647    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
648    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
649    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
650    InOutColumnConstraint(Box<InOutColumnConstraint>),
651    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
652    PathColumnConstraint(Box<PathColumnConstraint>),
653    Constraint(Box<Constraint>),
654    Export(Box<Export>),
655    Filter(Box<Filter>),
656    Changes(Box<Changes>),
657    CopyParameter(Box<CopyParameter>),
658    Credentials(Box<Credentials>),
659    Directory(Box<Directory>),
660    ForeignKey(Box<ForeignKey>),
661    ColumnPrefix(Box<ColumnPrefix>),
662    PrimaryKey(Box<PrimaryKey>),
663    IntoClause(Box<IntoClause>),
664    JoinHint(Box<JoinHint>),
665    Opclass(Box<Opclass>),
666    Index(Box<Index>),
667    IndexParameters(Box<IndexParameters>),
668    ConditionalInsert(Box<ConditionalInsert>),
669    MultitableInserts(Box<MultitableInserts>),
670    OnConflict(Box<OnConflict>),
671    OnCondition(Box<OnCondition>),
672    Returning(Box<Returning>),
673    Introducer(Box<Introducer>),
674    PartitionRange(Box<PartitionRange>),
675    Fetch(Box<Fetch>),
676    Group(Box<Group>),
677    Cube(Box<Cube>),
678    Rollup(Box<Rollup>),
679    GroupingSets(Box<GroupingSets>),
680    LimitOptions(Box<LimitOptions>),
681    Lateral(Box<Lateral>),
682    TableFromRows(Box<TableFromRows>),
683    RowsFrom(Box<RowsFrom>),
684    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
685    WithFill(Box<WithFill>),
686    Property(Box<Property>),
687    GrantPrivilege(Box<GrantPrivilege>),
688    GrantPrincipal(Box<GrantPrincipal>),
689    AllowedValuesProperty(Box<AllowedValuesProperty>),
690    AlgorithmProperty(Box<AlgorithmProperty>),
691    AutoIncrementProperty(Box<AutoIncrementProperty>),
692    AutoRefreshProperty(Box<AutoRefreshProperty>),
693    BackupProperty(Box<BackupProperty>),
694    BuildProperty(Box<BuildProperty>),
695    BlockCompressionProperty(Box<BlockCompressionProperty>),
696    CharacterSetProperty(Box<CharacterSetProperty>),
697    ChecksumProperty(Box<ChecksumProperty>),
698    CollateProperty(Box<CollateProperty>),
699    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
700    DataDeletionProperty(Box<DataDeletionProperty>),
701    DefinerProperty(Box<DefinerProperty>),
702    DistKeyProperty(Box<DistKeyProperty>),
703    DistributedByProperty(Box<DistributedByProperty>),
704    DistStyleProperty(Box<DistStyleProperty>),
705    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
706    EngineProperty(Box<EngineProperty>),
707    ToTableProperty(Box<ToTableProperty>),
708    ExecuteAsProperty(Box<ExecuteAsProperty>),
709    ExternalProperty(Box<ExternalProperty>),
710    FallbackProperty(Box<FallbackProperty>),
711    FileFormatProperty(Box<FileFormatProperty>),
712    CredentialsProperty(Box<CredentialsProperty>),
713    FreespaceProperty(Box<FreespaceProperty>),
714    InheritsProperty(Box<InheritsProperty>),
715    InputModelProperty(Box<InputModelProperty>),
716    OutputModelProperty(Box<OutputModelProperty>),
717    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
718    JournalProperty(Box<JournalProperty>),
719    LanguageProperty(Box<LanguageProperty>),
720    EnviromentProperty(Box<EnviromentProperty>),
721    ClusteredByProperty(Box<ClusteredByProperty>),
722    DictProperty(Box<DictProperty>),
723    DictRange(Box<DictRange>),
724    OnCluster(Box<OnCluster>),
725    LikeProperty(Box<LikeProperty>),
726    LocationProperty(Box<LocationProperty>),
727    LockProperty(Box<LockProperty>),
728    LockingProperty(Box<LockingProperty>),
729    LogProperty(Box<LogProperty>),
730    MaterializedProperty(Box<MaterializedProperty>),
731    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
732    OnProperty(Box<OnProperty>),
733    OnCommitProperty(Box<OnCommitProperty>),
734    PartitionedByProperty(Box<PartitionedByProperty>),
735    PartitionByProperty(Box<PartitionByProperty>),
736    PartitionedByBucket(Box<PartitionedByBucket>),
737    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
738    PartitionByTruncate(Box<PartitionByTruncate>),
739    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
740    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
741    PartitionByListProperty(Box<PartitionByListProperty>),
742    PartitionList(Box<PartitionList>),
743    Partition(Box<Partition>),
744    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
745    UniqueKeyProperty(Box<UniqueKeyProperty>),
746    RollupProperty(Box<RollupProperty>),
747    PartitionBoundSpec(Box<PartitionBoundSpec>),
748    PartitionedOfProperty(Box<PartitionedOfProperty>),
749    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
750    ReturnsProperty(Box<ReturnsProperty>),
751    RowFormatProperty(Box<RowFormatProperty>),
752    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
753    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
754    QueryTransform(Box<QueryTransform>),
755    SampleProperty(Box<SampleProperty>),
756    SecurityProperty(Box<SecurityProperty>),
757    SchemaCommentProperty(Box<SchemaCommentProperty>),
758    SemanticView(Box<SemanticView>),
759    SerdeProperties(Box<SerdeProperties>),
760    SetProperty(Box<SetProperty>),
761    SharingProperty(Box<SharingProperty>),
762    SetConfigProperty(Box<SetConfigProperty>),
763    SettingsProperty(Box<SettingsProperty>),
764    SortKeyProperty(Box<SortKeyProperty>),
765    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
766    SqlSecurityProperty(Box<SqlSecurityProperty>),
767    StabilityProperty(Box<StabilityProperty>),
768    StorageHandlerProperty(Box<StorageHandlerProperty>),
769    TemporaryProperty(Box<TemporaryProperty>),
770    Tags(Box<Tags>),
771    TransformModelProperty(Box<TransformModelProperty>),
772    TransientProperty(Box<TransientProperty>),
773    UsingTemplateProperty(Box<UsingTemplateProperty>),
774    ViewAttributeProperty(Box<ViewAttributeProperty>),
775    VolatileProperty(Box<VolatileProperty>),
776    WithDataProperty(Box<WithDataProperty>),
777    WithJournalTableProperty(Box<WithJournalTableProperty>),
778    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
779    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
780    WithProcedureOptions(Box<WithProcedureOptions>),
781    EncodeProperty(Box<EncodeProperty>),
782    IncludeProperty(Box<IncludeProperty>),
783    Properties(Box<Properties>),
784    OptionsProperty(Box<OptionsProperty>),
785    InputOutputFormat(Box<InputOutputFormat>),
786    Reference(Box<Reference>),
787    QueryOption(Box<QueryOption>),
788    WithTableHint(Box<WithTableHint>),
789    IndexTableHint(Box<IndexTableHint>),
790    HistoricalData(Box<HistoricalData>),
791    Get(Box<Get>),
792    SetOperation(Box<SetOperation>),
793    Var(Box<Var>),
794    Variadic(Box<Variadic>),
795    Version(Box<Version>),
796    Schema(Box<Schema>),
797    Lock(Box<Lock>),
798    TableSample(Box<TableSample>),
799    Tag(Box<Tag>),
800    UnpivotColumns(Box<UnpivotColumns>),
801    WindowSpec(Box<WindowSpec>),
802    SessionParameter(Box<SessionParameter>),
803    PseudoType(Box<PseudoType>),
804    ObjectIdentifier(Box<ObjectIdentifier>),
805    Transaction(Box<Transaction>),
806    Commit(Box<Commit>),
807    Rollback(Box<Rollback>),
808    AlterSession(Box<AlterSession>),
809    Analyze(Box<Analyze>),
810    AnalyzeStatistics(Box<AnalyzeStatistics>),
811    AnalyzeHistogram(Box<AnalyzeHistogram>),
812    AnalyzeSample(Box<AnalyzeSample>),
813    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
814    AnalyzeDelete(Box<AnalyzeDelete>),
815    AnalyzeWith(Box<AnalyzeWith>),
816    AnalyzeValidate(Box<AnalyzeValidate>),
817    AddPartition(Box<AddPartition>),
818    AttachOption(Box<AttachOption>),
819    DropPartition(Box<DropPartition>),
820    ReplacePartition(Box<ReplacePartition>),
821    DPipe(Box<DPipe>),
822    Operator(Box<Operator>),
823    PivotAny(Box<PivotAny>),
824    Aliases(Box<Aliases>),
825    AtIndex(Box<AtIndex>),
826    FromTimeZone(Box<FromTimeZone>),
827    FormatPhrase(Box<FormatPhrase>),
828    ForIn(Box<ForIn>),
829    TimeUnit(Box<TimeUnit>),
830    IntervalOp(Box<IntervalOp>),
831    IntervalSpan(Box<IntervalSpan>),
832    HavingMax(Box<HavingMax>),
833    CosineDistance(Box<CosineDistance>),
834    DotProduct(Box<DotProduct>),
835    EuclideanDistance(Box<EuclideanDistance>),
836    ManhattanDistance(Box<ManhattanDistance>),
837    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
838    Booland(Box<Booland>),
839    Boolor(Box<Boolor>),
840    ParameterizedAgg(Box<ParameterizedAgg>),
841    ArgMax(Box<ArgMax>),
842    ArgMin(Box<ArgMin>),
843    ApproxTopK(Box<ApproxTopK>),
844    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
845    ApproxTopKCombine(Box<ApproxTopKCombine>),
846    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
847    ApproxTopSum(Box<ApproxTopSum>),
848    ApproxQuantiles(Box<ApproxQuantiles>),
849    Minhash(Box<Minhash>),
850    FarmFingerprint(Box<FarmFingerprint>),
851    Float64(Box<Float64>),
852    Transform(Box<Transform>),
853    Translate(Box<Translate>),
854    Grouping(Box<Grouping>),
855    GroupingId(Box<GroupingId>),
856    Anonymous(Box<Anonymous>),
857    AnonymousAggFunc(Box<AnonymousAggFunc>),
858    CombinedAggFunc(Box<CombinedAggFunc>),
859    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
860    HashAgg(Box<HashAgg>),
861    Hll(Box<Hll>),
862    Apply(Box<Apply>),
863    ToBoolean(Box<ToBoolean>),
864    List(Box<List>),
865    ToMap(Box<ToMap>),
866    Pad(Box<Pad>),
867    ToChar(Box<ToChar>),
868    ToNumber(Box<ToNumber>),
869    ToDouble(Box<ToDouble>),
870    Int64(Box<UnaryFunc>),
871    StringFunc(Box<StringFunc>),
872    ToDecfloat(Box<ToDecfloat>),
873    TryToDecfloat(Box<TryToDecfloat>),
874    ToFile(Box<ToFile>),
875    Columns(Box<Columns>),
876    ConvertToCharset(Box<ConvertToCharset>),
877    ConvertTimezone(Box<ConvertTimezone>),
878    GenerateSeries(Box<GenerateSeries>),
879    AIAgg(Box<AIAgg>),
880    AIClassify(Box<AIClassify>),
881    ArrayAll(Box<ArrayAll>),
882    ArrayAny(Box<ArrayAny>),
883    ArrayConstructCompact(Box<ArrayConstructCompact>),
884    StPoint(Box<StPoint>),
885    StDistance(Box<StDistance>),
886    StringToArray(Box<StringToArray>),
887    ArraySum(Box<ArraySum>),
888    ObjectAgg(Box<ObjectAgg>),
889    CastToStrType(Box<CastToStrType>),
890    CheckJson(Box<CheckJson>),
891    CheckXml(Box<CheckXml>),
892    TranslateCharacters(Box<TranslateCharacters>),
893    CurrentSchemas(Box<CurrentSchemas>),
894    CurrentDatetime(Box<CurrentDatetime>),
895    Localtime(Box<Localtime>),
896    Localtimestamp(Box<Localtimestamp>),
897    Systimestamp(Box<Systimestamp>),
898    CurrentSchema(Box<CurrentSchema>),
899    CurrentUser(Box<CurrentUser>),
900    UtcTime(Box<UtcTime>),
901    UtcTimestamp(Box<UtcTimestamp>),
902    Timestamp(Box<TimestampFunc>),
903    DateBin(Box<DateBin>),
904    Datetime(Box<Datetime>),
905    DatetimeAdd(Box<DatetimeAdd>),
906    DatetimeSub(Box<DatetimeSub>),
907    DatetimeDiff(Box<DatetimeDiff>),
908    DatetimeTrunc(Box<DatetimeTrunc>),
909    Dayname(Box<Dayname>),
910    MakeInterval(Box<MakeInterval>),
911    PreviousDay(Box<PreviousDay>),
912    Elt(Box<Elt>),
913    TimestampAdd(Box<TimestampAdd>),
914    TimestampSub(Box<TimestampSub>),
915    TimestampDiff(Box<TimestampDiff>),
916    TimeSlice(Box<TimeSlice>),
917    TimeAdd(Box<TimeAdd>),
918    TimeSub(Box<TimeSub>),
919    TimeDiff(Box<TimeDiff>),
920    TimeTrunc(Box<TimeTrunc>),
921    DateFromParts(Box<DateFromParts>),
922    TimeFromParts(Box<TimeFromParts>),
923    DecodeCase(Box<DecodeCase>),
924    Decrypt(Box<Decrypt>),
925    DecryptRaw(Box<DecryptRaw>),
926    Encode(Box<Encode>),
927    Encrypt(Box<Encrypt>),
928    EncryptRaw(Box<EncryptRaw>),
929    EqualNull(Box<EqualNull>),
930    ToBinary(Box<ToBinary>),
931    Base64DecodeBinary(Box<Base64DecodeBinary>),
932    Base64DecodeString(Box<Base64DecodeString>),
933    Base64Encode(Box<Base64Encode>),
934    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
935    TryBase64DecodeString(Box<TryBase64DecodeString>),
936    GapFill(Box<GapFill>),
937    GenerateDateArray(Box<GenerateDateArray>),
938    GenerateTimestampArray(Box<GenerateTimestampArray>),
939    GetExtract(Box<GetExtract>),
940    Getbit(Box<Getbit>),
941    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
942    HexEncode(Box<HexEncode>),
943    Compress(Box<Compress>),
944    DecompressBinary(Box<DecompressBinary>),
945    DecompressString(Box<DecompressString>),
946    Xor(Box<Xor>),
947    Nullif(Box<Nullif>),
948    JSON(Box<JSON>),
949    JSONPath(Box<JSONPath>),
950    JSONPathFilter(Box<JSONPathFilter>),
951    JSONPathKey(Box<JSONPathKey>),
952    JSONPathRecursive(Box<JSONPathRecursive>),
953    JSONPathScript(Box<JSONPathScript>),
954    JSONPathSlice(Box<JSONPathSlice>),
955    JSONPathSelector(Box<JSONPathSelector>),
956    JSONPathSubscript(Box<JSONPathSubscript>),
957    JSONPathUnion(Box<JSONPathUnion>),
958    Format(Box<Format>),
959    JSONKeys(Box<JSONKeys>),
960    JSONKeyValue(Box<JSONKeyValue>),
961    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
962    JSONObject(Box<JSONObject>),
963    JSONObjectAgg(Box<JSONObjectAgg>),
964    JSONBObjectAgg(Box<JSONBObjectAgg>),
965    JSONArray(Box<JSONArray>),
966    JSONArrayAgg(Box<JSONArrayAgg>),
967    JSONExists(Box<JSONExists>),
968    JSONColumnDef(Box<JSONColumnDef>),
969    JSONSchema(Box<JSONSchema>),
970    JSONSet(Box<JSONSet>),
971    JSONStripNulls(Box<JSONStripNulls>),
972    JSONValue(Box<JSONValue>),
973    JSONValueArray(Box<JSONValueArray>),
974    JSONRemove(Box<JSONRemove>),
975    JSONTable(Box<JSONTable>),
976    JSONType(Box<JSONType>),
977    ObjectInsert(Box<ObjectInsert>),
978    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
979    OpenJSON(Box<OpenJSON>),
980    JSONBExists(Box<JSONBExists>),
981    JSONBContains(Box<BinaryFunc>),
982    JSONBExtract(Box<BinaryFunc>),
983    JSONCast(Box<JSONCast>),
984    JSONExtract(Box<JSONExtract>),
985    JSONExtractQuote(Box<JSONExtractQuote>),
986    JSONExtractArray(Box<JSONExtractArray>),
987    JSONExtractScalar(Box<JSONExtractScalar>),
988    JSONBExtractScalar(Box<JSONBExtractScalar>),
989    JSONFormat(Box<JSONFormat>),
990    JSONBool(Box<UnaryFunc>),
991    JSONPathRoot(JSONPathRoot),
992    JSONArrayAppend(Box<JSONArrayAppend>),
993    JSONArrayContains(Box<JSONArrayContains>),
994    JSONArrayInsert(Box<JSONArrayInsert>),
995    ParseJSON(Box<ParseJSON>),
996    ParseUrl(Box<ParseUrl>),
997    ParseIp(Box<ParseIp>),
998    ParseTime(Box<ParseTime>),
999    ParseDatetime(Box<ParseDatetime>),
1000    Map(Box<Map>),
1001    MapCat(Box<MapCat>),
1002    MapDelete(Box<MapDelete>),
1003    MapInsert(Box<MapInsert>),
1004    MapPick(Box<MapPick>),
1005    ScopeResolution(Box<ScopeResolution>),
1006    Slice(Box<Slice>),
1007    VarMap(Box<VarMap>),
1008    MatchAgainst(Box<MatchAgainst>),
1009    MD5Digest(Box<MD5Digest>),
1010    MD5NumberLower64(Box<UnaryFunc>),
1011    MD5NumberUpper64(Box<UnaryFunc>),
1012    Monthname(Box<Monthname>),
1013    Ntile(Box<Ntile>),
1014    Normalize(Box<Normalize>),
1015    Normal(Box<Normal>),
1016    Predict(Box<Predict>),
1017    MLTranslate(Box<MLTranslate>),
1018    FeaturesAtTime(Box<FeaturesAtTime>),
1019    GenerateEmbedding(Box<GenerateEmbedding>),
1020    MLForecast(Box<MLForecast>),
1021    ModelAttribute(Box<ModelAttribute>),
1022    VectorSearch(Box<VectorSearch>),
1023    Quantile(Box<Quantile>),
1024    ApproxQuantile(Box<ApproxQuantile>),
1025    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1026    Randn(Box<Randn>),
1027    Randstr(Box<Randstr>),
1028    RangeN(Box<RangeN>),
1029    RangeBucket(Box<RangeBucket>),
1030    ReadCSV(Box<ReadCSV>),
1031    ReadParquet(Box<ReadParquet>),
1032    Reduce(Box<Reduce>),
1033    RegexpExtractAll(Box<RegexpExtractAll>),
1034    RegexpILike(Box<RegexpILike>),
1035    RegexpFullMatch(Box<RegexpFullMatch>),
1036    RegexpInstr(Box<RegexpInstr>),
1037    RegexpSplit(Box<RegexpSplit>),
1038    RegexpCount(Box<RegexpCount>),
1039    RegrValx(Box<RegrValx>),
1040    RegrValy(Box<RegrValy>),
1041    RegrAvgy(Box<RegrAvgy>),
1042    RegrAvgx(Box<RegrAvgx>),
1043    RegrCount(Box<RegrCount>),
1044    RegrIntercept(Box<RegrIntercept>),
1045    RegrR2(Box<RegrR2>),
1046    RegrSxx(Box<RegrSxx>),
1047    RegrSxy(Box<RegrSxy>),
1048    RegrSyy(Box<RegrSyy>),
1049    RegrSlope(Box<RegrSlope>),
1050    SafeAdd(Box<SafeAdd>),
1051    SafeDivide(Box<SafeDivide>),
1052    SafeMultiply(Box<SafeMultiply>),
1053    SafeSubtract(Box<SafeSubtract>),
1054    SHA2(Box<SHA2>),
1055    SHA2Digest(Box<SHA2Digest>),
1056    SortArray(Box<SortArray>),
1057    SplitPart(Box<SplitPart>),
1058    SubstringIndex(Box<SubstringIndex>),
1059    StandardHash(Box<StandardHash>),
1060    StrPosition(Box<StrPosition>),
1061    Search(Box<Search>),
1062    SearchIp(Box<SearchIp>),
1063    StrToDate(Box<StrToDate>),
1064    DateStrToDate(Box<UnaryFunc>),
1065    DateToDateStr(Box<UnaryFunc>),
1066    StrToTime(Box<StrToTime>),
1067    StrToUnix(Box<StrToUnix>),
1068    StrToMap(Box<StrToMap>),
1069    NumberToStr(Box<NumberToStr>),
1070    FromBase(Box<FromBase>),
1071    Stuff(Box<Stuff>),
1072    TimeToStr(Box<TimeToStr>),
1073    TimeStrToTime(Box<TimeStrToTime>),
1074    TsOrDsAdd(Box<TsOrDsAdd>),
1075    TsOrDsDiff(Box<TsOrDsDiff>),
1076    TsOrDsToDate(Box<TsOrDsToDate>),
1077    TsOrDsToTime(Box<TsOrDsToTime>),
1078    Unhex(Box<Unhex>),
1079    Uniform(Box<Uniform>),
1080    UnixToStr(Box<UnixToStr>),
1081    UnixToTime(Box<UnixToTime>),
1082    Uuid(Box<Uuid>),
1083    TimestampFromParts(Box<TimestampFromParts>),
1084    TimestampTzFromParts(Box<TimestampTzFromParts>),
1085    Corr(Box<Corr>),
1086    WidthBucket(Box<WidthBucket>),
1087    CovarSamp(Box<CovarSamp>),
1088    CovarPop(Box<CovarPop>),
1089    Week(Box<Week>),
1090    XMLElement(Box<XMLElement>),
1091    XMLGet(Box<XMLGet>),
1092    XMLTable(Box<XMLTable>),
1093    XMLKeyValueOption(Box<XMLKeyValueOption>),
1094    Zipf(Box<Zipf>),
1095    Merge(Box<Merge>),
1096    When(Box<When>),
1097    Whens(Box<Whens>),
1098    NextValueFor(Box<NextValueFor>),
1099    /// RETURN statement (DuckDB stored procedures)
1100    ReturnStmt(Box<Expression>),
1101}
1102
1103impl Expression {
1104    /// Returns `true` if this expression is a valid top-level SQL statement.
1105    ///
1106    /// Bare expressions like identifiers, literals, and function calls are not
1107    /// valid statements. This is used by `validate()` to reject inputs like
1108    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1109    /// plus the bare identifier `doo`.
1110    pub fn is_statement(&self) -> bool {
1111        match self {
1112            // Queries
1113            Expression::Select(_)
1114            | Expression::Union(_)
1115            | Expression::Intersect(_)
1116            | Expression::Except(_)
1117            | Expression::Subquery(_)
1118            | Expression::Values(_)
1119            | Expression::PipeOperator(_)
1120
1121            // DML
1122            | Expression::Insert(_)
1123            | Expression::Update(_)
1124            | Expression::Delete(_)
1125            | Expression::Copy(_)
1126            | Expression::Put(_)
1127            | Expression::Merge(_)
1128
1129            // DDL
1130            | Expression::CreateTable(_)
1131            | Expression::DropTable(_)
1132            | Expression::AlterTable(_)
1133            | Expression::CreateIndex(_)
1134            | Expression::DropIndex(_)
1135            | Expression::CreateView(_)
1136            | Expression::DropView(_)
1137            | Expression::AlterView(_)
1138            | Expression::AlterIndex(_)
1139            | Expression::Truncate(_)
1140            | Expression::TruncateTable(_)
1141            | Expression::CreateSchema(_)
1142            | Expression::DropSchema(_)
1143            | Expression::DropNamespace(_)
1144            | Expression::CreateDatabase(_)
1145            | Expression::DropDatabase(_)
1146            | Expression::CreateFunction(_)
1147            | Expression::DropFunction(_)
1148            | Expression::CreateProcedure(_)
1149            | Expression::DropProcedure(_)
1150            | Expression::CreateSequence(_)
1151            | Expression::DropSequence(_)
1152            | Expression::AlterSequence(_)
1153            | Expression::CreateTrigger(_)
1154            | Expression::DropTrigger(_)
1155            | Expression::CreateType(_)
1156            | Expression::DropType(_)
1157            | Expression::Comment(_)
1158
1159            // Session/Transaction/Control
1160            | Expression::Use(_)
1161            | Expression::Set(_)
1162            | Expression::SetStatement(_)
1163            | Expression::Transaction(_)
1164            | Expression::Commit(_)
1165            | Expression::Rollback(_)
1166            | Expression::Grant(_)
1167            | Expression::Revoke(_)
1168            | Expression::Cache(_)
1169            | Expression::Uncache(_)
1170            | Expression::LoadData(_)
1171            | Expression::Pragma(_)
1172            | Expression::Describe(_)
1173            | Expression::Show(_)
1174            | Expression::Kill(_)
1175            | Expression::Execute(_)
1176            | Expression::Declare(_)
1177            | Expression::Refresh(_)
1178            | Expression::AlterSession(_)
1179            | Expression::LockingStatement(_)
1180
1181            // Analyze
1182            | Expression::Analyze(_)
1183            | Expression::AnalyzeStatistics(_)
1184            | Expression::AnalyzeHistogram(_)
1185            | Expression::AnalyzeSample(_)
1186            | Expression::AnalyzeListChainedRows(_)
1187            | Expression::AnalyzeDelete(_)
1188
1189            // Attach/Detach/Install/Summarize
1190            | Expression::Attach(_)
1191            | Expression::Detach(_)
1192            | Expression::Install(_)
1193            | Expression::Summarize(_)
1194
1195            // Pivot at statement level
1196            | Expression::Pivot(_)
1197            | Expression::Unpivot(_)
1198
1199            // Command (raw/unparsed statements)
1200            | Expression::Command(_)
1201            | Expression::Raw(_)
1202
1203            // Return statement
1204            | Expression::ReturnStmt(_) => true,
1205
1206            // Annotated wraps another expression with comments — check inner
1207            Expression::Annotated(a) => a.this.is_statement(),
1208
1209            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1210            Expression::Alias(a) => a.this.is_statement(),
1211
1212            // Everything else (identifiers, literals, operators, functions, etc.)
1213            _ => false,
1214        }
1215    }
1216
1217    /// Create a literal number expression from an integer.
1218    pub fn number(n: i64) -> Self {
1219        Expression::Literal(Literal::Number(n.to_string()))
1220    }
1221
1222    /// Create a single-quoted literal string expression.
1223    pub fn string(s: impl Into<String>) -> Self {
1224        Expression::Literal(Literal::String(s.into()))
1225    }
1226
1227    /// Create a literal number expression from a float.
1228    pub fn float(f: f64) -> Self {
1229        Expression::Literal(Literal::Number(f.to_string()))
1230    }
1231
1232    /// Get the inferred type annotation, if present.
1233    ///
1234    /// For value-producing expressions with an `inferred_type` field, returns
1235    /// the stored type. For literals and boolean constants, computes the type
1236    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1237    pub fn inferred_type(&self) -> Option<&DataType> {
1238        match self {
1239            // Structs with inferred_type field
1240            Expression::And(op)
1241            | Expression::Or(op)
1242            | Expression::Add(op)
1243            | Expression::Sub(op)
1244            | Expression::Mul(op)
1245            | Expression::Div(op)
1246            | Expression::Mod(op)
1247            | Expression::Eq(op)
1248            | Expression::Neq(op)
1249            | Expression::Lt(op)
1250            | Expression::Lte(op)
1251            | Expression::Gt(op)
1252            | Expression::Gte(op)
1253            | Expression::Concat(op)
1254            | Expression::BitwiseAnd(op)
1255            | Expression::BitwiseOr(op)
1256            | Expression::BitwiseXor(op)
1257            | Expression::Adjacent(op)
1258            | Expression::TsMatch(op)
1259            | Expression::PropertyEQ(op)
1260            | Expression::ArrayContainsAll(op)
1261            | Expression::ArrayContainedBy(op)
1262            | Expression::ArrayOverlaps(op)
1263            | Expression::JSONBContainsAllTopKeys(op)
1264            | Expression::JSONBContainsAnyTopKeys(op)
1265            | Expression::JSONBDeleteAtPath(op)
1266            | Expression::ExtendsLeft(op)
1267            | Expression::ExtendsRight(op)
1268            | Expression::Is(op)
1269            | Expression::MemberOf(op)
1270            | Expression::Match(op)
1271            | Expression::NullSafeEq(op)
1272            | Expression::NullSafeNeq(op)
1273            | Expression::Glob(op)
1274            | Expression::BitwiseLeftShift(op)
1275            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1276
1277            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1278                op.inferred_type.as_ref()
1279            }
1280
1281            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1282
1283            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1284                c.inferred_type.as_ref()
1285            }
1286
1287            Expression::Column(c) => c.inferred_type.as_ref(),
1288            Expression::Function(f) => f.inferred_type.as_ref(),
1289            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1290            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1291            Expression::Case(c) => c.inferred_type.as_ref(),
1292            Expression::Subquery(s) => s.inferred_type.as_ref(),
1293            Expression::Alias(a) => a.inferred_type.as_ref(),
1294            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1295            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1296            Expression::Count(f) => f.inferred_type.as_ref(),
1297            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1298            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1299            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1300            Expression::SumIf(f) => f.inferred_type.as_ref(),
1301
1302            // UnaryFunc variants
1303            Expression::Upper(f)
1304            | Expression::Lower(f)
1305            | Expression::Length(f)
1306            | Expression::LTrim(f)
1307            | Expression::RTrim(f)
1308            | Expression::Reverse(f)
1309            | Expression::Abs(f)
1310            | Expression::Sqrt(f)
1311            | Expression::Cbrt(f)
1312            | Expression::Ln(f)
1313            | Expression::Exp(f)
1314            | Expression::Sign(f)
1315            | Expression::Date(f)
1316            | Expression::Time(f)
1317            | Expression::Initcap(f)
1318            | Expression::Ascii(f)
1319            | Expression::Chr(f)
1320            | Expression::Soundex(f)
1321            | Expression::ByteLength(f)
1322            | Expression::Hex(f)
1323            | Expression::LowerHex(f)
1324            | Expression::Unicode(f)
1325            | Expression::Typeof(f)
1326            | Expression::Explode(f)
1327            | Expression::ExplodeOuter(f)
1328            | Expression::MapFromEntries(f)
1329            | Expression::MapKeys(f)
1330            | Expression::MapValues(f)
1331            | Expression::ArrayLength(f)
1332            | Expression::ArraySize(f)
1333            | Expression::Cardinality(f)
1334            | Expression::ArrayReverse(f)
1335            | Expression::ArrayDistinct(f)
1336            | Expression::ArrayFlatten(f)
1337            | Expression::ArrayCompact(f)
1338            | Expression::ToArray(f)
1339            | Expression::JsonArrayLength(f)
1340            | Expression::JsonKeys(f)
1341            | Expression::JsonType(f)
1342            | Expression::ParseJson(f)
1343            | Expression::ToJson(f)
1344            | Expression::Radians(f)
1345            | Expression::Degrees(f)
1346            | Expression::Sin(f)
1347            | Expression::Cos(f)
1348            | Expression::Tan(f)
1349            | Expression::Asin(f)
1350            | Expression::Acos(f)
1351            | Expression::Atan(f)
1352            | Expression::IsNan(f)
1353            | Expression::IsInf(f)
1354            | Expression::Year(f)
1355            | Expression::Month(f)
1356            | Expression::Day(f)
1357            | Expression::Hour(f)
1358            | Expression::Minute(f)
1359            | Expression::Second(f)
1360            | Expression::DayOfWeek(f)
1361            | Expression::DayOfWeekIso(f)
1362            | Expression::DayOfMonth(f)
1363            | Expression::DayOfYear(f)
1364            | Expression::WeekOfYear(f)
1365            | Expression::Quarter(f)
1366            | Expression::Epoch(f)
1367            | Expression::EpochMs(f)
1368            | Expression::BitwiseCount(f)
1369            | Expression::DateFromUnixDate(f)
1370            | Expression::UnixDate(f)
1371            | Expression::UnixSeconds(f)
1372            | Expression::UnixMillis(f)
1373            | Expression::UnixMicros(f)
1374            | Expression::TimeStrToDate(f)
1375            | Expression::DateToDi(f)
1376            | Expression::DiToDate(f)
1377            | Expression::TsOrDiToDi(f)
1378            | Expression::TsOrDsToDatetime(f)
1379            | Expression::TsOrDsToTimestamp(f)
1380            | Expression::YearOfWeek(f)
1381            | Expression::YearOfWeekIso(f)
1382            | Expression::SHA(f)
1383            | Expression::SHA1Digest(f)
1384            | Expression::TimeToUnix(f)
1385            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1386
1387            // BinaryFunc variants
1388            Expression::Power(f)
1389            | Expression::NullIf(f)
1390            | Expression::IfNull(f)
1391            | Expression::Nvl(f)
1392            | Expression::Contains(f)
1393            | Expression::StartsWith(f)
1394            | Expression::EndsWith(f)
1395            | Expression::Levenshtein(f)
1396            | Expression::ModFunc(f)
1397            | Expression::IntDiv(f)
1398            | Expression::Atan2(f)
1399            | Expression::AddMonths(f)
1400            | Expression::MonthsBetween(f)
1401            | Expression::NextDay(f)
1402            | Expression::UnixToTimeStr(f)
1403            | Expression::ArrayContains(f)
1404            | Expression::ArrayPosition(f)
1405            | Expression::ArrayAppend(f)
1406            | Expression::ArrayPrepend(f)
1407            | Expression::ArrayUnion(f)
1408            | Expression::ArrayExcept(f)
1409            | Expression::ArrayRemove(f)
1410            | Expression::StarMap(f)
1411            | Expression::MapFromArrays(f)
1412            | Expression::MapContainsKey(f)
1413            | Expression::ElementAt(f)
1414            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1415
1416            // VarArgFunc variants
1417            Expression::Coalesce(f)
1418            | Expression::Greatest(f)
1419            | Expression::Least(f)
1420            | Expression::ArrayConcat(f)
1421            | Expression::ArrayIntersect(f)
1422            | Expression::ArrayZip(f)
1423            | Expression::MapConcat(f)
1424            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1425
1426            // AggFunc variants
1427            Expression::Sum(f)
1428            | Expression::Avg(f)
1429            | Expression::Min(f)
1430            | Expression::Max(f)
1431            | Expression::ArrayAgg(f)
1432            | Expression::CountIf(f)
1433            | Expression::Stddev(f)
1434            | Expression::StddevPop(f)
1435            | Expression::StddevSamp(f)
1436            | Expression::Variance(f)
1437            | Expression::VarPop(f)
1438            | Expression::VarSamp(f)
1439            | Expression::Median(f)
1440            | Expression::Mode(f)
1441            | Expression::First(f)
1442            | Expression::Last(f)
1443            | Expression::AnyValue(f)
1444            | Expression::ApproxDistinct(f)
1445            | Expression::ApproxCountDistinct(f)
1446            | Expression::LogicalAnd(f)
1447            | Expression::LogicalOr(f)
1448            | Expression::Skewness(f)
1449            | Expression::ArrayConcatAgg(f)
1450            | Expression::ArrayUniqueAgg(f)
1451            | Expression::BoolXorAgg(f)
1452            | Expression::BitwiseAndAgg(f)
1453            | Expression::BitwiseOrAgg(f)
1454            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1455
1456            // Everything else: no inferred_type field
1457            _ => None,
1458        }
1459    }
1460
1461    /// Set the inferred type annotation on this expression.
1462    ///
1463    /// Only has an effect on value-producing expressions with an `inferred_type`
1464    /// field. For other expression types, this is a no-op.
1465    pub fn set_inferred_type(&mut self, dt: DataType) {
1466        match self {
1467            Expression::And(op)
1468            | Expression::Or(op)
1469            | Expression::Add(op)
1470            | Expression::Sub(op)
1471            | Expression::Mul(op)
1472            | Expression::Div(op)
1473            | Expression::Mod(op)
1474            | Expression::Eq(op)
1475            | Expression::Neq(op)
1476            | Expression::Lt(op)
1477            | Expression::Lte(op)
1478            | Expression::Gt(op)
1479            | Expression::Gte(op)
1480            | Expression::Concat(op)
1481            | Expression::BitwiseAnd(op)
1482            | Expression::BitwiseOr(op)
1483            | Expression::BitwiseXor(op)
1484            | Expression::Adjacent(op)
1485            | Expression::TsMatch(op)
1486            | Expression::PropertyEQ(op)
1487            | Expression::ArrayContainsAll(op)
1488            | Expression::ArrayContainedBy(op)
1489            | Expression::ArrayOverlaps(op)
1490            | Expression::JSONBContainsAllTopKeys(op)
1491            | Expression::JSONBContainsAnyTopKeys(op)
1492            | Expression::JSONBDeleteAtPath(op)
1493            | Expression::ExtendsLeft(op)
1494            | Expression::ExtendsRight(op)
1495            | Expression::Is(op)
1496            | Expression::MemberOf(op)
1497            | Expression::Match(op)
1498            | Expression::NullSafeEq(op)
1499            | Expression::NullSafeNeq(op)
1500            | Expression::Glob(op)
1501            | Expression::BitwiseLeftShift(op)
1502            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1503
1504            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1505                op.inferred_type = Some(dt)
1506            }
1507
1508            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1509
1510            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1511                c.inferred_type = Some(dt)
1512            }
1513
1514            Expression::Column(c) => c.inferred_type = Some(dt),
1515            Expression::Function(f) => f.inferred_type = Some(dt),
1516            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1517            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1518            Expression::Case(c) => c.inferred_type = Some(dt),
1519            Expression::Subquery(s) => s.inferred_type = Some(dt),
1520            Expression::Alias(a) => a.inferred_type = Some(dt),
1521            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1522            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1523            Expression::Count(f) => f.inferred_type = Some(dt),
1524            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1525            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1526            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1527            Expression::SumIf(f) => f.inferred_type = Some(dt),
1528
1529            // UnaryFunc variants
1530            Expression::Upper(f)
1531            | Expression::Lower(f)
1532            | Expression::Length(f)
1533            | Expression::LTrim(f)
1534            | Expression::RTrim(f)
1535            | Expression::Reverse(f)
1536            | Expression::Abs(f)
1537            | Expression::Sqrt(f)
1538            | Expression::Cbrt(f)
1539            | Expression::Ln(f)
1540            | Expression::Exp(f)
1541            | Expression::Sign(f)
1542            | Expression::Date(f)
1543            | Expression::Time(f)
1544            | Expression::Initcap(f)
1545            | Expression::Ascii(f)
1546            | Expression::Chr(f)
1547            | Expression::Soundex(f)
1548            | Expression::ByteLength(f)
1549            | Expression::Hex(f)
1550            | Expression::LowerHex(f)
1551            | Expression::Unicode(f)
1552            | Expression::Typeof(f)
1553            | Expression::Explode(f)
1554            | Expression::ExplodeOuter(f)
1555            | Expression::MapFromEntries(f)
1556            | Expression::MapKeys(f)
1557            | Expression::MapValues(f)
1558            | Expression::ArrayLength(f)
1559            | Expression::ArraySize(f)
1560            | Expression::Cardinality(f)
1561            | Expression::ArrayReverse(f)
1562            | Expression::ArrayDistinct(f)
1563            | Expression::ArrayFlatten(f)
1564            | Expression::ArrayCompact(f)
1565            | Expression::ToArray(f)
1566            | Expression::JsonArrayLength(f)
1567            | Expression::JsonKeys(f)
1568            | Expression::JsonType(f)
1569            | Expression::ParseJson(f)
1570            | Expression::ToJson(f)
1571            | Expression::Radians(f)
1572            | Expression::Degrees(f)
1573            | Expression::Sin(f)
1574            | Expression::Cos(f)
1575            | Expression::Tan(f)
1576            | Expression::Asin(f)
1577            | Expression::Acos(f)
1578            | Expression::Atan(f)
1579            | Expression::IsNan(f)
1580            | Expression::IsInf(f)
1581            | Expression::Year(f)
1582            | Expression::Month(f)
1583            | Expression::Day(f)
1584            | Expression::Hour(f)
1585            | Expression::Minute(f)
1586            | Expression::Second(f)
1587            | Expression::DayOfWeek(f)
1588            | Expression::DayOfWeekIso(f)
1589            | Expression::DayOfMonth(f)
1590            | Expression::DayOfYear(f)
1591            | Expression::WeekOfYear(f)
1592            | Expression::Quarter(f)
1593            | Expression::Epoch(f)
1594            | Expression::EpochMs(f)
1595            | Expression::BitwiseCount(f)
1596            | Expression::DateFromUnixDate(f)
1597            | Expression::UnixDate(f)
1598            | Expression::UnixSeconds(f)
1599            | Expression::UnixMillis(f)
1600            | Expression::UnixMicros(f)
1601            | Expression::TimeStrToDate(f)
1602            | Expression::DateToDi(f)
1603            | Expression::DiToDate(f)
1604            | Expression::TsOrDiToDi(f)
1605            | Expression::TsOrDsToDatetime(f)
1606            | Expression::TsOrDsToTimestamp(f)
1607            | Expression::YearOfWeek(f)
1608            | Expression::YearOfWeekIso(f)
1609            | Expression::SHA(f)
1610            | Expression::SHA1Digest(f)
1611            | Expression::TimeToUnix(f)
1612            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1613
1614            // BinaryFunc variants
1615            Expression::Power(f)
1616            | Expression::NullIf(f)
1617            | Expression::IfNull(f)
1618            | Expression::Nvl(f)
1619            | Expression::Contains(f)
1620            | Expression::StartsWith(f)
1621            | Expression::EndsWith(f)
1622            | Expression::Levenshtein(f)
1623            | Expression::ModFunc(f)
1624            | Expression::IntDiv(f)
1625            | Expression::Atan2(f)
1626            | Expression::AddMonths(f)
1627            | Expression::MonthsBetween(f)
1628            | Expression::NextDay(f)
1629            | Expression::UnixToTimeStr(f)
1630            | Expression::ArrayContains(f)
1631            | Expression::ArrayPosition(f)
1632            | Expression::ArrayAppend(f)
1633            | Expression::ArrayPrepend(f)
1634            | Expression::ArrayUnion(f)
1635            | Expression::ArrayExcept(f)
1636            | Expression::ArrayRemove(f)
1637            | Expression::StarMap(f)
1638            | Expression::MapFromArrays(f)
1639            | Expression::MapContainsKey(f)
1640            | Expression::ElementAt(f)
1641            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1642
1643            // VarArgFunc variants
1644            Expression::Coalesce(f)
1645            | Expression::Greatest(f)
1646            | Expression::Least(f)
1647            | Expression::ArrayConcat(f)
1648            | Expression::ArrayIntersect(f)
1649            | Expression::ArrayZip(f)
1650            | Expression::MapConcat(f)
1651            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1652
1653            // AggFunc variants
1654            Expression::Sum(f)
1655            | Expression::Avg(f)
1656            | Expression::Min(f)
1657            | Expression::Max(f)
1658            | Expression::ArrayAgg(f)
1659            | Expression::CountIf(f)
1660            | Expression::Stddev(f)
1661            | Expression::StddevPop(f)
1662            | Expression::StddevSamp(f)
1663            | Expression::Variance(f)
1664            | Expression::VarPop(f)
1665            | Expression::VarSamp(f)
1666            | Expression::Median(f)
1667            | Expression::Mode(f)
1668            | Expression::First(f)
1669            | Expression::Last(f)
1670            | Expression::AnyValue(f)
1671            | Expression::ApproxDistinct(f)
1672            | Expression::ApproxCountDistinct(f)
1673            | Expression::LogicalAnd(f)
1674            | Expression::LogicalOr(f)
1675            | Expression::Skewness(f)
1676            | Expression::ArrayConcatAgg(f)
1677            | Expression::ArrayUniqueAgg(f)
1678            | Expression::BoolXorAgg(f)
1679            | Expression::BitwiseAndAgg(f)
1680            | Expression::BitwiseOrAgg(f)
1681            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1682
1683            // Expressions without inferred_type field - no-op
1684            _ => {}
1685        }
1686    }
1687
1688    /// Create an unqualified column reference (e.g. `name`).
1689    pub fn column(name: impl Into<String>) -> Self {
1690        Expression::Column(Column {
1691            name: Identifier::new(name),
1692            table: None,
1693            join_mark: false,
1694            trailing_comments: Vec::new(),
1695            span: None,
1696            inferred_type: None,
1697        })
1698    }
1699
1700    /// Create a qualified column reference (`table.column`).
1701    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1702        Expression::Column(Column {
1703            name: Identifier::new(column),
1704            table: Some(Identifier::new(table)),
1705            join_mark: false,
1706            trailing_comments: Vec::new(),
1707            span: None,
1708            inferred_type: None,
1709        })
1710    }
1711
1712    /// Create a bare identifier expression (not a column reference).
1713    pub fn identifier(name: impl Into<String>) -> Self {
1714        Expression::Identifier(Identifier::new(name))
1715    }
1716
1717    /// Create a NULL expression
1718    pub fn null() -> Self {
1719        Expression::Null(Null)
1720    }
1721
1722    /// Create a TRUE expression
1723    pub fn true_() -> Self {
1724        Expression::Boolean(BooleanLiteral { value: true })
1725    }
1726
1727    /// Create a FALSE expression
1728    pub fn false_() -> Self {
1729        Expression::Boolean(BooleanLiteral { value: false })
1730    }
1731
1732    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1733    pub fn star() -> Self {
1734        Expression::Star(Star {
1735            table: None,
1736            except: None,
1737            replace: None,
1738            rename: None,
1739            trailing_comments: Vec::new(),
1740            span: None,
1741        })
1742    }
1743
1744    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1745    pub fn alias(self, name: impl Into<String>) -> Self {
1746        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1747    }
1748
1749    /// Check if this is a SELECT expression
1750    pub fn is_select(&self) -> bool {
1751        matches!(self, Expression::Select(_))
1752    }
1753
1754    /// Try to get as a Select
1755    pub fn as_select(&self) -> Option<&Select> {
1756        match self {
1757            Expression::Select(s) => Some(s),
1758            _ => None,
1759        }
1760    }
1761
1762    /// Try to get as a mutable Select
1763    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1764        match self {
1765            Expression::Select(s) => Some(s),
1766            _ => None,
1767        }
1768    }
1769
1770    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1771    ///
1772    /// Returns an empty string if generation fails. For dialect-specific output,
1773    /// use [`sql_for()`](Self::sql_for) instead.
1774    pub fn sql(&self) -> String {
1775        crate::generator::Generator::sql(self).unwrap_or_default()
1776    }
1777
1778    /// Generate a SQL string for this expression targeting a specific dialect.
1779    ///
1780    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1781    /// syntax variations) are applied automatically.  Returns an empty string if
1782    /// generation fails.
1783    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1784        crate::generate(self, dialect).unwrap_or_default()
1785    }
1786}
1787
1788impl fmt::Display for Expression {
1789    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1790        // Basic display - full SQL generation is in generator module
1791        match self {
1792            Expression::Literal(lit) => write!(f, "{}", lit),
1793            Expression::Identifier(id) => write!(f, "{}", id),
1794            Expression::Column(col) => write!(f, "{}", col),
1795            Expression::Star(_) => write!(f, "*"),
1796            Expression::Null(_) => write!(f, "NULL"),
1797            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1798            Expression::Select(_) => write!(f, "SELECT ..."),
1799            _ => write!(f, "{:?}", self),
1800        }
1801    }
1802}
1803
1804/// Represent a SQL literal value.
1805///
1806/// Numeric values are stored as their original text representation (not parsed
1807/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1808/// preserved across round-trips.
1809///
1810/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1811/// strings, raw strings, etc.) each have a dedicated variant so that the
1812/// generator can emit them with the correct syntax.
1813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1814#[cfg_attr(feature = "bindings", derive(TS))]
1815#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1816pub enum Literal {
1817    /// Single-quoted string literal: `'hello'`
1818    String(String),
1819    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1820    Number(String),
1821    /// Hex string literal: `X'FF'`
1822    HexString(String),
1823    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1824    HexNumber(String),
1825    BitString(String),
1826    /// Byte string: b"..." (BigQuery style)
1827    ByteString(String),
1828    /// National string: N'abc'
1829    NationalString(String),
1830    /// DATE literal: DATE '2024-01-15'
1831    Date(String),
1832    /// TIME literal: TIME '10:30:00'
1833    Time(String),
1834    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1835    Timestamp(String),
1836    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1837    Datetime(String),
1838    /// Triple-quoted string: """...""" or '''...'''
1839    /// Contains (content, quote_char) where quote_char is '"' or '\''
1840    TripleQuotedString(String, char),
1841    /// Escape string: E'...' (PostgreSQL)
1842    EscapeString(String),
1843    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1844    DollarString(String),
1845    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1846    /// In raw strings, backslashes are literal and not escape characters.
1847    /// When converting to a regular string, backslashes must be doubled.
1848    RawString(String),
1849}
1850
1851impl fmt::Display for Literal {
1852    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1853        match self {
1854            Literal::String(s) => write!(f, "'{}'", s),
1855            Literal::Number(n) => write!(f, "{}", n),
1856            Literal::HexString(h) => write!(f, "X'{}'", h),
1857            Literal::HexNumber(h) => write!(f, "0x{}", h),
1858            Literal::BitString(b) => write!(f, "B'{}'", b),
1859            Literal::ByteString(b) => write!(f, "b'{}'", b),
1860            Literal::NationalString(s) => write!(f, "N'{}'", s),
1861            Literal::Date(d) => write!(f, "DATE '{}'", d),
1862            Literal::Time(t) => write!(f, "TIME '{}'", t),
1863            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1864            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1865            Literal::TripleQuotedString(s, q) => {
1866                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1867            }
1868            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1869            Literal::DollarString(s) => write!(f, "$${}$$", s),
1870            Literal::RawString(s) => write!(f, "r'{}'", s),
1871        }
1872    }
1873}
1874
1875/// Boolean literal
1876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1877#[cfg_attr(feature = "bindings", derive(TS))]
1878pub struct BooleanLiteral {
1879    pub value: bool,
1880}
1881
1882/// NULL literal
1883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1884#[cfg_attr(feature = "bindings", derive(TS))]
1885pub struct Null;
1886
1887/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1888///
1889/// The `quoted` flag indicates whether the identifier was originally delimited
1890/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1891/// dialect). The generator uses this flag to decide whether to emit quoting
1892/// characters.
1893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1894#[cfg_attr(feature = "bindings", derive(TS))]
1895pub struct Identifier {
1896    /// The raw text of the identifier, without any quoting characters.
1897    pub name: String,
1898    /// Whether the identifier was quoted in the source SQL.
1899    pub quoted: bool,
1900    #[serde(default)]
1901    pub trailing_comments: Vec<String>,
1902    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1903    #[serde(default, skip_serializing_if = "Option::is_none")]
1904    pub span: Option<Span>,
1905}
1906
1907impl Identifier {
1908    pub fn new(name: impl Into<String>) -> Self {
1909        Self {
1910            name: name.into(),
1911            quoted: false,
1912            trailing_comments: Vec::new(),
1913            span: None,
1914        }
1915    }
1916
1917    pub fn quoted(name: impl Into<String>) -> Self {
1918        Self {
1919            name: name.into(),
1920            quoted: true,
1921            trailing_comments: Vec::new(),
1922            span: None,
1923        }
1924    }
1925
1926    pub fn empty() -> Self {
1927        Self {
1928            name: String::new(),
1929            quoted: false,
1930            trailing_comments: Vec::new(),
1931            span: None,
1932        }
1933    }
1934
1935    pub fn is_empty(&self) -> bool {
1936        self.name.is_empty()
1937    }
1938
1939    /// Set the source span on this identifier
1940    pub fn with_span(mut self, span: Span) -> Self {
1941        self.span = Some(span);
1942        self
1943    }
1944}
1945
1946impl fmt::Display for Identifier {
1947    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1948        if self.quoted {
1949            write!(f, "\"{}\"", self.name)
1950        } else {
1951            write!(f, "{}", self.name)
1952        }
1953    }
1954}
1955
1956/// Represent a column reference, optionally qualified by a table name.
1957///
1958/// Renders as `name` when unqualified, or `table.name` when qualified.
1959/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1960/// convenient construction.
1961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1962#[cfg_attr(feature = "bindings", derive(TS))]
1963pub struct Column {
1964    /// The column name.
1965    pub name: Identifier,
1966    /// Optional table qualifier (e.g. `t` in `t.col`).
1967    pub table: Option<Identifier>,
1968    /// Oracle-style join marker (+) for outer joins
1969    #[serde(default)]
1970    pub join_mark: bool,
1971    /// Trailing comments that appeared after this column reference
1972    #[serde(default)]
1973    pub trailing_comments: Vec<String>,
1974    /// Source position span
1975    #[serde(default, skip_serializing_if = "Option::is_none")]
1976    pub span: Option<Span>,
1977    /// Inferred data type from type annotation
1978    #[serde(default, skip_serializing_if = "Option::is_none")]
1979    pub inferred_type: Option<DataType>,
1980}
1981
1982impl fmt::Display for Column {
1983    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1984        if let Some(table) = &self.table {
1985            write!(f, "{}.{}", table, self.name)
1986        } else {
1987            write!(f, "{}", self.name)
1988        }
1989    }
1990}
1991
1992/// Represent a table reference with optional schema and catalog qualifiers.
1993///
1994/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1995/// which qualifiers are present. Supports aliases, column alias lists,
1996/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1997/// several other dialect-specific extensions.
1998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1999#[cfg_attr(feature = "bindings", derive(TS))]
2000pub struct TableRef {
2001    /// The unqualified table name.
2002    pub name: Identifier,
2003    /// Optional schema qualifier (e.g. `public` in `public.users`).
2004    pub schema: Option<Identifier>,
2005    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
2006    pub catalog: Option<Identifier>,
2007    /// Optional table alias (e.g. `t` in `FROM users AS t`).
2008    pub alias: Option<Identifier>,
2009    /// Whether AS keyword was explicitly used for the alias
2010    #[serde(default)]
2011    pub alias_explicit_as: bool,
2012    /// Column aliases for table alias: AS t(c1, c2)
2013    #[serde(default)]
2014    pub column_aliases: Vec<Identifier>,
2015    /// Trailing comments that appeared after this table reference
2016    #[serde(default)]
2017    pub trailing_comments: Vec<String>,
2018    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2019    #[serde(default)]
2020    pub when: Option<Box<HistoricalData>>,
2021    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
2022    #[serde(default)]
2023    pub only: bool,
2024    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
2025    #[serde(default)]
2026    pub final_: bool,
2027    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
2028    #[serde(default, skip_serializing_if = "Option::is_none")]
2029    pub table_sample: Option<Box<Sample>>,
2030    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
2031    #[serde(default)]
2032    pub hints: Vec<Expression>,
2033    /// TSQL: FOR SYSTEM_TIME temporal clause
2034    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
2035    #[serde(default, skip_serializing_if = "Option::is_none")]
2036    pub system_time: Option<String>,
2037    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
2038    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2039    pub partitions: Vec<Identifier>,
2040    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
2041    /// When set, this is used instead of the name field
2042    #[serde(default, skip_serializing_if = "Option::is_none")]
2043    pub identifier_func: Option<Box<Expression>>,
2044    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
2045    #[serde(default, skip_serializing_if = "Option::is_none")]
2046    pub changes: Option<Box<Changes>>,
2047    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
2048    #[serde(default, skip_serializing_if = "Option::is_none")]
2049    pub version: Option<Box<Version>>,
2050    /// Source position span
2051    #[serde(default, skip_serializing_if = "Option::is_none")]
2052    pub span: Option<Span>,
2053}
2054
2055impl TableRef {
2056    pub fn new(name: impl Into<String>) -> Self {
2057        Self {
2058            name: Identifier::new(name),
2059            schema: None,
2060            catalog: None,
2061            alias: None,
2062            alias_explicit_as: false,
2063            column_aliases: Vec::new(),
2064            trailing_comments: Vec::new(),
2065            when: None,
2066            only: false,
2067            final_: false,
2068            table_sample: None,
2069            hints: Vec::new(),
2070            system_time: None,
2071            partitions: Vec::new(),
2072            identifier_func: None,
2073            changes: None,
2074            version: None,
2075            span: None,
2076        }
2077    }
2078
2079    /// Create with a schema qualifier.
2080    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
2081        let mut t = Self::new(name);
2082        t.schema = Some(Identifier::new(schema));
2083        t
2084    }
2085
2086    /// Create with catalog and schema qualifiers.
2087    pub fn new_with_catalog(
2088        name: impl Into<String>,
2089        schema: impl Into<String>,
2090        catalog: impl Into<String>,
2091    ) -> Self {
2092        let mut t = Self::new(name);
2093        t.schema = Some(Identifier::new(schema));
2094        t.catalog = Some(Identifier::new(catalog));
2095        t
2096    }
2097
2098    /// Create from an Identifier, preserving the quoted flag
2099    pub fn from_identifier(name: Identifier) -> Self {
2100        Self {
2101            name,
2102            schema: None,
2103            catalog: None,
2104            alias: None,
2105            alias_explicit_as: false,
2106            column_aliases: Vec::new(),
2107            trailing_comments: Vec::new(),
2108            when: None,
2109            only: false,
2110            final_: false,
2111            table_sample: None,
2112            hints: Vec::new(),
2113            system_time: None,
2114            partitions: Vec::new(),
2115            identifier_func: None,
2116            changes: None,
2117            version: None,
2118            span: None,
2119        }
2120    }
2121
2122    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
2123        self.alias = Some(Identifier::new(alias));
2124        self
2125    }
2126
2127    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
2128        self.schema = Some(Identifier::new(schema));
2129        self
2130    }
2131}
2132
2133/// Represent a wildcard star expression (`*`, `table.*`).
2134///
2135/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
2136/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
2137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2138#[cfg_attr(feature = "bindings", derive(TS))]
2139pub struct Star {
2140    /// Optional table qualifier (e.g. `t` in `t.*`).
2141    pub table: Option<Identifier>,
2142    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
2143    pub except: Option<Vec<Identifier>>,
2144    /// REPLACE expressions (BigQuery, Snowflake)
2145    pub replace: Option<Vec<Alias>>,
2146    /// RENAME columns (Snowflake)
2147    pub rename: Option<Vec<(Identifier, Identifier)>>,
2148    /// Trailing comments that appeared after the star
2149    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2150    pub trailing_comments: Vec<String>,
2151    /// Source position span
2152    #[serde(default, skip_serializing_if = "Option::is_none")]
2153    pub span: Option<Span>,
2154}
2155
2156/// Represent a complete SELECT statement.
2157///
2158/// This is the most feature-rich AST node, covering the full surface area of
2159/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
2160/// `Vec` are omitted from the generated SQL when absent.
2161///
2162/// # Key Fields
2163///
2164/// - `expressions` -- the select-list (columns, `*`, computed expressions).
2165/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
2166/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
2167/// - `where_clause` -- the WHERE predicate.
2168/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
2169/// - `having` -- HAVING predicate.
2170/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
2171/// - `limit` / `offset` / `fetch` -- result set limiting.
2172/// - `with` -- Common Table Expressions (CTEs).
2173/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
2174/// - `windows` -- named window definitions (WINDOW w AS ...).
2175///
2176/// Dialect-specific extensions are supported via fields like `prewhere`
2177/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
2178/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
2179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2180#[cfg_attr(feature = "bindings", derive(TS))]
2181pub struct Select {
2182    /// The select-list: columns, expressions, aliases, and wildcards.
2183    pub expressions: Vec<Expression>,
2184    /// The FROM clause, containing one or more table sources.
2185    pub from: Option<From>,
2186    /// JOIN clauses applied after the FROM source.
2187    pub joins: Vec<Join>,
2188    pub lateral_views: Vec<LateralView>,
2189    /// ClickHouse PREWHERE clause
2190    #[serde(default, skip_serializing_if = "Option::is_none")]
2191    pub prewhere: Option<Expression>,
2192    pub where_clause: Option<Where>,
2193    pub group_by: Option<GroupBy>,
2194    pub having: Option<Having>,
2195    pub qualify: Option<Qualify>,
2196    pub order_by: Option<OrderBy>,
2197    pub distribute_by: Option<DistributeBy>,
2198    pub cluster_by: Option<ClusterBy>,
2199    pub sort_by: Option<SortBy>,
2200    pub limit: Option<Limit>,
2201    pub offset: Option<Offset>,
2202    /// ClickHouse LIMIT BY clause expressions
2203    #[serde(default, skip_serializing_if = "Option::is_none")]
2204    pub limit_by: Option<Vec<Expression>>,
2205    pub fetch: Option<Fetch>,
2206    pub distinct: bool,
2207    pub distinct_on: Option<Vec<Expression>>,
2208    pub top: Option<Top>,
2209    pub with: Option<With>,
2210    pub sample: Option<Sample>,
2211    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
2212    #[serde(default, skip_serializing_if = "Option::is_none")]
2213    pub settings: Option<Vec<Expression>>,
2214    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
2215    #[serde(default, skip_serializing_if = "Option::is_none")]
2216    pub format: Option<Expression>,
2217    pub windows: Option<Vec<NamedWindow>>,
2218    pub hint: Option<Hint>,
2219    /// Oracle CONNECT BY clause for hierarchical queries
2220    pub connect: Option<Connect>,
2221    /// SELECT ... INTO table_name for creating tables
2222    pub into: Option<SelectInto>,
2223    /// FOR UPDATE/SHARE locking clauses
2224    #[serde(default)]
2225    pub locks: Vec<Lock>,
2226    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
2227    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2228    pub for_xml: Vec<Expression>,
2229    /// Leading comments before the statement
2230    #[serde(default)]
2231    pub leading_comments: Vec<String>,
2232    /// Comments that appear after SELECT keyword (before expressions)
2233    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
2234    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2235    pub post_select_comments: Vec<String>,
2236    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
2237    #[serde(default, skip_serializing_if = "Option::is_none")]
2238    pub kind: Option<String>,
2239    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
2240    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2241    pub operation_modifiers: Vec<String>,
2242    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
2243    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2244    pub qualify_after_window: bool,
2245    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
2246    #[serde(default, skip_serializing_if = "Option::is_none")]
2247    pub option: Option<String>,
2248}
2249
2250impl Select {
2251    pub fn new() -> Self {
2252        Self {
2253            expressions: Vec::new(),
2254            from: None,
2255            joins: Vec::new(),
2256            lateral_views: Vec::new(),
2257            prewhere: None,
2258            where_clause: None,
2259            group_by: None,
2260            having: None,
2261            qualify: None,
2262            order_by: None,
2263            distribute_by: None,
2264            cluster_by: None,
2265            sort_by: None,
2266            limit: None,
2267            offset: None,
2268            limit_by: None,
2269            fetch: None,
2270            distinct: false,
2271            distinct_on: None,
2272            top: None,
2273            with: None,
2274            sample: None,
2275            settings: None,
2276            format: None,
2277            windows: None,
2278            hint: None,
2279            connect: None,
2280            into: None,
2281            locks: Vec::new(),
2282            for_xml: Vec::new(),
2283            leading_comments: Vec::new(),
2284            post_select_comments: Vec::new(),
2285            kind: None,
2286            operation_modifiers: Vec::new(),
2287            qualify_after_window: false,
2288            option: None,
2289        }
2290    }
2291
2292    /// Add a column to select
2293    pub fn column(mut self, expr: Expression) -> Self {
2294        self.expressions.push(expr);
2295        self
2296    }
2297
2298    /// Set the FROM clause
2299    pub fn from(mut self, table: Expression) -> Self {
2300        self.from = Some(From {
2301            expressions: vec![table],
2302        });
2303        self
2304    }
2305
2306    /// Add a WHERE clause
2307    pub fn where_(mut self, condition: Expression) -> Self {
2308        self.where_clause = Some(Where { this: condition });
2309        self
2310    }
2311
2312    /// Set DISTINCT
2313    pub fn distinct(mut self) -> Self {
2314        self.distinct = true;
2315        self
2316    }
2317
2318    /// Add a JOIN
2319    pub fn join(mut self, join: Join) -> Self {
2320        self.joins.push(join);
2321        self
2322    }
2323
2324    /// Set ORDER BY
2325    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
2326        self.order_by = Some(OrderBy {
2327            expressions,
2328            siblings: false,
2329            comments: Vec::new(),
2330        });
2331        self
2332    }
2333
2334    /// Set LIMIT
2335    pub fn limit(mut self, n: Expression) -> Self {
2336        self.limit = Some(Limit {
2337            this: n,
2338            percent: false,
2339            comments: Vec::new(),
2340        });
2341        self
2342    }
2343
2344    /// Set OFFSET
2345    pub fn offset(mut self, n: Expression) -> Self {
2346        self.offset = Some(Offset {
2347            this: n,
2348            rows: None,
2349        });
2350        self
2351    }
2352}
2353
2354impl Default for Select {
2355    fn default() -> Self {
2356        Self::new()
2357    }
2358}
2359
2360/// Represent a UNION set operation between two query expressions.
2361///
2362/// When `all` is true, duplicate rows are preserved (UNION ALL).
2363/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
2364/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
2365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2366#[cfg_attr(feature = "bindings", derive(TS))]
2367pub struct Union {
2368    /// The left-hand query operand.
2369    pub left: Expression,
2370    /// The right-hand query operand.
2371    pub right: Expression,
2372    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
2373    pub all: bool,
2374    /// Whether DISTINCT was explicitly specified
2375    #[serde(default)]
2376    pub distinct: bool,
2377    /// Optional WITH clause
2378    pub with: Option<With>,
2379    /// ORDER BY applied to entire UNION result
2380    pub order_by: Option<OrderBy>,
2381    /// LIMIT applied to entire UNION result
2382    pub limit: Option<Box<Expression>>,
2383    /// OFFSET applied to entire UNION result
2384    pub offset: Option<Box<Expression>>,
2385    /// DISTRIBUTE BY clause (Hive/Spark)
2386    #[serde(default, skip_serializing_if = "Option::is_none")]
2387    pub distribute_by: Option<DistributeBy>,
2388    /// SORT BY clause (Hive/Spark)
2389    #[serde(default, skip_serializing_if = "Option::is_none")]
2390    pub sort_by: Option<SortBy>,
2391    /// CLUSTER BY clause (Hive/Spark)
2392    #[serde(default, skip_serializing_if = "Option::is_none")]
2393    pub cluster_by: Option<ClusterBy>,
2394    /// DuckDB BY NAME modifier
2395    #[serde(default)]
2396    pub by_name: bool,
2397    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2398    #[serde(default, skip_serializing_if = "Option::is_none")]
2399    pub side: Option<String>,
2400    /// BigQuery: Set operation kind (INNER)
2401    #[serde(default, skip_serializing_if = "Option::is_none")]
2402    pub kind: Option<String>,
2403    /// BigQuery: CORRESPONDING modifier
2404    #[serde(default)]
2405    pub corresponding: bool,
2406    /// BigQuery: STRICT modifier (before CORRESPONDING)
2407    #[serde(default)]
2408    pub strict: bool,
2409    /// BigQuery: BY (columns) after CORRESPONDING
2410    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2411    pub on_columns: Vec<Expression>,
2412}
2413
2414/// Represent an INTERSECT set operation between two query expressions.
2415///
2416/// Returns only rows that appear in both operands. When `all` is true,
2417/// duplicates are preserved according to their multiplicity.
2418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2419#[cfg_attr(feature = "bindings", derive(TS))]
2420pub struct Intersect {
2421    /// The left-hand query operand.
2422    pub left: Expression,
2423    /// The right-hand query operand.
2424    pub right: Expression,
2425    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
2426    pub all: bool,
2427    /// Whether DISTINCT was explicitly specified
2428    #[serde(default)]
2429    pub distinct: bool,
2430    /// Optional WITH clause
2431    pub with: Option<With>,
2432    /// ORDER BY applied to entire INTERSECT result
2433    pub order_by: Option<OrderBy>,
2434    /// LIMIT applied to entire INTERSECT result
2435    pub limit: Option<Box<Expression>>,
2436    /// OFFSET applied to entire INTERSECT result
2437    pub offset: Option<Box<Expression>>,
2438    /// DISTRIBUTE BY clause (Hive/Spark)
2439    #[serde(default, skip_serializing_if = "Option::is_none")]
2440    pub distribute_by: Option<DistributeBy>,
2441    /// SORT BY clause (Hive/Spark)
2442    #[serde(default, skip_serializing_if = "Option::is_none")]
2443    pub sort_by: Option<SortBy>,
2444    /// CLUSTER BY clause (Hive/Spark)
2445    #[serde(default, skip_serializing_if = "Option::is_none")]
2446    pub cluster_by: Option<ClusterBy>,
2447    /// DuckDB BY NAME modifier
2448    #[serde(default)]
2449    pub by_name: bool,
2450    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2451    #[serde(default, skip_serializing_if = "Option::is_none")]
2452    pub side: Option<String>,
2453    /// BigQuery: Set operation kind (INNER)
2454    #[serde(default, skip_serializing_if = "Option::is_none")]
2455    pub kind: Option<String>,
2456    /// BigQuery: CORRESPONDING modifier
2457    #[serde(default)]
2458    pub corresponding: bool,
2459    /// BigQuery: STRICT modifier (before CORRESPONDING)
2460    #[serde(default)]
2461    pub strict: bool,
2462    /// BigQuery: BY (columns) after CORRESPONDING
2463    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2464    pub on_columns: Vec<Expression>,
2465}
2466
2467/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2468///
2469/// Returns rows from the left operand that do not appear in the right operand.
2470/// When `all` is true, duplicates are subtracted according to their multiplicity.
2471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2472#[cfg_attr(feature = "bindings", derive(TS))]
2473pub struct Except {
2474    /// The left-hand query operand.
2475    pub left: Expression,
2476    /// The right-hand query operand (rows to subtract).
2477    pub right: Expression,
2478    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2479    pub all: bool,
2480    /// Whether DISTINCT was explicitly specified
2481    #[serde(default)]
2482    pub distinct: bool,
2483    /// Optional WITH clause
2484    pub with: Option<With>,
2485    /// ORDER BY applied to entire EXCEPT result
2486    pub order_by: Option<OrderBy>,
2487    /// LIMIT applied to entire EXCEPT result
2488    pub limit: Option<Box<Expression>>,
2489    /// OFFSET applied to entire EXCEPT result
2490    pub offset: Option<Box<Expression>>,
2491    /// DISTRIBUTE BY clause (Hive/Spark)
2492    #[serde(default, skip_serializing_if = "Option::is_none")]
2493    pub distribute_by: Option<DistributeBy>,
2494    /// SORT BY clause (Hive/Spark)
2495    #[serde(default, skip_serializing_if = "Option::is_none")]
2496    pub sort_by: Option<SortBy>,
2497    /// CLUSTER BY clause (Hive/Spark)
2498    #[serde(default, skip_serializing_if = "Option::is_none")]
2499    pub cluster_by: Option<ClusterBy>,
2500    /// DuckDB BY NAME modifier
2501    #[serde(default)]
2502    pub by_name: bool,
2503    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2504    #[serde(default, skip_serializing_if = "Option::is_none")]
2505    pub side: Option<String>,
2506    /// BigQuery: Set operation kind (INNER)
2507    #[serde(default, skip_serializing_if = "Option::is_none")]
2508    pub kind: Option<String>,
2509    /// BigQuery: CORRESPONDING modifier
2510    #[serde(default)]
2511    pub corresponding: bool,
2512    /// BigQuery: STRICT modifier (before CORRESPONDING)
2513    #[serde(default)]
2514    pub strict: bool,
2515    /// BigQuery: BY (columns) after CORRESPONDING
2516    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2517    pub on_columns: Vec<Expression>,
2518}
2519
2520/// INTO clause for SELECT INTO statements
2521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2522#[cfg_attr(feature = "bindings", derive(TS))]
2523pub struct SelectInto {
2524    /// Target table or variable (used when single target)
2525    pub this: Expression,
2526    /// Whether TEMPORARY keyword was used
2527    #[serde(default)]
2528    pub temporary: bool,
2529    /// Whether UNLOGGED keyword was used (PostgreSQL)
2530    #[serde(default)]
2531    pub unlogged: bool,
2532    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2533    #[serde(default)]
2534    pub bulk_collect: bool,
2535    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2536    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2537    pub expressions: Vec<Expression>,
2538}
2539
2540/// Represent a parenthesized subquery expression.
2541///
2542/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2543/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2544/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2545/// modifiers are rendered inside or outside the parentheses.
2546///
2547/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2548/// scalar subqueries in select-lists, and derived tables.
2549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2550#[cfg_attr(feature = "bindings", derive(TS))]
2551pub struct Subquery {
2552    /// The inner query expression.
2553    pub this: Expression,
2554    /// Optional alias for the derived table.
2555    pub alias: Option<Identifier>,
2556    /// Optional column aliases: AS t(c1, c2)
2557    pub column_aliases: Vec<Identifier>,
2558    /// ORDER BY clause (for parenthesized queries)
2559    pub order_by: Option<OrderBy>,
2560    /// LIMIT clause
2561    pub limit: Option<Limit>,
2562    /// OFFSET clause
2563    pub offset: Option<Offset>,
2564    /// DISTRIBUTE BY clause (Hive/Spark)
2565    #[serde(default, skip_serializing_if = "Option::is_none")]
2566    pub distribute_by: Option<DistributeBy>,
2567    /// SORT BY clause (Hive/Spark)
2568    #[serde(default, skip_serializing_if = "Option::is_none")]
2569    pub sort_by: Option<SortBy>,
2570    /// CLUSTER BY clause (Hive/Spark)
2571    #[serde(default, skip_serializing_if = "Option::is_none")]
2572    pub cluster_by: Option<ClusterBy>,
2573    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2574    #[serde(default)]
2575    pub lateral: bool,
2576    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2577    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2578    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2579    #[serde(default)]
2580    pub modifiers_inside: bool,
2581    /// Trailing comments after the closing paren
2582    #[serde(default)]
2583    pub trailing_comments: Vec<String>,
2584    /// Inferred data type from type annotation
2585    #[serde(default, skip_serializing_if = "Option::is_none")]
2586    pub inferred_type: Option<DataType>,
2587}
2588
2589/// Pipe operator expression: query |> transform
2590///
2591/// Used in DataFusion and BigQuery pipe syntax:
2592///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2594#[cfg_attr(feature = "bindings", derive(TS))]
2595pub struct PipeOperator {
2596    /// The input query/expression (left side of |>)
2597    pub this: Expression,
2598    /// The piped operation (right side of |>)
2599    pub expression: Expression,
2600}
2601
2602/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2604#[cfg_attr(feature = "bindings", derive(TS))]
2605pub struct Values {
2606    /// The rows of values
2607    pub expressions: Vec<Tuple>,
2608    /// Optional alias for the table
2609    pub alias: Option<Identifier>,
2610    /// Optional column aliases: AS t(c1, c2)
2611    pub column_aliases: Vec<Identifier>,
2612}
2613
2614/// PIVOT operation - supports both standard and DuckDB simplified syntax
2615///
2616/// Standard syntax (in FROM clause):
2617///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2618///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2619///
2620/// DuckDB simplified syntax (statement-level):
2621///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2622///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2623#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2624#[cfg_attr(feature = "bindings", derive(TS))]
2625pub struct Pivot {
2626    /// Source table/expression
2627    pub this: Expression,
2628    /// For standard PIVOT: the aggregation function(s) (first is primary)
2629    /// For DuckDB simplified: unused (use `using` instead)
2630    #[serde(default)]
2631    pub expressions: Vec<Expression>,
2632    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2633    #[serde(default)]
2634    pub fields: Vec<Expression>,
2635    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2636    #[serde(default)]
2637    pub using: Vec<Expression>,
2638    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2639    #[serde(default)]
2640    pub group: Option<Box<Expression>>,
2641    /// Whether this is an UNPIVOT (vs PIVOT)
2642    #[serde(default)]
2643    pub unpivot: bool,
2644    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2645    #[serde(default)]
2646    pub into: Option<Box<Expression>>,
2647    /// Optional alias
2648    #[serde(default)]
2649    pub alias: Option<Identifier>,
2650    /// Include/exclude nulls (for UNPIVOT)
2651    #[serde(default)]
2652    pub include_nulls: Option<bool>,
2653    /// Default on null value (Snowflake)
2654    #[serde(default)]
2655    pub default_on_null: Option<Box<Expression>>,
2656    /// WITH clause (CTEs)
2657    #[serde(default, skip_serializing_if = "Option::is_none")]
2658    pub with: Option<With>,
2659}
2660
2661/// UNPIVOT operation
2662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2663#[cfg_attr(feature = "bindings", derive(TS))]
2664pub struct Unpivot {
2665    pub this: Expression,
2666    pub value_column: Identifier,
2667    pub name_column: Identifier,
2668    pub columns: Vec<Expression>,
2669    pub alias: Option<Identifier>,
2670    /// Whether the value_column was parenthesized in the original SQL
2671    #[serde(default)]
2672    pub value_column_parenthesized: bool,
2673    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2674    #[serde(default)]
2675    pub include_nulls: Option<bool>,
2676    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2677    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2678    pub extra_value_columns: Vec<Identifier>,
2679}
2680
2681/// PIVOT alias for aliasing pivot expressions
2682/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2684#[cfg_attr(feature = "bindings", derive(TS))]
2685pub struct PivotAlias {
2686    pub this: Expression,
2687    pub alias: Expression,
2688}
2689
2690/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2692#[cfg_attr(feature = "bindings", derive(TS))]
2693pub struct PreWhere {
2694    pub this: Expression,
2695}
2696
2697/// STREAM definition (Snowflake) - for change data capture
2698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2699#[cfg_attr(feature = "bindings", derive(TS))]
2700pub struct Stream {
2701    pub this: Expression,
2702    #[serde(skip_serializing_if = "Option::is_none")]
2703    pub on: Option<Expression>,
2704    #[serde(skip_serializing_if = "Option::is_none")]
2705    pub show_initial_rows: Option<bool>,
2706}
2707
2708/// USING DATA clause for data import statements
2709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2710#[cfg_attr(feature = "bindings", derive(TS))]
2711pub struct UsingData {
2712    pub this: Expression,
2713}
2714
2715/// XML Namespace declaration
2716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2717#[cfg_attr(feature = "bindings", derive(TS))]
2718pub struct XmlNamespace {
2719    pub this: Expression,
2720    #[serde(skip_serializing_if = "Option::is_none")]
2721    pub alias: Option<Identifier>,
2722}
2723
2724/// ROW FORMAT clause for Hive/Spark
2725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2726#[cfg_attr(feature = "bindings", derive(TS))]
2727pub struct RowFormat {
2728    pub delimited: bool,
2729    pub fields_terminated_by: Option<String>,
2730    pub collection_items_terminated_by: Option<String>,
2731    pub map_keys_terminated_by: Option<String>,
2732    pub lines_terminated_by: Option<String>,
2733    pub null_defined_as: Option<String>,
2734}
2735
2736/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2738#[cfg_attr(feature = "bindings", derive(TS))]
2739pub struct DirectoryInsert {
2740    pub local: bool,
2741    pub path: String,
2742    pub row_format: Option<RowFormat>,
2743    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2744    #[serde(default)]
2745    pub stored_as: Option<String>,
2746}
2747
2748/// INSERT statement
2749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2750#[cfg_attr(feature = "bindings", derive(TS))]
2751pub struct Insert {
2752    pub table: TableRef,
2753    pub columns: Vec<Identifier>,
2754    pub values: Vec<Vec<Expression>>,
2755    pub query: Option<Expression>,
2756    /// INSERT OVERWRITE for Hive/Spark
2757    pub overwrite: bool,
2758    /// PARTITION clause for Hive/Spark
2759    pub partition: Vec<(Identifier, Option<Expression>)>,
2760    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2761    #[serde(default)]
2762    pub directory: Option<DirectoryInsert>,
2763    /// RETURNING clause (PostgreSQL, SQLite)
2764    #[serde(default)]
2765    pub returning: Vec<Expression>,
2766    /// OUTPUT clause (TSQL)
2767    #[serde(default)]
2768    pub output: Option<OutputClause>,
2769    /// ON CONFLICT clause (PostgreSQL, SQLite)
2770    #[serde(default)]
2771    pub on_conflict: Option<Box<Expression>>,
2772    /// Leading comments before the statement
2773    #[serde(default)]
2774    pub leading_comments: Vec<String>,
2775    /// IF EXISTS clause (Hive)
2776    #[serde(default)]
2777    pub if_exists: bool,
2778    /// WITH clause (CTEs)
2779    #[serde(default)]
2780    pub with: Option<With>,
2781    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2782    #[serde(default)]
2783    pub ignore: bool,
2784    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2785    #[serde(default)]
2786    pub source_alias: Option<Identifier>,
2787    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2788    #[serde(default)]
2789    pub alias: Option<Identifier>,
2790    /// Whether the alias uses explicit AS keyword
2791    #[serde(default)]
2792    pub alias_explicit_as: bool,
2793    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2794    #[serde(default)]
2795    pub default_values: bool,
2796    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2797    #[serde(default)]
2798    pub by_name: bool,
2799    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2800    #[serde(default, skip_serializing_if = "Option::is_none")]
2801    pub conflict_action: Option<String>,
2802    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2803    #[serde(default)]
2804    pub is_replace: bool,
2805    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2806    #[serde(default, skip_serializing_if = "Option::is_none")]
2807    pub hint: Option<Hint>,
2808    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2809    #[serde(default)]
2810    pub replace_where: Option<Box<Expression>>,
2811    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2812    #[serde(default)]
2813    pub source: Option<Box<Expression>>,
2814    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2815    #[serde(default, skip_serializing_if = "Option::is_none")]
2816    pub function_target: Option<Box<Expression>>,
2817    /// ClickHouse: PARTITION BY expr
2818    #[serde(default, skip_serializing_if = "Option::is_none")]
2819    pub partition_by: Option<Box<Expression>>,
2820    /// ClickHouse: SETTINGS key = val, ...
2821    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2822    pub settings: Vec<Expression>,
2823}
2824
2825/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2826#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2827#[cfg_attr(feature = "bindings", derive(TS))]
2828pub struct OutputClause {
2829    /// Columns/expressions to output
2830    pub columns: Vec<Expression>,
2831    /// Optional INTO target table or table variable
2832    #[serde(default)]
2833    pub into_table: Option<Expression>,
2834}
2835
2836/// UPDATE statement
2837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2838#[cfg_attr(feature = "bindings", derive(TS))]
2839pub struct Update {
2840    pub table: TableRef,
2841    /// Additional tables for multi-table UPDATE (MySQL syntax)
2842    #[serde(default)]
2843    pub extra_tables: Vec<TableRef>,
2844    /// JOINs attached to the table list (MySQL multi-table syntax)
2845    #[serde(default)]
2846    pub table_joins: Vec<Join>,
2847    pub set: Vec<(Identifier, Expression)>,
2848    pub from_clause: Option<From>,
2849    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2850    #[serde(default)]
2851    pub from_joins: Vec<Join>,
2852    pub where_clause: Option<Where>,
2853    /// RETURNING clause (PostgreSQL, SQLite)
2854    #[serde(default)]
2855    pub returning: Vec<Expression>,
2856    /// OUTPUT clause (TSQL)
2857    #[serde(default)]
2858    pub output: Option<OutputClause>,
2859    /// WITH clause (CTEs)
2860    #[serde(default)]
2861    pub with: Option<With>,
2862    /// Leading comments before the statement
2863    #[serde(default)]
2864    pub leading_comments: Vec<String>,
2865    /// LIMIT clause (MySQL)
2866    #[serde(default)]
2867    pub limit: Option<Expression>,
2868    /// ORDER BY clause (MySQL)
2869    #[serde(default)]
2870    pub order_by: Option<OrderBy>,
2871    /// Whether FROM clause appears before SET (Snowflake syntax)
2872    #[serde(default)]
2873    pub from_before_set: bool,
2874}
2875
2876/// DELETE statement
2877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2878#[cfg_attr(feature = "bindings", derive(TS))]
2879pub struct Delete {
2880    pub table: TableRef,
2881    /// ClickHouse: ON CLUSTER clause for distributed DDL
2882    #[serde(default, skip_serializing_if = "Option::is_none")]
2883    pub on_cluster: Option<OnCluster>,
2884    /// Optional alias for the table
2885    pub alias: Option<Identifier>,
2886    /// Whether the alias was declared with explicit AS keyword
2887    #[serde(default)]
2888    pub alias_explicit_as: bool,
2889    /// PostgreSQL/DuckDB USING clause - additional tables to join
2890    pub using: Vec<TableRef>,
2891    pub where_clause: Option<Where>,
2892    /// OUTPUT clause (TSQL)
2893    #[serde(default)]
2894    pub output: Option<OutputClause>,
2895    /// Leading comments before the statement
2896    #[serde(default)]
2897    pub leading_comments: Vec<String>,
2898    /// WITH clause (CTEs)
2899    #[serde(default)]
2900    pub with: Option<With>,
2901    /// LIMIT clause (MySQL)
2902    #[serde(default)]
2903    pub limit: Option<Expression>,
2904    /// ORDER BY clause (MySQL)
2905    #[serde(default)]
2906    pub order_by: Option<OrderBy>,
2907    /// RETURNING clause (PostgreSQL)
2908    #[serde(default)]
2909    pub returning: Vec<Expression>,
2910    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2911    /// These are the target tables to delete from
2912    #[serde(default)]
2913    pub tables: Vec<TableRef>,
2914    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2915    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2916    #[serde(default)]
2917    pub tables_from_using: bool,
2918    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2919    #[serde(default)]
2920    pub joins: Vec<Join>,
2921    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2922    #[serde(default)]
2923    pub force_index: Option<String>,
2924    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2925    #[serde(default)]
2926    pub no_from: bool,
2927}
2928
2929/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2931#[cfg_attr(feature = "bindings", derive(TS))]
2932pub struct CopyStmt {
2933    /// Target table or query
2934    pub this: Expression,
2935    /// True for FROM (loading into table), false for TO (exporting)
2936    pub kind: bool,
2937    /// Source/destination file(s) or stage
2938    pub files: Vec<Expression>,
2939    /// Copy parameters
2940    #[serde(default)]
2941    pub params: Vec<CopyParameter>,
2942    /// Credentials for external access
2943    #[serde(default)]
2944    pub credentials: Option<Box<Credentials>>,
2945    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2946    #[serde(default)]
2947    pub is_into: bool,
2948    /// Whether parameters are wrapped in WITH (...) syntax
2949    #[serde(default)]
2950    pub with_wrapped: bool,
2951}
2952
2953/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2955#[cfg_attr(feature = "bindings", derive(TS))]
2956pub struct CopyParameter {
2957    pub name: String,
2958    pub value: Option<Expression>,
2959    pub values: Vec<Expression>,
2960    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2961    #[serde(default)]
2962    pub eq: bool,
2963}
2964
2965/// Credentials for external access (S3, Azure, etc.)
2966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2967#[cfg_attr(feature = "bindings", derive(TS))]
2968pub struct Credentials {
2969    pub credentials: Vec<(String, String)>,
2970    pub encryption: Option<String>,
2971    pub storage: Option<String>,
2972}
2973
2974/// PUT statement (Snowflake)
2975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2976#[cfg_attr(feature = "bindings", derive(TS))]
2977pub struct PutStmt {
2978    /// Source file path
2979    pub source: String,
2980    /// Whether source was quoted in the original SQL
2981    #[serde(default)]
2982    pub source_quoted: bool,
2983    /// Target stage
2984    pub target: Expression,
2985    /// PUT parameters
2986    #[serde(default)]
2987    pub params: Vec<CopyParameter>,
2988}
2989
2990/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2992#[cfg_attr(feature = "bindings", derive(TS))]
2993pub struct StageReference {
2994    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2995    pub name: String,
2996    /// Optional path within the stage (e.g., "/path/to/file.csv")
2997    #[serde(default)]
2998    pub path: Option<String>,
2999    /// Optional FILE_FORMAT parameter
3000    #[serde(default)]
3001    pub file_format: Option<Expression>,
3002    /// Optional PATTERN parameter
3003    #[serde(default)]
3004    pub pattern: Option<String>,
3005    /// Whether the stage reference was originally quoted (e.g., '@mystage')
3006    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3007    pub quoted: bool,
3008}
3009
3010/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3012#[cfg_attr(feature = "bindings", derive(TS))]
3013pub struct HistoricalData {
3014    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
3015    pub this: Box<Expression>,
3016    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
3017    pub kind: String,
3018    /// The expression value (e.g., the statement ID or timestamp)
3019    pub expression: Box<Expression>,
3020}
3021
3022/// Represent an aliased expression (`expr AS name`).
3023///
3024/// Used for column aliases in select-lists, table aliases on subqueries,
3025/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
3026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3027#[cfg_attr(feature = "bindings", derive(TS))]
3028pub struct Alias {
3029    /// The expression being aliased.
3030    pub this: Expression,
3031    /// The alias name (required for simple aliases, optional when only column aliases provided)
3032    pub alias: Identifier,
3033    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
3034    #[serde(default)]
3035    pub column_aliases: Vec<Identifier>,
3036    /// Comments that appeared between the expression and AS keyword
3037    #[serde(default)]
3038    pub pre_alias_comments: Vec<String>,
3039    /// Trailing comments that appeared after the alias
3040    #[serde(default)]
3041    pub trailing_comments: Vec<String>,
3042    /// Inferred data type from type annotation
3043    #[serde(default, skip_serializing_if = "Option::is_none")]
3044    pub inferred_type: Option<DataType>,
3045}
3046
3047impl Alias {
3048    /// Create a simple alias
3049    pub fn new(this: Expression, alias: Identifier) -> Self {
3050        Self {
3051            this,
3052            alias,
3053            column_aliases: Vec::new(),
3054            pre_alias_comments: Vec::new(),
3055            trailing_comments: Vec::new(),
3056            inferred_type: None,
3057        }
3058    }
3059
3060    /// Create an alias with column aliases only (no table alias name)
3061    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
3062        Self {
3063            this,
3064            alias: Identifier::empty(),
3065            column_aliases,
3066            pre_alias_comments: Vec::new(),
3067            trailing_comments: Vec::new(),
3068            inferred_type: None,
3069        }
3070    }
3071}
3072
3073/// Represent a type cast expression.
3074///
3075/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
3076/// shorthand `expr::type`. Also used as the payload for `TryCast` and
3077/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
3078/// CONVERSION ERROR (Oracle) clauses.
3079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3080#[cfg_attr(feature = "bindings", derive(TS))]
3081pub struct Cast {
3082    /// The expression being cast.
3083    pub this: Expression,
3084    /// The target data type.
3085    pub to: DataType,
3086    #[serde(default)]
3087    pub trailing_comments: Vec<String>,
3088    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
3089    #[serde(default)]
3090    pub double_colon_syntax: bool,
3091    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
3092    #[serde(skip_serializing_if = "Option::is_none", default)]
3093    pub format: Option<Box<Expression>>,
3094    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
3095    #[serde(skip_serializing_if = "Option::is_none", default)]
3096    pub default: Option<Box<Expression>>,
3097    /// Inferred data type from type annotation
3098    #[serde(default, skip_serializing_if = "Option::is_none")]
3099    pub inferred_type: Option<DataType>,
3100}
3101
3102///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
3103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3104#[cfg_attr(feature = "bindings", derive(TS))]
3105pub struct CollationExpr {
3106    pub this: Expression,
3107    pub collation: String,
3108    /// True if the collation was single-quoted in the original SQL (string literal)
3109    #[serde(default)]
3110    pub quoted: bool,
3111    /// True if the collation was double-quoted in the original SQL (identifier)
3112    #[serde(default)]
3113    pub double_quoted: bool,
3114}
3115
3116/// Represent a CASE expression (both simple and searched forms).
3117///
3118/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
3119/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
3120/// Each entry in `whens` is a `(condition, result)` pair.
3121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3122#[cfg_attr(feature = "bindings", derive(TS))]
3123pub struct Case {
3124    /// The operand for simple CASE, or `None` for searched CASE.
3125    pub operand: Option<Expression>,
3126    /// Pairs of (WHEN condition, THEN result).
3127    pub whens: Vec<(Expression, Expression)>,
3128    /// Optional ELSE result.
3129    pub else_: Option<Expression>,
3130    /// Comments from the CASE keyword (emitted after END)
3131    #[serde(default)]
3132    #[serde(skip_serializing_if = "Vec::is_empty")]
3133    pub comments: Vec<String>,
3134    /// Inferred data type from type annotation
3135    #[serde(default, skip_serializing_if = "Option::is_none")]
3136    pub inferred_type: Option<DataType>,
3137}
3138
3139/// Represent a binary operation (two operands separated by an operator).
3140///
3141/// This is the shared payload struct for all binary operator variants in the
3142/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
3143/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
3144/// bitwise, and dialect-specific operators. Comment fields enable round-trip
3145/// preservation of inline comments around operators.
3146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3147#[cfg_attr(feature = "bindings", derive(TS))]
3148pub struct BinaryOp {
3149    pub left: Expression,
3150    pub right: Expression,
3151    /// Comments after the left operand (before the operator)
3152    #[serde(default)]
3153    pub left_comments: Vec<String>,
3154    /// Comments after the operator (before the right operand)
3155    #[serde(default)]
3156    pub operator_comments: Vec<String>,
3157    /// Comments after the right operand
3158    #[serde(default)]
3159    pub trailing_comments: Vec<String>,
3160    /// Inferred data type from type annotation
3161    #[serde(default, skip_serializing_if = "Option::is_none")]
3162    pub inferred_type: Option<DataType>,
3163}
3164
3165impl BinaryOp {
3166    pub fn new(left: Expression, right: Expression) -> Self {
3167        Self {
3168            left,
3169            right,
3170            left_comments: Vec::new(),
3171            operator_comments: Vec::new(),
3172            trailing_comments: Vec::new(),
3173            inferred_type: None,
3174        }
3175    }
3176}
3177
3178/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
3179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3180#[cfg_attr(feature = "bindings", derive(TS))]
3181pub struct LikeOp {
3182    pub left: Expression,
3183    pub right: Expression,
3184    /// ESCAPE character/expression
3185    #[serde(default)]
3186    pub escape: Option<Expression>,
3187    /// Quantifier: ANY, ALL, or SOME
3188    #[serde(default)]
3189    pub quantifier: Option<String>,
3190    /// Inferred data type from type annotation
3191    #[serde(default, skip_serializing_if = "Option::is_none")]
3192    pub inferred_type: Option<DataType>,
3193}
3194
3195impl LikeOp {
3196    pub fn new(left: Expression, right: Expression) -> Self {
3197        Self {
3198            left,
3199            right,
3200            escape: None,
3201            quantifier: None,
3202            inferred_type: None,
3203        }
3204    }
3205
3206    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
3207        Self {
3208            left,
3209            right,
3210            escape: Some(escape),
3211            quantifier: None,
3212            inferred_type: None,
3213        }
3214    }
3215}
3216
3217/// Represent a unary operation (single operand with a prefix operator).
3218///
3219/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
3220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3221#[cfg_attr(feature = "bindings", derive(TS))]
3222pub struct UnaryOp {
3223    /// The operand expression.
3224    pub this: Expression,
3225    /// Inferred data type from type annotation
3226    #[serde(default, skip_serializing_if = "Option::is_none")]
3227    pub inferred_type: Option<DataType>,
3228}
3229
3230impl UnaryOp {
3231    pub fn new(this: Expression) -> Self {
3232        Self {
3233            this,
3234            inferred_type: None,
3235        }
3236    }
3237}
3238
3239/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
3240///
3241/// Either `expressions` (a value list) or `query` (a subquery) is populated,
3242/// but not both. When `not` is true, the predicate is `NOT IN`.
3243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3244#[cfg_attr(feature = "bindings", derive(TS))]
3245pub struct In {
3246    /// The expression being tested.
3247    pub this: Expression,
3248    /// The value list (mutually exclusive with `query`).
3249    pub expressions: Vec<Expression>,
3250    /// A subquery (mutually exclusive with `expressions`).
3251    pub query: Option<Expression>,
3252    /// Whether this is NOT IN.
3253    pub not: bool,
3254    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3255    pub global: bool,
3256    /// BigQuery: IN UNNEST(expr)
3257    #[serde(default, skip_serializing_if = "Option::is_none")]
3258    pub unnest: Option<Box<Expression>>,
3259    /// Whether the right side is a bare field reference (no parentheses).
3260    /// Matches Python sqlglot's `field` attribute on `In` expression.
3261    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
3262    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3263    pub is_field: bool,
3264}
3265
3266/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
3267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3268#[cfg_attr(feature = "bindings", derive(TS))]
3269pub struct Between {
3270    /// The expression being tested.
3271    pub this: Expression,
3272    /// The lower bound.
3273    pub low: Expression,
3274    /// The upper bound.
3275    pub high: Expression,
3276    /// Whether this is NOT BETWEEN.
3277    pub not: bool,
3278    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
3279    #[serde(default)]
3280    pub symmetric: Option<bool>,
3281}
3282
3283/// IS NULL predicate
3284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3285#[cfg_attr(feature = "bindings", derive(TS))]
3286pub struct IsNull {
3287    pub this: Expression,
3288    pub not: bool,
3289    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
3290    #[serde(default)]
3291    pub postfix_form: bool,
3292}
3293
3294/// IS TRUE / IS FALSE predicate
3295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3296#[cfg_attr(feature = "bindings", derive(TS))]
3297pub struct IsTrueFalse {
3298    pub this: Expression,
3299    pub not: bool,
3300}
3301
3302/// IS JSON predicate (SQL standard)
3303/// Checks if a value is valid JSON
3304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3305#[cfg_attr(feature = "bindings", derive(TS))]
3306pub struct IsJson {
3307    pub this: Expression,
3308    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
3309    pub json_type: Option<String>,
3310    /// Key uniqueness constraint
3311    pub unique_keys: Option<JsonUniqueKeys>,
3312    /// Whether IS NOT JSON
3313    pub negated: bool,
3314}
3315
3316/// JSON unique keys constraint variants
3317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3318#[cfg_attr(feature = "bindings", derive(TS))]
3319pub enum JsonUniqueKeys {
3320    /// WITH UNIQUE KEYS
3321    With,
3322    /// WITHOUT UNIQUE KEYS
3323    Without,
3324    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
3325    Shorthand,
3326}
3327
3328/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
3329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3330#[cfg_attr(feature = "bindings", derive(TS))]
3331pub struct Exists {
3332    /// The subquery expression.
3333    pub this: Expression,
3334    /// Whether this is NOT EXISTS.
3335    pub not: bool,
3336}
3337
3338/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
3339///
3340/// This is the generic function node. Well-known aggregates, window functions,
3341/// and built-in functions each have their own dedicated `Expression` variants
3342/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
3343/// not recognize as built-ins are represented with this struct.
3344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3345#[cfg_attr(feature = "bindings", derive(TS))]
3346pub struct Function {
3347    /// The function name, as originally written (may be schema-qualified).
3348    pub name: String,
3349    /// Positional arguments to the function.
3350    pub args: Vec<Expression>,
3351    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
3352    pub distinct: bool,
3353    #[serde(default)]
3354    pub trailing_comments: Vec<String>,
3355    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
3356    #[serde(default)]
3357    pub use_bracket_syntax: bool,
3358    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
3359    #[serde(default)]
3360    pub no_parens: bool,
3361    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
3362    #[serde(default)]
3363    pub quoted: bool,
3364    /// Source position span
3365    #[serde(default, skip_serializing_if = "Option::is_none")]
3366    pub span: Option<Span>,
3367    /// Inferred data type from type annotation
3368    #[serde(default, skip_serializing_if = "Option::is_none")]
3369    pub inferred_type: Option<DataType>,
3370}
3371
3372impl Default for Function {
3373    fn default() -> Self {
3374        Self {
3375            name: String::new(),
3376            args: Vec::new(),
3377            distinct: false,
3378            trailing_comments: Vec::new(),
3379            use_bracket_syntax: false,
3380            no_parens: false,
3381            quoted: false,
3382            span: None,
3383            inferred_type: None,
3384        }
3385    }
3386}
3387
3388impl Function {
3389    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
3390        Self {
3391            name: name.into(),
3392            args,
3393            distinct: false,
3394            trailing_comments: Vec::new(),
3395            use_bracket_syntax: false,
3396            no_parens: false,
3397            quoted: false,
3398            span: None,
3399            inferred_type: None,
3400        }
3401    }
3402}
3403
3404/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
3405///
3406/// This struct is used for aggregate function calls that are not covered by
3407/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
3408/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
3409/// IGNORE NULLS / RESPECT NULLS modifiers.
3410#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3411#[cfg_attr(feature = "bindings", derive(TS))]
3412pub struct AggregateFunction {
3413    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
3414    pub name: String,
3415    /// Positional arguments.
3416    pub args: Vec<Expression>,
3417    /// Whether DISTINCT was specified.
3418    pub distinct: bool,
3419    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
3420    pub filter: Option<Expression>,
3421    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
3422    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3423    pub order_by: Vec<Ordered>,
3424    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
3425    #[serde(default, skip_serializing_if = "Option::is_none")]
3426    pub limit: Option<Box<Expression>>,
3427    /// IGNORE NULLS / RESPECT NULLS
3428    #[serde(default, skip_serializing_if = "Option::is_none")]
3429    pub ignore_nulls: Option<bool>,
3430    /// Inferred data type from type annotation
3431    #[serde(default, skip_serializing_if = "Option::is_none")]
3432    pub inferred_type: Option<DataType>,
3433}
3434
3435/// Represent a window function call with its OVER clause.
3436///
3437/// The inner `this` expression is typically a window-specific expression
3438/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
3439/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
3440/// frame specification.
3441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3442#[cfg_attr(feature = "bindings", derive(TS))]
3443pub struct WindowFunction {
3444    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
3445    pub this: Expression,
3446    /// The OVER clause defining the window partitioning, ordering, and frame.
3447    pub over: Over,
3448    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
3449    #[serde(default, skip_serializing_if = "Option::is_none")]
3450    pub keep: Option<Keep>,
3451    /// Inferred data type from type annotation
3452    #[serde(default, skip_serializing_if = "Option::is_none")]
3453    pub inferred_type: Option<DataType>,
3454}
3455
3456/// Oracle KEEP clause for aggregate functions
3457/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
3458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3459#[cfg_attr(feature = "bindings", derive(TS))]
3460pub struct Keep {
3461    /// true = FIRST, false = LAST
3462    pub first: bool,
3463    /// ORDER BY clause inside KEEP
3464    pub order_by: Vec<Ordered>,
3465}
3466
3467/// WITHIN GROUP clause (for ordered-set aggregate functions)
3468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3469#[cfg_attr(feature = "bindings", derive(TS))]
3470pub struct WithinGroup {
3471    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
3472    pub this: Expression,
3473    /// The ORDER BY clause within the group
3474    pub order_by: Vec<Ordered>,
3475}
3476
3477/// Represent the FROM clause of a SELECT statement.
3478///
3479/// Contains one or more table sources (tables, subqueries, table-valued
3480/// functions, etc.). Multiple entries represent comma-separated implicit joins.
3481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3482#[cfg_attr(feature = "bindings", derive(TS))]
3483pub struct From {
3484    /// The table source expressions.
3485    pub expressions: Vec<Expression>,
3486}
3487
3488/// Represent a JOIN clause between two table sources.
3489///
3490/// The join condition can be specified via `on` (ON predicate) or `using`
3491/// (USING column list), but not both. The `kind` field determines the join
3492/// type (INNER, LEFT, CROSS, etc.).
3493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3494#[cfg_attr(feature = "bindings", derive(TS))]
3495pub struct Join {
3496    /// The right-hand table expression being joined.
3497    pub this: Expression,
3498    /// The ON condition (mutually exclusive with `using`).
3499    pub on: Option<Expression>,
3500    /// The USING column list (mutually exclusive with `on`).
3501    pub using: Vec<Identifier>,
3502    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
3503    pub kind: JoinKind,
3504    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3505    pub use_inner_keyword: bool,
3506    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3507    pub use_outer_keyword: bool,
3508    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3509    pub deferred_condition: bool,
3510    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3511    #[serde(default, skip_serializing_if = "Option::is_none")]
3512    pub join_hint: Option<String>,
3513    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3514    #[serde(default, skip_serializing_if = "Option::is_none")]
3515    pub match_condition: Option<Expression>,
3516    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3517    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3518    pub pivots: Vec<Expression>,
3519    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3520    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3521    pub comments: Vec<String>,
3522    /// Nesting group identifier for nested join pretty-printing.
3523    /// Joins in the same group were parsed together; group boundaries come from
3524    /// deferred condition resolution phases.
3525    #[serde(default)]
3526    pub nesting_group: usize,
3527    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3528    #[serde(default)]
3529    pub directed: bool,
3530}
3531
3532/// Enumerate all supported SQL join types.
3533///
3534/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3535/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3536/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3537/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3538#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3539#[cfg_attr(feature = "bindings", derive(TS))]
3540pub enum JoinKind {
3541    Inner,
3542    Left,
3543    Right,
3544    Full,
3545    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3546    Cross,
3547    Natural,
3548    NaturalLeft,
3549    NaturalRight,
3550    NaturalFull,
3551    Semi,
3552    Anti,
3553    // Directional SEMI/ANTI joins
3554    LeftSemi,
3555    LeftAnti,
3556    RightSemi,
3557    RightAnti,
3558    // SQL Server specific
3559    CrossApply,
3560    OuterApply,
3561    // Time-series specific
3562    AsOf,
3563    AsOfLeft,
3564    AsOfRight,
3565    // Lateral join
3566    Lateral,
3567    LeftLateral,
3568    // MySQL specific
3569    Straight,
3570    // Implicit join (comma-separated tables: FROM a, b)
3571    Implicit,
3572    // ClickHouse ARRAY JOIN
3573    Array,
3574    LeftArray,
3575    // ClickHouse PASTE JOIN (positional join)
3576    Paste,
3577}
3578
3579impl Default for JoinKind {
3580    fn default() -> Self {
3581        JoinKind::Inner
3582    }
3583}
3584
3585/// Parenthesized table expression with joins
3586/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3588#[cfg_attr(feature = "bindings", derive(TS))]
3589pub struct JoinedTable {
3590    /// The left-hand side table expression
3591    pub left: Expression,
3592    /// The joins applied to the left table
3593    pub joins: Vec<Join>,
3594    /// LATERAL VIEW clauses (Hive/Spark)
3595    pub lateral_views: Vec<LateralView>,
3596    /// Optional alias for the joined table expression
3597    pub alias: Option<Identifier>,
3598}
3599
3600/// Represent a WHERE clause containing a boolean filter predicate.
3601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3602#[cfg_attr(feature = "bindings", derive(TS))]
3603pub struct Where {
3604    /// The filter predicate expression.
3605    pub this: Expression,
3606}
3607
3608/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3609///
3610/// The `expressions` list may contain plain columns, ordinal positions,
3611/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3613#[cfg_attr(feature = "bindings", derive(TS))]
3614pub struct GroupBy {
3615    /// The grouping expressions.
3616    pub expressions: Vec<Expression>,
3617    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3618    #[serde(default)]
3619    pub all: Option<bool>,
3620    /// ClickHouse: WITH TOTALS modifier
3621    #[serde(default)]
3622    pub totals: bool,
3623    /// Leading comments that appeared before the GROUP BY keyword
3624    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3625    pub comments: Vec<String>,
3626}
3627
3628/// Represent a HAVING clause containing a predicate over aggregate results.
3629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3630#[cfg_attr(feature = "bindings", derive(TS))]
3631pub struct Having {
3632    /// The filter predicate, typically involving aggregate functions.
3633    pub this: Expression,
3634    /// Leading comments that appeared before the HAVING keyword
3635    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3636    pub comments: Vec<String>,
3637}
3638
3639/// Represent an ORDER BY clause containing one or more sort specifications.
3640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3641#[cfg_attr(feature = "bindings", derive(TS))]
3642pub struct OrderBy {
3643    /// The sort specifications, each with direction and null ordering.
3644    pub expressions: Vec<Ordered>,
3645    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3646    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3647    pub siblings: bool,
3648    /// Leading comments that appeared before the ORDER BY keyword
3649    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3650    pub comments: Vec<String>,
3651}
3652
3653/// Represent an expression with sort direction and null ordering.
3654///
3655/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3656/// When `desc` is false the sort is ascending. The `nulls_first` field
3657/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3658/// (database default).
3659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3660#[cfg_attr(feature = "bindings", derive(TS))]
3661pub struct Ordered {
3662    /// The expression to sort by.
3663    pub this: Expression,
3664    /// Whether the sort direction is descending (true) or ascending (false).
3665    pub desc: bool,
3666    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3667    pub nulls_first: Option<bool>,
3668    /// Whether ASC was explicitly written (not just implied)
3669    #[serde(default)]
3670    pub explicit_asc: bool,
3671    /// ClickHouse WITH FILL clause
3672    #[serde(default, skip_serializing_if = "Option::is_none")]
3673    pub with_fill: Option<Box<WithFill>>,
3674}
3675
3676impl Ordered {
3677    pub fn asc(expr: Expression) -> Self {
3678        Self {
3679            this: expr,
3680            desc: false,
3681            nulls_first: None,
3682            explicit_asc: false,
3683            with_fill: None,
3684        }
3685    }
3686
3687    pub fn desc(expr: Expression) -> Self {
3688        Self {
3689            this: expr,
3690            desc: true,
3691            nulls_first: None,
3692            explicit_asc: false,
3693            with_fill: None,
3694        }
3695    }
3696}
3697
3698/// DISTRIBUTE BY clause (Hive/Spark)
3699/// Controls how rows are distributed across reducers
3700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3701#[cfg_attr(feature = "bindings", derive(TS))]
3702#[cfg_attr(feature = "bindings", ts(export))]
3703pub struct DistributeBy {
3704    pub expressions: Vec<Expression>,
3705}
3706
3707/// CLUSTER BY clause (Hive/Spark)
3708/// Combines DISTRIBUTE BY and SORT BY on the same columns
3709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3710#[cfg_attr(feature = "bindings", derive(TS))]
3711#[cfg_attr(feature = "bindings", ts(export))]
3712pub struct ClusterBy {
3713    pub expressions: Vec<Ordered>,
3714}
3715
3716/// SORT BY clause (Hive/Spark)
3717/// Sorts data within each reducer (local sort, not global)
3718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3719#[cfg_attr(feature = "bindings", derive(TS))]
3720#[cfg_attr(feature = "bindings", ts(export))]
3721pub struct SortBy {
3722    pub expressions: Vec<Ordered>,
3723}
3724
3725/// LATERAL VIEW clause (Hive/Spark)
3726/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3728#[cfg_attr(feature = "bindings", derive(TS))]
3729#[cfg_attr(feature = "bindings", ts(export))]
3730pub struct LateralView {
3731    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3732    pub this: Expression,
3733    /// Table alias for the generated table
3734    pub table_alias: Option<Identifier>,
3735    /// Column aliases for the generated columns
3736    pub column_aliases: Vec<Identifier>,
3737    /// OUTER keyword - preserve nulls when input is empty/null
3738    pub outer: bool,
3739}
3740
3741/// Query hint
3742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3743#[cfg_attr(feature = "bindings", derive(TS))]
3744#[cfg_attr(feature = "bindings", ts(export))]
3745pub struct Hint {
3746    pub expressions: Vec<HintExpression>,
3747}
3748
3749/// Individual hint expression
3750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3751#[cfg_attr(feature = "bindings", derive(TS))]
3752#[cfg_attr(feature = "bindings", ts(export))]
3753pub enum HintExpression {
3754    /// Function-style hint: USE_HASH(table)
3755    Function { name: String, args: Vec<Expression> },
3756    /// Simple identifier hint: PARALLEL
3757    Identifier(String),
3758    /// Raw hint text (unparsed)
3759    Raw(String),
3760}
3761
3762/// Pseudocolumn type
3763#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3764#[cfg_attr(feature = "bindings", derive(TS))]
3765#[cfg_attr(feature = "bindings", ts(export))]
3766pub enum PseudocolumnType {
3767    Rownum,      // Oracle ROWNUM
3768    Rowid,       // Oracle ROWID
3769    Level,       // Oracle LEVEL (for CONNECT BY)
3770    Sysdate,     // Oracle SYSDATE
3771    ObjectId,    // Oracle OBJECT_ID
3772    ObjectValue, // Oracle OBJECT_VALUE
3773}
3774
3775impl PseudocolumnType {
3776    pub fn as_str(&self) -> &'static str {
3777        match self {
3778            PseudocolumnType::Rownum => "ROWNUM",
3779            PseudocolumnType::Rowid => "ROWID",
3780            PseudocolumnType::Level => "LEVEL",
3781            PseudocolumnType::Sysdate => "SYSDATE",
3782            PseudocolumnType::ObjectId => "OBJECT_ID",
3783            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3784        }
3785    }
3786
3787    pub fn from_str(s: &str) -> Option<Self> {
3788        match s.to_uppercase().as_str() {
3789            "ROWNUM" => Some(PseudocolumnType::Rownum),
3790            "ROWID" => Some(PseudocolumnType::Rowid),
3791            "LEVEL" => Some(PseudocolumnType::Level),
3792            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3793            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3794            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3795            _ => None,
3796        }
3797    }
3798}
3799
3800/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3801/// These are special identifiers that should not be quoted
3802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3803#[cfg_attr(feature = "bindings", derive(TS))]
3804#[cfg_attr(feature = "bindings", ts(export))]
3805pub struct Pseudocolumn {
3806    pub kind: PseudocolumnType,
3807}
3808
3809impl Pseudocolumn {
3810    pub fn rownum() -> Self {
3811        Self {
3812            kind: PseudocolumnType::Rownum,
3813        }
3814    }
3815
3816    pub fn rowid() -> Self {
3817        Self {
3818            kind: PseudocolumnType::Rowid,
3819        }
3820    }
3821
3822    pub fn level() -> Self {
3823        Self {
3824            kind: PseudocolumnType::Level,
3825        }
3826    }
3827}
3828
3829/// Oracle CONNECT BY clause for hierarchical queries
3830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3831#[cfg_attr(feature = "bindings", derive(TS))]
3832#[cfg_attr(feature = "bindings", ts(export))]
3833pub struct Connect {
3834    /// START WITH condition (optional, can come before or after CONNECT BY)
3835    pub start: Option<Expression>,
3836    /// CONNECT BY condition (required, contains PRIOR references)
3837    pub connect: Expression,
3838    /// NOCYCLE keyword to prevent infinite loops
3839    pub nocycle: bool,
3840}
3841
3842/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3844#[cfg_attr(feature = "bindings", derive(TS))]
3845#[cfg_attr(feature = "bindings", ts(export))]
3846pub struct Prior {
3847    pub this: Expression,
3848}
3849
3850/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3852#[cfg_attr(feature = "bindings", derive(TS))]
3853#[cfg_attr(feature = "bindings", ts(export))]
3854pub struct ConnectByRoot {
3855    pub this: Expression,
3856}
3857
3858/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3860#[cfg_attr(feature = "bindings", derive(TS))]
3861#[cfg_attr(feature = "bindings", ts(export))]
3862pub struct MatchRecognize {
3863    /// Source table/expression
3864    pub this: Option<Box<Expression>>,
3865    /// PARTITION BY expressions
3866    pub partition_by: Option<Vec<Expression>>,
3867    /// ORDER BY expressions
3868    pub order_by: Option<Vec<Ordered>>,
3869    /// MEASURES definitions
3870    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3871    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3872    pub rows: Option<MatchRecognizeRows>,
3873    /// AFTER MATCH SKIP behavior
3874    pub after: Option<MatchRecognizeAfter>,
3875    /// PATTERN definition (stored as raw string for complex regex patterns)
3876    pub pattern: Option<String>,
3877    /// DEFINE clauses (pattern variable definitions)
3878    pub define: Option<Vec<(Identifier, Expression)>>,
3879    /// Optional alias for the result
3880    pub alias: Option<Identifier>,
3881    /// Whether AS keyword was explicitly present before alias
3882    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3883    pub alias_explicit_as: bool,
3884}
3885
3886/// MEASURES expression with optional RUNNING/FINAL semantics
3887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3888#[cfg_attr(feature = "bindings", derive(TS))]
3889#[cfg_attr(feature = "bindings", ts(export))]
3890pub struct MatchRecognizeMeasure {
3891    /// The measure expression
3892    pub this: Expression,
3893    /// RUNNING or FINAL semantics (Snowflake-specific)
3894    pub window_frame: Option<MatchRecognizeSemantics>,
3895}
3896
3897/// Semantics for MEASURES in MATCH_RECOGNIZE
3898#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3899#[cfg_attr(feature = "bindings", derive(TS))]
3900#[cfg_attr(feature = "bindings", ts(export))]
3901pub enum MatchRecognizeSemantics {
3902    Running,
3903    Final,
3904}
3905
3906/// Row output semantics for MATCH_RECOGNIZE
3907#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3908#[cfg_attr(feature = "bindings", derive(TS))]
3909#[cfg_attr(feature = "bindings", ts(export))]
3910pub enum MatchRecognizeRows {
3911    OneRowPerMatch,
3912    AllRowsPerMatch,
3913    AllRowsPerMatchShowEmptyMatches,
3914    AllRowsPerMatchOmitEmptyMatches,
3915    AllRowsPerMatchWithUnmatchedRows,
3916}
3917
3918/// AFTER MATCH SKIP behavior
3919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3920#[cfg_attr(feature = "bindings", derive(TS))]
3921#[cfg_attr(feature = "bindings", ts(export))]
3922pub enum MatchRecognizeAfter {
3923    PastLastRow,
3924    ToNextRow,
3925    ToFirst(Identifier),
3926    ToLast(Identifier),
3927}
3928
3929/// Represent a LIMIT clause that restricts the number of returned rows.
3930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3931#[cfg_attr(feature = "bindings", derive(TS))]
3932pub struct Limit {
3933    /// The limit count expression.
3934    pub this: Expression,
3935    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3936    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3937    pub percent: bool,
3938    /// Comments from before the LIMIT keyword (emitted after the limit value)
3939    #[serde(default)]
3940    #[serde(skip_serializing_if = "Vec::is_empty")]
3941    pub comments: Vec<String>,
3942}
3943
3944/// OFFSET clause
3945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3946#[cfg_attr(feature = "bindings", derive(TS))]
3947pub struct Offset {
3948    pub this: Expression,
3949    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3950    #[serde(skip_serializing_if = "Option::is_none", default)]
3951    pub rows: Option<bool>,
3952}
3953
3954/// TOP clause (SQL Server)
3955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3956#[cfg_attr(feature = "bindings", derive(TS))]
3957pub struct Top {
3958    pub this: Expression,
3959    pub percent: bool,
3960    pub with_ties: bool,
3961    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3962    #[serde(default)]
3963    pub parenthesized: bool,
3964}
3965
3966/// FETCH FIRST/NEXT clause (SQL standard)
3967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3968#[cfg_attr(feature = "bindings", derive(TS))]
3969pub struct Fetch {
3970    /// FIRST or NEXT
3971    pub direction: String,
3972    /// Count expression (optional)
3973    pub count: Option<Expression>,
3974    /// PERCENT modifier
3975    pub percent: bool,
3976    /// ROWS or ROW keyword present
3977    pub rows: bool,
3978    /// WITH TIES modifier
3979    pub with_ties: bool,
3980}
3981
3982/// Represent a QUALIFY clause for filtering on window function results.
3983///
3984/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3985/// typically references a window function (e.g.
3986/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3988#[cfg_attr(feature = "bindings", derive(TS))]
3989pub struct Qualify {
3990    /// The filter predicate over window function results.
3991    pub this: Expression,
3992}
3993
3994/// SAMPLE / TABLESAMPLE clause
3995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3996#[cfg_attr(feature = "bindings", derive(TS))]
3997pub struct Sample {
3998    pub method: SampleMethod,
3999    pub size: Expression,
4000    pub seed: Option<Expression>,
4001    /// ClickHouse OFFSET expression after SAMPLE size
4002    #[serde(default)]
4003    pub offset: Option<Expression>,
4004    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
4005    pub unit_after_size: bool,
4006    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
4007    #[serde(default)]
4008    pub use_sample_keyword: bool,
4009    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
4010    #[serde(default)]
4011    pub explicit_method: bool,
4012    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
4013    #[serde(default)]
4014    pub method_before_size: bool,
4015    /// Whether SEED keyword was used (true) or REPEATABLE (false)
4016    #[serde(default)]
4017    pub use_seed_keyword: bool,
4018    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
4019    pub bucket_numerator: Option<Box<Expression>>,
4020    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
4021    pub bucket_denominator: Option<Box<Expression>>,
4022    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
4023    pub bucket_field: Option<Box<Expression>>,
4024    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
4025    #[serde(default)]
4026    pub is_using_sample: bool,
4027    /// Whether the unit was explicitly PERCENT (vs ROWS)
4028    #[serde(default)]
4029    pub is_percent: bool,
4030    /// Whether to suppress method output (for cross-dialect transpilation)
4031    #[serde(default)]
4032    pub suppress_method_output: bool,
4033}
4034
4035/// Sample method
4036#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4037#[cfg_attr(feature = "bindings", derive(TS))]
4038pub enum SampleMethod {
4039    Bernoulli,
4040    System,
4041    Block,
4042    Row,
4043    Percent,
4044    /// Hive bucket sampling
4045    Bucket,
4046    /// DuckDB reservoir sampling
4047    Reservoir,
4048}
4049
4050/// Named window definition (WINDOW w AS (...))
4051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4052#[cfg_attr(feature = "bindings", derive(TS))]
4053pub struct NamedWindow {
4054    pub name: Identifier,
4055    pub spec: Over,
4056}
4057
4058/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
4059///
4060/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
4061/// that reference themselves. Each CTE is defined in the `ctes` vector and
4062/// can be referenced by name in subsequent CTEs and in the main query body.
4063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4064#[cfg_attr(feature = "bindings", derive(TS))]
4065pub struct With {
4066    /// The list of CTE definitions, in order.
4067    pub ctes: Vec<Cte>,
4068    /// Whether the WITH RECURSIVE keyword was used.
4069    pub recursive: bool,
4070    /// Leading comments before the statement
4071    #[serde(default)]
4072    pub leading_comments: Vec<String>,
4073    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
4074    #[serde(default, skip_serializing_if = "Option::is_none")]
4075    pub search: Option<Box<Expression>>,
4076}
4077
4078/// Represent a single Common Table Expression definition.
4079///
4080/// A CTE has a name (`alias`), an optional column list, and a body query.
4081/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
4082/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
4083/// the expression comes before the alias (`alias_first`).
4084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4085#[cfg_attr(feature = "bindings", derive(TS))]
4086pub struct Cte {
4087    /// The CTE name.
4088    pub alias: Identifier,
4089    /// The CTE body (typically a SELECT, UNION, etc.).
4090    pub this: Expression,
4091    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
4092    pub columns: Vec<Identifier>,
4093    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
4094    pub materialized: Option<bool>,
4095    /// USING KEY (columns) for DuckDB recursive CTEs
4096    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4097    pub key_expressions: Vec<Identifier>,
4098    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
4099    #[serde(default)]
4100    pub alias_first: bool,
4101    /// Comments associated with this CTE (placed after alias name, before AS)
4102    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4103    pub comments: Vec<String>,
4104}
4105
4106/// Window specification
4107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4108#[cfg_attr(feature = "bindings", derive(TS))]
4109pub struct WindowSpec {
4110    pub partition_by: Vec<Expression>,
4111    pub order_by: Vec<Ordered>,
4112    pub frame: Option<WindowFrame>,
4113}
4114
4115/// OVER clause
4116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4117#[cfg_attr(feature = "bindings", derive(TS))]
4118pub struct Over {
4119    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
4120    pub window_name: Option<Identifier>,
4121    pub partition_by: Vec<Expression>,
4122    pub order_by: Vec<Ordered>,
4123    pub frame: Option<WindowFrame>,
4124    pub alias: Option<Identifier>,
4125}
4126
4127/// Window frame
4128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4129#[cfg_attr(feature = "bindings", derive(TS))]
4130pub struct WindowFrame {
4131    pub kind: WindowFrameKind,
4132    pub start: WindowFrameBound,
4133    pub end: Option<WindowFrameBound>,
4134    pub exclude: Option<WindowFrameExclude>,
4135    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
4136    #[serde(default, skip_serializing_if = "Option::is_none")]
4137    pub kind_text: Option<String>,
4138    /// Original text of the start bound side keyword (e.g. "preceding")
4139    #[serde(default, skip_serializing_if = "Option::is_none")]
4140    pub start_side_text: Option<String>,
4141    /// Original text of the end bound side keyword
4142    #[serde(default, skip_serializing_if = "Option::is_none")]
4143    pub end_side_text: Option<String>,
4144}
4145
4146#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4147#[cfg_attr(feature = "bindings", derive(TS))]
4148pub enum WindowFrameKind {
4149    Rows,
4150    Range,
4151    Groups,
4152}
4153
4154/// EXCLUDE clause for window frames
4155#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4156#[cfg_attr(feature = "bindings", derive(TS))]
4157pub enum WindowFrameExclude {
4158    CurrentRow,
4159    Group,
4160    Ties,
4161    NoOthers,
4162}
4163
4164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4165#[cfg_attr(feature = "bindings", derive(TS))]
4166pub enum WindowFrameBound {
4167    CurrentRow,
4168    UnboundedPreceding,
4169    UnboundedFollowing,
4170    Preceding(Box<Expression>),
4171    Following(Box<Expression>),
4172    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
4173    BarePreceding,
4174    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
4175    BareFollowing,
4176    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
4177    Value(Box<Expression>),
4178}
4179
4180/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
4181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4182#[cfg_attr(feature = "bindings", derive(TS))]
4183pub struct StructField {
4184    pub name: String,
4185    pub data_type: DataType,
4186    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4187    pub options: Vec<Expression>,
4188    #[serde(default, skip_serializing_if = "Option::is_none")]
4189    pub comment: Option<String>,
4190}
4191
4192impl StructField {
4193    /// Create a new struct field without options
4194    pub fn new(name: String, data_type: DataType) -> Self {
4195        Self {
4196            name,
4197            data_type,
4198            options: Vec::new(),
4199            comment: None,
4200        }
4201    }
4202
4203    /// Create a new struct field with options
4204    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
4205        Self {
4206            name,
4207            data_type,
4208            options,
4209            comment: None,
4210        }
4211    }
4212
4213    /// Create a new struct field with options and comment
4214    pub fn with_options_and_comment(
4215        name: String,
4216        data_type: DataType,
4217        options: Vec<Expression>,
4218        comment: Option<String>,
4219    ) -> Self {
4220        Self {
4221            name,
4222            data_type,
4223            options,
4224            comment,
4225        }
4226    }
4227}
4228
4229/// Enumerate all SQL data types recognized by the parser.
4230///
4231/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
4232/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
4233/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
4234///
4235/// This enum is used in CAST expressions, column definitions, function return
4236/// types, and anywhere a data type specification appears in SQL.
4237///
4238/// Types that do not match any known variant fall through to `Custom { name }`,
4239/// preserving the original type name for round-trip fidelity.
4240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4241#[cfg_attr(feature = "bindings", derive(TS))]
4242#[serde(tag = "data_type", rename_all = "snake_case")]
4243pub enum DataType {
4244    // Numeric
4245    Boolean,
4246    TinyInt {
4247        length: Option<u32>,
4248    },
4249    SmallInt {
4250        length: Option<u32>,
4251    },
4252    /// Int type with optional length. `integer_spelling` indicates whether the original
4253    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
4254    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
4255    Int {
4256        length: Option<u32>,
4257        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4258        integer_spelling: bool,
4259    },
4260    BigInt {
4261        length: Option<u32>,
4262    },
4263    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
4264    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
4265    /// preserve the original spelling.
4266    Float {
4267        precision: Option<u32>,
4268        scale: Option<u32>,
4269        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4270        real_spelling: bool,
4271    },
4272    Double {
4273        precision: Option<u32>,
4274        scale: Option<u32>,
4275    },
4276    Decimal {
4277        precision: Option<u32>,
4278        scale: Option<u32>,
4279    },
4280
4281    // String
4282    Char {
4283        length: Option<u32>,
4284    },
4285    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
4286    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
4287    VarChar {
4288        length: Option<u32>,
4289        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4290        parenthesized_length: bool,
4291    },
4292    /// String type with optional max length (BigQuery STRING(n))
4293    String {
4294        length: Option<u32>,
4295    },
4296    Text,
4297    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
4298    TextWithLength {
4299        length: u32,
4300    },
4301
4302    // Binary
4303    Binary {
4304        length: Option<u32>,
4305    },
4306    VarBinary {
4307        length: Option<u32>,
4308    },
4309    Blob,
4310
4311    // Bit
4312    Bit {
4313        length: Option<u32>,
4314    },
4315    VarBit {
4316        length: Option<u32>,
4317    },
4318
4319    // Date/Time
4320    Date,
4321    Time {
4322        precision: Option<u32>,
4323        #[serde(default)]
4324        timezone: bool,
4325    },
4326    Timestamp {
4327        precision: Option<u32>,
4328        timezone: bool,
4329    },
4330    Interval {
4331        unit: Option<String>,
4332        /// For range intervals like INTERVAL DAY TO HOUR
4333        #[serde(default, skip_serializing_if = "Option::is_none")]
4334        to: Option<String>,
4335    },
4336
4337    // JSON
4338    Json,
4339    JsonB,
4340
4341    // UUID
4342    Uuid,
4343
4344    // Array
4345    Array {
4346        element_type: Box<DataType>,
4347        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
4348        #[serde(default, skip_serializing_if = "Option::is_none")]
4349        dimension: Option<u32>,
4350    },
4351
4352    /// List type (Materialize): INT LIST, TEXT LIST LIST
4353    /// Uses postfix LIST syntax instead of ARRAY<T>
4354    List {
4355        element_type: Box<DataType>,
4356    },
4357
4358    // Struct/Map
4359    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
4360    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
4361    Struct {
4362        fields: Vec<StructField>,
4363        nested: bool,
4364    },
4365    Map {
4366        key_type: Box<DataType>,
4367        value_type: Box<DataType>,
4368    },
4369
4370    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
4371    Enum {
4372        values: Vec<String>,
4373        #[serde(default, skip_serializing_if = "Vec::is_empty")]
4374        assignments: Vec<Option<String>>,
4375    },
4376
4377    // Set type (MySQL): SET('a', 'b', 'c')
4378    Set {
4379        values: Vec<String>,
4380    },
4381
4382    // Union type (DuckDB): UNION(num INT, str TEXT)
4383    Union {
4384        fields: Vec<(String, DataType)>,
4385    },
4386
4387    // Vector (Snowflake / SingleStore)
4388    Vector {
4389        #[serde(default)]
4390        element_type: Option<Box<DataType>>,
4391        dimension: Option<u32>,
4392    },
4393
4394    // Object (Snowflake structured type)
4395    // fields: Vec of (field_name, field_type, not_null)
4396    Object {
4397        fields: Vec<(String, DataType, bool)>,
4398        modifier: Option<String>,
4399    },
4400
4401    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
4402    Nullable {
4403        inner: Box<DataType>,
4404    },
4405
4406    // Custom/User-defined
4407    Custom {
4408        name: String,
4409    },
4410
4411    // Spatial types
4412    Geometry {
4413        subtype: Option<String>,
4414        srid: Option<u32>,
4415    },
4416    Geography {
4417        subtype: Option<String>,
4418        srid: Option<u32>,
4419    },
4420
4421    // Character Set (for CONVERT USING in MySQL)
4422    // Renders as CHAR CHARACTER SET {name} in cast target
4423    CharacterSet {
4424        name: String,
4425    },
4426
4427    // Unknown
4428    Unknown,
4429}
4430
4431/// Array expression
4432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4433#[cfg_attr(feature = "bindings", derive(TS))]
4434#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
4435pub struct Array {
4436    pub expressions: Vec<Expression>,
4437}
4438
4439/// Struct expression
4440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4441#[cfg_attr(feature = "bindings", derive(TS))]
4442pub struct Struct {
4443    pub fields: Vec<(Option<String>, Expression)>,
4444}
4445
4446/// Tuple expression
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct Tuple {
4450    pub expressions: Vec<Expression>,
4451}
4452
4453/// Interval expression
4454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4455#[cfg_attr(feature = "bindings", derive(TS))]
4456pub struct Interval {
4457    /// The value expression (e.g., '1', 5, column_ref)
4458    pub this: Option<Expression>,
4459    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
4460    pub unit: Option<IntervalUnitSpec>,
4461}
4462
4463/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
4464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4465#[cfg_attr(feature = "bindings", derive(TS))]
4466#[serde(tag = "type", rename_all = "snake_case")]
4467pub enum IntervalUnitSpec {
4468    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
4469    Simple {
4470        unit: IntervalUnit,
4471        /// Whether to use plural form (e.g., DAYS vs DAY)
4472        use_plural: bool,
4473    },
4474    /// Interval span (e.g., HOUR TO SECOND)
4475    Span(IntervalSpan),
4476    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4477    /// The start and end can be expressions like function calls with precision
4478    ExprSpan(IntervalSpanExpr),
4479    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
4480    Expr(Box<Expression>),
4481}
4482
4483/// Interval span for ranges like HOUR TO SECOND
4484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4485#[cfg_attr(feature = "bindings", derive(TS))]
4486pub struct IntervalSpan {
4487    /// Start unit (e.g., HOUR)
4488    pub this: IntervalUnit,
4489    /// End unit (e.g., SECOND)
4490    pub expression: IntervalUnit,
4491}
4492
4493/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4494/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
4495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4496#[cfg_attr(feature = "bindings", derive(TS))]
4497pub struct IntervalSpanExpr {
4498    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
4499    pub this: Box<Expression>,
4500    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
4501    pub expression: Box<Expression>,
4502}
4503
4504#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4505#[cfg_attr(feature = "bindings", derive(TS))]
4506pub enum IntervalUnit {
4507    Year,
4508    Quarter,
4509    Month,
4510    Week,
4511    Day,
4512    Hour,
4513    Minute,
4514    Second,
4515    Millisecond,
4516    Microsecond,
4517    Nanosecond,
4518}
4519
4520/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4522#[cfg_attr(feature = "bindings", derive(TS))]
4523pub struct Command {
4524    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4525    pub this: String,
4526}
4527
4528/// EXEC/EXECUTE statement (TSQL stored procedure call)
4529/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4531#[cfg_attr(feature = "bindings", derive(TS))]
4532pub struct ExecuteStatement {
4533    /// The procedure name (can be qualified: schema.proc_name)
4534    pub this: Expression,
4535    /// Named parameters: @param=value pairs
4536    #[serde(default)]
4537    pub parameters: Vec<ExecuteParameter>,
4538}
4539
4540/// Named parameter in EXEC statement: @name=value
4541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4542#[cfg_attr(feature = "bindings", derive(TS))]
4543pub struct ExecuteParameter {
4544    /// Parameter name (including @)
4545    pub name: String,
4546    /// Parameter value
4547    pub value: Expression,
4548}
4549
4550/// KILL statement (MySQL/MariaDB)
4551/// KILL [CONNECTION | QUERY] <id>
4552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4553#[cfg_attr(feature = "bindings", derive(TS))]
4554pub struct Kill {
4555    /// The target (process ID or connection ID)
4556    pub this: Expression,
4557    /// Optional kind: "CONNECTION" or "QUERY"
4558    pub kind: Option<String>,
4559}
4560
4561/// Raw/unparsed SQL
4562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4563#[cfg_attr(feature = "bindings", derive(TS))]
4564pub struct Raw {
4565    pub sql: String,
4566}
4567
4568// ============================================================================
4569// Function expression types
4570// ============================================================================
4571
4572/// Generic unary function (takes a single argument)
4573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4574#[cfg_attr(feature = "bindings", derive(TS))]
4575pub struct UnaryFunc {
4576    pub this: Expression,
4577    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4578    #[serde(skip_serializing_if = "Option::is_none", default)]
4579    pub original_name: Option<String>,
4580    /// Inferred data type from type annotation
4581    #[serde(default, skip_serializing_if = "Option::is_none")]
4582    pub inferred_type: Option<DataType>,
4583}
4584
4585impl UnaryFunc {
4586    /// Create a new UnaryFunc with no original_name
4587    pub fn new(this: Expression) -> Self {
4588        Self {
4589            this,
4590            original_name: None,
4591            inferred_type: None,
4592        }
4593    }
4594
4595    /// Create a new UnaryFunc with an original name for round-trip preservation
4596    pub fn with_name(this: Expression, name: String) -> Self {
4597        Self {
4598            this,
4599            original_name: Some(name),
4600            inferred_type: None,
4601        }
4602    }
4603}
4604
4605/// CHAR/CHR function with multiple args and optional USING charset
4606/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4607/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4609#[cfg_attr(feature = "bindings", derive(TS))]
4610pub struct CharFunc {
4611    pub args: Vec<Expression>,
4612    #[serde(skip_serializing_if = "Option::is_none", default)]
4613    pub charset: Option<String>,
4614    /// Original function name (CHAR or CHR), defaults to CHAR
4615    #[serde(skip_serializing_if = "Option::is_none", default)]
4616    pub name: Option<String>,
4617}
4618
4619/// Generic binary function (takes two arguments)
4620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4621#[cfg_attr(feature = "bindings", derive(TS))]
4622pub struct BinaryFunc {
4623    pub this: Expression,
4624    pub expression: Expression,
4625    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4626    #[serde(skip_serializing_if = "Option::is_none", default)]
4627    pub original_name: Option<String>,
4628    /// Inferred data type from type annotation
4629    #[serde(default, skip_serializing_if = "Option::is_none")]
4630    pub inferred_type: Option<DataType>,
4631}
4632
4633/// Variable argument function
4634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4635#[cfg_attr(feature = "bindings", derive(TS))]
4636pub struct VarArgFunc {
4637    pub expressions: Vec<Expression>,
4638    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4639    #[serde(skip_serializing_if = "Option::is_none", default)]
4640    pub original_name: Option<String>,
4641    /// Inferred data type from type annotation
4642    #[serde(default, skip_serializing_if = "Option::is_none")]
4643    pub inferred_type: Option<DataType>,
4644}
4645
4646/// CONCAT_WS function
4647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4648#[cfg_attr(feature = "bindings", derive(TS))]
4649pub struct ConcatWs {
4650    pub separator: Expression,
4651    pub expressions: Vec<Expression>,
4652}
4653
4654/// SUBSTRING function
4655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4656#[cfg_attr(feature = "bindings", derive(TS))]
4657pub struct SubstringFunc {
4658    pub this: Expression,
4659    pub start: Expression,
4660    pub length: Option<Expression>,
4661    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4662    #[serde(default)]
4663    pub from_for_syntax: bool,
4664}
4665
4666/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4668#[cfg_attr(feature = "bindings", derive(TS))]
4669pub struct OverlayFunc {
4670    pub this: Expression,
4671    pub replacement: Expression,
4672    pub from: Expression,
4673    pub length: Option<Expression>,
4674}
4675
4676/// TRIM function
4677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4678#[cfg_attr(feature = "bindings", derive(TS))]
4679pub struct TrimFunc {
4680    pub this: Expression,
4681    pub characters: Option<Expression>,
4682    pub position: TrimPosition,
4683    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4684    #[serde(default)]
4685    pub sql_standard_syntax: bool,
4686    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4687    #[serde(default)]
4688    pub position_explicit: bool,
4689}
4690
4691#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4692#[cfg_attr(feature = "bindings", derive(TS))]
4693pub enum TrimPosition {
4694    Both,
4695    Leading,
4696    Trailing,
4697}
4698
4699/// REPLACE function
4700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4701#[cfg_attr(feature = "bindings", derive(TS))]
4702pub struct ReplaceFunc {
4703    pub this: Expression,
4704    pub old: Expression,
4705    pub new: Expression,
4706}
4707
4708/// LEFT/RIGHT function
4709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4710#[cfg_attr(feature = "bindings", derive(TS))]
4711pub struct LeftRightFunc {
4712    pub this: Expression,
4713    pub length: Expression,
4714}
4715
4716/// REPEAT function
4717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4718#[cfg_attr(feature = "bindings", derive(TS))]
4719pub struct RepeatFunc {
4720    pub this: Expression,
4721    pub times: Expression,
4722}
4723
4724/// LPAD/RPAD function
4725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4726#[cfg_attr(feature = "bindings", derive(TS))]
4727pub struct PadFunc {
4728    pub this: Expression,
4729    pub length: Expression,
4730    pub fill: Option<Expression>,
4731}
4732
4733/// SPLIT function
4734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4735#[cfg_attr(feature = "bindings", derive(TS))]
4736pub struct SplitFunc {
4737    pub this: Expression,
4738    pub delimiter: Expression,
4739}
4740
4741/// REGEXP_LIKE function
4742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4743#[cfg_attr(feature = "bindings", derive(TS))]
4744pub struct RegexpFunc {
4745    pub this: Expression,
4746    pub pattern: Expression,
4747    pub flags: Option<Expression>,
4748}
4749
4750/// REGEXP_REPLACE function
4751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4752#[cfg_attr(feature = "bindings", derive(TS))]
4753pub struct RegexpReplaceFunc {
4754    pub this: Expression,
4755    pub pattern: Expression,
4756    pub replacement: Expression,
4757    pub flags: Option<Expression>,
4758}
4759
4760/// REGEXP_EXTRACT function
4761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4762#[cfg_attr(feature = "bindings", derive(TS))]
4763pub struct RegexpExtractFunc {
4764    pub this: Expression,
4765    pub pattern: Expression,
4766    pub group: Option<Expression>,
4767}
4768
4769/// ROUND function
4770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4771#[cfg_attr(feature = "bindings", derive(TS))]
4772pub struct RoundFunc {
4773    pub this: Expression,
4774    pub decimals: Option<Expression>,
4775}
4776
4777/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4779#[cfg_attr(feature = "bindings", derive(TS))]
4780pub struct FloorFunc {
4781    pub this: Expression,
4782    pub scale: Option<Expression>,
4783    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4784    #[serde(skip_serializing_if = "Option::is_none", default)]
4785    pub to: Option<Expression>,
4786}
4787
4788/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4790#[cfg_attr(feature = "bindings", derive(TS))]
4791pub struct CeilFunc {
4792    pub this: Expression,
4793    #[serde(skip_serializing_if = "Option::is_none", default)]
4794    pub decimals: Option<Expression>,
4795    /// Time unit for Druid-style CEIL(time TO unit) syntax
4796    #[serde(skip_serializing_if = "Option::is_none", default)]
4797    pub to: Option<Expression>,
4798}
4799
4800/// LOG function
4801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4802#[cfg_attr(feature = "bindings", derive(TS))]
4803pub struct LogFunc {
4804    pub this: Expression,
4805    pub base: Option<Expression>,
4806}
4807
4808/// CURRENT_DATE (no arguments)
4809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4810#[cfg_attr(feature = "bindings", derive(TS))]
4811pub struct CurrentDate;
4812
4813/// CURRENT_TIME
4814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4815#[cfg_attr(feature = "bindings", derive(TS))]
4816pub struct CurrentTime {
4817    pub precision: Option<u32>,
4818}
4819
4820/// CURRENT_TIMESTAMP
4821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4822#[cfg_attr(feature = "bindings", derive(TS))]
4823pub struct CurrentTimestamp {
4824    pub precision: Option<u32>,
4825    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4826    #[serde(default)]
4827    pub sysdate: bool,
4828}
4829
4830/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4832#[cfg_attr(feature = "bindings", derive(TS))]
4833pub struct CurrentTimestampLTZ {
4834    pub precision: Option<u32>,
4835}
4836
4837/// AT TIME ZONE expression for timezone conversion
4838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4839#[cfg_attr(feature = "bindings", derive(TS))]
4840pub struct AtTimeZone {
4841    /// The expression to convert
4842    pub this: Expression,
4843    /// The target timezone
4844    pub zone: Expression,
4845}
4846
4847/// DATE_ADD / DATE_SUB function
4848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4849#[cfg_attr(feature = "bindings", derive(TS))]
4850pub struct DateAddFunc {
4851    pub this: Expression,
4852    pub interval: Expression,
4853    pub unit: IntervalUnit,
4854}
4855
4856/// DATEDIFF function
4857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4858#[cfg_attr(feature = "bindings", derive(TS))]
4859pub struct DateDiffFunc {
4860    pub this: Expression,
4861    pub expression: Expression,
4862    pub unit: Option<IntervalUnit>,
4863}
4864
4865/// DATE_TRUNC function
4866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4867#[cfg_attr(feature = "bindings", derive(TS))]
4868pub struct DateTruncFunc {
4869    pub this: Expression,
4870    pub unit: DateTimeField,
4871}
4872
4873/// EXTRACT function
4874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4875#[cfg_attr(feature = "bindings", derive(TS))]
4876pub struct ExtractFunc {
4877    pub this: Expression,
4878    pub field: DateTimeField,
4879}
4880
4881#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4882#[cfg_attr(feature = "bindings", derive(TS))]
4883pub enum DateTimeField {
4884    Year,
4885    Month,
4886    Day,
4887    Hour,
4888    Minute,
4889    Second,
4890    Millisecond,
4891    Microsecond,
4892    DayOfWeek,
4893    DayOfYear,
4894    Week,
4895    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4896    WeekWithModifier(String),
4897    Quarter,
4898    Epoch,
4899    Timezone,
4900    TimezoneHour,
4901    TimezoneMinute,
4902    Date,
4903    Time,
4904    /// Custom datetime field for dialect-specific or arbitrary fields
4905    Custom(String),
4906}
4907
4908/// TO_DATE function
4909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4910#[cfg_attr(feature = "bindings", derive(TS))]
4911pub struct ToDateFunc {
4912    pub this: Expression,
4913    pub format: Option<Expression>,
4914}
4915
4916/// TO_TIMESTAMP function
4917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4918#[cfg_attr(feature = "bindings", derive(TS))]
4919pub struct ToTimestampFunc {
4920    pub this: Expression,
4921    pub format: Option<Expression>,
4922}
4923
4924/// IF function
4925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4926#[cfg_attr(feature = "bindings", derive(TS))]
4927pub struct IfFunc {
4928    pub condition: Expression,
4929    pub true_value: Expression,
4930    pub false_value: Option<Expression>,
4931    /// Original function name (IF, IFF, IIF) for round-trip preservation
4932    #[serde(skip_serializing_if = "Option::is_none", default)]
4933    pub original_name: Option<String>,
4934    /// Inferred data type from type annotation
4935    #[serde(default, skip_serializing_if = "Option::is_none")]
4936    pub inferred_type: Option<DataType>,
4937}
4938
4939/// NVL2 function
4940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4941#[cfg_attr(feature = "bindings", derive(TS))]
4942pub struct Nvl2Func {
4943    pub this: Expression,
4944    pub true_value: Expression,
4945    pub false_value: Expression,
4946    /// Inferred data type from type annotation
4947    #[serde(default, skip_serializing_if = "Option::is_none")]
4948    pub inferred_type: Option<DataType>,
4949}
4950
4951// ============================================================================
4952// Typed Aggregate Function types
4953// ============================================================================
4954
4955/// Generic aggregate function base type
4956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4957#[cfg_attr(feature = "bindings", derive(TS))]
4958pub struct AggFunc {
4959    pub this: Expression,
4960    pub distinct: bool,
4961    pub filter: Option<Expression>,
4962    pub order_by: Vec<Ordered>,
4963    /// Original function name (case-preserving) when parsed from SQL
4964    #[serde(skip_serializing_if = "Option::is_none", default)]
4965    pub name: Option<String>,
4966    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4967    #[serde(skip_serializing_if = "Option::is_none", default)]
4968    pub ignore_nulls: Option<bool>,
4969    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4970    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4971    #[serde(skip_serializing_if = "Option::is_none", default)]
4972    pub having_max: Option<(Box<Expression>, bool)>,
4973    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4974    #[serde(skip_serializing_if = "Option::is_none", default)]
4975    pub limit: Option<Box<Expression>>,
4976    /// Inferred data type from type annotation
4977    #[serde(default, skip_serializing_if = "Option::is_none")]
4978    pub inferred_type: Option<DataType>,
4979}
4980
4981/// COUNT function with optional star
4982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4983#[cfg_attr(feature = "bindings", derive(TS))]
4984pub struct CountFunc {
4985    pub this: Option<Expression>,
4986    pub star: bool,
4987    pub distinct: bool,
4988    pub filter: Option<Expression>,
4989    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4990    #[serde(default, skip_serializing_if = "Option::is_none")]
4991    pub ignore_nulls: Option<bool>,
4992    /// Original function name for case preservation (e.g., "count" or "COUNT")
4993    #[serde(default, skip_serializing_if = "Option::is_none")]
4994    pub original_name: Option<String>,
4995    /// Inferred data type from type annotation
4996    #[serde(default, skip_serializing_if = "Option::is_none")]
4997    pub inferred_type: Option<DataType>,
4998}
4999
5000/// GROUP_CONCAT function (MySQL style)
5001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5002#[cfg_attr(feature = "bindings", derive(TS))]
5003pub struct GroupConcatFunc {
5004    pub this: Expression,
5005    pub separator: Option<Expression>,
5006    pub order_by: Option<Vec<Ordered>>,
5007    pub distinct: bool,
5008    pub filter: Option<Expression>,
5009    /// Inferred data type from type annotation
5010    #[serde(default, skip_serializing_if = "Option::is_none")]
5011    pub inferred_type: Option<DataType>,
5012}
5013
5014/// STRING_AGG function (PostgreSQL/Standard SQL)
5015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5016#[cfg_attr(feature = "bindings", derive(TS))]
5017pub struct StringAggFunc {
5018    pub this: Expression,
5019    #[serde(default)]
5020    pub separator: Option<Expression>,
5021    #[serde(default)]
5022    pub order_by: Option<Vec<Ordered>>,
5023    #[serde(default)]
5024    pub distinct: bool,
5025    #[serde(default)]
5026    pub filter: Option<Expression>,
5027    /// BigQuery LIMIT inside STRING_AGG
5028    #[serde(default, skip_serializing_if = "Option::is_none")]
5029    pub limit: Option<Box<Expression>>,
5030    /// Inferred data type from type annotation
5031    #[serde(default, skip_serializing_if = "Option::is_none")]
5032    pub inferred_type: Option<DataType>,
5033}
5034
5035/// LISTAGG function (Oracle style)
5036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5037#[cfg_attr(feature = "bindings", derive(TS))]
5038pub struct ListAggFunc {
5039    pub this: Expression,
5040    pub separator: Option<Expression>,
5041    pub on_overflow: Option<ListAggOverflow>,
5042    pub order_by: Option<Vec<Ordered>>,
5043    pub distinct: bool,
5044    pub filter: Option<Expression>,
5045    /// Inferred data type from type annotation
5046    #[serde(default, skip_serializing_if = "Option::is_none")]
5047    pub inferred_type: Option<DataType>,
5048}
5049
5050/// LISTAGG ON OVERFLOW behavior
5051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5052#[cfg_attr(feature = "bindings", derive(TS))]
5053pub enum ListAggOverflow {
5054    Error,
5055    Truncate {
5056        filler: Option<Expression>,
5057        with_count: bool,
5058    },
5059}
5060
5061/// SUM_IF / COUNT_IF function
5062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5063#[cfg_attr(feature = "bindings", derive(TS))]
5064pub struct SumIfFunc {
5065    pub this: Expression,
5066    pub condition: Expression,
5067    pub filter: Option<Expression>,
5068    /// Inferred data type from type annotation
5069    #[serde(default, skip_serializing_if = "Option::is_none")]
5070    pub inferred_type: Option<DataType>,
5071}
5072
5073/// APPROX_PERCENTILE function
5074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5075#[cfg_attr(feature = "bindings", derive(TS))]
5076pub struct ApproxPercentileFunc {
5077    pub this: Expression,
5078    pub percentile: Expression,
5079    pub accuracy: Option<Expression>,
5080    pub filter: Option<Expression>,
5081}
5082
5083/// PERCENTILE_CONT / PERCENTILE_DISC function
5084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5085#[cfg_attr(feature = "bindings", derive(TS))]
5086pub struct PercentileFunc {
5087    pub this: Expression,
5088    pub percentile: Expression,
5089    pub order_by: Option<Vec<Ordered>>,
5090    pub filter: Option<Expression>,
5091}
5092
5093// ============================================================================
5094// Typed Window Function types
5095// ============================================================================
5096
5097/// ROW_NUMBER function (no arguments)
5098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5099#[cfg_attr(feature = "bindings", derive(TS))]
5100pub struct RowNumber;
5101
5102/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5104#[cfg_attr(feature = "bindings", derive(TS))]
5105pub struct Rank {
5106    /// DuckDB: RANK(ORDER BY col) - order by inside function
5107    #[serde(default, skip_serializing_if = "Option::is_none")]
5108    pub order_by: Option<Vec<Ordered>>,
5109    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5110    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5111    pub args: Vec<Expression>,
5112}
5113
5114/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
5115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5116#[cfg_attr(feature = "bindings", derive(TS))]
5117pub struct DenseRank {
5118    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5119    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5120    pub args: Vec<Expression>,
5121}
5122
5123/// NTILE function (DuckDB allows ORDER BY inside)
5124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5125#[cfg_attr(feature = "bindings", derive(TS))]
5126pub struct NTileFunc {
5127    /// num_buckets is optional to support Databricks NTILE() without arguments
5128    #[serde(default, skip_serializing_if = "Option::is_none")]
5129    pub num_buckets: Option<Expression>,
5130    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
5131    #[serde(default, skip_serializing_if = "Option::is_none")]
5132    pub order_by: Option<Vec<Ordered>>,
5133}
5134
5135/// LEAD / LAG function
5136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5137#[cfg_attr(feature = "bindings", derive(TS))]
5138pub struct LeadLagFunc {
5139    pub this: Expression,
5140    pub offset: Option<Expression>,
5141    pub default: Option<Expression>,
5142    pub ignore_nulls: bool,
5143}
5144
5145/// FIRST_VALUE / LAST_VALUE function
5146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5147#[cfg_attr(feature = "bindings", derive(TS))]
5148pub struct ValueFunc {
5149    pub this: Expression,
5150    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5151    #[serde(default, skip_serializing_if = "Option::is_none")]
5152    pub ignore_nulls: Option<bool>,
5153}
5154
5155/// NTH_VALUE function
5156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5157#[cfg_attr(feature = "bindings", derive(TS))]
5158pub struct NthValueFunc {
5159    pub this: Expression,
5160    pub offset: Expression,
5161    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5162    #[serde(default, skip_serializing_if = "Option::is_none")]
5163    pub ignore_nulls: Option<bool>,
5164    /// Snowflake FROM FIRST / FROM LAST clause
5165    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
5166    #[serde(default, skip_serializing_if = "Option::is_none")]
5167    pub from_first: Option<bool>,
5168}
5169
5170/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5172#[cfg_attr(feature = "bindings", derive(TS))]
5173pub struct PercentRank {
5174    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
5175    #[serde(default, skip_serializing_if = "Option::is_none")]
5176    pub order_by: Option<Vec<Ordered>>,
5177    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5178    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5179    pub args: Vec<Expression>,
5180}
5181
5182/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5184#[cfg_attr(feature = "bindings", derive(TS))]
5185pub struct CumeDist {
5186    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
5187    #[serde(default, skip_serializing_if = "Option::is_none")]
5188    pub order_by: Option<Vec<Ordered>>,
5189    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5190    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5191    pub args: Vec<Expression>,
5192}
5193
5194// ============================================================================
5195// Additional String Function types
5196// ============================================================================
5197
5198/// POSITION/INSTR function
5199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5200#[cfg_attr(feature = "bindings", derive(TS))]
5201pub struct PositionFunc {
5202    pub substring: Expression,
5203    pub string: Expression,
5204    pub start: Option<Expression>,
5205}
5206
5207// ============================================================================
5208// Additional Math Function types
5209// ============================================================================
5210
5211/// RANDOM function (no arguments)
5212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5213#[cfg_attr(feature = "bindings", derive(TS))]
5214pub struct Random;
5215
5216/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
5217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5218#[cfg_attr(feature = "bindings", derive(TS))]
5219pub struct Rand {
5220    pub seed: Option<Box<Expression>>,
5221    /// Teradata RANDOM lower bound
5222    #[serde(default)]
5223    pub lower: Option<Box<Expression>>,
5224    /// Teradata RANDOM upper bound
5225    #[serde(default)]
5226    pub upper: Option<Box<Expression>>,
5227}
5228
5229/// TRUNCATE / TRUNC function
5230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5231#[cfg_attr(feature = "bindings", derive(TS))]
5232pub struct TruncateFunc {
5233    pub this: Expression,
5234    pub decimals: Option<Expression>,
5235}
5236
5237/// PI function (no arguments)
5238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5239#[cfg_attr(feature = "bindings", derive(TS))]
5240pub struct Pi;
5241
5242// ============================================================================
5243// Control Flow Function types
5244// ============================================================================
5245
5246/// DECODE function (Oracle style)
5247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5248#[cfg_attr(feature = "bindings", derive(TS))]
5249pub struct DecodeFunc {
5250    pub this: Expression,
5251    pub search_results: Vec<(Expression, Expression)>,
5252    pub default: Option<Expression>,
5253}
5254
5255// ============================================================================
5256// Additional Date/Time Function types
5257// ============================================================================
5258
5259/// DATE_FORMAT / FORMAT_DATE function
5260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5261#[cfg_attr(feature = "bindings", derive(TS))]
5262pub struct DateFormatFunc {
5263    pub this: Expression,
5264    pub format: Expression,
5265}
5266
5267/// FROM_UNIXTIME function
5268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5269#[cfg_attr(feature = "bindings", derive(TS))]
5270pub struct FromUnixtimeFunc {
5271    pub this: Expression,
5272    pub format: Option<Expression>,
5273}
5274
5275/// UNIX_TIMESTAMP function
5276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5277#[cfg_attr(feature = "bindings", derive(TS))]
5278pub struct UnixTimestampFunc {
5279    pub this: Option<Expression>,
5280    pub format: Option<Expression>,
5281}
5282
5283/// MAKE_DATE function
5284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5285#[cfg_attr(feature = "bindings", derive(TS))]
5286pub struct MakeDateFunc {
5287    pub year: Expression,
5288    pub month: Expression,
5289    pub day: Expression,
5290}
5291
5292/// MAKE_TIMESTAMP function
5293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5294#[cfg_attr(feature = "bindings", derive(TS))]
5295pub struct MakeTimestampFunc {
5296    pub year: Expression,
5297    pub month: Expression,
5298    pub day: Expression,
5299    pub hour: Expression,
5300    pub minute: Expression,
5301    pub second: Expression,
5302    pub timezone: Option<Expression>,
5303}
5304
5305/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
5306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5307#[cfg_attr(feature = "bindings", derive(TS))]
5308pub struct LastDayFunc {
5309    pub this: Expression,
5310    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
5311    #[serde(skip_serializing_if = "Option::is_none", default)]
5312    pub unit: Option<DateTimeField>,
5313}
5314
5315// ============================================================================
5316// Array Function types
5317// ============================================================================
5318
5319/// ARRAY constructor
5320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5321#[cfg_attr(feature = "bindings", derive(TS))]
5322pub struct ArrayConstructor {
5323    pub expressions: Vec<Expression>,
5324    pub bracket_notation: bool,
5325    /// True if LIST keyword was used instead of ARRAY (DuckDB)
5326    pub use_list_keyword: bool,
5327}
5328
5329/// ARRAY_SORT function
5330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5331#[cfg_attr(feature = "bindings", derive(TS))]
5332pub struct ArraySortFunc {
5333    pub this: Expression,
5334    pub comparator: Option<Expression>,
5335    pub desc: bool,
5336    pub nulls_first: Option<bool>,
5337}
5338
5339/// ARRAY_JOIN / ARRAY_TO_STRING function
5340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5341#[cfg_attr(feature = "bindings", derive(TS))]
5342pub struct ArrayJoinFunc {
5343    pub this: Expression,
5344    pub separator: Expression,
5345    pub null_replacement: Option<Expression>,
5346}
5347
5348/// UNNEST function
5349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5350#[cfg_attr(feature = "bindings", derive(TS))]
5351pub struct UnnestFunc {
5352    pub this: Expression,
5353    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
5354    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5355    pub expressions: Vec<Expression>,
5356    pub with_ordinality: bool,
5357    pub alias: Option<Identifier>,
5358    /// BigQuery: offset alias for WITH OFFSET AS <name>
5359    #[serde(default, skip_serializing_if = "Option::is_none")]
5360    pub offset_alias: Option<Identifier>,
5361}
5362
5363/// ARRAY_FILTER function (with lambda)
5364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5365#[cfg_attr(feature = "bindings", derive(TS))]
5366pub struct ArrayFilterFunc {
5367    pub this: Expression,
5368    pub filter: Expression,
5369}
5370
5371/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
5372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5373#[cfg_attr(feature = "bindings", derive(TS))]
5374pub struct ArrayTransformFunc {
5375    pub this: Expression,
5376    pub transform: Expression,
5377}
5378
5379/// SEQUENCE / GENERATE_SERIES function
5380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5381#[cfg_attr(feature = "bindings", derive(TS))]
5382pub struct SequenceFunc {
5383    pub start: Expression,
5384    pub stop: Expression,
5385    pub step: Option<Expression>,
5386}
5387
5388// ============================================================================
5389// Struct Function types
5390// ============================================================================
5391
5392/// STRUCT constructor
5393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5394#[cfg_attr(feature = "bindings", derive(TS))]
5395pub struct StructConstructor {
5396    pub fields: Vec<(Option<Identifier>, Expression)>,
5397}
5398
5399/// STRUCT_EXTRACT function
5400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5401#[cfg_attr(feature = "bindings", derive(TS))]
5402pub struct StructExtractFunc {
5403    pub this: Expression,
5404    pub field: Identifier,
5405}
5406
5407/// NAMED_STRUCT function
5408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5409#[cfg_attr(feature = "bindings", derive(TS))]
5410pub struct NamedStructFunc {
5411    pub pairs: Vec<(Expression, Expression)>,
5412}
5413
5414// ============================================================================
5415// Map Function types
5416// ============================================================================
5417
5418/// MAP constructor
5419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5420#[cfg_attr(feature = "bindings", derive(TS))]
5421pub struct MapConstructor {
5422    pub keys: Vec<Expression>,
5423    pub values: Vec<Expression>,
5424    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
5425    #[serde(default)]
5426    pub curly_brace_syntax: bool,
5427    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
5428    #[serde(default)]
5429    pub with_map_keyword: bool,
5430}
5431
5432/// TRANSFORM_KEYS / TRANSFORM_VALUES function
5433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5434#[cfg_attr(feature = "bindings", derive(TS))]
5435pub struct TransformFunc {
5436    pub this: Expression,
5437    pub transform: Expression,
5438}
5439
5440// ============================================================================
5441// JSON Function types
5442// ============================================================================
5443
5444/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct JsonExtractFunc {
5448    pub this: Expression,
5449    pub path: Expression,
5450    pub returning: Option<DataType>,
5451    /// True if parsed from -> or ->> operator syntax
5452    #[serde(default)]
5453    pub arrow_syntax: bool,
5454    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
5455    #[serde(default)]
5456    pub hash_arrow_syntax: bool,
5457    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
5458    #[serde(default)]
5459    pub wrapper_option: Option<String>,
5460    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
5461    #[serde(default)]
5462    pub quotes_option: Option<String>,
5463    /// ON SCALAR STRING flag
5464    #[serde(default)]
5465    pub on_scalar_string: bool,
5466    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
5467    #[serde(default)]
5468    pub on_error: Option<String>,
5469}
5470
5471/// JSON path extraction
5472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5473#[cfg_attr(feature = "bindings", derive(TS))]
5474pub struct JsonPathFunc {
5475    pub this: Expression,
5476    pub paths: Vec<Expression>,
5477}
5478
5479/// JSON_OBJECT function
5480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5481#[cfg_attr(feature = "bindings", derive(TS))]
5482pub struct JsonObjectFunc {
5483    pub pairs: Vec<(Expression, Expression)>,
5484    pub null_handling: Option<JsonNullHandling>,
5485    #[serde(default)]
5486    pub with_unique_keys: bool,
5487    #[serde(default)]
5488    pub returning_type: Option<DataType>,
5489    #[serde(default)]
5490    pub format_json: bool,
5491    #[serde(default)]
5492    pub encoding: Option<String>,
5493    /// For JSON_OBJECT(*) syntax
5494    #[serde(default)]
5495    pub star: bool,
5496}
5497
5498/// JSON null handling options
5499#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5500#[cfg_attr(feature = "bindings", derive(TS))]
5501pub enum JsonNullHandling {
5502    NullOnNull,
5503    AbsentOnNull,
5504}
5505
5506/// JSON_SET / JSON_INSERT function
5507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5508#[cfg_attr(feature = "bindings", derive(TS))]
5509pub struct JsonModifyFunc {
5510    pub this: Expression,
5511    pub path_values: Vec<(Expression, Expression)>,
5512}
5513
5514/// JSON_ARRAYAGG function
5515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5516#[cfg_attr(feature = "bindings", derive(TS))]
5517pub struct JsonArrayAggFunc {
5518    pub this: Expression,
5519    pub order_by: Option<Vec<Ordered>>,
5520    pub null_handling: Option<JsonNullHandling>,
5521    pub filter: Option<Expression>,
5522}
5523
5524/// JSON_OBJECTAGG function
5525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5526#[cfg_attr(feature = "bindings", derive(TS))]
5527pub struct JsonObjectAggFunc {
5528    pub key: Expression,
5529    pub value: Expression,
5530    pub null_handling: Option<JsonNullHandling>,
5531    pub filter: Option<Expression>,
5532}
5533
5534// ============================================================================
5535// Type Casting Function types
5536// ============================================================================
5537
5538/// CONVERT function (SQL Server style)
5539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5540#[cfg_attr(feature = "bindings", derive(TS))]
5541pub struct ConvertFunc {
5542    pub this: Expression,
5543    pub to: DataType,
5544    pub style: Option<Expression>,
5545}
5546
5547// ============================================================================
5548// Additional Expression types
5549// ============================================================================
5550
5551/// Lambda expression
5552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5553#[cfg_attr(feature = "bindings", derive(TS))]
5554pub struct LambdaExpr {
5555    pub parameters: Vec<Identifier>,
5556    pub body: Expression,
5557    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5558    #[serde(default)]
5559    pub colon: bool,
5560    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5561    /// Maps parameter index to data type
5562    #[serde(default)]
5563    pub parameter_types: Vec<Option<DataType>>,
5564}
5565
5566/// Parameter (parameterized queries)
5567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5568#[cfg_attr(feature = "bindings", derive(TS))]
5569pub struct Parameter {
5570    pub name: Option<String>,
5571    pub index: Option<u32>,
5572    pub style: ParameterStyle,
5573    /// Whether the name was quoted (e.g., @"x" vs @x)
5574    #[serde(default)]
5575    pub quoted: bool,
5576    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5577    #[serde(default)]
5578    pub string_quoted: bool,
5579    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5580    #[serde(default)]
5581    pub expression: Option<String>,
5582}
5583
5584/// Parameter placeholder styles
5585#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5586#[cfg_attr(feature = "bindings", derive(TS))]
5587pub enum ParameterStyle {
5588    Question,     // ?
5589    Dollar,       // $1, $2
5590    DollarBrace,  // ${name} (Databricks, Hive template variables)
5591    Brace,        // {name} (Spark/Databricks widget/template variables)
5592    Colon,        // :name
5593    At,           // @name
5594    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5595    DoubleDollar, // $$name
5596    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5597}
5598
5599/// Placeholder expression
5600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5601#[cfg_attr(feature = "bindings", derive(TS))]
5602pub struct Placeholder {
5603    pub index: Option<u32>,
5604}
5605
5606/// Named argument in function call: name => value or name := value
5607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5608#[cfg_attr(feature = "bindings", derive(TS))]
5609pub struct NamedArgument {
5610    pub name: Identifier,
5611    pub value: Expression,
5612    /// The separator used: `=>`, `:=`, or `=`
5613    pub separator: NamedArgSeparator,
5614}
5615
5616/// Separator style for named arguments
5617#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5618#[cfg_attr(feature = "bindings", derive(TS))]
5619pub enum NamedArgSeparator {
5620    /// `=>` (standard SQL, Snowflake, BigQuery)
5621    DArrow,
5622    /// `:=` (Oracle, MySQL)
5623    ColonEq,
5624    /// `=` (simple equals, some dialects)
5625    Eq,
5626}
5627
5628/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5629/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5631#[cfg_attr(feature = "bindings", derive(TS))]
5632pub struct TableArgument {
5633    /// The keyword prefix: "TABLE" or "MODEL"
5634    pub prefix: String,
5635    /// The table/model reference expression
5636    pub this: Expression,
5637}
5638
5639/// SQL Comment preservation
5640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5641#[cfg_attr(feature = "bindings", derive(TS))]
5642pub struct SqlComment {
5643    pub text: String,
5644    pub is_block: bool,
5645}
5646
5647// ============================================================================
5648// Additional Predicate types
5649// ============================================================================
5650
5651/// SIMILAR TO expression
5652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5653#[cfg_attr(feature = "bindings", derive(TS))]
5654pub struct SimilarToExpr {
5655    pub this: Expression,
5656    pub pattern: Expression,
5657    pub escape: Option<Expression>,
5658    pub not: bool,
5659}
5660
5661/// ANY / ALL quantified expression
5662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5663#[cfg_attr(feature = "bindings", derive(TS))]
5664pub struct QuantifiedExpr {
5665    pub this: Expression,
5666    pub subquery: Expression,
5667    pub op: Option<QuantifiedOp>,
5668}
5669
5670/// Comparison operator for quantified expressions
5671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5672#[cfg_attr(feature = "bindings", derive(TS))]
5673pub enum QuantifiedOp {
5674    Eq,
5675    Neq,
5676    Lt,
5677    Lte,
5678    Gt,
5679    Gte,
5680}
5681
5682/// OVERLAPS expression
5683/// Supports two forms:
5684/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5685/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5687#[cfg_attr(feature = "bindings", derive(TS))]
5688pub struct OverlapsExpr {
5689    /// Left operand for simple binary form
5690    #[serde(skip_serializing_if = "Option::is_none")]
5691    pub this: Option<Expression>,
5692    /// Right operand for simple binary form
5693    #[serde(skip_serializing_if = "Option::is_none")]
5694    pub expression: Option<Expression>,
5695    /// Left range start for full ANSI form
5696    #[serde(skip_serializing_if = "Option::is_none")]
5697    pub left_start: Option<Expression>,
5698    /// Left range end for full ANSI form
5699    #[serde(skip_serializing_if = "Option::is_none")]
5700    pub left_end: Option<Expression>,
5701    /// Right range start for full ANSI form
5702    #[serde(skip_serializing_if = "Option::is_none")]
5703    pub right_start: Option<Expression>,
5704    /// Right range end for full ANSI form
5705    #[serde(skip_serializing_if = "Option::is_none")]
5706    pub right_end: Option<Expression>,
5707}
5708
5709// ============================================================================
5710// Array/Struct/Map access
5711// ============================================================================
5712
5713/// Subscript access (array[index] or map[key])
5714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5715#[cfg_attr(feature = "bindings", derive(TS))]
5716pub struct Subscript {
5717    pub this: Expression,
5718    pub index: Expression,
5719}
5720
5721/// Dot access (struct.field)
5722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5723#[cfg_attr(feature = "bindings", derive(TS))]
5724pub struct DotAccess {
5725    pub this: Expression,
5726    pub field: Identifier,
5727}
5728
5729/// Method call (expr.method(args))
5730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5731#[cfg_attr(feature = "bindings", derive(TS))]
5732pub struct MethodCall {
5733    pub this: Expression,
5734    pub method: Identifier,
5735    pub args: Vec<Expression>,
5736}
5737
5738/// Array slice (array[start:end])
5739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5740#[cfg_attr(feature = "bindings", derive(TS))]
5741pub struct ArraySlice {
5742    pub this: Expression,
5743    pub start: Option<Expression>,
5744    pub end: Option<Expression>,
5745}
5746
5747// ============================================================================
5748// DDL (Data Definition Language) Statements
5749// ============================================================================
5750
5751/// ON COMMIT behavior for temporary tables
5752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5753#[cfg_attr(feature = "bindings", derive(TS))]
5754pub enum OnCommit {
5755    /// ON COMMIT PRESERVE ROWS
5756    PreserveRows,
5757    /// ON COMMIT DELETE ROWS
5758    DeleteRows,
5759}
5760
5761/// CREATE TABLE statement
5762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5763#[cfg_attr(feature = "bindings", derive(TS))]
5764pub struct CreateTable {
5765    pub name: TableRef,
5766    /// ClickHouse: ON CLUSTER clause for distributed DDL
5767    #[serde(default, skip_serializing_if = "Option::is_none")]
5768    pub on_cluster: Option<OnCluster>,
5769    pub columns: Vec<ColumnDef>,
5770    pub constraints: Vec<TableConstraint>,
5771    pub if_not_exists: bool,
5772    pub temporary: bool,
5773    pub or_replace: bool,
5774    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5775    #[serde(default, skip_serializing_if = "Option::is_none")]
5776    pub table_modifier: Option<String>,
5777    pub as_select: Option<Expression>,
5778    /// Whether the AS SELECT was wrapped in parentheses
5779    #[serde(default)]
5780    pub as_select_parenthesized: bool,
5781    /// ON COMMIT behavior for temporary tables
5782    #[serde(default)]
5783    pub on_commit: Option<OnCommit>,
5784    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5785    #[serde(default)]
5786    pub clone_source: Option<TableRef>,
5787    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5788    #[serde(default, skip_serializing_if = "Option::is_none")]
5789    pub clone_at_clause: Option<Expression>,
5790    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5791    #[serde(default)]
5792    pub is_copy: bool,
5793    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5794    #[serde(default)]
5795    pub shallow_clone: bool,
5796    /// Leading comments before the statement
5797    #[serde(default)]
5798    pub leading_comments: Vec<String>,
5799    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5800    #[serde(default)]
5801    pub with_properties: Vec<(String, String)>,
5802    /// Teradata: table options after name before columns (comma-separated)
5803    #[serde(default)]
5804    pub teradata_post_name_options: Vec<String>,
5805    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5806    #[serde(default)]
5807    pub with_data: Option<bool>,
5808    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5809    #[serde(default)]
5810    pub with_statistics: Option<bool>,
5811    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5812    #[serde(default)]
5813    pub teradata_indexes: Vec<TeradataIndex>,
5814    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5815    #[serde(default)]
5816    pub with_cte: Option<With>,
5817    /// Table properties like DEFAULT COLLATE (BigQuery)
5818    #[serde(default)]
5819    pub properties: Vec<Expression>,
5820    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5821    #[serde(default, skip_serializing_if = "Option::is_none")]
5822    pub partition_of: Option<Expression>,
5823    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5824    #[serde(default)]
5825    pub post_table_properties: Vec<Expression>,
5826    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5827    #[serde(default)]
5828    pub mysql_table_options: Vec<(String, String)>,
5829    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5830    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5831    pub inherits: Vec<TableRef>,
5832    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5833    #[serde(default, skip_serializing_if = "Option::is_none")]
5834    pub on_property: Option<OnProperty>,
5835    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5836    #[serde(default)]
5837    pub copy_grants: bool,
5838    /// Snowflake: USING TEMPLATE expression for schema inference
5839    #[serde(default, skip_serializing_if = "Option::is_none")]
5840    pub using_template: Option<Box<Expression>>,
5841    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5842    #[serde(default, skip_serializing_if = "Option::is_none")]
5843    pub rollup: Option<RollupProperty>,
5844}
5845
5846/// Teradata index specification for CREATE TABLE
5847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5848#[cfg_attr(feature = "bindings", derive(TS))]
5849pub struct TeradataIndex {
5850    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5851    pub kind: TeradataIndexKind,
5852    /// Optional index name
5853    pub name: Option<String>,
5854    /// Optional column list
5855    pub columns: Vec<String>,
5856}
5857
5858/// Kind of Teradata index
5859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5860#[cfg_attr(feature = "bindings", derive(TS))]
5861pub enum TeradataIndexKind {
5862    /// NO PRIMARY INDEX
5863    NoPrimary,
5864    /// PRIMARY INDEX
5865    Primary,
5866    /// PRIMARY AMP INDEX
5867    PrimaryAmp,
5868    /// UNIQUE INDEX
5869    Unique,
5870    /// UNIQUE PRIMARY INDEX
5871    UniquePrimary,
5872    /// INDEX (secondary, non-primary)
5873    Secondary,
5874}
5875
5876impl CreateTable {
5877    pub fn new(name: impl Into<String>) -> Self {
5878        Self {
5879            name: TableRef::new(name),
5880            on_cluster: None,
5881            columns: Vec::new(),
5882            constraints: Vec::new(),
5883            if_not_exists: false,
5884            temporary: false,
5885            or_replace: false,
5886            table_modifier: None,
5887            as_select: None,
5888            as_select_parenthesized: false,
5889            on_commit: None,
5890            clone_source: None,
5891            clone_at_clause: None,
5892            shallow_clone: false,
5893            is_copy: false,
5894            leading_comments: Vec::new(),
5895            with_properties: Vec::new(),
5896            teradata_post_name_options: Vec::new(),
5897            with_data: None,
5898            with_statistics: None,
5899            teradata_indexes: Vec::new(),
5900            with_cte: None,
5901            properties: Vec::new(),
5902            partition_of: None,
5903            post_table_properties: Vec::new(),
5904            mysql_table_options: Vec::new(),
5905            inherits: Vec::new(),
5906            on_property: None,
5907            copy_grants: false,
5908            using_template: None,
5909            rollup: None,
5910        }
5911    }
5912}
5913
5914/// Sort order for PRIMARY KEY ASC/DESC
5915#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5916#[cfg_attr(feature = "bindings", derive(TS))]
5917pub enum SortOrder {
5918    Asc,
5919    Desc,
5920}
5921
5922/// Type of column constraint for tracking order
5923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5924#[cfg_attr(feature = "bindings", derive(TS))]
5925pub enum ConstraintType {
5926    NotNull,
5927    Null,
5928    PrimaryKey,
5929    Unique,
5930    Default,
5931    AutoIncrement,
5932    Collate,
5933    Comment,
5934    References,
5935    Check,
5936    GeneratedAsIdentity,
5937    /// Snowflake: TAG (key='value', ...)
5938    Tags,
5939    /// Computed/generated column
5940    ComputedColumn,
5941    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5942    GeneratedAsRow,
5943    /// MySQL: ON UPDATE expression
5944    OnUpdate,
5945    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5946    Path,
5947    /// Redshift: ENCODE encoding_type
5948    Encode,
5949}
5950
5951/// Column definition in CREATE TABLE
5952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5953#[cfg_attr(feature = "bindings", derive(TS))]
5954pub struct ColumnDef {
5955    pub name: Identifier,
5956    pub data_type: DataType,
5957    pub nullable: Option<bool>,
5958    pub default: Option<Expression>,
5959    pub primary_key: bool,
5960    /// Sort order for PRIMARY KEY (ASC/DESC)
5961    #[serde(default)]
5962    pub primary_key_order: Option<SortOrder>,
5963    pub unique: bool,
5964    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5965    #[serde(default)]
5966    pub unique_nulls_not_distinct: bool,
5967    pub auto_increment: bool,
5968    pub comment: Option<String>,
5969    pub constraints: Vec<ColumnConstraint>,
5970    /// Track original order of constraints for accurate regeneration
5971    #[serde(default)]
5972    pub constraint_order: Vec<ConstraintType>,
5973    /// Teradata: FORMAT 'pattern'
5974    #[serde(default)]
5975    pub format: Option<String>,
5976    /// Teradata: TITLE 'title'
5977    #[serde(default)]
5978    pub title: Option<String>,
5979    /// Teradata: INLINE LENGTH n
5980    #[serde(default)]
5981    pub inline_length: Option<u64>,
5982    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5983    #[serde(default)]
5984    pub compress: Option<Vec<Expression>>,
5985    /// Teradata: CHARACTER SET name
5986    #[serde(default)]
5987    pub character_set: Option<String>,
5988    /// Teradata: UPPERCASE
5989    #[serde(default)]
5990    pub uppercase: bool,
5991    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5992    #[serde(default)]
5993    pub casespecific: Option<bool>,
5994    /// Snowflake: AUTOINCREMENT START value
5995    #[serde(default)]
5996    pub auto_increment_start: Option<Box<Expression>>,
5997    /// Snowflake: AUTOINCREMENT INCREMENT value
5998    #[serde(default)]
5999    pub auto_increment_increment: Option<Box<Expression>>,
6000    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
6001    #[serde(default)]
6002    pub auto_increment_order: Option<bool>,
6003    /// MySQL: UNSIGNED modifier
6004    #[serde(default)]
6005    pub unsigned: bool,
6006    /// MySQL: ZEROFILL modifier
6007    #[serde(default)]
6008    pub zerofill: bool,
6009    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
6010    #[serde(default, skip_serializing_if = "Option::is_none")]
6011    pub on_update: Option<Expression>,
6012    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
6013    #[serde(default, skip_serializing_if = "Option::is_none")]
6014    pub unique_constraint_name: Option<String>,
6015    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
6016    #[serde(default, skip_serializing_if = "Option::is_none")]
6017    pub not_null_constraint_name: Option<String>,
6018    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
6019    #[serde(default, skip_serializing_if = "Option::is_none")]
6020    pub primary_key_constraint_name: Option<String>,
6021    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
6022    #[serde(default, skip_serializing_if = "Option::is_none")]
6023    pub check_constraint_name: Option<String>,
6024    /// BigQuery: OPTIONS (key=value, ...) on column
6025    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6026    pub options: Vec<Expression>,
6027    /// SQLite: Column definition without explicit type
6028    #[serde(default)]
6029    pub no_type: bool,
6030    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
6031    #[serde(default, skip_serializing_if = "Option::is_none")]
6032    pub encoding: Option<String>,
6033    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
6034    #[serde(default, skip_serializing_if = "Option::is_none")]
6035    pub codec: Option<String>,
6036    /// ClickHouse: EPHEMERAL [expr] modifier
6037    #[serde(default, skip_serializing_if = "Option::is_none")]
6038    pub ephemeral: Option<Option<Box<Expression>>>,
6039    /// ClickHouse: MATERIALIZED expr modifier
6040    #[serde(default, skip_serializing_if = "Option::is_none")]
6041    pub materialized_expr: Option<Box<Expression>>,
6042    /// ClickHouse: ALIAS expr modifier
6043    #[serde(default, skip_serializing_if = "Option::is_none")]
6044    pub alias_expr: Option<Box<Expression>>,
6045    /// ClickHouse: TTL expr modifier on columns
6046    #[serde(default, skip_serializing_if = "Option::is_none")]
6047    pub ttl_expr: Option<Box<Expression>>,
6048    /// TSQL: NOT FOR REPLICATION
6049    #[serde(default)]
6050    pub not_for_replication: bool,
6051}
6052
6053impl ColumnDef {
6054    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
6055        Self {
6056            name: Identifier::new(name),
6057            data_type,
6058            nullable: None,
6059            default: None,
6060            primary_key: false,
6061            primary_key_order: None,
6062            unique: false,
6063            unique_nulls_not_distinct: false,
6064            auto_increment: false,
6065            comment: None,
6066            constraints: Vec::new(),
6067            constraint_order: Vec::new(),
6068            format: None,
6069            title: None,
6070            inline_length: None,
6071            compress: None,
6072            character_set: None,
6073            uppercase: false,
6074            casespecific: None,
6075            auto_increment_start: None,
6076            auto_increment_increment: None,
6077            auto_increment_order: None,
6078            unsigned: false,
6079            zerofill: false,
6080            on_update: None,
6081            unique_constraint_name: None,
6082            not_null_constraint_name: None,
6083            primary_key_constraint_name: None,
6084            check_constraint_name: None,
6085            options: Vec::new(),
6086            no_type: false,
6087            encoding: None,
6088            codec: None,
6089            ephemeral: None,
6090            materialized_expr: None,
6091            alias_expr: None,
6092            ttl_expr: None,
6093            not_for_replication: false,
6094        }
6095    }
6096}
6097
6098/// Column-level constraint
6099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6100#[cfg_attr(feature = "bindings", derive(TS))]
6101pub enum ColumnConstraint {
6102    NotNull,
6103    Null,
6104    Unique,
6105    PrimaryKey,
6106    Default(Expression),
6107    Check(Expression),
6108    References(ForeignKeyRef),
6109    GeneratedAsIdentity(GeneratedAsIdentity),
6110    Collate(Identifier),
6111    Comment(String),
6112    /// Snowflake: TAG (key='value', ...)
6113    Tags(Tags),
6114    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
6115    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
6116    ComputedColumn(ComputedColumn),
6117    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6118    GeneratedAsRow(GeneratedAsRow),
6119    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
6120    Path(Expression),
6121}
6122
6123/// Computed/generated column constraint
6124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6125#[cfg_attr(feature = "bindings", derive(TS))]
6126pub struct ComputedColumn {
6127    /// The expression that computes the column value
6128    pub expression: Box<Expression>,
6129    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
6130    #[serde(default)]
6131    pub persisted: bool,
6132    /// NOT NULL (TSQL computed columns)
6133    #[serde(default)]
6134    pub not_null: bool,
6135    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
6136    /// When None, defaults to dialect-appropriate output
6137    #[serde(default)]
6138    pub persistence_kind: Option<String>,
6139    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
6140    #[serde(default, skip_serializing_if = "Option::is_none")]
6141    pub data_type: Option<DataType>,
6142}
6143
6144/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6146#[cfg_attr(feature = "bindings", derive(TS))]
6147pub struct GeneratedAsRow {
6148    /// true = ROW START, false = ROW END
6149    pub start: bool,
6150    /// HIDDEN modifier
6151    #[serde(default)]
6152    pub hidden: bool,
6153}
6154
6155/// Generated identity column constraint
6156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6157#[cfg_attr(feature = "bindings", derive(TS))]
6158pub struct GeneratedAsIdentity {
6159    /// True for ALWAYS, False for BY DEFAULT
6160    pub always: bool,
6161    /// ON NULL (only valid with BY DEFAULT)
6162    pub on_null: bool,
6163    /// START WITH value
6164    pub start: Option<Box<Expression>>,
6165    /// INCREMENT BY value
6166    pub increment: Option<Box<Expression>>,
6167    /// MINVALUE
6168    pub minvalue: Option<Box<Expression>>,
6169    /// MAXVALUE
6170    pub maxvalue: Option<Box<Expression>>,
6171    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
6172    pub cycle: Option<bool>,
6173}
6174
6175/// Constraint modifiers (shared between table-level constraints)
6176#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
6177#[cfg_attr(feature = "bindings", derive(TS))]
6178pub struct ConstraintModifiers {
6179    /// ENFORCED / NOT ENFORCED
6180    pub enforced: Option<bool>,
6181    /// DEFERRABLE / NOT DEFERRABLE
6182    pub deferrable: Option<bool>,
6183    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
6184    pub initially_deferred: Option<bool>,
6185    /// NORELY (Oracle)
6186    pub norely: bool,
6187    /// RELY (Oracle)
6188    pub rely: bool,
6189    /// USING index type (MySQL): BTREE or HASH
6190    #[serde(default)]
6191    pub using: Option<String>,
6192    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
6193    #[serde(default)]
6194    pub using_before_columns: bool,
6195    /// MySQL index COMMENT 'text'
6196    #[serde(default, skip_serializing_if = "Option::is_none")]
6197    pub comment: Option<String>,
6198    /// MySQL index VISIBLE/INVISIBLE
6199    #[serde(default, skip_serializing_if = "Option::is_none")]
6200    pub visible: Option<bool>,
6201    /// MySQL ENGINE_ATTRIBUTE = 'value'
6202    #[serde(default, skip_serializing_if = "Option::is_none")]
6203    pub engine_attribute: Option<String>,
6204    /// MySQL WITH PARSER name
6205    #[serde(default, skip_serializing_if = "Option::is_none")]
6206    pub with_parser: Option<String>,
6207    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
6208    #[serde(default)]
6209    pub not_valid: bool,
6210    /// TSQL CLUSTERED/NONCLUSTERED modifier
6211    #[serde(default, skip_serializing_if = "Option::is_none")]
6212    pub clustered: Option<String>,
6213    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
6214    #[serde(default, skip_serializing_if = "Option::is_none")]
6215    pub on_conflict: Option<String>,
6216    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
6217    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6218    pub with_options: Vec<(String, String)>,
6219    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
6220    #[serde(default, skip_serializing_if = "Option::is_none")]
6221    pub on_filegroup: Option<Identifier>,
6222}
6223
6224/// Table-level constraint
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub enum TableConstraint {
6228    PrimaryKey {
6229        name: Option<Identifier>,
6230        columns: Vec<Identifier>,
6231        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
6232        #[serde(default)]
6233        include_columns: Vec<Identifier>,
6234        #[serde(default)]
6235        modifiers: ConstraintModifiers,
6236        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
6237        #[serde(default)]
6238        has_constraint_keyword: bool,
6239    },
6240    Unique {
6241        name: Option<Identifier>,
6242        columns: Vec<Identifier>,
6243        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
6244        #[serde(default)]
6245        columns_parenthesized: bool,
6246        #[serde(default)]
6247        modifiers: ConstraintModifiers,
6248        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
6249        #[serde(default)]
6250        has_constraint_keyword: bool,
6251        /// PostgreSQL 15+: NULLS NOT DISTINCT
6252        #[serde(default)]
6253        nulls_not_distinct: bool,
6254    },
6255    ForeignKey {
6256        name: Option<Identifier>,
6257        columns: Vec<Identifier>,
6258        #[serde(default)]
6259        references: Option<ForeignKeyRef>,
6260        /// ON DELETE action when REFERENCES is absent
6261        #[serde(default)]
6262        on_delete: Option<ReferentialAction>,
6263        /// ON UPDATE action when REFERENCES is absent
6264        #[serde(default)]
6265        on_update: Option<ReferentialAction>,
6266        #[serde(default)]
6267        modifiers: ConstraintModifiers,
6268    },
6269    Check {
6270        name: Option<Identifier>,
6271        expression: Expression,
6272        #[serde(default)]
6273        modifiers: ConstraintModifiers,
6274    },
6275    /// INDEX / KEY constraint (MySQL)
6276    Index {
6277        name: Option<Identifier>,
6278        columns: Vec<Identifier>,
6279        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
6280        #[serde(default)]
6281        kind: Option<String>,
6282        #[serde(default)]
6283        modifiers: ConstraintModifiers,
6284        /// True if KEY keyword was used instead of INDEX
6285        #[serde(default)]
6286        use_key_keyword: bool,
6287        /// ClickHouse: indexed expression (instead of columns)
6288        #[serde(default, skip_serializing_if = "Option::is_none")]
6289        expression: Option<Box<Expression>>,
6290        /// ClickHouse: TYPE type_func(args)
6291        #[serde(default, skip_serializing_if = "Option::is_none")]
6292        index_type: Option<Box<Expression>>,
6293        /// ClickHouse: GRANULARITY n
6294        #[serde(default, skip_serializing_if = "Option::is_none")]
6295        granularity: Option<Box<Expression>>,
6296    },
6297    /// ClickHouse PROJECTION definition
6298    Projection {
6299        name: Identifier,
6300        expression: Expression,
6301    },
6302    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
6303    Like {
6304        source: TableRef,
6305        /// Options as (INCLUDING|EXCLUDING, property) pairs
6306        options: Vec<(LikeOptionAction, String)>,
6307    },
6308    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
6309    PeriodForSystemTime {
6310        start_col: Identifier,
6311        end_col: Identifier,
6312    },
6313    /// PostgreSQL EXCLUDE constraint
6314    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
6315    Exclude {
6316        name: Option<Identifier>,
6317        /// Index access method (gist, btree, etc.)
6318        #[serde(default)]
6319        using: Option<String>,
6320        /// Elements: (expression, operator) pairs
6321        elements: Vec<ExcludeElement>,
6322        /// INCLUDE columns
6323        #[serde(default)]
6324        include_columns: Vec<Identifier>,
6325        /// WHERE predicate
6326        #[serde(default)]
6327        where_clause: Option<Box<Expression>>,
6328        /// WITH (storage_parameters)
6329        #[serde(default)]
6330        with_params: Vec<(String, String)>,
6331        /// USING INDEX TABLESPACE tablespace_name
6332        #[serde(default)]
6333        using_index_tablespace: Option<String>,
6334        #[serde(default)]
6335        modifiers: ConstraintModifiers,
6336    },
6337    /// Snowflake TAG clause: TAG (key='value', key2='value2')
6338    Tags(Tags),
6339    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
6340    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
6341    /// for all deferrable constraints in the table
6342    InitiallyDeferred {
6343        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
6344        deferred: bool,
6345    },
6346}
6347
6348/// Element in an EXCLUDE constraint: expression WITH operator
6349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6350#[cfg_attr(feature = "bindings", derive(TS))]
6351pub struct ExcludeElement {
6352    /// The column expression (may include operator class, ordering, nulls)
6353    pub expression: String,
6354    /// The operator (e.g., &&, =)
6355    pub operator: String,
6356}
6357
6358/// Action for LIKE clause options
6359#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6360#[cfg_attr(feature = "bindings", derive(TS))]
6361pub enum LikeOptionAction {
6362    Including,
6363    Excluding,
6364}
6365
6366/// MATCH type for foreign keys
6367#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6368#[cfg_attr(feature = "bindings", derive(TS))]
6369pub enum MatchType {
6370    Full,
6371    Partial,
6372    Simple,
6373}
6374
6375/// Foreign key reference
6376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6377#[cfg_attr(feature = "bindings", derive(TS))]
6378pub struct ForeignKeyRef {
6379    pub table: TableRef,
6380    pub columns: Vec<Identifier>,
6381    pub on_delete: Option<ReferentialAction>,
6382    pub on_update: Option<ReferentialAction>,
6383    /// True if ON UPDATE appears before ON DELETE in the original SQL
6384    #[serde(default)]
6385    pub on_update_first: bool,
6386    /// MATCH clause (FULL, PARTIAL, SIMPLE)
6387    #[serde(default)]
6388    pub match_type: Option<MatchType>,
6389    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
6390    #[serde(default)]
6391    pub match_after_actions: bool,
6392    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
6393    #[serde(default)]
6394    pub constraint_name: Option<String>,
6395    /// DEFERRABLE / NOT DEFERRABLE
6396    #[serde(default)]
6397    pub deferrable: Option<bool>,
6398    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
6399    #[serde(default)]
6400    pub has_foreign_key_keywords: bool,
6401}
6402
6403/// Referential action for foreign keys
6404#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6405#[cfg_attr(feature = "bindings", derive(TS))]
6406pub enum ReferentialAction {
6407    Cascade,
6408    SetNull,
6409    SetDefault,
6410    Restrict,
6411    NoAction,
6412}
6413
6414/// DROP TABLE statement
6415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6416#[cfg_attr(feature = "bindings", derive(TS))]
6417pub struct DropTable {
6418    pub names: Vec<TableRef>,
6419    pub if_exists: bool,
6420    pub cascade: bool,
6421    /// Oracle: CASCADE CONSTRAINTS
6422    #[serde(default)]
6423    pub cascade_constraints: bool,
6424    /// Oracle: PURGE
6425    #[serde(default)]
6426    pub purge: bool,
6427    /// Comments that appear before the DROP keyword (e.g., leading line comments)
6428    #[serde(default)]
6429    pub leading_comments: Vec<String>,
6430}
6431
6432impl DropTable {
6433    pub fn new(name: impl Into<String>) -> Self {
6434        Self {
6435            names: vec![TableRef::new(name)],
6436            if_exists: false,
6437            cascade: false,
6438            cascade_constraints: false,
6439            purge: false,
6440            leading_comments: Vec::new(),
6441        }
6442    }
6443}
6444
6445/// ALTER TABLE statement
6446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6447#[cfg_attr(feature = "bindings", derive(TS))]
6448pub struct AlterTable {
6449    pub name: TableRef,
6450    pub actions: Vec<AlterTableAction>,
6451    /// IF EXISTS clause
6452    #[serde(default)]
6453    pub if_exists: bool,
6454    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
6455    #[serde(default, skip_serializing_if = "Option::is_none")]
6456    pub algorithm: Option<String>,
6457    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
6458    #[serde(default, skip_serializing_if = "Option::is_none")]
6459    pub lock: Option<String>,
6460    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
6461    #[serde(default, skip_serializing_if = "Option::is_none")]
6462    pub with_check: Option<String>,
6463    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
6464    #[serde(default, skip_serializing_if = "Option::is_none")]
6465    pub partition: Option<Vec<(Identifier, Expression)>>,
6466    /// ClickHouse: ON CLUSTER clause for distributed DDL
6467    #[serde(default, skip_serializing_if = "Option::is_none")]
6468    pub on_cluster: Option<OnCluster>,
6469}
6470
6471impl AlterTable {
6472    pub fn new(name: impl Into<String>) -> Self {
6473        Self {
6474            name: TableRef::new(name),
6475            actions: Vec::new(),
6476            if_exists: false,
6477            algorithm: None,
6478            lock: None,
6479            with_check: None,
6480            partition: None,
6481            on_cluster: None,
6482        }
6483    }
6484}
6485
6486/// Column position for ADD COLUMN (MySQL/MariaDB)
6487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6488#[cfg_attr(feature = "bindings", derive(TS))]
6489pub enum ColumnPosition {
6490    First,
6491    After(Identifier),
6492}
6493
6494/// Actions for ALTER TABLE
6495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6496#[cfg_attr(feature = "bindings", derive(TS))]
6497pub enum AlterTableAction {
6498    AddColumn {
6499        column: ColumnDef,
6500        if_not_exists: bool,
6501        position: Option<ColumnPosition>,
6502    },
6503    DropColumn {
6504        name: Identifier,
6505        if_exists: bool,
6506        cascade: bool,
6507    },
6508    RenameColumn {
6509        old_name: Identifier,
6510        new_name: Identifier,
6511        if_exists: bool,
6512    },
6513    AlterColumn {
6514        name: Identifier,
6515        action: AlterColumnAction,
6516        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
6517        #[serde(default)]
6518        use_modify_keyword: bool,
6519    },
6520    RenameTable(TableRef),
6521    AddConstraint(TableConstraint),
6522    DropConstraint {
6523        name: Identifier,
6524        if_exists: bool,
6525    },
6526    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
6527    DropForeignKey {
6528        name: Identifier,
6529    },
6530    /// DROP PARTITION action (Hive/BigQuery)
6531    DropPartition {
6532        /// List of partitions to drop (each partition is a list of key=value pairs)
6533        partitions: Vec<Vec<(Identifier, Expression)>>,
6534        if_exists: bool,
6535    },
6536    /// ADD PARTITION action (Hive/Spark)
6537    AddPartition {
6538        /// The partition expression
6539        partition: Expression,
6540        if_not_exists: bool,
6541        location: Option<Expression>,
6542    },
6543    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6544    Delete {
6545        where_clause: Expression,
6546    },
6547    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6548    SwapWith(TableRef),
6549    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6550    SetProperty {
6551        properties: Vec<(String, Expression)>,
6552    },
6553    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6554    UnsetProperty {
6555        properties: Vec<String>,
6556    },
6557    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6558    ClusterBy {
6559        expressions: Vec<Expression>,
6560    },
6561    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6562    SetTag {
6563        expressions: Vec<(String, Expression)>,
6564    },
6565    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6566    UnsetTag {
6567        names: Vec<String>,
6568    },
6569    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6570    SetOptions {
6571        expressions: Vec<Expression>,
6572    },
6573    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6574    AlterIndex {
6575        name: Identifier,
6576        visible: bool,
6577    },
6578    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6579    SetAttribute {
6580        attribute: String,
6581    },
6582    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6583    SetStageFileFormat {
6584        options: Option<Expression>,
6585    },
6586    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6587    SetStageCopyOptions {
6588        options: Option<Expression>,
6589    },
6590    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6591    AddColumns {
6592        columns: Vec<ColumnDef>,
6593        cascade: bool,
6594    },
6595    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6596    DropColumns {
6597        names: Vec<Identifier>,
6598    },
6599    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6600    /// In SingleStore, data_type can be omitted for simple column renames
6601    ChangeColumn {
6602        old_name: Identifier,
6603        new_name: Identifier,
6604        #[serde(default, skip_serializing_if = "Option::is_none")]
6605        data_type: Option<DataType>,
6606        comment: Option<String>,
6607        #[serde(default)]
6608        cascade: bool,
6609    },
6610    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6611    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6612    AlterSortKey {
6613        /// AUTO or NONE keyword
6614        this: Option<String>,
6615        /// Column list for (col1, col2) syntax
6616        expressions: Vec<Expression>,
6617        /// Whether COMPOUND keyword was present
6618        compound: bool,
6619    },
6620    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6621    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6622    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6623    AlterDistStyle {
6624        /// Distribution style: ALL, EVEN, AUTO, or KEY
6625        style: String,
6626        /// DISTKEY column (only when style is KEY)
6627        distkey: Option<Identifier>,
6628    },
6629    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6630    SetTableProperties {
6631        properties: Vec<(Expression, Expression)>,
6632    },
6633    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6634    SetLocation {
6635        location: String,
6636    },
6637    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6638    SetFileFormat {
6639        format: String,
6640    },
6641    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6642    ReplacePartition {
6643        partition: Expression,
6644        source: Option<Box<Expression>>,
6645    },
6646    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6647    Raw {
6648        sql: String,
6649    },
6650}
6651
6652/// Actions for ALTER COLUMN
6653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6654#[cfg_attr(feature = "bindings", derive(TS))]
6655pub enum AlterColumnAction {
6656    SetDataType {
6657        data_type: DataType,
6658        /// USING expression for type conversion (PostgreSQL)
6659        using: Option<Expression>,
6660        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6661        #[serde(default, skip_serializing_if = "Option::is_none")]
6662        collate: Option<String>,
6663    },
6664    SetDefault(Expression),
6665    DropDefault,
6666    SetNotNull,
6667    DropNotNull,
6668    /// Set column comment
6669    Comment(String),
6670    /// MySQL: SET VISIBLE
6671    SetVisible,
6672    /// MySQL: SET INVISIBLE
6673    SetInvisible,
6674}
6675
6676/// CREATE INDEX statement
6677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6678#[cfg_attr(feature = "bindings", derive(TS))]
6679pub struct CreateIndex {
6680    pub name: Identifier,
6681    pub table: TableRef,
6682    pub columns: Vec<IndexColumn>,
6683    pub unique: bool,
6684    pub if_not_exists: bool,
6685    pub using: Option<String>,
6686    /// TSQL CLUSTERED/NONCLUSTERED modifier
6687    #[serde(default)]
6688    pub clustered: Option<String>,
6689    /// PostgreSQL CONCURRENTLY modifier
6690    #[serde(default)]
6691    pub concurrently: bool,
6692    /// PostgreSQL WHERE clause for partial indexes
6693    #[serde(default)]
6694    pub where_clause: Option<Box<Expression>>,
6695    /// PostgreSQL INCLUDE columns
6696    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6697    pub include_columns: Vec<Identifier>,
6698    /// TSQL WITH options (e.g., allow_page_locks=on)
6699    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6700    pub with_options: Vec<(String, String)>,
6701    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6702    #[serde(default)]
6703    pub on_filegroup: Option<String>,
6704}
6705
6706impl CreateIndex {
6707    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6708        Self {
6709            name: Identifier::new(name),
6710            table: TableRef::new(table),
6711            columns: Vec::new(),
6712            unique: false,
6713            if_not_exists: false,
6714            using: None,
6715            clustered: None,
6716            concurrently: false,
6717            where_clause: None,
6718            include_columns: Vec::new(),
6719            with_options: Vec::new(),
6720            on_filegroup: None,
6721        }
6722    }
6723}
6724
6725/// Index column specification
6726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6727#[cfg_attr(feature = "bindings", derive(TS))]
6728pub struct IndexColumn {
6729    pub column: Identifier,
6730    pub desc: bool,
6731    /// Explicit ASC keyword was present
6732    #[serde(default)]
6733    pub asc: bool,
6734    pub nulls_first: Option<bool>,
6735    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6736    #[serde(default, skip_serializing_if = "Option::is_none")]
6737    pub opclass: Option<String>,
6738}
6739
6740/// DROP INDEX statement
6741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6742#[cfg_attr(feature = "bindings", derive(TS))]
6743pub struct DropIndex {
6744    pub name: Identifier,
6745    pub table: Option<TableRef>,
6746    pub if_exists: bool,
6747    /// PostgreSQL CONCURRENTLY modifier
6748    #[serde(default)]
6749    pub concurrently: bool,
6750}
6751
6752impl DropIndex {
6753    pub fn new(name: impl Into<String>) -> Self {
6754        Self {
6755            name: Identifier::new(name),
6756            table: None,
6757            if_exists: false,
6758            concurrently: false,
6759        }
6760    }
6761}
6762
6763/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6765#[cfg_attr(feature = "bindings", derive(TS))]
6766pub struct ViewColumn {
6767    pub name: Identifier,
6768    pub comment: Option<String>,
6769    /// BigQuery: OPTIONS (key=value, ...) on column
6770    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6771    pub options: Vec<Expression>,
6772}
6773
6774impl ViewColumn {
6775    pub fn new(name: impl Into<String>) -> Self {
6776        Self {
6777            name: Identifier::new(name),
6778            comment: None,
6779            options: Vec::new(),
6780        }
6781    }
6782
6783    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6784        Self {
6785            name: Identifier::new(name),
6786            comment: Some(comment.into()),
6787            options: Vec::new(),
6788        }
6789    }
6790}
6791
6792/// CREATE VIEW statement
6793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6794#[cfg_attr(feature = "bindings", derive(TS))]
6795pub struct CreateView {
6796    pub name: TableRef,
6797    pub columns: Vec<ViewColumn>,
6798    pub query: Expression,
6799    pub or_replace: bool,
6800    pub if_not_exists: bool,
6801    pub materialized: bool,
6802    pub temporary: bool,
6803    /// Snowflake: SECURE VIEW
6804    #[serde(default)]
6805    pub secure: bool,
6806    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6807    #[serde(skip_serializing_if = "Option::is_none")]
6808    pub algorithm: Option<String>,
6809    /// MySQL: DEFINER=user@host
6810    #[serde(skip_serializing_if = "Option::is_none")]
6811    pub definer: Option<String>,
6812    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6813    #[serde(skip_serializing_if = "Option::is_none")]
6814    pub security: Option<FunctionSecurity>,
6815    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6816    #[serde(default = "default_true")]
6817    pub security_sql_style: bool,
6818    /// Whether the query was parenthesized: AS (SELECT ...)
6819    #[serde(default)]
6820    pub query_parenthesized: bool,
6821    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6822    #[serde(skip_serializing_if = "Option::is_none")]
6823    pub locking_mode: Option<String>,
6824    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6825    #[serde(skip_serializing_if = "Option::is_none")]
6826    pub locking_access: Option<String>,
6827    /// Snowflake: COPY GRANTS
6828    #[serde(default)]
6829    pub copy_grants: bool,
6830    /// Snowflake: COMMENT = 'text'
6831    #[serde(skip_serializing_if = "Option::is_none", default)]
6832    pub comment: Option<String>,
6833    /// Snowflake: TAG (name='value', ...)
6834    #[serde(default)]
6835    pub tags: Vec<(String, String)>,
6836    /// BigQuery: OPTIONS (key=value, ...)
6837    #[serde(default)]
6838    pub options: Vec<Expression>,
6839    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6840    #[serde(skip_serializing_if = "Option::is_none", default)]
6841    pub build: Option<String>,
6842    /// Doris: REFRESH property for materialized views
6843    #[serde(skip_serializing_if = "Option::is_none", default)]
6844    pub refresh: Option<Box<RefreshTriggerProperty>>,
6845    /// Doris: Schema with typed column definitions for materialized views
6846    /// This is used instead of `columns` when the view has typed column definitions
6847    #[serde(skip_serializing_if = "Option::is_none", default)]
6848    pub schema: Option<Box<Schema>>,
6849    /// Doris: KEY (columns) for materialized views
6850    #[serde(skip_serializing_if = "Option::is_none", default)]
6851    pub unique_key: Option<Box<UniqueKeyProperty>>,
6852    /// Redshift: WITH NO SCHEMA BINDING
6853    #[serde(default)]
6854    pub no_schema_binding: bool,
6855    /// Redshift: AUTO REFRESH YES|NO for materialized views
6856    #[serde(skip_serializing_if = "Option::is_none", default)]
6857    pub auto_refresh: Option<bool>,
6858    /// ClickHouse: ON CLUSTER clause
6859    #[serde(default, skip_serializing_if = "Option::is_none")]
6860    pub on_cluster: Option<OnCluster>,
6861    /// ClickHouse: TO destination_table
6862    #[serde(default, skip_serializing_if = "Option::is_none")]
6863    pub to_table: Option<TableRef>,
6864    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6865    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6866    pub table_properties: Vec<Expression>,
6867}
6868
6869impl CreateView {
6870    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6871        Self {
6872            name: TableRef::new(name),
6873            columns: Vec::new(),
6874            query,
6875            or_replace: false,
6876            if_not_exists: false,
6877            materialized: false,
6878            temporary: false,
6879            secure: false,
6880            algorithm: None,
6881            definer: None,
6882            security: None,
6883            security_sql_style: true,
6884            query_parenthesized: false,
6885            locking_mode: None,
6886            locking_access: None,
6887            copy_grants: false,
6888            comment: None,
6889            tags: Vec::new(),
6890            options: Vec::new(),
6891            build: None,
6892            refresh: None,
6893            schema: None,
6894            unique_key: None,
6895            no_schema_binding: false,
6896            auto_refresh: None,
6897            on_cluster: None,
6898            to_table: None,
6899            table_properties: Vec::new(),
6900        }
6901    }
6902}
6903
6904/// DROP VIEW statement
6905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6906#[cfg_attr(feature = "bindings", derive(TS))]
6907pub struct DropView {
6908    pub name: TableRef,
6909    pub if_exists: bool,
6910    pub materialized: bool,
6911}
6912
6913impl DropView {
6914    pub fn new(name: impl Into<String>) -> Self {
6915        Self {
6916            name: TableRef::new(name),
6917            if_exists: false,
6918            materialized: false,
6919        }
6920    }
6921}
6922
6923/// TRUNCATE TABLE statement
6924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6925#[cfg_attr(feature = "bindings", derive(TS))]
6926pub struct Truncate {
6927    /// Target of TRUNCATE (TABLE vs DATABASE)
6928    #[serde(default)]
6929    pub target: TruncateTarget,
6930    /// IF EXISTS clause
6931    #[serde(default)]
6932    pub if_exists: bool,
6933    pub table: TableRef,
6934    /// ClickHouse: ON CLUSTER clause for distributed DDL
6935    #[serde(default, skip_serializing_if = "Option::is_none")]
6936    pub on_cluster: Option<OnCluster>,
6937    pub cascade: bool,
6938    /// Additional tables for multi-table TRUNCATE
6939    #[serde(default)]
6940    pub extra_tables: Vec<TruncateTableEntry>,
6941    /// RESTART IDENTITY or CONTINUE IDENTITY
6942    #[serde(default)]
6943    pub identity: Option<TruncateIdentity>,
6944    /// RESTRICT option (alternative to CASCADE)
6945    #[serde(default)]
6946    pub restrict: bool,
6947    /// Hive PARTITION clause: PARTITION(key=value, ...)
6948    #[serde(default, skip_serializing_if = "Option::is_none")]
6949    pub partition: Option<Box<Expression>>,
6950}
6951
6952/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6954#[cfg_attr(feature = "bindings", derive(TS))]
6955pub struct TruncateTableEntry {
6956    pub table: TableRef,
6957    /// Whether the table has a * suffix (inherit children)
6958    #[serde(default)]
6959    pub star: bool,
6960}
6961
6962/// TRUNCATE target type
6963#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6964#[cfg_attr(feature = "bindings", derive(TS))]
6965pub enum TruncateTarget {
6966    Table,
6967    Database,
6968}
6969
6970impl Default for TruncateTarget {
6971    fn default() -> Self {
6972        TruncateTarget::Table
6973    }
6974}
6975
6976/// TRUNCATE identity option
6977#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6978#[cfg_attr(feature = "bindings", derive(TS))]
6979pub enum TruncateIdentity {
6980    Restart,
6981    Continue,
6982}
6983
6984impl Truncate {
6985    pub fn new(table: impl Into<String>) -> Self {
6986        Self {
6987            target: TruncateTarget::Table,
6988            if_exists: false,
6989            table: TableRef::new(table),
6990            on_cluster: None,
6991            cascade: false,
6992            extra_tables: Vec::new(),
6993            identity: None,
6994            restrict: false,
6995            partition: None,
6996        }
6997    }
6998}
6999
7000/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
7001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7002#[cfg_attr(feature = "bindings", derive(TS))]
7003pub struct Use {
7004    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
7005    pub kind: Option<UseKind>,
7006    /// The name of the object
7007    pub this: Identifier,
7008}
7009
7010/// Kind of USE statement
7011#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7012#[cfg_attr(feature = "bindings", derive(TS))]
7013pub enum UseKind {
7014    Database,
7015    Schema,
7016    Role,
7017    Warehouse,
7018    Catalog,
7019    /// Snowflake: USE SECONDARY ROLES ALL|NONE
7020    SecondaryRoles,
7021}
7022
7023/// SET variable statement
7024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7025#[cfg_attr(feature = "bindings", derive(TS))]
7026pub struct SetStatement {
7027    /// The items being set
7028    pub items: Vec<SetItem>,
7029}
7030
7031/// A single SET item (variable assignment)
7032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7033#[cfg_attr(feature = "bindings", derive(TS))]
7034pub struct SetItem {
7035    /// The variable name
7036    pub name: Expression,
7037    /// The value to set
7038    pub value: Expression,
7039    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
7040    pub kind: Option<String>,
7041    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
7042    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7043    pub no_equals: bool,
7044}
7045
7046/// CACHE TABLE statement (Spark)
7047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7048#[cfg_attr(feature = "bindings", derive(TS))]
7049pub struct Cache {
7050    /// The table to cache
7051    pub table: Identifier,
7052    /// LAZY keyword - defer caching until first use
7053    pub lazy: bool,
7054    /// Optional OPTIONS clause (key-value pairs)
7055    pub options: Vec<(Expression, Expression)>,
7056    /// Optional AS clause with query
7057    pub query: Option<Expression>,
7058}
7059
7060/// UNCACHE TABLE statement (Spark)
7061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7062#[cfg_attr(feature = "bindings", derive(TS))]
7063pub struct Uncache {
7064    /// The table to uncache
7065    pub table: Identifier,
7066    /// IF EXISTS clause
7067    pub if_exists: bool,
7068}
7069
7070/// LOAD DATA statement (Hive)
7071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7072#[cfg_attr(feature = "bindings", derive(TS))]
7073pub struct LoadData {
7074    /// LOCAL keyword - load from local filesystem
7075    pub local: bool,
7076    /// The path to load data from (INPATH value)
7077    pub inpath: String,
7078    /// Whether to overwrite existing data
7079    pub overwrite: bool,
7080    /// The target table
7081    pub table: Expression,
7082    /// Optional PARTITION clause with key-value pairs
7083    pub partition: Vec<(Identifier, Expression)>,
7084    /// Optional INPUTFORMAT clause
7085    pub input_format: Option<String>,
7086    /// Optional SERDE clause
7087    pub serde: Option<String>,
7088}
7089
7090/// PRAGMA statement (SQLite)
7091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7092#[cfg_attr(feature = "bindings", derive(TS))]
7093pub struct Pragma {
7094    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
7095    pub schema: Option<Identifier>,
7096    /// The pragma name
7097    pub name: Identifier,
7098    /// Optional value for assignment (PRAGMA name = value)
7099    pub value: Option<Expression>,
7100    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
7101    pub args: Vec<Expression>,
7102}
7103
7104/// A privilege with optional column list for GRANT/REVOKE
7105/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
7106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7107#[cfg_attr(feature = "bindings", derive(TS))]
7108pub struct Privilege {
7109    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
7110    pub name: String,
7111    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
7112    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7113    pub columns: Vec<String>,
7114}
7115
7116/// Principal in GRANT/REVOKE (user, role, etc.)
7117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7118#[cfg_attr(feature = "bindings", derive(TS))]
7119pub struct GrantPrincipal {
7120    /// The name of the principal
7121    pub name: Identifier,
7122    /// Whether prefixed with ROLE keyword
7123    pub is_role: bool,
7124    /// Whether prefixed with GROUP keyword (Redshift)
7125    #[serde(default)]
7126    pub is_group: bool,
7127}
7128
7129/// GRANT statement
7130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7131#[cfg_attr(feature = "bindings", derive(TS))]
7132pub struct Grant {
7133    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
7134    pub privileges: Vec<Privilege>,
7135    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7136    pub kind: Option<String>,
7137    /// The object to grant on
7138    pub securable: Identifier,
7139    /// Function parameter types (for FUNCTION kind)
7140    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7141    pub function_params: Vec<String>,
7142    /// The grantees
7143    pub principals: Vec<GrantPrincipal>,
7144    /// WITH GRANT OPTION
7145    pub grant_option: bool,
7146    /// TSQL: AS principal (the grantor role)
7147    #[serde(default, skip_serializing_if = "Option::is_none")]
7148    pub as_principal: Option<Identifier>,
7149}
7150
7151/// REVOKE statement
7152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7153#[cfg_attr(feature = "bindings", derive(TS))]
7154pub struct Revoke {
7155    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
7156    pub privileges: Vec<Privilege>,
7157    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7158    pub kind: Option<String>,
7159    /// The object to revoke from
7160    pub securable: Identifier,
7161    /// Function parameter types (for FUNCTION kind)
7162    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7163    pub function_params: Vec<String>,
7164    /// The grantees
7165    pub principals: Vec<GrantPrincipal>,
7166    /// GRANT OPTION FOR
7167    pub grant_option: bool,
7168    /// CASCADE
7169    pub cascade: bool,
7170    /// RESTRICT
7171    #[serde(default)]
7172    pub restrict: bool,
7173}
7174
7175/// COMMENT ON statement
7176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7177#[cfg_attr(feature = "bindings", derive(TS))]
7178pub struct Comment {
7179    /// The object being commented on
7180    pub this: Expression,
7181    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
7182    pub kind: String,
7183    /// The comment text expression
7184    pub expression: Expression,
7185    /// IF EXISTS clause
7186    pub exists: bool,
7187    /// MATERIALIZED keyword
7188    pub materialized: bool,
7189}
7190
7191// ============================================================================
7192// Phase 4: Additional DDL Statements
7193// ============================================================================
7194
7195/// ALTER VIEW statement
7196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7197#[cfg_attr(feature = "bindings", derive(TS))]
7198pub struct AlterView {
7199    pub name: TableRef,
7200    pub actions: Vec<AlterViewAction>,
7201    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
7202    #[serde(default, skip_serializing_if = "Option::is_none")]
7203    pub algorithm: Option<String>,
7204    /// MySQL: DEFINER = 'user'@'host'
7205    #[serde(default, skip_serializing_if = "Option::is_none")]
7206    pub definer: Option<String>,
7207    /// MySQL: SQL SECURITY = DEFINER|INVOKER
7208    #[serde(default, skip_serializing_if = "Option::is_none")]
7209    pub sql_security: Option<String>,
7210    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
7211    #[serde(default, skip_serializing_if = "Option::is_none")]
7212    pub with_option: Option<String>,
7213    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
7214    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7215    pub columns: Vec<ViewColumn>,
7216}
7217
7218/// Actions for ALTER VIEW
7219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7220#[cfg_attr(feature = "bindings", derive(TS))]
7221pub enum AlterViewAction {
7222    /// Rename the view
7223    Rename(TableRef),
7224    /// Change owner
7225    OwnerTo(Identifier),
7226    /// Set schema
7227    SetSchema(Identifier),
7228    /// Set authorization (Trino/Presto)
7229    SetAuthorization(String),
7230    /// Alter column
7231    AlterColumn {
7232        name: Identifier,
7233        action: AlterColumnAction,
7234    },
7235    /// Redefine view as query (SELECT, UNION, etc.)
7236    AsSelect(Box<Expression>),
7237    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
7238    SetTblproperties(Vec<(String, String)>),
7239    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
7240    UnsetTblproperties(Vec<String>),
7241}
7242
7243impl AlterView {
7244    pub fn new(name: impl Into<String>) -> Self {
7245        Self {
7246            name: TableRef::new(name),
7247            actions: Vec::new(),
7248            algorithm: None,
7249            definer: None,
7250            sql_security: None,
7251            with_option: None,
7252            columns: Vec::new(),
7253        }
7254    }
7255}
7256
7257/// ALTER INDEX statement
7258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7259#[cfg_attr(feature = "bindings", derive(TS))]
7260pub struct AlterIndex {
7261    pub name: Identifier,
7262    pub table: Option<TableRef>,
7263    pub actions: Vec<AlterIndexAction>,
7264}
7265
7266/// Actions for ALTER INDEX
7267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7268#[cfg_attr(feature = "bindings", derive(TS))]
7269pub enum AlterIndexAction {
7270    /// Rename the index
7271    Rename(Identifier),
7272    /// Set tablespace
7273    SetTablespace(Identifier),
7274    /// Set visibility (MySQL)
7275    Visible(bool),
7276}
7277
7278impl AlterIndex {
7279    pub fn new(name: impl Into<String>) -> Self {
7280        Self {
7281            name: Identifier::new(name),
7282            table: None,
7283            actions: Vec::new(),
7284        }
7285    }
7286}
7287
7288/// CREATE SCHEMA statement
7289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7290#[cfg_attr(feature = "bindings", derive(TS))]
7291pub struct CreateSchema {
7292    pub name: Identifier,
7293    pub if_not_exists: bool,
7294    pub authorization: Option<Identifier>,
7295    #[serde(default)]
7296    pub clone_from: Option<Identifier>,
7297    /// AT/BEFORE clause for time travel (Snowflake)
7298    #[serde(default)]
7299    pub at_clause: Option<Expression>,
7300    /// Schema properties like DEFAULT COLLATE
7301    #[serde(default)]
7302    pub properties: Vec<Expression>,
7303    /// Leading comments before the statement
7304    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7305    pub leading_comments: Vec<String>,
7306}
7307
7308impl CreateSchema {
7309    pub fn new(name: impl Into<String>) -> Self {
7310        Self {
7311            name: Identifier::new(name),
7312            if_not_exists: false,
7313            authorization: None,
7314            clone_from: None,
7315            at_clause: None,
7316            properties: Vec::new(),
7317            leading_comments: Vec::new(),
7318        }
7319    }
7320}
7321
7322/// DROP SCHEMA statement
7323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7324#[cfg_attr(feature = "bindings", derive(TS))]
7325pub struct DropSchema {
7326    pub name: Identifier,
7327    pub if_exists: bool,
7328    pub cascade: bool,
7329}
7330
7331impl DropSchema {
7332    pub fn new(name: impl Into<String>) -> Self {
7333        Self {
7334            name: Identifier::new(name),
7335            if_exists: false,
7336            cascade: false,
7337        }
7338    }
7339}
7340
7341/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
7342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7343#[cfg_attr(feature = "bindings", derive(TS))]
7344pub struct DropNamespace {
7345    pub name: Identifier,
7346    pub if_exists: bool,
7347    pub cascade: bool,
7348}
7349
7350impl DropNamespace {
7351    pub fn new(name: impl Into<String>) -> Self {
7352        Self {
7353            name: Identifier::new(name),
7354            if_exists: false,
7355            cascade: false,
7356        }
7357    }
7358}
7359
7360/// CREATE DATABASE statement
7361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7362#[cfg_attr(feature = "bindings", derive(TS))]
7363pub struct CreateDatabase {
7364    pub name: Identifier,
7365    pub if_not_exists: bool,
7366    pub options: Vec<DatabaseOption>,
7367    /// Snowflake CLONE source
7368    #[serde(default)]
7369    pub clone_from: Option<Identifier>,
7370    /// AT/BEFORE clause for time travel (Snowflake)
7371    #[serde(default)]
7372    pub at_clause: Option<Expression>,
7373}
7374
7375/// Database option
7376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7377#[cfg_attr(feature = "bindings", derive(TS))]
7378pub enum DatabaseOption {
7379    CharacterSet(String),
7380    Collate(String),
7381    Owner(Identifier),
7382    Template(Identifier),
7383    Encoding(String),
7384    Location(String),
7385}
7386
7387impl CreateDatabase {
7388    pub fn new(name: impl Into<String>) -> Self {
7389        Self {
7390            name: Identifier::new(name),
7391            if_not_exists: false,
7392            options: Vec::new(),
7393            clone_from: None,
7394            at_clause: None,
7395        }
7396    }
7397}
7398
7399/// DROP DATABASE statement
7400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7401#[cfg_attr(feature = "bindings", derive(TS))]
7402pub struct DropDatabase {
7403    pub name: Identifier,
7404    pub if_exists: bool,
7405}
7406
7407impl DropDatabase {
7408    pub fn new(name: impl Into<String>) -> Self {
7409        Self {
7410            name: Identifier::new(name),
7411            if_exists: false,
7412        }
7413    }
7414}
7415
7416/// CREATE FUNCTION statement
7417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7418#[cfg_attr(feature = "bindings", derive(TS))]
7419pub struct CreateFunction {
7420    pub name: TableRef,
7421    pub parameters: Vec<FunctionParameter>,
7422    pub return_type: Option<DataType>,
7423    pub body: Option<FunctionBody>,
7424    pub or_replace: bool,
7425    pub if_not_exists: bool,
7426    pub temporary: bool,
7427    pub language: Option<String>,
7428    pub deterministic: Option<bool>,
7429    pub returns_null_on_null_input: Option<bool>,
7430    pub security: Option<FunctionSecurity>,
7431    /// Whether parentheses were present in the original syntax
7432    #[serde(default = "default_true")]
7433    pub has_parens: bool,
7434    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
7435    #[serde(default)]
7436    pub sql_data_access: Option<SqlDataAccess>,
7437    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
7438    #[serde(default, skip_serializing_if = "Option::is_none")]
7439    pub returns_table_body: Option<String>,
7440    /// True if LANGUAGE clause appears before RETURNS clause
7441    #[serde(default)]
7442    pub language_first: bool,
7443    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
7444    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7445    pub set_options: Vec<FunctionSetOption>,
7446    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
7447    #[serde(default)]
7448    pub strict: bool,
7449    /// BigQuery: OPTIONS (key=value, ...)
7450    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7451    pub options: Vec<Expression>,
7452    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
7453    #[serde(default)]
7454    pub is_table_function: bool,
7455    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
7456    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7457    pub property_order: Vec<FunctionPropertyKind>,
7458    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
7459    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7460    pub environment: Vec<Expression>,
7461}
7462
7463/// A SET option in CREATE FUNCTION (PostgreSQL)
7464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7465#[cfg_attr(feature = "bindings", derive(TS))]
7466pub struct FunctionSetOption {
7467    pub name: String,
7468    pub value: FunctionSetValue,
7469}
7470
7471/// The value of a SET option
7472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7473#[cfg_attr(feature = "bindings", derive(TS))]
7474pub enum FunctionSetValue {
7475    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
7476    Value { value: String, use_to: bool },
7477    /// SET key FROM CURRENT
7478    FromCurrent,
7479}
7480
7481/// SQL data access characteristics for functions
7482#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7483#[cfg_attr(feature = "bindings", derive(TS))]
7484pub enum SqlDataAccess {
7485    /// NO SQL
7486    NoSql,
7487    /// CONTAINS SQL
7488    ContainsSql,
7489    /// READS SQL DATA
7490    ReadsSqlData,
7491    /// MODIFIES SQL DATA
7492    ModifiesSqlData,
7493}
7494
7495/// Types of properties in CREATE FUNCTION for tracking their original order
7496#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7497#[cfg_attr(feature = "bindings", derive(TS))]
7498pub enum FunctionPropertyKind {
7499    /// SET option
7500    Set,
7501    /// AS body
7502    As,
7503    /// LANGUAGE clause
7504    Language,
7505    /// IMMUTABLE/VOLATILE/STABLE (determinism)
7506    Determinism,
7507    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
7508    NullInput,
7509    /// SECURITY DEFINER/INVOKER
7510    Security,
7511    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
7512    SqlDataAccess,
7513    /// OPTIONS clause (BigQuery)
7514    Options,
7515    /// ENVIRONMENT clause (Databricks)
7516    Environment,
7517}
7518
7519/// Function parameter
7520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7521#[cfg_attr(feature = "bindings", derive(TS))]
7522pub struct FunctionParameter {
7523    pub name: Option<Identifier>,
7524    pub data_type: DataType,
7525    pub mode: Option<ParameterMode>,
7526    pub default: Option<Expression>,
7527    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
7528    #[serde(default, skip_serializing_if = "Option::is_none")]
7529    pub mode_text: Option<String>,
7530}
7531
7532/// Parameter mode (IN, OUT, INOUT, VARIADIC)
7533#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7534#[cfg_attr(feature = "bindings", derive(TS))]
7535pub enum ParameterMode {
7536    In,
7537    Out,
7538    InOut,
7539    Variadic,
7540}
7541
7542/// Function body
7543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7544#[cfg_attr(feature = "bindings", derive(TS))]
7545pub enum FunctionBody {
7546    /// AS $$ ... $$ (dollar-quoted)
7547    Block(String),
7548    /// AS 'string' (single-quoted string literal body)
7549    StringLiteral(String),
7550    /// AS 'expression'
7551    Expression(Expression),
7552    /// EXTERNAL NAME 'library'
7553    External(String),
7554    /// RETURN expression
7555    Return(Expression),
7556    /// BEGIN ... END block with parsed statements
7557    Statements(Vec<Expression>),
7558    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7559    /// Stores (content, optional_tag)
7560    DollarQuoted {
7561        content: String,
7562        tag: Option<String>,
7563    },
7564}
7565
7566/// Function security (DEFINER, INVOKER, or NONE)
7567#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7568#[cfg_attr(feature = "bindings", derive(TS))]
7569pub enum FunctionSecurity {
7570    Definer,
7571    Invoker,
7572    /// StarRocks/MySQL: SECURITY NONE
7573    None,
7574}
7575
7576impl CreateFunction {
7577    pub fn new(name: impl Into<String>) -> Self {
7578        Self {
7579            name: TableRef::new(name),
7580            parameters: Vec::new(),
7581            return_type: None,
7582            body: None,
7583            or_replace: false,
7584            if_not_exists: false,
7585            temporary: false,
7586            language: None,
7587            deterministic: None,
7588            returns_null_on_null_input: None,
7589            security: None,
7590            has_parens: true,
7591            sql_data_access: None,
7592            returns_table_body: None,
7593            language_first: false,
7594            set_options: Vec::new(),
7595            strict: false,
7596            options: Vec::new(),
7597            is_table_function: false,
7598            property_order: Vec::new(),
7599            environment: Vec::new(),
7600        }
7601    }
7602}
7603
7604/// DROP FUNCTION statement
7605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7606#[cfg_attr(feature = "bindings", derive(TS))]
7607pub struct DropFunction {
7608    pub name: TableRef,
7609    pub parameters: Option<Vec<DataType>>,
7610    pub if_exists: bool,
7611    pub cascade: bool,
7612}
7613
7614impl DropFunction {
7615    pub fn new(name: impl Into<String>) -> Self {
7616        Self {
7617            name: TableRef::new(name),
7618            parameters: None,
7619            if_exists: false,
7620            cascade: false,
7621        }
7622    }
7623}
7624
7625/// CREATE PROCEDURE statement
7626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7627#[cfg_attr(feature = "bindings", derive(TS))]
7628pub struct CreateProcedure {
7629    pub name: TableRef,
7630    pub parameters: Vec<FunctionParameter>,
7631    pub body: Option<FunctionBody>,
7632    pub or_replace: bool,
7633    pub if_not_exists: bool,
7634    pub language: Option<String>,
7635    pub security: Option<FunctionSecurity>,
7636    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7637    #[serde(default)]
7638    pub return_type: Option<DataType>,
7639    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7640    #[serde(default)]
7641    pub execute_as: Option<String>,
7642    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7643    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7644    pub with_options: Vec<String>,
7645    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7646    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7647    pub has_parens: bool,
7648    /// Whether the short form PROC was used (instead of PROCEDURE)
7649    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7650    pub use_proc_keyword: bool,
7651}
7652
7653impl CreateProcedure {
7654    pub fn new(name: impl Into<String>) -> Self {
7655        Self {
7656            name: TableRef::new(name),
7657            parameters: Vec::new(),
7658            body: None,
7659            or_replace: false,
7660            if_not_exists: false,
7661            language: None,
7662            security: None,
7663            return_type: None,
7664            execute_as: None,
7665            with_options: Vec::new(),
7666            has_parens: true,
7667            use_proc_keyword: false,
7668        }
7669    }
7670}
7671
7672/// DROP PROCEDURE statement
7673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7674#[cfg_attr(feature = "bindings", derive(TS))]
7675pub struct DropProcedure {
7676    pub name: TableRef,
7677    pub parameters: Option<Vec<DataType>>,
7678    pub if_exists: bool,
7679    pub cascade: bool,
7680}
7681
7682impl DropProcedure {
7683    pub fn new(name: impl Into<String>) -> Self {
7684        Self {
7685            name: TableRef::new(name),
7686            parameters: None,
7687            if_exists: false,
7688            cascade: false,
7689        }
7690    }
7691}
7692
7693/// Sequence property tag for ordering
7694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7695#[cfg_attr(feature = "bindings", derive(TS))]
7696pub enum SeqPropKind {
7697    Start,
7698    Increment,
7699    Minvalue,
7700    Maxvalue,
7701    Cache,
7702    NoCache,
7703    Cycle,
7704    NoCycle,
7705    OwnedBy,
7706    Order,
7707    NoOrder,
7708    Comment,
7709    /// SHARING=<value> (Oracle)
7710    Sharing,
7711    /// KEEP (Oracle)
7712    Keep,
7713    /// NOKEEP (Oracle)
7714    NoKeep,
7715    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7716    Scale,
7717    /// NOSCALE (Oracle)
7718    NoScale,
7719    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7720    Shard,
7721    /// NOSHARD (Oracle)
7722    NoShard,
7723    /// SESSION (Oracle)
7724    Session,
7725    /// GLOBAL (Oracle)
7726    Global,
7727    /// NOCACHE (single word, Oracle)
7728    NoCacheWord,
7729    /// NOCYCLE (single word, Oracle)
7730    NoCycleWord,
7731    /// NOMINVALUE (single word, Oracle)
7732    NoMinvalueWord,
7733    /// NOMAXVALUE (single word, Oracle)
7734    NoMaxvalueWord,
7735}
7736
7737/// CREATE SEQUENCE statement
7738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7739#[cfg_attr(feature = "bindings", derive(TS))]
7740pub struct CreateSequence {
7741    pub name: TableRef,
7742    pub if_not_exists: bool,
7743    pub temporary: bool,
7744    #[serde(default)]
7745    pub or_replace: bool,
7746    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7747    #[serde(default, skip_serializing_if = "Option::is_none")]
7748    pub as_type: Option<DataType>,
7749    pub increment: Option<i64>,
7750    pub minvalue: Option<SequenceBound>,
7751    pub maxvalue: Option<SequenceBound>,
7752    pub start: Option<i64>,
7753    pub cache: Option<i64>,
7754    pub cycle: bool,
7755    pub owned_by: Option<TableRef>,
7756    /// Whether OWNED BY NONE was specified
7757    #[serde(default)]
7758    pub owned_by_none: bool,
7759    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7760    #[serde(default)]
7761    pub order: Option<bool>,
7762    /// Snowflake: COMMENT = 'value'
7763    #[serde(default)]
7764    pub comment: Option<String>,
7765    /// SHARING=<value> (Oracle)
7766    #[serde(default, skip_serializing_if = "Option::is_none")]
7767    pub sharing: Option<String>,
7768    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7769    #[serde(default, skip_serializing_if = "Option::is_none")]
7770    pub scale_modifier: Option<String>,
7771    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7772    #[serde(default, skip_serializing_if = "Option::is_none")]
7773    pub shard_modifier: Option<String>,
7774    /// Tracks the order in which properties appeared in the source
7775    #[serde(default)]
7776    pub property_order: Vec<SeqPropKind>,
7777}
7778
7779/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7781#[cfg_attr(feature = "bindings", derive(TS))]
7782pub enum SequenceBound {
7783    Value(i64),
7784    None,
7785}
7786
7787impl CreateSequence {
7788    pub fn new(name: impl Into<String>) -> Self {
7789        Self {
7790            name: TableRef::new(name),
7791            if_not_exists: false,
7792            temporary: false,
7793            or_replace: false,
7794            as_type: None,
7795            increment: None,
7796            minvalue: None,
7797            maxvalue: None,
7798            start: None,
7799            cache: None,
7800            cycle: false,
7801            owned_by: None,
7802            owned_by_none: false,
7803            order: None,
7804            comment: None,
7805            sharing: None,
7806            scale_modifier: None,
7807            shard_modifier: None,
7808            property_order: Vec::new(),
7809        }
7810    }
7811}
7812
7813/// DROP SEQUENCE statement
7814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7815#[cfg_attr(feature = "bindings", derive(TS))]
7816pub struct DropSequence {
7817    pub name: TableRef,
7818    pub if_exists: bool,
7819    pub cascade: bool,
7820}
7821
7822impl DropSequence {
7823    pub fn new(name: impl Into<String>) -> Self {
7824        Self {
7825            name: TableRef::new(name),
7826            if_exists: false,
7827            cascade: false,
7828        }
7829    }
7830}
7831
7832/// ALTER SEQUENCE statement
7833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7834#[cfg_attr(feature = "bindings", derive(TS))]
7835pub struct AlterSequence {
7836    pub name: TableRef,
7837    pub if_exists: bool,
7838    pub increment: Option<i64>,
7839    pub minvalue: Option<SequenceBound>,
7840    pub maxvalue: Option<SequenceBound>,
7841    pub start: Option<i64>,
7842    pub restart: Option<Option<i64>>,
7843    pub cache: Option<i64>,
7844    pub cycle: Option<bool>,
7845    pub owned_by: Option<Option<TableRef>>,
7846}
7847
7848impl AlterSequence {
7849    pub fn new(name: impl Into<String>) -> Self {
7850        Self {
7851            name: TableRef::new(name),
7852            if_exists: false,
7853            increment: None,
7854            minvalue: None,
7855            maxvalue: None,
7856            start: None,
7857            restart: None,
7858            cache: None,
7859            cycle: None,
7860            owned_by: None,
7861        }
7862    }
7863}
7864
7865/// CREATE TRIGGER statement
7866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7867#[cfg_attr(feature = "bindings", derive(TS))]
7868pub struct CreateTrigger {
7869    pub name: Identifier,
7870    pub table: TableRef,
7871    pub timing: TriggerTiming,
7872    pub events: Vec<TriggerEvent>,
7873    pub for_each: TriggerForEach,
7874    pub when: Option<Expression>,
7875    pub body: TriggerBody,
7876    pub or_replace: bool,
7877    pub constraint: bool,
7878    pub deferrable: Option<bool>,
7879    pub initially_deferred: Option<bool>,
7880    pub referencing: Option<TriggerReferencing>,
7881}
7882
7883/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7884#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7885#[cfg_attr(feature = "bindings", derive(TS))]
7886pub enum TriggerTiming {
7887    Before,
7888    After,
7889    InsteadOf,
7890}
7891
7892/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7894#[cfg_attr(feature = "bindings", derive(TS))]
7895pub enum TriggerEvent {
7896    Insert,
7897    Update(Option<Vec<Identifier>>),
7898    Delete,
7899    Truncate,
7900}
7901
7902/// Trigger FOR EACH clause
7903#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7904#[cfg_attr(feature = "bindings", derive(TS))]
7905pub enum TriggerForEach {
7906    Row,
7907    Statement,
7908}
7909
7910/// Trigger body
7911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7912#[cfg_attr(feature = "bindings", derive(TS))]
7913pub enum TriggerBody {
7914    /// EXECUTE FUNCTION/PROCEDURE name(args)
7915    Execute {
7916        function: TableRef,
7917        args: Vec<Expression>,
7918    },
7919    /// BEGIN ... END block
7920    Block(String),
7921}
7922
7923/// Trigger REFERENCING clause
7924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7925#[cfg_attr(feature = "bindings", derive(TS))]
7926pub struct TriggerReferencing {
7927    pub old_table: Option<Identifier>,
7928    pub new_table: Option<Identifier>,
7929    pub old_row: Option<Identifier>,
7930    pub new_row: Option<Identifier>,
7931}
7932
7933impl CreateTrigger {
7934    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7935        Self {
7936            name: Identifier::new(name),
7937            table: TableRef::new(table),
7938            timing: TriggerTiming::Before,
7939            events: Vec::new(),
7940            for_each: TriggerForEach::Row,
7941            when: None,
7942            body: TriggerBody::Execute {
7943                function: TableRef::new(""),
7944                args: Vec::new(),
7945            },
7946            or_replace: false,
7947            constraint: false,
7948            deferrable: None,
7949            initially_deferred: None,
7950            referencing: None,
7951        }
7952    }
7953}
7954
7955/// DROP TRIGGER statement
7956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7957#[cfg_attr(feature = "bindings", derive(TS))]
7958pub struct DropTrigger {
7959    pub name: Identifier,
7960    pub table: Option<TableRef>,
7961    pub if_exists: bool,
7962    pub cascade: bool,
7963}
7964
7965impl DropTrigger {
7966    pub fn new(name: impl Into<String>) -> Self {
7967        Self {
7968            name: Identifier::new(name),
7969            table: None,
7970            if_exists: false,
7971            cascade: false,
7972        }
7973    }
7974}
7975
7976/// CREATE TYPE statement
7977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7978#[cfg_attr(feature = "bindings", derive(TS))]
7979pub struct CreateType {
7980    pub name: TableRef,
7981    pub definition: TypeDefinition,
7982    pub if_not_exists: bool,
7983}
7984
7985/// Type definition
7986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7987#[cfg_attr(feature = "bindings", derive(TS))]
7988pub enum TypeDefinition {
7989    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7990    Enum(Vec<String>),
7991    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7992    Composite(Vec<TypeAttribute>),
7993    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7994    Range {
7995        subtype: DataType,
7996        subtype_diff: Option<String>,
7997        canonical: Option<String>,
7998    },
7999    /// Base type (for advanced usage)
8000    Base {
8001        input: String,
8002        output: String,
8003        internallength: Option<i32>,
8004    },
8005    /// Domain type
8006    Domain {
8007        base_type: DataType,
8008        default: Option<Expression>,
8009        constraints: Vec<DomainConstraint>,
8010    },
8011}
8012
8013/// Type attribute for composite types
8014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8015#[cfg_attr(feature = "bindings", derive(TS))]
8016pub struct TypeAttribute {
8017    pub name: Identifier,
8018    pub data_type: DataType,
8019    pub collate: Option<Identifier>,
8020}
8021
8022/// Domain constraint
8023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8024#[cfg_attr(feature = "bindings", derive(TS))]
8025pub struct DomainConstraint {
8026    pub name: Option<Identifier>,
8027    pub check: Expression,
8028}
8029
8030impl CreateType {
8031    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
8032        Self {
8033            name: TableRef::new(name),
8034            definition: TypeDefinition::Enum(values),
8035            if_not_exists: false,
8036        }
8037    }
8038
8039    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
8040        Self {
8041            name: TableRef::new(name),
8042            definition: TypeDefinition::Composite(attributes),
8043            if_not_exists: false,
8044        }
8045    }
8046}
8047
8048/// DROP TYPE statement
8049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8050#[cfg_attr(feature = "bindings", derive(TS))]
8051pub struct DropType {
8052    pub name: TableRef,
8053    pub if_exists: bool,
8054    pub cascade: bool,
8055}
8056
8057impl DropType {
8058    pub fn new(name: impl Into<String>) -> Self {
8059        Self {
8060            name: TableRef::new(name),
8061            if_exists: false,
8062            cascade: false,
8063        }
8064    }
8065}
8066
8067/// DESCRIBE statement - shows table structure or query plan
8068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8069#[cfg_attr(feature = "bindings", derive(TS))]
8070pub struct Describe {
8071    /// The target to describe (table name or query)
8072    pub target: Expression,
8073    /// EXTENDED format
8074    pub extended: bool,
8075    /// FORMATTED format
8076    pub formatted: bool,
8077    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
8078    #[serde(default)]
8079    pub kind: Option<String>,
8080    /// Properties like type=stage
8081    #[serde(default)]
8082    pub properties: Vec<(String, String)>,
8083    /// Style keyword (e.g., "ANALYZE", "HISTORY")
8084    #[serde(default, skip_serializing_if = "Option::is_none")]
8085    pub style: Option<String>,
8086    /// Partition specification for DESCRIBE PARTITION
8087    #[serde(default)]
8088    pub partition: Option<Box<Expression>>,
8089    /// Leading comments before the statement
8090    #[serde(default)]
8091    pub leading_comments: Vec<String>,
8092    /// AS JSON suffix (Databricks)
8093    #[serde(default)]
8094    pub as_json: bool,
8095}
8096
8097impl Describe {
8098    pub fn new(target: Expression) -> Self {
8099        Self {
8100            target,
8101            extended: false,
8102            formatted: false,
8103            kind: None,
8104            properties: Vec::new(),
8105            style: None,
8106            partition: None,
8107            leading_comments: Vec::new(),
8108            as_json: false,
8109        }
8110    }
8111}
8112
8113/// SHOW statement - displays database objects
8114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8115#[cfg_attr(feature = "bindings", derive(TS))]
8116pub struct Show {
8117    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
8118    pub this: String,
8119    /// Whether TERSE was specified
8120    #[serde(default)]
8121    pub terse: bool,
8122    /// Whether HISTORY was specified
8123    #[serde(default)]
8124    pub history: bool,
8125    /// LIKE pattern
8126    pub like: Option<Expression>,
8127    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
8128    pub scope_kind: Option<String>,
8129    /// IN scope object
8130    pub scope: Option<Expression>,
8131    /// STARTS WITH pattern
8132    pub starts_with: Option<Expression>,
8133    /// LIMIT clause
8134    pub limit: Option<Box<Limit>>,
8135    /// FROM clause (for specific object)
8136    pub from: Option<Expression>,
8137    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
8138    #[serde(default, skip_serializing_if = "Option::is_none")]
8139    pub where_clause: Option<Expression>,
8140    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
8141    #[serde(default, skip_serializing_if = "Option::is_none")]
8142    pub for_target: Option<Expression>,
8143    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
8144    #[serde(default, skip_serializing_if = "Option::is_none")]
8145    pub db: Option<Expression>,
8146    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
8147    #[serde(default, skip_serializing_if = "Option::is_none")]
8148    pub target: Option<Expression>,
8149    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
8150    #[serde(default, skip_serializing_if = "Option::is_none")]
8151    pub mutex: Option<bool>,
8152    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
8153    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8154    pub privileges: Vec<String>,
8155}
8156
8157impl Show {
8158    pub fn new(this: impl Into<String>) -> Self {
8159        Self {
8160            this: this.into(),
8161            terse: false,
8162            history: false,
8163            like: None,
8164            scope_kind: None,
8165            scope: None,
8166            starts_with: None,
8167            limit: None,
8168            from: None,
8169            where_clause: None,
8170            for_target: None,
8171            db: None,
8172            target: None,
8173            mutex: None,
8174            privileges: Vec::new(),
8175        }
8176    }
8177}
8178
8179/// Represent an explicit parenthesized expression for grouping precedence.
8180///
8181/// Preserves user-written parentheses so that `(a + b) * c` round-trips
8182/// correctly instead of being flattened to `a + b * c`.
8183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8184#[cfg_attr(feature = "bindings", derive(TS))]
8185pub struct Paren {
8186    /// The inner expression wrapped by parentheses.
8187    pub this: Expression,
8188    #[serde(default)]
8189    pub trailing_comments: Vec<String>,
8190}
8191
8192/// Expression annotated with trailing comments (for round-trip preservation)
8193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8194#[cfg_attr(feature = "bindings", derive(TS))]
8195pub struct Annotated {
8196    pub this: Expression,
8197    pub trailing_comments: Vec<String>,
8198}
8199
8200// === BATCH GENERATED STRUCT DEFINITIONS ===
8201// Generated from Python sqlglot expressions.py
8202
8203/// Refresh
8204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8205#[cfg_attr(feature = "bindings", derive(TS))]
8206pub struct Refresh {
8207    pub this: Box<Expression>,
8208    pub kind: String,
8209}
8210
8211/// LockingStatement
8212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8213#[cfg_attr(feature = "bindings", derive(TS))]
8214pub struct LockingStatement {
8215    pub this: Box<Expression>,
8216    pub expression: Box<Expression>,
8217}
8218
8219/// SequenceProperties
8220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8221#[cfg_attr(feature = "bindings", derive(TS))]
8222pub struct SequenceProperties {
8223    #[serde(default)]
8224    pub increment: Option<Box<Expression>>,
8225    #[serde(default)]
8226    pub minvalue: Option<Box<Expression>>,
8227    #[serde(default)]
8228    pub maxvalue: Option<Box<Expression>>,
8229    #[serde(default)]
8230    pub cache: Option<Box<Expression>>,
8231    #[serde(default)]
8232    pub start: Option<Box<Expression>>,
8233    #[serde(default)]
8234    pub owned: Option<Box<Expression>>,
8235    #[serde(default)]
8236    pub options: Vec<Expression>,
8237}
8238
8239/// TruncateTable
8240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8241#[cfg_attr(feature = "bindings", derive(TS))]
8242pub struct TruncateTable {
8243    #[serde(default)]
8244    pub expressions: Vec<Expression>,
8245    #[serde(default)]
8246    pub is_database: Option<Box<Expression>>,
8247    #[serde(default)]
8248    pub exists: bool,
8249    #[serde(default)]
8250    pub only: Option<Box<Expression>>,
8251    #[serde(default)]
8252    pub cluster: Option<Box<Expression>>,
8253    #[serde(default)]
8254    pub identity: Option<Box<Expression>>,
8255    #[serde(default)]
8256    pub option: Option<Box<Expression>>,
8257    #[serde(default)]
8258    pub partition: Option<Box<Expression>>,
8259}
8260
8261/// Clone
8262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8263#[cfg_attr(feature = "bindings", derive(TS))]
8264pub struct Clone {
8265    pub this: Box<Expression>,
8266    #[serde(default)]
8267    pub shallow: Option<Box<Expression>>,
8268    #[serde(default)]
8269    pub copy: Option<Box<Expression>>,
8270}
8271
8272/// Attach
8273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8274#[cfg_attr(feature = "bindings", derive(TS))]
8275pub struct Attach {
8276    pub this: Box<Expression>,
8277    #[serde(default)]
8278    pub exists: bool,
8279    #[serde(default)]
8280    pub expressions: Vec<Expression>,
8281}
8282
8283/// Detach
8284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8285#[cfg_attr(feature = "bindings", derive(TS))]
8286pub struct Detach {
8287    pub this: Box<Expression>,
8288    #[serde(default)]
8289    pub exists: bool,
8290}
8291
8292/// Install
8293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8294#[cfg_attr(feature = "bindings", derive(TS))]
8295pub struct Install {
8296    pub this: Box<Expression>,
8297    #[serde(default)]
8298    pub from_: Option<Box<Expression>>,
8299    #[serde(default)]
8300    pub force: Option<Box<Expression>>,
8301}
8302
8303/// Summarize
8304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8305#[cfg_attr(feature = "bindings", derive(TS))]
8306pub struct Summarize {
8307    pub this: Box<Expression>,
8308    #[serde(default)]
8309    pub table: Option<Box<Expression>>,
8310}
8311
8312/// Declare
8313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8314#[cfg_attr(feature = "bindings", derive(TS))]
8315pub struct Declare {
8316    #[serde(default)]
8317    pub expressions: Vec<Expression>,
8318}
8319
8320/// DeclareItem
8321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8322#[cfg_attr(feature = "bindings", derive(TS))]
8323pub struct DeclareItem {
8324    pub this: Box<Expression>,
8325    #[serde(default)]
8326    pub kind: Option<String>,
8327    #[serde(default)]
8328    pub default: Option<Box<Expression>>,
8329    #[serde(default)]
8330    pub has_as: bool,
8331    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
8332    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8333    pub additional_names: Vec<Expression>,
8334}
8335
8336/// Set
8337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8338#[cfg_attr(feature = "bindings", derive(TS))]
8339pub struct Set {
8340    #[serde(default)]
8341    pub expressions: Vec<Expression>,
8342    #[serde(default)]
8343    pub unset: Option<Box<Expression>>,
8344    #[serde(default)]
8345    pub tag: Option<Box<Expression>>,
8346}
8347
8348/// Heredoc
8349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8350#[cfg_attr(feature = "bindings", derive(TS))]
8351pub struct Heredoc {
8352    pub this: Box<Expression>,
8353    #[serde(default)]
8354    pub tag: Option<Box<Expression>>,
8355}
8356
8357/// QueryBand
8358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8359#[cfg_attr(feature = "bindings", derive(TS))]
8360pub struct QueryBand {
8361    pub this: Box<Expression>,
8362    #[serde(default)]
8363    pub scope: Option<Box<Expression>>,
8364    #[serde(default)]
8365    pub update: Option<Box<Expression>>,
8366}
8367
8368/// UserDefinedFunction
8369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8370#[cfg_attr(feature = "bindings", derive(TS))]
8371pub struct UserDefinedFunction {
8372    pub this: Box<Expression>,
8373    #[serde(default)]
8374    pub expressions: Vec<Expression>,
8375    #[serde(default)]
8376    pub wrapped: Option<Box<Expression>>,
8377}
8378
8379/// RecursiveWithSearch
8380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8381#[cfg_attr(feature = "bindings", derive(TS))]
8382pub struct RecursiveWithSearch {
8383    pub kind: String,
8384    pub this: Box<Expression>,
8385    pub expression: Box<Expression>,
8386    #[serde(default)]
8387    pub using: Option<Box<Expression>>,
8388}
8389
8390/// ProjectionDef
8391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8392#[cfg_attr(feature = "bindings", derive(TS))]
8393pub struct ProjectionDef {
8394    pub this: Box<Expression>,
8395    pub expression: Box<Expression>,
8396}
8397
8398/// TableAlias
8399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8400#[cfg_attr(feature = "bindings", derive(TS))]
8401pub struct TableAlias {
8402    #[serde(default)]
8403    pub this: Option<Box<Expression>>,
8404    #[serde(default)]
8405    pub columns: Vec<Expression>,
8406}
8407
8408/// ByteString
8409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8410#[cfg_attr(feature = "bindings", derive(TS))]
8411pub struct ByteString {
8412    pub this: Box<Expression>,
8413    #[serde(default)]
8414    pub is_bytes: Option<Box<Expression>>,
8415}
8416
8417/// HexStringExpr - Hex string expression (not literal)
8418/// BigQuery: converts to FROM_HEX(this)
8419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8420#[cfg_attr(feature = "bindings", derive(TS))]
8421pub struct HexStringExpr {
8422    pub this: Box<Expression>,
8423    #[serde(default)]
8424    pub is_integer: Option<bool>,
8425}
8426
8427/// UnicodeString
8428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8429#[cfg_attr(feature = "bindings", derive(TS))]
8430pub struct UnicodeString {
8431    pub this: Box<Expression>,
8432    #[serde(default)]
8433    pub escape: Option<Box<Expression>>,
8434}
8435
8436/// AlterColumn
8437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8438#[cfg_attr(feature = "bindings", derive(TS))]
8439pub struct AlterColumn {
8440    pub this: Box<Expression>,
8441    #[serde(default)]
8442    pub dtype: Option<Box<Expression>>,
8443    #[serde(default)]
8444    pub collate: Option<Box<Expression>>,
8445    #[serde(default)]
8446    pub using: Option<Box<Expression>>,
8447    #[serde(default)]
8448    pub default: Option<Box<Expression>>,
8449    #[serde(default)]
8450    pub drop: Option<Box<Expression>>,
8451    #[serde(default)]
8452    pub comment: Option<Box<Expression>>,
8453    #[serde(default)]
8454    pub allow_null: Option<Box<Expression>>,
8455    #[serde(default)]
8456    pub visible: Option<Box<Expression>>,
8457    #[serde(default)]
8458    pub rename_to: Option<Box<Expression>>,
8459}
8460
8461/// AlterSortKey
8462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8463#[cfg_attr(feature = "bindings", derive(TS))]
8464pub struct AlterSortKey {
8465    #[serde(default)]
8466    pub this: Option<Box<Expression>>,
8467    #[serde(default)]
8468    pub expressions: Vec<Expression>,
8469    #[serde(default)]
8470    pub compound: Option<Box<Expression>>,
8471}
8472
8473/// AlterSet
8474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8475#[cfg_attr(feature = "bindings", derive(TS))]
8476pub struct AlterSet {
8477    #[serde(default)]
8478    pub expressions: Vec<Expression>,
8479    #[serde(default)]
8480    pub option: Option<Box<Expression>>,
8481    #[serde(default)]
8482    pub tablespace: Option<Box<Expression>>,
8483    #[serde(default)]
8484    pub access_method: Option<Box<Expression>>,
8485    #[serde(default)]
8486    pub file_format: Option<Box<Expression>>,
8487    #[serde(default)]
8488    pub copy_options: Option<Box<Expression>>,
8489    #[serde(default)]
8490    pub tag: Option<Box<Expression>>,
8491    #[serde(default)]
8492    pub location: Option<Box<Expression>>,
8493    #[serde(default)]
8494    pub serde: Option<Box<Expression>>,
8495}
8496
8497/// RenameColumn
8498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8499#[cfg_attr(feature = "bindings", derive(TS))]
8500pub struct RenameColumn {
8501    pub this: Box<Expression>,
8502    #[serde(default)]
8503    pub to: Option<Box<Expression>>,
8504    #[serde(default)]
8505    pub exists: bool,
8506}
8507
8508/// Comprehension
8509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8510#[cfg_attr(feature = "bindings", derive(TS))]
8511pub struct Comprehension {
8512    pub this: Box<Expression>,
8513    pub expression: Box<Expression>,
8514    #[serde(default)]
8515    pub position: Option<Box<Expression>>,
8516    #[serde(default)]
8517    pub iterator: Option<Box<Expression>>,
8518    #[serde(default)]
8519    pub condition: Option<Box<Expression>>,
8520}
8521
8522/// MergeTreeTTLAction
8523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8524#[cfg_attr(feature = "bindings", derive(TS))]
8525pub struct MergeTreeTTLAction {
8526    pub this: Box<Expression>,
8527    #[serde(default)]
8528    pub delete: Option<Box<Expression>>,
8529    #[serde(default)]
8530    pub recompress: Option<Box<Expression>>,
8531    #[serde(default)]
8532    pub to_disk: Option<Box<Expression>>,
8533    #[serde(default)]
8534    pub to_volume: Option<Box<Expression>>,
8535}
8536
8537/// MergeTreeTTL
8538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8539#[cfg_attr(feature = "bindings", derive(TS))]
8540pub struct MergeTreeTTL {
8541    #[serde(default)]
8542    pub expressions: Vec<Expression>,
8543    #[serde(default)]
8544    pub where_: Option<Box<Expression>>,
8545    #[serde(default)]
8546    pub group: Option<Box<Expression>>,
8547    #[serde(default)]
8548    pub aggregates: Option<Box<Expression>>,
8549}
8550
8551/// IndexConstraintOption
8552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8553#[cfg_attr(feature = "bindings", derive(TS))]
8554pub struct IndexConstraintOption {
8555    #[serde(default)]
8556    pub key_block_size: Option<Box<Expression>>,
8557    #[serde(default)]
8558    pub using: Option<Box<Expression>>,
8559    #[serde(default)]
8560    pub parser: Option<Box<Expression>>,
8561    #[serde(default)]
8562    pub comment: Option<Box<Expression>>,
8563    #[serde(default)]
8564    pub visible: Option<Box<Expression>>,
8565    #[serde(default)]
8566    pub engine_attr: Option<Box<Expression>>,
8567    #[serde(default)]
8568    pub secondary_engine_attr: Option<Box<Expression>>,
8569}
8570
8571/// PeriodForSystemTimeConstraint
8572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8573#[cfg_attr(feature = "bindings", derive(TS))]
8574pub struct PeriodForSystemTimeConstraint {
8575    pub this: Box<Expression>,
8576    pub expression: Box<Expression>,
8577}
8578
8579/// CaseSpecificColumnConstraint
8580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8581#[cfg_attr(feature = "bindings", derive(TS))]
8582pub struct CaseSpecificColumnConstraint {
8583    #[serde(default)]
8584    pub not_: Option<Box<Expression>>,
8585}
8586
8587/// CharacterSetColumnConstraint
8588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8589#[cfg_attr(feature = "bindings", derive(TS))]
8590pub struct CharacterSetColumnConstraint {
8591    pub this: Box<Expression>,
8592}
8593
8594/// CheckColumnConstraint
8595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8596#[cfg_attr(feature = "bindings", derive(TS))]
8597pub struct CheckColumnConstraint {
8598    pub this: Box<Expression>,
8599    #[serde(default)]
8600    pub enforced: Option<Box<Expression>>,
8601}
8602
8603/// CompressColumnConstraint
8604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8605#[cfg_attr(feature = "bindings", derive(TS))]
8606pub struct CompressColumnConstraint {
8607    #[serde(default)]
8608    pub this: Option<Box<Expression>>,
8609}
8610
8611/// DateFormatColumnConstraint
8612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8613#[cfg_attr(feature = "bindings", derive(TS))]
8614pub struct DateFormatColumnConstraint {
8615    pub this: Box<Expression>,
8616}
8617
8618/// EphemeralColumnConstraint
8619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8620#[cfg_attr(feature = "bindings", derive(TS))]
8621pub struct EphemeralColumnConstraint {
8622    #[serde(default)]
8623    pub this: Option<Box<Expression>>,
8624}
8625
8626/// WithOperator
8627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8628#[cfg_attr(feature = "bindings", derive(TS))]
8629pub struct WithOperator {
8630    pub this: Box<Expression>,
8631    pub op: String,
8632}
8633
8634/// GeneratedAsIdentityColumnConstraint
8635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8636#[cfg_attr(feature = "bindings", derive(TS))]
8637pub struct GeneratedAsIdentityColumnConstraint {
8638    #[serde(default)]
8639    pub this: Option<Box<Expression>>,
8640    #[serde(default)]
8641    pub expression: Option<Box<Expression>>,
8642    #[serde(default)]
8643    pub on_null: Option<Box<Expression>>,
8644    #[serde(default)]
8645    pub start: Option<Box<Expression>>,
8646    #[serde(default)]
8647    pub increment: Option<Box<Expression>>,
8648    #[serde(default)]
8649    pub minvalue: Option<Box<Expression>>,
8650    #[serde(default)]
8651    pub maxvalue: Option<Box<Expression>>,
8652    #[serde(default)]
8653    pub cycle: Option<Box<Expression>>,
8654    #[serde(default)]
8655    pub order: Option<Box<Expression>>,
8656}
8657
8658/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8659/// TSQL: outputs "IDENTITY"
8660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8661#[cfg_attr(feature = "bindings", derive(TS))]
8662pub struct AutoIncrementColumnConstraint;
8663
8664/// CommentColumnConstraint - Column comment marker
8665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8666#[cfg_attr(feature = "bindings", derive(TS))]
8667pub struct CommentColumnConstraint;
8668
8669/// GeneratedAsRowColumnConstraint
8670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8671#[cfg_attr(feature = "bindings", derive(TS))]
8672pub struct GeneratedAsRowColumnConstraint {
8673    #[serde(default)]
8674    pub start: Option<Box<Expression>>,
8675    #[serde(default)]
8676    pub hidden: Option<Box<Expression>>,
8677}
8678
8679/// IndexColumnConstraint
8680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8681#[cfg_attr(feature = "bindings", derive(TS))]
8682pub struct IndexColumnConstraint {
8683    #[serde(default)]
8684    pub this: Option<Box<Expression>>,
8685    #[serde(default)]
8686    pub expressions: Vec<Expression>,
8687    #[serde(default)]
8688    pub kind: Option<String>,
8689    #[serde(default)]
8690    pub index_type: Option<Box<Expression>>,
8691    #[serde(default)]
8692    pub options: Vec<Expression>,
8693    #[serde(default)]
8694    pub expression: Option<Box<Expression>>,
8695    #[serde(default)]
8696    pub granularity: Option<Box<Expression>>,
8697}
8698
8699/// MaskingPolicyColumnConstraint
8700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8701#[cfg_attr(feature = "bindings", derive(TS))]
8702pub struct MaskingPolicyColumnConstraint {
8703    pub this: Box<Expression>,
8704    #[serde(default)]
8705    pub expressions: Vec<Expression>,
8706}
8707
8708/// NotNullColumnConstraint
8709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8710#[cfg_attr(feature = "bindings", derive(TS))]
8711pub struct NotNullColumnConstraint {
8712    #[serde(default)]
8713    pub allow_null: Option<Box<Expression>>,
8714}
8715
8716/// DefaultColumnConstraint - DEFAULT value for a column
8717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8718#[cfg_attr(feature = "bindings", derive(TS))]
8719pub struct DefaultColumnConstraint {
8720    pub this: Box<Expression>,
8721}
8722
8723/// PrimaryKeyColumnConstraint
8724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8725#[cfg_attr(feature = "bindings", derive(TS))]
8726pub struct PrimaryKeyColumnConstraint {
8727    #[serde(default)]
8728    pub desc: Option<Box<Expression>>,
8729    #[serde(default)]
8730    pub options: Vec<Expression>,
8731}
8732
8733/// UniqueColumnConstraint
8734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8735#[cfg_attr(feature = "bindings", derive(TS))]
8736pub struct UniqueColumnConstraint {
8737    #[serde(default)]
8738    pub this: Option<Box<Expression>>,
8739    #[serde(default)]
8740    pub index_type: Option<Box<Expression>>,
8741    #[serde(default)]
8742    pub on_conflict: Option<Box<Expression>>,
8743    #[serde(default)]
8744    pub nulls: Option<Box<Expression>>,
8745    #[serde(default)]
8746    pub options: Vec<Expression>,
8747}
8748
8749/// WatermarkColumnConstraint
8750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8751#[cfg_attr(feature = "bindings", derive(TS))]
8752pub struct WatermarkColumnConstraint {
8753    pub this: Box<Expression>,
8754    pub expression: Box<Expression>,
8755}
8756
8757/// ComputedColumnConstraint
8758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8759#[cfg_attr(feature = "bindings", derive(TS))]
8760pub struct ComputedColumnConstraint {
8761    pub this: Box<Expression>,
8762    #[serde(default)]
8763    pub persisted: Option<Box<Expression>>,
8764    #[serde(default)]
8765    pub not_null: Option<Box<Expression>>,
8766    #[serde(default)]
8767    pub data_type: Option<Box<Expression>>,
8768}
8769
8770/// InOutColumnConstraint
8771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8772#[cfg_attr(feature = "bindings", derive(TS))]
8773pub struct InOutColumnConstraint {
8774    #[serde(default)]
8775    pub input_: Option<Box<Expression>>,
8776    #[serde(default)]
8777    pub output: Option<Box<Expression>>,
8778}
8779
8780/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8782#[cfg_attr(feature = "bindings", derive(TS))]
8783pub struct PathColumnConstraint {
8784    pub this: Box<Expression>,
8785}
8786
8787/// Constraint
8788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8789#[cfg_attr(feature = "bindings", derive(TS))]
8790pub struct Constraint {
8791    pub this: Box<Expression>,
8792    #[serde(default)]
8793    pub expressions: Vec<Expression>,
8794}
8795
8796/// Export
8797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8798#[cfg_attr(feature = "bindings", derive(TS))]
8799pub struct Export {
8800    pub this: Box<Expression>,
8801    #[serde(default)]
8802    pub connection: Option<Box<Expression>>,
8803    #[serde(default)]
8804    pub options: Vec<Expression>,
8805}
8806
8807/// Filter
8808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8809#[cfg_attr(feature = "bindings", derive(TS))]
8810pub struct Filter {
8811    pub this: Box<Expression>,
8812    pub expression: Box<Expression>,
8813}
8814
8815/// Changes
8816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8817#[cfg_attr(feature = "bindings", derive(TS))]
8818pub struct Changes {
8819    #[serde(default)]
8820    pub information: Option<Box<Expression>>,
8821    #[serde(default)]
8822    pub at_before: Option<Box<Expression>>,
8823    #[serde(default)]
8824    pub end: Option<Box<Expression>>,
8825}
8826
8827/// Directory
8828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8829#[cfg_attr(feature = "bindings", derive(TS))]
8830pub struct Directory {
8831    pub this: Box<Expression>,
8832    #[serde(default)]
8833    pub local: Option<Box<Expression>>,
8834    #[serde(default)]
8835    pub row_format: Option<Box<Expression>>,
8836}
8837
8838/// ForeignKey
8839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8840#[cfg_attr(feature = "bindings", derive(TS))]
8841pub struct ForeignKey {
8842    #[serde(default)]
8843    pub expressions: Vec<Expression>,
8844    #[serde(default)]
8845    pub reference: Option<Box<Expression>>,
8846    #[serde(default)]
8847    pub delete: Option<Box<Expression>>,
8848    #[serde(default)]
8849    pub update: Option<Box<Expression>>,
8850    #[serde(default)]
8851    pub options: Vec<Expression>,
8852}
8853
8854/// ColumnPrefix
8855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8856#[cfg_attr(feature = "bindings", derive(TS))]
8857pub struct ColumnPrefix {
8858    pub this: Box<Expression>,
8859    pub expression: Box<Expression>,
8860}
8861
8862/// PrimaryKey
8863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8864#[cfg_attr(feature = "bindings", derive(TS))]
8865pub struct PrimaryKey {
8866    #[serde(default)]
8867    pub this: Option<Box<Expression>>,
8868    #[serde(default)]
8869    pub expressions: Vec<Expression>,
8870    #[serde(default)]
8871    pub options: Vec<Expression>,
8872    #[serde(default)]
8873    pub include: Option<Box<Expression>>,
8874}
8875
8876/// Into
8877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8878#[cfg_attr(feature = "bindings", derive(TS))]
8879pub struct IntoClause {
8880    #[serde(default)]
8881    pub this: Option<Box<Expression>>,
8882    #[serde(default)]
8883    pub temporary: bool,
8884    #[serde(default)]
8885    pub unlogged: Option<Box<Expression>>,
8886    #[serde(default)]
8887    pub bulk_collect: Option<Box<Expression>>,
8888    #[serde(default)]
8889    pub expressions: Vec<Expression>,
8890}
8891
8892/// JoinHint
8893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8894#[cfg_attr(feature = "bindings", derive(TS))]
8895pub struct JoinHint {
8896    pub this: Box<Expression>,
8897    #[serde(default)]
8898    pub expressions: Vec<Expression>,
8899}
8900
8901/// Opclass
8902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8903#[cfg_attr(feature = "bindings", derive(TS))]
8904pub struct Opclass {
8905    pub this: Box<Expression>,
8906    pub expression: Box<Expression>,
8907}
8908
8909/// Index
8910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8911#[cfg_attr(feature = "bindings", derive(TS))]
8912pub struct Index {
8913    #[serde(default)]
8914    pub this: Option<Box<Expression>>,
8915    #[serde(default)]
8916    pub table: Option<Box<Expression>>,
8917    #[serde(default)]
8918    pub unique: bool,
8919    #[serde(default)]
8920    pub primary: Option<Box<Expression>>,
8921    #[serde(default)]
8922    pub amp: Option<Box<Expression>>,
8923    #[serde(default)]
8924    pub params: Vec<Expression>,
8925}
8926
8927/// IndexParameters
8928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8929#[cfg_attr(feature = "bindings", derive(TS))]
8930pub struct IndexParameters {
8931    #[serde(default)]
8932    pub using: Option<Box<Expression>>,
8933    #[serde(default)]
8934    pub include: Option<Box<Expression>>,
8935    #[serde(default)]
8936    pub columns: Vec<Expression>,
8937    #[serde(default)]
8938    pub with_storage: Option<Box<Expression>>,
8939    #[serde(default)]
8940    pub partition_by: Option<Box<Expression>>,
8941    #[serde(default)]
8942    pub tablespace: Option<Box<Expression>>,
8943    #[serde(default)]
8944    pub where_: Option<Box<Expression>>,
8945    #[serde(default)]
8946    pub on: Option<Box<Expression>>,
8947}
8948
8949/// ConditionalInsert
8950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8951#[cfg_attr(feature = "bindings", derive(TS))]
8952pub struct ConditionalInsert {
8953    pub this: Box<Expression>,
8954    #[serde(default)]
8955    pub expression: Option<Box<Expression>>,
8956    #[serde(default)]
8957    pub else_: Option<Box<Expression>>,
8958}
8959
8960/// MultitableInserts
8961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8962#[cfg_attr(feature = "bindings", derive(TS))]
8963pub struct MultitableInserts {
8964    #[serde(default)]
8965    pub expressions: Vec<Expression>,
8966    pub kind: String,
8967    #[serde(default)]
8968    pub source: Option<Box<Expression>>,
8969    /// Leading comments before the statement
8970    #[serde(default)]
8971    pub leading_comments: Vec<String>,
8972}
8973
8974/// OnConflict
8975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8976#[cfg_attr(feature = "bindings", derive(TS))]
8977pub struct OnConflict {
8978    #[serde(default)]
8979    pub duplicate: Option<Box<Expression>>,
8980    #[serde(default)]
8981    pub expressions: Vec<Expression>,
8982    #[serde(default)]
8983    pub action: Option<Box<Expression>>,
8984    #[serde(default)]
8985    pub conflict_keys: Option<Box<Expression>>,
8986    #[serde(default)]
8987    pub index_predicate: Option<Box<Expression>>,
8988    #[serde(default)]
8989    pub constraint: Option<Box<Expression>>,
8990    #[serde(default)]
8991    pub where_: Option<Box<Expression>>,
8992}
8993
8994/// OnCondition
8995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8996#[cfg_attr(feature = "bindings", derive(TS))]
8997pub struct OnCondition {
8998    #[serde(default)]
8999    pub error: Option<Box<Expression>>,
9000    #[serde(default)]
9001    pub empty: Option<Box<Expression>>,
9002    #[serde(default)]
9003    pub null: Option<Box<Expression>>,
9004}
9005
9006/// Returning
9007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9008#[cfg_attr(feature = "bindings", derive(TS))]
9009pub struct Returning {
9010    #[serde(default)]
9011    pub expressions: Vec<Expression>,
9012    #[serde(default)]
9013    pub into: Option<Box<Expression>>,
9014}
9015
9016/// Introducer
9017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9018#[cfg_attr(feature = "bindings", derive(TS))]
9019pub struct Introducer {
9020    pub this: Box<Expression>,
9021    pub expression: Box<Expression>,
9022}
9023
9024/// PartitionRange
9025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9026#[cfg_attr(feature = "bindings", derive(TS))]
9027pub struct PartitionRange {
9028    pub this: Box<Expression>,
9029    #[serde(default)]
9030    pub expression: Option<Box<Expression>>,
9031    #[serde(default)]
9032    pub expressions: Vec<Expression>,
9033}
9034
9035/// Group
9036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9037#[cfg_attr(feature = "bindings", derive(TS))]
9038pub struct Group {
9039    #[serde(default)]
9040    pub expressions: Vec<Expression>,
9041    #[serde(default)]
9042    pub grouping_sets: Option<Box<Expression>>,
9043    #[serde(default)]
9044    pub cube: Option<Box<Expression>>,
9045    #[serde(default)]
9046    pub rollup: Option<Box<Expression>>,
9047    #[serde(default)]
9048    pub totals: Option<Box<Expression>>,
9049    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
9050    #[serde(default)]
9051    pub all: Option<bool>,
9052}
9053
9054/// Cube
9055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9056#[cfg_attr(feature = "bindings", derive(TS))]
9057pub struct Cube {
9058    #[serde(default)]
9059    pub expressions: Vec<Expression>,
9060}
9061
9062/// Rollup
9063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9064#[cfg_attr(feature = "bindings", derive(TS))]
9065pub struct Rollup {
9066    #[serde(default)]
9067    pub expressions: Vec<Expression>,
9068}
9069
9070/// GroupingSets
9071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9072#[cfg_attr(feature = "bindings", derive(TS))]
9073pub struct GroupingSets {
9074    #[serde(default)]
9075    pub expressions: Vec<Expression>,
9076}
9077
9078/// LimitOptions
9079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9080#[cfg_attr(feature = "bindings", derive(TS))]
9081pub struct LimitOptions {
9082    #[serde(default)]
9083    pub percent: Option<Box<Expression>>,
9084    #[serde(default)]
9085    pub rows: Option<Box<Expression>>,
9086    #[serde(default)]
9087    pub with_ties: Option<Box<Expression>>,
9088}
9089
9090/// Lateral
9091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9092#[cfg_attr(feature = "bindings", derive(TS))]
9093pub struct Lateral {
9094    pub this: Box<Expression>,
9095    #[serde(default)]
9096    pub view: Option<Box<Expression>>,
9097    #[serde(default)]
9098    pub outer: Option<Box<Expression>>,
9099    #[serde(default)]
9100    pub alias: Option<String>,
9101    /// Whether the alias was originally quoted (backtick/double-quote)
9102    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9103    pub alias_quoted: bool,
9104    #[serde(default)]
9105    pub cross_apply: Option<Box<Expression>>,
9106    #[serde(default)]
9107    pub ordinality: Option<Box<Expression>>,
9108    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
9109    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9110    pub column_aliases: Vec<String>,
9111}
9112
9113/// TableFromRows
9114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9115#[cfg_attr(feature = "bindings", derive(TS))]
9116pub struct TableFromRows {
9117    pub this: Box<Expression>,
9118    #[serde(default)]
9119    pub alias: Option<String>,
9120    #[serde(default)]
9121    pub joins: Vec<Expression>,
9122    #[serde(default)]
9123    pub pivots: Option<Box<Expression>>,
9124    #[serde(default)]
9125    pub sample: Option<Box<Expression>>,
9126}
9127
9128/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
9129/// Used for set-returning functions with typed column definitions
9130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9131#[cfg_attr(feature = "bindings", derive(TS))]
9132pub struct RowsFrom {
9133    /// List of function expressions, each potentially with an alias and typed columns
9134    pub expressions: Vec<Expression>,
9135    /// WITH ORDINALITY modifier
9136    #[serde(default)]
9137    pub ordinality: bool,
9138    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
9139    #[serde(default)]
9140    pub alias: Option<Box<Expression>>,
9141}
9142
9143/// WithFill
9144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9145#[cfg_attr(feature = "bindings", derive(TS))]
9146pub struct WithFill {
9147    #[serde(default)]
9148    pub from_: Option<Box<Expression>>,
9149    #[serde(default)]
9150    pub to: Option<Box<Expression>>,
9151    #[serde(default)]
9152    pub step: Option<Box<Expression>>,
9153    #[serde(default)]
9154    pub staleness: Option<Box<Expression>>,
9155    #[serde(default)]
9156    pub interpolate: Option<Box<Expression>>,
9157}
9158
9159/// Property
9160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9161#[cfg_attr(feature = "bindings", derive(TS))]
9162pub struct Property {
9163    pub this: Box<Expression>,
9164    #[serde(default)]
9165    pub value: Option<Box<Expression>>,
9166}
9167
9168/// GrantPrivilege
9169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9170#[cfg_attr(feature = "bindings", derive(TS))]
9171pub struct GrantPrivilege {
9172    pub this: Box<Expression>,
9173    #[serde(default)]
9174    pub expressions: Vec<Expression>,
9175}
9176
9177/// AllowedValuesProperty
9178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9179#[cfg_attr(feature = "bindings", derive(TS))]
9180pub struct AllowedValuesProperty {
9181    #[serde(default)]
9182    pub expressions: Vec<Expression>,
9183}
9184
9185/// AlgorithmProperty
9186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9187#[cfg_attr(feature = "bindings", derive(TS))]
9188pub struct AlgorithmProperty {
9189    pub this: Box<Expression>,
9190}
9191
9192/// AutoIncrementProperty
9193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9194#[cfg_attr(feature = "bindings", derive(TS))]
9195pub struct AutoIncrementProperty {
9196    pub this: Box<Expression>,
9197}
9198
9199/// AutoRefreshProperty
9200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9201#[cfg_attr(feature = "bindings", derive(TS))]
9202pub struct AutoRefreshProperty {
9203    pub this: Box<Expression>,
9204}
9205
9206/// BackupProperty
9207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9208#[cfg_attr(feature = "bindings", derive(TS))]
9209pub struct BackupProperty {
9210    pub this: Box<Expression>,
9211}
9212
9213/// BuildProperty
9214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9215#[cfg_attr(feature = "bindings", derive(TS))]
9216pub struct BuildProperty {
9217    pub this: Box<Expression>,
9218}
9219
9220/// BlockCompressionProperty
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct BlockCompressionProperty {
9224    #[serde(default)]
9225    pub autotemp: Option<Box<Expression>>,
9226    #[serde(default)]
9227    pub always: Option<Box<Expression>>,
9228    #[serde(default)]
9229    pub default: Option<Box<Expression>>,
9230    #[serde(default)]
9231    pub manual: Option<Box<Expression>>,
9232    #[serde(default)]
9233    pub never: Option<Box<Expression>>,
9234}
9235
9236/// CharacterSetProperty
9237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9238#[cfg_attr(feature = "bindings", derive(TS))]
9239pub struct CharacterSetProperty {
9240    pub this: Box<Expression>,
9241    #[serde(default)]
9242    pub default: Option<Box<Expression>>,
9243}
9244
9245/// ChecksumProperty
9246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9247#[cfg_attr(feature = "bindings", derive(TS))]
9248pub struct ChecksumProperty {
9249    #[serde(default)]
9250    pub on: Option<Box<Expression>>,
9251    #[serde(default)]
9252    pub default: Option<Box<Expression>>,
9253}
9254
9255/// CollateProperty
9256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9257#[cfg_attr(feature = "bindings", derive(TS))]
9258pub struct CollateProperty {
9259    pub this: Box<Expression>,
9260    #[serde(default)]
9261    pub default: Option<Box<Expression>>,
9262}
9263
9264/// DataBlocksizeProperty
9265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9266#[cfg_attr(feature = "bindings", derive(TS))]
9267pub struct DataBlocksizeProperty {
9268    #[serde(default)]
9269    pub size: Option<i64>,
9270    #[serde(default)]
9271    pub units: Option<Box<Expression>>,
9272    #[serde(default)]
9273    pub minimum: Option<Box<Expression>>,
9274    #[serde(default)]
9275    pub maximum: Option<Box<Expression>>,
9276    #[serde(default)]
9277    pub default: Option<Box<Expression>>,
9278}
9279
9280/// DataDeletionProperty
9281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9282#[cfg_attr(feature = "bindings", derive(TS))]
9283pub struct DataDeletionProperty {
9284    pub on: Box<Expression>,
9285    #[serde(default)]
9286    pub filter_column: Option<Box<Expression>>,
9287    #[serde(default)]
9288    pub retention_period: Option<Box<Expression>>,
9289}
9290
9291/// DefinerProperty
9292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9293#[cfg_attr(feature = "bindings", derive(TS))]
9294pub struct DefinerProperty {
9295    pub this: Box<Expression>,
9296}
9297
9298/// DistKeyProperty
9299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9300#[cfg_attr(feature = "bindings", derive(TS))]
9301pub struct DistKeyProperty {
9302    pub this: Box<Expression>,
9303}
9304
9305/// DistributedByProperty
9306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9307#[cfg_attr(feature = "bindings", derive(TS))]
9308pub struct DistributedByProperty {
9309    #[serde(default)]
9310    pub expressions: Vec<Expression>,
9311    pub kind: String,
9312    #[serde(default)]
9313    pub buckets: Option<Box<Expression>>,
9314    #[serde(default)]
9315    pub order: Option<Box<Expression>>,
9316}
9317
9318/// DistStyleProperty
9319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9320#[cfg_attr(feature = "bindings", derive(TS))]
9321pub struct DistStyleProperty {
9322    pub this: Box<Expression>,
9323}
9324
9325/// DuplicateKeyProperty
9326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9327#[cfg_attr(feature = "bindings", derive(TS))]
9328pub struct DuplicateKeyProperty {
9329    #[serde(default)]
9330    pub expressions: Vec<Expression>,
9331}
9332
9333/// EngineProperty
9334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9335#[cfg_attr(feature = "bindings", derive(TS))]
9336pub struct EngineProperty {
9337    pub this: Box<Expression>,
9338}
9339
9340/// ToTableProperty
9341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9342#[cfg_attr(feature = "bindings", derive(TS))]
9343pub struct ToTableProperty {
9344    pub this: Box<Expression>,
9345}
9346
9347/// ExecuteAsProperty
9348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9349#[cfg_attr(feature = "bindings", derive(TS))]
9350pub struct ExecuteAsProperty {
9351    pub this: Box<Expression>,
9352}
9353
9354/// ExternalProperty
9355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9356#[cfg_attr(feature = "bindings", derive(TS))]
9357pub struct ExternalProperty {
9358    #[serde(default)]
9359    pub this: Option<Box<Expression>>,
9360}
9361
9362/// FallbackProperty
9363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9364#[cfg_attr(feature = "bindings", derive(TS))]
9365pub struct FallbackProperty {
9366    #[serde(default)]
9367    pub no: Option<Box<Expression>>,
9368    #[serde(default)]
9369    pub protection: Option<Box<Expression>>,
9370}
9371
9372/// FileFormatProperty
9373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9374#[cfg_attr(feature = "bindings", derive(TS))]
9375pub struct FileFormatProperty {
9376    #[serde(default)]
9377    pub this: Option<Box<Expression>>,
9378    #[serde(default)]
9379    pub expressions: Vec<Expression>,
9380    #[serde(default)]
9381    pub hive_format: Option<Box<Expression>>,
9382}
9383
9384/// CredentialsProperty
9385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9386#[cfg_attr(feature = "bindings", derive(TS))]
9387pub struct CredentialsProperty {
9388    #[serde(default)]
9389    pub expressions: Vec<Expression>,
9390}
9391
9392/// FreespaceProperty
9393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9394#[cfg_attr(feature = "bindings", derive(TS))]
9395pub struct FreespaceProperty {
9396    pub this: Box<Expression>,
9397    #[serde(default)]
9398    pub percent: Option<Box<Expression>>,
9399}
9400
9401/// InheritsProperty
9402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9403#[cfg_attr(feature = "bindings", derive(TS))]
9404pub struct InheritsProperty {
9405    #[serde(default)]
9406    pub expressions: Vec<Expression>,
9407}
9408
9409/// InputModelProperty
9410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9411#[cfg_attr(feature = "bindings", derive(TS))]
9412pub struct InputModelProperty {
9413    pub this: Box<Expression>,
9414}
9415
9416/// OutputModelProperty
9417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9418#[cfg_attr(feature = "bindings", derive(TS))]
9419pub struct OutputModelProperty {
9420    pub this: Box<Expression>,
9421}
9422
9423/// IsolatedLoadingProperty
9424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9425#[cfg_attr(feature = "bindings", derive(TS))]
9426pub struct IsolatedLoadingProperty {
9427    #[serde(default)]
9428    pub no: Option<Box<Expression>>,
9429    #[serde(default)]
9430    pub concurrent: Option<Box<Expression>>,
9431    #[serde(default)]
9432    pub target: Option<Box<Expression>>,
9433}
9434
9435/// JournalProperty
9436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9437#[cfg_attr(feature = "bindings", derive(TS))]
9438pub struct JournalProperty {
9439    #[serde(default)]
9440    pub no: Option<Box<Expression>>,
9441    #[serde(default)]
9442    pub dual: Option<Box<Expression>>,
9443    #[serde(default)]
9444    pub before: Option<Box<Expression>>,
9445    #[serde(default)]
9446    pub local: Option<Box<Expression>>,
9447    #[serde(default)]
9448    pub after: Option<Box<Expression>>,
9449}
9450
9451/// LanguageProperty
9452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9453#[cfg_attr(feature = "bindings", derive(TS))]
9454pub struct LanguageProperty {
9455    pub this: Box<Expression>,
9456}
9457
9458/// EnviromentProperty
9459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9460#[cfg_attr(feature = "bindings", derive(TS))]
9461pub struct EnviromentProperty {
9462    #[serde(default)]
9463    pub expressions: Vec<Expression>,
9464}
9465
9466/// ClusteredByProperty
9467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9468#[cfg_attr(feature = "bindings", derive(TS))]
9469pub struct ClusteredByProperty {
9470    #[serde(default)]
9471    pub expressions: Vec<Expression>,
9472    #[serde(default)]
9473    pub sorted_by: Option<Box<Expression>>,
9474    #[serde(default)]
9475    pub buckets: Option<Box<Expression>>,
9476}
9477
9478/// DictProperty
9479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9480#[cfg_attr(feature = "bindings", derive(TS))]
9481pub struct DictProperty {
9482    pub this: Box<Expression>,
9483    pub kind: String,
9484    #[serde(default)]
9485    pub settings: Option<Box<Expression>>,
9486}
9487
9488/// DictRange
9489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9490#[cfg_attr(feature = "bindings", derive(TS))]
9491pub struct DictRange {
9492    pub this: Box<Expression>,
9493    #[serde(default)]
9494    pub min: Option<Box<Expression>>,
9495    #[serde(default)]
9496    pub max: Option<Box<Expression>>,
9497}
9498
9499/// OnCluster
9500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9501#[cfg_attr(feature = "bindings", derive(TS))]
9502pub struct OnCluster {
9503    pub this: Box<Expression>,
9504}
9505
9506/// LikeProperty
9507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9508#[cfg_attr(feature = "bindings", derive(TS))]
9509pub struct LikeProperty {
9510    pub this: Box<Expression>,
9511    #[serde(default)]
9512    pub expressions: Vec<Expression>,
9513}
9514
9515/// LocationProperty
9516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9517#[cfg_attr(feature = "bindings", derive(TS))]
9518pub struct LocationProperty {
9519    pub this: Box<Expression>,
9520}
9521
9522/// LockProperty
9523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9524#[cfg_attr(feature = "bindings", derive(TS))]
9525pub struct LockProperty {
9526    pub this: Box<Expression>,
9527}
9528
9529/// LockingProperty
9530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9531#[cfg_attr(feature = "bindings", derive(TS))]
9532pub struct LockingProperty {
9533    #[serde(default)]
9534    pub this: Option<Box<Expression>>,
9535    pub kind: String,
9536    #[serde(default)]
9537    pub for_or_in: Option<Box<Expression>>,
9538    #[serde(default)]
9539    pub lock_type: Option<Box<Expression>>,
9540    #[serde(default)]
9541    pub override_: Option<Box<Expression>>,
9542}
9543
9544/// LogProperty
9545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub struct LogProperty {
9548    #[serde(default)]
9549    pub no: Option<Box<Expression>>,
9550}
9551
9552/// MaterializedProperty
9553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9554#[cfg_attr(feature = "bindings", derive(TS))]
9555pub struct MaterializedProperty {
9556    #[serde(default)]
9557    pub this: Option<Box<Expression>>,
9558}
9559
9560/// MergeBlockRatioProperty
9561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9562#[cfg_attr(feature = "bindings", derive(TS))]
9563pub struct MergeBlockRatioProperty {
9564    #[serde(default)]
9565    pub this: Option<Box<Expression>>,
9566    #[serde(default)]
9567    pub no: Option<Box<Expression>>,
9568    #[serde(default)]
9569    pub default: Option<Box<Expression>>,
9570    #[serde(default)]
9571    pub percent: Option<Box<Expression>>,
9572}
9573
9574/// OnProperty
9575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9576#[cfg_attr(feature = "bindings", derive(TS))]
9577pub struct OnProperty {
9578    pub this: Box<Expression>,
9579}
9580
9581/// OnCommitProperty
9582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9583#[cfg_attr(feature = "bindings", derive(TS))]
9584pub struct OnCommitProperty {
9585    #[serde(default)]
9586    pub delete: Option<Box<Expression>>,
9587}
9588
9589/// PartitionedByProperty
9590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9591#[cfg_attr(feature = "bindings", derive(TS))]
9592pub struct PartitionedByProperty {
9593    pub this: Box<Expression>,
9594}
9595
9596/// BigQuery PARTITION BY property in CREATE TABLE statements.
9597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9598#[cfg_attr(feature = "bindings", derive(TS))]
9599pub struct PartitionByProperty {
9600    #[serde(default)]
9601    pub expressions: Vec<Expression>,
9602}
9603
9604/// PartitionedByBucket
9605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9606#[cfg_attr(feature = "bindings", derive(TS))]
9607pub struct PartitionedByBucket {
9608    pub this: Box<Expression>,
9609    pub expression: Box<Expression>,
9610}
9611
9612/// BigQuery CLUSTER BY property in CREATE TABLE statements.
9613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9614#[cfg_attr(feature = "bindings", derive(TS))]
9615pub struct ClusterByColumnsProperty {
9616    #[serde(default)]
9617    pub columns: Vec<Identifier>,
9618}
9619
9620/// PartitionByTruncate
9621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9622#[cfg_attr(feature = "bindings", derive(TS))]
9623pub struct PartitionByTruncate {
9624    pub this: Box<Expression>,
9625    pub expression: Box<Expression>,
9626}
9627
9628/// PartitionByRangeProperty
9629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9630#[cfg_attr(feature = "bindings", derive(TS))]
9631pub struct PartitionByRangeProperty {
9632    #[serde(default)]
9633    pub partition_expressions: Option<Box<Expression>>,
9634    #[serde(default)]
9635    pub create_expressions: Option<Box<Expression>>,
9636}
9637
9638/// PartitionByRangePropertyDynamic
9639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9640#[cfg_attr(feature = "bindings", derive(TS))]
9641pub struct PartitionByRangePropertyDynamic {
9642    #[serde(default)]
9643    pub this: Option<Box<Expression>>,
9644    #[serde(default)]
9645    pub start: Option<Box<Expression>>,
9646    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9647    #[serde(default)]
9648    pub use_start_end: bool,
9649    #[serde(default)]
9650    pub end: Option<Box<Expression>>,
9651    #[serde(default)]
9652    pub every: Option<Box<Expression>>,
9653}
9654
9655/// PartitionByListProperty
9656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9657#[cfg_attr(feature = "bindings", derive(TS))]
9658pub struct PartitionByListProperty {
9659    #[serde(default)]
9660    pub partition_expressions: Option<Box<Expression>>,
9661    #[serde(default)]
9662    pub create_expressions: Option<Box<Expression>>,
9663}
9664
9665/// PartitionList
9666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9667#[cfg_attr(feature = "bindings", derive(TS))]
9668pub struct PartitionList {
9669    pub this: Box<Expression>,
9670    #[serde(default)]
9671    pub expressions: Vec<Expression>,
9672}
9673
9674/// Partition - represents PARTITION/SUBPARTITION clause
9675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9676#[cfg_attr(feature = "bindings", derive(TS))]
9677pub struct Partition {
9678    pub expressions: Vec<Expression>,
9679    #[serde(default)]
9680    pub subpartition: bool,
9681}
9682
9683/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9684/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9686#[cfg_attr(feature = "bindings", derive(TS))]
9687pub struct RefreshTriggerProperty {
9688    /// Method: COMPLETE or AUTO
9689    pub method: String,
9690    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9691    #[serde(default)]
9692    pub kind: Option<String>,
9693    /// For SCHEDULE: EVERY n (the number)
9694    #[serde(default)]
9695    pub every: Option<Box<Expression>>,
9696    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9697    #[serde(default)]
9698    pub unit: Option<String>,
9699    /// For SCHEDULE: STARTS 'datetime'
9700    #[serde(default)]
9701    pub starts: Option<Box<Expression>>,
9702}
9703
9704/// UniqueKeyProperty
9705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9706#[cfg_attr(feature = "bindings", derive(TS))]
9707pub struct UniqueKeyProperty {
9708    #[serde(default)]
9709    pub expressions: Vec<Expression>,
9710}
9711
9712/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9714#[cfg_attr(feature = "bindings", derive(TS))]
9715pub struct RollupProperty {
9716    pub expressions: Vec<RollupIndex>,
9717}
9718
9719/// RollupIndex - A single rollup index: name(col1, col2)
9720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9721#[cfg_attr(feature = "bindings", derive(TS))]
9722pub struct RollupIndex {
9723    pub name: Identifier,
9724    pub expressions: Vec<Identifier>,
9725}
9726
9727/// PartitionBoundSpec
9728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9729#[cfg_attr(feature = "bindings", derive(TS))]
9730pub struct PartitionBoundSpec {
9731    #[serde(default)]
9732    pub this: Option<Box<Expression>>,
9733    #[serde(default)]
9734    pub expression: Option<Box<Expression>>,
9735    #[serde(default)]
9736    pub from_expressions: Option<Box<Expression>>,
9737    #[serde(default)]
9738    pub to_expressions: Option<Box<Expression>>,
9739}
9740
9741/// PartitionedOfProperty
9742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9743#[cfg_attr(feature = "bindings", derive(TS))]
9744pub struct PartitionedOfProperty {
9745    pub this: Box<Expression>,
9746    pub expression: Box<Expression>,
9747}
9748
9749/// RemoteWithConnectionModelProperty
9750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9751#[cfg_attr(feature = "bindings", derive(TS))]
9752pub struct RemoteWithConnectionModelProperty {
9753    pub this: Box<Expression>,
9754}
9755
9756/// ReturnsProperty
9757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9758#[cfg_attr(feature = "bindings", derive(TS))]
9759pub struct ReturnsProperty {
9760    #[serde(default)]
9761    pub this: Option<Box<Expression>>,
9762    #[serde(default)]
9763    pub is_table: Option<Box<Expression>>,
9764    #[serde(default)]
9765    pub table: Option<Box<Expression>>,
9766    #[serde(default)]
9767    pub null: Option<Box<Expression>>,
9768}
9769
9770/// RowFormatProperty
9771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9772#[cfg_attr(feature = "bindings", derive(TS))]
9773pub struct RowFormatProperty {
9774    pub this: Box<Expression>,
9775}
9776
9777/// RowFormatDelimitedProperty
9778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9779#[cfg_attr(feature = "bindings", derive(TS))]
9780pub struct RowFormatDelimitedProperty {
9781    #[serde(default)]
9782    pub fields: Option<Box<Expression>>,
9783    #[serde(default)]
9784    pub escaped: Option<Box<Expression>>,
9785    #[serde(default)]
9786    pub collection_items: Option<Box<Expression>>,
9787    #[serde(default)]
9788    pub map_keys: Option<Box<Expression>>,
9789    #[serde(default)]
9790    pub lines: Option<Box<Expression>>,
9791    #[serde(default)]
9792    pub null: Option<Box<Expression>>,
9793    #[serde(default)]
9794    pub serde: Option<Box<Expression>>,
9795}
9796
9797/// RowFormatSerdeProperty
9798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9799#[cfg_attr(feature = "bindings", derive(TS))]
9800pub struct RowFormatSerdeProperty {
9801    pub this: Box<Expression>,
9802    #[serde(default)]
9803    pub serde_properties: Option<Box<Expression>>,
9804}
9805
9806/// QueryTransform
9807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9808#[cfg_attr(feature = "bindings", derive(TS))]
9809pub struct QueryTransform {
9810    #[serde(default)]
9811    pub expressions: Vec<Expression>,
9812    #[serde(default)]
9813    pub command_script: Option<Box<Expression>>,
9814    #[serde(default)]
9815    pub schema: Option<Box<Expression>>,
9816    #[serde(default)]
9817    pub row_format_before: Option<Box<Expression>>,
9818    #[serde(default)]
9819    pub record_writer: Option<Box<Expression>>,
9820    #[serde(default)]
9821    pub row_format_after: Option<Box<Expression>>,
9822    #[serde(default)]
9823    pub record_reader: Option<Box<Expression>>,
9824}
9825
9826/// SampleProperty
9827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9828#[cfg_attr(feature = "bindings", derive(TS))]
9829pub struct SampleProperty {
9830    pub this: Box<Expression>,
9831}
9832
9833/// SecurityProperty
9834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9835#[cfg_attr(feature = "bindings", derive(TS))]
9836pub struct SecurityProperty {
9837    pub this: Box<Expression>,
9838}
9839
9840/// SchemaCommentProperty
9841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9842#[cfg_attr(feature = "bindings", derive(TS))]
9843pub struct SchemaCommentProperty {
9844    pub this: Box<Expression>,
9845}
9846
9847/// SemanticView
9848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9849#[cfg_attr(feature = "bindings", derive(TS))]
9850pub struct SemanticView {
9851    pub this: Box<Expression>,
9852    #[serde(default)]
9853    pub metrics: Option<Box<Expression>>,
9854    #[serde(default)]
9855    pub dimensions: Option<Box<Expression>>,
9856    #[serde(default)]
9857    pub facts: Option<Box<Expression>>,
9858    #[serde(default)]
9859    pub where_: Option<Box<Expression>>,
9860}
9861
9862/// SerdeProperties
9863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9864#[cfg_attr(feature = "bindings", derive(TS))]
9865pub struct SerdeProperties {
9866    #[serde(default)]
9867    pub expressions: Vec<Expression>,
9868    #[serde(default)]
9869    pub with_: Option<Box<Expression>>,
9870}
9871
9872/// SetProperty
9873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9874#[cfg_attr(feature = "bindings", derive(TS))]
9875pub struct SetProperty {
9876    #[serde(default)]
9877    pub multi: Option<Box<Expression>>,
9878}
9879
9880/// SharingProperty
9881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9882#[cfg_attr(feature = "bindings", derive(TS))]
9883pub struct SharingProperty {
9884    #[serde(default)]
9885    pub this: Option<Box<Expression>>,
9886}
9887
9888/// SetConfigProperty
9889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9890#[cfg_attr(feature = "bindings", derive(TS))]
9891pub struct SetConfigProperty {
9892    pub this: Box<Expression>,
9893}
9894
9895/// SettingsProperty
9896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9897#[cfg_attr(feature = "bindings", derive(TS))]
9898pub struct SettingsProperty {
9899    #[serde(default)]
9900    pub expressions: Vec<Expression>,
9901}
9902
9903/// SortKeyProperty
9904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9905#[cfg_attr(feature = "bindings", derive(TS))]
9906pub struct SortKeyProperty {
9907    pub this: Box<Expression>,
9908    #[serde(default)]
9909    pub compound: Option<Box<Expression>>,
9910}
9911
9912/// SqlReadWriteProperty
9913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9914#[cfg_attr(feature = "bindings", derive(TS))]
9915pub struct SqlReadWriteProperty {
9916    pub this: Box<Expression>,
9917}
9918
9919/// SqlSecurityProperty
9920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9921#[cfg_attr(feature = "bindings", derive(TS))]
9922pub struct SqlSecurityProperty {
9923    pub this: Box<Expression>,
9924}
9925
9926/// StabilityProperty
9927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9928#[cfg_attr(feature = "bindings", derive(TS))]
9929pub struct StabilityProperty {
9930    pub this: Box<Expression>,
9931}
9932
9933/// StorageHandlerProperty
9934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9935#[cfg_attr(feature = "bindings", derive(TS))]
9936pub struct StorageHandlerProperty {
9937    pub this: Box<Expression>,
9938}
9939
9940/// TemporaryProperty
9941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9942#[cfg_attr(feature = "bindings", derive(TS))]
9943pub struct TemporaryProperty {
9944    #[serde(default)]
9945    pub this: Option<Box<Expression>>,
9946}
9947
9948/// Tags
9949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9950#[cfg_attr(feature = "bindings", derive(TS))]
9951pub struct Tags {
9952    #[serde(default)]
9953    pub expressions: Vec<Expression>,
9954}
9955
9956/// TransformModelProperty
9957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9958#[cfg_attr(feature = "bindings", derive(TS))]
9959pub struct TransformModelProperty {
9960    #[serde(default)]
9961    pub expressions: Vec<Expression>,
9962}
9963
9964/// TransientProperty
9965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9966#[cfg_attr(feature = "bindings", derive(TS))]
9967pub struct TransientProperty {
9968    #[serde(default)]
9969    pub this: Option<Box<Expression>>,
9970}
9971
9972/// UsingTemplateProperty
9973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9974#[cfg_attr(feature = "bindings", derive(TS))]
9975pub struct UsingTemplateProperty {
9976    pub this: Box<Expression>,
9977}
9978
9979/// ViewAttributeProperty
9980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9981#[cfg_attr(feature = "bindings", derive(TS))]
9982pub struct ViewAttributeProperty {
9983    pub this: Box<Expression>,
9984}
9985
9986/// VolatileProperty
9987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9988#[cfg_attr(feature = "bindings", derive(TS))]
9989pub struct VolatileProperty {
9990    #[serde(default)]
9991    pub this: Option<Box<Expression>>,
9992}
9993
9994/// WithDataProperty
9995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9996#[cfg_attr(feature = "bindings", derive(TS))]
9997pub struct WithDataProperty {
9998    #[serde(default)]
9999    pub no: Option<Box<Expression>>,
10000    #[serde(default)]
10001    pub statistics: Option<Box<Expression>>,
10002}
10003
10004/// WithJournalTableProperty
10005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10006#[cfg_attr(feature = "bindings", derive(TS))]
10007pub struct WithJournalTableProperty {
10008    pub this: Box<Expression>,
10009}
10010
10011/// WithSchemaBindingProperty
10012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10013#[cfg_attr(feature = "bindings", derive(TS))]
10014pub struct WithSchemaBindingProperty {
10015    pub this: Box<Expression>,
10016}
10017
10018/// WithSystemVersioningProperty
10019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10020#[cfg_attr(feature = "bindings", derive(TS))]
10021pub struct WithSystemVersioningProperty {
10022    #[serde(default)]
10023    pub on: Option<Box<Expression>>,
10024    #[serde(default)]
10025    pub this: Option<Box<Expression>>,
10026    #[serde(default)]
10027    pub data_consistency: Option<Box<Expression>>,
10028    #[serde(default)]
10029    pub retention_period: Option<Box<Expression>>,
10030    #[serde(default)]
10031    pub with_: Option<Box<Expression>>,
10032}
10033
10034/// WithProcedureOptions
10035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10036#[cfg_attr(feature = "bindings", derive(TS))]
10037pub struct WithProcedureOptions {
10038    #[serde(default)]
10039    pub expressions: Vec<Expression>,
10040}
10041
10042/// EncodeProperty
10043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10044#[cfg_attr(feature = "bindings", derive(TS))]
10045pub struct EncodeProperty {
10046    pub this: Box<Expression>,
10047    #[serde(default)]
10048    pub properties: Vec<Expression>,
10049    #[serde(default)]
10050    pub key: Option<Box<Expression>>,
10051}
10052
10053/// IncludeProperty
10054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10055#[cfg_attr(feature = "bindings", derive(TS))]
10056pub struct IncludeProperty {
10057    pub this: Box<Expression>,
10058    #[serde(default)]
10059    pub alias: Option<String>,
10060    #[serde(default)]
10061    pub column_def: Option<Box<Expression>>,
10062}
10063
10064/// Properties
10065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10066#[cfg_attr(feature = "bindings", derive(TS))]
10067pub struct Properties {
10068    #[serde(default)]
10069    pub expressions: Vec<Expression>,
10070}
10071
10072/// Key/value pair in a BigQuery OPTIONS (...) clause.
10073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10074#[cfg_attr(feature = "bindings", derive(TS))]
10075pub struct OptionEntry {
10076    pub key: Identifier,
10077    pub value: Expression,
10078}
10079
10080/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
10081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10082#[cfg_attr(feature = "bindings", derive(TS))]
10083pub struct OptionsProperty {
10084    #[serde(default)]
10085    pub entries: Vec<OptionEntry>,
10086}
10087
10088/// InputOutputFormat
10089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10090#[cfg_attr(feature = "bindings", derive(TS))]
10091pub struct InputOutputFormat {
10092    #[serde(default)]
10093    pub input_format: Option<Box<Expression>>,
10094    #[serde(default)]
10095    pub output_format: Option<Box<Expression>>,
10096}
10097
10098/// Reference
10099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10100#[cfg_attr(feature = "bindings", derive(TS))]
10101pub struct Reference {
10102    pub this: Box<Expression>,
10103    #[serde(default)]
10104    pub expressions: Vec<Expression>,
10105    #[serde(default)]
10106    pub options: Vec<Expression>,
10107}
10108
10109/// QueryOption
10110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10111#[cfg_attr(feature = "bindings", derive(TS))]
10112pub struct QueryOption {
10113    pub this: Box<Expression>,
10114    #[serde(default)]
10115    pub expression: Option<Box<Expression>>,
10116}
10117
10118/// WithTableHint
10119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10120#[cfg_attr(feature = "bindings", derive(TS))]
10121pub struct WithTableHint {
10122    #[serde(default)]
10123    pub expressions: Vec<Expression>,
10124}
10125
10126/// IndexTableHint
10127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10128#[cfg_attr(feature = "bindings", derive(TS))]
10129pub struct IndexTableHint {
10130    pub this: Box<Expression>,
10131    #[serde(default)]
10132    pub expressions: Vec<Expression>,
10133    #[serde(default)]
10134    pub target: Option<Box<Expression>>,
10135}
10136
10137/// Get
10138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10139#[cfg_attr(feature = "bindings", derive(TS))]
10140pub struct Get {
10141    pub this: Box<Expression>,
10142    #[serde(default)]
10143    pub target: Option<Box<Expression>>,
10144    #[serde(default)]
10145    pub properties: Vec<Expression>,
10146}
10147
10148/// SetOperation
10149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10150#[cfg_attr(feature = "bindings", derive(TS))]
10151pub struct SetOperation {
10152    #[serde(default)]
10153    pub with_: Option<Box<Expression>>,
10154    pub this: Box<Expression>,
10155    pub expression: Box<Expression>,
10156    #[serde(default)]
10157    pub distinct: bool,
10158    #[serde(default)]
10159    pub by_name: Option<Box<Expression>>,
10160    #[serde(default)]
10161    pub side: Option<Box<Expression>>,
10162    #[serde(default)]
10163    pub kind: Option<String>,
10164    #[serde(default)]
10165    pub on: Option<Box<Expression>>,
10166}
10167
10168/// Var - Simple variable reference (for SQL variables, keywords as values)
10169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10170#[cfg_attr(feature = "bindings", derive(TS))]
10171pub struct Var {
10172    pub this: String,
10173}
10174
10175/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
10176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10177#[cfg_attr(feature = "bindings", derive(TS))]
10178pub struct Variadic {
10179    pub this: Box<Expression>,
10180}
10181
10182/// Version
10183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10184#[cfg_attr(feature = "bindings", derive(TS))]
10185pub struct Version {
10186    pub this: Box<Expression>,
10187    pub kind: String,
10188    #[serde(default)]
10189    pub expression: Option<Box<Expression>>,
10190}
10191
10192/// Schema
10193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10194#[cfg_attr(feature = "bindings", derive(TS))]
10195pub struct Schema {
10196    #[serde(default)]
10197    pub this: Option<Box<Expression>>,
10198    #[serde(default)]
10199    pub expressions: Vec<Expression>,
10200}
10201
10202/// Lock
10203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10204#[cfg_attr(feature = "bindings", derive(TS))]
10205pub struct Lock {
10206    #[serde(default)]
10207    pub update: Option<Box<Expression>>,
10208    #[serde(default)]
10209    pub expressions: Vec<Expression>,
10210    #[serde(default)]
10211    pub wait: Option<Box<Expression>>,
10212    #[serde(default)]
10213    pub key: Option<Box<Expression>>,
10214}
10215
10216/// TableSample - wraps an expression with a TABLESAMPLE clause
10217/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
10218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10219#[cfg_attr(feature = "bindings", derive(TS))]
10220pub struct TableSample {
10221    /// The expression being sampled (subquery, function, etc.)
10222    #[serde(default, skip_serializing_if = "Option::is_none")]
10223    pub this: Option<Box<Expression>>,
10224    /// The sample specification
10225    #[serde(default, skip_serializing_if = "Option::is_none")]
10226    pub sample: Option<Box<Sample>>,
10227    #[serde(default)]
10228    pub expressions: Vec<Expression>,
10229    #[serde(default)]
10230    pub method: Option<String>,
10231    #[serde(default)]
10232    pub bucket_numerator: Option<Box<Expression>>,
10233    #[serde(default)]
10234    pub bucket_denominator: Option<Box<Expression>>,
10235    #[serde(default)]
10236    pub bucket_field: Option<Box<Expression>>,
10237    #[serde(default)]
10238    pub percent: Option<Box<Expression>>,
10239    #[serde(default)]
10240    pub rows: Option<Box<Expression>>,
10241    #[serde(default)]
10242    pub size: Option<i64>,
10243    #[serde(default)]
10244    pub seed: Option<Box<Expression>>,
10245}
10246
10247/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
10248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10249#[cfg_attr(feature = "bindings", derive(TS))]
10250pub struct Tag {
10251    #[serde(default)]
10252    pub this: Option<Box<Expression>>,
10253    #[serde(default)]
10254    pub prefix: Option<Box<Expression>>,
10255    #[serde(default)]
10256    pub postfix: Option<Box<Expression>>,
10257}
10258
10259/// UnpivotColumns
10260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10261#[cfg_attr(feature = "bindings", derive(TS))]
10262pub struct UnpivotColumns {
10263    pub this: Box<Expression>,
10264    #[serde(default)]
10265    pub expressions: Vec<Expression>,
10266}
10267
10268/// SessionParameter
10269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10270#[cfg_attr(feature = "bindings", derive(TS))]
10271pub struct SessionParameter {
10272    pub this: Box<Expression>,
10273    #[serde(default)]
10274    pub kind: Option<String>,
10275}
10276
10277/// PseudoType
10278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10279#[cfg_attr(feature = "bindings", derive(TS))]
10280pub struct PseudoType {
10281    pub this: Box<Expression>,
10282}
10283
10284/// ObjectIdentifier
10285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10286#[cfg_attr(feature = "bindings", derive(TS))]
10287pub struct ObjectIdentifier {
10288    pub this: Box<Expression>,
10289}
10290
10291/// Transaction
10292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10293#[cfg_attr(feature = "bindings", derive(TS))]
10294pub struct Transaction {
10295    #[serde(default)]
10296    pub this: Option<Box<Expression>>,
10297    #[serde(default)]
10298    pub modes: Option<Box<Expression>>,
10299    #[serde(default)]
10300    pub mark: Option<Box<Expression>>,
10301}
10302
10303/// Commit
10304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10305#[cfg_attr(feature = "bindings", derive(TS))]
10306pub struct Commit {
10307    #[serde(default)]
10308    pub chain: Option<Box<Expression>>,
10309    #[serde(default)]
10310    pub this: Option<Box<Expression>>,
10311    #[serde(default)]
10312    pub durability: Option<Box<Expression>>,
10313}
10314
10315/// Rollback
10316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10317#[cfg_attr(feature = "bindings", derive(TS))]
10318pub struct Rollback {
10319    #[serde(default)]
10320    pub savepoint: Option<Box<Expression>>,
10321    #[serde(default)]
10322    pub this: Option<Box<Expression>>,
10323}
10324
10325/// AlterSession
10326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10327#[cfg_attr(feature = "bindings", derive(TS))]
10328pub struct AlterSession {
10329    #[serde(default)]
10330    pub expressions: Vec<Expression>,
10331    #[serde(default)]
10332    pub unset: Option<Box<Expression>>,
10333}
10334
10335/// Analyze
10336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10337#[cfg_attr(feature = "bindings", derive(TS))]
10338pub struct Analyze {
10339    #[serde(default)]
10340    pub kind: Option<String>,
10341    #[serde(default)]
10342    pub this: Option<Box<Expression>>,
10343    #[serde(default)]
10344    pub options: Vec<Expression>,
10345    #[serde(default)]
10346    pub mode: Option<Box<Expression>>,
10347    #[serde(default)]
10348    pub partition: Option<Box<Expression>>,
10349    #[serde(default)]
10350    pub expression: Option<Box<Expression>>,
10351    #[serde(default)]
10352    pub properties: Vec<Expression>,
10353    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
10354    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10355    pub columns: Vec<String>,
10356}
10357
10358/// AnalyzeStatistics
10359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10360#[cfg_attr(feature = "bindings", derive(TS))]
10361pub struct AnalyzeStatistics {
10362    pub kind: String,
10363    #[serde(default)]
10364    pub option: Option<Box<Expression>>,
10365    #[serde(default)]
10366    pub this: Option<Box<Expression>>,
10367    #[serde(default)]
10368    pub expressions: Vec<Expression>,
10369}
10370
10371/// AnalyzeHistogram
10372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10373#[cfg_attr(feature = "bindings", derive(TS))]
10374pub struct AnalyzeHistogram {
10375    pub this: Box<Expression>,
10376    #[serde(default)]
10377    pub expressions: Vec<Expression>,
10378    #[serde(default)]
10379    pub expression: Option<Box<Expression>>,
10380    #[serde(default)]
10381    pub update_options: Option<Box<Expression>>,
10382}
10383
10384/// AnalyzeSample
10385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10386#[cfg_attr(feature = "bindings", derive(TS))]
10387pub struct AnalyzeSample {
10388    pub kind: String,
10389    #[serde(default)]
10390    pub sample: Option<Box<Expression>>,
10391}
10392
10393/// AnalyzeListChainedRows
10394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10395#[cfg_attr(feature = "bindings", derive(TS))]
10396pub struct AnalyzeListChainedRows {
10397    #[serde(default)]
10398    pub expression: Option<Box<Expression>>,
10399}
10400
10401/// AnalyzeDelete
10402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10403#[cfg_attr(feature = "bindings", derive(TS))]
10404pub struct AnalyzeDelete {
10405    #[serde(default)]
10406    pub kind: Option<String>,
10407}
10408
10409/// AnalyzeWith
10410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10411#[cfg_attr(feature = "bindings", derive(TS))]
10412pub struct AnalyzeWith {
10413    #[serde(default)]
10414    pub expressions: Vec<Expression>,
10415}
10416
10417/// AnalyzeValidate
10418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10419#[cfg_attr(feature = "bindings", derive(TS))]
10420pub struct AnalyzeValidate {
10421    pub kind: String,
10422    #[serde(default)]
10423    pub this: Option<Box<Expression>>,
10424    #[serde(default)]
10425    pub expression: Option<Box<Expression>>,
10426}
10427
10428/// AddPartition
10429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10430#[cfg_attr(feature = "bindings", derive(TS))]
10431pub struct AddPartition {
10432    pub this: Box<Expression>,
10433    #[serde(default)]
10434    pub exists: bool,
10435    #[serde(default)]
10436    pub location: Option<Box<Expression>>,
10437}
10438
10439/// AttachOption
10440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10441#[cfg_attr(feature = "bindings", derive(TS))]
10442pub struct AttachOption {
10443    pub this: Box<Expression>,
10444    #[serde(default)]
10445    pub expression: Option<Box<Expression>>,
10446}
10447
10448/// DropPartition
10449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10450#[cfg_attr(feature = "bindings", derive(TS))]
10451pub struct DropPartition {
10452    #[serde(default)]
10453    pub expressions: Vec<Expression>,
10454    #[serde(default)]
10455    pub exists: bool,
10456}
10457
10458/// ReplacePartition
10459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10460#[cfg_attr(feature = "bindings", derive(TS))]
10461pub struct ReplacePartition {
10462    pub expression: Box<Expression>,
10463    #[serde(default)]
10464    pub source: Option<Box<Expression>>,
10465}
10466
10467/// DPipe
10468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10469#[cfg_attr(feature = "bindings", derive(TS))]
10470pub struct DPipe {
10471    pub this: Box<Expression>,
10472    pub expression: Box<Expression>,
10473    #[serde(default)]
10474    pub safe: Option<Box<Expression>>,
10475}
10476
10477/// Operator
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct Operator {
10481    pub this: Box<Expression>,
10482    #[serde(default)]
10483    pub operator: Option<Box<Expression>>,
10484    pub expression: Box<Expression>,
10485    /// Comments between OPERATOR() and the RHS expression
10486    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10487    pub comments: Vec<String>,
10488}
10489
10490/// PivotAny
10491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10492#[cfg_attr(feature = "bindings", derive(TS))]
10493pub struct PivotAny {
10494    #[serde(default)]
10495    pub this: Option<Box<Expression>>,
10496}
10497
10498/// Aliases
10499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10500#[cfg_attr(feature = "bindings", derive(TS))]
10501pub struct Aliases {
10502    pub this: Box<Expression>,
10503    #[serde(default)]
10504    pub expressions: Vec<Expression>,
10505}
10506
10507/// AtIndex
10508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10509#[cfg_attr(feature = "bindings", derive(TS))]
10510pub struct AtIndex {
10511    pub this: Box<Expression>,
10512    pub expression: Box<Expression>,
10513}
10514
10515/// FromTimeZone
10516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10517#[cfg_attr(feature = "bindings", derive(TS))]
10518pub struct FromTimeZone {
10519    pub this: Box<Expression>,
10520    #[serde(default)]
10521    pub zone: Option<Box<Expression>>,
10522}
10523
10524/// Format override for a column in Teradata
10525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10526#[cfg_attr(feature = "bindings", derive(TS))]
10527pub struct FormatPhrase {
10528    pub this: Box<Expression>,
10529    pub format: String,
10530}
10531
10532/// ForIn
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct ForIn {
10536    pub this: Box<Expression>,
10537    pub expression: Box<Expression>,
10538}
10539
10540/// Automatically converts unit arg into a var.
10541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10542#[cfg_attr(feature = "bindings", derive(TS))]
10543pub struct TimeUnit {
10544    #[serde(default)]
10545    pub unit: Option<String>,
10546}
10547
10548/// IntervalOp
10549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10550#[cfg_attr(feature = "bindings", derive(TS))]
10551pub struct IntervalOp {
10552    #[serde(default)]
10553    pub unit: Option<String>,
10554    pub expression: Box<Expression>,
10555}
10556
10557/// HavingMax
10558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10559#[cfg_attr(feature = "bindings", derive(TS))]
10560pub struct HavingMax {
10561    pub this: Box<Expression>,
10562    pub expression: Box<Expression>,
10563    #[serde(default)]
10564    pub max: Option<Box<Expression>>,
10565}
10566
10567/// CosineDistance
10568#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10569#[cfg_attr(feature = "bindings", derive(TS))]
10570pub struct CosineDistance {
10571    pub this: Box<Expression>,
10572    pub expression: Box<Expression>,
10573}
10574
10575/// DotProduct
10576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10577#[cfg_attr(feature = "bindings", derive(TS))]
10578pub struct DotProduct {
10579    pub this: Box<Expression>,
10580    pub expression: Box<Expression>,
10581}
10582
10583/// EuclideanDistance
10584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10585#[cfg_attr(feature = "bindings", derive(TS))]
10586pub struct EuclideanDistance {
10587    pub this: Box<Expression>,
10588    pub expression: Box<Expression>,
10589}
10590
10591/// ManhattanDistance
10592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10593#[cfg_attr(feature = "bindings", derive(TS))]
10594pub struct ManhattanDistance {
10595    pub this: Box<Expression>,
10596    pub expression: Box<Expression>,
10597}
10598
10599/// JarowinklerSimilarity
10600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10601#[cfg_attr(feature = "bindings", derive(TS))]
10602pub struct JarowinklerSimilarity {
10603    pub this: Box<Expression>,
10604    pub expression: Box<Expression>,
10605}
10606
10607/// Booland
10608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10609#[cfg_attr(feature = "bindings", derive(TS))]
10610pub struct Booland {
10611    pub this: Box<Expression>,
10612    pub expression: Box<Expression>,
10613}
10614
10615/// Boolor
10616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10617#[cfg_attr(feature = "bindings", derive(TS))]
10618pub struct Boolor {
10619    pub this: Box<Expression>,
10620    pub expression: Box<Expression>,
10621}
10622
10623/// ParameterizedAgg
10624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10625#[cfg_attr(feature = "bindings", derive(TS))]
10626pub struct ParameterizedAgg {
10627    pub this: Box<Expression>,
10628    #[serde(default)]
10629    pub expressions: Vec<Expression>,
10630    #[serde(default)]
10631    pub params: Vec<Expression>,
10632}
10633
10634/// ArgMax
10635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10636#[cfg_attr(feature = "bindings", derive(TS))]
10637pub struct ArgMax {
10638    pub this: Box<Expression>,
10639    pub expression: Box<Expression>,
10640    #[serde(default)]
10641    pub count: Option<Box<Expression>>,
10642}
10643
10644/// ArgMin
10645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10646#[cfg_attr(feature = "bindings", derive(TS))]
10647pub struct ArgMin {
10648    pub this: Box<Expression>,
10649    pub expression: Box<Expression>,
10650    #[serde(default)]
10651    pub count: Option<Box<Expression>>,
10652}
10653
10654/// ApproxTopK
10655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10656#[cfg_attr(feature = "bindings", derive(TS))]
10657pub struct ApproxTopK {
10658    pub this: Box<Expression>,
10659    #[serde(default)]
10660    pub expression: Option<Box<Expression>>,
10661    #[serde(default)]
10662    pub counters: Option<Box<Expression>>,
10663}
10664
10665/// ApproxTopKAccumulate
10666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10667#[cfg_attr(feature = "bindings", derive(TS))]
10668pub struct ApproxTopKAccumulate {
10669    pub this: Box<Expression>,
10670    #[serde(default)]
10671    pub expression: Option<Box<Expression>>,
10672}
10673
10674/// ApproxTopKCombine
10675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10676#[cfg_attr(feature = "bindings", derive(TS))]
10677pub struct ApproxTopKCombine {
10678    pub this: Box<Expression>,
10679    #[serde(default)]
10680    pub expression: Option<Box<Expression>>,
10681}
10682
10683/// ApproxTopKEstimate
10684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10685#[cfg_attr(feature = "bindings", derive(TS))]
10686pub struct ApproxTopKEstimate {
10687    pub this: Box<Expression>,
10688    #[serde(default)]
10689    pub expression: Option<Box<Expression>>,
10690}
10691
10692/// ApproxTopSum
10693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10694#[cfg_attr(feature = "bindings", derive(TS))]
10695pub struct ApproxTopSum {
10696    pub this: Box<Expression>,
10697    pub expression: Box<Expression>,
10698    #[serde(default)]
10699    pub count: Option<Box<Expression>>,
10700}
10701
10702/// ApproxQuantiles
10703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10704#[cfg_attr(feature = "bindings", derive(TS))]
10705pub struct ApproxQuantiles {
10706    pub this: Box<Expression>,
10707    #[serde(default)]
10708    pub expression: Option<Box<Expression>>,
10709}
10710
10711/// Minhash
10712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10713#[cfg_attr(feature = "bindings", derive(TS))]
10714pub struct Minhash {
10715    pub this: Box<Expression>,
10716    #[serde(default)]
10717    pub expressions: Vec<Expression>,
10718}
10719
10720/// FarmFingerprint
10721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10722#[cfg_attr(feature = "bindings", derive(TS))]
10723pub struct FarmFingerprint {
10724    #[serde(default)]
10725    pub expressions: Vec<Expression>,
10726}
10727
10728/// Float64
10729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10730#[cfg_attr(feature = "bindings", derive(TS))]
10731pub struct Float64 {
10732    pub this: Box<Expression>,
10733    #[serde(default)]
10734    pub expression: Option<Box<Expression>>,
10735}
10736
10737/// Transform
10738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10739#[cfg_attr(feature = "bindings", derive(TS))]
10740pub struct Transform {
10741    pub this: Box<Expression>,
10742    pub expression: Box<Expression>,
10743}
10744
10745/// Translate
10746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10747#[cfg_attr(feature = "bindings", derive(TS))]
10748pub struct Translate {
10749    pub this: Box<Expression>,
10750    #[serde(default)]
10751    pub from_: Option<Box<Expression>>,
10752    #[serde(default)]
10753    pub to: Option<Box<Expression>>,
10754}
10755
10756/// Grouping
10757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10758#[cfg_attr(feature = "bindings", derive(TS))]
10759pub struct Grouping {
10760    #[serde(default)]
10761    pub expressions: Vec<Expression>,
10762}
10763
10764/// GroupingId
10765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10766#[cfg_attr(feature = "bindings", derive(TS))]
10767pub struct GroupingId {
10768    #[serde(default)]
10769    pub expressions: Vec<Expression>,
10770}
10771
10772/// Anonymous
10773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10774#[cfg_attr(feature = "bindings", derive(TS))]
10775pub struct Anonymous {
10776    pub this: Box<Expression>,
10777    #[serde(default)]
10778    pub expressions: Vec<Expression>,
10779}
10780
10781/// AnonymousAggFunc
10782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10783#[cfg_attr(feature = "bindings", derive(TS))]
10784pub struct AnonymousAggFunc {
10785    pub this: Box<Expression>,
10786    #[serde(default)]
10787    pub expressions: Vec<Expression>,
10788}
10789
10790/// CombinedAggFunc
10791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10792#[cfg_attr(feature = "bindings", derive(TS))]
10793pub struct CombinedAggFunc {
10794    pub this: Box<Expression>,
10795    #[serde(default)]
10796    pub expressions: Vec<Expression>,
10797}
10798
10799/// CombinedParameterizedAgg
10800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10801#[cfg_attr(feature = "bindings", derive(TS))]
10802pub struct CombinedParameterizedAgg {
10803    pub this: Box<Expression>,
10804    #[serde(default)]
10805    pub expressions: Vec<Expression>,
10806    #[serde(default)]
10807    pub params: Vec<Expression>,
10808}
10809
10810/// HashAgg
10811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10812#[cfg_attr(feature = "bindings", derive(TS))]
10813pub struct HashAgg {
10814    pub this: Box<Expression>,
10815    #[serde(default)]
10816    pub expressions: Vec<Expression>,
10817}
10818
10819/// Hll
10820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10821#[cfg_attr(feature = "bindings", derive(TS))]
10822pub struct Hll {
10823    pub this: Box<Expression>,
10824    #[serde(default)]
10825    pub expressions: Vec<Expression>,
10826}
10827
10828/// Apply
10829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10830#[cfg_attr(feature = "bindings", derive(TS))]
10831pub struct Apply {
10832    pub this: Box<Expression>,
10833    pub expression: Box<Expression>,
10834}
10835
10836/// ToBoolean
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct ToBoolean {
10840    pub this: Box<Expression>,
10841    #[serde(default)]
10842    pub safe: Option<Box<Expression>>,
10843}
10844
10845/// List
10846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10847#[cfg_attr(feature = "bindings", derive(TS))]
10848pub struct List {
10849    #[serde(default)]
10850    pub expressions: Vec<Expression>,
10851}
10852
10853/// ToMap - Materialize-style map constructor
10854/// Can hold either:
10855/// - A SELECT subquery (MAP(SELECT 'a', 1))
10856/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10858#[cfg_attr(feature = "bindings", derive(TS))]
10859pub struct ToMap {
10860    /// Either a Select subquery or a Struct containing PropertyEQ entries
10861    pub this: Box<Expression>,
10862}
10863
10864/// Pad
10865#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10866#[cfg_attr(feature = "bindings", derive(TS))]
10867pub struct Pad {
10868    pub this: Box<Expression>,
10869    pub expression: Box<Expression>,
10870    #[serde(default)]
10871    pub fill_pattern: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub is_left: Option<Box<Expression>>,
10874}
10875
10876/// ToChar
10877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10878#[cfg_attr(feature = "bindings", derive(TS))]
10879pub struct ToChar {
10880    pub this: Box<Expression>,
10881    #[serde(default)]
10882    pub format: Option<String>,
10883    #[serde(default)]
10884    pub nlsparam: Option<Box<Expression>>,
10885    #[serde(default)]
10886    pub is_numeric: Option<Box<Expression>>,
10887}
10888
10889/// StringFunc - String type conversion function (BigQuery STRING)
10890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10891#[cfg_attr(feature = "bindings", derive(TS))]
10892pub struct StringFunc {
10893    pub this: Box<Expression>,
10894    #[serde(default)]
10895    pub zone: Option<Box<Expression>>,
10896}
10897
10898/// ToNumber
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct ToNumber {
10902    pub this: Box<Expression>,
10903    #[serde(default)]
10904    pub format: Option<Box<Expression>>,
10905    #[serde(default)]
10906    pub nlsparam: Option<Box<Expression>>,
10907    #[serde(default)]
10908    pub precision: Option<Box<Expression>>,
10909    #[serde(default)]
10910    pub scale: Option<Box<Expression>>,
10911    #[serde(default)]
10912    pub safe: Option<Box<Expression>>,
10913    #[serde(default)]
10914    pub safe_name: Option<Box<Expression>>,
10915}
10916
10917/// ToDouble
10918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10919#[cfg_attr(feature = "bindings", derive(TS))]
10920pub struct ToDouble {
10921    pub this: Box<Expression>,
10922    #[serde(default)]
10923    pub format: Option<String>,
10924    #[serde(default)]
10925    pub safe: Option<Box<Expression>>,
10926}
10927
10928/// ToDecfloat
10929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10930#[cfg_attr(feature = "bindings", derive(TS))]
10931pub struct ToDecfloat {
10932    pub this: Box<Expression>,
10933    #[serde(default)]
10934    pub format: Option<String>,
10935}
10936
10937/// TryToDecfloat
10938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10939#[cfg_attr(feature = "bindings", derive(TS))]
10940pub struct TryToDecfloat {
10941    pub this: Box<Expression>,
10942    #[serde(default)]
10943    pub format: Option<String>,
10944}
10945
10946/// ToFile
10947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10948#[cfg_attr(feature = "bindings", derive(TS))]
10949pub struct ToFile {
10950    pub this: Box<Expression>,
10951    #[serde(default)]
10952    pub path: Option<Box<Expression>>,
10953    #[serde(default)]
10954    pub safe: Option<Box<Expression>>,
10955}
10956
10957/// Columns
10958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10959#[cfg_attr(feature = "bindings", derive(TS))]
10960pub struct Columns {
10961    pub this: Box<Expression>,
10962    #[serde(default)]
10963    pub unpack: Option<Box<Expression>>,
10964}
10965
10966/// ConvertToCharset
10967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10968#[cfg_attr(feature = "bindings", derive(TS))]
10969pub struct ConvertToCharset {
10970    pub this: Box<Expression>,
10971    #[serde(default)]
10972    pub dest: Option<Box<Expression>>,
10973    #[serde(default)]
10974    pub source: Option<Box<Expression>>,
10975}
10976
10977/// ConvertTimezone
10978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10979#[cfg_attr(feature = "bindings", derive(TS))]
10980pub struct ConvertTimezone {
10981    #[serde(default)]
10982    pub source_tz: Option<Box<Expression>>,
10983    #[serde(default)]
10984    pub target_tz: Option<Box<Expression>>,
10985    #[serde(default)]
10986    pub timestamp: Option<Box<Expression>>,
10987    #[serde(default)]
10988    pub options: Vec<Expression>,
10989}
10990
10991/// GenerateSeries
10992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10993#[cfg_attr(feature = "bindings", derive(TS))]
10994pub struct GenerateSeries {
10995    #[serde(default)]
10996    pub start: Option<Box<Expression>>,
10997    #[serde(default)]
10998    pub end: Option<Box<Expression>>,
10999    #[serde(default)]
11000    pub step: Option<Box<Expression>>,
11001    #[serde(default)]
11002    pub is_end_exclusive: Option<Box<Expression>>,
11003}
11004
11005/// AIAgg
11006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11007#[cfg_attr(feature = "bindings", derive(TS))]
11008pub struct AIAgg {
11009    pub this: Box<Expression>,
11010    pub expression: Box<Expression>,
11011}
11012
11013/// AIClassify
11014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11015#[cfg_attr(feature = "bindings", derive(TS))]
11016pub struct AIClassify {
11017    pub this: Box<Expression>,
11018    #[serde(default)]
11019    pub categories: Option<Box<Expression>>,
11020    #[serde(default)]
11021    pub config: Option<Box<Expression>>,
11022}
11023
11024/// ArrayAll
11025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11026#[cfg_attr(feature = "bindings", derive(TS))]
11027pub struct ArrayAll {
11028    pub this: Box<Expression>,
11029    pub expression: Box<Expression>,
11030}
11031
11032/// ArrayAny
11033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11034#[cfg_attr(feature = "bindings", derive(TS))]
11035pub struct ArrayAny {
11036    pub this: Box<Expression>,
11037    pub expression: Box<Expression>,
11038}
11039
11040/// ArrayConstructCompact
11041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11042#[cfg_attr(feature = "bindings", derive(TS))]
11043pub struct ArrayConstructCompact {
11044    #[serde(default)]
11045    pub expressions: Vec<Expression>,
11046}
11047
11048/// StPoint
11049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11050#[cfg_attr(feature = "bindings", derive(TS))]
11051pub struct StPoint {
11052    pub this: Box<Expression>,
11053    pub expression: Box<Expression>,
11054    #[serde(default)]
11055    pub null: Option<Box<Expression>>,
11056}
11057
11058/// StDistance
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct StDistance {
11062    pub this: Box<Expression>,
11063    pub expression: Box<Expression>,
11064    #[serde(default)]
11065    pub use_spheroid: Option<Box<Expression>>,
11066}
11067
11068/// StringToArray
11069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11070#[cfg_attr(feature = "bindings", derive(TS))]
11071pub struct StringToArray {
11072    pub this: Box<Expression>,
11073    #[serde(default)]
11074    pub expression: Option<Box<Expression>>,
11075    #[serde(default)]
11076    pub null: Option<Box<Expression>>,
11077}
11078
11079/// ArraySum
11080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11081#[cfg_attr(feature = "bindings", derive(TS))]
11082pub struct ArraySum {
11083    pub this: Box<Expression>,
11084    #[serde(default)]
11085    pub expression: Option<Box<Expression>>,
11086}
11087
11088/// ObjectAgg
11089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11090#[cfg_attr(feature = "bindings", derive(TS))]
11091pub struct ObjectAgg {
11092    pub this: Box<Expression>,
11093    pub expression: Box<Expression>,
11094}
11095
11096/// CastToStrType
11097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11098#[cfg_attr(feature = "bindings", derive(TS))]
11099pub struct CastToStrType {
11100    pub this: Box<Expression>,
11101    #[serde(default)]
11102    pub to: Option<Box<Expression>>,
11103}
11104
11105/// CheckJson
11106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11107#[cfg_attr(feature = "bindings", derive(TS))]
11108pub struct CheckJson {
11109    pub this: Box<Expression>,
11110}
11111
11112/// CheckXml
11113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11114#[cfg_attr(feature = "bindings", derive(TS))]
11115pub struct CheckXml {
11116    pub this: Box<Expression>,
11117    #[serde(default)]
11118    pub disable_auto_convert: Option<Box<Expression>>,
11119}
11120
11121/// TranslateCharacters
11122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11123#[cfg_attr(feature = "bindings", derive(TS))]
11124pub struct TranslateCharacters {
11125    pub this: Box<Expression>,
11126    pub expression: Box<Expression>,
11127    #[serde(default)]
11128    pub with_error: Option<Box<Expression>>,
11129}
11130
11131/// CurrentSchemas
11132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11133#[cfg_attr(feature = "bindings", derive(TS))]
11134pub struct CurrentSchemas {
11135    #[serde(default)]
11136    pub this: Option<Box<Expression>>,
11137}
11138
11139/// CurrentDatetime
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct CurrentDatetime {
11143    #[serde(default)]
11144    pub this: Option<Box<Expression>>,
11145}
11146
11147/// Localtime
11148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11149#[cfg_attr(feature = "bindings", derive(TS))]
11150pub struct Localtime {
11151    #[serde(default)]
11152    pub this: Option<Box<Expression>>,
11153}
11154
11155/// Localtimestamp
11156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11157#[cfg_attr(feature = "bindings", derive(TS))]
11158pub struct Localtimestamp {
11159    #[serde(default)]
11160    pub this: Option<Box<Expression>>,
11161}
11162
11163/// Systimestamp
11164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11165#[cfg_attr(feature = "bindings", derive(TS))]
11166pub struct Systimestamp {
11167    #[serde(default)]
11168    pub this: Option<Box<Expression>>,
11169}
11170
11171/// CurrentSchema
11172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11173#[cfg_attr(feature = "bindings", derive(TS))]
11174pub struct CurrentSchema {
11175    #[serde(default)]
11176    pub this: Option<Box<Expression>>,
11177}
11178
11179/// CurrentUser
11180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11181#[cfg_attr(feature = "bindings", derive(TS))]
11182pub struct CurrentUser {
11183    #[serde(default)]
11184    pub this: Option<Box<Expression>>,
11185}
11186
11187/// SessionUser - MySQL/PostgreSQL SESSION_USER function
11188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11189#[cfg_attr(feature = "bindings", derive(TS))]
11190pub struct SessionUser;
11191
11192/// JSONPathRoot - Represents $ in JSON path expressions
11193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11194#[cfg_attr(feature = "bindings", derive(TS))]
11195pub struct JSONPathRoot;
11196
11197/// UtcTime
11198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11199#[cfg_attr(feature = "bindings", derive(TS))]
11200pub struct UtcTime {
11201    #[serde(default)]
11202    pub this: Option<Box<Expression>>,
11203}
11204
11205/// UtcTimestamp
11206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11207#[cfg_attr(feature = "bindings", derive(TS))]
11208pub struct UtcTimestamp {
11209    #[serde(default)]
11210    pub this: Option<Box<Expression>>,
11211}
11212
11213/// TimestampFunc - TIMESTAMP constructor function
11214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11215#[cfg_attr(feature = "bindings", derive(TS))]
11216pub struct TimestampFunc {
11217    #[serde(default)]
11218    pub this: Option<Box<Expression>>,
11219    #[serde(default)]
11220    pub zone: Option<Box<Expression>>,
11221    #[serde(default)]
11222    pub with_tz: Option<bool>,
11223    #[serde(default)]
11224    pub safe: Option<bool>,
11225}
11226
11227/// DateBin
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct DateBin {
11231    pub this: Box<Expression>,
11232    pub expression: Box<Expression>,
11233    #[serde(default)]
11234    pub unit: Option<String>,
11235    #[serde(default)]
11236    pub zone: Option<Box<Expression>>,
11237    #[serde(default)]
11238    pub origin: Option<Box<Expression>>,
11239}
11240
11241/// Datetime
11242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11243#[cfg_attr(feature = "bindings", derive(TS))]
11244pub struct Datetime {
11245    pub this: Box<Expression>,
11246    #[serde(default)]
11247    pub expression: Option<Box<Expression>>,
11248}
11249
11250/// DatetimeAdd
11251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11252#[cfg_attr(feature = "bindings", derive(TS))]
11253pub struct DatetimeAdd {
11254    pub this: Box<Expression>,
11255    pub expression: Box<Expression>,
11256    #[serde(default)]
11257    pub unit: Option<String>,
11258}
11259
11260/// DatetimeSub
11261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11262#[cfg_attr(feature = "bindings", derive(TS))]
11263pub struct DatetimeSub {
11264    pub this: Box<Expression>,
11265    pub expression: Box<Expression>,
11266    #[serde(default)]
11267    pub unit: Option<String>,
11268}
11269
11270/// DatetimeDiff
11271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11272#[cfg_attr(feature = "bindings", derive(TS))]
11273pub struct DatetimeDiff {
11274    pub this: Box<Expression>,
11275    pub expression: Box<Expression>,
11276    #[serde(default)]
11277    pub unit: Option<String>,
11278}
11279
11280/// DatetimeTrunc
11281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11282#[cfg_attr(feature = "bindings", derive(TS))]
11283pub struct DatetimeTrunc {
11284    pub this: Box<Expression>,
11285    pub unit: String,
11286    #[serde(default)]
11287    pub zone: Option<Box<Expression>>,
11288}
11289
11290/// Dayname
11291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11292#[cfg_attr(feature = "bindings", derive(TS))]
11293pub struct Dayname {
11294    pub this: Box<Expression>,
11295    #[serde(default)]
11296    pub abbreviated: Option<Box<Expression>>,
11297}
11298
11299/// MakeInterval
11300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11301#[cfg_attr(feature = "bindings", derive(TS))]
11302pub struct MakeInterval {
11303    #[serde(default)]
11304    pub year: Option<Box<Expression>>,
11305    #[serde(default)]
11306    pub month: Option<Box<Expression>>,
11307    #[serde(default)]
11308    pub week: Option<Box<Expression>>,
11309    #[serde(default)]
11310    pub day: Option<Box<Expression>>,
11311    #[serde(default)]
11312    pub hour: Option<Box<Expression>>,
11313    #[serde(default)]
11314    pub minute: Option<Box<Expression>>,
11315    #[serde(default)]
11316    pub second: Option<Box<Expression>>,
11317}
11318
11319/// PreviousDay
11320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11321#[cfg_attr(feature = "bindings", derive(TS))]
11322pub struct PreviousDay {
11323    pub this: Box<Expression>,
11324    pub expression: Box<Expression>,
11325}
11326
11327/// Elt
11328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11329#[cfg_attr(feature = "bindings", derive(TS))]
11330pub struct Elt {
11331    pub this: Box<Expression>,
11332    #[serde(default)]
11333    pub expressions: Vec<Expression>,
11334}
11335
11336/// TimestampAdd
11337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11338#[cfg_attr(feature = "bindings", derive(TS))]
11339pub struct TimestampAdd {
11340    pub this: Box<Expression>,
11341    pub expression: Box<Expression>,
11342    #[serde(default)]
11343    pub unit: Option<String>,
11344}
11345
11346/// TimestampSub
11347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11348#[cfg_attr(feature = "bindings", derive(TS))]
11349pub struct TimestampSub {
11350    pub this: Box<Expression>,
11351    pub expression: Box<Expression>,
11352    #[serde(default)]
11353    pub unit: Option<String>,
11354}
11355
11356/// TimestampDiff
11357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11358#[cfg_attr(feature = "bindings", derive(TS))]
11359pub struct TimestampDiff {
11360    pub this: Box<Expression>,
11361    pub expression: Box<Expression>,
11362    #[serde(default)]
11363    pub unit: Option<String>,
11364}
11365
11366/// TimeSlice
11367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11368#[cfg_attr(feature = "bindings", derive(TS))]
11369pub struct TimeSlice {
11370    pub this: Box<Expression>,
11371    pub expression: Box<Expression>,
11372    pub unit: String,
11373    #[serde(default)]
11374    pub kind: Option<String>,
11375}
11376
11377/// TimeAdd
11378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11379#[cfg_attr(feature = "bindings", derive(TS))]
11380pub struct TimeAdd {
11381    pub this: Box<Expression>,
11382    pub expression: Box<Expression>,
11383    #[serde(default)]
11384    pub unit: Option<String>,
11385}
11386
11387/// TimeSub
11388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11389#[cfg_attr(feature = "bindings", derive(TS))]
11390pub struct TimeSub {
11391    pub this: Box<Expression>,
11392    pub expression: Box<Expression>,
11393    #[serde(default)]
11394    pub unit: Option<String>,
11395}
11396
11397/// TimeDiff
11398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11399#[cfg_attr(feature = "bindings", derive(TS))]
11400pub struct TimeDiff {
11401    pub this: Box<Expression>,
11402    pub expression: Box<Expression>,
11403    #[serde(default)]
11404    pub unit: Option<String>,
11405}
11406
11407/// TimeTrunc
11408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11409#[cfg_attr(feature = "bindings", derive(TS))]
11410pub struct TimeTrunc {
11411    pub this: Box<Expression>,
11412    pub unit: String,
11413    #[serde(default)]
11414    pub zone: Option<Box<Expression>>,
11415}
11416
11417/// DateFromParts
11418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11419#[cfg_attr(feature = "bindings", derive(TS))]
11420pub struct DateFromParts {
11421    #[serde(default)]
11422    pub year: Option<Box<Expression>>,
11423    #[serde(default)]
11424    pub month: Option<Box<Expression>>,
11425    #[serde(default)]
11426    pub day: Option<Box<Expression>>,
11427    #[serde(default)]
11428    pub allow_overflow: Option<Box<Expression>>,
11429}
11430
11431/// TimeFromParts
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct TimeFromParts {
11435    #[serde(default)]
11436    pub hour: Option<Box<Expression>>,
11437    #[serde(default)]
11438    pub min: Option<Box<Expression>>,
11439    #[serde(default)]
11440    pub sec: Option<Box<Expression>>,
11441    #[serde(default)]
11442    pub nano: Option<Box<Expression>>,
11443    #[serde(default)]
11444    pub fractions: Option<Box<Expression>>,
11445    #[serde(default)]
11446    pub precision: Option<i64>,
11447}
11448
11449/// DecodeCase
11450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11451#[cfg_attr(feature = "bindings", derive(TS))]
11452pub struct DecodeCase {
11453    #[serde(default)]
11454    pub expressions: Vec<Expression>,
11455}
11456
11457/// Decrypt
11458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11459#[cfg_attr(feature = "bindings", derive(TS))]
11460pub struct Decrypt {
11461    pub this: Box<Expression>,
11462    #[serde(default)]
11463    pub passphrase: Option<Box<Expression>>,
11464    #[serde(default)]
11465    pub aad: Option<Box<Expression>>,
11466    #[serde(default)]
11467    pub encryption_method: Option<Box<Expression>>,
11468    #[serde(default)]
11469    pub safe: Option<Box<Expression>>,
11470}
11471
11472/// DecryptRaw
11473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11474#[cfg_attr(feature = "bindings", derive(TS))]
11475pub struct DecryptRaw {
11476    pub this: Box<Expression>,
11477    #[serde(default)]
11478    pub key: Option<Box<Expression>>,
11479    #[serde(default)]
11480    pub iv: Option<Box<Expression>>,
11481    #[serde(default)]
11482    pub aad: Option<Box<Expression>>,
11483    #[serde(default)]
11484    pub encryption_method: Option<Box<Expression>>,
11485    #[serde(default)]
11486    pub aead: Option<Box<Expression>>,
11487    #[serde(default)]
11488    pub safe: Option<Box<Expression>>,
11489}
11490
11491/// Encode
11492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11493#[cfg_attr(feature = "bindings", derive(TS))]
11494pub struct Encode {
11495    pub this: Box<Expression>,
11496    #[serde(default)]
11497    pub charset: Option<Box<Expression>>,
11498}
11499
11500/// Encrypt
11501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11502#[cfg_attr(feature = "bindings", derive(TS))]
11503pub struct Encrypt {
11504    pub this: Box<Expression>,
11505    #[serde(default)]
11506    pub passphrase: Option<Box<Expression>>,
11507    #[serde(default)]
11508    pub aad: Option<Box<Expression>>,
11509    #[serde(default)]
11510    pub encryption_method: Option<Box<Expression>>,
11511}
11512
11513/// EncryptRaw
11514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11515#[cfg_attr(feature = "bindings", derive(TS))]
11516pub struct EncryptRaw {
11517    pub this: Box<Expression>,
11518    #[serde(default)]
11519    pub key: Option<Box<Expression>>,
11520    #[serde(default)]
11521    pub iv: Option<Box<Expression>>,
11522    #[serde(default)]
11523    pub aad: Option<Box<Expression>>,
11524    #[serde(default)]
11525    pub encryption_method: Option<Box<Expression>>,
11526}
11527
11528/// EqualNull
11529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11530#[cfg_attr(feature = "bindings", derive(TS))]
11531pub struct EqualNull {
11532    pub this: Box<Expression>,
11533    pub expression: Box<Expression>,
11534}
11535
11536/// ToBinary
11537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11538#[cfg_attr(feature = "bindings", derive(TS))]
11539pub struct ToBinary {
11540    pub this: Box<Expression>,
11541    #[serde(default)]
11542    pub format: Option<String>,
11543    #[serde(default)]
11544    pub safe: Option<Box<Expression>>,
11545}
11546
11547/// Base64DecodeBinary
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct Base64DecodeBinary {
11551    pub this: Box<Expression>,
11552    #[serde(default)]
11553    pub alphabet: Option<Box<Expression>>,
11554}
11555
11556/// Base64DecodeString
11557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11558#[cfg_attr(feature = "bindings", derive(TS))]
11559pub struct Base64DecodeString {
11560    pub this: Box<Expression>,
11561    #[serde(default)]
11562    pub alphabet: Option<Box<Expression>>,
11563}
11564
11565/// Base64Encode
11566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11567#[cfg_attr(feature = "bindings", derive(TS))]
11568pub struct Base64Encode {
11569    pub this: Box<Expression>,
11570    #[serde(default)]
11571    pub max_line_length: Option<Box<Expression>>,
11572    #[serde(default)]
11573    pub alphabet: Option<Box<Expression>>,
11574}
11575
11576/// TryBase64DecodeBinary
11577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11578#[cfg_attr(feature = "bindings", derive(TS))]
11579pub struct TryBase64DecodeBinary {
11580    pub this: Box<Expression>,
11581    #[serde(default)]
11582    pub alphabet: Option<Box<Expression>>,
11583}
11584
11585/// TryBase64DecodeString
11586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11587#[cfg_attr(feature = "bindings", derive(TS))]
11588pub struct TryBase64DecodeString {
11589    pub this: Box<Expression>,
11590    #[serde(default)]
11591    pub alphabet: Option<Box<Expression>>,
11592}
11593
11594/// GapFill
11595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11596#[cfg_attr(feature = "bindings", derive(TS))]
11597pub struct GapFill {
11598    pub this: Box<Expression>,
11599    #[serde(default)]
11600    pub ts_column: Option<Box<Expression>>,
11601    #[serde(default)]
11602    pub bucket_width: Option<Box<Expression>>,
11603    #[serde(default)]
11604    pub partitioning_columns: Option<Box<Expression>>,
11605    #[serde(default)]
11606    pub value_columns: Option<Box<Expression>>,
11607    #[serde(default)]
11608    pub origin: Option<Box<Expression>>,
11609    #[serde(default)]
11610    pub ignore_nulls: Option<Box<Expression>>,
11611}
11612
11613/// GenerateDateArray
11614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11615#[cfg_attr(feature = "bindings", derive(TS))]
11616pub struct GenerateDateArray {
11617    #[serde(default)]
11618    pub start: Option<Box<Expression>>,
11619    #[serde(default)]
11620    pub end: Option<Box<Expression>>,
11621    #[serde(default)]
11622    pub step: Option<Box<Expression>>,
11623}
11624
11625/// GenerateTimestampArray
11626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11627#[cfg_attr(feature = "bindings", derive(TS))]
11628pub struct GenerateTimestampArray {
11629    #[serde(default)]
11630    pub start: Option<Box<Expression>>,
11631    #[serde(default)]
11632    pub end: Option<Box<Expression>>,
11633    #[serde(default)]
11634    pub step: Option<Box<Expression>>,
11635}
11636
11637/// GetExtract
11638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11639#[cfg_attr(feature = "bindings", derive(TS))]
11640pub struct GetExtract {
11641    pub this: Box<Expression>,
11642    pub expression: Box<Expression>,
11643}
11644
11645/// Getbit
11646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11647#[cfg_attr(feature = "bindings", derive(TS))]
11648pub struct Getbit {
11649    pub this: Box<Expression>,
11650    pub expression: Box<Expression>,
11651    #[serde(default)]
11652    pub zero_is_msb: Option<Box<Expression>>,
11653}
11654
11655/// OverflowTruncateBehavior
11656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11657#[cfg_attr(feature = "bindings", derive(TS))]
11658pub struct OverflowTruncateBehavior {
11659    #[serde(default)]
11660    pub this: Option<Box<Expression>>,
11661    #[serde(default)]
11662    pub with_count: Option<Box<Expression>>,
11663}
11664
11665/// HexEncode
11666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11667#[cfg_attr(feature = "bindings", derive(TS))]
11668pub struct HexEncode {
11669    pub this: Box<Expression>,
11670    #[serde(default)]
11671    pub case: Option<Box<Expression>>,
11672}
11673
11674/// Compress
11675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11676#[cfg_attr(feature = "bindings", derive(TS))]
11677pub struct Compress {
11678    pub this: Box<Expression>,
11679    #[serde(default)]
11680    pub method: Option<String>,
11681}
11682
11683/// DecompressBinary
11684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11685#[cfg_attr(feature = "bindings", derive(TS))]
11686pub struct DecompressBinary {
11687    pub this: Box<Expression>,
11688    pub method: String,
11689}
11690
11691/// DecompressString
11692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11693#[cfg_attr(feature = "bindings", derive(TS))]
11694pub struct DecompressString {
11695    pub this: Box<Expression>,
11696    pub method: String,
11697}
11698
11699/// Xor
11700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11701#[cfg_attr(feature = "bindings", derive(TS))]
11702pub struct Xor {
11703    #[serde(default)]
11704    pub this: Option<Box<Expression>>,
11705    #[serde(default)]
11706    pub expression: Option<Box<Expression>>,
11707    #[serde(default)]
11708    pub expressions: Vec<Expression>,
11709}
11710
11711/// Nullif
11712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11713#[cfg_attr(feature = "bindings", derive(TS))]
11714pub struct Nullif {
11715    pub this: Box<Expression>,
11716    pub expression: Box<Expression>,
11717}
11718
11719/// JSON
11720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11721#[cfg_attr(feature = "bindings", derive(TS))]
11722pub struct JSON {
11723    #[serde(default)]
11724    pub this: Option<Box<Expression>>,
11725    #[serde(default)]
11726    pub with_: Option<Box<Expression>>,
11727    #[serde(default)]
11728    pub unique: bool,
11729}
11730
11731/// JSONPath
11732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11733#[cfg_attr(feature = "bindings", derive(TS))]
11734pub struct JSONPath {
11735    #[serde(default)]
11736    pub expressions: Vec<Expression>,
11737    #[serde(default)]
11738    pub escape: Option<Box<Expression>>,
11739}
11740
11741/// JSONPathFilter
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct JSONPathFilter {
11745    pub this: Box<Expression>,
11746}
11747
11748/// JSONPathKey
11749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11750#[cfg_attr(feature = "bindings", derive(TS))]
11751pub struct JSONPathKey {
11752    pub this: Box<Expression>,
11753}
11754
11755/// JSONPathRecursive
11756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11757#[cfg_attr(feature = "bindings", derive(TS))]
11758pub struct JSONPathRecursive {
11759    #[serde(default)]
11760    pub this: Option<Box<Expression>>,
11761}
11762
11763/// JSONPathScript
11764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11765#[cfg_attr(feature = "bindings", derive(TS))]
11766pub struct JSONPathScript {
11767    pub this: Box<Expression>,
11768}
11769
11770/// JSONPathSlice
11771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11772#[cfg_attr(feature = "bindings", derive(TS))]
11773pub struct JSONPathSlice {
11774    #[serde(default)]
11775    pub start: Option<Box<Expression>>,
11776    #[serde(default)]
11777    pub end: Option<Box<Expression>>,
11778    #[serde(default)]
11779    pub step: Option<Box<Expression>>,
11780}
11781
11782/// JSONPathSelector
11783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11784#[cfg_attr(feature = "bindings", derive(TS))]
11785pub struct JSONPathSelector {
11786    pub this: Box<Expression>,
11787}
11788
11789/// JSONPathSubscript
11790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11791#[cfg_attr(feature = "bindings", derive(TS))]
11792pub struct JSONPathSubscript {
11793    pub this: Box<Expression>,
11794}
11795
11796/// JSONPathUnion
11797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11798#[cfg_attr(feature = "bindings", derive(TS))]
11799pub struct JSONPathUnion {
11800    #[serde(default)]
11801    pub expressions: Vec<Expression>,
11802}
11803
11804/// Format
11805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11806#[cfg_attr(feature = "bindings", derive(TS))]
11807pub struct Format {
11808    pub this: Box<Expression>,
11809    #[serde(default)]
11810    pub expressions: Vec<Expression>,
11811}
11812
11813/// JSONKeys
11814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11815#[cfg_attr(feature = "bindings", derive(TS))]
11816pub struct JSONKeys {
11817    pub this: Box<Expression>,
11818    #[serde(default)]
11819    pub expression: Option<Box<Expression>>,
11820    #[serde(default)]
11821    pub expressions: Vec<Expression>,
11822}
11823
11824/// JSONKeyValue
11825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11826#[cfg_attr(feature = "bindings", derive(TS))]
11827pub struct JSONKeyValue {
11828    pub this: Box<Expression>,
11829    pub expression: Box<Expression>,
11830}
11831
11832/// JSONKeysAtDepth
11833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11834#[cfg_attr(feature = "bindings", derive(TS))]
11835pub struct JSONKeysAtDepth {
11836    pub this: Box<Expression>,
11837    #[serde(default)]
11838    pub expression: Option<Box<Expression>>,
11839    #[serde(default)]
11840    pub mode: Option<Box<Expression>>,
11841}
11842
11843/// JSONObject
11844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11845#[cfg_attr(feature = "bindings", derive(TS))]
11846pub struct JSONObject {
11847    #[serde(default)]
11848    pub expressions: Vec<Expression>,
11849    #[serde(default)]
11850    pub null_handling: Option<Box<Expression>>,
11851    #[serde(default)]
11852    pub unique_keys: Option<Box<Expression>>,
11853    #[serde(default)]
11854    pub return_type: Option<Box<Expression>>,
11855    #[serde(default)]
11856    pub encoding: Option<Box<Expression>>,
11857}
11858
11859/// JSONObjectAgg
11860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11861#[cfg_attr(feature = "bindings", derive(TS))]
11862pub struct JSONObjectAgg {
11863    #[serde(default)]
11864    pub expressions: Vec<Expression>,
11865    #[serde(default)]
11866    pub null_handling: Option<Box<Expression>>,
11867    #[serde(default)]
11868    pub unique_keys: Option<Box<Expression>>,
11869    #[serde(default)]
11870    pub return_type: Option<Box<Expression>>,
11871    #[serde(default)]
11872    pub encoding: Option<Box<Expression>>,
11873}
11874
11875/// JSONBObjectAgg
11876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11877#[cfg_attr(feature = "bindings", derive(TS))]
11878pub struct JSONBObjectAgg {
11879    pub this: Box<Expression>,
11880    pub expression: Box<Expression>,
11881}
11882
11883/// JSONArray
11884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11885#[cfg_attr(feature = "bindings", derive(TS))]
11886pub struct JSONArray {
11887    #[serde(default)]
11888    pub expressions: Vec<Expression>,
11889    #[serde(default)]
11890    pub null_handling: Option<Box<Expression>>,
11891    #[serde(default)]
11892    pub return_type: Option<Box<Expression>>,
11893    #[serde(default)]
11894    pub strict: Option<Box<Expression>>,
11895}
11896
11897/// JSONArrayAgg
11898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11899#[cfg_attr(feature = "bindings", derive(TS))]
11900pub struct JSONArrayAgg {
11901    pub this: Box<Expression>,
11902    #[serde(default)]
11903    pub order: Option<Box<Expression>>,
11904    #[serde(default)]
11905    pub null_handling: Option<Box<Expression>>,
11906    #[serde(default)]
11907    pub return_type: Option<Box<Expression>>,
11908    #[serde(default)]
11909    pub strict: Option<Box<Expression>>,
11910}
11911
11912/// JSONExists
11913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11914#[cfg_attr(feature = "bindings", derive(TS))]
11915pub struct JSONExists {
11916    pub this: Box<Expression>,
11917    #[serde(default)]
11918    pub path: Option<Box<Expression>>,
11919    #[serde(default)]
11920    pub passing: Option<Box<Expression>>,
11921    #[serde(default)]
11922    pub on_condition: Option<Box<Expression>>,
11923    #[serde(default)]
11924    pub from_dcolonqmark: Option<Box<Expression>>,
11925}
11926
11927/// JSONColumnDef
11928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11929#[cfg_attr(feature = "bindings", derive(TS))]
11930pub struct JSONColumnDef {
11931    #[serde(default)]
11932    pub this: Option<Box<Expression>>,
11933    #[serde(default)]
11934    pub kind: Option<String>,
11935    #[serde(default)]
11936    pub path: Option<Box<Expression>>,
11937    #[serde(default)]
11938    pub nested_schema: Option<Box<Expression>>,
11939    #[serde(default)]
11940    pub ordinality: Option<Box<Expression>>,
11941}
11942
11943/// JSONSchema
11944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11945#[cfg_attr(feature = "bindings", derive(TS))]
11946pub struct JSONSchema {
11947    #[serde(default)]
11948    pub expressions: Vec<Expression>,
11949}
11950
11951/// JSONSet
11952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11953#[cfg_attr(feature = "bindings", derive(TS))]
11954pub struct JSONSet {
11955    pub this: Box<Expression>,
11956    #[serde(default)]
11957    pub expressions: Vec<Expression>,
11958}
11959
11960/// JSONStripNulls
11961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11962#[cfg_attr(feature = "bindings", derive(TS))]
11963pub struct JSONStripNulls {
11964    pub this: Box<Expression>,
11965    #[serde(default)]
11966    pub expression: Option<Box<Expression>>,
11967    #[serde(default)]
11968    pub include_arrays: Option<Box<Expression>>,
11969    #[serde(default)]
11970    pub remove_empty: Option<Box<Expression>>,
11971}
11972
11973/// JSONValue
11974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11975#[cfg_attr(feature = "bindings", derive(TS))]
11976pub struct JSONValue {
11977    pub this: Box<Expression>,
11978    #[serde(default)]
11979    pub path: Option<Box<Expression>>,
11980    #[serde(default)]
11981    pub returning: Option<Box<Expression>>,
11982    #[serde(default)]
11983    pub on_condition: Option<Box<Expression>>,
11984}
11985
11986/// JSONValueArray
11987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11988#[cfg_attr(feature = "bindings", derive(TS))]
11989pub struct JSONValueArray {
11990    pub this: Box<Expression>,
11991    #[serde(default)]
11992    pub expression: Option<Box<Expression>>,
11993}
11994
11995/// JSONRemove
11996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11997#[cfg_attr(feature = "bindings", derive(TS))]
11998pub struct JSONRemove {
11999    pub this: Box<Expression>,
12000    #[serde(default)]
12001    pub expressions: Vec<Expression>,
12002}
12003
12004/// JSONTable
12005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12006#[cfg_attr(feature = "bindings", derive(TS))]
12007pub struct JSONTable {
12008    pub this: Box<Expression>,
12009    #[serde(default)]
12010    pub schema: Option<Box<Expression>>,
12011    #[serde(default)]
12012    pub path: Option<Box<Expression>>,
12013    #[serde(default)]
12014    pub error_handling: Option<Box<Expression>>,
12015    #[serde(default)]
12016    pub empty_handling: Option<Box<Expression>>,
12017}
12018
12019/// JSONType
12020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12021#[cfg_attr(feature = "bindings", derive(TS))]
12022pub struct JSONType {
12023    pub this: Box<Expression>,
12024    #[serde(default)]
12025    pub expression: Option<Box<Expression>>,
12026}
12027
12028/// ObjectInsert
12029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12030#[cfg_attr(feature = "bindings", derive(TS))]
12031pub struct ObjectInsert {
12032    pub this: Box<Expression>,
12033    #[serde(default)]
12034    pub key: Option<Box<Expression>>,
12035    #[serde(default)]
12036    pub value: Option<Box<Expression>>,
12037    #[serde(default)]
12038    pub update_flag: Option<Box<Expression>>,
12039}
12040
12041/// OpenJSONColumnDef
12042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12043#[cfg_attr(feature = "bindings", derive(TS))]
12044pub struct OpenJSONColumnDef {
12045    pub this: Box<Expression>,
12046    pub kind: String,
12047    #[serde(default)]
12048    pub path: Option<Box<Expression>>,
12049    #[serde(default)]
12050    pub as_json: Option<Box<Expression>>,
12051    /// The parsed data type for proper generation
12052    #[serde(default, skip_serializing_if = "Option::is_none")]
12053    pub data_type: Option<DataType>,
12054}
12055
12056/// OpenJSON
12057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12058#[cfg_attr(feature = "bindings", derive(TS))]
12059pub struct OpenJSON {
12060    pub this: Box<Expression>,
12061    #[serde(default)]
12062    pub path: Option<Box<Expression>>,
12063    #[serde(default)]
12064    pub expressions: Vec<Expression>,
12065}
12066
12067/// JSONBExists
12068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12069#[cfg_attr(feature = "bindings", derive(TS))]
12070pub struct JSONBExists {
12071    pub this: Box<Expression>,
12072    #[serde(default)]
12073    pub path: Option<Box<Expression>>,
12074}
12075
12076/// JSONCast
12077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12078#[cfg_attr(feature = "bindings", derive(TS))]
12079pub struct JSONCast {
12080    pub this: Box<Expression>,
12081    pub to: DataType,
12082}
12083
12084/// JSONExtract
12085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12086#[cfg_attr(feature = "bindings", derive(TS))]
12087pub struct JSONExtract {
12088    pub this: Box<Expression>,
12089    pub expression: Box<Expression>,
12090    #[serde(default)]
12091    pub only_json_types: Option<Box<Expression>>,
12092    #[serde(default)]
12093    pub expressions: Vec<Expression>,
12094    #[serde(default)]
12095    pub variant_extract: Option<Box<Expression>>,
12096    #[serde(default)]
12097    pub json_query: Option<Box<Expression>>,
12098    #[serde(default)]
12099    pub option: Option<Box<Expression>>,
12100    #[serde(default)]
12101    pub quote: Option<Box<Expression>>,
12102    #[serde(default)]
12103    pub on_condition: Option<Box<Expression>>,
12104    #[serde(default)]
12105    pub requires_json: Option<Box<Expression>>,
12106}
12107
12108/// JSONExtractQuote
12109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12110#[cfg_attr(feature = "bindings", derive(TS))]
12111pub struct JSONExtractQuote {
12112    #[serde(default)]
12113    pub option: Option<Box<Expression>>,
12114    #[serde(default)]
12115    pub scalar: Option<Box<Expression>>,
12116}
12117
12118/// JSONExtractArray
12119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12120#[cfg_attr(feature = "bindings", derive(TS))]
12121pub struct JSONExtractArray {
12122    pub this: Box<Expression>,
12123    #[serde(default)]
12124    pub expression: Option<Box<Expression>>,
12125}
12126
12127/// JSONExtractScalar
12128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12129#[cfg_attr(feature = "bindings", derive(TS))]
12130pub struct JSONExtractScalar {
12131    pub this: Box<Expression>,
12132    pub expression: Box<Expression>,
12133    #[serde(default)]
12134    pub only_json_types: Option<Box<Expression>>,
12135    #[serde(default)]
12136    pub expressions: Vec<Expression>,
12137    #[serde(default)]
12138    pub json_type: Option<Box<Expression>>,
12139    #[serde(default)]
12140    pub scalar_only: Option<Box<Expression>>,
12141}
12142
12143/// JSONBExtractScalar
12144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12145#[cfg_attr(feature = "bindings", derive(TS))]
12146pub struct JSONBExtractScalar {
12147    pub this: Box<Expression>,
12148    pub expression: Box<Expression>,
12149    #[serde(default)]
12150    pub json_type: Option<Box<Expression>>,
12151}
12152
12153/// JSONFormat
12154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12155#[cfg_attr(feature = "bindings", derive(TS))]
12156pub struct JSONFormat {
12157    #[serde(default)]
12158    pub this: Option<Box<Expression>>,
12159    #[serde(default)]
12160    pub options: Vec<Expression>,
12161    #[serde(default)]
12162    pub is_json: Option<Box<Expression>>,
12163    #[serde(default)]
12164    pub to_json: Option<Box<Expression>>,
12165}
12166
12167/// JSONArrayAppend
12168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12169#[cfg_attr(feature = "bindings", derive(TS))]
12170pub struct JSONArrayAppend {
12171    pub this: Box<Expression>,
12172    #[serde(default)]
12173    pub expressions: Vec<Expression>,
12174}
12175
12176/// JSONArrayContains
12177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12178#[cfg_attr(feature = "bindings", derive(TS))]
12179pub struct JSONArrayContains {
12180    pub this: Box<Expression>,
12181    pub expression: Box<Expression>,
12182    #[serde(default)]
12183    pub json_type: Option<Box<Expression>>,
12184}
12185
12186/// JSONArrayInsert
12187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12188#[cfg_attr(feature = "bindings", derive(TS))]
12189pub struct JSONArrayInsert {
12190    pub this: Box<Expression>,
12191    #[serde(default)]
12192    pub expressions: Vec<Expression>,
12193}
12194
12195/// ParseJSON
12196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12197#[cfg_attr(feature = "bindings", derive(TS))]
12198pub struct ParseJSON {
12199    pub this: Box<Expression>,
12200    #[serde(default)]
12201    pub expression: Option<Box<Expression>>,
12202    #[serde(default)]
12203    pub safe: Option<Box<Expression>>,
12204}
12205
12206/// ParseUrl
12207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12208#[cfg_attr(feature = "bindings", derive(TS))]
12209pub struct ParseUrl {
12210    pub this: Box<Expression>,
12211    #[serde(default)]
12212    pub part_to_extract: Option<Box<Expression>>,
12213    #[serde(default)]
12214    pub key: Option<Box<Expression>>,
12215    #[serde(default)]
12216    pub permissive: Option<Box<Expression>>,
12217}
12218
12219/// ParseIp
12220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12221#[cfg_attr(feature = "bindings", derive(TS))]
12222pub struct ParseIp {
12223    pub this: Box<Expression>,
12224    #[serde(default)]
12225    pub type_: Option<Box<Expression>>,
12226    #[serde(default)]
12227    pub permissive: Option<Box<Expression>>,
12228}
12229
12230/// ParseTime
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct ParseTime {
12234    pub this: Box<Expression>,
12235    pub format: String,
12236}
12237
12238/// ParseDatetime
12239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12240#[cfg_attr(feature = "bindings", derive(TS))]
12241pub struct ParseDatetime {
12242    pub this: Box<Expression>,
12243    #[serde(default)]
12244    pub format: Option<String>,
12245    #[serde(default)]
12246    pub zone: Option<Box<Expression>>,
12247}
12248
12249/// Map
12250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12251#[cfg_attr(feature = "bindings", derive(TS))]
12252pub struct Map {
12253    #[serde(default)]
12254    pub keys: Vec<Expression>,
12255    #[serde(default)]
12256    pub values: Vec<Expression>,
12257}
12258
12259/// MapCat
12260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12261#[cfg_attr(feature = "bindings", derive(TS))]
12262pub struct MapCat {
12263    pub this: Box<Expression>,
12264    pub expression: Box<Expression>,
12265}
12266
12267/// MapDelete
12268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12269#[cfg_attr(feature = "bindings", derive(TS))]
12270pub struct MapDelete {
12271    pub this: Box<Expression>,
12272    #[serde(default)]
12273    pub expressions: Vec<Expression>,
12274}
12275
12276/// MapInsert
12277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12278#[cfg_attr(feature = "bindings", derive(TS))]
12279pub struct MapInsert {
12280    pub this: Box<Expression>,
12281    #[serde(default)]
12282    pub key: Option<Box<Expression>>,
12283    #[serde(default)]
12284    pub value: Option<Box<Expression>>,
12285    #[serde(default)]
12286    pub update_flag: Option<Box<Expression>>,
12287}
12288
12289/// MapPick
12290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12291#[cfg_attr(feature = "bindings", derive(TS))]
12292pub struct MapPick {
12293    pub this: Box<Expression>,
12294    #[serde(default)]
12295    pub expressions: Vec<Expression>,
12296}
12297
12298/// ScopeResolution
12299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12300#[cfg_attr(feature = "bindings", derive(TS))]
12301pub struct ScopeResolution {
12302    #[serde(default)]
12303    pub this: Option<Box<Expression>>,
12304    pub expression: Box<Expression>,
12305}
12306
12307/// Slice
12308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12309#[cfg_attr(feature = "bindings", derive(TS))]
12310pub struct Slice {
12311    #[serde(default)]
12312    pub this: Option<Box<Expression>>,
12313    #[serde(default)]
12314    pub expression: Option<Box<Expression>>,
12315    #[serde(default)]
12316    pub step: Option<Box<Expression>>,
12317}
12318
12319/// VarMap
12320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12321#[cfg_attr(feature = "bindings", derive(TS))]
12322pub struct VarMap {
12323    #[serde(default)]
12324    pub keys: Vec<Expression>,
12325    #[serde(default)]
12326    pub values: Vec<Expression>,
12327}
12328
12329/// MatchAgainst
12330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12331#[cfg_attr(feature = "bindings", derive(TS))]
12332pub struct MatchAgainst {
12333    pub this: Box<Expression>,
12334    #[serde(default)]
12335    pub expressions: Vec<Expression>,
12336    #[serde(default)]
12337    pub modifier: Option<Box<Expression>>,
12338}
12339
12340/// MD5Digest
12341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12342#[cfg_attr(feature = "bindings", derive(TS))]
12343pub struct MD5Digest {
12344    pub this: Box<Expression>,
12345    #[serde(default)]
12346    pub expressions: Vec<Expression>,
12347}
12348
12349/// Monthname
12350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12351#[cfg_attr(feature = "bindings", derive(TS))]
12352pub struct Monthname {
12353    pub this: Box<Expression>,
12354    #[serde(default)]
12355    pub abbreviated: Option<Box<Expression>>,
12356}
12357
12358/// Ntile
12359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12360#[cfg_attr(feature = "bindings", derive(TS))]
12361pub struct Ntile {
12362    #[serde(default)]
12363    pub this: Option<Box<Expression>>,
12364}
12365
12366/// Normalize
12367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12368#[cfg_attr(feature = "bindings", derive(TS))]
12369pub struct Normalize {
12370    pub this: Box<Expression>,
12371    #[serde(default)]
12372    pub form: Option<Box<Expression>>,
12373    #[serde(default)]
12374    pub is_casefold: Option<Box<Expression>>,
12375}
12376
12377/// Normal
12378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12379#[cfg_attr(feature = "bindings", derive(TS))]
12380pub struct Normal {
12381    pub this: Box<Expression>,
12382    #[serde(default)]
12383    pub stddev: Option<Box<Expression>>,
12384    #[serde(default)]
12385    pub gen: Option<Box<Expression>>,
12386}
12387
12388/// Predict
12389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12390#[cfg_attr(feature = "bindings", derive(TS))]
12391pub struct Predict {
12392    pub this: Box<Expression>,
12393    pub expression: Box<Expression>,
12394    #[serde(default)]
12395    pub params_struct: Option<Box<Expression>>,
12396}
12397
12398/// MLTranslate
12399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12400#[cfg_attr(feature = "bindings", derive(TS))]
12401pub struct MLTranslate {
12402    pub this: Box<Expression>,
12403    pub expression: Box<Expression>,
12404    #[serde(default)]
12405    pub params_struct: Option<Box<Expression>>,
12406}
12407
12408/// FeaturesAtTime
12409#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12410#[cfg_attr(feature = "bindings", derive(TS))]
12411pub struct FeaturesAtTime {
12412    pub this: Box<Expression>,
12413    #[serde(default)]
12414    pub time: Option<Box<Expression>>,
12415    #[serde(default)]
12416    pub num_rows: Option<Box<Expression>>,
12417    #[serde(default)]
12418    pub ignore_feature_nulls: Option<Box<Expression>>,
12419}
12420
12421/// GenerateEmbedding
12422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12423#[cfg_attr(feature = "bindings", derive(TS))]
12424pub struct GenerateEmbedding {
12425    pub this: Box<Expression>,
12426    pub expression: Box<Expression>,
12427    #[serde(default)]
12428    pub params_struct: Option<Box<Expression>>,
12429    #[serde(default)]
12430    pub is_text: Option<Box<Expression>>,
12431}
12432
12433/// MLForecast
12434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12435#[cfg_attr(feature = "bindings", derive(TS))]
12436pub struct MLForecast {
12437    pub this: Box<Expression>,
12438    #[serde(default)]
12439    pub expression: Option<Box<Expression>>,
12440    #[serde(default)]
12441    pub params_struct: Option<Box<Expression>>,
12442}
12443
12444/// ModelAttribute
12445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12446#[cfg_attr(feature = "bindings", derive(TS))]
12447pub struct ModelAttribute {
12448    pub this: Box<Expression>,
12449    pub expression: Box<Expression>,
12450}
12451
12452/// VectorSearch
12453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12454#[cfg_attr(feature = "bindings", derive(TS))]
12455pub struct VectorSearch {
12456    pub this: Box<Expression>,
12457    #[serde(default)]
12458    pub column_to_search: Option<Box<Expression>>,
12459    #[serde(default)]
12460    pub query_table: Option<Box<Expression>>,
12461    #[serde(default)]
12462    pub query_column_to_search: Option<Box<Expression>>,
12463    #[serde(default)]
12464    pub top_k: Option<Box<Expression>>,
12465    #[serde(default)]
12466    pub distance_type: Option<Box<Expression>>,
12467    #[serde(default)]
12468    pub options: Vec<Expression>,
12469}
12470
12471/// Quantile
12472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12473#[cfg_attr(feature = "bindings", derive(TS))]
12474pub struct Quantile {
12475    pub this: Box<Expression>,
12476    #[serde(default)]
12477    pub quantile: Option<Box<Expression>>,
12478}
12479
12480/// ApproxQuantile
12481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12482#[cfg_attr(feature = "bindings", derive(TS))]
12483pub struct ApproxQuantile {
12484    pub this: Box<Expression>,
12485    #[serde(default)]
12486    pub quantile: Option<Box<Expression>>,
12487    #[serde(default)]
12488    pub accuracy: Option<Box<Expression>>,
12489    #[serde(default)]
12490    pub weight: Option<Box<Expression>>,
12491    #[serde(default)]
12492    pub error_tolerance: Option<Box<Expression>>,
12493}
12494
12495/// ApproxPercentileEstimate
12496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12497#[cfg_attr(feature = "bindings", derive(TS))]
12498pub struct ApproxPercentileEstimate {
12499    pub this: Box<Expression>,
12500    #[serde(default)]
12501    pub percentile: Option<Box<Expression>>,
12502}
12503
12504/// Randn
12505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12506#[cfg_attr(feature = "bindings", derive(TS))]
12507pub struct Randn {
12508    #[serde(default)]
12509    pub this: Option<Box<Expression>>,
12510}
12511
12512/// Randstr
12513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12514#[cfg_attr(feature = "bindings", derive(TS))]
12515pub struct Randstr {
12516    pub this: Box<Expression>,
12517    #[serde(default)]
12518    pub generator: Option<Box<Expression>>,
12519}
12520
12521/// RangeN
12522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12523#[cfg_attr(feature = "bindings", derive(TS))]
12524pub struct RangeN {
12525    pub this: Box<Expression>,
12526    #[serde(default)]
12527    pub expressions: Vec<Expression>,
12528    #[serde(default)]
12529    pub each: Option<Box<Expression>>,
12530}
12531
12532/// RangeBucket
12533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12534#[cfg_attr(feature = "bindings", derive(TS))]
12535pub struct RangeBucket {
12536    pub this: Box<Expression>,
12537    pub expression: Box<Expression>,
12538}
12539
12540/// ReadCSV
12541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12542#[cfg_attr(feature = "bindings", derive(TS))]
12543pub struct ReadCSV {
12544    pub this: Box<Expression>,
12545    #[serde(default)]
12546    pub expressions: Vec<Expression>,
12547}
12548
12549/// ReadParquet
12550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12551#[cfg_attr(feature = "bindings", derive(TS))]
12552pub struct ReadParquet {
12553    #[serde(default)]
12554    pub expressions: Vec<Expression>,
12555}
12556
12557/// Reduce
12558#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12559#[cfg_attr(feature = "bindings", derive(TS))]
12560pub struct Reduce {
12561    pub this: Box<Expression>,
12562    #[serde(default)]
12563    pub initial: Option<Box<Expression>>,
12564    #[serde(default)]
12565    pub merge: Option<Box<Expression>>,
12566    #[serde(default)]
12567    pub finish: Option<Box<Expression>>,
12568}
12569
12570/// RegexpExtractAll
12571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12572#[cfg_attr(feature = "bindings", derive(TS))]
12573pub struct RegexpExtractAll {
12574    pub this: Box<Expression>,
12575    pub expression: Box<Expression>,
12576    #[serde(default)]
12577    pub group: Option<Box<Expression>>,
12578    #[serde(default)]
12579    pub parameters: Option<Box<Expression>>,
12580    #[serde(default)]
12581    pub position: Option<Box<Expression>>,
12582    #[serde(default)]
12583    pub occurrence: Option<Box<Expression>>,
12584}
12585
12586/// RegexpILike
12587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12588#[cfg_attr(feature = "bindings", derive(TS))]
12589pub struct RegexpILike {
12590    pub this: Box<Expression>,
12591    pub expression: Box<Expression>,
12592    #[serde(default)]
12593    pub flag: Option<Box<Expression>>,
12594}
12595
12596/// RegexpFullMatch
12597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12598#[cfg_attr(feature = "bindings", derive(TS))]
12599pub struct RegexpFullMatch {
12600    pub this: Box<Expression>,
12601    pub expression: Box<Expression>,
12602    #[serde(default)]
12603    pub options: Vec<Expression>,
12604}
12605
12606/// RegexpInstr
12607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12608#[cfg_attr(feature = "bindings", derive(TS))]
12609pub struct RegexpInstr {
12610    pub this: Box<Expression>,
12611    pub expression: Box<Expression>,
12612    #[serde(default)]
12613    pub position: Option<Box<Expression>>,
12614    #[serde(default)]
12615    pub occurrence: Option<Box<Expression>>,
12616    #[serde(default)]
12617    pub option: Option<Box<Expression>>,
12618    #[serde(default)]
12619    pub parameters: Option<Box<Expression>>,
12620    #[serde(default)]
12621    pub group: Option<Box<Expression>>,
12622}
12623
12624/// RegexpSplit
12625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12626#[cfg_attr(feature = "bindings", derive(TS))]
12627pub struct RegexpSplit {
12628    pub this: Box<Expression>,
12629    pub expression: Box<Expression>,
12630    #[serde(default)]
12631    pub limit: Option<Box<Expression>>,
12632}
12633
12634/// RegexpCount
12635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12636#[cfg_attr(feature = "bindings", derive(TS))]
12637pub struct RegexpCount {
12638    pub this: Box<Expression>,
12639    pub expression: Box<Expression>,
12640    #[serde(default)]
12641    pub position: Option<Box<Expression>>,
12642    #[serde(default)]
12643    pub parameters: Option<Box<Expression>>,
12644}
12645
12646/// RegrValx
12647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12648#[cfg_attr(feature = "bindings", derive(TS))]
12649pub struct RegrValx {
12650    pub this: Box<Expression>,
12651    pub expression: Box<Expression>,
12652}
12653
12654/// RegrValy
12655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12656#[cfg_attr(feature = "bindings", derive(TS))]
12657pub struct RegrValy {
12658    pub this: Box<Expression>,
12659    pub expression: Box<Expression>,
12660}
12661
12662/// RegrAvgy
12663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12664#[cfg_attr(feature = "bindings", derive(TS))]
12665pub struct RegrAvgy {
12666    pub this: Box<Expression>,
12667    pub expression: Box<Expression>,
12668}
12669
12670/// RegrAvgx
12671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12672#[cfg_attr(feature = "bindings", derive(TS))]
12673pub struct RegrAvgx {
12674    pub this: Box<Expression>,
12675    pub expression: Box<Expression>,
12676}
12677
12678/// RegrCount
12679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12680#[cfg_attr(feature = "bindings", derive(TS))]
12681pub struct RegrCount {
12682    pub this: Box<Expression>,
12683    pub expression: Box<Expression>,
12684}
12685
12686/// RegrIntercept
12687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12688#[cfg_attr(feature = "bindings", derive(TS))]
12689pub struct RegrIntercept {
12690    pub this: Box<Expression>,
12691    pub expression: Box<Expression>,
12692}
12693
12694/// RegrR2
12695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12696#[cfg_attr(feature = "bindings", derive(TS))]
12697pub struct RegrR2 {
12698    pub this: Box<Expression>,
12699    pub expression: Box<Expression>,
12700}
12701
12702/// RegrSxx
12703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12704#[cfg_attr(feature = "bindings", derive(TS))]
12705pub struct RegrSxx {
12706    pub this: Box<Expression>,
12707    pub expression: Box<Expression>,
12708}
12709
12710/// RegrSxy
12711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12712#[cfg_attr(feature = "bindings", derive(TS))]
12713pub struct RegrSxy {
12714    pub this: Box<Expression>,
12715    pub expression: Box<Expression>,
12716}
12717
12718/// RegrSyy
12719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12720#[cfg_attr(feature = "bindings", derive(TS))]
12721pub struct RegrSyy {
12722    pub this: Box<Expression>,
12723    pub expression: Box<Expression>,
12724}
12725
12726/// RegrSlope
12727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12728#[cfg_attr(feature = "bindings", derive(TS))]
12729pub struct RegrSlope {
12730    pub this: Box<Expression>,
12731    pub expression: Box<Expression>,
12732}
12733
12734/// SafeAdd
12735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12736#[cfg_attr(feature = "bindings", derive(TS))]
12737pub struct SafeAdd {
12738    pub this: Box<Expression>,
12739    pub expression: Box<Expression>,
12740}
12741
12742/// SafeDivide
12743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12744#[cfg_attr(feature = "bindings", derive(TS))]
12745pub struct SafeDivide {
12746    pub this: Box<Expression>,
12747    pub expression: Box<Expression>,
12748}
12749
12750/// SafeMultiply
12751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12752#[cfg_attr(feature = "bindings", derive(TS))]
12753pub struct SafeMultiply {
12754    pub this: Box<Expression>,
12755    pub expression: Box<Expression>,
12756}
12757
12758/// SafeSubtract
12759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12760#[cfg_attr(feature = "bindings", derive(TS))]
12761pub struct SafeSubtract {
12762    pub this: Box<Expression>,
12763    pub expression: Box<Expression>,
12764}
12765
12766/// SHA2
12767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12768#[cfg_attr(feature = "bindings", derive(TS))]
12769pub struct SHA2 {
12770    pub this: Box<Expression>,
12771    #[serde(default)]
12772    pub length: Option<i64>,
12773}
12774
12775/// SHA2Digest
12776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12777#[cfg_attr(feature = "bindings", derive(TS))]
12778pub struct SHA2Digest {
12779    pub this: Box<Expression>,
12780    #[serde(default)]
12781    pub length: Option<i64>,
12782}
12783
12784/// SortArray
12785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12786#[cfg_attr(feature = "bindings", derive(TS))]
12787pub struct SortArray {
12788    pub this: Box<Expression>,
12789    #[serde(default)]
12790    pub asc: Option<Box<Expression>>,
12791    #[serde(default)]
12792    pub nulls_first: Option<Box<Expression>>,
12793}
12794
12795/// SplitPart
12796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12797#[cfg_attr(feature = "bindings", derive(TS))]
12798pub struct SplitPart {
12799    pub this: Box<Expression>,
12800    #[serde(default)]
12801    pub delimiter: Option<Box<Expression>>,
12802    #[serde(default)]
12803    pub part_index: Option<Box<Expression>>,
12804}
12805
12806/// SUBSTRING_INDEX(str, delim, count)
12807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12808#[cfg_attr(feature = "bindings", derive(TS))]
12809pub struct SubstringIndex {
12810    pub this: Box<Expression>,
12811    #[serde(default)]
12812    pub delimiter: Option<Box<Expression>>,
12813    #[serde(default)]
12814    pub count: Option<Box<Expression>>,
12815}
12816
12817/// StandardHash
12818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12819#[cfg_attr(feature = "bindings", derive(TS))]
12820pub struct StandardHash {
12821    pub this: Box<Expression>,
12822    #[serde(default)]
12823    pub expression: Option<Box<Expression>>,
12824}
12825
12826/// StrPosition
12827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12828#[cfg_attr(feature = "bindings", derive(TS))]
12829pub struct StrPosition {
12830    pub this: Box<Expression>,
12831    #[serde(default)]
12832    pub substr: Option<Box<Expression>>,
12833    #[serde(default)]
12834    pub position: Option<Box<Expression>>,
12835    #[serde(default)]
12836    pub occurrence: Option<Box<Expression>>,
12837}
12838
12839/// Search
12840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12841#[cfg_attr(feature = "bindings", derive(TS))]
12842pub struct Search {
12843    pub this: Box<Expression>,
12844    pub expression: Box<Expression>,
12845    #[serde(default)]
12846    pub json_scope: Option<Box<Expression>>,
12847    #[serde(default)]
12848    pub analyzer: Option<Box<Expression>>,
12849    #[serde(default)]
12850    pub analyzer_options: Option<Box<Expression>>,
12851    #[serde(default)]
12852    pub search_mode: Option<Box<Expression>>,
12853}
12854
12855/// SearchIp
12856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12857#[cfg_attr(feature = "bindings", derive(TS))]
12858pub struct SearchIp {
12859    pub this: Box<Expression>,
12860    pub expression: Box<Expression>,
12861}
12862
12863/// StrToDate
12864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12865#[cfg_attr(feature = "bindings", derive(TS))]
12866pub struct StrToDate {
12867    pub this: Box<Expression>,
12868    #[serde(default)]
12869    pub format: Option<String>,
12870    #[serde(default)]
12871    pub safe: Option<Box<Expression>>,
12872}
12873
12874/// StrToTime
12875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12876#[cfg_attr(feature = "bindings", derive(TS))]
12877pub struct StrToTime {
12878    pub this: Box<Expression>,
12879    pub format: String,
12880    #[serde(default)]
12881    pub zone: Option<Box<Expression>>,
12882    #[serde(default)]
12883    pub safe: Option<Box<Expression>>,
12884    #[serde(default)]
12885    pub target_type: Option<Box<Expression>>,
12886}
12887
12888/// StrToUnix
12889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12890#[cfg_attr(feature = "bindings", derive(TS))]
12891pub struct StrToUnix {
12892    #[serde(default)]
12893    pub this: Option<Box<Expression>>,
12894    #[serde(default)]
12895    pub format: Option<String>,
12896}
12897
12898/// StrToMap
12899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12900#[cfg_attr(feature = "bindings", derive(TS))]
12901pub struct StrToMap {
12902    pub this: Box<Expression>,
12903    #[serde(default)]
12904    pub pair_delim: Option<Box<Expression>>,
12905    #[serde(default)]
12906    pub key_value_delim: Option<Box<Expression>>,
12907    #[serde(default)]
12908    pub duplicate_resolution_callback: Option<Box<Expression>>,
12909}
12910
12911/// NumberToStr
12912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12913#[cfg_attr(feature = "bindings", derive(TS))]
12914pub struct NumberToStr {
12915    pub this: Box<Expression>,
12916    pub format: String,
12917    #[serde(default)]
12918    pub culture: Option<Box<Expression>>,
12919}
12920
12921/// FromBase
12922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12923#[cfg_attr(feature = "bindings", derive(TS))]
12924pub struct FromBase {
12925    pub this: Box<Expression>,
12926    pub expression: Box<Expression>,
12927}
12928
12929/// Stuff
12930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12931#[cfg_attr(feature = "bindings", derive(TS))]
12932pub struct Stuff {
12933    pub this: Box<Expression>,
12934    #[serde(default)]
12935    pub start: Option<Box<Expression>>,
12936    #[serde(default)]
12937    pub length: Option<i64>,
12938    pub expression: Box<Expression>,
12939}
12940
12941/// TimeToStr
12942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12943#[cfg_attr(feature = "bindings", derive(TS))]
12944pub struct TimeToStr {
12945    pub this: Box<Expression>,
12946    pub format: String,
12947    #[serde(default)]
12948    pub culture: Option<Box<Expression>>,
12949    #[serde(default)]
12950    pub zone: Option<Box<Expression>>,
12951}
12952
12953/// TimeStrToTime
12954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12955#[cfg_attr(feature = "bindings", derive(TS))]
12956pub struct TimeStrToTime {
12957    pub this: Box<Expression>,
12958    #[serde(default)]
12959    pub zone: Option<Box<Expression>>,
12960}
12961
12962/// TsOrDsAdd
12963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12964#[cfg_attr(feature = "bindings", derive(TS))]
12965pub struct TsOrDsAdd {
12966    pub this: Box<Expression>,
12967    pub expression: Box<Expression>,
12968    #[serde(default)]
12969    pub unit: Option<String>,
12970    #[serde(default)]
12971    pub return_type: Option<Box<Expression>>,
12972}
12973
12974/// TsOrDsDiff
12975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12976#[cfg_attr(feature = "bindings", derive(TS))]
12977pub struct TsOrDsDiff {
12978    pub this: Box<Expression>,
12979    pub expression: Box<Expression>,
12980    #[serde(default)]
12981    pub unit: Option<String>,
12982}
12983
12984/// TsOrDsToDate
12985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12986#[cfg_attr(feature = "bindings", derive(TS))]
12987pub struct TsOrDsToDate {
12988    pub this: Box<Expression>,
12989    #[serde(default)]
12990    pub format: Option<String>,
12991    #[serde(default)]
12992    pub safe: Option<Box<Expression>>,
12993}
12994
12995/// TsOrDsToTime
12996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12997#[cfg_attr(feature = "bindings", derive(TS))]
12998pub struct TsOrDsToTime {
12999    pub this: Box<Expression>,
13000    #[serde(default)]
13001    pub format: Option<String>,
13002    #[serde(default)]
13003    pub safe: Option<Box<Expression>>,
13004}
13005
13006/// Unhex
13007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13008#[cfg_attr(feature = "bindings", derive(TS))]
13009pub struct Unhex {
13010    pub this: Box<Expression>,
13011    #[serde(default)]
13012    pub expression: Option<Box<Expression>>,
13013}
13014
13015/// Uniform
13016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13017#[cfg_attr(feature = "bindings", derive(TS))]
13018pub struct Uniform {
13019    pub this: Box<Expression>,
13020    pub expression: Box<Expression>,
13021    #[serde(default)]
13022    pub gen: Option<Box<Expression>>,
13023    #[serde(default)]
13024    pub seed: Option<Box<Expression>>,
13025}
13026
13027/// UnixToStr
13028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13029#[cfg_attr(feature = "bindings", derive(TS))]
13030pub struct UnixToStr {
13031    pub this: Box<Expression>,
13032    #[serde(default)]
13033    pub format: Option<String>,
13034}
13035
13036/// UnixToTime
13037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13038#[cfg_attr(feature = "bindings", derive(TS))]
13039pub struct UnixToTime {
13040    pub this: Box<Expression>,
13041    #[serde(default)]
13042    pub scale: Option<i64>,
13043    #[serde(default)]
13044    pub zone: Option<Box<Expression>>,
13045    #[serde(default)]
13046    pub hours: Option<Box<Expression>>,
13047    #[serde(default)]
13048    pub minutes: Option<Box<Expression>>,
13049    #[serde(default)]
13050    pub format: Option<String>,
13051    #[serde(default)]
13052    pub target_type: Option<Box<Expression>>,
13053}
13054
13055/// Uuid
13056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13057#[cfg_attr(feature = "bindings", derive(TS))]
13058pub struct Uuid {
13059    #[serde(default)]
13060    pub this: Option<Box<Expression>>,
13061    #[serde(default)]
13062    pub name: Option<String>,
13063    #[serde(default)]
13064    pub is_string: Option<Box<Expression>>,
13065}
13066
13067/// TimestampFromParts
13068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13069#[cfg_attr(feature = "bindings", derive(TS))]
13070pub struct TimestampFromParts {
13071    #[serde(default)]
13072    pub zone: Option<Box<Expression>>,
13073    #[serde(default)]
13074    pub milli: Option<Box<Expression>>,
13075    #[serde(default)]
13076    pub this: Option<Box<Expression>>,
13077    #[serde(default)]
13078    pub expression: Option<Box<Expression>>,
13079}
13080
13081/// TimestampTzFromParts
13082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13083#[cfg_attr(feature = "bindings", derive(TS))]
13084pub struct TimestampTzFromParts {
13085    #[serde(default)]
13086    pub zone: Option<Box<Expression>>,
13087}
13088
13089/// Corr
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct Corr {
13093    pub this: Box<Expression>,
13094    pub expression: Box<Expression>,
13095    #[serde(default)]
13096    pub null_on_zero_variance: Option<Box<Expression>>,
13097}
13098
13099/// WidthBucket
13100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13101#[cfg_attr(feature = "bindings", derive(TS))]
13102pub struct WidthBucket {
13103    pub this: Box<Expression>,
13104    #[serde(default)]
13105    pub min_value: Option<Box<Expression>>,
13106    #[serde(default)]
13107    pub max_value: Option<Box<Expression>>,
13108    #[serde(default)]
13109    pub num_buckets: Option<Box<Expression>>,
13110    #[serde(default)]
13111    pub threshold: Option<Box<Expression>>,
13112}
13113
13114/// CovarSamp
13115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13116#[cfg_attr(feature = "bindings", derive(TS))]
13117pub struct CovarSamp {
13118    pub this: Box<Expression>,
13119    pub expression: Box<Expression>,
13120}
13121
13122/// CovarPop
13123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13124#[cfg_attr(feature = "bindings", derive(TS))]
13125pub struct CovarPop {
13126    pub this: Box<Expression>,
13127    pub expression: Box<Expression>,
13128}
13129
13130/// Week
13131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13132#[cfg_attr(feature = "bindings", derive(TS))]
13133pub struct Week {
13134    pub this: Box<Expression>,
13135    #[serde(default)]
13136    pub mode: Option<Box<Expression>>,
13137}
13138
13139/// XMLElement
13140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13141#[cfg_attr(feature = "bindings", derive(TS))]
13142pub struct XMLElement {
13143    pub this: Box<Expression>,
13144    #[serde(default)]
13145    pub expressions: Vec<Expression>,
13146    #[serde(default)]
13147    pub evalname: Option<Box<Expression>>,
13148}
13149
13150/// XMLGet
13151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13152#[cfg_attr(feature = "bindings", derive(TS))]
13153pub struct XMLGet {
13154    pub this: Box<Expression>,
13155    pub expression: Box<Expression>,
13156    #[serde(default)]
13157    pub instance: Option<Box<Expression>>,
13158}
13159
13160/// XMLTable
13161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13162#[cfg_attr(feature = "bindings", derive(TS))]
13163pub struct XMLTable {
13164    pub this: Box<Expression>,
13165    #[serde(default)]
13166    pub namespaces: Option<Box<Expression>>,
13167    #[serde(default)]
13168    pub passing: Option<Box<Expression>>,
13169    #[serde(default)]
13170    pub columns: Vec<Expression>,
13171    #[serde(default)]
13172    pub by_ref: Option<Box<Expression>>,
13173}
13174
13175/// XMLKeyValueOption
13176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13177#[cfg_attr(feature = "bindings", derive(TS))]
13178pub struct XMLKeyValueOption {
13179    pub this: Box<Expression>,
13180    #[serde(default)]
13181    pub expression: Option<Box<Expression>>,
13182}
13183
13184/// Zipf
13185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13186#[cfg_attr(feature = "bindings", derive(TS))]
13187pub struct Zipf {
13188    pub this: Box<Expression>,
13189    #[serde(default)]
13190    pub elementcount: Option<Box<Expression>>,
13191    #[serde(default)]
13192    pub gen: Option<Box<Expression>>,
13193}
13194
13195/// Merge
13196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13197#[cfg_attr(feature = "bindings", derive(TS))]
13198pub struct Merge {
13199    pub this: Box<Expression>,
13200    pub using: Box<Expression>,
13201    #[serde(default)]
13202    pub on: Option<Box<Expression>>,
13203    #[serde(default)]
13204    pub using_cond: Option<Box<Expression>>,
13205    #[serde(default)]
13206    pub whens: Option<Box<Expression>>,
13207    #[serde(default)]
13208    pub with_: Option<Box<Expression>>,
13209    #[serde(default)]
13210    pub returning: Option<Box<Expression>>,
13211}
13212
13213/// When
13214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13215#[cfg_attr(feature = "bindings", derive(TS))]
13216pub struct When {
13217    #[serde(default)]
13218    pub matched: Option<Box<Expression>>,
13219    #[serde(default)]
13220    pub source: Option<Box<Expression>>,
13221    #[serde(default)]
13222    pub condition: Option<Box<Expression>>,
13223    pub then: Box<Expression>,
13224}
13225
13226/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
13227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13228#[cfg_attr(feature = "bindings", derive(TS))]
13229pub struct Whens {
13230    #[serde(default)]
13231    pub expressions: Vec<Expression>,
13232}
13233
13234/// NextValueFor
13235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13236#[cfg_attr(feature = "bindings", derive(TS))]
13237pub struct NextValueFor {
13238    pub this: Box<Expression>,
13239    #[serde(default)]
13240    pub order: Option<Box<Expression>>,
13241}
13242
13243#[cfg(test)]
13244mod tests {
13245    use super::*;
13246
13247    #[test]
13248    #[cfg(feature = "bindings")]
13249    fn export_typescript_types() {
13250        // This test exports TypeScript types to the generated directory
13251        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
13252        Expression::export_all(&ts_rs::Config::default())
13253            .expect("Failed to export Expression types");
13254    }
13255
13256    #[test]
13257    fn test_simple_select_builder() {
13258        let select = Select::new()
13259            .column(Expression::star())
13260            .from(Expression::Table(TableRef::new("users")));
13261
13262        assert_eq!(select.expressions.len(), 1);
13263        assert!(select.from.is_some());
13264    }
13265
13266    #[test]
13267    fn test_expression_alias() {
13268        let expr = Expression::column("id").alias("user_id");
13269
13270        match expr {
13271            Expression::Alias(a) => {
13272                assert_eq!(a.alias.name, "user_id");
13273            }
13274            _ => panic!("Expected Alias"),
13275        }
13276    }
13277
13278    #[test]
13279    fn test_literal_creation() {
13280        let num = Expression::number(42);
13281        let str = Expression::string("hello");
13282
13283        match num {
13284            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
13285            _ => panic!("Expected Number"),
13286        }
13287
13288        match str {
13289            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
13290            _ => panic!("Expected String"),
13291        }
13292    }
13293
13294    #[test]
13295    fn test_expression_sql() {
13296        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
13297        assert_eq!(expr.sql(), "SELECT 1 + 2");
13298    }
13299
13300    #[test]
13301    fn test_expression_sql_for() {
13302        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
13303        let sql = expr.sql_for(crate::DialectType::Generic);
13304        // Generic mode normalizes IF() to CASE WHEN
13305        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
13306    }
13307}