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
1295            // UnaryFunc variants
1296            Expression::Upper(f)
1297            | Expression::Lower(f)
1298            | Expression::Length(f)
1299            | Expression::LTrim(f)
1300            | Expression::RTrim(f)
1301            | Expression::Reverse(f)
1302            | Expression::Abs(f)
1303            | Expression::Sqrt(f)
1304            | Expression::Cbrt(f)
1305            | Expression::Ln(f)
1306            | Expression::Exp(f)
1307            | Expression::Sign(f)
1308            | Expression::Date(f)
1309            | Expression::Time(f)
1310            | Expression::Initcap(f)
1311            | Expression::Ascii(f)
1312            | Expression::Chr(f)
1313            | Expression::Soundex(f)
1314            | Expression::ByteLength(f)
1315            | Expression::Hex(f)
1316            | Expression::LowerHex(f)
1317            | Expression::Unicode(f)
1318            | Expression::Typeof(f)
1319            | Expression::Explode(f)
1320            | Expression::ExplodeOuter(f)
1321            | Expression::MapFromEntries(f)
1322            | Expression::MapKeys(f)
1323            | Expression::MapValues(f)
1324            | Expression::ArrayLength(f)
1325            | Expression::ArraySize(f)
1326            | Expression::Cardinality(f)
1327            | Expression::ArrayReverse(f)
1328            | Expression::ArrayDistinct(f)
1329            | Expression::ArrayFlatten(f)
1330            | Expression::ArrayCompact(f)
1331            | Expression::ToArray(f)
1332            | Expression::JsonArrayLength(f)
1333            | Expression::JsonKeys(f)
1334            | Expression::JsonType(f)
1335            | Expression::ParseJson(f)
1336            | Expression::ToJson(f)
1337            | Expression::Radians(f)
1338            | Expression::Degrees(f)
1339            | Expression::Sin(f)
1340            | Expression::Cos(f)
1341            | Expression::Tan(f)
1342            | Expression::Asin(f)
1343            | Expression::Acos(f)
1344            | Expression::Atan(f)
1345            | Expression::IsNan(f)
1346            | Expression::IsInf(f)
1347            | Expression::Year(f)
1348            | Expression::Month(f)
1349            | Expression::Day(f)
1350            | Expression::Hour(f)
1351            | Expression::Minute(f)
1352            | Expression::Second(f)
1353            | Expression::DayOfWeek(f)
1354            | Expression::DayOfWeekIso(f)
1355            | Expression::DayOfMonth(f)
1356            | Expression::DayOfYear(f)
1357            | Expression::WeekOfYear(f)
1358            | Expression::Quarter(f)
1359            | Expression::Epoch(f)
1360            | Expression::EpochMs(f)
1361            | Expression::BitwiseCount(f)
1362            | Expression::DateFromUnixDate(f)
1363            | Expression::UnixDate(f)
1364            | Expression::UnixSeconds(f)
1365            | Expression::UnixMillis(f)
1366            | Expression::UnixMicros(f)
1367            | Expression::TimeStrToDate(f)
1368            | Expression::DateToDi(f)
1369            | Expression::DiToDate(f)
1370            | Expression::TsOrDiToDi(f)
1371            | Expression::TsOrDsToDatetime(f)
1372            | Expression::TsOrDsToTimestamp(f)
1373            | Expression::YearOfWeek(f)
1374            | Expression::YearOfWeekIso(f)
1375            | Expression::SHA(f)
1376            | Expression::SHA1Digest(f)
1377            | Expression::TimeToUnix(f)
1378            | Expression::TimeStrToUnix(f) => f.inferred_type.as_ref(),
1379
1380            // BinaryFunc variants
1381            Expression::Power(f)
1382            | Expression::NullIf(f)
1383            | Expression::IfNull(f)
1384            | Expression::Nvl(f)
1385            | Expression::Contains(f)
1386            | Expression::StartsWith(f)
1387            | Expression::EndsWith(f)
1388            | Expression::Levenshtein(f)
1389            | Expression::ModFunc(f)
1390            | Expression::IntDiv(f)
1391            | Expression::Atan2(f)
1392            | Expression::AddMonths(f)
1393            | Expression::MonthsBetween(f)
1394            | Expression::NextDay(f)
1395            | Expression::UnixToTimeStr(f)
1396            | Expression::ArrayContains(f)
1397            | Expression::ArrayPosition(f)
1398            | Expression::ArrayAppend(f)
1399            | Expression::ArrayPrepend(f)
1400            | Expression::ArrayUnion(f)
1401            | Expression::ArrayExcept(f)
1402            | Expression::ArrayRemove(f)
1403            | Expression::StarMap(f)
1404            | Expression::MapFromArrays(f)
1405            | Expression::MapContainsKey(f)
1406            | Expression::ElementAt(f)
1407            | Expression::JsonMergePatch(f) => f.inferred_type.as_ref(),
1408
1409            // VarArgFunc variants
1410            Expression::Coalesce(f)
1411            | Expression::Greatest(f)
1412            | Expression::Least(f)
1413            | Expression::ArrayConcat(f)
1414            | Expression::ArrayIntersect(f)
1415            | Expression::ArrayZip(f)
1416            | Expression::MapConcat(f)
1417            | Expression::JsonArray(f) => f.inferred_type.as_ref(),
1418
1419            // AggFunc variants
1420            Expression::Sum(f)
1421            | Expression::Avg(f)
1422            | Expression::Min(f)
1423            | Expression::Max(f)
1424            | Expression::ArrayAgg(f)
1425            | Expression::CountIf(f)
1426            | Expression::Stddev(f)
1427            | Expression::StddevPop(f)
1428            | Expression::StddevSamp(f)
1429            | Expression::Variance(f)
1430            | Expression::VarPop(f)
1431            | Expression::VarSamp(f)
1432            | Expression::Median(f)
1433            | Expression::Mode(f)
1434            | Expression::First(f)
1435            | Expression::Last(f)
1436            | Expression::AnyValue(f)
1437            | Expression::ApproxDistinct(f)
1438            | Expression::ApproxCountDistinct(f)
1439            | Expression::LogicalAnd(f)
1440            | Expression::LogicalOr(f)
1441            | Expression::Skewness(f)
1442            | Expression::ArrayConcatAgg(f)
1443            | Expression::ArrayUniqueAgg(f)
1444            | Expression::BoolXorAgg(f)
1445            | Expression::BitwiseAndAgg(f)
1446            | Expression::BitwiseOrAgg(f)
1447            | Expression::BitwiseXorAgg(f) => f.inferred_type.as_ref(),
1448
1449            // Everything else: no inferred_type field
1450            _ => None,
1451        }
1452    }
1453
1454    /// Set the inferred type annotation on this expression.
1455    ///
1456    /// Only has an effect on value-producing expressions with an `inferred_type`
1457    /// field. For other expression types, this is a no-op.
1458    pub fn set_inferred_type(&mut self, dt: DataType) {
1459        match self {
1460            Expression::And(op)
1461            | Expression::Or(op)
1462            | Expression::Add(op)
1463            | Expression::Sub(op)
1464            | Expression::Mul(op)
1465            | Expression::Div(op)
1466            | Expression::Mod(op)
1467            | Expression::Eq(op)
1468            | Expression::Neq(op)
1469            | Expression::Lt(op)
1470            | Expression::Lte(op)
1471            | Expression::Gt(op)
1472            | Expression::Gte(op)
1473            | Expression::Concat(op)
1474            | Expression::BitwiseAnd(op)
1475            | Expression::BitwiseOr(op)
1476            | Expression::BitwiseXor(op)
1477            | Expression::Adjacent(op)
1478            | Expression::TsMatch(op)
1479            | Expression::PropertyEQ(op)
1480            | Expression::ArrayContainsAll(op)
1481            | Expression::ArrayContainedBy(op)
1482            | Expression::ArrayOverlaps(op)
1483            | Expression::JSONBContainsAllTopKeys(op)
1484            | Expression::JSONBContainsAnyTopKeys(op)
1485            | Expression::JSONBDeleteAtPath(op)
1486            | Expression::ExtendsLeft(op)
1487            | Expression::ExtendsRight(op)
1488            | Expression::Is(op)
1489            | Expression::MemberOf(op)
1490            | Expression::Match(op)
1491            | Expression::NullSafeEq(op)
1492            | Expression::NullSafeNeq(op)
1493            | Expression::Glob(op)
1494            | Expression::BitwiseLeftShift(op)
1495            | Expression::BitwiseRightShift(op) => op.inferred_type = Some(dt),
1496
1497            Expression::Not(op) | Expression::Neg(op) | Expression::BitwiseNot(op) => {
1498                op.inferred_type = Some(dt)
1499            }
1500
1501            Expression::Like(op) | Expression::ILike(op) => op.inferred_type = Some(dt),
1502
1503            Expression::Cast(c) | Expression::TryCast(c) | Expression::SafeCast(c) => {
1504                c.inferred_type = Some(dt)
1505            }
1506
1507            Expression::Column(c) => c.inferred_type = Some(dt),
1508            Expression::Function(f) => f.inferred_type = Some(dt),
1509            Expression::AggregateFunction(f) => f.inferred_type = Some(dt),
1510            Expression::WindowFunction(f) => f.inferred_type = Some(dt),
1511            Expression::Case(c) => c.inferred_type = Some(dt),
1512            Expression::Subquery(s) => s.inferred_type = Some(dt),
1513            Expression::Alias(a) => a.inferred_type = Some(dt),
1514
1515            // UnaryFunc variants
1516            Expression::Upper(f)
1517            | Expression::Lower(f)
1518            | Expression::Length(f)
1519            | Expression::LTrim(f)
1520            | Expression::RTrim(f)
1521            | Expression::Reverse(f)
1522            | Expression::Abs(f)
1523            | Expression::Sqrt(f)
1524            | Expression::Cbrt(f)
1525            | Expression::Ln(f)
1526            | Expression::Exp(f)
1527            | Expression::Sign(f)
1528            | Expression::Date(f)
1529            | Expression::Time(f)
1530            | Expression::Initcap(f)
1531            | Expression::Ascii(f)
1532            | Expression::Chr(f)
1533            | Expression::Soundex(f)
1534            | Expression::ByteLength(f)
1535            | Expression::Hex(f)
1536            | Expression::LowerHex(f)
1537            | Expression::Unicode(f)
1538            | Expression::Typeof(f)
1539            | Expression::Explode(f)
1540            | Expression::ExplodeOuter(f)
1541            | Expression::MapFromEntries(f)
1542            | Expression::MapKeys(f)
1543            | Expression::MapValues(f)
1544            | Expression::ArrayLength(f)
1545            | Expression::ArraySize(f)
1546            | Expression::Cardinality(f)
1547            | Expression::ArrayReverse(f)
1548            | Expression::ArrayDistinct(f)
1549            | Expression::ArrayFlatten(f)
1550            | Expression::ArrayCompact(f)
1551            | Expression::ToArray(f)
1552            | Expression::JsonArrayLength(f)
1553            | Expression::JsonKeys(f)
1554            | Expression::JsonType(f)
1555            | Expression::ParseJson(f)
1556            | Expression::ToJson(f)
1557            | Expression::Radians(f)
1558            | Expression::Degrees(f)
1559            | Expression::Sin(f)
1560            | Expression::Cos(f)
1561            | Expression::Tan(f)
1562            | Expression::Asin(f)
1563            | Expression::Acos(f)
1564            | Expression::Atan(f)
1565            | Expression::IsNan(f)
1566            | Expression::IsInf(f)
1567            | Expression::Year(f)
1568            | Expression::Month(f)
1569            | Expression::Day(f)
1570            | Expression::Hour(f)
1571            | Expression::Minute(f)
1572            | Expression::Second(f)
1573            | Expression::DayOfWeek(f)
1574            | Expression::DayOfWeekIso(f)
1575            | Expression::DayOfMonth(f)
1576            | Expression::DayOfYear(f)
1577            | Expression::WeekOfYear(f)
1578            | Expression::Quarter(f)
1579            | Expression::Epoch(f)
1580            | Expression::EpochMs(f)
1581            | Expression::BitwiseCount(f)
1582            | Expression::DateFromUnixDate(f)
1583            | Expression::UnixDate(f)
1584            | Expression::UnixSeconds(f)
1585            | Expression::UnixMillis(f)
1586            | Expression::UnixMicros(f)
1587            | Expression::TimeStrToDate(f)
1588            | Expression::DateToDi(f)
1589            | Expression::DiToDate(f)
1590            | Expression::TsOrDiToDi(f)
1591            | Expression::TsOrDsToDatetime(f)
1592            | Expression::TsOrDsToTimestamp(f)
1593            | Expression::YearOfWeek(f)
1594            | Expression::YearOfWeekIso(f)
1595            | Expression::SHA(f)
1596            | Expression::SHA1Digest(f)
1597            | Expression::TimeToUnix(f)
1598            | Expression::TimeStrToUnix(f) => f.inferred_type = Some(dt),
1599
1600            // BinaryFunc variants
1601            Expression::Power(f)
1602            | Expression::NullIf(f)
1603            | Expression::IfNull(f)
1604            | Expression::Nvl(f)
1605            | Expression::Contains(f)
1606            | Expression::StartsWith(f)
1607            | Expression::EndsWith(f)
1608            | Expression::Levenshtein(f)
1609            | Expression::ModFunc(f)
1610            | Expression::IntDiv(f)
1611            | Expression::Atan2(f)
1612            | Expression::AddMonths(f)
1613            | Expression::MonthsBetween(f)
1614            | Expression::NextDay(f)
1615            | Expression::UnixToTimeStr(f)
1616            | Expression::ArrayContains(f)
1617            | Expression::ArrayPosition(f)
1618            | Expression::ArrayAppend(f)
1619            | Expression::ArrayPrepend(f)
1620            | Expression::ArrayUnion(f)
1621            | Expression::ArrayExcept(f)
1622            | Expression::ArrayRemove(f)
1623            | Expression::StarMap(f)
1624            | Expression::MapFromArrays(f)
1625            | Expression::MapContainsKey(f)
1626            | Expression::ElementAt(f)
1627            | Expression::JsonMergePatch(f) => f.inferred_type = Some(dt),
1628
1629            // VarArgFunc variants
1630            Expression::Coalesce(f)
1631            | Expression::Greatest(f)
1632            | Expression::Least(f)
1633            | Expression::ArrayConcat(f)
1634            | Expression::ArrayIntersect(f)
1635            | Expression::ArrayZip(f)
1636            | Expression::MapConcat(f)
1637            | Expression::JsonArray(f) => f.inferred_type = Some(dt),
1638
1639            // AggFunc variants
1640            Expression::Sum(f)
1641            | Expression::Avg(f)
1642            | Expression::Min(f)
1643            | Expression::Max(f)
1644            | Expression::ArrayAgg(f)
1645            | Expression::CountIf(f)
1646            | Expression::Stddev(f)
1647            | Expression::StddevPop(f)
1648            | Expression::StddevSamp(f)
1649            | Expression::Variance(f)
1650            | Expression::VarPop(f)
1651            | Expression::VarSamp(f)
1652            | Expression::Median(f)
1653            | Expression::Mode(f)
1654            | Expression::First(f)
1655            | Expression::Last(f)
1656            | Expression::AnyValue(f)
1657            | Expression::ApproxDistinct(f)
1658            | Expression::ApproxCountDistinct(f)
1659            | Expression::LogicalAnd(f)
1660            | Expression::LogicalOr(f)
1661            | Expression::Skewness(f)
1662            | Expression::ArrayConcatAgg(f)
1663            | Expression::ArrayUniqueAgg(f)
1664            | Expression::BoolXorAgg(f)
1665            | Expression::BitwiseAndAgg(f)
1666            | Expression::BitwiseOrAgg(f)
1667            | Expression::BitwiseXorAgg(f) => f.inferred_type = Some(dt),
1668
1669            // Expressions without inferred_type field - no-op
1670            _ => {}
1671        }
1672    }
1673
1674    /// Create an unqualified column reference (e.g. `name`).
1675    pub fn column(name: impl Into<String>) -> Self {
1676        Expression::Column(Column {
1677            name: Identifier::new(name),
1678            table: None,
1679            join_mark: false,
1680            trailing_comments: Vec::new(),
1681            span: None,
1682            inferred_type: None,
1683        })
1684    }
1685
1686    /// Create a qualified column reference (`table.column`).
1687    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1688        Expression::Column(Column {
1689            name: Identifier::new(column),
1690            table: Some(Identifier::new(table)),
1691            join_mark: false,
1692            trailing_comments: Vec::new(),
1693            span: None,
1694            inferred_type: None,
1695        })
1696    }
1697
1698    /// Create a bare identifier expression (not a column reference).
1699    pub fn identifier(name: impl Into<String>) -> Self {
1700        Expression::Identifier(Identifier::new(name))
1701    }
1702
1703    /// Create a NULL expression
1704    pub fn null() -> Self {
1705        Expression::Null(Null)
1706    }
1707
1708    /// Create a TRUE expression
1709    pub fn true_() -> Self {
1710        Expression::Boolean(BooleanLiteral { value: true })
1711    }
1712
1713    /// Create a FALSE expression
1714    pub fn false_() -> Self {
1715        Expression::Boolean(BooleanLiteral { value: false })
1716    }
1717
1718    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1719    pub fn star() -> Self {
1720        Expression::Star(Star {
1721            table: None,
1722            except: None,
1723            replace: None,
1724            rename: None,
1725            trailing_comments: Vec::new(),
1726            span: None,
1727        })
1728    }
1729
1730    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1731    pub fn alias(self, name: impl Into<String>) -> Self {
1732        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1733    }
1734
1735    /// Check if this is a SELECT expression
1736    pub fn is_select(&self) -> bool {
1737        matches!(self, Expression::Select(_))
1738    }
1739
1740    /// Try to get as a Select
1741    pub fn as_select(&self) -> Option<&Select> {
1742        match self {
1743            Expression::Select(s) => Some(s),
1744            _ => None,
1745        }
1746    }
1747
1748    /// Try to get as a mutable Select
1749    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1750        match self {
1751            Expression::Select(s) => Some(s),
1752            _ => None,
1753        }
1754    }
1755
1756    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1757    ///
1758    /// Returns an empty string if generation fails. For dialect-specific output,
1759    /// use [`sql_for()`](Self::sql_for) instead.
1760    pub fn sql(&self) -> String {
1761        crate::generator::Generator::sql(self).unwrap_or_default()
1762    }
1763
1764    /// Generate a SQL string for this expression targeting a specific dialect.
1765    ///
1766    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1767    /// syntax variations) are applied automatically.  Returns an empty string if
1768    /// generation fails.
1769    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1770        crate::generate(self, dialect).unwrap_or_default()
1771    }
1772}
1773
1774impl fmt::Display for Expression {
1775    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1776        // Basic display - full SQL generation is in generator module
1777        match self {
1778            Expression::Literal(lit) => write!(f, "{}", lit),
1779            Expression::Identifier(id) => write!(f, "{}", id),
1780            Expression::Column(col) => write!(f, "{}", col),
1781            Expression::Star(_) => write!(f, "*"),
1782            Expression::Null(_) => write!(f, "NULL"),
1783            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1784            Expression::Select(_) => write!(f, "SELECT ..."),
1785            _ => write!(f, "{:?}", self),
1786        }
1787    }
1788}
1789
1790/// Represent a SQL literal value.
1791///
1792/// Numeric values are stored as their original text representation (not parsed
1793/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1794/// preserved across round-trips.
1795///
1796/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1797/// strings, raw strings, etc.) each have a dedicated variant so that the
1798/// generator can emit them with the correct syntax.
1799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1800#[cfg_attr(feature = "bindings", derive(TS))]
1801#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1802pub enum Literal {
1803    /// Single-quoted string literal: `'hello'`
1804    String(String),
1805    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1806    Number(String),
1807    /// Hex string literal: `X'FF'`
1808    HexString(String),
1809    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1810    HexNumber(String),
1811    BitString(String),
1812    /// Byte string: b"..." (BigQuery style)
1813    ByteString(String),
1814    /// National string: N'abc'
1815    NationalString(String),
1816    /// DATE literal: DATE '2024-01-15'
1817    Date(String),
1818    /// TIME literal: TIME '10:30:00'
1819    Time(String),
1820    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1821    Timestamp(String),
1822    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1823    Datetime(String),
1824    /// Triple-quoted string: """...""" or '''...'''
1825    /// Contains (content, quote_char) where quote_char is '"' or '\''
1826    TripleQuotedString(String, char),
1827    /// Escape string: E'...' (PostgreSQL)
1828    EscapeString(String),
1829    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1830    DollarString(String),
1831    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1832    /// In raw strings, backslashes are literal and not escape characters.
1833    /// When converting to a regular string, backslashes must be doubled.
1834    RawString(String),
1835}
1836
1837impl fmt::Display for Literal {
1838    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1839        match self {
1840            Literal::String(s) => write!(f, "'{}'", s),
1841            Literal::Number(n) => write!(f, "{}", n),
1842            Literal::HexString(h) => write!(f, "X'{}'", h),
1843            Literal::HexNumber(h) => write!(f, "0x{}", h),
1844            Literal::BitString(b) => write!(f, "B'{}'", b),
1845            Literal::ByteString(b) => write!(f, "b'{}'", b),
1846            Literal::NationalString(s) => write!(f, "N'{}'", s),
1847            Literal::Date(d) => write!(f, "DATE '{}'", d),
1848            Literal::Time(t) => write!(f, "TIME '{}'", t),
1849            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1850            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1851            Literal::TripleQuotedString(s, q) => {
1852                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1853            }
1854            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1855            Literal::DollarString(s) => write!(f, "$${}$$", s),
1856            Literal::RawString(s) => write!(f, "r'{}'", s),
1857        }
1858    }
1859}
1860
1861/// Boolean literal
1862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1863#[cfg_attr(feature = "bindings", derive(TS))]
1864pub struct BooleanLiteral {
1865    pub value: bool,
1866}
1867
1868/// NULL literal
1869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1870#[cfg_attr(feature = "bindings", derive(TS))]
1871pub struct Null;
1872
1873/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1874///
1875/// The `quoted` flag indicates whether the identifier was originally delimited
1876/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1877/// dialect). The generator uses this flag to decide whether to emit quoting
1878/// characters.
1879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1880#[cfg_attr(feature = "bindings", derive(TS))]
1881pub struct Identifier {
1882    /// The raw text of the identifier, without any quoting characters.
1883    pub name: String,
1884    /// Whether the identifier was quoted in the source SQL.
1885    pub quoted: bool,
1886    #[serde(default)]
1887    pub trailing_comments: Vec<String>,
1888    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1889    #[serde(default, skip_serializing_if = "Option::is_none")]
1890    pub span: Option<Span>,
1891}
1892
1893impl Identifier {
1894    pub fn new(name: impl Into<String>) -> Self {
1895        Self {
1896            name: name.into(),
1897            quoted: false,
1898            trailing_comments: Vec::new(),
1899            span: None,
1900        }
1901    }
1902
1903    pub fn quoted(name: impl Into<String>) -> Self {
1904        Self {
1905            name: name.into(),
1906            quoted: true,
1907            trailing_comments: Vec::new(),
1908            span: None,
1909        }
1910    }
1911
1912    pub fn empty() -> Self {
1913        Self {
1914            name: String::new(),
1915            quoted: false,
1916            trailing_comments: Vec::new(),
1917            span: None,
1918        }
1919    }
1920
1921    pub fn is_empty(&self) -> bool {
1922        self.name.is_empty()
1923    }
1924
1925    /// Set the source span on this identifier
1926    pub fn with_span(mut self, span: Span) -> Self {
1927        self.span = Some(span);
1928        self
1929    }
1930}
1931
1932impl fmt::Display for Identifier {
1933    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1934        if self.quoted {
1935            write!(f, "\"{}\"", self.name)
1936        } else {
1937            write!(f, "{}", self.name)
1938        }
1939    }
1940}
1941
1942/// Represent a column reference, optionally qualified by a table name.
1943///
1944/// Renders as `name` when unqualified, or `table.name` when qualified.
1945/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1946/// convenient construction.
1947#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1948#[cfg_attr(feature = "bindings", derive(TS))]
1949pub struct Column {
1950    /// The column name.
1951    pub name: Identifier,
1952    /// Optional table qualifier (e.g. `t` in `t.col`).
1953    pub table: Option<Identifier>,
1954    /// Oracle-style join marker (+) for outer joins
1955    #[serde(default)]
1956    pub join_mark: bool,
1957    /// Trailing comments that appeared after this column reference
1958    #[serde(default)]
1959    pub trailing_comments: Vec<String>,
1960    /// Source position span
1961    #[serde(default, skip_serializing_if = "Option::is_none")]
1962    pub span: Option<Span>,
1963    /// Inferred data type from type annotation
1964    #[serde(default, skip_serializing_if = "Option::is_none")]
1965    pub inferred_type: Option<DataType>,
1966}
1967
1968impl fmt::Display for Column {
1969    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1970        if let Some(table) = &self.table {
1971            write!(f, "{}.{}", table, self.name)
1972        } else {
1973            write!(f, "{}", self.name)
1974        }
1975    }
1976}
1977
1978/// Represent a table reference with optional schema and catalog qualifiers.
1979///
1980/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1981/// which qualifiers are present. Supports aliases, column alias lists,
1982/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1983/// several other dialect-specific extensions.
1984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1985#[cfg_attr(feature = "bindings", derive(TS))]
1986pub struct TableRef {
1987    /// The unqualified table name.
1988    pub name: Identifier,
1989    /// Optional schema qualifier (e.g. `public` in `public.users`).
1990    pub schema: Option<Identifier>,
1991    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
1992    pub catalog: Option<Identifier>,
1993    /// Optional table alias (e.g. `t` in `FROM users AS t`).
1994    pub alias: Option<Identifier>,
1995    /// Whether AS keyword was explicitly used for the alias
1996    #[serde(default)]
1997    pub alias_explicit_as: bool,
1998    /// Column aliases for table alias: AS t(c1, c2)
1999    #[serde(default)]
2000    pub column_aliases: Vec<Identifier>,
2001    /// Trailing comments that appeared after this table reference
2002    #[serde(default)]
2003    pub trailing_comments: Vec<String>,
2004    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2005    #[serde(default)]
2006    pub when: Option<Box<HistoricalData>>,
2007    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
2008    #[serde(default)]
2009    pub only: bool,
2010    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
2011    #[serde(default)]
2012    pub final_: bool,
2013    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
2014    #[serde(default, skip_serializing_if = "Option::is_none")]
2015    pub table_sample: Option<Box<Sample>>,
2016    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
2017    #[serde(default)]
2018    pub hints: Vec<Expression>,
2019    /// TSQL: FOR SYSTEM_TIME temporal clause
2020    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
2021    #[serde(default, skip_serializing_if = "Option::is_none")]
2022    pub system_time: Option<String>,
2023    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
2024    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2025    pub partitions: Vec<Identifier>,
2026    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
2027    /// When set, this is used instead of the name field
2028    #[serde(default, skip_serializing_if = "Option::is_none")]
2029    pub identifier_func: Option<Box<Expression>>,
2030    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
2031    #[serde(default, skip_serializing_if = "Option::is_none")]
2032    pub changes: Option<Box<Changes>>,
2033    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
2034    #[serde(default, skip_serializing_if = "Option::is_none")]
2035    pub version: Option<Box<Version>>,
2036    /// Source position span
2037    #[serde(default, skip_serializing_if = "Option::is_none")]
2038    pub span: Option<Span>,
2039}
2040
2041impl TableRef {
2042    pub fn new(name: impl Into<String>) -> Self {
2043        Self {
2044            name: Identifier::new(name),
2045            schema: None,
2046            catalog: None,
2047            alias: None,
2048            alias_explicit_as: false,
2049            column_aliases: Vec::new(),
2050            trailing_comments: Vec::new(),
2051            when: None,
2052            only: false,
2053            final_: false,
2054            table_sample: None,
2055            hints: Vec::new(),
2056            system_time: None,
2057            partitions: Vec::new(),
2058            identifier_func: None,
2059            changes: None,
2060            version: None,
2061            span: None,
2062        }
2063    }
2064
2065    /// Create with a schema qualifier.
2066    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
2067        let mut t = Self::new(name);
2068        t.schema = Some(Identifier::new(schema));
2069        t
2070    }
2071
2072    /// Create with catalog and schema qualifiers.
2073    pub fn new_with_catalog(
2074        name: impl Into<String>,
2075        schema: impl Into<String>,
2076        catalog: impl Into<String>,
2077    ) -> Self {
2078        let mut t = Self::new(name);
2079        t.schema = Some(Identifier::new(schema));
2080        t.catalog = Some(Identifier::new(catalog));
2081        t
2082    }
2083
2084    /// Create from an Identifier, preserving the quoted flag
2085    pub fn from_identifier(name: Identifier) -> Self {
2086        Self {
2087            name,
2088            schema: None,
2089            catalog: None,
2090            alias: None,
2091            alias_explicit_as: false,
2092            column_aliases: Vec::new(),
2093            trailing_comments: Vec::new(),
2094            when: None,
2095            only: false,
2096            final_: false,
2097            table_sample: None,
2098            hints: Vec::new(),
2099            system_time: None,
2100            partitions: Vec::new(),
2101            identifier_func: None,
2102            changes: None,
2103            version: None,
2104            span: None,
2105        }
2106    }
2107
2108    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
2109        self.alias = Some(Identifier::new(alias));
2110        self
2111    }
2112
2113    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
2114        self.schema = Some(Identifier::new(schema));
2115        self
2116    }
2117}
2118
2119/// Represent a wildcard star expression (`*`, `table.*`).
2120///
2121/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
2122/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
2123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2124#[cfg_attr(feature = "bindings", derive(TS))]
2125pub struct Star {
2126    /// Optional table qualifier (e.g. `t` in `t.*`).
2127    pub table: Option<Identifier>,
2128    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
2129    pub except: Option<Vec<Identifier>>,
2130    /// REPLACE expressions (BigQuery, Snowflake)
2131    pub replace: Option<Vec<Alias>>,
2132    /// RENAME columns (Snowflake)
2133    pub rename: Option<Vec<(Identifier, Identifier)>>,
2134    /// Trailing comments that appeared after the star
2135    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2136    pub trailing_comments: Vec<String>,
2137    /// Source position span
2138    #[serde(default, skip_serializing_if = "Option::is_none")]
2139    pub span: Option<Span>,
2140}
2141
2142/// Represent a complete SELECT statement.
2143///
2144/// This is the most feature-rich AST node, covering the full surface area of
2145/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
2146/// `Vec` are omitted from the generated SQL when absent.
2147///
2148/// # Key Fields
2149///
2150/// - `expressions` -- the select-list (columns, `*`, computed expressions).
2151/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
2152/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
2153/// - `where_clause` -- the WHERE predicate.
2154/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
2155/// - `having` -- HAVING predicate.
2156/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
2157/// - `limit` / `offset` / `fetch` -- result set limiting.
2158/// - `with` -- Common Table Expressions (CTEs).
2159/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
2160/// - `windows` -- named window definitions (WINDOW w AS ...).
2161///
2162/// Dialect-specific extensions are supported via fields like `prewhere`
2163/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
2164/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
2165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2166#[cfg_attr(feature = "bindings", derive(TS))]
2167pub struct Select {
2168    /// The select-list: columns, expressions, aliases, and wildcards.
2169    pub expressions: Vec<Expression>,
2170    /// The FROM clause, containing one or more table sources.
2171    pub from: Option<From>,
2172    /// JOIN clauses applied after the FROM source.
2173    pub joins: Vec<Join>,
2174    pub lateral_views: Vec<LateralView>,
2175    /// ClickHouse PREWHERE clause
2176    #[serde(default, skip_serializing_if = "Option::is_none")]
2177    pub prewhere: Option<Expression>,
2178    pub where_clause: Option<Where>,
2179    pub group_by: Option<GroupBy>,
2180    pub having: Option<Having>,
2181    pub qualify: Option<Qualify>,
2182    pub order_by: Option<OrderBy>,
2183    pub distribute_by: Option<DistributeBy>,
2184    pub cluster_by: Option<ClusterBy>,
2185    pub sort_by: Option<SortBy>,
2186    pub limit: Option<Limit>,
2187    pub offset: Option<Offset>,
2188    /// ClickHouse LIMIT BY clause expressions
2189    #[serde(default, skip_serializing_if = "Option::is_none")]
2190    pub limit_by: Option<Vec<Expression>>,
2191    pub fetch: Option<Fetch>,
2192    pub distinct: bool,
2193    pub distinct_on: Option<Vec<Expression>>,
2194    pub top: Option<Top>,
2195    pub with: Option<With>,
2196    pub sample: Option<Sample>,
2197    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
2198    #[serde(default, skip_serializing_if = "Option::is_none")]
2199    pub settings: Option<Vec<Expression>>,
2200    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
2201    #[serde(default, skip_serializing_if = "Option::is_none")]
2202    pub format: Option<Expression>,
2203    pub windows: Option<Vec<NamedWindow>>,
2204    pub hint: Option<Hint>,
2205    /// Oracle CONNECT BY clause for hierarchical queries
2206    pub connect: Option<Connect>,
2207    /// SELECT ... INTO table_name for creating tables
2208    pub into: Option<SelectInto>,
2209    /// FOR UPDATE/SHARE locking clauses
2210    #[serde(default)]
2211    pub locks: Vec<Lock>,
2212    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
2213    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2214    pub for_xml: Vec<Expression>,
2215    /// Leading comments before the statement
2216    #[serde(default)]
2217    pub leading_comments: Vec<String>,
2218    /// Comments that appear after SELECT keyword (before expressions)
2219    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
2220    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2221    pub post_select_comments: Vec<String>,
2222    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
2223    #[serde(default, skip_serializing_if = "Option::is_none")]
2224    pub kind: Option<String>,
2225    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
2226    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2227    pub operation_modifiers: Vec<String>,
2228    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
2229    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2230    pub qualify_after_window: bool,
2231    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
2232    #[serde(default, skip_serializing_if = "Option::is_none")]
2233    pub option: Option<String>,
2234}
2235
2236impl Select {
2237    pub fn new() -> Self {
2238        Self {
2239            expressions: Vec::new(),
2240            from: None,
2241            joins: Vec::new(),
2242            lateral_views: Vec::new(),
2243            prewhere: None,
2244            where_clause: None,
2245            group_by: None,
2246            having: None,
2247            qualify: None,
2248            order_by: None,
2249            distribute_by: None,
2250            cluster_by: None,
2251            sort_by: None,
2252            limit: None,
2253            offset: None,
2254            limit_by: None,
2255            fetch: None,
2256            distinct: false,
2257            distinct_on: None,
2258            top: None,
2259            with: None,
2260            sample: None,
2261            settings: None,
2262            format: None,
2263            windows: None,
2264            hint: None,
2265            connect: None,
2266            into: None,
2267            locks: Vec::new(),
2268            for_xml: Vec::new(),
2269            leading_comments: Vec::new(),
2270            post_select_comments: Vec::new(),
2271            kind: None,
2272            operation_modifiers: Vec::new(),
2273            qualify_after_window: false,
2274            option: None,
2275        }
2276    }
2277
2278    /// Add a column to select
2279    pub fn column(mut self, expr: Expression) -> Self {
2280        self.expressions.push(expr);
2281        self
2282    }
2283
2284    /// Set the FROM clause
2285    pub fn from(mut self, table: Expression) -> Self {
2286        self.from = Some(From {
2287            expressions: vec![table],
2288        });
2289        self
2290    }
2291
2292    /// Add a WHERE clause
2293    pub fn where_(mut self, condition: Expression) -> Self {
2294        self.where_clause = Some(Where { this: condition });
2295        self
2296    }
2297
2298    /// Set DISTINCT
2299    pub fn distinct(mut self) -> Self {
2300        self.distinct = true;
2301        self
2302    }
2303
2304    /// Add a JOIN
2305    pub fn join(mut self, join: Join) -> Self {
2306        self.joins.push(join);
2307        self
2308    }
2309
2310    /// Set ORDER BY
2311    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
2312        self.order_by = Some(OrderBy {
2313            expressions,
2314            siblings: false,
2315            comments: Vec::new(),
2316        });
2317        self
2318    }
2319
2320    /// Set LIMIT
2321    pub fn limit(mut self, n: Expression) -> Self {
2322        self.limit = Some(Limit {
2323            this: n,
2324            percent: false,
2325            comments: Vec::new(),
2326        });
2327        self
2328    }
2329
2330    /// Set OFFSET
2331    pub fn offset(mut self, n: Expression) -> Self {
2332        self.offset = Some(Offset {
2333            this: n,
2334            rows: None,
2335        });
2336        self
2337    }
2338}
2339
2340impl Default for Select {
2341    fn default() -> Self {
2342        Self::new()
2343    }
2344}
2345
2346/// Represent a UNION set operation between two query expressions.
2347///
2348/// When `all` is true, duplicate rows are preserved (UNION ALL).
2349/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
2350/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
2351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2352#[cfg_attr(feature = "bindings", derive(TS))]
2353pub struct Union {
2354    /// The left-hand query operand.
2355    pub left: Expression,
2356    /// The right-hand query operand.
2357    pub right: Expression,
2358    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
2359    pub all: bool,
2360    /// Whether DISTINCT was explicitly specified
2361    #[serde(default)]
2362    pub distinct: bool,
2363    /// Optional WITH clause
2364    pub with: Option<With>,
2365    /// ORDER BY applied to entire UNION result
2366    pub order_by: Option<OrderBy>,
2367    /// LIMIT applied to entire UNION result
2368    pub limit: Option<Box<Expression>>,
2369    /// OFFSET applied to entire UNION result
2370    pub offset: Option<Box<Expression>>,
2371    /// DISTRIBUTE BY clause (Hive/Spark)
2372    #[serde(default, skip_serializing_if = "Option::is_none")]
2373    pub distribute_by: Option<DistributeBy>,
2374    /// SORT BY clause (Hive/Spark)
2375    #[serde(default, skip_serializing_if = "Option::is_none")]
2376    pub sort_by: Option<SortBy>,
2377    /// CLUSTER BY clause (Hive/Spark)
2378    #[serde(default, skip_serializing_if = "Option::is_none")]
2379    pub cluster_by: Option<ClusterBy>,
2380    /// DuckDB BY NAME modifier
2381    #[serde(default)]
2382    pub by_name: bool,
2383    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2384    #[serde(default, skip_serializing_if = "Option::is_none")]
2385    pub side: Option<String>,
2386    /// BigQuery: Set operation kind (INNER)
2387    #[serde(default, skip_serializing_if = "Option::is_none")]
2388    pub kind: Option<String>,
2389    /// BigQuery: CORRESPONDING modifier
2390    #[serde(default)]
2391    pub corresponding: bool,
2392    /// BigQuery: STRICT modifier (before CORRESPONDING)
2393    #[serde(default)]
2394    pub strict: bool,
2395    /// BigQuery: BY (columns) after CORRESPONDING
2396    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2397    pub on_columns: Vec<Expression>,
2398}
2399
2400/// Represent an INTERSECT set operation between two query expressions.
2401///
2402/// Returns only rows that appear in both operands. When `all` is true,
2403/// duplicates are preserved according to their multiplicity.
2404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2405#[cfg_attr(feature = "bindings", derive(TS))]
2406pub struct Intersect {
2407    /// The left-hand query operand.
2408    pub left: Expression,
2409    /// The right-hand query operand.
2410    pub right: Expression,
2411    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
2412    pub all: bool,
2413    /// Whether DISTINCT was explicitly specified
2414    #[serde(default)]
2415    pub distinct: bool,
2416    /// Optional WITH clause
2417    pub with: Option<With>,
2418    /// ORDER BY applied to entire INTERSECT result
2419    pub order_by: Option<OrderBy>,
2420    /// LIMIT applied to entire INTERSECT result
2421    pub limit: Option<Box<Expression>>,
2422    /// OFFSET applied to entire INTERSECT result
2423    pub offset: Option<Box<Expression>>,
2424    /// DISTRIBUTE BY clause (Hive/Spark)
2425    #[serde(default, skip_serializing_if = "Option::is_none")]
2426    pub distribute_by: Option<DistributeBy>,
2427    /// SORT BY clause (Hive/Spark)
2428    #[serde(default, skip_serializing_if = "Option::is_none")]
2429    pub sort_by: Option<SortBy>,
2430    /// CLUSTER BY clause (Hive/Spark)
2431    #[serde(default, skip_serializing_if = "Option::is_none")]
2432    pub cluster_by: Option<ClusterBy>,
2433    /// DuckDB BY NAME modifier
2434    #[serde(default)]
2435    pub by_name: bool,
2436    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2437    #[serde(default, skip_serializing_if = "Option::is_none")]
2438    pub side: Option<String>,
2439    /// BigQuery: Set operation kind (INNER)
2440    #[serde(default, skip_serializing_if = "Option::is_none")]
2441    pub kind: Option<String>,
2442    /// BigQuery: CORRESPONDING modifier
2443    #[serde(default)]
2444    pub corresponding: bool,
2445    /// BigQuery: STRICT modifier (before CORRESPONDING)
2446    #[serde(default)]
2447    pub strict: bool,
2448    /// BigQuery: BY (columns) after CORRESPONDING
2449    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2450    pub on_columns: Vec<Expression>,
2451}
2452
2453/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2454///
2455/// Returns rows from the left operand that do not appear in the right operand.
2456/// When `all` is true, duplicates are subtracted according to their multiplicity.
2457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2458#[cfg_attr(feature = "bindings", derive(TS))]
2459pub struct Except {
2460    /// The left-hand query operand.
2461    pub left: Expression,
2462    /// The right-hand query operand (rows to subtract).
2463    pub right: Expression,
2464    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2465    pub all: bool,
2466    /// Whether DISTINCT was explicitly specified
2467    #[serde(default)]
2468    pub distinct: bool,
2469    /// Optional WITH clause
2470    pub with: Option<With>,
2471    /// ORDER BY applied to entire EXCEPT result
2472    pub order_by: Option<OrderBy>,
2473    /// LIMIT applied to entire EXCEPT result
2474    pub limit: Option<Box<Expression>>,
2475    /// OFFSET applied to entire EXCEPT result
2476    pub offset: Option<Box<Expression>>,
2477    /// DISTRIBUTE BY clause (Hive/Spark)
2478    #[serde(default, skip_serializing_if = "Option::is_none")]
2479    pub distribute_by: Option<DistributeBy>,
2480    /// SORT BY clause (Hive/Spark)
2481    #[serde(default, skip_serializing_if = "Option::is_none")]
2482    pub sort_by: Option<SortBy>,
2483    /// CLUSTER BY clause (Hive/Spark)
2484    #[serde(default, skip_serializing_if = "Option::is_none")]
2485    pub cluster_by: Option<ClusterBy>,
2486    /// DuckDB BY NAME modifier
2487    #[serde(default)]
2488    pub by_name: bool,
2489    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2490    #[serde(default, skip_serializing_if = "Option::is_none")]
2491    pub side: Option<String>,
2492    /// BigQuery: Set operation kind (INNER)
2493    #[serde(default, skip_serializing_if = "Option::is_none")]
2494    pub kind: Option<String>,
2495    /// BigQuery: CORRESPONDING modifier
2496    #[serde(default)]
2497    pub corresponding: bool,
2498    /// BigQuery: STRICT modifier (before CORRESPONDING)
2499    #[serde(default)]
2500    pub strict: bool,
2501    /// BigQuery: BY (columns) after CORRESPONDING
2502    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2503    pub on_columns: Vec<Expression>,
2504}
2505
2506/// INTO clause for SELECT INTO statements
2507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2508#[cfg_attr(feature = "bindings", derive(TS))]
2509pub struct SelectInto {
2510    /// Target table or variable (used when single target)
2511    pub this: Expression,
2512    /// Whether TEMPORARY keyword was used
2513    #[serde(default)]
2514    pub temporary: bool,
2515    /// Whether UNLOGGED keyword was used (PostgreSQL)
2516    #[serde(default)]
2517    pub unlogged: bool,
2518    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2519    #[serde(default)]
2520    pub bulk_collect: bool,
2521    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2522    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2523    pub expressions: Vec<Expression>,
2524}
2525
2526/// Represent a parenthesized subquery expression.
2527///
2528/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2529/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2530/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2531/// modifiers are rendered inside or outside the parentheses.
2532///
2533/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2534/// scalar subqueries in select-lists, and derived tables.
2535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2536#[cfg_attr(feature = "bindings", derive(TS))]
2537pub struct Subquery {
2538    /// The inner query expression.
2539    pub this: Expression,
2540    /// Optional alias for the derived table.
2541    pub alias: Option<Identifier>,
2542    /// Optional column aliases: AS t(c1, c2)
2543    pub column_aliases: Vec<Identifier>,
2544    /// ORDER BY clause (for parenthesized queries)
2545    pub order_by: Option<OrderBy>,
2546    /// LIMIT clause
2547    pub limit: Option<Limit>,
2548    /// OFFSET clause
2549    pub offset: Option<Offset>,
2550    /// DISTRIBUTE BY clause (Hive/Spark)
2551    #[serde(default, skip_serializing_if = "Option::is_none")]
2552    pub distribute_by: Option<DistributeBy>,
2553    /// SORT BY clause (Hive/Spark)
2554    #[serde(default, skip_serializing_if = "Option::is_none")]
2555    pub sort_by: Option<SortBy>,
2556    /// CLUSTER BY clause (Hive/Spark)
2557    #[serde(default, skip_serializing_if = "Option::is_none")]
2558    pub cluster_by: Option<ClusterBy>,
2559    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2560    #[serde(default)]
2561    pub lateral: bool,
2562    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2563    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2564    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2565    #[serde(default)]
2566    pub modifiers_inside: bool,
2567    /// Trailing comments after the closing paren
2568    #[serde(default)]
2569    pub trailing_comments: Vec<String>,
2570    /// Inferred data type from type annotation
2571    #[serde(default, skip_serializing_if = "Option::is_none")]
2572    pub inferred_type: Option<DataType>,
2573}
2574
2575/// Pipe operator expression: query |> transform
2576///
2577/// Used in DataFusion and BigQuery pipe syntax:
2578///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2580#[cfg_attr(feature = "bindings", derive(TS))]
2581pub struct PipeOperator {
2582    /// The input query/expression (left side of |>)
2583    pub this: Expression,
2584    /// The piped operation (right side of |>)
2585    pub expression: Expression,
2586}
2587
2588/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2590#[cfg_attr(feature = "bindings", derive(TS))]
2591pub struct Values {
2592    /// The rows of values
2593    pub expressions: Vec<Tuple>,
2594    /// Optional alias for the table
2595    pub alias: Option<Identifier>,
2596    /// Optional column aliases: AS t(c1, c2)
2597    pub column_aliases: Vec<Identifier>,
2598}
2599
2600/// PIVOT operation - supports both standard and DuckDB simplified syntax
2601///
2602/// Standard syntax (in FROM clause):
2603///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2604///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2605///
2606/// DuckDB simplified syntax (statement-level):
2607///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2608///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2610#[cfg_attr(feature = "bindings", derive(TS))]
2611pub struct Pivot {
2612    /// Source table/expression
2613    pub this: Expression,
2614    /// For standard PIVOT: the aggregation function(s) (first is primary)
2615    /// For DuckDB simplified: unused (use `using` instead)
2616    #[serde(default)]
2617    pub expressions: Vec<Expression>,
2618    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2619    #[serde(default)]
2620    pub fields: Vec<Expression>,
2621    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2622    #[serde(default)]
2623    pub using: Vec<Expression>,
2624    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2625    #[serde(default)]
2626    pub group: Option<Box<Expression>>,
2627    /// Whether this is an UNPIVOT (vs PIVOT)
2628    #[serde(default)]
2629    pub unpivot: bool,
2630    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2631    #[serde(default)]
2632    pub into: Option<Box<Expression>>,
2633    /// Optional alias
2634    #[serde(default)]
2635    pub alias: Option<Identifier>,
2636    /// Include/exclude nulls (for UNPIVOT)
2637    #[serde(default)]
2638    pub include_nulls: Option<bool>,
2639    /// Default on null value (Snowflake)
2640    #[serde(default)]
2641    pub default_on_null: Option<Box<Expression>>,
2642    /// WITH clause (CTEs)
2643    #[serde(default, skip_serializing_if = "Option::is_none")]
2644    pub with: Option<With>,
2645}
2646
2647/// UNPIVOT operation
2648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2649#[cfg_attr(feature = "bindings", derive(TS))]
2650pub struct Unpivot {
2651    pub this: Expression,
2652    pub value_column: Identifier,
2653    pub name_column: Identifier,
2654    pub columns: Vec<Expression>,
2655    pub alias: Option<Identifier>,
2656    /// Whether the value_column was parenthesized in the original SQL
2657    #[serde(default)]
2658    pub value_column_parenthesized: bool,
2659    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2660    #[serde(default)]
2661    pub include_nulls: Option<bool>,
2662    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2663    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2664    pub extra_value_columns: Vec<Identifier>,
2665}
2666
2667/// PIVOT alias for aliasing pivot expressions
2668/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2669#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2670#[cfg_attr(feature = "bindings", derive(TS))]
2671pub struct PivotAlias {
2672    pub this: Expression,
2673    pub alias: Expression,
2674}
2675
2676/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2678#[cfg_attr(feature = "bindings", derive(TS))]
2679pub struct PreWhere {
2680    pub this: Expression,
2681}
2682
2683/// STREAM definition (Snowflake) - for change data capture
2684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2685#[cfg_attr(feature = "bindings", derive(TS))]
2686pub struct Stream {
2687    pub this: Expression,
2688    #[serde(skip_serializing_if = "Option::is_none")]
2689    pub on: Option<Expression>,
2690    #[serde(skip_serializing_if = "Option::is_none")]
2691    pub show_initial_rows: Option<bool>,
2692}
2693
2694/// USING DATA clause for data import statements
2695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2696#[cfg_attr(feature = "bindings", derive(TS))]
2697pub struct UsingData {
2698    pub this: Expression,
2699}
2700
2701/// XML Namespace declaration
2702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2703#[cfg_attr(feature = "bindings", derive(TS))]
2704pub struct XmlNamespace {
2705    pub this: Expression,
2706    #[serde(skip_serializing_if = "Option::is_none")]
2707    pub alias: Option<Identifier>,
2708}
2709
2710/// ROW FORMAT clause for Hive/Spark
2711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2712#[cfg_attr(feature = "bindings", derive(TS))]
2713pub struct RowFormat {
2714    pub delimited: bool,
2715    pub fields_terminated_by: Option<String>,
2716    pub collection_items_terminated_by: Option<String>,
2717    pub map_keys_terminated_by: Option<String>,
2718    pub lines_terminated_by: Option<String>,
2719    pub null_defined_as: Option<String>,
2720}
2721
2722/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2724#[cfg_attr(feature = "bindings", derive(TS))]
2725pub struct DirectoryInsert {
2726    pub local: bool,
2727    pub path: String,
2728    pub row_format: Option<RowFormat>,
2729    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2730    #[serde(default)]
2731    pub stored_as: Option<String>,
2732}
2733
2734/// INSERT statement
2735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2736#[cfg_attr(feature = "bindings", derive(TS))]
2737pub struct Insert {
2738    pub table: TableRef,
2739    pub columns: Vec<Identifier>,
2740    pub values: Vec<Vec<Expression>>,
2741    pub query: Option<Expression>,
2742    /// INSERT OVERWRITE for Hive/Spark
2743    pub overwrite: bool,
2744    /// PARTITION clause for Hive/Spark
2745    pub partition: Vec<(Identifier, Option<Expression>)>,
2746    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2747    #[serde(default)]
2748    pub directory: Option<DirectoryInsert>,
2749    /// RETURNING clause (PostgreSQL, SQLite)
2750    #[serde(default)]
2751    pub returning: Vec<Expression>,
2752    /// OUTPUT clause (TSQL)
2753    #[serde(default)]
2754    pub output: Option<OutputClause>,
2755    /// ON CONFLICT clause (PostgreSQL, SQLite)
2756    #[serde(default)]
2757    pub on_conflict: Option<Box<Expression>>,
2758    /// Leading comments before the statement
2759    #[serde(default)]
2760    pub leading_comments: Vec<String>,
2761    /// IF EXISTS clause (Hive)
2762    #[serde(default)]
2763    pub if_exists: bool,
2764    /// WITH clause (CTEs)
2765    #[serde(default)]
2766    pub with: Option<With>,
2767    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2768    #[serde(default)]
2769    pub ignore: bool,
2770    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2771    #[serde(default)]
2772    pub source_alias: Option<Identifier>,
2773    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2774    #[serde(default)]
2775    pub alias: Option<Identifier>,
2776    /// Whether the alias uses explicit AS keyword
2777    #[serde(default)]
2778    pub alias_explicit_as: bool,
2779    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2780    #[serde(default)]
2781    pub default_values: bool,
2782    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2783    #[serde(default)]
2784    pub by_name: bool,
2785    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2786    #[serde(default, skip_serializing_if = "Option::is_none")]
2787    pub conflict_action: Option<String>,
2788    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2789    #[serde(default)]
2790    pub is_replace: bool,
2791    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2792    #[serde(default, skip_serializing_if = "Option::is_none")]
2793    pub hint: Option<Hint>,
2794    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2795    #[serde(default)]
2796    pub replace_where: Option<Box<Expression>>,
2797    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2798    #[serde(default)]
2799    pub source: Option<Box<Expression>>,
2800    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2801    #[serde(default, skip_serializing_if = "Option::is_none")]
2802    pub function_target: Option<Box<Expression>>,
2803    /// ClickHouse: PARTITION BY expr
2804    #[serde(default, skip_serializing_if = "Option::is_none")]
2805    pub partition_by: Option<Box<Expression>>,
2806    /// ClickHouse: SETTINGS key = val, ...
2807    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2808    pub settings: Vec<Expression>,
2809}
2810
2811/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2813#[cfg_attr(feature = "bindings", derive(TS))]
2814pub struct OutputClause {
2815    /// Columns/expressions to output
2816    pub columns: Vec<Expression>,
2817    /// Optional INTO target table or table variable
2818    #[serde(default)]
2819    pub into_table: Option<Expression>,
2820}
2821
2822/// UPDATE statement
2823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2824#[cfg_attr(feature = "bindings", derive(TS))]
2825pub struct Update {
2826    pub table: TableRef,
2827    /// Additional tables for multi-table UPDATE (MySQL syntax)
2828    #[serde(default)]
2829    pub extra_tables: Vec<TableRef>,
2830    /// JOINs attached to the table list (MySQL multi-table syntax)
2831    #[serde(default)]
2832    pub table_joins: Vec<Join>,
2833    pub set: Vec<(Identifier, Expression)>,
2834    pub from_clause: Option<From>,
2835    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2836    #[serde(default)]
2837    pub from_joins: Vec<Join>,
2838    pub where_clause: Option<Where>,
2839    /// RETURNING clause (PostgreSQL, SQLite)
2840    #[serde(default)]
2841    pub returning: Vec<Expression>,
2842    /// OUTPUT clause (TSQL)
2843    #[serde(default)]
2844    pub output: Option<OutputClause>,
2845    /// WITH clause (CTEs)
2846    #[serde(default)]
2847    pub with: Option<With>,
2848    /// Leading comments before the statement
2849    #[serde(default)]
2850    pub leading_comments: Vec<String>,
2851    /// LIMIT clause (MySQL)
2852    #[serde(default)]
2853    pub limit: Option<Expression>,
2854    /// ORDER BY clause (MySQL)
2855    #[serde(default)]
2856    pub order_by: Option<OrderBy>,
2857    /// Whether FROM clause appears before SET (Snowflake syntax)
2858    #[serde(default)]
2859    pub from_before_set: bool,
2860}
2861
2862/// DELETE statement
2863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2864#[cfg_attr(feature = "bindings", derive(TS))]
2865pub struct Delete {
2866    pub table: TableRef,
2867    /// ClickHouse: ON CLUSTER clause for distributed DDL
2868    #[serde(default, skip_serializing_if = "Option::is_none")]
2869    pub on_cluster: Option<OnCluster>,
2870    /// Optional alias for the table
2871    pub alias: Option<Identifier>,
2872    /// Whether the alias was declared with explicit AS keyword
2873    #[serde(default)]
2874    pub alias_explicit_as: bool,
2875    /// PostgreSQL/DuckDB USING clause - additional tables to join
2876    pub using: Vec<TableRef>,
2877    pub where_clause: Option<Where>,
2878    /// OUTPUT clause (TSQL)
2879    #[serde(default)]
2880    pub output: Option<OutputClause>,
2881    /// Leading comments before the statement
2882    #[serde(default)]
2883    pub leading_comments: Vec<String>,
2884    /// WITH clause (CTEs)
2885    #[serde(default)]
2886    pub with: Option<With>,
2887    /// LIMIT clause (MySQL)
2888    #[serde(default)]
2889    pub limit: Option<Expression>,
2890    /// ORDER BY clause (MySQL)
2891    #[serde(default)]
2892    pub order_by: Option<OrderBy>,
2893    /// RETURNING clause (PostgreSQL)
2894    #[serde(default)]
2895    pub returning: Vec<Expression>,
2896    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2897    /// These are the target tables to delete from
2898    #[serde(default)]
2899    pub tables: Vec<TableRef>,
2900    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2901    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2902    #[serde(default)]
2903    pub tables_from_using: bool,
2904    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2905    #[serde(default)]
2906    pub joins: Vec<Join>,
2907    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2908    #[serde(default)]
2909    pub force_index: Option<String>,
2910    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2911    #[serde(default)]
2912    pub no_from: bool,
2913}
2914
2915/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2917#[cfg_attr(feature = "bindings", derive(TS))]
2918pub struct CopyStmt {
2919    /// Target table or query
2920    pub this: Expression,
2921    /// True for FROM (loading into table), false for TO (exporting)
2922    pub kind: bool,
2923    /// Source/destination file(s) or stage
2924    pub files: Vec<Expression>,
2925    /// Copy parameters
2926    #[serde(default)]
2927    pub params: Vec<CopyParameter>,
2928    /// Credentials for external access
2929    #[serde(default)]
2930    pub credentials: Option<Box<Credentials>>,
2931    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2932    #[serde(default)]
2933    pub is_into: bool,
2934    /// Whether parameters are wrapped in WITH (...) syntax
2935    #[serde(default)]
2936    pub with_wrapped: bool,
2937}
2938
2939/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2941#[cfg_attr(feature = "bindings", derive(TS))]
2942pub struct CopyParameter {
2943    pub name: String,
2944    pub value: Option<Expression>,
2945    pub values: Vec<Expression>,
2946    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2947    #[serde(default)]
2948    pub eq: bool,
2949}
2950
2951/// Credentials for external access (S3, Azure, etc.)
2952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2953#[cfg_attr(feature = "bindings", derive(TS))]
2954pub struct Credentials {
2955    pub credentials: Vec<(String, String)>,
2956    pub encryption: Option<String>,
2957    pub storage: Option<String>,
2958}
2959
2960/// PUT statement (Snowflake)
2961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2962#[cfg_attr(feature = "bindings", derive(TS))]
2963pub struct PutStmt {
2964    /// Source file path
2965    pub source: String,
2966    /// Whether source was quoted in the original SQL
2967    #[serde(default)]
2968    pub source_quoted: bool,
2969    /// Target stage
2970    pub target: Expression,
2971    /// PUT parameters
2972    #[serde(default)]
2973    pub params: Vec<CopyParameter>,
2974}
2975
2976/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2978#[cfg_attr(feature = "bindings", derive(TS))]
2979pub struct StageReference {
2980    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2981    pub name: String,
2982    /// Optional path within the stage (e.g., "/path/to/file.csv")
2983    #[serde(default)]
2984    pub path: Option<String>,
2985    /// Optional FILE_FORMAT parameter
2986    #[serde(default)]
2987    pub file_format: Option<Expression>,
2988    /// Optional PATTERN parameter
2989    #[serde(default)]
2990    pub pattern: Option<String>,
2991    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2992    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2993    pub quoted: bool,
2994}
2995
2996/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2998#[cfg_attr(feature = "bindings", derive(TS))]
2999pub struct HistoricalData {
3000    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
3001    pub this: Box<Expression>,
3002    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
3003    pub kind: String,
3004    /// The expression value (e.g., the statement ID or timestamp)
3005    pub expression: Box<Expression>,
3006}
3007
3008/// Represent an aliased expression (`expr AS name`).
3009///
3010/// Used for column aliases in select-lists, table aliases on subqueries,
3011/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
3012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3013#[cfg_attr(feature = "bindings", derive(TS))]
3014pub struct Alias {
3015    /// The expression being aliased.
3016    pub this: Expression,
3017    /// The alias name (required for simple aliases, optional when only column aliases provided)
3018    pub alias: Identifier,
3019    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
3020    #[serde(default)]
3021    pub column_aliases: Vec<Identifier>,
3022    /// Comments that appeared between the expression and AS keyword
3023    #[serde(default)]
3024    pub pre_alias_comments: Vec<String>,
3025    /// Trailing comments that appeared after the alias
3026    #[serde(default)]
3027    pub trailing_comments: Vec<String>,
3028    /// Inferred data type from type annotation
3029    #[serde(default, skip_serializing_if = "Option::is_none")]
3030    pub inferred_type: Option<DataType>,
3031}
3032
3033impl Alias {
3034    /// Create a simple alias
3035    pub fn new(this: Expression, alias: Identifier) -> Self {
3036        Self {
3037            this,
3038            alias,
3039            column_aliases: Vec::new(),
3040            pre_alias_comments: Vec::new(),
3041            trailing_comments: Vec::new(),
3042            inferred_type: None,
3043        }
3044    }
3045
3046    /// Create an alias with column aliases only (no table alias name)
3047    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
3048        Self {
3049            this,
3050            alias: Identifier::empty(),
3051            column_aliases,
3052            pre_alias_comments: Vec::new(),
3053            trailing_comments: Vec::new(),
3054            inferred_type: None,
3055        }
3056    }
3057}
3058
3059/// Represent a type cast expression.
3060///
3061/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
3062/// shorthand `expr::type`. Also used as the payload for `TryCast` and
3063/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
3064/// CONVERSION ERROR (Oracle) clauses.
3065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3066#[cfg_attr(feature = "bindings", derive(TS))]
3067pub struct Cast {
3068    /// The expression being cast.
3069    pub this: Expression,
3070    /// The target data type.
3071    pub to: DataType,
3072    #[serde(default)]
3073    pub trailing_comments: Vec<String>,
3074    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
3075    #[serde(default)]
3076    pub double_colon_syntax: bool,
3077    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
3078    #[serde(skip_serializing_if = "Option::is_none", default)]
3079    pub format: Option<Box<Expression>>,
3080    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
3081    #[serde(skip_serializing_if = "Option::is_none", default)]
3082    pub default: Option<Box<Expression>>,
3083    /// Inferred data type from type annotation
3084    #[serde(default, skip_serializing_if = "Option::is_none")]
3085    pub inferred_type: Option<DataType>,
3086}
3087
3088///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
3089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3090#[cfg_attr(feature = "bindings", derive(TS))]
3091pub struct CollationExpr {
3092    pub this: Expression,
3093    pub collation: String,
3094    /// True if the collation was single-quoted in the original SQL (string literal)
3095    #[serde(default)]
3096    pub quoted: bool,
3097    /// True if the collation was double-quoted in the original SQL (identifier)
3098    #[serde(default)]
3099    pub double_quoted: bool,
3100}
3101
3102/// Represent a CASE expression (both simple and searched forms).
3103///
3104/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
3105/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
3106/// Each entry in `whens` is a `(condition, result)` pair.
3107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3108#[cfg_attr(feature = "bindings", derive(TS))]
3109pub struct Case {
3110    /// The operand for simple CASE, or `None` for searched CASE.
3111    pub operand: Option<Expression>,
3112    /// Pairs of (WHEN condition, THEN result).
3113    pub whens: Vec<(Expression, Expression)>,
3114    /// Optional ELSE result.
3115    pub else_: Option<Expression>,
3116    /// Comments from the CASE keyword (emitted after END)
3117    #[serde(default)]
3118    #[serde(skip_serializing_if = "Vec::is_empty")]
3119    pub comments: Vec<String>,
3120    /// Inferred data type from type annotation
3121    #[serde(default, skip_serializing_if = "Option::is_none")]
3122    pub inferred_type: Option<DataType>,
3123}
3124
3125/// Represent a binary operation (two operands separated by an operator).
3126///
3127/// This is the shared payload struct for all binary operator variants in the
3128/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
3129/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
3130/// bitwise, and dialect-specific operators. Comment fields enable round-trip
3131/// preservation of inline comments around operators.
3132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3133#[cfg_attr(feature = "bindings", derive(TS))]
3134pub struct BinaryOp {
3135    pub left: Expression,
3136    pub right: Expression,
3137    /// Comments after the left operand (before the operator)
3138    #[serde(default)]
3139    pub left_comments: Vec<String>,
3140    /// Comments after the operator (before the right operand)
3141    #[serde(default)]
3142    pub operator_comments: Vec<String>,
3143    /// Comments after the right operand
3144    #[serde(default)]
3145    pub trailing_comments: Vec<String>,
3146    /// Inferred data type from type annotation
3147    #[serde(default, skip_serializing_if = "Option::is_none")]
3148    pub inferred_type: Option<DataType>,
3149}
3150
3151impl BinaryOp {
3152    pub fn new(left: Expression, right: Expression) -> Self {
3153        Self {
3154            left,
3155            right,
3156            left_comments: Vec::new(),
3157            operator_comments: Vec::new(),
3158            trailing_comments: Vec::new(),
3159            inferred_type: None,
3160        }
3161    }
3162}
3163
3164/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
3165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3166#[cfg_attr(feature = "bindings", derive(TS))]
3167pub struct LikeOp {
3168    pub left: Expression,
3169    pub right: Expression,
3170    /// ESCAPE character/expression
3171    #[serde(default)]
3172    pub escape: Option<Expression>,
3173    /// Quantifier: ANY, ALL, or SOME
3174    #[serde(default)]
3175    pub quantifier: Option<String>,
3176    /// Inferred data type from type annotation
3177    #[serde(default, skip_serializing_if = "Option::is_none")]
3178    pub inferred_type: Option<DataType>,
3179}
3180
3181impl LikeOp {
3182    pub fn new(left: Expression, right: Expression) -> Self {
3183        Self {
3184            left,
3185            right,
3186            escape: None,
3187            quantifier: None,
3188            inferred_type: None,
3189        }
3190    }
3191
3192    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
3193        Self {
3194            left,
3195            right,
3196            escape: Some(escape),
3197            quantifier: None,
3198            inferred_type: None,
3199        }
3200    }
3201}
3202
3203/// Represent a unary operation (single operand with a prefix operator).
3204///
3205/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
3206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3207#[cfg_attr(feature = "bindings", derive(TS))]
3208pub struct UnaryOp {
3209    /// The operand expression.
3210    pub this: Expression,
3211    /// Inferred data type from type annotation
3212    #[serde(default, skip_serializing_if = "Option::is_none")]
3213    pub inferred_type: Option<DataType>,
3214}
3215
3216impl UnaryOp {
3217    pub fn new(this: Expression) -> Self {
3218        Self {
3219            this,
3220            inferred_type: None,
3221        }
3222    }
3223}
3224
3225/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
3226///
3227/// Either `expressions` (a value list) or `query` (a subquery) is populated,
3228/// but not both. When `not` is true, the predicate is `NOT IN`.
3229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3230#[cfg_attr(feature = "bindings", derive(TS))]
3231pub struct In {
3232    /// The expression being tested.
3233    pub this: Expression,
3234    /// The value list (mutually exclusive with `query`).
3235    pub expressions: Vec<Expression>,
3236    /// A subquery (mutually exclusive with `expressions`).
3237    pub query: Option<Expression>,
3238    /// Whether this is NOT IN.
3239    pub not: bool,
3240    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3241    pub global: bool,
3242    /// BigQuery: IN UNNEST(expr)
3243    #[serde(default, skip_serializing_if = "Option::is_none")]
3244    pub unnest: Option<Box<Expression>>,
3245    /// Whether the right side is a bare field reference (no parentheses).
3246    /// Matches Python sqlglot's `field` attribute on `In` expression.
3247    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
3248    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3249    pub is_field: bool,
3250}
3251
3252/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
3253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3254#[cfg_attr(feature = "bindings", derive(TS))]
3255pub struct Between {
3256    /// The expression being tested.
3257    pub this: Expression,
3258    /// The lower bound.
3259    pub low: Expression,
3260    /// The upper bound.
3261    pub high: Expression,
3262    /// Whether this is NOT BETWEEN.
3263    pub not: bool,
3264    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
3265    #[serde(default)]
3266    pub symmetric: Option<bool>,
3267}
3268
3269/// IS NULL predicate
3270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3271#[cfg_attr(feature = "bindings", derive(TS))]
3272pub struct IsNull {
3273    pub this: Expression,
3274    pub not: bool,
3275    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
3276    #[serde(default)]
3277    pub postfix_form: bool,
3278}
3279
3280/// IS TRUE / IS FALSE predicate
3281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3282#[cfg_attr(feature = "bindings", derive(TS))]
3283pub struct IsTrueFalse {
3284    pub this: Expression,
3285    pub not: bool,
3286}
3287
3288/// IS JSON predicate (SQL standard)
3289/// Checks if a value is valid JSON
3290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3291#[cfg_attr(feature = "bindings", derive(TS))]
3292pub struct IsJson {
3293    pub this: Expression,
3294    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
3295    pub json_type: Option<String>,
3296    /// Key uniqueness constraint
3297    pub unique_keys: Option<JsonUniqueKeys>,
3298    /// Whether IS NOT JSON
3299    pub negated: bool,
3300}
3301
3302/// JSON unique keys constraint variants
3303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3304#[cfg_attr(feature = "bindings", derive(TS))]
3305pub enum JsonUniqueKeys {
3306    /// WITH UNIQUE KEYS
3307    With,
3308    /// WITHOUT UNIQUE KEYS
3309    Without,
3310    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
3311    Shorthand,
3312}
3313
3314/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
3315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3316#[cfg_attr(feature = "bindings", derive(TS))]
3317pub struct Exists {
3318    /// The subquery expression.
3319    pub this: Expression,
3320    /// Whether this is NOT EXISTS.
3321    pub not: bool,
3322}
3323
3324/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
3325///
3326/// This is the generic function node. Well-known aggregates, window functions,
3327/// and built-in functions each have their own dedicated `Expression` variants
3328/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
3329/// not recognize as built-ins are represented with this struct.
3330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3331#[cfg_attr(feature = "bindings", derive(TS))]
3332pub struct Function {
3333    /// The function name, as originally written (may be schema-qualified).
3334    pub name: String,
3335    /// Positional arguments to the function.
3336    pub args: Vec<Expression>,
3337    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
3338    pub distinct: bool,
3339    #[serde(default)]
3340    pub trailing_comments: Vec<String>,
3341    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
3342    #[serde(default)]
3343    pub use_bracket_syntax: bool,
3344    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
3345    #[serde(default)]
3346    pub no_parens: bool,
3347    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
3348    #[serde(default)]
3349    pub quoted: bool,
3350    /// Source position span
3351    #[serde(default, skip_serializing_if = "Option::is_none")]
3352    pub span: Option<Span>,
3353    /// Inferred data type from type annotation
3354    #[serde(default, skip_serializing_if = "Option::is_none")]
3355    pub inferred_type: Option<DataType>,
3356}
3357
3358impl Default for Function {
3359    fn default() -> Self {
3360        Self {
3361            name: String::new(),
3362            args: Vec::new(),
3363            distinct: false,
3364            trailing_comments: Vec::new(),
3365            use_bracket_syntax: false,
3366            no_parens: false,
3367            quoted: false,
3368            span: None,
3369            inferred_type: None,
3370        }
3371    }
3372}
3373
3374impl Function {
3375    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
3376        Self {
3377            name: name.into(),
3378            args,
3379            distinct: false,
3380            trailing_comments: Vec::new(),
3381            use_bracket_syntax: false,
3382            no_parens: false,
3383            quoted: false,
3384            span: None,
3385            inferred_type: None,
3386        }
3387    }
3388}
3389
3390/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
3391///
3392/// This struct is used for aggregate function calls that are not covered by
3393/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
3394/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
3395/// IGNORE NULLS / RESPECT NULLS modifiers.
3396#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3397#[cfg_attr(feature = "bindings", derive(TS))]
3398pub struct AggregateFunction {
3399    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
3400    pub name: String,
3401    /// Positional arguments.
3402    pub args: Vec<Expression>,
3403    /// Whether DISTINCT was specified.
3404    pub distinct: bool,
3405    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
3406    pub filter: Option<Expression>,
3407    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
3408    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3409    pub order_by: Vec<Ordered>,
3410    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
3411    #[serde(default, skip_serializing_if = "Option::is_none")]
3412    pub limit: Option<Box<Expression>>,
3413    /// IGNORE NULLS / RESPECT NULLS
3414    #[serde(default, skip_serializing_if = "Option::is_none")]
3415    pub ignore_nulls: Option<bool>,
3416    /// Inferred data type from type annotation
3417    #[serde(default, skip_serializing_if = "Option::is_none")]
3418    pub inferred_type: Option<DataType>,
3419}
3420
3421/// Represent a window function call with its OVER clause.
3422///
3423/// The inner `this` expression is typically a window-specific expression
3424/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
3425/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
3426/// frame specification.
3427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3428#[cfg_attr(feature = "bindings", derive(TS))]
3429pub struct WindowFunction {
3430    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
3431    pub this: Expression,
3432    /// The OVER clause defining the window partitioning, ordering, and frame.
3433    pub over: Over,
3434    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
3435    #[serde(default, skip_serializing_if = "Option::is_none")]
3436    pub keep: Option<Keep>,
3437    /// Inferred data type from type annotation
3438    #[serde(default, skip_serializing_if = "Option::is_none")]
3439    pub inferred_type: Option<DataType>,
3440}
3441
3442/// Oracle KEEP clause for aggregate functions
3443/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
3444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3445#[cfg_attr(feature = "bindings", derive(TS))]
3446pub struct Keep {
3447    /// true = FIRST, false = LAST
3448    pub first: bool,
3449    /// ORDER BY clause inside KEEP
3450    pub order_by: Vec<Ordered>,
3451}
3452
3453/// WITHIN GROUP clause (for ordered-set aggregate functions)
3454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3455#[cfg_attr(feature = "bindings", derive(TS))]
3456pub struct WithinGroup {
3457    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
3458    pub this: Expression,
3459    /// The ORDER BY clause within the group
3460    pub order_by: Vec<Ordered>,
3461}
3462
3463/// Represent the FROM clause of a SELECT statement.
3464///
3465/// Contains one or more table sources (tables, subqueries, table-valued
3466/// functions, etc.). Multiple entries represent comma-separated implicit joins.
3467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3468#[cfg_attr(feature = "bindings", derive(TS))]
3469pub struct From {
3470    /// The table source expressions.
3471    pub expressions: Vec<Expression>,
3472}
3473
3474/// Represent a JOIN clause between two table sources.
3475///
3476/// The join condition can be specified via `on` (ON predicate) or `using`
3477/// (USING column list), but not both. The `kind` field determines the join
3478/// type (INNER, LEFT, CROSS, etc.).
3479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3480#[cfg_attr(feature = "bindings", derive(TS))]
3481pub struct Join {
3482    /// The right-hand table expression being joined.
3483    pub this: Expression,
3484    /// The ON condition (mutually exclusive with `using`).
3485    pub on: Option<Expression>,
3486    /// The USING column list (mutually exclusive with `on`).
3487    pub using: Vec<Identifier>,
3488    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
3489    pub kind: JoinKind,
3490    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3491    pub use_inner_keyword: bool,
3492    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3493    pub use_outer_keyword: bool,
3494    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3495    pub deferred_condition: bool,
3496    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3497    #[serde(default, skip_serializing_if = "Option::is_none")]
3498    pub join_hint: Option<String>,
3499    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3500    #[serde(default, skip_serializing_if = "Option::is_none")]
3501    pub match_condition: Option<Expression>,
3502    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3503    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3504    pub pivots: Vec<Expression>,
3505    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3506    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3507    pub comments: Vec<String>,
3508    /// Nesting group identifier for nested join pretty-printing.
3509    /// Joins in the same group were parsed together; group boundaries come from
3510    /// deferred condition resolution phases.
3511    #[serde(default)]
3512    pub nesting_group: usize,
3513    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3514    #[serde(default)]
3515    pub directed: bool,
3516}
3517
3518/// Enumerate all supported SQL join types.
3519///
3520/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3521/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3522/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3523/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3524#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3525#[cfg_attr(feature = "bindings", derive(TS))]
3526pub enum JoinKind {
3527    Inner,
3528    Left,
3529    Right,
3530    Full,
3531    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3532    Cross,
3533    Natural,
3534    NaturalLeft,
3535    NaturalRight,
3536    NaturalFull,
3537    Semi,
3538    Anti,
3539    // Directional SEMI/ANTI joins
3540    LeftSemi,
3541    LeftAnti,
3542    RightSemi,
3543    RightAnti,
3544    // SQL Server specific
3545    CrossApply,
3546    OuterApply,
3547    // Time-series specific
3548    AsOf,
3549    AsOfLeft,
3550    AsOfRight,
3551    // Lateral join
3552    Lateral,
3553    LeftLateral,
3554    // MySQL specific
3555    Straight,
3556    // Implicit join (comma-separated tables: FROM a, b)
3557    Implicit,
3558    // ClickHouse ARRAY JOIN
3559    Array,
3560    LeftArray,
3561    // ClickHouse PASTE JOIN (positional join)
3562    Paste,
3563}
3564
3565impl Default for JoinKind {
3566    fn default() -> Self {
3567        JoinKind::Inner
3568    }
3569}
3570
3571/// Parenthesized table expression with joins
3572/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3574#[cfg_attr(feature = "bindings", derive(TS))]
3575pub struct JoinedTable {
3576    /// The left-hand side table expression
3577    pub left: Expression,
3578    /// The joins applied to the left table
3579    pub joins: Vec<Join>,
3580    /// LATERAL VIEW clauses (Hive/Spark)
3581    pub lateral_views: Vec<LateralView>,
3582    /// Optional alias for the joined table expression
3583    pub alias: Option<Identifier>,
3584}
3585
3586/// Represent a WHERE clause containing a boolean filter predicate.
3587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3588#[cfg_attr(feature = "bindings", derive(TS))]
3589pub struct Where {
3590    /// The filter predicate expression.
3591    pub this: Expression,
3592}
3593
3594/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3595///
3596/// The `expressions` list may contain plain columns, ordinal positions,
3597/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3599#[cfg_attr(feature = "bindings", derive(TS))]
3600pub struct GroupBy {
3601    /// The grouping expressions.
3602    pub expressions: Vec<Expression>,
3603    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3604    #[serde(default)]
3605    pub all: Option<bool>,
3606    /// ClickHouse: WITH TOTALS modifier
3607    #[serde(default)]
3608    pub totals: bool,
3609    /// Leading comments that appeared before the GROUP BY keyword
3610    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3611    pub comments: Vec<String>,
3612}
3613
3614/// Represent a HAVING clause containing a predicate over aggregate results.
3615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3616#[cfg_attr(feature = "bindings", derive(TS))]
3617pub struct Having {
3618    /// The filter predicate, typically involving aggregate functions.
3619    pub this: Expression,
3620    /// Leading comments that appeared before the HAVING keyword
3621    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3622    pub comments: Vec<String>,
3623}
3624
3625/// Represent an ORDER BY clause containing one or more sort specifications.
3626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3627#[cfg_attr(feature = "bindings", derive(TS))]
3628pub struct OrderBy {
3629    /// The sort specifications, each with direction and null ordering.
3630    pub expressions: Vec<Ordered>,
3631    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3632    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3633    pub siblings: bool,
3634    /// Leading comments that appeared before the ORDER BY keyword
3635    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3636    pub comments: Vec<String>,
3637}
3638
3639/// Represent an expression with sort direction and null ordering.
3640///
3641/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3642/// When `desc` is false the sort is ascending. The `nulls_first` field
3643/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3644/// (database default).
3645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3646#[cfg_attr(feature = "bindings", derive(TS))]
3647pub struct Ordered {
3648    /// The expression to sort by.
3649    pub this: Expression,
3650    /// Whether the sort direction is descending (true) or ascending (false).
3651    pub desc: bool,
3652    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3653    pub nulls_first: Option<bool>,
3654    /// Whether ASC was explicitly written (not just implied)
3655    #[serde(default)]
3656    pub explicit_asc: bool,
3657    /// ClickHouse WITH FILL clause
3658    #[serde(default, skip_serializing_if = "Option::is_none")]
3659    pub with_fill: Option<Box<WithFill>>,
3660}
3661
3662impl Ordered {
3663    pub fn asc(expr: Expression) -> Self {
3664        Self {
3665            this: expr,
3666            desc: false,
3667            nulls_first: None,
3668            explicit_asc: false,
3669            with_fill: None,
3670        }
3671    }
3672
3673    pub fn desc(expr: Expression) -> Self {
3674        Self {
3675            this: expr,
3676            desc: true,
3677            nulls_first: None,
3678            explicit_asc: false,
3679            with_fill: None,
3680        }
3681    }
3682}
3683
3684/// DISTRIBUTE BY clause (Hive/Spark)
3685/// Controls how rows are distributed across reducers
3686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3687#[cfg_attr(feature = "bindings", derive(TS))]
3688#[cfg_attr(feature = "bindings", ts(export))]
3689pub struct DistributeBy {
3690    pub expressions: Vec<Expression>,
3691}
3692
3693/// CLUSTER BY clause (Hive/Spark)
3694/// Combines DISTRIBUTE BY and SORT BY on the same columns
3695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3696#[cfg_attr(feature = "bindings", derive(TS))]
3697#[cfg_attr(feature = "bindings", ts(export))]
3698pub struct ClusterBy {
3699    pub expressions: Vec<Ordered>,
3700}
3701
3702/// SORT BY clause (Hive/Spark)
3703/// Sorts data within each reducer (local sort, not global)
3704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3705#[cfg_attr(feature = "bindings", derive(TS))]
3706#[cfg_attr(feature = "bindings", ts(export))]
3707pub struct SortBy {
3708    pub expressions: Vec<Ordered>,
3709}
3710
3711/// LATERAL VIEW clause (Hive/Spark)
3712/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3714#[cfg_attr(feature = "bindings", derive(TS))]
3715#[cfg_attr(feature = "bindings", ts(export))]
3716pub struct LateralView {
3717    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3718    pub this: Expression,
3719    /// Table alias for the generated table
3720    pub table_alias: Option<Identifier>,
3721    /// Column aliases for the generated columns
3722    pub column_aliases: Vec<Identifier>,
3723    /// OUTER keyword - preserve nulls when input is empty/null
3724    pub outer: bool,
3725}
3726
3727/// Query hint
3728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3729#[cfg_attr(feature = "bindings", derive(TS))]
3730#[cfg_attr(feature = "bindings", ts(export))]
3731pub struct Hint {
3732    pub expressions: Vec<HintExpression>,
3733}
3734
3735/// Individual hint expression
3736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3737#[cfg_attr(feature = "bindings", derive(TS))]
3738#[cfg_attr(feature = "bindings", ts(export))]
3739pub enum HintExpression {
3740    /// Function-style hint: USE_HASH(table)
3741    Function { name: String, args: Vec<Expression> },
3742    /// Simple identifier hint: PARALLEL
3743    Identifier(String),
3744    /// Raw hint text (unparsed)
3745    Raw(String),
3746}
3747
3748/// Pseudocolumn type
3749#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3750#[cfg_attr(feature = "bindings", derive(TS))]
3751#[cfg_attr(feature = "bindings", ts(export))]
3752pub enum PseudocolumnType {
3753    Rownum,      // Oracle ROWNUM
3754    Rowid,       // Oracle ROWID
3755    Level,       // Oracle LEVEL (for CONNECT BY)
3756    Sysdate,     // Oracle SYSDATE
3757    ObjectId,    // Oracle OBJECT_ID
3758    ObjectValue, // Oracle OBJECT_VALUE
3759}
3760
3761impl PseudocolumnType {
3762    pub fn as_str(&self) -> &'static str {
3763        match self {
3764            PseudocolumnType::Rownum => "ROWNUM",
3765            PseudocolumnType::Rowid => "ROWID",
3766            PseudocolumnType::Level => "LEVEL",
3767            PseudocolumnType::Sysdate => "SYSDATE",
3768            PseudocolumnType::ObjectId => "OBJECT_ID",
3769            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3770        }
3771    }
3772
3773    pub fn from_str(s: &str) -> Option<Self> {
3774        match s.to_uppercase().as_str() {
3775            "ROWNUM" => Some(PseudocolumnType::Rownum),
3776            "ROWID" => Some(PseudocolumnType::Rowid),
3777            "LEVEL" => Some(PseudocolumnType::Level),
3778            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3779            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3780            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3781            _ => None,
3782        }
3783    }
3784}
3785
3786/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3787/// These are special identifiers that should not be quoted
3788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3789#[cfg_attr(feature = "bindings", derive(TS))]
3790#[cfg_attr(feature = "bindings", ts(export))]
3791pub struct Pseudocolumn {
3792    pub kind: PseudocolumnType,
3793}
3794
3795impl Pseudocolumn {
3796    pub fn rownum() -> Self {
3797        Self {
3798            kind: PseudocolumnType::Rownum,
3799        }
3800    }
3801
3802    pub fn rowid() -> Self {
3803        Self {
3804            kind: PseudocolumnType::Rowid,
3805        }
3806    }
3807
3808    pub fn level() -> Self {
3809        Self {
3810            kind: PseudocolumnType::Level,
3811        }
3812    }
3813}
3814
3815/// Oracle CONNECT BY clause for hierarchical queries
3816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3817#[cfg_attr(feature = "bindings", derive(TS))]
3818#[cfg_attr(feature = "bindings", ts(export))]
3819pub struct Connect {
3820    /// START WITH condition (optional, can come before or after CONNECT BY)
3821    pub start: Option<Expression>,
3822    /// CONNECT BY condition (required, contains PRIOR references)
3823    pub connect: Expression,
3824    /// NOCYCLE keyword to prevent infinite loops
3825    pub nocycle: bool,
3826}
3827
3828/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3830#[cfg_attr(feature = "bindings", derive(TS))]
3831#[cfg_attr(feature = "bindings", ts(export))]
3832pub struct Prior {
3833    pub this: Expression,
3834}
3835
3836/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3838#[cfg_attr(feature = "bindings", derive(TS))]
3839#[cfg_attr(feature = "bindings", ts(export))]
3840pub struct ConnectByRoot {
3841    pub this: Expression,
3842}
3843
3844/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3845#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3846#[cfg_attr(feature = "bindings", derive(TS))]
3847#[cfg_attr(feature = "bindings", ts(export))]
3848pub struct MatchRecognize {
3849    /// Source table/expression
3850    pub this: Option<Box<Expression>>,
3851    /// PARTITION BY expressions
3852    pub partition_by: Option<Vec<Expression>>,
3853    /// ORDER BY expressions
3854    pub order_by: Option<Vec<Ordered>>,
3855    /// MEASURES definitions
3856    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3857    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3858    pub rows: Option<MatchRecognizeRows>,
3859    /// AFTER MATCH SKIP behavior
3860    pub after: Option<MatchRecognizeAfter>,
3861    /// PATTERN definition (stored as raw string for complex regex patterns)
3862    pub pattern: Option<String>,
3863    /// DEFINE clauses (pattern variable definitions)
3864    pub define: Option<Vec<(Identifier, Expression)>>,
3865    /// Optional alias for the result
3866    pub alias: Option<Identifier>,
3867    /// Whether AS keyword was explicitly present before alias
3868    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3869    pub alias_explicit_as: bool,
3870}
3871
3872/// MEASURES expression with optional RUNNING/FINAL semantics
3873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3874#[cfg_attr(feature = "bindings", derive(TS))]
3875#[cfg_attr(feature = "bindings", ts(export))]
3876pub struct MatchRecognizeMeasure {
3877    /// The measure expression
3878    pub this: Expression,
3879    /// RUNNING or FINAL semantics (Snowflake-specific)
3880    pub window_frame: Option<MatchRecognizeSemantics>,
3881}
3882
3883/// Semantics for MEASURES in MATCH_RECOGNIZE
3884#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3885#[cfg_attr(feature = "bindings", derive(TS))]
3886#[cfg_attr(feature = "bindings", ts(export))]
3887pub enum MatchRecognizeSemantics {
3888    Running,
3889    Final,
3890}
3891
3892/// Row output semantics for MATCH_RECOGNIZE
3893#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3894#[cfg_attr(feature = "bindings", derive(TS))]
3895#[cfg_attr(feature = "bindings", ts(export))]
3896pub enum MatchRecognizeRows {
3897    OneRowPerMatch,
3898    AllRowsPerMatch,
3899    AllRowsPerMatchShowEmptyMatches,
3900    AllRowsPerMatchOmitEmptyMatches,
3901    AllRowsPerMatchWithUnmatchedRows,
3902}
3903
3904/// AFTER MATCH SKIP behavior
3905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3906#[cfg_attr(feature = "bindings", derive(TS))]
3907#[cfg_attr(feature = "bindings", ts(export))]
3908pub enum MatchRecognizeAfter {
3909    PastLastRow,
3910    ToNextRow,
3911    ToFirst(Identifier),
3912    ToLast(Identifier),
3913}
3914
3915/// Represent a LIMIT clause that restricts the number of returned rows.
3916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3917#[cfg_attr(feature = "bindings", derive(TS))]
3918pub struct Limit {
3919    /// The limit count expression.
3920    pub this: Expression,
3921    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3922    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3923    pub percent: bool,
3924    /// Comments from before the LIMIT keyword (emitted after the limit value)
3925    #[serde(default)]
3926    #[serde(skip_serializing_if = "Vec::is_empty")]
3927    pub comments: Vec<String>,
3928}
3929
3930/// OFFSET clause
3931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3932#[cfg_attr(feature = "bindings", derive(TS))]
3933pub struct Offset {
3934    pub this: Expression,
3935    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3936    #[serde(skip_serializing_if = "Option::is_none", default)]
3937    pub rows: Option<bool>,
3938}
3939
3940/// TOP clause (SQL Server)
3941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3942#[cfg_attr(feature = "bindings", derive(TS))]
3943pub struct Top {
3944    pub this: Expression,
3945    pub percent: bool,
3946    pub with_ties: bool,
3947    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3948    #[serde(default)]
3949    pub parenthesized: bool,
3950}
3951
3952/// FETCH FIRST/NEXT clause (SQL standard)
3953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3954#[cfg_attr(feature = "bindings", derive(TS))]
3955pub struct Fetch {
3956    /// FIRST or NEXT
3957    pub direction: String,
3958    /// Count expression (optional)
3959    pub count: Option<Expression>,
3960    /// PERCENT modifier
3961    pub percent: bool,
3962    /// ROWS or ROW keyword present
3963    pub rows: bool,
3964    /// WITH TIES modifier
3965    pub with_ties: bool,
3966}
3967
3968/// Represent a QUALIFY clause for filtering on window function results.
3969///
3970/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3971/// typically references a window function (e.g.
3972/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3974#[cfg_attr(feature = "bindings", derive(TS))]
3975pub struct Qualify {
3976    /// The filter predicate over window function results.
3977    pub this: Expression,
3978}
3979
3980/// SAMPLE / TABLESAMPLE clause
3981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3982#[cfg_attr(feature = "bindings", derive(TS))]
3983pub struct Sample {
3984    pub method: SampleMethod,
3985    pub size: Expression,
3986    pub seed: Option<Expression>,
3987    /// ClickHouse OFFSET expression after SAMPLE size
3988    #[serde(default)]
3989    pub offset: Option<Expression>,
3990    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3991    pub unit_after_size: bool,
3992    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3993    #[serde(default)]
3994    pub use_sample_keyword: bool,
3995    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3996    #[serde(default)]
3997    pub explicit_method: bool,
3998    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3999    #[serde(default)]
4000    pub method_before_size: bool,
4001    /// Whether SEED keyword was used (true) or REPEATABLE (false)
4002    #[serde(default)]
4003    pub use_seed_keyword: bool,
4004    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
4005    pub bucket_numerator: Option<Box<Expression>>,
4006    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
4007    pub bucket_denominator: Option<Box<Expression>>,
4008    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
4009    pub bucket_field: Option<Box<Expression>>,
4010    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
4011    #[serde(default)]
4012    pub is_using_sample: bool,
4013    /// Whether the unit was explicitly PERCENT (vs ROWS)
4014    #[serde(default)]
4015    pub is_percent: bool,
4016    /// Whether to suppress method output (for cross-dialect transpilation)
4017    #[serde(default)]
4018    pub suppress_method_output: bool,
4019}
4020
4021/// Sample method
4022#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4023#[cfg_attr(feature = "bindings", derive(TS))]
4024pub enum SampleMethod {
4025    Bernoulli,
4026    System,
4027    Block,
4028    Row,
4029    Percent,
4030    /// Hive bucket sampling
4031    Bucket,
4032    /// DuckDB reservoir sampling
4033    Reservoir,
4034}
4035
4036/// Named window definition (WINDOW w AS (...))
4037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4038#[cfg_attr(feature = "bindings", derive(TS))]
4039pub struct NamedWindow {
4040    pub name: Identifier,
4041    pub spec: Over,
4042}
4043
4044/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
4045///
4046/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
4047/// that reference themselves. Each CTE is defined in the `ctes` vector and
4048/// can be referenced by name in subsequent CTEs and in the main query body.
4049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4050#[cfg_attr(feature = "bindings", derive(TS))]
4051pub struct With {
4052    /// The list of CTE definitions, in order.
4053    pub ctes: Vec<Cte>,
4054    /// Whether the WITH RECURSIVE keyword was used.
4055    pub recursive: bool,
4056    /// Leading comments before the statement
4057    #[serde(default)]
4058    pub leading_comments: Vec<String>,
4059    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
4060    #[serde(default, skip_serializing_if = "Option::is_none")]
4061    pub search: Option<Box<Expression>>,
4062}
4063
4064/// Represent a single Common Table Expression definition.
4065///
4066/// A CTE has a name (`alias`), an optional column list, and a body query.
4067/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
4068/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
4069/// the expression comes before the alias (`alias_first`).
4070#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4071#[cfg_attr(feature = "bindings", derive(TS))]
4072pub struct Cte {
4073    /// The CTE name.
4074    pub alias: Identifier,
4075    /// The CTE body (typically a SELECT, UNION, etc.).
4076    pub this: Expression,
4077    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
4078    pub columns: Vec<Identifier>,
4079    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
4080    pub materialized: Option<bool>,
4081    /// USING KEY (columns) for DuckDB recursive CTEs
4082    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4083    pub key_expressions: Vec<Identifier>,
4084    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
4085    #[serde(default)]
4086    pub alias_first: bool,
4087    /// Comments associated with this CTE (placed after alias name, before AS)
4088    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4089    pub comments: Vec<String>,
4090}
4091
4092/// Window specification
4093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4094#[cfg_attr(feature = "bindings", derive(TS))]
4095pub struct WindowSpec {
4096    pub partition_by: Vec<Expression>,
4097    pub order_by: Vec<Ordered>,
4098    pub frame: Option<WindowFrame>,
4099}
4100
4101/// OVER clause
4102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4103#[cfg_attr(feature = "bindings", derive(TS))]
4104pub struct Over {
4105    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
4106    pub window_name: Option<Identifier>,
4107    pub partition_by: Vec<Expression>,
4108    pub order_by: Vec<Ordered>,
4109    pub frame: Option<WindowFrame>,
4110    pub alias: Option<Identifier>,
4111}
4112
4113/// Window frame
4114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4115#[cfg_attr(feature = "bindings", derive(TS))]
4116pub struct WindowFrame {
4117    pub kind: WindowFrameKind,
4118    pub start: WindowFrameBound,
4119    pub end: Option<WindowFrameBound>,
4120    pub exclude: Option<WindowFrameExclude>,
4121    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
4122    #[serde(default, skip_serializing_if = "Option::is_none")]
4123    pub kind_text: Option<String>,
4124    /// Original text of the start bound side keyword (e.g. "preceding")
4125    #[serde(default, skip_serializing_if = "Option::is_none")]
4126    pub start_side_text: Option<String>,
4127    /// Original text of the end bound side keyword
4128    #[serde(default, skip_serializing_if = "Option::is_none")]
4129    pub end_side_text: Option<String>,
4130}
4131
4132#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4133#[cfg_attr(feature = "bindings", derive(TS))]
4134pub enum WindowFrameKind {
4135    Rows,
4136    Range,
4137    Groups,
4138}
4139
4140/// EXCLUDE clause for window frames
4141#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4142#[cfg_attr(feature = "bindings", derive(TS))]
4143pub enum WindowFrameExclude {
4144    CurrentRow,
4145    Group,
4146    Ties,
4147    NoOthers,
4148}
4149
4150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4151#[cfg_attr(feature = "bindings", derive(TS))]
4152pub enum WindowFrameBound {
4153    CurrentRow,
4154    UnboundedPreceding,
4155    UnboundedFollowing,
4156    Preceding(Box<Expression>),
4157    Following(Box<Expression>),
4158    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
4159    BarePreceding,
4160    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
4161    BareFollowing,
4162    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
4163    Value(Box<Expression>),
4164}
4165
4166/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
4167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4168#[cfg_attr(feature = "bindings", derive(TS))]
4169pub struct StructField {
4170    pub name: String,
4171    pub data_type: DataType,
4172    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4173    pub options: Vec<Expression>,
4174    #[serde(default, skip_serializing_if = "Option::is_none")]
4175    pub comment: Option<String>,
4176}
4177
4178impl StructField {
4179    /// Create a new struct field without options
4180    pub fn new(name: String, data_type: DataType) -> Self {
4181        Self {
4182            name,
4183            data_type,
4184            options: Vec::new(),
4185            comment: None,
4186        }
4187    }
4188
4189    /// Create a new struct field with options
4190    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
4191        Self {
4192            name,
4193            data_type,
4194            options,
4195            comment: None,
4196        }
4197    }
4198
4199    /// Create a new struct field with options and comment
4200    pub fn with_options_and_comment(
4201        name: String,
4202        data_type: DataType,
4203        options: Vec<Expression>,
4204        comment: Option<String>,
4205    ) -> Self {
4206        Self {
4207            name,
4208            data_type,
4209            options,
4210            comment,
4211        }
4212    }
4213}
4214
4215/// Enumerate all SQL data types recognized by the parser.
4216///
4217/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
4218/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
4219/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
4220///
4221/// This enum is used in CAST expressions, column definitions, function return
4222/// types, and anywhere a data type specification appears in SQL.
4223///
4224/// Types that do not match any known variant fall through to `Custom { name }`,
4225/// preserving the original type name for round-trip fidelity.
4226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4227#[cfg_attr(feature = "bindings", derive(TS))]
4228#[serde(tag = "data_type", rename_all = "snake_case")]
4229pub enum DataType {
4230    // Numeric
4231    Boolean,
4232    TinyInt {
4233        length: Option<u32>,
4234    },
4235    SmallInt {
4236        length: Option<u32>,
4237    },
4238    /// Int type with optional length. `integer_spelling` indicates whether the original
4239    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
4240    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
4241    Int {
4242        length: Option<u32>,
4243        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4244        integer_spelling: bool,
4245    },
4246    BigInt {
4247        length: Option<u32>,
4248    },
4249    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
4250    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
4251    /// preserve the original spelling.
4252    Float {
4253        precision: Option<u32>,
4254        scale: Option<u32>,
4255        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4256        real_spelling: bool,
4257    },
4258    Double {
4259        precision: Option<u32>,
4260        scale: Option<u32>,
4261    },
4262    Decimal {
4263        precision: Option<u32>,
4264        scale: Option<u32>,
4265    },
4266
4267    // String
4268    Char {
4269        length: Option<u32>,
4270    },
4271    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
4272    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
4273    VarChar {
4274        length: Option<u32>,
4275        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
4276        parenthesized_length: bool,
4277    },
4278    /// String type with optional max length (BigQuery STRING(n))
4279    String {
4280        length: Option<u32>,
4281    },
4282    Text,
4283    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
4284    TextWithLength {
4285        length: u32,
4286    },
4287
4288    // Binary
4289    Binary {
4290        length: Option<u32>,
4291    },
4292    VarBinary {
4293        length: Option<u32>,
4294    },
4295    Blob,
4296
4297    // Bit
4298    Bit {
4299        length: Option<u32>,
4300    },
4301    VarBit {
4302        length: Option<u32>,
4303    },
4304
4305    // Date/Time
4306    Date,
4307    Time {
4308        precision: Option<u32>,
4309        #[serde(default)]
4310        timezone: bool,
4311    },
4312    Timestamp {
4313        precision: Option<u32>,
4314        timezone: bool,
4315    },
4316    Interval {
4317        unit: Option<String>,
4318        /// For range intervals like INTERVAL DAY TO HOUR
4319        #[serde(default, skip_serializing_if = "Option::is_none")]
4320        to: Option<String>,
4321    },
4322
4323    // JSON
4324    Json,
4325    JsonB,
4326
4327    // UUID
4328    Uuid,
4329
4330    // Array
4331    Array {
4332        element_type: Box<DataType>,
4333        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
4334        #[serde(default, skip_serializing_if = "Option::is_none")]
4335        dimension: Option<u32>,
4336    },
4337
4338    /// List type (Materialize): INT LIST, TEXT LIST LIST
4339    /// Uses postfix LIST syntax instead of ARRAY<T>
4340    List {
4341        element_type: Box<DataType>,
4342    },
4343
4344    // Struct/Map
4345    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
4346    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
4347    Struct {
4348        fields: Vec<StructField>,
4349        nested: bool,
4350    },
4351    Map {
4352        key_type: Box<DataType>,
4353        value_type: Box<DataType>,
4354    },
4355
4356    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
4357    Enum {
4358        values: Vec<String>,
4359        #[serde(default, skip_serializing_if = "Vec::is_empty")]
4360        assignments: Vec<Option<String>>,
4361    },
4362
4363    // Set type (MySQL): SET('a', 'b', 'c')
4364    Set {
4365        values: Vec<String>,
4366    },
4367
4368    // Union type (DuckDB): UNION(num INT, str TEXT)
4369    Union {
4370        fields: Vec<(String, DataType)>,
4371    },
4372
4373    // Vector (Snowflake / SingleStore)
4374    Vector {
4375        #[serde(default)]
4376        element_type: Option<Box<DataType>>,
4377        dimension: Option<u32>,
4378    },
4379
4380    // Object (Snowflake structured type)
4381    // fields: Vec of (field_name, field_type, not_null)
4382    Object {
4383        fields: Vec<(String, DataType, bool)>,
4384        modifier: Option<String>,
4385    },
4386
4387    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
4388    Nullable {
4389        inner: Box<DataType>,
4390    },
4391
4392    // Custom/User-defined
4393    Custom {
4394        name: String,
4395    },
4396
4397    // Spatial types
4398    Geometry {
4399        subtype: Option<String>,
4400        srid: Option<u32>,
4401    },
4402    Geography {
4403        subtype: Option<String>,
4404        srid: Option<u32>,
4405    },
4406
4407    // Character Set (for CONVERT USING in MySQL)
4408    // Renders as CHAR CHARACTER SET {name} in cast target
4409    CharacterSet {
4410        name: String,
4411    },
4412
4413    // Unknown
4414    Unknown,
4415}
4416
4417/// Array expression
4418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4419#[cfg_attr(feature = "bindings", derive(TS))]
4420#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
4421pub struct Array {
4422    pub expressions: Vec<Expression>,
4423}
4424
4425/// Struct expression
4426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4427#[cfg_attr(feature = "bindings", derive(TS))]
4428pub struct Struct {
4429    pub fields: Vec<(Option<String>, Expression)>,
4430}
4431
4432/// Tuple expression
4433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4434#[cfg_attr(feature = "bindings", derive(TS))]
4435pub struct Tuple {
4436    pub expressions: Vec<Expression>,
4437}
4438
4439/// Interval expression
4440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4441#[cfg_attr(feature = "bindings", derive(TS))]
4442pub struct Interval {
4443    /// The value expression (e.g., '1', 5, column_ref)
4444    pub this: Option<Expression>,
4445    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
4446    pub unit: Option<IntervalUnitSpec>,
4447}
4448
4449/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
4450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4451#[cfg_attr(feature = "bindings", derive(TS))]
4452#[serde(tag = "type", rename_all = "snake_case")]
4453pub enum IntervalUnitSpec {
4454    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
4455    Simple {
4456        unit: IntervalUnit,
4457        /// Whether to use plural form (e.g., DAYS vs DAY)
4458        use_plural: bool,
4459    },
4460    /// Interval span (e.g., HOUR TO SECOND)
4461    Span(IntervalSpan),
4462    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4463    /// The start and end can be expressions like function calls with precision
4464    ExprSpan(IntervalSpanExpr),
4465    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
4466    Expr(Box<Expression>),
4467}
4468
4469/// Interval span for ranges like HOUR TO SECOND
4470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4471#[cfg_attr(feature = "bindings", derive(TS))]
4472pub struct IntervalSpan {
4473    /// Start unit (e.g., HOUR)
4474    pub this: IntervalUnit,
4475    /// End unit (e.g., SECOND)
4476    pub expression: IntervalUnit,
4477}
4478
4479/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
4480/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
4481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4482#[cfg_attr(feature = "bindings", derive(TS))]
4483pub struct IntervalSpanExpr {
4484    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
4485    pub this: Box<Expression>,
4486    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
4487    pub expression: Box<Expression>,
4488}
4489
4490#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4491#[cfg_attr(feature = "bindings", derive(TS))]
4492pub enum IntervalUnit {
4493    Year,
4494    Quarter,
4495    Month,
4496    Week,
4497    Day,
4498    Hour,
4499    Minute,
4500    Second,
4501    Millisecond,
4502    Microsecond,
4503    Nanosecond,
4504}
4505
4506/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4508#[cfg_attr(feature = "bindings", derive(TS))]
4509pub struct Command {
4510    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4511    pub this: String,
4512}
4513
4514/// EXEC/EXECUTE statement (TSQL stored procedure call)
4515/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4517#[cfg_attr(feature = "bindings", derive(TS))]
4518pub struct ExecuteStatement {
4519    /// The procedure name (can be qualified: schema.proc_name)
4520    pub this: Expression,
4521    /// Named parameters: @param=value pairs
4522    #[serde(default)]
4523    pub parameters: Vec<ExecuteParameter>,
4524}
4525
4526/// Named parameter in EXEC statement: @name=value
4527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4528#[cfg_attr(feature = "bindings", derive(TS))]
4529pub struct ExecuteParameter {
4530    /// Parameter name (including @)
4531    pub name: String,
4532    /// Parameter value
4533    pub value: Expression,
4534}
4535
4536/// KILL statement (MySQL/MariaDB)
4537/// KILL [CONNECTION | QUERY] <id>
4538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4539#[cfg_attr(feature = "bindings", derive(TS))]
4540pub struct Kill {
4541    /// The target (process ID or connection ID)
4542    pub this: Expression,
4543    /// Optional kind: "CONNECTION" or "QUERY"
4544    pub kind: Option<String>,
4545}
4546
4547/// Raw/unparsed SQL
4548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4549#[cfg_attr(feature = "bindings", derive(TS))]
4550pub struct Raw {
4551    pub sql: String,
4552}
4553
4554// ============================================================================
4555// Function expression types
4556// ============================================================================
4557
4558/// Generic unary function (takes a single argument)
4559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4560#[cfg_attr(feature = "bindings", derive(TS))]
4561pub struct UnaryFunc {
4562    pub this: Expression,
4563    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4564    #[serde(skip_serializing_if = "Option::is_none", default)]
4565    pub original_name: Option<String>,
4566    /// Inferred data type from type annotation
4567    #[serde(default, skip_serializing_if = "Option::is_none")]
4568    pub inferred_type: Option<DataType>,
4569}
4570
4571impl UnaryFunc {
4572    /// Create a new UnaryFunc with no original_name
4573    pub fn new(this: Expression) -> Self {
4574        Self {
4575            this,
4576            original_name: None,
4577            inferred_type: None,
4578        }
4579    }
4580
4581    /// Create a new UnaryFunc with an original name for round-trip preservation
4582    pub fn with_name(this: Expression, name: String) -> Self {
4583        Self {
4584            this,
4585            original_name: Some(name),
4586            inferred_type: None,
4587        }
4588    }
4589}
4590
4591/// CHAR/CHR function with multiple args and optional USING charset
4592/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4593/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4595#[cfg_attr(feature = "bindings", derive(TS))]
4596pub struct CharFunc {
4597    pub args: Vec<Expression>,
4598    #[serde(skip_serializing_if = "Option::is_none", default)]
4599    pub charset: Option<String>,
4600    /// Original function name (CHAR or CHR), defaults to CHAR
4601    #[serde(skip_serializing_if = "Option::is_none", default)]
4602    pub name: Option<String>,
4603}
4604
4605/// Generic binary function (takes two arguments)
4606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4607#[cfg_attr(feature = "bindings", derive(TS))]
4608pub struct BinaryFunc {
4609    pub this: Expression,
4610    pub expression: Expression,
4611    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4612    #[serde(skip_serializing_if = "Option::is_none", default)]
4613    pub original_name: Option<String>,
4614    /// Inferred data type from type annotation
4615    #[serde(default, skip_serializing_if = "Option::is_none")]
4616    pub inferred_type: Option<DataType>,
4617}
4618
4619/// Variable argument function
4620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4621#[cfg_attr(feature = "bindings", derive(TS))]
4622pub struct VarArgFunc {
4623    pub expressions: Vec<Expression>,
4624    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4625    #[serde(skip_serializing_if = "Option::is_none", default)]
4626    pub original_name: Option<String>,
4627    /// Inferred data type from type annotation
4628    #[serde(default, skip_serializing_if = "Option::is_none")]
4629    pub inferred_type: Option<DataType>,
4630}
4631
4632/// CONCAT_WS function
4633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4634#[cfg_attr(feature = "bindings", derive(TS))]
4635pub struct ConcatWs {
4636    pub separator: Expression,
4637    pub expressions: Vec<Expression>,
4638}
4639
4640/// SUBSTRING function
4641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4642#[cfg_attr(feature = "bindings", derive(TS))]
4643pub struct SubstringFunc {
4644    pub this: Expression,
4645    pub start: Expression,
4646    pub length: Option<Expression>,
4647    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4648    #[serde(default)]
4649    pub from_for_syntax: bool,
4650}
4651
4652/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4654#[cfg_attr(feature = "bindings", derive(TS))]
4655pub struct OverlayFunc {
4656    pub this: Expression,
4657    pub replacement: Expression,
4658    pub from: Expression,
4659    pub length: Option<Expression>,
4660}
4661
4662/// TRIM function
4663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4664#[cfg_attr(feature = "bindings", derive(TS))]
4665pub struct TrimFunc {
4666    pub this: Expression,
4667    pub characters: Option<Expression>,
4668    pub position: TrimPosition,
4669    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4670    #[serde(default)]
4671    pub sql_standard_syntax: bool,
4672    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4673    #[serde(default)]
4674    pub position_explicit: bool,
4675}
4676
4677#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4678#[cfg_attr(feature = "bindings", derive(TS))]
4679pub enum TrimPosition {
4680    Both,
4681    Leading,
4682    Trailing,
4683}
4684
4685/// REPLACE function
4686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4687#[cfg_attr(feature = "bindings", derive(TS))]
4688pub struct ReplaceFunc {
4689    pub this: Expression,
4690    pub old: Expression,
4691    pub new: Expression,
4692}
4693
4694/// LEFT/RIGHT function
4695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4696#[cfg_attr(feature = "bindings", derive(TS))]
4697pub struct LeftRightFunc {
4698    pub this: Expression,
4699    pub length: Expression,
4700}
4701
4702/// REPEAT function
4703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4704#[cfg_attr(feature = "bindings", derive(TS))]
4705pub struct RepeatFunc {
4706    pub this: Expression,
4707    pub times: Expression,
4708}
4709
4710/// LPAD/RPAD function
4711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4712#[cfg_attr(feature = "bindings", derive(TS))]
4713pub struct PadFunc {
4714    pub this: Expression,
4715    pub length: Expression,
4716    pub fill: Option<Expression>,
4717}
4718
4719/// SPLIT function
4720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4721#[cfg_attr(feature = "bindings", derive(TS))]
4722pub struct SplitFunc {
4723    pub this: Expression,
4724    pub delimiter: Expression,
4725}
4726
4727/// REGEXP_LIKE function
4728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4729#[cfg_attr(feature = "bindings", derive(TS))]
4730pub struct RegexpFunc {
4731    pub this: Expression,
4732    pub pattern: Expression,
4733    pub flags: Option<Expression>,
4734}
4735
4736/// REGEXP_REPLACE function
4737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4738#[cfg_attr(feature = "bindings", derive(TS))]
4739pub struct RegexpReplaceFunc {
4740    pub this: Expression,
4741    pub pattern: Expression,
4742    pub replacement: Expression,
4743    pub flags: Option<Expression>,
4744}
4745
4746/// REGEXP_EXTRACT function
4747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4748#[cfg_attr(feature = "bindings", derive(TS))]
4749pub struct RegexpExtractFunc {
4750    pub this: Expression,
4751    pub pattern: Expression,
4752    pub group: Option<Expression>,
4753}
4754
4755/// ROUND function
4756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4757#[cfg_attr(feature = "bindings", derive(TS))]
4758pub struct RoundFunc {
4759    pub this: Expression,
4760    pub decimals: Option<Expression>,
4761}
4762
4763/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4765#[cfg_attr(feature = "bindings", derive(TS))]
4766pub struct FloorFunc {
4767    pub this: Expression,
4768    pub scale: Option<Expression>,
4769    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4770    #[serde(skip_serializing_if = "Option::is_none", default)]
4771    pub to: Option<Expression>,
4772}
4773
4774/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4775#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4776#[cfg_attr(feature = "bindings", derive(TS))]
4777pub struct CeilFunc {
4778    pub this: Expression,
4779    #[serde(skip_serializing_if = "Option::is_none", default)]
4780    pub decimals: Option<Expression>,
4781    /// Time unit for Druid-style CEIL(time TO unit) syntax
4782    #[serde(skip_serializing_if = "Option::is_none", default)]
4783    pub to: Option<Expression>,
4784}
4785
4786/// LOG function
4787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4788#[cfg_attr(feature = "bindings", derive(TS))]
4789pub struct LogFunc {
4790    pub this: Expression,
4791    pub base: Option<Expression>,
4792}
4793
4794/// CURRENT_DATE (no arguments)
4795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4796#[cfg_attr(feature = "bindings", derive(TS))]
4797pub struct CurrentDate;
4798
4799/// CURRENT_TIME
4800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4801#[cfg_attr(feature = "bindings", derive(TS))]
4802pub struct CurrentTime {
4803    pub precision: Option<u32>,
4804}
4805
4806/// CURRENT_TIMESTAMP
4807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4808#[cfg_attr(feature = "bindings", derive(TS))]
4809pub struct CurrentTimestamp {
4810    pub precision: Option<u32>,
4811    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4812    #[serde(default)]
4813    pub sysdate: bool,
4814}
4815
4816/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4818#[cfg_attr(feature = "bindings", derive(TS))]
4819pub struct CurrentTimestampLTZ {
4820    pub precision: Option<u32>,
4821}
4822
4823/// AT TIME ZONE expression for timezone conversion
4824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4825#[cfg_attr(feature = "bindings", derive(TS))]
4826pub struct AtTimeZone {
4827    /// The expression to convert
4828    pub this: Expression,
4829    /// The target timezone
4830    pub zone: Expression,
4831}
4832
4833/// DATE_ADD / DATE_SUB function
4834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4835#[cfg_attr(feature = "bindings", derive(TS))]
4836pub struct DateAddFunc {
4837    pub this: Expression,
4838    pub interval: Expression,
4839    pub unit: IntervalUnit,
4840}
4841
4842/// DATEDIFF function
4843#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4844#[cfg_attr(feature = "bindings", derive(TS))]
4845pub struct DateDiffFunc {
4846    pub this: Expression,
4847    pub expression: Expression,
4848    pub unit: Option<IntervalUnit>,
4849}
4850
4851/// DATE_TRUNC function
4852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4853#[cfg_attr(feature = "bindings", derive(TS))]
4854pub struct DateTruncFunc {
4855    pub this: Expression,
4856    pub unit: DateTimeField,
4857}
4858
4859/// EXTRACT function
4860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4861#[cfg_attr(feature = "bindings", derive(TS))]
4862pub struct ExtractFunc {
4863    pub this: Expression,
4864    pub field: DateTimeField,
4865}
4866
4867#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4868#[cfg_attr(feature = "bindings", derive(TS))]
4869pub enum DateTimeField {
4870    Year,
4871    Month,
4872    Day,
4873    Hour,
4874    Minute,
4875    Second,
4876    Millisecond,
4877    Microsecond,
4878    DayOfWeek,
4879    DayOfYear,
4880    Week,
4881    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4882    WeekWithModifier(String),
4883    Quarter,
4884    Epoch,
4885    Timezone,
4886    TimezoneHour,
4887    TimezoneMinute,
4888    Date,
4889    Time,
4890    /// Custom datetime field for dialect-specific or arbitrary fields
4891    Custom(String),
4892}
4893
4894/// TO_DATE function
4895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4896#[cfg_attr(feature = "bindings", derive(TS))]
4897pub struct ToDateFunc {
4898    pub this: Expression,
4899    pub format: Option<Expression>,
4900}
4901
4902/// TO_TIMESTAMP function
4903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4904#[cfg_attr(feature = "bindings", derive(TS))]
4905pub struct ToTimestampFunc {
4906    pub this: Expression,
4907    pub format: Option<Expression>,
4908}
4909
4910/// IF function
4911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4912#[cfg_attr(feature = "bindings", derive(TS))]
4913pub struct IfFunc {
4914    pub condition: Expression,
4915    pub true_value: Expression,
4916    pub false_value: Option<Expression>,
4917    /// Original function name (IF, IFF, IIF) for round-trip preservation
4918    #[serde(skip_serializing_if = "Option::is_none", default)]
4919    pub original_name: Option<String>,
4920}
4921
4922/// NVL2 function
4923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4924#[cfg_attr(feature = "bindings", derive(TS))]
4925pub struct Nvl2Func {
4926    pub this: Expression,
4927    pub true_value: Expression,
4928    pub false_value: Expression,
4929}
4930
4931// ============================================================================
4932// Typed Aggregate Function types
4933// ============================================================================
4934
4935/// Generic aggregate function base type
4936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4937#[cfg_attr(feature = "bindings", derive(TS))]
4938pub struct AggFunc {
4939    pub this: Expression,
4940    pub distinct: bool,
4941    pub filter: Option<Expression>,
4942    pub order_by: Vec<Ordered>,
4943    /// Original function name (case-preserving) when parsed from SQL
4944    #[serde(skip_serializing_if = "Option::is_none", default)]
4945    pub name: Option<String>,
4946    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4947    #[serde(skip_serializing_if = "Option::is_none", default)]
4948    pub ignore_nulls: Option<bool>,
4949    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4950    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4951    #[serde(skip_serializing_if = "Option::is_none", default)]
4952    pub having_max: Option<(Box<Expression>, bool)>,
4953    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4954    #[serde(skip_serializing_if = "Option::is_none", default)]
4955    pub limit: Option<Box<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/// COUNT function with optional star
4962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4963#[cfg_attr(feature = "bindings", derive(TS))]
4964pub struct CountFunc {
4965    pub this: Option<Expression>,
4966    pub star: bool,
4967    pub distinct: bool,
4968    pub filter: Option<Expression>,
4969    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4970    #[serde(default, skip_serializing_if = "Option::is_none")]
4971    pub ignore_nulls: Option<bool>,
4972    /// Original function name for case preservation (e.g., "count" or "COUNT")
4973    #[serde(default, skip_serializing_if = "Option::is_none")]
4974    pub original_name: Option<String>,
4975}
4976
4977/// GROUP_CONCAT function (MySQL style)
4978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4979#[cfg_attr(feature = "bindings", derive(TS))]
4980pub struct GroupConcatFunc {
4981    pub this: Expression,
4982    pub separator: Option<Expression>,
4983    pub order_by: Option<Vec<Ordered>>,
4984    pub distinct: bool,
4985    pub filter: Option<Expression>,
4986}
4987
4988/// STRING_AGG function (PostgreSQL/Standard SQL)
4989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4990#[cfg_attr(feature = "bindings", derive(TS))]
4991pub struct StringAggFunc {
4992    pub this: Expression,
4993    #[serde(default)]
4994    pub separator: Option<Expression>,
4995    #[serde(default)]
4996    pub order_by: Option<Vec<Ordered>>,
4997    #[serde(default)]
4998    pub distinct: bool,
4999    #[serde(default)]
5000    pub filter: Option<Expression>,
5001    /// BigQuery LIMIT inside STRING_AGG
5002    #[serde(default, skip_serializing_if = "Option::is_none")]
5003    pub limit: Option<Box<Expression>>,
5004}
5005
5006/// LISTAGG function (Oracle style)
5007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5008#[cfg_attr(feature = "bindings", derive(TS))]
5009pub struct ListAggFunc {
5010    pub this: Expression,
5011    pub separator: Option<Expression>,
5012    pub on_overflow: Option<ListAggOverflow>,
5013    pub order_by: Option<Vec<Ordered>>,
5014    pub distinct: bool,
5015    pub filter: Option<Expression>,
5016}
5017
5018/// LISTAGG ON OVERFLOW behavior
5019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5020#[cfg_attr(feature = "bindings", derive(TS))]
5021pub enum ListAggOverflow {
5022    Error,
5023    Truncate {
5024        filler: Option<Expression>,
5025        with_count: bool,
5026    },
5027}
5028
5029/// SUM_IF / COUNT_IF function
5030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5031#[cfg_attr(feature = "bindings", derive(TS))]
5032pub struct SumIfFunc {
5033    pub this: Expression,
5034    pub condition: Expression,
5035    pub filter: Option<Expression>,
5036}
5037
5038/// APPROX_PERCENTILE function
5039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5040#[cfg_attr(feature = "bindings", derive(TS))]
5041pub struct ApproxPercentileFunc {
5042    pub this: Expression,
5043    pub percentile: Expression,
5044    pub accuracy: Option<Expression>,
5045    pub filter: Option<Expression>,
5046}
5047
5048/// PERCENTILE_CONT / PERCENTILE_DISC function
5049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5050#[cfg_attr(feature = "bindings", derive(TS))]
5051pub struct PercentileFunc {
5052    pub this: Expression,
5053    pub percentile: Expression,
5054    pub order_by: Option<Vec<Ordered>>,
5055    pub filter: Option<Expression>,
5056}
5057
5058// ============================================================================
5059// Typed Window Function types
5060// ============================================================================
5061
5062/// ROW_NUMBER function (no arguments)
5063#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5064#[cfg_attr(feature = "bindings", derive(TS))]
5065pub struct RowNumber;
5066
5067/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5069#[cfg_attr(feature = "bindings", derive(TS))]
5070pub struct Rank {
5071    /// DuckDB: RANK(ORDER BY col) - order by inside function
5072    #[serde(default, skip_serializing_if = "Option::is_none")]
5073    pub order_by: Option<Vec<Ordered>>,
5074    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5075    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5076    pub args: Vec<Expression>,
5077}
5078
5079/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
5080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5081#[cfg_attr(feature = "bindings", derive(TS))]
5082pub struct DenseRank {
5083    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5084    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5085    pub args: Vec<Expression>,
5086}
5087
5088/// NTILE function (DuckDB allows ORDER BY inside)
5089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5090#[cfg_attr(feature = "bindings", derive(TS))]
5091pub struct NTileFunc {
5092    /// num_buckets is optional to support Databricks NTILE() without arguments
5093    #[serde(default, skip_serializing_if = "Option::is_none")]
5094    pub num_buckets: Option<Expression>,
5095    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
5096    #[serde(default, skip_serializing_if = "Option::is_none")]
5097    pub order_by: Option<Vec<Ordered>>,
5098}
5099
5100/// LEAD / LAG function
5101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5102#[cfg_attr(feature = "bindings", derive(TS))]
5103pub struct LeadLagFunc {
5104    pub this: Expression,
5105    pub offset: Option<Expression>,
5106    pub default: Option<Expression>,
5107    pub ignore_nulls: bool,
5108}
5109
5110/// FIRST_VALUE / LAST_VALUE function
5111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5112#[cfg_attr(feature = "bindings", derive(TS))]
5113pub struct ValueFunc {
5114    pub this: Expression,
5115    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5116    #[serde(default, skip_serializing_if = "Option::is_none")]
5117    pub ignore_nulls: Option<bool>,
5118}
5119
5120/// NTH_VALUE function
5121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5122#[cfg_attr(feature = "bindings", derive(TS))]
5123pub struct NthValueFunc {
5124    pub this: Expression,
5125    pub offset: Expression,
5126    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
5127    #[serde(default, skip_serializing_if = "Option::is_none")]
5128    pub ignore_nulls: Option<bool>,
5129    /// Snowflake FROM FIRST / FROM LAST clause
5130    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
5131    #[serde(default, skip_serializing_if = "Option::is_none")]
5132    pub from_first: Option<bool>,
5133}
5134
5135/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5137#[cfg_attr(feature = "bindings", derive(TS))]
5138pub struct PercentRank {
5139    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
5140    #[serde(default, skip_serializing_if = "Option::is_none")]
5141    pub order_by: Option<Vec<Ordered>>,
5142    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5143    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5144    pub args: Vec<Expression>,
5145}
5146
5147/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
5148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5149#[cfg_attr(feature = "bindings", derive(TS))]
5150pub struct CumeDist {
5151    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
5152    #[serde(default, skip_serializing_if = "Option::is_none")]
5153    pub order_by: Option<Vec<Ordered>>,
5154    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
5155    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5156    pub args: Vec<Expression>,
5157}
5158
5159// ============================================================================
5160// Additional String Function types
5161// ============================================================================
5162
5163/// POSITION/INSTR function
5164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5165#[cfg_attr(feature = "bindings", derive(TS))]
5166pub struct PositionFunc {
5167    pub substring: Expression,
5168    pub string: Expression,
5169    pub start: Option<Expression>,
5170}
5171
5172// ============================================================================
5173// Additional Math Function types
5174// ============================================================================
5175
5176/// RANDOM function (no arguments)
5177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5178#[cfg_attr(feature = "bindings", derive(TS))]
5179pub struct Random;
5180
5181/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
5182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5183#[cfg_attr(feature = "bindings", derive(TS))]
5184pub struct Rand {
5185    pub seed: Option<Box<Expression>>,
5186    /// Teradata RANDOM lower bound
5187    #[serde(default)]
5188    pub lower: Option<Box<Expression>>,
5189    /// Teradata RANDOM upper bound
5190    #[serde(default)]
5191    pub upper: Option<Box<Expression>>,
5192}
5193
5194/// TRUNCATE / TRUNC function
5195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5196#[cfg_attr(feature = "bindings", derive(TS))]
5197pub struct TruncateFunc {
5198    pub this: Expression,
5199    pub decimals: Option<Expression>,
5200}
5201
5202/// PI function (no arguments)
5203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5204#[cfg_attr(feature = "bindings", derive(TS))]
5205pub struct Pi;
5206
5207// ============================================================================
5208// Control Flow Function types
5209// ============================================================================
5210
5211/// DECODE function (Oracle style)
5212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5213#[cfg_attr(feature = "bindings", derive(TS))]
5214pub struct DecodeFunc {
5215    pub this: Expression,
5216    pub search_results: Vec<(Expression, Expression)>,
5217    pub default: Option<Expression>,
5218}
5219
5220// ============================================================================
5221// Additional Date/Time Function types
5222// ============================================================================
5223
5224/// DATE_FORMAT / FORMAT_DATE function
5225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5226#[cfg_attr(feature = "bindings", derive(TS))]
5227pub struct DateFormatFunc {
5228    pub this: Expression,
5229    pub format: Expression,
5230}
5231
5232/// FROM_UNIXTIME function
5233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5234#[cfg_attr(feature = "bindings", derive(TS))]
5235pub struct FromUnixtimeFunc {
5236    pub this: Expression,
5237    pub format: Option<Expression>,
5238}
5239
5240/// UNIX_TIMESTAMP function
5241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5242#[cfg_attr(feature = "bindings", derive(TS))]
5243pub struct UnixTimestampFunc {
5244    pub this: Option<Expression>,
5245    pub format: Option<Expression>,
5246}
5247
5248/// MAKE_DATE function
5249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5250#[cfg_attr(feature = "bindings", derive(TS))]
5251pub struct MakeDateFunc {
5252    pub year: Expression,
5253    pub month: Expression,
5254    pub day: Expression,
5255}
5256
5257/// MAKE_TIMESTAMP function
5258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5259#[cfg_attr(feature = "bindings", derive(TS))]
5260pub struct MakeTimestampFunc {
5261    pub year: Expression,
5262    pub month: Expression,
5263    pub day: Expression,
5264    pub hour: Expression,
5265    pub minute: Expression,
5266    pub second: Expression,
5267    pub timezone: Option<Expression>,
5268}
5269
5270/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
5271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5272#[cfg_attr(feature = "bindings", derive(TS))]
5273pub struct LastDayFunc {
5274    pub this: Expression,
5275    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
5276    #[serde(skip_serializing_if = "Option::is_none", default)]
5277    pub unit: Option<DateTimeField>,
5278}
5279
5280// ============================================================================
5281// Array Function types
5282// ============================================================================
5283
5284/// ARRAY constructor
5285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5286#[cfg_attr(feature = "bindings", derive(TS))]
5287pub struct ArrayConstructor {
5288    pub expressions: Vec<Expression>,
5289    pub bracket_notation: bool,
5290    /// True if LIST keyword was used instead of ARRAY (DuckDB)
5291    pub use_list_keyword: bool,
5292}
5293
5294/// ARRAY_SORT function
5295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5296#[cfg_attr(feature = "bindings", derive(TS))]
5297pub struct ArraySortFunc {
5298    pub this: Expression,
5299    pub comparator: Option<Expression>,
5300    pub desc: bool,
5301    pub nulls_first: Option<bool>,
5302}
5303
5304/// ARRAY_JOIN / ARRAY_TO_STRING function
5305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5306#[cfg_attr(feature = "bindings", derive(TS))]
5307pub struct ArrayJoinFunc {
5308    pub this: Expression,
5309    pub separator: Expression,
5310    pub null_replacement: Option<Expression>,
5311}
5312
5313/// UNNEST function
5314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5315#[cfg_attr(feature = "bindings", derive(TS))]
5316pub struct UnnestFunc {
5317    pub this: Expression,
5318    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
5319    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5320    pub expressions: Vec<Expression>,
5321    pub with_ordinality: bool,
5322    pub alias: Option<Identifier>,
5323    /// BigQuery: offset alias for WITH OFFSET AS <name>
5324    #[serde(default, skip_serializing_if = "Option::is_none")]
5325    pub offset_alias: Option<Identifier>,
5326}
5327
5328/// ARRAY_FILTER function (with lambda)
5329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5330#[cfg_attr(feature = "bindings", derive(TS))]
5331pub struct ArrayFilterFunc {
5332    pub this: Expression,
5333    pub filter: Expression,
5334}
5335
5336/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
5337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5338#[cfg_attr(feature = "bindings", derive(TS))]
5339pub struct ArrayTransformFunc {
5340    pub this: Expression,
5341    pub transform: Expression,
5342}
5343
5344/// SEQUENCE / GENERATE_SERIES function
5345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5346#[cfg_attr(feature = "bindings", derive(TS))]
5347pub struct SequenceFunc {
5348    pub start: Expression,
5349    pub stop: Expression,
5350    pub step: Option<Expression>,
5351}
5352
5353// ============================================================================
5354// Struct Function types
5355// ============================================================================
5356
5357/// STRUCT constructor
5358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5359#[cfg_attr(feature = "bindings", derive(TS))]
5360pub struct StructConstructor {
5361    pub fields: Vec<(Option<Identifier>, Expression)>,
5362}
5363
5364/// STRUCT_EXTRACT function
5365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5366#[cfg_attr(feature = "bindings", derive(TS))]
5367pub struct StructExtractFunc {
5368    pub this: Expression,
5369    pub field: Identifier,
5370}
5371
5372/// NAMED_STRUCT function
5373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5374#[cfg_attr(feature = "bindings", derive(TS))]
5375pub struct NamedStructFunc {
5376    pub pairs: Vec<(Expression, Expression)>,
5377}
5378
5379// ============================================================================
5380// Map Function types
5381// ============================================================================
5382
5383/// MAP constructor
5384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5385#[cfg_attr(feature = "bindings", derive(TS))]
5386pub struct MapConstructor {
5387    pub keys: Vec<Expression>,
5388    pub values: Vec<Expression>,
5389    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
5390    #[serde(default)]
5391    pub curly_brace_syntax: bool,
5392    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
5393    #[serde(default)]
5394    pub with_map_keyword: bool,
5395}
5396
5397/// TRANSFORM_KEYS / TRANSFORM_VALUES function
5398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5399#[cfg_attr(feature = "bindings", derive(TS))]
5400pub struct TransformFunc {
5401    pub this: Expression,
5402    pub transform: Expression,
5403}
5404
5405// ============================================================================
5406// JSON Function types
5407// ============================================================================
5408
5409/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
5410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5411#[cfg_attr(feature = "bindings", derive(TS))]
5412pub struct JsonExtractFunc {
5413    pub this: Expression,
5414    pub path: Expression,
5415    pub returning: Option<DataType>,
5416    /// True if parsed from -> or ->> operator syntax
5417    #[serde(default)]
5418    pub arrow_syntax: bool,
5419    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
5420    #[serde(default)]
5421    pub hash_arrow_syntax: bool,
5422    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
5423    #[serde(default)]
5424    pub wrapper_option: Option<String>,
5425    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
5426    #[serde(default)]
5427    pub quotes_option: Option<String>,
5428    /// ON SCALAR STRING flag
5429    #[serde(default)]
5430    pub on_scalar_string: bool,
5431    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
5432    #[serde(default)]
5433    pub on_error: Option<String>,
5434}
5435
5436/// JSON path extraction
5437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5438#[cfg_attr(feature = "bindings", derive(TS))]
5439pub struct JsonPathFunc {
5440    pub this: Expression,
5441    pub paths: Vec<Expression>,
5442}
5443
5444/// JSON_OBJECT function
5445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5446#[cfg_attr(feature = "bindings", derive(TS))]
5447pub struct JsonObjectFunc {
5448    pub pairs: Vec<(Expression, Expression)>,
5449    pub null_handling: Option<JsonNullHandling>,
5450    #[serde(default)]
5451    pub with_unique_keys: bool,
5452    #[serde(default)]
5453    pub returning_type: Option<DataType>,
5454    #[serde(default)]
5455    pub format_json: bool,
5456    #[serde(default)]
5457    pub encoding: Option<String>,
5458    /// For JSON_OBJECT(*) syntax
5459    #[serde(default)]
5460    pub star: bool,
5461}
5462
5463/// JSON null handling options
5464#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5465#[cfg_attr(feature = "bindings", derive(TS))]
5466pub enum JsonNullHandling {
5467    NullOnNull,
5468    AbsentOnNull,
5469}
5470
5471/// JSON_SET / JSON_INSERT function
5472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5473#[cfg_attr(feature = "bindings", derive(TS))]
5474pub struct JsonModifyFunc {
5475    pub this: Expression,
5476    pub path_values: Vec<(Expression, Expression)>,
5477}
5478
5479/// JSON_ARRAYAGG function
5480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5481#[cfg_attr(feature = "bindings", derive(TS))]
5482pub struct JsonArrayAggFunc {
5483    pub this: Expression,
5484    pub order_by: Option<Vec<Ordered>>,
5485    pub null_handling: Option<JsonNullHandling>,
5486    pub filter: Option<Expression>,
5487}
5488
5489/// JSON_OBJECTAGG function
5490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5491#[cfg_attr(feature = "bindings", derive(TS))]
5492pub struct JsonObjectAggFunc {
5493    pub key: Expression,
5494    pub value: Expression,
5495    pub null_handling: Option<JsonNullHandling>,
5496    pub filter: Option<Expression>,
5497}
5498
5499// ============================================================================
5500// Type Casting Function types
5501// ============================================================================
5502
5503/// CONVERT function (SQL Server style)
5504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5505#[cfg_attr(feature = "bindings", derive(TS))]
5506pub struct ConvertFunc {
5507    pub this: Expression,
5508    pub to: DataType,
5509    pub style: Option<Expression>,
5510}
5511
5512// ============================================================================
5513// Additional Expression types
5514// ============================================================================
5515
5516/// Lambda expression
5517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5518#[cfg_attr(feature = "bindings", derive(TS))]
5519pub struct LambdaExpr {
5520    pub parameters: Vec<Identifier>,
5521    pub body: Expression,
5522    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5523    #[serde(default)]
5524    pub colon: bool,
5525    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5526    /// Maps parameter index to data type
5527    #[serde(default)]
5528    pub parameter_types: Vec<Option<DataType>>,
5529}
5530
5531/// Parameter (parameterized queries)
5532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5533#[cfg_attr(feature = "bindings", derive(TS))]
5534pub struct Parameter {
5535    pub name: Option<String>,
5536    pub index: Option<u32>,
5537    pub style: ParameterStyle,
5538    /// Whether the name was quoted (e.g., @"x" vs @x)
5539    #[serde(default)]
5540    pub quoted: bool,
5541    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5542    #[serde(default)]
5543    pub string_quoted: bool,
5544    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5545    #[serde(default)]
5546    pub expression: Option<String>,
5547}
5548
5549/// Parameter placeholder styles
5550#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5551#[cfg_attr(feature = "bindings", derive(TS))]
5552pub enum ParameterStyle {
5553    Question,     // ?
5554    Dollar,       // $1, $2
5555    DollarBrace,  // ${name} (Databricks, Hive template variables)
5556    Brace,        // {name} (Spark/Databricks widget/template variables)
5557    Colon,        // :name
5558    At,           // @name
5559    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5560    DoubleDollar, // $$name
5561    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5562}
5563
5564/// Placeholder expression
5565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5566#[cfg_attr(feature = "bindings", derive(TS))]
5567pub struct Placeholder {
5568    pub index: Option<u32>,
5569}
5570
5571/// Named argument in function call: name => value or name := value
5572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5573#[cfg_attr(feature = "bindings", derive(TS))]
5574pub struct NamedArgument {
5575    pub name: Identifier,
5576    pub value: Expression,
5577    /// The separator used: `=>`, `:=`, or `=`
5578    pub separator: NamedArgSeparator,
5579}
5580
5581/// Separator style for named arguments
5582#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5583#[cfg_attr(feature = "bindings", derive(TS))]
5584pub enum NamedArgSeparator {
5585    /// `=>` (standard SQL, Snowflake, BigQuery)
5586    DArrow,
5587    /// `:=` (Oracle, MySQL)
5588    ColonEq,
5589    /// `=` (simple equals, some dialects)
5590    Eq,
5591}
5592
5593/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5594/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5596#[cfg_attr(feature = "bindings", derive(TS))]
5597pub struct TableArgument {
5598    /// The keyword prefix: "TABLE" or "MODEL"
5599    pub prefix: String,
5600    /// The table/model reference expression
5601    pub this: Expression,
5602}
5603
5604/// SQL Comment preservation
5605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5606#[cfg_attr(feature = "bindings", derive(TS))]
5607pub struct SqlComment {
5608    pub text: String,
5609    pub is_block: bool,
5610}
5611
5612// ============================================================================
5613// Additional Predicate types
5614// ============================================================================
5615
5616/// SIMILAR TO expression
5617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5618#[cfg_attr(feature = "bindings", derive(TS))]
5619pub struct SimilarToExpr {
5620    pub this: Expression,
5621    pub pattern: Expression,
5622    pub escape: Option<Expression>,
5623    pub not: bool,
5624}
5625
5626/// ANY / ALL quantified expression
5627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5628#[cfg_attr(feature = "bindings", derive(TS))]
5629pub struct QuantifiedExpr {
5630    pub this: Expression,
5631    pub subquery: Expression,
5632    pub op: Option<QuantifiedOp>,
5633}
5634
5635/// Comparison operator for quantified expressions
5636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5637#[cfg_attr(feature = "bindings", derive(TS))]
5638pub enum QuantifiedOp {
5639    Eq,
5640    Neq,
5641    Lt,
5642    Lte,
5643    Gt,
5644    Gte,
5645}
5646
5647/// OVERLAPS expression
5648/// Supports two forms:
5649/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5650/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5652#[cfg_attr(feature = "bindings", derive(TS))]
5653pub struct OverlapsExpr {
5654    /// Left operand for simple binary form
5655    #[serde(skip_serializing_if = "Option::is_none")]
5656    pub this: Option<Expression>,
5657    /// Right operand for simple binary form
5658    #[serde(skip_serializing_if = "Option::is_none")]
5659    pub expression: Option<Expression>,
5660    /// Left range start for full ANSI form
5661    #[serde(skip_serializing_if = "Option::is_none")]
5662    pub left_start: Option<Expression>,
5663    /// Left range end for full ANSI form
5664    #[serde(skip_serializing_if = "Option::is_none")]
5665    pub left_end: Option<Expression>,
5666    /// Right range start for full ANSI form
5667    #[serde(skip_serializing_if = "Option::is_none")]
5668    pub right_start: Option<Expression>,
5669    /// Right range end for full ANSI form
5670    #[serde(skip_serializing_if = "Option::is_none")]
5671    pub right_end: Option<Expression>,
5672}
5673
5674// ============================================================================
5675// Array/Struct/Map access
5676// ============================================================================
5677
5678/// Subscript access (array[index] or map[key])
5679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5680#[cfg_attr(feature = "bindings", derive(TS))]
5681pub struct Subscript {
5682    pub this: Expression,
5683    pub index: Expression,
5684}
5685
5686/// Dot access (struct.field)
5687#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5688#[cfg_attr(feature = "bindings", derive(TS))]
5689pub struct DotAccess {
5690    pub this: Expression,
5691    pub field: Identifier,
5692}
5693
5694/// Method call (expr.method(args))
5695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5696#[cfg_attr(feature = "bindings", derive(TS))]
5697pub struct MethodCall {
5698    pub this: Expression,
5699    pub method: Identifier,
5700    pub args: Vec<Expression>,
5701}
5702
5703/// Array slice (array[start:end])
5704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5705#[cfg_attr(feature = "bindings", derive(TS))]
5706pub struct ArraySlice {
5707    pub this: Expression,
5708    pub start: Option<Expression>,
5709    pub end: Option<Expression>,
5710}
5711
5712// ============================================================================
5713// DDL (Data Definition Language) Statements
5714// ============================================================================
5715
5716/// ON COMMIT behavior for temporary tables
5717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5718#[cfg_attr(feature = "bindings", derive(TS))]
5719pub enum OnCommit {
5720    /// ON COMMIT PRESERVE ROWS
5721    PreserveRows,
5722    /// ON COMMIT DELETE ROWS
5723    DeleteRows,
5724}
5725
5726/// CREATE TABLE statement
5727#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5728#[cfg_attr(feature = "bindings", derive(TS))]
5729pub struct CreateTable {
5730    pub name: TableRef,
5731    /// ClickHouse: ON CLUSTER clause for distributed DDL
5732    #[serde(default, skip_serializing_if = "Option::is_none")]
5733    pub on_cluster: Option<OnCluster>,
5734    pub columns: Vec<ColumnDef>,
5735    pub constraints: Vec<TableConstraint>,
5736    pub if_not_exists: bool,
5737    pub temporary: bool,
5738    pub or_replace: bool,
5739    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5740    #[serde(default, skip_serializing_if = "Option::is_none")]
5741    pub table_modifier: Option<String>,
5742    pub as_select: Option<Expression>,
5743    /// Whether the AS SELECT was wrapped in parentheses
5744    #[serde(default)]
5745    pub as_select_parenthesized: bool,
5746    /// ON COMMIT behavior for temporary tables
5747    #[serde(default)]
5748    pub on_commit: Option<OnCommit>,
5749    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5750    #[serde(default)]
5751    pub clone_source: Option<TableRef>,
5752    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5753    #[serde(default, skip_serializing_if = "Option::is_none")]
5754    pub clone_at_clause: Option<Expression>,
5755    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5756    #[serde(default)]
5757    pub is_copy: bool,
5758    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5759    #[serde(default)]
5760    pub shallow_clone: bool,
5761    /// Leading comments before the statement
5762    #[serde(default)]
5763    pub leading_comments: Vec<String>,
5764    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5765    #[serde(default)]
5766    pub with_properties: Vec<(String, String)>,
5767    /// Teradata: table options after name before columns (comma-separated)
5768    #[serde(default)]
5769    pub teradata_post_name_options: Vec<String>,
5770    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5771    #[serde(default)]
5772    pub with_data: Option<bool>,
5773    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5774    #[serde(default)]
5775    pub with_statistics: Option<bool>,
5776    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5777    #[serde(default)]
5778    pub teradata_indexes: Vec<TeradataIndex>,
5779    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5780    #[serde(default)]
5781    pub with_cte: Option<With>,
5782    /// Table properties like DEFAULT COLLATE (BigQuery)
5783    #[serde(default)]
5784    pub properties: Vec<Expression>,
5785    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5786    #[serde(default, skip_serializing_if = "Option::is_none")]
5787    pub partition_of: Option<Expression>,
5788    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5789    #[serde(default)]
5790    pub post_table_properties: Vec<Expression>,
5791    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5792    #[serde(default)]
5793    pub mysql_table_options: Vec<(String, String)>,
5794    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5795    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5796    pub inherits: Vec<TableRef>,
5797    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5798    #[serde(default, skip_serializing_if = "Option::is_none")]
5799    pub on_property: Option<OnProperty>,
5800    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5801    #[serde(default)]
5802    pub copy_grants: bool,
5803    /// Snowflake: USING TEMPLATE expression for schema inference
5804    #[serde(default, skip_serializing_if = "Option::is_none")]
5805    pub using_template: Option<Box<Expression>>,
5806    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5807    #[serde(default, skip_serializing_if = "Option::is_none")]
5808    pub rollup: Option<RollupProperty>,
5809}
5810
5811/// Teradata index specification for CREATE TABLE
5812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5813#[cfg_attr(feature = "bindings", derive(TS))]
5814pub struct TeradataIndex {
5815    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5816    pub kind: TeradataIndexKind,
5817    /// Optional index name
5818    pub name: Option<String>,
5819    /// Optional column list
5820    pub columns: Vec<String>,
5821}
5822
5823/// Kind of Teradata index
5824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5825#[cfg_attr(feature = "bindings", derive(TS))]
5826pub enum TeradataIndexKind {
5827    /// NO PRIMARY INDEX
5828    NoPrimary,
5829    /// PRIMARY INDEX
5830    Primary,
5831    /// PRIMARY AMP INDEX
5832    PrimaryAmp,
5833    /// UNIQUE INDEX
5834    Unique,
5835    /// UNIQUE PRIMARY INDEX
5836    UniquePrimary,
5837    /// INDEX (secondary, non-primary)
5838    Secondary,
5839}
5840
5841impl CreateTable {
5842    pub fn new(name: impl Into<String>) -> Self {
5843        Self {
5844            name: TableRef::new(name),
5845            on_cluster: None,
5846            columns: Vec::new(),
5847            constraints: Vec::new(),
5848            if_not_exists: false,
5849            temporary: false,
5850            or_replace: false,
5851            table_modifier: None,
5852            as_select: None,
5853            as_select_parenthesized: false,
5854            on_commit: None,
5855            clone_source: None,
5856            clone_at_clause: None,
5857            shallow_clone: false,
5858            is_copy: false,
5859            leading_comments: Vec::new(),
5860            with_properties: Vec::new(),
5861            teradata_post_name_options: Vec::new(),
5862            with_data: None,
5863            with_statistics: None,
5864            teradata_indexes: Vec::new(),
5865            with_cte: None,
5866            properties: Vec::new(),
5867            partition_of: None,
5868            post_table_properties: Vec::new(),
5869            mysql_table_options: Vec::new(),
5870            inherits: Vec::new(),
5871            on_property: None,
5872            copy_grants: false,
5873            using_template: None,
5874            rollup: None,
5875        }
5876    }
5877}
5878
5879/// Sort order for PRIMARY KEY ASC/DESC
5880#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5881#[cfg_attr(feature = "bindings", derive(TS))]
5882pub enum SortOrder {
5883    Asc,
5884    Desc,
5885}
5886
5887/// Type of column constraint for tracking order
5888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5889#[cfg_attr(feature = "bindings", derive(TS))]
5890pub enum ConstraintType {
5891    NotNull,
5892    Null,
5893    PrimaryKey,
5894    Unique,
5895    Default,
5896    AutoIncrement,
5897    Collate,
5898    Comment,
5899    References,
5900    Check,
5901    GeneratedAsIdentity,
5902    /// Snowflake: TAG (key='value', ...)
5903    Tags,
5904    /// Computed/generated column
5905    ComputedColumn,
5906    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5907    GeneratedAsRow,
5908    /// MySQL: ON UPDATE expression
5909    OnUpdate,
5910    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5911    Path,
5912    /// Redshift: ENCODE encoding_type
5913    Encode,
5914}
5915
5916/// Column definition in CREATE TABLE
5917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5918#[cfg_attr(feature = "bindings", derive(TS))]
5919pub struct ColumnDef {
5920    pub name: Identifier,
5921    pub data_type: DataType,
5922    pub nullable: Option<bool>,
5923    pub default: Option<Expression>,
5924    pub primary_key: bool,
5925    /// Sort order for PRIMARY KEY (ASC/DESC)
5926    #[serde(default)]
5927    pub primary_key_order: Option<SortOrder>,
5928    pub unique: bool,
5929    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5930    #[serde(default)]
5931    pub unique_nulls_not_distinct: bool,
5932    pub auto_increment: bool,
5933    pub comment: Option<String>,
5934    pub constraints: Vec<ColumnConstraint>,
5935    /// Track original order of constraints for accurate regeneration
5936    #[serde(default)]
5937    pub constraint_order: Vec<ConstraintType>,
5938    /// Teradata: FORMAT 'pattern'
5939    #[serde(default)]
5940    pub format: Option<String>,
5941    /// Teradata: TITLE 'title'
5942    #[serde(default)]
5943    pub title: Option<String>,
5944    /// Teradata: INLINE LENGTH n
5945    #[serde(default)]
5946    pub inline_length: Option<u64>,
5947    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5948    #[serde(default)]
5949    pub compress: Option<Vec<Expression>>,
5950    /// Teradata: CHARACTER SET name
5951    #[serde(default)]
5952    pub character_set: Option<String>,
5953    /// Teradata: UPPERCASE
5954    #[serde(default)]
5955    pub uppercase: bool,
5956    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5957    #[serde(default)]
5958    pub casespecific: Option<bool>,
5959    /// Snowflake: AUTOINCREMENT START value
5960    #[serde(default)]
5961    pub auto_increment_start: Option<Box<Expression>>,
5962    /// Snowflake: AUTOINCREMENT INCREMENT value
5963    #[serde(default)]
5964    pub auto_increment_increment: Option<Box<Expression>>,
5965    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5966    #[serde(default)]
5967    pub auto_increment_order: Option<bool>,
5968    /// MySQL: UNSIGNED modifier
5969    #[serde(default)]
5970    pub unsigned: bool,
5971    /// MySQL: ZEROFILL modifier
5972    #[serde(default)]
5973    pub zerofill: bool,
5974    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5975    #[serde(default, skip_serializing_if = "Option::is_none")]
5976    pub on_update: Option<Expression>,
5977    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5978    #[serde(default, skip_serializing_if = "Option::is_none")]
5979    pub unique_constraint_name: Option<String>,
5980    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5981    #[serde(default, skip_serializing_if = "Option::is_none")]
5982    pub not_null_constraint_name: Option<String>,
5983    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5984    #[serde(default, skip_serializing_if = "Option::is_none")]
5985    pub primary_key_constraint_name: Option<String>,
5986    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5987    #[serde(default, skip_serializing_if = "Option::is_none")]
5988    pub check_constraint_name: Option<String>,
5989    /// BigQuery: OPTIONS (key=value, ...) on column
5990    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5991    pub options: Vec<Expression>,
5992    /// SQLite: Column definition without explicit type
5993    #[serde(default)]
5994    pub no_type: bool,
5995    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5996    #[serde(default, skip_serializing_if = "Option::is_none")]
5997    pub encoding: Option<String>,
5998    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5999    #[serde(default, skip_serializing_if = "Option::is_none")]
6000    pub codec: Option<String>,
6001    /// ClickHouse: EPHEMERAL [expr] modifier
6002    #[serde(default, skip_serializing_if = "Option::is_none")]
6003    pub ephemeral: Option<Option<Box<Expression>>>,
6004    /// ClickHouse: MATERIALIZED expr modifier
6005    #[serde(default, skip_serializing_if = "Option::is_none")]
6006    pub materialized_expr: Option<Box<Expression>>,
6007    /// ClickHouse: ALIAS expr modifier
6008    #[serde(default, skip_serializing_if = "Option::is_none")]
6009    pub alias_expr: Option<Box<Expression>>,
6010    /// ClickHouse: TTL expr modifier on columns
6011    #[serde(default, skip_serializing_if = "Option::is_none")]
6012    pub ttl_expr: Option<Box<Expression>>,
6013    /// TSQL: NOT FOR REPLICATION
6014    #[serde(default)]
6015    pub not_for_replication: bool,
6016}
6017
6018impl ColumnDef {
6019    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
6020        Self {
6021            name: Identifier::new(name),
6022            data_type,
6023            nullable: None,
6024            default: None,
6025            primary_key: false,
6026            primary_key_order: None,
6027            unique: false,
6028            unique_nulls_not_distinct: false,
6029            auto_increment: false,
6030            comment: None,
6031            constraints: Vec::new(),
6032            constraint_order: Vec::new(),
6033            format: None,
6034            title: None,
6035            inline_length: None,
6036            compress: None,
6037            character_set: None,
6038            uppercase: false,
6039            casespecific: None,
6040            auto_increment_start: None,
6041            auto_increment_increment: None,
6042            auto_increment_order: None,
6043            unsigned: false,
6044            zerofill: false,
6045            on_update: None,
6046            unique_constraint_name: None,
6047            not_null_constraint_name: None,
6048            primary_key_constraint_name: None,
6049            check_constraint_name: None,
6050            options: Vec::new(),
6051            no_type: false,
6052            encoding: None,
6053            codec: None,
6054            ephemeral: None,
6055            materialized_expr: None,
6056            alias_expr: None,
6057            ttl_expr: None,
6058            not_for_replication: false,
6059        }
6060    }
6061}
6062
6063/// Column-level constraint
6064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6065#[cfg_attr(feature = "bindings", derive(TS))]
6066pub enum ColumnConstraint {
6067    NotNull,
6068    Null,
6069    Unique,
6070    PrimaryKey,
6071    Default(Expression),
6072    Check(Expression),
6073    References(ForeignKeyRef),
6074    GeneratedAsIdentity(GeneratedAsIdentity),
6075    Collate(Identifier),
6076    Comment(String),
6077    /// Snowflake: TAG (key='value', ...)
6078    Tags(Tags),
6079    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
6080    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
6081    ComputedColumn(ComputedColumn),
6082    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6083    GeneratedAsRow(GeneratedAsRow),
6084    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
6085    Path(Expression),
6086}
6087
6088/// Computed/generated column constraint
6089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6090#[cfg_attr(feature = "bindings", derive(TS))]
6091pub struct ComputedColumn {
6092    /// The expression that computes the column value
6093    pub expression: Box<Expression>,
6094    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
6095    #[serde(default)]
6096    pub persisted: bool,
6097    /// NOT NULL (TSQL computed columns)
6098    #[serde(default)]
6099    pub not_null: bool,
6100    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
6101    /// When None, defaults to dialect-appropriate output
6102    #[serde(default)]
6103    pub persistence_kind: Option<String>,
6104    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
6105    #[serde(default, skip_serializing_if = "Option::is_none")]
6106    pub data_type: Option<DataType>,
6107}
6108
6109/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
6110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6111#[cfg_attr(feature = "bindings", derive(TS))]
6112pub struct GeneratedAsRow {
6113    /// true = ROW START, false = ROW END
6114    pub start: bool,
6115    /// HIDDEN modifier
6116    #[serde(default)]
6117    pub hidden: bool,
6118}
6119
6120/// Generated identity column constraint
6121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6122#[cfg_attr(feature = "bindings", derive(TS))]
6123pub struct GeneratedAsIdentity {
6124    /// True for ALWAYS, False for BY DEFAULT
6125    pub always: bool,
6126    /// ON NULL (only valid with BY DEFAULT)
6127    pub on_null: bool,
6128    /// START WITH value
6129    pub start: Option<Box<Expression>>,
6130    /// INCREMENT BY value
6131    pub increment: Option<Box<Expression>>,
6132    /// MINVALUE
6133    pub minvalue: Option<Box<Expression>>,
6134    /// MAXVALUE
6135    pub maxvalue: Option<Box<Expression>>,
6136    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
6137    pub cycle: Option<bool>,
6138}
6139
6140/// Constraint modifiers (shared between table-level constraints)
6141#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
6142#[cfg_attr(feature = "bindings", derive(TS))]
6143pub struct ConstraintModifiers {
6144    /// ENFORCED / NOT ENFORCED
6145    pub enforced: Option<bool>,
6146    /// DEFERRABLE / NOT DEFERRABLE
6147    pub deferrable: Option<bool>,
6148    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
6149    pub initially_deferred: Option<bool>,
6150    /// NORELY (Oracle)
6151    pub norely: bool,
6152    /// RELY (Oracle)
6153    pub rely: bool,
6154    /// USING index type (MySQL): BTREE or HASH
6155    #[serde(default)]
6156    pub using: Option<String>,
6157    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
6158    #[serde(default)]
6159    pub using_before_columns: bool,
6160    /// MySQL index COMMENT 'text'
6161    #[serde(default, skip_serializing_if = "Option::is_none")]
6162    pub comment: Option<String>,
6163    /// MySQL index VISIBLE/INVISIBLE
6164    #[serde(default, skip_serializing_if = "Option::is_none")]
6165    pub visible: Option<bool>,
6166    /// MySQL ENGINE_ATTRIBUTE = 'value'
6167    #[serde(default, skip_serializing_if = "Option::is_none")]
6168    pub engine_attribute: Option<String>,
6169    /// MySQL WITH PARSER name
6170    #[serde(default, skip_serializing_if = "Option::is_none")]
6171    pub with_parser: Option<String>,
6172    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
6173    #[serde(default)]
6174    pub not_valid: bool,
6175    /// TSQL CLUSTERED/NONCLUSTERED modifier
6176    #[serde(default, skip_serializing_if = "Option::is_none")]
6177    pub clustered: Option<String>,
6178    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
6179    #[serde(default, skip_serializing_if = "Option::is_none")]
6180    pub on_conflict: Option<String>,
6181    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
6182    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6183    pub with_options: Vec<(String, String)>,
6184    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
6185    #[serde(default, skip_serializing_if = "Option::is_none")]
6186    pub on_filegroup: Option<Identifier>,
6187}
6188
6189/// Table-level constraint
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub enum TableConstraint {
6193    PrimaryKey {
6194        name: Option<Identifier>,
6195        columns: Vec<Identifier>,
6196        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
6197        #[serde(default)]
6198        include_columns: Vec<Identifier>,
6199        #[serde(default)]
6200        modifiers: ConstraintModifiers,
6201        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
6202        #[serde(default)]
6203        has_constraint_keyword: bool,
6204    },
6205    Unique {
6206        name: Option<Identifier>,
6207        columns: Vec<Identifier>,
6208        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
6209        #[serde(default)]
6210        columns_parenthesized: bool,
6211        #[serde(default)]
6212        modifiers: ConstraintModifiers,
6213        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
6214        #[serde(default)]
6215        has_constraint_keyword: bool,
6216        /// PostgreSQL 15+: NULLS NOT DISTINCT
6217        #[serde(default)]
6218        nulls_not_distinct: bool,
6219    },
6220    ForeignKey {
6221        name: Option<Identifier>,
6222        columns: Vec<Identifier>,
6223        #[serde(default)]
6224        references: Option<ForeignKeyRef>,
6225        /// ON DELETE action when REFERENCES is absent
6226        #[serde(default)]
6227        on_delete: Option<ReferentialAction>,
6228        /// ON UPDATE action when REFERENCES is absent
6229        #[serde(default)]
6230        on_update: Option<ReferentialAction>,
6231        #[serde(default)]
6232        modifiers: ConstraintModifiers,
6233    },
6234    Check {
6235        name: Option<Identifier>,
6236        expression: Expression,
6237        #[serde(default)]
6238        modifiers: ConstraintModifiers,
6239    },
6240    /// INDEX / KEY constraint (MySQL)
6241    Index {
6242        name: Option<Identifier>,
6243        columns: Vec<Identifier>,
6244        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
6245        #[serde(default)]
6246        kind: Option<String>,
6247        #[serde(default)]
6248        modifiers: ConstraintModifiers,
6249        /// True if KEY keyword was used instead of INDEX
6250        #[serde(default)]
6251        use_key_keyword: bool,
6252        /// ClickHouse: indexed expression (instead of columns)
6253        #[serde(default, skip_serializing_if = "Option::is_none")]
6254        expression: Option<Box<Expression>>,
6255        /// ClickHouse: TYPE type_func(args)
6256        #[serde(default, skip_serializing_if = "Option::is_none")]
6257        index_type: Option<Box<Expression>>,
6258        /// ClickHouse: GRANULARITY n
6259        #[serde(default, skip_serializing_if = "Option::is_none")]
6260        granularity: Option<Box<Expression>>,
6261    },
6262    /// ClickHouse PROJECTION definition
6263    Projection {
6264        name: Identifier,
6265        expression: Expression,
6266    },
6267    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
6268    Like {
6269        source: TableRef,
6270        /// Options as (INCLUDING|EXCLUDING, property) pairs
6271        options: Vec<(LikeOptionAction, String)>,
6272    },
6273    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
6274    PeriodForSystemTime {
6275        start_col: Identifier,
6276        end_col: Identifier,
6277    },
6278    /// PostgreSQL EXCLUDE constraint
6279    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
6280    Exclude {
6281        name: Option<Identifier>,
6282        /// Index access method (gist, btree, etc.)
6283        #[serde(default)]
6284        using: Option<String>,
6285        /// Elements: (expression, operator) pairs
6286        elements: Vec<ExcludeElement>,
6287        /// INCLUDE columns
6288        #[serde(default)]
6289        include_columns: Vec<Identifier>,
6290        /// WHERE predicate
6291        #[serde(default)]
6292        where_clause: Option<Box<Expression>>,
6293        /// WITH (storage_parameters)
6294        #[serde(default)]
6295        with_params: Vec<(String, String)>,
6296        /// USING INDEX TABLESPACE tablespace_name
6297        #[serde(default)]
6298        using_index_tablespace: Option<String>,
6299        #[serde(default)]
6300        modifiers: ConstraintModifiers,
6301    },
6302    /// Snowflake TAG clause: TAG (key='value', key2='value2')
6303    Tags(Tags),
6304    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
6305    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
6306    /// for all deferrable constraints in the table
6307    InitiallyDeferred {
6308        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
6309        deferred: bool,
6310    },
6311}
6312
6313/// Element in an EXCLUDE constraint: expression WITH operator
6314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6315#[cfg_attr(feature = "bindings", derive(TS))]
6316pub struct ExcludeElement {
6317    /// The column expression (may include operator class, ordering, nulls)
6318    pub expression: String,
6319    /// The operator (e.g., &&, =)
6320    pub operator: String,
6321}
6322
6323/// Action for LIKE clause options
6324#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6325#[cfg_attr(feature = "bindings", derive(TS))]
6326pub enum LikeOptionAction {
6327    Including,
6328    Excluding,
6329}
6330
6331/// MATCH type for foreign keys
6332#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6333#[cfg_attr(feature = "bindings", derive(TS))]
6334pub enum MatchType {
6335    Full,
6336    Partial,
6337    Simple,
6338}
6339
6340/// Foreign key reference
6341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6342#[cfg_attr(feature = "bindings", derive(TS))]
6343pub struct ForeignKeyRef {
6344    pub table: TableRef,
6345    pub columns: Vec<Identifier>,
6346    pub on_delete: Option<ReferentialAction>,
6347    pub on_update: Option<ReferentialAction>,
6348    /// True if ON UPDATE appears before ON DELETE in the original SQL
6349    #[serde(default)]
6350    pub on_update_first: bool,
6351    /// MATCH clause (FULL, PARTIAL, SIMPLE)
6352    #[serde(default)]
6353    pub match_type: Option<MatchType>,
6354    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
6355    #[serde(default)]
6356    pub match_after_actions: bool,
6357    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
6358    #[serde(default)]
6359    pub constraint_name: Option<String>,
6360    /// DEFERRABLE / NOT DEFERRABLE
6361    #[serde(default)]
6362    pub deferrable: Option<bool>,
6363    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
6364    #[serde(default)]
6365    pub has_foreign_key_keywords: bool,
6366}
6367
6368/// Referential action for foreign keys
6369#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6370#[cfg_attr(feature = "bindings", derive(TS))]
6371pub enum ReferentialAction {
6372    Cascade,
6373    SetNull,
6374    SetDefault,
6375    Restrict,
6376    NoAction,
6377}
6378
6379/// DROP TABLE statement
6380#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6381#[cfg_attr(feature = "bindings", derive(TS))]
6382pub struct DropTable {
6383    pub names: Vec<TableRef>,
6384    pub if_exists: bool,
6385    pub cascade: bool,
6386    /// Oracle: CASCADE CONSTRAINTS
6387    #[serde(default)]
6388    pub cascade_constraints: bool,
6389    /// Oracle: PURGE
6390    #[serde(default)]
6391    pub purge: bool,
6392    /// Comments that appear before the DROP keyword (e.g., leading line comments)
6393    #[serde(default)]
6394    pub leading_comments: Vec<String>,
6395}
6396
6397impl DropTable {
6398    pub fn new(name: impl Into<String>) -> Self {
6399        Self {
6400            names: vec![TableRef::new(name)],
6401            if_exists: false,
6402            cascade: false,
6403            cascade_constraints: false,
6404            purge: false,
6405            leading_comments: Vec::new(),
6406        }
6407    }
6408}
6409
6410/// ALTER TABLE statement
6411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6412#[cfg_attr(feature = "bindings", derive(TS))]
6413pub struct AlterTable {
6414    pub name: TableRef,
6415    pub actions: Vec<AlterTableAction>,
6416    /// IF EXISTS clause
6417    #[serde(default)]
6418    pub if_exists: bool,
6419    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
6420    #[serde(default, skip_serializing_if = "Option::is_none")]
6421    pub algorithm: Option<String>,
6422    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
6423    #[serde(default, skip_serializing_if = "Option::is_none")]
6424    pub lock: Option<String>,
6425    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
6426    #[serde(default, skip_serializing_if = "Option::is_none")]
6427    pub with_check: Option<String>,
6428    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
6429    #[serde(default, skip_serializing_if = "Option::is_none")]
6430    pub partition: Option<Vec<(Identifier, Expression)>>,
6431    /// ClickHouse: ON CLUSTER clause for distributed DDL
6432    #[serde(default, skip_serializing_if = "Option::is_none")]
6433    pub on_cluster: Option<OnCluster>,
6434}
6435
6436impl AlterTable {
6437    pub fn new(name: impl Into<String>) -> Self {
6438        Self {
6439            name: TableRef::new(name),
6440            actions: Vec::new(),
6441            if_exists: false,
6442            algorithm: None,
6443            lock: None,
6444            with_check: None,
6445            partition: None,
6446            on_cluster: None,
6447        }
6448    }
6449}
6450
6451/// Column position for ADD COLUMN (MySQL/MariaDB)
6452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6453#[cfg_attr(feature = "bindings", derive(TS))]
6454pub enum ColumnPosition {
6455    First,
6456    After(Identifier),
6457}
6458
6459/// Actions for ALTER TABLE
6460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6461#[cfg_attr(feature = "bindings", derive(TS))]
6462pub enum AlterTableAction {
6463    AddColumn {
6464        column: ColumnDef,
6465        if_not_exists: bool,
6466        position: Option<ColumnPosition>,
6467    },
6468    DropColumn {
6469        name: Identifier,
6470        if_exists: bool,
6471        cascade: bool,
6472    },
6473    RenameColumn {
6474        old_name: Identifier,
6475        new_name: Identifier,
6476        if_exists: bool,
6477    },
6478    AlterColumn {
6479        name: Identifier,
6480        action: AlterColumnAction,
6481        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
6482        #[serde(default)]
6483        use_modify_keyword: bool,
6484    },
6485    RenameTable(TableRef),
6486    AddConstraint(TableConstraint),
6487    DropConstraint {
6488        name: Identifier,
6489        if_exists: bool,
6490    },
6491    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
6492    DropForeignKey {
6493        name: Identifier,
6494    },
6495    /// DROP PARTITION action (Hive/BigQuery)
6496    DropPartition {
6497        /// List of partitions to drop (each partition is a list of key=value pairs)
6498        partitions: Vec<Vec<(Identifier, Expression)>>,
6499        if_exists: bool,
6500    },
6501    /// ADD PARTITION action (Hive/Spark)
6502    AddPartition {
6503        /// The partition expression
6504        partition: Expression,
6505        if_not_exists: bool,
6506        location: Option<Expression>,
6507    },
6508    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6509    Delete {
6510        where_clause: Expression,
6511    },
6512    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6513    SwapWith(TableRef),
6514    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6515    SetProperty {
6516        properties: Vec<(String, Expression)>,
6517    },
6518    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6519    UnsetProperty {
6520        properties: Vec<String>,
6521    },
6522    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6523    ClusterBy {
6524        expressions: Vec<Expression>,
6525    },
6526    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6527    SetTag {
6528        expressions: Vec<(String, Expression)>,
6529    },
6530    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6531    UnsetTag {
6532        names: Vec<String>,
6533    },
6534    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6535    SetOptions {
6536        expressions: Vec<Expression>,
6537    },
6538    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6539    AlterIndex {
6540        name: Identifier,
6541        visible: bool,
6542    },
6543    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6544    SetAttribute {
6545        attribute: String,
6546    },
6547    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6548    SetStageFileFormat {
6549        options: Option<Expression>,
6550    },
6551    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6552    SetStageCopyOptions {
6553        options: Option<Expression>,
6554    },
6555    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6556    AddColumns {
6557        columns: Vec<ColumnDef>,
6558        cascade: bool,
6559    },
6560    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6561    DropColumns {
6562        names: Vec<Identifier>,
6563    },
6564    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6565    /// In SingleStore, data_type can be omitted for simple column renames
6566    ChangeColumn {
6567        old_name: Identifier,
6568        new_name: Identifier,
6569        #[serde(default, skip_serializing_if = "Option::is_none")]
6570        data_type: Option<DataType>,
6571        comment: Option<String>,
6572        #[serde(default)]
6573        cascade: bool,
6574    },
6575    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6576    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6577    AlterSortKey {
6578        /// AUTO or NONE keyword
6579        this: Option<String>,
6580        /// Column list for (col1, col2) syntax
6581        expressions: Vec<Expression>,
6582        /// Whether COMPOUND keyword was present
6583        compound: bool,
6584    },
6585    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6586    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6587    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6588    AlterDistStyle {
6589        /// Distribution style: ALL, EVEN, AUTO, or KEY
6590        style: String,
6591        /// DISTKEY column (only when style is KEY)
6592        distkey: Option<Identifier>,
6593    },
6594    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6595    SetTableProperties {
6596        properties: Vec<(Expression, Expression)>,
6597    },
6598    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6599    SetLocation {
6600        location: String,
6601    },
6602    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6603    SetFileFormat {
6604        format: String,
6605    },
6606    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6607    ReplacePartition {
6608        partition: Expression,
6609        source: Option<Box<Expression>>,
6610    },
6611    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6612    Raw {
6613        sql: String,
6614    },
6615}
6616
6617/// Actions for ALTER COLUMN
6618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6619#[cfg_attr(feature = "bindings", derive(TS))]
6620pub enum AlterColumnAction {
6621    SetDataType {
6622        data_type: DataType,
6623        /// USING expression for type conversion (PostgreSQL)
6624        using: Option<Expression>,
6625        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6626        #[serde(default, skip_serializing_if = "Option::is_none")]
6627        collate: Option<String>,
6628    },
6629    SetDefault(Expression),
6630    DropDefault,
6631    SetNotNull,
6632    DropNotNull,
6633    /// Set column comment
6634    Comment(String),
6635    /// MySQL: SET VISIBLE
6636    SetVisible,
6637    /// MySQL: SET INVISIBLE
6638    SetInvisible,
6639}
6640
6641/// CREATE INDEX statement
6642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6643#[cfg_attr(feature = "bindings", derive(TS))]
6644pub struct CreateIndex {
6645    pub name: Identifier,
6646    pub table: TableRef,
6647    pub columns: Vec<IndexColumn>,
6648    pub unique: bool,
6649    pub if_not_exists: bool,
6650    pub using: Option<String>,
6651    /// TSQL CLUSTERED/NONCLUSTERED modifier
6652    #[serde(default)]
6653    pub clustered: Option<String>,
6654    /// PostgreSQL CONCURRENTLY modifier
6655    #[serde(default)]
6656    pub concurrently: bool,
6657    /// PostgreSQL WHERE clause for partial indexes
6658    #[serde(default)]
6659    pub where_clause: Option<Box<Expression>>,
6660    /// PostgreSQL INCLUDE columns
6661    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6662    pub include_columns: Vec<Identifier>,
6663    /// TSQL WITH options (e.g., allow_page_locks=on)
6664    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6665    pub with_options: Vec<(String, String)>,
6666    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6667    #[serde(default)]
6668    pub on_filegroup: Option<String>,
6669}
6670
6671impl CreateIndex {
6672    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6673        Self {
6674            name: Identifier::new(name),
6675            table: TableRef::new(table),
6676            columns: Vec::new(),
6677            unique: false,
6678            if_not_exists: false,
6679            using: None,
6680            clustered: None,
6681            concurrently: false,
6682            where_clause: None,
6683            include_columns: Vec::new(),
6684            with_options: Vec::new(),
6685            on_filegroup: None,
6686        }
6687    }
6688}
6689
6690/// Index column specification
6691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6692#[cfg_attr(feature = "bindings", derive(TS))]
6693pub struct IndexColumn {
6694    pub column: Identifier,
6695    pub desc: bool,
6696    /// Explicit ASC keyword was present
6697    #[serde(default)]
6698    pub asc: bool,
6699    pub nulls_first: Option<bool>,
6700    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6701    #[serde(default, skip_serializing_if = "Option::is_none")]
6702    pub opclass: Option<String>,
6703}
6704
6705/// DROP INDEX statement
6706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6707#[cfg_attr(feature = "bindings", derive(TS))]
6708pub struct DropIndex {
6709    pub name: Identifier,
6710    pub table: Option<TableRef>,
6711    pub if_exists: bool,
6712    /// PostgreSQL CONCURRENTLY modifier
6713    #[serde(default)]
6714    pub concurrently: bool,
6715}
6716
6717impl DropIndex {
6718    pub fn new(name: impl Into<String>) -> Self {
6719        Self {
6720            name: Identifier::new(name),
6721            table: None,
6722            if_exists: false,
6723            concurrently: false,
6724        }
6725    }
6726}
6727
6728/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6730#[cfg_attr(feature = "bindings", derive(TS))]
6731pub struct ViewColumn {
6732    pub name: Identifier,
6733    pub comment: Option<String>,
6734    /// BigQuery: OPTIONS (key=value, ...) on column
6735    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6736    pub options: Vec<Expression>,
6737}
6738
6739impl ViewColumn {
6740    pub fn new(name: impl Into<String>) -> Self {
6741        Self {
6742            name: Identifier::new(name),
6743            comment: None,
6744            options: Vec::new(),
6745        }
6746    }
6747
6748    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6749        Self {
6750            name: Identifier::new(name),
6751            comment: Some(comment.into()),
6752            options: Vec::new(),
6753        }
6754    }
6755}
6756
6757/// CREATE VIEW statement
6758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6759#[cfg_attr(feature = "bindings", derive(TS))]
6760pub struct CreateView {
6761    pub name: TableRef,
6762    pub columns: Vec<ViewColumn>,
6763    pub query: Expression,
6764    pub or_replace: bool,
6765    pub if_not_exists: bool,
6766    pub materialized: bool,
6767    pub temporary: bool,
6768    /// Snowflake: SECURE VIEW
6769    #[serde(default)]
6770    pub secure: bool,
6771    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6772    #[serde(skip_serializing_if = "Option::is_none")]
6773    pub algorithm: Option<String>,
6774    /// MySQL: DEFINER=user@host
6775    #[serde(skip_serializing_if = "Option::is_none")]
6776    pub definer: Option<String>,
6777    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6778    #[serde(skip_serializing_if = "Option::is_none")]
6779    pub security: Option<FunctionSecurity>,
6780    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6781    #[serde(default = "default_true")]
6782    pub security_sql_style: bool,
6783    /// Whether the query was parenthesized: AS (SELECT ...)
6784    #[serde(default)]
6785    pub query_parenthesized: bool,
6786    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6787    #[serde(skip_serializing_if = "Option::is_none")]
6788    pub locking_mode: Option<String>,
6789    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6790    #[serde(skip_serializing_if = "Option::is_none")]
6791    pub locking_access: Option<String>,
6792    /// Snowflake: COPY GRANTS
6793    #[serde(default)]
6794    pub copy_grants: bool,
6795    /// Snowflake: COMMENT = 'text'
6796    #[serde(skip_serializing_if = "Option::is_none", default)]
6797    pub comment: Option<String>,
6798    /// Snowflake: TAG (name='value', ...)
6799    #[serde(default)]
6800    pub tags: Vec<(String, String)>,
6801    /// BigQuery: OPTIONS (key=value, ...)
6802    #[serde(default)]
6803    pub options: Vec<Expression>,
6804    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6805    #[serde(skip_serializing_if = "Option::is_none", default)]
6806    pub build: Option<String>,
6807    /// Doris: REFRESH property for materialized views
6808    #[serde(skip_serializing_if = "Option::is_none", default)]
6809    pub refresh: Option<Box<RefreshTriggerProperty>>,
6810    /// Doris: Schema with typed column definitions for materialized views
6811    /// This is used instead of `columns` when the view has typed column definitions
6812    #[serde(skip_serializing_if = "Option::is_none", default)]
6813    pub schema: Option<Box<Schema>>,
6814    /// Doris: KEY (columns) for materialized views
6815    #[serde(skip_serializing_if = "Option::is_none", default)]
6816    pub unique_key: Option<Box<UniqueKeyProperty>>,
6817    /// Redshift: WITH NO SCHEMA BINDING
6818    #[serde(default)]
6819    pub no_schema_binding: bool,
6820    /// Redshift: AUTO REFRESH YES|NO for materialized views
6821    #[serde(skip_serializing_if = "Option::is_none", default)]
6822    pub auto_refresh: Option<bool>,
6823    /// ClickHouse: ON CLUSTER clause
6824    #[serde(default, skip_serializing_if = "Option::is_none")]
6825    pub on_cluster: Option<OnCluster>,
6826    /// ClickHouse: TO destination_table
6827    #[serde(default, skip_serializing_if = "Option::is_none")]
6828    pub to_table: Option<TableRef>,
6829    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6830    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6831    pub table_properties: Vec<Expression>,
6832}
6833
6834impl CreateView {
6835    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6836        Self {
6837            name: TableRef::new(name),
6838            columns: Vec::new(),
6839            query,
6840            or_replace: false,
6841            if_not_exists: false,
6842            materialized: false,
6843            temporary: false,
6844            secure: false,
6845            algorithm: None,
6846            definer: None,
6847            security: None,
6848            security_sql_style: true,
6849            query_parenthesized: false,
6850            locking_mode: None,
6851            locking_access: None,
6852            copy_grants: false,
6853            comment: None,
6854            tags: Vec::new(),
6855            options: Vec::new(),
6856            build: None,
6857            refresh: None,
6858            schema: None,
6859            unique_key: None,
6860            no_schema_binding: false,
6861            auto_refresh: None,
6862            on_cluster: None,
6863            to_table: None,
6864            table_properties: Vec::new(),
6865        }
6866    }
6867}
6868
6869/// DROP VIEW statement
6870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6871#[cfg_attr(feature = "bindings", derive(TS))]
6872pub struct DropView {
6873    pub name: TableRef,
6874    pub if_exists: bool,
6875    pub materialized: bool,
6876}
6877
6878impl DropView {
6879    pub fn new(name: impl Into<String>) -> Self {
6880        Self {
6881            name: TableRef::new(name),
6882            if_exists: false,
6883            materialized: false,
6884        }
6885    }
6886}
6887
6888/// TRUNCATE TABLE statement
6889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6890#[cfg_attr(feature = "bindings", derive(TS))]
6891pub struct Truncate {
6892    /// Target of TRUNCATE (TABLE vs DATABASE)
6893    #[serde(default)]
6894    pub target: TruncateTarget,
6895    /// IF EXISTS clause
6896    #[serde(default)]
6897    pub if_exists: bool,
6898    pub table: TableRef,
6899    /// ClickHouse: ON CLUSTER clause for distributed DDL
6900    #[serde(default, skip_serializing_if = "Option::is_none")]
6901    pub on_cluster: Option<OnCluster>,
6902    pub cascade: bool,
6903    /// Additional tables for multi-table TRUNCATE
6904    #[serde(default)]
6905    pub extra_tables: Vec<TruncateTableEntry>,
6906    /// RESTART IDENTITY or CONTINUE IDENTITY
6907    #[serde(default)]
6908    pub identity: Option<TruncateIdentity>,
6909    /// RESTRICT option (alternative to CASCADE)
6910    #[serde(default)]
6911    pub restrict: bool,
6912    /// Hive PARTITION clause: PARTITION(key=value, ...)
6913    #[serde(default, skip_serializing_if = "Option::is_none")]
6914    pub partition: Option<Box<Expression>>,
6915}
6916
6917/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6919#[cfg_attr(feature = "bindings", derive(TS))]
6920pub struct TruncateTableEntry {
6921    pub table: TableRef,
6922    /// Whether the table has a * suffix (inherit children)
6923    #[serde(default)]
6924    pub star: bool,
6925}
6926
6927/// TRUNCATE target type
6928#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6929#[cfg_attr(feature = "bindings", derive(TS))]
6930pub enum TruncateTarget {
6931    Table,
6932    Database,
6933}
6934
6935impl Default for TruncateTarget {
6936    fn default() -> Self {
6937        TruncateTarget::Table
6938    }
6939}
6940
6941/// TRUNCATE identity option
6942#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6943#[cfg_attr(feature = "bindings", derive(TS))]
6944pub enum TruncateIdentity {
6945    Restart,
6946    Continue,
6947}
6948
6949impl Truncate {
6950    pub fn new(table: impl Into<String>) -> Self {
6951        Self {
6952            target: TruncateTarget::Table,
6953            if_exists: false,
6954            table: TableRef::new(table),
6955            on_cluster: None,
6956            cascade: false,
6957            extra_tables: Vec::new(),
6958            identity: None,
6959            restrict: false,
6960            partition: None,
6961        }
6962    }
6963}
6964
6965/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6967#[cfg_attr(feature = "bindings", derive(TS))]
6968pub struct Use {
6969    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6970    pub kind: Option<UseKind>,
6971    /// The name of the object
6972    pub this: Identifier,
6973}
6974
6975/// Kind of USE statement
6976#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6977#[cfg_attr(feature = "bindings", derive(TS))]
6978pub enum UseKind {
6979    Database,
6980    Schema,
6981    Role,
6982    Warehouse,
6983    Catalog,
6984    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6985    SecondaryRoles,
6986}
6987
6988/// SET variable statement
6989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6990#[cfg_attr(feature = "bindings", derive(TS))]
6991pub struct SetStatement {
6992    /// The items being set
6993    pub items: Vec<SetItem>,
6994}
6995
6996/// A single SET item (variable assignment)
6997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6998#[cfg_attr(feature = "bindings", derive(TS))]
6999pub struct SetItem {
7000    /// The variable name
7001    pub name: Expression,
7002    /// The value to set
7003    pub value: Expression,
7004    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
7005    pub kind: Option<String>,
7006    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
7007    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7008    pub no_equals: bool,
7009}
7010
7011/// CACHE TABLE statement (Spark)
7012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7013#[cfg_attr(feature = "bindings", derive(TS))]
7014pub struct Cache {
7015    /// The table to cache
7016    pub table: Identifier,
7017    /// LAZY keyword - defer caching until first use
7018    pub lazy: bool,
7019    /// Optional OPTIONS clause (key-value pairs)
7020    pub options: Vec<(Expression, Expression)>,
7021    /// Optional AS clause with query
7022    pub query: Option<Expression>,
7023}
7024
7025/// UNCACHE TABLE statement (Spark)
7026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7027#[cfg_attr(feature = "bindings", derive(TS))]
7028pub struct Uncache {
7029    /// The table to uncache
7030    pub table: Identifier,
7031    /// IF EXISTS clause
7032    pub if_exists: bool,
7033}
7034
7035/// LOAD DATA statement (Hive)
7036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7037#[cfg_attr(feature = "bindings", derive(TS))]
7038pub struct LoadData {
7039    /// LOCAL keyword - load from local filesystem
7040    pub local: bool,
7041    /// The path to load data from (INPATH value)
7042    pub inpath: String,
7043    /// Whether to overwrite existing data
7044    pub overwrite: bool,
7045    /// The target table
7046    pub table: Expression,
7047    /// Optional PARTITION clause with key-value pairs
7048    pub partition: Vec<(Identifier, Expression)>,
7049    /// Optional INPUTFORMAT clause
7050    pub input_format: Option<String>,
7051    /// Optional SERDE clause
7052    pub serde: Option<String>,
7053}
7054
7055/// PRAGMA statement (SQLite)
7056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7057#[cfg_attr(feature = "bindings", derive(TS))]
7058pub struct Pragma {
7059    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
7060    pub schema: Option<Identifier>,
7061    /// The pragma name
7062    pub name: Identifier,
7063    /// Optional value for assignment (PRAGMA name = value)
7064    pub value: Option<Expression>,
7065    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
7066    pub args: Vec<Expression>,
7067}
7068
7069/// A privilege with optional column list for GRANT/REVOKE
7070/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
7071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7072#[cfg_attr(feature = "bindings", derive(TS))]
7073pub struct Privilege {
7074    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
7075    pub name: String,
7076    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
7077    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7078    pub columns: Vec<String>,
7079}
7080
7081/// Principal in GRANT/REVOKE (user, role, etc.)
7082#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7083#[cfg_attr(feature = "bindings", derive(TS))]
7084pub struct GrantPrincipal {
7085    /// The name of the principal
7086    pub name: Identifier,
7087    /// Whether prefixed with ROLE keyword
7088    pub is_role: bool,
7089    /// Whether prefixed with GROUP keyword (Redshift)
7090    #[serde(default)]
7091    pub is_group: bool,
7092}
7093
7094/// GRANT statement
7095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7096#[cfg_attr(feature = "bindings", derive(TS))]
7097pub struct Grant {
7098    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
7099    pub privileges: Vec<Privilege>,
7100    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7101    pub kind: Option<String>,
7102    /// The object to grant on
7103    pub securable: Identifier,
7104    /// Function parameter types (for FUNCTION kind)
7105    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7106    pub function_params: Vec<String>,
7107    /// The grantees
7108    pub principals: Vec<GrantPrincipal>,
7109    /// WITH GRANT OPTION
7110    pub grant_option: bool,
7111    /// TSQL: AS principal (the grantor role)
7112    #[serde(default, skip_serializing_if = "Option::is_none")]
7113    pub as_principal: Option<Identifier>,
7114}
7115
7116/// REVOKE statement
7117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7118#[cfg_attr(feature = "bindings", derive(TS))]
7119pub struct Revoke {
7120    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
7121    pub privileges: Vec<Privilege>,
7122    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
7123    pub kind: Option<String>,
7124    /// The object to revoke from
7125    pub securable: Identifier,
7126    /// Function parameter types (for FUNCTION kind)
7127    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7128    pub function_params: Vec<String>,
7129    /// The grantees
7130    pub principals: Vec<GrantPrincipal>,
7131    /// GRANT OPTION FOR
7132    pub grant_option: bool,
7133    /// CASCADE
7134    pub cascade: bool,
7135    /// RESTRICT
7136    #[serde(default)]
7137    pub restrict: bool,
7138}
7139
7140/// COMMENT ON statement
7141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7142#[cfg_attr(feature = "bindings", derive(TS))]
7143pub struct Comment {
7144    /// The object being commented on
7145    pub this: Expression,
7146    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
7147    pub kind: String,
7148    /// The comment text expression
7149    pub expression: Expression,
7150    /// IF EXISTS clause
7151    pub exists: bool,
7152    /// MATERIALIZED keyword
7153    pub materialized: bool,
7154}
7155
7156// ============================================================================
7157// Phase 4: Additional DDL Statements
7158// ============================================================================
7159
7160/// ALTER VIEW statement
7161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7162#[cfg_attr(feature = "bindings", derive(TS))]
7163pub struct AlterView {
7164    pub name: TableRef,
7165    pub actions: Vec<AlterViewAction>,
7166    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
7167    #[serde(default, skip_serializing_if = "Option::is_none")]
7168    pub algorithm: Option<String>,
7169    /// MySQL: DEFINER = 'user'@'host'
7170    #[serde(default, skip_serializing_if = "Option::is_none")]
7171    pub definer: Option<String>,
7172    /// MySQL: SQL SECURITY = DEFINER|INVOKER
7173    #[serde(default, skip_serializing_if = "Option::is_none")]
7174    pub sql_security: Option<String>,
7175    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
7176    #[serde(default, skip_serializing_if = "Option::is_none")]
7177    pub with_option: Option<String>,
7178    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
7179    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7180    pub columns: Vec<ViewColumn>,
7181}
7182
7183/// Actions for ALTER VIEW
7184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7185#[cfg_attr(feature = "bindings", derive(TS))]
7186pub enum AlterViewAction {
7187    /// Rename the view
7188    Rename(TableRef),
7189    /// Change owner
7190    OwnerTo(Identifier),
7191    /// Set schema
7192    SetSchema(Identifier),
7193    /// Set authorization (Trino/Presto)
7194    SetAuthorization(String),
7195    /// Alter column
7196    AlterColumn {
7197        name: Identifier,
7198        action: AlterColumnAction,
7199    },
7200    /// Redefine view as query (SELECT, UNION, etc.)
7201    AsSelect(Box<Expression>),
7202    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
7203    SetTblproperties(Vec<(String, String)>),
7204    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
7205    UnsetTblproperties(Vec<String>),
7206}
7207
7208impl AlterView {
7209    pub fn new(name: impl Into<String>) -> Self {
7210        Self {
7211            name: TableRef::new(name),
7212            actions: Vec::new(),
7213            algorithm: None,
7214            definer: None,
7215            sql_security: None,
7216            with_option: None,
7217            columns: Vec::new(),
7218        }
7219    }
7220}
7221
7222/// ALTER INDEX statement
7223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7224#[cfg_attr(feature = "bindings", derive(TS))]
7225pub struct AlterIndex {
7226    pub name: Identifier,
7227    pub table: Option<TableRef>,
7228    pub actions: Vec<AlterIndexAction>,
7229}
7230
7231/// Actions for ALTER INDEX
7232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7233#[cfg_attr(feature = "bindings", derive(TS))]
7234pub enum AlterIndexAction {
7235    /// Rename the index
7236    Rename(Identifier),
7237    /// Set tablespace
7238    SetTablespace(Identifier),
7239    /// Set visibility (MySQL)
7240    Visible(bool),
7241}
7242
7243impl AlterIndex {
7244    pub fn new(name: impl Into<String>) -> Self {
7245        Self {
7246            name: Identifier::new(name),
7247            table: None,
7248            actions: Vec::new(),
7249        }
7250    }
7251}
7252
7253/// CREATE SCHEMA statement
7254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7255#[cfg_attr(feature = "bindings", derive(TS))]
7256pub struct CreateSchema {
7257    pub name: Identifier,
7258    pub if_not_exists: bool,
7259    pub authorization: Option<Identifier>,
7260    #[serde(default)]
7261    pub clone_from: Option<Identifier>,
7262    /// AT/BEFORE clause for time travel (Snowflake)
7263    #[serde(default)]
7264    pub at_clause: Option<Expression>,
7265    /// Schema properties like DEFAULT COLLATE
7266    #[serde(default)]
7267    pub properties: Vec<Expression>,
7268    /// Leading comments before the statement
7269    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7270    pub leading_comments: Vec<String>,
7271}
7272
7273impl CreateSchema {
7274    pub fn new(name: impl Into<String>) -> Self {
7275        Self {
7276            name: Identifier::new(name),
7277            if_not_exists: false,
7278            authorization: None,
7279            clone_from: None,
7280            at_clause: None,
7281            properties: Vec::new(),
7282            leading_comments: Vec::new(),
7283        }
7284    }
7285}
7286
7287/// DROP SCHEMA statement
7288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7289#[cfg_attr(feature = "bindings", derive(TS))]
7290pub struct DropSchema {
7291    pub name: Identifier,
7292    pub if_exists: bool,
7293    pub cascade: bool,
7294}
7295
7296impl DropSchema {
7297    pub fn new(name: impl Into<String>) -> Self {
7298        Self {
7299            name: Identifier::new(name),
7300            if_exists: false,
7301            cascade: false,
7302        }
7303    }
7304}
7305
7306/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
7307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7308#[cfg_attr(feature = "bindings", derive(TS))]
7309pub struct DropNamespace {
7310    pub name: Identifier,
7311    pub if_exists: bool,
7312    pub cascade: bool,
7313}
7314
7315impl DropNamespace {
7316    pub fn new(name: impl Into<String>) -> Self {
7317        Self {
7318            name: Identifier::new(name),
7319            if_exists: false,
7320            cascade: false,
7321        }
7322    }
7323}
7324
7325/// CREATE DATABASE statement
7326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7327#[cfg_attr(feature = "bindings", derive(TS))]
7328pub struct CreateDatabase {
7329    pub name: Identifier,
7330    pub if_not_exists: bool,
7331    pub options: Vec<DatabaseOption>,
7332    /// Snowflake CLONE source
7333    #[serde(default)]
7334    pub clone_from: Option<Identifier>,
7335    /// AT/BEFORE clause for time travel (Snowflake)
7336    #[serde(default)]
7337    pub at_clause: Option<Expression>,
7338}
7339
7340/// Database option
7341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7342#[cfg_attr(feature = "bindings", derive(TS))]
7343pub enum DatabaseOption {
7344    CharacterSet(String),
7345    Collate(String),
7346    Owner(Identifier),
7347    Template(Identifier),
7348    Encoding(String),
7349    Location(String),
7350}
7351
7352impl CreateDatabase {
7353    pub fn new(name: impl Into<String>) -> Self {
7354        Self {
7355            name: Identifier::new(name),
7356            if_not_exists: false,
7357            options: Vec::new(),
7358            clone_from: None,
7359            at_clause: None,
7360        }
7361    }
7362}
7363
7364/// DROP DATABASE statement
7365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7366#[cfg_attr(feature = "bindings", derive(TS))]
7367pub struct DropDatabase {
7368    pub name: Identifier,
7369    pub if_exists: bool,
7370}
7371
7372impl DropDatabase {
7373    pub fn new(name: impl Into<String>) -> Self {
7374        Self {
7375            name: Identifier::new(name),
7376            if_exists: false,
7377        }
7378    }
7379}
7380
7381/// CREATE FUNCTION statement
7382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7383#[cfg_attr(feature = "bindings", derive(TS))]
7384pub struct CreateFunction {
7385    pub name: TableRef,
7386    pub parameters: Vec<FunctionParameter>,
7387    pub return_type: Option<DataType>,
7388    pub body: Option<FunctionBody>,
7389    pub or_replace: bool,
7390    pub if_not_exists: bool,
7391    pub temporary: bool,
7392    pub language: Option<String>,
7393    pub deterministic: Option<bool>,
7394    pub returns_null_on_null_input: Option<bool>,
7395    pub security: Option<FunctionSecurity>,
7396    /// Whether parentheses were present in the original syntax
7397    #[serde(default = "default_true")]
7398    pub has_parens: bool,
7399    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
7400    #[serde(default)]
7401    pub sql_data_access: Option<SqlDataAccess>,
7402    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
7403    #[serde(default, skip_serializing_if = "Option::is_none")]
7404    pub returns_table_body: Option<String>,
7405    /// True if LANGUAGE clause appears before RETURNS clause
7406    #[serde(default)]
7407    pub language_first: bool,
7408    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
7409    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7410    pub set_options: Vec<FunctionSetOption>,
7411    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
7412    #[serde(default)]
7413    pub strict: bool,
7414    /// BigQuery: OPTIONS (key=value, ...)
7415    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7416    pub options: Vec<Expression>,
7417    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
7418    #[serde(default)]
7419    pub is_table_function: bool,
7420    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
7421    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7422    pub property_order: Vec<FunctionPropertyKind>,
7423    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
7424    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7425    pub environment: Vec<Expression>,
7426}
7427
7428/// A SET option in CREATE FUNCTION (PostgreSQL)
7429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7430#[cfg_attr(feature = "bindings", derive(TS))]
7431pub struct FunctionSetOption {
7432    pub name: String,
7433    pub value: FunctionSetValue,
7434}
7435
7436/// The value of a SET option
7437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7438#[cfg_attr(feature = "bindings", derive(TS))]
7439pub enum FunctionSetValue {
7440    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
7441    Value { value: String, use_to: bool },
7442    /// SET key FROM CURRENT
7443    FromCurrent,
7444}
7445
7446/// SQL data access characteristics for functions
7447#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7448#[cfg_attr(feature = "bindings", derive(TS))]
7449pub enum SqlDataAccess {
7450    /// NO SQL
7451    NoSql,
7452    /// CONTAINS SQL
7453    ContainsSql,
7454    /// READS SQL DATA
7455    ReadsSqlData,
7456    /// MODIFIES SQL DATA
7457    ModifiesSqlData,
7458}
7459
7460/// Types of properties in CREATE FUNCTION for tracking their original order
7461#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7462#[cfg_attr(feature = "bindings", derive(TS))]
7463pub enum FunctionPropertyKind {
7464    /// SET option
7465    Set,
7466    /// AS body
7467    As,
7468    /// LANGUAGE clause
7469    Language,
7470    /// IMMUTABLE/VOLATILE/STABLE (determinism)
7471    Determinism,
7472    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
7473    NullInput,
7474    /// SECURITY DEFINER/INVOKER
7475    Security,
7476    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
7477    SqlDataAccess,
7478    /// OPTIONS clause (BigQuery)
7479    Options,
7480    /// ENVIRONMENT clause (Databricks)
7481    Environment,
7482}
7483
7484/// Function parameter
7485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7486#[cfg_attr(feature = "bindings", derive(TS))]
7487pub struct FunctionParameter {
7488    pub name: Option<Identifier>,
7489    pub data_type: DataType,
7490    pub mode: Option<ParameterMode>,
7491    pub default: Option<Expression>,
7492    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
7493    #[serde(default, skip_serializing_if = "Option::is_none")]
7494    pub mode_text: Option<String>,
7495}
7496
7497/// Parameter mode (IN, OUT, INOUT, VARIADIC)
7498#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7499#[cfg_attr(feature = "bindings", derive(TS))]
7500pub enum ParameterMode {
7501    In,
7502    Out,
7503    InOut,
7504    Variadic,
7505}
7506
7507/// Function body
7508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7509#[cfg_attr(feature = "bindings", derive(TS))]
7510pub enum FunctionBody {
7511    /// AS $$ ... $$ (dollar-quoted)
7512    Block(String),
7513    /// AS 'string' (single-quoted string literal body)
7514    StringLiteral(String),
7515    /// AS 'expression'
7516    Expression(Expression),
7517    /// EXTERNAL NAME 'library'
7518    External(String),
7519    /// RETURN expression
7520    Return(Expression),
7521    /// BEGIN ... END block with parsed statements
7522    Statements(Vec<Expression>),
7523    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7524    /// Stores (content, optional_tag)
7525    DollarQuoted {
7526        content: String,
7527        tag: Option<String>,
7528    },
7529}
7530
7531/// Function security (DEFINER, INVOKER, or NONE)
7532#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7533#[cfg_attr(feature = "bindings", derive(TS))]
7534pub enum FunctionSecurity {
7535    Definer,
7536    Invoker,
7537    /// StarRocks/MySQL: SECURITY NONE
7538    None,
7539}
7540
7541impl CreateFunction {
7542    pub fn new(name: impl Into<String>) -> Self {
7543        Self {
7544            name: TableRef::new(name),
7545            parameters: Vec::new(),
7546            return_type: None,
7547            body: None,
7548            or_replace: false,
7549            if_not_exists: false,
7550            temporary: false,
7551            language: None,
7552            deterministic: None,
7553            returns_null_on_null_input: None,
7554            security: None,
7555            has_parens: true,
7556            sql_data_access: None,
7557            returns_table_body: None,
7558            language_first: false,
7559            set_options: Vec::new(),
7560            strict: false,
7561            options: Vec::new(),
7562            is_table_function: false,
7563            property_order: Vec::new(),
7564            environment: Vec::new(),
7565        }
7566    }
7567}
7568
7569/// DROP FUNCTION statement
7570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7571#[cfg_attr(feature = "bindings", derive(TS))]
7572pub struct DropFunction {
7573    pub name: TableRef,
7574    pub parameters: Option<Vec<DataType>>,
7575    pub if_exists: bool,
7576    pub cascade: bool,
7577}
7578
7579impl DropFunction {
7580    pub fn new(name: impl Into<String>) -> Self {
7581        Self {
7582            name: TableRef::new(name),
7583            parameters: None,
7584            if_exists: false,
7585            cascade: false,
7586        }
7587    }
7588}
7589
7590/// CREATE PROCEDURE statement
7591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7592#[cfg_attr(feature = "bindings", derive(TS))]
7593pub struct CreateProcedure {
7594    pub name: TableRef,
7595    pub parameters: Vec<FunctionParameter>,
7596    pub body: Option<FunctionBody>,
7597    pub or_replace: bool,
7598    pub if_not_exists: bool,
7599    pub language: Option<String>,
7600    pub security: Option<FunctionSecurity>,
7601    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7602    #[serde(default)]
7603    pub return_type: Option<DataType>,
7604    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7605    #[serde(default)]
7606    pub execute_as: Option<String>,
7607    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7608    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7609    pub with_options: Vec<String>,
7610    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7611    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7612    pub has_parens: bool,
7613    /// Whether the short form PROC was used (instead of PROCEDURE)
7614    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7615    pub use_proc_keyword: bool,
7616}
7617
7618impl CreateProcedure {
7619    pub fn new(name: impl Into<String>) -> Self {
7620        Self {
7621            name: TableRef::new(name),
7622            parameters: Vec::new(),
7623            body: None,
7624            or_replace: false,
7625            if_not_exists: false,
7626            language: None,
7627            security: None,
7628            return_type: None,
7629            execute_as: None,
7630            with_options: Vec::new(),
7631            has_parens: true,
7632            use_proc_keyword: false,
7633        }
7634    }
7635}
7636
7637/// DROP PROCEDURE statement
7638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7639#[cfg_attr(feature = "bindings", derive(TS))]
7640pub struct DropProcedure {
7641    pub name: TableRef,
7642    pub parameters: Option<Vec<DataType>>,
7643    pub if_exists: bool,
7644    pub cascade: bool,
7645}
7646
7647impl DropProcedure {
7648    pub fn new(name: impl Into<String>) -> Self {
7649        Self {
7650            name: TableRef::new(name),
7651            parameters: None,
7652            if_exists: false,
7653            cascade: false,
7654        }
7655    }
7656}
7657
7658/// Sequence property tag for ordering
7659#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7660#[cfg_attr(feature = "bindings", derive(TS))]
7661pub enum SeqPropKind {
7662    Start,
7663    Increment,
7664    Minvalue,
7665    Maxvalue,
7666    Cache,
7667    NoCache,
7668    Cycle,
7669    NoCycle,
7670    OwnedBy,
7671    Order,
7672    NoOrder,
7673    Comment,
7674    /// SHARING=<value> (Oracle)
7675    Sharing,
7676    /// KEEP (Oracle)
7677    Keep,
7678    /// NOKEEP (Oracle)
7679    NoKeep,
7680    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7681    Scale,
7682    /// NOSCALE (Oracle)
7683    NoScale,
7684    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7685    Shard,
7686    /// NOSHARD (Oracle)
7687    NoShard,
7688    /// SESSION (Oracle)
7689    Session,
7690    /// GLOBAL (Oracle)
7691    Global,
7692    /// NOCACHE (single word, Oracle)
7693    NoCacheWord,
7694    /// NOCYCLE (single word, Oracle)
7695    NoCycleWord,
7696    /// NOMINVALUE (single word, Oracle)
7697    NoMinvalueWord,
7698    /// NOMAXVALUE (single word, Oracle)
7699    NoMaxvalueWord,
7700}
7701
7702/// CREATE SEQUENCE statement
7703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7704#[cfg_attr(feature = "bindings", derive(TS))]
7705pub struct CreateSequence {
7706    pub name: TableRef,
7707    pub if_not_exists: bool,
7708    pub temporary: bool,
7709    #[serde(default)]
7710    pub or_replace: bool,
7711    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7712    #[serde(default, skip_serializing_if = "Option::is_none")]
7713    pub as_type: Option<DataType>,
7714    pub increment: Option<i64>,
7715    pub minvalue: Option<SequenceBound>,
7716    pub maxvalue: Option<SequenceBound>,
7717    pub start: Option<i64>,
7718    pub cache: Option<i64>,
7719    pub cycle: bool,
7720    pub owned_by: Option<TableRef>,
7721    /// Whether OWNED BY NONE was specified
7722    #[serde(default)]
7723    pub owned_by_none: bool,
7724    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7725    #[serde(default)]
7726    pub order: Option<bool>,
7727    /// Snowflake: COMMENT = 'value'
7728    #[serde(default)]
7729    pub comment: Option<String>,
7730    /// SHARING=<value> (Oracle)
7731    #[serde(default, skip_serializing_if = "Option::is_none")]
7732    pub sharing: Option<String>,
7733    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7734    #[serde(default, skip_serializing_if = "Option::is_none")]
7735    pub scale_modifier: Option<String>,
7736    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7737    #[serde(default, skip_serializing_if = "Option::is_none")]
7738    pub shard_modifier: Option<String>,
7739    /// Tracks the order in which properties appeared in the source
7740    #[serde(default)]
7741    pub property_order: Vec<SeqPropKind>,
7742}
7743
7744/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7746#[cfg_attr(feature = "bindings", derive(TS))]
7747pub enum SequenceBound {
7748    Value(i64),
7749    None,
7750}
7751
7752impl CreateSequence {
7753    pub fn new(name: impl Into<String>) -> Self {
7754        Self {
7755            name: TableRef::new(name),
7756            if_not_exists: false,
7757            temporary: false,
7758            or_replace: false,
7759            as_type: None,
7760            increment: None,
7761            minvalue: None,
7762            maxvalue: None,
7763            start: None,
7764            cache: None,
7765            cycle: false,
7766            owned_by: None,
7767            owned_by_none: false,
7768            order: None,
7769            comment: None,
7770            sharing: None,
7771            scale_modifier: None,
7772            shard_modifier: None,
7773            property_order: Vec::new(),
7774        }
7775    }
7776}
7777
7778/// DROP SEQUENCE statement
7779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7780#[cfg_attr(feature = "bindings", derive(TS))]
7781pub struct DropSequence {
7782    pub name: TableRef,
7783    pub if_exists: bool,
7784    pub cascade: bool,
7785}
7786
7787impl DropSequence {
7788    pub fn new(name: impl Into<String>) -> Self {
7789        Self {
7790            name: TableRef::new(name),
7791            if_exists: false,
7792            cascade: false,
7793        }
7794    }
7795}
7796
7797/// ALTER SEQUENCE statement
7798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7799#[cfg_attr(feature = "bindings", derive(TS))]
7800pub struct AlterSequence {
7801    pub name: TableRef,
7802    pub if_exists: bool,
7803    pub increment: Option<i64>,
7804    pub minvalue: Option<SequenceBound>,
7805    pub maxvalue: Option<SequenceBound>,
7806    pub start: Option<i64>,
7807    pub restart: Option<Option<i64>>,
7808    pub cache: Option<i64>,
7809    pub cycle: Option<bool>,
7810    pub owned_by: Option<Option<TableRef>>,
7811}
7812
7813impl AlterSequence {
7814    pub fn new(name: impl Into<String>) -> Self {
7815        Self {
7816            name: TableRef::new(name),
7817            if_exists: false,
7818            increment: None,
7819            minvalue: None,
7820            maxvalue: None,
7821            start: None,
7822            restart: None,
7823            cache: None,
7824            cycle: None,
7825            owned_by: None,
7826        }
7827    }
7828}
7829
7830/// CREATE TRIGGER statement
7831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7832#[cfg_attr(feature = "bindings", derive(TS))]
7833pub struct CreateTrigger {
7834    pub name: Identifier,
7835    pub table: TableRef,
7836    pub timing: TriggerTiming,
7837    pub events: Vec<TriggerEvent>,
7838    pub for_each: TriggerForEach,
7839    pub when: Option<Expression>,
7840    pub body: TriggerBody,
7841    pub or_replace: bool,
7842    pub constraint: bool,
7843    pub deferrable: Option<bool>,
7844    pub initially_deferred: Option<bool>,
7845    pub referencing: Option<TriggerReferencing>,
7846}
7847
7848/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7849#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7850#[cfg_attr(feature = "bindings", derive(TS))]
7851pub enum TriggerTiming {
7852    Before,
7853    After,
7854    InsteadOf,
7855}
7856
7857/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7859#[cfg_attr(feature = "bindings", derive(TS))]
7860pub enum TriggerEvent {
7861    Insert,
7862    Update(Option<Vec<Identifier>>),
7863    Delete,
7864    Truncate,
7865}
7866
7867/// Trigger FOR EACH clause
7868#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7869#[cfg_attr(feature = "bindings", derive(TS))]
7870pub enum TriggerForEach {
7871    Row,
7872    Statement,
7873}
7874
7875/// Trigger body
7876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7877#[cfg_attr(feature = "bindings", derive(TS))]
7878pub enum TriggerBody {
7879    /// EXECUTE FUNCTION/PROCEDURE name(args)
7880    Execute {
7881        function: TableRef,
7882        args: Vec<Expression>,
7883    },
7884    /// BEGIN ... END block
7885    Block(String),
7886}
7887
7888/// Trigger REFERENCING clause
7889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7890#[cfg_attr(feature = "bindings", derive(TS))]
7891pub struct TriggerReferencing {
7892    pub old_table: Option<Identifier>,
7893    pub new_table: Option<Identifier>,
7894    pub old_row: Option<Identifier>,
7895    pub new_row: Option<Identifier>,
7896}
7897
7898impl CreateTrigger {
7899    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7900        Self {
7901            name: Identifier::new(name),
7902            table: TableRef::new(table),
7903            timing: TriggerTiming::Before,
7904            events: Vec::new(),
7905            for_each: TriggerForEach::Row,
7906            when: None,
7907            body: TriggerBody::Execute {
7908                function: TableRef::new(""),
7909                args: Vec::new(),
7910            },
7911            or_replace: false,
7912            constraint: false,
7913            deferrable: None,
7914            initially_deferred: None,
7915            referencing: None,
7916        }
7917    }
7918}
7919
7920/// DROP TRIGGER statement
7921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7922#[cfg_attr(feature = "bindings", derive(TS))]
7923pub struct DropTrigger {
7924    pub name: Identifier,
7925    pub table: Option<TableRef>,
7926    pub if_exists: bool,
7927    pub cascade: bool,
7928}
7929
7930impl DropTrigger {
7931    pub fn new(name: impl Into<String>) -> Self {
7932        Self {
7933            name: Identifier::new(name),
7934            table: None,
7935            if_exists: false,
7936            cascade: false,
7937        }
7938    }
7939}
7940
7941/// CREATE TYPE statement
7942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7943#[cfg_attr(feature = "bindings", derive(TS))]
7944pub struct CreateType {
7945    pub name: TableRef,
7946    pub definition: TypeDefinition,
7947    pub if_not_exists: bool,
7948}
7949
7950/// Type definition
7951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7952#[cfg_attr(feature = "bindings", derive(TS))]
7953pub enum TypeDefinition {
7954    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7955    Enum(Vec<String>),
7956    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7957    Composite(Vec<TypeAttribute>),
7958    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7959    Range {
7960        subtype: DataType,
7961        subtype_diff: Option<String>,
7962        canonical: Option<String>,
7963    },
7964    /// Base type (for advanced usage)
7965    Base {
7966        input: String,
7967        output: String,
7968        internallength: Option<i32>,
7969    },
7970    /// Domain type
7971    Domain {
7972        base_type: DataType,
7973        default: Option<Expression>,
7974        constraints: Vec<DomainConstraint>,
7975    },
7976}
7977
7978/// Type attribute for composite types
7979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7980#[cfg_attr(feature = "bindings", derive(TS))]
7981pub struct TypeAttribute {
7982    pub name: Identifier,
7983    pub data_type: DataType,
7984    pub collate: Option<Identifier>,
7985}
7986
7987/// Domain constraint
7988#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7989#[cfg_attr(feature = "bindings", derive(TS))]
7990pub struct DomainConstraint {
7991    pub name: Option<Identifier>,
7992    pub check: Expression,
7993}
7994
7995impl CreateType {
7996    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7997        Self {
7998            name: TableRef::new(name),
7999            definition: TypeDefinition::Enum(values),
8000            if_not_exists: false,
8001        }
8002    }
8003
8004    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
8005        Self {
8006            name: TableRef::new(name),
8007            definition: TypeDefinition::Composite(attributes),
8008            if_not_exists: false,
8009        }
8010    }
8011}
8012
8013/// DROP TYPE statement
8014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8015#[cfg_attr(feature = "bindings", derive(TS))]
8016pub struct DropType {
8017    pub name: TableRef,
8018    pub if_exists: bool,
8019    pub cascade: bool,
8020}
8021
8022impl DropType {
8023    pub fn new(name: impl Into<String>) -> Self {
8024        Self {
8025            name: TableRef::new(name),
8026            if_exists: false,
8027            cascade: false,
8028        }
8029    }
8030}
8031
8032/// DESCRIBE statement - shows table structure or query plan
8033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8034#[cfg_attr(feature = "bindings", derive(TS))]
8035pub struct Describe {
8036    /// The target to describe (table name or query)
8037    pub target: Expression,
8038    /// EXTENDED format
8039    pub extended: bool,
8040    /// FORMATTED format
8041    pub formatted: bool,
8042    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
8043    #[serde(default)]
8044    pub kind: Option<String>,
8045    /// Properties like type=stage
8046    #[serde(default)]
8047    pub properties: Vec<(String, String)>,
8048    /// Style keyword (e.g., "ANALYZE", "HISTORY")
8049    #[serde(default, skip_serializing_if = "Option::is_none")]
8050    pub style: Option<String>,
8051    /// Partition specification for DESCRIBE PARTITION
8052    #[serde(default)]
8053    pub partition: Option<Box<Expression>>,
8054    /// Leading comments before the statement
8055    #[serde(default)]
8056    pub leading_comments: Vec<String>,
8057    /// AS JSON suffix (Databricks)
8058    #[serde(default)]
8059    pub as_json: bool,
8060}
8061
8062impl Describe {
8063    pub fn new(target: Expression) -> Self {
8064        Self {
8065            target,
8066            extended: false,
8067            formatted: false,
8068            kind: None,
8069            properties: Vec::new(),
8070            style: None,
8071            partition: None,
8072            leading_comments: Vec::new(),
8073            as_json: false,
8074        }
8075    }
8076}
8077
8078/// SHOW statement - displays database objects
8079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8080#[cfg_attr(feature = "bindings", derive(TS))]
8081pub struct Show {
8082    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
8083    pub this: String,
8084    /// Whether TERSE was specified
8085    #[serde(default)]
8086    pub terse: bool,
8087    /// Whether HISTORY was specified
8088    #[serde(default)]
8089    pub history: bool,
8090    /// LIKE pattern
8091    pub like: Option<Expression>,
8092    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
8093    pub scope_kind: Option<String>,
8094    /// IN scope object
8095    pub scope: Option<Expression>,
8096    /// STARTS WITH pattern
8097    pub starts_with: Option<Expression>,
8098    /// LIMIT clause
8099    pub limit: Option<Box<Limit>>,
8100    /// FROM clause (for specific object)
8101    pub from: Option<Expression>,
8102    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
8103    #[serde(default, skip_serializing_if = "Option::is_none")]
8104    pub where_clause: Option<Expression>,
8105    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
8106    #[serde(default, skip_serializing_if = "Option::is_none")]
8107    pub for_target: Option<Expression>,
8108    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
8109    #[serde(default, skip_serializing_if = "Option::is_none")]
8110    pub db: Option<Expression>,
8111    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
8112    #[serde(default, skip_serializing_if = "Option::is_none")]
8113    pub target: Option<Expression>,
8114    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
8115    #[serde(default, skip_serializing_if = "Option::is_none")]
8116    pub mutex: Option<bool>,
8117    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
8118    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8119    pub privileges: Vec<String>,
8120}
8121
8122impl Show {
8123    pub fn new(this: impl Into<String>) -> Self {
8124        Self {
8125            this: this.into(),
8126            terse: false,
8127            history: false,
8128            like: None,
8129            scope_kind: None,
8130            scope: None,
8131            starts_with: None,
8132            limit: None,
8133            from: None,
8134            where_clause: None,
8135            for_target: None,
8136            db: None,
8137            target: None,
8138            mutex: None,
8139            privileges: Vec::new(),
8140        }
8141    }
8142}
8143
8144/// Represent an explicit parenthesized expression for grouping precedence.
8145///
8146/// Preserves user-written parentheses so that `(a + b) * c` round-trips
8147/// correctly instead of being flattened to `a + b * c`.
8148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8149#[cfg_attr(feature = "bindings", derive(TS))]
8150pub struct Paren {
8151    /// The inner expression wrapped by parentheses.
8152    pub this: Expression,
8153    #[serde(default)]
8154    pub trailing_comments: Vec<String>,
8155}
8156
8157/// Expression annotated with trailing comments (for round-trip preservation)
8158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8159#[cfg_attr(feature = "bindings", derive(TS))]
8160pub struct Annotated {
8161    pub this: Expression,
8162    pub trailing_comments: Vec<String>,
8163}
8164
8165// === BATCH GENERATED STRUCT DEFINITIONS ===
8166// Generated from Python sqlglot expressions.py
8167
8168/// Refresh
8169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8170#[cfg_attr(feature = "bindings", derive(TS))]
8171pub struct Refresh {
8172    pub this: Box<Expression>,
8173    pub kind: String,
8174}
8175
8176/// LockingStatement
8177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8178#[cfg_attr(feature = "bindings", derive(TS))]
8179pub struct LockingStatement {
8180    pub this: Box<Expression>,
8181    pub expression: Box<Expression>,
8182}
8183
8184/// SequenceProperties
8185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8186#[cfg_attr(feature = "bindings", derive(TS))]
8187pub struct SequenceProperties {
8188    #[serde(default)]
8189    pub increment: Option<Box<Expression>>,
8190    #[serde(default)]
8191    pub minvalue: Option<Box<Expression>>,
8192    #[serde(default)]
8193    pub maxvalue: Option<Box<Expression>>,
8194    #[serde(default)]
8195    pub cache: Option<Box<Expression>>,
8196    #[serde(default)]
8197    pub start: Option<Box<Expression>>,
8198    #[serde(default)]
8199    pub owned: Option<Box<Expression>>,
8200    #[serde(default)]
8201    pub options: Vec<Expression>,
8202}
8203
8204/// TruncateTable
8205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8206#[cfg_attr(feature = "bindings", derive(TS))]
8207pub struct TruncateTable {
8208    #[serde(default)]
8209    pub expressions: Vec<Expression>,
8210    #[serde(default)]
8211    pub is_database: Option<Box<Expression>>,
8212    #[serde(default)]
8213    pub exists: bool,
8214    #[serde(default)]
8215    pub only: Option<Box<Expression>>,
8216    #[serde(default)]
8217    pub cluster: Option<Box<Expression>>,
8218    #[serde(default)]
8219    pub identity: Option<Box<Expression>>,
8220    #[serde(default)]
8221    pub option: Option<Box<Expression>>,
8222    #[serde(default)]
8223    pub partition: Option<Box<Expression>>,
8224}
8225
8226/// Clone
8227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8228#[cfg_attr(feature = "bindings", derive(TS))]
8229pub struct Clone {
8230    pub this: Box<Expression>,
8231    #[serde(default)]
8232    pub shallow: Option<Box<Expression>>,
8233    #[serde(default)]
8234    pub copy: Option<Box<Expression>>,
8235}
8236
8237/// Attach
8238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8239#[cfg_attr(feature = "bindings", derive(TS))]
8240pub struct Attach {
8241    pub this: Box<Expression>,
8242    #[serde(default)]
8243    pub exists: bool,
8244    #[serde(default)]
8245    pub expressions: Vec<Expression>,
8246}
8247
8248/// Detach
8249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8250#[cfg_attr(feature = "bindings", derive(TS))]
8251pub struct Detach {
8252    pub this: Box<Expression>,
8253    #[serde(default)]
8254    pub exists: bool,
8255}
8256
8257/// Install
8258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8259#[cfg_attr(feature = "bindings", derive(TS))]
8260pub struct Install {
8261    pub this: Box<Expression>,
8262    #[serde(default)]
8263    pub from_: Option<Box<Expression>>,
8264    #[serde(default)]
8265    pub force: Option<Box<Expression>>,
8266}
8267
8268/// Summarize
8269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8270#[cfg_attr(feature = "bindings", derive(TS))]
8271pub struct Summarize {
8272    pub this: Box<Expression>,
8273    #[serde(default)]
8274    pub table: Option<Box<Expression>>,
8275}
8276
8277/// Declare
8278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8279#[cfg_attr(feature = "bindings", derive(TS))]
8280pub struct Declare {
8281    #[serde(default)]
8282    pub expressions: Vec<Expression>,
8283}
8284
8285/// DeclareItem
8286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8287#[cfg_attr(feature = "bindings", derive(TS))]
8288pub struct DeclareItem {
8289    pub this: Box<Expression>,
8290    #[serde(default)]
8291    pub kind: Option<String>,
8292    #[serde(default)]
8293    pub default: Option<Box<Expression>>,
8294    #[serde(default)]
8295    pub has_as: bool,
8296    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
8297    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8298    pub additional_names: Vec<Expression>,
8299}
8300
8301/// Set
8302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8303#[cfg_attr(feature = "bindings", derive(TS))]
8304pub struct Set {
8305    #[serde(default)]
8306    pub expressions: Vec<Expression>,
8307    #[serde(default)]
8308    pub unset: Option<Box<Expression>>,
8309    #[serde(default)]
8310    pub tag: Option<Box<Expression>>,
8311}
8312
8313/// Heredoc
8314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8315#[cfg_attr(feature = "bindings", derive(TS))]
8316pub struct Heredoc {
8317    pub this: Box<Expression>,
8318    #[serde(default)]
8319    pub tag: Option<Box<Expression>>,
8320}
8321
8322/// QueryBand
8323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8324#[cfg_attr(feature = "bindings", derive(TS))]
8325pub struct QueryBand {
8326    pub this: Box<Expression>,
8327    #[serde(default)]
8328    pub scope: Option<Box<Expression>>,
8329    #[serde(default)]
8330    pub update: Option<Box<Expression>>,
8331}
8332
8333/// UserDefinedFunction
8334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8335#[cfg_attr(feature = "bindings", derive(TS))]
8336pub struct UserDefinedFunction {
8337    pub this: Box<Expression>,
8338    #[serde(default)]
8339    pub expressions: Vec<Expression>,
8340    #[serde(default)]
8341    pub wrapped: Option<Box<Expression>>,
8342}
8343
8344/// RecursiveWithSearch
8345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8346#[cfg_attr(feature = "bindings", derive(TS))]
8347pub struct RecursiveWithSearch {
8348    pub kind: String,
8349    pub this: Box<Expression>,
8350    pub expression: Box<Expression>,
8351    #[serde(default)]
8352    pub using: Option<Box<Expression>>,
8353}
8354
8355/// ProjectionDef
8356#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8357#[cfg_attr(feature = "bindings", derive(TS))]
8358pub struct ProjectionDef {
8359    pub this: Box<Expression>,
8360    pub expression: Box<Expression>,
8361}
8362
8363/// TableAlias
8364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8365#[cfg_attr(feature = "bindings", derive(TS))]
8366pub struct TableAlias {
8367    #[serde(default)]
8368    pub this: Option<Box<Expression>>,
8369    #[serde(default)]
8370    pub columns: Vec<Expression>,
8371}
8372
8373/// ByteString
8374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8375#[cfg_attr(feature = "bindings", derive(TS))]
8376pub struct ByteString {
8377    pub this: Box<Expression>,
8378    #[serde(default)]
8379    pub is_bytes: Option<Box<Expression>>,
8380}
8381
8382/// HexStringExpr - Hex string expression (not literal)
8383/// BigQuery: converts to FROM_HEX(this)
8384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8385#[cfg_attr(feature = "bindings", derive(TS))]
8386pub struct HexStringExpr {
8387    pub this: Box<Expression>,
8388    #[serde(default)]
8389    pub is_integer: Option<bool>,
8390}
8391
8392/// UnicodeString
8393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8394#[cfg_attr(feature = "bindings", derive(TS))]
8395pub struct UnicodeString {
8396    pub this: Box<Expression>,
8397    #[serde(default)]
8398    pub escape: Option<Box<Expression>>,
8399}
8400
8401/// AlterColumn
8402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8403#[cfg_attr(feature = "bindings", derive(TS))]
8404pub struct AlterColumn {
8405    pub this: Box<Expression>,
8406    #[serde(default)]
8407    pub dtype: Option<Box<Expression>>,
8408    #[serde(default)]
8409    pub collate: Option<Box<Expression>>,
8410    #[serde(default)]
8411    pub using: Option<Box<Expression>>,
8412    #[serde(default)]
8413    pub default: Option<Box<Expression>>,
8414    #[serde(default)]
8415    pub drop: Option<Box<Expression>>,
8416    #[serde(default)]
8417    pub comment: Option<Box<Expression>>,
8418    #[serde(default)]
8419    pub allow_null: Option<Box<Expression>>,
8420    #[serde(default)]
8421    pub visible: Option<Box<Expression>>,
8422    #[serde(default)]
8423    pub rename_to: Option<Box<Expression>>,
8424}
8425
8426/// AlterSortKey
8427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8428#[cfg_attr(feature = "bindings", derive(TS))]
8429pub struct AlterSortKey {
8430    #[serde(default)]
8431    pub this: Option<Box<Expression>>,
8432    #[serde(default)]
8433    pub expressions: Vec<Expression>,
8434    #[serde(default)]
8435    pub compound: Option<Box<Expression>>,
8436}
8437
8438/// AlterSet
8439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8440#[cfg_attr(feature = "bindings", derive(TS))]
8441pub struct AlterSet {
8442    #[serde(default)]
8443    pub expressions: Vec<Expression>,
8444    #[serde(default)]
8445    pub option: Option<Box<Expression>>,
8446    #[serde(default)]
8447    pub tablespace: Option<Box<Expression>>,
8448    #[serde(default)]
8449    pub access_method: Option<Box<Expression>>,
8450    #[serde(default)]
8451    pub file_format: Option<Box<Expression>>,
8452    #[serde(default)]
8453    pub copy_options: Option<Box<Expression>>,
8454    #[serde(default)]
8455    pub tag: Option<Box<Expression>>,
8456    #[serde(default)]
8457    pub location: Option<Box<Expression>>,
8458    #[serde(default)]
8459    pub serde: Option<Box<Expression>>,
8460}
8461
8462/// RenameColumn
8463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8464#[cfg_attr(feature = "bindings", derive(TS))]
8465pub struct RenameColumn {
8466    pub this: Box<Expression>,
8467    #[serde(default)]
8468    pub to: Option<Box<Expression>>,
8469    #[serde(default)]
8470    pub exists: bool,
8471}
8472
8473/// Comprehension
8474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8475#[cfg_attr(feature = "bindings", derive(TS))]
8476pub struct Comprehension {
8477    pub this: Box<Expression>,
8478    pub expression: Box<Expression>,
8479    #[serde(default)]
8480    pub position: Option<Box<Expression>>,
8481    #[serde(default)]
8482    pub iterator: Option<Box<Expression>>,
8483    #[serde(default)]
8484    pub condition: Option<Box<Expression>>,
8485}
8486
8487/// MergeTreeTTLAction
8488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8489#[cfg_attr(feature = "bindings", derive(TS))]
8490pub struct MergeTreeTTLAction {
8491    pub this: Box<Expression>,
8492    #[serde(default)]
8493    pub delete: Option<Box<Expression>>,
8494    #[serde(default)]
8495    pub recompress: Option<Box<Expression>>,
8496    #[serde(default)]
8497    pub to_disk: Option<Box<Expression>>,
8498    #[serde(default)]
8499    pub to_volume: Option<Box<Expression>>,
8500}
8501
8502/// MergeTreeTTL
8503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8504#[cfg_attr(feature = "bindings", derive(TS))]
8505pub struct MergeTreeTTL {
8506    #[serde(default)]
8507    pub expressions: Vec<Expression>,
8508    #[serde(default)]
8509    pub where_: Option<Box<Expression>>,
8510    #[serde(default)]
8511    pub group: Option<Box<Expression>>,
8512    #[serde(default)]
8513    pub aggregates: Option<Box<Expression>>,
8514}
8515
8516/// IndexConstraintOption
8517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8518#[cfg_attr(feature = "bindings", derive(TS))]
8519pub struct IndexConstraintOption {
8520    #[serde(default)]
8521    pub key_block_size: Option<Box<Expression>>,
8522    #[serde(default)]
8523    pub using: Option<Box<Expression>>,
8524    #[serde(default)]
8525    pub parser: Option<Box<Expression>>,
8526    #[serde(default)]
8527    pub comment: Option<Box<Expression>>,
8528    #[serde(default)]
8529    pub visible: Option<Box<Expression>>,
8530    #[serde(default)]
8531    pub engine_attr: Option<Box<Expression>>,
8532    #[serde(default)]
8533    pub secondary_engine_attr: Option<Box<Expression>>,
8534}
8535
8536/// PeriodForSystemTimeConstraint
8537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8538#[cfg_attr(feature = "bindings", derive(TS))]
8539pub struct PeriodForSystemTimeConstraint {
8540    pub this: Box<Expression>,
8541    pub expression: Box<Expression>,
8542}
8543
8544/// CaseSpecificColumnConstraint
8545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8546#[cfg_attr(feature = "bindings", derive(TS))]
8547pub struct CaseSpecificColumnConstraint {
8548    #[serde(default)]
8549    pub not_: Option<Box<Expression>>,
8550}
8551
8552/// CharacterSetColumnConstraint
8553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8554#[cfg_attr(feature = "bindings", derive(TS))]
8555pub struct CharacterSetColumnConstraint {
8556    pub this: Box<Expression>,
8557}
8558
8559/// CheckColumnConstraint
8560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8561#[cfg_attr(feature = "bindings", derive(TS))]
8562pub struct CheckColumnConstraint {
8563    pub this: Box<Expression>,
8564    #[serde(default)]
8565    pub enforced: Option<Box<Expression>>,
8566}
8567
8568/// CompressColumnConstraint
8569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8570#[cfg_attr(feature = "bindings", derive(TS))]
8571pub struct CompressColumnConstraint {
8572    #[serde(default)]
8573    pub this: Option<Box<Expression>>,
8574}
8575
8576/// DateFormatColumnConstraint
8577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8578#[cfg_attr(feature = "bindings", derive(TS))]
8579pub struct DateFormatColumnConstraint {
8580    pub this: Box<Expression>,
8581}
8582
8583/// EphemeralColumnConstraint
8584#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8585#[cfg_attr(feature = "bindings", derive(TS))]
8586pub struct EphemeralColumnConstraint {
8587    #[serde(default)]
8588    pub this: Option<Box<Expression>>,
8589}
8590
8591/// WithOperator
8592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8593#[cfg_attr(feature = "bindings", derive(TS))]
8594pub struct WithOperator {
8595    pub this: Box<Expression>,
8596    pub op: String,
8597}
8598
8599/// GeneratedAsIdentityColumnConstraint
8600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8601#[cfg_attr(feature = "bindings", derive(TS))]
8602pub struct GeneratedAsIdentityColumnConstraint {
8603    #[serde(default)]
8604    pub this: Option<Box<Expression>>,
8605    #[serde(default)]
8606    pub expression: Option<Box<Expression>>,
8607    #[serde(default)]
8608    pub on_null: Option<Box<Expression>>,
8609    #[serde(default)]
8610    pub start: Option<Box<Expression>>,
8611    #[serde(default)]
8612    pub increment: Option<Box<Expression>>,
8613    #[serde(default)]
8614    pub minvalue: Option<Box<Expression>>,
8615    #[serde(default)]
8616    pub maxvalue: Option<Box<Expression>>,
8617    #[serde(default)]
8618    pub cycle: Option<Box<Expression>>,
8619    #[serde(default)]
8620    pub order: Option<Box<Expression>>,
8621}
8622
8623/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8624/// TSQL: outputs "IDENTITY"
8625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8626#[cfg_attr(feature = "bindings", derive(TS))]
8627pub struct AutoIncrementColumnConstraint;
8628
8629/// CommentColumnConstraint - Column comment marker
8630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8631#[cfg_attr(feature = "bindings", derive(TS))]
8632pub struct CommentColumnConstraint;
8633
8634/// GeneratedAsRowColumnConstraint
8635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8636#[cfg_attr(feature = "bindings", derive(TS))]
8637pub struct GeneratedAsRowColumnConstraint {
8638    #[serde(default)]
8639    pub start: Option<Box<Expression>>,
8640    #[serde(default)]
8641    pub hidden: Option<Box<Expression>>,
8642}
8643
8644/// IndexColumnConstraint
8645#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8646#[cfg_attr(feature = "bindings", derive(TS))]
8647pub struct IndexColumnConstraint {
8648    #[serde(default)]
8649    pub this: Option<Box<Expression>>,
8650    #[serde(default)]
8651    pub expressions: Vec<Expression>,
8652    #[serde(default)]
8653    pub kind: Option<String>,
8654    #[serde(default)]
8655    pub index_type: Option<Box<Expression>>,
8656    #[serde(default)]
8657    pub options: Vec<Expression>,
8658    #[serde(default)]
8659    pub expression: Option<Box<Expression>>,
8660    #[serde(default)]
8661    pub granularity: Option<Box<Expression>>,
8662}
8663
8664/// MaskingPolicyColumnConstraint
8665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8666#[cfg_attr(feature = "bindings", derive(TS))]
8667pub struct MaskingPolicyColumnConstraint {
8668    pub this: Box<Expression>,
8669    #[serde(default)]
8670    pub expressions: Vec<Expression>,
8671}
8672
8673/// NotNullColumnConstraint
8674#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8675#[cfg_attr(feature = "bindings", derive(TS))]
8676pub struct NotNullColumnConstraint {
8677    #[serde(default)]
8678    pub allow_null: Option<Box<Expression>>,
8679}
8680
8681/// DefaultColumnConstraint - DEFAULT value for a column
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct DefaultColumnConstraint {
8685    pub this: Box<Expression>,
8686}
8687
8688/// PrimaryKeyColumnConstraint
8689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8690#[cfg_attr(feature = "bindings", derive(TS))]
8691pub struct PrimaryKeyColumnConstraint {
8692    #[serde(default)]
8693    pub desc: Option<Box<Expression>>,
8694    #[serde(default)]
8695    pub options: Vec<Expression>,
8696}
8697
8698/// UniqueColumnConstraint
8699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8700#[cfg_attr(feature = "bindings", derive(TS))]
8701pub struct UniqueColumnConstraint {
8702    #[serde(default)]
8703    pub this: Option<Box<Expression>>,
8704    #[serde(default)]
8705    pub index_type: Option<Box<Expression>>,
8706    #[serde(default)]
8707    pub on_conflict: Option<Box<Expression>>,
8708    #[serde(default)]
8709    pub nulls: Option<Box<Expression>>,
8710    #[serde(default)]
8711    pub options: Vec<Expression>,
8712}
8713
8714/// WatermarkColumnConstraint
8715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8716#[cfg_attr(feature = "bindings", derive(TS))]
8717pub struct WatermarkColumnConstraint {
8718    pub this: Box<Expression>,
8719    pub expression: Box<Expression>,
8720}
8721
8722/// ComputedColumnConstraint
8723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8724#[cfg_attr(feature = "bindings", derive(TS))]
8725pub struct ComputedColumnConstraint {
8726    pub this: Box<Expression>,
8727    #[serde(default)]
8728    pub persisted: Option<Box<Expression>>,
8729    #[serde(default)]
8730    pub not_null: Option<Box<Expression>>,
8731    #[serde(default)]
8732    pub data_type: Option<Box<Expression>>,
8733}
8734
8735/// InOutColumnConstraint
8736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8737#[cfg_attr(feature = "bindings", derive(TS))]
8738pub struct InOutColumnConstraint {
8739    #[serde(default)]
8740    pub input_: Option<Box<Expression>>,
8741    #[serde(default)]
8742    pub output: Option<Box<Expression>>,
8743}
8744
8745/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8746#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8747#[cfg_attr(feature = "bindings", derive(TS))]
8748pub struct PathColumnConstraint {
8749    pub this: Box<Expression>,
8750}
8751
8752/// Constraint
8753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8754#[cfg_attr(feature = "bindings", derive(TS))]
8755pub struct Constraint {
8756    pub this: Box<Expression>,
8757    #[serde(default)]
8758    pub expressions: Vec<Expression>,
8759}
8760
8761/// Export
8762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8763#[cfg_attr(feature = "bindings", derive(TS))]
8764pub struct Export {
8765    pub this: Box<Expression>,
8766    #[serde(default)]
8767    pub connection: Option<Box<Expression>>,
8768    #[serde(default)]
8769    pub options: Vec<Expression>,
8770}
8771
8772/// Filter
8773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8774#[cfg_attr(feature = "bindings", derive(TS))]
8775pub struct Filter {
8776    pub this: Box<Expression>,
8777    pub expression: Box<Expression>,
8778}
8779
8780/// Changes
8781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8782#[cfg_attr(feature = "bindings", derive(TS))]
8783pub struct Changes {
8784    #[serde(default)]
8785    pub information: Option<Box<Expression>>,
8786    #[serde(default)]
8787    pub at_before: Option<Box<Expression>>,
8788    #[serde(default)]
8789    pub end: Option<Box<Expression>>,
8790}
8791
8792/// Directory
8793#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8794#[cfg_attr(feature = "bindings", derive(TS))]
8795pub struct Directory {
8796    pub this: Box<Expression>,
8797    #[serde(default)]
8798    pub local: Option<Box<Expression>>,
8799    #[serde(default)]
8800    pub row_format: Option<Box<Expression>>,
8801}
8802
8803/// ForeignKey
8804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8805#[cfg_attr(feature = "bindings", derive(TS))]
8806pub struct ForeignKey {
8807    #[serde(default)]
8808    pub expressions: Vec<Expression>,
8809    #[serde(default)]
8810    pub reference: Option<Box<Expression>>,
8811    #[serde(default)]
8812    pub delete: Option<Box<Expression>>,
8813    #[serde(default)]
8814    pub update: Option<Box<Expression>>,
8815    #[serde(default)]
8816    pub options: Vec<Expression>,
8817}
8818
8819/// ColumnPrefix
8820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8821#[cfg_attr(feature = "bindings", derive(TS))]
8822pub struct ColumnPrefix {
8823    pub this: Box<Expression>,
8824    pub expression: Box<Expression>,
8825}
8826
8827/// PrimaryKey
8828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8829#[cfg_attr(feature = "bindings", derive(TS))]
8830pub struct PrimaryKey {
8831    #[serde(default)]
8832    pub this: Option<Box<Expression>>,
8833    #[serde(default)]
8834    pub expressions: Vec<Expression>,
8835    #[serde(default)]
8836    pub options: Vec<Expression>,
8837    #[serde(default)]
8838    pub include: Option<Box<Expression>>,
8839}
8840
8841/// Into
8842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8843#[cfg_attr(feature = "bindings", derive(TS))]
8844pub struct IntoClause {
8845    #[serde(default)]
8846    pub this: Option<Box<Expression>>,
8847    #[serde(default)]
8848    pub temporary: bool,
8849    #[serde(default)]
8850    pub unlogged: Option<Box<Expression>>,
8851    #[serde(default)]
8852    pub bulk_collect: Option<Box<Expression>>,
8853    #[serde(default)]
8854    pub expressions: Vec<Expression>,
8855}
8856
8857/// JoinHint
8858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8859#[cfg_attr(feature = "bindings", derive(TS))]
8860pub struct JoinHint {
8861    pub this: Box<Expression>,
8862    #[serde(default)]
8863    pub expressions: Vec<Expression>,
8864}
8865
8866/// Opclass
8867#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8868#[cfg_attr(feature = "bindings", derive(TS))]
8869pub struct Opclass {
8870    pub this: Box<Expression>,
8871    pub expression: Box<Expression>,
8872}
8873
8874/// Index
8875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8876#[cfg_attr(feature = "bindings", derive(TS))]
8877pub struct Index {
8878    #[serde(default)]
8879    pub this: Option<Box<Expression>>,
8880    #[serde(default)]
8881    pub table: Option<Box<Expression>>,
8882    #[serde(default)]
8883    pub unique: bool,
8884    #[serde(default)]
8885    pub primary: Option<Box<Expression>>,
8886    #[serde(default)]
8887    pub amp: Option<Box<Expression>>,
8888    #[serde(default)]
8889    pub params: Vec<Expression>,
8890}
8891
8892/// IndexParameters
8893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8894#[cfg_attr(feature = "bindings", derive(TS))]
8895pub struct IndexParameters {
8896    #[serde(default)]
8897    pub using: Option<Box<Expression>>,
8898    #[serde(default)]
8899    pub include: Option<Box<Expression>>,
8900    #[serde(default)]
8901    pub columns: Vec<Expression>,
8902    #[serde(default)]
8903    pub with_storage: Option<Box<Expression>>,
8904    #[serde(default)]
8905    pub partition_by: Option<Box<Expression>>,
8906    #[serde(default)]
8907    pub tablespace: Option<Box<Expression>>,
8908    #[serde(default)]
8909    pub where_: Option<Box<Expression>>,
8910    #[serde(default)]
8911    pub on: Option<Box<Expression>>,
8912}
8913
8914/// ConditionalInsert
8915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8916#[cfg_attr(feature = "bindings", derive(TS))]
8917pub struct ConditionalInsert {
8918    pub this: Box<Expression>,
8919    #[serde(default)]
8920    pub expression: Option<Box<Expression>>,
8921    #[serde(default)]
8922    pub else_: Option<Box<Expression>>,
8923}
8924
8925/// MultitableInserts
8926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8927#[cfg_attr(feature = "bindings", derive(TS))]
8928pub struct MultitableInserts {
8929    #[serde(default)]
8930    pub expressions: Vec<Expression>,
8931    pub kind: String,
8932    #[serde(default)]
8933    pub source: Option<Box<Expression>>,
8934    /// Leading comments before the statement
8935    #[serde(default)]
8936    pub leading_comments: Vec<String>,
8937}
8938
8939/// OnConflict
8940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8941#[cfg_attr(feature = "bindings", derive(TS))]
8942pub struct OnConflict {
8943    #[serde(default)]
8944    pub duplicate: Option<Box<Expression>>,
8945    #[serde(default)]
8946    pub expressions: Vec<Expression>,
8947    #[serde(default)]
8948    pub action: Option<Box<Expression>>,
8949    #[serde(default)]
8950    pub conflict_keys: Option<Box<Expression>>,
8951    #[serde(default)]
8952    pub index_predicate: Option<Box<Expression>>,
8953    #[serde(default)]
8954    pub constraint: Option<Box<Expression>>,
8955    #[serde(default)]
8956    pub where_: Option<Box<Expression>>,
8957}
8958
8959/// OnCondition
8960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8961#[cfg_attr(feature = "bindings", derive(TS))]
8962pub struct OnCondition {
8963    #[serde(default)]
8964    pub error: Option<Box<Expression>>,
8965    #[serde(default)]
8966    pub empty: Option<Box<Expression>>,
8967    #[serde(default)]
8968    pub null: Option<Box<Expression>>,
8969}
8970
8971/// Returning
8972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8973#[cfg_attr(feature = "bindings", derive(TS))]
8974pub struct Returning {
8975    #[serde(default)]
8976    pub expressions: Vec<Expression>,
8977    #[serde(default)]
8978    pub into: Option<Box<Expression>>,
8979}
8980
8981/// Introducer
8982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8983#[cfg_attr(feature = "bindings", derive(TS))]
8984pub struct Introducer {
8985    pub this: Box<Expression>,
8986    pub expression: Box<Expression>,
8987}
8988
8989/// PartitionRange
8990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8991#[cfg_attr(feature = "bindings", derive(TS))]
8992pub struct PartitionRange {
8993    pub this: Box<Expression>,
8994    #[serde(default)]
8995    pub expression: Option<Box<Expression>>,
8996    #[serde(default)]
8997    pub expressions: Vec<Expression>,
8998}
8999
9000/// Group
9001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9002#[cfg_attr(feature = "bindings", derive(TS))]
9003pub struct Group {
9004    #[serde(default)]
9005    pub expressions: Vec<Expression>,
9006    #[serde(default)]
9007    pub grouping_sets: Option<Box<Expression>>,
9008    #[serde(default)]
9009    pub cube: Option<Box<Expression>>,
9010    #[serde(default)]
9011    pub rollup: Option<Box<Expression>>,
9012    #[serde(default)]
9013    pub totals: Option<Box<Expression>>,
9014    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
9015    #[serde(default)]
9016    pub all: Option<bool>,
9017}
9018
9019/// Cube
9020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9021#[cfg_attr(feature = "bindings", derive(TS))]
9022pub struct Cube {
9023    #[serde(default)]
9024    pub expressions: Vec<Expression>,
9025}
9026
9027/// Rollup
9028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9029#[cfg_attr(feature = "bindings", derive(TS))]
9030pub struct Rollup {
9031    #[serde(default)]
9032    pub expressions: Vec<Expression>,
9033}
9034
9035/// GroupingSets
9036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9037#[cfg_attr(feature = "bindings", derive(TS))]
9038pub struct GroupingSets {
9039    #[serde(default)]
9040    pub expressions: Vec<Expression>,
9041}
9042
9043/// LimitOptions
9044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9045#[cfg_attr(feature = "bindings", derive(TS))]
9046pub struct LimitOptions {
9047    #[serde(default)]
9048    pub percent: Option<Box<Expression>>,
9049    #[serde(default)]
9050    pub rows: Option<Box<Expression>>,
9051    #[serde(default)]
9052    pub with_ties: Option<Box<Expression>>,
9053}
9054
9055/// Lateral
9056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9057#[cfg_attr(feature = "bindings", derive(TS))]
9058pub struct Lateral {
9059    pub this: Box<Expression>,
9060    #[serde(default)]
9061    pub view: Option<Box<Expression>>,
9062    #[serde(default)]
9063    pub outer: Option<Box<Expression>>,
9064    #[serde(default)]
9065    pub alias: Option<String>,
9066    /// Whether the alias was originally quoted (backtick/double-quote)
9067    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
9068    pub alias_quoted: bool,
9069    #[serde(default)]
9070    pub cross_apply: Option<Box<Expression>>,
9071    #[serde(default)]
9072    pub ordinality: Option<Box<Expression>>,
9073    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
9074    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9075    pub column_aliases: Vec<String>,
9076}
9077
9078/// TableFromRows
9079#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9080#[cfg_attr(feature = "bindings", derive(TS))]
9081pub struct TableFromRows {
9082    pub this: Box<Expression>,
9083    #[serde(default)]
9084    pub alias: Option<String>,
9085    #[serde(default)]
9086    pub joins: Vec<Expression>,
9087    #[serde(default)]
9088    pub pivots: Option<Box<Expression>>,
9089    #[serde(default)]
9090    pub sample: Option<Box<Expression>>,
9091}
9092
9093/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
9094/// Used for set-returning functions with typed column definitions
9095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9096#[cfg_attr(feature = "bindings", derive(TS))]
9097pub struct RowsFrom {
9098    /// List of function expressions, each potentially with an alias and typed columns
9099    pub expressions: Vec<Expression>,
9100    /// WITH ORDINALITY modifier
9101    #[serde(default)]
9102    pub ordinality: bool,
9103    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
9104    #[serde(default)]
9105    pub alias: Option<Box<Expression>>,
9106}
9107
9108/// WithFill
9109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9110#[cfg_attr(feature = "bindings", derive(TS))]
9111pub struct WithFill {
9112    #[serde(default)]
9113    pub from_: Option<Box<Expression>>,
9114    #[serde(default)]
9115    pub to: Option<Box<Expression>>,
9116    #[serde(default)]
9117    pub step: Option<Box<Expression>>,
9118    #[serde(default)]
9119    pub staleness: Option<Box<Expression>>,
9120    #[serde(default)]
9121    pub interpolate: Option<Box<Expression>>,
9122}
9123
9124/// Property
9125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9126#[cfg_attr(feature = "bindings", derive(TS))]
9127pub struct Property {
9128    pub this: Box<Expression>,
9129    #[serde(default)]
9130    pub value: Option<Box<Expression>>,
9131}
9132
9133/// GrantPrivilege
9134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9135#[cfg_attr(feature = "bindings", derive(TS))]
9136pub struct GrantPrivilege {
9137    pub this: Box<Expression>,
9138    #[serde(default)]
9139    pub expressions: Vec<Expression>,
9140}
9141
9142/// AllowedValuesProperty
9143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9144#[cfg_attr(feature = "bindings", derive(TS))]
9145pub struct AllowedValuesProperty {
9146    #[serde(default)]
9147    pub expressions: Vec<Expression>,
9148}
9149
9150/// AlgorithmProperty
9151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9152#[cfg_attr(feature = "bindings", derive(TS))]
9153pub struct AlgorithmProperty {
9154    pub this: Box<Expression>,
9155}
9156
9157/// AutoIncrementProperty
9158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9159#[cfg_attr(feature = "bindings", derive(TS))]
9160pub struct AutoIncrementProperty {
9161    pub this: Box<Expression>,
9162}
9163
9164/// AutoRefreshProperty
9165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9166#[cfg_attr(feature = "bindings", derive(TS))]
9167pub struct AutoRefreshProperty {
9168    pub this: Box<Expression>,
9169}
9170
9171/// BackupProperty
9172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9173#[cfg_attr(feature = "bindings", derive(TS))]
9174pub struct BackupProperty {
9175    pub this: Box<Expression>,
9176}
9177
9178/// BuildProperty
9179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9180#[cfg_attr(feature = "bindings", derive(TS))]
9181pub struct BuildProperty {
9182    pub this: Box<Expression>,
9183}
9184
9185/// BlockCompressionProperty
9186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9187#[cfg_attr(feature = "bindings", derive(TS))]
9188pub struct BlockCompressionProperty {
9189    #[serde(default)]
9190    pub autotemp: Option<Box<Expression>>,
9191    #[serde(default)]
9192    pub always: Option<Box<Expression>>,
9193    #[serde(default)]
9194    pub default: Option<Box<Expression>>,
9195    #[serde(default)]
9196    pub manual: Option<Box<Expression>>,
9197    #[serde(default)]
9198    pub never: Option<Box<Expression>>,
9199}
9200
9201/// CharacterSetProperty
9202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9203#[cfg_attr(feature = "bindings", derive(TS))]
9204pub struct CharacterSetProperty {
9205    pub this: Box<Expression>,
9206    #[serde(default)]
9207    pub default: Option<Box<Expression>>,
9208}
9209
9210/// ChecksumProperty
9211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9212#[cfg_attr(feature = "bindings", derive(TS))]
9213pub struct ChecksumProperty {
9214    #[serde(default)]
9215    pub on: Option<Box<Expression>>,
9216    #[serde(default)]
9217    pub default: Option<Box<Expression>>,
9218}
9219
9220/// CollateProperty
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct CollateProperty {
9224    pub this: Box<Expression>,
9225    #[serde(default)]
9226    pub default: Option<Box<Expression>>,
9227}
9228
9229/// DataBlocksizeProperty
9230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9231#[cfg_attr(feature = "bindings", derive(TS))]
9232pub struct DataBlocksizeProperty {
9233    #[serde(default)]
9234    pub size: Option<i64>,
9235    #[serde(default)]
9236    pub units: Option<Box<Expression>>,
9237    #[serde(default)]
9238    pub minimum: Option<Box<Expression>>,
9239    #[serde(default)]
9240    pub maximum: Option<Box<Expression>>,
9241    #[serde(default)]
9242    pub default: Option<Box<Expression>>,
9243}
9244
9245/// DataDeletionProperty
9246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9247#[cfg_attr(feature = "bindings", derive(TS))]
9248pub struct DataDeletionProperty {
9249    pub on: Box<Expression>,
9250    #[serde(default)]
9251    pub filter_column: Option<Box<Expression>>,
9252    #[serde(default)]
9253    pub retention_period: Option<Box<Expression>>,
9254}
9255
9256/// DefinerProperty
9257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9258#[cfg_attr(feature = "bindings", derive(TS))]
9259pub struct DefinerProperty {
9260    pub this: Box<Expression>,
9261}
9262
9263/// DistKeyProperty
9264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9265#[cfg_attr(feature = "bindings", derive(TS))]
9266pub struct DistKeyProperty {
9267    pub this: Box<Expression>,
9268}
9269
9270/// DistributedByProperty
9271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9272#[cfg_attr(feature = "bindings", derive(TS))]
9273pub struct DistributedByProperty {
9274    #[serde(default)]
9275    pub expressions: Vec<Expression>,
9276    pub kind: String,
9277    #[serde(default)]
9278    pub buckets: Option<Box<Expression>>,
9279    #[serde(default)]
9280    pub order: Option<Box<Expression>>,
9281}
9282
9283/// DistStyleProperty
9284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9285#[cfg_attr(feature = "bindings", derive(TS))]
9286pub struct DistStyleProperty {
9287    pub this: Box<Expression>,
9288}
9289
9290/// DuplicateKeyProperty
9291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9292#[cfg_attr(feature = "bindings", derive(TS))]
9293pub struct DuplicateKeyProperty {
9294    #[serde(default)]
9295    pub expressions: Vec<Expression>,
9296}
9297
9298/// EngineProperty
9299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9300#[cfg_attr(feature = "bindings", derive(TS))]
9301pub struct EngineProperty {
9302    pub this: Box<Expression>,
9303}
9304
9305/// ToTableProperty
9306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9307#[cfg_attr(feature = "bindings", derive(TS))]
9308pub struct ToTableProperty {
9309    pub this: Box<Expression>,
9310}
9311
9312/// ExecuteAsProperty
9313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9314#[cfg_attr(feature = "bindings", derive(TS))]
9315pub struct ExecuteAsProperty {
9316    pub this: Box<Expression>,
9317}
9318
9319/// ExternalProperty
9320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9321#[cfg_attr(feature = "bindings", derive(TS))]
9322pub struct ExternalProperty {
9323    #[serde(default)]
9324    pub this: Option<Box<Expression>>,
9325}
9326
9327/// FallbackProperty
9328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9329#[cfg_attr(feature = "bindings", derive(TS))]
9330pub struct FallbackProperty {
9331    #[serde(default)]
9332    pub no: Option<Box<Expression>>,
9333    #[serde(default)]
9334    pub protection: Option<Box<Expression>>,
9335}
9336
9337/// FileFormatProperty
9338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9339#[cfg_attr(feature = "bindings", derive(TS))]
9340pub struct FileFormatProperty {
9341    #[serde(default)]
9342    pub this: Option<Box<Expression>>,
9343    #[serde(default)]
9344    pub expressions: Vec<Expression>,
9345    #[serde(default)]
9346    pub hive_format: Option<Box<Expression>>,
9347}
9348
9349/// CredentialsProperty
9350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9351#[cfg_attr(feature = "bindings", derive(TS))]
9352pub struct CredentialsProperty {
9353    #[serde(default)]
9354    pub expressions: Vec<Expression>,
9355}
9356
9357/// FreespaceProperty
9358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9359#[cfg_attr(feature = "bindings", derive(TS))]
9360pub struct FreespaceProperty {
9361    pub this: Box<Expression>,
9362    #[serde(default)]
9363    pub percent: Option<Box<Expression>>,
9364}
9365
9366/// InheritsProperty
9367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9368#[cfg_attr(feature = "bindings", derive(TS))]
9369pub struct InheritsProperty {
9370    #[serde(default)]
9371    pub expressions: Vec<Expression>,
9372}
9373
9374/// InputModelProperty
9375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9376#[cfg_attr(feature = "bindings", derive(TS))]
9377pub struct InputModelProperty {
9378    pub this: Box<Expression>,
9379}
9380
9381/// OutputModelProperty
9382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9383#[cfg_attr(feature = "bindings", derive(TS))]
9384pub struct OutputModelProperty {
9385    pub this: Box<Expression>,
9386}
9387
9388/// IsolatedLoadingProperty
9389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9390#[cfg_attr(feature = "bindings", derive(TS))]
9391pub struct IsolatedLoadingProperty {
9392    #[serde(default)]
9393    pub no: Option<Box<Expression>>,
9394    #[serde(default)]
9395    pub concurrent: Option<Box<Expression>>,
9396    #[serde(default)]
9397    pub target: Option<Box<Expression>>,
9398}
9399
9400/// JournalProperty
9401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9402#[cfg_attr(feature = "bindings", derive(TS))]
9403pub struct JournalProperty {
9404    #[serde(default)]
9405    pub no: Option<Box<Expression>>,
9406    #[serde(default)]
9407    pub dual: Option<Box<Expression>>,
9408    #[serde(default)]
9409    pub before: Option<Box<Expression>>,
9410    #[serde(default)]
9411    pub local: Option<Box<Expression>>,
9412    #[serde(default)]
9413    pub after: Option<Box<Expression>>,
9414}
9415
9416/// LanguageProperty
9417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9418#[cfg_attr(feature = "bindings", derive(TS))]
9419pub struct LanguageProperty {
9420    pub this: Box<Expression>,
9421}
9422
9423/// EnviromentProperty
9424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9425#[cfg_attr(feature = "bindings", derive(TS))]
9426pub struct EnviromentProperty {
9427    #[serde(default)]
9428    pub expressions: Vec<Expression>,
9429}
9430
9431/// ClusteredByProperty
9432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub struct ClusteredByProperty {
9435    #[serde(default)]
9436    pub expressions: Vec<Expression>,
9437    #[serde(default)]
9438    pub sorted_by: Option<Box<Expression>>,
9439    #[serde(default)]
9440    pub buckets: Option<Box<Expression>>,
9441}
9442
9443/// DictProperty
9444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9445#[cfg_attr(feature = "bindings", derive(TS))]
9446pub struct DictProperty {
9447    pub this: Box<Expression>,
9448    pub kind: String,
9449    #[serde(default)]
9450    pub settings: Option<Box<Expression>>,
9451}
9452
9453/// DictRange
9454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9455#[cfg_attr(feature = "bindings", derive(TS))]
9456pub struct DictRange {
9457    pub this: Box<Expression>,
9458    #[serde(default)]
9459    pub min: Option<Box<Expression>>,
9460    #[serde(default)]
9461    pub max: Option<Box<Expression>>,
9462}
9463
9464/// OnCluster
9465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9466#[cfg_attr(feature = "bindings", derive(TS))]
9467pub struct OnCluster {
9468    pub this: Box<Expression>,
9469}
9470
9471/// LikeProperty
9472#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9473#[cfg_attr(feature = "bindings", derive(TS))]
9474pub struct LikeProperty {
9475    pub this: Box<Expression>,
9476    #[serde(default)]
9477    pub expressions: Vec<Expression>,
9478}
9479
9480/// LocationProperty
9481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9482#[cfg_attr(feature = "bindings", derive(TS))]
9483pub struct LocationProperty {
9484    pub this: Box<Expression>,
9485}
9486
9487/// LockProperty
9488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9489#[cfg_attr(feature = "bindings", derive(TS))]
9490pub struct LockProperty {
9491    pub this: Box<Expression>,
9492}
9493
9494/// LockingProperty
9495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9496#[cfg_attr(feature = "bindings", derive(TS))]
9497pub struct LockingProperty {
9498    #[serde(default)]
9499    pub this: Option<Box<Expression>>,
9500    pub kind: String,
9501    #[serde(default)]
9502    pub for_or_in: Option<Box<Expression>>,
9503    #[serde(default)]
9504    pub lock_type: Option<Box<Expression>>,
9505    #[serde(default)]
9506    pub override_: Option<Box<Expression>>,
9507}
9508
9509/// LogProperty
9510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9511#[cfg_attr(feature = "bindings", derive(TS))]
9512pub struct LogProperty {
9513    #[serde(default)]
9514    pub no: Option<Box<Expression>>,
9515}
9516
9517/// MaterializedProperty
9518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9519#[cfg_attr(feature = "bindings", derive(TS))]
9520pub struct MaterializedProperty {
9521    #[serde(default)]
9522    pub this: Option<Box<Expression>>,
9523}
9524
9525/// MergeBlockRatioProperty
9526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9527#[cfg_attr(feature = "bindings", derive(TS))]
9528pub struct MergeBlockRatioProperty {
9529    #[serde(default)]
9530    pub this: Option<Box<Expression>>,
9531    #[serde(default)]
9532    pub no: Option<Box<Expression>>,
9533    #[serde(default)]
9534    pub default: Option<Box<Expression>>,
9535    #[serde(default)]
9536    pub percent: Option<Box<Expression>>,
9537}
9538
9539/// OnProperty
9540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9541#[cfg_attr(feature = "bindings", derive(TS))]
9542pub struct OnProperty {
9543    pub this: Box<Expression>,
9544}
9545
9546/// OnCommitProperty
9547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9548#[cfg_attr(feature = "bindings", derive(TS))]
9549pub struct OnCommitProperty {
9550    #[serde(default)]
9551    pub delete: Option<Box<Expression>>,
9552}
9553
9554/// PartitionedByProperty
9555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9556#[cfg_attr(feature = "bindings", derive(TS))]
9557pub struct PartitionedByProperty {
9558    pub this: Box<Expression>,
9559}
9560
9561/// BigQuery PARTITION BY property in CREATE TABLE statements.
9562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9563#[cfg_attr(feature = "bindings", derive(TS))]
9564pub struct PartitionByProperty {
9565    #[serde(default)]
9566    pub expressions: Vec<Expression>,
9567}
9568
9569/// PartitionedByBucket
9570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9571#[cfg_attr(feature = "bindings", derive(TS))]
9572pub struct PartitionedByBucket {
9573    pub this: Box<Expression>,
9574    pub expression: Box<Expression>,
9575}
9576
9577/// BigQuery CLUSTER BY property in CREATE TABLE statements.
9578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9579#[cfg_attr(feature = "bindings", derive(TS))]
9580pub struct ClusterByColumnsProperty {
9581    #[serde(default)]
9582    pub columns: Vec<Identifier>,
9583}
9584
9585/// PartitionByTruncate
9586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9587#[cfg_attr(feature = "bindings", derive(TS))]
9588pub struct PartitionByTruncate {
9589    pub this: Box<Expression>,
9590    pub expression: Box<Expression>,
9591}
9592
9593/// PartitionByRangeProperty
9594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9595#[cfg_attr(feature = "bindings", derive(TS))]
9596pub struct PartitionByRangeProperty {
9597    #[serde(default)]
9598    pub partition_expressions: Option<Box<Expression>>,
9599    #[serde(default)]
9600    pub create_expressions: Option<Box<Expression>>,
9601}
9602
9603/// PartitionByRangePropertyDynamic
9604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9605#[cfg_attr(feature = "bindings", derive(TS))]
9606pub struct PartitionByRangePropertyDynamic {
9607    #[serde(default)]
9608    pub this: Option<Box<Expression>>,
9609    #[serde(default)]
9610    pub start: Option<Box<Expression>>,
9611    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9612    #[serde(default)]
9613    pub use_start_end: bool,
9614    #[serde(default)]
9615    pub end: Option<Box<Expression>>,
9616    #[serde(default)]
9617    pub every: Option<Box<Expression>>,
9618}
9619
9620/// PartitionByListProperty
9621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9622#[cfg_attr(feature = "bindings", derive(TS))]
9623pub struct PartitionByListProperty {
9624    #[serde(default)]
9625    pub partition_expressions: Option<Box<Expression>>,
9626    #[serde(default)]
9627    pub create_expressions: Option<Box<Expression>>,
9628}
9629
9630/// PartitionList
9631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9632#[cfg_attr(feature = "bindings", derive(TS))]
9633pub struct PartitionList {
9634    pub this: Box<Expression>,
9635    #[serde(default)]
9636    pub expressions: Vec<Expression>,
9637}
9638
9639/// Partition - represents PARTITION/SUBPARTITION clause
9640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9641#[cfg_attr(feature = "bindings", derive(TS))]
9642pub struct Partition {
9643    pub expressions: Vec<Expression>,
9644    #[serde(default)]
9645    pub subpartition: bool,
9646}
9647
9648/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9649/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9651#[cfg_attr(feature = "bindings", derive(TS))]
9652pub struct RefreshTriggerProperty {
9653    /// Method: COMPLETE or AUTO
9654    pub method: String,
9655    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9656    #[serde(default)]
9657    pub kind: Option<String>,
9658    /// For SCHEDULE: EVERY n (the number)
9659    #[serde(default)]
9660    pub every: Option<Box<Expression>>,
9661    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9662    #[serde(default)]
9663    pub unit: Option<String>,
9664    /// For SCHEDULE: STARTS 'datetime'
9665    #[serde(default)]
9666    pub starts: Option<Box<Expression>>,
9667}
9668
9669/// UniqueKeyProperty
9670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9671#[cfg_attr(feature = "bindings", derive(TS))]
9672pub struct UniqueKeyProperty {
9673    #[serde(default)]
9674    pub expressions: Vec<Expression>,
9675}
9676
9677/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9679#[cfg_attr(feature = "bindings", derive(TS))]
9680pub struct RollupProperty {
9681    pub expressions: Vec<RollupIndex>,
9682}
9683
9684/// RollupIndex - A single rollup index: name(col1, col2)
9685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9686#[cfg_attr(feature = "bindings", derive(TS))]
9687pub struct RollupIndex {
9688    pub name: Identifier,
9689    pub expressions: Vec<Identifier>,
9690}
9691
9692/// PartitionBoundSpec
9693#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9694#[cfg_attr(feature = "bindings", derive(TS))]
9695pub struct PartitionBoundSpec {
9696    #[serde(default)]
9697    pub this: Option<Box<Expression>>,
9698    #[serde(default)]
9699    pub expression: Option<Box<Expression>>,
9700    #[serde(default)]
9701    pub from_expressions: Option<Box<Expression>>,
9702    #[serde(default)]
9703    pub to_expressions: Option<Box<Expression>>,
9704}
9705
9706/// PartitionedOfProperty
9707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9708#[cfg_attr(feature = "bindings", derive(TS))]
9709pub struct PartitionedOfProperty {
9710    pub this: Box<Expression>,
9711    pub expression: Box<Expression>,
9712}
9713
9714/// RemoteWithConnectionModelProperty
9715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9716#[cfg_attr(feature = "bindings", derive(TS))]
9717pub struct RemoteWithConnectionModelProperty {
9718    pub this: Box<Expression>,
9719}
9720
9721/// ReturnsProperty
9722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9723#[cfg_attr(feature = "bindings", derive(TS))]
9724pub struct ReturnsProperty {
9725    #[serde(default)]
9726    pub this: Option<Box<Expression>>,
9727    #[serde(default)]
9728    pub is_table: Option<Box<Expression>>,
9729    #[serde(default)]
9730    pub table: Option<Box<Expression>>,
9731    #[serde(default)]
9732    pub null: Option<Box<Expression>>,
9733}
9734
9735/// RowFormatProperty
9736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9737#[cfg_attr(feature = "bindings", derive(TS))]
9738pub struct RowFormatProperty {
9739    pub this: Box<Expression>,
9740}
9741
9742/// RowFormatDelimitedProperty
9743#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9744#[cfg_attr(feature = "bindings", derive(TS))]
9745pub struct RowFormatDelimitedProperty {
9746    #[serde(default)]
9747    pub fields: Option<Box<Expression>>,
9748    #[serde(default)]
9749    pub escaped: Option<Box<Expression>>,
9750    #[serde(default)]
9751    pub collection_items: Option<Box<Expression>>,
9752    #[serde(default)]
9753    pub map_keys: Option<Box<Expression>>,
9754    #[serde(default)]
9755    pub lines: Option<Box<Expression>>,
9756    #[serde(default)]
9757    pub null: Option<Box<Expression>>,
9758    #[serde(default)]
9759    pub serde: Option<Box<Expression>>,
9760}
9761
9762/// RowFormatSerdeProperty
9763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9764#[cfg_attr(feature = "bindings", derive(TS))]
9765pub struct RowFormatSerdeProperty {
9766    pub this: Box<Expression>,
9767    #[serde(default)]
9768    pub serde_properties: Option<Box<Expression>>,
9769}
9770
9771/// QueryTransform
9772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9773#[cfg_attr(feature = "bindings", derive(TS))]
9774pub struct QueryTransform {
9775    #[serde(default)]
9776    pub expressions: Vec<Expression>,
9777    #[serde(default)]
9778    pub command_script: Option<Box<Expression>>,
9779    #[serde(default)]
9780    pub schema: Option<Box<Expression>>,
9781    #[serde(default)]
9782    pub row_format_before: Option<Box<Expression>>,
9783    #[serde(default)]
9784    pub record_writer: Option<Box<Expression>>,
9785    #[serde(default)]
9786    pub row_format_after: Option<Box<Expression>>,
9787    #[serde(default)]
9788    pub record_reader: Option<Box<Expression>>,
9789}
9790
9791/// SampleProperty
9792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9793#[cfg_attr(feature = "bindings", derive(TS))]
9794pub struct SampleProperty {
9795    pub this: Box<Expression>,
9796}
9797
9798/// SecurityProperty
9799#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9800#[cfg_attr(feature = "bindings", derive(TS))]
9801pub struct SecurityProperty {
9802    pub this: Box<Expression>,
9803}
9804
9805/// SchemaCommentProperty
9806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9807#[cfg_attr(feature = "bindings", derive(TS))]
9808pub struct SchemaCommentProperty {
9809    pub this: Box<Expression>,
9810}
9811
9812/// SemanticView
9813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9814#[cfg_attr(feature = "bindings", derive(TS))]
9815pub struct SemanticView {
9816    pub this: Box<Expression>,
9817    #[serde(default)]
9818    pub metrics: Option<Box<Expression>>,
9819    #[serde(default)]
9820    pub dimensions: Option<Box<Expression>>,
9821    #[serde(default)]
9822    pub facts: Option<Box<Expression>>,
9823    #[serde(default)]
9824    pub where_: Option<Box<Expression>>,
9825}
9826
9827/// SerdeProperties
9828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9829#[cfg_attr(feature = "bindings", derive(TS))]
9830pub struct SerdeProperties {
9831    #[serde(default)]
9832    pub expressions: Vec<Expression>,
9833    #[serde(default)]
9834    pub with_: Option<Box<Expression>>,
9835}
9836
9837/// SetProperty
9838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9839#[cfg_attr(feature = "bindings", derive(TS))]
9840pub struct SetProperty {
9841    #[serde(default)]
9842    pub multi: Option<Box<Expression>>,
9843}
9844
9845/// SharingProperty
9846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9847#[cfg_attr(feature = "bindings", derive(TS))]
9848pub struct SharingProperty {
9849    #[serde(default)]
9850    pub this: Option<Box<Expression>>,
9851}
9852
9853/// SetConfigProperty
9854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9855#[cfg_attr(feature = "bindings", derive(TS))]
9856pub struct SetConfigProperty {
9857    pub this: Box<Expression>,
9858}
9859
9860/// SettingsProperty
9861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9862#[cfg_attr(feature = "bindings", derive(TS))]
9863pub struct SettingsProperty {
9864    #[serde(default)]
9865    pub expressions: Vec<Expression>,
9866}
9867
9868/// SortKeyProperty
9869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9870#[cfg_attr(feature = "bindings", derive(TS))]
9871pub struct SortKeyProperty {
9872    pub this: Box<Expression>,
9873    #[serde(default)]
9874    pub compound: Option<Box<Expression>>,
9875}
9876
9877/// SqlReadWriteProperty
9878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9879#[cfg_attr(feature = "bindings", derive(TS))]
9880pub struct SqlReadWriteProperty {
9881    pub this: Box<Expression>,
9882}
9883
9884/// SqlSecurityProperty
9885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9886#[cfg_attr(feature = "bindings", derive(TS))]
9887pub struct SqlSecurityProperty {
9888    pub this: Box<Expression>,
9889}
9890
9891/// StabilityProperty
9892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9893#[cfg_attr(feature = "bindings", derive(TS))]
9894pub struct StabilityProperty {
9895    pub this: Box<Expression>,
9896}
9897
9898/// StorageHandlerProperty
9899#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9900#[cfg_attr(feature = "bindings", derive(TS))]
9901pub struct StorageHandlerProperty {
9902    pub this: Box<Expression>,
9903}
9904
9905/// TemporaryProperty
9906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9907#[cfg_attr(feature = "bindings", derive(TS))]
9908pub struct TemporaryProperty {
9909    #[serde(default)]
9910    pub this: Option<Box<Expression>>,
9911}
9912
9913/// Tags
9914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9915#[cfg_attr(feature = "bindings", derive(TS))]
9916pub struct Tags {
9917    #[serde(default)]
9918    pub expressions: Vec<Expression>,
9919}
9920
9921/// TransformModelProperty
9922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9923#[cfg_attr(feature = "bindings", derive(TS))]
9924pub struct TransformModelProperty {
9925    #[serde(default)]
9926    pub expressions: Vec<Expression>,
9927}
9928
9929/// TransientProperty
9930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9931#[cfg_attr(feature = "bindings", derive(TS))]
9932pub struct TransientProperty {
9933    #[serde(default)]
9934    pub this: Option<Box<Expression>>,
9935}
9936
9937/// UsingTemplateProperty
9938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9939#[cfg_attr(feature = "bindings", derive(TS))]
9940pub struct UsingTemplateProperty {
9941    pub this: Box<Expression>,
9942}
9943
9944/// ViewAttributeProperty
9945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9946#[cfg_attr(feature = "bindings", derive(TS))]
9947pub struct ViewAttributeProperty {
9948    pub this: Box<Expression>,
9949}
9950
9951/// VolatileProperty
9952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9953#[cfg_attr(feature = "bindings", derive(TS))]
9954pub struct VolatileProperty {
9955    #[serde(default)]
9956    pub this: Option<Box<Expression>>,
9957}
9958
9959/// WithDataProperty
9960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9961#[cfg_attr(feature = "bindings", derive(TS))]
9962pub struct WithDataProperty {
9963    #[serde(default)]
9964    pub no: Option<Box<Expression>>,
9965    #[serde(default)]
9966    pub statistics: Option<Box<Expression>>,
9967}
9968
9969/// WithJournalTableProperty
9970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9971#[cfg_attr(feature = "bindings", derive(TS))]
9972pub struct WithJournalTableProperty {
9973    pub this: Box<Expression>,
9974}
9975
9976/// WithSchemaBindingProperty
9977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9978#[cfg_attr(feature = "bindings", derive(TS))]
9979pub struct WithSchemaBindingProperty {
9980    pub this: Box<Expression>,
9981}
9982
9983/// WithSystemVersioningProperty
9984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9985#[cfg_attr(feature = "bindings", derive(TS))]
9986pub struct WithSystemVersioningProperty {
9987    #[serde(default)]
9988    pub on: Option<Box<Expression>>,
9989    #[serde(default)]
9990    pub this: Option<Box<Expression>>,
9991    #[serde(default)]
9992    pub data_consistency: Option<Box<Expression>>,
9993    #[serde(default)]
9994    pub retention_period: Option<Box<Expression>>,
9995    #[serde(default)]
9996    pub with_: Option<Box<Expression>>,
9997}
9998
9999/// WithProcedureOptions
10000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10001#[cfg_attr(feature = "bindings", derive(TS))]
10002pub struct WithProcedureOptions {
10003    #[serde(default)]
10004    pub expressions: Vec<Expression>,
10005}
10006
10007/// EncodeProperty
10008#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10009#[cfg_attr(feature = "bindings", derive(TS))]
10010pub struct EncodeProperty {
10011    pub this: Box<Expression>,
10012    #[serde(default)]
10013    pub properties: Vec<Expression>,
10014    #[serde(default)]
10015    pub key: Option<Box<Expression>>,
10016}
10017
10018/// IncludeProperty
10019#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10020#[cfg_attr(feature = "bindings", derive(TS))]
10021pub struct IncludeProperty {
10022    pub this: Box<Expression>,
10023    #[serde(default)]
10024    pub alias: Option<String>,
10025    #[serde(default)]
10026    pub column_def: Option<Box<Expression>>,
10027}
10028
10029/// Properties
10030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10031#[cfg_attr(feature = "bindings", derive(TS))]
10032pub struct Properties {
10033    #[serde(default)]
10034    pub expressions: Vec<Expression>,
10035}
10036
10037/// Key/value pair in a BigQuery OPTIONS (...) clause.
10038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10039#[cfg_attr(feature = "bindings", derive(TS))]
10040pub struct OptionEntry {
10041    pub key: Identifier,
10042    pub value: Expression,
10043}
10044
10045/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
10046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10047#[cfg_attr(feature = "bindings", derive(TS))]
10048pub struct OptionsProperty {
10049    #[serde(default)]
10050    pub entries: Vec<OptionEntry>,
10051}
10052
10053/// InputOutputFormat
10054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10055#[cfg_attr(feature = "bindings", derive(TS))]
10056pub struct InputOutputFormat {
10057    #[serde(default)]
10058    pub input_format: Option<Box<Expression>>,
10059    #[serde(default)]
10060    pub output_format: Option<Box<Expression>>,
10061}
10062
10063/// Reference
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct Reference {
10067    pub this: Box<Expression>,
10068    #[serde(default)]
10069    pub expressions: Vec<Expression>,
10070    #[serde(default)]
10071    pub options: Vec<Expression>,
10072}
10073
10074/// QueryOption
10075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10076#[cfg_attr(feature = "bindings", derive(TS))]
10077pub struct QueryOption {
10078    pub this: Box<Expression>,
10079    #[serde(default)]
10080    pub expression: Option<Box<Expression>>,
10081}
10082
10083/// WithTableHint
10084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10085#[cfg_attr(feature = "bindings", derive(TS))]
10086pub struct WithTableHint {
10087    #[serde(default)]
10088    pub expressions: Vec<Expression>,
10089}
10090
10091/// IndexTableHint
10092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10093#[cfg_attr(feature = "bindings", derive(TS))]
10094pub struct IndexTableHint {
10095    pub this: Box<Expression>,
10096    #[serde(default)]
10097    pub expressions: Vec<Expression>,
10098    #[serde(default)]
10099    pub target: Option<Box<Expression>>,
10100}
10101
10102/// Get
10103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10104#[cfg_attr(feature = "bindings", derive(TS))]
10105pub struct Get {
10106    pub this: Box<Expression>,
10107    #[serde(default)]
10108    pub target: Option<Box<Expression>>,
10109    #[serde(default)]
10110    pub properties: Vec<Expression>,
10111}
10112
10113/// SetOperation
10114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10115#[cfg_attr(feature = "bindings", derive(TS))]
10116pub struct SetOperation {
10117    #[serde(default)]
10118    pub with_: Option<Box<Expression>>,
10119    pub this: Box<Expression>,
10120    pub expression: Box<Expression>,
10121    #[serde(default)]
10122    pub distinct: bool,
10123    #[serde(default)]
10124    pub by_name: Option<Box<Expression>>,
10125    #[serde(default)]
10126    pub side: Option<Box<Expression>>,
10127    #[serde(default)]
10128    pub kind: Option<String>,
10129    #[serde(default)]
10130    pub on: Option<Box<Expression>>,
10131}
10132
10133/// Var - Simple variable reference (for SQL variables, keywords as values)
10134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10135#[cfg_attr(feature = "bindings", derive(TS))]
10136pub struct Var {
10137    pub this: String,
10138}
10139
10140/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
10141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10142#[cfg_attr(feature = "bindings", derive(TS))]
10143pub struct Variadic {
10144    pub this: Box<Expression>,
10145}
10146
10147/// Version
10148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10149#[cfg_attr(feature = "bindings", derive(TS))]
10150pub struct Version {
10151    pub this: Box<Expression>,
10152    pub kind: String,
10153    #[serde(default)]
10154    pub expression: Option<Box<Expression>>,
10155}
10156
10157/// Schema
10158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10159#[cfg_attr(feature = "bindings", derive(TS))]
10160pub struct Schema {
10161    #[serde(default)]
10162    pub this: Option<Box<Expression>>,
10163    #[serde(default)]
10164    pub expressions: Vec<Expression>,
10165}
10166
10167/// Lock
10168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10169#[cfg_attr(feature = "bindings", derive(TS))]
10170pub struct Lock {
10171    #[serde(default)]
10172    pub update: Option<Box<Expression>>,
10173    #[serde(default)]
10174    pub expressions: Vec<Expression>,
10175    #[serde(default)]
10176    pub wait: Option<Box<Expression>>,
10177    #[serde(default)]
10178    pub key: Option<Box<Expression>>,
10179}
10180
10181/// TableSample - wraps an expression with a TABLESAMPLE clause
10182/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
10183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10184#[cfg_attr(feature = "bindings", derive(TS))]
10185pub struct TableSample {
10186    /// The expression being sampled (subquery, function, etc.)
10187    #[serde(default, skip_serializing_if = "Option::is_none")]
10188    pub this: Option<Box<Expression>>,
10189    /// The sample specification
10190    #[serde(default, skip_serializing_if = "Option::is_none")]
10191    pub sample: Option<Box<Sample>>,
10192    #[serde(default)]
10193    pub expressions: Vec<Expression>,
10194    #[serde(default)]
10195    pub method: Option<String>,
10196    #[serde(default)]
10197    pub bucket_numerator: Option<Box<Expression>>,
10198    #[serde(default)]
10199    pub bucket_denominator: Option<Box<Expression>>,
10200    #[serde(default)]
10201    pub bucket_field: Option<Box<Expression>>,
10202    #[serde(default)]
10203    pub percent: Option<Box<Expression>>,
10204    #[serde(default)]
10205    pub rows: Option<Box<Expression>>,
10206    #[serde(default)]
10207    pub size: Option<i64>,
10208    #[serde(default)]
10209    pub seed: Option<Box<Expression>>,
10210}
10211
10212/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
10213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10214#[cfg_attr(feature = "bindings", derive(TS))]
10215pub struct Tag {
10216    #[serde(default)]
10217    pub this: Option<Box<Expression>>,
10218    #[serde(default)]
10219    pub prefix: Option<Box<Expression>>,
10220    #[serde(default)]
10221    pub postfix: Option<Box<Expression>>,
10222}
10223
10224/// UnpivotColumns
10225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10226#[cfg_attr(feature = "bindings", derive(TS))]
10227pub struct UnpivotColumns {
10228    pub this: Box<Expression>,
10229    #[serde(default)]
10230    pub expressions: Vec<Expression>,
10231}
10232
10233/// SessionParameter
10234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10235#[cfg_attr(feature = "bindings", derive(TS))]
10236pub struct SessionParameter {
10237    pub this: Box<Expression>,
10238    #[serde(default)]
10239    pub kind: Option<String>,
10240}
10241
10242/// PseudoType
10243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10244#[cfg_attr(feature = "bindings", derive(TS))]
10245pub struct PseudoType {
10246    pub this: Box<Expression>,
10247}
10248
10249/// ObjectIdentifier
10250#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10251#[cfg_attr(feature = "bindings", derive(TS))]
10252pub struct ObjectIdentifier {
10253    pub this: Box<Expression>,
10254}
10255
10256/// Transaction
10257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10258#[cfg_attr(feature = "bindings", derive(TS))]
10259pub struct Transaction {
10260    #[serde(default)]
10261    pub this: Option<Box<Expression>>,
10262    #[serde(default)]
10263    pub modes: Option<Box<Expression>>,
10264    #[serde(default)]
10265    pub mark: Option<Box<Expression>>,
10266}
10267
10268/// Commit
10269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10270#[cfg_attr(feature = "bindings", derive(TS))]
10271pub struct Commit {
10272    #[serde(default)]
10273    pub chain: Option<Box<Expression>>,
10274    #[serde(default)]
10275    pub this: Option<Box<Expression>>,
10276    #[serde(default)]
10277    pub durability: Option<Box<Expression>>,
10278}
10279
10280/// Rollback
10281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10282#[cfg_attr(feature = "bindings", derive(TS))]
10283pub struct Rollback {
10284    #[serde(default)]
10285    pub savepoint: Option<Box<Expression>>,
10286    #[serde(default)]
10287    pub this: Option<Box<Expression>>,
10288}
10289
10290/// AlterSession
10291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10292#[cfg_attr(feature = "bindings", derive(TS))]
10293pub struct AlterSession {
10294    #[serde(default)]
10295    pub expressions: Vec<Expression>,
10296    #[serde(default)]
10297    pub unset: Option<Box<Expression>>,
10298}
10299
10300/// Analyze
10301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10302#[cfg_attr(feature = "bindings", derive(TS))]
10303pub struct Analyze {
10304    #[serde(default)]
10305    pub kind: Option<String>,
10306    #[serde(default)]
10307    pub this: Option<Box<Expression>>,
10308    #[serde(default)]
10309    pub options: Vec<Expression>,
10310    #[serde(default)]
10311    pub mode: Option<Box<Expression>>,
10312    #[serde(default)]
10313    pub partition: Option<Box<Expression>>,
10314    #[serde(default)]
10315    pub expression: Option<Box<Expression>>,
10316    #[serde(default)]
10317    pub properties: Vec<Expression>,
10318    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
10319    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10320    pub columns: Vec<String>,
10321}
10322
10323/// AnalyzeStatistics
10324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10325#[cfg_attr(feature = "bindings", derive(TS))]
10326pub struct AnalyzeStatistics {
10327    pub kind: String,
10328    #[serde(default)]
10329    pub option: Option<Box<Expression>>,
10330    #[serde(default)]
10331    pub this: Option<Box<Expression>>,
10332    #[serde(default)]
10333    pub expressions: Vec<Expression>,
10334}
10335
10336/// AnalyzeHistogram
10337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10338#[cfg_attr(feature = "bindings", derive(TS))]
10339pub struct AnalyzeHistogram {
10340    pub this: Box<Expression>,
10341    #[serde(default)]
10342    pub expressions: Vec<Expression>,
10343    #[serde(default)]
10344    pub expression: Option<Box<Expression>>,
10345    #[serde(default)]
10346    pub update_options: Option<Box<Expression>>,
10347}
10348
10349/// AnalyzeSample
10350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10351#[cfg_attr(feature = "bindings", derive(TS))]
10352pub struct AnalyzeSample {
10353    pub kind: String,
10354    #[serde(default)]
10355    pub sample: Option<Box<Expression>>,
10356}
10357
10358/// AnalyzeListChainedRows
10359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10360#[cfg_attr(feature = "bindings", derive(TS))]
10361pub struct AnalyzeListChainedRows {
10362    #[serde(default)]
10363    pub expression: Option<Box<Expression>>,
10364}
10365
10366/// AnalyzeDelete
10367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10368#[cfg_attr(feature = "bindings", derive(TS))]
10369pub struct AnalyzeDelete {
10370    #[serde(default)]
10371    pub kind: Option<String>,
10372}
10373
10374/// AnalyzeWith
10375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10376#[cfg_attr(feature = "bindings", derive(TS))]
10377pub struct AnalyzeWith {
10378    #[serde(default)]
10379    pub expressions: Vec<Expression>,
10380}
10381
10382/// AnalyzeValidate
10383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10384#[cfg_attr(feature = "bindings", derive(TS))]
10385pub struct AnalyzeValidate {
10386    pub kind: String,
10387    #[serde(default)]
10388    pub this: Option<Box<Expression>>,
10389    #[serde(default)]
10390    pub expression: Option<Box<Expression>>,
10391}
10392
10393/// AddPartition
10394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10395#[cfg_attr(feature = "bindings", derive(TS))]
10396pub struct AddPartition {
10397    pub this: Box<Expression>,
10398    #[serde(default)]
10399    pub exists: bool,
10400    #[serde(default)]
10401    pub location: Option<Box<Expression>>,
10402}
10403
10404/// AttachOption
10405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10406#[cfg_attr(feature = "bindings", derive(TS))]
10407pub struct AttachOption {
10408    pub this: Box<Expression>,
10409    #[serde(default)]
10410    pub expression: Option<Box<Expression>>,
10411}
10412
10413/// DropPartition
10414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10415#[cfg_attr(feature = "bindings", derive(TS))]
10416pub struct DropPartition {
10417    #[serde(default)]
10418    pub expressions: Vec<Expression>,
10419    #[serde(default)]
10420    pub exists: bool,
10421}
10422
10423/// ReplacePartition
10424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10425#[cfg_attr(feature = "bindings", derive(TS))]
10426pub struct ReplacePartition {
10427    pub expression: Box<Expression>,
10428    #[serde(default)]
10429    pub source: Option<Box<Expression>>,
10430}
10431
10432/// DPipe
10433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10434#[cfg_attr(feature = "bindings", derive(TS))]
10435pub struct DPipe {
10436    pub this: Box<Expression>,
10437    pub expression: Box<Expression>,
10438    #[serde(default)]
10439    pub safe: Option<Box<Expression>>,
10440}
10441
10442/// Operator
10443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10444#[cfg_attr(feature = "bindings", derive(TS))]
10445pub struct Operator {
10446    pub this: Box<Expression>,
10447    #[serde(default)]
10448    pub operator: Option<Box<Expression>>,
10449    pub expression: Box<Expression>,
10450    /// Comments between OPERATOR() and the RHS expression
10451    #[serde(default, skip_serializing_if = "Vec::is_empty")]
10452    pub comments: Vec<String>,
10453}
10454
10455/// PivotAny
10456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10457#[cfg_attr(feature = "bindings", derive(TS))]
10458pub struct PivotAny {
10459    #[serde(default)]
10460    pub this: Option<Box<Expression>>,
10461}
10462
10463/// Aliases
10464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10465#[cfg_attr(feature = "bindings", derive(TS))]
10466pub struct Aliases {
10467    pub this: Box<Expression>,
10468    #[serde(default)]
10469    pub expressions: Vec<Expression>,
10470}
10471
10472/// AtIndex
10473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10474#[cfg_attr(feature = "bindings", derive(TS))]
10475pub struct AtIndex {
10476    pub this: Box<Expression>,
10477    pub expression: Box<Expression>,
10478}
10479
10480/// FromTimeZone
10481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10482#[cfg_attr(feature = "bindings", derive(TS))]
10483pub struct FromTimeZone {
10484    pub this: Box<Expression>,
10485    #[serde(default)]
10486    pub zone: Option<Box<Expression>>,
10487}
10488
10489/// Format override for a column in Teradata
10490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10491#[cfg_attr(feature = "bindings", derive(TS))]
10492pub struct FormatPhrase {
10493    pub this: Box<Expression>,
10494    pub format: String,
10495}
10496
10497/// ForIn
10498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10499#[cfg_attr(feature = "bindings", derive(TS))]
10500pub struct ForIn {
10501    pub this: Box<Expression>,
10502    pub expression: Box<Expression>,
10503}
10504
10505/// Automatically converts unit arg into a var.
10506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10507#[cfg_attr(feature = "bindings", derive(TS))]
10508pub struct TimeUnit {
10509    #[serde(default)]
10510    pub unit: Option<String>,
10511}
10512
10513/// IntervalOp
10514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10515#[cfg_attr(feature = "bindings", derive(TS))]
10516pub struct IntervalOp {
10517    #[serde(default)]
10518    pub unit: Option<String>,
10519    pub expression: Box<Expression>,
10520}
10521
10522/// HavingMax
10523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10524#[cfg_attr(feature = "bindings", derive(TS))]
10525pub struct HavingMax {
10526    pub this: Box<Expression>,
10527    pub expression: Box<Expression>,
10528    #[serde(default)]
10529    pub max: Option<Box<Expression>>,
10530}
10531
10532/// CosineDistance
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct CosineDistance {
10536    pub this: Box<Expression>,
10537    pub expression: Box<Expression>,
10538}
10539
10540/// DotProduct
10541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10542#[cfg_attr(feature = "bindings", derive(TS))]
10543pub struct DotProduct {
10544    pub this: Box<Expression>,
10545    pub expression: Box<Expression>,
10546}
10547
10548/// EuclideanDistance
10549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10550#[cfg_attr(feature = "bindings", derive(TS))]
10551pub struct EuclideanDistance {
10552    pub this: Box<Expression>,
10553    pub expression: Box<Expression>,
10554}
10555
10556/// ManhattanDistance
10557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10558#[cfg_attr(feature = "bindings", derive(TS))]
10559pub struct ManhattanDistance {
10560    pub this: Box<Expression>,
10561    pub expression: Box<Expression>,
10562}
10563
10564/// JarowinklerSimilarity
10565#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10566#[cfg_attr(feature = "bindings", derive(TS))]
10567pub struct JarowinklerSimilarity {
10568    pub this: Box<Expression>,
10569    pub expression: Box<Expression>,
10570}
10571
10572/// Booland
10573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10574#[cfg_attr(feature = "bindings", derive(TS))]
10575pub struct Booland {
10576    pub this: Box<Expression>,
10577    pub expression: Box<Expression>,
10578}
10579
10580/// Boolor
10581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10582#[cfg_attr(feature = "bindings", derive(TS))]
10583pub struct Boolor {
10584    pub this: Box<Expression>,
10585    pub expression: Box<Expression>,
10586}
10587
10588/// ParameterizedAgg
10589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10590#[cfg_attr(feature = "bindings", derive(TS))]
10591pub struct ParameterizedAgg {
10592    pub this: Box<Expression>,
10593    #[serde(default)]
10594    pub expressions: Vec<Expression>,
10595    #[serde(default)]
10596    pub params: Vec<Expression>,
10597}
10598
10599/// ArgMax
10600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10601#[cfg_attr(feature = "bindings", derive(TS))]
10602pub struct ArgMax {
10603    pub this: Box<Expression>,
10604    pub expression: Box<Expression>,
10605    #[serde(default)]
10606    pub count: Option<Box<Expression>>,
10607}
10608
10609/// ArgMin
10610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10611#[cfg_attr(feature = "bindings", derive(TS))]
10612pub struct ArgMin {
10613    pub this: Box<Expression>,
10614    pub expression: Box<Expression>,
10615    #[serde(default)]
10616    pub count: Option<Box<Expression>>,
10617}
10618
10619/// ApproxTopK
10620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10621#[cfg_attr(feature = "bindings", derive(TS))]
10622pub struct ApproxTopK {
10623    pub this: Box<Expression>,
10624    #[serde(default)]
10625    pub expression: Option<Box<Expression>>,
10626    #[serde(default)]
10627    pub counters: Option<Box<Expression>>,
10628}
10629
10630/// ApproxTopKAccumulate
10631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10632#[cfg_attr(feature = "bindings", derive(TS))]
10633pub struct ApproxTopKAccumulate {
10634    pub this: Box<Expression>,
10635    #[serde(default)]
10636    pub expression: Option<Box<Expression>>,
10637}
10638
10639/// ApproxTopKCombine
10640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10641#[cfg_attr(feature = "bindings", derive(TS))]
10642pub struct ApproxTopKCombine {
10643    pub this: Box<Expression>,
10644    #[serde(default)]
10645    pub expression: Option<Box<Expression>>,
10646}
10647
10648/// ApproxTopKEstimate
10649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10650#[cfg_attr(feature = "bindings", derive(TS))]
10651pub struct ApproxTopKEstimate {
10652    pub this: Box<Expression>,
10653    #[serde(default)]
10654    pub expression: Option<Box<Expression>>,
10655}
10656
10657/// ApproxTopSum
10658#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10659#[cfg_attr(feature = "bindings", derive(TS))]
10660pub struct ApproxTopSum {
10661    pub this: Box<Expression>,
10662    pub expression: Box<Expression>,
10663    #[serde(default)]
10664    pub count: Option<Box<Expression>>,
10665}
10666
10667/// ApproxQuantiles
10668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10669#[cfg_attr(feature = "bindings", derive(TS))]
10670pub struct ApproxQuantiles {
10671    pub this: Box<Expression>,
10672    #[serde(default)]
10673    pub expression: Option<Box<Expression>>,
10674}
10675
10676/// Minhash
10677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10678#[cfg_attr(feature = "bindings", derive(TS))]
10679pub struct Minhash {
10680    pub this: Box<Expression>,
10681    #[serde(default)]
10682    pub expressions: Vec<Expression>,
10683}
10684
10685/// FarmFingerprint
10686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10687#[cfg_attr(feature = "bindings", derive(TS))]
10688pub struct FarmFingerprint {
10689    #[serde(default)]
10690    pub expressions: Vec<Expression>,
10691}
10692
10693/// Float64
10694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10695#[cfg_attr(feature = "bindings", derive(TS))]
10696pub struct Float64 {
10697    pub this: Box<Expression>,
10698    #[serde(default)]
10699    pub expression: Option<Box<Expression>>,
10700}
10701
10702/// Transform
10703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10704#[cfg_attr(feature = "bindings", derive(TS))]
10705pub struct Transform {
10706    pub this: Box<Expression>,
10707    pub expression: Box<Expression>,
10708}
10709
10710/// Translate
10711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10712#[cfg_attr(feature = "bindings", derive(TS))]
10713pub struct Translate {
10714    pub this: Box<Expression>,
10715    #[serde(default)]
10716    pub from_: Option<Box<Expression>>,
10717    #[serde(default)]
10718    pub to: Option<Box<Expression>>,
10719}
10720
10721/// Grouping
10722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10723#[cfg_attr(feature = "bindings", derive(TS))]
10724pub struct Grouping {
10725    #[serde(default)]
10726    pub expressions: Vec<Expression>,
10727}
10728
10729/// GroupingId
10730#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10731#[cfg_attr(feature = "bindings", derive(TS))]
10732pub struct GroupingId {
10733    #[serde(default)]
10734    pub expressions: Vec<Expression>,
10735}
10736
10737/// Anonymous
10738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10739#[cfg_attr(feature = "bindings", derive(TS))]
10740pub struct Anonymous {
10741    pub this: Box<Expression>,
10742    #[serde(default)]
10743    pub expressions: Vec<Expression>,
10744}
10745
10746/// AnonymousAggFunc
10747#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10748#[cfg_attr(feature = "bindings", derive(TS))]
10749pub struct AnonymousAggFunc {
10750    pub this: Box<Expression>,
10751    #[serde(default)]
10752    pub expressions: Vec<Expression>,
10753}
10754
10755/// CombinedAggFunc
10756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10757#[cfg_attr(feature = "bindings", derive(TS))]
10758pub struct CombinedAggFunc {
10759    pub this: Box<Expression>,
10760    #[serde(default)]
10761    pub expressions: Vec<Expression>,
10762}
10763
10764/// CombinedParameterizedAgg
10765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10766#[cfg_attr(feature = "bindings", derive(TS))]
10767pub struct CombinedParameterizedAgg {
10768    pub this: Box<Expression>,
10769    #[serde(default)]
10770    pub expressions: Vec<Expression>,
10771    #[serde(default)]
10772    pub params: Vec<Expression>,
10773}
10774
10775/// HashAgg
10776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10777#[cfg_attr(feature = "bindings", derive(TS))]
10778pub struct HashAgg {
10779    pub this: Box<Expression>,
10780    #[serde(default)]
10781    pub expressions: Vec<Expression>,
10782}
10783
10784/// Hll
10785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10786#[cfg_attr(feature = "bindings", derive(TS))]
10787pub struct Hll {
10788    pub this: Box<Expression>,
10789    #[serde(default)]
10790    pub expressions: Vec<Expression>,
10791}
10792
10793/// Apply
10794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10795#[cfg_attr(feature = "bindings", derive(TS))]
10796pub struct Apply {
10797    pub this: Box<Expression>,
10798    pub expression: Box<Expression>,
10799}
10800
10801/// ToBoolean
10802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10803#[cfg_attr(feature = "bindings", derive(TS))]
10804pub struct ToBoolean {
10805    pub this: Box<Expression>,
10806    #[serde(default)]
10807    pub safe: Option<Box<Expression>>,
10808}
10809
10810/// List
10811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10812#[cfg_attr(feature = "bindings", derive(TS))]
10813pub struct List {
10814    #[serde(default)]
10815    pub expressions: Vec<Expression>,
10816}
10817
10818/// ToMap - Materialize-style map constructor
10819/// Can hold either:
10820/// - A SELECT subquery (MAP(SELECT 'a', 1))
10821/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10823#[cfg_attr(feature = "bindings", derive(TS))]
10824pub struct ToMap {
10825    /// Either a Select subquery or a Struct containing PropertyEQ entries
10826    pub this: Box<Expression>,
10827}
10828
10829/// Pad
10830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10831#[cfg_attr(feature = "bindings", derive(TS))]
10832pub struct Pad {
10833    pub this: Box<Expression>,
10834    pub expression: Box<Expression>,
10835    #[serde(default)]
10836    pub fill_pattern: Option<Box<Expression>>,
10837    #[serde(default)]
10838    pub is_left: Option<Box<Expression>>,
10839}
10840
10841/// ToChar
10842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10843#[cfg_attr(feature = "bindings", derive(TS))]
10844pub struct ToChar {
10845    pub this: Box<Expression>,
10846    #[serde(default)]
10847    pub format: Option<String>,
10848    #[serde(default)]
10849    pub nlsparam: Option<Box<Expression>>,
10850    #[serde(default)]
10851    pub is_numeric: Option<Box<Expression>>,
10852}
10853
10854/// StringFunc - String type conversion function (BigQuery STRING)
10855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10856#[cfg_attr(feature = "bindings", derive(TS))]
10857pub struct StringFunc {
10858    pub this: Box<Expression>,
10859    #[serde(default)]
10860    pub zone: Option<Box<Expression>>,
10861}
10862
10863/// ToNumber
10864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10865#[cfg_attr(feature = "bindings", derive(TS))]
10866pub struct ToNumber {
10867    pub this: Box<Expression>,
10868    #[serde(default)]
10869    pub format: Option<Box<Expression>>,
10870    #[serde(default)]
10871    pub nlsparam: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub precision: Option<Box<Expression>>,
10874    #[serde(default)]
10875    pub scale: Option<Box<Expression>>,
10876    #[serde(default)]
10877    pub safe: Option<Box<Expression>>,
10878    #[serde(default)]
10879    pub safe_name: Option<Box<Expression>>,
10880}
10881
10882/// ToDouble
10883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10884#[cfg_attr(feature = "bindings", derive(TS))]
10885pub struct ToDouble {
10886    pub this: Box<Expression>,
10887    #[serde(default)]
10888    pub format: Option<String>,
10889    #[serde(default)]
10890    pub safe: Option<Box<Expression>>,
10891}
10892
10893/// ToDecfloat
10894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10895#[cfg_attr(feature = "bindings", derive(TS))]
10896pub struct ToDecfloat {
10897    pub this: Box<Expression>,
10898    #[serde(default)]
10899    pub format: Option<String>,
10900}
10901
10902/// TryToDecfloat
10903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10904#[cfg_attr(feature = "bindings", derive(TS))]
10905pub struct TryToDecfloat {
10906    pub this: Box<Expression>,
10907    #[serde(default)]
10908    pub format: Option<String>,
10909}
10910
10911/// ToFile
10912#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10913#[cfg_attr(feature = "bindings", derive(TS))]
10914pub struct ToFile {
10915    pub this: Box<Expression>,
10916    #[serde(default)]
10917    pub path: Option<Box<Expression>>,
10918    #[serde(default)]
10919    pub safe: Option<Box<Expression>>,
10920}
10921
10922/// Columns
10923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10924#[cfg_attr(feature = "bindings", derive(TS))]
10925pub struct Columns {
10926    pub this: Box<Expression>,
10927    #[serde(default)]
10928    pub unpack: Option<Box<Expression>>,
10929}
10930
10931/// ConvertToCharset
10932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10933#[cfg_attr(feature = "bindings", derive(TS))]
10934pub struct ConvertToCharset {
10935    pub this: Box<Expression>,
10936    #[serde(default)]
10937    pub dest: Option<Box<Expression>>,
10938    #[serde(default)]
10939    pub source: Option<Box<Expression>>,
10940}
10941
10942/// ConvertTimezone
10943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10944#[cfg_attr(feature = "bindings", derive(TS))]
10945pub struct ConvertTimezone {
10946    #[serde(default)]
10947    pub source_tz: Option<Box<Expression>>,
10948    #[serde(default)]
10949    pub target_tz: Option<Box<Expression>>,
10950    #[serde(default)]
10951    pub timestamp: Option<Box<Expression>>,
10952    #[serde(default)]
10953    pub options: Vec<Expression>,
10954}
10955
10956/// GenerateSeries
10957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10958#[cfg_attr(feature = "bindings", derive(TS))]
10959pub struct GenerateSeries {
10960    #[serde(default)]
10961    pub start: Option<Box<Expression>>,
10962    #[serde(default)]
10963    pub end: Option<Box<Expression>>,
10964    #[serde(default)]
10965    pub step: Option<Box<Expression>>,
10966    #[serde(default)]
10967    pub is_end_exclusive: Option<Box<Expression>>,
10968}
10969
10970/// AIAgg
10971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10972#[cfg_attr(feature = "bindings", derive(TS))]
10973pub struct AIAgg {
10974    pub this: Box<Expression>,
10975    pub expression: Box<Expression>,
10976}
10977
10978/// AIClassify
10979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10980#[cfg_attr(feature = "bindings", derive(TS))]
10981pub struct AIClassify {
10982    pub this: Box<Expression>,
10983    #[serde(default)]
10984    pub categories: Option<Box<Expression>>,
10985    #[serde(default)]
10986    pub config: Option<Box<Expression>>,
10987}
10988
10989/// ArrayAll
10990#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10991#[cfg_attr(feature = "bindings", derive(TS))]
10992pub struct ArrayAll {
10993    pub this: Box<Expression>,
10994    pub expression: Box<Expression>,
10995}
10996
10997/// ArrayAny
10998#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10999#[cfg_attr(feature = "bindings", derive(TS))]
11000pub struct ArrayAny {
11001    pub this: Box<Expression>,
11002    pub expression: Box<Expression>,
11003}
11004
11005/// ArrayConstructCompact
11006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11007#[cfg_attr(feature = "bindings", derive(TS))]
11008pub struct ArrayConstructCompact {
11009    #[serde(default)]
11010    pub expressions: Vec<Expression>,
11011}
11012
11013/// StPoint
11014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11015#[cfg_attr(feature = "bindings", derive(TS))]
11016pub struct StPoint {
11017    pub this: Box<Expression>,
11018    pub expression: Box<Expression>,
11019    #[serde(default)]
11020    pub null: Option<Box<Expression>>,
11021}
11022
11023/// StDistance
11024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11025#[cfg_attr(feature = "bindings", derive(TS))]
11026pub struct StDistance {
11027    pub this: Box<Expression>,
11028    pub expression: Box<Expression>,
11029    #[serde(default)]
11030    pub use_spheroid: Option<Box<Expression>>,
11031}
11032
11033/// StringToArray
11034#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11035#[cfg_attr(feature = "bindings", derive(TS))]
11036pub struct StringToArray {
11037    pub this: Box<Expression>,
11038    #[serde(default)]
11039    pub expression: Option<Box<Expression>>,
11040    #[serde(default)]
11041    pub null: Option<Box<Expression>>,
11042}
11043
11044/// ArraySum
11045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11046#[cfg_attr(feature = "bindings", derive(TS))]
11047pub struct ArraySum {
11048    pub this: Box<Expression>,
11049    #[serde(default)]
11050    pub expression: Option<Box<Expression>>,
11051}
11052
11053/// ObjectAgg
11054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11055#[cfg_attr(feature = "bindings", derive(TS))]
11056pub struct ObjectAgg {
11057    pub this: Box<Expression>,
11058    pub expression: Box<Expression>,
11059}
11060
11061/// CastToStrType
11062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11063#[cfg_attr(feature = "bindings", derive(TS))]
11064pub struct CastToStrType {
11065    pub this: Box<Expression>,
11066    #[serde(default)]
11067    pub to: Option<Box<Expression>>,
11068}
11069
11070/// CheckJson
11071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11072#[cfg_attr(feature = "bindings", derive(TS))]
11073pub struct CheckJson {
11074    pub this: Box<Expression>,
11075}
11076
11077/// CheckXml
11078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11079#[cfg_attr(feature = "bindings", derive(TS))]
11080pub struct CheckXml {
11081    pub this: Box<Expression>,
11082    #[serde(default)]
11083    pub disable_auto_convert: Option<Box<Expression>>,
11084}
11085
11086/// TranslateCharacters
11087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11088#[cfg_attr(feature = "bindings", derive(TS))]
11089pub struct TranslateCharacters {
11090    pub this: Box<Expression>,
11091    pub expression: Box<Expression>,
11092    #[serde(default)]
11093    pub with_error: Option<Box<Expression>>,
11094}
11095
11096/// CurrentSchemas
11097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11098#[cfg_attr(feature = "bindings", derive(TS))]
11099pub struct CurrentSchemas {
11100    #[serde(default)]
11101    pub this: Option<Box<Expression>>,
11102}
11103
11104/// CurrentDatetime
11105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11106#[cfg_attr(feature = "bindings", derive(TS))]
11107pub struct CurrentDatetime {
11108    #[serde(default)]
11109    pub this: Option<Box<Expression>>,
11110}
11111
11112/// Localtime
11113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11114#[cfg_attr(feature = "bindings", derive(TS))]
11115pub struct Localtime {
11116    #[serde(default)]
11117    pub this: Option<Box<Expression>>,
11118}
11119
11120/// Localtimestamp
11121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11122#[cfg_attr(feature = "bindings", derive(TS))]
11123pub struct Localtimestamp {
11124    #[serde(default)]
11125    pub this: Option<Box<Expression>>,
11126}
11127
11128/// Systimestamp
11129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11130#[cfg_attr(feature = "bindings", derive(TS))]
11131pub struct Systimestamp {
11132    #[serde(default)]
11133    pub this: Option<Box<Expression>>,
11134}
11135
11136/// CurrentSchema
11137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11138#[cfg_attr(feature = "bindings", derive(TS))]
11139pub struct CurrentSchema {
11140    #[serde(default)]
11141    pub this: Option<Box<Expression>>,
11142}
11143
11144/// CurrentUser
11145#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11146#[cfg_attr(feature = "bindings", derive(TS))]
11147pub struct CurrentUser {
11148    #[serde(default)]
11149    pub this: Option<Box<Expression>>,
11150}
11151
11152/// SessionUser - MySQL/PostgreSQL SESSION_USER function
11153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11154#[cfg_attr(feature = "bindings", derive(TS))]
11155pub struct SessionUser;
11156
11157/// JSONPathRoot - Represents $ in JSON path expressions
11158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11159#[cfg_attr(feature = "bindings", derive(TS))]
11160pub struct JSONPathRoot;
11161
11162/// UtcTime
11163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11164#[cfg_attr(feature = "bindings", derive(TS))]
11165pub struct UtcTime {
11166    #[serde(default)]
11167    pub this: Option<Box<Expression>>,
11168}
11169
11170/// UtcTimestamp
11171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11172#[cfg_attr(feature = "bindings", derive(TS))]
11173pub struct UtcTimestamp {
11174    #[serde(default)]
11175    pub this: Option<Box<Expression>>,
11176}
11177
11178/// TimestampFunc - TIMESTAMP constructor function
11179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11180#[cfg_attr(feature = "bindings", derive(TS))]
11181pub struct TimestampFunc {
11182    #[serde(default)]
11183    pub this: Option<Box<Expression>>,
11184    #[serde(default)]
11185    pub zone: Option<Box<Expression>>,
11186    #[serde(default)]
11187    pub with_tz: Option<bool>,
11188    #[serde(default)]
11189    pub safe: Option<bool>,
11190}
11191
11192/// DateBin
11193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11194#[cfg_attr(feature = "bindings", derive(TS))]
11195pub struct DateBin {
11196    pub this: Box<Expression>,
11197    pub expression: Box<Expression>,
11198    #[serde(default)]
11199    pub unit: Option<String>,
11200    #[serde(default)]
11201    pub zone: Option<Box<Expression>>,
11202    #[serde(default)]
11203    pub origin: Option<Box<Expression>>,
11204}
11205
11206/// Datetime
11207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11208#[cfg_attr(feature = "bindings", derive(TS))]
11209pub struct Datetime {
11210    pub this: Box<Expression>,
11211    #[serde(default)]
11212    pub expression: Option<Box<Expression>>,
11213}
11214
11215/// DatetimeAdd
11216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11217#[cfg_attr(feature = "bindings", derive(TS))]
11218pub struct DatetimeAdd {
11219    pub this: Box<Expression>,
11220    pub expression: Box<Expression>,
11221    #[serde(default)]
11222    pub unit: Option<String>,
11223}
11224
11225/// DatetimeSub
11226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11227#[cfg_attr(feature = "bindings", derive(TS))]
11228pub struct DatetimeSub {
11229    pub this: Box<Expression>,
11230    pub expression: Box<Expression>,
11231    #[serde(default)]
11232    pub unit: Option<String>,
11233}
11234
11235/// DatetimeDiff
11236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11237#[cfg_attr(feature = "bindings", derive(TS))]
11238pub struct DatetimeDiff {
11239    pub this: Box<Expression>,
11240    pub expression: Box<Expression>,
11241    #[serde(default)]
11242    pub unit: Option<String>,
11243}
11244
11245/// DatetimeTrunc
11246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11247#[cfg_attr(feature = "bindings", derive(TS))]
11248pub struct DatetimeTrunc {
11249    pub this: Box<Expression>,
11250    pub unit: String,
11251    #[serde(default)]
11252    pub zone: Option<Box<Expression>>,
11253}
11254
11255/// Dayname
11256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11257#[cfg_attr(feature = "bindings", derive(TS))]
11258pub struct Dayname {
11259    pub this: Box<Expression>,
11260    #[serde(default)]
11261    pub abbreviated: Option<Box<Expression>>,
11262}
11263
11264/// MakeInterval
11265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11266#[cfg_attr(feature = "bindings", derive(TS))]
11267pub struct MakeInterval {
11268    #[serde(default)]
11269    pub year: Option<Box<Expression>>,
11270    #[serde(default)]
11271    pub month: Option<Box<Expression>>,
11272    #[serde(default)]
11273    pub week: Option<Box<Expression>>,
11274    #[serde(default)]
11275    pub day: Option<Box<Expression>>,
11276    #[serde(default)]
11277    pub hour: Option<Box<Expression>>,
11278    #[serde(default)]
11279    pub minute: Option<Box<Expression>>,
11280    #[serde(default)]
11281    pub second: Option<Box<Expression>>,
11282}
11283
11284/// PreviousDay
11285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11286#[cfg_attr(feature = "bindings", derive(TS))]
11287pub struct PreviousDay {
11288    pub this: Box<Expression>,
11289    pub expression: Box<Expression>,
11290}
11291
11292/// Elt
11293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11294#[cfg_attr(feature = "bindings", derive(TS))]
11295pub struct Elt {
11296    pub this: Box<Expression>,
11297    #[serde(default)]
11298    pub expressions: Vec<Expression>,
11299}
11300
11301/// TimestampAdd
11302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11303#[cfg_attr(feature = "bindings", derive(TS))]
11304pub struct TimestampAdd {
11305    pub this: Box<Expression>,
11306    pub expression: Box<Expression>,
11307    #[serde(default)]
11308    pub unit: Option<String>,
11309}
11310
11311/// TimestampSub
11312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11313#[cfg_attr(feature = "bindings", derive(TS))]
11314pub struct TimestampSub {
11315    pub this: Box<Expression>,
11316    pub expression: Box<Expression>,
11317    #[serde(default)]
11318    pub unit: Option<String>,
11319}
11320
11321/// TimestampDiff
11322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11323#[cfg_attr(feature = "bindings", derive(TS))]
11324pub struct TimestampDiff {
11325    pub this: Box<Expression>,
11326    pub expression: Box<Expression>,
11327    #[serde(default)]
11328    pub unit: Option<String>,
11329}
11330
11331/// TimeSlice
11332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11333#[cfg_attr(feature = "bindings", derive(TS))]
11334pub struct TimeSlice {
11335    pub this: Box<Expression>,
11336    pub expression: Box<Expression>,
11337    pub unit: String,
11338    #[serde(default)]
11339    pub kind: Option<String>,
11340}
11341
11342/// TimeAdd
11343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11344#[cfg_attr(feature = "bindings", derive(TS))]
11345pub struct TimeAdd {
11346    pub this: Box<Expression>,
11347    pub expression: Box<Expression>,
11348    #[serde(default)]
11349    pub unit: Option<String>,
11350}
11351
11352/// TimeSub
11353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11354#[cfg_attr(feature = "bindings", derive(TS))]
11355pub struct TimeSub {
11356    pub this: Box<Expression>,
11357    pub expression: Box<Expression>,
11358    #[serde(default)]
11359    pub unit: Option<String>,
11360}
11361
11362/// TimeDiff
11363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11364#[cfg_attr(feature = "bindings", derive(TS))]
11365pub struct TimeDiff {
11366    pub this: Box<Expression>,
11367    pub expression: Box<Expression>,
11368    #[serde(default)]
11369    pub unit: Option<String>,
11370}
11371
11372/// TimeTrunc
11373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11374#[cfg_attr(feature = "bindings", derive(TS))]
11375pub struct TimeTrunc {
11376    pub this: Box<Expression>,
11377    pub unit: String,
11378    #[serde(default)]
11379    pub zone: Option<Box<Expression>>,
11380}
11381
11382/// DateFromParts
11383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11384#[cfg_attr(feature = "bindings", derive(TS))]
11385pub struct DateFromParts {
11386    #[serde(default)]
11387    pub year: Option<Box<Expression>>,
11388    #[serde(default)]
11389    pub month: Option<Box<Expression>>,
11390    #[serde(default)]
11391    pub day: Option<Box<Expression>>,
11392    #[serde(default)]
11393    pub allow_overflow: Option<Box<Expression>>,
11394}
11395
11396/// TimeFromParts
11397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11398#[cfg_attr(feature = "bindings", derive(TS))]
11399pub struct TimeFromParts {
11400    #[serde(default)]
11401    pub hour: Option<Box<Expression>>,
11402    #[serde(default)]
11403    pub min: Option<Box<Expression>>,
11404    #[serde(default)]
11405    pub sec: Option<Box<Expression>>,
11406    #[serde(default)]
11407    pub nano: Option<Box<Expression>>,
11408    #[serde(default)]
11409    pub fractions: Option<Box<Expression>>,
11410    #[serde(default)]
11411    pub precision: Option<i64>,
11412}
11413
11414/// DecodeCase
11415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11416#[cfg_attr(feature = "bindings", derive(TS))]
11417pub struct DecodeCase {
11418    #[serde(default)]
11419    pub expressions: Vec<Expression>,
11420}
11421
11422/// Decrypt
11423#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11424#[cfg_attr(feature = "bindings", derive(TS))]
11425pub struct Decrypt {
11426    pub this: Box<Expression>,
11427    #[serde(default)]
11428    pub passphrase: Option<Box<Expression>>,
11429    #[serde(default)]
11430    pub aad: Option<Box<Expression>>,
11431    #[serde(default)]
11432    pub encryption_method: Option<Box<Expression>>,
11433    #[serde(default)]
11434    pub safe: Option<Box<Expression>>,
11435}
11436
11437/// DecryptRaw
11438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11439#[cfg_attr(feature = "bindings", derive(TS))]
11440pub struct DecryptRaw {
11441    pub this: Box<Expression>,
11442    #[serde(default)]
11443    pub key: Option<Box<Expression>>,
11444    #[serde(default)]
11445    pub iv: Option<Box<Expression>>,
11446    #[serde(default)]
11447    pub aad: Option<Box<Expression>>,
11448    #[serde(default)]
11449    pub encryption_method: Option<Box<Expression>>,
11450    #[serde(default)]
11451    pub aead: Option<Box<Expression>>,
11452    #[serde(default)]
11453    pub safe: Option<Box<Expression>>,
11454}
11455
11456/// Encode
11457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11458#[cfg_attr(feature = "bindings", derive(TS))]
11459pub struct Encode {
11460    pub this: Box<Expression>,
11461    #[serde(default)]
11462    pub charset: Option<Box<Expression>>,
11463}
11464
11465/// Encrypt
11466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11467#[cfg_attr(feature = "bindings", derive(TS))]
11468pub struct Encrypt {
11469    pub this: Box<Expression>,
11470    #[serde(default)]
11471    pub passphrase: Option<Box<Expression>>,
11472    #[serde(default)]
11473    pub aad: Option<Box<Expression>>,
11474    #[serde(default)]
11475    pub encryption_method: Option<Box<Expression>>,
11476}
11477
11478/// EncryptRaw
11479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11480#[cfg_attr(feature = "bindings", derive(TS))]
11481pub struct EncryptRaw {
11482    pub this: Box<Expression>,
11483    #[serde(default)]
11484    pub key: Option<Box<Expression>>,
11485    #[serde(default)]
11486    pub iv: Option<Box<Expression>>,
11487    #[serde(default)]
11488    pub aad: Option<Box<Expression>>,
11489    #[serde(default)]
11490    pub encryption_method: Option<Box<Expression>>,
11491}
11492
11493/// EqualNull
11494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11495#[cfg_attr(feature = "bindings", derive(TS))]
11496pub struct EqualNull {
11497    pub this: Box<Expression>,
11498    pub expression: Box<Expression>,
11499}
11500
11501/// ToBinary
11502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11503#[cfg_attr(feature = "bindings", derive(TS))]
11504pub struct ToBinary {
11505    pub this: Box<Expression>,
11506    #[serde(default)]
11507    pub format: Option<String>,
11508    #[serde(default)]
11509    pub safe: Option<Box<Expression>>,
11510}
11511
11512/// Base64DecodeBinary
11513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11514#[cfg_attr(feature = "bindings", derive(TS))]
11515pub struct Base64DecodeBinary {
11516    pub this: Box<Expression>,
11517    #[serde(default)]
11518    pub alphabet: Option<Box<Expression>>,
11519}
11520
11521/// Base64DecodeString
11522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11523#[cfg_attr(feature = "bindings", derive(TS))]
11524pub struct Base64DecodeString {
11525    pub this: Box<Expression>,
11526    #[serde(default)]
11527    pub alphabet: Option<Box<Expression>>,
11528}
11529
11530/// Base64Encode
11531#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11532#[cfg_attr(feature = "bindings", derive(TS))]
11533pub struct Base64Encode {
11534    pub this: Box<Expression>,
11535    #[serde(default)]
11536    pub max_line_length: Option<Box<Expression>>,
11537    #[serde(default)]
11538    pub alphabet: Option<Box<Expression>>,
11539}
11540
11541/// TryBase64DecodeBinary
11542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11543#[cfg_attr(feature = "bindings", derive(TS))]
11544pub struct TryBase64DecodeBinary {
11545    pub this: Box<Expression>,
11546    #[serde(default)]
11547    pub alphabet: Option<Box<Expression>>,
11548}
11549
11550/// TryBase64DecodeString
11551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11552#[cfg_attr(feature = "bindings", derive(TS))]
11553pub struct TryBase64DecodeString {
11554    pub this: Box<Expression>,
11555    #[serde(default)]
11556    pub alphabet: Option<Box<Expression>>,
11557}
11558
11559/// GapFill
11560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11561#[cfg_attr(feature = "bindings", derive(TS))]
11562pub struct GapFill {
11563    pub this: Box<Expression>,
11564    #[serde(default)]
11565    pub ts_column: Option<Box<Expression>>,
11566    #[serde(default)]
11567    pub bucket_width: Option<Box<Expression>>,
11568    #[serde(default)]
11569    pub partitioning_columns: Option<Box<Expression>>,
11570    #[serde(default)]
11571    pub value_columns: Option<Box<Expression>>,
11572    #[serde(default)]
11573    pub origin: Option<Box<Expression>>,
11574    #[serde(default)]
11575    pub ignore_nulls: Option<Box<Expression>>,
11576}
11577
11578/// GenerateDateArray
11579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11580#[cfg_attr(feature = "bindings", derive(TS))]
11581pub struct GenerateDateArray {
11582    #[serde(default)]
11583    pub start: Option<Box<Expression>>,
11584    #[serde(default)]
11585    pub end: Option<Box<Expression>>,
11586    #[serde(default)]
11587    pub step: Option<Box<Expression>>,
11588}
11589
11590/// GenerateTimestampArray
11591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11592#[cfg_attr(feature = "bindings", derive(TS))]
11593pub struct GenerateTimestampArray {
11594    #[serde(default)]
11595    pub start: Option<Box<Expression>>,
11596    #[serde(default)]
11597    pub end: Option<Box<Expression>>,
11598    #[serde(default)]
11599    pub step: Option<Box<Expression>>,
11600}
11601
11602/// GetExtract
11603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11604#[cfg_attr(feature = "bindings", derive(TS))]
11605pub struct GetExtract {
11606    pub this: Box<Expression>,
11607    pub expression: Box<Expression>,
11608}
11609
11610/// Getbit
11611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11612#[cfg_attr(feature = "bindings", derive(TS))]
11613pub struct Getbit {
11614    pub this: Box<Expression>,
11615    pub expression: Box<Expression>,
11616    #[serde(default)]
11617    pub zero_is_msb: Option<Box<Expression>>,
11618}
11619
11620/// OverflowTruncateBehavior
11621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11622#[cfg_attr(feature = "bindings", derive(TS))]
11623pub struct OverflowTruncateBehavior {
11624    #[serde(default)]
11625    pub this: Option<Box<Expression>>,
11626    #[serde(default)]
11627    pub with_count: Option<Box<Expression>>,
11628}
11629
11630/// HexEncode
11631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11632#[cfg_attr(feature = "bindings", derive(TS))]
11633pub struct HexEncode {
11634    pub this: Box<Expression>,
11635    #[serde(default)]
11636    pub case: Option<Box<Expression>>,
11637}
11638
11639/// Compress
11640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11641#[cfg_attr(feature = "bindings", derive(TS))]
11642pub struct Compress {
11643    pub this: Box<Expression>,
11644    #[serde(default)]
11645    pub method: Option<String>,
11646}
11647
11648/// DecompressBinary
11649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11650#[cfg_attr(feature = "bindings", derive(TS))]
11651pub struct DecompressBinary {
11652    pub this: Box<Expression>,
11653    pub method: String,
11654}
11655
11656/// DecompressString
11657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11658#[cfg_attr(feature = "bindings", derive(TS))]
11659pub struct DecompressString {
11660    pub this: Box<Expression>,
11661    pub method: String,
11662}
11663
11664/// Xor
11665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11666#[cfg_attr(feature = "bindings", derive(TS))]
11667pub struct Xor {
11668    #[serde(default)]
11669    pub this: Option<Box<Expression>>,
11670    #[serde(default)]
11671    pub expression: Option<Box<Expression>>,
11672    #[serde(default)]
11673    pub expressions: Vec<Expression>,
11674}
11675
11676/// Nullif
11677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11678#[cfg_attr(feature = "bindings", derive(TS))]
11679pub struct Nullif {
11680    pub this: Box<Expression>,
11681    pub expression: Box<Expression>,
11682}
11683
11684/// JSON
11685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11686#[cfg_attr(feature = "bindings", derive(TS))]
11687pub struct JSON {
11688    #[serde(default)]
11689    pub this: Option<Box<Expression>>,
11690    #[serde(default)]
11691    pub with_: Option<Box<Expression>>,
11692    #[serde(default)]
11693    pub unique: bool,
11694}
11695
11696/// JSONPath
11697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11698#[cfg_attr(feature = "bindings", derive(TS))]
11699pub struct JSONPath {
11700    #[serde(default)]
11701    pub expressions: Vec<Expression>,
11702    #[serde(default)]
11703    pub escape: Option<Box<Expression>>,
11704}
11705
11706/// JSONPathFilter
11707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11708#[cfg_attr(feature = "bindings", derive(TS))]
11709pub struct JSONPathFilter {
11710    pub this: Box<Expression>,
11711}
11712
11713/// JSONPathKey
11714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11715#[cfg_attr(feature = "bindings", derive(TS))]
11716pub struct JSONPathKey {
11717    pub this: Box<Expression>,
11718}
11719
11720/// JSONPathRecursive
11721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11722#[cfg_attr(feature = "bindings", derive(TS))]
11723pub struct JSONPathRecursive {
11724    #[serde(default)]
11725    pub this: Option<Box<Expression>>,
11726}
11727
11728/// JSONPathScript
11729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11730#[cfg_attr(feature = "bindings", derive(TS))]
11731pub struct JSONPathScript {
11732    pub this: Box<Expression>,
11733}
11734
11735/// JSONPathSlice
11736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11737#[cfg_attr(feature = "bindings", derive(TS))]
11738pub struct JSONPathSlice {
11739    #[serde(default)]
11740    pub start: Option<Box<Expression>>,
11741    #[serde(default)]
11742    pub end: Option<Box<Expression>>,
11743    #[serde(default)]
11744    pub step: Option<Box<Expression>>,
11745}
11746
11747/// JSONPathSelector
11748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11749#[cfg_attr(feature = "bindings", derive(TS))]
11750pub struct JSONPathSelector {
11751    pub this: Box<Expression>,
11752}
11753
11754/// JSONPathSubscript
11755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11756#[cfg_attr(feature = "bindings", derive(TS))]
11757pub struct JSONPathSubscript {
11758    pub this: Box<Expression>,
11759}
11760
11761/// JSONPathUnion
11762#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11763#[cfg_attr(feature = "bindings", derive(TS))]
11764pub struct JSONPathUnion {
11765    #[serde(default)]
11766    pub expressions: Vec<Expression>,
11767}
11768
11769/// Format
11770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11771#[cfg_attr(feature = "bindings", derive(TS))]
11772pub struct Format {
11773    pub this: Box<Expression>,
11774    #[serde(default)]
11775    pub expressions: Vec<Expression>,
11776}
11777
11778/// JSONKeys
11779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11780#[cfg_attr(feature = "bindings", derive(TS))]
11781pub struct JSONKeys {
11782    pub this: Box<Expression>,
11783    #[serde(default)]
11784    pub expression: Option<Box<Expression>>,
11785    #[serde(default)]
11786    pub expressions: Vec<Expression>,
11787}
11788
11789/// JSONKeyValue
11790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11791#[cfg_attr(feature = "bindings", derive(TS))]
11792pub struct JSONKeyValue {
11793    pub this: Box<Expression>,
11794    pub expression: Box<Expression>,
11795}
11796
11797/// JSONKeysAtDepth
11798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11799#[cfg_attr(feature = "bindings", derive(TS))]
11800pub struct JSONKeysAtDepth {
11801    pub this: Box<Expression>,
11802    #[serde(default)]
11803    pub expression: Option<Box<Expression>>,
11804    #[serde(default)]
11805    pub mode: Option<Box<Expression>>,
11806}
11807
11808/// JSONObject
11809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11810#[cfg_attr(feature = "bindings", derive(TS))]
11811pub struct JSONObject {
11812    #[serde(default)]
11813    pub expressions: Vec<Expression>,
11814    #[serde(default)]
11815    pub null_handling: Option<Box<Expression>>,
11816    #[serde(default)]
11817    pub unique_keys: Option<Box<Expression>>,
11818    #[serde(default)]
11819    pub return_type: Option<Box<Expression>>,
11820    #[serde(default)]
11821    pub encoding: Option<Box<Expression>>,
11822}
11823
11824/// JSONObjectAgg
11825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11826#[cfg_attr(feature = "bindings", derive(TS))]
11827pub struct JSONObjectAgg {
11828    #[serde(default)]
11829    pub expressions: Vec<Expression>,
11830    #[serde(default)]
11831    pub null_handling: Option<Box<Expression>>,
11832    #[serde(default)]
11833    pub unique_keys: Option<Box<Expression>>,
11834    #[serde(default)]
11835    pub return_type: Option<Box<Expression>>,
11836    #[serde(default)]
11837    pub encoding: Option<Box<Expression>>,
11838}
11839
11840/// JSONBObjectAgg
11841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11842#[cfg_attr(feature = "bindings", derive(TS))]
11843pub struct JSONBObjectAgg {
11844    pub this: Box<Expression>,
11845    pub expression: Box<Expression>,
11846}
11847
11848/// JSONArray
11849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11850#[cfg_attr(feature = "bindings", derive(TS))]
11851pub struct JSONArray {
11852    #[serde(default)]
11853    pub expressions: Vec<Expression>,
11854    #[serde(default)]
11855    pub null_handling: Option<Box<Expression>>,
11856    #[serde(default)]
11857    pub return_type: Option<Box<Expression>>,
11858    #[serde(default)]
11859    pub strict: Option<Box<Expression>>,
11860}
11861
11862/// JSONArrayAgg
11863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11864#[cfg_attr(feature = "bindings", derive(TS))]
11865pub struct JSONArrayAgg {
11866    pub this: Box<Expression>,
11867    #[serde(default)]
11868    pub order: Option<Box<Expression>>,
11869    #[serde(default)]
11870    pub null_handling: Option<Box<Expression>>,
11871    #[serde(default)]
11872    pub return_type: Option<Box<Expression>>,
11873    #[serde(default)]
11874    pub strict: Option<Box<Expression>>,
11875}
11876
11877/// JSONExists
11878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11879#[cfg_attr(feature = "bindings", derive(TS))]
11880pub struct JSONExists {
11881    pub this: Box<Expression>,
11882    #[serde(default)]
11883    pub path: Option<Box<Expression>>,
11884    #[serde(default)]
11885    pub passing: Option<Box<Expression>>,
11886    #[serde(default)]
11887    pub on_condition: Option<Box<Expression>>,
11888    #[serde(default)]
11889    pub from_dcolonqmark: Option<Box<Expression>>,
11890}
11891
11892/// JSONColumnDef
11893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11894#[cfg_attr(feature = "bindings", derive(TS))]
11895pub struct JSONColumnDef {
11896    #[serde(default)]
11897    pub this: Option<Box<Expression>>,
11898    #[serde(default)]
11899    pub kind: Option<String>,
11900    #[serde(default)]
11901    pub path: Option<Box<Expression>>,
11902    #[serde(default)]
11903    pub nested_schema: Option<Box<Expression>>,
11904    #[serde(default)]
11905    pub ordinality: Option<Box<Expression>>,
11906}
11907
11908/// JSONSchema
11909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11910#[cfg_attr(feature = "bindings", derive(TS))]
11911pub struct JSONSchema {
11912    #[serde(default)]
11913    pub expressions: Vec<Expression>,
11914}
11915
11916/// JSONSet
11917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11918#[cfg_attr(feature = "bindings", derive(TS))]
11919pub struct JSONSet {
11920    pub this: Box<Expression>,
11921    #[serde(default)]
11922    pub expressions: Vec<Expression>,
11923}
11924
11925/// JSONStripNulls
11926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11927#[cfg_attr(feature = "bindings", derive(TS))]
11928pub struct JSONStripNulls {
11929    pub this: Box<Expression>,
11930    #[serde(default)]
11931    pub expression: Option<Box<Expression>>,
11932    #[serde(default)]
11933    pub include_arrays: Option<Box<Expression>>,
11934    #[serde(default)]
11935    pub remove_empty: Option<Box<Expression>>,
11936}
11937
11938/// JSONValue
11939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11940#[cfg_attr(feature = "bindings", derive(TS))]
11941pub struct JSONValue {
11942    pub this: Box<Expression>,
11943    #[serde(default)]
11944    pub path: Option<Box<Expression>>,
11945    #[serde(default)]
11946    pub returning: Option<Box<Expression>>,
11947    #[serde(default)]
11948    pub on_condition: Option<Box<Expression>>,
11949}
11950
11951/// JSONValueArray
11952#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11953#[cfg_attr(feature = "bindings", derive(TS))]
11954pub struct JSONValueArray {
11955    pub this: Box<Expression>,
11956    #[serde(default)]
11957    pub expression: Option<Box<Expression>>,
11958}
11959
11960/// JSONRemove
11961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11962#[cfg_attr(feature = "bindings", derive(TS))]
11963pub struct JSONRemove {
11964    pub this: Box<Expression>,
11965    #[serde(default)]
11966    pub expressions: Vec<Expression>,
11967}
11968
11969/// JSONTable
11970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11971#[cfg_attr(feature = "bindings", derive(TS))]
11972pub struct JSONTable {
11973    pub this: Box<Expression>,
11974    #[serde(default)]
11975    pub schema: Option<Box<Expression>>,
11976    #[serde(default)]
11977    pub path: Option<Box<Expression>>,
11978    #[serde(default)]
11979    pub error_handling: Option<Box<Expression>>,
11980    #[serde(default)]
11981    pub empty_handling: Option<Box<Expression>>,
11982}
11983
11984/// JSONType
11985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11986#[cfg_attr(feature = "bindings", derive(TS))]
11987pub struct JSONType {
11988    pub this: Box<Expression>,
11989    #[serde(default)]
11990    pub expression: Option<Box<Expression>>,
11991}
11992
11993/// ObjectInsert
11994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11995#[cfg_attr(feature = "bindings", derive(TS))]
11996pub struct ObjectInsert {
11997    pub this: Box<Expression>,
11998    #[serde(default)]
11999    pub key: Option<Box<Expression>>,
12000    #[serde(default)]
12001    pub value: Option<Box<Expression>>,
12002    #[serde(default)]
12003    pub update_flag: Option<Box<Expression>>,
12004}
12005
12006/// OpenJSONColumnDef
12007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12008#[cfg_attr(feature = "bindings", derive(TS))]
12009pub struct OpenJSONColumnDef {
12010    pub this: Box<Expression>,
12011    pub kind: String,
12012    #[serde(default)]
12013    pub path: Option<Box<Expression>>,
12014    #[serde(default)]
12015    pub as_json: Option<Box<Expression>>,
12016    /// The parsed data type for proper generation
12017    #[serde(default, skip_serializing_if = "Option::is_none")]
12018    pub data_type: Option<DataType>,
12019}
12020
12021/// OpenJSON
12022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12023#[cfg_attr(feature = "bindings", derive(TS))]
12024pub struct OpenJSON {
12025    pub this: Box<Expression>,
12026    #[serde(default)]
12027    pub path: Option<Box<Expression>>,
12028    #[serde(default)]
12029    pub expressions: Vec<Expression>,
12030}
12031
12032/// JSONBExists
12033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12034#[cfg_attr(feature = "bindings", derive(TS))]
12035pub struct JSONBExists {
12036    pub this: Box<Expression>,
12037    #[serde(default)]
12038    pub path: Option<Box<Expression>>,
12039}
12040
12041/// JSONCast
12042#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12043#[cfg_attr(feature = "bindings", derive(TS))]
12044pub struct JSONCast {
12045    pub this: Box<Expression>,
12046    pub to: DataType,
12047}
12048
12049/// JSONExtract
12050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12051#[cfg_attr(feature = "bindings", derive(TS))]
12052pub struct JSONExtract {
12053    pub this: Box<Expression>,
12054    pub expression: Box<Expression>,
12055    #[serde(default)]
12056    pub only_json_types: Option<Box<Expression>>,
12057    #[serde(default)]
12058    pub expressions: Vec<Expression>,
12059    #[serde(default)]
12060    pub variant_extract: Option<Box<Expression>>,
12061    #[serde(default)]
12062    pub json_query: Option<Box<Expression>>,
12063    #[serde(default)]
12064    pub option: Option<Box<Expression>>,
12065    #[serde(default)]
12066    pub quote: Option<Box<Expression>>,
12067    #[serde(default)]
12068    pub on_condition: Option<Box<Expression>>,
12069    #[serde(default)]
12070    pub requires_json: Option<Box<Expression>>,
12071}
12072
12073/// JSONExtractQuote
12074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12075#[cfg_attr(feature = "bindings", derive(TS))]
12076pub struct JSONExtractQuote {
12077    #[serde(default)]
12078    pub option: Option<Box<Expression>>,
12079    #[serde(default)]
12080    pub scalar: Option<Box<Expression>>,
12081}
12082
12083/// JSONExtractArray
12084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12085#[cfg_attr(feature = "bindings", derive(TS))]
12086pub struct JSONExtractArray {
12087    pub this: Box<Expression>,
12088    #[serde(default)]
12089    pub expression: Option<Box<Expression>>,
12090}
12091
12092/// JSONExtractScalar
12093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12094#[cfg_attr(feature = "bindings", derive(TS))]
12095pub struct JSONExtractScalar {
12096    pub this: Box<Expression>,
12097    pub expression: Box<Expression>,
12098    #[serde(default)]
12099    pub only_json_types: Option<Box<Expression>>,
12100    #[serde(default)]
12101    pub expressions: Vec<Expression>,
12102    #[serde(default)]
12103    pub json_type: Option<Box<Expression>>,
12104    #[serde(default)]
12105    pub scalar_only: Option<Box<Expression>>,
12106}
12107
12108/// JSONBExtractScalar
12109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12110#[cfg_attr(feature = "bindings", derive(TS))]
12111pub struct JSONBExtractScalar {
12112    pub this: Box<Expression>,
12113    pub expression: Box<Expression>,
12114    #[serde(default)]
12115    pub json_type: Option<Box<Expression>>,
12116}
12117
12118/// JSONFormat
12119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12120#[cfg_attr(feature = "bindings", derive(TS))]
12121pub struct JSONFormat {
12122    #[serde(default)]
12123    pub this: Option<Box<Expression>>,
12124    #[serde(default)]
12125    pub options: Vec<Expression>,
12126    #[serde(default)]
12127    pub is_json: Option<Box<Expression>>,
12128    #[serde(default)]
12129    pub to_json: Option<Box<Expression>>,
12130}
12131
12132/// JSONArrayAppend
12133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12134#[cfg_attr(feature = "bindings", derive(TS))]
12135pub struct JSONArrayAppend {
12136    pub this: Box<Expression>,
12137    #[serde(default)]
12138    pub expressions: Vec<Expression>,
12139}
12140
12141/// JSONArrayContains
12142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12143#[cfg_attr(feature = "bindings", derive(TS))]
12144pub struct JSONArrayContains {
12145    pub this: Box<Expression>,
12146    pub expression: Box<Expression>,
12147    #[serde(default)]
12148    pub json_type: Option<Box<Expression>>,
12149}
12150
12151/// JSONArrayInsert
12152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12153#[cfg_attr(feature = "bindings", derive(TS))]
12154pub struct JSONArrayInsert {
12155    pub this: Box<Expression>,
12156    #[serde(default)]
12157    pub expressions: Vec<Expression>,
12158}
12159
12160/// ParseJSON
12161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12162#[cfg_attr(feature = "bindings", derive(TS))]
12163pub struct ParseJSON {
12164    pub this: Box<Expression>,
12165    #[serde(default)]
12166    pub expression: Option<Box<Expression>>,
12167    #[serde(default)]
12168    pub safe: Option<Box<Expression>>,
12169}
12170
12171/// ParseUrl
12172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12173#[cfg_attr(feature = "bindings", derive(TS))]
12174pub struct ParseUrl {
12175    pub this: Box<Expression>,
12176    #[serde(default)]
12177    pub part_to_extract: Option<Box<Expression>>,
12178    #[serde(default)]
12179    pub key: Option<Box<Expression>>,
12180    #[serde(default)]
12181    pub permissive: Option<Box<Expression>>,
12182}
12183
12184/// ParseIp
12185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12186#[cfg_attr(feature = "bindings", derive(TS))]
12187pub struct ParseIp {
12188    pub this: Box<Expression>,
12189    #[serde(default)]
12190    pub type_: Option<Box<Expression>>,
12191    #[serde(default)]
12192    pub permissive: Option<Box<Expression>>,
12193}
12194
12195/// ParseTime
12196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12197#[cfg_attr(feature = "bindings", derive(TS))]
12198pub struct ParseTime {
12199    pub this: Box<Expression>,
12200    pub format: String,
12201}
12202
12203/// ParseDatetime
12204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12205#[cfg_attr(feature = "bindings", derive(TS))]
12206pub struct ParseDatetime {
12207    pub this: Box<Expression>,
12208    #[serde(default)]
12209    pub format: Option<String>,
12210    #[serde(default)]
12211    pub zone: Option<Box<Expression>>,
12212}
12213
12214/// Map
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct Map {
12218    #[serde(default)]
12219    pub keys: Vec<Expression>,
12220    #[serde(default)]
12221    pub values: Vec<Expression>,
12222}
12223
12224/// MapCat
12225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12226#[cfg_attr(feature = "bindings", derive(TS))]
12227pub struct MapCat {
12228    pub this: Box<Expression>,
12229    pub expression: Box<Expression>,
12230}
12231
12232/// MapDelete
12233#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12234#[cfg_attr(feature = "bindings", derive(TS))]
12235pub struct MapDelete {
12236    pub this: Box<Expression>,
12237    #[serde(default)]
12238    pub expressions: Vec<Expression>,
12239}
12240
12241/// MapInsert
12242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12243#[cfg_attr(feature = "bindings", derive(TS))]
12244pub struct MapInsert {
12245    pub this: Box<Expression>,
12246    #[serde(default)]
12247    pub key: Option<Box<Expression>>,
12248    #[serde(default)]
12249    pub value: Option<Box<Expression>>,
12250    #[serde(default)]
12251    pub update_flag: Option<Box<Expression>>,
12252}
12253
12254/// MapPick
12255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12256#[cfg_attr(feature = "bindings", derive(TS))]
12257pub struct MapPick {
12258    pub this: Box<Expression>,
12259    #[serde(default)]
12260    pub expressions: Vec<Expression>,
12261}
12262
12263/// ScopeResolution
12264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12265#[cfg_attr(feature = "bindings", derive(TS))]
12266pub struct ScopeResolution {
12267    #[serde(default)]
12268    pub this: Option<Box<Expression>>,
12269    pub expression: Box<Expression>,
12270}
12271
12272/// Slice
12273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12274#[cfg_attr(feature = "bindings", derive(TS))]
12275pub struct Slice {
12276    #[serde(default)]
12277    pub this: Option<Box<Expression>>,
12278    #[serde(default)]
12279    pub expression: Option<Box<Expression>>,
12280    #[serde(default)]
12281    pub step: Option<Box<Expression>>,
12282}
12283
12284/// VarMap
12285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12286#[cfg_attr(feature = "bindings", derive(TS))]
12287pub struct VarMap {
12288    #[serde(default)]
12289    pub keys: Vec<Expression>,
12290    #[serde(default)]
12291    pub values: Vec<Expression>,
12292}
12293
12294/// MatchAgainst
12295#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12296#[cfg_attr(feature = "bindings", derive(TS))]
12297pub struct MatchAgainst {
12298    pub this: Box<Expression>,
12299    #[serde(default)]
12300    pub expressions: Vec<Expression>,
12301    #[serde(default)]
12302    pub modifier: Option<Box<Expression>>,
12303}
12304
12305/// MD5Digest
12306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12307#[cfg_attr(feature = "bindings", derive(TS))]
12308pub struct MD5Digest {
12309    pub this: Box<Expression>,
12310    #[serde(default)]
12311    pub expressions: Vec<Expression>,
12312}
12313
12314/// Monthname
12315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12316#[cfg_attr(feature = "bindings", derive(TS))]
12317pub struct Monthname {
12318    pub this: Box<Expression>,
12319    #[serde(default)]
12320    pub abbreviated: Option<Box<Expression>>,
12321}
12322
12323/// Ntile
12324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12325#[cfg_attr(feature = "bindings", derive(TS))]
12326pub struct Ntile {
12327    #[serde(default)]
12328    pub this: Option<Box<Expression>>,
12329}
12330
12331/// Normalize
12332#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12333#[cfg_attr(feature = "bindings", derive(TS))]
12334pub struct Normalize {
12335    pub this: Box<Expression>,
12336    #[serde(default)]
12337    pub form: Option<Box<Expression>>,
12338    #[serde(default)]
12339    pub is_casefold: Option<Box<Expression>>,
12340}
12341
12342/// Normal
12343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12344#[cfg_attr(feature = "bindings", derive(TS))]
12345pub struct Normal {
12346    pub this: Box<Expression>,
12347    #[serde(default)]
12348    pub stddev: Option<Box<Expression>>,
12349    #[serde(default)]
12350    pub gen: Option<Box<Expression>>,
12351}
12352
12353/// Predict
12354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12355#[cfg_attr(feature = "bindings", derive(TS))]
12356pub struct Predict {
12357    pub this: Box<Expression>,
12358    pub expression: Box<Expression>,
12359    #[serde(default)]
12360    pub params_struct: Option<Box<Expression>>,
12361}
12362
12363/// MLTranslate
12364#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12365#[cfg_attr(feature = "bindings", derive(TS))]
12366pub struct MLTranslate {
12367    pub this: Box<Expression>,
12368    pub expression: Box<Expression>,
12369    #[serde(default)]
12370    pub params_struct: Option<Box<Expression>>,
12371}
12372
12373/// FeaturesAtTime
12374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12375#[cfg_attr(feature = "bindings", derive(TS))]
12376pub struct FeaturesAtTime {
12377    pub this: Box<Expression>,
12378    #[serde(default)]
12379    pub time: Option<Box<Expression>>,
12380    #[serde(default)]
12381    pub num_rows: Option<Box<Expression>>,
12382    #[serde(default)]
12383    pub ignore_feature_nulls: Option<Box<Expression>>,
12384}
12385
12386/// GenerateEmbedding
12387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12388#[cfg_attr(feature = "bindings", derive(TS))]
12389pub struct GenerateEmbedding {
12390    pub this: Box<Expression>,
12391    pub expression: Box<Expression>,
12392    #[serde(default)]
12393    pub params_struct: Option<Box<Expression>>,
12394    #[serde(default)]
12395    pub is_text: Option<Box<Expression>>,
12396}
12397
12398/// MLForecast
12399#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12400#[cfg_attr(feature = "bindings", derive(TS))]
12401pub struct MLForecast {
12402    pub this: Box<Expression>,
12403    #[serde(default)]
12404    pub expression: Option<Box<Expression>>,
12405    #[serde(default)]
12406    pub params_struct: Option<Box<Expression>>,
12407}
12408
12409/// ModelAttribute
12410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12411#[cfg_attr(feature = "bindings", derive(TS))]
12412pub struct ModelAttribute {
12413    pub this: Box<Expression>,
12414    pub expression: Box<Expression>,
12415}
12416
12417/// VectorSearch
12418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12419#[cfg_attr(feature = "bindings", derive(TS))]
12420pub struct VectorSearch {
12421    pub this: Box<Expression>,
12422    #[serde(default)]
12423    pub column_to_search: Option<Box<Expression>>,
12424    #[serde(default)]
12425    pub query_table: Option<Box<Expression>>,
12426    #[serde(default)]
12427    pub query_column_to_search: Option<Box<Expression>>,
12428    #[serde(default)]
12429    pub top_k: Option<Box<Expression>>,
12430    #[serde(default)]
12431    pub distance_type: Option<Box<Expression>>,
12432    #[serde(default)]
12433    pub options: Vec<Expression>,
12434}
12435
12436/// Quantile
12437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12438#[cfg_attr(feature = "bindings", derive(TS))]
12439pub struct Quantile {
12440    pub this: Box<Expression>,
12441    #[serde(default)]
12442    pub quantile: Option<Box<Expression>>,
12443}
12444
12445/// ApproxQuantile
12446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12447#[cfg_attr(feature = "bindings", derive(TS))]
12448pub struct ApproxQuantile {
12449    pub this: Box<Expression>,
12450    #[serde(default)]
12451    pub quantile: Option<Box<Expression>>,
12452    #[serde(default)]
12453    pub accuracy: Option<Box<Expression>>,
12454    #[serde(default)]
12455    pub weight: Option<Box<Expression>>,
12456    #[serde(default)]
12457    pub error_tolerance: Option<Box<Expression>>,
12458}
12459
12460/// ApproxPercentileEstimate
12461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12462#[cfg_attr(feature = "bindings", derive(TS))]
12463pub struct ApproxPercentileEstimate {
12464    pub this: Box<Expression>,
12465    #[serde(default)]
12466    pub percentile: Option<Box<Expression>>,
12467}
12468
12469/// Randn
12470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12471#[cfg_attr(feature = "bindings", derive(TS))]
12472pub struct Randn {
12473    #[serde(default)]
12474    pub this: Option<Box<Expression>>,
12475}
12476
12477/// Randstr
12478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12479#[cfg_attr(feature = "bindings", derive(TS))]
12480pub struct Randstr {
12481    pub this: Box<Expression>,
12482    #[serde(default)]
12483    pub generator: Option<Box<Expression>>,
12484}
12485
12486/// RangeN
12487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12488#[cfg_attr(feature = "bindings", derive(TS))]
12489pub struct RangeN {
12490    pub this: Box<Expression>,
12491    #[serde(default)]
12492    pub expressions: Vec<Expression>,
12493    #[serde(default)]
12494    pub each: Option<Box<Expression>>,
12495}
12496
12497/// RangeBucket
12498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12499#[cfg_attr(feature = "bindings", derive(TS))]
12500pub struct RangeBucket {
12501    pub this: Box<Expression>,
12502    pub expression: Box<Expression>,
12503}
12504
12505/// ReadCSV
12506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12507#[cfg_attr(feature = "bindings", derive(TS))]
12508pub struct ReadCSV {
12509    pub this: Box<Expression>,
12510    #[serde(default)]
12511    pub expressions: Vec<Expression>,
12512}
12513
12514/// ReadParquet
12515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12516#[cfg_attr(feature = "bindings", derive(TS))]
12517pub struct ReadParquet {
12518    #[serde(default)]
12519    pub expressions: Vec<Expression>,
12520}
12521
12522/// Reduce
12523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12524#[cfg_attr(feature = "bindings", derive(TS))]
12525pub struct Reduce {
12526    pub this: Box<Expression>,
12527    #[serde(default)]
12528    pub initial: Option<Box<Expression>>,
12529    #[serde(default)]
12530    pub merge: Option<Box<Expression>>,
12531    #[serde(default)]
12532    pub finish: Option<Box<Expression>>,
12533}
12534
12535/// RegexpExtractAll
12536#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12537#[cfg_attr(feature = "bindings", derive(TS))]
12538pub struct RegexpExtractAll {
12539    pub this: Box<Expression>,
12540    pub expression: Box<Expression>,
12541    #[serde(default)]
12542    pub group: Option<Box<Expression>>,
12543    #[serde(default)]
12544    pub parameters: Option<Box<Expression>>,
12545    #[serde(default)]
12546    pub position: Option<Box<Expression>>,
12547    #[serde(default)]
12548    pub occurrence: Option<Box<Expression>>,
12549}
12550
12551/// RegexpILike
12552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12553#[cfg_attr(feature = "bindings", derive(TS))]
12554pub struct RegexpILike {
12555    pub this: Box<Expression>,
12556    pub expression: Box<Expression>,
12557    #[serde(default)]
12558    pub flag: Option<Box<Expression>>,
12559}
12560
12561/// RegexpFullMatch
12562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12563#[cfg_attr(feature = "bindings", derive(TS))]
12564pub struct RegexpFullMatch {
12565    pub this: Box<Expression>,
12566    pub expression: Box<Expression>,
12567    #[serde(default)]
12568    pub options: Vec<Expression>,
12569}
12570
12571/// RegexpInstr
12572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12573#[cfg_attr(feature = "bindings", derive(TS))]
12574pub struct RegexpInstr {
12575    pub this: Box<Expression>,
12576    pub expression: Box<Expression>,
12577    #[serde(default)]
12578    pub position: Option<Box<Expression>>,
12579    #[serde(default)]
12580    pub occurrence: Option<Box<Expression>>,
12581    #[serde(default)]
12582    pub option: Option<Box<Expression>>,
12583    #[serde(default)]
12584    pub parameters: Option<Box<Expression>>,
12585    #[serde(default)]
12586    pub group: Option<Box<Expression>>,
12587}
12588
12589/// RegexpSplit
12590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12591#[cfg_attr(feature = "bindings", derive(TS))]
12592pub struct RegexpSplit {
12593    pub this: Box<Expression>,
12594    pub expression: Box<Expression>,
12595    #[serde(default)]
12596    pub limit: Option<Box<Expression>>,
12597}
12598
12599/// RegexpCount
12600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12601#[cfg_attr(feature = "bindings", derive(TS))]
12602pub struct RegexpCount {
12603    pub this: Box<Expression>,
12604    pub expression: Box<Expression>,
12605    #[serde(default)]
12606    pub position: Option<Box<Expression>>,
12607    #[serde(default)]
12608    pub parameters: Option<Box<Expression>>,
12609}
12610
12611/// RegrValx
12612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12613#[cfg_attr(feature = "bindings", derive(TS))]
12614pub struct RegrValx {
12615    pub this: Box<Expression>,
12616    pub expression: Box<Expression>,
12617}
12618
12619/// RegrValy
12620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12621#[cfg_attr(feature = "bindings", derive(TS))]
12622pub struct RegrValy {
12623    pub this: Box<Expression>,
12624    pub expression: Box<Expression>,
12625}
12626
12627/// RegrAvgy
12628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12629#[cfg_attr(feature = "bindings", derive(TS))]
12630pub struct RegrAvgy {
12631    pub this: Box<Expression>,
12632    pub expression: Box<Expression>,
12633}
12634
12635/// RegrAvgx
12636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12637#[cfg_attr(feature = "bindings", derive(TS))]
12638pub struct RegrAvgx {
12639    pub this: Box<Expression>,
12640    pub expression: Box<Expression>,
12641}
12642
12643/// RegrCount
12644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12645#[cfg_attr(feature = "bindings", derive(TS))]
12646pub struct RegrCount {
12647    pub this: Box<Expression>,
12648    pub expression: Box<Expression>,
12649}
12650
12651/// RegrIntercept
12652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12653#[cfg_attr(feature = "bindings", derive(TS))]
12654pub struct RegrIntercept {
12655    pub this: Box<Expression>,
12656    pub expression: Box<Expression>,
12657}
12658
12659/// RegrR2
12660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12661#[cfg_attr(feature = "bindings", derive(TS))]
12662pub struct RegrR2 {
12663    pub this: Box<Expression>,
12664    pub expression: Box<Expression>,
12665}
12666
12667/// RegrSxx
12668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12669#[cfg_attr(feature = "bindings", derive(TS))]
12670pub struct RegrSxx {
12671    pub this: Box<Expression>,
12672    pub expression: Box<Expression>,
12673}
12674
12675/// RegrSxy
12676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12677#[cfg_attr(feature = "bindings", derive(TS))]
12678pub struct RegrSxy {
12679    pub this: Box<Expression>,
12680    pub expression: Box<Expression>,
12681}
12682
12683/// RegrSyy
12684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12685#[cfg_attr(feature = "bindings", derive(TS))]
12686pub struct RegrSyy {
12687    pub this: Box<Expression>,
12688    pub expression: Box<Expression>,
12689}
12690
12691/// RegrSlope
12692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12693#[cfg_attr(feature = "bindings", derive(TS))]
12694pub struct RegrSlope {
12695    pub this: Box<Expression>,
12696    pub expression: Box<Expression>,
12697}
12698
12699/// SafeAdd
12700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12701#[cfg_attr(feature = "bindings", derive(TS))]
12702pub struct SafeAdd {
12703    pub this: Box<Expression>,
12704    pub expression: Box<Expression>,
12705}
12706
12707/// SafeDivide
12708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12709#[cfg_attr(feature = "bindings", derive(TS))]
12710pub struct SafeDivide {
12711    pub this: Box<Expression>,
12712    pub expression: Box<Expression>,
12713}
12714
12715/// SafeMultiply
12716#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12717#[cfg_attr(feature = "bindings", derive(TS))]
12718pub struct SafeMultiply {
12719    pub this: Box<Expression>,
12720    pub expression: Box<Expression>,
12721}
12722
12723/// SafeSubtract
12724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12725#[cfg_attr(feature = "bindings", derive(TS))]
12726pub struct SafeSubtract {
12727    pub this: Box<Expression>,
12728    pub expression: Box<Expression>,
12729}
12730
12731/// SHA2
12732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12733#[cfg_attr(feature = "bindings", derive(TS))]
12734pub struct SHA2 {
12735    pub this: Box<Expression>,
12736    #[serde(default)]
12737    pub length: Option<i64>,
12738}
12739
12740/// SHA2Digest
12741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12742#[cfg_attr(feature = "bindings", derive(TS))]
12743pub struct SHA2Digest {
12744    pub this: Box<Expression>,
12745    #[serde(default)]
12746    pub length: Option<i64>,
12747}
12748
12749/// SortArray
12750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12751#[cfg_attr(feature = "bindings", derive(TS))]
12752pub struct SortArray {
12753    pub this: Box<Expression>,
12754    #[serde(default)]
12755    pub asc: Option<Box<Expression>>,
12756    #[serde(default)]
12757    pub nulls_first: Option<Box<Expression>>,
12758}
12759
12760/// SplitPart
12761#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12762#[cfg_attr(feature = "bindings", derive(TS))]
12763pub struct SplitPart {
12764    pub this: Box<Expression>,
12765    #[serde(default)]
12766    pub delimiter: Option<Box<Expression>>,
12767    #[serde(default)]
12768    pub part_index: Option<Box<Expression>>,
12769}
12770
12771/// SUBSTRING_INDEX(str, delim, count)
12772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12773#[cfg_attr(feature = "bindings", derive(TS))]
12774pub struct SubstringIndex {
12775    pub this: Box<Expression>,
12776    #[serde(default)]
12777    pub delimiter: Option<Box<Expression>>,
12778    #[serde(default)]
12779    pub count: Option<Box<Expression>>,
12780}
12781
12782/// StandardHash
12783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12784#[cfg_attr(feature = "bindings", derive(TS))]
12785pub struct StandardHash {
12786    pub this: Box<Expression>,
12787    #[serde(default)]
12788    pub expression: Option<Box<Expression>>,
12789}
12790
12791/// StrPosition
12792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12793#[cfg_attr(feature = "bindings", derive(TS))]
12794pub struct StrPosition {
12795    pub this: Box<Expression>,
12796    #[serde(default)]
12797    pub substr: Option<Box<Expression>>,
12798    #[serde(default)]
12799    pub position: Option<Box<Expression>>,
12800    #[serde(default)]
12801    pub occurrence: Option<Box<Expression>>,
12802}
12803
12804/// Search
12805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12806#[cfg_attr(feature = "bindings", derive(TS))]
12807pub struct Search {
12808    pub this: Box<Expression>,
12809    pub expression: Box<Expression>,
12810    #[serde(default)]
12811    pub json_scope: Option<Box<Expression>>,
12812    #[serde(default)]
12813    pub analyzer: Option<Box<Expression>>,
12814    #[serde(default)]
12815    pub analyzer_options: Option<Box<Expression>>,
12816    #[serde(default)]
12817    pub search_mode: Option<Box<Expression>>,
12818}
12819
12820/// SearchIp
12821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12822#[cfg_attr(feature = "bindings", derive(TS))]
12823pub struct SearchIp {
12824    pub this: Box<Expression>,
12825    pub expression: Box<Expression>,
12826}
12827
12828/// StrToDate
12829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12830#[cfg_attr(feature = "bindings", derive(TS))]
12831pub struct StrToDate {
12832    pub this: Box<Expression>,
12833    #[serde(default)]
12834    pub format: Option<String>,
12835    #[serde(default)]
12836    pub safe: Option<Box<Expression>>,
12837}
12838
12839/// StrToTime
12840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12841#[cfg_attr(feature = "bindings", derive(TS))]
12842pub struct StrToTime {
12843    pub this: Box<Expression>,
12844    pub format: String,
12845    #[serde(default)]
12846    pub zone: Option<Box<Expression>>,
12847    #[serde(default)]
12848    pub safe: Option<Box<Expression>>,
12849    #[serde(default)]
12850    pub target_type: Option<Box<Expression>>,
12851}
12852
12853/// StrToUnix
12854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12855#[cfg_attr(feature = "bindings", derive(TS))]
12856pub struct StrToUnix {
12857    #[serde(default)]
12858    pub this: Option<Box<Expression>>,
12859    #[serde(default)]
12860    pub format: Option<String>,
12861}
12862
12863/// StrToMap
12864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12865#[cfg_attr(feature = "bindings", derive(TS))]
12866pub struct StrToMap {
12867    pub this: Box<Expression>,
12868    #[serde(default)]
12869    pub pair_delim: Option<Box<Expression>>,
12870    #[serde(default)]
12871    pub key_value_delim: Option<Box<Expression>>,
12872    #[serde(default)]
12873    pub duplicate_resolution_callback: Option<Box<Expression>>,
12874}
12875
12876/// NumberToStr
12877#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12878#[cfg_attr(feature = "bindings", derive(TS))]
12879pub struct NumberToStr {
12880    pub this: Box<Expression>,
12881    pub format: String,
12882    #[serde(default)]
12883    pub culture: Option<Box<Expression>>,
12884}
12885
12886/// FromBase
12887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12888#[cfg_attr(feature = "bindings", derive(TS))]
12889pub struct FromBase {
12890    pub this: Box<Expression>,
12891    pub expression: Box<Expression>,
12892}
12893
12894/// Stuff
12895#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12896#[cfg_attr(feature = "bindings", derive(TS))]
12897pub struct Stuff {
12898    pub this: Box<Expression>,
12899    #[serde(default)]
12900    pub start: Option<Box<Expression>>,
12901    #[serde(default)]
12902    pub length: Option<i64>,
12903    pub expression: Box<Expression>,
12904}
12905
12906/// TimeToStr
12907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12908#[cfg_attr(feature = "bindings", derive(TS))]
12909pub struct TimeToStr {
12910    pub this: Box<Expression>,
12911    pub format: String,
12912    #[serde(default)]
12913    pub culture: Option<Box<Expression>>,
12914    #[serde(default)]
12915    pub zone: Option<Box<Expression>>,
12916}
12917
12918/// TimeStrToTime
12919#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12920#[cfg_attr(feature = "bindings", derive(TS))]
12921pub struct TimeStrToTime {
12922    pub this: Box<Expression>,
12923    #[serde(default)]
12924    pub zone: Option<Box<Expression>>,
12925}
12926
12927/// TsOrDsAdd
12928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12929#[cfg_attr(feature = "bindings", derive(TS))]
12930pub struct TsOrDsAdd {
12931    pub this: Box<Expression>,
12932    pub expression: Box<Expression>,
12933    #[serde(default)]
12934    pub unit: Option<String>,
12935    #[serde(default)]
12936    pub return_type: Option<Box<Expression>>,
12937}
12938
12939/// TsOrDsDiff
12940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12941#[cfg_attr(feature = "bindings", derive(TS))]
12942pub struct TsOrDsDiff {
12943    pub this: Box<Expression>,
12944    pub expression: Box<Expression>,
12945    #[serde(default)]
12946    pub unit: Option<String>,
12947}
12948
12949/// TsOrDsToDate
12950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12951#[cfg_attr(feature = "bindings", derive(TS))]
12952pub struct TsOrDsToDate {
12953    pub this: Box<Expression>,
12954    #[serde(default)]
12955    pub format: Option<String>,
12956    #[serde(default)]
12957    pub safe: Option<Box<Expression>>,
12958}
12959
12960/// TsOrDsToTime
12961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12962#[cfg_attr(feature = "bindings", derive(TS))]
12963pub struct TsOrDsToTime {
12964    pub this: Box<Expression>,
12965    #[serde(default)]
12966    pub format: Option<String>,
12967    #[serde(default)]
12968    pub safe: Option<Box<Expression>>,
12969}
12970
12971/// Unhex
12972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12973#[cfg_attr(feature = "bindings", derive(TS))]
12974pub struct Unhex {
12975    pub this: Box<Expression>,
12976    #[serde(default)]
12977    pub expression: Option<Box<Expression>>,
12978}
12979
12980/// Uniform
12981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12982#[cfg_attr(feature = "bindings", derive(TS))]
12983pub struct Uniform {
12984    pub this: Box<Expression>,
12985    pub expression: Box<Expression>,
12986    #[serde(default)]
12987    pub gen: Option<Box<Expression>>,
12988    #[serde(default)]
12989    pub seed: Option<Box<Expression>>,
12990}
12991
12992/// UnixToStr
12993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12994#[cfg_attr(feature = "bindings", derive(TS))]
12995pub struct UnixToStr {
12996    pub this: Box<Expression>,
12997    #[serde(default)]
12998    pub format: Option<String>,
12999}
13000
13001/// UnixToTime
13002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13003#[cfg_attr(feature = "bindings", derive(TS))]
13004pub struct UnixToTime {
13005    pub this: Box<Expression>,
13006    #[serde(default)]
13007    pub scale: Option<i64>,
13008    #[serde(default)]
13009    pub zone: Option<Box<Expression>>,
13010    #[serde(default)]
13011    pub hours: Option<Box<Expression>>,
13012    #[serde(default)]
13013    pub minutes: Option<Box<Expression>>,
13014    #[serde(default)]
13015    pub format: Option<String>,
13016    #[serde(default)]
13017    pub target_type: Option<Box<Expression>>,
13018}
13019
13020/// Uuid
13021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13022#[cfg_attr(feature = "bindings", derive(TS))]
13023pub struct Uuid {
13024    #[serde(default)]
13025    pub this: Option<Box<Expression>>,
13026    #[serde(default)]
13027    pub name: Option<String>,
13028    #[serde(default)]
13029    pub is_string: Option<Box<Expression>>,
13030}
13031
13032/// TimestampFromParts
13033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13034#[cfg_attr(feature = "bindings", derive(TS))]
13035pub struct TimestampFromParts {
13036    #[serde(default)]
13037    pub zone: Option<Box<Expression>>,
13038    #[serde(default)]
13039    pub milli: Option<Box<Expression>>,
13040    #[serde(default)]
13041    pub this: Option<Box<Expression>>,
13042    #[serde(default)]
13043    pub expression: Option<Box<Expression>>,
13044}
13045
13046/// TimestampTzFromParts
13047#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13048#[cfg_attr(feature = "bindings", derive(TS))]
13049pub struct TimestampTzFromParts {
13050    #[serde(default)]
13051    pub zone: Option<Box<Expression>>,
13052}
13053
13054/// Corr
13055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13056#[cfg_attr(feature = "bindings", derive(TS))]
13057pub struct Corr {
13058    pub this: Box<Expression>,
13059    pub expression: Box<Expression>,
13060    #[serde(default)]
13061    pub null_on_zero_variance: Option<Box<Expression>>,
13062}
13063
13064/// WidthBucket
13065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13066#[cfg_attr(feature = "bindings", derive(TS))]
13067pub struct WidthBucket {
13068    pub this: Box<Expression>,
13069    #[serde(default)]
13070    pub min_value: Option<Box<Expression>>,
13071    #[serde(default)]
13072    pub max_value: Option<Box<Expression>>,
13073    #[serde(default)]
13074    pub num_buckets: Option<Box<Expression>>,
13075    #[serde(default)]
13076    pub threshold: Option<Box<Expression>>,
13077}
13078
13079/// CovarSamp
13080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13081#[cfg_attr(feature = "bindings", derive(TS))]
13082pub struct CovarSamp {
13083    pub this: Box<Expression>,
13084    pub expression: Box<Expression>,
13085}
13086
13087/// CovarPop
13088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13089#[cfg_attr(feature = "bindings", derive(TS))]
13090pub struct CovarPop {
13091    pub this: Box<Expression>,
13092    pub expression: Box<Expression>,
13093}
13094
13095/// Week
13096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13097#[cfg_attr(feature = "bindings", derive(TS))]
13098pub struct Week {
13099    pub this: Box<Expression>,
13100    #[serde(default)]
13101    pub mode: Option<Box<Expression>>,
13102}
13103
13104/// XMLElement
13105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13106#[cfg_attr(feature = "bindings", derive(TS))]
13107pub struct XMLElement {
13108    pub this: Box<Expression>,
13109    #[serde(default)]
13110    pub expressions: Vec<Expression>,
13111    #[serde(default)]
13112    pub evalname: Option<Box<Expression>>,
13113}
13114
13115/// XMLGet
13116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13117#[cfg_attr(feature = "bindings", derive(TS))]
13118pub struct XMLGet {
13119    pub this: Box<Expression>,
13120    pub expression: Box<Expression>,
13121    #[serde(default)]
13122    pub instance: Option<Box<Expression>>,
13123}
13124
13125/// XMLTable
13126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13127#[cfg_attr(feature = "bindings", derive(TS))]
13128pub struct XMLTable {
13129    pub this: Box<Expression>,
13130    #[serde(default)]
13131    pub namespaces: Option<Box<Expression>>,
13132    #[serde(default)]
13133    pub passing: Option<Box<Expression>>,
13134    #[serde(default)]
13135    pub columns: Vec<Expression>,
13136    #[serde(default)]
13137    pub by_ref: Option<Box<Expression>>,
13138}
13139
13140/// XMLKeyValueOption
13141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13142#[cfg_attr(feature = "bindings", derive(TS))]
13143pub struct XMLKeyValueOption {
13144    pub this: Box<Expression>,
13145    #[serde(default)]
13146    pub expression: Option<Box<Expression>>,
13147}
13148
13149/// Zipf
13150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13151#[cfg_attr(feature = "bindings", derive(TS))]
13152pub struct Zipf {
13153    pub this: Box<Expression>,
13154    #[serde(default)]
13155    pub elementcount: Option<Box<Expression>>,
13156    #[serde(default)]
13157    pub gen: Option<Box<Expression>>,
13158}
13159
13160/// Merge
13161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13162#[cfg_attr(feature = "bindings", derive(TS))]
13163pub struct Merge {
13164    pub this: Box<Expression>,
13165    pub using: Box<Expression>,
13166    #[serde(default)]
13167    pub on: Option<Box<Expression>>,
13168    #[serde(default)]
13169    pub using_cond: Option<Box<Expression>>,
13170    #[serde(default)]
13171    pub whens: Option<Box<Expression>>,
13172    #[serde(default)]
13173    pub with_: Option<Box<Expression>>,
13174    #[serde(default)]
13175    pub returning: Option<Box<Expression>>,
13176}
13177
13178/// When
13179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13180#[cfg_attr(feature = "bindings", derive(TS))]
13181pub struct When {
13182    #[serde(default)]
13183    pub matched: Option<Box<Expression>>,
13184    #[serde(default)]
13185    pub source: Option<Box<Expression>>,
13186    #[serde(default)]
13187    pub condition: Option<Box<Expression>>,
13188    pub then: Box<Expression>,
13189}
13190
13191/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
13192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13193#[cfg_attr(feature = "bindings", derive(TS))]
13194pub struct Whens {
13195    #[serde(default)]
13196    pub expressions: Vec<Expression>,
13197}
13198
13199/// NextValueFor
13200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13201#[cfg_attr(feature = "bindings", derive(TS))]
13202pub struct NextValueFor {
13203    pub this: Box<Expression>,
13204    #[serde(default)]
13205    pub order: Option<Box<Expression>>,
13206}
13207
13208#[cfg(test)]
13209mod tests {
13210    use super::*;
13211
13212    #[test]
13213    #[cfg(feature = "bindings")]
13214    fn export_typescript_types() {
13215        // This test exports TypeScript types to the generated directory
13216        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
13217        Expression::export_all(&ts_rs::Config::default())
13218            .expect("Failed to export Expression types");
13219    }
13220
13221    #[test]
13222    fn test_simple_select_builder() {
13223        let select = Select::new()
13224            .column(Expression::star())
13225            .from(Expression::Table(TableRef::new("users")));
13226
13227        assert_eq!(select.expressions.len(), 1);
13228        assert!(select.from.is_some());
13229    }
13230
13231    #[test]
13232    fn test_expression_alias() {
13233        let expr = Expression::column("id").alias("user_id");
13234
13235        match expr {
13236            Expression::Alias(a) => {
13237                assert_eq!(a.alias.name, "user_id");
13238            }
13239            _ => panic!("Expected Alias"),
13240        }
13241    }
13242
13243    #[test]
13244    fn test_literal_creation() {
13245        let num = Expression::number(42);
13246        let str = Expression::string("hello");
13247
13248        match num {
13249            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
13250            _ => panic!("Expected Number"),
13251        }
13252
13253        match str {
13254            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
13255            _ => panic!("Expected String"),
13256        }
13257    }
13258
13259    #[test]
13260    fn test_expression_sql() {
13261        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
13262        assert_eq!(expr.sql(), "SELECT 1 + 2");
13263    }
13264
13265    #[test]
13266    fn test_expression_sql_for() {
13267        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
13268        let sql = expr.sql_for(crate::DialectType::Generic);
13269        // Generic mode normalizes IF() to CASE WHEN
13270        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
13271    }
13272}