Skip to main content

polyglot_sql/
expressions.rs

1//! SQL Expression AST (Abstract Syntax Tree).
2//!
3//! This module defines all the AST node types used to represent parsed SQL
4//! statements and expressions. The design follows Python sqlglot's expression
5//! hierarchy, ported to a Rust enum-based AST.
6//!
7//! # Architecture
8//!
9//! The central type is [`Expression`], a large tagged enum with one variant per
10//! SQL construct. Inner structs carry the fields for each variant. Most
11//! heap-allocated variants are wrapped in `Box` to keep the enum size small.
12//!
13//! # Variant Groups
14//!
15//! | Group | Examples | Purpose |
16//! |---|---|---|
17//! | **Queries** | `Select`, `Union`, `Intersect`, `Except`, `Subquery` | Top-level query structures |
18//! | **DML** | `Insert`, `Update`, `Delete`, `Merge`, `Copy` | Data manipulation |
19//! | **DDL** | `CreateTable`, `AlterTable`, `DropView`, `CreateIndex` | Schema definition |
20//! | **Clauses** | `From`, `Join`, `Where`, `GroupBy`, `OrderBy`, `With` | Query clauses |
21//! | **Operators** | `And`, `Or`, `Add`, `Eq`, `Like`, `Not` | Binary and unary operations |
22//! | **Functions** | `Function`, `AggregateFunction`, `WindowFunction`, `Count`, `Sum` | Scalar, aggregate, and window functions |
23//! | **Literals** | `Literal`, `Boolean`, `Null`, `Interval` | Constant values |
24//! | **Types** | `DataType`, `Cast`, `TryCast`, `SafeCast` | Data types and casts |
25//! | **Identifiers** | `Identifier`, `Column`, `Table`, `Star` | Name references |
26//!
27//! # SQL Generation
28//!
29//! Every `Expression` can be rendered back to SQL via [`Expression::sql()`]
30//! (generic dialect) or [`Expression::sql_for()`] (specific dialect). The
31//! actual generation logic lives in the `generator` module.
32
33use crate::tokens::Span;
34use serde::{Deserialize, Serialize};
35use std::fmt;
36#[cfg(feature = "bindings")]
37use ts_rs::TS;
38
39/// Helper function for serde default value
40fn default_true() -> bool {
41    true
42}
43
44fn is_true(v: &bool) -> bool {
45    *v
46}
47
48/// Represent any SQL expression or statement as a single, recursive AST node.
49///
50/// `Expression` is the root type of the polyglot AST. Every parsed SQL
51/// construct -- from a simple integer literal to a multi-CTE query with
52/// window functions -- is represented as a variant of this enum.
53///
54/// Variants are organized into logical groups (see the module-level docs).
55/// Most non-trivial variants box their payload so that `size_of::<Expression>()`
56/// stays small (currently two words: tag + pointer).
57///
58/// # Constructing Expressions
59///
60/// Use the convenience constructors on `impl Expression` for common cases:
61///
62/// ```rust,ignore
63/// use polyglot_sql::expressions::Expression;
64///
65/// let col  = Expression::column("id");
66/// let lit  = Expression::number(42);
67/// let star = Expression::star();
68/// ```
69///
70/// # Generating SQL
71///
72/// ```rust,ignore
73/// let expr = Expression::column("name");
74/// assert_eq!(expr.sql(), "name");
75/// ```
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[cfg_attr(feature = "bindings", derive(TS))]
78#[serde(rename_all = "snake_case")]
79#[cfg_attr(feature = "bindings", ts(export))]
80pub enum Expression {
81    // Literals
82    Literal(Literal),
83    Boolean(BooleanLiteral),
84    Null(Null),
85
86    // Identifiers
87    Identifier(Identifier),
88    Column(Column),
89    Table(TableRef),
90    Star(Star),
91    /// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
92    BracedWildcard(Box<Expression>),
93
94    // Queries
95    Select(Box<Select>),
96    Union(Box<Union>),
97    Intersect(Box<Intersect>),
98    Except(Box<Except>),
99    Subquery(Box<Subquery>),
100    PipeOperator(Box<PipeOperator>),
101    Pivot(Box<Pivot>),
102    PivotAlias(Box<PivotAlias>),
103    Unpivot(Box<Unpivot>),
104    Values(Box<Values>),
105    PreWhere(Box<PreWhere>),
106    Stream(Box<Stream>),
107    UsingData(Box<UsingData>),
108    XmlNamespace(Box<XmlNamespace>),
109
110    // DML
111    Insert(Box<Insert>),
112    Update(Box<Update>),
113    Delete(Box<Delete>),
114    Copy(Box<CopyStmt>),
115    Put(Box<PutStmt>),
116    StageReference(Box<StageReference>),
117
118    // Expressions
119    Alias(Box<Alias>),
120    Cast(Box<Cast>),
121    Collation(Box<CollationExpr>),
122    Case(Box<Case>),
123
124    // Binary operations
125    And(Box<BinaryOp>),
126    Or(Box<BinaryOp>),
127    Add(Box<BinaryOp>),
128    Sub(Box<BinaryOp>),
129    Mul(Box<BinaryOp>),
130    Div(Box<BinaryOp>),
131    Mod(Box<BinaryOp>),
132    Eq(Box<BinaryOp>),
133    Neq(Box<BinaryOp>),
134    Lt(Box<BinaryOp>),
135    Lte(Box<BinaryOp>),
136    Gt(Box<BinaryOp>),
137    Gte(Box<BinaryOp>),
138    Like(Box<LikeOp>),
139    ILike(Box<LikeOp>),
140    /// SQLite MATCH operator (FTS)
141    Match(Box<BinaryOp>),
142    BitwiseAnd(Box<BinaryOp>),
143    BitwiseOr(Box<BinaryOp>),
144    BitwiseXor(Box<BinaryOp>),
145    Concat(Box<BinaryOp>),
146    Adjacent(Box<BinaryOp>),   // PostgreSQL range adjacency operator (-|-)
147    TsMatch(Box<BinaryOp>),    // PostgreSQL text search match operator (@@)
148    PropertyEQ(Box<BinaryOp>), // := assignment operator (MySQL @var := val, DuckDB named args)
149
150    // PostgreSQL array/JSONB operators
151    ArrayContainsAll(Box<BinaryOp>), // @> operator (array contains all)
152    ArrayContainedBy(Box<BinaryOp>), // <@ operator (array contained by)
153    ArrayOverlaps(Box<BinaryOp>),    // && operator (array overlaps)
154    JSONBContainsAllTopKeys(Box<BinaryOp>), // ?& operator (JSONB contains all keys)
155    JSONBContainsAnyTopKeys(Box<BinaryOp>), // ?| operator (JSONB contains any key)
156    JSONBDeleteAtPath(Box<BinaryOp>), // #- operator (JSONB delete at path)
157    ExtendsLeft(Box<BinaryOp>),      // &< operator (PostgreSQL range extends left)
158    ExtendsRight(Box<BinaryOp>),     // &> operator (PostgreSQL range extends right)
159
160    // Unary operations
161    Not(Box<UnaryOp>),
162    Neg(Box<UnaryOp>),
163    BitwiseNot(Box<UnaryOp>),
164
165    // Predicates
166    In(Box<In>),
167    Between(Box<Between>),
168    IsNull(Box<IsNull>),
169    IsTrue(Box<IsTrueFalse>),
170    IsFalse(Box<IsTrueFalse>),
171    IsJson(Box<IsJson>),
172    Is(Box<BinaryOp>), // General IS expression (e.g., a IS ?)
173    Exists(Box<Exists>),
174    /// MySQL MEMBER OF operator: expr MEMBER OF(json_array)
175    MemberOf(Box<BinaryOp>),
176
177    // Functions
178    Function(Box<Function>),
179    AggregateFunction(Box<AggregateFunction>),
180    WindowFunction(Box<WindowFunction>),
181
182    // Clauses
183    From(Box<From>),
184    Join(Box<Join>),
185    JoinedTable(Box<JoinedTable>),
186    Where(Box<Where>),
187    GroupBy(Box<GroupBy>),
188    Having(Box<Having>),
189    OrderBy(Box<OrderBy>),
190    Limit(Box<Limit>),
191    Offset(Box<Offset>),
192    Qualify(Box<Qualify>),
193    With(Box<With>),
194    Cte(Box<Cte>),
195    DistributeBy(Box<DistributeBy>),
196    ClusterBy(Box<ClusterBy>),
197    SortBy(Box<SortBy>),
198    LateralView(Box<LateralView>),
199    Hint(Box<Hint>),
200    Pseudocolumn(Pseudocolumn),
201
202    // Oracle hierarchical queries (CONNECT BY)
203    Connect(Box<Connect>),
204    Prior(Box<Prior>),
205    ConnectByRoot(Box<ConnectByRoot>),
206
207    // Pattern matching (MATCH_RECOGNIZE)
208    MatchRecognize(Box<MatchRecognize>),
209
210    // Order expressions
211    Ordered(Box<Ordered>),
212
213    // Window specifications
214    Window(Box<WindowSpec>),
215    Over(Box<Over>),
216    WithinGroup(Box<WithinGroup>),
217
218    // Data types
219    DataType(DataType),
220
221    // Arrays and structs
222    Array(Box<Array>),
223    Struct(Box<Struct>),
224    Tuple(Box<Tuple>),
225
226    // Interval
227    Interval(Box<Interval>),
228
229    // String functions
230    ConcatWs(Box<ConcatWs>),
231    Substring(Box<SubstringFunc>),
232    Upper(Box<UnaryFunc>),
233    Lower(Box<UnaryFunc>),
234    Length(Box<UnaryFunc>),
235    Trim(Box<TrimFunc>),
236    LTrim(Box<UnaryFunc>),
237    RTrim(Box<UnaryFunc>),
238    Replace(Box<ReplaceFunc>),
239    Reverse(Box<UnaryFunc>),
240    Left(Box<LeftRightFunc>),
241    Right(Box<LeftRightFunc>),
242    Repeat(Box<RepeatFunc>),
243    Lpad(Box<PadFunc>),
244    Rpad(Box<PadFunc>),
245    Split(Box<SplitFunc>),
246    RegexpLike(Box<RegexpFunc>),
247    RegexpReplace(Box<RegexpReplaceFunc>),
248    RegexpExtract(Box<RegexpExtractFunc>),
249    Overlay(Box<OverlayFunc>),
250
251    // Math functions
252    Abs(Box<UnaryFunc>),
253    Round(Box<RoundFunc>),
254    Floor(Box<FloorFunc>),
255    Ceil(Box<CeilFunc>),
256    Power(Box<BinaryFunc>),
257    Sqrt(Box<UnaryFunc>),
258    Cbrt(Box<UnaryFunc>),
259    Ln(Box<UnaryFunc>),
260    Log(Box<LogFunc>),
261    Exp(Box<UnaryFunc>),
262    Sign(Box<UnaryFunc>),
263    Greatest(Box<VarArgFunc>),
264    Least(Box<VarArgFunc>),
265
266    // Date/time functions
267    CurrentDate(CurrentDate),
268    CurrentTime(CurrentTime),
269    CurrentTimestamp(CurrentTimestamp),
270    CurrentTimestampLTZ(CurrentTimestampLTZ),
271    AtTimeZone(Box<AtTimeZone>),
272    DateAdd(Box<DateAddFunc>),
273    DateSub(Box<DateAddFunc>),
274    DateDiff(Box<DateDiffFunc>),
275    DateTrunc(Box<DateTruncFunc>),
276    Extract(Box<ExtractFunc>),
277    ToDate(Box<ToDateFunc>),
278    ToTimestamp(Box<ToTimestampFunc>),
279    Date(Box<UnaryFunc>),
280    Time(Box<UnaryFunc>),
281    DateFromUnixDate(Box<UnaryFunc>),
282    UnixDate(Box<UnaryFunc>),
283    UnixSeconds(Box<UnaryFunc>),
284    UnixMillis(Box<UnaryFunc>),
285    UnixMicros(Box<UnaryFunc>),
286    UnixToTimeStr(Box<BinaryFunc>),
287    TimeStrToDate(Box<UnaryFunc>),
288    DateToDi(Box<UnaryFunc>),
289    DiToDate(Box<UnaryFunc>),
290    TsOrDiToDi(Box<UnaryFunc>),
291    TsOrDsToDatetime(Box<UnaryFunc>),
292    TsOrDsToTimestamp(Box<UnaryFunc>),
293    YearOfWeek(Box<UnaryFunc>),
294    YearOfWeekIso(Box<UnaryFunc>),
295
296    // Control flow functions
297    Coalesce(Box<VarArgFunc>),
298    NullIf(Box<BinaryFunc>),
299    IfFunc(Box<IfFunc>),
300    IfNull(Box<BinaryFunc>),
301    Nvl(Box<BinaryFunc>),
302    Nvl2(Box<Nvl2Func>),
303
304    // Type conversion
305    TryCast(Box<Cast>),
306    SafeCast(Box<Cast>),
307
308    // Typed aggregate functions
309    Count(Box<CountFunc>),
310    Sum(Box<AggFunc>),
311    Avg(Box<AggFunc>),
312    Min(Box<AggFunc>),
313    Max(Box<AggFunc>),
314    GroupConcat(Box<GroupConcatFunc>),
315    StringAgg(Box<StringAggFunc>),
316    ListAgg(Box<ListAggFunc>),
317    ArrayAgg(Box<AggFunc>),
318    CountIf(Box<AggFunc>),
319    SumIf(Box<SumIfFunc>),
320    Stddev(Box<AggFunc>),
321    StddevPop(Box<AggFunc>),
322    StddevSamp(Box<AggFunc>),
323    Variance(Box<AggFunc>),
324    VarPop(Box<AggFunc>),
325    VarSamp(Box<AggFunc>),
326    Median(Box<AggFunc>),
327    Mode(Box<AggFunc>),
328    First(Box<AggFunc>),
329    Last(Box<AggFunc>),
330    AnyValue(Box<AggFunc>),
331    ApproxDistinct(Box<AggFunc>),
332    ApproxCountDistinct(Box<AggFunc>),
333    ApproxPercentile(Box<ApproxPercentileFunc>),
334    Percentile(Box<PercentileFunc>),
335    LogicalAnd(Box<AggFunc>),
336    LogicalOr(Box<AggFunc>),
337    Skewness(Box<AggFunc>),
338    BitwiseCount(Box<UnaryFunc>),
339    ArrayConcatAgg(Box<AggFunc>),
340    ArrayUniqueAgg(Box<AggFunc>),
341    BoolXorAgg(Box<AggFunc>),
342
343    // Typed window functions
344    RowNumber(RowNumber),
345    Rank(Rank),
346    DenseRank(DenseRank),
347    NTile(Box<NTileFunc>),
348    Lead(Box<LeadLagFunc>),
349    Lag(Box<LeadLagFunc>),
350    FirstValue(Box<ValueFunc>),
351    LastValue(Box<ValueFunc>),
352    NthValue(Box<NthValueFunc>),
353    PercentRank(PercentRank),
354    CumeDist(CumeDist),
355    PercentileCont(Box<PercentileFunc>),
356    PercentileDisc(Box<PercentileFunc>),
357
358    // Additional string functions
359    Contains(Box<BinaryFunc>),
360    StartsWith(Box<BinaryFunc>),
361    EndsWith(Box<BinaryFunc>),
362    Position(Box<PositionFunc>),
363    Initcap(Box<UnaryFunc>),
364    Ascii(Box<UnaryFunc>),
365    Chr(Box<UnaryFunc>),
366    /// MySQL CHAR function with multiple args and optional USING charset
367    CharFunc(Box<CharFunc>),
368    Soundex(Box<UnaryFunc>),
369    Levenshtein(Box<BinaryFunc>),
370    ByteLength(Box<UnaryFunc>),
371    Hex(Box<UnaryFunc>),
372    LowerHex(Box<UnaryFunc>),
373    Unicode(Box<UnaryFunc>),
374
375    // Additional math functions
376    ModFunc(Box<BinaryFunc>),
377    Random(Random),
378    Rand(Box<Rand>),
379    TruncFunc(Box<TruncateFunc>),
380    Pi(Pi),
381    Radians(Box<UnaryFunc>),
382    Degrees(Box<UnaryFunc>),
383    Sin(Box<UnaryFunc>),
384    Cos(Box<UnaryFunc>),
385    Tan(Box<UnaryFunc>),
386    Asin(Box<UnaryFunc>),
387    Acos(Box<UnaryFunc>),
388    Atan(Box<UnaryFunc>),
389    Atan2(Box<BinaryFunc>),
390    IsNan(Box<UnaryFunc>),
391    IsInf(Box<UnaryFunc>),
392    IntDiv(Box<BinaryFunc>),
393
394    // Control flow
395    Decode(Box<DecodeFunc>),
396
397    // Additional date/time functions
398    DateFormat(Box<DateFormatFunc>),
399    FormatDate(Box<DateFormatFunc>),
400    Year(Box<UnaryFunc>),
401    Month(Box<UnaryFunc>),
402    Day(Box<UnaryFunc>),
403    Hour(Box<UnaryFunc>),
404    Minute(Box<UnaryFunc>),
405    Second(Box<UnaryFunc>),
406    DayOfWeek(Box<UnaryFunc>),
407    DayOfWeekIso(Box<UnaryFunc>),
408    DayOfMonth(Box<UnaryFunc>),
409    DayOfYear(Box<UnaryFunc>),
410    WeekOfYear(Box<UnaryFunc>),
411    Quarter(Box<UnaryFunc>),
412    AddMonths(Box<BinaryFunc>),
413    MonthsBetween(Box<BinaryFunc>),
414    LastDay(Box<LastDayFunc>),
415    NextDay(Box<BinaryFunc>),
416    Epoch(Box<UnaryFunc>),
417    EpochMs(Box<UnaryFunc>),
418    FromUnixtime(Box<FromUnixtimeFunc>),
419    UnixTimestamp(Box<UnixTimestampFunc>),
420    MakeDate(Box<MakeDateFunc>),
421    MakeTimestamp(Box<MakeTimestampFunc>),
422    TimestampTrunc(Box<DateTruncFunc>),
423    TimeStrToUnix(Box<UnaryFunc>),
424
425    // Session/User functions
426    SessionUser(SessionUser),
427
428    // Hash/Crypto functions
429    SHA(Box<UnaryFunc>),
430    SHA1Digest(Box<UnaryFunc>),
431
432    // Time conversion functions
433    TimeToUnix(Box<UnaryFunc>),
434
435    // Array functions
436    ArrayFunc(Box<ArrayConstructor>),
437    ArrayLength(Box<UnaryFunc>),
438    ArraySize(Box<UnaryFunc>),
439    Cardinality(Box<UnaryFunc>),
440    ArrayContains(Box<BinaryFunc>),
441    ArrayPosition(Box<BinaryFunc>),
442    ArrayAppend(Box<BinaryFunc>),
443    ArrayPrepend(Box<BinaryFunc>),
444    ArrayConcat(Box<VarArgFunc>),
445    ArraySort(Box<ArraySortFunc>),
446    ArrayReverse(Box<UnaryFunc>),
447    ArrayDistinct(Box<UnaryFunc>),
448    ArrayJoin(Box<ArrayJoinFunc>),
449    ArrayToString(Box<ArrayJoinFunc>),
450    Unnest(Box<UnnestFunc>),
451    Explode(Box<UnaryFunc>),
452    ExplodeOuter(Box<UnaryFunc>),
453    ArrayFilter(Box<ArrayFilterFunc>),
454    ArrayTransform(Box<ArrayTransformFunc>),
455    ArrayFlatten(Box<UnaryFunc>),
456    ArrayCompact(Box<UnaryFunc>),
457    ArrayIntersect(Box<VarArgFunc>),
458    ArrayUnion(Box<BinaryFunc>),
459    ArrayExcept(Box<BinaryFunc>),
460    ArrayRemove(Box<BinaryFunc>),
461    ArrayZip(Box<VarArgFunc>),
462    Sequence(Box<SequenceFunc>),
463    Generate(Box<SequenceFunc>),
464    ExplodingGenerateSeries(Box<SequenceFunc>),
465    ToArray(Box<UnaryFunc>),
466    StarMap(Box<BinaryFunc>),
467
468    // Struct functions
469    StructFunc(Box<StructConstructor>),
470    StructExtract(Box<StructExtractFunc>),
471    NamedStruct(Box<NamedStructFunc>),
472
473    // Map functions
474    MapFunc(Box<MapConstructor>),
475    MapFromEntries(Box<UnaryFunc>),
476    MapFromArrays(Box<BinaryFunc>),
477    MapKeys(Box<UnaryFunc>),
478    MapValues(Box<UnaryFunc>),
479    MapContainsKey(Box<BinaryFunc>),
480    MapConcat(Box<VarArgFunc>),
481    ElementAt(Box<BinaryFunc>),
482    TransformKeys(Box<TransformFunc>),
483    TransformValues(Box<TransformFunc>),
484
485    // JSON functions
486    JsonExtract(Box<JsonExtractFunc>),
487    JsonExtractScalar(Box<JsonExtractFunc>),
488    JsonExtractPath(Box<JsonPathFunc>),
489    JsonArray(Box<VarArgFunc>),
490    JsonObject(Box<JsonObjectFunc>),
491    JsonQuery(Box<JsonExtractFunc>),
492    JsonValue(Box<JsonExtractFunc>),
493    JsonArrayLength(Box<UnaryFunc>),
494    JsonKeys(Box<UnaryFunc>),
495    JsonType(Box<UnaryFunc>),
496    ParseJson(Box<UnaryFunc>),
497    ToJson(Box<UnaryFunc>),
498    JsonSet(Box<JsonModifyFunc>),
499    JsonInsert(Box<JsonModifyFunc>),
500    JsonRemove(Box<JsonPathFunc>),
501    JsonMergePatch(Box<BinaryFunc>),
502    JsonArrayAgg(Box<JsonArrayAggFunc>),
503    JsonObjectAgg(Box<JsonObjectAggFunc>),
504
505    // Type casting/conversion
506    Convert(Box<ConvertFunc>),
507    Typeof(Box<UnaryFunc>),
508
509    // Additional expressions
510    Lambda(Box<LambdaExpr>),
511    Parameter(Box<Parameter>),
512    Placeholder(Placeholder),
513    NamedArgument(Box<NamedArgument>),
514    /// TABLE ref or MODEL ref used as a function argument (BigQuery)
515    /// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
516    TableArgument(Box<TableArgument>),
517    SqlComment(Box<SqlComment>),
518
519    // Additional predicates
520    NullSafeEq(Box<BinaryOp>),
521    NullSafeNeq(Box<BinaryOp>),
522    Glob(Box<BinaryOp>),
523    SimilarTo(Box<SimilarToExpr>),
524    Any(Box<QuantifiedExpr>),
525    All(Box<QuantifiedExpr>),
526    Overlaps(Box<OverlapsExpr>),
527
528    // Bitwise operations
529    BitwiseLeftShift(Box<BinaryOp>),
530    BitwiseRightShift(Box<BinaryOp>),
531    BitwiseAndAgg(Box<AggFunc>),
532    BitwiseOrAgg(Box<AggFunc>),
533    BitwiseXorAgg(Box<AggFunc>),
534
535    // Array/struct/map access
536    Subscript(Box<Subscript>),
537    Dot(Box<DotAccess>),
538    MethodCall(Box<MethodCall>),
539    ArraySlice(Box<ArraySlice>),
540
541    // DDL statements
542    CreateTable(Box<CreateTable>),
543    DropTable(Box<DropTable>),
544    AlterTable(Box<AlterTable>),
545    CreateIndex(Box<CreateIndex>),
546    DropIndex(Box<DropIndex>),
547    CreateView(Box<CreateView>),
548    DropView(Box<DropView>),
549    AlterView(Box<AlterView>),
550    AlterIndex(Box<AlterIndex>),
551    Truncate(Box<Truncate>),
552    Use(Box<Use>),
553    Cache(Box<Cache>),
554    Uncache(Box<Uncache>),
555    LoadData(Box<LoadData>),
556    Pragma(Box<Pragma>),
557    Grant(Box<Grant>),
558    Revoke(Box<Revoke>),
559    Comment(Box<Comment>),
560    SetStatement(Box<SetStatement>),
561    // Phase 4: Additional DDL statements
562    CreateSchema(Box<CreateSchema>),
563    DropSchema(Box<DropSchema>),
564    DropNamespace(Box<DropNamespace>),
565    CreateDatabase(Box<CreateDatabase>),
566    DropDatabase(Box<DropDatabase>),
567    CreateFunction(Box<CreateFunction>),
568    DropFunction(Box<DropFunction>),
569    CreateProcedure(Box<CreateProcedure>),
570    DropProcedure(Box<DropProcedure>),
571    CreateSequence(Box<CreateSequence>),
572    DropSequence(Box<DropSequence>),
573    AlterSequence(Box<AlterSequence>),
574    CreateTrigger(Box<CreateTrigger>),
575    DropTrigger(Box<DropTrigger>),
576    CreateType(Box<CreateType>),
577    DropType(Box<DropType>),
578    Describe(Box<Describe>),
579    Show(Box<Show>),
580
581    // Transaction and other commands
582    Command(Box<Command>),
583    Kill(Box<Kill>),
584    /// EXEC/EXECUTE statement (TSQL stored procedure call)
585    Execute(Box<ExecuteStatement>),
586
587    // Placeholder for unparsed/raw SQL
588    Raw(Raw),
589
590    // Paren for grouping
591    Paren(Box<Paren>),
592
593    // Expression with trailing comments (for round-trip preservation)
594    Annotated(Box<Annotated>),
595
596    // === BATCH GENERATED EXPRESSION TYPES ===
597    // Generated from Python sqlglot expressions.py
598    Refresh(Box<Refresh>),
599    LockingStatement(Box<LockingStatement>),
600    SequenceProperties(Box<SequenceProperties>),
601    TruncateTable(Box<TruncateTable>),
602    Clone(Box<Clone>),
603    Attach(Box<Attach>),
604    Detach(Box<Detach>),
605    Install(Box<Install>),
606    Summarize(Box<Summarize>),
607    Declare(Box<Declare>),
608    DeclareItem(Box<DeclareItem>),
609    Set(Box<Set>),
610    Heredoc(Box<Heredoc>),
611    SetItem(Box<SetItem>),
612    QueryBand(Box<QueryBand>),
613    UserDefinedFunction(Box<UserDefinedFunction>),
614    RecursiveWithSearch(Box<RecursiveWithSearch>),
615    ProjectionDef(Box<ProjectionDef>),
616    TableAlias(Box<TableAlias>),
617    ByteString(Box<ByteString>),
618    HexStringExpr(Box<HexStringExpr>),
619    UnicodeString(Box<UnicodeString>),
620    ColumnPosition(Box<ColumnPosition>),
621    ColumnDef(Box<ColumnDef>),
622    AlterColumn(Box<AlterColumn>),
623    AlterSortKey(Box<AlterSortKey>),
624    AlterSet(Box<AlterSet>),
625    RenameColumn(Box<RenameColumn>),
626    Comprehension(Box<Comprehension>),
627    MergeTreeTTLAction(Box<MergeTreeTTLAction>),
628    MergeTreeTTL(Box<MergeTreeTTL>),
629    IndexConstraintOption(Box<IndexConstraintOption>),
630    ColumnConstraint(Box<ColumnConstraint>),
631    PeriodForSystemTimeConstraint(Box<PeriodForSystemTimeConstraint>),
632    CaseSpecificColumnConstraint(Box<CaseSpecificColumnConstraint>),
633    CharacterSetColumnConstraint(Box<CharacterSetColumnConstraint>),
634    CheckColumnConstraint(Box<CheckColumnConstraint>),
635    CompressColumnConstraint(Box<CompressColumnConstraint>),
636    DateFormatColumnConstraint(Box<DateFormatColumnConstraint>),
637    EphemeralColumnConstraint(Box<EphemeralColumnConstraint>),
638    WithOperator(Box<WithOperator>),
639    GeneratedAsIdentityColumnConstraint(Box<GeneratedAsIdentityColumnConstraint>),
640    AutoIncrementColumnConstraint(AutoIncrementColumnConstraint),
641    CommentColumnConstraint(CommentColumnConstraint),
642    GeneratedAsRowColumnConstraint(Box<GeneratedAsRowColumnConstraint>),
643    IndexColumnConstraint(Box<IndexColumnConstraint>),
644    MaskingPolicyColumnConstraint(Box<MaskingPolicyColumnConstraint>),
645    NotNullColumnConstraint(Box<NotNullColumnConstraint>),
646    PrimaryKeyColumnConstraint(Box<PrimaryKeyColumnConstraint>),
647    UniqueColumnConstraint(Box<UniqueColumnConstraint>),
648    WatermarkColumnConstraint(Box<WatermarkColumnConstraint>),
649    ComputedColumnConstraint(Box<ComputedColumnConstraint>),
650    InOutColumnConstraint(Box<InOutColumnConstraint>),
651    DefaultColumnConstraint(Box<DefaultColumnConstraint>),
652    PathColumnConstraint(Box<PathColumnConstraint>),
653    Constraint(Box<Constraint>),
654    Export(Box<Export>),
655    Filter(Box<Filter>),
656    Changes(Box<Changes>),
657    CopyParameter(Box<CopyParameter>),
658    Credentials(Box<Credentials>),
659    Directory(Box<Directory>),
660    ForeignKey(Box<ForeignKey>),
661    ColumnPrefix(Box<ColumnPrefix>),
662    PrimaryKey(Box<PrimaryKey>),
663    IntoClause(Box<IntoClause>),
664    JoinHint(Box<JoinHint>),
665    Opclass(Box<Opclass>),
666    Index(Box<Index>),
667    IndexParameters(Box<IndexParameters>),
668    ConditionalInsert(Box<ConditionalInsert>),
669    MultitableInserts(Box<MultitableInserts>),
670    OnConflict(Box<OnConflict>),
671    OnCondition(Box<OnCondition>),
672    Returning(Box<Returning>),
673    Introducer(Box<Introducer>),
674    PartitionRange(Box<PartitionRange>),
675    Fetch(Box<Fetch>),
676    Group(Box<Group>),
677    Cube(Box<Cube>),
678    Rollup(Box<Rollup>),
679    GroupingSets(Box<GroupingSets>),
680    LimitOptions(Box<LimitOptions>),
681    Lateral(Box<Lateral>),
682    TableFromRows(Box<TableFromRows>),
683    RowsFrom(Box<RowsFrom>),
684    MatchRecognizeMeasure(Box<MatchRecognizeMeasure>),
685    WithFill(Box<WithFill>),
686    Property(Box<Property>),
687    GrantPrivilege(Box<GrantPrivilege>),
688    GrantPrincipal(Box<GrantPrincipal>),
689    AllowedValuesProperty(Box<AllowedValuesProperty>),
690    AlgorithmProperty(Box<AlgorithmProperty>),
691    AutoIncrementProperty(Box<AutoIncrementProperty>),
692    AutoRefreshProperty(Box<AutoRefreshProperty>),
693    BackupProperty(Box<BackupProperty>),
694    BuildProperty(Box<BuildProperty>),
695    BlockCompressionProperty(Box<BlockCompressionProperty>),
696    CharacterSetProperty(Box<CharacterSetProperty>),
697    ChecksumProperty(Box<ChecksumProperty>),
698    CollateProperty(Box<CollateProperty>),
699    DataBlocksizeProperty(Box<DataBlocksizeProperty>),
700    DataDeletionProperty(Box<DataDeletionProperty>),
701    DefinerProperty(Box<DefinerProperty>),
702    DistKeyProperty(Box<DistKeyProperty>),
703    DistributedByProperty(Box<DistributedByProperty>),
704    DistStyleProperty(Box<DistStyleProperty>),
705    DuplicateKeyProperty(Box<DuplicateKeyProperty>),
706    EngineProperty(Box<EngineProperty>),
707    ToTableProperty(Box<ToTableProperty>),
708    ExecuteAsProperty(Box<ExecuteAsProperty>),
709    ExternalProperty(Box<ExternalProperty>),
710    FallbackProperty(Box<FallbackProperty>),
711    FileFormatProperty(Box<FileFormatProperty>),
712    CredentialsProperty(Box<CredentialsProperty>),
713    FreespaceProperty(Box<FreespaceProperty>),
714    InheritsProperty(Box<InheritsProperty>),
715    InputModelProperty(Box<InputModelProperty>),
716    OutputModelProperty(Box<OutputModelProperty>),
717    IsolatedLoadingProperty(Box<IsolatedLoadingProperty>),
718    JournalProperty(Box<JournalProperty>),
719    LanguageProperty(Box<LanguageProperty>),
720    EnviromentProperty(Box<EnviromentProperty>),
721    ClusteredByProperty(Box<ClusteredByProperty>),
722    DictProperty(Box<DictProperty>),
723    DictRange(Box<DictRange>),
724    OnCluster(Box<OnCluster>),
725    LikeProperty(Box<LikeProperty>),
726    LocationProperty(Box<LocationProperty>),
727    LockProperty(Box<LockProperty>),
728    LockingProperty(Box<LockingProperty>),
729    LogProperty(Box<LogProperty>),
730    MaterializedProperty(Box<MaterializedProperty>),
731    MergeBlockRatioProperty(Box<MergeBlockRatioProperty>),
732    OnProperty(Box<OnProperty>),
733    OnCommitProperty(Box<OnCommitProperty>),
734    PartitionedByProperty(Box<PartitionedByProperty>),
735    PartitionByProperty(Box<PartitionByProperty>),
736    PartitionedByBucket(Box<PartitionedByBucket>),
737    ClusterByColumnsProperty(Box<ClusterByColumnsProperty>),
738    PartitionByTruncate(Box<PartitionByTruncate>),
739    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
740    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
741    PartitionByListProperty(Box<PartitionByListProperty>),
742    PartitionList(Box<PartitionList>),
743    Partition(Box<Partition>),
744    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
745    UniqueKeyProperty(Box<UniqueKeyProperty>),
746    RollupProperty(Box<RollupProperty>),
747    PartitionBoundSpec(Box<PartitionBoundSpec>),
748    PartitionedOfProperty(Box<PartitionedOfProperty>),
749    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
750    ReturnsProperty(Box<ReturnsProperty>),
751    RowFormatProperty(Box<RowFormatProperty>),
752    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
753    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
754    QueryTransform(Box<QueryTransform>),
755    SampleProperty(Box<SampleProperty>),
756    SecurityProperty(Box<SecurityProperty>),
757    SchemaCommentProperty(Box<SchemaCommentProperty>),
758    SemanticView(Box<SemanticView>),
759    SerdeProperties(Box<SerdeProperties>),
760    SetProperty(Box<SetProperty>),
761    SharingProperty(Box<SharingProperty>),
762    SetConfigProperty(Box<SetConfigProperty>),
763    SettingsProperty(Box<SettingsProperty>),
764    SortKeyProperty(Box<SortKeyProperty>),
765    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
766    SqlSecurityProperty(Box<SqlSecurityProperty>),
767    StabilityProperty(Box<StabilityProperty>),
768    StorageHandlerProperty(Box<StorageHandlerProperty>),
769    TemporaryProperty(Box<TemporaryProperty>),
770    Tags(Box<Tags>),
771    TransformModelProperty(Box<TransformModelProperty>),
772    TransientProperty(Box<TransientProperty>),
773    UsingTemplateProperty(Box<UsingTemplateProperty>),
774    ViewAttributeProperty(Box<ViewAttributeProperty>),
775    VolatileProperty(Box<VolatileProperty>),
776    WithDataProperty(Box<WithDataProperty>),
777    WithJournalTableProperty(Box<WithJournalTableProperty>),
778    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
779    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
780    WithProcedureOptions(Box<WithProcedureOptions>),
781    EncodeProperty(Box<EncodeProperty>),
782    IncludeProperty(Box<IncludeProperty>),
783    Properties(Box<Properties>),
784    OptionsProperty(Box<OptionsProperty>),
785    InputOutputFormat(Box<InputOutputFormat>),
786    Reference(Box<Reference>),
787    QueryOption(Box<QueryOption>),
788    WithTableHint(Box<WithTableHint>),
789    IndexTableHint(Box<IndexTableHint>),
790    HistoricalData(Box<HistoricalData>),
791    Get(Box<Get>),
792    SetOperation(Box<SetOperation>),
793    Var(Box<Var>),
794    Variadic(Box<Variadic>),
795    Version(Box<Version>),
796    Schema(Box<Schema>),
797    Lock(Box<Lock>),
798    TableSample(Box<TableSample>),
799    Tag(Box<Tag>),
800    UnpivotColumns(Box<UnpivotColumns>),
801    WindowSpec(Box<WindowSpec>),
802    SessionParameter(Box<SessionParameter>),
803    PseudoType(Box<PseudoType>),
804    ObjectIdentifier(Box<ObjectIdentifier>),
805    Transaction(Box<Transaction>),
806    Commit(Box<Commit>),
807    Rollback(Box<Rollback>),
808    AlterSession(Box<AlterSession>),
809    Analyze(Box<Analyze>),
810    AnalyzeStatistics(Box<AnalyzeStatistics>),
811    AnalyzeHistogram(Box<AnalyzeHistogram>),
812    AnalyzeSample(Box<AnalyzeSample>),
813    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
814    AnalyzeDelete(Box<AnalyzeDelete>),
815    AnalyzeWith(Box<AnalyzeWith>),
816    AnalyzeValidate(Box<AnalyzeValidate>),
817    AddPartition(Box<AddPartition>),
818    AttachOption(Box<AttachOption>),
819    DropPartition(Box<DropPartition>),
820    ReplacePartition(Box<ReplacePartition>),
821    DPipe(Box<DPipe>),
822    Operator(Box<Operator>),
823    PivotAny(Box<PivotAny>),
824    Aliases(Box<Aliases>),
825    AtIndex(Box<AtIndex>),
826    FromTimeZone(Box<FromTimeZone>),
827    FormatPhrase(Box<FormatPhrase>),
828    ForIn(Box<ForIn>),
829    TimeUnit(Box<TimeUnit>),
830    IntervalOp(Box<IntervalOp>),
831    IntervalSpan(Box<IntervalSpan>),
832    HavingMax(Box<HavingMax>),
833    CosineDistance(Box<CosineDistance>),
834    DotProduct(Box<DotProduct>),
835    EuclideanDistance(Box<EuclideanDistance>),
836    ManhattanDistance(Box<ManhattanDistance>),
837    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
838    Booland(Box<Booland>),
839    Boolor(Box<Boolor>),
840    ParameterizedAgg(Box<ParameterizedAgg>),
841    ArgMax(Box<ArgMax>),
842    ArgMin(Box<ArgMin>),
843    ApproxTopK(Box<ApproxTopK>),
844    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
845    ApproxTopKCombine(Box<ApproxTopKCombine>),
846    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
847    ApproxTopSum(Box<ApproxTopSum>),
848    ApproxQuantiles(Box<ApproxQuantiles>),
849    Minhash(Box<Minhash>),
850    FarmFingerprint(Box<FarmFingerprint>),
851    Float64(Box<Float64>),
852    Transform(Box<Transform>),
853    Translate(Box<Translate>),
854    Grouping(Box<Grouping>),
855    GroupingId(Box<GroupingId>),
856    Anonymous(Box<Anonymous>),
857    AnonymousAggFunc(Box<AnonymousAggFunc>),
858    CombinedAggFunc(Box<CombinedAggFunc>),
859    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
860    HashAgg(Box<HashAgg>),
861    Hll(Box<Hll>),
862    Apply(Box<Apply>),
863    ToBoolean(Box<ToBoolean>),
864    List(Box<List>),
865    ToMap(Box<ToMap>),
866    Pad(Box<Pad>),
867    ToChar(Box<ToChar>),
868    ToNumber(Box<ToNumber>),
869    ToDouble(Box<ToDouble>),
870    Int64(Box<UnaryFunc>),
871    StringFunc(Box<StringFunc>),
872    ToDecfloat(Box<ToDecfloat>),
873    TryToDecfloat(Box<TryToDecfloat>),
874    ToFile(Box<ToFile>),
875    Columns(Box<Columns>),
876    ConvertToCharset(Box<ConvertToCharset>),
877    ConvertTimezone(Box<ConvertTimezone>),
878    GenerateSeries(Box<GenerateSeries>),
879    AIAgg(Box<AIAgg>),
880    AIClassify(Box<AIClassify>),
881    ArrayAll(Box<ArrayAll>),
882    ArrayAny(Box<ArrayAny>),
883    ArrayConstructCompact(Box<ArrayConstructCompact>),
884    StPoint(Box<StPoint>),
885    StDistance(Box<StDistance>),
886    StringToArray(Box<StringToArray>),
887    ArraySum(Box<ArraySum>),
888    ObjectAgg(Box<ObjectAgg>),
889    CastToStrType(Box<CastToStrType>),
890    CheckJson(Box<CheckJson>),
891    CheckXml(Box<CheckXml>),
892    TranslateCharacters(Box<TranslateCharacters>),
893    CurrentSchemas(Box<CurrentSchemas>),
894    CurrentDatetime(Box<CurrentDatetime>),
895    Localtime(Box<Localtime>),
896    Localtimestamp(Box<Localtimestamp>),
897    Systimestamp(Box<Systimestamp>),
898    CurrentSchema(Box<CurrentSchema>),
899    CurrentUser(Box<CurrentUser>),
900    UtcTime(Box<UtcTime>),
901    UtcTimestamp(Box<UtcTimestamp>),
902    Timestamp(Box<TimestampFunc>),
903    DateBin(Box<DateBin>),
904    Datetime(Box<Datetime>),
905    DatetimeAdd(Box<DatetimeAdd>),
906    DatetimeSub(Box<DatetimeSub>),
907    DatetimeDiff(Box<DatetimeDiff>),
908    DatetimeTrunc(Box<DatetimeTrunc>),
909    Dayname(Box<Dayname>),
910    MakeInterval(Box<MakeInterval>),
911    PreviousDay(Box<PreviousDay>),
912    Elt(Box<Elt>),
913    TimestampAdd(Box<TimestampAdd>),
914    TimestampSub(Box<TimestampSub>),
915    TimestampDiff(Box<TimestampDiff>),
916    TimeSlice(Box<TimeSlice>),
917    TimeAdd(Box<TimeAdd>),
918    TimeSub(Box<TimeSub>),
919    TimeDiff(Box<TimeDiff>),
920    TimeTrunc(Box<TimeTrunc>),
921    DateFromParts(Box<DateFromParts>),
922    TimeFromParts(Box<TimeFromParts>),
923    DecodeCase(Box<DecodeCase>),
924    Decrypt(Box<Decrypt>),
925    DecryptRaw(Box<DecryptRaw>),
926    Encode(Box<Encode>),
927    Encrypt(Box<Encrypt>),
928    EncryptRaw(Box<EncryptRaw>),
929    EqualNull(Box<EqualNull>),
930    ToBinary(Box<ToBinary>),
931    Base64DecodeBinary(Box<Base64DecodeBinary>),
932    Base64DecodeString(Box<Base64DecodeString>),
933    Base64Encode(Box<Base64Encode>),
934    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
935    TryBase64DecodeString(Box<TryBase64DecodeString>),
936    GapFill(Box<GapFill>),
937    GenerateDateArray(Box<GenerateDateArray>),
938    GenerateTimestampArray(Box<GenerateTimestampArray>),
939    GetExtract(Box<GetExtract>),
940    Getbit(Box<Getbit>),
941    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
942    HexEncode(Box<HexEncode>),
943    Compress(Box<Compress>),
944    DecompressBinary(Box<DecompressBinary>),
945    DecompressString(Box<DecompressString>),
946    Xor(Box<Xor>),
947    Nullif(Box<Nullif>),
948    JSON(Box<JSON>),
949    JSONPath(Box<JSONPath>),
950    JSONPathFilter(Box<JSONPathFilter>),
951    JSONPathKey(Box<JSONPathKey>),
952    JSONPathRecursive(Box<JSONPathRecursive>),
953    JSONPathScript(Box<JSONPathScript>),
954    JSONPathSlice(Box<JSONPathSlice>),
955    JSONPathSelector(Box<JSONPathSelector>),
956    JSONPathSubscript(Box<JSONPathSubscript>),
957    JSONPathUnion(Box<JSONPathUnion>),
958    Format(Box<Format>),
959    JSONKeys(Box<JSONKeys>),
960    JSONKeyValue(Box<JSONKeyValue>),
961    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
962    JSONObject(Box<JSONObject>),
963    JSONObjectAgg(Box<JSONObjectAgg>),
964    JSONBObjectAgg(Box<JSONBObjectAgg>),
965    JSONArray(Box<JSONArray>),
966    JSONArrayAgg(Box<JSONArrayAgg>),
967    JSONExists(Box<JSONExists>),
968    JSONColumnDef(Box<JSONColumnDef>),
969    JSONSchema(Box<JSONSchema>),
970    JSONSet(Box<JSONSet>),
971    JSONStripNulls(Box<JSONStripNulls>),
972    JSONValue(Box<JSONValue>),
973    JSONValueArray(Box<JSONValueArray>),
974    JSONRemove(Box<JSONRemove>),
975    JSONTable(Box<JSONTable>),
976    JSONType(Box<JSONType>),
977    ObjectInsert(Box<ObjectInsert>),
978    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
979    OpenJSON(Box<OpenJSON>),
980    JSONBExists(Box<JSONBExists>),
981    JSONBContains(Box<BinaryFunc>),
982    JSONBExtract(Box<BinaryFunc>),
983    JSONCast(Box<JSONCast>),
984    JSONExtract(Box<JSONExtract>),
985    JSONExtractQuote(Box<JSONExtractQuote>),
986    JSONExtractArray(Box<JSONExtractArray>),
987    JSONExtractScalar(Box<JSONExtractScalar>),
988    JSONBExtractScalar(Box<JSONBExtractScalar>),
989    JSONFormat(Box<JSONFormat>),
990    JSONBool(Box<UnaryFunc>),
991    JSONPathRoot(JSONPathRoot),
992    JSONArrayAppend(Box<JSONArrayAppend>),
993    JSONArrayContains(Box<JSONArrayContains>),
994    JSONArrayInsert(Box<JSONArrayInsert>),
995    ParseJSON(Box<ParseJSON>),
996    ParseUrl(Box<ParseUrl>),
997    ParseIp(Box<ParseIp>),
998    ParseTime(Box<ParseTime>),
999    ParseDatetime(Box<ParseDatetime>),
1000    Map(Box<Map>),
1001    MapCat(Box<MapCat>),
1002    MapDelete(Box<MapDelete>),
1003    MapInsert(Box<MapInsert>),
1004    MapPick(Box<MapPick>),
1005    ScopeResolution(Box<ScopeResolution>),
1006    Slice(Box<Slice>),
1007    VarMap(Box<VarMap>),
1008    MatchAgainst(Box<MatchAgainst>),
1009    MD5Digest(Box<MD5Digest>),
1010    MD5NumberLower64(Box<UnaryFunc>),
1011    MD5NumberUpper64(Box<UnaryFunc>),
1012    Monthname(Box<Monthname>),
1013    Ntile(Box<Ntile>),
1014    Normalize(Box<Normalize>),
1015    Normal(Box<Normal>),
1016    Predict(Box<Predict>),
1017    MLTranslate(Box<MLTranslate>),
1018    FeaturesAtTime(Box<FeaturesAtTime>),
1019    GenerateEmbedding(Box<GenerateEmbedding>),
1020    MLForecast(Box<MLForecast>),
1021    ModelAttribute(Box<ModelAttribute>),
1022    VectorSearch(Box<VectorSearch>),
1023    Quantile(Box<Quantile>),
1024    ApproxQuantile(Box<ApproxQuantile>),
1025    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1026    Randn(Box<Randn>),
1027    Randstr(Box<Randstr>),
1028    RangeN(Box<RangeN>),
1029    RangeBucket(Box<RangeBucket>),
1030    ReadCSV(Box<ReadCSV>),
1031    ReadParquet(Box<ReadParquet>),
1032    Reduce(Box<Reduce>),
1033    RegexpExtractAll(Box<RegexpExtractAll>),
1034    RegexpILike(Box<RegexpILike>),
1035    RegexpFullMatch(Box<RegexpFullMatch>),
1036    RegexpInstr(Box<RegexpInstr>),
1037    RegexpSplit(Box<RegexpSplit>),
1038    RegexpCount(Box<RegexpCount>),
1039    RegrValx(Box<RegrValx>),
1040    RegrValy(Box<RegrValy>),
1041    RegrAvgy(Box<RegrAvgy>),
1042    RegrAvgx(Box<RegrAvgx>),
1043    RegrCount(Box<RegrCount>),
1044    RegrIntercept(Box<RegrIntercept>),
1045    RegrR2(Box<RegrR2>),
1046    RegrSxx(Box<RegrSxx>),
1047    RegrSxy(Box<RegrSxy>),
1048    RegrSyy(Box<RegrSyy>),
1049    RegrSlope(Box<RegrSlope>),
1050    SafeAdd(Box<SafeAdd>),
1051    SafeDivide(Box<SafeDivide>),
1052    SafeMultiply(Box<SafeMultiply>),
1053    SafeSubtract(Box<SafeSubtract>),
1054    SHA2(Box<SHA2>),
1055    SHA2Digest(Box<SHA2Digest>),
1056    SortArray(Box<SortArray>),
1057    SplitPart(Box<SplitPart>),
1058    SubstringIndex(Box<SubstringIndex>),
1059    StandardHash(Box<StandardHash>),
1060    StrPosition(Box<StrPosition>),
1061    Search(Box<Search>),
1062    SearchIp(Box<SearchIp>),
1063    StrToDate(Box<StrToDate>),
1064    DateStrToDate(Box<UnaryFunc>),
1065    DateToDateStr(Box<UnaryFunc>),
1066    StrToTime(Box<StrToTime>),
1067    StrToUnix(Box<StrToUnix>),
1068    StrToMap(Box<StrToMap>),
1069    NumberToStr(Box<NumberToStr>),
1070    FromBase(Box<FromBase>),
1071    Stuff(Box<Stuff>),
1072    TimeToStr(Box<TimeToStr>),
1073    TimeStrToTime(Box<TimeStrToTime>),
1074    TsOrDsAdd(Box<TsOrDsAdd>),
1075    TsOrDsDiff(Box<TsOrDsDiff>),
1076    TsOrDsToDate(Box<TsOrDsToDate>),
1077    TsOrDsToTime(Box<TsOrDsToTime>),
1078    Unhex(Box<Unhex>),
1079    Uniform(Box<Uniform>),
1080    UnixToStr(Box<UnixToStr>),
1081    UnixToTime(Box<UnixToTime>),
1082    Uuid(Box<Uuid>),
1083    TimestampFromParts(Box<TimestampFromParts>),
1084    TimestampTzFromParts(Box<TimestampTzFromParts>),
1085    Corr(Box<Corr>),
1086    WidthBucket(Box<WidthBucket>),
1087    CovarSamp(Box<CovarSamp>),
1088    CovarPop(Box<CovarPop>),
1089    Week(Box<Week>),
1090    XMLElement(Box<XMLElement>),
1091    XMLGet(Box<XMLGet>),
1092    XMLTable(Box<XMLTable>),
1093    XMLKeyValueOption(Box<XMLKeyValueOption>),
1094    Zipf(Box<Zipf>),
1095    Merge(Box<Merge>),
1096    When(Box<When>),
1097    Whens(Box<Whens>),
1098    NextValueFor(Box<NextValueFor>),
1099    /// RETURN statement (DuckDB stored procedures)
1100    ReturnStmt(Box<Expression>),
1101}
1102
1103impl Expression {
1104    /// Returns `true` if this expression is a valid top-level SQL statement.
1105    ///
1106    /// Bare expressions like identifiers, literals, and function calls are not
1107    /// valid statements. This is used by `validate()` to reject inputs like
1108    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1109    /// plus the bare identifier `doo`.
1110    pub fn is_statement(&self) -> bool {
1111        match self {
1112            // Queries
1113            Expression::Select(_)
1114            | Expression::Union(_)
1115            | Expression::Intersect(_)
1116            | Expression::Except(_)
1117            | Expression::Subquery(_)
1118            | Expression::Values(_)
1119            | Expression::PipeOperator(_)
1120
1121            // DML
1122            | Expression::Insert(_)
1123            | Expression::Update(_)
1124            | Expression::Delete(_)
1125            | Expression::Copy(_)
1126            | Expression::Put(_)
1127            | Expression::Merge(_)
1128
1129            // DDL
1130            | Expression::CreateTable(_)
1131            | Expression::DropTable(_)
1132            | Expression::AlterTable(_)
1133            | Expression::CreateIndex(_)
1134            | Expression::DropIndex(_)
1135            | Expression::CreateView(_)
1136            | Expression::DropView(_)
1137            | Expression::AlterView(_)
1138            | Expression::AlterIndex(_)
1139            | Expression::Truncate(_)
1140            | Expression::TruncateTable(_)
1141            | Expression::CreateSchema(_)
1142            | Expression::DropSchema(_)
1143            | Expression::DropNamespace(_)
1144            | Expression::CreateDatabase(_)
1145            | Expression::DropDatabase(_)
1146            | Expression::CreateFunction(_)
1147            | Expression::DropFunction(_)
1148            | Expression::CreateProcedure(_)
1149            | Expression::DropProcedure(_)
1150            | Expression::CreateSequence(_)
1151            | Expression::DropSequence(_)
1152            | Expression::AlterSequence(_)
1153            | Expression::CreateTrigger(_)
1154            | Expression::DropTrigger(_)
1155            | Expression::CreateType(_)
1156            | Expression::DropType(_)
1157            | Expression::Comment(_)
1158
1159            // Session/Transaction/Control
1160            | Expression::Use(_)
1161            | Expression::Set(_)
1162            | Expression::SetStatement(_)
1163            | Expression::Transaction(_)
1164            | Expression::Commit(_)
1165            | Expression::Rollback(_)
1166            | Expression::Grant(_)
1167            | Expression::Revoke(_)
1168            | Expression::Cache(_)
1169            | Expression::Uncache(_)
1170            | Expression::LoadData(_)
1171            | Expression::Pragma(_)
1172            | Expression::Describe(_)
1173            | Expression::Show(_)
1174            | Expression::Kill(_)
1175            | Expression::Execute(_)
1176            | Expression::Declare(_)
1177            | Expression::Refresh(_)
1178            | Expression::AlterSession(_)
1179            | Expression::LockingStatement(_)
1180
1181            // Analyze
1182            | Expression::Analyze(_)
1183            | Expression::AnalyzeStatistics(_)
1184            | Expression::AnalyzeHistogram(_)
1185            | Expression::AnalyzeSample(_)
1186            | Expression::AnalyzeListChainedRows(_)
1187            | Expression::AnalyzeDelete(_)
1188
1189            // Attach/Detach/Install/Summarize
1190            | Expression::Attach(_)
1191            | Expression::Detach(_)
1192            | Expression::Install(_)
1193            | Expression::Summarize(_)
1194
1195            // Pivot at statement level
1196            | Expression::Pivot(_)
1197            | Expression::Unpivot(_)
1198
1199            // Command (raw/unparsed statements)
1200            | Expression::Command(_)
1201            | Expression::Raw(_)
1202
1203            // Return statement
1204            | Expression::ReturnStmt(_) => true,
1205
1206            // Annotated wraps another expression with comments — check inner
1207            Expression::Annotated(a) => a.this.is_statement(),
1208
1209            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1210            Expression::Alias(a) => a.this.is_statement(),
1211
1212            // Everything else (identifiers, literals, operators, functions, etc.)
1213            _ => false,
1214        }
1215    }
1216
1217    /// Create a literal number expression from an integer.
1218    pub fn number(n: i64) -> Self {
1219        Expression::Literal(Literal::Number(n.to_string()))
1220    }
1221
1222    /// Create a single-quoted literal string expression.
1223    pub fn string(s: impl Into<String>) -> Self {
1224        Expression::Literal(Literal::String(s.into()))
1225    }
1226
1227    /// Create a literal number expression from a float.
1228    pub fn float(f: f64) -> Self {
1229        Expression::Literal(Literal::Number(f.to_string()))
1230    }
1231
1232    /// Get the inferred type annotation, if present.
1233    ///
1234    /// For value-producing expressions with an `inferred_type` field, returns
1235    /// the stored type. For literals and boolean constants, computes the type
1236    /// on the fly from the variant. For DDL/clause expressions, returns `None`.
1237    pub fn inferred_type(&self) -> Option<&DataType> {
1238        match self {
1239            // Structs with inferred_type field
1240            Expression::And(op)
1241            | Expression::Or(op)
1242            | Expression::Add(op)
1243            | Expression::Sub(op)
1244            | Expression::Mul(op)
1245            | Expression::Div(op)
1246            | Expression::Mod(op)
1247            | Expression::Eq(op)
1248            | Expression::Neq(op)
1249            | Expression::Lt(op)
1250            | Expression::Lte(op)
1251            | Expression::Gt(op)
1252            | Expression::Gte(op)
1253            | Expression::Concat(op)
1254            | Expression::BitwiseAnd(op)
1255            | Expression::BitwiseOr(op)
1256            | Expression::BitwiseXor(op)
1257            | Expression::Adjacent(op)
1258            | Expression::TsMatch(op)
1259            | Expression::PropertyEQ(op)
1260            | Expression::ArrayContainsAll(op)
1261            | Expression::ArrayContainedBy(op)
1262            | Expression::ArrayOverlaps(op)
1263            | Expression::JSONBContainsAllTopKeys(op)
1264            | Expression::JSONBContainsAnyTopKeys(op)
1265            | Expression::JSONBDeleteAtPath(op)
1266            | Expression::ExtendsLeft(op)
1267            | Expression::ExtendsRight(op)
1268            | Expression::Is(op)
1269            | Expression::MemberOf(op)
1270            | Expression::Match(op)
1271            | Expression::NullSafeEq(op)
1272            | Expression::NullSafeNeq(op)
1273            | Expression::Glob(op)
1274            | Expression::BitwiseLeftShift(op)
1275            | Expression::BitwiseRightShift(op) => op.inferred_type.as_ref(),
1276
1277            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1278                op.inferred_type.as_ref()
1279            }
1280
1281            Expression::Like(op) | Expression::ILike(op) => op.inferred_type.as_ref(),
1282
1283            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1284                c.inferred_type.as_ref()
1285            }
1286
1287            Expression::Column(c) => c.inferred_type.as_ref(),
1288            Expression::Function(f) => f.inferred_type.as_ref(),
1289            Expression::AggregateFunction(f) => f.inferred_type.as_ref(),
1290            Expression::WindowFunction(f) => f.inferred_type.as_ref(),
1291            Expression::Case(c) => c.inferred_type.as_ref(),
1292            Expression::Subquery(s) => s.inferred_type.as_ref(),
1293            Expression::Alias(a) => a.inferred_type.as_ref(),
1294            Expression::IfFunc(f) => f.inferred_type.as_ref(),
1295            Expression::Nvl2(f) => f.inferred_type.as_ref(),
1296            Expression::Count(f) => f.inferred_type.as_ref(),
1297            Expression::GroupConcat(f) => f.inferred_type.as_ref(),
1298            Expression::StringAgg(f) => f.inferred_type.as_ref(),
1299            Expression::ListAgg(f) => f.inferred_type.as_ref(),
1300            Expression::SumIf(f) => f.inferred_type.as_ref(),
1301
1302            // UnaryFunc variants
1303            Expression::Upper(f)
1304            | Expression::Lower(f)
1305            | Expression::Length(f)
1306            | Expression::LTrim(f)
1307            | Expression::RTrim(f)
1308            | Expression::Reverse(f)
1309            | Expression::Abs(f)
1310            | Expression::Sqrt(f)
1311            | Expression::Cbrt(f)
1312            | Expression::Ln(f)
1313            | Expression::Exp(f)
1314            | Expression::Sign(f)
1315            | Expression::Date(f)
1316            | Expression::Time(f)
1317            | Expression::Initcap(f)
1318            | Expression::Ascii(f)
1319            | Expression::Chr(f)
1320            | Expression::Soundex(f)
1321            | Expression::ByteLength(f)
1322            | Expression::Hex(f)
1323            | Expression::LowerHex(f)
1324            | Expression::Unicode(f)
1325            | Expression::Typeof(f)
1326            | Expression::Explode(f)
1327            | Expression::ExplodeOuter(f)
1328            | Expression::MapFromEntries(f)
1329            | Expression::MapKeys(f)
1330            | Expression::MapValues(f)
1331            | Expression::ArrayLength(f)
1332            | Expression::ArraySize(f)
1333            | Expression::Cardinality(f)
1334            | Expression::ArrayReverse(f)
1335            | Expression::ArrayDistinct(f)
1336            | Expression::ArrayFlatten(f)
1337            | Expression::ArrayCompact(f)
1338            | Expression::ToArray(f)
1339            | Expression::JsonArrayLength(f)
1340            | Expression::JsonKeys(f)
1341            | Expression::JsonType(f)
1342            | Expression::ParseJson(f)
1343            | Expression::ToJson(f)
1344            | Expression::Radians(f)
1345            | Expression::Degrees(f)
1346            | Expression::Sin(f)
1347            | Expression::Cos(f)
1348            | Expression::Tan(f)
1349            | Expression::Asin(f)
1350            | Expression::Acos(f)
1351            | Expression::Atan(f)
1352            | Expression::IsNan(f)
1353            | Expression::IsInf(f)
1354            | Expression::Year(f)
1355            | Expression::Month(f)
1356            | Expression::Day(f)
1357            | Expression::Hour(f)
1358            | Expression::Minute(f)
1359            | Expression::Second(f)
1360            | Expression::DayOfWeek(f)
1361            | Expression::DayOfWeekIso(f)
1362            | Expression::DayOfMonth(f)
1363            | Expression::DayOfYear(f)
1364            | Expression::WeekOfYear(f)
1365            | Expression::Quarter(f)
1366            | Expression::Epoch(f)
1367            | Expression::EpochMs(f)
1368            | Expression::BitwiseCount(f)
1369            | Expression::DateFromUnixDate(f)
1370            | Expression::UnixDate(f)
1371            | Expression::UnixSeconds(f)
1372            | Expression::UnixMillis(f)
1373            | Expression::UnixMicros(f)
1374            | Expression::TimeStrToDate(f)
1375            | Expression::DateToDi(f)
1376            | Expression::DiToDate(f)
1377            | Expression::TsOrDiToDi(f)
1378            | Expression::TsOrDsToDatetime(f)
1379            | Expression::TsOrDsToTimestamp(f)
1380            | Expression::YearOfWeek(f)
1381            | Expression::YearOfWeekIso(f)
1382            | Expression::SHA(f)
1383            | Expression::SHA1Digest(f)
1384            | Expression::TimeToUnix(f)
1385            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1386
1387            // BinaryFunc variants
1388            Expression::Power(f)
1389            | Expression::NullIf(f)
1390            | Expression::IfNull(f)
1391            | Expression::Nvl(f)
1392            | Expression::Contains(f)
1393            | Expression::StartsWith(f)
1394            | Expression::EndsWith(f)
1395            | Expression::Levenshtein(f)
1396            | Expression::ModFunc(f)
1397            | Expression::IntDiv(f)
1398            | Expression::Atan2(f)
1399            | Expression::AddMonths(f)
1400            | Expression::MonthsBetween(f)
1401            | Expression::NextDay(f)
1402            | Expression::UnixToTimeStr(f)
1403            | Expression::ArrayContains(f)
1404            | Expression::ArrayPosition(f)
1405            | Expression::ArrayAppend(f)
1406            | Expression::ArrayPrepend(f)
1407            | Expression::ArrayUnion(f)
1408            | Expression::ArrayExcept(f)
1409            | Expression::ArrayRemove(f)
1410            | Expression::StarMap(f)
1411            | Expression::MapFromArrays(f)
1412            | Expression::MapContainsKey(f)
1413            | Expression::ElementAt(f)
1414            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1415
1416            // VarArgFunc variants
1417            Expression::Coalesce(f)
1418            | Expression::Greatest(f)
1419            | Expression::Least(f)
1420            | Expression::ArrayConcat(f)
1421            | Expression::ArrayIntersect(f)
1422            | Expression::ArrayZip(f)
1423            | Expression::MapConcat(f)
1424            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1425
1426            // AggFunc variants
1427            Expression::Sum(f)
1428            | Expression::Avg(f)
1429            | Expression::Min(f)
1430            | Expression::Max(f)
1431            | Expression::ArrayAgg(f)
1432            | Expression::CountIf(f)
1433            | Expression::Stddev(f)
1434            | Expression::StddevPop(f)
1435            | Expression::StddevSamp(f)
1436            | Expression::Variance(f)
1437            | Expression::VarPop(f)
1438            | Expression::VarSamp(f)
1439            | Expression::Median(f)
1440            | Expression::Mode(f)
1441            | Expression::First(f)
1442            | Expression::Last(f)
1443            | Expression::AnyValue(f)
1444            | Expression::ApproxDistinct(f)
1445            | Expression::ApproxCountDistinct(f)
1446            | Expression::LogicalAnd(f)
1447            | Expression::LogicalOr(f)
1448            | Expression::Skewness(f)
1449            | Expression::ArrayConcatAgg(f)
1450            | Expression::ArrayUniqueAgg(f)
1451            | Expression::BoolXorAgg(f)
1452            | Expression::BitwiseAndAgg(f)
1453            | Expression::BitwiseOrAgg(f)
1454            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1455
1456            // Everything else: no inferred_type field
1457            _ => None,
1458        }
1459    }
1460
1461    /// Set the inferred type annotation on this expression.
1462    ///
1463    /// Only has an effect on value-producing expressions with an `inferred_type`
1464    /// field. For other expression types, this is a no-op.
1465    pub fn set_inferred_type(&mut self, dt: DataType) {
1466        match self {
1467            Expression::And(op)
1468            | Expression::Or(op)
1469            | Expression::Add(op)
1470            | Expression::Sub(op)
1471            | Expression::Mul(op)
1472            | Expression::Div(op)
1473            | Expression::Mod(op)
1474            | Expression::Eq(op)
1475            | Expression::Neq(op)
1476            | Expression::Lt(op)
1477            | Expression::Lte(op)
1478            | Expression::Gt(op)
1479            | Expression::Gte(op)
1480            | Expression::Concat(op)
1481            | Expression::BitwiseAnd(op)
1482            | Expression::BitwiseOr(op)
1483            | Expression::BitwiseXor(op)
1484            | Expression::Adjacent(op)
1485            | Expression::TsMatch(op)
1486            | Expression::PropertyEQ(op)
1487            | Expression::ArrayContainsAll(op)
1488            | Expression::ArrayContainedBy(op)
1489            | Expression::ArrayOverlaps(op)
1490            | Expression::JSONBContainsAllTopKeys(op)
1491            | Expression::JSONBContainsAnyTopKeys(op)
1492            | Expression::JSONBDeleteAtPath(op)
1493            | Expression::ExtendsLeft(op)
1494            | Expression::ExtendsRight(op)
1495            | Expression::Is(op)
1496            | Expression::MemberOf(op)
1497            | Expression::Match(op)
1498            | Expression::NullSafeEq(op)
1499            | Expression::NullSafeNeq(op)
1500            | Expression::Glob(op)
1501            | Expression::BitwiseLeftShift(op)
1502            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1503
1504            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1505                op.inferred_type = Some(dt)
1506            }
1507
1508            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1509
1510            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1511                c.inferred_type = Some(dt)
1512            }
1513
1514            Expression::Column(c) => c.inferred_type = Some(dt),
1515            Expression::Function(f) => f.inferred_type = Some(dt),
1516            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1517            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1518            Expression::Case(c) => c.inferred_type = Some(dt),
1519            Expression::Subquery(s) => s.inferred_type = Some(dt),
1520            Expression::Alias(a) => a.inferred_type = Some(dt),
1521            Expression::IfFunc(f) => f.inferred_type = Some(dt),
1522            Expression::Nvl2(f) => f.inferred_type = Some(dt),
1523            Expression::Count(f) => f.inferred_type = Some(dt),
1524            Expression::GroupConcat(f) => f.inferred_type = Some(dt),
1525            Expression::StringAgg(f) => f.inferred_type = Some(dt),
1526            Expression::ListAgg(f) => f.inferred_type = Some(dt),
1527            Expression::SumIf(f) => f.inferred_type = Some(dt),
1528
1529            // UnaryFunc variants
1530            Expression::Upper(f)
1531            | Expression::Lower(f)
1532            | Expression::Length(f)
1533            | Expression::LTrim(f)
1534            | Expression::RTrim(f)
1535            | Expression::Reverse(f)
1536            | Expression::Abs(f)
1537            | Expression::Sqrt(f)
1538            | Expression::Cbrt(f)
1539            | Expression::Ln(f)
1540            | Expression::Exp(f)
1541            | Expression::Sign(f)
1542            | Expression::Date(f)
1543            | Expression::Time(f)
1544            | Expression::Initcap(f)
1545            | Expression::Ascii(f)
1546            | Expression::Chr(f)
1547            | Expression::Soundex(f)
1548            | Expression::ByteLength(f)
1549            | Expression::Hex(f)
1550            | Expression::LowerHex(f)
1551            | Expression::Unicode(f)
1552            | Expression::Typeof(f)
1553            | Expression::Explode(f)
1554            | Expression::ExplodeOuter(f)
1555            | Expression::MapFromEntries(f)
1556            | Expression::MapKeys(f)
1557            | Expression::MapValues(f)
1558            | Expression::ArrayLength(f)
1559            | Expression::ArraySize(f)
1560            | Expression::Cardinality(f)
1561            | Expression::ArrayReverse(f)
1562            | Expression::ArrayDistinct(f)
1563            | Expression::ArrayFlatten(f)
1564            | Expression::ArrayCompact(f)
1565            | Expression::ToArray(f)
1566            | Expression::JsonArrayLength(f)
1567            | Expression::JsonKeys(f)
1568            | Expression::JsonType(f)
1569            | Expression::ParseJson(f)
1570            | Expression::ToJson(f)
1571            | Expression::Radians(f)
1572            | Expression::Degrees(f)
1573            | Expression::Sin(f)
1574            | Expression::Cos(f)
1575            | Expression::Tan(f)
1576            | Expression::Asin(f)
1577            | Expression::Acos(f)
1578            | Expression::Atan(f)
1579            | Expression::IsNan(f)
1580            | Expression::IsInf(f)
1581            | Expression::Year(f)
1582            | Expression::Month(f)
1583            | Expression::Day(f)
1584            | Expression::Hour(f)
1585            | Expression::Minute(f)
1586            | Expression::Second(f)
1587            | Expression::DayOfWeek(f)
1588            | Expression::DayOfWeekIso(f)
1589            | Expression::DayOfMonth(f)
1590            | Expression::DayOfYear(f)
1591            | Expression::WeekOfYear(f)
1592            | Expression::Quarter(f)
1593            | Expression::Epoch(f)
1594            | Expression::EpochMs(f)
1595            | Expression::BitwiseCount(f)
1596            | Expression::DateFromUnixDate(f)
1597            | Expression::UnixDate(f)
1598            | Expression::UnixSeconds(f)
1599            | Expression::UnixMillis(f)
1600            | Expression::UnixMicros(f)
1601            | Expression::TimeStrToDate(f)
1602            | Expression::DateToDi(f)
1603            | Expression::DiToDate(f)
1604            | Expression::TsOrDiToDi(f)
1605            | Expression::TsOrDsToDatetime(f)
1606            | Expression::TsOrDsToTimestamp(f)
1607            | Expression::YearOfWeek(f)
1608            | Expression::YearOfWeekIso(f)
1609            | Expression::SHA(f)
1610            | Expression::SHA1Digest(f)
1611            | Expression::TimeToUnix(f)
1612            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1613
1614            // BinaryFunc variants
1615            Expression::Power(f)
1616            | Expression::NullIf(f)
1617            | Expression::IfNull(f)
1618            | Expression::Nvl(f)
1619            | Expression::Contains(f)
1620            | Expression::StartsWith(f)
1621            | Expression::EndsWith(f)
1622            | Expression::Levenshtein(f)
1623            | Expression::ModFunc(f)
1624            | Expression::IntDiv(f)
1625            | Expression::Atan2(f)
1626            | Expression::AddMonths(f)
1627            | Expression::MonthsBetween(f)
1628            | Expression::NextDay(f)
1629            | Expression::UnixToTimeStr(f)
1630            | Expression::ArrayContains(f)
1631            | Expression::ArrayPosition(f)
1632            | Expression::ArrayAppend(f)
1633            | Expression::ArrayPrepend(f)
1634            | Expression::ArrayUnion(f)
1635            | Expression::ArrayExcept(f)
1636            | Expression::ArrayRemove(f)
1637            | Expression::StarMap(f)
1638            | Expression::MapFromArrays(f)
1639            | Expression::MapContainsKey(f)
1640            | Expression::ElementAt(f)
1641            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1642
1643            // VarArgFunc variants
1644            Expression::Coalesce(f)
1645            | Expression::Greatest(f)
1646            | Expression::Least(f)
1647            | Expression::ArrayConcat(f)
1648            | Expression::ArrayIntersect(f)
1649            | Expression::ArrayZip(f)
1650            | Expression::MapConcat(f)
1651            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1652
1653            // AggFunc variants
1654            Expression::Sum(f)
1655            | Expression::Avg(f)
1656            | Expression::Min(f)
1657            | Expression::Max(f)
1658            | Expression::ArrayAgg(f)
1659            | Expression::CountIf(f)
1660            | Expression::Stddev(f)
1661            | Expression::StddevPop(f)
1662            | Expression::StddevSamp(f)
1663            | Expression::Variance(f)
1664            | Expression::VarPop(f)
1665            | Expression::VarSamp(f)
1666            | Expression::Median(f)
1667            | Expression::Mode(f)
1668            | Expression::First(f)
1669            | Expression::Last(f)
1670            | Expression::AnyValue(f)
1671            | Expression::ApproxDistinct(f)
1672            | Expression::ApproxCountDistinct(f)
1673            | Expression::LogicalAnd(f)
1674            | Expression::LogicalOr(f)
1675            | Expression::Skewness(f)
1676            | Expression::ArrayConcatAgg(f)
1677            | Expression::ArrayUniqueAgg(f)
1678            | Expression::BoolXorAgg(f)
1679            | Expression::BitwiseAndAgg(f)
1680            | Expression::BitwiseOrAgg(f)
1681            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1682
1683            // Expressions without inferred_type field - no-op
1684            _ => {}
1685        }
1686    }
1687
1688    /// Create an unqualified column reference (e.g. `name`).
1689    pub fn column(name: impl Into<String>) -> Self {
1690        Expression::Column(Column {
1691            name: Identifier::new(name),
1692            table: None,
1693            join_mark: false,
1694            trailing_comments: Vec::new(),
1695            span: None,
1696            inferred_type: None,
1697        })
1698    }
1699
1700    /// Create a qualified column reference (`table.column`).
1701    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1702        Expression::Column(Column {
1703            name: Identifier::new(column),
1704            table: Some(Identifier::new(table)),
1705            join_mark: false,
1706            trailing_comments: Vec::new(),
1707            span: None,
1708            inferred_type: None,
1709        })
1710    }
1711
1712    /// Create a bare identifier expression (not a column reference).
1713    pub fn identifier(name: impl Into<String>) -> Self {
1714        Expression::Identifier(Identifier::new(name))
1715    }
1716
1717    /// Create a NULL expression
1718    pub fn null() -> Self {
1719        Expression::Null(Null)
1720    }
1721
1722    /// Create a TRUE expression
1723    pub fn true_() -> Self {
1724        Expression::Boolean(BooleanLiteral { value: true })
1725    }
1726
1727    /// Create a FALSE expression
1728    pub fn false_() -> Self {
1729        Expression::Boolean(BooleanLiteral { value: false })
1730    }
1731
1732    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1733    pub fn star() -> Self {
1734        Expression::Star(Star {
1735            table: None,
1736            except: None,
1737            replace: None,
1738            rename: None,
1739            trailing_comments: Vec::new(),
1740            span: None,
1741        })
1742    }
1743
1744    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1745    pub fn alias(self, name: impl Into<String>) -> Self {
1746        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1747    }
1748
1749    /// Check if this is a SELECT expression
1750    pub fn is_select(&self) -> bool {
1751        matches!(self, Expression::Select(_))
1752    }
1753
1754    /// Try to get as a Select
1755    pub fn as_select(&self) -> Option<&Select> {
1756        match self {
1757            Expression::Select(s) => Some(s),
1758            _ => None,
1759        }
1760    }
1761
1762    /// Try to get as a mutable Select
1763    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1764        match self {
1765            Expression::Select(s) => Some(s),
1766            _ => None,
1767        }
1768    }
1769
1770    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1771    ///
1772    /// Returns an empty string if generation fails. For dialect-specific output,
1773    /// use [`sql_for()`](Self::sql_for) instead.
1774    pub fn sql(&self) -> String {
1775        crate::generator::Generator::sql(self).unwrap_or_default()
1776    }
1777
1778    /// Generate a SQL string for this expression targeting a specific dialect.
1779    ///
1780    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1781    /// syntax variations) are applied automatically.  Returns an empty string if
1782    /// generation fails.
1783    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1784        crate::generate(self, dialect).unwrap_or_default()
1785    }
1786}
1787
1788impl fmt::Display for Expression {
1789    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1790        // Basic display - full SQL generation is in generator module
1791        match self {
1792            Expression::Literal(lit) => write!(f, "{}", lit),
1793            Expression::Identifier(id) => write!(f, "{}", id),
1794            Expression::Column(col) => write!(f, "{}", col),
1795            Expression::Star(_) => write!(f, "*"),
1796            Expression::Null(_) => write!(f, "NULL"),
1797            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1798            Expression::Select(_) => write!(f, "SELECT ..."),
1799            _ => write!(f, "{:?}", self),
1800        }
1801    }
1802}
1803
1804/// Represent a SQL literal value.
1805///
1806/// Numeric values are stored as their original text representation (not parsed
1807/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1808/// preserved across round-trips.
1809///
1810/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1811/// strings, raw strings, etc.) each have a dedicated variant so that the
1812/// generator can emit them with the correct syntax.
1813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1814#[cfg_attr(feature = "bindings", derive(TS))]
1815#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1816pub enum Literal {
1817    /// Single-quoted string literal: `'hello'`
1818    String(String),
1819    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1820    Number(String),
1821    /// Hex string literal: `X'FF'`
1822    HexString(String),
1823    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1824    HexNumber(String),
1825    BitString(String),
1826    /// Byte string: b"..." (BigQuery style)
1827    ByteString(String),
1828    /// National string: N'abc'
1829    NationalString(String),
1830    /// DATE literal: DATE '2024-01-15'
1831    Date(String),
1832    /// TIME literal: TIME '10:30:00'
1833    Time(String),
1834    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1835    Timestamp(String),
1836    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1837    Datetime(String),
1838    /// Triple-quoted string: """...""" or '''...'''
1839    /// Contains (content, quote_char) where quote_char is '"' or '\''
1840    TripleQuotedString(String, char),
1841    /// Escape string: E'...' (PostgreSQL)
1842    EscapeString(String),
1843    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1844    DollarString(String),
1845    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1846    /// In raw strings, backslashes are literal and not escape characters.
1847    /// When converting to a regular string, backslashes must be doubled.
1848    RawString(String),
1849}
1850
1851impl fmt::Display for Literal {
1852    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1853        match self {
1854            Literal::String(s) => write!(f, "'{}'", s),
1855            Literal::Number(n) => write!(f, "{}", n),
1856            Literal::HexString(h) => write!(f, "X'{}'", h),
1857            Literal::HexNumber(h) => write!(f, "0x{}", h),
1858            Literal::BitString(b) => write!(f, "B'{}'", b),
1859            Literal::ByteString(b) => write!(f, "b'{}'", b),
1860            Literal::NationalString(s) => write!(f, "N'{}'", s),
1861            Literal::Date(d) => write!(f, "DATE '{}'", d),
1862            Literal::Time(t) => write!(f, "TIME '{}'", t),
1863            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1864            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1865            Literal::TripleQuotedString(s, q) => {
1866                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1867            }
1868            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1869            Literal::DollarString(s) => write!(f, "$${}$$", s),
1870            Literal::RawString(s) => write!(f, "r'{}'", s),
1871        }
1872    }
1873}
1874
1875/// Boolean literal
1876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1877#[cfg_attr(feature = "bindings", derive(TS))]
1878pub struct BooleanLiteral {
1879    pub value: bool,
1880}
1881
1882/// NULL literal
1883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1884#[cfg_attr(feature = "bindings", derive(TS))]
1885pub struct Null;
1886
1887/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1888///
1889/// The `quoted` flag indicates whether the identifier was originally delimited
1890/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1891/// dialect). The generator uses this flag to decide whether to emit quoting
1892/// characters.
1893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1894#[cfg_attr(feature = "bindings", derive(TS))]
1895pub struct Identifier {
1896    /// The raw text of the identifier, without any quoting characters.
1897    pub name: String,
1898    /// Whether the identifier was quoted in the source SQL.
1899    pub quoted: bool,
1900    #[serde(default)]
1901    pub trailing_comments: Vec<String>,
1902    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1903    #[serde(default, skip_serializing_if = "Option::is_none")]
1904    pub span: Option<Span>,
1905}
1906
1907impl Identifier {
1908    pub fn new(name: impl Into<String>) -> Self {
1909        Self {
1910            name: name.into(),
1911            quoted: false,
1912            trailing_comments: Vec::new(),
1913            span: None,
1914        }
1915    }
1916
1917    pub fn quoted(name: impl Into<String>) -> Self {
1918        Self {
1919            name: name.into(),
1920            quoted: true,
1921            trailing_comments: Vec::new(),
1922            span: None,
1923        }
1924    }
1925
1926    pub fn empty() -> Self {
1927        Self {
1928            name: String::new(),
1929            quoted: false,
1930            trailing_comments: Vec::new(),
1931            span: None,
1932        }
1933    }
1934
1935    pub fn is_empty(&self) -> bool {
1936        self.name.is_empty()
1937    }
1938
1939    /// Set the source span on this identifier
1940    pub fn with_span(mut self, span: Span) -> Self {
1941        self.span = Some(span);
1942        self
1943    }
1944}
1945
1946impl fmt::Display for Identifier {
1947    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1948        if self.quoted {
1949            write!(f, "\"{}\"", self.name)
1950        } else {
1951            write!(f, "{}", self.name)
1952        }
1953    }
1954}
1955
1956/// Represent a column reference, optionally qualified by a table name.
1957///
1958/// Renders as `name` when unqualified, or `table.name` when qualified.
1959/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1960/// convenient construction.
1961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1962#[cfg_attr(feature = "bindings", derive(TS))]
1963pub struct Column {
1964    /// The column name.
1965    pub name: Identifier,
1966    /// Optional table qualifier (e.g. `t` in `t.col`).
1967    pub table: Option<Identifier>,
1968    /// Oracle-style join marker (+) for outer joins
1969    #[serde(default)]
1970    pub join_mark: bool,
1971    /// Trailing comments that appeared after this column reference
1972    #[serde(default)]
1973    pub trailing_comments: Vec<String>,
1974    /// Source position span
1975    #[serde(default, skip_serializing_if = "Option::is_none")]
1976    pub span: Option<Span>,
1977    /// Inferred data type from type annotation
1978    #[serde(default, skip_serializing_if = "Option::is_none")]
1979    pub inferred_type: Option<DataType>,
1980}
1981
1982impl fmt::Display for Column {
1983    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1984        if let Some(table) = &self.table {
1985            write!(f, "{}.{}", table, self.name)
1986        } else {
1987            write!(f, "{}", self.name)
1988        }
1989    }
1990}
1991
1992/// Represent a table reference with optional schema and catalog qualifiers.
1993///
1994/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1995/// which qualifiers are present. Supports aliases, column alias lists,
1996/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1997/// several other dialect-specific extensions.
1998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1999#[cfg_attr(feature = "bindings", derive(TS))]
2000pub struct TableRef {
2001    /// The unqualified table name.
2002    pub name: Identifier,
2003    /// Optional schema qualifier (e.g. `public` in `public.users`).
2004    pub schema: Option<Identifier>,
2005    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
2006    pub catalog: Option<Identifier>,
2007    /// Optional table alias (e.g. `t` in `FROM users AS t`).
2008    pub alias: Option<Identifier>,
2009    /// Whether AS keyword was explicitly used for the alias
2010    #[serde(default)]
2011    pub alias_explicit_as: bool,
2012    /// Column aliases for table alias: AS t(c1, c2)
2013    #[serde(default)]
2014    pub column_aliases: Vec<Identifier>,
2015    /// Trailing comments that appeared after this table reference
2016    #[serde(default)]
2017    pub trailing_comments: Vec<String>,
2018    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2019    #[serde(default)]
2020    pub when: Option<Box<HistoricalData>>,
2021    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
2022    #[serde(default)]
2023    pub only: bool,
2024    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
2025    #[serde(default)]
2026    pub final_: bool,
2027    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
2028    #[serde(default, skip_serializing_if = "Option::is_none")]
2029    pub table_sample: Option<Box<Sample>>,
2030    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
2031    #[serde(default)]
2032    pub hints: Vec<Expression>,
2033    /// TSQL: FOR SYSTEM_TIME temporal clause
2034    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
2035    #[serde(default, skip_serializing_if = "Option::is_none")]
2036    pub system_time: Option<String>,
2037    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
2038    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2039    pub partitions: Vec<Identifier>,
2040    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
2041    /// When set, this is used instead of the name field
2042    #[serde(default, skip_serializing_if = "Option::is_none")]
2043    pub identifier_func: Option<Box<Expression>>,
2044    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
2045    #[serde(default, skip_serializing_if = "Option::is_none")]
2046    pub changes: Option<Box<Changes>>,
2047    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
2048    #[serde(default, skip_serializing_if = "Option::is_none")]
2049    pub version: Option<Box<Version>>,
2050    /// Source position span
2051    #[serde(default, skip_serializing_if = "Option::is_none")]
2052    pub span: Option<Span>,
2053}
2054
2055impl TableRef {
2056    pub fn new(name: impl Into<String>) -> Self {
2057        Self {
2058            name: Identifier::new(name),
2059            schema: None,
2060            catalog: None,
2061            alias: None,
2062            alias_explicit_as: false,
2063            column_aliases: Vec::new(),
2064            trailing_comments: Vec::new(),
2065            when: None,
2066            only: false,
2067            final_: false,
2068            table_sample: None,
2069            hints: Vec::new(),
2070            system_time: None,
2071            partitions: Vec::new(),
2072            identifier_func: None,
2073            changes: None,
2074            version: None,
2075            span: None,
2076        }
2077    }
2078
2079    /// Create with a schema qualifier.
2080    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
2081        let mut t = Self::new(name);
2082        t.schema = Some(Identifier::new(schema));
2083        t
2084    }
2085
2086    /// Create with catalog and schema qualifiers.
2087    pub fn new_with_catalog(
2088        name: impl Into<String>,
2089        schema: impl Into<String>,
2090        catalog: impl Into<String>,
2091    ) -> Self {
2092        let mut t = Self::new(name);
2093        t.schema = Some(Identifier::new(schema));
2094        t.catalog = Some(Identifier::new(catalog));
2095        t
2096    }
2097
2098    /// Create from an Identifier, preserving the quoted flag
2099    pub fn from_identifier(name: Identifier) -> Self {
2100        Self {
2101            name,
2102            schema: None,
2103            catalog: None,
2104            alias: None,
2105            alias_explicit_as: false,
2106            column_aliases: Vec::new(),
2107            trailing_comments: Vec::new(),
2108            when: None,
2109            only: false,
2110            final_: false,
2111            table_sample: None,
2112            hints: Vec::new(),
2113            system_time: None,
2114            partitions: Vec::new(),
2115            identifier_func: None,
2116            changes: None,
2117            version: None,
2118            span: None,
2119        }
2120    }
2121
2122    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
2123        self.alias = Some(Identifier::new(alias));
2124        self
2125    }
2126
2127    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
2128        self.schema = Some(Identifier::new(schema));
2129        self
2130    }
2131}
2132
2133/// Represent a wildcard star expression (`*`, `table.*`).
2134///
2135/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
2136/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
2137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2138#[cfg_attr(feature = "bindings", derive(TS))]
2139pub struct Star {
2140    /// Optional table qualifier (e.g. `t` in `t.*`).
2141    pub table: Option<Identifier>,
2142    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
2143    pub except: Option<Vec<Identifier>>,
2144    /// REPLACE expressions (BigQuery, Snowflake)
2145    pub replace: Option<Vec<Alias>>,
2146    /// RENAME columns (Snowflake)
2147    pub rename: Option<Vec<(Identifier, Identifier)>>,
2148    /// Trailing comments that appeared after the star
2149    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2150    pub trailing_comments: Vec<String>,
2151    /// Source position span
2152    #[serde(default, skip_serializing_if = "Option::is_none")]
2153    pub span: Option<Span>,
2154}
2155
2156/// Represent a complete SELECT statement.
2157///
2158/// This is the most feature-rich AST node, covering the full surface area of
2159/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
2160/// `Vec` are omitted from the generated SQL when absent.
2161///
2162/// # Key Fields
2163///
2164/// - `expressions` -- the select-list (columns, `*`, computed expressions).
2165/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
2166/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
2167/// - `where_clause` -- the WHERE predicate.
2168/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
2169/// - `having` -- HAVING predicate.
2170/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
2171/// - `limit` / `offset` / `fetch` -- result set limiting.
2172/// - `with` -- Common Table Expressions (CTEs).
2173/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
2174/// - `windows` -- named window definitions (WINDOW w AS ...).
2175///
2176/// Dialect-specific extensions are supported via fields like `prewhere`
2177/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
2178/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
2179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2180#[cfg_attr(feature = "bindings", derive(TS))]
2181pub struct Select {
2182    /// The select-list: columns, expressions, aliases, and wildcards.
2183    pub expressions: Vec<Expression>,
2184    /// The FROM clause, containing one or more table sources.
2185    pub from: Option<From>,
2186    /// JOIN clauses applied after the FROM source.
2187    pub joins: Vec<Join>,
2188    pub lateral_views: Vec<LateralView>,
2189    /// ClickHouse PREWHERE clause
2190    #[serde(default, skip_serializing_if = "Option::is_none")]
2191    pub prewhere: Option<Expression>,
2192    pub where_clause: Option<Where>,
2193    pub group_by: Option<GroupBy>,
2194    pub having: Option<Having>,
2195    pub qualify: Option<Qualify>,
2196    pub order_by: Option<OrderBy>,
2197    pub distribute_by: Option<DistributeBy>,
2198    pub cluster_by: Option<ClusterBy>,
2199    pub sort_by: Option<SortBy>,
2200    pub limit: Option<Limit>,
2201    pub offset: Option<Offset>,
2202    /// ClickHouse LIMIT BY clause expressions
2203    #[serde(default, skip_serializing_if = "Option::is_none")]
2204    pub limit_by: Option<Vec<Expression>>,
2205    pub fetch: Option<Fetch>,
2206    pub distinct: bool,
2207    pub distinct_on: Option<Vec<Expression>>,
2208    pub top: Option<Top>,
2209    pub with: Option<With>,
2210    pub sample: Option<Sample>,
2211    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
2212    #[serde(default, skip_serializing_if = "Option::is_none")]
2213    pub settings: Option<Vec<Expression>>,
2214    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
2215    #[serde(default, skip_serializing_if = "Option::is_none")]
2216    pub format: Option<Expression>,
2217    pub windows: Option<Vec<NamedWindow>>,
2218    pub hint: Option<Hint>,
2219    /// Oracle CONNECT BY clause for hierarchical queries
2220    pub connect: Option<Connect>,
2221    /// SELECT ... INTO table_name for creating tables
2222    pub into: Option<SelectInto>,
2223    /// FOR UPDATE/SHARE locking clauses
2224    #[serde(default)]
2225    pub locks: Vec<Lock>,
2226    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
2227    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2228    pub for_xml: Vec<Expression>,
2229    /// Leading comments before the statement
2230    #[serde(default)]
2231    pub leading_comments: Vec<String>,
2232    /// Comments that appear after SELECT keyword (before expressions)
2233    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
2234    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2235    pub post_select_comments: Vec<String>,
2236    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
2237    #[serde(default, skip_serializing_if = "Option::is_none")]
2238    pub kind: Option<String>,
2239    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
2240    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2241    pub operation_modifiers: Vec<String>,
2242    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
2243    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2244    pub qualify_after_window: bool,
2245    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
2246    #[serde(default, skip_serializing_if = "Option::is_none")]
2247    pub option: Option<String>,
2248    /// Redshift-style EXCLUDE clause at the end of the projection list
2249    /// e.g., SELECT *, 4 AS col4 EXCLUDE (col2, col3) FROM ...
2250    #[serde(default, skip_serializing_if = "Option::is_none")]
2251    pub exclude: Option<Vec<Expression>>,
2252}
2253
2254impl Select {
2255    pub fn new() -> Self {
2256        Self {
2257            expressions: Vec::new(),
2258            from: None,
2259            joins: Vec::new(),
2260            lateral_views: Vec::new(),
2261            prewhere: None,
2262            where_clause: None,
2263            group_by: None,
2264            having: None,
2265            qualify: None,
2266            order_by: None,
2267            distribute_by: None,
2268            cluster_by: None,
2269            sort_by: None,
2270            limit: None,
2271            offset: None,
2272            limit_by: None,
2273            fetch: None,
2274            distinct: false,
2275            distinct_on: None,
2276            top: None,
2277            with: None,
2278            sample: None,
2279            settings: None,
2280            format: None,
2281            windows: None,
2282            hint: None,
2283            connect: None,
2284            into: None,
2285            locks: Vec::new(),
2286            for_xml: Vec::new(),
2287            leading_comments: Vec::new(),
2288            post_select_comments: Vec::new(),
2289            kind: None,
2290            operation_modifiers: Vec::new(),
2291            qualify_after_window: false,
2292            option: None,
2293            exclude: None,
2294        }
2295    }
2296
2297    /// Add a column to select
2298    pub fn column(mut self, expr: Expression) -> Self {
2299        self.expressions.push(expr);
2300        self
2301    }
2302
2303    /// Set the FROM clause
2304    pub fn from(mut self, table: Expression) -> Self {
2305        self.from = Some(From {
2306            expressions: vec![table],
2307        });
2308        self
2309    }
2310
2311    /// Add a WHERE clause
2312    pub fn where_(mut self, condition: Expression) -> Self {
2313        self.where_clause = Some(Where { this: condition });
2314        self
2315    }
2316
2317    /// Set DISTINCT
2318    pub fn distinct(mut self) -> Self {
2319        self.distinct = true;
2320        self
2321    }
2322
2323    /// Add a JOIN
2324    pub fn join(mut self, join: Join) -> Self {
2325        self.joins.push(join);
2326        self
2327    }
2328
2329    /// Set ORDER BY
2330    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
2331        self.order_by = Some(OrderBy {
2332            expressions,
2333            siblings: false,
2334            comments: Vec::new(),
2335        });
2336        self
2337    }
2338
2339    /// Set LIMIT
2340    pub fn limit(mut self, n: Expression) -> Self {
2341        self.limit = Some(Limit {
2342            this: n,
2343            percent: false,
2344            comments: Vec::new(),
2345        });
2346        self
2347    }
2348
2349    /// Set OFFSET
2350    pub fn offset(mut self, n: Expression) -> Self {
2351        self.offset = Some(Offset {
2352            this: n,
2353            rows: None,
2354        });
2355        self
2356    }
2357}
2358
2359impl Default for Select {
2360    fn default() -> Self {
2361        Self::new()
2362    }
2363}
2364
2365/// Represent a UNION set operation between two query expressions.
2366///
2367/// When `all` is true, duplicate rows are preserved (UNION ALL).
2368/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
2369/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
2370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2371#[cfg_attr(feature = "bindings", derive(TS))]
2372pub struct Union {
2373    /// The left-hand query operand.
2374    pub left: Expression,
2375    /// The right-hand query operand.
2376    pub right: Expression,
2377    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
2378    pub all: bool,
2379    /// Whether DISTINCT was explicitly specified
2380    #[serde(default)]
2381    pub distinct: bool,
2382    /// Optional WITH clause
2383    pub with: Option<With>,
2384    /// ORDER BY applied to entire UNION result
2385    pub order_by: Option<OrderBy>,
2386    /// LIMIT applied to entire UNION result
2387    pub limit: Option<Box<Expression>>,
2388    /// OFFSET applied to entire UNION result
2389    pub offset: Option<Box<Expression>>,
2390    /// DISTRIBUTE BY clause (Hive/Spark)
2391    #[serde(default, skip_serializing_if = "Option::is_none")]
2392    pub distribute_by: Option<DistributeBy>,
2393    /// SORT BY clause (Hive/Spark)
2394    #[serde(default, skip_serializing_if = "Option::is_none")]
2395    pub sort_by: Option<SortBy>,
2396    /// CLUSTER BY clause (Hive/Spark)
2397    #[serde(default, skip_serializing_if = "Option::is_none")]
2398    pub cluster_by: Option<ClusterBy>,
2399    /// DuckDB BY NAME modifier
2400    #[serde(default)]
2401    pub by_name: bool,
2402    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2403    #[serde(default, skip_serializing_if = "Option::is_none")]
2404    pub side: Option<String>,
2405    /// BigQuery: Set operation kind (INNER)
2406    #[serde(default, skip_serializing_if = "Option::is_none")]
2407    pub kind: Option<String>,
2408    /// BigQuery: CORRESPONDING modifier
2409    #[serde(default)]
2410    pub corresponding: bool,
2411    /// BigQuery: STRICT modifier (before CORRESPONDING)
2412    #[serde(default)]
2413    pub strict: bool,
2414    /// BigQuery: BY (columns) after CORRESPONDING
2415    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2416    pub on_columns: Vec<Expression>,
2417}
2418
2419/// Represent an INTERSECT set operation between two query expressions.
2420///
2421/// Returns only rows that appear in both operands. When `all` is true,
2422/// duplicates are preserved according to their multiplicity.
2423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2424#[cfg_attr(feature = "bindings", derive(TS))]
2425pub struct Intersect {
2426    /// The left-hand query operand.
2427    pub left: Expression,
2428    /// The right-hand query operand.
2429    pub right: Expression,
2430    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
2431    pub all: bool,
2432    /// Whether DISTINCT was explicitly specified
2433    #[serde(default)]
2434    pub distinct: bool,
2435    /// Optional WITH clause
2436    pub with: Option<With>,
2437    /// ORDER BY applied to entire INTERSECT result
2438    pub order_by: Option<OrderBy>,
2439    /// LIMIT applied to entire INTERSECT result
2440    pub limit: Option<Box<Expression>>,
2441    /// OFFSET applied to entire INTERSECT result
2442    pub offset: Option<Box<Expression>>,
2443    /// DISTRIBUTE BY clause (Hive/Spark)
2444    #[serde(default, skip_serializing_if = "Option::is_none")]
2445    pub distribute_by: Option<DistributeBy>,
2446    /// SORT BY clause (Hive/Spark)
2447    #[serde(default, skip_serializing_if = "Option::is_none")]
2448    pub sort_by: Option<SortBy>,
2449    /// CLUSTER BY clause (Hive/Spark)
2450    #[serde(default, skip_serializing_if = "Option::is_none")]
2451    pub cluster_by: Option<ClusterBy>,
2452    /// DuckDB BY NAME modifier
2453    #[serde(default)]
2454    pub by_name: bool,
2455    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2456    #[serde(default, skip_serializing_if = "Option::is_none")]
2457    pub side: Option<String>,
2458    /// BigQuery: Set operation kind (INNER)
2459    #[serde(default, skip_serializing_if = "Option::is_none")]
2460    pub kind: Option<String>,
2461    /// BigQuery: CORRESPONDING modifier
2462    #[serde(default)]
2463    pub corresponding: bool,
2464    /// BigQuery: STRICT modifier (before CORRESPONDING)
2465    #[serde(default)]
2466    pub strict: bool,
2467    /// BigQuery: BY (columns) after CORRESPONDING
2468    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2469    pub on_columns: Vec<Expression>,
2470}
2471
2472/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2473///
2474/// Returns rows from the left operand that do not appear in the right operand.
2475/// When `all` is true, duplicates are subtracted according to their multiplicity.
2476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2477#[cfg_attr(feature = "bindings", derive(TS))]
2478pub struct Except {
2479    /// The left-hand query operand.
2480    pub left: Expression,
2481    /// The right-hand query operand (rows to subtract).
2482    pub right: Expression,
2483    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2484    pub all: bool,
2485    /// Whether DISTINCT was explicitly specified
2486    #[serde(default)]
2487    pub distinct: bool,
2488    /// Optional WITH clause
2489    pub with: Option<With>,
2490    /// ORDER BY applied to entire EXCEPT result
2491    pub order_by: Option<OrderBy>,
2492    /// LIMIT applied to entire EXCEPT result
2493    pub limit: Option<Box<Expression>>,
2494    /// OFFSET applied to entire EXCEPT result
2495    pub offset: Option<Box<Expression>>,
2496    /// DISTRIBUTE BY clause (Hive/Spark)
2497    #[serde(default, skip_serializing_if = "Option::is_none")]
2498    pub distribute_by: Option<DistributeBy>,
2499    /// SORT BY clause (Hive/Spark)
2500    #[serde(default, skip_serializing_if = "Option::is_none")]
2501    pub sort_by: Option<SortBy>,
2502    /// CLUSTER BY clause (Hive/Spark)
2503    #[serde(default, skip_serializing_if = "Option::is_none")]
2504    pub cluster_by: Option<ClusterBy>,
2505    /// DuckDB BY NAME modifier
2506    #[serde(default)]
2507    pub by_name: bool,
2508    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2509    #[serde(default, skip_serializing_if = "Option::is_none")]
2510    pub side: Option<String>,
2511    /// BigQuery: Set operation kind (INNER)
2512    #[serde(default, skip_serializing_if = "Option::is_none")]
2513    pub kind: Option<String>,
2514    /// BigQuery: CORRESPONDING modifier
2515    #[serde(default)]
2516    pub corresponding: bool,
2517    /// BigQuery: STRICT modifier (before CORRESPONDING)
2518    #[serde(default)]
2519    pub strict: bool,
2520    /// BigQuery: BY (columns) after CORRESPONDING
2521    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2522    pub on_columns: Vec<Expression>,
2523}
2524
2525/// INTO clause for SELECT INTO statements
2526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2527#[cfg_attr(feature = "bindings", derive(TS))]
2528pub struct SelectInto {
2529    /// Target table or variable (used when single target)
2530    pub this: Expression,
2531    /// Whether TEMPORARY keyword was used
2532    #[serde(default)]
2533    pub temporary: bool,
2534    /// Whether UNLOGGED keyword was used (PostgreSQL)
2535    #[serde(default)]
2536    pub unlogged: bool,
2537    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2538    #[serde(default)]
2539    pub bulk_collect: bool,
2540    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2541    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2542    pub expressions: Vec<Expression>,
2543}
2544
2545/// Represent a parenthesized subquery expression.
2546///
2547/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2548/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2549/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2550/// modifiers are rendered inside or outside the parentheses.
2551///
2552/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2553/// scalar subqueries in select-lists, and derived tables.
2554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2555#[cfg_attr(feature = "bindings", derive(TS))]
2556pub struct Subquery {
2557    /// The inner query expression.
2558    pub this: Expression,
2559    /// Optional alias for the derived table.
2560    pub alias: Option<Identifier>,
2561    /// Optional column aliases: AS t(c1, c2)
2562    pub column_aliases: Vec<Identifier>,
2563    /// ORDER BY clause (for parenthesized queries)
2564    pub order_by: Option<OrderBy>,
2565    /// LIMIT clause
2566    pub limit: Option<Limit>,
2567    /// OFFSET clause
2568    pub offset: Option<Offset>,
2569    /// DISTRIBUTE BY clause (Hive/Spark)
2570    #[serde(default, skip_serializing_if = "Option::is_none")]
2571    pub distribute_by: Option<DistributeBy>,
2572    /// SORT BY clause (Hive/Spark)
2573    #[serde(default, skip_serializing_if = "Option::is_none")]
2574    pub sort_by: Option<SortBy>,
2575    /// CLUSTER BY clause (Hive/Spark)
2576    #[serde(default, skip_serializing_if = "Option::is_none")]
2577    pub cluster_by: Option<ClusterBy>,
2578    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2579    #[serde(default)]
2580    pub lateral: bool,
2581    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2582    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2583    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2584    #[serde(default)]
2585    pub modifiers_inside: bool,
2586    /// Trailing comments after the closing paren
2587    #[serde(default)]
2588    pub trailing_comments: Vec<String>,
2589    /// Inferred data type from type annotation
2590    #[serde(default, skip_serializing_if = "Option::is_none")]
2591    pub inferred_type: Option<DataType>,
2592}
2593
2594/// Pipe operator expression: query |> transform
2595///
2596/// Used in DataFusion and BigQuery pipe syntax:
2597///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2599#[cfg_attr(feature = "bindings", derive(TS))]
2600pub struct PipeOperator {
2601    /// The input query/expression (left side of |>)
2602    pub this: Expression,
2603    /// The piped operation (right side of |>)
2604    pub expression: Expression,
2605}
2606
2607/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2609#[cfg_attr(feature = "bindings", derive(TS))]
2610pub struct Values {
2611    /// The rows of values
2612    pub expressions: Vec<Tuple>,
2613    /// Optional alias for the table
2614    pub alias: Option<Identifier>,
2615    /// Optional column aliases: AS t(c1, c2)
2616    pub column_aliases: Vec<Identifier>,
2617}
2618
2619/// PIVOT operation - supports both standard and DuckDB simplified syntax
2620///
2621/// Standard syntax (in FROM clause):
2622///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2623///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2624///
2625/// DuckDB simplified syntax (statement-level):
2626///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2627///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2629#[cfg_attr(feature = "bindings", derive(TS))]
2630pub struct Pivot {
2631    /// Source table/expression
2632    pub this: Expression,
2633    /// For standard PIVOT: the aggregation function(s) (first is primary)
2634    /// For DuckDB simplified: unused (use `using` instead)
2635    #[serde(default)]
2636    pub expressions: Vec<Expression>,
2637    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2638    #[serde(default)]
2639    pub fields: Vec<Expression>,
2640    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2641    #[serde(default)]
2642    pub using: Vec<Expression>,
2643    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2644    #[serde(default)]
2645    pub group: Option<Box<Expression>>,
2646    /// Whether this is an UNPIVOT (vs PIVOT)
2647    #[serde(default)]
2648    pub unpivot: bool,
2649    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2650    #[serde(default)]
2651    pub into: Option<Box<Expression>>,
2652    /// Optional alias
2653    #[serde(default)]
2654    pub alias: Option<Identifier>,
2655    /// Include/exclude nulls (for UNPIVOT)
2656    #[serde(default)]
2657    pub include_nulls: Option<bool>,
2658    /// Default on null value (Snowflake)
2659    #[serde(default)]
2660    pub default_on_null: Option<Box<Expression>>,
2661    /// WITH clause (CTEs)
2662    #[serde(default, skip_serializing_if = "Option::is_none")]
2663    pub with: Option<With>,
2664}
2665
2666/// UNPIVOT operation
2667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2668#[cfg_attr(feature = "bindings", derive(TS))]
2669pub struct Unpivot {
2670    pub this: Expression,
2671    pub value_column: Identifier,
2672    pub name_column: Identifier,
2673    pub columns: Vec<Expression>,
2674    pub alias: Option<Identifier>,
2675    /// Whether the value_column was parenthesized in the original SQL
2676    #[serde(default)]
2677    pub value_column_parenthesized: bool,
2678    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2679    #[serde(default)]
2680    pub include_nulls: Option<bool>,
2681    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2682    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2683    pub extra_value_columns: Vec<Identifier>,
2684}
2685
2686/// PIVOT alias for aliasing pivot expressions
2687/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2689#[cfg_attr(feature = "bindings", derive(TS))]
2690pub struct PivotAlias {
2691    pub this: Expression,
2692    pub alias: Expression,
2693}
2694
2695/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2696#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2697#[cfg_attr(feature = "bindings", derive(TS))]
2698pub struct PreWhere {
2699    pub this: Expression,
2700}
2701
2702/// STREAM definition (Snowflake) - for change data capture
2703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2704#[cfg_attr(feature = "bindings", derive(TS))]
2705pub struct Stream {
2706    pub this: Expression,
2707    #[serde(skip_serializing_if = "Option::is_none")]
2708    pub on: Option<Expression>,
2709    #[serde(skip_serializing_if = "Option::is_none")]
2710    pub show_initial_rows: Option<bool>,
2711}
2712
2713/// USING DATA clause for data import statements
2714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2715#[cfg_attr(feature = "bindings", derive(TS))]
2716pub struct UsingData {
2717    pub this: Expression,
2718}
2719
2720/// XML Namespace declaration
2721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2722#[cfg_attr(feature = "bindings", derive(TS))]
2723pub struct XmlNamespace {
2724    pub this: Expression,
2725    #[serde(skip_serializing_if = "Option::is_none")]
2726    pub alias: Option<Identifier>,
2727}
2728
2729/// ROW FORMAT clause for Hive/Spark
2730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2731#[cfg_attr(feature = "bindings", derive(TS))]
2732pub struct RowFormat {
2733    pub delimited: bool,
2734    pub fields_terminated_by: Option<String>,
2735    pub collection_items_terminated_by: Option<String>,
2736    pub map_keys_terminated_by: Option<String>,
2737    pub lines_terminated_by: Option<String>,
2738    pub null_defined_as: Option<String>,
2739}
2740
2741/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2743#[cfg_attr(feature = "bindings", derive(TS))]
2744pub struct DirectoryInsert {
2745    pub local: bool,
2746    pub path: String,
2747    pub row_format: Option<RowFormat>,
2748    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2749    #[serde(default)]
2750    pub stored_as: Option<String>,
2751}
2752
2753/// INSERT statement
2754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2755#[cfg_attr(feature = "bindings", derive(TS))]
2756pub struct Insert {
2757    pub table: TableRef,
2758    pub columns: Vec<Identifier>,
2759    pub values: Vec<Vec<Expression>>,
2760    pub query: Option<Expression>,
2761    /// INSERT OVERWRITE for Hive/Spark
2762    pub overwrite: bool,
2763    /// PARTITION clause for Hive/Spark
2764    pub partition: Vec<(Identifier, Option<Expression>)>,
2765    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2766    #[serde(default)]
2767    pub directory: Option<DirectoryInsert>,
2768    /// RETURNING clause (PostgreSQL, SQLite)
2769    #[serde(default)]
2770    pub returning: Vec<Expression>,
2771    /// OUTPUT clause (TSQL)
2772    #[serde(default)]
2773    pub output: Option<OutputClause>,
2774    /// ON CONFLICT clause (PostgreSQL, SQLite)
2775    #[serde(default)]
2776    pub on_conflict: Option<Box<Expression>>,
2777    /// Leading comments before the statement
2778    #[serde(default)]
2779    pub leading_comments: Vec<String>,
2780    /// IF EXISTS clause (Hive)
2781    #[serde(default)]
2782    pub if_exists: bool,
2783    /// WITH clause (CTEs)
2784    #[serde(default)]
2785    pub with: Option<With>,
2786    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2787    #[serde(default)]
2788    pub ignore: bool,
2789    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2790    #[serde(default)]
2791    pub source_alias: Option<Identifier>,
2792    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2793    #[serde(default)]
2794    pub alias: Option<Identifier>,
2795    /// Whether the alias uses explicit AS keyword
2796    #[serde(default)]
2797    pub alias_explicit_as: bool,
2798    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2799    #[serde(default)]
2800    pub default_values: bool,
2801    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2802    #[serde(default)]
2803    pub by_name: bool,
2804    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2805    #[serde(default, skip_serializing_if = "Option::is_none")]
2806    pub conflict_action: Option<String>,
2807    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2808    #[serde(default)]
2809    pub is_replace: bool,
2810    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2811    #[serde(default, skip_serializing_if = "Option::is_none")]
2812    pub hint: Option<Hint>,
2813    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2814    #[serde(default)]
2815    pub replace_where: Option<Box<Expression>>,
2816    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2817    #[serde(default)]
2818    pub source: Option<Box<Expression>>,
2819    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2820    #[serde(default, skip_serializing_if = "Option::is_none")]
2821    pub function_target: Option<Box<Expression>>,
2822    /// ClickHouse: PARTITION BY expr
2823    #[serde(default, skip_serializing_if = "Option::is_none")]
2824    pub partition_by: Option<Box<Expression>>,
2825    /// ClickHouse: SETTINGS key = val, ...
2826    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2827    pub settings: Vec<Expression>,
2828}
2829
2830/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2832#[cfg_attr(feature = "bindings", derive(TS))]
2833pub struct OutputClause {
2834    /// Columns/expressions to output
2835    pub columns: Vec<Expression>,
2836    /// Optional INTO target table or table variable
2837    #[serde(default)]
2838    pub into_table: Option<Expression>,
2839}
2840
2841/// UPDATE statement
2842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2843#[cfg_attr(feature = "bindings", derive(TS))]
2844pub struct Update {
2845    pub table: TableRef,
2846    /// Additional tables for multi-table UPDATE (MySQL syntax)
2847    #[serde(default)]
2848    pub extra_tables: Vec<TableRef>,
2849    /// JOINs attached to the table list (MySQL multi-table syntax)
2850    #[serde(default)]
2851    pub table_joins: Vec<Join>,
2852    pub set: Vec<(Identifier, Expression)>,
2853    pub from_clause: Option<From>,
2854    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2855    #[serde(default)]
2856    pub from_joins: Vec<Join>,
2857    pub where_clause: Option<Where>,
2858    /// RETURNING clause (PostgreSQL, SQLite)
2859    #[serde(default)]
2860    pub returning: Vec<Expression>,
2861    /// OUTPUT clause (TSQL)
2862    #[serde(default)]
2863    pub output: Option<OutputClause>,
2864    /// WITH clause (CTEs)
2865    #[serde(default)]
2866    pub with: Option<With>,
2867    /// Leading comments before the statement
2868    #[serde(default)]
2869    pub leading_comments: Vec<String>,
2870    /// LIMIT clause (MySQL)
2871    #[serde(default)]
2872    pub limit: Option<Expression>,
2873    /// ORDER BY clause (MySQL)
2874    #[serde(default)]
2875    pub order_by: Option<OrderBy>,
2876    /// Whether FROM clause appears before SET (Snowflake syntax)
2877    #[serde(default)]
2878    pub from_before_set: bool,
2879}
2880
2881/// DELETE statement
2882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2883#[cfg_attr(feature = "bindings", derive(TS))]
2884pub struct Delete {
2885    pub table: TableRef,
2886    /// ClickHouse: ON CLUSTER clause for distributed DDL
2887    #[serde(default, skip_serializing_if = "Option::is_none")]
2888    pub on_cluster: Option<OnCluster>,
2889    /// Optional alias for the table
2890    pub alias: Option<Identifier>,
2891    /// Whether the alias was declared with explicit AS keyword
2892    #[serde(default)]
2893    pub alias_explicit_as: bool,
2894    /// PostgreSQL/DuckDB USING clause - additional tables to join
2895    pub using: Vec<TableRef>,
2896    pub where_clause: Option<Where>,
2897    /// OUTPUT clause (TSQL)
2898    #[serde(default)]
2899    pub output: Option<OutputClause>,
2900    /// Leading comments before the statement
2901    #[serde(default)]
2902    pub leading_comments: Vec<String>,
2903    /// WITH clause (CTEs)
2904    #[serde(default)]
2905    pub with: Option<With>,
2906    /// LIMIT clause (MySQL)
2907    #[serde(default)]
2908    pub limit: Option<Expression>,
2909    /// ORDER BY clause (MySQL)
2910    #[serde(default)]
2911    pub order_by: Option<OrderBy>,
2912    /// RETURNING clause (PostgreSQL)
2913    #[serde(default)]
2914    pub returning: Vec<Expression>,
2915    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2916    /// These are the target tables to delete from
2917    #[serde(default)]
2918    pub tables: Vec<TableRef>,
2919    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2920    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2921    #[serde(default)]
2922    pub tables_from_using: bool,
2923    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2924    #[serde(default)]
2925    pub joins: Vec<Join>,
2926    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2927    #[serde(default)]
2928    pub force_index: Option<String>,
2929    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2930    #[serde(default)]
2931    pub no_from: bool,
2932}
2933
2934/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2936#[cfg_attr(feature = "bindings", derive(TS))]
2937pub struct CopyStmt {
2938    /// Target table or query
2939    pub this: Expression,
2940    /// True for FROM (loading into table), false for TO (exporting)
2941    pub kind: bool,
2942    /// Source/destination file(s) or stage
2943    pub files: Vec<Expression>,
2944    /// Copy parameters
2945    #[serde(default)]
2946    pub params: Vec<CopyParameter>,
2947    /// Credentials for external access
2948    #[serde(default)]
2949    pub credentials: Option<Box<Credentials>>,
2950    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2951    #[serde(default)]
2952    pub is_into: bool,
2953    /// Whether parameters are wrapped in WITH (...) syntax
2954    #[serde(default)]
2955    pub with_wrapped: bool,
2956}
2957
2958/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2960#[cfg_attr(feature = "bindings", derive(TS))]
2961pub struct CopyParameter {
2962    pub name: String,
2963    pub value: Option<Expression>,
2964    pub values: Vec<Expression>,
2965    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2966    #[serde(default)]
2967    pub eq: bool,
2968}
2969
2970/// Credentials for external access (S3, Azure, etc.)
2971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2972#[cfg_attr(feature = "bindings", derive(TS))]
2973pub struct Credentials {
2974    pub credentials: Vec<(String, String)>,
2975    pub encryption: Option<String>,
2976    pub storage: Option<String>,
2977}
2978
2979/// PUT statement (Snowflake)
2980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2981#[cfg_attr(feature = "bindings", derive(TS))]
2982pub struct PutStmt {
2983    /// Source file path
2984    pub source: String,
2985    /// Whether source was quoted in the original SQL
2986    #[serde(default)]
2987    pub source_quoted: bool,
2988    /// Target stage
2989    pub target: Expression,
2990    /// PUT parameters
2991    #[serde(default)]
2992    pub params: Vec<CopyParameter>,
2993}
2994
2995/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2997#[cfg_attr(feature = "bindings", derive(TS))]
2998pub struct StageReference {
2999    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
3000    pub name: String,
3001    /// Optional path within the stage (e.g., "/path/to/file.csv")
3002    #[serde(default)]
3003    pub path: Option<String>,
3004    /// Optional FILE_FORMAT parameter
3005    #[serde(default)]
3006    pub file_format: Option<Expression>,
3007    /// Optional PATTERN parameter
3008    #[serde(default)]
3009    pub pattern: Option<String>,
3010    /// Whether the stage reference was originally quoted (e.g., '@mystage')
3011    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3012    pub quoted: bool,
3013}
3014
3015/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
3016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3017#[cfg_attr(feature = "bindings", derive(TS))]
3018pub struct HistoricalData {
3019    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
3020    pub this: Box<Expression>,
3021    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
3022    pub kind: String,
3023    /// The expression value (e.g., the statement ID or timestamp)
3024    pub expression: Box<Expression>,
3025}
3026
3027/// Represent an aliased expression (`expr AS name`).
3028///
3029/// Used for column aliases in select-lists, table aliases on subqueries,
3030/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
3031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3032#[cfg_attr(feature = "bindings", derive(TS))]
3033pub struct Alias {
3034    /// The expression being aliased.
3035    pub this: Expression,
3036    /// The alias name (required for simple aliases, optional when only column aliases provided)
3037    pub alias: Identifier,
3038    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
3039    #[serde(default)]
3040    pub column_aliases: Vec<Identifier>,
3041    /// Comments that appeared between the expression and AS keyword
3042    #[serde(default)]
3043    pub pre_alias_comments: Vec<String>,
3044    /// Trailing comments that appeared after the alias
3045    #[serde(default)]
3046    pub trailing_comments: Vec<String>,
3047    /// Inferred data type from type annotation
3048    #[serde(default, skip_serializing_if = "Option::is_none")]
3049    pub inferred_type: Option<DataType>,
3050}
3051
3052impl Alias {
3053    /// Create a simple alias
3054    pub fn new(this: Expression, alias: Identifier) -> Self {
3055        Self {
3056            this,
3057            alias,
3058            column_aliases: Vec::new(),
3059            pre_alias_comments: Vec::new(),
3060            trailing_comments: Vec::new(),
3061            inferred_type: None,
3062        }
3063    }
3064
3065    /// Create an alias with column aliases only (no table alias name)
3066    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
3067        Self {
3068            this,
3069            alias: Identifier::empty(),
3070            column_aliases,
3071            pre_alias_comments: Vec::new(),
3072            trailing_comments: Vec::new(),
3073            inferred_type: None,
3074        }
3075    }
3076}
3077
3078/// Represent a type cast expression.
3079///
3080/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
3081/// shorthand `expr::type`. Also used as the payload for `TryCast` and
3082/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
3083/// CONVERSION ERROR (Oracle) clauses.
3084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3085#[cfg_attr(feature = "bindings", derive(TS))]
3086pub struct Cast {
3087    /// The expression being cast.
3088    pub this: Expression,
3089    /// The target data type.
3090    pub to: DataType,
3091    #[serde(default)]
3092    pub trailing_comments: Vec<String>,
3093    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
3094    #[serde(default)]
3095    pub double_colon_syntax: bool,
3096    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
3097    #[serde(skip_serializing_if = "Option::is_none", default)]
3098    pub format: Option<Box<Expression>>,
3099    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
3100    #[serde(skip_serializing_if = "Option::is_none", default)]
3101    pub default: Option<Box<Expression>>,
3102    /// Inferred data type from type annotation
3103    #[serde(default, skip_serializing_if = "Option::is_none")]
3104    pub inferred_type: Option<DataType>,
3105}
3106
3107///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
3108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3109#[cfg_attr(feature = "bindings", derive(TS))]
3110pub struct CollationExpr {
3111    pub this: Expression,
3112    pub collation: String,
3113    /// True if the collation was single-quoted in the original SQL (string literal)
3114    #[serde(default)]
3115    pub quoted: bool,
3116    /// True if the collation was double-quoted in the original SQL (identifier)
3117    #[serde(default)]
3118    pub double_quoted: bool,
3119}
3120
3121/// Represent a CASE expression (both simple and searched forms).
3122///
3123/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
3124/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
3125/// Each entry in `whens` is a `(condition, result)` pair.
3126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3127#[cfg_attr(feature = "bindings", derive(TS))]
3128pub struct Case {
3129    /// The operand for simple CASE, or `None` for searched CASE.
3130    pub operand: Option<Expression>,
3131    /// Pairs of (WHEN condition, THEN result).
3132    pub whens: Vec<(Expression, Expression)>,
3133    /// Optional ELSE result.
3134    pub else_: Option<Expression>,
3135    /// Comments from the CASE keyword (emitted after END)
3136    #[serde(default)]
3137    #[serde(skip_serializing_if = "Vec::is_empty")]
3138    pub comments: Vec<String>,
3139    /// Inferred data type from type annotation
3140    #[serde(default, skip_serializing_if = "Option::is_none")]
3141    pub inferred_type: Option<DataType>,
3142}
3143
3144/// Represent a binary operation (two operands separated by an operator).
3145///
3146/// This is the shared payload struct for all binary operator variants in the
3147/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
3148/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
3149/// bitwise, and dialect-specific operators. Comment fields enable round-trip
3150/// preservation of inline comments around operators.
3151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3152#[cfg_attr(feature = "bindings", derive(TS))]
3153pub struct BinaryOp {
3154    pub left: Expression,
3155    pub right: Expression,
3156    /// Comments after the left operand (before the operator)
3157    #[serde(default)]
3158    pub left_comments: Vec<String>,
3159    /// Comments after the operator (before the right operand)
3160    #[serde(default)]
3161    pub operator_comments: Vec<String>,
3162    /// Comments after the right operand
3163    #[serde(default)]
3164    pub trailing_comments: Vec<String>,
3165    /// Inferred data type from type annotation
3166    #[serde(default, skip_serializing_if = "Option::is_none")]
3167    pub inferred_type: Option<DataType>,
3168}
3169
3170impl BinaryOp {
3171    pub fn new(left: Expression, right: Expression) -> Self {
3172        Self {
3173            left,
3174            right,
3175            left_comments: Vec::new(),
3176            operator_comments: Vec::new(),
3177            trailing_comments: Vec::new(),
3178            inferred_type: None,
3179        }
3180    }
3181}
3182
3183/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
3184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3185#[cfg_attr(feature = "bindings", derive(TS))]
3186pub struct LikeOp {
3187    pub left: Expression,
3188    pub right: Expression,
3189    /// ESCAPE character/expression
3190    #[serde(default)]
3191    pub escape: Option<Expression>,
3192    /// Quantifier: ANY, ALL, or SOME
3193    #[serde(default)]
3194    pub quantifier: Option<String>,
3195    /// Inferred data type from type annotation
3196    #[serde(default, skip_serializing_if = "Option::is_none")]
3197    pub inferred_type: Option<DataType>,
3198}
3199
3200impl LikeOp {
3201    pub fn new(left: Expression, right: Expression) -> Self {
3202        Self {
3203            left,
3204            right,
3205            escape: None,
3206            quantifier: None,
3207            inferred_type: None,
3208        }
3209    }
3210
3211    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
3212        Self {
3213            left,
3214            right,
3215            escape: Some(escape),
3216            quantifier: None,
3217            inferred_type: None,
3218        }
3219    }
3220}
3221
3222/// Represent a unary operation (single operand with a prefix operator).
3223///
3224/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
3225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3226#[cfg_attr(feature = "bindings", derive(TS))]
3227pub struct UnaryOp {
3228    /// The operand expression.
3229    pub this: Expression,
3230    /// Inferred data type from type annotation
3231    #[serde(default, skip_serializing_if = "Option::is_none")]
3232    pub inferred_type: Option<DataType>,
3233}
3234
3235impl UnaryOp {
3236    pub fn new(this: Expression) -> Self {
3237        Self {
3238            this,
3239            inferred_type: None,
3240        }
3241    }
3242}
3243
3244/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
3245///
3246/// Either `expressions` (a value list) or `query` (a subquery) is populated,
3247/// but not both. When `not` is true, the predicate is `NOT IN`.
3248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3249#[cfg_attr(feature = "bindings", derive(TS))]
3250pub struct In {
3251    /// The expression being tested.
3252    pub this: Expression,
3253    /// The value list (mutually exclusive with `query`).
3254    pub expressions: Vec<Expression>,
3255    /// A subquery (mutually exclusive with `expressions`).
3256    pub query: Option<Expression>,
3257    /// Whether this is NOT IN.
3258    pub not: bool,
3259    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3260    pub global: bool,
3261    /// BigQuery: IN UNNEST(expr)
3262    #[serde(default, skip_serializing_if = "Option::is_none")]
3263    pub unnest: Option<Box<Expression>>,
3264    /// Whether the right side is a bare field reference (no parentheses).
3265    /// Matches Python sqlglot's `field` attribute on `In` expression.
3266    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
3267    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3268    pub is_field: bool,
3269}
3270
3271/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
3272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3273#[cfg_attr(feature = "bindings", derive(TS))]
3274pub struct Between {
3275    /// The expression being tested.
3276    pub this: Expression,
3277    /// The lower bound.
3278    pub low: Expression,
3279    /// The upper bound.
3280    pub high: Expression,
3281    /// Whether this is NOT BETWEEN.
3282    pub not: bool,
3283    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
3284    #[serde(default)]
3285    pub symmetric: Option<bool>,
3286}
3287
3288/// IS NULL predicate
3289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3290#[cfg_attr(feature = "bindings", derive(TS))]
3291pub struct IsNull {
3292    pub this: Expression,
3293    pub not: bool,
3294    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
3295    #[serde(default)]
3296    pub postfix_form: bool,
3297}
3298
3299/// IS TRUE / IS FALSE predicate
3300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3301#[cfg_attr(feature = "bindings", derive(TS))]
3302pub struct IsTrueFalse {
3303    pub this: Expression,
3304    pub not: bool,
3305}
3306
3307/// IS JSON predicate (SQL standard)
3308/// Checks if a value is valid JSON
3309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3310#[cfg_attr(feature = "bindings", derive(TS))]
3311pub struct IsJson {
3312    pub this: Expression,
3313    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
3314    pub json_type: Option<String>,
3315    /// Key uniqueness constraint
3316    pub unique_keys: Option<JsonUniqueKeys>,
3317    /// Whether IS NOT JSON
3318    pub negated: bool,
3319}
3320
3321/// JSON unique keys constraint variants
3322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3323#[cfg_attr(feature = "bindings", derive(TS))]
3324pub enum JsonUniqueKeys {
3325    /// WITH UNIQUE KEYS
3326    With,
3327    /// WITHOUT UNIQUE KEYS
3328    Without,
3329    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
3330    Shorthand,
3331}
3332
3333/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
3334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3335#[cfg_attr(feature = "bindings", derive(TS))]
3336pub struct Exists {
3337    /// The subquery expression.
3338    pub this: Expression,
3339    /// Whether this is NOT EXISTS.
3340    pub not: bool,
3341}
3342
3343/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
3344///
3345/// This is the generic function node. Well-known aggregates, window functions,
3346/// and built-in functions each have their own dedicated `Expression` variants
3347/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
3348/// not recognize as built-ins are represented with this struct.
3349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3350#[cfg_attr(feature = "bindings", derive(TS))]
3351pub struct Function {
3352    /// The function name, as originally written (may be schema-qualified).
3353    pub name: String,
3354    /// Positional arguments to the function.
3355    pub args: Vec<Expression>,
3356    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
3357    pub distinct: bool,
3358    #[serde(default)]
3359    pub trailing_comments: Vec<String>,
3360    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
3361    #[serde(default)]
3362    pub use_bracket_syntax: bool,
3363    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
3364    #[serde(default)]
3365    pub no_parens: bool,
3366    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
3367    #[serde(default)]
3368    pub quoted: bool,
3369    /// Source position span
3370    #[serde(default, skip_serializing_if = "Option::is_none")]
3371    pub span: Option<Span>,
3372    /// Inferred data type from type annotation
3373    #[serde(default, skip_serializing_if = "Option::is_none")]
3374    pub inferred_type: Option<DataType>,
3375}
3376
3377impl Default for Function {
3378    fn default() -> Self {
3379        Self {
3380            name: String::new(),
3381            args: Vec::new(),
3382            distinct: false,
3383            trailing_comments: Vec::new(),
3384            use_bracket_syntax: false,
3385            no_parens: false,
3386            quoted: false,
3387            span: None,
3388            inferred_type: None,
3389        }
3390    }
3391}
3392
3393impl Function {
3394    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
3395        Self {
3396            name: name.into(),
3397            args,
3398            distinct: false,
3399            trailing_comments: Vec::new(),
3400            use_bracket_syntax: false,
3401            no_parens: false,
3402            quoted: false,
3403            span: None,
3404            inferred_type: None,
3405        }
3406    }
3407}
3408
3409/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
3410///
3411/// This struct is used for aggregate function calls that are not covered by
3412/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
3413/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
3414/// IGNORE NULLS / RESPECT NULLS modifiers.
3415#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3416#[cfg_attr(feature = "bindings", derive(TS))]
3417pub struct AggregateFunction {
3418    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
3419    pub name: String,
3420    /// Positional arguments.
3421    pub args: Vec<Expression>,
3422    /// Whether DISTINCT was specified.
3423    pub distinct: bool,
3424    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
3425    pub filter: Option<Expression>,
3426    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
3427    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3428    pub order_by: Vec<Ordered>,
3429    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
3430    #[serde(default, skip_serializing_if = "Option::is_none")]
3431    pub limit: Option<Box<Expression>>,
3432    /// IGNORE NULLS / RESPECT NULLS
3433    #[serde(default, skip_serializing_if = "Option::is_none")]
3434    pub ignore_nulls: Option<bool>,
3435    /// Inferred data type from type annotation
3436    #[serde(default, skip_serializing_if = "Option::is_none")]
3437    pub inferred_type: Option<DataType>,
3438}
3439
3440/// Represent a window function call with its OVER clause.
3441///
3442/// The inner `this` expression is typically a window-specific expression
3443/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
3444/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
3445/// frame specification.
3446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3447#[cfg_attr(feature = "bindings", derive(TS))]
3448pub struct WindowFunction {
3449    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
3450    pub this: Expression,
3451    /// The OVER clause defining the window partitioning, ordering, and frame.
3452    pub over: Over,
3453    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
3454    #[serde(default, skip_serializing_if = "Option::is_none")]
3455    pub keep: Option<Keep>,
3456    /// Inferred data type from type annotation
3457    #[serde(default, skip_serializing_if = "Option::is_none")]
3458    pub inferred_type: Option<DataType>,
3459}
3460
3461/// Oracle KEEP clause for aggregate functions
3462/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
3463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3464#[cfg_attr(feature = "bindings", derive(TS))]
3465pub struct Keep {
3466    /// true = FIRST, false = LAST
3467    pub first: bool,
3468    /// ORDER BY clause inside KEEP
3469    pub order_by: Vec<Ordered>,
3470}
3471
3472/// WITHIN GROUP clause (for ordered-set aggregate functions)
3473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3474#[cfg_attr(feature = "bindings", derive(TS))]
3475pub struct WithinGroup {
3476    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
3477    pub this: Expression,
3478    /// The ORDER BY clause within the group
3479    pub order_by: Vec<Ordered>,
3480}
3481
3482/// Represent the FROM clause of a SELECT statement.
3483///
3484/// Contains one or more table sources (tables, subqueries, table-valued
3485/// functions, etc.). Multiple entries represent comma-separated implicit joins.
3486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3487#[cfg_attr(feature = "bindings", derive(TS))]
3488pub struct From {
3489    /// The table source expressions.
3490    pub expressions: Vec<Expression>,
3491}
3492
3493/// Represent a JOIN clause between two table sources.
3494///
3495/// The join condition can be specified via `on` (ON predicate) or `using`
3496/// (USING column list), but not both. The `kind` field determines the join
3497/// type (INNER, LEFT, CROSS, etc.).
3498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3499#[cfg_attr(feature = "bindings", derive(TS))]
3500pub struct Join {
3501    /// The right-hand table expression being joined.
3502    pub this: Expression,
3503    /// The ON condition (mutually exclusive with `using`).
3504    pub on: Option<Expression>,
3505    /// The USING column list (mutually exclusive with `on`).
3506    pub using: Vec<Identifier>,
3507    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
3508    pub kind: JoinKind,
3509    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3510    pub use_inner_keyword: bool,
3511    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3512    pub use_outer_keyword: bool,
3513    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3514    pub deferred_condition: bool,
3515    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3516    #[serde(default, skip_serializing_if = "Option::is_none")]
3517    pub join_hint: Option<String>,
3518    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3519    #[serde(default, skip_serializing_if = "Option::is_none")]
3520    pub match_condition: Option<Expression>,
3521    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3522    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3523    pub pivots: Vec<Expression>,
3524    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3525    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3526    pub comments: Vec<String>,
3527    /// Nesting group identifier for nested join pretty-printing.
3528    /// Joins in the same group were parsed together; group boundaries come from
3529    /// deferred condition resolution phases.
3530    #[serde(default)]
3531    pub nesting_group: usize,
3532    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3533    #[serde(default)]
3534    pub directed: bool,
3535}
3536
3537/// Enumerate all supported SQL join types.
3538///
3539/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3540/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3541/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3542/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3543#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3544#[cfg_attr(feature = "bindings", derive(TS))]
3545pub enum JoinKind {
3546    Inner,
3547    Left,
3548    Right,
3549    Full,
3550    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3551    Cross,
3552    Natural,
3553    NaturalLeft,
3554    NaturalRight,
3555    NaturalFull,
3556    Semi,
3557    Anti,
3558    // Directional SEMI/ANTI joins
3559    LeftSemi,
3560    LeftAnti,
3561    RightSemi,
3562    RightAnti,
3563    // SQL Server specific
3564    CrossApply,
3565    OuterApply,
3566    // Time-series specific
3567    AsOf,
3568    AsOfLeft,
3569    AsOfRight,
3570    // Lateral join
3571    Lateral,
3572    LeftLateral,
3573    // MySQL specific
3574    Straight,
3575    // Implicit join (comma-separated tables: FROM a, b)
3576    Implicit,
3577    // ClickHouse ARRAY JOIN
3578    Array,
3579    LeftArray,
3580    // ClickHouse PASTE JOIN (positional join)
3581    Paste,
3582    // DuckDB POSITIONAL JOIN
3583    Positional,
3584}
3585
3586impl Default for JoinKind {
3587    fn default() -> Self {
3588        JoinKind::Inner
3589    }
3590}
3591
3592/// Parenthesized table expression with joins
3593/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3595#[cfg_attr(feature = "bindings", derive(TS))]
3596pub struct JoinedTable {
3597    /// The left-hand side table expression
3598    pub left: Expression,
3599    /// The joins applied to the left table
3600    pub joins: Vec<Join>,
3601    /// LATERAL VIEW clauses (Hive/Spark)
3602    pub lateral_views: Vec<LateralView>,
3603    /// Optional alias for the joined table expression
3604    pub alias: Option<Identifier>,
3605}
3606
3607/// Represent a WHERE clause containing a boolean filter predicate.
3608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3609#[cfg_attr(feature = "bindings", derive(TS))]
3610pub struct Where {
3611    /// The filter predicate expression.
3612    pub this: Expression,
3613}
3614
3615/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3616///
3617/// The `expressions` list may contain plain columns, ordinal positions,
3618/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3620#[cfg_attr(feature = "bindings", derive(TS))]
3621pub struct GroupBy {
3622    /// The grouping expressions.
3623    pub expressions: Vec<Expression>,
3624    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3625    #[serde(default)]
3626    pub all: Option<bool>,
3627    /// ClickHouse: WITH TOTALS modifier
3628    #[serde(default)]
3629    pub totals: bool,
3630    /// Leading comments that appeared before the GROUP BY keyword
3631    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3632    pub comments: Vec<String>,
3633}
3634
3635/// Represent a HAVING clause containing a predicate over aggregate results.
3636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3637#[cfg_attr(feature = "bindings", derive(TS))]
3638pub struct Having {
3639    /// The filter predicate, typically involving aggregate functions.
3640    pub this: Expression,
3641    /// Leading comments that appeared before the HAVING keyword
3642    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3643    pub comments: Vec<String>,
3644}
3645
3646/// Represent an ORDER BY clause containing one or more sort specifications.
3647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3648#[cfg_attr(feature = "bindings", derive(TS))]
3649pub struct OrderBy {
3650    /// The sort specifications, each with direction and null ordering.
3651    pub expressions: Vec<Ordered>,
3652    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3653    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3654    pub siblings: bool,
3655    /// Leading comments that appeared before the ORDER BY keyword
3656    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3657    pub comments: Vec<String>,
3658}
3659
3660/// Represent an expression with sort direction and null ordering.
3661///
3662/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3663/// When `desc` is false the sort is ascending. The `nulls_first` field
3664/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3665/// (database default).
3666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3667#[cfg_attr(feature = "bindings", derive(TS))]
3668pub struct Ordered {
3669    /// The expression to sort by.
3670    pub this: Expression,
3671    /// Whether the sort direction is descending (true) or ascending (false).
3672    pub desc: bool,
3673    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3674    pub nulls_first: Option<bool>,
3675    /// Whether ASC was explicitly written (not just implied)
3676    #[serde(default)]
3677    pub explicit_asc: bool,
3678    /// ClickHouse WITH FILL clause
3679    #[serde(default, skip_serializing_if = "Option::is_none")]
3680    pub with_fill: Option<Box<WithFill>>,
3681}
3682
3683impl Ordered {
3684    pub fn asc(expr: Expression) -> Self {
3685        Self {
3686            this: expr,
3687            desc: false,
3688            nulls_first: None,
3689            explicit_asc: false,
3690            with_fill: None,
3691        }
3692    }
3693
3694    pub fn desc(expr: Expression) -> Self {
3695        Self {
3696            this: expr,
3697            desc: true,
3698            nulls_first: None,
3699            explicit_asc: false,
3700            with_fill: None,
3701        }
3702    }
3703}
3704
3705/// DISTRIBUTE BY clause (Hive/Spark)
3706/// Controls how rows are distributed across reducers
3707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3708#[cfg_attr(feature = "bindings", derive(TS))]
3709#[cfg_attr(feature = "bindings", ts(export))]
3710pub struct DistributeBy {
3711    pub expressions: Vec<Expression>,
3712}
3713
3714/// CLUSTER BY clause (Hive/Spark)
3715/// Combines DISTRIBUTE BY and SORT BY on the same columns
3716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3717#[cfg_attr(feature = "bindings", derive(TS))]
3718#[cfg_attr(feature = "bindings", ts(export))]
3719pub struct ClusterBy {
3720    pub expressions: Vec<Ordered>,
3721}
3722
3723/// SORT BY clause (Hive/Spark)
3724/// Sorts data within each reducer (local sort, not global)
3725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3726#[cfg_attr(feature = "bindings", derive(TS))]
3727#[cfg_attr(feature = "bindings", ts(export))]
3728pub struct SortBy {
3729    pub expressions: Vec<Ordered>,
3730}
3731
3732/// LATERAL VIEW clause (Hive/Spark)
3733/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3735#[cfg_attr(feature = "bindings", derive(TS))]
3736#[cfg_attr(feature = "bindings", ts(export))]
3737pub struct LateralView {
3738    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3739    pub this: Expression,
3740    /// Table alias for the generated table
3741    pub table_alias: Option<Identifier>,
3742    /// Column aliases for the generated columns
3743    pub column_aliases: Vec<Identifier>,
3744    /// OUTER keyword - preserve nulls when input is empty/null
3745    pub outer: bool,
3746}
3747
3748/// Query hint
3749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3750#[cfg_attr(feature = "bindings", derive(TS))]
3751#[cfg_attr(feature = "bindings", ts(export))]
3752pub struct Hint {
3753    pub expressions: Vec<HintExpression>,
3754}
3755
3756/// Individual hint expression
3757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3758#[cfg_attr(feature = "bindings", derive(TS))]
3759#[cfg_attr(feature = "bindings", ts(export))]
3760pub enum HintExpression {
3761    /// Function-style hint: USE_HASH(table)
3762    Function { name: String, args: Vec<Expression> },
3763    /// Simple identifier hint: PARALLEL
3764    Identifier(String),
3765    /// Raw hint text (unparsed)
3766    Raw(String),
3767}
3768
3769/// Pseudocolumn type
3770#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3771#[cfg_attr(feature = "bindings", derive(TS))]
3772#[cfg_attr(feature = "bindings", ts(export))]
3773pub enum PseudocolumnType {
3774    Rownum,      // Oracle ROWNUM
3775    Rowid,       // Oracle ROWID
3776    Level,       // Oracle LEVEL (for CONNECT BY)
3777    Sysdate,     // Oracle SYSDATE
3778    ObjectId,    // Oracle OBJECT_ID
3779    ObjectValue, // Oracle OBJECT_VALUE
3780}
3781
3782impl PseudocolumnType {
3783    pub fn as_str(&self) -> &'static str {
3784        match self {
3785            PseudocolumnType::Rownum => "ROWNUM",
3786            PseudocolumnType::Rowid => "ROWID",
3787            PseudocolumnType::Level => "LEVEL",
3788            PseudocolumnType::Sysdate => "SYSDATE",
3789            PseudocolumnType::ObjectId => "OBJECT_ID",
3790            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3791        }
3792    }
3793
3794    pub fn from_str(s: &str) -> Option<Self> {
3795        match s.to_uppercase().as_str() {
3796            "ROWNUM" => Some(PseudocolumnType::Rownum),
3797            "ROWID" => Some(PseudocolumnType::Rowid),
3798            "LEVEL" => Some(PseudocolumnType::Level),
3799            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3800            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3801            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3802            _ => None,
3803        }
3804    }
3805}
3806
3807/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3808/// These are special identifiers that should not be quoted
3809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3810#[cfg_attr(feature = "bindings", derive(TS))]
3811#[cfg_attr(feature = "bindings", ts(export))]
3812pub struct Pseudocolumn {
3813    pub kind: PseudocolumnType,
3814}
3815
3816impl Pseudocolumn {
3817    pub fn rownum() -> Self {
3818        Self {
3819            kind: PseudocolumnType::Rownum,
3820        }
3821    }
3822
3823    pub fn rowid() -> Self {
3824        Self {
3825            kind: PseudocolumnType::Rowid,
3826        }
3827    }
3828
3829    pub fn level() -> Self {
3830        Self {
3831            kind: PseudocolumnType::Level,
3832        }
3833    }
3834}
3835
3836/// Oracle CONNECT BY clause for hierarchical queries
3837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3838#[cfg_attr(feature = "bindings", derive(TS))]
3839#[cfg_attr(feature = "bindings", ts(export))]
3840pub struct Connect {
3841    /// START WITH condition (optional, can come before or after CONNECT BY)
3842    pub start: Option<Expression>,
3843    /// CONNECT BY condition (required, contains PRIOR references)
3844    pub connect: Expression,
3845    /// NOCYCLE keyword to prevent infinite loops
3846    pub nocycle: bool,
3847}
3848
3849/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3851#[cfg_attr(feature = "bindings", derive(TS))]
3852#[cfg_attr(feature = "bindings", ts(export))]
3853pub struct Prior {
3854    pub this: Expression,
3855}
3856
3857/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3859#[cfg_attr(feature = "bindings", derive(TS))]
3860#[cfg_attr(feature = "bindings", ts(export))]
3861pub struct ConnectByRoot {
3862    pub this: Expression,
3863}
3864
3865/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3867#[cfg_attr(feature = "bindings", derive(TS))]
3868#[cfg_attr(feature = "bindings", ts(export))]
3869pub struct MatchRecognize {
3870    /// Source table/expression
3871    pub this: Option<Box<Expression>>,
3872    /// PARTITION BY expressions
3873    pub partition_by: Option<Vec<Expression>>,
3874    /// ORDER BY expressions
3875    pub order_by: Option<Vec<Ordered>>,
3876    /// MEASURES definitions
3877    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3878    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3879    pub rows: Option<MatchRecognizeRows>,
3880    /// AFTER MATCH SKIP behavior
3881    pub after: Option<MatchRecognizeAfter>,
3882    /// PATTERN definition (stored as raw string for complex regex patterns)
3883    pub pattern: Option<String>,
3884    /// DEFINE clauses (pattern variable definitions)
3885    pub define: Option<Vec<(Identifier, Expression)>>,
3886    /// Optional alias for the result
3887    pub alias: Option<Identifier>,
3888    /// Whether AS keyword was explicitly present before alias
3889    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3890    pub alias_explicit_as: bool,
3891}
3892
3893/// MEASURES expression with optional RUNNING/FINAL semantics
3894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3895#[cfg_attr(feature = "bindings", derive(TS))]
3896#[cfg_attr(feature = "bindings", ts(export))]
3897pub struct MatchRecognizeMeasure {
3898    /// The measure expression
3899    pub this: Expression,
3900    /// RUNNING or FINAL semantics (Snowflake-specific)
3901    pub window_frame: Option<MatchRecognizeSemantics>,
3902}
3903
3904/// Semantics for MEASURES in MATCH_RECOGNIZE
3905#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3906#[cfg_attr(feature = "bindings", derive(TS))]
3907#[cfg_attr(feature = "bindings", ts(export))]
3908pub enum MatchRecognizeSemantics {
3909    Running,
3910    Final,
3911}
3912
3913/// Row output semantics for MATCH_RECOGNIZE
3914#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3915#[cfg_attr(feature = "bindings", derive(TS))]
3916#[cfg_attr(feature = "bindings", ts(export))]
3917pub enum MatchRecognizeRows {
3918    OneRowPerMatch,
3919    AllRowsPerMatch,
3920    AllRowsPerMatchShowEmptyMatches,
3921    AllRowsPerMatchOmitEmptyMatches,
3922    AllRowsPerMatchWithUnmatchedRows,
3923}
3924
3925/// AFTER MATCH SKIP behavior
3926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3927#[cfg_attr(feature = "bindings", derive(TS))]
3928#[cfg_attr(feature = "bindings", ts(export))]
3929pub enum MatchRecognizeAfter {
3930    PastLastRow,
3931    ToNextRow,
3932    ToFirst(Identifier),
3933    ToLast(Identifier),
3934}
3935
3936/// Represent a LIMIT clause that restricts the number of returned rows.
3937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3938#[cfg_attr(feature = "bindings", derive(TS))]
3939pub struct Limit {
3940    /// The limit count expression.
3941    pub this: Expression,
3942    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3943    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3944    pub percent: bool,
3945    /// Comments from before the LIMIT keyword (emitted after the limit value)
3946    #[serde(default)]
3947    #[serde(skip_serializing_if = "Vec::is_empty")]
3948    pub comments: Vec<String>,
3949}
3950
3951/// OFFSET clause
3952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3953#[cfg_attr(feature = "bindings", derive(TS))]
3954pub struct Offset {
3955    pub this: Expression,
3956    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3957    #[serde(skip_serializing_if = "Option::is_none", default)]
3958    pub rows: Option<bool>,
3959}
3960
3961/// TOP clause (SQL Server)
3962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3963#[cfg_attr(feature = "bindings", derive(TS))]
3964pub struct Top {
3965    pub this: Expression,
3966    pub percent: bool,
3967    pub with_ties: bool,
3968    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3969    #[serde(default)]
3970    pub parenthesized: bool,
3971}
3972
3973/// FETCH FIRST/NEXT clause (SQL standard)
3974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3975#[cfg_attr(feature = "bindings", derive(TS))]
3976pub struct Fetch {
3977    /// FIRST or NEXT
3978    pub direction: String,
3979    /// Count expression (optional)
3980    pub count: Option<Expression>,
3981    /// PERCENT modifier
3982    pub percent: bool,
3983    /// ROWS or ROW keyword present
3984    pub rows: bool,
3985    /// WITH TIES modifier
3986    pub with_ties: bool,
3987}
3988
3989/// Represent a QUALIFY clause for filtering on window function results.
3990///
3991/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3992/// typically references a window function (e.g.
3993/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3995#[cfg_attr(feature = "bindings", derive(TS))]
3996pub struct Qualify {
3997    /// The filter predicate over window function results.
3998    pub this: Expression,
3999}
4000
4001/// SAMPLE / TABLESAMPLE clause
4002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4003#[cfg_attr(feature = "bindings", derive(TS))]
4004pub struct Sample {
4005    pub method: SampleMethod,
4006    pub size: Expression,
4007    pub seed: Option<Expression>,
4008    /// ClickHouse OFFSET expression after SAMPLE size
4009    #[serde(default)]
4010    pub offset: Option<Expression>,
4011    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
4012    pub unit_after_size: bool,
4013    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
4014    #[serde(default)]
4015    pub use_sample_keyword: bool,
4016    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
4017    #[serde(default)]
4018    pub explicit_method: bool,
4019    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
4020    #[serde(default)]
4021    pub method_before_size: bool,
4022    /// Whether SEED keyword was used (true) or REPEATABLE (false)
4023    #[serde(default)]
4024    pub use_seed_keyword: bool,
4025    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
4026    pub bucket_numerator: Option<Box<Expression>>,
4027    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
4028    pub bucket_denominator: Option<Box<Expression>>,
4029    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
4030    pub bucket_field: Option<Box<Expression>>,
4031    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
4032    #[serde(default)]
4033    pub is_using_sample: bool,
4034    /// Whether the unit was explicitly PERCENT (vs ROWS)
4035    #[serde(default)]
4036    pub is_percent: bool,
4037    /// Whether to suppress method output (for cross-dialect transpilation)
4038    #[serde(default)]
4039    pub suppress_method_output: bool,
4040}
4041
4042/// Sample method
4043#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4044#[cfg_attr(feature = "bindings", derive(TS))]
4045pub enum SampleMethod {
4046    Bernoulli,
4047    System,
4048    Block,
4049    Row,
4050    Percent,
4051    /// Hive bucket sampling
4052    Bucket,
4053    /// DuckDB reservoir sampling
4054    Reservoir,
4055}
4056
4057/// Named window definition (WINDOW w AS (...))
4058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4059#[cfg_attr(feature = "bindings", derive(TS))]
4060pub struct NamedWindow {
4061    pub name: Identifier,
4062    pub spec: Over,
4063}
4064
4065/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
4066///
4067/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
4068/// that reference themselves. Each CTE is defined in the `ctes` vector and
4069/// can be referenced by name in subsequent CTEs and in the main query body.
4070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4071#[cfg_attr(feature = "bindings", derive(TS))]
4072pub struct With {
4073    /// The list of CTE definitions, in order.
4074    pub ctes: Vec<Cte>,
4075    /// Whether the WITH RECURSIVE keyword was used.
4076    pub recursive: bool,
4077    /// Leading comments before the statement
4078    #[serde(default)]
4079    pub leading_comments: Vec<String>,
4080    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
4081    #[serde(default, skip_serializing_if = "Option::is_none")]
4082    pub search: Option<Box<Expression>>,
4083}
4084
4085/// Represent a single Common Table Expression definition.
4086///
4087/// A CTE has a name (`alias`), an optional column list, and a body query.
4088/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
4089/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
4090/// the expression comes before the alias (`alias_first`).
4091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4092#[cfg_attr(feature = "bindings", derive(TS))]
4093pub struct Cte {
4094    /// The CTE name.
4095    pub alias: Identifier,
4096    /// The CTE body (typically a SELECT, UNION, etc.).
4097    pub this: Expression,
4098    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
4099    pub columns: Vec<Identifier>,
4100    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
4101    pub materialized: Option<bool>,
4102    /// USING KEY (columns) for DuckDB recursive CTEs
4103    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4104    pub key_expressions: Vec<Identifier>,
4105    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
4106    #[serde(default)]
4107    pub alias_first: bool,
4108    /// Comments associated with this CTE (placed after alias name, before AS)
4109    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4110    pub comments: Vec<String>,
4111}
4112
4113/// Window specification
4114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4115#[cfg_attr(feature = "bindings", derive(TS))]
4116pub struct WindowSpec {
4117    pub partition_by: Vec<Expression>,
4118    pub order_by: Vec<Ordered>,
4119    pub frame: Option<WindowFrame>,
4120}
4121
4122/// OVER clause
4123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4124#[cfg_attr(feature = "bindings", derive(TS))]
4125pub struct Over {
4126    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
4127    pub window_name: Option<Identifier>,
4128    pub partition_by: Vec<Expression>,
4129    pub order_by: Vec<Ordered>,
4130    pub frame: Option<WindowFrame>,
4131    pub alias: Option<Identifier>,
4132}
4133
4134/// Window frame
4135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4136#[cfg_attr(feature = "bindings", derive(TS))]
4137pub struct WindowFrame {
4138    pub kind: WindowFrameKind,
4139    pub start: WindowFrameBound,
4140    pub end: Option<WindowFrameBound>,
4141    pub exclude: Option<WindowFrameExclude>,
4142    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
4143    #[serde(default, skip_serializing_if = "Option::is_none")]
4144    pub kind_text: Option<String>,
4145    /// Original text of the start bound side keyword (e.g. "preceding")
4146    #[serde(default, skip_serializing_if = "Option::is_none")]
4147    pub start_side_text: Option<String>,
4148    /// Original text of the end bound side keyword
4149    #[serde(default, skip_serializing_if = "Option::is_none")]
4150    pub end_side_text: Option<String>,
4151}
4152
4153#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4154#[cfg_attr(feature = "bindings", derive(TS))]
4155pub enum WindowFrameKind {
4156    Rows,
4157    Range,
4158    Groups,
4159}
4160
4161/// EXCLUDE clause for window frames
4162#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4163#[cfg_attr(feature = "bindings", derive(TS))]
4164pub enum WindowFrameExclude {
4165    CurrentRow,
4166    Group,
4167    Ties,
4168    NoOthers,
4169}
4170
4171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4172#[cfg_attr(feature = "bindings", derive(TS))]
4173pub enum WindowFrameBound {
4174    CurrentRow,
4175    UnboundedPreceding,
4176    UnboundedFollowing,
4177    Preceding(Box<Expression>),
4178    Following(Box<Expression>),
4179    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
4180    BarePreceding,
4181    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
4182    BareFollowing,
4183    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
4184    Value(Box<Expression>),
4185}
4186
4187/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
4188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4189#[cfg_attr(feature = "bindings", derive(TS))]
4190pub struct StructField {
4191    pub name: String,
4192    pub data_type: DataType,
4193    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4194    pub options: Vec<Expression>,
4195    #[serde(default, skip_serializing_if = "Option::is_none")]
4196    pub comment: Option<String>,
4197}
4198
4199impl StructField {
4200    /// Create a new struct field without options
4201    pub fn new(name: String, data_type: DataType) -> Self {
4202        Self {
4203            name,
4204            data_type,
4205            options: Vec::new(),
4206            comment: None,
4207        }
4208    }
4209
4210    /// Create a new struct field with options
4211    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
4212        Self {
4213            name,
4214            data_type,
4215            options,
4216            comment: None,
4217        }
4218    }
4219
4220    /// Create a new struct field with options and comment
4221    pub fn with_options_and_comment(
4222        name: String,
4223        data_type: DataType,
4224        options: Vec<Expression>,
4225        comment: Option<String>,
4226    ) -> Self {
4227        Self {
4228            name,
4229            data_type,
4230            options,
4231            comment,
4232        }
4233    }
4234}
4235
4236/// Enumerate all SQL data types recognized by the parser.
4237///
4238/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
4239/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
4240/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
4241///
4242/// This enum is used in CAST expressions, column definitions, function return
4243/// types, and anywhere a data type specification appears in SQL.
4244///
4245/// Types that do not match any known variant fall through to `Custom { name }`,
4246/// preserving the original type name for round-trip fidelity.
4247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4248#[cfg_attr(feature = "bindings", derive(TS))]
4249#[serde(tag = "data_type", rename_all = "snake_case")]
4250pub enum DataType {
4251    // Numeric
4252    Boolean,
4253    TinyInt {
4254        length: Option<u32>,
4255    },
4256    SmallInt {
4257        length: Option<u32>,
4258    },
4259    /// Int type with optional length. `integer_spelling` indicates whether the original
4260    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
4261    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
4262    Int {
4263        length: Option<u32>,
4264        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4265        integer_spelling: bool,
4266    },
4267    BigInt {
4268        length: Option<u32>,
4269    },
4270    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
4271    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
4272    /// preserve the original spelling.
4273    Float {
4274        precision: Option<u32>,
4275        scale: Option<u32>,
4276        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4277        real_spelling: bool,
4278    },
4279    Double {
4280        precision: Option<u32>,
4281        scale: Option<u32>,
4282    },
4283    Decimal {
4284        precision: Option<u32>,
4285        scale: Option<u32>,
4286    },
4287
4288    // String
4289    Char {
4290        length: Option<u32>,
4291    },
4292    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
4293    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
4294    VarChar {
4295        length: Option<u32>,
4296        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4297        parenthesized_length: bool,
4298    },
4299    /// String type with optional max length (BigQuery STRING(n))
4300    String {
4301        length: Option<u32>,
4302    },
4303    Text,
4304    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
4305    TextWithLength {
4306        length: u32,
4307    },
4308
4309    // Binary
4310    Binary {
4311        length: Option<u32>,
4312    },
4313    VarBinary {
4314        length: Option<u32>,
4315    },
4316    Blob,
4317
4318    // Bit
4319    Bit {
4320        length: Option<u32>,
4321    },
4322    VarBit {
4323        length: Option<u32>,
4324    },
4325
4326    // Date/Time
4327    Date,
4328    Time {
4329        precision: Option<u32>,
4330        #[serde(default)]
4331        timezone: bool,
4332    },
4333    Timestamp {
4334        precision: Option<u32>,
4335        timezone: bool,
4336    },
4337    Interval {
4338        unit: Option<String>,
4339        /// For range intervals like INTERVAL DAY TO HOUR
4340        #[serde(default, skip_serializing_if = "Option::is_none")]
4341        to: Option<String>,
4342    },
4343
4344    // JSON
4345    Json,
4346    JsonB,
4347
4348    // UUID
4349    Uuid,
4350
4351    // Array
4352    Array {
4353        element_type: Box<DataType>,
4354        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
4355        #[serde(default, skip_serializing_if = "Option::is_none")]
4356        dimension: Option<u32>,
4357    },
4358
4359    /// List type (Materialize): INT LIST, TEXT LIST LIST
4360    /// Uses postfix LIST syntax instead of ARRAY<T>
4361    List {
4362        element_type: Box<DataType>,
4363    },
4364
4365    // Struct/Map
4366    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
4367    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
4368    Struct {
4369        fields: Vec<StructField>,
4370        nested: bool,
4371    },
4372    Map {
4373        key_type: Box<DataType>,
4374        value_type: Box<DataType>,
4375    },
4376
4377    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
4378    Enum {
4379        values: Vec<String>,
4380        #[serde(default, skip_serializing_if = "Vec::is_empty")]
4381        assignments: Vec<Option<String>>,
4382    },
4383
4384    // Set type (MySQL): SET('a', 'b', 'c')
4385    Set {
4386        values: Vec<String>,
4387    },
4388
4389    // Union type (DuckDB): UNION(num INT, str TEXT)
4390    Union {
4391        fields: Vec<(String, DataType)>,
4392    },
4393
4394    // Vector (Snowflake / SingleStore)
4395    Vector {
4396        #[serde(default)]
4397        element_type: Option<Box<DataType>>,
4398        dimension: Option<u32>,
4399    },
4400
4401    // Object (Snowflake structured type)
4402    // fields: Vec of (field_name, field_type, not_null)
4403    Object {
4404        fields: Vec<(String, DataType, bool)>,
4405        modifier: Option<String>,
4406    },
4407
4408    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
4409    Nullable {
4410        inner: Box<DataType>,
4411    },
4412
4413    // Custom/User-defined
4414    Custom {
4415        name: String,
4416    },
4417
4418    // Spatial types
4419    Geometry {
4420        subtype: Option<String>,
4421        srid: Option<u32>,
4422    },
4423    Geography {
4424        subtype: Option<String>,
4425        srid: Option<u32>,
4426    },
4427
4428    // Character Set (for CONVERT USING in MySQL)
4429    // Renders as CHAR CHARACTER SET {name} in cast target
4430    CharacterSet {
4431        name: String,
4432    },
4433
4434    // Unknown
4435    Unknown,
4436}
4437
4438/// Array expression
4439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4440#[cfg_attr(feature = "bindings", derive(TS))]
4441#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
4442pub struct Array {
4443    pub expressions: Vec<Expression>,
4444}
4445
4446/// Struct expression
4447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4448#[cfg_attr(feature = "bindings", derive(TS))]
4449pub struct Struct {
4450    pub fields: Vec<(Option<String>, Expression)>,
4451}
4452
4453/// Tuple expression
4454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4455#[cfg_attr(feature = "bindings", derive(TS))]
4456pub struct Tuple {
4457    pub expressions: Vec<Expression>,
4458}
4459
4460/// Interval expression
4461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4462#[cfg_attr(feature = "bindings", derive(TS))]
4463pub struct Interval {
4464    /// The value expression (e.g., '1', 5, column_ref)
4465    pub this: Option<Expression>,
4466    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
4467    pub unit: Option<IntervalUnitSpec>,
4468}
4469
4470/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
4471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4472#[cfg_attr(feature = "bindings", derive(TS))]
4473#[serde(tag = "type", rename_all = "snake_case")]
4474pub enum IntervalUnitSpec {
4475    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
4476    Simple {
4477        unit: IntervalUnit,
4478        /// Whether to use plural form (e.g., DAYS vs DAY)
4479        use_plural: bool,
4480    },
4481    /// Interval span (e.g., HOUR TO SECOND)
4482    Span(IntervalSpan),
4483    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4484    /// The start and end can be expressions like function calls with precision
4485    ExprSpan(IntervalSpanExpr),
4486    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
4487    Expr(Box<Expression>),
4488}
4489
4490/// Interval span for ranges like HOUR TO SECOND
4491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4492#[cfg_attr(feature = "bindings", derive(TS))]
4493pub struct IntervalSpan {
4494    /// Start unit (e.g., HOUR)
4495    pub this: IntervalUnit,
4496    /// End unit (e.g., SECOND)
4497    pub expression: IntervalUnit,
4498}
4499
4500/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4501/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
4502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4503#[cfg_attr(feature = "bindings", derive(TS))]
4504pub struct IntervalSpanExpr {
4505    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
4506    pub this: Box<Expression>,
4507    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
4508    pub expression: Box<Expression>,
4509}
4510
4511#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4512#[cfg_attr(feature = "bindings", derive(TS))]
4513pub enum IntervalUnit {
4514    Year,
4515    Quarter,
4516    Month,
4517    Week,
4518    Day,
4519    Hour,
4520    Minute,
4521    Second,
4522    Millisecond,
4523    Microsecond,
4524    Nanosecond,
4525}
4526
4527/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4529#[cfg_attr(feature = "bindings", derive(TS))]
4530pub struct Command {
4531    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4532    pub this: String,
4533}
4534
4535/// EXEC/EXECUTE statement (TSQL stored procedure call)
4536/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4538#[cfg_attr(feature = "bindings", derive(TS))]
4539pub struct ExecuteStatement {
4540    /// The procedure name (can be qualified: schema.proc_name)
4541    pub this: Expression,
4542    /// Named parameters: @param=value pairs
4543    #[serde(default)]
4544    pub parameters: Vec<ExecuteParameter>,
4545}
4546
4547/// Named parameter in EXEC statement: @name=value
4548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4549#[cfg_attr(feature = "bindings", derive(TS))]
4550pub struct ExecuteParameter {
4551    /// Parameter name (including @)
4552    pub name: String,
4553    /// Parameter value
4554    pub value: Expression,
4555    /// Whether this is a positional parameter (no = sign)
4556    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4557    pub positional: bool,
4558}
4559
4560/// KILL statement (MySQL/MariaDB)
4561/// KILL [CONNECTION | QUERY] <id>
4562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4563#[cfg_attr(feature = "bindings", derive(TS))]
4564pub struct Kill {
4565    /// The target (process ID or connection ID)
4566    pub this: Expression,
4567    /// Optional kind: "CONNECTION" or "QUERY"
4568    pub kind: Option<String>,
4569}
4570
4571/// Raw/unparsed SQL
4572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4573#[cfg_attr(feature = "bindings", derive(TS))]
4574pub struct Raw {
4575    pub sql: String,
4576}
4577
4578// ============================================================================
4579// Function expression types
4580// ============================================================================
4581
4582/// Generic unary function (takes a single argument)
4583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4584#[cfg_attr(feature = "bindings", derive(TS))]
4585pub struct UnaryFunc {
4586    pub this: Expression,
4587    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4588    #[serde(skip_serializing_if = "Option::is_none", default)]
4589    pub original_name: Option<String>,
4590    /// Inferred data type from type annotation
4591    #[serde(default, skip_serializing_if = "Option::is_none")]
4592    pub inferred_type: Option<DataType>,
4593}
4594
4595impl UnaryFunc {
4596    /// Create a new UnaryFunc with no original_name
4597    pub fn new(this: Expression) -> Self {
4598        Self {
4599            this,
4600            original_name: None,
4601            inferred_type: None,
4602        }
4603    }
4604
4605    /// Create a new UnaryFunc with an original name for round-trip preservation
4606    pub fn with_name(this: Expression, name: String) -> Self {
4607        Self {
4608            this,
4609            original_name: Some(name),
4610            inferred_type: None,
4611        }
4612    }
4613}
4614
4615/// CHAR/CHR function with multiple args and optional USING charset
4616/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4617/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4619#[cfg_attr(feature = "bindings", derive(TS))]
4620pub struct CharFunc {
4621    pub args: Vec<Expression>,
4622    #[serde(skip_serializing_if = "Option::is_none", default)]
4623    pub charset: Option<String>,
4624    /// Original function name (CHAR or CHR), defaults to CHAR
4625    #[serde(skip_serializing_if = "Option::is_none", default)]
4626    pub name: Option<String>,
4627}
4628
4629/// Generic binary function (takes two arguments)
4630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4631#[cfg_attr(feature = "bindings", derive(TS))]
4632pub struct BinaryFunc {
4633    pub this: Expression,
4634    pub expression: Expression,
4635    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4636    #[serde(skip_serializing_if = "Option::is_none", default)]
4637    pub original_name: Option<String>,
4638    /// Inferred data type from type annotation
4639    #[serde(default, skip_serializing_if = "Option::is_none")]
4640    pub inferred_type: Option<DataType>,
4641}
4642
4643/// Variable argument function
4644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4645#[cfg_attr(feature = "bindings", derive(TS))]
4646pub struct VarArgFunc {
4647    pub expressions: Vec<Expression>,
4648    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4649    #[serde(skip_serializing_if = "Option::is_none", default)]
4650    pub original_name: Option<String>,
4651    /// Inferred data type from type annotation
4652    #[serde(default, skip_serializing_if = "Option::is_none")]
4653    pub inferred_type: Option<DataType>,
4654}
4655
4656/// CONCAT_WS function
4657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4658#[cfg_attr(feature = "bindings", derive(TS))]
4659pub struct ConcatWs {
4660    pub separator: Expression,
4661    pub expressions: Vec<Expression>,
4662}
4663
4664/// SUBSTRING function
4665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4666#[cfg_attr(feature = "bindings", derive(TS))]
4667pub struct SubstringFunc {
4668    pub this: Expression,
4669    pub start: Expression,
4670    pub length: Option<Expression>,
4671    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4672    #[serde(default)]
4673    pub from_for_syntax: bool,
4674}
4675
4676/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4678#[cfg_attr(feature = "bindings", derive(TS))]
4679pub struct OverlayFunc {
4680    pub this: Expression,
4681    pub replacement: Expression,
4682    pub from: Expression,
4683    pub length: Option<Expression>,
4684}
4685
4686/// TRIM function
4687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4688#[cfg_attr(feature = "bindings", derive(TS))]
4689pub struct TrimFunc {
4690    pub this: Expression,
4691    pub characters: Option<Expression>,
4692    pub position: TrimPosition,
4693    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4694    #[serde(default)]
4695    pub sql_standard_syntax: bool,
4696    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4697    #[serde(default)]
4698    pub position_explicit: bool,
4699}
4700
4701#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4702#[cfg_attr(feature = "bindings", derive(TS))]
4703pub enum TrimPosition {
4704    Both,
4705    Leading,
4706    Trailing,
4707}
4708
4709/// REPLACE function
4710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4711#[cfg_attr(feature = "bindings", derive(TS))]
4712pub struct ReplaceFunc {
4713    pub this: Expression,
4714    pub old: Expression,
4715    pub new: Expression,
4716}
4717
4718/// LEFT/RIGHT function
4719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4720#[cfg_attr(feature = "bindings", derive(TS))]
4721pub struct LeftRightFunc {
4722    pub this: Expression,
4723    pub length: Expression,
4724}
4725
4726/// REPEAT function
4727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4728#[cfg_attr(feature = "bindings", derive(TS))]
4729pub struct RepeatFunc {
4730    pub this: Expression,
4731    pub times: Expression,
4732}
4733
4734/// LPAD/RPAD function
4735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4736#[cfg_attr(feature = "bindings", derive(TS))]
4737pub struct PadFunc {
4738    pub this: Expression,
4739    pub length: Expression,
4740    pub fill: Option<Expression>,
4741}
4742
4743/// SPLIT function
4744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4745#[cfg_attr(feature = "bindings", derive(TS))]
4746pub struct SplitFunc {
4747    pub this: Expression,
4748    pub delimiter: Expression,
4749}
4750
4751/// REGEXP_LIKE function
4752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4753#[cfg_attr(feature = "bindings", derive(TS))]
4754pub struct RegexpFunc {
4755    pub this: Expression,
4756    pub pattern: Expression,
4757    pub flags: Option<Expression>,
4758}
4759
4760/// REGEXP_REPLACE function
4761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4762#[cfg_attr(feature = "bindings", derive(TS))]
4763pub struct RegexpReplaceFunc {
4764    pub this: Expression,
4765    pub pattern: Expression,
4766    pub replacement: Expression,
4767    pub flags: Option<Expression>,
4768}
4769
4770/// REGEXP_EXTRACT function
4771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4772#[cfg_attr(feature = "bindings", derive(TS))]
4773pub struct RegexpExtractFunc {
4774    pub this: Expression,
4775    pub pattern: Expression,
4776    pub group: Option<Expression>,
4777}
4778
4779/// ROUND function
4780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4781#[cfg_attr(feature = "bindings", derive(TS))]
4782pub struct RoundFunc {
4783    pub this: Expression,
4784    pub decimals: Option<Expression>,
4785}
4786
4787/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4789#[cfg_attr(feature = "bindings", derive(TS))]
4790pub struct FloorFunc {
4791    pub this: Expression,
4792    pub scale: Option<Expression>,
4793    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4794    #[serde(skip_serializing_if = "Option::is_none", default)]
4795    pub to: Option<Expression>,
4796}
4797
4798/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4800#[cfg_attr(feature = "bindings", derive(TS))]
4801pub struct CeilFunc {
4802    pub this: Expression,
4803    #[serde(skip_serializing_if = "Option::is_none", default)]
4804    pub decimals: Option<Expression>,
4805    /// Time unit for Druid-style CEIL(time TO unit) syntax
4806    #[serde(skip_serializing_if = "Option::is_none", default)]
4807    pub to: Option<Expression>,
4808}
4809
4810/// LOG function
4811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4812#[cfg_attr(feature = "bindings", derive(TS))]
4813pub struct LogFunc {
4814    pub this: Expression,
4815    pub base: Option<Expression>,
4816}
4817
4818/// CURRENT_DATE (no arguments)
4819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4820#[cfg_attr(feature = "bindings", derive(TS))]
4821pub struct CurrentDate;
4822
4823/// CURRENT_TIME
4824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4825#[cfg_attr(feature = "bindings", derive(TS))]
4826pub struct CurrentTime {
4827    pub precision: Option<u32>,
4828}
4829
4830/// CURRENT_TIMESTAMP
4831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4832#[cfg_attr(feature = "bindings", derive(TS))]
4833pub struct CurrentTimestamp {
4834    pub precision: Option<u32>,
4835    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4836    #[serde(default)]
4837    pub sysdate: bool,
4838}
4839
4840/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4842#[cfg_attr(feature = "bindings", derive(TS))]
4843pub struct CurrentTimestampLTZ {
4844    pub precision: Option<u32>,
4845}
4846
4847/// AT TIME ZONE expression for timezone conversion
4848#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4849#[cfg_attr(feature = "bindings", derive(TS))]
4850pub struct AtTimeZone {
4851    /// The expression to convert
4852    pub this: Expression,
4853    /// The target timezone
4854    pub zone: Expression,
4855}
4856
4857/// DATE_ADD / DATE_SUB function
4858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4859#[cfg_attr(feature = "bindings", derive(TS))]
4860pub struct DateAddFunc {
4861    pub this: Expression,
4862    pub interval: Expression,
4863    pub unit: IntervalUnit,
4864}
4865
4866/// DATEDIFF function
4867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4868#[cfg_attr(feature = "bindings", derive(TS))]
4869pub struct DateDiffFunc {
4870    pub this: Expression,
4871    pub expression: Expression,
4872    pub unit: Option<IntervalUnit>,
4873}
4874
4875/// DATE_TRUNC function
4876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4877#[cfg_attr(feature = "bindings", derive(TS))]
4878pub struct DateTruncFunc {
4879    pub this: Expression,
4880    pub unit: DateTimeField,
4881}
4882
4883/// EXTRACT function
4884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4885#[cfg_attr(feature = "bindings", derive(TS))]
4886pub struct ExtractFunc {
4887    pub this: Expression,
4888    pub field: DateTimeField,
4889}
4890
4891#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4892#[cfg_attr(feature = "bindings", derive(TS))]
4893pub enum DateTimeField {
4894    Year,
4895    Month,
4896    Day,
4897    Hour,
4898    Minute,
4899    Second,
4900    Millisecond,
4901    Microsecond,
4902    DayOfWeek,
4903    DayOfYear,
4904    Week,
4905    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4906    WeekWithModifier(String),
4907    Quarter,
4908    Epoch,
4909    Timezone,
4910    TimezoneHour,
4911    TimezoneMinute,
4912    Date,
4913    Time,
4914    /// Custom datetime field for dialect-specific or arbitrary fields
4915    Custom(String),
4916}
4917
4918/// TO_DATE function
4919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4920#[cfg_attr(feature = "bindings", derive(TS))]
4921pub struct ToDateFunc {
4922    pub this: Expression,
4923    pub format: Option<Expression>,
4924}
4925
4926/// TO_TIMESTAMP function
4927#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4928#[cfg_attr(feature = "bindings", derive(TS))]
4929pub struct ToTimestampFunc {
4930    pub this: Expression,
4931    pub format: Option<Expression>,
4932}
4933
4934/// IF function
4935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4936#[cfg_attr(feature = "bindings", derive(TS))]
4937pub struct IfFunc {
4938    pub condition: Expression,
4939    pub true_value: Expression,
4940    pub false_value: Option<Expression>,
4941    /// Original function name (IF, IFF, IIF) for round-trip preservation
4942    #[serde(skip_serializing_if = "Option::is_none", default)]
4943    pub original_name: Option<String>,
4944    /// Inferred data type from type annotation
4945    #[serde(default, skip_serializing_if = "Option::is_none")]
4946    pub inferred_type: Option<DataType>,
4947}
4948
4949/// NVL2 function
4950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4951#[cfg_attr(feature = "bindings", derive(TS))]
4952pub struct Nvl2Func {
4953    pub this: Expression,
4954    pub true_value: Expression,
4955    pub false_value: Expression,
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// ============================================================================
4962// Typed Aggregate Function types
4963// ============================================================================
4964
4965/// Generic aggregate function base type
4966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4967#[cfg_attr(feature = "bindings", derive(TS))]
4968pub struct AggFunc {
4969    pub this: Expression,
4970    pub distinct: bool,
4971    pub filter: Option<Expression>,
4972    pub order_by: Vec<Ordered>,
4973    /// Original function name (case-preserving) when parsed from SQL
4974    #[serde(skip_serializing_if = "Option::is_none", default)]
4975    pub name: Option<String>,
4976    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4977    #[serde(skip_serializing_if = "Option::is_none", default)]
4978    pub ignore_nulls: Option<bool>,
4979    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4980    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4981    #[serde(skip_serializing_if = "Option::is_none", default)]
4982    pub having_max: Option<(Box<Expression>, bool)>,
4983    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4984    #[serde(skip_serializing_if = "Option::is_none", default)]
4985    pub limit: Option<Box<Expression>>,
4986    /// Inferred data type from type annotation
4987    #[serde(default, skip_serializing_if = "Option::is_none")]
4988    pub inferred_type: Option<DataType>,
4989}
4990
4991/// COUNT function with optional star
4992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4993#[cfg_attr(feature = "bindings", derive(TS))]
4994pub struct CountFunc {
4995    pub this: Option<Expression>,
4996    pub star: bool,
4997    pub distinct: bool,
4998    pub filter: Option<Expression>,
4999    /// IGNORE NULLS (true) or RESPECT NULLS (false)
5000    #[serde(default, skip_serializing_if = "Option::is_none")]
5001    pub ignore_nulls: Option<bool>,
5002    /// Original function name for case preservation (e.g., "count" or "COUNT")
5003    #[serde(default, skip_serializing_if = "Option::is_none")]
5004    pub original_name: Option<String>,
5005    /// Inferred data type from type annotation
5006    #[serde(default, skip_serializing_if = "Option::is_none")]
5007    pub inferred_type: Option<DataType>,
5008}
5009
5010/// GROUP_CONCAT function (MySQL style)
5011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5012#[cfg_attr(feature = "bindings", derive(TS))]
5013pub struct GroupConcatFunc {
5014    pub this: Expression,
5015    pub separator: Option<Expression>,
5016    pub order_by: Option<Vec<Ordered>>,
5017    pub distinct: bool,
5018    pub filter: Option<Expression>,
5019    /// Inferred data type from type annotation
5020    #[serde(default, skip_serializing_if = "Option::is_none")]
5021    pub inferred_type: Option<DataType>,
5022}
5023
5024/// STRING_AGG function (PostgreSQL/Standard SQL)
5025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5026#[cfg_attr(feature = "bindings", derive(TS))]
5027pub struct StringAggFunc {
5028    pub this: Expression,
5029    #[serde(default)]
5030    pub separator: Option<Expression>,
5031    #[serde(default)]
5032    pub order_by: Option<Vec<Ordered>>,
5033    #[serde(default)]
5034    pub distinct: bool,
5035    #[serde(default)]
5036    pub filter: Option<Expression>,
5037    /// BigQuery LIMIT inside STRING_AGG
5038    #[serde(default, skip_serializing_if = "Option::is_none")]
5039    pub limit: Option<Box<Expression>>,
5040    /// Inferred data type from type annotation
5041    #[serde(default, skip_serializing_if = "Option::is_none")]
5042    pub inferred_type: Option<DataType>,
5043}
5044
5045/// LISTAGG function (Oracle style)
5046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5047#[cfg_attr(feature = "bindings", derive(TS))]
5048pub struct ListAggFunc {
5049    pub this: Expression,
5050    pub separator: Option<Expression>,
5051    pub on_overflow: Option<ListAggOverflow>,
5052    pub order_by: Option<Vec<Ordered>>,
5053    pub distinct: bool,
5054    pub filter: Option<Expression>,
5055    /// Inferred data type from type annotation
5056    #[serde(default, skip_serializing_if = "Option::is_none")]
5057    pub inferred_type: Option<DataType>,
5058}
5059
5060/// LISTAGG ON OVERFLOW behavior
5061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5062#[cfg_attr(feature = "bindings", derive(TS))]
5063pub enum ListAggOverflow {
5064    Error,
5065    Truncate {
5066        filler: Option<Expression>,
5067        with_count: bool,
5068    },
5069}
5070
5071/// SUM_IF / COUNT_IF function
5072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5073#[cfg_attr(feature = "bindings", derive(TS))]
5074pub struct SumIfFunc {
5075    pub this: Expression,
5076    pub condition: Expression,
5077    pub filter: Option<Expression>,
5078    /// Inferred data type from type annotation
5079    #[serde(default, skip_serializing_if = "Option::is_none")]
5080    pub inferred_type: Option<DataType>,
5081}
5082
5083/// APPROX_PERCENTILE function
5084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5085#[cfg_attr(feature = "bindings", derive(TS))]
5086pub struct ApproxPercentileFunc {
5087    pub this: Expression,
5088    pub percentile: Expression,
5089    pub accuracy: Option<Expression>,
5090    pub filter: Option<Expression>,
5091}
5092
5093/// PERCENTILE_CONT / PERCENTILE_DISC function
5094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5095#[cfg_attr(feature = "bindings", derive(TS))]
5096pub struct PercentileFunc {
5097    pub this: Expression,
5098    pub percentile: Expression,
5099    pub order_by: Option<Vec<Ordered>>,
5100    pub filter: Option<Expression>,
5101}
5102
5103// ============================================================================
5104// Typed Window Function types
5105// ============================================================================
5106
5107/// ROW_NUMBER function (no arguments)
5108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5109#[cfg_attr(feature = "bindings", derive(TS))]
5110pub struct RowNumber;
5111
5112/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5114#[cfg_attr(feature = "bindings", derive(TS))]
5115pub struct Rank {
5116    /// DuckDB: RANK(ORDER BY col) - order by inside function
5117    #[serde(default, skip_serializing_if = "Option::is_none")]
5118    pub order_by: Option<Vec<Ordered>>,
5119    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5120    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5121    pub args: Vec<Expression>,
5122}
5123
5124/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
5125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5126#[cfg_attr(feature = "bindings", derive(TS))]
5127pub struct DenseRank {
5128    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5129    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5130    pub args: Vec<Expression>,
5131}
5132
5133/// NTILE function (DuckDB allows ORDER BY inside)
5134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5135#[cfg_attr(feature = "bindings", derive(TS))]
5136pub struct NTileFunc {
5137    /// num_buckets is optional to support Databricks NTILE() without arguments
5138    #[serde(default, skip_serializing_if = "Option::is_none")]
5139    pub num_buckets: Option<Expression>,
5140    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
5141    #[serde(default, skip_serializing_if = "Option::is_none")]
5142    pub order_by: Option<Vec<Ordered>>,
5143}
5144
5145/// LEAD / LAG function
5146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5147#[cfg_attr(feature = "bindings", derive(TS))]
5148pub struct LeadLagFunc {
5149    pub this: Expression,
5150    pub offset: Option<Expression>,
5151    pub default: Option<Expression>,
5152    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5153    #[serde(default, skip_serializing_if = "Option::is_none")]
5154    pub ignore_nulls: Option<bool>,
5155}
5156
5157/// FIRST_VALUE / LAST_VALUE function
5158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5159#[cfg_attr(feature = "bindings", derive(TS))]
5160pub struct ValueFunc {
5161    pub this: Expression,
5162    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5163    #[serde(default, skip_serializing_if = "Option::is_none")]
5164    pub ignore_nulls: Option<bool>,
5165}
5166
5167/// NTH_VALUE function
5168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5169#[cfg_attr(feature = "bindings", derive(TS))]
5170pub struct NthValueFunc {
5171    pub this: Expression,
5172    pub offset: Expression,
5173    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5174    #[serde(default, skip_serializing_if = "Option::is_none")]
5175    pub ignore_nulls: Option<bool>,
5176    /// Snowflake FROM FIRST / FROM LAST clause
5177    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
5178    #[serde(default, skip_serializing_if = "Option::is_none")]
5179    pub from_first: Option<bool>,
5180}
5181
5182/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5184#[cfg_attr(feature = "bindings", derive(TS))]
5185pub struct PercentRank {
5186    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
5187    #[serde(default, skip_serializing_if = "Option::is_none")]
5188    pub order_by: Option<Vec<Ordered>>,
5189    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5190    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5191    pub args: Vec<Expression>,
5192}
5193
5194/// CUME_DIST 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 CumeDist {
5198    /// DuckDB: CUME_DIST(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: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5202    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5203    pub args: Vec<Expression>,
5204}
5205
5206// ============================================================================
5207// Additional String Function types
5208// ============================================================================
5209
5210/// POSITION/INSTR function
5211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5212#[cfg_attr(feature = "bindings", derive(TS))]
5213pub struct PositionFunc {
5214    pub substring: Expression,
5215    pub string: Expression,
5216    pub start: Option<Expression>,
5217}
5218
5219// ============================================================================
5220// Additional Math Function types
5221// ============================================================================
5222
5223/// RANDOM function (no arguments)
5224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5225#[cfg_attr(feature = "bindings", derive(TS))]
5226pub struct Random;
5227
5228/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
5229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5230#[cfg_attr(feature = "bindings", derive(TS))]
5231pub struct Rand {
5232    pub seed: Option<Box<Expression>>,
5233    /// Teradata RANDOM lower bound
5234    #[serde(default)]
5235    pub lower: Option<Box<Expression>>,
5236    /// Teradata RANDOM upper bound
5237    #[serde(default)]
5238    pub upper: Option<Box<Expression>>,
5239}
5240
5241/// TRUNCATE / TRUNC function
5242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5243#[cfg_attr(feature = "bindings", derive(TS))]
5244pub struct TruncateFunc {
5245    pub this: Expression,
5246    pub decimals: Option<Expression>,
5247}
5248
5249/// PI function (no arguments)
5250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5251#[cfg_attr(feature = "bindings", derive(TS))]
5252pub struct Pi;
5253
5254// ============================================================================
5255// Control Flow Function types
5256// ============================================================================
5257
5258/// DECODE function (Oracle style)
5259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5260#[cfg_attr(feature = "bindings", derive(TS))]
5261pub struct DecodeFunc {
5262    pub this: Expression,
5263    pub search_results: Vec<(Expression, Expression)>,
5264    pub default: Option<Expression>,
5265}
5266
5267// ============================================================================
5268// Additional Date/Time Function types
5269// ============================================================================
5270
5271/// DATE_FORMAT / FORMAT_DATE function
5272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5273#[cfg_attr(feature = "bindings", derive(TS))]
5274pub struct DateFormatFunc {
5275    pub this: Expression,
5276    pub format: Expression,
5277}
5278
5279/// FROM_UNIXTIME function
5280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5281#[cfg_attr(feature = "bindings", derive(TS))]
5282pub struct FromUnixtimeFunc {
5283    pub this: Expression,
5284    pub format: Option<Expression>,
5285}
5286
5287/// UNIX_TIMESTAMP function
5288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5289#[cfg_attr(feature = "bindings", derive(TS))]
5290pub struct UnixTimestampFunc {
5291    pub this: Option<Expression>,
5292    pub format: Option<Expression>,
5293}
5294
5295/// MAKE_DATE function
5296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5297#[cfg_attr(feature = "bindings", derive(TS))]
5298pub struct MakeDateFunc {
5299    pub year: Expression,
5300    pub month: Expression,
5301    pub day: Expression,
5302}
5303
5304/// MAKE_TIMESTAMP function
5305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5306#[cfg_attr(feature = "bindings", derive(TS))]
5307pub struct MakeTimestampFunc {
5308    pub year: Expression,
5309    pub month: Expression,
5310    pub day: Expression,
5311    pub hour: Expression,
5312    pub minute: Expression,
5313    pub second: Expression,
5314    pub timezone: Option<Expression>,
5315}
5316
5317/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
5318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5319#[cfg_attr(feature = "bindings", derive(TS))]
5320pub struct LastDayFunc {
5321    pub this: Expression,
5322    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
5323    #[serde(skip_serializing_if = "Option::is_none", default)]
5324    pub unit: Option<DateTimeField>,
5325}
5326
5327// ============================================================================
5328// Array Function types
5329// ============================================================================
5330
5331/// ARRAY constructor
5332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5333#[cfg_attr(feature = "bindings", derive(TS))]
5334pub struct ArrayConstructor {
5335    pub expressions: Vec<Expression>,
5336    pub bracket_notation: bool,
5337    /// True if LIST keyword was used instead of ARRAY (DuckDB)
5338    pub use_list_keyword: bool,
5339}
5340
5341/// ARRAY_SORT function
5342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5343#[cfg_attr(feature = "bindings", derive(TS))]
5344pub struct ArraySortFunc {
5345    pub this: Expression,
5346    pub comparator: Option<Expression>,
5347    pub desc: bool,
5348    pub nulls_first: Option<bool>,
5349}
5350
5351/// ARRAY_JOIN / ARRAY_TO_STRING function
5352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5353#[cfg_attr(feature = "bindings", derive(TS))]
5354pub struct ArrayJoinFunc {
5355    pub this: Expression,
5356    pub separator: Expression,
5357    pub null_replacement: Option<Expression>,
5358}
5359
5360/// UNNEST function
5361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5362#[cfg_attr(feature = "bindings", derive(TS))]
5363pub struct UnnestFunc {
5364    pub this: Expression,
5365    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
5366    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5367    pub expressions: Vec<Expression>,
5368    pub with_ordinality: bool,
5369    pub alias: Option<Identifier>,
5370    /// BigQuery: offset alias for WITH OFFSET AS <name>
5371    #[serde(default, skip_serializing_if = "Option::is_none")]
5372    pub offset_alias: Option<Identifier>,
5373}
5374
5375/// ARRAY_FILTER function (with lambda)
5376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5377#[cfg_attr(feature = "bindings", derive(TS))]
5378pub struct ArrayFilterFunc {
5379    pub this: Expression,
5380    pub filter: Expression,
5381}
5382
5383/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
5384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5385#[cfg_attr(feature = "bindings", derive(TS))]
5386pub struct ArrayTransformFunc {
5387    pub this: Expression,
5388    pub transform: Expression,
5389}
5390
5391/// SEQUENCE / GENERATE_SERIES function
5392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5393#[cfg_attr(feature = "bindings", derive(TS))]
5394pub struct SequenceFunc {
5395    pub start: Expression,
5396    pub stop: Expression,
5397    pub step: Option<Expression>,
5398}
5399
5400// ============================================================================
5401// Struct Function types
5402// ============================================================================
5403
5404/// STRUCT constructor
5405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5406#[cfg_attr(feature = "bindings", derive(TS))]
5407pub struct StructConstructor {
5408    pub fields: Vec<(Option<Identifier>, Expression)>,
5409}
5410
5411/// STRUCT_EXTRACT function
5412#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5413#[cfg_attr(feature = "bindings", derive(TS))]
5414pub struct StructExtractFunc {
5415    pub this: Expression,
5416    pub field: Identifier,
5417}
5418
5419/// NAMED_STRUCT function
5420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5421#[cfg_attr(feature = "bindings", derive(TS))]
5422pub struct NamedStructFunc {
5423    pub pairs: Vec<(Expression, Expression)>,
5424}
5425
5426// ============================================================================
5427// Map Function types
5428// ============================================================================
5429
5430/// MAP constructor
5431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5432#[cfg_attr(feature = "bindings", derive(TS))]
5433pub struct MapConstructor {
5434    pub keys: Vec<Expression>,
5435    pub values: Vec<Expression>,
5436    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
5437    #[serde(default)]
5438    pub curly_brace_syntax: bool,
5439    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
5440    #[serde(default)]
5441    pub with_map_keyword: bool,
5442}
5443
5444/// TRANSFORM_KEYS / TRANSFORM_VALUES function
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct TransformFunc {
5448    pub this: Expression,
5449    pub transform: Expression,
5450}
5451
5452// ============================================================================
5453// JSON Function types
5454// ============================================================================
5455
5456/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
5457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5458#[cfg_attr(feature = "bindings", derive(TS))]
5459pub struct JsonExtractFunc {
5460    pub this: Expression,
5461    pub path: Expression,
5462    pub returning: Option<DataType>,
5463    /// True if parsed from -> or ->> operator syntax
5464    #[serde(default)]
5465    pub arrow_syntax: bool,
5466    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
5467    #[serde(default)]
5468    pub hash_arrow_syntax: bool,
5469    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
5470    #[serde(default)]
5471    pub wrapper_option: Option<String>,
5472    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
5473    #[serde(default)]
5474    pub quotes_option: Option<String>,
5475    /// ON SCALAR STRING flag
5476    #[serde(default)]
5477    pub on_scalar_string: bool,
5478    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
5479    #[serde(default)]
5480    pub on_error: Option<String>,
5481}
5482
5483/// JSON path extraction
5484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5485#[cfg_attr(feature = "bindings", derive(TS))]
5486pub struct JsonPathFunc {
5487    pub this: Expression,
5488    pub paths: Vec<Expression>,
5489}
5490
5491/// JSON_OBJECT function
5492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5493#[cfg_attr(feature = "bindings", derive(TS))]
5494pub struct JsonObjectFunc {
5495    pub pairs: Vec<(Expression, Expression)>,
5496    pub null_handling: Option<JsonNullHandling>,
5497    #[serde(default)]
5498    pub with_unique_keys: bool,
5499    #[serde(default)]
5500    pub returning_type: Option<DataType>,
5501    #[serde(default)]
5502    pub format_json: bool,
5503    #[serde(default)]
5504    pub encoding: Option<String>,
5505    /// For JSON_OBJECT(*) syntax
5506    #[serde(default)]
5507    pub star: bool,
5508}
5509
5510/// JSON null handling options
5511#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5512#[cfg_attr(feature = "bindings", derive(TS))]
5513pub enum JsonNullHandling {
5514    NullOnNull,
5515    AbsentOnNull,
5516}
5517
5518/// JSON_SET / JSON_INSERT function
5519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5520#[cfg_attr(feature = "bindings", derive(TS))]
5521pub struct JsonModifyFunc {
5522    pub this: Expression,
5523    pub path_values: Vec<(Expression, Expression)>,
5524}
5525
5526/// JSON_ARRAYAGG function
5527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5528#[cfg_attr(feature = "bindings", derive(TS))]
5529pub struct JsonArrayAggFunc {
5530    pub this: Expression,
5531    pub order_by: Option<Vec<Ordered>>,
5532    pub null_handling: Option<JsonNullHandling>,
5533    pub filter: Option<Expression>,
5534}
5535
5536/// JSON_OBJECTAGG function
5537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5538#[cfg_attr(feature = "bindings", derive(TS))]
5539pub struct JsonObjectAggFunc {
5540    pub key: Expression,
5541    pub value: Expression,
5542    pub null_handling: Option<JsonNullHandling>,
5543    pub filter: Option<Expression>,
5544}
5545
5546// ============================================================================
5547// Type Casting Function types
5548// ============================================================================
5549
5550/// CONVERT function (SQL Server style)
5551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5552#[cfg_attr(feature = "bindings", derive(TS))]
5553pub struct ConvertFunc {
5554    pub this: Expression,
5555    pub to: DataType,
5556    pub style: Option<Expression>,
5557}
5558
5559// ============================================================================
5560// Additional Expression types
5561// ============================================================================
5562
5563/// Lambda expression
5564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5565#[cfg_attr(feature = "bindings", derive(TS))]
5566pub struct LambdaExpr {
5567    pub parameters: Vec<Identifier>,
5568    pub body: Expression,
5569    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5570    #[serde(default)]
5571    pub colon: bool,
5572    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5573    /// Maps parameter index to data type
5574    #[serde(default)]
5575    pub parameter_types: Vec<Option<DataType>>,
5576}
5577
5578/// Parameter (parameterized queries)
5579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5580#[cfg_attr(feature = "bindings", derive(TS))]
5581pub struct Parameter {
5582    pub name: Option<String>,
5583    pub index: Option<u32>,
5584    pub style: ParameterStyle,
5585    /// Whether the name was quoted (e.g., @"x" vs @x)
5586    #[serde(default)]
5587    pub quoted: bool,
5588    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5589    #[serde(default)]
5590    pub string_quoted: bool,
5591    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5592    #[serde(default)]
5593    pub expression: Option<String>,
5594}
5595
5596/// Parameter placeholder styles
5597#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5598#[cfg_attr(feature = "bindings", derive(TS))]
5599pub enum ParameterStyle {
5600    Question,     // ?
5601    Dollar,       // $1, $2
5602    DollarBrace,  // ${name} (Databricks, Hive template variables)
5603    Brace,        // {name} (Spark/Databricks widget/template variables)
5604    Colon,        // :name
5605    At,           // @name
5606    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5607    DoubleDollar, // $$name
5608    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5609}
5610
5611/// Placeholder expression
5612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5613#[cfg_attr(feature = "bindings", derive(TS))]
5614pub struct Placeholder {
5615    pub index: Option<u32>,
5616}
5617
5618/// Named argument in function call: name => value or name := value
5619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5620#[cfg_attr(feature = "bindings", derive(TS))]
5621pub struct NamedArgument {
5622    pub name: Identifier,
5623    pub value: Expression,
5624    /// The separator used: `=>`, `:=`, or `=`
5625    pub separator: NamedArgSeparator,
5626}
5627
5628/// Separator style for named arguments
5629#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5630#[cfg_attr(feature = "bindings", derive(TS))]
5631pub enum NamedArgSeparator {
5632    /// `=>` (standard SQL, Snowflake, BigQuery)
5633    DArrow,
5634    /// `:=` (Oracle, MySQL)
5635    ColonEq,
5636    /// `=` (simple equals, some dialects)
5637    Eq,
5638}
5639
5640/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5641/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5643#[cfg_attr(feature = "bindings", derive(TS))]
5644pub struct TableArgument {
5645    /// The keyword prefix: "TABLE" or "MODEL"
5646    pub prefix: String,
5647    /// The table/model reference expression
5648    pub this: Expression,
5649}
5650
5651/// SQL Comment preservation
5652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5653#[cfg_attr(feature = "bindings", derive(TS))]
5654pub struct SqlComment {
5655    pub text: String,
5656    pub is_block: bool,
5657}
5658
5659// ============================================================================
5660// Additional Predicate types
5661// ============================================================================
5662
5663/// SIMILAR TO expression
5664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5665#[cfg_attr(feature = "bindings", derive(TS))]
5666pub struct SimilarToExpr {
5667    pub this: Expression,
5668    pub pattern: Expression,
5669    pub escape: Option<Expression>,
5670    pub not: bool,
5671}
5672
5673/// ANY / ALL quantified expression
5674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5675#[cfg_attr(feature = "bindings", derive(TS))]
5676pub struct QuantifiedExpr {
5677    pub this: Expression,
5678    pub subquery: Expression,
5679    pub op: Option<QuantifiedOp>,
5680}
5681
5682/// Comparison operator for quantified expressions
5683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5684#[cfg_attr(feature = "bindings", derive(TS))]
5685pub enum QuantifiedOp {
5686    Eq,
5687    Neq,
5688    Lt,
5689    Lte,
5690    Gt,
5691    Gte,
5692}
5693
5694/// OVERLAPS expression
5695/// Supports two forms:
5696/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5697/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5699#[cfg_attr(feature = "bindings", derive(TS))]
5700pub struct OverlapsExpr {
5701    /// Left operand for simple binary form
5702    #[serde(skip_serializing_if = "Option::is_none")]
5703    pub this: Option<Expression>,
5704    /// Right operand for simple binary form
5705    #[serde(skip_serializing_if = "Option::is_none")]
5706    pub expression: Option<Expression>,
5707    /// Left range start for full ANSI form
5708    #[serde(skip_serializing_if = "Option::is_none")]
5709    pub left_start: Option<Expression>,
5710    /// Left range end for full ANSI form
5711    #[serde(skip_serializing_if = "Option::is_none")]
5712    pub left_end: Option<Expression>,
5713    /// Right range start for full ANSI form
5714    #[serde(skip_serializing_if = "Option::is_none")]
5715    pub right_start: Option<Expression>,
5716    /// Right range end for full ANSI form
5717    #[serde(skip_serializing_if = "Option::is_none")]
5718    pub right_end: Option<Expression>,
5719}
5720
5721// ============================================================================
5722// Array/Struct/Map access
5723// ============================================================================
5724
5725/// Subscript access (array[index] or map[key])
5726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5727#[cfg_attr(feature = "bindings", derive(TS))]
5728pub struct Subscript {
5729    pub this: Expression,
5730    pub index: Expression,
5731}
5732
5733/// Dot access (struct.field)
5734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5735#[cfg_attr(feature = "bindings", derive(TS))]
5736pub struct DotAccess {
5737    pub this: Expression,
5738    pub field: Identifier,
5739}
5740
5741/// Method call (expr.method(args))
5742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5743#[cfg_attr(feature = "bindings", derive(TS))]
5744pub struct MethodCall {
5745    pub this: Expression,
5746    pub method: Identifier,
5747    pub args: Vec<Expression>,
5748}
5749
5750/// Array slice (array[start:end])
5751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5752#[cfg_attr(feature = "bindings", derive(TS))]
5753pub struct ArraySlice {
5754    pub this: Expression,
5755    pub start: Option<Expression>,
5756    pub end: Option<Expression>,
5757}
5758
5759// ============================================================================
5760// DDL (Data Definition Language) Statements
5761// ============================================================================
5762
5763/// ON COMMIT behavior for temporary tables
5764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5765#[cfg_attr(feature = "bindings", derive(TS))]
5766pub enum OnCommit {
5767    /// ON COMMIT PRESERVE ROWS
5768    PreserveRows,
5769    /// ON COMMIT DELETE ROWS
5770    DeleteRows,
5771}
5772
5773/// CREATE TABLE statement
5774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5775#[cfg_attr(feature = "bindings", derive(TS))]
5776pub struct CreateTable {
5777    pub name: TableRef,
5778    /// ClickHouse: ON CLUSTER clause for distributed DDL
5779    #[serde(default, skip_serializing_if = "Option::is_none")]
5780    pub on_cluster: Option<OnCluster>,
5781    pub columns: Vec<ColumnDef>,
5782    pub constraints: Vec<TableConstraint>,
5783    pub if_not_exists: bool,
5784    pub temporary: bool,
5785    pub or_replace: bool,
5786    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5787    #[serde(default, skip_serializing_if = "Option::is_none")]
5788    pub table_modifier: Option<String>,
5789    pub as_select: Option<Expression>,
5790    /// Whether the AS SELECT was wrapped in parentheses
5791    #[serde(default)]
5792    pub as_select_parenthesized: bool,
5793    /// ON COMMIT behavior for temporary tables
5794    #[serde(default)]
5795    pub on_commit: Option<OnCommit>,
5796    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5797    #[serde(default)]
5798    pub clone_source: Option<TableRef>,
5799    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5800    #[serde(default, skip_serializing_if = "Option::is_none")]
5801    pub clone_at_clause: Option<Expression>,
5802    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5803    #[serde(default)]
5804    pub is_copy: bool,
5805    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5806    #[serde(default)]
5807    pub shallow_clone: bool,
5808    /// Leading comments before the statement
5809    #[serde(default)]
5810    pub leading_comments: Vec<String>,
5811    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5812    #[serde(default)]
5813    pub with_properties: Vec<(String, String)>,
5814    /// Teradata: table options after name before columns (comma-separated)
5815    #[serde(default)]
5816    pub teradata_post_name_options: Vec<String>,
5817    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5818    #[serde(default)]
5819    pub with_data: Option<bool>,
5820    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5821    #[serde(default)]
5822    pub with_statistics: Option<bool>,
5823    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5824    #[serde(default)]
5825    pub teradata_indexes: Vec<TeradataIndex>,
5826    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5827    #[serde(default)]
5828    pub with_cte: Option<With>,
5829    /// Table properties like DEFAULT COLLATE (BigQuery)
5830    #[serde(default)]
5831    pub properties: Vec<Expression>,
5832    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5833    #[serde(default, skip_serializing_if = "Option::is_none")]
5834    pub partition_of: Option<Expression>,
5835    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5836    #[serde(default)]
5837    pub post_table_properties: Vec<Expression>,
5838    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5839    #[serde(default)]
5840    pub mysql_table_options: Vec<(String, String)>,
5841    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5842    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5843    pub inherits: Vec<TableRef>,
5844    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5845    #[serde(default, skip_serializing_if = "Option::is_none")]
5846    pub on_property: Option<OnProperty>,
5847    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5848    #[serde(default)]
5849    pub copy_grants: bool,
5850    /// Snowflake: USING TEMPLATE expression for schema inference
5851    #[serde(default, skip_serializing_if = "Option::is_none")]
5852    pub using_template: Option<Box<Expression>>,
5853    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5854    #[serde(default, skip_serializing_if = "Option::is_none")]
5855    pub rollup: Option<RollupProperty>,
5856}
5857
5858/// Teradata index specification for CREATE TABLE
5859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5860#[cfg_attr(feature = "bindings", derive(TS))]
5861pub struct TeradataIndex {
5862    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5863    pub kind: TeradataIndexKind,
5864    /// Optional index name
5865    pub name: Option<String>,
5866    /// Optional column list
5867    pub columns: Vec<String>,
5868}
5869
5870/// Kind of Teradata index
5871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5872#[cfg_attr(feature = "bindings", derive(TS))]
5873pub enum TeradataIndexKind {
5874    /// NO PRIMARY INDEX
5875    NoPrimary,
5876    /// PRIMARY INDEX
5877    Primary,
5878    /// PRIMARY AMP INDEX
5879    PrimaryAmp,
5880    /// UNIQUE INDEX
5881    Unique,
5882    /// UNIQUE PRIMARY INDEX
5883    UniquePrimary,
5884    /// INDEX (secondary, non-primary)
5885    Secondary,
5886}
5887
5888impl CreateTable {
5889    pub fn new(name: impl Into<String>) -> Self {
5890        Self {
5891            name: TableRef::new(name),
5892            on_cluster: None,
5893            columns: Vec::new(),
5894            constraints: Vec::new(),
5895            if_not_exists: false,
5896            temporary: false,
5897            or_replace: false,
5898            table_modifier: None,
5899            as_select: None,
5900            as_select_parenthesized: false,
5901            on_commit: None,
5902            clone_source: None,
5903            clone_at_clause: None,
5904            shallow_clone: false,
5905            is_copy: false,
5906            leading_comments: Vec::new(),
5907            with_properties: Vec::new(),
5908            teradata_post_name_options: Vec::new(),
5909            with_data: None,
5910            with_statistics: None,
5911            teradata_indexes: Vec::new(),
5912            with_cte: None,
5913            properties: Vec::new(),
5914            partition_of: None,
5915            post_table_properties: Vec::new(),
5916            mysql_table_options: Vec::new(),
5917            inherits: Vec::new(),
5918            on_property: None,
5919            copy_grants: false,
5920            using_template: None,
5921            rollup: None,
5922        }
5923    }
5924}
5925
5926/// Sort order for PRIMARY KEY ASC/DESC
5927#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5928#[cfg_attr(feature = "bindings", derive(TS))]
5929pub enum SortOrder {
5930    Asc,
5931    Desc,
5932}
5933
5934/// Type of column constraint for tracking order
5935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5936#[cfg_attr(feature = "bindings", derive(TS))]
5937pub enum ConstraintType {
5938    NotNull,
5939    Null,
5940    PrimaryKey,
5941    Unique,
5942    Default,
5943    AutoIncrement,
5944    Collate,
5945    Comment,
5946    References,
5947    Check,
5948    GeneratedAsIdentity,
5949    /// Snowflake: TAG (key='value', ...)
5950    Tags,
5951    /// Computed/generated column
5952    ComputedColumn,
5953    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5954    GeneratedAsRow,
5955    /// MySQL: ON UPDATE expression
5956    OnUpdate,
5957    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5958    Path,
5959    /// Redshift: ENCODE encoding_type
5960    Encode,
5961}
5962
5963/// Column definition in CREATE TABLE
5964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5965#[cfg_attr(feature = "bindings", derive(TS))]
5966pub struct ColumnDef {
5967    pub name: Identifier,
5968    pub data_type: DataType,
5969    pub nullable: Option<bool>,
5970    pub default: Option<Expression>,
5971    pub primary_key: bool,
5972    /// Sort order for PRIMARY KEY (ASC/DESC)
5973    #[serde(default)]
5974    pub primary_key_order: Option<SortOrder>,
5975    pub unique: bool,
5976    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5977    #[serde(default)]
5978    pub unique_nulls_not_distinct: bool,
5979    pub auto_increment: bool,
5980    pub comment: Option<String>,
5981    pub constraints: Vec<ColumnConstraint>,
5982    /// Track original order of constraints for accurate regeneration
5983    #[serde(default)]
5984    pub constraint_order: Vec<ConstraintType>,
5985    /// Teradata: FORMAT 'pattern'
5986    #[serde(default)]
5987    pub format: Option<String>,
5988    /// Teradata: TITLE 'title'
5989    #[serde(default)]
5990    pub title: Option<String>,
5991    /// Teradata: INLINE LENGTH n
5992    #[serde(default)]
5993    pub inline_length: Option<u64>,
5994    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5995    #[serde(default)]
5996    pub compress: Option<Vec<Expression>>,
5997    /// Teradata: CHARACTER SET name
5998    #[serde(default)]
5999    pub character_set: Option<String>,
6000    /// Teradata: UPPERCASE
6001    #[serde(default)]
6002    pub uppercase: bool,
6003    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
6004    #[serde(default)]
6005    pub casespecific: Option<bool>,
6006    /// Snowflake: AUTOINCREMENT START value
6007    #[serde(default)]
6008    pub auto_increment_start: Option<Box<Expression>>,
6009    /// Snowflake: AUTOINCREMENT INCREMENT value
6010    #[serde(default)]
6011    pub auto_increment_increment: Option<Box<Expression>>,
6012    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
6013    #[serde(default)]
6014    pub auto_increment_order: Option<bool>,
6015    /// MySQL: UNSIGNED modifier
6016    #[serde(default)]
6017    pub unsigned: bool,
6018    /// MySQL: ZEROFILL modifier
6019    #[serde(default)]
6020    pub zerofill: bool,
6021    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
6022    #[serde(default, skip_serializing_if = "Option::is_none")]
6023    pub on_update: Option<Expression>,
6024    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
6025    #[serde(default, skip_serializing_if = "Option::is_none")]
6026    pub unique_constraint_name: Option<String>,
6027    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
6028    #[serde(default, skip_serializing_if = "Option::is_none")]
6029    pub not_null_constraint_name: Option<String>,
6030    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
6031    #[serde(default, skip_serializing_if = "Option::is_none")]
6032    pub primary_key_constraint_name: Option<String>,
6033    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
6034    #[serde(default, skip_serializing_if = "Option::is_none")]
6035    pub check_constraint_name: Option<String>,
6036    /// BigQuery: OPTIONS (key=value, ...) on column
6037    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6038    pub options: Vec<Expression>,
6039    /// SQLite: Column definition without explicit type
6040    #[serde(default)]
6041    pub no_type: bool,
6042    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
6043    #[serde(default, skip_serializing_if = "Option::is_none")]
6044    pub encoding: Option<String>,
6045    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
6046    #[serde(default, skip_serializing_if = "Option::is_none")]
6047    pub codec: Option<String>,
6048    /// ClickHouse: EPHEMERAL [expr] modifier
6049    #[serde(default, skip_serializing_if = "Option::is_none")]
6050    pub ephemeral: Option<Option<Box<Expression>>>,
6051    /// ClickHouse: MATERIALIZED expr modifier
6052    #[serde(default, skip_serializing_if = "Option::is_none")]
6053    pub materialized_expr: Option<Box<Expression>>,
6054    /// ClickHouse: ALIAS expr modifier
6055    #[serde(default, skip_serializing_if = "Option::is_none")]
6056    pub alias_expr: Option<Box<Expression>>,
6057    /// ClickHouse: TTL expr modifier on columns
6058    #[serde(default, skip_serializing_if = "Option::is_none")]
6059    pub ttl_expr: Option<Box<Expression>>,
6060    /// TSQL: NOT FOR REPLICATION
6061    #[serde(default)]
6062    pub not_for_replication: bool,
6063}
6064
6065impl ColumnDef {
6066    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
6067        Self {
6068            name: Identifier::new(name),
6069            data_type,
6070            nullable: None,
6071            default: None,
6072            primary_key: false,
6073            primary_key_order: None,
6074            unique: false,
6075            unique_nulls_not_distinct: false,
6076            auto_increment: false,
6077            comment: None,
6078            constraints: Vec::new(),
6079            constraint_order: Vec::new(),
6080            format: None,
6081            title: None,
6082            inline_length: None,
6083            compress: None,
6084            character_set: None,
6085            uppercase: false,
6086            casespecific: None,
6087            auto_increment_start: None,
6088            auto_increment_increment: None,
6089            auto_increment_order: None,
6090            unsigned: false,
6091            zerofill: false,
6092            on_update: None,
6093            unique_constraint_name: None,
6094            not_null_constraint_name: None,
6095            primary_key_constraint_name: None,
6096            check_constraint_name: None,
6097            options: Vec::new(),
6098            no_type: false,
6099            encoding: None,
6100            codec: None,
6101            ephemeral: None,
6102            materialized_expr: None,
6103            alias_expr: None,
6104            ttl_expr: None,
6105            not_for_replication: false,
6106        }
6107    }
6108}
6109
6110/// Column-level constraint
6111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6112#[cfg_attr(feature = "bindings", derive(TS))]
6113pub enum ColumnConstraint {
6114    NotNull,
6115    Null,
6116    Unique,
6117    PrimaryKey,
6118    Default(Expression),
6119    Check(Expression),
6120    References(ForeignKeyRef),
6121    GeneratedAsIdentity(GeneratedAsIdentity),
6122    Collate(Identifier),
6123    Comment(String),
6124    /// Snowflake: TAG (key='value', ...)
6125    Tags(Tags),
6126    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
6127    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
6128    ComputedColumn(ComputedColumn),
6129    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6130    GeneratedAsRow(GeneratedAsRow),
6131    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
6132    Path(Expression),
6133}
6134
6135/// Computed/generated column constraint
6136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6137#[cfg_attr(feature = "bindings", derive(TS))]
6138pub struct ComputedColumn {
6139    /// The expression that computes the column value
6140    pub expression: Box<Expression>,
6141    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
6142    #[serde(default)]
6143    pub persisted: bool,
6144    /// NOT NULL (TSQL computed columns)
6145    #[serde(default)]
6146    pub not_null: bool,
6147    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
6148    /// When None, defaults to dialect-appropriate output
6149    #[serde(default)]
6150    pub persistence_kind: Option<String>,
6151    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
6152    #[serde(default, skip_serializing_if = "Option::is_none")]
6153    pub data_type: Option<DataType>,
6154}
6155
6156/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6158#[cfg_attr(feature = "bindings", derive(TS))]
6159pub struct GeneratedAsRow {
6160    /// true = ROW START, false = ROW END
6161    pub start: bool,
6162    /// HIDDEN modifier
6163    #[serde(default)]
6164    pub hidden: bool,
6165}
6166
6167/// Generated identity column constraint
6168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6169#[cfg_attr(feature = "bindings", derive(TS))]
6170pub struct GeneratedAsIdentity {
6171    /// True for ALWAYS, False for BY DEFAULT
6172    pub always: bool,
6173    /// ON NULL (only valid with BY DEFAULT)
6174    pub on_null: bool,
6175    /// START WITH value
6176    pub start: Option<Box<Expression>>,
6177    /// INCREMENT BY value
6178    pub increment: Option<Box<Expression>>,
6179    /// MINVALUE
6180    pub minvalue: Option<Box<Expression>>,
6181    /// MAXVALUE
6182    pub maxvalue: Option<Box<Expression>>,
6183    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
6184    pub cycle: Option<bool>,
6185}
6186
6187/// Constraint modifiers (shared between table-level constraints)
6188#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
6189#[cfg_attr(feature = "bindings", derive(TS))]
6190pub struct ConstraintModifiers {
6191    /// ENFORCED / NOT ENFORCED
6192    pub enforced: Option<bool>,
6193    /// DEFERRABLE / NOT DEFERRABLE
6194    pub deferrable: Option<bool>,
6195    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
6196    pub initially_deferred: Option<bool>,
6197    /// NORELY (Oracle)
6198    pub norely: bool,
6199    /// RELY (Oracle)
6200    pub rely: bool,
6201    /// USING index type (MySQL): BTREE or HASH
6202    #[serde(default)]
6203    pub using: Option<String>,
6204    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
6205    #[serde(default)]
6206    pub using_before_columns: bool,
6207    /// MySQL index COMMENT 'text'
6208    #[serde(default, skip_serializing_if = "Option::is_none")]
6209    pub comment: Option<String>,
6210    /// MySQL index VISIBLE/INVISIBLE
6211    #[serde(default, skip_serializing_if = "Option::is_none")]
6212    pub visible: Option<bool>,
6213    /// MySQL ENGINE_ATTRIBUTE = 'value'
6214    #[serde(default, skip_serializing_if = "Option::is_none")]
6215    pub engine_attribute: Option<String>,
6216    /// MySQL WITH PARSER name
6217    #[serde(default, skip_serializing_if = "Option::is_none")]
6218    pub with_parser: Option<String>,
6219    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
6220    #[serde(default)]
6221    pub not_valid: bool,
6222    /// TSQL CLUSTERED/NONCLUSTERED modifier
6223    #[serde(default, skip_serializing_if = "Option::is_none")]
6224    pub clustered: Option<String>,
6225    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
6226    #[serde(default, skip_serializing_if = "Option::is_none")]
6227    pub on_conflict: Option<String>,
6228    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
6229    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6230    pub with_options: Vec<(String, String)>,
6231    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
6232    #[serde(default, skip_serializing_if = "Option::is_none")]
6233    pub on_filegroup: Option<Identifier>,
6234}
6235
6236/// Table-level constraint
6237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6238#[cfg_attr(feature = "bindings", derive(TS))]
6239pub enum TableConstraint {
6240    PrimaryKey {
6241        name: Option<Identifier>,
6242        columns: Vec<Identifier>,
6243        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
6244        #[serde(default)]
6245        include_columns: Vec<Identifier>,
6246        #[serde(default)]
6247        modifiers: ConstraintModifiers,
6248        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
6249        #[serde(default)]
6250        has_constraint_keyword: bool,
6251    },
6252    Unique {
6253        name: Option<Identifier>,
6254        columns: Vec<Identifier>,
6255        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
6256        #[serde(default)]
6257        columns_parenthesized: bool,
6258        #[serde(default)]
6259        modifiers: ConstraintModifiers,
6260        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
6261        #[serde(default)]
6262        has_constraint_keyword: bool,
6263        /// PostgreSQL 15+: NULLS NOT DISTINCT
6264        #[serde(default)]
6265        nulls_not_distinct: bool,
6266    },
6267    ForeignKey {
6268        name: Option<Identifier>,
6269        columns: Vec<Identifier>,
6270        #[serde(default)]
6271        references: Option<ForeignKeyRef>,
6272        /// ON DELETE action when REFERENCES is absent
6273        #[serde(default)]
6274        on_delete: Option<ReferentialAction>,
6275        /// ON UPDATE action when REFERENCES is absent
6276        #[serde(default)]
6277        on_update: Option<ReferentialAction>,
6278        #[serde(default)]
6279        modifiers: ConstraintModifiers,
6280    },
6281    Check {
6282        name: Option<Identifier>,
6283        expression: Expression,
6284        #[serde(default)]
6285        modifiers: ConstraintModifiers,
6286    },
6287    /// INDEX / KEY constraint (MySQL)
6288    Index {
6289        name: Option<Identifier>,
6290        columns: Vec<Identifier>,
6291        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
6292        #[serde(default)]
6293        kind: Option<String>,
6294        #[serde(default)]
6295        modifiers: ConstraintModifiers,
6296        /// True if KEY keyword was used instead of INDEX
6297        #[serde(default)]
6298        use_key_keyword: bool,
6299        /// ClickHouse: indexed expression (instead of columns)
6300        #[serde(default, skip_serializing_if = "Option::is_none")]
6301        expression: Option<Box<Expression>>,
6302        /// ClickHouse: TYPE type_func(args)
6303        #[serde(default, skip_serializing_if = "Option::is_none")]
6304        index_type: Option<Box<Expression>>,
6305        /// ClickHouse: GRANULARITY n
6306        #[serde(default, skip_serializing_if = "Option::is_none")]
6307        granularity: Option<Box<Expression>>,
6308    },
6309    /// ClickHouse PROJECTION definition
6310    Projection {
6311        name: Identifier,
6312        expression: Expression,
6313    },
6314    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
6315    Like {
6316        source: TableRef,
6317        /// Options as (INCLUDING|EXCLUDING, property) pairs
6318        options: Vec<(LikeOptionAction, String)>,
6319    },
6320    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
6321    PeriodForSystemTime {
6322        start_col: Identifier,
6323        end_col: Identifier,
6324    },
6325    /// PostgreSQL EXCLUDE constraint
6326    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
6327    Exclude {
6328        name: Option<Identifier>,
6329        /// Index access method (gist, btree, etc.)
6330        #[serde(default)]
6331        using: Option<String>,
6332        /// Elements: (expression, operator) pairs
6333        elements: Vec<ExcludeElement>,
6334        /// INCLUDE columns
6335        #[serde(default)]
6336        include_columns: Vec<Identifier>,
6337        /// WHERE predicate
6338        #[serde(default)]
6339        where_clause: Option<Box<Expression>>,
6340        /// WITH (storage_parameters)
6341        #[serde(default)]
6342        with_params: Vec<(String, String)>,
6343        /// USING INDEX TABLESPACE tablespace_name
6344        #[serde(default)]
6345        using_index_tablespace: Option<String>,
6346        #[serde(default)]
6347        modifiers: ConstraintModifiers,
6348    },
6349    /// Snowflake TAG clause: TAG (key='value', key2='value2')
6350    Tags(Tags),
6351    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
6352    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
6353    /// for all deferrable constraints in the table
6354    InitiallyDeferred {
6355        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
6356        deferred: bool,
6357    },
6358}
6359
6360/// Element in an EXCLUDE constraint: expression WITH operator
6361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6362#[cfg_attr(feature = "bindings", derive(TS))]
6363pub struct ExcludeElement {
6364    /// The column expression (may include operator class, ordering, nulls)
6365    pub expression: String,
6366    /// The operator (e.g., &&, =)
6367    pub operator: String,
6368}
6369
6370/// Action for LIKE clause options
6371#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6372#[cfg_attr(feature = "bindings", derive(TS))]
6373pub enum LikeOptionAction {
6374    Including,
6375    Excluding,
6376}
6377
6378/// MATCH type for foreign keys
6379#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6380#[cfg_attr(feature = "bindings", derive(TS))]
6381pub enum MatchType {
6382    Full,
6383    Partial,
6384    Simple,
6385}
6386
6387/// Foreign key reference
6388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6389#[cfg_attr(feature = "bindings", derive(TS))]
6390pub struct ForeignKeyRef {
6391    pub table: TableRef,
6392    pub columns: Vec<Identifier>,
6393    pub on_delete: Option<ReferentialAction>,
6394    pub on_update: Option<ReferentialAction>,
6395    /// True if ON UPDATE appears before ON DELETE in the original SQL
6396    #[serde(default)]
6397    pub on_update_first: bool,
6398    /// MATCH clause (FULL, PARTIAL, SIMPLE)
6399    #[serde(default)]
6400    pub match_type: Option<MatchType>,
6401    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
6402    #[serde(default)]
6403    pub match_after_actions: bool,
6404    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
6405    #[serde(default)]
6406    pub constraint_name: Option<String>,
6407    /// DEFERRABLE / NOT DEFERRABLE
6408    #[serde(default)]
6409    pub deferrable: Option<bool>,
6410    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
6411    #[serde(default)]
6412    pub has_foreign_key_keywords: bool,
6413}
6414
6415/// Referential action for foreign keys
6416#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6417#[cfg_attr(feature = "bindings", derive(TS))]
6418pub enum ReferentialAction {
6419    Cascade,
6420    SetNull,
6421    SetDefault,
6422    Restrict,
6423    NoAction,
6424}
6425
6426/// DROP TABLE statement
6427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6428#[cfg_attr(feature = "bindings", derive(TS))]
6429pub struct DropTable {
6430    pub names: Vec<TableRef>,
6431    pub if_exists: bool,
6432    pub cascade: bool,
6433    /// Oracle: CASCADE CONSTRAINTS
6434    #[serde(default)]
6435    pub cascade_constraints: bool,
6436    /// Oracle: PURGE
6437    #[serde(default)]
6438    pub purge: bool,
6439    /// Comments that appear before the DROP keyword (e.g., leading line comments)
6440    #[serde(default)]
6441    pub leading_comments: Vec<String>,
6442    /// TSQL: OBJECT_ID arguments for reconstructing IF OBJECT_ID(...) IS NOT NULL pattern
6443    /// When set, TSQL generator outputs IF NOT OBJECT_ID(...) IS NULL BEGIN DROP TABLE ...; END
6444    #[serde(default, skip_serializing_if = "Option::is_none")]
6445    pub object_id_args: Option<String>,
6446}
6447
6448impl DropTable {
6449    pub fn new(name: impl Into<String>) -> Self {
6450        Self {
6451            names: vec![TableRef::new(name)],
6452            if_exists: false,
6453            cascade: false,
6454            cascade_constraints: false,
6455            purge: false,
6456            leading_comments: Vec::new(),
6457            object_id_args: None,
6458        }
6459    }
6460}
6461
6462/// ALTER TABLE statement
6463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6464#[cfg_attr(feature = "bindings", derive(TS))]
6465pub struct AlterTable {
6466    pub name: TableRef,
6467    pub actions: Vec<AlterTableAction>,
6468    /// IF EXISTS clause
6469    #[serde(default)]
6470    pub if_exists: bool,
6471    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
6472    #[serde(default, skip_serializing_if = "Option::is_none")]
6473    pub algorithm: Option<String>,
6474    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
6475    #[serde(default, skip_serializing_if = "Option::is_none")]
6476    pub lock: Option<String>,
6477    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
6478    #[serde(default, skip_serializing_if = "Option::is_none")]
6479    pub with_check: Option<String>,
6480    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
6481    #[serde(default, skip_serializing_if = "Option::is_none")]
6482    pub partition: Option<Vec<(Identifier, Expression)>>,
6483    /// ClickHouse: ON CLUSTER clause for distributed DDL
6484    #[serde(default, skip_serializing_if = "Option::is_none")]
6485    pub on_cluster: Option<OnCluster>,
6486}
6487
6488impl AlterTable {
6489    pub fn new(name: impl Into<String>) -> Self {
6490        Self {
6491            name: TableRef::new(name),
6492            actions: Vec::new(),
6493            if_exists: false,
6494            algorithm: None,
6495            lock: None,
6496            with_check: None,
6497            partition: None,
6498            on_cluster: None,
6499        }
6500    }
6501}
6502
6503/// Column position for ADD COLUMN (MySQL/MariaDB)
6504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6505#[cfg_attr(feature = "bindings", derive(TS))]
6506pub enum ColumnPosition {
6507    First,
6508    After(Identifier),
6509}
6510
6511/// Actions for ALTER TABLE
6512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6513#[cfg_attr(feature = "bindings", derive(TS))]
6514pub enum AlterTableAction {
6515    AddColumn {
6516        column: ColumnDef,
6517        if_not_exists: bool,
6518        position: Option<ColumnPosition>,
6519    },
6520    DropColumn {
6521        name: Identifier,
6522        if_exists: bool,
6523        cascade: bool,
6524    },
6525    RenameColumn {
6526        old_name: Identifier,
6527        new_name: Identifier,
6528        if_exists: bool,
6529    },
6530    AlterColumn {
6531        name: Identifier,
6532        action: AlterColumnAction,
6533        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
6534        #[serde(default)]
6535        use_modify_keyword: bool,
6536    },
6537    RenameTable(TableRef),
6538    AddConstraint(TableConstraint),
6539    DropConstraint {
6540        name: Identifier,
6541        if_exists: bool,
6542    },
6543    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
6544    DropForeignKey {
6545        name: Identifier,
6546    },
6547    /// DROP PARTITION action (Hive/BigQuery)
6548    DropPartition {
6549        /// List of partitions to drop (each partition is a list of key=value pairs)
6550        partitions: Vec<Vec<(Identifier, Expression)>>,
6551        if_exists: bool,
6552    },
6553    /// ADD PARTITION action (Hive/Spark)
6554    AddPartition {
6555        /// The partition expression
6556        partition: Expression,
6557        if_not_exists: bool,
6558        location: Option<Expression>,
6559    },
6560    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6561    Delete {
6562        where_clause: Expression,
6563    },
6564    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6565    SwapWith(TableRef),
6566    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6567    SetProperty {
6568        properties: Vec<(String, Expression)>,
6569    },
6570    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6571    UnsetProperty {
6572        properties: Vec<String>,
6573    },
6574    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6575    ClusterBy {
6576        expressions: Vec<Expression>,
6577    },
6578    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6579    SetTag {
6580        expressions: Vec<(String, Expression)>,
6581    },
6582    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6583    UnsetTag {
6584        names: Vec<String>,
6585    },
6586    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6587    SetOptions {
6588        expressions: Vec<Expression>,
6589    },
6590    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6591    AlterIndex {
6592        name: Identifier,
6593        visible: bool,
6594    },
6595    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6596    SetAttribute {
6597        attribute: String,
6598    },
6599    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6600    SetStageFileFormat {
6601        options: Option<Expression>,
6602    },
6603    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6604    SetStageCopyOptions {
6605        options: Option<Expression>,
6606    },
6607    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6608    AddColumns {
6609        columns: Vec<ColumnDef>,
6610        cascade: bool,
6611    },
6612    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6613    DropColumns {
6614        names: Vec<Identifier>,
6615    },
6616    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6617    /// In SingleStore, data_type can be omitted for simple column renames
6618    ChangeColumn {
6619        old_name: Identifier,
6620        new_name: Identifier,
6621        #[serde(default, skip_serializing_if = "Option::is_none")]
6622        data_type: Option<DataType>,
6623        comment: Option<String>,
6624        #[serde(default)]
6625        cascade: bool,
6626    },
6627    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6628    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6629    AlterSortKey {
6630        /// AUTO or NONE keyword
6631        this: Option<String>,
6632        /// Column list for (col1, col2) syntax
6633        expressions: Vec<Expression>,
6634        /// Whether COMPOUND keyword was present
6635        compound: bool,
6636    },
6637    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6638    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6639    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6640    AlterDistStyle {
6641        /// Distribution style: ALL, EVEN, AUTO, or KEY
6642        style: String,
6643        /// DISTKEY column (only when style is KEY)
6644        distkey: Option<Identifier>,
6645    },
6646    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6647    SetTableProperties {
6648        properties: Vec<(Expression, Expression)>,
6649    },
6650    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6651    SetLocation {
6652        location: String,
6653    },
6654    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6655    SetFileFormat {
6656        format: String,
6657    },
6658    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6659    ReplacePartition {
6660        partition: Expression,
6661        source: Option<Box<Expression>>,
6662    },
6663    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6664    Raw {
6665        sql: String,
6666    },
6667}
6668
6669/// Actions for ALTER COLUMN
6670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6671#[cfg_attr(feature = "bindings", derive(TS))]
6672pub enum AlterColumnAction {
6673    SetDataType {
6674        data_type: DataType,
6675        /// USING expression for type conversion (PostgreSQL)
6676        using: Option<Expression>,
6677        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6678        #[serde(default, skip_serializing_if = "Option::is_none")]
6679        collate: Option<String>,
6680    },
6681    SetDefault(Expression),
6682    DropDefault,
6683    SetNotNull,
6684    DropNotNull,
6685    /// Set column comment
6686    Comment(String),
6687    /// MySQL: SET VISIBLE
6688    SetVisible,
6689    /// MySQL: SET INVISIBLE
6690    SetInvisible,
6691}
6692
6693/// CREATE INDEX statement
6694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6695#[cfg_attr(feature = "bindings", derive(TS))]
6696pub struct CreateIndex {
6697    pub name: Identifier,
6698    pub table: TableRef,
6699    pub columns: Vec<IndexColumn>,
6700    pub unique: bool,
6701    pub if_not_exists: bool,
6702    pub using: Option<String>,
6703    /// TSQL CLUSTERED/NONCLUSTERED modifier
6704    #[serde(default)]
6705    pub clustered: Option<String>,
6706    /// PostgreSQL CONCURRENTLY modifier
6707    #[serde(default)]
6708    pub concurrently: bool,
6709    /// PostgreSQL WHERE clause for partial indexes
6710    #[serde(default)]
6711    pub where_clause: Option<Box<Expression>>,
6712    /// PostgreSQL INCLUDE columns
6713    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6714    pub include_columns: Vec<Identifier>,
6715    /// TSQL WITH options (e.g., allow_page_locks=on)
6716    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6717    pub with_options: Vec<(String, String)>,
6718    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6719    #[serde(default)]
6720    pub on_filegroup: Option<String>,
6721}
6722
6723impl CreateIndex {
6724    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6725        Self {
6726            name: Identifier::new(name),
6727            table: TableRef::new(table),
6728            columns: Vec::new(),
6729            unique: false,
6730            if_not_exists: false,
6731            using: None,
6732            clustered: None,
6733            concurrently: false,
6734            where_clause: None,
6735            include_columns: Vec::new(),
6736            with_options: Vec::new(),
6737            on_filegroup: None,
6738        }
6739    }
6740}
6741
6742/// Index column specification
6743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6744#[cfg_attr(feature = "bindings", derive(TS))]
6745pub struct IndexColumn {
6746    pub column: Identifier,
6747    pub desc: bool,
6748    /// Explicit ASC keyword was present
6749    #[serde(default)]
6750    pub asc: bool,
6751    pub nulls_first: Option<bool>,
6752    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6753    #[serde(default, skip_serializing_if = "Option::is_none")]
6754    pub opclass: Option<String>,
6755}
6756
6757/// DROP INDEX statement
6758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6759#[cfg_attr(feature = "bindings", derive(TS))]
6760pub struct DropIndex {
6761    pub name: Identifier,
6762    pub table: Option<TableRef>,
6763    pub if_exists: bool,
6764    /// PostgreSQL CONCURRENTLY modifier
6765    #[serde(default)]
6766    pub concurrently: bool,
6767}
6768
6769impl DropIndex {
6770    pub fn new(name: impl Into<String>) -> Self {
6771        Self {
6772            name: Identifier::new(name),
6773            table: None,
6774            if_exists: false,
6775            concurrently: false,
6776        }
6777    }
6778}
6779
6780/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6782#[cfg_attr(feature = "bindings", derive(TS))]
6783pub struct ViewColumn {
6784    pub name: Identifier,
6785    pub comment: Option<String>,
6786    /// BigQuery: OPTIONS (key=value, ...) on column
6787    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6788    pub options: Vec<Expression>,
6789}
6790
6791impl ViewColumn {
6792    pub fn new(name: impl Into<String>) -> Self {
6793        Self {
6794            name: Identifier::new(name),
6795            comment: None,
6796            options: Vec::new(),
6797        }
6798    }
6799
6800    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6801        Self {
6802            name: Identifier::new(name),
6803            comment: Some(comment.into()),
6804            options: Vec::new(),
6805        }
6806    }
6807}
6808
6809/// CREATE VIEW statement
6810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6811#[cfg_attr(feature = "bindings", derive(TS))]
6812pub struct CreateView {
6813    pub name: TableRef,
6814    pub columns: Vec<ViewColumn>,
6815    pub query: Expression,
6816    pub or_replace: bool,
6817    pub if_not_exists: bool,
6818    pub materialized: bool,
6819    pub temporary: bool,
6820    /// Snowflake: SECURE VIEW
6821    #[serde(default)]
6822    pub secure: bool,
6823    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6824    #[serde(skip_serializing_if = "Option::is_none")]
6825    pub algorithm: Option<String>,
6826    /// MySQL: DEFINER=user@host
6827    #[serde(skip_serializing_if = "Option::is_none")]
6828    pub definer: Option<String>,
6829    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6830    #[serde(skip_serializing_if = "Option::is_none")]
6831    pub security: Option<FunctionSecurity>,
6832    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6833    #[serde(default = "default_true")]
6834    pub security_sql_style: bool,
6835    /// Whether the query was parenthesized: AS (SELECT ...)
6836    #[serde(default)]
6837    pub query_parenthesized: bool,
6838    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6839    #[serde(skip_serializing_if = "Option::is_none")]
6840    pub locking_mode: Option<String>,
6841    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6842    #[serde(skip_serializing_if = "Option::is_none")]
6843    pub locking_access: Option<String>,
6844    /// Snowflake: COPY GRANTS
6845    #[serde(default)]
6846    pub copy_grants: bool,
6847    /// Snowflake: COMMENT = 'text'
6848    #[serde(skip_serializing_if = "Option::is_none", default)]
6849    pub comment: Option<String>,
6850    /// Snowflake: TAG (name='value', ...)
6851    #[serde(default)]
6852    pub tags: Vec<(String, String)>,
6853    /// BigQuery: OPTIONS (key=value, ...)
6854    #[serde(default)]
6855    pub options: Vec<Expression>,
6856    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6857    #[serde(skip_serializing_if = "Option::is_none", default)]
6858    pub build: Option<String>,
6859    /// Doris: REFRESH property for materialized views
6860    #[serde(skip_serializing_if = "Option::is_none", default)]
6861    pub refresh: Option<Box<RefreshTriggerProperty>>,
6862    /// Doris: Schema with typed column definitions for materialized views
6863    /// This is used instead of `columns` when the view has typed column definitions
6864    #[serde(skip_serializing_if = "Option::is_none", default)]
6865    pub schema: Option<Box<Schema>>,
6866    /// Doris: KEY (columns) for materialized views
6867    #[serde(skip_serializing_if = "Option::is_none", default)]
6868    pub unique_key: Option<Box<UniqueKeyProperty>>,
6869    /// Redshift: WITH NO SCHEMA BINDING
6870    #[serde(default)]
6871    pub no_schema_binding: bool,
6872    /// Redshift: AUTO REFRESH YES|NO for materialized views
6873    #[serde(skip_serializing_if = "Option::is_none", default)]
6874    pub auto_refresh: Option<bool>,
6875    /// ClickHouse: ON CLUSTER clause
6876    #[serde(default, skip_serializing_if = "Option::is_none")]
6877    pub on_cluster: Option<OnCluster>,
6878    /// ClickHouse: TO destination_table
6879    #[serde(default, skip_serializing_if = "Option::is_none")]
6880    pub to_table: Option<TableRef>,
6881    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6882    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6883    pub table_properties: Vec<Expression>,
6884}
6885
6886impl CreateView {
6887    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6888        Self {
6889            name: TableRef::new(name),
6890            columns: Vec::new(),
6891            query,
6892            or_replace: false,
6893            if_not_exists: false,
6894            materialized: false,
6895            temporary: false,
6896            secure: false,
6897            algorithm: None,
6898            definer: None,
6899            security: None,
6900            security_sql_style: true,
6901            query_parenthesized: false,
6902            locking_mode: None,
6903            locking_access: None,
6904            copy_grants: false,
6905            comment: None,
6906            tags: Vec::new(),
6907            options: Vec::new(),
6908            build: None,
6909            refresh: None,
6910            schema: None,
6911            unique_key: None,
6912            no_schema_binding: false,
6913            auto_refresh: None,
6914            on_cluster: None,
6915            to_table: None,
6916            table_properties: Vec::new(),
6917        }
6918    }
6919}
6920
6921/// DROP VIEW statement
6922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6923#[cfg_attr(feature = "bindings", derive(TS))]
6924pub struct DropView {
6925    pub name: TableRef,
6926    pub if_exists: bool,
6927    pub materialized: bool,
6928}
6929
6930impl DropView {
6931    pub fn new(name: impl Into<String>) -> Self {
6932        Self {
6933            name: TableRef::new(name),
6934            if_exists: false,
6935            materialized: false,
6936        }
6937    }
6938}
6939
6940/// TRUNCATE TABLE statement
6941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6942#[cfg_attr(feature = "bindings", derive(TS))]
6943pub struct Truncate {
6944    /// Target of TRUNCATE (TABLE vs DATABASE)
6945    #[serde(default)]
6946    pub target: TruncateTarget,
6947    /// IF EXISTS clause
6948    #[serde(default)]
6949    pub if_exists: bool,
6950    pub table: TableRef,
6951    /// ClickHouse: ON CLUSTER clause for distributed DDL
6952    #[serde(default, skip_serializing_if = "Option::is_none")]
6953    pub on_cluster: Option<OnCluster>,
6954    pub cascade: bool,
6955    /// Additional tables for multi-table TRUNCATE
6956    #[serde(default)]
6957    pub extra_tables: Vec<TruncateTableEntry>,
6958    /// RESTART IDENTITY or CONTINUE IDENTITY
6959    #[serde(default)]
6960    pub identity: Option<TruncateIdentity>,
6961    /// RESTRICT option (alternative to CASCADE)
6962    #[serde(default)]
6963    pub restrict: bool,
6964    /// Hive PARTITION clause: PARTITION(key=value, ...)
6965    #[serde(default, skip_serializing_if = "Option::is_none")]
6966    pub partition: Option<Box<Expression>>,
6967}
6968
6969/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6971#[cfg_attr(feature = "bindings", derive(TS))]
6972pub struct TruncateTableEntry {
6973    pub table: TableRef,
6974    /// Whether the table has a * suffix (inherit children)
6975    #[serde(default)]
6976    pub star: bool,
6977}
6978
6979/// TRUNCATE target type
6980#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6981#[cfg_attr(feature = "bindings", derive(TS))]
6982pub enum TruncateTarget {
6983    Table,
6984    Database,
6985}
6986
6987impl Default for TruncateTarget {
6988    fn default() -> Self {
6989        TruncateTarget::Table
6990    }
6991}
6992
6993/// TRUNCATE identity option
6994#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6995#[cfg_attr(feature = "bindings", derive(TS))]
6996pub enum TruncateIdentity {
6997    Restart,
6998    Continue,
6999}
7000
7001impl Truncate {
7002    pub fn new(table: impl Into<String>) -> Self {
7003        Self {
7004            target: TruncateTarget::Table,
7005            if_exists: false,
7006            table: TableRef::new(table),
7007            on_cluster: None,
7008            cascade: false,
7009            extra_tables: Vec::new(),
7010            identity: None,
7011            restrict: false,
7012            partition: None,
7013        }
7014    }
7015}
7016
7017/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
7018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7019#[cfg_attr(feature = "bindings", derive(TS))]
7020pub struct Use {
7021    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
7022    pub kind: Option<UseKind>,
7023    /// The name of the object
7024    pub this: Identifier,
7025}
7026
7027/// Kind of USE statement
7028#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7029#[cfg_attr(feature = "bindings", derive(TS))]
7030pub enum UseKind {
7031    Database,
7032    Schema,
7033    Role,
7034    Warehouse,
7035    Catalog,
7036    /// Snowflake: USE SECONDARY ROLES ALL|NONE
7037    SecondaryRoles,
7038}
7039
7040/// SET variable statement
7041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7042#[cfg_attr(feature = "bindings", derive(TS))]
7043pub struct SetStatement {
7044    /// The items being set
7045    pub items: Vec<SetItem>,
7046}
7047
7048/// A single SET item (variable assignment)
7049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7050#[cfg_attr(feature = "bindings", derive(TS))]
7051pub struct SetItem {
7052    /// The variable name
7053    pub name: Expression,
7054    /// The value to set
7055    pub value: Expression,
7056    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
7057    pub kind: Option<String>,
7058    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
7059    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7060    pub no_equals: bool,
7061}
7062
7063/// CACHE TABLE statement (Spark)
7064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7065#[cfg_attr(feature = "bindings", derive(TS))]
7066pub struct Cache {
7067    /// The table to cache
7068    pub table: Identifier,
7069    /// LAZY keyword - defer caching until first use
7070    pub lazy: bool,
7071    /// Optional OPTIONS clause (key-value pairs)
7072    pub options: Vec<(Expression, Expression)>,
7073    /// Optional AS clause with query
7074    pub query: Option<Expression>,
7075}
7076
7077/// UNCACHE TABLE statement (Spark)
7078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7079#[cfg_attr(feature = "bindings", derive(TS))]
7080pub struct Uncache {
7081    /// The table to uncache
7082    pub table: Identifier,
7083    /// IF EXISTS clause
7084    pub if_exists: bool,
7085}
7086
7087/// LOAD DATA statement (Hive)
7088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7089#[cfg_attr(feature = "bindings", derive(TS))]
7090pub struct LoadData {
7091    /// LOCAL keyword - load from local filesystem
7092    pub local: bool,
7093    /// The path to load data from (INPATH value)
7094    pub inpath: String,
7095    /// Whether to overwrite existing data
7096    pub overwrite: bool,
7097    /// The target table
7098    pub table: Expression,
7099    /// Optional PARTITION clause with key-value pairs
7100    pub partition: Vec<(Identifier, Expression)>,
7101    /// Optional INPUTFORMAT clause
7102    pub input_format: Option<String>,
7103    /// Optional SERDE clause
7104    pub serde: Option<String>,
7105}
7106
7107/// PRAGMA statement (SQLite)
7108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7109#[cfg_attr(feature = "bindings", derive(TS))]
7110pub struct Pragma {
7111    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
7112    pub schema: Option<Identifier>,
7113    /// The pragma name
7114    pub name: Identifier,
7115    /// Optional value for assignment (PRAGMA name = value)
7116    pub value: Option<Expression>,
7117    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
7118    pub args: Vec<Expression>,
7119}
7120
7121/// A privilege with optional column list for GRANT/REVOKE
7122/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
7123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7124#[cfg_attr(feature = "bindings", derive(TS))]
7125pub struct Privilege {
7126    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
7127    pub name: String,
7128    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
7129    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7130    pub columns: Vec<String>,
7131}
7132
7133/// Principal in GRANT/REVOKE (user, role, etc.)
7134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7135#[cfg_attr(feature = "bindings", derive(TS))]
7136pub struct GrantPrincipal {
7137    /// The name of the principal
7138    pub name: Identifier,
7139    /// Whether prefixed with ROLE keyword
7140    pub is_role: bool,
7141    /// Whether prefixed with GROUP keyword (Redshift)
7142    #[serde(default)]
7143    pub is_group: bool,
7144}
7145
7146/// GRANT statement
7147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7148#[cfg_attr(feature = "bindings", derive(TS))]
7149pub struct Grant {
7150    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
7151    pub privileges: Vec<Privilege>,
7152    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7153    pub kind: Option<String>,
7154    /// The object to grant on
7155    pub securable: Identifier,
7156    /// Function parameter types (for FUNCTION kind)
7157    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7158    pub function_params: Vec<String>,
7159    /// The grantees
7160    pub principals: Vec<GrantPrincipal>,
7161    /// WITH GRANT OPTION
7162    pub grant_option: bool,
7163    /// TSQL: AS principal (the grantor role)
7164    #[serde(default, skip_serializing_if = "Option::is_none")]
7165    pub as_principal: Option<Identifier>,
7166}
7167
7168/// REVOKE statement
7169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7170#[cfg_attr(feature = "bindings", derive(TS))]
7171pub struct Revoke {
7172    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
7173    pub privileges: Vec<Privilege>,
7174    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7175    pub kind: Option<String>,
7176    /// The object to revoke from
7177    pub securable: Identifier,
7178    /// Function parameter types (for FUNCTION kind)
7179    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7180    pub function_params: Vec<String>,
7181    /// The grantees
7182    pub principals: Vec<GrantPrincipal>,
7183    /// GRANT OPTION FOR
7184    pub grant_option: bool,
7185    /// CASCADE
7186    pub cascade: bool,
7187    /// RESTRICT
7188    #[serde(default)]
7189    pub restrict: bool,
7190}
7191
7192/// COMMENT ON statement
7193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7194#[cfg_attr(feature = "bindings", derive(TS))]
7195pub struct Comment {
7196    /// The object being commented on
7197    pub this: Expression,
7198    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
7199    pub kind: String,
7200    /// The comment text expression
7201    pub expression: Expression,
7202    /// IF EXISTS clause
7203    pub exists: bool,
7204    /// MATERIALIZED keyword
7205    pub materialized: bool,
7206}
7207
7208// ============================================================================
7209// Phase 4: Additional DDL Statements
7210// ============================================================================
7211
7212/// ALTER VIEW statement
7213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7214#[cfg_attr(feature = "bindings", derive(TS))]
7215pub struct AlterView {
7216    pub name: TableRef,
7217    pub actions: Vec<AlterViewAction>,
7218    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
7219    #[serde(default, skip_serializing_if = "Option::is_none")]
7220    pub algorithm: Option<String>,
7221    /// MySQL: DEFINER = 'user'@'host'
7222    #[serde(default, skip_serializing_if = "Option::is_none")]
7223    pub definer: Option<String>,
7224    /// MySQL: SQL SECURITY = DEFINER|INVOKER
7225    #[serde(default, skip_serializing_if = "Option::is_none")]
7226    pub sql_security: Option<String>,
7227    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
7228    #[serde(default, skip_serializing_if = "Option::is_none")]
7229    pub with_option: Option<String>,
7230    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
7231    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7232    pub columns: Vec<ViewColumn>,
7233}
7234
7235/// Actions for ALTER VIEW
7236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7237#[cfg_attr(feature = "bindings", derive(TS))]
7238pub enum AlterViewAction {
7239    /// Rename the view
7240    Rename(TableRef),
7241    /// Change owner
7242    OwnerTo(Identifier),
7243    /// Set schema
7244    SetSchema(Identifier),
7245    /// Set authorization (Trino/Presto)
7246    SetAuthorization(String),
7247    /// Alter column
7248    AlterColumn {
7249        name: Identifier,
7250        action: AlterColumnAction,
7251    },
7252    /// Redefine view as query (SELECT, UNION, etc.)
7253    AsSelect(Box<Expression>),
7254    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
7255    SetTblproperties(Vec<(String, String)>),
7256    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
7257    UnsetTblproperties(Vec<String>),
7258}
7259
7260impl AlterView {
7261    pub fn new(name: impl Into<String>) -> Self {
7262        Self {
7263            name: TableRef::new(name),
7264            actions: Vec::new(),
7265            algorithm: None,
7266            definer: None,
7267            sql_security: None,
7268            with_option: None,
7269            columns: Vec::new(),
7270        }
7271    }
7272}
7273
7274/// ALTER INDEX statement
7275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7276#[cfg_attr(feature = "bindings", derive(TS))]
7277pub struct AlterIndex {
7278    pub name: Identifier,
7279    pub table: Option<TableRef>,
7280    pub actions: Vec<AlterIndexAction>,
7281}
7282
7283/// Actions for ALTER INDEX
7284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7285#[cfg_attr(feature = "bindings", derive(TS))]
7286pub enum AlterIndexAction {
7287    /// Rename the index
7288    Rename(Identifier),
7289    /// Set tablespace
7290    SetTablespace(Identifier),
7291    /// Set visibility (MySQL)
7292    Visible(bool),
7293}
7294
7295impl AlterIndex {
7296    pub fn new(name: impl Into<String>) -> Self {
7297        Self {
7298            name: Identifier::new(name),
7299            table: None,
7300            actions: Vec::new(),
7301        }
7302    }
7303}
7304
7305/// CREATE SCHEMA statement
7306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7307#[cfg_attr(feature = "bindings", derive(TS))]
7308pub struct CreateSchema {
7309    pub name: Identifier,
7310    pub if_not_exists: bool,
7311    pub authorization: Option<Identifier>,
7312    #[serde(default)]
7313    pub clone_from: Option<Identifier>,
7314    /// AT/BEFORE clause for time travel (Snowflake)
7315    #[serde(default)]
7316    pub at_clause: Option<Expression>,
7317    /// Schema properties like DEFAULT COLLATE
7318    #[serde(default)]
7319    pub properties: Vec<Expression>,
7320    /// Leading comments before the statement
7321    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7322    pub leading_comments: Vec<String>,
7323}
7324
7325impl CreateSchema {
7326    pub fn new(name: impl Into<String>) -> Self {
7327        Self {
7328            name: Identifier::new(name),
7329            if_not_exists: false,
7330            authorization: None,
7331            clone_from: None,
7332            at_clause: None,
7333            properties: Vec::new(),
7334            leading_comments: Vec::new(),
7335        }
7336    }
7337}
7338
7339/// DROP SCHEMA statement
7340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7341#[cfg_attr(feature = "bindings", derive(TS))]
7342pub struct DropSchema {
7343    pub name: Identifier,
7344    pub if_exists: bool,
7345    pub cascade: bool,
7346}
7347
7348impl DropSchema {
7349    pub fn new(name: impl Into<String>) -> Self {
7350        Self {
7351            name: Identifier::new(name),
7352            if_exists: false,
7353            cascade: false,
7354        }
7355    }
7356}
7357
7358/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
7359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7360#[cfg_attr(feature = "bindings", derive(TS))]
7361pub struct DropNamespace {
7362    pub name: Identifier,
7363    pub if_exists: bool,
7364    pub cascade: bool,
7365}
7366
7367impl DropNamespace {
7368    pub fn new(name: impl Into<String>) -> Self {
7369        Self {
7370            name: Identifier::new(name),
7371            if_exists: false,
7372            cascade: false,
7373        }
7374    }
7375}
7376
7377/// CREATE DATABASE statement
7378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7379#[cfg_attr(feature = "bindings", derive(TS))]
7380pub struct CreateDatabase {
7381    pub name: Identifier,
7382    pub if_not_exists: bool,
7383    pub options: Vec<DatabaseOption>,
7384    /// Snowflake CLONE source
7385    #[serde(default)]
7386    pub clone_from: Option<Identifier>,
7387    /// AT/BEFORE clause for time travel (Snowflake)
7388    #[serde(default)]
7389    pub at_clause: Option<Expression>,
7390}
7391
7392/// Database option
7393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7394#[cfg_attr(feature = "bindings", derive(TS))]
7395pub enum DatabaseOption {
7396    CharacterSet(String),
7397    Collate(String),
7398    Owner(Identifier),
7399    Template(Identifier),
7400    Encoding(String),
7401    Location(String),
7402}
7403
7404impl CreateDatabase {
7405    pub fn new(name: impl Into<String>) -> Self {
7406        Self {
7407            name: Identifier::new(name),
7408            if_not_exists: false,
7409            options: Vec::new(),
7410            clone_from: None,
7411            at_clause: None,
7412        }
7413    }
7414}
7415
7416/// DROP DATABASE statement
7417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7418#[cfg_attr(feature = "bindings", derive(TS))]
7419pub struct DropDatabase {
7420    pub name: Identifier,
7421    pub if_exists: bool,
7422}
7423
7424impl DropDatabase {
7425    pub fn new(name: impl Into<String>) -> Self {
7426        Self {
7427            name: Identifier::new(name),
7428            if_exists: false,
7429        }
7430    }
7431}
7432
7433/// CREATE FUNCTION statement
7434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7435#[cfg_attr(feature = "bindings", derive(TS))]
7436pub struct CreateFunction {
7437    pub name: TableRef,
7438    pub parameters: Vec<FunctionParameter>,
7439    pub return_type: Option<DataType>,
7440    pub body: Option<FunctionBody>,
7441    pub or_replace: bool,
7442    pub if_not_exists: bool,
7443    pub temporary: bool,
7444    pub language: Option<String>,
7445    pub deterministic: Option<bool>,
7446    pub returns_null_on_null_input: Option<bool>,
7447    pub security: Option<FunctionSecurity>,
7448    /// Whether parentheses were present in the original syntax
7449    #[serde(default = "default_true")]
7450    pub has_parens: bool,
7451    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
7452    #[serde(default)]
7453    pub sql_data_access: Option<SqlDataAccess>,
7454    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
7455    #[serde(default, skip_serializing_if = "Option::is_none")]
7456    pub returns_table_body: Option<String>,
7457    /// True if LANGUAGE clause appears before RETURNS clause
7458    #[serde(default)]
7459    pub language_first: bool,
7460    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
7461    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7462    pub set_options: Vec<FunctionSetOption>,
7463    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
7464    #[serde(default)]
7465    pub strict: bool,
7466    /// BigQuery: OPTIONS (key=value, ...)
7467    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7468    pub options: Vec<Expression>,
7469    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
7470    #[serde(default)]
7471    pub is_table_function: bool,
7472    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
7473    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7474    pub property_order: Vec<FunctionPropertyKind>,
7475    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
7476    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7477    pub environment: Vec<Expression>,
7478}
7479
7480/// A SET option in CREATE FUNCTION (PostgreSQL)
7481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7482#[cfg_attr(feature = "bindings", derive(TS))]
7483pub struct FunctionSetOption {
7484    pub name: String,
7485    pub value: FunctionSetValue,
7486}
7487
7488/// The value of a SET option
7489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7490#[cfg_attr(feature = "bindings", derive(TS))]
7491pub enum FunctionSetValue {
7492    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
7493    Value { value: String, use_to: bool },
7494    /// SET key FROM CURRENT
7495    FromCurrent,
7496}
7497
7498/// SQL data access characteristics for functions
7499#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7500#[cfg_attr(feature = "bindings", derive(TS))]
7501pub enum SqlDataAccess {
7502    /// NO SQL
7503    NoSql,
7504    /// CONTAINS SQL
7505    ContainsSql,
7506    /// READS SQL DATA
7507    ReadsSqlData,
7508    /// MODIFIES SQL DATA
7509    ModifiesSqlData,
7510}
7511
7512/// Types of properties in CREATE FUNCTION for tracking their original order
7513#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7514#[cfg_attr(feature = "bindings", derive(TS))]
7515pub enum FunctionPropertyKind {
7516    /// SET option
7517    Set,
7518    /// AS body
7519    As,
7520    /// LANGUAGE clause
7521    Language,
7522    /// IMMUTABLE/VOLATILE/STABLE (determinism)
7523    Determinism,
7524    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
7525    NullInput,
7526    /// SECURITY DEFINER/INVOKER
7527    Security,
7528    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
7529    SqlDataAccess,
7530    /// OPTIONS clause (BigQuery)
7531    Options,
7532    /// ENVIRONMENT clause (Databricks)
7533    Environment,
7534}
7535
7536/// Function parameter
7537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7538#[cfg_attr(feature = "bindings", derive(TS))]
7539pub struct FunctionParameter {
7540    pub name: Option<Identifier>,
7541    pub data_type: DataType,
7542    pub mode: Option<ParameterMode>,
7543    pub default: Option<Expression>,
7544    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
7545    #[serde(default, skip_serializing_if = "Option::is_none")]
7546    pub mode_text: Option<String>,
7547}
7548
7549/// Parameter mode (IN, OUT, INOUT, VARIADIC)
7550#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7551#[cfg_attr(feature = "bindings", derive(TS))]
7552pub enum ParameterMode {
7553    In,
7554    Out,
7555    InOut,
7556    Variadic,
7557}
7558
7559/// Function body
7560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7561#[cfg_attr(feature = "bindings", derive(TS))]
7562pub enum FunctionBody {
7563    /// AS $$ ... $$ (dollar-quoted)
7564    Block(String),
7565    /// AS 'string' (single-quoted string literal body)
7566    StringLiteral(String),
7567    /// AS 'expression'
7568    Expression(Expression),
7569    /// EXTERNAL NAME 'library'
7570    External(String),
7571    /// RETURN expression
7572    Return(Expression),
7573    /// BEGIN ... END block with parsed statements
7574    Statements(Vec<Expression>),
7575    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7576    /// Stores (content, optional_tag)
7577    DollarQuoted {
7578        content: String,
7579        tag: Option<String>,
7580    },
7581}
7582
7583/// Function security (DEFINER, INVOKER, or NONE)
7584#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7585#[cfg_attr(feature = "bindings", derive(TS))]
7586pub enum FunctionSecurity {
7587    Definer,
7588    Invoker,
7589    /// StarRocks/MySQL: SECURITY NONE
7590    None,
7591}
7592
7593impl CreateFunction {
7594    pub fn new(name: impl Into<String>) -> Self {
7595        Self {
7596            name: TableRef::new(name),
7597            parameters: Vec::new(),
7598            return_type: None,
7599            body: None,
7600            or_replace: false,
7601            if_not_exists: false,
7602            temporary: false,
7603            language: None,
7604            deterministic: None,
7605            returns_null_on_null_input: None,
7606            security: None,
7607            has_parens: true,
7608            sql_data_access: None,
7609            returns_table_body: None,
7610            language_first: false,
7611            set_options: Vec::new(),
7612            strict: false,
7613            options: Vec::new(),
7614            is_table_function: false,
7615            property_order: Vec::new(),
7616            environment: Vec::new(),
7617        }
7618    }
7619}
7620
7621/// DROP FUNCTION statement
7622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7623#[cfg_attr(feature = "bindings", derive(TS))]
7624pub struct DropFunction {
7625    pub name: TableRef,
7626    pub parameters: Option<Vec<DataType>>,
7627    pub if_exists: bool,
7628    pub cascade: bool,
7629}
7630
7631impl DropFunction {
7632    pub fn new(name: impl Into<String>) -> Self {
7633        Self {
7634            name: TableRef::new(name),
7635            parameters: None,
7636            if_exists: false,
7637            cascade: false,
7638        }
7639    }
7640}
7641
7642/// CREATE PROCEDURE statement
7643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7644#[cfg_attr(feature = "bindings", derive(TS))]
7645pub struct CreateProcedure {
7646    pub name: TableRef,
7647    pub parameters: Vec<FunctionParameter>,
7648    pub body: Option<FunctionBody>,
7649    pub or_replace: bool,
7650    pub if_not_exists: bool,
7651    pub language: Option<String>,
7652    pub security: Option<FunctionSecurity>,
7653    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7654    #[serde(default)]
7655    pub return_type: Option<DataType>,
7656    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7657    #[serde(default)]
7658    pub execute_as: Option<String>,
7659    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7660    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7661    pub with_options: Vec<String>,
7662    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7663    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7664    pub has_parens: bool,
7665    /// Whether the short form PROC was used (instead of PROCEDURE)
7666    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7667    pub use_proc_keyword: bool,
7668}
7669
7670impl CreateProcedure {
7671    pub fn new(name: impl Into<String>) -> Self {
7672        Self {
7673            name: TableRef::new(name),
7674            parameters: Vec::new(),
7675            body: None,
7676            or_replace: false,
7677            if_not_exists: false,
7678            language: None,
7679            security: None,
7680            return_type: None,
7681            execute_as: None,
7682            with_options: Vec::new(),
7683            has_parens: true,
7684            use_proc_keyword: false,
7685        }
7686    }
7687}
7688
7689/// DROP PROCEDURE statement
7690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7691#[cfg_attr(feature = "bindings", derive(TS))]
7692pub struct DropProcedure {
7693    pub name: TableRef,
7694    pub parameters: Option<Vec<DataType>>,
7695    pub if_exists: bool,
7696    pub cascade: bool,
7697}
7698
7699impl DropProcedure {
7700    pub fn new(name: impl Into<String>) -> Self {
7701        Self {
7702            name: TableRef::new(name),
7703            parameters: None,
7704            if_exists: false,
7705            cascade: false,
7706        }
7707    }
7708}
7709
7710/// Sequence property tag for ordering
7711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7712#[cfg_attr(feature = "bindings", derive(TS))]
7713pub enum SeqPropKind {
7714    Start,
7715    Increment,
7716    Minvalue,
7717    Maxvalue,
7718    Cache,
7719    NoCache,
7720    Cycle,
7721    NoCycle,
7722    OwnedBy,
7723    Order,
7724    NoOrder,
7725    Comment,
7726    /// SHARING=<value> (Oracle)
7727    Sharing,
7728    /// KEEP (Oracle)
7729    Keep,
7730    /// NOKEEP (Oracle)
7731    NoKeep,
7732    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7733    Scale,
7734    /// NOSCALE (Oracle)
7735    NoScale,
7736    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7737    Shard,
7738    /// NOSHARD (Oracle)
7739    NoShard,
7740    /// SESSION (Oracle)
7741    Session,
7742    /// GLOBAL (Oracle)
7743    Global,
7744    /// NOCACHE (single word, Oracle)
7745    NoCacheWord,
7746    /// NOCYCLE (single word, Oracle)
7747    NoCycleWord,
7748    /// NOMINVALUE (single word, Oracle)
7749    NoMinvalueWord,
7750    /// NOMAXVALUE (single word, Oracle)
7751    NoMaxvalueWord,
7752}
7753
7754/// CREATE SEQUENCE statement
7755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7756#[cfg_attr(feature = "bindings", derive(TS))]
7757pub struct CreateSequence {
7758    pub name: TableRef,
7759    pub if_not_exists: bool,
7760    pub temporary: bool,
7761    #[serde(default)]
7762    pub or_replace: bool,
7763    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7764    #[serde(default, skip_serializing_if = "Option::is_none")]
7765    pub as_type: Option<DataType>,
7766    pub increment: Option<i64>,
7767    pub minvalue: Option<SequenceBound>,
7768    pub maxvalue: Option<SequenceBound>,
7769    pub start: Option<i64>,
7770    pub cache: Option<i64>,
7771    pub cycle: bool,
7772    pub owned_by: Option<TableRef>,
7773    /// Whether OWNED BY NONE was specified
7774    #[serde(default)]
7775    pub owned_by_none: bool,
7776    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7777    #[serde(default)]
7778    pub order: Option<bool>,
7779    /// Snowflake: COMMENT = 'value'
7780    #[serde(default)]
7781    pub comment: Option<String>,
7782    /// SHARING=<value> (Oracle)
7783    #[serde(default, skip_serializing_if = "Option::is_none")]
7784    pub sharing: Option<String>,
7785    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7786    #[serde(default, skip_serializing_if = "Option::is_none")]
7787    pub scale_modifier: Option<String>,
7788    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7789    #[serde(default, skip_serializing_if = "Option::is_none")]
7790    pub shard_modifier: Option<String>,
7791    /// Tracks the order in which properties appeared in the source
7792    #[serde(default)]
7793    pub property_order: Vec<SeqPropKind>,
7794}
7795
7796/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7798#[cfg_attr(feature = "bindings", derive(TS))]
7799pub enum SequenceBound {
7800    Value(i64),
7801    None,
7802}
7803
7804impl CreateSequence {
7805    pub fn new(name: impl Into<String>) -> Self {
7806        Self {
7807            name: TableRef::new(name),
7808            if_not_exists: false,
7809            temporary: false,
7810            or_replace: false,
7811            as_type: None,
7812            increment: None,
7813            minvalue: None,
7814            maxvalue: None,
7815            start: None,
7816            cache: None,
7817            cycle: false,
7818            owned_by: None,
7819            owned_by_none: false,
7820            order: None,
7821            comment: None,
7822            sharing: None,
7823            scale_modifier: None,
7824            shard_modifier: None,
7825            property_order: Vec::new(),
7826        }
7827    }
7828}
7829
7830/// DROP SEQUENCE statement
7831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7832#[cfg_attr(feature = "bindings", derive(TS))]
7833pub struct DropSequence {
7834    pub name: TableRef,
7835    pub if_exists: bool,
7836    pub cascade: bool,
7837}
7838
7839impl DropSequence {
7840    pub fn new(name: impl Into<String>) -> Self {
7841        Self {
7842            name: TableRef::new(name),
7843            if_exists: false,
7844            cascade: false,
7845        }
7846    }
7847}
7848
7849/// ALTER SEQUENCE statement
7850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7851#[cfg_attr(feature = "bindings", derive(TS))]
7852pub struct AlterSequence {
7853    pub name: TableRef,
7854    pub if_exists: bool,
7855    pub increment: Option<i64>,
7856    pub minvalue: Option<SequenceBound>,
7857    pub maxvalue: Option<SequenceBound>,
7858    pub start: Option<i64>,
7859    pub restart: Option<Option<i64>>,
7860    pub cache: Option<i64>,
7861    pub cycle: Option<bool>,
7862    pub owned_by: Option<Option<TableRef>>,
7863}
7864
7865impl AlterSequence {
7866    pub fn new(name: impl Into<String>) -> Self {
7867        Self {
7868            name: TableRef::new(name),
7869            if_exists: false,
7870            increment: None,
7871            minvalue: None,
7872            maxvalue: None,
7873            start: None,
7874            restart: None,
7875            cache: None,
7876            cycle: None,
7877            owned_by: None,
7878        }
7879    }
7880}
7881
7882/// CREATE TRIGGER statement
7883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7884#[cfg_attr(feature = "bindings", derive(TS))]
7885pub struct CreateTrigger {
7886    pub name: Identifier,
7887    pub table: TableRef,
7888    pub timing: TriggerTiming,
7889    pub events: Vec<TriggerEvent>,
7890    #[serde(default, skip_serializing_if = "Option::is_none")]
7891    pub for_each: Option<TriggerForEach>,
7892    pub when: Option<Expression>,
7893    /// Whether the WHEN clause was parenthesized in the original SQL
7894    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7895    pub when_paren: bool,
7896    pub body: TriggerBody,
7897    pub or_replace: bool,
7898    pub constraint: bool,
7899    pub deferrable: Option<bool>,
7900    pub initially_deferred: Option<bool>,
7901    pub referencing: Option<TriggerReferencing>,
7902}
7903
7904/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7905#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7906#[cfg_attr(feature = "bindings", derive(TS))]
7907pub enum TriggerTiming {
7908    Before,
7909    After,
7910    InsteadOf,
7911}
7912
7913/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7915#[cfg_attr(feature = "bindings", derive(TS))]
7916pub enum TriggerEvent {
7917    Insert,
7918    Update(Option<Vec<Identifier>>),
7919    Delete,
7920    Truncate,
7921}
7922
7923/// Trigger FOR EACH clause
7924#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7925#[cfg_attr(feature = "bindings", derive(TS))]
7926pub enum TriggerForEach {
7927    Row,
7928    Statement,
7929}
7930
7931/// Trigger body
7932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7933#[cfg_attr(feature = "bindings", derive(TS))]
7934pub enum TriggerBody {
7935    /// EXECUTE FUNCTION/PROCEDURE name(args)
7936    Execute {
7937        function: TableRef,
7938        args: Vec<Expression>,
7939    },
7940    /// BEGIN ... END block
7941    Block(String),
7942}
7943
7944/// Trigger REFERENCING clause
7945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7946#[cfg_attr(feature = "bindings", derive(TS))]
7947pub struct TriggerReferencing {
7948    pub old_table: Option<Identifier>,
7949    pub new_table: Option<Identifier>,
7950    pub old_row: Option<Identifier>,
7951    pub new_row: Option<Identifier>,
7952}
7953
7954impl CreateTrigger {
7955    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7956        Self {
7957            name: Identifier::new(name),
7958            table: TableRef::new(table),
7959            timing: TriggerTiming::Before,
7960            events: Vec::new(),
7961            for_each: Some(TriggerForEach::Row),
7962            when: None,
7963            when_paren: false,
7964            body: TriggerBody::Execute {
7965                function: TableRef::new(""),
7966                args: Vec::new(),
7967            },
7968            or_replace: false,
7969            constraint: false,
7970            deferrable: None,
7971            initially_deferred: None,
7972            referencing: None,
7973        }
7974    }
7975}
7976
7977/// DROP TRIGGER statement
7978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7979#[cfg_attr(feature = "bindings", derive(TS))]
7980pub struct DropTrigger {
7981    pub name: Identifier,
7982    pub table: Option<TableRef>,
7983    pub if_exists: bool,
7984    pub cascade: bool,
7985}
7986
7987impl DropTrigger {
7988    pub fn new(name: impl Into<String>) -> Self {
7989        Self {
7990            name: Identifier::new(name),
7991            table: None,
7992            if_exists: false,
7993            cascade: false,
7994        }
7995    }
7996}
7997
7998/// CREATE TYPE statement
7999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8000#[cfg_attr(feature = "bindings", derive(TS))]
8001pub struct CreateType {
8002    pub name: TableRef,
8003    pub definition: TypeDefinition,
8004    pub if_not_exists: bool,
8005}
8006
8007/// Type definition
8008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8009#[cfg_attr(feature = "bindings", derive(TS))]
8010pub enum TypeDefinition {
8011    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
8012    Enum(Vec<String>),
8013    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
8014    Composite(Vec<TypeAttribute>),
8015    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
8016    Range {
8017        subtype: DataType,
8018        subtype_diff: Option<String>,
8019        canonical: Option<String>,
8020    },
8021    /// Base type (for advanced usage)
8022    Base {
8023        input: String,
8024        output: String,
8025        internallength: Option<i32>,
8026    },
8027    /// Domain type
8028    Domain {
8029        base_type: DataType,
8030        default: Option<Expression>,
8031        constraints: Vec<DomainConstraint>,
8032    },
8033}
8034
8035/// Type attribute for composite types
8036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8037#[cfg_attr(feature = "bindings", derive(TS))]
8038pub struct TypeAttribute {
8039    pub name: Identifier,
8040    pub data_type: DataType,
8041    pub collate: Option<Identifier>,
8042}
8043
8044/// Domain constraint
8045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8046#[cfg_attr(feature = "bindings", derive(TS))]
8047pub struct DomainConstraint {
8048    pub name: Option<Identifier>,
8049    pub check: Expression,
8050}
8051
8052impl CreateType {
8053    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
8054        Self {
8055            name: TableRef::new(name),
8056            definition: TypeDefinition::Enum(values),
8057            if_not_exists: false,
8058        }
8059    }
8060
8061    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
8062        Self {
8063            name: TableRef::new(name),
8064            definition: TypeDefinition::Composite(attributes),
8065            if_not_exists: false,
8066        }
8067    }
8068}
8069
8070/// DROP TYPE statement
8071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8072#[cfg_attr(feature = "bindings", derive(TS))]
8073pub struct DropType {
8074    pub name: TableRef,
8075    pub if_exists: bool,
8076    pub cascade: bool,
8077}
8078
8079impl DropType {
8080    pub fn new(name: impl Into<String>) -> Self {
8081        Self {
8082            name: TableRef::new(name),
8083            if_exists: false,
8084            cascade: false,
8085        }
8086    }
8087}
8088
8089/// DESCRIBE statement - shows table structure or query plan
8090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8091#[cfg_attr(feature = "bindings", derive(TS))]
8092pub struct Describe {
8093    /// The target to describe (table name or query)
8094    pub target: Expression,
8095    /// EXTENDED format
8096    pub extended: bool,
8097    /// FORMATTED format
8098    pub formatted: bool,
8099    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
8100    #[serde(default)]
8101    pub kind: Option<String>,
8102    /// Properties like type=stage
8103    #[serde(default)]
8104    pub properties: Vec<(String, String)>,
8105    /// Style keyword (e.g., "ANALYZE", "HISTORY")
8106    #[serde(default, skip_serializing_if = "Option::is_none")]
8107    pub style: Option<String>,
8108    /// Partition specification for DESCRIBE PARTITION
8109    #[serde(default)]
8110    pub partition: Option<Box<Expression>>,
8111    /// Leading comments before the statement
8112    #[serde(default)]
8113    pub leading_comments: Vec<String>,
8114    /// AS JSON suffix (Databricks)
8115    #[serde(default)]
8116    pub as_json: bool,
8117}
8118
8119impl Describe {
8120    pub fn new(target: Expression) -> Self {
8121        Self {
8122            target,
8123            extended: false,
8124            formatted: false,
8125            kind: None,
8126            properties: Vec::new(),
8127            style: None,
8128            partition: None,
8129            leading_comments: Vec::new(),
8130            as_json: false,
8131        }
8132    }
8133}
8134
8135/// SHOW statement - displays database objects
8136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8137#[cfg_attr(feature = "bindings", derive(TS))]
8138pub struct Show {
8139    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
8140    pub this: String,
8141    /// Whether TERSE was specified
8142    #[serde(default)]
8143    pub terse: bool,
8144    /// Whether HISTORY was specified
8145    #[serde(default)]
8146    pub history: bool,
8147    /// LIKE pattern
8148    pub like: Option<Expression>,
8149    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
8150    pub scope_kind: Option<String>,
8151    /// IN scope object
8152    pub scope: Option<Expression>,
8153    /// STARTS WITH pattern
8154    pub starts_with: Option<Expression>,
8155    /// LIMIT clause
8156    pub limit: Option<Box<Limit>>,
8157    /// FROM clause (for specific object)
8158    pub from: Option<Expression>,
8159    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
8160    #[serde(default, skip_serializing_if = "Option::is_none")]
8161    pub where_clause: Option<Expression>,
8162    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
8163    #[serde(default, skip_serializing_if = "Option::is_none")]
8164    pub for_target: Option<Expression>,
8165    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
8166    #[serde(default, skip_serializing_if = "Option::is_none")]
8167    pub db: Option<Expression>,
8168    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
8169    #[serde(default, skip_serializing_if = "Option::is_none")]
8170    pub target: Option<Expression>,
8171    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
8172    #[serde(default, skip_serializing_if = "Option::is_none")]
8173    pub mutex: Option<bool>,
8174    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
8175    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8176    pub privileges: Vec<String>,
8177}
8178
8179impl Show {
8180    pub fn new(this: impl Into<String>) -> Self {
8181        Self {
8182            this: this.into(),
8183            terse: false,
8184            history: false,
8185            like: None,
8186            scope_kind: None,
8187            scope: None,
8188            starts_with: None,
8189            limit: None,
8190            from: None,
8191            where_clause: None,
8192            for_target: None,
8193            db: None,
8194            target: None,
8195            mutex: None,
8196            privileges: Vec::new(),
8197        }
8198    }
8199}
8200
8201/// Represent an explicit parenthesized expression for grouping precedence.
8202///
8203/// Preserves user-written parentheses so that `(a + b) * c` round-trips
8204/// correctly instead of being flattened to `a + b * c`.
8205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8206#[cfg_attr(feature = "bindings", derive(TS))]
8207pub struct Paren {
8208    /// The inner expression wrapped by parentheses.
8209    pub this: Expression,
8210    #[serde(default)]
8211    pub trailing_comments: Vec<String>,
8212}
8213
8214/// Expression annotated with trailing comments (for round-trip preservation)
8215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8216#[cfg_attr(feature = "bindings", derive(TS))]
8217pub struct Annotated {
8218    pub this: Expression,
8219    pub trailing_comments: Vec<String>,
8220}
8221
8222// === BATCH GENERATED STRUCT DEFINITIONS ===
8223// Generated from Python sqlglot expressions.py
8224
8225/// Refresh
8226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8227#[cfg_attr(feature = "bindings", derive(TS))]
8228pub struct Refresh {
8229    pub this: Box<Expression>,
8230    pub kind: String,
8231}
8232
8233/// LockingStatement
8234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8235#[cfg_attr(feature = "bindings", derive(TS))]
8236pub struct LockingStatement {
8237    pub this: Box<Expression>,
8238    pub expression: Box<Expression>,
8239}
8240
8241/// SequenceProperties
8242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8243#[cfg_attr(feature = "bindings", derive(TS))]
8244pub struct SequenceProperties {
8245    #[serde(default)]
8246    pub increment: Option<Box<Expression>>,
8247    #[serde(default)]
8248    pub minvalue: Option<Box<Expression>>,
8249    #[serde(default)]
8250    pub maxvalue: Option<Box<Expression>>,
8251    #[serde(default)]
8252    pub cache: Option<Box<Expression>>,
8253    #[serde(default)]
8254    pub start: Option<Box<Expression>>,
8255    #[serde(default)]
8256    pub owned: Option<Box<Expression>>,
8257    #[serde(default)]
8258    pub options: Vec<Expression>,
8259}
8260
8261/// TruncateTable
8262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8263#[cfg_attr(feature = "bindings", derive(TS))]
8264pub struct TruncateTable {
8265    #[serde(default)]
8266    pub expressions: Vec<Expression>,
8267    #[serde(default)]
8268    pub is_database: Option<Box<Expression>>,
8269    #[serde(default)]
8270    pub exists: bool,
8271    #[serde(default)]
8272    pub only: Option<Box<Expression>>,
8273    #[serde(default)]
8274    pub cluster: Option<Box<Expression>>,
8275    #[serde(default)]
8276    pub identity: Option<Box<Expression>>,
8277    #[serde(default)]
8278    pub option: Option<Box<Expression>>,
8279    #[serde(default)]
8280    pub partition: Option<Box<Expression>>,
8281}
8282
8283/// Clone
8284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8285#[cfg_attr(feature = "bindings", derive(TS))]
8286pub struct Clone {
8287    pub this: Box<Expression>,
8288    #[serde(default)]
8289    pub shallow: Option<Box<Expression>>,
8290    #[serde(default)]
8291    pub copy: Option<Box<Expression>>,
8292}
8293
8294/// Attach
8295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8296#[cfg_attr(feature = "bindings", derive(TS))]
8297pub struct Attach {
8298    pub this: Box<Expression>,
8299    #[serde(default)]
8300    pub exists: bool,
8301    #[serde(default)]
8302    pub expressions: Vec<Expression>,
8303}
8304
8305/// Detach
8306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8307#[cfg_attr(feature = "bindings", derive(TS))]
8308pub struct Detach {
8309    pub this: Box<Expression>,
8310    #[serde(default)]
8311    pub exists: bool,
8312}
8313
8314/// Install
8315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8316#[cfg_attr(feature = "bindings", derive(TS))]
8317pub struct Install {
8318    pub this: Box<Expression>,
8319    #[serde(default)]
8320    pub from_: Option<Box<Expression>>,
8321    #[serde(default)]
8322    pub force: Option<Box<Expression>>,
8323}
8324
8325/// Summarize
8326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8327#[cfg_attr(feature = "bindings", derive(TS))]
8328pub struct Summarize {
8329    pub this: Box<Expression>,
8330    #[serde(default)]
8331    pub table: Option<Box<Expression>>,
8332}
8333
8334/// Declare
8335#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8336#[cfg_attr(feature = "bindings", derive(TS))]
8337pub struct Declare {
8338    #[serde(default)]
8339    pub expressions: Vec<Expression>,
8340}
8341
8342/// DeclareItem
8343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8344#[cfg_attr(feature = "bindings", derive(TS))]
8345pub struct DeclareItem {
8346    pub this: Box<Expression>,
8347    #[serde(default)]
8348    pub kind: Option<String>,
8349    #[serde(default)]
8350    pub default: Option<Box<Expression>>,
8351    #[serde(default)]
8352    pub has_as: bool,
8353    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
8354    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8355    pub additional_names: Vec<Expression>,
8356}
8357
8358/// Set
8359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8360#[cfg_attr(feature = "bindings", derive(TS))]
8361pub struct Set {
8362    #[serde(default)]
8363    pub expressions: Vec<Expression>,
8364    #[serde(default)]
8365    pub unset: Option<Box<Expression>>,
8366    #[serde(default)]
8367    pub tag: Option<Box<Expression>>,
8368}
8369
8370/// Heredoc
8371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8372#[cfg_attr(feature = "bindings", derive(TS))]
8373pub struct Heredoc {
8374    pub this: Box<Expression>,
8375    #[serde(default)]
8376    pub tag: Option<Box<Expression>>,
8377}
8378
8379/// QueryBand
8380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8381#[cfg_attr(feature = "bindings", derive(TS))]
8382pub struct QueryBand {
8383    pub this: Box<Expression>,
8384    #[serde(default)]
8385    pub scope: Option<Box<Expression>>,
8386    #[serde(default)]
8387    pub update: Option<Box<Expression>>,
8388}
8389
8390/// UserDefinedFunction
8391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8392#[cfg_attr(feature = "bindings", derive(TS))]
8393pub struct UserDefinedFunction {
8394    pub this: Box<Expression>,
8395    #[serde(default)]
8396    pub expressions: Vec<Expression>,
8397    #[serde(default)]
8398    pub wrapped: Option<Box<Expression>>,
8399}
8400
8401/// RecursiveWithSearch
8402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8403#[cfg_attr(feature = "bindings", derive(TS))]
8404pub struct RecursiveWithSearch {
8405    pub kind: String,
8406    pub this: Box<Expression>,
8407    pub expression: Box<Expression>,
8408    #[serde(default)]
8409    pub using: Option<Box<Expression>>,
8410}
8411
8412/// ProjectionDef
8413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8414#[cfg_attr(feature = "bindings", derive(TS))]
8415pub struct ProjectionDef {
8416    pub this: Box<Expression>,
8417    pub expression: Box<Expression>,
8418}
8419
8420/// TableAlias
8421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8422#[cfg_attr(feature = "bindings", derive(TS))]
8423pub struct TableAlias {
8424    #[serde(default)]
8425    pub this: Option<Box<Expression>>,
8426    #[serde(default)]
8427    pub columns: Vec<Expression>,
8428}
8429
8430/// ByteString
8431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8432#[cfg_attr(feature = "bindings", derive(TS))]
8433pub struct ByteString {
8434    pub this: Box<Expression>,
8435    #[serde(default)]
8436    pub is_bytes: Option<Box<Expression>>,
8437}
8438
8439/// HexStringExpr - Hex string expression (not literal)
8440/// BigQuery: converts to FROM_HEX(this)
8441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8442#[cfg_attr(feature = "bindings", derive(TS))]
8443pub struct HexStringExpr {
8444    pub this: Box<Expression>,
8445    #[serde(default)]
8446    pub is_integer: Option<bool>,
8447}
8448
8449/// UnicodeString
8450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8451#[cfg_attr(feature = "bindings", derive(TS))]
8452pub struct UnicodeString {
8453    pub this: Box<Expression>,
8454    #[serde(default)]
8455    pub escape: Option<Box<Expression>>,
8456}
8457
8458/// AlterColumn
8459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8460#[cfg_attr(feature = "bindings", derive(TS))]
8461pub struct AlterColumn {
8462    pub this: Box<Expression>,
8463    #[serde(default)]
8464    pub dtype: Option<Box<Expression>>,
8465    #[serde(default)]
8466    pub collate: Option<Box<Expression>>,
8467    #[serde(default)]
8468    pub using: Option<Box<Expression>>,
8469    #[serde(default)]
8470    pub default: Option<Box<Expression>>,
8471    #[serde(default)]
8472    pub drop: Option<Box<Expression>>,
8473    #[serde(default)]
8474    pub comment: Option<Box<Expression>>,
8475    #[serde(default)]
8476    pub allow_null: Option<Box<Expression>>,
8477    #[serde(default)]
8478    pub visible: Option<Box<Expression>>,
8479    #[serde(default)]
8480    pub rename_to: Option<Box<Expression>>,
8481}
8482
8483/// AlterSortKey
8484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8485#[cfg_attr(feature = "bindings", derive(TS))]
8486pub struct AlterSortKey {
8487    #[serde(default)]
8488    pub this: Option<Box<Expression>>,
8489    #[serde(default)]
8490    pub expressions: Vec<Expression>,
8491    #[serde(default)]
8492    pub compound: Option<Box<Expression>>,
8493}
8494
8495/// AlterSet
8496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8497#[cfg_attr(feature = "bindings", derive(TS))]
8498pub struct AlterSet {
8499    #[serde(default)]
8500    pub expressions: Vec<Expression>,
8501    #[serde(default)]
8502    pub option: Option<Box<Expression>>,
8503    #[serde(default)]
8504    pub tablespace: Option<Box<Expression>>,
8505    #[serde(default)]
8506    pub access_method: Option<Box<Expression>>,
8507    #[serde(default)]
8508    pub file_format: Option<Box<Expression>>,
8509    #[serde(default)]
8510    pub copy_options: Option<Box<Expression>>,
8511    #[serde(default)]
8512    pub tag: Option<Box<Expression>>,
8513    #[serde(default)]
8514    pub location: Option<Box<Expression>>,
8515    #[serde(default)]
8516    pub serde: Option<Box<Expression>>,
8517}
8518
8519/// RenameColumn
8520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8521#[cfg_attr(feature = "bindings", derive(TS))]
8522pub struct RenameColumn {
8523    pub this: Box<Expression>,
8524    #[serde(default)]
8525    pub to: Option<Box<Expression>>,
8526    #[serde(default)]
8527    pub exists: bool,
8528}
8529
8530/// Comprehension
8531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8532#[cfg_attr(feature = "bindings", derive(TS))]
8533pub struct Comprehension {
8534    pub this: Box<Expression>,
8535    pub expression: Box<Expression>,
8536    #[serde(default)]
8537    pub position: Option<Box<Expression>>,
8538    #[serde(default)]
8539    pub iterator: Option<Box<Expression>>,
8540    #[serde(default)]
8541    pub condition: Option<Box<Expression>>,
8542}
8543
8544/// MergeTreeTTLAction
8545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8546#[cfg_attr(feature = "bindings", derive(TS))]
8547pub struct MergeTreeTTLAction {
8548    pub this: Box<Expression>,
8549    #[serde(default)]
8550    pub delete: Option<Box<Expression>>,
8551    #[serde(default)]
8552    pub recompress: Option<Box<Expression>>,
8553    #[serde(default)]
8554    pub to_disk: Option<Box<Expression>>,
8555    #[serde(default)]
8556    pub to_volume: Option<Box<Expression>>,
8557}
8558
8559/// MergeTreeTTL
8560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8561#[cfg_attr(feature = "bindings", derive(TS))]
8562pub struct MergeTreeTTL {
8563    #[serde(default)]
8564    pub expressions: Vec<Expression>,
8565    #[serde(default)]
8566    pub where_: Option<Box<Expression>>,
8567    #[serde(default)]
8568    pub group: Option<Box<Expression>>,
8569    #[serde(default)]
8570    pub aggregates: Option<Box<Expression>>,
8571}
8572
8573/// IndexConstraintOption
8574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8575#[cfg_attr(feature = "bindings", derive(TS))]
8576pub struct IndexConstraintOption {
8577    #[serde(default)]
8578    pub key_block_size: Option<Box<Expression>>,
8579    #[serde(default)]
8580    pub using: Option<Box<Expression>>,
8581    #[serde(default)]
8582    pub parser: Option<Box<Expression>>,
8583    #[serde(default)]
8584    pub comment: Option<Box<Expression>>,
8585    #[serde(default)]
8586    pub visible: Option<Box<Expression>>,
8587    #[serde(default)]
8588    pub engine_attr: Option<Box<Expression>>,
8589    #[serde(default)]
8590    pub secondary_engine_attr: Option<Box<Expression>>,
8591}
8592
8593/// PeriodForSystemTimeConstraint
8594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8595#[cfg_attr(feature = "bindings", derive(TS))]
8596pub struct PeriodForSystemTimeConstraint {
8597    pub this: Box<Expression>,
8598    pub expression: Box<Expression>,
8599}
8600
8601/// CaseSpecificColumnConstraint
8602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8603#[cfg_attr(feature = "bindings", derive(TS))]
8604pub struct CaseSpecificColumnConstraint {
8605    #[serde(default)]
8606    pub not_: Option<Box<Expression>>,
8607}
8608
8609/// CharacterSetColumnConstraint
8610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8611#[cfg_attr(feature = "bindings", derive(TS))]
8612pub struct CharacterSetColumnConstraint {
8613    pub this: Box<Expression>,
8614}
8615
8616/// CheckColumnConstraint
8617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8618#[cfg_attr(feature = "bindings", derive(TS))]
8619pub struct CheckColumnConstraint {
8620    pub this: Box<Expression>,
8621    #[serde(default)]
8622    pub enforced: Option<Box<Expression>>,
8623}
8624
8625/// CompressColumnConstraint
8626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8627#[cfg_attr(feature = "bindings", derive(TS))]
8628pub struct CompressColumnConstraint {
8629    #[serde(default)]
8630    pub this: Option<Box<Expression>>,
8631}
8632
8633/// DateFormatColumnConstraint
8634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8635#[cfg_attr(feature = "bindings", derive(TS))]
8636pub struct DateFormatColumnConstraint {
8637    pub this: Box<Expression>,
8638}
8639
8640/// EphemeralColumnConstraint
8641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8642#[cfg_attr(feature = "bindings", derive(TS))]
8643pub struct EphemeralColumnConstraint {
8644    #[serde(default)]
8645    pub this: Option<Box<Expression>>,
8646}
8647
8648/// WithOperator
8649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8650#[cfg_attr(feature = "bindings", derive(TS))]
8651pub struct WithOperator {
8652    pub this: Box<Expression>,
8653    pub op: String,
8654}
8655
8656/// GeneratedAsIdentityColumnConstraint
8657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8658#[cfg_attr(feature = "bindings", derive(TS))]
8659pub struct GeneratedAsIdentityColumnConstraint {
8660    #[serde(default)]
8661    pub this: Option<Box<Expression>>,
8662    #[serde(default)]
8663    pub expression: Option<Box<Expression>>,
8664    #[serde(default)]
8665    pub on_null: Option<Box<Expression>>,
8666    #[serde(default)]
8667    pub start: Option<Box<Expression>>,
8668    #[serde(default)]
8669    pub increment: Option<Box<Expression>>,
8670    #[serde(default)]
8671    pub minvalue: Option<Box<Expression>>,
8672    #[serde(default)]
8673    pub maxvalue: Option<Box<Expression>>,
8674    #[serde(default)]
8675    pub cycle: Option<Box<Expression>>,
8676    #[serde(default)]
8677    pub order: Option<Box<Expression>>,
8678}
8679
8680/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8681/// TSQL: outputs "IDENTITY"
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct AutoIncrementColumnConstraint;
8685
8686/// CommentColumnConstraint - Column comment marker
8687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8688#[cfg_attr(feature = "bindings", derive(TS))]
8689pub struct CommentColumnConstraint;
8690
8691/// GeneratedAsRowColumnConstraint
8692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8693#[cfg_attr(feature = "bindings", derive(TS))]
8694pub struct GeneratedAsRowColumnConstraint {
8695    #[serde(default)]
8696    pub start: Option<Box<Expression>>,
8697    #[serde(default)]
8698    pub hidden: Option<Box<Expression>>,
8699}
8700
8701/// IndexColumnConstraint
8702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8703#[cfg_attr(feature = "bindings", derive(TS))]
8704pub struct IndexColumnConstraint {
8705    #[serde(default)]
8706    pub this: Option<Box<Expression>>,
8707    #[serde(default)]
8708    pub expressions: Vec<Expression>,
8709    #[serde(default)]
8710    pub kind: Option<String>,
8711    #[serde(default)]
8712    pub index_type: Option<Box<Expression>>,
8713    #[serde(default)]
8714    pub options: Vec<Expression>,
8715    #[serde(default)]
8716    pub expression: Option<Box<Expression>>,
8717    #[serde(default)]
8718    pub granularity: Option<Box<Expression>>,
8719}
8720
8721/// MaskingPolicyColumnConstraint
8722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8723#[cfg_attr(feature = "bindings", derive(TS))]
8724pub struct MaskingPolicyColumnConstraint {
8725    pub this: Box<Expression>,
8726    #[serde(default)]
8727    pub expressions: Vec<Expression>,
8728}
8729
8730/// NotNullColumnConstraint
8731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8732#[cfg_attr(feature = "bindings", derive(TS))]
8733pub struct NotNullColumnConstraint {
8734    #[serde(default)]
8735    pub allow_null: Option<Box<Expression>>,
8736}
8737
8738/// DefaultColumnConstraint - DEFAULT value for a column
8739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8740#[cfg_attr(feature = "bindings", derive(TS))]
8741pub struct DefaultColumnConstraint {
8742    pub this: Box<Expression>,
8743}
8744
8745/// PrimaryKeyColumnConstraint
8746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8747#[cfg_attr(feature = "bindings", derive(TS))]
8748pub struct PrimaryKeyColumnConstraint {
8749    #[serde(default)]
8750    pub desc: Option<Box<Expression>>,
8751    #[serde(default)]
8752    pub options: Vec<Expression>,
8753}
8754
8755/// UniqueColumnConstraint
8756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8757#[cfg_attr(feature = "bindings", derive(TS))]
8758pub struct UniqueColumnConstraint {
8759    #[serde(default)]
8760    pub this: Option<Box<Expression>>,
8761    #[serde(default)]
8762    pub index_type: Option<Box<Expression>>,
8763    #[serde(default)]
8764    pub on_conflict: Option<Box<Expression>>,
8765    #[serde(default)]
8766    pub nulls: Option<Box<Expression>>,
8767    #[serde(default)]
8768    pub options: Vec<Expression>,
8769}
8770
8771/// WatermarkColumnConstraint
8772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8773#[cfg_attr(feature = "bindings", derive(TS))]
8774pub struct WatermarkColumnConstraint {
8775    pub this: Box<Expression>,
8776    pub expression: Box<Expression>,
8777}
8778
8779/// ComputedColumnConstraint
8780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8781#[cfg_attr(feature = "bindings", derive(TS))]
8782pub struct ComputedColumnConstraint {
8783    pub this: Box<Expression>,
8784    #[serde(default)]
8785    pub persisted: Option<Box<Expression>>,
8786    #[serde(default)]
8787    pub not_null: Option<Box<Expression>>,
8788    #[serde(default)]
8789    pub data_type: Option<Box<Expression>>,
8790}
8791
8792/// InOutColumnConstraint
8793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8794#[cfg_attr(feature = "bindings", derive(TS))]
8795pub struct InOutColumnConstraint {
8796    #[serde(default)]
8797    pub input_: Option<Box<Expression>>,
8798    #[serde(default)]
8799    pub output: Option<Box<Expression>>,
8800}
8801
8802/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8804#[cfg_attr(feature = "bindings", derive(TS))]
8805pub struct PathColumnConstraint {
8806    pub this: Box<Expression>,
8807}
8808
8809/// Constraint
8810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8811#[cfg_attr(feature = "bindings", derive(TS))]
8812pub struct Constraint {
8813    pub this: Box<Expression>,
8814    #[serde(default)]
8815    pub expressions: Vec<Expression>,
8816}
8817
8818/// Export
8819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8820#[cfg_attr(feature = "bindings", derive(TS))]
8821pub struct Export {
8822    pub this: Box<Expression>,
8823    #[serde(default)]
8824    pub connection: Option<Box<Expression>>,
8825    #[serde(default)]
8826    pub options: Vec<Expression>,
8827}
8828
8829/// Filter
8830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8831#[cfg_attr(feature = "bindings", derive(TS))]
8832pub struct Filter {
8833    pub this: Box<Expression>,
8834    pub expression: Box<Expression>,
8835}
8836
8837/// Changes
8838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8839#[cfg_attr(feature = "bindings", derive(TS))]
8840pub struct Changes {
8841    #[serde(default)]
8842    pub information: Option<Box<Expression>>,
8843    #[serde(default)]
8844    pub at_before: Option<Box<Expression>>,
8845    #[serde(default)]
8846    pub end: Option<Box<Expression>>,
8847}
8848
8849/// Directory
8850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8851#[cfg_attr(feature = "bindings", derive(TS))]
8852pub struct Directory {
8853    pub this: Box<Expression>,
8854    #[serde(default)]
8855    pub local: Option<Box<Expression>>,
8856    #[serde(default)]
8857    pub row_format: Option<Box<Expression>>,
8858}
8859
8860/// ForeignKey
8861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8862#[cfg_attr(feature = "bindings", derive(TS))]
8863pub struct ForeignKey {
8864    #[serde(default)]
8865    pub expressions: Vec<Expression>,
8866    #[serde(default)]
8867    pub reference: Option<Box<Expression>>,
8868    #[serde(default)]
8869    pub delete: Option<Box<Expression>>,
8870    #[serde(default)]
8871    pub update: Option<Box<Expression>>,
8872    #[serde(default)]
8873    pub options: Vec<Expression>,
8874}
8875
8876/// ColumnPrefix
8877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8878#[cfg_attr(feature = "bindings", derive(TS))]
8879pub struct ColumnPrefix {
8880    pub this: Box<Expression>,
8881    pub expression: Box<Expression>,
8882}
8883
8884/// PrimaryKey
8885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8886#[cfg_attr(feature = "bindings", derive(TS))]
8887pub struct PrimaryKey {
8888    #[serde(default)]
8889    pub this: Option<Box<Expression>>,
8890    #[serde(default)]
8891    pub expressions: Vec<Expression>,
8892    #[serde(default)]
8893    pub options: Vec<Expression>,
8894    #[serde(default)]
8895    pub include: Option<Box<Expression>>,
8896}
8897
8898/// Into
8899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8900#[cfg_attr(feature = "bindings", derive(TS))]
8901pub struct IntoClause {
8902    #[serde(default)]
8903    pub this: Option<Box<Expression>>,
8904    #[serde(default)]
8905    pub temporary: bool,
8906    #[serde(default)]
8907    pub unlogged: Option<Box<Expression>>,
8908    #[serde(default)]
8909    pub bulk_collect: Option<Box<Expression>>,
8910    #[serde(default)]
8911    pub expressions: Vec<Expression>,
8912}
8913
8914/// JoinHint
8915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8916#[cfg_attr(feature = "bindings", derive(TS))]
8917pub struct JoinHint {
8918    pub this: Box<Expression>,
8919    #[serde(default)]
8920    pub expressions: Vec<Expression>,
8921}
8922
8923/// Opclass
8924#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8925#[cfg_attr(feature = "bindings", derive(TS))]
8926pub struct Opclass {
8927    pub this: Box<Expression>,
8928    pub expression: Box<Expression>,
8929}
8930
8931/// Index
8932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8933#[cfg_attr(feature = "bindings", derive(TS))]
8934pub struct Index {
8935    #[serde(default)]
8936    pub this: Option<Box<Expression>>,
8937    #[serde(default)]
8938    pub table: Option<Box<Expression>>,
8939    #[serde(default)]
8940    pub unique: bool,
8941    #[serde(default)]
8942    pub primary: Option<Box<Expression>>,
8943    #[serde(default)]
8944    pub amp: Option<Box<Expression>>,
8945    #[serde(default)]
8946    pub params: Vec<Expression>,
8947}
8948
8949/// IndexParameters
8950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8951#[cfg_attr(feature = "bindings", derive(TS))]
8952pub struct IndexParameters {
8953    #[serde(default)]
8954    pub using: Option<Box<Expression>>,
8955    #[serde(default)]
8956    pub include: Option<Box<Expression>>,
8957    #[serde(default)]
8958    pub columns: Vec<Expression>,
8959    #[serde(default)]
8960    pub with_storage: Option<Box<Expression>>,
8961    #[serde(default)]
8962    pub partition_by: Option<Box<Expression>>,
8963    #[serde(default)]
8964    pub tablespace: Option<Box<Expression>>,
8965    #[serde(default)]
8966    pub where_: Option<Box<Expression>>,
8967    #[serde(default)]
8968    pub on: Option<Box<Expression>>,
8969}
8970
8971/// ConditionalInsert
8972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8973#[cfg_attr(feature = "bindings", derive(TS))]
8974pub struct ConditionalInsert {
8975    pub this: Box<Expression>,
8976    #[serde(default)]
8977    pub expression: Option<Box<Expression>>,
8978    #[serde(default)]
8979    pub else_: Option<Box<Expression>>,
8980}
8981
8982/// MultitableInserts
8983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8984#[cfg_attr(feature = "bindings", derive(TS))]
8985pub struct MultitableInserts {
8986    #[serde(default)]
8987    pub expressions: Vec<Expression>,
8988    pub kind: String,
8989    #[serde(default)]
8990    pub source: Option<Box<Expression>>,
8991    /// Leading comments before the statement
8992    #[serde(default)]
8993    pub leading_comments: Vec<String>,
8994}
8995
8996/// OnConflict
8997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8998#[cfg_attr(feature = "bindings", derive(TS))]
8999pub struct OnConflict {
9000    #[serde(default)]
9001    pub duplicate: Option<Box<Expression>>,
9002    #[serde(default)]
9003    pub expressions: Vec<Expression>,
9004    #[serde(default)]
9005    pub action: Option<Box<Expression>>,
9006    #[serde(default)]
9007    pub conflict_keys: Option<Box<Expression>>,
9008    #[serde(default)]
9009    pub index_predicate: Option<Box<Expression>>,
9010    #[serde(default)]
9011    pub constraint: Option<Box<Expression>>,
9012    #[serde(default)]
9013    pub where_: Option<Box<Expression>>,
9014}
9015
9016/// OnCondition
9017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9018#[cfg_attr(feature = "bindings", derive(TS))]
9019pub struct OnCondition {
9020    #[serde(default)]
9021    pub error: Option<Box<Expression>>,
9022    #[serde(default)]
9023    pub empty: Option<Box<Expression>>,
9024    #[serde(default)]
9025    pub null: Option<Box<Expression>>,
9026}
9027
9028/// Returning
9029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9030#[cfg_attr(feature = "bindings", derive(TS))]
9031pub struct Returning {
9032    #[serde(default)]
9033    pub expressions: Vec<Expression>,
9034    #[serde(default)]
9035    pub into: Option<Box<Expression>>,
9036}
9037
9038/// Introducer
9039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9040#[cfg_attr(feature = "bindings", derive(TS))]
9041pub struct Introducer {
9042    pub this: Box<Expression>,
9043    pub expression: Box<Expression>,
9044}
9045
9046/// PartitionRange
9047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9048#[cfg_attr(feature = "bindings", derive(TS))]
9049pub struct PartitionRange {
9050    pub this: Box<Expression>,
9051    #[serde(default)]
9052    pub expression: Option<Box<Expression>>,
9053    #[serde(default)]
9054    pub expressions: Vec<Expression>,
9055}
9056
9057/// Group
9058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9059#[cfg_attr(feature = "bindings", derive(TS))]
9060pub struct Group {
9061    #[serde(default)]
9062    pub expressions: Vec<Expression>,
9063    #[serde(default)]
9064    pub grouping_sets: Option<Box<Expression>>,
9065    #[serde(default)]
9066    pub cube: Option<Box<Expression>>,
9067    #[serde(default)]
9068    pub rollup: Option<Box<Expression>>,
9069    #[serde(default)]
9070    pub totals: Option<Box<Expression>>,
9071    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
9072    #[serde(default)]
9073    pub all: Option<bool>,
9074}
9075
9076/// Cube
9077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9078#[cfg_attr(feature = "bindings", derive(TS))]
9079pub struct Cube {
9080    #[serde(default)]
9081    pub expressions: Vec<Expression>,
9082}
9083
9084/// Rollup
9085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9086#[cfg_attr(feature = "bindings", derive(TS))]
9087pub struct Rollup {
9088    #[serde(default)]
9089    pub expressions: Vec<Expression>,
9090}
9091
9092/// GroupingSets
9093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9094#[cfg_attr(feature = "bindings", derive(TS))]
9095pub struct GroupingSets {
9096    #[serde(default)]
9097    pub expressions: Vec<Expression>,
9098}
9099
9100/// LimitOptions
9101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9102#[cfg_attr(feature = "bindings", derive(TS))]
9103pub struct LimitOptions {
9104    #[serde(default)]
9105    pub percent: Option<Box<Expression>>,
9106    #[serde(default)]
9107    pub rows: Option<Box<Expression>>,
9108    #[serde(default)]
9109    pub with_ties: Option<Box<Expression>>,
9110}
9111
9112/// Lateral
9113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9114#[cfg_attr(feature = "bindings", derive(TS))]
9115pub struct Lateral {
9116    pub this: Box<Expression>,
9117    #[serde(default)]
9118    pub view: Option<Box<Expression>>,
9119    #[serde(default)]
9120    pub outer: Option<Box<Expression>>,
9121    #[serde(default)]
9122    pub alias: Option<String>,
9123    /// Whether the alias was originally quoted (backtick/double-quote)
9124    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9125    pub alias_quoted: bool,
9126    #[serde(default)]
9127    pub cross_apply: Option<Box<Expression>>,
9128    #[serde(default)]
9129    pub ordinality: Option<Box<Expression>>,
9130    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
9131    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9132    pub column_aliases: Vec<String>,
9133}
9134
9135/// TableFromRows
9136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9137#[cfg_attr(feature = "bindings", derive(TS))]
9138pub struct TableFromRows {
9139    pub this: Box<Expression>,
9140    #[serde(default)]
9141    pub alias: Option<String>,
9142    #[serde(default)]
9143    pub joins: Vec<Expression>,
9144    #[serde(default)]
9145    pub pivots: Option<Box<Expression>>,
9146    #[serde(default)]
9147    pub sample: Option<Box<Expression>>,
9148}
9149
9150/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
9151/// Used for set-returning functions with typed column definitions
9152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9153#[cfg_attr(feature = "bindings", derive(TS))]
9154pub struct RowsFrom {
9155    /// List of function expressions, each potentially with an alias and typed columns
9156    pub expressions: Vec<Expression>,
9157    /// WITH ORDINALITY modifier
9158    #[serde(default)]
9159    pub ordinality: bool,
9160    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
9161    #[serde(default)]
9162    pub alias: Option<Box<Expression>>,
9163}
9164
9165/// WithFill
9166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9167#[cfg_attr(feature = "bindings", derive(TS))]
9168pub struct WithFill {
9169    #[serde(default)]
9170    pub from_: Option<Box<Expression>>,
9171    #[serde(default)]
9172    pub to: Option<Box<Expression>>,
9173    #[serde(default)]
9174    pub step: Option<Box<Expression>>,
9175    #[serde(default)]
9176    pub staleness: Option<Box<Expression>>,
9177    #[serde(default)]
9178    pub interpolate: Option<Box<Expression>>,
9179}
9180
9181/// Property
9182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9183#[cfg_attr(feature = "bindings", derive(TS))]
9184pub struct Property {
9185    pub this: Box<Expression>,
9186    #[serde(default)]
9187    pub value: Option<Box<Expression>>,
9188}
9189
9190/// GrantPrivilege
9191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9192#[cfg_attr(feature = "bindings", derive(TS))]
9193pub struct GrantPrivilege {
9194    pub this: Box<Expression>,
9195    #[serde(default)]
9196    pub expressions: Vec<Expression>,
9197}
9198
9199/// AllowedValuesProperty
9200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9201#[cfg_attr(feature = "bindings", derive(TS))]
9202pub struct AllowedValuesProperty {
9203    #[serde(default)]
9204    pub expressions: Vec<Expression>,
9205}
9206
9207/// AlgorithmProperty
9208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9209#[cfg_attr(feature = "bindings", derive(TS))]
9210pub struct AlgorithmProperty {
9211    pub this: Box<Expression>,
9212}
9213
9214/// AutoIncrementProperty
9215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9216#[cfg_attr(feature = "bindings", derive(TS))]
9217pub struct AutoIncrementProperty {
9218    pub this: Box<Expression>,
9219}
9220
9221/// AutoRefreshProperty
9222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9223#[cfg_attr(feature = "bindings", derive(TS))]
9224pub struct AutoRefreshProperty {
9225    pub this: Box<Expression>,
9226}
9227
9228/// BackupProperty
9229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9230#[cfg_attr(feature = "bindings", derive(TS))]
9231pub struct BackupProperty {
9232    pub this: Box<Expression>,
9233}
9234
9235/// BuildProperty
9236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9237#[cfg_attr(feature = "bindings", derive(TS))]
9238pub struct BuildProperty {
9239    pub this: Box<Expression>,
9240}
9241
9242/// BlockCompressionProperty
9243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9244#[cfg_attr(feature = "bindings", derive(TS))]
9245pub struct BlockCompressionProperty {
9246    #[serde(default)]
9247    pub autotemp: Option<Box<Expression>>,
9248    #[serde(default)]
9249    pub always: Option<Box<Expression>>,
9250    #[serde(default)]
9251    pub default: Option<Box<Expression>>,
9252    #[serde(default)]
9253    pub manual: Option<Box<Expression>>,
9254    #[serde(default)]
9255    pub never: Option<Box<Expression>>,
9256}
9257
9258/// CharacterSetProperty
9259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9260#[cfg_attr(feature = "bindings", derive(TS))]
9261pub struct CharacterSetProperty {
9262    pub this: Box<Expression>,
9263    #[serde(default)]
9264    pub default: Option<Box<Expression>>,
9265}
9266
9267/// ChecksumProperty
9268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9269#[cfg_attr(feature = "bindings", derive(TS))]
9270pub struct ChecksumProperty {
9271    #[serde(default)]
9272    pub on: Option<Box<Expression>>,
9273    #[serde(default)]
9274    pub default: Option<Box<Expression>>,
9275}
9276
9277/// CollateProperty
9278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9279#[cfg_attr(feature = "bindings", derive(TS))]
9280pub struct CollateProperty {
9281    pub this: Box<Expression>,
9282    #[serde(default)]
9283    pub default: Option<Box<Expression>>,
9284}
9285
9286/// DataBlocksizeProperty
9287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9288#[cfg_attr(feature = "bindings", derive(TS))]
9289pub struct DataBlocksizeProperty {
9290    #[serde(default)]
9291    pub size: Option<i64>,
9292    #[serde(default)]
9293    pub units: Option<Box<Expression>>,
9294    #[serde(default)]
9295    pub minimum: Option<Box<Expression>>,
9296    #[serde(default)]
9297    pub maximum: Option<Box<Expression>>,
9298    #[serde(default)]
9299    pub default: Option<Box<Expression>>,
9300}
9301
9302/// DataDeletionProperty
9303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9304#[cfg_attr(feature = "bindings", derive(TS))]
9305pub struct DataDeletionProperty {
9306    pub on: Box<Expression>,
9307    #[serde(default)]
9308    pub filter_column: Option<Box<Expression>>,
9309    #[serde(default)]
9310    pub retention_period: Option<Box<Expression>>,
9311}
9312
9313/// DefinerProperty
9314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9315#[cfg_attr(feature = "bindings", derive(TS))]
9316pub struct DefinerProperty {
9317    pub this: Box<Expression>,
9318}
9319
9320/// DistKeyProperty
9321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9322#[cfg_attr(feature = "bindings", derive(TS))]
9323pub struct DistKeyProperty {
9324    pub this: Box<Expression>,
9325}
9326
9327/// DistributedByProperty
9328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9329#[cfg_attr(feature = "bindings", derive(TS))]
9330pub struct DistributedByProperty {
9331    #[serde(default)]
9332    pub expressions: Vec<Expression>,
9333    pub kind: String,
9334    #[serde(default)]
9335    pub buckets: Option<Box<Expression>>,
9336    #[serde(default)]
9337    pub order: Option<Box<Expression>>,
9338}
9339
9340/// DistStyleProperty
9341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9342#[cfg_attr(feature = "bindings", derive(TS))]
9343pub struct DistStyleProperty {
9344    pub this: Box<Expression>,
9345}
9346
9347/// DuplicateKeyProperty
9348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9349#[cfg_attr(feature = "bindings", derive(TS))]
9350pub struct DuplicateKeyProperty {
9351    #[serde(default)]
9352    pub expressions: Vec<Expression>,
9353}
9354
9355/// EngineProperty
9356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9357#[cfg_attr(feature = "bindings", derive(TS))]
9358pub struct EngineProperty {
9359    pub this: Box<Expression>,
9360}
9361
9362/// ToTableProperty
9363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9364#[cfg_attr(feature = "bindings", derive(TS))]
9365pub struct ToTableProperty {
9366    pub this: Box<Expression>,
9367}
9368
9369/// ExecuteAsProperty
9370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9371#[cfg_attr(feature = "bindings", derive(TS))]
9372pub struct ExecuteAsProperty {
9373    pub this: Box<Expression>,
9374}
9375
9376/// ExternalProperty
9377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9378#[cfg_attr(feature = "bindings", derive(TS))]
9379pub struct ExternalProperty {
9380    #[serde(default)]
9381    pub this: Option<Box<Expression>>,
9382}
9383
9384/// FallbackProperty
9385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9386#[cfg_attr(feature = "bindings", derive(TS))]
9387pub struct FallbackProperty {
9388    #[serde(default)]
9389    pub no: Option<Box<Expression>>,
9390    #[serde(default)]
9391    pub protection: Option<Box<Expression>>,
9392}
9393
9394/// FileFormatProperty
9395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9396#[cfg_attr(feature = "bindings", derive(TS))]
9397pub struct FileFormatProperty {
9398    #[serde(default)]
9399    pub this: Option<Box<Expression>>,
9400    #[serde(default)]
9401    pub expressions: Vec<Expression>,
9402    #[serde(default)]
9403    pub hive_format: Option<Box<Expression>>,
9404}
9405
9406/// CredentialsProperty
9407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9408#[cfg_attr(feature = "bindings", derive(TS))]
9409pub struct CredentialsProperty {
9410    #[serde(default)]
9411    pub expressions: Vec<Expression>,
9412}
9413
9414/// FreespaceProperty
9415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9416#[cfg_attr(feature = "bindings", derive(TS))]
9417pub struct FreespaceProperty {
9418    pub this: Box<Expression>,
9419    #[serde(default)]
9420    pub percent: Option<Box<Expression>>,
9421}
9422
9423/// InheritsProperty
9424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9425#[cfg_attr(feature = "bindings", derive(TS))]
9426pub struct InheritsProperty {
9427    #[serde(default)]
9428    pub expressions: Vec<Expression>,
9429}
9430
9431/// InputModelProperty
9432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub struct InputModelProperty {
9435    pub this: Box<Expression>,
9436}
9437
9438/// OutputModelProperty
9439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9440#[cfg_attr(feature = "bindings", derive(TS))]
9441pub struct OutputModelProperty {
9442    pub this: Box<Expression>,
9443}
9444
9445/// IsolatedLoadingProperty
9446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9447#[cfg_attr(feature = "bindings", derive(TS))]
9448pub struct IsolatedLoadingProperty {
9449    #[serde(default)]
9450    pub no: Option<Box<Expression>>,
9451    #[serde(default)]
9452    pub concurrent: Option<Box<Expression>>,
9453    #[serde(default)]
9454    pub target: Option<Box<Expression>>,
9455}
9456
9457/// JournalProperty
9458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9459#[cfg_attr(feature = "bindings", derive(TS))]
9460pub struct JournalProperty {
9461    #[serde(default)]
9462    pub no: Option<Box<Expression>>,
9463    #[serde(default)]
9464    pub dual: Option<Box<Expression>>,
9465    #[serde(default)]
9466    pub before: Option<Box<Expression>>,
9467    #[serde(default)]
9468    pub local: Option<Box<Expression>>,
9469    #[serde(default)]
9470    pub after: Option<Box<Expression>>,
9471}
9472
9473/// LanguageProperty
9474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9475#[cfg_attr(feature = "bindings", derive(TS))]
9476pub struct LanguageProperty {
9477    pub this: Box<Expression>,
9478}
9479
9480/// EnviromentProperty
9481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9482#[cfg_attr(feature = "bindings", derive(TS))]
9483pub struct EnviromentProperty {
9484    #[serde(default)]
9485    pub expressions: Vec<Expression>,
9486}
9487
9488/// ClusteredByProperty
9489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9490#[cfg_attr(feature = "bindings", derive(TS))]
9491pub struct ClusteredByProperty {
9492    #[serde(default)]
9493    pub expressions: Vec<Expression>,
9494    #[serde(default)]
9495    pub sorted_by: Option<Box<Expression>>,
9496    #[serde(default)]
9497    pub buckets: Option<Box<Expression>>,
9498}
9499
9500/// DictProperty
9501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9502#[cfg_attr(feature = "bindings", derive(TS))]
9503pub struct DictProperty {
9504    pub this: Box<Expression>,
9505    pub kind: String,
9506    #[serde(default)]
9507    pub settings: Option<Box<Expression>>,
9508}
9509
9510/// DictRange
9511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9512#[cfg_attr(feature = "bindings", derive(TS))]
9513pub struct DictRange {
9514    pub this: Box<Expression>,
9515    #[serde(default)]
9516    pub min: Option<Box<Expression>>,
9517    #[serde(default)]
9518    pub max: Option<Box<Expression>>,
9519}
9520
9521/// OnCluster
9522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9523#[cfg_attr(feature = "bindings", derive(TS))]
9524pub struct OnCluster {
9525    pub this: Box<Expression>,
9526}
9527
9528/// LikeProperty
9529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9530#[cfg_attr(feature = "bindings", derive(TS))]
9531pub struct LikeProperty {
9532    pub this: Box<Expression>,
9533    #[serde(default)]
9534    pub expressions: Vec<Expression>,
9535}
9536
9537/// LocationProperty
9538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9539#[cfg_attr(feature = "bindings", derive(TS))]
9540pub struct LocationProperty {
9541    pub this: Box<Expression>,
9542}
9543
9544/// LockProperty
9545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub struct LockProperty {
9548    pub this: Box<Expression>,
9549}
9550
9551/// LockingProperty
9552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9553#[cfg_attr(feature = "bindings", derive(TS))]
9554pub struct LockingProperty {
9555    #[serde(default)]
9556    pub this: Option<Box<Expression>>,
9557    pub kind: String,
9558    #[serde(default)]
9559    pub for_or_in: Option<Box<Expression>>,
9560    #[serde(default)]
9561    pub lock_type: Option<Box<Expression>>,
9562    #[serde(default)]
9563    pub override_: Option<Box<Expression>>,
9564}
9565
9566/// LogProperty
9567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9568#[cfg_attr(feature = "bindings", derive(TS))]
9569pub struct LogProperty {
9570    #[serde(default)]
9571    pub no: Option<Box<Expression>>,
9572}
9573
9574/// MaterializedProperty
9575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9576#[cfg_attr(feature = "bindings", derive(TS))]
9577pub struct MaterializedProperty {
9578    #[serde(default)]
9579    pub this: Option<Box<Expression>>,
9580}
9581
9582/// MergeBlockRatioProperty
9583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9584#[cfg_attr(feature = "bindings", derive(TS))]
9585pub struct MergeBlockRatioProperty {
9586    #[serde(default)]
9587    pub this: Option<Box<Expression>>,
9588    #[serde(default)]
9589    pub no: Option<Box<Expression>>,
9590    #[serde(default)]
9591    pub default: Option<Box<Expression>>,
9592    #[serde(default)]
9593    pub percent: Option<Box<Expression>>,
9594}
9595
9596/// OnProperty
9597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9598#[cfg_attr(feature = "bindings", derive(TS))]
9599pub struct OnProperty {
9600    pub this: Box<Expression>,
9601}
9602
9603/// OnCommitProperty
9604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9605#[cfg_attr(feature = "bindings", derive(TS))]
9606pub struct OnCommitProperty {
9607    #[serde(default)]
9608    pub delete: Option<Box<Expression>>,
9609}
9610
9611/// PartitionedByProperty
9612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9613#[cfg_attr(feature = "bindings", derive(TS))]
9614pub struct PartitionedByProperty {
9615    pub this: Box<Expression>,
9616}
9617
9618/// BigQuery PARTITION BY property in CREATE TABLE statements.
9619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9620#[cfg_attr(feature = "bindings", derive(TS))]
9621pub struct PartitionByProperty {
9622    #[serde(default)]
9623    pub expressions: Vec<Expression>,
9624}
9625
9626/// PartitionedByBucket
9627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9628#[cfg_attr(feature = "bindings", derive(TS))]
9629pub struct PartitionedByBucket {
9630    pub this: Box<Expression>,
9631    pub expression: Box<Expression>,
9632}
9633
9634/// BigQuery CLUSTER BY property in CREATE TABLE statements.
9635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9636#[cfg_attr(feature = "bindings", derive(TS))]
9637pub struct ClusterByColumnsProperty {
9638    #[serde(default)]
9639    pub columns: Vec<Identifier>,
9640}
9641
9642/// PartitionByTruncate
9643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9644#[cfg_attr(feature = "bindings", derive(TS))]
9645pub struct PartitionByTruncate {
9646    pub this: Box<Expression>,
9647    pub expression: Box<Expression>,
9648}
9649
9650/// PartitionByRangeProperty
9651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9652#[cfg_attr(feature = "bindings", derive(TS))]
9653pub struct PartitionByRangeProperty {
9654    #[serde(default)]
9655    pub partition_expressions: Option<Box<Expression>>,
9656    #[serde(default)]
9657    pub create_expressions: Option<Box<Expression>>,
9658}
9659
9660/// PartitionByRangePropertyDynamic
9661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9662#[cfg_attr(feature = "bindings", derive(TS))]
9663pub struct PartitionByRangePropertyDynamic {
9664    #[serde(default)]
9665    pub this: Option<Box<Expression>>,
9666    #[serde(default)]
9667    pub start: Option<Box<Expression>>,
9668    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9669    #[serde(default)]
9670    pub use_start_end: bool,
9671    #[serde(default)]
9672    pub end: Option<Box<Expression>>,
9673    #[serde(default)]
9674    pub every: Option<Box<Expression>>,
9675}
9676
9677/// PartitionByListProperty
9678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9679#[cfg_attr(feature = "bindings", derive(TS))]
9680pub struct PartitionByListProperty {
9681    #[serde(default)]
9682    pub partition_expressions: Option<Box<Expression>>,
9683    #[serde(default)]
9684    pub create_expressions: Option<Box<Expression>>,
9685}
9686
9687/// PartitionList
9688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9689#[cfg_attr(feature = "bindings", derive(TS))]
9690pub struct PartitionList {
9691    pub this: Box<Expression>,
9692    #[serde(default)]
9693    pub expressions: Vec<Expression>,
9694}
9695
9696/// Partition - represents PARTITION/SUBPARTITION clause
9697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9698#[cfg_attr(feature = "bindings", derive(TS))]
9699pub struct Partition {
9700    pub expressions: Vec<Expression>,
9701    #[serde(default)]
9702    pub subpartition: bool,
9703}
9704
9705/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9706/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9708#[cfg_attr(feature = "bindings", derive(TS))]
9709pub struct RefreshTriggerProperty {
9710    /// Method: COMPLETE or AUTO
9711    pub method: String,
9712    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9713    #[serde(default)]
9714    pub kind: Option<String>,
9715    /// For SCHEDULE: EVERY n (the number)
9716    #[serde(default)]
9717    pub every: Option<Box<Expression>>,
9718    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9719    #[serde(default)]
9720    pub unit: Option<String>,
9721    /// For SCHEDULE: STARTS 'datetime'
9722    #[serde(default)]
9723    pub starts: Option<Box<Expression>>,
9724}
9725
9726/// UniqueKeyProperty
9727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9728#[cfg_attr(feature = "bindings", derive(TS))]
9729pub struct UniqueKeyProperty {
9730    #[serde(default)]
9731    pub expressions: Vec<Expression>,
9732}
9733
9734/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9736#[cfg_attr(feature = "bindings", derive(TS))]
9737pub struct RollupProperty {
9738    pub expressions: Vec<RollupIndex>,
9739}
9740
9741/// RollupIndex - A single rollup index: name(col1, col2)
9742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9743#[cfg_attr(feature = "bindings", derive(TS))]
9744pub struct RollupIndex {
9745    pub name: Identifier,
9746    pub expressions: Vec<Identifier>,
9747}
9748
9749/// PartitionBoundSpec
9750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9751#[cfg_attr(feature = "bindings", derive(TS))]
9752pub struct PartitionBoundSpec {
9753    #[serde(default)]
9754    pub this: Option<Box<Expression>>,
9755    #[serde(default)]
9756    pub expression: Option<Box<Expression>>,
9757    #[serde(default)]
9758    pub from_expressions: Option<Box<Expression>>,
9759    #[serde(default)]
9760    pub to_expressions: Option<Box<Expression>>,
9761}
9762
9763/// PartitionedOfProperty
9764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9765#[cfg_attr(feature = "bindings", derive(TS))]
9766pub struct PartitionedOfProperty {
9767    pub this: Box<Expression>,
9768    pub expression: Box<Expression>,
9769}
9770
9771/// RemoteWithConnectionModelProperty
9772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9773#[cfg_attr(feature = "bindings", derive(TS))]
9774pub struct RemoteWithConnectionModelProperty {
9775    pub this: Box<Expression>,
9776}
9777
9778/// ReturnsProperty
9779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9780#[cfg_attr(feature = "bindings", derive(TS))]
9781pub struct ReturnsProperty {
9782    #[serde(default)]
9783    pub this: Option<Box<Expression>>,
9784    #[serde(default)]
9785    pub is_table: Option<Box<Expression>>,
9786    #[serde(default)]
9787    pub table: Option<Box<Expression>>,
9788    #[serde(default)]
9789    pub null: Option<Box<Expression>>,
9790}
9791
9792/// RowFormatProperty
9793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9794#[cfg_attr(feature = "bindings", derive(TS))]
9795pub struct RowFormatProperty {
9796    pub this: Box<Expression>,
9797}
9798
9799/// RowFormatDelimitedProperty
9800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9801#[cfg_attr(feature = "bindings", derive(TS))]
9802pub struct RowFormatDelimitedProperty {
9803    #[serde(default)]
9804    pub fields: Option<Box<Expression>>,
9805    #[serde(default)]
9806    pub escaped: Option<Box<Expression>>,
9807    #[serde(default)]
9808    pub collection_items: Option<Box<Expression>>,
9809    #[serde(default)]
9810    pub map_keys: Option<Box<Expression>>,
9811    #[serde(default)]
9812    pub lines: Option<Box<Expression>>,
9813    #[serde(default)]
9814    pub null: Option<Box<Expression>>,
9815    #[serde(default)]
9816    pub serde: Option<Box<Expression>>,
9817}
9818
9819/// RowFormatSerdeProperty
9820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9821#[cfg_attr(feature = "bindings", derive(TS))]
9822pub struct RowFormatSerdeProperty {
9823    pub this: Box<Expression>,
9824    #[serde(default)]
9825    pub serde_properties: Option<Box<Expression>>,
9826}
9827
9828/// QueryTransform
9829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9830#[cfg_attr(feature = "bindings", derive(TS))]
9831pub struct QueryTransform {
9832    #[serde(default)]
9833    pub expressions: Vec<Expression>,
9834    #[serde(default)]
9835    pub command_script: Option<Box<Expression>>,
9836    #[serde(default)]
9837    pub schema: Option<Box<Expression>>,
9838    #[serde(default)]
9839    pub row_format_before: Option<Box<Expression>>,
9840    #[serde(default)]
9841    pub record_writer: Option<Box<Expression>>,
9842    #[serde(default)]
9843    pub row_format_after: Option<Box<Expression>>,
9844    #[serde(default)]
9845    pub record_reader: Option<Box<Expression>>,
9846}
9847
9848/// SampleProperty
9849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9850#[cfg_attr(feature = "bindings", derive(TS))]
9851pub struct SampleProperty {
9852    pub this: Box<Expression>,
9853}
9854
9855/// SecurityProperty
9856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9857#[cfg_attr(feature = "bindings", derive(TS))]
9858pub struct SecurityProperty {
9859    pub this: Box<Expression>,
9860}
9861
9862/// SchemaCommentProperty
9863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9864#[cfg_attr(feature = "bindings", derive(TS))]
9865pub struct SchemaCommentProperty {
9866    pub this: Box<Expression>,
9867}
9868
9869/// SemanticView
9870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9871#[cfg_attr(feature = "bindings", derive(TS))]
9872pub struct SemanticView {
9873    pub this: Box<Expression>,
9874    #[serde(default)]
9875    pub metrics: Option<Box<Expression>>,
9876    #[serde(default)]
9877    pub dimensions: Option<Box<Expression>>,
9878    #[serde(default)]
9879    pub facts: Option<Box<Expression>>,
9880    #[serde(default)]
9881    pub where_: Option<Box<Expression>>,
9882}
9883
9884/// SerdeProperties
9885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9886#[cfg_attr(feature = "bindings", derive(TS))]
9887pub struct SerdeProperties {
9888    #[serde(default)]
9889    pub expressions: Vec<Expression>,
9890    #[serde(default)]
9891    pub with_: Option<Box<Expression>>,
9892}
9893
9894/// SetProperty
9895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9896#[cfg_attr(feature = "bindings", derive(TS))]
9897pub struct SetProperty {
9898    #[serde(default)]
9899    pub multi: Option<Box<Expression>>,
9900}
9901
9902/// SharingProperty
9903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9904#[cfg_attr(feature = "bindings", derive(TS))]
9905pub struct SharingProperty {
9906    #[serde(default)]
9907    pub this: Option<Box<Expression>>,
9908}
9909
9910/// SetConfigProperty
9911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9912#[cfg_attr(feature = "bindings", derive(TS))]
9913pub struct SetConfigProperty {
9914    pub this: Box<Expression>,
9915}
9916
9917/// SettingsProperty
9918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9919#[cfg_attr(feature = "bindings", derive(TS))]
9920pub struct SettingsProperty {
9921    #[serde(default)]
9922    pub expressions: Vec<Expression>,
9923}
9924
9925/// SortKeyProperty
9926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9927#[cfg_attr(feature = "bindings", derive(TS))]
9928pub struct SortKeyProperty {
9929    pub this: Box<Expression>,
9930    #[serde(default)]
9931    pub compound: Option<Box<Expression>>,
9932}
9933
9934/// SqlReadWriteProperty
9935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9936#[cfg_attr(feature = "bindings", derive(TS))]
9937pub struct SqlReadWriteProperty {
9938    pub this: Box<Expression>,
9939}
9940
9941/// SqlSecurityProperty
9942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9943#[cfg_attr(feature = "bindings", derive(TS))]
9944pub struct SqlSecurityProperty {
9945    pub this: Box<Expression>,
9946}
9947
9948/// StabilityProperty
9949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9950#[cfg_attr(feature = "bindings", derive(TS))]
9951pub struct StabilityProperty {
9952    pub this: Box<Expression>,
9953}
9954
9955/// StorageHandlerProperty
9956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9957#[cfg_attr(feature = "bindings", derive(TS))]
9958pub struct StorageHandlerProperty {
9959    pub this: Box<Expression>,
9960}
9961
9962/// TemporaryProperty
9963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9964#[cfg_attr(feature = "bindings", derive(TS))]
9965pub struct TemporaryProperty {
9966    #[serde(default)]
9967    pub this: Option<Box<Expression>>,
9968}
9969
9970/// Tags
9971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9972#[cfg_attr(feature = "bindings", derive(TS))]
9973pub struct Tags {
9974    #[serde(default)]
9975    pub expressions: Vec<Expression>,
9976}
9977
9978/// TransformModelProperty
9979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9980#[cfg_attr(feature = "bindings", derive(TS))]
9981pub struct TransformModelProperty {
9982    #[serde(default)]
9983    pub expressions: Vec<Expression>,
9984}
9985
9986/// TransientProperty
9987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9988#[cfg_attr(feature = "bindings", derive(TS))]
9989pub struct TransientProperty {
9990    #[serde(default)]
9991    pub this: Option<Box<Expression>>,
9992}
9993
9994/// UsingTemplateProperty
9995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9996#[cfg_attr(feature = "bindings", derive(TS))]
9997pub struct UsingTemplateProperty {
9998    pub this: Box<Expression>,
9999}
10000
10001/// ViewAttributeProperty
10002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10003#[cfg_attr(feature = "bindings", derive(TS))]
10004pub struct ViewAttributeProperty {
10005    pub this: Box<Expression>,
10006}
10007
10008/// VolatileProperty
10009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10010#[cfg_attr(feature = "bindings", derive(TS))]
10011pub struct VolatileProperty {
10012    #[serde(default)]
10013    pub this: Option<Box<Expression>>,
10014}
10015
10016/// WithDataProperty
10017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10018#[cfg_attr(feature = "bindings", derive(TS))]
10019pub struct WithDataProperty {
10020    #[serde(default)]
10021    pub no: Option<Box<Expression>>,
10022    #[serde(default)]
10023    pub statistics: Option<Box<Expression>>,
10024}
10025
10026/// WithJournalTableProperty
10027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10028#[cfg_attr(feature = "bindings", derive(TS))]
10029pub struct WithJournalTableProperty {
10030    pub this: Box<Expression>,
10031}
10032
10033/// WithSchemaBindingProperty
10034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10035#[cfg_attr(feature = "bindings", derive(TS))]
10036pub struct WithSchemaBindingProperty {
10037    pub this: Box<Expression>,
10038}
10039
10040/// WithSystemVersioningProperty
10041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10042#[cfg_attr(feature = "bindings", derive(TS))]
10043pub struct WithSystemVersioningProperty {
10044    #[serde(default)]
10045    pub on: Option<Box<Expression>>,
10046    #[serde(default)]
10047    pub this: Option<Box<Expression>>,
10048    #[serde(default)]
10049    pub data_consistency: Option<Box<Expression>>,
10050    #[serde(default)]
10051    pub retention_period: Option<Box<Expression>>,
10052    #[serde(default)]
10053    pub with_: Option<Box<Expression>>,
10054}
10055
10056/// WithProcedureOptions
10057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10058#[cfg_attr(feature = "bindings", derive(TS))]
10059pub struct WithProcedureOptions {
10060    #[serde(default)]
10061    pub expressions: Vec<Expression>,
10062}
10063
10064/// EncodeProperty
10065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10066#[cfg_attr(feature = "bindings", derive(TS))]
10067pub struct EncodeProperty {
10068    pub this: Box<Expression>,
10069    #[serde(default)]
10070    pub properties: Vec<Expression>,
10071    #[serde(default)]
10072    pub key: Option<Box<Expression>>,
10073}
10074
10075/// IncludeProperty
10076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10077#[cfg_attr(feature = "bindings", derive(TS))]
10078pub struct IncludeProperty {
10079    pub this: Box<Expression>,
10080    #[serde(default)]
10081    pub alias: Option<String>,
10082    #[serde(default)]
10083    pub column_def: Option<Box<Expression>>,
10084}
10085
10086/// Properties
10087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10088#[cfg_attr(feature = "bindings", derive(TS))]
10089pub struct Properties {
10090    #[serde(default)]
10091    pub expressions: Vec<Expression>,
10092}
10093
10094/// Key/value pair in a BigQuery OPTIONS (...) clause.
10095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10096#[cfg_attr(feature = "bindings", derive(TS))]
10097pub struct OptionEntry {
10098    pub key: Identifier,
10099    pub value: Expression,
10100}
10101
10102/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
10103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10104#[cfg_attr(feature = "bindings", derive(TS))]
10105pub struct OptionsProperty {
10106    #[serde(default)]
10107    pub entries: Vec<OptionEntry>,
10108}
10109
10110/// InputOutputFormat
10111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10112#[cfg_attr(feature = "bindings", derive(TS))]
10113pub struct InputOutputFormat {
10114    #[serde(default)]
10115    pub input_format: Option<Box<Expression>>,
10116    #[serde(default)]
10117    pub output_format: Option<Box<Expression>>,
10118}
10119
10120/// Reference
10121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10122#[cfg_attr(feature = "bindings", derive(TS))]
10123pub struct Reference {
10124    pub this: Box<Expression>,
10125    #[serde(default)]
10126    pub expressions: Vec<Expression>,
10127    #[serde(default)]
10128    pub options: Vec<Expression>,
10129}
10130
10131/// QueryOption
10132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10133#[cfg_attr(feature = "bindings", derive(TS))]
10134pub struct QueryOption {
10135    pub this: Box<Expression>,
10136    #[serde(default)]
10137    pub expression: Option<Box<Expression>>,
10138}
10139
10140/// WithTableHint
10141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10142#[cfg_attr(feature = "bindings", derive(TS))]
10143pub struct WithTableHint {
10144    #[serde(default)]
10145    pub expressions: Vec<Expression>,
10146}
10147
10148/// IndexTableHint
10149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10150#[cfg_attr(feature = "bindings", derive(TS))]
10151pub struct IndexTableHint {
10152    pub this: Box<Expression>,
10153    #[serde(default)]
10154    pub expressions: Vec<Expression>,
10155    #[serde(default)]
10156    pub target: Option<Box<Expression>>,
10157}
10158
10159/// Get
10160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10161#[cfg_attr(feature = "bindings", derive(TS))]
10162pub struct Get {
10163    pub this: Box<Expression>,
10164    #[serde(default)]
10165    pub target: Option<Box<Expression>>,
10166    #[serde(default)]
10167    pub properties: Vec<Expression>,
10168}
10169
10170/// SetOperation
10171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10172#[cfg_attr(feature = "bindings", derive(TS))]
10173pub struct SetOperation {
10174    #[serde(default)]
10175    pub with_: Option<Box<Expression>>,
10176    pub this: Box<Expression>,
10177    pub expression: Box<Expression>,
10178    #[serde(default)]
10179    pub distinct: bool,
10180    #[serde(default)]
10181    pub by_name: Option<Box<Expression>>,
10182    #[serde(default)]
10183    pub side: Option<Box<Expression>>,
10184    #[serde(default)]
10185    pub kind: Option<String>,
10186    #[serde(default)]
10187    pub on: Option<Box<Expression>>,
10188}
10189
10190/// Var - Simple variable reference (for SQL variables, keywords as values)
10191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10192#[cfg_attr(feature = "bindings", derive(TS))]
10193pub struct Var {
10194    pub this: String,
10195}
10196
10197/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
10198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10199#[cfg_attr(feature = "bindings", derive(TS))]
10200pub struct Variadic {
10201    pub this: Box<Expression>,
10202}
10203
10204/// Version
10205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10206#[cfg_attr(feature = "bindings", derive(TS))]
10207pub struct Version {
10208    pub this: Box<Expression>,
10209    pub kind: String,
10210    #[serde(default)]
10211    pub expression: Option<Box<Expression>>,
10212}
10213
10214/// Schema
10215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10216#[cfg_attr(feature = "bindings", derive(TS))]
10217pub struct Schema {
10218    #[serde(default)]
10219    pub this: Option<Box<Expression>>,
10220    #[serde(default)]
10221    pub expressions: Vec<Expression>,
10222}
10223
10224/// Lock
10225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10226#[cfg_attr(feature = "bindings", derive(TS))]
10227pub struct Lock {
10228    #[serde(default)]
10229    pub update: Option<Box<Expression>>,
10230    #[serde(default)]
10231    pub expressions: Vec<Expression>,
10232    #[serde(default)]
10233    pub wait: Option<Box<Expression>>,
10234    #[serde(default)]
10235    pub key: Option<Box<Expression>>,
10236}
10237
10238/// TableSample - wraps an expression with a TABLESAMPLE clause
10239/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
10240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10241#[cfg_attr(feature = "bindings", derive(TS))]
10242pub struct TableSample {
10243    /// The expression being sampled (subquery, function, etc.)
10244    #[serde(default, skip_serializing_if = "Option::is_none")]
10245    pub this: Option<Box<Expression>>,
10246    /// The sample specification
10247    #[serde(default, skip_serializing_if = "Option::is_none")]
10248    pub sample: Option<Box<Sample>>,
10249    #[serde(default)]
10250    pub expressions: Vec<Expression>,
10251    #[serde(default)]
10252    pub method: Option<String>,
10253    #[serde(default)]
10254    pub bucket_numerator: Option<Box<Expression>>,
10255    #[serde(default)]
10256    pub bucket_denominator: Option<Box<Expression>>,
10257    #[serde(default)]
10258    pub bucket_field: Option<Box<Expression>>,
10259    #[serde(default)]
10260    pub percent: Option<Box<Expression>>,
10261    #[serde(default)]
10262    pub rows: Option<Box<Expression>>,
10263    #[serde(default)]
10264    pub size: Option<i64>,
10265    #[serde(default)]
10266    pub seed: Option<Box<Expression>>,
10267}
10268
10269/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
10270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10271#[cfg_attr(feature = "bindings", derive(TS))]
10272pub struct Tag {
10273    #[serde(default)]
10274    pub this: Option<Box<Expression>>,
10275    #[serde(default)]
10276    pub prefix: Option<Box<Expression>>,
10277    #[serde(default)]
10278    pub postfix: Option<Box<Expression>>,
10279}
10280
10281/// UnpivotColumns
10282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10283#[cfg_attr(feature = "bindings", derive(TS))]
10284pub struct UnpivotColumns {
10285    pub this: Box<Expression>,
10286    #[serde(default)]
10287    pub expressions: Vec<Expression>,
10288}
10289
10290/// SessionParameter
10291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10292#[cfg_attr(feature = "bindings", derive(TS))]
10293pub struct SessionParameter {
10294    pub this: Box<Expression>,
10295    #[serde(default)]
10296    pub kind: Option<String>,
10297}
10298
10299/// PseudoType
10300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10301#[cfg_attr(feature = "bindings", derive(TS))]
10302pub struct PseudoType {
10303    pub this: Box<Expression>,
10304}
10305
10306/// ObjectIdentifier
10307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10308#[cfg_attr(feature = "bindings", derive(TS))]
10309pub struct ObjectIdentifier {
10310    pub this: Box<Expression>,
10311}
10312
10313/// Transaction
10314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10315#[cfg_attr(feature = "bindings", derive(TS))]
10316pub struct Transaction {
10317    #[serde(default)]
10318    pub this: Option<Box<Expression>>,
10319    #[serde(default)]
10320    pub modes: Option<Box<Expression>>,
10321    #[serde(default)]
10322    pub mark: Option<Box<Expression>>,
10323}
10324
10325/// Commit
10326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10327#[cfg_attr(feature = "bindings", derive(TS))]
10328pub struct Commit {
10329    #[serde(default)]
10330    pub chain: Option<Box<Expression>>,
10331    #[serde(default)]
10332    pub this: Option<Box<Expression>>,
10333    #[serde(default)]
10334    pub durability: Option<Box<Expression>>,
10335}
10336
10337/// Rollback
10338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10339#[cfg_attr(feature = "bindings", derive(TS))]
10340pub struct Rollback {
10341    #[serde(default)]
10342    pub savepoint: Option<Box<Expression>>,
10343    #[serde(default)]
10344    pub this: Option<Box<Expression>>,
10345}
10346
10347/// AlterSession
10348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10349#[cfg_attr(feature = "bindings", derive(TS))]
10350pub struct AlterSession {
10351    #[serde(default)]
10352    pub expressions: Vec<Expression>,
10353    #[serde(default)]
10354    pub unset: Option<Box<Expression>>,
10355}
10356
10357/// Analyze
10358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10359#[cfg_attr(feature = "bindings", derive(TS))]
10360pub struct Analyze {
10361    #[serde(default)]
10362    pub kind: Option<String>,
10363    #[serde(default)]
10364    pub this: Option<Box<Expression>>,
10365    #[serde(default)]
10366    pub options: Vec<Expression>,
10367    #[serde(default)]
10368    pub mode: Option<Box<Expression>>,
10369    #[serde(default)]
10370    pub partition: Option<Box<Expression>>,
10371    #[serde(default)]
10372    pub expression: Option<Box<Expression>>,
10373    #[serde(default)]
10374    pub properties: Vec<Expression>,
10375    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
10376    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10377    pub columns: Vec<String>,
10378}
10379
10380/// AnalyzeStatistics
10381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10382#[cfg_attr(feature = "bindings", derive(TS))]
10383pub struct AnalyzeStatistics {
10384    pub kind: String,
10385    #[serde(default)]
10386    pub option: Option<Box<Expression>>,
10387    #[serde(default)]
10388    pub this: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub expressions: Vec<Expression>,
10391}
10392
10393/// AnalyzeHistogram
10394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10395#[cfg_attr(feature = "bindings", derive(TS))]
10396pub struct AnalyzeHistogram {
10397    pub this: Box<Expression>,
10398    #[serde(default)]
10399    pub expressions: Vec<Expression>,
10400    #[serde(default)]
10401    pub expression: Option<Box<Expression>>,
10402    #[serde(default)]
10403    pub update_options: Option<Box<Expression>>,
10404}
10405
10406/// AnalyzeSample
10407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10408#[cfg_attr(feature = "bindings", derive(TS))]
10409pub struct AnalyzeSample {
10410    pub kind: String,
10411    #[serde(default)]
10412    pub sample: Option<Box<Expression>>,
10413}
10414
10415/// AnalyzeListChainedRows
10416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10417#[cfg_attr(feature = "bindings", derive(TS))]
10418pub struct AnalyzeListChainedRows {
10419    #[serde(default)]
10420    pub expression: Option<Box<Expression>>,
10421}
10422
10423/// AnalyzeDelete
10424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10425#[cfg_attr(feature = "bindings", derive(TS))]
10426pub struct AnalyzeDelete {
10427    #[serde(default)]
10428    pub kind: Option<String>,
10429}
10430
10431/// AnalyzeWith
10432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10433#[cfg_attr(feature = "bindings", derive(TS))]
10434pub struct AnalyzeWith {
10435    #[serde(default)]
10436    pub expressions: Vec<Expression>,
10437}
10438
10439/// AnalyzeValidate
10440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10441#[cfg_attr(feature = "bindings", derive(TS))]
10442pub struct AnalyzeValidate {
10443    pub kind: String,
10444    #[serde(default)]
10445    pub this: Option<Box<Expression>>,
10446    #[serde(default)]
10447    pub expression: Option<Box<Expression>>,
10448}
10449
10450/// AddPartition
10451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10452#[cfg_attr(feature = "bindings", derive(TS))]
10453pub struct AddPartition {
10454    pub this: Box<Expression>,
10455    #[serde(default)]
10456    pub exists: bool,
10457    #[serde(default)]
10458    pub location: Option<Box<Expression>>,
10459}
10460
10461/// AttachOption
10462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10463#[cfg_attr(feature = "bindings", derive(TS))]
10464pub struct AttachOption {
10465    pub this: Box<Expression>,
10466    #[serde(default)]
10467    pub expression: Option<Box<Expression>>,
10468}
10469
10470/// DropPartition
10471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10472#[cfg_attr(feature = "bindings", derive(TS))]
10473pub struct DropPartition {
10474    #[serde(default)]
10475    pub expressions: Vec<Expression>,
10476    #[serde(default)]
10477    pub exists: bool,
10478}
10479
10480/// ReplacePartition
10481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10482#[cfg_attr(feature = "bindings", derive(TS))]
10483pub struct ReplacePartition {
10484    pub expression: Box<Expression>,
10485    #[serde(default)]
10486    pub source: Option<Box<Expression>>,
10487}
10488
10489/// DPipe
10490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10491#[cfg_attr(feature = "bindings", derive(TS))]
10492pub struct DPipe {
10493    pub this: Box<Expression>,
10494    pub expression: Box<Expression>,
10495    #[serde(default)]
10496    pub safe: Option<Box<Expression>>,
10497}
10498
10499/// Operator
10500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10501#[cfg_attr(feature = "bindings", derive(TS))]
10502pub struct Operator {
10503    pub this: Box<Expression>,
10504    #[serde(default)]
10505    pub operator: Option<Box<Expression>>,
10506    pub expression: Box<Expression>,
10507    /// Comments between OPERATOR() and the RHS expression
10508    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10509    pub comments: Vec<String>,
10510}
10511
10512/// PivotAny
10513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10514#[cfg_attr(feature = "bindings", derive(TS))]
10515pub struct PivotAny {
10516    #[serde(default)]
10517    pub this: Option<Box<Expression>>,
10518}
10519
10520/// Aliases
10521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10522#[cfg_attr(feature = "bindings", derive(TS))]
10523pub struct Aliases {
10524    pub this: Box<Expression>,
10525    #[serde(default)]
10526    pub expressions: Vec<Expression>,
10527}
10528
10529/// AtIndex
10530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10531#[cfg_attr(feature = "bindings", derive(TS))]
10532pub struct AtIndex {
10533    pub this: Box<Expression>,
10534    pub expression: Box<Expression>,
10535}
10536
10537/// FromTimeZone
10538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10539#[cfg_attr(feature = "bindings", derive(TS))]
10540pub struct FromTimeZone {
10541    pub this: Box<Expression>,
10542    #[serde(default)]
10543    pub zone: Option<Box<Expression>>,
10544}
10545
10546/// Format override for a column in Teradata
10547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10548#[cfg_attr(feature = "bindings", derive(TS))]
10549pub struct FormatPhrase {
10550    pub this: Box<Expression>,
10551    pub format: String,
10552}
10553
10554/// ForIn
10555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10556#[cfg_attr(feature = "bindings", derive(TS))]
10557pub struct ForIn {
10558    pub this: Box<Expression>,
10559    pub expression: Box<Expression>,
10560}
10561
10562/// Automatically converts unit arg into a var.
10563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10564#[cfg_attr(feature = "bindings", derive(TS))]
10565pub struct TimeUnit {
10566    #[serde(default)]
10567    pub unit: Option<String>,
10568}
10569
10570/// IntervalOp
10571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10572#[cfg_attr(feature = "bindings", derive(TS))]
10573pub struct IntervalOp {
10574    #[serde(default)]
10575    pub unit: Option<String>,
10576    pub expression: Box<Expression>,
10577}
10578
10579/// HavingMax
10580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10581#[cfg_attr(feature = "bindings", derive(TS))]
10582pub struct HavingMax {
10583    pub this: Box<Expression>,
10584    pub expression: Box<Expression>,
10585    #[serde(default)]
10586    pub max: Option<Box<Expression>>,
10587}
10588
10589/// CosineDistance
10590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10591#[cfg_attr(feature = "bindings", derive(TS))]
10592pub struct CosineDistance {
10593    pub this: Box<Expression>,
10594    pub expression: Box<Expression>,
10595}
10596
10597/// DotProduct
10598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10599#[cfg_attr(feature = "bindings", derive(TS))]
10600pub struct DotProduct {
10601    pub this: Box<Expression>,
10602    pub expression: Box<Expression>,
10603}
10604
10605/// EuclideanDistance
10606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10607#[cfg_attr(feature = "bindings", derive(TS))]
10608pub struct EuclideanDistance {
10609    pub this: Box<Expression>,
10610    pub expression: Box<Expression>,
10611}
10612
10613/// ManhattanDistance
10614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10615#[cfg_attr(feature = "bindings", derive(TS))]
10616pub struct ManhattanDistance {
10617    pub this: Box<Expression>,
10618    pub expression: Box<Expression>,
10619}
10620
10621/// JarowinklerSimilarity
10622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10623#[cfg_attr(feature = "bindings", derive(TS))]
10624pub struct JarowinklerSimilarity {
10625    pub this: Box<Expression>,
10626    pub expression: Box<Expression>,
10627}
10628
10629/// Booland
10630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10631#[cfg_attr(feature = "bindings", derive(TS))]
10632pub struct Booland {
10633    pub this: Box<Expression>,
10634    pub expression: Box<Expression>,
10635}
10636
10637/// Boolor
10638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10639#[cfg_attr(feature = "bindings", derive(TS))]
10640pub struct Boolor {
10641    pub this: Box<Expression>,
10642    pub expression: Box<Expression>,
10643}
10644
10645/// ParameterizedAgg
10646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10647#[cfg_attr(feature = "bindings", derive(TS))]
10648pub struct ParameterizedAgg {
10649    pub this: Box<Expression>,
10650    #[serde(default)]
10651    pub expressions: Vec<Expression>,
10652    #[serde(default)]
10653    pub params: Vec<Expression>,
10654}
10655
10656/// ArgMax
10657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10658#[cfg_attr(feature = "bindings", derive(TS))]
10659pub struct ArgMax {
10660    pub this: Box<Expression>,
10661    pub expression: Box<Expression>,
10662    #[serde(default)]
10663    pub count: Option<Box<Expression>>,
10664}
10665
10666/// ArgMin
10667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10668#[cfg_attr(feature = "bindings", derive(TS))]
10669pub struct ArgMin {
10670    pub this: Box<Expression>,
10671    pub expression: Box<Expression>,
10672    #[serde(default)]
10673    pub count: Option<Box<Expression>>,
10674}
10675
10676/// ApproxTopK
10677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10678#[cfg_attr(feature = "bindings", derive(TS))]
10679pub struct ApproxTopK {
10680    pub this: Box<Expression>,
10681    #[serde(default)]
10682    pub expression: Option<Box<Expression>>,
10683    #[serde(default)]
10684    pub counters: Option<Box<Expression>>,
10685}
10686
10687/// ApproxTopKAccumulate
10688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10689#[cfg_attr(feature = "bindings", derive(TS))]
10690pub struct ApproxTopKAccumulate {
10691    pub this: Box<Expression>,
10692    #[serde(default)]
10693    pub expression: Option<Box<Expression>>,
10694}
10695
10696/// ApproxTopKCombine
10697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10698#[cfg_attr(feature = "bindings", derive(TS))]
10699pub struct ApproxTopKCombine {
10700    pub this: Box<Expression>,
10701    #[serde(default)]
10702    pub expression: Option<Box<Expression>>,
10703}
10704
10705/// ApproxTopKEstimate
10706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10707#[cfg_attr(feature = "bindings", derive(TS))]
10708pub struct ApproxTopKEstimate {
10709    pub this: Box<Expression>,
10710    #[serde(default)]
10711    pub expression: Option<Box<Expression>>,
10712}
10713
10714/// ApproxTopSum
10715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10716#[cfg_attr(feature = "bindings", derive(TS))]
10717pub struct ApproxTopSum {
10718    pub this: Box<Expression>,
10719    pub expression: Box<Expression>,
10720    #[serde(default)]
10721    pub count: Option<Box<Expression>>,
10722}
10723
10724/// ApproxQuantiles
10725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10726#[cfg_attr(feature = "bindings", derive(TS))]
10727pub struct ApproxQuantiles {
10728    pub this: Box<Expression>,
10729    #[serde(default)]
10730    pub expression: Option<Box<Expression>>,
10731}
10732
10733/// Minhash
10734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10735#[cfg_attr(feature = "bindings", derive(TS))]
10736pub struct Minhash {
10737    pub this: Box<Expression>,
10738    #[serde(default)]
10739    pub expressions: Vec<Expression>,
10740}
10741
10742/// FarmFingerprint
10743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10744#[cfg_attr(feature = "bindings", derive(TS))]
10745pub struct FarmFingerprint {
10746    #[serde(default)]
10747    pub expressions: Vec<Expression>,
10748}
10749
10750/// Float64
10751#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10752#[cfg_attr(feature = "bindings", derive(TS))]
10753pub struct Float64 {
10754    pub this: Box<Expression>,
10755    #[serde(default)]
10756    pub expression: Option<Box<Expression>>,
10757}
10758
10759/// Transform
10760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10761#[cfg_attr(feature = "bindings", derive(TS))]
10762pub struct Transform {
10763    pub this: Box<Expression>,
10764    pub expression: Box<Expression>,
10765}
10766
10767/// Translate
10768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10769#[cfg_attr(feature = "bindings", derive(TS))]
10770pub struct Translate {
10771    pub this: Box<Expression>,
10772    #[serde(default)]
10773    pub from_: Option<Box<Expression>>,
10774    #[serde(default)]
10775    pub to: Option<Box<Expression>>,
10776}
10777
10778/// Grouping
10779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10780#[cfg_attr(feature = "bindings", derive(TS))]
10781pub struct Grouping {
10782    #[serde(default)]
10783    pub expressions: Vec<Expression>,
10784}
10785
10786/// GroupingId
10787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10788#[cfg_attr(feature = "bindings", derive(TS))]
10789pub struct GroupingId {
10790    #[serde(default)]
10791    pub expressions: Vec<Expression>,
10792}
10793
10794/// Anonymous
10795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10796#[cfg_attr(feature = "bindings", derive(TS))]
10797pub struct Anonymous {
10798    pub this: Box<Expression>,
10799    #[serde(default)]
10800    pub expressions: Vec<Expression>,
10801}
10802
10803/// AnonymousAggFunc
10804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10805#[cfg_attr(feature = "bindings", derive(TS))]
10806pub struct AnonymousAggFunc {
10807    pub this: Box<Expression>,
10808    #[serde(default)]
10809    pub expressions: Vec<Expression>,
10810}
10811
10812/// CombinedAggFunc
10813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10814#[cfg_attr(feature = "bindings", derive(TS))]
10815pub struct CombinedAggFunc {
10816    pub this: Box<Expression>,
10817    #[serde(default)]
10818    pub expressions: Vec<Expression>,
10819}
10820
10821/// CombinedParameterizedAgg
10822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10823#[cfg_attr(feature = "bindings", derive(TS))]
10824pub struct CombinedParameterizedAgg {
10825    pub this: Box<Expression>,
10826    #[serde(default)]
10827    pub expressions: Vec<Expression>,
10828    #[serde(default)]
10829    pub params: Vec<Expression>,
10830}
10831
10832/// HashAgg
10833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10834#[cfg_attr(feature = "bindings", derive(TS))]
10835pub struct HashAgg {
10836    pub this: Box<Expression>,
10837    #[serde(default)]
10838    pub expressions: Vec<Expression>,
10839}
10840
10841/// Hll
10842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10843#[cfg_attr(feature = "bindings", derive(TS))]
10844pub struct Hll {
10845    pub this: Box<Expression>,
10846    #[serde(default)]
10847    pub expressions: Vec<Expression>,
10848}
10849
10850/// Apply
10851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10852#[cfg_attr(feature = "bindings", derive(TS))]
10853pub struct Apply {
10854    pub this: Box<Expression>,
10855    pub expression: Box<Expression>,
10856}
10857
10858/// ToBoolean
10859#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10860#[cfg_attr(feature = "bindings", derive(TS))]
10861pub struct ToBoolean {
10862    pub this: Box<Expression>,
10863    #[serde(default)]
10864    pub safe: Option<Box<Expression>>,
10865}
10866
10867/// List
10868#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10869#[cfg_attr(feature = "bindings", derive(TS))]
10870pub struct List {
10871    #[serde(default)]
10872    pub expressions: Vec<Expression>,
10873}
10874
10875/// ToMap - Materialize-style map constructor
10876/// Can hold either:
10877/// - A SELECT subquery (MAP(SELECT 'a', 1))
10878/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10880#[cfg_attr(feature = "bindings", derive(TS))]
10881pub struct ToMap {
10882    /// Either a Select subquery or a Struct containing PropertyEQ entries
10883    pub this: Box<Expression>,
10884}
10885
10886/// Pad
10887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10888#[cfg_attr(feature = "bindings", derive(TS))]
10889pub struct Pad {
10890    pub this: Box<Expression>,
10891    pub expression: Box<Expression>,
10892    #[serde(default)]
10893    pub fill_pattern: Option<Box<Expression>>,
10894    #[serde(default)]
10895    pub is_left: Option<Box<Expression>>,
10896}
10897
10898/// ToChar
10899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10900#[cfg_attr(feature = "bindings", derive(TS))]
10901pub struct ToChar {
10902    pub this: Box<Expression>,
10903    #[serde(default)]
10904    pub format: Option<String>,
10905    #[serde(default)]
10906    pub nlsparam: Option<Box<Expression>>,
10907    #[serde(default)]
10908    pub is_numeric: Option<Box<Expression>>,
10909}
10910
10911/// StringFunc - String type conversion function (BigQuery STRING)
10912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10913#[cfg_attr(feature = "bindings", derive(TS))]
10914pub struct StringFunc {
10915    pub this: Box<Expression>,
10916    #[serde(default)]
10917    pub zone: Option<Box<Expression>>,
10918}
10919
10920/// ToNumber
10921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10922#[cfg_attr(feature = "bindings", derive(TS))]
10923pub struct ToNumber {
10924    pub this: Box<Expression>,
10925    #[serde(default)]
10926    pub format: Option<Box<Expression>>,
10927    #[serde(default)]
10928    pub nlsparam: Option<Box<Expression>>,
10929    #[serde(default)]
10930    pub precision: Option<Box<Expression>>,
10931    #[serde(default)]
10932    pub scale: Option<Box<Expression>>,
10933    #[serde(default)]
10934    pub safe: Option<Box<Expression>>,
10935    #[serde(default)]
10936    pub safe_name: Option<Box<Expression>>,
10937}
10938
10939/// ToDouble
10940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10941#[cfg_attr(feature = "bindings", derive(TS))]
10942pub struct ToDouble {
10943    pub this: Box<Expression>,
10944    #[serde(default)]
10945    pub format: Option<String>,
10946    #[serde(default)]
10947    pub safe: Option<Box<Expression>>,
10948}
10949
10950/// ToDecfloat
10951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10952#[cfg_attr(feature = "bindings", derive(TS))]
10953pub struct ToDecfloat {
10954    pub this: Box<Expression>,
10955    #[serde(default)]
10956    pub format: Option<String>,
10957}
10958
10959/// TryToDecfloat
10960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10961#[cfg_attr(feature = "bindings", derive(TS))]
10962pub struct TryToDecfloat {
10963    pub this: Box<Expression>,
10964    #[serde(default)]
10965    pub format: Option<String>,
10966}
10967
10968/// ToFile
10969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10970#[cfg_attr(feature = "bindings", derive(TS))]
10971pub struct ToFile {
10972    pub this: Box<Expression>,
10973    #[serde(default)]
10974    pub path: Option<Box<Expression>>,
10975    #[serde(default)]
10976    pub safe: Option<Box<Expression>>,
10977}
10978
10979/// Columns
10980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10981#[cfg_attr(feature = "bindings", derive(TS))]
10982pub struct Columns {
10983    pub this: Box<Expression>,
10984    #[serde(default)]
10985    pub unpack: Option<Box<Expression>>,
10986}
10987
10988/// ConvertToCharset
10989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10990#[cfg_attr(feature = "bindings", derive(TS))]
10991pub struct ConvertToCharset {
10992    pub this: Box<Expression>,
10993    #[serde(default)]
10994    pub dest: Option<Box<Expression>>,
10995    #[serde(default)]
10996    pub source: Option<Box<Expression>>,
10997}
10998
10999/// ConvertTimezone
11000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11001#[cfg_attr(feature = "bindings", derive(TS))]
11002pub struct ConvertTimezone {
11003    #[serde(default)]
11004    pub source_tz: Option<Box<Expression>>,
11005    #[serde(default)]
11006    pub target_tz: Option<Box<Expression>>,
11007    #[serde(default)]
11008    pub timestamp: Option<Box<Expression>>,
11009    #[serde(default)]
11010    pub options: Vec<Expression>,
11011}
11012
11013/// GenerateSeries
11014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11015#[cfg_attr(feature = "bindings", derive(TS))]
11016pub struct GenerateSeries {
11017    #[serde(default)]
11018    pub start: Option<Box<Expression>>,
11019    #[serde(default)]
11020    pub end: Option<Box<Expression>>,
11021    #[serde(default)]
11022    pub step: Option<Box<Expression>>,
11023    #[serde(default)]
11024    pub is_end_exclusive: Option<Box<Expression>>,
11025}
11026
11027/// AIAgg
11028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11029#[cfg_attr(feature = "bindings", derive(TS))]
11030pub struct AIAgg {
11031    pub this: Box<Expression>,
11032    pub expression: Box<Expression>,
11033}
11034
11035/// AIClassify
11036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11037#[cfg_attr(feature = "bindings", derive(TS))]
11038pub struct AIClassify {
11039    pub this: Box<Expression>,
11040    #[serde(default)]
11041    pub categories: Option<Box<Expression>>,
11042    #[serde(default)]
11043    pub config: Option<Box<Expression>>,
11044}
11045
11046/// ArrayAll
11047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11048#[cfg_attr(feature = "bindings", derive(TS))]
11049pub struct ArrayAll {
11050    pub this: Box<Expression>,
11051    pub expression: Box<Expression>,
11052}
11053
11054/// ArrayAny
11055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11056#[cfg_attr(feature = "bindings", derive(TS))]
11057pub struct ArrayAny {
11058    pub this: Box<Expression>,
11059    pub expression: Box<Expression>,
11060}
11061
11062/// ArrayConstructCompact
11063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11064#[cfg_attr(feature = "bindings", derive(TS))]
11065pub struct ArrayConstructCompact {
11066    #[serde(default)]
11067    pub expressions: Vec<Expression>,
11068}
11069
11070/// StPoint
11071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11072#[cfg_attr(feature = "bindings", derive(TS))]
11073pub struct StPoint {
11074    pub this: Box<Expression>,
11075    pub expression: Box<Expression>,
11076    #[serde(default)]
11077    pub null: Option<Box<Expression>>,
11078}
11079
11080/// StDistance
11081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11082#[cfg_attr(feature = "bindings", derive(TS))]
11083pub struct StDistance {
11084    pub this: Box<Expression>,
11085    pub expression: Box<Expression>,
11086    #[serde(default)]
11087    pub use_spheroid: Option<Box<Expression>>,
11088}
11089
11090/// StringToArray
11091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11092#[cfg_attr(feature = "bindings", derive(TS))]
11093pub struct StringToArray {
11094    pub this: Box<Expression>,
11095    #[serde(default)]
11096    pub expression: Option<Box<Expression>>,
11097    #[serde(default)]
11098    pub null: Option<Box<Expression>>,
11099}
11100
11101/// ArraySum
11102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11103#[cfg_attr(feature = "bindings", derive(TS))]
11104pub struct ArraySum {
11105    pub this: Box<Expression>,
11106    #[serde(default)]
11107    pub expression: Option<Box<Expression>>,
11108}
11109
11110/// ObjectAgg
11111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11112#[cfg_attr(feature = "bindings", derive(TS))]
11113pub struct ObjectAgg {
11114    pub this: Box<Expression>,
11115    pub expression: Box<Expression>,
11116}
11117
11118/// CastToStrType
11119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11120#[cfg_attr(feature = "bindings", derive(TS))]
11121pub struct CastToStrType {
11122    pub this: Box<Expression>,
11123    #[serde(default)]
11124    pub to: Option<Box<Expression>>,
11125}
11126
11127/// CheckJson
11128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11129#[cfg_attr(feature = "bindings", derive(TS))]
11130pub struct CheckJson {
11131    pub this: Box<Expression>,
11132}
11133
11134/// CheckXml
11135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11136#[cfg_attr(feature = "bindings", derive(TS))]
11137pub struct CheckXml {
11138    pub this: Box<Expression>,
11139    #[serde(default)]
11140    pub disable_auto_convert: Option<Box<Expression>>,
11141}
11142
11143/// TranslateCharacters
11144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11145#[cfg_attr(feature = "bindings", derive(TS))]
11146pub struct TranslateCharacters {
11147    pub this: Box<Expression>,
11148    pub expression: Box<Expression>,
11149    #[serde(default)]
11150    pub with_error: Option<Box<Expression>>,
11151}
11152
11153/// CurrentSchemas
11154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11155#[cfg_attr(feature = "bindings", derive(TS))]
11156pub struct CurrentSchemas {
11157    #[serde(default)]
11158    pub this: Option<Box<Expression>>,
11159}
11160
11161/// CurrentDatetime
11162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11163#[cfg_attr(feature = "bindings", derive(TS))]
11164pub struct CurrentDatetime {
11165    #[serde(default)]
11166    pub this: Option<Box<Expression>>,
11167}
11168
11169/// Localtime
11170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11171#[cfg_attr(feature = "bindings", derive(TS))]
11172pub struct Localtime {
11173    #[serde(default)]
11174    pub this: Option<Box<Expression>>,
11175}
11176
11177/// Localtimestamp
11178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11179#[cfg_attr(feature = "bindings", derive(TS))]
11180pub struct Localtimestamp {
11181    #[serde(default)]
11182    pub this: Option<Box<Expression>>,
11183}
11184
11185/// Systimestamp
11186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11187#[cfg_attr(feature = "bindings", derive(TS))]
11188pub struct Systimestamp {
11189    #[serde(default)]
11190    pub this: Option<Box<Expression>>,
11191}
11192
11193/// CurrentSchema
11194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11195#[cfg_attr(feature = "bindings", derive(TS))]
11196pub struct CurrentSchema {
11197    #[serde(default)]
11198    pub this: Option<Box<Expression>>,
11199}
11200
11201/// CurrentUser
11202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11203#[cfg_attr(feature = "bindings", derive(TS))]
11204pub struct CurrentUser {
11205    #[serde(default)]
11206    pub this: Option<Box<Expression>>,
11207}
11208
11209/// SessionUser - MySQL/PostgreSQL SESSION_USER function
11210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11211#[cfg_attr(feature = "bindings", derive(TS))]
11212pub struct SessionUser;
11213
11214/// JSONPathRoot - Represents $ in JSON path expressions
11215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11216#[cfg_attr(feature = "bindings", derive(TS))]
11217pub struct JSONPathRoot;
11218
11219/// UtcTime
11220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11221#[cfg_attr(feature = "bindings", derive(TS))]
11222pub struct UtcTime {
11223    #[serde(default)]
11224    pub this: Option<Box<Expression>>,
11225}
11226
11227/// UtcTimestamp
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct UtcTimestamp {
11231    #[serde(default)]
11232    pub this: Option<Box<Expression>>,
11233}
11234
11235/// TimestampFunc - TIMESTAMP constructor function
11236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11237#[cfg_attr(feature = "bindings", derive(TS))]
11238pub struct TimestampFunc {
11239    #[serde(default)]
11240    pub this: Option<Box<Expression>>,
11241    #[serde(default)]
11242    pub zone: Option<Box<Expression>>,
11243    #[serde(default)]
11244    pub with_tz: Option<bool>,
11245    #[serde(default)]
11246    pub safe: Option<bool>,
11247}
11248
11249/// DateBin
11250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11251#[cfg_attr(feature = "bindings", derive(TS))]
11252pub struct DateBin {
11253    pub this: Box<Expression>,
11254    pub expression: Box<Expression>,
11255    #[serde(default)]
11256    pub unit: Option<String>,
11257    #[serde(default)]
11258    pub zone: Option<Box<Expression>>,
11259    #[serde(default)]
11260    pub origin: Option<Box<Expression>>,
11261}
11262
11263/// Datetime
11264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11265#[cfg_attr(feature = "bindings", derive(TS))]
11266pub struct Datetime {
11267    pub this: Box<Expression>,
11268    #[serde(default)]
11269    pub expression: Option<Box<Expression>>,
11270}
11271
11272/// DatetimeAdd
11273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11274#[cfg_attr(feature = "bindings", derive(TS))]
11275pub struct DatetimeAdd {
11276    pub this: Box<Expression>,
11277    pub expression: Box<Expression>,
11278    #[serde(default)]
11279    pub unit: Option<String>,
11280}
11281
11282/// DatetimeSub
11283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11284#[cfg_attr(feature = "bindings", derive(TS))]
11285pub struct DatetimeSub {
11286    pub this: Box<Expression>,
11287    pub expression: Box<Expression>,
11288    #[serde(default)]
11289    pub unit: Option<String>,
11290}
11291
11292/// DatetimeDiff
11293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11294#[cfg_attr(feature = "bindings", derive(TS))]
11295pub struct DatetimeDiff {
11296    pub this: Box<Expression>,
11297    pub expression: Box<Expression>,
11298    #[serde(default)]
11299    pub unit: Option<String>,
11300}
11301
11302/// DatetimeTrunc
11303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11304#[cfg_attr(feature = "bindings", derive(TS))]
11305pub struct DatetimeTrunc {
11306    pub this: Box<Expression>,
11307    pub unit: String,
11308    #[serde(default)]
11309    pub zone: Option<Box<Expression>>,
11310}
11311
11312/// Dayname
11313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11314#[cfg_attr(feature = "bindings", derive(TS))]
11315pub struct Dayname {
11316    pub this: Box<Expression>,
11317    #[serde(default)]
11318    pub abbreviated: Option<Box<Expression>>,
11319}
11320
11321/// MakeInterval
11322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11323#[cfg_attr(feature = "bindings", derive(TS))]
11324pub struct MakeInterval {
11325    #[serde(default)]
11326    pub year: Option<Box<Expression>>,
11327    #[serde(default)]
11328    pub month: Option<Box<Expression>>,
11329    #[serde(default)]
11330    pub week: Option<Box<Expression>>,
11331    #[serde(default)]
11332    pub day: Option<Box<Expression>>,
11333    #[serde(default)]
11334    pub hour: Option<Box<Expression>>,
11335    #[serde(default)]
11336    pub minute: Option<Box<Expression>>,
11337    #[serde(default)]
11338    pub second: Option<Box<Expression>>,
11339}
11340
11341/// PreviousDay
11342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11343#[cfg_attr(feature = "bindings", derive(TS))]
11344pub struct PreviousDay {
11345    pub this: Box<Expression>,
11346    pub expression: Box<Expression>,
11347}
11348
11349/// Elt
11350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11351#[cfg_attr(feature = "bindings", derive(TS))]
11352pub struct Elt {
11353    pub this: Box<Expression>,
11354    #[serde(default)]
11355    pub expressions: Vec<Expression>,
11356}
11357
11358/// TimestampAdd
11359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11360#[cfg_attr(feature = "bindings", derive(TS))]
11361pub struct TimestampAdd {
11362    pub this: Box<Expression>,
11363    pub expression: Box<Expression>,
11364    #[serde(default)]
11365    pub unit: Option<String>,
11366}
11367
11368/// TimestampSub
11369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11370#[cfg_attr(feature = "bindings", derive(TS))]
11371pub struct TimestampSub {
11372    pub this: Box<Expression>,
11373    pub expression: Box<Expression>,
11374    #[serde(default)]
11375    pub unit: Option<String>,
11376}
11377
11378/// TimestampDiff
11379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11380#[cfg_attr(feature = "bindings", derive(TS))]
11381pub struct TimestampDiff {
11382    pub this: Box<Expression>,
11383    pub expression: Box<Expression>,
11384    #[serde(default)]
11385    pub unit: Option<String>,
11386}
11387
11388/// TimeSlice
11389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11390#[cfg_attr(feature = "bindings", derive(TS))]
11391pub struct TimeSlice {
11392    pub this: Box<Expression>,
11393    pub expression: Box<Expression>,
11394    pub unit: String,
11395    #[serde(default)]
11396    pub kind: Option<String>,
11397}
11398
11399/// TimeAdd
11400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11401#[cfg_attr(feature = "bindings", derive(TS))]
11402pub struct TimeAdd {
11403    pub this: Box<Expression>,
11404    pub expression: Box<Expression>,
11405    #[serde(default)]
11406    pub unit: Option<String>,
11407}
11408
11409/// TimeSub
11410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11411#[cfg_attr(feature = "bindings", derive(TS))]
11412pub struct TimeSub {
11413    pub this: Box<Expression>,
11414    pub expression: Box<Expression>,
11415    #[serde(default)]
11416    pub unit: Option<String>,
11417}
11418
11419/// TimeDiff
11420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11421#[cfg_attr(feature = "bindings", derive(TS))]
11422pub struct TimeDiff {
11423    pub this: Box<Expression>,
11424    pub expression: Box<Expression>,
11425    #[serde(default)]
11426    pub unit: Option<String>,
11427}
11428
11429/// TimeTrunc
11430#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11431#[cfg_attr(feature = "bindings", derive(TS))]
11432pub struct TimeTrunc {
11433    pub this: Box<Expression>,
11434    pub unit: String,
11435    #[serde(default)]
11436    pub zone: Option<Box<Expression>>,
11437}
11438
11439/// DateFromParts
11440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11441#[cfg_attr(feature = "bindings", derive(TS))]
11442pub struct DateFromParts {
11443    #[serde(default)]
11444    pub year: Option<Box<Expression>>,
11445    #[serde(default)]
11446    pub month: Option<Box<Expression>>,
11447    #[serde(default)]
11448    pub day: Option<Box<Expression>>,
11449    #[serde(default)]
11450    pub allow_overflow: Option<Box<Expression>>,
11451}
11452
11453/// TimeFromParts
11454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11455#[cfg_attr(feature = "bindings", derive(TS))]
11456pub struct TimeFromParts {
11457    #[serde(default)]
11458    pub hour: Option<Box<Expression>>,
11459    #[serde(default)]
11460    pub min: Option<Box<Expression>>,
11461    #[serde(default)]
11462    pub sec: Option<Box<Expression>>,
11463    #[serde(default)]
11464    pub nano: Option<Box<Expression>>,
11465    #[serde(default)]
11466    pub fractions: Option<Box<Expression>>,
11467    #[serde(default)]
11468    pub precision: Option<i64>,
11469}
11470
11471/// DecodeCase
11472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11473#[cfg_attr(feature = "bindings", derive(TS))]
11474pub struct DecodeCase {
11475    #[serde(default)]
11476    pub expressions: Vec<Expression>,
11477}
11478
11479/// Decrypt
11480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11481#[cfg_attr(feature = "bindings", derive(TS))]
11482pub struct Decrypt {
11483    pub this: Box<Expression>,
11484    #[serde(default)]
11485    pub passphrase: Option<Box<Expression>>,
11486    #[serde(default)]
11487    pub aad: Option<Box<Expression>>,
11488    #[serde(default)]
11489    pub encryption_method: Option<Box<Expression>>,
11490    #[serde(default)]
11491    pub safe: Option<Box<Expression>>,
11492}
11493
11494/// DecryptRaw
11495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11496#[cfg_attr(feature = "bindings", derive(TS))]
11497pub struct DecryptRaw {
11498    pub this: Box<Expression>,
11499    #[serde(default)]
11500    pub key: Option<Box<Expression>>,
11501    #[serde(default)]
11502    pub iv: Option<Box<Expression>>,
11503    #[serde(default)]
11504    pub aad: Option<Box<Expression>>,
11505    #[serde(default)]
11506    pub encryption_method: Option<Box<Expression>>,
11507    #[serde(default)]
11508    pub aead: Option<Box<Expression>>,
11509    #[serde(default)]
11510    pub safe: Option<Box<Expression>>,
11511}
11512
11513/// Encode
11514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11515#[cfg_attr(feature = "bindings", derive(TS))]
11516pub struct Encode {
11517    pub this: Box<Expression>,
11518    #[serde(default)]
11519    pub charset: Option<Box<Expression>>,
11520}
11521
11522/// Encrypt
11523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11524#[cfg_attr(feature = "bindings", derive(TS))]
11525pub struct Encrypt {
11526    pub this: Box<Expression>,
11527    #[serde(default)]
11528    pub passphrase: Option<Box<Expression>>,
11529    #[serde(default)]
11530    pub aad: Option<Box<Expression>>,
11531    #[serde(default)]
11532    pub encryption_method: Option<Box<Expression>>,
11533}
11534
11535/// EncryptRaw
11536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11537#[cfg_attr(feature = "bindings", derive(TS))]
11538pub struct EncryptRaw {
11539    pub this: Box<Expression>,
11540    #[serde(default)]
11541    pub key: Option<Box<Expression>>,
11542    #[serde(default)]
11543    pub iv: Option<Box<Expression>>,
11544    #[serde(default)]
11545    pub aad: Option<Box<Expression>>,
11546    #[serde(default)]
11547    pub encryption_method: Option<Box<Expression>>,
11548}
11549
11550/// EqualNull
11551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11552#[cfg_attr(feature = "bindings", derive(TS))]
11553pub struct EqualNull {
11554    pub this: Box<Expression>,
11555    pub expression: Box<Expression>,
11556}
11557
11558/// ToBinary
11559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11560#[cfg_attr(feature = "bindings", derive(TS))]
11561pub struct ToBinary {
11562    pub this: Box<Expression>,
11563    #[serde(default)]
11564    pub format: Option<String>,
11565    #[serde(default)]
11566    pub safe: Option<Box<Expression>>,
11567}
11568
11569/// Base64DecodeBinary
11570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11571#[cfg_attr(feature = "bindings", derive(TS))]
11572pub struct Base64DecodeBinary {
11573    pub this: Box<Expression>,
11574    #[serde(default)]
11575    pub alphabet: Option<Box<Expression>>,
11576}
11577
11578/// Base64DecodeString
11579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11580#[cfg_attr(feature = "bindings", derive(TS))]
11581pub struct Base64DecodeString {
11582    pub this: Box<Expression>,
11583    #[serde(default)]
11584    pub alphabet: Option<Box<Expression>>,
11585}
11586
11587/// Base64Encode
11588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11589#[cfg_attr(feature = "bindings", derive(TS))]
11590pub struct Base64Encode {
11591    pub this: Box<Expression>,
11592    #[serde(default)]
11593    pub max_line_length: Option<Box<Expression>>,
11594    #[serde(default)]
11595    pub alphabet: Option<Box<Expression>>,
11596}
11597
11598/// TryBase64DecodeBinary
11599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11600#[cfg_attr(feature = "bindings", derive(TS))]
11601pub struct TryBase64DecodeBinary {
11602    pub this: Box<Expression>,
11603    #[serde(default)]
11604    pub alphabet: Option<Box<Expression>>,
11605}
11606
11607/// TryBase64DecodeString
11608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11609#[cfg_attr(feature = "bindings", derive(TS))]
11610pub struct TryBase64DecodeString {
11611    pub this: Box<Expression>,
11612    #[serde(default)]
11613    pub alphabet: Option<Box<Expression>>,
11614}
11615
11616/// GapFill
11617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11618#[cfg_attr(feature = "bindings", derive(TS))]
11619pub struct GapFill {
11620    pub this: Box<Expression>,
11621    #[serde(default)]
11622    pub ts_column: Option<Box<Expression>>,
11623    #[serde(default)]
11624    pub bucket_width: Option<Box<Expression>>,
11625    #[serde(default)]
11626    pub partitioning_columns: Option<Box<Expression>>,
11627    #[serde(default)]
11628    pub value_columns: Option<Box<Expression>>,
11629    #[serde(default)]
11630    pub origin: Option<Box<Expression>>,
11631    #[serde(default)]
11632    pub ignore_nulls: Option<Box<Expression>>,
11633}
11634
11635/// GenerateDateArray
11636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11637#[cfg_attr(feature = "bindings", derive(TS))]
11638pub struct GenerateDateArray {
11639    #[serde(default)]
11640    pub start: Option<Box<Expression>>,
11641    #[serde(default)]
11642    pub end: Option<Box<Expression>>,
11643    #[serde(default)]
11644    pub step: Option<Box<Expression>>,
11645}
11646
11647/// GenerateTimestampArray
11648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11649#[cfg_attr(feature = "bindings", derive(TS))]
11650pub struct GenerateTimestampArray {
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/// GetExtract
11660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11661#[cfg_attr(feature = "bindings", derive(TS))]
11662pub struct GetExtract {
11663    pub this: Box<Expression>,
11664    pub expression: Box<Expression>,
11665}
11666
11667/// Getbit
11668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11669#[cfg_attr(feature = "bindings", derive(TS))]
11670pub struct Getbit {
11671    pub this: Box<Expression>,
11672    pub expression: Box<Expression>,
11673    #[serde(default)]
11674    pub zero_is_msb: Option<Box<Expression>>,
11675}
11676
11677/// OverflowTruncateBehavior
11678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11679#[cfg_attr(feature = "bindings", derive(TS))]
11680pub struct OverflowTruncateBehavior {
11681    #[serde(default)]
11682    pub this: Option<Box<Expression>>,
11683    #[serde(default)]
11684    pub with_count: Option<Box<Expression>>,
11685}
11686
11687/// HexEncode
11688#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11689#[cfg_attr(feature = "bindings", derive(TS))]
11690pub struct HexEncode {
11691    pub this: Box<Expression>,
11692    #[serde(default)]
11693    pub case: Option<Box<Expression>>,
11694}
11695
11696/// Compress
11697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11698#[cfg_attr(feature = "bindings", derive(TS))]
11699pub struct Compress {
11700    pub this: Box<Expression>,
11701    #[serde(default)]
11702    pub method: Option<String>,
11703}
11704
11705/// DecompressBinary
11706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11707#[cfg_attr(feature = "bindings", derive(TS))]
11708pub struct DecompressBinary {
11709    pub this: Box<Expression>,
11710    pub method: String,
11711}
11712
11713/// DecompressString
11714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11715#[cfg_attr(feature = "bindings", derive(TS))]
11716pub struct DecompressString {
11717    pub this: Box<Expression>,
11718    pub method: String,
11719}
11720
11721/// Xor
11722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11723#[cfg_attr(feature = "bindings", derive(TS))]
11724pub struct Xor {
11725    #[serde(default)]
11726    pub this: Option<Box<Expression>>,
11727    #[serde(default)]
11728    pub expression: Option<Box<Expression>>,
11729    #[serde(default)]
11730    pub expressions: Vec<Expression>,
11731}
11732
11733/// Nullif
11734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11735#[cfg_attr(feature = "bindings", derive(TS))]
11736pub struct Nullif {
11737    pub this: Box<Expression>,
11738    pub expression: Box<Expression>,
11739}
11740
11741/// JSON
11742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11743#[cfg_attr(feature = "bindings", derive(TS))]
11744pub struct JSON {
11745    #[serde(default)]
11746    pub this: Option<Box<Expression>>,
11747    #[serde(default)]
11748    pub with_: Option<Box<Expression>>,
11749    #[serde(default)]
11750    pub unique: bool,
11751}
11752
11753/// JSONPath
11754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11755#[cfg_attr(feature = "bindings", derive(TS))]
11756pub struct JSONPath {
11757    #[serde(default)]
11758    pub expressions: Vec<Expression>,
11759    #[serde(default)]
11760    pub escape: Option<Box<Expression>>,
11761}
11762
11763/// JSONPathFilter
11764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11765#[cfg_attr(feature = "bindings", derive(TS))]
11766pub struct JSONPathFilter {
11767    pub this: Box<Expression>,
11768}
11769
11770/// JSONPathKey
11771#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11772#[cfg_attr(feature = "bindings", derive(TS))]
11773pub struct JSONPathKey {
11774    pub this: Box<Expression>,
11775}
11776
11777/// JSONPathRecursive
11778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11779#[cfg_attr(feature = "bindings", derive(TS))]
11780pub struct JSONPathRecursive {
11781    #[serde(default)]
11782    pub this: Option<Box<Expression>>,
11783}
11784
11785/// JSONPathScript
11786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11787#[cfg_attr(feature = "bindings", derive(TS))]
11788pub struct JSONPathScript {
11789    pub this: Box<Expression>,
11790}
11791
11792/// JSONPathSlice
11793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11794#[cfg_attr(feature = "bindings", derive(TS))]
11795pub struct JSONPathSlice {
11796    #[serde(default)]
11797    pub start: Option<Box<Expression>>,
11798    #[serde(default)]
11799    pub end: Option<Box<Expression>>,
11800    #[serde(default)]
11801    pub step: Option<Box<Expression>>,
11802}
11803
11804/// JSONPathSelector
11805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11806#[cfg_attr(feature = "bindings", derive(TS))]
11807pub struct JSONPathSelector {
11808    pub this: Box<Expression>,
11809}
11810
11811/// JSONPathSubscript
11812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11813#[cfg_attr(feature = "bindings", derive(TS))]
11814pub struct JSONPathSubscript {
11815    pub this: Box<Expression>,
11816}
11817
11818/// JSONPathUnion
11819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11820#[cfg_attr(feature = "bindings", derive(TS))]
11821pub struct JSONPathUnion {
11822    #[serde(default)]
11823    pub expressions: Vec<Expression>,
11824}
11825
11826/// Format
11827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11828#[cfg_attr(feature = "bindings", derive(TS))]
11829pub struct Format {
11830    pub this: Box<Expression>,
11831    #[serde(default)]
11832    pub expressions: Vec<Expression>,
11833}
11834
11835/// JSONKeys
11836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11837#[cfg_attr(feature = "bindings", derive(TS))]
11838pub struct JSONKeys {
11839    pub this: Box<Expression>,
11840    #[serde(default)]
11841    pub expression: Option<Box<Expression>>,
11842    #[serde(default)]
11843    pub expressions: Vec<Expression>,
11844}
11845
11846/// JSONKeyValue
11847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11848#[cfg_attr(feature = "bindings", derive(TS))]
11849pub struct JSONKeyValue {
11850    pub this: Box<Expression>,
11851    pub expression: Box<Expression>,
11852}
11853
11854/// JSONKeysAtDepth
11855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11856#[cfg_attr(feature = "bindings", derive(TS))]
11857pub struct JSONKeysAtDepth {
11858    pub this: Box<Expression>,
11859    #[serde(default)]
11860    pub expression: Option<Box<Expression>>,
11861    #[serde(default)]
11862    pub mode: Option<Box<Expression>>,
11863}
11864
11865/// JSONObject
11866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11867#[cfg_attr(feature = "bindings", derive(TS))]
11868pub struct JSONObject {
11869    #[serde(default)]
11870    pub expressions: Vec<Expression>,
11871    #[serde(default)]
11872    pub null_handling: Option<Box<Expression>>,
11873    #[serde(default)]
11874    pub unique_keys: Option<Box<Expression>>,
11875    #[serde(default)]
11876    pub return_type: Option<Box<Expression>>,
11877    #[serde(default)]
11878    pub encoding: Option<Box<Expression>>,
11879}
11880
11881/// JSONObjectAgg
11882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11883#[cfg_attr(feature = "bindings", derive(TS))]
11884pub struct JSONObjectAgg {
11885    #[serde(default)]
11886    pub expressions: Vec<Expression>,
11887    #[serde(default)]
11888    pub null_handling: Option<Box<Expression>>,
11889    #[serde(default)]
11890    pub unique_keys: Option<Box<Expression>>,
11891    #[serde(default)]
11892    pub return_type: Option<Box<Expression>>,
11893    #[serde(default)]
11894    pub encoding: Option<Box<Expression>>,
11895}
11896
11897/// JSONBObjectAgg
11898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11899#[cfg_attr(feature = "bindings", derive(TS))]
11900pub struct JSONBObjectAgg {
11901    pub this: Box<Expression>,
11902    pub expression: Box<Expression>,
11903}
11904
11905/// JSONArray
11906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11907#[cfg_attr(feature = "bindings", derive(TS))]
11908pub struct JSONArray {
11909    #[serde(default)]
11910    pub expressions: Vec<Expression>,
11911    #[serde(default)]
11912    pub null_handling: Option<Box<Expression>>,
11913    #[serde(default)]
11914    pub return_type: Option<Box<Expression>>,
11915    #[serde(default)]
11916    pub strict: Option<Box<Expression>>,
11917}
11918
11919/// JSONArrayAgg
11920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11921#[cfg_attr(feature = "bindings", derive(TS))]
11922pub struct JSONArrayAgg {
11923    pub this: Box<Expression>,
11924    #[serde(default)]
11925    pub order: Option<Box<Expression>>,
11926    #[serde(default)]
11927    pub null_handling: Option<Box<Expression>>,
11928    #[serde(default)]
11929    pub return_type: Option<Box<Expression>>,
11930    #[serde(default)]
11931    pub strict: Option<Box<Expression>>,
11932}
11933
11934/// JSONExists
11935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11936#[cfg_attr(feature = "bindings", derive(TS))]
11937pub struct JSONExists {
11938    pub this: Box<Expression>,
11939    #[serde(default)]
11940    pub path: Option<Box<Expression>>,
11941    #[serde(default)]
11942    pub passing: Option<Box<Expression>>,
11943    #[serde(default)]
11944    pub on_condition: Option<Box<Expression>>,
11945    #[serde(default)]
11946    pub from_dcolonqmark: Option<Box<Expression>>,
11947}
11948
11949/// JSONColumnDef
11950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11951#[cfg_attr(feature = "bindings", derive(TS))]
11952pub struct JSONColumnDef {
11953    #[serde(default)]
11954    pub this: Option<Box<Expression>>,
11955    #[serde(default)]
11956    pub kind: Option<String>,
11957    #[serde(default)]
11958    pub path: Option<Box<Expression>>,
11959    #[serde(default)]
11960    pub nested_schema: Option<Box<Expression>>,
11961    #[serde(default)]
11962    pub ordinality: Option<Box<Expression>>,
11963}
11964
11965/// JSONSchema
11966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11967#[cfg_attr(feature = "bindings", derive(TS))]
11968pub struct JSONSchema {
11969    #[serde(default)]
11970    pub expressions: Vec<Expression>,
11971}
11972
11973/// JSONSet
11974#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11975#[cfg_attr(feature = "bindings", derive(TS))]
11976pub struct JSONSet {
11977    pub this: Box<Expression>,
11978    #[serde(default)]
11979    pub expressions: Vec<Expression>,
11980}
11981
11982/// JSONStripNulls
11983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11984#[cfg_attr(feature = "bindings", derive(TS))]
11985pub struct JSONStripNulls {
11986    pub this: Box<Expression>,
11987    #[serde(default)]
11988    pub expression: Option<Box<Expression>>,
11989    #[serde(default)]
11990    pub include_arrays: Option<Box<Expression>>,
11991    #[serde(default)]
11992    pub remove_empty: Option<Box<Expression>>,
11993}
11994
11995/// JSONValue
11996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11997#[cfg_attr(feature = "bindings", derive(TS))]
11998pub struct JSONValue {
11999    pub this: Box<Expression>,
12000    #[serde(default)]
12001    pub path: Option<Box<Expression>>,
12002    #[serde(default)]
12003    pub returning: Option<Box<Expression>>,
12004    #[serde(default)]
12005    pub on_condition: Option<Box<Expression>>,
12006}
12007
12008/// JSONValueArray
12009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12010#[cfg_attr(feature = "bindings", derive(TS))]
12011pub struct JSONValueArray {
12012    pub this: Box<Expression>,
12013    #[serde(default)]
12014    pub expression: Option<Box<Expression>>,
12015}
12016
12017/// JSONRemove
12018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12019#[cfg_attr(feature = "bindings", derive(TS))]
12020pub struct JSONRemove {
12021    pub this: Box<Expression>,
12022    #[serde(default)]
12023    pub expressions: Vec<Expression>,
12024}
12025
12026/// JSONTable
12027#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12028#[cfg_attr(feature = "bindings", derive(TS))]
12029pub struct JSONTable {
12030    pub this: Box<Expression>,
12031    #[serde(default)]
12032    pub schema: Option<Box<Expression>>,
12033    #[serde(default)]
12034    pub path: Option<Box<Expression>>,
12035    #[serde(default)]
12036    pub error_handling: Option<Box<Expression>>,
12037    #[serde(default)]
12038    pub empty_handling: Option<Box<Expression>>,
12039}
12040
12041/// JSONType
12042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12043#[cfg_attr(feature = "bindings", derive(TS))]
12044pub struct JSONType {
12045    pub this: Box<Expression>,
12046    #[serde(default)]
12047    pub expression: Option<Box<Expression>>,
12048}
12049
12050/// ObjectInsert
12051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12052#[cfg_attr(feature = "bindings", derive(TS))]
12053pub struct ObjectInsert {
12054    pub this: Box<Expression>,
12055    #[serde(default)]
12056    pub key: Option<Box<Expression>>,
12057    #[serde(default)]
12058    pub value: Option<Box<Expression>>,
12059    #[serde(default)]
12060    pub update_flag: Option<Box<Expression>>,
12061}
12062
12063/// OpenJSONColumnDef
12064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12065#[cfg_attr(feature = "bindings", derive(TS))]
12066pub struct OpenJSONColumnDef {
12067    pub this: Box<Expression>,
12068    pub kind: String,
12069    #[serde(default)]
12070    pub path: Option<Box<Expression>>,
12071    #[serde(default)]
12072    pub as_json: Option<Box<Expression>>,
12073    /// The parsed data type for proper generation
12074    #[serde(default, skip_serializing_if = "Option::is_none")]
12075    pub data_type: Option<DataType>,
12076}
12077
12078/// OpenJSON
12079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12080#[cfg_attr(feature = "bindings", derive(TS))]
12081pub struct OpenJSON {
12082    pub this: Box<Expression>,
12083    #[serde(default)]
12084    pub path: Option<Box<Expression>>,
12085    #[serde(default)]
12086    pub expressions: Vec<Expression>,
12087}
12088
12089/// JSONBExists
12090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12091#[cfg_attr(feature = "bindings", derive(TS))]
12092pub struct JSONBExists {
12093    pub this: Box<Expression>,
12094    #[serde(default)]
12095    pub path: Option<Box<Expression>>,
12096}
12097
12098/// JSONCast
12099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12100#[cfg_attr(feature = "bindings", derive(TS))]
12101pub struct JSONCast {
12102    pub this: Box<Expression>,
12103    pub to: DataType,
12104}
12105
12106/// JSONExtract
12107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12108#[cfg_attr(feature = "bindings", derive(TS))]
12109pub struct JSONExtract {
12110    pub this: Box<Expression>,
12111    pub expression: Box<Expression>,
12112    #[serde(default)]
12113    pub only_json_types: Option<Box<Expression>>,
12114    #[serde(default)]
12115    pub expressions: Vec<Expression>,
12116    #[serde(default)]
12117    pub variant_extract: Option<Box<Expression>>,
12118    #[serde(default)]
12119    pub json_query: Option<Box<Expression>>,
12120    #[serde(default)]
12121    pub option: Option<Box<Expression>>,
12122    #[serde(default)]
12123    pub quote: Option<Box<Expression>>,
12124    #[serde(default)]
12125    pub on_condition: Option<Box<Expression>>,
12126    #[serde(default)]
12127    pub requires_json: Option<Box<Expression>>,
12128}
12129
12130/// JSONExtractQuote
12131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12132#[cfg_attr(feature = "bindings", derive(TS))]
12133pub struct JSONExtractQuote {
12134    #[serde(default)]
12135    pub option: Option<Box<Expression>>,
12136    #[serde(default)]
12137    pub scalar: Option<Box<Expression>>,
12138}
12139
12140/// JSONExtractArray
12141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12142#[cfg_attr(feature = "bindings", derive(TS))]
12143pub struct JSONExtractArray {
12144    pub this: Box<Expression>,
12145    #[serde(default)]
12146    pub expression: Option<Box<Expression>>,
12147}
12148
12149/// JSONExtractScalar
12150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12151#[cfg_attr(feature = "bindings", derive(TS))]
12152pub struct JSONExtractScalar {
12153    pub this: Box<Expression>,
12154    pub expression: Box<Expression>,
12155    #[serde(default)]
12156    pub only_json_types: Option<Box<Expression>>,
12157    #[serde(default)]
12158    pub expressions: Vec<Expression>,
12159    #[serde(default)]
12160    pub json_type: Option<Box<Expression>>,
12161    #[serde(default)]
12162    pub scalar_only: Option<Box<Expression>>,
12163}
12164
12165/// JSONBExtractScalar
12166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12167#[cfg_attr(feature = "bindings", derive(TS))]
12168pub struct JSONBExtractScalar {
12169    pub this: Box<Expression>,
12170    pub expression: Box<Expression>,
12171    #[serde(default)]
12172    pub json_type: Option<Box<Expression>>,
12173}
12174
12175/// JSONFormat
12176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12177#[cfg_attr(feature = "bindings", derive(TS))]
12178pub struct JSONFormat {
12179    #[serde(default)]
12180    pub this: Option<Box<Expression>>,
12181    #[serde(default)]
12182    pub options: Vec<Expression>,
12183    #[serde(default)]
12184    pub is_json: Option<Box<Expression>>,
12185    #[serde(default)]
12186    pub to_json: Option<Box<Expression>>,
12187}
12188
12189/// JSONArrayAppend
12190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12191#[cfg_attr(feature = "bindings", derive(TS))]
12192pub struct JSONArrayAppend {
12193    pub this: Box<Expression>,
12194    #[serde(default)]
12195    pub expressions: Vec<Expression>,
12196}
12197
12198/// JSONArrayContains
12199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12200#[cfg_attr(feature = "bindings", derive(TS))]
12201pub struct JSONArrayContains {
12202    pub this: Box<Expression>,
12203    pub expression: Box<Expression>,
12204    #[serde(default)]
12205    pub json_type: Option<Box<Expression>>,
12206}
12207
12208/// JSONArrayInsert
12209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12210#[cfg_attr(feature = "bindings", derive(TS))]
12211pub struct JSONArrayInsert {
12212    pub this: Box<Expression>,
12213    #[serde(default)]
12214    pub expressions: Vec<Expression>,
12215}
12216
12217/// ParseJSON
12218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12219#[cfg_attr(feature = "bindings", derive(TS))]
12220pub struct ParseJSON {
12221    pub this: Box<Expression>,
12222    #[serde(default)]
12223    pub expression: Option<Box<Expression>>,
12224    #[serde(default)]
12225    pub safe: Option<Box<Expression>>,
12226}
12227
12228/// ParseUrl
12229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12230#[cfg_attr(feature = "bindings", derive(TS))]
12231pub struct ParseUrl {
12232    pub this: Box<Expression>,
12233    #[serde(default)]
12234    pub part_to_extract: Option<Box<Expression>>,
12235    #[serde(default)]
12236    pub key: Option<Box<Expression>>,
12237    #[serde(default)]
12238    pub permissive: Option<Box<Expression>>,
12239}
12240
12241/// ParseIp
12242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12243#[cfg_attr(feature = "bindings", derive(TS))]
12244pub struct ParseIp {
12245    pub this: Box<Expression>,
12246    #[serde(default)]
12247    pub type_: Option<Box<Expression>>,
12248    #[serde(default)]
12249    pub permissive: Option<Box<Expression>>,
12250}
12251
12252/// ParseTime
12253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12254#[cfg_attr(feature = "bindings", derive(TS))]
12255pub struct ParseTime {
12256    pub this: Box<Expression>,
12257    pub format: String,
12258}
12259
12260/// ParseDatetime
12261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12262#[cfg_attr(feature = "bindings", derive(TS))]
12263pub struct ParseDatetime {
12264    pub this: Box<Expression>,
12265    #[serde(default)]
12266    pub format: Option<String>,
12267    #[serde(default)]
12268    pub zone: Option<Box<Expression>>,
12269}
12270
12271/// Map
12272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12273#[cfg_attr(feature = "bindings", derive(TS))]
12274pub struct Map {
12275    #[serde(default)]
12276    pub keys: Vec<Expression>,
12277    #[serde(default)]
12278    pub values: Vec<Expression>,
12279}
12280
12281/// MapCat
12282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12283#[cfg_attr(feature = "bindings", derive(TS))]
12284pub struct MapCat {
12285    pub this: Box<Expression>,
12286    pub expression: Box<Expression>,
12287}
12288
12289/// MapDelete
12290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12291#[cfg_attr(feature = "bindings", derive(TS))]
12292pub struct MapDelete {
12293    pub this: Box<Expression>,
12294    #[serde(default)]
12295    pub expressions: Vec<Expression>,
12296}
12297
12298/// MapInsert
12299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12300#[cfg_attr(feature = "bindings", derive(TS))]
12301pub struct MapInsert {
12302    pub this: Box<Expression>,
12303    #[serde(default)]
12304    pub key: Option<Box<Expression>>,
12305    #[serde(default)]
12306    pub value: Option<Box<Expression>>,
12307    #[serde(default)]
12308    pub update_flag: Option<Box<Expression>>,
12309}
12310
12311/// MapPick
12312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12313#[cfg_attr(feature = "bindings", derive(TS))]
12314pub struct MapPick {
12315    pub this: Box<Expression>,
12316    #[serde(default)]
12317    pub expressions: Vec<Expression>,
12318}
12319
12320/// ScopeResolution
12321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12322#[cfg_attr(feature = "bindings", derive(TS))]
12323pub struct ScopeResolution {
12324    #[serde(default)]
12325    pub this: Option<Box<Expression>>,
12326    pub expression: Box<Expression>,
12327}
12328
12329/// Slice
12330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12331#[cfg_attr(feature = "bindings", derive(TS))]
12332pub struct Slice {
12333    #[serde(default)]
12334    pub this: Option<Box<Expression>>,
12335    #[serde(default)]
12336    pub expression: Option<Box<Expression>>,
12337    #[serde(default)]
12338    pub step: Option<Box<Expression>>,
12339}
12340
12341/// VarMap
12342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12343#[cfg_attr(feature = "bindings", derive(TS))]
12344pub struct VarMap {
12345    #[serde(default)]
12346    pub keys: Vec<Expression>,
12347    #[serde(default)]
12348    pub values: Vec<Expression>,
12349}
12350
12351/// MatchAgainst
12352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12353#[cfg_attr(feature = "bindings", derive(TS))]
12354pub struct MatchAgainst {
12355    pub this: Box<Expression>,
12356    #[serde(default)]
12357    pub expressions: Vec<Expression>,
12358    #[serde(default)]
12359    pub modifier: Option<Box<Expression>>,
12360}
12361
12362/// MD5Digest
12363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12364#[cfg_attr(feature = "bindings", derive(TS))]
12365pub struct MD5Digest {
12366    pub this: Box<Expression>,
12367    #[serde(default)]
12368    pub expressions: Vec<Expression>,
12369}
12370
12371/// Monthname
12372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12373#[cfg_attr(feature = "bindings", derive(TS))]
12374pub struct Monthname {
12375    pub this: Box<Expression>,
12376    #[serde(default)]
12377    pub abbreviated: Option<Box<Expression>>,
12378}
12379
12380/// Ntile
12381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12382#[cfg_attr(feature = "bindings", derive(TS))]
12383pub struct Ntile {
12384    #[serde(default)]
12385    pub this: Option<Box<Expression>>,
12386}
12387
12388/// Normalize
12389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12390#[cfg_attr(feature = "bindings", derive(TS))]
12391pub struct Normalize {
12392    pub this: Box<Expression>,
12393    #[serde(default)]
12394    pub form: Option<Box<Expression>>,
12395    #[serde(default)]
12396    pub is_casefold: Option<Box<Expression>>,
12397}
12398
12399/// Normal
12400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12401#[cfg_attr(feature = "bindings", derive(TS))]
12402pub struct Normal {
12403    pub this: Box<Expression>,
12404    #[serde(default)]
12405    pub stddev: Option<Box<Expression>>,
12406    #[serde(default)]
12407    pub gen: Option<Box<Expression>>,
12408}
12409
12410/// Predict
12411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12412#[cfg_attr(feature = "bindings", derive(TS))]
12413pub struct Predict {
12414    pub this: Box<Expression>,
12415    pub expression: Box<Expression>,
12416    #[serde(default)]
12417    pub params_struct: Option<Box<Expression>>,
12418}
12419
12420/// MLTranslate
12421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12422#[cfg_attr(feature = "bindings", derive(TS))]
12423pub struct MLTranslate {
12424    pub this: Box<Expression>,
12425    pub expression: Box<Expression>,
12426    #[serde(default)]
12427    pub params_struct: Option<Box<Expression>>,
12428}
12429
12430/// FeaturesAtTime
12431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12432#[cfg_attr(feature = "bindings", derive(TS))]
12433pub struct FeaturesAtTime {
12434    pub this: Box<Expression>,
12435    #[serde(default)]
12436    pub time: Option<Box<Expression>>,
12437    #[serde(default)]
12438    pub num_rows: Option<Box<Expression>>,
12439    #[serde(default)]
12440    pub ignore_feature_nulls: Option<Box<Expression>>,
12441}
12442
12443/// GenerateEmbedding
12444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12445#[cfg_attr(feature = "bindings", derive(TS))]
12446pub struct GenerateEmbedding {
12447    pub this: Box<Expression>,
12448    pub expression: Box<Expression>,
12449    #[serde(default)]
12450    pub params_struct: Option<Box<Expression>>,
12451    #[serde(default)]
12452    pub is_text: Option<Box<Expression>>,
12453}
12454
12455/// MLForecast
12456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12457#[cfg_attr(feature = "bindings", derive(TS))]
12458pub struct MLForecast {
12459    pub this: Box<Expression>,
12460    #[serde(default)]
12461    pub expression: Option<Box<Expression>>,
12462    #[serde(default)]
12463    pub params_struct: Option<Box<Expression>>,
12464}
12465
12466/// ModelAttribute
12467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12468#[cfg_attr(feature = "bindings", derive(TS))]
12469pub struct ModelAttribute {
12470    pub this: Box<Expression>,
12471    pub expression: Box<Expression>,
12472}
12473
12474/// VectorSearch
12475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12476#[cfg_attr(feature = "bindings", derive(TS))]
12477pub struct VectorSearch {
12478    pub this: Box<Expression>,
12479    #[serde(default)]
12480    pub column_to_search: Option<Box<Expression>>,
12481    #[serde(default)]
12482    pub query_table: Option<Box<Expression>>,
12483    #[serde(default)]
12484    pub query_column_to_search: Option<Box<Expression>>,
12485    #[serde(default)]
12486    pub top_k: Option<Box<Expression>>,
12487    #[serde(default)]
12488    pub distance_type: Option<Box<Expression>>,
12489    #[serde(default)]
12490    pub options: Vec<Expression>,
12491}
12492
12493/// Quantile
12494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12495#[cfg_attr(feature = "bindings", derive(TS))]
12496pub struct Quantile {
12497    pub this: Box<Expression>,
12498    #[serde(default)]
12499    pub quantile: Option<Box<Expression>>,
12500}
12501
12502/// ApproxQuantile
12503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12504#[cfg_attr(feature = "bindings", derive(TS))]
12505pub struct ApproxQuantile {
12506    pub this: Box<Expression>,
12507    #[serde(default)]
12508    pub quantile: Option<Box<Expression>>,
12509    #[serde(default)]
12510    pub accuracy: Option<Box<Expression>>,
12511    #[serde(default)]
12512    pub weight: Option<Box<Expression>>,
12513    #[serde(default)]
12514    pub error_tolerance: Option<Box<Expression>>,
12515}
12516
12517/// ApproxPercentileEstimate
12518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12519#[cfg_attr(feature = "bindings", derive(TS))]
12520pub struct ApproxPercentileEstimate {
12521    pub this: Box<Expression>,
12522    #[serde(default)]
12523    pub percentile: Option<Box<Expression>>,
12524}
12525
12526/// Randn
12527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12528#[cfg_attr(feature = "bindings", derive(TS))]
12529pub struct Randn {
12530    #[serde(default)]
12531    pub this: Option<Box<Expression>>,
12532}
12533
12534/// Randstr
12535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12536#[cfg_attr(feature = "bindings", derive(TS))]
12537pub struct Randstr {
12538    pub this: Box<Expression>,
12539    #[serde(default)]
12540    pub generator: Option<Box<Expression>>,
12541}
12542
12543/// RangeN
12544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12545#[cfg_attr(feature = "bindings", derive(TS))]
12546pub struct RangeN {
12547    pub this: Box<Expression>,
12548    #[serde(default)]
12549    pub expressions: Vec<Expression>,
12550    #[serde(default)]
12551    pub each: Option<Box<Expression>>,
12552}
12553
12554/// RangeBucket
12555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12556#[cfg_attr(feature = "bindings", derive(TS))]
12557pub struct RangeBucket {
12558    pub this: Box<Expression>,
12559    pub expression: Box<Expression>,
12560}
12561
12562/// ReadCSV
12563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12564#[cfg_attr(feature = "bindings", derive(TS))]
12565pub struct ReadCSV {
12566    pub this: Box<Expression>,
12567    #[serde(default)]
12568    pub expressions: Vec<Expression>,
12569}
12570
12571/// ReadParquet
12572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12573#[cfg_attr(feature = "bindings", derive(TS))]
12574pub struct ReadParquet {
12575    #[serde(default)]
12576    pub expressions: Vec<Expression>,
12577}
12578
12579/// Reduce
12580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12581#[cfg_attr(feature = "bindings", derive(TS))]
12582pub struct Reduce {
12583    pub this: Box<Expression>,
12584    #[serde(default)]
12585    pub initial: Option<Box<Expression>>,
12586    #[serde(default)]
12587    pub merge: Option<Box<Expression>>,
12588    #[serde(default)]
12589    pub finish: Option<Box<Expression>>,
12590}
12591
12592/// RegexpExtractAll
12593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12594#[cfg_attr(feature = "bindings", derive(TS))]
12595pub struct RegexpExtractAll {
12596    pub this: Box<Expression>,
12597    pub expression: Box<Expression>,
12598    #[serde(default)]
12599    pub group: Option<Box<Expression>>,
12600    #[serde(default)]
12601    pub parameters: Option<Box<Expression>>,
12602    #[serde(default)]
12603    pub position: Option<Box<Expression>>,
12604    #[serde(default)]
12605    pub occurrence: Option<Box<Expression>>,
12606}
12607
12608/// RegexpILike
12609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12610#[cfg_attr(feature = "bindings", derive(TS))]
12611pub struct RegexpILike {
12612    pub this: Box<Expression>,
12613    pub expression: Box<Expression>,
12614    #[serde(default)]
12615    pub flag: Option<Box<Expression>>,
12616}
12617
12618/// RegexpFullMatch
12619#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12620#[cfg_attr(feature = "bindings", derive(TS))]
12621pub struct RegexpFullMatch {
12622    pub this: Box<Expression>,
12623    pub expression: Box<Expression>,
12624    #[serde(default)]
12625    pub options: Vec<Expression>,
12626}
12627
12628/// RegexpInstr
12629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12630#[cfg_attr(feature = "bindings", derive(TS))]
12631pub struct RegexpInstr {
12632    pub this: Box<Expression>,
12633    pub expression: Box<Expression>,
12634    #[serde(default)]
12635    pub position: Option<Box<Expression>>,
12636    #[serde(default)]
12637    pub occurrence: Option<Box<Expression>>,
12638    #[serde(default)]
12639    pub option: Option<Box<Expression>>,
12640    #[serde(default)]
12641    pub parameters: Option<Box<Expression>>,
12642    #[serde(default)]
12643    pub group: Option<Box<Expression>>,
12644}
12645
12646/// RegexpSplit
12647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12648#[cfg_attr(feature = "bindings", derive(TS))]
12649pub struct RegexpSplit {
12650    pub this: Box<Expression>,
12651    pub expression: Box<Expression>,
12652    #[serde(default)]
12653    pub limit: Option<Box<Expression>>,
12654}
12655
12656/// RegexpCount
12657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12658#[cfg_attr(feature = "bindings", derive(TS))]
12659pub struct RegexpCount {
12660    pub this: Box<Expression>,
12661    pub expression: Box<Expression>,
12662    #[serde(default)]
12663    pub position: Option<Box<Expression>>,
12664    #[serde(default)]
12665    pub parameters: Option<Box<Expression>>,
12666}
12667
12668/// RegrValx
12669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12670#[cfg_attr(feature = "bindings", derive(TS))]
12671pub struct RegrValx {
12672    pub this: Box<Expression>,
12673    pub expression: Box<Expression>,
12674}
12675
12676/// RegrValy
12677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12678#[cfg_attr(feature = "bindings", derive(TS))]
12679pub struct RegrValy {
12680    pub this: Box<Expression>,
12681    pub expression: Box<Expression>,
12682}
12683
12684/// RegrAvgy
12685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12686#[cfg_attr(feature = "bindings", derive(TS))]
12687pub struct RegrAvgy {
12688    pub this: Box<Expression>,
12689    pub expression: Box<Expression>,
12690}
12691
12692/// RegrAvgx
12693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12694#[cfg_attr(feature = "bindings", derive(TS))]
12695pub struct RegrAvgx {
12696    pub this: Box<Expression>,
12697    pub expression: Box<Expression>,
12698}
12699
12700/// RegrCount
12701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12702#[cfg_attr(feature = "bindings", derive(TS))]
12703pub struct RegrCount {
12704    pub this: Box<Expression>,
12705    pub expression: Box<Expression>,
12706}
12707
12708/// RegrIntercept
12709#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12710#[cfg_attr(feature = "bindings", derive(TS))]
12711pub struct RegrIntercept {
12712    pub this: Box<Expression>,
12713    pub expression: Box<Expression>,
12714}
12715
12716/// RegrR2
12717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12718#[cfg_attr(feature = "bindings", derive(TS))]
12719pub struct RegrR2 {
12720    pub this: Box<Expression>,
12721    pub expression: Box<Expression>,
12722}
12723
12724/// RegrSxx
12725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12726#[cfg_attr(feature = "bindings", derive(TS))]
12727pub struct RegrSxx {
12728    pub this: Box<Expression>,
12729    pub expression: Box<Expression>,
12730}
12731
12732/// RegrSxy
12733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12734#[cfg_attr(feature = "bindings", derive(TS))]
12735pub struct RegrSxy {
12736    pub this: Box<Expression>,
12737    pub expression: Box<Expression>,
12738}
12739
12740/// RegrSyy
12741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12742#[cfg_attr(feature = "bindings", derive(TS))]
12743pub struct RegrSyy {
12744    pub this: Box<Expression>,
12745    pub expression: Box<Expression>,
12746}
12747
12748/// RegrSlope
12749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12750#[cfg_attr(feature = "bindings", derive(TS))]
12751pub struct RegrSlope {
12752    pub this: Box<Expression>,
12753    pub expression: Box<Expression>,
12754}
12755
12756/// SafeAdd
12757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12758#[cfg_attr(feature = "bindings", derive(TS))]
12759pub struct SafeAdd {
12760    pub this: Box<Expression>,
12761    pub expression: Box<Expression>,
12762}
12763
12764/// SafeDivide
12765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12766#[cfg_attr(feature = "bindings", derive(TS))]
12767pub struct SafeDivide {
12768    pub this: Box<Expression>,
12769    pub expression: Box<Expression>,
12770}
12771
12772/// SafeMultiply
12773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12774#[cfg_attr(feature = "bindings", derive(TS))]
12775pub struct SafeMultiply {
12776    pub this: Box<Expression>,
12777    pub expression: Box<Expression>,
12778}
12779
12780/// SafeSubtract
12781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12782#[cfg_attr(feature = "bindings", derive(TS))]
12783pub struct SafeSubtract {
12784    pub this: Box<Expression>,
12785    pub expression: Box<Expression>,
12786}
12787
12788/// SHA2
12789#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12790#[cfg_attr(feature = "bindings", derive(TS))]
12791pub struct SHA2 {
12792    pub this: Box<Expression>,
12793    #[serde(default)]
12794    pub length: Option<i64>,
12795}
12796
12797/// SHA2Digest
12798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12799#[cfg_attr(feature = "bindings", derive(TS))]
12800pub struct SHA2Digest {
12801    pub this: Box<Expression>,
12802    #[serde(default)]
12803    pub length: Option<i64>,
12804}
12805
12806/// SortArray
12807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12808#[cfg_attr(feature = "bindings", derive(TS))]
12809pub struct SortArray {
12810    pub this: Box<Expression>,
12811    #[serde(default)]
12812    pub asc: Option<Box<Expression>>,
12813    #[serde(default)]
12814    pub nulls_first: Option<Box<Expression>>,
12815}
12816
12817/// SplitPart
12818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12819#[cfg_attr(feature = "bindings", derive(TS))]
12820pub struct SplitPart {
12821    pub this: Box<Expression>,
12822    #[serde(default)]
12823    pub delimiter: Option<Box<Expression>>,
12824    #[serde(default)]
12825    pub part_index: Option<Box<Expression>>,
12826}
12827
12828/// SUBSTRING_INDEX(str, delim, count)
12829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12830#[cfg_attr(feature = "bindings", derive(TS))]
12831pub struct SubstringIndex {
12832    pub this: Box<Expression>,
12833    #[serde(default)]
12834    pub delimiter: Option<Box<Expression>>,
12835    #[serde(default)]
12836    pub count: Option<Box<Expression>>,
12837}
12838
12839/// StandardHash
12840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12841#[cfg_attr(feature = "bindings", derive(TS))]
12842pub struct StandardHash {
12843    pub this: Box<Expression>,
12844    #[serde(default)]
12845    pub expression: Option<Box<Expression>>,
12846}
12847
12848/// StrPosition
12849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12850#[cfg_attr(feature = "bindings", derive(TS))]
12851pub struct StrPosition {
12852    pub this: Box<Expression>,
12853    #[serde(default)]
12854    pub substr: Option<Box<Expression>>,
12855    #[serde(default)]
12856    pub position: Option<Box<Expression>>,
12857    #[serde(default)]
12858    pub occurrence: Option<Box<Expression>>,
12859}
12860
12861/// Search
12862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12863#[cfg_attr(feature = "bindings", derive(TS))]
12864pub struct Search {
12865    pub this: Box<Expression>,
12866    pub expression: Box<Expression>,
12867    #[serde(default)]
12868    pub json_scope: Option<Box<Expression>>,
12869    #[serde(default)]
12870    pub analyzer: Option<Box<Expression>>,
12871    #[serde(default)]
12872    pub analyzer_options: Option<Box<Expression>>,
12873    #[serde(default)]
12874    pub search_mode: Option<Box<Expression>>,
12875}
12876
12877/// SearchIp
12878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12879#[cfg_attr(feature = "bindings", derive(TS))]
12880pub struct SearchIp {
12881    pub this: Box<Expression>,
12882    pub expression: Box<Expression>,
12883}
12884
12885/// StrToDate
12886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12887#[cfg_attr(feature = "bindings", derive(TS))]
12888pub struct StrToDate {
12889    pub this: Box<Expression>,
12890    #[serde(default)]
12891    pub format: Option<String>,
12892    #[serde(default)]
12893    pub safe: Option<Box<Expression>>,
12894}
12895
12896/// StrToTime
12897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12898#[cfg_attr(feature = "bindings", derive(TS))]
12899pub struct StrToTime {
12900    pub this: Box<Expression>,
12901    pub format: String,
12902    #[serde(default)]
12903    pub zone: Option<Box<Expression>>,
12904    #[serde(default)]
12905    pub safe: Option<Box<Expression>>,
12906    #[serde(default)]
12907    pub target_type: Option<Box<Expression>>,
12908}
12909
12910/// StrToUnix
12911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12912#[cfg_attr(feature = "bindings", derive(TS))]
12913pub struct StrToUnix {
12914    #[serde(default)]
12915    pub this: Option<Box<Expression>>,
12916    #[serde(default)]
12917    pub format: Option<String>,
12918}
12919
12920/// StrToMap
12921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12922#[cfg_attr(feature = "bindings", derive(TS))]
12923pub struct StrToMap {
12924    pub this: Box<Expression>,
12925    #[serde(default)]
12926    pub pair_delim: Option<Box<Expression>>,
12927    #[serde(default)]
12928    pub key_value_delim: Option<Box<Expression>>,
12929    #[serde(default)]
12930    pub duplicate_resolution_callback: Option<Box<Expression>>,
12931}
12932
12933/// NumberToStr
12934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12935#[cfg_attr(feature = "bindings", derive(TS))]
12936pub struct NumberToStr {
12937    pub this: Box<Expression>,
12938    pub format: String,
12939    #[serde(default)]
12940    pub culture: Option<Box<Expression>>,
12941}
12942
12943/// FromBase
12944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12945#[cfg_attr(feature = "bindings", derive(TS))]
12946pub struct FromBase {
12947    pub this: Box<Expression>,
12948    pub expression: Box<Expression>,
12949}
12950
12951/// Stuff
12952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12953#[cfg_attr(feature = "bindings", derive(TS))]
12954pub struct Stuff {
12955    pub this: Box<Expression>,
12956    #[serde(default)]
12957    pub start: Option<Box<Expression>>,
12958    #[serde(default)]
12959    pub length: Option<i64>,
12960    pub expression: Box<Expression>,
12961}
12962
12963/// TimeToStr
12964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12965#[cfg_attr(feature = "bindings", derive(TS))]
12966pub struct TimeToStr {
12967    pub this: Box<Expression>,
12968    pub format: String,
12969    #[serde(default)]
12970    pub culture: Option<Box<Expression>>,
12971    #[serde(default)]
12972    pub zone: Option<Box<Expression>>,
12973}
12974
12975/// TimeStrToTime
12976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12977#[cfg_attr(feature = "bindings", derive(TS))]
12978pub struct TimeStrToTime {
12979    pub this: Box<Expression>,
12980    #[serde(default)]
12981    pub zone: Option<Box<Expression>>,
12982}
12983
12984/// TsOrDsAdd
12985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12986#[cfg_attr(feature = "bindings", derive(TS))]
12987pub struct TsOrDsAdd {
12988    pub this: Box<Expression>,
12989    pub expression: Box<Expression>,
12990    #[serde(default)]
12991    pub unit: Option<String>,
12992    #[serde(default)]
12993    pub return_type: Option<Box<Expression>>,
12994}
12995
12996/// TsOrDsDiff
12997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12998#[cfg_attr(feature = "bindings", derive(TS))]
12999pub struct TsOrDsDiff {
13000    pub this: Box<Expression>,
13001    pub expression: Box<Expression>,
13002    #[serde(default)]
13003    pub unit: Option<String>,
13004}
13005
13006/// TsOrDsToDate
13007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13008#[cfg_attr(feature = "bindings", derive(TS))]
13009pub struct TsOrDsToDate {
13010    pub this: Box<Expression>,
13011    #[serde(default)]
13012    pub format: Option<String>,
13013    #[serde(default)]
13014    pub safe: Option<Box<Expression>>,
13015}
13016
13017/// TsOrDsToTime
13018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13019#[cfg_attr(feature = "bindings", derive(TS))]
13020pub struct TsOrDsToTime {
13021    pub this: Box<Expression>,
13022    #[serde(default)]
13023    pub format: Option<String>,
13024    #[serde(default)]
13025    pub safe: Option<Box<Expression>>,
13026}
13027
13028/// Unhex
13029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13030#[cfg_attr(feature = "bindings", derive(TS))]
13031pub struct Unhex {
13032    pub this: Box<Expression>,
13033    #[serde(default)]
13034    pub expression: Option<Box<Expression>>,
13035}
13036
13037/// Uniform
13038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13039#[cfg_attr(feature = "bindings", derive(TS))]
13040pub struct Uniform {
13041    pub this: Box<Expression>,
13042    pub expression: Box<Expression>,
13043    #[serde(default)]
13044    pub gen: Option<Box<Expression>>,
13045    #[serde(default)]
13046    pub seed: Option<Box<Expression>>,
13047}
13048
13049/// UnixToStr
13050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13051#[cfg_attr(feature = "bindings", derive(TS))]
13052pub struct UnixToStr {
13053    pub this: Box<Expression>,
13054    #[serde(default)]
13055    pub format: Option<String>,
13056}
13057
13058/// UnixToTime
13059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13060#[cfg_attr(feature = "bindings", derive(TS))]
13061pub struct UnixToTime {
13062    pub this: Box<Expression>,
13063    #[serde(default)]
13064    pub scale: Option<i64>,
13065    #[serde(default)]
13066    pub zone: Option<Box<Expression>>,
13067    #[serde(default)]
13068    pub hours: Option<Box<Expression>>,
13069    #[serde(default)]
13070    pub minutes: Option<Box<Expression>>,
13071    #[serde(default)]
13072    pub format: Option<String>,
13073    #[serde(default)]
13074    pub target_type: Option<Box<Expression>>,
13075}
13076
13077/// Uuid
13078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13079#[cfg_attr(feature = "bindings", derive(TS))]
13080pub struct Uuid {
13081    #[serde(default)]
13082    pub this: Option<Box<Expression>>,
13083    #[serde(default)]
13084    pub name: Option<String>,
13085    #[serde(default)]
13086    pub is_string: Option<Box<Expression>>,
13087}
13088
13089/// TimestampFromParts
13090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13091#[cfg_attr(feature = "bindings", derive(TS))]
13092pub struct TimestampFromParts {
13093    #[serde(default)]
13094    pub zone: Option<Box<Expression>>,
13095    #[serde(default)]
13096    pub milli: Option<Box<Expression>>,
13097    #[serde(default)]
13098    pub this: Option<Box<Expression>>,
13099    #[serde(default)]
13100    pub expression: Option<Box<Expression>>,
13101}
13102
13103/// TimestampTzFromParts
13104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13105#[cfg_attr(feature = "bindings", derive(TS))]
13106pub struct TimestampTzFromParts {
13107    #[serde(default)]
13108    pub zone: Option<Box<Expression>>,
13109}
13110
13111/// Corr
13112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13113#[cfg_attr(feature = "bindings", derive(TS))]
13114pub struct Corr {
13115    pub this: Box<Expression>,
13116    pub expression: Box<Expression>,
13117    #[serde(default)]
13118    pub null_on_zero_variance: Option<Box<Expression>>,
13119}
13120
13121/// WidthBucket
13122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13123#[cfg_attr(feature = "bindings", derive(TS))]
13124pub struct WidthBucket {
13125    pub this: Box<Expression>,
13126    #[serde(default)]
13127    pub min_value: Option<Box<Expression>>,
13128    #[serde(default)]
13129    pub max_value: Option<Box<Expression>>,
13130    #[serde(default)]
13131    pub num_buckets: Option<Box<Expression>>,
13132    #[serde(default)]
13133    pub threshold: Option<Box<Expression>>,
13134}
13135
13136/// CovarSamp
13137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13138#[cfg_attr(feature = "bindings", derive(TS))]
13139pub struct CovarSamp {
13140    pub this: Box<Expression>,
13141    pub expression: Box<Expression>,
13142}
13143
13144/// CovarPop
13145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13146#[cfg_attr(feature = "bindings", derive(TS))]
13147pub struct CovarPop {
13148    pub this: Box<Expression>,
13149    pub expression: Box<Expression>,
13150}
13151
13152/// Week
13153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13154#[cfg_attr(feature = "bindings", derive(TS))]
13155pub struct Week {
13156    pub this: Box<Expression>,
13157    #[serde(default)]
13158    pub mode: Option<Box<Expression>>,
13159}
13160
13161/// XMLElement
13162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13163#[cfg_attr(feature = "bindings", derive(TS))]
13164pub struct XMLElement {
13165    pub this: Box<Expression>,
13166    #[serde(default)]
13167    pub expressions: Vec<Expression>,
13168    #[serde(default)]
13169    pub evalname: Option<Box<Expression>>,
13170}
13171
13172/// XMLGet
13173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13174#[cfg_attr(feature = "bindings", derive(TS))]
13175pub struct XMLGet {
13176    pub this: Box<Expression>,
13177    pub expression: Box<Expression>,
13178    #[serde(default)]
13179    pub instance: Option<Box<Expression>>,
13180}
13181
13182/// XMLTable
13183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13184#[cfg_attr(feature = "bindings", derive(TS))]
13185pub struct XMLTable {
13186    pub this: Box<Expression>,
13187    #[serde(default)]
13188    pub namespaces: Option<Box<Expression>>,
13189    #[serde(default)]
13190    pub passing: Option<Box<Expression>>,
13191    #[serde(default)]
13192    pub columns: Vec<Expression>,
13193    #[serde(default)]
13194    pub by_ref: Option<Box<Expression>>,
13195}
13196
13197/// XMLKeyValueOption
13198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13199#[cfg_attr(feature = "bindings", derive(TS))]
13200pub struct XMLKeyValueOption {
13201    pub this: Box<Expression>,
13202    #[serde(default)]
13203    pub expression: Option<Box<Expression>>,
13204}
13205
13206/// Zipf
13207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13208#[cfg_attr(feature = "bindings", derive(TS))]
13209pub struct Zipf {
13210    pub this: Box<Expression>,
13211    #[serde(default)]
13212    pub elementcount: Option<Box<Expression>>,
13213    #[serde(default)]
13214    pub gen: Option<Box<Expression>>,
13215}
13216
13217/// Merge
13218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13219#[cfg_attr(feature = "bindings", derive(TS))]
13220pub struct Merge {
13221    pub this: Box<Expression>,
13222    pub using: Box<Expression>,
13223    #[serde(default)]
13224    pub on: Option<Box<Expression>>,
13225    #[serde(default)]
13226    pub using_cond: Option<Box<Expression>>,
13227    #[serde(default)]
13228    pub whens: Option<Box<Expression>>,
13229    #[serde(default)]
13230    pub with_: Option<Box<Expression>>,
13231    #[serde(default)]
13232    pub returning: Option<Box<Expression>>,
13233}
13234
13235/// When
13236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13237#[cfg_attr(feature = "bindings", derive(TS))]
13238pub struct When {
13239    #[serde(default)]
13240    pub matched: Option<Box<Expression>>,
13241    #[serde(default)]
13242    pub source: Option<Box<Expression>>,
13243    #[serde(default)]
13244    pub condition: Option<Box<Expression>>,
13245    pub then: Box<Expression>,
13246}
13247
13248/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
13249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13250#[cfg_attr(feature = "bindings", derive(TS))]
13251pub struct Whens {
13252    #[serde(default)]
13253    pub expressions: Vec<Expression>,
13254}
13255
13256/// NextValueFor
13257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13258#[cfg_attr(feature = "bindings", derive(TS))]
13259pub struct NextValueFor {
13260    pub this: Box<Expression>,
13261    #[serde(default)]
13262    pub order: Option<Box<Expression>>,
13263}
13264
13265#[cfg(test)]
13266mod tests {
13267    use super::*;
13268
13269    #[test]
13270    #[cfg(feature = "bindings")]
13271    fn export_typescript_types() {
13272        // This test exports TypeScript types to the generated directory
13273        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
13274        Expression::export_all(&ts_rs::Config::default())
13275            .expect("Failed to export Expression types");
13276    }
13277
13278    #[test]
13279    fn test_simple_select_builder() {
13280        let select = Select::new()
13281            .column(Expression::star())
13282            .from(Expression::Table(TableRef::new("users")));
13283
13284        assert_eq!(select.expressions.len(), 1);
13285        assert!(select.from.is_some());
13286    }
13287
13288    #[test]
13289    fn test_expression_alias() {
13290        let expr = Expression::column("id").alias("user_id");
13291
13292        match expr {
13293            Expression::Alias(a) => {
13294                assert_eq!(a.alias.name, "user_id");
13295            }
13296            _ => panic!("Expected Alias"),
13297        }
13298    }
13299
13300    #[test]
13301    fn test_literal_creation() {
13302        let num = Expression::number(42);
13303        let str = Expression::string("hello");
13304
13305        match num {
13306            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
13307            _ => panic!("Expected Number"),
13308        }
13309
13310        match str {
13311            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
13312            _ => panic!("Expected String"),
13313        }
13314    }
13315
13316    #[test]
13317    fn test_expression_sql() {
13318        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
13319        assert_eq!(expr.sql(), "SELECT 1 + 2");
13320    }
13321
13322    #[test]
13323    fn test_expression_sql_for() {
13324        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
13325        let sql = expr.sql_for(crate::DialectType::Generic);
13326        // Generic mode normalizes IF() to CASE WHEN
13327        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
13328    }
13329}