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(Box<Column>),
89    Table(Box<TableRef>),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // 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    /// Create a `Column` variant, boxing the value automatically.
1105    #[inline]
1106    pub fn boxed_column(col: Column) -> Self {
1107        Expression::Column(Box::new(col))
1108    }
1109
1110    /// Create a `Table` variant, boxing the value automatically.
1111    #[inline]
1112    pub fn boxed_table(t: TableRef) -> Self {
1113        Expression::Table(Box::new(t))
1114    }
1115
1116    /// Returns `true` if this expression is a valid top-level SQL statement.
1117    ///
1118    /// Bare expressions like identifiers, literals, and function calls are not
1119    /// valid statements. This is used by `validate()` to reject inputs like
1120    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1121    /// plus the bare identifier `doo`.
1122    pub fn is_statement(&self) -> bool {
1123        match self {
1124            // Queries
1125            Expression::Select(_)
1126            | Expression::Union(_)
1127            | Expression::Intersect(_)
1128            | Expression::Except(_)
1129            | Expression::Subquery(_)
1130            | Expression::Values(_)
1131            | Expression::PipeOperator(_)
1132
1133            // DML
1134            | Expression::Insert(_)
1135            | Expression::Update(_)
1136            | Expression::Delete(_)
1137            | Expression::Copy(_)
1138            | Expression::Put(_)
1139            | Expression::Merge(_)
1140
1141            // DDL
1142            | Expression::CreateTable(_)
1143            | Expression::DropTable(_)
1144            | Expression::AlterTable(_)
1145            | Expression::CreateIndex(_)
1146            | Expression::DropIndex(_)
1147            | Expression::CreateView(_)
1148            | Expression::DropView(_)
1149            | Expression::AlterView(_)
1150            | Expression::AlterIndex(_)
1151            | Expression::Truncate(_)
1152            | Expression::TruncateTable(_)
1153            | Expression::CreateSchema(_)
1154            | Expression::DropSchema(_)
1155            | Expression::DropNamespace(_)
1156            | Expression::CreateDatabase(_)
1157            | Expression::DropDatabase(_)
1158            | Expression::CreateFunction(_)
1159            | Expression::DropFunction(_)
1160            | Expression::CreateProcedure(_)
1161            | Expression::DropProcedure(_)
1162            | Expression::CreateSequence(_)
1163            | Expression::DropSequence(_)
1164            | Expression::AlterSequence(_)
1165            | Expression::CreateTrigger(_)
1166            | Expression::DropTrigger(_)
1167            | Expression::CreateType(_)
1168            | Expression::DropType(_)
1169            | Expression::Comment(_)
1170
1171            // Session/Transaction/Control
1172            | Expression::Use(_)
1173            | Expression::Set(_)
1174            | Expression::SetStatement(_)
1175            | Expression::Transaction(_)
1176            | Expression::Commit(_)
1177            | Expression::Rollback(_)
1178            | Expression::Grant(_)
1179            | Expression::Revoke(_)
1180            | Expression::Cache(_)
1181            | Expression::Uncache(_)
1182            | Expression::LoadData(_)
1183            | Expression::Pragma(_)
1184            | Expression::Describe(_)
1185            | Expression::Show(_)
1186            | Expression::Kill(_)
1187            | Expression::Execute(_)
1188            | Expression::Declare(_)
1189            | Expression::Refresh(_)
1190            | Expression::AlterSession(_)
1191            | Expression::LockingStatement(_)
1192
1193            // Analyze
1194            | Expression::Analyze(_)
1195            | Expression::AnalyzeStatistics(_)
1196            | Expression::AnalyzeHistogram(_)
1197            | Expression::AnalyzeSample(_)
1198            | Expression::AnalyzeListChainedRows(_)
1199            | Expression::AnalyzeDelete(_)
1200
1201            // Attach/Detach/Install/Summarize
1202            | Expression::Attach(_)
1203            | Expression::Detach(_)
1204            | Expression::Install(_)
1205            | Expression::Summarize(_)
1206
1207            // Pivot at statement level
1208            | Expression::Pivot(_)
1209            | Expression::Unpivot(_)
1210
1211            // Command (raw/unparsed statements)
1212            | Expression::Command(_)
1213            | Expression::Raw(_)
1214
1215            // Return statement
1216            | Expression::ReturnStmt(_) => true,
1217
1218            // Annotated wraps another expression with comments — check inner
1219            Expression::Annotated(a) => a.this.is_statement(),
1220
1221            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1222            Expression::Alias(a) => a.this.is_statement(),
1223
1224            // Everything else (identifiers, literals, operators, functions, etc.)
1225            _ => false,
1226        }
1227    }
1228
1229    /// Create a literal number expression from an integer.
1230    pub fn number(n: i64) -> Self {
1231        Expression::Literal(Literal::Number(n.to_string()))
1232    }
1233
1234    /// Create a single-quoted literal string expression.
1235    pub fn string(s: impl Into<String>) -> Self {
1236        Expression::Literal(Literal::String(s.into()))
1237    }
1238
1239    /// Create a literal number expression from a float.
1240    pub fn float(f: f64) -> Self {
1241        Expression::Literal(Literal::Number(f.to_string()))
1242    }
1243
1244    /// Get the inferred type annotation, if present.
1245    ///
1246    /// For value-producing expressions with an `inferred_type` field, returns
1247    /// the stored type. For literals and boolean constants, computes the type
1248    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1249    pub fn inferred_type(&self) -> Option<&DataType> {
1250        match self {
1251            // Structs with inferred_type field
1252            Expression::And(op)
1253            | Expression::Or(op)
1254            | Expression::Add(op)
1255            | Expression::Sub(op)
1256            | Expression::Mul(op)
1257            | Expression::Div(op)
1258            | Expression::Mod(op)
1259            | Expression::Eq(op)
1260            | Expression::Neq(op)
1261            | Expression::Lt(op)
1262            | Expression::Lte(op)
1263            | Expression::Gt(op)
1264            | Expression::Gte(op)
1265            | Expression::Concat(op)
1266            | Expression::BitwiseAnd(op)
1267            | Expression::BitwiseOr(op)
1268            | Expression::BitwiseXor(op)
1269            | Expression::Adjacent(op)
1270            | Expression::TsMatch(op)
1271            | Expression::PropertyEQ(op)
1272            | Expression::ArrayContainsAll(op)
1273            | Expression::ArrayContainedBy(op)
1274            | Expression::ArrayOverlaps(op)
1275            | Expression::JSONBContainsAllTopKeys(op)
1276            | Expression::JSONBContainsAnyTopKeys(op)
1277            | Expression::JSONBDeleteAtPath(op)
1278            | Expression::ExtendsLeft(op)
1279            | Expression::ExtendsRight(op)
1280            | Expression::Is(op)
1281            | Expression::MemberOf(op)
1282            | Expression::Match(op)
1283            | Expression::NullSafeEq(op)
1284            | Expression::NullSafeNeq(op)
1285            | Expression::Glob(op)
1286            | Expression::BitwiseLeftShift(op)
1287            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1288
1289            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1290                op.inferred_type.as_ref()
1291            }
1292
1293            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1294
1295            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1296                c.inferred_type.as_ref()
1297            }
1298
1299            Expression::Column(c) => c.inferred_type.as_ref(),
1300            Expression::Function(f) => f.inferred_type.as_ref(),
1301            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1302            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1303            Expression::Case(c) => c.inferred_type.as_ref(),
1304            Expression::Subquery(s) => s.inferred_type.as_ref(),
1305            Expression::Alias(a) => a.inferred_type.as_ref(),
1306            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1307            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1308            Expression::Count(f) => f.inferred_type.as_ref(),
1309            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1310            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1311            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1312            Expression::SumIf(f) => f.inferred_type.as_ref(),
1313
1314            // UnaryFunc variants
1315            Expression::Upper(f)
1316            | Expression::Lower(f)
1317            | Expression::Length(f)
1318            | Expression::LTrim(f)
1319            | Expression::RTrim(f)
1320            | Expression::Reverse(f)
1321            | Expression::Abs(f)
1322            | Expression::Sqrt(f)
1323            | Expression::Cbrt(f)
1324            | Expression::Ln(f)
1325            | Expression::Exp(f)
1326            | Expression::Sign(f)
1327            | Expression::Date(f)
1328            | Expression::Time(f)
1329            | Expression::Initcap(f)
1330            | Expression::Ascii(f)
1331            | Expression::Chr(f)
1332            | Expression::Soundex(f)
1333            | Expression::ByteLength(f)
1334            | Expression::Hex(f)
1335            | Expression::LowerHex(f)
1336            | Expression::Unicode(f)
1337            | Expression::Typeof(f)
1338            | Expression::Explode(f)
1339            | Expression::ExplodeOuter(f)
1340            | Expression::MapFromEntries(f)
1341            | Expression::MapKeys(f)
1342            | Expression::MapValues(f)
1343            | Expression::ArrayLength(f)
1344            | Expression::ArraySize(f)
1345            | Expression::Cardinality(f)
1346            | Expression::ArrayReverse(f)
1347            | Expression::ArrayDistinct(f)
1348            | Expression::ArrayFlatten(f)
1349            | Expression::ArrayCompact(f)
1350            | Expression::ToArray(f)
1351            | Expression::JsonArrayLength(f)
1352            | Expression::JsonKeys(f)
1353            | Expression::JsonType(f)
1354            | Expression::ParseJson(f)
1355            | Expression::ToJson(f)
1356            | Expression::Radians(f)
1357            | Expression::Degrees(f)
1358            | Expression::Sin(f)
1359            | Expression::Cos(f)
1360            | Expression::Tan(f)
1361            | Expression::Asin(f)
1362            | Expression::Acos(f)
1363            | Expression::Atan(f)
1364            | Expression::IsNan(f)
1365            | Expression::IsInf(f)
1366            | Expression::Year(f)
1367            | Expression::Month(f)
1368            | Expression::Day(f)
1369            | Expression::Hour(f)
1370            | Expression::Minute(f)
1371            | Expression::Second(f)
1372            | Expression::DayOfWeek(f)
1373            | Expression::DayOfWeekIso(f)
1374            | Expression::DayOfMonth(f)
1375            | Expression::DayOfYear(f)
1376            | Expression::WeekOfYear(f)
1377            | Expression::Quarter(f)
1378            | Expression::Epoch(f)
1379            | Expression::EpochMs(f)
1380            | Expression::BitwiseCount(f)
1381            | Expression::DateFromUnixDate(f)
1382            | Expression::UnixDate(f)
1383            | Expression::UnixSeconds(f)
1384            | Expression::UnixMillis(f)
1385            | Expression::UnixMicros(f)
1386            | Expression::TimeStrToDate(f)
1387            | Expression::DateToDi(f)
1388            | Expression::DiToDate(f)
1389            | Expression::TsOrDiToDi(f)
1390            | Expression::TsOrDsToDatetime(f)
1391            | Expression::TsOrDsToTimestamp(f)
1392            | Expression::YearOfWeek(f)
1393            | Expression::YearOfWeekIso(f)
1394            | Expression::SHA(f)
1395            | Expression::SHA1Digest(f)
1396            | Expression::TimeToUnix(f)
1397            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1398
1399            // BinaryFunc variants
1400            Expression::Power(f)
1401            | Expression::NullIf(f)
1402            | Expression::IfNull(f)
1403            | Expression::Nvl(f)
1404            | Expression::Contains(f)
1405            | Expression::StartsWith(f)
1406            | Expression::EndsWith(f)
1407            | Expression::Levenshtein(f)
1408            | Expression::ModFunc(f)
1409            | Expression::IntDiv(f)
1410            | Expression::Atan2(f)
1411            | Expression::AddMonths(f)
1412            | Expression::MonthsBetween(f)
1413            | Expression::NextDay(f)
1414            | Expression::UnixToTimeStr(f)
1415            | Expression::ArrayContains(f)
1416            | Expression::ArrayPosition(f)
1417            | Expression::ArrayAppend(f)
1418            | Expression::ArrayPrepend(f)
1419            | Expression::ArrayUnion(f)
1420            | Expression::ArrayExcept(f)
1421            | Expression::ArrayRemove(f)
1422            | Expression::StarMap(f)
1423            | Expression::MapFromArrays(f)
1424            | Expression::MapContainsKey(f)
1425            | Expression::ElementAt(f)
1426            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1427
1428            // VarArgFunc variants
1429            Expression::Coalesce(f)
1430            | Expression::Greatest(f)
1431            | Expression::Least(f)
1432            | Expression::ArrayConcat(f)
1433            | Expression::ArrayIntersect(f)
1434            | Expression::ArrayZip(f)
1435            | Expression::MapConcat(f)
1436            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1437
1438            // AggFunc variants
1439            Expression::Sum(f)
1440            | Expression::Avg(f)
1441            | Expression::Min(f)
1442            | Expression::Max(f)
1443            | Expression::ArrayAgg(f)
1444            | Expression::CountIf(f)
1445            | Expression::Stddev(f)
1446            | Expression::StddevPop(f)
1447            | Expression::StddevSamp(f)
1448            | Expression::Variance(f)
1449            | Expression::VarPop(f)
1450            | Expression::VarSamp(f)
1451            | Expression::Median(f)
1452            | Expression::Mode(f)
1453            | Expression::First(f)
1454            | Expression::Last(f)
1455            | Expression::AnyValue(f)
1456            | Expression::ApproxDistinct(f)
1457            | Expression::ApproxCountDistinct(f)
1458            | Expression::LogicalAnd(f)
1459            | Expression::LogicalOr(f)
1460            | Expression::Skewness(f)
1461            | Expression::ArrayConcatAgg(f)
1462            | Expression::ArrayUniqueAgg(f)
1463            | Expression::BoolXorAgg(f)
1464            | Expression::BitwiseAndAgg(f)
1465            | Expression::BitwiseOrAgg(f)
1466            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1467
1468            // Everything else: no inferred_type field
1469            _ => None,
1470        }
1471    }
1472
1473    /// Set the inferred type annotation on this expression.
1474    ///
1475    /// Only has an effect on value-producing expressions with an `inferred_type`
1476    /// field. For other expression types, this is a no-op.
1477    pub fn set_inferred_type(&mut self, dt: DataType) {
1478        match self {
1479            Expression::And(op)
1480            | Expression::Or(op)
1481            | Expression::Add(op)
1482            | Expression::Sub(op)
1483            | Expression::Mul(op)
1484            | Expression::Div(op)
1485            | Expression::Mod(op)
1486            | Expression::Eq(op)
1487            | Expression::Neq(op)
1488            | Expression::Lt(op)
1489            | Expression::Lte(op)
1490            | Expression::Gt(op)
1491            | Expression::Gte(op)
1492            | Expression::Concat(op)
1493            | Expression::BitwiseAnd(op)
1494            | Expression::BitwiseOr(op)
1495            | Expression::BitwiseXor(op)
1496            | Expression::Adjacent(op)
1497            | Expression::TsMatch(op)
1498            | Expression::PropertyEQ(op)
1499            | Expression::ArrayContainsAll(op)
1500            | Expression::ArrayContainedBy(op)
1501            | Expression::ArrayOverlaps(op)
1502            | Expression::JSONBContainsAllTopKeys(op)
1503            | Expression::JSONBContainsAnyTopKeys(op)
1504            | Expression::JSONBDeleteAtPath(op)
1505            | Expression::ExtendsLeft(op)
1506            | Expression::ExtendsRight(op)
1507            | Expression::Is(op)
1508            | Expression::MemberOf(op)
1509            | Expression::Match(op)
1510            | Expression::NullSafeEq(op)
1511            | Expression::NullSafeNeq(op)
1512            | Expression::Glob(op)
1513            | Expression::BitwiseLeftShift(op)
1514            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1515
1516            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1517                op.inferred_type = Some(dt)
1518            }
1519
1520            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1521
1522            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1523                c.inferred_type = Some(dt)
1524            }
1525
1526            Expression::Column(c) => c.inferred_type = Some(dt),
1527            Expression::Function(f) => f.inferred_type = Some(dt),
1528            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1529            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1530            Expression::Case(c) => c.inferred_type = Some(dt),
1531            Expression::Subquery(s) => s.inferred_type = Some(dt),
1532            Expression::Alias(a) => a.inferred_type = Some(dt),
1533            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1534            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1535            Expression::Count(f) => f.inferred_type = Some(dt),
1536            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1537            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1538            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1539            Expression::SumIf(f) => f.inferred_type = Some(dt),
1540
1541            // UnaryFunc variants
1542            Expression::Upper(f)
1543            | Expression::Lower(f)
1544            | Expression::Length(f)
1545            | Expression::LTrim(f)
1546            | Expression::RTrim(f)
1547            | Expression::Reverse(f)
1548            | Expression::Abs(f)
1549            | Expression::Sqrt(f)
1550            | Expression::Cbrt(f)
1551            | Expression::Ln(f)
1552            | Expression::Exp(f)
1553            | Expression::Sign(f)
1554            | Expression::Date(f)
1555            | Expression::Time(f)
1556            | Expression::Initcap(f)
1557            | Expression::Ascii(f)
1558            | Expression::Chr(f)
1559            | Expression::Soundex(f)
1560            | Expression::ByteLength(f)
1561            | Expression::Hex(f)
1562            | Expression::LowerHex(f)
1563            | Expression::Unicode(f)
1564            | Expression::Typeof(f)
1565            | Expression::Explode(f)
1566            | Expression::ExplodeOuter(f)
1567            | Expression::MapFromEntries(f)
1568            | Expression::MapKeys(f)
1569            | Expression::MapValues(f)
1570            | Expression::ArrayLength(f)
1571            | Expression::ArraySize(f)
1572            | Expression::Cardinality(f)
1573            | Expression::ArrayReverse(f)
1574            | Expression::ArrayDistinct(f)
1575            | Expression::ArrayFlatten(f)
1576            | Expression::ArrayCompact(f)
1577            | Expression::ToArray(f)
1578            | Expression::JsonArrayLength(f)
1579            | Expression::JsonKeys(f)
1580            | Expression::JsonType(f)
1581            | Expression::ParseJson(f)
1582            | Expression::ToJson(f)
1583            | Expression::Radians(f)
1584            | Expression::Degrees(f)
1585            | Expression::Sin(f)
1586            | Expression::Cos(f)
1587            | Expression::Tan(f)
1588            | Expression::Asin(f)
1589            | Expression::Acos(f)
1590            | Expression::Atan(f)
1591            | Expression::IsNan(f)
1592            | Expression::IsInf(f)
1593            | Expression::Year(f)
1594            | Expression::Month(f)
1595            | Expression::Day(f)
1596            | Expression::Hour(f)
1597            | Expression::Minute(f)
1598            | Expression::Second(f)
1599            | Expression::DayOfWeek(f)
1600            | Expression::DayOfWeekIso(f)
1601            | Expression::DayOfMonth(f)
1602            | Expression::DayOfYear(f)
1603            | Expression::WeekOfYear(f)
1604            | Expression::Quarter(f)
1605            | Expression::Epoch(f)
1606            | Expression::EpochMs(f)
1607            | Expression::BitwiseCount(f)
1608            | Expression::DateFromUnixDate(f)
1609            | Expression::UnixDate(f)
1610            | Expression::UnixSeconds(f)
1611            | Expression::UnixMillis(f)
1612            | Expression::UnixMicros(f)
1613            | Expression::TimeStrToDate(f)
1614            | Expression::DateToDi(f)
1615            | Expression::DiToDate(f)
1616            | Expression::TsOrDiToDi(f)
1617            | Expression::TsOrDsToDatetime(f)
1618            | Expression::TsOrDsToTimestamp(f)
1619            | Expression::YearOfWeek(f)
1620            | Expression::YearOfWeekIso(f)
1621            | Expression::SHA(f)
1622            | Expression::SHA1Digest(f)
1623            | Expression::TimeToUnix(f)
1624            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1625
1626            // BinaryFunc variants
1627            Expression::Power(f)
1628            | Expression::NullIf(f)
1629            | Expression::IfNull(f)
1630            | Expression::Nvl(f)
1631            | Expression::Contains(f)
1632            | Expression::StartsWith(f)
1633            | Expression::EndsWith(f)
1634            | Expression::Levenshtein(f)
1635            | Expression::ModFunc(f)
1636            | Expression::IntDiv(f)
1637            | Expression::Atan2(f)
1638            | Expression::AddMonths(f)
1639            | Expression::MonthsBetween(f)
1640            | Expression::NextDay(f)
1641            | Expression::UnixToTimeStr(f)
1642            | Expression::ArrayContains(f)
1643            | Expression::ArrayPosition(f)
1644            | Expression::ArrayAppend(f)
1645            | Expression::ArrayPrepend(f)
1646            | Expression::ArrayUnion(f)
1647            | Expression::ArrayExcept(f)
1648            | Expression::ArrayRemove(f)
1649            | Expression::StarMap(f)
1650            | Expression::MapFromArrays(f)
1651            | Expression::MapContainsKey(f)
1652            | Expression::ElementAt(f)
1653            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1654
1655            // VarArgFunc variants
1656            Expression::Coalesce(f)
1657            | Expression::Greatest(f)
1658            | Expression::Least(f)
1659            | Expression::ArrayConcat(f)
1660            | Expression::ArrayIntersect(f)
1661            | Expression::ArrayZip(f)
1662            | Expression::MapConcat(f)
1663            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1664
1665            // AggFunc variants
1666            Expression::Sum(f)
1667            | Expression::Avg(f)
1668            | Expression::Min(f)
1669            | Expression::Max(f)
1670            | Expression::ArrayAgg(f)
1671            | Expression::CountIf(f)
1672            | Expression::Stddev(f)
1673            | Expression::StddevPop(f)
1674            | Expression::StddevSamp(f)
1675            | Expression::Variance(f)
1676            | Expression::VarPop(f)
1677            | Expression::VarSamp(f)
1678            | Expression::Median(f)
1679            | Expression::Mode(f)
1680            | Expression::First(f)
1681            | Expression::Last(f)
1682            | Expression::AnyValue(f)
1683            | Expression::ApproxDistinct(f)
1684            | Expression::ApproxCountDistinct(f)
1685            | Expression::LogicalAnd(f)
1686            | Expression::LogicalOr(f)
1687            | Expression::Skewness(f)
1688            | Expression::ArrayConcatAgg(f)
1689            | Expression::ArrayUniqueAgg(f)
1690            | Expression::BoolXorAgg(f)
1691            | Expression::BitwiseAndAgg(f)
1692            | Expression::BitwiseOrAgg(f)
1693            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1694
1695            // Expressions without inferred_type field - no-op
1696            _ => {}
1697        }
1698    }
1699
1700    /// Create an unqualified column reference (e.g. `name`).
1701    pub fn column(name: impl Into<String>) -> Self {
1702        Expression::Column(Box::new(Column {
1703            name: Identifier::new(name),
1704            table: None,
1705            join_mark: false,
1706            trailing_comments: Vec::new(),
1707            span: None,
1708            inferred_type: None,
1709        }))
1710    }
1711
1712    /// Create a qualified column reference (`table.column`).
1713    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1714        Expression::Column(Box::new(Column {
1715            name: Identifier::new(column),
1716            table: Some(Identifier::new(table)),
1717            join_mark: false,
1718            trailing_comments: Vec::new(),
1719            span: None,
1720            inferred_type: None,
1721        }))
1722    }
1723
1724    /// Create a bare identifier expression (not a column reference).
1725    pub fn identifier(name: impl Into<String>) -> Self {
1726        Expression::Identifier(Identifier::new(name))
1727    }
1728
1729    /// Create a NULL expression
1730    pub fn null() -> Self {
1731        Expression::Null(Null)
1732    }
1733
1734    /// Create a TRUE expression
1735    pub fn true_() -> Self {
1736        Expression::Boolean(BooleanLiteral { value: true })
1737    }
1738
1739    /// Create a FALSE expression
1740    pub fn false_() -> Self {
1741        Expression::Boolean(BooleanLiteral { value: false })
1742    }
1743
1744    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1745    pub fn star() -> Self {
1746        Expression::Star(Star {
1747            table: None,
1748            except: None,
1749            replace: None,
1750            rename: None,
1751            trailing_comments: Vec::new(),
1752            span: None,
1753        })
1754    }
1755
1756    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1757    pub fn alias(self, name: impl Into<String>) -> Self {
1758        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1759    }
1760
1761    /// Check if this is a SELECT expression
1762    pub fn is_select(&self) -> bool {
1763        matches!(self, Expression::Select(_))
1764    }
1765
1766    /// Try to get as a Select
1767    pub fn as_select(&self) -> Option<&Select> {
1768        match self {
1769            Expression::Select(s) => Some(s),
1770            _ => None,
1771        }
1772    }
1773
1774    /// Try to get as a mutable Select
1775    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1776        match self {
1777            Expression::Select(s) => Some(s),
1778            _ => None,
1779        }
1780    }
1781
1782    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1783    ///
1784    /// Returns an empty string if generation fails. For dialect-specific output,
1785    /// use [`sql_for()`](Self::sql_for) instead.
1786    pub fn sql(&self) -> String {
1787        crate::generator::Generator::sql(self).unwrap_or_default()
1788    }
1789
1790    /// Generate a SQL string for this expression targeting a specific dialect.
1791    ///
1792    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1793    /// syntax variations) are applied automatically.  Returns an empty string if
1794    /// generation fails.
1795    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1796        crate::generate(self, dialect).unwrap_or_default()
1797    }
1798}
1799
1800impl fmt::Display for Expression {
1801    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1802        // Basic display - full SQL generation is in generator module
1803        match self {
1804            Expression::Literal(lit) => write!(f, "{}", lit),
1805            Expression::Identifier(id) => write!(f, "{}", id),
1806            Expression::Column(col) => write!(f, "{}", col),
1807            Expression::Star(_) => write!(f, "*"),
1808            Expression::Null(_) => write!(f, "NULL"),
1809            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1810            Expression::Select(_) => write!(f, "SELECT ..."),
1811            _ => write!(f, "{:?}", self),
1812        }
1813    }
1814}
1815
1816/// Represent a SQL literal value.
1817///
1818/// Numeric values are stored as their original text representation (not parsed
1819/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1820/// preserved across round-trips.
1821///
1822/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1823/// strings, raw strings, etc.) each have a dedicated variant so that the
1824/// generator can emit them with the correct syntax.
1825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1826#[cfg_attr(feature = "bindings", derive(TS))]
1827#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1828pub enum Literal {
1829    /// Single-quoted string literal: `'hello'`
1830    String(String),
1831    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1832    Number(String),
1833    /// Hex string literal: `X'FF'`
1834    HexString(String),
1835    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1836    HexNumber(String),
1837    BitString(String),
1838    /// Byte string: b"..." (BigQuery style)
1839    ByteString(String),
1840    /// National string: N'abc'
1841    NationalString(String),
1842    /// DATE literal: DATE '2024-01-15'
1843    Date(String),
1844    /// TIME literal: TIME '10:30:00'
1845    Time(String),
1846    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1847    Timestamp(String),
1848    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1849    Datetime(String),
1850    /// Triple-quoted string: """...""" or '''...'''
1851    /// Contains (content, quote_char) where quote_char is '"' or '\''
1852    TripleQuotedString(String, char),
1853    /// Escape string: E'...' (PostgreSQL)
1854    EscapeString(String),
1855    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1856    DollarString(String),
1857    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1858    /// In raw strings, backslashes are literal and not escape characters.
1859    /// When converting to a regular string, backslashes must be doubled.
1860    RawString(String),
1861}
1862
1863impl fmt::Display for Literal {
1864    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1865        match self {
1866            Literal::String(s) => write!(f, "'{}'", s),
1867            Literal::Number(n) => write!(f, "{}", n),
1868            Literal::HexString(h) => write!(f, "X'{}'", h),
1869            Literal::HexNumber(h) => write!(f, "0x{}", h),
1870            Literal::BitString(b) => write!(f, "B'{}'", b),
1871            Literal::ByteString(b) => write!(f, "b'{}'", b),
1872            Literal::NationalString(s) => write!(f, "N'{}'", s),
1873            Literal::Date(d) => write!(f, "DATE '{}'", d),
1874            Literal::Time(t) => write!(f, "TIME '{}'", t),
1875            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1876            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1877            Literal::TripleQuotedString(s, q) => {
1878                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1879            }
1880            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1881            Literal::DollarString(s) => write!(f, "$${}$$", s),
1882            Literal::RawString(s) => write!(f, "r'{}'", s),
1883        }
1884    }
1885}
1886
1887/// Boolean literal
1888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1889#[cfg_attr(feature = "bindings", derive(TS))]
1890pub struct BooleanLiteral {
1891    pub value: bool,
1892}
1893
1894/// NULL literal
1895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1896#[cfg_attr(feature = "bindings", derive(TS))]
1897pub struct Null;
1898
1899/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1900///
1901/// The `quoted` flag indicates whether the identifier was originally delimited
1902/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1903/// dialect). The generator uses this flag to decide whether to emit quoting
1904/// characters.
1905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1906#[cfg_attr(feature = "bindings", derive(TS))]
1907pub struct Identifier {
1908    /// The raw text of the identifier, without any quoting characters.
1909    pub name: String,
1910    /// Whether the identifier was quoted in the source SQL.
1911    pub quoted: bool,
1912    #[serde(default)]
1913    pub trailing_comments: Vec<String>,
1914    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1915    #[serde(default, skip_serializing_if = "Option::is_none")]
1916    pub span: Option<Span>,
1917}
1918
1919impl Identifier {
1920    pub fn new(name: impl Into<String>) -> Self {
1921        Self {
1922            name: name.into(),
1923            quoted: false,
1924            trailing_comments: Vec::new(),
1925            span: None,
1926        }
1927    }
1928
1929    pub fn quoted(name: impl Into<String>) -> Self {
1930        Self {
1931            name: name.into(),
1932            quoted: true,
1933            trailing_comments: Vec::new(),
1934            span: None,
1935        }
1936    }
1937
1938    pub fn empty() -> Self {
1939        Self {
1940            name: String::new(),
1941            quoted: false,
1942            trailing_comments: Vec::new(),
1943            span: None,
1944        }
1945    }
1946
1947    pub fn is_empty(&self) -> bool {
1948        self.name.is_empty()
1949    }
1950
1951    /// Set the source span on this identifier
1952    pub fn with_span(mut self, span: Span) -> Self {
1953        self.span = Some(span);
1954        self
1955    }
1956}
1957
1958impl fmt::Display for Identifier {
1959    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1960        if self.quoted {
1961            write!(f, "\"{}\"", self.name)
1962        } else {
1963            write!(f, "{}", self.name)
1964        }
1965    }
1966}
1967
1968/// Represent a column reference, optionally qualified by a table name.
1969///
1970/// Renders as `name` when unqualified, or `table.name` when qualified.
1971/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1972/// convenient construction.
1973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1974#[cfg_attr(feature = "bindings", derive(TS))]
1975pub struct Column {
1976    /// The column name.
1977    pub name: Identifier,
1978    /// Optional table qualifier (e.g. `t` in `t.col`).
1979    pub table: Option<Identifier>,
1980    /// Oracle-style join marker (+) for outer joins
1981    #[serde(default)]
1982    pub join_mark: bool,
1983    /// Trailing comments that appeared after this column reference
1984    #[serde(default)]
1985    pub trailing_comments: Vec<String>,
1986    /// Source position span
1987    #[serde(default, skip_serializing_if = "Option::is_none")]
1988    pub span: Option<Span>,
1989    /// Inferred data type from type annotation
1990    #[serde(default, skip_serializing_if = "Option::is_none")]
1991    pub inferred_type: Option<DataType>,
1992}
1993
1994impl fmt::Display for Column {
1995    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1996        if let Some(table) = &self.table {
1997            write!(f, "{}.{}", table, self.name)
1998        } else {
1999            write!(f, "{}", self.name)
2000        }
2001    }
2002}
2003
2004/// Represent a table reference with optional schema and catalog qualifiers.
2005///
2006/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
2007/// which qualifiers are present. Supports aliases, column alias lists,
2008/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
2009/// several other dialect-specific extensions.
2010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2011#[cfg_attr(feature = "bindings", derive(TS))]
2012pub struct TableRef {
2013    /// The unqualified table name.
2014    pub name: Identifier,
2015    /// Optional schema qualifier (e.g. `public` in `public.users`).
2016    pub schema: Option<Identifier>,
2017    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
2018    pub catalog: Option<Identifier>,
2019    /// Optional table alias (e.g. `t` in `FROM users AS t`).
2020    pub alias: Option<Identifier>,
2021    /// Whether AS keyword was explicitly used for the alias
2022    #[serde(default)]
2023    pub alias_explicit_as: bool,
2024    /// Column aliases for table alias: AS t(c1, c2)
2025    #[serde(default)]
2026    pub column_aliases: Vec<Identifier>,
2027    /// Trailing comments that appeared after this table reference
2028    #[serde(default)]
2029    pub trailing_comments: Vec<String>,
2030    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2031    #[serde(default)]
2032    pub when: Option<Box<HistoricalData>>,
2033    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
2034    #[serde(default)]
2035    pub only: bool,
2036    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
2037    #[serde(default)]
2038    pub final_: bool,
2039    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
2040    #[serde(default, skip_serializing_if = "Option::is_none")]
2041    pub table_sample: Option<Box<Sample>>,
2042    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
2043    #[serde(default)]
2044    pub hints: Vec<Expression>,
2045    /// TSQL: FOR SYSTEM_TIME temporal clause
2046    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
2047    #[serde(default, skip_serializing_if = "Option::is_none")]
2048    pub system_time: Option<String>,
2049    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
2050    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2051    pub partitions: Vec<Identifier>,
2052    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
2053    /// When set, this is used instead of the name field
2054    #[serde(default, skip_serializing_if = "Option::is_none")]
2055    pub identifier_func: Option<Box<Expression>>,
2056    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
2057    #[serde(default, skip_serializing_if = "Option::is_none")]
2058    pub changes: Option<Box<Changes>>,
2059    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
2060    #[serde(default, skip_serializing_if = "Option::is_none")]
2061    pub version: Option<Box<Version>>,
2062    /// Source position span
2063    #[serde(default, skip_serializing_if = "Option::is_none")]
2064    pub span: Option<Span>,
2065}
2066
2067impl TableRef {
2068    pub fn new(name: impl Into<String>) -> Self {
2069        Self {
2070            name: Identifier::new(name),
2071            schema: None,
2072            catalog: None,
2073            alias: None,
2074            alias_explicit_as: false,
2075            column_aliases: Vec::new(),
2076            trailing_comments: Vec::new(),
2077            when: None,
2078            only: false,
2079            final_: false,
2080            table_sample: None,
2081            hints: Vec::new(),
2082            system_time: None,
2083            partitions: Vec::new(),
2084            identifier_func: None,
2085            changes: None,
2086            version: None,
2087            span: None,
2088        }
2089    }
2090
2091    /// Create with a schema qualifier.
2092    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
2093        let mut t = Self::new(name);
2094        t.schema = Some(Identifier::new(schema));
2095        t
2096    }
2097
2098    /// Create with catalog and schema qualifiers.
2099    pub fn new_with_catalog(
2100        name: impl Into<String>,
2101        schema: impl Into<String>,
2102        catalog: impl Into<String>,
2103    ) -> Self {
2104        let mut t = Self::new(name);
2105        t.schema = Some(Identifier::new(schema));
2106        t.catalog = Some(Identifier::new(catalog));
2107        t
2108    }
2109
2110    /// Create from an Identifier, preserving the quoted flag
2111    pub fn from_identifier(name: Identifier) -> Self {
2112        Self {
2113            name,
2114            schema: None,
2115            catalog: None,
2116            alias: None,
2117            alias_explicit_as: false,
2118            column_aliases: Vec::new(),
2119            trailing_comments: Vec::new(),
2120            when: None,
2121            only: false,
2122            final_: false,
2123            table_sample: None,
2124            hints: Vec::new(),
2125            system_time: None,
2126            partitions: Vec::new(),
2127            identifier_func: None,
2128            changes: None,
2129            version: None,
2130            span: None,
2131        }
2132    }
2133
2134    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
2135        self.alias = Some(Identifier::new(alias));
2136        self
2137    }
2138
2139    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
2140        self.schema = Some(Identifier::new(schema));
2141        self
2142    }
2143}
2144
2145/// Represent a wildcard star expression (`*`, `table.*`).
2146///
2147/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
2148/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
2149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2150#[cfg_attr(feature = "bindings", derive(TS))]
2151pub struct Star {
2152    /// Optional table qualifier (e.g. `t` in `t.*`).
2153    pub table: Option<Identifier>,
2154    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
2155    pub except: Option<Vec<Identifier>>,
2156    /// REPLACE expressions (BigQuery, Snowflake)
2157    pub replace: Option<Vec<Alias>>,
2158    /// RENAME columns (Snowflake)
2159    pub rename: Option<Vec<(Identifier, Identifier)>>,
2160    /// Trailing comments that appeared after the star
2161    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2162    pub trailing_comments: Vec<String>,
2163    /// Source position span
2164    #[serde(default, skip_serializing_if = "Option::is_none")]
2165    pub span: Option<Span>,
2166}
2167
2168/// Represent a complete SELECT statement.
2169///
2170/// This is the most feature-rich AST node, covering the full surface area of
2171/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
2172/// `Vec` are omitted from the generated SQL when absent.
2173///
2174/// # Key Fields
2175///
2176/// - `expressions` -- the select-list (columns, `*`, computed expressions).
2177/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
2178/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
2179/// - `where_clause` -- the WHERE predicate.
2180/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
2181/// - `having` -- HAVING predicate.
2182/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
2183/// - `limit` / `offset` / `fetch` -- result set limiting.
2184/// - `with` -- Common Table Expressions (CTEs).
2185/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
2186/// - `windows` -- named window definitions (WINDOW w AS ...).
2187///
2188/// Dialect-specific extensions are supported via fields like `prewhere`
2189/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
2190/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
2191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2192#[cfg_attr(feature = "bindings", derive(TS))]
2193pub struct Select {
2194    /// The select-list: columns, expressions, aliases, and wildcards.
2195    pub expressions: Vec<Expression>,
2196    /// The FROM clause, containing one or more table sources.
2197    pub from: Option<From>,
2198    /// JOIN clauses applied after the FROM source.
2199    pub joins: Vec<Join>,
2200    pub lateral_views: Vec<LateralView>,
2201    /// ClickHouse PREWHERE clause
2202    #[serde(default, skip_serializing_if = "Option::is_none")]
2203    pub prewhere: Option<Expression>,
2204    pub where_clause: Option<Where>,
2205    pub group_by: Option<GroupBy>,
2206    pub having: Option<Having>,
2207    pub qualify: Option<Qualify>,
2208    pub order_by: Option<OrderBy>,
2209    pub distribute_by: Option<DistributeBy>,
2210    pub cluster_by: Option<ClusterBy>,
2211    pub sort_by: Option<SortBy>,
2212    pub limit: Option<Limit>,
2213    pub offset: Option<Offset>,
2214    /// ClickHouse LIMIT BY clause expressions
2215    #[serde(default, skip_serializing_if = "Option::is_none")]
2216    pub limit_by: Option<Vec<Expression>>,
2217    pub fetch: Option<Fetch>,
2218    pub distinct: bool,
2219    pub distinct_on: Option<Vec<Expression>>,
2220    pub top: Option<Top>,
2221    pub with: Option<With>,
2222    pub sample: Option<Sample>,
2223    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
2224    #[serde(default, skip_serializing_if = "Option::is_none")]
2225    pub settings: Option<Vec<Expression>>,
2226    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
2227    #[serde(default, skip_serializing_if = "Option::is_none")]
2228    pub format: Option<Expression>,
2229    pub windows: Option<Vec<NamedWindow>>,
2230    pub hint: Option<Hint>,
2231    /// Oracle CONNECT BY clause for hierarchical queries
2232    pub connect: Option<Connect>,
2233    /// SELECT ... INTO table_name for creating tables
2234    pub into: Option<SelectInto>,
2235    /// FOR UPDATE/SHARE locking clauses
2236    #[serde(default)]
2237    pub locks: Vec<Lock>,
2238    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
2239    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2240    pub for_xml: Vec<Expression>,
2241    /// Leading comments before the statement
2242    #[serde(default)]
2243    pub leading_comments: Vec<String>,
2244    /// Comments that appear after SELECT keyword (before expressions)
2245    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
2246    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2247    pub post_select_comments: Vec<String>,
2248    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
2249    #[serde(default, skip_serializing_if = "Option::is_none")]
2250    pub kind: Option<String>,
2251    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
2252    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2253    pub operation_modifiers: Vec<String>,
2254    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
2255    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2256    pub qualify_after_window: bool,
2257    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
2258    #[serde(default, skip_serializing_if = "Option::is_none")]
2259    pub option: Option<String>,
2260    /// Redshift-style EXCLUDE clause at the end of the projection list
2261    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
2262    #[serde(default, skip_serializing_if = "Option::is_none")]
2263    pub exclude: Option<Vec<Expression>>,
2264}
2265
2266impl Select {
2267    pub fn new() -> Self {
2268        Self {
2269            expressions: Vec::new(),
2270            from: None,
2271            joins: Vec::new(),
2272            lateral_views: Vec::new(),
2273            prewhere: None,
2274            where_clause: None,
2275            group_by: None,
2276            having: None,
2277            qualify: None,
2278            order_by: None,
2279            distribute_by: None,
2280            cluster_by: None,
2281            sort_by: None,
2282            limit: None,
2283            offset: None,
2284            limit_by: None,
2285            fetch: None,
2286            distinct: false,
2287            distinct_on: None,
2288            top: None,
2289            with: None,
2290            sample: None,
2291            settings: None,
2292            format: None,
2293            windows: None,
2294            hint: None,
2295            connect: None,
2296            into: None,
2297            locks: Vec::new(),
2298            for_xml: Vec::new(),
2299            leading_comments: Vec::new(),
2300            post_select_comments: Vec::new(),
2301            kind: None,
2302            operation_modifiers: Vec::new(),
2303            qualify_after_window: false,
2304            option: None,
2305            exclude: None,
2306        }
2307    }
2308
2309    /// Add a column to select
2310    pub fn column(mut self, expr: Expression) -> Self {
2311        self.expressions.push(expr);
2312        self
2313    }
2314
2315    /// Set the FROM clause
2316    pub fn from(mut self, table: Expression) -> Self {
2317        self.from = Some(From {
2318            expressions: vec![table],
2319        });
2320        self
2321    }
2322
2323    /// Add a WHERE clause
2324    pub fn where_(mut self, condition: Expression) -> Self {
2325        self.where_clause = Some(Where { this: condition });
2326        self
2327    }
2328
2329    /// Set DISTINCT
2330    pub fn distinct(mut self) -> Self {
2331        self.distinct = true;
2332        self
2333    }
2334
2335    /// Add a JOIN
2336    pub fn join(mut self, join: Join) -> Self {
2337        self.joins.push(join);
2338        self
2339    }
2340
2341    /// Set ORDER BY
2342    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
2343        self.order_by = Some(OrderBy {
2344            expressions,
2345            siblings: false,
2346            comments: Vec::new(),
2347        });
2348        self
2349    }
2350
2351    /// Set LIMIT
2352    pub fn limit(mut self, n: Expression) -> Self {
2353        self.limit = Some(Limit {
2354            this: n,
2355            percent: false,
2356            comments: Vec::new(),
2357        });
2358        self
2359    }
2360
2361    /// Set OFFSET
2362    pub fn offset(mut self, n: Expression) -> Self {
2363        self.offset = Some(Offset {
2364            this: n,
2365            rows: None,
2366        });
2367        self
2368    }
2369}
2370
2371impl Default for Select {
2372    fn default() -> Self {
2373        Self::new()
2374    }
2375}
2376
2377/// Represent a UNION set operation between two query expressions.
2378///
2379/// When `all` is true, duplicate rows are preserved (UNION ALL).
2380/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
2381/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
2382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2383#[cfg_attr(feature = "bindings", derive(TS))]
2384pub struct Union {
2385    /// The left-hand query operand.
2386    pub left: Expression,
2387    /// The right-hand query operand.
2388    pub right: Expression,
2389    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
2390    pub all: bool,
2391    /// Whether DISTINCT was explicitly specified
2392    #[serde(default)]
2393    pub distinct: bool,
2394    /// Optional WITH clause
2395    pub with: Option<With>,
2396    /// ORDER BY applied to entire UNION result
2397    pub order_by: Option<OrderBy>,
2398    /// LIMIT applied to entire UNION result
2399    pub limit: Option<Box<Expression>>,
2400    /// OFFSET applied to entire UNION result
2401    pub offset: Option<Box<Expression>>,
2402    /// DISTRIBUTE BY clause (Hive/Spark)
2403    #[serde(default, skip_serializing_if = "Option::is_none")]
2404    pub distribute_by: Option<DistributeBy>,
2405    /// SORT BY clause (Hive/Spark)
2406    #[serde(default, skip_serializing_if = "Option::is_none")]
2407    pub sort_by: Option<SortBy>,
2408    /// CLUSTER BY clause (Hive/Spark)
2409    #[serde(default, skip_serializing_if = "Option::is_none")]
2410    pub cluster_by: Option<ClusterBy>,
2411    /// DuckDB BY NAME modifier
2412    #[serde(default)]
2413    pub by_name: bool,
2414    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2415    #[serde(default, skip_serializing_if = "Option::is_none")]
2416    pub side: Option<String>,
2417    /// BigQuery: Set operation kind (INNER)
2418    #[serde(default, skip_serializing_if = "Option::is_none")]
2419    pub kind: Option<String>,
2420    /// BigQuery: CORRESPONDING modifier
2421    #[serde(default)]
2422    pub corresponding: bool,
2423    /// BigQuery: STRICT modifier (before CORRESPONDING)
2424    #[serde(default)]
2425    pub strict: bool,
2426    /// BigQuery: BY (columns) after CORRESPONDING
2427    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2428    pub on_columns: Vec<Expression>,
2429}
2430
2431/// Represent an INTERSECT set operation between two query expressions.
2432///
2433/// Returns only rows that appear in both operands. When `all` is true,
2434/// duplicates are preserved according to their multiplicity.
2435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2436#[cfg_attr(feature = "bindings", derive(TS))]
2437pub struct Intersect {
2438    /// The left-hand query operand.
2439    pub left: Expression,
2440    /// The right-hand query operand.
2441    pub right: Expression,
2442    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
2443    pub all: bool,
2444    /// Whether DISTINCT was explicitly specified
2445    #[serde(default)]
2446    pub distinct: bool,
2447    /// Optional WITH clause
2448    pub with: Option<With>,
2449    /// ORDER BY applied to entire INTERSECT result
2450    pub order_by: Option<OrderBy>,
2451    /// LIMIT applied to entire INTERSECT result
2452    pub limit: Option<Box<Expression>>,
2453    /// OFFSET applied to entire INTERSECT result
2454    pub offset: Option<Box<Expression>>,
2455    /// DISTRIBUTE BY clause (Hive/Spark)
2456    #[serde(default, skip_serializing_if = "Option::is_none")]
2457    pub distribute_by: Option<DistributeBy>,
2458    /// SORT BY clause (Hive/Spark)
2459    #[serde(default, skip_serializing_if = "Option::is_none")]
2460    pub sort_by: Option<SortBy>,
2461    /// CLUSTER BY clause (Hive/Spark)
2462    #[serde(default, skip_serializing_if = "Option::is_none")]
2463    pub cluster_by: Option<ClusterBy>,
2464    /// DuckDB BY NAME modifier
2465    #[serde(default)]
2466    pub by_name: bool,
2467    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2468    #[serde(default, skip_serializing_if = "Option::is_none")]
2469    pub side: Option<String>,
2470    /// BigQuery: Set operation kind (INNER)
2471    #[serde(default, skip_serializing_if = "Option::is_none")]
2472    pub kind: Option<String>,
2473    /// BigQuery: CORRESPONDING modifier
2474    #[serde(default)]
2475    pub corresponding: bool,
2476    /// BigQuery: STRICT modifier (before CORRESPONDING)
2477    #[serde(default)]
2478    pub strict: bool,
2479    /// BigQuery: BY (columns) after CORRESPONDING
2480    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2481    pub on_columns: Vec<Expression>,
2482}
2483
2484/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2485///
2486/// Returns rows from the left operand that do not appear in the right operand.
2487/// When `all` is true, duplicates are subtracted according to their multiplicity.
2488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2489#[cfg_attr(feature = "bindings", derive(TS))]
2490pub struct Except {
2491    /// The left-hand query operand.
2492    pub left: Expression,
2493    /// The right-hand query operand (rows to subtract).
2494    pub right: Expression,
2495    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2496    pub all: bool,
2497    /// Whether DISTINCT was explicitly specified
2498    #[serde(default)]
2499    pub distinct: bool,
2500    /// Optional WITH clause
2501    pub with: Option<With>,
2502    /// ORDER BY applied to entire EXCEPT result
2503    pub order_by: Option<OrderBy>,
2504    /// LIMIT applied to entire EXCEPT result
2505    pub limit: Option<Box<Expression>>,
2506    /// OFFSET applied to entire EXCEPT result
2507    pub offset: Option<Box<Expression>>,
2508    /// DISTRIBUTE BY clause (Hive/Spark)
2509    #[serde(default, skip_serializing_if = "Option::is_none")]
2510    pub distribute_by: Option<DistributeBy>,
2511    /// SORT BY clause (Hive/Spark)
2512    #[serde(default, skip_serializing_if = "Option::is_none")]
2513    pub sort_by: Option<SortBy>,
2514    /// CLUSTER BY clause (Hive/Spark)
2515    #[serde(default, skip_serializing_if = "Option::is_none")]
2516    pub cluster_by: Option<ClusterBy>,
2517    /// DuckDB BY NAME modifier
2518    #[serde(default)]
2519    pub by_name: bool,
2520    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2521    #[serde(default, skip_serializing_if = "Option::is_none")]
2522    pub side: Option<String>,
2523    /// BigQuery: Set operation kind (INNER)
2524    #[serde(default, skip_serializing_if = "Option::is_none")]
2525    pub kind: Option<String>,
2526    /// BigQuery: CORRESPONDING modifier
2527    #[serde(default)]
2528    pub corresponding: bool,
2529    /// BigQuery: STRICT modifier (before CORRESPONDING)
2530    #[serde(default)]
2531    pub strict: bool,
2532    /// BigQuery: BY (columns) after CORRESPONDING
2533    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2534    pub on_columns: Vec<Expression>,
2535}
2536
2537/// INTO clause for SELECT INTO statements
2538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2539#[cfg_attr(feature = "bindings", derive(TS))]
2540pub struct SelectInto {
2541    /// Target table or variable (used when single target)
2542    pub this: Expression,
2543    /// Whether TEMPORARY keyword was used
2544    #[serde(default)]
2545    pub temporary: bool,
2546    /// Whether UNLOGGED keyword was used (PostgreSQL)
2547    #[serde(default)]
2548    pub unlogged: bool,
2549    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2550    #[serde(default)]
2551    pub bulk_collect: bool,
2552    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2553    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2554    pub expressions: Vec<Expression>,
2555}
2556
2557/// Represent a parenthesized subquery expression.
2558///
2559/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2560/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2561/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2562/// modifiers are rendered inside or outside the parentheses.
2563///
2564/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2565/// scalar subqueries in select-lists, and derived tables.
2566#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2567#[cfg_attr(feature = "bindings", derive(TS))]
2568pub struct Subquery {
2569    /// The inner query expression.
2570    pub this: Expression,
2571    /// Optional alias for the derived table.
2572    pub alias: Option<Identifier>,
2573    /// Optional column aliases: AS t(c1, c2)
2574    pub column_aliases: Vec<Identifier>,
2575    /// ORDER BY clause (for parenthesized queries)
2576    pub order_by: Option<OrderBy>,
2577    /// LIMIT clause
2578    pub limit: Option<Limit>,
2579    /// OFFSET clause
2580    pub offset: Option<Offset>,
2581    /// DISTRIBUTE BY clause (Hive/Spark)
2582    #[serde(default, skip_serializing_if = "Option::is_none")]
2583    pub distribute_by: Option<DistributeBy>,
2584    /// SORT BY clause (Hive/Spark)
2585    #[serde(default, skip_serializing_if = "Option::is_none")]
2586    pub sort_by: Option<SortBy>,
2587    /// CLUSTER BY clause (Hive/Spark)
2588    #[serde(default, skip_serializing_if = "Option::is_none")]
2589    pub cluster_by: Option<ClusterBy>,
2590    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2591    #[serde(default)]
2592    pub lateral: bool,
2593    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2594    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2595    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2596    #[serde(default)]
2597    pub modifiers_inside: bool,
2598    /// Trailing comments after the closing paren
2599    #[serde(default)]
2600    pub trailing_comments: Vec<String>,
2601    /// Inferred data type from type annotation
2602    #[serde(default, skip_serializing_if = "Option::is_none")]
2603    pub inferred_type: Option<DataType>,
2604}
2605
2606/// Pipe operator expression: query |> transform
2607///
2608/// Used in DataFusion and BigQuery pipe syntax:
2609///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2611#[cfg_attr(feature = "bindings", derive(TS))]
2612pub struct PipeOperator {
2613    /// The input query/expression (left side of |>)
2614    pub this: Expression,
2615    /// The piped operation (right side of |>)
2616    pub expression: Expression,
2617}
2618
2619/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2621#[cfg_attr(feature = "bindings", derive(TS))]
2622pub struct Values {
2623    /// The rows of values
2624    pub expressions: Vec<Tuple>,
2625    /// Optional alias for the table
2626    pub alias: Option<Identifier>,
2627    /// Optional column aliases: AS t(c1, c2)
2628    pub column_aliases: Vec<Identifier>,
2629}
2630
2631/// PIVOT operation - supports both standard and DuckDB simplified syntax
2632///
2633/// Standard syntax (in FROM clause):
2634///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2635///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2636///
2637/// DuckDB simplified syntax (statement-level):
2638///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2639///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2641#[cfg_attr(feature = "bindings", derive(TS))]
2642pub struct Pivot {
2643    /// Source table/expression
2644    pub this: Expression,
2645    /// For standard PIVOT: the aggregation function(s) (first is primary)
2646    /// For DuckDB simplified: unused (use `using` instead)
2647    #[serde(default)]
2648    pub expressions: Vec<Expression>,
2649    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2650    #[serde(default)]
2651    pub fields: Vec<Expression>,
2652    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2653    #[serde(default)]
2654    pub using: Vec<Expression>,
2655    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2656    #[serde(default)]
2657    pub group: Option<Box<Expression>>,
2658    /// Whether this is an UNPIVOT (vs PIVOT)
2659    #[serde(default)]
2660    pub unpivot: bool,
2661    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2662    #[serde(default)]
2663    pub into: Option<Box<Expression>>,
2664    /// Optional alias
2665    #[serde(default)]
2666    pub alias: Option<Identifier>,
2667    /// Include/exclude nulls (for UNPIVOT)
2668    #[serde(default)]
2669    pub include_nulls: Option<bool>,
2670    /// Default on null value (Snowflake)
2671    #[serde(default)]
2672    pub default_on_null: Option<Box<Expression>>,
2673    /// WITH clause (CTEs)
2674    #[serde(default, skip_serializing_if = "Option::is_none")]
2675    pub with: Option<With>,
2676}
2677
2678/// UNPIVOT operation
2679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2680#[cfg_attr(feature = "bindings", derive(TS))]
2681pub struct Unpivot {
2682    pub this: Expression,
2683    pub value_column: Identifier,
2684    pub name_column: Identifier,
2685    pub columns: Vec<Expression>,
2686    pub alias: Option<Identifier>,
2687    /// Whether the value_column was parenthesized in the original SQL
2688    #[serde(default)]
2689    pub value_column_parenthesized: bool,
2690    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2691    #[serde(default)]
2692    pub include_nulls: Option<bool>,
2693    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2694    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2695    pub extra_value_columns: Vec<Identifier>,
2696}
2697
2698/// PIVOT alias for aliasing pivot expressions
2699/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2701#[cfg_attr(feature = "bindings", derive(TS))]
2702pub struct PivotAlias {
2703    pub this: Expression,
2704    pub alias: Expression,
2705}
2706
2707/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2709#[cfg_attr(feature = "bindings", derive(TS))]
2710pub struct PreWhere {
2711    pub this: Expression,
2712}
2713
2714/// STREAM definition (Snowflake) - for change data capture
2715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2716#[cfg_attr(feature = "bindings", derive(TS))]
2717pub struct Stream {
2718    pub this: Expression,
2719    #[serde(skip_serializing_if = "Option::is_none")]
2720    pub on: Option<Expression>,
2721    #[serde(skip_serializing_if = "Option::is_none")]
2722    pub show_initial_rows: Option<bool>,
2723}
2724
2725/// USING DATA clause for data import statements
2726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2727#[cfg_attr(feature = "bindings", derive(TS))]
2728pub struct UsingData {
2729    pub this: Expression,
2730}
2731
2732/// XML Namespace declaration
2733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2734#[cfg_attr(feature = "bindings", derive(TS))]
2735pub struct XmlNamespace {
2736    pub this: Expression,
2737    #[serde(skip_serializing_if = "Option::is_none")]
2738    pub alias: Option<Identifier>,
2739}
2740
2741/// ROW FORMAT clause for Hive/Spark
2742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2743#[cfg_attr(feature = "bindings", derive(TS))]
2744pub struct RowFormat {
2745    pub delimited: bool,
2746    pub fields_terminated_by: Option<String>,
2747    pub collection_items_terminated_by: Option<String>,
2748    pub map_keys_terminated_by: Option<String>,
2749    pub lines_terminated_by: Option<String>,
2750    pub null_defined_as: Option<String>,
2751}
2752
2753/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2755#[cfg_attr(feature = "bindings", derive(TS))]
2756pub struct DirectoryInsert {
2757    pub local: bool,
2758    pub path: String,
2759    pub row_format: Option<RowFormat>,
2760    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2761    #[serde(default)]
2762    pub stored_as: Option<String>,
2763}
2764
2765/// INSERT statement
2766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2767#[cfg_attr(feature = "bindings", derive(TS))]
2768pub struct Insert {
2769    pub table: TableRef,
2770    pub columns: Vec<Identifier>,
2771    pub values: Vec<Vec<Expression>>,
2772    pub query: Option<Expression>,
2773    /// INSERT OVERWRITE for Hive/Spark
2774    pub overwrite: bool,
2775    /// PARTITION clause for Hive/Spark
2776    pub partition: Vec<(Identifier, Option<Expression>)>,
2777    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2778    #[serde(default)]
2779    pub directory: Option<DirectoryInsert>,
2780    /// RETURNING clause (PostgreSQL, SQLite)
2781    #[serde(default)]
2782    pub returning: Vec<Expression>,
2783    /// OUTPUT clause (TSQL)
2784    #[serde(default)]
2785    pub output: Option<OutputClause>,
2786    /// ON CONFLICT clause (PostgreSQL, SQLite)
2787    #[serde(default)]
2788    pub on_conflict: Option<Box<Expression>>,
2789    /// Leading comments before the statement
2790    #[serde(default)]
2791    pub leading_comments: Vec<String>,
2792    /// IF EXISTS clause (Hive)
2793    #[serde(default)]
2794    pub if_exists: bool,
2795    /// WITH clause (CTEs)
2796    #[serde(default)]
2797    pub with: Option<With>,
2798    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2799    #[serde(default)]
2800    pub ignore: bool,
2801    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2802    #[serde(default)]
2803    pub source_alias: Option<Identifier>,
2804    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2805    #[serde(default)]
2806    pub alias: Option<Identifier>,
2807    /// Whether the alias uses explicit AS keyword
2808    #[serde(default)]
2809    pub alias_explicit_as: bool,
2810    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2811    #[serde(default)]
2812    pub default_values: bool,
2813    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2814    #[serde(default)]
2815    pub by_name: bool,
2816    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2817    #[serde(default, skip_serializing_if = "Option::is_none")]
2818    pub conflict_action: Option<String>,
2819    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2820    #[serde(default)]
2821    pub is_replace: bool,
2822    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2823    #[serde(default, skip_serializing_if = "Option::is_none")]
2824    pub hint: Option<Hint>,
2825    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2826    #[serde(default)]
2827    pub replace_where: Option<Box<Expression>>,
2828    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2829    #[serde(default)]
2830    pub source: Option<Box<Expression>>,
2831    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2832    #[serde(default, skip_serializing_if = "Option::is_none")]
2833    pub function_target: Option<Box<Expression>>,
2834    /// ClickHouse: PARTITION BY expr
2835    #[serde(default, skip_serializing_if = "Option::is_none")]
2836    pub partition_by: Option<Box<Expression>>,
2837    /// ClickHouse: SETTINGS key = val, ...
2838    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2839    pub settings: Vec<Expression>,
2840}
2841
2842/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2844#[cfg_attr(feature = "bindings", derive(TS))]
2845pub struct OutputClause {
2846    /// Columns/expressions to output
2847    pub columns: Vec<Expression>,
2848    /// Optional INTO target table or table variable
2849    #[serde(default)]
2850    pub into_table: Option<Expression>,
2851}
2852
2853/// UPDATE statement
2854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2855#[cfg_attr(feature = "bindings", derive(TS))]
2856pub struct Update {
2857    pub table: TableRef,
2858    /// Additional tables for multi-table UPDATE (MySQL syntax)
2859    #[serde(default)]
2860    pub extra_tables: Vec<TableRef>,
2861    /// JOINs attached to the table list (MySQL multi-table syntax)
2862    #[serde(default)]
2863    pub table_joins: Vec<Join>,
2864    pub set: Vec<(Identifier, Expression)>,
2865    pub from_clause: Option<From>,
2866    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2867    #[serde(default)]
2868    pub from_joins: Vec<Join>,
2869    pub where_clause: Option<Where>,
2870    /// RETURNING clause (PostgreSQL, SQLite)
2871    #[serde(default)]
2872    pub returning: Vec<Expression>,
2873    /// OUTPUT clause (TSQL)
2874    #[serde(default)]
2875    pub output: Option<OutputClause>,
2876    /// WITH clause (CTEs)
2877    #[serde(default)]
2878    pub with: Option<With>,
2879    /// Leading comments before the statement
2880    #[serde(default)]
2881    pub leading_comments: Vec<String>,
2882    /// LIMIT clause (MySQL)
2883    #[serde(default)]
2884    pub limit: Option<Expression>,
2885    /// ORDER BY clause (MySQL)
2886    #[serde(default)]
2887    pub order_by: Option<OrderBy>,
2888    /// Whether FROM clause appears before SET (Snowflake syntax)
2889    #[serde(default)]
2890    pub from_before_set: bool,
2891}
2892
2893/// DELETE statement
2894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2895#[cfg_attr(feature = "bindings", derive(TS))]
2896pub struct Delete {
2897    pub table: TableRef,
2898    /// ClickHouse: ON CLUSTER clause for distributed DDL
2899    #[serde(default, skip_serializing_if = "Option::is_none")]
2900    pub on_cluster: Option<OnCluster>,
2901    /// Optional alias for the table
2902    pub alias: Option<Identifier>,
2903    /// Whether the alias was declared with explicit AS keyword
2904    #[serde(default)]
2905    pub alias_explicit_as: bool,
2906    /// PostgreSQL/DuckDB USING clause - additional tables to join
2907    pub using: Vec<TableRef>,
2908    pub where_clause: Option<Where>,
2909    /// OUTPUT clause (TSQL)
2910    #[serde(default)]
2911    pub output: Option<OutputClause>,
2912    /// Leading comments before the statement
2913    #[serde(default)]
2914    pub leading_comments: Vec<String>,
2915    /// WITH clause (CTEs)
2916    #[serde(default)]
2917    pub with: Option<With>,
2918    /// LIMIT clause (MySQL)
2919    #[serde(default)]
2920    pub limit: Option<Expression>,
2921    /// ORDER BY clause (MySQL)
2922    #[serde(default)]
2923    pub order_by: Option<OrderBy>,
2924    /// RETURNING clause (PostgreSQL)
2925    #[serde(default)]
2926    pub returning: Vec<Expression>,
2927    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2928    /// These are the target tables to delete from
2929    #[serde(default)]
2930    pub tables: Vec<TableRef>,
2931    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2932    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2933    #[serde(default)]
2934    pub tables_from_using: bool,
2935    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2936    #[serde(default)]
2937    pub joins: Vec<Join>,
2938    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2939    #[serde(default)]
2940    pub force_index: Option<String>,
2941    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2942    #[serde(default)]
2943    pub no_from: bool,
2944}
2945
2946/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2948#[cfg_attr(feature = "bindings", derive(TS))]
2949pub struct CopyStmt {
2950    /// Target table or query
2951    pub this: Expression,
2952    /// True for FROM (loading into table), false for TO (exporting)
2953    pub kind: bool,
2954    /// Source/destination file(s) or stage
2955    pub files: Vec<Expression>,
2956    /// Copy parameters
2957    #[serde(default)]
2958    pub params: Vec<CopyParameter>,
2959    /// Credentials for external access
2960    #[serde(default)]
2961    pub credentials: Option<Box<Credentials>>,
2962    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2963    #[serde(default)]
2964    pub is_into: bool,
2965    /// Whether parameters are wrapped in WITH (...) syntax
2966    #[serde(default)]
2967    pub with_wrapped: bool,
2968}
2969
2970/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2972#[cfg_attr(feature = "bindings", derive(TS))]
2973pub struct CopyParameter {
2974    pub name: String,
2975    pub value: Option<Expression>,
2976    pub values: Vec<Expression>,
2977    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2978    #[serde(default)]
2979    pub eq: bool,
2980}
2981
2982/// Credentials for external access (S3, Azure, etc.)
2983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2984#[cfg_attr(feature = "bindings", derive(TS))]
2985pub struct Credentials {
2986    pub credentials: Vec<(String, String)>,
2987    pub encryption: Option<String>,
2988    pub storage: Option<String>,
2989}
2990
2991/// PUT statement (Snowflake)
2992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2993#[cfg_attr(feature = "bindings", derive(TS))]
2994pub struct PutStmt {
2995    /// Source file path
2996    pub source: String,
2997    /// Whether source was quoted in the original SQL
2998    #[serde(default)]
2999    pub source_quoted: bool,
3000    /// Target stage
3001    pub target: Expression,
3002    /// PUT parameters
3003    #[serde(default)]
3004    pub params: Vec<CopyParameter>,
3005}
3006
3007/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
3008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3009#[cfg_attr(feature = "bindings", derive(TS))]
3010pub struct StageReference {
3011    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
3012    pub name: String,
3013    /// Optional path within the stage (e.g., "/path/to/file.csv")
3014    #[serde(default)]
3015    pub path: Option<String>,
3016    /// Optional FILE_FORMAT parameter
3017    #[serde(default)]
3018    pub file_format: Option<Expression>,
3019    /// Optional PATTERN parameter
3020    #[serde(default)]
3021    pub pattern: Option<String>,
3022    /// Whether the stage reference was originally quoted (e.g., '@mystage')
3023    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3024    pub quoted: bool,
3025}
3026
3027/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3029#[cfg_attr(feature = "bindings", derive(TS))]
3030pub struct HistoricalData {
3031    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
3032    pub this: Box<Expression>,
3033    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
3034    pub kind: String,
3035    /// The expression value (e.g., the statement ID or timestamp)
3036    pub expression: Box<Expression>,
3037}
3038
3039/// Represent an aliased expression (`expr AS name`).
3040///
3041/// Used for column aliases in select-lists, table aliases on subqueries,
3042/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
3043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3044#[cfg_attr(feature = "bindings", derive(TS))]
3045pub struct Alias {
3046    /// The expression being aliased.
3047    pub this: Expression,
3048    /// The alias name (required for simple aliases, optional when only column aliases provided)
3049    pub alias: Identifier,
3050    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
3051    #[serde(default)]
3052    pub column_aliases: Vec<Identifier>,
3053    /// Comments that appeared between the expression and AS keyword
3054    #[serde(default)]
3055    pub pre_alias_comments: Vec<String>,
3056    /// Trailing comments that appeared after the alias
3057    #[serde(default)]
3058    pub trailing_comments: Vec<String>,
3059    /// Inferred data type from type annotation
3060    #[serde(default, skip_serializing_if = "Option::is_none")]
3061    pub inferred_type: Option<DataType>,
3062}
3063
3064impl Alias {
3065    /// Create a simple alias
3066    pub fn new(this: Expression, alias: Identifier) -> Self {
3067        Self {
3068            this,
3069            alias,
3070            column_aliases: Vec::new(),
3071            pre_alias_comments: Vec::new(),
3072            trailing_comments: Vec::new(),
3073            inferred_type: None,
3074        }
3075    }
3076
3077    /// Create an alias with column aliases only (no table alias name)
3078    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
3079        Self {
3080            this,
3081            alias: Identifier::empty(),
3082            column_aliases,
3083            pre_alias_comments: Vec::new(),
3084            trailing_comments: Vec::new(),
3085            inferred_type: None,
3086        }
3087    }
3088}
3089
3090/// Represent a type cast expression.
3091///
3092/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
3093/// shorthand `expr::type`. Also used as the payload for `TryCast` and
3094/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
3095/// CONVERSION ERROR (Oracle) clauses.
3096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3097#[cfg_attr(feature = "bindings", derive(TS))]
3098pub struct Cast {
3099    /// The expression being cast.
3100    pub this: Expression,
3101    /// The target data type.
3102    pub to: DataType,
3103    #[serde(default)]
3104    pub trailing_comments: Vec<String>,
3105    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
3106    #[serde(default)]
3107    pub double_colon_syntax: bool,
3108    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
3109    #[serde(skip_serializing_if = "Option::is_none", default)]
3110    pub format: Option<Box<Expression>>,
3111    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
3112    #[serde(skip_serializing_if = "Option::is_none", default)]
3113    pub default: Option<Box<Expression>>,
3114    /// Inferred data type from type annotation
3115    #[serde(default, skip_serializing_if = "Option::is_none")]
3116    pub inferred_type: Option<DataType>,
3117}
3118
3119///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
3120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3121#[cfg_attr(feature = "bindings", derive(TS))]
3122pub struct CollationExpr {
3123    pub this: Expression,
3124    pub collation: String,
3125    /// True if the collation was single-quoted in the original SQL (string literal)
3126    #[serde(default)]
3127    pub quoted: bool,
3128    /// True if the collation was double-quoted in the original SQL (identifier)
3129    #[serde(default)]
3130    pub double_quoted: bool,
3131}
3132
3133/// Represent a CASE expression (both simple and searched forms).
3134///
3135/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
3136/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
3137/// Each entry in `whens` is a `(condition, result)` pair.
3138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3139#[cfg_attr(feature = "bindings", derive(TS))]
3140pub struct Case {
3141    /// The operand for simple CASE, or `None` for searched CASE.
3142    pub operand: Option<Expression>,
3143    /// Pairs of (WHEN condition, THEN result).
3144    pub whens: Vec<(Expression, Expression)>,
3145    /// Optional ELSE result.
3146    pub else_: Option<Expression>,
3147    /// Comments from the CASE keyword (emitted after END)
3148    #[serde(default)]
3149    #[serde(skip_serializing_if = "Vec::is_empty")]
3150    pub comments: Vec<String>,
3151    /// Inferred data type from type annotation
3152    #[serde(default, skip_serializing_if = "Option::is_none")]
3153    pub inferred_type: Option<DataType>,
3154}
3155
3156/// Represent a binary operation (two operands separated by an operator).
3157///
3158/// This is the shared payload struct for all binary operator variants in the
3159/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
3160/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
3161/// bitwise, and dialect-specific operators. Comment fields enable round-trip
3162/// preservation of inline comments around operators.
3163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3164#[cfg_attr(feature = "bindings", derive(TS))]
3165pub struct BinaryOp {
3166    pub left: Expression,
3167    pub right: Expression,
3168    /// Comments after the left operand (before the operator)
3169    #[serde(default)]
3170    pub left_comments: Vec<String>,
3171    /// Comments after the operator (before the right operand)
3172    #[serde(default)]
3173    pub operator_comments: Vec<String>,
3174    /// Comments after the right operand
3175    #[serde(default)]
3176    pub trailing_comments: Vec<String>,
3177    /// Inferred data type from type annotation
3178    #[serde(default, skip_serializing_if = "Option::is_none")]
3179    pub inferred_type: Option<DataType>,
3180}
3181
3182impl BinaryOp {
3183    pub fn new(left: Expression, right: Expression) -> Self {
3184        Self {
3185            left,
3186            right,
3187            left_comments: Vec::new(),
3188            operator_comments: Vec::new(),
3189            trailing_comments: Vec::new(),
3190            inferred_type: None,
3191        }
3192    }
3193}
3194
3195/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
3196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3197#[cfg_attr(feature = "bindings", derive(TS))]
3198pub struct LikeOp {
3199    pub left: Expression,
3200    pub right: Expression,
3201    /// ESCAPE character/expression
3202    #[serde(default)]
3203    pub escape: Option<Expression>,
3204    /// Quantifier: ANY, ALL, or SOME
3205    #[serde(default)]
3206    pub quantifier: Option<String>,
3207    /// Inferred data type from type annotation
3208    #[serde(default, skip_serializing_if = "Option::is_none")]
3209    pub inferred_type: Option<DataType>,
3210}
3211
3212impl LikeOp {
3213    pub fn new(left: Expression, right: Expression) -> Self {
3214        Self {
3215            left,
3216            right,
3217            escape: None,
3218            quantifier: None,
3219            inferred_type: None,
3220        }
3221    }
3222
3223    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
3224        Self {
3225            left,
3226            right,
3227            escape: Some(escape),
3228            quantifier: None,
3229            inferred_type: None,
3230        }
3231    }
3232}
3233
3234/// Represent a unary operation (single operand with a prefix operator).
3235///
3236/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
3237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3238#[cfg_attr(feature = "bindings", derive(TS))]
3239pub struct UnaryOp {
3240    /// The operand expression.
3241    pub this: Expression,
3242    /// Inferred data type from type annotation
3243    #[serde(default, skip_serializing_if = "Option::is_none")]
3244    pub inferred_type: Option<DataType>,
3245}
3246
3247impl UnaryOp {
3248    pub fn new(this: Expression) -> Self {
3249        Self {
3250            this,
3251            inferred_type: None,
3252        }
3253    }
3254}
3255
3256/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
3257///
3258/// Either `expressions` (a value list) or `query` (a subquery) is populated,
3259/// but not both. When `not` is true, the predicate is `NOT IN`.
3260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3261#[cfg_attr(feature = "bindings", derive(TS))]
3262pub struct In {
3263    /// The expression being tested.
3264    pub this: Expression,
3265    /// The value list (mutually exclusive with `query`).
3266    pub expressions: Vec<Expression>,
3267    /// A subquery (mutually exclusive with `expressions`).
3268    pub query: Option<Expression>,
3269    /// Whether this is NOT IN.
3270    pub not: bool,
3271    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3272    pub global: bool,
3273    /// BigQuery: IN UNNEST(expr)
3274    #[serde(default, skip_serializing_if = "Option::is_none")]
3275    pub unnest: Option<Box<Expression>>,
3276    /// Whether the right side is a bare field reference (no parentheses).
3277    /// Matches Python sqlglot's `field` attribute on `In` expression.
3278    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
3279    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3280    pub is_field: bool,
3281}
3282
3283/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
3284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3285#[cfg_attr(feature = "bindings", derive(TS))]
3286pub struct Between {
3287    /// The expression being tested.
3288    pub this: Expression,
3289    /// The lower bound.
3290    pub low: Expression,
3291    /// The upper bound.
3292    pub high: Expression,
3293    /// Whether this is NOT BETWEEN.
3294    pub not: bool,
3295    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
3296    #[serde(default)]
3297    pub symmetric: Option<bool>,
3298}
3299
3300/// IS NULL predicate
3301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3302#[cfg_attr(feature = "bindings", derive(TS))]
3303pub struct IsNull {
3304    pub this: Expression,
3305    pub not: bool,
3306    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
3307    #[serde(default)]
3308    pub postfix_form: bool,
3309}
3310
3311/// IS TRUE / IS FALSE predicate
3312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3313#[cfg_attr(feature = "bindings", derive(TS))]
3314pub struct IsTrueFalse {
3315    pub this: Expression,
3316    pub not: bool,
3317}
3318
3319/// IS JSON predicate (SQL standard)
3320/// Checks if a value is valid JSON
3321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3322#[cfg_attr(feature = "bindings", derive(TS))]
3323pub struct IsJson {
3324    pub this: Expression,
3325    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
3326    pub json_type: Option<String>,
3327    /// Key uniqueness constraint
3328    pub unique_keys: Option<JsonUniqueKeys>,
3329    /// Whether IS NOT JSON
3330    pub negated: bool,
3331}
3332
3333/// JSON unique keys constraint variants
3334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3335#[cfg_attr(feature = "bindings", derive(TS))]
3336pub enum JsonUniqueKeys {
3337    /// WITH UNIQUE KEYS
3338    With,
3339    /// WITHOUT UNIQUE KEYS
3340    Without,
3341    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
3342    Shorthand,
3343}
3344
3345/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
3346#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3347#[cfg_attr(feature = "bindings", derive(TS))]
3348pub struct Exists {
3349    /// The subquery expression.
3350    pub this: Expression,
3351    /// Whether this is NOT EXISTS.
3352    pub not: bool,
3353}
3354
3355/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
3356///
3357/// This is the generic function node. Well-known aggregates, window functions,
3358/// and built-in functions each have their own dedicated `Expression` variants
3359/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
3360/// not recognize as built-ins are represented with this struct.
3361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3362#[cfg_attr(feature = "bindings", derive(TS))]
3363pub struct Function {
3364    /// The function name, as originally written (may be schema-qualified).
3365    pub name: String,
3366    /// Positional arguments to the function.
3367    pub args: Vec<Expression>,
3368    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
3369    pub distinct: bool,
3370    #[serde(default)]
3371    pub trailing_comments: Vec<String>,
3372    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
3373    #[serde(default)]
3374    pub use_bracket_syntax: bool,
3375    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
3376    #[serde(default)]
3377    pub no_parens: bool,
3378    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
3379    #[serde(default)]
3380    pub quoted: bool,
3381    /// Source position span
3382    #[serde(default, skip_serializing_if = "Option::is_none")]
3383    pub span: Option<Span>,
3384    /// Inferred data type from type annotation
3385    #[serde(default, skip_serializing_if = "Option::is_none")]
3386    pub inferred_type: Option<DataType>,
3387}
3388
3389impl Default for Function {
3390    fn default() -> Self {
3391        Self {
3392            name: String::new(),
3393            args: Vec::new(),
3394            distinct: false,
3395            trailing_comments: Vec::new(),
3396            use_bracket_syntax: false,
3397            no_parens: false,
3398            quoted: false,
3399            span: None,
3400            inferred_type: None,
3401        }
3402    }
3403}
3404
3405impl Function {
3406    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
3407        Self {
3408            name: name.into(),
3409            args,
3410            distinct: false,
3411            trailing_comments: Vec::new(),
3412            use_bracket_syntax: false,
3413            no_parens: false,
3414            quoted: false,
3415            span: None,
3416            inferred_type: None,
3417        }
3418    }
3419}
3420
3421/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
3422///
3423/// This struct is used for aggregate function calls that are not covered by
3424/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
3425/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
3426/// IGNORE NULLS / RESPECT NULLS modifiers.
3427#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3428#[cfg_attr(feature = "bindings", derive(TS))]
3429pub struct AggregateFunction {
3430    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
3431    pub name: String,
3432    /// Positional arguments.
3433    pub args: Vec<Expression>,
3434    /// Whether DISTINCT was specified.
3435    pub distinct: bool,
3436    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
3437    pub filter: Option<Expression>,
3438    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
3439    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3440    pub order_by: Vec<Ordered>,
3441    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
3442    #[serde(default, skip_serializing_if = "Option::is_none")]
3443    pub limit: Option<Box<Expression>>,
3444    /// IGNORE NULLS / RESPECT NULLS
3445    #[serde(default, skip_serializing_if = "Option::is_none")]
3446    pub ignore_nulls: Option<bool>,
3447    /// Inferred data type from type annotation
3448    #[serde(default, skip_serializing_if = "Option::is_none")]
3449    pub inferred_type: Option<DataType>,
3450}
3451
3452/// Represent a window function call with its OVER clause.
3453///
3454/// The inner `this` expression is typically a window-specific expression
3455/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
3456/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
3457/// frame specification.
3458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3459#[cfg_attr(feature = "bindings", derive(TS))]
3460pub struct WindowFunction {
3461    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
3462    pub this: Expression,
3463    /// The OVER clause defining the window partitioning, ordering, and frame.
3464    pub over: Over,
3465    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
3466    #[serde(default, skip_serializing_if = "Option::is_none")]
3467    pub keep: Option<Keep>,
3468    /// Inferred data type from type annotation
3469    #[serde(default, skip_serializing_if = "Option::is_none")]
3470    pub inferred_type: Option<DataType>,
3471}
3472
3473/// Oracle KEEP clause for aggregate functions
3474/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
3475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3476#[cfg_attr(feature = "bindings", derive(TS))]
3477pub struct Keep {
3478    /// true = FIRST, false = LAST
3479    pub first: bool,
3480    /// ORDER BY clause inside KEEP
3481    pub order_by: Vec<Ordered>,
3482}
3483
3484/// WITHIN GROUP clause (for ordered-set aggregate functions)
3485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3486#[cfg_attr(feature = "bindings", derive(TS))]
3487pub struct WithinGroup {
3488    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
3489    pub this: Expression,
3490    /// The ORDER BY clause within the group
3491    pub order_by: Vec<Ordered>,
3492}
3493
3494/// Represent the FROM clause of a SELECT statement.
3495///
3496/// Contains one or more table sources (tables, subqueries, table-valued
3497/// functions, etc.). Multiple entries represent comma-separated implicit joins.
3498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3499#[cfg_attr(feature = "bindings", derive(TS))]
3500pub struct From {
3501    /// The table source expressions.
3502    pub expressions: Vec<Expression>,
3503}
3504
3505/// Represent a JOIN clause between two table sources.
3506///
3507/// The join condition can be specified via `on` (ON predicate) or `using`
3508/// (USING column list), but not both. The `kind` field determines the join
3509/// type (INNER, LEFT, CROSS, etc.).
3510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3511#[cfg_attr(feature = "bindings", derive(TS))]
3512pub struct Join {
3513    /// The right-hand table expression being joined.
3514    pub this: Expression,
3515    /// The ON condition (mutually exclusive with `using`).
3516    pub on: Option<Expression>,
3517    /// The USING column list (mutually exclusive with `on`).
3518    pub using: Vec<Identifier>,
3519    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
3520    pub kind: JoinKind,
3521    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3522    pub use_inner_keyword: bool,
3523    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3524    pub use_outer_keyword: bool,
3525    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3526    pub deferred_condition: bool,
3527    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3528    #[serde(default, skip_serializing_if = "Option::is_none")]
3529    pub join_hint: Option<String>,
3530    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3531    #[serde(default, skip_serializing_if = "Option::is_none")]
3532    pub match_condition: Option<Expression>,
3533    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3534    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3535    pub pivots: Vec<Expression>,
3536    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3537    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3538    pub comments: Vec<String>,
3539    /// Nesting group identifier for nested join pretty-printing.
3540    /// Joins in the same group were parsed together; group boundaries come from
3541    /// deferred condition resolution phases.
3542    #[serde(default)]
3543    pub nesting_group: usize,
3544    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3545    #[serde(default)]
3546    pub directed: bool,
3547}
3548
3549/// Enumerate all supported SQL join types.
3550///
3551/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3552/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3553/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3554/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3555#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3556#[cfg_attr(feature = "bindings", derive(TS))]
3557pub enum JoinKind {
3558    Inner,
3559    Left,
3560    Right,
3561    Full,
3562    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3563    Cross,
3564    Natural,
3565    NaturalLeft,
3566    NaturalRight,
3567    NaturalFull,
3568    Semi,
3569    Anti,
3570    // Directional SEMI/ANTI joins
3571    LeftSemi,
3572    LeftAnti,
3573    RightSemi,
3574    RightAnti,
3575    // SQL Server specific
3576    CrossApply,
3577    OuterApply,
3578    // Time-series specific
3579    AsOf,
3580    AsOfLeft,
3581    AsOfRight,
3582    // Lateral join
3583    Lateral,
3584    LeftLateral,
3585    // MySQL specific
3586    Straight,
3587    // Implicit join (comma-separated tables: FROM a, b)
3588    Implicit,
3589    // ClickHouse ARRAY JOIN
3590    Array,
3591    LeftArray,
3592    // ClickHouse PASTE JOIN (positional join)
3593    Paste,
3594    // DuckDB POSITIONAL JOIN
3595    Positional,
3596}
3597
3598impl Default for JoinKind {
3599    fn default() -> Self {
3600        JoinKind::Inner
3601    }
3602}
3603
3604/// Parenthesized table expression with joins
3605/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3607#[cfg_attr(feature = "bindings", derive(TS))]
3608pub struct JoinedTable {
3609    /// The left-hand side table expression
3610    pub left: Expression,
3611    /// The joins applied to the left table
3612    pub joins: Vec<Join>,
3613    /// LATERAL VIEW clauses (Hive/Spark)
3614    pub lateral_views: Vec<LateralView>,
3615    /// Optional alias for the joined table expression
3616    pub alias: Option<Identifier>,
3617}
3618
3619/// Represent a WHERE clause containing a boolean filter predicate.
3620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3621#[cfg_attr(feature = "bindings", derive(TS))]
3622pub struct Where {
3623    /// The filter predicate expression.
3624    pub this: Expression,
3625}
3626
3627/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3628///
3629/// The `expressions` list may contain plain columns, ordinal positions,
3630/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3632#[cfg_attr(feature = "bindings", derive(TS))]
3633pub struct GroupBy {
3634    /// The grouping expressions.
3635    pub expressions: Vec<Expression>,
3636    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3637    #[serde(default)]
3638    pub all: Option<bool>,
3639    /// ClickHouse: WITH TOTALS modifier
3640    #[serde(default)]
3641    pub totals: bool,
3642    /// Leading comments that appeared before the GROUP BY keyword
3643    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3644    pub comments: Vec<String>,
3645}
3646
3647/// Represent a HAVING clause containing a predicate over aggregate results.
3648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3649#[cfg_attr(feature = "bindings", derive(TS))]
3650pub struct Having {
3651    /// The filter predicate, typically involving aggregate functions.
3652    pub this: Expression,
3653    /// Leading comments that appeared before the HAVING keyword
3654    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3655    pub comments: Vec<String>,
3656}
3657
3658/// Represent an ORDER BY clause containing one or more sort specifications.
3659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3660#[cfg_attr(feature = "bindings", derive(TS))]
3661pub struct OrderBy {
3662    /// The sort specifications, each with direction and null ordering.
3663    pub expressions: Vec<Ordered>,
3664    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3665    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3666    pub siblings: bool,
3667    /// Leading comments that appeared before the ORDER BY keyword
3668    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3669    pub comments: Vec<String>,
3670}
3671
3672/// Represent an expression with sort direction and null ordering.
3673///
3674/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3675/// When `desc` is false the sort is ascending. The `nulls_first` field
3676/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3677/// (database default).
3678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3679#[cfg_attr(feature = "bindings", derive(TS))]
3680pub struct Ordered {
3681    /// The expression to sort by.
3682    pub this: Expression,
3683    /// Whether the sort direction is descending (true) or ascending (false).
3684    pub desc: bool,
3685    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3686    pub nulls_first: Option<bool>,
3687    /// Whether ASC was explicitly written (not just implied)
3688    #[serde(default)]
3689    pub explicit_asc: bool,
3690    /// ClickHouse WITH FILL clause
3691    #[serde(default, skip_serializing_if = "Option::is_none")]
3692    pub with_fill: Option<Box<WithFill>>,
3693}
3694
3695impl Ordered {
3696    pub fn asc(expr: Expression) -> Self {
3697        Self {
3698            this: expr,
3699            desc: false,
3700            nulls_first: None,
3701            explicit_asc: false,
3702            with_fill: None,
3703        }
3704    }
3705
3706    pub fn desc(expr: Expression) -> Self {
3707        Self {
3708            this: expr,
3709            desc: true,
3710            nulls_first: None,
3711            explicit_asc: false,
3712            with_fill: None,
3713        }
3714    }
3715}
3716
3717/// DISTRIBUTE BY clause (Hive/Spark)
3718/// Controls how rows are distributed across reducers
3719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3720#[cfg_attr(feature = "bindings", derive(TS))]
3721#[cfg_attr(feature = "bindings", ts(export))]
3722pub struct DistributeBy {
3723    pub expressions: Vec<Expression>,
3724}
3725
3726/// CLUSTER BY clause (Hive/Spark)
3727/// Combines DISTRIBUTE BY and SORT BY on the same columns
3728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3729#[cfg_attr(feature = "bindings", derive(TS))]
3730#[cfg_attr(feature = "bindings", ts(export))]
3731pub struct ClusterBy {
3732    pub expressions: Vec<Ordered>,
3733}
3734
3735/// SORT BY clause (Hive/Spark)
3736/// Sorts data within each reducer (local sort, not global)
3737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3738#[cfg_attr(feature = "bindings", derive(TS))]
3739#[cfg_attr(feature = "bindings", ts(export))]
3740pub struct SortBy {
3741    pub expressions: Vec<Ordered>,
3742}
3743
3744/// LATERAL VIEW clause (Hive/Spark)
3745/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3747#[cfg_attr(feature = "bindings", derive(TS))]
3748#[cfg_attr(feature = "bindings", ts(export))]
3749pub struct LateralView {
3750    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3751    pub this: Expression,
3752    /// Table alias for the generated table
3753    pub table_alias: Option<Identifier>,
3754    /// Column aliases for the generated columns
3755    pub column_aliases: Vec<Identifier>,
3756    /// OUTER keyword - preserve nulls when input is empty/null
3757    pub outer: bool,
3758}
3759
3760/// Query hint
3761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3762#[cfg_attr(feature = "bindings", derive(TS))]
3763#[cfg_attr(feature = "bindings", ts(export))]
3764pub struct Hint {
3765    pub expressions: Vec<HintExpression>,
3766}
3767
3768/// Individual hint expression
3769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3770#[cfg_attr(feature = "bindings", derive(TS))]
3771#[cfg_attr(feature = "bindings", ts(export))]
3772pub enum HintExpression {
3773    /// Function-style hint: USE_HASH(table)
3774    Function { name: String, args: Vec<Expression> },
3775    /// Simple identifier hint: PARALLEL
3776    Identifier(String),
3777    /// Raw hint text (unparsed)
3778    Raw(String),
3779}
3780
3781/// Pseudocolumn type
3782#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3783#[cfg_attr(feature = "bindings", derive(TS))]
3784#[cfg_attr(feature = "bindings", ts(export))]
3785pub enum PseudocolumnType {
3786    Rownum,      // Oracle ROWNUM
3787    Rowid,       // Oracle ROWID
3788    Level,       // Oracle LEVEL (for CONNECT BY)
3789    Sysdate,     // Oracle SYSDATE
3790    ObjectId,    // Oracle OBJECT_ID
3791    ObjectValue, // Oracle OBJECT_VALUE
3792}
3793
3794impl PseudocolumnType {
3795    pub fn as_str(&self) -> &'static str {
3796        match self {
3797            PseudocolumnType::Rownum => "ROWNUM",
3798            PseudocolumnType::Rowid => "ROWID",
3799            PseudocolumnType::Level => "LEVEL",
3800            PseudocolumnType::Sysdate => "SYSDATE",
3801            PseudocolumnType::ObjectId => "OBJECT_ID",
3802            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3803        }
3804    }
3805
3806    pub fn from_str(s: &str) -> Option<Self> {
3807        match s.to_uppercase().as_str() {
3808            "ROWNUM" => Some(PseudocolumnType::Rownum),
3809            "ROWID" => Some(PseudocolumnType::Rowid),
3810            "LEVEL" => Some(PseudocolumnType::Level),
3811            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3812            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3813            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3814            _ => None,
3815        }
3816    }
3817}
3818
3819/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3820/// These are special identifiers that should not be quoted
3821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3822#[cfg_attr(feature = "bindings", derive(TS))]
3823#[cfg_attr(feature = "bindings", ts(export))]
3824pub struct Pseudocolumn {
3825    pub kind: PseudocolumnType,
3826}
3827
3828impl Pseudocolumn {
3829    pub fn rownum() -> Self {
3830        Self {
3831            kind: PseudocolumnType::Rownum,
3832        }
3833    }
3834
3835    pub fn rowid() -> Self {
3836        Self {
3837            kind: PseudocolumnType::Rowid,
3838        }
3839    }
3840
3841    pub fn level() -> Self {
3842        Self {
3843            kind: PseudocolumnType::Level,
3844        }
3845    }
3846}
3847
3848/// Oracle CONNECT BY clause for hierarchical queries
3849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3850#[cfg_attr(feature = "bindings", derive(TS))]
3851#[cfg_attr(feature = "bindings", ts(export))]
3852pub struct Connect {
3853    /// START WITH condition (optional, can come before or after CONNECT BY)
3854    pub start: Option<Expression>,
3855    /// CONNECT BY condition (required, contains PRIOR references)
3856    pub connect: Expression,
3857    /// NOCYCLE keyword to prevent infinite loops
3858    pub nocycle: bool,
3859}
3860
3861/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3863#[cfg_attr(feature = "bindings", derive(TS))]
3864#[cfg_attr(feature = "bindings", ts(export))]
3865pub struct Prior {
3866    pub this: Expression,
3867}
3868
3869/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3871#[cfg_attr(feature = "bindings", derive(TS))]
3872#[cfg_attr(feature = "bindings", ts(export))]
3873pub struct ConnectByRoot {
3874    pub this: Expression,
3875}
3876
3877/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3879#[cfg_attr(feature = "bindings", derive(TS))]
3880#[cfg_attr(feature = "bindings", ts(export))]
3881pub struct MatchRecognize {
3882    /// Source table/expression
3883    pub this: Option<Box<Expression>>,
3884    /// PARTITION BY expressions
3885    pub partition_by: Option<Vec<Expression>>,
3886    /// ORDER BY expressions
3887    pub order_by: Option<Vec<Ordered>>,
3888    /// MEASURES definitions
3889    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3890    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3891    pub rows: Option<MatchRecognizeRows>,
3892    /// AFTER MATCH SKIP behavior
3893    pub after: Option<MatchRecognizeAfter>,
3894    /// PATTERN definition (stored as raw string for complex regex patterns)
3895    pub pattern: Option<String>,
3896    /// DEFINE clauses (pattern variable definitions)
3897    pub define: Option<Vec<(Identifier, Expression)>>,
3898    /// Optional alias for the result
3899    pub alias: Option<Identifier>,
3900    /// Whether AS keyword was explicitly present before alias
3901    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3902    pub alias_explicit_as: bool,
3903}
3904
3905/// MEASURES expression with optional RUNNING/FINAL semantics
3906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3907#[cfg_attr(feature = "bindings", derive(TS))]
3908#[cfg_attr(feature = "bindings", ts(export))]
3909pub struct MatchRecognizeMeasure {
3910    /// The measure expression
3911    pub this: Expression,
3912    /// RUNNING or FINAL semantics (Snowflake-specific)
3913    pub window_frame: Option<MatchRecognizeSemantics>,
3914}
3915
3916/// Semantics for MEASURES in MATCH_RECOGNIZE
3917#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3918#[cfg_attr(feature = "bindings", derive(TS))]
3919#[cfg_attr(feature = "bindings", ts(export))]
3920pub enum MatchRecognizeSemantics {
3921    Running,
3922    Final,
3923}
3924
3925/// Row output semantics for MATCH_RECOGNIZE
3926#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3927#[cfg_attr(feature = "bindings", derive(TS))]
3928#[cfg_attr(feature = "bindings", ts(export))]
3929pub enum MatchRecognizeRows {
3930    OneRowPerMatch,
3931    AllRowsPerMatch,
3932    AllRowsPerMatchShowEmptyMatches,
3933    AllRowsPerMatchOmitEmptyMatches,
3934    AllRowsPerMatchWithUnmatchedRows,
3935}
3936
3937/// AFTER MATCH SKIP behavior
3938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3939#[cfg_attr(feature = "bindings", derive(TS))]
3940#[cfg_attr(feature = "bindings", ts(export))]
3941pub enum MatchRecognizeAfter {
3942    PastLastRow,
3943    ToNextRow,
3944    ToFirst(Identifier),
3945    ToLast(Identifier),
3946}
3947
3948/// Represent a LIMIT clause that restricts the number of returned rows.
3949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3950#[cfg_attr(feature = "bindings", derive(TS))]
3951pub struct Limit {
3952    /// The limit count expression.
3953    pub this: Expression,
3954    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3955    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3956    pub percent: bool,
3957    /// Comments from before the LIMIT keyword (emitted after the limit value)
3958    #[serde(default)]
3959    #[serde(skip_serializing_if = "Vec::is_empty")]
3960    pub comments: Vec<String>,
3961}
3962
3963/// OFFSET clause
3964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3965#[cfg_attr(feature = "bindings", derive(TS))]
3966pub struct Offset {
3967    pub this: Expression,
3968    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3969    #[serde(skip_serializing_if = "Option::is_none", default)]
3970    pub rows: Option<bool>,
3971}
3972
3973/// TOP clause (SQL Server)
3974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3975#[cfg_attr(feature = "bindings", derive(TS))]
3976pub struct Top {
3977    pub this: Expression,
3978    pub percent: bool,
3979    pub with_ties: bool,
3980    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3981    #[serde(default)]
3982    pub parenthesized: bool,
3983}
3984
3985/// FETCH FIRST/NEXT clause (SQL standard)
3986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3987#[cfg_attr(feature = "bindings", derive(TS))]
3988pub struct Fetch {
3989    /// FIRST or NEXT
3990    pub direction: String,
3991    /// Count expression (optional)
3992    pub count: Option<Expression>,
3993    /// PERCENT modifier
3994    pub percent: bool,
3995    /// ROWS or ROW keyword present
3996    pub rows: bool,
3997    /// WITH TIES modifier
3998    pub with_ties: bool,
3999}
4000
4001/// Represent a QUALIFY clause for filtering on window function results.
4002///
4003/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
4004/// typically references a window function (e.g.
4005/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
4006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4007#[cfg_attr(feature = "bindings", derive(TS))]
4008pub struct Qualify {
4009    /// The filter predicate over window function results.
4010    pub this: Expression,
4011}
4012
4013/// SAMPLE / TABLESAMPLE clause
4014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4015#[cfg_attr(feature = "bindings", derive(TS))]
4016pub struct Sample {
4017    pub method: SampleMethod,
4018    pub size: Expression,
4019    pub seed: Option<Expression>,
4020    /// ClickHouse OFFSET expression after SAMPLE size
4021    #[serde(default)]
4022    pub offset: Option<Expression>,
4023    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
4024    pub unit_after_size: bool,
4025    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
4026    #[serde(default)]
4027    pub use_sample_keyword: bool,
4028    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
4029    #[serde(default)]
4030    pub explicit_method: bool,
4031    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
4032    #[serde(default)]
4033    pub method_before_size: bool,
4034    /// Whether SEED keyword was used (true) or REPEATABLE (false)
4035    #[serde(default)]
4036    pub use_seed_keyword: bool,
4037    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
4038    pub bucket_numerator: Option<Box<Expression>>,
4039    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
4040    pub bucket_denominator: Option<Box<Expression>>,
4041    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
4042    pub bucket_field: Option<Box<Expression>>,
4043    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
4044    #[serde(default)]
4045    pub is_using_sample: bool,
4046    /// Whether the unit was explicitly PERCENT (vs ROWS)
4047    #[serde(default)]
4048    pub is_percent: bool,
4049    /// Whether to suppress method output (for cross-dialect transpilation)
4050    #[serde(default)]
4051    pub suppress_method_output: bool,
4052}
4053
4054/// Sample method
4055#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4056#[cfg_attr(feature = "bindings", derive(TS))]
4057pub enum SampleMethod {
4058    Bernoulli,
4059    System,
4060    Block,
4061    Row,
4062    Percent,
4063    /// Hive bucket sampling
4064    Bucket,
4065    /// DuckDB reservoir sampling
4066    Reservoir,
4067}
4068
4069/// Named window definition (WINDOW w AS (...))
4070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4071#[cfg_attr(feature = "bindings", derive(TS))]
4072pub struct NamedWindow {
4073    pub name: Identifier,
4074    pub spec: Over,
4075}
4076
4077/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
4078///
4079/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
4080/// that reference themselves. Each CTE is defined in the `ctes` vector and
4081/// can be referenced by name in subsequent CTEs and in the main query body.
4082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4083#[cfg_attr(feature = "bindings", derive(TS))]
4084pub struct With {
4085    /// The list of CTE definitions, in order.
4086    pub ctes: Vec<Cte>,
4087    /// Whether the WITH RECURSIVE keyword was used.
4088    pub recursive: bool,
4089    /// Leading comments before the statement
4090    #[serde(default)]
4091    pub leading_comments: Vec<String>,
4092    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
4093    #[serde(default, skip_serializing_if = "Option::is_none")]
4094    pub search: Option<Box<Expression>>,
4095}
4096
4097/// Represent a single Common Table Expression definition.
4098///
4099/// A CTE has a name (`alias`), an optional column list, and a body query.
4100/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
4101/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
4102/// the expression comes before the alias (`alias_first`).
4103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4104#[cfg_attr(feature = "bindings", derive(TS))]
4105pub struct Cte {
4106    /// The CTE name.
4107    pub alias: Identifier,
4108    /// The CTE body (typically a SELECT, UNION, etc.).
4109    pub this: Expression,
4110    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
4111    pub columns: Vec<Identifier>,
4112    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
4113    pub materialized: Option<bool>,
4114    /// USING KEY (columns) for DuckDB recursive CTEs
4115    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4116    pub key_expressions: Vec<Identifier>,
4117    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
4118    #[serde(default)]
4119    pub alias_first: bool,
4120    /// Comments associated with this CTE (placed after alias name, before AS)
4121    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4122    pub comments: Vec<String>,
4123}
4124
4125/// Window specification
4126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4127#[cfg_attr(feature = "bindings", derive(TS))]
4128pub struct WindowSpec {
4129    pub partition_by: Vec<Expression>,
4130    pub order_by: Vec<Ordered>,
4131    pub frame: Option<WindowFrame>,
4132}
4133
4134/// OVER clause
4135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4136#[cfg_attr(feature = "bindings", derive(TS))]
4137pub struct Over {
4138    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
4139    pub window_name: Option<Identifier>,
4140    pub partition_by: Vec<Expression>,
4141    pub order_by: Vec<Ordered>,
4142    pub frame: Option<WindowFrame>,
4143    pub alias: Option<Identifier>,
4144}
4145
4146/// Window frame
4147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4148#[cfg_attr(feature = "bindings", derive(TS))]
4149pub struct WindowFrame {
4150    pub kind: WindowFrameKind,
4151    pub start: WindowFrameBound,
4152    pub end: Option<WindowFrameBound>,
4153    pub exclude: Option<WindowFrameExclude>,
4154    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
4155    #[serde(default, skip_serializing_if = "Option::is_none")]
4156    pub kind_text: Option<String>,
4157    /// Original text of the start bound side keyword (e.g. "preceding")
4158    #[serde(default, skip_serializing_if = "Option::is_none")]
4159    pub start_side_text: Option<String>,
4160    /// Original text of the end bound side keyword
4161    #[serde(default, skip_serializing_if = "Option::is_none")]
4162    pub end_side_text: Option<String>,
4163}
4164
4165#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub enum WindowFrameKind {
4168    Rows,
4169    Range,
4170    Groups,
4171}
4172
4173/// EXCLUDE clause for window frames
4174#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4175#[cfg_attr(feature = "bindings", derive(TS))]
4176pub enum WindowFrameExclude {
4177    CurrentRow,
4178    Group,
4179    Ties,
4180    NoOthers,
4181}
4182
4183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4184#[cfg_attr(feature = "bindings", derive(TS))]
4185pub enum WindowFrameBound {
4186    CurrentRow,
4187    UnboundedPreceding,
4188    UnboundedFollowing,
4189    Preceding(Box<Expression>),
4190    Following(Box<Expression>),
4191    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
4192    BarePreceding,
4193    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
4194    BareFollowing,
4195    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
4196    Value(Box<Expression>),
4197}
4198
4199/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
4200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4201#[cfg_attr(feature = "bindings", derive(TS))]
4202pub struct StructField {
4203    pub name: String,
4204    pub data_type: DataType,
4205    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4206    pub options: Vec<Expression>,
4207    #[serde(default, skip_serializing_if = "Option::is_none")]
4208    pub comment: Option<String>,
4209}
4210
4211impl StructField {
4212    /// Create a new struct field without options
4213    pub fn new(name: String, data_type: DataType) -> Self {
4214        Self {
4215            name,
4216            data_type,
4217            options: Vec::new(),
4218            comment: None,
4219        }
4220    }
4221
4222    /// Create a new struct field with options
4223    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
4224        Self {
4225            name,
4226            data_type,
4227            options,
4228            comment: None,
4229        }
4230    }
4231
4232    /// Create a new struct field with options and comment
4233    pub fn with_options_and_comment(
4234        name: String,
4235        data_type: DataType,
4236        options: Vec<Expression>,
4237        comment: Option<String>,
4238    ) -> Self {
4239        Self {
4240            name,
4241            data_type,
4242            options,
4243            comment,
4244        }
4245    }
4246}
4247
4248/// Enumerate all SQL data types recognized by the parser.
4249///
4250/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
4251/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
4252/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
4253///
4254/// This enum is used in CAST expressions, column definitions, function return
4255/// types, and anywhere a data type specification appears in SQL.
4256///
4257/// Types that do not match any known variant fall through to `Custom { name }`,
4258/// preserving the original type name for round-trip fidelity.
4259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4260#[cfg_attr(feature = "bindings", derive(TS))]
4261#[serde(tag = "data_type", rename_all = "snake_case")]
4262pub enum DataType {
4263    // Numeric
4264    Boolean,
4265    TinyInt {
4266        length: Option<u32>,
4267    },
4268    SmallInt {
4269        length: Option<u32>,
4270    },
4271    /// Int type with optional length. `integer_spelling` indicates whether the original
4272    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
4273    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
4274    Int {
4275        length: Option<u32>,
4276        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4277        integer_spelling: bool,
4278    },
4279    BigInt {
4280        length: Option<u32>,
4281    },
4282    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
4283    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
4284    /// preserve the original spelling.
4285    Float {
4286        precision: Option<u32>,
4287        scale: Option<u32>,
4288        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4289        real_spelling: bool,
4290    },
4291    Double {
4292        precision: Option<u32>,
4293        scale: Option<u32>,
4294    },
4295    Decimal {
4296        precision: Option<u32>,
4297        scale: Option<u32>,
4298    },
4299
4300    // String
4301    Char {
4302        length: Option<u32>,
4303    },
4304    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
4305    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
4306    VarChar {
4307        length: Option<u32>,
4308        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4309        parenthesized_length: bool,
4310    },
4311    /// String type with optional max length (BigQuery STRING(n))
4312    String {
4313        length: Option<u32>,
4314    },
4315    Text,
4316    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
4317    TextWithLength {
4318        length: u32,
4319    },
4320
4321    // Binary
4322    Binary {
4323        length: Option<u32>,
4324    },
4325    VarBinary {
4326        length: Option<u32>,
4327    },
4328    Blob,
4329
4330    // Bit
4331    Bit {
4332        length: Option<u32>,
4333    },
4334    VarBit {
4335        length: Option<u32>,
4336    },
4337
4338    // Date/Time
4339    Date,
4340    Time {
4341        precision: Option<u32>,
4342        #[serde(default)]
4343        timezone: bool,
4344    },
4345    Timestamp {
4346        precision: Option<u32>,
4347        timezone: bool,
4348    },
4349    Interval {
4350        unit: Option<String>,
4351        /// For range intervals like INTERVAL DAY TO HOUR
4352        #[serde(default, skip_serializing_if = "Option::is_none")]
4353        to: Option<String>,
4354    },
4355
4356    // JSON
4357    Json,
4358    JsonB,
4359
4360    // UUID
4361    Uuid,
4362
4363    // Array
4364    Array {
4365        element_type: Box<DataType>,
4366        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
4367        #[serde(default, skip_serializing_if = "Option::is_none")]
4368        dimension: Option<u32>,
4369    },
4370
4371    /// List type (Materialize): INT LIST, TEXT LIST LIST
4372    /// Uses postfix LIST syntax instead of ARRAY<T>
4373    List {
4374        element_type: Box<DataType>,
4375    },
4376
4377    // Struct/Map
4378    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
4379    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
4380    Struct {
4381        fields: Vec<StructField>,
4382        nested: bool,
4383    },
4384    Map {
4385        key_type: Box<DataType>,
4386        value_type: Box<DataType>,
4387    },
4388
4389    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
4390    Enum {
4391        values: Vec<String>,
4392        #[serde(default, skip_serializing_if = "Vec::is_empty")]
4393        assignments: Vec<Option<String>>,
4394    },
4395
4396    // Set type (MySQL): SET('a', 'b', 'c')
4397    Set {
4398        values: Vec<String>,
4399    },
4400
4401    // Union type (DuckDB): UNION(num INT, str TEXT)
4402    Union {
4403        fields: Vec<(String, DataType)>,
4404    },
4405
4406    // Vector (Snowflake / SingleStore)
4407    Vector {
4408        #[serde(default)]
4409        element_type: Option<Box<DataType>>,
4410        dimension: Option<u32>,
4411    },
4412
4413    // Object (Snowflake structured type)
4414    // fields: Vec of (field_name, field_type, not_null)
4415    Object {
4416        fields: Vec<(String, DataType, bool)>,
4417        modifier: Option<String>,
4418    },
4419
4420    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
4421    Nullable {
4422        inner: Box<DataType>,
4423    },
4424
4425    // Custom/User-defined
4426    Custom {
4427        name: String,
4428    },
4429
4430    // Spatial types
4431    Geometry {
4432        subtype: Option<String>,
4433        srid: Option<u32>,
4434    },
4435    Geography {
4436        subtype: Option<String>,
4437        srid: Option<u32>,
4438    },
4439
4440    // Character Set (for CONVERT USING in MySQL)
4441    // Renders as CHAR CHARACTER SET {name} in cast target
4442    CharacterSet {
4443        name: String,
4444    },
4445
4446    // Unknown
4447    Unknown,
4448}
4449
4450/// Array expression
4451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4452#[cfg_attr(feature = "bindings", derive(TS))]
4453#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
4454pub struct Array {
4455    pub expressions: Vec<Expression>,
4456}
4457
4458/// Struct expression
4459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4460#[cfg_attr(feature = "bindings", derive(TS))]
4461pub struct Struct {
4462    pub fields: Vec<(Option<String>, Expression)>,
4463}
4464
4465/// Tuple expression
4466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4467#[cfg_attr(feature = "bindings", derive(TS))]
4468pub struct Tuple {
4469    pub expressions: Vec<Expression>,
4470}
4471
4472/// Interval expression
4473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4474#[cfg_attr(feature = "bindings", derive(TS))]
4475pub struct Interval {
4476    /// The value expression (e.g., '1', 5, column_ref)
4477    pub this: Option<Expression>,
4478    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
4479    pub unit: Option<IntervalUnitSpec>,
4480}
4481
4482/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
4483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4484#[cfg_attr(feature = "bindings", derive(TS))]
4485#[serde(tag = "type", rename_all = "snake_case")]
4486pub enum IntervalUnitSpec {
4487    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
4488    Simple {
4489        unit: IntervalUnit,
4490        /// Whether to use plural form (e.g., DAYS vs DAY)
4491        use_plural: bool,
4492    },
4493    /// Interval span (e.g., HOUR TO SECOND)
4494    Span(IntervalSpan),
4495    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4496    /// The start and end can be expressions like function calls with precision
4497    ExprSpan(IntervalSpanExpr),
4498    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
4499    Expr(Box<Expression>),
4500}
4501
4502/// Interval span for ranges like HOUR TO SECOND
4503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4504#[cfg_attr(feature = "bindings", derive(TS))]
4505pub struct IntervalSpan {
4506    /// Start unit (e.g., HOUR)
4507    pub this: IntervalUnit,
4508    /// End unit (e.g., SECOND)
4509    pub expression: IntervalUnit,
4510}
4511
4512/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4513/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
4514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4515#[cfg_attr(feature = "bindings", derive(TS))]
4516pub struct IntervalSpanExpr {
4517    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
4518    pub this: Box<Expression>,
4519    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
4520    pub expression: Box<Expression>,
4521}
4522
4523#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4524#[cfg_attr(feature = "bindings", derive(TS))]
4525pub enum IntervalUnit {
4526    Year,
4527    Quarter,
4528    Month,
4529    Week,
4530    Day,
4531    Hour,
4532    Minute,
4533    Second,
4534    Millisecond,
4535    Microsecond,
4536    Nanosecond,
4537}
4538
4539/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4541#[cfg_attr(feature = "bindings", derive(TS))]
4542pub struct Command {
4543    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4544    pub this: String,
4545}
4546
4547/// EXEC/EXECUTE statement (TSQL stored procedure call)
4548/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4550#[cfg_attr(feature = "bindings", derive(TS))]
4551pub struct ExecuteStatement {
4552    /// The procedure name (can be qualified: schema.proc_name)
4553    pub this: Expression,
4554    /// Named parameters: @param=value pairs
4555    #[serde(default)]
4556    pub parameters: Vec<ExecuteParameter>,
4557}
4558
4559/// Named parameter in EXEC statement: @name=value
4560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4561#[cfg_attr(feature = "bindings", derive(TS))]
4562pub struct ExecuteParameter {
4563    /// Parameter name (including @)
4564    pub name: String,
4565    /// Parameter value
4566    pub value: Expression,
4567    /// Whether this is a positional parameter (no = sign)
4568    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4569    pub positional: bool,
4570}
4571
4572/// KILL statement (MySQL/MariaDB)
4573/// KILL [CONNECTION | QUERY] <id>
4574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4575#[cfg_attr(feature = "bindings", derive(TS))]
4576pub struct Kill {
4577    /// The target (process ID or connection ID)
4578    pub this: Expression,
4579    /// Optional kind: "CONNECTION" or "QUERY"
4580    pub kind: Option<String>,
4581}
4582
4583/// Raw/unparsed SQL
4584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4585#[cfg_attr(feature = "bindings", derive(TS))]
4586pub struct Raw {
4587    pub sql: String,
4588}
4589
4590// ============================================================================
4591// Function expression types
4592// ============================================================================
4593
4594/// Generic unary function (takes a single argument)
4595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4596#[cfg_attr(feature = "bindings", derive(TS))]
4597pub struct UnaryFunc {
4598    pub this: Expression,
4599    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4600    #[serde(skip_serializing_if = "Option::is_none", default)]
4601    pub original_name: Option<String>,
4602    /// Inferred data type from type annotation
4603    #[serde(default, skip_serializing_if = "Option::is_none")]
4604    pub inferred_type: Option<DataType>,
4605}
4606
4607impl UnaryFunc {
4608    /// Create a new UnaryFunc with no original_name
4609    pub fn new(this: Expression) -> Self {
4610        Self {
4611            this,
4612            original_name: None,
4613            inferred_type: None,
4614        }
4615    }
4616
4617    /// Create a new UnaryFunc with an original name for round-trip preservation
4618    pub fn with_name(this: Expression, name: String) -> Self {
4619        Self {
4620            this,
4621            original_name: Some(name),
4622            inferred_type: None,
4623        }
4624    }
4625}
4626
4627/// CHAR/CHR function with multiple args and optional USING charset
4628/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4629/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4631#[cfg_attr(feature = "bindings", derive(TS))]
4632pub struct CharFunc {
4633    pub args: Vec<Expression>,
4634    #[serde(skip_serializing_if = "Option::is_none", default)]
4635    pub charset: Option<String>,
4636    /// Original function name (CHAR or CHR), defaults to CHAR
4637    #[serde(skip_serializing_if = "Option::is_none", default)]
4638    pub name: Option<String>,
4639}
4640
4641/// Generic binary function (takes two arguments)
4642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4643#[cfg_attr(feature = "bindings", derive(TS))]
4644pub struct BinaryFunc {
4645    pub this: Expression,
4646    pub expression: Expression,
4647    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4648    #[serde(skip_serializing_if = "Option::is_none", default)]
4649    pub original_name: Option<String>,
4650    /// Inferred data type from type annotation
4651    #[serde(default, skip_serializing_if = "Option::is_none")]
4652    pub inferred_type: Option<DataType>,
4653}
4654
4655/// Variable argument function
4656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4657#[cfg_attr(feature = "bindings", derive(TS))]
4658pub struct VarArgFunc {
4659    pub expressions: Vec<Expression>,
4660    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4661    #[serde(skip_serializing_if = "Option::is_none", default)]
4662    pub original_name: Option<String>,
4663    /// Inferred data type from type annotation
4664    #[serde(default, skip_serializing_if = "Option::is_none")]
4665    pub inferred_type: Option<DataType>,
4666}
4667
4668/// CONCAT_WS function
4669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4670#[cfg_attr(feature = "bindings", derive(TS))]
4671pub struct ConcatWs {
4672    pub separator: Expression,
4673    pub expressions: Vec<Expression>,
4674}
4675
4676/// SUBSTRING function
4677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4678#[cfg_attr(feature = "bindings", derive(TS))]
4679pub struct SubstringFunc {
4680    pub this: Expression,
4681    pub start: Expression,
4682    pub length: Option<Expression>,
4683    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4684    #[serde(default)]
4685    pub from_for_syntax: bool,
4686}
4687
4688/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4690#[cfg_attr(feature = "bindings", derive(TS))]
4691pub struct OverlayFunc {
4692    pub this: Expression,
4693    pub replacement: Expression,
4694    pub from: Expression,
4695    pub length: Option<Expression>,
4696}
4697
4698/// TRIM function
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct TrimFunc {
4702    pub this: Expression,
4703    pub characters: Option<Expression>,
4704    pub position: TrimPosition,
4705    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4706    #[serde(default)]
4707    pub sql_standard_syntax: bool,
4708    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4709    #[serde(default)]
4710    pub position_explicit: bool,
4711}
4712
4713#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4714#[cfg_attr(feature = "bindings", derive(TS))]
4715pub enum TrimPosition {
4716    Both,
4717    Leading,
4718    Trailing,
4719}
4720
4721/// REPLACE function
4722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4723#[cfg_attr(feature = "bindings", derive(TS))]
4724pub struct ReplaceFunc {
4725    pub this: Expression,
4726    pub old: Expression,
4727    pub new: Expression,
4728}
4729
4730/// LEFT/RIGHT function
4731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4732#[cfg_attr(feature = "bindings", derive(TS))]
4733pub struct LeftRightFunc {
4734    pub this: Expression,
4735    pub length: Expression,
4736}
4737
4738/// REPEAT function
4739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4740#[cfg_attr(feature = "bindings", derive(TS))]
4741pub struct RepeatFunc {
4742    pub this: Expression,
4743    pub times: Expression,
4744}
4745
4746/// LPAD/RPAD function
4747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4748#[cfg_attr(feature = "bindings", derive(TS))]
4749pub struct PadFunc {
4750    pub this: Expression,
4751    pub length: Expression,
4752    pub fill: Option<Expression>,
4753}
4754
4755/// SPLIT function
4756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4757#[cfg_attr(feature = "bindings", derive(TS))]
4758pub struct SplitFunc {
4759    pub this: Expression,
4760    pub delimiter: Expression,
4761}
4762
4763/// REGEXP_LIKE function
4764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4765#[cfg_attr(feature = "bindings", derive(TS))]
4766pub struct RegexpFunc {
4767    pub this: Expression,
4768    pub pattern: Expression,
4769    pub flags: Option<Expression>,
4770}
4771
4772/// REGEXP_REPLACE function
4773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4774#[cfg_attr(feature = "bindings", derive(TS))]
4775pub struct RegexpReplaceFunc {
4776    pub this: Expression,
4777    pub pattern: Expression,
4778    pub replacement: Expression,
4779    pub flags: Option<Expression>,
4780}
4781
4782/// REGEXP_EXTRACT function
4783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4784#[cfg_attr(feature = "bindings", derive(TS))]
4785pub struct RegexpExtractFunc {
4786    pub this: Expression,
4787    pub pattern: Expression,
4788    pub group: Option<Expression>,
4789}
4790
4791/// ROUND function
4792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4793#[cfg_attr(feature = "bindings", derive(TS))]
4794pub struct RoundFunc {
4795    pub this: Expression,
4796    pub decimals: Option<Expression>,
4797}
4798
4799/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4801#[cfg_attr(feature = "bindings", derive(TS))]
4802pub struct FloorFunc {
4803    pub this: Expression,
4804    pub scale: Option<Expression>,
4805    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4806    #[serde(skip_serializing_if = "Option::is_none", default)]
4807    pub to: Option<Expression>,
4808}
4809
4810/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4812#[cfg_attr(feature = "bindings", derive(TS))]
4813pub struct CeilFunc {
4814    pub this: Expression,
4815    #[serde(skip_serializing_if = "Option::is_none", default)]
4816    pub decimals: Option<Expression>,
4817    /// Time unit for Druid-style CEIL(time TO unit) syntax
4818    #[serde(skip_serializing_if = "Option::is_none", default)]
4819    pub to: Option<Expression>,
4820}
4821
4822/// LOG function
4823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4824#[cfg_attr(feature = "bindings", derive(TS))]
4825pub struct LogFunc {
4826    pub this: Expression,
4827    pub base: Option<Expression>,
4828}
4829
4830/// CURRENT_DATE (no arguments)
4831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4832#[cfg_attr(feature = "bindings", derive(TS))]
4833pub struct CurrentDate;
4834
4835/// CURRENT_TIME
4836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4837#[cfg_attr(feature = "bindings", derive(TS))]
4838pub struct CurrentTime {
4839    pub precision: Option<u32>,
4840}
4841
4842/// CURRENT_TIMESTAMP
4843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4844#[cfg_attr(feature = "bindings", derive(TS))]
4845pub struct CurrentTimestamp {
4846    pub precision: Option<u32>,
4847    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4848    #[serde(default)]
4849    pub sysdate: bool,
4850}
4851
4852/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4854#[cfg_attr(feature = "bindings", derive(TS))]
4855pub struct CurrentTimestampLTZ {
4856    pub precision: Option<u32>,
4857}
4858
4859/// AT TIME ZONE expression for timezone conversion
4860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4861#[cfg_attr(feature = "bindings", derive(TS))]
4862pub struct AtTimeZone {
4863    /// The expression to convert
4864    pub this: Expression,
4865    /// The target timezone
4866    pub zone: Expression,
4867}
4868
4869/// DATE_ADD / DATE_SUB function
4870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4871#[cfg_attr(feature = "bindings", derive(TS))]
4872pub struct DateAddFunc {
4873    pub this: Expression,
4874    pub interval: Expression,
4875    pub unit: IntervalUnit,
4876}
4877
4878/// DATEDIFF function
4879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4880#[cfg_attr(feature = "bindings", derive(TS))]
4881pub struct DateDiffFunc {
4882    pub this: Expression,
4883    pub expression: Expression,
4884    pub unit: Option<IntervalUnit>,
4885}
4886
4887/// DATE_TRUNC function
4888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4889#[cfg_attr(feature = "bindings", derive(TS))]
4890pub struct DateTruncFunc {
4891    pub this: Expression,
4892    pub unit: DateTimeField,
4893}
4894
4895/// EXTRACT function
4896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4897#[cfg_attr(feature = "bindings", derive(TS))]
4898pub struct ExtractFunc {
4899    pub this: Expression,
4900    pub field: DateTimeField,
4901}
4902
4903#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4904#[cfg_attr(feature = "bindings", derive(TS))]
4905pub enum DateTimeField {
4906    Year,
4907    Month,
4908    Day,
4909    Hour,
4910    Minute,
4911    Second,
4912    Millisecond,
4913    Microsecond,
4914    DayOfWeek,
4915    DayOfYear,
4916    Week,
4917    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4918    WeekWithModifier(String),
4919    Quarter,
4920    Epoch,
4921    Timezone,
4922    TimezoneHour,
4923    TimezoneMinute,
4924    Date,
4925    Time,
4926    /// Custom datetime field for dialect-specific or arbitrary fields
4927    Custom(String),
4928}
4929
4930/// TO_DATE function
4931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4932#[cfg_attr(feature = "bindings", derive(TS))]
4933pub struct ToDateFunc {
4934    pub this: Expression,
4935    pub format: Option<Expression>,
4936}
4937
4938/// TO_TIMESTAMP function
4939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4940#[cfg_attr(feature = "bindings", derive(TS))]
4941pub struct ToTimestampFunc {
4942    pub this: Expression,
4943    pub format: Option<Expression>,
4944}
4945
4946/// IF function
4947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4948#[cfg_attr(feature = "bindings", derive(TS))]
4949pub struct IfFunc {
4950    pub condition: Expression,
4951    pub true_value: Expression,
4952    pub false_value: Option<Expression>,
4953    /// Original function name (IF, IFF, IIF) for round-trip preservation
4954    #[serde(skip_serializing_if = "Option::is_none", default)]
4955    pub original_name: Option<String>,
4956    /// Inferred data type from type annotation
4957    #[serde(default, skip_serializing_if = "Option::is_none")]
4958    pub inferred_type: Option<DataType>,
4959}
4960
4961/// NVL2 function
4962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4963#[cfg_attr(feature = "bindings", derive(TS))]
4964pub struct Nvl2Func {
4965    pub this: Expression,
4966    pub true_value: Expression,
4967    pub false_value: Expression,
4968    /// Inferred data type from type annotation
4969    #[serde(default, skip_serializing_if = "Option::is_none")]
4970    pub inferred_type: Option<DataType>,
4971}
4972
4973// ============================================================================
4974// Typed Aggregate Function types
4975// ============================================================================
4976
4977/// Generic aggregate function base type
4978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4979#[cfg_attr(feature = "bindings", derive(TS))]
4980pub struct AggFunc {
4981    pub this: Expression,
4982    pub distinct: bool,
4983    pub filter: Option<Expression>,
4984    pub order_by: Vec<Ordered>,
4985    /// Original function name (case-preserving) when parsed from SQL
4986    #[serde(skip_serializing_if = "Option::is_none", default)]
4987    pub name: Option<String>,
4988    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4989    #[serde(skip_serializing_if = "Option::is_none", default)]
4990    pub ignore_nulls: Option<bool>,
4991    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4992    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4993    #[serde(skip_serializing_if = "Option::is_none", default)]
4994    pub having_max: Option<(Box<Expression>, bool)>,
4995    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4996    #[serde(skip_serializing_if = "Option::is_none", default)]
4997    pub limit: Option<Box<Expression>>,
4998    /// Inferred data type from type annotation
4999    #[serde(default, skip_serializing_if = "Option::is_none")]
5000    pub inferred_type: Option<DataType>,
5001}
5002
5003/// COUNT function with optional star
5004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5005#[cfg_attr(feature = "bindings", derive(TS))]
5006pub struct CountFunc {
5007    pub this: Option<Expression>,
5008    pub star: bool,
5009    pub distinct: bool,
5010    pub filter: Option<Expression>,
5011    /// IGNORE NULLS (true) or RESPECT NULLS (false)
5012    #[serde(default, skip_serializing_if = "Option::is_none")]
5013    pub ignore_nulls: Option<bool>,
5014    /// Original function name for case preservation (e.g., "count" or "COUNT")
5015    #[serde(default, skip_serializing_if = "Option::is_none")]
5016    pub original_name: Option<String>,
5017    /// Inferred data type from type annotation
5018    #[serde(default, skip_serializing_if = "Option::is_none")]
5019    pub inferred_type: Option<DataType>,
5020}
5021
5022/// GROUP_CONCAT function (MySQL style)
5023#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5024#[cfg_attr(feature = "bindings", derive(TS))]
5025pub struct GroupConcatFunc {
5026    pub this: Expression,
5027    pub separator: Option<Expression>,
5028    pub order_by: Option<Vec<Ordered>>,
5029    pub distinct: bool,
5030    pub filter: Option<Expression>,
5031    /// Inferred data type from type annotation
5032    #[serde(default, skip_serializing_if = "Option::is_none")]
5033    pub inferred_type: Option<DataType>,
5034}
5035
5036/// STRING_AGG function (PostgreSQL/Standard SQL)
5037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5038#[cfg_attr(feature = "bindings", derive(TS))]
5039pub struct StringAggFunc {
5040    pub this: Expression,
5041    #[serde(default)]
5042    pub separator: Option<Expression>,
5043    #[serde(default)]
5044    pub order_by: Option<Vec<Ordered>>,
5045    #[serde(default)]
5046    pub distinct: bool,
5047    #[serde(default)]
5048    pub filter: Option<Expression>,
5049    /// BigQuery LIMIT inside STRING_AGG
5050    #[serde(default, skip_serializing_if = "Option::is_none")]
5051    pub limit: Option<Box<Expression>>,
5052    /// Inferred data type from type annotation
5053    #[serde(default, skip_serializing_if = "Option::is_none")]
5054    pub inferred_type: Option<DataType>,
5055}
5056
5057/// LISTAGG function (Oracle style)
5058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5059#[cfg_attr(feature = "bindings", derive(TS))]
5060pub struct ListAggFunc {
5061    pub this: Expression,
5062    pub separator: Option<Expression>,
5063    pub on_overflow: Option<ListAggOverflow>,
5064    pub order_by: Option<Vec<Ordered>>,
5065    pub distinct: bool,
5066    pub filter: Option<Expression>,
5067    /// Inferred data type from type annotation
5068    #[serde(default, skip_serializing_if = "Option::is_none")]
5069    pub inferred_type: Option<DataType>,
5070}
5071
5072/// LISTAGG ON OVERFLOW behavior
5073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5074#[cfg_attr(feature = "bindings", derive(TS))]
5075pub enum ListAggOverflow {
5076    Error,
5077    Truncate {
5078        filler: Option<Expression>,
5079        with_count: bool,
5080    },
5081}
5082
5083/// SUM_IF / COUNT_IF function
5084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5085#[cfg_attr(feature = "bindings", derive(TS))]
5086pub struct SumIfFunc {
5087    pub this: Expression,
5088    pub condition: Expression,
5089    pub filter: Option<Expression>,
5090    /// Inferred data type from type annotation
5091    #[serde(default, skip_serializing_if = "Option::is_none")]
5092    pub inferred_type: Option<DataType>,
5093}
5094
5095/// APPROX_PERCENTILE function
5096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5097#[cfg_attr(feature = "bindings", derive(TS))]
5098pub struct ApproxPercentileFunc {
5099    pub this: Expression,
5100    pub percentile: Expression,
5101    pub accuracy: Option<Expression>,
5102    pub filter: Option<Expression>,
5103}
5104
5105/// PERCENTILE_CONT / PERCENTILE_DISC function
5106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5107#[cfg_attr(feature = "bindings", derive(TS))]
5108pub struct PercentileFunc {
5109    pub this: Expression,
5110    pub percentile: Expression,
5111    pub order_by: Option<Vec<Ordered>>,
5112    pub filter: Option<Expression>,
5113}
5114
5115// ============================================================================
5116// Typed Window Function types
5117// ============================================================================
5118
5119/// ROW_NUMBER function (no arguments)
5120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5121#[cfg_attr(feature = "bindings", derive(TS))]
5122pub struct RowNumber;
5123
5124/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5126#[cfg_attr(feature = "bindings", derive(TS))]
5127pub struct Rank {
5128    /// DuckDB: RANK(ORDER BY col) - order by inside function
5129    #[serde(default, skip_serializing_if = "Option::is_none")]
5130    pub order_by: Option<Vec<Ordered>>,
5131    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5132    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5133    pub args: Vec<Expression>,
5134}
5135
5136/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
5137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5138#[cfg_attr(feature = "bindings", derive(TS))]
5139pub struct DenseRank {
5140    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5141    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5142    pub args: Vec<Expression>,
5143}
5144
5145/// NTILE function (DuckDB allows ORDER BY inside)
5146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5147#[cfg_attr(feature = "bindings", derive(TS))]
5148pub struct NTileFunc {
5149    /// num_buckets is optional to support Databricks NTILE() without arguments
5150    #[serde(default, skip_serializing_if = "Option::is_none")]
5151    pub num_buckets: Option<Expression>,
5152    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
5153    #[serde(default, skip_serializing_if = "Option::is_none")]
5154    pub order_by: Option<Vec<Ordered>>,
5155}
5156
5157/// LEAD / LAG function
5158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5159#[cfg_attr(feature = "bindings", derive(TS))]
5160pub struct LeadLagFunc {
5161    pub this: Expression,
5162    pub offset: Option<Expression>,
5163    pub default: Option<Expression>,
5164    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5165    #[serde(default, skip_serializing_if = "Option::is_none")]
5166    pub ignore_nulls: Option<bool>,
5167}
5168
5169/// FIRST_VALUE / LAST_VALUE function
5170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5171#[cfg_attr(feature = "bindings", derive(TS))]
5172pub struct ValueFunc {
5173    pub this: Expression,
5174    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5175    #[serde(default, skip_serializing_if = "Option::is_none")]
5176    pub ignore_nulls: Option<bool>,
5177}
5178
5179/// NTH_VALUE function
5180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5181#[cfg_attr(feature = "bindings", derive(TS))]
5182pub struct NthValueFunc {
5183    pub this: Expression,
5184    pub offset: Expression,
5185    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5186    #[serde(default, skip_serializing_if = "Option::is_none")]
5187    pub ignore_nulls: Option<bool>,
5188    /// Snowflake FROM FIRST / FROM LAST clause
5189    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
5190    #[serde(default, skip_serializing_if = "Option::is_none")]
5191    pub from_first: Option<bool>,
5192}
5193
5194/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5196#[cfg_attr(feature = "bindings", derive(TS))]
5197pub struct PercentRank {
5198    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
5199    #[serde(default, skip_serializing_if = "Option::is_none")]
5200    pub order_by: Option<Vec<Ordered>>,
5201    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5202    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5203    pub args: Vec<Expression>,
5204}
5205
5206/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5208#[cfg_attr(feature = "bindings", derive(TS))]
5209pub struct CumeDist {
5210    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
5211    #[serde(default, skip_serializing_if = "Option::is_none")]
5212    pub order_by: Option<Vec<Ordered>>,
5213    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5214    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5215    pub args: Vec<Expression>,
5216}
5217
5218// ============================================================================
5219// Additional String Function types
5220// ============================================================================
5221
5222/// POSITION/INSTR function
5223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5224#[cfg_attr(feature = "bindings", derive(TS))]
5225pub struct PositionFunc {
5226    pub substring: Expression,
5227    pub string: Expression,
5228    pub start: Option<Expression>,
5229}
5230
5231// ============================================================================
5232// Additional Math Function types
5233// ============================================================================
5234
5235/// RANDOM function (no arguments)
5236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5237#[cfg_attr(feature = "bindings", derive(TS))]
5238pub struct Random;
5239
5240/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
5241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5242#[cfg_attr(feature = "bindings", derive(TS))]
5243pub struct Rand {
5244    pub seed: Option<Box<Expression>>,
5245    /// Teradata RANDOM lower bound
5246    #[serde(default)]
5247    pub lower: Option<Box<Expression>>,
5248    /// Teradata RANDOM upper bound
5249    #[serde(default)]
5250    pub upper: Option<Box<Expression>>,
5251}
5252
5253/// TRUNCATE / TRUNC function
5254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5255#[cfg_attr(feature = "bindings", derive(TS))]
5256pub struct TruncateFunc {
5257    pub this: Expression,
5258    pub decimals: Option<Expression>,
5259}
5260
5261/// PI function (no arguments)
5262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5263#[cfg_attr(feature = "bindings", derive(TS))]
5264pub struct Pi;
5265
5266// ============================================================================
5267// Control Flow Function types
5268// ============================================================================
5269
5270/// DECODE function (Oracle style)
5271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5272#[cfg_attr(feature = "bindings", derive(TS))]
5273pub struct DecodeFunc {
5274    pub this: Expression,
5275    pub search_results: Vec<(Expression, Expression)>,
5276    pub default: Option<Expression>,
5277}
5278
5279// ============================================================================
5280// Additional Date/Time Function types
5281// ============================================================================
5282
5283/// DATE_FORMAT / FORMAT_DATE function
5284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5285#[cfg_attr(feature = "bindings", derive(TS))]
5286pub struct DateFormatFunc {
5287    pub this: Expression,
5288    pub format: Expression,
5289}
5290
5291/// FROM_UNIXTIME function
5292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5293#[cfg_attr(feature = "bindings", derive(TS))]
5294pub struct FromUnixtimeFunc {
5295    pub this: Expression,
5296    pub format: Option<Expression>,
5297}
5298
5299/// UNIX_TIMESTAMP function
5300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5301#[cfg_attr(feature = "bindings", derive(TS))]
5302pub struct UnixTimestampFunc {
5303    pub this: Option<Expression>,
5304    pub format: Option<Expression>,
5305}
5306
5307/// MAKE_DATE function
5308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5309#[cfg_attr(feature = "bindings", derive(TS))]
5310pub struct MakeDateFunc {
5311    pub year: Expression,
5312    pub month: Expression,
5313    pub day: Expression,
5314}
5315
5316/// MAKE_TIMESTAMP function
5317#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5318#[cfg_attr(feature = "bindings", derive(TS))]
5319pub struct MakeTimestampFunc {
5320    pub year: Expression,
5321    pub month: Expression,
5322    pub day: Expression,
5323    pub hour: Expression,
5324    pub minute: Expression,
5325    pub second: Expression,
5326    pub timezone: Option<Expression>,
5327}
5328
5329/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
5330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5331#[cfg_attr(feature = "bindings", derive(TS))]
5332pub struct LastDayFunc {
5333    pub this: Expression,
5334    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
5335    #[serde(skip_serializing_if = "Option::is_none", default)]
5336    pub unit: Option<DateTimeField>,
5337}
5338
5339// ============================================================================
5340// Array Function types
5341// ============================================================================
5342
5343/// ARRAY constructor
5344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5345#[cfg_attr(feature = "bindings", derive(TS))]
5346pub struct ArrayConstructor {
5347    pub expressions: Vec<Expression>,
5348    pub bracket_notation: bool,
5349    /// True if LIST keyword was used instead of ARRAY (DuckDB)
5350    pub use_list_keyword: bool,
5351}
5352
5353/// ARRAY_SORT function
5354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5355#[cfg_attr(feature = "bindings", derive(TS))]
5356pub struct ArraySortFunc {
5357    pub this: Expression,
5358    pub comparator: Option<Expression>,
5359    pub desc: bool,
5360    pub nulls_first: Option<bool>,
5361}
5362
5363/// ARRAY_JOIN / ARRAY_TO_STRING function
5364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5365#[cfg_attr(feature = "bindings", derive(TS))]
5366pub struct ArrayJoinFunc {
5367    pub this: Expression,
5368    pub separator: Expression,
5369    pub null_replacement: Option<Expression>,
5370}
5371
5372/// UNNEST function
5373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5374#[cfg_attr(feature = "bindings", derive(TS))]
5375pub struct UnnestFunc {
5376    pub this: Expression,
5377    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
5378    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5379    pub expressions: Vec<Expression>,
5380    pub with_ordinality: bool,
5381    pub alias: Option<Identifier>,
5382    /// BigQuery: offset alias for WITH OFFSET AS <name>
5383    #[serde(default, skip_serializing_if = "Option::is_none")]
5384    pub offset_alias: Option<Identifier>,
5385}
5386
5387/// ARRAY_FILTER function (with lambda)
5388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5389#[cfg_attr(feature = "bindings", derive(TS))]
5390pub struct ArrayFilterFunc {
5391    pub this: Expression,
5392    pub filter: Expression,
5393}
5394
5395/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
5396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5397#[cfg_attr(feature = "bindings", derive(TS))]
5398pub struct ArrayTransformFunc {
5399    pub this: Expression,
5400    pub transform: Expression,
5401}
5402
5403/// SEQUENCE / GENERATE_SERIES function
5404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5405#[cfg_attr(feature = "bindings", derive(TS))]
5406pub struct SequenceFunc {
5407    pub start: Expression,
5408    pub stop: Expression,
5409    pub step: Option<Expression>,
5410}
5411
5412// ============================================================================
5413// Struct Function types
5414// ============================================================================
5415
5416/// STRUCT constructor
5417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5418#[cfg_attr(feature = "bindings", derive(TS))]
5419pub struct StructConstructor {
5420    pub fields: Vec<(Option<Identifier>, Expression)>,
5421}
5422
5423/// STRUCT_EXTRACT function
5424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5425#[cfg_attr(feature = "bindings", derive(TS))]
5426pub struct StructExtractFunc {
5427    pub this: Expression,
5428    pub field: Identifier,
5429}
5430
5431/// NAMED_STRUCT function
5432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5433#[cfg_attr(feature = "bindings", derive(TS))]
5434pub struct NamedStructFunc {
5435    pub pairs: Vec<(Expression, Expression)>,
5436}
5437
5438// ============================================================================
5439// Map Function types
5440// ============================================================================
5441
5442/// MAP constructor
5443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5444#[cfg_attr(feature = "bindings", derive(TS))]
5445pub struct MapConstructor {
5446    pub keys: Vec<Expression>,
5447    pub values: Vec<Expression>,
5448    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
5449    #[serde(default)]
5450    pub curly_brace_syntax: bool,
5451    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
5452    #[serde(default)]
5453    pub with_map_keyword: bool,
5454}
5455
5456/// TRANSFORM_KEYS / TRANSFORM_VALUES function
5457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5458#[cfg_attr(feature = "bindings", derive(TS))]
5459pub struct TransformFunc {
5460    pub this: Expression,
5461    pub transform: Expression,
5462}
5463
5464// ============================================================================
5465// JSON Function types
5466// ============================================================================
5467
5468/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
5469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5470#[cfg_attr(feature = "bindings", derive(TS))]
5471pub struct JsonExtractFunc {
5472    pub this: Expression,
5473    pub path: Expression,
5474    pub returning: Option<DataType>,
5475    /// True if parsed from -> or ->> operator syntax
5476    #[serde(default)]
5477    pub arrow_syntax: bool,
5478    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
5479    #[serde(default)]
5480    pub hash_arrow_syntax: bool,
5481    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
5482    #[serde(default)]
5483    pub wrapper_option: Option<String>,
5484    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
5485    #[serde(default)]
5486    pub quotes_option: Option<String>,
5487    /// ON SCALAR STRING flag
5488    #[serde(default)]
5489    pub on_scalar_string: bool,
5490    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
5491    #[serde(default)]
5492    pub on_error: Option<String>,
5493}
5494
5495/// JSON path extraction
5496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5497#[cfg_attr(feature = "bindings", derive(TS))]
5498pub struct JsonPathFunc {
5499    pub this: Expression,
5500    pub paths: Vec<Expression>,
5501}
5502
5503/// JSON_OBJECT function
5504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5505#[cfg_attr(feature = "bindings", derive(TS))]
5506pub struct JsonObjectFunc {
5507    pub pairs: Vec<(Expression, Expression)>,
5508    pub null_handling: Option<JsonNullHandling>,
5509    #[serde(default)]
5510    pub with_unique_keys: bool,
5511    #[serde(default)]
5512    pub returning_type: Option<DataType>,
5513    #[serde(default)]
5514    pub format_json: bool,
5515    #[serde(default)]
5516    pub encoding: Option<String>,
5517    /// For JSON_OBJECT(*) syntax
5518    #[serde(default)]
5519    pub star: bool,
5520}
5521
5522/// JSON null handling options
5523#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5524#[cfg_attr(feature = "bindings", derive(TS))]
5525pub enum JsonNullHandling {
5526    NullOnNull,
5527    AbsentOnNull,
5528}
5529
5530/// JSON_SET / JSON_INSERT function
5531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5532#[cfg_attr(feature = "bindings", derive(TS))]
5533pub struct JsonModifyFunc {
5534    pub this: Expression,
5535    pub path_values: Vec<(Expression, Expression)>,
5536}
5537
5538/// JSON_ARRAYAGG function
5539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5540#[cfg_attr(feature = "bindings", derive(TS))]
5541pub struct JsonArrayAggFunc {
5542    pub this: Expression,
5543    pub order_by: Option<Vec<Ordered>>,
5544    pub null_handling: Option<JsonNullHandling>,
5545    pub filter: Option<Expression>,
5546}
5547
5548/// JSON_OBJECTAGG function
5549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5550#[cfg_attr(feature = "bindings", derive(TS))]
5551pub struct JsonObjectAggFunc {
5552    pub key: Expression,
5553    pub value: Expression,
5554    pub null_handling: Option<JsonNullHandling>,
5555    pub filter: Option<Expression>,
5556}
5557
5558// ============================================================================
5559// Type Casting Function types
5560// ============================================================================
5561
5562/// CONVERT function (SQL Server style)
5563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5564#[cfg_attr(feature = "bindings", derive(TS))]
5565pub struct ConvertFunc {
5566    pub this: Expression,
5567    pub to: DataType,
5568    pub style: Option<Expression>,
5569}
5570
5571// ============================================================================
5572// Additional Expression types
5573// ============================================================================
5574
5575/// Lambda expression
5576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5577#[cfg_attr(feature = "bindings", derive(TS))]
5578pub struct LambdaExpr {
5579    pub parameters: Vec<Identifier>,
5580    pub body: Expression,
5581    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5582    #[serde(default)]
5583    pub colon: bool,
5584    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5585    /// Maps parameter index to data type
5586    #[serde(default)]
5587    pub parameter_types: Vec<Option<DataType>>,
5588}
5589
5590/// Parameter (parameterized queries)
5591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5592#[cfg_attr(feature = "bindings", derive(TS))]
5593pub struct Parameter {
5594    pub name: Option<String>,
5595    pub index: Option<u32>,
5596    pub style: ParameterStyle,
5597    /// Whether the name was quoted (e.g., @"x" vs @x)
5598    #[serde(default)]
5599    pub quoted: bool,
5600    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5601    #[serde(default)]
5602    pub string_quoted: bool,
5603    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5604    #[serde(default)]
5605    pub expression: Option<String>,
5606}
5607
5608/// Parameter placeholder styles
5609#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5610#[cfg_attr(feature = "bindings", derive(TS))]
5611pub enum ParameterStyle {
5612    Question,     // ?
5613    Dollar,       // $1, $2
5614    DollarBrace,  // ${name} (Databricks, Hive template variables)
5615    Brace,        // {name} (Spark/Databricks widget/template variables)
5616    Colon,        // :name
5617    At,           // @name
5618    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5619    DoubleDollar, // $$name
5620    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5621}
5622
5623/// Placeholder expression
5624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5625#[cfg_attr(feature = "bindings", derive(TS))]
5626pub struct Placeholder {
5627    pub index: Option<u32>,
5628}
5629
5630/// Named argument in function call: name => value or name := value
5631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5632#[cfg_attr(feature = "bindings", derive(TS))]
5633pub struct NamedArgument {
5634    pub name: Identifier,
5635    pub value: Expression,
5636    /// The separator used: `=>`, `:=`, or `=`
5637    pub separator: NamedArgSeparator,
5638}
5639
5640/// Separator style for named arguments
5641#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5642#[cfg_attr(feature = "bindings", derive(TS))]
5643pub enum NamedArgSeparator {
5644    /// `=>` (standard SQL, Snowflake, BigQuery)
5645    DArrow,
5646    /// `:=` (Oracle, MySQL)
5647    ColonEq,
5648    /// `=` (simple equals, some dialects)
5649    Eq,
5650}
5651
5652/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5653/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5655#[cfg_attr(feature = "bindings", derive(TS))]
5656pub struct TableArgument {
5657    /// The keyword prefix: "TABLE" or "MODEL"
5658    pub prefix: String,
5659    /// The table/model reference expression
5660    pub this: Expression,
5661}
5662
5663/// SQL Comment preservation
5664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5665#[cfg_attr(feature = "bindings", derive(TS))]
5666pub struct SqlComment {
5667    pub text: String,
5668    pub is_block: bool,
5669}
5670
5671// ============================================================================
5672// Additional Predicate types
5673// ============================================================================
5674
5675/// SIMILAR TO expression
5676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5677#[cfg_attr(feature = "bindings", derive(TS))]
5678pub struct SimilarToExpr {
5679    pub this: Expression,
5680    pub pattern: Expression,
5681    pub escape: Option<Expression>,
5682    pub not: bool,
5683}
5684
5685/// ANY / ALL quantified expression
5686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5687#[cfg_attr(feature = "bindings", derive(TS))]
5688pub struct QuantifiedExpr {
5689    pub this: Expression,
5690    pub subquery: Expression,
5691    pub op: Option<QuantifiedOp>,
5692}
5693
5694/// Comparison operator for quantified expressions
5695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5696#[cfg_attr(feature = "bindings", derive(TS))]
5697pub enum QuantifiedOp {
5698    Eq,
5699    Neq,
5700    Lt,
5701    Lte,
5702    Gt,
5703    Gte,
5704}
5705
5706/// OVERLAPS expression
5707/// Supports two forms:
5708/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5709/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5711#[cfg_attr(feature = "bindings", derive(TS))]
5712pub struct OverlapsExpr {
5713    /// Left operand for simple binary form
5714    #[serde(skip_serializing_if = "Option::is_none")]
5715    pub this: Option<Expression>,
5716    /// Right operand for simple binary form
5717    #[serde(skip_serializing_if = "Option::is_none")]
5718    pub expression: Option<Expression>,
5719    /// Left range start for full ANSI form
5720    #[serde(skip_serializing_if = "Option::is_none")]
5721    pub left_start: Option<Expression>,
5722    /// Left range end for full ANSI form
5723    #[serde(skip_serializing_if = "Option::is_none")]
5724    pub left_end: Option<Expression>,
5725    /// Right range start for full ANSI form
5726    #[serde(skip_serializing_if = "Option::is_none")]
5727    pub right_start: Option<Expression>,
5728    /// Right range end for full ANSI form
5729    #[serde(skip_serializing_if = "Option::is_none")]
5730    pub right_end: Option<Expression>,
5731}
5732
5733// ============================================================================
5734// Array/Struct/Map access
5735// ============================================================================
5736
5737/// Subscript access (array[index] or map[key])
5738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5739#[cfg_attr(feature = "bindings", derive(TS))]
5740pub struct Subscript {
5741    pub this: Expression,
5742    pub index: Expression,
5743}
5744
5745/// Dot access (struct.field)
5746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5747#[cfg_attr(feature = "bindings", derive(TS))]
5748pub struct DotAccess {
5749    pub this: Expression,
5750    pub field: Identifier,
5751}
5752
5753/// Method call (expr.method(args))
5754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5755#[cfg_attr(feature = "bindings", derive(TS))]
5756pub struct MethodCall {
5757    pub this: Expression,
5758    pub method: Identifier,
5759    pub args: Vec<Expression>,
5760}
5761
5762/// Array slice (array[start:end])
5763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5764#[cfg_attr(feature = "bindings", derive(TS))]
5765pub struct ArraySlice {
5766    pub this: Expression,
5767    pub start: Option<Expression>,
5768    pub end: Option<Expression>,
5769}
5770
5771// ============================================================================
5772// DDL (Data Definition Language) Statements
5773// ============================================================================
5774
5775/// ON COMMIT behavior for temporary tables
5776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5777#[cfg_attr(feature = "bindings", derive(TS))]
5778pub enum OnCommit {
5779    /// ON COMMIT PRESERVE ROWS
5780    PreserveRows,
5781    /// ON COMMIT DELETE ROWS
5782    DeleteRows,
5783}
5784
5785/// CREATE TABLE statement
5786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5787#[cfg_attr(feature = "bindings", derive(TS))]
5788pub struct CreateTable {
5789    pub name: TableRef,
5790    /// ClickHouse: ON CLUSTER clause for distributed DDL
5791    #[serde(default, skip_serializing_if = "Option::is_none")]
5792    pub on_cluster: Option<OnCluster>,
5793    pub columns: Vec<ColumnDef>,
5794    pub constraints: Vec<TableConstraint>,
5795    pub if_not_exists: bool,
5796    pub temporary: bool,
5797    pub or_replace: bool,
5798    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5799    #[serde(default, skip_serializing_if = "Option::is_none")]
5800    pub table_modifier: Option<String>,
5801    pub as_select: Option<Expression>,
5802    /// Whether the AS SELECT was wrapped in parentheses
5803    #[serde(default)]
5804    pub as_select_parenthesized: bool,
5805    /// ON COMMIT behavior for temporary tables
5806    #[serde(default)]
5807    pub on_commit: Option<OnCommit>,
5808    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5809    #[serde(default)]
5810    pub clone_source: Option<TableRef>,
5811    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5812    #[serde(default, skip_serializing_if = "Option::is_none")]
5813    pub clone_at_clause: Option<Expression>,
5814    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5815    #[serde(default)]
5816    pub is_copy: bool,
5817    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5818    #[serde(default)]
5819    pub shallow_clone: bool,
5820    /// Leading comments before the statement
5821    #[serde(default)]
5822    pub leading_comments: Vec<String>,
5823    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5824    #[serde(default)]
5825    pub with_properties: Vec<(String, String)>,
5826    /// Teradata: table options after name before columns (comma-separated)
5827    #[serde(default)]
5828    pub teradata_post_name_options: Vec<String>,
5829    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5830    #[serde(default)]
5831    pub with_data: Option<bool>,
5832    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5833    #[serde(default)]
5834    pub with_statistics: Option<bool>,
5835    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5836    #[serde(default)]
5837    pub teradata_indexes: Vec<TeradataIndex>,
5838    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5839    #[serde(default)]
5840    pub with_cte: Option<With>,
5841    /// Table properties like DEFAULT COLLATE (BigQuery)
5842    #[serde(default)]
5843    pub properties: Vec<Expression>,
5844    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5845    #[serde(default, skip_serializing_if = "Option::is_none")]
5846    pub partition_of: Option<Expression>,
5847    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5848    #[serde(default)]
5849    pub post_table_properties: Vec<Expression>,
5850    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5851    #[serde(default)]
5852    pub mysql_table_options: Vec<(String, String)>,
5853    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5854    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5855    pub inherits: Vec<TableRef>,
5856    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5857    #[serde(default, skip_serializing_if = "Option::is_none")]
5858    pub on_property: Option<OnProperty>,
5859    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5860    #[serde(default)]
5861    pub copy_grants: bool,
5862    /// Snowflake: USING TEMPLATE expression for schema inference
5863    #[serde(default, skip_serializing_if = "Option::is_none")]
5864    pub using_template: Option<Box<Expression>>,
5865    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5866    #[serde(default, skip_serializing_if = "Option::is_none")]
5867    pub rollup: Option<RollupProperty>,
5868}
5869
5870/// Teradata index specification for CREATE TABLE
5871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5872#[cfg_attr(feature = "bindings", derive(TS))]
5873pub struct TeradataIndex {
5874    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5875    pub kind: TeradataIndexKind,
5876    /// Optional index name
5877    pub name: Option<String>,
5878    /// Optional column list
5879    pub columns: Vec<String>,
5880}
5881
5882/// Kind of Teradata index
5883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5884#[cfg_attr(feature = "bindings", derive(TS))]
5885pub enum TeradataIndexKind {
5886    /// NO PRIMARY INDEX
5887    NoPrimary,
5888    /// PRIMARY INDEX
5889    Primary,
5890    /// PRIMARY AMP INDEX
5891    PrimaryAmp,
5892    /// UNIQUE INDEX
5893    Unique,
5894    /// UNIQUE PRIMARY INDEX
5895    UniquePrimary,
5896    /// INDEX (secondary, non-primary)
5897    Secondary,
5898}
5899
5900impl CreateTable {
5901    pub fn new(name: impl Into<String>) -> Self {
5902        Self {
5903            name: TableRef::new(name),
5904            on_cluster: None,
5905            columns: Vec::new(),
5906            constraints: Vec::new(),
5907            if_not_exists: false,
5908            temporary: false,
5909            or_replace: false,
5910            table_modifier: None,
5911            as_select: None,
5912            as_select_parenthesized: false,
5913            on_commit: None,
5914            clone_source: None,
5915            clone_at_clause: None,
5916            shallow_clone: false,
5917            is_copy: false,
5918            leading_comments: Vec::new(),
5919            with_properties: Vec::new(),
5920            teradata_post_name_options: Vec::new(),
5921            with_data: None,
5922            with_statistics: None,
5923            teradata_indexes: Vec::new(),
5924            with_cte: None,
5925            properties: Vec::new(),
5926            partition_of: None,
5927            post_table_properties: Vec::new(),
5928            mysql_table_options: Vec::new(),
5929            inherits: Vec::new(),
5930            on_property: None,
5931            copy_grants: false,
5932            using_template: None,
5933            rollup: None,
5934        }
5935    }
5936}
5937
5938/// Sort order for PRIMARY KEY ASC/DESC
5939#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5940#[cfg_attr(feature = "bindings", derive(TS))]
5941pub enum SortOrder {
5942    Asc,
5943    Desc,
5944}
5945
5946/// Type of column constraint for tracking order
5947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5948#[cfg_attr(feature = "bindings", derive(TS))]
5949pub enum ConstraintType {
5950    NotNull,
5951    Null,
5952    PrimaryKey,
5953    Unique,
5954    Default,
5955    AutoIncrement,
5956    Collate,
5957    Comment,
5958    References,
5959    Check,
5960    GeneratedAsIdentity,
5961    /// Snowflake: TAG (key='value', ...)
5962    Tags,
5963    /// Computed/generated column
5964    ComputedColumn,
5965    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5966    GeneratedAsRow,
5967    /// MySQL: ON UPDATE expression
5968    OnUpdate,
5969    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5970    Path,
5971    /// Redshift: ENCODE encoding_type
5972    Encode,
5973}
5974
5975/// Column definition in CREATE TABLE
5976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5977#[cfg_attr(feature = "bindings", derive(TS))]
5978pub struct ColumnDef {
5979    pub name: Identifier,
5980    pub data_type: DataType,
5981    pub nullable: Option<bool>,
5982    pub default: Option<Expression>,
5983    pub primary_key: bool,
5984    /// Sort order for PRIMARY KEY (ASC/DESC)
5985    #[serde(default)]
5986    pub primary_key_order: Option<SortOrder>,
5987    pub unique: bool,
5988    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5989    #[serde(default)]
5990    pub unique_nulls_not_distinct: bool,
5991    pub auto_increment: bool,
5992    pub comment: Option<String>,
5993    pub constraints: Vec<ColumnConstraint>,
5994    /// Track original order of constraints for accurate regeneration
5995    #[serde(default)]
5996    pub constraint_order: Vec<ConstraintType>,
5997    /// Teradata: FORMAT 'pattern'
5998    #[serde(default)]
5999    pub format: Option<String>,
6000    /// Teradata: TITLE 'title'
6001    #[serde(default)]
6002    pub title: Option<String>,
6003    /// Teradata: INLINE LENGTH n
6004    #[serde(default)]
6005    pub inline_length: Option<u64>,
6006    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
6007    #[serde(default)]
6008    pub compress: Option<Vec<Expression>>,
6009    /// Teradata: CHARACTER SET name
6010    #[serde(default)]
6011    pub character_set: Option<String>,
6012    /// Teradata: UPPERCASE
6013    #[serde(default)]
6014    pub uppercase: bool,
6015    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
6016    #[serde(default)]
6017    pub casespecific: Option<bool>,
6018    /// Snowflake: AUTOINCREMENT START value
6019    #[serde(default)]
6020    pub auto_increment_start: Option<Box<Expression>>,
6021    /// Snowflake: AUTOINCREMENT INCREMENT value
6022    #[serde(default)]
6023    pub auto_increment_increment: Option<Box<Expression>>,
6024    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
6025    #[serde(default)]
6026    pub auto_increment_order: Option<bool>,
6027    /// MySQL: UNSIGNED modifier
6028    #[serde(default)]
6029    pub unsigned: bool,
6030    /// MySQL: ZEROFILL modifier
6031    #[serde(default)]
6032    pub zerofill: bool,
6033    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
6034    #[serde(default, skip_serializing_if = "Option::is_none")]
6035    pub on_update: Option<Expression>,
6036    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
6037    #[serde(default, skip_serializing_if = "Option::is_none")]
6038    pub unique_constraint_name: Option<String>,
6039    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
6040    #[serde(default, skip_serializing_if = "Option::is_none")]
6041    pub not_null_constraint_name: Option<String>,
6042    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
6043    #[serde(default, skip_serializing_if = "Option::is_none")]
6044    pub primary_key_constraint_name: Option<String>,
6045    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
6046    #[serde(default, skip_serializing_if = "Option::is_none")]
6047    pub check_constraint_name: Option<String>,
6048    /// BigQuery: OPTIONS (key=value, ...) on column
6049    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6050    pub options: Vec<Expression>,
6051    /// SQLite: Column definition without explicit type
6052    #[serde(default)]
6053    pub no_type: bool,
6054    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
6055    #[serde(default, skip_serializing_if = "Option::is_none")]
6056    pub encoding: Option<String>,
6057    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
6058    #[serde(default, skip_serializing_if = "Option::is_none")]
6059    pub codec: Option<String>,
6060    /// ClickHouse: EPHEMERAL [expr] modifier
6061    #[serde(default, skip_serializing_if = "Option::is_none")]
6062    pub ephemeral: Option<Option<Box<Expression>>>,
6063    /// ClickHouse: MATERIALIZED expr modifier
6064    #[serde(default, skip_serializing_if = "Option::is_none")]
6065    pub materialized_expr: Option<Box<Expression>>,
6066    /// ClickHouse: ALIAS expr modifier
6067    #[serde(default, skip_serializing_if = "Option::is_none")]
6068    pub alias_expr: Option<Box<Expression>>,
6069    /// ClickHouse: TTL expr modifier on columns
6070    #[serde(default, skip_serializing_if = "Option::is_none")]
6071    pub ttl_expr: Option<Box<Expression>>,
6072    /// TSQL: NOT FOR REPLICATION
6073    #[serde(default)]
6074    pub not_for_replication: bool,
6075}
6076
6077impl ColumnDef {
6078    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
6079        Self {
6080            name: Identifier::new(name),
6081            data_type,
6082            nullable: None,
6083            default: None,
6084            primary_key: false,
6085            primary_key_order: None,
6086            unique: false,
6087            unique_nulls_not_distinct: false,
6088            auto_increment: false,
6089            comment: None,
6090            constraints: Vec::new(),
6091            constraint_order: Vec::new(),
6092            format: None,
6093            title: None,
6094            inline_length: None,
6095            compress: None,
6096            character_set: None,
6097            uppercase: false,
6098            casespecific: None,
6099            auto_increment_start: None,
6100            auto_increment_increment: None,
6101            auto_increment_order: None,
6102            unsigned: false,
6103            zerofill: false,
6104            on_update: None,
6105            unique_constraint_name: None,
6106            not_null_constraint_name: None,
6107            primary_key_constraint_name: None,
6108            check_constraint_name: None,
6109            options: Vec::new(),
6110            no_type: false,
6111            encoding: None,
6112            codec: None,
6113            ephemeral: None,
6114            materialized_expr: None,
6115            alias_expr: None,
6116            ttl_expr: None,
6117            not_for_replication: false,
6118        }
6119    }
6120}
6121
6122/// Column-level constraint
6123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6124#[cfg_attr(feature = "bindings", derive(TS))]
6125pub enum ColumnConstraint {
6126    NotNull,
6127    Null,
6128    Unique,
6129    PrimaryKey,
6130    Default(Expression),
6131    Check(Expression),
6132    References(ForeignKeyRef),
6133    GeneratedAsIdentity(GeneratedAsIdentity),
6134    Collate(Identifier),
6135    Comment(String),
6136    /// Snowflake: TAG (key='value', ...)
6137    Tags(Tags),
6138    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
6139    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
6140    ComputedColumn(ComputedColumn),
6141    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6142    GeneratedAsRow(GeneratedAsRow),
6143    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
6144    Path(Expression),
6145}
6146
6147/// Computed/generated column constraint
6148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6149#[cfg_attr(feature = "bindings", derive(TS))]
6150pub struct ComputedColumn {
6151    /// The expression that computes the column value
6152    pub expression: Box<Expression>,
6153    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
6154    #[serde(default)]
6155    pub persisted: bool,
6156    /// NOT NULL (TSQL computed columns)
6157    #[serde(default)]
6158    pub not_null: bool,
6159    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
6160    /// When None, defaults to dialect-appropriate output
6161    #[serde(default)]
6162    pub persistence_kind: Option<String>,
6163    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
6164    #[serde(default, skip_serializing_if = "Option::is_none")]
6165    pub data_type: Option<DataType>,
6166}
6167
6168/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6170#[cfg_attr(feature = "bindings", derive(TS))]
6171pub struct GeneratedAsRow {
6172    /// true = ROW START, false = ROW END
6173    pub start: bool,
6174    /// HIDDEN modifier
6175    #[serde(default)]
6176    pub hidden: bool,
6177}
6178
6179/// Generated identity column constraint
6180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6181#[cfg_attr(feature = "bindings", derive(TS))]
6182pub struct GeneratedAsIdentity {
6183    /// True for ALWAYS, False for BY DEFAULT
6184    pub always: bool,
6185    /// ON NULL (only valid with BY DEFAULT)
6186    pub on_null: bool,
6187    /// START WITH value
6188    pub start: Option<Box<Expression>>,
6189    /// INCREMENT BY value
6190    pub increment: Option<Box<Expression>>,
6191    /// MINVALUE
6192    pub minvalue: Option<Box<Expression>>,
6193    /// MAXVALUE
6194    pub maxvalue: Option<Box<Expression>>,
6195    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
6196    pub cycle: Option<bool>,
6197}
6198
6199/// Constraint modifiers (shared between table-level constraints)
6200#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
6201#[cfg_attr(feature = "bindings", derive(TS))]
6202pub struct ConstraintModifiers {
6203    /// ENFORCED / NOT ENFORCED
6204    pub enforced: Option<bool>,
6205    /// DEFERRABLE / NOT DEFERRABLE
6206    pub deferrable: Option<bool>,
6207    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
6208    pub initially_deferred: Option<bool>,
6209    /// NORELY (Oracle)
6210    pub norely: bool,
6211    /// RELY (Oracle)
6212    pub rely: bool,
6213    /// USING index type (MySQL): BTREE or HASH
6214    #[serde(default)]
6215    pub using: Option<String>,
6216    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
6217    #[serde(default)]
6218    pub using_before_columns: bool,
6219    /// MySQL index COMMENT 'text'
6220    #[serde(default, skip_serializing_if = "Option::is_none")]
6221    pub comment: Option<String>,
6222    /// MySQL index VISIBLE/INVISIBLE
6223    #[serde(default, skip_serializing_if = "Option::is_none")]
6224    pub visible: Option<bool>,
6225    /// MySQL ENGINE_ATTRIBUTE = 'value'
6226    #[serde(default, skip_serializing_if = "Option::is_none")]
6227    pub engine_attribute: Option<String>,
6228    /// MySQL WITH PARSER name
6229    #[serde(default, skip_serializing_if = "Option::is_none")]
6230    pub with_parser: Option<String>,
6231    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
6232    #[serde(default)]
6233    pub not_valid: bool,
6234    /// TSQL CLUSTERED/NONCLUSTERED modifier
6235    #[serde(default, skip_serializing_if = "Option::is_none")]
6236    pub clustered: Option<String>,
6237    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
6238    #[serde(default, skip_serializing_if = "Option::is_none")]
6239    pub on_conflict: Option<String>,
6240    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
6241    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6242    pub with_options: Vec<(String, String)>,
6243    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
6244    #[serde(default, skip_serializing_if = "Option::is_none")]
6245    pub on_filegroup: Option<Identifier>,
6246}
6247
6248/// Table-level constraint
6249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6250#[cfg_attr(feature = "bindings", derive(TS))]
6251pub enum TableConstraint {
6252    PrimaryKey {
6253        name: Option<Identifier>,
6254        columns: Vec<Identifier>,
6255        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
6256        #[serde(default)]
6257        include_columns: Vec<Identifier>,
6258        #[serde(default)]
6259        modifiers: ConstraintModifiers,
6260        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
6261        #[serde(default)]
6262        has_constraint_keyword: bool,
6263    },
6264    Unique {
6265        name: Option<Identifier>,
6266        columns: Vec<Identifier>,
6267        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
6268        #[serde(default)]
6269        columns_parenthesized: bool,
6270        #[serde(default)]
6271        modifiers: ConstraintModifiers,
6272        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
6273        #[serde(default)]
6274        has_constraint_keyword: bool,
6275        /// PostgreSQL 15+: NULLS NOT DISTINCT
6276        #[serde(default)]
6277        nulls_not_distinct: bool,
6278    },
6279    ForeignKey {
6280        name: Option<Identifier>,
6281        columns: Vec<Identifier>,
6282        #[serde(default)]
6283        references: Option<ForeignKeyRef>,
6284        /// ON DELETE action when REFERENCES is absent
6285        #[serde(default)]
6286        on_delete: Option<ReferentialAction>,
6287        /// ON UPDATE action when REFERENCES is absent
6288        #[serde(default)]
6289        on_update: Option<ReferentialAction>,
6290        #[serde(default)]
6291        modifiers: ConstraintModifiers,
6292    },
6293    Check {
6294        name: Option<Identifier>,
6295        expression: Expression,
6296        #[serde(default)]
6297        modifiers: ConstraintModifiers,
6298    },
6299    /// INDEX / KEY constraint (MySQL)
6300    Index {
6301        name: Option<Identifier>,
6302        columns: Vec<Identifier>,
6303        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
6304        #[serde(default)]
6305        kind: Option<String>,
6306        #[serde(default)]
6307        modifiers: ConstraintModifiers,
6308        /// True if KEY keyword was used instead of INDEX
6309        #[serde(default)]
6310        use_key_keyword: bool,
6311        /// ClickHouse: indexed expression (instead of columns)
6312        #[serde(default, skip_serializing_if = "Option::is_none")]
6313        expression: Option<Box<Expression>>,
6314        /// ClickHouse: TYPE type_func(args)
6315        #[serde(default, skip_serializing_if = "Option::is_none")]
6316        index_type: Option<Box<Expression>>,
6317        /// ClickHouse: GRANULARITY n
6318        #[serde(default, skip_serializing_if = "Option::is_none")]
6319        granularity: Option<Box<Expression>>,
6320    },
6321    /// ClickHouse PROJECTION definition
6322    Projection {
6323        name: Identifier,
6324        expression: Expression,
6325    },
6326    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
6327    Like {
6328        source: TableRef,
6329        /// Options as (INCLUDING|EXCLUDING, property) pairs
6330        options: Vec<(LikeOptionAction, String)>,
6331    },
6332    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
6333    PeriodForSystemTime {
6334        start_col: Identifier,
6335        end_col: Identifier,
6336    },
6337    /// PostgreSQL EXCLUDE constraint
6338    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
6339    Exclude {
6340        name: Option<Identifier>,
6341        /// Index access method (gist, btree, etc.)
6342        #[serde(default)]
6343        using: Option<String>,
6344        /// Elements: (expression, operator) pairs
6345        elements: Vec<ExcludeElement>,
6346        /// INCLUDE columns
6347        #[serde(default)]
6348        include_columns: Vec<Identifier>,
6349        /// WHERE predicate
6350        #[serde(default)]
6351        where_clause: Option<Box<Expression>>,
6352        /// WITH (storage_parameters)
6353        #[serde(default)]
6354        with_params: Vec<(String, String)>,
6355        /// USING INDEX TABLESPACE tablespace_name
6356        #[serde(default)]
6357        using_index_tablespace: Option<String>,
6358        #[serde(default)]
6359        modifiers: ConstraintModifiers,
6360    },
6361    /// Snowflake TAG clause: TAG (key='value', key2='value2')
6362    Tags(Tags),
6363    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
6364    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
6365    /// for all deferrable constraints in the table
6366    InitiallyDeferred {
6367        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
6368        deferred: bool,
6369    },
6370}
6371
6372/// Element in an EXCLUDE constraint: expression WITH operator
6373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6374#[cfg_attr(feature = "bindings", derive(TS))]
6375pub struct ExcludeElement {
6376    /// The column expression (may include operator class, ordering, nulls)
6377    pub expression: String,
6378    /// The operator (e.g., &&, =)
6379    pub operator: String,
6380}
6381
6382/// Action for LIKE clause options
6383#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6384#[cfg_attr(feature = "bindings", derive(TS))]
6385pub enum LikeOptionAction {
6386    Including,
6387    Excluding,
6388}
6389
6390/// MATCH type for foreign keys
6391#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6392#[cfg_attr(feature = "bindings", derive(TS))]
6393pub enum MatchType {
6394    Full,
6395    Partial,
6396    Simple,
6397}
6398
6399/// Foreign key reference
6400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6401#[cfg_attr(feature = "bindings", derive(TS))]
6402pub struct ForeignKeyRef {
6403    pub table: TableRef,
6404    pub columns: Vec<Identifier>,
6405    pub on_delete: Option<ReferentialAction>,
6406    pub on_update: Option<ReferentialAction>,
6407    /// True if ON UPDATE appears before ON DELETE in the original SQL
6408    #[serde(default)]
6409    pub on_update_first: bool,
6410    /// MATCH clause (FULL, PARTIAL, SIMPLE)
6411    #[serde(default)]
6412    pub match_type: Option<MatchType>,
6413    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
6414    #[serde(default)]
6415    pub match_after_actions: bool,
6416    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
6417    #[serde(default)]
6418    pub constraint_name: Option<String>,
6419    /// DEFERRABLE / NOT DEFERRABLE
6420    #[serde(default)]
6421    pub deferrable: Option<bool>,
6422    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
6423    #[serde(default)]
6424    pub has_foreign_key_keywords: bool,
6425}
6426
6427/// Referential action for foreign keys
6428#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6429#[cfg_attr(feature = "bindings", derive(TS))]
6430pub enum ReferentialAction {
6431    Cascade,
6432    SetNull,
6433    SetDefault,
6434    Restrict,
6435    NoAction,
6436}
6437
6438/// DROP TABLE statement
6439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6440#[cfg_attr(feature = "bindings", derive(TS))]
6441pub struct DropTable {
6442    pub names: Vec<TableRef>,
6443    pub if_exists: bool,
6444    pub cascade: bool,
6445    /// Oracle: CASCADE CONSTRAINTS
6446    #[serde(default)]
6447    pub cascade_constraints: bool,
6448    /// Oracle: PURGE
6449    #[serde(default)]
6450    pub purge: bool,
6451    /// Comments that appear before the DROP keyword (e.g., leading line comments)
6452    #[serde(default)]
6453    pub leading_comments: Vec<String>,
6454    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
6455    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
6456    #[serde(default, skip_serializing_if = "Option::is_none")]
6457    pub object_id_args: Option<String>,
6458}
6459
6460impl DropTable {
6461    pub fn new(name: impl Into<String>) -> Self {
6462        Self {
6463            names: vec![TableRef::new(name)],
6464            if_exists: false,
6465            cascade: false,
6466            cascade_constraints: false,
6467            purge: false,
6468            leading_comments: Vec::new(),
6469            object_id_args: None,
6470        }
6471    }
6472}
6473
6474/// ALTER TABLE statement
6475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6476#[cfg_attr(feature = "bindings", derive(TS))]
6477pub struct AlterTable {
6478    pub name: TableRef,
6479    pub actions: Vec<AlterTableAction>,
6480    /// IF EXISTS clause
6481    #[serde(default)]
6482    pub if_exists: bool,
6483    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
6484    #[serde(default, skip_serializing_if = "Option::is_none")]
6485    pub algorithm: Option<String>,
6486    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
6487    #[serde(default, skip_serializing_if = "Option::is_none")]
6488    pub lock: Option<String>,
6489    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
6490    #[serde(default, skip_serializing_if = "Option::is_none")]
6491    pub with_check: Option<String>,
6492    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
6493    #[serde(default, skip_serializing_if = "Option::is_none")]
6494    pub partition: Option<Vec<(Identifier, Expression)>>,
6495    /// ClickHouse: ON CLUSTER clause for distributed DDL
6496    #[serde(default, skip_serializing_if = "Option::is_none")]
6497    pub on_cluster: Option<OnCluster>,
6498}
6499
6500impl AlterTable {
6501    pub fn new(name: impl Into<String>) -> Self {
6502        Self {
6503            name: TableRef::new(name),
6504            actions: Vec::new(),
6505            if_exists: false,
6506            algorithm: None,
6507            lock: None,
6508            with_check: None,
6509            partition: None,
6510            on_cluster: None,
6511        }
6512    }
6513}
6514
6515/// Column position for ADD COLUMN (MySQL/MariaDB)
6516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6517#[cfg_attr(feature = "bindings", derive(TS))]
6518pub enum ColumnPosition {
6519    First,
6520    After(Identifier),
6521}
6522
6523/// Actions for ALTER TABLE
6524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6525#[cfg_attr(feature = "bindings", derive(TS))]
6526pub enum AlterTableAction {
6527    AddColumn {
6528        column: ColumnDef,
6529        if_not_exists: bool,
6530        position: Option<ColumnPosition>,
6531    },
6532    DropColumn {
6533        name: Identifier,
6534        if_exists: bool,
6535        cascade: bool,
6536    },
6537    RenameColumn {
6538        old_name: Identifier,
6539        new_name: Identifier,
6540        if_exists: bool,
6541    },
6542    AlterColumn {
6543        name: Identifier,
6544        action: AlterColumnAction,
6545        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
6546        #[serde(default)]
6547        use_modify_keyword: bool,
6548    },
6549    RenameTable(TableRef),
6550    AddConstraint(TableConstraint),
6551    DropConstraint {
6552        name: Identifier,
6553        if_exists: bool,
6554    },
6555    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
6556    DropForeignKey {
6557        name: Identifier,
6558    },
6559    /// DROP PARTITION action (Hive/BigQuery)
6560    DropPartition {
6561        /// List of partitions to drop (each partition is a list of key=value pairs)
6562        partitions: Vec<Vec<(Identifier, Expression)>>,
6563        if_exists: bool,
6564    },
6565    /// ADD PARTITION action (Hive/Spark)
6566    AddPartition {
6567        /// The partition expression
6568        partition: Expression,
6569        if_not_exists: bool,
6570        location: Option<Expression>,
6571    },
6572    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6573    Delete {
6574        where_clause: Expression,
6575    },
6576    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6577    SwapWith(TableRef),
6578    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6579    SetProperty {
6580        properties: Vec<(String, Expression)>,
6581    },
6582    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6583    UnsetProperty {
6584        properties: Vec<String>,
6585    },
6586    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6587    ClusterBy {
6588        expressions: Vec<Expression>,
6589    },
6590    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6591    SetTag {
6592        expressions: Vec<(String, Expression)>,
6593    },
6594    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6595    UnsetTag {
6596        names: Vec<String>,
6597    },
6598    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6599    SetOptions {
6600        expressions: Vec<Expression>,
6601    },
6602    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6603    AlterIndex {
6604        name: Identifier,
6605        visible: bool,
6606    },
6607    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6608    SetAttribute {
6609        attribute: String,
6610    },
6611    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6612    SetStageFileFormat {
6613        options: Option<Expression>,
6614    },
6615    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6616    SetStageCopyOptions {
6617        options: Option<Expression>,
6618    },
6619    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6620    AddColumns {
6621        columns: Vec<ColumnDef>,
6622        cascade: bool,
6623    },
6624    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6625    DropColumns {
6626        names: Vec<Identifier>,
6627    },
6628    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6629    /// In SingleStore, data_type can be omitted for simple column renames
6630    ChangeColumn {
6631        old_name: Identifier,
6632        new_name: Identifier,
6633        #[serde(default, skip_serializing_if = "Option::is_none")]
6634        data_type: Option<DataType>,
6635        comment: Option<String>,
6636        #[serde(default)]
6637        cascade: bool,
6638    },
6639    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6640    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6641    AlterSortKey {
6642        /// AUTO or NONE keyword
6643        this: Option<String>,
6644        /// Column list for (col1, col2) syntax
6645        expressions: Vec<Expression>,
6646        /// Whether COMPOUND keyword was present
6647        compound: bool,
6648    },
6649    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6650    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6651    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6652    AlterDistStyle {
6653        /// Distribution style: ALL, EVEN, AUTO, or KEY
6654        style: String,
6655        /// DISTKEY column (only when style is KEY)
6656        distkey: Option<Identifier>,
6657    },
6658    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6659    SetTableProperties {
6660        properties: Vec<(Expression, Expression)>,
6661    },
6662    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6663    SetLocation {
6664        location: String,
6665    },
6666    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6667    SetFileFormat {
6668        format: String,
6669    },
6670    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6671    ReplacePartition {
6672        partition: Expression,
6673        source: Option<Box<Expression>>,
6674    },
6675    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6676    Raw {
6677        sql: String,
6678    },
6679}
6680
6681/// Actions for ALTER COLUMN
6682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6683#[cfg_attr(feature = "bindings", derive(TS))]
6684pub enum AlterColumnAction {
6685    SetDataType {
6686        data_type: DataType,
6687        /// USING expression for type conversion (PostgreSQL)
6688        using: Option<Expression>,
6689        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6690        #[serde(default, skip_serializing_if = "Option::is_none")]
6691        collate: Option<String>,
6692    },
6693    SetDefault(Expression),
6694    DropDefault,
6695    SetNotNull,
6696    DropNotNull,
6697    /// Set column comment
6698    Comment(String),
6699    /// MySQL: SET VISIBLE
6700    SetVisible,
6701    /// MySQL: SET INVISIBLE
6702    SetInvisible,
6703}
6704
6705/// CREATE INDEX statement
6706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6707#[cfg_attr(feature = "bindings", derive(TS))]
6708pub struct CreateIndex {
6709    pub name: Identifier,
6710    pub table: TableRef,
6711    pub columns: Vec<IndexColumn>,
6712    pub unique: bool,
6713    pub if_not_exists: bool,
6714    pub using: Option<String>,
6715    /// TSQL CLUSTERED/NONCLUSTERED modifier
6716    #[serde(default)]
6717    pub clustered: Option<String>,
6718    /// PostgreSQL CONCURRENTLY modifier
6719    #[serde(default)]
6720    pub concurrently: bool,
6721    /// PostgreSQL WHERE clause for partial indexes
6722    #[serde(default)]
6723    pub where_clause: Option<Box<Expression>>,
6724    /// PostgreSQL INCLUDE columns
6725    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6726    pub include_columns: Vec<Identifier>,
6727    /// TSQL WITH options (e.g., allow_page_locks=on)
6728    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6729    pub with_options: Vec<(String, String)>,
6730    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6731    #[serde(default)]
6732    pub on_filegroup: Option<String>,
6733}
6734
6735impl CreateIndex {
6736    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6737        Self {
6738            name: Identifier::new(name),
6739            table: TableRef::new(table),
6740            columns: Vec::new(),
6741            unique: false,
6742            if_not_exists: false,
6743            using: None,
6744            clustered: None,
6745            concurrently: false,
6746            where_clause: None,
6747            include_columns: Vec::new(),
6748            with_options: Vec::new(),
6749            on_filegroup: None,
6750        }
6751    }
6752}
6753
6754/// Index column specification
6755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6756#[cfg_attr(feature = "bindings", derive(TS))]
6757pub struct IndexColumn {
6758    pub column: Identifier,
6759    pub desc: bool,
6760    /// Explicit ASC keyword was present
6761    #[serde(default)]
6762    pub asc: bool,
6763    pub nulls_first: Option<bool>,
6764    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6765    #[serde(default, skip_serializing_if = "Option::is_none")]
6766    pub opclass: Option<String>,
6767}
6768
6769/// DROP INDEX statement
6770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6771#[cfg_attr(feature = "bindings", derive(TS))]
6772pub struct DropIndex {
6773    pub name: Identifier,
6774    pub table: Option<TableRef>,
6775    pub if_exists: bool,
6776    /// PostgreSQL CONCURRENTLY modifier
6777    #[serde(default)]
6778    pub concurrently: bool,
6779}
6780
6781impl DropIndex {
6782    pub fn new(name: impl Into<String>) -> Self {
6783        Self {
6784            name: Identifier::new(name),
6785            table: None,
6786            if_exists: false,
6787            concurrently: false,
6788        }
6789    }
6790}
6791
6792/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6794#[cfg_attr(feature = "bindings", derive(TS))]
6795pub struct ViewColumn {
6796    pub name: Identifier,
6797    pub comment: Option<String>,
6798    /// BigQuery: OPTIONS (key=value, ...) on column
6799    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6800    pub options: Vec<Expression>,
6801}
6802
6803impl ViewColumn {
6804    pub fn new(name: impl Into<String>) -> Self {
6805        Self {
6806            name: Identifier::new(name),
6807            comment: None,
6808            options: Vec::new(),
6809        }
6810    }
6811
6812    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6813        Self {
6814            name: Identifier::new(name),
6815            comment: Some(comment.into()),
6816            options: Vec::new(),
6817        }
6818    }
6819}
6820
6821/// CREATE VIEW statement
6822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6823#[cfg_attr(feature = "bindings", derive(TS))]
6824pub struct CreateView {
6825    pub name: TableRef,
6826    pub columns: Vec<ViewColumn>,
6827    pub query: Expression,
6828    pub or_replace: bool,
6829    pub if_not_exists: bool,
6830    pub materialized: bool,
6831    pub temporary: bool,
6832    /// Snowflake: SECURE VIEW
6833    #[serde(default)]
6834    pub secure: bool,
6835    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6836    #[serde(skip_serializing_if = "Option::is_none")]
6837    pub algorithm: Option<String>,
6838    /// MySQL: DEFINER=user@host
6839    #[serde(skip_serializing_if = "Option::is_none")]
6840    pub definer: Option<String>,
6841    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6842    #[serde(skip_serializing_if = "Option::is_none")]
6843    pub security: Option<FunctionSecurity>,
6844    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6845    #[serde(default = "default_true")]
6846    pub security_sql_style: bool,
6847    /// Whether the query was parenthesized: AS (SELECT ...)
6848    #[serde(default)]
6849    pub query_parenthesized: bool,
6850    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6851    #[serde(skip_serializing_if = "Option::is_none")]
6852    pub locking_mode: Option<String>,
6853    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6854    #[serde(skip_serializing_if = "Option::is_none")]
6855    pub locking_access: Option<String>,
6856    /// Snowflake: COPY GRANTS
6857    #[serde(default)]
6858    pub copy_grants: bool,
6859    /// Snowflake: COMMENT = 'text'
6860    #[serde(skip_serializing_if = "Option::is_none", default)]
6861    pub comment: Option<String>,
6862    /// Snowflake: TAG (name='value', ...)
6863    #[serde(default)]
6864    pub tags: Vec<(String, String)>,
6865    /// BigQuery: OPTIONS (key=value, ...)
6866    #[serde(default)]
6867    pub options: Vec<Expression>,
6868    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6869    #[serde(skip_serializing_if = "Option::is_none", default)]
6870    pub build: Option<String>,
6871    /// Doris: REFRESH property for materialized views
6872    #[serde(skip_serializing_if = "Option::is_none", default)]
6873    pub refresh: Option<Box<RefreshTriggerProperty>>,
6874    /// Doris: Schema with typed column definitions for materialized views
6875    /// This is used instead of `columns` when the view has typed column definitions
6876    #[serde(skip_serializing_if = "Option::is_none", default)]
6877    pub schema: Option<Box<Schema>>,
6878    /// Doris: KEY (columns) for materialized views
6879    #[serde(skip_serializing_if = "Option::is_none", default)]
6880    pub unique_key: Option<Box<UniqueKeyProperty>>,
6881    /// Redshift: WITH NO SCHEMA BINDING
6882    #[serde(default)]
6883    pub no_schema_binding: bool,
6884    /// Redshift: AUTO REFRESH YES|NO for materialized views
6885    #[serde(skip_serializing_if = "Option::is_none", default)]
6886    pub auto_refresh: Option<bool>,
6887    /// ClickHouse: ON CLUSTER clause
6888    #[serde(default, skip_serializing_if = "Option::is_none")]
6889    pub on_cluster: Option<OnCluster>,
6890    /// ClickHouse: TO destination_table
6891    #[serde(default, skip_serializing_if = "Option::is_none")]
6892    pub to_table: Option<TableRef>,
6893    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6894    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6895    pub table_properties: Vec<Expression>,
6896}
6897
6898impl CreateView {
6899    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6900        Self {
6901            name: TableRef::new(name),
6902            columns: Vec::new(),
6903            query,
6904            or_replace: false,
6905            if_not_exists: false,
6906            materialized: false,
6907            temporary: false,
6908            secure: false,
6909            algorithm: None,
6910            definer: None,
6911            security: None,
6912            security_sql_style: true,
6913            query_parenthesized: false,
6914            locking_mode: None,
6915            locking_access: None,
6916            copy_grants: false,
6917            comment: None,
6918            tags: Vec::new(),
6919            options: Vec::new(),
6920            build: None,
6921            refresh: None,
6922            schema: None,
6923            unique_key: None,
6924            no_schema_binding: false,
6925            auto_refresh: None,
6926            on_cluster: None,
6927            to_table: None,
6928            table_properties: Vec::new(),
6929        }
6930    }
6931}
6932
6933/// DROP VIEW statement
6934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6935#[cfg_attr(feature = "bindings", derive(TS))]
6936pub struct DropView {
6937    pub name: TableRef,
6938    pub if_exists: bool,
6939    pub materialized: bool,
6940}
6941
6942impl DropView {
6943    pub fn new(name: impl Into<String>) -> Self {
6944        Self {
6945            name: TableRef::new(name),
6946            if_exists: false,
6947            materialized: false,
6948        }
6949    }
6950}
6951
6952/// TRUNCATE TABLE statement
6953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6954#[cfg_attr(feature = "bindings", derive(TS))]
6955pub struct Truncate {
6956    /// Target of TRUNCATE (TABLE vs DATABASE)
6957    #[serde(default)]
6958    pub target: TruncateTarget,
6959    /// IF EXISTS clause
6960    #[serde(default)]
6961    pub if_exists: bool,
6962    pub table: TableRef,
6963    /// ClickHouse: ON CLUSTER clause for distributed DDL
6964    #[serde(default, skip_serializing_if = "Option::is_none")]
6965    pub on_cluster: Option<OnCluster>,
6966    pub cascade: bool,
6967    /// Additional tables for multi-table TRUNCATE
6968    #[serde(default)]
6969    pub extra_tables: Vec<TruncateTableEntry>,
6970    /// RESTART IDENTITY or CONTINUE IDENTITY
6971    #[serde(default)]
6972    pub identity: Option<TruncateIdentity>,
6973    /// RESTRICT option (alternative to CASCADE)
6974    #[serde(default)]
6975    pub restrict: bool,
6976    /// Hive PARTITION clause: PARTITION(key=value, ...)
6977    #[serde(default, skip_serializing_if = "Option::is_none")]
6978    pub partition: Option<Box<Expression>>,
6979}
6980
6981/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6983#[cfg_attr(feature = "bindings", derive(TS))]
6984pub struct TruncateTableEntry {
6985    pub table: TableRef,
6986    /// Whether the table has a * suffix (inherit children)
6987    #[serde(default)]
6988    pub star: bool,
6989}
6990
6991/// TRUNCATE target type
6992#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6993#[cfg_attr(feature = "bindings", derive(TS))]
6994pub enum TruncateTarget {
6995    Table,
6996    Database,
6997}
6998
6999impl Default for TruncateTarget {
7000    fn default() -> Self {
7001        TruncateTarget::Table
7002    }
7003}
7004
7005/// TRUNCATE identity option
7006#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7007#[cfg_attr(feature = "bindings", derive(TS))]
7008pub enum TruncateIdentity {
7009    Restart,
7010    Continue,
7011}
7012
7013impl Truncate {
7014    pub fn new(table: impl Into<String>) -> Self {
7015        Self {
7016            target: TruncateTarget::Table,
7017            if_exists: false,
7018            table: TableRef::new(table),
7019            on_cluster: None,
7020            cascade: false,
7021            extra_tables: Vec::new(),
7022            identity: None,
7023            restrict: false,
7024            partition: None,
7025        }
7026    }
7027}
7028
7029/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
7030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7031#[cfg_attr(feature = "bindings", derive(TS))]
7032pub struct Use {
7033    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
7034    pub kind: Option<UseKind>,
7035    /// The name of the object
7036    pub this: Identifier,
7037}
7038
7039/// Kind of USE statement
7040#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7041#[cfg_attr(feature = "bindings", derive(TS))]
7042pub enum UseKind {
7043    Database,
7044    Schema,
7045    Role,
7046    Warehouse,
7047    Catalog,
7048    /// Snowflake: USE SECONDARY ROLES ALL|NONE
7049    SecondaryRoles,
7050}
7051
7052/// SET variable statement
7053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7054#[cfg_attr(feature = "bindings", derive(TS))]
7055pub struct SetStatement {
7056    /// The items being set
7057    pub items: Vec<SetItem>,
7058}
7059
7060/// A single SET item (variable assignment)
7061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7062#[cfg_attr(feature = "bindings", derive(TS))]
7063pub struct SetItem {
7064    /// The variable name
7065    pub name: Expression,
7066    /// The value to set
7067    pub value: Expression,
7068    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
7069    pub kind: Option<String>,
7070    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
7071    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7072    pub no_equals: bool,
7073}
7074
7075/// CACHE TABLE statement (Spark)
7076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7077#[cfg_attr(feature = "bindings", derive(TS))]
7078pub struct Cache {
7079    /// The table to cache
7080    pub table: Identifier,
7081    /// LAZY keyword - defer caching until first use
7082    pub lazy: bool,
7083    /// Optional OPTIONS clause (key-value pairs)
7084    pub options: Vec<(Expression, Expression)>,
7085    /// Optional AS clause with query
7086    pub query: Option<Expression>,
7087}
7088
7089/// UNCACHE TABLE statement (Spark)
7090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7091#[cfg_attr(feature = "bindings", derive(TS))]
7092pub struct Uncache {
7093    /// The table to uncache
7094    pub table: Identifier,
7095    /// IF EXISTS clause
7096    pub if_exists: bool,
7097}
7098
7099/// LOAD DATA statement (Hive)
7100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7101#[cfg_attr(feature = "bindings", derive(TS))]
7102pub struct LoadData {
7103    /// LOCAL keyword - load from local filesystem
7104    pub local: bool,
7105    /// The path to load data from (INPATH value)
7106    pub inpath: String,
7107    /// Whether to overwrite existing data
7108    pub overwrite: bool,
7109    /// The target table
7110    pub table: Expression,
7111    /// Optional PARTITION clause with key-value pairs
7112    pub partition: Vec<(Identifier, Expression)>,
7113    /// Optional INPUTFORMAT clause
7114    pub input_format: Option<String>,
7115    /// Optional SERDE clause
7116    pub serde: Option<String>,
7117}
7118
7119/// PRAGMA statement (SQLite)
7120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7121#[cfg_attr(feature = "bindings", derive(TS))]
7122pub struct Pragma {
7123    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
7124    pub schema: Option<Identifier>,
7125    /// The pragma name
7126    pub name: Identifier,
7127    /// Optional value for assignment (PRAGMA name = value)
7128    pub value: Option<Expression>,
7129    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
7130    pub args: Vec<Expression>,
7131}
7132
7133/// A privilege with optional column list for GRANT/REVOKE
7134/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
7135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7136#[cfg_attr(feature = "bindings", derive(TS))]
7137pub struct Privilege {
7138    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
7139    pub name: String,
7140    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
7141    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7142    pub columns: Vec<String>,
7143}
7144
7145/// Principal in GRANT/REVOKE (user, role, etc.)
7146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7147#[cfg_attr(feature = "bindings", derive(TS))]
7148pub struct GrantPrincipal {
7149    /// The name of the principal
7150    pub name: Identifier,
7151    /// Whether prefixed with ROLE keyword
7152    pub is_role: bool,
7153    /// Whether prefixed with GROUP keyword (Redshift)
7154    #[serde(default)]
7155    pub is_group: bool,
7156}
7157
7158/// GRANT statement
7159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7160#[cfg_attr(feature = "bindings", derive(TS))]
7161pub struct Grant {
7162    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
7163    pub privileges: Vec<Privilege>,
7164    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7165    pub kind: Option<String>,
7166    /// The object to grant on
7167    pub securable: Identifier,
7168    /// Function parameter types (for FUNCTION kind)
7169    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7170    pub function_params: Vec<String>,
7171    /// The grantees
7172    pub principals: Vec<GrantPrincipal>,
7173    /// WITH GRANT OPTION
7174    pub grant_option: bool,
7175    /// TSQL: AS principal (the grantor role)
7176    #[serde(default, skip_serializing_if = "Option::is_none")]
7177    pub as_principal: Option<Identifier>,
7178}
7179
7180/// REVOKE statement
7181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7182#[cfg_attr(feature = "bindings", derive(TS))]
7183pub struct Revoke {
7184    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
7185    pub privileges: Vec<Privilege>,
7186    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7187    pub kind: Option<String>,
7188    /// The object to revoke from
7189    pub securable: Identifier,
7190    /// Function parameter types (for FUNCTION kind)
7191    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7192    pub function_params: Vec<String>,
7193    /// The grantees
7194    pub principals: Vec<GrantPrincipal>,
7195    /// GRANT OPTION FOR
7196    pub grant_option: bool,
7197    /// CASCADE
7198    pub cascade: bool,
7199    /// RESTRICT
7200    #[serde(default)]
7201    pub restrict: bool,
7202}
7203
7204/// COMMENT ON statement
7205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7206#[cfg_attr(feature = "bindings", derive(TS))]
7207pub struct Comment {
7208    /// The object being commented on
7209    pub this: Expression,
7210    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
7211    pub kind: String,
7212    /// The comment text expression
7213    pub expression: Expression,
7214    /// IF EXISTS clause
7215    pub exists: bool,
7216    /// MATERIALIZED keyword
7217    pub materialized: bool,
7218}
7219
7220// ============================================================================
7221// Phase 4: Additional DDL Statements
7222// ============================================================================
7223
7224/// ALTER VIEW statement
7225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7226#[cfg_attr(feature = "bindings", derive(TS))]
7227pub struct AlterView {
7228    pub name: TableRef,
7229    pub actions: Vec<AlterViewAction>,
7230    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
7231    #[serde(default, skip_serializing_if = "Option::is_none")]
7232    pub algorithm: Option<String>,
7233    /// MySQL: DEFINER = 'user'@'host'
7234    #[serde(default, skip_serializing_if = "Option::is_none")]
7235    pub definer: Option<String>,
7236    /// MySQL: SQL SECURITY = DEFINER|INVOKER
7237    #[serde(default, skip_serializing_if = "Option::is_none")]
7238    pub sql_security: Option<String>,
7239    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
7240    #[serde(default, skip_serializing_if = "Option::is_none")]
7241    pub with_option: Option<String>,
7242    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
7243    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7244    pub columns: Vec<ViewColumn>,
7245}
7246
7247/// Actions for ALTER VIEW
7248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7249#[cfg_attr(feature = "bindings", derive(TS))]
7250pub enum AlterViewAction {
7251    /// Rename the view
7252    Rename(TableRef),
7253    /// Change owner
7254    OwnerTo(Identifier),
7255    /// Set schema
7256    SetSchema(Identifier),
7257    /// Set authorization (Trino/Presto)
7258    SetAuthorization(String),
7259    /// Alter column
7260    AlterColumn {
7261        name: Identifier,
7262        action: AlterColumnAction,
7263    },
7264    /// Redefine view as query (SELECT, UNION, etc.)
7265    AsSelect(Box<Expression>),
7266    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
7267    SetTblproperties(Vec<(String, String)>),
7268    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
7269    UnsetTblproperties(Vec<String>),
7270}
7271
7272impl AlterView {
7273    pub fn new(name: impl Into<String>) -> Self {
7274        Self {
7275            name: TableRef::new(name),
7276            actions: Vec::new(),
7277            algorithm: None,
7278            definer: None,
7279            sql_security: None,
7280            with_option: None,
7281            columns: Vec::new(),
7282        }
7283    }
7284}
7285
7286/// ALTER INDEX statement
7287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7288#[cfg_attr(feature = "bindings", derive(TS))]
7289pub struct AlterIndex {
7290    pub name: Identifier,
7291    pub table: Option<TableRef>,
7292    pub actions: Vec<AlterIndexAction>,
7293}
7294
7295/// Actions for ALTER INDEX
7296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7297#[cfg_attr(feature = "bindings", derive(TS))]
7298pub enum AlterIndexAction {
7299    /// Rename the index
7300    Rename(Identifier),
7301    /// Set tablespace
7302    SetTablespace(Identifier),
7303    /// Set visibility (MySQL)
7304    Visible(bool),
7305}
7306
7307impl AlterIndex {
7308    pub fn new(name: impl Into<String>) -> Self {
7309        Self {
7310            name: Identifier::new(name),
7311            table: None,
7312            actions: Vec::new(),
7313        }
7314    }
7315}
7316
7317/// CREATE SCHEMA statement
7318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7319#[cfg_attr(feature = "bindings", derive(TS))]
7320pub struct CreateSchema {
7321    pub name: Identifier,
7322    pub if_not_exists: bool,
7323    pub authorization: Option<Identifier>,
7324    #[serde(default)]
7325    pub clone_from: Option<Identifier>,
7326    /// AT/BEFORE clause for time travel (Snowflake)
7327    #[serde(default)]
7328    pub at_clause: Option<Expression>,
7329    /// Schema properties like DEFAULT COLLATE
7330    #[serde(default)]
7331    pub properties: Vec<Expression>,
7332    /// Leading comments before the statement
7333    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7334    pub leading_comments: Vec<String>,
7335}
7336
7337impl CreateSchema {
7338    pub fn new(name: impl Into<String>) -> Self {
7339        Self {
7340            name: Identifier::new(name),
7341            if_not_exists: false,
7342            authorization: None,
7343            clone_from: None,
7344            at_clause: None,
7345            properties: Vec::new(),
7346            leading_comments: Vec::new(),
7347        }
7348    }
7349}
7350
7351/// DROP SCHEMA statement
7352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7353#[cfg_attr(feature = "bindings", derive(TS))]
7354pub struct DropSchema {
7355    pub name: Identifier,
7356    pub if_exists: bool,
7357    pub cascade: bool,
7358}
7359
7360impl DropSchema {
7361    pub fn new(name: impl Into<String>) -> Self {
7362        Self {
7363            name: Identifier::new(name),
7364            if_exists: false,
7365            cascade: false,
7366        }
7367    }
7368}
7369
7370/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
7371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7372#[cfg_attr(feature = "bindings", derive(TS))]
7373pub struct DropNamespace {
7374    pub name: Identifier,
7375    pub if_exists: bool,
7376    pub cascade: bool,
7377}
7378
7379impl DropNamespace {
7380    pub fn new(name: impl Into<String>) -> Self {
7381        Self {
7382            name: Identifier::new(name),
7383            if_exists: false,
7384            cascade: false,
7385        }
7386    }
7387}
7388
7389/// CREATE DATABASE statement
7390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7391#[cfg_attr(feature = "bindings", derive(TS))]
7392pub struct CreateDatabase {
7393    pub name: Identifier,
7394    pub if_not_exists: bool,
7395    pub options: Vec<DatabaseOption>,
7396    /// Snowflake CLONE source
7397    #[serde(default)]
7398    pub clone_from: Option<Identifier>,
7399    /// AT/BEFORE clause for time travel (Snowflake)
7400    #[serde(default)]
7401    pub at_clause: Option<Expression>,
7402}
7403
7404/// Database option
7405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7406#[cfg_attr(feature = "bindings", derive(TS))]
7407pub enum DatabaseOption {
7408    CharacterSet(String),
7409    Collate(String),
7410    Owner(Identifier),
7411    Template(Identifier),
7412    Encoding(String),
7413    Location(String),
7414}
7415
7416impl CreateDatabase {
7417    pub fn new(name: impl Into<String>) -> Self {
7418        Self {
7419            name: Identifier::new(name),
7420            if_not_exists: false,
7421            options: Vec::new(),
7422            clone_from: None,
7423            at_clause: None,
7424        }
7425    }
7426}
7427
7428/// DROP DATABASE statement
7429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7430#[cfg_attr(feature = "bindings", derive(TS))]
7431pub struct DropDatabase {
7432    pub name: Identifier,
7433    pub if_exists: bool,
7434}
7435
7436impl DropDatabase {
7437    pub fn new(name: impl Into<String>) -> Self {
7438        Self {
7439            name: Identifier::new(name),
7440            if_exists: false,
7441        }
7442    }
7443}
7444
7445/// CREATE FUNCTION statement
7446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7447#[cfg_attr(feature = "bindings", derive(TS))]
7448pub struct CreateFunction {
7449    pub name: TableRef,
7450    pub parameters: Vec<FunctionParameter>,
7451    pub return_type: Option<DataType>,
7452    pub body: Option<FunctionBody>,
7453    pub or_replace: bool,
7454    pub if_not_exists: bool,
7455    pub temporary: bool,
7456    pub language: Option<String>,
7457    pub deterministic: Option<bool>,
7458    pub returns_null_on_null_input: Option<bool>,
7459    pub security: Option<FunctionSecurity>,
7460    /// Whether parentheses were present in the original syntax
7461    #[serde(default = "default_true")]
7462    pub has_parens: bool,
7463    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
7464    #[serde(default)]
7465    pub sql_data_access: Option<SqlDataAccess>,
7466    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
7467    #[serde(default, skip_serializing_if = "Option::is_none")]
7468    pub returns_table_body: Option<String>,
7469    /// True if LANGUAGE clause appears before RETURNS clause
7470    #[serde(default)]
7471    pub language_first: bool,
7472    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
7473    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7474    pub set_options: Vec<FunctionSetOption>,
7475    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
7476    #[serde(default)]
7477    pub strict: bool,
7478    /// BigQuery: OPTIONS (key=value, ...)
7479    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7480    pub options: Vec<Expression>,
7481    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
7482    #[serde(default)]
7483    pub is_table_function: bool,
7484    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
7485    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7486    pub property_order: Vec<FunctionPropertyKind>,
7487    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
7488    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7489    pub environment: Vec<Expression>,
7490}
7491
7492/// A SET option in CREATE FUNCTION (PostgreSQL)
7493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7494#[cfg_attr(feature = "bindings", derive(TS))]
7495pub struct FunctionSetOption {
7496    pub name: String,
7497    pub value: FunctionSetValue,
7498}
7499
7500/// The value of a SET option
7501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7502#[cfg_attr(feature = "bindings", derive(TS))]
7503pub enum FunctionSetValue {
7504    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
7505    Value { value: String, use_to: bool },
7506    /// SET key FROM CURRENT
7507    FromCurrent,
7508}
7509
7510/// SQL data access characteristics for functions
7511#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7512#[cfg_attr(feature = "bindings", derive(TS))]
7513pub enum SqlDataAccess {
7514    /// NO SQL
7515    NoSql,
7516    /// CONTAINS SQL
7517    ContainsSql,
7518    /// READS SQL DATA
7519    ReadsSqlData,
7520    /// MODIFIES SQL DATA
7521    ModifiesSqlData,
7522}
7523
7524/// Types of properties in CREATE FUNCTION for tracking their original order
7525#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7526#[cfg_attr(feature = "bindings", derive(TS))]
7527pub enum FunctionPropertyKind {
7528    /// SET option
7529    Set,
7530    /// AS body
7531    As,
7532    /// LANGUAGE clause
7533    Language,
7534    /// IMMUTABLE/VOLATILE/STABLE (determinism)
7535    Determinism,
7536    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
7537    NullInput,
7538    /// SECURITY DEFINER/INVOKER
7539    Security,
7540    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
7541    SqlDataAccess,
7542    /// OPTIONS clause (BigQuery)
7543    Options,
7544    /// ENVIRONMENT clause (Databricks)
7545    Environment,
7546}
7547
7548/// Function parameter
7549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7550#[cfg_attr(feature = "bindings", derive(TS))]
7551pub struct FunctionParameter {
7552    pub name: Option<Identifier>,
7553    pub data_type: DataType,
7554    pub mode: Option<ParameterMode>,
7555    pub default: Option<Expression>,
7556    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
7557    #[serde(default, skip_serializing_if = "Option::is_none")]
7558    pub mode_text: Option<String>,
7559}
7560
7561/// Parameter mode (IN, OUT, INOUT, VARIADIC)
7562#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7563#[cfg_attr(feature = "bindings", derive(TS))]
7564pub enum ParameterMode {
7565    In,
7566    Out,
7567    InOut,
7568    Variadic,
7569}
7570
7571/// Function body
7572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7573#[cfg_attr(feature = "bindings", derive(TS))]
7574pub enum FunctionBody {
7575    /// AS $$ ... $$ (dollar-quoted)
7576    Block(String),
7577    /// AS 'string' (single-quoted string literal body)
7578    StringLiteral(String),
7579    /// AS 'expression'
7580    Expression(Expression),
7581    /// EXTERNAL NAME 'library'
7582    External(String),
7583    /// RETURN expression
7584    Return(Expression),
7585    /// BEGIN ... END block with parsed statements
7586    Statements(Vec<Expression>),
7587    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7588    /// Stores (content, optional_tag)
7589    DollarQuoted {
7590        content: String,
7591        tag: Option<String>,
7592    },
7593}
7594
7595/// Function security (DEFINER, INVOKER, or NONE)
7596#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7597#[cfg_attr(feature = "bindings", derive(TS))]
7598pub enum FunctionSecurity {
7599    Definer,
7600    Invoker,
7601    /// StarRocks/MySQL: SECURITY NONE
7602    None,
7603}
7604
7605impl CreateFunction {
7606    pub fn new(name: impl Into<String>) -> Self {
7607        Self {
7608            name: TableRef::new(name),
7609            parameters: Vec::new(),
7610            return_type: None,
7611            body: None,
7612            or_replace: false,
7613            if_not_exists: false,
7614            temporary: false,
7615            language: None,
7616            deterministic: None,
7617            returns_null_on_null_input: None,
7618            security: None,
7619            has_parens: true,
7620            sql_data_access: None,
7621            returns_table_body: None,
7622            language_first: false,
7623            set_options: Vec::new(),
7624            strict: false,
7625            options: Vec::new(),
7626            is_table_function: false,
7627            property_order: Vec::new(),
7628            environment: Vec::new(),
7629        }
7630    }
7631}
7632
7633/// DROP FUNCTION statement
7634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7635#[cfg_attr(feature = "bindings", derive(TS))]
7636pub struct DropFunction {
7637    pub name: TableRef,
7638    pub parameters: Option<Vec<DataType>>,
7639    pub if_exists: bool,
7640    pub cascade: bool,
7641}
7642
7643impl DropFunction {
7644    pub fn new(name: impl Into<String>) -> Self {
7645        Self {
7646            name: TableRef::new(name),
7647            parameters: None,
7648            if_exists: false,
7649            cascade: false,
7650        }
7651    }
7652}
7653
7654/// CREATE PROCEDURE statement
7655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7656#[cfg_attr(feature = "bindings", derive(TS))]
7657pub struct CreateProcedure {
7658    pub name: TableRef,
7659    pub parameters: Vec<FunctionParameter>,
7660    pub body: Option<FunctionBody>,
7661    pub or_replace: bool,
7662    pub if_not_exists: bool,
7663    pub language: Option<String>,
7664    pub security: Option<FunctionSecurity>,
7665    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7666    #[serde(default)]
7667    pub return_type: Option<DataType>,
7668    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7669    #[serde(default)]
7670    pub execute_as: Option<String>,
7671    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7672    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7673    pub with_options: Vec<String>,
7674    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7675    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7676    pub has_parens: bool,
7677    /// Whether the short form PROC was used (instead of PROCEDURE)
7678    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7679    pub use_proc_keyword: bool,
7680}
7681
7682impl CreateProcedure {
7683    pub fn new(name: impl Into<String>) -> Self {
7684        Self {
7685            name: TableRef::new(name),
7686            parameters: Vec::new(),
7687            body: None,
7688            or_replace: false,
7689            if_not_exists: false,
7690            language: None,
7691            security: None,
7692            return_type: None,
7693            execute_as: None,
7694            with_options: Vec::new(),
7695            has_parens: true,
7696            use_proc_keyword: false,
7697        }
7698    }
7699}
7700
7701/// DROP PROCEDURE statement
7702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7703#[cfg_attr(feature = "bindings", derive(TS))]
7704pub struct DropProcedure {
7705    pub name: TableRef,
7706    pub parameters: Option<Vec<DataType>>,
7707    pub if_exists: bool,
7708    pub cascade: bool,
7709}
7710
7711impl DropProcedure {
7712    pub fn new(name: impl Into<String>) -> Self {
7713        Self {
7714            name: TableRef::new(name),
7715            parameters: None,
7716            if_exists: false,
7717            cascade: false,
7718        }
7719    }
7720}
7721
7722/// Sequence property tag for ordering
7723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7724#[cfg_attr(feature = "bindings", derive(TS))]
7725pub enum SeqPropKind {
7726    Start,
7727    Increment,
7728    Minvalue,
7729    Maxvalue,
7730    Cache,
7731    NoCache,
7732    Cycle,
7733    NoCycle,
7734    OwnedBy,
7735    Order,
7736    NoOrder,
7737    Comment,
7738    /// SHARING=<value> (Oracle)
7739    Sharing,
7740    /// KEEP (Oracle)
7741    Keep,
7742    /// NOKEEP (Oracle)
7743    NoKeep,
7744    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7745    Scale,
7746    /// NOSCALE (Oracle)
7747    NoScale,
7748    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7749    Shard,
7750    /// NOSHARD (Oracle)
7751    NoShard,
7752    /// SESSION (Oracle)
7753    Session,
7754    /// GLOBAL (Oracle)
7755    Global,
7756    /// NOCACHE (single word, Oracle)
7757    NoCacheWord,
7758    /// NOCYCLE (single word, Oracle)
7759    NoCycleWord,
7760    /// NOMINVALUE (single word, Oracle)
7761    NoMinvalueWord,
7762    /// NOMAXVALUE (single word, Oracle)
7763    NoMaxvalueWord,
7764}
7765
7766/// CREATE SEQUENCE statement
7767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7768#[cfg_attr(feature = "bindings", derive(TS))]
7769pub struct CreateSequence {
7770    pub name: TableRef,
7771    pub if_not_exists: bool,
7772    pub temporary: bool,
7773    #[serde(default)]
7774    pub or_replace: bool,
7775    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7776    #[serde(default, skip_serializing_if = "Option::is_none")]
7777    pub as_type: Option<DataType>,
7778    pub increment: Option<i64>,
7779    pub minvalue: Option<SequenceBound>,
7780    pub maxvalue: Option<SequenceBound>,
7781    pub start: Option<i64>,
7782    pub cache: Option<i64>,
7783    pub cycle: bool,
7784    pub owned_by: Option<TableRef>,
7785    /// Whether OWNED BY NONE was specified
7786    #[serde(default)]
7787    pub owned_by_none: bool,
7788    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7789    #[serde(default)]
7790    pub order: Option<bool>,
7791    /// Snowflake: COMMENT = 'value'
7792    #[serde(default)]
7793    pub comment: Option<String>,
7794    /// SHARING=<value> (Oracle)
7795    #[serde(default, skip_serializing_if = "Option::is_none")]
7796    pub sharing: Option<String>,
7797    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7798    #[serde(default, skip_serializing_if = "Option::is_none")]
7799    pub scale_modifier: Option<String>,
7800    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7801    #[serde(default, skip_serializing_if = "Option::is_none")]
7802    pub shard_modifier: Option<String>,
7803    /// Tracks the order in which properties appeared in the source
7804    #[serde(default)]
7805    pub property_order: Vec<SeqPropKind>,
7806}
7807
7808/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7810#[cfg_attr(feature = "bindings", derive(TS))]
7811pub enum SequenceBound {
7812    Value(i64),
7813    None,
7814}
7815
7816impl CreateSequence {
7817    pub fn new(name: impl Into<String>) -> Self {
7818        Self {
7819            name: TableRef::new(name),
7820            if_not_exists: false,
7821            temporary: false,
7822            or_replace: false,
7823            as_type: None,
7824            increment: None,
7825            minvalue: None,
7826            maxvalue: None,
7827            start: None,
7828            cache: None,
7829            cycle: false,
7830            owned_by: None,
7831            owned_by_none: false,
7832            order: None,
7833            comment: None,
7834            sharing: None,
7835            scale_modifier: None,
7836            shard_modifier: None,
7837            property_order: Vec::new(),
7838        }
7839    }
7840}
7841
7842/// DROP SEQUENCE statement
7843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7844#[cfg_attr(feature = "bindings", derive(TS))]
7845pub struct DropSequence {
7846    pub name: TableRef,
7847    pub if_exists: bool,
7848    pub cascade: bool,
7849}
7850
7851impl DropSequence {
7852    pub fn new(name: impl Into<String>) -> Self {
7853        Self {
7854            name: TableRef::new(name),
7855            if_exists: false,
7856            cascade: false,
7857        }
7858    }
7859}
7860
7861/// ALTER SEQUENCE statement
7862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7863#[cfg_attr(feature = "bindings", derive(TS))]
7864pub struct AlterSequence {
7865    pub name: TableRef,
7866    pub if_exists: bool,
7867    pub increment: Option<i64>,
7868    pub minvalue: Option<SequenceBound>,
7869    pub maxvalue: Option<SequenceBound>,
7870    pub start: Option<i64>,
7871    pub restart: Option<Option<i64>>,
7872    pub cache: Option<i64>,
7873    pub cycle: Option<bool>,
7874    pub owned_by: Option<Option<TableRef>>,
7875}
7876
7877impl AlterSequence {
7878    pub fn new(name: impl Into<String>) -> Self {
7879        Self {
7880            name: TableRef::new(name),
7881            if_exists: false,
7882            increment: None,
7883            minvalue: None,
7884            maxvalue: None,
7885            start: None,
7886            restart: None,
7887            cache: None,
7888            cycle: None,
7889            owned_by: None,
7890        }
7891    }
7892}
7893
7894/// CREATE TRIGGER statement
7895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7896#[cfg_attr(feature = "bindings", derive(TS))]
7897pub struct CreateTrigger {
7898    pub name: Identifier,
7899    pub table: TableRef,
7900    pub timing: TriggerTiming,
7901    pub events: Vec<TriggerEvent>,
7902    #[serde(default, skip_serializing_if = "Option::is_none")]
7903    pub for_each: Option<TriggerForEach>,
7904    pub when: Option<Expression>,
7905    /// Whether the WHEN clause was parenthesized in the original SQL
7906    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7907    pub when_paren: bool,
7908    pub body: TriggerBody,
7909    pub or_replace: bool,
7910    pub constraint: bool,
7911    pub deferrable: Option<bool>,
7912    pub initially_deferred: Option<bool>,
7913    pub referencing: Option<TriggerReferencing>,
7914}
7915
7916/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7917#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7918#[cfg_attr(feature = "bindings", derive(TS))]
7919pub enum TriggerTiming {
7920    Before,
7921    After,
7922    InsteadOf,
7923}
7924
7925/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7927#[cfg_attr(feature = "bindings", derive(TS))]
7928pub enum TriggerEvent {
7929    Insert,
7930    Update(Option<Vec<Identifier>>),
7931    Delete,
7932    Truncate,
7933}
7934
7935/// Trigger FOR EACH clause
7936#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7937#[cfg_attr(feature = "bindings", derive(TS))]
7938pub enum TriggerForEach {
7939    Row,
7940    Statement,
7941}
7942
7943/// Trigger body
7944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7945#[cfg_attr(feature = "bindings", derive(TS))]
7946pub enum TriggerBody {
7947    /// EXECUTE FUNCTION/PROCEDURE name(args)
7948    Execute {
7949        function: TableRef,
7950        args: Vec<Expression>,
7951    },
7952    /// BEGIN ... END block
7953    Block(String),
7954}
7955
7956/// Trigger REFERENCING clause
7957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7958#[cfg_attr(feature = "bindings", derive(TS))]
7959pub struct TriggerReferencing {
7960    pub old_table: Option<Identifier>,
7961    pub new_table: Option<Identifier>,
7962    pub old_row: Option<Identifier>,
7963    pub new_row: Option<Identifier>,
7964}
7965
7966impl CreateTrigger {
7967    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7968        Self {
7969            name: Identifier::new(name),
7970            table: TableRef::new(table),
7971            timing: TriggerTiming::Before,
7972            events: Vec::new(),
7973            for_each: Some(TriggerForEach::Row),
7974            when: None,
7975            when_paren: false,
7976            body: TriggerBody::Execute {
7977                function: TableRef::new(""),
7978                args: Vec::new(),
7979            },
7980            or_replace: false,
7981            constraint: false,
7982            deferrable: None,
7983            initially_deferred: None,
7984            referencing: None,
7985        }
7986    }
7987}
7988
7989/// DROP TRIGGER statement
7990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7991#[cfg_attr(feature = "bindings", derive(TS))]
7992pub struct DropTrigger {
7993    pub name: Identifier,
7994    pub table: Option<TableRef>,
7995    pub if_exists: bool,
7996    pub cascade: bool,
7997}
7998
7999impl DropTrigger {
8000    pub fn new(name: impl Into<String>) -> Self {
8001        Self {
8002            name: Identifier::new(name),
8003            table: None,
8004            if_exists: false,
8005            cascade: false,
8006        }
8007    }
8008}
8009
8010/// CREATE TYPE statement
8011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8012#[cfg_attr(feature = "bindings", derive(TS))]
8013pub struct CreateType {
8014    pub name: TableRef,
8015    pub definition: TypeDefinition,
8016    pub if_not_exists: bool,
8017}
8018
8019/// Type definition
8020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8021#[cfg_attr(feature = "bindings", derive(TS))]
8022pub enum TypeDefinition {
8023    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
8024    Enum(Vec<String>),
8025    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
8026    Composite(Vec<TypeAttribute>),
8027    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
8028    Range {
8029        subtype: DataType,
8030        subtype_diff: Option<String>,
8031        canonical: Option<String>,
8032    },
8033    /// Base type (for advanced usage)
8034    Base {
8035        input: String,
8036        output: String,
8037        internallength: Option<i32>,
8038    },
8039    /// Domain type
8040    Domain {
8041        base_type: DataType,
8042        default: Option<Expression>,
8043        constraints: Vec<DomainConstraint>,
8044    },
8045}
8046
8047/// Type attribute for composite types
8048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8049#[cfg_attr(feature = "bindings", derive(TS))]
8050pub struct TypeAttribute {
8051    pub name: Identifier,
8052    pub data_type: DataType,
8053    pub collate: Option<Identifier>,
8054}
8055
8056/// Domain constraint
8057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8058#[cfg_attr(feature = "bindings", derive(TS))]
8059pub struct DomainConstraint {
8060    pub name: Option<Identifier>,
8061    pub check: Expression,
8062}
8063
8064impl CreateType {
8065    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
8066        Self {
8067            name: TableRef::new(name),
8068            definition: TypeDefinition::Enum(values),
8069            if_not_exists: false,
8070        }
8071    }
8072
8073    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
8074        Self {
8075            name: TableRef::new(name),
8076            definition: TypeDefinition::Composite(attributes),
8077            if_not_exists: false,
8078        }
8079    }
8080}
8081
8082/// DROP TYPE statement
8083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8084#[cfg_attr(feature = "bindings", derive(TS))]
8085pub struct DropType {
8086    pub name: TableRef,
8087    pub if_exists: bool,
8088    pub cascade: bool,
8089}
8090
8091impl DropType {
8092    pub fn new(name: impl Into<String>) -> Self {
8093        Self {
8094            name: TableRef::new(name),
8095            if_exists: false,
8096            cascade: false,
8097        }
8098    }
8099}
8100
8101/// DESCRIBE statement - shows table structure or query plan
8102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8103#[cfg_attr(feature = "bindings", derive(TS))]
8104pub struct Describe {
8105    /// The target to describe (table name or query)
8106    pub target: Expression,
8107    /// EXTENDED format
8108    pub extended: bool,
8109    /// FORMATTED format
8110    pub formatted: bool,
8111    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
8112    #[serde(default)]
8113    pub kind: Option<String>,
8114    /// Properties like type=stage
8115    #[serde(default)]
8116    pub properties: Vec<(String, String)>,
8117    /// Style keyword (e.g., "ANALYZE", "HISTORY")
8118    #[serde(default, skip_serializing_if = "Option::is_none")]
8119    pub style: Option<String>,
8120    /// Partition specification for DESCRIBE PARTITION
8121    #[serde(default)]
8122    pub partition: Option<Box<Expression>>,
8123    /// Leading comments before the statement
8124    #[serde(default)]
8125    pub leading_comments: Vec<String>,
8126    /// AS JSON suffix (Databricks)
8127    #[serde(default)]
8128    pub as_json: bool,
8129}
8130
8131impl Describe {
8132    pub fn new(target: Expression) -> Self {
8133        Self {
8134            target,
8135            extended: false,
8136            formatted: false,
8137            kind: None,
8138            properties: Vec::new(),
8139            style: None,
8140            partition: None,
8141            leading_comments: Vec::new(),
8142            as_json: false,
8143        }
8144    }
8145}
8146
8147/// SHOW statement - displays database objects
8148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8149#[cfg_attr(feature = "bindings", derive(TS))]
8150pub struct Show {
8151    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
8152    pub this: String,
8153    /// Whether TERSE was specified
8154    #[serde(default)]
8155    pub terse: bool,
8156    /// Whether HISTORY was specified
8157    #[serde(default)]
8158    pub history: bool,
8159    /// LIKE pattern
8160    pub like: Option<Expression>,
8161    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
8162    pub scope_kind: Option<String>,
8163    /// IN scope object
8164    pub scope: Option<Expression>,
8165    /// STARTS WITH pattern
8166    pub starts_with: Option<Expression>,
8167    /// LIMIT clause
8168    pub limit: Option<Box<Limit>>,
8169    /// FROM clause (for specific object)
8170    pub from: Option<Expression>,
8171    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
8172    #[serde(default, skip_serializing_if = "Option::is_none")]
8173    pub where_clause: Option<Expression>,
8174    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
8175    #[serde(default, skip_serializing_if = "Option::is_none")]
8176    pub for_target: Option<Expression>,
8177    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
8178    #[serde(default, skip_serializing_if = "Option::is_none")]
8179    pub db: Option<Expression>,
8180    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
8181    #[serde(default, skip_serializing_if = "Option::is_none")]
8182    pub target: Option<Expression>,
8183    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
8184    #[serde(default, skip_serializing_if = "Option::is_none")]
8185    pub mutex: Option<bool>,
8186    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
8187    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8188    pub privileges: Vec<String>,
8189}
8190
8191impl Show {
8192    pub fn new(this: impl Into<String>) -> Self {
8193        Self {
8194            this: this.into(),
8195            terse: false,
8196            history: false,
8197            like: None,
8198            scope_kind: None,
8199            scope: None,
8200            starts_with: None,
8201            limit: None,
8202            from: None,
8203            where_clause: None,
8204            for_target: None,
8205            db: None,
8206            target: None,
8207            mutex: None,
8208            privileges: Vec::new(),
8209        }
8210    }
8211}
8212
8213/// Represent an explicit parenthesized expression for grouping precedence.
8214///
8215/// Preserves user-written parentheses so that `(a + b) * c` round-trips
8216/// correctly instead of being flattened to `a + b * c`.
8217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8218#[cfg_attr(feature = "bindings", derive(TS))]
8219pub struct Paren {
8220    /// The inner expression wrapped by parentheses.
8221    pub this: Expression,
8222    #[serde(default)]
8223    pub trailing_comments: Vec<String>,
8224}
8225
8226/// Expression annotated with trailing comments (for round-trip preservation)
8227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8228#[cfg_attr(feature = "bindings", derive(TS))]
8229pub struct Annotated {
8230    pub this: Expression,
8231    pub trailing_comments: Vec<String>,
8232}
8233
8234// === BATCH GENERATED STRUCT DEFINITIONS ===
8235// Generated from Python sqlglot expressions.py
8236
8237/// Refresh
8238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8239#[cfg_attr(feature = "bindings", derive(TS))]
8240pub struct Refresh {
8241    pub this: Box<Expression>,
8242    pub kind: String,
8243}
8244
8245/// LockingStatement
8246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8247#[cfg_attr(feature = "bindings", derive(TS))]
8248pub struct LockingStatement {
8249    pub this: Box<Expression>,
8250    pub expression: Box<Expression>,
8251}
8252
8253/// SequenceProperties
8254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8255#[cfg_attr(feature = "bindings", derive(TS))]
8256pub struct SequenceProperties {
8257    #[serde(default)]
8258    pub increment: Option<Box<Expression>>,
8259    #[serde(default)]
8260    pub minvalue: Option<Box<Expression>>,
8261    #[serde(default)]
8262    pub maxvalue: Option<Box<Expression>>,
8263    #[serde(default)]
8264    pub cache: Option<Box<Expression>>,
8265    #[serde(default)]
8266    pub start: Option<Box<Expression>>,
8267    #[serde(default)]
8268    pub owned: Option<Box<Expression>>,
8269    #[serde(default)]
8270    pub options: Vec<Expression>,
8271}
8272
8273/// TruncateTable
8274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8275#[cfg_attr(feature = "bindings", derive(TS))]
8276pub struct TruncateTable {
8277    #[serde(default)]
8278    pub expressions: Vec<Expression>,
8279    #[serde(default)]
8280    pub is_database: Option<Box<Expression>>,
8281    #[serde(default)]
8282    pub exists: bool,
8283    #[serde(default)]
8284    pub only: Option<Box<Expression>>,
8285    #[serde(default)]
8286    pub cluster: Option<Box<Expression>>,
8287    #[serde(default)]
8288    pub identity: Option<Box<Expression>>,
8289    #[serde(default)]
8290    pub option: Option<Box<Expression>>,
8291    #[serde(default)]
8292    pub partition: Option<Box<Expression>>,
8293}
8294
8295/// Clone
8296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8297#[cfg_attr(feature = "bindings", derive(TS))]
8298pub struct Clone {
8299    pub this: Box<Expression>,
8300    #[serde(default)]
8301    pub shallow: Option<Box<Expression>>,
8302    #[serde(default)]
8303    pub copy: Option<Box<Expression>>,
8304}
8305
8306/// Attach
8307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8308#[cfg_attr(feature = "bindings", derive(TS))]
8309pub struct Attach {
8310    pub this: Box<Expression>,
8311    #[serde(default)]
8312    pub exists: bool,
8313    #[serde(default)]
8314    pub expressions: Vec<Expression>,
8315}
8316
8317/// Detach
8318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8319#[cfg_attr(feature = "bindings", derive(TS))]
8320pub struct Detach {
8321    pub this: Box<Expression>,
8322    #[serde(default)]
8323    pub exists: bool,
8324}
8325
8326/// Install
8327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8328#[cfg_attr(feature = "bindings", derive(TS))]
8329pub struct Install {
8330    pub this: Box<Expression>,
8331    #[serde(default)]
8332    pub from_: Option<Box<Expression>>,
8333    #[serde(default)]
8334    pub force: Option<Box<Expression>>,
8335}
8336
8337/// Summarize
8338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8339#[cfg_attr(feature = "bindings", derive(TS))]
8340pub struct Summarize {
8341    pub this: Box<Expression>,
8342    #[serde(default)]
8343    pub table: Option<Box<Expression>>,
8344}
8345
8346/// Declare
8347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8348#[cfg_attr(feature = "bindings", derive(TS))]
8349pub struct Declare {
8350    #[serde(default)]
8351    pub expressions: Vec<Expression>,
8352}
8353
8354/// DeclareItem
8355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8356#[cfg_attr(feature = "bindings", derive(TS))]
8357pub struct DeclareItem {
8358    pub this: Box<Expression>,
8359    #[serde(default)]
8360    pub kind: Option<String>,
8361    #[serde(default)]
8362    pub default: Option<Box<Expression>>,
8363    #[serde(default)]
8364    pub has_as: bool,
8365    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
8366    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8367    pub additional_names: Vec<Expression>,
8368}
8369
8370/// Set
8371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8372#[cfg_attr(feature = "bindings", derive(TS))]
8373pub struct Set {
8374    #[serde(default)]
8375    pub expressions: Vec<Expression>,
8376    #[serde(default)]
8377    pub unset: Option<Box<Expression>>,
8378    #[serde(default)]
8379    pub tag: Option<Box<Expression>>,
8380}
8381
8382/// Heredoc
8383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8384#[cfg_attr(feature = "bindings", derive(TS))]
8385pub struct Heredoc {
8386    pub this: Box<Expression>,
8387    #[serde(default)]
8388    pub tag: Option<Box<Expression>>,
8389}
8390
8391/// QueryBand
8392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8393#[cfg_attr(feature = "bindings", derive(TS))]
8394pub struct QueryBand {
8395    pub this: Box<Expression>,
8396    #[serde(default)]
8397    pub scope: Option<Box<Expression>>,
8398    #[serde(default)]
8399    pub update: Option<Box<Expression>>,
8400}
8401
8402/// UserDefinedFunction
8403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8404#[cfg_attr(feature = "bindings", derive(TS))]
8405pub struct UserDefinedFunction {
8406    pub this: Box<Expression>,
8407    #[serde(default)]
8408    pub expressions: Vec<Expression>,
8409    #[serde(default)]
8410    pub wrapped: Option<Box<Expression>>,
8411}
8412
8413/// RecursiveWithSearch
8414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8415#[cfg_attr(feature = "bindings", derive(TS))]
8416pub struct RecursiveWithSearch {
8417    pub kind: String,
8418    pub this: Box<Expression>,
8419    pub expression: Box<Expression>,
8420    #[serde(default)]
8421    pub using: Option<Box<Expression>>,
8422}
8423
8424/// ProjectionDef
8425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8426#[cfg_attr(feature = "bindings", derive(TS))]
8427pub struct ProjectionDef {
8428    pub this: Box<Expression>,
8429    pub expression: Box<Expression>,
8430}
8431
8432/// TableAlias
8433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8434#[cfg_attr(feature = "bindings", derive(TS))]
8435pub struct TableAlias {
8436    #[serde(default)]
8437    pub this: Option<Box<Expression>>,
8438    #[serde(default)]
8439    pub columns: Vec<Expression>,
8440}
8441
8442/// ByteString
8443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8444#[cfg_attr(feature = "bindings", derive(TS))]
8445pub struct ByteString {
8446    pub this: Box<Expression>,
8447    #[serde(default)]
8448    pub is_bytes: Option<Box<Expression>>,
8449}
8450
8451/// HexStringExpr - Hex string expression (not literal)
8452/// BigQuery: converts to FROM_HEX(this)
8453#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8454#[cfg_attr(feature = "bindings", derive(TS))]
8455pub struct HexStringExpr {
8456    pub this: Box<Expression>,
8457    #[serde(default)]
8458    pub is_integer: Option<bool>,
8459}
8460
8461/// UnicodeString
8462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8463#[cfg_attr(feature = "bindings", derive(TS))]
8464pub struct UnicodeString {
8465    pub this: Box<Expression>,
8466    #[serde(default)]
8467    pub escape: Option<Box<Expression>>,
8468}
8469
8470/// AlterColumn
8471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8472#[cfg_attr(feature = "bindings", derive(TS))]
8473pub struct AlterColumn {
8474    pub this: Box<Expression>,
8475    #[serde(default)]
8476    pub dtype: Option<Box<Expression>>,
8477    #[serde(default)]
8478    pub collate: Option<Box<Expression>>,
8479    #[serde(default)]
8480    pub using: Option<Box<Expression>>,
8481    #[serde(default)]
8482    pub default: Option<Box<Expression>>,
8483    #[serde(default)]
8484    pub drop: Option<Box<Expression>>,
8485    #[serde(default)]
8486    pub comment: Option<Box<Expression>>,
8487    #[serde(default)]
8488    pub allow_null: Option<Box<Expression>>,
8489    #[serde(default)]
8490    pub visible: Option<Box<Expression>>,
8491    #[serde(default)]
8492    pub rename_to: Option<Box<Expression>>,
8493}
8494
8495/// AlterSortKey
8496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8497#[cfg_attr(feature = "bindings", derive(TS))]
8498pub struct AlterSortKey {
8499    #[serde(default)]
8500    pub this: Option<Box<Expression>>,
8501    #[serde(default)]
8502    pub expressions: Vec<Expression>,
8503    #[serde(default)]
8504    pub compound: Option<Box<Expression>>,
8505}
8506
8507/// AlterSet
8508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8509#[cfg_attr(feature = "bindings", derive(TS))]
8510pub struct AlterSet {
8511    #[serde(default)]
8512    pub expressions: Vec<Expression>,
8513    #[serde(default)]
8514    pub option: Option<Box<Expression>>,
8515    #[serde(default)]
8516    pub tablespace: Option<Box<Expression>>,
8517    #[serde(default)]
8518    pub access_method: Option<Box<Expression>>,
8519    #[serde(default)]
8520    pub file_format: Option<Box<Expression>>,
8521    #[serde(default)]
8522    pub copy_options: Option<Box<Expression>>,
8523    #[serde(default)]
8524    pub tag: Option<Box<Expression>>,
8525    #[serde(default)]
8526    pub location: Option<Box<Expression>>,
8527    #[serde(default)]
8528    pub serde: Option<Box<Expression>>,
8529}
8530
8531/// RenameColumn
8532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8533#[cfg_attr(feature = "bindings", derive(TS))]
8534pub struct RenameColumn {
8535    pub this: Box<Expression>,
8536    #[serde(default)]
8537    pub to: Option<Box<Expression>>,
8538    #[serde(default)]
8539    pub exists: bool,
8540}
8541
8542/// Comprehension
8543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8544#[cfg_attr(feature = "bindings", derive(TS))]
8545pub struct Comprehension {
8546    pub this: Box<Expression>,
8547    pub expression: Box<Expression>,
8548    #[serde(default)]
8549    pub position: Option<Box<Expression>>,
8550    #[serde(default)]
8551    pub iterator: Option<Box<Expression>>,
8552    #[serde(default)]
8553    pub condition: Option<Box<Expression>>,
8554}
8555
8556/// MergeTreeTTLAction
8557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8558#[cfg_attr(feature = "bindings", derive(TS))]
8559pub struct MergeTreeTTLAction {
8560    pub this: Box<Expression>,
8561    #[serde(default)]
8562    pub delete: Option<Box<Expression>>,
8563    #[serde(default)]
8564    pub recompress: Option<Box<Expression>>,
8565    #[serde(default)]
8566    pub to_disk: Option<Box<Expression>>,
8567    #[serde(default)]
8568    pub to_volume: Option<Box<Expression>>,
8569}
8570
8571/// MergeTreeTTL
8572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8573#[cfg_attr(feature = "bindings", derive(TS))]
8574pub struct MergeTreeTTL {
8575    #[serde(default)]
8576    pub expressions: Vec<Expression>,
8577    #[serde(default)]
8578    pub where_: Option<Box<Expression>>,
8579    #[serde(default)]
8580    pub group: Option<Box<Expression>>,
8581    #[serde(default)]
8582    pub aggregates: Option<Box<Expression>>,
8583}
8584
8585/// IndexConstraintOption
8586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8587#[cfg_attr(feature = "bindings", derive(TS))]
8588pub struct IndexConstraintOption {
8589    #[serde(default)]
8590    pub key_block_size: Option<Box<Expression>>,
8591    #[serde(default)]
8592    pub using: Option<Box<Expression>>,
8593    #[serde(default)]
8594    pub parser: Option<Box<Expression>>,
8595    #[serde(default)]
8596    pub comment: Option<Box<Expression>>,
8597    #[serde(default)]
8598    pub visible: Option<Box<Expression>>,
8599    #[serde(default)]
8600    pub engine_attr: Option<Box<Expression>>,
8601    #[serde(default)]
8602    pub secondary_engine_attr: Option<Box<Expression>>,
8603}
8604
8605/// PeriodForSystemTimeConstraint
8606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8607#[cfg_attr(feature = "bindings", derive(TS))]
8608pub struct PeriodForSystemTimeConstraint {
8609    pub this: Box<Expression>,
8610    pub expression: Box<Expression>,
8611}
8612
8613/// CaseSpecificColumnConstraint
8614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8615#[cfg_attr(feature = "bindings", derive(TS))]
8616pub struct CaseSpecificColumnConstraint {
8617    #[serde(default)]
8618    pub not_: Option<Box<Expression>>,
8619}
8620
8621/// CharacterSetColumnConstraint
8622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8623#[cfg_attr(feature = "bindings", derive(TS))]
8624pub struct CharacterSetColumnConstraint {
8625    pub this: Box<Expression>,
8626}
8627
8628/// CheckColumnConstraint
8629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8630#[cfg_attr(feature = "bindings", derive(TS))]
8631pub struct CheckColumnConstraint {
8632    pub this: Box<Expression>,
8633    #[serde(default)]
8634    pub enforced: Option<Box<Expression>>,
8635}
8636
8637/// CompressColumnConstraint
8638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8639#[cfg_attr(feature = "bindings", derive(TS))]
8640pub struct CompressColumnConstraint {
8641    #[serde(default)]
8642    pub this: Option<Box<Expression>>,
8643}
8644
8645/// DateFormatColumnConstraint
8646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8647#[cfg_attr(feature = "bindings", derive(TS))]
8648pub struct DateFormatColumnConstraint {
8649    pub this: Box<Expression>,
8650}
8651
8652/// EphemeralColumnConstraint
8653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8654#[cfg_attr(feature = "bindings", derive(TS))]
8655pub struct EphemeralColumnConstraint {
8656    #[serde(default)]
8657    pub this: Option<Box<Expression>>,
8658}
8659
8660/// WithOperator
8661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8662#[cfg_attr(feature = "bindings", derive(TS))]
8663pub struct WithOperator {
8664    pub this: Box<Expression>,
8665    pub op: String,
8666}
8667
8668/// GeneratedAsIdentityColumnConstraint
8669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8670#[cfg_attr(feature = "bindings", derive(TS))]
8671pub struct GeneratedAsIdentityColumnConstraint {
8672    #[serde(default)]
8673    pub this: Option<Box<Expression>>,
8674    #[serde(default)]
8675    pub expression: Option<Box<Expression>>,
8676    #[serde(default)]
8677    pub on_null: Option<Box<Expression>>,
8678    #[serde(default)]
8679    pub start: Option<Box<Expression>>,
8680    #[serde(default)]
8681    pub increment: Option<Box<Expression>>,
8682    #[serde(default)]
8683    pub minvalue: Option<Box<Expression>>,
8684    #[serde(default)]
8685    pub maxvalue: Option<Box<Expression>>,
8686    #[serde(default)]
8687    pub cycle: Option<Box<Expression>>,
8688    #[serde(default)]
8689    pub order: Option<Box<Expression>>,
8690}
8691
8692/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8693/// TSQL: outputs "IDENTITY"
8694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8695#[cfg_attr(feature = "bindings", derive(TS))]
8696pub struct AutoIncrementColumnConstraint;
8697
8698/// CommentColumnConstraint - Column comment marker
8699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8700#[cfg_attr(feature = "bindings", derive(TS))]
8701pub struct CommentColumnConstraint;
8702
8703/// GeneratedAsRowColumnConstraint
8704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8705#[cfg_attr(feature = "bindings", derive(TS))]
8706pub struct GeneratedAsRowColumnConstraint {
8707    #[serde(default)]
8708    pub start: Option<Box<Expression>>,
8709    #[serde(default)]
8710    pub hidden: Option<Box<Expression>>,
8711}
8712
8713/// IndexColumnConstraint
8714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8715#[cfg_attr(feature = "bindings", derive(TS))]
8716pub struct IndexColumnConstraint {
8717    #[serde(default)]
8718    pub this: Option<Box<Expression>>,
8719    #[serde(default)]
8720    pub expressions: Vec<Expression>,
8721    #[serde(default)]
8722    pub kind: Option<String>,
8723    #[serde(default)]
8724    pub index_type: Option<Box<Expression>>,
8725    #[serde(default)]
8726    pub options: Vec<Expression>,
8727    #[serde(default)]
8728    pub expression: Option<Box<Expression>>,
8729    #[serde(default)]
8730    pub granularity: Option<Box<Expression>>,
8731}
8732
8733/// MaskingPolicyColumnConstraint
8734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8735#[cfg_attr(feature = "bindings", derive(TS))]
8736pub struct MaskingPolicyColumnConstraint {
8737    pub this: Box<Expression>,
8738    #[serde(default)]
8739    pub expressions: Vec<Expression>,
8740}
8741
8742/// NotNullColumnConstraint
8743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8744#[cfg_attr(feature = "bindings", derive(TS))]
8745pub struct NotNullColumnConstraint {
8746    #[serde(default)]
8747    pub allow_null: Option<Box<Expression>>,
8748}
8749
8750/// DefaultColumnConstraint - DEFAULT value for a column
8751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8752#[cfg_attr(feature = "bindings", derive(TS))]
8753pub struct DefaultColumnConstraint {
8754    pub this: Box<Expression>,
8755}
8756
8757/// PrimaryKeyColumnConstraint
8758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8759#[cfg_attr(feature = "bindings", derive(TS))]
8760pub struct PrimaryKeyColumnConstraint {
8761    #[serde(default)]
8762    pub desc: Option<Box<Expression>>,
8763    #[serde(default)]
8764    pub options: Vec<Expression>,
8765}
8766
8767/// UniqueColumnConstraint
8768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8769#[cfg_attr(feature = "bindings", derive(TS))]
8770pub struct UniqueColumnConstraint {
8771    #[serde(default)]
8772    pub this: Option<Box<Expression>>,
8773    #[serde(default)]
8774    pub index_type: Option<Box<Expression>>,
8775    #[serde(default)]
8776    pub on_conflict: Option<Box<Expression>>,
8777    #[serde(default)]
8778    pub nulls: Option<Box<Expression>>,
8779    #[serde(default)]
8780    pub options: Vec<Expression>,
8781}
8782
8783/// WatermarkColumnConstraint
8784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8785#[cfg_attr(feature = "bindings", derive(TS))]
8786pub struct WatermarkColumnConstraint {
8787    pub this: Box<Expression>,
8788    pub expression: Box<Expression>,
8789}
8790
8791/// ComputedColumnConstraint
8792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8793#[cfg_attr(feature = "bindings", derive(TS))]
8794pub struct ComputedColumnConstraint {
8795    pub this: Box<Expression>,
8796    #[serde(default)]
8797    pub persisted: Option<Box<Expression>>,
8798    #[serde(default)]
8799    pub not_null: Option<Box<Expression>>,
8800    #[serde(default)]
8801    pub data_type: Option<Box<Expression>>,
8802}
8803
8804/// InOutColumnConstraint
8805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8806#[cfg_attr(feature = "bindings", derive(TS))]
8807pub struct InOutColumnConstraint {
8808    #[serde(default)]
8809    pub input_: Option<Box<Expression>>,
8810    #[serde(default)]
8811    pub output: Option<Box<Expression>>,
8812}
8813
8814/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8816#[cfg_attr(feature = "bindings", derive(TS))]
8817pub struct PathColumnConstraint {
8818    pub this: Box<Expression>,
8819}
8820
8821/// Constraint
8822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8823#[cfg_attr(feature = "bindings", derive(TS))]
8824pub struct Constraint {
8825    pub this: Box<Expression>,
8826    #[serde(default)]
8827    pub expressions: Vec<Expression>,
8828}
8829
8830/// Export
8831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8832#[cfg_attr(feature = "bindings", derive(TS))]
8833pub struct Export {
8834    pub this: Box<Expression>,
8835    #[serde(default)]
8836    pub connection: Option<Box<Expression>>,
8837    #[serde(default)]
8838    pub options: Vec<Expression>,
8839}
8840
8841/// Filter
8842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8843#[cfg_attr(feature = "bindings", derive(TS))]
8844pub struct Filter {
8845    pub this: Box<Expression>,
8846    pub expression: Box<Expression>,
8847}
8848
8849/// Changes
8850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8851#[cfg_attr(feature = "bindings", derive(TS))]
8852pub struct Changes {
8853    #[serde(default)]
8854    pub information: Option<Box<Expression>>,
8855    #[serde(default)]
8856    pub at_before: Option<Box<Expression>>,
8857    #[serde(default)]
8858    pub end: Option<Box<Expression>>,
8859}
8860
8861/// Directory
8862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8863#[cfg_attr(feature = "bindings", derive(TS))]
8864pub struct Directory {
8865    pub this: Box<Expression>,
8866    #[serde(default)]
8867    pub local: Option<Box<Expression>>,
8868    #[serde(default)]
8869    pub row_format: Option<Box<Expression>>,
8870}
8871
8872/// ForeignKey
8873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8874#[cfg_attr(feature = "bindings", derive(TS))]
8875pub struct ForeignKey {
8876    #[serde(default)]
8877    pub expressions: Vec<Expression>,
8878    #[serde(default)]
8879    pub reference: Option<Box<Expression>>,
8880    #[serde(default)]
8881    pub delete: Option<Box<Expression>>,
8882    #[serde(default)]
8883    pub update: Option<Box<Expression>>,
8884    #[serde(default)]
8885    pub options: Vec<Expression>,
8886}
8887
8888/// ColumnPrefix
8889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8890#[cfg_attr(feature = "bindings", derive(TS))]
8891pub struct ColumnPrefix {
8892    pub this: Box<Expression>,
8893    pub expression: Box<Expression>,
8894}
8895
8896/// PrimaryKey
8897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8898#[cfg_attr(feature = "bindings", derive(TS))]
8899pub struct PrimaryKey {
8900    #[serde(default)]
8901    pub this: Option<Box<Expression>>,
8902    #[serde(default)]
8903    pub expressions: Vec<Expression>,
8904    #[serde(default)]
8905    pub options: Vec<Expression>,
8906    #[serde(default)]
8907    pub include: Option<Box<Expression>>,
8908}
8909
8910/// Into
8911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8912#[cfg_attr(feature = "bindings", derive(TS))]
8913pub struct IntoClause {
8914    #[serde(default)]
8915    pub this: Option<Box<Expression>>,
8916    #[serde(default)]
8917    pub temporary: bool,
8918    #[serde(default)]
8919    pub unlogged: Option<Box<Expression>>,
8920    #[serde(default)]
8921    pub bulk_collect: Option<Box<Expression>>,
8922    #[serde(default)]
8923    pub expressions: Vec<Expression>,
8924}
8925
8926/// JoinHint
8927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8928#[cfg_attr(feature = "bindings", derive(TS))]
8929pub struct JoinHint {
8930    pub this: Box<Expression>,
8931    #[serde(default)]
8932    pub expressions: Vec<Expression>,
8933}
8934
8935/// Opclass
8936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8937#[cfg_attr(feature = "bindings", derive(TS))]
8938pub struct Opclass {
8939    pub this: Box<Expression>,
8940    pub expression: Box<Expression>,
8941}
8942
8943/// Index
8944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8945#[cfg_attr(feature = "bindings", derive(TS))]
8946pub struct Index {
8947    #[serde(default)]
8948    pub this: Option<Box<Expression>>,
8949    #[serde(default)]
8950    pub table: Option<Box<Expression>>,
8951    #[serde(default)]
8952    pub unique: bool,
8953    #[serde(default)]
8954    pub primary: Option<Box<Expression>>,
8955    #[serde(default)]
8956    pub amp: Option<Box<Expression>>,
8957    #[serde(default)]
8958    pub params: Vec<Expression>,
8959}
8960
8961/// IndexParameters
8962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8963#[cfg_attr(feature = "bindings", derive(TS))]
8964pub struct IndexParameters {
8965    #[serde(default)]
8966    pub using: Option<Box<Expression>>,
8967    #[serde(default)]
8968    pub include: Option<Box<Expression>>,
8969    #[serde(default)]
8970    pub columns: Vec<Expression>,
8971    #[serde(default)]
8972    pub with_storage: Option<Box<Expression>>,
8973    #[serde(default)]
8974    pub partition_by: Option<Box<Expression>>,
8975    #[serde(default)]
8976    pub tablespace: Option<Box<Expression>>,
8977    #[serde(default)]
8978    pub where_: Option<Box<Expression>>,
8979    #[serde(default)]
8980    pub on: Option<Box<Expression>>,
8981}
8982
8983/// ConditionalInsert
8984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8985#[cfg_attr(feature = "bindings", derive(TS))]
8986pub struct ConditionalInsert {
8987    pub this: Box<Expression>,
8988    #[serde(default)]
8989    pub expression: Option<Box<Expression>>,
8990    #[serde(default)]
8991    pub else_: Option<Box<Expression>>,
8992}
8993
8994/// MultitableInserts
8995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8996#[cfg_attr(feature = "bindings", derive(TS))]
8997pub struct MultitableInserts {
8998    #[serde(default)]
8999    pub expressions: Vec<Expression>,
9000    pub kind: String,
9001    #[serde(default)]
9002    pub source: Option<Box<Expression>>,
9003    /// Leading comments before the statement
9004    #[serde(default)]
9005    pub leading_comments: Vec<String>,
9006}
9007
9008/// OnConflict
9009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9010#[cfg_attr(feature = "bindings", derive(TS))]
9011pub struct OnConflict {
9012    #[serde(default)]
9013    pub duplicate: Option<Box<Expression>>,
9014    #[serde(default)]
9015    pub expressions: Vec<Expression>,
9016    #[serde(default)]
9017    pub action: Option<Box<Expression>>,
9018    #[serde(default)]
9019    pub conflict_keys: Option<Box<Expression>>,
9020    #[serde(default)]
9021    pub index_predicate: Option<Box<Expression>>,
9022    #[serde(default)]
9023    pub constraint: Option<Box<Expression>>,
9024    #[serde(default)]
9025    pub where_: Option<Box<Expression>>,
9026}
9027
9028/// OnCondition
9029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9030#[cfg_attr(feature = "bindings", derive(TS))]
9031pub struct OnCondition {
9032    #[serde(default)]
9033    pub error: Option<Box<Expression>>,
9034    #[serde(default)]
9035    pub empty: Option<Box<Expression>>,
9036    #[serde(default)]
9037    pub null: Option<Box<Expression>>,
9038}
9039
9040/// Returning
9041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9042#[cfg_attr(feature = "bindings", derive(TS))]
9043pub struct Returning {
9044    #[serde(default)]
9045    pub expressions: Vec<Expression>,
9046    #[serde(default)]
9047    pub into: Option<Box<Expression>>,
9048}
9049
9050/// Introducer
9051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9052#[cfg_attr(feature = "bindings", derive(TS))]
9053pub struct Introducer {
9054    pub this: Box<Expression>,
9055    pub expression: Box<Expression>,
9056}
9057
9058/// PartitionRange
9059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9060#[cfg_attr(feature = "bindings", derive(TS))]
9061pub struct PartitionRange {
9062    pub this: Box<Expression>,
9063    #[serde(default)]
9064    pub expression: Option<Box<Expression>>,
9065    #[serde(default)]
9066    pub expressions: Vec<Expression>,
9067}
9068
9069/// Group
9070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9071#[cfg_attr(feature = "bindings", derive(TS))]
9072pub struct Group {
9073    #[serde(default)]
9074    pub expressions: Vec<Expression>,
9075    #[serde(default)]
9076    pub grouping_sets: Option<Box<Expression>>,
9077    #[serde(default)]
9078    pub cube: Option<Box<Expression>>,
9079    #[serde(default)]
9080    pub rollup: Option<Box<Expression>>,
9081    #[serde(default)]
9082    pub totals: Option<Box<Expression>>,
9083    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
9084    #[serde(default)]
9085    pub all: Option<bool>,
9086}
9087
9088/// Cube
9089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9090#[cfg_attr(feature = "bindings", derive(TS))]
9091pub struct Cube {
9092    #[serde(default)]
9093    pub expressions: Vec<Expression>,
9094}
9095
9096/// Rollup
9097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9098#[cfg_attr(feature = "bindings", derive(TS))]
9099pub struct Rollup {
9100    #[serde(default)]
9101    pub expressions: Vec<Expression>,
9102}
9103
9104/// GroupingSets
9105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9106#[cfg_attr(feature = "bindings", derive(TS))]
9107pub struct GroupingSets {
9108    #[serde(default)]
9109    pub expressions: Vec<Expression>,
9110}
9111
9112/// LimitOptions
9113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9114#[cfg_attr(feature = "bindings", derive(TS))]
9115pub struct LimitOptions {
9116    #[serde(default)]
9117    pub percent: Option<Box<Expression>>,
9118    #[serde(default)]
9119    pub rows: Option<Box<Expression>>,
9120    #[serde(default)]
9121    pub with_ties: Option<Box<Expression>>,
9122}
9123
9124/// Lateral
9125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9126#[cfg_attr(feature = "bindings", derive(TS))]
9127pub struct Lateral {
9128    pub this: Box<Expression>,
9129    #[serde(default)]
9130    pub view: Option<Box<Expression>>,
9131    #[serde(default)]
9132    pub outer: Option<Box<Expression>>,
9133    #[serde(default)]
9134    pub alias: Option<String>,
9135    /// Whether the alias was originally quoted (backtick/double-quote)
9136    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9137    pub alias_quoted: bool,
9138    #[serde(default)]
9139    pub cross_apply: Option<Box<Expression>>,
9140    #[serde(default)]
9141    pub ordinality: Option<Box<Expression>>,
9142    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
9143    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9144    pub column_aliases: Vec<String>,
9145}
9146
9147/// TableFromRows
9148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9149#[cfg_attr(feature = "bindings", derive(TS))]
9150pub struct TableFromRows {
9151    pub this: Box<Expression>,
9152    #[serde(default)]
9153    pub alias: Option<String>,
9154    #[serde(default)]
9155    pub joins: Vec<Expression>,
9156    #[serde(default)]
9157    pub pivots: Option<Box<Expression>>,
9158    #[serde(default)]
9159    pub sample: Option<Box<Expression>>,
9160}
9161
9162/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
9163/// Used for set-returning functions with typed column definitions
9164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9165#[cfg_attr(feature = "bindings", derive(TS))]
9166pub struct RowsFrom {
9167    /// List of function expressions, each potentially with an alias and typed columns
9168    pub expressions: Vec<Expression>,
9169    /// WITH ORDINALITY modifier
9170    #[serde(default)]
9171    pub ordinality: bool,
9172    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
9173    #[serde(default)]
9174    pub alias: Option<Box<Expression>>,
9175}
9176
9177/// WithFill
9178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9179#[cfg_attr(feature = "bindings", derive(TS))]
9180pub struct WithFill {
9181    #[serde(default)]
9182    pub from_: Option<Box<Expression>>,
9183    #[serde(default)]
9184    pub to: Option<Box<Expression>>,
9185    #[serde(default)]
9186    pub step: Option<Box<Expression>>,
9187    #[serde(default)]
9188    pub staleness: Option<Box<Expression>>,
9189    #[serde(default)]
9190    pub interpolate: Option<Box<Expression>>,
9191}
9192
9193/// Property
9194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9195#[cfg_attr(feature = "bindings", derive(TS))]
9196pub struct Property {
9197    pub this: Box<Expression>,
9198    #[serde(default)]
9199    pub value: Option<Box<Expression>>,
9200}
9201
9202/// GrantPrivilege
9203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9204#[cfg_attr(feature = "bindings", derive(TS))]
9205pub struct GrantPrivilege {
9206    pub this: Box<Expression>,
9207    #[serde(default)]
9208    pub expressions: Vec<Expression>,
9209}
9210
9211/// AllowedValuesProperty
9212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9213#[cfg_attr(feature = "bindings", derive(TS))]
9214pub struct AllowedValuesProperty {
9215    #[serde(default)]
9216    pub expressions: Vec<Expression>,
9217}
9218
9219/// AlgorithmProperty
9220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9221#[cfg_attr(feature = "bindings", derive(TS))]
9222pub struct AlgorithmProperty {
9223    pub this: Box<Expression>,
9224}
9225
9226/// AutoIncrementProperty
9227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9228#[cfg_attr(feature = "bindings", derive(TS))]
9229pub struct AutoIncrementProperty {
9230    pub this: Box<Expression>,
9231}
9232
9233/// AutoRefreshProperty
9234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9235#[cfg_attr(feature = "bindings", derive(TS))]
9236pub struct AutoRefreshProperty {
9237    pub this: Box<Expression>,
9238}
9239
9240/// BackupProperty
9241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9242#[cfg_attr(feature = "bindings", derive(TS))]
9243pub struct BackupProperty {
9244    pub this: Box<Expression>,
9245}
9246
9247/// BuildProperty
9248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9249#[cfg_attr(feature = "bindings", derive(TS))]
9250pub struct BuildProperty {
9251    pub this: Box<Expression>,
9252}
9253
9254/// BlockCompressionProperty
9255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9256#[cfg_attr(feature = "bindings", derive(TS))]
9257pub struct BlockCompressionProperty {
9258    #[serde(default)]
9259    pub autotemp: Option<Box<Expression>>,
9260    #[serde(default)]
9261    pub always: Option<Box<Expression>>,
9262    #[serde(default)]
9263    pub default: Option<Box<Expression>>,
9264    #[serde(default)]
9265    pub manual: Option<Box<Expression>>,
9266    #[serde(default)]
9267    pub never: Option<Box<Expression>>,
9268}
9269
9270/// CharacterSetProperty
9271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9272#[cfg_attr(feature = "bindings", derive(TS))]
9273pub struct CharacterSetProperty {
9274    pub this: Box<Expression>,
9275    #[serde(default)]
9276    pub default: Option<Box<Expression>>,
9277}
9278
9279/// ChecksumProperty
9280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9281#[cfg_attr(feature = "bindings", derive(TS))]
9282pub struct ChecksumProperty {
9283    #[serde(default)]
9284    pub on: Option<Box<Expression>>,
9285    #[serde(default)]
9286    pub default: Option<Box<Expression>>,
9287}
9288
9289/// CollateProperty
9290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9291#[cfg_attr(feature = "bindings", derive(TS))]
9292pub struct CollateProperty {
9293    pub this: Box<Expression>,
9294    #[serde(default)]
9295    pub default: Option<Box<Expression>>,
9296}
9297
9298/// DataBlocksizeProperty
9299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9300#[cfg_attr(feature = "bindings", derive(TS))]
9301pub struct DataBlocksizeProperty {
9302    #[serde(default)]
9303    pub size: Option<i64>,
9304    #[serde(default)]
9305    pub units: Option<Box<Expression>>,
9306    #[serde(default)]
9307    pub minimum: Option<Box<Expression>>,
9308    #[serde(default)]
9309    pub maximum: Option<Box<Expression>>,
9310    #[serde(default)]
9311    pub default: Option<Box<Expression>>,
9312}
9313
9314/// DataDeletionProperty
9315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9316#[cfg_attr(feature = "bindings", derive(TS))]
9317pub struct DataDeletionProperty {
9318    pub on: Box<Expression>,
9319    #[serde(default)]
9320    pub filter_column: Option<Box<Expression>>,
9321    #[serde(default)]
9322    pub retention_period: Option<Box<Expression>>,
9323}
9324
9325/// DefinerProperty
9326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9327#[cfg_attr(feature = "bindings", derive(TS))]
9328pub struct DefinerProperty {
9329    pub this: Box<Expression>,
9330}
9331
9332/// DistKeyProperty
9333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9334#[cfg_attr(feature = "bindings", derive(TS))]
9335pub struct DistKeyProperty {
9336    pub this: Box<Expression>,
9337}
9338
9339/// DistributedByProperty
9340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9341#[cfg_attr(feature = "bindings", derive(TS))]
9342pub struct DistributedByProperty {
9343    #[serde(default)]
9344    pub expressions: Vec<Expression>,
9345    pub kind: String,
9346    #[serde(default)]
9347    pub buckets: Option<Box<Expression>>,
9348    #[serde(default)]
9349    pub order: Option<Box<Expression>>,
9350}
9351
9352/// DistStyleProperty
9353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9354#[cfg_attr(feature = "bindings", derive(TS))]
9355pub struct DistStyleProperty {
9356    pub this: Box<Expression>,
9357}
9358
9359/// DuplicateKeyProperty
9360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9361#[cfg_attr(feature = "bindings", derive(TS))]
9362pub struct DuplicateKeyProperty {
9363    #[serde(default)]
9364    pub expressions: Vec<Expression>,
9365}
9366
9367/// EngineProperty
9368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9369#[cfg_attr(feature = "bindings", derive(TS))]
9370pub struct EngineProperty {
9371    pub this: Box<Expression>,
9372}
9373
9374/// ToTableProperty
9375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9376#[cfg_attr(feature = "bindings", derive(TS))]
9377pub struct ToTableProperty {
9378    pub this: Box<Expression>,
9379}
9380
9381/// ExecuteAsProperty
9382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9383#[cfg_attr(feature = "bindings", derive(TS))]
9384pub struct ExecuteAsProperty {
9385    pub this: Box<Expression>,
9386}
9387
9388/// ExternalProperty
9389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9390#[cfg_attr(feature = "bindings", derive(TS))]
9391pub struct ExternalProperty {
9392    #[serde(default)]
9393    pub this: Option<Box<Expression>>,
9394}
9395
9396/// FallbackProperty
9397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9398#[cfg_attr(feature = "bindings", derive(TS))]
9399pub struct FallbackProperty {
9400    #[serde(default)]
9401    pub no: Option<Box<Expression>>,
9402    #[serde(default)]
9403    pub protection: Option<Box<Expression>>,
9404}
9405
9406/// FileFormatProperty
9407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9408#[cfg_attr(feature = "bindings", derive(TS))]
9409pub struct FileFormatProperty {
9410    #[serde(default)]
9411    pub this: Option<Box<Expression>>,
9412    #[serde(default)]
9413    pub expressions: Vec<Expression>,
9414    #[serde(default)]
9415    pub hive_format: Option<Box<Expression>>,
9416}
9417
9418/// CredentialsProperty
9419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9420#[cfg_attr(feature = "bindings", derive(TS))]
9421pub struct CredentialsProperty {
9422    #[serde(default)]
9423    pub expressions: Vec<Expression>,
9424}
9425
9426/// FreespaceProperty
9427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9428#[cfg_attr(feature = "bindings", derive(TS))]
9429pub struct FreespaceProperty {
9430    pub this: Box<Expression>,
9431    #[serde(default)]
9432    pub percent: Option<Box<Expression>>,
9433}
9434
9435/// InheritsProperty
9436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9437#[cfg_attr(feature = "bindings", derive(TS))]
9438pub struct InheritsProperty {
9439    #[serde(default)]
9440    pub expressions: Vec<Expression>,
9441}
9442
9443/// InputModelProperty
9444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9445#[cfg_attr(feature = "bindings", derive(TS))]
9446pub struct InputModelProperty {
9447    pub this: Box<Expression>,
9448}
9449
9450/// OutputModelProperty
9451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9452#[cfg_attr(feature = "bindings", derive(TS))]
9453pub struct OutputModelProperty {
9454    pub this: Box<Expression>,
9455}
9456
9457/// IsolatedLoadingProperty
9458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9459#[cfg_attr(feature = "bindings", derive(TS))]
9460pub struct IsolatedLoadingProperty {
9461    #[serde(default)]
9462    pub no: Option<Box<Expression>>,
9463    #[serde(default)]
9464    pub concurrent: Option<Box<Expression>>,
9465    #[serde(default)]
9466    pub target: Option<Box<Expression>>,
9467}
9468
9469/// JournalProperty
9470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9471#[cfg_attr(feature = "bindings", derive(TS))]
9472pub struct JournalProperty {
9473    #[serde(default)]
9474    pub no: Option<Box<Expression>>,
9475    #[serde(default)]
9476    pub dual: Option<Box<Expression>>,
9477    #[serde(default)]
9478    pub before: Option<Box<Expression>>,
9479    #[serde(default)]
9480    pub local: Option<Box<Expression>>,
9481    #[serde(default)]
9482    pub after: Option<Box<Expression>>,
9483}
9484
9485/// LanguageProperty
9486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9487#[cfg_attr(feature = "bindings", derive(TS))]
9488pub struct LanguageProperty {
9489    pub this: Box<Expression>,
9490}
9491
9492/// EnviromentProperty
9493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9494#[cfg_attr(feature = "bindings", derive(TS))]
9495pub struct EnviromentProperty {
9496    #[serde(default)]
9497    pub expressions: Vec<Expression>,
9498}
9499
9500/// ClusteredByProperty
9501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9502#[cfg_attr(feature = "bindings", derive(TS))]
9503pub struct ClusteredByProperty {
9504    #[serde(default)]
9505    pub expressions: Vec<Expression>,
9506    #[serde(default)]
9507    pub sorted_by: Option<Box<Expression>>,
9508    #[serde(default)]
9509    pub buckets: Option<Box<Expression>>,
9510}
9511
9512/// DictProperty
9513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9514#[cfg_attr(feature = "bindings", derive(TS))]
9515pub struct DictProperty {
9516    pub this: Box<Expression>,
9517    pub kind: String,
9518    #[serde(default)]
9519    pub settings: Option<Box<Expression>>,
9520}
9521
9522/// DictRange
9523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9524#[cfg_attr(feature = "bindings", derive(TS))]
9525pub struct DictRange {
9526    pub this: Box<Expression>,
9527    #[serde(default)]
9528    pub min: Option<Box<Expression>>,
9529    #[serde(default)]
9530    pub max: Option<Box<Expression>>,
9531}
9532
9533/// OnCluster
9534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9535#[cfg_attr(feature = "bindings", derive(TS))]
9536pub struct OnCluster {
9537    pub this: Box<Expression>,
9538}
9539
9540/// LikeProperty
9541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9542#[cfg_attr(feature = "bindings", derive(TS))]
9543pub struct LikeProperty {
9544    pub this: Box<Expression>,
9545    #[serde(default)]
9546    pub expressions: Vec<Expression>,
9547}
9548
9549/// LocationProperty
9550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9551#[cfg_attr(feature = "bindings", derive(TS))]
9552pub struct LocationProperty {
9553    pub this: Box<Expression>,
9554}
9555
9556/// LockProperty
9557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9558#[cfg_attr(feature = "bindings", derive(TS))]
9559pub struct LockProperty {
9560    pub this: Box<Expression>,
9561}
9562
9563/// LockingProperty
9564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9565#[cfg_attr(feature = "bindings", derive(TS))]
9566pub struct LockingProperty {
9567    #[serde(default)]
9568    pub this: Option<Box<Expression>>,
9569    pub kind: String,
9570    #[serde(default)]
9571    pub for_or_in: Option<Box<Expression>>,
9572    #[serde(default)]
9573    pub lock_type: Option<Box<Expression>>,
9574    #[serde(default)]
9575    pub override_: Option<Box<Expression>>,
9576}
9577
9578/// LogProperty
9579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9580#[cfg_attr(feature = "bindings", derive(TS))]
9581pub struct LogProperty {
9582    #[serde(default)]
9583    pub no: Option<Box<Expression>>,
9584}
9585
9586/// MaterializedProperty
9587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9588#[cfg_attr(feature = "bindings", derive(TS))]
9589pub struct MaterializedProperty {
9590    #[serde(default)]
9591    pub this: Option<Box<Expression>>,
9592}
9593
9594/// MergeBlockRatioProperty
9595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9596#[cfg_attr(feature = "bindings", derive(TS))]
9597pub struct MergeBlockRatioProperty {
9598    #[serde(default)]
9599    pub this: Option<Box<Expression>>,
9600    #[serde(default)]
9601    pub no: Option<Box<Expression>>,
9602    #[serde(default)]
9603    pub default: Option<Box<Expression>>,
9604    #[serde(default)]
9605    pub percent: Option<Box<Expression>>,
9606}
9607
9608/// OnProperty
9609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9610#[cfg_attr(feature = "bindings", derive(TS))]
9611pub struct OnProperty {
9612    pub this: Box<Expression>,
9613}
9614
9615/// OnCommitProperty
9616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9617#[cfg_attr(feature = "bindings", derive(TS))]
9618pub struct OnCommitProperty {
9619    #[serde(default)]
9620    pub delete: Option<Box<Expression>>,
9621}
9622
9623/// PartitionedByProperty
9624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9625#[cfg_attr(feature = "bindings", derive(TS))]
9626pub struct PartitionedByProperty {
9627    pub this: Box<Expression>,
9628}
9629
9630/// BigQuery PARTITION BY property in CREATE TABLE statements.
9631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9632#[cfg_attr(feature = "bindings", derive(TS))]
9633pub struct PartitionByProperty {
9634    #[serde(default)]
9635    pub expressions: Vec<Expression>,
9636}
9637
9638/// PartitionedByBucket
9639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9640#[cfg_attr(feature = "bindings", derive(TS))]
9641pub struct PartitionedByBucket {
9642    pub this: Box<Expression>,
9643    pub expression: Box<Expression>,
9644}
9645
9646/// BigQuery CLUSTER BY property in CREATE TABLE statements.
9647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9648#[cfg_attr(feature = "bindings", derive(TS))]
9649pub struct ClusterByColumnsProperty {
9650    #[serde(default)]
9651    pub columns: Vec<Identifier>,
9652}
9653
9654/// PartitionByTruncate
9655#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9656#[cfg_attr(feature = "bindings", derive(TS))]
9657pub struct PartitionByTruncate {
9658    pub this: Box<Expression>,
9659    pub expression: Box<Expression>,
9660}
9661
9662/// PartitionByRangeProperty
9663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9664#[cfg_attr(feature = "bindings", derive(TS))]
9665pub struct PartitionByRangeProperty {
9666    #[serde(default)]
9667    pub partition_expressions: Option<Box<Expression>>,
9668    #[serde(default)]
9669    pub create_expressions: Option<Box<Expression>>,
9670}
9671
9672/// PartitionByRangePropertyDynamic
9673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9674#[cfg_attr(feature = "bindings", derive(TS))]
9675pub struct PartitionByRangePropertyDynamic {
9676    #[serde(default)]
9677    pub this: Option<Box<Expression>>,
9678    #[serde(default)]
9679    pub start: Option<Box<Expression>>,
9680    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9681    #[serde(default)]
9682    pub use_start_end: bool,
9683    #[serde(default)]
9684    pub end: Option<Box<Expression>>,
9685    #[serde(default)]
9686    pub every: Option<Box<Expression>>,
9687}
9688
9689/// PartitionByListProperty
9690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9691#[cfg_attr(feature = "bindings", derive(TS))]
9692pub struct PartitionByListProperty {
9693    #[serde(default)]
9694    pub partition_expressions: Option<Box<Expression>>,
9695    #[serde(default)]
9696    pub create_expressions: Option<Box<Expression>>,
9697}
9698
9699/// PartitionList
9700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9701#[cfg_attr(feature = "bindings", derive(TS))]
9702pub struct PartitionList {
9703    pub this: Box<Expression>,
9704    #[serde(default)]
9705    pub expressions: Vec<Expression>,
9706}
9707
9708/// Partition - represents PARTITION/SUBPARTITION clause
9709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9710#[cfg_attr(feature = "bindings", derive(TS))]
9711pub struct Partition {
9712    pub expressions: Vec<Expression>,
9713    #[serde(default)]
9714    pub subpartition: bool,
9715}
9716
9717/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9718/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9720#[cfg_attr(feature = "bindings", derive(TS))]
9721pub struct RefreshTriggerProperty {
9722    /// Method: COMPLETE or AUTO
9723    pub method: String,
9724    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9725    #[serde(default)]
9726    pub kind: Option<String>,
9727    /// For SCHEDULE: EVERY n (the number)
9728    #[serde(default)]
9729    pub every: Option<Box<Expression>>,
9730    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9731    #[serde(default)]
9732    pub unit: Option<String>,
9733    /// For SCHEDULE: STARTS 'datetime'
9734    #[serde(default)]
9735    pub starts: Option<Box<Expression>>,
9736}
9737
9738/// UniqueKeyProperty
9739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9740#[cfg_attr(feature = "bindings", derive(TS))]
9741pub struct UniqueKeyProperty {
9742    #[serde(default)]
9743    pub expressions: Vec<Expression>,
9744}
9745
9746/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9748#[cfg_attr(feature = "bindings", derive(TS))]
9749pub struct RollupProperty {
9750    pub expressions: Vec<RollupIndex>,
9751}
9752
9753/// RollupIndex - A single rollup index: name(col1, col2)
9754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9755#[cfg_attr(feature = "bindings", derive(TS))]
9756pub struct RollupIndex {
9757    pub name: Identifier,
9758    pub expressions: Vec<Identifier>,
9759}
9760
9761/// PartitionBoundSpec
9762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9763#[cfg_attr(feature = "bindings", derive(TS))]
9764pub struct PartitionBoundSpec {
9765    #[serde(default)]
9766    pub this: Option<Box<Expression>>,
9767    #[serde(default)]
9768    pub expression: Option<Box<Expression>>,
9769    #[serde(default)]
9770    pub from_expressions: Option<Box<Expression>>,
9771    #[serde(default)]
9772    pub to_expressions: Option<Box<Expression>>,
9773}
9774
9775/// PartitionedOfProperty
9776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9777#[cfg_attr(feature = "bindings", derive(TS))]
9778pub struct PartitionedOfProperty {
9779    pub this: Box<Expression>,
9780    pub expression: Box<Expression>,
9781}
9782
9783/// RemoteWithConnectionModelProperty
9784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9785#[cfg_attr(feature = "bindings", derive(TS))]
9786pub struct RemoteWithConnectionModelProperty {
9787    pub this: Box<Expression>,
9788}
9789
9790/// ReturnsProperty
9791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9792#[cfg_attr(feature = "bindings", derive(TS))]
9793pub struct ReturnsProperty {
9794    #[serde(default)]
9795    pub this: Option<Box<Expression>>,
9796    #[serde(default)]
9797    pub is_table: Option<Box<Expression>>,
9798    #[serde(default)]
9799    pub table: Option<Box<Expression>>,
9800    #[serde(default)]
9801    pub null: Option<Box<Expression>>,
9802}
9803
9804/// RowFormatProperty
9805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9806#[cfg_attr(feature = "bindings", derive(TS))]
9807pub struct RowFormatProperty {
9808    pub this: Box<Expression>,
9809}
9810
9811/// RowFormatDelimitedProperty
9812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9813#[cfg_attr(feature = "bindings", derive(TS))]
9814pub struct RowFormatDelimitedProperty {
9815    #[serde(default)]
9816    pub fields: Option<Box<Expression>>,
9817    #[serde(default)]
9818    pub escaped: Option<Box<Expression>>,
9819    #[serde(default)]
9820    pub collection_items: Option<Box<Expression>>,
9821    #[serde(default)]
9822    pub map_keys: Option<Box<Expression>>,
9823    #[serde(default)]
9824    pub lines: Option<Box<Expression>>,
9825    #[serde(default)]
9826    pub null: Option<Box<Expression>>,
9827    #[serde(default)]
9828    pub serde: Option<Box<Expression>>,
9829}
9830
9831/// RowFormatSerdeProperty
9832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9833#[cfg_attr(feature = "bindings", derive(TS))]
9834pub struct RowFormatSerdeProperty {
9835    pub this: Box<Expression>,
9836    #[serde(default)]
9837    pub serde_properties: Option<Box<Expression>>,
9838}
9839
9840/// QueryTransform
9841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9842#[cfg_attr(feature = "bindings", derive(TS))]
9843pub struct QueryTransform {
9844    #[serde(default)]
9845    pub expressions: Vec<Expression>,
9846    #[serde(default)]
9847    pub command_script: Option<Box<Expression>>,
9848    #[serde(default)]
9849    pub schema: Option<Box<Expression>>,
9850    #[serde(default)]
9851    pub row_format_before: Option<Box<Expression>>,
9852    #[serde(default)]
9853    pub record_writer: Option<Box<Expression>>,
9854    #[serde(default)]
9855    pub row_format_after: Option<Box<Expression>>,
9856    #[serde(default)]
9857    pub record_reader: Option<Box<Expression>>,
9858}
9859
9860/// SampleProperty
9861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9862#[cfg_attr(feature = "bindings", derive(TS))]
9863pub struct SampleProperty {
9864    pub this: Box<Expression>,
9865}
9866
9867/// SecurityProperty
9868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9869#[cfg_attr(feature = "bindings", derive(TS))]
9870pub struct SecurityProperty {
9871    pub this: Box<Expression>,
9872}
9873
9874/// SchemaCommentProperty
9875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9876#[cfg_attr(feature = "bindings", derive(TS))]
9877pub struct SchemaCommentProperty {
9878    pub this: Box<Expression>,
9879}
9880
9881/// SemanticView
9882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9883#[cfg_attr(feature = "bindings", derive(TS))]
9884pub struct SemanticView {
9885    pub this: Box<Expression>,
9886    #[serde(default)]
9887    pub metrics: Option<Box<Expression>>,
9888    #[serde(default)]
9889    pub dimensions: Option<Box<Expression>>,
9890    #[serde(default)]
9891    pub facts: Option<Box<Expression>>,
9892    #[serde(default)]
9893    pub where_: Option<Box<Expression>>,
9894}
9895
9896/// SerdeProperties
9897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9898#[cfg_attr(feature = "bindings", derive(TS))]
9899pub struct SerdeProperties {
9900    #[serde(default)]
9901    pub expressions: Vec<Expression>,
9902    #[serde(default)]
9903    pub with_: Option<Box<Expression>>,
9904}
9905
9906/// SetProperty
9907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9908#[cfg_attr(feature = "bindings", derive(TS))]
9909pub struct SetProperty {
9910    #[serde(default)]
9911    pub multi: Option<Box<Expression>>,
9912}
9913
9914/// SharingProperty
9915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9916#[cfg_attr(feature = "bindings", derive(TS))]
9917pub struct SharingProperty {
9918    #[serde(default)]
9919    pub this: Option<Box<Expression>>,
9920}
9921
9922/// SetConfigProperty
9923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9924#[cfg_attr(feature = "bindings", derive(TS))]
9925pub struct SetConfigProperty {
9926    pub this: Box<Expression>,
9927}
9928
9929/// SettingsProperty
9930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9931#[cfg_attr(feature = "bindings", derive(TS))]
9932pub struct SettingsProperty {
9933    #[serde(default)]
9934    pub expressions: Vec<Expression>,
9935}
9936
9937/// SortKeyProperty
9938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9939#[cfg_attr(feature = "bindings", derive(TS))]
9940pub struct SortKeyProperty {
9941    pub this: Box<Expression>,
9942    #[serde(default)]
9943    pub compound: Option<Box<Expression>>,
9944}
9945
9946/// SqlReadWriteProperty
9947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9948#[cfg_attr(feature = "bindings", derive(TS))]
9949pub struct SqlReadWriteProperty {
9950    pub this: Box<Expression>,
9951}
9952
9953/// SqlSecurityProperty
9954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9955#[cfg_attr(feature = "bindings", derive(TS))]
9956pub struct SqlSecurityProperty {
9957    pub this: Box<Expression>,
9958}
9959
9960/// StabilityProperty
9961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9962#[cfg_attr(feature = "bindings", derive(TS))]
9963pub struct StabilityProperty {
9964    pub this: Box<Expression>,
9965}
9966
9967/// StorageHandlerProperty
9968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9969#[cfg_attr(feature = "bindings", derive(TS))]
9970pub struct StorageHandlerProperty {
9971    pub this: Box<Expression>,
9972}
9973
9974/// TemporaryProperty
9975#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9976#[cfg_attr(feature = "bindings", derive(TS))]
9977pub struct TemporaryProperty {
9978    #[serde(default)]
9979    pub this: Option<Box<Expression>>,
9980}
9981
9982/// Tags
9983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9984#[cfg_attr(feature = "bindings", derive(TS))]
9985pub struct Tags {
9986    #[serde(default)]
9987    pub expressions: Vec<Expression>,
9988}
9989
9990/// TransformModelProperty
9991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9992#[cfg_attr(feature = "bindings", derive(TS))]
9993pub struct TransformModelProperty {
9994    #[serde(default)]
9995    pub expressions: Vec<Expression>,
9996}
9997
9998/// TransientProperty
9999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10000#[cfg_attr(feature = "bindings", derive(TS))]
10001pub struct TransientProperty {
10002    #[serde(default)]
10003    pub this: Option<Box<Expression>>,
10004}
10005
10006/// UsingTemplateProperty
10007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10008#[cfg_attr(feature = "bindings", derive(TS))]
10009pub struct UsingTemplateProperty {
10010    pub this: Box<Expression>,
10011}
10012
10013/// ViewAttributeProperty
10014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10015#[cfg_attr(feature = "bindings", derive(TS))]
10016pub struct ViewAttributeProperty {
10017    pub this: Box<Expression>,
10018}
10019
10020/// VolatileProperty
10021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10022#[cfg_attr(feature = "bindings", derive(TS))]
10023pub struct VolatileProperty {
10024    #[serde(default)]
10025    pub this: Option<Box<Expression>>,
10026}
10027
10028/// WithDataProperty
10029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10030#[cfg_attr(feature = "bindings", derive(TS))]
10031pub struct WithDataProperty {
10032    #[serde(default)]
10033    pub no: Option<Box<Expression>>,
10034    #[serde(default)]
10035    pub statistics: Option<Box<Expression>>,
10036}
10037
10038/// WithJournalTableProperty
10039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10040#[cfg_attr(feature = "bindings", derive(TS))]
10041pub struct WithJournalTableProperty {
10042    pub this: Box<Expression>,
10043}
10044
10045/// WithSchemaBindingProperty
10046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10047#[cfg_attr(feature = "bindings", derive(TS))]
10048pub struct WithSchemaBindingProperty {
10049    pub this: Box<Expression>,
10050}
10051
10052/// WithSystemVersioningProperty
10053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10054#[cfg_attr(feature = "bindings", derive(TS))]
10055pub struct WithSystemVersioningProperty {
10056    #[serde(default)]
10057    pub on: Option<Box<Expression>>,
10058    #[serde(default)]
10059    pub this: Option<Box<Expression>>,
10060    #[serde(default)]
10061    pub data_consistency: Option<Box<Expression>>,
10062    #[serde(default)]
10063    pub retention_period: Option<Box<Expression>>,
10064    #[serde(default)]
10065    pub with_: Option<Box<Expression>>,
10066}
10067
10068/// WithProcedureOptions
10069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10070#[cfg_attr(feature = "bindings", derive(TS))]
10071pub struct WithProcedureOptions {
10072    #[serde(default)]
10073    pub expressions: Vec<Expression>,
10074}
10075
10076/// EncodeProperty
10077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10078#[cfg_attr(feature = "bindings", derive(TS))]
10079pub struct EncodeProperty {
10080    pub this: Box<Expression>,
10081    #[serde(default)]
10082    pub properties: Vec<Expression>,
10083    #[serde(default)]
10084    pub key: Option<Box<Expression>>,
10085}
10086
10087/// IncludeProperty
10088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10089#[cfg_attr(feature = "bindings", derive(TS))]
10090pub struct IncludeProperty {
10091    pub this: Box<Expression>,
10092    #[serde(default)]
10093    pub alias: Option<String>,
10094    #[serde(default)]
10095    pub column_def: Option<Box<Expression>>,
10096}
10097
10098/// Properties
10099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10100#[cfg_attr(feature = "bindings", derive(TS))]
10101pub struct Properties {
10102    #[serde(default)]
10103    pub expressions: Vec<Expression>,
10104}
10105
10106/// Key/value pair in a BigQuery OPTIONS (...) clause.
10107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10108#[cfg_attr(feature = "bindings", derive(TS))]
10109pub struct OptionEntry {
10110    pub key: Identifier,
10111    pub value: Expression,
10112}
10113
10114/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
10115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10116#[cfg_attr(feature = "bindings", derive(TS))]
10117pub struct OptionsProperty {
10118    #[serde(default)]
10119    pub entries: Vec<OptionEntry>,
10120}
10121
10122/// InputOutputFormat
10123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10124#[cfg_attr(feature = "bindings", derive(TS))]
10125pub struct InputOutputFormat {
10126    #[serde(default)]
10127    pub input_format: Option<Box<Expression>>,
10128    #[serde(default)]
10129    pub output_format: Option<Box<Expression>>,
10130}
10131
10132/// Reference
10133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10134#[cfg_attr(feature = "bindings", derive(TS))]
10135pub struct Reference {
10136    pub this: Box<Expression>,
10137    #[serde(default)]
10138    pub expressions: Vec<Expression>,
10139    #[serde(default)]
10140    pub options: Vec<Expression>,
10141}
10142
10143/// QueryOption
10144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10145#[cfg_attr(feature = "bindings", derive(TS))]
10146pub struct QueryOption {
10147    pub this: Box<Expression>,
10148    #[serde(default)]
10149    pub expression: Option<Box<Expression>>,
10150}
10151
10152/// WithTableHint
10153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10154#[cfg_attr(feature = "bindings", derive(TS))]
10155pub struct WithTableHint {
10156    #[serde(default)]
10157    pub expressions: Vec<Expression>,
10158}
10159
10160/// IndexTableHint
10161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10162#[cfg_attr(feature = "bindings", derive(TS))]
10163pub struct IndexTableHint {
10164    pub this: Box<Expression>,
10165    #[serde(default)]
10166    pub expressions: Vec<Expression>,
10167    #[serde(default)]
10168    pub target: Option<Box<Expression>>,
10169}
10170
10171/// Get
10172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10173#[cfg_attr(feature = "bindings", derive(TS))]
10174pub struct Get {
10175    pub this: Box<Expression>,
10176    #[serde(default)]
10177    pub target: Option<Box<Expression>>,
10178    #[serde(default)]
10179    pub properties: Vec<Expression>,
10180}
10181
10182/// SetOperation
10183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10184#[cfg_attr(feature = "bindings", derive(TS))]
10185pub struct SetOperation {
10186    #[serde(default)]
10187    pub with_: Option<Box<Expression>>,
10188    pub this: Box<Expression>,
10189    pub expression: Box<Expression>,
10190    #[serde(default)]
10191    pub distinct: bool,
10192    #[serde(default)]
10193    pub by_name: Option<Box<Expression>>,
10194    #[serde(default)]
10195    pub side: Option<Box<Expression>>,
10196    #[serde(default)]
10197    pub kind: Option<String>,
10198    #[serde(default)]
10199    pub on: Option<Box<Expression>>,
10200}
10201
10202/// Var - Simple variable reference (for SQL variables, keywords as values)
10203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10204#[cfg_attr(feature = "bindings", derive(TS))]
10205pub struct Var {
10206    pub this: String,
10207}
10208
10209/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
10210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10211#[cfg_attr(feature = "bindings", derive(TS))]
10212pub struct Variadic {
10213    pub this: Box<Expression>,
10214}
10215
10216/// Version
10217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10218#[cfg_attr(feature = "bindings", derive(TS))]
10219pub struct Version {
10220    pub this: Box<Expression>,
10221    pub kind: String,
10222    #[serde(default)]
10223    pub expression: Option<Box<Expression>>,
10224}
10225
10226/// Schema
10227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10228#[cfg_attr(feature = "bindings", derive(TS))]
10229pub struct Schema {
10230    #[serde(default)]
10231    pub this: Option<Box<Expression>>,
10232    #[serde(default)]
10233    pub expressions: Vec<Expression>,
10234}
10235
10236/// Lock
10237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10238#[cfg_attr(feature = "bindings", derive(TS))]
10239pub struct Lock {
10240    #[serde(default)]
10241    pub update: Option<Box<Expression>>,
10242    #[serde(default)]
10243    pub expressions: Vec<Expression>,
10244    #[serde(default)]
10245    pub wait: Option<Box<Expression>>,
10246    #[serde(default)]
10247    pub key: Option<Box<Expression>>,
10248}
10249
10250/// TableSample - wraps an expression with a TABLESAMPLE clause
10251/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
10252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10253#[cfg_attr(feature = "bindings", derive(TS))]
10254pub struct TableSample {
10255    /// The expression being sampled (subquery, function, etc.)
10256    #[serde(default, skip_serializing_if = "Option::is_none")]
10257    pub this: Option<Box<Expression>>,
10258    /// The sample specification
10259    #[serde(default, skip_serializing_if = "Option::is_none")]
10260    pub sample: Option<Box<Sample>>,
10261    #[serde(default)]
10262    pub expressions: Vec<Expression>,
10263    #[serde(default)]
10264    pub method: Option<String>,
10265    #[serde(default)]
10266    pub bucket_numerator: Option<Box<Expression>>,
10267    #[serde(default)]
10268    pub bucket_denominator: Option<Box<Expression>>,
10269    #[serde(default)]
10270    pub bucket_field: Option<Box<Expression>>,
10271    #[serde(default)]
10272    pub percent: Option<Box<Expression>>,
10273    #[serde(default)]
10274    pub rows: Option<Box<Expression>>,
10275    #[serde(default)]
10276    pub size: Option<i64>,
10277    #[serde(default)]
10278    pub seed: Option<Box<Expression>>,
10279}
10280
10281/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
10282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10283#[cfg_attr(feature = "bindings", derive(TS))]
10284pub struct Tag {
10285    #[serde(default)]
10286    pub this: Option<Box<Expression>>,
10287    #[serde(default)]
10288    pub prefix: Option<Box<Expression>>,
10289    #[serde(default)]
10290    pub postfix: Option<Box<Expression>>,
10291}
10292
10293/// UnpivotColumns
10294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10295#[cfg_attr(feature = "bindings", derive(TS))]
10296pub struct UnpivotColumns {
10297    pub this: Box<Expression>,
10298    #[serde(default)]
10299    pub expressions: Vec<Expression>,
10300}
10301
10302/// SessionParameter
10303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10304#[cfg_attr(feature = "bindings", derive(TS))]
10305pub struct SessionParameter {
10306    pub this: Box<Expression>,
10307    #[serde(default)]
10308    pub kind: Option<String>,
10309}
10310
10311/// PseudoType
10312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10313#[cfg_attr(feature = "bindings", derive(TS))]
10314pub struct PseudoType {
10315    pub this: Box<Expression>,
10316}
10317
10318/// ObjectIdentifier
10319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10320#[cfg_attr(feature = "bindings", derive(TS))]
10321pub struct ObjectIdentifier {
10322    pub this: Box<Expression>,
10323}
10324
10325/// Transaction
10326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10327#[cfg_attr(feature = "bindings", derive(TS))]
10328pub struct Transaction {
10329    #[serde(default)]
10330    pub this: Option<Box<Expression>>,
10331    #[serde(default)]
10332    pub modes: Option<Box<Expression>>,
10333    #[serde(default)]
10334    pub mark: Option<Box<Expression>>,
10335}
10336
10337/// Commit
10338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10339#[cfg_attr(feature = "bindings", derive(TS))]
10340pub struct Commit {
10341    #[serde(default)]
10342    pub chain: Option<Box<Expression>>,
10343    #[serde(default)]
10344    pub this: Option<Box<Expression>>,
10345    #[serde(default)]
10346    pub durability: Option<Box<Expression>>,
10347}
10348
10349/// Rollback
10350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10351#[cfg_attr(feature = "bindings", derive(TS))]
10352pub struct Rollback {
10353    #[serde(default)]
10354    pub savepoint: Option<Box<Expression>>,
10355    #[serde(default)]
10356    pub this: Option<Box<Expression>>,
10357}
10358
10359/// AlterSession
10360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10361#[cfg_attr(feature = "bindings", derive(TS))]
10362pub struct AlterSession {
10363    #[serde(default)]
10364    pub expressions: Vec<Expression>,
10365    #[serde(default)]
10366    pub unset: Option<Box<Expression>>,
10367}
10368
10369/// Analyze
10370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10371#[cfg_attr(feature = "bindings", derive(TS))]
10372pub struct Analyze {
10373    #[serde(default)]
10374    pub kind: Option<String>,
10375    #[serde(default)]
10376    pub this: Option<Box<Expression>>,
10377    #[serde(default)]
10378    pub options: Vec<Expression>,
10379    #[serde(default)]
10380    pub mode: Option<Box<Expression>>,
10381    #[serde(default)]
10382    pub partition: Option<Box<Expression>>,
10383    #[serde(default)]
10384    pub expression: Option<Box<Expression>>,
10385    #[serde(default)]
10386    pub properties: Vec<Expression>,
10387    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
10388    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10389    pub columns: Vec<String>,
10390}
10391
10392/// AnalyzeStatistics
10393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10394#[cfg_attr(feature = "bindings", derive(TS))]
10395pub struct AnalyzeStatistics {
10396    pub kind: String,
10397    #[serde(default)]
10398    pub option: Option<Box<Expression>>,
10399    #[serde(default)]
10400    pub this: Option<Box<Expression>>,
10401    #[serde(default)]
10402    pub expressions: Vec<Expression>,
10403}
10404
10405/// AnalyzeHistogram
10406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10407#[cfg_attr(feature = "bindings", derive(TS))]
10408pub struct AnalyzeHistogram {
10409    pub this: Box<Expression>,
10410    #[serde(default)]
10411    pub expressions: Vec<Expression>,
10412    #[serde(default)]
10413    pub expression: Option<Box<Expression>>,
10414    #[serde(default)]
10415    pub update_options: Option<Box<Expression>>,
10416}
10417
10418/// AnalyzeSample
10419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10420#[cfg_attr(feature = "bindings", derive(TS))]
10421pub struct AnalyzeSample {
10422    pub kind: String,
10423    #[serde(default)]
10424    pub sample: Option<Box<Expression>>,
10425}
10426
10427/// AnalyzeListChainedRows
10428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10429#[cfg_attr(feature = "bindings", derive(TS))]
10430pub struct AnalyzeListChainedRows {
10431    #[serde(default)]
10432    pub expression: Option<Box<Expression>>,
10433}
10434
10435/// AnalyzeDelete
10436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10437#[cfg_attr(feature = "bindings", derive(TS))]
10438pub struct AnalyzeDelete {
10439    #[serde(default)]
10440    pub kind: Option<String>,
10441}
10442
10443/// AnalyzeWith
10444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10445#[cfg_attr(feature = "bindings", derive(TS))]
10446pub struct AnalyzeWith {
10447    #[serde(default)]
10448    pub expressions: Vec<Expression>,
10449}
10450
10451/// AnalyzeValidate
10452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10453#[cfg_attr(feature = "bindings", derive(TS))]
10454pub struct AnalyzeValidate {
10455    pub kind: String,
10456    #[serde(default)]
10457    pub this: Option<Box<Expression>>,
10458    #[serde(default)]
10459    pub expression: Option<Box<Expression>>,
10460}
10461
10462/// AddPartition
10463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10464#[cfg_attr(feature = "bindings", derive(TS))]
10465pub struct AddPartition {
10466    pub this: Box<Expression>,
10467    #[serde(default)]
10468    pub exists: bool,
10469    #[serde(default)]
10470    pub location: Option<Box<Expression>>,
10471}
10472
10473/// AttachOption
10474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10475#[cfg_attr(feature = "bindings", derive(TS))]
10476pub struct AttachOption {
10477    pub this: Box<Expression>,
10478    #[serde(default)]
10479    pub expression: Option<Box<Expression>>,
10480}
10481
10482/// DropPartition
10483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10484#[cfg_attr(feature = "bindings", derive(TS))]
10485pub struct DropPartition {
10486    #[serde(default)]
10487    pub expressions: Vec<Expression>,
10488    #[serde(default)]
10489    pub exists: bool,
10490}
10491
10492/// ReplacePartition
10493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10494#[cfg_attr(feature = "bindings", derive(TS))]
10495pub struct ReplacePartition {
10496    pub expression: Box<Expression>,
10497    #[serde(default)]
10498    pub source: Option<Box<Expression>>,
10499}
10500
10501/// DPipe
10502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10503#[cfg_attr(feature = "bindings", derive(TS))]
10504pub struct DPipe {
10505    pub this: Box<Expression>,
10506    pub expression: Box<Expression>,
10507    #[serde(default)]
10508    pub safe: Option<Box<Expression>>,
10509}
10510
10511/// Operator
10512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10513#[cfg_attr(feature = "bindings", derive(TS))]
10514pub struct Operator {
10515    pub this: Box<Expression>,
10516    #[serde(default)]
10517    pub operator: Option<Box<Expression>>,
10518    pub expression: Box<Expression>,
10519    /// Comments between OPERATOR() and the RHS expression
10520    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10521    pub comments: Vec<String>,
10522}
10523
10524/// PivotAny
10525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10526#[cfg_attr(feature = "bindings", derive(TS))]
10527pub struct PivotAny {
10528    #[serde(default)]
10529    pub this: Option<Box<Expression>>,
10530}
10531
10532/// Aliases
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct Aliases {
10536    pub this: Box<Expression>,
10537    #[serde(default)]
10538    pub expressions: Vec<Expression>,
10539}
10540
10541/// AtIndex
10542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10543#[cfg_attr(feature = "bindings", derive(TS))]
10544pub struct AtIndex {
10545    pub this: Box<Expression>,
10546    pub expression: Box<Expression>,
10547}
10548
10549/// FromTimeZone
10550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10551#[cfg_attr(feature = "bindings", derive(TS))]
10552pub struct FromTimeZone {
10553    pub this: Box<Expression>,
10554    #[serde(default)]
10555    pub zone: Option<Box<Expression>>,
10556}
10557
10558/// Format override for a column in Teradata
10559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10560#[cfg_attr(feature = "bindings", derive(TS))]
10561pub struct FormatPhrase {
10562    pub this: Box<Expression>,
10563    pub format: String,
10564}
10565
10566/// ForIn
10567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10568#[cfg_attr(feature = "bindings", derive(TS))]
10569pub struct ForIn {
10570    pub this: Box<Expression>,
10571    pub expression: Box<Expression>,
10572}
10573
10574/// Automatically converts unit arg into a var.
10575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10576#[cfg_attr(feature = "bindings", derive(TS))]
10577pub struct TimeUnit {
10578    #[serde(default)]
10579    pub unit: Option<String>,
10580}
10581
10582/// IntervalOp
10583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10584#[cfg_attr(feature = "bindings", derive(TS))]
10585pub struct IntervalOp {
10586    #[serde(default)]
10587    pub unit: Option<String>,
10588    pub expression: Box<Expression>,
10589}
10590
10591/// HavingMax
10592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10593#[cfg_attr(feature = "bindings", derive(TS))]
10594pub struct HavingMax {
10595    pub this: Box<Expression>,
10596    pub expression: Box<Expression>,
10597    #[serde(default)]
10598    pub max: Option<Box<Expression>>,
10599}
10600
10601/// CosineDistance
10602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10603#[cfg_attr(feature = "bindings", derive(TS))]
10604pub struct CosineDistance {
10605    pub this: Box<Expression>,
10606    pub expression: Box<Expression>,
10607}
10608
10609/// DotProduct
10610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10611#[cfg_attr(feature = "bindings", derive(TS))]
10612pub struct DotProduct {
10613    pub this: Box<Expression>,
10614    pub expression: Box<Expression>,
10615}
10616
10617/// EuclideanDistance
10618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10619#[cfg_attr(feature = "bindings", derive(TS))]
10620pub struct EuclideanDistance {
10621    pub this: Box<Expression>,
10622    pub expression: Box<Expression>,
10623}
10624
10625/// ManhattanDistance
10626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10627#[cfg_attr(feature = "bindings", derive(TS))]
10628pub struct ManhattanDistance {
10629    pub this: Box<Expression>,
10630    pub expression: Box<Expression>,
10631}
10632
10633/// JarowinklerSimilarity
10634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10635#[cfg_attr(feature = "bindings", derive(TS))]
10636pub struct JarowinklerSimilarity {
10637    pub this: Box<Expression>,
10638    pub expression: Box<Expression>,
10639}
10640
10641/// Booland
10642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10643#[cfg_attr(feature = "bindings", derive(TS))]
10644pub struct Booland {
10645    pub this: Box<Expression>,
10646    pub expression: Box<Expression>,
10647}
10648
10649/// Boolor
10650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10651#[cfg_attr(feature = "bindings", derive(TS))]
10652pub struct Boolor {
10653    pub this: Box<Expression>,
10654    pub expression: Box<Expression>,
10655}
10656
10657/// ParameterizedAgg
10658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10659#[cfg_attr(feature = "bindings", derive(TS))]
10660pub struct ParameterizedAgg {
10661    pub this: Box<Expression>,
10662    #[serde(default)]
10663    pub expressions: Vec<Expression>,
10664    #[serde(default)]
10665    pub params: Vec<Expression>,
10666}
10667
10668/// ArgMax
10669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10670#[cfg_attr(feature = "bindings", derive(TS))]
10671pub struct ArgMax {
10672    pub this: Box<Expression>,
10673    pub expression: Box<Expression>,
10674    #[serde(default)]
10675    pub count: Option<Box<Expression>>,
10676}
10677
10678/// ArgMin
10679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10680#[cfg_attr(feature = "bindings", derive(TS))]
10681pub struct ArgMin {
10682    pub this: Box<Expression>,
10683    pub expression: Box<Expression>,
10684    #[serde(default)]
10685    pub count: Option<Box<Expression>>,
10686}
10687
10688/// ApproxTopK
10689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10690#[cfg_attr(feature = "bindings", derive(TS))]
10691pub struct ApproxTopK {
10692    pub this: Box<Expression>,
10693    #[serde(default)]
10694    pub expression: Option<Box<Expression>>,
10695    #[serde(default)]
10696    pub counters: Option<Box<Expression>>,
10697}
10698
10699/// ApproxTopKAccumulate
10700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10701#[cfg_attr(feature = "bindings", derive(TS))]
10702pub struct ApproxTopKAccumulate {
10703    pub this: Box<Expression>,
10704    #[serde(default)]
10705    pub expression: Option<Box<Expression>>,
10706}
10707
10708/// ApproxTopKCombine
10709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10710#[cfg_attr(feature = "bindings", derive(TS))]
10711pub struct ApproxTopKCombine {
10712    pub this: Box<Expression>,
10713    #[serde(default)]
10714    pub expression: Option<Box<Expression>>,
10715}
10716
10717/// ApproxTopKEstimate
10718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10719#[cfg_attr(feature = "bindings", derive(TS))]
10720pub struct ApproxTopKEstimate {
10721    pub this: Box<Expression>,
10722    #[serde(default)]
10723    pub expression: Option<Box<Expression>>,
10724}
10725
10726/// ApproxTopSum
10727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10728#[cfg_attr(feature = "bindings", derive(TS))]
10729pub struct ApproxTopSum {
10730    pub this: Box<Expression>,
10731    pub expression: Box<Expression>,
10732    #[serde(default)]
10733    pub count: Option<Box<Expression>>,
10734}
10735
10736/// ApproxQuantiles
10737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10738#[cfg_attr(feature = "bindings", derive(TS))]
10739pub struct ApproxQuantiles {
10740    pub this: Box<Expression>,
10741    #[serde(default)]
10742    pub expression: Option<Box<Expression>>,
10743}
10744
10745/// Minhash
10746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10747#[cfg_attr(feature = "bindings", derive(TS))]
10748pub struct Minhash {
10749    pub this: Box<Expression>,
10750    #[serde(default)]
10751    pub expressions: Vec<Expression>,
10752}
10753
10754/// FarmFingerprint
10755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10756#[cfg_attr(feature = "bindings", derive(TS))]
10757pub struct FarmFingerprint {
10758    #[serde(default)]
10759    pub expressions: Vec<Expression>,
10760}
10761
10762/// Float64
10763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10764#[cfg_attr(feature = "bindings", derive(TS))]
10765pub struct Float64 {
10766    pub this: Box<Expression>,
10767    #[serde(default)]
10768    pub expression: Option<Box<Expression>>,
10769}
10770
10771/// Transform
10772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10773#[cfg_attr(feature = "bindings", derive(TS))]
10774pub struct Transform {
10775    pub this: Box<Expression>,
10776    pub expression: Box<Expression>,
10777}
10778
10779/// Translate
10780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10781#[cfg_attr(feature = "bindings", derive(TS))]
10782pub struct Translate {
10783    pub this: Box<Expression>,
10784    #[serde(default)]
10785    pub from_: Option<Box<Expression>>,
10786    #[serde(default)]
10787    pub to: Option<Box<Expression>>,
10788}
10789
10790/// Grouping
10791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10792#[cfg_attr(feature = "bindings", derive(TS))]
10793pub struct Grouping {
10794    #[serde(default)]
10795    pub expressions: Vec<Expression>,
10796}
10797
10798/// GroupingId
10799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10800#[cfg_attr(feature = "bindings", derive(TS))]
10801pub struct GroupingId {
10802    #[serde(default)]
10803    pub expressions: Vec<Expression>,
10804}
10805
10806/// Anonymous
10807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10808#[cfg_attr(feature = "bindings", derive(TS))]
10809pub struct Anonymous {
10810    pub this: Box<Expression>,
10811    #[serde(default)]
10812    pub expressions: Vec<Expression>,
10813}
10814
10815/// AnonymousAggFunc
10816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10817#[cfg_attr(feature = "bindings", derive(TS))]
10818pub struct AnonymousAggFunc {
10819    pub this: Box<Expression>,
10820    #[serde(default)]
10821    pub expressions: Vec<Expression>,
10822}
10823
10824/// CombinedAggFunc
10825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10826#[cfg_attr(feature = "bindings", derive(TS))]
10827pub struct CombinedAggFunc {
10828    pub this: Box<Expression>,
10829    #[serde(default)]
10830    pub expressions: Vec<Expression>,
10831}
10832
10833/// CombinedParameterizedAgg
10834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10835#[cfg_attr(feature = "bindings", derive(TS))]
10836pub struct CombinedParameterizedAgg {
10837    pub this: Box<Expression>,
10838    #[serde(default)]
10839    pub expressions: Vec<Expression>,
10840    #[serde(default)]
10841    pub params: Vec<Expression>,
10842}
10843
10844/// HashAgg
10845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10846#[cfg_attr(feature = "bindings", derive(TS))]
10847pub struct HashAgg {
10848    pub this: Box<Expression>,
10849    #[serde(default)]
10850    pub expressions: Vec<Expression>,
10851}
10852
10853/// Hll
10854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10855#[cfg_attr(feature = "bindings", derive(TS))]
10856pub struct Hll {
10857    pub this: Box<Expression>,
10858    #[serde(default)]
10859    pub expressions: Vec<Expression>,
10860}
10861
10862/// Apply
10863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10864#[cfg_attr(feature = "bindings", derive(TS))]
10865pub struct Apply {
10866    pub this: Box<Expression>,
10867    pub expression: Box<Expression>,
10868}
10869
10870/// ToBoolean
10871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10872#[cfg_attr(feature = "bindings", derive(TS))]
10873pub struct ToBoolean {
10874    pub this: Box<Expression>,
10875    #[serde(default)]
10876    pub safe: Option<Box<Expression>>,
10877}
10878
10879/// List
10880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10881#[cfg_attr(feature = "bindings", derive(TS))]
10882pub struct List {
10883    #[serde(default)]
10884    pub expressions: Vec<Expression>,
10885}
10886
10887/// ToMap - Materialize-style map constructor
10888/// Can hold either:
10889/// - A SELECT subquery (MAP(SELECT 'a', 1))
10890/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10892#[cfg_attr(feature = "bindings", derive(TS))]
10893pub struct ToMap {
10894    /// Either a Select subquery or a Struct containing PropertyEQ entries
10895    pub this: Box<Expression>,
10896}
10897
10898/// Pad
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct Pad {
10902    pub this: Box<Expression>,
10903    pub expression: Box<Expression>,
10904    #[serde(default)]
10905    pub fill_pattern: Option<Box<Expression>>,
10906    #[serde(default)]
10907    pub is_left: Option<Box<Expression>>,
10908}
10909
10910/// ToChar
10911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10912#[cfg_attr(feature = "bindings", derive(TS))]
10913pub struct ToChar {
10914    pub this: Box<Expression>,
10915    #[serde(default)]
10916    pub format: Option<String>,
10917    #[serde(default)]
10918    pub nlsparam: Option<Box<Expression>>,
10919    #[serde(default)]
10920    pub is_numeric: Option<Box<Expression>>,
10921}
10922
10923/// StringFunc - String type conversion function (BigQuery STRING)
10924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10925#[cfg_attr(feature = "bindings", derive(TS))]
10926pub struct StringFunc {
10927    pub this: Box<Expression>,
10928    #[serde(default)]
10929    pub zone: Option<Box<Expression>>,
10930}
10931
10932/// ToNumber
10933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10934#[cfg_attr(feature = "bindings", derive(TS))]
10935pub struct ToNumber {
10936    pub this: Box<Expression>,
10937    #[serde(default)]
10938    pub format: Option<Box<Expression>>,
10939    #[serde(default)]
10940    pub nlsparam: Option<Box<Expression>>,
10941    #[serde(default)]
10942    pub precision: Option<Box<Expression>>,
10943    #[serde(default)]
10944    pub scale: Option<Box<Expression>>,
10945    #[serde(default)]
10946    pub safe: Option<Box<Expression>>,
10947    #[serde(default)]
10948    pub safe_name: Option<Box<Expression>>,
10949}
10950
10951/// ToDouble
10952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10953#[cfg_attr(feature = "bindings", derive(TS))]
10954pub struct ToDouble {
10955    pub this: Box<Expression>,
10956    #[serde(default)]
10957    pub format: Option<String>,
10958    #[serde(default)]
10959    pub safe: Option<Box<Expression>>,
10960}
10961
10962/// ToDecfloat
10963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10964#[cfg_attr(feature = "bindings", derive(TS))]
10965pub struct ToDecfloat {
10966    pub this: Box<Expression>,
10967    #[serde(default)]
10968    pub format: Option<String>,
10969}
10970
10971/// TryToDecfloat
10972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10973#[cfg_attr(feature = "bindings", derive(TS))]
10974pub struct TryToDecfloat {
10975    pub this: Box<Expression>,
10976    #[serde(default)]
10977    pub format: Option<String>,
10978}
10979
10980/// ToFile
10981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10982#[cfg_attr(feature = "bindings", derive(TS))]
10983pub struct ToFile {
10984    pub this: Box<Expression>,
10985    #[serde(default)]
10986    pub path: Option<Box<Expression>>,
10987    #[serde(default)]
10988    pub safe: Option<Box<Expression>>,
10989}
10990
10991/// Columns
10992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10993#[cfg_attr(feature = "bindings", derive(TS))]
10994pub struct Columns {
10995    pub this: Box<Expression>,
10996    #[serde(default)]
10997    pub unpack: Option<Box<Expression>>,
10998}
10999
11000/// ConvertToCharset
11001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11002#[cfg_attr(feature = "bindings", derive(TS))]
11003pub struct ConvertToCharset {
11004    pub this: Box<Expression>,
11005    #[serde(default)]
11006    pub dest: Option<Box<Expression>>,
11007    #[serde(default)]
11008    pub source: Option<Box<Expression>>,
11009}
11010
11011/// ConvertTimezone
11012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11013#[cfg_attr(feature = "bindings", derive(TS))]
11014pub struct ConvertTimezone {
11015    #[serde(default)]
11016    pub source_tz: Option<Box<Expression>>,
11017    #[serde(default)]
11018    pub target_tz: Option<Box<Expression>>,
11019    #[serde(default)]
11020    pub timestamp: Option<Box<Expression>>,
11021    #[serde(default)]
11022    pub options: Vec<Expression>,
11023}
11024
11025/// GenerateSeries
11026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11027#[cfg_attr(feature = "bindings", derive(TS))]
11028pub struct GenerateSeries {
11029    #[serde(default)]
11030    pub start: Option<Box<Expression>>,
11031    #[serde(default)]
11032    pub end: Option<Box<Expression>>,
11033    #[serde(default)]
11034    pub step: Option<Box<Expression>>,
11035    #[serde(default)]
11036    pub is_end_exclusive: Option<Box<Expression>>,
11037}
11038
11039/// AIAgg
11040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11041#[cfg_attr(feature = "bindings", derive(TS))]
11042pub struct AIAgg {
11043    pub this: Box<Expression>,
11044    pub expression: Box<Expression>,
11045}
11046
11047/// AIClassify
11048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11049#[cfg_attr(feature = "bindings", derive(TS))]
11050pub struct AIClassify {
11051    pub this: Box<Expression>,
11052    #[serde(default)]
11053    pub categories: Option<Box<Expression>>,
11054    #[serde(default)]
11055    pub config: Option<Box<Expression>>,
11056}
11057
11058/// ArrayAll
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct ArrayAll {
11062    pub this: Box<Expression>,
11063    pub expression: Box<Expression>,
11064}
11065
11066/// ArrayAny
11067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11068#[cfg_attr(feature = "bindings", derive(TS))]
11069pub struct ArrayAny {
11070    pub this: Box<Expression>,
11071    pub expression: Box<Expression>,
11072}
11073
11074/// ArrayConstructCompact
11075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11076#[cfg_attr(feature = "bindings", derive(TS))]
11077pub struct ArrayConstructCompact {
11078    #[serde(default)]
11079    pub expressions: Vec<Expression>,
11080}
11081
11082/// StPoint
11083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11084#[cfg_attr(feature = "bindings", derive(TS))]
11085pub struct StPoint {
11086    pub this: Box<Expression>,
11087    pub expression: Box<Expression>,
11088    #[serde(default)]
11089    pub null: Option<Box<Expression>>,
11090}
11091
11092/// StDistance
11093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11094#[cfg_attr(feature = "bindings", derive(TS))]
11095pub struct StDistance {
11096    pub this: Box<Expression>,
11097    pub expression: Box<Expression>,
11098    #[serde(default)]
11099    pub use_spheroid: Option<Box<Expression>>,
11100}
11101
11102/// StringToArray
11103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11104#[cfg_attr(feature = "bindings", derive(TS))]
11105pub struct StringToArray {
11106    pub this: Box<Expression>,
11107    #[serde(default)]
11108    pub expression: Option<Box<Expression>>,
11109    #[serde(default)]
11110    pub null: Option<Box<Expression>>,
11111}
11112
11113/// ArraySum
11114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11115#[cfg_attr(feature = "bindings", derive(TS))]
11116pub struct ArraySum {
11117    pub this: Box<Expression>,
11118    #[serde(default)]
11119    pub expression: Option<Box<Expression>>,
11120}
11121
11122/// ObjectAgg
11123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11124#[cfg_attr(feature = "bindings", derive(TS))]
11125pub struct ObjectAgg {
11126    pub this: Box<Expression>,
11127    pub expression: Box<Expression>,
11128}
11129
11130/// CastToStrType
11131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11132#[cfg_attr(feature = "bindings", derive(TS))]
11133pub struct CastToStrType {
11134    pub this: Box<Expression>,
11135    #[serde(default)]
11136    pub to: Option<Box<Expression>>,
11137}
11138
11139/// CheckJson
11140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11141#[cfg_attr(feature = "bindings", derive(TS))]
11142pub struct CheckJson {
11143    pub this: Box<Expression>,
11144}
11145
11146/// CheckXml
11147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11148#[cfg_attr(feature = "bindings", derive(TS))]
11149pub struct CheckXml {
11150    pub this: Box<Expression>,
11151    #[serde(default)]
11152    pub disable_auto_convert: Option<Box<Expression>>,
11153}
11154
11155/// TranslateCharacters
11156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11157#[cfg_attr(feature = "bindings", derive(TS))]
11158pub struct TranslateCharacters {
11159    pub this: Box<Expression>,
11160    pub expression: Box<Expression>,
11161    #[serde(default)]
11162    pub with_error: Option<Box<Expression>>,
11163}
11164
11165/// CurrentSchemas
11166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11167#[cfg_attr(feature = "bindings", derive(TS))]
11168pub struct CurrentSchemas {
11169    #[serde(default)]
11170    pub this: Option<Box<Expression>>,
11171}
11172
11173/// CurrentDatetime
11174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11175#[cfg_attr(feature = "bindings", derive(TS))]
11176pub struct CurrentDatetime {
11177    #[serde(default)]
11178    pub this: Option<Box<Expression>>,
11179}
11180
11181/// Localtime
11182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11183#[cfg_attr(feature = "bindings", derive(TS))]
11184pub struct Localtime {
11185    #[serde(default)]
11186    pub this: Option<Box<Expression>>,
11187}
11188
11189/// Localtimestamp
11190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11191#[cfg_attr(feature = "bindings", derive(TS))]
11192pub struct Localtimestamp {
11193    #[serde(default)]
11194    pub this: Option<Box<Expression>>,
11195}
11196
11197/// Systimestamp
11198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11199#[cfg_attr(feature = "bindings", derive(TS))]
11200pub struct Systimestamp {
11201    #[serde(default)]
11202    pub this: Option<Box<Expression>>,
11203}
11204
11205/// CurrentSchema
11206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11207#[cfg_attr(feature = "bindings", derive(TS))]
11208pub struct CurrentSchema {
11209    #[serde(default)]
11210    pub this: Option<Box<Expression>>,
11211}
11212
11213/// CurrentUser
11214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11215#[cfg_attr(feature = "bindings", derive(TS))]
11216pub struct CurrentUser {
11217    #[serde(default)]
11218    pub this: Option<Box<Expression>>,
11219}
11220
11221/// SessionUser - MySQL/PostgreSQL SESSION_USER function
11222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11223#[cfg_attr(feature = "bindings", derive(TS))]
11224pub struct SessionUser;
11225
11226/// JSONPathRoot - Represents $ in JSON path expressions
11227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11228#[cfg_attr(feature = "bindings", derive(TS))]
11229pub struct JSONPathRoot;
11230
11231/// UtcTime
11232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11233#[cfg_attr(feature = "bindings", derive(TS))]
11234pub struct UtcTime {
11235    #[serde(default)]
11236    pub this: Option<Box<Expression>>,
11237}
11238
11239/// UtcTimestamp
11240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11241#[cfg_attr(feature = "bindings", derive(TS))]
11242pub struct UtcTimestamp {
11243    #[serde(default)]
11244    pub this: Option<Box<Expression>>,
11245}
11246
11247/// TimestampFunc - TIMESTAMP constructor function
11248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11249#[cfg_attr(feature = "bindings", derive(TS))]
11250pub struct TimestampFunc {
11251    #[serde(default)]
11252    pub this: Option<Box<Expression>>,
11253    #[serde(default)]
11254    pub zone: Option<Box<Expression>>,
11255    #[serde(default)]
11256    pub with_tz: Option<bool>,
11257    #[serde(default)]
11258    pub safe: Option<bool>,
11259}
11260
11261/// DateBin
11262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11263#[cfg_attr(feature = "bindings", derive(TS))]
11264pub struct DateBin {
11265    pub this: Box<Expression>,
11266    pub expression: Box<Expression>,
11267    #[serde(default)]
11268    pub unit: Option<String>,
11269    #[serde(default)]
11270    pub zone: Option<Box<Expression>>,
11271    #[serde(default)]
11272    pub origin: Option<Box<Expression>>,
11273}
11274
11275/// Datetime
11276#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11277#[cfg_attr(feature = "bindings", derive(TS))]
11278pub struct Datetime {
11279    pub this: Box<Expression>,
11280    #[serde(default)]
11281    pub expression: Option<Box<Expression>>,
11282}
11283
11284/// DatetimeAdd
11285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11286#[cfg_attr(feature = "bindings", derive(TS))]
11287pub struct DatetimeAdd {
11288    pub this: Box<Expression>,
11289    pub expression: Box<Expression>,
11290    #[serde(default)]
11291    pub unit: Option<String>,
11292}
11293
11294/// DatetimeSub
11295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11296#[cfg_attr(feature = "bindings", derive(TS))]
11297pub struct DatetimeSub {
11298    pub this: Box<Expression>,
11299    pub expression: Box<Expression>,
11300    #[serde(default)]
11301    pub unit: Option<String>,
11302}
11303
11304/// DatetimeDiff
11305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11306#[cfg_attr(feature = "bindings", derive(TS))]
11307pub struct DatetimeDiff {
11308    pub this: Box<Expression>,
11309    pub expression: Box<Expression>,
11310    #[serde(default)]
11311    pub unit: Option<String>,
11312}
11313
11314/// DatetimeTrunc
11315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11316#[cfg_attr(feature = "bindings", derive(TS))]
11317pub struct DatetimeTrunc {
11318    pub this: Box<Expression>,
11319    pub unit: String,
11320    #[serde(default)]
11321    pub zone: Option<Box<Expression>>,
11322}
11323
11324/// Dayname
11325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11326#[cfg_attr(feature = "bindings", derive(TS))]
11327pub struct Dayname {
11328    pub this: Box<Expression>,
11329    #[serde(default)]
11330    pub abbreviated: Option<Box<Expression>>,
11331}
11332
11333/// MakeInterval
11334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11335#[cfg_attr(feature = "bindings", derive(TS))]
11336pub struct MakeInterval {
11337    #[serde(default)]
11338    pub year: Option<Box<Expression>>,
11339    #[serde(default)]
11340    pub month: Option<Box<Expression>>,
11341    #[serde(default)]
11342    pub week: Option<Box<Expression>>,
11343    #[serde(default)]
11344    pub day: Option<Box<Expression>>,
11345    #[serde(default)]
11346    pub hour: Option<Box<Expression>>,
11347    #[serde(default)]
11348    pub minute: Option<Box<Expression>>,
11349    #[serde(default)]
11350    pub second: Option<Box<Expression>>,
11351}
11352
11353/// PreviousDay
11354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11355#[cfg_attr(feature = "bindings", derive(TS))]
11356pub struct PreviousDay {
11357    pub this: Box<Expression>,
11358    pub expression: Box<Expression>,
11359}
11360
11361/// Elt
11362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11363#[cfg_attr(feature = "bindings", derive(TS))]
11364pub struct Elt {
11365    pub this: Box<Expression>,
11366    #[serde(default)]
11367    pub expressions: Vec<Expression>,
11368}
11369
11370/// TimestampAdd
11371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11372#[cfg_attr(feature = "bindings", derive(TS))]
11373pub struct TimestampAdd {
11374    pub this: Box<Expression>,
11375    pub expression: Box<Expression>,
11376    #[serde(default)]
11377    pub unit: Option<String>,
11378}
11379
11380/// TimestampSub
11381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11382#[cfg_attr(feature = "bindings", derive(TS))]
11383pub struct TimestampSub {
11384    pub this: Box<Expression>,
11385    pub expression: Box<Expression>,
11386    #[serde(default)]
11387    pub unit: Option<String>,
11388}
11389
11390/// TimestampDiff
11391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11392#[cfg_attr(feature = "bindings", derive(TS))]
11393pub struct TimestampDiff {
11394    pub this: Box<Expression>,
11395    pub expression: Box<Expression>,
11396    #[serde(default)]
11397    pub unit: Option<String>,
11398}
11399
11400/// TimeSlice
11401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11402#[cfg_attr(feature = "bindings", derive(TS))]
11403pub struct TimeSlice {
11404    pub this: Box<Expression>,
11405    pub expression: Box<Expression>,
11406    pub unit: String,
11407    #[serde(default)]
11408    pub kind: Option<String>,
11409}
11410
11411/// TimeAdd
11412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11413#[cfg_attr(feature = "bindings", derive(TS))]
11414pub struct TimeAdd {
11415    pub this: Box<Expression>,
11416    pub expression: Box<Expression>,
11417    #[serde(default)]
11418    pub unit: Option<String>,
11419}
11420
11421/// TimeSub
11422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11423#[cfg_attr(feature = "bindings", derive(TS))]
11424pub struct TimeSub {
11425    pub this: Box<Expression>,
11426    pub expression: Box<Expression>,
11427    #[serde(default)]
11428    pub unit: Option<String>,
11429}
11430
11431/// TimeDiff
11432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11433#[cfg_attr(feature = "bindings", derive(TS))]
11434pub struct TimeDiff {
11435    pub this: Box<Expression>,
11436    pub expression: Box<Expression>,
11437    #[serde(default)]
11438    pub unit: Option<String>,
11439}
11440
11441/// TimeTrunc
11442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11443#[cfg_attr(feature = "bindings", derive(TS))]
11444pub struct TimeTrunc {
11445    pub this: Box<Expression>,
11446    pub unit: String,
11447    #[serde(default)]
11448    pub zone: Option<Box<Expression>>,
11449}
11450
11451/// DateFromParts
11452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11453#[cfg_attr(feature = "bindings", derive(TS))]
11454pub struct DateFromParts {
11455    #[serde(default)]
11456    pub year: Option<Box<Expression>>,
11457    #[serde(default)]
11458    pub month: Option<Box<Expression>>,
11459    #[serde(default)]
11460    pub day: Option<Box<Expression>>,
11461    #[serde(default)]
11462    pub allow_overflow: Option<Box<Expression>>,
11463}
11464
11465/// TimeFromParts
11466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11467#[cfg_attr(feature = "bindings", derive(TS))]
11468pub struct TimeFromParts {
11469    #[serde(default)]
11470    pub hour: Option<Box<Expression>>,
11471    #[serde(default)]
11472    pub min: Option<Box<Expression>>,
11473    #[serde(default)]
11474    pub sec: Option<Box<Expression>>,
11475    #[serde(default)]
11476    pub nano: Option<Box<Expression>>,
11477    #[serde(default)]
11478    pub fractions: Option<Box<Expression>>,
11479    #[serde(default)]
11480    pub precision: Option<i64>,
11481}
11482
11483/// DecodeCase
11484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11485#[cfg_attr(feature = "bindings", derive(TS))]
11486pub struct DecodeCase {
11487    #[serde(default)]
11488    pub expressions: Vec<Expression>,
11489}
11490
11491/// Decrypt
11492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11493#[cfg_attr(feature = "bindings", derive(TS))]
11494pub struct Decrypt {
11495    pub this: Box<Expression>,
11496    #[serde(default)]
11497    pub passphrase: Option<Box<Expression>>,
11498    #[serde(default)]
11499    pub aad: Option<Box<Expression>>,
11500    #[serde(default)]
11501    pub encryption_method: Option<Box<Expression>>,
11502    #[serde(default)]
11503    pub safe: Option<Box<Expression>>,
11504}
11505
11506/// DecryptRaw
11507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11508#[cfg_attr(feature = "bindings", derive(TS))]
11509pub struct DecryptRaw {
11510    pub this: Box<Expression>,
11511    #[serde(default)]
11512    pub key: Option<Box<Expression>>,
11513    #[serde(default)]
11514    pub iv: Option<Box<Expression>>,
11515    #[serde(default)]
11516    pub aad: Option<Box<Expression>>,
11517    #[serde(default)]
11518    pub encryption_method: Option<Box<Expression>>,
11519    #[serde(default)]
11520    pub aead: Option<Box<Expression>>,
11521    #[serde(default)]
11522    pub safe: Option<Box<Expression>>,
11523}
11524
11525/// Encode
11526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11527#[cfg_attr(feature = "bindings", derive(TS))]
11528pub struct Encode {
11529    pub this: Box<Expression>,
11530    #[serde(default)]
11531    pub charset: Option<Box<Expression>>,
11532}
11533
11534/// Encrypt
11535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11536#[cfg_attr(feature = "bindings", derive(TS))]
11537pub struct Encrypt {
11538    pub this: Box<Expression>,
11539    #[serde(default)]
11540    pub passphrase: Option<Box<Expression>>,
11541    #[serde(default)]
11542    pub aad: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub encryption_method: Option<Box<Expression>>,
11545}
11546
11547/// EncryptRaw
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct EncryptRaw {
11551    pub this: Box<Expression>,
11552    #[serde(default)]
11553    pub key: Option<Box<Expression>>,
11554    #[serde(default)]
11555    pub iv: Option<Box<Expression>>,
11556    #[serde(default)]
11557    pub aad: Option<Box<Expression>>,
11558    #[serde(default)]
11559    pub encryption_method: Option<Box<Expression>>,
11560}
11561
11562/// EqualNull
11563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11564#[cfg_attr(feature = "bindings", derive(TS))]
11565pub struct EqualNull {
11566    pub this: Box<Expression>,
11567    pub expression: Box<Expression>,
11568}
11569
11570/// ToBinary
11571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11572#[cfg_attr(feature = "bindings", derive(TS))]
11573pub struct ToBinary {
11574    pub this: Box<Expression>,
11575    #[serde(default)]
11576    pub format: Option<String>,
11577    #[serde(default)]
11578    pub safe: Option<Box<Expression>>,
11579}
11580
11581/// Base64DecodeBinary
11582#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11583#[cfg_attr(feature = "bindings", derive(TS))]
11584pub struct Base64DecodeBinary {
11585    pub this: Box<Expression>,
11586    #[serde(default)]
11587    pub alphabet: Option<Box<Expression>>,
11588}
11589
11590/// Base64DecodeString
11591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11592#[cfg_attr(feature = "bindings", derive(TS))]
11593pub struct Base64DecodeString {
11594    pub this: Box<Expression>,
11595    #[serde(default)]
11596    pub alphabet: Option<Box<Expression>>,
11597}
11598
11599/// Base64Encode
11600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11601#[cfg_attr(feature = "bindings", derive(TS))]
11602pub struct Base64Encode {
11603    pub this: Box<Expression>,
11604    #[serde(default)]
11605    pub max_line_length: Option<Box<Expression>>,
11606    #[serde(default)]
11607    pub alphabet: Option<Box<Expression>>,
11608}
11609
11610/// TryBase64DecodeBinary
11611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11612#[cfg_attr(feature = "bindings", derive(TS))]
11613pub struct TryBase64DecodeBinary {
11614    pub this: Box<Expression>,
11615    #[serde(default)]
11616    pub alphabet: Option<Box<Expression>>,
11617}
11618
11619/// TryBase64DecodeString
11620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11621#[cfg_attr(feature = "bindings", derive(TS))]
11622pub struct TryBase64DecodeString {
11623    pub this: Box<Expression>,
11624    #[serde(default)]
11625    pub alphabet: Option<Box<Expression>>,
11626}
11627
11628/// GapFill
11629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11630#[cfg_attr(feature = "bindings", derive(TS))]
11631pub struct GapFill {
11632    pub this: Box<Expression>,
11633    #[serde(default)]
11634    pub ts_column: Option<Box<Expression>>,
11635    #[serde(default)]
11636    pub bucket_width: Option<Box<Expression>>,
11637    #[serde(default)]
11638    pub partitioning_columns: Option<Box<Expression>>,
11639    #[serde(default)]
11640    pub value_columns: Option<Box<Expression>>,
11641    #[serde(default)]
11642    pub origin: Option<Box<Expression>>,
11643    #[serde(default)]
11644    pub ignore_nulls: Option<Box<Expression>>,
11645}
11646
11647/// GenerateDateArray
11648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11649#[cfg_attr(feature = "bindings", derive(TS))]
11650pub struct GenerateDateArray {
11651    #[serde(default)]
11652    pub start: Option<Box<Expression>>,
11653    #[serde(default)]
11654    pub end: Option<Box<Expression>>,
11655    #[serde(default)]
11656    pub step: Option<Box<Expression>>,
11657}
11658
11659/// GenerateTimestampArray
11660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11661#[cfg_attr(feature = "bindings", derive(TS))]
11662pub struct GenerateTimestampArray {
11663    #[serde(default)]
11664    pub start: Option<Box<Expression>>,
11665    #[serde(default)]
11666    pub end: Option<Box<Expression>>,
11667    #[serde(default)]
11668    pub step: Option<Box<Expression>>,
11669}
11670
11671/// GetExtract
11672#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11673#[cfg_attr(feature = "bindings", derive(TS))]
11674pub struct GetExtract {
11675    pub this: Box<Expression>,
11676    pub expression: Box<Expression>,
11677}
11678
11679/// Getbit
11680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11681#[cfg_attr(feature = "bindings", derive(TS))]
11682pub struct Getbit {
11683    pub this: Box<Expression>,
11684    pub expression: Box<Expression>,
11685    #[serde(default)]
11686    pub zero_is_msb: Option<Box<Expression>>,
11687}
11688
11689/// OverflowTruncateBehavior
11690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11691#[cfg_attr(feature = "bindings", derive(TS))]
11692pub struct OverflowTruncateBehavior {
11693    #[serde(default)]
11694    pub this: Option<Box<Expression>>,
11695    #[serde(default)]
11696    pub with_count: Option<Box<Expression>>,
11697}
11698
11699/// HexEncode
11700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11701#[cfg_attr(feature = "bindings", derive(TS))]
11702pub struct HexEncode {
11703    pub this: Box<Expression>,
11704    #[serde(default)]
11705    pub case: Option<Box<Expression>>,
11706}
11707
11708/// Compress
11709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11710#[cfg_attr(feature = "bindings", derive(TS))]
11711pub struct Compress {
11712    pub this: Box<Expression>,
11713    #[serde(default)]
11714    pub method: Option<String>,
11715}
11716
11717/// DecompressBinary
11718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11719#[cfg_attr(feature = "bindings", derive(TS))]
11720pub struct DecompressBinary {
11721    pub this: Box<Expression>,
11722    pub method: String,
11723}
11724
11725/// DecompressString
11726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11727#[cfg_attr(feature = "bindings", derive(TS))]
11728pub struct DecompressString {
11729    pub this: Box<Expression>,
11730    pub method: String,
11731}
11732
11733/// Xor
11734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11735#[cfg_attr(feature = "bindings", derive(TS))]
11736pub struct Xor {
11737    #[serde(default)]
11738    pub this: Option<Box<Expression>>,
11739    #[serde(default)]
11740    pub expression: Option<Box<Expression>>,
11741    #[serde(default)]
11742    pub expressions: Vec<Expression>,
11743}
11744
11745/// Nullif
11746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11747#[cfg_attr(feature = "bindings", derive(TS))]
11748pub struct Nullif {
11749    pub this: Box<Expression>,
11750    pub expression: Box<Expression>,
11751}
11752
11753/// JSON
11754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11755#[cfg_attr(feature = "bindings", derive(TS))]
11756pub struct JSON {
11757    #[serde(default)]
11758    pub this: Option<Box<Expression>>,
11759    #[serde(default)]
11760    pub with_: Option<Box<Expression>>,
11761    #[serde(default)]
11762    pub unique: bool,
11763}
11764
11765/// JSONPath
11766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11767#[cfg_attr(feature = "bindings", derive(TS))]
11768pub struct JSONPath {
11769    #[serde(default)]
11770    pub expressions: Vec<Expression>,
11771    #[serde(default)]
11772    pub escape: Option<Box<Expression>>,
11773}
11774
11775/// JSONPathFilter
11776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11777#[cfg_attr(feature = "bindings", derive(TS))]
11778pub struct JSONPathFilter {
11779    pub this: Box<Expression>,
11780}
11781
11782/// JSONPathKey
11783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11784#[cfg_attr(feature = "bindings", derive(TS))]
11785pub struct JSONPathKey {
11786    pub this: Box<Expression>,
11787}
11788
11789/// JSONPathRecursive
11790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11791#[cfg_attr(feature = "bindings", derive(TS))]
11792pub struct JSONPathRecursive {
11793    #[serde(default)]
11794    pub this: Option<Box<Expression>>,
11795}
11796
11797/// JSONPathScript
11798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11799#[cfg_attr(feature = "bindings", derive(TS))]
11800pub struct JSONPathScript {
11801    pub this: Box<Expression>,
11802}
11803
11804/// JSONPathSlice
11805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11806#[cfg_attr(feature = "bindings", derive(TS))]
11807pub struct JSONPathSlice {
11808    #[serde(default)]
11809    pub start: Option<Box<Expression>>,
11810    #[serde(default)]
11811    pub end: Option<Box<Expression>>,
11812    #[serde(default)]
11813    pub step: Option<Box<Expression>>,
11814}
11815
11816/// JSONPathSelector
11817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11818#[cfg_attr(feature = "bindings", derive(TS))]
11819pub struct JSONPathSelector {
11820    pub this: Box<Expression>,
11821}
11822
11823/// JSONPathSubscript
11824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11825#[cfg_attr(feature = "bindings", derive(TS))]
11826pub struct JSONPathSubscript {
11827    pub this: Box<Expression>,
11828}
11829
11830/// JSONPathUnion
11831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11832#[cfg_attr(feature = "bindings", derive(TS))]
11833pub struct JSONPathUnion {
11834    #[serde(default)]
11835    pub expressions: Vec<Expression>,
11836}
11837
11838/// Format
11839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11840#[cfg_attr(feature = "bindings", derive(TS))]
11841pub struct Format {
11842    pub this: Box<Expression>,
11843    #[serde(default)]
11844    pub expressions: Vec<Expression>,
11845}
11846
11847/// JSONKeys
11848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11849#[cfg_attr(feature = "bindings", derive(TS))]
11850pub struct JSONKeys {
11851    pub this: Box<Expression>,
11852    #[serde(default)]
11853    pub expression: Option<Box<Expression>>,
11854    #[serde(default)]
11855    pub expressions: Vec<Expression>,
11856}
11857
11858/// JSONKeyValue
11859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11860#[cfg_attr(feature = "bindings", derive(TS))]
11861pub struct JSONKeyValue {
11862    pub this: Box<Expression>,
11863    pub expression: Box<Expression>,
11864}
11865
11866/// JSONKeysAtDepth
11867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11868#[cfg_attr(feature = "bindings", derive(TS))]
11869pub struct JSONKeysAtDepth {
11870    pub this: Box<Expression>,
11871    #[serde(default)]
11872    pub expression: Option<Box<Expression>>,
11873    #[serde(default)]
11874    pub mode: Option<Box<Expression>>,
11875}
11876
11877/// JSONObject
11878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11879#[cfg_attr(feature = "bindings", derive(TS))]
11880pub struct JSONObject {
11881    #[serde(default)]
11882    pub expressions: Vec<Expression>,
11883    #[serde(default)]
11884    pub null_handling: Option<Box<Expression>>,
11885    #[serde(default)]
11886    pub unique_keys: Option<Box<Expression>>,
11887    #[serde(default)]
11888    pub return_type: Option<Box<Expression>>,
11889    #[serde(default)]
11890    pub encoding: Option<Box<Expression>>,
11891}
11892
11893/// JSONObjectAgg
11894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11895#[cfg_attr(feature = "bindings", derive(TS))]
11896pub struct JSONObjectAgg {
11897    #[serde(default)]
11898    pub expressions: Vec<Expression>,
11899    #[serde(default)]
11900    pub null_handling: Option<Box<Expression>>,
11901    #[serde(default)]
11902    pub unique_keys: Option<Box<Expression>>,
11903    #[serde(default)]
11904    pub return_type: Option<Box<Expression>>,
11905    #[serde(default)]
11906    pub encoding: Option<Box<Expression>>,
11907}
11908
11909/// JSONBObjectAgg
11910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11911#[cfg_attr(feature = "bindings", derive(TS))]
11912pub struct JSONBObjectAgg {
11913    pub this: Box<Expression>,
11914    pub expression: Box<Expression>,
11915}
11916
11917/// JSONArray
11918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11919#[cfg_attr(feature = "bindings", derive(TS))]
11920pub struct JSONArray {
11921    #[serde(default)]
11922    pub expressions: Vec<Expression>,
11923    #[serde(default)]
11924    pub null_handling: Option<Box<Expression>>,
11925    #[serde(default)]
11926    pub return_type: Option<Box<Expression>>,
11927    #[serde(default)]
11928    pub strict: Option<Box<Expression>>,
11929}
11930
11931/// JSONArrayAgg
11932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11933#[cfg_attr(feature = "bindings", derive(TS))]
11934pub struct JSONArrayAgg {
11935    pub this: Box<Expression>,
11936    #[serde(default)]
11937    pub order: Option<Box<Expression>>,
11938    #[serde(default)]
11939    pub null_handling: Option<Box<Expression>>,
11940    #[serde(default)]
11941    pub return_type: Option<Box<Expression>>,
11942    #[serde(default)]
11943    pub strict: Option<Box<Expression>>,
11944}
11945
11946/// JSONExists
11947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11948#[cfg_attr(feature = "bindings", derive(TS))]
11949pub struct JSONExists {
11950    pub this: Box<Expression>,
11951    #[serde(default)]
11952    pub path: Option<Box<Expression>>,
11953    #[serde(default)]
11954    pub passing: Option<Box<Expression>>,
11955    #[serde(default)]
11956    pub on_condition: Option<Box<Expression>>,
11957    #[serde(default)]
11958    pub from_dcolonqmark: Option<Box<Expression>>,
11959}
11960
11961/// JSONColumnDef
11962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11963#[cfg_attr(feature = "bindings", derive(TS))]
11964pub struct JSONColumnDef {
11965    #[serde(default)]
11966    pub this: Option<Box<Expression>>,
11967    #[serde(default)]
11968    pub kind: Option<String>,
11969    #[serde(default)]
11970    pub path: Option<Box<Expression>>,
11971    #[serde(default)]
11972    pub nested_schema: Option<Box<Expression>>,
11973    #[serde(default)]
11974    pub ordinality: Option<Box<Expression>>,
11975}
11976
11977/// JSONSchema
11978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11979#[cfg_attr(feature = "bindings", derive(TS))]
11980pub struct JSONSchema {
11981    #[serde(default)]
11982    pub expressions: Vec<Expression>,
11983}
11984
11985/// JSONSet
11986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11987#[cfg_attr(feature = "bindings", derive(TS))]
11988pub struct JSONSet {
11989    pub this: Box<Expression>,
11990    #[serde(default)]
11991    pub expressions: Vec<Expression>,
11992}
11993
11994/// JSONStripNulls
11995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11996#[cfg_attr(feature = "bindings", derive(TS))]
11997pub struct JSONStripNulls {
11998    pub this: Box<Expression>,
11999    #[serde(default)]
12000    pub expression: Option<Box<Expression>>,
12001    #[serde(default)]
12002    pub include_arrays: Option<Box<Expression>>,
12003    #[serde(default)]
12004    pub remove_empty: Option<Box<Expression>>,
12005}
12006
12007/// JSONValue
12008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12009#[cfg_attr(feature = "bindings", derive(TS))]
12010pub struct JSONValue {
12011    pub this: Box<Expression>,
12012    #[serde(default)]
12013    pub path: Option<Box<Expression>>,
12014    #[serde(default)]
12015    pub returning: Option<Box<Expression>>,
12016    #[serde(default)]
12017    pub on_condition: Option<Box<Expression>>,
12018}
12019
12020/// JSONValueArray
12021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12022#[cfg_attr(feature = "bindings", derive(TS))]
12023pub struct JSONValueArray {
12024    pub this: Box<Expression>,
12025    #[serde(default)]
12026    pub expression: Option<Box<Expression>>,
12027}
12028
12029/// JSONRemove
12030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12031#[cfg_attr(feature = "bindings", derive(TS))]
12032pub struct JSONRemove {
12033    pub this: Box<Expression>,
12034    #[serde(default)]
12035    pub expressions: Vec<Expression>,
12036}
12037
12038/// JSONTable
12039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12040#[cfg_attr(feature = "bindings", derive(TS))]
12041pub struct JSONTable {
12042    pub this: Box<Expression>,
12043    #[serde(default)]
12044    pub schema: Option<Box<Expression>>,
12045    #[serde(default)]
12046    pub path: Option<Box<Expression>>,
12047    #[serde(default)]
12048    pub error_handling: Option<Box<Expression>>,
12049    #[serde(default)]
12050    pub empty_handling: Option<Box<Expression>>,
12051}
12052
12053/// JSONType
12054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12055#[cfg_attr(feature = "bindings", derive(TS))]
12056pub struct JSONType {
12057    pub this: Box<Expression>,
12058    #[serde(default)]
12059    pub expression: Option<Box<Expression>>,
12060}
12061
12062/// ObjectInsert
12063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12064#[cfg_attr(feature = "bindings", derive(TS))]
12065pub struct ObjectInsert {
12066    pub this: Box<Expression>,
12067    #[serde(default)]
12068    pub key: Option<Box<Expression>>,
12069    #[serde(default)]
12070    pub value: Option<Box<Expression>>,
12071    #[serde(default)]
12072    pub update_flag: Option<Box<Expression>>,
12073}
12074
12075/// OpenJSONColumnDef
12076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12077#[cfg_attr(feature = "bindings", derive(TS))]
12078pub struct OpenJSONColumnDef {
12079    pub this: Box<Expression>,
12080    pub kind: String,
12081    #[serde(default)]
12082    pub path: Option<Box<Expression>>,
12083    #[serde(default)]
12084    pub as_json: Option<Box<Expression>>,
12085    /// The parsed data type for proper generation
12086    #[serde(default, skip_serializing_if = "Option::is_none")]
12087    pub data_type: Option<DataType>,
12088}
12089
12090/// OpenJSON
12091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12092#[cfg_attr(feature = "bindings", derive(TS))]
12093pub struct OpenJSON {
12094    pub this: Box<Expression>,
12095    #[serde(default)]
12096    pub path: Option<Box<Expression>>,
12097    #[serde(default)]
12098    pub expressions: Vec<Expression>,
12099}
12100
12101/// JSONBExists
12102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12103#[cfg_attr(feature = "bindings", derive(TS))]
12104pub struct JSONBExists {
12105    pub this: Box<Expression>,
12106    #[serde(default)]
12107    pub path: Option<Box<Expression>>,
12108}
12109
12110/// JSONCast
12111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12112#[cfg_attr(feature = "bindings", derive(TS))]
12113pub struct JSONCast {
12114    pub this: Box<Expression>,
12115    pub to: DataType,
12116}
12117
12118/// JSONExtract
12119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12120#[cfg_attr(feature = "bindings", derive(TS))]
12121pub struct JSONExtract {
12122    pub this: Box<Expression>,
12123    pub expression: Box<Expression>,
12124    #[serde(default)]
12125    pub only_json_types: Option<Box<Expression>>,
12126    #[serde(default)]
12127    pub expressions: Vec<Expression>,
12128    #[serde(default)]
12129    pub variant_extract: Option<Box<Expression>>,
12130    #[serde(default)]
12131    pub json_query: Option<Box<Expression>>,
12132    #[serde(default)]
12133    pub option: Option<Box<Expression>>,
12134    #[serde(default)]
12135    pub quote: Option<Box<Expression>>,
12136    #[serde(default)]
12137    pub on_condition: Option<Box<Expression>>,
12138    #[serde(default)]
12139    pub requires_json: Option<Box<Expression>>,
12140}
12141
12142/// JSONExtractQuote
12143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12144#[cfg_attr(feature = "bindings", derive(TS))]
12145pub struct JSONExtractQuote {
12146    #[serde(default)]
12147    pub option: Option<Box<Expression>>,
12148    #[serde(default)]
12149    pub scalar: Option<Box<Expression>>,
12150}
12151
12152/// JSONExtractArray
12153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12154#[cfg_attr(feature = "bindings", derive(TS))]
12155pub struct JSONExtractArray {
12156    pub this: Box<Expression>,
12157    #[serde(default)]
12158    pub expression: Option<Box<Expression>>,
12159}
12160
12161/// JSONExtractScalar
12162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12163#[cfg_attr(feature = "bindings", derive(TS))]
12164pub struct JSONExtractScalar {
12165    pub this: Box<Expression>,
12166    pub expression: Box<Expression>,
12167    #[serde(default)]
12168    pub only_json_types: Option<Box<Expression>>,
12169    #[serde(default)]
12170    pub expressions: Vec<Expression>,
12171    #[serde(default)]
12172    pub json_type: Option<Box<Expression>>,
12173    #[serde(default)]
12174    pub scalar_only: Option<Box<Expression>>,
12175}
12176
12177/// JSONBExtractScalar
12178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12179#[cfg_attr(feature = "bindings", derive(TS))]
12180pub struct JSONBExtractScalar {
12181    pub this: Box<Expression>,
12182    pub expression: Box<Expression>,
12183    #[serde(default)]
12184    pub json_type: Option<Box<Expression>>,
12185}
12186
12187/// JSONFormat
12188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12189#[cfg_attr(feature = "bindings", derive(TS))]
12190pub struct JSONFormat {
12191    #[serde(default)]
12192    pub this: Option<Box<Expression>>,
12193    #[serde(default)]
12194    pub options: Vec<Expression>,
12195    #[serde(default)]
12196    pub is_json: Option<Box<Expression>>,
12197    #[serde(default)]
12198    pub to_json: Option<Box<Expression>>,
12199}
12200
12201/// JSONArrayAppend
12202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12203#[cfg_attr(feature = "bindings", derive(TS))]
12204pub struct JSONArrayAppend {
12205    pub this: Box<Expression>,
12206    #[serde(default)]
12207    pub expressions: Vec<Expression>,
12208}
12209
12210/// JSONArrayContains
12211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12212#[cfg_attr(feature = "bindings", derive(TS))]
12213pub struct JSONArrayContains {
12214    pub this: Box<Expression>,
12215    pub expression: Box<Expression>,
12216    #[serde(default)]
12217    pub json_type: Option<Box<Expression>>,
12218}
12219
12220/// JSONArrayInsert
12221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12222#[cfg_attr(feature = "bindings", derive(TS))]
12223pub struct JSONArrayInsert {
12224    pub this: Box<Expression>,
12225    #[serde(default)]
12226    pub expressions: Vec<Expression>,
12227}
12228
12229/// ParseJSON
12230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12231#[cfg_attr(feature = "bindings", derive(TS))]
12232pub struct ParseJSON {
12233    pub this: Box<Expression>,
12234    #[serde(default)]
12235    pub expression: Option<Box<Expression>>,
12236    #[serde(default)]
12237    pub safe: Option<Box<Expression>>,
12238}
12239
12240/// ParseUrl
12241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12242#[cfg_attr(feature = "bindings", derive(TS))]
12243pub struct ParseUrl {
12244    pub this: Box<Expression>,
12245    #[serde(default)]
12246    pub part_to_extract: Option<Box<Expression>>,
12247    #[serde(default)]
12248    pub key: Option<Box<Expression>>,
12249    #[serde(default)]
12250    pub permissive: Option<Box<Expression>>,
12251}
12252
12253/// ParseIp
12254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12255#[cfg_attr(feature = "bindings", derive(TS))]
12256pub struct ParseIp {
12257    pub this: Box<Expression>,
12258    #[serde(default)]
12259    pub type_: Option<Box<Expression>>,
12260    #[serde(default)]
12261    pub permissive: Option<Box<Expression>>,
12262}
12263
12264/// ParseTime
12265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12266#[cfg_attr(feature = "bindings", derive(TS))]
12267pub struct ParseTime {
12268    pub this: Box<Expression>,
12269    pub format: String,
12270}
12271
12272/// ParseDatetime
12273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12274#[cfg_attr(feature = "bindings", derive(TS))]
12275pub struct ParseDatetime {
12276    pub this: Box<Expression>,
12277    #[serde(default)]
12278    pub format: Option<String>,
12279    #[serde(default)]
12280    pub zone: Option<Box<Expression>>,
12281}
12282
12283/// Map
12284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12285#[cfg_attr(feature = "bindings", derive(TS))]
12286pub struct Map {
12287    #[serde(default)]
12288    pub keys: Vec<Expression>,
12289    #[serde(default)]
12290    pub values: Vec<Expression>,
12291}
12292
12293/// MapCat
12294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12295#[cfg_attr(feature = "bindings", derive(TS))]
12296pub struct MapCat {
12297    pub this: Box<Expression>,
12298    pub expression: Box<Expression>,
12299}
12300
12301/// MapDelete
12302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12303#[cfg_attr(feature = "bindings", derive(TS))]
12304pub struct MapDelete {
12305    pub this: Box<Expression>,
12306    #[serde(default)]
12307    pub expressions: Vec<Expression>,
12308}
12309
12310/// MapInsert
12311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12312#[cfg_attr(feature = "bindings", derive(TS))]
12313pub struct MapInsert {
12314    pub this: Box<Expression>,
12315    #[serde(default)]
12316    pub key: Option<Box<Expression>>,
12317    #[serde(default)]
12318    pub value: Option<Box<Expression>>,
12319    #[serde(default)]
12320    pub update_flag: Option<Box<Expression>>,
12321}
12322
12323/// MapPick
12324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12325#[cfg_attr(feature = "bindings", derive(TS))]
12326pub struct MapPick {
12327    pub this: Box<Expression>,
12328    #[serde(default)]
12329    pub expressions: Vec<Expression>,
12330}
12331
12332/// ScopeResolution
12333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12334#[cfg_attr(feature = "bindings", derive(TS))]
12335pub struct ScopeResolution {
12336    #[serde(default)]
12337    pub this: Option<Box<Expression>>,
12338    pub expression: Box<Expression>,
12339}
12340
12341/// Slice
12342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12343#[cfg_attr(feature = "bindings", derive(TS))]
12344pub struct Slice {
12345    #[serde(default)]
12346    pub this: Option<Box<Expression>>,
12347    #[serde(default)]
12348    pub expression: Option<Box<Expression>>,
12349    #[serde(default)]
12350    pub step: Option<Box<Expression>>,
12351}
12352
12353/// VarMap
12354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12355#[cfg_attr(feature = "bindings", derive(TS))]
12356pub struct VarMap {
12357    #[serde(default)]
12358    pub keys: Vec<Expression>,
12359    #[serde(default)]
12360    pub values: Vec<Expression>,
12361}
12362
12363/// MatchAgainst
12364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12365#[cfg_attr(feature = "bindings", derive(TS))]
12366pub struct MatchAgainst {
12367    pub this: Box<Expression>,
12368    #[serde(default)]
12369    pub expressions: Vec<Expression>,
12370    #[serde(default)]
12371    pub modifier: Option<Box<Expression>>,
12372}
12373
12374/// MD5Digest
12375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12376#[cfg_attr(feature = "bindings", derive(TS))]
12377pub struct MD5Digest {
12378    pub this: Box<Expression>,
12379    #[serde(default)]
12380    pub expressions: Vec<Expression>,
12381}
12382
12383/// Monthname
12384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12385#[cfg_attr(feature = "bindings", derive(TS))]
12386pub struct Monthname {
12387    pub this: Box<Expression>,
12388    #[serde(default)]
12389    pub abbreviated: Option<Box<Expression>>,
12390}
12391
12392/// Ntile
12393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12394#[cfg_attr(feature = "bindings", derive(TS))]
12395pub struct Ntile {
12396    #[serde(default)]
12397    pub this: Option<Box<Expression>>,
12398}
12399
12400/// Normalize
12401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12402#[cfg_attr(feature = "bindings", derive(TS))]
12403pub struct Normalize {
12404    pub this: Box<Expression>,
12405    #[serde(default)]
12406    pub form: Option<Box<Expression>>,
12407    #[serde(default)]
12408    pub is_casefold: Option<Box<Expression>>,
12409}
12410
12411/// Normal
12412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12413#[cfg_attr(feature = "bindings", derive(TS))]
12414pub struct Normal {
12415    pub this: Box<Expression>,
12416    #[serde(default)]
12417    pub stddev: Option<Box<Expression>>,
12418    #[serde(default)]
12419    pub gen: Option<Box<Expression>>,
12420}
12421
12422/// Predict
12423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12424#[cfg_attr(feature = "bindings", derive(TS))]
12425pub struct Predict {
12426    pub this: Box<Expression>,
12427    pub expression: Box<Expression>,
12428    #[serde(default)]
12429    pub params_struct: Option<Box<Expression>>,
12430}
12431
12432/// MLTranslate
12433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12434#[cfg_attr(feature = "bindings", derive(TS))]
12435pub struct MLTranslate {
12436    pub this: Box<Expression>,
12437    pub expression: Box<Expression>,
12438    #[serde(default)]
12439    pub params_struct: Option<Box<Expression>>,
12440}
12441
12442/// FeaturesAtTime
12443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12444#[cfg_attr(feature = "bindings", derive(TS))]
12445pub struct FeaturesAtTime {
12446    pub this: Box<Expression>,
12447    #[serde(default)]
12448    pub time: Option<Box<Expression>>,
12449    #[serde(default)]
12450    pub num_rows: Option<Box<Expression>>,
12451    #[serde(default)]
12452    pub ignore_feature_nulls: Option<Box<Expression>>,
12453}
12454
12455/// GenerateEmbedding
12456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12457#[cfg_attr(feature = "bindings", derive(TS))]
12458pub struct GenerateEmbedding {
12459    pub this: Box<Expression>,
12460    pub expression: Box<Expression>,
12461    #[serde(default)]
12462    pub params_struct: Option<Box<Expression>>,
12463    #[serde(default)]
12464    pub is_text: Option<Box<Expression>>,
12465}
12466
12467/// MLForecast
12468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12469#[cfg_attr(feature = "bindings", derive(TS))]
12470pub struct MLForecast {
12471    pub this: Box<Expression>,
12472    #[serde(default)]
12473    pub expression: Option<Box<Expression>>,
12474    #[serde(default)]
12475    pub params_struct: Option<Box<Expression>>,
12476}
12477
12478/// ModelAttribute
12479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12480#[cfg_attr(feature = "bindings", derive(TS))]
12481pub struct ModelAttribute {
12482    pub this: Box<Expression>,
12483    pub expression: Box<Expression>,
12484}
12485
12486/// VectorSearch
12487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12488#[cfg_attr(feature = "bindings", derive(TS))]
12489pub struct VectorSearch {
12490    pub this: Box<Expression>,
12491    #[serde(default)]
12492    pub column_to_search: Option<Box<Expression>>,
12493    #[serde(default)]
12494    pub query_table: Option<Box<Expression>>,
12495    #[serde(default)]
12496    pub query_column_to_search: Option<Box<Expression>>,
12497    #[serde(default)]
12498    pub top_k: Option<Box<Expression>>,
12499    #[serde(default)]
12500    pub distance_type: Option<Box<Expression>>,
12501    #[serde(default)]
12502    pub options: Vec<Expression>,
12503}
12504
12505/// Quantile
12506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12507#[cfg_attr(feature = "bindings", derive(TS))]
12508pub struct Quantile {
12509    pub this: Box<Expression>,
12510    #[serde(default)]
12511    pub quantile: Option<Box<Expression>>,
12512}
12513
12514/// ApproxQuantile
12515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12516#[cfg_attr(feature = "bindings", derive(TS))]
12517pub struct ApproxQuantile {
12518    pub this: Box<Expression>,
12519    #[serde(default)]
12520    pub quantile: Option<Box<Expression>>,
12521    #[serde(default)]
12522    pub accuracy: Option<Box<Expression>>,
12523    #[serde(default)]
12524    pub weight: Option<Box<Expression>>,
12525    #[serde(default)]
12526    pub error_tolerance: Option<Box<Expression>>,
12527}
12528
12529/// ApproxPercentileEstimate
12530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12531#[cfg_attr(feature = "bindings", derive(TS))]
12532pub struct ApproxPercentileEstimate {
12533    pub this: Box<Expression>,
12534    #[serde(default)]
12535    pub percentile: Option<Box<Expression>>,
12536}
12537
12538/// Randn
12539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12540#[cfg_attr(feature = "bindings", derive(TS))]
12541pub struct Randn {
12542    #[serde(default)]
12543    pub this: Option<Box<Expression>>,
12544}
12545
12546/// Randstr
12547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12548#[cfg_attr(feature = "bindings", derive(TS))]
12549pub struct Randstr {
12550    pub this: Box<Expression>,
12551    #[serde(default)]
12552    pub generator: Option<Box<Expression>>,
12553}
12554
12555/// RangeN
12556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12557#[cfg_attr(feature = "bindings", derive(TS))]
12558pub struct RangeN {
12559    pub this: Box<Expression>,
12560    #[serde(default)]
12561    pub expressions: Vec<Expression>,
12562    #[serde(default)]
12563    pub each: Option<Box<Expression>>,
12564}
12565
12566/// RangeBucket
12567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12568#[cfg_attr(feature = "bindings", derive(TS))]
12569pub struct RangeBucket {
12570    pub this: Box<Expression>,
12571    pub expression: Box<Expression>,
12572}
12573
12574/// ReadCSV
12575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12576#[cfg_attr(feature = "bindings", derive(TS))]
12577pub struct ReadCSV {
12578    pub this: Box<Expression>,
12579    #[serde(default)]
12580    pub expressions: Vec<Expression>,
12581}
12582
12583/// ReadParquet
12584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12585#[cfg_attr(feature = "bindings", derive(TS))]
12586pub struct ReadParquet {
12587    #[serde(default)]
12588    pub expressions: Vec<Expression>,
12589}
12590
12591/// Reduce
12592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12593#[cfg_attr(feature = "bindings", derive(TS))]
12594pub struct Reduce {
12595    pub this: Box<Expression>,
12596    #[serde(default)]
12597    pub initial: Option<Box<Expression>>,
12598    #[serde(default)]
12599    pub merge: Option<Box<Expression>>,
12600    #[serde(default)]
12601    pub finish: Option<Box<Expression>>,
12602}
12603
12604/// RegexpExtractAll
12605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12606#[cfg_attr(feature = "bindings", derive(TS))]
12607pub struct RegexpExtractAll {
12608    pub this: Box<Expression>,
12609    pub expression: Box<Expression>,
12610    #[serde(default)]
12611    pub group: Option<Box<Expression>>,
12612    #[serde(default)]
12613    pub parameters: Option<Box<Expression>>,
12614    #[serde(default)]
12615    pub position: Option<Box<Expression>>,
12616    #[serde(default)]
12617    pub occurrence: Option<Box<Expression>>,
12618}
12619
12620/// RegexpILike
12621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12622#[cfg_attr(feature = "bindings", derive(TS))]
12623pub struct RegexpILike {
12624    pub this: Box<Expression>,
12625    pub expression: Box<Expression>,
12626    #[serde(default)]
12627    pub flag: Option<Box<Expression>>,
12628}
12629
12630/// RegexpFullMatch
12631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12632#[cfg_attr(feature = "bindings", derive(TS))]
12633pub struct RegexpFullMatch {
12634    pub this: Box<Expression>,
12635    pub expression: Box<Expression>,
12636    #[serde(default)]
12637    pub options: Vec<Expression>,
12638}
12639
12640/// RegexpInstr
12641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12642#[cfg_attr(feature = "bindings", derive(TS))]
12643pub struct RegexpInstr {
12644    pub this: Box<Expression>,
12645    pub expression: Box<Expression>,
12646    #[serde(default)]
12647    pub position: Option<Box<Expression>>,
12648    #[serde(default)]
12649    pub occurrence: Option<Box<Expression>>,
12650    #[serde(default)]
12651    pub option: Option<Box<Expression>>,
12652    #[serde(default)]
12653    pub parameters: Option<Box<Expression>>,
12654    #[serde(default)]
12655    pub group: Option<Box<Expression>>,
12656}
12657
12658/// RegexpSplit
12659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12660#[cfg_attr(feature = "bindings", derive(TS))]
12661pub struct RegexpSplit {
12662    pub this: Box<Expression>,
12663    pub expression: Box<Expression>,
12664    #[serde(default)]
12665    pub limit: Option<Box<Expression>>,
12666}
12667
12668/// RegexpCount
12669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12670#[cfg_attr(feature = "bindings", derive(TS))]
12671pub struct RegexpCount {
12672    pub this: Box<Expression>,
12673    pub expression: Box<Expression>,
12674    #[serde(default)]
12675    pub position: Option<Box<Expression>>,
12676    #[serde(default)]
12677    pub parameters: Option<Box<Expression>>,
12678}
12679
12680/// RegrValx
12681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12682#[cfg_attr(feature = "bindings", derive(TS))]
12683pub struct RegrValx {
12684    pub this: Box<Expression>,
12685    pub expression: Box<Expression>,
12686}
12687
12688/// RegrValy
12689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12690#[cfg_attr(feature = "bindings", derive(TS))]
12691pub struct RegrValy {
12692    pub this: Box<Expression>,
12693    pub expression: Box<Expression>,
12694}
12695
12696/// RegrAvgy
12697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12698#[cfg_attr(feature = "bindings", derive(TS))]
12699pub struct RegrAvgy {
12700    pub this: Box<Expression>,
12701    pub expression: Box<Expression>,
12702}
12703
12704/// RegrAvgx
12705#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12706#[cfg_attr(feature = "bindings", derive(TS))]
12707pub struct RegrAvgx {
12708    pub this: Box<Expression>,
12709    pub expression: Box<Expression>,
12710}
12711
12712/// RegrCount
12713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12714#[cfg_attr(feature = "bindings", derive(TS))]
12715pub struct RegrCount {
12716    pub this: Box<Expression>,
12717    pub expression: Box<Expression>,
12718}
12719
12720/// RegrIntercept
12721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12722#[cfg_attr(feature = "bindings", derive(TS))]
12723pub struct RegrIntercept {
12724    pub this: Box<Expression>,
12725    pub expression: Box<Expression>,
12726}
12727
12728/// RegrR2
12729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12730#[cfg_attr(feature = "bindings", derive(TS))]
12731pub struct RegrR2 {
12732    pub this: Box<Expression>,
12733    pub expression: Box<Expression>,
12734}
12735
12736/// RegrSxx
12737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12738#[cfg_attr(feature = "bindings", derive(TS))]
12739pub struct RegrSxx {
12740    pub this: Box<Expression>,
12741    pub expression: Box<Expression>,
12742}
12743
12744/// RegrSxy
12745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12746#[cfg_attr(feature = "bindings", derive(TS))]
12747pub struct RegrSxy {
12748    pub this: Box<Expression>,
12749    pub expression: Box<Expression>,
12750}
12751
12752/// RegrSyy
12753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12754#[cfg_attr(feature = "bindings", derive(TS))]
12755pub struct RegrSyy {
12756    pub this: Box<Expression>,
12757    pub expression: Box<Expression>,
12758}
12759
12760/// RegrSlope
12761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12762#[cfg_attr(feature = "bindings", derive(TS))]
12763pub struct RegrSlope {
12764    pub this: Box<Expression>,
12765    pub expression: Box<Expression>,
12766}
12767
12768/// SafeAdd
12769#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12770#[cfg_attr(feature = "bindings", derive(TS))]
12771pub struct SafeAdd {
12772    pub this: Box<Expression>,
12773    pub expression: Box<Expression>,
12774}
12775
12776/// SafeDivide
12777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12778#[cfg_attr(feature = "bindings", derive(TS))]
12779pub struct SafeDivide {
12780    pub this: Box<Expression>,
12781    pub expression: Box<Expression>,
12782}
12783
12784/// SafeMultiply
12785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12786#[cfg_attr(feature = "bindings", derive(TS))]
12787pub struct SafeMultiply {
12788    pub this: Box<Expression>,
12789    pub expression: Box<Expression>,
12790}
12791
12792/// SafeSubtract
12793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12794#[cfg_attr(feature = "bindings", derive(TS))]
12795pub struct SafeSubtract {
12796    pub this: Box<Expression>,
12797    pub expression: Box<Expression>,
12798}
12799
12800/// SHA2
12801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12802#[cfg_attr(feature = "bindings", derive(TS))]
12803pub struct SHA2 {
12804    pub this: Box<Expression>,
12805    #[serde(default)]
12806    pub length: Option<i64>,
12807}
12808
12809/// SHA2Digest
12810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12811#[cfg_attr(feature = "bindings", derive(TS))]
12812pub struct SHA2Digest {
12813    pub this: Box<Expression>,
12814    #[serde(default)]
12815    pub length: Option<i64>,
12816}
12817
12818/// SortArray
12819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12820#[cfg_attr(feature = "bindings", derive(TS))]
12821pub struct SortArray {
12822    pub this: Box<Expression>,
12823    #[serde(default)]
12824    pub asc: Option<Box<Expression>>,
12825    #[serde(default)]
12826    pub nulls_first: Option<Box<Expression>>,
12827}
12828
12829/// SplitPart
12830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12831#[cfg_attr(feature = "bindings", derive(TS))]
12832pub struct SplitPart {
12833    pub this: Box<Expression>,
12834    #[serde(default)]
12835    pub delimiter: Option<Box<Expression>>,
12836    #[serde(default)]
12837    pub part_index: Option<Box<Expression>>,
12838}
12839
12840/// SUBSTRING_INDEX(str, delim, count)
12841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12842#[cfg_attr(feature = "bindings", derive(TS))]
12843pub struct SubstringIndex {
12844    pub this: Box<Expression>,
12845    #[serde(default)]
12846    pub delimiter: Option<Box<Expression>>,
12847    #[serde(default)]
12848    pub count: Option<Box<Expression>>,
12849}
12850
12851/// StandardHash
12852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12853#[cfg_attr(feature = "bindings", derive(TS))]
12854pub struct StandardHash {
12855    pub this: Box<Expression>,
12856    #[serde(default)]
12857    pub expression: Option<Box<Expression>>,
12858}
12859
12860/// StrPosition
12861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12862#[cfg_attr(feature = "bindings", derive(TS))]
12863pub struct StrPosition {
12864    pub this: Box<Expression>,
12865    #[serde(default)]
12866    pub substr: Option<Box<Expression>>,
12867    #[serde(default)]
12868    pub position: Option<Box<Expression>>,
12869    #[serde(default)]
12870    pub occurrence: Option<Box<Expression>>,
12871}
12872
12873/// Search
12874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12875#[cfg_attr(feature = "bindings", derive(TS))]
12876pub struct Search {
12877    pub this: Box<Expression>,
12878    pub expression: Box<Expression>,
12879    #[serde(default)]
12880    pub json_scope: Option<Box<Expression>>,
12881    #[serde(default)]
12882    pub analyzer: Option<Box<Expression>>,
12883    #[serde(default)]
12884    pub analyzer_options: Option<Box<Expression>>,
12885    #[serde(default)]
12886    pub search_mode: Option<Box<Expression>>,
12887}
12888
12889/// SearchIp
12890#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12891#[cfg_attr(feature = "bindings", derive(TS))]
12892pub struct SearchIp {
12893    pub this: Box<Expression>,
12894    pub expression: Box<Expression>,
12895}
12896
12897/// StrToDate
12898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12899#[cfg_attr(feature = "bindings", derive(TS))]
12900pub struct StrToDate {
12901    pub this: Box<Expression>,
12902    #[serde(default)]
12903    pub format: Option<String>,
12904    #[serde(default)]
12905    pub safe: Option<Box<Expression>>,
12906}
12907
12908/// StrToTime
12909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12910#[cfg_attr(feature = "bindings", derive(TS))]
12911pub struct StrToTime {
12912    pub this: Box<Expression>,
12913    pub format: String,
12914    #[serde(default)]
12915    pub zone: Option<Box<Expression>>,
12916    #[serde(default)]
12917    pub safe: Option<Box<Expression>>,
12918    #[serde(default)]
12919    pub target_type: Option<Box<Expression>>,
12920}
12921
12922/// StrToUnix
12923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12924#[cfg_attr(feature = "bindings", derive(TS))]
12925pub struct StrToUnix {
12926    #[serde(default)]
12927    pub this: Option<Box<Expression>>,
12928    #[serde(default)]
12929    pub format: Option<String>,
12930}
12931
12932/// StrToMap
12933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12934#[cfg_attr(feature = "bindings", derive(TS))]
12935pub struct StrToMap {
12936    pub this: Box<Expression>,
12937    #[serde(default)]
12938    pub pair_delim: Option<Box<Expression>>,
12939    #[serde(default)]
12940    pub key_value_delim: Option<Box<Expression>>,
12941    #[serde(default)]
12942    pub duplicate_resolution_callback: Option<Box<Expression>>,
12943}
12944
12945/// NumberToStr
12946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12947#[cfg_attr(feature = "bindings", derive(TS))]
12948pub struct NumberToStr {
12949    pub this: Box<Expression>,
12950    pub format: String,
12951    #[serde(default)]
12952    pub culture: Option<Box<Expression>>,
12953}
12954
12955/// FromBase
12956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12957#[cfg_attr(feature = "bindings", derive(TS))]
12958pub struct FromBase {
12959    pub this: Box<Expression>,
12960    pub expression: Box<Expression>,
12961}
12962
12963/// Stuff
12964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12965#[cfg_attr(feature = "bindings", derive(TS))]
12966pub struct Stuff {
12967    pub this: Box<Expression>,
12968    #[serde(default)]
12969    pub start: Option<Box<Expression>>,
12970    #[serde(default)]
12971    pub length: Option<i64>,
12972    pub expression: Box<Expression>,
12973}
12974
12975/// TimeToStr
12976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12977#[cfg_attr(feature = "bindings", derive(TS))]
12978pub struct TimeToStr {
12979    pub this: Box<Expression>,
12980    pub format: String,
12981    #[serde(default)]
12982    pub culture: Option<Box<Expression>>,
12983    #[serde(default)]
12984    pub zone: Option<Box<Expression>>,
12985}
12986
12987/// TimeStrToTime
12988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12989#[cfg_attr(feature = "bindings", derive(TS))]
12990pub struct TimeStrToTime {
12991    pub this: Box<Expression>,
12992    #[serde(default)]
12993    pub zone: Option<Box<Expression>>,
12994}
12995
12996/// TsOrDsAdd
12997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12998#[cfg_attr(feature = "bindings", derive(TS))]
12999pub struct TsOrDsAdd {
13000    pub this: Box<Expression>,
13001    pub expression: Box<Expression>,
13002    #[serde(default)]
13003    pub unit: Option<String>,
13004    #[serde(default)]
13005    pub return_type: Option<Box<Expression>>,
13006}
13007
13008/// TsOrDsDiff
13009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13010#[cfg_attr(feature = "bindings", derive(TS))]
13011pub struct TsOrDsDiff {
13012    pub this: Box<Expression>,
13013    pub expression: Box<Expression>,
13014    #[serde(default)]
13015    pub unit: Option<String>,
13016}
13017
13018/// TsOrDsToDate
13019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13020#[cfg_attr(feature = "bindings", derive(TS))]
13021pub struct TsOrDsToDate {
13022    pub this: Box<Expression>,
13023    #[serde(default)]
13024    pub format: Option<String>,
13025    #[serde(default)]
13026    pub safe: Option<Box<Expression>>,
13027}
13028
13029/// TsOrDsToTime
13030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13031#[cfg_attr(feature = "bindings", derive(TS))]
13032pub struct TsOrDsToTime {
13033    pub this: Box<Expression>,
13034    #[serde(default)]
13035    pub format: Option<String>,
13036    #[serde(default)]
13037    pub safe: Option<Box<Expression>>,
13038}
13039
13040/// Unhex
13041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13042#[cfg_attr(feature = "bindings", derive(TS))]
13043pub struct Unhex {
13044    pub this: Box<Expression>,
13045    #[serde(default)]
13046    pub expression: Option<Box<Expression>>,
13047}
13048
13049/// Uniform
13050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13051#[cfg_attr(feature = "bindings", derive(TS))]
13052pub struct Uniform {
13053    pub this: Box<Expression>,
13054    pub expression: Box<Expression>,
13055    #[serde(default)]
13056    pub gen: Option<Box<Expression>>,
13057    #[serde(default)]
13058    pub seed: Option<Box<Expression>>,
13059}
13060
13061/// UnixToStr
13062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13063#[cfg_attr(feature = "bindings", derive(TS))]
13064pub struct UnixToStr {
13065    pub this: Box<Expression>,
13066    #[serde(default)]
13067    pub format: Option<String>,
13068}
13069
13070/// UnixToTime
13071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13072#[cfg_attr(feature = "bindings", derive(TS))]
13073pub struct UnixToTime {
13074    pub this: Box<Expression>,
13075    #[serde(default)]
13076    pub scale: Option<i64>,
13077    #[serde(default)]
13078    pub zone: Option<Box<Expression>>,
13079    #[serde(default)]
13080    pub hours: Option<Box<Expression>>,
13081    #[serde(default)]
13082    pub minutes: Option<Box<Expression>>,
13083    #[serde(default)]
13084    pub format: Option<String>,
13085    #[serde(default)]
13086    pub target_type: Option<Box<Expression>>,
13087}
13088
13089/// Uuid
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct Uuid {
13093    #[serde(default)]
13094    pub this: Option<Box<Expression>>,
13095    #[serde(default)]
13096    pub name: Option<String>,
13097    #[serde(default)]
13098    pub is_string: Option<Box<Expression>>,
13099}
13100
13101/// TimestampFromParts
13102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13103#[cfg_attr(feature = "bindings", derive(TS))]
13104pub struct TimestampFromParts {
13105    #[serde(default)]
13106    pub zone: Option<Box<Expression>>,
13107    #[serde(default)]
13108    pub milli: Option<Box<Expression>>,
13109    #[serde(default)]
13110    pub this: Option<Box<Expression>>,
13111    #[serde(default)]
13112    pub expression: Option<Box<Expression>>,
13113}
13114
13115/// TimestampTzFromParts
13116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13117#[cfg_attr(feature = "bindings", derive(TS))]
13118pub struct TimestampTzFromParts {
13119    #[serde(default)]
13120    pub zone: Option<Box<Expression>>,
13121}
13122
13123/// Corr
13124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13125#[cfg_attr(feature = "bindings", derive(TS))]
13126pub struct Corr {
13127    pub this: Box<Expression>,
13128    pub expression: Box<Expression>,
13129    #[serde(default)]
13130    pub null_on_zero_variance: Option<Box<Expression>>,
13131}
13132
13133/// WidthBucket
13134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13135#[cfg_attr(feature = "bindings", derive(TS))]
13136pub struct WidthBucket {
13137    pub this: Box<Expression>,
13138    #[serde(default)]
13139    pub min_value: Option<Box<Expression>>,
13140    #[serde(default)]
13141    pub max_value: Option<Box<Expression>>,
13142    #[serde(default)]
13143    pub num_buckets: Option<Box<Expression>>,
13144    #[serde(default)]
13145    pub threshold: Option<Box<Expression>>,
13146}
13147
13148/// CovarSamp
13149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13150#[cfg_attr(feature = "bindings", derive(TS))]
13151pub struct CovarSamp {
13152    pub this: Box<Expression>,
13153    pub expression: Box<Expression>,
13154}
13155
13156/// CovarPop
13157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13158#[cfg_attr(feature = "bindings", derive(TS))]
13159pub struct CovarPop {
13160    pub this: Box<Expression>,
13161    pub expression: Box<Expression>,
13162}
13163
13164/// Week
13165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13166#[cfg_attr(feature = "bindings", derive(TS))]
13167pub struct Week {
13168    pub this: Box<Expression>,
13169    #[serde(default)]
13170    pub mode: Option<Box<Expression>>,
13171}
13172
13173/// XMLElement
13174#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13175#[cfg_attr(feature = "bindings", derive(TS))]
13176pub struct XMLElement {
13177    pub this: Box<Expression>,
13178    #[serde(default)]
13179    pub expressions: Vec<Expression>,
13180    #[serde(default)]
13181    pub evalname: Option<Box<Expression>>,
13182}
13183
13184/// XMLGet
13185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13186#[cfg_attr(feature = "bindings", derive(TS))]
13187pub struct XMLGet {
13188    pub this: Box<Expression>,
13189    pub expression: Box<Expression>,
13190    #[serde(default)]
13191    pub instance: Option<Box<Expression>>,
13192}
13193
13194/// XMLTable
13195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13196#[cfg_attr(feature = "bindings", derive(TS))]
13197pub struct XMLTable {
13198    pub this: Box<Expression>,
13199    #[serde(default)]
13200    pub namespaces: Option<Box<Expression>>,
13201    #[serde(default)]
13202    pub passing: Option<Box<Expression>>,
13203    #[serde(default)]
13204    pub columns: Vec<Expression>,
13205    #[serde(default)]
13206    pub by_ref: Option<Box<Expression>>,
13207}
13208
13209/// XMLKeyValueOption
13210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13211#[cfg_attr(feature = "bindings", derive(TS))]
13212pub struct XMLKeyValueOption {
13213    pub this: Box<Expression>,
13214    #[serde(default)]
13215    pub expression: Option<Box<Expression>>,
13216}
13217
13218/// Zipf
13219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13220#[cfg_attr(feature = "bindings", derive(TS))]
13221pub struct Zipf {
13222    pub this: Box<Expression>,
13223    #[serde(default)]
13224    pub elementcount: Option<Box<Expression>>,
13225    #[serde(default)]
13226    pub gen: Option<Box<Expression>>,
13227}
13228
13229/// Merge
13230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13231#[cfg_attr(feature = "bindings", derive(TS))]
13232pub struct Merge {
13233    pub this: Box<Expression>,
13234    pub using: Box<Expression>,
13235    #[serde(default)]
13236    pub on: Option<Box<Expression>>,
13237    #[serde(default)]
13238    pub using_cond: Option<Box<Expression>>,
13239    #[serde(default)]
13240    pub whens: Option<Box<Expression>>,
13241    #[serde(default)]
13242    pub with_: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub returning: Option<Box<Expression>>,
13245}
13246
13247/// When
13248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13249#[cfg_attr(feature = "bindings", derive(TS))]
13250pub struct When {
13251    #[serde(default)]
13252    pub matched: Option<Box<Expression>>,
13253    #[serde(default)]
13254    pub source: Option<Box<Expression>>,
13255    #[serde(default)]
13256    pub condition: Option<Box<Expression>>,
13257    pub then: Box<Expression>,
13258}
13259
13260/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
13261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13262#[cfg_attr(feature = "bindings", derive(TS))]
13263pub struct Whens {
13264    #[serde(default)]
13265    pub expressions: Vec<Expression>,
13266}
13267
13268/// NextValueFor
13269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13270#[cfg_attr(feature = "bindings", derive(TS))]
13271pub struct NextValueFor {
13272    pub this: Box<Expression>,
13273    #[serde(default)]
13274    pub order: Option<Box<Expression>>,
13275}
13276
13277#[cfg(test)]
13278mod tests {
13279    use super::*;
13280
13281    #[test]
13282    #[cfg(feature = "bindings")]
13283    fn export_typescript_types() {
13284        // This test exports TypeScript types to the generated directory
13285        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
13286        Expression::export_all(&ts_rs::Config::default())
13287            .expect("Failed to export Expression types");
13288    }
13289
13290    #[test]
13291    fn test_simple_select_builder() {
13292        let select = Select::new()
13293            .column(Expression::star())
13294            .from(Expression::Table(Box::new(TableRef::new("users"))));
13295
13296        assert_eq!(select.expressions.len(), 1);
13297        assert!(select.from.is_some());
13298    }
13299
13300    #[test]
13301    fn test_expression_alias() {
13302        let expr = Expression::column("id").alias("user_id");
13303
13304        match expr {
13305            Expression::Alias(a) => {
13306                assert_eq!(a.alias.name, "user_id");
13307            }
13308            _ => panic!("Expected Alias"),
13309        }
13310    }
13311
13312    #[test]
13313    fn test_literal_creation() {
13314        let num = Expression::number(42);
13315        let str = Expression::string("hello");
13316
13317        match num {
13318            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
13319            _ => panic!("Expected Number"),
13320        }
13321
13322        match str {
13323            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
13324            _ => panic!("Expected String"),
13325        }
13326    }
13327
13328    #[test]
13329    fn test_expression_sql() {
13330        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
13331        assert_eq!(expr.sql(), "SELECT 1 + 2");
13332    }
13333
13334    #[test]
13335    fn test_expression_sql_for() {
13336        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
13337        let sql = expr.sql_for(crate::DialectType::Generic);
13338        // Generic mode normalizes IF() to CASE WHEN
13339        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
13340    }
13341}